@ai-matrx/office 0.8.45 → 0.8.47
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 +7 -0
- package/dist/pdf-model.cjs +232 -0
- package/dist/pdf-model.cjs.map +1 -0
- package/dist/pdf-model.d.cts +248 -0
- package/dist/pdf-model.d.ts +248 -0
- package/dist/pdf-model.js +209 -0
- package/dist/pdf-model.js.map +1 -0
- package/dist/pdf.cjs +1127 -0
- package/dist/pdf.cjs.map +1 -0
- package/dist/pdf.d.cts +255 -0
- package/dist/pdf.d.ts +255 -0
- package/dist/pdf.js +1133 -0
- package/dist/pdf.js.map +1 -0
- package/dist/univer-collab.cjs +63 -16
- package/dist/univer-collab.cjs.map +1 -1
- package/dist/univer-collab.d.cts +42 -14
- package/dist/univer-collab.d.ts +42 -14
- package/dist/univer-collab.js +63 -16
- package/dist/univer-collab.js.map +1 -1
- package/package.json +26 -6
package/dist/pdf.d.ts
ADDED
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import { ComingSoonEntry } from '@ai-matrx/kit/coming-soon';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The page decisions of one workspace session: which pages are turned, left out, or moved. Pure.
|
|
7
|
+
*
|
|
8
|
+
* Decisions are PENDING: the viewer and the page grid show them at once, and "Apply" sends them
|
|
9
|
+
* to the server as the smallest list of page operations (`compilePageOps`). Pages are named by
|
|
10
|
+
* their ORIGINAL 1-based number everywhere, so a decision survives any later move.
|
|
11
|
+
*/
|
|
12
|
+
type Turn = 0 | 90 | 180 | 270;
|
|
13
|
+
interface PageDecisions {
|
|
14
|
+
/** Original page numbers in the order the person wants them (deleted pages stay in the list). */
|
|
15
|
+
order: number[];
|
|
16
|
+
/** Extra clockwise turn per original page; absent = 0. */
|
|
17
|
+
turns: Record<number, Turn>;
|
|
18
|
+
/** Original page numbers left out. */
|
|
19
|
+
deleted: number[];
|
|
20
|
+
}
|
|
21
|
+
declare function freshDecisions(pageCount: number): PageDecisions;
|
|
22
|
+
declare function turnPages(d: PageDecisions, pages: readonly number[], by: 90 | -90 | 180): PageDecisions;
|
|
23
|
+
declare function deletePages(d: PageDecisions, pages: readonly number[]): PageDecisions;
|
|
24
|
+
declare function restorePages(d: PageDecisions, pages: readonly number[]): PageDecisions;
|
|
25
|
+
/** The new order, as the grid reports it (a list of original page numbers). */
|
|
26
|
+
declare function reorderPages(d: PageDecisions, order: readonly number[]): PageDecisions;
|
|
27
|
+
declare function isDirty(d: PageDecisions): boolean;
|
|
28
|
+
/** The pages that will remain, in their new order. */
|
|
29
|
+
declare function keptOrder(d: PageDecisions): number[];
|
|
30
|
+
type PageOp = {
|
|
31
|
+
kind: "rotate";
|
|
32
|
+
pages: number[];
|
|
33
|
+
rotation: 90 | 180 | 270;
|
|
34
|
+
} | {
|
|
35
|
+
kind: "delete";
|
|
36
|
+
pages: number[];
|
|
37
|
+
} | {
|
|
38
|
+
kind: "reorder";
|
|
39
|
+
newOrder: number[];
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* The server operations that make the document match the decisions, in the order they must run:
|
|
43
|
+
* turns (original numbering), deletions (original numbering), then one reorder over what remains
|
|
44
|
+
* (renumbered 1..n). Nothing is emitted for a decision that changes nothing.
|
|
45
|
+
*/
|
|
46
|
+
declare function compilePageOps(d: PageDecisions): PageOp[];
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* What the PDF workspace needs from the app that mounts it. The package owns the chrome (rail,
|
|
50
|
+
* panels, top bar, find, undo, shortcuts); the host owns everything that touches a server, a route
|
|
51
|
+
* or the PDF engine: it injects them as ONE object (`PdfWorkspaceHost`), the same way the Sheets and
|
|
52
|
+
* Docs hosts inject theirs. Nothing here fails silently: an operation that cannot run REJECTS with a
|
|
53
|
+
* sentence and the shell shows it; an optional port that is absent hides its control (no dead button).
|
|
54
|
+
*/
|
|
55
|
+
|
|
56
|
+
/** What the shell hands the injected viewer. */
|
|
57
|
+
interface PdfViewerState {
|
|
58
|
+
/** 1 = the container's width (the viewer's own zoom unit). */
|
|
59
|
+
zoom: number;
|
|
60
|
+
spread: "single" | "two-up";
|
|
61
|
+
/** Pending turns per page, degrees clockwise (see `PageDecisions`). */
|
|
62
|
+
rotations: Record<number, number>;
|
|
63
|
+
/** Changes when the file changed on the server: the viewer must load it again. */
|
|
64
|
+
reloadKey: number;
|
|
65
|
+
/** The document parsed with this many pages. */
|
|
66
|
+
onDocumentLoad(pageCount: number): void;
|
|
67
|
+
/** A page was measured, in PDF points (crop and fit-page need it). */
|
|
68
|
+
onPageSize(page: number, widthPt: number, heightPt: number): void;
|
|
69
|
+
}
|
|
70
|
+
type PdfRunRequest = {
|
|
71
|
+
tool: "apply-pages";
|
|
72
|
+
ops: PageOp[];
|
|
73
|
+
} | {
|
|
74
|
+
tool: "extract-pages";
|
|
75
|
+
pages: number[];
|
|
76
|
+
} | {
|
|
77
|
+
tool: "split";
|
|
78
|
+
maxPagesPerPart: number;
|
|
79
|
+
} | {
|
|
80
|
+
tool: "crop";
|
|
81
|
+
pages: number[];
|
|
82
|
+
box: {
|
|
83
|
+
x0: number;
|
|
84
|
+
y0: number;
|
|
85
|
+
x1: number;
|
|
86
|
+
y1: number;
|
|
87
|
+
};
|
|
88
|
+
} | {
|
|
89
|
+
tool: "redact";
|
|
90
|
+
pattern: string;
|
|
91
|
+
reason: string;
|
|
92
|
+
} | {
|
|
93
|
+
tool: "compress";
|
|
94
|
+
level: 1 | 2 | 3 | 4 | 5;
|
|
95
|
+
} | {
|
|
96
|
+
tool: "extract-text";
|
|
97
|
+
} | {
|
|
98
|
+
tool: "extract-tables";
|
|
99
|
+
pages: number[];
|
|
100
|
+
};
|
|
101
|
+
type PdfRunResult =
|
|
102
|
+
/** The file itself changed (a new version): the shell reloads the viewer. */
|
|
103
|
+
{
|
|
104
|
+
kind: "replaced";
|
|
105
|
+
version?: number;
|
|
106
|
+
}
|
|
107
|
+
/** A new file was made (the original is untouched). */
|
|
108
|
+
| {
|
|
109
|
+
kind: "file";
|
|
110
|
+
fileId: string;
|
|
111
|
+
name?: string;
|
|
112
|
+
} | {
|
|
113
|
+
kind: "text";
|
|
114
|
+
text: string;
|
|
115
|
+
} | {
|
|
116
|
+
kind: "tables";
|
|
117
|
+
tables: Array<{
|
|
118
|
+
page: number;
|
|
119
|
+
rows: string[][];
|
|
120
|
+
}>;
|
|
121
|
+
};
|
|
122
|
+
interface PdfWorkspaceHost {
|
|
123
|
+
file: {
|
|
124
|
+
id: string;
|
|
125
|
+
name: string;
|
|
126
|
+
};
|
|
127
|
+
/** The injected windowed viewer (`@ai-matrx/media/viewers/pdf`, continuous layout, no toolbar). */
|
|
128
|
+
renderViewer(state: PdfViewerState): ReactNode;
|
|
129
|
+
/** One page thumbnail (the left panel). Absent: the panel numbers its pages only. */
|
|
130
|
+
renderThumbnail?(page: number, widthPx: number): ReactNode;
|
|
131
|
+
/** Run one tool on the server. Rejects with a sentence on failure. */
|
|
132
|
+
run(request: PdfRunRequest): Promise<PdfRunResult>;
|
|
133
|
+
/** Open another page of the app for the same file (Scan, Sign). */
|
|
134
|
+
openTool(tool: "scan" | "sign"): void;
|
|
135
|
+
/** Open a file the workspace made. */
|
|
136
|
+
openFile(fileId: string): void;
|
|
137
|
+
download(): void;
|
|
138
|
+
/** Absent: no Share control. */
|
|
139
|
+
share?(): void;
|
|
140
|
+
/** Rename the file. Absent: the name is read-only. */
|
|
141
|
+
rename?(name: string): Promise<void>;
|
|
142
|
+
/** Print the whole file (`pages` null) or just these. Absent: no Print control. */
|
|
143
|
+
print?(pages: number[] | null): Promise<void>;
|
|
144
|
+
/** The layers (optional content) of the document. Absent: the Layers tab announces it is not built. */
|
|
145
|
+
layers?: {
|
|
146
|
+
list(): Promise<Array<{
|
|
147
|
+
id: string;
|
|
148
|
+
name: string;
|
|
149
|
+
visible: boolean;
|
|
150
|
+
}>>;
|
|
151
|
+
set(id: string, visible: boolean): Promise<void>;
|
|
152
|
+
};
|
|
153
|
+
/** The server's redaction pattern catalog (ids are the server's contract). Absent: a free pattern field. */
|
|
154
|
+
redactPatterns?(): Promise<Array<{
|
|
155
|
+
id: string;
|
|
156
|
+
label: string;
|
|
157
|
+
}>>;
|
|
158
|
+
/** False while the device is offline: the save pill says so and edits are not queued. */
|
|
159
|
+
online?: boolean;
|
|
160
|
+
/** Show a failure to the person (the host's toast). Defaults to an inline banner. */
|
|
161
|
+
notify?(message: string, tone: "error" | "info"): void;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
interface PdfWorkspaceProps {
|
|
165
|
+
host: PdfWorkspaceHost;
|
|
166
|
+
className?: string;
|
|
167
|
+
}
|
|
168
|
+
declare function PdfWorkspace({ host, className }: PdfWorkspaceProps): react.JSX.Element;
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* The PDF workspace's tool rail, as data. Pure (no React, no icons): the host registers the
|
|
172
|
+
* Coming-soon rows from here (`PDF_COMING_SOON`), the shell draws the rail from it, and the tests
|
|
173
|
+
* check that the two agree.
|
|
174
|
+
*
|
|
175
|
+
* A tool is `ready` only where a real capability stands behind it today (`capability` names the
|
|
176
|
+
* server operation or app route). Anything else is `soon`: the rail shows it plainly marked, and
|
|
177
|
+
* choosing it announces its registered promise through `@ai-matrx/kit/coming-soon`. There is no
|
|
178
|
+
* third state, so no dead button.
|
|
179
|
+
*/
|
|
180
|
+
|
|
181
|
+
type PdfToolId = "browse" | "organize" | "extract-pages" | "split" | "crop" | "redact" | "compress" | "scan" | "sign" | "extract-data" | "edit" | "forms" | "protect" | "ocr" | "convert" | "compare" | "stamp";
|
|
182
|
+
interface PdfToolDef {
|
|
183
|
+
id: PdfToolId;
|
|
184
|
+
label: string;
|
|
185
|
+
/** Single-key shortcut that picks the tool (shown in the tooltip and the shortcut map). */
|
|
186
|
+
key?: string;
|
|
187
|
+
status: "ready" | "soon";
|
|
188
|
+
/** The server operation or route behind a ready tool; the wiring test reads it. */
|
|
189
|
+
capability?: string;
|
|
190
|
+
/** What choosing a ready tool does: show its panel, or leave for another page. */
|
|
191
|
+
opens: "panel" | "page" | "none";
|
|
192
|
+
group: 0 | 1 | 2;
|
|
193
|
+
/** One short line under the panel title. */
|
|
194
|
+
hint?: string;
|
|
195
|
+
}
|
|
196
|
+
declare const PDF_TOOLS: readonly PdfToolDef[];
|
|
197
|
+
declare const pdfTool: (id: string) => PdfToolDef | undefined;
|
|
198
|
+
/** The Coming-soon id of an unbuilt tool. */
|
|
199
|
+
declare const comingSoonIdOf: (id: PdfToolId) => string;
|
|
200
|
+
/** One row per unbuilt tool, ready for `registerComingSoon` or the host's registry table. */
|
|
201
|
+
declare const PDF_COMING_SOON: Record<string, ComingSoonEntry>;
|
|
202
|
+
|
|
203
|
+
type PdfActionId = "undo" | "redo" | "find" | "print" | "save" | "zoom-in" | "zoom-out" | "zoom-fit-width" | "zoom-fit-page" | "page-next" | "page-prev" | "page-first" | "page-last" | "rotate-right" | "rotate-left" | "delete-pages" | "select-all-pages" | "toggle-pages" | "toggle-properties" | "read-mode" | "two-up" | "shortcuts" | `tool:${string}`;
|
|
204
|
+
interface PdfShortcut {
|
|
205
|
+
action: PdfActionId;
|
|
206
|
+
label: string;
|
|
207
|
+
/** Display keys: "Mod+Z" shows as Cmd+Z on a Mac and Ctrl+Z elsewhere. */
|
|
208
|
+
keys: string;
|
|
209
|
+
section: "Edit" | "View" | "Pages" | "Tools";
|
|
210
|
+
}
|
|
211
|
+
declare const PDF_SHORTCUTS: readonly PdfShortcut[];
|
|
212
|
+
interface KeyLike {
|
|
213
|
+
key: string;
|
|
214
|
+
ctrlKey: boolean;
|
|
215
|
+
metaKey: boolean;
|
|
216
|
+
shiftKey: boolean;
|
|
217
|
+
altKey: boolean;
|
|
218
|
+
}
|
|
219
|
+
/** The action a key press means, or null. Never matches while `typing` (a text field has the key). */
|
|
220
|
+
declare function matchShortcut(e: KeyLike, typing: boolean): PdfActionId | null;
|
|
221
|
+
/** "Mod+Shift+Z" → "⌘⇧Z" on a Mac, "Ctrl+Shift+Z" elsewhere. */
|
|
222
|
+
declare function formatKeys(keys: string, mac: boolean): string;
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* The session's one undo/redo stack. Pure and generic: the workspace keeps page decisions and tool
|
|
226
|
+
* form values in it, each step with the label the menu shows ("Undo Rotate 3 pages"). A new step
|
|
227
|
+
* clears what was undone; the stack holds at most `limit` steps. Saved versions of the file are the
|
|
228
|
+
* durable undo: applying changes empties this stack.
|
|
229
|
+
*/
|
|
230
|
+
interface History<T> {
|
|
231
|
+
past: Array<{
|
|
232
|
+
label: string;
|
|
233
|
+
value: T;
|
|
234
|
+
}>;
|
|
235
|
+
present: {
|
|
236
|
+
label: string;
|
|
237
|
+
value: T;
|
|
238
|
+
};
|
|
239
|
+
future: Array<{
|
|
240
|
+
label: string;
|
|
241
|
+
value: T;
|
|
242
|
+
}>;
|
|
243
|
+
}
|
|
244
|
+
declare const HISTORY_LIMIT = 100;
|
|
245
|
+
declare function startHistory<T>(value: T): History<T>;
|
|
246
|
+
declare function pushStep<T>(h: History<T>, label: string, value: T, limit?: number): History<T>;
|
|
247
|
+
declare function undo<T>(h: History<T>): History<T>;
|
|
248
|
+
declare function redo<T>(h: History<T>): History<T>;
|
|
249
|
+
declare const canUndo: (h: History<unknown>) => boolean;
|
|
250
|
+
declare const canRedo: (h: History<unknown>) => boolean;
|
|
251
|
+
/** The label of the step Undo would take back. */
|
|
252
|
+
declare const undoLabel: (h: History<unknown>) => string;
|
|
253
|
+
declare const redoLabel: (h: History<unknown>) => string;
|
|
254
|
+
|
|
255
|
+
export { HISTORY_LIMIT, type History, type KeyLike, PDF_COMING_SOON, PDF_SHORTCUTS, PDF_TOOLS, type PageDecisions, type PageOp, type PdfActionId, type PdfRunRequest, type PdfRunResult, type PdfShortcut, type PdfToolDef, type PdfToolId, type PdfViewerState, PdfWorkspace, type PdfWorkspaceHost, type PdfWorkspaceProps, type Turn, canRedo, canUndo, comingSoonIdOf, compilePageOps, deletePages, formatKeys, freshDecisions, isDirty, keptOrder, matchShortcut, pdfTool, pushStep, redo, redoLabel, reorderPages, restorePages, startHistory, turnPages, undo, undoLabel };
|