@embedpdf/core 1.0.18 → 1.0.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/shared/context.ts","../../src/shared/components/embed-pdf.tsx","../../src/shared/components/counter-rotate-container.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"],"sourcesContent":["import { createContext } from '@framework';\nimport type { PluginRegistry } from '@embedpdf/core';\n\nexport interface PDFContextState {\n registry: PluginRegistry | null;\n isInitializing: boolean;\n pluginsReady: boolean;\n}\n\nexport const PDFContext = createContext<PDFContextState>({\n registry: null,\n isInitializing: true,\n pluginsReady: false,\n});\n","import { useState, useEffect, useRef, ReactNode } from '@framework';\nimport { PdfEngine } from '@embedpdf/models';\nimport { PluginRegistry } from '@embedpdf/core';\nimport type { IPlugin, PluginBatchRegistration } from '@embedpdf/core';\n\nimport { PDFContext, PDFContextState } from '../context';\n\ninterface EmbedPDFProps {\n engine: PdfEngine;\n onInitialized?: (registry: PluginRegistry) => Promise<void>;\n plugins: PluginBatchRegistration<IPlugin<any>, any>[];\n children: ReactNode | ((state: PDFContextState) => ReactNode);\n}\n\nexport function EmbedPDF({ engine, onInitialized, plugins, children }: EmbedPDFProps) {\n const [registry, setRegistry] = useState<PluginRegistry | 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; // update without triggering re-runs\n }, [onInitialized]);\n\n useEffect(() => {\n const pdfViewer = new PluginRegistry(engine);\n pdfViewer.registerPluginBatch(plugins);\n\n const initialize = async () => {\n await pdfViewer.initialize();\n // if the registry is destroyed, don't do anything\n if (pdfViewer.isDestroyed()) {\n return;\n }\n\n /* always call the *latest* callback */\n await initRef.current?.(pdfViewer);\n\n // if the registry is destroyed, don't do anything\n if (pdfViewer.isDestroyed()) {\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\n initialize().catch(console.error);\n\n return () => {\n pdfViewer.destroy();\n setRegistry(null);\n setIsInitializing(true);\n setPluginsReady(false);\n };\n }, [engine, plugins]);\n\n return (\n <PDFContext.Provider value={{ registry, isInitializing, pluginsReady }}>\n {typeof children === 'function'\n ? children({ registry, isInitializing, pluginsReady })\n : children}\n </PDFContext.Provider>\n );\n}\n","import { Rect, Rotation } from '@embedpdf/models';\nimport { ReactNode, CSSProperties, PointerEvent, Fragment, TouchEvent } from '@framework';\n\ninterface CounterRotateProps {\n rect: Rect;\n rotation: Rotation;\n}\n\ninterface CounterTransformResult {\n matrix: string; // CSS matrix(a,b,c,d,e,f)\n width: number; // new width\n height: number; // new height\n}\n\n/**\n * Given an already-placed rect (left/top/width/height in px) and the page rotation,\n * return the counter-rotation matrix + adjusted width/height.\n *\n * transform-origin is expected to be \"0 0\".\n * left/top DO NOT change, apply them as-is.\n */\nexport function getCounterRotation(rect: Rect, rotation: Rotation): CounterTransformResult {\n const { width: w, height: h } = rect.size;\n\n switch (rotation % 4) {\n case 1: // 90° cw → need matrix(0,-1,1,0,0,h) and swap w/h\n return {\n matrix: `matrix(0, -1, 1, 0, 0, ${h})`,\n width: h,\n height: w,\n };\n\n case 2: // 180° → matrix(-1,0,0,-1,w,h), width/height unchanged\n return {\n matrix: `matrix(-1, 0, 0, -1, ${w}, ${h})`,\n width: w,\n height: h,\n };\n\n case 3: // 270° cw → matrix(0,1,-1,0,w,0), swap w/h\n return {\n matrix: `matrix(0, 1, -1, 0, ${w}, 0)`,\n width: h,\n height: w,\n };\n\n default:\n return {\n matrix: `matrix(1, 0, 0, 1, 0, 0)`,\n width: w,\n height: h,\n };\n }\n}\n\nexport interface MenuWrapperProps {\n style: CSSProperties;\n onPointerDown: (e: PointerEvent<HTMLDivElement>) => void;\n onTouchStart: (e: TouchEvent<HTMLDivElement>) => void;\n}\n\ninterface CounterRotateComponentProps extends CounterRotateProps {\n children: (props: {\n matrix: string;\n rect: Rect;\n menuWrapperProps: MenuWrapperProps;\n }) => ReactNode;\n}\n\nexport function CounterRotate({ children, ...props }: CounterRotateComponentProps) {\n const { rect, rotation } = props;\n const { matrix, width, height } = getCounterRotation(rect, rotation);\n\n const menuWrapperStyle: CSSProperties = {\n position: 'absolute',\n left: rect.origin.x,\n top: rect.origin.y,\n transform: matrix,\n transformOrigin: '0 0',\n width: width,\n height: height,\n pointerEvents: 'none',\n zIndex: 3,\n };\n\n const menuWrapperProps = {\n style: menuWrapperStyle,\n onPointerDown: (e: PointerEvent<HTMLDivElement>) => e.stopPropagation(),\n onTouchStart: (e: TouchEvent<HTMLDivElement>) => e.stopPropagation(),\n };\n\n return (\n <Fragment>\n {children({\n menuWrapperProps,\n matrix,\n rect: {\n origin: { x: rect.origin.x, y: rect.origin.y },\n size: { width: width, height: height },\n },\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 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 { useState, useEffect } from '@framework';\nimport { CoreState, arePropsEqual } from '@embedpdf/core';\nimport { useRegistry } from './use-registry';\n\n/**\n * Hook that provides access to the current core state\n * and re-renders the component only when the core state changes\n */\nexport function useCoreState(): CoreState | null {\n const { registry } = useRegistry();\n const [coreState, setCoreState] = useState<CoreState | null>(null);\n\n useEffect(() => {\n if (!registry) return;\n\n const store = registry.getStore();\n\n // Get initial core state\n setCoreState(store.getState().core);\n\n // Create a single subscription that handles all core actions\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) && !arePropsEqual(newState.core, oldState.core)) {\n setCoreState(newState.core);\n }\n });\n\n return () => unsubscribe();\n }, [registry]);\n\n return coreState;\n}\n"],"names":[],"mappings":";;;;AASO,MAAM,aAAa,cAA+B;AAAA,EACvD,UAAU;AAAA,EACV,gBAAgB;AAAA,EAChB,cAAc;AAChB,CAAC;ACCM,SAAS,SAAS,EAAE,QAAQ,eAAe,SAAS,YAA2B;AACpF,QAAM,CAAC,UAAU,WAAW,IAAI,SAAgC,IAAI;AACpE,QAAM,CAAC,gBAAgB,iBAAiB,IAAI,SAAkB,IAAI;AAClE,QAAM,CAAC,cAAc,eAAe,IAAI,SAAkB,KAAK;AACzD,QAAA,UAAU,OAAuC,aAAa;AAEpE,YAAU,MAAM;AACd,YAAQ,UAAU;AAAA,EAAA,GACjB,CAAC,aAAa,CAAC;AAElB,YAAU,MAAM;AACR,UAAA,YAAY,IAAI,eAAe,MAAM;AAC3C,cAAU,oBAAoB,OAAO;AAErC,UAAM,aAAa,YAAY;;AAC7B,YAAM,UAAU,WAAW;AAEvB,UAAA,UAAU,eAAe;AAC3B;AAAA,MAAA;AAII,cAAA,aAAQ,YAAR,iCAAkB;AAGpB,UAAA,UAAU,eA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,CAAC;AAEN,SAAA;AACT;"}
1
+ {"version":3,"file":"index.js","sources":["../../src/shared/context.ts","../../src/shared/components/embed-pdf.tsx","../../src/shared/components/counter-rotate-container.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"],"sourcesContent":["import { createContext } from '@framework';\nimport type { PluginRegistry } from '@embedpdf/core';\n\nexport interface PDFContextState {\n registry: PluginRegistry | null;\n isInitializing: boolean;\n pluginsReady: boolean;\n}\n\nexport const PDFContext = createContext<PDFContextState>({\n registry: null,\n isInitializing: true,\n pluginsReady: false,\n});\n","import { useState, useEffect, useRef, ReactNode } from '@framework';\nimport { Logger, PdfEngine } from '@embedpdf/models';\nimport { PluginRegistry } from '@embedpdf/core';\nimport type { IPlugin, PluginBatchRegistration } from '@embedpdf/core';\n\nimport { PDFContext, PDFContextState } from '../context';\n\ninterface EmbedPDFProps {\n engine: PdfEngine;\n logger?: Logger;\n onInitialized?: (registry: PluginRegistry) => Promise<void>;\n plugins: PluginBatchRegistration<IPlugin<any>, any>[];\n children: ReactNode | ((state: PDFContextState) => ReactNode);\n}\n\nexport function EmbedPDF({ engine, logger, onInitialized, plugins, children }: EmbedPDFProps) {\n const [registry, setRegistry] = useState<PluginRegistry | 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; // update without triggering re-runs\n }, [onInitialized]);\n\n useEffect(() => {\n const pdfViewer = new PluginRegistry(engine, { logger });\n pdfViewer.registerPluginBatch(plugins);\n\n const initialize = async () => {\n await pdfViewer.initialize();\n // if the registry is destroyed, don't do anything\n if (pdfViewer.isDestroyed()) {\n return;\n }\n\n /* always call the *latest* callback */\n await initRef.current?.(pdfViewer);\n\n // if the registry is destroyed, don't do anything\n if (pdfViewer.isDestroyed()) {\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\n initialize().catch(console.error);\n\n return () => {\n pdfViewer.destroy();\n setRegistry(null);\n setIsInitializing(true);\n setPluginsReady(false);\n };\n }, [engine, plugins]);\n\n return (\n <PDFContext.Provider value={{ registry, isInitializing, pluginsReady }}>\n {typeof children === 'function'\n ? children({ registry, isInitializing, pluginsReady })\n : children}\n </PDFContext.Provider>\n );\n}\n","import { Rect, Rotation } from '@embedpdf/models';\nimport { ReactNode, CSSProperties, PointerEvent, Fragment, TouchEvent } from '@framework';\n\ninterface CounterRotateProps {\n rect: Rect;\n rotation: Rotation;\n}\n\ninterface CounterTransformResult {\n matrix: string; // CSS matrix(a,b,c,d,e,f)\n width: number; // new width\n height: number; // new height\n}\n\n/**\n * Given an already-placed rect (left/top/width/height in px) and the page rotation,\n * return the counter-rotation matrix + adjusted width/height.\n *\n * transform-origin is expected to be \"0 0\".\n * left/top DO NOT change, apply them as-is.\n */\nexport function getCounterRotation(rect: Rect, rotation: Rotation): CounterTransformResult {\n const { width: w, height: h } = rect.size;\n\n switch (rotation % 4) {\n case 1: // 90° cw → need matrix(0,-1,1,0,0,h) and swap w/h\n return {\n matrix: `matrix(0, -1, 1, 0, 0, ${h})`,\n width: h,\n height: w,\n };\n\n case 2: // 180° → matrix(-1,0,0,-1,w,h), width/height unchanged\n return {\n matrix: `matrix(-1, 0, 0, -1, ${w}, ${h})`,\n width: w,\n height: h,\n };\n\n case 3: // 270° cw → matrix(0,1,-1,0,w,0), swap w/h\n return {\n matrix: `matrix(0, 1, -1, 0, ${w}, 0)`,\n width: h,\n height: w,\n };\n\n default:\n return {\n matrix: `matrix(1, 0, 0, 1, 0, 0)`,\n width: w,\n height: h,\n };\n }\n}\n\nexport interface MenuWrapperProps {\n style: CSSProperties;\n onPointerDown: (e: PointerEvent<HTMLDivElement>) => void;\n onTouchStart: (e: TouchEvent<HTMLDivElement>) => void;\n}\n\ninterface CounterRotateComponentProps extends CounterRotateProps {\n children: (props: {\n matrix: string;\n rect: Rect;\n menuWrapperProps: MenuWrapperProps;\n }) => ReactNode;\n}\n\nexport function CounterRotate({ children, ...props }: CounterRotateComponentProps) {\n const { rect, rotation } = props;\n const { matrix, width, height } = getCounterRotation(rect, rotation);\n\n const menuWrapperStyle: CSSProperties = {\n position: 'absolute',\n left: rect.origin.x,\n top: rect.origin.y,\n transform: matrix,\n transformOrigin: '0 0',\n width: width,\n height: height,\n pointerEvents: 'none',\n zIndex: 3,\n };\n\n const menuWrapperProps = {\n style: menuWrapperStyle,\n onPointerDown: (e: PointerEvent<HTMLDivElement>) => e.stopPropagation(),\n onTouchStart: (e: TouchEvent<HTMLDivElement>) => e.stopPropagation(),\n };\n\n return (\n <Fragment>\n {children({\n menuWrapperProps,\n matrix,\n rect: {\n origin: { x: rect.origin.x, y: rect.origin.y },\n size: { width: width, height: height },\n },\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 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 { useState, useEffect } from '@framework';\nimport { CoreState, arePropsEqual } from '@embedpdf/core';\nimport { useRegistry } from './use-registry';\n\n/**\n * Hook that provides access to the current core state\n * and re-renders the component only when the core state changes\n */\nexport function useCoreState(): CoreState | null {\n const { registry } = useRegistry();\n const [coreState, setCoreState] = useState<CoreState | null>(null);\n\n useEffect(() => {\n if (!registry) return;\n\n const store = registry.getStore();\n\n // Get initial core state\n setCoreState(store.getState().core);\n\n // Create a single subscription that handles all core actions\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) && !arePropsEqual(newState.core, oldState.core)) {\n setCoreState(newState.core);\n }\n });\n\n return () => unsubscribe();\n }, [registry]);\n\n return coreState;\n}\n"],"names":[],"mappings":";;;;AASO,MAAM,aAAa,cAA+B;AAAA,EACvD,UAAU;AAAA,EACV,gBAAgB;AAAA,EAChB,cAAc;AAChB,CAAC;ACEM,SAAS,SAAS,EAAE,QAAQ,QAAQ,eAAe,SAAS,YAA2B;AAC5F,QAAM,CAAC,UAAU,WAAW,IAAI,SAAgC,IAAI;AACpE,QAAM,CAAC,gBAAgB,iBAAiB,IAAI,SAAkB,IAAI;AAClE,QAAM,CAAC,cAAc,eAAe,IAAI,SAAkB,KAAK;AACzD,QAAA,UAAU,OAAuC,aAAa;AAEpE,YAAU,MAAM;AACd,YAAQ,UAAU;AAAA,EAAA,GACjB,CAAC,aAAa,CAAC;AAElB,YAAU,MAAM;AACd,UAAM,YAAY,IAAI,eAAe,QAAQ,EAAE,QAAQ;AACvD,cAAU,oBAAoB,OAAO;AAErC,UAAM,aAAa,YAAY;;AAC7B,YAAM,UAAU,WAAW;AAEvB,UAAA,UAAU,eAAe;AAC3B;AAAA,MAAA;AAII,cAAA,aAAQ,YAAR,iCAAkB;AAGpB,UAAA,UAAU,eAAe;AAC3B;AAAA,MAAA;AAGQ,gBAAA,eAAe,KAAK,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
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react"),e=require("react/jsx-runtime"),r=require("@embedpdf/core"),i=t.createContext({registry:null,isInitializing:!0,pluginsReady:!1});function n(t,e){const{width:r,height:i}=t.size;switch(e%4){case 1:return{matrix:`matrix(0, -1, 1, 0, 0, ${i})`,width:i,height:r};case 2:return{matrix:`matrix(-1, 0, 0, -1, ${r}, ${i})`,width:r,height:i};case 3:return{matrix:`matrix(0, 1, -1, 0, ${r}, 0)`,width:i,height:r};default:return{matrix:"matrix(1, 0, 0, 1, 0, 0)",width:r,height:i}}}function o(){const e=t.useContext(i);if(void 0===e)throw new Error("useCapability must be used within a PDFContext.Provider");const{registry:r,isInitializing:n}=e;if(n)return e;if(null===r)throw new Error("PDF registry failed to initialize properly");return e}function s(t){const{registry:e}=o();if(null===e)return{plugin:null,isLoading:!0,ready:new Promise((()=>{}))};const r=e.getPlugin(t);if(!r)throw new Error(`Plugin ${t} not found`);return{plugin:r,isLoading:!1,ready:r.ready()}}exports.CounterRotate=function({children:r,...i}){const{rect:o,rotation:s}=i,{matrix:u,width:a,height:l}=n(o,s),c={style:{position:"absolute",left:o.origin.x,top:o.origin.y,transform:u,transformOrigin:"0 0",width:a,height:l,pointerEvents:"none",zIndex:3},onPointerDown:t=>t.stopPropagation(),onTouchStart:t=>t.stopPropagation()};return e.jsx(t.Fragment,{children:r({menuWrapperProps:c,matrix:u,rect:{origin:{x:o.origin.x,y:o.origin.y},size:{width:a,height:l}}})})},exports.EmbedPDF=function({engine:n,onInitialized:o,plugins:s,children:u}){const[a,l]=t.useState(null),[c,g]=t.useState(!0),[d,p]=t.useState(!1),h=t.useRef(o);return t.useEffect((()=>{h.current=o}),[o]),t.useEffect((()=>{const t=new r.PluginRegistry(n);t.registerPluginBatch(s);return(async()=>{var e;await t.initialize(),t.isDestroyed()||(await(null==(e=h.current)?void 0:e.call(h,t)),t.isDestroyed()||(t.pluginsReady().then((()=>{t.isDestroyed()||p(!0)})),l(t),g(!1)))})().catch(console.error),()=>{t.destroy(),l(null),g(!0),p(!1)}}),[n,s]),e.jsx(i.Provider,{value:{registry:a,isInitializing:c,pluginsReady:d},children:"function"==typeof u?u({registry:a,isInitializing:c,pluginsReady:d}):u})},exports.PDFContext=i,exports.getCounterRotation=n,exports.useCapability=function(t){const{plugin:e,isLoading:r,ready:i}=s(t);if(!e)return{provides:null,isLoading:r,ready:i};if(!e.provides)throw new Error(`Plugin ${t} does not provide a capability`);return{provides:e.provides(),isLoading:r,ready:i}},exports.useCoreState=function(){const{registry:e}=o(),[i,n]=t.useState(null);return t.useEffect((()=>{if(!e)return;const t=e.getStore();n(t.getState().core);const i=t.subscribe(((e,i,o)=>{t.isCoreAction(e)&&!r.arePropsEqual(i.core,o.core)&&n(i.core)}));return()=>i()}),[e]),i},exports.usePlugin=s,exports.useRegistry=o,exports.useStoreState=function(){const{registry:e}=o(),[r,i]=t.useState(null);return t.useEffect((()=>{if(!e)return;i(e.getStore().getState());const t=e.getStore().subscribe(((t,e)=>{i(e)}));return()=>t()}),[e]),r};
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react"),t=require("react/jsx-runtime"),r=require("@embedpdf/core"),i=e.createContext({registry:null,isInitializing:!0,pluginsReady:!1});function n(e,t){const{width:r,height:i}=e.size;switch(t%4){case 1:return{matrix:`matrix(0, -1, 1, 0, 0, ${i})`,width:i,height:r};case 2:return{matrix:`matrix(-1, 0, 0, -1, ${r}, ${i})`,width:r,height:i};case 3:return{matrix:`matrix(0, 1, -1, 0, ${r}, 0)`,width:i,height:r};default:return{matrix:"matrix(1, 0, 0, 1, 0, 0)",width:r,height:i}}}function o(){const t=e.useContext(i);if(void 0===t)throw new Error("useCapability must be used within a PDFContext.Provider");const{registry:r,isInitializing:n}=t;if(n)return t;if(null===r)throw new Error("PDF registry failed to initialize properly");return t}function s(e){const{registry:t}=o();if(null===t)return{plugin:null,isLoading:!0,ready:new Promise((()=>{}))};const r=t.getPlugin(e);if(!r)throw new Error(`Plugin ${e} not found`);return{plugin:r,isLoading:!1,ready:r.ready()}}exports.CounterRotate=function({children:r,...i}){const{rect:o,rotation:s}=i,{matrix:u,width:a,height:g}=n(o,s),l={style:{position:"absolute",left:o.origin.x,top:o.origin.y,transform:u,transformOrigin:"0 0",width:a,height:g,pointerEvents:"none",zIndex:3},onPointerDown:e=>e.stopPropagation(),onTouchStart:e=>e.stopPropagation()};return t.jsx(e.Fragment,{children:r({menuWrapperProps:l,matrix:u,rect:{origin:{x:o.origin.x,y:o.origin.y},size:{width:a,height:g}}})})},exports.EmbedPDF=function({engine:n,logger:o,onInitialized:s,plugins:u,children:a}){const[g,l]=e.useState(null),[c,d]=e.useState(!0),[p,h]=e.useState(!1),f=e.useRef(s);return e.useEffect((()=>{f.current=s}),[s]),e.useEffect((()=>{const e=new r.PluginRegistry(n,{logger:o});e.registerPluginBatch(u);return(async()=>{var t;await e.initialize(),e.isDestroyed()||(await(null==(t=f.current)?void 0:t.call(f,e)),e.isDestroyed()||(e.pluginsReady().then((()=>{e.isDestroyed()||h(!0)})),l(e),d(!1)))})().catch(console.error),()=>{e.destroy(),l(null),d(!0),h(!1)}}),[n,u]),t.jsx(i.Provider,{value:{registry:g,isInitializing:c,pluginsReady:p},children:"function"==typeof a?a({registry:g,isInitializing:c,pluginsReady:p}):a})},exports.PDFContext=i,exports.getCounterRotation=n,exports.useCapability=function(e){const{plugin:t,isLoading:r,ready:i}=s(e);if(!t)return{provides:null,isLoading:r,ready:i};if(!t.provides)throw new Error(`Plugin ${e} does not provide a capability`);return{provides:t.provides(),isLoading:r,ready:i}},exports.useCoreState=function(){const{registry:t}=o(),[i,n]=e.useState(null);return e.useEffect((()=>{if(!t)return;const e=t.getStore();n(e.getState().core);const i=e.subscribe(((t,i,o)=>{e.isCoreAction(t)&&!r.arePropsEqual(i.core,o.core)&&n(i.core)}));return()=>i()}),[t]),i},exports.usePlugin=s,exports.useRegistry=o,exports.useStoreState=function(){const{registry:t}=o(),[r,i]=e.useState(null);return e.useEffect((()=>{if(!t)return;i(t.getStore().getState());const e=t.getStore().subscribe(((e,t)=>{i(t)}));return()=>e()}),[t]),r};
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../../src/shared/context.ts","../../src/shared/components/counter-rotate-container.tsx","../../src/shared/hooks/use-registry.ts","../../src/shared/hooks/use-plugin.ts","../../src/shared/components/embed-pdf.tsx","../../src/shared/hooks/use-capability.ts","../../src/shared/hooks/use-core-state.ts","../../src/shared/hooks/use-store-state.ts"],"sourcesContent":["import { createContext } from '@framework';\nimport type { PluginRegistry } from '@embedpdf/core';\n\nexport interface PDFContextState {\n registry: PluginRegistry | null;\n isInitializing: boolean;\n pluginsReady: boolean;\n}\n\nexport const PDFContext = createContext<PDFContextState>({\n registry: null,\n isInitializing: true,\n pluginsReady: false,\n});\n","import { Rect, Rotation } from '@embedpdf/models';\nimport { ReactNode, CSSProperties, PointerEvent, Fragment, TouchEvent } from '@framework';\n\ninterface CounterRotateProps {\n rect: Rect;\n rotation: Rotation;\n}\n\ninterface CounterTransformResult {\n matrix: string; // CSS matrix(a,b,c,d,e,f)\n width: number; // new width\n height: number; // new height\n}\n\n/**\n * Given an already-placed rect (left/top/width/height in px) and the page rotation,\n * return the counter-rotation matrix + adjusted width/height.\n *\n * transform-origin is expected to be \"0 0\".\n * left/top DO NOT change, apply them as-is.\n */\nexport function getCounterRotation(rect: Rect, rotation: Rotation): CounterTransformResult {\n const { width: w, height: h } = rect.size;\n\n switch (rotation % 4) {\n case 1: // 90° cw → need matrix(0,-1,1,0,0,h) and swap w/h\n return {\n matrix: `matrix(0, -1, 1, 0, 0, ${h})`,\n width: h,\n height: w,\n };\n\n case 2: // 180° → matrix(-1,0,0,-1,w,h), width/height unchanged\n return {\n matrix: `matrix(-1, 0, 0, -1, ${w}, ${h})`,\n width: w,\n height: h,\n };\n\n case 3: // 270° cw → matrix(0,1,-1,0,w,0), swap w/h\n return {\n matrix: `matrix(0, 1, -1, 0, ${w}, 0)`,\n width: h,\n height: w,\n };\n\n default:\n return {\n matrix: `matrix(1, 0, 0, 1, 0, 0)`,\n width: w,\n height: h,\n };\n }\n}\n\nexport interface MenuWrapperProps {\n style: CSSProperties;\n onPointerDown: (e: PointerEvent<HTMLDivElement>) => void;\n onTouchStart: (e: TouchEvent<HTMLDivElement>) => void;\n}\n\ninterface CounterRotateComponentProps extends CounterRotateProps {\n children: (props: {\n matrix: string;\n rect: Rect;\n menuWrapperProps: MenuWrapperProps;\n }) => ReactNode;\n}\n\nexport function CounterRotate({ children, ...props }: CounterRotateComponentProps) {\n const { rect, rotation } = props;\n const { matrix, width, height } = getCounterRotation(rect, rotation);\n\n const menuWrapperStyle: CSSProperties = {\n position: 'absolute',\n left: rect.origin.x,\n top: rect.origin.y,\n transform: matrix,\n transformOrigin: '0 0',\n width: width,\n height: height,\n pointerEvents: 'none',\n zIndex: 3,\n };\n\n const menuWrapperProps = {\n style: menuWrapperStyle,\n onPointerDown: (e: PointerEvent<HTMLDivElement>) => e.stopPropagation(),\n onTouchStart: (e: TouchEvent<HTMLDivElement>) => e.stopPropagation(),\n };\n\n return (\n <Fragment>\n {children({\n menuWrapperProps,\n matrix,\n rect: {\n origin: { x: rect.origin.x, y: rect.origin.y },\n size: { width: width, height: height },\n },\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 { useState, useEffect, useRef, ReactNode } from '@framework';\nimport { PdfEngine } from '@embedpdf/models';\nimport { PluginRegistry } from '@embedpdf/core';\nimport type { IPlugin, PluginBatchRegistration } from '@embedpdf/core';\n\nimport { PDFContext, PDFContextState } from '../context';\n\ninterface EmbedPDFProps {\n engine: PdfEngine;\n onInitialized?: (registry: PluginRegistry) => Promise<void>;\n plugins: PluginBatchRegistration<IPlugin<any>, any>[];\n children: ReactNode | ((state: PDFContextState) => ReactNode);\n}\n\nexport function EmbedPDF({ engine, onInitialized, plugins, children }: EmbedPDFProps) {\n const [registry, setRegistry] = useState<PluginRegistry | 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; // update without triggering re-runs\n }, [onInitialized]);\n\n useEffect(() => {\n const pdfViewer = new PluginRegistry(engine);\n pdfViewer.registerPluginBatch(plugins);\n\n const initialize = async () => {\n await pdfViewer.initialize();\n // if the registry is destroyed, don't do anything\n if (pdfViewer.isDestroyed()) {\n return;\n }\n\n /* always call the *latest* callback */\n await initRef.current?.(pdfViewer);\n\n // if the registry is destroyed, don't do anything\n if (pdfViewer.isDestroyed()) {\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\n initialize().catch(console.error);\n\n return () => {\n pdfViewer.destroy();\n setRegistry(null);\n setIsInitializing(true);\n setPluginsReady(false);\n };\n }, [engine, plugins]);\n\n return (\n <PDFContext.Provider value={{ registry, isInitializing, pluginsReady }}>\n {typeof children === 'function'\n ? children({ registry, isInitializing, pluginsReady })\n : children}\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 { useState, useEffect } from '@framework';\nimport { CoreState, arePropsEqual } from '@embedpdf/core';\nimport { useRegistry } from './use-registry';\n\n/**\n * Hook that provides access to the current core state\n * and re-renders the component only when the core state changes\n */\nexport function useCoreState(): CoreState | null {\n const { registry } = useRegistry();\n const [coreState, setCoreState] = useState<CoreState | null>(null);\n\n useEffect(() => {\n if (!registry) return;\n\n const store = registry.getStore();\n\n // Get initial core state\n setCoreState(store.getState().core);\n\n // Create a single subscription that handles all core actions\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) && !arePropsEqual(newState.core, oldState.core)) {\n setCoreState(newState.core);\n }\n });\n\n return () => unsubscribe();\n }, [registry]);\n\n return coreState;\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","isInitializing","pluginsReady","getCounterRotation","rect","rotation","width","w","height","h","size","matrix","useRegistry","contextValue","useContext","Error","usePlugin","pluginId","plugin","isLoading","ready","Promise","getPlugin","children","props","menuWrapperProps","style","position","left","origin","x","top","y","transform","transformOrigin","pointerEvents","zIndex","onPointerDown","e","stopPropagation","onTouchStart","Fragment","engine","onInitialized","plugins","setRegistry","useState","setIsInitializing","setPluginsReady","initRef","useRef","jsx","useEffect","current","pdfViewer","PluginRegistry","registerPluginBatch","async","initialize","isDestroyed","_a","call","then","catch","console","error","destroy","Provider","value","provides","coreState","setCoreState","store","getStore","getState","core","unsubscribe","subscribe","action","newState","oldState","isCoreAction","arePropsEqual","state","setState","_action"],"mappings":"oKASaA,EAAaC,EAAAA,cAA+B,CACvDC,SAAU,KACVC,gBAAgB,EAChBC,cAAc,ICSA,SAAAC,EAAmBC,EAAYC,GAC7C,MAAQC,MAAOC,EAAGC,OAAQC,GAAML,EAAKM,KAErC,OAAQL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AC,QAEJ,uBC7BO,WACC,MAAApB,SAAEA,GAAaY,KACd0D,EAAWC,GAAgBzB,EAAAA,SAA2B,MAqBtD,OAnBPM,EAAAA,WAAU,KACR,IAAKpD,EAAU,OAET,MAAAwE,EAAQxE,EAASyE,WAGVF,EAAAC,EAAME,WAAWC,MAG9B,MAAMC,EAAcJ,EAAMK,WAAU,CAACC,EAAQC,EAAUC,KAEjDR,EAAMS,aAAaH,KAAYI,gBAAcH,EAASJ,KAAMK,EAASL,OACvEJ,EAAaQ,EAASJ,KAAI,IAI9B,MAAO,IAAMC,GAAY,GACxB,CAAC5E,IAEGsE,CACT,kECxBO,WACC,MAAAtE,SAAEA,GAAaY,KACduE,EAAOC,GAAYtC,EAAAA,SAA+B,MAgBlD,OAdPM,EAAAA,WAAU,KACR,IAAKpD,EAAU,OAGfoF,EAASpF,EAASyE,WAAWC,YAG7B,MAAME,EAAc5E,EAASyE,WAAWI,WAAU,CAACQ,EAASN,KAC1DK,EAASL,EAAyB,IAGpC,MAAO,IAAMH,GAAY,GACxB,CAAC5E,IAEGmF,CACT"}
1
+ {"version":3,"file":"index.cjs","sources":["../../src/shared/context.ts","../../src/shared/components/counter-rotate-container.tsx","../../src/shared/hooks/use-registry.ts","../../src/shared/hooks/use-plugin.ts","../../src/shared/components/embed-pdf.tsx","../../src/shared/hooks/use-capability.ts","../../src/shared/hooks/use-core-state.ts","../../src/shared/hooks/use-store-state.ts"],"sourcesContent":["import { createContext } from '@framework';\nimport type { PluginRegistry } from '@embedpdf/core';\n\nexport interface PDFContextState {\n registry: PluginRegistry | null;\n isInitializing: boolean;\n pluginsReady: boolean;\n}\n\nexport const PDFContext = createContext<PDFContextState>({\n registry: null,\n isInitializing: true,\n pluginsReady: false,\n});\n","import { Rect, Rotation } from '@embedpdf/models';\nimport { ReactNode, CSSProperties, PointerEvent, Fragment, TouchEvent } from '@framework';\n\ninterface CounterRotateProps {\n rect: Rect;\n rotation: Rotation;\n}\n\ninterface CounterTransformResult {\n matrix: string; // CSS matrix(a,b,c,d,e,f)\n width: number; // new width\n height: number; // new height\n}\n\n/**\n * Given an already-placed rect (left/top/width/height in px) and the page rotation,\n * return the counter-rotation matrix + adjusted width/height.\n *\n * transform-origin is expected to be \"0 0\".\n * left/top DO NOT change, apply them as-is.\n */\nexport function getCounterRotation(rect: Rect, rotation: Rotation): CounterTransformResult {\n const { width: w, height: h } = rect.size;\n\n switch (rotation % 4) {\n case 1: // 90° cw → need matrix(0,-1,1,0,0,h) and swap w/h\n return {\n matrix: `matrix(0, -1, 1, 0, 0, ${h})`,\n width: h,\n height: w,\n };\n\n case 2: // 180° → matrix(-1,0,0,-1,w,h), width/height unchanged\n return {\n matrix: `matrix(-1, 0, 0, -1, ${w}, ${h})`,\n width: w,\n height: h,\n };\n\n case 3: // 270° cw → matrix(0,1,-1,0,w,0), swap w/h\n return {\n matrix: `matrix(0, 1, -1, 0, ${w}, 0)`,\n width: h,\n height: w,\n };\n\n default:\n return {\n matrix: `matrix(1, 0, 0, 1, 0, 0)`,\n width: w,\n height: h,\n };\n }\n}\n\nexport interface MenuWrapperProps {\n style: CSSProperties;\n onPointerDown: (e: PointerEvent<HTMLDivElement>) => void;\n onTouchStart: (e: TouchEvent<HTMLDivElement>) => void;\n}\n\ninterface CounterRotateComponentProps extends CounterRotateProps {\n children: (props: {\n matrix: string;\n rect: Rect;\n menuWrapperProps: MenuWrapperProps;\n }) => ReactNode;\n}\n\nexport function CounterRotate({ children, ...props }: CounterRotateComponentProps) {\n const { rect, rotation } = props;\n const { matrix, width, height } = getCounterRotation(rect, rotation);\n\n const menuWrapperStyle: CSSProperties = {\n position: 'absolute',\n left: rect.origin.x,\n top: rect.origin.y,\n transform: matrix,\n transformOrigin: '0 0',\n width: width,\n height: height,\n pointerEvents: 'none',\n zIndex: 3,\n };\n\n const menuWrapperProps = {\n style: menuWrapperStyle,\n onPointerDown: (e: PointerEvent<HTMLDivElement>) => e.stopPropagation(),\n onTouchStart: (e: TouchEvent<HTMLDivElement>) => e.stopPropagation(),\n };\n\n return (\n <Fragment>\n {children({\n menuWrapperProps,\n matrix,\n rect: {\n origin: { x: rect.origin.x, y: rect.origin.y },\n size: { width: width, height: height },\n },\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 { useState, useEffect, useRef, ReactNode } from '@framework';\nimport { Logger, PdfEngine } from '@embedpdf/models';\nimport { PluginRegistry } from '@embedpdf/core';\nimport type { IPlugin, PluginBatchRegistration } from '@embedpdf/core';\n\nimport { PDFContext, PDFContextState } from '../context';\n\ninterface EmbedPDFProps {\n engine: PdfEngine;\n logger?: Logger;\n onInitialized?: (registry: PluginRegistry) => Promise<void>;\n plugins: PluginBatchRegistration<IPlugin<any>, any>[];\n children: ReactNode | ((state: PDFContextState) => ReactNode);\n}\n\nexport function EmbedPDF({ engine, logger, onInitialized, plugins, children }: EmbedPDFProps) {\n const [registry, setRegistry] = useState<PluginRegistry | 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; // update without triggering re-runs\n }, [onInitialized]);\n\n useEffect(() => {\n const pdfViewer = new PluginRegistry(engine, { logger });\n pdfViewer.registerPluginBatch(plugins);\n\n const initialize = async () => {\n await pdfViewer.initialize();\n // if the registry is destroyed, don't do anything\n if (pdfViewer.isDestroyed()) {\n return;\n }\n\n /* always call the *latest* callback */\n await initRef.current?.(pdfViewer);\n\n // if the registry is destroyed, don't do anything\n if (pdfViewer.isDestroyed()) {\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\n initialize().catch(console.error);\n\n return () => {\n pdfViewer.destroy();\n setRegistry(null);\n setIsInitializing(true);\n setPluginsReady(false);\n };\n }, [engine, plugins]);\n\n return (\n <PDFContext.Provider value={{ registry, isInitializing, pluginsReady }}>\n {typeof children === 'function'\n ? children({ registry, isInitializing, pluginsReady })\n : children}\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 { useState, useEffect } from '@framework';\nimport { CoreState, arePropsEqual } from '@embedpdf/core';\nimport { useRegistry } from './use-registry';\n\n/**\n * Hook that provides access to the current core state\n * and re-renders the component only when the core state changes\n */\nexport function useCoreState(): CoreState | null {\n const { registry } = useRegistry();\n const [coreState, setCoreState] = useState<CoreState | null>(null);\n\n useEffect(() => {\n if (!registry) return;\n\n const store = registry.getStore();\n\n // Get initial core state\n setCoreState(store.getState().core);\n\n // Create a single subscription that handles all core actions\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) && !arePropsEqual(newState.core, oldState.core)) {\n setCoreState(newState.core);\n }\n });\n\n return () => unsubscribe();\n }, [registry]);\n\n return coreState;\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","isInitializing","pluginsReady","getCounterRotation","rect","rotation","width","w","height","h","size","matrix","useRegistry","contextValue","useContext","Error","usePlugin","pluginId","plugin","isLoading","ready","Promise","getPlugin","children","props","menuWrapperProps","style","position","left","origin","x","top","y","transform","transformOrigin","pointerEvents","zIndex","onPointerDown","e","stopPropagation","onTouchStart","Fragment","engine","logger","onInitialized","plugins","setRegistry","useState","setIsInitializing","setPluginsReady","initRef","useRef","jsx","useEffect","current","pdfViewer","PluginRegistry","registerPluginBatch","async","initialize","isDestroyed","_a","call","then","catch","console","error","destroy","Provider","value","provides","coreState","setCoreState","store","getStore","getState","core","unsubscribe","subscribe","action","newState","oldState","isCoreAction","arePropsEqual","state","setState","_action"],"mappings":"oKASaA,EAAaC,EAAAA,cAA+B,CACvDC,SAAU,KACVC,gBAAgB,EAChBC,cAAc,ICSA,SAAAC,EAAmBC,EAAYC,GAC7C,MAAQC,MAAOC,EAAGC,OAAQC,GAAML,EAAKM,KAErC,OAAQL,EAAW,GACjB,KAAK,EACI,MAAA,CACLM,OAAQ,0BAA0BF,KAClCH,MAAOG,EACPD,OAAQD,GAGZ,KAAK,EACI,MAAA,CACLI,OAAQ,wBAAwBJ,MAAME,KACtCH,MAAOC,EACPC,OAAQC,GAGZ,KAAK,EACI,MAAA,CACLE,OAAQ,uBAAuBJ,QAC/BD,MAAOG,EACPD,OAAQD,GAGZ,QACS,MAAA,CACLI,OAAQ,2BACRL,MAAOC,EACPC,OAAQC,GAGhB,CC9CO,SAASG,IACR,MAAAC,EAAeC,aAAWhB,GAGhC,QAAqB,IAAjBe,EACI,MAAA,IAAIE,MAAM,2DAGZ,MAAAf,SAAEA,EAAUC,eAAAA,GAAmBY,EAGrC,GAAIZ,EACK,OAAAY,EAIT,GAAiB,OAAbb,EACI,MAAA,IAAIe,MAAM,8CAGX,OAAAF,CACT,CCXO,SAASG,EAAgCC,GACxC,MAAAjB,SAAEA,GAAaY,IAErB,GAAiB,OAAbZ,EACK,MAAA,CACLkB,OAAQ,KACRC,WAAW,EACXC,MAAO,IAAIC,SAAQ,UAIjB,MAAAH,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C7E,IAEGoF,CACT"}
@@ -6,7 +6,7 @@ const PDFContext = createContext({
6
6
  isInitializing: true,
7
7
  pluginsReady: false
8
8
  });
9
- function EmbedPDF({ engine, onInitialized, plugins, children }) {
9
+ function EmbedPDF({ engine, logger, onInitialized, plugins, children }) {
10
10
  const [registry, setRegistry] = useState(null);
11
11
  const [isInitializing, setIsInitializing] = useState(true);
12
12
  const [pluginsReady, setPluginsReady] = useState(false);
@@ -15,7 +15,7 @@ function EmbedPDF({ engine, onInitialized, plugins, children }) {
15
15
  initRef.current = onInitialized;
16
16
  }, [onInitialized]);
17
17
  useEffect(() => {
18
- const pdfViewer = new PluginRegistry(engine);
18
+ const pdfViewer = new PluginRegistry(engine, { logger });
19
19
  pdfViewer.registerPluginBatch(plugins);
20
20
  const initialize = async () => {
21
21
  var _a;
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/shared/context.ts","../../src/shared/components/embed-pdf.tsx","../../src/shared/components/counter-rotate-container.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"],"sourcesContent":["import { createContext } from '@framework';\nimport type { PluginRegistry } from '@embedpdf/core';\n\nexport interface PDFContextState {\n registry: PluginRegistry | null;\n isInitializing: boolean;\n pluginsReady: boolean;\n}\n\nexport const PDFContext = createContext<PDFContextState>({\n registry: null,\n isInitializing: true,\n pluginsReady: false,\n});\n","import { useState, useEffect, useRef, ReactNode } from '@framework';\nimport { PdfEngine } from '@embedpdf/models';\nimport { PluginRegistry } from '@embedpdf/core';\nimport type { IPlugin, PluginBatchRegistration } from '@embedpdf/core';\n\nimport { PDFContext, PDFContextState } from '../context';\n\ninterface EmbedPDFProps {\n engine: PdfEngine;\n onInitialized?: (registry: PluginRegistry) => Promise<void>;\n plugins: PluginBatchRegistration<IPlugin<any>, any>[];\n children: ReactNode | ((state: PDFContextState) => ReactNode);\n}\n\nexport function EmbedPDF({ engine, onInitialized, plugins, children }: EmbedPDFProps) {\n const [registry, setRegistry] = useState<PluginRegistry | 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; // update without triggering re-runs\n }, [onInitialized]);\n\n useEffect(() => {\n const pdfViewer = new PluginRegistry(engine);\n pdfViewer.registerPluginBatch(plugins);\n\n const initialize = async () => {\n await pdfViewer.initialize();\n // if the registry is destroyed, don't do anything\n if (pdfViewer.isDestroyed()) {\n return;\n }\n\n /* always call the *latest* callback */\n await initRef.current?.(pdfViewer);\n\n // if the registry is destroyed, don't do anything\n if (pdfViewer.isDestroyed()) {\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\n initialize().catch(console.error);\n\n return () => {\n pdfViewer.destroy();\n setRegistry(null);\n setIsInitializing(true);\n setPluginsReady(false);\n };\n }, [engine, plugins]);\n\n return (\n <PDFContext.Provider value={{ registry, isInitializing, pluginsReady }}>\n {typeof children === 'function'\n ? children({ registry, isInitializing, pluginsReady })\n : children}\n </PDFContext.Provider>\n );\n}\n","import { Rect, Rotation } from '@embedpdf/models';\nimport { ReactNode, CSSProperties, PointerEvent, Fragment, TouchEvent } from '@framework';\n\ninterface CounterRotateProps {\n rect: Rect;\n rotation: Rotation;\n}\n\ninterface CounterTransformResult {\n matrix: string; // CSS matrix(a,b,c,d,e,f)\n width: number; // new width\n height: number; // new height\n}\n\n/**\n * Given an already-placed rect (left/top/width/height in px) and the page rotation,\n * return the counter-rotation matrix + adjusted width/height.\n *\n * transform-origin is expected to be \"0 0\".\n * left/top DO NOT change, apply them as-is.\n */\nexport function getCounterRotation(rect: Rect, rotation: Rotation): CounterTransformResult {\n const { width: w, height: h } = rect.size;\n\n switch (rotation % 4) {\n case 1: // 90° cw → need matrix(0,-1,1,0,0,h) and swap w/h\n return {\n matrix: `matrix(0, -1, 1, 0, 0, ${h})`,\n width: h,\n height: w,\n };\n\n case 2: // 180° → matrix(-1,0,0,-1,w,h), width/height unchanged\n return {\n matrix: `matrix(-1, 0, 0, -1, ${w}, ${h})`,\n width: w,\n height: h,\n };\n\n case 3: // 270° cw → matrix(0,1,-1,0,w,0), swap w/h\n return {\n matrix: `matrix(0, 1, -1, 0, ${w}, 0)`,\n width: h,\n height: w,\n };\n\n default:\n return {\n matrix: `matrix(1, 0, 0, 1, 0, 0)`,\n width: w,\n height: h,\n };\n }\n}\n\nexport interface MenuWrapperProps {\n style: CSSProperties;\n onPointerDown: (e: PointerEvent<HTMLDivElement>) => void;\n onTouchStart: (e: TouchEvent<HTMLDivElement>) => void;\n}\n\ninterface CounterRotateComponentProps extends CounterRotateProps {\n children: (props: {\n matrix: string;\n rect: Rect;\n menuWrapperProps: MenuWrapperProps;\n }) => ReactNode;\n}\n\nexport function CounterRotate({ children, ...props }: CounterRotateComponentProps) {\n const { rect, rotation } = props;\n const { matrix, width, height } = getCounterRotation(rect, rotation);\n\n const menuWrapperStyle: CSSProperties = {\n position: 'absolute',\n left: rect.origin.x,\n top: rect.origin.y,\n transform: matrix,\n transformOrigin: '0 0',\n width: width,\n height: height,\n pointerEvents: 'none',\n zIndex: 3,\n };\n\n const menuWrapperProps = {\n style: menuWrapperStyle,\n onPointerDown: (e: PointerEvent<HTMLDivElement>) => e.stopPropagation(),\n onTouchStart: (e: TouchEvent<HTMLDivElement>) => e.stopPropagation(),\n };\n\n return (\n <Fragment>\n {children({\n menuWrapperProps,\n matrix,\n rect: {\n origin: { x: rect.origin.x, y: rect.origin.y },\n size: { width: width, height: height },\n },\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 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 { useState, useEffect } from '@framework';\nimport { CoreState, arePropsEqual } from '@embedpdf/core';\nimport { useRegistry } from './use-registry';\n\n/**\n * Hook that provides access to the current core state\n * and re-renders the component only when the core state changes\n */\nexport function useCoreState(): CoreState | null {\n const { registry } = useRegistry();\n const [coreState, setCoreState] = useState<CoreState | null>(null);\n\n useEffect(() => {\n if (!registry) return;\n\n const store = registry.getStore();\n\n // Get initial core state\n setCoreState(store.getState().core);\n\n // Create a single subscription that handles all core actions\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) && !arePropsEqual(newState.core, oldState.core)) {\n setCoreState(newState.core);\n }\n });\n\n return () => unsubscribe();\n }, [registry]);\n\n return coreState;\n}\n"],"names":[],"mappings":";;;AASO,MAAM,aAAa,cAA+B;AAAA,EACvD,UAAU;AAAA,EACV,gBAAgB;AAAA,EAChB,cAAc;AAChB,CAAC;ACCM,SAAS,SAAS,EAAE,QAAQ,eAAe,SAAS,YAA2B;AACpF,QAAM,CAAC,UAAU,WAAW,IAAI,SAAgC,IAAI;AACpE,QAAM,CAAC,gBAAgB,iBAAiB,IAAI,S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M,CAAC,WAAW,YAAY,IAAI,SAA2B,IAAI;AAEjE,YAAU,MAAM;AACd,QAAI,CAAC,SAAU;AAET,UAAA,QAAQ,SAAS,SAAS;AAGnB,iBAAA,MAAM,SAAS,EAAE,IAAI;AAGlC,UAAM,cAAc,MAAM,UAAU,CAAC,QAAQ,UAAU,aAAa;AAE9D,UAAA,MAAM,aAAa,MAAM,KAAK,CAAC,cAAc,SAAS,MAAM,SAAS,IAAI,GAAG;AAC9E,qBAAa,SAAS,IAAI;AAAA,MAAA;AAAA,IAC5B,CACD;AAED,WAAO,MAAM,YAAY;AAAA,EAAA,GACxB,CAAC,QAAQ,CAAC;AAEN,SAAA;AACT;"}
1
+ {"version":3,"file":"index.js","sources":["../../src/shared/context.ts","../../src/shared/components/embed-pdf.tsx","../../src/shared/components/counter-rotate-container.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"],"sourcesContent":["import { createContext } from '@framework';\nimport type { PluginRegistry } from '@embedpdf/core';\n\nexport interface PDFContextState {\n registry: PluginRegistry | null;\n isInitializing: boolean;\n pluginsReady: boolean;\n}\n\nexport const PDFContext = createContext<PDFContextState>({\n registry: null,\n isInitializing: true,\n pluginsReady: false,\n});\n","import { useState, useEffect, useRef, ReactNode } from '@framework';\nimport { Logger, PdfEngine } from '@embedpdf/models';\nimport { PluginRegistry } from '@embedpdf/core';\nimport type { IPlugin, PluginBatchRegistration } from '@embedpdf/core';\n\nimport { PDFContext, PDFContextState } from '../context';\n\ninterface EmbedPDFProps {\n engine: PdfEngine;\n logger?: Logger;\n onInitialized?: (registry: PluginRegistry) => Promise<void>;\n plugins: PluginBatchRegistration<IPlugin<any>, any>[];\n children: ReactNode | ((state: PDFContextState) => ReactNode);\n}\n\nexport function EmbedPDF({ engine, logger, onInitialized, plugins, children }: EmbedPDFProps) {\n const [registry, setRegistry] = useState<PluginRegistry | 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; // update without triggering re-runs\n }, [onInitialized]);\n\n useEffect(() => {\n const pdfViewer = new PluginRegistry(engine, { logger });\n pdfViewer.registerPluginBatch(plugins);\n\n const initialize = async () => {\n await pdfViewer.initialize();\n // if the registry is destroyed, don't do anything\n if (pdfViewer.isDestroyed()) {\n return;\n }\n\n /* always call the *latest* callback */\n await initRef.current?.(pdfViewer);\n\n // if the registry is destroyed, don't do anything\n if (pdfViewer.isDestroyed()) {\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\n initialize().catch(console.error);\n\n return () => {\n pdfViewer.destroy();\n setRegistry(null);\n setIsInitializing(true);\n setPluginsReady(false);\n };\n }, [engine, plugins]);\n\n return (\n <PDFContext.Provider value={{ registry, isInitializing, pluginsReady }}>\n {typeof children === 'function'\n ? children({ registry, isInitializing, pluginsReady })\n : children}\n </PDFContext.Provider>\n );\n}\n","import { Rect, Rotation } from '@embedpdf/models';\nimport { ReactNode, CSSProperties, PointerEvent, Fragment, TouchEvent } from '@framework';\n\ninterface CounterRotateProps {\n rect: Rect;\n rotation: Rotation;\n}\n\ninterface CounterTransformResult {\n matrix: string; // CSS matrix(a,b,c,d,e,f)\n width: number; // new width\n height: number; // new height\n}\n\n/**\n * Given an already-placed rect (left/top/width/height in px) and the page rotation,\n * return the counter-rotation matrix + adjusted width/height.\n *\n * transform-origin is expected to be \"0 0\".\n * left/top DO NOT change, apply them as-is.\n */\nexport function getCounterRotation(rect: Rect, rotation: Rotation): CounterTransformResult {\n const { width: w, height: h } = rect.size;\n\n switch (rotation % 4) {\n case 1: // 90° cw → need matrix(0,-1,1,0,0,h) and swap w/h\n return {\n matrix: `matrix(0, -1, 1, 0, 0, ${h})`,\n width: h,\n height: w,\n };\n\n case 2: // 180° → matrix(-1,0,0,-1,w,h), width/height unchanged\n return {\n matrix: `matrix(-1, 0, 0, -1, ${w}, ${h})`,\n width: w,\n height: h,\n };\n\n case 3: // 270° cw → matrix(0,1,-1,0,w,0), swap w/h\n return {\n matrix: `matrix(0, 1, -1, 0, ${w}, 0)`,\n width: h,\n height: w,\n };\n\n default:\n return {\n matrix: `matrix(1, 0, 0, 1, 0, 0)`,\n width: w,\n height: h,\n };\n }\n}\n\nexport interface MenuWrapperProps {\n style: CSSProperties;\n onPointerDown: (e: PointerEvent<HTMLDivElement>) => void;\n onTouchStart: (e: TouchEvent<HTMLDivElement>) => void;\n}\n\ninterface CounterRotateComponentProps extends CounterRotateProps {\n children: (props: {\n matrix: string;\n rect: Rect;\n menuWrapperProps: MenuWrapperProps;\n }) => ReactNode;\n}\n\nexport function CounterRotate({ children, ...props }: CounterRotateComponentProps) {\n const { rect, rotation } = props;\n const { matrix, width, height } = getCounterRotation(rect, rotation);\n\n const menuWrapperStyle: CSSProperties = {\n position: 'absolute',\n left: rect.origin.x,\n top: rect.origin.y,\n transform: matrix,\n transformOrigin: '0 0',\n width: width,\n height: height,\n pointerEvents: 'none',\n zIndex: 3,\n };\n\n const menuWrapperProps = {\n style: menuWrapperStyle,\n onPointerDown: (e: PointerEvent<HTMLDivElement>) => e.stopPropagation(),\n onTouchStart: (e: TouchEvent<HTMLDivElement>) => e.stopPropagation(),\n };\n\n return (\n <Fragment>\n {children({\n menuWrapperProps,\n matrix,\n rect: {\n origin: { x: rect.origin.x, y: rect.origin.y },\n size: { width: width, height: height },\n },\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 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 { useState, useEffect } from '@framework';\nimport { CoreState, arePropsEqual } from '@embedpdf/core';\nimport { useRegistry } from './use-registry';\n\n/**\n * Hook that provides access to the current core state\n * and re-renders the component only when the core state changes\n */\nexport function useCoreState(): CoreState | null {\n const { registry } = useRegistry();\n const [coreState, setCoreState] = useState<CoreState | null>(null);\n\n useEffect(() => {\n if (!registry) return;\n\n const store = registry.getStore();\n\n // Get initial core state\n setCoreState(store.getState().core);\n\n // Create a single subscription that handles all core actions\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) && !arePropsEqual(newState.core, oldState.core)) {\n setCoreState(newState.core);\n }\n });\n\n return () => unsubscribe();\n }, [registry]);\n\n return coreState;\n}\n"],"names":[],"mappings":";;;AASO,MAAM,aAAa,cAA+B;AAAA,EACvD,UAAU;AAAA,EACV,gBAAgB;AAAA,EAChB,cAAc;AAChB,CAAC;ACEM,SAAS,SAAS,EAAE,QAAQ,QAAQ,eAAe,SAAS,YAA2B;AAC5F,QAAM,CAAC,UAAU,WAAW,IAAI,SAAgC,IAAI;AACpE,QAAM,CAAC,gBAAgB,iBAAiB,IAAI,SAAkB,IAAI;AAClE,QAAM,CAAC,cAAc,eAAe,IAAI,SAAkB,KAAK;AAC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AU,MAAM;AACd,QAAI,CAAC,SAAU;AAET,UAAA,QAAQ,SAAS,SAAS;AAGnB,iBAAA,MAAM,SAAS,EAAE,IAAI;AAGlC,UAAM,cAAc,MAAM,UAAU,CAAC,QAAQ,UAAU,aAAa;AAE9D,UAAA,MAAM,aAAa,MAAM,KAAK,CAAC,cAAc,SAAS,MAAM,SAAS,IAAI,GAAG;AAC9E,qBAAa,SAAS,IAAI;AAAA,MAAA;AAAA,IAC5B,CACD;AAED,WAAO,MAAM,YAAY;AAAA,EAAA,GACxB,CAAC,QAAQ,CAAC;AAEN,SAAA;AACT;"}
@@ -1,12 +1,13 @@
1
1
  import { ReactNode } from '../../preact/adapter.ts';
2
- import { PdfEngine } from '@embedpdf/models';
2
+ import { Logger, PdfEngine } from '@embedpdf/models';
3
3
  import { PluginRegistry, IPlugin, PluginBatchRegistration } from '../../lib/index.ts';
4
4
  import { PDFContextState } from '../context';
5
5
  interface EmbedPDFProps {
6
6
  engine: PdfEngine;
7
+ logger?: Logger;
7
8
  onInitialized?: (registry: PluginRegistry) => Promise<void>;
8
9
  plugins: PluginBatchRegistration<IPlugin<any>, any>[];
9
10
  children: ReactNode | ((state: PDFContextState) => ReactNode);
10
11
  }
11
- export declare function EmbedPDF({ engine, onInitialized, plugins, children }: EmbedPDFProps): import("preact").JSX.Element;
12
+ export declare function EmbedPDF({ engine, logger, onInitialized, plugins, children }: EmbedPDFProps): import("preact").JSX.Element;
12
13
  export {};
@@ -1,12 +1,13 @@
1
1
  import { ReactNode } from '../../react/adapter.ts';
2
- import { PdfEngine } from '@embedpdf/models';
2
+ import { Logger, PdfEngine } from '@embedpdf/models';
3
3
  import { PluginRegistry, IPlugin, PluginBatchRegistration } from '../../lib/index.ts';
4
4
  import { PDFContextState } from '../context';
5
5
  interface EmbedPDFProps {
6
6
  engine: PdfEngine;
7
+ logger?: Logger;
7
8
  onInitialized?: (registry: PluginRegistry) => Promise<void>;
8
9
  plugins: PluginBatchRegistration<IPlugin<any>, any>[];
9
10
  children: ReactNode | ((state: PDFContextState) => ReactNode);
10
11
  }
11
- export declare function EmbedPDF({ engine, onInitialized, plugins, children }: EmbedPDFProps): import("react/jsx-runtime").JSX.Element;
12
+ export declare function EmbedPDF({ engine, logger, onInitialized, plugins, children }: EmbedPDFProps): import("react/jsx-runtime").JSX.Element;
12
13
  export {};
@@ -1,7 +1,8 @@
1
1
  import { PluginRegistry, PluginBatchRegistration } from '../../lib/index.ts';
2
- import { PdfEngine } from '@embedpdf/models';
2
+ import { Logger, PdfEngine } from '@embedpdf/models';
3
3
  type __VLS_Props = {
4
4
  engine: PdfEngine;
5
+ logger?: Logger;
5
6
  plugins: PluginBatchRegistration<any, any>[];
6
7
  onInitialized?: (registry: PluginRegistry) => Promise<void>;
7
8
  };
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),n=require("@embedpdf/core"),r=Symbol("pdfKey");function t(){const n=e.inject(r);if(!n)throw new Error("useRegistry must be used inside <EmbedPDF>");return n}function o(n){const{registry:r}=t(),o=e.shallowRef(null),i=e.ref(!0),u=e.ref(new Promise((()=>{}))),l=()=>{var e;if(!r.value)return;const t=r.value.getPlugin(n);if(!t)throw new Error(`Plugin ${n} not found`);o.value=t,i.value=!1,u.value=(null==(e=t.ready)?void 0:e.call(t))??Promise.resolve()};return e.onMounted(l),e.watch(r,l),{plugin:o,isLoading:i,ready:u}}const i=e.defineComponent({__name:"embed-pdf",props:{engine:{},plugins:{},onInitialized:{type:Function}},setup(t){const o=t,i=e.shallowRef(null),u=e.ref(!0),l=e.ref(!1);return e.provide(r,{registry:i,isInitializing:u,pluginsReady:l}),e.onMounted((async()=>{var e;const r=new n.PluginRegistry(o.engine);r.registerPluginBatch(o.plugins),await r.initialize(),await(null==(e=o.onInitialized)?void 0:e.call(o,r)),i.value=r,u.value=!1,r.pluginsReady().then((()=>l.value=!0))})),e.onBeforeUnmount((()=>{var e;return null==(e=i.value)?void 0:e.destroy()})),(n,r)=>e.renderSlot(n.$slots,"default",{registry:i.value,isInitializing:u.value,pluginsReady:l.value})}});exports.EmbedPDF=i,exports.useCapability=function(n){const{plugin:r,isLoading:t,ready:i}=o(n);return{provides:e.computed((()=>{if(!r.value)return null;if(!r.value.provides)throw new Error(`Plugin ${n} does not implement provides()`);return r.value.provides()})),isLoading:t,ready:i}},exports.useCoreState=function(){const{registry:r}=t(),o=e.ref();return e.onMounted((()=>{const t=r.value.getStore();o.value=t.getState().core;const i=t.subscribe(((e,r,i)=>{t.isCoreAction(e)&&!n.arePropsEqual(r.core,i.core)&&(o.value=r.core)}));e.onBeforeUnmount(i)})),o},exports.usePlugin=o,exports.useRegistry=t,exports.useStoreState=function(){const{registry:n}=t(),r=e.ref();function o(){return n.value?(r.value=n.value.getStore().getState(),n.value.getStore().subscribe(((e,n)=>r.value=n))):()=>{}}let i=o();return e.watch(n,(()=>{null==i||i(),i=o()})),e.onBeforeUnmount((()=>null==i?void 0:i())),r};
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),n=require("@embedpdf/core"),r=Symbol("pdfKey");function t(){const n=e.inject(r);if(!n)throw new Error("useRegistry must be used inside <EmbedPDF>");return n}function o(n){const{registry:r}=t(),o=e.shallowRef(null),i=e.ref(!0),u=e.ref(new Promise((()=>{}))),l=()=>{var e;if(!r.value)return;const t=r.value.getPlugin(n);if(!t)throw new Error(`Plugin ${n} not found`);o.value=t,i.value=!1,u.value=(null==(e=t.ready)?void 0:e.call(t))??Promise.resolve()};return e.onMounted(l),e.watch(r,l),{plugin:o,isLoading:i,ready:u}}const i=e.defineComponent({__name:"embed-pdf",props:{engine:{},logger:{},plugins:{},onInitialized:{type:Function}},setup(t){const o=t,i=e.shallowRef(null),u=e.ref(!0),l=e.ref(!1);return e.provide(r,{registry:i,isInitializing:u,pluginsReady:l}),e.onMounted((async()=>{var e;const r=new n.PluginRegistry(o.engine,{logger:o.logger});r.registerPluginBatch(o.plugins),await r.initialize(),await(null==(e=o.onInitialized)?void 0:e.call(o,r)),i.value=r,u.value=!1,r.pluginsReady().then((()=>l.value=!0))})),e.onBeforeUnmount((()=>{var e;return null==(e=i.value)?void 0:e.destroy()})),(n,r)=>e.renderSlot(n.$slots,"default",{registry:i.value,isInitializing:u.value,pluginsReady:l.value})}});exports.EmbedPDF=i,exports.useCapability=function(n){const{plugin:r,isLoading:t,ready:i}=o(n);return{provides:e.computed((()=>{if(!r.value)return null;if(!r.value.provides)throw new Error(`Plugin ${n} does not implement provides()`);return r.value.provides()})),isLoading:t,ready:i}},exports.useCoreState=function(){const{registry:r}=t(),o=e.ref();return e.onMounted((()=>{const t=r.value.getStore();o.value=t.getState().core;const i=t.subscribe(((e,r,i)=>{t.isCoreAction(e)&&!n.arePropsEqual(r.core,i.core)&&(o.value=r.core)}));e.onBeforeUnmount(i)})),o},exports.usePlugin=o,exports.useRegistry=t,exports.useStoreState=function(){const{registry:n}=t(),r=e.ref();function o(){return n.value?(r.value=n.value.getStore().getState(),n.value.getStore().subscribe(((e,n)=>r.value=n))):()=>{}}let i=o();return e.watch(n,(()=>{null==i||i(),i=o()})),e.onBeforeUnmount((()=>null==i?void 0:i())),r};
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../../src/vue/context.ts","../../src/vue/composables/use-registry.ts","../../src/vue/composables/use-plugin.ts","../../src/vue/components/embed-pdf.vue","../../src/vue/composables/use-capability.ts","../../src/vue/composables/use-core-state.ts","../../src/vue/composables/use-store-state.ts"],"sourcesContent":["import { InjectionKey, Ref, ShallowRef } from 'vue';\nimport type { PluginRegistry } from '@embedpdf/core';\n\nexport interface PDFContextState {\n registry: ShallowRef<PluginRegistry | null>;\n isInitializing: Ref<boolean>;\n pluginsReady: Ref<boolean>;\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 { 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\">\nimport { ref, provide, onMounted, onBeforeUnmount, shallowRef } from 'vue';\nimport { PluginRegistry, PluginBatchRegistration } from '@embedpdf/core';\nimport { PdfEngine } from '@embedpdf/models';\nimport { pdfKey, PDFContextState } from '../context';\n\nconst props = defineProps<{\n engine: PdfEngine;\n plugins: PluginBatchRegistration<any, any>[];\n onInitialized?: (registry: PluginRegistry) => Promise<void>;\n}>();\n\n/* reactive state */\nconst registry = shallowRef<PluginRegistry | null>(null);\nconst isInit = ref(true);\nconst pluginsOk = ref(false);\n\n/* expose to children */\nprovide<PDFContextState>(pdfKey, { registry, isInitializing: isInit, pluginsReady: pluginsOk });\n\nonMounted(async () => {\n const reg = new PluginRegistry(props.engine);\n reg.registerPluginBatch(props.plugins);\n await reg.initialize();\n await props.onInitialized?.(reg);\n\n registry.value = reg;\n isInit.value = false;\n\n reg.pluginsReady().then(() => (pluginsOk.value = true));\n});\n\nonBeforeUnmount(() => registry.value?.destroy());\n</script>\n\n<template>\n <!-- scoped slot keeps API parity with React version -->\n <slot :registry=\"registry\"\n :isInitializing=\"isInit\"\n :pluginsReady=\"pluginsOk\" />\n</template>","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 } from 'vue';\nimport { arePropsEqual, type CoreState } from '@embedpdf/core';\nimport { useRegistry } from './use-registry';\n\nexport function useCoreState() {\n const { registry } = useRegistry();\n const core = ref<CoreState>();\n\n onMounted(() => {\n const store = registry.value!.getStore();\n core.value = store.getState().core;\n\n const unsub = store.subscribe((action, newSt, oldSt) => {\n if (store.isCoreAction(action) && !arePropsEqual(newSt.core, oldSt.core)) {\n core.value = newSt.core;\n }\n });\n onBeforeUnmount(unsub);\n });\n\n return core;\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","usePlugin","pluginId","registry","plugin","shallowRef","isLoading","ref","ready","Promise","load","value","p","getPlugin","_a","call","resolve","onMounted","vue","watch","props","__props","isInit","pluginsOk","provide","isInitializing","pluginsReady","async","reg","PluginRegistry","engine","registerPluginBatch","plugins","initialize","onInitialized","then","onBeforeUnmount","destroy","_renderSlot","_ctx","$slots","provides","computed","core","store","getStore","core$1","getState","unsub","subscribe","action","newSt","oldSt","isCoreAction","arePropsEqual","state","attach","_action","newState","unsubscribe"],"mappings":"mIASaA,EAAwCC,OAAO,UCNrD,SAASC,IACR,MAAAC,EAAMC,SAAOJ,GACnB,IAAKG,EAAW,MAAA,IAAIE,MAAM,8CACnB,OAAAF,CACT,CCGO,SAASG,EAAgCC,GACxC,MAAAC,SAAEA,GAAaN,IAEfO,EAASC,aAAW,MAEpBC,EAAYC,OAAI,GAChBC,EAAQD,EAAAA,IAAmB,IAAIE,SAAQ,UAEvCC,EAAO,WACP,IAACP,EAASQ,MAAO,OAErB,MAAMC,EAAIT,EAASQ,MAAME,UAAaX,GACtC,IAAKU,EAAG,MAAM,IAAIZ,MAAM,UAAUE,eAElCE,EAAOO,MAAQC,EACfN,EAAUK,OAAQ,EAClBH,EAAMG,OAAQ,OAAAG,EAAAF,EAAEJ,YAAF,EAAAM,EAAAC,KAAAH,KAAeH,QAAQO,SAAQ,EAMxC,OAHPC,EAAAA,UAAUP,GACVQ,EAAAC,MAAMhB,EAAUO,GAET,CAAEN,SAAQE,YAAWE,QA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A,IAGvBP,EAAAA,gBAAgBY,EAAK,IAGhBL,CACT,kECTO,WACC,MAAAxC,SAAEA,GAAaN,IACf0D,EAAQhD,EAAAA,MAEd,SAASiD,IACP,OAAKrD,EAASQ,OAGd4C,EAAM5C,MAAQR,EAASQ,MAAMkC,WAAWE,WAGjC5C,EAASQ,MACbkC,WACAI,WAAU,CAACQ,EAASC,IAAcH,EAAM5C,MAAQ+C,KARvB,MAQiD,CAI/E,IAAIC,EAAcH,IAQX,OAPPtC,EAAAC,MAAMhB,GAAU,KACA,MAAAwD,GAAAA,IACdA,EAAcH,GAAO,IAGPtC,EAAAkB,iBAAA,IAAqB,MAAfuB,OAAe,EAAAA,MAE9BJ,CACT"}
1
+ {"version":3,"file":"index.cjs","sources":["../../src/vue/context.ts","../../src/vue/composables/use-registry.ts","../../src/vue/composables/use-plugin.ts","../../src/vue/components/embed-pdf.vue","../../src/vue/composables/use-capability.ts","../../src/vue/composables/use-core-state.ts","../../src/vue/composables/use-store-state.ts"],"sourcesContent":["import { InjectionKey, Ref, ShallowRef } from 'vue';\nimport type { PluginRegistry } from '@embedpdf/core';\n\nexport interface PDFContextState {\n registry: ShallowRef<PluginRegistry | null>;\n isInitializing: Ref<boolean>;\n pluginsReady: Ref<boolean>;\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 { 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\">\nimport { ref, provide, onMounted, onBeforeUnmount, shallowRef } from 'vue';\nimport { PluginRegistry, PluginBatchRegistration } from '@embedpdf/core';\nimport { Logger, PdfEngine } from '@embedpdf/models';\nimport { pdfKey, PDFContextState } from '../context';\n\nconst props = defineProps<{\n engine: PdfEngine;\n logger?: Logger;\n plugins: PluginBatchRegistration<any, any>[];\n onInitialized?: (registry: PluginRegistry) => Promise<void>;\n}>();\n\n/* reactive state */\nconst registry = shallowRef<PluginRegistry | null>(null);\nconst isInit = ref(true);\nconst pluginsOk = ref(false);\n\n/* expose to children */\nprovide<PDFContextState>(pdfKey, { registry, isInitializing: isInit, pluginsReady: pluginsOk });\n\nonMounted(async () => {\n const reg = new PluginRegistry(props.engine, { logger: props.logger });\n reg.registerPluginBatch(props.plugins);\n await reg.initialize();\n await props.onInitialized?.(reg);\n\n registry.value = reg;\n isInit.value = false;\n\n reg.pluginsReady().then(() => (pluginsOk.value = true));\n});\n\nonBeforeUnmount(() => registry.value?.destroy());\n</script>\n\n<template>\n <!-- scoped slot keeps API parity with React version -->\n <slot :registry=\"registry\" :isInitializing=\"isInit\" :pluginsReady=\"pluginsOk\" />\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 { ref, onMounted, onBeforeUnmount } from 'vue';\nimport { arePropsEqual, type CoreState } from '@embedpdf/core';\nimport { useRegistry } from './use-registry';\n\nexport function useCoreState() {\n const { registry } = useRegistry();\n const core = ref<CoreState>();\n\n onMounted(() => {\n const store = registry.value!.getStore();\n core.value = store.getState().core;\n\n const unsub = store.subscribe((action, newSt, oldSt) => {\n if (store.isCoreAction(action) && !arePropsEqual(newSt.core, oldSt.core)) {\n core.value = newSt.core;\n }\n });\n onBeforeUnmount(unsub);\n });\n\n return core;\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","usePlugin","pluginId","registry","plugin","shallowRef","isLoading","ref","ready","Promise","load","value","p","getPlugin","_a","call","resolve","onMounted","vue","watch","props","__props","isInit","pluginsOk","provide","isInitializing","pluginsReady","async","reg","PluginRegistry","engine","logger","registerPluginBatch","plugins","initialize","onInitialized","then","onBeforeUnmount","destroy","_renderSlot","_ctx","$slots","provides","computed","core","store","getStore","core$1","getState","unsub","subscribe","action","newSt","oldSt","isCoreAction","arePropsEqual","state","attach","_action","newState","unsubscribe"],"mappings":"mIASaA,EAAwCC,OAAO,UCNrD,SAASC,IACR,MAAAC,EAAMC,SAAOJ,GACnB,IAAKG,EAAW,MAAA,IAAIE,MAAM,8CACnB,OAAAF,CACT,CCGO,SAASG,EAAgCC,GACxC,MAAAC,SAAEA,GAAaN,IAEfO,EAASC,aAAW,MAEpBC,EAAYC,OAAI,GAChBC,EAAQD,EAAAA,IAAmB,IAAIE,SAAQ,UAEvCC,EAAO,WACP,IAACP,EAASQ,MAAO,OAErB,MAAMC,EAAIT,EAASQ,MAAME,UAAaX,GACtC,IAAKU,EAAG,MAAM,IAAIZ,MAAM,UAAUE,eAElCE,EAAOO,MAAQC,EACfN,EAAUK,OAAQ,EAClBH,EAAMG,OAAQ,OAAAG,EAAAF,EAAEJ,YAAF,EAAAM,EAAAC,KAAAH,KAAeH,QAAQO,SAAQ,EAMxC,OAHPC,EAAAA,UAAUP,GACVQ,EAAAC,MAAMhB,EAAUO,GAET,CAAEN,SAAQE,YAAWE,QAC9B,6HC3BA,MAAMY,EAAQC,EAQRlB,EAAWE,aAAkC,MAC7CiB,EAASf,OAAI,GACbgB,EAAYhB,OAAI,UAGtBW,EAAAM,QAAyB7B,EAAQ,CAAEQ,WAAUsB,eAAgBH,EAAQI,aAAcH,IAEnFN,EAAAA,WAAUU,gBACF,MAAAC,EAAM,IAAIC,EAAAA,eAAeT,EAAMU,OAAQ,CAAEC,OAAQX,EAAMW,SACzDH,EAAAI,oBAAoBZ,EAAMa,eACxBL,EAAIM,m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IC,EAAcH,IAQX,OAPPvC,EAAAC,MAAMhB,GAAU,KACA,MAAAyD,GAAAA,IACdA,EAAcH,GAAO,IAGPvC,EAAAmB,iBAAA,IAAqB,MAAfuB,OAAe,EAAAA,MAE9BJ,CACT"}
package/dist/vue/index.js CHANGED
@@ -72,6 +72,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
72
72
  __name: "embed-pdf",
73
73
  props: {
74
74
  engine: {},
75
+ logger: {},
75
76
  plugins: {},
76
77
  onInitialized: { type: Function }
77
78
  },
@@ -83,7 +84,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
83
84
  provide(pdfKey, { registry, isInitializing: isInit, pluginsReady: pluginsOk });
84
85
  onMounted(async () => {
85
86
  var _a;
86
- const reg = new PluginRegistry(props.engine);
87
+ const reg = new PluginRegistry(props.engine, { logger: props.logger });
87
88
  reg.registerPluginBatch(props.plugins);
88
89
  await reg.initialize();
89
90
  await ((_a = props.onInitialized) == null ? void 0 : _a.call(props, reg));
@@ -1 +1 @@
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-plugin.ts","../../src/vue/composables/use-capability.ts","../../src/vue/composables/use-store-state.ts","../../src/vue/components/embed-pdf.vue"],"sourcesContent":["import { InjectionKey, Ref, ShallowRef } from 'vue';\nimport type { PluginRegistry } from '@embedpdf/core';\n\nexport interface PDFContextState {\n registry: ShallowRef<PluginRegistry | null>;\n isInitializing: Ref<boolean>;\n pluginsReady: Ref<boolean>;\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, onMounted, onBeforeUnmount } from 'vue';\nimport { arePropsEqual, type CoreState } from '@embedpdf/core';\nimport { useRegistry } from './use-registry';\n\nexport function useCoreState() {\n const { registry } = useRegistry();\n const core = ref<CoreState>();\n\n onMounted(() => {\n const store = registry.value!.getStore();\n core.value = store.getState().core;\n\n const unsub = store.subscribe((action, newSt, oldSt) => {\n if (store.isCoreAction(action) && !arePropsEqual(newSt.core, oldSt.core)) {\n core.value = newSt.core;\n }\n });\n onBeforeUnmount(unsub);\n });\n\n return core;\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\">\nimport { ref, provide, onMounted, onBeforeUnmount, shallowRef } from 'vue';\nimport { PluginRegistry, PluginBatchRegistration } from '@embedpdf/core';\nimport { PdfEngine } from '@embedpdf/models';\nimport { pdfKey, PDFContextState } from '../context';\n\nconst props = defineProps<{\n engine: PdfEngine;\n plugins: PluginBatchRegistration<any, any>[];\n onInitialized?: (registry: PluginRegistry) => Promise<void>;\n}>();\n\n/* reactive state */\nconst registry = shallowRef<PluginRegistry | null>(null);\nconst isInit = ref(true);\nconst pluginsOk = ref(false);\n\n/* expose to children */\nprovide<PDFContextState>(pdfKey, { registry, isInitializing: isInit, pluginsReady: pluginsOk });\n\nonMounted(async () => {\n const reg = new PluginRegistry(props.engine);\n reg.registerPluginBatch(props.plugins);\n await reg.initialize();\n await props.onInitialized?.(reg);\n\n registry.value = reg;\n isInit.value = false;\n\n reg.pluginsReady().then(() => (pluginsOk.value = true));\n});\n\nonBeforeUnmount(() => registry.value?.destroy());\n</script>\n\n<template>\n <!-- scoped slot keeps API parity with React version -->\n <slot :registry=\"registry\"\n :isInitializing=\"isInit\"\n :pluginsReady=\"pluginsOk\" />\n</template>"],"names":["_renderSlot"],"mappings":";;AASa,MAAA,SAAwC,OAAO,QAAQ;ACN7D,SAAS,cAAc;AACtB,QAAA,MAAM,OAAO,MAAM;AACzB,MAAI,CAAC,IAAW,OAAA,IAAI,MAAM,4CAA4C;AAC/D,SAAA;AACT;ACHO,SAAS,eAAe;AACvB,QAAA,EAAE,SAAS,IAAI,YAAY;AACjC,QAAM,OAAO,IAAe;AAE5B,YAAU,MAAM;AACR,UAAA,QAAQ,SAAS,MAAO,SAAS;AAClC,SAAA,QAAQ,MAAM,SAAW,EAAA;AAE9B,UAAM,QAAQ,MAAM,UAAU,CAAC,QAAQ,OAAO,UAAU;AAClD,UAAA,MAAM,aAAa,MAAM,KAAK,CAAC,cAAc,MAAM,MAAM,MAAM,IAAI,GAAG;AACxE,aAAK,QAAQ,MAAM;AAAA,MAAA;AAAA,IACrB,CACD;AACD,oBAAgB,KAAK;AAAA,EAAA,CACtB;AAEM,SAAA;AACT;ACXO,SAAS,UAAgC,UAAmC;AAC3E,QAAA,EAAE,SAAS,IAAI,YAAY;AAE3B,QAAA,SAAS,WAAW,IAAI;AAExB,QAAA,YAAY,IAAI,IAAI;AAC1B,QAAM,QAAQ,IAAmB,IAAI,QAAQ,MAAM;AAAA,EAAA,CAAE,CAAC;AAEtD,QAAM,OAAO,MAAM;;AACb,QAAA,CAAC,SAAS,MAAO;AAErB,UAAM,IAAI,SAAS,MAAM,UAAa,QAAQ;AAC9C,QAAI,CAAC,EAAG,OAAM,IAAI,MAAM,UAAU,QAAQ,YAAY;AAEtD,WAAO,QAAQ;AACf,cAAU,QAAQ;AAClB,UAAM,UAAQ,OAAE,UAAF,+BAAe,QAAQ,QAAQ;AAAA,EAC/C;AAEA,YAAU,IAAI;AACd,QAAM,UAAU,IAAI;AAEb,SAA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IAAA,CACvD;AAED,oBAAgB,MAAM;;AAAA,4BAAS,UAAT,mBAAgB;AAAA,KAAS;;AAK7C,aAAAA,WAEkC,KAAA,QAAA,WAAA;AAAA,QAF3B,UAAU,SAAQ;AAAA,QAClB,gBAAgB,OAAM;AAAA,QACtB,cAAc,UAAS;AAAA,MAAA;;;;"}
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-plugin.ts","../../src/vue/composables/use-capability.ts","../../src/vue/composables/use-store-state.ts","../../src/vue/components/embed-pdf.vue"],"sourcesContent":["import { InjectionKey, Ref, ShallowRef } from 'vue';\nimport type { PluginRegistry } from '@embedpdf/core';\n\nexport interface PDFContextState {\n registry: ShallowRef<PluginRegistry | null>;\n isInitializing: Ref<boolean>;\n pluginsReady: Ref<boolean>;\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, onMounted, onBeforeUnmount } from 'vue';\nimport { arePropsEqual, type CoreState } from '@embedpdf/core';\nimport { useRegistry } from './use-registry';\n\nexport function useCoreState() {\n const { registry } = useRegistry();\n const core = ref<CoreState>();\n\n onMounted(() => {\n const store = registry.value!.getStore();\n core.value = store.getState().core;\n\n const unsub = store.subscribe((action, newSt, oldSt) => {\n if (store.isCoreAction(action) && !arePropsEqual(newSt.core, oldSt.core)) {\n core.value = newSt.core;\n }\n });\n onBeforeUnmount(unsub);\n });\n\n return core;\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\">\nimport { ref, provide, onMounted, onBeforeUnmount, shallowRef } from 'vue';\nimport { PluginRegistry, PluginBatchRegistration } from '@embedpdf/core';\nimport { Logger, PdfEngine } from '@embedpdf/models';\nimport { pdfKey, PDFContextState } from '../context';\n\nconst props = defineProps<{\n engine: PdfEngine;\n logger?: Logger;\n plugins: PluginBatchRegistration<any, any>[];\n onInitialized?: (registry: PluginRegistry) => Promise<void>;\n}>();\n\n/* reactive state */\nconst registry = shallowRef<PluginRegistry | null>(null);\nconst isInit = ref(true);\nconst pluginsOk = ref(false);\n\n/* expose to children */\nprovide<PDFContextState>(pdfKey, { registry, isInitializing: isInit, pluginsReady: pluginsOk });\n\nonMounted(async () => {\n const reg = new PluginRegistry(props.engine, { logger: props.logger });\n reg.registerPluginBatch(props.plugins);\n await reg.initialize();\n await props.onInitialized?.(reg);\n\n registry.value = reg;\n isInit.value = false;\n\n reg.pluginsReady().then(() => (pluginsOk.value = true));\n});\n\nonBeforeUnmount(() => registry.value?.destroy());\n</script>\n\n<template>\n <!-- scoped slot keeps API parity with React version -->\n <slot :registry=\"registry\" :isInitializing=\"isInit\" :pluginsReady=\"pluginsOk\" />\n</template>\n"],"names":["_renderSlot"],"mappings":";;AASa,MAAA,SAAwC,OAAO,QAAQ;ACN7D,SAAS,cAAc;AACtB,QAAA,MAAM,OAAO,MAAM;AACzB,MAAI,CAAC,IAAW,OAAA,IAAI,MAAM,4CAA4C;AAC/D,SAAA;AACT;ACHO,SAAS,eAAe;AACvB,QAAA,EAAE,SAAS,IAAI,YAAY;AACjC,QAAM,OAAO,IAAe;AAE5B,YAAU,M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@ -33,8 +33,8 @@
33
33
  "@embedpdf/build": "1.0.0"
34
34
  },
35
35
  "dependencies": {
36
- "@embedpdf/engines": "1.0.18",
37
- "@embedpdf/models": "1.0.18"
36
+ "@embedpdf/engines": "1.0.20",
37
+ "@embedpdf/models": "1.0.20"
38
38
  },
39
39
  "peerDependencies": {
40
40
  "preact": "^10.26.4",