@embedpdf/plugin-redaction 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/README.md +66 -24
- package/dist/contract-Ib0iOWF3.cjs +43 -0
- package/dist/contract-Ib0iOWF3.cjs.map +1 -0
- package/dist/contract-TU9orxrO.d.cts +184 -0
- package/dist/contract-TU9orxrO.d.ts +184 -0
- package/dist/contract-eQ3P0UU-.js +33 -0
- package/dist/contract-eQ3P0UU-.js.map +1 -0
- package/dist/contract.cjs +2 -1
- package/dist/contract.d.cts +2 -2
- package/dist/contract.d.ts +2 -2
- package/dist/contract.js +2 -2
- package/dist/index.cjs +455 -190
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +26 -9
- package/dist/index.d.ts +26 -9
- package/dist/index.js +455 -192
- package/dist/index.js.map +1 -1
- package/package.json +7 -6
- package/dist/contract--fJOCVRN.d.cts +0 -84
- package/dist/contract--fJOCVRN.d.ts +0 -84
- package/dist/contract-BZLrD3p2.js +0 -7
- package/dist/contract-BZLrD3p2.js.map +0 -1
- package/dist/contract-CyLm5eeQ.cjs +0 -11
- package/dist/contract-CyLm5eeQ.cjs.map +0 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @embedpdf/plugin-redaction
|
|
2
2
|
|
|
3
|
-
Redaction for EmbedPDF
|
|
3
|
+
Redaction for EmbedPDF — mark content for removal, review the pending
|
|
4
4
|
marks, then destroy the content permanently.
|
|
5
5
|
|
|
6
6
|
Redaction is a **two-stage** workflow (ISO 32000-2):
|
|
@@ -9,7 +9,7 @@ Redaction is a **two-stage** workflow (ISO 32000-2):
|
|
|
9
9
|
redaction mark is a real `redact` annotation: it renders, selects,
|
|
10
10
|
syncs, and deletes like any other annotation, and nothing is removed
|
|
11
11
|
yet. You don't need this plugin to mark — the `redact` tool ships with
|
|
12
|
-
`@embedpdf/plugin-annotation
|
|
12
|
+
`@embedpdf/plugin-annotation` — but it adds marking verbs for code.
|
|
13
13
|
2. **Applying** is destructive and is what this plugin wraps: the content
|
|
14
14
|
under every marked region is permanently removed, the configured
|
|
15
15
|
overlay (fill + label) is painted in its place, and the consumed marks
|
|
@@ -37,7 +37,15 @@ const plugins = [
|
|
|
37
37
|
|
|
38
38
|
Requires `plugin-annotation`. With `plugin-selection` and
|
|
39
39
|
`plugin-interaction` present (the usual viewer setup), the marking tool
|
|
40
|
-
and `
|
|
40
|
+
and `markSelection()` light up too; `markMatches()` needs `plugin-search`.
|
|
41
|
+
|
|
42
|
+
`redactionPlugin({ overlay })` sets what applying paints over every mark,
|
|
43
|
+
whichever way it was made (the `redact` tool, the selected text, or code):
|
|
44
|
+
`overlay.fill` is the colour painted on apply (default black) and
|
|
45
|
+
`overlay.text` styles the label (`color`, default white; `fontFamily`,
|
|
46
|
+
default Helvetica; `fontSize`, where the default 0 fits the area). The
|
|
47
|
+
settings become the redact tool's defaults, and `redaction.updateSettings()`
|
|
48
|
+
changes them for the marks made from then on.
|
|
41
49
|
|
|
42
50
|
## Marking
|
|
43
51
|
|
|
@@ -46,16 +54,29 @@ text marks the selected text (per-line quads, like a highlight), and
|
|
|
46
54
|
dragging anywhere else marks a rectangular area. One tool, both modes.
|
|
47
55
|
|
|
48
56
|
```ts
|
|
49
|
-
|
|
57
|
+
import { useInteraction, useInteractionState } from '@embedpdf/react/interaction';
|
|
58
|
+
import { useRedaction } from '@embedpdf/react/redaction';
|
|
59
|
+
|
|
60
|
+
const redaction = useRedaction();
|
|
61
|
+
const interaction = useInteraction();
|
|
62
|
+
const { activeToolId } = useInteractionState();
|
|
50
63
|
|
|
51
|
-
|
|
52
|
-
|
|
64
|
+
interaction.activateTool('redact'); // arm the redact tool
|
|
65
|
+
activeToolId === 'redact';
|
|
53
66
|
|
|
54
67
|
// Mark the current text selection without switching tools
|
|
55
68
|
// (context-menu "Mark for Redaction"):
|
|
56
|
-
await redaction.
|
|
69
|
+
const { marks } = await redaction.markSelection();
|
|
70
|
+
|
|
71
|
+
// Or mark from code (page space; a page is a ref or an index):
|
|
72
|
+
const { mark } = await redaction.markArea(page, { x: 72, y: 72, width: 200, height: 40 });
|
|
73
|
+
await redaction.markPage(0);
|
|
74
|
+
await redaction.markMatches({ text: 'Confidential' }); // every search hit: { marks }
|
|
57
75
|
```
|
|
58
76
|
|
|
77
|
+
`canMark()` is annotation create authority: a mark is an ordinary
|
|
78
|
+
annotation, so anyone who can annotate can propose redactions.
|
|
79
|
+
|
|
59
80
|
Marks carry their appearance: `color` (marking outline), `interiorColor`
|
|
60
81
|
(the fill painted on apply), and an optional label (`/OverlayText`)
|
|
61
82
|
styled by `fontFamily`/`fontSize`/`fontColor`/`textAlign` with
|
|
@@ -63,9 +84,12 @@ styled by `fontFamily`/`fontSize`/`fontColor`/`textAlign` with
|
|
|
63
84
|
normal annotation style panel; the label text itself:
|
|
64
85
|
|
|
65
86
|
```ts
|
|
66
|
-
redaction.
|
|
87
|
+
const { mark } = await redaction.updateLabel(ref, { overlayText: 'REDACTED', repeat: true });
|
|
67
88
|
```
|
|
68
89
|
|
|
90
|
+
`canUnmark(ref)` and `canUpdateLabel(ref)` answer per mark, as the
|
|
91
|
+
annotation's own delete and update checks do.
|
|
92
|
+
|
|
69
93
|
## The pending queue
|
|
70
94
|
|
|
71
95
|
Pending marks are **not plugin state** — they are a live view over the
|
|
@@ -73,37 +97,55 @@ annotation plane (`subtype === 'redact'`). Deleting a mark is just
|
|
|
73
97
|
deleting an annotation.
|
|
74
98
|
|
|
75
99
|
```ts
|
|
76
|
-
redaction.
|
|
77
|
-
redaction.
|
|
78
|
-
redaction.
|
|
79
|
-
|
|
80
|
-
//
|
|
100
|
+
redaction.listPending(); // RedactionMark[] — ref, page, pageIndex, kind: 'area' | 'text', bounds, overlayText, repeat
|
|
101
|
+
redaction.listPending({ page }); // one page's marks
|
|
102
|
+
redaction.getPending(ref); // one mark, or null
|
|
103
|
+
redaction.getPendingCount();
|
|
104
|
+
redaction.estimateCollateral(); // { count, refs }: a client-side estimate of the
|
|
105
|
+
// other annotations the pending marks would destroy — show
|
|
106
|
+
// this in your confirm dialog before applying
|
|
107
|
+
|
|
108
|
+
await redaction.unmark([ref]); // remove marks; refs that are not marks are skipped, refused ones fail
|
|
109
|
+
await redaction.clearPending(); // remove every mark
|
|
110
|
+
|
|
111
|
+
redaction.onPendingChanged(({ pages }) => {
|
|
112
|
+
/* marks were created, changed or removed on these pages */
|
|
113
|
+
});
|
|
81
114
|
```
|
|
82
115
|
|
|
83
116
|
## Applying
|
|
84
117
|
|
|
85
118
|
```ts
|
|
86
|
-
// Everything
|
|
119
|
+
// Everything in the document, including marks on pages this client never loaded:
|
|
87
120
|
const result = await redaction.applyAll();
|
|
88
|
-
|
|
89
|
-
// Or
|
|
90
|
-
const result = await redaction.apply([id1, id2]);
|
|
121
|
+
// Or specific marks: await redaction.apply([ref1, ref2]);
|
|
122
|
+
// Or the marks on pages: await redaction.applyPages([page]);
|
|
91
123
|
|
|
92
124
|
result.removedAnnotationCount; // authoritative collateral count
|
|
93
125
|
result.results; // per-page applied/unchanged/failed/skipped
|
|
94
126
|
|
|
95
|
-
redaction.onApplied((result) => {
|
|
127
|
+
redaction.onApplied(({ result, origin }) => {
|
|
96
128
|
/* toast, audit, ... */
|
|
97
129
|
});
|
|
98
130
|
```
|
|
99
131
|
|
|
100
|
-
`apply` resolves after the engine confirms.
|
|
101
|
-
(content-scope invalidation)
|
|
102
|
-
automatically — including when a
|
|
103
|
-
document. On a document whose token
|
|
104
|
-
`
|
|
132
|
+
`apply` resolves after the engine confirms. Applies run one at a time,
|
|
133
|
+
in call order. Affected pages re-rasterize (content-scope invalidation)
|
|
134
|
+
and their annotation lists reload automatically — including when a
|
|
135
|
+
**collaborator** applies on a shared document. On a document whose token
|
|
136
|
+
lacks `doc.redact` (or `doc.pages.modify` and `doc.annotate.modify`, which
|
|
137
|
+
apply also asserts), `canApply()` is false and `apply` rejects with
|
|
138
|
+
`permission-denied`; without an engine redaction service it rejects with
|
|
139
|
+
`unsupported`.
|
|
105
140
|
|
|
106
141
|
```ts
|
|
107
|
-
redaction.canApply(); // engine service present
|
|
142
|
+
redaction.canApply(); // engine service present and every apply capability granted
|
|
108
143
|
redaction.isApplying(); // in-flight state for spinners
|
|
144
|
+
redaction.getLastResult(); // the last confirmed apply, from this session or another
|
|
109
145
|
```
|
|
146
|
+
|
|
147
|
+
In React, `useRedaction()` is the capability, `useRedactionState()` reads
|
|
148
|
+
`{ pendingCount, applying, lastResult }`, `usePendingRedactions(filter?)` is
|
|
149
|
+
the reactive pending list, `useRedactionSettings()` the settings, and
|
|
150
|
+
`useRedactionEvent((redaction) => redaction.onApplied, handler)` subscribes
|
|
151
|
+
for the mounted lifetime — all from `@embedpdf/react/redaction`.
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
//#region src/token.ts
|
|
2
|
+
/** The package token, created once here and re-exported by `contract.ts`. */
|
|
3
|
+
const RedactionToken = (0, require("@embedpdf/core").createCapabilityToken)("redaction", {
|
|
4
|
+
hint: `add redactionPlugin() from '@embedpdf/plugin-redaction' to your plugins list`,
|
|
5
|
+
promises: {
|
|
6
|
+
markSelection: true,
|
|
7
|
+
markArea: true,
|
|
8
|
+
markPage: true,
|
|
9
|
+
markMatches: true,
|
|
10
|
+
unmark: true,
|
|
11
|
+
clearPending: true,
|
|
12
|
+
updateLabel: true,
|
|
13
|
+
apply: true,
|
|
14
|
+
applyAll: true,
|
|
15
|
+
applyPages: true
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region src/contract.ts
|
|
20
|
+
/** What the redaction settings are when the app registers none. */
|
|
21
|
+
const REDACTION_DEFAULTS = { overlay: {
|
|
22
|
+
fill: "#000000",
|
|
23
|
+
text: {
|
|
24
|
+
color: "#ffffff",
|
|
25
|
+
fontFamily: "helvetica",
|
|
26
|
+
fontSize: 0
|
|
27
|
+
}
|
|
28
|
+
} };
|
|
29
|
+
//#endregion
|
|
30
|
+
Object.defineProperty(exports, "REDACTION_DEFAULTS", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function() {
|
|
33
|
+
return REDACTION_DEFAULTS;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
Object.defineProperty(exports, "RedactionToken", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function() {
|
|
39
|
+
return RedactionToken;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
//# sourceMappingURL=contract-Ib0iOWF3.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract-Ib0iOWF3.cjs","names":[],"sources":["../src/token.ts","../src/contract.ts"],"sourcesContent":["/** The package token, created once here and re-exported by `contract.ts`. */\nimport { createCapabilityToken } from '@embedpdf/core';\n\nimport type { RedactionCapability } from './contract';\n\nexport const RedactionToken = createCapabilityToken<RedactionCapability>('redaction', {\n hint: `add redactionPlugin() from '@embedpdf/plugin-redaction' to your plugins list`,\n // Without a document, an adapter's stand-in rejects these with `not-ready`, as the\n // capability would; the type asks for every member that returns a promise.\n promises: {\n markSelection: true,\n markArea: true,\n markPage: true,\n markMatches: true,\n unmark: true,\n clearPending: true,\n updateLabel: true,\n apply: true,\n applyAll: true,\n applyPages: true,\n },\n});\n","/**\n * @embedpdf/plugin-redaction/contract: the public redaction vocabulary.\n * Marking is annotation authoring (a mark is a `redact` annotation); applying\n * is the destructive document mutation. The plugin owns no mark state: the\n * pending view is a live projection of the annotation plane.\n */\nimport type {\n BatchResult,\n DeepPartial,\n EventHook,\n EventOrigin,\n OperationOptions,\n SettingsApi,\n} from '@embedpdf/core';\nimport type { Rect } from '@embedpdf/core-geometry';\nimport type {\n AnnotationRef,\n FreeTextFont,\n PageRef,\n RedactionApplyResult,\n SearchQuery,\n} from '@embedpdf/engine-core';\n\nexport { RedactionToken } from './token';\nexport type { RedactionApplyResult } from '@embedpdf/engine-core';\n\n/**\n * The redaction plugin's settings. `redactionPlugin(config)` registers them\n * over {@link REDACTION_DEFAULTS}, and `updateSettings()` changes them for\n * every document while the app runs. They are PDF colors and fonts, written\n * into each mark, so CSS doesn't reach them.\n */\nexport interface RedactionSettings {\n /**\n * What applying paints over every mark, whichever way it was made: the\n * `redact` tool, the selected text, or code. They are the redact tool's\n * defaults from then on; a style panel can still change one mark.\n */\n readonly overlay: {\n /** The color of a redacted area. */\n readonly fill: string;\n readonly text: {\n /** The color of a label. */\n readonly color: string;\n /** The label's font: a standard font or a registered one. */\n readonly fontFamily: FreeTextFont;\n /** The label's size in points; `0` fits it to the area. */\n readonly fontSize: number;\n };\n };\n}\n\n/** What the redaction settings are when the app registers none. */\nexport const REDACTION_DEFAULTS: RedactionSettings = {\n overlay: {\n fill: '#000000',\n text: { color: '#ffffff', fontFamily: 'helvetica', fontSize: 0 },\n },\n};\n\n/** What `redactionPlugin(config)` takes: any of the settings, merged over the defaults. */\nexport type RedactionConfig = DeepPartial<RedactionSettings>;\n\n/**\n * One pending redaction mark — a live projection of a `redact` annotation on\n * the annotation plane (delete the annotation and the mark is gone).\n */\nexport interface RedactionMark {\n readonly ref: AnnotationRef;\n readonly page: PageRef;\n /** Display index (0-based) from the page registry — for \"page N\" labels. */\n readonly pageIndex: number;\n /** `area` = rect-only mark (marquee); `text` = per-line quads (selection). */\n readonly kind: 'area' | 'text';\n /** Page-space bounds of the region. */\n readonly bounds: Rect;\n /** `/OverlayText` label, when set. */\n readonly overlayText: string | null;\n /** Whether the label fills the area over and over, or shows once. */\n readonly repeat: boolean;\n}\n\nexport interface RedactionMarkFilter {\n /** One page's marks: its ref or its index. */\n readonly page?: PageRef | number;\n}\n\n/** A label edit: `overlayText: null` clears it; `repeat` tiles it. */\nexport interface RedactionLabelPatch {\n overlayText?: string | null;\n repeat?: boolean;\n}\n\n/** Which other annotations an apply would destroy (a client-side estimate; the result is authoritative). */\nexport interface RedactionCollateral {\n readonly count: number;\n readonly refs: readonly AnnotationRef[];\n}\n\n// ── events ──\n/** A confirmed apply, from this session or another. */\nexport interface RedactionAppliedEvent {\n readonly result: RedactionApplyResult;\n readonly origin: EventOrigin;\n}\n/** Marks were created, changed or removed on these pages. */\nexport interface RedactionPendingChangedEvent {\n readonly pages: readonly PageRef[];\n}\n\n/**\n * Redaction for one document: marking (a mark is a `redact` annotation), the\n * pending marks, and applying them, which can't be undone. A page argument\n * is a ref or an index: a read given a page that isn't there answers empty,\n * a verb refuses it with `not-found`. Every async verb takes a `signal`. The\n * settings belong to the plugin, not to a document.\n */\nexport interface RedactionCapability extends SettingsApi<RedactionSettings> {\n /**\n * Whether marking is allowed. Marking and applying are different powers: a\n * mark is an ordinary `redact` annotation, so this is annotation create\n * authority (matches Acrobat: any reviewer who can annotate can propose\n * redactions).\n */\n canMark(): boolean;\n /** Whether this mark may be removed before it's applied: it is a mark, and may be deleted (`annotations:delete`). */\n canUnmark(ref: AnnotationRef): boolean;\n /** Whether this mark's label may change: it is a mark, and may be changed (`annotations:update`). */\n canUpdateLabel(ref: AnnotationRef): boolean;\n /**\n * Whether applying is allowed: the engine has a redaction service and every\n * capability its apply asserts is granted (`doc.redact`, `doc.pages.modify`,\n * `doc.annotate.modify`).\n */\n canApply(): boolean;\n /** An apply of this session is running at the engine. */\n isApplying(): boolean;\n /** The last confirmed apply result, from this session or another. */\n getLastResult(): RedactionApplyResult | null;\n\n // ── the pending view ──\n /** Pending marks in page order, or one page's. Reference-stable while unchanged. */\n listPending(filter?: RedactionMarkFilter): readonly RedactionMark[];\n getPending(ref: AnnotationRef): RedactionMark | null;\n /** How many marks wait to be applied, in the document or on one page. */\n getPendingCount(page?: PageRef | number): number;\n /** Which other annotations applying these marks (default: all) would destroy. */\n estimateCollateral(refs?: readonly AnnotationRef[]): RedactionCollateral;\n\n // ── marking ──\n // Every marking verb rejects `permission-denied` without annotation create\n // authority (see `canMark`). Marks take the `overlay` settings.\n /**\n * Mark the current text selection (one mark per page) and clear it.\n * Resolves `{ marks }`, empty without a selection; rejects `unsupported`\n * without the selection plugin.\n */\n markSelection(options?: OperationOptions): Promise<{ marks: readonly RedactionMark[] }>;\n /** Mark a page-space rectangle. Resolves `{ mark }`; rejects `not-found` for a page that isn't there. */\n markArea(\n page: PageRef | number,\n bounds: Rect,\n options?: OperationOptions,\n ): Promise<{ mark: RedactionMark }>;\n /** Mark a whole page. Resolves `{ mark }`; rejects `not-found` for a page that isn't there. */\n markPage(page: PageRef | number, options?: OperationOptions): Promise<{ mark: RedactionMark }>;\n /**\n * Mark every match of a search, or the ones on some pages. Runs the query\n * through the search plugin, so it replaces the user's current search.\n * Resolves `{ marks }`, one per match; rejects `unsupported` without the\n * search plugin.\n */\n markMatches(\n query: SearchQuery,\n options?: { pages?: readonly (PageRef | number)[] } & OperationOptions,\n ): Promise<{ marks: readonly RedactionMark[] }>;\n /**\n * Remove marks without applying them. Refs that are not pending marks are\n * skipped; a mark this session may not delete fails with\n * `permission-denied` (see `canUnmark`).\n */\n unmark(\n refs: readonly AnnotationRef[],\n options?: OperationOptions,\n ): Promise<BatchResult<AnnotationRef, AnnotationRef>>;\n /** Remove every mark, as `unmark` does. */\n clearPending(options?: OperationOptions): Promise<BatchResult<AnnotationRef, AnnotationRef>>;\n /**\n * Set the label a mark shows once it's applied; `overlayText: null` clears\n * it. Keeps the mark's font and colors. Resolves `{ mark }`. Rejects\n * `not-found` for a ref that isn't a mark, `permission-denied` when\n * `canUpdateLabel(ref)` is false.\n */\n updateLabel(\n ref: AnnotationRef,\n patch: RedactionLabelPatch,\n options?: OperationOptions,\n ): Promise<{ mark: RedactionMark }>;\n\n // ── applying (irreversible) ──\n /**\n * Apply specific pending marks. Per-page outcomes ride the result. Applies\n * run one at a time in call order; when one resolves, `getLastResult()`\n * holds its result and `onApplied` has fired. Rejects with `not-found` when\n * none of the refs is a pending mark, `unsupported` without an engine\n * redaction service, or the engine's `permission-denied`.\n */\n apply(refs: readonly AnnotationRef[], options?: OperationOptions): Promise<RedactionApplyResult>;\n /**\n * Apply every redaction in the document, in pages scope, including marks\n * on pages this client never loaded. Rejects like `apply`, and with\n * `not-ready` when the document has no pages.\n */\n applyAll(options?: OperationOptions): Promise<RedactionApplyResult>;\n /**\n * Apply the marks on some pages. Rejects like `apply`, with\n * `invalid-input` for no pages, and `not-found` for a page that isn't there.\n */\n applyPages(\n pages: readonly (PageRef | number)[],\n options?: OperationOptions,\n ): Promise<RedactionApplyResult>;\n\n // ── events ──\n /** A confirmed apply, from this session or another; fires after `getLastResult()` changed. */\n readonly onApplied: EventHook<RedactionAppliedEvent>;\n /** Marks were created, changed or removed on some pages. */\n readonly onPendingChanged: EventHook<RedactionPendingChangedEvent>;\n}\n"],"mappings":";;AAKA,MAAa,kBAAA,2BAAA,CAAA,CAAA,sBAAA,CAA4D,aAAa;CACpF,MAAM;CAGN,UAAU;EACR,eAAe;EACf,UAAU;EACV,UAAU;EACV,aAAa;EACb,QAAQ;EACR,cAAc;EACd,aAAa;EACb,OAAO;EACP,UAAU;EACV,YAAY;CACd;AACF,CAAC;;;;ACgCD,MAAa,qBAAwC,EACnD,SAAS;CACP,MAAM;CACN,MAAM;EAAE,OAAO;EAAW,YAAY;EAAa,UAAU;CAAE;AACjE,EACF"}
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { BatchResult, DeepPartial, EventHook, EventOrigin, OperationOptions, SettingsApi } from "@embedpdf/core";
|
|
2
|
+
import { Rect } from "@embedpdf/core-geometry";
|
|
3
|
+
import { AnnotationRef, FreeTextFont, PageRef, RedactionApplyResult, RedactionApplyResult as RedactionApplyResult$1, SearchQuery } from "@embedpdf/engine-core";
|
|
4
|
+
//#region src/token.d.ts
|
|
5
|
+
declare const RedactionToken: import("@embedpdf/core").CapabilityToken<RedactionCapability>;
|
|
6
|
+
//#endregion
|
|
7
|
+
//#region src/contract.d.ts
|
|
8
|
+
/**
|
|
9
|
+
* The redaction plugin's settings. `redactionPlugin(config)` registers them
|
|
10
|
+
* over {@link REDACTION_DEFAULTS}, and `updateSettings()` changes them for
|
|
11
|
+
* every document while the app runs. They are PDF colors and fonts, written
|
|
12
|
+
* into each mark, so CSS doesn't reach them.
|
|
13
|
+
*/
|
|
14
|
+
interface RedactionSettings {
|
|
15
|
+
/**
|
|
16
|
+
* What applying paints over every mark, whichever way it was made: the
|
|
17
|
+
* `redact` tool, the selected text, or code. They are the redact tool's
|
|
18
|
+
* defaults from then on; a style panel can still change one mark.
|
|
19
|
+
*/
|
|
20
|
+
readonly overlay: {
|
|
21
|
+
/** The color of a redacted area. */
|
|
22
|
+
readonly fill: string;
|
|
23
|
+
readonly text: {
|
|
24
|
+
/** The color of a label. */
|
|
25
|
+
readonly color: string;
|
|
26
|
+
/** The label's font: a standard font or a registered one. */
|
|
27
|
+
readonly fontFamily: FreeTextFont;
|
|
28
|
+
/** The label's size in points; `0` fits it to the area. */
|
|
29
|
+
readonly fontSize: number;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/** What the redaction settings are when the app registers none. */
|
|
34
|
+
declare const REDACTION_DEFAULTS: RedactionSettings;
|
|
35
|
+
/** What `redactionPlugin(config)` takes: any of the settings, merged over the defaults. */
|
|
36
|
+
type RedactionConfig = DeepPartial<RedactionSettings>;
|
|
37
|
+
/**
|
|
38
|
+
* One pending redaction mark — a live projection of a `redact` annotation on
|
|
39
|
+
* the annotation plane (delete the annotation and the mark is gone).
|
|
40
|
+
*/
|
|
41
|
+
interface RedactionMark {
|
|
42
|
+
readonly ref: AnnotationRef;
|
|
43
|
+
readonly page: PageRef;
|
|
44
|
+
/** Display index (0-based) from the page registry — for "page N" labels. */
|
|
45
|
+
readonly pageIndex: number;
|
|
46
|
+
/** `area` = rect-only mark (marquee); `text` = per-line quads (selection). */
|
|
47
|
+
readonly kind: 'area' | 'text';
|
|
48
|
+
/** Page-space bounds of the region. */
|
|
49
|
+
readonly bounds: Rect;
|
|
50
|
+
/** `/OverlayText` label, when set. */
|
|
51
|
+
readonly overlayText: string | null;
|
|
52
|
+
/** Whether the label fills the area over and over, or shows once. */
|
|
53
|
+
readonly repeat: boolean;
|
|
54
|
+
}
|
|
55
|
+
interface RedactionMarkFilter {
|
|
56
|
+
/** One page's marks: its ref or its index. */
|
|
57
|
+
readonly page?: PageRef | number;
|
|
58
|
+
}
|
|
59
|
+
/** A label edit: `overlayText: null` clears it; `repeat` tiles it. */
|
|
60
|
+
interface RedactionLabelPatch {
|
|
61
|
+
overlayText?: string | null;
|
|
62
|
+
repeat?: boolean;
|
|
63
|
+
}
|
|
64
|
+
/** Which other annotations an apply would destroy (a client-side estimate; the result is authoritative). */
|
|
65
|
+
interface RedactionCollateral {
|
|
66
|
+
readonly count: number;
|
|
67
|
+
readonly refs: readonly AnnotationRef[];
|
|
68
|
+
}
|
|
69
|
+
/** A confirmed apply, from this session or another. */
|
|
70
|
+
interface RedactionAppliedEvent {
|
|
71
|
+
readonly result: RedactionApplyResult;
|
|
72
|
+
readonly origin: EventOrigin;
|
|
73
|
+
}
|
|
74
|
+
/** Marks were created, changed or removed on these pages. */
|
|
75
|
+
interface RedactionPendingChangedEvent {
|
|
76
|
+
readonly pages: readonly PageRef[];
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Redaction for one document: marking (a mark is a `redact` annotation), the
|
|
80
|
+
* pending marks, and applying them, which can't be undone. A page argument
|
|
81
|
+
* is a ref or an index: a read given a page that isn't there answers empty,
|
|
82
|
+
* a verb refuses it with `not-found`. Every async verb takes a `signal`. The
|
|
83
|
+
* settings belong to the plugin, not to a document.
|
|
84
|
+
*/
|
|
85
|
+
interface RedactionCapability extends SettingsApi<RedactionSettings> {
|
|
86
|
+
/**
|
|
87
|
+
* Whether marking is allowed. Marking and applying are different powers: a
|
|
88
|
+
* mark is an ordinary `redact` annotation, so this is annotation create
|
|
89
|
+
* authority (matches Acrobat: any reviewer who can annotate can propose
|
|
90
|
+
* redactions).
|
|
91
|
+
*/
|
|
92
|
+
canMark(): boolean;
|
|
93
|
+
/** Whether this mark may be removed before it's applied: it is a mark, and may be deleted (`annotations:delete`). */
|
|
94
|
+
canUnmark(ref: AnnotationRef): boolean;
|
|
95
|
+
/** Whether this mark's label may change: it is a mark, and may be changed (`annotations:update`). */
|
|
96
|
+
canUpdateLabel(ref: AnnotationRef): boolean;
|
|
97
|
+
/**
|
|
98
|
+
* Whether applying is allowed: the engine has a redaction service and every
|
|
99
|
+
* capability its apply asserts is granted (`doc.redact`, `doc.pages.modify`,
|
|
100
|
+
* `doc.annotate.modify`).
|
|
101
|
+
*/
|
|
102
|
+
canApply(): boolean;
|
|
103
|
+
/** An apply of this session is running at the engine. */
|
|
104
|
+
isApplying(): boolean;
|
|
105
|
+
/** The last confirmed apply result, from this session or another. */
|
|
106
|
+
getLastResult(): RedactionApplyResult | null;
|
|
107
|
+
/** Pending marks in page order, or one page's. Reference-stable while unchanged. */
|
|
108
|
+
listPending(filter?: RedactionMarkFilter): readonly RedactionMark[];
|
|
109
|
+
getPending(ref: AnnotationRef): RedactionMark | null;
|
|
110
|
+
/** How many marks wait to be applied, in the document or on one page. */
|
|
111
|
+
getPendingCount(page?: PageRef | number): number;
|
|
112
|
+
/** Which other annotations applying these marks (default: all) would destroy. */
|
|
113
|
+
estimateCollateral(refs?: readonly AnnotationRef[]): RedactionCollateral;
|
|
114
|
+
/**
|
|
115
|
+
* Mark the current text selection (one mark per page) and clear it.
|
|
116
|
+
* Resolves `{ marks }`, empty without a selection; rejects `unsupported`
|
|
117
|
+
* without the selection plugin.
|
|
118
|
+
*/
|
|
119
|
+
markSelection(options?: OperationOptions): Promise<{
|
|
120
|
+
marks: readonly RedactionMark[];
|
|
121
|
+
}>;
|
|
122
|
+
/** Mark a page-space rectangle. Resolves `{ mark }`; rejects `not-found` for a page that isn't there. */
|
|
123
|
+
markArea(page: PageRef | number, bounds: Rect, options?: OperationOptions): Promise<{
|
|
124
|
+
mark: RedactionMark;
|
|
125
|
+
}>;
|
|
126
|
+
/** Mark a whole page. Resolves `{ mark }`; rejects `not-found` for a page that isn't there. */
|
|
127
|
+
markPage(page: PageRef | number, options?: OperationOptions): Promise<{
|
|
128
|
+
mark: RedactionMark;
|
|
129
|
+
}>;
|
|
130
|
+
/**
|
|
131
|
+
* Mark every match of a search, or the ones on some pages. Runs the query
|
|
132
|
+
* through the search plugin, so it replaces the user's current search.
|
|
133
|
+
* Resolves `{ marks }`, one per match; rejects `unsupported` without the
|
|
134
|
+
* search plugin.
|
|
135
|
+
*/
|
|
136
|
+
markMatches(query: SearchQuery, options?: {
|
|
137
|
+
pages?: readonly (PageRef | number)[];
|
|
138
|
+
} & OperationOptions): Promise<{
|
|
139
|
+
marks: readonly RedactionMark[];
|
|
140
|
+
}>;
|
|
141
|
+
/**
|
|
142
|
+
* Remove marks without applying them. Refs that are not pending marks are
|
|
143
|
+
* skipped; a mark this session may not delete fails with
|
|
144
|
+
* `permission-denied` (see `canUnmark`).
|
|
145
|
+
*/
|
|
146
|
+
unmark(refs: readonly AnnotationRef[], options?: OperationOptions): Promise<BatchResult<AnnotationRef, AnnotationRef>>;
|
|
147
|
+
/** Remove every mark, as `unmark` does. */
|
|
148
|
+
clearPending(options?: OperationOptions): Promise<BatchResult<AnnotationRef, AnnotationRef>>;
|
|
149
|
+
/**
|
|
150
|
+
* Set the label a mark shows once it's applied; `overlayText: null` clears
|
|
151
|
+
* it. Keeps the mark's font and colors. Resolves `{ mark }`. Rejects
|
|
152
|
+
* `not-found` for a ref that isn't a mark, `permission-denied` when
|
|
153
|
+
* `canUpdateLabel(ref)` is false.
|
|
154
|
+
*/
|
|
155
|
+
updateLabel(ref: AnnotationRef, patch: RedactionLabelPatch, options?: OperationOptions): Promise<{
|
|
156
|
+
mark: RedactionMark;
|
|
157
|
+
}>;
|
|
158
|
+
/**
|
|
159
|
+
* Apply specific pending marks. Per-page outcomes ride the result. Applies
|
|
160
|
+
* run one at a time in call order; when one resolves, `getLastResult()`
|
|
161
|
+
* holds its result and `onApplied` has fired. Rejects with `not-found` when
|
|
162
|
+
* none of the refs is a pending mark, `unsupported` without an engine
|
|
163
|
+
* redaction service, or the engine's `permission-denied`.
|
|
164
|
+
*/
|
|
165
|
+
apply(refs: readonly AnnotationRef[], options?: OperationOptions): Promise<RedactionApplyResult>;
|
|
166
|
+
/**
|
|
167
|
+
* Apply every redaction in the document, in pages scope, including marks
|
|
168
|
+
* on pages this client never loaded. Rejects like `apply`, and with
|
|
169
|
+
* `not-ready` when the document has no pages.
|
|
170
|
+
*/
|
|
171
|
+
applyAll(options?: OperationOptions): Promise<RedactionApplyResult>;
|
|
172
|
+
/**
|
|
173
|
+
* Apply the marks on some pages. Rejects like `apply`, with
|
|
174
|
+
* `invalid-input` for no pages, and `not-found` for a page that isn't there.
|
|
175
|
+
*/
|
|
176
|
+
applyPages(pages: readonly (PageRef | number)[], options?: OperationOptions): Promise<RedactionApplyResult>;
|
|
177
|
+
/** A confirmed apply, from this session or another; fires after `getLastResult()` changed. */
|
|
178
|
+
readonly onApplied: EventHook<RedactionAppliedEvent>;
|
|
179
|
+
/** Marks were created, changed or removed on some pages. */
|
|
180
|
+
readonly onPendingChanged: EventHook<RedactionPendingChangedEvent>;
|
|
181
|
+
}
|
|
182
|
+
//#endregion
|
|
183
|
+
export { RedactionCollateral as a, RedactionMark as c, RedactionSettings as d, RedactionToken as f, RedactionCapability as i, RedactionMarkFilter as l, RedactionAppliedEvent as n, RedactionConfig as o, RedactionApplyResult$1 as r, RedactionLabelPatch as s, REDACTION_DEFAULTS as t, RedactionPendingChangedEvent as u };
|
|
184
|
+
//# sourceMappingURL=contract-TU9orxrO.d.cts.map
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { BatchResult, DeepPartial, EventHook, EventOrigin, OperationOptions, SettingsApi } from "@embedpdf/core";
|
|
2
|
+
import { Rect } from "@embedpdf/core-geometry";
|
|
3
|
+
import { AnnotationRef, FreeTextFont, PageRef, RedactionApplyResult, RedactionApplyResult as RedactionApplyResult$1, SearchQuery } from "@embedpdf/engine-core";
|
|
4
|
+
//#region src/token.d.ts
|
|
5
|
+
declare const RedactionToken: import("@embedpdf/core").CapabilityToken<RedactionCapability>;
|
|
6
|
+
//#endregion
|
|
7
|
+
//#region src/contract.d.ts
|
|
8
|
+
/**
|
|
9
|
+
* The redaction plugin's settings. `redactionPlugin(config)` registers them
|
|
10
|
+
* over {@link REDACTION_DEFAULTS}, and `updateSettings()` changes them for
|
|
11
|
+
* every document while the app runs. They are PDF colors and fonts, written
|
|
12
|
+
* into each mark, so CSS doesn't reach them.
|
|
13
|
+
*/
|
|
14
|
+
interface RedactionSettings {
|
|
15
|
+
/**
|
|
16
|
+
* What applying paints over every mark, whichever way it was made: the
|
|
17
|
+
* `redact` tool, the selected text, or code. They are the redact tool's
|
|
18
|
+
* defaults from then on; a style panel can still change one mark.
|
|
19
|
+
*/
|
|
20
|
+
readonly overlay: {
|
|
21
|
+
/** The color of a redacted area. */
|
|
22
|
+
readonly fill: string;
|
|
23
|
+
readonly text: {
|
|
24
|
+
/** The color of a label. */
|
|
25
|
+
readonly color: string;
|
|
26
|
+
/** The label's font: a standard font or a registered one. */
|
|
27
|
+
readonly fontFamily: FreeTextFont;
|
|
28
|
+
/** The label's size in points; `0` fits it to the area. */
|
|
29
|
+
readonly fontSize: number;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/** What the redaction settings are when the app registers none. */
|
|
34
|
+
declare const REDACTION_DEFAULTS: RedactionSettings;
|
|
35
|
+
/** What `redactionPlugin(config)` takes: any of the settings, merged over the defaults. */
|
|
36
|
+
type RedactionConfig = DeepPartial<RedactionSettings>;
|
|
37
|
+
/**
|
|
38
|
+
* One pending redaction mark — a live projection of a `redact` annotation on
|
|
39
|
+
* the annotation plane (delete the annotation and the mark is gone).
|
|
40
|
+
*/
|
|
41
|
+
interface RedactionMark {
|
|
42
|
+
readonly ref: AnnotationRef;
|
|
43
|
+
readonly page: PageRef;
|
|
44
|
+
/** Display index (0-based) from the page registry — for "page N" labels. */
|
|
45
|
+
readonly pageIndex: number;
|
|
46
|
+
/** `area` = rect-only mark (marquee); `text` = per-line quads (selection). */
|
|
47
|
+
readonly kind: 'area' | 'text';
|
|
48
|
+
/** Page-space bounds of the region. */
|
|
49
|
+
readonly bounds: Rect;
|
|
50
|
+
/** `/OverlayText` label, when set. */
|
|
51
|
+
readonly overlayText: string | null;
|
|
52
|
+
/** Whether the label fills the area over and over, or shows once. */
|
|
53
|
+
readonly repeat: boolean;
|
|
54
|
+
}
|
|
55
|
+
interface RedactionMarkFilter {
|
|
56
|
+
/** One page's marks: its ref or its index. */
|
|
57
|
+
readonly page?: PageRef | number;
|
|
58
|
+
}
|
|
59
|
+
/** A label edit: `overlayText: null` clears it; `repeat` tiles it. */
|
|
60
|
+
interface RedactionLabelPatch {
|
|
61
|
+
overlayText?: string | null;
|
|
62
|
+
repeat?: boolean;
|
|
63
|
+
}
|
|
64
|
+
/** Which other annotations an apply would destroy (a client-side estimate; the result is authoritative). */
|
|
65
|
+
interface RedactionCollateral {
|
|
66
|
+
readonly count: number;
|
|
67
|
+
readonly refs: readonly AnnotationRef[];
|
|
68
|
+
}
|
|
69
|
+
/** A confirmed apply, from this session or another. */
|
|
70
|
+
interface RedactionAppliedEvent {
|
|
71
|
+
readonly result: RedactionApplyResult;
|
|
72
|
+
readonly origin: EventOrigin;
|
|
73
|
+
}
|
|
74
|
+
/** Marks were created, changed or removed on these pages. */
|
|
75
|
+
interface RedactionPendingChangedEvent {
|
|
76
|
+
readonly pages: readonly PageRef[];
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Redaction for one document: marking (a mark is a `redact` annotation), the
|
|
80
|
+
* pending marks, and applying them, which can't be undone. A page argument
|
|
81
|
+
* is a ref or an index: a read given a page that isn't there answers empty,
|
|
82
|
+
* a verb refuses it with `not-found`. Every async verb takes a `signal`. The
|
|
83
|
+
* settings belong to the plugin, not to a document.
|
|
84
|
+
*/
|
|
85
|
+
interface RedactionCapability extends SettingsApi<RedactionSettings> {
|
|
86
|
+
/**
|
|
87
|
+
* Whether marking is allowed. Marking and applying are different powers: a
|
|
88
|
+
* mark is an ordinary `redact` annotation, so this is annotation create
|
|
89
|
+
* authority (matches Acrobat: any reviewer who can annotate can propose
|
|
90
|
+
* redactions).
|
|
91
|
+
*/
|
|
92
|
+
canMark(): boolean;
|
|
93
|
+
/** Whether this mark may be removed before it's applied: it is a mark, and may be deleted (`annotations:delete`). */
|
|
94
|
+
canUnmark(ref: AnnotationRef): boolean;
|
|
95
|
+
/** Whether this mark's label may change: it is a mark, and may be changed (`annotations:update`). */
|
|
96
|
+
canUpdateLabel(ref: AnnotationRef): boolean;
|
|
97
|
+
/**
|
|
98
|
+
* Whether applying is allowed: the engine has a redaction service and every
|
|
99
|
+
* capability its apply asserts is granted (`doc.redact`, `doc.pages.modify`,
|
|
100
|
+
* `doc.annotate.modify`).
|
|
101
|
+
*/
|
|
102
|
+
canApply(): boolean;
|
|
103
|
+
/** An apply of this session is running at the engine. */
|
|
104
|
+
isApplying(): boolean;
|
|
105
|
+
/** The last confirmed apply result, from this session or another. */
|
|
106
|
+
getLastResult(): RedactionApplyResult | null;
|
|
107
|
+
/** Pending marks in page order, or one page's. Reference-stable while unchanged. */
|
|
108
|
+
listPending(filter?: RedactionMarkFilter): readonly RedactionMark[];
|
|
109
|
+
getPending(ref: AnnotationRef): RedactionMark | null;
|
|
110
|
+
/** How many marks wait to be applied, in the document or on one page. */
|
|
111
|
+
getPendingCount(page?: PageRef | number): number;
|
|
112
|
+
/** Which other annotations applying these marks (default: all) would destroy. */
|
|
113
|
+
estimateCollateral(refs?: readonly AnnotationRef[]): RedactionCollateral;
|
|
114
|
+
/**
|
|
115
|
+
* Mark the current text selection (one mark per page) and clear it.
|
|
116
|
+
* Resolves `{ marks }`, empty without a selection; rejects `unsupported`
|
|
117
|
+
* without the selection plugin.
|
|
118
|
+
*/
|
|
119
|
+
markSelection(options?: OperationOptions): Promise<{
|
|
120
|
+
marks: readonly RedactionMark[];
|
|
121
|
+
}>;
|
|
122
|
+
/** Mark a page-space rectangle. Resolves `{ mark }`; rejects `not-found` for a page that isn't there. */
|
|
123
|
+
markArea(page: PageRef | number, bounds: Rect, options?: OperationOptions): Promise<{
|
|
124
|
+
mark: RedactionMark;
|
|
125
|
+
}>;
|
|
126
|
+
/** Mark a whole page. Resolves `{ mark }`; rejects `not-found` for a page that isn't there. */
|
|
127
|
+
markPage(page: PageRef | number, options?: OperationOptions): Promise<{
|
|
128
|
+
mark: RedactionMark;
|
|
129
|
+
}>;
|
|
130
|
+
/**
|
|
131
|
+
* Mark every match of a search, or the ones on some pages. Runs the query
|
|
132
|
+
* through the search plugin, so it replaces the user's current search.
|
|
133
|
+
* Resolves `{ marks }`, one per match; rejects `unsupported` without the
|
|
134
|
+
* search plugin.
|
|
135
|
+
*/
|
|
136
|
+
markMatches(query: SearchQuery, options?: {
|
|
137
|
+
pages?: readonly (PageRef | number)[];
|
|
138
|
+
} & OperationOptions): Promise<{
|
|
139
|
+
marks: readonly RedactionMark[];
|
|
140
|
+
}>;
|
|
141
|
+
/**
|
|
142
|
+
* Remove marks without applying them. Refs that are not pending marks are
|
|
143
|
+
* skipped; a mark this session may not delete fails with
|
|
144
|
+
* `permission-denied` (see `canUnmark`).
|
|
145
|
+
*/
|
|
146
|
+
unmark(refs: readonly AnnotationRef[], options?: OperationOptions): Promise<BatchResult<AnnotationRef, AnnotationRef>>;
|
|
147
|
+
/** Remove every mark, as `unmark` does. */
|
|
148
|
+
clearPending(options?: OperationOptions): Promise<BatchResult<AnnotationRef, AnnotationRef>>;
|
|
149
|
+
/**
|
|
150
|
+
* Set the label a mark shows once it's applied; `overlayText: null` clears
|
|
151
|
+
* it. Keeps the mark's font and colors. Resolves `{ mark }`. Rejects
|
|
152
|
+
* `not-found` for a ref that isn't a mark, `permission-denied` when
|
|
153
|
+
* `canUpdateLabel(ref)` is false.
|
|
154
|
+
*/
|
|
155
|
+
updateLabel(ref: AnnotationRef, patch: RedactionLabelPatch, options?: OperationOptions): Promise<{
|
|
156
|
+
mark: RedactionMark;
|
|
157
|
+
}>;
|
|
158
|
+
/**
|
|
159
|
+
* Apply specific pending marks. Per-page outcomes ride the result. Applies
|
|
160
|
+
* run one at a time in call order; when one resolves, `getLastResult()`
|
|
161
|
+
* holds its result and `onApplied` has fired. Rejects with `not-found` when
|
|
162
|
+
* none of the refs is a pending mark, `unsupported` without an engine
|
|
163
|
+
* redaction service, or the engine's `permission-denied`.
|
|
164
|
+
*/
|
|
165
|
+
apply(refs: readonly AnnotationRef[], options?: OperationOptions): Promise<RedactionApplyResult>;
|
|
166
|
+
/**
|
|
167
|
+
* Apply every redaction in the document, in pages scope, including marks
|
|
168
|
+
* on pages this client never loaded. Rejects like `apply`, and with
|
|
169
|
+
* `not-ready` when the document has no pages.
|
|
170
|
+
*/
|
|
171
|
+
applyAll(options?: OperationOptions): Promise<RedactionApplyResult>;
|
|
172
|
+
/**
|
|
173
|
+
* Apply the marks on some pages. Rejects like `apply`, with
|
|
174
|
+
* `invalid-input` for no pages, and `not-found` for a page that isn't there.
|
|
175
|
+
*/
|
|
176
|
+
applyPages(pages: readonly (PageRef | number)[], options?: OperationOptions): Promise<RedactionApplyResult>;
|
|
177
|
+
/** A confirmed apply, from this session or another; fires after `getLastResult()` changed. */
|
|
178
|
+
readonly onApplied: EventHook<RedactionAppliedEvent>;
|
|
179
|
+
/** Marks were created, changed or removed on some pages. */
|
|
180
|
+
readonly onPendingChanged: EventHook<RedactionPendingChangedEvent>;
|
|
181
|
+
}
|
|
182
|
+
//#endregion
|
|
183
|
+
export { RedactionCollateral as a, RedactionMark as c, RedactionSettings as d, RedactionToken as f, RedactionCapability as i, RedactionMarkFilter as l, RedactionAppliedEvent as n, RedactionConfig as o, RedactionApplyResult$1 as r, RedactionLabelPatch as s, REDACTION_DEFAULTS as t, RedactionPendingChangedEvent as u };
|
|
184
|
+
//# sourceMappingURL=contract-TU9orxrO.d.ts.map
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { createCapabilityToken } from "@embedpdf/core";
|
|
2
|
+
//#region src/token.ts
|
|
3
|
+
/** The package token, created once here and re-exported by `contract.ts`. */
|
|
4
|
+
const RedactionToken = createCapabilityToken("redaction", {
|
|
5
|
+
hint: `add redactionPlugin() from '@embedpdf/plugin-redaction' to your plugins list`,
|
|
6
|
+
promises: {
|
|
7
|
+
markSelection: true,
|
|
8
|
+
markArea: true,
|
|
9
|
+
markPage: true,
|
|
10
|
+
markMatches: true,
|
|
11
|
+
unmark: true,
|
|
12
|
+
clearPending: true,
|
|
13
|
+
updateLabel: true,
|
|
14
|
+
apply: true,
|
|
15
|
+
applyAll: true,
|
|
16
|
+
applyPages: true
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
//#endregion
|
|
20
|
+
//#region src/contract.ts
|
|
21
|
+
/** What the redaction settings are when the app registers none. */
|
|
22
|
+
const REDACTION_DEFAULTS = { overlay: {
|
|
23
|
+
fill: "#000000",
|
|
24
|
+
text: {
|
|
25
|
+
color: "#ffffff",
|
|
26
|
+
fontFamily: "helvetica",
|
|
27
|
+
fontSize: 0
|
|
28
|
+
}
|
|
29
|
+
} };
|
|
30
|
+
//#endregion
|
|
31
|
+
export { RedactionToken as n, REDACTION_DEFAULTS as t };
|
|
32
|
+
|
|
33
|
+
//# sourceMappingURL=contract-eQ3P0UU-.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract-eQ3P0UU-.js","names":[],"sources":["../src/token.ts","../src/contract.ts"],"sourcesContent":["/** The package token, created once here and re-exported by `contract.ts`. */\nimport { createCapabilityToken } from '@embedpdf/core';\n\nimport type { RedactionCapability } from './contract';\n\nexport const RedactionToken = createCapabilityToken<RedactionCapability>('redaction', {\n hint: `add redactionPlugin() from '@embedpdf/plugin-redaction' to your plugins list`,\n // Without a document, an adapter's stand-in rejects these with `not-ready`, as the\n // capability would; the type asks for every member that returns a promise.\n promises: {\n markSelection: true,\n markArea: true,\n markPage: true,\n markMatches: true,\n unmark: true,\n clearPending: true,\n updateLabel: true,\n apply: true,\n applyAll: true,\n applyPages: true,\n },\n});\n","/**\n * @embedpdf/plugin-redaction/contract: the public redaction vocabulary.\n * Marking is annotation authoring (a mark is a `redact` annotation); applying\n * is the destructive document mutation. The plugin owns no mark state: the\n * pending view is a live projection of the annotation plane.\n */\nimport type {\n BatchResult,\n DeepPartial,\n EventHook,\n EventOrigin,\n OperationOptions,\n SettingsApi,\n} from '@embedpdf/core';\nimport type { Rect } from '@embedpdf/core-geometry';\nimport type {\n AnnotationRef,\n FreeTextFont,\n PageRef,\n RedactionApplyResult,\n SearchQuery,\n} from '@embedpdf/engine-core';\n\nexport { RedactionToken } from './token';\nexport type { RedactionApplyResult } from '@embedpdf/engine-core';\n\n/**\n * The redaction plugin's settings. `redactionPlugin(config)` registers them\n * over {@link REDACTION_DEFAULTS}, and `updateSettings()` changes them for\n * every document while the app runs. They are PDF colors and fonts, written\n * into each mark, so CSS doesn't reach them.\n */\nexport interface RedactionSettings {\n /**\n * What applying paints over every mark, whichever way it was made: the\n * `redact` tool, the selected text, or code. They are the redact tool's\n * defaults from then on; a style panel can still change one mark.\n */\n readonly overlay: {\n /** The color of a redacted area. */\n readonly fill: string;\n readonly text: {\n /** The color of a label. */\n readonly color: string;\n /** The label's font: a standard font or a registered one. */\n readonly fontFamily: FreeTextFont;\n /** The label's size in points; `0` fits it to the area. */\n readonly fontSize: number;\n };\n };\n}\n\n/** What the redaction settings are when the app registers none. */\nexport const REDACTION_DEFAULTS: RedactionSettings = {\n overlay: {\n fill: '#000000',\n text: { color: '#ffffff', fontFamily: 'helvetica', fontSize: 0 },\n },\n};\n\n/** What `redactionPlugin(config)` takes: any of the settings, merged over the defaults. */\nexport type RedactionConfig = DeepPartial<RedactionSettings>;\n\n/**\n * One pending redaction mark — a live projection of a `redact` annotation on\n * the annotation plane (delete the annotation and the mark is gone).\n */\nexport interface RedactionMark {\n readonly ref: AnnotationRef;\n readonly page: PageRef;\n /** Display index (0-based) from the page registry — for \"page N\" labels. */\n readonly pageIndex: number;\n /** `area` = rect-only mark (marquee); `text` = per-line quads (selection). */\n readonly kind: 'area' | 'text';\n /** Page-space bounds of the region. */\n readonly bounds: Rect;\n /** `/OverlayText` label, when set. */\n readonly overlayText: string | null;\n /** Whether the label fills the area over and over, or shows once. */\n readonly repeat: boolean;\n}\n\nexport interface RedactionMarkFilter {\n /** One page's marks: its ref or its index. */\n readonly page?: PageRef | number;\n}\n\n/** A label edit: `overlayText: null` clears it; `repeat` tiles it. */\nexport interface RedactionLabelPatch {\n overlayText?: string | null;\n repeat?: boolean;\n}\n\n/** Which other annotations an apply would destroy (a client-side estimate; the result is authoritative). */\nexport interface RedactionCollateral {\n readonly count: number;\n readonly refs: readonly AnnotationRef[];\n}\n\n// ── events ──\n/** A confirmed apply, from this session or another. */\nexport interface RedactionAppliedEvent {\n readonly result: RedactionApplyResult;\n readonly origin: EventOrigin;\n}\n/** Marks were created, changed or removed on these pages. */\nexport interface RedactionPendingChangedEvent {\n readonly pages: readonly PageRef[];\n}\n\n/**\n * Redaction for one document: marking (a mark is a `redact` annotation), the\n * pending marks, and applying them, which can't be undone. A page argument\n * is a ref or an index: a read given a page that isn't there answers empty,\n * a verb refuses it with `not-found`. Every async verb takes a `signal`. The\n * settings belong to the plugin, not to a document.\n */\nexport interface RedactionCapability extends SettingsApi<RedactionSettings> {\n /**\n * Whether marking is allowed. Marking and applying are different powers: a\n * mark is an ordinary `redact` annotation, so this is annotation create\n * authority (matches Acrobat: any reviewer who can annotate can propose\n * redactions).\n */\n canMark(): boolean;\n /** Whether this mark may be removed before it's applied: it is a mark, and may be deleted (`annotations:delete`). */\n canUnmark(ref: AnnotationRef): boolean;\n /** Whether this mark's label may change: it is a mark, and may be changed (`annotations:update`). */\n canUpdateLabel(ref: AnnotationRef): boolean;\n /**\n * Whether applying is allowed: the engine has a redaction service and every\n * capability its apply asserts is granted (`doc.redact`, `doc.pages.modify`,\n * `doc.annotate.modify`).\n */\n canApply(): boolean;\n /** An apply of this session is running at the engine. */\n isApplying(): boolean;\n /** The last confirmed apply result, from this session or another. */\n getLastResult(): RedactionApplyResult | null;\n\n // ── the pending view ──\n /** Pending marks in page order, or one page's. Reference-stable while unchanged. */\n listPending(filter?: RedactionMarkFilter): readonly RedactionMark[];\n getPending(ref: AnnotationRef): RedactionMark | null;\n /** How many marks wait to be applied, in the document or on one page. */\n getPendingCount(page?: PageRef | number): number;\n /** Which other annotations applying these marks (default: all) would destroy. */\n estimateCollateral(refs?: readonly AnnotationRef[]): RedactionCollateral;\n\n // ── marking ──\n // Every marking verb rejects `permission-denied` without annotation create\n // authority (see `canMark`). Marks take the `overlay` settings.\n /**\n * Mark the current text selection (one mark per page) and clear it.\n * Resolves `{ marks }`, empty without a selection; rejects `unsupported`\n * without the selection plugin.\n */\n markSelection(options?: OperationOptions): Promise<{ marks: readonly RedactionMark[] }>;\n /** Mark a page-space rectangle. Resolves `{ mark }`; rejects `not-found` for a page that isn't there. */\n markArea(\n page: PageRef | number,\n bounds: Rect,\n options?: OperationOptions,\n ): Promise<{ mark: RedactionMark }>;\n /** Mark a whole page. Resolves `{ mark }`; rejects `not-found` for a page that isn't there. */\n markPage(page: PageRef | number, options?: OperationOptions): Promise<{ mark: RedactionMark }>;\n /**\n * Mark every match of a search, or the ones on some pages. Runs the query\n * through the search plugin, so it replaces the user's current search.\n * Resolves `{ marks }`, one per match; rejects `unsupported` without the\n * search plugin.\n */\n markMatches(\n query: SearchQuery,\n options?: { pages?: readonly (PageRef | number)[] } & OperationOptions,\n ): Promise<{ marks: readonly RedactionMark[] }>;\n /**\n * Remove marks without applying them. Refs that are not pending marks are\n * skipped; a mark this session may not delete fails with\n * `permission-denied` (see `canUnmark`).\n */\n unmark(\n refs: readonly AnnotationRef[],\n options?: OperationOptions,\n ): Promise<BatchResult<AnnotationRef, AnnotationRef>>;\n /** Remove every mark, as `unmark` does. */\n clearPending(options?: OperationOptions): Promise<BatchResult<AnnotationRef, AnnotationRef>>;\n /**\n * Set the label a mark shows once it's applied; `overlayText: null` clears\n * it. Keeps the mark's font and colors. Resolves `{ mark }`. Rejects\n * `not-found` for a ref that isn't a mark, `permission-denied` when\n * `canUpdateLabel(ref)` is false.\n */\n updateLabel(\n ref: AnnotationRef,\n patch: RedactionLabelPatch,\n options?: OperationOptions,\n ): Promise<{ mark: RedactionMark }>;\n\n // ── applying (irreversible) ──\n /**\n * Apply specific pending marks. Per-page outcomes ride the result. Applies\n * run one at a time in call order; when one resolves, `getLastResult()`\n * holds its result and `onApplied` has fired. Rejects with `not-found` when\n * none of the refs is a pending mark, `unsupported` without an engine\n * redaction service, or the engine's `permission-denied`.\n */\n apply(refs: readonly AnnotationRef[], options?: OperationOptions): Promise<RedactionApplyResult>;\n /**\n * Apply every redaction in the document, in pages scope, including marks\n * on pages this client never loaded. Rejects like `apply`, and with\n * `not-ready` when the document has no pages.\n */\n applyAll(options?: OperationOptions): Promise<RedactionApplyResult>;\n /**\n * Apply the marks on some pages. Rejects like `apply`, with\n * `invalid-input` for no pages, and `not-found` for a page that isn't there.\n */\n applyPages(\n pages: readonly (PageRef | number)[],\n options?: OperationOptions,\n ): Promise<RedactionApplyResult>;\n\n // ── events ──\n /** A confirmed apply, from this session or another; fires after `getLastResult()` changed. */\n readonly onApplied: EventHook<RedactionAppliedEvent>;\n /** Marks were created, changed or removed on some pages. */\n readonly onPendingChanged: EventHook<RedactionPendingChangedEvent>;\n}\n"],"mappings":";;;AAKA,MAAa,iBAAiB,sBAA2C,aAAa;CACpF,MAAM;CAGN,UAAU;EACR,eAAe;EACf,UAAU;EACV,UAAU;EACV,aAAa;EACb,QAAQ;EACR,cAAc;EACd,aAAa;EACb,OAAO;EACP,UAAU;EACV,YAAY;CACd;AACF,CAAC;;;;ACgCD,MAAa,qBAAwC,EACnD,SAAS;CACP,MAAM;CACN,MAAM;EAAE,OAAO;EAAW,YAAY;EAAa,UAAU;CAAE;AACjE,EACF"}
|
package/dist/contract.cjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_contract = require("./contract-
|
|
2
|
+
const require_contract = require("./contract-Ib0iOWF3.cjs");
|
|
3
|
+
exports.REDACTION_DEFAULTS = require_contract.REDACTION_DEFAULTS;
|
|
3
4
|
exports.RedactionToken = require_contract.RedactionToken;
|