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