@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
package/dist/index.js ADDED
@@ -0,0 +1,814 @@
1
+ const BOOKMARK_PLUGIN_ID = "bookmark";
2
+ const manifest = {
3
+ id: BOOKMARK_PLUGIN_ID,
4
+ name: "Bookmark Plugin",
5
+ version: "1.0.0",
6
+ provides: ["bookmark"],
7
+ requires: [],
8
+ optional: [],
9
+ defaultConfig: {}
10
+ };
11
+ const PdfSoftHyphenMarker = "­";
12
+ const PdfZeroWidthSpace = "​";
13
+ const PdfWordJoiner = "⁠";
14
+ const PdfBomOrZwnbsp = "\uFEFF";
15
+ const PdfNonCharacterFFFE = "￾";
16
+ const PdfNonCharacterFFFF = "￿";
17
+ const PdfUnwantedTextMarkers = Object.freeze([
18
+ PdfSoftHyphenMarker,
19
+ PdfZeroWidthSpace,
20
+ PdfWordJoiner,
21
+ PdfBomOrZwnbsp,
22
+ PdfNonCharacterFFFE,
23
+ PdfNonCharacterFFFF
24
+ ]);
25
+ new RegExp(`[${PdfUnwantedTextMarkers.join("")}]`, "g");
26
+ var PdfStandardFont = /* @__PURE__ */ ((PdfStandardFont2) => {
27
+ PdfStandardFont2[PdfStandardFont2["Unknown"] = -1] = "Unknown";
28
+ PdfStandardFont2[PdfStandardFont2["Courier"] = 0] = "Courier";
29
+ PdfStandardFont2[PdfStandardFont2["Courier_Bold"] = 1] = "Courier_Bold";
30
+ PdfStandardFont2[PdfStandardFont2["Courier_BoldOblique"] = 2] = "Courier_BoldOblique";
31
+ PdfStandardFont2[PdfStandardFont2["Courier_Oblique"] = 3] = "Courier_Oblique";
32
+ PdfStandardFont2[PdfStandardFont2["Helvetica"] = 4] = "Helvetica";
33
+ PdfStandardFont2[PdfStandardFont2["Helvetica_Bold"] = 5] = "Helvetica_Bold";
34
+ PdfStandardFont2[PdfStandardFont2["Helvetica_BoldOblique"] = 6] = "Helvetica_BoldOblique";
35
+ PdfStandardFont2[PdfStandardFont2["Helvetica_Oblique"] = 7] = "Helvetica_Oblique";
36
+ PdfStandardFont2[PdfStandardFont2["Times_Roman"] = 8] = "Times_Roman";
37
+ PdfStandardFont2[PdfStandardFont2["Times_Bold"] = 9] = "Times_Bold";
38
+ PdfStandardFont2[PdfStandardFont2["Times_BoldItalic"] = 10] = "Times_BoldItalic";
39
+ PdfStandardFont2[PdfStandardFont2["Times_Italic"] = 11] = "Times_Italic";
40
+ PdfStandardFont2[PdfStandardFont2["Symbol"] = 12] = "Symbol";
41
+ PdfStandardFont2[PdfStandardFont2["ZapfDingbats"] = 13] = "ZapfDingbats";
42
+ return PdfStandardFont2;
43
+ })(PdfStandardFont || {});
44
+ var PdfTextAlignment = /* @__PURE__ */ ((PdfTextAlignment2) => {
45
+ PdfTextAlignment2[PdfTextAlignment2["Left"] = 0] = "Left";
46
+ PdfTextAlignment2[PdfTextAlignment2["Center"] = 1] = "Center";
47
+ PdfTextAlignment2[PdfTextAlignment2["Right"] = 2] = "Right";
48
+ return PdfTextAlignment2;
49
+ })(PdfTextAlignment || {});
50
+ var PdfBlendMode = /* @__PURE__ */ ((PdfBlendMode2) => {
51
+ PdfBlendMode2[PdfBlendMode2["Normal"] = 0] = "Normal";
52
+ PdfBlendMode2[PdfBlendMode2["Multiply"] = 1] = "Multiply";
53
+ PdfBlendMode2[PdfBlendMode2["Screen"] = 2] = "Screen";
54
+ PdfBlendMode2[PdfBlendMode2["Overlay"] = 3] = "Overlay";
55
+ PdfBlendMode2[PdfBlendMode2["Darken"] = 4] = "Darken";
56
+ PdfBlendMode2[PdfBlendMode2["Lighten"] = 5] = "Lighten";
57
+ PdfBlendMode2[PdfBlendMode2["ColorDodge"] = 6] = "ColorDodge";
58
+ PdfBlendMode2[PdfBlendMode2["ColorBurn"] = 7] = "ColorBurn";
59
+ PdfBlendMode2[PdfBlendMode2["HardLight"] = 8] = "HardLight";
60
+ PdfBlendMode2[PdfBlendMode2["SoftLight"] = 9] = "SoftLight";
61
+ PdfBlendMode2[PdfBlendMode2["Difference"] = 10] = "Difference";
62
+ PdfBlendMode2[PdfBlendMode2["Exclusion"] = 11] = "Exclusion";
63
+ PdfBlendMode2[PdfBlendMode2["Hue"] = 12] = "Hue";
64
+ PdfBlendMode2[PdfBlendMode2["Saturation"] = 13] = "Saturation";
65
+ PdfBlendMode2[PdfBlendMode2["Color"] = 14] = "Color";
66
+ PdfBlendMode2[PdfBlendMode2["Luminosity"] = 15] = "Luminosity";
67
+ return PdfBlendMode2;
68
+ })(PdfBlendMode || {});
69
+ const PdfAnnotationFlagName = Object.freeze({
70
+ [
71
+ 1
72
+ /* INVISIBLE */
73
+ ]: "invisible",
74
+ [
75
+ 2
76
+ /* HIDDEN */
77
+ ]: "hidden",
78
+ [
79
+ 4
80
+ /* PRINT */
81
+ ]: "print",
82
+ [
83
+ 8
84
+ /* NO_ZOOM */
85
+ ]: "noZoom",
86
+ [
87
+ 16
88
+ /* NO_ROTATE */
89
+ ]: "noRotate",
90
+ [
91
+ 32
92
+ /* NO_VIEW */
93
+ ]: "noView",
94
+ [
95
+ 64
96
+ /* READ_ONLY */
97
+ ]: "readOnly",
98
+ [
99
+ 128
100
+ /* LOCKED */
101
+ ]: "locked",
102
+ [
103
+ 256
104
+ /* TOGGLE_NOVIEW */
105
+ ]: "toggleNoView"
106
+ });
107
+ Object.entries(
108
+ PdfAnnotationFlagName
109
+ ).reduce(
110
+ (acc, [bit, name]) => {
111
+ acc[name] = Number(bit);
112
+ return acc;
113
+ },
114
+ {}
115
+ );
116
+ var PdfPermissionFlag = /* @__PURE__ */ ((PdfPermissionFlag2) => {
117
+ PdfPermissionFlag2[PdfPermissionFlag2["Print"] = 4] = "Print";
118
+ PdfPermissionFlag2[PdfPermissionFlag2["ModifyContents"] = 8] = "ModifyContents";
119
+ PdfPermissionFlag2[PdfPermissionFlag2["CopyContents"] = 16] = "CopyContents";
120
+ PdfPermissionFlag2[PdfPermissionFlag2["ModifyAnnotations"] = 32] = "ModifyAnnotations";
121
+ PdfPermissionFlag2[PdfPermissionFlag2["FillForms"] = 256] = "FillForms";
122
+ PdfPermissionFlag2[PdfPermissionFlag2["ExtractForAccessibility"] = 512] = "ExtractForAccessibility";
123
+ PdfPermissionFlag2[PdfPermissionFlag2["AssembleDocument"] = 1024] = "AssembleDocument";
124
+ PdfPermissionFlag2[PdfPermissionFlag2["PrintHighQuality"] = 2048] = "PrintHighQuality";
125
+ PdfPermissionFlag2[PdfPermissionFlag2["AllowAll"] = 3900] = "AllowAll";
126
+ return PdfPermissionFlag2;
127
+ })(PdfPermissionFlag || {});
128
+ class PermissionDeniedError extends Error {
129
+ constructor(requiredFlags, currentPermissions) {
130
+ const flagNames = requiredFlags.map((f) => PdfPermissionFlag[f]).join(", ");
131
+ super(`Permission denied. Required: ${flagNames}`);
132
+ this.requiredFlags = requiredFlags;
133
+ this.currentPermissions = currentPermissions;
134
+ this.name = "PermissionDeniedError";
135
+ }
136
+ }
137
+ const TEXT_ALIGNMENT_INFOS = Object.freeze([
138
+ { id: PdfTextAlignment.Left, label: "Left", css: "left" },
139
+ { id: PdfTextAlignment.Center, label: "Center", css: "center" },
140
+ { id: PdfTextAlignment.Right, label: "Right", css: "right" }
141
+ ]);
142
+ TEXT_ALIGNMENT_INFOS.reduce(
143
+ (m, info) => {
144
+ m[info.id] = info;
145
+ return m;
146
+ },
147
+ {}
148
+ );
149
+ TEXT_ALIGNMENT_INFOS.reduce(
150
+ (m, info) => {
151
+ m[info.css] = info.id;
152
+ return m;
153
+ },
154
+ {}
155
+ );
156
+ TEXT_ALIGNMENT_INFOS.map((info) => ({
157
+ value: info.id,
158
+ label: info.label
159
+ }));
160
+ var PdfStandardFontFamily = /* @__PURE__ */ ((PdfStandardFontFamily2) => {
161
+ PdfStandardFontFamily2["Courier"] = "Courier";
162
+ PdfStandardFontFamily2["Helvetica"] = "Helvetica";
163
+ PdfStandardFontFamily2["Times"] = "Times";
164
+ PdfStandardFontFamily2["Symbol"] = "Symbol";
165
+ PdfStandardFontFamily2["ZapfDingbats"] = "ZapfDingbats";
166
+ PdfStandardFontFamily2["Unknown"] = "Unknown";
167
+ return PdfStandardFontFamily2;
168
+ })(PdfStandardFontFamily || {});
169
+ PdfStandardFont.Helvetica;
170
+ const HELVETICA_DESC = {
171
+ id: PdfStandardFont.Helvetica,
172
+ family: "Helvetica",
173
+ bold: false,
174
+ italic: false,
175
+ label: "Helvetica",
176
+ css: "Helvetica, Arial, sans-serif"
177
+ };
178
+ const STANDARD_FONT_DESCRIPTORS = Object.freeze([
179
+ {
180
+ id: PdfStandardFont.Courier,
181
+ family: "Courier",
182
+ bold: false,
183
+ italic: false,
184
+ label: "Courier",
185
+ css: "Courier, monospace"
186
+ },
187
+ {
188
+ id: PdfStandardFont.Courier_Bold,
189
+ family: "Courier",
190
+ bold: true,
191
+ italic: false,
192
+ label: "Courier Bold",
193
+ css: "Courier, monospace"
194
+ },
195
+ {
196
+ id: PdfStandardFont.Courier_BoldOblique,
197
+ family: "Courier",
198
+ bold: true,
199
+ italic: true,
200
+ label: "Courier Bold Oblique",
201
+ css: "Courier, monospace"
202
+ },
203
+ {
204
+ id: PdfStandardFont.Courier_Oblique,
205
+ family: "Courier",
206
+ bold: false,
207
+ italic: true,
208
+ label: "Courier Oblique",
209
+ css: "Courier, monospace"
210
+ },
211
+ HELVETICA_DESC,
212
+ {
213
+ id: PdfStandardFont.Helvetica_Bold,
214
+ family: "Helvetica",
215
+ bold: true,
216
+ italic: false,
217
+ label: "Helvetica Bold",
218
+ css: "Helvetica, Arial, sans-serif"
219
+ },
220
+ {
221
+ id: PdfStandardFont.Helvetica_BoldOblique,
222
+ family: "Helvetica",
223
+ bold: true,
224
+ italic: true,
225
+ label: "Helvetica Bold Oblique",
226
+ css: "Helvetica, Arial, sans-serif"
227
+ },
228
+ {
229
+ id: PdfStandardFont.Helvetica_Oblique,
230
+ family: "Helvetica",
231
+ bold: false,
232
+ italic: true,
233
+ label: "Helvetica Oblique",
234
+ css: "Helvetica, Arial, sans-serif"
235
+ },
236
+ {
237
+ id: PdfStandardFont.Times_Roman,
238
+ family: "Times",
239
+ bold: false,
240
+ italic: false,
241
+ label: "Times Roman",
242
+ css: '"Times New Roman", Times, serif'
243
+ },
244
+ {
245
+ id: PdfStandardFont.Times_Bold,
246
+ family: "Times",
247
+ bold: true,
248
+ italic: false,
249
+ label: "Times Bold",
250
+ css: '"Times New Roman", Times, serif'
251
+ },
252
+ {
253
+ id: PdfStandardFont.Times_BoldItalic,
254
+ family: "Times",
255
+ bold: true,
256
+ italic: true,
257
+ label: "Times Bold Italic",
258
+ css: '"Times New Roman", Times, serif'
259
+ },
260
+ {
261
+ id: PdfStandardFont.Times_Italic,
262
+ family: "Times",
263
+ bold: false,
264
+ italic: true,
265
+ label: "Times Italic",
266
+ css: '"Times New Roman", Times, serif'
267
+ },
268
+ {
269
+ id: PdfStandardFont.Symbol,
270
+ family: "Symbol",
271
+ bold: false,
272
+ italic: false,
273
+ label: "Symbol",
274
+ css: "Symbol, serif"
275
+ },
276
+ {
277
+ id: PdfStandardFont.ZapfDingbats,
278
+ family: "ZapfDingbats",
279
+ bold: false,
280
+ italic: false,
281
+ label: "Zapf Dingbats",
282
+ css: "ZapfDingbats, serif"
283
+ }
284
+ ]);
285
+ STANDARD_FONT_DESCRIPTORS.reduce((m, d) => (m[d.id] = d, m), {});
286
+ const familyStyleToId = /* @__PURE__ */ new Map();
287
+ for (const d of STANDARD_FONT_DESCRIPTORS) {
288
+ familyStyleToId.set(`${d.family}_${d.bold}_${d.italic}`, d.id);
289
+ }
290
+ Object.values(PdfStandardFontFamily).filter(
291
+ (f) => f !== "Unknown"
292
+ /* Unknown */
293
+ ).map((family) => ({ value: family, label: family }));
294
+ [
295
+ ...new Set(STANDARD_FONT_DESCRIPTORS.map((d) => d.family))
296
+ ];
297
+ const BLEND_MODE_INFOS = Object.freeze([
298
+ { id: PdfBlendMode.Normal, label: "Normal", css: "normal" },
299
+ { id: PdfBlendMode.Multiply, label: "Multiply", css: "multiply" },
300
+ { id: PdfBlendMode.Screen, label: "Screen", css: "screen" },
301
+ { id: PdfBlendMode.Overlay, label: "Overlay", css: "overlay" },
302
+ { id: PdfBlendMode.Darken, label: "Darken", css: "darken" },
303
+ { id: PdfBlendMode.Lighten, label: "Lighten", css: "lighten" },
304
+ { id: PdfBlendMode.ColorDodge, label: "Color Dodge", css: "color-dodge" },
305
+ { id: PdfBlendMode.ColorBurn, label: "Color Burn", css: "color-burn" },
306
+ { id: PdfBlendMode.HardLight, label: "Hard Light", css: "hard-light" },
307
+ { id: PdfBlendMode.SoftLight, label: "Soft Light", css: "soft-light" },
308
+ { id: PdfBlendMode.Difference, label: "Difference", css: "difference" },
309
+ { id: PdfBlendMode.Exclusion, label: "Exclusion", css: "exclusion" },
310
+ { id: PdfBlendMode.Hue, label: "Hue", css: "hue" },
311
+ { id: PdfBlendMode.Saturation, label: "Saturation", css: "saturation" },
312
+ { id: PdfBlendMode.Color, label: "Color", css: "color" },
313
+ { id: PdfBlendMode.Luminosity, label: "Luminosity", css: "luminosity" }
314
+ ]);
315
+ BLEND_MODE_INFOS.reduce(
316
+ (m, info) => {
317
+ m[info.id] = info;
318
+ return m;
319
+ },
320
+ {}
321
+ );
322
+ BLEND_MODE_INFOS.reduce(
323
+ (m, info) => {
324
+ m[info.css] = info.id;
325
+ return m;
326
+ },
327
+ {}
328
+ );
329
+ BLEND_MODE_INFOS.map((info) => ({
330
+ value: info.id,
331
+ label: info.label
332
+ }));
333
+ BLEND_MODE_INFOS.map((info) => info.id);
334
+ const START_LOADING_DOCUMENT = "START_LOADING_DOCUMENT";
335
+ const SET_DOCUMENT_LOADED = "SET_DOCUMENT_LOADED";
336
+ const CLOSE_DOCUMENT = "CLOSE_DOCUMENT";
337
+ const SET_SCALE = "SET_SCALE";
338
+ const SET_ROTATION = "SET_ROTATION";
339
+ ({
340
+ print: PdfPermissionFlag.Print,
341
+ modifyContents: PdfPermissionFlag.ModifyContents,
342
+ copyContents: PdfPermissionFlag.CopyContents,
343
+ modifyAnnotations: PdfPermissionFlag.ModifyAnnotations,
344
+ fillForms: PdfPermissionFlag.FillForms,
345
+ extractForAccessibility: PdfPermissionFlag.ExtractForAccessibility,
346
+ assembleDocument: PdfPermissionFlag.AssembleDocument,
347
+ printHighQuality: PdfPermissionFlag.PrintHighQuality
348
+ });
349
+ const ALL_PERMISSION_FLAGS = [
350
+ PdfPermissionFlag.Print,
351
+ PdfPermissionFlag.ModifyContents,
352
+ PdfPermissionFlag.CopyContents,
353
+ PdfPermissionFlag.ModifyAnnotations,
354
+ PdfPermissionFlag.FillForms,
355
+ PdfPermissionFlag.ExtractForAccessibility,
356
+ PdfPermissionFlag.AssembleDocument,
357
+ PdfPermissionFlag.PrintHighQuality
358
+ ];
359
+ const PERMISSION_FLAG_TO_NAME = {
360
+ [PdfPermissionFlag.Print]: "print",
361
+ [PdfPermissionFlag.ModifyContents]: "modifyContents",
362
+ [PdfPermissionFlag.CopyContents]: "copyContents",
363
+ [PdfPermissionFlag.ModifyAnnotations]: "modifyAnnotations",
364
+ [PdfPermissionFlag.FillForms]: "fillForms",
365
+ [PdfPermissionFlag.ExtractForAccessibility]: "extractForAccessibility",
366
+ [PdfPermissionFlag.AssembleDocument]: "assembleDocument",
367
+ [PdfPermissionFlag.PrintHighQuality]: "printHighQuality"
368
+ };
369
+ function getPermissionOverride(overrides, flag) {
370
+ if (!overrides) return void 0;
371
+ if (flag in overrides) {
372
+ return overrides[flag];
373
+ }
374
+ const name = PERMISSION_FLAG_TO_NAME[flag];
375
+ if (name && name in overrides) {
376
+ return overrides[name];
377
+ }
378
+ return void 0;
379
+ }
380
+ function getEffectivePermission(state, documentId, flag) {
381
+ var _a;
382
+ const docState = state.documents[documentId];
383
+ const docConfig = docState == null ? void 0 : docState.permissions;
384
+ const globalConfig = state.globalPermissions;
385
+ const pdfPermissions = ((_a = docState == null ? void 0 : docState.document) == null ? void 0 : _a.permissions) ?? PdfPermissionFlag.AllowAll;
386
+ const docOverride = getPermissionOverride(docConfig == null ? void 0 : docConfig.overrides, flag);
387
+ if (docOverride !== void 0) {
388
+ return docOverride;
389
+ }
390
+ const globalOverride = getPermissionOverride(globalConfig == null ? void 0 : globalConfig.overrides, flag);
391
+ if (globalOverride !== void 0) {
392
+ return globalOverride;
393
+ }
394
+ const enforce = (docConfig == null ? void 0 : docConfig.enforceDocumentPermissions) ?? (globalConfig == null ? void 0 : globalConfig.enforceDocumentPermissions) ?? true;
395
+ if (!enforce) return true;
396
+ return (pdfPermissions & flag) !== 0;
397
+ }
398
+ function getEffectivePermissions(state, documentId) {
399
+ return ALL_PERMISSION_FLAGS.reduce((acc, flag) => {
400
+ return getEffectivePermission(state, documentId, flag) ? acc | flag : acc;
401
+ }, 0);
402
+ }
403
+ class BasePlugin {
404
+ constructor(id, registry) {
405
+ this.id = id;
406
+ this.registry = registry;
407
+ this.cooldownActions = {};
408
+ this.debouncedTimeouts = {};
409
+ this.unsubscribeFromState = null;
410
+ this.unsubscribeFromCoreStore = null;
411
+ this.unsubscribeFromStartLoadingDocument = null;
412
+ this.unsubscribeFromSetDocumentLoaded = null;
413
+ this.unsubscribeFromCloseDocument = null;
414
+ this.unsubscribeFromSetScale = null;
415
+ this.unsubscribeFromSetRotation = null;
416
+ if (id !== this.constructor.id) {
417
+ throw new Error(
418
+ `Plugin ID mismatch: ${id} !== ${this.constructor.id}`
419
+ );
420
+ }
421
+ this.engine = this.registry.getEngine();
422
+ this.logger = this.registry.getLogger();
423
+ this.coreStore = this.registry.getStore();
424
+ this.pluginStore = this.coreStore.getPluginStore(this.id);
425
+ this.unsubscribeFromState = this.pluginStore.subscribeToState((action, newState, oldState) => {
426
+ this.onStoreUpdated(oldState, newState);
427
+ });
428
+ this.unsubscribeFromCoreStore = this.coreStore.subscribe((action, newState, oldState) => {
429
+ this.onCoreStoreUpdated(oldState, newState);
430
+ if (newState.core.activeDocumentId !== oldState.core.activeDocumentId) {
431
+ this.onActiveDocumentChanged(
432
+ oldState.core.activeDocumentId,
433
+ newState.core.activeDocumentId
434
+ );
435
+ }
436
+ });
437
+ this.unsubscribeFromStartLoadingDocument = this.coreStore.onAction(
438
+ START_LOADING_DOCUMENT,
439
+ (action) => {
440
+ this.onDocumentLoadingStarted(action.payload.documentId);
441
+ }
442
+ );
443
+ this.unsubscribeFromSetDocumentLoaded = this.coreStore.onAction(
444
+ SET_DOCUMENT_LOADED,
445
+ (action) => {
446
+ this.onDocumentLoaded(action.payload.documentId);
447
+ }
448
+ );
449
+ this.unsubscribeFromCloseDocument = this.coreStore.onAction(CLOSE_DOCUMENT, (action) => {
450
+ this.onDocumentClosed(action.payload.documentId);
451
+ });
452
+ this.unsubscribeFromSetScale = this.coreStore.onAction(SET_SCALE, (action, state) => {
453
+ const targetId = action.payload.documentId ?? state.core.activeDocumentId;
454
+ if (targetId) {
455
+ this.onScaleChanged(targetId, action.payload.scale);
456
+ }
457
+ });
458
+ this.unsubscribeFromSetRotation = this.coreStore.onAction(SET_ROTATION, (action, state) => {
459
+ const targetId = action.payload.documentId ?? state.core.activeDocumentId;
460
+ if (targetId) {
461
+ this.onRotationChanged(targetId, action.payload.rotation);
462
+ }
463
+ });
464
+ this.readyPromise = new Promise((resolve) => {
465
+ this.readyResolve = resolve;
466
+ });
467
+ this.readyResolve();
468
+ }
469
+ provides() {
470
+ if (!this._capability) {
471
+ const cap = this.buildCapability();
472
+ this._capability = Object.freeze(cap);
473
+ }
474
+ return this._capability;
475
+ }
476
+ /**
477
+ * Get a copy of the current state
478
+ */
479
+ get state() {
480
+ return this.pluginStore.getState();
481
+ }
482
+ /**
483
+ * Get a copy of the current core state
484
+ */
485
+ get coreState() {
486
+ return this.coreStore.getState();
487
+ }
488
+ /**
489
+ * @deprecated use `this.state` Get a copy of the current state
490
+ */
491
+ getState() {
492
+ return this.pluginStore.getState();
493
+ }
494
+ /**
495
+ * @deprecated use `this.coreState` Get a copy of the current core state
496
+ */
497
+ getCoreState() {
498
+ return this.coreStore.getState();
499
+ }
500
+ /**
501
+ * Core Dispatch
502
+ */
503
+ dispatchCoreAction(action) {
504
+ return this.coreStore.dispatchToCore(action);
505
+ }
506
+ /**
507
+ * Dispatch an action to all plugins
508
+ */
509
+ dispatchToAllPlugins(action) {
510
+ return this.coreStore.dispatch(action);
511
+ }
512
+ /**
513
+ * Dispatch an action
514
+ */
515
+ dispatch(action) {
516
+ return this.pluginStore.dispatch(action);
517
+ }
518
+ /**
519
+ * Dispatch an action with a cooldown to prevent rapid repeated calls
520
+ * This executes immediately if cooldown has expired, then blocks subsequent calls
521
+ * @param action The action to dispatch
522
+ * @param cooldownTime Time in ms for cooldown (default: 100ms)
523
+ * @returns boolean indicating whether the action was dispatched or blocked
524
+ */
525
+ cooldownDispatch(action, cooldownTime = 100) {
526
+ const now = Date.now();
527
+ const lastActionTime = this.cooldownActions[action.type] || 0;
528
+ if (now - lastActionTime >= cooldownTime) {
529
+ this.cooldownActions[action.type] = now;
530
+ this.dispatch(action);
531
+ return true;
532
+ }
533
+ return false;
534
+ }
535
+ /**
536
+ * Dispatch an action with true debouncing - waits for the delay after the last call
537
+ * Each new call resets the timer. Action only executes after no calls for the specified time.
538
+ * @param action The action to dispatch
539
+ * @param debounceTime Time in ms to wait after the last call
540
+ */
541
+ debouncedDispatch(action, debounceTime = 100) {
542
+ const actionKey = action.type;
543
+ if (this.debouncedTimeouts[actionKey]) {
544
+ clearTimeout(this.debouncedTimeouts[actionKey]);
545
+ }
546
+ this.debouncedTimeouts[actionKey] = setTimeout(() => {
547
+ this.dispatch(action);
548
+ delete this.debouncedTimeouts[actionKey];
549
+ }, debounceTime);
550
+ }
551
+ /**
552
+ * Cancel a pending debounced action
553
+ * @param actionType The action type to cancel
554
+ */
555
+ cancelDebouncedDispatch(actionType) {
556
+ if (this.debouncedTimeouts[actionType]) {
557
+ clearTimeout(this.debouncedTimeouts[actionType]);
558
+ delete this.debouncedTimeouts[actionType];
559
+ }
560
+ }
561
+ /**
562
+ * Subscribe to state changes
563
+ */
564
+ subscribe(listener) {
565
+ return this.pluginStore.subscribeToState(listener);
566
+ }
567
+ /**
568
+ * Subscribe to core store changes
569
+ */
570
+ subscribeToCoreStore(listener) {
571
+ return this.coreStore.subscribe(listener);
572
+ }
573
+ /**
574
+ * Called when the plugin store state is updated
575
+ * @param oldState Previous state
576
+ * @param newState New state
577
+ */
578
+ onStoreUpdated(oldState, newState) {
579
+ }
580
+ /**
581
+ * Called when the core store state is updated
582
+ * @param oldState Previous state
583
+ * @param newState New state
584
+ */
585
+ onCoreStoreUpdated(oldState, newState) {
586
+ }
587
+ /**
588
+ * Called when a document is opened
589
+ * Override to initialize per-document state
590
+ * @param documentId The ID of the document that was opened
591
+ */
592
+ onDocumentLoadingStarted(documentId) {
593
+ }
594
+ /**
595
+ * Called when a document is loaded
596
+ * @param documentId The ID of the document that is loaded
597
+ */
598
+ onDocumentLoaded(documentId) {
599
+ }
600
+ /**
601
+ * Called when a document is closed
602
+ * Override to cleanup per-document state
603
+ * @param documentId The ID of the document that was closed
604
+ */
605
+ onDocumentClosed(documentId) {
606
+ }
607
+ /**
608
+ * Called when the active document changes
609
+ * @param previousId The ID of the previous active document
610
+ * @param currentId The ID of the new active document
611
+ */
612
+ onActiveDocumentChanged(previousId, currentId) {
613
+ }
614
+ onScaleChanged(documentId, scale) {
615
+ }
616
+ onRotationChanged(documentId, rotation) {
617
+ }
618
+ /**
619
+ * Cleanup method to be called when plugin is being destroyed
620
+ */
621
+ destroy() {
622
+ Object.values(this.debouncedTimeouts).forEach((timeout) => {
623
+ clearTimeout(timeout);
624
+ });
625
+ this.debouncedTimeouts = {};
626
+ if (this.unsubscribeFromState) {
627
+ this.unsubscribeFromState();
628
+ this.unsubscribeFromState = null;
629
+ }
630
+ if (this.unsubscribeFromCoreStore) {
631
+ this.unsubscribeFromCoreStore();
632
+ this.unsubscribeFromCoreStore = null;
633
+ }
634
+ if (this.unsubscribeFromStartLoadingDocument) {
635
+ this.unsubscribeFromStartLoadingDocument();
636
+ this.unsubscribeFromStartLoadingDocument = null;
637
+ }
638
+ if (this.unsubscribeFromSetDocumentLoaded) {
639
+ this.unsubscribeFromSetDocumentLoaded();
640
+ this.unsubscribeFromSetDocumentLoaded = null;
641
+ }
642
+ if (this.unsubscribeFromCloseDocument) {
643
+ this.unsubscribeFromCloseDocument();
644
+ this.unsubscribeFromCloseDocument = null;
645
+ }
646
+ if (this.unsubscribeFromSetScale) {
647
+ this.unsubscribeFromSetScale();
648
+ this.unsubscribeFromSetScale = null;
649
+ }
650
+ if (this.unsubscribeFromSetRotation) {
651
+ this.unsubscribeFromSetRotation();
652
+ this.unsubscribeFromSetRotation = null;
653
+ }
654
+ }
655
+ /**
656
+ * Returns a promise that resolves when the plugin is ready
657
+ */
658
+ ready() {
659
+ return this.readyPromise;
660
+ }
661
+ /**
662
+ * Mark the plugin as ready
663
+ */
664
+ markReady() {
665
+ this.readyResolve();
666
+ }
667
+ /**
668
+ * Reset the ready state (useful for plugins that need to reinitialize)
669
+ */
670
+ resetReady() {
671
+ this.readyPromise = new Promise((resolve) => {
672
+ this.readyResolve = resolve;
673
+ });
674
+ }
675
+ /**
676
+ * Get the active document ID
677
+ * @throws Error if no active document exists
678
+ */
679
+ getActiveDocumentId() {
680
+ const id = this.coreState.core.activeDocumentId;
681
+ if (!id) {
682
+ throw new Error("No active document");
683
+ }
684
+ return id;
685
+ }
686
+ /**
687
+ * Get the active document ID or null if none exists
688
+ */
689
+ getActiveDocumentIdOrNull() {
690
+ return this.coreState.core.activeDocumentId;
691
+ }
692
+ /**
693
+ * Get core document state for a specific document
694
+ * @param documentId Document ID (optional, defaults to active document)
695
+ * @returns Document state or null if not found
696
+ */
697
+ getCoreDocument(documentId) {
698
+ const id = documentId ?? this.getActiveDocumentIdOrNull();
699
+ if (!id) return null;
700
+ return this.coreState.core.documents[id] ?? null;
701
+ }
702
+ /**
703
+ * Get core document state for a specific document
704
+ * @param documentId Document ID (optional, defaults to active document)
705
+ * @throws Error if document not found
706
+ */
707
+ getCoreDocumentOrThrow(documentId) {
708
+ const doc = this.getCoreDocument(documentId);
709
+ if (!doc) {
710
+ throw new Error(`Document not found: ${documentId ?? "active"}`);
711
+ }
712
+ return doc;
713
+ }
714
+ // ─────────────────────────────────────────────────────────
715
+ // Permission Helpers
716
+ // ─────────────────────────────────────────────────────────
717
+ /**
718
+ * Get the effective permission flags for a document.
719
+ * Applies layered resolution: per-document override → global override → PDF permission.
720
+ * Returns AllowAll if document not found.
721
+ * @param documentId Document ID (optional, defaults to active document)
722
+ */
723
+ getDocumentPermissions(documentId) {
724
+ const docId = documentId ?? this.coreState.core.activeDocumentId;
725
+ if (!docId) return PdfPermissionFlag.AllowAll;
726
+ return getEffectivePermissions(this.coreState.core, docId);
727
+ }
728
+ /**
729
+ * Check if a document has the required permissions (returns boolean).
730
+ * Applies layered resolution: per-document override → global override → PDF permission.
731
+ * Useful for conditional UI logic.
732
+ * @param documentId Document ID (optional, defaults to active document)
733
+ * @param flags Permission flags to check
734
+ */
735
+ checkPermission(documentId, ...flags) {
736
+ const docId = documentId ?? this.coreState.core.activeDocumentId;
737
+ if (!docId) return true;
738
+ return flags.every((flag) => getEffectivePermission(this.coreState.core, docId, flag));
739
+ }
740
+ /**
741
+ * Assert that a document has the required permissions.
742
+ * Applies layered resolution: per-document override → global override → PDF permission.
743
+ * Throws PermissionDeniedError if any flag is missing.
744
+ * @param documentId Document ID (optional, defaults to active document)
745
+ * @param flags Permission flags to require
746
+ */
747
+ requirePermission(documentId, ...flags) {
748
+ const docId = documentId ?? this.coreState.core.activeDocumentId;
749
+ if (!docId) return;
750
+ const missingFlags = [];
751
+ for (const flag of flags) {
752
+ if (!getEffectivePermission(this.coreState.core, docId, flag)) {
753
+ missingFlags.push(flag);
754
+ }
755
+ }
756
+ if (missingFlags.length > 0) {
757
+ const effectivePermissions = getEffectivePermissions(this.coreState.core, docId);
758
+ throw new PermissionDeniedError(missingFlags, effectivePermissions);
759
+ }
760
+ }
761
+ }
762
+ const _BookmarkPlugin = class _BookmarkPlugin extends BasePlugin {
763
+ constructor(id, registry) {
764
+ super(id, registry);
765
+ }
766
+ async initialize(_) {
767
+ }
768
+ // ─────────────────────────────────────────────────────────
769
+ // Capability
770
+ // ─────────────────────────────────────────────────────────
771
+ buildCapability() {
772
+ return {
773
+ // Active document operations
774
+ getBookmarks: () => this.getBookmarks(),
775
+ // Document-scoped operations
776
+ forDocument: (documentId) => this.createBookmarkScope(documentId)
777
+ };
778
+ }
779
+ // ─────────────────────────────────────────────────────────
780
+ // Document Scoping
781
+ // ─────────────────────────────────────────────────────────
782
+ createBookmarkScope(documentId) {
783
+ return {
784
+ getBookmarks: () => this.getBookmarks(documentId)
785
+ };
786
+ }
787
+ // ─────────────────────────────────────────────────────────
788
+ // Core Operations
789
+ // ─────────────────────────────────────────────────────────
790
+ getBookmarks(documentId) {
791
+ const id = documentId ?? this.getActiveDocumentId();
792
+ const coreDoc = this.coreState.core.documents[id];
793
+ if (!(coreDoc == null ? void 0 : coreDoc.document)) {
794
+ throw new Error(`Document ${id} not loaded`);
795
+ }
796
+ return this.engine.getBookmarks(coreDoc.document);
797
+ }
798
+ };
799
+ _BookmarkPlugin.id = "bookmark";
800
+ let BookmarkPlugin = _BookmarkPlugin;
801
+ const BookmarkPluginPackage = {
802
+ manifest,
803
+ create: (registry) => new BookmarkPlugin(BOOKMARK_PLUGIN_ID, registry),
804
+ reducer: () => {
805
+ },
806
+ initialState: {}
807
+ };
808
+ export {
809
+ BOOKMARK_PLUGIN_ID,
810
+ BookmarkPlugin,
811
+ BookmarkPluginPackage,
812
+ manifest
813
+ };
814
+ //# sourceMappingURL=index.js.map