@docscode/adapter-pdf 1.0.0 → 1.0.1

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/index.cjs ADDED
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ PdfAdapter: () => PdfAdapter
34
+ });
35
+ module.exports = __toCommonJS(index_exports);
36
+ var Y = __toESM(require("yjs"), 1);
37
+ var import_core = require("@docscode/core");
38
+ var import_pdf_lib = require("pdf-lib");
39
+ var PdfAdapter = class {
40
+ format = "pdf";
41
+ docling = new import_core.DoclingClient();
42
+ async read(source) {
43
+ const yDoc = new Y.Doc();
44
+ const canonical = new import_core.CanonicalDoc(yDoc);
45
+ const input = Buffer.isBuffer(source) ? `base64:${source.toString("base64")}` : source;
46
+ const result = await this.docling.convert(input);
47
+ for (const block of result.content) {
48
+ if (block.type === "p") {
49
+ canonical.addParagraph(block.text);
50
+ }
51
+ }
52
+ return yDoc;
53
+ }
54
+ async write(doc, original) {
55
+ if (!original) {
56
+ throw new Error("PDF write adapter requires the original buffer to apply annotations.");
57
+ }
58
+ const pdfDoc = await import_pdf_lib.PDFDocument.load(original);
59
+ const pages = pdfDoc.getPages();
60
+ const firstPage = pages[0];
61
+ firstPage.drawText("-- Kairo AI Annotation Overlay --", {
62
+ x: 50,
63
+ y: 50,
64
+ size: 10,
65
+ color: (0, import_pdf_lib.rgb)(0.95, 0.1, 0.1)
66
+ });
67
+ return Buffer.from(await pdfDoc.save());
68
+ }
69
+ };
70
+ // Annotate the CommonJS export names for ESM import in node:
71
+ 0 && (module.exports = {
72
+ PdfAdapter
73
+ });
@@ -0,0 +1,11 @@
1
+ import * as Y from 'yjs';
2
+ import { FormatAdapter } from '@docscode/core';
3
+
4
+ declare class PdfAdapter implements FormatAdapter {
5
+ readonly format = "pdf";
6
+ private docling;
7
+ read(source: Buffer | string): Promise<Y.Doc>;
8
+ write(doc: Y.Doc, original?: Buffer): Promise<Buffer>;
9
+ }
10
+
11
+ export { PdfAdapter };
@@ -0,0 +1,11 @@
1
+ import * as Y from 'yjs';
2
+ import { FormatAdapter } from '@docscode/core';
3
+
4
+ declare class PdfAdapter implements FormatAdapter {
5
+ readonly format = "pdf";
6
+ private docling;
7
+ read(source: Buffer | string): Promise<Y.Doc>;
8
+ write(doc: Y.Doc, original?: Buffer): Promise<Buffer>;
9
+ }
10
+
11
+ export { PdfAdapter };
package/dist/index.js ADDED
@@ -0,0 +1,38 @@
1
+ // src/index.ts
2
+ import * as Y from "yjs";
3
+ import { CanonicalDoc, DoclingClient } from "@docscode/core";
4
+ import { PDFDocument, rgb } from "pdf-lib";
5
+ var PdfAdapter = class {
6
+ format = "pdf";
7
+ docling = new DoclingClient();
8
+ async read(source) {
9
+ const yDoc = new Y.Doc();
10
+ const canonical = new CanonicalDoc(yDoc);
11
+ const input = Buffer.isBuffer(source) ? `base64:${source.toString("base64")}` : source;
12
+ const result = await this.docling.convert(input);
13
+ for (const block of result.content) {
14
+ if (block.type === "p") {
15
+ canonical.addParagraph(block.text);
16
+ }
17
+ }
18
+ return yDoc;
19
+ }
20
+ async write(doc, original) {
21
+ if (!original) {
22
+ throw new Error("PDF write adapter requires the original buffer to apply annotations.");
23
+ }
24
+ const pdfDoc = await PDFDocument.load(original);
25
+ const pages = pdfDoc.getPages();
26
+ const firstPage = pages[0];
27
+ firstPage.drawText("-- Kairo AI Annotation Overlay --", {
28
+ x: 50,
29
+ y: 50,
30
+ size: 10,
31
+ color: rgb(0.95, 0.1, 0.1)
32
+ });
33
+ return Buffer.from(await pdfDoc.save());
34
+ }
35
+ };
36
+ export {
37
+ PdfAdapter
38
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docscode/adapter-pdf",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "PDF Format Adapter for Kairo",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
@@ -13,5 +13,8 @@
13
13
  "@docscode/core": "*",
14
14
  "pdf-lib": "^1.17.1",
15
15
  "yjs": "^13.6.30"
16
- }
17
- }
16
+ },
17
+ "files": [
18
+ "dist"
19
+ ]
20
+ }
package/src/index.ts DELETED
@@ -1,48 +0,0 @@
1
- import * as Y from 'yjs';
2
- import { FormatAdapter, CanonicalDoc, DoclingClient } from '@docscode/core';
3
- import { PDFDocument, rgb } from 'pdf-lib';
4
-
5
- export class PdfAdapter implements FormatAdapter {
6
- readonly format = 'pdf';
7
- private docling = new DoclingClient();
8
-
9
- async read(source: Buffer | string): Promise<Y.Doc> {
10
- const yDoc = new Y.Doc();
11
- const canonical = new CanonicalDoc(yDoc);
12
-
13
- const input = Buffer.isBuffer(source)
14
- ? `base64:${source.toString('base64')}`
15
- : source;
16
-
17
- const result = await this.docling.convert(input);
18
-
19
- for (const block of result.content) {
20
- if (block.type === 'p') {
21
- canonical.addParagraph(block.text);
22
- }
23
- }
24
-
25
- return yDoc;
26
- }
27
-
28
- async write(doc: Y.Doc, original?: Buffer): Promise<Buffer> {
29
- if (!original) {
30
- throw new Error('PDF write adapter requires the original buffer to apply annotations.');
31
- }
32
-
33
- const pdfDoc = await PDFDocument.load(original);
34
- const pages = pdfDoc.getPages();
35
- const firstPage = pages[0];
36
-
37
- // Placeholder for AI Annotation Layer
38
- // In a real implementation, we would map CRDT changes to specific coordinates
39
- firstPage.drawText('-- Kairo AI Annotation Overlay --', {
40
- x: 50,
41
- y: 50,
42
- size: 10,
43
- color: rgb(0.95, 0.1, 0.1),
44
- });
45
-
46
- return Buffer.from(await pdfDoc.save());
47
- }
48
- }