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