@embedpdf/core
Advanced tools
@@ -1,2 +0,2 @@ | ||
| "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("preact"),n=require("preact/hooks"),i=require("preact/jsx-runtime"),t=require("@embedpdf/core"),s=require("@embedpdf/models"),o=e.createContext({registry:null,coreState:null,isInitializing:!0,pluginsReady:!1,activeDocumentId:null,activeDocument:null,documents:{},documentStates:[]});function r({plugins:s,children:o}){const{utilities:r,wrappers:l}=n.useMemo(()=>{const e=[],n=[];for(const i of s){const s=i.package;if(t.hasAutoMountElements(s)){const i=s.autoMountElements()||[];for(const t of i)"utility"===t.type?e.push(t.component):"wrapper"===t.type&&n.push(t.component)}}return{utilities:e,wrappers:n}},[s]),u=l.reduce((e,n)=>i.jsx(n,{children:e}),o);return i.jsxs(e.Fragment,{children:[u,r.map((e,n)=>i.jsx(e,{},`utility-${n}`))]})}function l(){const e=n.useContext(o);if(void 0===e)throw new Error("useCapability must be used within a PDFContext.Provider");const{registry:i,isInitializing:t}=e;if(t)return e;if(null===i)throw new Error("PDF registry failed to initialize properly");return e}function u(e){const{registry:n}=l();if(null===n)return{plugin:null,isLoading:!0,ready:new Promise(()=>{})};const i=n.getPlugin(e);if(!i)throw new Error(`Plugin ${e} not found`);return{plugin:i,isLoading:!1,ready:i.ready()}}function a(){const{coreState:e}=n.useContext(o);return e}s.PdfPermissionFlag.Print,s.PdfPermissionFlag.ModifyContents,s.PdfPermissionFlag.CopyContents,s.PdfPermissionFlag.ModifyAnnotations,s.PdfPermissionFlag.FillForms,s.PdfPermissionFlag.ExtractForAccessibility,s.PdfPermissionFlag.AssembleDocument,s.PdfPermissionFlag.PrintHighQuality;const c=[s.PdfPermissionFlag.Print,s.PdfPermissionFlag.ModifyContents,s.PdfPermissionFlag.CopyContents,s.PdfPermissionFlag.ModifyAnnotations,s.PdfPermissionFlag.FillForms,s.PdfPermissionFlag.ExtractForAccessibility,s.PdfPermissionFlag.AssembleDocument,s.PdfPermissionFlag.PrintHighQuality],d={[s.PdfPermissionFlag.Print]:"print",[s.PdfPermissionFlag.ModifyContents]:"modifyContents",[s.PdfPermissionFlag.CopyContents]:"copyContents",[s.PdfPermissionFlag.ModifyAnnotations]:"modifyAnnotations",[s.PdfPermissionFlag.FillForms]:"fillForms",[s.PdfPermissionFlag.ExtractForAccessibility]:"extractForAccessibility",[s.PdfPermissionFlag.AssembleDocument]:"assembleDocument",[s.PdfPermissionFlag.PrintHighQuality]:"printHighQuality"};function m(e,n){if(!e)return;if(n in e)return e[n];const i=d[n];return i&&i in e?e[i]:void 0}function P(e,n,i){var t;const o=e.documents[n],r=null==o?void 0:o.permissions,l=e.globalPermissions,u=(null==(t=null==o?void 0:o.document)?void 0:t.permissions)??s.PdfPermissionFlag.AllowAll,a=m(null==r?void 0:r.overrides,i);if(void 0!==a)return a;const c=m(null==l?void 0:l.overrides,i);if(void 0!==c)return c;return!((null==r?void 0:r.enforceDocumentPermissions)??(null==l?void 0:l.enforceDocumentPermissions)??!0)||0!==(u&i)}exports.EmbedPDF=function({engine:e,config:s,logger:l,onInitialized:u,plugins:a,children:c,autoMountDomElements:d=!0}){const[m,P]=n.useState(null),[f,g]=n.useState(null),[y,p]=n.useState(!0),[F,v]=n.useState(!1),A=n.useRef(u);n.useEffect(()=>{A.current=u},[u]),n.useEffect(()=>{const n={...s,logger:(null==s?void 0:s.logger)??l},i=new t.PluginRegistry(e,n);i.registerPluginBatch(a);let o;return(async()=>{var e;if(await i.initialize(),i.isDestroyed())return;const n=i.getStore();g(n.getState().core);const t=n.subscribe((e,i,t)=>{n.isCoreAction(e)&&i.core!==t.core&&g(i.core)});if(await(null==(e=A.current)?void 0:e.call(A,i)),!i.isDestroyed())return i.pluginsReady().then(()=>{i.isDestroyed()||v(!0)}),P(i),p(!1),t;t()})().then(e=>{o=e}).catch(console.error),()=>{null==o||o(),i.destroy(),P(null),g(null),p(!0),v(!1)}},[e,a]);const h=n.useMemo(()=>{const e=(null==f?void 0:f.activeDocumentId)??null,n=(null==f?void 0:f.documents)??{},i=(null==f?void 0:f.documentOrder)??[],t=e&&n[e]?n[e]:null,s=i.map(e=>n[e]).filter(e=>null!=e);return{registry:m,coreState:f,isInitializing:y,pluginsReady:F,activeDocumentId:e,activeDocument:t,documents:n,documentStates:s}},[m,f,y,F]),C="function"==typeof c?c(h):c;return i.jsx(o.Provider,{value:h,children:F&&d?i.jsx(r,{plugins:a,children:C}):C})},exports.PDFContext=o,exports.useCapability=function(e){const{plugin:n,isLoading:i,ready:t}=u(e);if(!n)return{provides:null,isLoading:i,ready:t};if(!n.provides)throw new Error(`Plugin ${e} does not provide a capability`);return{provides:n.provides(),isLoading:i,ready:t}},exports.useCoreState=a,exports.useDocumentPermissions=function(e){const i=a();return n.useMemo(()=>{var n,t;if(!i)return{permissions:s.PdfPermissionFlag.AllowAll,pdfPermissions:s.PdfPermissionFlag.AllowAll,hasPermission:()=>!0,hasAllPermissions:()=>!0,canPrint:!0,canModifyContents:!0,canCopyContents:!0,canModifyAnnotations:!0,canFillForms:!0,canExtractForAccessibility:!0,canAssembleDocument:!0,canPrintHighQuality:!0};const o=function(e,n){return c.reduce((i,t)=>P(e,n,t)?i|t:i,0)}(i,e),r=n=>P(i,e,n);return{permissions:o,pdfPermissions:(null==(t=null==(n=i.documents[e])?void 0:n.document)?void 0:t.permissions)??s.PdfPermissionFlag.AllowAll,hasPermission:r,hasAllPermissions:(...n)=>n.every(n=>P(i,e,n)),canPrint:r(s.PdfPermissionFlag.Print),canModifyContents:r(s.PdfPermissionFlag.ModifyContents),canCopyContents:r(s.PdfPermissionFlag.CopyContents),canModifyAnnotations:r(s.PdfPermissionFlag.ModifyAnnotations),canFillForms:r(s.PdfPermissionFlag.FillForms),canExtractForAccessibility:r(s.PdfPermissionFlag.ExtractForAccessibility),canAssembleDocument:r(s.PdfPermissionFlag.AssembleDocument),canPrintHighQuality:r(s.PdfPermissionFlag.PrintHighQuality)}},[i,e])},exports.useDocumentState=function(e){const i=a();return n.useMemo(()=>i&&e?i.documents[e]??null:null,[i,e])},exports.usePlugin=u,exports.useRegistry=l,exports.useStoreState=function(){const{registry:e}=l(),[i,t]=n.useState(null);return n.useEffect(()=>{if(!e)return;t(e.getStore().getState());const n=e.getStore().subscribe((e,n)=>{t(n)});return()=>n()},[e]),i}; | ||
| "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("preact"),n=require("preact/hooks"),i=require("preact/jsx-runtime"),t=require("@embedpdf/core"),s=require("@embedpdf/models"),o=e.createContext({registry:null,coreState:null,isInitializing:!0,pluginsReady:!1,activeDocumentId:null,activeDocument:null,documents:{},documentStates:[]});function r({plugins:s,children:o}){const{utilities:r,wrappers:l}=n.useMemo(()=>{const e=[],n=[];for(const i of s){const s=i.package;if(t.hasAutoMountElements(s)){const i=s.autoMountElements()||[];for(const t of i)"utility"===t.type?e.push(t.component):"wrapper"===t.type&&n.push(t.component)}}return{utilities:e,wrappers:n}},[s]),u=i.jsxs(e.Fragment,{children:[o,r.map((e,n)=>i.jsx(e,{},`utility-${n}`))]}),a=l.reduce((e,n)=>i.jsx(n,{children:e}),u);return i.jsx(e.Fragment,{children:a})}function l(){const e=n.useContext(o);if(void 0===e)throw new Error("useCapability must be used within a PDFContext.Provider");const{registry:i,isInitializing:t}=e;if(t)return e;if(null===i)throw new Error("PDF registry failed to initialize properly");return e}function u(e){const{registry:n}=l();if(null===n)return{plugin:null,isLoading:!0,ready:new Promise(()=>{})};const i=n.getPlugin(e);if(!i)throw new Error(`Plugin ${e} not found`);return{plugin:i,isLoading:!1,ready:i.ready()}}function a(){const{coreState:e}=n.useContext(o);return e}s.PdfPermissionFlag.Print,s.PdfPermissionFlag.ModifyContents,s.PdfPermissionFlag.CopyContents,s.PdfPermissionFlag.ModifyAnnotations,s.PdfPermissionFlag.FillForms,s.PdfPermissionFlag.ExtractForAccessibility,s.PdfPermissionFlag.AssembleDocument,s.PdfPermissionFlag.PrintHighQuality;const c=[s.PdfPermissionFlag.Print,s.PdfPermissionFlag.ModifyContents,s.PdfPermissionFlag.CopyContents,s.PdfPermissionFlag.ModifyAnnotations,s.PdfPermissionFlag.FillForms,s.PdfPermissionFlag.ExtractForAccessibility,s.PdfPermissionFlag.AssembleDocument,s.PdfPermissionFlag.PrintHighQuality],d={[s.PdfPermissionFlag.Print]:"print",[s.PdfPermissionFlag.ModifyContents]:"modifyContents",[s.PdfPermissionFlag.CopyContents]:"copyContents",[s.PdfPermissionFlag.ModifyAnnotations]:"modifyAnnotations",[s.PdfPermissionFlag.FillForms]:"fillForms",[s.PdfPermissionFlag.ExtractForAccessibility]:"extractForAccessibility",[s.PdfPermissionFlag.AssembleDocument]:"assembleDocument",[s.PdfPermissionFlag.PrintHighQuality]:"printHighQuality"};function m(e,n){if(!e)return;if(n in e)return e[n];const i=d[n];return i&&i in e?e[i]:void 0}function P(e,n,i){var t;const o=e.documents[n],r=null==o?void 0:o.permissions,l=e.globalPermissions,u=(null==(t=null==o?void 0:o.document)?void 0:t.permissions)??s.PdfPermissionFlag.AllowAll,a=m(null==r?void 0:r.overrides,i);if(void 0!==a)return a;const c=m(null==l?void 0:l.overrides,i);if(void 0!==c)return c;return!((null==r?void 0:r.enforceDocumentPermissions)??(null==l?void 0:l.enforceDocumentPermissions)??!0)||0!==(u&i)}exports.EmbedPDF=function({engine:e,config:s,logger:l,onInitialized:u,plugins:a,children:c,autoMountDomElements:d=!0}){const[m,P]=n.useState(null),[f,g]=n.useState(null),[y,p]=n.useState(!0),[F,v]=n.useState(!1),A=n.useRef(u);n.useEffect(()=>{A.current=u},[u]),n.useEffect(()=>{const n={...s,logger:(null==s?void 0:s.logger)??l},i=new t.PluginRegistry(e,n);i.registerPluginBatch(a);let o;return(async()=>{var e;if(await i.initialize(),i.isDestroyed())return;const n=i.getStore();g(n.getState().core);const t=n.subscribe((e,i,t)=>{n.isCoreAction(e)&&i.core!==t.core&&g(i.core)});if(await(null==(e=A.current)?void 0:e.call(A,i)),!i.isDestroyed())return i.pluginsReady().then(()=>{i.isDestroyed()||v(!0)}),P(i),p(!1),t;t()})().then(e=>{o=e}).catch(console.error),()=>{null==o||o(),i.destroy(),P(null),g(null),p(!0),v(!1)}},[e,a]);const h=n.useMemo(()=>{const e=(null==f?void 0:f.activeDocumentId)??null,n=(null==f?void 0:f.documents)??{},i=(null==f?void 0:f.documentOrder)??[],t=e&&n[e]?n[e]:null,s=i.map(e=>n[e]).filter(e=>null!=e);return{registry:m,coreState:f,isInitializing:y,pluginsReady:F,activeDocumentId:e,activeDocument:t,documents:n,documentStates:s}},[m,f,y,F]),x="function"==typeof c?c(h):c;return i.jsx(o.Provider,{value:h,children:F&&d?i.jsx(r,{plugins:a,children:x}):x})},exports.PDFContext=o,exports.useCapability=function(e){const{plugin:n,isLoading:i,ready:t}=u(e);if(!n)return{provides:null,isLoading:i,ready:t};if(!n.provides)throw new Error(`Plugin ${e} does not provide a capability`);return{provides:n.provides(),isLoading:i,ready:t}},exports.useCoreState=a,exports.useDocumentPermissions=function(e){const i=a();return n.useMemo(()=>{var n,t;if(!i)return{permissions:s.PdfPermissionFlag.AllowAll,pdfPermissions:s.PdfPermissionFlag.AllowAll,hasPermission:()=>!0,hasAllPermissions:()=>!0,canPrint:!0,canModifyContents:!0,canCopyContents:!0,canModifyAnnotations:!0,canFillForms:!0,canExtractForAccessibility:!0,canAssembleDocument:!0,canPrintHighQuality:!0};const o=function(e,n){return c.reduce((i,t)=>P(e,n,t)?i|t:i,0)}(i,e),r=n=>P(i,e,n);return{permissions:o,pdfPermissions:(null==(t=null==(n=i.documents[e])?void 0:n.document)?void 0:t.permissions)??s.PdfPermissionFlag.AllowAll,hasPermission:r,hasAllPermissions:(...n)=>n.every(n=>P(i,e,n)),canPrint:r(s.PdfPermissionFlag.Print),canModifyContents:r(s.PdfPermissionFlag.ModifyContents),canCopyContents:r(s.PdfPermissionFlag.CopyContents),canModifyAnnotations:r(s.PdfPermissionFlag.ModifyAnnotations),canFillForms:r(s.PdfPermissionFlag.FillForms),canExtractForAccessibility:r(s.PdfPermissionFlag.ExtractForAccessibility),canAssembleDocument:r(s.PdfPermissionFlag.AssembleDocument),canPrintHighQuality:r(s.PdfPermissionFlag.PrintHighQuality)}},[i,e])},exports.useDocumentState=function(e){const i=a();return n.useMemo(()=>i&&e?i.documents[e]??null:null,[i,e])},exports.usePlugin=u,exports.useRegistry=l,exports.useStoreState=function(){const{registry:e}=l(),[i,t]=n.useState(null);return n.useEffect(()=>{if(!e)return;t(e.getStore().getState());const n=e.getStore().subscribe((e,n)=>{t(n)});return()=>n()},[e]),i}; | ||
| //# sourceMappingURL=index.cjs.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"index.cjs","sources":["../../src/shared/context.ts","../../src/shared/components/auto-mount.tsx","../../src/shared/hooks/use-registry.ts","../../src/shared/hooks/use-plugin.ts","../../src/shared/hooks/use-core-state.ts","../../src/lib/types/permissions.ts","../../src/lib/store/selectors.ts","../../src/shared/components/embed-pdf.tsx","../../src/shared/hooks/use-capability.ts","../../src/shared/hooks/use-document-permissions.ts","../../src/shared/hooks/use-document-state.ts","../../src/shared/hooks/use-store-state.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 { 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 { 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 { 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 { 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 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 { 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","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 { 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"],"names":["PDFContext","createContext","registry","coreState","isInitializing","pluginsReady","activeDocumentId","activeDocument","documents","documentStates","AutoMount","plugins","children","utilities","wrappers","useMemo","reg","pkg","package","hasAutoMountElements","elements","autoMountElements","element","type","push","component","wrappedContent","reduce","content","Wrapper","jsx","Fragment","map","Utility","i","useRegistry","contextValue","useContext","Error","usePlugin","pluginId","plugin","isLoading","ready","Promise","getPlugin","useCoreState","PdfPermissionFlag","Print","ModifyContents","CopyContents","ModifyAnnotations","FillForms","ExtractForAccessibility","AssembleDocument","PrintHighQuality","ALL_PERMISSION_FLAGS","PERMISSION_FLAG_TO_NAME","getPermissionOverride","overrides","flag","name","getEffectivePermission","state","documentId","docState","docConfig","permissions","globalConfig","globalPermissions","pdfPermissions","_a","document","AllowAll","docOverride","globalOverride","enforceDocumentPermissions","engine","config","logger","onInitialized","autoMountDomElements","setRegistry","useState","setCoreState","setIsInitializing","setPluginsReady","initRef","useRef","useEffect","current","finalConfig","pdfViewer","PluginRegistry","registerPluginBatch","cleanup","async","initialize","isDestroyed","store","getStore","getState","core","unsubscribe","subscribe","action","newState","oldState","isCoreAction","call","then","unsub","catch","console","error","destroy","documentOrder","docId","filter","doc","Provider","value","provides","hasPermission","hasAllPermissions","canPrint","canModifyContents","canCopyContents","canModifyAnnotations","canFillForms","canExtractForAccessibility","canAssembleDocument","canPrintHighQuality","effectivePermissions","acc","getEffectivePermissions","_b","flags","every","setState","_action"],"mappings":"8NAgBaA,EAAaC,EAAAA,cAA+B,CACvDC,SAAU,KACVC,UAAW,KACXC,gBAAgB,EAChBC,cAAc,EACdC,iBAAkB,KAClBC,eAAgB,KAChBC,UAAW,CAAA,EACXC,eAAgB,KCfX,SAASC,GAAUC,QAAEA,EAAAC,SAASA,IACnC,MAAMC,UAAEA,EAAAC,SAAWA,GAAaC,EAAAA,QAAQ,KAEtC,MAAMF,EAA6B,GAC7BC,EAAqD,GAE3D,IAAA,MAAWE,KAAOL,EAAS,CACzB,MAAMM,EAAMD,EAAIE,QAChB,GAAIC,EAAAA,qBAAqBF,GAAM,CAC7B,MAAMG,EAAWH,EAAII,qBAAuB,GAE5C,IAAA,MAAWC,KAAWF,EACC,YAAjBE,EAAQC,KACVV,EAAUW,KAAKF,EAAQG,WACG,YAAjBH,EAAQC,MAEjBT,EAASU,KAAKF,EAAQG,UAG5B,CACF,CACA,MAAO,CAAEZ,UAAAA,EAAWC,SAAAA,IACnB,CAACH,IAGEe,EAA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0B,SAU5EkD,gBACAC,kBAPwB,IAAIa,IAC5BA,EAAMC,MAAO9E,GAASE,EAAuB3D,EAAW6D,EAAYJ,IAQpEiE,SAAUF,EAAc5E,EAAAA,kBAAkBC,OAC1C8E,kBAAmBH,EAAc5E,EAAAA,kBAAkBE,gBACnD8E,gBAAiBJ,EAAc5E,EAAAA,kBAAkBG,cACjD8E,qBAAsBL,EAAc5E,EAAAA,kBAAkBI,mBACtD8E,aAAcN,EAAc5E,EAAAA,kBAAkBK,WAC9C8E,2BAA4BP,EAAc5E,EAAAA,kBAAkBM,yBAC5D8E,oBAAqBR,EAAc5E,EAAAA,kBAAkBO,kBACrD8E,oBAAqBT,EAAc5E,EAAAA,kBAAkBQ,oBAEtD,CAACpD,EAAW6D,GACjB,2BC7EO,SAA0BA,GAC/B,MAAM7D,EAAY2C,IAOlB,OALsB/B,EAAAA,QAAQ,IACvBZ,GAAc6D,EACZ7D,EAAUK,UAAUwD,IAAe,KADJ,KAErC,CAAC7D,EAAW6D,GAGjB,kECXO,WACL,MAAM9D,SAAEA,GAAaiC,KACd4B,EAAO4E,GAAYxD,EAAAA,SAA+B,MAgBzD,OAdAM,EAAAA,UAAU,KACR,IAAKvF,EAAU,OAGfyI,EAASzI,EAASkG,WAAWC,YAG7B,MAAME,EAAcrG,EAASkG,WAAWI,UAAU,CAACoC,EAASlC,KAC1DiC,EAASjC,KAGX,MAAO,IAAMH,KACZ,CAACrG,IAEG6D,CACT"} | ||
| {"version":3,"file":"index.cjs","sources":["../../src/shared/context.ts","../../src/shared/components/auto-mount.tsx","../../src/shared/hooks/use-registry.ts","../../src/shared/hooks/use-plugin.ts","../../src/shared/hooks/use-core-state.ts","../../src/lib/types/permissions.ts","../../src/lib/store/selectors.ts","../../src/shared/components/embed-pdf.tsx","../../src/shared/hooks/use-capability.ts","../../src/shared/hooks/use-document-permissions.ts","../../src/shared/hooks/use-document-state.ts","../../src/shared/hooks/use-store-state.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 { 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 { 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 { 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 { 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 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 { 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","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 { 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"],"names":["PDFContext","createContext","registry","coreState","isInitializing","pluginsReady","activeDocumentId","activeDocument","documents","documentStates","AutoMount","plugins","children","utilities","wrappers","useMemo","reg","pkg","package","hasAutoMountElements","elements","autoMountElements","element","type","push","component","contentWithUtilities","Fragment","map","Utility","i","wrappedContent","reduce","content","Wrapper","jsx","useRegistry","contextValue","useContext","Error","usePlugin","pluginId","plugin","isLoading","ready","Promise","getPlugin","useCoreState","PdfPermissionFlag","Print","ModifyContents","CopyContents","ModifyAnnotations","FillForms","ExtractForAccessibility","AssembleDocument","PrintHighQuality","ALL_PERMISSION_FLAGS","PERMISSION_FLAG_TO_NAME","getPermissionOverride","overrides","flag","name","getEffectivePermission","state","documentId","docState","docConfig","permissions","globalConfig","globalPermissions","pdfPermissions","_a","document","AllowAll","docOverride","globalOverride","enforceDocumentPermissions","engine","config","logger","onInitialized","autoMountDomElements","setRegistry","useState","setCoreState","setIsInitializing","setPluginsReady","initRef","useRef","useEffect","current","finalConfig","pdfViewer","PluginRegistry","registerPluginBatch","cleanup","async","initialize","isDestroyed","store","getStore","getState","core","unsubscribe","subscribe","action","newState","oldState","isCoreAction","call","then","unsub","catch","console","error","destroy","documentOrder","docId","filter","doc","Provider","value","provides","hasPermission","hasAllPermissions","canPrint","canModifyContents","canCopyContents","canModifyAnnotations","canFillForms","canExtractForAccessibility","canAssembleDocument","canPrintHighQuality","effectivePermissions","acc","getEffectivePermissions","_b","flags","every","setState","_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c8D,EACZ9D,EAAUK,UAAUyD,IAAe,KADJ,KAErC,CAAC9D,EAAW8D,GAGjB,kECXO,WACL,MAAM/D,SAAEA,GAAakC,KACd4B,EAAO4E,GAAYxD,EAAAA,SAA+B,MAgBzD,OAdAM,EAAAA,UAAU,KACR,IAAKxF,EAAU,OAGf0I,EAAS1I,EAASmG,WAAWC,YAG7B,MAAME,EAActG,EAASmG,WAAWI,UAAU,CAACoC,EAASlC,KAC1DiC,EAASjC,KAGX,MAAO,IAAMH,KACZ,CAACtG,IAEG8D,CACT"} |
| import { createContext, Fragment } from "preact"; | ||
| import { useMemo, useState, useRef, useEffect, useContext } from "preact/hooks"; | ||
| import { jsx, jsxs } from "preact/jsx-runtime"; | ||
| import { jsxs, jsx } from "preact/jsx-runtime"; | ||
| import { hasAutoMountElements, PluginRegistry } from "@embedpdf/core"; | ||
@@ -35,10 +35,11 @@ import { PdfPermissionFlag } from "@embedpdf/models"; | ||
| }, [plugins]); | ||
| const contentWithUtilities = /* @__PURE__ */ jsxs(Fragment, { children: [ | ||
| children, | ||
| utilities.map((Utility, i) => /* @__PURE__ */ jsx(Utility, {}, `utility-${i}`)) | ||
| ] }); | ||
| const wrappedContent = wrappers.reduce( | ||
| (content, Wrapper) => /* @__PURE__ */ jsx(Wrapper, { children: content }), | ||
| children | ||
| contentWithUtilities | ||
| ); | ||
| return /* @__PURE__ */ jsxs(Fragment, { children: [ | ||
| wrappedContent, | ||
| utilities.map((Utility, i) => /* @__PURE__ */ jsx(Utility, {}, `utility-${i}`)) | ||
| ] }); | ||
| return /* @__PURE__ */ jsx(Fragment, { children: wrappedContent }); | ||
| } | ||
@@ -45,0 +46,0 @@ function EmbedPDF({ |
@@ -1,1 +0,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,QAAM,EAAE,WAAW,SAAA,IAAa,QAAQ,MAAM;AAE5C,UAAMA,aAA6B,CAAA;AACnC,UAAMC,YAAqD,CAAA;AAE3D,eAAW,OAAO,SAAS;AACzB,YAAM,MAAM,IAAI;AAChB,UAAI,qBAAqB,GAAG,GAAG;AAC7B,cAAM,WAAW,IAAI,kBAAA,KAAuB,CAAA;AAE5C,mBAAW,WAAW,UAAU;AAC9B,cAAI,QAAQ,SAAS,WAAW;AAC9BD,uBAAU,KAAK,QAAQ,SAAS;AAAA,UAClC,WAAW,QAAQ,SAAS,WAAW;AAErCC,sBAAS,KAAK,QAAQ,SAAS;AAAA,UACjC;AAAA,QACF;AAAA,MACF;AAAA,IACF;AACA,WAAO,EAAE,WAAAD,YAAW,UAAAC,UAAAA;AAAAA,EACtB,GAAG,CAAC,OAAO,CAAC;AAGZ,QAAM,iBAAiB,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AAAA,QACd,4BAA4B;AAAA,QAC5B,qBAAqB;AAAA,QACrB,qBAAqB;AAAA,MAAA;AAAA,IAEzB;AAEA,UAAM,uBAAuB,wBAAwB,WAAW,UAAU;AAC1E,UAAM,mBACJ,qBAAU,UAAU,UAAU,MAA9B,mBAAiC,aAAjC,mBAA2C,gBAAe,kBAAkB;AAE9E,UAAM,gBAAgB,CAAC,SACrB,uBAAuB,WAAW,YAAY,IAAI;AACpD,UAAM,oBAAoB,IAAI,UAC5B,MAAM,MAAM,CAAC,SAAS,uBAAuB,WAAW,YAAY,IAAI,CAAC;AAE3E,WAAO;AAAA,MACL,aAAa;AAAA,MACb;AAAA,MACA;AAAA,MACA;AAAA;AAAA,MAEA,UAAU,cAAc,kBAAkB,KAAK;AAAA,MAC/C,mBAAmB,cAAc,kBAAkB,cAAc;AAAA,MACjE,iBAAiB,cAAc,kBAAkB,YAAY;AAAA,MAC7D,sBAAsB,cAAc,kBAAkB,iBAAiB;AAAA,MACvE,cAAc,cAAc,kBAAkB,SAAS;AAAA,MACvD,4BAA4B,cAAc,kBAAkB,uBAAuB;AAAA,MACnF,qBAAqB,cAAc,kBAAkB,gBAAgB;AAAA,MACrE,qBAAqB,cAAc,kBAAkB,gBAAgB;AAAA,IAAA;AAAA,EAEzE,GAAG,CAAC,WAAW,UAAU,CAAC;AAC5B;"} | ||
| {"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,IAAI;AAChB,UAAI,qBAAqB,GAAG,GAAG;AAC7B,cAAM,WAAW,IAAI,kBAAA,KAAuB,CAAA;AAE5C,mBAAW,WAAW,UAAU;AAC9B,cAAI,QAAQ,SAAS,WAAW;AAC9BD,uBAAU,KAAK,QAAQ,SAAS;AAAA,UAClC,WAAW,QAAQ,SAAS,WAAW;AAErCC,sBAAS,KAAK,QAAQ,SAAS;AAAA,UACjC;AAAA,QACF;AAAA,MACF;AAAA,IACF;AACA,WAAO,EAAE,WAAAD,YAAW,UAAAC,UAAAA;AAAAA,EACtB,GAAG,CAAC,OAAO,CAAC;AAGZ,QAAM,4CACH,UAAA,EACE,UAAA;AAAA,IAAA;AAAA,IACA,UAAU,IAAI,CAAC,SAAS,0BACtB,SAAA,IAAa,WAAW,CAAC,EAAI,CAC/B;AAAA,EAAA,GACH;AAIF,QAAM,iBAAiB,SAAS;A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AuB,wBAAwB,WAAW,UAAU;AAC1E,UAAM,mBACJ,qBAAU,UAAU,UAAU,MAA9B,mBAAiC,aAAjC,mBAA2C,gBAAe,kBAAkB;AAE9E,UAAM,gBAAgB,CAAC,SACrB,uBAAuB,WAAW,YAAY,IAAI;AACpD,UAAM,oBAAoB,IAAI,UAC5B,MAAM,MAAM,CAAC,SAAS,uBAAuB,WAAW,YAAY,IAAI,CAAC;AAE3E,WAAO;AAAA,MACL,aAAa;AAAA,MACb;AAAA,MACA;AAAA,MACA;AAAA;AAAA,MAEA,UAAU,cAAc,kBAAkB,KAAK;AAAA,MAC/C,mBAAmB,cAAc,kBAAkB,cAAc;AAAA,MACjE,iBAAiB,cAAc,kBAAkB,YAAY;AAAA,MAC7D,sBAAsB,cAAc,kBAAkB,iBAAiB;AAAA,MACvE,cAAc,cAAc,kBAAkB,SAAS;AAAA,MACvD,4BAA4B,cAAc,kBAAkB,uBAAuB;AAAA,MACnF,qBAAqB,cAAc,kBAAkB,gBAAgB;AAAA,MACrE,qBAAqB,cAAc,kBAAkB,gBAAgB;AAAA,IAAA;AAAA,EAEzE,GAAG,CAAC,WAAW,UAAU,CAAC;AAC5B;"} |
@@ -1,2 +0,2 @@ | ||
| "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react"),n=require("react/jsx-runtime"),i=require("@embedpdf/core"),t=require("@embedpdf/models"),s=e.createContext({registry:null,coreState:null,isInitializing:!0,pluginsReady:!1,activeDocumentId:null,activeDocument:null,documents:{},documentStates:[]});function o({plugins:t,children:s}){const{utilities:o,wrappers:r}=e.useMemo(()=>{const e=[],n=[];for(const s of t){const t=s.package;if(i.hasAutoMountElements(t)){const i=t.autoMountElements()||[];for(const t of i)"utility"===t.type?e.push(t.component):"wrapper"===t.type&&n.push(t.component)}}return{utilities:e,wrappers:n}},[t]),l=r.reduce((e,i)=>n.jsx(i,{children:e}),s);return n.jsxs(e.Fragment,{children:[l,o.map((e,i)=>n.jsx(e,{},`utility-${i}`))]})}function r(){const n=e.useContext(s);if(void 0===n)throw new Error("useCapability must be used within a PDFContext.Provider");const{registry:i,isInitializing:t}=n;if(t)return n;if(null===i)throw new Error("PDF registry failed to initialize properly");return n}function l(e){const{registry:n}=r();if(null===n)return{plugin:null,isLoading:!0,ready:new Promise(()=>{})};const i=n.getPlugin(e);if(!i)throw new Error(`Plugin ${e} not found`);return{plugin:i,isLoading:!1,ready:i.ready()}}function u(){const{coreState:n}=e.useContext(s);return n}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 a=[t.PdfPermissionFlag.Print,t.PdfPermissionFlag.ModifyContents,t.PdfPermissionFlag.CopyContents,t.PdfPermissionFlag.ModifyAnnotations,t.PdfPermissionFlag.FillForms,t.PdfPermissionFlag.ExtractForAccessibility,t.PdfPermissionFlag.AssembleDocument,t.PdfPermissionFlag.PrintHighQuality],c={[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 d(e,n){if(!e)return;if(n in e)return e[n];const i=c[n];return i&&i in e?e[i]:void 0}function m(e,n,i){var s;const o=e.documents[n],r=null==o?void 0:o.permissions,l=e.globalPermissions,u=(null==(s=null==o?void 0:o.document)?void 0:s.permissions)??t.PdfPermissionFlag.AllowAll,a=d(null==r?void 0:r.overrides,i);if(void 0!==a)return a;const c=d(null==l?void 0:l.overrides,i);if(void 0!==c)return c;return!((null==r?void 0:r.enforceDocumentPermissions)??(null==l?void 0:l.enforceDocumentPermissions)??!0)||0!==(u&i)}exports.EmbedPDF=function({engine:t,config:r,logger:l,onInitialized:u,plugins:a,children:c,autoMountDomElements:d=!0}){const[m,P]=e.useState(null),[f,g]=e.useState(null),[y,p]=e.useState(!0),[F,v]=e.useState(!1),A=e.useRef(u);e.useEffect(()=>{A.current=u},[u]),e.useEffect(()=>{const e={...r,logger:(null==r?void 0:r.logger)??l},n=new i.PluginRegistry(t,e);n.registerPluginBatch(a);let s;return(async()=>{var e;if(await n.initialize(),n.isDestroyed())return;const i=n.getStore();g(i.getState().core);const t=i.subscribe((e,n,t)=>{i.isCoreAction(e)&&n.core!==t.core&&g(n.core)});if(await(null==(e=A.current)?void 0:e.call(A,n)),!n.isDestroyed())return n.pluginsReady().then(()=>{n.isDestroyed()||v(!0)}),P(n),p(!1),t;t()})().then(e=>{s=e}).catch(console.error),()=>{null==s||s(),n.destroy(),P(null),g(null),p(!0),v(!1)}},[t,a]);const h=e.useMemo(()=>{const e=(null==f?void 0:f.activeDocumentId)??null,n=(null==f?void 0:f.documents)??{},i=(null==f?void 0:f.documentOrder)??[],t=e&&n[e]?n[e]:null,s=i.map(e=>n[e]).filter(e=>null!=e);return{registry:m,coreState:f,isInitializing:y,pluginsReady:F,activeDocumentId:e,activeDocument:t,documents:n,documentStates:s}},[m,f,y,F]),C="function"==typeof c?c(h):c;return n.jsx(s.Provider,{value:h,children:F&&d?n.jsx(o,{plugins:a,children:C}):C})},exports.PDFContext=s,exports.useCapability=function(e){const{plugin:n,isLoading:i,ready:t}=l(e);if(!n)return{provides:null,isLoading:i,ready:t};if(!n.provides)throw new Error(`Plugin ${e} does not provide a capability`);return{provides:n.provides(),isLoading:i,ready:t}},exports.useCoreState=u,exports.useDocumentPermissions=function(n){const i=u();return e.useMemo(()=>{var e,s;if(!i)return{permissions:t.PdfPermissionFlag.AllowAll,pdfPermissions:t.PdfPermissionFlag.AllowAll,hasPermission:()=>!0,hasAllPermissions:()=>!0,canPrint:!0,canModifyContents:!0,canCopyContents:!0,canModifyAnnotations:!0,canFillForms:!0,canExtractForAccessibility:!0,canAssembleDocument:!0,canPrintHighQuality:!0};const o=function(e,n){return a.reduce((i,t)=>m(e,n,t)?i|t:i,0)}(i,n),r=e=>m(i,n,e);return{permissions:o,pdfPermissions:(null==(s=null==(e=i.documents[n])?void 0:e.document)?void 0:s.permissions)??t.PdfPermissionFlag.AllowAll,hasPermission:r,hasAllPermissions:(...e)=>e.every(e=>m(i,n,e)),canPrint:r(t.PdfPermissionFlag.Print),canModifyContents:r(t.PdfPermissionFlag.ModifyContents),canCopyContents:r(t.PdfPermissionFlag.CopyContents),canModifyAnnotations:r(t.PdfPermissionFlag.ModifyAnnotations),canFillForms:r(t.PdfPermissionFlag.FillForms),canExtractForAccessibility:r(t.PdfPermissionFlag.ExtractForAccessibility),canAssembleDocument:r(t.PdfPermissionFlag.AssembleDocument),canPrintHighQuality:r(t.PdfPermissionFlag.PrintHighQuality)}},[i,n])},exports.useDocumentState=function(n){const i=u();return e.useMemo(()=>i&&n?i.documents[n]??null:null,[i,n])},exports.usePlugin=l,exports.useRegistry=r,exports.useStoreState=function(){const{registry:n}=r(),[i,t]=e.useState(null);return e.useEffect(()=>{if(!n)return;t(n.getStore().getState());const e=n.getStore().subscribe((e,n)=>{t(n)});return()=>e()},[n]),i}; | ||
| "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react"),n=require("react/jsx-runtime"),i=require("@embedpdf/core"),t=require("@embedpdf/models"),s=e.createContext({registry:null,coreState:null,isInitializing:!0,pluginsReady:!1,activeDocumentId:null,activeDocument:null,documents:{},documentStates:[]});function o({plugins:t,children:s}){const{utilities:o,wrappers:r}=e.useMemo(()=>{const e=[],n=[];for(const s of t){const t=s.package;if(i.hasAutoMountElements(t)){const i=t.autoMountElements()||[];for(const t of i)"utility"===t.type?e.push(t.component):"wrapper"===t.type&&n.push(t.component)}}return{utilities:e,wrappers:n}},[t]),l=n.jsxs(e.Fragment,{children:[s,o.map((e,i)=>n.jsx(e,{},`utility-${i}`))]}),u=r.reduce((e,i)=>n.jsx(i,{children:e}),l);return n.jsx(e.Fragment,{children:u})}function r(){const n=e.useContext(s);if(void 0===n)throw new Error("useCapability must be used within a PDFContext.Provider");const{registry:i,isInitializing:t}=n;if(t)return n;if(null===i)throw new Error("PDF registry failed to initialize properly");return n}function l(e){const{registry:n}=r();if(null===n)return{plugin:null,isLoading:!0,ready:new Promise(()=>{})};const i=n.getPlugin(e);if(!i)throw new Error(`Plugin ${e} not found`);return{plugin:i,isLoading:!1,ready:i.ready()}}function u(){const{coreState:n}=e.useContext(s);return n}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 a=[t.PdfPermissionFlag.Print,t.PdfPermissionFlag.ModifyContents,t.PdfPermissionFlag.CopyContents,t.PdfPermissionFlag.ModifyAnnotations,t.PdfPermissionFlag.FillForms,t.PdfPermissionFlag.ExtractForAccessibility,t.PdfPermissionFlag.AssembleDocument,t.PdfPermissionFlag.PrintHighQuality],c={[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 d(e,n){if(!e)return;if(n in e)return e[n];const i=c[n];return i&&i in e?e[i]:void 0}function m(e,n,i){var s;const o=e.documents[n],r=null==o?void 0:o.permissions,l=e.globalPermissions,u=(null==(s=null==o?void 0:o.document)?void 0:s.permissions)??t.PdfPermissionFlag.AllowAll,a=d(null==r?void 0:r.overrides,i);if(void 0!==a)return a;const c=d(null==l?void 0:l.overrides,i);if(void 0!==c)return c;return!((null==r?void 0:r.enforceDocumentPermissions)??(null==l?void 0:l.enforceDocumentPermissions)??!0)||0!==(u&i)}exports.EmbedPDF=function({engine:t,config:r,logger:l,onInitialized:u,plugins:a,children:c,autoMountDomElements:d=!0}){const[m,P]=e.useState(null),[f,g]=e.useState(null),[y,p]=e.useState(!0),[F,v]=e.useState(!1),A=e.useRef(u);e.useEffect(()=>{A.current=u},[u]),e.useEffect(()=>{const e={...r,logger:(null==r?void 0:r.logger)??l},n=new i.PluginRegistry(t,e);n.registerPluginBatch(a);let s;return(async()=>{var e;if(await n.initialize(),n.isDestroyed())return;const i=n.getStore();g(i.getState().core);const t=i.subscribe((e,n,t)=>{i.isCoreAction(e)&&n.core!==t.core&&g(n.core)});if(await(null==(e=A.current)?void 0:e.call(A,n)),!n.isDestroyed())return n.pluginsReady().then(()=>{n.isDestroyed()||v(!0)}),P(n),p(!1),t;t()})().then(e=>{s=e}).catch(console.error),()=>{null==s||s(),n.destroy(),P(null),g(null),p(!0),v(!1)}},[t,a]);const h=e.useMemo(()=>{const e=(null==f?void 0:f.activeDocumentId)??null,n=(null==f?void 0:f.documents)??{},i=(null==f?void 0:f.documentOrder)??[],t=e&&n[e]?n[e]:null,s=i.map(e=>n[e]).filter(e=>null!=e);return{registry:m,coreState:f,isInitializing:y,pluginsReady:F,activeDocumentId:e,activeDocument:t,documents:n,documentStates:s}},[m,f,y,F]),x="function"==typeof c?c(h):c;return n.jsx(s.Provider,{value:h,children:F&&d?n.jsx(o,{plugins:a,children:x}):x})},exports.PDFContext=s,exports.useCapability=function(e){const{plugin:n,isLoading:i,ready:t}=l(e);if(!n)return{provides:null,isLoading:i,ready:t};if(!n.provides)throw new Error(`Plugin ${e} does not provide a capability`);return{provides:n.provides(),isLoading:i,ready:t}},exports.useCoreState=u,exports.useDocumentPermissions=function(n){const i=u();return e.useMemo(()=>{var e,s;if(!i)return{permissions:t.PdfPermissionFlag.AllowAll,pdfPermissions:t.PdfPermissionFlag.AllowAll,hasPermission:()=>!0,hasAllPermissions:()=>!0,canPrint:!0,canModifyContents:!0,canCopyContents:!0,canModifyAnnotations:!0,canFillForms:!0,canExtractForAccessibility:!0,canAssembleDocument:!0,canPrintHighQuality:!0};const o=function(e,n){return a.reduce((i,t)=>m(e,n,t)?i|t:i,0)}(i,n),r=e=>m(i,n,e);return{permissions:o,pdfPermissions:(null==(s=null==(e=i.documents[n])?void 0:e.document)?void 0:s.permissions)??t.PdfPermissionFlag.AllowAll,hasPermission:r,hasAllPermissions:(...e)=>e.every(e=>m(i,n,e)),canPrint:r(t.PdfPermissionFlag.Print),canModifyContents:r(t.PdfPermissionFlag.ModifyContents),canCopyContents:r(t.PdfPermissionFlag.CopyContents),canModifyAnnotations:r(t.PdfPermissionFlag.ModifyAnnotations),canFillForms:r(t.PdfPermissionFlag.FillForms),canExtractForAccessibility:r(t.PdfPermissionFlag.ExtractForAccessibility),canAssembleDocument:r(t.PdfPermissionFlag.AssembleDocument),canPrintHighQuality:r(t.PdfPermissionFlag.PrintHighQuality)}},[i,n])},exports.useDocumentState=function(n){const i=u();return e.useMemo(()=>i&&n?i.documents[n]??null:null,[i,n])},exports.usePlugin=l,exports.useRegistry=r,exports.useStoreState=function(){const{registry:n}=r(),[i,t]=e.useState(null);return e.useEffect(()=>{if(!n)return;t(n.getStore().getState());const e=n.getStore().subscribe((e,n)=>{t(n)});return()=>e()},[n]),i}; | ||
| //# sourceMappingURL=index.cjs.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"index.cjs","sources":["../../src/shared/context.ts","../../src/shared/components/auto-mount.tsx","../../src/shared/hooks/use-registry.ts","../../src/shared/hooks/use-plugin.ts","../../src/shared/hooks/use-core-state.ts","../../src/lib/types/permissions.ts","../../src/lib/store/selectors.ts","../../src/shared/components/embed-pdf.tsx","../../src/shared/hooks/use-capability.ts","../../src/shared/hooks/use-document-permissions.ts","../../src/shared/hooks/use-document-state.ts","../../src/shared/hooks/use-store-state.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 { 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 { 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 { 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 { 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 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 { 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","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 { 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"],"names":["PDFContext","createContext","registry","coreState","isInitializing","pluginsReady","activeDocumentId","activeDocument","documents","documentStates","AutoMount","plugins","children","utilities","wrappers","useMemo","reg","pkg","package","hasAutoMountElements","elements","autoMountElements","element","type","push","component","wrappedContent","reduce","content","Wrapper","jsx","Fragment","map","Utility","i","useRegistry","contextValue","useContext","Error","usePlugin","pluginId","plugin","isLoading","ready","Promise","getPlugin","useCoreState","PdfPermissionFlag","Print","ModifyContents","CopyContents","ModifyAnnotations","FillForms","ExtractForAccessibility","AssembleDocument","PrintHighQuality","ALL_PERMISSION_FLAGS","PERMISSION_FLAG_TO_NAME","getPermissionOverride","overrides","flag","name","getEffectivePermission","state","documentId","docState","docConfig","permissions","globalConfig","globalPermissions","pdfPermissions","_a","document","AllowAll","docOverride","globalOverride","enforceDocumentPermissions","engine","config","logger","onInitialized","autoMountDomElements","setRegistry","useState","setCoreState","setIsInitializing","setPluginsReady","initRef","useRef","useEffect","current","finalConfig","pdfViewer","PluginRegistry","registerPluginBatch","cleanup","async","initialize","isDestroyed","store","getStore","getState","core","unsubscribe","subscribe","action","newState","oldState","isCoreAction","call","then","unsub","catch","console","error","destroy","documentOrder","docId","filter","doc","Provider","value","provides","hasPermission","hasAllPermissions","canPrint","canModifyContents","canCopyContents","canModifyAnnotations","canFillForms","canExtractForAccessibility","canAssembleDocument","canPrintHighQuality","effectivePermissions","acc","getEffectivePermissions","_b","flags","every","setState","_action"],"mappings":"kMAgBaA,EAAaC,EAAAA,cAA+B,CACvDC,SAAU,KACVC,UAAW,KACXC,gBAAgB,EAChBC,cAAc,EACdC,iBAAkB,KAClBC,eAAgB,KAChBC,UAAW,CAAA,EACXC,eAAgB,KCfX,SAASC,GAAUC,QAAEA,EAAAC,SAASA,IACnC,MAAMC,UAAEA,EAAAC,SAAWA,GAAaC,EAAAA,QAAQ,KAEtC,MAAMF,EAA6B,GAC7BC,EAAqD,GAE3D,IAAA,MAAWE,KAAOL,EAAS,CACzB,MAAMM,EAAMD,EAAIE,QAChB,GAAIC,EAAAA,qBAAqBF,GAAM,CAC7B,MAAMG,EAAWH,EAAII,qBAAuB,GAE5C,IAAA,MAAWC,KAAWF,EACC,YAAjBE,EAAQC,KACVV,EAAUW,KAAKF,EAAQG,WACG,YAAjBH,EAAQC,MAEjBT,EAASU,KAAKF,EAAQG,UAG5B,CACF,CACA,MAAO,CAAEZ,UAAAA,EAAWC,SAAAA,IACnB,CAACH,IAGEe,EAAiBZ,EAASa,OAC9B,CAACC,EAASC,IAAYC,EAAAA,IAACD,GAASjB,SAAAgB,IAChChB,GAGF,cACGmB,WAAA,CACEnB,SAAA,CAAAc,EACAb,EAAUmB,IAAI,CAACC,EAASC,UACtBD,EAAA,GAAa,WAAWC,QAIjC,CCxCO,SAASC,IACd,MAAMC,EAAeC,EAAAA,WAAWrC,GAGhC,QAAqB,IAAjBoC,EACF,MAAM,IAAIE,MAAM,2DAGlB,MAAMpC,SAAEA,EAAAE,eAAUA,GAAmBgC,EAGrC,GAAIhC,EACF,OAAOgC,EAIT,GAAiB,OAAblC,EACF,MAAM,IAAIoC,MAAM,8CAGlB,OAAOF,CACT,CCXO,SAASG,EAAgCC,GAC9C,MAAMtC,SAAEA,GAAaiC,IAErB,GAAiB,OAAbjC,EACF,MAAO,CACLuC,OAAQ,KACRC,WAAW,EACXC,MAAO,IAAIC,QA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Z,GAAc6D,EACZ7D,EAAUK,UAAUwD,IAAe,KADJ,KAErC,CAAC7D,EAAW6D,GAGjB,kECXO,WACL,MAAM9D,SAAEA,GAAaiC,KACd4B,EAAO4E,GAAYxD,EAAAA,SAA+B,MAgBzD,OAdAM,EAAAA,UAAU,KACR,IAAKvF,EAAU,OAGfyI,EAASzI,EAASkG,WAAWC,YAG7B,MAAME,EAAcrG,EAASkG,WAAWI,UAAU,CAACoC,EAASlC,KAC1DiC,EAASjC,KAGX,MAAO,IAAMH,KACZ,CAACrG,IAEG6D,CACT"} | ||
| {"version":3,"file":"index.cjs","sources":["../../src/shared/context.ts","../../src/shared/components/auto-mount.tsx","../../src/shared/hooks/use-registry.ts","../../src/shared/hooks/use-plugin.ts","../../src/shared/hooks/use-core-state.ts","../../src/lib/types/permissions.ts","../../src/lib/store/selectors.ts","../../src/shared/components/embed-pdf.tsx","../../src/shared/hooks/use-capability.ts","../../src/shared/hooks/use-document-permissions.ts","../../src/shared/hooks/use-document-state.ts","../../src/shared/hooks/use-store-state.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 { 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 { 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 { 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 { 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 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 { 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","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 { 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"],"names":["PDFContext","createContext","registry","coreState","isInitializing","pluginsReady","activeDocumentId","activeDocument","documents","documentStates","AutoMount","plugins","children","utilities","wrappers","useMemo","reg","pkg","package","hasAutoMountElements","elements","autoMountElements","element","type","push","component","contentWithUtilities","Fragment","map","Utility","i","wrappedContent","reduce","content","Wrapper","jsx","useRegistry","contextValue","useContext","Error","usePlugin","pluginId","plugin","isLoading","ready","Promise","getPlugin","useCoreState","PdfPermissionFlag","Print","ModifyContents","CopyContents","ModifyAnnotations","FillForms","ExtractForAccessibility","AssembleDocument","PrintHighQuality","ALL_PERMISSION_FLAGS","PERMISSION_FLAG_TO_NAME","getPermissionOverride","overrides","flag","name","getEffectivePermission","state","documentId","docState","docConfig","permissions","globalConfig","globalPermissions","pdfPermissions","_a","document","AllowAll","docOverride","globalOverride","enforceDocumentPermissions","engine","config","logger","onInitialized","autoMountDomElements","setRegistry","useState","setCoreState","setIsInitializing","setPluginsReady","initRef","useRef","useEffect","current","finalConfig","pdfViewer","PluginRegistry","registerPluginBatch","cleanup","async","initialize","isDestroyed","store","getStore","getState","core","unsubscribe","subscribe","action","newState","oldState","isCoreAction","call","then","unsub","catch","console","error","destroy","documentOrder","docId","filter","doc","Provider","value","provides","hasPermission","hasAllPermissions","canPrint","canModifyContents","canCopyContents","canModifyAnnotations","canFillForms","canExtractForAccessibility","canAssembleDocument","canPrintHighQuality","effectivePermissions","acc","getEffectivePermissions","_b","flags","every","setState","_action"],"mappings":"kMAgBaA,EAAaC,EAAAA,cAA+B,CACvDC,SAAU,KACVC,UAAW,KACXC,gBAAgB,EAChBC,cAAc,EACdC,iBAAkB,KAClBC,eAAgB,KAChBC,UAAW,CAAA,EACXC,eAAgB,KCfX,SAASC,GAAUC,QAAEA,EAAAC,SAASA,IACnC,MAAMC,UAAEA,EAAAC,SAAWA,GAAaC,EAAAA,QAAQ,KAEtC,MAAMF,EAA6B,GAC7BC,EAAqD,GAE3D,IAAA,MAAWE,KAAOL,EAAS,CACzB,MAAMM,EAAMD,EAAIE,QAChB,GAAIC,EAAAA,qBAAqBF,GAAM,CAC7B,MAAMG,EAAWH,EAAII,qBAAuB,GAE5C,IAAA,MAAWC,KAAWF,EACC,YAAjBE,EAAQC,KACVV,EAAUW,KAAKF,EAAQG,WACG,YAAjBH,EAAQC,MAEjBT,EAASU,KAAKF,EAAQG,UAG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AAakE,EACb/D,gBATA,OAAAkE,EAAA,OAAAjE,EAAArE,EAAUK,UAAUyD,aAAaQ,eAAjC,EAAAgE,EAA2CrE,cAAepB,EAAAA,kBAAkB0B,SAU5EkD,gBACAC,kBAPwB,IAAIa,IAC5BA,EAAMC,MAAO9E,GAASE,EAAuB5D,EAAW8D,EAAYJ,IAQpEiE,SAAUF,EAAc5E,EAAAA,kBAAkBC,OAC1C8E,kBAAmBH,EAAc5E,EAAAA,kBAAkBE,gBACnD8E,gBAAiBJ,EAAc5E,EAAAA,kBAAkBG,cACjD8E,qBAAsBL,EAAc5E,EAAAA,kBAAkBI,mBACtD8E,aAAcN,EAAc5E,EAAAA,kBAAkBK,WAC9C8E,2BAA4BP,EAAc5E,EAAAA,kBAAkBM,yBAC5D8E,oBAAqBR,EAAc5E,EAAAA,kBAAkBO,kBACrD8E,oBAAqBT,EAAc5E,EAAAA,kBAAkBQ,oBAEtD,CAACrD,EAAW8D,GACjB,2BC7EO,SAA0BA,GAC/B,MAAM9D,EAAY4C,IAOlB,OALsBhC,EAAAA,QAAQ,IACvBZ,GAAc8D,EACZ9D,EAAUK,UAAUyD,IAAe,KADJ,KAErC,CAAC9D,EAAW8D,GAGjB,kECXO,WACL,MAAM/D,SAAEA,GAAakC,KACd4B,EAAO4E,GAAYxD,EAAAA,SAA+B,MAgBzD,OAdAM,EAAAA,UAAU,KACR,IAAKxF,EAAU,OAGf0I,EAAS1I,EAASmG,WAAWC,YAG7B,MAAME,EAActG,EAASmG,WAAWI,UAAU,CAACoC,EAASlC,KAC1DiC,EAASjC,KAGX,MAAO,IAAMH,KACZ,CAACtG,IAEG8D,CACT"} |
| import { createContext, useMemo, Fragment, useState, useRef, useEffect, useContext } from "react"; | ||
| import { jsx, jsxs } from "react/jsx-runtime"; | ||
| import { jsxs, jsx } from "react/jsx-runtime"; | ||
| import { hasAutoMountElements, PluginRegistry } from "@embedpdf/core"; | ||
@@ -34,10 +34,11 @@ import { PdfPermissionFlag } from "@embedpdf/models"; | ||
| }, [plugins]); | ||
| const contentWithUtilities = /* @__PURE__ */ jsxs(Fragment, { children: [ | ||
| children, | ||
| utilities.map((Utility, i) => /* @__PURE__ */ jsx(Utility, {}, `utility-${i}`)) | ||
| ] }); | ||
| const wrappedContent = wrappers.reduce( | ||
| (content, Wrapper) => /* @__PURE__ */ jsx(Wrapper, { children: content }), | ||
| children | ||
| contentWithUtilities | ||
| ); | ||
| return /* @__PURE__ */ jsxs(Fragment, { children: [ | ||
| wrappedContent, | ||
| utilities.map((Utility, i) => /* @__PURE__ */ jsx(Utility, {}, `utility-${i}`)) | ||
| ] }); | ||
| return /* @__PURE__ */ jsx(Fragment, { children: wrappedContent }); | ||
| } | ||
@@ -44,0 +45,0 @@ function EmbedPDF({ |
@@ -1,1 +0,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,EACl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AAc,kBAAkB,iBAAiB;AAAA,MACvE,cAAc,cAAc,kBAAkB,SAAS;AAAA,MACvD,4BAA4B,cAAc,kBAAkB,uBAAuB;AAAA,MACnF,qBAAqB,cAAc,kBAAkB,gBAAgB;AAAA,MACrE,qBAAqB,cAAc,kBAAkB,gBAAgB;AAAA,IAAA;AAAA,EAEzE,GAAG,CAAC,WAAW,UAAU,CAAC;AAC5B;"} | ||
| {"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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AAAA,MACnF,qBAAqB,cAAc,kBAAkB,gBAAgB;AAAA,MACrE,qBAAqB,cAAc,kBAAkB,gBAAgB;AAAA,IAAA;AAAA,EAEzE,GAAG,CAAC,WAAW,UAAU,CAAC;AAC5B;"} |
@@ -5,2 +5,3 @@ import { Component, Snippet } from 'svelte'; | ||
| wrappers: Component[]; | ||
| utilities?: Component[]; | ||
| children?: Snippet; | ||
@@ -7,0 +8,0 @@ } |
@@ -1,2 +0,2 @@ | ||
| "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 d(){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 c=[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,d=(null==(r=null==o?void 0:o.document)?void 0:r.permissions)??t.PdfPermissionFlag.AllowAll,c=a(null==s?void 0:s.overrides,i);if(void 0!==c)return c;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!==(d&i)}function m(e,t){r.push(t,!0);var n=r.comment(),i=r.first_child(n),o=e=>{const n=r.derived(()=>t.wrappers[0]);var i=r.comment(),o=r.first_child(i);r.component(o,()=>r.get(n),(e,n)=>{n(e,{children:(e,n)=>{{let n=r.derived(()=>t.wrappers.slice(1));m(e,{get wrappers(){return r.get(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,i)},s=e=>{const n=r.derived(()=>t.wrappers[0]);var i=r.comment(),o=r.first_child(i);r.component(o,()=>r.get(n),(e,n)=>{n(e,{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}})}),r.append(e,i)};r.if(i,e=>{t.wrappers.length>1?e(o):e(s,!1)}),r.append(e,n),r.pop()}var p=r.from_html("<!> <!>",1);function f(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=p(),l=r.first_child(s),d=e=>{m(e,{get wrappers(){return r.get(o)},get children(){return t.children}})},c=e=>{var n=r.comment(),i=r.first_child(n);r.snippet(i,()=>t.children??r.noop),r.append(e,n)};r.if(l,e=>{r.get(o).length>0?e(d):e(c,!1)});var u=r.sibling(l,2);r.each(u,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,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(),d=r.first_child(l),c=e=>{f(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(d,e=>{o.pluginsReady&&i()?e(c):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=d,exports.useDocumentPermissions=function(e){const n=d(),i=r.derived(e),o=r.derived(()=>n.current),s=r.derived(()=>r.get(o)?function(e,t){return c.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=d(),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; | ||
| "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; | ||
| //# sourceMappingURL=index.cjs.map |
@@ -1,1 +0,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,QAEdH,CACT,CC3BgB,SAAAO,IACR,MAAAC,EAAUX,WAGV,WAAAY,GACK,OAAAD,EAAQlB,SACjB,EAEJ,CCGSoB,EAAAA,kBAAkBC,MACTD,EAAAA,kBAAkBE,eACpBF,EAAAA,kBAAkBG,aACbH,EAAAA,kBAAkBI,kBAC1BJ,EAAAA,kBAAkBK,UACJL,EAA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AAMC,MAAOpG,IAAAoB,EAAA+B,IAAUpF,IAAYmC,EAAAkB,EAAA+B,IAAuBpF,GAAAqD,EAAA+B,IAAWhD,GAAYH,IAW7E,YAAAqG,gBACKtI,IACHmC,QAAuBnC,GAAAqD,EAAA+B,IAAWhD,GAAYhB,EAAAA,kBAAkBC,MAEtE,EACI,qBAAAkH,gBACKvI,IACHmC,QAAuBnC,GAAAqD,EAAA+B,IAAWhD,GAAYhB,EAAAA,kBAAkBE,eAEtE,EACI,mBAAAkH,gBACKxI,IACHmC,QAAuBnC,GAAAqD,EAAA+B,IAAWhD,GAAYhB,EAAAA,kBAAkBG,aAEtE,EACI,wBAAAkH,gBACKzI,IACHmC,QAAuBnC,GAAAqD,EAAA+B,IAAWhD,GAAYhB,EAAAA,kBAAkBI,kBAEtE,EACI,gBAAAkH,gBACK1I,IACHmC,QAAuBnC,GAAAqD,EAAA+B,IAAWhD,GAAYhB,EAAAA,kBAAkBK,UAEtE,EACI,8BAAAkH,gBACK3I,IACHmC,QAAuBnC,GAAAqD,EAAA+B,IAAWhD,GAAYhB,EAAAA,kBAAkBM,wBAEtE,EACI,uBAAAkH,gBACK5I,IACHmC,QAAuBnC,GAAAqD,EAAA+B,IAAWhD,GAAYhB,EAAAA,kBAAkBO,iBAEtE,EACI,uBAAAkH,gBACK7I,IACHmC,QAAuBnC,GAAAqD,EAAA+B,IAAWhD,GAAYhB,EAAAA,kBAAkBQ,iBAEtE,EAEJ,oCCtGiCgG,GACzB,MAAAC,EAAe5G,IAGfmB,YAAsBwF,GAEtBkB,EAAAzF,EAAAC,QAAA,IACJuE,EAAa1G,eAAWiB,GACnByF,EAAa1G,QAAQd,UAAAgD,EAAA+B,IAAUhD,KAAe,KAC/C,aAIA,WAAAjB,gBACK2H,EACT,EAEJ"} | ||
| {"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","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,QA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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"} |
+30
-13
@@ -184,4 +184,6 @@ import * as $ from "svelte/internal/client"; | ||
| } | ||
| var root_5 = $.from_html(`<!> <!>`, 1); | ||
| function NestedWrapper_1($$anchor, $$props) { | ||
| $.push($$props, true); | ||
| let utilities = $.prop($$props, "utilities", 19, () => []); | ||
| var fragment = $.comment(); | ||
@@ -203,2 +205,5 @@ var node = $.first_child(fragment); | ||
| }, | ||
| get utilities() { | ||
| return utilities(); | ||
| }, | ||
| children: ($$anchor5, $$slotProps2) => { | ||
@@ -226,5 +231,14 @@ var fragment_3 = $.comment(); | ||
| children: ($$anchor4, $$slotProps) => { | ||
| var fragment_5 = $.comment(); | ||
| var fragment_5 = root_5(); | ||
| var node_4 = $.first_child(fragment_5); | ||
| $.snippet(node_4, () => $$props.children ?? $.noop); | ||
| var node_5 = $.sibling(node_4, 2); | ||
| $.each(node_5, 19, utilities, (Utility, i) => `utility-${i}`, ($$anchor5, Utility) => { | ||
| var fragment_6 = $.comment(); | ||
| var node_6 = $.first_child(fragment_6); | ||
| $.component(node_6, () => $.get(Utility), ($$anchor6, Utility_1) => { | ||
| Utility_1($$anchor6, {}); | ||
| }); | ||
| $.append($$anchor5, fragment_6); | ||
| }); | ||
| $.append($$anchor4, fragment_5); | ||
@@ -245,3 +259,3 @@ }, | ||
| } | ||
| var root = $.from_html(`<!> <!>`, 1); | ||
| var root_2 = $.from_html(`<!> <!>`, 1); | ||
| function AutoMount($$anchor, $$props) { | ||
@@ -271,3 +285,3 @@ $.push($$props, true); | ||
| }); | ||
| var fragment = root(); | ||
| var fragment = $.comment(); | ||
| var node = $.first_child(fragment); | ||
@@ -280,2 +294,5 @@ { | ||
| }, | ||
| get utilities() { | ||
| return $.get(utilities); | ||
| }, | ||
| get children() { | ||
@@ -287,5 +304,14 @@ return $$props.children; | ||
| var alternate = ($$anchor2) => { | ||
| var fragment_2 = $.comment(); | ||
| var fragment_2 = root_2(); | ||
| var node_1 = $.first_child(fragment_2); | ||
| $.snippet(node_1, () => $$props.children ?? $.noop); | ||
| var node_2 = $.sibling(node_1, 2); | ||
| $.each(node_2, 19, () => $.get(utilities), (Utility, i) => `utility-${i}`, ($$anchor3, Utility) => { | ||
| var fragment_3 = $.comment(); | ||
| var node_3 = $.first_child(fragment_3); | ||
| $.component(node_3, () => $.get(Utility), ($$anchor4, Utility_1) => { | ||
| Utility_1($$anchor4, {}); | ||
| }); | ||
| $.append($$anchor3, fragment_3); | ||
| }); | ||
| $.append($$anchor2, fragment_2); | ||
@@ -298,11 +324,2 @@ }; | ||
| } | ||
| var node_2 = $.sibling(node, 2); | ||
| $.each(node_2, 19, () => $.get(utilities), (Utility, i) => `utility-${i}`, ($$anchor2, Utility) => { | ||
| var fragment_3 = $.comment(); | ||
| var node_3 = $.first_child(fragment_3); | ||
| $.component(node_3, () => $.get(Utility), ($$anchor3, Utility_1) => { | ||
| Utility_1($$anchor3, {}); | ||
| }); | ||
| $.append($$anchor2, fragment_3); | ||
| }); | ||
| $.append($$anchor, fragment); | ||
@@ -309,0 +326,0 @@ $.pop(); |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"index.js","sources":["../../src/svelte/hooks/use-registry.svelte.ts","../../src/svelte/hooks/use-plugin.svelte.ts","../../src/svelte/hooks/use-capability.svelte.ts","../../src/svelte/hooks/use-core-state.svelte.ts","../../src/svelte/hooks/use-document-state.svelte.ts","../../src/lib/types/permissions.ts","../../src/lib/store/selectors.ts","../../src/svelte/hooks/use-document-permissions.svelte.ts","../../src/svelte/components/NestedWrapper.svelte","../../src/svelte/components/AutoMount.svelte","../../src/svelte/components/EmbedPDF.svelte"],"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 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 { 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 { 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","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 { 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","<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"],"names":["$$anchor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tB,mBAAW,YAAY;AACvB,mBAAW,iBAAiB;AAC5B,mBAAW,eAAe;AAC1B,mBAAW,mBAAmB;AAC9B,mBAAW,iBAAiB;AAC5B,mBAAW,YAAS,CAAA;AACpB,mBAAW,iBAAc,CAAA;AAAA,MAC3B;AAAA,IACF;AAAA,EACF,CAAC;;;;;AAIA,gBAASA,WAAA;AAAA;;;;;;0DAA6B,UAAU;;;;;;;;;sDAE/B,UAAU;;;;UAHzB,WAAW,gBAAgB,uBAAoB,UAAA,UAAA;AAAA,UAAA,UAAA,WAAA,KAAA;AAAA;;;;AAF5C;"} | ||
| {"version":3,"file":"index.js","sources":["../../src/svelte/hooks/use-registry.svelte.ts","../../src/svelte/hooks/use-plugin.svelte.ts","../../src/svelte/hooks/use-capability.svelte.ts","../../src/svelte/hooks/use-core-state.svelte.ts","../../src/svelte/hooks/use-document-state.svelte.ts","../../src/lib/types/permissions.ts","../../src/lib/store/selectors.ts","../../src/svelte/hooks/use-document-permissions.svelte.ts","../../src/svelte/components/NestedWrapper.svelte","../../src/svelte/components/AutoMount.svelte","../../src/svelte/components/EmbedPDF.svelte"],"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 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 { 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 { 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","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 { 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","<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"],"names":["$$anchor","NestedWrapper"],"mappings":";;;;MAea;EACX,UAAU;AAAA,EACV,WAAW;AAAA,EACX,gBAAgB;AAAA,EAChB,cAAc;AAAA,EACd,kBAAkB;AAAA,EAClB,gBAAgB;AAAA,EAChB;EACA;;AAQW,MAAA,oBAAoB;SCpBjB,UAAgC,UAAmB;AACzD,QAAA,EAAA,aAAa;AAEf,QAAA,kBACJ,QAAQ,MACR,WAAW,MACX,OAAA,IAAW,QAAA,MAAoB;AAAA,EAAA,CAAE,EAAA,CAAA;MAG/B,aAAa,MAAM;WACd;AAAA,EACT;AAEM,QAAA,SAAS,SAAS,UAAa,QAAQ;AAExC,MAAA,CAAA,QAAQ;AACD,UAAA,IAAA,gBAAgB,QAAQ,YAAA;AAAA,EACpC;AAEA,QAAM,SAAS;AACf,QAAM,YAAY;AAClB,QAAM,QAAQ,OAAO,MAAA;SAEd;AACT;SCxBgB,cAAoC,UAAmB;QAC/D,IAAI,UAAa,QAAQ;QAEzB;IACJ,UAAU;AAAA,IACV,WAAW;AAAA,IACX,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from '../../lib/index.ts'; | ||
| }; | ||
| declare var __VLS_7: {}, __VLS_9: {}; | ||
| declare var __VLS_8: {}, __VLS_10: {}; | ||
| type __VLS_Slots = {} & { | ||
| default?: (props: typeof __VLS_7) => any; | ||
| default?: (props: typeof __VLS_8) => any; | ||
| } & { | ||
| default?: (props: typeof __VLS_9) => any; | ||
| default?: (props: typeof __VLS_10) => any; | ||
| }; | ||
@@ -12,0 +12,0 @@ declare const __VLS_base: import('vue').DefineComponent<__VLS_Props, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>; |
| type __VLS_Props = { | ||
| wrappers: any[]; | ||
| utilities?: any[]; | ||
| }; | ||
@@ -4,0 +5,0 @@ declare var __VLS_14: {}, __VLS_16: {}; |
@@ -1,2 +0,2 @@ | ||
| "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),n=require("@embedpdf/models"),t=require("@embedpdf/core"),o=Symbol("pdfKey");function i(){const n=e.inject(o);if(!n)throw new Error("useRegistry must be used inside <EmbedPDF>");return n}function s(){const{coreState:e}=i();return e}n.PdfPermissionFlag.Print,n.PdfPermissionFlag.ModifyContents,n.PdfPermissionFlag.CopyContents,n.PdfPermissionFlag.ModifyAnnotations,n.PdfPermissionFlag.FillForms,n.PdfPermissionFlag.ExtractForAccessibility,n.PdfPermissionFlag.AssembleDocument,n.PdfPermissionFlag.PrintHighQuality;const r=[n.PdfPermissionFlag.Print,n.PdfPermissionFlag.ModifyContents,n.PdfPermissionFlag.CopyContents,n.PdfPermissionFlag.ModifyAnnotations,n.PdfPermissionFlag.FillForms,n.PdfPermissionFlag.ExtractForAccessibility,n.PdfPermissionFlag.AssembleDocument,n.PdfPermissionFlag.PrintHighQuality],l={[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"};function u(e,n){if(!e)return;if(n in e)return e[n];const t=l[n];return t&&t in e?e[t]:void 0}function a(e,t,o){var i;const s=e.documents[t],r=null==s?void 0:s.permissions,l=e.globalPermissions,a=(null==(i=null==s?void 0:s.document)?void 0:i.permissions)??n.PdfPermissionFlag.AllowAll,c=u(null==r?void 0:r.overrides,o);if(void 0!==c)return c;const d=u(null==l?void 0:l.overrides,o);if(void 0!==d)return d;return!((null==r?void 0:r.enforceDocumentPermissions)??(null==l?void 0:l.enforceDocumentPermissions)??!0)||0!==(a&o)}function c(n){const{registry:t}=i(),o=e.shallowRef(null),s=e.ref(!0),r=e.ref(new Promise(()=>{})),l=()=>{var e;if(!t.value)return;const i=t.value.getPlugin(n);if(!i)throw new Error(`Plugin ${n} not found`);o.value=i,s.value=!1,r.value=(null==(e=i.ready)?void 0:e.call(i))??Promise.resolve()};return e.onMounted(l),e.watch(t,l),{plugin:o,isLoading:s,ready:r}}const d=e.defineComponent({__name:"nested-wrapper",props:{wrappers:{}},setup:n=>(t,o)=>{const i=e.resolveComponent("NestedWrapper",!0);return e.openBlock(),e.createBlock(e.resolveDynamicComponent(n.wrappers[0]),null,{default:e.withCtx(()=>[n.wrappers.length>1?(e.openBlock(),e.createBlock(i,{key:0,wrappers:n.wrappers.slice(1)},{default:e.withCtx(()=>[e.renderSlot(t.$slots,"default")]),_:3},8,["wrappers"])):e.renderSlot(t.$slots,"default",{key:1})]),_:3})}}),m=e.defineComponent({__name:"auto-mount",props:{plugins:{}},setup(n){const o=n,i=e.computed(()=>{const e=[],n=[];for(const i of o.plugins){const o=i.package;if(t.hasAutoMountElements(o)){const t=o.autoMountElements()||[];for(const o of t)"utility"===o.type?e.push(o.component):"wrapper"===o.type&&n.push(o.component)}}return{utilities:e,wrappers:n}});return(n,t)=>(e.openBlock(),e.createElementBlock(e.Fragment,null,[i.value.wrappers.length>0?(e.openBlock(),e.createBlock(d,{key:0,wrappers:i.value.wrappers},{default:e.withCtx(()=>[e.renderSlot(n.$slots,"default")]),_:3},8,["wrappers"])):e.renderSlot(n.$slots,"default",{key:1}),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(i.value.utilities,(n,t)=>(e.openBlock(),e.createBlock(e.resolveDynamicComponent(n),{key:`utility-${t}`}))),128))],64))}}),p=e.defineComponent({__name:"embed-pdf",props:{engine:{},config:{},logger:{},plugins:{},onInitialized:{},autoMountDomElements:{type:Boolean,default:!0}},setup(n){const i=n,s=e.shallowRef(null),r=e.ref(null),l=e.ref(!0),u=e.ref(!1),a=e.computed(()=>{var e;return(null==(e=r.value)?void 0:e.activeDocumentId)??null}),c=e.computed(()=>{var e;return(null==(e=r.value)?void 0:e.documents)??{}}),d=e.computed(()=>{var e;return(null==(e=r.value)?void 0:e.documentOrder)??[]}),p=e.computed(()=>{const e=a.value,n=c.value;return e&&n[e]?n[e]:null}),f=e.computed(()=>{const e=c.value;return d.value.map(n=>e[n]).filter(e=>null!=e)});return e.provide(o,{registry:s,coreState:r,isInitializing:l,pluginsReady:u,activeDocumentId:a,activeDocument:p,documents:c,documentStates:f}),e.onMounted(async()=>{var n,o;const a={...i.config,logger:(null==(n=i.config)?void 0:n.logger)??i.logger},c=new t.PluginRegistry(i.engine,a);if(c.registerPluginBatch(i.plugins),await c.initialize(),c.isDestroyed())return;const d=c.getStore();r.value=d.getState().core;const m=d.subscribe((e,n,t)=>{d.isCoreAction(e)&&n.core!==t.core&&(r.value=n.core)});await(null==(o=i.onInitialized)?void 0:o.call(i,c)),c.isDestroyed()?m():(s.value=c,l.value=!1,c.pluginsReady().then(()=>{c.isDestroyed()||(u.value=!0)}),e.onBeforeUnmount(()=>{var e;m(),null==(e=s.value)||e.destroy()}))}),(t,o)=>u.value&&n.autoMountDomElements?(e.openBlock(),e.createBlock(m,{key:0,plugins:n.plugins},{default:e.withCtx(()=>[e.renderSlot(t.$slots,"default",{registry:s.value,coreState:r.value,isInitializing:l.value,pluginsReady:u.value,activeDocumentId:a.value,activeDocument:p.value,documents:c.value,documentStates:f.value})]),_:3},8,["plugins"])):e.renderSlot(t.$slots,"default",{key:1,registry:s.value,coreState:r.value,isInitializing:l.value,pluginsReady:u.value,activeDocumentId:a.value,activeDocument:p.value,documents:c.value,documentStates:f.value})}});exports.EmbedPDF=p,exports.useCapability=function(n){const{plugin:t,isLoading:o,ready:i}=c(n);return{provides:e.computed(()=>{if(!t.value)return null;if(!t.value.provides)throw new Error(`Plugin ${n} does not implement provides()`);return t.value.provides()}),isLoading:o,ready:i}},exports.useCoreState=s,exports.useDocumentPermissions=function(t){const o=s();return e.computed(()=>{var i,s;const l=e.toValue(t),u=o.value;if(!u)return{permissions:n.PdfPermissionFlag.AllowAll,pdfPermissions:n.PdfPermissionFlag.AllowAll,hasPermission:()=>!0,hasAllPermissions:()=>!0,canPrint:!0,canModifyContents:!0,canCopyContents:!0,canModifyAnnotations:!0,canFillForms:!0,canExtractForAccessibility:!0,canAssembleDocument:!0,canPrintHighQuality:!0};const c=function(e,n){return r.reduce((t,o)=>a(e,n,o)?t|o:t,0)}(u,l),d=e=>a(u,l,e);return{permissions:c,pdfPermissions:(null==(s=null==(i=u.documents[l])?void 0:i.document)?void 0:s.permissions)??n.PdfPermissionFlag.AllowAll,hasPermission:d,hasAllPermissions:(...e)=>e.every(e=>a(u,l,e)),canPrint:d(n.PdfPermissionFlag.Print),canModifyContents:d(n.PdfPermissionFlag.ModifyContents),canCopyContents:d(n.PdfPermissionFlag.CopyContents),canModifyAnnotations:d(n.PdfPermissionFlag.ModifyAnnotations),canFillForms:d(n.PdfPermissionFlag.FillForms),canExtractForAccessibility:d(n.PdfPermissionFlag.ExtractForAccessibility),canAssembleDocument:d(n.PdfPermissionFlag.AssembleDocument),canPrintHighQuality:d(n.PdfPermissionFlag.PrintHighQuality)}})},exports.useDocumentState=function(n){const t=s();return e.computed(()=>{const o=t.value,i=e.toValue(n);return o&&i?o.documents[i]??null:null})},exports.usePlugin=c,exports.useRegistry=i,exports.useStoreState=function(){const{registry:n}=i(),t=e.ref();function o(){return n.value?(t.value=n.value.getStore().getState(),n.value.getStore().subscribe((e,n)=>t.value=n)):()=>{}}let s=o();return e.watch(n,()=>{null==s||s(),s=o()}),e.onBeforeUnmount(()=>null==s?void 0:s()),t}; | ||
| "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),n=require("@embedpdf/models"),t=require("@embedpdf/core"),o=Symbol("pdfKey");function i(){const n=e.inject(o);if(!n)throw new Error("useRegistry must be used inside <EmbedPDF>");return n}function s(){const{coreState:e}=i();return e}n.PdfPermissionFlag.Print,n.PdfPermissionFlag.ModifyContents,n.PdfPermissionFlag.CopyContents,n.PdfPermissionFlag.ModifyAnnotations,n.PdfPermissionFlag.FillForms,n.PdfPermissionFlag.ExtractForAccessibility,n.PdfPermissionFlag.AssembleDocument,n.PdfPermissionFlag.PrintHighQuality;const r=[n.PdfPermissionFlag.Print,n.PdfPermissionFlag.ModifyContents,n.PdfPermissionFlag.CopyContents,n.PdfPermissionFlag.ModifyAnnotations,n.PdfPermissionFlag.FillForms,n.PdfPermissionFlag.ExtractForAccessibility,n.PdfPermissionFlag.AssembleDocument,n.PdfPermissionFlag.PrintHighQuality],l={[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"};function u(e,n){if(!e)return;if(n in e)return e[n];const t=l[n];return t&&t in e?e[t]:void 0}function a(e,t,o){var i;const s=e.documents[t],r=null==s?void 0:s.permissions,l=e.globalPermissions,a=(null==(i=null==s?void 0:s.document)?void 0:i.permissions)??n.PdfPermissionFlag.AllowAll,c=u(null==r?void 0:r.overrides,o);if(void 0!==c)return c;const d=u(null==l?void 0:l.overrides,o);if(void 0!==d)return d;return!((null==r?void 0:r.enforceDocumentPermissions)??(null==l?void 0:l.enforceDocumentPermissions)??!0)||0!==(a&o)}function c(n){const{registry:t}=i(),o=e.shallowRef(null),s=e.ref(!0),r=e.ref(new Promise(()=>{})),l=()=>{var e;if(!t.value)return;const i=t.value.getPlugin(n);if(!i)throw new Error(`Plugin ${n} not found`);o.value=i,s.value=!1,r.value=(null==(e=i.ready)?void 0:e.call(i))??Promise.resolve()};return e.onMounted(l),e.watch(t,l),{plugin:o,isLoading:s,ready:r}}const d=e.defineComponent({__name:"nested-wrapper",props:{wrappers:{},utilities:{}},setup:n=>(t,o)=>{const i=e.resolveComponent("NestedWrapper",!0);return e.openBlock(),e.createBlock(e.resolveDynamicComponent(n.wrappers[0]),null,{default:e.withCtx(()=>[n.wrappers.length>1?(e.openBlock(),e.createBlock(i,{key:0,wrappers:n.wrappers.slice(1),utilities:n.utilities},{default:e.withCtx(()=>[e.renderSlot(t.$slots,"default")]),_:3},8,["wrappers","utilities"])):(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[e.renderSlot(t.$slots,"default"),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(n.utilities,(n,t)=>(e.openBlock(),e.createBlock(e.resolveDynamicComponent(n),{key:`utility-${t}`}))),128))],64))]),_:3})}}),m=e.defineComponent({__name:"auto-mount",props:{plugins:{}},setup(n){const o=n,i=e.computed(()=>{const e=[],n=[];for(const i of o.plugins){const o=i.package;if(t.hasAutoMountElements(o)){const t=o.autoMountElements()||[];for(const o of t)"utility"===o.type?e.push(o.component):"wrapper"===o.type&&n.push(o.component)}}return{utilities:e,wrappers:n}});return(n,t)=>i.value.wrappers.length>0?(e.openBlock(),e.createBlock(d,{key:0,wrappers:i.value.wrappers,utilities:i.value.utilities},{default:e.withCtx(()=>[e.renderSlot(n.$slots,"default")]),_:3},8,["wrappers","utilities"])):(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[e.renderSlot(n.$slots,"default"),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(i.value.utilities,(n,t)=>(e.openBlock(),e.createBlock(e.resolveDynamicComponent(n),{key:`utility-${t}`}))),128))],64))}}),p=e.defineComponent({__name:"embed-pdf",props:{engine:{},config:{},logger:{},plugins:{},onInitialized:{},autoMountDomElements:{type:Boolean,default:!0}},setup(n){const i=n,s=e.shallowRef(null),r=e.ref(null),l=e.ref(!0),u=e.ref(!1),a=e.computed(()=>{var e;return(null==(e=r.value)?void 0:e.activeDocumentId)??null}),c=e.computed(()=>{var e;return(null==(e=r.value)?void 0:e.documents)??{}}),d=e.computed(()=>{var e;return(null==(e=r.value)?void 0:e.documentOrder)??[]}),p=e.computed(()=>{const e=a.value,n=c.value;return e&&n[e]?n[e]:null}),f=e.computed(()=>{const e=c.value;return d.value.map(n=>e[n]).filter(e=>null!=e)});return e.provide(o,{registry:s,coreState:r,isInitializing:l,pluginsReady:u,activeDocumentId:a,activeDocument:p,documents:c,documentStates:f}),e.onMounted(async()=>{var n,o;const a={...i.config,logger:(null==(n=i.config)?void 0:n.logger)??i.logger},c=new t.PluginRegistry(i.engine,a);if(c.registerPluginBatch(i.plugins),await c.initialize(),c.isDestroyed())return;const d=c.getStore();r.value=d.getState().core;const m=d.subscribe((e,n,t)=>{d.isCoreAction(e)&&n.core!==t.core&&(r.value=n.core)});await(null==(o=i.onInitialized)?void 0:o.call(i,c)),c.isDestroyed()?m():(s.value=c,l.value=!1,c.pluginsReady().then(()=>{c.isDestroyed()||(u.value=!0)}),e.onBeforeUnmount(()=>{var e;m(),null==(e=s.value)||e.destroy()}))}),(t,o)=>u.value&&n.autoMountDomElements?(e.openBlock(),e.createBlock(m,{key:0,plugins:n.plugins},{default:e.withCtx(()=>[e.renderSlot(t.$slots,"default",{registry:s.value,coreState:r.value,isInitializing:l.value,pluginsReady:u.value,activeDocumentId:a.value,activeDocument:p.value,documents:c.value,documentStates:f.value})]),_:3},8,["plugins"])):e.renderSlot(t.$slots,"default",{key:1,registry:s.value,coreState:r.value,isInitializing:l.value,pluginsReady:u.value,activeDocumentId:a.value,activeDocument:p.value,documents:c.value,documentStates:f.value})}});exports.EmbedPDF=p,exports.useCapability=function(n){const{plugin:t,isLoading:o,ready:i}=c(n);return{provides:e.computed(()=>{if(!t.value)return null;if(!t.value.provides)throw new Error(`Plugin ${n} does not implement provides()`);return t.value.provides()}),isLoading:o,ready:i}},exports.useCoreState=s,exports.useDocumentPermissions=function(t){const o=s();return e.computed(()=>{var i,s;const l=e.toValue(t),u=o.value;if(!u)return{permissions:n.PdfPermissionFlag.AllowAll,pdfPermissions:n.PdfPermissionFlag.AllowAll,hasPermission:()=>!0,hasAllPermissions:()=>!0,canPrint:!0,canModifyContents:!0,canCopyContents:!0,canModifyAnnotations:!0,canFillForms:!0,canExtractForAccessibility:!0,canAssembleDocument:!0,canPrintHighQuality:!0};const c=function(e,n){return r.reduce((t,o)=>a(e,n,o)?t|o:t,0)}(u,l),d=e=>a(u,l,e);return{permissions:c,pdfPermissions:(null==(s=null==(i=u.documents[l])?void 0:i.document)?void 0:s.permissions)??n.PdfPermissionFlag.AllowAll,hasPermission:d,hasAllPermissions:(...e)=>e.every(e=>a(u,l,e)),canPrint:d(n.PdfPermissionFlag.Print),canModifyContents:d(n.PdfPermissionFlag.ModifyContents),canCopyContents:d(n.PdfPermissionFlag.CopyContents),canModifyAnnotations:d(n.PdfPermissionFlag.ModifyAnnotations),canFillForms:d(n.PdfPermissionFlag.FillForms),canExtractForAccessibility:d(n.PdfPermissionFlag.ExtractForAccessibility),canAssembleDocument:d(n.PdfPermissionFlag.AssembleDocument),canPrintHighQuality:d(n.PdfPermissionFlag.PrintHighQuality)}})},exports.useDocumentState=function(n){const t=s();return e.computed(()=>{const o=t.value,i=e.toValue(n);return o&&i?o.documents[i]??null:null})},exports.usePlugin=c,exports.useRegistry=i,exports.useStoreState=function(){const{registry:n}=i(),t=e.ref();function o(){return n.value?(t.value=n.value.getStore().getState(),n.value.getStore().subscribe((e,n)=>t.value=n)):()=>{}}let s=o();return e.watch(n,()=>{null==s||s(),s=o()}),e.onBeforeUnmount(()=>null==s?void 0:s()),t}; | ||
| //# sourceMappingURL=index.cjs.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"index.cjs","sources":["../../src/vue/context.ts","../../src/vue/composables/use-registry.ts","../../src/vue/composables/use-core-state.ts","../../src/lib/types/permissions.ts","../../src/lib/store/selectors.ts","../../src/vue/composables/use-plugin.ts","../../src/vue/components/nested-wrapper.vue","../../src/vue/components/auto-mount.vue","../../src/vue/components/embed-pdf.vue","../../src/vue/composables/use-capability.ts","../../src/vue/composables/use-document-permissions.ts","../../src/vue/composables/use-document-state.ts","../../src/vue/composables/use-store-state.ts"],"sourcesContent":["import { InjectionKey, Ref, ShallowRef } from 'vue';\nimport type { PluginRegistry, CoreState, DocumentState } from '@embedpdf/core';\n\nexport interface PDFContextState {\n registry: ShallowRef<PluginRegistry | null>;\n coreState: Ref<CoreState | null>;\n isInitializing: Ref<boolean>;\n pluginsReady: Ref<boolean>;\n\n // Convenience accessors (always safe to use)\n activeDocumentId: Ref<string | null>;\n activeDocument: Ref<DocumentState | null>;\n documents: Ref<Record<string, DocumentState>>;\n documentStates: Ref<DocumentState[]>;\n}\n\nexport const pdfKey: InjectionKey<PDFContextState> = Symbol('pdfKey');\n","import { inject } from 'vue';\nimport { pdfKey } from '../context';\n\nexport function useRegistry() {\n const ctx = inject(pdfKey);\n if (!ctx) throw new Error('useRegistry must be used inside <EmbedPDF>');\n return ctx;\n}\n","import { Ref } from 'vue';\nimport { type CoreState } from '@embedpdf/core';\nimport { useRegistry } from './use-registry';\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(): Ref<CoreState | null> {\n const { coreState } = useRegistry();\n return coreState;\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 { shallowRef, ref, onMounted, watch, type ShallowRef, type Ref } from 'vue';\nimport type { BasePlugin } from '@embedpdf/core';\nimport { useRegistry } from './use-registry';\n\nexport interface PluginState<T extends BasePlugin> {\n plugin: ShallowRef<T | null>;\n isLoading: Ref<boolean>;\n ready: Ref<Promise<void>>;\n}\n\nexport function usePlugin<T extends BasePlugin>(pluginId: T['id']): PluginState<T> {\n const { registry } = useRegistry();\n\n const plugin = shallowRef(null) as ShallowRef<T | null>;\n\n const isLoading = ref(true);\n const ready = ref<Promise<void>>(new Promise(() => {}));\n\n const load = () => {\n if (!registry.value) return;\n\n const p = registry.value.getPlugin<T>(pluginId);\n if (!p) throw new Error(`Plugin ${pluginId} not found`);\n\n plugin.value = p;\n isLoading.value = false;\n ready.value = p.ready?.() ?? Promise.resolve();\n };\n\n onMounted(load);\n watch(registry, load);\n\n return { plugin, isLoading, ready };\n}\n","<script setup lang=\"ts\">\ndefineProps<{\n wrappers: any[];\n}>();\n</script>\n\n<template>\n <component :is=\"wrappers[0]\">\n <NestedWrapper v-if=\"wrappers.length > 1\" :wrappers=\"wrappers.slice(1)\">\n <slot />\n </NestedWrapper>\n <slot v-else />\n </component>\n</template>\n","<script setup lang=\"ts\">\nimport { computed } from 'vue';\nimport { hasAutoMountElements, type PluginBatchRegistration, type IPlugin } from '@embedpdf/core';\nimport NestedWrapper from './nested-wrapper.vue';\n\nconst props = defineProps<{\n plugins: PluginBatchRegistration<IPlugin<any>, any>[];\n}>();\n\nconst elements = computed(() => {\n const utilities: any[] = [];\n const wrappers: any[] = [];\n\n for (const reg of props.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 wrappers.push(element.component);\n }\n }\n }\n }\n\n return { utilities, wrappers };\n});\n</script>\n\n<template>\n <NestedWrapper v-if=\"elements.wrappers.length > 0\" :wrappers=\"elements.wrappers\">\n <slot />\n </NestedWrapper>\n <slot v-else />\n\n <component\n v-for=\"(utility, index) in elements.utilities\"\n :key=\"`utility-${index}`\"\n :is=\"utility\"\n />\n</template>\n","<script setup lang=\"ts\">\nimport { ref, provide, onMounted, onBeforeUnmount, shallowRef, computed } from 'vue';\nimport {\n PluginRegistry,\n PluginBatchRegistrations,\n PluginRegistryConfig,\n CoreState,\n DocumentState,\n} from '@embedpdf/core';\nimport { Logger, PdfEngine } from '@embedpdf/models';\nimport { pdfKey, PDFContextState } from '../context';\nimport AutoMount from './auto-mount.vue';\n\nexport type { PluginBatchRegistrations };\n\nconst props = withDefaults(\n defineProps<{\n engine: PdfEngine;\n /** Registry configuration including logger, permissions, and defaults. */\n config?: PluginRegistryConfig;\n /** @deprecated Use config.logger instead. Will be removed in next major version. */\n logger?: Logger;\n plugins: PluginBatchRegistrations;\n onInitialized?: (registry: PluginRegistry) => Promise<void>;\n autoMountDomElements?: boolean;\n }>(),\n {\n autoMountDomElements: true,\n },\n);\n\n/* reactive state */\nconst registry = shallowRef<PluginRegistry | null>(null);\nconst coreState = ref<CoreState | null>(null);\nconst isInit = ref(true);\nconst pluginsOk = ref(false);\n\n// Compute convenience accessors\nconst activeDocumentId = computed(() => coreState.value?.activeDocumentId ?? null);\nconst documents = computed(() => coreState.value?.documents ?? {});\nconst documentOrder = computed(() => coreState.value?.documentOrder ?? []);\n\nconst activeDocument = computed(() => {\n const docId = activeDocumentId.value;\n const docs = documents.value;\n return docId && docs[docId] ? docs[docId] : null;\n});\n\nconst documentStates = computed(() => {\n const docs = documents.value;\n const order = documentOrder.value;\n return order\n .map((docId) => docs[docId])\n .filter((doc): doc is DocumentState => doc !== null && doc !== undefined);\n});\n\n/* expose to children */\nprovide<PDFContextState>(pdfKey, {\n registry,\n coreState,\n isInitializing: isInit,\n pluginsReady: pluginsOk,\n activeDocumentId,\n activeDocument,\n documents,\n documentStates,\n});\n\nonMounted(async () => {\n // Merge deprecated logger prop into config (config.logger takes precedence)\n const finalConfig: PluginRegistryConfig = {\n ...props.config,\n logger: props.config?.logger ?? props.logger,\n };\n const reg = new PluginRegistry(props.engine, finalConfig);\n reg.registerPluginBatch(props.plugins);\n await reg.initialize();\n\n if (reg.isDestroyed()) {\n return;\n }\n\n const store = reg.getStore();\n coreState.value = 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 coreState.value = newState.core;\n }\n });\n\n await props.onInitialized?.(reg);\n\n if (reg.isDestroyed()) {\n unsubscribe();\n return;\n }\n\n registry.value = reg;\n isInit.value = false;\n\n reg.pluginsReady().then(() => {\n if (!reg.isDestroyed()) {\n pluginsOk.value = true;\n }\n });\n\n onBeforeUnmount(() => {\n unsubscribe();\n registry.value?.destroy();\n });\n});\n</script>\n\n<template>\n <AutoMount v-if=\"pluginsOk && autoMountDomElements\" :plugins=\"plugins\">\n <!-- scoped slot keeps API parity with React version -->\n <slot\n :registry=\"registry\"\n :coreState=\"coreState\"\n :isInitializing=\"isInit\"\n :pluginsReady=\"pluginsOk\"\n :activeDocumentId=\"activeDocumentId\"\n :activeDocument=\"activeDocument\"\n :documents=\"documents\"\n :documentStates=\"documentStates\"\n />\n </AutoMount>\n\n <!-- No auto-mount or not ready yet -->\n <slot\n v-else\n :registry=\"registry\"\n :coreState=\"coreState\"\n :isInitializing=\"isInit\"\n :pluginsReady=\"pluginsOk\"\n :activeDocumentId=\"activeDocumentId\"\n :activeDocument=\"activeDocument\"\n :documents=\"documents\"\n :documentStates=\"documentStates\"\n />\n</template>\n","import type { BasePlugin } from '@embedpdf/core';\nimport { computed, type Ref } from 'vue';\nimport { usePlugin } from './use-plugin';\n\nexport interface CapabilityState<C> {\n provides: Ref<C | null>;\n isLoading: Ref<boolean>;\n ready: Ref<Promise<void>>;\n}\n\n/**\n * Access the public capability exposed by a plugin.\n *\n * @example\n * const { provides: zoom } = useCapability<ZoomPlugin>(ZoomPlugin.id);\n * zoom.value?.zoomIn();\n */\nexport function useCapability<T extends BasePlugin>(\n pluginId: T['id'],\n): CapabilityState<ReturnType<NonNullable<T['provides']>>> {\n const { plugin, isLoading, ready } = usePlugin<T>(pluginId);\n\n const provides = computed(() => {\n if (!plugin.value) return null;\n if (!plugin.value.provides) {\n throw new Error(`Plugin ${pluginId} does not implement provides()`);\n }\n return plugin.value.provides() as ReturnType<NonNullable<T['provides']>>;\n });\n\n return { provides, isLoading, ready };\n}\n","import { computed, toValue, type MaybeRefOrGetter, ComputedRef } from 'vue';\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 * Composable 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 (can be ref, computed, getter, or plain value).\n * @returns A computed ref with the permission object.\n */\nexport function useDocumentPermissions(\n documentId: MaybeRefOrGetter<string>,\n): ComputedRef<DocumentPermissions> {\n const coreState = useCoreState();\n\n return computed(() => {\n const docId = toValue(documentId);\n const state = coreState.value;\n\n if (!state) {\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(state, docId);\n const pdfPermissions =\n state.documents[docId]?.document?.permissions ?? PdfPermissionFlag.AllowAll;\n\n const hasPermission = (flag: PdfPermissionFlag) => getEffectivePermission(state, docId, flag);\n const hasAllPermissions = (...flags: PdfPermissionFlag[]) =>\n flags.every((flag) => getEffectivePermission(state, docId, flag));\n\n return {\n permissions: effectivePermissions,\n pdfPermissions,\n hasPermission,\n hasAllPermissions,\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 });\n}\n","import { computed, toValue, type MaybeRefOrGetter } from 'vue';\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 (can be ref, computed, getter, or plain value).\n * @returns A computed ref containing the DocumentState object or null if not found.\n */\nexport function useDocumentState(documentId: MaybeRefOrGetter<string | null>) {\n const coreState = useCoreState();\n\n const documentState = computed(() => {\n const core = coreState.value;\n const docId = toValue(documentId);\n\n if (!core || !docId) return null;\n return core.documents[docId] ?? null;\n });\n\n return documentState;\n}\n","import { ref, onMounted, onBeforeUnmount, watch } from 'vue';\nimport type { CoreState, StoreState } from '@embedpdf/core';\nimport { useRegistry } from './use-registry';\n\n/**\n * Reactive getter for the *entire* global store.\n * Re‑emits whenever any slice changes.\n *\n * @example\n * const state = useStoreState(); // Ref<StoreState<CoreState>>\n * console.log(state.value.core.scale);\n */\nexport function useStoreState<T = CoreState>() {\n const { registry } = useRegistry();\n const state = ref<StoreState<T>>();\n\n function attach() {\n if (!registry.value) return () => {};\n\n // initial snapshot\n state.value = registry.value.getStore().getState() as StoreState<T>;\n\n // live updates\n return registry.value\n .getStore()\n .subscribe((_action, newState) => (state.value = newState as StoreState<T>));\n }\n\n /* attach now and re‑attach if registry instance ever changes */\n let unsubscribe = attach();\n watch(registry, () => {\n unsubscribe?.();\n unsubscribe = attach();\n });\n\n onBeforeUnmount(() => unsubscribe?.());\n\n return state;\n}\n"],"names":["pdfKey","Symbol","useRegistry","ctx","inject","Error","useCoreState","coreState","PdfPermissionFlag","Print","ModifyContents","CopyContents","ModifyAnnotations","FillForms","ExtractForAccessibility","AssembleDocument","PrintHighQuality","ALL_PERMISSION_FLAGS","PERMISSION_FLAG_TO_NAME","getPermissionOverride","overrides","flag","name","getEffectivePermission","state","documentId","docState","documents","docConfig","permissions","globalConfig","globalPermissions","pdfPermissions","_a","document","AllowAll","docOverride","globalOverride","enforceDocumentPermissions","usePlugin","pluginId","registry","plugin","shallowRef","isLoading","ref","ready","Promise","load","value","p","getPlugin","call","resolve","onMounted","watch","_openBlock","_createBlock","_resolveDynamicComponent","__props","wrappers","length","_component_NestedWrapper","slice","_renderSlot","_ctx","$slots","key","props","elements","computed","utilities","reg","plugins","pkg","package","hasAutoMountElements","autoMountElements","element","type","push","component","NestedWrapper","_createElementBlock","_Fragment","utility","index","isInit","pluginsOk","activeDocumentId","documentOrder","activeDocument","docId","docs","documentStates","map","filter","doc","provide","isInitializing","pluginsReady","async","finalConfig","config","logger","PluginRegistry","engine","registerPluginBatch","initialize","isDestroyed","store","getStore","getState","core","unsubscribe","subscribe","action","newState","oldState","isCoreAction","_b","onInitialized","then","onBeforeUnmount","destroy","autoMountDomElements","AutoMount","provides","toValue","hasPermission","hasAllPermissions","canPrint","canModifyContents","canCopyContents","canModifyAnnotations","canFillForms","canExtractForAccessibility","canAssembleDocument","canPrintHighQuality","effectivePermissions","reduce","acc","getEffectivePermissions","flags","every","attach","_action"],"mappings":"iKAgBaA,EAAwCC,OAAO,UCbrD,SAASC,IACd,MAAMC,EAAMC,EAAAA,OAAOJ,GACnB,IAAKG,EAAK,MAAM,IAAIE,MAAM,8CAC1B,OAAOF,CACT,CCGO,SAASG,IACd,MAAMC,UAAEA,GAAcL,IACtB,OAAOK,CACT,CCMSC,EAAAA,kBAAkBC,MACTD,EAAAA,kBAAkBE,eACpBF,EAAAA,kBAAkBG,aACbH,EAAAA,kBAAkBI,kBAC1BJ,EAAAA,kBAAkBK,UACJL,EAAAA,kBAAkBM,wBACzBN,EAAAA,kBAAkBO,iBAClBP,EAAAA,kBAAkBQ,iBAyC/B,MAAMC,EAA4C,CACvDT,EAAAA,kBAAkBC,MAClBD,EAAAA,kBAAkBE,eAClBF,EAAAA,kBAAkBG,aAClBH,EAAAA,kBAAkBI,kBAClBJ,EAAAA,kBAAkBK,UAClBL,EAAAA,kBAAkBM,wBAClBN,EAAAA,kBAAkBO,iBAClBP,oBAAkBQ,kBAoBPE,EAAqE,CAChF,CAACV,EAAAA,kBAAkBC,OAAQ,QAC3B,CAACD,EAAAA,kBAAkBE,gBAAiB,iBACpC,CAACF,EAAAA,kBAAkBG,cAAe,eAClC,CAACH,EA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MACjB2C,EAAQoC,EAAAA,QAAQvG,GAEtB,OAAKwF,GAASrB,EACPqB,EAAKtF,UAAUiE,IAAU,KADJ,MAKhC,kECTO,WACL,MAAMnD,SAAEA,GAAavC,IACfsB,EAAQqB,EAAAA,MAEd,SAASoG,IACP,OAAKxG,EAASQ,OAGdzB,EAAMyB,MAAQR,EAASQ,MAAM8D,WAAWC,WAGjCvE,EAASQ,MACb8D,WACAI,UAAU,CAAC+B,EAAS7B,IAAc7F,EAAMyB,MAAQoE,IARvB,MAS9B,CAGA,IAAIH,EAAc+B,IAQlB,OAPA1F,EAAAA,MAAMd,EAAU,KACd,MAAAyE,GAAAA,IACAA,EAAc+B,MAGhBtB,EAAAA,gBAAgB,IAAM,MAAAT,OAAA,EAAAA,KAEf1F,CACT"} | ||
| {"version":3,"file":"index.cjs","sources":["../../src/vue/context.ts","../../src/vue/composables/use-registry.ts","../../src/vue/composables/use-core-state.ts","../../src/lib/types/permissions.ts","../../src/lib/store/selectors.ts","../../src/vue/composables/use-plugin.ts","../../src/vue/components/nested-wrapper.vue","../../src/vue/components/auto-mount.vue","../../src/vue/components/embed-pdf.vue","../../src/vue/composables/use-capability.ts","../../src/vue/composables/use-document-permissions.ts","../../src/vue/composables/use-document-state.ts","../../src/vue/composables/use-store-state.ts"],"sourcesContent":["import { InjectionKey, Ref, ShallowRef } from 'vue';\nimport type { PluginRegistry, CoreState, DocumentState } from '@embedpdf/core';\n\nexport interface PDFContextState {\n registry: ShallowRef<PluginRegistry | null>;\n coreState: Ref<CoreState | null>;\n isInitializing: Ref<boolean>;\n pluginsReady: Ref<boolean>;\n\n // Convenience accessors (always safe to use)\n activeDocumentId: Ref<string | null>;\n activeDocument: Ref<DocumentState | null>;\n documents: Ref<Record<string, DocumentState>>;\n documentStates: Ref<DocumentState[]>;\n}\n\nexport const pdfKey: InjectionKey<PDFContextState> = Symbol('pdfKey');\n","import { inject } from 'vue';\nimport { pdfKey } from '../context';\n\nexport function useRegistry() {\n const ctx = inject(pdfKey);\n if (!ctx) throw new Error('useRegistry must be used inside <EmbedPDF>');\n return ctx;\n}\n","import { Ref } from 'vue';\nimport { type CoreState } from '@embedpdf/core';\nimport { useRegistry } from './use-registry';\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(): Ref<CoreState | null> {\n const { coreState } = useRegistry();\n return coreState;\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 { shallowRef, ref, onMounted, watch, type ShallowRef, type Ref } from 'vue';\nimport type { BasePlugin } from '@embedpdf/core';\nimport { useRegistry } from './use-registry';\n\nexport interface PluginState<T extends BasePlugin> {\n plugin: ShallowRef<T | null>;\n isLoading: Ref<boolean>;\n ready: Ref<Promise<void>>;\n}\n\nexport function usePlugin<T extends BasePlugin>(pluginId: T['id']): PluginState<T> {\n const { registry } = useRegistry();\n\n const plugin = shallowRef(null) as ShallowRef<T | null>;\n\n const isLoading = ref(true);\n const ready = ref<Promise<void>>(new Promise(() => {}));\n\n const load = () => {\n if (!registry.value) return;\n\n const p = registry.value.getPlugin<T>(pluginId);\n if (!p) throw new Error(`Plugin ${pluginId} not found`);\n\n plugin.value = p;\n isLoading.value = false;\n ready.value = p.ready?.() ?? Promise.resolve();\n };\n\n onMounted(load);\n watch(registry, load);\n\n return { plugin, isLoading, ready };\n}\n","<script setup lang=\"ts\">\ndefineProps<{\n wrappers: any[];\n utilities?: any[];\n}>();\n</script>\n\n<template>\n <component :is=\"wrappers[0]\">\n <NestedWrapper v-if=\"wrappers.length > 1\" :wrappers=\"wrappers.slice(1)\" :utilities=\"utilities\">\n <slot />\n </NestedWrapper>\n <template v-else>\n <slot />\n <!-- Render utilities inside the innermost wrapper -->\n <component v-for=\"(utility, index) in utilities\" :key=\"`utility-${index}`\" :is=\"utility\" />\n </template>\n </component>\n</template>\n","<script setup lang=\"ts\">\nimport { computed } from 'vue';\nimport { hasAutoMountElements, type PluginBatchRegistration, type IPlugin } from '@embedpdf/core';\nimport NestedWrapper from './nested-wrapper.vue';\n\nconst props = defineProps<{\n plugins: PluginBatchRegistration<IPlugin<any>, any>[];\n}>();\n\nconst elements = computed(() => {\n const utilities: any[] = [];\n const wrappers: any[] = [];\n\n for (const reg of props.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 wrappers.push(element.component);\n }\n }\n }\n }\n\n return { utilities, wrappers };\n});\n</script>\n\n<template>\n <NestedWrapper\n v-if=\"elements.wrappers.length > 0\"\n :wrappers=\"elements.wrappers\"\n :utilities=\"elements.utilities\"\n >\n <slot />\n </NestedWrapper>\n <template v-else>\n <!-- No wrappers - render children and utilities directly -->\n <slot />\n <component\n v-for=\"(utility, index) in elements.utilities\"\n :key=\"`utility-${index}`\"\n :is=\"utility\"\n />\n </template>\n</template>\n","<script setup lang=\"ts\">\nimport { ref, provide, onMounted, onBeforeUnmount, shallowRef, computed } from 'vue';\nimport {\n PluginRegistry,\n PluginBatchRegistrations,\n PluginRegistryConfig,\n CoreState,\n DocumentState,\n} from '@embedpdf/core';\nimport { Logger, PdfEngine } from '@embedpdf/models';\nimport { pdfKey, PDFContextState } from '../context';\nimport AutoMount from './auto-mount.vue';\n\nexport type { PluginBatchRegistrations };\n\nconst props = withDefaults(\n defineProps<{\n engine: PdfEngine;\n /** Registry configuration including logger, permissions, and defaults. */\n config?: PluginRegistryConfig;\n /** @deprecated Use config.logger instead. Will be removed in next major version. */\n logger?: Logger;\n plugins: PluginBatchRegistrations;\n onInitialized?: (registry: PluginRegistry) => Promise<void>;\n autoMountDomElements?: boolean;\n }>(),\n {\n autoMountDomElements: true,\n },\n);\n\n/* reactive state */\nconst registry = shallowRef<PluginRegistry | null>(null);\nconst coreState = ref<CoreState | null>(null);\nconst isInit = ref(true);\nconst pluginsOk = ref(false);\n\n// Compute convenience accessors\nconst activeDocumentId = computed(() => coreState.value?.activeDocumentId ?? null);\nconst documents = computed(() => coreState.value?.documents ?? {});\nconst documentOrder = computed(() => coreState.value?.documentOrder ?? []);\n\nconst activeDocument = computed(() => {\n const docId = activeDocumentId.value;\n const docs = documents.value;\n return docId && docs[docId] ? docs[docId] : null;\n});\n\nconst documentStates = computed(() => {\n const docs = documents.value;\n const order = documentOrder.value;\n return order\n .map((docId) => docs[docId])\n .filter((doc): doc is DocumentState => doc !== null && doc !== undefined);\n});\n\n/* expose to children */\nprovide<PDFContextState>(pdfKey, {\n registry,\n coreState,\n isInitializing: isInit,\n pluginsReady: pluginsOk,\n activeDocumentId,\n activeDocument,\n documents,\n documentStates,\n});\n\nonMounted(async () => {\n // Merge deprecated logger prop into config (config.logger takes precedence)\n const finalConfig: PluginRegistryConfig = {\n ...props.config,\n logger: props.config?.logger ?? props.logger,\n };\n const reg = new PluginRegistry(props.engine, finalConfig);\n reg.registerPluginBatch(props.plugins);\n await reg.initialize();\n\n if (reg.isDestroyed()) {\n return;\n }\n\n const store = reg.getStore();\n coreState.value = 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 coreState.value = newState.core;\n }\n });\n\n await props.onInitialized?.(reg);\n\n if (reg.isDestroyed()) {\n unsubscribe();\n return;\n }\n\n registry.value = reg;\n isInit.value = false;\n\n reg.pluginsReady().then(() => {\n if (!reg.isDestroyed()) {\n pluginsOk.value = true;\n }\n });\n\n onBeforeUnmount(() => {\n unsubscribe();\n registry.value?.destroy();\n });\n});\n</script>\n\n<template>\n <AutoMount v-if=\"pluginsOk && autoMountDomElements\" :plugins=\"plugins\">\n <!-- scoped slot keeps API parity with React version -->\n <slot\n :registry=\"registry\"\n :coreState=\"coreState\"\n :isInitializing=\"isInit\"\n :pluginsReady=\"pluginsOk\"\n :activeDocumentId=\"activeDocumentId\"\n :activeDocument=\"activeDocument\"\n :documents=\"documents\"\n :documentStates=\"documentStates\"\n />\n </AutoMount>\n\n <!-- No auto-mount or not ready yet -->\n <slot\n v-else\n :registry=\"registry\"\n :coreState=\"coreState\"\n :isInitializing=\"isInit\"\n :pluginsReady=\"pluginsOk\"\n :activeDocumentId=\"activeDocumentId\"\n :activeDocument=\"activeDocument\"\n :documents=\"documents\"\n :documentStates=\"documentStates\"\n />\n</template>\n","import type { BasePlugin } from '@embedpdf/core';\nimport { computed, type Ref } from 'vue';\nimport { usePlugin } from './use-plugin';\n\nexport interface CapabilityState<C> {\n provides: Ref<C | null>;\n isLoading: Ref<boolean>;\n ready: Ref<Promise<void>>;\n}\n\n/**\n * Access the public capability exposed by a plugin.\n *\n * @example\n * const { provides: zoom } = useCapability<ZoomPlugin>(ZoomPlugin.id);\n * zoom.value?.zoomIn();\n */\nexport function useCapability<T extends BasePlugin>(\n pluginId: T['id'],\n): CapabilityState<ReturnType<NonNullable<T['provides']>>> {\n const { plugin, isLoading, ready } = usePlugin<T>(pluginId);\n\n const provides = computed(() => {\n if (!plugin.value) return null;\n if (!plugin.value.provides) {\n throw new Error(`Plugin ${pluginId} does not implement provides()`);\n }\n return plugin.value.provides() as ReturnType<NonNullable<T['provides']>>;\n });\n\n return { provides, isLoading, ready };\n}\n","import { computed, toValue, type MaybeRefOrGetter, ComputedRef } from 'vue';\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 * Composable 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 (can be ref, computed, getter, or plain value).\n * @returns A computed ref with the permission object.\n */\nexport function useDocumentPermissions(\n documentId: MaybeRefOrGetter<string>,\n): ComputedRef<DocumentPermissions> {\n const coreState = useCoreState();\n\n return computed(() => {\n const docId = toValue(documentId);\n const state = coreState.value;\n\n if (!state) {\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(state, docId);\n const pdfPermissions =\n state.documents[docId]?.document?.permissions ?? PdfPermissionFlag.AllowAll;\n\n const hasPermission = (flag: PdfPermissionFlag) => getEffectivePermission(state, docId, flag);\n const hasAllPermissions = (...flags: PdfPermissionFlag[]) =>\n flags.every((flag) => getEffectivePermission(state, docId, flag));\n\n return {\n permissions: effectivePermissions,\n pdfPermissions,\n hasPermission,\n hasAllPermissions,\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 });\n}\n","import { computed, toValue, type MaybeRefOrGetter } from 'vue';\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 (can be ref, computed, getter, or plain value).\n * @returns A computed ref containing the DocumentState object or null if not found.\n */\nexport function useDocumentState(documentId: MaybeRefOrGetter<string | null>) {\n const coreState = useCoreState();\n\n const documentState = computed(() => {\n const core = coreState.value;\n const docId = toValue(documentId);\n\n if (!core || !docId) return null;\n return core.documents[docId] ?? null;\n });\n\n return documentState;\n}\n","import { ref, onMounted, onBeforeUnmount, watch } from 'vue';\nimport type { CoreState, StoreState } from '@embedpdf/core';\nimport { useRegistry } from './use-registry';\n\n/**\n * Reactive getter for the *entire* global store.\n * Re‑emits whenever any slice changes.\n *\n * @example\n * const state = useStoreState(); // Ref<StoreState<CoreState>>\n * console.log(state.value.core.scale);\n */\nexport function useStoreState<T = CoreState>() {\n const { registry } = useRegistry();\n const state = ref<StoreState<T>>();\n\n function attach() {\n if (!registry.value) return () => {};\n\n // initial snapshot\n state.value = registry.value.getStore().getState() as StoreState<T>;\n\n // live updates\n return registry.value\n .getStore()\n .subscribe((_action, newState) => (state.value = newState as StoreState<T>));\n }\n\n /* attach now and re‑attach if registry instance ever changes */\n let unsubscribe = attach();\n watch(registry, () => {\n unsubscribe?.();\n unsubscribe = attach();\n });\n\n onBeforeUnmount(() => unsubscribe?.());\n\n return state;\n}\n"],"names":["pdfKey","Symbol","useRegistry","ctx","inject","Error","useCoreState","coreState","PdfPermissionFlag","Print","ModifyContents","CopyContents","ModifyAnnotations","FillForms","ExtractForAccessibility","AssembleDocument","PrintHighQuality","ALL_PERMISSION_FLAGS","PERMISSION_FLAG_TO_NAME","getPermissionOverride","overrides","flag","name","getEffectivePermission","state","documentId","docState","documents","docConfig","permissions","globalConfig","globalPermissions","pdfPermissions","_a","document","AllowAll","docOverride","globalOverride","enforceDocumentPermissions","usePlugin","pluginId","registry","plugin","shallowRef","isLoading","ref","ready","Promise","load","value","p","getPlugin","call","resolve","onMounted","watch","_openBlock","_createBlock","_resolveDynamicComponent","__props","wrappers","length","_component_NestedWrapper","slice","utilities","_renderSlot","_ctx","$slots","_createElementBlock","_Fragment","key","_renderList","utility","index","props","elements","computed","reg","plugins","pkg","package","hasAutoMountElements","autoMountElements","element","type","push","component","NestedWrapper","isInit","pluginsOk","activeDocumentId","documentOrder","activeDocument","docId","docs","documentStates","map","filter","doc","provide","isInitializing","pluginsReady","async","finalConfig","config","logger","PluginRegistry","engine","registerPluginBatch","initialize","isDestroyed","store","getStore","getState","core","unsubscribe","subscribe","action","newState","oldState","isCoreAction","_b","onInitialized","then","onBeforeUnmount","destroy","autoMountDomElements","AutoMount","provides","toValue","hasPermission","hasAllPermissions","canPrint","canModifyContents","canCopyContents","canModifyAnnotations","canFillForms","canExtractForAccessibility","canAssembleDocument","canPrintHighQuality","effectivePermissions","reduce","acc","getEffectivePermissions","flags","every","attach","_action"],"mappings":"iKAgBaA,EAAwCC,OAAO,UCbrD,SAASC,IACd,MAAMC,EAAMC,EAAAA,OAAOJ,GACnB,IAAKG,EAAK,MAAM,IAAIE,MAAM,8CAC1B,OAAOF,CACT,CCGO,SAASG,IACd,MAAMC,UAAEA,GAAcL,IACtB,OAAOK,CACT,CCMSC,EAAAA,kBAAkBC,MACTD,EAAAA,kBAAkBE,eACpBF,EAAAA,kBAAkBG,aACbH,EAAAA,kBAAkBI,kBAC1BJ,EAAAA,kBAAkBK,UACJL,EAAAA,kBAAkBM,wBACzBN,EAAAA,kBAAkBO,iBAClBP,EAAAA,kBAAkBQ,iBAyC/B,MAAMC,EAA4C,CACvDT,EAAAA,kBAAkBC,MAClBD,EAA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aAAQ3D,eAAxB,EAAAuF,EAAkC5F,cAAerB,EAAAA,kBAAkB2B,SASnE+F,gBACAC,kBAPwB,IAAIa,IAC5BA,EAAMC,MAAO5H,GAASE,EAAuBC,EAAOqE,EAAOxE,IAO3D+G,SAAUF,EAAc1H,EAAAA,kBAAkBC,OAC1C4H,kBAAmBH,EAAc1H,EAAAA,kBAAkBE,gBACnD4H,gBAAiBJ,EAAc1H,EAAAA,kBAAkBG,cACjD4H,qBAAsBL,EAAc1H,EAAAA,kBAAkBI,mBACtD4H,aAAcN,EAAc1H,EAAAA,kBAAkBK,WAC9C4H,2BAA4BP,EAAc1H,EAAAA,kBAAkBM,yBAC5D4H,oBAAqBR,EAAc1H,EAAAA,kBAAkBO,kBACrD4H,oBAAqBT,EAAc1H,EAAAA,kBAAkBQ,oBAG3D,2BCjFO,SAA0BS,GAC/B,MAAMlB,EAAYD,IAUlB,OARsBsE,EAAAA,SAAS,KAC7B,MAAMsC,EAAO3G,EAAU0C,MACjB4C,EAAQoC,EAAAA,QAAQxG,GAEtB,OAAKyF,GAASrB,EACPqB,EAAKvF,UAAUkE,IAAU,KADJ,MAKhC,kECTO,WACL,MAAMpD,SAAEA,GAAavC,IACfsB,EAAQqB,EAAAA,MAEd,SAASqG,IACP,OAAKzG,EAASQ,OAGdzB,EAAMyB,MAAQR,EAASQ,MAAM+D,WAAWC,WAGjCxE,EAASQ,MACb+D,WACAI,UAAU,CAAC+B,EAAS7B,IAAc9F,EAAMyB,MAAQqE,IARvB,MAS9B,CAGA,IAAIH,EAAc+B,IAQlB,OAPA3F,EAAAA,MAAMd,EAAU,KACd,MAAA0E,GAAAA,IACAA,EAAc+B,MAGhBtB,EAAAA,gBAAgB,IAAM,MAAAT,OAAA,EAAAA,KAEf3F,CACT"} |
+25
-15
@@ -1,2 +0,2 @@ | ||
| import { inject, computed, toValue, shallowRef, ref, onMounted, watch, onBeforeUnmount, defineComponent, resolveComponent, createBlock, openBlock, resolveDynamicComponent, withCtx, renderSlot, createElementBlock, Fragment, renderList, provide } from "vue"; | ||
| import { inject, computed, toValue, shallowRef, ref, onMounted, watch, onBeforeUnmount, defineComponent, resolveComponent, createBlock, openBlock, resolveDynamicComponent, withCtx, createElementBlock, renderSlot, Fragment, renderList, provide } from "vue"; | ||
| import { PdfPermissionFlag } from "@embedpdf/models"; | ||
@@ -180,3 +180,4 @@ import { hasAutoMountElements, PluginRegistry } from "@embedpdf/core"; | ||
| props: { | ||
| wrappers: {} | ||
| wrappers: {}, | ||
| utilities: {} | ||
| }, | ||
@@ -190,3 +191,4 @@ setup(__props) { | ||
| key: 0, | ||
| wrappers: __props.wrappers.slice(1) | ||
| wrappers: __props.wrappers.slice(1), | ||
| utilities: __props.utilities | ||
| }, { | ||
@@ -197,3 +199,10 @@ default: withCtx(() => [ | ||
| _: 3 | ||
| }, 8, ["wrappers"])) : renderSlot(_ctx.$slots, "default", { key: 1 }) | ||
| }, 8, ["wrappers", "utilities"])) : (openBlock(), createElementBlock(Fragment, { key: 1 }, [ | ||
| renderSlot(_ctx.$slots, "default"), | ||
| (openBlock(true), createElementBlock(Fragment, null, renderList(__props.utilities, (utility, index) => { | ||
| return openBlock(), createBlock(resolveDynamicComponent(utility), { | ||
| key: `utility-${index}` | ||
| }); | ||
| }), 128)) | ||
| ], 64)) | ||
| ]), | ||
@@ -231,12 +240,13 @@ _: 3 | ||
| return (_ctx, _cache) => { | ||
| return openBlock(), createElementBlock(Fragment, null, [ | ||
| elements.value.wrappers.length > 0 ? (openBlock(), createBlock(_sfc_main$2, { | ||
| key: 0, | ||
| wrappers: elements.value.wrappers | ||
| }, { | ||
| default: withCtx(() => [ | ||
| renderSlot(_ctx.$slots, "default") | ||
| ]), | ||
| _: 3 | ||
| }, 8, ["wrappers"])) : renderSlot(_ctx.$slots, "default", { key: 1 }), | ||
| return elements.value.wrappers.length > 0 ? (openBlock(), createBlock(_sfc_main$2, { | ||
| key: 0, | ||
| wrappers: elements.value.wrappers, | ||
| utilities: elements.value.utilities | ||
| }, { | ||
| default: withCtx(() => [ | ||
| renderSlot(_ctx.$slots, "default") | ||
| ]), | ||
| _: 3 | ||
| }, 8, ["wrappers", "utilities"])) : (openBlock(), createElementBlock(Fragment, { key: 1 }, [ | ||
| renderSlot(_ctx.$slots, "default"), | ||
| (openBlock(true), createElementBlock(Fragment, null, renderList(elements.value.utilities, (utility, index) => { | ||
@@ -247,3 +257,3 @@ return openBlock(), createBlock(resolveDynamicComponent(utility), { | ||
| }), 128)) | ||
| ], 64); | ||
| ], 64)); | ||
| }; | ||
@@ -250,0 +260,0 @@ } |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"index.js","sources":["../../src/vue/context.ts","../../src/vue/composables/use-registry.ts","../../src/vue/composables/use-core-state.ts","../../src/vue/composables/use-document-state.ts","../../src/lib/types/permissions.ts","../../src/lib/store/selectors.ts","../../src/vue/composables/use-document-permissions.ts","../../src/vue/composables/use-plugin.ts","../../src/vue/composables/use-capability.ts","../../src/vue/composables/use-store-state.ts","../../src/vue/components/nested-wrapper.vue","../../src/vue/components/auto-mount.vue","../../src/vue/components/embed-pdf.vue"],"sourcesContent":["import { InjectionKey, Ref, ShallowRef } from 'vue';\nimport type { PluginRegistry, CoreState, DocumentState } from '@embedpdf/core';\n\nexport interface PDFContextState {\n registry: ShallowRef<PluginRegistry | null>;\n coreState: Ref<CoreState | null>;\n isInitializing: Ref<boolean>;\n pluginsReady: Ref<boolean>;\n\n // Convenience accessors (always safe to use)\n activeDocumentId: Ref<string | null>;\n activeDocument: Ref<DocumentState | null>;\n documents: Ref<Record<string, DocumentState>>;\n documentStates: Ref<DocumentState[]>;\n}\n\nexport const pdfKey: InjectionKey<PDFContextState> = Symbol('pdfKey');\n","import { inject } from 'vue';\nimport { pdfKey } from '../context';\n\nexport function useRegistry() {\n const ctx = inject(pdfKey);\n if (!ctx) throw new Error('useRegistry must be used inside <EmbedPDF>');\n return ctx;\n}\n","import { Ref } from 'vue';\nimport { type CoreState } from '@embedpdf/core';\nimport { useRegistry } from './use-registry';\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(): Ref<CoreState | null> {\n const { coreState } = useRegistry();\n return coreState;\n}\n","import { computed, toValue, type MaybeRefOrGetter } from 'vue';\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 (can be ref, computed, getter, or plain value).\n * @returns A computed ref containing the DocumentState object or null if not found.\n */\nexport function useDocumentState(documentId: MaybeRefOrGetter<string | null>) {\n const coreState = useCoreState();\n\n const documentState = computed(() => {\n const core = coreState.value;\n const docId = toValue(documentId);\n\n if (!core || !docId) return null;\n return core.documents[docId] ?? null;\n });\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 { computed, toValue, type MaybeRefOrGetter, ComputedRef } from 'vue';\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 * Composable 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 (can be ref, computed, getter, or plain value).\n * @returns A computed ref with the permission object.\n */\nexport function useDocumentPermissions(\n documentId: MaybeRefOrGetter<string>,\n): ComputedRef<DocumentPermissions> {\n const coreState = useCoreState();\n\n return computed(() => {\n const docId = toValue(documentId);\n const state = coreState.value;\n\n if (!state) {\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(state, docId);\n const pdfPermissions =\n state.documents[docId]?.document?.permissions ?? PdfPermissionFlag.AllowAll;\n\n const hasPermission = (flag: PdfPermissionFlag) => getEffectivePermission(state, docId, flag);\n const hasAllPermissions = (...flags: PdfPermissionFlag[]) =>\n flags.every((flag) => getEffectivePermission(state, docId, flag));\n\n return {\n permissions: effectivePermissions,\n pdfPermissions,\n hasPermission,\n hasAllPermissions,\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 });\n}\n","import { shallowRef, ref, onMounted, watch, type ShallowRef, type Ref } from 'vue';\nimport type { BasePlugin } from '@embedpdf/core';\nimport { useRegistry } from './use-registry';\n\nexport interface PluginState<T extends BasePlugin> {\n plugin: ShallowRef<T | null>;\n isLoading: Ref<boolean>;\n ready: Ref<Promise<void>>;\n}\n\nexport function usePlugin<T extends BasePlugin>(pluginId: T['id']): PluginState<T> {\n const { registry } = useRegistry();\n\n const plugin = shallowRef(null) as ShallowRef<T | null>;\n\n const isLoading = ref(true);\n const ready = ref<Promise<void>>(new Promise(() => {}));\n\n const load = () => {\n if (!registry.value) return;\n\n const p = registry.value.getPlugin<T>(pluginId);\n if (!p) throw new Error(`Plugin ${pluginId} not found`);\n\n plugin.value = p;\n isLoading.value = false;\n ready.value = p.ready?.() ?? Promise.resolve();\n };\n\n onMounted(load);\n watch(registry, load);\n\n return { plugin, isLoading, ready };\n}\n","import type { BasePlugin } from '@embedpdf/core';\nimport { computed, type Ref } from 'vue';\nimport { usePlugin } from './use-plugin';\n\nexport interface CapabilityState<C> {\n provides: Ref<C | null>;\n isLoading: Ref<boolean>;\n ready: Ref<Promise<void>>;\n}\n\n/**\n * Access the public capability exposed by a plugin.\n *\n * @example\n * const { provides: zoom } = useCapability<ZoomPlugin>(ZoomPlugin.id);\n * zoom.value?.zoomIn();\n */\nexport function useCapability<T extends BasePlugin>(\n pluginId: T['id'],\n): CapabilityState<ReturnType<NonNullable<T['provides']>>> {\n const { plugin, isLoading, ready } = usePlugin<T>(pluginId);\n\n const provides = computed(() => {\n if (!plugin.value) return null;\n if (!plugin.value.provides) {\n throw new Error(`Plugin ${pluginId} does not implement provides()`);\n }\n return plugin.value.provides() as ReturnType<NonNullable<T['provides']>>;\n });\n\n return { provides, isLoading, ready };\n}\n","import { ref, onMounted, onBeforeUnmount, watch } from 'vue';\nimport type { CoreState, StoreState } from '@embedpdf/core';\nimport { useRegistry } from './use-registry';\n\n/**\n * Reactive getter for the *entire* global store.\n * Re‑emits whenever any slice changes.\n *\n * @example\n * const state = useStoreState(); // Ref<StoreState<CoreState>>\n * console.log(state.value.core.scale);\n */\nexport function useStoreState<T = CoreState>() {\n const { registry } = useRegistry();\n const state = ref<StoreState<T>>();\n\n function attach() {\n if (!registry.value) return () => {};\n\n // initial snapshot\n state.value = registry.value.getStore().getState() as StoreState<T>;\n\n // live updates\n return registry.value\n .getStore()\n .subscribe((_action, newState) => (state.value = newState as StoreState<T>));\n }\n\n /* attach now and re‑attach if registry instance ever changes */\n let unsubscribe = attach();\n watch(registry, () => {\n unsubscribe?.();\n unsubscribe = attach();\n });\n\n onBeforeUnmount(() => unsubscribe?.());\n\n return state;\n}\n","<script setup lang=\"ts\">\ndefineProps<{\n wrappers: any[];\n}>();\n</script>\n\n<template>\n <component :is=\"wrappers[0]\">\n <NestedWrapper v-if=\"wrappers.length > 1\" :wrappers=\"wrappers.slice(1)\">\n <slot />\n </NestedWrapper>\n <slot v-else />\n </component>\n</template>\n","<script setup lang=\"ts\">\nimport { computed } from 'vue';\nimport { hasAutoMountElements, type PluginBatchRegistration, type IPlugin } from '@embedpdf/core';\nimport NestedWrapper from './nested-wrapper.vue';\n\nconst props = defineProps<{\n plugins: PluginBatchRegistration<IPlugin<any>, any>[];\n}>();\n\nconst elements = computed(() => {\n const utilities: any[] = [];\n const wrappers: any[] = [];\n\n for (const reg of props.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 wrappers.push(element.component);\n }\n }\n }\n }\n\n return { utilities, wrappers };\n});\n</script>\n\n<template>\n <NestedWrapper v-if=\"elements.wrappers.length > 0\" :wrappers=\"elements.wrappers\">\n <slot />\n </NestedWrapper>\n <slot v-else />\n\n <component\n v-for=\"(utility, index) in elements.utilities\"\n :key=\"`utility-${index}`\"\n :is=\"utility\"\n />\n</template>\n","<script setup lang=\"ts\">\nimport { ref, provide, onMounted, onBeforeUnmount, shallowRef, computed } from 'vue';\nimport {\n PluginRegistry,\n PluginBatchRegistrations,\n PluginRegistryConfig,\n CoreState,\n DocumentState,\n} from '@embedpdf/core';\nimport { Logger, PdfEngine } from '@embedpdf/models';\nimport { pdfKey, PDFContextState } from '../context';\nimport AutoMount from './auto-mount.vue';\n\nexport type { PluginBatchRegistrations };\n\nconst props = withDefaults(\n defineProps<{\n engine: PdfEngine;\n /** Registry configuration including logger, permissions, and defaults. */\n config?: PluginRegistryConfig;\n /** @deprecated Use config.logger instead. Will be removed in next major version. */\n logger?: Logger;\n plugins: PluginBatchRegistrations;\n onInitialized?: (registry: PluginRegistry) => Promise<void>;\n autoMountDomElements?: boolean;\n }>(),\n {\n autoMountDomElements: true,\n },\n);\n\n/* reactive state */\nconst registry = shallowRef<PluginRegistry | null>(null);\nconst coreState = ref<CoreState | null>(null);\nconst isInit = ref(true);\nconst pluginsOk = ref(false);\n\n// Compute convenience accessors\nconst activeDocumentId = computed(() => coreState.value?.activeDocumentId ?? null);\nconst documents = computed(() => coreState.value?.documents ?? {});\nconst documentOrder = computed(() => coreState.value?.documentOrder ?? []);\n\nconst activeDocument = computed(() => {\n const docId = activeDocumentId.value;\n const docs = documents.value;\n return docId && docs[docId] ? docs[docId] : null;\n});\n\nconst documentStates = computed(() => {\n const docs = documents.value;\n const order = documentOrder.value;\n return order\n .map((docId) => docs[docId])\n .filter((doc): doc is DocumentState => doc !== null && doc !== undefined);\n});\n\n/* expose to children */\nprovide<PDFContextState>(pdfKey, {\n registry,\n coreState,\n isInitializing: isInit,\n pluginsReady: pluginsOk,\n activeDocumentId,\n activeDocument,\n documents,\n documentStates,\n});\n\nonMounted(async () => {\n // Merge deprecated logger prop into config (config.logger takes precedence)\n const finalConfig: PluginRegistryConfig = {\n ...props.config,\n logger: props.config?.logger ?? props.logger,\n };\n const reg = new PluginRegistry(props.engine, finalConfig);\n reg.registerPluginBatch(props.plugins);\n await reg.initialize();\n\n if (reg.isDestroyed()) {\n return;\n }\n\n const store = reg.getStore();\n coreState.value = 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 coreState.value = newState.core;\n }\n });\n\n await props.onInitialized?.(reg);\n\n if (reg.isDestroyed()) {\n unsubscribe();\n return;\n }\n\n registry.value = reg;\n isInit.value = false;\n\n reg.pluginsReady().then(() => {\n if (!reg.isDestroyed()) {\n pluginsOk.value = true;\n }\n });\n\n onBeforeUnmount(() => {\n unsubscribe();\n registry.value?.destroy();\n });\n});\n</script>\n\n<template>\n <AutoMount v-if=\"pluginsOk && autoMountDomElements\" :plugins=\"plugins\">\n <!-- scoped slot keeps API parity with React version -->\n <slot\n :registry=\"registry\"\n :coreState=\"coreState\"\n :isInitializing=\"isInit\"\n :pluginsReady=\"pluginsOk\"\n :activeDocumentId=\"activeDocumentId\"\n :activeDocument=\"activeDocument\"\n :documents=\"documents\"\n :documentStates=\"documentStates\"\n />\n </AutoMount>\n\n <!-- No auto-mount or not ready yet -->\n <slot\n v-else\n :registry=\"registry\"\n :coreState=\"coreState\"\n :isInitializing=\"isInit\"\n :pluginsReady=\"pluginsOk\"\n :activeDocumentId=\"activeDocumentId\"\n :activeDocument=\"activeDocument\"\n :documents=\"documents\"\n :documentStates=\"documentStates\"\n />\n</template>\n"],"names":["_openBlock","_createBlock","_resolveDynamicComponent","_renderSlot","elements","NestedWrapper","_createElementBlock","_Fragment","_a","AutoMount"],"mappings":";;;AAgBO,MAAM,SAAwC,OAAO,QAAQ;ACb7D,SAAS,cAAc;AAC5B,QAAM,MAAM,OAAO,MAAM;AACzB,MAAI,CAAC,IAAK,OAAM,IAAI,MAAM,4CAA4C;AACtE,SAAO;AACT;ACGO,SAAS,eAAsC;AACpD,QAAM,EAAE,UAAA,IAAc,YAAA;AACtB,SAAO;AACT;ACJO,SAAS,iBAAiB,YAA6C;AAC5E,QAAM,YAAY,aAAA;AAElB,QAAM,gBAAgB,SAAS,MAAM;AACnC,UAAM,OAAO,UAAU;AACvB,UAAM,QAAQ,QAAQ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MAAA;yBAE5D,MASE;AAAA,UATFN,WASE,KAAA,QAAA,WAAA;AAAA,YARC,UAAU,SAAA;AAAA,YACV,WAAW,UAAA;AAAA,YACX,gBAAgB,OAAA;AAAA,YAChB,cAAc,UAAA;AAAA,YACd,kBAAkB,iBAAA;AAAA,YAClB,gBAAgB,eAAA;AAAA,YAChB,WAAW,UAAA;AAAA,YACX,gBAAgB,eAAA;AAAA,UAAA;;;4BAKrBA,WAUE,KAAA,QAAA,WAAA;AAAA;QARC,UAAU,SAAA;AAAA,QACV,WAAW,UAAA;AAAA,QACX,gBAAgB,OAAA;AAAA,QAChB,cAAc,UAAA;AAAA,QACd,kBAAkB,iBAAA;AAAA,QAClB,gBAAgB,eAAA;AAAA,QAChB,WAAW,UAAA;AAAA,QACX,gBAAgB,eAAA;AAAA,MAAA;;;;"} | ||
| {"version":3,"file":"index.js","sources":["../../src/vue/context.ts","../../src/vue/composables/use-registry.ts","../../src/vue/composables/use-core-state.ts","../../src/vue/composables/use-document-state.ts","../../src/lib/types/permissions.ts","../../src/lib/store/selectors.ts","../../src/vue/composables/use-document-permissions.ts","../../src/vue/composables/use-plugin.ts","../../src/vue/composables/use-capability.ts","../../src/vue/composables/use-store-state.ts","../../src/vue/components/nested-wrapper.vue","../../src/vue/components/auto-mount.vue","../../src/vue/components/embed-pdf.vue"],"sourcesContent":["import { InjectionKey, Ref, ShallowRef } from 'vue';\nimport type { PluginRegistry, CoreState, DocumentState } from '@embedpdf/core';\n\nexport interface PDFContextState {\n registry: ShallowRef<PluginRegistry | null>;\n coreState: Ref<CoreState | null>;\n isInitializing: Ref<boolean>;\n pluginsReady: Ref<boolean>;\n\n // Convenience accessors (always safe to use)\n activeDocumentId: Ref<string | null>;\n activeDocument: Ref<DocumentState | null>;\n documents: Ref<Record<string, DocumentState>>;\n documentStates: Ref<DocumentState[]>;\n}\n\nexport const pdfKey: InjectionKey<PDFContextState> = Symbol('pdfKey');\n","import { inject } from 'vue';\nimport { pdfKey } from '../context';\n\nexport function useRegistry() {\n const ctx = inject(pdfKey);\n if (!ctx) throw new Error('useRegistry must be used inside <EmbedPDF>');\n return ctx;\n}\n","import { Ref } from 'vue';\nimport { type CoreState } from '@embedpdf/core';\nimport { useRegistry } from './use-registry';\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(): Ref<CoreState | null> {\n const { coreState } = useRegistry();\n return coreState;\n}\n","import { computed, toValue, type MaybeRefOrGetter } from 'vue';\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 (can be ref, computed, getter, or plain value).\n * @returns A computed ref containing the DocumentState object or null if not found.\n */\nexport function useDocumentState(documentId: MaybeRefOrGetter<string | null>) {\n const coreState = useCoreState();\n\n const documentState = computed(() => {\n const core = coreState.value;\n const docId = toValue(documentId);\n\n if (!core || !docId) return null;\n return core.documents[docId] ?? null;\n });\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 { computed, toValue, type MaybeRefOrGetter, ComputedRef } from 'vue';\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 * Composable 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 (can be ref, computed, getter, or plain value).\n * @returns A computed ref with the permission object.\n */\nexport function useDocumentPermissions(\n documentId: MaybeRefOrGetter<string>,\n): ComputedRef<DocumentPermissions> {\n const coreState = useCoreState();\n\n return computed(() => {\n const docId = toValue(documentId);\n const state = coreState.value;\n\n if (!state) {\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(state, docId);\n const pdfPermissions =\n state.documents[docId]?.document?.permissions ?? PdfPermissionFlag.AllowAll;\n\n const hasPermission = (flag: PdfPermissionFlag) => getEffectivePermission(state, docId, flag);\n const hasAllPermissions = (...flags: PdfPermissionFlag[]) =>\n flags.every((flag) => getEffectivePermission(state, docId, flag));\n\n return {\n permissions: effectivePermissions,\n pdfPermissions,\n hasPermission,\n hasAllPermissions,\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 });\n}\n","import { shallowRef, ref, onMounted, watch, type ShallowRef, type Ref } from 'vue';\nimport type { BasePlugin } from '@embedpdf/core';\nimport { useRegistry } from './use-registry';\n\nexport interface PluginState<T extends BasePlugin> {\n plugin: ShallowRef<T | null>;\n isLoading: Ref<boolean>;\n ready: Ref<Promise<void>>;\n}\n\nexport function usePlugin<T extends BasePlugin>(pluginId: T['id']): PluginState<T> {\n const { registry } = useRegistry();\n\n const plugin = shallowRef(null) as ShallowRef<T | null>;\n\n const isLoading = ref(true);\n const ready = ref<Promise<void>>(new Promise(() => {}));\n\n const load = () => {\n if (!registry.value) return;\n\n const p = registry.value.getPlugin<T>(pluginId);\n if (!p) throw new Error(`Plugin ${pluginId} not found`);\n\n plugin.value = p;\n isLoading.value = false;\n ready.value = p.ready?.() ?? Promise.resolve();\n };\n\n onMounted(load);\n watch(registry, load);\n\n return { plugin, isLoading, ready };\n}\n","import type { BasePlugin } from '@embedpdf/core';\nimport { computed, type Ref } from 'vue';\nimport { usePlugin } from './use-plugin';\n\nexport interface CapabilityState<C> {\n provides: Ref<C | null>;\n isLoading: Ref<boolean>;\n ready: Ref<Promise<void>>;\n}\n\n/**\n * Access the public capability exposed by a plugin.\n *\n * @example\n * const { provides: zoom } = useCapability<ZoomPlugin>(ZoomPlugin.id);\n * zoom.value?.zoomIn();\n */\nexport function useCapability<T extends BasePlugin>(\n pluginId: T['id'],\n): CapabilityState<ReturnType<NonNullable<T['provides']>>> {\n const { plugin, isLoading, ready } = usePlugin<T>(pluginId);\n\n const provides = computed(() => {\n if (!plugin.value) return null;\n if (!plugin.value.provides) {\n throw new Error(`Plugin ${pluginId} does not implement provides()`);\n }\n return plugin.value.provides() as ReturnType<NonNullable<T['provides']>>;\n });\n\n return { provides, isLoading, ready };\n}\n","import { ref, onMounted, onBeforeUnmount, watch } from 'vue';\nimport type { CoreState, StoreState } from '@embedpdf/core';\nimport { useRegistry } from './use-registry';\n\n/**\n * Reactive getter for the *entire* global store.\n * Re‑emits whenever any slice changes.\n *\n * @example\n * const state = useStoreState(); // Ref<StoreState<CoreState>>\n * console.log(state.value.core.scale);\n */\nexport function useStoreState<T = CoreState>() {\n const { registry } = useRegistry();\n const state = ref<StoreState<T>>();\n\n function attach() {\n if (!registry.value) return () => {};\n\n // initial snapshot\n state.value = registry.value.getStore().getState() as StoreState<T>;\n\n // live updates\n return registry.value\n .getStore()\n .subscribe((_action, newState) => (state.value = newState as StoreState<T>));\n }\n\n /* attach now and re‑attach if registry instance ever changes */\n let unsubscribe = attach();\n watch(registry, () => {\n unsubscribe?.();\n unsubscribe = attach();\n });\n\n onBeforeUnmount(() => unsubscribe?.());\n\n return state;\n}\n","<script setup lang=\"ts\">\ndefineProps<{\n wrappers: any[];\n utilities?: any[];\n}>();\n</script>\n\n<template>\n <component :is=\"wrappers[0]\">\n <NestedWrapper v-if=\"wrappers.length > 1\" :wrappers=\"wrappers.slice(1)\" :utilities=\"utilities\">\n <slot />\n </NestedWrapper>\n <template v-else>\n <slot />\n <!-- Render utilities inside the innermost wrapper -->\n <component v-for=\"(utility, index) in utilities\" :key=\"`utility-${index}`\" :is=\"utility\" />\n </template>\n </component>\n</template>\n","<script setup lang=\"ts\">\nimport { computed } from 'vue';\nimport { hasAutoMountElements, type PluginBatchRegistration, type IPlugin } from '@embedpdf/core';\nimport NestedWrapper from './nested-wrapper.vue';\n\nconst props = defineProps<{\n plugins: PluginBatchRegistration<IPlugin<any>, any>[];\n}>();\n\nconst elements = computed(() => {\n const utilities: any[] = [];\n const wrappers: any[] = [];\n\n for (const reg of props.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 wrappers.push(element.component);\n }\n }\n }\n }\n\n return { utilities, wrappers };\n});\n</script>\n\n<template>\n <NestedWrapper\n v-if=\"elements.wrappers.length > 0\"\n :wrappers=\"elements.wrappers\"\n :utilities=\"elements.utilities\"\n >\n <slot />\n </NestedWrapper>\n <template v-else>\n <!-- No wrappers - render children and utilities directly -->\n <slot />\n <component\n v-for=\"(utility, index) in elements.utilities\"\n :key=\"`utility-${index}`\"\n :is=\"utility\"\n />\n </template>\n</template>\n","<script setup lang=\"ts\">\nimport { ref, provide, onMounted, onBeforeUnmount, shallowRef, computed } from 'vue';\nimport {\n PluginRegistry,\n PluginBatchRegistrations,\n PluginRegistryConfig,\n CoreState,\n DocumentState,\n} from '@embedpdf/core';\nimport { Logger, PdfEngine } from '@embedpdf/models';\nimport { pdfKey, PDFContextState } from '../context';\nimport AutoMount from './auto-mount.vue';\n\nexport type { PluginBatchRegistrations };\n\nconst props = withDefaults(\n defineProps<{\n engine: PdfEngine;\n /** Registry configuration including logger, permissions, and defaults. */\n config?: PluginRegistryConfig;\n /** @deprecated Use config.logger instead. Will be removed in next major version. */\n logger?: Logger;\n plugins: PluginBatchRegistrations;\n onInitialized?: (registry: PluginRegistry) => Promise<void>;\n autoMountDomElements?: boolean;\n }>(),\n {\n autoMountDomElements: true,\n },\n);\n\n/* reactive state */\nconst registry = shallowRef<PluginRegistry | null>(null);\nconst coreState = ref<CoreState | null>(null);\nconst isInit = ref(true);\nconst pluginsOk = ref(false);\n\n// Compute convenience accessors\nconst activeDocumentId = computed(() => coreState.value?.activeDocumentId ?? null);\nconst documents = computed(() => coreState.value?.documents ?? {});\nconst documentOrder = computed(() => coreState.value?.documentOrder ?? []);\n\nconst activeDocument = computed(() => {\n const docId = activeDocumentId.value;\n const docs = documents.value;\n return docId && docs[docId] ? docs[docId] : null;\n});\n\nconst documentStates = computed(() => {\n const docs = documents.value;\n const order = documentOrder.value;\n return order\n .map((docId) => docs[docId])\n .filter((doc): doc is DocumentState => doc !== null && doc !== undefined);\n});\n\n/* expose to children */\nprovide<PDFContextState>(pdfKey, {\n registry,\n coreState,\n isInitializing: isInit,\n pluginsReady: pluginsOk,\n activeDocumentId,\n activeDocument,\n documents,\n documentStates,\n});\n\nonMounted(async () => {\n // Merge deprecated logger prop into config (config.logger takes precedence)\n const finalConfig: PluginRegistryConfig = {\n ...props.config,\n logger: props.config?.logger ?? props.logger,\n };\n const reg = new PluginRegistry(props.engine, finalConfig);\n reg.registerPluginBatch(props.plugins);\n await reg.initialize();\n\n if (reg.isDestroyed()) {\n return;\n }\n\n const store = reg.getStore();\n coreState.value = 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 coreState.value = newState.core;\n }\n });\n\n await props.onInitialized?.(reg);\n\n if (reg.isDestroyed()) {\n unsubscribe();\n return;\n }\n\n registry.value = reg;\n isInit.value = false;\n\n reg.pluginsReady().then(() => {\n if (!reg.isDestroyed()) {\n pluginsOk.value = true;\n }\n });\n\n onBeforeUnmount(() => {\n unsubscribe();\n registry.value?.destroy();\n });\n});\n</script>\n\n<template>\n <AutoMount v-if=\"pluginsOk && autoMountDomElements\" :plugins=\"plugins\">\n <!-- scoped slot keeps API parity with React version -->\n <slot\n :registry=\"registry\"\n :coreState=\"coreState\"\n :isInitializing=\"isInit\"\n :pluginsReady=\"pluginsOk\"\n :activeDocumentId=\"activeDocumentId\"\n :activeDocument=\"activeDocument\"\n :documents=\"documents\"\n :documentStates=\"documentStates\"\n />\n </AutoMount>\n\n <!-- No auto-mount or not ready yet -->\n <slot\n v-else\n :registry=\"registry\"\n :coreState=\"coreState\"\n :isInitializing=\"isInit\"\n :pluginsReady=\"pluginsOk\"\n :activeDocumentId=\"activeDocumentId\"\n :activeDocument=\"activeDocument\"\n :documents=\"documents\"\n :documentStates=\"documentStates\"\n />\n</template>\n"],"names":["_openBlock","_createBlock","_resolveDynamicComponent","_renderSlot","_createElementBlock","_Fragment","_renderList","elements","NestedWrapper","_a","AutoMount"],"mappings":";;;AAgBO,MAAM,SAAwC,OAAO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4 @@ "license": "MIT", | ||
| "dependencies": { | ||
| "@embedpdf/models": "2.3.0", | ||
| "@embedpdf/engines": "2.3.0" | ||
| "@embedpdf/engines": "2.4.0", | ||
| "@embedpdf/models": "2.4.0" | ||
| }, | ||
@@ -47,0 +47,0 @@ "peerDependencies": { |
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
804809
0.67%5836
0.59%+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
Updated
Updated