@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@embedpdf/core",
3
- "version": "1.0.10",
3
+ "version": "1.0.12",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
@@ -20,21 +20,27 @@
20
20
  "types": "./dist/preact/index.d.ts",
21
21
  "import": "./dist/preact/index.js",
22
22
  "require": "./dist/preact/index.cjs"
23
+ },
24
+ "./vue": {
25
+ "types": "./dist/vue/index.d.ts",
26
+ "import": "./dist/vue/index.js",
27
+ "require": "./dist/vue/index.cjs"
23
28
  }
24
29
  },
25
30
  "devDependencies": {
26
- "tsup": "^8.0.0",
31
+ "@types/react": "^18.2.0",
27
32
  "typescript": "^5.0.0",
28
- "@types/react": "^18.2.0"
33
+ "@embedpdf/build": "1.0.0"
29
34
  },
30
35
  "dependencies": {
31
- "@embedpdf/models": "1.0.10",
32
- "@embedpdf/engines": "1.0.10"
36
+ "@embedpdf/models": "1.0.12",
37
+ "@embedpdf/engines": "1.0.12"
33
38
  },
34
39
  "peerDependencies": {
40
+ "preact": "^10.26.4",
35
41
  "react": ">=16.8.0",
36
42
  "react-dom": ">=16.8.0",
37
- "preact": "^10.26.4"
43
+ "vue": ">=3.2.0"
38
44
  },
39
45
  "files": [
40
46
  "dist",
@@ -44,11 +50,13 @@
44
50
  "access": "public"
45
51
  },
46
52
  "scripts": {
47
- "build": "PROJECT_CWD=$(pwd) pnpm -w p:build",
48
- "build:watch": "PROJECT_CWD=$(pwd) pnpm -w p:build:watch",
49
- "clean": "PROJECT_CWD=$(pwd) pnpm -w p:clean",
50
- "lint": "PROJECT_CWD=$(pwd) pnpm -w p:lint",
51
- "lint:fix": "PROJECT_CWD=$(pwd) pnpm -w p:lint:fix",
52
- "typecheck": "PROJECT_CWD=$(pwd) pnpm -w p:typecheck"
53
+ "build:base": "vite build --mode base",
54
+ "build:react": "vite build --mode react",
55
+ "build:preact": "vite build --mode preact",
56
+ "build:vue": "vite build --mode vue",
57
+ "build": "pnpm run clean && concurrently -c auto -n base,react,preact,vue \"vite build --mode base\" \"vite build --mode react\" \"vite build --mode preact\" \"vite build --mode vue\"",
58
+ "clean": "rimraf dist",
59
+ "lint": "eslint src --color",
60
+ "lint:fix": "eslint src --color --fix"
53
61
  }
54
62
  }
package/dist/index.d.cts DELETED
@@ -1,585 +0,0 @@
1
- import { Rotation, PdfDocumentObject, PdfPageObject, PdfPageObjectWithRotatedSize, PdfEngine } from '@embedpdf/models';
2
-
3
- /** Represents an action with a type and optional payload */
4
- interface Action {
5
- type: string;
6
- payload?: any;
7
- }
8
- /** A reducer function that updates a specific state based on an action */
9
- type Reducer<State, Action> = (state: State, action: Action) => State;
10
- /**
11
- * Represents the overall store state, with a typed core and plugin states
12
- */
13
- interface StoreState<CoreState> {
14
- core: CoreState;
15
- plugins: Record<string, any>;
16
- }
17
- /**
18
- * The signature of a main-store listener. You now receive:
19
- * - `action` => The action that was dispatched
20
- * - `newState` => The store state *after* the update
21
- * - `oldState` => The store state *before* the update
22
- */
23
- type StoreListener<CoreState> = (action: Action, newState: StoreState<CoreState>, oldState: StoreState<CoreState>) => void;
24
- /**
25
- * The signature of a plugin-store listener. You now receive:
26
- * - `action` => The action that was dispatched
27
- * - `newPluginState` => The plugin state *after* the update
28
- * - `oldPluginState` => The plugin state *before* the update
29
- */
30
- type PluginListener = (action: Action, newPluginState: any, oldPluginState: any) => void;
31
-
32
- /**
33
- * A type-safe store handle for plugins, providing access to plugin-specific state and actions.
34
- */
35
- declare class PluginStore<PluginState, PluginAction extends Action> {
36
- private store;
37
- private pluginId;
38
- /**
39
- * Initializes the PluginStore with the main store and plugin ID.
40
- * @param store The main store instance.
41
- * @param pluginId The unique identifier for the plugin.
42
- */
43
- constructor(store: Store<any, any>, pluginId: string);
44
- /**
45
- * Gets the current state of the plugin.
46
- * @returns The plugin's state.
47
- */
48
- getState(): PluginState;
49
- /**
50
- * Dispatches an action for the plugin and returns the *new* global state.
51
- * If you only need the plugin’s updated state, call `getState()` afterward.
52
- * @param action The action to dispatch.
53
- * @returns The updated global store state (after plugin reducer).
54
- */
55
- dispatch(action: PluginAction): PluginState;
56
- /**
57
- * Subscribes to state changes only for this specific plugin.
58
- * You now receive (action, newPluginState, oldPluginState) in the callback.
59
- *
60
- * @param listener The callback to invoke when plugin state changes.
61
- * @returns A function to unsubscribe the listener.
62
- */
63
- subscribeToState(listener: (action: PluginAction, newState: PluginState, oldState: PluginState) => void): () => void;
64
- /**
65
- * Subscribes to a specific action type for the plugin.
66
- * This still uses the main store's `onAction`, so you get the *global*
67
- * old/new store states there. If you specifically want old/new plugin state,
68
- * use `subscribeToState` instead.
69
- *
70
- * @param type The action type to listen for.
71
- * @param handler The callback to invoke when the action occurs.
72
- * @returns A function to unsubscribe the handler.
73
- */
74
- onAction<T extends PluginAction['type']>(type: T, handler: (action: Extract<PluginAction, {
75
- type: T;
76
- }>, state: PluginState, oldState: PluginState) => void): () => void;
77
- }
78
-
79
- /**
80
- * A generic, type-safe store class managing core and plugin states, reducers, and subscriptions.
81
- * @template CoreState The type of the core state.
82
- * @template CoreAction The type of actions handled by core reducers (extends Action).
83
- */
84
- declare class Store<CoreState, CoreAction extends Action = Action> {
85
- initialCoreState: CoreState;
86
- private state;
87
- private coreReducer;
88
- private pluginReducers;
89
- private listeners;
90
- private pluginListeners;
91
- /**
92
- * Initializes the store with the provided core state.
93
- * @param reducer The core reducer function
94
- * @param initialCoreState The initial core state
95
- */
96
- constructor(reducer: Reducer<CoreState, CoreAction>, initialCoreState: CoreState);
97
- /**
98
- * Adds a reducer for a plugin-specific state.
99
- * @param pluginId The unique identifier for the plugin.
100
- * @param reducer The reducer function for the plugin state.
101
- * @param initialState The initial state for the plugin.
102
- */
103
- addPluginReducer<PluginState>(pluginId: string, reducer: Reducer<PluginState, Action>, initialState: PluginState): void;
104
- /**
105
- * Dispatches an action *only* to the core reducer.
106
- * Notifies the global store listeners with (action, newState, oldState).
107
- *
108
- * @param action The action to dispatch, typed as CoreAction
109
- * @returns The updated *global* store state
110
- */
111
- dispatchToCore(action: CoreAction): StoreState<CoreState>;
112
- /**
113
- * Dispatches an action *only* to a specific plugin.
114
- * Optionally notifies global store listeners if `notifyGlobal` is true.
115
- * Always notifies plugin-specific listeners with (action, newPluginState, oldPluginState).
116
- *
117
- * @param pluginId The plugin identifier
118
- * @param action The plugin action to dispatch
119
- * @param notifyGlobal Whether to also notify global store listeners
120
- * @returns The updated *global* store state
121
- */
122
- dispatchToPlugin<PluginAction extends Action>(pluginId: string, action: PluginAction, notifyGlobal?: boolean): any;
123
- /**
124
- * Dispatches an action to update the state using:
125
- * - the core reducer (if it's a CoreAction)
126
- * - *all* plugin reducers (regardless of action type), with no global notify for each plugin
127
- *
128
- * Returns the new *global* store state after all reducers have processed the action.
129
- *
130
- * @param action The action to dispatch (can be CoreAction or any Action).
131
- */
132
- dispatch(action: CoreAction | Action): StoreState<CoreState>;
133
- /**
134
- * Returns a shallow copy of the current state.
135
- * @returns The current store state.
136
- */
137
- getState(): StoreState<CoreState>;
138
- /**
139
- * Subscribes a listener to *global* state changes.
140
- * The callback signature is now (action, newState, oldState).
141
- *
142
- * @param listener The callback to invoke on state changes
143
- * @returns A function to unsubscribe the listener
144
- */
145
- subscribe(listener: StoreListener<CoreState>): () => void;
146
- /**
147
- * Subscribes a listener to *plugin-specific* state changes.
148
- * The callback signature is now (action, newPluginState, oldPluginState).
149
- *
150
- * @param pluginId The unique identifier for the plugin.
151
- * @param listener The callback to invoke on plugin state changes.
152
- * @returns A function to unsubscribe the listener.
153
- */
154
- subscribeToPlugin(pluginId: string, listener: PluginListener): () => void;
155
- /**
156
- * Subscribes to a specific action type (only from the core's action union).
157
- * The callback signature is (action, newState, oldState).
158
- *
159
- * @param type The action type to listen for.
160
- * @param handler The callback to invoke when the action occurs.
161
- * @returns A function to unsubscribe the handler.
162
- */
163
- onAction<T extends CoreAction['type']>(type: T, handler: (action: Extract<CoreAction, {
164
- type: T;
165
- }>, state: StoreState<CoreState>, oldState: StoreState<CoreState>) => void): () => void;
166
- /**
167
- * Gets a PluginStore handle for a specific plugin.
168
- * @param pluginId The unique identifier for the plugin.
169
- * @returns A PluginStore instance for the plugin.
170
- */
171
- getPluginStore<PluginState, PluginAction extends Action>(pluginId: string): PluginStore<PluginState, PluginAction>;
172
- /**
173
- * Helper method to check if an action is a CoreAction.
174
- * Adjust if you have a more refined way to differentiate CoreAction vs. any other Action.
175
- */
176
- isCoreAction(action: Action): action is CoreAction;
177
- /**
178
- * Destroy the store: drop every listener and plugin reducer
179
- */
180
- destroy(): void;
181
- }
182
-
183
- interface CoreState {
184
- scale: number;
185
- rotation: Rotation;
186
- document: PdfDocumentObject | null;
187
- pages: PdfPageObject[][];
188
- loading: boolean;
189
- error: string | null;
190
- }
191
- declare const initialCoreState: (config?: PluginRegistryConfig) => CoreState;
192
-
193
- declare const LOAD_DOCUMENT = "LOAD_DOCUMENT";
194
- declare const SET_DOCUMENT = "SET_DOCUMENT";
195
- declare const SET_DOCUMENT_ERROR = "SET_DOCUMENT_ERROR";
196
- declare const SET_SCALE = "SET_SCALE";
197
- declare const SET_ROTATION = "SET_ROTATION";
198
- declare const SET_PAGES = "SET_PAGES";
199
- declare const CORE_ACTION_TYPES: readonly ["LOAD_DOCUMENT", "SET_DOCUMENT", "SET_DOCUMENT_ERROR", "SET_SCALE", "SET_ROTATION", "SET_PAGES"];
200
- interface LoadDocumentAction {
201
- type: typeof LOAD_DOCUMENT;
202
- }
203
- interface SetDocumentAction {
204
- type: typeof SET_DOCUMENT;
205
- payload: PdfDocumentObject;
206
- }
207
- interface SetDocumentErrorAction {
208
- type: typeof SET_DOCUMENT_ERROR;
209
- payload: string;
210
- }
211
- interface SetScaleAction {
212
- type: typeof SET_SCALE;
213
- payload: number;
214
- }
215
- interface SetRotationAction {
216
- type: typeof SET_ROTATION;
217
- payload: Rotation;
218
- }
219
- interface SetPagesAction {
220
- type: typeof SET_PAGES;
221
- payload: PdfPageObject[][];
222
- }
223
- type DocumentAction = LoadDocumentAction | SetDocumentAction | SetDocumentErrorAction | SetScaleAction | SetRotationAction | SetPagesAction;
224
- type CoreAction = DocumentAction;
225
- declare const loadDocument: () => CoreAction;
226
- declare const setDocument: (document: PdfDocumentObject) => CoreAction;
227
- declare const setDocumentError: (error: string) => CoreAction;
228
- declare const setScale: (scale: number) => CoreAction;
229
- declare const setRotation: (rotation: Rotation) => CoreAction;
230
- declare const setPages: (pages: PdfPageObject[][]) => CoreAction;
231
-
232
- declare const getPagesWithRotatedSize: (state: CoreState) => PdfPageObjectWithRotatedSize[][];
233
-
234
- interface IPlugin<TConfig = unknown> {
235
- id: string;
236
- initialize?(config: TConfig): Promise<void>;
237
- destroy?(): Promise<void> | void;
238
- provides?(): any;
239
- postInitialize?(): Promise<void>;
240
- ready?(): Promise<void>;
241
- }
242
- interface BasePluginConfig {
243
- enabled?: boolean;
244
- }
245
- interface PluginRegistryConfig {
246
- rotation?: Rotation;
247
- scale?: number;
248
- }
249
- interface PluginManifest<TConfig = unknown> {
250
- id: string;
251
- name: string;
252
- version: string;
253
- provides: string[];
254
- requires: string[];
255
- optional: string[];
256
- defaultConfig: TConfig;
257
- metadata?: {
258
- description?: string;
259
- author?: string;
260
- homepage?: string;
261
- [key: string]: unknown;
262
- };
263
- }
264
- interface PluginPackage<T extends IPlugin<TConfig>, TConfig = unknown, TState = unknown, TAction extends Action = Action> {
265
- manifest: PluginManifest<TConfig>;
266
- create(registry: PluginRegistry, engine: PdfEngine, config: TConfig): T;
267
- reducer: Reducer<TState, TAction>;
268
- initialState: TState | ((coreState: CoreState, config: TConfig) => TState);
269
- }
270
- type PluginStatus = 'registered' | 'active' | 'error' | 'disabled' | 'unregistered';
271
- interface PluginBatchRegistration<T extends IPlugin<TConfig>, TConfig = unknown, TState = unknown, TAction extends Action = Action> {
272
- package: PluginPackage<T, TConfig, TState, TAction>;
273
- config?: Partial<TConfig>;
274
- }
275
- interface GlobalStoreState<TPlugins extends Record<string, any> = {}> {
276
- core: CoreState;
277
- plugins: TPlugins;
278
- }
279
-
280
- declare class PluginRegistry {
281
- private plugins;
282
- private manifests;
283
- private capabilities;
284
- private status;
285
- private resolver;
286
- private configurations;
287
- private engine;
288
- private engineInitialized;
289
- private store;
290
- private initPromise;
291
- private pendingRegistrations;
292
- private processingRegistrations;
293
- private initialized;
294
- private isInitializing;
295
- private initialCoreState;
296
- private pluginsReadyPromise;
297
- private destroyed;
298
- constructor(engine: PdfEngine, config?: PluginRegistryConfig);
299
- /**
300
- * Ensure engine is initialized before proceeding
301
- */
302
- private ensureEngineInitialized;
303
- /**
304
- * Register a plugin without initializing it
305
- */
306
- registerPlugin<TPlugin extends IPlugin<TConfig>, TConfig = unknown, TState = unknown, TAction extends Action = Action>(pluginPackage: PluginPackage<TPlugin, TConfig, TState, TAction>, config?: Partial<TConfig>): void;
307
- /**
308
- * Get the central store instance
309
- */
310
- getStore(): Store<CoreState, CoreAction>;
311
- /**
312
- * Get the engine instance
313
- */
314
- getEngine(): PdfEngine;
315
- /**
316
- * Get a promise that resolves when all plugins are ready
317
- */
318
- pluginsReady(): Promise<void>;
319
- /**
320
- * INITIALISE THE REGISTRY – runs once no-matter-how-many calls *
321
- */
322
- initialize(): Promise<void>;
323
- /**
324
- * Initialize a single plugin with all necessary checks
325
- */
326
- private initializePlugin;
327
- getPluginConfig<TConfig>(pluginId: string): TConfig;
328
- private validateConfig;
329
- updatePluginConfig<TConfig>(pluginId: string, config: Partial<TConfig>): Promise<void>;
330
- /**
331
- * Register multiple plugins at once
332
- */
333
- registerPluginBatch(registrations: PluginBatchRegistration<IPlugin<any>, any, any, any>[]): void;
334
- /**
335
- * Unregister a plugin
336
- */
337
- unregisterPlugin(pluginId: string): Promise<void>;
338
- /**
339
- * Get a plugin instance
340
- * @param pluginId The ID of the plugin to get
341
- * @returns The plugin instance or null if not found
342
- */
343
- getPlugin<T extends IPlugin>(pluginId: string): T | null;
344
- /**
345
- * Get a plugin that provides a specific capability
346
- * @param capability The capability to get a provider for
347
- * @returns The plugin providing the capability or null if not found
348
- */
349
- getCapabilityProvider(capability: string): IPlugin | null;
350
- /**
351
- * Check if a capability is available
352
- */
353
- hasCapability(capability: string): boolean;
354
- /**
355
- * Get all registered plugins
356
- */
357
- getAllPlugins(): IPlugin[];
358
- /**
359
- * Get plugin status
360
- */
361
- getPluginStatus(pluginId: string): PluginStatus;
362
- /**
363
- * Validate plugin object
364
- */
365
- private validatePlugin;
366
- /**
367
- * Validate plugin manifest
368
- */
369
- private validateManifest;
370
- isDestroyed(): boolean;
371
- /**
372
- * DESTROY EVERYTHING – waits for any ongoing initialise(), once *
373
- */
374
- destroy(): Promise<void>;
375
- }
376
-
377
- declare class DependencyResolver {
378
- private dependencyGraph;
379
- addNode(id: string, dependencies?: string[]): void;
380
- private hasCircularDependencies;
381
- resolveLoadOrder(): string[];
382
- }
383
-
384
- /**
385
- * Helper function to create a properly typed plugin registration
386
- */
387
- declare function createPluginRegistration<T extends IPlugin<TConfig>, TConfig, TState, TAction extends Action>(pluginPackage: PluginPackage<T, TConfig, TState, TAction>, config?: Partial<TConfig>): PluginBatchRegistration<T, TConfig, any, any>;
388
-
389
- declare class PluginRegistrationError extends Error {
390
- constructor(message: string);
391
- }
392
- declare class PluginNotFoundError extends Error {
393
- constructor(message: string);
394
- }
395
- declare class CircularDependencyError extends Error {
396
- constructor(message: string);
397
- }
398
- declare class CapabilityNotFoundError extends Error {
399
- constructor(message: string);
400
- }
401
- declare class CapabilityConflictError extends Error {
402
- constructor(message: string);
403
- }
404
- declare class PluginInitializationError extends Error {
405
- constructor(message: string);
406
- }
407
- declare class PluginConfigurationError extends Error {
408
- constructor(message: string);
409
- }
410
-
411
- interface StateChangeHandler<TState> {
412
- (state: TState): void;
413
- }
414
- declare abstract class BasePlugin<TConfig = unknown, TCapability = unknown, TState = unknown, TAction extends Action = Action> implements IPlugin<TConfig> {
415
- readonly id: string;
416
- protected registry: PluginRegistry;
417
- static readonly id: string;
418
- protected pluginStore: PluginStore<TState, TAction>;
419
- protected coreStore: Store<CoreState, CoreAction>;
420
- private debouncedActions;
421
- private unsubscribeFromState;
422
- private unsubscribeFromCoreStore;
423
- private _capability?;
424
- private readyPromise;
425
- private readyResolve;
426
- constructor(id: string, registry: PluginRegistry);
427
- /** Construct the public capability (called once & cached). */
428
- protected abstract buildCapability(): TCapability;
429
- provides(): Readonly<TCapability>;
430
- /**
431
- * Initialize plugin with config
432
- */
433
- abstract initialize(config: TConfig): Promise<void>;
434
- /**
435
- * Get a copy of the current state
436
- */
437
- protected get state(): Readonly<TState>;
438
- /**
439
- * Get a copy of the current core state
440
- */
441
- protected get coreState(): Readonly<StoreState<CoreState>>;
442
- /**
443
- * @deprecated use `this.state` Get a copy of the current state
444
- */
445
- protected getState(): TState;
446
- /**
447
- * @deprecated use `this.coreState` Get a copy of the current core state
448
- */
449
- protected getCoreState(): StoreState<CoreState>;
450
- /**
451
- * Core Dispatch
452
- */
453
- protected dispatchCoreAction(action: CoreAction): StoreState<CoreState>;
454
- /**
455
- * Dispatch an action to all plugins
456
- */
457
- protected dispatchToAllPlugins(action: TAction): StoreState<CoreState>;
458
- /**
459
- * Dispatch an action
460
- */
461
- protected dispatch(action: TAction): TState;
462
- /**
463
- * Dispatch an action with debouncing to prevent rapid repeated calls
464
- * @param action The action to dispatch
465
- * @param debounceTime Time in ms to debounce (default: 100ms)
466
- * @returns boolean indicating whether the action was dispatched or debounced
467
- */
468
- protected debouncedDispatch(action: TAction, debounceTime?: number): boolean;
469
- /**
470
- * Subscribe to state changes
471
- */
472
- protected subscribe(listener: (action: TAction, state: TState) => void): () => void;
473
- /**
474
- * Subscribe to core store changes
475
- */
476
- protected subscribeToCoreStore(listener: (action: Action, state: StoreState<CoreState>) => void): () => void;
477
- /**
478
- * Called when the plugin store state is updated
479
- * @param oldState Previous state
480
- * @param newState New state
481
- */
482
- protected onStoreUpdated(oldState: TState, newState: TState): void;
483
- /**
484
- * Called when the core store state is updated
485
- * @param oldState Previous state
486
- * @param newState New state
487
- */
488
- protected onCoreStoreUpdated(oldState: StoreState<CoreState>, newState: StoreState<CoreState>): void;
489
- /**
490
- * Cleanup method to be called when plugin is being destroyed
491
- */
492
- destroy(): void;
493
- /**
494
- * Returns a promise that resolves when the plugin is ready
495
- */
496
- ready(): Promise<void>;
497
- /**
498
- * Mark the plugin as ready
499
- */
500
- protected markReady(): void;
501
- /**
502
- * Reset the ready state (useful for plugins that need to reinitialize)
503
- */
504
- protected resetReady(): void;
505
- }
506
-
507
- type EventHandler<T> = (data: T) => void;
508
- interface BaseEventControlOptions {
509
- wait: number;
510
- }
511
- interface DebounceOptions extends BaseEventControlOptions {
512
- mode: 'debounce';
513
- }
514
- interface ThrottleOptions extends BaseEventControlOptions {
515
- mode: 'throttle';
516
- throttleMode?: 'leading-trailing' | 'trailing';
517
- }
518
- type EventControlOptions = DebounceOptions | ThrottleOptions;
519
- declare class EventControl<T> {
520
- private handler;
521
- private options;
522
- private timeoutId?;
523
- private lastRun;
524
- constructor(handler: EventHandler<T>, options: EventControlOptions);
525
- handle: (data: T) => void;
526
- private debounce;
527
- private throttle;
528
- destroy(): void;
529
- }
530
-
531
- type Listener<T = any> = (value: T) => void;
532
- type Unsubscribe = () => void;
533
- type EventListener<T> = ((listener: Listener<T>) => Unsubscribe) | ((listener: Listener<T>, options?: EventControlOptions) => Unsubscribe);
534
- type EventHook<T = any> = EventListener<T>;
535
- interface Emitter<T = any> {
536
- emit(value?: T): void;
537
- on(listener: Listener<T>): Unsubscribe;
538
- off(listener: Listener<T>): void;
539
- clear(): void;
540
- }
541
- declare function createEmitter<T = any>(): Emitter<T>;
542
- interface BehaviorEmitter<T = any> extends Omit<Emitter<T>, 'on' | 'off'> {
543
- readonly value?: T;
544
- on: EventHook<T>;
545
- off(listener: Listener<T>): void;
546
- select<U>(selector: (v: T) => U, equality?: (a: U, b: U) => boolean): EventHook<U>;
547
- }
548
- declare function createBehaviorEmitter<T = any>(initial?: T, equality?: (a: T, b: T) => boolean): BehaviorEmitter<T>;
549
-
550
- /**
551
- * Restrict a numeric value to the inclusive range [min, max].
552
- *
553
- * @example
554
- * clamp( 5, 0, 10) // 5
555
- * clamp(-3, 0, 10) // 0
556
- * clamp(17, 0, 10) // 10
557
- */
558
- declare function clamp(value: number, min: number, max: number): number;
559
- /**
560
- * Deeply compares two values (objects, arrays, primitives)
561
- * with the following rules:
562
- * - Objects are compared ignoring property order.
563
- * - Arrays are compared ignoring element order (multiset comparison).
564
- * - Primitives are compared by strict equality.
565
- * - null/undefined are treated as normal primitives.
566
- *
567
- * @param a First value
568
- * @param b Second value
569
- * @param visited Used internally to detect cycles
570
- */
571
- declare function arePropsEqual(a: any, b: any, visited?: Set<any>): boolean;
572
-
573
- type EnumKey = string | number;
574
- /**
575
- * Iterate over a Record whose keys are enum members (numeric or string),
576
- * getting back a fully-typed `[key, value]` tuple array.
577
- *
578
- * Usage:
579
- * for (const [subtype, defaults] of enumEntries(this.state.toolDefaults)) {
580
- * // subtype is inferred as keyof ToolDefaultsBySubtype
581
- * }
582
- */
583
- declare function enumEntries<E extends EnumKey, V>(record: Record<E, V>): Array<[E, V]>;
584
-
585
- export { type Action, type BaseEventControlOptions, BasePlugin, type BasePluginConfig, type BehaviorEmitter, CORE_ACTION_TYPES, CapabilityConflictError, CapabilityNotFoundError, CircularDependencyError, type CoreAction, type CoreState, type DebounceOptions, DependencyResolver, type DocumentAction, type Emitter, EventControl, type EventControlOptions, type EventHandler, type EventHook, type EventListener, type GlobalStoreState, type IPlugin, LOAD_DOCUMENT, type Listener, type LoadDocumentAction, type PluginBatchRegistration, PluginConfigurationError, PluginInitializationError, type PluginListener, type PluginManifest, PluginNotFoundError, type PluginPackage, PluginRegistrationError, PluginRegistry, type PluginRegistryConfig, type PluginStatus, type Reducer, SET_DOCUMENT, SET_DOCUMENT_ERROR, SET_PAGES, SET_ROTATION, SET_SCALE, type SetDocumentAction, type SetDocumentErrorAction, type SetPagesAction, type SetRotationAction, type SetScaleAction, type StateChangeHandler, type StoreListener, type StoreState, type ThrottleOptions, type Unsubscribe, arePropsEqual, clamp, createBehaviorEmitter, createEmitter, createPluginRegistration, enumEntries, getPagesWithRotatedSize, initialCoreState, loadDocument, setDocument, setDocumentError, setPages, setRotation, setScale };