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