@embedpdf/core 2.15.0 → 3.0.0-next.1

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 (117) hide show
  1. package/LICENSE +192 -21
  2. package/dist/index.cjs +864 -2
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.d.cts +313 -0
  5. package/dist/index.d.ts +313 -1
  6. package/dist/index.js +816 -2124
  7. package/dist/index.js.map +1 -1
  8. package/package.json +22 -52
  9. package/README.md +0 -40
  10. package/dist/lib/base/base-plugin.d.ts +0 -190
  11. package/dist/lib/index.d.ts +0 -17
  12. package/dist/lib/plugin/builder.d.ts +0 -11
  13. package/dist/lib/registry/plugin-registry.d.ts +0 -104
  14. package/dist/lib/store/actions.d.ts +0 -154
  15. package/dist/lib/store/index.d.ts +0 -6
  16. package/dist/lib/store/initial-state.d.ts +0 -31
  17. package/dist/lib/store/plugin-store.d.ts +0 -48
  18. package/dist/lib/store/reducer-helpers.d.ts +0 -11
  19. package/dist/lib/store/reducer.d.ts +0 -4
  20. package/dist/lib/store/selectors.d.ts +0 -41
  21. package/dist/lib/store/store.d.ts +0 -106
  22. package/dist/lib/store/types.d.ts +0 -28
  23. package/dist/lib/types/errors.d.ts +0 -21
  24. package/dist/lib/types/permissions.d.ts +0 -55
  25. package/dist/lib/types/plugin.d.ts +0 -75
  26. package/dist/lib/utils/dependency-resolver.d.ts +0 -6
  27. package/dist/lib/utils/event-control.d.ts +0 -58
  28. package/dist/lib/utils/eventing.d.ts +0 -19
  29. package/dist/lib/utils/math.d.ts +0 -22
  30. package/dist/lib/utils/plugin-helpers.d.ts +0 -6
  31. package/dist/lib/utils/scoped-eventing.d.ts +0 -71
  32. package/dist/lib/utils/typed-object.d.ts +0 -12
  33. package/dist/preact/adapter.d.ts +0 -11
  34. package/dist/preact/index.cjs +0 -2
  35. package/dist/preact/index.cjs.map +0 -1
  36. package/dist/preact/index.d.ts +0 -1
  37. package/dist/preact/index.js +0 -323
  38. package/dist/preact/index.js.map +0 -1
  39. package/dist/react/adapter.d.ts +0 -2
  40. package/dist/react/index.cjs +0 -2
  41. package/dist/react/index.cjs.map +0 -1
  42. package/dist/react/index.d.ts +0 -1
  43. package/dist/react/index.js +0 -322
  44. package/dist/react/index.js.map +0 -1
  45. package/dist/shared/components/auto-mount.d.ts +0 -8
  46. package/dist/shared/components/embed-pdf.d.ts +0 -37
  47. package/dist/shared/components/index.d.ts +0 -1
  48. package/dist/shared/context.d.ts +0 -12
  49. package/dist/shared/hooks/index.d.ts +0 -7
  50. package/dist/shared/hooks/use-capability.d.ts +0 -16
  51. package/dist/shared/hooks/use-core-state.d.ts +0 -8
  52. package/dist/shared/hooks/use-document-permissions.d.ts +0 -35
  53. package/dist/shared/hooks/use-document-state.d.ts +0 -8
  54. package/dist/shared/hooks/use-plugin.d.ts +0 -16
  55. package/dist/shared/hooks/use-registry.d.ts +0 -6
  56. package/dist/shared/hooks/use-store-state.d.ts +0 -6
  57. package/dist/shared/index.d.ts +0 -3
  58. package/dist/shared-preact/components/auto-mount.d.ts +0 -8
  59. package/dist/shared-preact/components/embed-pdf.d.ts +0 -37
  60. package/dist/shared-preact/components/index.d.ts +0 -1
  61. package/dist/shared-preact/context.d.ts +0 -12
  62. package/dist/shared-preact/hooks/index.d.ts +0 -7
  63. package/dist/shared-preact/hooks/use-capability.d.ts +0 -16
  64. package/dist/shared-preact/hooks/use-core-state.d.ts +0 -8
  65. package/dist/shared-preact/hooks/use-document-permissions.d.ts +0 -35
  66. package/dist/shared-preact/hooks/use-document-state.d.ts +0 -8
  67. package/dist/shared-preact/hooks/use-plugin.d.ts +0 -16
  68. package/dist/shared-preact/hooks/use-registry.d.ts +0 -6
  69. package/dist/shared-preact/hooks/use-store-state.d.ts +0 -6
  70. package/dist/shared-preact/index.d.ts +0 -3
  71. package/dist/shared-react/components/auto-mount.d.ts +0 -8
  72. package/dist/shared-react/components/embed-pdf.d.ts +0 -37
  73. package/dist/shared-react/components/index.d.ts +0 -1
  74. package/dist/shared-react/context.d.ts +0 -12
  75. package/dist/shared-react/hooks/index.d.ts +0 -7
  76. package/dist/shared-react/hooks/use-capability.d.ts +0 -16
  77. package/dist/shared-react/hooks/use-core-state.d.ts +0 -8
  78. package/dist/shared-react/hooks/use-document-permissions.d.ts +0 -35
  79. package/dist/shared-react/hooks/use-document-state.d.ts +0 -8
  80. package/dist/shared-react/hooks/use-plugin.d.ts +0 -16
  81. package/dist/shared-react/hooks/use-registry.d.ts +0 -6
  82. package/dist/shared-react/hooks/use-store-state.d.ts +0 -6
  83. package/dist/shared-react/index.d.ts +0 -3
  84. package/dist/svelte/components/AutoMount.svelte.d.ts +0 -9
  85. package/dist/svelte/components/EmbedPDF.svelte.d.ts +0 -40
  86. package/dist/svelte/components/NestedWrapper.svelte.d.ts +0 -10
  87. package/dist/svelte/components/index.d.ts +0 -1
  88. package/dist/svelte/hooks/index.d.ts +0 -6
  89. package/dist/svelte/hooks/use-capability.svelte.d.ts +0 -14
  90. package/dist/svelte/hooks/use-core-state.svelte.d.ts +0 -9
  91. package/dist/svelte/hooks/use-document-permissions.svelte.d.ts +0 -35
  92. package/dist/svelte/hooks/use-document-state.svelte.d.ts +0 -9
  93. package/dist/svelte/hooks/use-plugin.svelte.d.ts +0 -14
  94. package/dist/svelte/hooks/use-registry.svelte.d.ts +0 -17
  95. package/dist/svelte/index.cjs +0 -2
  96. package/dist/svelte/index.cjs.map +0 -1
  97. package/dist/svelte/index.d.ts +0 -2
  98. package/dist/svelte/index.js +0 -430
  99. package/dist/svelte/index.js.map +0 -1
  100. package/dist/vue/components/auto-mount.vue.d.ts +0 -19
  101. package/dist/vue/components/embed-pdf.vue.d.ts +0 -104
  102. package/dist/vue/components/index.d.ts +0 -1
  103. package/dist/vue/components/nested-wrapper.vue.d.ts +0 -19
  104. package/dist/vue/composables/index.d.ts +0 -7
  105. package/dist/vue/composables/use-capability.d.ts +0 -15
  106. package/dist/vue/composables/use-core-state.d.ts +0 -9
  107. package/dist/vue/composables/use-document-permissions.d.ts +0 -36
  108. package/dist/vue/composables/use-document-state.d.ts +0 -8
  109. package/dist/vue/composables/use-plugin.d.ts +0 -8
  110. package/dist/vue/composables/use-registry.d.ts +0 -1
  111. package/dist/vue/composables/use-store-state.d.ts +0 -10
  112. package/dist/vue/context.d.ts +0 -13
  113. package/dist/vue/index.cjs +0 -2
  114. package/dist/vue/index.cjs.map +0 -1
  115. package/dist/vue/index.d.ts +0 -2
  116. package/dist/vue/index.js +0 -384
  117. package/dist/vue/index.js.map +0 -1
@@ -1,48 +0,0 @@
1
- import { Store } from './store';
2
- import { Action } from './types';
3
- /**
4
- * A type-safe store handle for plugins, providing access to plugin-specific state and actions.
5
- */
6
- export declare class PluginStore<PluginState, PluginAction extends Action> {
7
- private store;
8
- private pluginId;
9
- /**
10
- * Initializes the PluginStore with the main store and plugin ID.
11
- * @param store The main store instance.
12
- * @param pluginId The unique identifier for the plugin.
13
- */
14
- constructor(store: Store<any, any>, pluginId: string);
15
- /**
16
- * Gets the current state of the plugin.
17
- * @returns The plugin's state.
18
- */
19
- getState(): PluginState;
20
- /**
21
- * Dispatches an action for the plugin and returns the *new* global state.
22
- * If you only need the plugin’s updated state, call `getState()` afterward.
23
- * @param action The action to dispatch.
24
- * @returns The updated global store state (after plugin reducer).
25
- */
26
- dispatch(action: PluginAction): PluginState;
27
- /**
28
- * Subscribes to state changes only for this specific plugin.
29
- * You now receive (action, newPluginState, oldPluginState) in the callback.
30
- *
31
- * @param listener The callback to invoke when plugin state changes.
32
- * @returns A function to unsubscribe the listener.
33
- */
34
- subscribeToState(listener: (action: PluginAction, newState: PluginState, oldState: PluginState) => void): () => void;
35
- /**
36
- * Subscribes to a specific action type for the plugin.
37
- * This still uses the main store's `onAction`, so you get the *global*
38
- * old/new store states there. If you specifically want old/new plugin state,
39
- * use `subscribeToState` instead.
40
- *
41
- * @param type The action type to listen for.
42
- * @param handler The callback to invoke when the action occurs.
43
- * @returns A function to unsubscribe the handler.
44
- */
45
- onAction<T extends PluginAction['type']>(type: T, handler: (action: Extract<PluginAction, {
46
- type: T;
47
- }>, state: PluginState, oldState: PluginState) => void): () => void;
48
- }
@@ -1,11 +0,0 @@
1
- import { CoreState } from './initial-state';
2
- /**
3
- * Calculate the next active document when closing a document.
4
- * Returns the document to activate, or null if no documents remain.
5
- */
6
- export declare function calculateNextActiveDocument(state: CoreState, closingDocumentId: string, explicitNext?: string | null): string | null;
7
- /**
8
- * Reorder a document within the documentOrder array.
9
- * Returns the new order, or null if the operation is invalid.
10
- */
11
- export declare function moveDocumentInOrder(currentOrder: string[], documentId: string, toIndex: number): string[] | null;
@@ -1,4 +0,0 @@
1
- import { Reducer } from './types';
2
- import { CoreState } from './initial-state';
3
- import { CoreAction } from './actions';
4
- export declare const coreReducer: Reducer<CoreState, CoreAction>;
@@ -1,41 +0,0 @@
1
- import { PdfPermissionFlag } from '@embedpdf/models';
2
- import { CoreState, DocumentState } from './initial-state';
3
- /**
4
- * Get the active document state
5
- */
6
- export declare const getActiveDocumentState: (state: CoreState) => DocumentState | null;
7
- /**
8
- * Get document state by ID
9
- */
10
- export declare const getDocumentState: (state: CoreState, documentId: string) => DocumentState | null;
11
- /**
12
- * Get all document IDs
13
- */
14
- export declare const getDocumentIds: (state: CoreState) => string[];
15
- /**
16
- * Check if a document is loaded
17
- */
18
- export declare const isDocumentLoaded: (state: CoreState, documentId: string) => boolean;
19
- /**
20
- * Get the number of open documents
21
- */
22
- export declare const getDocumentCount: (state: CoreState) => number;
23
- /**
24
- * Check if a specific permission flag is effectively allowed for a document.
25
- * Applies layered resolution: per-document override → global override → enforceDocumentPermissions → PDF permission.
26
- *
27
- * @param state - The core state
28
- * @param documentId - The document ID to check permissions for
29
- * @param flag - The permission flag to check
30
- * @returns true if the permission is allowed, false otherwise
31
- */
32
- export declare function getEffectivePermission(state: CoreState, documentId: string, flag: PdfPermissionFlag): boolean;
33
- /**
34
- * Get all effective permissions as a bitmask for a document.
35
- * Combines all individual permission checks into a single bitmask.
36
- *
37
- * @param state - The core state
38
- * @param documentId - The document ID to get permissions for
39
- * @returns A bitmask of all effective permissions
40
- */
41
- export declare function getEffectivePermissions(state: CoreState, documentId: string): number;
@@ -1,106 +0,0 @@
1
- import { Reducer, Action, StoreState, StoreListener, PluginListener } from './types';
2
- import { PluginStore } from './plugin-store';
3
- /**
4
- * A generic, type-safe store class managing core and plugin states, reducers, and subscriptions.
5
- * @template CoreState The type of the core state.
6
- * @template CoreAction The type of actions handled by core reducers (extends Action).
7
- */
8
- export declare class Store<CoreState, CoreAction extends Action = Action> {
9
- initialCoreState: CoreState;
10
- private state;
11
- private coreReducer;
12
- private pluginReducers;
13
- private listeners;
14
- private pluginListeners;
15
- private isDispatching;
16
- /**
17
- * Initializes the store with the provided core state.
18
- * @param reducer The core reducer function
19
- * @param initialCoreState The initial core state
20
- */
21
- constructor(reducer: Reducer<CoreState, CoreAction>, initialCoreState: CoreState);
22
- /**
23
- * Adds a reducer for a plugin-specific state.
24
- * @param pluginId The unique identifier for the plugin.
25
- * @param reducer The reducer function for the plugin state.
26
- * @param initialState The initial state for the plugin.
27
- */
28
- addPluginReducer<PluginState>(pluginId: string, reducer: Reducer<PluginState, Action>, initialState: PluginState): void;
29
- /**
30
- * Dispatches an action *only* to the core reducer.
31
- * Notifies the global store listeners with (action, newState, oldState).
32
- *
33
- * @param action The action to dispatch, typed as CoreAction
34
- * @returns The updated *global* store state
35
- */
36
- dispatchToCore(action: CoreAction): StoreState<CoreState>;
37
- /**
38
- * Dispatches an action *only* to a specific plugin.
39
- * Optionally notifies global store listeners if `notifyGlobal` is true.
40
- * Always notifies plugin-specific listeners with (action, newPluginState, oldPluginState).
41
- *
42
- * @param pluginId The plugin identifier
43
- * @param action The plugin action to dispatch
44
- * @param notifyGlobal Whether to also notify global store listeners
45
- * @returns The updated plugin state
46
- */
47
- dispatchToPlugin<PluginAction extends Action>(pluginId: string, action: PluginAction, notifyGlobal?: boolean): any;
48
- /**
49
- * Dispatches an action to update the state using:
50
- * - the core reducer (if it's a CoreAction)
51
- * - *all* plugin reducers (regardless of action type), with no global notify for each plugin
52
- *
53
- * Returns the new *global* store state after all reducers have processed the action.
54
- *
55
- * @param action The action to dispatch (can be CoreAction or any Action).
56
- */
57
- dispatch(action: CoreAction | Action): StoreState<CoreState>;
58
- /**
59
- * Returns a shallow copy of the current state.
60
- * @returns The current store state.
61
- */
62
- getState(): StoreState<CoreState>;
63
- /**
64
- * Subscribes a listener to *global* state changes.
65
- * The callback signature is now (action, newState, oldState).
66
- *
67
- * @param listener The callback to invoke on state changes
68
- * @returns A function to unsubscribe the listener
69
- */
70
- subscribe(listener: StoreListener<CoreState>): () => void;
71
- /**
72
- * Subscribes a listener to *plugin-specific* state changes.
73
- * The callback signature is now (action, newPluginState, oldPluginState).
74
- *
75
- * @param pluginId The unique identifier for the plugin.
76
- * @param listener The callback to invoke on plugin state changes.
77
- * @returns A function to unsubscribe the listener.
78
- */
79
- subscribeToPlugin(pluginId: string, listener: PluginListener): () => void;
80
- /**
81
- * Subscribes to a specific action type (only from the core's action union).
82
- * The callback signature is (action, newState, oldState).
83
- *
84
- * @param type The action type to listen for.
85
- * @param handler The callback to invoke when the action occurs.
86
- * @returns A function to unsubscribe the handler.
87
- */
88
- onAction<T extends CoreAction['type']>(type: T, handler: (action: Extract<CoreAction, {
89
- type: T;
90
- }>, state: StoreState<CoreState>, oldState: StoreState<CoreState>) => void): () => void;
91
- /**
92
- * Gets a PluginStore handle for a specific plugin.
93
- * @param pluginId The unique identifier for the plugin.
94
- * @returns A PluginStore instance for the plugin.
95
- */
96
- getPluginStore<PluginState, PluginAction extends Action>(pluginId: string): PluginStore<PluginState, PluginAction>;
97
- /**
98
- * Helper method to check if an action is a CoreAction.
99
- * Adjust if you have a more refined way to differentiate CoreAction vs. any other Action.
100
- */
101
- isCoreAction(action: Action): action is CoreAction;
102
- /**
103
- * Destroy the store: drop every listener and plugin reducer
104
- */
105
- destroy(): void;
106
- }
@@ -1,28 +0,0 @@
1
- /** Represents an action with a type and optional payload */
2
- export interface Action {
3
- type: string;
4
- payload?: any;
5
- }
6
- /** A reducer function that updates a specific state based on an action */
7
- export type Reducer<State, Action> = (state: State, action: Action) => State;
8
- /**
9
- * Represents the overall store state, with a typed core and plugin states
10
- */
11
- export interface StoreState<CoreState> {
12
- core: CoreState;
13
- plugins: Record<string, any>;
14
- }
15
- /**
16
- * The signature of a main-store listener. You now receive:
17
- * - `action` => The action that was dispatched
18
- * - `newState` => The store state *after* the update
19
- * - `oldState` => The store state *before* the update
20
- */
21
- export type StoreListener<CoreState> = (action: Action, newState: StoreState<CoreState>, oldState: StoreState<CoreState>) => void;
22
- /**
23
- * The signature of a plugin-store listener. You now receive:
24
- * - `action` => The action that was dispatched
25
- * - `newPluginState` => The plugin state *after* the update
26
- * - `oldPluginState` => The plugin state *before* the update
27
- */
28
- export type PluginListener = (action: Action, newPluginState: any, oldPluginState: any) => void;
@@ -1,21 +0,0 @@
1
- export declare class PluginRegistrationError extends Error {
2
- constructor(message: string);
3
- }
4
- export declare class PluginNotFoundError extends Error {
5
- constructor(message: string);
6
- }
7
- export declare class CircularDependencyError extends Error {
8
- constructor(message: string);
9
- }
10
- export declare class CapabilityNotFoundError extends Error {
11
- constructor(message: string);
12
- }
13
- export declare class CapabilityConflictError extends Error {
14
- constructor(message: string);
15
- }
16
- export declare class PluginInitializationError extends Error {
17
- constructor(message: string);
18
- }
19
- export declare class PluginConfigurationError extends Error {
20
- constructor(message: string);
21
- }
@@ -1,55 +0,0 @@
1
- import { PdfPermissionFlag } from '@embedpdf/models';
2
- /**
3
- * Human-readable permission names for use in configuration.
4
- */
5
- export type PermissionName = 'print' | 'modifyContents' | 'copyContents' | 'modifyAnnotations' | 'fillForms' | 'extractForAccessibility' | 'assembleDocument' | 'printHighQuality';
6
- /**
7
- * Map from human-readable names to PdfPermissionFlag values.
8
- */
9
- export declare const PERMISSION_NAME_TO_FLAG: Record<PermissionName, PdfPermissionFlag>;
10
- /**
11
- * Permission overrides can use either numeric flags or human-readable string names.
12
- */
13
- export type PermissionOverrides = Partial<Record<PdfPermissionFlag, boolean> & Record<PermissionName, boolean>>;
14
- /**
15
- * Configuration for overriding document permissions.
16
- * Can be applied globally (at PluginRegistry level) or per-document (when opening).
17
- */
18
- export interface PermissionConfig {
19
- /**
20
- * When true (default): use PDF's permissions as the base, then apply overrides.
21
- * When false: treat document as having all permissions allowed, then apply overrides.
22
- */
23
- enforceDocumentPermissions?: boolean;
24
- /**
25
- * Explicit per-flag overrides. Supports both numeric flags and string names.
26
- * - true = force allow (even if PDF denies)
27
- * - false = force deny (even if PDF allows)
28
- * - undefined = use base permissions
29
- *
30
- * @example
31
- * // Using string names (recommended)
32
- * overrides: { print: false, modifyAnnotations: true }
33
- *
34
- * @example
35
- * // Using numeric flags
36
- * overrides: { [PdfPermissionFlag.Print]: false }
37
- */
38
- overrides?: PermissionOverrides;
39
- }
40
- /**
41
- * All permission flags for iteration when computing effective permissions.
42
- */
43
- export declare const ALL_PERMISSION_FLAGS: PdfPermissionFlag[];
44
- /**
45
- * All permission names for iteration.
46
- */
47
- export declare const ALL_PERMISSION_NAMES: PermissionName[];
48
- /**
49
- * Map from PdfPermissionFlag to human-readable name.
50
- */
51
- export declare const PERMISSION_FLAG_TO_NAME: Record<PdfPermissionFlag, PermissionName>;
52
- /**
53
- * Helper to get the override value for a permission flag, checking both numeric and string keys.
54
- */
55
- export declare function getPermissionOverride(overrides: PermissionOverrides | undefined, flag: PdfPermissionFlag): boolean | undefined;
@@ -1,75 +0,0 @@
1
- import { PluginRegistry } from '../registry/plugin-registry';
2
- import { Logger, Rotation } from '@embedpdf/models';
3
- import { Action, Reducer } from '../store/types';
4
- import { CoreState } from '../store';
5
- import { PermissionConfig } from './permissions';
6
- export interface IPlugin<TConfig = unknown> {
7
- id: string;
8
- initialize?(config: TConfig): Promise<void>;
9
- destroy?(): Promise<void> | void;
10
- provides?(): any;
11
- postInitialize?(): Promise<void>;
12
- ready?(): Promise<void>;
13
- }
14
- export interface BasePluginConfig {
15
- }
16
- export interface PluginRegistryConfig {
17
- defaultRotation?: Rotation;
18
- defaultScale?: number;
19
- logger?: Logger;
20
- /**
21
- * Global permission configuration.
22
- * Applied to all documents unless overridden per-document.
23
- */
24
- permissions?: PermissionConfig;
25
- }
26
- export interface PluginManifest<TConfig = unknown> {
27
- id: string;
28
- name: string;
29
- version: string;
30
- provides: string[];
31
- requires: string[];
32
- optional: string[];
33
- defaultConfig: TConfig;
34
- metadata?: {
35
- description?: string;
36
- author?: string;
37
- homepage?: string;
38
- [key: string]: unknown;
39
- };
40
- }
41
- export interface PluginPackage<T extends IPlugin<TConfig>, TConfig = unknown, TState = unknown, TAction extends Action = Action> {
42
- manifest: PluginManifest<TConfig>;
43
- create(registry: PluginRegistry, config: TConfig): T;
44
- reducer: Reducer<TState, TAction>;
45
- initialState: TState | ((coreState: CoreState, config: TConfig) => TState);
46
- }
47
- export type Component = any;
48
- export type StandaloneComponent = Component;
49
- export type ContainerComponent = Component;
50
- export type AutoMountElement = {
51
- component: StandaloneComponent;
52
- type: 'utility';
53
- } | {
54
- component: ContainerComponent;
55
- type: 'wrapper';
56
- };
57
- export type WithAutoMount<T extends PluginPackage<any, any, any, any>> = T & {
58
- /**
59
- * Returns an array of components/elements with their mount type.
60
- * - 'utility': Mounted as hidden DOM elements (file pickers, download anchors)
61
- * - 'wrapper': Wraps the viewer content (fullscreen providers, theme providers)
62
- */
63
- autoMountElements: () => AutoMountElement[];
64
- };
65
- export declare function hasAutoMountElements<T extends PluginPackage<any, any, any, any>>(pkg: T): pkg is WithAutoMount<T>;
66
- export type PluginStatus = 'registered' | 'active' | 'error' | 'disabled' | 'unregistered';
67
- export interface PluginBatchRegistration<T extends IPlugin<TConfig>, TConfig = unknown, TState = unknown, TAction extends Action = Action> {
68
- package: PluginPackage<T, TConfig, TState, TAction>;
69
- config?: Partial<TConfig>;
70
- }
71
- export type PluginBatchRegistrations = PluginBatchRegistration<IPlugin<any>, any>[];
72
- export interface GlobalStoreState<TPlugins extends Record<string, any> = {}> {
73
- core: CoreState;
74
- plugins: TPlugins;
75
- }
@@ -1,6 +0,0 @@
1
- export declare class DependencyResolver {
2
- private dependencyGraph;
3
- addNode(id: string, dependencies?: string[]): void;
4
- private hasCircularDependencies;
5
- resolveLoadOrder(): string[];
6
- }
@@ -1,58 +0,0 @@
1
- export type EventHandler<T> = (data: T) => void;
2
- export interface BaseEventControlOptions {
3
- wait: number;
4
- }
5
- export interface DebounceOptions extends BaseEventControlOptions {
6
- mode: 'debounce';
7
- }
8
- export interface ThrottleOptions extends BaseEventControlOptions {
9
- mode: 'throttle';
10
- throttleMode?: 'leading-trailing' | 'trailing';
11
- }
12
- export interface KeyedDebounceOptions<T> extends BaseEventControlOptions {
13
- mode: 'debounce';
14
- keyExtractor: (data: T) => string | number;
15
- }
16
- export interface KeyedThrottleOptions<T> extends BaseEventControlOptions {
17
- mode: 'throttle';
18
- throttleMode?: 'leading-trailing' | 'trailing';
19
- keyExtractor: (data: T) => string | number;
20
- }
21
- export type EventControlOptions<T = any> = DebounceOptions | ThrottleOptions | KeyedDebounceOptions<T> | KeyedThrottleOptions<T>;
22
- export declare class EventControl<T> {
23
- private handler;
24
- private options;
25
- private timeoutId?;
26
- private lastRun;
27
- constructor(handler: EventHandler<T>, options: DebounceOptions | ThrottleOptions);
28
- handle: (data: T) => void;
29
- private debounce;
30
- private throttle;
31
- destroy(): void;
32
- }
33
- /**
34
- * Event control with independent debouncing/throttling per key.
35
- * Useful when events carry a discriminator (like documentId) and
36
- * you want to debounce/throttle each key's events independently.
37
- *
38
- * @example
39
- * // Debounce viewport resize events independently per document
40
- * const control = new KeyedEventControl(
41
- * (event) => recalcZoom(event.documentId),
42
- * { mode: 'debounce', wait: 150, keyExtractor: (e) => e.documentId }
43
- * );
44
- * control.handle(event); // Each documentId gets its own 150ms debounce
45
- */
46
- export declare class KeyedEventControl<T> {
47
- private handler;
48
- private options;
49
- private controls;
50
- private readonly baseOptions;
51
- constructor(handler: EventHandler<T>, options: KeyedDebounceOptions<T> | KeyedThrottleOptions<T>);
52
- handle: (data: T) => void;
53
- destroy(): void;
54
- }
55
- /**
56
- * Type guard to check if options are keyed
57
- */
58
- export declare function isKeyedOptions<T>(options: EventControlOptions<T>): options is KeyedDebounceOptions<T> | KeyedThrottleOptions<T>;
@@ -1,19 +0,0 @@
1
- import { EventControlOptions } from './event-control';
2
- export type Listener<T = any> = (value: T) => void;
3
- export type Unsubscribe = () => void;
4
- export type EventListener<T> = ((listener: Listener<T>) => Unsubscribe) | ((listener: Listener<T>, options?: EventControlOptions<T>) => Unsubscribe);
5
- export type EventHook<T = any> = EventListener<T>;
6
- export interface Emitter<T = any> {
7
- emit(value?: T): void;
8
- on(listener: Listener<T>): Unsubscribe;
9
- off(listener: Listener<T>): void;
10
- clear(): void;
11
- }
12
- export declare function createEmitter<T = any>(): Emitter<T>;
13
- export interface BehaviorEmitter<T = any> extends Omit<Emitter<T>, 'on' | 'off'> {
14
- readonly value?: T;
15
- on: EventHook<T>;
16
- off(listener: Listener<T>): void;
17
- select<U>(selector: (v: T) => U, equality?: (a: U, b: U) => boolean): EventHook<U>;
18
- }
19
- export declare function createBehaviorEmitter<T = any>(initial?: T, equality?: (a: T, b: T) => boolean): BehaviorEmitter<T>;
@@ -1,22 +0,0 @@
1
- /**
2
- * Restrict a numeric value to the inclusive range [min, max].
3
- *
4
- * @example
5
- * clamp( 5, 0, 10) // 5
6
- * clamp(-3, 0, 10) // 0
7
- * clamp(17, 0, 10) // 10
8
- */
9
- export declare function clamp(value: number, min: number, max: number): number;
10
- /**
11
- * Deeply compares two values (objects, arrays, primitives)
12
- * with the following rules:
13
- * - Objects are compared ignoring property order.
14
- * - Arrays are compared ignoring element order (multiset comparison).
15
- * - Primitives are compared by strict equality.
16
- * - null/undefined are treated as normal primitives.
17
- *
18
- * @param a First value
19
- * @param b Second value
20
- * @param visited Used internally to detect cycles
21
- */
22
- export declare function arePropsEqual(a: any, b: any, visited?: Set<any>): boolean;
@@ -1,6 +0,0 @@
1
- import { Action } from '../store';
2
- import { IPlugin, PluginBatchRegistration, PluginPackage } from '../types/plugin';
3
- /**
4
- * Helper function to create a properly typed plugin registration
5
- */
6
- export 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>;
@@ -1,71 +0,0 @@
1
- import { EventHook } from './eventing';
2
- /**
3
- * A scoped behavior emitter that maintains separate cached values
4
- * and listener sets per scope key.
5
- *
6
- * @typeParam TData - The scoped data type (without key context)
7
- * @typeParam TGlobalEvent - The global event type (includes key context)
8
- * @typeParam TKey - The key type (string, number, or both)
9
- */
10
- export interface ScopedEmitter<TData = any, TGlobalEvent = {
11
- key: string;
12
- data: TData;
13
- }, TKey extends string | number = string | number> {
14
- /**
15
- * Emit an event for a specific scope key.
16
- */
17
- emit(key: TKey, data: TData): void;
18
- /**
19
- * Get a scoped event hook that only receives events for this key.
20
- */
21
- forScope(key: TKey): EventHook<TData>;
22
- /**
23
- * Global event hook that receives events from all scopes.
24
- */
25
- readonly onGlobal: EventHook<TGlobalEvent>;
26
- /**
27
- * Clear all scopes' caches and listeners
28
- */
29
- clear(): void;
30
- /**
31
- * Clear a specific scope's cache and listeners
32
- */
33
- clearScope(key: TKey): void;
34
- /**
35
- * Get the current cached value for a specific scope
36
- */
37
- getValue(key: TKey): TData | undefined;
38
- /**
39
- * Get all active scope keys
40
- */
41
- getScopes(): TKey[];
42
- }
43
- /**
44
- * Creates a scoped emitter with optional caching behavior.
45
- *
46
- * @param toGlobalEvent - Transform function to convert (key, data) into a global event
47
- * @param options - Configuration options
48
- * @param options.cache - Whether to cache values per scope (default: true)
49
- * @param options.equality - Equality function for cached values (default: arePropsEqual)
50
- *
51
- * @example
52
- * ```typescript
53
- * // With caching (stateful) - default behavior
54
- * const window$ = createScopedEmitter<WindowState, WindowChangeEvent, string>(
55
- * (documentId, window) => ({ documentId, window })
56
- * );
57
- *
58
- * // Without caching (transient events)
59
- * const refreshPages$ = createScopedEmitter<number[], RefreshPagesEvent, string>(
60
- * (documentId, pages) => ({ documentId, pages }),
61
- * { cache: false }
62
- * );
63
- * ```
64
- */
65
- export declare function createScopedEmitter<TData = any, TGlobalEvent = {
66
- key: string;
67
- data: TData;
68
- }, TKey extends string | number = string | number>(toGlobalEvent: (key: TKey, data: TData) => TGlobalEvent, options?: {
69
- cache?: boolean;
70
- equality?: (a: TData, b: TData) => boolean;
71
- }): ScopedEmitter<TData, TGlobalEvent, TKey>;
@@ -1,12 +0,0 @@
1
- type EnumKey = string | number;
2
- /**
3
- * Iterate over a Record whose keys are enum members (numeric or string),
4
- * getting back a fully-typed `[key, value]` tuple array.
5
- *
6
- * Usage:
7
- * for (const [subtype, defaults] of enumEntries(this.state.toolDefaults)) {
8
- * // subtype is inferred as keyof ToolDefaultsBySubtype
9
- * }
10
- */
11
- export declare function enumEntries<E extends EnumKey, V>(record: Record<E, V>): Array<[E, V]>;
12
- export {};
@@ -1,11 +0,0 @@
1
- import { createContext, JSX, Fragment, FunctionComponent } from 'preact';
2
- export { useEffect, useRef, useState, useCallback, useMemo, useContext } from 'preact/hooks';
3
- export type { ComponentChildren as ReactNode, JSX } from 'preact';
4
- export { createContext, Fragment };
5
- export type CSSProperties = import('preact').JSX.CSSProperties;
6
- export type HTMLAttributes<T = any> = import('preact').JSX.HTMLAttributes<T extends EventTarget ? T : never>;
7
- export type MouseEvent<T = Element> = JSX.TargetedMouseEvent<T extends EventTarget ? T : never>;
8
- export type PointerEvent<T = Element> = JSX.TargetedPointerEvent<T extends EventTarget ? T : never>;
9
- export type ChangeEvent<T = Element> = JSX.TargetedInputEvent<T extends EventTarget ? T : never>;
10
- export type TouchEvent<T = Element> = JSX.TargetedTouchEvent<T extends EventTarget ? T : never>;
11
- export type ComponentType<P = any> = FunctionComponent<P>;
@@ -1,2 +0,0 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("preact"),n=require("preact/hooks"),i=require("preact/jsx-runtime"),t=require("@embedpdf/core"),s=require("@embedpdf/models"),o=e.createContext({registry:null,coreState:null,isInitializing:!0,pluginsReady:!1,activeDocumentId:null,activeDocument:null,documents:{},documentStates:[]});function r({plugins:s,children:o}){const{utilities:r,wrappers:l}=n.useMemo(()=>{const e=[],n=[];for(const i of s){const s=i.package;if(t.hasAutoMountElements(s)){const i=s.autoMountElements()||[];for(const t of i)"utility"===t.type?e.push(t.component):"wrapper"===t.type&&n.push(t.component)}}return{utilities:e,wrappers:n}},[s]),u=i.jsxs(e.Fragment,{children:[o,r.map((e,n)=>i.jsx(e,{},`utility-${n}`))]}),a=l.reduce((e,n)=>i.jsx(n,{children:e}),u);return i.jsx(e.Fragment,{children:a})}function l(){const e=n.useContext(o);if(void 0===e)throw new Error("useCapability must be used within a PDFContext.Provider");const{registry:i,isInitializing:t}=e;if(t)return e;if(null===i)throw new Error("PDF registry failed to initialize properly");return e}function u(e){const{registry:n}=l();if(null===n)return{plugin:null,isLoading:!0,ready:new Promise(()=>{})};const i=n.getPlugin(e);if(!i)throw new Error(`Plugin ${e} not found`);return{plugin:i,isLoading:!1,ready:i.ready()}}function a(){const{coreState:e}=n.useContext(o);return e}s.PdfPermissionFlag.Print,s.PdfPermissionFlag.ModifyContents,s.PdfPermissionFlag.CopyContents,s.PdfPermissionFlag.ModifyAnnotations,s.PdfPermissionFlag.FillForms,s.PdfPermissionFlag.ExtractForAccessibility,s.PdfPermissionFlag.AssembleDocument,s.PdfPermissionFlag.PrintHighQuality;const c=[s.PdfPermissionFlag.Print,s.PdfPermissionFlag.ModifyContents,s.PdfPermissionFlag.CopyContents,s.PdfPermissionFlag.ModifyAnnotations,s.PdfPermissionFlag.FillForms,s.PdfPermissionFlag.ExtractForAccessibility,s.PdfPermissionFlag.AssembleDocument,s.PdfPermissionFlag.PrintHighQuality],d={[s.PdfPermissionFlag.Print]:"print",[s.PdfPermissionFlag.ModifyContents]:"modifyContents",[s.PdfPermissionFlag.CopyContents]:"copyContents",[s.PdfPermissionFlag.ModifyAnnotations]:"modifyAnnotations",[s.PdfPermissionFlag.FillForms]:"fillForms",[s.PdfPermissionFlag.ExtractForAccessibility]:"extractForAccessibility",[s.PdfPermissionFlag.AssembleDocument]:"assembleDocument",[s.PdfPermissionFlag.PrintHighQuality]:"printHighQuality"};function m(e,n){if(!e)return;if(n in e)return e[n];const i=d[n];return i&&i in e?e[i]:void 0}function P(e,n,i){var t;const o=e.documents[n],r=null==o?void 0:o.permissions,l=e.globalPermissions,u=(null==(t=null==o?void 0:o.document)?void 0:t.permissions)??s.PdfPermissionFlag.AllowAll,a=m(null==r?void 0:r.overrides,i);if(void 0!==a)return a;const c=m(null==l?void 0:l.overrides,i);if(void 0!==c)return c;return!((null==r?void 0:r.enforceDocumentPermissions)??(null==l?void 0:l.enforceDocumentPermissions)??!0)||0!==(u&i)}exports.EmbedPDF=function({engine:e,config:s,logger:l,onInitialized:u,plugins:a,children:c,autoMountDomElements:d=!0}){const[m,P]=n.useState(null),[f,g]=n.useState(null),[y,p]=n.useState(!0),[F,v]=n.useState(!1),A=n.useRef(u);n.useEffect(()=>{A.current=u},[u]),n.useEffect(()=>{const n={...s,logger:(null==s?void 0:s.logger)??l},i=new t.PluginRegistry(e,n);i.registerPluginBatch(a);let o;return(async()=>{var e;if(await i.initialize(),i.isDestroyed())return;const n=i.getStore();g(n.getState().core);const t=n.subscribe((e,i,t)=>{n.isCoreAction(e)&&i.core!==t.core&&g(i.core)});if(await(null==(e=A.current)?void 0:e.call(A,i)),!i.isDestroyed())return i.pluginsReady().then(()=>{i.isDestroyed()||v(!0)}),P(i),p(!1),t;t()})().then(e=>{o=e}).catch(console.error),()=>{null==o||o(),i.destroy(),P(null),g(null),p(!0),v(!1)}},[e,a]);const h=n.useMemo(()=>{const e=(null==f?void 0:f.activeDocumentId)??null,n=(null==f?void 0:f.documents)??{},i=(null==f?void 0:f.documentOrder)??[],t=e&&n[e]?n[e]:null,s=i.map(e=>n[e]).filter(e=>null!=e);return{registry:m,coreState:f,isInitializing:y,pluginsReady:F,activeDocumentId:e,activeDocument:t,documents:n,documentStates:s}},[m,f,y,F]),x="function"==typeof c?c(h):c;return i.jsx(o.Provider,{value:h,children:F&&d?i.jsx(r,{plugins:a,children:x}):x})},exports.PDFContext=o,exports.useCapability=function(e){const{plugin:n,isLoading:i,ready:t}=u(e);if(!n)return{provides:null,isLoading:i,ready:t};if(!n.provides)throw new Error(`Plugin ${e} does not provide a capability`);return{provides:n.provides(),isLoading:i,ready:t}},exports.useCoreState=a,exports.useDocumentPermissions=function(e){const i=a();return n.useMemo(()=>{var n,t;if(!i)return{permissions:s.PdfPermissionFlag.AllowAll,pdfPermissions:s.PdfPermissionFlag.AllowAll,hasPermission:()=>!0,hasAllPermissions:()=>!0,canPrint:!0,canModifyContents:!0,canCopyContents:!0,canModifyAnnotations:!0,canFillForms:!0,canExtractForAccessibility:!0,canAssembleDocument:!0,canPrintHighQuality:!0};const o=function(e,n){return c.reduce((i,t)=>P(e,n,t)?i|t:i,0)}(i,e),r=n=>P(i,e,n);return{permissions:o,pdfPermissions:(null==(t=null==(n=i.documents[e])?void 0:n.document)?void 0:t.permissions)??s.PdfPermissionFlag.AllowAll,hasPermission:r,hasAllPermissions:(...n)=>n.every(n=>P(i,e,n)),canPrint:r(s.PdfPermissionFlag.Print),canModifyContents:r(s.PdfPermissionFlag.ModifyContents),canCopyContents:r(s.PdfPermissionFlag.CopyContents),canModifyAnnotations:r(s.PdfPermissionFlag.ModifyAnnotations),canFillForms:r(s.PdfPermissionFlag.FillForms),canExtractForAccessibility:r(s.PdfPermissionFlag.ExtractForAccessibility),canAssembleDocument:r(s.PdfPermissionFlag.AssembleDocument),canPrintHighQuality:r(s.PdfPermissionFlag.PrintHighQuality)}},[i,e])},exports.useDocumentState=function(e){const i=a();return n.useMemo(()=>i&&e?i.documents[e]??null:null,[i,e])},exports.usePlugin=u,exports.useRegistry=l,exports.useStoreState=function(){const{registry:e}=l(),[i,t]=n.useState(null);return n.useEffect(()=>{if(!e)return;t(e.getStore().getState());const n=e.getStore().subscribe((e,n)=>{t(n)});return()=>n()},[e]),i};
2
- //# sourceMappingURL=index.cjs.map