@convo-lang/convo-lang-pdf 0.7.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.
@@ -0,0 +1,3 @@
1
+ {
2
+ "sideEffects": false
3
+ }
@@ -0,0 +1,2 @@
1
+ export * from './lib/ConvoPdfDocReader';
2
+ export * from './lib/convoPdfDocReaderFactory';
@@ -0,0 +1,3 @@
1
+ export * from './lib/ConvoPdfDocReader';
2
+ export * from './lib/convoPdfDocReaderFactory';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/convo-lang-pdf/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC;AACxC,cAAc,gCAAgC,CAAC"}
@@ -0,0 +1,12 @@
1
+ import { ConvoDocReader } from "@convo-lang/convo-lang";
2
+ import { VfsItem } from "@iyio/vfs";
3
+ export declare class ConvoPdfDocReader implements ConvoDocReader {
4
+ private readonly reader;
5
+ constructor(src: VfsItem | string);
6
+ private _isDisposed;
7
+ get isDisposed(): boolean;
8
+ dispose(): void;
9
+ pageToImageAsync(pageIndex: number, format?: string): Promise<Blob | undefined>;
10
+ getPageCountAsync(): Promise<number>;
11
+ pageToTextAsync(pageIndex: number): Promise<string>;
12
+ }
@@ -0,0 +1,54 @@
1
+ import { __awaiter } from "tslib";
2
+ import { pdfReaderPool } from "@iyio/pdf-viewer";
3
+ import { getVfsItemUrl } from "@iyio/vfs";
4
+ export class ConvoPdfDocReader {
5
+ constructor(src) {
6
+ this._isDisposed = false;
7
+ const url = getVfsItemUrl(src);
8
+ if (!url) {
9
+ throw new Error('Unable to get URL from src');
10
+ }
11
+ const reader = pdfReaderPool().getReader(url);
12
+ this.reader = reader;
13
+ }
14
+ get isDisposed() { return this._isDisposed; }
15
+ dispose() {
16
+ if (this._isDisposed) {
17
+ return;
18
+ }
19
+ this._isDisposed = true;
20
+ pdfReaderPool().returnReader(this.reader);
21
+ }
22
+ pageToImageAsync(pageIndex, format) {
23
+ return __awaiter(this, void 0, void 0, function* () {
24
+ const r = yield this.reader.pageToImageAsync(pageIndex, format);
25
+ return r !== null && r !== void 0 ? r : undefined;
26
+ });
27
+ }
28
+ getPageCountAsync() {
29
+ return __awaiter(this, void 0, void 0, function* () {
30
+ var _a, _b;
31
+ return (_b = (_a = (yield this.reader.getDocAsync())) === null || _a === void 0 ? void 0 : _a.numPages) !== null && _b !== void 0 ? _b : 0;
32
+ });
33
+ }
34
+ pageToTextAsync(pageIndex) {
35
+ return __awaiter(this, void 0, void 0, function* () {
36
+ const page = yield this.reader.getPageAsync(pageIndex);
37
+ if (!page) {
38
+ return '';
39
+ }
40
+ const content = yield page.page.getTextContent();
41
+ const out = [];
42
+ for (const c of content.items) {
43
+ const item = c;
44
+ if (!(item === null || item === void 0 ? void 0 : item.str)) {
45
+ continue;
46
+ }
47
+ out.push(item.str);
48
+ out.push(item.hasEOL ? '\n\n' : ' ');
49
+ }
50
+ return out.join('');
51
+ });
52
+ }
53
+ }
54
+ //# sourceMappingURL=ConvoPdfDocReader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ConvoPdfDocReader.js","sourceRoot":"","sources":["../../../../../../packages/convo-lang-pdf/src/lib/ConvoPdfDocReader.ts"],"names":[],"mappings":";AACA,OAAO,EAAa,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAW,aAAa,EAAE,MAAM,WAAW,CAAC;AAGnD,MAAM,OAAO,iBAAiB;IAK1B,YAAmB,GAAkB;QAU7B,gBAAW,GAAC,KAAK,CAAC;QARtB,MAAM,GAAG,GAAC,aAAa,CAAC,GAAG,CAAC,CAAC;QAC7B,IAAG,CAAC,GAAG,EAAC,CAAC;YACL,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;QAClD,CAAC;QAED,MAAM,MAAM,GAAC,aAAa,EAAE,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;QAC5C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AC,CAAC;gBACnB,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAA,CAAC,CAAA,MAAM,CAAA,CAAC,CAAA,GAAG,CAAC,CAAC;YACrC,CAAC;YAED,OAAO,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;QACvB,CAAC;KAAA;CACJ"}
@@ -0,0 +1,2 @@
1
+ import { ConvoDocReaderFactory } from "@convo-lang/convo-lang";
2
+ export declare const convoPdfDocReaderFactory: ConvoDocReaderFactory;
@@ -0,0 +1,5 @@
1
+ import { ConvoPdfDocReader } from "./ConvoPdfDocReader";
2
+ export const convoPdfDocReaderFactory = (contentType, url, src) => {
3
+ return contentType.endsWith('/pdf') ? new ConvoPdfDocReader(src) : undefined;
4
+ };
5
+ //# sourceMappingURL=convoPdfDocReaderFactory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"convoPdfDocReaderFactory.js","sourceRoot":"","sources":["../../../../../../packages/convo-lang-pdf/src/lib/convoPdfDocReaderFactory.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD,MAAM,CAAC,MAAM,wBAAwB,GAAuB,CAAC,WAAW,EAAC,GAAG,EAAC,GAAG,EAAC,EAAE;IAC/E,OAAO,WAAW,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA,CAAC,CAAA,IAAI,iBAAiB,CAAC,GAAG,CAAC,CAAA,CAAC,CAAA,SAAS,CAAC;AAC7E,CAAC,CAAA"}
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "@convo-lang/convo-lang-pdf",
3
+ "version": "0.7.0",
4
+ "sideEffects": false,
5
+ "dependencies": {
6
+ "blurhash": "^2.0.5",
7
+ "date-fns": "^2.29.3",
8
+ "json5": "^2.2.3",
9
+ "pdfjs-dist": "^3.11.174",
10
+ "react": "^18.0.0",
11
+ "react-dom": "^18.0.0",
12
+ "rxjs": "^7.8.0",
13
+ "uuid": "^9.0.0",
14
+ "zod": "^3.21.4"
15
+ },
16
+ "peerDependencies": {
17
+ "@convo-lang/convo-lang": "0.7.0",
18
+ "@iyio/at-dot-css": "0.7.0",
19
+ "@iyio/common": "0.7.0",
20
+ "@iyio/pdf-viewer": "0.7.0",
21
+ "@iyio/react-common": "0.7.0",
22
+ "@iyio/rtxt": "0.7.0",
23
+ "@iyio/vfs": "0.7.0"
24
+ },
25
+ "main": "./src/index.js",
26
+ "module": "./esm/src/index.js"
27
+ }
package/src/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './lib/ConvoPdfDocReader';
2
+ export * from './lib/convoPdfDocReaderFactory';
package/src/index.js ADDED
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./lib/ConvoPdfDocReader"), exports);
5
+ tslib_1.__exportStar(require("./lib/convoPdfDocReaderFactory"), exports);
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/convo-lang-pdf/src/index.ts"],"names":[],"mappings":";;;AAAA,kEAAwC;AACxC,yEAA+C"}
@@ -0,0 +1,12 @@
1
+ import { ConvoDocReader } from "@convo-lang/convo-lang";
2
+ import { VfsItem } from "@iyio/vfs";
3
+ export declare class ConvoPdfDocReader implements ConvoDocReader {
4
+ private readonly reader;
5
+ constructor(src: VfsItem | string);
6
+ private _isDisposed;
7
+ get isDisposed(): boolean;
8
+ dispose(): void;
9
+ pageToImageAsync(pageIndex: number, format?: string): Promise<Blob | undefined>;
10
+ getPageCountAsync(): Promise<number>;
11
+ pageToTextAsync(pageIndex: number): Promise<string>;
12
+ }
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConvoPdfDocReader = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const pdf_viewer_1 = require("@iyio/pdf-viewer");
6
+ const vfs_1 = require("@iyio/vfs");
7
+ class ConvoPdfDocReader {
8
+ constructor(src) {
9
+ this._isDisposed = false;
10
+ const url = (0, vfs_1.getVfsItemUrl)(src);
11
+ if (!url) {
12
+ throw new Error('Unable to get URL from src');
13
+ }
14
+ const reader = (0, pdf_viewer_1.pdfReaderPool)().getReader(url);
15
+ this.reader = reader;
16
+ }
17
+ get isDisposed() { return this._isDisposed; }
18
+ dispose() {
19
+ if (this._isDisposed) {
20
+ return;
21
+ }
22
+ this._isDisposed = true;
23
+ (0, pdf_viewer_1.pdfReaderPool)().returnReader(this.reader);
24
+ }
25
+ pageToImageAsync(pageIndex, format) {
26
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
27
+ const r = yield this.reader.pageToImageAsync(pageIndex, format);
28
+ return r !== null && r !== void 0 ? r : undefined;
29
+ });
30
+ }
31
+ getPageCountAsync() {
32
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
33
+ var _a, _b;
34
+ return (_b = (_a = (yield this.reader.getDocAsync())) === null || _a === void 0 ? void 0 : _a.numPages) !== null && _b !== void 0 ? _b : 0;
35
+ });
36
+ }
37
+ pageToTextAsync(pageIndex) {
38
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
39
+ const page = yield this.reader.getPageAsync(pageIndex);
40
+ if (!page) {
41
+ return '';
42
+ }
43
+ const content = yield page.page.getTextContent();
44
+ const out = [];
45
+ for (const c of content.items) {
46
+ const item = c;
47
+ if (!(item === null || item === void 0 ? void 0 : item.str)) {
48
+ continue;
49
+ }
50
+ out.push(item.str);
51
+ out.push(item.hasEOL ? '\n\n' : ' ');
52
+ }
53
+ return out.join('');
54
+ });
55
+ }
56
+ }
57
+ exports.ConvoPdfDocReader = ConvoPdfDocReader;
58
+ //# sourceMappingURL=ConvoPdfDocReader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ConvoPdfDocReader.js","sourceRoot":"","sources":["../../../../../packages/convo-lang-pdf/src/lib/ConvoPdfDocRe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d,CAAC;YACD,MAAM,OAAO,GAAC,MAAM,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC;YAC/C,MAAM,GAAG,GAAU,EAAE,CAAC;YAEtB,KAAI,MAAM,CAAC,IAAI,OAAO,CAAC,KAAK,EAAC,CAAC;gBAC1B,MAAM,IAAI,GAAC,CAAa,CAAC;gBACzB,IAAG,CAAC,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,GAAG,CAAA,EAAC,CAAC;oBACX,SAAS;gBACb,CAAC;gBACD,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;gBACnB,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAA,CAAC,CAAA,MAAM,CAAA,CAAC,CAAA,GAAG,CAAC,CAAC;YACrC,CAAC;YAED,OAAO,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;QACvB,CAAC;KAAA;CACJ;AArDD,8CAqDC"}
@@ -0,0 +1,2 @@
1
+ import { ConvoDocReaderFactory } from "@convo-lang/convo-lang";
2
+ export declare const convoPdfDocReaderFactory: ConvoDocReaderFactory;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.convoPdfDocReaderFactory = void 0;
4
+ const ConvoPdfDocReader_1 = require("./ConvoPdfDocReader");
5
+ const convoPdfDocReaderFactory = (contentType, url, src) => {
6
+ return contentType.endsWith('/pdf') ? new ConvoPdfDocReader_1.ConvoPdfDocReader(src) : undefined;
7
+ };
8
+ exports.convoPdfDocReaderFactory = convoPdfDocReaderFactory;
9
+ //# sourceMappingURL=convoPdfDocReaderFactory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"convoPdfDocReaderFactory.js","sourceRoot":"","sources":["../../../../../packages/convo-lang-pdf/src/lib/convoPdfDocReaderFactory.ts"],"names":[],"mappings":";;;AACA,2DAAwD;AAEjD,MAAM,wBAAwB,GAAuB,CAAC,WAAW,EAAC,GAAG,EAAC,GAAG,EAAC,EAAE;IAC/E,OAAO,WAAW,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA,CAAC,CAAA,IAAI,qCAAiB,CAAC,GAAG,CAAC,CAAA,CAAC,CAAA,SAAS,CAAC;AAC7E,CAAC,CAAA;AAFY,QAAA,wBAAwB,4BAEpC"}
@@ -0,0 +1,4 @@
1
+ {
2
+ "type": "commonjs",
3
+ "sideEffects": false
4
+ }