unpdf 0.5.3 → 0.6.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.
Files changed (85) hide show
  1. package/README.md +64 -31
  2. package/dist/index.node.cjs +8 -9
  3. package/dist/index.node.d.cts +4 -4
  4. package/dist/index.node.d.mts +4 -4
  5. package/dist/index.node.d.ts +4 -4
  6. package/dist/index.node.mjs +2 -3
  7. package/dist/index.web.cjs +8 -9
  8. package/dist/index.web.d.cts +4 -4
  9. package/dist/index.web.d.mts +4 -4
  10. package/dist/index.web.d.ts +4 -4
  11. package/dist/index.web.mjs +2 -3
  12. package/dist/index.worker.cjs +14 -11
  13. package/dist/index.worker.d.cts +4 -4
  14. package/dist/index.worker.d.mts +4 -4
  15. package/dist/index.worker.d.ts +4 -4
  16. package/dist/index.worker.mjs +12 -8
  17. package/dist/pdfjs.d.mts +1 -0
  18. package/dist/pdfjs.d.ts +1 -0
  19. package/dist/pdfjs.mjs +1 -0
  20. package/dist/shared/{unpdf.d3d8f5ac.d.mts → unpdf.3991886a.d.cts} +11 -9
  21. package/dist/shared/{unpdf.d3d8f5ac.d.cts → unpdf.3991886a.d.mts} +11 -9
  22. package/dist/shared/{unpdf.d3d8f5ac.d.ts → unpdf.3991886a.d.ts} +11 -9
  23. package/dist/shared/unpdf.6c0ca5b5.cjs +107 -0
  24. package/dist/shared/unpdf.ce219a40.mjs +99 -0
  25. package/dist/types/external/webL10n/l10n.d.ts +0 -0
  26. package/dist/types/src/display/annotation_layer.d.ts +203 -0
  27. package/dist/types/src/display/annotation_storage.d.ts +89 -0
  28. package/dist/types/src/display/api.d.ts +1466 -0
  29. package/dist/types/src/display/base_factory.d.ts +54 -0
  30. package/dist/types/src/display/canvas.d.ts +208 -0
  31. package/dist/types/src/display/display_utils.d.ts +277 -0
  32. package/dist/types/src/display/editor/annotation_editor_layer.d.ts +196 -0
  33. package/dist/types/src/display/editor/editor.d.ts +325 -0
  34. package/dist/types/src/display/editor/freetext.d.ts +72 -0
  35. package/dist/types/src/display/editor/ink.d.ts +95 -0
  36. package/dist/types/src/display/editor/stamp.d.ts +28 -0
  37. package/dist/types/src/display/editor/tools.d.ts +349 -0
  38. package/dist/types/src/display/font_loader.d.ts +43 -0
  39. package/dist/types/src/display/metadata.d.ts +11 -0
  40. package/dist/types/src/display/optional_content_config.d.ts +13 -0
  41. package/dist/types/src/display/pattern_helper.d.ts +73 -0
  42. package/dist/types/src/display/text_layer.d.ts +151 -0
  43. package/dist/types/src/display/transport_stream.d.ts +68 -0
  44. package/dist/types/src/display/worker_options.d.ts +27 -0
  45. package/dist/types/src/display/xfa_layer.d.ts +46 -0
  46. package/dist/types/src/display/xfa_text.d.ts +19 -0
  47. package/dist/types/src/pdf.d.ts +50 -0
  48. package/dist/types/src/shared/image_utils.d.ts +17 -0
  49. package/dist/types/src/shared/message_handler.d.ts +43 -0
  50. package/dist/types/src/shared/murmurhash3.d.ts +7 -0
  51. package/dist/types/src/shared/scripting_utils.d.ts +16 -0
  52. package/dist/types/src/shared/util.d.ts +398 -0
  53. package/dist/types/web/annotation_editor_layer_builder.d.ts +50 -0
  54. package/dist/types/web/annotation_layer_builder.d.ts +83 -0
  55. package/dist/types/web/app_options.d.ts +14 -0
  56. package/dist/types/web/download_manager.d.ts +14 -0
  57. package/dist/types/web/event_utils.d.ts +75 -0
  58. package/dist/types/web/generic_scripting.d.ts +8 -0
  59. package/dist/types/web/genericl10n.d.ts +13 -0
  60. package/dist/types/web/interfaces.d.ts +163 -0
  61. package/dist/types/web/l10n_utils.d.ts +7 -0
  62. package/dist/types/web/pdf_find_controller.d.ts +108 -0
  63. package/dist/types/web/pdf_find_utils.d.ts +16 -0
  64. package/dist/types/web/pdf_history.d.ts +168 -0
  65. package/dist/types/web/pdf_link_service.d.ts +243 -0
  66. package/dist/types/web/pdf_page_view.d.ts +209 -0
  67. package/dist/types/web/pdf_rendering_queue.d.ts +53 -0
  68. package/dist/types/web/pdf_scripting_manager.component.d.ts +5 -0
  69. package/dist/types/web/pdf_scripting_manager.d.ts +61 -0
  70. package/dist/types/web/pdf_single_page_viewer.d.ts +7 -0
  71. package/dist/types/web/pdf_thumbnail_view.d.ts +131 -0
  72. package/dist/types/web/pdf_thumbnail_viewer.d.ts +104 -0
  73. package/dist/types/web/pdf_viewer.component.d.ts +24 -0
  74. package/dist/types/web/pdf_viewer.d.ts +455 -0
  75. package/dist/types/web/struct_tree_layer_builder.d.ts +7 -0
  76. package/dist/types/web/text_accessibility.d.ts +42 -0
  77. package/dist/types/web/text_highlighter.d.ts +63 -0
  78. package/dist/types/web/text_layer_builder.d.ts +64 -0
  79. package/dist/types/web/ui_utils.d.ts +288 -0
  80. package/dist/types/web/xfa_layer_builder.d.ts +41 -0
  81. package/package.json +67 -41
  82. package/dist/shared/unpdf.61a2a4e1.cjs +0 -56
  83. package/dist/shared/unpdf.9511ac30.cjs +0 -52
  84. package/dist/shared/unpdf.c7f36e56.mjs +0 -50
  85. package/dist/shared/unpdf.cd67d475.mjs +0 -48
@@ -0,0 +1,288 @@
1
+ export type GetPageSizeInchesParameters = {
2
+ view: number[];
3
+ userUnit: number;
4
+ rotate: number;
5
+ };
6
+ export type PageSize = {
7
+ /**
8
+ * - In inches.
9
+ */
10
+ width: number;
11
+ /**
12
+ * - In inches.
13
+ */
14
+ height: number;
15
+ };
16
+ export type GetVisibleElementsParameters = {
17
+ /**
18
+ * - A container that can possibly scroll.
19
+ */
20
+ scrollEl: HTMLElement;
21
+ /**
22
+ * - Objects with a `div` property that contains an
23
+ * HTMLElement, which should all be descendants of `scrollEl` satisfying the
24
+ * relevant layout assumptions.
25
+ */
26
+ views: any[];
27
+ /**
28
+ * - If `true`, the returned elements are
29
+ * sorted in descending order of the percent of their padding box that is
30
+ * visible. The default value is `false`.
31
+ */
32
+ sortByVisibility: boolean;
33
+ /**
34
+ * - If `true`, the elements are assumed to be
35
+ * laid out horizontally instead of vertically. The default value is `false`.
36
+ */
37
+ horizontal: boolean;
38
+ /**
39
+ * - If `true`, the `scrollEl` container is assumed to
40
+ * be in right-to-left mode. The default value is `false`.
41
+ */
42
+ rtl: boolean;
43
+ };
44
+ /**
45
+ * Promise that is resolved when DOM window becomes visible.
46
+ */
47
+ export const animationStarted: Promise<any>;
48
+ /**
49
+ * Converts API PageLayout values to the format used by `BaseViewer`.
50
+ * @param {string} mode - The API PageLayout value.
51
+ * @returns {Object}
52
+ */
53
+ export function apiPageLayoutToViewerModes(layout: any): Object;
54
+ /**
55
+ * Converts API PageMode values to the format used by `PDFSidebar`.
56
+ * NOTE: There's also a "FullScreen" parameter which is not possible to support,
57
+ * since the Fullscreen API used in browsers requires that entering
58
+ * fullscreen mode only occurs as a result of a user-initiated event.
59
+ * @param {string} mode - The API PageMode value.
60
+ * @returns {number} A value from {SidebarView}.
61
+ */
62
+ export function apiPageModeToSidebarView(mode: string): number;
63
+ /**
64
+ * Approximates float number as a fraction using Farey sequence (max order
65
+ * of 8).
66
+ * @param {number} x - Positive float number.
67
+ * @returns {Array} Estimated fraction: the first array item is a numerator,
68
+ * the second one is a denominator.
69
+ */
70
+ export function approximateFraction(x: number): any[];
71
+ export const AutoPrintRegExp: RegExp;
72
+ /**
73
+ * Helper function for getVisibleElements.
74
+ *
75
+ * @param {number} index - initial guess at the first visible element
76
+ * @param {Array} views - array of pages, into which `index` is an index
77
+ * @param {number} top - the top of the scroll pane
78
+ * @returns {number} less than or equal to `index` that is definitely at or
79
+ * before the first visible element in `views`, but not by too much. (Usually,
80
+ * this will be the first element in the first partially visible row in
81
+ * `views`, although sometimes it goes back one row further.)
82
+ */
83
+ export function backtrackBeforeAllVisibleElements(index: number, views: any[], top: number): number;
84
+ /**
85
+ * Use binary search to find the index of the first item in a given array which
86
+ * passes a given condition. The items are expected to be sorted in the sense
87
+ * that if the condition is true for one item in the array, then it is also true
88
+ * for all following items.
89
+ *
90
+ * @returns {number} Index of the first array element to pass the test,
91
+ * or |items.length| if no such element exists.
92
+ */
93
+ export function binarySearchFirstItem(items: any, condition: any, start?: number): number;
94
+ export namespace CursorTool {
95
+ let SELECT: number;
96
+ let HAND: number;
97
+ let ZOOM: number;
98
+ }
99
+ export const DEFAULT_SCALE: 1;
100
+ export const DEFAULT_SCALE_DELTA: 1.1;
101
+ export const DEFAULT_SCALE_VALUE: "auto";
102
+ export const docStyle: CSSStyleDeclaration | null;
103
+ /**
104
+ * Get the active or focused element in current DOM.
105
+ *
106
+ * Recursively search for the truly active or focused element in case there are
107
+ * shadow DOMs.
108
+ *
109
+ * @returns {Element} the truly active or focused element.
110
+ */
111
+ export function getActiveOrFocusedElement(): Element;
112
+ /**
113
+ * @typedef {Object} GetPageSizeInchesParameters
114
+ * @property {number[]} view
115
+ * @property {number} userUnit
116
+ * @property {number} rotate
117
+ */
118
+ /**
119
+ * @typedef {Object} PageSize
120
+ * @property {number} width - In inches.
121
+ * @property {number} height - In inches.
122
+ */
123
+ /**
124
+ * Gets the size of the specified page, converted from PDF units to inches.
125
+ * @param {GetPageSizeInchesParameters} params
126
+ * @returns {PageSize}
127
+ */
128
+ export function getPageSizeInches({ view, userUnit, rotate }: GetPageSizeInchesParameters): PageSize;
129
+ /**
130
+ * @typedef {Object} GetVisibleElementsParameters
131
+ * @property {HTMLElement} scrollEl - A container that can possibly scroll.
132
+ * @property {Array} views - Objects with a `div` property that contains an
133
+ * HTMLElement, which should all be descendants of `scrollEl` satisfying the
134
+ * relevant layout assumptions.
135
+ * @property {boolean} sortByVisibility - If `true`, the returned elements are
136
+ * sorted in descending order of the percent of their padding box that is
137
+ * visible. The default value is `false`.
138
+ * @property {boolean} horizontal - If `true`, the elements are assumed to be
139
+ * laid out horizontally instead of vertically. The default value is `false`.
140
+ * @property {boolean} rtl - If `true`, the `scrollEl` container is assumed to
141
+ * be in right-to-left mode. The default value is `false`.
142
+ */
143
+ /**
144
+ * Generic helper to find out what elements are visible within a scroll pane.
145
+ *
146
+ * Well, pretty generic. There are some assumptions placed on the elements
147
+ * referenced by `views`:
148
+ * - If `horizontal`, no left of any earlier element is to the right of the
149
+ * left of any later element.
150
+ * - Otherwise, `views` can be split into contiguous rows where, within a row,
151
+ * no top of any element is below the bottom of any other element, and
152
+ * between rows, no bottom of any element in an earlier row is below the
153
+ * top of any element in a later row.
154
+ *
155
+ * (Here, top, left, etc. all refer to the padding edge of the element in
156
+ * question. For pages, that ends up being equivalent to the bounding box of the
157
+ * rendering canvas. Earlier and later refer to index in `views`, not page
158
+ * layout.)
159
+ *
160
+ * @param {GetVisibleElementsParameters}
161
+ * @returns {Object} `{ first, last, views: [{ id, x, y, view, percent }] }`
162
+ */
163
+ export function getVisibleElements({ scrollEl, views, sortByVisibility, horizontal, rtl, }: GetVisibleElementsParameters): Object;
164
+ export function isPortraitOrientation(size: any): boolean;
165
+ export function isValidRotation(angle: any): boolean;
166
+ export function isValidScrollMode(mode: any): boolean;
167
+ export function isValidSpreadMode(mode: any): boolean;
168
+ export const MAX_AUTO_SCALE: 1.25;
169
+ export const MAX_SCALE: 10;
170
+ export const MIN_SCALE: 0.1;
171
+ /**
172
+ * Event handler to suppress context menu.
173
+ */
174
+ export function noContextMenuHandler(evt: any): void;
175
+ export function normalizeWheelEventDelta(evt: any): number;
176
+ export function normalizeWheelEventDirection(evt: any): number;
177
+ /**
178
+ * Scale factors for the canvas, necessary with HiDPI displays.
179
+ */
180
+ export class OutputScale {
181
+ /**
182
+ * @type {number} Horizontal scale.
183
+ */
184
+ sx: number;
185
+ /**
186
+ * @type {number} Vertical scale.
187
+ */
188
+ sy: number;
189
+ /**
190
+ * @type {boolean} Returns `true` when scaling is required, `false` otherwise.
191
+ */
192
+ get scaled(): boolean;
193
+ }
194
+ /**
195
+ * Helper function to parse query string (e.g. ?param1=value&param2=...).
196
+ * @param {string}
197
+ * @returns {Map}
198
+ */
199
+ export function parseQueryString(query: any): Map<any, any>;
200
+ export namespace PresentationModeState {
201
+ let UNKNOWN: number;
202
+ let NORMAL: number;
203
+ let CHANGING: number;
204
+ let FULLSCREEN: number;
205
+ }
206
+ export class ProgressBar {
207
+ constructor(bar: any);
208
+ set percent(arg: number);
209
+ get percent(): number;
210
+ setWidth(viewer: any): void;
211
+ setDisableAutoFetch(delay?: number): void;
212
+ hide(): void;
213
+ show(): void;
214
+ #private;
215
+ }
216
+ /**
217
+ * @param {string} str
218
+ * @param {boolean} [replaceInvisible]
219
+ */
220
+ export function removeNullCharacters(str: string, replaceInvisible?: boolean | undefined): string;
221
+ export namespace RenderingStates {
222
+ let INITIAL: number;
223
+ let RUNNING: number;
224
+ let PAUSED: number;
225
+ let FINISHED: number;
226
+ }
227
+ export function roundToDivide(x: any, div: any): any;
228
+ export const SCROLLBAR_PADDING: 40;
229
+ /**
230
+ * Scrolls specified element into view of its parent.
231
+ * @param {HTMLElement} element - The element to be visible.
232
+ * @param {Object} [spot] - An object with optional top and left properties,
233
+ * specifying the offset from the top left edge.
234
+ * @param {number} [spot.left]
235
+ * @param {number} [spot.top]
236
+ * @param {boolean} [scrollMatches] - When scrolling search results into view,
237
+ * ignore elements that either: Contains marked content identifiers,
238
+ * or have the CSS-rule `overflow: hidden;` set. The default value is `false`.
239
+ */
240
+ export function scrollIntoView(element: HTMLElement, spot?: {
241
+ left?: number | undefined;
242
+ top?: number | undefined;
243
+ } | undefined, scrollMatches?: boolean | undefined): void;
244
+ export namespace ScrollMode {
245
+ let UNKNOWN_1: number;
246
+ export { UNKNOWN_1 as UNKNOWN };
247
+ export let VERTICAL: number;
248
+ export let HORIZONTAL: number;
249
+ export let WRAPPED: number;
250
+ export let PAGE: number;
251
+ }
252
+ export namespace SidebarView {
253
+ let UNKNOWN_2: number;
254
+ export { UNKNOWN_2 as UNKNOWN };
255
+ export let NONE: number;
256
+ export let THUMBS: number;
257
+ export let OUTLINE: number;
258
+ export let ATTACHMENTS: number;
259
+ export let LAYERS: number;
260
+ }
261
+ export namespace SpreadMode {
262
+ let UNKNOWN_3: number;
263
+ export { UNKNOWN_3 as UNKNOWN };
264
+ let NONE_1: number;
265
+ export { NONE_1 as NONE };
266
+ export let ODD: number;
267
+ export let EVEN: number;
268
+ }
269
+ export namespace TextLayerMode {
270
+ let DISABLE: number;
271
+ let ENABLE: number;
272
+ let ENABLE_PERMISSIONS: number;
273
+ }
274
+ export function toggleCheckedBtn(button: any, toggle: any, view?: null): void;
275
+ export function toggleExpandedBtn(button: any, toggle: any, view?: null): void;
276
+ export const UNKNOWN_SCALE: 0;
277
+ export const VERTICAL_PADDING: 5;
278
+ /**
279
+ * Helper function to start monitoring the scroll event and converting them into
280
+ * PDF.js friendly one: with scroll debounce and scroll direction.
281
+ */
282
+ export function watchScroll(viewAreaElement: any, callback: any): {
283
+ right: boolean;
284
+ down: boolean;
285
+ lastX: any;
286
+ lastY: any;
287
+ _eventHandler: (evt: any) => void;
288
+ };
@@ -0,0 +1,41 @@
1
+ export type PDFPageProxy = import("../src/display/api").PDFPageProxy;
2
+ export type PageViewport = import("../src/display/display_utils").PageViewport;
3
+ export type IPDFLinkService = import("./interfaces").IPDFLinkService;
4
+ export type XfaLayerBuilderOptions = {
5
+ pageDiv: HTMLDivElement;
6
+ pdfPage: PDFPageProxy;
7
+ annotationStorage?: any;
8
+ linkService: IPDFLinkService;
9
+ xfaHtml?: Object | undefined;
10
+ };
11
+ /**
12
+ * @typedef {Object} XfaLayerBuilderOptions
13
+ * @property {HTMLDivElement} pageDiv
14
+ * @property {PDFPageProxy} pdfPage
15
+ * @property {AnnotationStorage} [annotationStorage]
16
+ * @property {IPDFLinkService} linkService
17
+ * @property {Object} [xfaHtml]
18
+ */
19
+ export class XfaLayerBuilder {
20
+ /**
21
+ * @param {XfaLayerBuilderOptions} options
22
+ */
23
+ constructor({ pageDiv, pdfPage, annotationStorage, linkService, xfaHtml, }: XfaLayerBuilderOptions);
24
+ pageDiv: HTMLDivElement;
25
+ pdfPage: import("../src/display/api").PDFPageProxy;
26
+ annotationStorage: any;
27
+ linkService: import("./interfaces").IPDFLinkService;
28
+ xfaHtml: Object;
29
+ div: HTMLDivElement | null;
30
+ _cancelled: boolean;
31
+ /**
32
+ * @param {PageViewport} viewport
33
+ * @param {string} intent (default value is 'display')
34
+ * @returns {Promise<Object | void>} A promise that is resolved when rendering
35
+ * of the XFA layer is complete. The first rendering will return an object
36
+ * with a `textDivs` property that can be used with the TextHighlighter.
37
+ */
38
+ render(viewport: PageViewport, intent?: string): Promise<Object | void>;
39
+ cancel(): void;
40
+ hide(): void;
41
+ }
package/package.json CHANGED
@@ -1,72 +1,98 @@
1
1
  {
2
2
  "name": "unpdf",
3
3
  "type": "module",
4
- "version": "0.5.3",
5
- "packageManager": "pnpm@8.6.12",
6
- "description": "Utilities to work with PDFs, like extracting text",
4
+ "version": "0.6.0",
5
+ "packageManager": "pnpm@8.7.0",
6
+ "description": "Utilities to work with PDFs in Node.js, browser and workers",
7
7
  "author": "Johann Schopplich <pkg@johannschopplich.com>",
8
8
  "license": "MIT",
9
- "homepage": "https://github.com/johannschopplich/unpdf#readme",
9
+ "homepage": "https://github.com/unjs/unpdf#readme",
10
10
  "repository": {
11
11
  "type": "git",
12
- "url": "git+https://github.com/johannschopplich/unpdf.git"
12
+ "url": "git+https://github.com/unjs/unpdf.git"
13
13
  },
14
14
  "bugs": {
15
- "url": "https://github.com/johannschopplich/unpdf/issues"
15
+ "url": "https://github.com/unjs/unpdf/issues"
16
16
  },
17
17
  "keywords": [
18
- "pdf",
19
- "parse"
18
+ "parse",
19
+ "pdfjs-dist",
20
+ "pdf"
20
21
  ],
21
22
  "sideEffects": false,
22
23
  "exports": {
23
- "browser": "./dist/index.web.mjs",
24
- "bun": "./dist/index.worker.mjs",
25
- "deno": "./dist/index.worker.mjs",
26
- "edge-light": "./dist/index.worker.mjs",
27
- "edge-routine": "./dist/index.worker.mjs",
28
- "lagon": "./dist/index.worker.mjs",
29
- "netlify": "./dist/index.worker.mjs",
30
- "react-native": "./dist/index.worker.mjs",
31
- "wintercg": "./dist/index.worker.mjs",
32
- "worker": "./dist/index.worker.mjs",
33
- "workerd": "./dist/index.worker.mjs",
34
- "node": {
35
- "types": "./dist/index.node.d.ts",
36
- "import": "./dist/index.node.mjs",
37
- "require": "./dist/index.node.cjs"
24
+ ".": {
25
+ "browser": "./dist/index.web.mjs",
26
+ "bun": "./dist/index.worker.mjs",
27
+ "deno": "./dist/index.worker.mjs",
28
+ "edge-light": "./dist/index.worker.mjs",
29
+ "edge-routine": "./dist/index.worker.mjs",
30
+ "lagon": "./dist/index.worker.mjs",
31
+ "netlify": "./dist/index.worker.mjs",
32
+ "react-native": "./dist/index.worker.mjs",
33
+ "wintercg": "./dist/index.worker.mjs",
34
+ "worker": "./dist/index.worker.mjs",
35
+ "workerd": "./dist/index.worker.mjs",
36
+ "node": {
37
+ "types": "./dist/index.node.d.ts",
38
+ "import": "./dist/index.node.mjs",
39
+ "require": "./dist/index.node.cjs"
40
+ },
41
+ "types": "./dist/index.web.d.ts",
42
+ "import": "./dist/index.web.mjs",
43
+ "require": "./dist/index.web.cjs"
38
44
  },
39
- "types": "./dist/index.web.d.ts",
40
- "import": "./dist/index.web.mjs",
41
- "require": "./dist/index.web.cjs"
45
+ "./pdfjs": {
46
+ "types": "./dist/pdfjs.d.ts",
47
+ "import": "./dist/pdfjs.mjs"
48
+ }
42
49
  },
43
50
  "main": "./dist/index.node.cjs",
44
51
  "module": "./dist/index.web.mjs",
45
- "browser": "./dist/index.web.mjs",
46
52
  "types": "./dist/index.web.d.ts",
53
+ "typesVersions": {
54
+ "*": {
55
+ "*": [
56
+ "*",
57
+ "dist/*",
58
+ "dist/*.d.ts"
59
+ ]
60
+ }
61
+ },
47
62
  "files": [
48
63
  "dist"
49
64
  ],
50
65
  "scripts": {
51
- "build": "unbuild",
66
+ "build": "unbuild && node scripts/post-build.mjs",
67
+ "build:pdfjs": "rollup --config pdfjs.rollup.config.ts --configPlugin typescript && cp -R node_modules/pdfjs-dist/types dist",
52
68
  "dev": "unbuild --stub",
53
- "lint": "eslint .",
54
- "lint:fix": "eslint . --fix",
69
+ "lint": "eslint \"**/*.ts\" --ignore-path .gitignore",
70
+ "lint:fix": "npm run lint -- --fix",
71
+ "format": "prettier \"**/*.{css,html,json,md,mjs,ts,vue,yml}\" --write",
72
+ "format:check": "prettier \"**/*.{css,html,json,md,mjs,ts,vue,yml}\" --check",
55
73
  "release": "bumpp --commit --push --tag",
56
- "test": "tsx test/index.ts",
74
+ "test": "vitest",
57
75
  "test:types": "tsc --noEmit"
58
76
  },
59
- "peerDependencies": {
60
- "pdfjs-dist": "^3.9.179"
61
- },
62
77
  "devDependencies": {
63
- "@antfu/eslint-config": "^0.40.2",
64
- "@types/node": "^20.4.10",
65
- "bumpp": "^9.1.1",
66
- "eslint": "^8.47.0",
67
- "pdfjs-dist": "^3.9.179",
68
- "tsx": "^3.12.7",
78
+ "@rollup/plugin-alias": "^5.0.0",
79
+ "@rollup/plugin-commonjs": "^25.0.4",
80
+ "@rollup/plugin-inject": "^5.0.3",
81
+ "@rollup/plugin-node-resolve": "^15.2.1",
82
+ "@rollup/plugin-replace": "^5.0.2",
83
+ "@rollup/plugin-terser": "^0.4.3",
84
+ "@rollup/plugin-typescript": "^11.1.3",
85
+ "@types/node": "^20.5.7",
86
+ "bumpp": "^9.2.0",
87
+ "eslint": "^8.48.0",
88
+ "eslint-config-unjs": "^0.2.1",
89
+ "fast-glob": "^3.3.1",
90
+ "pdfjs-dist": "^3.10.111",
91
+ "prettier": "^3.0.2",
92
+ "rollup": "^3.28.1",
69
93
  "typescript": "^5.1.6",
70
- "unbuild": "^2.0.0-rc.0"
94
+ "unbuild": "^2.0.0",
95
+ "unenv": "^1.7.4",
96
+ "vitest": "^0.34.3"
71
97
  }
72
98
  }
@@ -1,56 +0,0 @@
1
- 'use strict';
2
-
3
- let resolvedModule;
4
- async function getDocumentProxy(data, options = {}) {
5
- const { getDocument } = await getResolvedPDFJS();
6
- const pdf = await getDocument({
7
- data,
8
- useWorkerFetch: false,
9
- isEvalSupported: false,
10
- useSystemFonts: true,
11
- ...options
12
- }).promise;
13
- return pdf;
14
- }
15
- async function defineUnPDFConfig({ pdfjs }) {
16
- if (pdfjs) {
17
- try {
18
- const { default: mod } = await pdfjs();
19
- resolvedModule = mod;
20
- } catch (error) {
21
- throw new Error("Resolving the PDF.js module failed. Please check your configuration.");
22
- }
23
- }
24
- }
25
- async function getResolvedPDFJS() {
26
- if (!resolvedModule)
27
- await resolvePDFJSImports();
28
- return resolvedModule;
29
- }
30
- async function resolvePDFJSImports(pdfjs) {
31
- if (resolvedModule)
32
- return;
33
- if (pdfjs) {
34
- try {
35
- const { default: mod } = await pdfjs();
36
- resolvedModule = mod;
37
- } catch (error) {
38
- throw new Error("Resolving the PDF.js module failed. Please check your configuration.");
39
- }
40
- }
41
- try {
42
- const { default: mod } = await import('pdfjs-dist');
43
- resolvedModule = mod;
44
- } catch (error) {
45
- throw new Error("PDF.js is not available. Please add the package as a dependency.");
46
- }
47
- }
48
- function isPDFDocumentProxy(data) {
49
- return typeof data === "object" && data !== null && "_pdfInfo" in data;
50
- }
51
-
52
- exports.defineUnPDFConfig = defineUnPDFConfig;
53
- exports.getDocumentProxy = getDocumentProxy;
54
- exports.getResolvedPDFJS = getResolvedPDFJS;
55
- exports.isPDFDocumentProxy = isPDFDocumentProxy;
56
- exports.resolvePDFJSImports = resolvePDFJSImports;
@@ -1,52 +0,0 @@
1
- 'use strict';
2
-
3
- const utils = require('./unpdf.61a2a4e1.cjs');
4
-
5
- async function getPDFMeta(data) {
6
- const pdf = utils.isPDFDocumentProxy(data) ? data : await utils.getDocumentProxy(data);
7
- const meta = await pdf.getMetadata().catch(() => null);
8
- return {
9
- info: meta?.info ?? {},
10
- metadata: meta?.metadata?.getAll() ?? {}
11
- };
12
- }
13
-
14
- async function extractPDFText(data, { mergePages = false } = {}) {
15
- const pdf = utils.isPDFDocumentProxy(data) ? data : await utils.getDocumentProxy(data);
16
- const texts = await Promise.all(
17
- Array.from({ length: pdf.numPages }, (_, i) => getPageText(pdf, i + 1))
18
- );
19
- const filteredTexts = texts.filter(Boolean);
20
- return {
21
- totalPages: pdf.numPages,
22
- text: mergePages ? filteredTexts.join("\n\n") : filteredTexts
23
- };
24
- }
25
- async function getPageText(pdf, pageNumber) {
26
- const page = await pdf.getPage(pageNumber);
27
- const content = await page.getTextContent();
28
- const items = content.items;
29
- if (items.length === 0)
30
- return;
31
- return items.map(({ str }) => str).join("\n");
32
- }
33
-
34
- async function getImagesFromPage(data, pageNumber) {
35
- const pdf = utils.isPDFDocumentProxy(data) ? data : await utils.getDocumentProxy(data);
36
- const page = await pdf.getPage(pageNumber);
37
- const operatorList = await page.getOperatorList();
38
- const { OPS } = await utils.getResolvedPDFJS();
39
- const images = [];
40
- for (const op of operatorList.fnArray) {
41
- if (op !== OPS.paintImageXObject)
42
- continue;
43
- const image = await page.objs.get(operatorList.argsArray[op][0]);
44
- if (image.data)
45
- images.push(image.data.buffer);
46
- }
47
- return images;
48
- }
49
-
50
- exports.extractPDFText = extractPDFText;
51
- exports.getImagesFromPage = getImagesFromPage;
52
- exports.getPDFMeta = getPDFMeta;
@@ -1,50 +0,0 @@
1
- let resolvedModule;
2
- async function getDocumentProxy(data, options = {}) {
3
- const { getDocument } = await getResolvedPDFJS();
4
- const pdf = await getDocument({
5
- data,
6
- useWorkerFetch: false,
7
- isEvalSupported: false,
8
- useSystemFonts: true,
9
- ...options
10
- }).promise;
11
- return pdf;
12
- }
13
- async function defineUnPDFConfig({ pdfjs }) {
14
- if (pdfjs) {
15
- try {
16
- const { default: mod } = await pdfjs();
17
- resolvedModule = mod;
18
- } catch (error) {
19
- throw new Error("Resolving the PDF.js module failed. Please check your configuration.");
20
- }
21
- }
22
- }
23
- async function getResolvedPDFJS() {
24
- if (!resolvedModule)
25
- await resolvePDFJSImports();
26
- return resolvedModule;
27
- }
28
- async function resolvePDFJSImports(pdfjs) {
29
- if (resolvedModule)
30
- return;
31
- if (pdfjs) {
32
- try {
33
- const { default: mod } = await pdfjs();
34
- resolvedModule = mod;
35
- } catch (error) {
36
- throw new Error("Resolving the PDF.js module failed. Please check your configuration.");
37
- }
38
- }
39
- try {
40
- const { default: mod } = await import('pdfjs-dist');
41
- resolvedModule = mod;
42
- } catch (error) {
43
- throw new Error("PDF.js is not available. Please add the package as a dependency.");
44
- }
45
- }
46
- function isPDFDocumentProxy(data) {
47
- return typeof data === "object" && data !== null && "_pdfInfo" in data;
48
- }
49
-
50
- export { getResolvedPDFJS as a, defineUnPDFConfig as d, getDocumentProxy as g, isPDFDocumentProxy as i, resolvePDFJSImports as r };
@@ -1,48 +0,0 @@
1
- import { i as isPDFDocumentProxy, g as getDocumentProxy, a as getResolvedPDFJS } from './unpdf.c7f36e56.mjs';
2
-
3
- async function getPDFMeta(data) {
4
- const pdf = isPDFDocumentProxy(data) ? data : await getDocumentProxy(data);
5
- const meta = await pdf.getMetadata().catch(() => null);
6
- return {
7
- info: meta?.info ?? {},
8
- metadata: meta?.metadata?.getAll() ?? {}
9
- };
10
- }
11
-
12
- async function extractPDFText(data, { mergePages = false } = {}) {
13
- const pdf = isPDFDocumentProxy(data) ? data : await getDocumentProxy(data);
14
- const texts = await Promise.all(
15
- Array.from({ length: pdf.numPages }, (_, i) => getPageText(pdf, i + 1))
16
- );
17
- const filteredTexts = texts.filter(Boolean);
18
- return {
19
- totalPages: pdf.numPages,
20
- text: mergePages ? filteredTexts.join("\n\n") : filteredTexts
21
- };
22
- }
23
- async function getPageText(pdf, pageNumber) {
24
- const page = await pdf.getPage(pageNumber);
25
- const content = await page.getTextContent();
26
- const items = content.items;
27
- if (items.length === 0)
28
- return;
29
- return items.map(({ str }) => str).join("\n");
30
- }
31
-
32
- async function getImagesFromPage(data, pageNumber) {
33
- const pdf = isPDFDocumentProxy(data) ? data : await getDocumentProxy(data);
34
- const page = await pdf.getPage(pageNumber);
35
- const operatorList = await page.getOperatorList();
36
- const { OPS } = await getResolvedPDFJS();
37
- const images = [];
38
- for (const op of operatorList.fnArray) {
39
- if (op !== OPS.paintImageXObject)
40
- continue;
41
- const image = await page.objs.get(operatorList.argsArray[op][0]);
42
- if (image.data)
43
- images.push(image.data.buffer);
44
- }
45
- return images;
46
- }
47
-
48
- export { getImagesFromPage as a, extractPDFText as e, getPDFMeta as g };