@veryfront/ext-document-kreuzberg 0.1.989 → 0.1.991
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/esm/extensions/ext-document-kreuzberg/src/extraction-config.d.ts +2 -0
- package/esm/extensions/ext-document-kreuzberg/src/extraction-config.d.ts.map +1 -0
- package/esm/extensions/ext-document-kreuzberg/src/extraction-config.js +17 -0
- package/esm/extensions/ext-document-kreuzberg/src/index.d.ts.map +1 -1
- package/esm/extensions/ext-document-kreuzberg/src/index.js +3 -2
- package/esm/extensions/ext-document-kreuzberg/src/kreuzberg.d.ts.map +1 -1
- package/esm/extensions/ext-document-kreuzberg/src/native-progress-extraction-worker.js +7 -1
- package/esm/extensions/ext-document-kreuzberg/src/upload-extraction-worker.js +6 -1
- package/package.json +2 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extraction-config.d.ts","sourceRoot":"","sources":["../../../../src/extensions/ext-document-kreuzberg/src/extraction-config.ts"],"names":[],"mappings":"AAcA,wBAAgB,2BAA2B,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAIjG"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const PDF_TEXT_ONLY_EXTRACTION_CONFIG = {
|
|
2
|
+
images: { extractImages: false },
|
|
3
|
+
pdfOptions: {
|
|
4
|
+
extractImages: false,
|
|
5
|
+
extractMetadata: false,
|
|
6
|
+
extractAnnotations: false,
|
|
7
|
+
hierarchy: { enabled: false, includeBbox: false },
|
|
8
|
+
},
|
|
9
|
+
};
|
|
10
|
+
function normalizeMimeType(mimeType) {
|
|
11
|
+
return mimeType.toLowerCase().split(";")[0]?.trim() ?? "";
|
|
12
|
+
}
|
|
13
|
+
export function extractionConfigForMimeType(mimeType) {
|
|
14
|
+
return normalizeMimeType(mimeType) === "application/pdf"
|
|
15
|
+
? PDF_TEXT_ONLY_EXTRACTION_CONFIG
|
|
16
|
+
: undefined;
|
|
17
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/extensions/ext-document-kreuzberg/src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,4BAA4B,CAAC;AAKpC,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AAC1F,OAAO,KAAK,EACV,yBAAyB,EAEzB,iBAAiB,EACjB,kBAAkB,EACnB,MAAM,yCAAyC,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/extensions/ext-document-kreuzberg/src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,4BAA4B,CAAC;AAKpC,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AAC1F,OAAO,KAAK,EACV,yBAAyB,EAEzB,iBAAiB,EACjB,kBAAkB,EACnB,MAAM,yCAAyC,CAAC;AAKjD,2EAA2E;AAC3E,eAAO,MAAM,qBAAqB,SAAU,CAAC;AAC7C,eAAO,MAAM,+BAA+B,SAAU,CAAC;AACvD,eAAO,MAAM,+BAA+B,QAAc,CAAC;AAE3D,iBAAS,mBAAmB,CAC1B,MAAM,EAAE,WAAW,EACnB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,MAAM,CAAC,CA0CjB;AAED,MAAM,WAAW,8BAA8B;IAC7C,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,mBAAmB,CAAC,EAAE,MAAM,OAAO,CAAC,kBAAkB,CAAC,CAAC;IACxD,mBAAmB,CAAC,EAAE,OAAO,mBAAmB,CAAC;IACjD,6BAA6B,CAAC,EAAE,OAAO,6BAA6B,CAAC;IACrE,MAAM,CAAC,EAAE,IAAI,CAAC,eAAe,EAAE,MAAM,CAAC,CAAC;CACxC;AA2CD,iBAAS,6BAA6B,CACpC,MAAM,EAAE,WAAW,EACnB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,yBAAyB,GACjC,OAAO,CAAC,MAAM,CAAC,CAgFjB;AAED,qBAAa,0BAA2B,YAAW,iBAAiB;IACtD,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAAJ,IAAI,GAAE,8BAAmC;IAEtE,eAAe,IAAI,OAAO,CAAC,kBAAkB,CAAC;IAIxC,eAAe,CACnB,MAAM,EAAE,WAAW,EACnB,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE,yBAA8B,GACtC,OAAO,CAAC,MAAM,CAAC;CAoDnB;AAED,QAAA,MAAM,oBAAoB,EAAE,gBAiB3B,CAAC;AAEF,eAAe,oBAAoB,CAAC"}
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
import "../../../_dnt.polyfills.js";
|
|
10
10
|
import * as dntShim from "../../../_dnt.shims.js";
|
|
11
11
|
import { isMissingPackageError, loadKreuzberg, loadKreuzbergNative } from "./kreuzberg.js";
|
|
12
|
+
import { extractionConfigForMimeType } from "./extraction-config.js";
|
|
12
13
|
import { isDeno } from "./runtime.js";
|
|
13
14
|
/** Maximum time to wait for fallback worker extraction before aborting. */
|
|
14
15
|
export const EXTRACTION_TIMEOUT_MS = 120_000;
|
|
@@ -62,7 +63,7 @@ function isNativeProgressMimeType(mimeType) {
|
|
|
62
63
|
}
|
|
63
64
|
async function extractWithNativeKreuzberg(buffer, mimeType, loadNative) {
|
|
64
65
|
const { extractBytes } = await loadNative();
|
|
65
|
-
const result = await extractBytes(new Uint8Array(buffer), mimeType);
|
|
66
|
+
const result = await extractBytes(new Uint8Array(buffer), mimeType, extractionConfigForMimeType(mimeType));
|
|
66
67
|
return result.content;
|
|
67
68
|
}
|
|
68
69
|
function warningDetails(mimeType, error) {
|
|
@@ -159,7 +160,7 @@ export class KreuzbergDocumentExtractor {
|
|
|
159
160
|
// PDF path can hang on valid large manuals.
|
|
160
161
|
if (!isDenoRuntime) {
|
|
161
162
|
const { extractBytes } = await loadKreuzberg();
|
|
162
|
-
const result = await extractBytes(new Uint8Array(buffer), mimeType);
|
|
163
|
+
const result = await extractBytes(new Uint8Array(buffer), mimeType, extractionConfigForMimeType(mimeType));
|
|
163
164
|
return result.content;
|
|
164
165
|
}
|
|
165
166
|
if (options.onProgress && isNativeProgressMimeType(mimeType)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kreuzberg.d.ts","sourceRoot":"","sources":["../../../../src/extensions/ext-document-kreuzberg/src/kreuzberg.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yCAAyC,CAAC;
|
|
1
|
+
{"version":3,"file":"kreuzberg.d.ts","sourceRoot":"","sources":["../../../../src/extensions/ext-document-kreuzberg/src/kreuzberg.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yCAAyC,CAAC;AAOlF,wBAAsB,mBAAmB,IAAI,OAAO,CAAC,kBAAkB,CAAC,CAWvE;AAED,wBAAsB,aAAa,IAAI,OAAO,CAAC,kBAAkB,CAAC,CA2BjE;AAeD,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAqB7D"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { PDFDocument } from "pdf-lib";
|
|
2
2
|
import JSZip from "jszip";
|
|
3
|
+
import { extractionConfigForMimeType } from "./extraction-config.js";
|
|
3
4
|
import { loadKreuzbergNative } from "./kreuzberg.js";
|
|
4
5
|
function postProgress(event) {
|
|
5
6
|
self.postMessage({ type: "progress", event });
|
|
@@ -93,12 +94,17 @@ async function extractPdfByPage(buffer) {
|
|
|
93
94
|
const source = await PDFDocument.load(buffer, { ignoreEncryption: true });
|
|
94
95
|
const total = source.getPageCount();
|
|
95
96
|
const pages = [];
|
|
97
|
+
const pdfConfig = extractionConfigForMimeType("application/pdf");
|
|
96
98
|
for (let index = 0; index < total; index += 1) {
|
|
97
99
|
const singlePage = await PDFDocument.create();
|
|
98
100
|
const [page] = await singlePage.copyPages(source, [index]);
|
|
99
101
|
singlePage.addPage(page);
|
|
100
102
|
const bytes = await singlePage.save({ useObjectStreams: false });
|
|
101
|
-
const result = await extractBytes(
|
|
103
|
+
const result = await extractBytes(
|
|
104
|
+
new Uint8Array(bytes),
|
|
105
|
+
"application/pdf",
|
|
106
|
+
pdfConfig
|
|
107
|
+
);
|
|
102
108
|
const content = result.content.trim();
|
|
103
109
|
pages.push(content);
|
|
104
110
|
postProgress({
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { loadKreuzberg } from "./kreuzberg.js";
|
|
2
|
+
import { extractionConfigForMimeType } from "./extraction-config.js";
|
|
2
3
|
self.onmessage = async (event) => {
|
|
3
4
|
if (event.origin && event.origin !== self.location.origin) {
|
|
4
5
|
self.postMessage(
|
|
@@ -11,7 +12,11 @@ self.onmessage = async (event) => {
|
|
|
11
12
|
try {
|
|
12
13
|
const { buffer, mimeType } = event.data;
|
|
13
14
|
const { extractBytes } = await loadKreuzberg();
|
|
14
|
-
const result = await extractBytes(
|
|
15
|
+
const result = await extractBytes(
|
|
16
|
+
new Uint8Array(buffer),
|
|
17
|
+
mimeType,
|
|
18
|
+
extractionConfigForMimeType(mimeType)
|
|
19
|
+
);
|
|
15
20
|
self.postMessage({ content: result.content });
|
|
16
21
|
} catch (err) {
|
|
17
22
|
const message = err instanceof Error ? err.message : String(err);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@veryfront/ext-document-kreuzberg",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.991",
|
|
4
4
|
"description": "Veryfront first-party extension package for ext-document-kreuzberg",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"veryfront",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"pdf-lib": "1.17.1"
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {
|
|
58
|
-
"veryfront": "^0.1.
|
|
58
|
+
"veryfront": "^0.1.991"
|
|
59
59
|
},
|
|
60
60
|
"type": "module",
|
|
61
61
|
"types": "./esm/extensions/ext-document-kreuzberg/src/index.d.ts",
|