@pdfmergy-embedpdf/plugin-attachment 2.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1571 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/attachment-plugin.d.ts +11 -0
- package/dist/lib/index.d.ts +7 -0
- package/dist/lib/manifest.d.ts +4 -0
- package/dist/lib/types.d.ts +13 -0
- package/dist/preact/core.d.ts +1 -0
- package/dist/preact/index.cjs +2 -0
- package/dist/preact/index.cjs.map +1 -0
- package/dist/preact/index.d.ts +1 -0
- package/dist/preact/index.js +1984 -0
- package/dist/preact/index.js.map +1 -0
- package/dist/react/core.d.ts +1 -0
- package/dist/react/index.cjs +2 -0
- package/dist/react/index.cjs.map +1 -0
- package/dist/react/index.d.ts +1 -0
- package/dist/react/index.js +1983 -0
- package/dist/react/index.js.map +1 -0
- package/dist/shared/hooks/index.d.ts +1 -0
- package/dist/shared/hooks/use-attachment.d.ts +11 -0
- package/dist/shared/index.d.ts +2 -0
- package/dist/shared-preact/hooks/index.d.ts +1 -0
- package/dist/shared-preact/hooks/use-attachment.d.ts +11 -0
- package/dist/shared-preact/index.d.ts +2 -0
- package/dist/shared-react/hooks/index.d.ts +1 -0
- package/dist/shared-react/hooks/use-attachment.d.ts +11 -0
- package/dist/shared-react/index.d.ts +2 -0
- package/dist/svelte/hooks/index.d.ts +1 -0
- package/dist/svelte/hooks/use-attachment.d.ts +11 -0
- package/dist/svelte/index.cjs +2 -0
- package/dist/svelte/index.cjs.map +1 -0
- package/dist/svelte/index.d.ts +1 -0
- package/dist/svelte/index.js +1952 -0
- package/dist/svelte/index.js.map +1 -0
- package/dist/vue/hooks/index.d.ts +1 -0
- package/dist/vue/hooks/use-attachment.d.ts +3 -0
- package/dist/vue/index.cjs +2 -0
- package/dist/vue/index.cjs.map +1 -0
- package/dist/vue/index.d.ts +2 -0
- package/dist/vue/index.js +1956 -0
- package/dist/vue/index.js.map +1 -0
- package/package.json +80 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,1571 @@
|
|
|
1
|
+
const PdfSoftHyphenMarker$1 = "";
|
|
2
|
+
const PdfZeroWidthSpace$1 = "";
|
|
3
|
+
const PdfWordJoiner$1 = "";
|
|
4
|
+
const PdfBomOrZwnbsp$1 = "\uFEFF";
|
|
5
|
+
const PdfNonCharacterFFFE$1 = "";
|
|
6
|
+
const PdfNonCharacterFFFF$1 = "";
|
|
7
|
+
const PdfUnwantedTextMarkers$1 = Object.freeze([
|
|
8
|
+
PdfSoftHyphenMarker$1,
|
|
9
|
+
PdfZeroWidthSpace$1,
|
|
10
|
+
PdfWordJoiner$1,
|
|
11
|
+
PdfBomOrZwnbsp$1,
|
|
12
|
+
PdfNonCharacterFFFE$1,
|
|
13
|
+
PdfNonCharacterFFFF$1
|
|
14
|
+
]);
|
|
15
|
+
new RegExp(`[${PdfUnwantedTextMarkers$1.join("")}]`, "g");
|
|
16
|
+
var PdfStandardFont$1 = /* @__PURE__ */ ((PdfStandardFont2) => {
|
|
17
|
+
PdfStandardFont2[PdfStandardFont2["Unknown"] = -1] = "Unknown";
|
|
18
|
+
PdfStandardFont2[PdfStandardFont2["Courier"] = 0] = "Courier";
|
|
19
|
+
PdfStandardFont2[PdfStandardFont2["Courier_Bold"] = 1] = "Courier_Bold";
|
|
20
|
+
PdfStandardFont2[PdfStandardFont2["Courier_BoldOblique"] = 2] = "Courier_BoldOblique";
|
|
21
|
+
PdfStandardFont2[PdfStandardFont2["Courier_Oblique"] = 3] = "Courier_Oblique";
|
|
22
|
+
PdfStandardFont2[PdfStandardFont2["Helvetica"] = 4] = "Helvetica";
|
|
23
|
+
PdfStandardFont2[PdfStandardFont2["Helvetica_Bold"] = 5] = "Helvetica_Bold";
|
|
24
|
+
PdfStandardFont2[PdfStandardFont2["Helvetica_BoldOblique"] = 6] = "Helvetica_BoldOblique";
|
|
25
|
+
PdfStandardFont2[PdfStandardFont2["Helvetica_Oblique"] = 7] = "Helvetica_Oblique";
|
|
26
|
+
PdfStandardFont2[PdfStandardFont2["Times_Roman"] = 8] = "Times_Roman";
|
|
27
|
+
PdfStandardFont2[PdfStandardFont2["Times_Bold"] = 9] = "Times_Bold";
|
|
28
|
+
PdfStandardFont2[PdfStandardFont2["Times_BoldItalic"] = 10] = "Times_BoldItalic";
|
|
29
|
+
PdfStandardFont2[PdfStandardFont2["Times_Italic"] = 11] = "Times_Italic";
|
|
30
|
+
PdfStandardFont2[PdfStandardFont2["Symbol"] = 12] = "Symbol";
|
|
31
|
+
PdfStandardFont2[PdfStandardFont2["ZapfDingbats"] = 13] = "ZapfDingbats";
|
|
32
|
+
return PdfStandardFont2;
|
|
33
|
+
})(PdfStandardFont$1 || {});
|
|
34
|
+
var PdfTextAlignment$1 = /* @__PURE__ */ ((PdfTextAlignment2) => {
|
|
35
|
+
PdfTextAlignment2[PdfTextAlignment2["Left"] = 0] = "Left";
|
|
36
|
+
PdfTextAlignment2[PdfTextAlignment2["Center"] = 1] = "Center";
|
|
37
|
+
PdfTextAlignment2[PdfTextAlignment2["Right"] = 2] = "Right";
|
|
38
|
+
return PdfTextAlignment2;
|
|
39
|
+
})(PdfTextAlignment$1 || {});
|
|
40
|
+
var PdfBlendMode$1 = /* @__PURE__ */ ((PdfBlendMode2) => {
|
|
41
|
+
PdfBlendMode2[PdfBlendMode2["Normal"] = 0] = "Normal";
|
|
42
|
+
PdfBlendMode2[PdfBlendMode2["Multiply"] = 1] = "Multiply";
|
|
43
|
+
PdfBlendMode2[PdfBlendMode2["Screen"] = 2] = "Screen";
|
|
44
|
+
PdfBlendMode2[PdfBlendMode2["Overlay"] = 3] = "Overlay";
|
|
45
|
+
PdfBlendMode2[PdfBlendMode2["Darken"] = 4] = "Darken";
|
|
46
|
+
PdfBlendMode2[PdfBlendMode2["Lighten"] = 5] = "Lighten";
|
|
47
|
+
PdfBlendMode2[PdfBlendMode2["ColorDodge"] = 6] = "ColorDodge";
|
|
48
|
+
PdfBlendMode2[PdfBlendMode2["ColorBurn"] = 7] = "ColorBurn";
|
|
49
|
+
PdfBlendMode2[PdfBlendMode2["HardLight"] = 8] = "HardLight";
|
|
50
|
+
PdfBlendMode2[PdfBlendMode2["SoftLight"] = 9] = "SoftLight";
|
|
51
|
+
PdfBlendMode2[PdfBlendMode2["Difference"] = 10] = "Difference";
|
|
52
|
+
PdfBlendMode2[PdfBlendMode2["Exclusion"] = 11] = "Exclusion";
|
|
53
|
+
PdfBlendMode2[PdfBlendMode2["Hue"] = 12] = "Hue";
|
|
54
|
+
PdfBlendMode2[PdfBlendMode2["Saturation"] = 13] = "Saturation";
|
|
55
|
+
PdfBlendMode2[PdfBlendMode2["Color"] = 14] = "Color";
|
|
56
|
+
PdfBlendMode2[PdfBlendMode2["Luminosity"] = 15] = "Luminosity";
|
|
57
|
+
return PdfBlendMode2;
|
|
58
|
+
})(PdfBlendMode$1 || {});
|
|
59
|
+
const PdfAnnotationFlagName$1 = Object.freeze({
|
|
60
|
+
[
|
|
61
|
+
1
|
|
62
|
+
/* INVISIBLE */
|
|
63
|
+
]: "invisible",
|
|
64
|
+
[
|
|
65
|
+
2
|
|
66
|
+
/* HIDDEN */
|
|
67
|
+
]: "hidden",
|
|
68
|
+
[
|
|
69
|
+
4
|
|
70
|
+
/* PRINT */
|
|
71
|
+
]: "print",
|
|
72
|
+
[
|
|
73
|
+
8
|
|
74
|
+
/* NO_ZOOM */
|
|
75
|
+
]: "noZoom",
|
|
76
|
+
[
|
|
77
|
+
16
|
|
78
|
+
/* NO_ROTATE */
|
|
79
|
+
]: "noRotate",
|
|
80
|
+
[
|
|
81
|
+
32
|
|
82
|
+
/* NO_VIEW */
|
|
83
|
+
]: "noView",
|
|
84
|
+
[
|
|
85
|
+
64
|
|
86
|
+
/* READ_ONLY */
|
|
87
|
+
]: "readOnly",
|
|
88
|
+
[
|
|
89
|
+
128
|
|
90
|
+
/* LOCKED */
|
|
91
|
+
]: "locked",
|
|
92
|
+
[
|
|
93
|
+
256
|
|
94
|
+
/* TOGGLE_NOVIEW */
|
|
95
|
+
]: "toggleNoView"
|
|
96
|
+
});
|
|
97
|
+
Object.entries(
|
|
98
|
+
PdfAnnotationFlagName$1
|
|
99
|
+
).reduce(
|
|
100
|
+
(acc, [bit, name]) => {
|
|
101
|
+
acc[name] = Number(bit);
|
|
102
|
+
return acc;
|
|
103
|
+
},
|
|
104
|
+
{}
|
|
105
|
+
);
|
|
106
|
+
var PdfPermissionFlag = /* @__PURE__ */ ((PdfPermissionFlag2) => {
|
|
107
|
+
PdfPermissionFlag2[PdfPermissionFlag2["Print"] = 4] = "Print";
|
|
108
|
+
PdfPermissionFlag2[PdfPermissionFlag2["ModifyContents"] = 8] = "ModifyContents";
|
|
109
|
+
PdfPermissionFlag2[PdfPermissionFlag2["CopyContents"] = 16] = "CopyContents";
|
|
110
|
+
PdfPermissionFlag2[PdfPermissionFlag2["ModifyAnnotations"] = 32] = "ModifyAnnotations";
|
|
111
|
+
PdfPermissionFlag2[PdfPermissionFlag2["FillForms"] = 256] = "FillForms";
|
|
112
|
+
PdfPermissionFlag2[PdfPermissionFlag2["ExtractForAccessibility"] = 512] = "ExtractForAccessibility";
|
|
113
|
+
PdfPermissionFlag2[PdfPermissionFlag2["AssembleDocument"] = 1024] = "AssembleDocument";
|
|
114
|
+
PdfPermissionFlag2[PdfPermissionFlag2["PrintHighQuality"] = 2048] = "PrintHighQuality";
|
|
115
|
+
PdfPermissionFlag2[PdfPermissionFlag2["AllowAll"] = 3900] = "AllowAll";
|
|
116
|
+
return PdfPermissionFlag2;
|
|
117
|
+
})(PdfPermissionFlag || {});
|
|
118
|
+
class PermissionDeniedError extends Error {
|
|
119
|
+
constructor(requiredFlags, currentPermissions) {
|
|
120
|
+
const flagNames = requiredFlags.map((f) => PdfPermissionFlag[f]).join(", ");
|
|
121
|
+
super(`Permission denied. Required: ${flagNames}`);
|
|
122
|
+
this.requiredFlags = requiredFlags;
|
|
123
|
+
this.currentPermissions = currentPermissions;
|
|
124
|
+
this.name = "PermissionDeniedError";
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
const TEXT_ALIGNMENT_INFOS$1 = Object.freeze([
|
|
128
|
+
{ id: PdfTextAlignment$1.Left, label: "Left", css: "left" },
|
|
129
|
+
{ id: PdfTextAlignment$1.Center, label: "Center", css: "center" },
|
|
130
|
+
{ id: PdfTextAlignment$1.Right, label: "Right", css: "right" }
|
|
131
|
+
]);
|
|
132
|
+
TEXT_ALIGNMENT_INFOS$1.reduce(
|
|
133
|
+
(m, info) => {
|
|
134
|
+
m[info.id] = info;
|
|
135
|
+
return m;
|
|
136
|
+
},
|
|
137
|
+
{}
|
|
138
|
+
);
|
|
139
|
+
TEXT_ALIGNMENT_INFOS$1.reduce(
|
|
140
|
+
(m, info) => {
|
|
141
|
+
m[info.css] = info.id;
|
|
142
|
+
return m;
|
|
143
|
+
},
|
|
144
|
+
{}
|
|
145
|
+
);
|
|
146
|
+
TEXT_ALIGNMENT_INFOS$1.map((info) => ({
|
|
147
|
+
value: info.id,
|
|
148
|
+
label: info.label
|
|
149
|
+
}));
|
|
150
|
+
var PdfStandardFontFamily$1 = /* @__PURE__ */ ((PdfStandardFontFamily2) => {
|
|
151
|
+
PdfStandardFontFamily2["Courier"] = "Courier";
|
|
152
|
+
PdfStandardFontFamily2["Helvetica"] = "Helvetica";
|
|
153
|
+
PdfStandardFontFamily2["Times"] = "Times";
|
|
154
|
+
PdfStandardFontFamily2["Symbol"] = "Symbol";
|
|
155
|
+
PdfStandardFontFamily2["ZapfDingbats"] = "ZapfDingbats";
|
|
156
|
+
PdfStandardFontFamily2["Unknown"] = "Unknown";
|
|
157
|
+
return PdfStandardFontFamily2;
|
|
158
|
+
})(PdfStandardFontFamily$1 || {});
|
|
159
|
+
PdfStandardFont$1.Helvetica;
|
|
160
|
+
const HELVETICA_DESC$1 = {
|
|
161
|
+
id: PdfStandardFont$1.Helvetica,
|
|
162
|
+
family: "Helvetica",
|
|
163
|
+
bold: false,
|
|
164
|
+
italic: false,
|
|
165
|
+
label: "Helvetica",
|
|
166
|
+
css: "Helvetica, Arial, sans-serif"
|
|
167
|
+
};
|
|
168
|
+
const STANDARD_FONT_DESCRIPTORS$1 = Object.freeze([
|
|
169
|
+
{
|
|
170
|
+
id: PdfStandardFont$1.Courier,
|
|
171
|
+
family: "Courier",
|
|
172
|
+
bold: false,
|
|
173
|
+
italic: false,
|
|
174
|
+
label: "Courier",
|
|
175
|
+
css: "Courier, monospace"
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
id: PdfStandardFont$1.Courier_Bold,
|
|
179
|
+
family: "Courier",
|
|
180
|
+
bold: true,
|
|
181
|
+
italic: false,
|
|
182
|
+
label: "Courier Bold",
|
|
183
|
+
css: "Courier, monospace"
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
id: PdfStandardFont$1.Courier_BoldOblique,
|
|
187
|
+
family: "Courier",
|
|
188
|
+
bold: true,
|
|
189
|
+
italic: true,
|
|
190
|
+
label: "Courier Bold Oblique",
|
|
191
|
+
css: "Courier, monospace"
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
id: PdfStandardFont$1.Courier_Oblique,
|
|
195
|
+
family: "Courier",
|
|
196
|
+
bold: false,
|
|
197
|
+
italic: true,
|
|
198
|
+
label: "Courier Oblique",
|
|
199
|
+
css: "Courier, monospace"
|
|
200
|
+
},
|
|
201
|
+
HELVETICA_DESC$1,
|
|
202
|
+
{
|
|
203
|
+
id: PdfStandardFont$1.Helvetica_Bold,
|
|
204
|
+
family: "Helvetica",
|
|
205
|
+
bold: true,
|
|
206
|
+
italic: false,
|
|
207
|
+
label: "Helvetica Bold",
|
|
208
|
+
css: "Helvetica, Arial, sans-serif"
|
|
209
|
+
},
|
|
210
|
+
{
|
|
211
|
+
id: PdfStandardFont$1.Helvetica_BoldOblique,
|
|
212
|
+
family: "Helvetica",
|
|
213
|
+
bold: true,
|
|
214
|
+
italic: true,
|
|
215
|
+
label: "Helvetica Bold Oblique",
|
|
216
|
+
css: "Helvetica, Arial, sans-serif"
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
id: PdfStandardFont$1.Helvetica_Oblique,
|
|
220
|
+
family: "Helvetica",
|
|
221
|
+
bold: false,
|
|
222
|
+
italic: true,
|
|
223
|
+
label: "Helvetica Oblique",
|
|
224
|
+
css: "Helvetica, Arial, sans-serif"
|
|
225
|
+
},
|
|
226
|
+
{
|
|
227
|
+
id: PdfStandardFont$1.Times_Roman,
|
|
228
|
+
family: "Times",
|
|
229
|
+
bold: false,
|
|
230
|
+
italic: false,
|
|
231
|
+
label: "Times Roman",
|
|
232
|
+
css: '"Times New Roman", Times, serif'
|
|
233
|
+
},
|
|
234
|
+
{
|
|
235
|
+
id: PdfStandardFont$1.Times_Bold,
|
|
236
|
+
family: "Times",
|
|
237
|
+
bold: true,
|
|
238
|
+
italic: false,
|
|
239
|
+
label: "Times Bold",
|
|
240
|
+
css: '"Times New Roman", Times, serif'
|
|
241
|
+
},
|
|
242
|
+
{
|
|
243
|
+
id: PdfStandardFont$1.Times_BoldItalic,
|
|
244
|
+
family: "Times",
|
|
245
|
+
bold: true,
|
|
246
|
+
italic: true,
|
|
247
|
+
label: "Times Bold Italic",
|
|
248
|
+
css: '"Times New Roman", Times, serif'
|
|
249
|
+
},
|
|
250
|
+
{
|
|
251
|
+
id: PdfStandardFont$1.Times_Italic,
|
|
252
|
+
family: "Times",
|
|
253
|
+
bold: false,
|
|
254
|
+
italic: true,
|
|
255
|
+
label: "Times Italic",
|
|
256
|
+
css: '"Times New Roman", Times, serif'
|
|
257
|
+
},
|
|
258
|
+
{
|
|
259
|
+
id: PdfStandardFont$1.Symbol,
|
|
260
|
+
family: "Symbol",
|
|
261
|
+
bold: false,
|
|
262
|
+
italic: false,
|
|
263
|
+
label: "Symbol",
|
|
264
|
+
css: "Symbol, serif"
|
|
265
|
+
},
|
|
266
|
+
{
|
|
267
|
+
id: PdfStandardFont$1.ZapfDingbats,
|
|
268
|
+
family: "ZapfDingbats",
|
|
269
|
+
bold: false,
|
|
270
|
+
italic: false,
|
|
271
|
+
label: "Zapf Dingbats",
|
|
272
|
+
css: "ZapfDingbats, serif"
|
|
273
|
+
}
|
|
274
|
+
]);
|
|
275
|
+
STANDARD_FONT_DESCRIPTORS$1.reduce((m, d) => (m[d.id] = d, m), {});
|
|
276
|
+
const familyStyleToId$1 = /* @__PURE__ */ new Map();
|
|
277
|
+
for (const d of STANDARD_FONT_DESCRIPTORS$1) {
|
|
278
|
+
familyStyleToId$1.set(`${d.family}_${d.bold}_${d.italic}`, d.id);
|
|
279
|
+
}
|
|
280
|
+
Object.values(PdfStandardFontFamily$1).filter(
|
|
281
|
+
(f) => f !== "Unknown"
|
|
282
|
+
/* Unknown */
|
|
283
|
+
).map((family) => ({ value: family, label: family }));
|
|
284
|
+
[
|
|
285
|
+
...new Set(STANDARD_FONT_DESCRIPTORS$1.map((d) => d.family))
|
|
286
|
+
];
|
|
287
|
+
const BLEND_MODE_INFOS$1 = Object.freeze([
|
|
288
|
+
{ id: PdfBlendMode$1.Normal, label: "Normal", css: "normal" },
|
|
289
|
+
{ id: PdfBlendMode$1.Multiply, label: "Multiply", css: "multiply" },
|
|
290
|
+
{ id: PdfBlendMode$1.Screen, label: "Screen", css: "screen" },
|
|
291
|
+
{ id: PdfBlendMode$1.Overlay, label: "Overlay", css: "overlay" },
|
|
292
|
+
{ id: PdfBlendMode$1.Darken, label: "Darken", css: "darken" },
|
|
293
|
+
{ id: PdfBlendMode$1.Lighten, label: "Lighten", css: "lighten" },
|
|
294
|
+
{ id: PdfBlendMode$1.ColorDodge, label: "Color Dodge", css: "color-dodge" },
|
|
295
|
+
{ id: PdfBlendMode$1.ColorBurn, label: "Color Burn", css: "color-burn" },
|
|
296
|
+
{ id: PdfBlendMode$1.HardLight, label: "Hard Light", css: "hard-light" },
|
|
297
|
+
{ id: PdfBlendMode$1.SoftLight, label: "Soft Light", css: "soft-light" },
|
|
298
|
+
{ id: PdfBlendMode$1.Difference, label: "Difference", css: "difference" },
|
|
299
|
+
{ id: PdfBlendMode$1.Exclusion, label: "Exclusion", css: "exclusion" },
|
|
300
|
+
{ id: PdfBlendMode$1.Hue, label: "Hue", css: "hue" },
|
|
301
|
+
{ id: PdfBlendMode$1.Saturation, label: "Saturation", css: "saturation" },
|
|
302
|
+
{ id: PdfBlendMode$1.Color, label: "Color", css: "color" },
|
|
303
|
+
{ id: PdfBlendMode$1.Luminosity, label: "Luminosity", css: "luminosity" }
|
|
304
|
+
]);
|
|
305
|
+
BLEND_MODE_INFOS$1.reduce(
|
|
306
|
+
(m, info) => {
|
|
307
|
+
m[info.id] = info;
|
|
308
|
+
return m;
|
|
309
|
+
},
|
|
310
|
+
{}
|
|
311
|
+
);
|
|
312
|
+
BLEND_MODE_INFOS$1.reduce(
|
|
313
|
+
(m, info) => {
|
|
314
|
+
m[info.css] = info.id;
|
|
315
|
+
return m;
|
|
316
|
+
},
|
|
317
|
+
{}
|
|
318
|
+
);
|
|
319
|
+
BLEND_MODE_INFOS$1.map((info) => ({
|
|
320
|
+
value: info.id,
|
|
321
|
+
label: info.label
|
|
322
|
+
}));
|
|
323
|
+
BLEND_MODE_INFOS$1.map((info) => info.id);
|
|
324
|
+
const START_LOADING_DOCUMENT = "START_LOADING_DOCUMENT";
|
|
325
|
+
const SET_DOCUMENT_LOADED = "SET_DOCUMENT_LOADED";
|
|
326
|
+
const CLOSE_DOCUMENT = "CLOSE_DOCUMENT";
|
|
327
|
+
const SET_SCALE = "SET_SCALE";
|
|
328
|
+
const SET_ROTATION = "SET_ROTATION";
|
|
329
|
+
({
|
|
330
|
+
print: PdfPermissionFlag.Print,
|
|
331
|
+
modifyContents: PdfPermissionFlag.ModifyContents,
|
|
332
|
+
copyContents: PdfPermissionFlag.CopyContents,
|
|
333
|
+
modifyAnnotations: PdfPermissionFlag.ModifyAnnotations,
|
|
334
|
+
fillForms: PdfPermissionFlag.FillForms,
|
|
335
|
+
extractForAccessibility: PdfPermissionFlag.ExtractForAccessibility,
|
|
336
|
+
assembleDocument: PdfPermissionFlag.AssembleDocument,
|
|
337
|
+
printHighQuality: PdfPermissionFlag.PrintHighQuality
|
|
338
|
+
});
|
|
339
|
+
const ALL_PERMISSION_FLAGS = [
|
|
340
|
+
PdfPermissionFlag.Print,
|
|
341
|
+
PdfPermissionFlag.ModifyContents,
|
|
342
|
+
PdfPermissionFlag.CopyContents,
|
|
343
|
+
PdfPermissionFlag.ModifyAnnotations,
|
|
344
|
+
PdfPermissionFlag.FillForms,
|
|
345
|
+
PdfPermissionFlag.ExtractForAccessibility,
|
|
346
|
+
PdfPermissionFlag.AssembleDocument,
|
|
347
|
+
PdfPermissionFlag.PrintHighQuality
|
|
348
|
+
];
|
|
349
|
+
const PERMISSION_FLAG_TO_NAME = {
|
|
350
|
+
[PdfPermissionFlag.Print]: "print",
|
|
351
|
+
[PdfPermissionFlag.ModifyContents]: "modifyContents",
|
|
352
|
+
[PdfPermissionFlag.CopyContents]: "copyContents",
|
|
353
|
+
[PdfPermissionFlag.ModifyAnnotations]: "modifyAnnotations",
|
|
354
|
+
[PdfPermissionFlag.FillForms]: "fillForms",
|
|
355
|
+
[PdfPermissionFlag.ExtractForAccessibility]: "extractForAccessibility",
|
|
356
|
+
[PdfPermissionFlag.AssembleDocument]: "assembleDocument",
|
|
357
|
+
[PdfPermissionFlag.PrintHighQuality]: "printHighQuality"
|
|
358
|
+
};
|
|
359
|
+
function getPermissionOverride(overrides, flag) {
|
|
360
|
+
if (!overrides) return void 0;
|
|
361
|
+
if (flag in overrides) {
|
|
362
|
+
return overrides[flag];
|
|
363
|
+
}
|
|
364
|
+
const name = PERMISSION_FLAG_TO_NAME[flag];
|
|
365
|
+
if (name && name in overrides) {
|
|
366
|
+
return overrides[name];
|
|
367
|
+
}
|
|
368
|
+
return void 0;
|
|
369
|
+
}
|
|
370
|
+
function getEffectivePermission(state, documentId, flag) {
|
|
371
|
+
var _a;
|
|
372
|
+
const docState = state.documents[documentId];
|
|
373
|
+
const docConfig = docState == null ? void 0 : docState.permissions;
|
|
374
|
+
const globalConfig = state.globalPermissions;
|
|
375
|
+
const pdfPermissions = ((_a = docState == null ? void 0 : docState.document) == null ? void 0 : _a.permissions) ?? PdfPermissionFlag.AllowAll;
|
|
376
|
+
const docOverride = getPermissionOverride(docConfig == null ? void 0 : docConfig.overrides, flag);
|
|
377
|
+
if (docOverride !== void 0) {
|
|
378
|
+
return docOverride;
|
|
379
|
+
}
|
|
380
|
+
const globalOverride = getPermissionOverride(globalConfig == null ? void 0 : globalConfig.overrides, flag);
|
|
381
|
+
if (globalOverride !== void 0) {
|
|
382
|
+
return globalOverride;
|
|
383
|
+
}
|
|
384
|
+
const enforce = (docConfig == null ? void 0 : docConfig.enforceDocumentPermissions) ?? (globalConfig == null ? void 0 : globalConfig.enforceDocumentPermissions) ?? true;
|
|
385
|
+
if (!enforce) return true;
|
|
386
|
+
return (pdfPermissions & flag) !== 0;
|
|
387
|
+
}
|
|
388
|
+
function getEffectivePermissions(state, documentId) {
|
|
389
|
+
return ALL_PERMISSION_FLAGS.reduce((acc, flag) => {
|
|
390
|
+
return getEffectivePermission(state, documentId, flag) ? acc | flag : acc;
|
|
391
|
+
}, 0);
|
|
392
|
+
}
|
|
393
|
+
class BasePlugin {
|
|
394
|
+
constructor(id, registry) {
|
|
395
|
+
this.id = id;
|
|
396
|
+
this.registry = registry;
|
|
397
|
+
this.cooldownActions = {};
|
|
398
|
+
this.debouncedTimeouts = {};
|
|
399
|
+
this.unsubscribeFromState = null;
|
|
400
|
+
this.unsubscribeFromCoreStore = null;
|
|
401
|
+
this.unsubscribeFromStartLoadingDocument = null;
|
|
402
|
+
this.unsubscribeFromSetDocumentLoaded = null;
|
|
403
|
+
this.unsubscribeFromCloseDocument = null;
|
|
404
|
+
this.unsubscribeFromSetScale = null;
|
|
405
|
+
this.unsubscribeFromSetRotation = null;
|
|
406
|
+
if (id !== this.constructor.id) {
|
|
407
|
+
throw new Error(
|
|
408
|
+
`Plugin ID mismatch: ${id} !== ${this.constructor.id}`
|
|
409
|
+
);
|
|
410
|
+
}
|
|
411
|
+
this.engine = this.registry.getEngine();
|
|
412
|
+
this.logger = this.registry.getLogger();
|
|
413
|
+
this.coreStore = this.registry.getStore();
|
|
414
|
+
this.pluginStore = this.coreStore.getPluginStore(this.id);
|
|
415
|
+
this.unsubscribeFromState = this.pluginStore.subscribeToState((action, newState, oldState) => {
|
|
416
|
+
this.onStoreUpdated(oldState, newState);
|
|
417
|
+
});
|
|
418
|
+
this.unsubscribeFromCoreStore = this.coreStore.subscribe((action, newState, oldState) => {
|
|
419
|
+
this.onCoreStoreUpdated(oldState, newState);
|
|
420
|
+
if (newState.core.activeDocumentId !== oldState.core.activeDocumentId) {
|
|
421
|
+
this.onActiveDocumentChanged(
|
|
422
|
+
oldState.core.activeDocumentId,
|
|
423
|
+
newState.core.activeDocumentId
|
|
424
|
+
);
|
|
425
|
+
}
|
|
426
|
+
});
|
|
427
|
+
this.unsubscribeFromStartLoadingDocument = this.coreStore.onAction(
|
|
428
|
+
START_LOADING_DOCUMENT,
|
|
429
|
+
(action) => {
|
|
430
|
+
this.onDocumentLoadingStarted(action.payload.documentId);
|
|
431
|
+
}
|
|
432
|
+
);
|
|
433
|
+
this.unsubscribeFromSetDocumentLoaded = this.coreStore.onAction(
|
|
434
|
+
SET_DOCUMENT_LOADED,
|
|
435
|
+
(action) => {
|
|
436
|
+
this.onDocumentLoaded(action.payload.documentId);
|
|
437
|
+
}
|
|
438
|
+
);
|
|
439
|
+
this.unsubscribeFromCloseDocument = this.coreStore.onAction(CLOSE_DOCUMENT, (action) => {
|
|
440
|
+
this.onDocumentClosed(action.payload.documentId);
|
|
441
|
+
});
|
|
442
|
+
this.unsubscribeFromSetScale = this.coreStore.onAction(SET_SCALE, (action, state) => {
|
|
443
|
+
const targetId = action.payload.documentId ?? state.core.activeDocumentId;
|
|
444
|
+
if (targetId) {
|
|
445
|
+
this.onScaleChanged(targetId, action.payload.scale);
|
|
446
|
+
}
|
|
447
|
+
});
|
|
448
|
+
this.unsubscribeFromSetRotation = this.coreStore.onAction(SET_ROTATION, (action, state) => {
|
|
449
|
+
const targetId = action.payload.documentId ?? state.core.activeDocumentId;
|
|
450
|
+
if (targetId) {
|
|
451
|
+
this.onRotationChanged(targetId, action.payload.rotation);
|
|
452
|
+
}
|
|
453
|
+
});
|
|
454
|
+
this.readyPromise = new Promise((resolve) => {
|
|
455
|
+
this.readyResolve = resolve;
|
|
456
|
+
});
|
|
457
|
+
this.readyResolve();
|
|
458
|
+
}
|
|
459
|
+
provides() {
|
|
460
|
+
if (!this._capability) {
|
|
461
|
+
const cap = this.buildCapability();
|
|
462
|
+
this._capability = Object.freeze(cap);
|
|
463
|
+
}
|
|
464
|
+
return this._capability;
|
|
465
|
+
}
|
|
466
|
+
/**
|
|
467
|
+
* Get a copy of the current state
|
|
468
|
+
*/
|
|
469
|
+
get state() {
|
|
470
|
+
return this.pluginStore.getState();
|
|
471
|
+
}
|
|
472
|
+
/**
|
|
473
|
+
* Get a copy of the current core state
|
|
474
|
+
*/
|
|
475
|
+
get coreState() {
|
|
476
|
+
return this.coreStore.getState();
|
|
477
|
+
}
|
|
478
|
+
/**
|
|
479
|
+
* @deprecated use `this.state` Get a copy of the current state
|
|
480
|
+
*/
|
|
481
|
+
getState() {
|
|
482
|
+
return this.pluginStore.getState();
|
|
483
|
+
}
|
|
484
|
+
/**
|
|
485
|
+
* @deprecated use `this.coreState` Get a copy of the current core state
|
|
486
|
+
*/
|
|
487
|
+
getCoreState() {
|
|
488
|
+
return this.coreStore.getState();
|
|
489
|
+
}
|
|
490
|
+
/**
|
|
491
|
+
* Core Dispatch
|
|
492
|
+
*/
|
|
493
|
+
dispatchCoreAction(action) {
|
|
494
|
+
return this.coreStore.dispatchToCore(action);
|
|
495
|
+
}
|
|
496
|
+
/**
|
|
497
|
+
* Dispatch an action to all plugins
|
|
498
|
+
*/
|
|
499
|
+
dispatchToAllPlugins(action) {
|
|
500
|
+
return this.coreStore.dispatch(action);
|
|
501
|
+
}
|
|
502
|
+
/**
|
|
503
|
+
* Dispatch an action
|
|
504
|
+
*/
|
|
505
|
+
dispatch(action) {
|
|
506
|
+
return this.pluginStore.dispatch(action);
|
|
507
|
+
}
|
|
508
|
+
/**
|
|
509
|
+
* Dispatch an action with a cooldown to prevent rapid repeated calls
|
|
510
|
+
* This executes immediately if cooldown has expired, then blocks subsequent calls
|
|
511
|
+
* @param action The action to dispatch
|
|
512
|
+
* @param cooldownTime Time in ms for cooldown (default: 100ms)
|
|
513
|
+
* @returns boolean indicating whether the action was dispatched or blocked
|
|
514
|
+
*/
|
|
515
|
+
cooldownDispatch(action, cooldownTime = 100) {
|
|
516
|
+
const now = Date.now();
|
|
517
|
+
const lastActionTime = this.cooldownActions[action.type] || 0;
|
|
518
|
+
if (now - lastActionTime >= cooldownTime) {
|
|
519
|
+
this.cooldownActions[action.type] = now;
|
|
520
|
+
this.dispatch(action);
|
|
521
|
+
return true;
|
|
522
|
+
}
|
|
523
|
+
return false;
|
|
524
|
+
}
|
|
525
|
+
/**
|
|
526
|
+
* Dispatch an action with true debouncing - waits for the delay after the last call
|
|
527
|
+
* Each new call resets the timer. Action only executes after no calls for the specified time.
|
|
528
|
+
* @param action The action to dispatch
|
|
529
|
+
* @param debounceTime Time in ms to wait after the last call
|
|
530
|
+
*/
|
|
531
|
+
debouncedDispatch(action, debounceTime = 100) {
|
|
532
|
+
const actionKey = action.type;
|
|
533
|
+
if (this.debouncedTimeouts[actionKey]) {
|
|
534
|
+
clearTimeout(this.debouncedTimeouts[actionKey]);
|
|
535
|
+
}
|
|
536
|
+
this.debouncedTimeouts[actionKey] = setTimeout(() => {
|
|
537
|
+
this.dispatch(action);
|
|
538
|
+
delete this.debouncedTimeouts[actionKey];
|
|
539
|
+
}, debounceTime);
|
|
540
|
+
}
|
|
541
|
+
/**
|
|
542
|
+
* Cancel a pending debounced action
|
|
543
|
+
* @param actionType The action type to cancel
|
|
544
|
+
*/
|
|
545
|
+
cancelDebouncedDispatch(actionType) {
|
|
546
|
+
if (this.debouncedTimeouts[actionType]) {
|
|
547
|
+
clearTimeout(this.debouncedTimeouts[actionType]);
|
|
548
|
+
delete this.debouncedTimeouts[actionType];
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
/**
|
|
552
|
+
* Subscribe to state changes
|
|
553
|
+
*/
|
|
554
|
+
subscribe(listener) {
|
|
555
|
+
return this.pluginStore.subscribeToState(listener);
|
|
556
|
+
}
|
|
557
|
+
/**
|
|
558
|
+
* Subscribe to core store changes
|
|
559
|
+
*/
|
|
560
|
+
subscribeToCoreStore(listener) {
|
|
561
|
+
return this.coreStore.subscribe(listener);
|
|
562
|
+
}
|
|
563
|
+
/**
|
|
564
|
+
* Called when the plugin store state is updated
|
|
565
|
+
* @param oldState Previous state
|
|
566
|
+
* @param newState New state
|
|
567
|
+
*/
|
|
568
|
+
onStoreUpdated(oldState, newState) {
|
|
569
|
+
}
|
|
570
|
+
/**
|
|
571
|
+
* Called when the core store state is updated
|
|
572
|
+
* @param oldState Previous state
|
|
573
|
+
* @param newState New state
|
|
574
|
+
*/
|
|
575
|
+
onCoreStoreUpdated(oldState, newState) {
|
|
576
|
+
}
|
|
577
|
+
/**
|
|
578
|
+
* Called when a document is opened
|
|
579
|
+
* Override to initialize per-document state
|
|
580
|
+
* @param documentId The ID of the document that was opened
|
|
581
|
+
*/
|
|
582
|
+
onDocumentLoadingStarted(documentId) {
|
|
583
|
+
}
|
|
584
|
+
/**
|
|
585
|
+
* Called when a document is loaded
|
|
586
|
+
* @param documentId The ID of the document that is loaded
|
|
587
|
+
*/
|
|
588
|
+
onDocumentLoaded(documentId) {
|
|
589
|
+
}
|
|
590
|
+
/**
|
|
591
|
+
* Called when a document is closed
|
|
592
|
+
* Override to cleanup per-document state
|
|
593
|
+
* @param documentId The ID of the document that was closed
|
|
594
|
+
*/
|
|
595
|
+
onDocumentClosed(documentId) {
|
|
596
|
+
}
|
|
597
|
+
/**
|
|
598
|
+
* Called when the active document changes
|
|
599
|
+
* @param previousId The ID of the previous active document
|
|
600
|
+
* @param currentId The ID of the new active document
|
|
601
|
+
*/
|
|
602
|
+
onActiveDocumentChanged(previousId, currentId) {
|
|
603
|
+
}
|
|
604
|
+
onScaleChanged(documentId, scale) {
|
|
605
|
+
}
|
|
606
|
+
onRotationChanged(documentId, rotation) {
|
|
607
|
+
}
|
|
608
|
+
/**
|
|
609
|
+
* Cleanup method to be called when plugin is being destroyed
|
|
610
|
+
*/
|
|
611
|
+
destroy() {
|
|
612
|
+
Object.values(this.debouncedTimeouts).forEach((timeout) => {
|
|
613
|
+
clearTimeout(timeout);
|
|
614
|
+
});
|
|
615
|
+
this.debouncedTimeouts = {};
|
|
616
|
+
if (this.unsubscribeFromState) {
|
|
617
|
+
this.unsubscribeFromState();
|
|
618
|
+
this.unsubscribeFromState = null;
|
|
619
|
+
}
|
|
620
|
+
if (this.unsubscribeFromCoreStore) {
|
|
621
|
+
this.unsubscribeFromCoreStore();
|
|
622
|
+
this.unsubscribeFromCoreStore = null;
|
|
623
|
+
}
|
|
624
|
+
if (this.unsubscribeFromStartLoadingDocument) {
|
|
625
|
+
this.unsubscribeFromStartLoadingDocument();
|
|
626
|
+
this.unsubscribeFromStartLoadingDocument = null;
|
|
627
|
+
}
|
|
628
|
+
if (this.unsubscribeFromSetDocumentLoaded) {
|
|
629
|
+
this.unsubscribeFromSetDocumentLoaded();
|
|
630
|
+
this.unsubscribeFromSetDocumentLoaded = null;
|
|
631
|
+
}
|
|
632
|
+
if (this.unsubscribeFromCloseDocument) {
|
|
633
|
+
this.unsubscribeFromCloseDocument();
|
|
634
|
+
this.unsubscribeFromCloseDocument = null;
|
|
635
|
+
}
|
|
636
|
+
if (this.unsubscribeFromSetScale) {
|
|
637
|
+
this.unsubscribeFromSetScale();
|
|
638
|
+
this.unsubscribeFromSetScale = null;
|
|
639
|
+
}
|
|
640
|
+
if (this.unsubscribeFromSetRotation) {
|
|
641
|
+
this.unsubscribeFromSetRotation();
|
|
642
|
+
this.unsubscribeFromSetRotation = null;
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
/**
|
|
646
|
+
* Returns a promise that resolves when the plugin is ready
|
|
647
|
+
*/
|
|
648
|
+
ready() {
|
|
649
|
+
return this.readyPromise;
|
|
650
|
+
}
|
|
651
|
+
/**
|
|
652
|
+
* Mark the plugin as ready
|
|
653
|
+
*/
|
|
654
|
+
markReady() {
|
|
655
|
+
this.readyResolve();
|
|
656
|
+
}
|
|
657
|
+
/**
|
|
658
|
+
* Reset the ready state (useful for plugins that need to reinitialize)
|
|
659
|
+
*/
|
|
660
|
+
resetReady() {
|
|
661
|
+
this.readyPromise = new Promise((resolve) => {
|
|
662
|
+
this.readyResolve = resolve;
|
|
663
|
+
});
|
|
664
|
+
}
|
|
665
|
+
/**
|
|
666
|
+
* Get the active document ID
|
|
667
|
+
* @throws Error if no active document exists
|
|
668
|
+
*/
|
|
669
|
+
getActiveDocumentId() {
|
|
670
|
+
const id = this.coreState.core.activeDocumentId;
|
|
671
|
+
if (!id) {
|
|
672
|
+
throw new Error("No active document");
|
|
673
|
+
}
|
|
674
|
+
return id;
|
|
675
|
+
}
|
|
676
|
+
/**
|
|
677
|
+
* Get the active document ID or null if none exists
|
|
678
|
+
*/
|
|
679
|
+
getActiveDocumentIdOrNull() {
|
|
680
|
+
return this.coreState.core.activeDocumentId;
|
|
681
|
+
}
|
|
682
|
+
/**
|
|
683
|
+
* Get core document state for a specific document
|
|
684
|
+
* @param documentId Document ID (optional, defaults to active document)
|
|
685
|
+
* @returns Document state or null if not found
|
|
686
|
+
*/
|
|
687
|
+
getCoreDocument(documentId) {
|
|
688
|
+
const id = documentId ?? this.getActiveDocumentIdOrNull();
|
|
689
|
+
if (!id) return null;
|
|
690
|
+
return this.coreState.core.documents[id] ?? null;
|
|
691
|
+
}
|
|
692
|
+
/**
|
|
693
|
+
* Get core document state for a specific document
|
|
694
|
+
* @param documentId Document ID (optional, defaults to active document)
|
|
695
|
+
* @throws Error if document not found
|
|
696
|
+
*/
|
|
697
|
+
getCoreDocumentOrThrow(documentId) {
|
|
698
|
+
const doc = this.getCoreDocument(documentId);
|
|
699
|
+
if (!doc) {
|
|
700
|
+
throw new Error(`Document not found: ${documentId ?? "active"}`);
|
|
701
|
+
}
|
|
702
|
+
return doc;
|
|
703
|
+
}
|
|
704
|
+
// ─────────────────────────────────────────────────────────
|
|
705
|
+
// Permission Helpers
|
|
706
|
+
// ─────────────────────────────────────────────────────────
|
|
707
|
+
/**
|
|
708
|
+
* Get the effective permission flags for a document.
|
|
709
|
+
* Applies layered resolution: per-document override → global override → PDF permission.
|
|
710
|
+
* Returns AllowAll if document not found.
|
|
711
|
+
* @param documentId Document ID (optional, defaults to active document)
|
|
712
|
+
*/
|
|
713
|
+
getDocumentPermissions(documentId) {
|
|
714
|
+
const docId = documentId ?? this.coreState.core.activeDocumentId;
|
|
715
|
+
if (!docId) return PdfPermissionFlag.AllowAll;
|
|
716
|
+
return getEffectivePermissions(this.coreState.core, docId);
|
|
717
|
+
}
|
|
718
|
+
/**
|
|
719
|
+
* Check if a document has the required permissions (returns boolean).
|
|
720
|
+
* Applies layered resolution: per-document override → global override → PDF permission.
|
|
721
|
+
* Useful for conditional UI logic.
|
|
722
|
+
* @param documentId Document ID (optional, defaults to active document)
|
|
723
|
+
* @param flags Permission flags to check
|
|
724
|
+
*/
|
|
725
|
+
checkPermission(documentId, ...flags) {
|
|
726
|
+
const docId = documentId ?? this.coreState.core.activeDocumentId;
|
|
727
|
+
if (!docId) return true;
|
|
728
|
+
return flags.every((flag) => getEffectivePermission(this.coreState.core, docId, flag));
|
|
729
|
+
}
|
|
730
|
+
/**
|
|
731
|
+
* Assert that a document has the required permissions.
|
|
732
|
+
* Applies layered resolution: per-document override → global override → PDF permission.
|
|
733
|
+
* Throws PermissionDeniedError if any flag is missing.
|
|
734
|
+
* @param documentId Document ID (optional, defaults to active document)
|
|
735
|
+
* @param flags Permission flags to require
|
|
736
|
+
*/
|
|
737
|
+
requirePermission(documentId, ...flags) {
|
|
738
|
+
const docId = documentId ?? this.coreState.core.activeDocumentId;
|
|
739
|
+
if (!docId) return;
|
|
740
|
+
const missingFlags = [];
|
|
741
|
+
for (const flag of flags) {
|
|
742
|
+
if (!getEffectivePermission(this.coreState.core, docId, flag)) {
|
|
743
|
+
missingFlags.push(flag);
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
if (missingFlags.length > 0) {
|
|
747
|
+
const effectivePermissions = getEffectivePermissions(this.coreState.core, docId);
|
|
748
|
+
throw new PermissionDeniedError(missingFlags, effectivePermissions);
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
class TaskAbortedError extends Error {
|
|
753
|
+
constructor(reason) {
|
|
754
|
+
super(`Task aborted: ${JSON.stringify(reason)}`);
|
|
755
|
+
this.name = "TaskAbortedError";
|
|
756
|
+
this.reason = reason;
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
class TaskRejectedError extends Error {
|
|
760
|
+
constructor(reason) {
|
|
761
|
+
super(`Task rejected: ${JSON.stringify(reason)}`);
|
|
762
|
+
this.name = "TaskRejectedError";
|
|
763
|
+
this.reason = reason;
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
class Task {
|
|
767
|
+
constructor() {
|
|
768
|
+
this.state = {
|
|
769
|
+
stage: 0
|
|
770
|
+
/* Pending */
|
|
771
|
+
};
|
|
772
|
+
this.resolvedCallbacks = [];
|
|
773
|
+
this.rejectedCallbacks = [];
|
|
774
|
+
this._promise = null;
|
|
775
|
+
this.progressCbs = [];
|
|
776
|
+
}
|
|
777
|
+
/**
|
|
778
|
+
* Convert task to promise
|
|
779
|
+
* @returns promise that will be resolved when task is settled
|
|
780
|
+
*/
|
|
781
|
+
toPromise() {
|
|
782
|
+
if (!this._promise) {
|
|
783
|
+
this._promise = new Promise((resolve, reject) => {
|
|
784
|
+
this.wait(
|
|
785
|
+
(result) => resolve(result),
|
|
786
|
+
(error) => {
|
|
787
|
+
if (error.type === "abort") {
|
|
788
|
+
reject(new TaskAbortedError(error.reason));
|
|
789
|
+
} else {
|
|
790
|
+
reject(new TaskRejectedError(error.reason));
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
);
|
|
794
|
+
});
|
|
795
|
+
}
|
|
796
|
+
return this._promise;
|
|
797
|
+
}
|
|
798
|
+
/**
|
|
799
|
+
* wait for task to be settled
|
|
800
|
+
* @param resolvedCallback - callback for resolved value
|
|
801
|
+
* @param rejectedCallback - callback for rejected value
|
|
802
|
+
*/
|
|
803
|
+
wait(resolvedCallback, rejectedCallback) {
|
|
804
|
+
switch (this.state.stage) {
|
|
805
|
+
case 0:
|
|
806
|
+
this.resolvedCallbacks.push(resolvedCallback);
|
|
807
|
+
this.rejectedCallbacks.push(rejectedCallback);
|
|
808
|
+
break;
|
|
809
|
+
case 1:
|
|
810
|
+
resolvedCallback(this.state.result);
|
|
811
|
+
break;
|
|
812
|
+
case 2:
|
|
813
|
+
rejectedCallback({
|
|
814
|
+
type: "reject",
|
|
815
|
+
reason: this.state.reason
|
|
816
|
+
});
|
|
817
|
+
break;
|
|
818
|
+
case 3:
|
|
819
|
+
rejectedCallback({
|
|
820
|
+
type: "abort",
|
|
821
|
+
reason: this.state.reason
|
|
822
|
+
});
|
|
823
|
+
break;
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
/**
|
|
827
|
+
* resolve task with specific result
|
|
828
|
+
* @param result - result value
|
|
829
|
+
*/
|
|
830
|
+
resolve(result) {
|
|
831
|
+
if (this.state.stage === 0) {
|
|
832
|
+
this.state = {
|
|
833
|
+
stage: 1,
|
|
834
|
+
result
|
|
835
|
+
};
|
|
836
|
+
for (const resolvedCallback of this.resolvedCallbacks) {
|
|
837
|
+
try {
|
|
838
|
+
resolvedCallback(result);
|
|
839
|
+
} catch (e) {
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
this.resolvedCallbacks = [];
|
|
843
|
+
this.rejectedCallbacks = [];
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
/**
|
|
847
|
+
* reject task with specific reason
|
|
848
|
+
* @param reason - abort reason
|
|
849
|
+
*
|
|
850
|
+
*/
|
|
851
|
+
reject(reason) {
|
|
852
|
+
if (this.state.stage === 0) {
|
|
853
|
+
this.state = {
|
|
854
|
+
stage: 2,
|
|
855
|
+
reason
|
|
856
|
+
};
|
|
857
|
+
for (const rejectedCallback of this.rejectedCallbacks) {
|
|
858
|
+
try {
|
|
859
|
+
rejectedCallback({
|
|
860
|
+
type: "reject",
|
|
861
|
+
reason
|
|
862
|
+
});
|
|
863
|
+
} catch (e) {
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
this.resolvedCallbacks = [];
|
|
867
|
+
this.rejectedCallbacks = [];
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
/**
|
|
871
|
+
* abort task with specific reason
|
|
872
|
+
* @param reason - abort reason
|
|
873
|
+
*/
|
|
874
|
+
abort(reason) {
|
|
875
|
+
if (this.state.stage === 0) {
|
|
876
|
+
this.state = {
|
|
877
|
+
stage: 3,
|
|
878
|
+
reason
|
|
879
|
+
};
|
|
880
|
+
for (const rejectedCallback of this.rejectedCallbacks) {
|
|
881
|
+
try {
|
|
882
|
+
rejectedCallback({
|
|
883
|
+
type: "abort",
|
|
884
|
+
reason
|
|
885
|
+
});
|
|
886
|
+
} catch (e) {
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
this.resolvedCallbacks = [];
|
|
890
|
+
this.rejectedCallbacks = [];
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
/**
|
|
894
|
+
* fail task with a TaskError from another task
|
|
895
|
+
* This is a convenience method for error propagation between tasks
|
|
896
|
+
* @param error - TaskError from another task
|
|
897
|
+
*/
|
|
898
|
+
fail(error) {
|
|
899
|
+
if (error.type === "abort") {
|
|
900
|
+
this.abort(error.reason);
|
|
901
|
+
} else {
|
|
902
|
+
this.reject(error.reason);
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
/**
|
|
906
|
+
* Transform the result of this task using a mapping function.
|
|
907
|
+
* Returns a new Task that resolves with the mapped value.
|
|
908
|
+
*
|
|
909
|
+
* Aborting the derived task also aborts the source task, and source errors
|
|
910
|
+
* are forwarded to the derived task directly (bypassing `errMap`).
|
|
911
|
+
*
|
|
912
|
+
* Note: progress events from the source task are **not** forwarded
|
|
913
|
+
* to the derived task.
|
|
914
|
+
*
|
|
915
|
+
* @param fn - mapping function that transforms the source result
|
|
916
|
+
* @param errMap - maps errors from `fn` (sync throws or rejected promises)
|
|
917
|
+
* into the error type `D`. Source task errors are forwarded as-is.
|
|
918
|
+
* @returns a new Task that resolves with the mapped result
|
|
919
|
+
*/
|
|
920
|
+
map(fn, errMap) {
|
|
921
|
+
const derived = new Task();
|
|
922
|
+
const origAbort = derived.abort.bind(derived);
|
|
923
|
+
derived.abort = (reason) => {
|
|
924
|
+
this.abort(reason);
|
|
925
|
+
origAbort(reason);
|
|
926
|
+
};
|
|
927
|
+
this.wait(
|
|
928
|
+
(result) => {
|
|
929
|
+
if (derived.state.stage !== 0) return;
|
|
930
|
+
try {
|
|
931
|
+
const mapped = fn(result);
|
|
932
|
+
if (mapped instanceof Promise) {
|
|
933
|
+
mapped.then(
|
|
934
|
+
(value) => {
|
|
935
|
+
if (derived.state.stage === 0) {
|
|
936
|
+
derived.resolve(value);
|
|
937
|
+
}
|
|
938
|
+
},
|
|
939
|
+
(err) => {
|
|
940
|
+
if (derived.state.stage === 0) {
|
|
941
|
+
derived.reject(errMap(err));
|
|
942
|
+
}
|
|
943
|
+
}
|
|
944
|
+
);
|
|
945
|
+
} else {
|
|
946
|
+
derived.resolve(mapped);
|
|
947
|
+
}
|
|
948
|
+
} catch (err) {
|
|
949
|
+
if (derived.state.stage === 0) {
|
|
950
|
+
derived.reject(errMap(err));
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
},
|
|
954
|
+
(error) => {
|
|
955
|
+
if (derived.state.stage === 0) {
|
|
956
|
+
derived.fail(error);
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
);
|
|
960
|
+
return derived;
|
|
961
|
+
}
|
|
962
|
+
/**
|
|
963
|
+
* add a progress callback
|
|
964
|
+
* @param cb - progress callback
|
|
965
|
+
*/
|
|
966
|
+
onProgress(cb) {
|
|
967
|
+
this.progressCbs.push(cb);
|
|
968
|
+
}
|
|
969
|
+
/**
|
|
970
|
+
* call progress callback
|
|
971
|
+
* @param p - progress value
|
|
972
|
+
*/
|
|
973
|
+
progress(p) {
|
|
974
|
+
for (const cb of this.progressCbs) cb(p);
|
|
975
|
+
}
|
|
976
|
+
/**
|
|
977
|
+
* Static method to wait for all tasks to resolve
|
|
978
|
+
* Returns a new task that resolves with an array of all results
|
|
979
|
+
* Rejects immediately if any task fails
|
|
980
|
+
*
|
|
981
|
+
* @param tasks - array of tasks to wait for
|
|
982
|
+
* @returns new task that resolves when all input tasks resolve
|
|
983
|
+
* @public
|
|
984
|
+
*/
|
|
985
|
+
static all(tasks) {
|
|
986
|
+
const combinedTask = new Task();
|
|
987
|
+
if (tasks.length === 0) {
|
|
988
|
+
combinedTask.resolve([]);
|
|
989
|
+
return combinedTask;
|
|
990
|
+
}
|
|
991
|
+
const results = new Array(tasks.length);
|
|
992
|
+
let resolvedCount = 0;
|
|
993
|
+
let isSettled = false;
|
|
994
|
+
tasks.forEach((task, index) => {
|
|
995
|
+
task.wait(
|
|
996
|
+
(result) => {
|
|
997
|
+
if (isSettled) return;
|
|
998
|
+
results[index] = result;
|
|
999
|
+
resolvedCount++;
|
|
1000
|
+
if (resolvedCount === tasks.length) {
|
|
1001
|
+
isSettled = true;
|
|
1002
|
+
combinedTask.resolve(results);
|
|
1003
|
+
}
|
|
1004
|
+
},
|
|
1005
|
+
(error) => {
|
|
1006
|
+
if (isSettled) return;
|
|
1007
|
+
isSettled = true;
|
|
1008
|
+
if (error.type === "abort") {
|
|
1009
|
+
combinedTask.abort(error.reason);
|
|
1010
|
+
} else {
|
|
1011
|
+
combinedTask.reject(error.reason);
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
);
|
|
1015
|
+
});
|
|
1016
|
+
return combinedTask;
|
|
1017
|
+
}
|
|
1018
|
+
/**
|
|
1019
|
+
* Static method to wait for all tasks to settle (resolve, reject, or abort)
|
|
1020
|
+
* Always resolves with an array of settlement results
|
|
1021
|
+
*
|
|
1022
|
+
* @param tasks - array of tasks to wait for
|
|
1023
|
+
* @returns new task that resolves when all input tasks settle
|
|
1024
|
+
* @public
|
|
1025
|
+
*/
|
|
1026
|
+
static allSettled(tasks) {
|
|
1027
|
+
const combinedTask = new Task();
|
|
1028
|
+
if (tasks.length === 0) {
|
|
1029
|
+
combinedTask.resolve([]);
|
|
1030
|
+
return combinedTask;
|
|
1031
|
+
}
|
|
1032
|
+
const results = new Array(tasks.length);
|
|
1033
|
+
let settledCount = 0;
|
|
1034
|
+
tasks.forEach((task, index) => {
|
|
1035
|
+
task.wait(
|
|
1036
|
+
(result) => {
|
|
1037
|
+
results[index] = { status: "resolved", value: result };
|
|
1038
|
+
settledCount++;
|
|
1039
|
+
if (settledCount === tasks.length) {
|
|
1040
|
+
combinedTask.resolve(results);
|
|
1041
|
+
}
|
|
1042
|
+
},
|
|
1043
|
+
(error) => {
|
|
1044
|
+
results[index] = {
|
|
1045
|
+
status: error.type === "abort" ? "aborted" : "rejected",
|
|
1046
|
+
reason: error.reason
|
|
1047
|
+
};
|
|
1048
|
+
settledCount++;
|
|
1049
|
+
if (settledCount === tasks.length) {
|
|
1050
|
+
combinedTask.resolve(results);
|
|
1051
|
+
}
|
|
1052
|
+
}
|
|
1053
|
+
);
|
|
1054
|
+
});
|
|
1055
|
+
return combinedTask;
|
|
1056
|
+
}
|
|
1057
|
+
/**
|
|
1058
|
+
* Static method that resolves/rejects with the first task that settles
|
|
1059
|
+
*
|
|
1060
|
+
* @param tasks - array of tasks to race
|
|
1061
|
+
* @returns new task that settles with the first input task that settles
|
|
1062
|
+
* @public
|
|
1063
|
+
*/
|
|
1064
|
+
static race(tasks) {
|
|
1065
|
+
const combinedTask = new Task();
|
|
1066
|
+
if (tasks.length === 0) {
|
|
1067
|
+
combinedTask.reject("No tasks provided");
|
|
1068
|
+
return combinedTask;
|
|
1069
|
+
}
|
|
1070
|
+
let isSettled = false;
|
|
1071
|
+
tasks.forEach((task) => {
|
|
1072
|
+
task.wait(
|
|
1073
|
+
(result) => {
|
|
1074
|
+
if (isSettled) return;
|
|
1075
|
+
isSettled = true;
|
|
1076
|
+
combinedTask.resolve(result);
|
|
1077
|
+
},
|
|
1078
|
+
(error) => {
|
|
1079
|
+
if (isSettled) return;
|
|
1080
|
+
isSettled = true;
|
|
1081
|
+
if (error.type === "abort") {
|
|
1082
|
+
combinedTask.abort(error.reason);
|
|
1083
|
+
} else {
|
|
1084
|
+
combinedTask.reject(error.reason);
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
1087
|
+
);
|
|
1088
|
+
});
|
|
1089
|
+
return combinedTask;
|
|
1090
|
+
}
|
|
1091
|
+
/**
|
|
1092
|
+
* Utility to track progress of multiple tasks
|
|
1093
|
+
*
|
|
1094
|
+
* @param tasks - array of tasks to track
|
|
1095
|
+
* @param onProgress - callback called when any task completes
|
|
1096
|
+
* @returns new task that resolves when all input tasks resolve
|
|
1097
|
+
* @public
|
|
1098
|
+
*/
|
|
1099
|
+
static withProgress(tasks, onProgress) {
|
|
1100
|
+
const combinedTask = Task.all(tasks);
|
|
1101
|
+
if (onProgress) {
|
|
1102
|
+
let completedCount = 0;
|
|
1103
|
+
tasks.forEach((task) => {
|
|
1104
|
+
task.wait(
|
|
1105
|
+
() => {
|
|
1106
|
+
completedCount++;
|
|
1107
|
+
onProgress(completedCount, tasks.length);
|
|
1108
|
+
},
|
|
1109
|
+
() => {
|
|
1110
|
+
completedCount++;
|
|
1111
|
+
onProgress(completedCount, tasks.length);
|
|
1112
|
+
}
|
|
1113
|
+
);
|
|
1114
|
+
});
|
|
1115
|
+
}
|
|
1116
|
+
return combinedTask;
|
|
1117
|
+
}
|
|
1118
|
+
}
|
|
1119
|
+
const PdfSoftHyphenMarker = "";
|
|
1120
|
+
const PdfZeroWidthSpace = "";
|
|
1121
|
+
const PdfWordJoiner = "";
|
|
1122
|
+
const PdfBomOrZwnbsp = "\uFEFF";
|
|
1123
|
+
const PdfNonCharacterFFFE = "";
|
|
1124
|
+
const PdfNonCharacterFFFF = "";
|
|
1125
|
+
const PdfUnwantedTextMarkers = Object.freeze([
|
|
1126
|
+
PdfSoftHyphenMarker,
|
|
1127
|
+
PdfZeroWidthSpace,
|
|
1128
|
+
PdfWordJoiner,
|
|
1129
|
+
PdfBomOrZwnbsp,
|
|
1130
|
+
PdfNonCharacterFFFE,
|
|
1131
|
+
PdfNonCharacterFFFF
|
|
1132
|
+
]);
|
|
1133
|
+
new RegExp(`[${PdfUnwantedTextMarkers.join("")}]`, "g");
|
|
1134
|
+
var PdfStandardFont = /* @__PURE__ */ ((PdfStandardFont2) => {
|
|
1135
|
+
PdfStandardFont2[PdfStandardFont2["Unknown"] = -1] = "Unknown";
|
|
1136
|
+
PdfStandardFont2[PdfStandardFont2["Courier"] = 0] = "Courier";
|
|
1137
|
+
PdfStandardFont2[PdfStandardFont2["Courier_Bold"] = 1] = "Courier_Bold";
|
|
1138
|
+
PdfStandardFont2[PdfStandardFont2["Courier_BoldOblique"] = 2] = "Courier_BoldOblique";
|
|
1139
|
+
PdfStandardFont2[PdfStandardFont2["Courier_Oblique"] = 3] = "Courier_Oblique";
|
|
1140
|
+
PdfStandardFont2[PdfStandardFont2["Helvetica"] = 4] = "Helvetica";
|
|
1141
|
+
PdfStandardFont2[PdfStandardFont2["Helvetica_Bold"] = 5] = "Helvetica_Bold";
|
|
1142
|
+
PdfStandardFont2[PdfStandardFont2["Helvetica_BoldOblique"] = 6] = "Helvetica_BoldOblique";
|
|
1143
|
+
PdfStandardFont2[PdfStandardFont2["Helvetica_Oblique"] = 7] = "Helvetica_Oblique";
|
|
1144
|
+
PdfStandardFont2[PdfStandardFont2["Times_Roman"] = 8] = "Times_Roman";
|
|
1145
|
+
PdfStandardFont2[PdfStandardFont2["Times_Bold"] = 9] = "Times_Bold";
|
|
1146
|
+
PdfStandardFont2[PdfStandardFont2["Times_BoldItalic"] = 10] = "Times_BoldItalic";
|
|
1147
|
+
PdfStandardFont2[PdfStandardFont2["Times_Italic"] = 11] = "Times_Italic";
|
|
1148
|
+
PdfStandardFont2[PdfStandardFont2["Symbol"] = 12] = "Symbol";
|
|
1149
|
+
PdfStandardFont2[PdfStandardFont2["ZapfDingbats"] = 13] = "ZapfDingbats";
|
|
1150
|
+
return PdfStandardFont2;
|
|
1151
|
+
})(PdfStandardFont || {});
|
|
1152
|
+
var PdfTextAlignment = /* @__PURE__ */ ((PdfTextAlignment2) => {
|
|
1153
|
+
PdfTextAlignment2[PdfTextAlignment2["Left"] = 0] = "Left";
|
|
1154
|
+
PdfTextAlignment2[PdfTextAlignment2["Center"] = 1] = "Center";
|
|
1155
|
+
PdfTextAlignment2[PdfTextAlignment2["Right"] = 2] = "Right";
|
|
1156
|
+
return PdfTextAlignment2;
|
|
1157
|
+
})(PdfTextAlignment || {});
|
|
1158
|
+
var PdfBlendMode = /* @__PURE__ */ ((PdfBlendMode2) => {
|
|
1159
|
+
PdfBlendMode2[PdfBlendMode2["Normal"] = 0] = "Normal";
|
|
1160
|
+
PdfBlendMode2[PdfBlendMode2["Multiply"] = 1] = "Multiply";
|
|
1161
|
+
PdfBlendMode2[PdfBlendMode2["Screen"] = 2] = "Screen";
|
|
1162
|
+
PdfBlendMode2[PdfBlendMode2["Overlay"] = 3] = "Overlay";
|
|
1163
|
+
PdfBlendMode2[PdfBlendMode2["Darken"] = 4] = "Darken";
|
|
1164
|
+
PdfBlendMode2[PdfBlendMode2["Lighten"] = 5] = "Lighten";
|
|
1165
|
+
PdfBlendMode2[PdfBlendMode2["ColorDodge"] = 6] = "ColorDodge";
|
|
1166
|
+
PdfBlendMode2[PdfBlendMode2["ColorBurn"] = 7] = "ColorBurn";
|
|
1167
|
+
PdfBlendMode2[PdfBlendMode2["HardLight"] = 8] = "HardLight";
|
|
1168
|
+
PdfBlendMode2[PdfBlendMode2["SoftLight"] = 9] = "SoftLight";
|
|
1169
|
+
PdfBlendMode2[PdfBlendMode2["Difference"] = 10] = "Difference";
|
|
1170
|
+
PdfBlendMode2[PdfBlendMode2["Exclusion"] = 11] = "Exclusion";
|
|
1171
|
+
PdfBlendMode2[PdfBlendMode2["Hue"] = 12] = "Hue";
|
|
1172
|
+
PdfBlendMode2[PdfBlendMode2["Saturation"] = 13] = "Saturation";
|
|
1173
|
+
PdfBlendMode2[PdfBlendMode2["Color"] = 14] = "Color";
|
|
1174
|
+
PdfBlendMode2[PdfBlendMode2["Luminosity"] = 15] = "Luminosity";
|
|
1175
|
+
return PdfBlendMode2;
|
|
1176
|
+
})(PdfBlendMode || {});
|
|
1177
|
+
const PdfAnnotationFlagName = Object.freeze({
|
|
1178
|
+
[
|
|
1179
|
+
1
|
|
1180
|
+
/* INVISIBLE */
|
|
1181
|
+
]: "invisible",
|
|
1182
|
+
[
|
|
1183
|
+
2
|
|
1184
|
+
/* HIDDEN */
|
|
1185
|
+
]: "hidden",
|
|
1186
|
+
[
|
|
1187
|
+
4
|
|
1188
|
+
/* PRINT */
|
|
1189
|
+
]: "print",
|
|
1190
|
+
[
|
|
1191
|
+
8
|
|
1192
|
+
/* NO_ZOOM */
|
|
1193
|
+
]: "noZoom",
|
|
1194
|
+
[
|
|
1195
|
+
16
|
|
1196
|
+
/* NO_ROTATE */
|
|
1197
|
+
]: "noRotate",
|
|
1198
|
+
[
|
|
1199
|
+
32
|
|
1200
|
+
/* NO_VIEW */
|
|
1201
|
+
]: "noView",
|
|
1202
|
+
[
|
|
1203
|
+
64
|
|
1204
|
+
/* READ_ONLY */
|
|
1205
|
+
]: "readOnly",
|
|
1206
|
+
[
|
|
1207
|
+
128
|
|
1208
|
+
/* LOCKED */
|
|
1209
|
+
]: "locked",
|
|
1210
|
+
[
|
|
1211
|
+
256
|
|
1212
|
+
/* TOGGLE_NOVIEW */
|
|
1213
|
+
]: "toggleNoView"
|
|
1214
|
+
});
|
|
1215
|
+
Object.entries(
|
|
1216
|
+
PdfAnnotationFlagName
|
|
1217
|
+
).reduce(
|
|
1218
|
+
(acc, [bit, name]) => {
|
|
1219
|
+
acc[name] = Number(bit);
|
|
1220
|
+
return acc;
|
|
1221
|
+
},
|
|
1222
|
+
{}
|
|
1223
|
+
);
|
|
1224
|
+
var PdfErrorCode = /* @__PURE__ */ ((PdfErrorCode2) => {
|
|
1225
|
+
PdfErrorCode2[PdfErrorCode2["Ok"] = 0] = "Ok";
|
|
1226
|
+
PdfErrorCode2[PdfErrorCode2["Unknown"] = 1] = "Unknown";
|
|
1227
|
+
PdfErrorCode2[PdfErrorCode2["NotFound"] = 2] = "NotFound";
|
|
1228
|
+
PdfErrorCode2[PdfErrorCode2["WrongFormat"] = 3] = "WrongFormat";
|
|
1229
|
+
PdfErrorCode2[PdfErrorCode2["Password"] = 4] = "Password";
|
|
1230
|
+
PdfErrorCode2[PdfErrorCode2["Security"] = 5] = "Security";
|
|
1231
|
+
PdfErrorCode2[PdfErrorCode2["PageError"] = 6] = "PageError";
|
|
1232
|
+
PdfErrorCode2[PdfErrorCode2["XFALoad"] = 7] = "XFALoad";
|
|
1233
|
+
PdfErrorCode2[PdfErrorCode2["XFALayout"] = 8] = "XFALayout";
|
|
1234
|
+
PdfErrorCode2[PdfErrorCode2["Cancelled"] = 9] = "Cancelled";
|
|
1235
|
+
PdfErrorCode2[PdfErrorCode2["Initialization"] = 10] = "Initialization";
|
|
1236
|
+
PdfErrorCode2[PdfErrorCode2["NotReady"] = 11] = "NotReady";
|
|
1237
|
+
PdfErrorCode2[PdfErrorCode2["NotSupport"] = 12] = "NotSupport";
|
|
1238
|
+
PdfErrorCode2[PdfErrorCode2["LoadDoc"] = 13] = "LoadDoc";
|
|
1239
|
+
PdfErrorCode2[PdfErrorCode2["DocNotOpen"] = 14] = "DocNotOpen";
|
|
1240
|
+
PdfErrorCode2[PdfErrorCode2["CantCloseDoc"] = 15] = "CantCloseDoc";
|
|
1241
|
+
PdfErrorCode2[PdfErrorCode2["CantCreateNewDoc"] = 16] = "CantCreateNewDoc";
|
|
1242
|
+
PdfErrorCode2[PdfErrorCode2["CantImportPages"] = 17] = "CantImportPages";
|
|
1243
|
+
PdfErrorCode2[PdfErrorCode2["CantCreateAnnot"] = 18] = "CantCreateAnnot";
|
|
1244
|
+
PdfErrorCode2[PdfErrorCode2["CantSetAnnotRect"] = 19] = "CantSetAnnotRect";
|
|
1245
|
+
PdfErrorCode2[PdfErrorCode2["CantSetAnnotContent"] = 20] = "CantSetAnnotContent";
|
|
1246
|
+
PdfErrorCode2[PdfErrorCode2["CantRemoveInkList"] = 21] = "CantRemoveInkList";
|
|
1247
|
+
PdfErrorCode2[PdfErrorCode2["CantAddInkStoke"] = 22] = "CantAddInkStoke";
|
|
1248
|
+
PdfErrorCode2[PdfErrorCode2["CantReadAttachmentSize"] = 23] = "CantReadAttachmentSize";
|
|
1249
|
+
PdfErrorCode2[PdfErrorCode2["CantReadAttachmentContent"] = 24] = "CantReadAttachmentContent";
|
|
1250
|
+
PdfErrorCode2[PdfErrorCode2["CantFocusAnnot"] = 25] = "CantFocusAnnot";
|
|
1251
|
+
PdfErrorCode2[PdfErrorCode2["CantSelectText"] = 26] = "CantSelectText";
|
|
1252
|
+
PdfErrorCode2[PdfErrorCode2["CantSelectOption"] = 27] = "CantSelectOption";
|
|
1253
|
+
PdfErrorCode2[PdfErrorCode2["CantCheckField"] = 28] = "CantCheckField";
|
|
1254
|
+
PdfErrorCode2[PdfErrorCode2["CantSetAnnotString"] = 29] = "CantSetAnnotString";
|
|
1255
|
+
return PdfErrorCode2;
|
|
1256
|
+
})(PdfErrorCode || {});
|
|
1257
|
+
class PdfTaskHelper {
|
|
1258
|
+
/**
|
|
1259
|
+
* Create a task
|
|
1260
|
+
* @returns new task
|
|
1261
|
+
*/
|
|
1262
|
+
static create() {
|
|
1263
|
+
return new Task();
|
|
1264
|
+
}
|
|
1265
|
+
/**
|
|
1266
|
+
* Create a task that has been resolved with value
|
|
1267
|
+
* @param result - resolved value
|
|
1268
|
+
* @returns resolved task
|
|
1269
|
+
*/
|
|
1270
|
+
static resolve(result) {
|
|
1271
|
+
const task = new Task();
|
|
1272
|
+
task.resolve(result);
|
|
1273
|
+
return task;
|
|
1274
|
+
}
|
|
1275
|
+
/**
|
|
1276
|
+
* Create a task that has been rejected with error
|
|
1277
|
+
* @param reason - rejected error
|
|
1278
|
+
* @returns rejected task
|
|
1279
|
+
*/
|
|
1280
|
+
static reject(reason) {
|
|
1281
|
+
const task = new Task();
|
|
1282
|
+
task.reject(reason);
|
|
1283
|
+
return task;
|
|
1284
|
+
}
|
|
1285
|
+
/**
|
|
1286
|
+
* Create a task that has been aborted with error
|
|
1287
|
+
* @param reason - aborted error
|
|
1288
|
+
* @returns aborted task
|
|
1289
|
+
*/
|
|
1290
|
+
static abort(reason) {
|
|
1291
|
+
const task = new Task();
|
|
1292
|
+
task.reject(reason);
|
|
1293
|
+
return task;
|
|
1294
|
+
}
|
|
1295
|
+
}
|
|
1296
|
+
const TEXT_ALIGNMENT_INFOS = Object.freeze([
|
|
1297
|
+
{ id: PdfTextAlignment.Left, label: "Left", css: "left" },
|
|
1298
|
+
{ id: PdfTextAlignment.Center, label: "Center", css: "center" },
|
|
1299
|
+
{ id: PdfTextAlignment.Right, label: "Right", css: "right" }
|
|
1300
|
+
]);
|
|
1301
|
+
TEXT_ALIGNMENT_INFOS.reduce(
|
|
1302
|
+
(m, info) => {
|
|
1303
|
+
m[info.id] = info;
|
|
1304
|
+
return m;
|
|
1305
|
+
},
|
|
1306
|
+
{}
|
|
1307
|
+
);
|
|
1308
|
+
TEXT_ALIGNMENT_INFOS.reduce(
|
|
1309
|
+
(m, info) => {
|
|
1310
|
+
m[info.css] = info.id;
|
|
1311
|
+
return m;
|
|
1312
|
+
},
|
|
1313
|
+
{}
|
|
1314
|
+
);
|
|
1315
|
+
TEXT_ALIGNMENT_INFOS.map((info) => ({
|
|
1316
|
+
value: info.id,
|
|
1317
|
+
label: info.label
|
|
1318
|
+
}));
|
|
1319
|
+
var PdfStandardFontFamily = /* @__PURE__ */ ((PdfStandardFontFamily2) => {
|
|
1320
|
+
PdfStandardFontFamily2["Courier"] = "Courier";
|
|
1321
|
+
PdfStandardFontFamily2["Helvetica"] = "Helvetica";
|
|
1322
|
+
PdfStandardFontFamily2["Times"] = "Times";
|
|
1323
|
+
PdfStandardFontFamily2["Symbol"] = "Symbol";
|
|
1324
|
+
PdfStandardFontFamily2["ZapfDingbats"] = "ZapfDingbats";
|
|
1325
|
+
PdfStandardFontFamily2["Unknown"] = "Unknown";
|
|
1326
|
+
return PdfStandardFontFamily2;
|
|
1327
|
+
})(PdfStandardFontFamily || {});
|
|
1328
|
+
PdfStandardFont.Helvetica;
|
|
1329
|
+
const HELVETICA_DESC = {
|
|
1330
|
+
id: PdfStandardFont.Helvetica,
|
|
1331
|
+
family: "Helvetica",
|
|
1332
|
+
bold: false,
|
|
1333
|
+
italic: false,
|
|
1334
|
+
label: "Helvetica",
|
|
1335
|
+
css: "Helvetica, Arial, sans-serif"
|
|
1336
|
+
};
|
|
1337
|
+
const STANDARD_FONT_DESCRIPTORS = Object.freeze([
|
|
1338
|
+
{
|
|
1339
|
+
id: PdfStandardFont.Courier,
|
|
1340
|
+
family: "Courier",
|
|
1341
|
+
bold: false,
|
|
1342
|
+
italic: false,
|
|
1343
|
+
label: "Courier",
|
|
1344
|
+
css: "Courier, monospace"
|
|
1345
|
+
},
|
|
1346
|
+
{
|
|
1347
|
+
id: PdfStandardFont.Courier_Bold,
|
|
1348
|
+
family: "Courier",
|
|
1349
|
+
bold: true,
|
|
1350
|
+
italic: false,
|
|
1351
|
+
label: "Courier Bold",
|
|
1352
|
+
css: "Courier, monospace"
|
|
1353
|
+
},
|
|
1354
|
+
{
|
|
1355
|
+
id: PdfStandardFont.Courier_BoldOblique,
|
|
1356
|
+
family: "Courier",
|
|
1357
|
+
bold: true,
|
|
1358
|
+
italic: true,
|
|
1359
|
+
label: "Courier Bold Oblique",
|
|
1360
|
+
css: "Courier, monospace"
|
|
1361
|
+
},
|
|
1362
|
+
{
|
|
1363
|
+
id: PdfStandardFont.Courier_Oblique,
|
|
1364
|
+
family: "Courier",
|
|
1365
|
+
bold: false,
|
|
1366
|
+
italic: true,
|
|
1367
|
+
label: "Courier Oblique",
|
|
1368
|
+
css: "Courier, monospace"
|
|
1369
|
+
},
|
|
1370
|
+
HELVETICA_DESC,
|
|
1371
|
+
{
|
|
1372
|
+
id: PdfStandardFont.Helvetica_Bold,
|
|
1373
|
+
family: "Helvetica",
|
|
1374
|
+
bold: true,
|
|
1375
|
+
italic: false,
|
|
1376
|
+
label: "Helvetica Bold",
|
|
1377
|
+
css: "Helvetica, Arial, sans-serif"
|
|
1378
|
+
},
|
|
1379
|
+
{
|
|
1380
|
+
id: PdfStandardFont.Helvetica_BoldOblique,
|
|
1381
|
+
family: "Helvetica",
|
|
1382
|
+
bold: true,
|
|
1383
|
+
italic: true,
|
|
1384
|
+
label: "Helvetica Bold Oblique",
|
|
1385
|
+
css: "Helvetica, Arial, sans-serif"
|
|
1386
|
+
},
|
|
1387
|
+
{
|
|
1388
|
+
id: PdfStandardFont.Helvetica_Oblique,
|
|
1389
|
+
family: "Helvetica",
|
|
1390
|
+
bold: false,
|
|
1391
|
+
italic: true,
|
|
1392
|
+
label: "Helvetica Oblique",
|
|
1393
|
+
css: "Helvetica, Arial, sans-serif"
|
|
1394
|
+
},
|
|
1395
|
+
{
|
|
1396
|
+
id: PdfStandardFont.Times_Roman,
|
|
1397
|
+
family: "Times",
|
|
1398
|
+
bold: false,
|
|
1399
|
+
italic: false,
|
|
1400
|
+
label: "Times Roman",
|
|
1401
|
+
css: '"Times New Roman", Times, serif'
|
|
1402
|
+
},
|
|
1403
|
+
{
|
|
1404
|
+
id: PdfStandardFont.Times_Bold,
|
|
1405
|
+
family: "Times",
|
|
1406
|
+
bold: true,
|
|
1407
|
+
italic: false,
|
|
1408
|
+
label: "Times Bold",
|
|
1409
|
+
css: '"Times New Roman", Times, serif'
|
|
1410
|
+
},
|
|
1411
|
+
{
|
|
1412
|
+
id: PdfStandardFont.Times_BoldItalic,
|
|
1413
|
+
family: "Times",
|
|
1414
|
+
bold: true,
|
|
1415
|
+
italic: true,
|
|
1416
|
+
label: "Times Bold Italic",
|
|
1417
|
+
css: '"Times New Roman", Times, serif'
|
|
1418
|
+
},
|
|
1419
|
+
{
|
|
1420
|
+
id: PdfStandardFont.Times_Italic,
|
|
1421
|
+
family: "Times",
|
|
1422
|
+
bold: false,
|
|
1423
|
+
italic: true,
|
|
1424
|
+
label: "Times Italic",
|
|
1425
|
+
css: '"Times New Roman", Times, serif'
|
|
1426
|
+
},
|
|
1427
|
+
{
|
|
1428
|
+
id: PdfStandardFont.Symbol,
|
|
1429
|
+
family: "Symbol",
|
|
1430
|
+
bold: false,
|
|
1431
|
+
italic: false,
|
|
1432
|
+
label: "Symbol",
|
|
1433
|
+
css: "Symbol, serif"
|
|
1434
|
+
},
|
|
1435
|
+
{
|
|
1436
|
+
id: PdfStandardFont.ZapfDingbats,
|
|
1437
|
+
family: "ZapfDingbats",
|
|
1438
|
+
bold: false,
|
|
1439
|
+
italic: false,
|
|
1440
|
+
label: "Zapf Dingbats",
|
|
1441
|
+
css: "ZapfDingbats, serif"
|
|
1442
|
+
}
|
|
1443
|
+
]);
|
|
1444
|
+
STANDARD_FONT_DESCRIPTORS.reduce((m, d) => (m[d.id] = d, m), {});
|
|
1445
|
+
const familyStyleToId = /* @__PURE__ */ new Map();
|
|
1446
|
+
for (const d of STANDARD_FONT_DESCRIPTORS) {
|
|
1447
|
+
familyStyleToId.set(`${d.family}_${d.bold}_${d.italic}`, d.id);
|
|
1448
|
+
}
|
|
1449
|
+
Object.values(PdfStandardFontFamily).filter(
|
|
1450
|
+
(f) => f !== "Unknown"
|
|
1451
|
+
/* Unknown */
|
|
1452
|
+
).map((family) => ({ value: family, label: family }));
|
|
1453
|
+
[
|
|
1454
|
+
...new Set(STANDARD_FONT_DESCRIPTORS.map((d) => d.family))
|
|
1455
|
+
];
|
|
1456
|
+
const BLEND_MODE_INFOS = Object.freeze([
|
|
1457
|
+
{ id: PdfBlendMode.Normal, label: "Normal", css: "normal" },
|
|
1458
|
+
{ id: PdfBlendMode.Multiply, label: "Multiply", css: "multiply" },
|
|
1459
|
+
{ id: PdfBlendMode.Screen, label: "Screen", css: "screen" },
|
|
1460
|
+
{ id: PdfBlendMode.Overlay, label: "Overlay", css: "overlay" },
|
|
1461
|
+
{ id: PdfBlendMode.Darken, label: "Darken", css: "darken" },
|
|
1462
|
+
{ id: PdfBlendMode.Lighten, label: "Lighten", css: "lighten" },
|
|
1463
|
+
{ id: PdfBlendMode.ColorDodge, label: "Color Dodge", css: "color-dodge" },
|
|
1464
|
+
{ id: PdfBlendMode.ColorBurn, label: "Color Burn", css: "color-burn" },
|
|
1465
|
+
{ id: PdfBlendMode.HardLight, label: "Hard Light", css: "hard-light" },
|
|
1466
|
+
{ id: PdfBlendMode.SoftLight, label: "Soft Light", css: "soft-light" },
|
|
1467
|
+
{ id: PdfBlendMode.Difference, label: "Difference", css: "difference" },
|
|
1468
|
+
{ id: PdfBlendMode.Exclusion, label: "Exclusion", css: "exclusion" },
|
|
1469
|
+
{ id: PdfBlendMode.Hue, label: "Hue", css: "hue" },
|
|
1470
|
+
{ id: PdfBlendMode.Saturation, label: "Saturation", css: "saturation" },
|
|
1471
|
+
{ id: PdfBlendMode.Color, label: "Color", css: "color" },
|
|
1472
|
+
{ id: PdfBlendMode.Luminosity, label: "Luminosity", css: "luminosity" }
|
|
1473
|
+
]);
|
|
1474
|
+
BLEND_MODE_INFOS.reduce(
|
|
1475
|
+
(m, info) => {
|
|
1476
|
+
m[info.id] = info;
|
|
1477
|
+
return m;
|
|
1478
|
+
},
|
|
1479
|
+
{}
|
|
1480
|
+
);
|
|
1481
|
+
BLEND_MODE_INFOS.reduce(
|
|
1482
|
+
(m, info) => {
|
|
1483
|
+
m[info.css] = info.id;
|
|
1484
|
+
return m;
|
|
1485
|
+
},
|
|
1486
|
+
{}
|
|
1487
|
+
);
|
|
1488
|
+
BLEND_MODE_INFOS.map((info) => ({
|
|
1489
|
+
value: info.id,
|
|
1490
|
+
label: info.label
|
|
1491
|
+
}));
|
|
1492
|
+
BLEND_MODE_INFOS.map((info) => info.id);
|
|
1493
|
+
const _AttachmentPlugin = class _AttachmentPlugin extends BasePlugin {
|
|
1494
|
+
constructor(id, registry) {
|
|
1495
|
+
super(id, registry);
|
|
1496
|
+
}
|
|
1497
|
+
async initialize(_) {
|
|
1498
|
+
}
|
|
1499
|
+
// ─────────────────────────────────────────────────────────
|
|
1500
|
+
// Capability
|
|
1501
|
+
// ─────────────────────────────────────────────────────────
|
|
1502
|
+
buildCapability() {
|
|
1503
|
+
return {
|
|
1504
|
+
// Active document operations
|
|
1505
|
+
getAttachments: () => this.getAttachments(),
|
|
1506
|
+
downloadAttachment: (attachment) => this.downloadAttachment(attachment),
|
|
1507
|
+
// Document-scoped operations
|
|
1508
|
+
forDocument: (documentId) => this.createAttachmentScope(documentId)
|
|
1509
|
+
};
|
|
1510
|
+
}
|
|
1511
|
+
// ─────────────────────────────────────────────────────────
|
|
1512
|
+
// Document Scoping
|
|
1513
|
+
// ─────────────────────────────────────────────────────────
|
|
1514
|
+
createAttachmentScope(documentId) {
|
|
1515
|
+
return {
|
|
1516
|
+
getAttachments: () => this.getAttachments(documentId),
|
|
1517
|
+
downloadAttachment: (attachment) => this.downloadAttachment(attachment, documentId)
|
|
1518
|
+
};
|
|
1519
|
+
}
|
|
1520
|
+
// ─────────────────────────────────────────────────────────
|
|
1521
|
+
// Core Operations
|
|
1522
|
+
// ─────────────────────────────────────────────────────────
|
|
1523
|
+
downloadAttachment(attachment, documentId) {
|
|
1524
|
+
const id = documentId ?? this.getActiveDocumentId();
|
|
1525
|
+
const coreDoc = this.coreState.core.documents[id];
|
|
1526
|
+
if (!(coreDoc == null ? void 0 : coreDoc.document)) {
|
|
1527
|
+
return PdfTaskHelper.reject({
|
|
1528
|
+
code: PdfErrorCode.NotFound,
|
|
1529
|
+
message: `Document ${id} not found`
|
|
1530
|
+
});
|
|
1531
|
+
}
|
|
1532
|
+
return this.engine.readAttachmentContent(coreDoc.document, attachment);
|
|
1533
|
+
}
|
|
1534
|
+
getAttachments(documentId) {
|
|
1535
|
+
const id = documentId ?? this.getActiveDocumentId();
|
|
1536
|
+
const coreDoc = this.coreState.core.documents[id];
|
|
1537
|
+
if (!(coreDoc == null ? void 0 : coreDoc.document)) {
|
|
1538
|
+
return PdfTaskHelper.reject({
|
|
1539
|
+
code: PdfErrorCode.NotFound,
|
|
1540
|
+
message: `Document ${id} not found`
|
|
1541
|
+
});
|
|
1542
|
+
}
|
|
1543
|
+
return this.engine.getAttachments(coreDoc.document);
|
|
1544
|
+
}
|
|
1545
|
+
};
|
|
1546
|
+
_AttachmentPlugin.id = "attachment";
|
|
1547
|
+
let AttachmentPlugin = _AttachmentPlugin;
|
|
1548
|
+
const ATTACHMENT_PLUGIN_ID = "attachment";
|
|
1549
|
+
const manifest = {
|
|
1550
|
+
id: ATTACHMENT_PLUGIN_ID,
|
|
1551
|
+
name: "Attachment Plugin",
|
|
1552
|
+
version: "1.0.0",
|
|
1553
|
+
provides: ["attachment"],
|
|
1554
|
+
requires: [],
|
|
1555
|
+
optional: [],
|
|
1556
|
+
defaultConfig: {}
|
|
1557
|
+
};
|
|
1558
|
+
const AttachmentPluginPackage = {
|
|
1559
|
+
manifest,
|
|
1560
|
+
create: (registry) => new AttachmentPlugin(ATTACHMENT_PLUGIN_ID, registry),
|
|
1561
|
+
reducer: () => {
|
|
1562
|
+
},
|
|
1563
|
+
initialState: {}
|
|
1564
|
+
};
|
|
1565
|
+
export {
|
|
1566
|
+
ATTACHMENT_PLUGIN_ID,
|
|
1567
|
+
AttachmentPlugin,
|
|
1568
|
+
AttachmentPluginPackage,
|
|
1569
|
+
manifest
|
|
1570
|
+
};
|
|
1571
|
+
//# sourceMappingURL=index.js.map
|