@embedpdf/core-acrojs 3.0.0-next.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.
package/dist/index.cjs ADDED
@@ -0,0 +1,582 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ //#region src/actions.ts
3
+ /**
4
+ * Return executable JavaScript in PDF action order (root, then `/Next`
5
+ * depth-first). A poisoned native snapshot is never partially executed.
6
+ */
7
+ function javaScriptSourcesFromActionTree(tree) {
8
+ if (tree.incomplete) throw new Error("Refusing to execute an incomplete PDF action tree");
9
+ const sources = [];
10
+ const visit = (node) => {
11
+ if (node.type === "javascript" && node.script !== void 0) sources.push(node.script);
12
+ for (const child of node.next) visit(child);
13
+ };
14
+ if (tree.root) visit(tree.root);
15
+ return sources;
16
+ }
17
+ /** One event source that preserves the tree's shared field overlay. */
18
+ function javaScriptProgramFromActionTree(tree) {
19
+ return javaScriptSourcesFromActionTree(tree).join("\n;\n");
20
+ }
21
+ //#endregion
22
+ //#region src/input.ts
23
+ function valueFromEntry(entry) {
24
+ switch (entry.kind) {
25
+ case "scalar": return entry.value;
26
+ case "array": return [...entry.values];
27
+ case "none":
28
+ case "unsupported": return null;
29
+ }
30
+ }
31
+ function fieldValueFromEntry(family, entry) {
32
+ if ((family === "checkbox" || family === "radio") && entry.kind === "none") return "Off";
33
+ return valueFromEntry(entry);
34
+ }
35
+ /** Build the VM's detached field view from the engine's lossless snapshot. */
36
+ function scriptFieldsFromSnapshot(snapshot) {
37
+ return snapshot.fields.map((field) => ({
38
+ ref: field.ref,
39
+ name: field.name,
40
+ family: field.family,
41
+ value: fieldValueFromEntry(field.family, field.valueEntry),
42
+ defaultValue: fieldValueFromEntry(field.family, field.defaultValueEntry),
43
+ display: "visible",
44
+ readOnly: field.flags.readOnly,
45
+ required: field.flags.required,
46
+ ..."options" in field ? { options: field.options.map((option) => ({
47
+ label: option.label,
48
+ value: option.value
49
+ })) } : {}
50
+ }));
51
+ }
52
+ //#endregion
53
+ //#region src/prelude.ts
54
+ /**
55
+ * Install the curated Acrobat object model into an isolated JavaScript realm.
56
+ *
57
+ * This function must remain self-contained: no imports and no closed-over
58
+ * values. The sandbox ships `installAcroJs.toString()` into QuickJS, while
59
+ * tests execute the same source in a Node VM. Types disappear at build time.
60
+ */
61
+ function installAcroJs(g) {
62
+ const host = g;
63
+ const NativeDate = Date;
64
+ let state = null;
65
+ const cloneValue = (value) => Array.isArray(value) ? value.map((item) => String(item)) : value;
66
+ const sameValue = (a, b) => {
67
+ if (Array.isArray(a) && Array.isArray(b)) return a.length === b.length && a.every((item, index) => item === b[index]);
68
+ return a === b;
69
+ };
70
+ const refKey = (ref) => {
71
+ const value = ref;
72
+ return value?.kind === "objectNumber" ? `obj:${String(value.fieldObjectNumber)}` : `fqn:${String(value?.name ?? "")}`;
73
+ };
74
+ const diagnostic = (code, message) => {
75
+ state?.diagnostics.push({
76
+ code,
77
+ message
78
+ });
79
+ };
80
+ const blocked = (api) => {
81
+ diagnostic("blocked-network", `${api} is blocked by the scripting policy`);
82
+ };
83
+ const numberValue = (value) => {
84
+ if (typeof value === "number") return Number.isFinite(value) ? value : 0;
85
+ const parsed = Number(String(value ?? "").replace(/[^0-9+\-.]/g, ""));
86
+ return Number.isFinite(parsed) ? parsed : 0;
87
+ };
88
+ const displayToCode = (display) => display === "hidden" ? 1 : display === "noPrint" ? 2 : display === "noView" ? 3 : 0;
89
+ const codeToDisplay = (code) => Number(code) === 1 ? "hidden" : Number(code) === 2 ? "noPrint" : Number(code) === 3 ? "noView" : "visible";
90
+ const eventName = (kind) => kind === "widget-activate" ? "Mouse Up" : kind === "field-keystroke" ? "Keystroke" : kind === "field-validate" ? "Validate" : kind === "field-calculate" ? "Calculate" : kind === "field-format" ? "Format" : "Open";
91
+ const doc = {};
92
+ const makeField = (record) => {
93
+ const input = record.input;
94
+ const wrapper = {};
95
+ Object.defineProperties(wrapper, {
96
+ name: {
97
+ enumerable: true,
98
+ get: () => input.name
99
+ },
100
+ type: {
101
+ enumerable: true,
102
+ get: () => input.family
103
+ },
104
+ value: {
105
+ enumerable: true,
106
+ get: () => cloneValue(record.value),
107
+ set: (value) => {
108
+ record.value = cloneValue(value);
109
+ }
110
+ },
111
+ valueAsString: {
112
+ enumerable: true,
113
+ get: () => Array.isArray(record.value) ? record.value.join(",") : String(record.value ?? "")
114
+ },
115
+ defaultValue: {
116
+ enumerable: true,
117
+ get: () => cloneValue(input.defaultValue)
118
+ },
119
+ readonly: {
120
+ enumerable: true,
121
+ get: () => Boolean(input.readOnly),
122
+ set: () => {
123
+ diagnostic("unsupported-api", "Field.readonly writes are not supported in v1");
124
+ }
125
+ },
126
+ required: {
127
+ enumerable: true,
128
+ get: () => Boolean(input.required),
129
+ set: () => {
130
+ diagnostic("unsupported-api", "Field.required writes are not supported in v1");
131
+ }
132
+ },
133
+ display: {
134
+ enumerable: true,
135
+ get: () => displayToCode(record.display),
136
+ set: (value) => {
137
+ record.display = codeToDisplay(value);
138
+ }
139
+ },
140
+ source: {
141
+ enumerable: false,
142
+ get: () => doc
143
+ }
144
+ });
145
+ wrapper.setFocus = () => diagnostic("unsupported-api", "Field.setFocus is not supported in v1");
146
+ return wrapper;
147
+ };
148
+ const getField = (name) => state?.fieldsByName.get(String(name))?.wrapper ?? null;
149
+ Object.defineProperties(doc, {
150
+ documentFileName: {
151
+ enumerable: true,
152
+ get: () => String((state?.input.document)?.fileName ?? "")
153
+ },
154
+ numFields: {
155
+ enumerable: true,
156
+ get: () => state?.fields.length ?? 0
157
+ },
158
+ pageNum: {
159
+ enumerable: true,
160
+ get: () => Number((state?.input.document)?.pageNumber ?? 0),
161
+ set: (value) => {
162
+ const page = Math.trunc(Number(value));
163
+ if (Number.isFinite(page)) state?.uiEffects.push({
164
+ kind: "gotoPage",
165
+ page
166
+ });
167
+ }
168
+ }
169
+ });
170
+ doc.getField = getField;
171
+ doc.getNthFieldName = (index) => String(state?.fields[Math.trunc(Number(index))]?.input.name ?? "");
172
+ doc.resetForm = (names) => {
173
+ if (!state) return;
174
+ const requested = names === void 0 ? state.fields : (Array.isArray(names) ? names : [names]).map((name) => state.fieldsByName.get(String(name))).filter((field) => field !== void 0);
175
+ for (const field of requested) {
176
+ field.value = cloneValue(field.input.defaultValue);
177
+ const key = refKey(field.input.ref);
178
+ if (!state.resetKeys.has(key)) {
179
+ state.resetKeys.add(key);
180
+ state.resetRefs.push(field.input.ref);
181
+ }
182
+ }
183
+ };
184
+ doc.print = () => state?.uiEffects.push({ kind: "print" });
185
+ doc.submitForm = () => blocked("submitForm");
186
+ doc.mailDoc = () => blocked("mailDoc");
187
+ doc.getURL = () => blocked("getURL");
188
+ const app = {
189
+ platform: "WIN",
190
+ language: "ENU",
191
+ viewerType: "Reader",
192
+ viewerVariation: "Reader",
193
+ viewerVersion: 21,
194
+ formsVersion: 21,
195
+ alert: (message, icon, _type, title) => {
196
+ state?.uiEffects.push({
197
+ kind: "alert",
198
+ message: String(message),
199
+ icon: Number.isFinite(Number(icon)) ? Number(icon) : 0,
200
+ ...title === void 0 ? {} : { title: String(title) }
201
+ });
202
+ return 1;
203
+ },
204
+ beep: () => diagnostic("unsupported-api", "app.beep is not supported in v1"),
205
+ response: () => {
206
+ diagnostic("unsupported-api", "app.response is not supported in v1");
207
+ return null;
208
+ },
209
+ launchURL: () => blocked("app.launchURL"),
210
+ findComponent: () => {
211
+ diagnostic("unsupported-api", "app.findComponent: no installable components in this viewer");
212
+ }
213
+ };
214
+ const pad = (value, length = 2) => String(value).padStart(length, "0");
215
+ const monthShort = [
216
+ "Jan",
217
+ "Feb",
218
+ "Mar",
219
+ "Apr",
220
+ "May",
221
+ "Jun",
222
+ "Jul",
223
+ "Aug",
224
+ "Sep",
225
+ "Oct",
226
+ "Nov",
227
+ "Dec"
228
+ ];
229
+ const monthLong = [
230
+ "January",
231
+ "February",
232
+ "March",
233
+ "April",
234
+ "May",
235
+ "June",
236
+ "July",
237
+ "August",
238
+ "September",
239
+ "October",
240
+ "November",
241
+ "December"
242
+ ];
243
+ const printd = (format, inputDate) => {
244
+ const environment = state?.input.environment ?? {};
245
+ const date = inputDate && typeof inputDate.getTime === "function" ? new NativeDate(Number(inputDate.getTime())) : new NativeDate(Number(environment.nowMs ?? 0));
246
+ const local = new NativeDate(date.getTime() + Number(environment.utcOffsetMinutes ?? 0) * 6e4);
247
+ const year = local.getUTCFullYear();
248
+ const month = local.getUTCMonth();
249
+ const day = local.getUTCDate();
250
+ const hour = local.getUTCHours();
251
+ const minute = local.getUTCMinutes();
252
+ const second = local.getUTCSeconds();
253
+ const tokens = {
254
+ yyyy: String(year),
255
+ yy: pad(year % 100),
256
+ mmmm: monthLong[month],
257
+ mmm: monthShort[month],
258
+ mm: pad(month + 1),
259
+ m: String(month + 1),
260
+ dd: pad(day),
261
+ d: String(day),
262
+ HH: pad(hour),
263
+ H: String(hour),
264
+ MM: pad(minute),
265
+ M: String(minute),
266
+ ss: pad(second)
267
+ };
268
+ return String(format).replace(/yyyy|mmmm|mmm|yy|mm|dd|HH|MM|ss|m|d|H|M/g, (token) => tokens[token]);
269
+ };
270
+ const util = {
271
+ printd,
272
+ printf: (format, ...values) => {
273
+ let index = 0;
274
+ return String(format).replace(/%(?:,?\d*(?:\.\d+)?)?[dfs]/g, (token) => {
275
+ const value = values[index++];
276
+ if (token.endsWith("s")) return String(value ?? "");
277
+ if (token.endsWith("d")) return String(Math.trunc(numberValue(value)));
278
+ const precision = /\.(\d+)/.exec(token)?.[1];
279
+ return numberValue(value).toFixed(precision ? Number(precision) : 0);
280
+ });
281
+ }
282
+ };
283
+ const begin = (input, budget) => {
284
+ const fields = (input.fields ?? []).map((field) => {
285
+ const record = {
286
+ input: field,
287
+ originalValue: cloneValue(field.value),
288
+ value: cloneValue(field.value),
289
+ originalDisplay: String(field.display ?? "visible"),
290
+ display: String(field.display ?? "visible"),
291
+ wrapper: {}
292
+ };
293
+ record.wrapper = makeField(record);
294
+ return record;
295
+ });
296
+ const fieldsByName = new Map(fields.map((field) => [String(field.input.name), field]));
297
+ const fieldsByRef = new Map(fields.map((field) => [refKey(field.input.ref), field]));
298
+ const eventInput = input.event ?? {};
299
+ const target = fieldsByRef.get(refKey(eventInput.target));
300
+ const source = fieldsByRef.get(refKey(eventInput.source));
301
+ const initialValue = eventInput.value !== void 0 ? cloneValue(eventInput.value) : cloneValue(target?.value ?? null);
302
+ const event = {
303
+ name: eventName(String(eventInput.kind ?? "")),
304
+ type: eventInput.kind === "name-tree-boot" ? "Doc" : "Field",
305
+ target: target?.wrapper ?? null,
306
+ targetName: String(target?.input.name ?? ""),
307
+ source: source?.wrapper ?? { source: doc },
308
+ value: initialValue,
309
+ change: String(eventInput.change ?? ""),
310
+ selStart: Math.max(0, Math.trunc(Number(eventInput.selStart ?? 0))),
311
+ selEnd: Math.max(0, Math.trunc(Number(eventInput.selEnd ?? 0))),
312
+ willCommit: Boolean(eventInput.willCommit),
313
+ modifier: Boolean(eventInput.modifier),
314
+ shift: Boolean(eventInput.shift),
315
+ rc: true
316
+ };
317
+ state = {
318
+ input,
319
+ fields,
320
+ fieldsByName,
321
+ fieldsByRef,
322
+ event,
323
+ resetRefs: [],
324
+ resetKeys: /* @__PURE__ */ new Set(),
325
+ uiEffects: [],
326
+ diagnostics: [],
327
+ randomState: Number(input.environment?.randomSeed ?? 1) >>> 0,
328
+ maxEffects: Math.max(1, Math.trunc(Number(budget?.maxEffects ?? 256)))
329
+ };
330
+ host.event = event;
331
+ host.identity = { ...input.identity ?? {} };
332
+ };
333
+ const formValue = (field, value) => {
334
+ const family = String(field.input.family);
335
+ if (family === "text") return {
336
+ type: "text",
337
+ value: String(value ?? "")
338
+ };
339
+ if (family === "checkbox" || family === "radio") return {
340
+ type: "toggle",
341
+ state: value === null || value === void 0 || String(value) === "Off" ? null : String(value)
342
+ };
343
+ if (family === "combobox") return {
344
+ type: "choice",
345
+ values: Array.isArray(value) ? value.slice(0, 1).map(String) : [String(value ?? "")]
346
+ };
347
+ if (family === "listbox") return {
348
+ type: "choice",
349
+ values: Array.isArray(value) ? value.map(String) : [String(value ?? "")]
350
+ };
351
+ diagnostic("invalid-field-value", `field '${String(field.input.name)}' cannot accept a scripted value`);
352
+ return null;
353
+ };
354
+ const eventOutput = () => ({
355
+ rc: Boolean(state?.event.rc),
356
+ value: cloneValue(state?.event.value ?? null),
357
+ change: String(state?.event.change ?? ""),
358
+ selStart: Math.max(0, Math.trunc(Number(state?.event.selStart ?? 0))),
359
+ selEnd: Math.max(0, Math.trunc(Number(state?.event.selEnd ?? 0)))
360
+ });
361
+ const finish = () => {
362
+ if (!state) throw new Error("AcroJS run state was not initialized");
363
+ const eventInput = state.input.event;
364
+ const target = state.fieldsByRef.get(refKey(eventInput.target));
365
+ const kind = String(eventInput.kind ?? "");
366
+ if (target && kind === "field-calculate") target.value = cloneValue(state.event.value);
367
+ const formEffects = [];
368
+ if (state.resetRefs.length > 0) formEffects.push({
369
+ kind: "reset",
370
+ refs: [...state.resetRefs]
371
+ });
372
+ for (const field of state.fields) {
373
+ const key = refKey(field.input.ref);
374
+ const valueBaseline = state.resetKeys.has(key) ? field.input.defaultValue : field.originalValue;
375
+ if (!sameValue(field.value, valueBaseline)) {
376
+ const value = formValue(field, field.value);
377
+ if (value) formEffects.push({
378
+ kind: "setValue",
379
+ ref: field.input.ref,
380
+ value
381
+ });
382
+ }
383
+ if (field.display !== field.originalDisplay) formEffects.push({
384
+ kind: "setDisplay",
385
+ ref: field.input.ref,
386
+ display: field.display
387
+ });
388
+ }
389
+ if (target && kind === "field-format") formEffects.push({
390
+ kind: "setAppearanceText",
391
+ ref: target.input.ref,
392
+ text: String(state.event.value ?? "")
393
+ });
394
+ const totalEffects = formEffects.length + state.uiEffects.length;
395
+ if (totalEffects > state.maxEffects) return {
396
+ event: eventOutput(),
397
+ formEffects: [],
398
+ uiEffects: [],
399
+ diagnostics: [...state.diagnostics],
400
+ error: {
401
+ kind: "budget",
402
+ message: `script produced ${totalEffects} effects; limit is ${state.maxEffects}`
403
+ }
404
+ };
405
+ return {
406
+ event: eventOutput(),
407
+ formEffects,
408
+ uiEffects: [...state.uiEffects],
409
+ diagnostics: [...state.diagnostics]
410
+ };
411
+ };
412
+ const failed = (error) => ({
413
+ event: eventOutput(),
414
+ formEffects: [],
415
+ uiEffects: [],
416
+ diagnostics: [...state?.diagnostics ?? []],
417
+ error: {
418
+ kind: "exception",
419
+ message: error instanceof Error ? error.message : String(error),
420
+ ...error instanceof Error && error.stack ? { stack: error.stack } : {}
421
+ }
422
+ });
423
+ const evaluate = (source) => {
424
+ return (0, eval)(source);
425
+ };
426
+ const boot = (sources, input, budget) => {
427
+ begin(input, budget);
428
+ try {
429
+ for (const source of sources ?? []) evaluate(String(source));
430
+ return finish();
431
+ } catch (error) {
432
+ return failed(error);
433
+ }
434
+ };
435
+ const run = (source, input, budget) => {
436
+ begin(input, budget);
437
+ try {
438
+ evaluate(String(source));
439
+ return finish();
440
+ } catch (error) {
441
+ return failed(error);
442
+ }
443
+ };
444
+ Object.defineProperties(host, {
445
+ __acrojsBoot: {
446
+ configurable: false,
447
+ writable: false,
448
+ value: boot
449
+ },
450
+ __acrojsRun: {
451
+ configurable: false,
452
+ writable: false,
453
+ value: run
454
+ }
455
+ });
456
+ host.app = app;
457
+ host.util = util;
458
+ host.display = Object.freeze({
459
+ visible: 0,
460
+ hidden: 1,
461
+ noPrint: 2,
462
+ noView: 3
463
+ });
464
+ host.getField = getField;
465
+ host.resetForm = doc.resetForm;
466
+ host.print = doc.print;
467
+ host.submitForm = doc.submitForm;
468
+ host.mailDoc = doc.mailDoc;
469
+ host.getURL = doc.getURL;
470
+ Object.defineProperties(host, {
471
+ documentFileName: {
472
+ configurable: true,
473
+ get: () => doc.documentFileName
474
+ },
475
+ numFields: {
476
+ configurable: true,
477
+ get: () => doc.numFields
478
+ },
479
+ pageNum: {
480
+ configurable: true,
481
+ get: () => doc.pageNum,
482
+ set: (value) => {
483
+ doc.pageNum = value;
484
+ }
485
+ }
486
+ });
487
+ class FixedDate extends NativeDate {
488
+ constructor(...args) {
489
+ if (args.length === 0) super(Number((state?.input.environment ?? {}).nowMs ?? 0));
490
+ else if (args.length === 1) super(args[0]);
491
+ else super(Number(args[0]), Number(args[1]), Number(args[2] ?? 1), Number(args[3] ?? 0), Number(args[4] ?? 0), Number(args[5] ?? 0), Number(args[6] ?? 0));
492
+ }
493
+ static now() {
494
+ return Number((state?.input.environment ?? {}).nowMs ?? 0);
495
+ }
496
+ }
497
+ host.Date = FixedDate;
498
+ const math = host.Math;
499
+ if (math) math.random = () => {
500
+ if (!state) return 0;
501
+ state.randomState = 1664525 * state.randomState + 1013904223 >>> 0;
502
+ return state.randomState / 4294967296;
503
+ };
504
+ host.AFSimple_Calculate = (operation, names) => {
505
+ const values = (Array.isArray(names) ? names : String(names).split(",")).map((name) => numberValue(getField(String(name).trim())?.value));
506
+ const op = String(operation).toUpperCase();
507
+ const value = values.length === 0 ? 0 : op === "PRD" ? values.reduce((a, b) => a * b, 1) : op === "AVG" ? values.reduce((a, b) => a + b, 0) / values.length : op === "MIN" ? Math.min(...values) : op === "MAX" ? Math.max(...values) : values.reduce((a, b) => a + b, 0);
508
+ if (state) state.event.value = value;
509
+ };
510
+ host.AFNumber_Format = (decimals, separatorStyle, _negativeStyle, _currencyStyle, currency, prepend) => {
511
+ if (!state) return;
512
+ const places = Math.max(0, Math.min(10, Math.trunc(Number(decimals))));
513
+ let formatted = numberValue(state.event.value).toFixed(places);
514
+ if (Number(separatorStyle) === 0 || Number(separatorStyle) === 2) {
515
+ const [whole, fraction] = formatted.split(".");
516
+ formatted = `${whole.replace(/\B(?=(\d{3})+(?!\d))/g, ",")}${fraction === void 0 ? "" : `.${fraction}`}`;
517
+ }
518
+ const symbol = String(currency ?? "");
519
+ state.event.value = prepend ? `${symbol}${formatted}` : `${formatted}${symbol}`;
520
+ };
521
+ host.AFPercent_Format = (decimals) => {
522
+ if (!state) return;
523
+ const places = Math.max(0, Math.min(10, Math.trunc(Number(decimals))));
524
+ state.event.value = `${(numberValue(state.event.value) * 100).toFixed(places)}%`;
525
+ };
526
+ host.AFDate_FormatEx = (format) => {
527
+ if (state) state.event.value = printd(format, new FixedDate(String(state.event.value ?? "")));
528
+ };
529
+ host.fetch = void 0;
530
+ host.XMLHttpRequest = void 0;
531
+ host.WebSocket = void 0;
532
+ }
533
+ /** The exact self-contained source evaluated in Node parity tests and QuickJS. */
534
+ const PRELUDE_SOURCE = `(${installAcroJs.toString()})(globalThis);`;
535
+ //#endregion
536
+ //#region src/types.ts
537
+ const DEFAULT_SCRIPT_BUDGET = Object.freeze({
538
+ maxExecutionMs: 50,
539
+ maxMemoryBytes: 16 * 1024 * 1024,
540
+ maxStackBytes: 512 * 1024,
541
+ maxEffects: 256,
542
+ maxOutputBytes: 1024 * 1024
543
+ });
544
+ const DEFAULT_SCRIPT_SECURITY_POLICY = Object.freeze({
545
+ enabled: false,
546
+ executionOwner: "originating-client-only",
547
+ nameTreeBoot: "lazy-first-transaction",
548
+ submitForm: "blocked",
549
+ openAction: "preserve-only",
550
+ pageActions: "preserve-only",
551
+ catalogLifecycleActions: "preserve-only",
552
+ annotationActions: "widget-activate-only"
553
+ });
554
+ /** Frozen V1 dispatch matrix; extracted actions outside it remain data only. */
555
+ const SCRIPT_EVENT_MATRIX = Object.freeze({
556
+ nameTree: "lazy-first-originating-field-transaction",
557
+ field: Object.freeze({
558
+ keystroke: "execute-on-commit",
559
+ validate: "execute",
560
+ calculate: "execute-in-calculation-order",
561
+ format: "execute-after-value-calculation"
562
+ }),
563
+ openAction: "preserve-only",
564
+ page: "preserve-only",
565
+ catalogLifecycle: "preserve-only",
566
+ annotation: Object.freeze({
567
+ widgetActivate: "execute-on-originating-client",
568
+ other: "preserve-only"
569
+ }),
570
+ submitForm: "blocked"
571
+ });
572
+ //#endregion
573
+ exports.DEFAULT_SCRIPT_BUDGET = DEFAULT_SCRIPT_BUDGET;
574
+ exports.DEFAULT_SCRIPT_SECURITY_POLICY = DEFAULT_SCRIPT_SECURITY_POLICY;
575
+ exports.PRELUDE_SOURCE = PRELUDE_SOURCE;
576
+ exports.SCRIPT_EVENT_MATRIX = SCRIPT_EVENT_MATRIX;
577
+ exports.installAcroJs = installAcroJs;
578
+ exports.javaScriptProgramFromActionTree = javaScriptProgramFromActionTree;
579
+ exports.javaScriptSourcesFromActionTree = javaScriptSourcesFromActionTree;
580
+ exports.scriptFieldsFromSnapshot = scriptFieldsFromSnapshot;
581
+
582
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","names":[],"sources":["../src/actions.ts","../src/input.ts","../src/prelude.ts","../src/types.ts"],"sourcesContent":["import type { PdfActionNode, PdfActionTree } from '@embedpdf/engine-core/runtime';\n\n/**\n * Return executable JavaScript in PDF action order (root, then `/Next`\n * depth-first). A poisoned native snapshot is never partially executed.\n */\nexport function javaScriptSourcesFromActionTree(tree: PdfActionTree): string[] {\n if (tree.incomplete) {\n throw new Error('Refusing to execute an incomplete PDF action tree');\n }\n\n const sources: string[] = [];\n const visit = (node: PdfActionNode): void => {\n if (node.type === 'javascript' && node.script !== undefined) sources.push(node.script);\n for (const child of node.next) visit(child);\n };\n if (tree.root) visit(tree.root);\n return sources;\n}\n\n/** One event source that preserves the tree's shared field overlay. */\nexport function javaScriptProgramFromActionTree(tree: PdfActionTree): string {\n return javaScriptSourcesFromActionTree(tree).join('\\n;\\n');\n}\n","import type {\n FormFieldDTO,\n FormFieldFamily,\n FormSnapshot,\n FormValueEntry,\n} from '@embedpdf/engine-core/runtime';\n\nimport type { ScriptFieldInput, ScriptValue } from './types';\n\nfunction valueFromEntry(entry: FormValueEntry): ScriptValue {\n switch (entry.kind) {\n case 'scalar':\n return entry.value;\n case 'array':\n return [...entry.values];\n case 'none':\n case 'unsupported':\n return null;\n }\n}\n\nfunction fieldValueFromEntry(family: FormFieldFamily, entry: FormValueEntry): ScriptValue {\n if ((family === 'checkbox' || family === 'radio') && entry.kind === 'none') return 'Off';\n return valueFromEntry(entry);\n}\n\n/** Build the VM's detached field view from the engine's lossless snapshot. */\nexport function scriptFieldsFromSnapshot(snapshot: FormSnapshot): ScriptFieldInput[] {\n return snapshot.fields.map((field: FormFieldDTO) => ({\n ref: field.ref,\n name: field.name,\n family: field.family,\n value: fieldValueFromEntry(field.family, field.valueEntry),\n defaultValue: fieldValueFromEntry(field.family, field.defaultValueEntry),\n // Form DTOs do not yet aggregate widget visibility; annotation joins may\n // override this when the orchestrator has that plane loaded.\n display: 'visible',\n readOnly: field.flags.readOnly,\n required: field.flags.required,\n ...('options' in field\n ? { options: field.options.map((option) => ({ label: option.label, value: option.value })) }\n : {}),\n }));\n}\n","/**\n * Install the curated Acrobat object model into an isolated JavaScript realm.\n *\n * This function must remain self-contained: no imports and no closed-over\n * values. The sandbox ships `installAcroJs.toString()` into QuickJS, while\n * tests execute the same source in a Node VM. Types disappear at build time.\n */\nexport function installAcroJs(g: Record<string, unknown>): void {\n type AnyRecord = Record<string, unknown>;\n type FieldRecord = {\n input: AnyRecord;\n originalValue: unknown;\n value: unknown;\n originalDisplay: string;\n display: string;\n wrapper: AnyRecord;\n };\n type RunState = {\n input: AnyRecord;\n fields: FieldRecord[];\n fieldsByName: Map<string, FieldRecord>;\n fieldsByRef: Map<string, FieldRecord>;\n event: AnyRecord;\n resetRefs: AnyRecord[];\n resetKeys: Set<string>;\n uiEffects: AnyRecord[];\n diagnostics: AnyRecord[];\n randomState: number;\n maxEffects: number;\n };\n\n const host = g as AnyRecord;\n const NativeDate = Date;\n let state: RunState | null = null;\n\n const cloneValue = (value: unknown): unknown =>\n Array.isArray(value) ? value.map((item) => String(item)) : value;\n const sameValue = (a: unknown, b: unknown): boolean => {\n if (Array.isArray(a) && Array.isArray(b)) {\n return a.length === b.length && a.every((item, index) => item === b[index]);\n }\n return a === b;\n };\n const refKey = (ref: unknown): string => {\n const value = ref as AnyRecord | null | undefined;\n return value?.kind === 'objectNumber'\n ? `obj:${String(value.fieldObjectNumber)}`\n : `fqn:${String(value?.name ?? '')}`;\n };\n const diagnostic = (code: string, message: string): void => {\n state?.diagnostics.push({ code, message });\n };\n const blocked = (api: string): undefined => {\n diagnostic('blocked-network', `${api} is blocked by the scripting policy`);\n return undefined;\n };\n const numberValue = (value: unknown): number => {\n if (typeof value === 'number') return Number.isFinite(value) ? value : 0;\n const parsed = Number(String(value ?? '').replace(/[^0-9+\\-.]/g, ''));\n return Number.isFinite(parsed) ? parsed : 0;\n };\n const displayToCode = (display: string): number =>\n display === 'hidden' ? 1 : display === 'noPrint' ? 2 : display === 'noView' ? 3 : 0;\n const codeToDisplay = (code: unknown): string =>\n Number(code) === 1\n ? 'hidden'\n : Number(code) === 2\n ? 'noPrint'\n : Number(code) === 3\n ? 'noView'\n : 'visible';\n const eventName = (kind: string): string =>\n kind === 'widget-activate'\n ? 'Mouse Up'\n : kind === 'field-keystroke'\n ? 'Keystroke'\n : kind === 'field-validate'\n ? 'Validate'\n : kind === 'field-calculate'\n ? 'Calculate'\n : kind === 'field-format'\n ? 'Format'\n : 'Open';\n\n const doc: AnyRecord = {};\n\n const makeField = (record: FieldRecord): AnyRecord => {\n const input = record.input;\n const wrapper: AnyRecord = {};\n Object.defineProperties(wrapper, {\n name: { enumerable: true, get: () => input.name },\n type: { enumerable: true, get: () => input.family },\n value: {\n enumerable: true,\n get: () => cloneValue(record.value),\n set: (value: unknown) => {\n record.value = cloneValue(value);\n },\n },\n valueAsString: {\n enumerable: true,\n get: () =>\n Array.isArray(record.value) ? record.value.join(',') : String(record.value ?? ''),\n },\n defaultValue: { enumerable: true, get: () => cloneValue(input.defaultValue) },\n readonly: {\n enumerable: true,\n get: () => Boolean(input.readOnly),\n set: () => {\n diagnostic('unsupported-api', 'Field.readonly writes are not supported in v1');\n },\n },\n required: {\n enumerable: true,\n get: () => Boolean(input.required),\n set: () => {\n diagnostic('unsupported-api', 'Field.required writes are not supported in v1');\n },\n },\n display: {\n enumerable: true,\n get: () => displayToCode(record.display),\n set: (value: unknown) => {\n record.display = codeToDisplay(value);\n },\n },\n source: { enumerable: false, get: () => doc },\n });\n wrapper.setFocus = () => diagnostic('unsupported-api', 'Field.setFocus is not supported in v1');\n return wrapper;\n };\n\n const getField = (name: unknown): AnyRecord | null =>\n state?.fieldsByName.get(String(name))?.wrapper ?? null;\n\n Object.defineProperties(doc, {\n documentFileName: {\n enumerable: true,\n get: () => String((state?.input.document as AnyRecord | undefined)?.fileName ?? ''),\n },\n numFields: { enumerable: true, get: () => state?.fields.length ?? 0 },\n pageNum: {\n enumerable: true,\n get: () => Number((state?.input.document as AnyRecord | undefined)?.pageNumber ?? 0),\n set: (value: unknown) => {\n const page = Math.trunc(Number(value));\n if (Number.isFinite(page)) state?.uiEffects.push({ kind: 'gotoPage', page });\n },\n },\n });\n doc.getField = getField;\n doc.getNthFieldName = (index: unknown) =>\n String(state?.fields[Math.trunc(Number(index))]?.input.name ?? '');\n doc.resetForm = (names?: unknown) => {\n if (!state) return;\n const requested =\n names === undefined\n ? state.fields\n : (Array.isArray(names) ? names : [names])\n .map((name) => state!.fieldsByName.get(String(name)))\n .filter((field): field is FieldRecord => field !== undefined);\n for (const field of requested) {\n field.value = cloneValue(field.input.defaultValue);\n const key = refKey(field.input.ref);\n if (!state.resetKeys.has(key)) {\n state.resetKeys.add(key);\n state.resetRefs.push(field.input.ref as AnyRecord);\n }\n }\n };\n doc.print = () => state?.uiEffects.push({ kind: 'print' });\n doc.submitForm = () => blocked('submitForm');\n doc.mailDoc = () => blocked('mailDoc');\n doc.getURL = () => blocked('getURL');\n\n const app = {\n // Viewer identity — the properties Adobe's ubiquitous version-check\n // boilerplate (`!ADBE::…VersChk…` name-tree scripts) branches on. Honest\n // values for an emulated modern-Reader-level environment, so those\n // scripts take their \"viewer is current\" paths instead of tripping over\n // `undefined`. Deliberately NO `xfa_installed`: we never claim XFA.\n platform: 'WIN',\n language: 'ENU',\n viewerType: 'Reader',\n viewerVariation: 'Reader',\n viewerVersion: 21,\n formsVersion: 21,\n alert: (message: unknown, icon?: unknown, _type?: unknown, title?: unknown): number => {\n state?.uiEffects.push({\n kind: 'alert',\n message: String(message),\n icon: Number.isFinite(Number(icon)) ? Number(icon) : 0,\n ...(title === undefined ? {} : { title: String(title) }),\n });\n return 1;\n },\n beep: () => diagnostic('unsupported-api', 'app.beep is not supported in v1'),\n response: () => {\n diagnostic('unsupported-api', 'app.response is not supported in v1');\n return null;\n },\n launchURL: () => blocked('app.launchURL'),\n // Acrobat's contract when a viewer component (e.g. the XFA plugin) is not\n // available is `undefined` — NEVER a throw. A web viewer has no\n // installable components, so \"not available\" is always the truthful\n // answer; Adobe's XFA-check boilerplate calls this after its upgrade nag.\n findComponent: (): undefined => {\n diagnostic('unsupported-api', 'app.findComponent: no installable components in this viewer');\n return undefined;\n },\n };\n\n const pad = (value: number, length = 2): string => String(value).padStart(length, '0');\n const monthShort = [\n 'Jan',\n 'Feb',\n 'Mar',\n 'Apr',\n 'May',\n 'Jun',\n 'Jul',\n 'Aug',\n 'Sep',\n 'Oct',\n 'Nov',\n 'Dec',\n ];\n const monthLong = [\n 'January',\n 'February',\n 'March',\n 'April',\n 'May',\n 'June',\n 'July',\n 'August',\n 'September',\n 'October',\n 'November',\n 'December',\n ];\n const printd = (format: unknown, inputDate: unknown): string => {\n const environment = (state?.input.environment ?? {}) as AnyRecord;\n const date =\n inputDate && typeof (inputDate as AnyRecord).getTime === 'function'\n ? new NativeDate(Number((inputDate as { getTime(): number }).getTime()))\n : new NativeDate(Number(environment.nowMs ?? 0));\n const local = new NativeDate(\n date.getTime() + Number(environment.utcOffsetMinutes ?? 0) * 60000,\n );\n const year = local.getUTCFullYear();\n const month = local.getUTCMonth();\n const day = local.getUTCDate();\n const hour = local.getUTCHours();\n const minute = local.getUTCMinutes();\n const second = local.getUTCSeconds();\n const tokens: Record<string, string> = {\n yyyy: String(year),\n yy: pad(year % 100),\n mmmm: monthLong[month],\n mmm: monthShort[month],\n mm: pad(month + 1),\n m: String(month + 1),\n dd: pad(day),\n d: String(day),\n HH: pad(hour),\n H: String(hour),\n MM: pad(minute),\n M: String(minute),\n ss: pad(second),\n };\n return String(format).replace(\n /yyyy|mmmm|mmm|yy|mm|dd|HH|MM|ss|m|d|H|M/g,\n (token) => tokens[token],\n );\n };\n const util = {\n printd,\n printf: (format: unknown, ...values: unknown[]): string => {\n let index = 0;\n return String(format).replace(/%(?:,?\\d*(?:\\.\\d+)?)?[dfs]/g, (token) => {\n const value = values[index++];\n if (token.endsWith('s')) return String(value ?? '');\n if (token.endsWith('d')) return String(Math.trunc(numberValue(value)));\n const precision = /\\.(\\d+)/.exec(token)?.[1];\n return numberValue(value).toFixed(precision ? Number(precision) : 0);\n });\n },\n };\n\n const begin = (input: AnyRecord, budget?: AnyRecord): void => {\n const fields: FieldRecord[] = ((input.fields as AnyRecord[] | undefined) ?? []).map((field) => {\n const record: FieldRecord = {\n input: field,\n originalValue: cloneValue(field.value),\n value: cloneValue(field.value),\n originalDisplay: String(field.display ?? 'visible'),\n display: String(field.display ?? 'visible'),\n wrapper: {},\n };\n record.wrapper = makeField(record);\n return record;\n });\n const fieldsByName = new Map(fields.map((field) => [String(field.input.name), field]));\n const fieldsByRef = new Map(fields.map((field) => [refKey(field.input.ref), field]));\n const eventInput = (input.event ?? {}) as AnyRecord;\n const target = fieldsByRef.get(refKey(eventInput.target));\n const source = fieldsByRef.get(refKey(eventInput.source));\n const initialValue =\n eventInput.value !== undefined\n ? cloneValue(eventInput.value)\n : cloneValue(target?.value ?? null);\n const event: AnyRecord = {\n name: eventName(String(eventInput.kind ?? '')),\n type: eventInput.kind === 'name-tree-boot' ? 'Doc' : 'Field',\n target: target?.wrapper ?? null,\n targetName: String(target?.input.name ?? ''),\n source: source?.wrapper ?? { source: doc },\n value: initialValue,\n change: String(eventInput.change ?? ''),\n selStart: Math.max(0, Math.trunc(Number(eventInput.selStart ?? 0))),\n selEnd: Math.max(0, Math.trunc(Number(eventInput.selEnd ?? 0))),\n willCommit: Boolean(eventInput.willCommit),\n modifier: Boolean(eventInput.modifier),\n shift: Boolean(eventInput.shift),\n rc: true,\n };\n state = {\n input,\n fields,\n fieldsByName,\n fieldsByRef,\n event,\n resetRefs: [],\n resetKeys: new Set(),\n uiEffects: [],\n diagnostics: [],\n randomState: Number((input.environment as AnyRecord | undefined)?.randomSeed ?? 1) >>> 0,\n maxEffects: Math.max(1, Math.trunc(Number(budget?.maxEffects ?? 256))),\n };\n host.event = event;\n host.identity = { ...((input.identity as AnyRecord | undefined) ?? {}) };\n };\n\n const formValue = (field: FieldRecord, value: unknown): AnyRecord | null => {\n const family = String(field.input.family);\n if (family === 'text') return { type: 'text', value: String(value ?? '') };\n if (family === 'checkbox' || family === 'radio') {\n const token =\n value === null || value === undefined || String(value) === 'Off' ? null : String(value);\n return { type: 'toggle', state: token };\n }\n if (family === 'combobox') {\n const selected = Array.isArray(value) ? value.slice(0, 1).map(String) : [String(value ?? '')];\n return { type: 'choice', values: selected };\n }\n if (family === 'listbox') {\n return {\n type: 'choice',\n values: Array.isArray(value) ? value.map(String) : [String(value ?? '')],\n };\n }\n diagnostic(\n 'invalid-field-value',\n `field '${String(field.input.name)}' cannot accept a scripted value`,\n );\n return null;\n };\n\n const eventOutput = (): AnyRecord => ({\n rc: Boolean(state?.event.rc),\n value: cloneValue(state?.event.value ?? null),\n change: String(state?.event.change ?? ''),\n selStart: Math.max(0, Math.trunc(Number(state?.event.selStart ?? 0))),\n selEnd: Math.max(0, Math.trunc(Number(state?.event.selEnd ?? 0))),\n });\n\n const finish = (): AnyRecord => {\n if (!state) throw new Error('AcroJS run state was not initialized');\n const eventInput = state.input.event as AnyRecord;\n const target = state.fieldsByRef.get(refKey(eventInput.target));\n const kind = String(eventInput.kind ?? '');\n if (target && kind === 'field-calculate') target.value = cloneValue(state.event.value);\n\n const formEffects: AnyRecord[] = [];\n if (state.resetRefs.length > 0) formEffects.push({ kind: 'reset', refs: [...state.resetRefs] });\n for (const field of state.fields) {\n const key = refKey(field.input.ref);\n // A reset effect is replayed before the value effects below, so reset\n // fields start from their default rather than the transaction input.\n // This preserves reset -> rewrite-to-original sequences.\n const valueBaseline = state.resetKeys.has(key)\n ? field.input.defaultValue\n : field.originalValue;\n if (!sameValue(field.value, valueBaseline)) {\n const value = formValue(field, field.value);\n if (value) formEffects.push({ kind: 'setValue', ref: field.input.ref, value });\n }\n if (field.display !== field.originalDisplay) {\n formEffects.push({ kind: 'setDisplay', ref: field.input.ref, display: field.display });\n }\n }\n if (target && kind === 'field-format') {\n formEffects.push({\n kind: 'setAppearanceText',\n ref: target.input.ref,\n text: String(state.event.value ?? ''),\n });\n }\n const totalEffects = formEffects.length + state.uiEffects.length;\n if (totalEffects > state.maxEffects) {\n return {\n event: eventOutput(),\n formEffects: [],\n uiEffects: [],\n diagnostics: [...state.diagnostics],\n error: {\n kind: 'budget',\n message: `script produced ${totalEffects} effects; limit is ${state.maxEffects}`,\n },\n };\n }\n return {\n event: eventOutput(),\n formEffects,\n uiEffects: [...state.uiEffects],\n diagnostics: [...state.diagnostics],\n };\n };\n\n const failed = (error: unknown): AnyRecord => ({\n event: eventOutput(),\n formEffects: [],\n uiEffects: [],\n diagnostics: [...(state?.diagnostics ?? [])],\n error: {\n kind: 'exception',\n message: error instanceof Error ? error.message : String(error),\n ...(error instanceof Error && error.stack ? { stack: error.stack } : {}),\n },\n });\n\n const evaluate = (source: string): unknown => {\n // Indirect eval is deliberate: name-tree declarations must persist in the\n // isolated realm's global scope for later field events.\n return (0, eval)(source);\n };\n\n const boot = (sources: unknown, input: unknown, budget?: unknown): AnyRecord => {\n begin(input as AnyRecord, budget as AnyRecord | undefined);\n try {\n for (const source of (sources as unknown[]) ?? []) evaluate(String(source));\n return finish();\n } catch (error) {\n return failed(error);\n }\n };\n const run = (source: unknown, input: unknown, budget?: unknown): AnyRecord => {\n begin(input as AnyRecord, budget as AnyRecord | undefined);\n try {\n evaluate(String(source));\n return finish();\n } catch (error) {\n return failed(error);\n }\n };\n\n // PDF scripts share this realm, but they must not replace the host-owned\n // transaction boundary for later events in the same document.\n Object.defineProperties(host, {\n __acrojsBoot: { configurable: false, writable: false, value: boot },\n __acrojsRun: { configurable: false, writable: false, value: run },\n });\n\n host.app = app;\n host.util = util;\n host.display = Object.freeze({ visible: 0, hidden: 1, noPrint: 2, noView: 3 });\n host.getField = getField;\n host.resetForm = doc.resetForm;\n host.print = doc.print;\n host.submitForm = doc.submitForm;\n host.mailDoc = doc.mailDoc;\n host.getURL = doc.getURL;\n Object.defineProperties(host, {\n documentFileName: { configurable: true, get: () => doc.documentFileName },\n numFields: { configurable: true, get: () => doc.numFields },\n pageNum: {\n configurable: true,\n get: () => doc.pageNum,\n set: (value: unknown) => {\n doc.pageNum = value;\n },\n },\n });\n\n class FixedDate extends NativeDate {\n constructor(...args: unknown[]) {\n if (args.length === 0) {\n super(Number(((state?.input.environment ?? {}) as AnyRecord).nowMs ?? 0));\n } else if (args.length === 1) {\n super(args[0] as string | number);\n } else {\n super(\n Number(args[0]),\n Number(args[1]),\n Number(args[2] ?? 1),\n Number(args[3] ?? 0),\n Number(args[4] ?? 0),\n Number(args[5] ?? 0),\n Number(args[6] ?? 0),\n );\n }\n }\n static now(): number {\n return Number(((state?.input.environment ?? {}) as AnyRecord).nowMs ?? 0);\n }\n }\n host.Date = FixedDate;\n\n const math = host.Math as Math | undefined;\n if (math) {\n math.random = () => {\n if (!state) return 0;\n state.randomState = (1664525 * state.randomState + 1013904223) >>> 0;\n return state.randomState / 0x100000000;\n };\n }\n\n host.AFSimple_Calculate = (operation: unknown, names: unknown): void => {\n const requested = Array.isArray(names) ? names : String(names).split(',');\n const values = requested.map((name) => numberValue(getField(String(name).trim())?.value));\n const op = String(operation).toUpperCase();\n const value =\n values.length === 0\n ? 0\n : op === 'PRD'\n ? values.reduce((a, b) => a * b, 1)\n : op === 'AVG'\n ? values.reduce((a, b) => a + b, 0) / values.length\n : op === 'MIN'\n ? Math.min(...values)\n : op === 'MAX'\n ? Math.max(...values)\n : values.reduce((a, b) => a + b, 0);\n if (state) state.event.value = value;\n };\n host.AFNumber_Format = (\n decimals: unknown,\n separatorStyle: unknown,\n _negativeStyle: unknown,\n _currencyStyle: unknown,\n currency: unknown,\n prepend: unknown,\n ): void => {\n if (!state) return;\n const places = Math.max(0, Math.min(10, Math.trunc(Number(decimals))));\n let formatted = numberValue(state.event.value).toFixed(places);\n if (Number(separatorStyle) === 0 || Number(separatorStyle) === 2) {\n const [whole, fraction] = formatted.split('.');\n formatted = `${whole.replace(/\\B(?=(\\d{3})+(?!\\d))/g, ',')}${fraction === undefined ? '' : `.${fraction}`}`;\n }\n const symbol = String(currency ?? '');\n state.event.value = prepend ? `${symbol}${formatted}` : `${formatted}${symbol}`;\n };\n host.AFPercent_Format = (decimals: unknown): void => {\n if (!state) return;\n const places = Math.max(0, Math.min(10, Math.trunc(Number(decimals))));\n state.event.value = `${(numberValue(state.event.value) * 100).toFixed(places)}%`;\n };\n host.AFDate_FormatEx = (format: unknown): void => {\n if (state) state.event.value = printd(format, new FixedDate(String(state.event.value ?? '')));\n };\n\n // QuickJS does not provide browser networking, but explicitly shadow these\n // names so a future adapter cannot accidentally inject ambient authority.\n host.fetch = undefined;\n host.XMLHttpRequest = undefined;\n host.WebSocket = undefined;\n}\n\n/** The exact self-contained source evaluated in Node parity tests and QuickJS. */\nexport const PRELUDE_SOURCE = `(${installAcroJs.toString()})(globalThis);`;\n","import type {\n FormEffect,\n FormFieldDisplay,\n FormFieldFamily,\n FormFieldRef,\n} from '@embedpdf/engine-core/runtime';\n\n/** JSON-safe value vocabulary exposed through Acrobat's `event` and `Field`. */\nexport type ScriptValue = string | number | boolean | null | string[];\n\nexport interface ScriptFieldOption {\n label: string;\n value: string;\n}\n\n/** Detached field state supplied to one script transaction. */\nexport interface ScriptFieldInput {\n ref: FormFieldRef;\n name: string;\n family: FormFieldFamily;\n value: ScriptValue;\n defaultValue: ScriptValue;\n display: FormFieldDisplay;\n readOnly: boolean;\n required: boolean;\n options?: ScriptFieldOption[];\n}\n\nexport interface ScriptIdentity {\n /** Acrobat `identity.name`. Empty when the embedder did not configure it. */\n name: string;\n loginName: string;\n corporation: string;\n email: string;\n}\n\nexport interface ScriptDocumentInput {\n id: string;\n fileName: string;\n pageCount: number;\n /** Zero-based current page, matching Acrobat `this.pageNum`. */\n pageNumber: number;\n}\n\n/** Required deterministic environment. `utcOffsetMinutes` is local minus UTC. */\nexport interface ScriptEnvironment {\n nowMs: number;\n utcOffsetMinutes: number;\n randomSeed: number;\n}\n\nexport type ScriptEventKind =\n | 'name-tree-boot'\n | 'widget-activate'\n | 'field-keystroke'\n | 'field-validate'\n | 'field-calculate'\n | 'field-format';\n\nexport interface ScriptEventInput {\n kind: ScriptEventKind;\n target?: FormFieldRef;\n source?: FormFieldRef;\n value?: ScriptValue;\n change?: string;\n selStart?: number;\n selEnd?: number;\n willCommit?: boolean;\n modifier?: boolean;\n shift?: boolean;\n}\n\n/** Complete input for one deterministic run. No ambient host values are read. */\nexport interface ScriptInput {\n document: ScriptDocumentInput;\n identity: ScriptIdentity;\n environment: ScriptEnvironment;\n fields: ScriptFieldInput[];\n event: ScriptEventInput;\n}\n\nexport type ScriptUiEffect =\n | { kind: 'alert'; message: string; icon: number; title?: string }\n | { kind: 'print' }\n | { kind: 'gotoPage'; page: number };\n\nexport type ScriptDiagnosticCode =\n | 'blocked-network'\n | 'unsupported-api'\n | 'invalid-field-value'\n // A document-level script failed and was degraded to a warning (a boot\n // script error must never disable interactive filling).\n | 'script-error';\n\nexport interface ScriptDiagnostic {\n code: ScriptDiagnosticCode;\n message: string;\n}\n\nexport interface ScriptExecutionError {\n kind: 'exception' | 'budget' | 'invalid-output';\n message: string;\n stack?: string;\n}\n\nexport interface ScriptEventOutput {\n rc: boolean;\n value: ScriptValue;\n change: string;\n selStart: number;\n selEnd: number;\n}\n\n/** Effects are committed only by the originating client's orchestrator. */\nexport interface ScriptOutput {\n event: ScriptEventOutput;\n formEffects: FormEffect[];\n uiEffects: ScriptUiEffect[];\n diagnostics: ScriptDiagnostic[];\n error?: ScriptExecutionError;\n}\n\nexport interface ScriptBudget {\n maxExecutionMs: number;\n maxMemoryBytes: number;\n maxStackBytes: number;\n maxEffects: number;\n maxOutputBytes: number;\n}\n\nexport const DEFAULT_SCRIPT_BUDGET: Readonly<ScriptBudget> = Object.freeze({\n maxExecutionMs: 50,\n maxMemoryBytes: 16 * 1024 * 1024,\n maxStackBytes: 512 * 1024,\n maxEffects: 256,\n maxOutputBytes: 1024 * 1024,\n});\n\n/** V1 security posture. The only configurable switch is explicit opt-in. */\nexport interface ScriptSecurityPolicy {\n enabled: boolean;\n executionOwner: 'originating-client-only';\n nameTreeBoot: 'lazy-first-transaction';\n submitForm: 'blocked';\n openAction: 'preserve-only';\n pageActions: 'preserve-only';\n catalogLifecycleActions: 'preserve-only';\n annotationActions: 'widget-activate-only';\n}\n\nexport const DEFAULT_SCRIPT_SECURITY_POLICY: Readonly<ScriptSecurityPolicy> = Object.freeze({\n enabled: false,\n executionOwner: 'originating-client-only',\n nameTreeBoot: 'lazy-first-transaction',\n submitForm: 'blocked',\n openAction: 'preserve-only',\n pageActions: 'preserve-only',\n catalogLifecycleActions: 'preserve-only',\n annotationActions: 'widget-activate-only',\n});\n\n/** Frozen V1 dispatch matrix; extracted actions outside it remain data only. */\nexport const SCRIPT_EVENT_MATRIX = Object.freeze({\n nameTree: 'lazy-first-originating-field-transaction',\n field: Object.freeze({\n keystroke: 'execute-on-commit',\n validate: 'execute',\n calculate: 'execute-in-calculation-order',\n format: 'execute-after-value-calculation',\n }),\n openAction: 'preserve-only',\n page: 'preserve-only',\n catalogLifecycle: 'preserve-only',\n annotation: Object.freeze({\n widgetActivate: 'execute-on-originating-client',\n other: 'preserve-only',\n }),\n submitForm: 'blocked',\n} as const);\n\n/** Functions installed into the isolated VM global by `PRELUDE_SOURCE`. */\nexport interface AcroJsVmGlobal {\n __acrojsBoot(\n sources: string[],\n input: ScriptInput,\n budget?: Pick<ScriptBudget, 'maxEffects'>,\n ): ScriptOutput;\n __acrojsRun(\n source: string,\n input: ScriptInput,\n budget?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