Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

officePreviewProtocol.ts

95 lines3.4 KB

1import type { PreviewPassword, PreviewUnlock } from "./previewUnlock";
2import type { OfficePreviewKind } from "@t3tools/shared/filePreview";
3import type { PreviewFailure } from "./previewFailure";
4​
5export const OFFICE_PREVIEW_MAX_BYTES = 50 * 1024 * 1024;
6export const OFFICE_PREVIEW_MAX_ROWS = 250_000;
7export const OFFICE_PREVIEW_MAX_COLUMNS = 1024;
8​
9/** Workbook settings used by the preview worker. */
10export type WorkbookView = {
11 /** The default cell style's widest digit, in CSS pixels. */
12 readonly digitWidth: number;
13 /** The theme's heading and body fonts, which chart text names as `+mj-lt` and `+mn-lt`. */
14 readonly themeFonts: { readonly major: string; readonly minor: string };
15};
16​
17export type OfficeWorkerRequest =
18 | PreviewUnlock
19 | { readonly type: "open"; readonly kind: OfficePreviewKind; readonly bytes: ArrayBuffer }
20 | { readonly type: "epub-page"; readonly index: number }
21 | { readonly type: "sheet-page"; readonly sheet: number; readonly index: number }
22 | { readonly type: "sheet-copy"; readonly sheet: number };
23​
24export type NotebookCell = {
25 readonly kind: "markdown" | "code" | "raw";
26 readonly source: string;
27 readonly outputs: { readonly kind: "text" | "image" | "html"; readonly text: string }[];
28};
29​
30export type EpubLocation = { readonly index: number; readonly anchor?: string };
31export type EpubNarrationCue = {
32 readonly src: string;
33 readonly begin: number;
34 readonly end?: number;
35 readonly anchor?: string;
36};
37export type EpubPage = {
38 readonly html: string;
39 readonly title?: string | undefined;
40 readonly styles?: readonly { css: string; media: string }[];
41 readonly htmlAttrs?: string | undefined;
42 readonly bodyAttrs?: string | undefined;
43 readonly fixed?: { width: number; height: number } | undefined;
44 readonly imagePage?: boolean;
45 readonly narration?: readonly EpubNarrationCue[];
46};
47​
48export type OfficeWorkerResult =
49 | PreviewPassword
50 | {
51 readonly type: "epub";
52 readonly first: number;
53 readonly rtl: boolean;
54 readonly chapters: readonly { title: string | undefined; linear: boolean }[];
55 readonly contents: readonly (EpubLocation & { title: string })[];
56 }
57 | {
58 readonly type: "epub-page";
59 readonly index: number;
60 readonly result: EpubPage | PreviewFailure;
61 }
62 | {
63 readonly type: "document";
64 readonly navigation: "page" | "slide";
65 readonly pages: { title: string | undefined; html: string }[];
66 }
67 | { readonly type: "notebook"; readonly language: string; readonly cells: NotebookCell[] }
68 | ({ readonly type: "error" } & PreviewFailure)
69 | {
70 readonly type: "docx" | "xlsx" | "pptx";
71 readonly bytes: ArrayBuffer;
72 readonly truncated: boolean;
73 /** For a workbook; undefined for other files. */
74 readonly view: WorkbookView | undefined;
75 }
76 | {
77 readonly type: "ods";
78 readonly sheets: {
79 name: string | undefined;
80 rows: string[][];
81 truncated: boolean;
82 rowCount: number;
83 columns: number;
84 /** Zero-based sheet positions of the rows and columns shown, when some are hidden. */
85 rowIndexes: number[] | undefined;
86 columnIndexes: number[] | undefined;
87 }[];
88 }
89 | {
90 readonly type: "sheet-page";
91 readonly sheet: number;
92 readonly index: number;
93 readonly rows: string[][];
94 }
95 | { readonly type: "sheet-copy"; readonly sheet: number; readonly text: string };