@embedpdf/core 1.0.10 → 1.0.12

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 (74) hide show
  1. package/dist/index.cjs +2 -1335
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.d.ts +1 -585
  4. package/dist/index.js +55 -84
  5. package/dist/index.js.map +1 -1
  6. package/dist/lib/base/base-plugin.d.ts +98 -0
  7. package/dist/lib/index.d.ts +14 -0
  8. package/dist/lib/registry/plugin-registry.d.ts +100 -0
  9. package/dist/lib/store/actions.d.ts +39 -0
  10. package/dist/lib/store/index.d.ts +6 -0
  11. package/dist/lib/store/initial-state.d.ts +11 -0
  12. package/dist/lib/store/plugin-store.d.ts +48 -0
  13. package/dist/lib/store/reducer.d.ts +4 -0
  14. package/dist/lib/store/selectors.d.ts +3 -0
  15. package/dist/lib/store/store.d.ts +105 -0
  16. package/dist/lib/store/types.d.ts +28 -0
  17. package/dist/lib/types/errors.d.ts +21 -0
  18. package/dist/lib/types/plugin.d.ts +49 -0
  19. package/dist/lib/utils/dependency-resolver.d.ts +6 -0
  20. package/dist/lib/utils/event-control.d.ts +23 -0
  21. package/dist/lib/utils/eventing.d.ts +19 -0
  22. package/dist/lib/utils/math.d.ts +22 -0
  23. package/dist/lib/utils/plugin-helpers.d.ts +6 -0
  24. package/dist/lib/utils/typed-object.d.ts +12 -0
  25. package/dist/preact/adapter.d.ts +4 -0
  26. package/dist/preact/index.cjs +2 -188
  27. package/dist/preact/index.cjs.map +1 -1
  28. package/dist/preact/index.d.ts +1 -71
  29. package/dist/preact/index.js +11 -27
  30. package/dist/preact/index.js.map +1 -1
  31. package/dist/react/adapter.d.ts +2 -0
  32. package/dist/react/index.cjs +2 -188
  33. package/dist/react/index.cjs.map +1 -1
  34. package/dist/react/index.d.ts +1 -70
  35. package/dist/react/index.js +11 -28
  36. package/dist/react/index.js.map +1 -1
  37. package/dist/shared-preact/components/embed-pdf.d.ts +12 -0
  38. package/dist/shared-preact/components/index.d.ts +1 -0
  39. package/dist/shared-preact/context.d.ts +7 -0
  40. package/dist/shared-preact/hooks/index.d.ts +5 -0
  41. package/dist/shared-preact/hooks/use-capability.d.ts +16 -0
  42. package/dist/shared-preact/hooks/use-core-state.d.ts +6 -0
  43. package/dist/shared-preact/hooks/use-plugin.d.ts +16 -0
  44. package/dist/shared-preact/hooks/use-registry.d.ts +6 -0
  45. package/dist/shared-preact/hooks/use-store-state.d.ts +6 -0
  46. package/dist/shared-preact/index.d.ts +3 -0
  47. package/dist/shared-react/components/embed-pdf.d.ts +12 -0
  48. package/dist/shared-react/components/index.d.ts +1 -0
  49. package/dist/shared-react/context.d.ts +7 -0
  50. package/dist/shared-react/hooks/index.d.ts +5 -0
  51. package/dist/shared-react/hooks/use-capability.d.ts +16 -0
  52. package/dist/shared-react/hooks/use-core-state.d.ts +6 -0
  53. package/dist/shared-react/hooks/use-plugin.d.ts +16 -0
  54. package/dist/shared-react/hooks/use-registry.d.ts +6 -0
  55. package/dist/shared-react/hooks/use-store-state.d.ts +6 -0
  56. package/dist/shared-react/index.d.ts +3 -0
  57. package/dist/vue/components/embed-pdf.vue.d.ts +23 -0
  58. package/dist/vue/components/index.d.ts +1 -0
  59. package/dist/vue/composables/index.d.ts +5 -0
  60. package/dist/vue/composables/use-capability.d.ts +15 -0
  61. package/dist/vue/composables/use-core-state.d.ts +2 -0
  62. package/dist/vue/composables/use-plugin.d.ts +8 -0
  63. package/dist/vue/composables/use-registry.d.ts +1 -0
  64. package/dist/vue/composables/use-store-state.d.ts +10 -0
  65. package/dist/vue/context.d.ts +8 -0
  66. package/dist/vue/index.cjs +2 -0
  67. package/dist/vue/index.cjs.map +1 -0
  68. package/dist/vue/index.d.ts +2 -0
  69. package/dist/vue/index.js +115 -0
  70. package/dist/vue/index.js.map +1 -0
  71. package/package.json +20 -12
  72. package/dist/index.d.cts +0 -585
  73. package/dist/preact/index.d.cts +0 -71
  74. package/dist/react/index.d.cts +0 -70
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- // src/lib/utils/dependency-resolver.ts
2
- var DependencyResolver = class {
1
+ import { Rotation, transformSize } from "@embedpdf/models";
2
+ class DependencyResolver {
3
3
  constructor() {
4
4
  this.dependencyGraph = /* @__PURE__ */ new Map();
5
5
  }
@@ -56,54 +56,50 @@ var DependencyResolver = class {
56
56
  }
57
57
  return result;
58
58
  }
59
- };
60
-
61
- // src/lib/types/errors.ts
62
- var PluginRegistrationError = class extends Error {
59
+ }
60
+ class PluginRegistrationError extends Error {
63
61
  constructor(message) {
64
62
  super(message);
65
63
  this.name = "PluginRegistrationError";
66
64
  }
67
- };
68
- var PluginNotFoundError = class extends Error {
65
+ }
66
+ class PluginNotFoundError extends Error {
69
67
  constructor(message) {
70
68
  super(message);
71
69
  this.name = "PluginNotFoundError";
72
70
  }
73
- };
74
- var CircularDependencyError = class extends Error {
71
+ }
72
+ class CircularDependencyError extends Error {
75
73
  constructor(message) {
76
74
  super(message);
77
75
  this.name = "CircularDependencyError";
78
76
  }
79
- };
80
- var CapabilityNotFoundError = class extends Error {
77
+ }
78
+ class CapabilityNotFoundError extends Error {
81
79
  constructor(message) {
82
80
  super(message);
83
81
  this.name = "CapabilityNotFoundError";
84
82
  }
85
- };
86
- var CapabilityConflictError = class extends Error {
83
+ }
84
+ class CapabilityConflictError extends Error {
87
85
  constructor(message) {
88
86
  super(message);
89
87
  this.name = "CapabilityConflictError";
90
88
  }
91
- };
92
- var PluginInitializationError = class extends Error {
89
+ }
90
+ class PluginInitializationError extends Error {
93
91
  constructor(message) {
94
92
  super(message);
95
93
  this.name = "PluginInitializationError";
96
94
  }
97
- };
98
- var PluginConfigurationError = class extends Error {
95
+ }
96
+ class PluginConfigurationError extends Error {
99
97
  constructor(message) {
100
98
  super(message);
101
99
  this.name = "PluginConfigurationError";
102
100
  }
103
- };
104
-
105
- // src/lib/store/plugin-store.ts
106
- var PluginStore = class {
101
+ }
102
+ class PluginStore {
107
103
  /**
108
104
  * Initializes the PluginStore with the main store and plugin ID.
109
105
  * @param store The main store instance.
@@ -164,16 +160,14 @@ var PluginStore = class {
164
160
  );
165
161
  });
166
162
  }
167
- };
168
-
169
- // src/lib/store/actions.ts
170
- var LOAD_DOCUMENT = "LOAD_DOCUMENT";
171
- var SET_DOCUMENT = "SET_DOCUMENT";
172
- var SET_DOCUMENT_ERROR = "SET_DOCUMENT_ERROR";
173
- var SET_SCALE = "SET_SCALE";
174
- var SET_ROTATION = "SET_ROTATION";
175
- var SET_PAGES = "SET_PAGES";
176
- var CORE_ACTION_TYPES = [
163
+ }
164
+ const LOAD_DOCUMENT = "LOAD_DOCUMENT";
165
+ const SET_DOCUMENT = "SET_DOCUMENT";
166
+ const SET_DOCUMENT_ERROR = "SET_DOCUMENT_ERROR";
167
+ const SET_SCALE = "SET_SCALE";
168
+ const SET_ROTATION = "SET_ROTATION";
169
+ const SET_PAGES = "SET_PAGES";
170
+ const CORE_ACTION_TYPES = [
177
171
  LOAD_DOCUMENT,
178
172
  SET_DOCUMENT,
179
173
  SET_DOCUMENT_ERROR,
@@ -181,27 +175,25 @@ var CORE_ACTION_TYPES = [
181
175
  SET_ROTATION,
182
176
  SET_PAGES
183
177
  ];
184
- var loadDocument = () => ({ type: LOAD_DOCUMENT });
185
- var setDocument = (document) => ({
178
+ const loadDocument = () => ({ type: LOAD_DOCUMENT });
179
+ const setDocument = (document) => ({
186
180
  type: SET_DOCUMENT,
187
181
  payload: document
188
182
  });
189
- var setDocumentError = (error) => ({
183
+ const setDocumentError = (error) => ({
190
184
  type: SET_DOCUMENT_ERROR,
191
185
  payload: error
192
186
  });
193
- var setScale = (scale) => ({ type: SET_SCALE, payload: scale });
194
- var setRotation = (rotation) => ({
187
+ const setScale = (scale) => ({ type: SET_SCALE, payload: scale });
188
+ const setRotation = (rotation) => ({
195
189
  type: SET_ROTATION,
196
190
  payload: rotation
197
191
  });
198
- var setPages = (pages) => ({
192
+ const setPages = (pages) => ({
199
193
  type: SET_PAGES,
200
194
  payload: pages
201
195
  });
202
-
203
- // src/lib/store/store.ts
204
- var Store = class {
196
+ class Store {
205
197
  /**
206
198
  * Initializes the store with the provided core state.
207
199
  * @param reducer The core reducer function
@@ -384,31 +376,26 @@ var Store = class {
384
376
  * Destroy the store: drop every listener and plugin reducer
385
377
  */
386
378
  destroy() {
379
+ var _a, _b;
387
380
  this.listeners.length = 0;
388
381
  for (const id in this.pluginListeners) {
389
- this.pluginListeners[id]?.splice?.(0);
382
+ (_b = (_a = this.pluginListeners[id]) == null ? void 0 : _a.splice) == null ? void 0 : _b.call(_a, 0);
390
383
  }
391
384
  this.pluginListeners = {};
392
385
  this.pluginReducers = {};
393
386
  this.state.plugins = {};
394
387
  this.state.core = { ...this.initialCoreState };
395
388
  }
396
- };
397
-
398
- // src/lib/store/initial-state.ts
399
- import { Rotation } from "@embedpdf/models";
400
- var initialCoreState = (config) => ({
401
- scale: config?.scale ?? 1,
402
- rotation: config?.rotation ?? Rotation.Degree0,
389
+ }
390
+ const initialCoreState = (config) => ({
391
+ scale: (config == null ? void 0 : config.scale) ?? 1,
392
+ rotation: (config == null ? void 0 : config.rotation) ?? Rotation.Degree0,
403
393
  document: null,
404
394
  pages: [],
405
395
  loading: false,
406
396
  error: null
407
397
  });
408
-
409
- // src/lib/store/selectors.ts
410
- import { transformSize } from "@embedpdf/models";
411
- var getPagesWithRotatedSize = (state) => {
398
+ const getPagesWithRotatedSize = (state) => {
412
399
  return state.pages.map(
413
400
  (page) => page.map((p) => ({
414
401
  ...p,
@@ -416,9 +403,7 @@ var getPagesWithRotatedSize = (state) => {
416
403
  }))
417
404
  );
418
405
  };
419
-
420
- // src/lib/store/reducer.ts
421
- var coreReducer = (state, action) => {
406
+ const coreReducer = (state, action) => {
422
407
  switch (action.type) {
423
408
  case LOAD_DOCUMENT:
424
409
  return {
@@ -459,14 +444,11 @@ var coreReducer = (state, action) => {
459
444
  return state;
460
445
  }
461
446
  };
462
-
463
- // src/lib/registry/plugin-registry.ts
464
- var PluginRegistry = class {
447
+ class PluginRegistry {
465
448
  constructor(engine, config) {
466
449
  this.plugins = /* @__PURE__ */ new Map();
467
450
  this.manifests = /* @__PURE__ */ new Map();
468
451
  this.capabilities = /* @__PURE__ */ new Map();
469
- // capability -> pluginId
470
452
  this.status = /* @__PURE__ */ new Map();
471
453
  this.configurations = /* @__PURE__ */ new Map();
472
454
  this.engineInitialized = false;
@@ -564,6 +546,7 @@ var PluginRegistry = class {
564
546
  return this.initPromise;
565
547
  }
566
548
  this.initPromise = (async () => {
549
+ var _a;
567
550
  if (this.initialized) {
568
551
  throw new PluginRegistrationError("Registry is already initialized");
569
552
  }
@@ -599,10 +582,10 @@ var PluginRegistry = class {
599
582
  this.resolver = new DependencyResolver();
600
583
  }
601
584
  for (const plugin of this.plugins.values()) {
602
- await plugin.postInitialize?.().catch((e) => {
585
+ await ((_a = plugin.postInitialize) == null ? void 0 : _a.call(plugin).catch((e) => {
603
586
  console.error(`Error in postInitialize for plugin ${plugin.id}`, e);
604
587
  this.status.set(plugin.id, "error");
605
- });
588
+ }));
606
589
  }
607
590
  this.initialized = true;
608
591
  } catch (err) {
@@ -835,6 +818,7 @@ var PluginRegistry = class {
835
818
  * DESTROY EVERYTHING – waits for any ongoing initialise(), once *
836
819
  */
837
820
  async destroy() {
821
+ var _a;
838
822
  if (this.destroyed) throw new PluginRegistrationError("Registry has already been destroyed");
839
823
  this.destroyed = true;
840
824
  try {
@@ -842,7 +826,7 @@ var PluginRegistry = class {
842
826
  } catch {
843
827
  }
844
828
  for (const plugin of Array.from(this.plugins.values()).reverse()) {
845
- await plugin.destroy?.();
829
+ await ((_a = plugin.destroy) == null ? void 0 : _a.call(plugin));
846
830
  }
847
831
  this.store.destroy();
848
832
  this.plugins.clear();
@@ -852,22 +836,17 @@ var PluginRegistry = class {
852
836
  this.pendingRegistrations.length = 0;
853
837
  this.processingRegistrations.length = 0;
854
838
  }
855
- };
856
-
857
- // src/lib/utils/plugin-helpers.ts
839
+ }
858
840
  function createPluginRegistration(pluginPackage, config) {
859
841
  return {
860
842
  package: pluginPackage,
861
843
  config
862
844
  };
863
845
  }
864
-
865
- // src/lib/base/base-plugin.ts
866
- var BasePlugin = class {
846
+ class BasePlugin {
867
847
  constructor(id, registry) {
868
848
  this.id = id;
869
849
  this.registry = registry;
870
- // Track debounced actions
871
850
  this.debouncedActions = {};
872
851
  this.unsubscribeFromState = null;
873
852
  this.unsubscribeFromCoreStore = null;
@@ -1013,10 +992,8 @@ var BasePlugin = class {
1013
992
  this.readyResolve = resolve;
1014
993
  });
1015
994
  }
1016
- };
1017
-
1018
- // src/lib/utils/event-control.ts
1019
- var EventControl = class {
995
+ }
996
+ class EventControl {
1020
997
  constructor(handler, options) {
1021
998
  this.handler = handler;
1022
999
  this.options = options;
@@ -1065,9 +1042,7 @@ var EventControl = class {
1065
1042
  window.clearTimeout(this.timeoutId);
1066
1043
  }
1067
1044
  }
1068
- };
1069
-
1070
- // src/lib/utils/math.ts
1045
+ }
1071
1046
  function clamp(value, min, max) {
1072
1047
  return value < min ? min : value > max ? max : value;
1073
1048
  }
@@ -1103,8 +1078,8 @@ function arePropsEqual(a, b, visited) {
1103
1078
  function getPairId(a, b) {
1104
1079
  return `${objectId(a)}__${objectId(b)}`;
1105
1080
  }
1106
- var objectIdCounter = 0;
1107
- var objectIds = /* @__PURE__ */ new WeakMap();
1081
+ let objectIdCounter = 0;
1082
+ const objectIds = /* @__PURE__ */ new WeakMap();
1108
1083
  function objectId(obj) {
1109
1084
  if (!objectIds.has(obj)) {
1110
1085
  objectIds.set(obj, ++objectIdCounter);
@@ -1143,8 +1118,6 @@ function objectsEqual(a, b, visited) {
1143
1118
  }
1144
1119
  return true;
1145
1120
  }
1146
-
1147
- // src/lib/utils/eventing.ts
1148
1121
  function createEmitter() {
1149
1122
  const listeners = /* @__PURE__ */ new Set();
1150
1123
  const on = (l) => {
@@ -1231,8 +1204,6 @@ function createBehaviorEmitter(initial, equality = arePropsEqual) {
1231
1204
  }
1232
1205
  };
1233
1206
  }
1234
-
1235
- // src/lib/utils/typed-object.ts
1236
1207
  function enumEntries(record) {
1237
1208
  return Object.entries(record).map(([k, v]) => {
1238
1209
  const maybeNum = Number(k);
@@ -1274,4 +1245,4 @@ export {
1274
1245
  setRotation,
1275
1246
  setScale
1276
1247
  };
1277
- //# sourceMappingURL=index.js.map
1248
+ //# sourceMappingURL=index.js.map