@embedpdf/engine-core 3.0.0-next.14 → 3.0.0-next.16
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/AnnotationList-DcyhF2kU.d.cts +27691 -0
- package/dist/AnnotationList-DcyhF2kU.d.ts +27691 -0
- package/dist/Change-Ct-dB8D5.cjs +1133 -0
- package/dist/Change-Ct-dB8D5.cjs.map +1 -0
- package/dist/Change-tMR34hTU.js +978 -0
- package/dist/Change-tMR34hTU.js.map +1 -0
- package/dist/DocumentRenderService-9IjSQEIU.cjs +121 -0
- package/dist/DocumentRenderService-9IjSQEIU.cjs.map +1 -0
- package/dist/DocumentRenderService-DFrZ9wfW.js +86 -0
- package/dist/DocumentRenderService-DFrZ9wfW.js.map +1 -0
- package/dist/{DocumentSecurityService-Ca6EK3-3.d.ts → DocumentSecurityService-D2zA4NKi.d.cts} +100 -112
- package/dist/{DocumentSecurityService-CIx1MT0T.d.cts → DocumentSecurityService-YJV9df8P.d.ts} +100 -112
- package/dist/LocalDocumentHandle-D02FMm-Z.cjs +53 -0
- package/dist/LocalDocumentHandle-D02FMm-Z.cjs.map +1 -0
- package/dist/LocalDocumentHandle-DAPdaOt_.js +30 -0
- package/dist/LocalDocumentHandle-DAPdaOt_.js.map +1 -0
- package/dist/LocalEngine-DBt2-GWF.d.ts +1649 -0
- package/dist/LocalEngine-IA9zh3Jh.d.cts +1649 -0
- package/dist/PageInsertBlankInput-CXHAM7l6.cjs +17 -0
- package/dist/PageInsertBlankInput-CXHAM7l6.cjs.map +1 -0
- package/dist/PageInsertBlankInput-DhVYVJ_S.js +12 -0
- package/dist/PageInsertBlankInput-DhVYVJ_S.js.map +1 -0
- package/dist/authority-BFp6XM04.cjs +2997 -0
- package/dist/authority-BFp6XM04.cjs.map +1 -0
- package/dist/authority-PuxpGFhJ.js +2506 -0
- package/dist/authority-PuxpGFhJ.js.map +1 -0
- package/dist/builders-DV62HA3I.js +165 -0
- package/dist/builders-DV62HA3I.js.map +1 -0
- package/dist/builders-DgTAj_tP.cjs +188 -0
- package/dist/builders-DgTAj_tP.cjs.map +1 -0
- package/dist/calibrate-DJbi1wuK.cjs +3012 -0
- package/dist/calibrate-DJbi1wuK.cjs.map +1 -0
- package/dist/calibrate-nQFgCuki.js +2461 -0
- package/dist/calibrate-nQFgCuki.js.map +1 -0
- package/dist/charmap-Cprti1ta.js +239 -0
- package/dist/charmap-Cprti1ta.js.map +1 -0
- package/dist/charmap-aYlefQP9.cjs +304 -0
- package/dist/charmap-aYlefQP9.cjs.map +1 -0
- package/dist/conformance.cjs +18146 -5258
- package/dist/conformance.cjs.map +1 -1
- package/dist/conformance.d.cts +1024 -170
- package/dist/conformance.d.ts +1024 -170
- package/dist/conformance.js +18148 -5309
- package/dist/conformance.js.map +1 -1
- package/dist/format-Bp3QFSH1.cjs +574 -0
- package/dist/format-Bp3QFSH1.cjs.map +1 -0
- package/dist/format-Dgg428Kb.js +461 -0
- package/dist/format-Dgg428Kb.js.map +1 -0
- package/dist/index.cjs +342 -116
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +14 -5
- package/dist/pageRefs-B3ur7Ckm.cjs +51 -0
- package/dist/pageRefs-B3ur7Ckm.cjs.map +1 -0
- package/dist/pageRefs-DkbuxSCV.js +40 -0
- package/dist/pageRefs-DkbuxSCV.js.map +1 -0
- package/dist/public.cjs +59 -0
- package/dist/public.d.cts +5 -0
- package/dist/public.d.ts +5 -0
- package/dist/public.js +9 -0
- package/dist/resolveAnnotationDraft-7Ke4nV7F.cjs +3646 -0
- package/dist/resolveAnnotationDraft-7Ke4nV7F.cjs.map +1 -0
- package/dist/resolveAnnotationDraft-CUpf0SMh.js +3167 -0
- package/dist/resolveAnnotationDraft-CUpf0SMh.js.map +1 -0
- package/dist/{resolver-inAVzsWt.js → resolver-BBggAxQc.js} +298 -145
- package/dist/resolver-BBggAxQc.js.map +1 -0
- package/dist/{resolver-CYVNV4hn.cjs → resolver-BWSWSF6R.cjs} +351 -144
- package/dist/resolver-BWSWSF6R.cjs.map +1 -0
- package/dist/runtime-BaDKjxiu.d.ts +1959 -0
- package/dist/runtime-CWEuiwbk.d.cts +1959 -0
- package/dist/runtime.cjs +986 -297
- package/dist/runtime.cjs.map +1 -1
- package/dist/runtime.d.cts +5 -1372
- package/dist/runtime.d.ts +5 -1372
- package/dist/runtime.js +634 -179
- package/dist/runtime.js.map +1 -1
- package/dist/schema-6S2VmlAj.js +2087 -0
- package/dist/schema-6S2VmlAj.js.map +1 -0
- package/dist/schema-miH6tWQC.cjs +3046 -0
- package/dist/schema-miH6tWQC.cjs.map +1 -0
- package/dist/schemas-BE2QGOit.js +1851 -0
- package/dist/schemas-BE2QGOit.js.map +1 -0
- package/dist/schemas-DljJR9ut.cjs +2798 -0
- package/dist/schemas-DljJR9ut.cjs.map +1 -0
- package/dist/subtype-CG4WpIRj.js +129 -0
- package/dist/subtype-CG4WpIRj.js.map +1 -0
- package/dist/subtype-aDt5TFmK.cjs +158 -0
- package/dist/subtype-aDt5TFmK.cjs.map +1 -0
- package/dist/validation.cjs +578 -0
- package/dist/validation.cjs.map +1 -0
- package/dist/validation.d.cts +174 -0
- package/dist/validation.d.ts +174 -0
- package/dist/validation.js +571 -0
- package/dist/validation.js.map +1 -0
- package/dist/value-BFS1R8ek.cjs +435 -0
- package/dist/value-BFS1R8ek.cjs.map +1 -0
- package/dist/value-Dhc8eYcx.js +340 -0
- package/dist/value-Dhc8eYcx.js.map +1 -0
- package/dist/viewport-CHG9qQUb.cjs +671 -0
- package/dist/viewport-CHG9qQUb.cjs.map +1 -0
- package/dist/viewport-DQR5LyX3.js +540 -0
- package/dist/viewport-DQR5LyX3.js.map +1 -0
- package/dist/wire.cjs +1242 -420
- package/dist/wire.cjs.map +1 -1
- package/dist/wire.d.cts +14840 -830
- package/dist/wire.d.ts +14840 -830
- package/dist/wire.js +985 -261
- package/dist/wire.js.map +1 -1
- package/package.json +10 -1
- package/dist/AbortError-DwuHPK_I.js +0 -27
- package/dist/AbortError-DwuHPK_I.js.map +0 -1
- package/dist/AbortError-P0RU0Mgg.cjs +0 -38
- package/dist/AbortError-P0RU0Mgg.cjs.map +0 -1
- package/dist/AnnotationListSnapshot-D9R5n2Kf.d.cts +0 -7101
- package/dist/AnnotationListSnapshot-D9R5n2Kf.d.ts +0 -7101
- package/dist/Engine-EWWHhEIi.d.ts +0 -1277
- package/dist/Engine-FNaAEjfb.d.cts +0 -1277
- package/dist/derive-BbsDk_Kz.cjs +0 -880
- package/dist/derive-BbsDk_Kz.cjs.map +0 -1
- package/dist/derive-DAFJolWu.js +0 -647
- package/dist/derive-DAFJolWu.js.map +0 -1
- package/dist/format-Bbphf4zR.js +0 -435
- package/dist/format-Bbphf4zR.js.map +0 -1
- package/dist/format-D_epWlob.cjs +0 -518
- package/dist/format-D_epWlob.cjs.map +0 -1
- package/dist/resolver-CYVNV4hn.cjs.map +0 -1
- package/dist/resolver-inAVzsWt.js.map +0 -1
- package/dist/schemas-CFQGvWiu.js +0 -3243
- package/dist/schemas-CFQGvWiu.js.map +0 -1
- package/dist/schemas-D0g6tKa9.cjs +0 -4694
- package/dist/schemas-D0g6tKa9.cjs.map +0 -1
- package/dist/viewport-BWeNHZmb.cjs +0 -3503
- package/dist/viewport-BWeNHZmb.cjs.map +0 -1
- package/dist/viewport-CvMcadfQ.js +0 -3072
- package/dist/viewport-CvMcadfQ.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subtype-aDt5TFmK.cjs","names":[],"sources":["../src/annotation/subtype.ts"],"sourcesContent":["/**\n * Closed-world string catalog of annotation subtypes the wire format knows\n * about. The TypeScript discriminated union `Annotation` is keyed on this\n * literal type. PDFium's integer subtype code is mapped onto these strings\n * by the reader registry.\n *\n * `unsupported` is the forward-compat fallback for any PDF subtype the\n * engine has no reader for. Unknown subtypes never\n * silently disappear from the wire — they round-trip as\n * `{ subtype: 'unsupported', rawSubtypeCode }`.\n */\nexport const ANNOTATION_SUBTYPES = [\n 'text',\n 'link',\n 'free-text',\n 'line',\n 'square',\n 'circle',\n 'polygon',\n 'polyline',\n 'highlight',\n 'underline',\n 'squiggly',\n 'strikeout',\n 'stamp',\n 'caret',\n 'ink',\n 'popup',\n 'file-attachment',\n 'redact',\n 'widget',\n 'unsupported',\n] as const;\n\nexport type AnnotationSubtype = (typeof ANNOTATION_SUBTYPES)[number];\n\n/**\n * PDFium subtype codes from `FPDFAnnot_GetSubtype`. Mirrors\n * `FPDF_ANNOTATION_SUBTYPE` in `public/fpdf_annot.h`. We keep this here\n * (rather than importing from @embedpdf/engine-runtime) so the engine-core\n * package has zero PDFium dependency.\n */\nexport const PdfAnnotationSubtypeCode = {\n UNKNOWN: 0,\n TEXT: 1,\n LINK: 2,\n FREETEXT: 3,\n LINE: 4,\n SQUARE: 5,\n CIRCLE: 6,\n POLYGON: 7,\n POLYLINE: 8,\n HIGHLIGHT: 9,\n UNDERLINE: 10,\n SQUIGGLY: 11,\n STRIKEOUT: 12,\n STAMP: 13,\n CARET: 14,\n INK: 15,\n POPUP: 16,\n FILEATTACHMENT: 17,\n SOUND: 18,\n MOVIE: 19,\n WIDGET: 20,\n SCREEN: 21,\n PRINTERMARK: 22,\n TRAPNET: 23,\n WATERMARK: 24,\n THREED: 25,\n RICHMEDIA: 26,\n XFAWIDGET: 27,\n REDACT: 28,\n} as const;\n\nexport type PdfAnnotationSubtypeCode =\n (typeof PdfAnnotationSubtypeCode)[keyof typeof PdfAnnotationSubtypeCode];\n\n/**\n * Map from PDFium codes to wire-stable string subtypes. A code missing here\n * reads as 'unsupported'.\n */\nexport const PDF_CODE_TO_SUBTYPE: Readonly<Record<number, AnnotationSubtype>> = Object.freeze({\n [PdfAnnotationSubtypeCode.TEXT]: 'text',\n [PdfAnnotationSubtypeCode.LINK]: 'link',\n [PdfAnnotationSubtypeCode.FREETEXT]: 'free-text',\n [PdfAnnotationSubtypeCode.LINE]: 'line',\n [PdfAnnotationSubtypeCode.SQUARE]: 'square',\n [PdfAnnotationSubtypeCode.CIRCLE]: 'circle',\n [PdfAnnotationSubtypeCode.POLYGON]: 'polygon',\n [PdfAnnotationSubtypeCode.POLYLINE]: 'polyline',\n [PdfAnnotationSubtypeCode.HIGHLIGHT]: 'highlight',\n [PdfAnnotationSubtypeCode.UNDERLINE]: 'underline',\n [PdfAnnotationSubtypeCode.SQUIGGLY]: 'squiggly',\n [PdfAnnotationSubtypeCode.STRIKEOUT]: 'strikeout',\n [PdfAnnotationSubtypeCode.STAMP]: 'stamp',\n [PdfAnnotationSubtypeCode.CARET]: 'caret',\n [PdfAnnotationSubtypeCode.INK]: 'ink',\n [PdfAnnotationSubtypeCode.POPUP]: 'popup',\n [PdfAnnotationSubtypeCode.FILEATTACHMENT]: 'file-attachment',\n [PdfAnnotationSubtypeCode.WIDGET]: 'widget',\n [PdfAnnotationSubtypeCode.REDACT]: 'redact',\n});\n\n/**\n * Reverse map for write paths that need to turn a wire subtype back into the\n * PDFium integer code without importing the zod-backed annotation registry.\n */\nexport const PDF_SUBTYPE_TO_CODE: Readonly<Record<AnnotationSubtype, PdfAnnotationSubtypeCode>> =\n Object.freeze({\n text: PdfAnnotationSubtypeCode.TEXT,\n link: PdfAnnotationSubtypeCode.LINK,\n 'free-text': PdfAnnotationSubtypeCode.FREETEXT,\n line: PdfAnnotationSubtypeCode.LINE,\n square: PdfAnnotationSubtypeCode.SQUARE,\n circle: PdfAnnotationSubtypeCode.CIRCLE,\n polygon: PdfAnnotationSubtypeCode.POLYGON,\n polyline: PdfAnnotationSubtypeCode.POLYLINE,\n highlight: PdfAnnotationSubtypeCode.HIGHLIGHT,\n underline: PdfAnnotationSubtypeCode.UNDERLINE,\n squiggly: PdfAnnotationSubtypeCode.SQUIGGLY,\n strikeout: PdfAnnotationSubtypeCode.STRIKEOUT,\n stamp: PdfAnnotationSubtypeCode.STAMP,\n caret: PdfAnnotationSubtypeCode.CARET,\n ink: PdfAnnotationSubtypeCode.INK,\n popup: PdfAnnotationSubtypeCode.POPUP,\n 'file-attachment': PdfAnnotationSubtypeCode.FILEATTACHMENT,\n redact: PdfAnnotationSubtypeCode.REDACT,\n widget: PdfAnnotationSubtypeCode.WIDGET,\n unsupported: PdfAnnotationSubtypeCode.UNKNOWN,\n });\n\nexport function subtypeFromCode(code: number): AnnotationSubtype {\n return PDF_CODE_TO_SUBTYPE[code] ?? 'unsupported';\n}\n"],"mappings":";;;;;;;;;;;;AAWA,MAAa,sBAAsB;CACjC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;;;;;;AAUA,MAAa,2BAA2B;CACtC,SAAS;CACT,MAAM;CACN,MAAM;CACN,UAAU;CACV,MAAM;CACN,QAAQ;CACR,QAAQ;CACR,SAAS;CACT,UAAU;CACV,WAAW;CACX,WAAW;CACX,UAAU;CACV,WAAW;CACX,OAAO;CACP,OAAO;CACP,KAAK;CACL,OAAO;CACP,gBAAgB;CAChB,OAAO;CACP,OAAO;CACP,QAAQ;CACR,QAAQ;CACR,aAAa;CACb,SAAS;CACT,WAAW;CACX,QAAQ;CACR,WAAW;CACX,WAAW;CACX,QAAQ;AACV;;;;;AASA,MAAa,sBAAmE,OAAO,OAAO;EAC3F,yBAAyB,OAAO;EAChC,yBAAyB,OAAO;EAChC,yBAAyB,WAAW;EACpC,yBAAyB,OAAO;EAChC,yBAAyB,SAAS;EAClC,yBAAyB,SAAS;EAClC,yBAAyB,UAAU;EACnC,yBAAyB,WAAW;EACpC,yBAAyB,YAAY;EACrC,yBAAyB,YAAY;EACrC,yBAAyB,WAAW;EACpC,yBAAyB,YAAY;EACrC,yBAAyB,QAAQ;EACjC,yBAAyB,QAAQ;EACjC,yBAAyB,MAAM;EAC/B,yBAAyB,QAAQ;EACjC,yBAAyB,iBAAiB;EAC1C,yBAAyB,SAAS;EAClC,yBAAyB,SAAS;AACrC,CAAC;;;;;AAMD,MAAa,sBACX,OAAO,OAAO;CACZ,MAAM,yBAAyB;CAC/B,MAAM,yBAAyB;CAC/B,aAAa,yBAAyB;CACtC,MAAM,yBAAyB;CAC/B,QAAQ,yBAAyB;CACjC,QAAQ,yBAAyB;CACjC,SAAS,yBAAyB;CAClC,UAAU,yBAAyB;CACnC,WAAW,yBAAyB;CACpC,WAAW,yBAAyB;CACpC,UAAU,yBAAyB;CACnC,WAAW,yBAAyB;CACpC,OAAO,yBAAyB;CAChC,OAAO,yBAAyB;CAChC,KAAK,yBAAyB;CAC9B,OAAO,yBAAyB;CAChC,mBAAmB,yBAAyB;CAC5C,QAAQ,yBAAyB;CACjC,QAAQ,yBAAyB;CACjC,aAAa,yBAAyB;AACxC,CAAC;AAEH,SAAgB,gBAAgB,MAAiC;CAC/D,OAAO,oBAAoB,SAAS;AACtC"}
|
|
@@ -0,0 +1,578 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_value = require("./value-BFS1R8ek.cjs");
|
|
3
|
+
const require_resolveAnnotationDraft = require("./resolveAnnotationDraft-7Ke4nV7F.cjs");
|
|
4
|
+
const require_format = require("./format-Bp3QFSH1.cjs");
|
|
5
|
+
const require_pageRefs = require("./pageRefs-B3ur7Ckm.cjs");
|
|
6
|
+
const require_schema = require("./schema-miH6tWQC.cjs");
|
|
7
|
+
//#region src/annotation/checkWrite.ts
|
|
8
|
+
/**
|
|
9
|
+
* A prepared create's data checked against its kind's schema. The caller
|
|
10
|
+
* writes its own data, not the schema's output, so nothing is reshaped on its
|
|
11
|
+
* way in.
|
|
12
|
+
*/
|
|
13
|
+
function assertAnnotationDraft(draft, options = {}) {
|
|
14
|
+
const declaration = require_schema.declarationOf(String(draft.subtype));
|
|
15
|
+
const linked = options.linked ?? [];
|
|
16
|
+
const checked = (declaration && linked.length > 0 ? declaration.fileSchemas.create.omit(Object.fromEntries(linked.map((name) => [name, true]))) : require_schema.FileAnnotationDraftSchema).safeParse(draft);
|
|
17
|
+
if (!checked.success) throw invalidWrite(checked.error, `${String(draft.subtype)} create`);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* A prepared update's data (`pdfPrepareAnnotationPatch`) checked against the
|
|
21
|
+
* kind of `current`. A `readBack()` value still in it is a change, as
|
|
22
|
+
* preparation drops one sent back as it reads, so one a write can't make is
|
|
23
|
+
* refused; the rest is checked against the kind's update schema.
|
|
24
|
+
*/
|
|
25
|
+
function assertAnnotationPatch(current, prepared) {
|
|
26
|
+
if (current.subtype === "unsupported") return;
|
|
27
|
+
const values = prepared;
|
|
28
|
+
for (const [name, write] of Object.entries(require_schema.KIND_BY_SUBTYPE[current.subtype].readBackWrites)) {
|
|
29
|
+
const value = values[name];
|
|
30
|
+
if (value === void 0 || write?.safeParse(value).success) continue;
|
|
31
|
+
throw new require_format.EngineError(require_format.EngineErrorCode.InvalidArg, write ? `${current.subtype} update field '${name}': this value can be read but not written; send it back unchanged or replace it` : `${current.subtype} update field '${name}': the engine works this out; send it back unchanged or leave it out`, { details: { field: name } });
|
|
32
|
+
}
|
|
33
|
+
const parsed = require_schema.fileAnnotationPatchSchemaOf(current.subtype).safeParse(prepared);
|
|
34
|
+
if (!parsed.success) throw invalidWrite(parsed.error, `${current.subtype} update`);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* The draft the engine writes for `draft`, in the file's coordinates:
|
|
38
|
+
* prepared (`pdfPrepareAnnotationDraft`), checked against its kind, and
|
|
39
|
+
* every field that follows from it stated (`pdfDeriveAnnotationDraft`). A
|
|
40
|
+
* viewer predicts the same without schema validation
|
|
41
|
+
* (`pdfPredictAnnotationDraft`).
|
|
42
|
+
*
|
|
43
|
+
* Throws `InvalidArg` for a draft the engine refuses. Pure: it reads nothing
|
|
44
|
+
* but its arguments.
|
|
45
|
+
*/
|
|
46
|
+
function pdfResolveAnnotationDraft(draft, options = {}) {
|
|
47
|
+
const prepared = require_resolveAnnotationDraft.pdfPrepareAnnotationDraft(draft);
|
|
48
|
+
assertAnnotationDraft(prepared, { linked: options.linked ?? [] });
|
|
49
|
+
return require_resolveAnnotationDraft.pdfDeriveAnnotationDraft(prepared, options);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The patch the engine writes for `patch` on `current`, in the file's
|
|
53
|
+
* coordinates: prepared (`pdfPrepareAnnotationPatch`), checked against its
|
|
54
|
+
* kind (`assertAnnotationPatch`), and every field that follows from it
|
|
55
|
+
* stated (`pdfDeriveAnnotationPatch`). A viewer predicts the same without
|
|
56
|
+
* schema validation (`pdfPredictAnnotationPatch`).
|
|
57
|
+
*
|
|
58
|
+
* Throws `InvalidArg` for a patch the engine refuses. Pure: it reads nothing
|
|
59
|
+
* but its arguments.
|
|
60
|
+
*/
|
|
61
|
+
function pdfResolveAnnotationPatch(current, patch, options = {}) {
|
|
62
|
+
const prepared = require_resolveAnnotationDraft.pdfPrepareAnnotationPatch(current, patch);
|
|
63
|
+
assertAnnotationPatch(current, prepared);
|
|
64
|
+
return require_resolveAnnotationDraft.pdfDeriveAnnotationPatch(current, prepared, options);
|
|
65
|
+
}
|
|
66
|
+
function invalidWrite(error, where) {
|
|
67
|
+
const issue = error.issues[0];
|
|
68
|
+
const field = issue.path.join(".");
|
|
69
|
+
return new require_format.EngineError(require_format.EngineErrorCode.InvalidArg, `${where}${field ? ` field '${field}'` : ""}: ${issue.message}`, { details: field ? { field } : {} });
|
|
70
|
+
}
|
|
71
|
+
//#endregion
|
|
72
|
+
//#region src/transfer/planAnnotationImport.ts
|
|
73
|
+
/**
|
|
74
|
+
* What an import of `bundle` into the `target` pages creates, and what it
|
|
75
|
+
* leaves out. Nothing here touches a document, so an import refuses before
|
|
76
|
+
* its first write:
|
|
77
|
+
*
|
|
78
|
+
* - `InvalidArg` when an item's data isn't valid for its kind, or when a
|
|
79
|
+
* page an item is on or points at maps to no target page (naming them);
|
|
80
|
+
* - `NotFound` when a page list maps to a page the target doesn't have.
|
|
81
|
+
*
|
|
82
|
+
* Unsupported items and unresolved relationships are left out in this order:
|
|
83
|
+
*
|
|
84
|
+
* 1. an item of an unsupported kind, and a form field's widget; a field
|
|
85
|
+
* marker leaves out only that field;
|
|
86
|
+
* 2. an item whose `reply.to` or `parent` is no item of the bundle on the
|
|
87
|
+
* same target page (`parent-missing`);
|
|
88
|
+
* 3. an item whose name is used on its target page, or by an earlier item
|
|
89
|
+
* going to the same page (`name-conflict`);
|
|
90
|
+
* 4. then, until nothing changes, an item whose `reply.to` or `parent` was
|
|
91
|
+
* left out (`parent-dropped`), so a whole branch goes together.
|
|
92
|
+
*
|
|
93
|
+
* `nameTaken(page, nm)` answers for the target page as it is before the import.
|
|
94
|
+
*/
|
|
95
|
+
function planAnnotationImport(input) {
|
|
96
|
+
const { bundle, target, nameTaken } = input;
|
|
97
|
+
const items = bundle.items.map((item) => item.data);
|
|
98
|
+
const mapPage = require_resolveAnnotationDraft.bundlePageMapping({
|
|
99
|
+
bundlePages: bundle.pages,
|
|
100
|
+
pages: input.pages ?? "same",
|
|
101
|
+
target,
|
|
102
|
+
named: items.flatMap(pagesNamedBy)
|
|
103
|
+
});
|
|
104
|
+
const drops = /* @__PURE__ */ new Map();
|
|
105
|
+
const fieldDrops = /* @__PURE__ */ new Map();
|
|
106
|
+
const drafts = /* @__PURE__ */ new Map();
|
|
107
|
+
items.forEach((data, index) => {
|
|
108
|
+
if (data.subtype === "unsupported") {
|
|
109
|
+
drops.set(index, "unsupported-kind");
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
if (data.subtype === "widget") {
|
|
113
|
+
drops.set(index, "widget");
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
if (data.subtype === "popup" && data.parent === null) {
|
|
117
|
+
drops.set(index, "parent-missing");
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
const unwritable = unwritableValuesOf(data);
|
|
121
|
+
if (unwritable === "item") {
|
|
122
|
+
drops.set(index, "unsupported-value");
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
const markers = [...fieldMarkersOf(data), ...unwritable];
|
|
126
|
+
if (markers.length > 0) fieldDrops.set(index, markers);
|
|
127
|
+
drafts.set(index, draftOf$1(data, markers, mapPage, index));
|
|
128
|
+
});
|
|
129
|
+
const byKey = /* @__PURE__ */ new Map();
|
|
130
|
+
items.forEach((data, index) => {
|
|
131
|
+
const key = require_format.annotationKey(data.ref);
|
|
132
|
+
if (!byKey.has(key)) byKey.set(key, index);
|
|
133
|
+
});
|
|
134
|
+
const pageOf = (index) => require_format.encodePageKey(mapPage(items[index].ref.page));
|
|
135
|
+
const resolve = (ref, from) => {
|
|
136
|
+
const found = byKey.get(require_format.annotationKey(ref));
|
|
137
|
+
return found !== void 0 && pageOf(found) === pageOf(from) ? found : void 0;
|
|
138
|
+
};
|
|
139
|
+
const linksOf = (data) => [data.reply?.to, data.subtype === "popup" ? data.parent : null].filter((ref) => ref != null);
|
|
140
|
+
items.forEach((data, index) => {
|
|
141
|
+
if (drops.has(index)) return;
|
|
142
|
+
if (linksOf(data).some((ref) => resolve(ref, index) === void 0)) drops.set(index, "parent-missing");
|
|
143
|
+
});
|
|
144
|
+
const popupOf = /* @__PURE__ */ new Map();
|
|
145
|
+
items.forEach((data, index) => {
|
|
146
|
+
if (drops.has(index) || data.subtype !== "popup" || !data.parent) return;
|
|
147
|
+
const parent = resolve(data.parent, index);
|
|
148
|
+
if (popupOf.has(parent)) drops.set(index, "popup-taken");
|
|
149
|
+
else popupOf.set(parent, index);
|
|
150
|
+
});
|
|
151
|
+
const claimed = /* @__PURE__ */ new Set();
|
|
152
|
+
items.forEach((data, index) => {
|
|
153
|
+
if (drops.has(index) || !data.nm) return;
|
|
154
|
+
const page = mapPage(data.ref.page);
|
|
155
|
+
const claim = `${require_format.encodePageKey(page)}\u0000${data.nm}`;
|
|
156
|
+
if (claimed.has(claim) || nameTaken(page, data.nm)) drops.set(index, "name-conflict");
|
|
157
|
+
else claimed.add(claim);
|
|
158
|
+
});
|
|
159
|
+
for (let changed = true; changed;) {
|
|
160
|
+
changed = false;
|
|
161
|
+
items.forEach((data, index) => {
|
|
162
|
+
if (drops.has(index)) return;
|
|
163
|
+
if (linksOf(data).some((ref) => drops.has(resolve(ref, index)))) {
|
|
164
|
+
drops.set(index, "parent-dropped");
|
|
165
|
+
changed = true;
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
const planned = /* @__PURE__ */ new Map();
|
|
170
|
+
items.forEach((_data, index) => {
|
|
171
|
+
if (!drops.has(index)) planned.set(index, planned.size);
|
|
172
|
+
});
|
|
173
|
+
const creates = [...planned.keys()].map((index) => {
|
|
174
|
+
const data = items[index];
|
|
175
|
+
const replyTo = data.reply ? planned.get(resolve(data.reply.to, index)) : void 0;
|
|
176
|
+
const parent = data.subtype === "popup" && data.parent ? planned.get(resolve(data.parent, index)) : void 0;
|
|
177
|
+
return {
|
|
178
|
+
item: index,
|
|
179
|
+
page: mapPage(data.ref.page),
|
|
180
|
+
draft: drafts.get(index),
|
|
181
|
+
...replyTo !== void 0 ? { replyTo: {
|
|
182
|
+
planned: replyTo,
|
|
183
|
+
type: data.reply.type
|
|
184
|
+
} } : {},
|
|
185
|
+
...parent !== void 0 ? { parent } : {}
|
|
186
|
+
};
|
|
187
|
+
});
|
|
188
|
+
const dropped = [];
|
|
189
|
+
items.forEach((data, index) => {
|
|
190
|
+
const reason = drops.get(index);
|
|
191
|
+
if (reason) dropped.push({
|
|
192
|
+
ref: data.ref,
|
|
193
|
+
reason
|
|
194
|
+
});
|
|
195
|
+
else for (const drop of fieldDrops.get(index) ?? []) dropped.push({
|
|
196
|
+
ref: data.ref,
|
|
197
|
+
...drop
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
return {
|
|
201
|
+
creates,
|
|
202
|
+
dropped
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* The pages an item is on or points at, apart from its links to other
|
|
207
|
+
* annotations (`reply.to`, `parent`, `popup`), which resolve in the bundle.
|
|
208
|
+
*/
|
|
209
|
+
function pagesNamedBy(data) {
|
|
210
|
+
const { ref, reply: _reply, popup: _popup, ...rest } = data;
|
|
211
|
+
const fields = { ...rest };
|
|
212
|
+
if (data.subtype === "popup") delete fields.parent;
|
|
213
|
+
return [ref.page, ...require_pageRefs.pageRefsIn(fields)];
|
|
214
|
+
}
|
|
215
|
+
/** The fields of `data` that are markers for something the engine can't write. */
|
|
216
|
+
function fieldMarkersOf(data) {
|
|
217
|
+
const markers = [];
|
|
218
|
+
const measure = data.measure;
|
|
219
|
+
if (measure?.subtype === "geospatial") markers.push({
|
|
220
|
+
field: "measure",
|
|
221
|
+
reason: "geospatial"
|
|
222
|
+
});
|
|
223
|
+
if (measure?.subtype === "unknown") markers.push({
|
|
224
|
+
field: "measure",
|
|
225
|
+
reason: "unknown-measure"
|
|
226
|
+
});
|
|
227
|
+
const target = data.subtype === "link" ? data.target : null;
|
|
228
|
+
const carriedTarget = !!target && isWritableLinkTarget(target);
|
|
229
|
+
if (target && !carriedTarget) markers.push({
|
|
230
|
+
field: "target",
|
|
231
|
+
reason: "unsupported-action"
|
|
232
|
+
});
|
|
233
|
+
const { actions } = data;
|
|
234
|
+
if (Object.entries(actions ?? {}).some(([trigger, tree]) => data.subtype !== "link" || trigger !== "activate" ? true : carriedTarget && !writtenAsIs(tree))) markers.push({
|
|
235
|
+
field: "actions",
|
|
236
|
+
reason: "unsupported-action"
|
|
237
|
+
});
|
|
238
|
+
return markers;
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* The values `data` reads that a write can't make (a `readBack()` field's
|
|
242
|
+
* read-only values), each left out; `'item'` when one is a field every
|
|
243
|
+
* create needs. A link's target is reported by {@link fieldMarkersOf}.
|
|
244
|
+
*/
|
|
245
|
+
function unwritableValuesOf(data) {
|
|
246
|
+
const unwritable = [];
|
|
247
|
+
const declaration = require_schema.declarationOf(data.subtype);
|
|
248
|
+
for (const [name, spec] of Object.entries(declaration?.fields ?? {})) {
|
|
249
|
+
const { owner, readBack, required } = spec.traits;
|
|
250
|
+
if (owner !== "data" || !readBack || name === "target") continue;
|
|
251
|
+
const value = data[name];
|
|
252
|
+
if (value == null || spec.write.safeParse(value).success) continue;
|
|
253
|
+
if (required) return "item";
|
|
254
|
+
unwritable.push({
|
|
255
|
+
field: name,
|
|
256
|
+
reason: "unsupported-value"
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
return unwritable;
|
|
260
|
+
}
|
|
261
|
+
/** Whether a link's `/A` is what writing its target writes again. */
|
|
262
|
+
function writtenAsIs(tree) {
|
|
263
|
+
const root = tree?.root;
|
|
264
|
+
if (!tree || tree.incomplete || !root || root.next.length > 0) return false;
|
|
265
|
+
return !(root.type === "uri" && root.isMap);
|
|
266
|
+
}
|
|
267
|
+
/** Whether a write can make a link's target; the others read as markers. */
|
|
268
|
+
function isWritableLinkTarget(target) {
|
|
269
|
+
return target.kind === "named" ? STANDARD_NAMED_ACTIONS.has(target.name ?? "") : target.kind === "goto" || target.kind === "uri";
|
|
270
|
+
}
|
|
271
|
+
const STANDARD_NAMED_ACTIONS = /* @__PURE__ */ new Set([
|
|
272
|
+
"NextPage",
|
|
273
|
+
"PrevPage",
|
|
274
|
+
"FirstPage",
|
|
275
|
+
"LastPage"
|
|
276
|
+
]);
|
|
277
|
+
/** The create an item becomes, checked against its kind's create schema. */
|
|
278
|
+
function draftOf$1(data, markers, mapPage, index) {
|
|
279
|
+
const fields = { ...data };
|
|
280
|
+
delete fields.reply;
|
|
281
|
+
const declared = require_schema.declarationOf(data.subtype)?.fields ?? {};
|
|
282
|
+
for (const { field } of markers) if (declared[field]?.traits.writeNullable) fields[field] = null;
|
|
283
|
+
else delete fields[field];
|
|
284
|
+
const checked = require_schema.AnnotationDraftSchema.safeParse(fields);
|
|
285
|
+
if (data.subtype === "popup") delete fields.parent;
|
|
286
|
+
if (!checked.success) {
|
|
287
|
+
const issue = checked.error.issues[0];
|
|
288
|
+
const path = issue.path.join(".");
|
|
289
|
+
throw new require_format.EngineError(require_format.EngineErrorCode.InvalidArg, `import: item ${index}${path ? ` field '${path}'` : ""}: ${issue.message}`, { details: {
|
|
290
|
+
item: index,
|
|
291
|
+
...path ? { field: path } : {}
|
|
292
|
+
} });
|
|
293
|
+
}
|
|
294
|
+
return require_pageRefs.mapPageRefs(fields, mapPage);
|
|
295
|
+
}
|
|
296
|
+
//#endregion
|
|
297
|
+
//#region src/transfer/planFormImport.ts
|
|
298
|
+
/**
|
|
299
|
+
* What a form import writes and leaves out, decided before its first write: a design import's
|
|
300
|
+
* fields checked against the create schema, a values import's values matched to the form's
|
|
301
|
+
* fields. Built with zod, so it runs where the engine does, from
|
|
302
|
+
* `@embedpdf/engine-core/validation`; the facts an import commits are in `formImport.ts`.
|
|
303
|
+
*/
|
|
304
|
+
/**
|
|
305
|
+
* What a design import of `bundle` into the `target` pages creates, and what
|
|
306
|
+
* it leaves out. Nothing here touches a document, so an import refuses
|
|
307
|
+
* before its first write:
|
|
308
|
+
*
|
|
309
|
+
* - `InvalidArg` when a field's data isn't valid for its family, or when a
|
|
310
|
+
* page a widget is on or points at maps to no target page;
|
|
311
|
+
* - `NotFound` when a page list maps to a page the target doesn't have.
|
|
312
|
+
*
|
|
313
|
+
* Left out, in bundle order: a field of an unknown family, a field whose
|
|
314
|
+
* name is taken (`nameTaken`, for the document as it is before the
|
|
315
|
+
* import), a widget whose field isn't in the bundle, and each action that
|
|
316
|
+
* is a script, a submit or a link when `mayScript` is false
|
|
317
|
+
* (`doc.forms.script`), or that a write can't make. Each field keeps every
|
|
318
|
+
* widget it has. With `values`, each field gets the value the bundle holds.
|
|
319
|
+
*/
|
|
320
|
+
function planFormImport(input) {
|
|
321
|
+
const { bundle, mayScript } = input;
|
|
322
|
+
const mapPage = require_resolveAnnotationDraft.bundlePageMapping({
|
|
323
|
+
bundlePages: bundle.pages,
|
|
324
|
+
pages: input.pages ?? "same",
|
|
325
|
+
target: input.target,
|
|
326
|
+
named: bundle.widgets.flatMap((row) => require_pageRefs.pageRefsIn(row.data))
|
|
327
|
+
});
|
|
328
|
+
const rowByKey = new Map(bundle.widgets.map((row, index) => [require_format.annotationKey(row.data.ref), index]));
|
|
329
|
+
const owned = /* @__PURE__ */ new Set();
|
|
330
|
+
const dropped = [];
|
|
331
|
+
const claimed = /* @__PURE__ */ new Set();
|
|
332
|
+
const creates = [];
|
|
333
|
+
bundle.fields.forEach(({ data: field }, index) => {
|
|
334
|
+
const rows = field.widgets.flatMap((widget) => {
|
|
335
|
+
const row = widget.ref ? rowByKey.get(require_format.annotationKey(widget.ref)) : void 0;
|
|
336
|
+
return row === void 0 ? [] : [row];
|
|
337
|
+
});
|
|
338
|
+
for (const row of rows) owned.add(row);
|
|
339
|
+
if (field.family === "unknown") {
|
|
340
|
+
dropped.push({
|
|
341
|
+
ref: field.ref,
|
|
342
|
+
reason: "unsupported-family"
|
|
343
|
+
});
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
if (claimed.has(field.name) || input.nameTaken(field.name)) {
|
|
347
|
+
dropped.push({
|
|
348
|
+
ref: field.ref,
|
|
349
|
+
reason: "name-conflict"
|
|
350
|
+
});
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
353
|
+
claimed.add(field.name);
|
|
354
|
+
const draft = draftOf(field, fieldActionsOf(field, mayScript, dropped), rows.map((row) => placementOf(field, bundle.widgets[row].data, mapPage, mayScript, dropped)), index);
|
|
355
|
+
const value = input.values && holdsValue(field) ? require_value.fieldValueOf(field) : null;
|
|
356
|
+
creates.push({
|
|
357
|
+
field: index,
|
|
358
|
+
draft,
|
|
359
|
+
widgets: rows,
|
|
360
|
+
flags: rows.map((row) => flagsOf(bundle.widgets[row].data)),
|
|
361
|
+
...value ? { value } : {}
|
|
362
|
+
});
|
|
363
|
+
});
|
|
364
|
+
bundle.widgets.forEach((row, index) => {
|
|
365
|
+
if (!owned.has(index)) dropped.push({
|
|
366
|
+
ref: row.data.field,
|
|
367
|
+
widget: row.data.ref,
|
|
368
|
+
reason: "no-field"
|
|
369
|
+
});
|
|
370
|
+
});
|
|
371
|
+
return {
|
|
372
|
+
creates,
|
|
373
|
+
calculationOrder: bundle.calculationOrder.flatMap((ref) => {
|
|
374
|
+
const at = creates.findIndex((create) => require_format.encodeFieldRefKey(bundle.fields[create.field].data.ref) === require_format.encodeFieldRefKey(ref) && create.draft.actions?.calculate);
|
|
375
|
+
return at < 0 ? [] : [at];
|
|
376
|
+
}),
|
|
377
|
+
dropped
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* What a values import of `bundle` writes into a form whose fields are
|
|
382
|
+
* `target`: each field the bundle holds a value for gets it, matched by full
|
|
383
|
+
* name. Left out, in bundle order: a field the document doesn't have
|
|
384
|
+
* (`no-field`), one of another family (`wrong-family`), and one `refusal`
|
|
385
|
+
* names a reason for: a value the field can't take, a field a signature
|
|
386
|
+
* locked, a field the session may not fill in. So everything is decided
|
|
387
|
+
* before the first write.
|
|
388
|
+
*/
|
|
389
|
+
function planFormValuesImport(input) {
|
|
390
|
+
const writes = [];
|
|
391
|
+
const dropped = [];
|
|
392
|
+
input.bundle.fields.forEach(({ data: field }, index) => {
|
|
393
|
+
const value = holdsValue(field) ? require_value.fieldValueOf(field) : null;
|
|
394
|
+
if (!value) return;
|
|
395
|
+
const target = input.target.find((candidate) => require_value.fieldMatches(candidate, {
|
|
396
|
+
kind: "fqn",
|
|
397
|
+
name: field.name
|
|
398
|
+
}));
|
|
399
|
+
if (!target) dropped.push({
|
|
400
|
+
ref: field.ref,
|
|
401
|
+
reason: "no-field"
|
|
402
|
+
});
|
|
403
|
+
else if (target.family !== field.family) dropped.push({
|
|
404
|
+
ref: field.ref,
|
|
405
|
+
reason: "wrong-family"
|
|
406
|
+
});
|
|
407
|
+
else {
|
|
408
|
+
const refused = input.refusal?.(target, value);
|
|
409
|
+
if (refused) dropped.push({
|
|
410
|
+
ref: field.ref,
|
|
411
|
+
reason: refused
|
|
412
|
+
});
|
|
413
|
+
else writes.push({
|
|
414
|
+
field: index,
|
|
415
|
+
target,
|
|
416
|
+
value
|
|
417
|
+
});
|
|
418
|
+
}
|
|
419
|
+
});
|
|
420
|
+
return {
|
|
421
|
+
writes,
|
|
422
|
+
dropped
|
|
423
|
+
};
|
|
424
|
+
}
|
|
425
|
+
/** Whether a field read holds a value a write can set. */
|
|
426
|
+
function holdsValue(field) {
|
|
427
|
+
return field.valueEntry.kind === "scalar" || field.valueEntry.kind === "array";
|
|
428
|
+
}
|
|
429
|
+
/** A field's scripts as a create writes them; each left out is reported. */
|
|
430
|
+
function fieldActionsOf(field, mayScript, dropped) {
|
|
431
|
+
const actions = {};
|
|
432
|
+
for (const [event, tree] of Object.entries(field.actions ?? {})) {
|
|
433
|
+
if (!tree) continue;
|
|
434
|
+
const script = require_value.fieldScriptOf(tree);
|
|
435
|
+
const member = `actions.${event}`;
|
|
436
|
+
if (!script) dropped.push({
|
|
437
|
+
ref: field.ref,
|
|
438
|
+
field: member,
|
|
439
|
+
reason: "unsupported-action"
|
|
440
|
+
});
|
|
441
|
+
else if (!mayScript) dropped.push({
|
|
442
|
+
ref: field.ref,
|
|
443
|
+
field: member,
|
|
444
|
+
reason: "script-not-allowed"
|
|
445
|
+
});
|
|
446
|
+
else actions[event] = script;
|
|
447
|
+
}
|
|
448
|
+
return actions;
|
|
449
|
+
}
|
|
450
|
+
/** A widget row as a create places it: on its mapped page, with its look and actions. */
|
|
451
|
+
function placementOf(field, row, mapPage, mayScript, dropped) {
|
|
452
|
+
const actions = {};
|
|
453
|
+
for (const event of require_value.WIDGET_ACTION_EVENTS) {
|
|
454
|
+
const tree = row.actions?.[event];
|
|
455
|
+
if (!tree) continue;
|
|
456
|
+
const write = require_value.actionWriteOf(tree);
|
|
457
|
+
const drop = (reason) => dropped.push({
|
|
458
|
+
ref: field.ref,
|
|
459
|
+
widget: row.ref,
|
|
460
|
+
field: `actions.${event}`,
|
|
461
|
+
reason
|
|
462
|
+
});
|
|
463
|
+
if (!write) drop("unsupported-action");
|
|
464
|
+
else if (!mayScript && require_value.needsScriptRight(write)) drop("script-not-allowed");
|
|
465
|
+
else actions[event] = require_pageRefs.mapPageRefs(write, mapPage);
|
|
466
|
+
}
|
|
467
|
+
const toggle = field.family === "checkbox" || field.family === "radio" ? field.widgets.find((widget) => widget.ref && require_format.annotationKey(widget.ref) === require_format.annotationKey(row.ref)) : void 0;
|
|
468
|
+
const look = {
|
|
469
|
+
color: row.color,
|
|
470
|
+
interiorColor: row.interiorColor,
|
|
471
|
+
fontFamily: row.fontFamily,
|
|
472
|
+
fontSize: row.fontSize,
|
|
473
|
+
fontColor: row.fontColor,
|
|
474
|
+
caption: field.family === "pushbutton" ? row.caption : null
|
|
475
|
+
};
|
|
476
|
+
return {
|
|
477
|
+
page: mapPage(row.page),
|
|
478
|
+
rect: row.rect,
|
|
479
|
+
...row.rotation ? { rotation: row.rotation } : {},
|
|
480
|
+
strokeWidth: row.strokeWidth,
|
|
481
|
+
borderStyle: row.borderStyle,
|
|
482
|
+
textAlign: row.textAlign,
|
|
483
|
+
...Object.fromEntries(Object.entries(look).filter(([, value]) => value != null)),
|
|
484
|
+
...toggle && "exportValue" in toggle ? { exportValue: toggle.exportValue } : {},
|
|
485
|
+
...Object.keys(actions).length > 0 ? { actions } : {}
|
|
486
|
+
};
|
|
487
|
+
}
|
|
488
|
+
function flagsOf(row) {
|
|
489
|
+
return Object.fromEntries(require_value.WIDGET_FLAG_NAMES.map((name) => [name, row[name]]));
|
|
490
|
+
}
|
|
491
|
+
/** The create a field row becomes, checked against the create schema. */
|
|
492
|
+
function draftOf(field, actions, widgets, index) {
|
|
493
|
+
const base = {
|
|
494
|
+
name: field.name,
|
|
495
|
+
readOnly: field.readOnly,
|
|
496
|
+
required: field.required,
|
|
497
|
+
noExport: field.noExport,
|
|
498
|
+
...field.alternateName !== null ? { alternateName: field.alternateName } : {},
|
|
499
|
+
...field.mappingName !== null ? { mappingName: field.mappingName } : {},
|
|
500
|
+
...field.groupId !== null ? { groupId: field.groupId } : {},
|
|
501
|
+
...Object.keys(actions).length > 0 ? { actions } : {},
|
|
502
|
+
widgets
|
|
503
|
+
};
|
|
504
|
+
const hasDefault = field.defaultValueEntry.kind !== "none";
|
|
505
|
+
const options = (list) => list.map(({ label, value }) => ({
|
|
506
|
+
label,
|
|
507
|
+
value
|
|
508
|
+
}));
|
|
509
|
+
let draft;
|
|
510
|
+
switch (field.family) {
|
|
511
|
+
case "text":
|
|
512
|
+
draft = {
|
|
513
|
+
...base,
|
|
514
|
+
family: "text",
|
|
515
|
+
...hasDefault ? { defaultValue: field.defaultValue } : {},
|
|
516
|
+
...field.maxLength !== null ? { maxLength: field.maxLength } : {},
|
|
517
|
+
multiline: field.multiline,
|
|
518
|
+
password: field.password,
|
|
519
|
+
comb: field.comb
|
|
520
|
+
};
|
|
521
|
+
break;
|
|
522
|
+
case "radio":
|
|
523
|
+
draft = {
|
|
524
|
+
...base,
|
|
525
|
+
family: "radio",
|
|
526
|
+
radiosInUnison: field.radiosInUnison,
|
|
527
|
+
noToggleToOff: field.noToggleToOff
|
|
528
|
+
};
|
|
529
|
+
break;
|
|
530
|
+
case "combobox":
|
|
531
|
+
draft = {
|
|
532
|
+
...base,
|
|
533
|
+
family: "combobox",
|
|
534
|
+
edit: field.edit,
|
|
535
|
+
options: options(field.options),
|
|
536
|
+
...hasDefault ? { defaultValue: field.defaultValue } : {}
|
|
537
|
+
};
|
|
538
|
+
break;
|
|
539
|
+
case "listbox":
|
|
540
|
+
draft = {
|
|
541
|
+
...base,
|
|
542
|
+
family: "listbox",
|
|
543
|
+
multiSelect: field.multiSelect,
|
|
544
|
+
options: options(field.options),
|
|
545
|
+
...hasDefault ? { defaultValue: field.defaultValue } : {}
|
|
546
|
+
};
|
|
547
|
+
break;
|
|
548
|
+
case "checkbox":
|
|
549
|
+
case "pushbutton":
|
|
550
|
+
case "signature":
|
|
551
|
+
draft = {
|
|
552
|
+
...base,
|
|
553
|
+
family: field.family
|
|
554
|
+
};
|
|
555
|
+
break;
|
|
556
|
+
default: throw new require_format.EngineError(require_format.EngineErrorCode.InvalidArg, `import: field ${index} has no family`);
|
|
557
|
+
}
|
|
558
|
+
const checked = require_schema.FormFieldDraftSchema.safeParse(draft);
|
|
559
|
+
if (!checked.success) {
|
|
560
|
+
const issue = checked.error.issues[0];
|
|
561
|
+
const path = issue.path.join(".");
|
|
562
|
+
throw new require_format.EngineError(require_format.EngineErrorCode.InvalidArg, `import: field ${index}${path ? ` member '${path}'` : ""}: ${issue.message}`, { details: {
|
|
563
|
+
item: index,
|
|
564
|
+
...path ? { field: path } : {}
|
|
565
|
+
} });
|
|
566
|
+
}
|
|
567
|
+
return draft;
|
|
568
|
+
}
|
|
569
|
+
//#endregion
|
|
570
|
+
exports.assertAnnotationDraft = assertAnnotationDraft;
|
|
571
|
+
exports.assertAnnotationPatch = assertAnnotationPatch;
|
|
572
|
+
exports.pdfResolveAnnotationDraft = pdfResolveAnnotationDraft;
|
|
573
|
+
exports.pdfResolveAnnotationPatch = pdfResolveAnnotationPatch;
|
|
574
|
+
exports.planAnnotationImport = planAnnotationImport;
|
|
575
|
+
exports.planFormImport = planFormImport;
|
|
576
|
+
exports.planFormValuesImport = planFormValuesImport;
|
|
577
|
+
|
|
578
|
+
//# sourceMappingURL=validation.cjs.map
|