@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,1310 @@
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 PdfSoftHyphenMarker = "­";
411
+ const PdfZeroWidthSpace = "​";
412
+ const PdfWordJoiner = "⁠";
413
+ const PdfBomOrZwnbsp = "\uFEFF";
414
+ const PdfNonCharacterFFFE = "￾";
415
+ const PdfNonCharacterFFFF = "￿";
416
+ const PdfUnwantedTextMarkers = Object.freeze([
417
+ PdfSoftHyphenMarker,
418
+ PdfZeroWidthSpace,
419
+ PdfWordJoiner,
420
+ PdfBomOrZwnbsp,
421
+ PdfNonCharacterFFFE,
422
+ PdfNonCharacterFFFF
423
+ ]);
424
+ new RegExp(`[${PdfUnwantedTextMarkers.join("")}]`, "g");
425
+ var PdfStandardFont = /* @__PURE__ */ ((PdfStandardFont2) => {
426
+ PdfStandardFont2[PdfStandardFont2["Unknown"] = -1] = "Unknown";
427
+ PdfStandardFont2[PdfStandardFont2["Courier"] = 0] = "Courier";
428
+ PdfStandardFont2[PdfStandardFont2["Courier_Bold"] = 1] = "Courier_Bold";
429
+ PdfStandardFont2[PdfStandardFont2["Courier_BoldOblique"] = 2] = "Courier_BoldOblique";
430
+ PdfStandardFont2[PdfStandardFont2["Courier_Oblique"] = 3] = "Courier_Oblique";
431
+ PdfStandardFont2[PdfStandardFont2["Helvetica"] = 4] = "Helvetica";
432
+ PdfStandardFont2[PdfStandardFont2["Helvetica_Bold"] = 5] = "Helvetica_Bold";
433
+ PdfStandardFont2[PdfStandardFont2["Helvetica_BoldOblique"] = 6] = "Helvetica_BoldOblique";
434
+ PdfStandardFont2[PdfStandardFont2["Helvetica_Oblique"] = 7] = "Helvetica_Oblique";
435
+ PdfStandardFont2[PdfStandardFont2["Times_Roman"] = 8] = "Times_Roman";
436
+ PdfStandardFont2[PdfStandardFont2["Times_Bold"] = 9] = "Times_Bold";
437
+ PdfStandardFont2[PdfStandardFont2["Times_BoldItalic"] = 10] = "Times_BoldItalic";
438
+ PdfStandardFont2[PdfStandardFont2["Times_Italic"] = 11] = "Times_Italic";
439
+ PdfStandardFont2[PdfStandardFont2["Symbol"] = 12] = "Symbol";
440
+ PdfStandardFont2[PdfStandardFont2["ZapfDingbats"] = 13] = "ZapfDingbats";
441
+ return PdfStandardFont2;
442
+ })(PdfStandardFont || {});
443
+ var PdfTextAlignment = /* @__PURE__ */ ((PdfTextAlignment2) => {
444
+ PdfTextAlignment2[PdfTextAlignment2["Left"] = 0] = "Left";
445
+ PdfTextAlignment2[PdfTextAlignment2["Center"] = 1] = "Center";
446
+ PdfTextAlignment2[PdfTextAlignment2["Right"] = 2] = "Right";
447
+ return PdfTextAlignment2;
448
+ })(PdfTextAlignment || {});
449
+ var PdfBlendMode = /* @__PURE__ */ ((PdfBlendMode2) => {
450
+ PdfBlendMode2[PdfBlendMode2["Normal"] = 0] = "Normal";
451
+ PdfBlendMode2[PdfBlendMode2["Multiply"] = 1] = "Multiply";
452
+ PdfBlendMode2[PdfBlendMode2["Screen"] = 2] = "Screen";
453
+ PdfBlendMode2[PdfBlendMode2["Overlay"] = 3] = "Overlay";
454
+ PdfBlendMode2[PdfBlendMode2["Darken"] = 4] = "Darken";
455
+ PdfBlendMode2[PdfBlendMode2["Lighten"] = 5] = "Lighten";
456
+ PdfBlendMode2[PdfBlendMode2["ColorDodge"] = 6] = "ColorDodge";
457
+ PdfBlendMode2[PdfBlendMode2["ColorBurn"] = 7] = "ColorBurn";
458
+ PdfBlendMode2[PdfBlendMode2["HardLight"] = 8] = "HardLight";
459
+ PdfBlendMode2[PdfBlendMode2["SoftLight"] = 9] = "SoftLight";
460
+ PdfBlendMode2[PdfBlendMode2["Difference"] = 10] = "Difference";
461
+ PdfBlendMode2[PdfBlendMode2["Exclusion"] = 11] = "Exclusion";
462
+ PdfBlendMode2[PdfBlendMode2["Hue"] = 12] = "Hue";
463
+ PdfBlendMode2[PdfBlendMode2["Saturation"] = 13] = "Saturation";
464
+ PdfBlendMode2[PdfBlendMode2["Color"] = 14] = "Color";
465
+ PdfBlendMode2[PdfBlendMode2["Luminosity"] = 15] = "Luminosity";
466
+ return PdfBlendMode2;
467
+ })(PdfBlendMode || {});
468
+ const PdfAnnotationFlagName = Object.freeze({
469
+ [
470
+ 1
471
+ /* INVISIBLE */
472
+ ]: "invisible",
473
+ [
474
+ 2
475
+ /* HIDDEN */
476
+ ]: "hidden",
477
+ [
478
+ 4
479
+ /* PRINT */
480
+ ]: "print",
481
+ [
482
+ 8
483
+ /* NO_ZOOM */
484
+ ]: "noZoom",
485
+ [
486
+ 16
487
+ /* NO_ROTATE */
488
+ ]: "noRotate",
489
+ [
490
+ 32
491
+ /* NO_VIEW */
492
+ ]: "noView",
493
+ [
494
+ 64
495
+ /* READ_ONLY */
496
+ ]: "readOnly",
497
+ [
498
+ 128
499
+ /* LOCKED */
500
+ ]: "locked",
501
+ [
502
+ 256
503
+ /* TOGGLE_NOVIEW */
504
+ ]: "toggleNoView"
505
+ });
506
+ Object.entries(
507
+ PdfAnnotationFlagName
508
+ ).reduce(
509
+ (acc, [bit, name]) => {
510
+ acc[name] = Number(bit);
511
+ return acc;
512
+ },
513
+ {}
514
+ );
515
+ var PdfPermissionFlag = /* @__PURE__ */ ((PdfPermissionFlag2) => {
516
+ PdfPermissionFlag2[PdfPermissionFlag2["Print"] = 4] = "Print";
517
+ PdfPermissionFlag2[PdfPermissionFlag2["ModifyContents"] = 8] = "ModifyContents";
518
+ PdfPermissionFlag2[PdfPermissionFlag2["CopyContents"] = 16] = "CopyContents";
519
+ PdfPermissionFlag2[PdfPermissionFlag2["ModifyAnnotations"] = 32] = "ModifyAnnotations";
520
+ PdfPermissionFlag2[PdfPermissionFlag2["FillForms"] = 256] = "FillForms";
521
+ PdfPermissionFlag2[PdfPermissionFlag2["ExtractForAccessibility"] = 512] = "ExtractForAccessibility";
522
+ PdfPermissionFlag2[PdfPermissionFlag2["AssembleDocument"] = 1024] = "AssembleDocument";
523
+ PdfPermissionFlag2[PdfPermissionFlag2["PrintHighQuality"] = 2048] = "PrintHighQuality";
524
+ PdfPermissionFlag2[PdfPermissionFlag2["AllowAll"] = 3900] = "AllowAll";
525
+ return PdfPermissionFlag2;
526
+ })(PdfPermissionFlag || {});
527
+ class PermissionDeniedError extends Error {
528
+ constructor(requiredFlags, currentPermissions) {
529
+ const flagNames = requiredFlags.map((f) => PdfPermissionFlag[f]).join(", ");
530
+ super(`Permission denied. Required: ${flagNames}`);
531
+ this.requiredFlags = requiredFlags;
532
+ this.currentPermissions = currentPermissions;
533
+ this.name = "PermissionDeniedError";
534
+ }
535
+ }
536
+ const TEXT_ALIGNMENT_INFOS = Object.freeze([
537
+ { id: PdfTextAlignment.Left, label: "Left", css: "left" },
538
+ { id: PdfTextAlignment.Center, label: "Center", css: "center" },
539
+ { id: PdfTextAlignment.Right, label: "Right", css: "right" }
540
+ ]);
541
+ TEXT_ALIGNMENT_INFOS.reduce(
542
+ (m, info) => {
543
+ m[info.id] = info;
544
+ return m;
545
+ },
546
+ {}
547
+ );
548
+ TEXT_ALIGNMENT_INFOS.reduce(
549
+ (m, info) => {
550
+ m[info.css] = info.id;
551
+ return m;
552
+ },
553
+ {}
554
+ );
555
+ TEXT_ALIGNMENT_INFOS.map((info) => ({
556
+ value: info.id,
557
+ label: info.label
558
+ }));
559
+ var PdfStandardFontFamily = /* @__PURE__ */ ((PdfStandardFontFamily2) => {
560
+ PdfStandardFontFamily2["Courier"] = "Courier";
561
+ PdfStandardFontFamily2["Helvetica"] = "Helvetica";
562
+ PdfStandardFontFamily2["Times"] = "Times";
563
+ PdfStandardFontFamily2["Symbol"] = "Symbol";
564
+ PdfStandardFontFamily2["ZapfDingbats"] = "ZapfDingbats";
565
+ PdfStandardFontFamily2["Unknown"] = "Unknown";
566
+ return PdfStandardFontFamily2;
567
+ })(PdfStandardFontFamily || {});
568
+ PdfStandardFont.Helvetica;
569
+ const HELVETICA_DESC = {
570
+ id: PdfStandardFont.Helvetica,
571
+ family: "Helvetica",
572
+ bold: false,
573
+ italic: false,
574
+ label: "Helvetica",
575
+ css: "Helvetica, Arial, sans-serif"
576
+ };
577
+ const STANDARD_FONT_DESCRIPTORS = Object.freeze([
578
+ {
579
+ id: PdfStandardFont.Courier,
580
+ family: "Courier",
581
+ bold: false,
582
+ italic: false,
583
+ label: "Courier",
584
+ css: "Courier, monospace"
585
+ },
586
+ {
587
+ id: PdfStandardFont.Courier_Bold,
588
+ family: "Courier",
589
+ bold: true,
590
+ italic: false,
591
+ label: "Courier Bold",
592
+ css: "Courier, monospace"
593
+ },
594
+ {
595
+ id: PdfStandardFont.Courier_BoldOblique,
596
+ family: "Courier",
597
+ bold: true,
598
+ italic: true,
599
+ label: "Courier Bold Oblique",
600
+ css: "Courier, monospace"
601
+ },
602
+ {
603
+ id: PdfStandardFont.Courier_Oblique,
604
+ family: "Courier",
605
+ bold: false,
606
+ italic: true,
607
+ label: "Courier Oblique",
608
+ css: "Courier, monospace"
609
+ },
610
+ HELVETICA_DESC,
611
+ {
612
+ id: PdfStandardFont.Helvetica_Bold,
613
+ family: "Helvetica",
614
+ bold: true,
615
+ italic: false,
616
+ label: "Helvetica Bold",
617
+ css: "Helvetica, Arial, sans-serif"
618
+ },
619
+ {
620
+ id: PdfStandardFont.Helvetica_BoldOblique,
621
+ family: "Helvetica",
622
+ bold: true,
623
+ italic: true,
624
+ label: "Helvetica Bold Oblique",
625
+ css: "Helvetica, Arial, sans-serif"
626
+ },
627
+ {
628
+ id: PdfStandardFont.Helvetica_Oblique,
629
+ family: "Helvetica",
630
+ bold: false,
631
+ italic: true,
632
+ label: "Helvetica Oblique",
633
+ css: "Helvetica, Arial, sans-serif"
634
+ },
635
+ {
636
+ id: PdfStandardFont.Times_Roman,
637
+ family: "Times",
638
+ bold: false,
639
+ italic: false,
640
+ label: "Times Roman",
641
+ css: '"Times New Roman", Times, serif'
642
+ },
643
+ {
644
+ id: PdfStandardFont.Times_Bold,
645
+ family: "Times",
646
+ bold: true,
647
+ italic: false,
648
+ label: "Times Bold",
649
+ css: '"Times New Roman", Times, serif'
650
+ },
651
+ {
652
+ id: PdfStandardFont.Times_BoldItalic,
653
+ family: "Times",
654
+ bold: true,
655
+ italic: true,
656
+ label: "Times Bold Italic",
657
+ css: '"Times New Roman", Times, serif'
658
+ },
659
+ {
660
+ id: PdfStandardFont.Times_Italic,
661
+ family: "Times",
662
+ bold: false,
663
+ italic: true,
664
+ label: "Times Italic",
665
+ css: '"Times New Roman", Times, serif'
666
+ },
667
+ {
668
+ id: PdfStandardFont.Symbol,
669
+ family: "Symbol",
670
+ bold: false,
671
+ italic: false,
672
+ label: "Symbol",
673
+ css: "Symbol, serif"
674
+ },
675
+ {
676
+ id: PdfStandardFont.ZapfDingbats,
677
+ family: "ZapfDingbats",
678
+ bold: false,
679
+ italic: false,
680
+ label: "Zapf Dingbats",
681
+ css: "ZapfDingbats, serif"
682
+ }
683
+ ]);
684
+ STANDARD_FONT_DESCRIPTORS.reduce((m, d) => (m[d.id] = d, m), {});
685
+ const familyStyleToId = /* @__PURE__ */ new Map();
686
+ for (const d of STANDARD_FONT_DESCRIPTORS) {
687
+ familyStyleToId.set(`${d.family}_${d.bold}_${d.italic}`, d.id);
688
+ }
689
+ Object.values(PdfStandardFontFamily).filter(
690
+ (f) => f !== "Unknown"
691
+ /* Unknown */
692
+ ).map((family) => ({ value: family, label: family }));
693
+ [
694
+ ...new Set(STANDARD_FONT_DESCRIPTORS.map((d) => d.family))
695
+ ];
696
+ const BLEND_MODE_INFOS = Object.freeze([
697
+ { id: PdfBlendMode.Normal, label: "Normal", css: "normal" },
698
+ { id: PdfBlendMode.Multiply, label: "Multiply", css: "multiply" },
699
+ { id: PdfBlendMode.Screen, label: "Screen", css: "screen" },
700
+ { id: PdfBlendMode.Overlay, label: "Overlay", css: "overlay" },
701
+ { id: PdfBlendMode.Darken, label: "Darken", css: "darken" },
702
+ { id: PdfBlendMode.Lighten, label: "Lighten", css: "lighten" },
703
+ { id: PdfBlendMode.ColorDodge, label: "Color Dodge", css: "color-dodge" },
704
+ { id: PdfBlendMode.ColorBurn, label: "Color Burn", css: "color-burn" },
705
+ { id: PdfBlendMode.HardLight, label: "Hard Light", css: "hard-light" },
706
+ { id: PdfBlendMode.SoftLight, label: "Soft Light", css: "soft-light" },
707
+ { id: PdfBlendMode.Difference, label: "Difference", css: "difference" },
708
+ { id: PdfBlendMode.Exclusion, label: "Exclusion", css: "exclusion" },
709
+ { id: PdfBlendMode.Hue, label: "Hue", css: "hue" },
710
+ { id: PdfBlendMode.Saturation, label: "Saturation", css: "saturation" },
711
+ { id: PdfBlendMode.Color, label: "Color", css: "color" },
712
+ { id: PdfBlendMode.Luminosity, label: "Luminosity", css: "luminosity" }
713
+ ]);
714
+ BLEND_MODE_INFOS.reduce(
715
+ (m, info) => {
716
+ m[info.id] = info;
717
+ return m;
718
+ },
719
+ {}
720
+ );
721
+ BLEND_MODE_INFOS.reduce(
722
+ (m, info) => {
723
+ m[info.css] = info.id;
724
+ return m;
725
+ },
726
+ {}
727
+ );
728
+ BLEND_MODE_INFOS.map((info) => ({
729
+ value: info.id,
730
+ label: info.label
731
+ }));
732
+ BLEND_MODE_INFOS.map((info) => info.id);
733
+ const START_LOADING_DOCUMENT = "START_LOADING_DOCUMENT";
734
+ const SET_DOCUMENT_LOADED = "SET_DOCUMENT_LOADED";
735
+ const CLOSE_DOCUMENT = "CLOSE_DOCUMENT";
736
+ const SET_SCALE = "SET_SCALE";
737
+ const SET_ROTATION = "SET_ROTATION";
738
+ ({
739
+ print: PdfPermissionFlag.Print,
740
+ modifyContents: PdfPermissionFlag.ModifyContents,
741
+ copyContents: PdfPermissionFlag.CopyContents,
742
+ modifyAnnotations: PdfPermissionFlag.ModifyAnnotations,
743
+ fillForms: PdfPermissionFlag.FillForms,
744
+ extractForAccessibility: PdfPermissionFlag.ExtractForAccessibility,
745
+ assembleDocument: PdfPermissionFlag.AssembleDocument,
746
+ printHighQuality: PdfPermissionFlag.PrintHighQuality
747
+ });
748
+ const ALL_PERMISSION_FLAGS = [
749
+ PdfPermissionFlag.Print,
750
+ PdfPermissionFlag.ModifyContents,
751
+ PdfPermissionFlag.CopyContents,
752
+ PdfPermissionFlag.ModifyAnnotations,
753
+ PdfPermissionFlag.FillForms,
754
+ PdfPermissionFlag.ExtractForAccessibility,
755
+ PdfPermissionFlag.AssembleDocument,
756
+ PdfPermissionFlag.PrintHighQuality
757
+ ];
758
+ const PERMISSION_FLAG_TO_NAME = {
759
+ [PdfPermissionFlag.Print]: "print",
760
+ [PdfPermissionFlag.ModifyContents]: "modifyContents",
761
+ [PdfPermissionFlag.CopyContents]: "copyContents",
762
+ [PdfPermissionFlag.ModifyAnnotations]: "modifyAnnotations",
763
+ [PdfPermissionFlag.FillForms]: "fillForms",
764
+ [PdfPermissionFlag.ExtractForAccessibility]: "extractForAccessibility",
765
+ [PdfPermissionFlag.AssembleDocument]: "assembleDocument",
766
+ [PdfPermissionFlag.PrintHighQuality]: "printHighQuality"
767
+ };
768
+ function getPermissionOverride(overrides, flag) {
769
+ if (!overrides) return void 0;
770
+ if (flag in overrides) {
771
+ return overrides[flag];
772
+ }
773
+ const name = PERMISSION_FLAG_TO_NAME[flag];
774
+ if (name && name in overrides) {
775
+ return overrides[name];
776
+ }
777
+ return void 0;
778
+ }
779
+ function getEffectivePermission(state, documentId, flag) {
780
+ var _a;
781
+ const docState = state.documents[documentId];
782
+ const docConfig = docState == null ? void 0 : docState.permissions;
783
+ const globalConfig = state.globalPermissions;
784
+ const pdfPermissions = ((_a = docState == null ? void 0 : docState.document) == null ? void 0 : _a.permissions) ?? PdfPermissionFlag.AllowAll;
785
+ const docOverride = getPermissionOverride(docConfig == null ? void 0 : docConfig.overrides, flag);
786
+ if (docOverride !== void 0) {
787
+ return docOverride;
788
+ }
789
+ const globalOverride = getPermissionOverride(globalConfig == null ? void 0 : globalConfig.overrides, flag);
790
+ if (globalOverride !== void 0) {
791
+ return globalOverride;
792
+ }
793
+ const enforce = (docConfig == null ? void 0 : docConfig.enforceDocumentPermissions) ?? (globalConfig == null ? void 0 : globalConfig.enforceDocumentPermissions) ?? true;
794
+ if (!enforce) return true;
795
+ return (pdfPermissions & flag) !== 0;
796
+ }
797
+ function getEffectivePermissions(state, documentId) {
798
+ return ALL_PERMISSION_FLAGS.reduce((acc, flag) => {
799
+ return getEffectivePermission(state, documentId, flag) ? acc | flag : acc;
800
+ }, 0);
801
+ }
802
+ class BasePlugin {
803
+ constructor(id, registry) {
804
+ this.id = id;
805
+ this.registry = registry;
806
+ this.cooldownActions = {};
807
+ this.debouncedTimeouts = {};
808
+ this.unsubscribeFromState = null;
809
+ this.unsubscribeFromCoreStore = null;
810
+ this.unsubscribeFromStartLoadingDocument = null;
811
+ this.unsubscribeFromSetDocumentLoaded = null;
812
+ this.unsubscribeFromCloseDocument = null;
813
+ this.unsubscribeFromSetScale = null;
814
+ this.unsubscribeFromSetRotation = null;
815
+ if (id !== this.constructor.id) {
816
+ throw new Error(
817
+ `Plugin ID mismatch: ${id} !== ${this.constructor.id}`
818
+ );
819
+ }
820
+ this.engine = this.registry.getEngine();
821
+ this.logger = this.registry.getLogger();
822
+ this.coreStore = this.registry.getStore();
823
+ this.pluginStore = this.coreStore.getPluginStore(this.id);
824
+ this.unsubscribeFromState = this.pluginStore.subscribeToState((action, newState, oldState) => {
825
+ this.onStoreUpdated(oldState, newState);
826
+ });
827
+ this.unsubscribeFromCoreStore = this.coreStore.subscribe((action, newState, oldState) => {
828
+ this.onCoreStoreUpdated(oldState, newState);
829
+ if (newState.core.activeDocumentId !== oldState.core.activeDocumentId) {
830
+ this.onActiveDocumentChanged(
831
+ oldState.core.activeDocumentId,
832
+ newState.core.activeDocumentId
833
+ );
834
+ }
835
+ });
836
+ this.unsubscribeFromStartLoadingDocument = this.coreStore.onAction(
837
+ START_LOADING_DOCUMENT,
838
+ (action) => {
839
+ this.onDocumentLoadingStarted(action.payload.documentId);
840
+ }
841
+ );
842
+ this.unsubscribeFromSetDocumentLoaded = this.coreStore.onAction(
843
+ SET_DOCUMENT_LOADED,
844
+ (action) => {
845
+ this.onDocumentLoaded(action.payload.documentId);
846
+ }
847
+ );
848
+ this.unsubscribeFromCloseDocument = this.coreStore.onAction(CLOSE_DOCUMENT, (action) => {
849
+ this.onDocumentClosed(action.payload.documentId);
850
+ });
851
+ this.unsubscribeFromSetScale = this.coreStore.onAction(SET_SCALE, (action, state) => {
852
+ const targetId = action.payload.documentId ?? state.core.activeDocumentId;
853
+ if (targetId) {
854
+ this.onScaleChanged(targetId, action.payload.scale);
855
+ }
856
+ });
857
+ this.unsubscribeFromSetRotation = this.coreStore.onAction(SET_ROTATION, (action, state) => {
858
+ const targetId = action.payload.documentId ?? state.core.activeDocumentId;
859
+ if (targetId) {
860
+ this.onRotationChanged(targetId, action.payload.rotation);
861
+ }
862
+ });
863
+ this.readyPromise = new Promise((resolve) => {
864
+ this.readyResolve = resolve;
865
+ });
866
+ this.readyResolve();
867
+ }
868
+ provides() {
869
+ if (!this._capability) {
870
+ const cap = this.buildCapability();
871
+ this._capability = Object.freeze(cap);
872
+ }
873
+ return this._capability;
874
+ }
875
+ /**
876
+ * Get a copy of the current state
877
+ */
878
+ get state() {
879
+ return this.pluginStore.getState();
880
+ }
881
+ /**
882
+ * Get a copy of the current core state
883
+ */
884
+ get coreState() {
885
+ return this.coreStore.getState();
886
+ }
887
+ /**
888
+ * @deprecated use `this.state` Get a copy of the current state
889
+ */
890
+ getState() {
891
+ return this.pluginStore.getState();
892
+ }
893
+ /**
894
+ * @deprecated use `this.coreState` Get a copy of the current core state
895
+ */
896
+ getCoreState() {
897
+ return this.coreStore.getState();
898
+ }
899
+ /**
900
+ * Core Dispatch
901
+ */
902
+ dispatchCoreAction(action) {
903
+ return this.coreStore.dispatchToCore(action);
904
+ }
905
+ /**
906
+ * Dispatch an action to all plugins
907
+ */
908
+ dispatchToAllPlugins(action) {
909
+ return this.coreStore.dispatch(action);
910
+ }
911
+ /**
912
+ * Dispatch an action
913
+ */
914
+ dispatch(action) {
915
+ return this.pluginStore.dispatch(action);
916
+ }
917
+ /**
918
+ * Dispatch an action with a cooldown to prevent rapid repeated calls
919
+ * This executes immediately if cooldown has expired, then blocks subsequent calls
920
+ * @param action The action to dispatch
921
+ * @param cooldownTime Time in ms for cooldown (default: 100ms)
922
+ * @returns boolean indicating whether the action was dispatched or blocked
923
+ */
924
+ cooldownDispatch(action, cooldownTime = 100) {
925
+ const now = Date.now();
926
+ const lastActionTime = this.cooldownActions[action.type] || 0;
927
+ if (now - lastActionTime >= cooldownTime) {
928
+ this.cooldownActions[action.type] = now;
929
+ this.dispatch(action);
930
+ return true;
931
+ }
932
+ return false;
933
+ }
934
+ /**
935
+ * Dispatch an action with true debouncing - waits for the delay after the last call
936
+ * Each new call resets the timer. Action only executes after no calls for the specified time.
937
+ * @param action The action to dispatch
938
+ * @param debounceTime Time in ms to wait after the last call
939
+ */
940
+ debouncedDispatch(action, debounceTime = 100) {
941
+ const actionKey = action.type;
942
+ if (this.debouncedTimeouts[actionKey]) {
943
+ clearTimeout(this.debouncedTimeouts[actionKey]);
944
+ }
945
+ this.debouncedTimeouts[actionKey] = setTimeout(() => {
946
+ this.dispatch(action);
947
+ delete this.debouncedTimeouts[actionKey];
948
+ }, debounceTime);
949
+ }
950
+ /**
951
+ * Cancel a pending debounced action
952
+ * @param actionType The action type to cancel
953
+ */
954
+ cancelDebouncedDispatch(actionType) {
955
+ if (this.debouncedTimeouts[actionType]) {
956
+ clearTimeout(this.debouncedTimeouts[actionType]);
957
+ delete this.debouncedTimeouts[actionType];
958
+ }
959
+ }
960
+ /**
961
+ * Subscribe to state changes
962
+ */
963
+ subscribe(listener) {
964
+ return this.pluginStore.subscribeToState(listener);
965
+ }
966
+ /**
967
+ * Subscribe to core store changes
968
+ */
969
+ subscribeToCoreStore(listener) {
970
+ return this.coreStore.subscribe(listener);
971
+ }
972
+ /**
973
+ * Called when the plugin store state is updated
974
+ * @param oldState Previous state
975
+ * @param newState New state
976
+ */
977
+ onStoreUpdated(oldState, newState) {
978
+ }
979
+ /**
980
+ * Called when the core store state is updated
981
+ * @param oldState Previous state
982
+ * @param newState New state
983
+ */
984
+ onCoreStoreUpdated(oldState, newState) {
985
+ }
986
+ /**
987
+ * Called when a document is opened
988
+ * Override to initialize per-document state
989
+ * @param documentId The ID of the document that was opened
990
+ */
991
+ onDocumentLoadingStarted(documentId) {
992
+ }
993
+ /**
994
+ * Called when a document is loaded
995
+ * @param documentId The ID of the document that is loaded
996
+ */
997
+ onDocumentLoaded(documentId) {
998
+ }
999
+ /**
1000
+ * Called when a document is closed
1001
+ * Override to cleanup per-document state
1002
+ * @param documentId The ID of the document that was closed
1003
+ */
1004
+ onDocumentClosed(documentId) {
1005
+ }
1006
+ /**
1007
+ * Called when the active document changes
1008
+ * @param previousId The ID of the previous active document
1009
+ * @param currentId The ID of the new active document
1010
+ */
1011
+ onActiveDocumentChanged(previousId, currentId) {
1012
+ }
1013
+ onScaleChanged(documentId, scale) {
1014
+ }
1015
+ onRotationChanged(documentId, rotation) {
1016
+ }
1017
+ /**
1018
+ * Cleanup method to be called when plugin is being destroyed
1019
+ */
1020
+ destroy() {
1021
+ Object.values(this.debouncedTimeouts).forEach((timeout) => {
1022
+ clearTimeout(timeout);
1023
+ });
1024
+ this.debouncedTimeouts = {};
1025
+ if (this.unsubscribeFromState) {
1026
+ this.unsubscribeFromState();
1027
+ this.unsubscribeFromState = null;
1028
+ }
1029
+ if (this.unsubscribeFromCoreStore) {
1030
+ this.unsubscribeFromCoreStore();
1031
+ this.unsubscribeFromCoreStore = null;
1032
+ }
1033
+ if (this.unsubscribeFromStartLoadingDocument) {
1034
+ this.unsubscribeFromStartLoadingDocument();
1035
+ this.unsubscribeFromStartLoadingDocument = null;
1036
+ }
1037
+ if (this.unsubscribeFromSetDocumentLoaded) {
1038
+ this.unsubscribeFromSetDocumentLoaded();
1039
+ this.unsubscribeFromSetDocumentLoaded = null;
1040
+ }
1041
+ if (this.unsubscribeFromCloseDocument) {
1042
+ this.unsubscribeFromCloseDocument();
1043
+ this.unsubscribeFromCloseDocument = null;
1044
+ }
1045
+ if (this.unsubscribeFromSetScale) {
1046
+ this.unsubscribeFromSetScale();
1047
+ this.unsubscribeFromSetScale = null;
1048
+ }
1049
+ if (this.unsubscribeFromSetRotation) {
1050
+ this.unsubscribeFromSetRotation();
1051
+ this.unsubscribeFromSetRotation = null;
1052
+ }
1053
+ }
1054
+ /**
1055
+ * Returns a promise that resolves when the plugin is ready
1056
+ */
1057
+ ready() {
1058
+ return this.readyPromise;
1059
+ }
1060
+ /**
1061
+ * Mark the plugin as ready
1062
+ */
1063
+ markReady() {
1064
+ this.readyResolve();
1065
+ }
1066
+ /**
1067
+ * Reset the ready state (useful for plugins that need to reinitialize)
1068
+ */
1069
+ resetReady() {
1070
+ this.readyPromise = new Promise((resolve) => {
1071
+ this.readyResolve = resolve;
1072
+ });
1073
+ }
1074
+ /**
1075
+ * Get the active document ID
1076
+ * @throws Error if no active document exists
1077
+ */
1078
+ getActiveDocumentId() {
1079
+ const id = this.coreState.core.activeDocumentId;
1080
+ if (!id) {
1081
+ throw new Error("No active document");
1082
+ }
1083
+ return id;
1084
+ }
1085
+ /**
1086
+ * Get the active document ID or null if none exists
1087
+ */
1088
+ getActiveDocumentIdOrNull() {
1089
+ return this.coreState.core.activeDocumentId;
1090
+ }
1091
+ /**
1092
+ * Get core document state for a specific document
1093
+ * @param documentId Document ID (optional, defaults to active document)
1094
+ * @returns Document state or null if not found
1095
+ */
1096
+ getCoreDocument(documentId) {
1097
+ const id = documentId ?? this.getActiveDocumentIdOrNull();
1098
+ if (!id) return null;
1099
+ return this.coreState.core.documents[id] ?? null;
1100
+ }
1101
+ /**
1102
+ * Get core document state for a specific document
1103
+ * @param documentId Document ID (optional, defaults to active document)
1104
+ * @throws Error if document not found
1105
+ */
1106
+ getCoreDocumentOrThrow(documentId) {
1107
+ const doc = this.getCoreDocument(documentId);
1108
+ if (!doc) {
1109
+ throw new Error(`Document not found: ${documentId ?? "active"}`);
1110
+ }
1111
+ return doc;
1112
+ }
1113
+ // ─────────────────────────────────────────────────────────
1114
+ // Permission Helpers
1115
+ // ─────────────────────────────────────────────────────────
1116
+ /**
1117
+ * Get the effective permission flags for a document.
1118
+ * Applies layered resolution: per-document override → global override → PDF permission.
1119
+ * Returns AllowAll if document not found.
1120
+ * @param documentId Document ID (optional, defaults to active document)
1121
+ */
1122
+ getDocumentPermissions(documentId) {
1123
+ const docId = documentId ?? this.coreState.core.activeDocumentId;
1124
+ if (!docId) return PdfPermissionFlag.AllowAll;
1125
+ return getEffectivePermissions(this.coreState.core, docId);
1126
+ }
1127
+ /**
1128
+ * Check if a document has the required permissions (returns boolean).
1129
+ * Applies layered resolution: per-document override → global override → PDF permission.
1130
+ * Useful for conditional UI logic.
1131
+ * @param documentId Document ID (optional, defaults to active document)
1132
+ * @param flags Permission flags to check
1133
+ */
1134
+ checkPermission(documentId, ...flags) {
1135
+ const docId = documentId ?? this.coreState.core.activeDocumentId;
1136
+ if (!docId) return true;
1137
+ return flags.every((flag) => getEffectivePermission(this.coreState.core, docId, flag));
1138
+ }
1139
+ /**
1140
+ * Assert that a document has the required permissions.
1141
+ * Applies layered resolution: per-document override → global override → PDF permission.
1142
+ * Throws PermissionDeniedError if any flag is missing.
1143
+ * @param documentId Document ID (optional, defaults to active document)
1144
+ * @param flags Permission flags to require
1145
+ */
1146
+ requirePermission(documentId, ...flags) {
1147
+ const docId = documentId ?? this.coreState.core.activeDocumentId;
1148
+ if (!docId) return;
1149
+ const missingFlags = [];
1150
+ for (const flag of flags) {
1151
+ if (!getEffectivePermission(this.coreState.core, docId, flag)) {
1152
+ missingFlags.push(flag);
1153
+ }
1154
+ }
1155
+ if (missingFlags.length > 0) {
1156
+ const effectivePermissions = getEffectivePermissions(this.coreState.core, docId);
1157
+ throw new PermissionDeniedError(missingFlags, effectivePermissions);
1158
+ }
1159
+ }
1160
+ }
1161
+ const SET_BACKEND = "AI_MANAGER/SET_BACKEND";
1162
+ const SET_MODEL_LOADED = "AI_MANAGER/SET_MODEL_LOADED";
1163
+ const SET_MODEL_UNLOADED = "AI_MANAGER/SET_MODEL_UNLOADED";
1164
+ const SET_MODEL_LOADING = "AI_MANAGER/SET_MODEL_LOADING";
1165
+ const SET_MODEL_LOADING_DONE = "AI_MANAGER/SET_MODEL_LOADING_DONE";
1166
+ function setBackend(backend) {
1167
+ return { type: SET_BACKEND, payload: backend };
1168
+ }
1169
+ function setModelLoaded(modelId) {
1170
+ return { type: SET_MODEL_LOADED, payload: modelId };
1171
+ }
1172
+ function setModelUnloaded(modelId) {
1173
+ return { type: SET_MODEL_UNLOADED, payload: modelId };
1174
+ }
1175
+ function setModelLoading(modelId) {
1176
+ return { type: SET_MODEL_LOADING, payload: modelId };
1177
+ }
1178
+ function setModelLoadingDone(modelId) {
1179
+ return { type: SET_MODEL_LOADING_DONE, payload: modelId };
1180
+ }
1181
+ const _AiManagerPlugin = class _AiManagerPlugin extends BasePlugin {
1182
+ constructor(id, registry, config) {
1183
+ super(id, registry);
1184
+ this.config = config;
1185
+ }
1186
+ async initialize(config) {
1187
+ this.runtime = config.runtime;
1188
+ if (!this.runtime) {
1189
+ throw new Error(
1190
+ "[AiManagerPlugin] A runtime instance is required. Pass it via config: createPluginRegistration(AiManagerPluginPackage, { runtime: aiRuntime })"
1191
+ );
1192
+ }
1193
+ }
1194
+ buildCapability() {
1195
+ return {
1196
+ run: (pipeline, input) => {
1197
+ const task = this.runtime.run(pipeline, input);
1198
+ if (!this.runtime.isModelLoaded(pipeline.modelId)) {
1199
+ this.dispatch(setModelLoading(pipeline.modelId));
1200
+ task.wait(
1201
+ () => {
1202
+ this.dispatch(setModelLoaded(pipeline.modelId));
1203
+ this.dispatch(setBackend(this.runtime.getBackend()));
1204
+ },
1205
+ () => {
1206
+ this.dispatch(setModelLoadingDone(pipeline.modelId));
1207
+ }
1208
+ );
1209
+ }
1210
+ return task;
1211
+ },
1212
+ loadModel: (modelId) => {
1213
+ this.dispatch(setModelLoading(modelId));
1214
+ const task = this.runtime.loadModel(modelId);
1215
+ task.wait(
1216
+ () => {
1217
+ this.dispatch(setModelLoaded(modelId));
1218
+ this.dispatch(setBackend(this.runtime.getBackend()));
1219
+ },
1220
+ () => {
1221
+ this.dispatch(setModelLoadingDone(modelId));
1222
+ }
1223
+ );
1224
+ return task;
1225
+ },
1226
+ unloadModel: (modelId) => {
1227
+ this.runtime.unloadModel(modelId);
1228
+ this.dispatch(setModelUnloaded(modelId));
1229
+ },
1230
+ isModelLoaded: (modelId) => {
1231
+ return this.runtime.isModelLoaded(modelId);
1232
+ },
1233
+ getBackend: () => {
1234
+ return this.runtime.getBackend();
1235
+ },
1236
+ getRuntime: () => {
1237
+ return this.runtime;
1238
+ }
1239
+ };
1240
+ }
1241
+ async destroy() {
1242
+ await this.runtime.destroy();
1243
+ }
1244
+ };
1245
+ _AiManagerPlugin.id = "ai-manager";
1246
+ let AiManagerPlugin = _AiManagerPlugin;
1247
+ const AI_MANAGER_PLUGIN_ID = "ai-manager";
1248
+ const manifest = {
1249
+ id: AI_MANAGER_PLUGIN_ID,
1250
+ name: "AI Manager Plugin",
1251
+ version: "1.0.0",
1252
+ provides: ["ai-manager"],
1253
+ requires: [],
1254
+ optional: [],
1255
+ defaultConfig: {
1256
+ // runtime must be provided by the user
1257
+ runtime: null
1258
+ }
1259
+ };
1260
+ const initialState = {
1261
+ backend: null,
1262
+ loadedModels: [],
1263
+ loadingModels: []
1264
+ };
1265
+ const reducer = (state = initialState, action) => {
1266
+ switch (action.type) {
1267
+ case SET_BACKEND:
1268
+ return { ...state, backend: action.payload };
1269
+ case SET_MODEL_LOADING:
1270
+ return {
1271
+ ...state,
1272
+ loadingModels: state.loadingModels.includes(action.payload) ? state.loadingModels : [...state.loadingModels, action.payload]
1273
+ };
1274
+ case SET_MODEL_LOADING_DONE:
1275
+ return {
1276
+ ...state,
1277
+ loadingModels: state.loadingModels.filter((id) => id !== action.payload)
1278
+ };
1279
+ case SET_MODEL_LOADED:
1280
+ return {
1281
+ ...state,
1282
+ loadedModels: state.loadedModels.includes(action.payload) ? state.loadedModels : [...state.loadedModels, action.payload],
1283
+ loadingModels: state.loadingModels.filter((id) => id !== action.payload)
1284
+ };
1285
+ case SET_MODEL_UNLOADED:
1286
+ return {
1287
+ ...state,
1288
+ loadedModels: state.loadedModels.filter((id) => id !== action.payload)
1289
+ };
1290
+ default:
1291
+ return state;
1292
+ }
1293
+ };
1294
+ const AiManagerPluginPackage = {
1295
+ manifest,
1296
+ create: (registry, config) => new AiManagerPlugin(AI_MANAGER_PLUGIN_ID, registry, config),
1297
+ reducer,
1298
+ initialState
1299
+ };
1300
+ const useAiManagerPlugin = () => usePlugin(AiManagerPlugin.id);
1301
+ const useAiManagerCapability = () => useCapability(AiManagerPlugin.id);
1302
+ export {
1303
+ AI_MANAGER_PLUGIN_ID,
1304
+ AiManagerPlugin,
1305
+ AiManagerPluginPackage,
1306
+ manifest,
1307
+ useAiManagerCapability,
1308
+ useAiManagerPlugin
1309
+ };
1310
+ //# sourceMappingURL=index.js.map