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