@docmentis/udoc-viewer 0.2.1 → 0.2.3
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 +113 -3
- package/dist/src/UDocClient.d.ts.map +1 -1
- package/dist/src/UDocClient.js +181 -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 +107 -27
- package/dist/src/wasm/udoc.js +223 -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 +93 -9
- package/dist/src/worker/WorkerClient.d.ts.map +1 -1
- package/dist/src/worker/WorkerClient.js +295 -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 +94 -3
- package/dist/src/worker/worker.d.ts.map +1 -1
- package/dist/src/worker/worker.js +47 -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
|
/**
|
|
@@ -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,117 @@ 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 options - Split options
|
|
240
|
+
* @param options.maxLevel - Maximum outline level to consider (1 = top level only, default: 1)
|
|
241
|
+
* @param options.splitMidPage - When true, filters page content when sections share a page (default: false)
|
|
242
|
+
* @returns Object with viewers array and sections metadata
|
|
243
|
+
*
|
|
244
|
+
* @example
|
|
245
|
+
* ```ts
|
|
246
|
+
* // Split a document by top-level bookmarks
|
|
247
|
+
* const result = await client.splitByOutline(viewer);
|
|
248
|
+
* console.log(`Split into ${result.viewers.length} documents`);
|
|
249
|
+
* result.sections.forEach((section, i) => {
|
|
250
|
+
* console.log(`Document ${i}: ${section.title}`);
|
|
251
|
+
* });
|
|
252
|
+
*
|
|
253
|
+
* // Split with mid-page content filtering
|
|
254
|
+
* const result = await client.splitByOutline(viewer, { maxLevel: 2, splitMidPage: true });
|
|
255
|
+
* ```
|
|
256
|
+
*/
|
|
257
|
+
splitByOutline(source: DocumentSource, options?: {
|
|
258
|
+
maxLevel?: number;
|
|
259
|
+
splitMidPage?: boolean;
|
|
260
|
+
}): Promise<{
|
|
261
|
+
viewers: UDocViewer[];
|
|
262
|
+
sections: {
|
|
263
|
+
title: string;
|
|
264
|
+
index: number;
|
|
265
|
+
}[];
|
|
266
|
+
}>;
|
|
267
|
+
/**
|
|
268
|
+
* Extract all embedded images from a document.
|
|
269
|
+
*
|
|
270
|
+
* @param source - Document source (viewer, URL, File, or bytes)
|
|
271
|
+
* @param options - Extract options
|
|
272
|
+
* @param options.convertRawToPng - When true, converts raw pixel data to PNG format (default: false)
|
|
273
|
+
* @returns Array of extracted images with metadata and data
|
|
274
|
+
*
|
|
275
|
+
* @example
|
|
276
|
+
* ```ts
|
|
277
|
+
* const images = await client.extractImages(viewer);
|
|
278
|
+
* for (const image of images) {
|
|
279
|
+
* console.log(`${image.name}: ${image.format} (${image.width}x${image.height})`);
|
|
280
|
+
* // image.data contains the raw image bytes
|
|
281
|
+
* }
|
|
282
|
+
*
|
|
283
|
+
* // Convert raw images to PNG for easier viewing
|
|
284
|
+
* const pngImages = await client.extractImages(viewer, { convertRawToPng: true });
|
|
285
|
+
* ```
|
|
286
|
+
*/
|
|
287
|
+
extractImages(source: DocumentSource, options?: {
|
|
288
|
+
convertRawToPng?: boolean;
|
|
289
|
+
}): Promise<ExtractedImage[]>;
|
|
290
|
+
/**
|
|
291
|
+
* Extract all embedded fonts from a document.
|
|
292
|
+
*
|
|
293
|
+
* @param source - Document source (viewer, URL, File, or bytes)
|
|
294
|
+
* @returns Array of extracted fonts with metadata and data
|
|
295
|
+
*
|
|
296
|
+
* @example
|
|
297
|
+
* ```ts
|
|
298
|
+
* const fonts = await client.extractFonts(viewer);
|
|
299
|
+
* for (const font of fonts) {
|
|
300
|
+
* console.log(`${font.name}: ${font.fontType} (.${font.extension})`);
|
|
301
|
+
* // font.data contains the raw font bytes
|
|
302
|
+
* }
|
|
303
|
+
* ```
|
|
304
|
+
*/
|
|
305
|
+
extractFonts(source: DocumentSource): Promise<ExtractedFont[]>;
|
|
306
|
+
/**
|
|
307
|
+
* Compress a document.
|
|
308
|
+
*
|
|
309
|
+
* Saves the document with full compression options enabled:
|
|
310
|
+
* - Compress stream data using FlateDecode
|
|
311
|
+
* - Pack objects into compressed object streams (PDF 1.5+)
|
|
312
|
+
* - Use compressed xref streams (PDF 1.5+)
|
|
313
|
+
* - Remove unreferenced objects
|
|
314
|
+
*
|
|
315
|
+
* @param source - Document source (viewer, URL, File, or bytes)
|
|
316
|
+
* @returns Compressed PDF data as Uint8Array
|
|
317
|
+
*
|
|
318
|
+
* @example
|
|
319
|
+
* ```ts
|
|
320
|
+
* const compressedBytes = await client.compress(viewer);
|
|
321
|
+
* // Save to file or download
|
|
322
|
+
* const blob = new Blob([compressedBytes], { type: 'application/pdf' });
|
|
323
|
+
* ```
|
|
324
|
+
*/
|
|
325
|
+
compress(source: DocumentSource): Promise<Uint8Array>;
|
|
326
|
+
/**
|
|
327
|
+
* Decompress a document.
|
|
328
|
+
*
|
|
329
|
+
* Removes all filter encodings from streams, resulting in raw,
|
|
330
|
+
* uncompressed stream data. Useful for debugging or inspection.
|
|
331
|
+
*
|
|
332
|
+
* @param source - Document source (viewer, URL, File, or bytes)
|
|
333
|
+
* @returns Decompressed PDF data as Uint8Array
|
|
334
|
+
*
|
|
335
|
+
* @example
|
|
336
|
+
* ```ts
|
|
337
|
+
* const decompressedBytes = await client.decompress(viewer);
|
|
338
|
+
* // Save to file for inspection
|
|
339
|
+
* const blob = new Blob([decompressedBytes], { type: 'application/pdf' });
|
|
340
|
+
* ```
|
|
341
|
+
*/
|
|
342
|
+
decompress(source: DocumentSource): Promise<Uint8Array>;
|
|
233
343
|
/**
|
|
234
344
|
* Load a document source and return its ID.
|
|
235
345
|
*/
|
|
@@ -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/UD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|
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,188 @@ 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 options - Split options
|
|
177
|
+
* @param options.maxLevel - Maximum outline level to consider (1 = top level only, default: 1)
|
|
178
|
+
* @param options.splitMidPage - When true, filters page content when sections share a page (default: false)
|
|
179
|
+
* @returns Object with viewers array and sections metadata
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* ```ts
|
|
183
|
+
* // Split a document by top-level bookmarks
|
|
184
|
+
* const result = await client.splitByOutline(viewer);
|
|
185
|
+
* console.log(`Split into ${result.viewers.length} documents`);
|
|
186
|
+
* result.sections.forEach((section, i) => {
|
|
187
|
+
* console.log(`Document ${i}: ${section.title}`);
|
|
188
|
+
* });
|
|
189
|
+
*
|
|
190
|
+
* // Split with mid-page content filtering
|
|
191
|
+
* const result = await client.splitByOutline(viewer, { maxLevel: 2, splitMidPage: true });
|
|
192
|
+
* ```
|
|
193
|
+
*/
|
|
194
|
+
async splitByOutline(source, options = {}) {
|
|
195
|
+
this.ensureNotDestroyed();
|
|
196
|
+
const { maxLevel = 1, splitMidPage = false } = options;
|
|
197
|
+
const docId = await this.loadSource(source);
|
|
198
|
+
const isTemporary = !(source instanceof UDocViewer);
|
|
199
|
+
try {
|
|
200
|
+
const result = await this.workerClient.pdfSplitByOutline(docId, maxLevel, splitMidPage);
|
|
201
|
+
// Create viewers for the split documents
|
|
202
|
+
const viewers = [];
|
|
203
|
+
for (const newDocId of result.documentIds) {
|
|
204
|
+
const viewer = new UDocViewer(this.workerClient, {});
|
|
205
|
+
await viewer.initializeFromDocId(newDocId);
|
|
206
|
+
this.viewers.add(viewer);
|
|
207
|
+
viewers.push(viewer);
|
|
208
|
+
}
|
|
209
|
+
return {
|
|
210
|
+
viewers,
|
|
211
|
+
sections: result.sections,
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
finally {
|
|
215
|
+
// Unload temporary source
|
|
216
|
+
if (isTemporary) {
|
|
217
|
+
await this.workerClient.unloadPdf(docId);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Extract all embedded images from a document.
|
|
223
|
+
*
|
|
224
|
+
* @param source - Document source (viewer, URL, File, or bytes)
|
|
225
|
+
* @param options - Extract options
|
|
226
|
+
* @param options.convertRawToPng - When true, converts raw pixel data to PNG format (default: false)
|
|
227
|
+
* @returns Array of extracted images with metadata and data
|
|
228
|
+
*
|
|
229
|
+
* @example
|
|
230
|
+
* ```ts
|
|
231
|
+
* const images = await client.extractImages(viewer);
|
|
232
|
+
* for (const image of images) {
|
|
233
|
+
* console.log(`${image.name}: ${image.format} (${image.width}x${image.height})`);
|
|
234
|
+
* // image.data contains the raw image bytes
|
|
235
|
+
* }
|
|
236
|
+
*
|
|
237
|
+
* // Convert raw images to PNG for easier viewing
|
|
238
|
+
* const pngImages = await client.extractImages(viewer, { convertRawToPng: true });
|
|
239
|
+
* ```
|
|
240
|
+
*/
|
|
241
|
+
async extractImages(source, options = {}) {
|
|
242
|
+
this.ensureNotDestroyed();
|
|
243
|
+
const { convertRawToPng = false } = options;
|
|
244
|
+
const docId = await this.loadSource(source);
|
|
245
|
+
const isTemporary = !(source instanceof UDocViewer);
|
|
246
|
+
try {
|
|
247
|
+
return await this.workerClient.pdfExtractImages(docId, convertRawToPng);
|
|
248
|
+
}
|
|
249
|
+
finally {
|
|
250
|
+
if (isTemporary) {
|
|
251
|
+
await this.workerClient.unloadPdf(docId);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Extract all embedded fonts from a document.
|
|
257
|
+
*
|
|
258
|
+
* @param source - Document source (viewer, URL, File, or bytes)
|
|
259
|
+
* @returns Array of extracted fonts with metadata and data
|
|
260
|
+
*
|
|
261
|
+
* @example
|
|
262
|
+
* ```ts
|
|
263
|
+
* const fonts = await client.extractFonts(viewer);
|
|
264
|
+
* for (const font of fonts) {
|
|
265
|
+
* console.log(`${font.name}: ${font.fontType} (.${font.extension})`);
|
|
266
|
+
* // font.data contains the raw font bytes
|
|
267
|
+
* }
|
|
268
|
+
* ```
|
|
269
|
+
*/
|
|
270
|
+
async extractFonts(source) {
|
|
271
|
+
this.ensureNotDestroyed();
|
|
272
|
+
const docId = await this.loadSource(source);
|
|
273
|
+
const isTemporary = !(source instanceof UDocViewer);
|
|
274
|
+
try {
|
|
275
|
+
return await this.workerClient.pdfExtractFonts(docId);
|
|
276
|
+
}
|
|
277
|
+
finally {
|
|
278
|
+
if (isTemporary) {
|
|
279
|
+
await this.workerClient.unloadPdf(docId);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Compress a document.
|
|
285
|
+
*
|
|
286
|
+
* Saves the document with full compression options enabled:
|
|
287
|
+
* - Compress stream data using FlateDecode
|
|
288
|
+
* - Pack objects into compressed object streams (PDF 1.5+)
|
|
289
|
+
* - Use compressed xref streams (PDF 1.5+)
|
|
290
|
+
* - Remove unreferenced objects
|
|
291
|
+
*
|
|
292
|
+
* @param source - Document source (viewer, URL, File, or bytes)
|
|
293
|
+
* @returns Compressed PDF data as Uint8Array
|
|
294
|
+
*
|
|
295
|
+
* @example
|
|
296
|
+
* ```ts
|
|
297
|
+
* const compressedBytes = await client.compress(viewer);
|
|
298
|
+
* // Save to file or download
|
|
299
|
+
* const blob = new Blob([compressedBytes], { type: 'application/pdf' });
|
|
300
|
+
* ```
|
|
301
|
+
*/
|
|
302
|
+
async compress(source) {
|
|
303
|
+
this.ensureNotDestroyed();
|
|
304
|
+
const docId = await this.loadSource(source);
|
|
305
|
+
const isTemporary = !(source instanceof UDocViewer);
|
|
306
|
+
try {
|
|
307
|
+
return await this.workerClient.pdfCompress(docId);
|
|
308
|
+
}
|
|
309
|
+
finally {
|
|
310
|
+
if (isTemporary) {
|
|
311
|
+
await this.workerClient.unloadPdf(docId);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* Decompress a document.
|
|
317
|
+
*
|
|
318
|
+
* Removes all filter encodings from streams, resulting in raw,
|
|
319
|
+
* uncompressed stream data. Useful for debugging or inspection.
|
|
320
|
+
*
|
|
321
|
+
* @param source - Document source (viewer, URL, File, or bytes)
|
|
322
|
+
* @returns Decompressed PDF data as Uint8Array
|
|
323
|
+
*
|
|
324
|
+
* @example
|
|
325
|
+
* ```ts
|
|
326
|
+
* const decompressedBytes = await client.decompress(viewer);
|
|
327
|
+
* // Save to file for inspection
|
|
328
|
+
* const blob = new Blob([decompressedBytes], { type: 'application/pdf' });
|
|
329
|
+
* ```
|
|
330
|
+
*/
|
|
331
|
+
async decompress(source) {
|
|
332
|
+
this.ensureNotDestroyed();
|
|
333
|
+
const docId = await this.loadSource(source);
|
|
334
|
+
const isTemporary = !(source instanceof UDocViewer);
|
|
335
|
+
try {
|
|
336
|
+
return await this.workerClient.pdfDecompress(docId);
|
|
337
|
+
}
|
|
338
|
+
finally {
|
|
339
|
+
if (isTemporary) {
|
|
340
|
+
await this.workerClient.unloadPdf(docId);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
}
|
|
185
344
|
/**
|
|
186
345
|
* Load a document source and return its ID.
|
|
187
346
|
*/
|
|
@@ -234,9 +393,7 @@ export class UDocClient {
|
|
|
234
393
|
viewer.destroy();
|
|
235
394
|
}
|
|
236
395
|
this.viewers.clear();
|
|
237
|
-
//
|
|
238
|
-
this.renderManager.destroy();
|
|
239
|
-
// Terminate the worker
|
|
396
|
+
// Terminate the worker (also cleans up render resources)
|
|
240
397
|
this.workerClient.terminate();
|
|
241
398
|
}
|
|
242
399
|
/**
|
|
@@ -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,m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,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,KAAK,EAAE,YAAY,EAAE,QAAQ,
|
|
1
|
+
{"version":3,"file":"UDocViewer.d.ts","sourceRoot":"","sources":["../../src/UDocViewer.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAc,MAAM,mBAAmB,CAAC;AAC5E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAErD,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