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