@zonsh/ui 0.2.0 → 0.4.1

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 (180) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +19 -13
  3. package/dist/components/alert-dialog.js +1 -1
  4. package/dist/components/ascii-field.d.ts +1 -1
  5. package/dist/components/bottom-nav.d.ts +86 -0
  6. package/dist/components/bottom-nav.js +175 -0
  7. package/dist/components/breadcrumb.d.ts +9 -0
  8. package/dist/components/breadcrumb.js +6 -1
  9. package/dist/components/button-group.d.ts +1 -1
  10. package/dist/components/button-group.js +2 -2
  11. package/dist/components/calendar.d.ts +1 -1
  12. package/dist/components/calendar.js +18 -3
  13. package/dist/components/carousel.d.ts +22 -3
  14. package/dist/components/carousel.js +25 -7
  15. package/dist/components/chart.d.ts +9 -0
  16. package/dist/components/chart.js +40 -3
  17. package/dist/components/code-block.d.ts +20 -10
  18. package/dist/components/code-block.js +54 -12
  19. package/dist/components/collapsible.js +2 -2
  20. package/dist/components/color-picker.d.ts +30 -8
  21. package/dist/components/color-picker.js +48 -27
  22. package/dist/components/combobox.d.ts +21 -3
  23. package/dist/components/combobox.js +79 -7
  24. package/dist/components/command.d.ts +23 -3
  25. package/dist/components/command.js +61 -16
  26. package/dist/components/conversation.d.ts +10 -1
  27. package/dist/components/conversation.js +14 -4
  28. package/dist/components/copy-button.d.ts +15 -6
  29. package/dist/components/copy-button.js +20 -5
  30. package/dist/components/data-table.d.ts +66 -6
  31. package/dist/components/data-table.js +376 -23
  32. package/dist/components/date-picker.d.ts +73 -4
  33. package/dist/components/date-picker.js +138 -7
  34. package/dist/components/dialog.d.ts +10 -1
  35. package/dist/components/dialog.js +6 -3
  36. package/dist/components/drawer.d.ts +10 -1
  37. package/dist/components/drawer.js +6 -3
  38. package/dist/components/feature-list.js +2 -2
  39. package/dist/components/field.d.ts +27 -8
  40. package/dist/components/field.js +49 -4
  41. package/dist/components/file-drop.d.ts +26 -4
  42. package/dist/components/file-drop.js +125 -64
  43. package/dist/components/filter-bar.d.ts +50 -3
  44. package/dist/components/filter-bar.js +71 -33
  45. package/dist/components/form.d.ts +4 -2
  46. package/dist/components/form.js +24 -2
  47. package/dist/components/graph.d.ts +41 -0
  48. package/dist/components/graph.js +84 -45
  49. package/dist/components/illustration.js +1 -1
  50. package/dist/components/input-group.d.ts +16 -5
  51. package/dist/components/input-group.js +35 -15
  52. package/dist/components/input.d.ts +2 -2
  53. package/dist/components/input.js +3 -3
  54. package/dist/components/kbd.d.ts +17 -0
  55. package/dist/components/kbd.js +8 -1
  56. package/dist/components/lightbox.d.ts +100 -0
  57. package/dist/components/lightbox.js +439 -0
  58. package/dist/components/locale.d.ts +44 -0
  59. package/dist/components/locale.js +37 -0
  60. package/dist/components/logo.js +1 -1
  61. package/dist/components/menu.js +3 -1
  62. package/dist/components/message.d.ts +3 -3
  63. package/dist/components/message.js +10 -7
  64. package/dist/components/meter.js +3 -1
  65. package/dist/components/money-input.d.ts +80 -0
  66. package/dist/components/money-input.js +253 -0
  67. package/dist/components/number-field.d.ts +21 -2
  68. package/dist/components/number-field.js +27 -16
  69. package/dist/components/otp-field.d.ts +14 -1
  70. package/dist/components/otp-field.js +10 -2
  71. package/dist/components/pagination.d.ts +13 -7
  72. package/dist/components/pagination.js +18 -7
  73. package/dist/components/pdf-viewer.d.ts +67 -2
  74. package/dist/components/pdf-viewer.js +88 -21
  75. package/dist/components/phone-input.d.ts +79 -0
  76. package/dist/components/phone-input.js +282 -0
  77. package/dist/components/popover.js +1 -1
  78. package/dist/components/progress.js +3 -1
  79. package/dist/components/prompt-input.d.ts +34 -9
  80. package/dist/components/prompt-input.js +28 -16
  81. package/dist/components/rating.d.ts +73 -0
  82. package/dist/components/rating.js +124 -0
  83. package/dist/components/reasoning.d.ts +16 -1
  84. package/dist/components/reasoning.js +10 -7
  85. package/dist/components/resizable.d.ts +10 -1
  86. package/dist/components/resizable.js +4 -1
  87. package/dist/components/response.d.ts +14 -3
  88. package/dist/components/response.js +36 -8
  89. package/dist/components/scroll-area.d.ts +1 -1
  90. package/dist/components/select.js +14 -3
  91. package/dist/components/separator.js +1 -1
  92. package/dist/components/sidebar.d.ts +20 -4
  93. package/dist/components/sidebar.js +34 -18
  94. package/dist/components/site-header.d.ts +46 -12
  95. package/dist/components/site-header.js +73 -19
  96. package/dist/components/slider.js +3 -1
  97. package/dist/components/sortable.d.ts +178 -0
  98. package/dist/components/sortable.js +1258 -0
  99. package/dist/components/sources.d.ts +17 -2
  100. package/dist/components/sources.js +11 -4
  101. package/dist/components/spinner.d.ts +13 -1
  102. package/dist/components/spinner.js +5 -2
  103. package/dist/components/stat.d.ts +91 -0
  104. package/dist/components/stat.js +141 -0
  105. package/dist/components/stepper.d.ts +71 -0
  106. package/dist/components/stepper.js +101 -0
  107. package/dist/components/switch.d.ts +2 -2
  108. package/dist/components/switch.js +2 -2
  109. package/dist/components/table.d.ts +12 -2
  110. package/dist/components/table.js +176 -39
  111. package/dist/components/tags-input.d.ts +18 -2
  112. package/dist/components/tags-input.js +65 -33
  113. package/dist/components/theme.d.ts +16 -2
  114. package/dist/components/theme.js +15 -7
  115. package/dist/components/time-field.d.ts +22 -3
  116. package/dist/components/time-field.js +19 -6
  117. package/dist/components/timeline.d.ts +18 -2
  118. package/dist/components/timeline.js +13 -4
  119. package/dist/components/tippy.d.ts +48 -0
  120. package/dist/components/tippy.js +648 -0
  121. package/dist/components/toast.d.ts +18 -2
  122. package/dist/components/toast.js +12 -3
  123. package/dist/components/tool-call.d.ts +19 -8
  124. package/dist/components/tool-call.js +18 -7
  125. package/dist/components/toolbar.js +6 -1
  126. package/dist/components/tour.d.ts +127 -0
  127. package/dist/components/tour.js +648 -0
  128. package/dist/components/tree.js +17 -4
  129. package/dist/components/video-player.d.ts +10 -2
  130. package/dist/components/video-player.js +73 -33
  131. package/dist/illustration.d.ts +2 -0
  132. package/dist/illustration.js +7 -0
  133. package/dist/index.d.ts +11 -3
  134. package/dist/index.js +11 -3
  135. package/dist/lib/code-highlight.d.ts +3 -16
  136. package/dist/lib/code-highlight.js +160 -10
  137. package/dist/lib/code-theme.js +3 -3
  138. package/dist/lib/digit-roll.js +8 -8
  139. package/dist/lib/field-errors.d.ts +28 -0
  140. package/dist/lib/field-errors.js +24 -0
  141. package/dist/lib/field-value.d.ts +13 -0
  142. package/dist/lib/field-value.js +44 -0
  143. package/dist/lib/graph-layout.js +11 -2
  144. package/dist/lib/money.d.ts +73 -0
  145. package/dist/lib/money.js +343 -0
  146. package/dist/lib/phone-countries.d.ts +1 -0
  147. package/dist/lib/phone-countries.js +281 -0
  148. package/dist/lib/phone.d.ts +90 -0
  149. package/dist/lib/phone.js +286 -0
  150. package/dist/lib/platform.d.ts +8 -3
  151. package/dist/lib/platform.js +13 -6
  152. package/dist/lib/row-index.d.ts +15 -0
  153. package/dist/lib/row-index.js +136 -0
  154. package/dist/lib/table-fit.js +23 -4
  155. package/dist/lib/theme-script.d.ts +15 -2
  156. package/dist/lib/theme-script.js +23 -3
  157. package/dist/lib/tippy/pixels.d.ts +47 -0
  158. package/dist/lib/tippy/pixels.js +187 -0
  159. package/dist/lib/tippy/sprite.d.ts +86 -0
  160. package/dist/lib/tippy/sprite.js +753 -0
  161. package/dist/messages/de.d.ts +12 -0
  162. package/dist/messages/de.js +326 -0
  163. package/dist/styles/expressive.css +20 -5
  164. package/dist/styles/index.css +3 -2
  165. package/dist/styles/material.css +7 -3
  166. package/dist/styles/parts/ai.css +2 -1
  167. package/dist/styles/parts/controls.css +62 -13
  168. package/dist/styles/parts/feedback.css +68 -1
  169. package/dist/styles/parts/foundations.css +1 -1
  170. package/dist/styles/parts/navigation.css +194 -2
  171. package/dist/styles/parts/overlays.css +7 -7
  172. package/dist/styles/tokens.css +12 -3
  173. package/dist/vite.d.ts +0 -50
  174. package/dist/vite.js +0 -100
  175. package/package.json +28 -33
  176. package/dist/components/code-highlight.d.ts +0 -13
  177. package/dist/components/code-highlight.js +0 -107
  178. package/dist/components/whiteboard.d.ts +0 -80
  179. package/dist/components/whiteboard.js +0 -389
  180. package/dist/styles/parts/whiteboard.css +0 -855
@@ -5,6 +5,13 @@ import * as React from "react";
5
5
  import { cn } from "../lib/cn.js";
6
6
  import { glideMotion, glideStyle, useGlide, useMergedRef } from "../lib/glide.js";
7
7
  import { Button } from "./button.js";
8
+ import { useMessages } from "./locale.js";
9
+ const defaultMessages = {
10
+ nav: "Pagination",
11
+ previous: "Previous page",
12
+ next: "Next page",
13
+ page: (page) => `Page ${page}`,
14
+ };
8
15
  const PAGE = '[data-slot="pagination-page"]';
9
16
  const findCurrent = (nav) => nav.querySelector(`${PAGE}[aria-current="page"]`);
10
17
  function getPages(page, count, siblings) {
@@ -46,25 +53,29 @@ export function Pagination({ page, pageCount, onPageChange, getHref, siblingCoun
46
53
  const siblings = siblingCount >= 0 ? Math.floor(siblingCount) : 1;
47
54
  const pages = getPages(current, count, siblings);
48
55
  const square = size === "sm" ? "min-w-(--control-h-sm) px-2" : "min-w-(--control-h) px-2.5";
49
- const pageLabel = labels?.page ?? ((p) => `Page ${p}`);
56
+ // Previous and Next are exactly square at any control height, not as wide as chevron + padding.
57
+ const arrow = size === "sm" ? "w-(--control-h-sm) px-0" : "w-(--control-h) px-0";
58
+ const text = useMessages("pagination", defaultMessages, labels);
50
59
  const control = (target, content, extra) => {
51
60
  const disabled = target < 1 || target > count;
52
61
  const asLink = getHref && !disabled;
53
62
  return (_jsx(Button, { variant: "secondary", size: size, disabled: disabled,
54
63
  // Previous and Next stay focusable when they run out, so pressing Next onto the last
55
64
  // page leaves keyboard focus on it instead of dropping it to the page.
56
- focusableWhenDisabled: true, nativeButton: !asLink, render: asLink ? _jsx("a", { href: getHref(target) }) : undefined, onClick: () => !disabled && target !== page && onPageChange?.(target), className: cn(square, "font-mono text-[13px] font-normal tabular-nums"), ...extra, children: content }));
65
+ focusableWhenDisabled: true, nativeButton: !asLink, render: asLink ? _jsx("a", { href: getHref(target) }) : undefined, onClick: () => !disabled && target !== page && onPageChange?.(target), className: cn(square, "font-mono text-[13px] leading-none font-normal tabular-nums"), ...extra, children: content }));
57
66
  };
58
- return (_jsxs("nav", { "aria-label": labels?.nav ?? "Pagination", "data-slot": "pagination", "data-size": size, "data-glide": glide.visible ? "" : undefined, ref: setNavRef, className: cn("group/pagination relative flex", className), ...props, children: [_jsx("span", { "aria-hidden": true, "data-slot": "pagination-indicator", "data-visible": glide.visible ? "" : undefined, "data-instant": glide.instant ? "" : undefined, className: cn(glideMotion, "z-10 rounded-button ring-1 ring-control-focus duration-[calc(var(--duration)*1.3)]"), style: glideStyle(glide) }), _jsxs("ul", { className: "m-0 flex list-none flex-wrap items-center gap-1.5 p-0", children: [_jsx("li", { children: control(current - 1, _jsx(ChevronLeftIcon, { className: "rtl:-scale-x-100" }), {
59
- "aria-label": labels?.previous ?? "Previous page",
67
+ return (_jsxs("nav", { "aria-label": text.nav, "data-slot": "pagination", "data-size": size, "data-glide": glide.visible ? "" : undefined, ref: setNavRef, className: cn("group/pagination relative flex", className), ...props, children: [_jsx("span", { "aria-hidden": true, "data-slot": "pagination-indicator", "data-visible": glide.visible ? "" : undefined, "data-instant": glide.instant ? "" : undefined, className: cn(glideMotion, "z-10 rounded-button ring-1 ring-control-focus duration-[calc(var(--duration)*1.3)]"), style: glideStyle(glide) }), _jsxs("ul", { className: "m-0 flex list-none flex-wrap items-center gap-1.5 p-0 [&>li]:flex", children: [_jsx("li", { children: control(current - 1, _jsx(ChevronLeftIcon, { className: "rtl:-scale-x-100" }), {
68
+ "aria-label": text.previous,
69
+ className: arrow,
60
70
  }) }), pages.map((p) => typeof p === "number" ? (_jsx("li", { children: control(p, p, {
61
- "aria-label": pageLabel(p),
71
+ "aria-label": text.page(p),
62
72
  "aria-current": p === current ? "page" : undefined,
63
73
  "data-slot": "pagination-page",
64
- className: cn(square, "font-mono text-[13px] font-normal tabular-nums", "aria-[current=page]:bg-control-hover aria-[current=page]:shadow-raised-current",
74
+ className: cn(square, "font-mono text-[13px] leading-none font-normal tabular-nums", "aria-[current=page]:bg-control-hover aria-[current=page]:shadow-raised-current",
65
75
  // The gliding indicator carries the focus edge once it is placed.
66
76
  "group-data-glide/pagination:aria-[current=page]:shadow-raised"),
67
77
  }) }, p)) : (_jsx("li", { "aria-hidden": true, "data-slot": "pagination-ellipsis", className: cn("inline-flex items-center justify-center font-mono text-[13px] text-muted-foreground", square), children: "\u2026" }, p))), _jsx("li", { children: control(current + 1, _jsx(ChevronRightIcon, { className: "rtl:-scale-x-100" }), {
68
- "aria-label": labels?.next ?? "Next page",
78
+ "aria-label": text.next,
79
+ className: arrow,
69
80
  }) })] })] }));
70
81
  }
@@ -5,6 +5,67 @@ import { type PdfSource } from "../lib/pdf.js";
5
5
  * it, `fit-page` shows whole pages, or a factor (1 = 100%, the printed size).
6
6
  */
7
7
  export type PdfZoom = "auto" | "fit-width" | "fit-page" | number;
8
+ /** Why a PDF couldn't be opened. */
9
+ export type PdfError = "password" | "invalid" | "missing" | "empty" | "unknown";
10
+ export interface PdfViewerMessages {
11
+ /** Why it couldn't be opened, under the title `cantOpen`. */
12
+ error: (reason: PdfError) => string;
13
+ cantOpen: string;
14
+ downloadFile: string;
15
+ /** The toolbar's name. */
16
+ toolbar: string;
17
+ showSidebar: string;
18
+ hideSidebar: string;
19
+ previousPage: string;
20
+ nextPage: string;
21
+ /** The page field, and what is read after it: "of 12 pages". */
22
+ pageField: string;
23
+ ofPages: (count: number) => string;
24
+ zoomIn: string;
25
+ zoomOut: string;
26
+ /** The zoom menu's button, with the zoom as a percentage. */
27
+ zoom: (percent: number) => string;
28
+ zoomAuto: string;
29
+ zoomFitWidth: string;
30
+ zoomFitPage: string;
31
+ rotate: string;
32
+ search: string;
33
+ download: string;
34
+ print: string;
35
+ fullScreen: string;
36
+ exitFullScreen: string;
37
+ /** The rail's tabs and what they hold. */
38
+ sidebar: string;
39
+ pages: string;
40
+ outline: string;
41
+ /** The scrolling pages' name. */
42
+ document: (name: string, page: number, count: number) => string;
43
+ /** A thumbnail. */
44
+ page: (page: number) => string;
45
+ /** An outline entry's toggle. */
46
+ expand: (title: string) => string;
47
+ collapse: (title: string) => string;
48
+ /** A link on a page: to a web address, or to another page. */
49
+ link: (address: string) => string;
50
+ goToPage: (page: number) => string;
51
+ /** The search field: its name and placeholder, the matches and its buttons. */
52
+ searchField: string;
53
+ matches: (index: number, total: number) => string;
54
+ noMatches: string;
55
+ previousMatch: string;
56
+ nextMatch: string;
57
+ closeSearch: string;
58
+ /** PdfPreview's line under the title, and its dialog's close button. */
59
+ previewPages: (count: number) => string;
60
+ previewError: string;
61
+ previewPdf: string;
62
+ close: string;
63
+ }
64
+ declare module "./locale" {
65
+ interface Messages {
66
+ pdfViewer: PdfViewerMessages;
67
+ }
68
+ }
8
69
  declare const viewerVariants: {
9
70
  readonly region: "surface-container";
10
71
  readonly card: "surface-card overflow-hidden [--card-padding:0]";
@@ -34,6 +95,8 @@ export interface PdfViewerProps extends Omit<React.ComponentProps<"div">, "child
34
95
  fullscreen?: boolean;
35
96
  /** Extra toolbar items at the end, e.g. a close button in a dialog. */
36
97
  toolbarEnd?: React.ReactNode;
98
+ /** The reader's words; a LocaleProvider sets them for every PdfViewer and PdfPreview. */
99
+ labels?: Partial<PdfViewerMessages>;
37
100
  }
38
101
  /**
39
102
  * PdfViewer — a full reader for PDF documents: pages drawn by pdf.js with selectable text, a
@@ -44,7 +107,7 @@ export interface PdfViewerProps extends Omit<React.ComponentProps<"div">, "child
44
107
  * The rule people break: putting a viewer where a link would do — for a document people only
45
108
  * download, link to it; for a glance, use `PdfPreview`.
46
109
  */
47
- export declare function PdfViewer({ src, fileName, variant, defaultZoom, defaultPage, onPageChange, thumbnails, defaultThumbnailsOpen, search, download, print, fullscreen: allowFullscreen, toolbarEnd, className, onKeyDown, ...props }: PdfViewerProps): React.JSX.Element;
110
+ export declare function PdfViewer(props: PdfViewerProps): React.JSX.Element;
48
111
  export interface PdfPreviewProps extends Omit<React.ComponentProps<"button">, "children" | "title"> {
49
112
  src: PdfSource;
50
113
  /** Used for downloads; also the title when none is given. */
@@ -55,6 +118,8 @@ export interface PdfPreviewProps extends Omit<React.ComponentProps<"button">, "c
55
118
  description?: React.ReactNode;
56
119
  /** Props for the viewer that opens. */
57
120
  viewer?: Omit<PdfViewerProps, "src" | "fileName" | "variant" | "toolbarEnd">;
121
+ /** The card's and the reader's words; a LocaleProvider sets them for every PdfPreview. */
122
+ labels?: Partial<PdfViewerMessages>;
58
123
  }
59
124
  /**
60
125
  * PdfPreview — a compact card with a document's first page, its name and its length. Clicking it
@@ -65,5 +130,5 @@ export interface PdfPreviewProps extends Omit<React.ComponentProps<"button">, "c
65
130
  * people break: a grid of previews for documents nobody needs to recognise by their cover — a
66
131
  * list of names is quicker to scan.
67
132
  */
68
- export declare function PdfPreview({ src, fileName, title, description, viewer, className, ...props }: PdfPreviewProps): React.JSX.Element;
133
+ export declare function PdfPreview({ src, fileName, title, description, viewer, labels, className, ...props }: PdfPreviewProps): React.JSX.Element;
69
134
  export {};
@@ -11,21 +11,74 @@ import { Dialog, DialogClose, DialogContent, DialogTitle, DialogTrigger } from "
11
11
  import { Empty, EmptyActions, EmptyDescription, EmptyMedia, EmptyTitle } from "./empty.js";
12
12
  import { Input } from "./input.js";
13
13
  import { InputGroup, InputGroupAddon, InputGroupButton, InputGroupInput, InputGroupText, } from "./input-group.js";
14
+ import { useMessages } from "./locale.js";
14
15
  import { Menu, MenuContent, MenuRadioGroup, MenuRadioItem, MenuSeparator, MenuTrigger } from "./menu.js";
15
16
  import { ScrollArea } from "./scroll-area.js";
16
17
  import { Spinner } from "./spinner.js";
17
18
  import { Tabs, TabsList, TabsTab } from "./tabs.js";
18
19
  import { Toolbar, ToolbarButton, ToolbarGroup, ToolbarSeparator } from "./toolbar.js";
19
20
  import { Tooltip, TooltipContent, TooltipTrigger } from "./tooltip.js";
21
+ const errors = {
22
+ password: "This PDF is protected with a password.",
23
+ invalid: "This file isn't a readable PDF.",
24
+ missing: "The file couldn't be loaded.",
25
+ empty: "This PDF has no pages.",
26
+ unknown: "Something went wrong while opening it.",
27
+ };
28
+ const defaultMessages = {
29
+ error: (reason) => errors[reason],
30
+ cantOpen: "This PDF couldn't be opened",
31
+ downloadFile: "Download the file",
32
+ toolbar: "Document",
33
+ showSidebar: "Show sidebar",
34
+ hideSidebar: "Hide sidebar",
35
+ previousPage: "Previous page",
36
+ nextPage: "Next page",
37
+ pageField: "Page",
38
+ ofPages: (count) => `of ${count} pages`,
39
+ zoomIn: "Zoom in",
40
+ zoomOut: "Zoom out",
41
+ zoom: (percent) => `Zoom, ${percent}%`,
42
+ zoomAuto: "Automatic",
43
+ zoomFitWidth: "Fit width",
44
+ zoomFitPage: "Fit page",
45
+ rotate: "Rotate",
46
+ search: "Search",
47
+ download: "Download",
48
+ print: "Print",
49
+ fullScreen: "Full screen",
50
+ exitFullScreen: "Exit full screen",
51
+ sidebar: "Sidebar",
52
+ pages: "Pages",
53
+ outline: "Outline",
54
+ document: (name, page, count) => `${name}, page ${page} of ${count}`,
55
+ page: (page) => `Page ${page}`,
56
+ expand: (title) => `Expand ${title}`,
57
+ collapse: (title) => `Collapse ${title}`,
58
+ link: (address) => `${address} (opens in a new tab)`,
59
+ goToPage: (page) => `Go to page ${page}`,
60
+ searchField: "Search in document",
61
+ matches: (index, total) => `${index} / ${total}`,
62
+ noMatches: "No matches",
63
+ previousMatch: "Previous match",
64
+ nextMatch: "Next match",
65
+ closeSearch: "Close search",
66
+ previewPages: (count) => `PDF · ${count} ${count === 1 ? "page" : "pages"}`,
67
+ previewError: "PDF · can't be opened",
68
+ previewPdf: "PDF",
69
+ close: "Close",
70
+ };
71
+ /** The nearest viewer's words, for its parts. */
72
+ const TextContext = React.createContext(defaultMessages);
20
73
  function describeError(error) {
21
74
  const name = error?.name;
22
75
  if (name === "PasswordException")
23
- return "This PDF is protected with a password.";
76
+ return "password";
24
77
  if (name === "InvalidPDFException")
25
- return "This file isn't a readable PDF.";
78
+ return "invalid";
26
79
  if (name === "ResponseException" || name === "MissingPDFException")
27
- return "The file couldn't be loaded.";
28
- return "Something went wrong while opening it.";
80
+ return "missing";
81
+ return "unknown";
29
82
  }
30
83
  /** Open a document while `enabled`; it is destroyed when the source changes or the view goes. */
31
84
  function usePdfDocument(src, enabled = true) {
@@ -46,7 +99,7 @@ function usePdfDocument(src, enabled = true) {
46
99
  // Nothing to show is a file that can't be shown, not an empty reader.
47
100
  if (!doc.numPages) {
48
101
  if (alive)
49
- setState({ status: "error", message: "This PDF has no pages." });
102
+ setState({ status: "error", reason: "empty" });
50
103
  return;
51
104
  }
52
105
  const sizes = await Promise.all(Array.from({ length: doc.numPages }, (_, i) => doc.getPage(i + 1).then((page) => {
@@ -58,7 +111,7 @@ function usePdfDocument(src, enabled = true) {
58
111
  })
59
112
  .catch((error) => {
60
113
  if (alive)
61
- setState({ status: "error", message: describeError(error) });
114
+ setState({ status: "error", reason: describeError(error) });
62
115
  });
63
116
  return () => {
64
117
  alive = false;
@@ -249,6 +302,7 @@ async function printPdf(doc) {
249
302
  }, 60_000);
250
303
  }
251
304
  const PageView = React.memo(function PageView({ doc, n, size, rotation, scale, renderScale, near, hits, current, onCurrent, onLink, register, }) {
305
+ const text = React.useContext(TextContext);
252
306
  const art = React.useRef(null);
253
307
  const textHost = React.useRef(null);
254
308
  const layer = React.useRef(null);
@@ -391,7 +445,7 @@ const PageView = React.memo(function PageView({ doc, n, size, rotation, scale, r
391
445
  }, children: [_jsx("div", { ref: art, className: "absolute inset-0" }), _jsx("div", { ref: textHost, className: "absolute inset-0" }), links.map((link, i) => {
392
446
  const box = turnBox(link, rotation);
393
447
  const style = { left: pct(box.x), top: pct(box.y), width: pct(box.w), height: pct(box.h) };
394
- return "url" in link ? (_jsx("a", { "data-slot": "pdf-viewer-link", href: link.url, target: "_blank", rel: "noopener noreferrer", "aria-label": `${link.url.replace(/^(https?:\/\/|mailto:)/, "").replace(/\/$/, "")} (opens in a new tab)`, style: style }, i)) : (_jsx("a", { "data-slot": "pdf-viewer-link", href: `#page=${link.target.page}`, "aria-label": `Go to page ${link.target.page}`, onClick: (e) => {
448
+ return "url" in link ? (_jsx("a", { "data-slot": "pdf-viewer-link", href: link.url, target: "_blank", rel: "noopener noreferrer", "aria-label": text.link(link.url.replace(/^(https?:\/\/|mailto:)/, "").replace(/\/$/, "")), style: style }, i)) : (_jsx("a", { "data-slot": "pdf-viewer-link", href: `#page=${link.target.page}`, "aria-label": text.goToPage(link.target.page), onClick: (e) => {
395
449
  e.preventDefault();
396
450
  onLink(link.target);
397
451
  }, style: style }, i));
@@ -400,6 +454,7 @@ const PageView = React.memo(function PageView({ doc, n, size, rotation, scale, r
400
454
  /* ── Thumbnail ──────────────────────────────────────────────────────────────── */
401
455
  const THUMB_W = 104;
402
456
  const Thumbnail = React.memo(function Thumbnail({ doc, n, size, rotation, current, onSelect, }) {
457
+ const text = React.useContext(TextContext);
403
458
  const ref = React.useRef(null);
404
459
  const art = React.useRef(null);
405
460
  const [seen, setSeen] = React.useState(false);
@@ -445,18 +500,19 @@ const Thumbnail = React.memo(function Thumbnail({ doc, n, size, rotation, curren
445
500
  else if (r.bottom > v.bottom)
446
501
  rail.scrollTop += r.bottom - v.bottom;
447
502
  }, [current]);
448
- return (_jsxs("button", { ref: ref, type: "button", "data-slot": "pdf-viewer-thumbnail", "aria-label": `Page ${n}`, "aria-current": current ? "page" : undefined, onClick: () => onSelect(n), className: "relative flex shrink-0 cursor-pointer rounded-item material-row p-1.5 focus-ring", children: [_jsx("span", { ref: art, "aria-hidden": true, "data-slot": "pdf-viewer-thumbnail-page", "data-drawn": drawn ? "" : undefined, className: "relative block overflow-hidden bg-white", style: { width: THUMB_W, height: Math.round((THUMB_W * size.h) / size.w) } }), _jsx("span", { "aria-hidden": true, "data-slot": "pdf-viewer-thumbnail-number", className: cn("theme-light absolute right-2.5 bottom-2.5 rounded-checkbox border px-1 font-mono text-[10px] leading-3.5 tabular-nums", current
503
+ return (_jsxs("button", { ref: ref, type: "button", "data-slot": "pdf-viewer-thumbnail", "aria-label": text.page(n), "aria-current": current ? "page" : undefined, onClick: () => onSelect(n), className: "relative flex shrink-0 cursor-pointer rounded-item material-row p-1.5 focus-ring", children: [_jsx("span", { ref: art, "aria-hidden": true, "data-slot": "pdf-viewer-thumbnail-page", "data-drawn": drawn ? "" : undefined, className: "relative block overflow-hidden bg-white", style: { width: THUMB_W, height: Math.round((THUMB_W * size.h) / size.w) } }), _jsx("span", { "aria-hidden": true, "data-slot": "pdf-viewer-thumbnail-number", className: cn("theme-light absolute end-2.5 bottom-2.5 rounded-checkbox border px-1 font-mono text-[10px] leading-3.5 tabular-nums", current
449
504
  ? "border-foreground bg-foreground text-background"
450
- : "border-border bg-background/90 text-muted-foreground"), children: String(n).padStart(2, "0") })] }));
505
+ : "border-border bg-background/90 text-muted-foreground"), children: n })] }));
451
506
  });
452
507
  /* ── Outline ────────────────────────────────────────────────────────────────── */
453
508
  function OutlineList({ entries, current, onSelect, }) {
454
509
  return (_jsx("ul", { className: "m-0 flex list-none flex-col gap-0.5 p-0", children: entries.map((entry, i) => (_jsx(OutlineRow, { entry: entry, current: current, onSelect: onSelect }, i))) }));
455
510
  }
456
511
  function OutlineRow({ entry, current, onSelect, }) {
512
+ const text = React.useContext(TextContext);
457
513
  const [open, setOpen] = React.useState(true);
458
514
  const nested = entry.children.length > 0;
459
- return (_jsxs("li", { className: "flex flex-col gap-0.5", children: [_jsxs("div", { className: "flex items-center", children: [nested ? (_jsx("button", { type: "button", "aria-label": `${open ? "Collapse" : "Expand"} ${entry.title}`, "aria-expanded": open, onClick: () => setOpen((o) => !o), className: "flex size-6 shrink-0 cursor-pointer items-center justify-center rounded-checkbox text-muted-foreground focus-ring transition-colors duration-(--duration) ease-(--ease) hover:text-foreground", children: _jsx(ChevronRightIcon, { "aria-hidden": true, className: cn("size-3.5 transition-transform duration-(--duration) ease-(--ease) motion-reduce:transition-none rtl:-scale-x-100", open && "rotate-90 rtl:-rotate-90") }) })) : (_jsx("span", { "aria-hidden": true, className: "w-6 shrink-0" })), _jsxs("button", { type: "button", disabled: !entry.target && !entry.url, "aria-current": entry === current ? "true" : undefined, onClick: () => onSelect(entry), className: "flex min-h-(--control-h-sm) min-w-0 flex-1 cursor-pointer items-center gap-2 rounded-item material-row px-2 text-start text-[13px] leading-tight focus-ring disabled:cursor-default disabled:opacity-60", children: [_jsx("span", { className: "min-w-0 flex-1 truncate", children: entry.title }), entry.target && (_jsx("span", { className: "font-mono text-[11px] text-muted-foreground tabular-nums", children: String(entry.target.page).padStart(2, "0") }))] })] }), nested && open && (_jsx("div", { className: "pl-4", children: _jsx(OutlineList, { entries: entry.children, current: current, onSelect: onSelect }) }))] }));
515
+ return (_jsxs("li", { className: "flex flex-col gap-0.5", children: [_jsxs("div", { className: "flex items-center", children: [nested ? (_jsx("button", { type: "button", "aria-label": open ? text.collapse(entry.title) : text.expand(entry.title), "aria-expanded": open, onClick: () => setOpen((o) => !o), className: "flex size-6 shrink-0 cursor-pointer items-center justify-center rounded-checkbox text-muted-foreground focus-ring transition-colors duration-(--duration) ease-(--ease) hover:text-foreground", children: _jsx(ChevronRightIcon, { "aria-hidden": true, className: cn("size-3.5 transition-transform duration-(--duration) ease-(--ease) motion-reduce:transition-none rtl:-scale-x-100", open && "rotate-90 rtl:-rotate-90") }) })) : (_jsx("span", { "aria-hidden": true, className: "w-6 shrink-0" })), _jsxs("button", { type: "button", disabled: !entry.target && !entry.url, "aria-current": entry === current ? "true" : undefined, onClick: () => onSelect(entry), className: "flex min-h-(--control-h-sm) min-w-0 flex-1 cursor-pointer items-center gap-2 rounded-item material-row px-2 text-start text-[13px] leading-tight focus-ring disabled:cursor-default disabled:opacity-60", children: [_jsx("span", { className: "min-w-0 flex-1 truncate", children: entry.title }), entry.target && (_jsx("span", { className: "font-mono text-[11px] text-muted-foreground tabular-nums", children: String(entry.target.page).padStart(2, "0") }))] })] }), nested && open && (_jsx("div", { className: "ps-4", children: _jsx(OutlineList, { entries: entry.children, current: current, onSelect: onSelect }) }))] }));
460
516
  }
461
517
  /* ── Viewer ─────────────────────────────────────────────────────────────────── */
462
518
  const ZOOM_STEPS = [0.5, 0.75, 1, 1.25, 1.5, 2, 3, 4];
@@ -480,7 +536,13 @@ function Tool({ label, children, ...props }) {
480
536
  * The rule people break: putting a viewer where a link would do — for a document people only
481
537
  * download, link to it; for a glance, use `PdfPreview`.
482
538
  */
483
- export function PdfViewer({ src, fileName, variant = "region", defaultZoom = "auto", defaultPage = 1, onPageChange, thumbnails = true, defaultThumbnailsOpen = true, search = true, download = true, print = true, fullscreen: allowFullscreen = true, toolbarEnd, className, onKeyDown, ...props }) {
539
+ export function PdfViewer(props) {
540
+ // The parts read the words from here: the reader, its pages, thumbnails and outline.
541
+ const text = useMessages("pdfViewer", defaultMessages, props.labels);
542
+ return (_jsx(TextContext.Provider, { value: text, children: _jsx(Reader, { ...props }) }));
543
+ }
544
+ function Reader({ src, fileName, variant = "region", defaultZoom = "auto", defaultPage = 1, onPageChange, thumbnails = true, defaultThumbnailsOpen = true, search = true, download = true, print = true, fullscreen: allowFullscreen = true, toolbarEnd, labels: _labels, className, onKeyDown, ...props }) {
545
+ const text = React.useContext(TextContext);
484
546
  const state = usePdfDocument(src);
485
547
  const doc = state.status === "ready" ? state.doc : undefined;
486
548
  const [rotation, setRotation] = React.useState(0);
@@ -838,7 +900,7 @@ export function PdfViewer({ src, fileName, variant = "region", defaultZoom = "au
838
900
  sizes?.map((size, i) => (_jsx(Thumbnail, { doc: doc, n: i + 1, size: size, rotation: rotation, current: page === i + 1, onSelect: goTo }, i))), [doc, sizes, rotation, page, goTo]);
839
901
  return (_jsxs("div", { ref: root, "data-slot": "pdf-viewer", "data-variant": variant, "data-fullscreen": isFullscreen ? "" : undefined, "aria-busy": state.status === "idle" || state.status === "loading", onKeyDown: handleKeyDown, className: cn("@container/pdf relative flex h-[min(80svh,46rem)] min-h-0 w-full min-w-0 flex-col font-body", viewerVariants[variant], className,
840
902
  // Last, so filling the window beats a height given in `className`.
841
- isFullscreen && "fixed inset-0 z-50 h-svh w-screen rounded-none border-0 bg-background"), ...props, children: [_jsx("div", { "data-slot": "pdf-viewer-header", className: "flex shrink-0 items-center border-b border-border/60 p-1.5", children: state.status === "error" ? (_jsxs(Toolbar, { "data-slot": "pdf-viewer-toolbar", "aria-label": "Document", className: "w-full min-w-0", children: [_jsxs("span", { className: "flex min-h-(--control-h-sm) min-w-0 flex-1 items-center gap-2 px-2 font-mono text-xs text-muted-foreground", children: [_jsx(FileWarningIcon, { "aria-hidden": true, className: "size-4 shrink-0" }), _jsx("span", { className: "truncate", children: name })] }), toolbarEnd && _jsx(ToolbarGroup, { className: "ml-auto", children: toolbarEnd })] })) : (_jsxs(Toolbar, { "data-slot": "pdf-viewer-toolbar", "aria-label": "Document", className: "w-full min-w-0 flex-wrap", children: [thumbnails && (_jsxs(_Fragment, { children: [_jsx(Tool, { label: railOpen ? "Hide sidebar" : "Show sidebar", "aria-pressed": railOpen, disabled: !ready, onClick: () => setRailOpen((o) => !o), className: "hidden @3xl/pdf:inline-flex", children: _jsx(PanelLeftIcon, { "aria-hidden": true }) }), _jsx(ToolbarSeparator, { className: "hidden @3xl/pdf:block" })] })), _jsxs(ToolbarGroup, { children: [_jsx(Tool, { label: "Previous page", disabled: !ready || page <= 1, onClick: () => goTo(page - 1), className: "hidden @min-[25rem]/pdf:inline-flex", children: _jsx(ChevronLeftIcon, { "aria-hidden": true, className: "rtl:-scale-x-100" }) }), _jsxs("span", { className: "flex items-center gap-1.5 px-1 font-mono text-xs text-muted-foreground tabular-nums", children: [_jsx(BaseToolbar.Input, { "aria-label": "Page", disabled: !ready, inputMode: "numeric", value: pageDraft ?? String(page), onChange: (e) => setPageDraft(e.currentTarget.value.replace(/\D/g, "")), onFocus: (e) => e.currentTarget.select(), onBlur: commitPage, onKeyDown: (e) => {
903
+ isFullscreen && "fixed inset-0 z-50 h-svh w-screen rounded-none border-0 bg-background"), ...props, children: [_jsx("div", { "data-slot": "pdf-viewer-header", className: "flex shrink-0 items-center border-b border-border/60 p-1.5", children: state.status === "error" ? (_jsxs(Toolbar, { "data-slot": "pdf-viewer-toolbar", "aria-label": text.toolbar, className: "w-full min-w-0", children: [_jsxs("span", { className: "flex min-h-(--control-h-sm) min-w-0 flex-1 items-center gap-2 px-2 font-mono text-xs text-muted-foreground", children: [_jsx(FileWarningIcon, { "aria-hidden": true, className: "size-4 shrink-0" }), _jsx("span", { className: "truncate", children: name })] }), toolbarEnd && _jsx(ToolbarGroup, { className: "ms-auto", children: toolbarEnd })] })) : (_jsxs(Toolbar, { "data-slot": "pdf-viewer-toolbar", "aria-label": text.toolbar, className: "w-full min-w-0 flex-wrap", children: [thumbnails && (_jsxs(_Fragment, { children: [_jsx(Tool, { label: railOpen ? text.hideSidebar : text.showSidebar, "aria-pressed": railOpen, disabled: !ready, onClick: () => setRailOpen((o) => !o), className: "hidden @3xl/pdf:inline-flex", children: _jsx(PanelLeftIcon, { "aria-hidden": true, className: "rtl:-scale-x-100" }) }), _jsx(ToolbarSeparator, { className: "hidden @3xl/pdf:block" })] })), _jsxs(ToolbarGroup, { children: [_jsx(Tool, { label: text.previousPage, disabled: !ready || page <= 1, onClick: () => goTo(page - 1), className: "hidden @min-[25rem]/pdf:inline-flex", children: _jsx(ChevronLeftIcon, { "aria-hidden": true, className: "rtl:-scale-x-100" }) }), _jsxs("span", { className: "flex items-center gap-1.5 px-1 font-mono text-xs text-muted-foreground tabular-nums", children: [_jsx(BaseToolbar.Input, { "aria-label": text.pageField, disabled: !ready, inputMode: "numeric", value: pageDraft ?? String(page), onChange: (e) => setPageDraft(e.currentTarget.value.replace(/\D/g, "")), onFocus: (e) => e.currentTarget.select(), onBlur: commitPage, onKeyDown: (e) => {
842
904
  if (e.key === "Enter") {
843
905
  // Not a submit of a form the viewer sits in.
844
906
  e.preventDefault();
@@ -849,10 +911,10 @@ export function PdfViewer({ src, fileName, variant = "region", defaultZoom = "au
849
911
  e.stopPropagation();
850
912
  setPageDraft(null);
851
913
  }
852
- }, render: _jsx(Input, { size: "sm", className: "w-11 px-1 text-center font-mono tabular-nums" }) }), _jsx("span", { "aria-hidden": true, children: "/" }), _jsx("span", { "aria-label": `of ${count} pages`, children: count || "–" })] }), _jsx(Tool, { label: "Next page", disabled: !ready || page >= count, onClick: () => goTo(page + 1), className: "hidden @min-[25rem]/pdf:inline-flex", children: _jsx(ChevronRightIcon, { "aria-hidden": true, className: "rtl:-scale-x-100" }) })] }), _jsx(ToolbarSeparator, {}), _jsxs(ToolbarGroup, { children: [_jsx(Tool, { label: "Zoom out", disabled: !ready || scale <= 0.26, onClick: () => zoomBy(-1), className: "hidden @md/pdf:inline-flex", children: _jsx(MinusIcon, { "aria-hidden": true }) }), _jsxs(Menu, { children: [_jsxs(ToolbarButton, { disabled: !ready, "aria-label": `Zoom, ${Math.round(scale * 100)}%`, render: _jsx(MenuTrigger, {}), className: "w-16 gap-1 px-1.5 font-mono text-xs tabular-nums", children: [Math.round(scale * 100), "%", _jsx(ChevronDownIcon, { "aria-hidden": true, className: "size-3!" })] }), _jsx(MenuContent, { align: "center", children: _jsxs(MenuRadioGroup, { value: zoomValue, onValueChange: (v) => zoomTo(v === "auto" || v === "fit-width" || v === "fit-page" ? v : Number(v)), children: [_jsx(MenuRadioItem, { value: "auto", closeOnClick: true, children: "Automatic" }), _jsx(MenuRadioItem, { value: "fit-width", closeOnClick: true, children: "Fit width" }), _jsx(MenuRadioItem, { value: "fit-page", closeOnClick: true, children: "Fit page" }), _jsx(MenuSeparator, {}), ZOOM_STEPS.map((z) => (_jsxs(MenuRadioItem, { value: String(z), closeOnClick: true, className: "font-mono tabular-nums", children: [Math.round(z * 100), "%"] }, z)))] }) })] }), _jsx(Tool, { label: "Zoom in", disabled: !ready || scale >= 4.99, onClick: () => zoomBy(1), className: "hidden @md/pdf:inline-flex", children: _jsx(PlusIcon, { "aria-hidden": true }) })] }), _jsx(ToolbarSeparator, { className: "hidden @lg/pdf:block" }), _jsx(Tool, { label: "Rotate", disabled: !ready, onClick: rotate, className: "hidden @lg/pdf:inline-flex", children: _jsx(RotateCwIcon, { "aria-hidden": true }) }), _jsx("span", { className: "hidden min-w-0 flex-1 truncate px-2 text-center font-mono text-xs text-muted-foreground @2xl/pdf:block", children: name }), _jsxs(ToolbarGroup, { className: "ml-auto @2xl/pdf:ml-0", children: [search && (_jsx(Tool, { label: "Search", "aria-pressed": searchOpen, disabled: !ready, onClick: () => (searchOpen ? closeSearch() : openSearch()), children: _jsx(SearchIcon, { "aria-hidden": true }) })), download && (_jsx(Tool, { label: "Download", disabled: !ready, onClick: () => doc && void savePdf(doc, name), children: _jsx(DownloadIcon, { "aria-hidden": true }) })), print && (_jsx(Tool, { label: "Print", disabled: !ready, onClick: () => doc && void printPdf(doc), className: "hidden @lg/pdf:inline-flex", children: _jsx(PrinterIcon, { "aria-hidden": true }) })), allowFullscreen && (_jsx(Tool, { label: isFullscreen ? "Exit full screen" : "Full screen", onClick: toggleFullscreen, children: isFullscreen ? _jsx(MinimizeIcon, { "aria-hidden": true }) : _jsx(MaximizeIcon, { "aria-hidden": true }) })), toolbarEnd] })] })) }), _jsxs("div", { className: "flex min-h-0 flex-1", children: [thumbnails && railOpen && doc && sizes && (_jsxs("div", { "data-slot": "pdf-viewer-rail", className: cn("hidden shrink-0 flex-col border-r border-border/60 @3xl/pdf:flex", showOutline ? "w-60" : "w-[136px]"), children: [outline && (_jsx(Tabs, { value: railTab, onValueChange: (v) => setRailTab(v), className: "w-auto shrink-0 gap-0 border-b border-border/60 p-1.5", children: _jsx(TabsList, { "aria-label": "Sidebar", className: "w-full", children: [
853
- ["pages", "Pages", LayoutGridIcon],
854
- ["outline", "Outline", ListTreeIcon],
855
- ].map(([value, label, Icon]) => (_jsxs(Tooltip, { children: [_jsx(TooltipTrigger, { render: _jsx(TabsTab, { value: value, "aria-label": label, className: "flex-1 px-0" }), children: _jsx(Icon, { "aria-hidden": true }) }), _jsx(TooltipContent, { children: label })] }, value))) }) })), showOutline ? (_jsx(ScrollArea, { "data-slot": "pdf-viewer-outline", scrollbar: false, className: "min-h-0 flex-1", contentClassName: "p-1.5", children: _jsx("nav", { "aria-label": "Outline", children: _jsx(OutlineList, { entries: outline, current: reading, onSelect: openEntry }) }) })) : (_jsx(ScrollArea, { "data-slot": "pdf-viewer-thumbnails", scrollbar: false, "aria-label": "Pages", className: "min-h-0 flex-1", contentClassName: "flex flex-col items-center gap-1.5 py-3", children: thumbnailViews }))] })), _jsxs("div", { className: "relative min-w-0 flex-1", children: [_jsx("div", { ref: viewport, "data-slot": "pdf-viewer-pages", tabIndex: 0, role: "region", "aria-label": count ? `${name}, page ${page} of ${count}` : name, onScroll: onScroll, className: "absolute inset-0 [scrollbar-gutter:stable] overflow-auto overscroll-contain bg-(--field-surface) focus-ring", children: doc && sizes ? (_jsx("div", { className: "mx-auto flex w-max min-w-full flex-col items-center", style: { padding: pad, gap: pad }, children: pageViews })) : state.status === "error" ? (_jsxs(Empty, { className: "h-full justify-center", children: [_jsx(EmptyMedia, { children: _jsx(FileWarningIcon, { "aria-hidden": true }) }), _jsx(EmptyTitle, { children: "This PDF couldn't be opened" }), _jsx(EmptyDescription, { children: state.message }), (typeof src === "string" || src instanceof URL) && (_jsx(EmptyActions, { children: _jsxs(Button, { variant: "secondary", render: _jsx("a", { href: String(src), download: name }), nativeButton: false, children: [_jsx(DownloadIcon, { "aria-hidden": true }), "Download the file"] }) }))] })) : (_jsxs("div", { className: "flex h-full items-center justify-center gap-2.5 font-mono text-xs text-muted-foreground", children: [_jsx(Spinner, { size: "sm" }), "Opening ", name] })) }), searchOpen && (_jsxs("div", { "data-slot": "pdf-viewer-search", role: "search", className: "absolute end-5 top-3 z-20 flex w-[min(24rem,calc(100%-2.5rem))] items-center gap-1 rounded-button material-menu p-1 transition-[opacity,translate] duration-(--duration) ease-(--ease) motion-reduce:transition-none starting:-translate-y-1 starting:opacity-0", children: [_jsxs(InputGroup, { size: "sm", className: "min-w-0 flex-1", children: [_jsx(InputGroupAddon, { className: "pl-2.5", children: _jsx(SearchIcon, { "aria-hidden": true }) }), _jsx(InputGroupInput, { ref: searchInput, "aria-label": "Search in document", placeholder: "Search in document", value: query, onChange: (e) => setQuery(e.currentTarget.value), onKeyDown: (e) => {
914
+ }, render: _jsx(Input, { size: "sm", className: "w-11 px-1 text-center font-mono tabular-nums" }) }), _jsx("span", { "aria-hidden": true, children: "/" }), _jsx("span", { "aria-label": text.ofPages(count), children: count || "–" })] }), _jsx(Tool, { label: text.nextPage, disabled: !ready || page >= count, onClick: () => goTo(page + 1), className: "hidden @min-[25rem]/pdf:inline-flex", children: _jsx(ChevronRightIcon, { "aria-hidden": true, className: "rtl:-scale-x-100" }) })] }), _jsx(ToolbarSeparator, {}), _jsxs(ToolbarGroup, { children: [_jsx(Tool, { label: text.zoomOut, disabled: !ready || scale <= 0.26, onClick: () => zoomBy(-1), className: "hidden @md/pdf:inline-flex", children: _jsx(MinusIcon, { "aria-hidden": true }) }), _jsxs(Menu, { children: [_jsxs(ToolbarButton, { disabled: !ready, "aria-label": text.zoom(Math.round(scale * 100)), render: _jsx(MenuTrigger, {}), className: "w-16 gap-1 px-1.5 font-mono text-xs tabular-nums", children: [Math.round(scale * 100), "%", _jsx(ChevronDownIcon, { "aria-hidden": true, className: "size-3!" })] }), _jsx(MenuContent, { align: "center", children: _jsxs(MenuRadioGroup, { value: zoomValue, onValueChange: (v) => zoomTo(v === "auto" || v === "fit-width" || v === "fit-page" ? v : Number(v)), children: [_jsx(MenuRadioItem, { value: "auto", closeOnClick: true, children: text.zoomAuto }), _jsx(MenuRadioItem, { value: "fit-width", closeOnClick: true, children: text.zoomFitWidth }), _jsx(MenuRadioItem, { value: "fit-page", closeOnClick: true, children: text.zoomFitPage }), _jsx(MenuSeparator, {}), ZOOM_STEPS.map((z) => (_jsxs(MenuRadioItem, { value: String(z), closeOnClick: true, className: "font-mono tabular-nums", children: [Math.round(z * 100), "%"] }, z)))] }) })] }), _jsx(Tool, { label: text.zoomIn, disabled: !ready || scale >= 4.99, onClick: () => zoomBy(1), className: "hidden @md/pdf:inline-flex", children: _jsx(PlusIcon, { "aria-hidden": true }) })] }), _jsx(ToolbarSeparator, { className: "hidden @lg/pdf:block" }), _jsx(Tool, { label: text.rotate, disabled: !ready, onClick: rotate, className: "hidden @lg/pdf:inline-flex", children: _jsx(RotateCwIcon, { "aria-hidden": true }) }), _jsx("span", { className: "hidden min-w-0 flex-1 truncate px-2 text-center font-mono text-xs text-muted-foreground @2xl/pdf:block", children: name }), _jsxs(ToolbarGroup, { className: "ms-auto @2xl/pdf:ms-0", children: [search && (_jsx(Tool, { label: text.search, "aria-pressed": searchOpen, disabled: !ready, onClick: () => (searchOpen ? closeSearch() : openSearch()), children: _jsx(SearchIcon, { "aria-hidden": true }) })), download && (_jsx(Tool, { label: text.download, disabled: !ready, onClick: () => doc && void savePdf(doc, name), children: _jsx(DownloadIcon, { "aria-hidden": true }) })), print && (_jsx(Tool, { label: text.print, disabled: !ready, onClick: () => doc && void printPdf(doc), className: "hidden @lg/pdf:inline-flex", children: _jsx(PrinterIcon, { "aria-hidden": true }) })), allowFullscreen && (_jsx(Tool, { label: isFullscreen ? text.exitFullScreen : text.fullScreen, onClick: toggleFullscreen, children: isFullscreen ? _jsx(MinimizeIcon, { "aria-hidden": true }) : _jsx(MaximizeIcon, { "aria-hidden": true }) })), toolbarEnd] })] })) }), _jsxs("div", { className: "flex min-h-0 flex-1", children: [thumbnails && railOpen && doc && sizes && (_jsxs("div", { "data-slot": "pdf-viewer-rail", className: cn("hidden shrink-0 flex-col border-e border-border/60 @3xl/pdf:flex", showOutline ? "w-60" : "w-[136px]"), children: [outline && (_jsx(Tabs, { value: railTab, onValueChange: (v) => setRailTab(v), className: "w-auto shrink-0 gap-0 border-b border-border/60 p-1.5", children: _jsx(TabsList, { "aria-label": text.sidebar, className: "w-full", children: [
915
+ ["pages", text.pages, LayoutGridIcon],
916
+ ["outline", text.outline, ListTreeIcon],
917
+ ].map(([value, label, Icon]) => (_jsxs(Tooltip, { children: [_jsx(TooltipTrigger, { render: _jsx(TabsTab, { value: value, "aria-label": label, className: "flex-1 px-0" }), children: _jsx(Icon, { "aria-hidden": true }) }), _jsx(TooltipContent, { children: label })] }, value))) }) })), showOutline ? (_jsx(ScrollArea, { "data-slot": "pdf-viewer-outline", scrollbar: false, className: "min-h-0 flex-1", contentClassName: "p-1.5", children: _jsx("nav", { "aria-label": text.outline, children: _jsx(OutlineList, { entries: outline, current: reading, onSelect: openEntry }) }) })) : (_jsx(ScrollArea, { "data-slot": "pdf-viewer-thumbnails", scrollbar: false, "aria-label": text.pages, className: "min-h-0 flex-1", contentClassName: "flex flex-col items-center gap-1.5 py-3", children: thumbnailViews }))] })), _jsxs("div", { className: "relative min-w-0 flex-1", children: [_jsx("div", { ref: viewport, "data-slot": "pdf-viewer-pages", tabIndex: 0, role: "region", "aria-label": count ? text.document(name, page, count) : name, onScroll: onScroll, className: "absolute inset-0 [scrollbar-gutter:stable] overflow-auto overscroll-contain bg-(--field-surface) focus-ring", children: doc && sizes ? (_jsx("div", { className: "mx-auto flex w-max min-w-full flex-col items-center", style: { padding: pad, gap: pad }, children: pageViews })) : state.status === "error" ? (_jsxs(Empty, { className: "h-full justify-center", children: [_jsx(EmptyMedia, { children: _jsx(FileWarningIcon, { "aria-hidden": true }) }), _jsx(EmptyTitle, { children: text.cantOpen }), _jsx(EmptyDescription, { children: text.error(state.reason) }), (typeof src === "string" || src instanceof URL) && (_jsx(EmptyActions, { children: _jsxs(Button, { variant: "secondary", render: _jsx("a", { href: String(src), download: name }), nativeButton: false, children: [_jsx(DownloadIcon, { "aria-hidden": true }), text.downloadFile] }) }))] })) : (_jsxs("div", { className: "flex h-full items-center justify-center gap-2.5 font-mono text-xs text-muted-foreground", children: [_jsx(Spinner, { size: "sm" }), "Opening ", name] })) }), searchOpen && (_jsxs("div", { "data-slot": "pdf-viewer-search", role: "search", className: "absolute end-5 top-3 z-20 flex w-[min(24rem,calc(100%-2.5rem))] items-center gap-1 rounded-button material-menu p-1 transition-[opacity,translate] duration-(--duration) ease-(--ease) motion-reduce:transition-none starting:-translate-y-1 starting:opacity-0", children: [_jsxs(InputGroup, { size: "sm", className: "min-w-0 flex-1", children: [_jsx(InputGroupAddon, { className: "ps-2.5", children: _jsx(SearchIcon, { "aria-hidden": true }) }), _jsx(InputGroupInput, { ref: searchInput, "aria-label": text.searchField, placeholder: text.searchField, value: query, onChange: (e) => setQuery(e.currentTarget.value), onKeyDown: (e) => {
856
918
  if (e.key === "Enter") {
857
919
  e.preventDefault();
858
920
  step(e.shiftKey ? -1 : 1);
@@ -862,7 +924,11 @@ export function PdfViewer({ src, fileName, variant = "region", defaultZoom = "au
862
924
  e.stopPropagation();
863
925
  closeSearch();
864
926
  }
865
- } }), _jsxs(InputGroupAddon, { align: "inline-end", className: "gap-0.5 pr-0.75", children: [_jsx(InputGroupText, { "aria-live": "polite", className: "pr-1.5 whitespace-nowrap", children: hits === null ? "" : hits.length ? `${hitIndex + 1} / ${hits.length}` : "No matches" }), _jsx(InputGroupButton, { variant: "ghost", size: "icon-sm", "aria-label": "Previous match", disabled: !hits?.length, onClick: () => step(-1), children: _jsx(ChevronUpIcon, { "aria-hidden": true }) }), _jsx(InputGroupButton, { variant: "ghost", size: "icon-sm", "aria-label": "Next match", disabled: !hits?.length, onClick: () => step(1), children: _jsx(ChevronDownIcon, { "aria-hidden": true }) })] })] }), _jsx(Button, { variant: "ghost", size: "icon-sm", "aria-label": "Close search", onClick: closeSearch, children: _jsx(XIcon, { "aria-hidden": true }) })] })), count > 1 && (_jsxs("span", { "aria-hidden": true, "data-slot": "pdf-viewer-page-chip", className: cn("pointer-events-none absolute bottom-4 left-1/2 z-10 -translate-x-1/2 rounded-item material-menu px-2.5 py-1.5 font-mono text-xs leading-none tabular-nums transition-opacity duration-(--duration) ease-(--ease)", chip ? "opacity-100" : "opacity-0"), children: [String(page).padStart(2, "0"), " / ", String(count).padStart(2, "0")] }))] })] })] }));
927
+ } }), _jsxs(InputGroupAddon, { align: "inline-end", className: "gap-0.5 pe-0.75", children: [_jsx(InputGroupText, { "aria-live": "polite", className: "pe-1.5 whitespace-nowrap", children: hits === null
928
+ ? ""
929
+ : hits.length
930
+ ? text.matches(hitIndex + 1, hits.length)
931
+ : text.noMatches }), _jsx(InputGroupButton, { variant: "ghost", size: "icon-sm", "aria-label": text.previousMatch, disabled: !hits?.length, onClick: () => step(-1), children: _jsx(ChevronUpIcon, { "aria-hidden": true }) }), _jsx(InputGroupButton, { variant: "ghost", size: "icon-sm", "aria-label": text.nextMatch, disabled: !hits?.length, onClick: () => step(1), children: _jsx(ChevronDownIcon, { "aria-hidden": true }) })] })] }), _jsx(Button, { variant: "ghost", size: "icon-sm", "aria-label": text.closeSearch, onClick: closeSearch, children: _jsx(XIcon, { "aria-hidden": true }) })] })), count > 1 && (_jsxs("span", { "aria-hidden": true, "data-slot": "pdf-viewer-page-chip", className: cn("pointer-events-none absolute bottom-4 left-1/2 z-10 -translate-x-1/2 rounded-item material-menu px-2.5 py-1.5 font-mono text-xs leading-none tabular-nums transition-opacity duration-(--duration) ease-(--ease)", chip ? "opacity-100" : "opacity-0"), children: [String(page).padStart(2, "0"), " / ", String(count).padStart(2, "0")] }))] })] })] }));
866
932
  }
867
933
  /**
868
934
  * PdfPreview — a compact card with a document's first page, its name and its length. Clicking it
@@ -873,7 +939,8 @@ export function PdfViewer({ src, fileName, variant = "region", defaultZoom = "au
873
939
  * people break: a grid of previews for documents nobody needs to recognise by their cover — a
874
940
  * list of names is quicker to scan.
875
941
  */
876
- export function PdfPreview({ src, fileName, title, description, viewer, className, ...props }) {
942
+ export function PdfPreview({ src, fileName, title, description, viewer, labels, className, ...props }) {
943
+ const text = useMessages("pdfViewer", defaultMessages, labels);
877
944
  const ref = React.useRef(null);
878
945
  const art = React.useRef(null);
879
946
  const [seen, setSeen] = React.useState(false);
@@ -922,8 +989,8 @@ export function PdfPreview({ src, fileName, title, description, viewer, classNam
922
989
  const count = state.status === "ready" ? state.sizes.length : undefined;
923
990
  return (_jsxs(Dialog, { children: [_jsxs(DialogTrigger, { render: _jsx("button", { ref: ref, type: "button", "data-slot": "pdf-preview", "aria-busy": !drawn && state.status !== "error", className: cn("group/preview flex w-full max-w-xs cursor-pointer flex-col overflow-hidden surface-card text-start focus-ring [--card-padding:0]", className), ...props }), children: [_jsxs("span", { "data-slot": "pdf-preview-page", className: "relative block aspect-[4/3] overflow-hidden border-b border-border/60 px-6 pt-6", children: [_jsx("span", { ref: art, "aria-hidden": true, className: "relative block w-full bg-white shadow-card transition-transform duration-(--duration) ease-(--ease) group-hover/preview:-translate-y-1", style: { aspectRatio: first ? `${first.w} / ${first.h}` : "1 / 1.414" } }), state.status === "error" && (_jsx("span", { className: "absolute inset-0 flex items-center justify-center text-muted-foreground", children: _jsx(FileWarningIcon, { "aria-hidden": true, className: "size-6" }) }))] }), _jsxs("span", { className: "flex items-start gap-3 p-4", children: [_jsx(FileTextIcon, { "aria-hidden": true, className: "mt-0.5 size-4 shrink-0 text-muted-foreground" }), _jsxs("span", { className: "flex min-w-0 flex-col gap-1", children: [_jsx("span", { className: "truncate text-sm font-medium text-foreground", children: title ?? name }), _jsx("span", { className: "font-mono text-[11px] tracking-[0.12em] text-muted-foreground uppercase", children: description ??
924
991
  (state.status === "error"
925
- ? "PDF · can't be opened"
992
+ ? text.previewError
926
993
  : count
927
- ? `PDF · ${count} ${count === 1 ? "page" : "pages"}`
928
- : "PDF") })] })] })] }), _jsxs(DialogContent, { size: "xl", showCloseButton: false, className: "h-[min(90svh,60rem)] max-w-[min(72rem,100%)] gap-0 p-0 sm:p-0", children: [_jsx(DialogTitle, { className: "sr-only", children: typeof title === "string" ? title : name }), _jsx(PdfViewer, { ...viewer, src: src, fileName: name, variant: "plain", className: cn("h-full", viewer?.className), toolbarEnd: _jsxs(_Fragment, { children: [_jsx(ToolbarSeparator, {}), _jsxs(Tooltip, { children: [_jsx(TooltipTrigger, { render: _jsx(ToolbarButton, { "aria-label": "Close", render: _jsx(DialogClose, {}) }), children: _jsx(XIcon, { "aria-hidden": true }) }), _jsx(TooltipContent, { children: "Close" })] })] }) })] })] }));
994
+ ? text.previewPages(count)
995
+ : text.previewPdf) })] })] })] }), _jsxs(DialogContent, { size: "xl", showCloseButton: false, className: "h-[min(90svh,60rem)] max-w-[min(72rem,100%)] gap-0 p-0 sm:p-0", children: [_jsx(DialogTitle, { className: "sr-only", children: typeof title === "string" ? title : name }), _jsx(PdfViewer, { labels: labels, ...viewer, src: src, fileName: name, variant: "plain", className: cn("h-full", viewer?.className), toolbarEnd: _jsxs(_Fragment, { children: [_jsx(ToolbarSeparator, {}), _jsxs(Tooltip, { children: [_jsx(TooltipTrigger, { render: _jsx(ToolbarButton, { "aria-label": text.close, render: _jsx(DialogClose, {}) }), children: _jsx(XIcon, { "aria-hidden": true }) }), _jsx(TooltipContent, { children: text.close })] })] }) })] })] }));
929
996
  }
@@ -0,0 +1,79 @@
1
+ import * as React from "react";
2
+ export interface PhoneInputMessages {
3
+ /** The country picker's name, before the country it shows: "Country". */
4
+ country: string;
5
+ /** The search field over the countries. */
6
+ search: string;
7
+ /** Shown when no country matches the search. */
8
+ empty: string;
9
+ /** Read out when typing or pasting a number switches the country. */
10
+ countryChanged: (country: string) => string;
11
+ /** The number has fewer digits than a number in the country: its name and calling code ("44"). */
12
+ tooShort: (country: string, callingCode: string) => string;
13
+ /** The number has more digits than any number in the country. */
14
+ tooLong: (country: string, callingCode: string) => string;
15
+ /** A "+" and digits that start with no calling code. */
16
+ unknownCode: string;
17
+ }
18
+ declare module "./locale" {
19
+ interface Messages {
20
+ phoneInput: PhoneInputMessages;
21
+ }
22
+ }
23
+ declare const sizes: {
24
+ readonly sm: {
25
+ readonly group: "sm";
26
+ readonly button: "sm";
27
+ readonly className: "";
28
+ };
29
+ readonly default: {
30
+ readonly group: "default";
31
+ readonly button: "default";
32
+ readonly className: "";
33
+ };
34
+ readonly lg: {
35
+ readonly group: "default";
36
+ readonly button: "default";
37
+ readonly className: "min-h-(--control-h-lg) text-lg sm:text-lg";
38
+ };
39
+ };
40
+ export interface PhoneInputChangeDetails {
41
+ /** The country the number is in. */
42
+ country: string;
43
+ /** The national number, digits only, without the trunk prefix: "2079460018". */
44
+ nationalNumber: string;
45
+ /** Whether the number has one of the country's lengths. Not whether it is in use. */
46
+ valid: boolean;
47
+ }
48
+ export interface PhoneInputProps extends Omit<React.ComponentProps<"input">, "value" | "defaultValue" | "onChange" | "size" | "type" | "children"> {
49
+ /** The number in E.164: `"+4915112345678"`; `null` while there are no digits. */
50
+ value?: string | null;
51
+ defaultValue?: string | null;
52
+ /** Called as the number changes, with its country and whether its length fits. */
53
+ onValueChange?: (value: string | null, details: PhoneInputChangeDetails) => void;
54
+ /** The country, as an ISO 3166 code ("DE"), when you control it. */
55
+ country?: string;
56
+ /** The country to start in. Default: the value's, else the locale's region, else US. */
57
+ defaultCountry?: string;
58
+ onCountryChange?: (country: string) => void;
59
+ /** Only these countries, as ISO codes, in the picker. Default: every one. */
60
+ countries?: readonly string[];
61
+ /** A BCP 47 locale for the country names. Default: the LocaleProvider's, then the browser's. */
62
+ locale?: string;
63
+ /** `sm` (30px), `default` (38px) or `lg` (46px). */
64
+ size?: keyof typeof sizes;
65
+ /** Interface text; a LocaleProvider sets it for every PhoneInput. */
66
+ labels?: Partial<PhoneInputMessages>;
67
+ }
68
+ /**
69
+ * PhoneInput — an international phone number: a country picker joined to the number in one
70
+ * recessed field. The picker shows the ISO code and the calling code in mono (`DE +49`) and
71
+ * opens a searchable list of countries named in the locale; the number is grouped in mono as it
72
+ * is typed (`163 7568602`). Typing or pasting a full `+44 20 7946 0018` switches the country.
73
+ *
74
+ * The value is E.164 (`"+4915112345678"`), the form every SMS and voice provider takes. Lengths
75
+ * are checked per country against libphonenumber's metadata — a sanity check, not proof the number
76
+ * exists. The rule people break: storing the number as typed. Keep the E.164 value.
77
+ */
78
+ export declare function PhoneInput({ value: valueProp, defaultValue, onValueChange, country: countryProp, defaultCountry, onCountryChange, countries, locale: localeProp, size, labels, id: idProp, name, required, disabled: disabledProp, readOnly, placeholder, className, onFocus, onBlur, onKeyDown, onPaste, ref: refProp, ...props }: PhoneInputProps): React.JSX.Element;
79
+ export {};