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