@docmentis/udoc-viewer 0.2.0 → 0.2.2
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/dist/package.json +1 -1
- package/dist/src/UDocClient.d.ts +101 -6
- package/dist/src/UDocClient.d.ts.map +1 -1
- package/dist/src/UDocClient.js +169 -24
- package/dist/src/UDocClient.js.map +1 -1
- package/dist/src/UDocViewer.d.ts +21 -5
- package/dist/src/UDocViewer.d.ts.map +1 -1
- package/dist/src/UDocViewer.js +45 -35
- package/dist/src/UDocViewer.js.map +1 -1
- package/dist/src/ui/viewer/components/LeftPanel.d.ts +2 -2
- package/dist/src/ui/viewer/components/LeftPanel.d.ts.map +1 -1
- package/dist/src/ui/viewer/components/LeftPanel.js +6 -6
- package/dist/src/ui/viewer/components/LeftPanel.js.map +1 -1
- package/dist/src/ui/viewer/components/Spread.d.ts +2 -2
- package/dist/src/ui/viewer/components/Spread.d.ts.map +1 -1
- package/dist/src/ui/viewer/components/Spread.js +2 -2
- package/dist/src/ui/viewer/components/Spread.js.map +1 -1
- package/dist/src/ui/viewer/components/ThumbnailPanel.d.ts +2 -2
- package/dist/src/ui/viewer/components/ThumbnailPanel.d.ts.map +1 -1
- package/dist/src/ui/viewer/components/ThumbnailPanel.js +5 -5
- package/dist/src/ui/viewer/components/ThumbnailPanel.js.map +1 -1
- package/dist/src/ui/viewer/components/Viewport.d.ts +2 -2
- package/dist/src/ui/viewer/components/Viewport.d.ts.map +1 -1
- package/dist/src/ui/viewer/components/Viewport.js +9 -9
- package/dist/src/ui/viewer/components/Viewport.js.map +1 -1
- package/dist/src/ui/viewer/effects.d.ts +2 -2
- package/dist/src/ui/viewer/effects.d.ts.map +1 -1
- package/dist/src/ui/viewer/effects.js +7 -6
- package/dist/src/ui/viewer/effects.js.map +1 -1
- package/dist/src/ui/viewer/shell.d.ts +2 -5
- package/dist/src/ui/viewer/shell.d.ts.map +1 -1
- package/dist/src/ui/viewer/shell.js +4 -6
- package/dist/src/ui/viewer/shell.js.map +1 -1
- package/dist/src/wasm/udoc.d.ts +106 -28
- package/dist/src/wasm/udoc.js +219 -44
- package/dist/src/wasm/udoc_bg.wasm +0 -0
- package/dist/src/wasm/udoc_bg.wasm.d.ts +6 -1
- package/dist/src/worker/WorkerClient.d.ts +91 -9
- package/dist/src/worker/WorkerClient.d.ts.map +1 -1
- package/dist/src/worker/WorkerClient.js +293 -15
- package/dist/src/worker/WorkerClient.js.map +1 -1
- package/dist/src/worker/index.d.ts +1 -1
- package/dist/src/worker/index.d.ts.map +1 -1
- package/dist/src/worker/worker.d.ts +93 -4
- package/dist/src/worker/worker.d.ts.map +1 -1
- package/dist/src/worker/worker.js +33 -3
- package/dist/src/worker/worker.js.map +1 -1
- package/package.json +1 -1
- package/dist/src/ui/viewer/rendering/RenderManager.d.ts +0 -76
- package/dist/src/ui/viewer/rendering/RenderManager.d.ts.map +0 -1
- package/dist/src/ui/viewer/rendering/RenderManager.js +0 -236
- package/dist/src/ui/viewer/rendering/RenderManager.js.map +0 -1
package/dist/package.json
CHANGED
package/dist/src/UDocClient.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Manages the WASM engine and provides document operations.
|
|
5
5
|
*/
|
|
6
6
|
import { WorkerClient } from "./worker/index.js";
|
|
7
|
-
import type { Composition, ComposePick } from "./worker/index.js";
|
|
7
|
+
import type { Composition, ComposePick, ExtractedFont, ExtractedImage, SplitByOutlineResult } from "./worker/index.js";
|
|
8
8
|
import { UDocViewer } from "./UDocViewer.js";
|
|
9
9
|
import type { ScrollMode, LayoutMode, ZoomMode, PanelTab } from "./ui/viewer/state.js";
|
|
10
10
|
/**
|
|
@@ -140,9 +140,9 @@ export interface Pick {
|
|
|
140
140
|
doc: DocumentSource;
|
|
141
141
|
/**
|
|
142
142
|
* Page range to pick. Can be:
|
|
143
|
-
* - A string like "
|
|
144
|
-
* - A single page
|
|
145
|
-
* - An array of page
|
|
143
|
+
* - A string like "0-2,4" (0-based page indices)
|
|
144
|
+
* - A single page index
|
|
145
|
+
* - An array of page indices
|
|
146
146
|
*/
|
|
147
147
|
pages: string | number | number[];
|
|
148
148
|
/**
|
|
@@ -154,7 +154,7 @@ export interface Pick {
|
|
|
154
154
|
/**
|
|
155
155
|
* Re-export low-level types for advanced usage.
|
|
156
156
|
*/
|
|
157
|
-
export type { Composition, ComposePick };
|
|
157
|
+
export type { Composition, ComposePick, ExtractedFont, ExtractedImage, SplitByOutlineResult };
|
|
158
158
|
/**
|
|
159
159
|
* SDK entry point for document viewing.
|
|
160
160
|
*
|
|
@@ -166,7 +166,6 @@ export declare class UDocClient {
|
|
|
166
166
|
*/
|
|
167
167
|
static readonly version: string;
|
|
168
168
|
private workerClient;
|
|
169
|
-
private renderManager;
|
|
170
169
|
private options;
|
|
171
170
|
private viewers;
|
|
172
171
|
private destroyed;
|
|
@@ -230,6 +229,102 @@ export declare class UDocClient {
|
|
|
230
229
|
* ```
|
|
231
230
|
*/
|
|
232
231
|
compose(compositions: Pick[][]): Promise<UDocViewer[]>;
|
|
232
|
+
/**
|
|
233
|
+
* Split a document by its outline (bookmarks) structure.
|
|
234
|
+
*
|
|
235
|
+
* Creates multiple documents, one for each outline section at the specified level.
|
|
236
|
+
* The original document remains unchanged.
|
|
237
|
+
*
|
|
238
|
+
* @param source - Document source (viewer, URL, File, or bytes)
|
|
239
|
+
* @param maxLevel - Maximum outline level to consider (1 = top level only)
|
|
240
|
+
* @returns Object with viewers array and sections metadata
|
|
241
|
+
*
|
|
242
|
+
* @example
|
|
243
|
+
* ```ts
|
|
244
|
+
* // Split a document by top-level bookmarks
|
|
245
|
+
* const result = await client.splitByOutline(viewer, 1);
|
|
246
|
+
* console.log(`Split into ${result.viewers.length} documents`);
|
|
247
|
+
* result.sections.forEach((section, i) => {
|
|
248
|
+
* console.log(`Document ${i}: ${section.title}`);
|
|
249
|
+
* });
|
|
250
|
+
* ```
|
|
251
|
+
*/
|
|
252
|
+
splitByOutline(source: DocumentSource, maxLevel?: number): Promise<{
|
|
253
|
+
viewers: UDocViewer[];
|
|
254
|
+
sections: {
|
|
255
|
+
title: string;
|
|
256
|
+
index: number;
|
|
257
|
+
}[];
|
|
258
|
+
}>;
|
|
259
|
+
/**
|
|
260
|
+
* Extract all embedded images from a document.
|
|
261
|
+
*
|
|
262
|
+
* @param source - Document source (viewer, URL, File, or bytes)
|
|
263
|
+
* @returns Array of extracted images with metadata and data
|
|
264
|
+
*
|
|
265
|
+
* @example
|
|
266
|
+
* ```ts
|
|
267
|
+
* const images = await client.extractImages(viewer);
|
|
268
|
+
* for (const image of images) {
|
|
269
|
+
* console.log(`${image.name}: ${image.format} (${image.width}x${image.height})`);
|
|
270
|
+
* // image.data contains the raw image bytes
|
|
271
|
+
* }
|
|
272
|
+
* ```
|
|
273
|
+
*/
|
|
274
|
+
extractImages(source: DocumentSource): Promise<ExtractedImage[]>;
|
|
275
|
+
/**
|
|
276
|
+
* Extract all embedded fonts from a document.
|
|
277
|
+
*
|
|
278
|
+
* @param source - Document source (viewer, URL, File, or bytes)
|
|
279
|
+
* @returns Array of extracted fonts with metadata and data
|
|
280
|
+
*
|
|
281
|
+
* @example
|
|
282
|
+
* ```ts
|
|
283
|
+
* const fonts = await client.extractFonts(viewer);
|
|
284
|
+
* for (const font of fonts) {
|
|
285
|
+
* console.log(`${font.name}: ${font.fontType} (.${font.extension})`);
|
|
286
|
+
* // font.data contains the raw font bytes
|
|
287
|
+
* }
|
|
288
|
+
* ```
|
|
289
|
+
*/
|
|
290
|
+
extractFonts(source: DocumentSource): Promise<ExtractedFont[]>;
|
|
291
|
+
/**
|
|
292
|
+
* Compress a document.
|
|
293
|
+
*
|
|
294
|
+
* Saves the document with full compression options enabled:
|
|
295
|
+
* - Compress stream data using FlateDecode
|
|
296
|
+
* - Pack objects into compressed object streams (PDF 1.5+)
|
|
297
|
+
* - Use compressed xref streams (PDF 1.5+)
|
|
298
|
+
* - Remove unreferenced objects
|
|
299
|
+
*
|
|
300
|
+
* @param source - Document source (viewer, URL, File, or bytes)
|
|
301
|
+
* @returns Compressed PDF data as Uint8Array
|
|
302
|
+
*
|
|
303
|
+
* @example
|
|
304
|
+
* ```ts
|
|
305
|
+
* const compressedBytes = await client.compress(viewer);
|
|
306
|
+
* // Save to file or download
|
|
307
|
+
* const blob = new Blob([compressedBytes], { type: 'application/pdf' });
|
|
308
|
+
* ```
|
|
309
|
+
*/
|
|
310
|
+
compress(source: DocumentSource): Promise<Uint8Array>;
|
|
311
|
+
/**
|
|
312
|
+
* Decompress a document.
|
|
313
|
+
*
|
|
314
|
+
* Removes all filter encodings from streams, resulting in raw,
|
|
315
|
+
* uncompressed stream data. Useful for debugging or inspection.
|
|
316
|
+
*
|
|
317
|
+
* @param source - Document source (viewer, URL, File, or bytes)
|
|
318
|
+
* @returns Decompressed PDF data as Uint8Array
|
|
319
|
+
*
|
|
320
|
+
* @example
|
|
321
|
+
* ```ts
|
|
322
|
+
* const decompressedBytes = await client.decompress(viewer);
|
|
323
|
+
* // Save to file for inspection
|
|
324
|
+
* const blob = new Blob([decompressedBytes], { type: 'application/pdf' });
|
|
325
|
+
* ```
|
|
326
|
+
*/
|
|
327
|
+
decompress(source: DocumentSource): Promise<Uint8Array>;
|
|
233
328
|
/**
|
|
234
329
|
* Load a document source and return its ID.
|
|
235
330
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UDocClient.d.ts","sourceRoot":"","sources":["../../src/UDocClient.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"UDocClient.d.ts","sourceRoot":"","sources":["../../src/UDocClient.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,KAAK,EAEV,WAAW,EACX,WAAW,EACX,aAAa,EACb,cAAc,EACd,oBAAoB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G,OAAO,CAAC,UAAU,EAAE,CAAC;IA2D5D;;;;;;;;;;;;;;;;;;;OAmBG;IACG,cAAc,CAClB,MAAM,EAAE,cAAc,EACtB,QAAQ,GAAE,MAAU,GACnB,OAAO,CAAC;QAAE,OAAO,EAAE,UAAU,EAAE,CAAC;QAAC,QAAQ,EAAE;YAAE,KAAK,EAAE,MAAM,CAAC;YAAC,KAAK,EAAE,MAAM,CAAA;SAAE,EAAE,CAAA;KAAE,CAAC;IA8BnF;;;;;;;;;;;;;;OAcG;IACG,aAAa,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC;IAetE;;;;;;;;;;;;;;OAcG;IACG,YAAY,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;IAepE;;;;;;;;;;;;;;;;;;OAkBG;IACG,QAAQ,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,UAAU,CAAC;IAe3D;;;;;;;;;;;;;;;OAeG;IACG,UAAU,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,UAAU,CAAC;IAe7D;;OAEG;YACW,UAAU;IAyBxB;;OAEG;IACH,OAAO,CAAC,cAAc;IAUtB;;;OAGG;IACH,OAAO,IAAI,IAAI;IAef;;;OAGG;IACH,eAAe,IAAI,YAAY;IAI/B,OAAO,CAAC,kBAAkB;CAK3B"}
|
package/dist/src/UDocClient.js
CHANGED
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { WorkerClient } from "./worker/index.js";
|
|
7
7
|
import { UDocViewer } from "./UDocViewer.js";
|
|
8
|
-
import { RenderManager } from "./ui/viewer/rendering/RenderManager.js";
|
|
9
8
|
import pkg from "../package.json" with { type: "json" };
|
|
10
9
|
/**
|
|
11
10
|
* SDK entry point for document viewing.
|
|
@@ -18,7 +17,6 @@ export class UDocClient {
|
|
|
18
17
|
*/
|
|
19
18
|
static version = pkg.version;
|
|
20
19
|
workerClient;
|
|
21
|
-
renderManager;
|
|
22
20
|
options;
|
|
23
21
|
viewers = new Set();
|
|
24
22
|
destroyed = false;
|
|
@@ -28,9 +26,8 @@ export class UDocClient {
|
|
|
28
26
|
features: [],
|
|
29
27
|
limits: {},
|
|
30
28
|
};
|
|
31
|
-
constructor(workerClient,
|
|
29
|
+
constructor(workerClient, options) {
|
|
32
30
|
this.workerClient = workerClient;
|
|
33
|
-
this.renderManager = renderManager;
|
|
34
31
|
this.options = options;
|
|
35
32
|
}
|
|
36
33
|
/**
|
|
@@ -47,20 +44,7 @@ export class UDocClient {
|
|
|
47
44
|
? new URL("udoc_bg.wasm", options.baseUrl).href
|
|
48
45
|
: undefined;
|
|
49
46
|
await workerClient.init(wasmUrl);
|
|
50
|
-
|
|
51
|
-
const renderManager = new RenderManager({
|
|
52
|
-
render: async (docId, page, scale) => {
|
|
53
|
-
const pageInfo = await workerClient.getPageInfo(docId, page - 1);
|
|
54
|
-
const width = Math.round(pageInfo.width * scale);
|
|
55
|
-
const height = Math.round(pageInfo.height * scale);
|
|
56
|
-
const rendered = await workerClient.renderPage(docId, page - 1, width, height);
|
|
57
|
-
const buffer = new ArrayBuffer(rendered.rgba.byteLength);
|
|
58
|
-
new Uint8Array(buffer).set(rendered.rgba);
|
|
59
|
-
const imageData = new ImageData(new Uint8ClampedArray(buffer), rendered.width, rendered.height);
|
|
60
|
-
return createImageBitmap(imageData);
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
const client = new UDocClient(workerClient, renderManager, options);
|
|
47
|
+
const client = new UDocClient(workerClient, options);
|
|
64
48
|
// Validate license if provided
|
|
65
49
|
if (options.license) {
|
|
66
50
|
const domain = typeof window !== "undefined"
|
|
@@ -95,7 +79,7 @@ export class UDocClient {
|
|
|
95
79
|
*/
|
|
96
80
|
async createViewer(options = {}) {
|
|
97
81
|
this.ensureNotDestroyed();
|
|
98
|
-
const viewer = new UDocViewer(this.workerClient,
|
|
82
|
+
const viewer = new UDocViewer(this.workerClient, options);
|
|
99
83
|
this.viewers.add(viewer);
|
|
100
84
|
return viewer;
|
|
101
85
|
}
|
|
@@ -165,7 +149,7 @@ export class UDocClient {
|
|
|
165
149
|
rotation: pick.rotation,
|
|
166
150
|
})));
|
|
167
151
|
// Execute compose
|
|
168
|
-
const newDocIds = await this.workerClient.
|
|
152
|
+
const newDocIds = await this.workerClient.pdfCompose(lowLevelCompositions, docIds);
|
|
169
153
|
// Unload temporary sources that weren't from viewers
|
|
170
154
|
for (const [source, docId] of sourceMap) {
|
|
171
155
|
if (!(source instanceof UDocViewer)) {
|
|
@@ -175,13 +159,176 @@ export class UDocClient {
|
|
|
175
159
|
// Create viewers for the composed documents
|
|
176
160
|
const viewers = [];
|
|
177
161
|
for (const docId of newDocIds) {
|
|
178
|
-
const viewer = new UDocViewer(this.workerClient,
|
|
162
|
+
const viewer = new UDocViewer(this.workerClient, {});
|
|
179
163
|
await viewer.initializeFromDocId(docId);
|
|
180
164
|
this.viewers.add(viewer);
|
|
181
165
|
viewers.push(viewer);
|
|
182
166
|
}
|
|
183
167
|
return viewers;
|
|
184
168
|
}
|
|
169
|
+
/**
|
|
170
|
+
* Split a document by its outline (bookmarks) structure.
|
|
171
|
+
*
|
|
172
|
+
* Creates multiple documents, one for each outline section at the specified level.
|
|
173
|
+
* The original document remains unchanged.
|
|
174
|
+
*
|
|
175
|
+
* @param source - Document source (viewer, URL, File, or bytes)
|
|
176
|
+
* @param maxLevel - Maximum outline level to consider (1 = top level only)
|
|
177
|
+
* @returns Object with viewers array and sections metadata
|
|
178
|
+
*
|
|
179
|
+
* @example
|
|
180
|
+
* ```ts
|
|
181
|
+
* // Split a document by top-level bookmarks
|
|
182
|
+
* const result = await client.splitByOutline(viewer, 1);
|
|
183
|
+
* console.log(`Split into ${result.viewers.length} documents`);
|
|
184
|
+
* result.sections.forEach((section, i) => {
|
|
185
|
+
* console.log(`Document ${i}: ${section.title}`);
|
|
186
|
+
* });
|
|
187
|
+
* ```
|
|
188
|
+
*/
|
|
189
|
+
async splitByOutline(source, maxLevel = 1) {
|
|
190
|
+
this.ensureNotDestroyed();
|
|
191
|
+
const docId = await this.loadSource(source);
|
|
192
|
+
const isTemporary = !(source instanceof UDocViewer);
|
|
193
|
+
try {
|
|
194
|
+
const result = await this.workerClient.pdfSplitByOutline(docId, maxLevel);
|
|
195
|
+
// Create viewers for the split documents
|
|
196
|
+
const viewers = [];
|
|
197
|
+
for (const newDocId of result.documentIds) {
|
|
198
|
+
const viewer = new UDocViewer(this.workerClient, {});
|
|
199
|
+
await viewer.initializeFromDocId(newDocId);
|
|
200
|
+
this.viewers.add(viewer);
|
|
201
|
+
viewers.push(viewer);
|
|
202
|
+
}
|
|
203
|
+
return {
|
|
204
|
+
viewers,
|
|
205
|
+
sections: result.sections,
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
finally {
|
|
209
|
+
// Unload temporary source
|
|
210
|
+
if (isTemporary) {
|
|
211
|
+
await this.workerClient.unloadPdf(docId);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Extract all embedded images from a document.
|
|
217
|
+
*
|
|
218
|
+
* @param source - Document source (viewer, URL, File, or bytes)
|
|
219
|
+
* @returns Array of extracted images with metadata and data
|
|
220
|
+
*
|
|
221
|
+
* @example
|
|
222
|
+
* ```ts
|
|
223
|
+
* const images = await client.extractImages(viewer);
|
|
224
|
+
* for (const image of images) {
|
|
225
|
+
* console.log(`${image.name}: ${image.format} (${image.width}x${image.height})`);
|
|
226
|
+
* // image.data contains the raw image bytes
|
|
227
|
+
* }
|
|
228
|
+
* ```
|
|
229
|
+
*/
|
|
230
|
+
async extractImages(source) {
|
|
231
|
+
this.ensureNotDestroyed();
|
|
232
|
+
const docId = await this.loadSource(source);
|
|
233
|
+
const isTemporary = !(source instanceof UDocViewer);
|
|
234
|
+
try {
|
|
235
|
+
return await this.workerClient.pdfExtractImages(docId);
|
|
236
|
+
}
|
|
237
|
+
finally {
|
|
238
|
+
if (isTemporary) {
|
|
239
|
+
await this.workerClient.unloadPdf(docId);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Extract all embedded fonts from a document.
|
|
245
|
+
*
|
|
246
|
+
* @param source - Document source (viewer, URL, File, or bytes)
|
|
247
|
+
* @returns Array of extracted fonts with metadata and data
|
|
248
|
+
*
|
|
249
|
+
* @example
|
|
250
|
+
* ```ts
|
|
251
|
+
* const fonts = await client.extractFonts(viewer);
|
|
252
|
+
* for (const font of fonts) {
|
|
253
|
+
* console.log(`${font.name}: ${font.fontType} (.${font.extension})`);
|
|
254
|
+
* // font.data contains the raw font bytes
|
|
255
|
+
* }
|
|
256
|
+
* ```
|
|
257
|
+
*/
|
|
258
|
+
async extractFonts(source) {
|
|
259
|
+
this.ensureNotDestroyed();
|
|
260
|
+
const docId = await this.loadSource(source);
|
|
261
|
+
const isTemporary = !(source instanceof UDocViewer);
|
|
262
|
+
try {
|
|
263
|
+
return await this.workerClient.pdfExtractFonts(docId);
|
|
264
|
+
}
|
|
265
|
+
finally {
|
|
266
|
+
if (isTemporary) {
|
|
267
|
+
await this.workerClient.unloadPdf(docId);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Compress a document.
|
|
273
|
+
*
|
|
274
|
+
* Saves the document with full compression options enabled:
|
|
275
|
+
* - Compress stream data using FlateDecode
|
|
276
|
+
* - Pack objects into compressed object streams (PDF 1.5+)
|
|
277
|
+
* - Use compressed xref streams (PDF 1.5+)
|
|
278
|
+
* - Remove unreferenced objects
|
|
279
|
+
*
|
|
280
|
+
* @param source - Document source (viewer, URL, File, or bytes)
|
|
281
|
+
* @returns Compressed PDF data as Uint8Array
|
|
282
|
+
*
|
|
283
|
+
* @example
|
|
284
|
+
* ```ts
|
|
285
|
+
* const compressedBytes = await client.compress(viewer);
|
|
286
|
+
* // Save to file or download
|
|
287
|
+
* const blob = new Blob([compressedBytes], { type: 'application/pdf' });
|
|
288
|
+
* ```
|
|
289
|
+
*/
|
|
290
|
+
async compress(source) {
|
|
291
|
+
this.ensureNotDestroyed();
|
|
292
|
+
const docId = await this.loadSource(source);
|
|
293
|
+
const isTemporary = !(source instanceof UDocViewer);
|
|
294
|
+
try {
|
|
295
|
+
return await this.workerClient.pdfCompress(docId);
|
|
296
|
+
}
|
|
297
|
+
finally {
|
|
298
|
+
if (isTemporary) {
|
|
299
|
+
await this.workerClient.unloadPdf(docId);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Decompress a document.
|
|
305
|
+
*
|
|
306
|
+
* Removes all filter encodings from streams, resulting in raw,
|
|
307
|
+
* uncompressed stream data. Useful for debugging or inspection.
|
|
308
|
+
*
|
|
309
|
+
* @param source - Document source (viewer, URL, File, or bytes)
|
|
310
|
+
* @returns Decompressed PDF data as Uint8Array
|
|
311
|
+
*
|
|
312
|
+
* @example
|
|
313
|
+
* ```ts
|
|
314
|
+
* const decompressedBytes = await client.decompress(viewer);
|
|
315
|
+
* // Save to file for inspection
|
|
316
|
+
* const blob = new Blob([decompressedBytes], { type: 'application/pdf' });
|
|
317
|
+
* ```
|
|
318
|
+
*/
|
|
319
|
+
async decompress(source) {
|
|
320
|
+
this.ensureNotDestroyed();
|
|
321
|
+
const docId = await this.loadSource(source);
|
|
322
|
+
const isTemporary = !(source instanceof UDocViewer);
|
|
323
|
+
try {
|
|
324
|
+
return await this.workerClient.pdfDecompress(docId);
|
|
325
|
+
}
|
|
326
|
+
finally {
|
|
327
|
+
if (isTemporary) {
|
|
328
|
+
await this.workerClient.unloadPdf(docId);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
}
|
|
185
332
|
/**
|
|
186
333
|
* Load a document source and return its ID.
|
|
187
334
|
*/
|
|
@@ -234,9 +381,7 @@ export class UDocClient {
|
|
|
234
381
|
viewer.destroy();
|
|
235
382
|
}
|
|
236
383
|
this.viewers.clear();
|
|
237
|
-
//
|
|
238
|
-
this.renderManager.destroy();
|
|
239
|
-
// Terminate the worker
|
|
384
|
+
// Terminate the worker (also cleans up render resources)
|
|
240
385
|
this.workerClient.terminate();
|
|
241
386
|
}
|
|
242
387
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UDocClient.js","sourceRoot":"","sources":["../../src/UDocClient.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"UDocClient.js","sourceRoot":"","sources":["../../src/UDocClient.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AASjD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,GAAG,MAAM,iBAAiB,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAC;AAgLxD;;;;GAIG;AACH,MAAM,OAAO,UAAU;IACrB;;OAEG;IACH,MAAM,CAAU,OAAO,GAAW,GAAG,CAAC,OAAO,CAAC;IAEtC,YAAY,CAAe;IAC3B,OAAO,CAAgB;IACvB,OAAO,GAAoB,IAAI,GAAG,EAAE,CAAC;IACrC,SAAS,GAAG,KAAK,CAAC;IAClB,WAAW,GAAgB;QACjC,KAAK,EAAE,IAAI;QACX,IAAI,EAAE,MAAM;QACZ,QAAQ,EAAE,EAAE;QACZ,MAAM,EAAE,EAAE;KACX,CAAC;IAEF,YAAoB,YAA0B,EAAE,OAAsB;QACpE,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,UAAyB,EAAE;QAC7C,kFAAkF;QAClF,MAAM,YAAY,GAAG,OAAO,CAAC,OAAO;YAClC,CAAC,CAAC,Y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AI,mBAAmB,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,MAAM;QAC/D,QAAQ,EAAE,MAAM,CAAC,QAAQ;QACzB,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,YAAY,EAAE,MAAM,CAAC,YAAY;QACjC,SAAS,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,SAAS,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS;QAC3E,KAAK,EAAE,MAAM,CAAC,KAAK;KACpB,CAAC;AACJ,CAAC"}
|
package/dist/src/UDocViewer.d.ts
CHANGED
|
@@ -6,7 +6,6 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import type { WorkerClient, PageInfo } from "./worker/index.js";
|
|
8
8
|
import type { ViewerOptions } from "./UDocClient.js";
|
|
9
|
-
import type { RenderManager } from "./ui/viewer/rendering/RenderManager.js";
|
|
10
9
|
import type { Destination, OutlineItem } from "./ui/viewer/navigation.js";
|
|
11
10
|
import type { Annotation } from "./ui/viewer/annotation/index.js";
|
|
12
11
|
export type { Annotation } from "./ui/viewer/annotation/index.js";
|
|
@@ -25,7 +24,7 @@ export interface RenderOptions {
|
|
|
25
24
|
* Output format.
|
|
26
25
|
* @default 'image-data'
|
|
27
26
|
*/
|
|
28
|
-
format?: "image-data" | "blob" | "data-url";
|
|
27
|
+
format?: "image-data" | "image-bitmap" | "blob" | "data-url";
|
|
29
28
|
/**
|
|
30
29
|
* Image type when format is 'blob' or 'data-url'.
|
|
31
30
|
* @default 'image/png'
|
|
@@ -45,7 +44,7 @@ export interface RenderOptions {
|
|
|
45
44
|
/**
|
|
46
45
|
* Rendered page result.
|
|
47
46
|
*/
|
|
48
|
-
export type RenderedPage = ImageData | Blob | string;
|
|
47
|
+
export type RenderedPage = ImageData | ImageBitmap | Blob | string;
|
|
49
48
|
/**
|
|
50
49
|
* Document metadata.
|
|
51
50
|
*/
|
|
@@ -85,7 +84,6 @@ type EventHandler<K extends keyof ViewerEventMap> = (payload: ViewerEventMap[K])
|
|
|
85
84
|
*/
|
|
86
85
|
export declare class UDocViewer {
|
|
87
86
|
private workerClient;
|
|
88
|
-
private renderManager;
|
|
89
87
|
private container;
|
|
90
88
|
private uiShell;
|
|
91
89
|
private documentId;
|
|
@@ -97,7 +95,7 @@ export declare class UDocViewer {
|
|
|
97
95
|
* @internal
|
|
98
96
|
* Use `client.createViewer()` instead.
|
|
99
97
|
*/
|
|
100
|
-
constructor(workerClient: WorkerClient,
|
|
98
|
+
constructor(workerClient: WorkerClient, options?: ViewerOptions);
|
|
101
99
|
private buildStateOverrides;
|
|
102
100
|
/**
|
|
103
101
|
* Load a document.
|
|
@@ -159,6 +157,24 @@ export declare class UDocViewer {
|
|
|
159
157
|
* @param options - Render options (scale, format, etc.)
|
|
160
158
|
*/
|
|
161
159
|
renderPage(page: number, options?: RenderOptions): Promise<RenderedPage>;
|
|
160
|
+
/**
|
|
161
|
+
* Render a thumbnail of a page.
|
|
162
|
+
*
|
|
163
|
+
* Similar to renderPage but uses lower priority in the render queue,
|
|
164
|
+
* making it suitable for generating thumbnails without blocking main page renders.
|
|
165
|
+
*
|
|
166
|
+
* @param page - Page index (0-based)
|
|
167
|
+
* @param options - Render options (scale, format, etc.)
|
|
168
|
+
*/
|
|
169
|
+
renderThumbnail(page: number, options?: RenderOptions): Promise<RenderedPage>;
|
|
170
|
+
/**
|
|
171
|
+
* Internal method to render a page with a specific render type.
|
|
172
|
+
*/
|
|
173
|
+
private renderWithType;
|
|
174
|
+
/**
|
|
175
|
+
* Convert an ImageBitmap to the requested output format.
|
|
176
|
+
*/
|
|
177
|
+
private convertBitmapToFormat;
|
|
162
178
|
/**
|
|
163
179
|
* Export document as bytes.
|
|
164
180
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UDocViewer.d.ts","sourceRoot":"","sources":["../../src/UDocViewer.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,K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;IAmB3B,OAAO,CAAC,IAAI;IAaZ,OAAO,CAAC,mBAAmB;IAiB3B,OAAO,CAAC,kBAAkB;IAM1B,OAAO,CAAC,YAAY;CAMrB"}
|
package/dist/src/UDocViewer.js
CHANGED
|
@@ -13,7 +13,6 @@ import { mountViewerShell } from "./ui/viewer/shell.js";
|
|
|
13
13
|
*/
|
|
14
14
|
export class UDocViewer {
|
|
15
15
|
workerClient;
|
|
16
|
-
renderManager;
|
|
17
16
|
container = null;
|
|
18
17
|
uiShell = null;
|
|
19
18
|
documentId = null;
|
|
@@ -25,13 +24,12 @@ export class UDocViewer {
|
|
|
25
24
|
* @internal
|
|
26
25
|
* Use `client.createViewer()` instead.
|
|
27
26
|
*/
|
|
28
|
-
constructor(workerClient,
|
|
27
|
+
constructor(workerClient, options = {}) {
|
|
29
28
|
this.workerClient = workerClient;
|
|
30
|
-
this.renderManager = renderManager;
|
|
31
29
|
if (options.container) {
|
|
32
30
|
this.container = this.resolveContainer(options.container);
|
|
33
31
|
const overrides = this.buildStateOverrides(options);
|
|
34
|
-
this.uiShell = mountViewerShell(this.container, this.createEngineAdapter(), this.
|
|
32
|
+
this.uiShell = mountViewerShell(this.container, this.createEngineAdapter(), this.workerClient, overrides);
|
|
35
33
|
}
|
|
36
34
|
}
|
|
37
35
|
buildStateOverrides(options) {
|
|
@@ -122,9 +120,9 @@ export class UDocViewer {
|
|
|
122
120
|
close() {
|
|
123
121
|
if (this.documentId) {
|
|
124
122
|
const docId = this.documentId;
|
|
125
|
-
// Clean up
|
|
126
|
-
this.
|
|
127
|
-
this.
|
|
123
|
+
// Clean up render cache first (cancel pending, clear cache)
|
|
124
|
+
this.workerClient.cancelRenders(docId);
|
|
125
|
+
this.workerClient.invalidateRenderCache(docId);
|
|
128
126
|
// Unload from WASM worker
|
|
129
127
|
this.workerClient.unloadPdf(docId).catch(() => {
|
|
130
128
|
// Ignore errors during close
|
|
@@ -243,29 +241,52 @@ export class UDocViewer {
|
|
|
243
241
|
* @param options - Render options (scale, format, etc.)
|
|
244
242
|
*/
|
|
245
243
|
async renderPage(page, options = {}) {
|
|
244
|
+
return this.renderWithType(page, "page", options);
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Render a thumbnail of a page.
|
|
248
|
+
*
|
|
249
|
+
* Similar to renderPage but uses lower priority in the render queue,
|
|
250
|
+
* making it suitable for generating thumbnails without blocking main page renders.
|
|
251
|
+
*
|
|
252
|
+
* @param page - Page index (0-based)
|
|
253
|
+
* @param options - Render options (scale, format, etc.)
|
|
254
|
+
*/
|
|
255
|
+
async renderThumbnail(page, options = {}) {
|
|
256
|
+
return this.renderWithType(page, "thumbnail", options);
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Internal method to render a page with a specific render type.
|
|
260
|
+
*/
|
|
261
|
+
async renderWithType(page, type, options = {}) {
|
|
246
262
|
this.ensureLoaded();
|
|
247
263
|
const scale = options.scale ?? 1;
|
|
248
264
|
const format = options.format ?? "image-data";
|
|
249
|
-
//
|
|
250
|
-
const
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
//
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
265
|
+
// Request render through WorkerClient (uses 1-based page numbers)
|
|
266
|
+
const result = await this.workerClient.requestRender({
|
|
267
|
+
docId: this.documentId,
|
|
268
|
+
page: page + 1,
|
|
269
|
+
type,
|
|
270
|
+
scale
|
|
271
|
+
});
|
|
272
|
+
// Convert ImageBitmap to the requested format
|
|
273
|
+
return this.convertBitmapToFormat(result.bitmap, format, options);
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Convert an ImageBitmap to the requested output format.
|
|
277
|
+
*/
|
|
278
|
+
async convertBitmapToFormat(bitmap, format, options) {
|
|
279
|
+
if (format === "image-bitmap") {
|
|
280
|
+
return bitmap;
|
|
262
281
|
}
|
|
263
|
-
// Convert to blob or data URL using HTMLCanvasElement
|
|
264
282
|
const canvas = document.createElement("canvas");
|
|
265
|
-
canvas.width =
|
|
266
|
-
canvas.height =
|
|
283
|
+
canvas.width = bitmap.width;
|
|
284
|
+
canvas.height = bitmap.height;
|
|
267
285
|
const ctx = canvas.getContext("2d");
|
|
268
|
-
ctx.
|
|
286
|
+
ctx.drawImage(bitmap, 0, 0);
|
|
287
|
+
if (format === "image-data") {
|
|
288
|
+
return ctx.getImageData(0, 0, bitmap.width, bitmap.height);
|
|
289
|
+
}
|
|
269
290
|
const imageType = options.imageType ?? "image/png";
|
|
270
291
|
const quality = options.quality ?? 0.92;
|
|
271
292
|
if (format === "blob") {
|
|
@@ -436,17 +457,6 @@ export class UDocViewer {
|
|
|
436
457
|
}
|
|
437
458
|
createEngineAdapter() {
|
|
438
459
|
return {
|
|
439
|
-
renderPage: async (doc, page, zoom) => {
|
|
440
|
-
const pageIndex = Math.max(0, page - 1);
|
|
441
|
-
const pageSize = this._pageInfo[pageIndex] ?? { width: 0, height: 0 };
|
|
442
|
-
const width = Math.round(pageSize.width * zoom);
|
|
443
|
-
const height = Math.round(pageSize.height * zoom);
|
|
444
|
-
const rendered = await this.workerClient.renderPage(doc.id, pageIndex, width, height);
|
|
445
|
-
const buffer = new ArrayBuffer(rendered.rgba.byteLength);
|
|
446
|
-
new Uint8Array(buffer).set(rendered.rgba);
|
|
447
|
-
const imageData = new ImageData(new Uint8ClampedArray(buffer), rendered.width, rendered.height);
|
|
448
|
-
return createImageBitmap(imageData);
|
|
449
|
-
},
|
|
450
460
|
getPageInfo: async (_doc, page) => {
|
|
451
461
|
const pageIndex = Math.max(0, page - 1);
|
|
452
462
|
return this._pageInfo[pageIndex] ?? { width: 0, height: 0 };
|