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