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