@embedpdf/core 2.3.0 → 2.4.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.
- package/dist/preact/index.cjs +1 -1
- package/dist/preact/index.cjs.map +1 -1
- package/dist/preact/index.js +7 -6
- package/dist/preact/index.js.map +1 -1
- package/dist/react/index.cjs +1 -1
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.js +7 -6
- package/dist/react/index.js.map +1 -1
- package/dist/svelte/components/NestedWrapper.svelte.d.ts +1 -0
- package/dist/svelte/index.cjs +1 -1
- package/dist/svelte/index.cjs.map +1 -1
- package/dist/svelte/index.js +30 -13
- package/dist/svelte/index.js.map +1 -1
- package/dist/vue/components/auto-mount.vue.d.ts +3 -3
- package/dist/vue/components/nested-wrapper.vue.d.ts +1 -0
- package/dist/vue/index.cjs +1 -1
- package/dist/vue/index.cjs.map +1 -1
- package/dist/vue/index.js +25 -15
- package/dist/vue/index.js.map +1 -1
- package/package.json +3 -3
package/dist/react/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createContext, useMemo, Fragment, useState, useRef, useEffect, useContext } from "react";
|
|
2
|
-
import {
|
|
2
|
+
import { jsxs, jsx } from "react/jsx-runtime";
|
|
3
3
|
import { hasAutoMountElements, PluginRegistry } from "@embedpdf/core";
|
|
4
4
|
import { PdfPermissionFlag } from "@embedpdf/models";
|
|
5
5
|
const PDFContext = createContext({
|
|
@@ -31,14 +31,15 @@ function AutoMount({ plugins, children }) {
|
|
|
31
31
|
}
|
|
32
32
|
return { utilities: utilities2, wrappers: wrappers2 };
|
|
33
33
|
}, [plugins]);
|
|
34
|
+
const contentWithUtilities = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
35
|
+
children,
|
|
36
|
+
utilities.map((Utility, i) => /* @__PURE__ */ jsx(Utility, {}, `utility-${i}`))
|
|
37
|
+
] });
|
|
34
38
|
const wrappedContent = wrappers.reduce(
|
|
35
39
|
(content, Wrapper) => /* @__PURE__ */ jsx(Wrapper, { children: content }),
|
|
36
|
-
|
|
40
|
+
contentWithUtilities
|
|
37
41
|
);
|
|
38
|
-
return /* @__PURE__ */
|
|
39
|
-
wrappedContent,
|
|
40
|
-
utilities.map((Utility, i) => /* @__PURE__ */ jsx(Utility, {}, `utility-${i}`))
|
|
41
|
-
] });
|
|
42
|
+
return /* @__PURE__ */ jsx(Fragment, { children: wrappedContent });
|
|
42
43
|
}
|
|
43
44
|
function EmbedPDF({
|
|
44
45
|
engine,
|
package/dist/react/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/shared/context.ts","../../src/shared/components/auto-mount.tsx","../../src/shared/components/embed-pdf.tsx","../../src/shared/hooks/use-registry.ts","../../src/shared/hooks/use-plugin.ts","../../src/shared/hooks/use-capability.ts","../../src/shared/hooks/use-store-state.ts","../../src/shared/hooks/use-core-state.ts","../../src/shared/hooks/use-document-state.ts","../../src/lib/types/permissions.ts","../../src/lib/store/selectors.ts","../../src/shared/hooks/use-document-permissions.ts"],"sourcesContent":["import { createContext } from '@framework';\nimport type { CoreState, DocumentState, PluginRegistry } from '@embedpdf/core';\n\nexport interface PDFContextState {\n registry: PluginRegistry | null;\n coreState: CoreState | null;\n isInitializing: boolean;\n pluginsReady: boolean;\n\n // Convenience accessors (always safe to use)\n activeDocumentId: string | null;\n activeDocument: DocumentState | null;\n documents: Record<string, DocumentState>;\n documentStates: DocumentState[];\n}\n\nexport const PDFContext = createContext<PDFContextState>({\n registry: null,\n coreState: null,\n isInitializing: true,\n pluginsReady: false,\n activeDocumentId: null,\n activeDocument: null,\n documents: {},\n documentStates: [],\n});\n","import { Fragment, useMemo, ComponentType, ReactNode } from '@framework';\nimport { hasAutoMountElements } from '@embedpdf/core';\nimport type { PluginBatchRegistration, IPlugin } from '@embedpdf/core';\n\ninterface AutoMountProps {\n plugins: PluginBatchRegistration<IPlugin<any>, any>[];\n children: ReactNode;\n}\n\nexport function AutoMount({ plugins, children }: AutoMountProps) {\n const { utilities, wrappers } = useMemo(() => {\n // React-specific types for internal use\n const utilities: ComponentType[] = [];\n const wrappers: ComponentType<{ children: ReactNode }>[] = [];\n\n for (const reg of plugins) {\n const pkg = reg.package;\n if (hasAutoMountElements(pkg)) {\n const elements = pkg.autoMountElements() || [];\n\n for (const element of elements) {\n if (element.type === 'utility') {\n utilities.push(element.component);\n } else if (element.type === 'wrapper') {\n // In React context, we know wrappers need children\n wrappers.push(element.component);\n }\n }\n }\n }\n return { utilities, wrappers };\n }, [plugins]);\n\n // React-specific wrapping logic\n const wrappedContent = wrappers.reduce(\n (content, Wrapper) => <Wrapper>{content}</Wrapper>,\n children,\n );\n\n return (\n <Fragment>\n {wrappedContent}\n {utilities.map((Utility, i) => (\n <Utility key={`utility-${i}`} />\n ))}\n </Fragment>\n );\n}\n","import { useState, useEffect, useRef, useMemo, ReactNode } from '@framework';\nimport { Logger, PdfEngine } from '@embedpdf/models';\nimport { PluginRegistry, CoreState, DocumentState, PluginRegistryConfig } from '@embedpdf/core';\nimport type { PluginBatchRegistrations } from '@embedpdf/core';\n\nimport { PDFContext, PDFContextState } from '../context';\nimport { AutoMount } from './auto-mount';\n\nexport type { PluginBatchRegistrations };\n\ninterface EmbedPDFProps {\n /**\n * The PDF engine to use for the PDF viewer.\n */\n engine: PdfEngine;\n /**\n * Registry configuration including logger, permissions, and defaults.\n */\n config?: PluginRegistryConfig;\n /**\n * @deprecated Use config.logger instead. Will be removed in next major version.\n */\n logger?: Logger;\n /**\n * The callback to call when the PDF viewer is initialized.\n */\n onInitialized?: (registry: PluginRegistry) => Promise<void>;\n /**\n * The plugins to use for the PDF viewer.\n */\n plugins: PluginBatchRegistrations;\n /**\n * The children to render for the PDF viewer.\n */\n children: ReactNode | ((state: PDFContextState) => ReactNode);\n /**\n * Whether to auto-mount specific non-visual DOM elements from plugins.\n * @default true\n */\n autoMountDomElements?: boolean;\n}\n\nexport function EmbedPDF({\n engine,\n config,\n logger,\n onInitialized,\n plugins,\n children,\n autoMountDomElements = true,\n}: EmbedPDFProps) {\n const [registry, setRegistry] = useState<PluginRegistry | null>(null);\n const [coreState, setCoreState] = useState<CoreState | null>(null);\n const [isInitializing, setIsInitializing] = useState<boolean>(true);\n const [pluginsReady, setPluginsReady] = useState<boolean>(false);\n const initRef = useRef<EmbedPDFProps['onInitialized']>(onInitialized);\n\n useEffect(() => {\n initRef.current = onInitialized;\n }, [onInitialized]);\n\n useEffect(() => {\n // Merge deprecated logger prop into config (config.logger takes precedence)\n const finalConfig: PluginRegistryConfig = {\n ...config,\n logger: config?.logger ?? logger,\n };\n const pdfViewer = new PluginRegistry(engine, finalConfig);\n pdfViewer.registerPluginBatch(plugins);\n\n const initialize = async () => {\n await pdfViewer.initialize();\n\n if (pdfViewer.isDestroyed()) {\n return;\n }\n\n const store = pdfViewer.getStore();\n setCoreState(store.getState().core);\n\n const unsubscribe = store.subscribe((action, newState, oldState) => {\n // Only update if it's a core action and the core state changed\n if (store.isCoreAction(action) && newState.core !== oldState.core) {\n setCoreState(newState.core);\n }\n });\n\n /* always call the *latest* callback */\n await initRef.current?.(pdfViewer);\n\n if (pdfViewer.isDestroyed()) {\n unsubscribe();\n return;\n }\n\n pdfViewer.pluginsReady().then(() => {\n if (!pdfViewer.isDestroyed()) {\n setPluginsReady(true);\n }\n });\n\n // Provide the registry to children via context\n setRegistry(pdfViewer);\n setIsInitializing(false);\n\n // Return cleanup function\n return unsubscribe;\n };\n\n let cleanup: (() => void) | undefined;\n initialize()\n .then((unsub) => {\n cleanup = unsub;\n })\n .catch(console.error);\n\n return () => {\n cleanup?.();\n pdfViewer.destroy();\n setRegistry(null);\n setCoreState(null);\n setIsInitializing(true);\n setPluginsReady(false);\n };\n }, [engine, plugins]);\n\n // Compute convenience accessors\n const contextValue: PDFContextState = useMemo(() => {\n const activeDocumentId = coreState?.activeDocumentId ?? null;\n const documents = coreState?.documents ?? {};\n const documentOrder = coreState?.documentOrder ?? [];\n\n // Compute active document\n const activeDocument =\n activeDocumentId && documents[activeDocumentId] ? documents[activeDocumentId] : null;\n\n // Compute open documents in order\n const documentStates = documentOrder\n .map((docId) => documents[docId])\n .filter((doc): doc is DocumentState => doc !== null && doc !== undefined);\n\n return {\n registry,\n coreState,\n isInitializing,\n pluginsReady,\n // Convenience accessors (always safe to use)\n activeDocumentId,\n activeDocument,\n documents,\n documentStates,\n };\n }, [registry, coreState, isInitializing, pluginsReady]);\n\n const content = typeof children === 'function' ? children(contextValue) : children;\n\n return (\n <PDFContext.Provider value={contextValue}>\n {pluginsReady && autoMountDomElements ? (\n <AutoMount plugins={plugins}>{content}</AutoMount>\n ) : (\n content\n )}\n </PDFContext.Provider>\n );\n}\n","import { useContext } from '@framework';\nimport { PDFContext, PDFContextState } from '../context';\n\n/**\n * Hook to access the PDF registry.\n * @returns The PDF registry or null during initialization\n */\nexport function useRegistry(): PDFContextState {\n const contextValue = useContext(PDFContext);\n\n // Error if used outside of context\n if (contextValue === undefined) {\n throw new Error('useCapability must be used within a PDFContext.Provider');\n }\n\n const { registry, isInitializing } = contextValue;\n\n // During initialization, return null instead of throwing an error\n if (isInitializing) {\n return contextValue;\n }\n\n // At this point, initialization is complete but registry is still null, which is unexpected\n if (registry === null) {\n throw new Error('PDF registry failed to initialize properly');\n }\n\n return contextValue;\n}\n","import type { BasePlugin } from '@embedpdf/core';\nimport { useRegistry } from './use-registry';\n\ntype PluginState<T extends BasePlugin> = {\n plugin: T | null;\n isLoading: boolean;\n ready: Promise<void>;\n};\n\n/**\n * Hook to access a plugin.\n * @param pluginId The ID of the plugin to access\n * @returns The plugin or null during initialization\n * @example\n * // Get zoom plugin\n * const zoom = usePlugin<ZoomPlugin>(ZoomPlugin.id);\n */\nexport function usePlugin<T extends BasePlugin>(pluginId: T['id']): PluginState<T> {\n const { registry } = useRegistry();\n\n if (registry === null) {\n return {\n plugin: null,\n isLoading: true,\n ready: new Promise(() => {}),\n };\n }\n\n const plugin = registry.getPlugin<T>(pluginId);\n\n if (!plugin) {\n throw new Error(`Plugin ${pluginId} not found`);\n }\n\n return {\n plugin,\n isLoading: false,\n ready: plugin.ready(),\n };\n}\n","import type { BasePlugin } from '@embedpdf/core';\nimport { usePlugin } from './use-plugin';\n\ntype CapabilityState<T extends BasePlugin> = {\n provides: ReturnType<NonNullable<T['provides']>> | null;\n isLoading: boolean;\n ready: Promise<void>;\n};\n\n/**\n * Hook to access a plugin's capability.\n * @param pluginId The ID of the plugin to access\n * @returns The capability provided by the plugin or null during initialization\n * @example\n * // Get zoom capability\n * const zoom = useCapability<ZoomPlugin>(ZoomPlugin.id);\n */\nexport function useCapability<T extends BasePlugin>(pluginId: T['id']): CapabilityState<T> {\n const { plugin, isLoading, ready } = usePlugin<T>(pluginId);\n\n if (!plugin) {\n return {\n provides: null,\n isLoading,\n ready,\n };\n }\n\n if (!plugin.provides) {\n throw new Error(`Plugin ${pluginId} does not provide a capability`);\n }\n\n return {\n provides: plugin.provides() as ReturnType<NonNullable<T['provides']>>,\n isLoading,\n ready,\n };\n}\n","import { useState, useEffect } from '@framework';\nimport { CoreState, StoreState } from '@embedpdf/core';\nimport { useRegistry } from './use-registry';\n\n/**\n * Hook that provides access to the current global store state\n * and re-renders the component when the state changes\n */\nexport function useStoreState<T = CoreState>(): StoreState<T> | null {\n const { registry } = useRegistry();\n const [state, setState] = useState<StoreState<T> | null>(null);\n\n useEffect(() => {\n if (!registry) return;\n\n // Get initial state\n setState(registry.getStore().getState() as StoreState<T>);\n\n // Subscribe to store changes\n const unsubscribe = registry.getStore().subscribe((_action, newState) => {\n setState(newState as StoreState<T>);\n });\n\n return () => unsubscribe();\n }, [registry]);\n\n return state;\n}\n","import { useContext } from '@framework';\nimport { CoreState } from '@embedpdf/core';\nimport { PDFContext } from '../context';\n\n/**\n * Hook that provides access to the current core state.\n *\n * Note: This reads from the context which is already subscribed to core state changes\n * in the EmbedPDF component, so there's no additional subscription overhead.\n */\nexport function useCoreState(): CoreState | null {\n const { coreState } = useContext(PDFContext);\n return coreState;\n}\n","import { useMemo } from '@framework';\nimport { DocumentState } from '@embedpdf/core';\nimport { useCoreState } from './use-core-state';\n\n/**\n * Hook that provides reactive access to a specific document's state from the core store.\n *\n * @param documentId The ID of the document to retrieve.\n * @returns The reactive DocumentState object or null if not found.\n */\nexport function useDocumentState(documentId: string | null): DocumentState | null {\n const coreState = useCoreState();\n\n const documentState = useMemo(() => {\n if (!coreState || !documentId) return null;\n return coreState.documents[documentId] ?? null;\n }, [coreState, documentId]);\n\n return documentState;\n}\n","import { PdfPermissionFlag } from '@embedpdf/models';\n\n/**\n * Human-readable permission names for use in configuration.\n */\nexport type PermissionName =\n | 'print'\n | 'modifyContents'\n | 'copyContents'\n | 'modifyAnnotations'\n | 'fillForms'\n | 'extractForAccessibility'\n | 'assembleDocument'\n | 'printHighQuality';\n\n/**\n * Map from human-readable names to PdfPermissionFlag values.\n */\nexport const PERMISSION_NAME_TO_FLAG: Record<PermissionName, PdfPermissionFlag> = {\n print: PdfPermissionFlag.Print,\n modifyContents: PdfPermissionFlag.ModifyContents,\n copyContents: PdfPermissionFlag.CopyContents,\n modifyAnnotations: PdfPermissionFlag.ModifyAnnotations,\n fillForms: PdfPermissionFlag.FillForms,\n extractForAccessibility: PdfPermissionFlag.ExtractForAccessibility,\n assembleDocument: PdfPermissionFlag.AssembleDocument,\n printHighQuality: PdfPermissionFlag.PrintHighQuality,\n};\n\n/**\n * Permission overrides can use either numeric flags or human-readable string names.\n */\nexport type PermissionOverrides = Partial<\n Record<PdfPermissionFlag, boolean> & Record<PermissionName, boolean>\n>;\n\n/**\n * Configuration for overriding document permissions.\n * Can be applied globally (at PluginRegistry level) or per-document (when opening).\n */\nexport interface PermissionConfig {\n /**\n * When true (default): use PDF's permissions as the base, then apply overrides.\n * When false: treat document as having all permissions allowed, then apply overrides.\n */\n enforceDocumentPermissions?: boolean;\n\n /**\n * Explicit per-flag overrides. Supports both numeric flags and string names.\n * - true = force allow (even if PDF denies)\n * - false = force deny (even if PDF allows)\n * - undefined = use base permissions\n *\n * @example\n * // Using string names (recommended)\n * overrides: { print: false, modifyAnnotations: true }\n *\n * @example\n * // Using numeric flags\n * overrides: { [PdfPermissionFlag.Print]: false }\n */\n overrides?: PermissionOverrides;\n}\n\n/**\n * All permission flags for iteration when computing effective permissions.\n */\nexport const ALL_PERMISSION_FLAGS: PdfPermissionFlag[] = [\n PdfPermissionFlag.Print,\n PdfPermissionFlag.ModifyContents,\n PdfPermissionFlag.CopyContents,\n PdfPermissionFlag.ModifyAnnotations,\n PdfPermissionFlag.FillForms,\n PdfPermissionFlag.ExtractForAccessibility,\n PdfPermissionFlag.AssembleDocument,\n PdfPermissionFlag.PrintHighQuality,\n];\n\n/**\n * All permission names for iteration.\n */\nexport const ALL_PERMISSION_NAMES: PermissionName[] = [\n 'print',\n 'modifyContents',\n 'copyContents',\n 'modifyAnnotations',\n 'fillForms',\n 'extractForAccessibility',\n 'assembleDocument',\n 'printHighQuality',\n];\n\n/**\n * Map from PdfPermissionFlag to human-readable name.\n */\nexport const PERMISSION_FLAG_TO_NAME: Record<PdfPermissionFlag, PermissionName> = {\n [PdfPermissionFlag.Print]: 'print',\n [PdfPermissionFlag.ModifyContents]: 'modifyContents',\n [PdfPermissionFlag.CopyContents]: 'copyContents',\n [PdfPermissionFlag.ModifyAnnotations]: 'modifyAnnotations',\n [PdfPermissionFlag.FillForms]: 'fillForms',\n [PdfPermissionFlag.ExtractForAccessibility]: 'extractForAccessibility',\n [PdfPermissionFlag.AssembleDocument]: 'assembleDocument',\n [PdfPermissionFlag.PrintHighQuality]: 'printHighQuality',\n};\n\n/**\n * Helper to get the override value for a permission flag, checking both numeric and string keys.\n */\nexport function getPermissionOverride(\n overrides: PermissionOverrides | undefined,\n flag: PdfPermissionFlag,\n): boolean | undefined {\n if (!overrides) return undefined;\n\n // Check numeric key first\n if (flag in overrides) {\n return (overrides as Record<PdfPermissionFlag, boolean>)[flag];\n }\n\n // Check string key\n const name = PERMISSION_FLAG_TO_NAME[flag];\n if (name && name in overrides) {\n return (overrides as Record<PermissionName, boolean>)[name];\n }\n\n return undefined;\n}\n","import { PdfPermissionFlag } from '@embedpdf/models';\nimport { CoreState, DocumentState } from './initial-state';\nimport { ALL_PERMISSION_FLAGS, getPermissionOverride } from '../types/permissions';\n\n/**\n * Get the active document state\n */\nexport const getActiveDocumentState = (state: CoreState): DocumentState | null => {\n if (!state.activeDocumentId) return null;\n return state.documents[state.activeDocumentId] ?? null;\n};\n\n/**\n * Get document state by ID\n */\nexport const getDocumentState = (state: CoreState, documentId: string): DocumentState | null => {\n return state.documents[documentId] ?? null;\n};\n\n/**\n * Get all document IDs\n */\nexport const getDocumentIds = (state: CoreState): string[] => {\n return Object.keys(state.documents);\n};\n\n/**\n * Check if a document is loaded\n */\nexport const isDocumentLoaded = (state: CoreState, documentId: string): boolean => {\n return !!state.documents[documentId];\n};\n\n/**\n * Get the number of open documents\n */\nexport const getDocumentCount = (state: CoreState): number => {\n return Object.keys(state.documents).length;\n};\n\n// ─────────────────────────────────────────────────────────\n// Permission Selectors\n// ─────────────────────────────────────────────────────────\n\n/**\n * Check if a specific permission flag is effectively allowed for a document.\n * Applies layered resolution: per-document override → global override → enforceDocumentPermissions → PDF permission.\n *\n * @param state - The core state\n * @param documentId - The document ID to check permissions for\n * @param flag - The permission flag to check\n * @returns true if the permission is allowed, false otherwise\n */\nexport function getEffectivePermission(\n state: CoreState,\n documentId: string,\n flag: PdfPermissionFlag,\n): boolean {\n const docState = state.documents[documentId];\n const docConfig = docState?.permissions;\n const globalConfig = state.globalPermissions;\n const pdfPermissions = docState?.document?.permissions ?? PdfPermissionFlag.AllowAll;\n\n // 1. Per-document override wins (supports both numeric and string keys)\n const docOverride = getPermissionOverride(docConfig?.overrides, flag);\n if (docOverride !== undefined) {\n return docOverride;\n }\n\n // 2. Global override (supports both numeric and string keys)\n const globalOverride = getPermissionOverride(globalConfig?.overrides, flag);\n if (globalOverride !== undefined) {\n return globalOverride;\n }\n\n // 3. Check enforce setting (per-doc takes precedence over global)\n const enforce =\n docConfig?.enforceDocumentPermissions ?? globalConfig?.enforceDocumentPermissions ?? true;\n\n if (!enforce) return true; // Not enforcing = allow all\n\n // 4. Use PDF permission\n return (pdfPermissions & flag) !== 0;\n}\n\n/**\n * Get all effective permissions as a bitmask for a document.\n * Combines all individual permission checks into a single bitmask.\n *\n * @param state - The core state\n * @param documentId - The document ID to get permissions for\n * @returns A bitmask of all effective permissions\n */\nexport function getEffectivePermissions(state: CoreState, documentId: string): number {\n return ALL_PERMISSION_FLAGS.reduce((acc, flag) => {\n return getEffectivePermission(state, documentId, flag) ? acc | flag : acc;\n }, 0);\n}\n","import { useMemo } from '@framework';\nimport { PdfPermissionFlag } from '@embedpdf/models';\nimport { useCoreState } from './use-core-state';\nimport { getEffectivePermission, getEffectivePermissions } from '../../lib/store/selectors';\n\nexport interface DocumentPermissions {\n /** Effective permission flags after applying overrides */\n permissions: number;\n /** Raw PDF permission flags (before overrides) */\n pdfPermissions: number;\n /** Check if a specific permission flag is effectively allowed */\n hasPermission: (flag: PdfPermissionFlag) => boolean;\n /** Check if all specified flags are effectively allowed */\n hasAllPermissions: (...flags: PdfPermissionFlag[]) => boolean;\n\n // Shorthand booleans for all permission flags (using effective permissions):\n /** Can print (possibly degraded quality) */\n canPrint: boolean;\n /** Can modify document contents */\n canModifyContents: boolean;\n /** Can copy/extract text and graphics */\n canCopyContents: boolean;\n /** Can add/modify annotations and fill forms */\n canModifyAnnotations: boolean;\n /** Can fill in existing form fields */\n canFillForms: boolean;\n /** Can extract for accessibility */\n canExtractForAccessibility: boolean;\n /** Can assemble document (insert, rotate, delete pages) */\n canAssembleDocument: boolean;\n /** Can print high quality */\n canPrintHighQuality: boolean;\n}\n\n/**\n * Hook that provides reactive access to a document's effective permission flags.\n * Applies layered resolution: per-document override → global override → PDF permission.\n *\n * @param documentId The ID of the document to check permissions for.\n * @returns An object with effective permissions, raw PDF permissions, helper functions, and shorthand booleans.\n */\nexport function useDocumentPermissions(documentId: string): DocumentPermissions {\n const coreState = useCoreState();\n\n return useMemo(() => {\n if (!coreState) {\n return {\n permissions: PdfPermissionFlag.AllowAll,\n pdfPermissions: PdfPermissionFlag.AllowAll,\n hasPermission: () => true,\n hasAllPermissions: () => true,\n canPrint: true,\n canModifyContents: true,\n canCopyContents: true,\n canModifyAnnotations: true,\n canFillForms: true,\n canExtractForAccessibility: true,\n canAssembleDocument: true,\n canPrintHighQuality: true,\n };\n }\n\n const effectivePermissions = getEffectivePermissions(coreState, documentId);\n const pdfPermissions =\n coreState.documents[documentId]?.document?.permissions ?? PdfPermissionFlag.AllowAll;\n\n const hasPermission = (flag: PdfPermissionFlag) =>\n getEffectivePermission(coreState, documentId, flag);\n const hasAllPermissions = (...flags: PdfPermissionFlag[]) =>\n flags.every((flag) => getEffectivePermission(coreState, documentId, flag));\n\n return {\n permissions: effectivePermissions,\n pdfPermissions,\n hasPermission,\n hasAllPermissions,\n // All permission flags as booleans (using effective permissions)\n canPrint: hasPermission(PdfPermissionFlag.Print),\n canModifyContents: hasPermission(PdfPermissionFlag.ModifyContents),\n canCopyContents: hasPermission(PdfPermissionFlag.CopyContents),\n canModifyAnnotations: hasPermission(PdfPermissionFlag.ModifyAnnotations),\n canFillForms: hasPermission(PdfPermissionFlag.FillForms),\n canExtractForAccessibility: hasPermission(PdfPermissionFlag.ExtractForAccessibility),\n canAssembleDocument: hasPermission(PdfPermissionFlag.AssembleDocument),\n canPrintHighQuality: hasPermission(PdfPermissionFlag.PrintHighQuality),\n };\n }, [coreState, documentId]);\n}\n"],"names":["utilities","wrappers"],"mappings":";;;;AAgBO,MAAM,aAAa,cAA+B;AAAA,EACvD,UAAU;AAAA,EACV,WAAW;AAAA,EACX,gBAAgB;AAAA,EAChB,cAAc;AAAA,EACd,kBAAkB;AAAA,EAClB,gBAAgB;AAAA,EAChB,WAAW,CAAA;AAAA,EACX,gBAAgB,CAAA;AAClB,CAAC;AChBM,SAAS,UAAU,EAAE,SAAS,YAA4B;AAC/D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qBAAqB,cAAc,kBAAkB,gBAAgB;AAAA,MACrE,qBAAqB,cAAc,kBAAkB,gBAAgB;AAAA,IAAA;AAAA,EAEzE,GAAG,CAAC,WAAW,UAAU,CAAC;AAC5B;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/shared/context.ts","../../src/shared/components/auto-mount.tsx","../../src/shared/components/embed-pdf.tsx","../../src/shared/hooks/use-registry.ts","../../src/shared/hooks/use-plugin.ts","../../src/shared/hooks/use-capability.ts","../../src/shared/hooks/use-store-state.ts","../../src/shared/hooks/use-core-state.ts","../../src/shared/hooks/use-document-state.ts","../../src/lib/types/permissions.ts","../../src/lib/store/selectors.ts","../../src/shared/hooks/use-document-permissions.ts"],"sourcesContent":["import { createContext } from '@framework';\nimport type { CoreState, DocumentState, PluginRegistry } from '@embedpdf/core';\n\nexport interface PDFContextState {\n registry: PluginRegistry | null;\n coreState: CoreState | null;\n isInitializing: boolean;\n pluginsReady: boolean;\n\n // Convenience accessors (always safe to use)\n activeDocumentId: string | null;\n activeDocument: DocumentState | null;\n documents: Record<string, DocumentState>;\n documentStates: DocumentState[];\n}\n\nexport const PDFContext = createContext<PDFContextState>({\n registry: null,\n coreState: null,\n isInitializing: true,\n pluginsReady: false,\n activeDocumentId: null,\n activeDocument: null,\n documents: {},\n documentStates: [],\n});\n","import { Fragment, useMemo, ComponentType, ReactNode } from '@framework';\nimport { hasAutoMountElements } from '@embedpdf/core';\nimport type { PluginBatchRegistration, IPlugin } from '@embedpdf/core';\n\ninterface AutoMountProps {\n plugins: PluginBatchRegistration<IPlugin<any>, any>[];\n children: ReactNode;\n}\n\nexport function AutoMount({ plugins, children }: AutoMountProps) {\n const { utilities, wrappers } = useMemo(() => {\n // React-specific types for internal use\n const utilities: ComponentType[] = [];\n const wrappers: ComponentType<{ children: ReactNode }>[] = [];\n\n for (const reg of plugins) {\n const pkg = reg.package;\n if (hasAutoMountElements(pkg)) {\n const elements = pkg.autoMountElements() || [];\n\n for (const element of elements) {\n if (element.type === 'utility') {\n utilities.push(element.component);\n } else if (element.type === 'wrapper') {\n // In React context, we know wrappers need children\n wrappers.push(element.component);\n }\n }\n }\n }\n return { utilities, wrappers };\n }, [plugins]);\n\n // Combine children and utilities as siblings inside the wrapper chain\n const contentWithUtilities = (\n <Fragment>\n {children}\n {utilities.map((Utility, i) => (\n <Utility key={`utility-${i}`} />\n ))}\n </Fragment>\n );\n\n // Wrap everything together - utilities now inside wrapper context\n const wrappedContent = wrappers.reduce(\n (content, Wrapper) => <Wrapper>{content}</Wrapper>,\n contentWithUtilities,\n );\n\n return <Fragment>{wrappedContent}</Fragment>;\n}\n","import { useState, useEffect, useRef, useMemo, ReactNode } from '@framework';\nimport { Logger, PdfEngine } from '@embedpdf/models';\nimport { PluginRegistry, CoreState, DocumentState, PluginRegistryConfig } from '@embedpdf/core';\nimport type { PluginBatchRegistrations } from '@embedpdf/core';\n\nimport { PDFContext, PDFContextState } from '../context';\nimport { AutoMount } from './auto-mount';\n\nexport type { PluginBatchRegistrations };\n\ninterface EmbedPDFProps {\n /**\n * The PDF engine to use for the PDF viewer.\n */\n engine: PdfEngine;\n /**\n * Registry configuration including logger, permissions, and defaults.\n */\n config?: PluginRegistryConfig;\n /**\n * @deprecated Use config.logger instead. Will be removed in next major version.\n */\n logger?: Logger;\n /**\n * The callback to call when the PDF viewer is initialized.\n */\n onInitialized?: (registry: PluginRegistry) => Promise<void>;\n /**\n * The plugins to use for the PDF viewer.\n */\n plugins: PluginBatchRegistrations;\n /**\n * The children to render for the PDF viewer.\n */\n children: ReactNode | ((state: PDFContextState) => ReactNode);\n /**\n * Whether to auto-mount specific non-visual DOM elements from plugins.\n * @default true\n */\n autoMountDomElements?: boolean;\n}\n\nexport function EmbedPDF({\n engine,\n config,\n logger,\n onInitialized,\n plugins,\n children,\n autoMountDomElements = true,\n}: EmbedPDFProps) {\n const [registry, setRegistry] = useState<PluginRegistry | null>(null);\n const [coreState, setCoreState] = useState<CoreState | null>(null);\n const [isInitializing, setIsInitializing] = useState<boolean>(true);\n const [pluginsReady, setPluginsReady] = useState<boolean>(false);\n const initRef = useRef<EmbedPDFProps['onInitialized']>(onInitialized);\n\n useEffect(() => {\n initRef.current = onInitialized;\n }, [onInitialized]);\n\n useEffect(() => {\n // Merge deprecated logger prop into config (config.logger takes precedence)\n const finalConfig: PluginRegistryConfig = {\n ...config,\n logger: config?.logger ?? logger,\n };\n const pdfViewer = new PluginRegistry(engine, finalConfig);\n pdfViewer.registerPluginBatch(plugins);\n\n const initialize = async () => {\n await pdfViewer.initialize();\n\n if (pdfViewer.isDestroyed()) {\n return;\n }\n\n const store = pdfViewer.getStore();\n setCoreState(store.getState().core);\n\n const unsubscribe = store.subscribe((action, newState, oldState) => {\n // Only update if it's a core action and the core state changed\n if (store.isCoreAction(action) && newState.core !== oldState.core) {\n setCoreState(newState.core);\n }\n });\n\n /* always call the *latest* callback */\n await initRef.current?.(pdfViewer);\n\n if (pdfViewer.isDestroyed()) {\n unsubscribe();\n return;\n }\n\n pdfViewer.pluginsReady().then(() => {\n if (!pdfViewer.isDestroyed()) {\n setPluginsReady(true);\n }\n });\n\n // Provide the registry to children via context\n setRegistry(pdfViewer);\n setIsInitializing(false);\n\n // Return cleanup function\n return unsubscribe;\n };\n\n let cleanup: (() => void) | undefined;\n initialize()\n .then((unsub) => {\n cleanup = unsub;\n })\n .catch(console.error);\n\n return () => {\n cleanup?.();\n pdfViewer.destroy();\n setRegistry(null);\n setCoreState(null);\n setIsInitializing(true);\n setPluginsReady(false);\n };\n }, [engine, plugins]);\n\n // Compute convenience accessors\n const contextValue: PDFContextState = useMemo(() => {\n const activeDocumentId = coreState?.activeDocumentId ?? null;\n const documents = coreState?.documents ?? {};\n const documentOrder = coreState?.documentOrder ?? [];\n\n // Compute active document\n const activeDocument =\n activeDocumentId && documents[activeDocumentId] ? documents[activeDocumentId] : null;\n\n // Compute open documents in order\n const documentStates = documentOrder\n .map((docId) => documents[docId])\n .filter((doc): doc is DocumentState => doc !== null && doc !== undefined);\n\n return {\n registry,\n coreState,\n isInitializing,\n pluginsReady,\n // Convenience accessors (always safe to use)\n activeDocumentId,\n activeDocument,\n documents,\n documentStates,\n };\n }, [registry, coreState, isInitializing, pluginsReady]);\n\n const content = typeof children === 'function' ? children(contextValue) : children;\n\n return (\n <PDFContext.Provider value={contextValue}>\n {pluginsReady && autoMountDomElements ? (\n <AutoMount plugins={plugins}>{content}</AutoMount>\n ) : (\n content\n )}\n </PDFContext.Provider>\n );\n}\n","import { useContext } from '@framework';\nimport { PDFContext, PDFContextState } from '../context';\n\n/**\n * Hook to access the PDF registry.\n * @returns The PDF registry or null during initialization\n */\nexport function useRegistry(): PDFContextState {\n const contextValue = useContext(PDFContext);\n\n // Error if used outside of context\n if (contextValue === undefined) {\n throw new Error('useCapability must be used within a PDFContext.Provider');\n }\n\n const { registry, isInitializing } = contextValue;\n\n // During initialization, return null instead of throwing an error\n if (isInitializing) {\n return contextValue;\n }\n\n // At this point, initialization is complete but registry is still null, which is unexpected\n if (registry === null) {\n throw new Error('PDF registry failed to initialize properly');\n }\n\n return contextValue;\n}\n","import type { BasePlugin } from '@embedpdf/core';\nimport { useRegistry } from './use-registry';\n\ntype PluginState<T extends BasePlugin> = {\n plugin: T | null;\n isLoading: boolean;\n ready: Promise<void>;\n};\n\n/**\n * Hook to access a plugin.\n * @param pluginId The ID of the plugin to access\n * @returns The plugin or null during initialization\n * @example\n * // Get zoom plugin\n * const zoom = usePlugin<ZoomPlugin>(ZoomPlugin.id);\n */\nexport function usePlugin<T extends BasePlugin>(pluginId: T['id']): PluginState<T> {\n const { registry } = useRegistry();\n\n if (registry === null) {\n return {\n plugin: null,\n isLoading: true,\n ready: new Promise(() => {}),\n };\n }\n\n const plugin = registry.getPlugin<T>(pluginId);\n\n if (!plugin) {\n throw new Error(`Plugin ${pluginId} not found`);\n }\n\n return {\n plugin,\n isLoading: false,\n ready: plugin.ready(),\n };\n}\n","import type { BasePlugin } from '@embedpdf/core';\nimport { usePlugin } from './use-plugin';\n\ntype CapabilityState<T extends BasePlugin> = {\n provides: ReturnType<NonNullable<T['provides']>> | null;\n isLoading: boolean;\n ready: Promise<void>;\n};\n\n/**\n * Hook to access a plugin's capability.\n * @param pluginId The ID of the plugin to access\n * @returns The capability provided by the plugin or null during initialization\n * @example\n * // Get zoom capability\n * const zoom = useCapability<ZoomPlugin>(ZoomPlugin.id);\n */\nexport function useCapability<T extends BasePlugin>(pluginId: T['id']): CapabilityState<T> {\n const { plugin, isLoading, ready } = usePlugin<T>(pluginId);\n\n if (!plugin) {\n return {\n provides: null,\n isLoading,\n ready,\n };\n }\n\n if (!plugin.provides) {\n throw new Error(`Plugin ${pluginId} does not provide a capability`);\n }\n\n return {\n provides: plugin.provides() as ReturnType<NonNullable<T['provides']>>,\n isLoading,\n ready,\n };\n}\n","import { useState, useEffect } from '@framework';\nimport { CoreState, StoreState } from '@embedpdf/core';\nimport { useRegistry } from './use-registry';\n\n/**\n * Hook that provides access to the current global store state\n * and re-renders the component when the state changes\n */\nexport function useStoreState<T = CoreState>(): StoreState<T> | null {\n const { registry } = useRegistry();\n const [state, setState] = useState<StoreState<T> | null>(null);\n\n useEffect(() => {\n if (!registry) return;\n\n // Get initial state\n setState(registry.getStore().getState() as StoreState<T>);\n\n // Subscribe to store changes\n const unsubscribe = registry.getStore().subscribe((_action, newState) => {\n setState(newState as StoreState<T>);\n });\n\n return () => unsubscribe();\n }, [registry]);\n\n return state;\n}\n","import { useContext } from '@framework';\nimport { CoreState } from '@embedpdf/core';\nimport { PDFContext } from '../context';\n\n/**\n * Hook that provides access to the current core state.\n *\n * Note: This reads from the context which is already subscribed to core state changes\n * in the EmbedPDF component, so there's no additional subscription overhead.\n */\nexport function useCoreState(): CoreState | null {\n const { coreState } = useContext(PDFContext);\n return coreState;\n}\n","import { useMemo } from '@framework';\nimport { DocumentState } from '@embedpdf/core';\nimport { useCoreState } from './use-core-state';\n\n/**\n * Hook that provides reactive access to a specific document's state from the core store.\n *\n * @param documentId The ID of the document to retrieve.\n * @returns The reactive DocumentState object or null if not found.\n */\nexport function useDocumentState(documentId: string | null): DocumentState | null {\n const coreState = useCoreState();\n\n const documentState = useMemo(() => {\n if (!coreState || !documentId) return null;\n return coreState.documents[documentId] ?? null;\n }, [coreState, documentId]);\n\n return documentState;\n}\n","import { PdfPermissionFlag } from '@embedpdf/models';\n\n/**\n * Human-readable permission names for use in configuration.\n */\nexport type PermissionName =\n | 'print'\n | 'modifyContents'\n | 'copyContents'\n | 'modifyAnnotations'\n | 'fillForms'\n | 'extractForAccessibility'\n | 'assembleDocument'\n | 'printHighQuality';\n\n/**\n * Map from human-readable names to PdfPermissionFlag values.\n */\nexport const PERMISSION_NAME_TO_FLAG: Record<PermissionName, PdfPermissionFlag> = {\n print: PdfPermissionFlag.Print,\n modifyContents: PdfPermissionFlag.ModifyContents,\n copyContents: PdfPermissionFlag.CopyContents,\n modifyAnnotations: PdfPermissionFlag.ModifyAnnotations,\n fillForms: PdfPermissionFlag.FillForms,\n extractForAccessibility: PdfPermissionFlag.ExtractForAccessibility,\n assembleDocument: PdfPermissionFlag.AssembleDocument,\n printHighQuality: PdfPermissionFlag.PrintHighQuality,\n};\n\n/**\n * Permission overrides can use either numeric flags or human-readable string names.\n */\nexport type PermissionOverrides = Partial<\n Record<PdfPermissionFlag, boolean> & Record<PermissionName, boolean>\n>;\n\n/**\n * Configuration for overriding document permissions.\n * Can be applied globally (at PluginRegistry level) or per-document (when opening).\n */\nexport interface PermissionConfig {\n /**\n * When true (default): use PDF's permissions as the base, then apply overrides.\n * When false: treat document as having all permissions allowed, then apply overrides.\n */\n enforceDocumentPermissions?: boolean;\n\n /**\n * Explicit per-flag overrides. Supports both numeric flags and string names.\n * - true = force allow (even if PDF denies)\n * - false = force deny (even if PDF allows)\n * - undefined = use base permissions\n *\n * @example\n * // Using string names (recommended)\n * overrides: { print: false, modifyAnnotations: true }\n *\n * @example\n * // Using numeric flags\n * overrides: { [PdfPermissionFlag.Print]: false }\n */\n overrides?: PermissionOverrides;\n}\n\n/**\n * All permission flags for iteration when computing effective permissions.\n */\nexport const ALL_PERMISSION_FLAGS: PdfPermissionFlag[] = [\n PdfPermissionFlag.Print,\n PdfPermissionFlag.ModifyContents,\n PdfPermissionFlag.CopyContents,\n PdfPermissionFlag.ModifyAnnotations,\n PdfPermissionFlag.FillForms,\n PdfPermissionFlag.ExtractForAccessibility,\n PdfPermissionFlag.AssembleDocument,\n PdfPermissionFlag.PrintHighQuality,\n];\n\n/**\n * All permission names for iteration.\n */\nexport const ALL_PERMISSION_NAMES: PermissionName[] = [\n 'print',\n 'modifyContents',\n 'copyContents',\n 'modifyAnnotations',\n 'fillForms',\n 'extractForAccessibility',\n 'assembleDocument',\n 'printHighQuality',\n];\n\n/**\n * Map from PdfPermissionFlag to human-readable name.\n */\nexport const PERMISSION_FLAG_TO_NAME: Record<PdfPermissionFlag, PermissionName> = {\n [PdfPermissionFlag.Print]: 'print',\n [PdfPermissionFlag.ModifyContents]: 'modifyContents',\n [PdfPermissionFlag.CopyContents]: 'copyContents',\n [PdfPermissionFlag.ModifyAnnotations]: 'modifyAnnotations',\n [PdfPermissionFlag.FillForms]: 'fillForms',\n [PdfPermissionFlag.ExtractForAccessibility]: 'extractForAccessibility',\n [PdfPermissionFlag.AssembleDocument]: 'assembleDocument',\n [PdfPermissionFlag.PrintHighQuality]: 'printHighQuality',\n};\n\n/**\n * Helper to get the override value for a permission flag, checking both numeric and string keys.\n */\nexport function getPermissionOverride(\n overrides: PermissionOverrides | undefined,\n flag: PdfPermissionFlag,\n): boolean | undefined {\n if (!overrides) return undefined;\n\n // Check numeric key first\n if (flag in overrides) {\n return (overrides as Record<PdfPermissionFlag, boolean>)[flag];\n }\n\n // Check string key\n const name = PERMISSION_FLAG_TO_NAME[flag];\n if (name && name in overrides) {\n return (overrides as Record<PermissionName, boolean>)[name];\n }\n\n return undefined;\n}\n","import { PdfPermissionFlag } from '@embedpdf/models';\nimport { CoreState, DocumentState } from './initial-state';\nimport { ALL_PERMISSION_FLAGS, getPermissionOverride } from '../types/permissions';\n\n/**\n * Get the active document state\n */\nexport const getActiveDocumentState = (state: CoreState): DocumentState | null => {\n if (!state.activeDocumentId) return null;\n return state.documents[state.activeDocumentId] ?? null;\n};\n\n/**\n * Get document state by ID\n */\nexport const getDocumentState = (state: CoreState, documentId: string): DocumentState | null => {\n return state.documents[documentId] ?? null;\n};\n\n/**\n * Get all document IDs\n */\nexport const getDocumentIds = (state: CoreState): string[] => {\n return Object.keys(state.documents);\n};\n\n/**\n * Check if a document is loaded\n */\nexport const isDocumentLoaded = (state: CoreState, documentId: string): boolean => {\n return !!state.documents[documentId];\n};\n\n/**\n * Get the number of open documents\n */\nexport const getDocumentCount = (state: CoreState): number => {\n return Object.keys(state.documents).length;\n};\n\n// ─────────────────────────────────────────────────────────\n// Permission Selectors\n// ─────────────────────────────────────────────────────────\n\n/**\n * Check if a specific permission flag is effectively allowed for a document.\n * Applies layered resolution: per-document override → global override → enforceDocumentPermissions → PDF permission.\n *\n * @param state - The core state\n * @param documentId - The document ID to check permissions for\n * @param flag - The permission flag to check\n * @returns true if the permission is allowed, false otherwise\n */\nexport function getEffectivePermission(\n state: CoreState,\n documentId: string,\n flag: PdfPermissionFlag,\n): boolean {\n const docState = state.documents[documentId];\n const docConfig = docState?.permissions;\n const globalConfig = state.globalPermissions;\n const pdfPermissions = docState?.document?.permissions ?? PdfPermissionFlag.AllowAll;\n\n // 1. Per-document override wins (supports both numeric and string keys)\n const docOverride = getPermissionOverride(docConfig?.overrides, flag);\n if (docOverride !== undefined) {\n return docOverride;\n }\n\n // 2. Global override (supports both numeric and string keys)\n const globalOverride = getPermissionOverride(globalConfig?.overrides, flag);\n if (globalOverride !== undefined) {\n return globalOverride;\n }\n\n // 3. Check enforce setting (per-doc takes precedence over global)\n const enforce =\n docConfig?.enforceDocumentPermissions ?? globalConfig?.enforceDocumentPermissions ?? true;\n\n if (!enforce) return true; // Not enforcing = allow all\n\n // 4. Use PDF permission\n return (pdfPermissions & flag) !== 0;\n}\n\n/**\n * Get all effective permissions as a bitmask for a document.\n * Combines all individual permission checks into a single bitmask.\n *\n * @param state - The core state\n * @param documentId - The document ID to get permissions for\n * @returns A bitmask of all effective permissions\n */\nexport function getEffectivePermissions(state: CoreState, documentId: string): number {\n return ALL_PERMISSION_FLAGS.reduce((acc, flag) => {\n return getEffectivePermission(state, documentId, flag) ? acc | flag : acc;\n }, 0);\n}\n","import { useMemo } from '@framework';\nimport { PdfPermissionFlag } from '@embedpdf/models';\nimport { useCoreState } from './use-core-state';\nimport { getEffectivePermission, getEffectivePermissions } from '../../lib/store/selectors';\n\nexport interface DocumentPermissions {\n /** Effective permission flags after applying overrides */\n permissions: number;\n /** Raw PDF permission flags (before overrides) */\n pdfPermissions: number;\n /** Check if a specific permission flag is effectively allowed */\n hasPermission: (flag: PdfPermissionFlag) => boolean;\n /** Check if all specified flags are effectively allowed */\n hasAllPermissions: (...flags: PdfPermissionFlag[]) => boolean;\n\n // Shorthand booleans for all permission flags (using effective permissions):\n /** Can print (possibly degraded quality) */\n canPrint: boolean;\n /** Can modify document contents */\n canModifyContents: boolean;\n /** Can copy/extract text and graphics */\n canCopyContents: boolean;\n /** Can add/modify annotations and fill forms */\n canModifyAnnotations: boolean;\n /** Can fill in existing form fields */\n canFillForms: boolean;\n /** Can extract for accessibility */\n canExtractForAccessibility: boolean;\n /** Can assemble document (insert, rotate, delete pages) */\n canAssembleDocument: boolean;\n /** Can print high quality */\n canPrintHighQuality: boolean;\n}\n\n/**\n * Hook that provides reactive access to a document's effective permission flags.\n * Applies layered resolution: per-document override → global override → PDF permission.\n *\n * @param documentId The ID of the document to check permissions for.\n * @returns An object with effective permissions, raw PDF permissions, helper functions, and shorthand booleans.\n */\nexport function useDocumentPermissions(documentId: string): DocumentPermissions {\n const coreState = useCoreState();\n\n return useMemo(() => {\n if (!coreState) {\n return {\n permissions: PdfPermissionFlag.AllowAll,\n pdfPermissions: PdfPermissionFlag.AllowAll,\n hasPermission: () => true,\n hasAllPermissions: () => true,\n canPrint: true,\n canModifyContents: true,\n canCopyContents: true,\n canModifyAnnotations: true,\n canFillForms: true,\n canExtractForAccessibility: true,\n canAssembleDocument: true,\n canPrintHighQuality: true,\n };\n }\n\n const effectivePermissions = getEffectivePermissions(coreState, documentId);\n const pdfPermissions =\n coreState.documents[documentId]?.document?.permissions ?? PdfPermissionFlag.AllowAll;\n\n const hasPermission = (flag: PdfPermissionFlag) =>\n getEffectivePermission(coreState, documentId, flag);\n const hasAllPermissions = (...flags: PdfPermissionFlag[]) =>\n flags.every((flag) => getEffectivePermission(coreState, documentId, flag));\n\n return {\n permissions: effectivePermissions,\n pdfPermissions,\n hasPermission,\n hasAllPermissions,\n // All permission flags as booleans (using effective permissions)\n canPrint: hasPermission(PdfPermissionFlag.Print),\n canModifyContents: hasPermission(PdfPermissionFlag.ModifyContents),\n canCopyContents: hasPermission(PdfPermissionFlag.CopyContents),\n canModifyAnnotations: hasPermission(PdfPermissionFlag.ModifyAnnotations),\n canFillForms: hasPermission(PdfPermissionFlag.FillForms),\n canExtractForAccessibility: hasPermission(PdfPermissionFlag.ExtractForAccessibility),\n canAssembleDocument: hasPermission(PdfPermissionFlag.AssembleDocument),\n canPrintHighQuality: hasPermission(PdfPermissionFlag.PrintHighQuality),\n };\n }, [coreState, documentId]);\n}\n"],"names":["utilities","wrappers"],"mappings":";;;;AAgBO,MAAM,aAAa,cAA+B;AAAA,EACvD,UAAU;AAAA,EACV,WAAW;AAAA,EACX,gBAAgB;AAAA,EAChB,cAAc;AAAA,EACd,kBAAkB;AAAA,EAClB,gBAAgB;AAAA,EAChB,WAAW,CAAA;AAAA,EACX,gBAAgB,CAAA;AAClB,CAAC;AChBM,SAAS,UAAU,EAAE,SAAS,YAA4B;AAC/D,QAAM,EAAE,WAAW,SAAA,IAAa,QAAQ,MAAM;AAE5C,UAAMA,aAA6B,CAAA;AACnC,UAAMC,YAAqD,CAAA;AAE3D,eAAW,OAAO,SAAS;AACzB,YAAM,MAAM,IA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zE,GAAG,CAAC,WAAW,UAAU,CAAC;AAC5B;"}
|
package/dist/svelte/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("svelte/internal/client"),t=require("@embedpdf/models");require("svelte/internal/disclose-version");const n=require("@embedpdf/core");function i(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e)for(const n in e)if("default"!==n){const i=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,i.get?i:{enumerable:!0,get:()=>e[n]})}return t.default=e,Object.freeze(t)}const r=i(e),o=r.proxy({registry:null,coreState:null,isInitializing:!0,pluginsReady:!1,activeDocumentId:null,activeDocument:null,documents:{},documentStates:[]}),s=()=>o;function l(e){const{registry:t}=o,n=r.proxy({plugin:null,isLoading:!0,ready:new Promise(()=>{})});if(null===t)return n;const i=t.getPlugin(e);if(!i)throw new Error(`Plugin ${e} not found`);return n.plugin=i,n.isLoading=!1,n.ready=i.ready(),n}function
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("svelte/internal/client"),t=require("@embedpdf/models");require("svelte/internal/disclose-version");const n=require("@embedpdf/core");function i(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e)for(const n in e)if("default"!==n){const i=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,i.get?i:{enumerable:!0,get:()=>e[n]})}return t.default=e,Object.freeze(t)}const r=i(e),o=r.proxy({registry:null,coreState:null,isInitializing:!0,pluginsReady:!1,activeDocumentId:null,activeDocument:null,documents:{},documentStates:[]}),s=()=>o;function l(e){const{registry:t}=o,n=r.proxy({plugin:null,isLoading:!0,ready:new Promise(()=>{})});if(null===t)return n;const i=t.getPlugin(e);if(!i)throw new Error(`Plugin ${e} not found`);return n.plugin=i,n.isLoading=!1,n.ready=i.ready(),n}function c(){const e=s();return{get current(){return e.coreState}}}t.PdfPermissionFlag.Print,t.PdfPermissionFlag.ModifyContents,t.PdfPermissionFlag.CopyContents,t.PdfPermissionFlag.ModifyAnnotations,t.PdfPermissionFlag.FillForms,t.PdfPermissionFlag.ExtractForAccessibility,t.PdfPermissionFlag.AssembleDocument,t.PdfPermissionFlag.PrintHighQuality;const d=[t.PdfPermissionFlag.Print,t.PdfPermissionFlag.ModifyContents,t.PdfPermissionFlag.CopyContents,t.PdfPermissionFlag.ModifyAnnotations,t.PdfPermissionFlag.FillForms,t.PdfPermissionFlag.ExtractForAccessibility,t.PdfPermissionFlag.AssembleDocument,t.PdfPermissionFlag.PrintHighQuality],u={[t.PdfPermissionFlag.Print]:"print",[t.PdfPermissionFlag.ModifyContents]:"modifyContents",[t.PdfPermissionFlag.CopyContents]:"copyContents",[t.PdfPermissionFlag.ModifyAnnotations]:"modifyAnnotations",[t.PdfPermissionFlag.FillForms]:"fillForms",[t.PdfPermissionFlag.ExtractForAccessibility]:"extractForAccessibility",[t.PdfPermissionFlag.AssembleDocument]:"assembleDocument",[t.PdfPermissionFlag.PrintHighQuality]:"printHighQuality"};function a(e,t){if(!e)return;if(t in e)return e[t];const n=u[t];return n&&n in e?e[n]:void 0}function g(e,n,i){var r;const o=e.documents[n],s=null==o?void 0:o.permissions,l=e.globalPermissions,c=(null==(r=null==o?void 0:o.document)?void 0:r.permissions)??t.PdfPermissionFlag.AllowAll,d=a(null==s?void 0:s.overrides,i);if(void 0!==d)return d;const u=a(null==l?void 0:l.overrides,i);if(void 0!==u)return u;return!((null==s?void 0:s.enforceDocumentPermissions)??(null==l?void 0:l.enforceDocumentPermissions)??!0)||0!==(c&i)}var m=r.from_html("<!> <!>",1);function p(e,t){r.push(t,!0);let n=r.prop(t,"utilities",19,()=>[]);var i=r.comment(),o=r.first_child(i),s=e=>{const i=r.derived(()=>t.wrappers[0]);var o=r.comment(),s=r.first_child(o);r.component(s,()=>r.get(i),(e,i)=>{i(e,{children:(e,i)=>{{let i=r.derived(()=>t.wrappers.slice(1));p(e,{get wrappers(){return r.get(i)},get utilities(){return n()},children:(e,n)=>{var i=r.comment(),o=r.first_child(i);r.snippet(o,()=>t.children??r.noop),r.append(e,i)},$$slots:{default:!0}})}},$$slots:{default:!0}})}),r.append(e,o)},l=e=>{const i=r.derived(()=>t.wrappers[0]);var o=r.comment(),s=r.first_child(o);r.component(s,()=>r.get(i),(e,i)=>{i(e,{children:(e,i)=>{var o=m(),s=r.first_child(o);r.snippet(s,()=>t.children??r.noop);var l=r.sibling(s,2);r.each(l,19,n,(e,t)=>`utility-${t}`,(e,t)=>{var n=r.comment(),i=r.first_child(n);r.component(i,()=>r.get(t),(e,t)=>{t(e,{})}),r.append(e,n)}),r.append(e,o)},$$slots:{default:!0}})}),r.append(e,o)};r.if(o,e=>{t.wrappers.length>1?e(s):e(l,!1)}),r.append(e,i),r.pop()}var f=r.from_html("<!> <!>",1);function P(e,t){r.push(t,!0);let i=r.state(r.proxy([])),o=r.state(r.proxy([]));r.user_effect(()=>{var e;const s=[],l=[];for(const i of t.plugins){const t=i.package;if(n.hasAutoMountElements(t)){const n=(null==(e=t.autoMountElements)?void 0:e.call(t))??[];for(const e of n)"utility"===e.type?s.push(e.component):"wrapper"===e.type&&l.push(e.component)}}r.set(i,s,!0),r.set(o,l,!0)});var s=r.comment(),l=r.first_child(s),c=e=>{p(e,{get wrappers(){return r.get(o)},get utilities(){return r.get(i)},get children(){return t.children}})},d=e=>{var n=f(),o=r.first_child(n);r.snippet(o,()=>t.children??r.noop);var s=r.sibling(o,2);r.each(s,19,()=>r.get(i),(e,t)=>`utility-${t}`,(e,t)=>{var n=r.comment(),i=r.first_child(n);r.component(i,()=>r.get(t),(e,t)=>{t(e,{})}),r.append(e,n)}),r.append(e,n)};r.if(l,e=>{r.get(o).length>0?e(c):e(d,!1)}),r.append(e,s),r.pop()}exports.EmbedPDF=function(e,t){r.push(t,!0);let i=r.prop(t,"autoMountDomElements",3,!0),s=t.onInitialized;r.user_effect(()=>{t.onInitialized&&(s=t.onInitialized)}),r.user_effect(()=>{var e;if(t.engine||t.engine&&t.plugins){const i={...t.config,logger:(null==(e=t.config)?void 0:e.logger)??t.logger},r=new n.PluginRegistry(t.engine,i);r.registerPluginBatch(t.plugins);let l;return(async()=>{if(await r.initialize(),r.isDestroyed())return;const e=r.getStore();o.coreState=e.getState().core;const t=e.subscribe((t,n,i)=>{if(e.isCoreAction(t)&&n.core!==i.core){o.coreState=n.core;const e=n.core.activeDocumentId??null,t=n.core.documents??{},i=n.core.documentOrder??[];o.activeDocumentId=e,o.activeDocument=e&&t[e]?t[e]:null,o.documents=t,o.documentStates=i.map(e=>t[e]).filter(e=>null!=e)}});if(await(null==s?void 0:s(r)),!r.isDestroyed())return r.pluginsReady().then(()=>{r.isDestroyed()||(o.pluginsReady=!0)}),o.registry=r,o.isInitializing=!1,t;t()})().then(e=>{l=e}).catch(console.error),()=>{null==l||l(),r.destroy(),o.registry=null,o.coreState=null,o.isInitializing=!0,o.pluginsReady=!1,o.activeDocumentId=null,o.activeDocument=null,o.documents={},o.documentStates=[]}}});var l=r.comment(),c=r.first_child(l),d=e=>{P(e,{get plugins(){return t.plugins},children:(e,n)=>{var i=r.comment(),s=r.first_child(i);r.snippet(s,()=>t.children,()=>o),r.append(e,i)},$$slots:{default:!0}})},u=e=>{var n=r.comment(),i=r.first_child(n);r.snippet(i,()=>t.children,()=>o),r.append(e,n)};r.if(c,e=>{o.pluginsReady&&i()?e(d):e(u,!1)}),r.append(e,l),r.pop()},exports.pdfContext=o,exports.useCapability=function(e){const t=l(e),n=r.proxy({provides:null,isLoading:!0,ready:new Promise(()=>{})});return r.user_effect(()=>{if(!t.plugin)return n.provides=null,n.isLoading=t.isLoading,void(n.ready=t.ready);if(!t.plugin.provides)throw new Error(`Plugin ${e} does not provide a capability`);n.provides=t.plugin.provides(),n.isLoading=t.isLoading,n.ready=t.ready}),n},exports.useCoreState=c,exports.useDocumentPermissions=function(e){const n=c(),i=r.derived(e),o=r.derived(()=>n.current),s=r.derived(()=>r.get(o)?function(e,t){return d.reduce((n,i)=>g(e,t,i)?n|i:n,0)}(r.get(o),r.get(i)):t.PdfPermissionFlag.AllowAll),l=r.derived(()=>{var e,n,s;return(null==(s=null==(n=null==(e=r.get(o))?void 0:e.documents[r.get(i)])?void 0:n.document)?void 0:s.permissions)??t.PdfPermissionFlag.AllowAll});return{get permissions(){return r.get(s)},get pdfPermissions(){return r.get(l)},hasPermission:e=>!r.get(o)||g(r.get(o),r.get(i),e),hasAllPermissions:(...e)=>e.every(e=>!r.get(o)||g(r.get(o),r.get(i),e)),get canPrint(){return!r.get(o)||g(r.get(o),r.get(i),t.PdfPermissionFlag.Print)},get canModifyContents(){return!r.get(o)||g(r.get(o),r.get(i),t.PdfPermissionFlag.ModifyContents)},get canCopyContents(){return!r.get(o)||g(r.get(o),r.get(i),t.PdfPermissionFlag.CopyContents)},get canModifyAnnotations(){return!r.get(o)||g(r.get(o),r.get(i),t.PdfPermissionFlag.ModifyAnnotations)},get canFillForms(){return!r.get(o)||g(r.get(o),r.get(i),t.PdfPermissionFlag.FillForms)},get canExtractForAccessibility(){return!r.get(o)||g(r.get(o),r.get(i),t.PdfPermissionFlag.ExtractForAccessibility)},get canAssembleDocument(){return!r.get(o)||g(r.get(o),r.get(i),t.PdfPermissionFlag.AssembleDocument)},get canPrintHighQuality(){return!r.get(o)||g(r.get(o),r.get(i),t.PdfPermissionFlag.PrintHighQuality)}}},exports.useDocumentState=function(e){const t=c(),n=r.derived(e),i=r.derived(()=>t.current&&r.get(n)?t.current.documents[r.get(n)]??null:null);return{get current(){return r.get(i)}}},exports.usePlugin=l,exports.useRegistry=s;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../src/svelte/hooks/use-registry.svelte.ts","../../src/svelte/hooks/use-plugin.svelte.ts","../../src/svelte/hooks/use-core-state.svelte.ts","../../src/lib/types/permissions.ts","../../src/lib/store/selectors.ts","../../src/svelte/components/NestedWrapper.svelte","../../src/svelte/components/AutoMount.svelte","../../src/svelte/components/EmbedPDF.svelte","../../src/svelte/hooks/use-capability.svelte.ts","../../src/svelte/hooks/use-document-permissions.svelte.ts","../../src/svelte/hooks/use-document-state.svelte.ts"],"sourcesContent":["import type { PluginRegistry, CoreState, DocumentState } from '@embedpdf/core';\n\nexport interface PDFContextState {\n registry: PluginRegistry | null;\n coreState: CoreState | null;\n isInitializing: boolean;\n pluginsReady: boolean;\n\n // Convenience accessors (always safe to use)\n activeDocumentId: string | null;\n activeDocument: DocumentState | null;\n documents: Record<string, DocumentState>;\n documentStates: DocumentState[];\n}\n\nexport const pdfContext = $state<PDFContextState>({\n registry: null,\n coreState: null,\n isInitializing: true,\n pluginsReady: false,\n activeDocumentId: null,\n activeDocument: null,\n documents: {},\n documentStates: [],\n});\n\n/**\n * Hook to access the PDF registry context.\n * @returns The PDF registry or null during initialization\n */\n\nexport const useRegistry = () => pdfContext;\n","import type { BasePlugin } from '@embedpdf/core';\nimport { pdfContext } from './use-registry.svelte.js';\n\n/**\n * Hook to access a plugin.\n * @param pluginId The ID of the plugin to access\n * @returns The plugin or null during initialization\n * @example\n * // Get zoom plugin\n * const zoom = usePlugin<ZoomPlugin>(ZoomPlugin.id);\n */\nexport function usePlugin<T extends BasePlugin>(pluginId: T['id']) {\n const { registry } = pdfContext;\n\n const state = $state({\n plugin: null as T | null,\n isLoading: true,\n ready: new Promise<void>(() => {}),\n });\n\n if (registry === null) {\n return state;\n }\n\n const plugin = registry.getPlugin<T>(pluginId);\n\n if (!plugin) {\n throw new Error(`Plugin ${pluginId} not found`);\n }\n\n state.plugin = plugin;\n state.isLoading = false;\n state.ready = plugin.ready();\n\n return state;\n}\n","import { useRegistry } from './use-registry.svelte';\n\n/**\n * Hook that provides access to the current core state.\n *\n * Note: This reads from the context which is already subscribed to core state changes\n * in the EmbedPDF component, so there's no additional subscription overhead.\n */\nexport function useCoreState() {\n const context = useRegistry();\n\n return {\n get current() {\n return context.coreState;\n },\n };\n}\n","import { PdfPermissionFlag } from '@embedpdf/models';\n\n/**\n * Human-readable permission names for use in configuration.\n */\nexport type PermissionName =\n | 'print'\n | 'modifyContents'\n | 'copyContents'\n | 'modifyAnnotations'\n | 'fillForms'\n | 'extractForAccessibility'\n | 'assembleDocument'\n | 'printHighQuality';\n\n/**\n * Map from human-readable names to PdfPermissionFlag values.\n */\nexport const PERMISSION_NAME_TO_FLAG: Record<PermissionName, PdfPermissionFlag> = {\n print: PdfPermissionFlag.Print,\n modifyContents: PdfPermissionFlag.ModifyContents,\n copyContents: PdfPermissionFlag.CopyContents,\n modifyAnnotations: PdfPermissionFlag.ModifyAnnotations,\n fillForms: PdfPermissionFlag.FillForms,\n extractForAccessibility: PdfPermissionFlag.ExtractForAccessibility,\n assembleDocument: PdfPermissionFlag.AssembleDocument,\n printHighQuality: PdfPermissionFlag.PrintHighQuality,\n};\n\n/**\n * Permission overrides can use either numeric flags or human-readable string names.\n */\nexport type PermissionOverrides = Partial<\n Record<PdfPermissionFlag, boolean> & Record<PermissionName, boolean>\n>;\n\n/**\n * Configuration for overriding document permissions.\n * Can be applied globally (at PluginRegistry level) or per-document (when opening).\n */\nexport interface PermissionConfig {\n /**\n * When true (default): use PDF's permissions as the base, then apply overrides.\n * When false: treat document as having all permissions allowed, then apply overrides.\n */\n enforceDocumentPermissions?: boolean;\n\n /**\n * Explicit per-flag overrides. Supports both numeric flags and string names.\n * - true = force allow (even if PDF denies)\n * - false = force deny (even if PDF allows)\n * - undefined = use base permissions\n *\n * @example\n * // Using string names (recommended)\n * overrides: { print: false, modifyAnnotations: true }\n *\n * @example\n * // Using numeric flags\n * overrides: { [PdfPermissionFlag.Print]: false }\n */\n overrides?: PermissionOverrides;\n}\n\n/**\n * All permission flags for iteration when computing effective permissions.\n */\nexport const ALL_PERMISSION_FLAGS: PdfPermissionFlag[] = [\n PdfPermissionFlag.Print,\n PdfPermissionFlag.ModifyContents,\n PdfPermissionFlag.CopyContents,\n PdfPermissionFlag.ModifyAnnotations,\n PdfPermissionFlag.FillForms,\n PdfPermissionFlag.ExtractForAccessibility,\n PdfPermissionFlag.AssembleDocument,\n PdfPermissionFlag.PrintHighQuality,\n];\n\n/**\n * All permission names for iteration.\n */\nexport const ALL_PERMISSION_NAMES: PermissionName[] = [\n 'print',\n 'modifyContents',\n 'copyContents',\n 'modifyAnnotations',\n 'fillForms',\n 'extractForAccessibility',\n 'assembleDocument',\n 'printHighQuality',\n];\n\n/**\n * Map from PdfPermissionFlag to human-readable name.\n */\nexport const PERMISSION_FLAG_TO_NAME: Record<PdfPermissionFlag, PermissionName> = {\n [PdfPermissionFlag.Print]: 'print',\n [PdfPermissionFlag.ModifyContents]: 'modifyContents',\n [PdfPermissionFlag.CopyContents]: 'copyContents',\n [PdfPermissionFlag.ModifyAnnotations]: 'modifyAnnotations',\n [PdfPermissionFlag.FillForms]: 'fillForms',\n [PdfPermissionFlag.ExtractForAccessibility]: 'extractForAccessibility',\n [PdfPermissionFlag.AssembleDocument]: 'assembleDocument',\n [PdfPermissionFlag.PrintHighQuality]: 'printHighQuality',\n};\n\n/**\n * Helper to get the override value for a permission flag, checking both numeric and string keys.\n */\nexport function getPermissionOverride(\n overrides: PermissionOverrides | undefined,\n flag: PdfPermissionFlag,\n): boolean | undefined {\n if (!overrides) return undefined;\n\n // Check numeric key first\n if (flag in overrides) {\n return (overrides as Record<PdfPermissionFlag, boolean>)[flag];\n }\n\n // Check string key\n const name = PERMISSION_FLAG_TO_NAME[flag];\n if (name && name in overrides) {\n return (overrides as Record<PermissionName, boolean>)[name];\n }\n\n return undefined;\n}\n","import { PdfPermissionFlag } from '@embedpdf/models';\nimport { CoreState, DocumentState } from './initial-state';\nimport { ALL_PERMISSION_FLAGS, getPermissionOverride } from '../types/permissions';\n\n/**\n * Get the active document state\n */\nexport const getActiveDocumentState = (state: CoreState): DocumentState | null => {\n if (!state.activeDocumentId) return null;\n return state.documents[state.activeDocumentId] ?? null;\n};\n\n/**\n * Get document state by ID\n */\nexport const getDocumentState = (state: CoreState, documentId: string): DocumentState | null => {\n return state.documents[documentId] ?? null;\n};\n\n/**\n * Get all document IDs\n */\nexport const getDocumentIds = (state: CoreState): string[] => {\n return Object.keys(state.documents);\n};\n\n/**\n * Check if a document is loaded\n */\nexport const isDocumentLoaded = (state: CoreState, documentId: string): boolean => {\n return !!state.documents[documentId];\n};\n\n/**\n * Get the number of open documents\n */\nexport const getDocumentCount = (state: CoreState): number => {\n return Object.keys(state.documents).length;\n};\n\n// ─────────────────────────────────────────────────────────\n// Permission Selectors\n// ─────────────────────────────────────────────────────────\n\n/**\n * Check if a specific permission flag is effectively allowed for a document.\n * Applies layered resolution: per-document override → global override → enforceDocumentPermissions → PDF permission.\n *\n * @param state - The core state\n * @param documentId - The document ID to check permissions for\n * @param flag - The permission flag to check\n * @returns true if the permission is allowed, false otherwise\n */\nexport function getEffectivePermission(\n state: CoreState,\n documentId: string,\n flag: PdfPermissionFlag,\n): boolean {\n const docState = state.documents[documentId];\n const docConfig = docState?.permissions;\n const globalConfig = state.globalPermissions;\n const pdfPermissions = docState?.document?.permissions ?? PdfPermissionFlag.AllowAll;\n\n // 1. Per-document override wins (supports both numeric and string keys)\n const docOverride = getPermissionOverride(docConfig?.overrides, flag);\n if (docOverride !== undefined) {\n return docOverride;\n }\n\n // 2. Global override (supports both numeric and string keys)\n const globalOverride = getPermissionOverride(globalConfig?.overrides, flag);\n if (globalOverride !== undefined) {\n return globalOverride;\n }\n\n // 3. Check enforce setting (per-doc takes precedence over global)\n const enforce =\n docConfig?.enforceDocumentPermissions ?? globalConfig?.enforceDocumentPermissions ?? true;\n\n if (!enforce) return true; // Not enforcing = allow all\n\n // 4. Use PDF permission\n return (pdfPermissions & flag) !== 0;\n}\n\n/**\n * Get all effective permissions as a bitmask for a document.\n * Combines all individual permission checks into a single bitmask.\n *\n * @param state - The core state\n * @param documentId - The document ID to get permissions for\n * @returns A bitmask of all effective permissions\n */\nexport function getEffectivePermissions(state: CoreState, documentId: string): number {\n return ALL_PERMISSION_FLAGS.reduce((acc, flag) => {\n return getEffectivePermission(state, documentId, flag) ? acc | flag : acc;\n }, 0);\n}\n","<script lang=\"ts\">\n import { type Component, type Snippet } from 'svelte';\n import NestedWrapper from './NestedWrapper.svelte';\n\n interface Props {\n wrappers: Component[];\n children?: Snippet;\n }\n\n let { wrappers, children }: Props = $props();\n</script>\n\n{#if wrappers.length > 1}\n {@const Wrapper = wrappers[0]}\n <Wrapper>\n <NestedWrapper wrappers={wrappers.slice(1)}>\n {@render children?.()}\n </NestedWrapper>\n </Wrapper>\n{:else}\n {@const Wrapper = wrappers[0]}\n <Wrapper>\n {@render children?.()}\n </Wrapper>\n{/if}\n","<script lang=\"ts\">\n import { hasAutoMountElements, type PluginBatchRegistration, type IPlugin } from '@embedpdf/core';\n import NestedWrapper from './NestedWrapper.svelte';\n import type { Snippet } from 'svelte';\n\n type Props = {\n plugins: PluginBatchRegistration<IPlugin<any>, any>[];\n children: Snippet;\n };\n\n let { plugins, children }: Props = $props();\n let utilities: any[] = $state([]);\n let wrappers: any[] = $state([]);\n\n // recompute when plugins change\n $effect(() => {\n const nextUtilities: any[] = [];\n const nextWrappers: any[] = [];\n\n for (const reg of plugins) {\n const pkg = reg.package;\n if (hasAutoMountElements(pkg)) {\n const elements = pkg.autoMountElements?.() ?? [];\n for (const element of elements) {\n if (element.type === 'utility') {\n nextUtilities.push(element.component);\n } else if (element.type === 'wrapper') {\n nextWrappers.push(element.component);\n }\n }\n }\n }\n\n utilities = nextUtilities;\n wrappers = nextWrappers;\n });\n</script>\n\n{#if wrappers.length > 0}\n <!-- wrap slot content inside all wrappers -->\n <NestedWrapper {wrappers} {children} />\n{:else}\n {@render children?.()}\n{/if}\n\n<!-- mount all utilities -->\n{#each utilities as Utility, i (`utility-${i}`)}\n <Utility />\n{/each}\n","<script lang=\"ts\">\n import type { Logger, PdfEngine } from '@embedpdf/models';\n import {\n type IPlugin,\n type PluginBatchRegistrations,\n type PluginRegistryConfig,\n PluginRegistry,\n } from '@embedpdf/core';\n import { type Snippet } from 'svelte';\n import AutoMount from './AutoMount.svelte';\n import { pdfContext, type PDFContextState } from '../hooks';\n\n export type { PluginBatchRegistrations };\n\n interface EmbedPDFProps {\n /**\n * The PDF engine to use for the PDF viewer.\n */\n engine: PdfEngine;\n /**\n * Registry configuration including logger, permissions, and defaults.\n */\n config?: PluginRegistryConfig;\n /**\n * @deprecated Use config.logger instead. Will be removed in next major version.\n */\n logger?: Logger;\n /**\n * The callback to call when the PDF viewer is initialized.\n */\n onInitialized?: (registry: PluginRegistry) => Promise<void>;\n /**\n * The plugins to use for the PDF viewer.\n */\n plugins: PluginBatchRegistrations;\n /**\n * The children to render for the PDF viewer.\n */\n children: Snippet<[PDFContextState]>;\n /**\n * Whether to auto-mount specific non-visual DOM elements from plugins.\n * @default true\n */\n autoMountDomElements?: boolean;\n }\n\n let {\n engine,\n config,\n logger,\n onInitialized,\n plugins,\n children,\n autoMountDomElements = true,\n }: EmbedPDFProps = $props();\n\n let latestInit = onInitialized;\n\n $effect(() => {\n if (onInitialized) {\n latestInit = onInitialized;\n }\n });\n\n $effect(() => {\n if (engine || (engine && plugins)) {\n // Merge deprecated logger prop into config (config.logger takes precedence)\n const finalConfig: PluginRegistryConfig = {\n ...config,\n logger: config?.logger ?? logger,\n };\n const reg = new PluginRegistry(engine, finalConfig);\n reg.registerPluginBatch(plugins);\n\n const initialize = async () => {\n await reg.initialize();\n\n // if the registry is destroyed, don't do anything\n if (reg.isDestroyed()) {\n return;\n }\n\n const store = reg.getStore();\n pdfContext.coreState = store.getState().core;\n\n const unsubscribe = store.subscribe((action, newState, oldState) => {\n // Only update if it's a core action and the core state changed\n if (store.isCoreAction(action) && newState.core !== oldState.core) {\n pdfContext.coreState = newState.core;\n\n // Update convenience accessors\n const activeDocumentId = newState.core.activeDocumentId ?? null;\n const documents = newState.core.documents ?? {};\n const documentOrder = newState.core.documentOrder ?? [];\n\n pdfContext.activeDocumentId = activeDocumentId;\n pdfContext.activeDocument =\n activeDocumentId && documents[activeDocumentId] ? documents[activeDocumentId] : null;\n pdfContext.documents = documents;\n pdfContext.documentStates = documentOrder\n .map((docId) => documents[docId])\n .filter(\n (doc): doc is import('@embedpdf/core').DocumentState =>\n doc !== null && doc !== undefined,\n );\n }\n });\n\n /* always call the *latest* callback */\n await latestInit?.(reg);\n\n // if the registry is destroyed, don't do anything\n if (reg.isDestroyed()) {\n unsubscribe();\n return;\n }\n\n reg.pluginsReady().then(() => {\n if (!reg.isDestroyed()) {\n pdfContext.pluginsReady = true;\n }\n });\n\n // Provide the registry to children via context\n pdfContext.registry = reg;\n pdfContext.isInitializing = false;\n\n return unsubscribe;\n };\n\n let cleanup: (() => void) | undefined;\n initialize()\n .then((unsub) => {\n cleanup = unsub;\n })\n .catch(console.error);\n\n return () => {\n cleanup?.();\n reg.destroy();\n pdfContext.registry = null;\n pdfContext.coreState = null;\n pdfContext.isInitializing = true;\n pdfContext.pluginsReady = false;\n pdfContext.activeDocumentId = null;\n pdfContext.activeDocument = null;\n pdfContext.documents = {};\n pdfContext.documentStates = [];\n };\n }\n });\n</script>\n\n{#if pdfContext.pluginsReady && autoMountDomElements}\n <AutoMount {plugins}>{@render children(pdfContext)}</AutoMount>\n{:else}\n {@render children(pdfContext)}\n{/if}\n","import type { BasePlugin } from '@embedpdf/core';\nimport { usePlugin } from './use-plugin.svelte.js';\n\n/**\n * Hook to access a plugin's capability.\n * @param pluginId The ID of the plugin to access\n * @returns The capability provided by the plugin or null during initialization\n * @example\n * // Get zoom capability\n * const zoom = useCapability<ZoomPlugin>(ZoomPlugin.id);\n */\nexport function useCapability<T extends BasePlugin>(pluginId: T['id']) {\n const p = usePlugin<T>(pluginId);\n\n const state = $state({\n provides: null as ReturnType<NonNullable<T['provides']>> | null,\n isLoading: true,\n ready: new Promise<void>(() => {}),\n });\n\n // Use $effect to reactively update when plugin loads\n $effect(() => {\n if (!p.plugin) {\n state.provides = null;\n state.isLoading = p.isLoading;\n state.ready = p.ready;\n return;\n }\n\n if (!p.plugin.provides) {\n throw new Error(`Plugin ${pluginId} does not provide a capability`);\n }\n\n state.provides = p.plugin.provides() as ReturnType<NonNullable<T['provides']>>;\n state.isLoading = p.isLoading;\n state.ready = p.ready;\n });\n\n return state;\n}\n","import { PdfPermissionFlag } from '@embedpdf/models';\nimport { useCoreState } from './use-core-state.svelte';\nimport { getEffectivePermission, getEffectivePermissions } from '../../lib/store/selectors';\n\nexport interface DocumentPermissions {\n /** Effective permission flags after applying overrides */\n permissions: number;\n /** Raw PDF permission flags (before overrides) */\n pdfPermissions: number;\n /** Check if a specific permission flag is effectively allowed */\n hasPermission: (flag: PdfPermissionFlag) => boolean;\n /** Check if all specified flags are effectively allowed */\n hasAllPermissions: (...flags: PdfPermissionFlag[]) => boolean;\n\n // Shorthand booleans for all permission flags (using effective permissions):\n /** Can print (possibly degraded quality) */\n canPrint: boolean;\n /** Can modify document contents */\n canModifyContents: boolean;\n /** Can copy/extract text and graphics */\n canCopyContents: boolean;\n /** Can add/modify annotations and fill forms */\n canModifyAnnotations: boolean;\n /** Can fill in existing form fields */\n canFillForms: boolean;\n /** Can extract for accessibility */\n canExtractForAccessibility: boolean;\n /** Can assemble document (insert, rotate, delete pages) */\n canAssembleDocument: boolean;\n /** Can print high quality */\n canPrintHighQuality: boolean;\n}\n\n/**\n * Hook that provides reactive access to a document's effective permission flags.\n * Applies layered resolution: per-document override → global override → PDF permission.\n *\n * @param getDocumentId Function that returns the document ID\n * @returns An object with reactive permission properties.\n */\nexport function useDocumentPermissions(getDocumentId: () => string): DocumentPermissions {\n const coreStateRef = useCoreState();\n\n const documentId = $derived(getDocumentId());\n const coreState = $derived(coreStateRef.current);\n\n const effectivePermissions = $derived(\n coreState ? getEffectivePermissions(coreState, documentId) : PdfPermissionFlag.AllowAll,\n );\n\n const pdfPermissions = $derived(\n coreState?.documents[documentId]?.document?.permissions ?? PdfPermissionFlag.AllowAll,\n );\n\n const hasPermission = (flag: PdfPermissionFlag) =>\n coreState ? getEffectivePermission(coreState, documentId, flag) : true;\n\n const hasAllPermissions = (...flags: PdfPermissionFlag[]) =>\n flags.every((flag) => (coreState ? getEffectivePermission(coreState, documentId, flag) : true));\n\n return {\n get permissions() {\n return effectivePermissions;\n },\n get pdfPermissions() {\n return pdfPermissions;\n },\n hasPermission,\n hasAllPermissions,\n get canPrint() {\n return coreState\n ? getEffectivePermission(coreState, documentId, PdfPermissionFlag.Print)\n : true;\n },\n get canModifyContents() {\n return coreState\n ? getEffectivePermission(coreState, documentId, PdfPermissionFlag.ModifyContents)\n : true;\n },\n get canCopyContents() {\n return coreState\n ? getEffectivePermission(coreState, documentId, PdfPermissionFlag.CopyContents)\n : true;\n },\n get canModifyAnnotations() {\n return coreState\n ? getEffectivePermission(coreState, documentId, PdfPermissionFlag.ModifyAnnotations)\n : true;\n },\n get canFillForms() {\n return coreState\n ? getEffectivePermission(coreState, documentId, PdfPermissionFlag.FillForms)\n : true;\n },\n get canExtractForAccessibility() {\n return coreState\n ? getEffectivePermission(coreState, documentId, PdfPermissionFlag.ExtractForAccessibility)\n : true;\n },\n get canAssembleDocument() {\n return coreState\n ? getEffectivePermission(coreState, documentId, PdfPermissionFlag.AssembleDocument)\n : true;\n },\n get canPrintHighQuality() {\n return coreState\n ? getEffectivePermission(coreState, documentId, PdfPermissionFlag.PrintHighQuality)\n : true;\n },\n };\n}\n","import { useCoreState } from './use-core-state.svelte';\n\n/**\n * Hook that provides reactive access to a specific document's state from the core store.\n *\n * @param getDocumentId Function that returns the document ID\n * @returns The reactive DocumentState object or null if not found.\n */\nexport function useDocumentState(getDocumentId: () => string | null) {\n const coreStateRef = useCoreState();\n\n // Reactive documentId\n const documentId = $derived(getDocumentId());\n\n const documentState = $derived(\n coreStateRef.current && documentId\n ? (coreStateRef.current.documents[documentId] ?? null)\n : null,\n );\n\n return {\n get current() {\n return documentState;\n },\n };\n}\n"],"names":["pdfContext","registry","coreState","isInitializing","pluginsReady","activeDocumentId","activeDocument","documents","documentStates","useRegistry","usePlugin","pluginId","state","plugin","isLoading","ready","Promise","getPlugin","Error","useCoreState","context","current","PdfPermissionFlag","Print","ModifyContents","CopyContents","ModifyAnnotations","FillForms","ExtractForAccessibility","AssembleDocument","PrintHighQuality","ALL_PERMISSION_FLAGS","PERMISSION_FLAG_TO_NAME","getPermissionOverride","overrides","flag","name","getEffectivePermission","documentId","docState","docConfig","permissions","globalConfig","globalPermissions","pdfPermissions","_a","document","AllowAll","docOverride","globalOverride","enforceDocumentPermissions","Wrapper","Wrapper_1","$$anchor","$0","$","derived","$$props","wrappers","slice","NestedWrapper","Wrapper_2","length","consequent","$$render","alternate","utilities","proxy","user_effect","nextUtilities","nextWrappers","reg","plugins","pkg","package","hasAutoMountElements","elements","autoMountElements","call","element","type","push","component","set","each","node_2","get","Utility","i","Utility_1","autoMountDomElements","latestInit","onInitialized","engine","finalConfig","logger","PluginRegistry","registerPluginBatch","cleanup","async","initialize","isDestroyed","store","getStore","getState","core","unsubscribe","subscribe","action","newState","oldState","isCoreAction","documentOrder","map","docId","filter","doc","then","unsub","catch","console","error","destroy","AutoMount","p","provides","getDocumentId","coreStateRef","effectivePermissions","reduce","acc","getEffectivePermissions","hasPermission","hasAllPermissions","flags","every","canPrint","canModifyContents","canCopyContents","canModifyAnnotations","canFillForms","canExtractForAccessibility","canAssembleDocument","canPrintHighQuality","documentState"],"mappings":"8fAeaA,WACXC,SAAU,KACVC,UAAW,KACXC,gBAAgB,EAChBC,cAAc,EACdC,iBAAkB,KAClBC,eAAgB,KAChBC,aACAC,oBAQWC,MAAoBT,WCpBjBU,EAAgCC,GACtC,MAAAV,SAAAA,GAAaD,EAEfY,WACJC,OAAQ,KACRC,WAAW,EACXC,MAAA,IAAWC,QAAA,aAGI,OAAbf,SACKW,EAGH,MAAAC,EAASZ,EAASgB,UAAaN,GAEhC,IAAAE,EACO,MAAA,IAAAK,gBAAgBP,sBAG5BC,EAAMC,OAASA,EACfD,EAAME,WAAY,EAClBF,EAAMG,MAAQF,EAAOE,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B,GACnByF,EAAa1G,QAAQd,UAAAgD,EAAA+B,IAAUhD,KAAe,KAC/C,aAIA,WAAAjB,gBACK2H,EACT,EAEJ"}
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/svelte/hooks/use-registry.svelte.ts","../../src/svelte/hooks/use-plugin.svelte.ts","../../src/svelte/hooks/use-core-state.svelte.ts","../../src/lib/types/permissions.ts","../../src/lib/store/selectors.ts","../../src/svelte/components/NestedWrapper.svelte","../../src/svelte/components/AutoMount.svelte","../../src/svelte/components/EmbedPDF.svelte","../../src/svelte/hooks/use-capability.svelte.ts","../../src/svelte/hooks/use-document-permissions.svelte.ts","../../src/svelte/hooks/use-document-state.svelte.ts"],"sourcesContent":["import type { PluginRegistry, CoreState, DocumentState } from '@embedpdf/core';\n\nexport interface PDFContextState {\n registry: PluginRegistry | null;\n coreState: CoreState | null;\n isInitializing: boolean;\n pluginsReady: boolean;\n\n // Convenience accessors (always safe to use)\n activeDocumentId: string | null;\n activeDocument: DocumentState | null;\n documents: Record<string, DocumentState>;\n documentStates: DocumentState[];\n}\n\nexport const pdfContext = $state<PDFContextState>({\n registry: null,\n coreState: null,\n isInitializing: true,\n pluginsReady: false,\n activeDocumentId: null,\n activeDocument: null,\n documents: {},\n documentStates: [],\n});\n\n/**\n * Hook to access the PDF registry context.\n * @returns The PDF registry or null during initialization\n */\n\nexport const useRegistry = () => pdfContext;\n","import type { BasePlugin } from '@embedpdf/core';\nimport { pdfContext } from './use-registry.svelte.js';\n\n/**\n * Hook to access a plugin.\n * @param pluginId The ID of the plugin to access\n * @returns The plugin or null during initialization\n * @example\n * // Get zoom plugin\n * const zoom = usePlugin<ZoomPlugin>(ZoomPlugin.id);\n */\nexport function usePlugin<T extends BasePlugin>(pluginId: T['id']) {\n const { registry } = pdfContext;\n\n const state = $state({\n plugin: null as T | null,\n isLoading: true,\n ready: new Promise<void>(() => {}),\n });\n\n if (registry === null) {\n return state;\n }\n\n const plugin = registry.getPlugin<T>(pluginId);\n\n if (!plugin) {\n throw new Error(`Plugin ${pluginId} not found`);\n }\n\n state.plugin = plugin;\n state.isLoading = false;\n state.ready = plugin.ready();\n\n return state;\n}\n","import { useRegistry } from './use-registry.svelte';\n\n/**\n * Hook that provides access to the current core state.\n *\n * Note: This reads from the context which is already subscribed to core state changes\n * in the EmbedPDF component, so there's no additional subscription overhead.\n */\nexport function useCoreState() {\n const context = useRegistry();\n\n return {\n get current() {\n return context.coreState;\n },\n };\n}\n","import { PdfPermissionFlag } from '@embedpdf/models';\n\n/**\n * Human-readable permission names for use in configuration.\n */\nexport type PermissionName =\n | 'print'\n | 'modifyContents'\n | 'copyContents'\n | 'modifyAnnotations'\n | 'fillForms'\n | 'extractForAccessibility'\n | 'assembleDocument'\n | 'printHighQuality';\n\n/**\n * Map from human-readable names to PdfPermissionFlag values.\n */\nexport const PERMISSION_NAME_TO_FLAG: Record<PermissionName, PdfPermissionFlag> = {\n print: PdfPermissionFlag.Print,\n modifyContents: PdfPermissionFlag.ModifyContents,\n copyContents: PdfPermissionFlag.CopyContents,\n modifyAnnotations: PdfPermissionFlag.ModifyAnnotations,\n fillForms: PdfPermissionFlag.FillForms,\n extractForAccessibility: PdfPermissionFlag.ExtractForAccessibility,\n assembleDocument: PdfPermissionFlag.AssembleDocument,\n printHighQuality: PdfPermissionFlag.PrintHighQuality,\n};\n\n/**\n * Permission overrides can use either numeric flags or human-readable string names.\n */\nexport type PermissionOverrides = Partial<\n Record<PdfPermissionFlag, boolean> & Record<PermissionName, boolean>\n>;\n\n/**\n * Configuration for overriding document permissions.\n * Can be applied globally (at PluginRegistry level) or per-document (when opening).\n */\nexport interface PermissionConfig {\n /**\n * When true (default): use PDF's permissions as the base, then apply overrides.\n * When false: treat document as having all permissions allowed, then apply overrides.\n */\n enforceDocumentPermissions?: boolean;\n\n /**\n * Explicit per-flag overrides. Supports both numeric flags and string names.\n * - true = force allow (even if PDF denies)\n * - false = force deny (even if PDF allows)\n * - undefined = use base permissions\n *\n * @example\n * // Using string names (recommended)\n * overrides: { print: false, modifyAnnotations: true }\n *\n * @example\n * // Using numeric flags\n * overrides: { [PdfPermissionFlag.Print]: false }\n */\n overrides?: PermissionOverrides;\n}\n\n/**\n * All permission flags for iteration when computing effective permissions.\n */\nexport const ALL_PERMISSION_FLAGS: PdfPermissionFlag[] = [\n PdfPermissionFlag.Print,\n PdfPermissionFlag.ModifyContents,\n PdfPermissionFlag.CopyContents,\n PdfPermissionFlag.ModifyAnnotations,\n PdfPermissionFlag.FillForms,\n PdfPermissionFlag.ExtractForAccessibility,\n PdfPermissionFlag.AssembleDocument,\n PdfPermissionFlag.PrintHighQuality,\n];\n\n/**\n * All permission names for iteration.\n */\nexport const ALL_PERMISSION_NAMES: PermissionName[] = [\n 'print',\n 'modifyContents',\n 'copyContents',\n 'modifyAnnotations',\n 'fillForms',\n 'extractForAccessibility',\n 'assembleDocument',\n 'printHighQuality',\n];\n\n/**\n * Map from PdfPermissionFlag to human-readable name.\n */\nexport const PERMISSION_FLAG_TO_NAME: Record<PdfPermissionFlag, PermissionName> = {\n [PdfPermissionFlag.Print]: 'print',\n [PdfPermissionFlag.ModifyContents]: 'modifyContents',\n [PdfPermissionFlag.CopyContents]: 'copyContents',\n [PdfPermissionFlag.ModifyAnnotations]: 'modifyAnnotations',\n [PdfPermissionFlag.FillForms]: 'fillForms',\n [PdfPermissionFlag.ExtractForAccessibility]: 'extractForAccessibility',\n [PdfPermissionFlag.AssembleDocument]: 'assembleDocument',\n [PdfPermissionFlag.PrintHighQuality]: 'printHighQuality',\n};\n\n/**\n * Helper to get the override value for a permission flag, checking both numeric and string keys.\n */\nexport function getPermissionOverride(\n overrides: PermissionOverrides | undefined,\n flag: PdfPermissionFlag,\n): boolean | undefined {\n if (!overrides) return undefined;\n\n // Check numeric key first\n if (flag in overrides) {\n return (overrides as Record<PdfPermissionFlag, boolean>)[flag];\n }\n\n // Check string key\n const name = PERMISSION_FLAG_TO_NAME[flag];\n if (name && name in overrides) {\n return (overrides as Record<PermissionName, boolean>)[name];\n }\n\n return undefined;\n}\n","import { PdfPermissionFlag } from '@embedpdf/models';\nimport { CoreState, DocumentState } from './initial-state';\nimport { ALL_PERMISSION_FLAGS, getPermissionOverride } from '../types/permissions';\n\n/**\n * Get the active document state\n */\nexport const getActiveDocumentState = (state: CoreState): DocumentState | null => {\n if (!state.activeDocumentId) return null;\n return state.documents[state.activeDocumentId] ?? null;\n};\n\n/**\n * Get document state by ID\n */\nexport const getDocumentState = (state: CoreState, documentId: string): DocumentState | null => {\n return state.documents[documentId] ?? null;\n};\n\n/**\n * Get all document IDs\n */\nexport const getDocumentIds = (state: CoreState): string[] => {\n return Object.keys(state.documents);\n};\n\n/**\n * Check if a document is loaded\n */\nexport const isDocumentLoaded = (state: CoreState, documentId: string): boolean => {\n return !!state.documents[documentId];\n};\n\n/**\n * Get the number of open documents\n */\nexport const getDocumentCount = (state: CoreState): number => {\n return Object.keys(state.documents).length;\n};\n\n// ─────────────────────────────────────────────────────────\n// Permission Selectors\n// ─────────────────────────────────────────────────────────\n\n/**\n * Check if a specific permission flag is effectively allowed for a document.\n * Applies layered resolution: per-document override → global override → enforceDocumentPermissions → PDF permission.\n *\n * @param state - The core state\n * @param documentId - The document ID to check permissions for\n * @param flag - The permission flag to check\n * @returns true if the permission is allowed, false otherwise\n */\nexport function getEffectivePermission(\n state: CoreState,\n documentId: string,\n flag: PdfPermissionFlag,\n): boolean {\n const docState = state.documents[documentId];\n const docConfig = docState?.permissions;\n const globalConfig = state.globalPermissions;\n const pdfPermissions = docState?.document?.permissions ?? PdfPermissionFlag.AllowAll;\n\n // 1. Per-document override wins (supports both numeric and string keys)\n const docOverride = getPermissionOverride(docConfig?.overrides, flag);\n if (docOverride !== undefined) {\n return docOverride;\n }\n\n // 2. Global override (supports both numeric and string keys)\n const globalOverride = getPermissionOverride(globalConfig?.overrides, flag);\n if (globalOverride !== undefined) {\n return globalOverride;\n }\n\n // 3. Check enforce setting (per-doc takes precedence over global)\n const enforce =\n docConfig?.enforceDocumentPermissions ?? globalConfig?.enforceDocumentPermissions ?? true;\n\n if (!enforce) return true; // Not enforcing = allow all\n\n // 4. Use PDF permission\n return (pdfPermissions & flag) !== 0;\n}\n\n/**\n * Get all effective permissions as a bitmask for a document.\n * Combines all individual permission checks into a single bitmask.\n *\n * @param state - The core state\n * @param documentId - The document ID to get permissions for\n * @returns A bitmask of all effective permissions\n */\nexport function getEffectivePermissions(state: CoreState, documentId: string): number {\n return ALL_PERMISSION_FLAGS.reduce((acc, flag) => {\n return getEffectivePermission(state, documentId, flag) ? acc | flag : acc;\n }, 0);\n}\n","<script lang=\"ts\">\n import { type Component, type Snippet } from 'svelte';\n import NestedWrapper from './NestedWrapper.svelte';\n\n interface Props {\n wrappers: Component[];\n utilities?: Component[];\n children?: Snippet;\n }\n\n let { wrappers, utilities = [], children }: Props = $props();\n</script>\n\n{#if wrappers.length > 1}\n {@const Wrapper = wrappers[0]}\n <Wrapper>\n <NestedWrapper wrappers={wrappers.slice(1)} {utilities}>\n {@render children?.()}\n </NestedWrapper>\n </Wrapper>\n{:else}\n {@const Wrapper = wrappers[0]}\n <Wrapper>\n {@render children?.()}\n <!-- Render utilities inside the innermost wrapper -->\n {#each utilities as Utility, i (`utility-${i}`)}\n <Utility />\n {/each}\n </Wrapper>\n{/if}\n","<script lang=\"ts\">\n import { hasAutoMountElements, type PluginBatchRegistration, type IPlugin } from '@embedpdf/core';\n import NestedWrapper from './NestedWrapper.svelte';\n import type { Snippet } from 'svelte';\n\n type Props = {\n plugins: PluginBatchRegistration<IPlugin<any>, any>[];\n children: Snippet;\n };\n\n let { plugins, children }: Props = $props();\n let utilities: any[] = $state([]);\n let wrappers: any[] = $state([]);\n\n // recompute when plugins change\n $effect(() => {\n const nextUtilities: any[] = [];\n const nextWrappers: any[] = [];\n\n for (const reg of plugins) {\n const pkg = reg.package;\n if (hasAutoMountElements(pkg)) {\n const elements = pkg.autoMountElements?.() ?? [];\n for (const element of elements) {\n if (element.type === 'utility') {\n nextUtilities.push(element.component);\n } else if (element.type === 'wrapper') {\n nextWrappers.push(element.component);\n }\n }\n }\n }\n\n utilities = nextUtilities;\n wrappers = nextWrappers;\n });\n</script>\n\n{#if wrappers.length > 0}\n <!-- wrap slot content and utilities inside all wrappers -->\n <NestedWrapper {wrappers} {utilities} {children} />\n{:else}\n <!-- No wrappers - render children and utilities directly -->\n {@render children?.()}\n {#each utilities as Utility, i (`utility-${i}`)}\n <Utility />\n {/each}\n{/if}\n","<script lang=\"ts\">\n import type { Logger, PdfEngine } from '@embedpdf/models';\n import {\n type IPlugin,\n type PluginBatchRegistrations,\n type PluginRegistryConfig,\n PluginRegistry,\n } from '@embedpdf/core';\n import { type Snippet } from 'svelte';\n import AutoMount from './AutoMount.svelte';\n import { pdfContext, type PDFContextState } from '../hooks';\n\n export type { PluginBatchRegistrations };\n\n interface EmbedPDFProps {\n /**\n * The PDF engine to use for the PDF viewer.\n */\n engine: PdfEngine;\n /**\n * Registry configuration including logger, permissions, and defaults.\n */\n config?: PluginRegistryConfig;\n /**\n * @deprecated Use config.logger instead. Will be removed in next major version.\n */\n logger?: Logger;\n /**\n * The callback to call when the PDF viewer is initialized.\n */\n onInitialized?: (registry: PluginRegistry) => Promise<void>;\n /**\n * The plugins to use for the PDF viewer.\n */\n plugins: PluginBatchRegistrations;\n /**\n * The children to render for the PDF viewer.\n */\n children: Snippet<[PDFContextState]>;\n /**\n * Whether to auto-mount specific non-visual DOM elements from plugins.\n * @default true\n */\n autoMountDomElements?: boolean;\n }\n\n let {\n engine,\n config,\n logger,\n onInitialized,\n plugins,\n children,\n autoMountDomElements = true,\n }: EmbedPDFProps = $props();\n\n let latestInit = onInitialized;\n\n $effect(() => {\n if (onInitialized) {\n latestInit = onInitialized;\n }\n });\n\n $effect(() => {\n if (engine || (engine && plugins)) {\n // Merge deprecated logger prop into config (config.logger takes precedence)\n const finalConfig: PluginRegistryConfig = {\n ...config,\n logger: config?.logger ?? logger,\n };\n const reg = new PluginRegistry(engine, finalConfig);\n reg.registerPluginBatch(plugins);\n\n const initialize = async () => {\n await reg.initialize();\n\n // if the registry is destroyed, don't do anything\n if (reg.isDestroyed()) {\n return;\n }\n\n const store = reg.getStore();\n pdfContext.coreState = store.getState().core;\n\n const unsubscribe = store.subscribe((action, newState, oldState) => {\n // Only update if it's a core action and the core state changed\n if (store.isCoreAction(action) && newState.core !== oldState.core) {\n pdfContext.coreState = newState.core;\n\n // Update convenience accessors\n const activeDocumentId = newState.core.activeDocumentId ?? null;\n const documents = newState.core.documents ?? {};\n const documentOrder = newState.core.documentOrder ?? [];\n\n pdfContext.activeDocumentId = activeDocumentId;\n pdfContext.activeDocument =\n activeDocumentId && documents[activeDocumentId] ? documents[activeDocumentId] : null;\n pdfContext.documents = documents;\n pdfContext.documentStates = documentOrder\n .map((docId) => documents[docId])\n .filter(\n (doc): doc is import('@embedpdf/core').DocumentState =>\n doc !== null && doc !== undefined,\n );\n }\n });\n\n /* always call the *latest* callback */\n await latestInit?.(reg);\n\n // if the registry is destroyed, don't do anything\n if (reg.isDestroyed()) {\n unsubscribe();\n return;\n }\n\n reg.pluginsReady().then(() => {\n if (!reg.isDestroyed()) {\n pdfContext.pluginsReady = true;\n }\n });\n\n // Provide the registry to children via context\n pdfContext.registry = reg;\n pdfContext.isInitializing = false;\n\n return unsubscribe;\n };\n\n let cleanup: (() => void) | undefined;\n initialize()\n .then((unsub) => {\n cleanup = unsub;\n })\n .catch(console.error);\n\n return () => {\n cleanup?.();\n reg.destroy();\n pdfContext.registry = null;\n pdfContext.coreState = null;\n pdfContext.isInitializing = true;\n pdfContext.pluginsReady = false;\n pdfContext.activeDocumentId = null;\n pdfContext.activeDocument = null;\n pdfContext.documents = {};\n pdfContext.documentStates = [];\n };\n }\n });\n</script>\n\n{#if pdfContext.pluginsReady && autoMountDomElements}\n <AutoMount {plugins}>{@render children(pdfContext)}</AutoMount>\n{:else}\n {@render children(pdfContext)}\n{/if}\n","import type { BasePlugin } from '@embedpdf/core';\nimport { usePlugin } from './use-plugin.svelte.js';\n\n/**\n * Hook to access a plugin's capability.\n * @param pluginId The ID of the plugin to access\n * @returns The capability provided by the plugin or null during initialization\n * @example\n * // Get zoom capability\n * const zoom = useCapability<ZoomPlugin>(ZoomPlugin.id);\n */\nexport function useCapability<T extends BasePlugin>(pluginId: T['id']) {\n const p = usePlugin<T>(pluginId);\n\n const state = $state({\n provides: null as ReturnType<NonNullable<T['provides']>> | null,\n isLoading: true,\n ready: new Promise<void>(() => {}),\n });\n\n // Use $effect to reactively update when plugin loads\n $effect(() => {\n if (!p.plugin) {\n state.provides = null;\n state.isLoading = p.isLoading;\n state.ready = p.ready;\n return;\n }\n\n if (!p.plugin.provides) {\n throw new Error(`Plugin ${pluginId} does not provide a capability`);\n }\n\n state.provides = p.plugin.provides() as ReturnType<NonNullable<T['provides']>>;\n state.isLoading = p.isLoading;\n state.ready = p.ready;\n });\n\n return state;\n}\n","import { PdfPermissionFlag } from '@embedpdf/models';\nimport { useCoreState } from './use-core-state.svelte';\nimport { getEffectivePermission, getEffectivePermissions } from '../../lib/store/selectors';\n\nexport interface DocumentPermissions {\n /** Effective permission flags after applying overrides */\n permissions: number;\n /** Raw PDF permission flags (before overrides) */\n pdfPermissions: number;\n /** Check if a specific permission flag is effectively allowed */\n hasPermission: (flag: PdfPermissionFlag) => boolean;\n /** Check if all specified flags are effectively allowed */\n hasAllPermissions: (...flags: PdfPermissionFlag[]) => boolean;\n\n // Shorthand booleans for all permission flags (using effective permissions):\n /** Can print (possibly degraded quality) */\n canPrint: boolean;\n /** Can modify document contents */\n canModifyContents: boolean;\n /** Can copy/extract text and graphics */\n canCopyContents: boolean;\n /** Can add/modify annotations and fill forms */\n canModifyAnnotations: boolean;\n /** Can fill in existing form fields */\n canFillForms: boolean;\n /** Can extract for accessibility */\n canExtractForAccessibility: boolean;\n /** Can assemble document (insert, rotate, delete pages) */\n canAssembleDocument: boolean;\n /** Can print high quality */\n canPrintHighQuality: boolean;\n}\n\n/**\n * Hook that provides reactive access to a document's effective permission flags.\n * Applies layered resolution: per-document override → global override → PDF permission.\n *\n * @param getDocumentId Function that returns the document ID\n * @returns An object with reactive permission properties.\n */\nexport function useDocumentPermissions(getDocumentId: () => string): DocumentPermissions {\n const coreStateRef = useCoreState();\n\n const documentId = $derived(getDocumentId());\n const coreState = $derived(coreStateRef.current);\n\n const effectivePermissions = $derived(\n coreState ? getEffectivePermissions(coreState, documentId) : PdfPermissionFlag.AllowAll,\n );\n\n const pdfPermissions = $derived(\n coreState?.documents[documentId]?.document?.permissions ?? PdfPermissionFlag.AllowAll,\n );\n\n const hasPermission = (flag: PdfPermissionFlag) =>\n coreState ? getEffectivePermission(coreState, documentId, flag) : true;\n\n const hasAllPermissions = (...flags: PdfPermissionFlag[]) =>\n flags.every((flag) => (coreState ? getEffectivePermission(coreState, documentId, flag) : true));\n\n return {\n get permissions() {\n return effectivePermissions;\n },\n get pdfPermissions() {\n return pdfPermissions;\n },\n hasPermission,\n hasAllPermissions,\n get canPrint() {\n return coreState\n ? getEffectivePermission(coreState, documentId, PdfPermissionFlag.Print)\n : true;\n },\n get canModifyContents() {\n return coreState\n ? getEffectivePermission(coreState, documentId, PdfPermissionFlag.ModifyContents)\n : true;\n },\n get canCopyContents() {\n return coreState\n ? getEffectivePermission(coreState, documentId, PdfPermissionFlag.CopyContents)\n : true;\n },\n get canModifyAnnotations() {\n return coreState\n ? getEffectivePermission(coreState, documentId, PdfPermissionFlag.ModifyAnnotations)\n : true;\n },\n get canFillForms() {\n return coreState\n ? getEffectivePermission(coreState, documentId, PdfPermissionFlag.FillForms)\n : true;\n },\n get canExtractForAccessibility() {\n return coreState\n ? getEffectivePermission(coreState, documentId, PdfPermissionFlag.ExtractForAccessibility)\n : true;\n },\n get canAssembleDocument() {\n return coreState\n ? getEffectivePermission(coreState, documentId, PdfPermissionFlag.AssembleDocument)\n : true;\n },\n get canPrintHighQuality() {\n return coreState\n ? getEffectivePermission(coreState, documentId, PdfPermissionFlag.PrintHighQuality)\n : true;\n },\n };\n}\n","import { useCoreState } from './use-core-state.svelte';\n\n/**\n * Hook that provides reactive access to a specific document's state from the core store.\n *\n * @param getDocumentId Function that returns the document ID\n * @returns The reactive DocumentState object or null if not found.\n */\nexport function useDocumentState(getDocumentId: () => string | null) {\n const coreStateRef = useCoreState();\n\n // Reactive documentId\n const documentId = $derived(getDocumentId());\n\n const documentState = $derived(\n coreStateRef.current && documentId\n ? (coreStateRef.current.documents[documentId] ?? null)\n : null,\n );\n\n return {\n get current() {\n return documentState;\n },\n };\n}\n"],"names":["pdfContext","registry","coreState","isInitializing","pluginsReady","activeDocumentId","activeDocument","documents","documentStates","useRegistry","usePlugin","pluginId","state","plugin","isLoading","ready","Promise","getPlugin","Error","useCoreState","context","current","PdfPermissionFlag","Print","ModifyContents","CopyContents","ModifyAnnotations","FillForms","ExtractForAccessibility","AssembleDocument","PrintHighQuality","ALL_PERMISSION_FLAGS","PERMISSION_FLAG_TO_NAME","getPermissionOverride","overrides","flag","name","getEffectivePermission","documentId","docState","docConfig","permissions","globalConfig","globalPermissions","pdfPermissions","_a","document","AllowAll","docOverride","globalOverride","enforceDocumentPermissions","utilities","$","prop","$$props","Wrapper","Wrapper_1","$$anchor","$0","derived","wrappers","slice","NestedWrapper","Wrapper_2","each","node_5","Utility","i","Utility_1","length","consequent","$$render","alternate","proxy","user_effect","nextUtilities","nextWrappers","reg","plugins","pkg","package","hasAutoMountElements","elements","autoMountElements","call","element","type","push","component","set","node_2","get","autoMountDomElements","latestInit","onInitialized","engine","finalConfig","logger","PluginRegistry","registerPluginBatch","cleanup","async","initialize","isDestroyed","store","getStore","getState","core","unsubscribe","subscribe","action","newState","oldState","isCoreAction","documentOrder","map","docId","filter","doc","then","unsub","catch","console","error","destroy","AutoMount","p","provides","getDocumentId","coreStateRef","effectivePermissions","reduce","acc","getEffectivePermissions","hasPermission","hasAllPermissions","flags","every","canPrint","canModifyContents","canCopyContents","canModifyAnnotations","canFillForms","canExtractForAccessibility","canAssembleDocument","canPrintHighQuality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oH,gBACK3I,IACHmC,QAAuBnC,GAAAkD,EAAAuC,IAAWrD,GAAYhB,EAAAA,kBAAkBI,kBAEtE,EACI,gBAAAoH,gBACK5I,IACHmC,QAAuBnC,GAAAkD,EAAAuC,IAAWrD,GAAYhB,EAAAA,kBAAkBK,UAEtE,EACI,8BAAAoH,gBACK7I,IACHmC,QAAuBnC,GAAAkD,EAAAuC,IAAWrD,GAAYhB,EAAAA,kBAAkBM,wBAEtE,EACI,uBAAAoH,gBACK9I,IACHmC,QAAuBnC,GAAAkD,EAAAuC,IAAWrD,GAAYhB,EAAAA,kBAAkBO,iBAEtE,EACI,uBAAAoH,gBACK/I,IACHmC,QAAuBnC,GAAAkD,EAAAuC,IAAWrD,GAAYhB,EAAAA,kBAAkBQ,iBAEtE,EAEJ,oCCtGiCkG,GACzB,MAAAC,EAAe9G,IAGfmB,YAAsB0F,GAEtBkB,EAAA9F,EAAAO,QAAA,IACJsE,EAAa5G,eAAWiB,GACnB2F,EAAa5G,QAAQd,UAAA6C,EAAAuC,IAAUrD,KAAe,KAC/C,aAIA,WAAAjB,gBACK6H,EACT,EAEJ"}
|
package/dist/svelte/index.js
CHANGED
|
@@ -181,8 +181,10 @@ function useDocumentPermissions(getDocumentId) {
|
|
|
181
181
|
}
|
|
182
182
|
};
|
|
183
183
|
}
|
|
184
|
+
var root_5 = $.from_html(`<!> <!>`, 1);
|
|
184
185
|
function NestedWrapper_1($$anchor, $$props) {
|
|
185
186
|
$.push($$props, true);
|
|
187
|
+
let utilities = $.prop($$props, "utilities", 19, () => []);
|
|
186
188
|
var fragment = $.comment();
|
|
187
189
|
var node = $.first_child(fragment);
|
|
188
190
|
{
|
|
@@ -199,6 +201,9 @@ function NestedWrapper_1($$anchor, $$props) {
|
|
|
199
201
|
get wrappers() {
|
|
200
202
|
return $.get($0);
|
|
201
203
|
},
|
|
204
|
+
get utilities() {
|
|
205
|
+
return utilities();
|
|
206
|
+
},
|
|
202
207
|
children: ($$anchor5, $$slotProps2) => {
|
|
203
208
|
var fragment_3 = $.comment();
|
|
204
209
|
var node_2 = $.first_child(fragment_3);
|
|
@@ -221,9 +226,18 @@ function NestedWrapper_1($$anchor, $$props) {
|
|
|
221
226
|
$.component(node_3, () => $.get(Wrapper), ($$anchor3, Wrapper_2) => {
|
|
222
227
|
Wrapper_2($$anchor3, {
|
|
223
228
|
children: ($$anchor4, $$slotProps) => {
|
|
224
|
-
var fragment_5 =
|
|
229
|
+
var fragment_5 = root_5();
|
|
225
230
|
var node_4 = $.first_child(fragment_5);
|
|
226
231
|
$.snippet(node_4, () => $$props.children ?? $.noop);
|
|
232
|
+
var node_5 = $.sibling(node_4, 2);
|
|
233
|
+
$.each(node_5, 19, utilities, (Utility, i) => `utility-${i}`, ($$anchor5, Utility) => {
|
|
234
|
+
var fragment_6 = $.comment();
|
|
235
|
+
var node_6 = $.first_child(fragment_6);
|
|
236
|
+
$.component(node_6, () => $.get(Utility), ($$anchor6, Utility_1) => {
|
|
237
|
+
Utility_1($$anchor6, {});
|
|
238
|
+
});
|
|
239
|
+
$.append($$anchor5, fragment_6);
|
|
240
|
+
});
|
|
227
241
|
$.append($$anchor4, fragment_5);
|
|
228
242
|
},
|
|
229
243
|
$$slots: { default: true }
|
|
@@ -239,7 +253,7 @@ function NestedWrapper_1($$anchor, $$props) {
|
|
|
239
253
|
$.append($$anchor, fragment);
|
|
240
254
|
$.pop();
|
|
241
255
|
}
|
|
242
|
-
var
|
|
256
|
+
var root_2 = $.from_html(`<!> <!>`, 1);
|
|
243
257
|
function AutoMount($$anchor, $$props) {
|
|
244
258
|
$.push($$props, true);
|
|
245
259
|
let utilities = $.state($.proxy([]));
|
|
@@ -264,7 +278,7 @@ function AutoMount($$anchor, $$props) {
|
|
|
264
278
|
$.set(utilities, nextUtilities, true);
|
|
265
279
|
$.set(wrappers, nextWrappers, true);
|
|
266
280
|
});
|
|
267
|
-
var fragment =
|
|
281
|
+
var fragment = $.comment();
|
|
268
282
|
var node = $.first_child(fragment);
|
|
269
283
|
{
|
|
270
284
|
var consequent = ($$anchor2) => {
|
|
@@ -272,15 +286,27 @@ function AutoMount($$anchor, $$props) {
|
|
|
272
286
|
get wrappers() {
|
|
273
287
|
return $.get(wrappers);
|
|
274
288
|
},
|
|
289
|
+
get utilities() {
|
|
290
|
+
return $.get(utilities);
|
|
291
|
+
},
|
|
275
292
|
get children() {
|
|
276
293
|
return $$props.children;
|
|
277
294
|
}
|
|
278
295
|
});
|
|
279
296
|
};
|
|
280
297
|
var alternate = ($$anchor2) => {
|
|
281
|
-
var fragment_2 =
|
|
298
|
+
var fragment_2 = root_2();
|
|
282
299
|
var node_1 = $.first_child(fragment_2);
|
|
283
300
|
$.snippet(node_1, () => $$props.children ?? $.noop);
|
|
301
|
+
var node_2 = $.sibling(node_1, 2);
|
|
302
|
+
$.each(node_2, 19, () => $.get(utilities), (Utility, i) => `utility-${i}`, ($$anchor3, Utility) => {
|
|
303
|
+
var fragment_3 = $.comment();
|
|
304
|
+
var node_3 = $.first_child(fragment_3);
|
|
305
|
+
$.component(node_3, () => $.get(Utility), ($$anchor4, Utility_1) => {
|
|
306
|
+
Utility_1($$anchor4, {});
|
|
307
|
+
});
|
|
308
|
+
$.append($$anchor3, fragment_3);
|
|
309
|
+
});
|
|
284
310
|
$.append($$anchor2, fragment_2);
|
|
285
311
|
};
|
|
286
312
|
$.if(node, ($$render) => {
|
|
@@ -288,15 +314,6 @@ function AutoMount($$anchor, $$props) {
|
|
|
288
314
|
else $$render(alternate, false);
|
|
289
315
|
});
|
|
290
316
|
}
|
|
291
|
-
var node_2 = $.sibling(node, 2);
|
|
292
|
-
$.each(node_2, 19, () => $.get(utilities), (Utility, i) => `utility-${i}`, ($$anchor2, Utility) => {
|
|
293
|
-
var fragment_3 = $.comment();
|
|
294
|
-
var node_3 = $.first_child(fragment_3);
|
|
295
|
-
$.component(node_3, () => $.get(Utility), ($$anchor3, Utility_1) => {
|
|
296
|
-
Utility_1($$anchor3, {});
|
|
297
|
-
});
|
|
298
|
-
$.append($$anchor2, fragment_3);
|
|
299
|
-
});
|
|
300
317
|
$.append($$anchor, fragment);
|
|
301
318
|
$.pop();
|
|
302
319
|
}
|