unpdf 0.12.2 → 1.0.0
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/README.md +147 -79
- package/dist/index.cjs +118 -73
- package/dist/index.d.cts +24 -41
- package/dist/index.d.mts +24 -41
- package/dist/index.d.ts +24 -41
- package/dist/index.mjs +117 -72
- package/dist/pdfjs.mjs +1 -1
- package/dist/types/src/display/annotation_layer.d.ts +25 -1
- package/dist/types/src/display/annotation_storage.d.ts +1 -8
- package/dist/types/src/display/api.d.ts +147 -57
- package/dist/types/src/display/canvas.d.ts +21 -28
- package/dist/types/src/display/canvas_factory.d.ts +27 -0
- package/dist/types/src/display/cmap_reader_factory.d.ts +25 -0
- package/dist/types/src/display/display_utils.d.ts +40 -60
- package/dist/types/src/display/draw_layer.d.ts +7 -19
- package/dist/types/src/display/editor/alt_text.d.ts +3 -2
- package/dist/types/src/display/editor/annotation_editor_layer.d.ts +16 -11
- package/dist/types/src/display/editor/color_picker.d.ts +1 -0
- package/dist/types/src/display/editor/draw.d.ts +121 -0
- package/dist/types/src/display/editor/drawers/contour.d.ts +3 -0
- package/dist/types/src/display/editor/drawers/freedraw.d.ts +31 -0
- package/dist/types/src/display/editor/drawers/highlight.d.ts +36 -0
- package/dist/types/src/display/editor/drawers/inkdraw.d.ts +129 -0
- package/dist/types/src/display/editor/drawers/outline.d.ts +19 -0
- package/dist/types/src/display/editor/drawers/signaturedraw.d.ts +79 -0
- package/dist/types/src/display/editor/editor.d.ts +55 -13
- package/dist/types/src/display/editor/freetext.d.ts +5 -16
- package/dist/types/src/display/editor/highlight.d.ts +8 -25
- package/dist/types/src/display/editor/ink.d.ts +21 -74
- package/dist/types/src/display/editor/signature.d.ts +80 -0
- package/dist/types/src/display/editor/stamp.d.ts +16 -22
- package/dist/types/src/display/editor/toolbar.d.ts +5 -2
- package/dist/types/src/display/editor/tools.d.ts +17 -9
- package/dist/types/src/display/fetch_stream.d.ts +6 -13
- package/dist/types/src/display/filter_factory.d.ts +29 -0
- package/dist/types/src/display/font_loader.d.ts +3 -6
- package/dist/types/src/display/metadata.d.ts +1 -2
- package/dist/types/src/display/network.d.ts +11 -7
- package/dist/types/src/display/network_utils.d.ts +7 -6
- package/dist/types/src/display/node_stream.d.ts +6 -22
- package/dist/types/src/display/node_utils.d.ts +15 -11
- package/dist/types/src/display/optional_content_config.d.ts +2 -2
- package/dist/types/src/display/pattern_helper.d.ts +4 -2
- package/dist/types/src/display/standard_fontdata_factory.d.ts +20 -0
- package/dist/types/src/display/svg_factory.d.ts +14 -0
- package/dist/types/src/display/text_layer.d.ts +12 -9
- package/dist/types/src/display/touch_manager.d.ts +18 -0
- package/dist/types/src/display/transport_stream.d.ts +1 -1
- package/dist/types/src/display/wasm_factory.d.ts +20 -0
- package/dist/types/src/display/worker_options.d.ts +2 -2
- package/dist/types/src/interfaces.d.ts +4 -0
- package/dist/types/src/pdf.d.ts +13 -5
- package/dist/types/src/shared/message_handler.d.ts +9 -4
- package/dist/types/src/shared/util.d.ts +137 -129
- package/dist/types/web/annotation_editor_layer_builder.d.ts +20 -5
- package/dist/types/web/annotation_layer_builder.d.ts +35 -4
- package/dist/types/web/app_options.d.ts +1 -1
- package/dist/types/web/autolinker.d.ts +28 -0
- package/dist/types/web/base_pdf_page_view.d.ts +27 -0
- package/dist/types/web/draw_layer_builder.d.ts +13 -2
- package/dist/types/web/event_utils.d.ts +2 -2
- package/dist/types/web/genericl10n.d.ts +5 -5
- package/dist/types/web/interfaces.d.ts +5 -5
- package/dist/types/web/l10n.d.ts +2 -2
- package/dist/types/web/pdf_find_controller.d.ts +2 -0
- package/dist/types/web/pdf_link_service.d.ts +1 -2
- package/dist/types/web/pdf_page_detail_view.d.ts +32 -0
- package/dist/types/web/pdf_page_view.d.ts +44 -23
- package/dist/types/web/pdf_rendering_queue.d.ts +2 -1
- package/dist/types/web/pdf_thumbnail_view.d.ts +23 -3
- package/dist/types/web/pdf_thumbnail_viewer.d.ts +21 -1
- package/dist/types/web/pdf_viewer.d.ts +44 -16
- package/dist/types/web/struct_tree_layer_builder.d.ts +20 -2
- package/dist/types/web/text_accessibility.d.ts +1 -1
- package/dist/types/web/text_layer_builder.d.ts +25 -17
- package/dist/types/web/ui_utils.d.ts +3 -19
- package/dist/types/web/xfa_layer_builder.d.ts +14 -3
- package/package.json +31 -28
- package/dist/types/src/display/base_factory.d.ts +0 -60
- package/dist/types/src/display/editor/outliner.d.ts +0 -70
|
@@ -92,6 +92,7 @@ export function backtrackBeforeAllVisibleElements(index: number, views: any[], t
|
|
|
92
92
|
* or |items.length| if no such element exists.
|
|
93
93
|
*/
|
|
94
94
|
export function binarySearchFirstItem(items: any, condition: any, start?: number): number;
|
|
95
|
+
export const calcRound: ((x: number) => number) | ((x: any) => any);
|
|
95
96
|
export namespace CursorTool {
|
|
96
97
|
let SELECT: number;
|
|
97
98
|
let HAND: number;
|
|
@@ -176,23 +177,6 @@ export const MAX_SCALE: 10;
|
|
|
176
177
|
export const MIN_SCALE: 0.1;
|
|
177
178
|
export function normalizeWheelEventDelta(evt: any): number;
|
|
178
179
|
export function normalizeWheelEventDirection(evt: any): number;
|
|
179
|
-
/**
|
|
180
|
-
* Scale factors for the canvas, necessary with HiDPI displays.
|
|
181
|
-
*/
|
|
182
|
-
export class OutputScale {
|
|
183
|
-
/**
|
|
184
|
-
* @type {number} Horizontal scale.
|
|
185
|
-
*/
|
|
186
|
-
sx: number;
|
|
187
|
-
/**
|
|
188
|
-
* @type {number} Vertical scale.
|
|
189
|
-
*/
|
|
190
|
-
sy: number;
|
|
191
|
-
/**
|
|
192
|
-
* @type {boolean} Returns `true` when scaling is required, `false` otherwise.
|
|
193
|
-
*/
|
|
194
|
-
get scaled(): boolean;
|
|
195
|
-
}
|
|
196
180
|
/**
|
|
197
181
|
* Helper function to parse query string (e.g. ?param1=value¶m2=...).
|
|
198
182
|
* @param {string} query
|
|
@@ -219,7 +203,7 @@ export class ProgressBar {
|
|
|
219
203
|
* @param {string} str
|
|
220
204
|
* @param {boolean} [replaceInvisible]
|
|
221
205
|
*/
|
|
222
|
-
export function removeNullCharacters(str: string, replaceInvisible?: boolean
|
|
206
|
+
export function removeNullCharacters(str: string, replaceInvisible?: boolean): string;
|
|
223
207
|
export namespace RenderingStates {
|
|
224
208
|
let INITIAL: number;
|
|
225
209
|
let RUNNING: number;
|
|
@@ -241,7 +225,7 @@ export const SCROLLBAR_PADDING: 40;
|
|
|
241
225
|
export function scrollIntoView(element: HTMLElement, spot?: {
|
|
242
226
|
left?: number | undefined;
|
|
243
227
|
top?: number | undefined;
|
|
244
|
-
}
|
|
228
|
+
}, scrollMatches?: boolean): void;
|
|
245
229
|
export namespace ScrollMode {
|
|
246
230
|
let UNKNOWN_1: number;
|
|
247
231
|
export { UNKNOWN_1 as UNKNOWN };
|
|
@@ -8,6 +8,13 @@ export type XfaLayerBuilderOptions = {
|
|
|
8
8
|
linkService: IPDFLinkService;
|
|
9
9
|
xfaHtml?: Object | undefined;
|
|
10
10
|
};
|
|
11
|
+
export type XfaLayerBuilderRenderOptions = {
|
|
12
|
+
viewport: PageViewport;
|
|
13
|
+
/**
|
|
14
|
+
* - The default value is "display".
|
|
15
|
+
*/
|
|
16
|
+
intent?: string | undefined;
|
|
17
|
+
};
|
|
11
18
|
/**
|
|
12
19
|
* @typedef {Object} XfaLayerBuilderOptions
|
|
13
20
|
* @property {PDFPageProxy} pdfPage
|
|
@@ -15,6 +22,11 @@ export type XfaLayerBuilderOptions = {
|
|
|
15
22
|
* @property {IPDFLinkService} linkService
|
|
16
23
|
* @property {Object} [xfaHtml]
|
|
17
24
|
*/
|
|
25
|
+
/**
|
|
26
|
+
* @typedef {Object} XfaLayerBuilderRenderOptions
|
|
27
|
+
* @property {PageViewport} viewport
|
|
28
|
+
* @property {string} [intent] - The default value is "display".
|
|
29
|
+
*/
|
|
18
30
|
export class XfaLayerBuilder {
|
|
19
31
|
/**
|
|
20
32
|
* @param {XfaLayerBuilderOptions} options
|
|
@@ -27,13 +39,12 @@ export class XfaLayerBuilder {
|
|
|
27
39
|
div: HTMLDivElement | null;
|
|
28
40
|
_cancelled: boolean;
|
|
29
41
|
/**
|
|
30
|
-
* @param {
|
|
31
|
-
* @param {string} intent (default value is 'display')
|
|
42
|
+
* @param {XfaLayerBuilderRenderOptions} viewport
|
|
32
43
|
* @returns {Promise<Object | void>} A promise that is resolved when rendering
|
|
33
44
|
* of the XFA layer is complete. The first rendering will return an object
|
|
34
45
|
* with a `textDivs` property that can be used with the TextHighlighter.
|
|
35
46
|
*/
|
|
36
|
-
render(viewport
|
|
47
|
+
render({ viewport, intent }: XfaLayerBuilderRenderOptions): Promise<Object | void>;
|
|
37
48
|
cancel(): void;
|
|
38
49
|
hide(): void;
|
|
39
50
|
}
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "unpdf",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
5
|
-
"packageManager": "pnpm@
|
|
6
|
-
"description": "
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"packageManager": "pnpm@10.10.0",
|
|
6
|
+
"description": "PDF handling for Node.js, browsers, and serverless environments",
|
|
7
7
|
"author": "Johann Schopplich <hello@johannschopplich.com>",
|
|
8
8
|
"license": "MIT",
|
|
9
9
|
"homepage": "https://github.com/unjs/unpdf#readme",
|
|
@@ -17,7 +17,8 @@
|
|
|
17
17
|
"keywords": [
|
|
18
18
|
"parse",
|
|
19
19
|
"pdfjs-dist",
|
|
20
|
-
"pdf"
|
|
20
|
+
"pdf",
|
|
21
|
+
"serverless"
|
|
21
22
|
],
|
|
22
23
|
"sideEffects": false,
|
|
23
24
|
"exports": {
|
|
@@ -43,8 +44,7 @@
|
|
|
43
44
|
"*": {
|
|
44
45
|
"*": [
|
|
45
46
|
"*",
|
|
46
|
-
"dist/*"
|
|
47
|
-
"dist/*.d.ts"
|
|
47
|
+
"dist/*"
|
|
48
48
|
]
|
|
49
49
|
}
|
|
50
50
|
},
|
|
@@ -59,35 +59,38 @@
|
|
|
59
59
|
"lint:fix": "eslint . --fix",
|
|
60
60
|
"release": "bumpp",
|
|
61
61
|
"test": "vitest",
|
|
62
|
+
"test:worker": "esbuild --bundle --platform=neutral --outfile=test/artifacts/worker.js test/worker/index.ts && wrangler dev test/artifacts/worker.js",
|
|
62
63
|
"test:types": "tsc --noEmit"
|
|
63
64
|
},
|
|
64
|
-
"
|
|
65
|
-
"canvas": "^
|
|
65
|
+
"peerDependencies": {
|
|
66
|
+
"@napi-rs/canvas": "^0.1.69"
|
|
67
|
+
},
|
|
68
|
+
"peerDependenciesMeta": {
|
|
69
|
+
"@napi-rs/canvas": {
|
|
70
|
+
"optional": true
|
|
71
|
+
}
|
|
66
72
|
},
|
|
67
73
|
"devDependencies": {
|
|
68
|
-
"@antfu/eslint-config": "^
|
|
74
|
+
"@antfu/eslint-config": "^4.12.0",
|
|
75
|
+
"@napi-rs/canvas": "^0.1.69",
|
|
69
76
|
"@rollup/plugin-alias": "^5.1.1",
|
|
70
|
-
"@rollup/plugin-commonjs": "^28.0.0",
|
|
71
77
|
"@rollup/plugin-inject": "^5.0.5",
|
|
72
|
-
"@rollup/plugin-node-resolve": "^
|
|
73
|
-
"@rollup/plugin-replace": "^6.0.
|
|
78
|
+
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
79
|
+
"@rollup/plugin-replace": "^6.0.2",
|
|
74
80
|
"@rollup/plugin-terser": "^0.4.4",
|
|
75
|
-
"@rollup/plugin-typescript": "^12.1.
|
|
76
|
-
"@types/node": "^
|
|
77
|
-
"bumpp": "^
|
|
78
|
-
"
|
|
79
|
-
"
|
|
80
|
-
"
|
|
81
|
-
"
|
|
82
|
-
"
|
|
83
|
-
"
|
|
84
|
-
"
|
|
81
|
+
"@rollup/plugin-typescript": "^12.1.2",
|
|
82
|
+
"@types/node": "^22.15.3",
|
|
83
|
+
"bumpp": "^10.1.0",
|
|
84
|
+
"esbuild": "^0.25.3",
|
|
85
|
+
"eslint": "^9.25.1",
|
|
86
|
+
"fast-glob": "^3.3.3",
|
|
87
|
+
"pdfjs-dist": "~5.2.133",
|
|
88
|
+
"rollup": "^4.40.1",
|
|
89
|
+
"tslib": "^2.8.1",
|
|
90
|
+
"typescript": "^5.8.3",
|
|
91
|
+
"unbuild": "^3.5.0",
|
|
85
92
|
"unenv": "^1.10.0",
|
|
86
|
-
"vitest": "^
|
|
87
|
-
|
|
88
|
-
"pnpm": {
|
|
89
|
-
"patchedDependencies": {
|
|
90
|
-
"pdfjs-dist@4.6.82": "patches/pdfjs-dist@4.6.82.patch"
|
|
91
|
-
}
|
|
93
|
+
"vitest": "^3.1.2",
|
|
94
|
+
"wrangler": "^4.14.0"
|
|
92
95
|
}
|
|
93
96
|
}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
export class BaseCanvasFactory {
|
|
2
|
-
constructor({ enableHWA }?: {
|
|
3
|
-
enableHWA?: boolean | undefined;
|
|
4
|
-
});
|
|
5
|
-
create(width: any, height: any): {
|
|
6
|
-
canvas: void;
|
|
7
|
-
context: any;
|
|
8
|
-
};
|
|
9
|
-
reset(canvasAndContext: any, width: any, height: any): void;
|
|
10
|
-
destroy(canvasAndContext: any): void;
|
|
11
|
-
/**
|
|
12
|
-
* @ignore
|
|
13
|
-
*/
|
|
14
|
-
_createCanvas(width: any, height: any): void;
|
|
15
|
-
#private;
|
|
16
|
-
}
|
|
17
|
-
export class BaseCMapReaderFactory {
|
|
18
|
-
constructor({ baseUrl, isCompressed }: {
|
|
19
|
-
baseUrl?: null | undefined;
|
|
20
|
-
isCompressed?: boolean | undefined;
|
|
21
|
-
});
|
|
22
|
-
baseUrl: any;
|
|
23
|
-
isCompressed: boolean;
|
|
24
|
-
fetch({ name }: {
|
|
25
|
-
name: any;
|
|
26
|
-
}): Promise<any>;
|
|
27
|
-
/**
|
|
28
|
-
* @ignore
|
|
29
|
-
*/
|
|
30
|
-
_fetchData(url: any, compressionType: any): void;
|
|
31
|
-
}
|
|
32
|
-
export class BaseFilterFactory {
|
|
33
|
-
addFilter(maps: any): string;
|
|
34
|
-
addHCMFilter(fgColor: any, bgColor: any): string;
|
|
35
|
-
addAlphaFilter(map: any): string;
|
|
36
|
-
addLuminosityFilter(map: any): string;
|
|
37
|
-
addHighlightHCMFilter(filterName: any, fgColor: any, bgColor: any, newFgColor: any, newBgColor: any): string;
|
|
38
|
-
destroy(keepHCM?: boolean): void;
|
|
39
|
-
}
|
|
40
|
-
export class BaseStandardFontDataFactory {
|
|
41
|
-
constructor({ baseUrl }: {
|
|
42
|
-
baseUrl?: null | undefined;
|
|
43
|
-
});
|
|
44
|
-
baseUrl: any;
|
|
45
|
-
fetch({ filename }: {
|
|
46
|
-
filename: any;
|
|
47
|
-
}): Promise<any>;
|
|
48
|
-
/**
|
|
49
|
-
* @ignore
|
|
50
|
-
*/
|
|
51
|
-
_fetchData(url: any): void;
|
|
52
|
-
}
|
|
53
|
-
export class BaseSVGFactory {
|
|
54
|
-
create(width: any, height: any, skipDimensions?: boolean): void;
|
|
55
|
-
createElement(type: any): void;
|
|
56
|
-
/**
|
|
57
|
-
* @ignore
|
|
58
|
-
*/
|
|
59
|
-
_createSVG(type: any): void;
|
|
60
|
-
}
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
export class FreeOutliner {
|
|
2
|
-
static "__#21@#MIN_DIST": number;
|
|
3
|
-
static "__#21@#MIN_DIFF": number;
|
|
4
|
-
static "__#21@#MIN": number;
|
|
5
|
-
constructor({ x, y }: {
|
|
6
|
-
x: any;
|
|
7
|
-
y: any;
|
|
8
|
-
}, box: any, scaleFactor: any, thickness: any, isLTR: any, innerMargin?: number);
|
|
9
|
-
get free(): boolean;
|
|
10
|
-
isEmpty(): boolean;
|
|
11
|
-
add({ x, y }: {
|
|
12
|
-
x: any;
|
|
13
|
-
y: any;
|
|
14
|
-
}): boolean;
|
|
15
|
-
toSVGPath(): string;
|
|
16
|
-
getOutlines(): FreeHighlightOutline;
|
|
17
|
-
#private;
|
|
18
|
-
}
|
|
19
|
-
export class Outliner {
|
|
20
|
-
/**
|
|
21
|
-
* Construct an outliner.
|
|
22
|
-
* @param {Array<Object>} boxes - An array of axis-aligned rectangles.
|
|
23
|
-
* @param {number} borderWidth - The width of the border of the boxes, it
|
|
24
|
-
* allows to make the boxes bigger (or smaller).
|
|
25
|
-
* @param {number} innerMargin - The margin between the boxes and the
|
|
26
|
-
* outlines. It's important to not have a null innerMargin when we want to
|
|
27
|
-
* draw the outline else the stroked outline could be clipped because of its
|
|
28
|
-
* width.
|
|
29
|
-
* @param {boolean} isLTR - true if we're in LTR mode. It's used to determine
|
|
30
|
-
* the last point of the boxes.
|
|
31
|
-
*/
|
|
32
|
-
constructor(boxes: Array<Object>, borderWidth?: number, innerMargin?: number, isLTR?: boolean);
|
|
33
|
-
getOutlines(): HighlightOutline;
|
|
34
|
-
#private;
|
|
35
|
-
}
|
|
36
|
-
declare class FreeHighlightOutline extends Outline {
|
|
37
|
-
constructor(outline: any, points: any, box: any, scaleFactor: any, innerMargin: any, isLTR: any);
|
|
38
|
-
serialize([blX, blY, trX, trY]: [any, any, any, any], rotation: any): {
|
|
39
|
-
outline: number[];
|
|
40
|
-
points: number[][];
|
|
41
|
-
};
|
|
42
|
-
get box(): null;
|
|
43
|
-
getNewOutline(thickness: any, innerMargin: any): FreeHighlightOutline;
|
|
44
|
-
#private;
|
|
45
|
-
}
|
|
46
|
-
declare class HighlightOutline extends Outline {
|
|
47
|
-
constructor(outlines: any, box: any);
|
|
48
|
-
/**
|
|
49
|
-
* Serialize the outlines into the PDF page coordinate system.
|
|
50
|
-
* @param {Array<number>} _bbox - the bounding box of the annotation.
|
|
51
|
-
* @param {number} _rotation - the rotation of the annotation.
|
|
52
|
-
* @returns {Array<Array<number>>}
|
|
53
|
-
*/
|
|
54
|
-
serialize([blX, blY, trX, trY]: Array<number>, _rotation: number): Array<Array<number>>;
|
|
55
|
-
get box(): any;
|
|
56
|
-
#private;
|
|
57
|
-
}
|
|
58
|
-
declare class Outline {
|
|
59
|
-
/**
|
|
60
|
-
* @returns {string} The SVG path of the outline.
|
|
61
|
-
*/
|
|
62
|
-
toSVGPath(): string;
|
|
63
|
-
/**
|
|
64
|
-
* @type {Object|null} The bounding box of the outline.
|
|
65
|
-
*/
|
|
66
|
-
get box(): Object | null;
|
|
67
|
-
serialize(_bbox: any, _rotation: any): void;
|
|
68
|
-
get free(): any;
|
|
69
|
-
}
|
|
70
|
-
export {};
|