@embedpdf/engine-services 3.0.0-next.11 → 3.0.0-next.12
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 +305 -81
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +41 -2
- package/dist/index.d.ts +41 -2
- package/dist/index.js +305 -82
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1731,7 +1731,8 @@ var PagesReader = class {
|
|
|
1731
1731
|
});
|
|
1732
1732
|
return {
|
|
1733
1733
|
pageCount: pages.length,
|
|
1734
|
-
pages
|
|
1734
|
+
pages,
|
|
1735
|
+
namedPages: readNamedPages(fn, mem, docPtr)
|
|
1735
1736
|
};
|
|
1736
1737
|
});
|
|
1737
1738
|
}
|
|
@@ -1796,6 +1797,41 @@ function readUserUnit(fn, mem, docPtr, index, userUnitPtr) {
|
|
|
1796
1797
|
function readLabel(fn, mem, docPtr, index) {
|
|
1797
1798
|
return readUtf16String(mem, (buf, capacity) => fn.FPDF_GetPageLabel(docPtr, index, buf, capacity), null) || null;
|
|
1798
1799
|
}
|
|
1800
|
+
const NAMED_PAGE_TREES = [0, 1];
|
|
1801
|
+
const NAMED_PAGE_KIND_PAGE = 0;
|
|
1802
|
+
const NAMED_PAGE_KIND_TEMPLATE = 1;
|
|
1803
|
+
/**
|
|
1804
|
+
* The catalog's `/Names /Pages` and `/Names /Templates` registrations, in
|
|
1805
|
+
* tree order, each value classified by the fork (page / template /
|
|
1806
|
+
* dangling). Page-identity data like `label`, so it ships inside the same
|
|
1807
|
+
* snapshot — a registration is only meaningful against the page set that
|
|
1808
|
+
* contains its target.
|
|
1809
|
+
*/
|
|
1810
|
+
function readNamedPages(fn, mem, docPtr) {
|
|
1811
|
+
const entries = [];
|
|
1812
|
+
withScratchN(mem, [4, 4], ([objNumPtr, kindPtr]) => {
|
|
1813
|
+
for (const tree of NAMED_PAGE_TREES) {
|
|
1814
|
+
const count = fn.EPDFDoc_GetNamedPageCount(docPtr, tree);
|
|
1815
|
+
for (let index = 0; index < count; index++) {
|
|
1816
|
+
const name = readUtf16String(mem, (buf, capacity) => fn.EPDFDoc_GetNamedPageAt(docPtr, tree, index, buf, capacity, objNumPtr, kindPtr), "");
|
|
1817
|
+
if (name === null) continue;
|
|
1818
|
+
const objectNumber = Number(mem.peek(objNumPtr, "i32")) >>> 0;
|
|
1819
|
+
const kind = Number(mem.peek(kindPtr, "i32"));
|
|
1820
|
+
entries.push({
|
|
1821
|
+
name,
|
|
1822
|
+
target: kind === NAMED_PAGE_KIND_PAGE ? {
|
|
1823
|
+
kind: "page",
|
|
1824
|
+
pageObjectNumber: objectNumber
|
|
1825
|
+
} : kind === NAMED_PAGE_KIND_TEMPLATE ? {
|
|
1826
|
+
kind: "template",
|
|
1827
|
+
objectNumber
|
|
1828
|
+
} : { kind: "dangling" }
|
|
1829
|
+
});
|
|
1830
|
+
}
|
|
1831
|
+
}
|
|
1832
|
+
});
|
|
1833
|
+
return entries;
|
|
1834
|
+
}
|
|
1799
1835
|
//#endregion
|
|
1800
1836
|
//#region src/features/pages/PagesMutator.ts
|
|
1801
1837
|
/**
|
|
@@ -1943,6 +1979,38 @@ var PagesMutator = class {
|
|
|
1943
1979
|
cache: null
|
|
1944
1980
|
};
|
|
1945
1981
|
}
|
|
1982
|
+
/**
|
|
1983
|
+
* Register `name` → page in `/Names /Pages` (create, or replace what the
|
|
1984
|
+
* key points at); with `replace`, drop that other key first — a rename as
|
|
1985
|
+
* one job. Named pages are LAYOUT: page identity and order are untouched
|
|
1986
|
+
* (no registry refresh, no revision bumps) and the fresh snapshot is
|
|
1987
|
+
* returned like `move()`.
|
|
1988
|
+
*/
|
|
1989
|
+
setName(input, signal) {
|
|
1990
|
+
throwIfAborted(signal);
|
|
1991
|
+
if (input.name.length === 0) throw new EngineError(EngineErrorCode.InvalidArg, "pages.setName requires a non-empty name");
|
|
1992
|
+
const { fn, mem } = this.runtime;
|
|
1993
|
+
const docPtr = this.session.requireDocPtr();
|
|
1994
|
+
this.session.recordByObjectNumber(input.pageObjectNumber);
|
|
1995
|
+
if (input.replace !== void 0 && input.replace !== input.name && input.replace.length > 0) writeUtf16String(mem, input.replace, (ptr) => fn.EPDFDoc_RemoveNamedPage(docPtr, ptr));
|
|
1996
|
+
if (!writeUtf16String(mem, input.name, (ptr) => fn.EPDFDoc_SetNamedPage(docPtr, ptr, input.pageObjectNumber))) throw new EngineError(EngineErrorCode.Unknown, `EPDFDoc_SetNamedPage rejected '${input.name}' for page ${input.pageObjectNumber}`);
|
|
1997
|
+
return {
|
|
1998
|
+
layout: new PagesReader(this.runtime, this.session).read(signal),
|
|
1999
|
+
cache: null
|
|
2000
|
+
};
|
|
2001
|
+
}
|
|
2002
|
+
/** Remove one `/Names /Pages` registration; the page stays. */
|
|
2003
|
+
removeName(input, signal) {
|
|
2004
|
+
throwIfAborted(signal);
|
|
2005
|
+
if (input.name.length === 0) throw new EngineError(EngineErrorCode.InvalidArg, "pages.removeName requires a non-empty name");
|
|
2006
|
+
const { fn, mem } = this.runtime;
|
|
2007
|
+
const docPtr = this.session.requireDocPtr();
|
|
2008
|
+
if (!writeUtf16String(mem, input.name, (ptr) => fn.EPDFDoc_RemoveNamedPage(docPtr, ptr))) throw new EngineError(EngineErrorCode.NotFound, `pages.removeName: no /Names /Pages registration '${input.name}'`);
|
|
2009
|
+
return {
|
|
2010
|
+
layout: new PagesReader(this.runtime, this.session).read(signal),
|
|
2011
|
+
cache: null
|
|
2012
|
+
};
|
|
2013
|
+
}
|
|
1946
2014
|
/** Shared input check: non-empty, no duplicate PONs. */
|
|
1947
2015
|
requireUniquePons(op, pageObjectNumbers) {
|
|
1948
2016
|
if (pageObjectNumbers.length === 0) throw new EngineError(EngineErrorCode.InvalidArg, `${op} requires at least one page`);
|
|
@@ -1955,7 +2023,7 @@ var PagesMutator = class {
|
|
|
1955
2023
|
};
|
|
1956
2024
|
//#endregion
|
|
1957
2025
|
//#region src/features/pages/PagesExtractor.ts
|
|
1958
|
-
const FPDF_NO_INCREMENTAL$
|
|
2026
|
+
const FPDF_NO_INCREMENTAL$2 = 2;
|
|
1959
2027
|
/**
|
|
1960
2028
|
* Export a subset of pages as a standalone PDF. A READ over the session:
|
|
1961
2029
|
* `FPDF_ImportPagesByIndex` copies pages into a scratch document, so the
|
|
@@ -1994,7 +2062,7 @@ var PagesExtractor = class {
|
|
|
1994
2062
|
for (let i = 0; i < indices.length; i++) mem.poke(idxPtr, "i32", indices[i], 4 * i);
|
|
1995
2063
|
if (!fn.FPDF_ImportPagesByIndex(destPtr, srcPtr, idxPtr, indices.length, 0)) throw new EngineError(EngineErrorCode.Unknown, `FPDF_ImportPagesByIndex rejected the request (indices=[${indices.join(",")}])`);
|
|
1996
2064
|
mem.poke(sizePtr, "i32", 0);
|
|
1997
|
-
pdfPtr = fn.EPDF_SaveDocumentToOwnedBuffer(destPtr, FPDF_NO_INCREMENTAL$
|
|
2065
|
+
pdfPtr = fn.EPDF_SaveDocumentToOwnedBuffer(destPtr, FPDF_NO_INCREMENTAL$2, sizePtr);
|
|
1998
2066
|
const size = Number(mem.peek(sizePtr, "i32"));
|
|
1999
2067
|
if (!pdfPtr || size <= 0) throw new EngineError(EngineErrorCode.DocOpenFailed, "failed to save extracted pages");
|
|
2000
2068
|
const bytes = mem.readBytes(pdfPtr, size);
|
|
@@ -2546,6 +2614,13 @@ function readQuadPoints(fn, mem, annotPtr) {
|
|
|
2546
2614
|
return out;
|
|
2547
2615
|
});
|
|
2548
2616
|
}
|
|
2617
|
+
/**
|
|
2618
|
+
* `/Name` as text, whatever its value (`EPDFAnnot_GetName`): a standard
|
|
2619
|
+
* icon/stamp name or a custom identifier. `null` when absent.
|
|
2620
|
+
*/
|
|
2621
|
+
function readAnnotName(fn, mem, annotPtr) {
|
|
2622
|
+
return readUtf8String(mem, (buf, capacity) => fn.EPDFAnnot_GetName(annotPtr, buf, capacity));
|
|
2623
|
+
}
|
|
2549
2624
|
//#endregion
|
|
2550
2625
|
//#region src/features/annotations/internal/read/readAnnotationTransformMetadata.ts
|
|
2551
2626
|
/**
|
|
@@ -2795,29 +2870,29 @@ function normalizeChecksum(raw) {
|
|
|
2795
2870
|
//#endregion
|
|
2796
2871
|
//#region src/features/annotations/internal/annotationIcon.ts
|
|
2797
2872
|
/**
|
|
2798
|
-
* `/Name` icon ↔
|
|
2799
|
-
*
|
|
2800
|
-
*
|
|
2801
|
-
*
|
|
2802
|
-
*
|
|
2803
|
-
*/
|
|
2804
|
-
const
|
|
2805
|
-
comment:
|
|
2806
|
-
key:
|
|
2807
|
-
note:
|
|
2808
|
-
help:
|
|
2809
|
-
"new-paragraph":
|
|
2810
|
-
paragraph:
|
|
2811
|
-
insert:
|
|
2873
|
+
* `/Name` icon vocabulary ↔ PDF name mapping for text and file-attachment
|
|
2874
|
+
* annotations (ISO 32000-2 tables 175 and 184). The wire speaks the
|
|
2875
|
+
* kebab-case ids; `EPDFAnnot_SetName` / `EPDFAnnot_GetName` speak the PDF
|
|
2876
|
+
* names. An unknown PDF name reads as the subtype's default (the reader
|
|
2877
|
+
* draws the default glyph for names it does not know — spec behavior).
|
|
2878
|
+
*/
|
|
2879
|
+
const NOTE_ICON_TO_NAME = Object.freeze({
|
|
2880
|
+
comment: "Comment",
|
|
2881
|
+
key: "Key",
|
|
2882
|
+
note: "Note",
|
|
2883
|
+
help: "Help",
|
|
2884
|
+
"new-paragraph": "NewParagraph",
|
|
2885
|
+
paragraph: "Paragraph",
|
|
2886
|
+
insert: "Insert"
|
|
2812
2887
|
});
|
|
2813
|
-
const
|
|
2814
|
-
const
|
|
2815
|
-
graph:
|
|
2816
|
-
"push-pin":
|
|
2817
|
-
paperclip:
|
|
2818
|
-
tag:
|
|
2888
|
+
const NOTE_NAME_TO_ICON = Object.freeze(Object.fromEntries(Object.entries(NOTE_ICON_TO_NAME).map(([icon, name]) => [name, icon])));
|
|
2889
|
+
const FILE_ICON_TO_NAME = Object.freeze({
|
|
2890
|
+
graph: "Graph",
|
|
2891
|
+
"push-pin": "PushPin",
|
|
2892
|
+
paperclip: "Paperclip",
|
|
2893
|
+
tag: "Tag"
|
|
2819
2894
|
});
|
|
2820
|
-
const
|
|
2895
|
+
const FILE_NAME_TO_ICON = Object.freeze(Object.fromEntries(Object.entries(FILE_ICON_TO_NAME).map(([icon, name]) => [name, icon])));
|
|
2821
2896
|
//#endregion
|
|
2822
2897
|
//#region src/features/annotations/internal/read/readFileAttachmentAnnotation.ts
|
|
2823
2898
|
/** Default `/C` — matches the generator's default icon fill and the writer default. */
|
|
@@ -2839,7 +2914,7 @@ function readFileAttachment(fn, mem, annotPtr, base) {
|
|
|
2839
2914
|
const color = readAnnotColor(fn, mem, annotPtr) ?? { ...DEFAULT_FILE_ATTACHMENT_COLOR$1 };
|
|
2840
2915
|
const ca = readAnnotOpacity(fn, mem, annotPtr);
|
|
2841
2916
|
const opacity = ca == null ? 1 : Math.max(0, Math.min(1, ca));
|
|
2842
|
-
const icon =
|
|
2917
|
+
const icon = FILE_NAME_TO_ICON[readAnnotName(fn, mem, annotPtr) ?? ""] ?? DEFAULT_FILE_ATTACHMENT_ICON;
|
|
2843
2918
|
const attachmentPtr = fn.FPDFAnnot_GetFileAttachment(annotPtr);
|
|
2844
2919
|
const file = attachmentPtr ? readAttachmentFileInfo(fn, mem, attachmentPtr) : { name: "" };
|
|
2845
2920
|
return {
|
|
@@ -3308,45 +3383,10 @@ function readSquare(fn, mem, annotPtr, base) {
|
|
|
3308
3383
|
};
|
|
3309
3384
|
}
|
|
3310
3385
|
//#endregion
|
|
3311
|
-
//#region src/features/annotations/internal/stampName.ts
|
|
3312
|
-
/**
|
|
3313
|
-
* Stamp `/Name` label ↔ `FPDF_ANNOT_NAME` enum code mapping for the
|
|
3314
|
-
* `EPDFAnnot_SetName` / `EPDFAnnot_GetName` fork helpers. Labels are the
|
|
3315
|
-
* PDF spec / Adobe literal name values (ISO 32000 §12.5.6.12 table 181
|
|
3316
|
-
* plus the Adobe SB/SH extended set the fork supports). Codes mirror the
|
|
3317
|
-
* `FPDF_ANNOT_NAME` enum in `public/fpdf_annot.h` — same pattern as
|
|
3318
|
-
* `lineEnding.ts` keeping engine-core PDFium-free.
|
|
3319
|
-
*/
|
|
3320
|
-
const STAMP_NAME_TO_CODE = Object.freeze({
|
|
3321
|
-
Approved: 13,
|
|
3322
|
-
Experimental: 14,
|
|
3323
|
-
NotApproved: 15,
|
|
3324
|
-
AsIs: 16,
|
|
3325
|
-
Expired: 17,
|
|
3326
|
-
NotForPublicRelease: 18,
|
|
3327
|
-
Confidential: 19,
|
|
3328
|
-
Final: 20,
|
|
3329
|
-
Sold: 21,
|
|
3330
|
-
Departmental: 22,
|
|
3331
|
-
ForComment: 23,
|
|
3332
|
-
TopSecret: 24,
|
|
3333
|
-
Draft: 25,
|
|
3334
|
-
ForPublicRelease: 26,
|
|
3335
|
-
Completed: 27,
|
|
3336
|
-
Void: 28,
|
|
3337
|
-
PreliminaryResults: 29,
|
|
3338
|
-
InformationOnly: 30,
|
|
3339
|
-
Rejected: 31,
|
|
3340
|
-
Witness: 32,
|
|
3341
|
-
InitialHere: 33,
|
|
3342
|
-
SignHere: 34,
|
|
3343
|
-
Accepted: 35
|
|
3344
|
-
});
|
|
3345
|
-
const STAMP_CODE_TO_NAME = Object.freeze(Object.fromEntries(Object.entries(STAMP_NAME_TO_CODE).map(([name, code]) => [code, name])));
|
|
3346
|
-
//#endregion
|
|
3347
3386
|
//#region src/features/annotations/internal/read/readStampAnnotation.ts
|
|
3348
3387
|
/**
|
|
3349
|
-
* Stamp DTO: base + `/Name`
|
|
3388
|
+
* Stamp DTO: base + `/Name` (standard or custom identifier, verbatim) +
|
|
3389
|
+
* transform metadata. The visual content
|
|
3350
3390
|
* stays in the `/AP` stream — rendered via `renderAppearanceImages()`,
|
|
3351
3391
|
* never surfaced as DTO data.
|
|
3352
3392
|
*/
|
|
@@ -3356,16 +3396,11 @@ function readStamp(fn, mem, annotPtr, base) {
|
|
|
3356
3396
|
return {
|
|
3357
3397
|
...base,
|
|
3358
3398
|
subtype: "stamp",
|
|
3359
|
-
name:
|
|
3399
|
+
name: readAnnotName(fn, mem, annotPtr),
|
|
3360
3400
|
...rotation != null ? { rotation } : {},
|
|
3361
3401
|
...unrotatedRect != null ? { unrotatedRect } : {}
|
|
3362
3402
|
};
|
|
3363
3403
|
}
|
|
3364
|
-
function readStampName(fn, mem, annotPtr) {
|
|
3365
|
-
const known = STAMP_CODE_TO_NAME[fn.EPDFAnnot_GetName(annotPtr)];
|
|
3366
|
-
if (known !== void 0) return known;
|
|
3367
|
-
return readAnnotString(fn, mem, annotPtr, "Name");
|
|
3368
|
-
}
|
|
3369
3404
|
//#endregion
|
|
3370
3405
|
//#region src/features/annotations/internal/annotationState.ts
|
|
3371
3406
|
/**
|
|
@@ -3421,7 +3456,7 @@ function readText(fn, mem, annotPtr, base) {
|
|
|
3421
3456
|
const color = readAnnotColor(fn, mem, annotPtr) ?? { ...DEFAULT_NOTE_COLOR$1 };
|
|
3422
3457
|
const ca = readAnnotOpacity(fn, mem, annotPtr);
|
|
3423
3458
|
const opacity = ca == null ? 1 : Math.max(0, Math.min(1, ca));
|
|
3424
|
-
const icon =
|
|
3459
|
+
const icon = NOTE_NAME_TO_ICON[readAnnotName(fn, mem, annotPtr) ?? ""] ?? DEFAULT_NOTE_ICON;
|
|
3425
3460
|
const stateRaw = readAnnotString(fn, mem, annotPtr, "State");
|
|
3426
3461
|
const stateModelRaw = readAnnotString(fn, mem, annotPtr, "StateModel");
|
|
3427
3462
|
return {
|
|
@@ -5443,7 +5478,7 @@ function isFileAttachmentSubtype(subtype) {
|
|
|
5443
5478
|
return subtype === "file-attachment";
|
|
5444
5479
|
}
|
|
5445
5480
|
function setFileAttachmentIcon(fn, annotPtr, icon) {
|
|
5446
|
-
if (!fn.EPDFAnnot_SetName(annotPtr,
|
|
5481
|
+
if (!fn.EPDFAnnot_SetName(annotPtr, FILE_ICON_TO_NAME[icon])) throw new EngineError(EngineErrorCode.Unknown, "EPDFAnnot_SetName returned false");
|
|
5447
5482
|
}
|
|
5448
5483
|
function requireFileResource(file, ctx) {
|
|
5449
5484
|
const resource = ctx?.resources?.[file.resource];
|
|
@@ -6105,12 +6140,12 @@ const STAMP_FIT_TO_CODE = {
|
|
|
6105
6140
|
* creating an annotation or strengthening a weak annotation id.
|
|
6106
6141
|
*/
|
|
6107
6142
|
function preflightStampDraft(draft, ctx) {
|
|
6108
|
-
if (draft.name !== void 0)
|
|
6143
|
+
if (draft.name !== void 0) requireStampName(draft.name);
|
|
6109
6144
|
requireStampFit(draft.fit ?? "contain");
|
|
6110
6145
|
requireStampContent(draft.source, ctx);
|
|
6111
6146
|
}
|
|
6112
6147
|
function preflightStampPatch(patch, ctx) {
|
|
6113
|
-
if (patch.name !== void 0)
|
|
6148
|
+
if (patch.name !== void 0 && patch.name !== null) requireStampName(patch.name);
|
|
6114
6149
|
requireStampFit(patch.fit ?? "contain");
|
|
6115
6150
|
if (patch.source !== void 0) requireStampContent(patch.source, ctx);
|
|
6116
6151
|
}
|
|
@@ -6136,7 +6171,8 @@ function applyStampDraft(fn, mem, annotPtr, draft, ctx) {
|
|
|
6136
6171
|
}
|
|
6137
6172
|
function applyStampPatch(fn, mem, annotPtr, patch, ctx) {
|
|
6138
6173
|
applyAnnotationBasePatch(fn, mem, annotPtr, patch);
|
|
6139
|
-
if (patch.name
|
|
6174
|
+
if (patch.name === null) fn.EPDFAnnot_RemoveKey(annotPtr, "Name");
|
|
6175
|
+
else if (patch.name !== void 0) setStampName(fn, annotPtr, patch.name);
|
|
6140
6176
|
if (patch.source !== void 0) {
|
|
6141
6177
|
const rect = patch.rect ?? readAnnotRect(fn, mem, annotPtr);
|
|
6142
6178
|
authorStampAppearance(fn, mem, annotPtr, patch.source, patch.fit ?? "contain", {
|
|
@@ -6156,15 +6192,14 @@ function applyStampPatch(fn, mem, annotPtr, patch, ctx) {
|
|
|
6156
6192
|
function isStampSubtype(subtype) {
|
|
6157
6193
|
return subtype === "stamp";
|
|
6158
6194
|
}
|
|
6195
|
+
/** Any non-empty name: standard ('Approved') or custom ('#LBGiYhk8V…') —
|
|
6196
|
+
* the fork writes a name object and escapes it; predefined sets are a
|
|
6197
|
+
* reader concern (ISO 32000-2 table 187 allows additional names). */
|
|
6159
6198
|
function setStampName(fn, annotPtr, name) {
|
|
6160
|
-
|
|
6161
|
-
if (code === void 0) throw new EngineError(EngineErrorCode.Unknown, "stamp name preflight invariant broken");
|
|
6162
|
-
if (!fn.EPDFAnnot_SetName(annotPtr, code)) throw new EngineError(EngineErrorCode.Unknown, "EPDFAnnot_SetName returned false");
|
|
6199
|
+
if (!fn.EPDFAnnot_SetName(annotPtr, name)) throw new EngineError(EngineErrorCode.Unknown, "EPDFAnnot_SetName returned false");
|
|
6163
6200
|
}
|
|
6164
|
-
function
|
|
6165
|
-
|
|
6166
|
-
if (code === void 0) throw new EngineError(EngineErrorCode.InvalidArg, `unknown stamp name '${name}'; supported names: ${Object.keys(STAMP_NAME_TO_CODE).join(", ")}`);
|
|
6167
|
-
return code;
|
|
6201
|
+
function requireStampName(name) {
|
|
6202
|
+
if (name.length === 0) throw new EngineError(EngineErrorCode.InvalidArg, "stamp name must be non-empty");
|
|
6168
6203
|
}
|
|
6169
6204
|
function requireStampFit(fit) {
|
|
6170
6205
|
if (STAMP_FIT_TO_CODE[fit] === void 0) throw new EngineError(EngineErrorCode.InvalidArg, `unknown stamp fit '${String(fit)}'; expected contain, cover, or fill`);
|
|
@@ -6352,7 +6387,7 @@ function isTextSubtype(subtype) {
|
|
|
6352
6387
|
return subtype === "text";
|
|
6353
6388
|
}
|
|
6354
6389
|
function setNoteIcon(fn, annotPtr, icon) {
|
|
6355
|
-
if (!fn.EPDFAnnot_SetName(annotPtr,
|
|
6390
|
+
if (!fn.EPDFAnnot_SetName(annotPtr, NOTE_ICON_TO_NAME[icon])) throw new EngineError(EngineErrorCode.Unknown, "EPDFAnnot_SetName returned false");
|
|
6356
6391
|
}
|
|
6357
6392
|
//#endregion
|
|
6358
6393
|
//#region src/features/annotations/internal/write/writeVertexAnnotation.ts
|
|
@@ -7079,6 +7114,141 @@ var AnnotationMutator = class {
|
|
|
7079
7114
|
}
|
|
7080
7115
|
};
|
|
7081
7116
|
//#endregion
|
|
7117
|
+
//#region src/features/annotations/AnnotationFlattener.ts
|
|
7118
|
+
const FLATTEN_FAIL$1 = 0;
|
|
7119
|
+
const FLATTEN_SUCCESS$1 = 1;
|
|
7120
|
+
const FLATTEN_NOTHING_TO_DO$1 = 2;
|
|
7121
|
+
const STATUS_APPLIED = 0;
|
|
7122
|
+
const STATUS_NOT_ON_PAGE = 2;
|
|
7123
|
+
const FPDF_NO_INCREMENTAL$1 = 2;
|
|
7124
|
+
/**
|
|
7125
|
+
* The annotation-plane flatten verbs — `pages.flatten` for a chosen set:
|
|
7126
|
+
* in place (`flatten`) or into a new single-page document
|
|
7127
|
+
* (`exportAppearance`). Both resolve refs to native handles on the page,
|
|
7128
|
+
* hand the SET to the fork (one candidate plan, one placement writer — the
|
|
7129
|
+
* same code whole-page flatten runs), and release every handle afterwards.
|
|
7130
|
+
*/
|
|
7131
|
+
var AnnotationFlattener = class {
|
|
7132
|
+
constructor(runtime, session) {
|
|
7133
|
+
this.runtime = runtime;
|
|
7134
|
+
this.session = session;
|
|
7135
|
+
}
|
|
7136
|
+
flatten(pageObjectNumber, refs, usage, signal) {
|
|
7137
|
+
throwIfAborted(signal);
|
|
7138
|
+
this.requireRefs("annotations.flatten", pageObjectNumber, refs);
|
|
7139
|
+
const { fn, mem } = this.runtime;
|
|
7140
|
+
const pool = this.session.pagePool();
|
|
7141
|
+
const pagePtr = pool.acquire(pageObjectNumber);
|
|
7142
|
+
try {
|
|
7143
|
+
const annotPtrs = this.resolveAll(pagePtr, refs);
|
|
7144
|
+
let code;
|
|
7145
|
+
let statuses;
|
|
7146
|
+
try {
|
|
7147
|
+
[code, statuses] = this.withHandleArray(annotPtrs, (arrayPtr) => withScratch(mem, 4 * refs.length, (statusPtr) => {
|
|
7148
|
+
const rc = fn.EPDFPage_FlattenAnnotations(pagePtr, arrayPtr, refs.length, usage === "print" ? 1 : 0, statusPtr);
|
|
7149
|
+
const out = [];
|
|
7150
|
+
for (let i = 0; i < refs.length; i++) out.push(Number(mem.peek(statusPtr, "i32", 4 * i)));
|
|
7151
|
+
return [rc, out];
|
|
7152
|
+
}));
|
|
7153
|
+
} finally {
|
|
7154
|
+
for (const annotPtr of annotPtrs) fn.FPDFPage_CloseAnnot(annotPtr);
|
|
7155
|
+
}
|
|
7156
|
+
if (code === FLATTEN_FAIL$1) {
|
|
7157
|
+
const foreign = statuses.findIndex((status) => status === STATUS_NOT_ON_PAGE);
|
|
7158
|
+
throw new EngineError(foreign >= 0 ? EngineErrorCode.InvalidArg : EngineErrorCode.Unknown, foreign >= 0 ? `annotations.flatten: ref ${foreign} is not an annotation of page ${pageObjectNumber}` : "native annotation flatten failed after preflight");
|
|
7159
|
+
}
|
|
7160
|
+
const results = refs.map((ref, i) => ({
|
|
7161
|
+
ref,
|
|
7162
|
+
status: statuses[i] === STATUS_APPLIED ? "applied" : "skipped"
|
|
7163
|
+
}));
|
|
7164
|
+
if (code === FLATTEN_NOTHING_TO_DO$1 || code !== FLATTEN_SUCCESS$1) return {
|
|
7165
|
+
pageObjectNumber,
|
|
7166
|
+
usage,
|
|
7167
|
+
results,
|
|
7168
|
+
meta: null
|
|
7169
|
+
};
|
|
7170
|
+
this.session.noteMutation();
|
|
7171
|
+
this.session.bumpRevision(pageObjectNumber);
|
|
7172
|
+
try {
|
|
7173
|
+
new AnnotationReader(this.runtime, this.session).list(pageObjectNumber, signal);
|
|
7174
|
+
} catch {}
|
|
7175
|
+
return {
|
|
7176
|
+
pageObjectNumber,
|
|
7177
|
+
usage,
|
|
7178
|
+
results,
|
|
7179
|
+
meta: {
|
|
7180
|
+
affectedPages: [this.session.pageState(pageObjectNumber)],
|
|
7181
|
+
cacheDelta: null
|
|
7182
|
+
}
|
|
7183
|
+
};
|
|
7184
|
+
} finally {
|
|
7185
|
+
pool.release(pageObjectNumber);
|
|
7186
|
+
}
|
|
7187
|
+
}
|
|
7188
|
+
exportAppearance(pageObjectNumber, refs, signal) {
|
|
7189
|
+
throwIfAborted(signal);
|
|
7190
|
+
this.requireRefs("annotations.exportAppearance", pageObjectNumber, refs);
|
|
7191
|
+
const { fn, mem } = this.runtime;
|
|
7192
|
+
const pool = this.session.pagePool();
|
|
7193
|
+
const pagePtr = pool.acquire(pageObjectNumber);
|
|
7194
|
+
let exportedPtr = null;
|
|
7195
|
+
let pdfPtr = null;
|
|
7196
|
+
try {
|
|
7197
|
+
const annotPtrs = this.resolveAll(pagePtr, refs);
|
|
7198
|
+
try {
|
|
7199
|
+
exportedPtr = this.withHandleArray(annotPtrs, (arrayPtr) => fn.EPDFPage_ExportAnnotationsAsDocument(pagePtr, arrayPtr, refs.length));
|
|
7200
|
+
} finally {
|
|
7201
|
+
for (const annotPtr of annotPtrs) fn.FPDFPage_CloseAnnot(annotPtr);
|
|
7202
|
+
}
|
|
7203
|
+
if (!exportedPtr) throw new EngineError(EngineErrorCode.InvalidArg, "annotations.exportAppearance: every ref must be a visible annotation of this page with a normal appearance");
|
|
7204
|
+
return withScratch(mem, 4, (sizePtr) => {
|
|
7205
|
+
mem.poke(sizePtr, "i32", 0);
|
|
7206
|
+
pdfPtr = fn.EPDF_SaveDocumentToOwnedBuffer(exportedPtr, FPDF_NO_INCREMENTAL$1, sizePtr);
|
|
7207
|
+
const size = Number(mem.peek(sizePtr, "i32"));
|
|
7208
|
+
if (!pdfPtr || size <= 0) throw new EngineError(EngineErrorCode.DocOpenFailed, "failed to save exported appearances");
|
|
7209
|
+
const bytes = mem.readBytes(pdfPtr, size);
|
|
7210
|
+
const buffer = new ArrayBuffer(bytes.byteLength);
|
|
7211
|
+
new Uint8Array(buffer).set(bytes);
|
|
7212
|
+
return {
|
|
7213
|
+
bytes: buffer,
|
|
7214
|
+
size
|
|
7215
|
+
};
|
|
7216
|
+
});
|
|
7217
|
+
} finally {
|
|
7218
|
+
if (pdfPtr) fn.EPDF_FreeBuffer(pdfPtr);
|
|
7219
|
+
if (exportedPtr) fn.FPDF_CloseDocument(exportedPtr);
|
|
7220
|
+
pool.release(pageObjectNumber);
|
|
7221
|
+
}
|
|
7222
|
+
}
|
|
7223
|
+
/** Resolve every ref on `pagePtr` (NotFound / InvalidReference from the
|
|
7224
|
+
* resolver on caller error); on any failure, close what was opened. */
|
|
7225
|
+
resolveAll(pagePtr, refs) {
|
|
7226
|
+
const { fn } = this.runtime;
|
|
7227
|
+
const annotPtrs = [];
|
|
7228
|
+
try {
|
|
7229
|
+
for (const ref of refs) annotPtrs.push(resolveAnnotPtr(this.runtime, this.session, pagePtr, ref));
|
|
7230
|
+
return annotPtrs;
|
|
7231
|
+
} catch (error) {
|
|
7232
|
+
for (const annotPtr of annotPtrs) fn.FPDFPage_CloseAnnot(annotPtr);
|
|
7233
|
+
throw error;
|
|
7234
|
+
}
|
|
7235
|
+
}
|
|
7236
|
+
/** Marshal an `FPDF_ANNOTATION*` array for the call's duration. */
|
|
7237
|
+
withHandleArray(annotPtrs, body) {
|
|
7238
|
+
const { mem } = this.runtime;
|
|
7239
|
+
const isWasm = this.runtime.kind === "wasm";
|
|
7240
|
+
const ptrSize = isWasm ? 4 : 8;
|
|
7241
|
+
return withScratch(mem, Math.max(1, annotPtrs.length * ptrSize), (arrayPtr) => {
|
|
7242
|
+
annotPtrs.forEach((ptr, i) => isWasm ? mem.poke(arrayPtr, "i32", Number(ptr), i * 4) : mem.poke(arrayPtr, "i64", ptr, i * 8));
|
|
7243
|
+
return body(arrayPtr);
|
|
7244
|
+
});
|
|
7245
|
+
}
|
|
7246
|
+
requireRefs(op, pageObjectNumber, refs) {
|
|
7247
|
+
if (refs.length === 0) throw new EngineError(EngineErrorCode.InvalidArg, `${op} requires at least one ref`);
|
|
7248
|
+
for (const ref of refs) if (ref.pageObjectNumber !== pageObjectNumber) throw new EngineError(EngineErrorCode.InvalidArg, `${op} refs must all target page ${pageObjectNumber}; got ref on page ${ref.pageObjectNumber}`);
|
|
7249
|
+
}
|
|
7250
|
+
};
|
|
7251
|
+
//#endregion
|
|
7082
7252
|
//#region src/features/pages/PagesFlattener.ts
|
|
7083
7253
|
const FLATTEN_FAIL = 0;
|
|
7084
7254
|
const FLATTEN_SUCCESS = 1;
|
|
@@ -9685,6 +9855,18 @@ var WorkerHost = class {
|
|
|
9685
9855
|
case "pages.delete":
|
|
9686
9856
|
resultPack = this.handlePagesDelete(msg, ctrl.signal);
|
|
9687
9857
|
break;
|
|
9858
|
+
case "pages.setName":
|
|
9859
|
+
resultPack = this.handlePagesSetName(msg, ctrl.signal);
|
|
9860
|
+
break;
|
|
9861
|
+
case "annotations.flatten":
|
|
9862
|
+
resultPack = this.handleAnnotationsFlatten(msg, ctrl.signal);
|
|
9863
|
+
break;
|
|
9864
|
+
case "annotations.exportAppearance":
|
|
9865
|
+
resultPack = this.handleAnnotationsExportAppearance(msg, ctrl.signal);
|
|
9866
|
+
break;
|
|
9867
|
+
case "pages.removeName":
|
|
9868
|
+
resultPack = this.handlePagesRemoveName(msg, ctrl.signal);
|
|
9869
|
+
break;
|
|
9688
9870
|
case "pages.flatten":
|
|
9689
9871
|
resultPack = this.handlePagesFlatten(msg, ctrl.signal);
|
|
9690
9872
|
break;
|
|
@@ -9912,6 +10094,27 @@ var WorkerHost = class {
|
|
|
9912
10094
|
result
|
|
9913
10095
|
}, req.artifactPath);
|
|
9914
10096
|
}
|
|
10097
|
+
handleAnnotationsFlatten(req, signal) {
|
|
10098
|
+
const session = this.requireSession(req);
|
|
10099
|
+
const result = new AnnotationFlattener(this.runtime, session).flatten(req.pageObjectNumber, req.refs, req.usage, signal);
|
|
10100
|
+
if (result.meta === null) return wirePack({
|
|
10101
|
+
tag: "annotations.flatten",
|
|
10102
|
+
result
|
|
10103
|
+
});
|
|
10104
|
+
return this.finishMutation(session, {
|
|
10105
|
+
tag: "annotations.flatten",
|
|
10106
|
+
result
|
|
10107
|
+
}, req.artifactPath);
|
|
10108
|
+
}
|
|
10109
|
+
handleAnnotationsExportAppearance(req, signal) {
|
|
10110
|
+
const session = this.requireSession(req);
|
|
10111
|
+
const exported = new AnnotationFlattener(this.runtime, session).exportAppearance(req.pageObjectNumber, req.refs, signal);
|
|
10112
|
+
return wirePack({
|
|
10113
|
+
tag: "annotations.exportAppearance",
|
|
10114
|
+
bytes: exported.bytes,
|
|
10115
|
+
size: exported.size
|
|
10116
|
+
}, [exported.bytes]);
|
|
10117
|
+
}
|
|
9915
10118
|
handleAnnotationsMove(req, signal) {
|
|
9916
10119
|
const session = this.requireSession(req);
|
|
9917
10120
|
const result = new AnnotationMutator(this.runtime, session).move(req.pageObjectNumber, req.refs, req.toIndex, signal);
|
|
@@ -9951,6 +10154,26 @@ var WorkerHost = class {
|
|
|
9951
10154
|
result
|
|
9952
10155
|
}, req.artifactPath);
|
|
9953
10156
|
}
|
|
10157
|
+
handlePagesSetName(req, signal) {
|
|
10158
|
+
const session = this.requireSession(req);
|
|
10159
|
+
const result = new PagesMutator(this.runtime, session).setName({
|
|
10160
|
+
name: req.name,
|
|
10161
|
+
pageObjectNumber: req.pageObjectNumber,
|
|
10162
|
+
...req.replace !== void 0 ? { replace: req.replace } : {}
|
|
10163
|
+
}, signal);
|
|
10164
|
+
return this.finishMutation(session, {
|
|
10165
|
+
tag: "pages.setName",
|
|
10166
|
+
result
|
|
10167
|
+
}, req.artifactPath);
|
|
10168
|
+
}
|
|
10169
|
+
handlePagesRemoveName(req, signal) {
|
|
10170
|
+
const session = this.requireSession(req);
|
|
10171
|
+
const result = new PagesMutator(this.runtime, session).removeName({ name: req.name }, signal);
|
|
10172
|
+
return this.finishMutation(session, {
|
|
10173
|
+
tag: "pages.removeName",
|
|
10174
|
+
result
|
|
10175
|
+
}, req.artifactPath);
|
|
10176
|
+
}
|
|
9954
10177
|
handlePagesFlatten(req, signal) {
|
|
9955
10178
|
const session = this.requireSession(req);
|
|
9956
10179
|
const result = new PagesFlattener(this.runtime, session).flatten(req.pageObjectNumbers, req.usage, signal);
|
|
@@ -10525,6 +10748,6 @@ function passwordRequiredProbe() {
|
|
|
10525
10748
|
};
|
|
10526
10749
|
}
|
|
10527
10750
|
//#endregion
|
|
10528
|
-
export { ALL_STANDARD_SECURITY_PERMISSIONS, ActionReadBudgetTracker, AnnotationAppearanceReader, AnnotationMutator, AnnotationReader, AttachmentMutator, AttachmentReader, BaseDocumentRegistry, CloseStack, DocumentActionsReader, PagesMutator as DocumentPagesMutator, PagesMutator, DocumentSaver, DocumentSession, EPDF_CHAR_GEOMETRY_LAYOUT, EventHub, FontRegistrar, FormMutator, FormReader, FormsEffectsApplier, LocalRevisionAuthority, MetadataMutator, MetadataReader, PageGeometryReader, PagesReader as PageLayoutReader, PagesReader, PagePtrPool, PageRenderReader as PageRasterReader, PageRenderReader, PageTextReader, PagesExtractor, PagesFlattener, PagesInserter, RawAnnotationReader, RedactionApplier, SearchReader, SecurityReader, SessionEventPublisher, WorkerHost, buildRunsFromRawGlyphs, computeMutationImpact, destroyLibrary, disposeFormModel, ensureInitialized, formatPdfDate, generateUuid, hasAllStandardSecurityPermissions, normalizeU32, openFatMemoryDocument, openLayerDocument, pdfDateToIso, readActionModel, readAttachmentFileInfo, throwIfAborted, writeAttachmentFilePayload };
|
|
10751
|
+
export { ALL_STANDARD_SECURITY_PERMISSIONS, ActionReadBudgetTracker, AnnotationAppearanceReader, AnnotationFlattener, AnnotationMutator, AnnotationReader, AttachmentMutator, AttachmentReader, BaseDocumentRegistry, CloseStack, DocumentActionsReader, PagesMutator as DocumentPagesMutator, PagesMutator, DocumentSaver, DocumentSession, EPDF_CHAR_GEOMETRY_LAYOUT, EventHub, FontRegistrar, FormMutator, FormReader, FormsEffectsApplier, LocalRevisionAuthority, MetadataMutator, MetadataReader, PageGeometryReader, PagesReader as PageLayoutReader, PagesReader, PagePtrPool, PageRenderReader as PageRasterReader, PageRenderReader, PageTextReader, PagesExtractor, PagesFlattener, PagesInserter, RawAnnotationReader, RedactionApplier, SearchReader, SecurityReader, SessionEventPublisher, WorkerHost, buildRunsFromRawGlyphs, computeMutationImpact, destroyLibrary, disposeFormModel, ensureInitialized, formatPdfDate, generateUuid, hasAllStandardSecurityPermissions, normalizeU32, openFatMemoryDocument, openLayerDocument, pdfDateToIso, readActionModel, readAttachmentFileInfo, throwIfAborted, writeAttachmentFilePayload };
|
|
10529
10752
|
|
|
10530
10753
|
//# sourceMappingURL=index.js.map
|