@softure-ai/theme-notion 0.17.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.
package/CHANGELOG.md CHANGED
@@ -4,6 +4,19 @@ Newest first. Each version lists what changed for an app that uses the theme. Wh
4
4
  production, the version gets a line `verified in: <app>@<commit>` ([docs/05](../../docs/05-adoption-playbook.md),
5
5
  "Definition of done").
6
6
 
7
+ ## 0.18.0
8
+
9
+ - `DocumentViewer`, `DocumentList`, `DocumentRow` (#1256): documents shown inside the page, never in a new browser
10
+ window. `DocumentViewer` is a full-screen `Dialog` (title, page count, zoom 50 % to 300 % of the fitted width, a
11
+ 44 px close button below the safe area) that draws a PDF's pages into canvases with pdf.js or shows an image, from a
12
+ `Blob` (offline) or a URL; a broken file, a failed fetch or another type shows a message. `DocumentRow` draws one
13
+ document of a `DocumentList`: an icon by type, the title as a touch-sized open button, the size, an "available
14
+ offline" mark and optional actions. `getDocumentKind`, `DOCUMENT_ZOOM_STEPS`, `loadPdfjsEngine` (pdf.js, loaded
15
+ once on first use, its worker code run on the main thread: no worker URL to configure) and the `PdfEngine`
16
+ interface for another engine. Copy in `notionMessages.en.document`.
17
+ - New dependency: `pdfjs-dist` (Apache-2.0), imported only when a PDF opens.
18
+ - Migration: none.
19
+
7
20
  ## 0.17.0
8
21
 
9
22
  - `AsidePanelProvider keepsSidebarOpen`: the left `Sidebar` and the right `AsidePanel` stay open together on a wide
package/README.md CHANGED
@@ -148,6 +148,8 @@ stages with a state, below), `Timeline` (dated entries on a vertical rail, below
148
148
  `UploadField`, `UploadList` and `UploadItem` (pick or drop files, one row per file with progress, retry and remove,
149
149
  below),
150
150
  `FileInput` (a compact file picker for a form row: a button and the chosen file's name, below),
151
+ `DocumentViewer`, `DocumentList` and `DocumentRow` (a PDF's pages or an image shown inside the page, with page count
152
+ and zoom; one row per document with its type, size and an "available offline" mark, below),
151
153
  `FormGrid` (fields side by side whose label, control and hint line up across columns, below).
152
154
 
153
155
  **Touch sizes.** The controls a phone view taps most reach the `touch-target` token (44 px, Apple's HIG and WCAG
@@ -556,6 +558,37 @@ name); `messages` replaces any of it.
556
558
  </UploadList>
557
559
  ```
558
560
 
561
+ **`DocumentViewer`, `DocumentList`, `DocumentRow`.** Documents shown inside the page, never in a new browser window
562
+ (which an installed iOS app cannot come back from offline). `DocumentViewer` is a full-screen `Dialog` with the
563
+ title, the page count, zoom out and in (50 % to 300 % of the fitted width, `DOCUMENT_ZOOM_STEPS`) and a 44 px close
564
+ button. Its `source` is `{ blob }` (a copy kept on the device, e.g. `createKeptFiles(...).find(url)` of
565
+ `@softure-ai/pwa`, shown with no network) or `{ url }` (fetched with the page's cookies, or by `fetchFile`). By
566
+ `contentType`, a PDF's pages are drawn one under the other into canvases by pdf.js (`pdfjs-dist`, Apache-2.0),
567
+ loaded only when the first PDF opens and run on the main thread, so there is no worker URL to configure; an image
568
+ shows from an object URL; another type, a broken file or a failed fetch shows a message instead of a blank screen.
569
+ `loadPdfEngine` takes another `PdfEngine` (`open(bytes)` → `{ pageCount, renderPage(page, canvas, width), destroy }`).
570
+ Call `loadPdfjsEngine()` once while online (e.g. when a page with documents opens): its chunks are ordinary build
571
+ files, so a service worker that keeps `/_next/static/` has them for an offline open later. `DocumentRow` is one
572
+ `li` of a `DocumentList`: an icon by type (`getDocumentKind`), the title as a touch-sized button that calls `onOpen`,
573
+ the size, an "available offline" mark with `isOffline`, and `actions` (e.g. a menu) after it. Every text has a
574
+ `messages` override (`notionMessages.en.document`).
575
+
576
+ ```tsx
577
+ const [opened, setOpened] = useState<Doc | null>(null);
578
+ <DocumentList label="Documents">
579
+ {docs.map((doc) => (
580
+ <DocumentRow key={doc.id} title={doc.name} contentType={doc.type} size={doc.size} isOffline={doc.isKept} onOpen={() => setOpened(doc)} />
581
+ ))}
582
+ </DocumentList>
583
+ <DocumentViewer
584
+ open={opened !== null}
585
+ onOpenChange={(open) => !open && setOpened(null)}
586
+ title={opened?.name ?? ""}
587
+ contentType={opened?.type ?? ""}
588
+ source={opened === null ? null : opened.blob !== null ? { blob: opened.blob } : { url: opened.url }}
589
+ />
590
+ ```
591
+
559
592
  **`FileInput`.** The file picker of a form row, where `UploadField`'s dropping area is too large (one font, one
560
593
  logo). A button at the height of `Input` and the default `SelectTrigger` (28 px) and, beside it, the chosen file's name
561
594
  or "No file chosen", all in the app's words: `notionMessages.en.fileInput` (`choose`, `chooseMany` with `multiple`,
package/dist/index.d.ts CHANGED
@@ -67,6 +67,9 @@ export { Steps, type StepItem, type StepState, type StepsLayout, type StepsProps
67
67
  export { TabBar, type TabBarItem, type TabBarProps } from "./notion/TabBar.js";
68
68
  export { Timeline, type TimelineItem, type TimelineItemFold, type TimelineItemSize, type TimelineLine, type TimelineProps } from "./notion/Timeline.js";
69
69
  export { TopLoadingBar, type TopLoadingBarProps } from "./notion/TopLoadingBar.js";
70
+ export { DOCUMENT_ZOOM_STEPS, getDocumentKind, type DocumentKind } from "./notion/document-kind.js";
71
+ export { DocumentList, DocumentRow, DocumentViewer, type DocumentListProps, type DocumentMessages, type DocumentMessagesOverride, type DocumentRowProps, type DocumentSource, type DocumentViewerProps, } from "./notion/Document.js";
72
+ export { loadPdfjsEngine, type PdfDocumentHandle, type PdfEngine } from "./notion/pdf-engine.js";
70
73
  export { UploadField, UploadItem, UploadList, type UploadFieldProps, type UploadFileItem, type UploadItemProps, type UploadListProps, type UploadMessages, type UploadMessagesOverride, type UploadState, } from "./notion/Upload.js";
71
74
  export { formatFileSize } from "./notion/format-file-size.js";
72
75
  export { UpdatePrompt, type UpdatePromptProps } from "./notion/UpdatePrompt.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AACpC,OAAO,EAAE,cAAc,EAAE,KAAK,cA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,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,sBAAsB,EAC3B,KAAK,WAAW,GACjB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,KAAK,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAChF,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK,IAAI,EAAE,MAAM,mBAAmB,CAAC"}
package/dist/index.js CHANGED
@@ -69,6 +69,9 @@ export { Steps } from "./notion/Steps.js";
69
69
  export { TabBar } from "./notion/TabBar.js";
70
70
  export { Timeline } from "./notion/Timeline.js";
71
71
  export { TopLoadingBar } from "./notion/TopLoadingBar.js";
72
+ export { DOCUMENT_ZOOM_STEPS, getDocumentKind } from "./notion/document-kind.js";
73
+ export { DocumentList, DocumentRow, DocumentViewer, } from "./notion/Document.js";
74
+ export { loadPdfjsEngine } from "./notion/pdf-engine.js";
72
75
  export { UploadField, UploadItem, UploadList, } from "./notion/Upload.js";
73
76
  export { formatFileSize } from "./notion/format-file-size.js";
74
77
  export { UpdatePrompt } from "./notion/UpdatePrompt.js";
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,wGAAwG;AACxG,oGAAoG;AACpG,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AACpC,OAAO,EAAE,cAAc,EAAuB,MAAM,qBAAqB,CAAC;AAE1E,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,sBAAsB,CAAC;AACrC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAA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,mBAAmB,CAAC"}
@@ -65,6 +65,20 @@ export declare const en: {
65
65
  readonly done: "Done";
66
66
  readonly failed: "Failed";
67
67
  };
68
+ readonly document: {
69
+ readonly close: "Close";
70
+ readonly zoomIn: "Zoom in";
71
+ readonly zoomOut: "Zoom out";
72
+ readonly zoom: "{percent}%";
73
+ readonly pageCount: "{count} pages";
74
+ readonly pageCountOne: "1 page";
75
+ readonly page: "Page {number} of {count}";
76
+ readonly loading: "Opening the document";
77
+ readonly failed: "This document cannot be shown.";
78
+ readonly unsupported: "This type of document cannot be shown here.";
79
+ readonly offline: "Available offline";
80
+ readonly open: "Open";
81
+ };
68
82
  readonly steps: {
69
83
  readonly done: "Done";
70
84
  readonly current: "Current";
@@ -1 +1 @@
1
- {"version":3,"file":"en.d.ts","sourceRoot":"","sources":["../../src/messages/en.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,EAAE;aACb,UAAU;iBACR,IAAI,EAAE,gBAAgB;iBACtB,IAAI,EAAE,gBAAgB;iBACtB,KAAK,EAAE,iBAAiB;iBACxB,MAAM,EAAE,kBAAkB;iBAC1B,WAAW,EAAE,kCAAkC;;aAEjD,UAAU;iBAAI,KAAK,EAAE,YAAY;iBAAE,IAAI,EAAE,MAAM;;aAC/C,MAAM;iBAAI,KAAK,EAAE,OAAO;;aACxB,SAAS;iBAAI,MAAM,EAAE,eAAe;iBAAE,UAAU,EAAE,cAAc;iBAAE,IAAI,EAAE,gBAAgB;iBAAE,KAAK,EAAE,eAAe;;aAChH,UAAU;iBAAI,GAAG,EAAE,YAAY;;aAC/B,KAAK;iBAAI,KAAK,EAAE,OAAO;;aACvB,SAAS;iBAAI,KAAK,EAAE,OAAO;;aAC3B,OAAO;iBAAI,WAAW,EAAE,SAAS;iBAAE,iBAAiB,EAAE,8BAA8B;iBAAE,MAAM,EAAE,gBAAgB;;aAC9G,OAAO;iBAAI,KAAK,EAAE,SAAS;;aAC3B,QAAQ;iBACN,YAAY,EACV,mIAAmI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AAE,SAAS;iBAAE,IAAI,EAAE,OAAO;iBAAE,MAAM,EAAE,QAAQ;;aAC1E,OAAO;iBAAI,KAAK,EAAE,iBAAiB;iBAAE,WAAW,EAAE,gCAAgC;;CAC1E,CAAC"}
@@ -43,6 +43,20 @@ export const en = {
43
43
  done: "Done",
44
44
  failed: "Failed",
45
45
  },
46
+ document: {
47
+ close: "Close",
48
+ zoomIn: "Zoom in",
49
+ zoomOut: "Zoom out",
50
+ zoom: "{percent}%",
51
+ pageCount: "{count} pages",
52
+ pageCountOne: "1 page",
53
+ page: "Page {number} of {count}",
54
+ loading: "Opening the document",
55
+ failed: "This document cannot be shown.",
56
+ unsupported: "This type of document cannot be shown here.",
57
+ offline: "Available offline",
58
+ open: "Open",
59
+ },
46
60
  steps: { done: "Done", current: "Current", todo: "To do", failed: "Failed" },
47
61
  command: { title: "Command Palette", description: "Search for a command to run..." },
48
62
  };
@@ -1 +1 @@
1
- {"version":3,"file":"en.js","sourceRoot":"","sources":["../../src/messages/en.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAC,MAAM,EAAE,GAAG;IAChB,UAAU,EAAE;QACV,IAAI,EAAE,gBAAgB;QACtB,IAAI,EAAE,gBAAgB;QACtB,KAAK,EAAE,iBAAiB;QACxB,MAAM,EAAE,kBAAkB;QAC1B,WAAW,EAAE,kCAAkC;KAChD;IACD,UAAU,EAAE,EAAE,KAAK,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,EAAE;IACjD,MAAM,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE;IAC1B,SAAS,EAAE,EAAE,MAAM,EAAE,eAAe,EAAE,UAAU,EAAE,cAAc,EAAE,IAAI,EAAE,gBAAgB,EAAE,KAAK,EAAE,eAAe,EAAE;IAClH,UAAU,EAAE,EAAE,GAAG,EAAE,YAAY,EAAE;IACjC,KAAK,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE;IACzB,SAAS,EAAE,EAAE,KAAK,EAAE,OAAO,EAA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;QAClB,SAAS,EAAE,eAAe;QAC1B,YAAY,EAAE,QAAQ;QACtB,IAAI,EAAE,0BAA0B;QAChC,OAAO,EAAE,sBAAsB;QAC/B,MAAM,EAAE,gCAAgC;QACxC,WAAW,EAAE,6CAA6C;QAC1D,OAAO,EAAE,mBAAmB;QAC5B,IAAI,EAAE,MAAM;KACb;IACD,KAAK,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE;IAC5E,OAAO,EAAE,EAAE,KAAK,EAAE,iBAAiB,EAAE,WAAW,EAAE,gCAAgC,EAAE;CAC5E,CAAC"}
@@ -64,6 +64,20 @@ export declare const notionMessages: {
64
64
  readonly done: "Done";
65
65
  readonly failed: "Failed";
66
66
  };
67
+ readonly document: {
68
+ readonly close: "Close";
69
+ readonly zoomIn: "Zoom in";
70
+ readonly zoomOut: "Zoom out";
71
+ readonly zoom: "{percent}%";
72
+ readonly pageCount: "{count} pages";
73
+ readonly pageCountOne: "1 page";
74
+ readonly page: "Page {number} of {count}";
75
+ readonly loading: "Opening the document";
76
+ readonly failed: "This document cannot be shown.";
77
+ readonly unsupported: "This type of document cannot be shown here.";
78
+ readonly offline: "Available offline";
79
+ readonly open: "Open";
80
+ };
67
81
  readonly steps: {
68
82
  readonly done: "Done";
69
83
  readonly current: "Current";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/messages/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAE7B,qGAAqG;AACrG,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAAS,CAAC;AAErC,MAAM,MAAM,cAAc,GAAG,OAAO,EAAE,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/messages/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAE7B,qGAAqG;AACrG,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAAS,CAAC;AAErC,MAAM,MAAM,cAAc,GAAG,OAAO,EAAE,CAAC"}
@@ -0,0 +1,71 @@
1
+ import { type ReactNode } from "react";
2
+ import { type PdfEngine } from "./pdf-engine.js";
3
+ /** What the viewer shows: the bytes at hand (a kept copy, offline) or a URL it fetches. */
4
+ export type DocumentSource = {
5
+ readonly blob: Blob;
6
+ } | {
7
+ readonly url: string;
8
+ };
9
+ /** The texts of the document parts; `{count}`, `{number}` and `{percent}` are filled in. Built-in English: `notionMessages.en.document`. */
10
+ export interface DocumentMessages {
11
+ readonly close: string;
12
+ readonly zoomIn: string;
13
+ readonly zoomOut: string;
14
+ readonly zoom: string;
15
+ readonly pageCount: string;
16
+ readonly pageCountOne: string;
17
+ readonly page: string;
18
+ readonly loading: string;
19
+ readonly failed: string;
20
+ readonly unsupported: string;
21
+ readonly offline: string;
22
+ /** Read by a screen reader before a row's title. */
23
+ readonly open: string;
24
+ }
25
+ /** The app's wording for the document parts; each text left out keeps the built-in English one. */
26
+ export type DocumentMessagesOverride = Partial<DocumentMessages>;
27
+ export interface DocumentViewerProps {
28
+ readonly open: boolean;
29
+ readonly onOpenChange: (open: boolean) => void;
30
+ /** The document's title, shown on top and as the dialog's name. */
31
+ readonly title: string;
32
+ /** The media type; it decides between PDF pages and an image. */
33
+ readonly contentType: string;
34
+ /** The bytes or the URL; nothing loads while it is `null`. */
35
+ readonly source: DocumentSource | null;
36
+ /** The PDF engine; pdf.js loaded on first use by default. */
37
+ readonly loadPdfEngine?: () => Promise<PdfEngine>;
38
+ /** Reads a URL source; `fetch` with the page's cookies by default. */
39
+ readonly fetchFile?: (url: string) => Promise<Blob>;
40
+ /** Something beside the zoom, e.g. a download link. */
41
+ readonly actions?: ReactNode;
42
+ readonly messages?: DocumentMessagesOverride;
43
+ readonly className?: string;
44
+ }
45
+ export declare function DocumentViewer({ open, onOpenChange, title, contentType, source, loadPdfEngine, fetchFile, actions, messages, className }: DocumentViewerProps): import("react").JSX.Element;
46
+ export interface DocumentListProps {
47
+ /** The list's accessible name, e.g. "Documents". */
48
+ readonly label: string;
49
+ /** `DocumentRow` rows. */
50
+ readonly children: ReactNode;
51
+ readonly className?: string;
52
+ }
53
+ export declare function DocumentList({ label, children, className }: DocumentListProps): import("react").JSX.Element;
54
+ export interface DocumentRowProps {
55
+ readonly title: string;
56
+ readonly contentType: string;
57
+ /** In bytes. */
58
+ readonly size: number;
59
+ /** Whether a copy is kept on the device; draws the "available offline" mark. */
60
+ readonly isOffline?: boolean;
61
+ /** Opens the document, e.g. in `DocumentViewer`. */
62
+ readonly onOpen: () => void;
63
+ /** Buttons after the row, e.g. a menu to rename or remove. */
64
+ readonly actions?: ReactNode;
65
+ /** Formats the size, e.g. "de" writes "1,5 kB". */
66
+ readonly locale?: string;
67
+ readonly messages?: DocumentMessagesOverride;
68
+ readonly className?: string;
69
+ }
70
+ export declare function DocumentRow({ title, contentType, size, isOffline, onOpen, actions, locale, messages, className }: DocumentRowProps): import("react").JSX.Element;
71
+ //# sourceMappingURL=Document.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Document.d.ts","sourceRoot":"","sources":["../../src/notion/Document.tsx"],"names":[],"mappings":"AAGA,OAAO,EAA+B,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAUpE,OAAO,EAA2C,KAAK,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAG1F,2FAA2F;AAC3F,MAAM,MAAM,cAAc,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAA;CAAE,GAAG;IAAE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC;AAEhF,4I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AE,MAAM,EAAE,OAAO,EAAE,MAAa,EAAE,QAAQ,EAAE,SAAS,EAAE,EAAE,gBAAgB,+BA8BjJ"}
@@ -0,0 +1,147 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { CircleCheck, File as FileIcon, FileImage, FileText, LoaderCircle, Minus, Plus, X } from "lucide-react";
4
+ import { useEffect, useRef, useState } from "react";
5
+ import { en } from "../messages/en.js";
6
+ import { cn } from "../lib/utils.js";
7
+ import { Button } from "../ui/button.js";
8
+ import { Dialog, DialogClose, DialogContent, DialogDescription, DialogTitle } from "../ui/dialog.js";
9
+ import { DOCUMENT_ZOOM_STEPS, getDocumentKind } from "./document-kind.js";
10
+ import { formatFileSize } from "./format-file-size.js";
11
+ import { ICON_STROKE_WIDTH } from "./icon-stroke.js";
12
+ import { loadPdfjsEngine } from "./pdf-engine.js";
13
+ import { Status } from "./Status.js";
14
+ function mergeMessages(override) {
15
+ return { ...en.document, ...override };
16
+ }
17
+ function fill(template, values) {
18
+ return template.replaceAll(/\{(\w+)\}/g, (match, key) => (key in values ? String(values[key]) : match));
19
+ }
20
+ const FIT_INDEX = 2;
21
+ /** The width a PDF page fits when the viewer cannot measure its area (a page rendered on the server, a test). */
22
+ const FALLBACK_WIDTH = 800;
23
+ /** The widest a page is drawn at 100 %: a printed page's width on a wide screen, so its lines stay readable. */
24
+ const MAX_FIT_WIDTH = 880;
25
+ /** Reads a URL's bytes as the signed-in user, the way the app's own page would. */
26
+ async function fetchDocument(url) {
27
+ const response = await fetch(url, { credentials: "same-origin" });
28
+ if (!response.ok)
29
+ throw new Error(`DocumentViewer: fetching ${url} answered ${String(response.status)}`);
30
+ return response.blob();
31
+ }
32
+ // A document inside the page, on the whole screen: a PDF's pages drawn one under the other, or an image, with the
33
+ // title, the page count, zoom and a close button. It never opens a new browser window, which an installed phone app
34
+ // cannot come back from offline; with a `Blob` source it needs no network at all.
35
+ export function DocumentViewer({ open, onOpenChange, title, contentType, source, loadPdfEngine = loadPdfjsEngine, fetchFile = fetchDocument, actions, messages, className }) {
36
+ const words = mergeMessages(messages);
37
+ const [loaded, setLoaded] = useState({ state: "loading" });
38
+ const [zoomIndex, setZoomIndex] = useState(FIT_INDEX);
39
+ const kind = getDocumentKind(contentType);
40
+ useEffect(() => {
41
+ if (!open || source === null)
42
+ return undefined;
43
+ if (kind === "other") {
44
+ setLoaded({ state: "unsupported" });
45
+ return undefined;
46
+ }
47
+ let isCurrent = true;
48
+ let release = () => undefined;
49
+ setLoaded({ state: "loading" });
50
+ setZoomIndex(FIT_INDEX);
51
+ void (async () => {
52
+ try {
53
+ const blob = "blob" in source ? source.blob : await fetchFile(source.url);
54
+ if (kind === "image") {
55
+ const url = URL.createObjectURL(blob);
56
+ release = () => URL.revokeObjectURL(url);
57
+ if (isCurrent)
58
+ setLoaded({ state: "image", url });
59
+ else
60
+ release();
61
+ return;
62
+ }
63
+ const engine = await loadPdfEngine();
64
+ const document = await engine.open(await blob.arrayBuffer());
65
+ release = () => document.destroy();
66
+ if (isCurrent)
67
+ setLoaded({ state: "pdf", document });
68
+ else
69
+ release();
70
+ }
71
+ catch {
72
+ if (isCurrent)
73
+ setLoaded({ state: "failed" });
74
+ }
75
+ })();
76
+ return () => {
77
+ isCurrent = false;
78
+ release();
79
+ };
80
+ }, [open, source, kind, loadPdfEngine, fetchFile]);
81
+ const zoom = DOCUMENT_ZOOM_STEPS[zoomIndex] ?? 1;
82
+ const pageCount = loaded.state === "pdf" ? loaded.document.pageCount : null;
83
+ const canZoom = loaded.state === "pdf" || loaded.state === "image";
84
+ return (_jsx(Dialog, { open: open, onOpenChange: onOpenChange, children: _jsxs(DialogContent, { "data-slot": "document-viewer", showCloseButton: false, className: cn("top-0 left-0 flex h-dvh max-w-none translate-x-0 translate-y-0 flex-col gap-0 rounded-none p-0 sm:max-w-none", "pt-[env(safe-area-inset-top)] pb-[env(safe-area-inset-bottom)]", className), children: [_jsxs("div", { "data-slot": "document-viewer-header", className: "flex min-w-0 items-center gap-2 border-b border-border py-1 pr-2 pl-4", children: [_jsxs("div", { className: "flex min-w-0 flex-1 flex-col", children: [_jsx(DialogTitle, { className: "truncate text-base", title: title, children: title }), _jsx(DialogDescription, { "data-slot": "document-viewer-pages", className: "text-small", children: pageCount === null ? "" : pageCount === 1 ? words.pageCountOne : fill(words.pageCount, { count: pageCount }) })] }), actions, canZoom ? (_jsxs("div", { "data-slot": "document-viewer-zoom", className: "flex shrink-0 items-center gap-1", children: [_jsx(Button, { type: "button", variant: "ghost", size: "icon-touch", className: "md:size-7", "aria-label": words.zoomOut, title: words.zoomOut, disabled: zoomIndex === 0, onClick: () => setZoomIndex((index) => Math.max(0, index - 1)), children: _jsx(Minus, { "aria-hidden": "true", strokeWidth: ICON_STROKE_WIDTH }) }), _jsx("span", { "data-slot": "document-viewer-zoom-level", "aria-live": "polite", className: "w-12 text-center text-small text-muted-foreground tabular-nums", children: fill(words.zoom, { percent: Math.round(zoom * 100) }) }), _jsx(Button, { type: "button", variant: "ghost", size: "icon-touch", className: "md:size-7", "aria-label": words.zoomIn, title: words.zoomIn, disabled: zoomIndex === DOCUMENT_ZOOM_STEPS.length - 1, onClick: () => setZoomIndex((index) => Math.min(DOCUMENT_ZOOM_STEPS.length - 1, index + 1)), children: _jsx(Plus, { "aria-hidden": "true", strokeWidth: ICON_STROKE_WIDTH }) })] })) : null, _jsx(DialogClose, { asChild: true, children: _jsx(Button, { type: "button", variant: "ghost", size: "icon-touch", "data-slot": "document-viewer-close", "aria-label": words.close, title: words.close, className: "shrink-0", children: _jsx(X, { "aria-hidden": "true", strokeWidth: ICON_STROKE_WIDTH }) }) })] }), _jsx("div", { "data-slot": "document-viewer-body", role: "region", "aria-label": title, tabIndex: 0, className: "min-h-0 flex-1 overflow-auto bg-muted outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:ring-inset", children: _jsx(DocumentBody, { loaded: loaded, zoom: zoom, title: title, words: words }) })] }) }));
85
+ }
86
+ function DocumentBody({ loaded, zoom, title, words }) {
87
+ if (loaded.state === "loading") {
88
+ return (_jsxs("p", { role: "status", "data-slot": "document-viewer-loading", className: "flex h-full items-center justify-center gap-2 text-sm text-muted-foreground", children: [_jsx(LoaderCircle, { "aria-hidden": "true", strokeWidth: ICON_STROKE_WIDTH, className: "size-4 animate-spin" }), words.loading] }));
89
+ }
90
+ if (loaded.state === "failed" || loaded.state === "unsupported") {
91
+ return (_jsx("p", { role: "alert", "data-slot": "document-viewer-error", className: "flex h-full items-center justify-center p-6 text-center text-sm text-muted-foreground", children: loaded.state === "failed" ? words.failed : words.unsupported }));
92
+ }
93
+ if (loaded.state === "image") {
94
+ return (_jsx("div", { className: "flex min-h-full items-start justify-center p-4", children: _jsx("img", { "data-slot": "document-viewer-image", src: loaded.url, alt: title, className: "h-auto max-w-none", style: { width: `${String(zoom * 100)}%` } }) }));
95
+ }
96
+ return _jsx(PdfPages, { document: loaded.document, zoom: zoom, words: words });
97
+ }
98
+ function PdfPages({ document, zoom, words }) {
99
+ const areaRef = useRef(null);
100
+ const [areaWidth, setAreaWidth] = useState(null);
101
+ useEffect(() => {
102
+ const area = areaRef.current;
103
+ if (area === null)
104
+ return undefined;
105
+ // The width inside the area's padding: at 100 % a page fits the screen with its margin on both sides.
106
+ const measure = () => {
107
+ const style = globalThis.getComputedStyle(area);
108
+ const inner = area.clientWidth - (Number.parseFloat(style.paddingLeft) || 0) - (Number.parseFloat(style.paddingRight) || 0);
109
+ setAreaWidth(inner > 0 ? Math.min(inner, MAX_FIT_WIDTH) : FALLBACK_WIDTH);
110
+ };
111
+ measure();
112
+ if (typeof ResizeObserver === "undefined")
113
+ return undefined;
114
+ const observer = new ResizeObserver(measure);
115
+ observer.observe(area);
116
+ return () => observer.disconnect();
117
+ }, []);
118
+ const pages = Array.from({ length: document.pageCount }, (_, index) => index + 1);
119
+ return (_jsx("div", { ref: areaRef, "data-slot": "document-viewer-pages-area", className: "flex flex-col items-center gap-3 p-4", children: areaWidth === null
120
+ ? null
121
+ : pages.map((pageNumber) => (_jsx(PdfPage, { document: document, pageNumber: pageNumber, width: Math.round(areaWidth * zoom), label: fill(words.page, { number: pageNumber, count: document.pageCount }) }, pageNumber))) }));
122
+ }
123
+ function PdfPage({ document, pageNumber, width, label }) {
124
+ const canvasRef = useRef(null);
125
+ const [hasFailed, setHasFailed] = useState(false);
126
+ useEffect(() => {
127
+ const canvas = canvasRef.current;
128
+ if (canvas === null)
129
+ return;
130
+ document.renderPage(pageNumber, canvas, width).then(() => setHasFailed(false), () => setHasFailed(true));
131
+ }, [document, pageNumber, width]);
132
+ return (_jsx("canvas", { ref: canvasRef, role: "img", "aria-label": label, "data-slot": "document-viewer-page", "data-page": pageNumber, "data-failed": hasFailed || undefined, className: "max-w-none bg-background shadow-dialog" }));
133
+ }
134
+ const KIND_ICONS = { pdf: FileText, image: FileImage, other: FileIcon };
135
+ // The documents of an entry, one `DocumentRow` per row.
136
+ export function DocumentList({ label, children, className }) {
137
+ return (_jsx("ul", { "aria-label": label, "data-slot": "document-list", className: cn("flex flex-col gap-1", className), children: children }));
138
+ }
139
+ // One document: an icon by its type, the title as a touch-sized button that opens it, its size, and a mark when a copy
140
+ // is kept on the device.
141
+ export function DocumentRow({ title, contentType, size, isOffline = false, onOpen, actions, locale = "en", messages, className }) {
142
+ const words = mergeMessages(messages);
143
+ const kind = getDocumentKind(contentType);
144
+ const Icon = KIND_ICONS[kind];
145
+ return (_jsxs("li", { "data-slot": "document-row", "data-kind": kind, "data-offline": isOffline || undefined, className: cn("flex min-w-0 items-center gap-2 rounded-md px-2 py-1", className), children: [_jsx(Icon, { "aria-hidden": "true", strokeWidth: ICON_STROKE_WIDTH, className: "size-4 shrink-0 text-muted-foreground" }), _jsxs("button", { type: "button", "data-slot": "document-row-open", onClick: onOpen, className: "flex min-h-touch-target min-w-0 flex-1 flex-wrap items-center gap-x-2 rounded-sm text-left outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50 md:min-h-7", children: [_jsxs("span", { className: "sr-only", children: [words.open, " "] }), _jsx("span", { "data-slot": "document-row-title", title: title, className: "min-w-0 truncate text-sm font-medium", children: title }), _jsx("span", { "data-slot": "document-row-size", className: "shrink-0 text-small text-muted-foreground tabular-nums", children: formatFileSize(size, locale) }), isOffline ? (_jsx(Status, { color: "green", icon: CircleCheck, className: "shrink-0 text-small", children: words.offline })) : null] }), actions === undefined ? null : _jsx("div", { "data-slot": "document-row-actions", className: "flex shrink-0 items-center gap-1", children: actions })] }));
146
+ }
147
+ //# sourceMappingURL=Document.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Document.js","sourceRoot":"","sources":["../../src/notion/Document.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EAAE,WAAW,EAAE,IAAI,IAAI,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,YAAY,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,EAAmB,MAAM,cAAc,CAAC;AACjI,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAkB,MAAM,OAAO,CAAC;AAEpE,OAAO,EAAE,EAAE,EAAE,MAAM,mBAAmB,CAAC;AACvC,OAAO,EAAE,EAAE,EAAE,MAAM,iBAAiB,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,aAAa,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAErG,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAqB,MAAM,oBAAoB,CAAC;AAC7F,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,eAAe,EAA0C,MAAM,iBAAiB,CAAC;AAC1F,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAyBrC,SAAS,aAAa,CAAC,QAA8C;IACnE,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
@@ -0,0 +1,7 @@
1
+ /** How a document is shown: a PDF's pages, an image, or neither. */
2
+ export type DocumentKind = "pdf" | "image" | "other";
3
+ /** The kind of a document by its media type (`application/pdf`, `image/png`; parameters ignored). */
4
+ export declare function getDocumentKind(contentType: string): DocumentKind;
5
+ /** The zoom steps, as a share of the fitted width. */
6
+ export declare const DOCUMENT_ZOOM_STEPS: readonly number[];
7
+ //# sourceMappingURL=document-kind.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"document-kind.d.ts","sourceRoot":"","sources":["../../src/notion/document-kind.ts"],"names":[],"mappings":"AAEA,oEAAoE;AACpE,MAAM,MAAM,YAAY,GAAG,KAAK,GAAG,OAAO,GAAG,OAAO,CAAC;AAErD,qGAAqG;AACrG,wBAAgB,eAAe,CAAC,WAAW,EAAE,MAAM,GAAG,YAAY,CAKjE;AAED,sDAAsD;AACtD,eAAO,MAAM,mBAAmB,EAAE,SAAS,MAAM,EAAoC,CAAC"}
@@ -0,0 +1,13 @@
1
+ // Plain helpers of the document parts, kept outside the client module so Server Components can use them.
2
+ /** The kind of a document by its media type (`application/pdf`, `image/png`; parameters ignored). */
3
+ export function getDocumentKind(contentType) {
4
+ const essence = (contentType.split(";")[0] ?? "").trim().toLowerCase();
5
+ if (essence === "application/pdf")
6
+ return "pdf";
7
+ if (essence.startsWith("image/"))
8
+ return "image";
9
+ return "other";
10
+ }
11
+ /** The zoom steps, as a share of the fitted width. */
12
+ export const DOCUMENT_ZOOM_STEPS = [0.5, 0.75, 1, 1.25, 1.5, 2, 3];
13
+ //# sourceMappingURL=document-kind.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"document-kind.js","sourceRoot":"","sources":["../../src/notion/document-kind.ts"],"names":[],"mappings":"AAAA,yGAAyG;AAKzG,qGAAqG;AACrG,MAAM,UAAU,eAAe,CAAC,WAAmB;IACjD,MAAM,OAAO,GAAG,CAAC,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IACvE,IAAI,OAAO,KAAK,iBAAiB;QAAE,OAAO,KAAK,CAAC;IAChD,IAAI,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC;QAAE,OAAO,OAAO,CAAC;IACjD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,sDAAsD;AACtD,MAAM,CAAC,MAAM,mBAAmB,GAAsB,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC"}
@@ -0,0 +1,18 @@
1
+ /** An opened PDF: its page count, and each page drawn into a canvas at a CSS width. */
2
+ export interface PdfDocumentHandle {
3
+ readonly pageCount: number;
4
+ /** Draws page `pageNumber` (from 1) into `canvas`, `width` CSS pixels wide, sharp on the device's pixel ratio. */
5
+ renderPage(pageNumber: number, canvas: HTMLCanvasElement, width: number): Promise<void>;
6
+ /** Frees the document; a render after it fails. */
7
+ destroy(): void;
8
+ }
9
+ export interface PdfEngine {
10
+ /** Opens a PDF from its bytes; rejects for bytes that are not a PDF it can read. */
11
+ open(data: ArrayBuffer): Promise<PdfDocumentHandle>;
12
+ }
13
+ /**
14
+ * pdf.js as a `PdfEngine`, loaded once. The legacy build, so an older phone browser reads it too. Call it ahead (e.g.
15
+ * when a page with documents opens) to fetch its chunks while online, so an installed app opens a PDF offline later.
16
+ */
17
+ export declare function loadPdfjsEngine(): Promise<PdfEngine>;
18
+ //# sourceMappingURL=pdf-engine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pdf-engine.d.ts","sourceRoot":"","sources":["../../src/notion/pdf-engine.ts"],"names":[],"mappings":"AAIA,uFAAuF;AACvF,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,kHAAkH;IAClH,UAAU,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,iBAAiB,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACxF,mDAAmD;IACnD,OAAO,IAAI,IAAI,CAAC;CACjB;AAED,MAAM,WAAW,SAAS;IACxB,oFAAoF;IACpF,IAAI,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;CACrD;AAQD;;;GAGG;AACH,wBAAgB,eAAe,IAAI,OAAO,CAAC,SAAS,CAAC,CAMpD"}
@@ -0,0 +1,44 @@
1
+ // The PDF engine of `DocumentViewer`: pdf.js (Apache-2.0) loaded on first use, its worker code run on the page's main
2
+ // thread (no worker URL to configure, and the chunks are ordinary build files a service worker keeps). Behind a small
3
+ // interface, so a test or an app can pass another engine.
4
+ let loading = null;
5
+ /**
6
+ * pdf.js as a `PdfEngine`, loaded once. The legacy build, so an older phone browser reads it too. Call it ahead (e.g.
7
+ * when a page with documents opens) to fetch its chunks while online, so an installed app opens a PDF offline later.
8
+ */
9
+ export function loadPdfjsEngine() {
10
+ loading ??= importPdfjs().catch((error) => {
11
+ loading = null;
12
+ throw error;
13
+ });
14
+ return loading;
15
+ }
16
+ async function importPdfjs() {
17
+ const [pdfjs, worker] = await Promise.all([import("pdfjs-dist/legacy/build/pdf.mjs"), import("pdfjs-dist/legacy/build/pdf.worker.min.mjs")]);
18
+ const scope = globalThis;
19
+ scope.pdfjsWorker ??= worker;
20
+ return {
21
+ async open(data) {
22
+ const task = pdfjs.getDocument({ data: new Uint8Array(data.slice(0)), useSystemFonts: true });
23
+ const document = await task.promise;
24
+ return {
25
+ pageCount: document.numPages,
26
+ async renderPage(pageNumber, canvas, width) {
27
+ const page = await document.getPage(pageNumber);
28
+ const base = page.getViewport({ scale: 1 });
29
+ const ratio = globalThis.devicePixelRatio > 0 ? globalThis.devicePixelRatio : 1;
30
+ const viewport = page.getViewport({ scale: (width / base.width) * ratio });
31
+ canvas.width = Math.floor(viewport.width);
32
+ canvas.height = Math.floor(viewport.height);
33
+ canvas.style.width = `${String(width)}px`;
34
+ canvas.style.height = `${String(Math.floor(viewport.height / ratio))}px`;
35
+ await page.render({ canvas, viewport }).promise;
36
+ },
37
+ destroy() {
38
+ void task.destroy();
39
+ },
40
+ };
41
+ },
42
+ };
43
+ }
44
+ //# sourceMappingURL=pdf-engine.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pdf-engine.js","sourceRoot":"","sources":["../../src/notion/pdf-engine.ts"],"names":[],"mappings":"AAAA,sHAAsH;AACtH,sHAAsH;AACtH,0DAA0D;AAoB1D,IAAI,OAAO,GAA8B,IAAI,CAAC;AAE9C;;;GAGG;AACH,MAAM,UAAU,eAAe;IAC7B,OAAO,KAAK,WAAW,EAAE,CAAC,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;QACjD,OAAO,GAAG,IAAI,CAAC;QACf,MAAM,KAAK,CAAC;IACd,CAAC,CAAC,CAAC;IACH,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,KAAK,UAAU,WAAW;IACxB,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,iCAAiC,CAAC,EAAE,MAAM,CAAC,4CAA4C,CAAC,CAAC,CAAC,CAAC;IAC7I,MAAM,KAAK,GAAG,UAAyB,CAAC;IACxC,KAAK,CAAC,WAAW,KAAK,MAAM,CAAC;IAC7B,OAAO;QACL,KAAK,CAAC,IAAI,CAAC,IAAI;YACb,MAAM,IAAI,GAAG,KAAK,CAAC,WAAW,CAAC,EAAE,IAAI,EAAE,IAAI,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,cAAc,EAAE,IAAI,EAAE,CAAC,CAAC;YAC9F,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC;YACpC,OAAO;gBACL,SAAS,EAAE,QAAQ,CAAC,QAAQ;gBAC5B,KAAK,CAAC,UAAU,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK;oBACxC,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;oBAChD,MAAM,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC;oBAC5C,MAAM,KAAK,GAAG,UAAU,CAAC,gBAAgB,GAAG,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC;oBAChF,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,EAAE,KAAK,EAAE,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,KAAK,EAAE,CAAC,CAAC;oBAC3E,MAAM,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;oBAC1C,MAAM,CAAC,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;oBAC5C,MAAM,CAAC,KAAK,CAAC,KAAK,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC;oBAC1C,MAAM,CAAC,KAAK,CAAC,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,GAAG,KAAK,CAAC,CAAC,IAAI,CAAC;oBACzE,MAAM,IAAI,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC;gBAClD,CAAC;gBACD,OAAO;oBACL,KAAK,IAAI,CAAC,OAAO,EAAE,CAAC;gBACtB,CAAC;aACF,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@softure-ai/theme-notion",
3
- "version": "0.17.0",
3
+ "version": "0.18.0",
4
4
  "description": "SOFTURE AI Notion theme: shadcn/ui components (new-york v4, Radix, Tailwind CSS v4, lucide) with the Notion design system's tokens and deltas, ready to import.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -65,6 +65,7 @@
65
65
  "class-variance-authority": "^0.7.1",
66
66
  "cmdk": "^1.1.1",
67
67
  "lucide-react": "^1.70.0",
68
+ "pdfjs-dist": "^6.5.438",
68
69
  "radix-ui": "^1.8.1",
69
70
  "sonner": "^2.0.8",
70
71
  "tw-animate-css": "^1.4.0"
package/src/index.ts CHANGED
@@ -105,6 +105,19 @@ export { Steps, type StepItem, type StepState, type StepsLayout, type StepsProps
105
105
  export { TabBar, type TabBarItem, type TabBarProps } from "./notion/TabBar.js";
106
106
  export { Timeline, type TimelineItem, type TimelineItemFold, type TimelineItemSize, type TimelineLine, type TimelineProps } from "./notion/Timeline.js";
107
107
  export { TopLoadingBar, type TopLoadingBarProps } from "./notion/TopLoadingBar.js";
108
+ export { DOCUMENT_ZOOM_STEPS, getDocumentKind, type DocumentKind } from "./notion/document-kind.js";
109
+ export {
110
+ DocumentList,
111
+ DocumentRow,
112
+ DocumentViewer,
113
+ type DocumentListProps,
114
+ type DocumentMessages,
115
+ type DocumentMessagesOverride,
116
+ type DocumentRowProps,
117
+ type DocumentSource,
118
+ type DocumentViewerProps,
119
+ } from "./notion/Document.js";
120
+ export { loadPdfjsEngine, type PdfDocumentHandle, type PdfEngine } from "./notion/pdf-engine.js";
108
121
  export {
109
122
  UploadField,
110
123
  UploadItem,
@@ -0,0 +1,4 @@
1
+ // The PDF engine's worker module, imported only to run its message handler on the page's main thread.
2
+ declare module "pdfjs-dist/legacy/build/pdf.worker.min.mjs" {
3
+ export const WorkerMessageHandler: unknown;
4
+ }
@@ -44,6 +44,20 @@ export const en = {
44
44
  done: "Done",
45
45
  failed: "Failed",
46
46
  },
47
+ document: {
48
+ close: "Close",
49
+ zoomIn: "Zoom in",
50
+ zoomOut: "Zoom out",
51
+ zoom: "{percent}%",
52
+ pageCount: "{count} pages",
53
+ pageCountOne: "1 page",
54
+ page: "Page {number} of {count}",
55
+ loading: "Opening the document",
56
+ failed: "This document cannot be shown.",
57
+ unsupported: "This type of document cannot be shown here.",
58
+ offline: "Available offline",
59
+ open: "Open",
60
+ },
47
61
  steps: { done: "Done", current: "Current", todo: "To do", failed: "Failed" },
48
62
  command: { title: "Command Palette", description: "Search for a command to run..." },
49
63
  } as const;
@@ -0,0 +1,347 @@
1
+ "use client";
2
+
3
+ import { CircleCheck, File as FileIcon, FileImage, FileText, LoaderCircle, Minus, Plus, X, type LucideIcon } from "lucide-react";
4
+ import { useEffect, useRef, useState, type ReactNode } from "react";
5
+
6
+ import { en } from "../messages/en.js";
7
+ import { cn } from "../lib/utils.js";
8
+ import { Button } from "../ui/button.js";
9
+ import { Dialog, DialogClose, DialogContent, DialogDescription, DialogTitle } from "../ui/dialog.js";
10
+
11
+ import { DOCUMENT_ZOOM_STEPS, getDocumentKind, type DocumentKind } from "./document-kind.js";
12
+ import { formatFileSize } from "./format-file-size.js";
13
+ import { ICON_STROKE_WIDTH } from "./icon-stroke.js";
14
+ import { loadPdfjsEngine, type PdfDocumentHandle, type PdfEngine } from "./pdf-engine.js";
15
+ import { Status } from "./Status.js";
16
+
17
+ /** What the viewer shows: the bytes at hand (a kept copy, offline) or a URL it fetches. */
18
+ export type DocumentSource = { readonly blob: Blob } | { readonly url: string };
19
+
20
+ /** The texts of the document parts; `{count}`, `{number}` and `{percent}` are filled in. Built-in English: `notionMessages.en.document`. */
21
+ export interface DocumentMessages {
22
+ readonly close: string;
23
+ readonly zoomIn: string;
24
+ readonly zoomOut: string;
25
+ readonly zoom: string;
26
+ readonly pageCount: string;
27
+ readonly pageCountOne: string;
28
+ readonly page: string;
29
+ readonly loading: string;
30
+ readonly failed: string;
31
+ readonly unsupported: string;
32
+ readonly offline: string;
33
+ /** Read by a screen reader before a row's title. */
34
+ readonly open: string;
35
+ }
36
+
37
+ /** The app's wording for the document parts; each text left out keeps the built-in English one. */
38
+ export type DocumentMessagesOverride = Partial<DocumentMessages>;
39
+
40
+ function mergeMessages(override: DocumentMessagesOverride | undefined): DocumentMessages {
41
+ return { ...en.document, ...override };
42
+ }
43
+
44
+ function fill(template: string, values: Readonly<Record<string, string | number>>): string {
45
+ return template.replaceAll(/\{(\w+)\}/g, (match, key: string) => (key in values ? String(values[key]) : match));
46
+ }
47
+
48
+ const FIT_INDEX = 2;
49
+ /** The width a PDF page fits when the viewer cannot measure its area (a page rendered on the server, a test). */
50
+ const FALLBACK_WIDTH = 800;
51
+ /** The widest a page is drawn at 100 %: a printed page's width on a wide screen, so its lines stay readable. */
52
+ const MAX_FIT_WIDTH = 880;
53
+
54
+ /** Reads a URL's bytes as the signed-in user, the way the app's own page would. */
55
+ async function fetchDocument(url: string): Promise<Blob> {
56
+ const response = await fetch(url, { credentials: "same-origin" });
57
+ if (!response.ok) throw new Error(`DocumentViewer: fetching ${url} answered ${String(response.status)}`);
58
+ return response.blob();
59
+ }
60
+
61
+ type Loaded =
62
+ | { readonly state: "loading" }
63
+ | { readonly state: "failed" }
64
+ | { readonly state: "unsupported" }
65
+ | { readonly state: "pdf"; readonly document: PdfDocumentHandle }
66
+ | { readonly state: "image"; readonly url: string };
67
+
68
+ export interface DocumentViewerProps {
69
+ readonly open: boolean;
70
+ readonly onOpenChange: (open: boolean) => void;
71
+ /** The document's title, shown on top and as the dialog's name. */
72
+ readonly title: string;
73
+ /** The media type; it decides between PDF pages and an image. */
74
+ readonly contentType: string;
75
+ /** The bytes or the URL; nothing loads while it is `null`. */
76
+ readonly source: DocumentSource | null;
77
+ /** The PDF engine; pdf.js loaded on first use by default. */
78
+ readonly loadPdfEngine?: () => Promise<PdfEngine>;
79
+ /** Reads a URL source; `fetch` with the page's cookies by default. */
80
+ readonly fetchFile?: (url: string) => Promise<Blob>;
81
+ /** Something beside the zoom, e.g. a download link. */
82
+ readonly actions?: ReactNode;
83
+ readonly messages?: DocumentMessagesOverride;
84
+ readonly className?: string;
85
+ }
86
+
87
+ // A document inside the page, on the whole screen: a PDF's pages drawn one under the other, or an image, with the
88
+ // title, the page count, zoom and a close button. It never opens a new browser window, which an installed phone app
89
+ // cannot come back from offline; with a `Blob` source it needs no network at all.
90
+ export function DocumentViewer({ open, onOpenChange, title, contentType, source, loadPdfEngine = loadPdfjsEngine, fetchFile = fetchDocument, actions, messages, className }: DocumentViewerProps) {
91
+ const words = mergeMessages(messages);
92
+ const [loaded, setLoaded] = useState<Loaded>({ state: "loading" });
93
+ const [zoomIndex, setZoomIndex] = useState(FIT_INDEX);
94
+ const kind = getDocumentKind(contentType);
95
+
96
+ useEffect(() => {
97
+ if (!open || source === null) return undefined;
98
+ if (kind === "other") {
99
+ setLoaded({ state: "unsupported" });
100
+ return undefined;
101
+ }
102
+ let isCurrent = true;
103
+ let release = (): void => undefined;
104
+ setLoaded({ state: "loading" });
105
+ setZoomIndex(FIT_INDEX);
106
+ void (async () => {
107
+ try {
108
+ const blob = "blob" in source ? source.blob : await fetchFile(source.url);
109
+ if (kind === "image") {
110
+ const url = URL.createObjectURL(blob);
111
+ release = () => URL.revokeObjectURL(url);
112
+ if (isCurrent) setLoaded({ state: "image", url });
113
+ else release();
114
+ return;
115
+ }
116
+ const engine = await loadPdfEngine();
117
+ const document = await engine.open(await blob.arrayBuffer());
118
+ release = () => document.destroy();
119
+ if (isCurrent) setLoaded({ state: "pdf", document });
120
+ else release();
121
+ } catch {
122
+ if (isCurrent) setLoaded({ state: "failed" });
123
+ }
124
+ })();
125
+ return () => {
126
+ isCurrent = false;
127
+ release();
128
+ };
129
+ }, [open, source, kind, loadPdfEngine, fetchFile]);
130
+
131
+ const zoom = DOCUMENT_ZOOM_STEPS[zoomIndex] ?? 1;
132
+ const pageCount = loaded.state === "pdf" ? loaded.document.pageCount : null;
133
+ const canZoom = loaded.state === "pdf" || loaded.state === "image";
134
+
135
+ return (
136
+ <Dialog open={open} onOpenChange={onOpenChange}>
137
+ <DialogContent
138
+ data-slot="document-viewer"
139
+ showCloseButton={false}
140
+ className={cn(
141
+ "top-0 left-0 flex h-dvh max-w-none translate-x-0 translate-y-0 flex-col gap-0 rounded-none p-0 sm:max-w-none",
142
+ "pt-[env(safe-area-inset-top)] pb-[env(safe-area-inset-bottom)]",
143
+ className,
144
+ )}
145
+ >
146
+ <div data-slot="document-viewer-header" className="flex min-w-0 items-center gap-2 border-b border-border py-1 pr-2 pl-4">
147
+ <div className="flex min-w-0 flex-1 flex-col">
148
+ <DialogTitle className="truncate text-base" title={title}>
149
+ {title}
150
+ </DialogTitle>
151
+ <DialogDescription data-slot="document-viewer-pages" className="text-small">
152
+ {pageCount === null ? "" : pageCount === 1 ? words.pageCountOne : fill(words.pageCount, { count: pageCount })}
153
+ </DialogDescription>
154
+ </div>
155
+ {actions}
156
+ {canZoom ? (
157
+ <div data-slot="document-viewer-zoom" className="flex shrink-0 items-center gap-1">
158
+ <Button type="button" variant="ghost" size="icon-touch" className="md:size-7" aria-label={words.zoomOut} title={words.zoomOut} disabled={zoomIndex === 0} onClick={() => setZoomIndex((index) => Math.max(0, index - 1))}>
159
+ <Minus aria-hidden="true" strokeWidth={ICON_STROKE_WIDTH} />
160
+ </Button>
161
+ <span data-slot="document-viewer-zoom-level" aria-live="polite" className="w-12 text-center text-small text-muted-foreground tabular-nums">
162
+ {fill(words.zoom, { percent: Math.round(zoom * 100) })}
163
+ </span>
164
+ <Button
165
+ type="button"
166
+ variant="ghost"
167
+ size="icon-touch"
168
+ className="md:size-7"
169
+ aria-label={words.zoomIn}
170
+ title={words.zoomIn}
171
+ disabled={zoomIndex === DOCUMENT_ZOOM_STEPS.length - 1}
172
+ onClick={() => setZoomIndex((index) => Math.min(DOCUMENT_ZOOM_STEPS.length - 1, index + 1))}
173
+ >
174
+ <Plus aria-hidden="true" strokeWidth={ICON_STROKE_WIDTH} />
175
+ </Button>
176
+ </div>
177
+ ) : null}
178
+ {/* In the header, below the safe area, where the dialog's own corner button would sit under a phone's notch. */}
179
+ <DialogClose asChild>
180
+ <Button type="button" variant="ghost" size="icon-touch" data-slot="document-viewer-close" aria-label={words.close} title={words.close} className="shrink-0">
181
+ <X aria-hidden="true" strokeWidth={ICON_STROKE_WIDTH} />
182
+ </Button>
183
+ </DialogClose>
184
+ </div>
185
+ {/* Focusable, so the pages scroll with the keyboard too. */}
186
+ <div data-slot="document-viewer-body" role="region" aria-label={title} tabIndex={0} className="min-h-0 flex-1 overflow-auto bg-muted outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:ring-inset">
187
+ <DocumentBody loaded={loaded} zoom={zoom} title={title} words={words} />
188
+ </div>
189
+ </DialogContent>
190
+ </Dialog>
191
+ );
192
+ }
193
+
194
+ function DocumentBody({ loaded, zoom, title, words }: { readonly loaded: Loaded; readonly zoom: number; readonly title: string; readonly words: DocumentMessages }) {
195
+ if (loaded.state === "loading") {
196
+ return (
197
+ <p role="status" data-slot="document-viewer-loading" className="flex h-full items-center justify-center gap-2 text-sm text-muted-foreground">
198
+ <LoaderCircle aria-hidden="true" strokeWidth={ICON_STROKE_WIDTH} className="size-4 animate-spin" />
199
+ {words.loading}
200
+ </p>
201
+ );
202
+ }
203
+ if (loaded.state === "failed" || loaded.state === "unsupported") {
204
+ return (
205
+ <p role="alert" data-slot="document-viewer-error" className="flex h-full items-center justify-center p-6 text-center text-sm text-muted-foreground">
206
+ {loaded.state === "failed" ? words.failed : words.unsupported}
207
+ </p>
208
+ );
209
+ }
210
+ if (loaded.state === "image") {
211
+ return (
212
+ <div className="flex min-h-full items-start justify-center p-4">
213
+ {/* An object URL of the bytes at hand: nothing for an image optimizer to fetch. */}
214
+ <img data-slot="document-viewer-image" src={loaded.url} alt={title} className="h-auto max-w-none" style={{ width: `${String(zoom * 100)}%` }} />
215
+ </div>
216
+ );
217
+ }
218
+ return <PdfPages document={loaded.document} zoom={zoom} words={words} />;
219
+ }
220
+
221
+ function PdfPages({ document, zoom, words }: { readonly document: PdfDocumentHandle; readonly zoom: number; readonly words: DocumentMessages }) {
222
+ const areaRef = useRef<HTMLDivElement>(null);
223
+ const [areaWidth, setAreaWidth] = useState<number | null>(null);
224
+
225
+ useEffect(() => {
226
+ const area = areaRef.current;
227
+ if (area === null) return undefined;
228
+ // The width inside the area's padding: at 100 % a page fits the screen with its margin on both sides.
229
+ const measure = (): void => {
230
+ const style = globalThis.getComputedStyle(area);
231
+ const inner = area.clientWidth - (Number.parseFloat(style.paddingLeft) || 0) - (Number.parseFloat(style.paddingRight) || 0);
232
+ setAreaWidth(inner > 0 ? Math.min(inner, MAX_FIT_WIDTH) : FALLBACK_WIDTH);
233
+ };
234
+ measure();
235
+ if (typeof ResizeObserver === "undefined") return undefined;
236
+ const observer = new ResizeObserver(measure);
237
+ observer.observe(area);
238
+ return () => observer.disconnect();
239
+ }, []);
240
+
241
+ const pages = Array.from({ length: document.pageCount }, (_, index) => index + 1);
242
+ return (
243
+ <div ref={areaRef} data-slot="document-viewer-pages-area" className="flex flex-col items-center gap-3 p-4">
244
+ {areaWidth === null
245
+ ? null
246
+ : pages.map((pageNumber) => (
247
+ <PdfPage key={pageNumber} document={document} pageNumber={pageNumber} width={Math.round(areaWidth * zoom)} label={fill(words.page, { number: pageNumber, count: document.pageCount })} />
248
+ ))}
249
+ </div>
250
+ );
251
+ }
252
+
253
+ function PdfPage({ document, pageNumber, width, label }: { readonly document: PdfDocumentHandle; readonly pageNumber: number; readonly width: number; readonly label: string }) {
254
+ const canvasRef = useRef<HTMLCanvasElement>(null);
255
+ const [hasFailed, setHasFailed] = useState(false);
256
+
257
+ useEffect(() => {
258
+ const canvas = canvasRef.current;
259
+ if (canvas === null) return;
260
+ document.renderPage(pageNumber, canvas, width).then(
261
+ () => setHasFailed(false),
262
+ () => setHasFailed(true),
263
+ );
264
+ }, [document, pageNumber, width]);
265
+
266
+ return (
267
+ <canvas
268
+ ref={canvasRef}
269
+ role="img"
270
+ aria-label={label}
271
+ data-slot="document-viewer-page"
272
+ data-page={pageNumber}
273
+ data-failed={hasFailed || undefined}
274
+ className="max-w-none bg-background shadow-dialog"
275
+ />
276
+ );
277
+ }
278
+
279
+ const KIND_ICONS: Readonly<Record<DocumentKind, LucideIcon>> = { pdf: FileText, image: FileImage, other: FileIcon };
280
+
281
+ export interface DocumentListProps {
282
+ /** The list's accessible name, e.g. "Documents". */
283
+ readonly label: string;
284
+ /** `DocumentRow` rows. */
285
+ readonly children: ReactNode;
286
+ readonly className?: string;
287
+ }
288
+
289
+ // The documents of an entry, one `DocumentRow` per row.
290
+ export function DocumentList({ label, children, className }: DocumentListProps) {
291
+ return (
292
+ <ul aria-label={label} data-slot="document-list" className={cn("flex flex-col gap-1", className)}>
293
+ {children}
294
+ </ul>
295
+ );
296
+ }
297
+
298
+ export interface DocumentRowProps {
299
+ readonly title: string;
300
+ readonly contentType: string;
301
+ /** In bytes. */
302
+ readonly size: number;
303
+ /** Whether a copy is kept on the device; draws the "available offline" mark. */
304
+ readonly isOffline?: boolean;
305
+ /** Opens the document, e.g. in `DocumentViewer`. */
306
+ readonly onOpen: () => void;
307
+ /** Buttons after the row, e.g. a menu to rename or remove. */
308
+ readonly actions?: ReactNode;
309
+ /** Formats the size, e.g. "de" writes "1,5 kB". */
310
+ readonly locale?: string;
311
+ readonly messages?: DocumentMessagesOverride;
312
+ readonly className?: string;
313
+ }
314
+
315
+ // One document: an icon by its type, the title as a touch-sized button that opens it, its size, and a mark when a copy
316
+ // is kept on the device.
317
+ export function DocumentRow({ title, contentType, size, isOffline = false, onOpen, actions, locale = "en", messages, className }: DocumentRowProps) {
318
+ const words = mergeMessages(messages);
319
+ const kind = getDocumentKind(contentType);
320
+ const Icon = KIND_ICONS[kind];
321
+ return (
322
+ <li data-slot="document-row" data-kind={kind} data-offline={isOffline || undefined} className={cn("flex min-w-0 items-center gap-2 rounded-md px-2 py-1", className)}>
323
+ <Icon aria-hidden="true" strokeWidth={ICON_STROKE_WIDTH} className="size-4 shrink-0 text-muted-foreground" />
324
+ <button
325
+ type="button"
326
+ data-slot="document-row-open"
327
+ onClick={onOpen}
328
+ className="flex min-h-touch-target min-w-0 flex-1 flex-wrap items-center gap-x-2 rounded-sm text-left outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50 md:min-h-7"
329
+ >
330
+ {/* Read before the title, so the button's name is what it does and still holds every visible word. */}
331
+ <span className="sr-only">{words.open} </span>
332
+ <span data-slot="document-row-title" title={title} className="min-w-0 truncate text-sm font-medium">
333
+ {title}
334
+ </span>
335
+ <span data-slot="document-row-size" className="shrink-0 text-small text-muted-foreground tabular-nums">
336
+ {formatFileSize(size, locale)}
337
+ </span>
338
+ {isOffline ? (
339
+ <Status color="green" icon={CircleCheck} className="shrink-0 text-small">
340
+ {words.offline}
341
+ </Status>
342
+ ) : null}
343
+ </button>
344
+ {actions === undefined ? null : <div data-slot="document-row-actions" className="flex shrink-0 items-center gap-1">{actions}</div>}
345
+ </li>
346
+ );
347
+ }
@@ -0,0 +1,15 @@
1
+ // Plain helpers of the document parts, kept outside the client module so Server Components can use them.
2
+
3
+ /** How a document is shown: a PDF's pages, an image, or neither. */
4
+ export type DocumentKind = "pdf" | "image" | "other";
5
+
6
+ /** The kind of a document by its media type (`application/pdf`, `image/png`; parameters ignored). */
7
+ export function getDocumentKind(contentType: string): DocumentKind {
8
+ const essence = (contentType.split(";")[0] ?? "").trim().toLowerCase();
9
+ if (essence === "application/pdf") return "pdf";
10
+ if (essence.startsWith("image/")) return "image";
11
+ return "other";
12
+ }
13
+
14
+ /** The zoom steps, as a share of the fitted width. */
15
+ export const DOCUMENT_ZOOM_STEPS: readonly number[] = [0.5, 0.75, 1, 1.25, 1.5, 2, 3];
@@ -0,0 +1,64 @@
1
+ // The PDF engine of `DocumentViewer`: pdf.js (Apache-2.0) loaded on first use, its worker code run on the page's main
2
+ // thread (no worker URL to configure, and the chunks are ordinary build files a service worker keeps). Behind a small
3
+ // interface, so a test or an app can pass another engine.
4
+
5
+ /** An opened PDF: its page count, and each page drawn into a canvas at a CSS width. */
6
+ export interface PdfDocumentHandle {
7
+ readonly pageCount: number;
8
+ /** Draws page `pageNumber` (from 1) into `canvas`, `width` CSS pixels wide, sharp on the device's pixel ratio. */
9
+ renderPage(pageNumber: number, canvas: HTMLCanvasElement, width: number): Promise<void>;
10
+ /** Frees the document; a render after it fails. */
11
+ destroy(): void;
12
+ }
13
+
14
+ export interface PdfEngine {
15
+ /** Opens a PDF from its bytes; rejects for bytes that are not a PDF it can read. */
16
+ open(data: ArrayBuffer): Promise<PdfDocumentHandle>;
17
+ }
18
+
19
+ interface PdfjsGlobal {
20
+ pdfjsWorker?: unknown;
21
+ }
22
+
23
+ let loading: Promise<PdfEngine> | null = null;
24
+
25
+ /**
26
+ * pdf.js as a `PdfEngine`, loaded once. The legacy build, so an older phone browser reads it too. Call it ahead (e.g.
27
+ * when a page with documents opens) to fetch its chunks while online, so an installed app opens a PDF offline later.
28
+ */
29
+ export function loadPdfjsEngine(): Promise<PdfEngine> {
30
+ loading ??= importPdfjs().catch((error: unknown) => {
31
+ loading = null;
32
+ throw error;
33
+ });
34
+ return loading;
35
+ }
36
+
37
+ async function importPdfjs(): Promise<PdfEngine> {
38
+ const [pdfjs, worker] = await Promise.all([import("pdfjs-dist/legacy/build/pdf.mjs"), import("pdfjs-dist/legacy/build/pdf.worker.min.mjs")]);
39
+ const scope = globalThis as PdfjsGlobal;
40
+ scope.pdfjsWorker ??= worker;
41
+ return {
42
+ async open(data) {
43
+ const task = pdfjs.getDocument({ data: new Uint8Array(data.slice(0)), useSystemFonts: true });
44
+ const document = await task.promise;
45
+ return {
46
+ pageCount: document.numPages,
47
+ async renderPage(pageNumber, canvas, width) {
48
+ const page = await document.getPage(pageNumber);
49
+ const base = page.getViewport({ scale: 1 });
50
+ const ratio = globalThis.devicePixelRatio > 0 ? globalThis.devicePixelRatio : 1;
51
+ const viewport = page.getViewport({ scale: (width / base.width) * ratio });
52
+ canvas.width = Math.floor(viewport.width);
53
+ canvas.height = Math.floor(viewport.height);
54
+ canvas.style.width = `${String(width)}px`;
55
+ canvas.style.height = `${String(Math.floor(viewport.height / ratio))}px`;
56
+ await page.render({ canvas, viewport }).promise;
57
+ },
58
+ destroy() {
59
+ void task.destroy();
60
+ },
61
+ };
62
+ },
63
+ };
64
+ }