@pdfmergy-embedpdf/plugin-bookmark 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 +814 -0
  5. package/dist/index.js.map +1 -0
  6. package/dist/lib/bookmark-plugin.d.ts +10 -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 +15 -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 +1227 -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 +1226 -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-bookmark.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-bookmark.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-bookmark.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-bookmark.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 +1195 -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-bookmark.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 +1199 -0
  44. package/dist/vue/index.js.map +1 -0
  45. package/package.json +80 -0
@@ -0,0 +1,1199 @@
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$1 = "­";
9
+ const PdfZeroWidthSpace$1 = "​";
10
+ const PdfWordJoiner$1 = "⁠";
11
+ const PdfBomOrZwnbsp$1 = "\uFEFF";
12
+ const PdfNonCharacterFFFE$1 = "￾";
13
+ const PdfNonCharacterFFFF$1 = "￿";
14
+ const PdfUnwantedTextMarkers$1 = Object.freeze([
15
+ PdfSoftHyphenMarker$1,
16
+ PdfZeroWidthSpace$1,
17
+ PdfWordJoiner$1,
18
+ PdfBomOrZwnbsp$1,
19
+ PdfNonCharacterFFFE$1,
20
+ PdfNonCharacterFFFF$1
21
+ ]);
22
+ new RegExp(`[${PdfUnwantedTextMarkers$1.join("")}]`, "g");
23
+ var PdfStandardFont$1 = /* @__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$1 || {});
41
+ var PdfTextAlignment$1 = /* @__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$1 || {});
47
+ var PdfBlendMode$1 = /* @__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$1 || {});
66
+ const PdfAnnotationFlagName$1 = 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$1
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$1 = Object.freeze([
126
+ { id: PdfTextAlignment$1.Left, label: "Left", css: "left" },
127
+ { id: PdfTextAlignment$1.Center, label: "Center", css: "center" },
128
+ { id: PdfTextAlignment$1.Right, label: "Right", css: "right" }
129
+ ]);
130
+ TEXT_ALIGNMENT_INFOS$1.reduce(
131
+ (m, info) => {
132
+ m[info.id] = info;
133
+ return m;
134
+ },
135
+ {}
136
+ );
137
+ TEXT_ALIGNMENT_INFOS$1.reduce(
138
+ (m, info) => {
139
+ m[info.css] = info.id;
140
+ return m;
141
+ },
142
+ {}
143
+ );
144
+ TEXT_ALIGNMENT_INFOS$1.map((info) => ({
145
+ value: info.id,
146
+ label: info.label
147
+ }));
148
+ var PdfStandardFontFamily$1 = /* @__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$1 || {});
157
+ PdfStandardFont$1.Helvetica;
158
+ const HELVETICA_DESC$1 = {
159
+ id: PdfStandardFont$1.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$1 = Object.freeze([
167
+ {
168
+ id: PdfStandardFont$1.Courier,
169
+ family: "Courier",
170
+ bold: false,
171
+ italic: false,
172
+ label: "Courier",
173
+ css: "Courier, monospace"
174
+ },
175
+ {
176
+ id: PdfStandardFont$1.Courier_Bold,
177
+ family: "Courier",
178
+ bold: true,
179
+ italic: false,
180
+ label: "Courier Bold",
181
+ css: "Courier, monospace"
182
+ },
183
+ {
184
+ id: PdfStandardFont$1.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$1.Courier_Oblique,
193
+ family: "Courier",
194
+ bold: false,
195
+ italic: true,
196
+ label: "Courier Oblique",
197
+ css: "Courier, monospace"
198
+ },
199
+ HELVETICA_DESC$1,
200
+ {
201
+ id: PdfStandardFont$1.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$1.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$1.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$1.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$1.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$1.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$1.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$1.Symbol,
258
+ family: "Symbol",
259
+ bold: false,
260
+ italic: false,
261
+ label: "Symbol",
262
+ css: "Symbol, serif"
263
+ },
264
+ {
265
+ id: PdfStandardFont$1.ZapfDingbats,
266
+ family: "ZapfDingbats",
267
+ bold: false,
268
+ italic: false,
269
+ label: "Zapf Dingbats",
270
+ css: "ZapfDingbats, serif"
271
+ }
272
+ ]);
273
+ STANDARD_FONT_DESCRIPTORS$1.reduce((m, d) => (m[d.id] = d, m), {});
274
+ const familyStyleToId$1 = /* @__PURE__ */ new Map();
275
+ for (const d of STANDARD_FONT_DESCRIPTORS$1) {
276
+ familyStyleToId$1.set(`${d.family}_${d.bold}_${d.italic}`, d.id);
277
+ }
278
+ Object.values(PdfStandardFontFamily$1).filter(
279
+ (f) => f !== "Unknown"
280
+ /* Unknown */
281
+ ).map((family) => ({ value: family, label: family }));
282
+ [
283
+ ...new Set(STANDARD_FONT_DESCRIPTORS$1.map((d) => d.family))
284
+ ];
285
+ const BLEND_MODE_INFOS$1 = Object.freeze([
286
+ { id: PdfBlendMode$1.Normal, label: "Normal", css: "normal" },
287
+ { id: PdfBlendMode$1.Multiply, label: "Multiply", css: "multiply" },
288
+ { id: PdfBlendMode$1.Screen, label: "Screen", css: "screen" },
289
+ { id: PdfBlendMode$1.Overlay, label: "Overlay", css: "overlay" },
290
+ { id: PdfBlendMode$1.Darken, label: "Darken", css: "darken" },
291
+ { id: PdfBlendMode$1.Lighten, label: "Lighten", css: "lighten" },
292
+ { id: PdfBlendMode$1.ColorDodge, label: "Color Dodge", css: "color-dodge" },
293
+ { id: PdfBlendMode$1.ColorBurn, label: "Color Burn", css: "color-burn" },
294
+ { id: PdfBlendMode$1.HardLight, label: "Hard Light", css: "hard-light" },
295
+ { id: PdfBlendMode$1.SoftLight, label: "Soft Light", css: "soft-light" },
296
+ { id: PdfBlendMode$1.Difference, label: "Difference", css: "difference" },
297
+ { id: PdfBlendMode$1.Exclusion, label: "Exclusion", css: "exclusion" },
298
+ { id: PdfBlendMode$1.Hue, label: "Hue", css: "hue" },
299
+ { id: PdfBlendMode$1.Saturation, label: "Saturation", css: "saturation" },
300
+ { id: PdfBlendMode$1.Color, label: "Color", css: "color" },
301
+ { id: PdfBlendMode$1.Luminosity, label: "Luminosity", css: "luminosity" }
302
+ ]);
303
+ BLEND_MODE_INFOS$1.reduce(
304
+ (m, info) => {
305
+ m[info.id] = info;
306
+ return m;
307
+ },
308
+ {}
309
+ );
310
+ BLEND_MODE_INFOS$1.reduce(
311
+ (m, info) => {
312
+ m[info.css] = info.id;
313
+ return m;
314
+ },
315
+ {}
316
+ );
317
+ BLEND_MODE_INFOS$1.map((info) => ({
318
+ value: info.id,
319
+ label: info.label
320
+ }));
321
+ BLEND_MODE_INFOS$1.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 BOOKMARK_PLUGIN_ID = "bookmark";
383
+ const manifest = {
384
+ id: BOOKMARK_PLUGIN_ID,
385
+ name: "Bookmark Plugin",
386
+ version: "1.0.0",
387
+ provides: ["bookmark"],
388
+ requires: [],
389
+ optional: [],
390
+ defaultConfig: {}
391
+ };
392
+ const PdfSoftHyphenMarker = "­";
393
+ const PdfZeroWidthSpace = "​";
394
+ const PdfWordJoiner = "⁠";
395
+ const PdfBomOrZwnbsp = "\uFEFF";
396
+ const PdfNonCharacterFFFE = "￾";
397
+ const PdfNonCharacterFFFF = "￿";
398
+ const PdfUnwantedTextMarkers = Object.freeze([
399
+ PdfSoftHyphenMarker,
400
+ PdfZeroWidthSpace,
401
+ PdfWordJoiner,
402
+ PdfBomOrZwnbsp,
403
+ PdfNonCharacterFFFE,
404
+ PdfNonCharacterFFFF
405
+ ]);
406
+ new RegExp(`[${PdfUnwantedTextMarkers.join("")}]`, "g");
407
+ var PdfStandardFont = /* @__PURE__ */ ((PdfStandardFont2) => {
408
+ PdfStandardFont2[PdfStandardFont2["Unknown"] = -1] = "Unknown";
409
+ PdfStandardFont2[PdfStandardFont2["Courier"] = 0] = "Courier";
410
+ PdfStandardFont2[PdfStandardFont2["Courier_Bold"] = 1] = "Courier_Bold";
411
+ PdfStandardFont2[PdfStandardFont2["Courier_BoldOblique"] = 2] = "Courier_BoldOblique";
412
+ PdfStandardFont2[PdfStandardFont2["Courier_Oblique"] = 3] = "Courier_Oblique";
413
+ PdfStandardFont2[PdfStandardFont2["Helvetica"] = 4] = "Helvetica";
414
+ PdfStandardFont2[PdfStandardFont2["Helvetica_Bold"] = 5] = "Helvetica_Bold";
415
+ PdfStandardFont2[PdfStandardFont2["Helvetica_BoldOblique"] = 6] = "Helvetica_BoldOblique";
416
+ PdfStandardFont2[PdfStandardFont2["Helvetica_Oblique"] = 7] = "Helvetica_Oblique";
417
+ PdfStandardFont2[PdfStandardFont2["Times_Roman"] = 8] = "Times_Roman";
418
+ PdfStandardFont2[PdfStandardFont2["Times_Bold"] = 9] = "Times_Bold";
419
+ PdfStandardFont2[PdfStandardFont2["Times_BoldItalic"] = 10] = "Times_BoldItalic";
420
+ PdfStandardFont2[PdfStandardFont2["Times_Italic"] = 11] = "Times_Italic";
421
+ PdfStandardFont2[PdfStandardFont2["Symbol"] = 12] = "Symbol";
422
+ PdfStandardFont2[PdfStandardFont2["ZapfDingbats"] = 13] = "ZapfDingbats";
423
+ return PdfStandardFont2;
424
+ })(PdfStandardFont || {});
425
+ var PdfTextAlignment = /* @__PURE__ */ ((PdfTextAlignment2) => {
426
+ PdfTextAlignment2[PdfTextAlignment2["Left"] = 0] = "Left";
427
+ PdfTextAlignment2[PdfTextAlignment2["Center"] = 1] = "Center";
428
+ PdfTextAlignment2[PdfTextAlignment2["Right"] = 2] = "Right";
429
+ return PdfTextAlignment2;
430
+ })(PdfTextAlignment || {});
431
+ var PdfBlendMode = /* @__PURE__ */ ((PdfBlendMode2) => {
432
+ PdfBlendMode2[PdfBlendMode2["Normal"] = 0] = "Normal";
433
+ PdfBlendMode2[PdfBlendMode2["Multiply"] = 1] = "Multiply";
434
+ PdfBlendMode2[PdfBlendMode2["Screen"] = 2] = "Screen";
435
+ PdfBlendMode2[PdfBlendMode2["Overlay"] = 3] = "Overlay";
436
+ PdfBlendMode2[PdfBlendMode2["Darken"] = 4] = "Darken";
437
+ PdfBlendMode2[PdfBlendMode2["Lighten"] = 5] = "Lighten";
438
+ PdfBlendMode2[PdfBlendMode2["ColorDodge"] = 6] = "ColorDodge";
439
+ PdfBlendMode2[PdfBlendMode2["ColorBurn"] = 7] = "ColorBurn";
440
+ PdfBlendMode2[PdfBlendMode2["HardLight"] = 8] = "HardLight";
441
+ PdfBlendMode2[PdfBlendMode2["SoftLight"] = 9] = "SoftLight";
442
+ PdfBlendMode2[PdfBlendMode2["Difference"] = 10] = "Difference";
443
+ PdfBlendMode2[PdfBlendMode2["Exclusion"] = 11] = "Exclusion";
444
+ PdfBlendMode2[PdfBlendMode2["Hue"] = 12] = "Hue";
445
+ PdfBlendMode2[PdfBlendMode2["Saturation"] = 13] = "Saturation";
446
+ PdfBlendMode2[PdfBlendMode2["Color"] = 14] = "Color";
447
+ PdfBlendMode2[PdfBlendMode2["Luminosity"] = 15] = "Luminosity";
448
+ return PdfBlendMode2;
449
+ })(PdfBlendMode || {});
450
+ const PdfAnnotationFlagName = Object.freeze({
451
+ [
452
+ 1
453
+ /* INVISIBLE */
454
+ ]: "invisible",
455
+ [
456
+ 2
457
+ /* HIDDEN */
458
+ ]: "hidden",
459
+ [
460
+ 4
461
+ /* PRINT */
462
+ ]: "print",
463
+ [
464
+ 8
465
+ /* NO_ZOOM */
466
+ ]: "noZoom",
467
+ [
468
+ 16
469
+ /* NO_ROTATE */
470
+ ]: "noRotate",
471
+ [
472
+ 32
473
+ /* NO_VIEW */
474
+ ]: "noView",
475
+ [
476
+ 64
477
+ /* READ_ONLY */
478
+ ]: "readOnly",
479
+ [
480
+ 128
481
+ /* LOCKED */
482
+ ]: "locked",
483
+ [
484
+ 256
485
+ /* TOGGLE_NOVIEW */
486
+ ]: "toggleNoView"
487
+ });
488
+ Object.entries(
489
+ PdfAnnotationFlagName
490
+ ).reduce(
491
+ (acc, [bit, name]) => {
492
+ acc[name] = Number(bit);
493
+ return acc;
494
+ },
495
+ {}
496
+ );
497
+ var PdfPermissionFlag = /* @__PURE__ */ ((PdfPermissionFlag2) => {
498
+ PdfPermissionFlag2[PdfPermissionFlag2["Print"] = 4] = "Print";
499
+ PdfPermissionFlag2[PdfPermissionFlag2["ModifyContents"] = 8] = "ModifyContents";
500
+ PdfPermissionFlag2[PdfPermissionFlag2["CopyContents"] = 16] = "CopyContents";
501
+ PdfPermissionFlag2[PdfPermissionFlag2["ModifyAnnotations"] = 32] = "ModifyAnnotations";
502
+ PdfPermissionFlag2[PdfPermissionFlag2["FillForms"] = 256] = "FillForms";
503
+ PdfPermissionFlag2[PdfPermissionFlag2["ExtractForAccessibility"] = 512] = "ExtractForAccessibility";
504
+ PdfPermissionFlag2[PdfPermissionFlag2["AssembleDocument"] = 1024] = "AssembleDocument";
505
+ PdfPermissionFlag2[PdfPermissionFlag2["PrintHighQuality"] = 2048] = "PrintHighQuality";
506
+ PdfPermissionFlag2[PdfPermissionFlag2["AllowAll"] = 3900] = "AllowAll";
507
+ return PdfPermissionFlag2;
508
+ })(PdfPermissionFlag || {});
509
+ class PermissionDeniedError extends Error {
510
+ constructor(requiredFlags, currentPermissions) {
511
+ const flagNames = requiredFlags.map((f) => PdfPermissionFlag[f]).join(", ");
512
+ super(`Permission denied. Required: ${flagNames}`);
513
+ this.requiredFlags = requiredFlags;
514
+ this.currentPermissions = currentPermissions;
515
+ this.name = "PermissionDeniedError";
516
+ }
517
+ }
518
+ const TEXT_ALIGNMENT_INFOS = Object.freeze([
519
+ { id: PdfTextAlignment.Left, label: "Left", css: "left" },
520
+ { id: PdfTextAlignment.Center, label: "Center", css: "center" },
521
+ { id: PdfTextAlignment.Right, label: "Right", css: "right" }
522
+ ]);
523
+ TEXT_ALIGNMENT_INFOS.reduce(
524
+ (m, info) => {
525
+ m[info.id] = info;
526
+ return m;
527
+ },
528
+ {}
529
+ );
530
+ TEXT_ALIGNMENT_INFOS.reduce(
531
+ (m, info) => {
532
+ m[info.css] = info.id;
533
+ return m;
534
+ },
535
+ {}
536
+ );
537
+ TEXT_ALIGNMENT_INFOS.map((info) => ({
538
+ value: info.id,
539
+ label: info.label
540
+ }));
541
+ var PdfStandardFontFamily = /* @__PURE__ */ ((PdfStandardFontFamily2) => {
542
+ PdfStandardFontFamily2["Courier"] = "Courier";
543
+ PdfStandardFontFamily2["Helvetica"] = "Helvetica";
544
+ PdfStandardFontFamily2["Times"] = "Times";
545
+ PdfStandardFontFamily2["Symbol"] = "Symbol";
546
+ PdfStandardFontFamily2["ZapfDingbats"] = "ZapfDingbats";
547
+ PdfStandardFontFamily2["Unknown"] = "Unknown";
548
+ return PdfStandardFontFamily2;
549
+ })(PdfStandardFontFamily || {});
550
+ PdfStandardFont.Helvetica;
551
+ const HELVETICA_DESC = {
552
+ id: PdfStandardFont.Helvetica,
553
+ family: "Helvetica",
554
+ bold: false,
555
+ italic: false,
556
+ label: "Helvetica",
557
+ css: "Helvetica, Arial, sans-serif"
558
+ };
559
+ const STANDARD_FONT_DESCRIPTORS = Object.freeze([
560
+ {
561
+ id: PdfStandardFont.Courier,
562
+ family: "Courier",
563
+ bold: false,
564
+ italic: false,
565
+ label: "Courier",
566
+ css: "Courier, monospace"
567
+ },
568
+ {
569
+ id: PdfStandardFont.Courier_Bold,
570
+ family: "Courier",
571
+ bold: true,
572
+ italic: false,
573
+ label: "Courier Bold",
574
+ css: "Courier, monospace"
575
+ },
576
+ {
577
+ id: PdfStandardFont.Courier_BoldOblique,
578
+ family: "Courier",
579
+ bold: true,
580
+ italic: true,
581
+ label: "Courier Bold Oblique",
582
+ css: "Courier, monospace"
583
+ },
584
+ {
585
+ id: PdfStandardFont.Courier_Oblique,
586
+ family: "Courier",
587
+ bold: false,
588
+ italic: true,
589
+ label: "Courier Oblique",
590
+ css: "Courier, monospace"
591
+ },
592
+ HELVETICA_DESC,
593
+ {
594
+ id: PdfStandardFont.Helvetica_Bold,
595
+ family: "Helvetica",
596
+ bold: true,
597
+ italic: false,
598
+ label: "Helvetica Bold",
599
+ css: "Helvetica, Arial, sans-serif"
600
+ },
601
+ {
602
+ id: PdfStandardFont.Helvetica_BoldOblique,
603
+ family: "Helvetica",
604
+ bold: true,
605
+ italic: true,
606
+ label: "Helvetica Bold Oblique",
607
+ css: "Helvetica, Arial, sans-serif"
608
+ },
609
+ {
610
+ id: PdfStandardFont.Helvetica_Oblique,
611
+ family: "Helvetica",
612
+ bold: false,
613
+ italic: true,
614
+ label: "Helvetica Oblique",
615
+ css: "Helvetica, Arial, sans-serif"
616
+ },
617
+ {
618
+ id: PdfStandardFont.Times_Roman,
619
+ family: "Times",
620
+ bold: false,
621
+ italic: false,
622
+ label: "Times Roman",
623
+ css: '"Times New Roman", Times, serif'
624
+ },
625
+ {
626
+ id: PdfStandardFont.Times_Bold,
627
+ family: "Times",
628
+ bold: true,
629
+ italic: false,
630
+ label: "Times Bold",
631
+ css: '"Times New Roman", Times, serif'
632
+ },
633
+ {
634
+ id: PdfStandardFont.Times_BoldItalic,
635
+ family: "Times",
636
+ bold: true,
637
+ italic: true,
638
+ label: "Times Bold Italic",
639
+ css: '"Times New Roman", Times, serif'
640
+ },
641
+ {
642
+ id: PdfStandardFont.Times_Italic,
643
+ family: "Times",
644
+ bold: false,
645
+ italic: true,
646
+ label: "Times Italic",
647
+ css: '"Times New Roman", Times, serif'
648
+ },
649
+ {
650
+ id: PdfStandardFont.Symbol,
651
+ family: "Symbol",
652
+ bold: false,
653
+ italic: false,
654
+ label: "Symbol",
655
+ css: "Symbol, serif"
656
+ },
657
+ {
658
+ id: PdfStandardFont.ZapfDingbats,
659
+ family: "ZapfDingbats",
660
+ bold: false,
661
+ italic: false,
662
+ label: "Zapf Dingbats",
663
+ css: "ZapfDingbats, serif"
664
+ }
665
+ ]);
666
+ STANDARD_FONT_DESCRIPTORS.reduce((m, d) => (m[d.id] = d, m), {});
667
+ const familyStyleToId = /* @__PURE__ */ new Map();
668
+ for (const d of STANDARD_FONT_DESCRIPTORS) {
669
+ familyStyleToId.set(`${d.family}_${d.bold}_${d.italic}`, d.id);
670
+ }
671
+ Object.values(PdfStandardFontFamily).filter(
672
+ (f) => f !== "Unknown"
673
+ /* Unknown */
674
+ ).map((family) => ({ value: family, label: family }));
675
+ [
676
+ ...new Set(STANDARD_FONT_DESCRIPTORS.map((d) => d.family))
677
+ ];
678
+ const BLEND_MODE_INFOS = Object.freeze([
679
+ { id: PdfBlendMode.Normal, label: "Normal", css: "normal" },
680
+ { id: PdfBlendMode.Multiply, label: "Multiply", css: "multiply" },
681
+ { id: PdfBlendMode.Screen, label: "Screen", css: "screen" },
682
+ { id: PdfBlendMode.Overlay, label: "Overlay", css: "overlay" },
683
+ { id: PdfBlendMode.Darken, label: "Darken", css: "darken" },
684
+ { id: PdfBlendMode.Lighten, label: "Lighten", css: "lighten" },
685
+ { id: PdfBlendMode.ColorDodge, label: "Color Dodge", css: "color-dodge" },
686
+ { id: PdfBlendMode.ColorBurn, label: "Color Burn", css: "color-burn" },
687
+ { id: PdfBlendMode.HardLight, label: "Hard Light", css: "hard-light" },
688
+ { id: PdfBlendMode.SoftLight, label: "Soft Light", css: "soft-light" },
689
+ { id: PdfBlendMode.Difference, label: "Difference", css: "difference" },
690
+ { id: PdfBlendMode.Exclusion, label: "Exclusion", css: "exclusion" },
691
+ { id: PdfBlendMode.Hue, label: "Hue", css: "hue" },
692
+ { id: PdfBlendMode.Saturation, label: "Saturation", css: "saturation" },
693
+ { id: PdfBlendMode.Color, label: "Color", css: "color" },
694
+ { id: PdfBlendMode.Luminosity, label: "Luminosity", css: "luminosity" }
695
+ ]);
696
+ BLEND_MODE_INFOS.reduce(
697
+ (m, info) => {
698
+ m[info.id] = info;
699
+ return m;
700
+ },
701
+ {}
702
+ );
703
+ BLEND_MODE_INFOS.reduce(
704
+ (m, info) => {
705
+ m[info.css] = info.id;
706
+ return m;
707
+ },
708
+ {}
709
+ );
710
+ BLEND_MODE_INFOS.map((info) => ({
711
+ value: info.id,
712
+ label: info.label
713
+ }));
714
+ BLEND_MODE_INFOS.map((info) => info.id);
715
+ const START_LOADING_DOCUMENT = "START_LOADING_DOCUMENT";
716
+ const SET_DOCUMENT_LOADED = "SET_DOCUMENT_LOADED";
717
+ const CLOSE_DOCUMENT = "CLOSE_DOCUMENT";
718
+ const SET_SCALE = "SET_SCALE";
719
+ const SET_ROTATION = "SET_ROTATION";
720
+ ({
721
+ print: PdfPermissionFlag.Print,
722
+ modifyContents: PdfPermissionFlag.ModifyContents,
723
+ copyContents: PdfPermissionFlag.CopyContents,
724
+ modifyAnnotations: PdfPermissionFlag.ModifyAnnotations,
725
+ fillForms: PdfPermissionFlag.FillForms,
726
+ extractForAccessibility: PdfPermissionFlag.ExtractForAccessibility,
727
+ assembleDocument: PdfPermissionFlag.AssembleDocument,
728
+ printHighQuality: PdfPermissionFlag.PrintHighQuality
729
+ });
730
+ const ALL_PERMISSION_FLAGS = [
731
+ PdfPermissionFlag.Print,
732
+ PdfPermissionFlag.ModifyContents,
733
+ PdfPermissionFlag.CopyContents,
734
+ PdfPermissionFlag.ModifyAnnotations,
735
+ PdfPermissionFlag.FillForms,
736
+ PdfPermissionFlag.ExtractForAccessibility,
737
+ PdfPermissionFlag.AssembleDocument,
738
+ PdfPermissionFlag.PrintHighQuality
739
+ ];
740
+ const PERMISSION_FLAG_TO_NAME = {
741
+ [PdfPermissionFlag.Print]: "print",
742
+ [PdfPermissionFlag.ModifyContents]: "modifyContents",
743
+ [PdfPermissionFlag.CopyContents]: "copyContents",
744
+ [PdfPermissionFlag.ModifyAnnotations]: "modifyAnnotations",
745
+ [PdfPermissionFlag.FillForms]: "fillForms",
746
+ [PdfPermissionFlag.ExtractForAccessibility]: "extractForAccessibility",
747
+ [PdfPermissionFlag.AssembleDocument]: "assembleDocument",
748
+ [PdfPermissionFlag.PrintHighQuality]: "printHighQuality"
749
+ };
750
+ function getPermissionOverride(overrides, flag) {
751
+ if (!overrides) return void 0;
752
+ if (flag in overrides) {
753
+ return overrides[flag];
754
+ }
755
+ const name = PERMISSION_FLAG_TO_NAME[flag];
756
+ if (name && name in overrides) {
757
+ return overrides[name];
758
+ }
759
+ return void 0;
760
+ }
761
+ function getEffectivePermission(state, documentId, flag) {
762
+ var _a;
763
+ const docState = state.documents[documentId];
764
+ const docConfig = docState == null ? void 0 : docState.permissions;
765
+ const globalConfig = state.globalPermissions;
766
+ const pdfPermissions = ((_a = docState == null ? void 0 : docState.document) == null ? void 0 : _a.permissions) ?? PdfPermissionFlag.AllowAll;
767
+ const docOverride = getPermissionOverride(docConfig == null ? void 0 : docConfig.overrides, flag);
768
+ if (docOverride !== void 0) {
769
+ return docOverride;
770
+ }
771
+ const globalOverride = getPermissionOverride(globalConfig == null ? void 0 : globalConfig.overrides, flag);
772
+ if (globalOverride !== void 0) {
773
+ return globalOverride;
774
+ }
775
+ const enforce = (docConfig == null ? void 0 : docConfig.enforceDocumentPermissions) ?? (globalConfig == null ? void 0 : globalConfig.enforceDocumentPermissions) ?? true;
776
+ if (!enforce) return true;
777
+ return (pdfPermissions & flag) !== 0;
778
+ }
779
+ function getEffectivePermissions(state, documentId) {
780
+ return ALL_PERMISSION_FLAGS.reduce((acc, flag) => {
781
+ return getEffectivePermission(state, documentId, flag) ? acc | flag : acc;
782
+ }, 0);
783
+ }
784
+ class BasePlugin {
785
+ constructor(id, registry) {
786
+ this.id = id;
787
+ this.registry = registry;
788
+ this.cooldownActions = {};
789
+ this.debouncedTimeouts = {};
790
+ this.unsubscribeFromState = null;
791
+ this.unsubscribeFromCoreStore = null;
792
+ this.unsubscribeFromStartLoadingDocument = null;
793
+ this.unsubscribeFromSetDocumentLoaded = null;
794
+ this.unsubscribeFromCloseDocument = null;
795
+ this.unsubscribeFromSetScale = null;
796
+ this.unsubscribeFromSetRotation = null;
797
+ if (id !== this.constructor.id) {
798
+ throw new Error(
799
+ `Plugin ID mismatch: ${id} !== ${this.constructor.id}`
800
+ );
801
+ }
802
+ this.engine = this.registry.getEngine();
803
+ this.logger = this.registry.getLogger();
804
+ this.coreStore = this.registry.getStore();
805
+ this.pluginStore = this.coreStore.getPluginStore(this.id);
806
+ this.unsubscribeFromState = this.pluginStore.subscribeToState((action, newState, oldState) => {
807
+ this.onStoreUpdated(oldState, newState);
808
+ });
809
+ this.unsubscribeFromCoreStore = this.coreStore.subscribe((action, newState, oldState) => {
810
+ this.onCoreStoreUpdated(oldState, newState);
811
+ if (newState.core.activeDocumentId !== oldState.core.activeDocumentId) {
812
+ this.onActiveDocumentChanged(
813
+ oldState.core.activeDocumentId,
814
+ newState.core.activeDocumentId
815
+ );
816
+ }
817
+ });
818
+ this.unsubscribeFromStartLoadingDocument = this.coreStore.onAction(
819
+ START_LOADING_DOCUMENT,
820
+ (action) => {
821
+ this.onDocumentLoadingStarted(action.payload.documentId);
822
+ }
823
+ );
824
+ this.unsubscribeFromSetDocumentLoaded = this.coreStore.onAction(
825
+ SET_DOCUMENT_LOADED,
826
+ (action) => {
827
+ this.onDocumentLoaded(action.payload.documentId);
828
+ }
829
+ );
830
+ this.unsubscribeFromCloseDocument = this.coreStore.onAction(CLOSE_DOCUMENT, (action) => {
831
+ this.onDocumentClosed(action.payload.documentId);
832
+ });
833
+ this.unsubscribeFromSetScale = this.coreStore.onAction(SET_SCALE, (action, state) => {
834
+ const targetId = action.payload.documentId ?? state.core.activeDocumentId;
835
+ if (targetId) {
836
+ this.onScaleChanged(targetId, action.payload.scale);
837
+ }
838
+ });
839
+ this.unsubscribeFromSetRotation = this.coreStore.onAction(SET_ROTATION, (action, state) => {
840
+ const targetId = action.payload.documentId ?? state.core.activeDocumentId;
841
+ if (targetId) {
842
+ this.onRotationChanged(targetId, action.payload.rotation);
843
+ }
844
+ });
845
+ this.readyPromise = new Promise((resolve) => {
846
+ this.readyResolve = resolve;
847
+ });
848
+ this.readyResolve();
849
+ }
850
+ provides() {
851
+ if (!this._capability) {
852
+ const cap = this.buildCapability();
853
+ this._capability = Object.freeze(cap);
854
+ }
855
+ return this._capability;
856
+ }
857
+ /**
858
+ * Get a copy of the current state
859
+ */
860
+ get state() {
861
+ return this.pluginStore.getState();
862
+ }
863
+ /**
864
+ * Get a copy of the current core state
865
+ */
866
+ get coreState() {
867
+ return this.coreStore.getState();
868
+ }
869
+ /**
870
+ * @deprecated use `this.state` Get a copy of the current state
871
+ */
872
+ getState() {
873
+ return this.pluginStore.getState();
874
+ }
875
+ /**
876
+ * @deprecated use `this.coreState` Get a copy of the current core state
877
+ */
878
+ getCoreState() {
879
+ return this.coreStore.getState();
880
+ }
881
+ /**
882
+ * Core Dispatch
883
+ */
884
+ dispatchCoreAction(action) {
885
+ return this.coreStore.dispatchToCore(action);
886
+ }
887
+ /**
888
+ * Dispatch an action to all plugins
889
+ */
890
+ dispatchToAllPlugins(action) {
891
+ return this.coreStore.dispatch(action);
892
+ }
893
+ /**
894
+ * Dispatch an action
895
+ */
896
+ dispatch(action) {
897
+ return this.pluginStore.dispatch(action);
898
+ }
899
+ /**
900
+ * Dispatch an action with a cooldown to prevent rapid repeated calls
901
+ * This executes immediately if cooldown has expired, then blocks subsequent calls
902
+ * @param action The action to dispatch
903
+ * @param cooldownTime Time in ms for cooldown (default: 100ms)
904
+ * @returns boolean indicating whether the action was dispatched or blocked
905
+ */
906
+ cooldownDispatch(action, cooldownTime = 100) {
907
+ const now = Date.now();
908
+ const lastActionTime = this.cooldownActions[action.type] || 0;
909
+ if (now - lastActionTime >= cooldownTime) {
910
+ this.cooldownActions[action.type] = now;
911
+ this.dispatch(action);
912
+ return true;
913
+ }
914
+ return false;
915
+ }
916
+ /**
917
+ * Dispatch an action with true debouncing - waits for the delay after the last call
918
+ * Each new call resets the timer. Action only executes after no calls for the specified time.
919
+ * @param action The action to dispatch
920
+ * @param debounceTime Time in ms to wait after the last call
921
+ */
922
+ debouncedDispatch(action, debounceTime = 100) {
923
+ const actionKey = action.type;
924
+ if (this.debouncedTimeouts[actionKey]) {
925
+ clearTimeout(this.debouncedTimeouts[actionKey]);
926
+ }
927
+ this.debouncedTimeouts[actionKey] = setTimeout(() => {
928
+ this.dispatch(action);
929
+ delete this.debouncedTimeouts[actionKey];
930
+ }, debounceTime);
931
+ }
932
+ /**
933
+ * Cancel a pending debounced action
934
+ * @param actionType The action type to cancel
935
+ */
936
+ cancelDebouncedDispatch(actionType) {
937
+ if (this.debouncedTimeouts[actionType]) {
938
+ clearTimeout(this.debouncedTimeouts[actionType]);
939
+ delete this.debouncedTimeouts[actionType];
940
+ }
941
+ }
942
+ /**
943
+ * Subscribe to state changes
944
+ */
945
+ subscribe(listener) {
946
+ return this.pluginStore.subscribeToState(listener);
947
+ }
948
+ /**
949
+ * Subscribe to core store changes
950
+ */
951
+ subscribeToCoreStore(listener) {
952
+ return this.coreStore.subscribe(listener);
953
+ }
954
+ /**
955
+ * Called when the plugin store state is updated
956
+ * @param oldState Previous state
957
+ * @param newState New state
958
+ */
959
+ onStoreUpdated(oldState, newState) {
960
+ }
961
+ /**
962
+ * Called when the core store state is updated
963
+ * @param oldState Previous state
964
+ * @param newState New state
965
+ */
966
+ onCoreStoreUpdated(oldState, newState) {
967
+ }
968
+ /**
969
+ * Called when a document is opened
970
+ * Override to initialize per-document state
971
+ * @param documentId The ID of the document that was opened
972
+ */
973
+ onDocumentLoadingStarted(documentId) {
974
+ }
975
+ /**
976
+ * Called when a document is loaded
977
+ * @param documentId The ID of the document that is loaded
978
+ */
979
+ onDocumentLoaded(documentId) {
980
+ }
981
+ /**
982
+ * Called when a document is closed
983
+ * Override to cleanup per-document state
984
+ * @param documentId The ID of the document that was closed
985
+ */
986
+ onDocumentClosed(documentId) {
987
+ }
988
+ /**
989
+ * Called when the active document changes
990
+ * @param previousId The ID of the previous active document
991
+ * @param currentId The ID of the new active document
992
+ */
993
+ onActiveDocumentChanged(previousId, currentId) {
994
+ }
995
+ onScaleChanged(documentId, scale) {
996
+ }
997
+ onRotationChanged(documentId, rotation) {
998
+ }
999
+ /**
1000
+ * Cleanup method to be called when plugin is being destroyed
1001
+ */
1002
+ destroy() {
1003
+ Object.values(this.debouncedTimeouts).forEach((timeout) => {
1004
+ clearTimeout(timeout);
1005
+ });
1006
+ this.debouncedTimeouts = {};
1007
+ if (this.unsubscribeFromState) {
1008
+ this.unsubscribeFromState();
1009
+ this.unsubscribeFromState = null;
1010
+ }
1011
+ if (this.unsubscribeFromCoreStore) {
1012
+ this.unsubscribeFromCoreStore();
1013
+ this.unsubscribeFromCoreStore = null;
1014
+ }
1015
+ if (this.unsubscribeFromStartLoadingDocument) {
1016
+ this.unsubscribeFromStartLoadingDocument();
1017
+ this.unsubscribeFromStartLoadingDocument = null;
1018
+ }
1019
+ if (this.unsubscribeFromSetDocumentLoaded) {
1020
+ this.unsubscribeFromSetDocumentLoaded();
1021
+ this.unsubscribeFromSetDocumentLoaded = null;
1022
+ }
1023
+ if (this.unsubscribeFromCloseDocument) {
1024
+ this.unsubscribeFromCloseDocument();
1025
+ this.unsubscribeFromCloseDocument = null;
1026
+ }
1027
+ if (this.unsubscribeFromSetScale) {
1028
+ this.unsubscribeFromSetScale();
1029
+ this.unsubscribeFromSetScale = null;
1030
+ }
1031
+ if (this.unsubscribeFromSetRotation) {
1032
+ this.unsubscribeFromSetRotation();
1033
+ this.unsubscribeFromSetRotation = null;
1034
+ }
1035
+ }
1036
+ /**
1037
+ * Returns a promise that resolves when the plugin is ready
1038
+ */
1039
+ ready() {
1040
+ return this.readyPromise;
1041
+ }
1042
+ /**
1043
+ * Mark the plugin as ready
1044
+ */
1045
+ markReady() {
1046
+ this.readyResolve();
1047
+ }
1048
+ /**
1049
+ * Reset the ready state (useful for plugins that need to reinitialize)
1050
+ */
1051
+ resetReady() {
1052
+ this.readyPromise = new Promise((resolve) => {
1053
+ this.readyResolve = resolve;
1054
+ });
1055
+ }
1056
+ /**
1057
+ * Get the active document ID
1058
+ * @throws Error if no active document exists
1059
+ */
1060
+ getActiveDocumentId() {
1061
+ const id = this.coreState.core.activeDocumentId;
1062
+ if (!id) {
1063
+ throw new Error("No active document");
1064
+ }
1065
+ return id;
1066
+ }
1067
+ /**
1068
+ * Get the active document ID or null if none exists
1069
+ */
1070
+ getActiveDocumentIdOrNull() {
1071
+ return this.coreState.core.activeDocumentId;
1072
+ }
1073
+ /**
1074
+ * Get core document state for a specific document
1075
+ * @param documentId Document ID (optional, defaults to active document)
1076
+ * @returns Document state or null if not found
1077
+ */
1078
+ getCoreDocument(documentId) {
1079
+ const id = documentId ?? this.getActiveDocumentIdOrNull();
1080
+ if (!id) return null;
1081
+ return this.coreState.core.documents[id] ?? null;
1082
+ }
1083
+ /**
1084
+ * Get core document state for a specific document
1085
+ * @param documentId Document ID (optional, defaults to active document)
1086
+ * @throws Error if document not found
1087
+ */
1088
+ getCoreDocumentOrThrow(documentId) {
1089
+ const doc = this.getCoreDocument(documentId);
1090
+ if (!doc) {
1091
+ throw new Error(`Document not found: ${documentId ?? "active"}`);
1092
+ }
1093
+ return doc;
1094
+ }
1095
+ // ─────────────────────────────────────────────────────────
1096
+ // Permission Helpers
1097
+ // ─────────────────────────────────────────────────────────
1098
+ /**
1099
+ * Get the effective permission flags for a document.
1100
+ * Applies layered resolution: per-document override → global override → PDF permission.
1101
+ * Returns AllowAll if document not found.
1102
+ * @param documentId Document ID (optional, defaults to active document)
1103
+ */
1104
+ getDocumentPermissions(documentId) {
1105
+ const docId = documentId ?? this.coreState.core.activeDocumentId;
1106
+ if (!docId) return PdfPermissionFlag.AllowAll;
1107
+ return getEffectivePermissions(this.coreState.core, docId);
1108
+ }
1109
+ /**
1110
+ * Check if a document has the required permissions (returns boolean).
1111
+ * Applies layered resolution: per-document override → global override → PDF permission.
1112
+ * Useful for conditional UI logic.
1113
+ * @param documentId Document ID (optional, defaults to active document)
1114
+ * @param flags Permission flags to check
1115
+ */
1116
+ checkPermission(documentId, ...flags) {
1117
+ const docId = documentId ?? this.coreState.core.activeDocumentId;
1118
+ if (!docId) return true;
1119
+ return flags.every((flag) => getEffectivePermission(this.coreState.core, docId, flag));
1120
+ }
1121
+ /**
1122
+ * Assert that a document has the required permissions.
1123
+ * Applies layered resolution: per-document override → global override → PDF permission.
1124
+ * Throws PermissionDeniedError if any flag is missing.
1125
+ * @param documentId Document ID (optional, defaults to active document)
1126
+ * @param flags Permission flags to require
1127
+ */
1128
+ requirePermission(documentId, ...flags) {
1129
+ const docId = documentId ?? this.coreState.core.activeDocumentId;
1130
+ if (!docId) return;
1131
+ const missingFlags = [];
1132
+ for (const flag of flags) {
1133
+ if (!getEffectivePermission(this.coreState.core, docId, flag)) {
1134
+ missingFlags.push(flag);
1135
+ }
1136
+ }
1137
+ if (missingFlags.length > 0) {
1138
+ const effectivePermissions = getEffectivePermissions(this.coreState.core, docId);
1139
+ throw new PermissionDeniedError(missingFlags, effectivePermissions);
1140
+ }
1141
+ }
1142
+ }
1143
+ const _BookmarkPlugin = class _BookmarkPlugin extends BasePlugin {
1144
+ constructor(id, registry) {
1145
+ super(id, registry);
1146
+ }
1147
+ async initialize(_) {
1148
+ }
1149
+ // ─────────────────────────────────────────────────────────
1150
+ // Capability
1151
+ // ─────────────────────────────────────────────────────────
1152
+ buildCapability() {
1153
+ return {
1154
+ // Active document operations
1155
+ getBookmarks: () => this.getBookmarks(),
1156
+ // Document-scoped operations
1157
+ forDocument: (documentId) => this.createBookmarkScope(documentId)
1158
+ };
1159
+ }
1160
+ // ─────────────────────────────────────────────────────────
1161
+ // Document Scoping
1162
+ // ─────────────────────────────────────────────────────────
1163
+ createBookmarkScope(documentId) {
1164
+ return {
1165
+ getBookmarks: () => this.getBookmarks(documentId)
1166
+ };
1167
+ }
1168
+ // ─────────────────────────────────────────────────────────
1169
+ // Core Operations
1170
+ // ─────────────────────────────────────────────────────────
1171
+ getBookmarks(documentId) {
1172
+ const id = documentId ?? this.getActiveDocumentId();
1173
+ const coreDoc = this.coreState.core.documents[id];
1174
+ if (!(coreDoc == null ? void 0 : coreDoc.document)) {
1175
+ throw new Error(`Document ${id} not loaded`);
1176
+ }
1177
+ return this.engine.getBookmarks(coreDoc.document);
1178
+ }
1179
+ };
1180
+ _BookmarkPlugin.id = "bookmark";
1181
+ let BookmarkPlugin = _BookmarkPlugin;
1182
+ const BookmarkPluginPackage = {
1183
+ manifest,
1184
+ create: (registry) => new BookmarkPlugin(BOOKMARK_PLUGIN_ID, registry),
1185
+ reducer: () => {
1186
+ },
1187
+ initialState: {}
1188
+ };
1189
+ const useBookmarkPlugin = () => usePlugin(BookmarkPlugin.id);
1190
+ const useBookmarkCapability = () => useCapability(BookmarkPlugin.id);
1191
+ export {
1192
+ BOOKMARK_PLUGIN_ID,
1193
+ BookmarkPlugin,
1194
+ BookmarkPluginPackage,
1195
+ manifest,
1196
+ useBookmarkCapability,
1197
+ useBookmarkPlugin
1198
+ };
1199
+ //# sourceMappingURL=index.js.map