@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.
- package/dist/index.cjs +2 -1335
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -585
- package/dist/index.js +55 -84
- package/dist/index.js.map +1 -1
- package/dist/lib/base/base-plugin.d.ts +98 -0
- package/dist/lib/index.d.ts +14 -0
- package/dist/lib/registry/plugin-registry.d.ts +100 -0
- package/dist/lib/store/actions.d.ts +39 -0
- package/dist/lib/store/index.d.ts +6 -0
- package/dist/lib/store/initial-state.d.ts +11 -0
- package/dist/lib/store/plugin-store.d.ts +48 -0
- package/dist/lib/store/reducer.d.ts +4 -0
- package/dist/lib/store/selectors.d.ts +3 -0
- package/dist/lib/store/store.d.ts +105 -0
- package/dist/lib/store/types.d.ts +28 -0
- package/dist/lib/types/errors.d.ts +21 -0
- package/dist/lib/types/plugin.d.ts +49 -0
- package/dist/lib/utils/dependency-resolver.d.ts +6 -0
- package/dist/lib/utils/event-control.d.ts +23 -0
- package/dist/lib/utils/eventing.d.ts +19 -0
- package/dist/lib/utils/math.d.ts +22 -0
- package/dist/lib/utils/plugin-helpers.d.ts +6 -0
- package/dist/lib/utils/typed-object.d.ts +12 -0
- package/dist/preact/adapter.d.ts +4 -0
- package/dist/preact/index.cjs +2 -188
- package/dist/preact/index.cjs.map +1 -1
- package/dist/preact/index.d.ts +1 -71
- package/dist/preact/index.js +11 -27
- package/dist/preact/index.js.map +1 -1
- package/dist/react/adapter.d.ts +2 -0
- package/dist/react/index.cjs +2 -188
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.ts +1 -70
- package/dist/react/index.js +11 -28
- package/dist/react/index.js.map +1 -1
- package/dist/shared-preact/components/embed-pdf.d.ts +12 -0
- package/dist/shared-preact/components/index.d.ts +1 -0
- package/dist/shared-preact/context.d.ts +7 -0
- package/dist/shared-preact/hooks/index.d.ts +5 -0
- package/dist/shared-preact/hooks/use-capability.d.ts +16 -0
- package/dist/shared-preact/hooks/use-core-state.d.ts +6 -0
- package/dist/shared-preact/hooks/use-plugin.d.ts +16 -0
- package/dist/shared-preact/hooks/use-registry.d.ts +6 -0
- package/dist/shared-preact/hooks/use-store-state.d.ts +6 -0
- package/dist/shared-preact/index.d.ts +3 -0
- package/dist/shared-react/components/embed-pdf.d.ts +12 -0
- package/dist/shared-react/components/index.d.ts +1 -0
- package/dist/shared-react/context.d.ts +7 -0
- package/dist/shared-react/hooks/index.d.ts +5 -0
- package/dist/shared-react/hooks/use-capability.d.ts +16 -0
- package/dist/shared-react/hooks/use-core-state.d.ts +6 -0
- package/dist/shared-react/hooks/use-plugin.d.ts +16 -0
- package/dist/shared-react/hooks/use-registry.d.ts +6 -0
- package/dist/shared-react/hooks/use-store-state.d.ts +6 -0
- package/dist/shared-react/index.d.ts +3 -0
- package/dist/vue/components/embed-pdf.vue.d.ts +23 -0
- package/dist/vue/components/index.d.ts +1 -0
- package/dist/vue/composables/index.d.ts +5 -0
- package/dist/vue/composables/use-capability.d.ts +15 -0
- package/dist/vue/composables/use-core-state.d.ts +2 -0
- package/dist/vue/composables/use-plugin.d.ts +8 -0
- package/dist/vue/composables/use-registry.d.ts +1 -0
- package/dist/vue/composables/use-store-state.d.ts +10 -0
- package/dist/vue/context.d.ts +8 -0
- package/dist/vue/index.cjs +2 -0
- package/dist/vue/index.cjs.map +1 -0
- package/dist/vue/index.d.ts +2 -0
- package/dist/vue/index.js +115 -0
- package/dist/vue/index.js.map +1 -0
- package/package.json +20 -12
- package/dist/index.d.cts +0 -585
- package/dist/preact/index.d.cts +0 -71
- package/dist/react/index.d.cts +0 -70
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
-
|
|
65
|
+
}
|
|
66
|
+
class PluginNotFoundError extends Error {
|
|
69
67
|
constructor(message) {
|
|
70
68
|
super(message);
|
|
71
69
|
this.name = "PluginNotFoundError";
|
|
72
70
|
}
|
|
73
|
-
}
|
|
74
|
-
|
|
71
|
+
}
|
|
72
|
+
class CircularDependencyError extends Error {
|
|
75
73
|
constructor(message) {
|
|
76
74
|
super(message);
|
|
77
75
|
this.name = "CircularDependencyError";
|
|
78
76
|
}
|
|
79
|
-
}
|
|
80
|
-
|
|
77
|
+
}
|
|
78
|
+
class CapabilityNotFoundError extends Error {
|
|
81
79
|
constructor(message) {
|
|
82
80
|
super(message);
|
|
83
81
|
this.name = "CapabilityNotFoundError";
|
|
84
82
|
}
|
|
85
|
-
}
|
|
86
|
-
|
|
83
|
+
}
|
|
84
|
+
class CapabilityConflictError extends Error {
|
|
87
85
|
constructor(message) {
|
|
88
86
|
super(message);
|
|
89
87
|
this.name = "CapabilityConflictError";
|
|
90
88
|
}
|
|
91
|
-
}
|
|
92
|
-
|
|
89
|
+
}
|
|
90
|
+
class PluginInitializationError extends Error {
|
|
93
91
|
constructor(message) {
|
|
94
92
|
super(message);
|
|
95
93
|
this.name = "PluginInitializationError";
|
|
96
94
|
}
|
|
97
|
-
}
|
|
98
|
-
|
|
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
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
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
|
-
|
|
185
|
-
|
|
178
|
+
const loadDocument = () => ({ type: LOAD_DOCUMENT });
|
|
179
|
+
const setDocument = (document) => ({
|
|
186
180
|
type: SET_DOCUMENT,
|
|
187
181
|
payload: document
|
|
188
182
|
});
|
|
189
|
-
|
|
183
|
+
const setDocumentError = (error) => ({
|
|
190
184
|
type: SET_DOCUMENT_ERROR,
|
|
191
185
|
payload: error
|
|
192
186
|
});
|
|
193
|
-
|
|
194
|
-
|
|
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
|
-
|
|
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]
|
|
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
|
-
|
|
399
|
-
|
|
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
|
|
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
|
-
|
|
1107
|
-
|
|
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
|