@larkup/tool-doc-editor 0.2.4 → 0.2.6
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/editor.js +1 -15
- package/package.json +4 -4
- package/src/editor.ts +1 -15
- package/tool.manifest.json +1 -1
package/dist/editor.js
CHANGED
|
@@ -99,19 +99,13 @@ export async function applyFieldEdits(sessionId, edits) {
|
|
|
99
99
|
try {
|
|
100
100
|
let resultBuffer;
|
|
101
101
|
let updatedFields = [];
|
|
102
|
-
// Map field IDs to actual field names for native PDF filling and sandbox scripts.
|
|
103
|
-
// The LLM sends field IDs like "pdf_field_0"; we resolve them to the actual PDF field names.
|
|
104
|
-
// If the ID doesn't match any field, try matching by name directly (case-insensitive).
|
|
105
102
|
const resolvedEdits = edits.map((edit) => {
|
|
106
|
-
// Primary: look up by ID
|
|
107
103
|
let field = session.parsed.fields.find((f) => f.id === edit.fieldId);
|
|
108
104
|
if (!field) {
|
|
109
|
-
// Fallback: match by name (case-insensitive, trimmed)
|
|
110
105
|
const needle = edit.fieldId.trim().toLowerCase();
|
|
111
106
|
field = session.parsed.fields.find((f) => f.name.trim().toLowerCase() === needle);
|
|
112
107
|
}
|
|
113
108
|
if (!field) {
|
|
114
|
-
// Fallback: match by partial name containment
|
|
115
109
|
const needle = edit.fieldId.trim().toLowerCase();
|
|
116
110
|
field = session.parsed.fields.find((f) => f.name.trim().toLowerCase().includes(needle) ||
|
|
117
111
|
needle.includes(f.name.trim().toLowerCase()));
|
|
@@ -464,26 +458,18 @@ export async function applySignature(sessionId, data) {
|
|
|
464
458
|
let resolvedY = null;
|
|
465
459
|
if (data.detectedContext) {
|
|
466
460
|
try {
|
|
467
|
-
// Use sandbox PyPDF to find text coordinates on this page
|
|
468
461
|
const coords = await findTextPositionOnPage(buffer, pageIndex, data.detectedContext);
|
|
469
462
|
if (coords) {
|
|
470
|
-
// Place signature right below the detected text line
|
|
471
463
|
resolvedX = coords.x;
|
|
472
|
-
// coords.y is the bottom of the text in PDF coordinate system
|
|
473
|
-
// Place signature just below (subtract a small offset for spacing)
|
|
474
464
|
resolvedY = coords.y - 10;
|
|
475
465
|
}
|
|
476
466
|
}
|
|
477
|
-
catch {
|
|
478
|
-
// Fallback to UI-provided coordinates
|
|
479
|
-
}
|
|
467
|
+
catch { }
|
|
480
468
|
}
|
|
481
|
-
// Fall back to user-specified percentages
|
|
482
469
|
if (resolvedX === null || resolvedY === null) {
|
|
483
470
|
const xPct = data.x ?? 50;
|
|
484
471
|
const yPct = data.y ?? 50;
|
|
485
472
|
resolvedX = (xPct / 100) * width;
|
|
486
|
-
// Invert Y: UI treats y=0 as top, PDF treats y=0 as bottom
|
|
487
473
|
resolvedY = height - (yPct / 100) * height;
|
|
488
474
|
}
|
|
489
475
|
const x = resolvedX;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@larkup/tool-doc-editor",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.6",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"mammoth": "^1.12.0",
|
|
42
42
|
"pdf-lib": "^1.17.1",
|
|
43
43
|
"@larkup/sandbox": "0.1.2",
|
|
44
|
-
"@larkup/core": "0.2.
|
|
44
|
+
"@larkup/core": "0.2.5"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
47
|
"@larkup/marketplace": ">=0.1.0"
|
|
@@ -53,12 +53,12 @@
|
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"typescript": "5.7.3",
|
|
56
|
-
"@larkup/marketplace": "0.1.
|
|
56
|
+
"@larkup/marketplace": "0.1.11"
|
|
57
57
|
},
|
|
58
58
|
"license": "Apache-2.0",
|
|
59
59
|
"repository": {
|
|
60
60
|
"type": "git",
|
|
61
|
-
"url": "https://github.com/Larkup-AI/larkup
|
|
61
|
+
"url": "https://github.com/Larkup-AI/larkup",
|
|
62
62
|
"directory": "packages/tools/doc-editor"
|
|
63
63
|
},
|
|
64
64
|
"scripts": {
|
package/src/editor.ts
CHANGED
|
@@ -144,19 +144,13 @@ export async function applyFieldEdits(sessionId: string, edits: FieldEdit[]): Pr
|
|
|
144
144
|
let resultBuffer: Buffer;
|
|
145
145
|
let updatedFields: string[] = [];
|
|
146
146
|
|
|
147
|
-
// Map field IDs to actual field names for native PDF filling and sandbox scripts.
|
|
148
|
-
// The LLM sends field IDs like "pdf_field_0"; we resolve them to the actual PDF field names.
|
|
149
|
-
// If the ID doesn't match any field, try matching by name directly (case-insensitive).
|
|
150
147
|
const resolvedEdits = edits.map((edit) => {
|
|
151
|
-
// Primary: look up by ID
|
|
152
148
|
let field = session.parsed.fields.find((f) => f.id === edit.fieldId);
|
|
153
149
|
if (!field) {
|
|
154
|
-
// Fallback: match by name (case-insensitive, trimmed)
|
|
155
150
|
const needle = edit.fieldId.trim().toLowerCase();
|
|
156
151
|
field = session.parsed.fields.find((f) => f.name.trim().toLowerCase() === needle);
|
|
157
152
|
}
|
|
158
153
|
if (!field) {
|
|
159
|
-
// Fallback: match by partial name containment
|
|
160
154
|
const needle = edit.fieldId.trim().toLowerCase();
|
|
161
155
|
field = session.parsed.fields.find(
|
|
162
156
|
(f) =>
|
|
@@ -575,26 +569,18 @@ export async function applySignature(sessionId: string, data: SignatureData): Pr
|
|
|
575
569
|
|
|
576
570
|
if (data.detectedContext) {
|
|
577
571
|
try {
|
|
578
|
-
// Use sandbox PyPDF to find text coordinates on this page
|
|
579
572
|
const coords = await findTextPositionOnPage(buffer, pageIndex, data.detectedContext);
|
|
580
573
|
if (coords) {
|
|
581
|
-
// Place signature right below the detected text line
|
|
582
574
|
resolvedX = coords.x;
|
|
583
|
-
// coords.y is the bottom of the text in PDF coordinate system
|
|
584
|
-
// Place signature just below (subtract a small offset for spacing)
|
|
585
575
|
resolvedY = coords.y - 10;
|
|
586
576
|
}
|
|
587
|
-
} catch {
|
|
588
|
-
// Fallback to UI-provided coordinates
|
|
589
|
-
}
|
|
577
|
+
} catch {}
|
|
590
578
|
}
|
|
591
579
|
|
|
592
|
-
// Fall back to user-specified percentages
|
|
593
580
|
if (resolvedX === null || resolvedY === null) {
|
|
594
581
|
const xPct = data.x ?? 50;
|
|
595
582
|
const yPct = data.y ?? 50;
|
|
596
583
|
resolvedX = (xPct / 100) * width;
|
|
597
|
-
// Invert Y: UI treats y=0 as top, PDF treats y=0 as bottom
|
|
598
584
|
resolvedY = height - (yPct / 100) * height;
|
|
599
585
|
}
|
|
600
586
|
|
package/tool.manifest.json
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"capabilities": ["document-editing", "form-filling", "document-preview"],
|
|
17
17
|
"tags": ["pdf", "docx", "pptx", "form", "canvas", "editor", "fill"],
|
|
18
18
|
"downloads": 0,
|
|
19
|
-
"repositoryUrl": "https://github.com/Larkup-AI/larkup
|
|
19
|
+
"repositoryUrl": "https://github.com/Larkup-AI/larkup",
|
|
20
20
|
"license": "Apache-2.0",
|
|
21
21
|
"updatedAt": "2026-07-20"
|
|
22
22
|
}
|