@embedpdf/plugin-actions 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.
@@ -1 +1 @@
1
- {"version":3,"file":"host.cjs","names":["PublicActionsToken"],"sources":["../../src/host-contract.ts"],"sourcesContent":["/** Host-typed actions token and registration protocol for sibling plugins. */\nimport type { CapabilityToken } from '@embedpdf/core';\n\nimport { ActionsToken as PublicActionsToken } from './types';\nimport type { ActionsHostCapability } from './types';\n\nexport const ActionsToken = PublicActionsToken as CapabilityToken<ActionsHostCapability>;\nexport type {\n ActionExecutor,\n ActionExecutorResult,\n ActionsHostCapability,\n ActionSubmitRequest,\n AnnotCommitEntry,\n AnnotCommitResult,\n AnnotCommitSink,\n FormCommitSink,\n PageStateReport,\n ScriptSurfaceResult,\n SubmitIntent,\n SubmitResolver,\n} from './types';\n"],"mappings":";;AAMA,MAAa,8CAAeA,CAAAA,CAAAA"}
1
+ {"version":3,"file":"host.cjs","names":["PublicActionsToken"],"sources":["../../src/host-contract.ts"],"sourcesContent":["/** Host-typed actions token and registration protocol for sibling plugins. */\nimport type { CapabilityToken } from '@embedpdf/core';\n\nimport { ActionsToken as PublicActionsToken } from './types';\nimport type { ActionsHostCapability } from './types';\n\nexport const ActionsToken = PublicActionsToken as CapabilityToken<ActionsHostCapability>;\nexport type {\n ActionExecutor,\n ActionExecutorResult,\n ActionsHostCapability,\n ActionSubmitRequest,\n AnnotCommitEntry,\n AnnotCommitResult,\n AnnotCommitSink,\n DetachedScriptRealm,\n FormCommitSink,\n PageStateReport,\n ScriptCommitSurface,\n ScriptRealmKind,\n ScriptRealmPort,\n ScriptRealmTarget,\n ScriptSurfaceResult,\n SubmitIntent,\n SubmitResolver,\n} from './types';\n"],"mappings":";;AAMA,MAAa,8CAAeA,CAAAA,CAAAA"}
@@ -1,7 +1,7 @@
1
- import { C as ActionsHostCapability, D as AnnotCommitEntry, F as SubmitIntent, I as SubmitResolver, M as PageStateReport, O as AnnotCommitResult, P as ScriptSurfaceResult, a as ActionExecutor, g as ActionSubmitRequest, j as FormCommitSink, k as AnnotCommitSink, o as ActionExecutorResult } from "../types-DRQReAuO.cjs";
1
+ import { A as DetachedScriptRealm, B as SubmitIntent, C as ActionsHostCapability, D as AnnotCommitEntry, F as ScriptCommitSurface, I as ScriptRealmKind, L as ScriptRealmPort, M as FormCommitSink, N as PageStateReport, O as AnnotCommitResult, R as ScriptRealmTarget, V as SubmitResolver, a as ActionExecutor, g as ActionSubmitRequest, k as AnnotCommitSink, o as ActionExecutorResult, z as ScriptSurfaceResult } from "../types-D-DoiESj.cjs";
2
2
  import { CapabilityToken } from "@embedpdf/core";
3
3
  //#region src/host-contract.d.ts
4
4
  declare const ActionsToken: CapabilityToken<ActionsHostCapability>;
5
5
  //#endregion
6
- export { type ActionExecutor, type ActionExecutorResult, type ActionSubmitRequest, type ActionsHostCapability, ActionsToken, type AnnotCommitEntry, type AnnotCommitResult, type AnnotCommitSink, type FormCommitSink, type PageStateReport, type ScriptSurfaceResult, type SubmitIntent, type SubmitResolver };
6
+ export { type ActionExecutor, type ActionExecutorResult, type ActionSubmitRequest, type ActionsHostCapability, ActionsToken, type AnnotCommitEntry, type AnnotCommitResult, type AnnotCommitSink, type DetachedScriptRealm, type FormCommitSink, type PageStateReport, type ScriptCommitSurface, type ScriptRealmKind, type ScriptRealmPort, type ScriptRealmTarget, type ScriptSurfaceResult, type SubmitIntent, type SubmitResolver };
7
7
  //# sourceMappingURL=host.d.cts.map
@@ -1,7 +1,7 @@
1
- import { C as ActionsHostCapability, D as AnnotCommitEntry, F as SubmitIntent, I as SubmitResolver, M as PageStateReport, O as AnnotCommitResult, P as ScriptSurfaceResult, a as ActionExecutor, g as ActionSubmitRequest, j as FormCommitSink, k as AnnotCommitSink, o as ActionExecutorResult } from "../types-DRQReAuO.js";
1
+ import { A as DetachedScriptRealm, B as SubmitIntent, C as ActionsHostCapability, D as AnnotCommitEntry, F as ScriptCommitSurface, I as ScriptRealmKind, L as ScriptRealmPort, M as FormCommitSink, N as PageStateReport, O as AnnotCommitResult, R as ScriptRealmTarget, V as SubmitResolver, a as ActionExecutor, g as ActionSubmitRequest, k as AnnotCommitSink, o as ActionExecutorResult, z as ScriptSurfaceResult } from "../types-D-DoiESj.js";
2
2
  import { CapabilityToken } from "@embedpdf/core";
3
3
  //#region src/host-contract.d.ts
4
4
  declare const ActionsToken: CapabilityToken<ActionsHostCapability>;
5
5
  //#endregion
6
- export { type ActionExecutor, type ActionExecutorResult, type ActionSubmitRequest, type ActionsHostCapability, ActionsToken, type AnnotCommitEntry, type AnnotCommitResult, type AnnotCommitSink, type FormCommitSink, type PageStateReport, type ScriptSurfaceResult, type SubmitIntent, type SubmitResolver };
6
+ export { type ActionExecutor, type ActionExecutorResult, type ActionSubmitRequest, type ActionsHostCapability, ActionsToken, type AnnotCommitEntry, type AnnotCommitResult, type AnnotCommitSink, type DetachedScriptRealm, type FormCommitSink, type PageStateReport, type ScriptCommitSurface, type ScriptRealmKind, type ScriptRealmPort, type ScriptRealmTarget, type ScriptSurfaceResult, type SubmitIntent, type SubmitResolver };
7
7
  //# sourceMappingURL=host.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"host.js","names":["PublicActionsToken"],"sources":["../../src/host-contract.ts"],"sourcesContent":["/** Host-typed actions token and registration protocol for sibling plugins. */\nimport type { CapabilityToken } from '@embedpdf/core';\n\nimport { ActionsToken as PublicActionsToken } from './types';\nimport type { ActionsHostCapability } from './types';\n\nexport const ActionsToken = PublicActionsToken as CapabilityToken<ActionsHostCapability>;\nexport type {\n ActionExecutor,\n ActionExecutorResult,\n ActionsHostCapability,\n ActionSubmitRequest,\n AnnotCommitEntry,\n AnnotCommitResult,\n AnnotCommitSink,\n FormCommitSink,\n PageStateReport,\n ScriptSurfaceResult,\n SubmitIntent,\n SubmitResolver,\n} from './types';\n"],"mappings":";;AAMA,MAAa,eAAeA"}
1
+ {"version":3,"file":"host.js","names":["PublicActionsToken"],"sources":["../../src/host-contract.ts"],"sourcesContent":["/** Host-typed actions token and registration protocol for sibling plugins. */\nimport type { CapabilityToken } from '@embedpdf/core';\n\nimport { ActionsToken as PublicActionsToken } from './types';\nimport type { ActionsHostCapability } from './types';\n\nexport const ActionsToken = PublicActionsToken as CapabilityToken<ActionsHostCapability>;\nexport type {\n ActionExecutor,\n ActionExecutorResult,\n ActionsHostCapability,\n ActionSubmitRequest,\n AnnotCommitEntry,\n AnnotCommitResult,\n AnnotCommitSink,\n DetachedScriptRealm,\n FormCommitSink,\n PageStateReport,\n ScriptCommitSurface,\n ScriptRealmKind,\n ScriptRealmPort,\n ScriptRealmTarget,\n ScriptSurfaceResult,\n SubmitIntent,\n SubmitResolver,\n} from './types';\n"],"mappings":";;AAMA,MAAa,eAAeA"}
@@ -1,4 +1,4 @@
1
- import { _ as ActionTrigger, p as ActionSource, v as ActionTriggerResult } from "./types-DRQReAuO.js";
1
+ import { _ as ActionTrigger, p as ActionSource, v as ActionTriggerResult } from "./types-D-DoiESj.js";
2
2
  import { AnnotationRef, FormSubmissionEntry, PageObjectNumber } from "@embedpdf/engine-core/runtime";
3
3
  //#region src/hover-pump.d.ts
4
4
  /** One hoverable target, as a feed sees it. `events` lets a feed that KNOWS
@@ -47,4 +47,4 @@ declare function createHoverPump(dispatch: (trigger: ActionTrigger) => Promise<A
47
47
  declare const submitEntriesToUrlEncoded: (entries: FormSubmissionEntry[]) => string;
48
48
  //#endregion
49
49
  export { createHoverPump as i, HoverPump as n, HoverTarget as r, submitEntriesToUrlEncoded as t };
50
- //# sourceMappingURL=contract-Cl-f3d61.d.ts.map
50
+ //# sourceMappingURL=contract-COk-w3Fo.d.ts.map
@@ -1,4 +1,4 @@
1
- import { _ as ActionTrigger, p as ActionSource, v as ActionTriggerResult } from "./types-DRQReAuO.cjs";
1
+ import { _ as ActionTrigger, p as ActionSource, v as ActionTriggerResult } from "./types-D-DoiESj.cjs";
2
2
  import { AnnotationRef, FormSubmissionEntry, PageObjectNumber } from "@embedpdf/engine-core/runtime";
3
3
  //#region src/hover-pump.d.ts
4
4
  /** One hoverable target, as a feed sees it. `events` lets a feed that KNOWS
@@ -47,4 +47,4 @@ declare function createHoverPump(dispatch: (trigger: ActionTrigger) => Promise<A
47
47
  declare const submitEntriesToUrlEncoded: (entries: FormSubmissionEntry[]) => string;
48
48
  //#endregion
49
49
  export { createHoverPump as i, HoverPump as n, HoverTarget as r, submitEntriesToUrlEncoded as t };
50
- //# sourceMappingURL=contract-KaJQWh67.d.cts.map
50
+ //# sourceMappingURL=contract-Os5y4NaD.d.cts.map
@@ -1,3 +1,3 @@
1
- import { A as DocumentTriggerEvent, E as ActionsToken, F as SubmitIntent, L as originOf, N as PdfAnnotationEventKind, S as ActionsCapability, _ as ActionTrigger, b as ActionUiContext, c as ActionNodeStatus, d as ActionPolicyDecision, f as ActionPolicyRow, g as ActionSubmitRequest, h as ActionSubmitHandler, i as ActionDispatchResult, l as ActionOrigin, m as ActionStepResult, n as ActionDiagnostic, p as ActionSource, r as ActionDispatchEvent, s as ActionNodeResult, t as ActionContext, u as ActionPolicy, v as ActionTriggerResult, w as ActionsPluginConfig, y as ActionUiAdapter } from "./types-DRQReAuO.cjs";
2
- import { i as createHoverPump, n as HoverPump, r as HoverTarget, t as submitEntriesToUrlEncoded } from "./contract-KaJQWh67.cjs";
1
+ import { B as SubmitIntent, E as ActionsToken, H as originOf, P as PdfAnnotationEventKind, S as ActionsCapability, _ as ActionTrigger, b as ActionUiContext, c as ActionNodeStatus, d as ActionPolicyDecision, f as ActionPolicyRow, g as ActionSubmitRequest, h as ActionSubmitHandler, i as ActionDispatchResult, j as DocumentTriggerEvent, l as ActionOrigin, m as ActionStepResult, n as ActionDiagnostic, p as ActionSource, r as ActionDispatchEvent, s as ActionNodeResult, t as ActionContext, u as ActionPolicy, v as ActionTriggerResult, w as ActionsPluginConfig, y as ActionUiAdapter } from "./types-D-DoiESj.cjs";
2
+ import { i as createHoverPump, n as HoverPump, r as HoverTarget, t as submitEntriesToUrlEncoded } from "./contract-Os5y4NaD.cjs";
3
3
  export { type ActionContext, type ActionDiagnostic, type ActionDispatchEvent, type ActionDispatchResult, type ActionNodeResult, type ActionNodeStatus, type ActionOrigin, type ActionPolicy, type ActionPolicyDecision, type ActionPolicyRow, type ActionSource, type ActionStepResult, type ActionSubmitHandler, type ActionSubmitRequest, type ActionTrigger, type ActionTriggerResult, type ActionUiAdapter, type ActionUiContext, type ActionsCapability, type ActionsPluginConfig, ActionsToken, type DocumentTriggerEvent, type HoverPump, type HoverTarget, type PdfAnnotationEventKind, type SubmitIntent, createHoverPump, originOf, submitEntriesToUrlEncoded };
@@ -1,3 +1,3 @@
1
- import { A as DocumentTriggerEvent, E as ActionsToken, F as SubmitIntent, L as originOf, N as PdfAnnotationEventKind, S as ActionsCapability, _ as ActionTrigger, b as ActionUiContext, c as ActionNodeStatus, d as ActionPolicyDecision, f as ActionPolicyRow, g as ActionSubmitRequest, h as ActionSubmitHandler, i as ActionDispatchResult, l as ActionOrigin, m as ActionStepResult, n as ActionDiagnostic, p as ActionSource, r as ActionDispatchEvent, s as ActionNodeResult, t as ActionContext, u as ActionPolicy, v as ActionTriggerResult, w as ActionsPluginConfig, y as ActionUiAdapter } from "./types-DRQReAuO.js";
2
- import { i as createHoverPump, n as HoverPump, r as HoverTarget, t as submitEntriesToUrlEncoded } from "./contract-Cl-f3d61.js";
1
+ import { B as SubmitIntent, E as ActionsToken, H as originOf, P as PdfAnnotationEventKind, S as ActionsCapability, _ as ActionTrigger, b as ActionUiContext, c as ActionNodeStatus, d as ActionPolicyDecision, f as ActionPolicyRow, g as ActionSubmitRequest, h as ActionSubmitHandler, i as ActionDispatchResult, j as DocumentTriggerEvent, l as ActionOrigin, m as ActionStepResult, n as ActionDiagnostic, p as ActionSource, r as ActionDispatchEvent, s as ActionNodeResult, t as ActionContext, u as ActionPolicy, v as ActionTriggerResult, w as ActionsPluginConfig, y as ActionUiAdapter } from "./types-D-DoiESj.js";
2
+ import { i as createHoverPump, n as HoverPump, r as HoverTarget, t as submitEntriesToUrlEncoded } from "./contract-COk-w3Fo.js";
3
3
  export { type ActionContext, type ActionDiagnostic, type ActionDispatchEvent, type ActionDispatchResult, type ActionNodeResult, type ActionNodeStatus, type ActionOrigin, type ActionPolicy, type ActionPolicyDecision, type ActionPolicyRow, type ActionSource, type ActionStepResult, type ActionSubmitHandler, type ActionSubmitRequest, type ActionTrigger, type ActionTriggerResult, type ActionUiAdapter, type ActionUiContext, type ActionsCapability, type ActionsPluginConfig, ActionsToken, type DocumentTriggerEvent, type HoverPump, type HoverTarget, type PdfAnnotationEventKind, type SubmitIntent, createHoverPump, originOf, submitEntriesToUrlEncoded };
package/dist/index.cjs CHANGED
@@ -3,6 +3,38 @@ const require_types = require("./types-BXJLAKXi.cjs");
3
3
  const require_contract = require("./contract-C1K3H4RP.cjs");
4
4
  let _embedpdf_core = require("@embedpdf/core");
5
5
  let _embedpdf_core_acrojs = require("@embedpdf/core-acrojs");
6
+ //#region src/script-environment.ts
7
+ function createScriptRealmFactory(js, identityDoc) {
8
+ const sandboxFactory = js.sandboxFactory ?? (() => import("@embedpdf/core-js-sandbox").then(({ createQuickJsSandbox }) => createQuickJsSandbox()));
9
+ const budget = js.budget ?? _embedpdf_core_acrojs.DEFAULT_SCRIPT_BUDGET;
10
+ return {
11
+ budget,
12
+ realmFor: (target) => (0, _embedpdf_core_acrojs.createScriptHost)({
13
+ sandboxFactory,
14
+ document: () => {
15
+ const meta = target.document();
16
+ return {
17
+ id: target.doc.id,
18
+ fileName: js.fileName?.() ?? meta?.name ?? "document.pdf",
19
+ pageCount: meta?.pageCount ?? 0,
20
+ pageNumber: 0
21
+ };
22
+ },
23
+ identity: () => (0, _embedpdf_core_acrojs.resolveScriptIdentity)(identityDoc, js.identity),
24
+ environment: (sequence) => {
25
+ const nowMs = js.now?.() ?? Date.now();
26
+ return {
27
+ nowMs,
28
+ utcOffsetMinutes: js.utcOffsetMinutes?.() ?? -new Date(nowMs).getTimezoneOffset(),
29
+ randomSeed: js.randomSeed?.() ?? (0, _embedpdf_core_acrojs.seedFrom)(target.doc.id, sequence)
30
+ };
31
+ },
32
+ bootSources: target.bootSources,
33
+ budget
34
+ })
35
+ };
36
+ }
37
+ //#endregion
6
38
  //#region src/capability.ts
7
39
  const ALLOW_ALL = {
8
40
  user: "allow",
@@ -226,35 +258,13 @@ function createActionsCapability(ctx, config = {}) {
226
258
  };
227
259
  };
228
260
  const js = config.javascript;
229
- const scriptHost = js?.enabled && ctx.doc ? (0, _embedpdf_core_acrojs.createScriptHost)({
230
- sandboxFactory: js.sandboxFactory ?? (() => import("@embedpdf/core-js-sandbox").then(({ createQuickJsSandbox }) => createQuickJsSandbox())),
231
- document: () => {
232
- const meta = ctx.document();
233
- return {
234
- id: ctx.documentId ?? "document",
235
- fileName: js.fileName?.() ?? meta?.name ?? "document.pdf",
236
- pageCount: meta?.pageCount ?? 0,
237
- pageNumber: 0
238
- };
239
- },
240
- identity: () => ctx.doc ? (0, _embedpdf_core_acrojs.resolveScriptIdentity)(ctx.doc, js.identity) : {
241
- name: "",
242
- loginName: "",
243
- corporation: "",
244
- email: ""
245
- },
246
- environment: (sequence) => {
247
- const nowMs = js.now?.() ?? Date.now();
248
- return {
249
- nowMs,
250
- utcOffsetMinutes: js.utcOffsetMinutes?.() ?? -new Date(nowMs).getTimezoneOffset(),
251
- randomSeed: js.randomSeed?.() ?? (0, _embedpdf_core_acrojs.seedFrom)(ctx.documentId ?? "document", sequence)
252
- };
253
- },
261
+ const realms = js?.enabled && ctx.doc ? createScriptRealmFactory(js, ctx.doc) : null;
262
+ const scriptHost = realms && ctx.doc ? realms.realmFor({
263
+ doc: ctx.doc,
264
+ document: () => ctx.document(),
254
265
  bootSources: async () => {
255
266
  return ((await readDocumentActions())?.nameTreeScripts ?? []).map(({ action }) => (0, _embedpdf_core_acrojs.javaScriptProgramFromActionTree)(action));
256
- },
257
- ...js.budget ? { budget: js.budget } : {}
267
+ }
258
268
  }) : null;
259
269
  if (scriptHost) ctx.cleanup(() => scriptHost.dispose());
260
270
  const surfaceScriptResult = (result) => {
@@ -263,6 +273,13 @@ function createActionsCapability(ctx, config = {}) {
263
273
  phase: result.phase
264
274
  };
265
275
  for (const effect of result.uiEffects) {
276
+ if (result.realm === "detached" && effect.kind !== "alert") {
277
+ scriptDiagnosticHook.emit({
278
+ code: "ui-effect-suppressed",
279
+ message: `script ${effect.kind} request from a detached realm suppressed: no document surface`
280
+ });
281
+ continue;
282
+ }
266
283
  if (effect.kind === "submitForm") {
267
284
  performSubmit(intentOfSubmitEffect(effect), {
268
285
  origin: result.origin,
@@ -303,6 +320,23 @@ function createActionsCapability(ctx, config = {}) {
303
320
  for (const diagnostic of result.diagnostics) scriptDiagnosticHook.emit(diagnostic);
304
321
  if (result.error) scriptErrorHook.emit(result.error);
305
322
  };
323
+ /** A K/V/C/F commit surfaces as up to two results: the boot phase (only
324
+ * when it produced effects) and the user phase (always — it carries the
325
+ * diagnostics and the error). */
326
+ const surfaceScriptCommit = (commit, context) => {
327
+ for (const phase of ["boot", "user"]) {
328
+ const uiEffects = commit.uiEffects.filter((effect) => effect.phase === phase);
329
+ if (uiEffects.length === 0 && phase === "boot") continue;
330
+ surfaceScriptResult({
331
+ uiEffects,
332
+ diagnostics: phase === "user" ? commit.diagnostics : [],
333
+ ...phase === "user" && commit.error ? { error: commit.error } : {},
334
+ origin: context.origin,
335
+ phase,
336
+ realm: context.realm
337
+ });
338
+ }
339
+ };
306
340
  /** Script `doc.submitForm(...)` → the one normalized intent. Script field
307
341
  * names are include-mode by definition (Acrobat's aFields). */
308
342
  const intentOfSubmitEffect = (effect) => {
@@ -499,7 +533,8 @@ function createActionsCapability(ctx, config = {}) {
499
533
  diagnostics: boot.diagnostics,
500
534
  ...boot.error ? { error: boot.error } : {},
501
535
  origin: actionCtx.origin,
502
- phase: "boot"
536
+ phase: "boot",
537
+ realm: "document"
503
538
  });
504
539
  if (boot.formEffects.length || boot.annotEffects.length) built = await scriptWorldFor(pon);
505
540
  }
@@ -512,7 +547,8 @@ function createActionsCapability(ctx, config = {}) {
512
547
  diagnostics: output.diagnostics,
513
548
  ...output.error ? { error: output.error } : {},
514
549
  origin: actionCtx.origin,
515
- phase: "user"
550
+ phase: "user",
551
+ realm: "document"
516
552
  });
517
553
  if (output.error) return {
518
554
  status: "failed",
@@ -1336,8 +1372,22 @@ function createActionsCapability(ctx, config = {}) {
1336
1372
  if (formCommitSink === sink) formCommitSink = null;
1337
1373
  };
1338
1374
  },
1339
- ...scriptHost ? { scriptTransaction: (body) => scriptHost.transaction(body) } : {},
1375
+ ...scriptHost && realms ? {
1376
+ scriptRealm: {
1377
+ transaction: (body) => scriptHost.transaction(body),
1378
+ budget: realms.budget
1379
+ },
1380
+ createDetachedScriptRealm: (target) => {
1381
+ const host = realms.realmFor(target);
1382
+ return {
1383
+ transaction: (body) => host.transaction(body),
1384
+ budget: realms.budget,
1385
+ dispose: () => host.dispose()
1386
+ };
1387
+ }
1388
+ } : {},
1340
1389
  surfaceScriptResult,
1390
+ surfaceScriptCommit,
1341
1391
  reportPageState,
1342
1392
  registerSubmitResolver: (resolver) => {
1343
1393
  submitResolver = resolver;