@laminapdf/viewer 0.2.0-alpha.4 → 0.2.0-alpha.6

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 (127) hide show
  1. package/README.md +79 -10
  2. package/dist/client.d.ts +60 -2
  3. package/dist/client.d.ts.map +1 -1
  4. package/dist/client.js +241 -22
  5. package/dist/client.js.map +1 -1
  6. package/dist/edit/session.d.ts +91 -0
  7. package/dist/edit/session.d.ts.map +1 -0
  8. package/dist/edit/session.js +179 -0
  9. package/dist/edit/session.js.map +1 -0
  10. package/dist/edit-log.d.ts +32 -0
  11. package/dist/edit-log.d.ts.map +1 -0
  12. package/dist/edit-log.js +74 -0
  13. package/dist/edit-log.js.map +1 -0
  14. package/dist/find/controller.d.ts +6 -0
  15. package/dist/find/controller.d.ts.map +1 -1
  16. package/dist/find/controller.js +69 -2
  17. package/dist/find/controller.js.map +1 -1
  18. package/dist/first-draw.d.ts +10 -0
  19. package/dist/first-draw.d.ts.map +1 -0
  20. package/dist/first-draw.js +33 -0
  21. package/dist/first-draw.js.map +1 -0
  22. package/dist/history/history.d.ts +74 -0
  23. package/dist/history/history.d.ts.map +1 -0
  24. package/dist/history/history.js +135 -0
  25. package/dist/history/history.js.map +1 -0
  26. package/dist/index.d.ts +11 -3
  27. package/dist/index.d.ts.map +1 -1
  28. package/dist/index.js +4 -0
  29. package/dist/index.js.map +1 -1
  30. package/dist/layers/copy.d.ts +26 -0
  31. package/dist/layers/copy.d.ts.map +1 -0
  32. package/dist/layers/copy.js +150 -0
  33. package/dist/layers/copy.js.map +1 -0
  34. package/dist/layers/link-layer.d.ts +101 -0
  35. package/dist/layers/link-layer.d.ts.map +1 -0
  36. package/dist/layers/link-layer.js +527 -0
  37. package/dist/layers/link-layer.js.map +1 -0
  38. package/dist/layers/link-preview.d.ts +77 -0
  39. package/dist/layers/link-preview.d.ts.map +1 -0
  40. package/dist/layers/link-preview.js +202 -0
  41. package/dist/layers/link-preview.js.map +1 -0
  42. package/dist/layers/link-url.d.ts +19 -0
  43. package/dist/layers/link-url.d.ts.map +1 -0
  44. package/dist/layers/link-url.js +47 -0
  45. package/dist/layers/link-url.js.map +1 -0
  46. package/dist/layers/spans.d.ts +0 -6
  47. package/dist/layers/spans.d.ts.map +1 -1
  48. package/dist/layers/spans.js +2 -20
  49. package/dist/layers/spans.js.map +1 -1
  50. package/dist/layers/structure-layer.d.ts.map +1 -1
  51. package/dist/layers/structure-layer.js +3 -0
  52. package/dist/layers/structure-layer.js.map +1 -1
  53. package/dist/layers/text-layer.d.ts +27 -6
  54. package/dist/layers/text-layer.d.ts.map +1 -1
  55. package/dist/layers/text-layer.js +310 -28
  56. package/dist/layers/text-layer.js.map +1 -1
  57. package/dist/layout/page-layout.d.ts +7 -0
  58. package/dist/layout/page-layout.d.ts.map +1 -1
  59. package/dist/layout/page-layout.js +15 -0
  60. package/dist/layout/page-layout.js.map +1 -1
  61. package/dist/protocol.d.ts +197 -5
  62. package/dist/protocol.d.ts.map +1 -1
  63. package/dist/protocol.js +33 -6
  64. package/dist/protocol.js.map +1 -1
  65. package/dist/source/opfs.d.ts +35 -0
  66. package/dist/source/opfs.d.ts.map +1 -0
  67. package/dist/source/opfs.js +178 -0
  68. package/dist/source/opfs.js.map +1 -0
  69. package/dist/thumbnails/strip.d.ts +1 -1
  70. package/dist/thumbnails/strip.d.ts.map +1 -1
  71. package/dist/thumbnails/strip.js +48 -4
  72. package/dist/thumbnails/strip.js.map +1 -1
  73. package/dist/view/previews.d.ts +47 -0
  74. package/dist/view/previews.d.ts.map +1 -0
  75. package/dist/view/previews.js +97 -0
  76. package/dist/view/previews.js.map +1 -0
  77. package/dist/view/user-select.d.ts +3 -0
  78. package/dist/view/user-select.d.ts.map +1 -0
  79. package/dist/view/user-select.js +10 -0
  80. package/dist/view/user-select.js.map +1 -0
  81. package/dist/view/viewer.d.ts +143 -5
  82. package/dist/view/viewer.d.ts.map +1 -1
  83. package/dist/view/viewer.js +590 -50
  84. package/dist/view/viewer.js.map +1 -1
  85. package/dist/worker/document.d.ts +66 -6
  86. package/dist/worker/document.d.ts.map +1 -1
  87. package/dist/worker/document.js +139 -23
  88. package/dist/worker/document.js.map +1 -1
  89. package/dist/worker/edit.d.ts +35 -0
  90. package/dist/worker/edit.d.ts.map +1 -0
  91. package/dist/worker/edit.js +305 -0
  92. package/dist/worker/edit.js.map +1 -0
  93. package/dist/worker/find.d.ts +2 -2
  94. package/dist/worker/find.d.ts.map +1 -1
  95. package/dist/worker/find.js +8 -21
  96. package/dist/worker/find.js.map +1 -1
  97. package/dist/worker/fingerprint.d.ts +10 -0
  98. package/dist/worker/fingerprint.d.ts.map +1 -0
  99. package/dist/worker/fingerprint.js +42 -0
  100. package/dist/worker/fingerprint.js.map +1 -0
  101. package/dist/worker/methods.d.ts.map +1 -1
  102. package/dist/worker/methods.js +42 -4
  103. package/dist/worker/methods.js.map +1 -1
  104. package/dist/worker/navigation.d.ts +5 -1
  105. package/dist/worker/navigation.d.ts.map +1 -1
  106. package/dist/worker/navigation.js +22 -4
  107. package/dist/worker/navigation.js.map +1 -1
  108. package/dist/worker/print.d.ts +14 -0
  109. package/dist/worker/print.d.ts.map +1 -0
  110. package/dist/worker/print.js +49 -0
  111. package/dist/worker/print.js.map +1 -0
  112. package/dist/worker/recent-pages.d.ts +16 -0
  113. package/dist/worker/recent-pages.d.ts.map +1 -0
  114. package/dist/worker/recent-pages.js +68 -0
  115. package/dist/worker/recent-pages.js.map +1 -0
  116. package/dist/worker/render.d.ts.map +1 -1
  117. package/dist/worker/render.js +5 -2
  118. package/dist/worker/render.js.map +1 -1
  119. package/dist/worker/session.d.ts +59 -0
  120. package/dist/worker/session.d.ts.map +1 -0
  121. package/dist/worker/session.js +152 -0
  122. package/dist/worker/session.js.map +1 -0
  123. package/dist/worker/text.d.ts +11 -3
  124. package/dist/worker/text.d.ts.map +1 -1
  125. package/dist/worker/text.js +33 -25
  126. package/dist/worker/text.js.map +1 -1
  127. package/package.json +9 -8
@@ -1,5 +1,5 @@
1
- import { type CloneableWasmSource, type RenderLimits, type RenderRequest } from "@laminapdf/render";
2
- import type { Limits, OutlineNode, PageInfo, StructureNode, Target } from "@laminapdf/sdk";
1
+ import { type CloneableWasmSource, type PageAppearance, type RenderLimits, type RenderRequest } from "@laminapdf/render";
2
+ import type { DocumentProperties, Limits, Op, OutlineNode, PageInfo, PageLink, Reflow, StructureNode, Target } from "@laminapdf/sdk";
3
3
  import type { FindOptions } from "./find/fold.js";
4
4
  import type { FindSnippet } from "./find/page.js";
5
5
  /** Which engine draws the pages (ADR 0004: PDFium by default, hayro the CI oracle). */
@@ -26,6 +26,13 @@ export interface ViewerOpenOptions {
26
26
  readonly limits?: Partial<Limits>;
27
27
  /** The backend's render limits (ADR 0004). */
28
28
  readonly renderLimits?: Partial<RenderLimits>;
29
+ /**
30
+ * A local file larger than this many bytes is copied into the origin-private file system and
31
+ * read from there, not held in memory (default 200 MiB; tests lower it).
32
+ */
33
+ readonly copyAbove?: number;
34
+ /** Keep that copy once the document closes, for next time (default true); false removes it then. */
35
+ readonly keepCopy?: boolean;
29
36
  }
30
37
  /** An open document, as layout needs it up front. */
31
38
  export interface OpenedDocument {
@@ -36,13 +43,89 @@ export interface OpenedDocument {
36
43
  readonly pages: readonly PageInfo[];
37
44
  /** Whether the file can't be opened without its password, so a restarted worker must ask again. */
38
45
  readonly needsPassword: boolean;
46
+ /**
47
+ * A hash of the file's first revision (`"fp1:"` and a SHA-256 in hex): the same for a renamed
48
+ * copy and after an incremental update, so a reading position kept under it follows the file.
49
+ * Absent when it couldn't be computed (no Web Crypto, a failed read): the document still opens.
50
+ */
51
+ readonly fingerprint?: string;
39
52
  readonly backend: {
40
53
  readonly name: BackendName;
41
54
  readonly version: string;
42
55
  };
43
56
  /** The title in the file's metadata, for the window's title; absent when the file has none. */
44
57
  readonly title?: string;
58
+ /**
59
+ * Whether the file is encrypted: it can't take an edit until saving can encrypt again (E11),
60
+ * since its edits are written into memory to be drawn, and that save is refused (`encrypted-base`).
61
+ */
62
+ readonly encrypted: boolean;
63
+ }
64
+ /**
65
+ * What an edit, an undo or a redo did, for the view to redraw (`applyEdit`, `undoEdit`,
66
+ * `redoEdit`, `goToStep`): the pages it touched, as they are after it, and the edit session's
67
+ * history now. Each page's size is its displayed size in points, so a quarter turn swaps its width
68
+ * and height. An edit that touched no page (the document's metadata) leaves `pages` empty.
69
+ */
70
+ export interface EditResult {
71
+ readonly pages: readonly PageInfo[];
72
+ readonly history: EditHistory;
73
+ /** Each step an undo or redo took back or made again, in order, with how it went (none for an edit). */
74
+ readonly reverted?: readonly RevertedStep[];
75
+ }
76
+ /** The most steps an edit session keeps: the oldest go after this many (ADR 0006 §4). */
77
+ export declare const HISTORY_DEPTH = 500;
78
+ /** One step of an edit session: a transaction, as the history lists it. */
79
+ export interface EditStep {
80
+ /** Unique in the session, and increasing. */
81
+ readonly id: number;
82
+ /** What it did, in the words its caller gave ("Rotate page 5"). */
83
+ readonly label: string;
84
+ /** The pages it touched (0-based), in order. */
85
+ readonly pages: readonly number[];
86
+ /** When it was made, in ms since the epoch. */
87
+ readonly at: number;
88
+ /**
89
+ * Its last undo (`"undo"`) or redo (`"redo"`) restored only part of it (`UndoOutcome::Partial`):
90
+ * a later change replaced some of what it changed, which keeps the later value.
91
+ */
92
+ readonly partial?: "undo" | "redo";
45
93
  }
94
+ /**
95
+ * An edit session's history (the worker holds the op log; this is its summary): the steps kept,
96
+ * oldest first, of which the first `position` are done and the rest undone, ready to redo.
97
+ */
98
+ export interface EditHistory {
99
+ readonly steps: readonly EditStep[];
100
+ readonly position: number;
101
+ /** How many of the oldest steps the depth limit dropped ({@link HISTORY_DEPTH}). */
102
+ readonly dropped: number;
103
+ /**
104
+ * Transactions between the document now and its last save, or as opened (ADR 0006 §7, the
105
+ * semantic level): 0 when they match, as after undoing every step since.
106
+ */
107
+ readonly unsaved: number;
108
+ /** An edit failed and couldn't be undone: nothing more can be edited until the document opens again. */
109
+ readonly diverged: boolean;
110
+ }
111
+ /** How an undo or redo of one step went. */
112
+ export interface RevertedStep {
113
+ readonly step: EditStep;
114
+ readonly way: "undo" | "redo";
115
+ /**
116
+ * `partial`: some of it was left alone, because a later change replaced it; `skipped`: nothing
117
+ * could be restored, and the step is gone from the history.
118
+ */
119
+ readonly outcome: "applied" | "partial" | "skipped";
120
+ }
121
+ /** The ops of one step and its label, as a restarted worker replays them (`restoreEdits`). */
122
+ export interface ReplayedStep {
123
+ readonly ops: readonly Op[];
124
+ readonly label: string;
125
+ readonly at: number;
126
+ }
127
+ /** An edit session with nothing in it. */
128
+ export declare const EMPTY_HISTORY: EditHistory;
46
129
  /** A rendered tile on the page: an ImageBitmap transferred from the worker. Close it when done. */
47
130
  export interface RenderedBitmap {
48
131
  readonly bitmap: ImageBitmap;
@@ -66,14 +149,59 @@ export interface Methods {
66
149
  version: string;
67
150
  };
68
151
  };
152
+ /** `ticket`: the page's number for this open, which `currentDocument` gives back. */
69
153
  openDocument: {
70
- params: [source: SourceInit, options: ViewerOpenOptions];
154
+ params: [source: SourceInit, options: ViewerOpenOptions, ticket?: number];
71
155
  result: OpenedDocument;
72
156
  };
157
+ /** The open document's answer and its open's ticket; asked after a cancelled open. */
158
+ currentDocument: {
159
+ params: [];
160
+ result: {
161
+ readonly document: OpenedDocument;
162
+ readonly ticket: number | undefined;
163
+ } | undefined;
164
+ };
73
165
  closeDocument: {
74
166
  params: [];
75
167
  result: undefined;
76
168
  };
169
+ /**
170
+ * Applies `ops` to document `document` as one transaction, then redraws from the result: the
171
+ * pages it touched are drawn from the edited file from then on.
172
+ */
173
+ applyEdit: {
174
+ params: [ops: readonly Op[], document: number, label?: string];
175
+ result: EditResult;
176
+ };
177
+ /** Undoes the newest done step of document `document`'s edit session, and redraws. */
178
+ undoEdit: {
179
+ params: [document: number];
180
+ result: EditResult;
181
+ };
182
+ /** Redoes the oldest undone step, and redraws. */
183
+ redoEdit: {
184
+ params: [document: number];
185
+ result: EditResult;
186
+ };
187
+ /** Undoes or redoes steps until `position` of them are done, and redraws once. */
188
+ goToStep: {
189
+ params: [position: number, document: number];
190
+ result: EditResult;
191
+ };
192
+ /** The edit session's history. */
193
+ editHistory: {
194
+ params: [document: number];
195
+ result: EditHistory;
196
+ };
197
+ /**
198
+ * A restarted worker's document takes the edits the old one had: `steps` applied again, one
199
+ * transaction each, then the newest `undone` of them undone, and drawn once.
200
+ */
201
+ restoreEdits: {
202
+ params: [steps: readonly ReplayedStep[], undone: number, document: number];
203
+ result: EditResult;
204
+ };
77
205
  pageInfo: {
78
206
  params: [index: number];
79
207
  result: PageInfo;
@@ -94,6 +222,10 @@ export interface Methods {
94
222
  params: [];
95
223
  result: StructureData;
96
224
  };
225
+ reflow: {
226
+ params: [];
227
+ result: Reflow;
228
+ };
97
229
  networkLog: {
98
230
  params: [];
99
231
  result: WorkerNetworkLog;
@@ -106,10 +238,58 @@ export interface Methods {
106
238
  params: [name: string];
107
239
  result: Target | undefined;
108
240
  };
241
+ pageLinks: {
242
+ params: [index: number];
243
+ result: readonly PageLink[];
244
+ };
245
+ properties: {
246
+ params: [];
247
+ result: DocumentProperties;
248
+ };
249
+ printPage: {
250
+ params: [index: number, options: PrintOptions];
251
+ result: PrintedPage;
252
+ };
253
+ fileBytes: {
254
+ params: [];
255
+ result: Uint8Array;
256
+ };
109
257
  find: {
110
258
  params: [query: string, options: FindOptions, pages: readonly number[]];
111
259
  result: FindPageResult[];
112
260
  };
261
+ readingOrder: {
262
+ params: [index: number];
263
+ result: ReadingBlock[];
264
+ };
265
+ }
266
+ /**
267
+ * One block of a page's text in reading order, as Lamina PDF's extraction finds it (ADR 0030):
268
+ * where it is, in page space (points from the displayed page's top-left, y down), and what kind
269
+ * of block it is. Copy as paragraph joins the selected text block by block in this order.
270
+ */
271
+ export interface ReadingBlock {
272
+ /** Its box: `[x, y, width, height]`. */
273
+ readonly bbox: readonly [number, number, number, number];
274
+ /** `paragraph`, `heading`, `list-item`, `caption`, `footnote`, `table` or `other`. */
275
+ readonly type: string;
276
+ }
277
+ /** How a page is drawn for printing. */
278
+ export interface PrintOptions {
279
+ /** Dots per inch: 150 (standard) or 300 (high). Lowered for a page too large to hold. */
280
+ readonly dpi: number;
281
+ /** Draw annotations as their print flags say (comments, highlights, stamps); off leaves them out. */
282
+ readonly annotations: boolean;
283
+ }
284
+ /** One page drawn for printing. */
285
+ export interface PrintedPage {
286
+ /** The page as a PNG. */
287
+ readonly image: Blob;
288
+ /** Its displayed size in points (`/Rotate` applied), which the printed page takes. */
289
+ readonly width: number;
290
+ readonly height: number;
291
+ /** The resolution it was drawn at: below the one asked for when the page was too large. */
292
+ readonly dpi: number;
113
293
  }
114
294
  /** One page's find results: each match as its quads (8 numbers per run it touches), in page space. */
115
295
  export interface FindPageResult {
@@ -213,8 +393,20 @@ export interface RenderKeyFields {
213
393
  export declare function renderKeyFields(key: string): RenderKeyFields;
214
394
  /**
215
395
  * The coalescing key of a render on document `id`: the document and the whole normalised
216
- * RenderRequest (page, scale, clip, rotation, flags and background), so two requests share a run
217
- * only when their pixels are the same (ADR 0009 §3.3).
396
+ * RenderRequest (page, scale, clip, rotation, flags, background and appearance), so two requests
397
+ * share a run only when their pixels are the same (ADR 0009 §3.3).
218
398
  */
219
399
  export declare function renderKey(request: RenderRequest, id: number): string;
400
+ /**
401
+ * The view's cache key of a render: its {@link renderKey}'s fields and the page's `revision`,
402
+ * which each edit of the page bumps, so a bitmap of the page before an edit never answers for it
403
+ * after. {@link renderKeyFields} reads both kinds of key.
404
+ */
405
+ export declare function viewKey(request: RenderRequest, id: number, revision: number): string;
406
+ /** The request field for `appearance`: none for the pages' own colours, as requests were before page appearances. */
407
+ export declare function appearanceField(appearance: PageAppearance): {
408
+ appearance?: PageAppearance;
409
+ };
410
+ /** A page appearance as a string: equal for the same appearance, whatever the object. */
411
+ export declare function appearanceKey(appearance: PageAppearance | undefined): string;
220
412
  //# sourceMappingURL=protocol.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"protocol.d.ts","sourceRoot":"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AO,CAAC;AACvC,+BAA+B;AAC/B,MAAM,MAAM,MAAM,CAAC,CAAC,SAAS,UAAU,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;AAChE,2BAA2B;AAC3B,MAAM,MAAM,MAAM,CAAC,CAAC,SAAS,UAAU,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;AAEhE;;;GAGG;AACH,MAAM,MAAM,QAAQ,GAAG,SAAS,GAAG,UAAU,GAAG,YAAY,CAAC;AAE7D,mEAAmE;AACnE,eAAO,MAAM,QAAQ,EAAE;IAAE,QAAQ,EAAE,CAAC,IAAI,QAAQ,GAAG,UAAU,GAAG,MAAM;CAKpE,CAAC;AAEH,yFAAyF;AACzF,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B;AAED,kEAAkE;AAClE,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,eAAe,CAG5D;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,aAAa,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAEpE;AAED;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,OAAO,EAAE,aAAa,EAAE,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEpF;AAgBD,qHAAqH;AACrH,wBAAgB,eAAe,CAAC,UAAU,EAAE,cAAc,GAAG;IAAE,UAAU,CAAC,EAAE,cAAc,CAAA;CAAE,CAE3F;AAED,yFAAyF;AACzF,wBAAgB,aAAa,CAAC,UAAU,EAAE,cAAc,GAAG,SAAS,GAAG,MAAM,CAI5E"}
package/dist/protocol.js CHANGED
@@ -3,7 +3,11 @@
3
3
  // added through `serve({ methods })` in the worker and `client.request` on the page. This module
4
4
  // holds what both sides agree on: the method map (params and results), the priorities and the
5
5
  // coalescing key.
6
- import { flagsOf } from "@laminapdf/render";
6
+ import { flagsOf, } from "@laminapdf/render";
7
+ /** The most steps an edit session keeps: the oldest go after this many (ADR 0006 §4). */
8
+ export const HISTORY_DEPTH = 500;
9
+ /** An edit session with nothing in it. */
10
+ export const EMPTY_HISTORY = { steps: [], position: 0, dropped: 0, unsaved: 0, diverged: false };
7
11
  /** The worker queue's numbers for each priority (higher first). */
8
12
  export const PRIORITY = Object.freeze({
9
13
  document: 4,
@@ -18,12 +22,23 @@ export function renderKeyFields(key) {
18
22
  }
19
23
  /**
20
24
  * The coalescing key of a render on document `id`: the document and the whole normalised
21
- * RenderRequest (page, scale, clip, rotation, flags and background), so two requests share a run
22
- * only when their pixels are the same (ADR 0009 §3.3).
25
+ * RenderRequest (page, scale, clip, rotation, flags, background and appearance), so two requests
26
+ * share a run only when their pixels are the same (ADR 0009 §3.3).
23
27
  */
24
28
  export function renderKey(request, id) {
25
- const { page, scale, clip, rotation = 0, flags, background } = request;
26
- return JSON.stringify([
29
+ return JSON.stringify(keyFields(request, id));
30
+ }
31
+ /**
32
+ * The view's cache key of a render: its {@link renderKey}'s fields and the page's `revision`,
33
+ * which each edit of the page bumps, so a bitmap of the page before an edit never answers for it
34
+ * after. {@link renderKeyFields} reads both kinds of key.
35
+ */
36
+ export function viewKey(request, id, revision) {
37
+ return JSON.stringify([...keyFields(request, id), revision]);
38
+ }
39
+ function keyFields(request, id) {
40
+ const { page, scale, clip, rotation = 0, flags, background, appearance } = request;
41
+ return [
27
42
  id,
28
43
  page,
29
44
  scale,
@@ -31,6 +46,18 @@ export function renderKey(request, id) {
31
46
  rotation,
32
47
  flagsOf(flags),
33
48
  background === undefined ? "white" : background,
34
- ]);
49
+ appearanceKey(appearance),
50
+ ];
51
+ }
52
+ /** The request field for `appearance`: none for the pages' own colours, as requests were before page appearances. */
53
+ export function appearanceField(appearance) {
54
+ return appearance === "original" ? {} : { appearance };
55
+ }
56
+ /** A page appearance as a string: equal for the same appearance, whatever the object. */
57
+ export function appearanceKey(appearance) {
58
+ if (appearance === undefined || typeof appearance === "string")
59
+ return appearance ?? "original";
60
+ const { ink: i, paper: p } = appearance;
61
+ return `high-contrast:${i.r},${i.g},${i.b},${i.a}:${p.r},${p.g},${p.b},${p.a}`;
35
62
  }
36
63
  //# sourceMappingURL=protocol.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"protocol.js","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA,kGAAkG;AAClG,wFAAwF;AACxF,iGAAiG;AACjG,8FAA8F;AAC9F,kBAAkB;AAElB,OAAO,EAA4B,OAAO,EAAyC,MAAM,mBAAmB,CAAC;AAqL7G,mEAAmE;AACnE,MAAM,CAAC,MAAM,QAAQ,GAAsD,MAAM,CAAC,MAAM,CAAC;IACvF,QAAQ,EAAE,CAAC;IACX,OAAO,EAAE,CAAC;IACV,QAAQ,EAAE,CAAC;IACX,UAAU,EAAE,CAAC;CACd,CAAC,CAAC;AAQH,kEAAkE;AAClE,MAAM,UAAU,eAAe,CAAC,GAAW;IACzC,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAc,CAAC;IAC5C,OAAO,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC,CAAW,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAW,EAAE,CAAC;AACvE,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,SAAS,CAAC,OAAsB,EAAE,EAAU;IAC1D,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,GAAG,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC;IACvE,OAAO,IAAI,CAAC,SAAS,CAAC;QACpB,EAAE;QACF,IAAI;QACJ,KAAK;QACL,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,EAAE,I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AAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;AACjF,CAAC"}
@@ -0,0 +1,35 @@
1
+ import type { RenderSource } from "@laminapdf/render";
2
+ import type { RangeSource } from "@laminapdf/sdk";
3
+ /** The OPFS folder of document copies, which the app's "Clear recent files and cached documents" empties too. */
4
+ export declare const CACHE_FOLDER = "documents";
5
+ /** Files above this many bytes are read from a copy: 200 MiB. */
6
+ export declare const COPY_ABOVE: number;
7
+ /** The copy's name: its size, date and a hash of its name, so the same file finds its copy again. */
8
+ export declare function copyName(file: Pick<File, "name" | "size" | "lastModified">): string;
9
+ /** How a copy is made and kept. */
10
+ export interface CopyOptions {
11
+ readonly signal: AbortSignal;
12
+ /** Told after each step of a copy being made. */
13
+ readonly onProgress?: ((loaded: number, total: number) => void) | undefined;
14
+ /** Keep the copy for next time once its document closes; false removes it then. */
15
+ readonly keep: boolean;
16
+ }
17
+ /** A copied file, read synchronously; both a RangeSource (Lamina PDF) and a RenderSource. */
18
+ export declare class OpfsByteSource implements RangeSource, RenderSource {
19
+ #private;
20
+ readonly size: number;
21
+ private constructor();
22
+ /**
23
+ * `file` read from its OPFS copy, made now if it isn't there; `undefined` where the browser has
24
+ * no OPFS or the copy can't be made (no room, locked by another tab, a write that fails), so the
25
+ * caller reads it from memory. Rejects only when `options.signal` aborts.
26
+ */
27
+ static open(file: File, options: CopyOptions): Promise<OpfsByteSource | undefined>;
28
+ readSync(offset: number, length: number): Uint8Array | undefined;
29
+ read(offset: number, length: number, options?: {
30
+ readonly signal?: AbortSignal;
31
+ }): Promise<Uint8Array>;
32
+ /** Lets the copy go: kept in the folder for next time, or removed when it isn't to be kept. */
33
+ close(): void;
34
+ }
35
+ //# sourceMappingURL=opfs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"opfs.d.ts","sourceRoot":"","sources":["../../src/source/opfs.ts"],"names":[],"mappings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@
1
+ // A large local file read from the origin-private file system: copied there once, in the document
2
+ // worker, then read through a synchronous access handle, so neither Lamina PDF nor the render
3
+ // backend (PDFium reads synchronously) needs the whole file in memory. Copies live in one folder,
4
+ // named by the file's size, date and name, so opening the same file again reads the copy already
5
+ // there; when the folder would pass its budget, the copies used longest ago go first. OPFS is a
6
+ // cache, never the only copy: a browser without it, a copy that doesn't fit or fails partway, or a
7
+ // file another tab holds opens from memory, as before; only a cancel stops the open.
8
+ /** The OPFS folder of document copies, which the app's "Clear recent files and cached documents" empties too. */
9
+ export const CACHE_FOLDER = "documents";
10
+ /** Files above this many bytes are read from a copy: 200 MiB. */
11
+ export const COPY_ABOVE = 200 * 1024 * 1024;
12
+ /** How much the copies may take, at most: 2 GiB, and never more than half the free quota. */
13
+ const MAX_CACHE_BYTES = 2 * 1024 * 1024 * 1024;
14
+ /** Copied in steps of 8 MiB, each a chance to stop and to report progress. */
15
+ const CHUNK = 8 * 1024 * 1024;
16
+ /** Beside each copy, a file holding when it was last opened (the copy's own date is when it was made). */
17
+ const USED = ".used";
18
+ /** The copy's name: its size, date and a hash of its name, so the same file finds its copy again. */
19
+ export function copyName(file) {
20
+ let hash = 2166136261;
21
+ for (let i = 0; i < file.name.length; i++)
22
+ hash = Math.imul(hash ^ file.name.charCodeAt(i), 16777619);
23
+ return `${file.size}-${file.lastModified}-${(hash >>> 0).toString(16)}.pdf`;
24
+ }
25
+ /** A copied file, read synchronously; both a RangeSource (Lamina PDF) and a RenderSource. */
26
+ export class OpfsByteSource {
27
+ size;
28
+ #handle;
29
+ #folder;
30
+ #name;
31
+ #keep;
32
+ constructor(handle, folder, name, keep) {
33
+ this.#handle = handle;
34
+ this.#folder = folder;
35
+ this.#name = name;
36
+ this.#keep = keep;
37
+ this.size = handle.getSize();
38
+ }
39
+ /**
40
+ * `file` read from its OPFS copy, made now if it isn't there; `undefined` where the browser has
41
+ * no OPFS or the copy can't be made (no room, locked by another tab, a write that fails), so the
42
+ * caller reads it from memory. Rejects only when `options.signal` aborts.
43
+ */
44
+ static async open(file, options) {
45
+ const folder = await cacheFolder();
46
+ if (folder === undefined)
47
+ return undefined;
48
+ const name = copyName(file);
49
+ let handle;
50
+ try {
51
+ const fileHandle = (await folder.getFileHandle(name, { create: true }));
52
+ handle = await fileHandle.createSyncAccessHandle();
53
+ }
54
+ catch {
55
+ // Locked by another tab's worker, or the browser refuses: read it from memory instead.
56
+ return undefined;
57
+ }
58
+ try {
59
+ if (handle.getSize() !== file.size) {
60
+ if (!(await makeRoom(folder, name, file.size)))
61
+ throw new Error("no room for the copy");
62
+ await copyInto(handle, file, options);
63
+ }
64
+ // The use record is best effort: another tab may hold it, and the copy is good without it.
65
+ await touch(folder, name).catch(() => undefined);
66
+ return new OpfsByteSource(handle, folder, name, options.keep);
67
+ }
68
+ catch (error) {
69
+ // A copy cut short (a cancel, the disk full) is never left to look complete.
70
+ handle.close();
71
+ await removeCopy(folder, name);
72
+ if (options.signal.aborted)
73
+ throw error;
74
+ return undefined;
75
+ }
76
+ }
77
+ readSync(offset, length) {
78
+ const end = Math.min(this.size, offset + length);
79
+ if (offset < 0 || end < offset)
80
+ return undefined;
81
+ const out = new Uint8Array(end - offset);
82
+ this.#handle.read(out, { at: offset });
83
+ return out;
84
+ }
85
+ read(offset, length, options) {
86
+ options?.signal?.throwIfAborted();
87
+ return Promise.resolve(this.readSync(offset, length) ?? new Uint8Array());
88
+ }
89
+ /** Lets the copy go: kept in the folder for next time, or removed when it isn't to be kept. */
90
+ close() {
91
+ this.#handle.close();
92
+ if (!this.#keep)
93
+ void removeCopy(this.#folder, this.#name);
94
+ }
95
+ }
96
+ async function cacheFolder() {
97
+ try {
98
+ const root = await navigator.storage.getDirectory();
99
+ return await root.getDirectoryHandle(CACHE_FOLDER, { create: true });
100
+ }
101
+ catch {
102
+ return undefined;
103
+ }
104
+ }
105
+ /** Removes a copy and its use record; a copy another tab is reading stays (false). */
106
+ async function removeCopy(folder, name) {
107
+ try {
108
+ await folder.removeEntry(name);
109
+ }
110
+ catch {
111
+ return false;
112
+ }
113
+ await folder.removeEntry(name + USED).catch(() => undefined);
114
+ return true;
115
+ }
116
+ /** Records that copy `name` was opened now. */
117
+ async function touch(folder, name) {
118
+ const used = (await folder.getFileHandle(name + USED, { create: true }));
119
+ const handle = await used.createSyncAccessHandle();
120
+ try {
121
+ const stamp = new Uint8Array(8);
122
+ new DataView(stamp.buffer).setFloat64(0, Date.now());
123
+ handle.truncate(0);
124
+ handle.write(stamp, { at: 0 });
125
+ handle.flush();
126
+ }
127
+ finally {
128
+ handle.close();
129
+ }
130
+ }
131
+ /** When copy `name` was last opened, else when it was made. */
132
+ async function lastUsed(folder, name, made) {
133
+ try {
134
+ const record = await (await folder.getFileHandle(name + USED)).getFile();
135
+ return new DataView(await record.arrayBuffer()).getFloat64(0);
136
+ }
137
+ catch {
138
+ return made;
139
+ }
140
+ }
141
+ /**
142
+ * Whether a copy of `size` bytes fits, making room by removing other copies, those used longest
143
+ * ago first. The copies together may take half of what is free for them (the quota's free space
144
+ * plus what the copies already hold), and never more than MAX_CACHE_BYTES.
145
+ */
146
+ async function makeRoom(folder, keep, size) {
147
+ const copies = [];
148
+ for await (const [name, entry] of folder.entries()) {
149
+ if (name === keep || name.endsWith(USED) || entry.kind !== "file")
150
+ continue;
151
+ const copy = await entry.getFile().catch(() => undefined);
152
+ if (copy !== undefined)
153
+ copies.push({ name, size: copy.size, used: await lastUsed(folder, name, copy.lastModified) });
154
+ }
155
+ let held = copies.reduce((sum, c) => sum + c.size, 0);
156
+ const { quota = 0, usage = 0 } = await navigator.storage.estimate();
157
+ const budget = Math.min(MAX_CACHE_BYTES, (quota - usage + held) / 2);
158
+ if (size > budget)
159
+ return false;
160
+ for (const copy of copies.sort((a, b) => a.used - b.used)) {
161
+ if (held + size <= budget)
162
+ break;
163
+ if (await removeCopy(folder, copy.name))
164
+ held -= copy.size;
165
+ }
166
+ return held + size <= budget;
167
+ }
168
+ async function copyInto(handle, file, options) {
169
+ handle.truncate(0);
170
+ for (let at = 0; at < file.size; at += CHUNK) {
171
+ options.signal.throwIfAborted();
172
+ const bytes = new Uint8Array(await file.slice(at, Math.min(file.size, at + CHUNK)).arrayBuffer());
173
+ handle.write(bytes, { at });
174
+ options.onProgress?.(Math.min(file.size, at + CHUNK), file.size);
175
+ }
176
+ handle.flush();
177
+ }
178
+ //# sourceMappingURL=opfs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"opfs.js","sourceRoot":"","sources":["../../src/source/opfs.ts"],"names":[],"mappings":"AAAA,kGAAkG;AAClG,8FAA8F;AAC9F,kGAAkG;AAClG,iGAAiG;AACjG,gGAAgG;AAChG,mGAAmG;AACnG,qFAAqF;AAKrF,iHAAiH;AACjH,MAAM,CAAC,MAAM,YAAY,GAAG,WAAW,CAAC;AAExC,iEAAiE;AACjE,MAAM,CAAC,MAAM,UAAU,GAAG,GAAG,GAAG,IAAI,GAAG,IAAI,CAAC;AAE5C,6FAA6F;AAC7F,MAAM,eAAe,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;AAE/C,8EAA8E;AAC9E,MAAM,KAAK,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC;AAE9B,0GAA0G;AAC1G,MAAM,IAAI,GAAG,OAAO,CAAC;AAcrB,qGAAqG;AACrG,MAAM,UAAU,QAAQ,CAAC,IAAkD;IACzE,IAAI,IAAI,GAAG,UAAU,CAAC;IACtB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE;QAAE,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC;IACtG,OAAO,GAAG,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,YAAY,IAAI,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,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AC;QAChC,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,MAAM,IAAI,CAAC,KAAK,CAAC,EAAE,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC;QAClG,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;QAC5B,OAAO,CAAC,UAAU,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,GAAG,KAAK,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;IACnE,CAAC;IACD,MAAM,CAAC,KAAK,EAAE,CAAC;AACjB,CAAC"}
@@ -1,6 +1,6 @@
1
1
  import type { PageInfo } from "@laminapdf/sdk";
2
2
  import type { ViewerClient } from "../client.js";
3
- import type { OpenedDocument } from "../protocol.js";
3
+ import { type OpenedDocument } from "../protocol.js";
4
4
  import type { Viewer } from "../view/viewer.js";
5
5
  /** How a strip looks and how much it keeps. */
6
6
  export interface ThumbnailStripOptions {
@@ -1 +1 @@
1
- {"version":3,"file":"strip.d.ts","sourceRoot":"","sources":["../../src/thumbnails/strip.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAG/C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAEjD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAEhD,+CAA+C;AAC/C,MAAM,WAAW,qBAAqB;IACpC,iEAAiE;IACjE,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,gEAAgE;IAChE,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,0DAA0D;IAC1D,QAAQ,CAAC,UAAU,CAAC,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