@embedpdf/core 1.0.16 → 1.0.18

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,4 +1,4 @@
1
- import { createContext } from "preact";
1
+ import { createContext, Fragment } from "preact";
2
2
  import { useState, useRef, useEffect, useContext } from "preact/hooks";
3
3
  import { jsx } from "preact/jsx-runtime";
4
4
  import { PluginRegistry, arePropsEqual } from "@embedpdf/core";
@@ -46,6 +46,63 @@ function EmbedPDF({ engine, onInitialized, plugins, children }) {
46
46
  }, [engine, plugins]);
47
47
  return /* @__PURE__ */ jsx(PDFContext.Provider, { value: { registry, isInitializing, pluginsReady }, children: typeof children === "function" ? children({ registry, isInitializing, pluginsReady }) : children });
48
48
  }
49
+ function getCounterRotation(rect, rotation) {
50
+ const { width: w, height: h } = rect.size;
51
+ switch (rotation % 4) {
52
+ case 1:
53
+ return {
54
+ matrix: `matrix(0, -1, 1, 0, 0, ${h})`,
55
+ width: h,
56
+ height: w
57
+ };
58
+ case 2:
59
+ return {
60
+ matrix: `matrix(-1, 0, 0, -1, ${w}, ${h})`,
61
+ width: w,
62
+ height: h
63
+ };
64
+ case 3:
65
+ return {
66
+ matrix: `matrix(0, 1, -1, 0, ${w}, 0)`,
67
+ width: h,
68
+ height: w
69
+ };
70
+ default:
71
+ return {
72
+ matrix: `matrix(1, 0, 0, 1, 0, 0)`,
73
+ width: w,
74
+ height: h
75
+ };
76
+ }
77
+ }
78
+ function CounterRotate({ children, ...props }) {
79
+ const { rect, rotation } = props;
80
+ const { matrix, width, height } = getCounterRotation(rect, rotation);
81
+ const menuWrapperStyle = {
82
+ position: "absolute",
83
+ left: rect.origin.x,
84
+ top: rect.origin.y,
85
+ transform: matrix,
86
+ transformOrigin: "0 0",
87
+ width,
88
+ height,
89
+ pointerEvents: "none",
90
+ zIndex: 3
91
+ };
92
+ const menuWrapperProps = {
93
+ style: menuWrapperStyle,
94
+ onPointerDown: (e) => e.stopPropagation(),
95
+ onTouchStart: (e) => e.stopPropagation()
96
+ };
97
+ return /* @__PURE__ */ jsx(Fragment, { children: children({
98
+ menuWrapperProps,
99
+ matrix,
100
+ rect: {
101
+ origin: { x: rect.origin.x, y: rect.origin.y },
102
+ size: { width, height }
103
+ }
104
+ }) });
105
+ }
49
106
  function useRegistry() {
50
107
  const contextValue = useContext(PDFContext);
51
108
  if (contextValue === void 0) {
@@ -128,8 +185,10 @@ function useCoreState() {
128
185
  return coreState;
129
186
  }
130
187
  export {
188
+ CounterRotate,
131
189
  EmbedPDF,
132
190
  PDFContext,
191
+ getCounterRotation,
133
192
  useCapability,
134
193
  useCoreState,
135
194
  usePlugin,
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/shared/context.ts","../../src/shared/components/embed-pdf.tsx","../../src/shared/hooks/use-registry.ts","../../src/shared/hooks/use-plugin.ts","../../src/shared/hooks/use-capability.ts","../../src/shared/hooks/use-store-state.ts","../../src/shared/hooks/use-core-state.ts"],"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 { 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,eAAe;AAC3B;AAAA,MA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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,eAAe;AAC3B;AAAA,MAAA;AAGQ,gBAAA,eAAe,KAAK,MAAM;AAC9B,YAAA,CAAC,UAAU,eAAe;AAC5B,0BAAgB,IAAI;AAAA,QAAA;AAAA,MACtB,CACD;AAGD,kBAAY,SAAS;AACrB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,WAAA;AAAA,MACL,UAAU;AAAA,MACV;AAAA,MACA;AAAA,IACF;AAAA,EAAA;AAGE,MAAA,CAAC,OAAO,UAAU;AACpB,UAAM,IAAI,MAAM,UAAU,QAAQ,gCAAgC;AAAA,EAAA;AAG7D,SAAA;AAAA,IACL,UAAU,OAAO,SAAS;AAAA,IAC1B;AAAA,IACA;AAAA,EACF;AACF;AC7BO,SAAS,gBAAqD;AAC7D,QAAA,EAAE,SAAS,IAAI,YAAY;AACjC,QAAM,CAAC,OAAO,QAAQ,IAAI,SAA+B,IAAI;AAE7D,YAAU,MAAM;AACd,QAAI,CAAC,SAAU;AAGf,aAAS,SAAS,SAAW,EAAA,SAAA,CAA2B;AAGxD,UAAM,cAAc,SAAS,SAAA,EAAW,UAAU,CAAC,SAAS,aAAa;AACvE,eAAS,QAAyB;AAAA,IAAA,CACnC;AAED,WAAO,MAAM,YAAY;AAAA,EAAA,GACxB,CAAC,QAAQ,CAAC;AAEN,SAAA;AACT;ACnBO,SAAS,eAAiC;AACzC,QAAA,EAAE,SAAS,IAAI,YAAY;AACjC,QAAM,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,2 +1,2 @@
1
1
  export { Fragment, useEffect, useRef, useState, useCallback, useMemo, JSX, createContext, useContext, } from 'react';
2
- export type { ReactNode, HTMLAttributes, CSSProperties, MouseEvent, PointerEvent } from 'react';
2
+ export type { ReactNode, HTMLAttributes, CSSProperties, MouseEvent, PointerEvent, TouchEvent, } from 'react';
@@ -1,2 +1,2 @@
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(){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}=n();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.EmbedPDF=function({engine:n,onInitialized:s,plugins:o,children:u}){const[a,l]=e.useState(null),[c,g]=e.useState(!0),[d,y]=e.useState(!1),f=e.useRef(s);return e.useEffect((()=>{f.current=s}),[s]),e.useEffect((()=>{const e=new r.PluginRegistry(n);e.registerPluginBatch(o);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()||y(!0)})),l(e),g(!1)))})().catch(console.error),()=>{e.destroy(),l(null),g(!0),y(!1)}}),[n,o]),t.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.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}=n(),[i,s]=e.useState(null);return e.useEffect((()=>{if(!t)return;const e=t.getStore();s(e.getState().core);const i=e.subscribe(((t,i,n)=>{e.isCoreAction(t)&&!r.arePropsEqual(i.core,n.core)&&s(i.core)}));return()=>i()}),[t]),i},exports.usePlugin=s,exports.useRegistry=n,exports.useStoreState=function(){const{registry:t}=n(),[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};
1
+ "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};
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../../src/shared/context.ts","../../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 { 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","useRegistry","contextValue","useContext","Error","usePlugin","pluginId","plugin","isLoading","ready","Promise","getPlugin","engine","onInitialized","plugins","children","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,ICLT,SAASC,IACR,MAAAC,EAAeC,aAAWP,GAGhC,QAAqB,IAAjBM,EACI,MAAA,IAAIE,MAAM,2DAGZ,MAAAN,SAAEA,EAAUC,eAAAA,GAAmBG,EAGrC,GAAIH,EACK,OAAAG,EAIT,GAAiB,OAAbJ,EACI,MAAA,IAAIM,MAAM,8CAGX,OAAAF,CACT,CCXO,SAASG,EAAgCC,GACxC,MAAAR,SAAEA,GAAaG,IAErB,GAAiB,OAAbH,EACK,MAAA,CACLS,OAAQ,KACRC,WAAW,EACXC,MAAO,IAAIC,SAAQ,UAIjB,MAAAH,EAAST,EAASa,UAAaL,GAErC,IAAKC,EACH,MAAM,IAAIH,MAAM,UAAUE,eAGrB,MAAA,CACLC,SACAC,WAAW,EACXC,MAAOF,EAAOE,QAElB,kBCzBO,UAAkBG,OAAEA,EAAAC,cAAQA,EAAeC,QAAAA,EAAAC,SAASA,IACzD,MAAOjB,EAAUkB,GAAeC,EAAAA,SAAgC,OACzDlB,EAAgBmB,GAAqBD,EAAAA,UAAkB,IACvDjB,EAAcmB,GAAmBF,EAAAA,UAAkB,GACpDG,EAAUC,SAAuCR,GA+CrDS,OA7CFC,EAAAA,WAAU,KACRH,EAAQI,QAAUX,CAAA,GACjB,CAACA,IAEJU,EAAAA,WAAU,KACF,MAAAE,EAAY,IAAIC,EAAAA,eAAed,GACrCa,EAAUE,oBAAoBb,GA8B9B,MA5BmBc,uBACXH,EAAUI,aAEZJ,EAAUK,sBAKR,OAAAC,EAAAX,EAAQI,cAAU,EAAAO,EAAAC,KAAAZ,EAAAK,IAGpBA,EAAUK,gBAIJL,EAAAzB,eAAeiC,M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ACjD,IAEGwD,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 { 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,EAAW,GACjB,KAAK,EACI,MAAA,CACLM,OAAQ,0BAA0BF,KAClCH,MAAOG,EACPD,OAAQD,GAGZ,KAAK,EACI,MAAA,CACLI,OAAQ,wBAAwBJ,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AAU,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,4 +1,4 @@
1
- import { createContext, useState, useRef, useEffect, useContext } from "react";
1
+ import { createContext, useState, useRef, useEffect, Fragment, useContext } from "react";
2
2
  import { jsx } from "react/jsx-runtime";
3
3
  import { PluginRegistry, arePropsEqual } from "@embedpdf/core";
4
4
  const PDFContext = createContext({
@@ -45,6 +45,63 @@ function EmbedPDF({ engine, onInitialized, plugins, children }) {
45
45
  }, [engine, plugins]);
46
46
  return /* @__PURE__ */ jsx(PDFContext.Provider, { value: { registry, isInitializing, pluginsReady }, children: typeof children === "function" ? children({ registry, isInitializing, pluginsReady }) : children });
47
47
  }
48
+ function getCounterRotation(rect, rotation) {
49
+ const { width: w, height: h } = rect.size;
50
+ switch (rotation % 4) {
51
+ case 1:
52
+ return {
53
+ matrix: `matrix(0, -1, 1, 0, 0, ${h})`,
54
+ width: h,
55
+ height: w
56
+ };
57
+ case 2:
58
+ return {
59
+ matrix: `matrix(-1, 0, 0, -1, ${w}, ${h})`,
60
+ width: w,
61
+ height: h
62
+ };
63
+ case 3:
64
+ return {
65
+ matrix: `matrix(0, 1, -1, 0, ${w}, 0)`,
66
+ width: h,
67
+ height: w
68
+ };
69
+ default:
70
+ return {
71
+ matrix: `matrix(1, 0, 0, 1, 0, 0)`,
72
+ width: w,
73
+ height: h
74
+ };
75
+ }
76
+ }
77
+ function CounterRotate({ children, ...props }) {
78
+ const { rect, rotation } = props;
79
+ const { matrix, width, height } = getCounterRotation(rect, rotation);
80
+ const menuWrapperStyle = {
81
+ position: "absolute",
82
+ left: rect.origin.x,
83
+ top: rect.origin.y,
84
+ transform: matrix,
85
+ transformOrigin: "0 0",
86
+ width,
87
+ height,
88
+ pointerEvents: "none",
89
+ zIndex: 3
90
+ };
91
+ const menuWrapperProps = {
92
+ style: menuWrapperStyle,
93
+ onPointerDown: (e) => e.stopPropagation(),
94
+ onTouchStart: (e) => e.stopPropagation()
95
+ };
96
+ return /* @__PURE__ */ jsx(Fragment, { children: children({
97
+ menuWrapperProps,
98
+ matrix,
99
+ rect: {
100
+ origin: { x: rect.origin.x, y: rect.origin.y },
101
+ size: { width, height }
102
+ }
103
+ }) });
104
+ }
48
105
  function useRegistry() {
49
106
  const contextValue = useContext(PDFContext);
50
107
  if (contextValue === void 0) {
@@ -127,8 +184,10 @@ function useCoreState() {
127
184
  return coreState;
128
185
  }
129
186
  export {
187
+ CounterRotate,
130
188
  EmbedPDF,
131
189
  PDFContext,
190
+ getCounterRotation,
132
191
  useCapability,
133
192
  useCoreState,
134
193
  usePlugin,
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/shared/context.ts","../../src/shared/components/embed-pdf.tsx","../../src/shared/hooks/use-registry.ts","../../src/shared/hooks/use-plugin.ts","../../src/shared/hooks/use-capability.ts","../../src/shared/hooks/use-store-state.ts","../../src/shared/hooks/use-core-state.ts"],"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 { 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,QAA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,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 { 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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;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;"}
@@ -0,0 +1,33 @@
1
+ import { Rect, Rotation } from '@embedpdf/models';
2
+ import { ReactNode, CSSProperties, PointerEvent, TouchEvent } from '../../preact/adapter.ts';
3
+ interface CounterRotateProps {
4
+ rect: Rect;
5
+ rotation: Rotation;
6
+ }
7
+ interface CounterTransformResult {
8
+ matrix: string;
9
+ width: number;
10
+ height: number;
11
+ }
12
+ /**
13
+ * Given an already-placed rect (left/top/width/height in px) and the page rotation,
14
+ * return the counter-rotation matrix + adjusted width/height.
15
+ *
16
+ * transform-origin is expected to be "0 0".
17
+ * left/top DO NOT change, apply them as-is.
18
+ */
19
+ export declare function getCounterRotation(rect: Rect, rotation: Rotation): CounterTransformResult;
20
+ export interface MenuWrapperProps {
21
+ style: CSSProperties;
22
+ onPointerDown: (e: PointerEvent<HTMLDivElement>) => void;
23
+ onTouchStart: (e: TouchEvent<HTMLDivElement>) => void;
24
+ }
25
+ interface CounterRotateComponentProps extends CounterRotateProps {
26
+ children: (props: {
27
+ matrix: string;
28
+ rect: Rect;
29
+ menuWrapperProps: MenuWrapperProps;
30
+ }) => ReactNode;
31
+ }
32
+ export declare function CounterRotate({ children, ...props }: CounterRotateComponentProps): import("preact").JSX.Element;
33
+ export {};
@@ -1 +1,2 @@
1
1
  export * from './embed-pdf';
2
+ export * from './counter-rotate-container';
@@ -0,0 +1,33 @@
1
+ import { Rect, Rotation } from '@embedpdf/models';
2
+ import { ReactNode, CSSProperties, PointerEvent, TouchEvent } from '../../react/adapter.ts';
3
+ interface CounterRotateProps {
4
+ rect: Rect;
5
+ rotation: Rotation;
6
+ }
7
+ interface CounterTransformResult {
8
+ matrix: string;
9
+ width: number;
10
+ height: number;
11
+ }
12
+ /**
13
+ * Given an already-placed rect (left/top/width/height in px) and the page rotation,
14
+ * return the counter-rotation matrix + adjusted width/height.
15
+ *
16
+ * transform-origin is expected to be "0 0".
17
+ * left/top DO NOT change, apply them as-is.
18
+ */
19
+ export declare function getCounterRotation(rect: Rect, rotation: Rotation): CounterTransformResult;
20
+ export interface MenuWrapperProps {
21
+ style: CSSProperties;
22
+ onPointerDown: (e: PointerEvent<HTMLDivElement>) => void;
23
+ onTouchStart: (e: TouchEvent<HTMLDivElement>) => void;
24
+ }
25
+ interface CounterRotateComponentProps extends CounterRotateProps {
26
+ children: (props: {
27
+ matrix: string;
28
+ rect: Rect;
29
+ menuWrapperProps: MenuWrapperProps;
30
+ }) => ReactNode;
31
+ }
32
+ export declare function CounterRotate({ children, ...props }: CounterRotateComponentProps): import("react/jsx-runtime").JSX.Element;
33
+ export {};
@@ -1 +1,2 @@
1
1
  export * from './embed-pdf';
2
+ export * from './counter-rotate-container';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@embedpdf/core",
3
- "version": "1.0.16",
3
+ "version": "1.0.18",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
@@ -33,8 +33,8 @@
33
33
  "@embedpdf/build": "1.0.0"
34
34
  },
35
35
  "dependencies": {
36
- "@embedpdf/engines": "1.0.16",
37
- "@embedpdf/models": "1.0.16"
36
+ "@embedpdf/engines": "1.0.18",
37
+ "@embedpdf/models": "1.0.18"
38
38
  },
39
39
  "peerDependencies": {
40
40
  "preact": "^10.26.4",