@embedpdf/plugin-redaction 2.15.0 → 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/LICENSE +192 -21
- package/README.md +109 -0
- package/dist/index.cjs +227 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +89 -0
- package/dist/index.d.ts +89 -1
- package/dist/index.js +220 -1532
- package/dist/index.js.map +1 -1
- package/package.json +22 -67
- package/dist/lib/actions.d.ts +0 -113
- package/dist/lib/handlers/index.d.ts +0 -0
- package/dist/lib/index.d.ts +0 -11
- package/dist/lib/manifest.d.ts +0 -4
- package/dist/lib/redaction-plugin.d.ts +0 -153
- package/dist/lib/reducer.d.ts +0 -6
- package/dist/lib/selectors.d.ts +0 -5
- package/dist/lib/tools.d.ts +0 -64
- package/dist/lib/types.d.ts +0 -142
- package/dist/preact/adapter.d.ts +0 -10
- package/dist/preact/annotation.d.ts +0 -1
- package/dist/preact/core.d.ts +0 -1
- package/dist/preact/index.cjs +0 -2
- package/dist/preact/index.cjs.map +0 -1
- package/dist/preact/index.d.ts +0 -1
- package/dist/preact/index.js +0 -520
- package/dist/preact/index.js.map +0 -1
- package/dist/preact/utils.d.ts +0 -1
- package/dist/react/adapter.d.ts +0 -2
- package/dist/react/annotation.d.ts +0 -1
- package/dist/react/core.d.ts +0 -1
- package/dist/react/index.cjs +0 -2
- package/dist/react/index.cjs.map +0 -1
- package/dist/react/index.d.ts +0 -1
- package/dist/react/index.js +0 -519
- package/dist/react/index.js.map +0 -1
- package/dist/react/utils.d.ts +0 -1
- package/dist/shared/components/annotations/index.d.ts +0 -2
- package/dist/shared/components/annotations/redact-area.d.ts +0 -18
- package/dist/shared/components/annotations/redact-highlight.d.ts +0 -18
- package/dist/shared/components/highlight.d.ts +0 -14
- package/dist/shared/components/index.d.ts +0 -5
- package/dist/shared/components/marquee-redact.d.ts +0 -15
- package/dist/shared/components/pending-redactions.d.ts +0 -12
- package/dist/shared/components/redact-renderer-registration.d.ts +0 -5
- package/dist/shared/components/redact-renderers.d.ts +0 -7
- package/dist/shared/components/redaction-layer.d.ts +0 -16
- package/dist/shared/components/selection-redact.d.ts +0 -7
- package/dist/shared/components/types.d.ts +0 -9
- package/dist/shared/hooks/index.d.ts +0 -1
- package/dist/shared/hooks/use-redaction.d.ts +0 -15
- package/dist/shared/index.d.ts +0 -4
- package/dist/shared-preact/components/annotations/index.d.ts +0 -2
- package/dist/shared-preact/components/annotations/redact-area.d.ts +0 -18
- package/dist/shared-preact/components/annotations/redact-highlight.d.ts +0 -18
- package/dist/shared-preact/components/highlight.d.ts +0 -14
- package/dist/shared-preact/components/index.d.ts +0 -5
- package/dist/shared-preact/components/marquee-redact.d.ts +0 -15
- package/dist/shared-preact/components/pending-redactions.d.ts +0 -12
- package/dist/shared-preact/components/redact-renderer-registration.d.ts +0 -5
- package/dist/shared-preact/components/redact-renderers.d.ts +0 -7
- package/dist/shared-preact/components/redaction-layer.d.ts +0 -16
- package/dist/shared-preact/components/selection-redact.d.ts +0 -7
- package/dist/shared-preact/components/types.d.ts +0 -9
- package/dist/shared-preact/hooks/index.d.ts +0 -1
- package/dist/shared-preact/hooks/use-redaction.d.ts +0 -15
- package/dist/shared-preact/index.d.ts +0 -4
- package/dist/shared-react/components/annotations/index.d.ts +0 -2
- package/dist/shared-react/components/annotations/redact-area.d.ts +0 -18
- package/dist/shared-react/components/annotations/redact-highlight.d.ts +0 -18
- package/dist/shared-react/components/highlight.d.ts +0 -14
- package/dist/shared-react/components/index.d.ts +0 -5
- package/dist/shared-react/components/marquee-redact.d.ts +0 -15
- package/dist/shared-react/components/pending-redactions.d.ts +0 -12
- package/dist/shared-react/components/redact-renderer-registration.d.ts +0 -5
- package/dist/shared-react/components/redact-renderers.d.ts +0 -7
- package/dist/shared-react/components/redaction-layer.d.ts +0 -16
- package/dist/shared-react/components/selection-redact.d.ts +0 -7
- package/dist/shared-react/components/types.d.ts +0 -9
- package/dist/shared-react/hooks/index.d.ts +0 -1
- package/dist/shared-react/hooks/use-redaction.d.ts +0 -15
- package/dist/shared-react/index.d.ts +0 -4
- package/dist/svelte/components/RedactRendererRegistration.svelte.d.ts +0 -7
- package/dist/svelte/components/annotations/RedactArea.svelte.d.ts +0 -5
- package/dist/svelte/components/annotations/RedactHighlight.svelte.d.ts +0 -5
- package/dist/svelte/components/annotations/index.d.ts +0 -2
- package/dist/svelte/components/highlight.svelte.d.ts +0 -14
- package/dist/svelte/components/index.d.ts +0 -8
- package/dist/svelte/components/marquee-redact.svelte.d.ts +0 -16
- package/dist/svelte/components/pending-redactions.svelte.d.ts +0 -15
- package/dist/svelte/components/redact-renderers.d.ts +0 -7
- package/dist/svelte/components/redaction-layer.svelte.d.ts +0 -20
- package/dist/svelte/components/selection-redact.svelte.d.ts +0 -8
- package/dist/svelte/hooks/index.d.ts +0 -1
- package/dist/svelte/hooks/use-redaction.svelte.d.ts +0 -21
- package/dist/svelte/index.cjs +0 -2
- package/dist/svelte/index.cjs.map +0 -1
- package/dist/svelte/index.d.ts +0 -5
- package/dist/svelte/index.js +0 -801
- package/dist/svelte/index.js.map +0 -1
- package/dist/svelte/types.d.ts +0 -10
- package/dist/vue/components/annotations/index.d.ts +0 -2
- package/dist/vue/components/annotations/redact-area.vue.d.ts +0 -6
- package/dist/vue/components/annotations/redact-highlight.vue.d.ts +0 -6
- package/dist/vue/components/highlight.vue.d.ts +0 -17
- package/dist/vue/components/index.d.ts +0 -8
- package/dist/vue/components/marquee-redact.vue.d.ts +0 -19
- package/dist/vue/components/pending-redactions.vue.d.ts +0 -68
- package/dist/vue/components/redact-renderer-registration.vue.d.ts +0 -13
- package/dist/vue/components/redact-renderers.d.ts +0 -7
- package/dist/vue/components/redaction-layer.vue.d.ts +0 -50
- package/dist/vue/components/selection-redact.vue.d.ts +0 -8
- package/dist/vue/components/types.d.ts +0 -9
- package/dist/vue/hooks/index.d.ts +0 -1
- package/dist/vue/hooks/use-redaction.d.ts +0 -12
- package/dist/vue/index.cjs +0 -2
- package/dist/vue/index.cjs.map +0 -1
- package/dist/vue/index.d.ts +0 -5
- package/dist/vue/index.js +0 -638
- package/dist/vue/index.js.map +0 -1
package/LICENSE
CHANGED
|
@@ -1,21 +1,192 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
1
|
+
Copyright 2026 CloudPDF LTD
|
|
2
|
+
|
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use files in this distribution except in compliance with the License.
|
|
5
|
+
You may obtain a copy of the License at
|
|
6
|
+
|
|
7
|
+
https://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
See the License for the specific language governing permissions and
|
|
13
|
+
limitations under the License.
|
|
14
|
+
|
|
15
|
+
-----------------------------------------------------------------------
|
|
16
|
+
|
|
17
|
+
Apache License
|
|
18
|
+
Version 2.0, January 2004
|
|
19
|
+
http://www.apache.org/licenses/
|
|
20
|
+
|
|
21
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
22
|
+
|
|
23
|
+
1. Definitions.
|
|
24
|
+
|
|
25
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
26
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
27
|
+
|
|
28
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
29
|
+
the copyright owner that is granting the License.
|
|
30
|
+
|
|
31
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
32
|
+
other entities that control, are controlled by, or are under common
|
|
33
|
+
control with that entity. For the purposes of this definition,
|
|
34
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
35
|
+
direction or management of such entity, whether by contract or
|
|
36
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
37
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
38
|
+
|
|
39
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
40
|
+
exercising permissions granted by this License.
|
|
41
|
+
|
|
42
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
43
|
+
including but not limited to software source code, documentation
|
|
44
|
+
source, and configuration files.
|
|
45
|
+
|
|
46
|
+
"Object" form shall mean any form resulting from mechanical
|
|
47
|
+
transformation or translation of a Source form, including but
|
|
48
|
+
not limited to compiled object code, generated documentation,
|
|
49
|
+
and conversions to other media types.
|
|
50
|
+
|
|
51
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
52
|
+
Object form, made available under the License, as indicated by a
|
|
53
|
+
copyright notice that is included in or attached to the work
|
|
54
|
+
(an example is provided in the Appendix below).
|
|
55
|
+
|
|
56
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
57
|
+
form, that is based on (or derived from) the Work and for which the
|
|
58
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
59
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
60
|
+
of this License, Derivative Works shall not include works that remain
|
|
61
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
62
|
+
the Work and Derivative Works thereof.
|
|
63
|
+
|
|
64
|
+
"Contribution" shall mean any work of authorship, including
|
|
65
|
+
the original version of the Work and any modifications or additions
|
|
66
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
67
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
68
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
69
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
70
|
+
means any form of electronic, verbal, or written communication sent
|
|
71
|
+
to the Licensor or its representatives, including but not limited to
|
|
72
|
+
communication on electronic mailing lists, source code control systems,
|
|
73
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
74
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
75
|
+
excluding communication that is conspicuously marked or otherwise
|
|
76
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
77
|
+
|
|
78
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
79
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
80
|
+
subsequently incorporated within the Work.
|
|
81
|
+
|
|
82
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
83
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
84
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
85
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
86
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
87
|
+
Work and such Derivative Works in Source or Object form.
|
|
88
|
+
|
|
89
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
90
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
91
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
92
|
+
(except as stated in this section) patent license to make, have made,
|
|
93
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
94
|
+
where such license applies only to those patent claims licensable
|
|
95
|
+
by such Contributor that are necessarily infringed by their
|
|
96
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
97
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
98
|
+
institute patent litigation against any entity (including a
|
|
99
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
100
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
101
|
+
or contributory patent infringement, then any patent licenses
|
|
102
|
+
granted to You under this License for that Work shall terminate
|
|
103
|
+
as of the date such litigation is filed.
|
|
104
|
+
|
|
105
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
106
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
107
|
+
modifications, and in Source or Object form, provided that You
|
|
108
|
+
meet the following conditions:
|
|
109
|
+
|
|
110
|
+
(a) You must give any other recipients of the Work or
|
|
111
|
+
Derivative Works a copy of this License; and
|
|
112
|
+
|
|
113
|
+
(b) You must cause any modified files to carry prominent notices
|
|
114
|
+
stating that You changed the files; and
|
|
115
|
+
|
|
116
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
117
|
+
that You distribute, all copyright, patent, trademark, and
|
|
118
|
+
attribution notices from the Source form of the Work,
|
|
119
|
+
excluding those notices that do not pertain to any part of
|
|
120
|
+
the Derivative Works; and
|
|
121
|
+
|
|
122
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
123
|
+
distribution, then any Derivative Works that You distribute must
|
|
124
|
+
include a readable copy of the attribution notices contained
|
|
125
|
+
within such NOTICE file, excluding those notices that do not
|
|
126
|
+
pertain to any part of the Derivative Works, in at least one
|
|
127
|
+
of the following places: within a NOTICE text file distributed
|
|
128
|
+
as part of the Derivative Works; within the Source form or
|
|
129
|
+
documentation, if provided along with the Derivative Works; or,
|
|
130
|
+
within a display generated by the Derivative Works, if and
|
|
131
|
+
wherever such third-party notices normally appear. The contents
|
|
132
|
+
of the NOTICE file are for informational purposes only and
|
|
133
|
+
do not modify the License. You may add Your own attribution
|
|
134
|
+
notices within Derivative Works that You distribute, alongside
|
|
135
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
136
|
+
that such additional attribution notices cannot be construed
|
|
137
|
+
as modifying the License.
|
|
138
|
+
|
|
139
|
+
You may add Your own copyright statement to Your modifications and
|
|
140
|
+
may provide additional or different license terms and conditions
|
|
141
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
142
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
143
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
144
|
+
the conditions stated in this License.
|
|
145
|
+
|
|
146
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
147
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
148
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
149
|
+
this License, without any additional terms or conditions.
|
|
150
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
151
|
+
the terms of any separate license agreement you may have executed
|
|
152
|
+
with Licensor regarding such Contributions.
|
|
153
|
+
|
|
154
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
155
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
156
|
+
except as required for reasonable and customary use in describing the
|
|
157
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
158
|
+
|
|
159
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
160
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
161
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
162
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
163
|
+
implied, including, without limitation, any warranties or conditions
|
|
164
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
165
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
166
|
+
appropriateness of using or redistributing the Work and assume any
|
|
167
|
+
risks associated with Your exercise of permissions under this License.
|
|
168
|
+
|
|
169
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
170
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
171
|
+
unless required by applicable law (such as deliberate and grossly
|
|
172
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
173
|
+
liable to You for damages, including any direct, indirect, special,
|
|
174
|
+
incidental, or consequential damages of any character arising as a
|
|
175
|
+
result of this License or out of the use or inability to use the
|
|
176
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
177
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
178
|
+
other commercial damages or losses), even if such Contributor
|
|
179
|
+
has been advised of the possibility of such damages.
|
|
180
|
+
|
|
181
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
182
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
183
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
184
|
+
or other liability obligations and/or rights consistent with this
|
|
185
|
+
License. However, in accepting such obligations, You may act only
|
|
186
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
187
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
188
|
+
defend, and hold each Contributor harmless for any liability
|
|
189
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
190
|
+
of your accepting any such warranty or additional liability.
|
|
191
|
+
|
|
192
|
+
END OF TERMS AND CONDITIONS
|
package/README.md
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
# @embedpdf/plugin-redaction
|
|
2
|
+
|
|
3
|
+
Redaction for EmbedPDF v3 — mark content for removal, review the pending
|
|
4
|
+
marks, then destroy the content permanently.
|
|
5
|
+
|
|
6
|
+
Redaction is a **two-stage** workflow (ISO 32000-2):
|
|
7
|
+
|
|
8
|
+
1. **Marking** is non-destructive and lives on the annotation plane. A
|
|
9
|
+
redaction mark is a real `redact` annotation: it renders, selects,
|
|
10
|
+
syncs, and deletes like any other annotation, and nothing is removed
|
|
11
|
+
yet. You don't need this plugin to mark — the `redact` tool ships with
|
|
12
|
+
`@embedpdf/plugin-annotation`.
|
|
13
|
+
2. **Applying** is destructive and is what this plugin wraps: the content
|
|
14
|
+
under every marked region is permanently removed, the configured
|
|
15
|
+
overlay (fill + label) is painted in its place, and the consumed marks
|
|
16
|
+
— plus any annotation intersecting the region — are deleted. **There
|
|
17
|
+
is no undo.**
|
|
18
|
+
|
|
19
|
+
> **Trust boundary.** On a layered/cloud document, applying rewrites the
|
|
20
|
+
> current layer's bytes. The immutable base document keeps the original
|
|
21
|
+
> content — redacted content is truly unrecoverable only in what leaves
|
|
22
|
+
> the system (a layer download/export, or a local document saved after
|
|
23
|
+
> apply). Word any "permanently removed" UI accordingly.
|
|
24
|
+
|
|
25
|
+
## Setup
|
|
26
|
+
|
|
27
|
+
```tsx
|
|
28
|
+
import { annotationPlugin } from '@embedpdf/react/annotation';
|
|
29
|
+
import { redactionPlugin } from '@embedpdf/react/redaction';
|
|
30
|
+
|
|
31
|
+
const plugins = [
|
|
32
|
+
// ...stage, interaction, selection...
|
|
33
|
+
annotationPlugin(), // required: owns the marks
|
|
34
|
+
redactionPlugin(), // the destructive apply + pending queue view
|
|
35
|
+
];
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Requires `plugin-annotation`. With `plugin-selection` and
|
|
39
|
+
`plugin-interaction` present (the usual viewer setup), the marking tool
|
|
40
|
+
and `queueCurrentSelection()` light up too.
|
|
41
|
+
|
|
42
|
+
## Marking
|
|
43
|
+
|
|
44
|
+
The `redact` tool is a **composed** tool: with it active, dragging over
|
|
45
|
+
text marks the selected text (per-line quads, like a highlight), and
|
|
46
|
+
dragging anywhere else marks a rectangular area. One tool, both modes.
|
|
47
|
+
|
|
48
|
+
```ts
|
|
49
|
+
const redaction = useCapability(RedactionToken);
|
|
50
|
+
|
|
51
|
+
redaction.toggleRedact(); // toggle the redact tool
|
|
52
|
+
redaction.isRedactActive();
|
|
53
|
+
|
|
54
|
+
// Mark the current text selection without switching tools
|
|
55
|
+
// (context-menu "Mark for Redaction"):
|
|
56
|
+
await redaction.queueCurrentSelection();
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Marks carry their appearance: `color` (marking outline), `interiorColor`
|
|
60
|
+
(the fill painted on apply), and an optional label (`/OverlayText`)
|
|
61
|
+
styled by `fontFamily`/`fontSize`/`fontColor`/`textAlign` with
|
|
62
|
+
`repeat` tiling it across the region. Style props flow through the
|
|
63
|
+
normal annotation style panel; the label text itself:
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
redaction.setLabel(id, { overlayText: 'REDACTED', repeat: true });
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## The pending queue
|
|
70
|
+
|
|
71
|
+
Pending marks are **not plugin state** — they are a live view over the
|
|
72
|
+
annotation plane (`subtype === 'redact'`). Deleting a mark is just
|
|
73
|
+
deleting an annotation.
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
redaction.getPending(); // RedactionPendingItem[] — id, ref, page, kind: 'area' | 'text', label
|
|
77
|
+
redaction.pendingCount();
|
|
78
|
+
redaction.estimateCollateral(); // client-side count of OTHER annotations
|
|
79
|
+
// the pending marks would destroy — show
|
|
80
|
+
// this in your confirm dialog BEFORE applying
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Applying
|
|
84
|
+
|
|
85
|
+
```ts
|
|
86
|
+
// Everything pending:
|
|
87
|
+
const result = await redaction.applyAll();
|
|
88
|
+
|
|
89
|
+
// Or specific marks:
|
|
90
|
+
const result = await redaction.apply([id1, id2]);
|
|
91
|
+
|
|
92
|
+
result.removedAnnotationCount; // authoritative collateral count
|
|
93
|
+
result.results; // per-page applied/unchanged/failed/skipped
|
|
94
|
+
|
|
95
|
+
redaction.onApplied((result) => {
|
|
96
|
+
/* toast, audit, ... */
|
|
97
|
+
});
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
`apply` resolves after the engine confirms. Affected pages re-rasterize
|
|
101
|
+
(content-scope invalidation) and their annotation lists reload
|
|
102
|
+
automatically — including when a **collaborator** applies on a shared
|
|
103
|
+
document. On a document whose token lacks the `doc.redact` capability,
|
|
104
|
+
`canApply()` is false and `apply` rejects.
|
|
105
|
+
|
|
106
|
+
```ts
|
|
107
|
+
redaction.canApply(); // engine service present AND doc.redact granted
|
|
108
|
+
redaction.isApplying(); // in-flight state for spinners
|
|
109
|
+
```
|
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,227 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core"),t=require("@embedpdf/models"),n=require("@embedpdf/plugin-annotation");var o=(e=>(e.Redact="redact",e.MarqueeRedact="marqueeRedact",e.RedactSelection="redactSelection",e))(o||{});const i="REDACTION/INIT_STATE",a="REDACTION/CLEANUP_STATE",c="START_REDACTION",s="END_REDACTION",d="ADD_PENDING",r="REMOVE_PENDING",l="UPDATE_PENDING",u="CLEAR_PENDING",g="SELECT_PENDING",h="DESELECT_PENDING";const m=(e,t)=>({type:d,payload:{documentId:e,items:t}}),p=(e,t,n)=>({type:r,payload:{documentId:e,page:t,id:n}}),f=e=>({type:u,payload:e}),y=(e,t,n,o)=>({type:l,payload:{documentId:e,page:t,id:n,patch:o}}),v=(e,t,n)=>({type:g,payload:{documentId:e,page:t,id:n}}),R=e=>({type:h,payload:e}),C=e=>Object.values(e).reduce((e,t)=>e+t.length,0),P={isRedacting:!1,activeType:null,pending:{},pendingCount:0,selected:null},A={documents:{},activeDocumentId:null},b=n.defineAnnotationTool({id:"redact",name:"Redact",categories:["annotation","redaction"],matchScore:e=>e.type===t.PdfAnnotationSubtype.REDACT?10:0,interaction:{mode:o.Redact,exclusive:!1,cursor:"crosshair",textSelection:!0,isDraggable:e=>{var n;return e.type!==t.PdfAnnotationSubtype.REDACT||!(null==(n=e.segmentRects)?void 0:n.length)},isResizable:e=>{var n;return e.type!==t.PdfAnnotationSubtype.REDACT||!(null==(n=e.segmentRects)?void 0:n.length)},isRotatable:!1,lockAspectRatio:!1,isGroupDraggable:!1,isGroupResizable:!1,isGroupRotatable:!1},defaults:{type:t.PdfAnnotationSubtype.REDACT,color:"#000000",overlayColor:"#FFFFFF",strokeColor:"#E44234",opacity:1},behavior:{useAppearanceStream:!1}}),M=[b],S=class extends e.BasePlugin{constructor(t,n,o){var i,a,c,s;if(super(t,n),this.redactionSelection$=new Map,this.redactionMarquee$=new Map,this.pending$=e.createBehaviorEmitter(),this.selected$=e.createBehaviorEmitter(),this.state$=e.createBehaviorEmitter(),this.events$=e.createBehaviorEmitter(),this.documentUnsubscribers=new Map,this.config=o,this.selectionCapability=null==(i=this.registry.getPlugin("selection"))?void 0:i.provides(),this.interactionManagerCapability=null==(a=this.registry.getPlugin("interaction-manager"))?void 0:a.provides(),this.annotationCapability=null==(c=this.registry.getPlugin("annotation"))?void 0:c.provides(),this.historyCapability=null==(s=this.registry.getPlugin("history"))?void 0:s.provides(),this.config.useAnnotationMode?this.annotationCapability?this.useAnnotationMode=!0:(this.logger.warn("RedactionPlugin","ConfigError","useAnnotationMode is enabled but annotation plugin is not available. Falling back to legacy mode."),this.useAnnotationMode=!1):this.useAnnotationMode=!1,this.useAnnotationMode&&this.annotationCapability)for(const e of M)this.annotationCapability.addTool(e);this.setupRedactionModes(),!this.useAnnotationMode&&this.annotationCapability&&this.logger.info("RedactionPlugin","LegacyMode","Using legacy redaction mode. Set useAnnotationMode: true in config to use annotation-based redactions."),this.setupModeChangeListener()}setupRedactionModes(){this.interactionManagerCapability&&(this.interactionManagerCapability.registerMode({id:o.Redact,scope:"page",exclusive:!1,cursor:"crosshair"}),this.interactionManagerCapability.registerMode({id:o.MarqueeRedact,scope:"page",exclusive:!1,cursor:"crosshair"}),this.interactionManagerCapability.registerMode({id:o.RedactSelection,scope:"page",exclusive:!1}))}setupModeChangeListener(){var e;null==(e=this.interactionManagerCapability)||e.onModeChange(e=>{const t=e.documentId;if(e.activeMode===o.Redact||e.activeMode===o.MarqueeRedact||e.activeMode===o.RedactSelection)this.dispatch(((e,t)=>({type:c,payload:{documentId:e,mode:t}}))(t,e.activeMode));else{const e=this.getDocumentState(t);(null==e?void 0:e.isRedacting)&&this.dispatch((e=>({type:s,payload:e}))(t))}})}onDocumentLoadingStarted(n){this.dispatch(function(e,t){return{type:i,payload:{documentId:e,state:t}}}(n,{...P})),this.redactionSelection$.set(n,e.createBehaviorEmitter()),this.redactionMarquee$.set(n,e.createBehaviorEmitter());const o=[];if(this.selectionCapability){const e=this.selectionCapability.forDocument(n),i=e.onSelectionChange(()=>{const t=this.getDocumentState(n);if(!(null==t?void 0:t.isRedacting))return;const o=e.getFormattedSelection(),i=this.redactionSelection$.get(n);null==i||i.emit(o)}),a=e.onEndSelection(()=>{const o=this.getDocumentState(n);if(!(null==o?void 0:o.isRedacting))return;if(!this.checkPermission(n,t.PdfPermissionFlag.ModifyContents))return;const i=e.getFormattedSelection();if(!i.length)return;const a=e.getSelectedText(),c=this.redactionSelection$.get(n);null==c||c.emit([]),e.clear(),a.wait(e=>{const t=e.join(" ");this.createRedactionsFromSelection(n,i,t)},()=>{this.createRedactionsFromSelection(n,i)})}),c=e.onMarqueeChange(e=>{var t;const o=this.getDocumentState(n);(null==o?void 0:o.isRedacting)&&(null==(t=this.redactionMarquee$.get(n))||t.emit({pageIndex:e.pageIndex,rect:e.rect,modeId:e.modeId}))}),s=e.onMarqueeEnd(e=>{const o=this.getDocumentState(n);if((null==o?void 0:o.isRedacting)&&this.checkPermission(n,t.PdfPermissionFlag.ModifyContents))if(this.useAnnotationMode)this.createRedactAnnotationFromArea(n,e.pageIndex,e.rect);else{const o=this.config.drawBlackBoxes?"#000000":"transparent",i={id:t.uuidV4(),kind:"area",page:e.pageIndex,rect:e.rect,source:"legacy",markColor:"#FF0000",redactionColor:o};this.dispatch(m(n,[i])),this.selectPending(e.pageIndex,i.id,n)}}),d=e.onEmptySpaceClick(()=>{this.deselectPending(n)});o.push(i,a,c,s,d)}if(this.useAnnotationMode&&this.annotationCapability){const e=this.annotationCapability.forDocument(n),i=e.onAnnotationEvent(e=>{var o;if("loaded"===e.type)return void this.syncFromAnnotationLoad(n);if((null==(o=e.annotation)?void 0:o.type)!==t.PdfAnnotationSubtype.REDACT)return;const i=e.annotation;"create"===e.type?(this.syncFromAnnotationCreate(n,i),this.events$.emit({type:"add",documentId:n,items:[this.annotationToRedactionItem(i)]})):"update"===e.type?(this.logger.debug("RedactionPlugin","AnnotationUpdated",{documentId:n,redactAnno:i,patch:e.patch}),this.syncFromAnnotationUpdate(n,i,e.patch)):"delete"===e.type&&(this.syncFromAnnotationDelete(n,i),this.events$.emit({type:"remove",documentId:n,page:i.pageIndex,id:i.id}))}),a=e.onStateChange(()=>{this.syncSelectionFromAnnotation(n)});o.push(i,a)}this.documentUnsubscribers.set(n,o),this.logger.debug("RedactionPlugin","DocumentOpened",`Initialized redaction state for document: ${n}`)}onDocumentLoaded(e){var t,n,i;null==(t=this.selectionCapability)||t.enableForMode(o.Redact,{enableSelection:!0,showSelectionRects:!1,enableMarquee:!0,showMarqueeRects:!1},e),null==(n=this.selectionCapability)||n.enableForMode(o.MarqueeRedact,{enableSelection:!1,enableMarquee:!0,showMarqueeRects:!1},e),null==(i=this.selectionCapability)||i.enableForMode(o.RedactSelection,{enableSelection:!0,showSelectionRects:!1},e)}onDocumentClosed(e){this.dispatch(function(e){return{type:a,payload:e}}(e));const t=this.redactionSelection$.get(e);null==t||t.clear(),this.redactionSelection$.delete(e);const n=this.redactionMarquee$.get(e);null==n||n.clear(),this.redactionMarquee$.delete(e);const o=this.documentUnsubscribers.get(e);o&&(o.forEach(e=>e()),this.documentUnsubscribers.delete(e)),this.logger.debug("RedactionPlugin","DocumentClosed",`Cleaned up redaction state for document: ${e}`)}async initialize(e){this.logger.info("RedactionPlugin","Initialize","Redaction plugin initialized")}buildCapability(){return{queueCurrentSelectionAsPending:()=>this.queueCurrentSelectionAsPending(),enableRedact:()=>this.enableRedact(),toggleRedact:()=>this.toggleRedact(),isRedactActive:()=>this.isRedactActive(),endRedact:()=>this.endRedact(),enableMarqueeRedact:()=>this.enableMarqueeRedact(),toggleMarqueeRedact:()=>this.toggleMarqueeRedact(),isMarqueeRedactActive:()=>this.isMarqueeRedactActive(),enableRedactSelection:()=>this.enableRedactSelection(),toggleRedactSelection:()=>this.toggleRedactSelection(),isRedactSelectionActive:()=>this.isRedactSelectionActive(),addPending:e=>this.addPendingItems(e),removePending:(e,t)=>this.removePendingItem(e,t),clearPending:()=>this.clearPendingItems(),commitAllPending:()=>this.commitAllPending(),commitPending:(e,t)=>this.commitPendingOne(e,t),selectPending:(e,t)=>this.selectPending(e,t),getSelectedPending:()=>this.getSelectedPending(),deselectPending:()=>this.deselectPending(),getState:()=>this.getDocumentStateOrThrow(),forDocument:e=>this.createRedactionScope(e),onPendingChange:this.pending$.on,onSelectedChange:this.selected$.on,onRedactionEvent:this.events$.on,onStateChange:this.state$.on}}createRedactionScope(e){return{queueCurrentSelectionAsPending:()=>this.queueCurrentSelectionAsPending(e),enableRedact:()=>this.enableRedact(e),toggleRedact:()=>this.toggleRedact(e),isRedactActive:()=>this.isRedactActive(e),endRedact:()=>this.endRedact(e),enableMarqueeRedact:()=>this.enableMarqueeRedact(e),toggleMarqueeRedact:()=>this.toggleMarqueeRedact(e),isMarqueeRedactActive:()=>this.isMarqueeRedactActive(e),enableRedactSelection:()=>this.enableRedactSelection(e),toggleRedactSelection:()=>this.toggleRedactSelection(e),isRedactSelectionActive:()=>this.isRedactSelectionActive(e),addPending:t=>this.addPendingItems(t,e),removePending:(t,n)=>this.removePendingItem(t,n,e),clearPending:()=>this.clearPendingItems(e),commitAllPending:()=>this.commitAllPending(e),commitPending:(t,n)=>this.commitPendingOne(t,n,e),selectPending:(t,n)=>this.selectPending(t,n,e),getSelectedPending:()=>this.getSelectedPending(e),deselectPending:()=>this.deselectPending(e),getState:()=>this.getDocumentStateOrThrow(e),onPendingChange:t=>this.pending$.on(n=>{n.documentId===e&&t(n.pending)}),onSelectedChange:t=>this.selected$.on(n=>{n.documentId===e&&t(n.selected)}),onRedactionEvent:t=>this.events$.on(n=>{n.documentId===e&&t(n)}),onStateChange:t=>this.state$.on(n=>{n.documentId===e&&t(n.state)})}}getPendingFromAnnotations(e){if(!this.annotationCapability)return{};try{const n=this.annotationCapability.forDocument(e).getState(),o={};for(const e of Object.values(n.byUid))if(e.object.type===t.PdfAnnotationSubtype.REDACT){const t=this.annotationToRedactionItem(e.object),n=e.object.pageIndex;(o[n]??(o[n]=[])).push(t)}return o}catch{return{}}}getDocumentState(e){const t=e??this.getActiveDocumentId();return this.state.documents[t]??null}getDocumentStateOrThrow(e){const t=this.getDocumentState(e);if(!t)throw new Error(`Redaction state not found for document: ${e??"active"}`);return t}isRedactTool(e){return(null==e?void 0:e.id)===b.id&&e.defaults.type===t.PdfAnnotationSubtype.REDACT}getRedactTool(){var e;const t=null==(e=this.annotationCapability)?void 0:e.getTool("redact");return this.isRedactTool(t)?t:void 0}syncFromAnnotationCreate(e,t){const n=this.annotationToRedactionItem(t);this.dispatch(m(e,[n]))}syncFromAnnotationUpdate(e,t,n){if(!("rect"in n||"segmentRects"in n||"strokeColor"in n||"color"in n))return;const o={};n.rect&&(o.rect=n.rect),n.segmentRects&&(o.rects=n.segmentRects),n.strokeColor&&(o.markColor=n.strokeColor),n.color&&(o.redactionColor=n.color),this.logger.debug("RedactionPlugin","AnnotationUpdated",{documentId:e,annotation:t,patch:o}),this.dispatch(y(e,t.pageIndex,t.id,o))}syncFromAnnotationDelete(e,t){this.dispatch(p(e,t.pageIndex,t.id))}syncFromAnnotationLoad(e){const t=this.getPendingFromAnnotations(e);this.dispatch(f(e));for(const[,n]of Object.entries(t))n.length>0&&this.dispatch(m(e,n))}syncSelectionFromAnnotation(e){var n;const o=null==(n=this.annotationCapability)?void 0:n.forDocument(e).getState();if(!o)return;const i=o.selectedUids.map(e=>o.byUid[e]).find(e=>(null==e?void 0:e.object.type)===t.PdfAnnotationSubtype.REDACT);if(i){const t=i.object;this.dispatch(v(e,t.pageIndex,t.id))}else{const t=this.getDocumentState(e);(null==t?void 0:t.selected)&&this.dispatch(R(e))}}addPendingItems(e,n){const o=n??this.getActiveDocumentId();if(this.checkPermission(o,t.PdfPermissionFlag.ModifyContents)){if(this.useAnnotationMode){if(!this.annotationCapability)return;const t=this.annotationCapability.forDocument(o);for(const n of e){const e=this.redactionItemToAnnotation(n);t.createAnnotation(n.page,e)}if(e.length>0){const n=e[e.length-1];t.selectAnnotation(n.page,n.id)}}else this.dispatch(m(o,e));this.events$.emit({type:"add",documentId:o,items:e})}else this.logger.debug("RedactionPlugin","AddPendingItems",`Cannot add redactions: document ${o} lacks ModifyContents permission`)}removePendingItem(e,t,n){var o;const i=n??this.getActiveDocumentId();this.useAnnotationMode?null==(o=this.annotationCapability)||o.forDocument(i).deleteAnnotation(e,t):this.dispatch(p(i,e,t)),this.events$.emit({type:"remove",documentId:i,page:e,id:t})}clearPendingItems(e){var t;const n=e??this.getActiveDocumentId();if(this.useAnnotationMode){const e=this.getPendingFromAnnotations(n),o=null==(t=this.annotationCapability)?void 0:t.forDocument(n);for(const[t,n]of Object.entries(e)){const e=Number(t);for(const t of n)null==o||o.deleteAnnotation(e,t.id)}}else this.dispatch(f(n));this.events$.emit({type:"clear",documentId:n})}selectPending(e,t,n){var o,i,a;const c=n??this.getActiveDocumentId();this.useAnnotationMode?null==(o=this.annotationCapability)||o.forDocument(c).selectAnnotation(e,t):(this.dispatch(v(c,e,t)),null==(i=this.interactionManagerCapability)||i.claimPageActivity(c,"redaction-selection",e)),null==(a=this.selectionCapability)||a.forDocument(c).clear()}getSelectedPending(e){var t;const n=e??this.getActiveDocumentId();return(null==(t=this.getDocumentState(n))?void 0:t.selected)??null}deselectPending(e){var t,n;const o=e??this.getActiveDocumentId();this.useAnnotationMode?null==(t=this.annotationCapability)||t.forDocument(o).deselectAnnotation():(this.dispatch(R(o)),null==(n=this.interactionManagerCapability)||n.releasePageActivity(o,"redaction-selection"))}enableRedactSelection(e){var n;const i=e??this.getActiveDocumentId();this.checkPermission(i,t.PdfPermissionFlag.ModifyContents)?null==(n=this.interactionManagerCapability)||n.forDocument(i).activate(o.RedactSelection):this.logger.debug("RedactionPlugin","EnableRedactSelection",`Cannot enable redact selection: document ${i} lacks ModifyContents permission`)}toggleRedactSelection(e){var n;const i=e??this.getActiveDocumentId(),a=null==(n=this.interactionManagerCapability)?void 0:n.forDocument(i);if((null==a?void 0:a.getActiveMode())===o.RedactSelection)null==a||a.activateDefaultMode();else{if(!this.checkPermission(i,t.PdfPermissionFlag.ModifyContents))return;null==a||a.activate(o.RedactSelection)}}isRedactSelectionActive(e){var t;const n=e??this.getActiveDocumentId(),i=null==(t=this.interactionManagerCapability)?void 0:t.forDocument(n).getActiveMode();return i===o.Redact||i===o.RedactSelection}enableMarqueeRedact(e){var n;const i=e??this.getActiveDocumentId();this.checkPermission(i,t.PdfPermissionFlag.ModifyContents)?null==(n=this.interactionManagerCapability)||n.forDocument(i).activate(o.MarqueeRedact):this.logger.debug("RedactionPlugin","EnableMarqueeRedact",`Cannot enable marquee redact: document ${i} lacks ModifyContents permission`)}toggleMarqueeRedact(e){var n;const i=e??this.getActiveDocumentId(),a=null==(n=this.interactionManagerCapability)?void 0:n.forDocument(i);if((null==a?void 0:a.getActiveMode())===o.MarqueeRedact)null==a||a.activateDefaultMode();else{if(!this.checkPermission(i,t.PdfPermissionFlag.ModifyContents))return;null==a||a.activate(o.MarqueeRedact)}}isMarqueeRedactActive(e){var t;const n=e??this.getActiveDocumentId(),i=null==(t=this.interactionManagerCapability)?void 0:t.forDocument(n).getActiveMode();return i===o.Redact||i===o.MarqueeRedact}enableRedact(e){var n;const i=e??this.getActiveDocumentId();this.checkPermission(i,t.PdfPermissionFlag.ModifyContents)?null==(n=this.interactionManagerCapability)||n.forDocument(i).activate(o.Redact):this.logger.debug("RedactionPlugin","EnableRedact",`Cannot enable redact mode: document ${i} lacks ModifyContents permission`)}toggleRedact(e){var n;const i=e??this.getActiveDocumentId(),a=null==(n=this.interactionManagerCapability)?void 0:n.forDocument(i);if((null==a?void 0:a.getActiveMode())===o.Redact)null==a||a.activateDefaultMode();else{if(!this.checkPermission(i,t.PdfPermissionFlag.ModifyContents))return;null==a||a.activate(o.Redact)}}isRedactActive(e){var t;const n=e??this.getActiveDocumentId();return(null==(t=this.interactionManagerCapability)?void 0:t.forDocument(n).getActiveMode())===o.Redact}endRedact(e){var t;const n=e??this.getActiveDocumentId();null==(t=this.interactionManagerCapability)||t.forDocument(n).activateDefaultMode()}onRedactionSelectionChange(e,t){const n=this.redactionSelection$.get(e);return(null==n?void 0:n.on(t))??(()=>{})}onRedactionMarqueeChange(e,t){const n=this.redactionMarquee$.get(e);return(null==n?void 0:n.on(t))??(()=>{})}getPreviewStrokeColor(){var e;return this.useAnnotationMode?(null==(e=this.getRedactTool())?void 0:e.defaults.strokeColor)??"#FF0000":"#FF0000"}queueCurrentSelectionAsPending(e){const n=e??this.getActiveDocumentId();if(!this.selectionCapability)return t.PdfTaskHelper.reject({code:t.PdfErrorCode.NotFound,message:"[RedactionPlugin] selection plugin required"});const o=this.coreState.core.documents[n];if(!(null==o?void 0:o.document))return t.PdfTaskHelper.reject({code:t.PdfErrorCode.NotFound,message:"Document not found"});const i=this.selectionCapability.forDocument(n),a=i.getFormattedSelection();if(!a.length)return t.PdfTaskHelper.resolve(!0);const c=i.getSelectedText(),s=this.redactionSelection$.get(n);null==s||s.emit([]),i.clear(),this.useAnnotationMode||this.enableRedactSelection(n);const d=new t.Task;return c.wait(e=>{const t=e.join(" ");this.createRedactionsFromSelection(n,a,t),d.resolve(!0)},()=>{this.createRedactionsFromSelection(n,a),d.resolve(!0)}),d}commitPendingOne(e,n,o){const i=o??this.getActiveDocumentId();if(!this.checkPermission(i,t.PdfPermissionFlag.ModifyContents))return this.logger.debug("RedactionPlugin","CommitPendingOne",`Cannot commit redaction: document ${i} lacks ModifyContents permission`),t.PdfTaskHelper.reject({code:t.PdfErrorCode.Security,message:"Document lacks ModifyContents permission"});const a=this.coreState.core.documents[i];if(!(null==a?void 0:a.document))return t.PdfTaskHelper.reject({code:t.PdfErrorCode.NotFound,message:"Document not found"});const c=a.document.pages[e];if(!c)return t.PdfTaskHelper.reject({code:t.PdfErrorCode.NotFound,message:"Page not found"});if(this.useAnnotationMode)return this.logger.debug("RedactionPlugin","CommitPendingOne",`Applying redaction in annotation mode: page ${e}, id ${n}`),this.applyRedactionAnnotationMode(i,a.document,c,n);const s=this.getDocumentState(i);if(!s)return t.PdfTaskHelper.reject({code:t.PdfErrorCode.NotFound,message:"Document state not found"});const d=(s.pending[e]??[]).find(e=>e.id===n);return d?this.commitPendingOneLegacy(i,a.document,c,e,d):(this.logger.debug("RedactionPlugin","CommitPendingOne",`No pending item found for page ${e}, id ${n}`),t.PdfTaskHelper.resolve(!0))}commitPendingOneLegacy(n,o,i,a,c){const s="text"===c.kind?c.rects:[c.rect],d=new t.Task;return this.engine.redactTextInRects(o,i,s,{drawBlackBoxes:this.config.drawBlackBoxes}).wait(()=>{this.dispatch(p(n,a,c.id)),this.dispatchCoreAction(e.refreshPages(n,[a])),this.events$.emit({type:"commit",documentId:n,success:!0}),d.resolve(!0)},e=>{this.events$.emit({type:"commit",documentId:n,success:!1,error:e.reason}),d.reject({code:t.PdfErrorCode.Unknown,message:"Failed to commit redactions"})}),d}applyRedactionAnnotationMode(n,o,i,a){var c;const s=new t.Task,d=null==(c=this.annotationCapability)?void 0:c.forDocument(n).getAnnotationById(a);return this.logger.debug("RedactionPlugin","ApplyRedactionAnnotationMode",`Looking for annotation ${a}, found: ${!!d}, type: ${null==d?void 0:d.object.type}`),d&&d.object.type===t.PdfAnnotationSubtype.REDACT?(this.logger.debug("RedactionPlugin","ApplyRedactionAnnotationMode",`Calling engine.applyRedaction for annotation ${a} on page ${i.index}`),this.engine.applyRedaction(o,i,d.object).wait(()=>{var t,o;this.logger.debug("RedactionPlugin","ApplyRedactionAnnotationMode",`Successfully applied redaction ${a} on page ${i.index}`),null==(t=this.annotationCapability)||t.forDocument(n).purgeAnnotation(i.index,a),this.dispatch(p(n,i.index,a)),null==(o=this.historyCapability)||o.forDocument(n).purgeByMetadata(e=>{var t;return(null==(t=null==e?void 0:e.annotationIds)?void 0:t.includes(a))??!1},"annotations"),this.dispatchCoreAction(e.refreshPages(n,[i.index])),this.events$.emit({type:"commit",documentId:n,success:!0}),s.resolve(!0)},e=>{var o;this.logger.error("RedactionPlugin","ApplyRedactionAnnotationMode",`Failed to apply redaction ${a}: ${(null==(o=e.reason)?void 0:o.message)??"Unknown error"}`),this.events$.emit({type:"commit",documentId:n,success:!1,error:e.reason}),s.reject({code:t.PdfErrorCode.Unknown,message:"Failed to apply redaction"})}),s):(this.logger.warn("RedactionPlugin","ApplyRedactionAnnotationMode",`Redaction annotation not found or wrong type: ${a}`),t.PdfTaskHelper.reject({code:t.PdfErrorCode.NotFound,message:"Redaction annotation not found"}))}commitAllPending(e){const n=e??this.getActiveDocumentId();if(!this.checkPermission(n,t.PdfPermissionFlag.ModifyContents))return this.logger.debug("RedactionPlugin","CommitAllPending",`Cannot commit redactions: document ${n} lacks ModifyContents permission`),t.PdfTaskHelper.reject({code:t.PdfErrorCode.Security,message:"Document lacks ModifyContents permission"});const o=this.coreState.core.documents[n];if(!(null==o?void 0:o.document))return t.PdfTaskHelper.reject({code:t.PdfErrorCode.NotFound,message:"Document not found"});const i=this.getDocumentState(n);return i?this.useAnnotationMode?this.applyAllRedactionsAnnotationMode(n,o.document):this.commitAllPendingLegacy(n,o.document,i):t.PdfTaskHelper.reject({code:t.PdfErrorCode.NotFound,message:"Document state not found"})}commitAllPendingLegacy(n,o,i){const a=new Map;for(const[e,t]of Object.entries(i.pending)){const n=Number(e),o=a.get(n)??[];for(const e of t)"text"===e.kind?o.push(...e.rects):o.push(e.rect);a.set(n,o)}const c=Array.from(a.entries()).filter(([e,t])=>t.length>0).map(([e])=>e),s=[];for(const[e,t]of a){const n=o.pages[e];n&&(t.length&&s.push(this.engine.redactTextInRects(o,n,t,{drawBlackBoxes:this.config.drawBlackBoxes})))}const d=new t.Task;return t.Task.all(s).wait(()=>{this.dispatch(f(n)),this.dispatchCoreAction(e.refreshPages(n,c)),this.events$.emit({type:"commit",documentId:n,success:!0}),d.resolve(!0)},e=>{this.events$.emit({type:"commit",documentId:n,success:!1,error:e.reason}),d.reject({code:t.PdfErrorCode.Unknown,message:"Failed to commit redactions"})}),d}applyAllRedactionsAnnotationMode(n,o){const i=this.annotationCapability;if(!i)return t.PdfTaskHelper.reject({code:t.PdfErrorCode.NotFound,message:"Annotation capability not found"});const a=i.forDocument(n).getState(),c=new Map;for(const e of Object.values(a.byUid))if(e.object.type===t.PdfAnnotationSubtype.REDACT){const t=c.get(e.object.pageIndex)??[];t.push(e.object.id),c.set(e.object.pageIndex,t)}const s=Array.from(c.keys());if(0===s.length)return t.PdfTaskHelper.resolve(!0);const d=[];for(const e of s){const t=o.pages[e];t&&d.push(this.engine.applyAllRedactions(o,t))}const r=new t.Task;return t.Task.all(d).wait(()=>{var t;const o=i.forDocument(n),a=[];for(const[e,i]of c)for(const t of i)o.purgeAnnotation(e,t),this.dispatch(p(n,e,t)),a.push(t);a.length>0&&(null==(t=this.historyCapability)||t.forDocument(n).purgeByMetadata(e=>{var t;return(null==(t=null==e?void 0:e.annotationIds)?void 0:t.some(e=>a.includes(e)))??!1},"annotations")),this.dispatchCoreAction(e.refreshPages(n,s)),this.events$.emit({type:"commit",documentId:n,success:!0}),r.resolve(!0)},e=>{this.events$.emit({type:"commit",documentId:n,success:!1,error:e.reason}),r.reject({code:t.PdfErrorCode.Unknown,message:"Failed to apply redactions"})}),r}createRedactAnnotationsFromSelection(e,n,o){var i;if(!this.annotationCapability)return[];const a=this.annotationCapability.forDocument(e),c=null==(i=this.getRedactTool())?void 0:i.defaults,s=[];for(const d of n){const e=t.uuidV4();s.push(e);const i={...c,id:e,type:t.PdfAnnotationSubtype.REDACT,pageIndex:d.pageIndex,rect:d.rect,segmentRects:d.segmentRects,...o?{custom:{text:o}}:{},created:new Date};a.createAnnotation(d.pageIndex,i),d===n[n.length-1]&&a.selectAnnotation(d.pageIndex,e)}if(o)for(let t=0;t<s.length;t++){const i=n[t].pageIndex;this.dispatch(y(e,i,s[t],{text:o}))}return s}createLegacyRedactionsFromSelection(e,n,o){const i=this.config.drawBlackBoxes?"#000000":"transparent",a=n.map(e=>({id:t.uuidV4(),kind:"text",page:e.pageIndex,rect:e.rect,rects:e.segmentRects,source:"legacy",markColor:"#FF0000",redactionColor:i,text:o}));this.dispatch(m(e,a)),a.length&&this.selectPending(a[a.length-1].page,a[a.length-1].id,e)}createRedactionsFromSelection(e,t,n){this.useAnnotationMode?this.createRedactAnnotationsFromSelection(e,t,n):this.createLegacyRedactionsFromSelection(e,t,n)}createRedactAnnotationFromArea(e,n,o){var i;if(!this.annotationCapability)return;const a=this.annotationCapability.forDocument(e),c=null==(i=this.getRedactTool())?void 0:i.defaults,s=t.uuidV4(),d={...c,id:s,type:t.PdfAnnotationSubtype.REDACT,pageIndex:n,rect:o,segmentRects:[],created:new Date};a.createAnnotation(n,d),a.selectAnnotation(n,s)}redactionItemToAnnotation(e){var n;return{...(null==(n=this.getRedactTool())?void 0:n.defaults)??{},id:e.id,type:t.PdfAnnotationSubtype.REDACT,pageIndex:e.page,rect:e.rect,segmentRects:"text"===e.kind?e.rects:[],created:new Date}}annotationToRedactionItem(e){var t;const n=e.strokeColor??"#FF0000",o=e.color??"transparent";return e.segmentRects&&e.segmentRects.length>0?{id:e.id,kind:"text",page:e.pageIndex,rect:e.rect,rects:e.segmentRects,source:"annotation",markColor:n,redactionColor:o,...(null==(t=e.custom)?void 0:t.text)?{text:e.custom.text}:{}}:{id:e.id,kind:"area",page:e.pageIndex,rect:e.rect,source:"annotation",markColor:n,redactionColor:o}}emitPendingChange(e){const t=this.getDocumentState(e);t&&this.pending$.emit({documentId:e,pending:t.pending})}emitSelectedChange(e){const t=this.getDocumentState(e);t&&this.selected$.emit({documentId:e,selected:t.selected})}emitStateChange(e){const t=this.getDocumentState(e);t&&this.state$.emit({documentId:e,state:t})}onStoreUpdated(e,t){for(const n in t.documents){t.documents[n]&&(this.emitPendingChange(n),this.emitSelectedChange(n),this.emitStateChange(n))}}async destroy(){this.pending$.clear(),this.selected$.clear(),this.state$.clear(),this.events$.clear(),this.redactionSelection$.forEach(e=>e.clear()),this.redactionSelection$.clear(),this.redactionMarquee$.forEach(e=>e.clear()),this.redactionMarquee$.clear(),this.documentUnsubscribers.forEach(e=>{e.forEach(e=>e())}),this.documentUnsubscribers.clear(),await super.destroy()}};S.id="redaction";let D=S;const I="redaction",T={id:I,name:"Redaction Plugin",version:"1.0.0",provides:["redaction"],requires:[],optional:["interaction-manager","selection","annotation"],defaultConfig:{drawBlackBoxes:!0}},E={manifest:T,create:(e,t)=>new D(I,e,t),reducer:(e=A,t)=>{switch(t.type){case i:{const{documentId:n,state:o}=t.payload;return{...e,documents:{...e.documents,[n]:o},activeDocumentId:e.activeDocumentId??n}}case a:{const n=t.payload,{[n]:o,...i}=e.documents;return{...e,documents:i,activeDocumentId:e.activeDocumentId===n?null:e.activeDocumentId}}case"REDACTION/SET_ACTIVE_DOCUMENT":return{...e,activeDocumentId:t.payload};case d:{const{documentId:n,items:o}=t.payload,i=e.documents[n];if(!i)return e;const a={...i.pending};for(const e of o){const t=a[e.page]??[];t.some(t=>t.id===e.id)||(a[e.page]=t.concat(e))}return{...e,documents:{...e.documents,[n]:{...i,pending:a,pendingCount:C(a)}}}}case r:{const{documentId:n,page:o,id:i}=t.payload,a=e.documents[n];if(!a)return e;const c=(a.pending[o]??[]).filter(e=>e.id!==i),s={...a.pending,[o]:c},d=a.selected&&!(a.selected.page===o&&a.selected.id===i);return{...e,documents:{...e.documents,[n]:{...a,pending:s,pendingCount:C(s),selected:d?a.selected:null}}}}case l:{const{documentId:n,page:o,id:i,patch:a}=t.payload,c=e.documents[n];if(!c)return e;const s=(c.pending[o]??[]).map(e=>e.id===i?{...e,...a}:e);return{...e,documents:{...e.documents,[n]:{...c,pending:{...c.pending,[o]:s}}}}}case u:{const n=t.payload,o=e.documents[n];return o?{...e,documents:{...e.documents,[n]:{...o,pending:{},pendingCount:0,selected:null}}}:e}case g:{const{documentId:n,page:o,id:i}=t.payload,a=e.documents[n];return a?{...e,documents:{...e.documents,[n]:{...a,selected:{page:o,id:i}}}}:e}case h:{const n=t.payload,o=e.documents[n];return o?{...e,documents:{...e.documents,[n]:{...o,selected:null}}}:e}case c:{const{documentId:n,mode:o}=t.payload,i=e.documents[n];return i?{...e,documents:{...e.documents,[n]:{...i,isRedacting:!0,activeType:o}}}:e}case s:{const n=t.payload,o=e.documents[n];return o?{...e,documents:{...e.documents,[n]:{...o,isRedacting:!1,activeType:null}}}:e}case"SET_ACTIVE_TYPE":{const{documentId:n,mode:o}=t.payload,i=e.documents[n];return i?{...e,documents:{...e.documents,[n]:{...i,activeType:o}}}:e}default:return e}},initialState:A};exports.REDACTION_PLUGIN_ID=I,exports.RedactionMode=o,exports.RedactionPlugin=D,exports.RedactionPluginPackage=E,exports.getDocumentPendingCount=(e,t)=>{var n;return(null==(n=e.documents[t])?void 0:n.pendingCount)??0},exports.getPendingRedactionsCount=e=>e.pendingCount,exports.getTotalPendingCount=e=>Object.values(e.documents).reduce((e,t)=>e+t.pendingCount,0),exports.hasPendingRedactions=e=>e.pendingCount>0,exports.initialDocumentState=P,exports.initialState=A,exports.manifest=T,exports.redactTool=b,exports.redactTools=M;
|
|
2
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let _embedpdf_core = require("@embedpdf/core");
|
|
3
|
+
let _embedpdf_plugin_annotation_internal = require("@embedpdf/plugin-annotation/internal");
|
|
4
|
+
let _embedpdf_plugin_interaction = require("@embedpdf/plugin-interaction");
|
|
5
|
+
let _embedpdf_plugin_selection = require("@embedpdf/plugin-selection");
|
|
6
|
+
//#region src/capability.ts
|
|
7
|
+
/** Applying destroys content — its own granted power, narrower than annotate. */
|
|
8
|
+
const REDACT_CAPABILITY = "doc.redact";
|
|
9
|
+
/** The annotation plugin's model-id convention for a durable ref. */
|
|
10
|
+
const idOf = (ref) => ref.kind === "objectNumber" ? `obj:${ref.annotObjectNumber}` : ref.kind === "nm" ? `nm:${ref.nm}` : `idx:${ref.pageObjectNumber}:${ref.index}`;
|
|
11
|
+
/** The PDF-space regions a redact mark targets: its quads' boxes, else `/Rect`. */
|
|
12
|
+
function regionsOf(dto) {
|
|
13
|
+
if (dto.quadPoints.length === 0) return [dto.rect];
|
|
14
|
+
return dto.quadPoints.map((q) => {
|
|
15
|
+
const xs = [
|
|
16
|
+
q.p1.x,
|
|
17
|
+
q.p2.x,
|
|
18
|
+
q.p3.x,
|
|
19
|
+
q.p4.x
|
|
20
|
+
];
|
|
21
|
+
const ys = [
|
|
22
|
+
q.p1.y,
|
|
23
|
+
q.p2.y,
|
|
24
|
+
q.p3.y,
|
|
25
|
+
q.p4.y
|
|
26
|
+
];
|
|
27
|
+
return {
|
|
28
|
+
left: Math.min(...xs),
|
|
29
|
+
right: Math.max(...xs),
|
|
30
|
+
bottom: Math.min(...ys),
|
|
31
|
+
top: Math.max(...ys)
|
|
32
|
+
};
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
/** Positive-area intersection — the engine's collateral rule. */
|
|
36
|
+
const intersects = (a, b) => Math.min(a.right, b.right) > Math.max(a.left, b.left) && Math.min(a.top, b.top) > Math.max(a.bottom, b.bottom);
|
|
37
|
+
function createRedactionCapability(ctx) {
|
|
38
|
+
const anno = ctx.get(_embedpdf_plugin_annotation_internal.AnnotationToken);
|
|
39
|
+
const appliedCallbacks = /* @__PURE__ */ new Set();
|
|
40
|
+
const requireDoc = () => {
|
|
41
|
+
const doc = ctx.doc;
|
|
42
|
+
if (!doc) throw new Error("[redaction] no document bound");
|
|
43
|
+
return doc;
|
|
44
|
+
};
|
|
45
|
+
const requireService = () => {
|
|
46
|
+
const doc = requireDoc();
|
|
47
|
+
if (!doc.redaction) throw new Error("[redaction] engine has no redaction service");
|
|
48
|
+
return doc.redaction;
|
|
49
|
+
};
|
|
50
|
+
const pons = () => (ctx.document()?.pages ?? []).map((p) => p.pageObjectNumber);
|
|
51
|
+
const pageIndexOf = (pon) => ctx.document()?.pages.find((p) => p.pageObjectNumber === pon)?.index ?? -1;
|
|
52
|
+
const pendingOn = (pon) => anno.list(pon).filter((a) => a.subtype === "redact");
|
|
53
|
+
const collectPending = () => {
|
|
54
|
+
const items = [];
|
|
55
|
+
for (const pon of pons()) for (const dto of pendingOn(pon)) items.push({
|
|
56
|
+
id: idOf(dto.ref),
|
|
57
|
+
ref: dto.ref,
|
|
58
|
+
pageObjectNumber: pon,
|
|
59
|
+
pageIndex: pageIndexOf(pon),
|
|
60
|
+
kind: dto.quadPoints.length > 0 ? "text" : "area",
|
|
61
|
+
overlayText: dto.overlayText
|
|
62
|
+
});
|
|
63
|
+
return items;
|
|
64
|
+
};
|
|
65
|
+
const fireApplied = (result) => {
|
|
66
|
+
for (const cb of appliedCallbacks) try {
|
|
67
|
+
cb(result);
|
|
68
|
+
} catch (err) {
|
|
69
|
+
console.error("[redaction] onApplied callback failed", err);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
const runApply = async (scope) => {
|
|
73
|
+
const service = requireService();
|
|
74
|
+
ctx.dispatch({ type: "APPLY_STARTED" });
|
|
75
|
+
try {
|
|
76
|
+
const result = await service.apply(scope);
|
|
77
|
+
ctx.dispatch({
|
|
78
|
+
type: "APPLY_FINISHED",
|
|
79
|
+
result
|
|
80
|
+
});
|
|
81
|
+
fireApplied(result);
|
|
82
|
+
return result;
|
|
83
|
+
} catch (err) {
|
|
84
|
+
ctx.dispatch({
|
|
85
|
+
type: "APPLY_FINISHED",
|
|
86
|
+
result: null
|
|
87
|
+
});
|
|
88
|
+
throw err;
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
const doc = ctx.doc;
|
|
92
|
+
if (doc) ctx.cleanup(doc.events.subscribe((event) => {
|
|
93
|
+
if (event.type !== "redaction.applied") return;
|
|
94
|
+
if (event.origin.kind !== "remote") return;
|
|
95
|
+
ctx.dispatch({
|
|
96
|
+
type: "APPLY_FINISHED",
|
|
97
|
+
result: event
|
|
98
|
+
});
|
|
99
|
+
fireApplied(event);
|
|
100
|
+
}));
|
|
101
|
+
return {
|
|
102
|
+
canApply: () => (ctx.doc?.redaction !== void 0 && ctx.doc?.security.allows(REDACT_CAPABILITY)) ?? false,
|
|
103
|
+
isApplying: () => ctx.getState().applying,
|
|
104
|
+
lastResult: () => ctx.getState().lastResult,
|
|
105
|
+
enableRedact: () => ctx.tryGet(_embedpdf_plugin_interaction.InteractionToken)?.activateTool("redact"),
|
|
106
|
+
toggleRedact: () => {
|
|
107
|
+
const interaction = ctx.tryGet(_embedpdf_plugin_interaction.InteractionToken);
|
|
108
|
+
if (!interaction) return;
|
|
109
|
+
interaction.activateTool(interaction.activeToolId() === "redact" ? "pointer" : "redact");
|
|
110
|
+
},
|
|
111
|
+
isRedactActive: () => ctx.tryGet(_embedpdf_plugin_interaction.InteractionToken)?.activeToolId() === "redact",
|
|
112
|
+
queueCurrentSelection: async () => {
|
|
113
|
+
const selection = ctx.tryGet(_embedpdf_plugin_selection.SelectionToken);
|
|
114
|
+
if (!selection || !selection.hasSelection()) return false;
|
|
115
|
+
const snapshot = selection.snapshot();
|
|
116
|
+
for (const page of snapshot.pages) {
|
|
117
|
+
if (page.rects.length === 0) continue;
|
|
118
|
+
anno.createMarkup("redact", page.pon, page.rects, "redact");
|
|
119
|
+
}
|
|
120
|
+
selection.clear();
|
|
121
|
+
return true;
|
|
122
|
+
},
|
|
123
|
+
preparePending: async () => {
|
|
124
|
+
await Promise.all(pons().map((pon) => anno.ensurePage(pon)));
|
|
125
|
+
},
|
|
126
|
+
getPending: collectPending,
|
|
127
|
+
pendingCount: () => collectPending().length,
|
|
128
|
+
estimateCollateral: (ids) => {
|
|
129
|
+
const wanted = ids ? new Set(ids) : null;
|
|
130
|
+
let count = 0;
|
|
131
|
+
for (const pon of pons()) {
|
|
132
|
+
const all = anno.list(pon);
|
|
133
|
+
const marks = all.filter((a) => a.subtype === "redact" && (!wanted || wanted.has(idOf(a.ref))));
|
|
134
|
+
if (marks.length === 0) continue;
|
|
135
|
+
const regions = marks.flatMap(regionsOf);
|
|
136
|
+
for (const other of all) {
|
|
137
|
+
if (other.subtype === "redact") continue;
|
|
138
|
+
if (regions.some((r) => intersects(r, other.rect))) count++;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return count;
|
|
142
|
+
},
|
|
143
|
+
setLabel: async (ref, patch) => {
|
|
144
|
+
const current = anno.get(ref);
|
|
145
|
+
if (!current || current.subtype !== "redact") throw new Error("[redaction] setLabel target is not a redact annotation");
|
|
146
|
+
await anno.update(ref, {
|
|
147
|
+
subtype: "redact",
|
|
148
|
+
...patch.overlayText !== void 0 ? { overlayText: patch.overlayText } : {},
|
|
149
|
+
...patch.repeat !== void 0 ? { repeat: patch.repeat } : {},
|
|
150
|
+
fontFamily: current.fontFamily,
|
|
151
|
+
fontSize: current.fontSize,
|
|
152
|
+
fontColor: current.fontColor,
|
|
153
|
+
textAlign: current.textAlign
|
|
154
|
+
});
|
|
155
|
+
},
|
|
156
|
+
apply: async (ids) => {
|
|
157
|
+
const wanted = new Set(ids);
|
|
158
|
+
const refs = collectPending().filter((p) => wanted.has(p.id)).map((p) => p.ref);
|
|
159
|
+
if (refs.length === 0) throw new Error("[redaction] no matching pending redactions");
|
|
160
|
+
return runApply({
|
|
161
|
+
kind: "annotations",
|
|
162
|
+
refs
|
|
163
|
+
});
|
|
164
|
+
},
|
|
165
|
+
applyAll: async () => {
|
|
166
|
+
const pageObjectNumbers = pons();
|
|
167
|
+
if (pageObjectNumbers.length === 0) throw new Error("[redaction] document has no pages");
|
|
168
|
+
return runApply({
|
|
169
|
+
kind: "pages",
|
|
170
|
+
pageObjectNumbers
|
|
171
|
+
});
|
|
172
|
+
},
|
|
173
|
+
onApplied: (cb) => {
|
|
174
|
+
appliedCallbacks.add(cb);
|
|
175
|
+
return () => appliedCallbacks.delete(cb);
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
//#endregion
|
|
180
|
+
//#region src/reducer.ts
|
|
181
|
+
const initialRedactionState = () => ({
|
|
182
|
+
applying: false,
|
|
183
|
+
lastResult: null
|
|
184
|
+
});
|
|
185
|
+
const redactionReducer = (state, action) => {
|
|
186
|
+
switch (action.type) {
|
|
187
|
+
case "APPLY_STARTED": return {
|
|
188
|
+
...state,
|
|
189
|
+
applying: true
|
|
190
|
+
};
|
|
191
|
+
case "APPLY_FINISHED": return {
|
|
192
|
+
applying: false,
|
|
193
|
+
lastResult: action.result ?? state.lastResult
|
|
194
|
+
};
|
|
195
|
+
default: return state;
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
//#endregion
|
|
199
|
+
//#region src/types.ts
|
|
200
|
+
const RedactionToken = (0, _embedpdf_core.createCapabilityToken)("redaction");
|
|
201
|
+
//#endregion
|
|
202
|
+
//#region src/redaction.plugin.ts
|
|
203
|
+
/**
|
|
204
|
+
* Document-scoped redaction plugin — the DESTRUCTIVE half of the two-stage
|
|
205
|
+
* model. Marking is annotation-plane work (the composed `redact` tool ships
|
|
206
|
+
* with plugin-annotation); this plugin wraps `doc.redaction.apply`, projects
|
|
207
|
+
* the pending queue out of annotation state, and estimates collateral for
|
|
208
|
+
* confirm dialogs. It owns no mark state of its own.
|
|
209
|
+
*
|
|
210
|
+
* Trust boundary: on a layered document, applying rewrites the LAYER's bytes;
|
|
211
|
+
* the immutable base keeps the original. See the package README.
|
|
212
|
+
*/
|
|
213
|
+
const redactionPlugin = () => (0, _embedpdf_core.definePlugin)({
|
|
214
|
+
id: "redaction",
|
|
215
|
+
token: RedactionToken,
|
|
216
|
+
scope: "document",
|
|
217
|
+
requires: [_embedpdf_plugin_annotation_internal.AnnotationToken],
|
|
218
|
+
optional: [_embedpdf_plugin_interaction.InteractionToken, _embedpdf_plugin_selection.SelectionToken],
|
|
219
|
+
initialState: initialRedactionState,
|
|
220
|
+
reduce: redactionReducer,
|
|
221
|
+
capability: createRedactionCapability
|
|
222
|
+
});
|
|
223
|
+
//#endregion
|
|
224
|
+
exports.RedactionToken = RedactionToken;
|
|
225
|
+
exports.redactionPlugin = redactionPlugin;
|
|
226
|
+
|
|
227
|
+
//# sourceMappingURL=index.cjs.map
|