@embedpdf/plugin-interaction-manager 1.5.0 → 2.0.0-next.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/dist/index.cjs +1 -1
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.js +456 -185
  4. package/dist/index.js.map +1 -1
  5. package/dist/lib/actions.d.ts +61 -36
  6. package/dist/lib/interaction-manager-plugin.d.ts +19 -14
  7. package/dist/lib/reducer.d.ts +2 -1
  8. package/dist/lib/types.d.ts +58 -50
  9. package/dist/preact/index.cjs +1 -1
  10. package/dist/preact/index.cjs.map +1 -1
  11. package/dist/preact/index.js +61 -40
  12. package/dist/preact/index.js.map +1 -1
  13. package/dist/react/index.cjs +1 -1
  14. package/dist/react/index.cjs.map +1 -1
  15. package/dist/react/index.js +61 -40
  16. package/dist/react/index.js.map +1 -1
  17. package/dist/shared/components/global-pointer-provider.d.ts +2 -1
  18. package/dist/shared/components/page-pointer-provider.d.ts +4 -5
  19. package/dist/shared/hooks/use-interaction-manager.d.ts +9 -7
  20. package/dist/shared-preact/components/global-pointer-provider.d.ts +2 -1
  21. package/dist/shared-preact/components/page-pointer-provider.d.ts +4 -5
  22. package/dist/shared-preact/hooks/use-interaction-manager.d.ts +9 -7
  23. package/dist/shared-react/components/global-pointer-provider.d.ts +2 -1
  24. package/dist/shared-react/components/page-pointer-provider.d.ts +4 -5
  25. package/dist/shared-react/hooks/use-interaction-manager.d.ts +9 -7
  26. package/dist/svelte/components/GlobalPointerProvider.svelte.d.ts +1 -0
  27. package/dist/svelte/components/PagePointerProvider.svelte.d.ts +4 -5
  28. package/dist/svelte/hooks/use-interaction-manager.svelte.d.ts +10 -8
  29. package/dist/svelte/index.cjs +1 -1
  30. package/dist/svelte/index.cjs.map +1 -1
  31. package/dist/svelte/index.js +128 -56
  32. package/dist/svelte/index.js.map +1 -1
  33. package/dist/vue/components/global-pointer-provider.vue.d.ts +6 -2
  34. package/dist/vue/components/page-pointer-provider.vue.d.ts +7 -7
  35. package/dist/vue/hooks/use-interaction-manager.d.ts +19 -26
  36. package/dist/vue/index.cjs +1 -1
  37. package/dist/vue/index.cjs.map +1 -1
  38. package/dist/vue/index.js +131 -63
  39. package/dist/vue/index.js.map +1 -1
  40. package/package.json +4 -4
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../../src/shared/hooks/use-interaction-manager.ts","../../src/shared/utils.ts","../../src/shared/components/global-pointer-provider.tsx","../../src/shared/components/page-pointer-provider.tsx"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/@framework';\nimport {\n initialState,\n InteractionManagerPlugin,\n InteractionManagerState,\n PointerEventHandlersWithLifecycle,\n} from '@embedpdf/plugin-interaction-manager';\nimport { useState, useEffect } from '@framework';\n\nexport const useInteractionManagerPlugin = () =>\n usePlugin<InteractionManagerPlugin>(InteractionManagerPlugin.id);\nexport const useInteractionManagerCapability = () =>\n useCapability<InteractionManagerPlugin>(InteractionManagerPlugin.id);\n\nexport function useInteractionManager() {\n const { provides } = useInteractionManagerCapability();\n const [state, setState] = useState<InteractionManagerState>(initialState);\n\n useEffect(() => {\n if (!provides) return;\n return provides.onStateChange((state) => {\n setState(state);\n });\n }, [provides]);\n\n return {\n provides,\n state,\n };\n}\n\nexport function useCursor() {\n const { provides } = useInteractionManagerCapability();\n return {\n setCursor: (token: string, cursor: string, prio = 0) => {\n provides?.setCursor(token, cursor, prio);\n },\n removeCursor: (token: string) => {\n provides?.removeCursor(token);\n },\n };\n}\n\ninterface UsePointerHandlersOptions {\n modeId?: string | string[];\n pageIndex?: number;\n}\n\nexport function usePointerHandlers({ modeId, pageIndex }: UsePointerHandlersOptions) {\n const { provides } = useInteractionManagerCapability();\n return {\n register: (\n handlers: PointerEventHandlersWithLifecycle,\n options?: { modeId?: string | string[]; pageIndex?: number },\n ) => {\n // Use provided options or fall back to hook-level options\n const finalModeId = options?.modeId ?? modeId;\n const finalPageIndex = options?.pageIndex ?? pageIndex;\n\n return finalModeId\n ? provides?.registerHandlers({\n modeId: finalModeId,\n handlers,\n pageIndex: finalPageIndex,\n })\n : provides?.registerAlways({\n scope:\n finalPageIndex !== undefined\n ? { type: 'page', pageIndex: finalPageIndex }\n : { type: 'global' },\n handlers,\n });\n },\n };\n}\n\nexport function useIsPageExclusive() {\n const { provides: cap } = useInteractionManagerCapability();\n\n const [isPageExclusive, setIsPageExclusive] = useState<boolean>(() => {\n const m = cap?.getActiveInteractionMode();\n return m?.scope === 'page' && !!m.exclusive;\n });\n\n useEffect(() => {\n if (!cap) return;\n\n return cap.onModeChange(() => {\n const mode = cap.getActiveInteractionMode();\n setIsPageExclusive(mode?.scope === 'page' && !!mode?.exclusive);\n });\n }, [cap]);\n\n return isPageExclusive;\n}\n","import { Position } from '@embedpdf/models';\nimport type {\n InteractionManagerCapability,\n InteractionScope,\n PointerEventHandlers,\n EmbedPdfPointerEvent,\n InteractionExclusionRules,\n} from '@embedpdf/plugin-interaction-manager';\n\n/* -------------------------------------------------- */\n/* event → handler key lookup */\n/* -------------------------------------------------- */\ntype K = keyof PointerEventHandlers;\nconst domEventMap: Record<string, K> = {\n pointerdown: 'onPointerDown',\n pointerup: 'onPointerUp',\n pointermove: 'onPointerMove',\n pointerenter: 'onPointerEnter',\n pointerleave: 'onPointerLeave',\n pointercancel: 'onPointerCancel',\n\n mousedown: 'onMouseDown',\n mouseup: 'onMouseUp',\n mousemove: 'onMouseMove',\n mouseenter: 'onMouseEnter',\n mouseleave: 'onMouseLeave',\n mousecancel: 'onMouseCancel',\n\n click: 'onClick',\n dblclick: 'onDoubleClick',\n\n /* touch → pointer fallback for very old browsers */\n touchstart: 'onPointerDown',\n touchend: 'onPointerUp',\n touchmove: 'onPointerMove',\n touchcancel: 'onPointerCancel',\n};\n\nconst pointerEventTypes = [\n 'pointerdown',\n 'pointerup',\n 'pointermove',\n 'pointerenter',\n 'pointerleave',\n 'pointercancel',\n 'mousedown',\n 'mouseup',\n 'mousemove',\n 'mouseenter',\n 'mouseleave',\n 'mousecancel',\n 'click',\n 'dblclick',\n];\n\nconst touchEventTypes = ['touchstart', 'touchend', 'touchmove', 'touchcancel'];\nconst HAS_POINTER = typeof PointerEvent !== 'undefined';\n// If the browser supports Pointer Events, don't attach legacy touch events to avoid double-dispatch.\nconst allEventTypes = HAS_POINTER ? pointerEventTypes : [...pointerEventTypes, ...touchEventTypes];\n\n/* -------------------------------------------------- */\n/* helper: decide listener options per event type */\n/* -------------------------------------------------- */\nfunction listenerOpts(eventType: string, wantsRawTouch: boolean): AddEventListenerOptions {\n // Only touch events are toggled; pointer/mouse stay non-passive\n return eventType.startsWith('touch') ? { passive: !wantsRawTouch } : { passive: false };\n}\n\nfunction isTouchEvent(evt: Event): evt is TouchEvent {\n return typeof TouchEvent !== 'undefined' && evt instanceof TouchEvent;\n}\n\n/**\n * Check if an element should be excluded based on rules\n * This is in the framework layer, not the plugin\n */\nfunction shouldExcludeElement(element: Element | null, rules: InteractionExclusionRules): boolean {\n if (!element) return false;\n\n let current: Element | null = element;\n\n while (current) {\n // Check classes\n if (rules.classes?.length) {\n for (const className of rules.classes) {\n if (current.classList?.contains(className)) {\n return true;\n }\n }\n }\n\n // Check data attributes\n if (rules.dataAttributes?.length) {\n for (const attr of rules.dataAttributes) {\n if (current.hasAttribute(attr)) {\n return true;\n }\n }\n }\n\n // Move up the DOM tree\n current = current.parentElement;\n }\n\n return false;\n}\n\n/* -------------------------------------------------- */\n/* createPointerProvider */\n/* -------------------------------------------------- */\nexport function createPointerProvider(\n cap: InteractionManagerCapability,\n scope: InteractionScope,\n element: HTMLElement,\n convertEventToPoint?: (evt: PointerEvent, host: HTMLElement) => Position,\n) {\n /* ---------- live handler set --------------------------------------------------- */\n let active: PointerEventHandlers | null = cap.getHandlersForScope(scope);\n\n /* ---------- helper to compute current wantsRawTouch (defaults to true) --------- */\n const wantsRawTouchNow = () => cap.getActiveInteractionMode()?.wantsRawTouch !== false; // default → true\n\n /* ---------- dynamic listener (re)attachment ------------------------------------ */\n const listeners: Record<string, (evt: Event) => void> = {};\n let attachedWithRawTouch = wantsRawTouchNow(); // remember current mode’s wish\n\n const addListeners = (raw: boolean) => {\n allEventTypes.forEach((type) => {\n const fn = (listeners[type] ??= handleEvent);\n element.addEventListener(type, fn, listenerOpts(type, raw));\n });\n };\n const removeListeners = () => {\n allEventTypes.forEach((type) => {\n const fn = listeners[type];\n if (fn) element.removeEventListener(type, fn);\n });\n };\n\n /* attach for the first time */\n addListeners(attachedWithRawTouch);\n element.style.touchAction = attachedWithRawTouch ? 'none' : '';\n\n /* ---------- mode & handler change hooks --------------------------------------- */\n const stopMode = cap.onModeChange(() => {\n /* cursor baseline update for global wrapper */\n if (scope.type === 'global') {\n const mode = cap.getActiveInteractionMode();\n element.style.cursor = mode?.scope === 'global' ? (mode.cursor ?? 'auto') : 'auto';\n }\n\n active = cap.getHandlersForScope(scope);\n\n /* re-attach listeners if wantsRawTouch toggled */\n const raw = wantsRawTouchNow();\n if (raw !== attachedWithRawTouch) {\n removeListeners();\n addListeners(raw);\n attachedWithRawTouch = raw;\n element.style.touchAction = attachedWithRawTouch ? 'none' : '';\n }\n });\n\n const stopHandler = cap.onHandlerChange(() => {\n active = cap.getHandlersForScope(scope);\n });\n\n /* ---------- cursor sync -------------------------------------------------------- */\n const initialMode = cap.getActiveInteractionMode();\n const initialCursor = cap.getCurrentCursor();\n element.style.cursor =\n scope.type === 'global' && initialMode?.scope !== 'global' ? 'auto' : initialCursor;\n\n const stopCursor = cap.onCursorChange((c) => {\n if (scope.type === 'global' && cap.getActiveInteractionMode()?.scope !== 'global') return;\n element.style.cursor = c;\n });\n\n /* ---------- point conversion --------------------------------------------------- */\n const toPos = (e: { clientX: number; clientY: number }, host: HTMLElement): Position => {\n if (convertEventToPoint) return convertEventToPoint(e as PointerEvent, host);\n const r = host.getBoundingClientRect();\n return { x: e.clientX - r.left, y: e.clientY - r.top };\n };\n\n /* ---------- central event handler --------------------------------------------- */\n function handleEvent(evt: Event) {\n if (cap.isPaused()) return;\n\n // Get exclusion rules from capability and check in framework layer\n const exclusionRules = cap.getExclusionRules();\n if (evt.target && shouldExcludeElement(evt.target as Element, exclusionRules)) {\n return; // Skip processing this event\n }\n\n const handlerKey = domEventMap[evt.type];\n if (!handlerKey || !active?.[handlerKey]) return;\n\n /* preventDefault only when mode really wants raw touch */\n if (\n isTouchEvent(evt) &&\n attachedWithRawTouch &&\n (evt.type === 'touchmove' || evt.type === 'touchcancel')\n ) {\n evt.preventDefault();\n }\n\n // ----- normalise ----------------------------------------------------------------\n let pos!: Position;\n let normEvt!: EmbedPdfPointerEvent & {\n target: EventTarget | null;\n currentTarget: EventTarget | null;\n };\n\n if (isTouchEvent(evt)) {\n const tp =\n evt.type === 'touchend' || evt.type === 'touchcancel'\n ? evt.changedTouches[0]\n : evt.touches[0];\n if (!tp) return;\n\n pos = toPos(tp, element);\n normEvt = {\n clientX: tp.clientX,\n clientY: tp.clientY,\n ctrlKey: evt.ctrlKey,\n shiftKey: evt.shiftKey,\n altKey: evt.altKey,\n metaKey: evt.metaKey,\n target: evt.target,\n currentTarget: evt.currentTarget,\n setPointerCapture: () => {},\n releasePointerCapture: () => {},\n };\n } else {\n const pe = evt as PointerEvent;\n pos = toPos(pe, element);\n normEvt = {\n clientX: pe.clientX,\n clientY: pe.clientY,\n ctrlKey: pe.ctrlKey,\n shiftKey: pe.shiftKey,\n altKey: pe.altKey,\n metaKey: pe.metaKey,\n target: pe.target,\n currentTarget: pe.currentTarget,\n setPointerCapture: () => {\n (pe.target as HTMLElement)?.setPointerCapture?.(pe.pointerId);\n },\n releasePointerCapture: () => {\n (pe.target as HTMLElement)?.releasePointerCapture?.(pe.pointerId);\n },\n };\n }\n\n active[handlerKey]?.(pos, normEvt, cap.getActiveMode());\n }\n\n /* ---------- teardown ----------------------------------------------------------- */\n return () => {\n removeListeners();\n stopMode();\n stopCursor();\n stopHandler();\n };\n}\n","import { ReactNode, useEffect, useRef, HTMLAttributes, CSSProperties } from '@framework';\nimport { createPointerProvider } from '../utils';\n\nimport { useInteractionManagerCapability } from '../hooks';\n\ninterface GlobalPointerProviderProps extends HTMLAttributes<HTMLDivElement> {\n children: ReactNode;\n style?: CSSProperties;\n}\n\nexport const GlobalPointerProvider = ({\n children,\n style,\n ...props\n}: GlobalPointerProviderProps) => {\n const ref = useRef<HTMLDivElement>(null);\n const { provides: cap } = useInteractionManagerCapability();\n\n useEffect(() => {\n if (!cap || !ref.current) return;\n\n return createPointerProvider(cap, { type: 'global' }, ref.current);\n }, [cap]);\n\n return (\n <div\n ref={ref}\n style={{\n width: '100%',\n height: '100%',\n ...style,\n }}\n {...props}\n >\n {children}\n </div>\n );\n};\n","import {\n ReactNode,\n useEffect,\n useRef,\n useCallback,\n HTMLAttributes,\n CSSProperties,\n} from '@framework';\nimport { Position, restorePosition, Size, transformSize } from '@embedpdf/models';\nimport { createPointerProvider } from '../utils';\n\nimport { useInteractionManagerCapability, useIsPageExclusive } from '../hooks';\n\ninterface PagePointerProviderProps extends HTMLAttributes<HTMLDivElement> {\n children: ReactNode;\n pageIndex: number;\n pageWidth: number;\n pageHeight: number;\n rotation: number;\n scale: number;\n style?: CSSProperties;\n convertEventToPoint?: (event: PointerEvent, element: HTMLElement) => Position;\n}\n\nexport const PagePointerProvider = ({\n pageIndex,\n children,\n pageWidth,\n pageHeight,\n rotation,\n scale,\n convertEventToPoint,\n style,\n ...props\n}: PagePointerProviderProps) => {\n const ref = useRef<HTMLDivElement>(null);\n const { provides: cap } = useInteractionManagerCapability();\n const isPageExclusive = useIsPageExclusive();\n\n // Memoize the default conversion function\n const defaultConvertEventToPoint = useCallback(\n (event: PointerEvent, element: HTMLElement): Position => {\n const rect = element.getBoundingClientRect();\n const displayPoint = {\n x: event.clientX - rect.left,\n y: event.clientY - rect.top,\n };\n\n const displaySize: Size = transformSize(\n { width: pageWidth, height: pageHeight },\n rotation,\n 1,\n );\n\n return restorePosition(displaySize, displayPoint, rotation, scale);\n },\n [pageWidth, pageHeight, rotation, scale],\n );\n\n useEffect(() => {\n if (!cap || !ref.current) return;\n\n return createPointerProvider(\n cap,\n { type: 'page', pageIndex },\n ref.current,\n convertEventToPoint || defaultConvertEventToPoint,\n );\n }, [cap, pageIndex, convertEventToPoint, defaultConvertEventToPoint]);\n\n return (\n <div\n ref={ref}\n style={{\n position: 'relative',\n width: pageWidth,\n height: pageHeight,\n ...style,\n }}\n {...props}\n >\n {children}\n {isPageExclusive && (\n <div style={{ position: 'absolute', top: 0, left: 0, right: 0, bottom: 0, zIndex: 10 }} />\n )}\n </div>\n );\n};\n"],"names":["useInteractionManagerCapability","useCapability","InteractionManagerPlugin","id","useIsPageExclusive","provides","cap","isPageExclusive","setIsPageExclusive","useState","m","getActiveInteractionMode","scope","exclusive","useEffect","onModeChange","mode","domEventMap","pointerdown","pointerup","pointermove","pointerenter","pointerleave","pointercancel","mousedown","mouseup","mousemove","mouseenter","mouseleave","mousecancel","click","dblclick","touchstart","touchend","touchmove","touchcancel","pointerEventTypes","allEventTypes","PointerEvent","isTouchEvent","evt","TouchEvent","createPointerProvider","element","convertEventToPoint","active","getHandlersForScope","wantsRawTouchNow","_a","wantsRawTouch","listeners","attachedWithRawTouch","addListeners","raw","forEach","type","fn","handleEvent","addEventListener","startsWith","passive","removeListeners","removeEventListener","style","touchAction","stopMode","cursor","stopHandler","onHandlerChange","initialMode","initialCursor","getCurrentCursor","stopCursor","onCursorChange","c","toPos","e","host","r","getBoundingClientRect","x","clientX","left","y","clientY","top","isPaused","exclusionRules","getExclusionRules","target","rules","current","classes","length","className","_b","classList","contains","_c","dataAttributes","attr","hasAttribute","parentElement","shouldExcludeElement","handlerKey","pos","normEvt","preventDefault","tp","changedTouches","touches","ctrlKey","shiftKey","altKey","metaKey","currentTarget","setPointerCapture","releasePointerCapture","pe","call","pointerId","getActiveMode","children","props","ref","useRef","jsxRuntime","jsx","width","height","pageIndex","pageWidth","pageHeight","rotation","scale","defaultConvertEventToPoint","useCallback","event","rect","displayPoint","displaySize","transformSize","restorePosition","jsxs","position","right","bottom","zIndex","setCursor","token","prio","removeCursor","state","setState","initialState","onStateChange","usePlugin","modeId","register","handlers","options","finalModeId","finalPageIndex","registerHandlers","registerAlways"],"mappings":"mQAWaA,EAAkC,IAC7CC,gBAAwCC,EAAAA,yBAAyBC,IAgE5D,SAASC,IACd,MAAQC,SAAUC,GAAQN,KAEnBO,EAAiBC,GAAsBC,YAAkB,KACxD,MAAAC,EAAS,MAALJ,OAAK,EAAAA,EAAAK,2BACf,MAAoB,UAAV,MAAHD,OAAG,EAAAA,EAAAE,UAAsBF,EAAEG,SAAA,IAY7B,OATPC,EAAAA,WAAU,KACR,GAAKR,EAEE,OAAAA,EAAIS,cAAa,KAChB,MAAAC,EAAOV,EAAIK,2BACjBH,EAAmC,gBAAhBQ,WAAMJ,iBAAsBI,WAAMH,WAAS,GAC/D,GACA,CAACP,IAEGC,CACT,CCjFA,MAAMU,EAAiC,CACrCC,YAAa,gBACbC,UAAW,cACXC,YAAa,gBACbC,aAAc,iBACdC,aAAc,iBACdC,cAAe,kBAEfC,UAAW,cACXC,QAAS,YACTC,UAAW,cACXC,WAAY,eACZC,WAAY,eACZC,YAAa,gBAEbC,MAAO,UACPC,SAAU,gBAGVC,WAAY,gBACZC,SAAU,cACVC,UAAW,gBACXC,YAAa,mBAGTC,EAAoB,CACxB,cACA,YACA,cACA,eACA,eACA,gBACA,YACA,UACA,YACA,aACA,aACA,cACA,QACA,YAMIC,EAFsC,oBAAjBC,aAESF,EAAoB,IAAIA,EAHnC,aAAc,WAAY,YAAa,eAahE,SAASG,EAAaC,GACb,MAAsB,oBAAfC,YAA8BD,aAAeC,UAC7D,CAwCO,SAASC,EACdpC,EACAM,EACA+B,EACAC,GAGI,IAAAC,EAAsCvC,EAAIwC,oBAAoBlC,GAGlE,MAAMmC,EAAmB,WAAU,OAA8C,KAAlD,OAAIC,EAAA1C,EAAAK,iCAAJ,EAAAqC,EAAgCC,cAAkB,EAG3EC,EAAkD,CAAC,EAC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mJ,QAEJ,gFApB2C,IACzCI,YAAoC1J,EAAAA,yBAAyBC,4DAsCxD,UAA4B0J,OAAEA,EAAQ3B,UAAAA,IACrC,MAAA7H,SAAEA,GAAaL,IACd,MAAA,CACL8J,SAAU,CACRC,EACAC,KAGM,MAAAC,SAAcD,WAASH,SAAUA,EACjCK,SAAiBF,WAAS9B,YAAaA,EAEtC,OAAA+B,QACH5J,WAAU8J,iBAAiB,CACzBN,OAAQI,EACRF,WACA7B,UAAWgC,UAEb7J,WAAU+J,eAAe,CACvBxJ,WACqB,IAAnBsJ,EACI,CAAE3G,KAAM,OAAQ2E,UAAWgC,GAC3B,CAAE3G,KAAM,UACdwG,YAAA,EAIZ"}
1
+ {"version":3,"file":"index.cjs","sources":["../../src/shared/hooks/use-interaction-manager.ts","../../src/shared/utils.ts","../../src/shared/components/global-pointer-provider.tsx","../../src/shared/components/page-pointer-provider.tsx"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/@framework';\nimport {\n initialDocumentState,\n InteractionDocumentState,\n InteractionManagerPlugin,\n PointerEventHandlersWithLifecycle,\n} from '@embedpdf/plugin-interaction-manager';\nimport { useState, useEffect } from '@framework';\n\nexport const useInteractionManagerPlugin = () =>\n usePlugin<InteractionManagerPlugin>(InteractionManagerPlugin.id);\nexport const useInteractionManagerCapability = () =>\n useCapability<InteractionManagerPlugin>(InteractionManagerPlugin.id);\n\nexport function useInteractionManager(documentId: string) {\n const { provides } = useInteractionManagerCapability();\n const [state, setState] = useState<InteractionDocumentState>(initialDocumentState);\n\n useEffect(() => {\n if (!provides) return;\n const scope = provides.forDocument(documentId);\n return scope.onStateChange((state) => {\n setState(state);\n });\n }, [provides]);\n\n return {\n provides: provides?.forDocument(documentId) ?? null,\n state,\n };\n}\n\nexport function useCursor(documentId: string) {\n const { provides } = useInteractionManagerCapability();\n return {\n setCursor: (token: string, cursor: string, prio = 0) => {\n if (!provides) return;\n const scope = provides.forDocument(documentId);\n scope.setCursor(token, cursor, prio);\n },\n removeCursor: (token: string) => {\n if (!provides) return;\n const scope = provides.forDocument(documentId);\n scope.removeCursor(token);\n },\n };\n}\n\ninterface UsePointerHandlersOptions {\n modeId?: string | string[];\n pageIndex?: number;\n documentId: string;\n}\n\nexport function usePointerHandlers({ modeId, pageIndex, documentId }: UsePointerHandlersOptions) {\n const { provides } = useInteractionManagerCapability();\n return {\n register: (\n handlers: PointerEventHandlersWithLifecycle,\n options?: { modeId?: string | string[]; pageIndex?: number; documentId?: string },\n ) => {\n // Use provided options or fall back to hook-level options\n const finalModeId = options?.modeId ?? modeId;\n const finalPageIndex = options?.pageIndex ?? pageIndex;\n const finalDocumentId = options?.documentId ?? documentId;\n\n return finalModeId\n ? provides?.registerHandlers({\n modeId: finalModeId,\n handlers,\n pageIndex: finalPageIndex,\n documentId: finalDocumentId,\n })\n : provides?.registerAlways({\n scope:\n finalPageIndex !== undefined\n ? { type: 'page', documentId: finalDocumentId, pageIndex: finalPageIndex }\n : { type: 'global', documentId: finalDocumentId },\n handlers,\n });\n },\n };\n}\n\nexport function useIsPageExclusive(documentId: string) {\n const { provides: cap } = useInteractionManagerCapability();\n\n const [isPageExclusive, setIsPageExclusive] = useState<boolean>(() => {\n if (!cap) return false;\n const scope = cap.forDocument(documentId);\n const m = scope.getActiveInteractionMode();\n return m?.scope === 'page' && !!m.exclusive;\n });\n\n useEffect(() => {\n if (!cap) return;\n\n const scope = cap.forDocument(documentId);\n\n return scope.onModeChange(() => {\n const mode = scope.getActiveInteractionMode();\n setIsPageExclusive(mode?.scope === 'page' && !!mode?.exclusive);\n });\n }, [cap, documentId]);\n\n return isPageExclusive;\n}\n","import { Position } from '@embedpdf/models';\nimport type {\n InteractionManagerCapability,\n InteractionScope,\n PointerEventHandlers,\n EmbedPdfPointerEvent,\n InteractionExclusionRules,\n} from '@embedpdf/plugin-interaction-manager';\n\n/* -------------------------------------------------- */\n/* event → handler key lookup */\n/* -------------------------------------------------- */\ntype K = keyof PointerEventHandlers;\nconst domEventMap: Record<string, K> = {\n pointerdown: 'onPointerDown',\n pointerup: 'onPointerUp',\n pointermove: 'onPointerMove',\n pointerenter: 'onPointerEnter',\n pointerleave: 'onPointerLeave',\n pointercancel: 'onPointerCancel',\n\n mousedown: 'onMouseDown',\n mouseup: 'onMouseUp',\n mousemove: 'onMouseMove',\n mouseenter: 'onMouseEnter',\n mouseleave: 'onMouseLeave',\n mousecancel: 'onMouseCancel',\n\n click: 'onClick',\n dblclick: 'onDoubleClick',\n\n /* touch → pointer fallback for very old browsers */\n touchstart: 'onPointerDown',\n touchend: 'onPointerUp',\n touchmove: 'onPointerMove',\n touchcancel: 'onPointerCancel',\n};\n\nconst pointerEventTypes = [\n 'pointerdown',\n 'pointerup',\n 'pointermove',\n 'pointerenter',\n 'pointerleave',\n 'pointercancel',\n 'mousedown',\n 'mouseup',\n 'mousemove',\n 'mouseenter',\n 'mouseleave',\n 'mousecancel',\n 'click',\n 'dblclick',\n];\n\nconst touchEventTypes = ['touchstart', 'touchend', 'touchmove', 'touchcancel'];\nconst HAS_POINTER = typeof PointerEvent !== 'undefined';\n// If the browser supports Pointer Events, don't attach legacy touch events to avoid double-dispatch.\nconst allEventTypes = HAS_POINTER ? pointerEventTypes : [...pointerEventTypes, ...touchEventTypes];\n\n/* -------------------------------------------------- */\n/* helper: decide listener options per event type */\n/* -------------------------------------------------- */\nfunction listenerOpts(eventType: string, wantsRawTouch: boolean): AddEventListenerOptions {\n // Only touch events are toggled; pointer/mouse stay non-passive\n return eventType.startsWith('touch') ? { passive: !wantsRawTouch } : { passive: false };\n}\n\nfunction isTouchEvent(evt: Event): evt is TouchEvent {\n return typeof TouchEvent !== 'undefined' && evt instanceof TouchEvent;\n}\n\n/**\n * Check if an element should be excluded based on rules\n * This is in the framework layer, not the plugin\n */\nfunction shouldExcludeElement(element: Element | null, rules: InteractionExclusionRules): boolean {\n if (!element) return false;\n\n let current: Element | null = element;\n\n while (current) {\n // Check classes\n if (rules.classes?.length) {\n for (const className of rules.classes) {\n if (current.classList?.contains(className)) {\n return true;\n }\n }\n }\n\n // Check data attributes\n if (rules.dataAttributes?.length) {\n for (const attr of rules.dataAttributes) {\n if (current.hasAttribute(attr)) {\n return true;\n }\n }\n }\n\n // Move up the DOM tree\n current = current.parentElement;\n }\n\n return false;\n}\n\n/* -------------------------------------------------- */\n/* createPointerProvider */\n/* -------------------------------------------------- */\nexport function createPointerProvider(\n cap: InteractionManagerCapability,\n scope: InteractionScope,\n element: HTMLElement,\n convertEventToPoint?: (evt: PointerEvent, host: HTMLElement) => Position,\n) {\n const capScope = cap.forDocument(scope.documentId);\n /* ---------- live handler set --------------------------------------------------- */\n let active: PointerEventHandlers | null = cap.getHandlersForScope(scope);\n\n /* ---------- helper to compute current wantsRawTouch (defaults to true) --------- */\n const wantsRawTouchNow = () => capScope.getActiveInteractionMode()?.wantsRawTouch !== false; // default → true\n\n /* ---------- dynamic listener (re)attachment ------------------------------------ */\n const listeners: Record<string, (evt: Event) => void> = {};\n let attachedWithRawTouch = wantsRawTouchNow(); // remember current mode’s wish\n\n const addListeners = (raw: boolean) => {\n allEventTypes.forEach((type) => {\n const fn = (listeners[type] ??= handleEvent);\n element.addEventListener(type, fn, listenerOpts(type, raw));\n });\n };\n const removeListeners = () => {\n allEventTypes.forEach((type) => {\n const fn = listeners[type];\n if (fn) element.removeEventListener(type, fn);\n });\n };\n\n /* attach for the first time */\n addListeners(attachedWithRawTouch);\n element.style.touchAction = attachedWithRawTouch ? 'none' : '';\n\n /* ---------- mode & handler change hooks --------------------------------------- */\n const stopMode = capScope.onModeChange(() => {\n /* cursor baseline update for global wrapper */\n if (scope.type === 'global') {\n const mode = capScope.getActiveInteractionMode();\n element.style.cursor = mode?.scope === 'global' ? (mode.cursor ?? 'auto') : 'auto';\n }\n\n active = cap.getHandlersForScope(scope);\n\n /* re-attach listeners if wantsRawTouch toggled */\n const raw = wantsRawTouchNow();\n if (raw !== attachedWithRawTouch) {\n removeListeners();\n addListeners(raw);\n attachedWithRawTouch = raw;\n element.style.touchAction = attachedWithRawTouch ? 'none' : '';\n }\n });\n\n const stopHandler = cap.onHandlerChange(() => {\n active = cap.getHandlersForScope(scope);\n });\n\n /* ---------- cursor sync -------------------------------------------------------- */\n const initialMode = capScope.getActiveInteractionMode();\n const initialCursor = capScope.getCurrentCursor();\n element.style.cursor =\n scope.type === 'global' && initialMode?.scope !== 'global' ? 'auto' : initialCursor;\n\n const stopCursor = capScope.onCursorChange((c) => {\n if (scope.type === 'global' && capScope.getActiveInteractionMode()?.scope !== 'global') return;\n element.style.cursor = c;\n });\n\n /* ---------- point conversion --------------------------------------------------- */\n const toPos = (e: { clientX: number; clientY: number }, host: HTMLElement): Position => {\n if (convertEventToPoint) return convertEventToPoint(e as PointerEvent, host);\n const r = host.getBoundingClientRect();\n return { x: e.clientX - r.left, y: e.clientY - r.top };\n };\n\n /* ---------- central event handler --------------------------------------------- */\n function handleEvent(evt: Event) {\n if (cap.isPaused()) return;\n\n // Get exclusion rules from capability and check in framework layer\n const exclusionRules = cap.getExclusionRules();\n if (evt.target && shouldExcludeElement(evt.target as Element, exclusionRules)) {\n return; // Skip processing this event\n }\n\n const handlerKey = domEventMap[evt.type];\n if (!handlerKey || !active?.[handlerKey]) return;\n\n /* preventDefault only when mode really wants raw touch */\n if (\n isTouchEvent(evt) &&\n attachedWithRawTouch &&\n (evt.type === 'touchmove' || evt.type === 'touchcancel')\n ) {\n evt.preventDefault();\n }\n\n // ----- normalise ----------------------------------------------------------------\n let pos!: Position;\n let normEvt!: EmbedPdfPointerEvent & {\n target: EventTarget | null;\n currentTarget: EventTarget | null;\n };\n\n if (isTouchEvent(evt)) {\n const tp =\n evt.type === 'touchend' || evt.type === 'touchcancel'\n ? evt.changedTouches[0]\n : evt.touches[0];\n if (!tp) return;\n\n pos = toPos(tp, element);\n normEvt = {\n clientX: tp.clientX,\n clientY: tp.clientY,\n ctrlKey: evt.ctrlKey,\n shiftKey: evt.shiftKey,\n altKey: evt.altKey,\n metaKey: evt.metaKey,\n target: evt.target,\n currentTarget: evt.currentTarget,\n setPointerCapture: () => {},\n releasePointerCapture: () => {},\n };\n } else {\n const pe = evt as PointerEvent;\n pos = toPos(pe, element);\n normEvt = {\n clientX: pe.clientX,\n clientY: pe.clientY,\n ctrlKey: pe.ctrlKey,\n shiftKey: pe.shiftKey,\n altKey: pe.altKey,\n metaKey: pe.metaKey,\n target: pe.target,\n currentTarget: pe.currentTarget,\n setPointerCapture: () => {\n (pe.target as HTMLElement)?.setPointerCapture?.(pe.pointerId);\n },\n releasePointerCapture: () => {\n (pe.target as HTMLElement)?.releasePointerCapture?.(pe.pointerId);\n },\n };\n }\n\n active[handlerKey]?.(pos, normEvt, capScope.getActiveMode());\n }\n\n /* ---------- teardown ----------------------------------------------------------- */\n return () => {\n removeListeners();\n stopMode();\n stopCursor();\n stopHandler();\n };\n}\n","import { ReactNode, useEffect, useRef, HTMLAttributes, CSSProperties } from '@framework';\nimport { createPointerProvider } from '../utils';\nimport { useInteractionManagerCapability } from '../hooks';\n\ninterface GlobalPointerProviderProps extends HTMLAttributes<HTMLDivElement> {\n children: ReactNode;\n documentId: string;\n style?: CSSProperties;\n}\n\nexport const GlobalPointerProvider = ({\n children,\n documentId,\n style,\n ...props\n}: GlobalPointerProviderProps) => {\n const ref = useRef<HTMLDivElement>(null);\n const { provides: cap } = useInteractionManagerCapability();\n\n useEffect(() => {\n if (!cap || !ref.current) return;\n\n return createPointerProvider(cap, { type: 'global', documentId }, ref.current);\n }, [cap, documentId]);\n\n return (\n <div\n ref={ref}\n style={{\n width: '100%',\n height: '100%',\n ...style,\n }}\n {...props}\n >\n {children}\n </div>\n );\n};\n","import {\n ReactNode,\n useEffect,\n useRef,\n useCallback,\n HTMLAttributes,\n CSSProperties,\n} from '@framework';\nimport { useDocumentState } from '@embedpdf/core/@framework';\nimport { Position, restorePosition, Size, transformSize } from '@embedpdf/models';\nimport { createPointerProvider } from '../utils';\n\nimport { useInteractionManagerCapability, useIsPageExclusive } from '../hooks';\n\ninterface PagePointerProviderProps extends HTMLAttributes<HTMLDivElement> {\n children: ReactNode;\n documentId: string;\n pageIndex: number;\n rotation?: number;\n scale?: number;\n style?: CSSProperties;\n convertEventToPoint?: (event: PointerEvent, element: HTMLElement) => Position;\n}\n\nexport const PagePointerProvider = ({\n documentId,\n pageIndex,\n children,\n rotation: rotationOverride,\n scale: scaleOverride,\n convertEventToPoint,\n style,\n ...props\n}: PagePointerProviderProps) => {\n const ref = useRef<HTMLDivElement>(null);\n const { provides: cap } = useInteractionManagerCapability();\n const isPageExclusive = useIsPageExclusive(documentId);\n const documentState = useDocumentState(documentId);\n\n // Get page dimensions and transformations from document state\n // Calculate inline - this is cheap and memoization isn't necessary\n const page = documentState?.document?.pages?.[pageIndex];\n const naturalPageSize = page?.size ?? { width: 0, height: 0 };\n const rotation = rotationOverride ?? documentState?.rotation ?? 0;\n const scale = scaleOverride ?? documentState?.scale ?? 1;\n const displaySize = transformSize(naturalPageSize, 0, scale);\n\n // Simplified conversion function\n const defaultConvertEventToPoint = useCallback(\n (event: PointerEvent, element: HTMLElement): Position => {\n const rect = element.getBoundingClientRect();\n const displayPoint = {\n x: event.clientX - rect.left,\n y: event.clientY - rect.top,\n };\n\n // Get the rotated natural size (width/height may be swapped, but not scaled)\n const rotatedNaturalSize = transformSize(\n {\n width: displaySize.width,\n height: displaySize.height,\n },\n rotation,\n 1,\n );\n\n return restorePosition(rotatedNaturalSize, displayPoint, rotation, scale);\n },\n [naturalPageSize, rotation, scale],\n );\n\n useEffect(() => {\n if (!cap || !ref.current) return;\n\n return createPointerProvider(\n cap,\n { type: 'page', documentId, pageIndex },\n ref.current,\n convertEventToPoint || defaultConvertEventToPoint,\n );\n }, [cap, documentId, pageIndex, convertEventToPoint, defaultConvertEventToPoint]);\n\n return (\n <div\n ref={ref}\n style={{\n position: 'relative',\n width: displaySize.width,\n height: displaySize.height,\n ...style,\n }}\n {...props}\n >\n {children}\n {isPageExclusive && (\n <div style={{ position: 'absolute', top: 0, left: 0, right: 0, bottom: 0, zIndex: 10 }} />\n )}\n </div>\n );\n};\n"],"names":["useInteractionManagerCapability","useCapability","InteractionManagerPlugin","id","useIsPageExclusive","documentId","provides","cap","isPageExclusive","setIsPageExclusive","useState","m","forDocument","getActiveInteractionMode","scope","exclusive","useEffect","onModeChange","mode","domEventMap","pointerdown","pointerup","pointermove","pointerenter","pointerleave","pointercancel","mousedown","mouseup","mousemove","mouseenter","mouseleave","mousecancel","click","dblclick","touchstart","touchend","touchmove","touchcancel","pointerEventTypes","allEventTypes","PointerEvent","isTouchEvent","evt","TouchEvent","createPointerProvider","element","convertEventToPoint","capScope","active","getHandlersForScope","wantsRawTouchNow","_a","wantsRawTouch","listeners","attachedWithRawTouch","addListeners","raw","forEach","type","fn","handleEvent","addEventListener","startsWith","passive","removeListeners","removeEventListener","style","touchAction","stopMode","cursor","stopHandler","onHandlerChange","initialMode","initialCursor","getCurrentCursor","stopCursor","onCursorChange","c","toPos","e","host","r","getBoundingClientRect","x","clientX","left","y","clientY","top","isPaused","exclusionRules","getExclusionRules","target","rules","current","classes","length","className","_b","classList","contains","_c","dataAttributes","attr","hasAttribute","parentElement","shouldExcludeElement","handlerKey","pos","normEvt","preventDefault","tp","changedTouches","touches","ctrlKey","shiftKey","altKey","metaKey","currentTarget","setPointerCapture","releasePointerCapture","pe","call","pointerId","getActiveMode","children","props","ref","useRef","jsx","width","height","pageIndex","rotation","rotationOverride","scale","scaleOverride","documentState","useDocumentState","page","document","pages","naturalPageSize","size","displaySize","transformSize","defaultConvertEventToPoint","useCallback","event","rect","displayPoint","rotatedNaturalSize","restorePosition","jsxs","position","right","bottom","zIndex","setCursor","token","prio","removeCursor","state","setState","initialDocumentState","onStateChange","usePlugin","modeId","register","handlers","options","finalModeId","finalPageIndex","finalDocumentId","registerHandlers","registerAlways"],"mappings":"mQAWaA,EAAkC,IAC7CC,gBAAwCC,EAAAA,yBAAyBC,IAwE5D,SAASC,EAAmBC,GACjC,MAAQC,SAAUC,GAAQP,KAEnBQ,EA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AASM,YAAYP,GAC7ByJ,UAAUC,EAAO1F,EAAQ2F,IAEjCC,aAAeF,IACb,IAAKzJ,EAAU,OACDA,EAASM,YAAYP,GAC7B4J,aAAaF,IAGzB,gCAhCO,SAA+B1J,GACpC,MAAMC,SAAEA,GAAaN,KACdkK,EAAOC,GAAYzJ,EAAAA,SAAmC0J,EAAAA,sBAU7D,OARApJ,EAAAA,UAAU,KACR,IAAKV,EAAU,OAEf,OADcA,EAASM,YAAYP,GACtBgK,cAAeH,IAC1BC,EAASD,MAEV,CAAC5J,IAEG,CACLA,UAAU,MAAAA,OAAA,EAAAA,EAAUM,YAAYP,KAAe,KAC/C6J,QAEJ,gFArB2C,IACzCI,YAAoCpK,EAAAA,yBAAyBC,4DA4CxD,UAA4BoK,OAAEA,EAAAnC,UAAQA,EAAA/H,WAAWA,IACtD,MAAMC,SAAEA,GAAaN,IACrB,MAAO,CACLwK,SAAU,CACRC,EACAC,KAGA,MAAMC,SAAcD,WAASH,SAAUA,EACjCK,SAAiBF,WAAStC,YAAaA,EACvCyC,SAAkBH,WAASrK,aAAcA,EAE/C,OAAOsK,QACHrK,WAAUwK,iBAAiB,CACzBP,OAAQI,EACRF,WACArC,UAAWwC,EACXvK,WAAYwK,UAEdvK,WAAUyK,eAAe,CACvBjK,WACqB,IAAnB8J,EACI,CAAElH,KAAM,OAAQrD,WAAYwK,EAAiBzC,UAAWwC,GACxD,CAAElH,KAAM,SAAUrD,WAAYwK,GACpCJ,cAIZ"}
@@ -1,66 +1,76 @@
1
- import { usePlugin, useCapability } from "@embedpdf/core/preact";
2
- import { InteractionManagerPlugin, initialState } from "@embedpdf/plugin-interaction-manager";
1
+ import { usePlugin, useCapability, useDocumentState } from "@embedpdf/core/preact";
2
+ import { InteractionManagerPlugin, initialDocumentState } from "@embedpdf/plugin-interaction-manager";
3
3
  export * from "@embedpdf/plugin-interaction-manager";
4
4
  import { useState, useEffect, useRef, useCallback } from "preact/hooks";
5
5
  import { jsx, jsxs } from "preact/jsx-runtime";
6
6
  import { transformSize, restorePosition } from "@embedpdf/models";
7
7
  const useInteractionManagerPlugin = () => usePlugin(InteractionManagerPlugin.id);
8
8
  const useInteractionManagerCapability = () => useCapability(InteractionManagerPlugin.id);
9
- function useInteractionManager() {
9
+ function useInteractionManager(documentId) {
10
10
  const { provides } = useInteractionManagerCapability();
11
- const [state, setState] = useState(initialState);
11
+ const [state, setState] = useState(initialDocumentState);
12
12
  useEffect(() => {
13
13
  if (!provides) return;
14
- return provides.onStateChange((state2) => {
14
+ const scope = provides.forDocument(documentId);
15
+ return scope.onStateChange((state2) => {
15
16
  setState(state2);
16
17
  });
17
18
  }, [provides]);
18
19
  return {
19
- provides,
20
+ provides: (provides == null ? void 0 : provides.forDocument(documentId)) ?? null,
20
21
  state
21
22
  };
22
23
  }
23
- function useCursor() {
24
+ function useCursor(documentId) {
24
25
  const { provides } = useInteractionManagerCapability();
25
26
  return {
26
27
  setCursor: (token, cursor, prio = 0) => {
27
- provides == null ? void 0 : provides.setCursor(token, cursor, prio);
28
+ if (!provides) return;
29
+ const scope = provides.forDocument(documentId);
30
+ scope.setCursor(token, cursor, prio);
28
31
  },
29
32
  removeCursor: (token) => {
30
- provides == null ? void 0 : provides.removeCursor(token);
33
+ if (!provides) return;
34
+ const scope = provides.forDocument(documentId);
35
+ scope.removeCursor(token);
31
36
  }
32
37
  };
33
38
  }
34
- function usePointerHandlers({ modeId, pageIndex }) {
39
+ function usePointerHandlers({ modeId, pageIndex, documentId }) {
35
40
  const { provides } = useInteractionManagerCapability();
36
41
  return {
37
42
  register: (handlers, options) => {
38
43
  const finalModeId = (options == null ? void 0 : options.modeId) ?? modeId;
39
44
  const finalPageIndex = (options == null ? void 0 : options.pageIndex) ?? pageIndex;
45
+ const finalDocumentId = (options == null ? void 0 : options.documentId) ?? documentId;
40
46
  return finalModeId ? provides == null ? void 0 : provides.registerHandlers({
41
47
  modeId: finalModeId,
42
48
  handlers,
43
- pageIndex: finalPageIndex
49
+ pageIndex: finalPageIndex,
50
+ documentId: finalDocumentId
44
51
  }) : provides == null ? void 0 : provides.registerAlways({
45
- scope: finalPageIndex !== void 0 ? { type: "page", pageIndex: finalPageIndex } : { type: "global" },
52
+ scope: finalPageIndex !== void 0 ? { type: "page", documentId: finalDocumentId, pageIndex: finalPageIndex } : { type: "global", documentId: finalDocumentId },
46
53
  handlers
47
54
  });
48
55
  }
49
56
  };
50
57
  }
51
- function useIsPageExclusive() {
58
+ function useIsPageExclusive(documentId) {
52
59
  const { provides: cap } = useInteractionManagerCapability();
53
60
  const [isPageExclusive, setIsPageExclusive] = useState(() => {
54
- const m = cap == null ? void 0 : cap.getActiveInteractionMode();
61
+ if (!cap) return false;
62
+ const scope = cap.forDocument(documentId);
63
+ const m = scope.getActiveInteractionMode();
55
64
  return (m == null ? void 0 : m.scope) === "page" && !!m.exclusive;
56
65
  });
57
66
  useEffect(() => {
58
67
  if (!cap) return;
59
- return cap.onModeChange(() => {
60
- const mode = cap.getActiveInteractionMode();
68
+ const scope = cap.forDocument(documentId);
69
+ return scope.onModeChange(() => {
70
+ const mode = scope.getActiveInteractionMode();
61
71
  setIsPageExclusive((mode == null ? void 0 : mode.scope) === "page" && !!(mode == null ? void 0 : mode.exclusive));
62
72
  });
63
- }, [cap]);
73
+ }, [cap, documentId]);
64
74
  return isPageExclusive;
65
75
  }
66
76
  const domEventMap = {
@@ -133,10 +143,11 @@ function shouldExcludeElement(element, rules) {
133
143
  return false;
134
144
  }
135
145
  function createPointerProvider(cap, scope, element, convertEventToPoint) {
146
+ const capScope = cap.forDocument(scope.documentId);
136
147
  let active = cap.getHandlersForScope(scope);
137
148
  const wantsRawTouchNow = () => {
138
149
  var _a;
139
- return ((_a = cap.getActiveInteractionMode()) == null ? void 0 : _a.wantsRawTouch) !== false;
150
+ return ((_a = capScope.getActiveInteractionMode()) == null ? void 0 : _a.wantsRawTouch) !== false;
140
151
  };
141
152
  const listeners = {};
142
153
  let attachedWithRawTouch = wantsRawTouchNow();
@@ -154,9 +165,9 @@ function createPointerProvider(cap, scope, element, convertEventToPoint) {
154
165
  };
155
166
  addListeners(attachedWithRawTouch);
156
167
  element.style.touchAction = attachedWithRawTouch ? "none" : "";
157
- const stopMode = cap.onModeChange(() => {
168
+ const stopMode = capScope.onModeChange(() => {
158
169
  if (scope.type === "global") {
159
- const mode = cap.getActiveInteractionMode();
170
+ const mode = capScope.getActiveInteractionMode();
160
171
  element.style.cursor = (mode == null ? void 0 : mode.scope) === "global" ? mode.cursor ?? "auto" : "auto";
161
172
  }
162
173
  active = cap.getHandlersForScope(scope);
@@ -171,12 +182,12 @@ function createPointerProvider(cap, scope, element, convertEventToPoint) {
171
182
  const stopHandler = cap.onHandlerChange(() => {
172
183
  active = cap.getHandlersForScope(scope);
173
184
  });
174
- const initialMode = cap.getActiveInteractionMode();
175
- const initialCursor = cap.getCurrentCursor();
185
+ const initialMode = capScope.getActiveInteractionMode();
186
+ const initialCursor = capScope.getCurrentCursor();
176
187
  element.style.cursor = scope.type === "global" && (initialMode == null ? void 0 : initialMode.scope) !== "global" ? "auto" : initialCursor;
177
- const stopCursor = cap.onCursorChange((c) => {
188
+ const stopCursor = capScope.onCursorChange((c) => {
178
189
  var _a;
179
- if (scope.type === "global" && ((_a = cap.getActiveInteractionMode()) == null ? void 0 : _a.scope) !== "global") return;
190
+ if (scope.type === "global" && ((_a = capScope.getActiveInteractionMode()) == null ? void 0 : _a.scope) !== "global") return;
180
191
  element.style.cursor = c;
181
192
  });
182
193
  const toPos = (e, host) => {
@@ -238,7 +249,7 @@ function createPointerProvider(cap, scope, element, convertEventToPoint) {
238
249
  }
239
250
  };
240
251
  }
241
- (_a = active[handlerKey]) == null ? void 0 : _a.call(active, pos, normEvt, cap.getActiveMode());
252
+ (_a = active[handlerKey]) == null ? void 0 : _a.call(active, pos, normEvt, capScope.getActiveMode());
242
253
  }
243
254
  return () => {
244
255
  removeListeners();
@@ -249,6 +260,7 @@ function createPointerProvider(cap, scope, element, convertEventToPoint) {
249
260
  }
250
261
  const GlobalPointerProvider = ({
251
262
  children,
263
+ documentId,
252
264
  style,
253
265
  ...props
254
266
  }) => {
@@ -256,8 +268,8 @@ const GlobalPointerProvider = ({
256
268
  const { provides: cap } = useInteractionManagerCapability();
257
269
  useEffect(() => {
258
270
  if (!cap || !ref.current) return;
259
- return createPointerProvider(cap, { type: "global" }, ref.current);
260
- }, [cap]);
271
+ return createPointerProvider(cap, { type: "global", documentId }, ref.current);
272
+ }, [cap, documentId]);
261
273
  return /* @__PURE__ */ jsx(
262
274
  "div",
263
275
  {
@@ -273,19 +285,25 @@ const GlobalPointerProvider = ({
273
285
  );
274
286
  };
275
287
  const PagePointerProvider = ({
288
+ documentId,
276
289
  pageIndex,
277
290
  children,
278
- pageWidth,
279
- pageHeight,
280
- rotation,
281
- scale,
291
+ rotation: rotationOverride,
292
+ scale: scaleOverride,
282
293
  convertEventToPoint,
283
294
  style,
284
295
  ...props
285
296
  }) => {
297
+ var _a, _b;
286
298
  const ref = useRef(null);
287
299
  const { provides: cap } = useInteractionManagerCapability();
288
- const isPageExclusive = useIsPageExclusive();
300
+ const isPageExclusive = useIsPageExclusive(documentId);
301
+ const documentState = useDocumentState(documentId);
302
+ const page = (_b = (_a = documentState == null ? void 0 : documentState.document) == null ? void 0 : _a.pages) == null ? void 0 : _b[pageIndex];
303
+ const naturalPageSize = (page == null ? void 0 : page.size) ?? { width: 0, height: 0 };
304
+ const rotation = rotationOverride ?? (documentState == null ? void 0 : documentState.rotation) ?? 0;
305
+ const scale = scaleOverride ?? (documentState == null ? void 0 : documentState.scale) ?? 1;
306
+ const displaySize = transformSize(naturalPageSize, 0, scale);
289
307
  const defaultConvertEventToPoint = useCallback(
290
308
  (event, element) => {
291
309
  const rect = element.getBoundingClientRect();
@@ -293,32 +311,35 @@ const PagePointerProvider = ({
293
311
  x: event.clientX - rect.left,
294
312
  y: event.clientY - rect.top
295
313
  };
296
- const displaySize = transformSize(
297
- { width: pageWidth, height: pageHeight },
314
+ const rotatedNaturalSize = transformSize(
315
+ {
316
+ width: displaySize.width,
317
+ height: displaySize.height
318
+ },
298
319
  rotation,
299
320
  1
300
321
  );
301
- return restorePosition(displaySize, displayPoint, rotation, scale);
322
+ return restorePosition(rotatedNaturalSize, displayPoint, rotation, scale);
302
323
  },
303
- [pageWidth, pageHeight, rotation, scale]
324
+ [naturalPageSize, rotation, scale]
304
325
  );
305
326
  useEffect(() => {
306
327
  if (!cap || !ref.current) return;
307
328
  return createPointerProvider(
308
329
  cap,
309
- { type: "page", pageIndex },
330
+ { type: "page", documentId, pageIndex },
310
331
  ref.current,
311
332
  convertEventToPoint || defaultConvertEventToPoint
312
333
  );
313
- }, [cap, pageIndex, convertEventToPoint, defaultConvertEventToPoint]);
334
+ }, [cap, documentId, pageIndex, convertEventToPoint, defaultConvertEventToPoint]);
314
335
  return /* @__PURE__ */ jsxs(
315
336
  "div",
316
337
  {
317
338
  ref,
318
339
  style: {
319
340
  position: "relative",
320
- width: pageWidth,
321
- height: pageHeight,
341
+ width: displaySize.width,
342
+ height: displaySize.height,
322
343
  ...style
323
344
  },
324
345
  ...props,
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/shared/hooks/use-interaction-manager.ts","../../src/shared/utils.ts","../../src/shared/components/global-pointer-provider.tsx","../../src/shared/components/page-pointer-provider.tsx"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/@framework';\nimport {\n initialState,\n InteractionManagerPlugin,\n InteractionManagerState,\n PointerEventHandlersWithLifecycle,\n} from '@embedpdf/plugin-interaction-manager';\nimport { useState, useEffect } from '@framework';\n\nexport const useInteractionManagerPlugin = () =>\n usePlugin<InteractionManagerPlugin>(InteractionManagerPlugin.id);\nexport const useInteractionManagerCapability = () =>\n useCapability<InteractionManagerPlugin>(InteractionManagerPlugin.id);\n\nexport function useInteractionManager() {\n const { provides } = useInteractionManagerCapability();\n const [state, setState] = useState<InteractionManagerState>(initialState);\n\n useEffect(() => {\n if (!provides) return;\n return provides.onStateChange((state) => {\n setState(state);\n });\n }, [provides]);\n\n return {\n provides,\n state,\n };\n}\n\nexport function useCursor() {\n const { provides } = useInteractionManagerCapability();\n return {\n setCursor: (token: string, cursor: string, prio = 0) => {\n provides?.setCursor(token, cursor, prio);\n },\n removeCursor: (token: string) => {\n provides?.removeCursor(token);\n },\n };\n}\n\ninterface UsePointerHandlersOptions {\n modeId?: string | string[];\n pageIndex?: number;\n}\n\nexport function usePointerHandlers({ modeId, pageIndex }: UsePointerHandlersOptions) {\n const { provides } = useInteractionManagerCapability();\n return {\n register: (\n handlers: PointerEventHandlersWithLifecycle,\n options?: { modeId?: string | string[]; pageIndex?: number },\n ) => {\n // Use provided options or fall back to hook-level options\n const finalModeId = options?.modeId ?? modeId;\n const finalPageIndex = options?.pageIndex ?? pageIndex;\n\n return finalModeId\n ? provides?.registerHandlers({\n modeId: finalModeId,\n handlers,\n pageIndex: finalPageIndex,\n })\n : provides?.registerAlways({\n scope:\n finalPageIndex !== undefined\n ? { type: 'page', pageIndex: finalPageIndex }\n : { type: 'global' },\n handlers,\n });\n },\n };\n}\n\nexport function useIsPageExclusive() {\n const { provides: cap } = useInteractionManagerCapability();\n\n const [isPageExclusive, setIsPageExclusive] = useState<boolean>(() => {\n const m = cap?.getActiveInteractionMode();\n return m?.scope === 'page' && !!m.exclusive;\n });\n\n useEffect(() => {\n if (!cap) return;\n\n return cap.onModeChange(() => {\n const mode = cap.getActiveInteractionMode();\n setIsPageExclusive(mode?.scope === 'page' && !!mode?.exclusive);\n });\n }, [cap]);\n\n return isPageExclusive;\n}\n","import { Position } from '@embedpdf/models';\nimport type {\n InteractionManagerCapability,\n InteractionScope,\n PointerEventHandlers,\n EmbedPdfPointerEvent,\n InteractionExclusionRules,\n} from '@embedpdf/plugin-interaction-manager';\n\n/* -------------------------------------------------- */\n/* event → handler key lookup */\n/* -------------------------------------------------- */\ntype K = keyof PointerEventHandlers;\nconst domEventMap: Record<string, K> = {\n pointerdown: 'onPointerDown',\n pointerup: 'onPointerUp',\n pointermove: 'onPointerMove',\n pointerenter: 'onPointerEnter',\n pointerleave: 'onPointerLeave',\n pointercancel: 'onPointerCancel',\n\n mousedown: 'onMouseDown',\n mouseup: 'onMouseUp',\n mousemove: 'onMouseMove',\n mouseenter: 'onMouseEnter',\n mouseleave: 'onMouseLeave',\n mousecancel: 'onMouseCancel',\n\n click: 'onClick',\n dblclick: 'onDoubleClick',\n\n /* touch → pointer fallback for very old browsers */\n touchstart: 'onPointerDown',\n touchend: 'onPointerUp',\n touchmove: 'onPointerMove',\n touchcancel: 'onPointerCancel',\n};\n\nconst pointerEventTypes = [\n 'pointerdown',\n 'pointerup',\n 'pointermove',\n 'pointerenter',\n 'pointerleave',\n 'pointercancel',\n 'mousedown',\n 'mouseup',\n 'mousemove',\n 'mouseenter',\n 'mouseleave',\n 'mousecancel',\n 'click',\n 'dblclick',\n];\n\nconst touchEventTypes = ['touchstart', 'touchend', 'touchmove', 'touchcancel'];\nconst HAS_POINTER = typeof PointerEvent !== 'undefined';\n// If the browser supports Pointer Events, don't attach legacy touch events to avoid double-dispatch.\nconst allEventTypes = HAS_POINTER ? pointerEventTypes : [...pointerEventTypes, ...touchEventTypes];\n\n/* -------------------------------------------------- */\n/* helper: decide listener options per event type */\n/* -------------------------------------------------- */\nfunction listenerOpts(eventType: string, wantsRawTouch: boolean): AddEventListenerOptions {\n // Only touch events are toggled; pointer/mouse stay non-passive\n return eventType.startsWith('touch') ? { passive: !wantsRawTouch } : { passive: false };\n}\n\nfunction isTouchEvent(evt: Event): evt is TouchEvent {\n return typeof TouchEvent !== 'undefined' && evt instanceof TouchEvent;\n}\n\n/**\n * Check if an element should be excluded based on rules\n * This is in the framework layer, not the plugin\n */\nfunction shouldExcludeElement(element: Element | null, rules: InteractionExclusionRules): boolean {\n if (!element) return false;\n\n let current: Element | null = element;\n\n while (current) {\n // Check classes\n if (rules.classes?.length) {\n for (const className of rules.classes) {\n if (current.classList?.contains(className)) {\n return true;\n }\n }\n }\n\n // Check data attributes\n if (rules.dataAttributes?.length) {\n for (const attr of rules.dataAttributes) {\n if (current.hasAttribute(attr)) {\n return true;\n }\n }\n }\n\n // Move up the DOM tree\n current = current.parentElement;\n }\n\n return false;\n}\n\n/* -------------------------------------------------- */\n/* createPointerProvider */\n/* -------------------------------------------------- */\nexport function createPointerProvider(\n cap: InteractionManagerCapability,\n scope: InteractionScope,\n element: HTMLElement,\n convertEventToPoint?: (evt: PointerEvent, host: HTMLElement) => Position,\n) {\n /* ---------- live handler set --------------------------------------------------- */\n let active: PointerEventHandlers | null = cap.getHandlersForScope(scope);\n\n /* ---------- helper to compute current wantsRawTouch (defaults to true) --------- */\n const wantsRawTouchNow = () => cap.getActiveInteractionMode()?.wantsRawTouch !== false; // default → true\n\n /* ---------- dynamic listener (re)attachment ------------------------------------ */\n const listeners: Record<string, (evt: Event) => void> = {};\n let attachedWithRawTouch = wantsRawTouchNow(); // remember current mode’s wish\n\n const addListeners = (raw: boolean) => {\n allEventTypes.forEach((type) => {\n const fn = (listeners[type] ??= handleEvent);\n element.addEventListener(type, fn, listenerOpts(type, raw));\n });\n };\n const removeListeners = () => {\n allEventTypes.forEach((type) => {\n const fn = listeners[type];\n if (fn) element.removeEventListener(type, fn);\n });\n };\n\n /* attach for the first time */\n addListeners(attachedWithRawTouch);\n element.style.touchAction = attachedWithRawTouch ? 'none' : '';\n\n /* ---------- mode & handler change hooks --------------------------------------- */\n const stopMode = cap.onModeChange(() => {\n /* cursor baseline update for global wrapper */\n if (scope.type === 'global') {\n const mode = cap.getActiveInteractionMode();\n element.style.cursor = mode?.scope === 'global' ? (mode.cursor ?? 'auto') : 'auto';\n }\n\n active = cap.getHandlersForScope(scope);\n\n /* re-attach listeners if wantsRawTouch toggled */\n const raw = wantsRawTouchNow();\n if (raw !== attachedWithRawTouch) {\n removeListeners();\n addListeners(raw);\n attachedWithRawTouch = raw;\n element.style.touchAction = attachedWithRawTouch ? 'none' : '';\n }\n });\n\n const stopHandler = cap.onHandlerChange(() => {\n active = cap.getHandlersForScope(scope);\n });\n\n /* ---------- cursor sync -------------------------------------------------------- */\n const initialMode = cap.getActiveInteractionMode();\n const initialCursor = cap.getCurrentCursor();\n element.style.cursor =\n scope.type === 'global' && initialMode?.scope !== 'global' ? 'auto' : initialCursor;\n\n const stopCursor = cap.onCursorChange((c) => {\n if (scope.type === 'global' && cap.getActiveInteractionMode()?.scope !== 'global') return;\n element.style.cursor = c;\n });\n\n /* ---------- point conversion --------------------------------------------------- */\n const toPos = (e: { clientX: number; clientY: number }, host: HTMLElement): Position => {\n if (convertEventToPoint) return convertEventToPoint(e as PointerEvent, host);\n const r = host.getBoundingClientRect();\n return { x: e.clientX - r.left, y: e.clientY - r.top };\n };\n\n /* ---------- central event handler --------------------------------------------- */\n function handleEvent(evt: Event) {\n if (cap.isPaused()) return;\n\n // Get exclusion rules from capability and check in framework layer\n const exclusionRules = cap.getExclusionRules();\n if (evt.target && shouldExcludeElement(evt.target as Element, exclusionRules)) {\n return; // Skip processing this event\n }\n\n const handlerKey = domEventMap[evt.type];\n if (!handlerKey || !active?.[handlerKey]) return;\n\n /* preventDefault only when mode really wants raw touch */\n if (\n isTouchEvent(evt) &&\n attachedWithRawTouch &&\n (evt.type === 'touchmove' || evt.type === 'touchcancel')\n ) {\n evt.preventDefault();\n }\n\n // ----- normalise ----------------------------------------------------------------\n let pos!: Position;\n let normEvt!: EmbedPdfPointerEvent & {\n target: EventTarget | null;\n currentTarget: EventTarget | null;\n };\n\n if (isTouchEvent(evt)) {\n const tp =\n evt.type === 'touchend' || evt.type === 'touchcancel'\n ? evt.changedTouches[0]\n : evt.touches[0];\n if (!tp) return;\n\n pos = toPos(tp, element);\n normEvt = {\n clientX: tp.clientX,\n clientY: tp.clientY,\n ctrlKey: evt.ctrlKey,\n shiftKey: evt.shiftKey,\n altKey: evt.altKey,\n metaKey: evt.metaKey,\n target: evt.target,\n currentTarget: evt.currentTarget,\n setPointerCapture: () => {},\n releasePointerCapture: () => {},\n };\n } else {\n const pe = evt as PointerEvent;\n pos = toPos(pe, element);\n normEvt = {\n clientX: pe.clientX,\n clientY: pe.clientY,\n ctrlKey: pe.ctrlKey,\n shiftKey: pe.shiftKey,\n altKey: pe.altKey,\n metaKey: pe.metaKey,\n target: pe.target,\n currentTarget: pe.currentTarget,\n setPointerCapture: () => {\n (pe.target as HTMLElement)?.setPointerCapture?.(pe.pointerId);\n },\n releasePointerCapture: () => {\n (pe.target as HTMLElement)?.releasePointerCapture?.(pe.pointerId);\n },\n };\n }\n\n active[handlerKey]?.(pos, normEvt, cap.getActiveMode());\n }\n\n /* ---------- teardown ----------------------------------------------------------- */\n return () => {\n removeListeners();\n stopMode();\n stopCursor();\n stopHandler();\n };\n}\n","import { ReactNode, useEffect, useRef, HTMLAttributes, CSSProperties } from '@framework';\nimport { createPointerProvider } from '../utils';\n\nimport { useInteractionManagerCapability } from '../hooks';\n\ninterface GlobalPointerProviderProps extends HTMLAttributes<HTMLDivElement> {\n children: ReactNode;\n style?: CSSProperties;\n}\n\nexport const GlobalPointerProvider = ({\n children,\n style,\n ...props\n}: GlobalPointerProviderProps) => {\n const ref = useRef<HTMLDivElement>(null);\n const { provides: cap } = useInteractionManagerCapability();\n\n useEffect(() => {\n if (!cap || !ref.current) return;\n\n return createPointerProvider(cap, { type: 'global' }, ref.current);\n }, [cap]);\n\n return (\n <div\n ref={ref}\n style={{\n width: '100%',\n height: '100%',\n ...style,\n }}\n {...props}\n >\n {children}\n </div>\n );\n};\n","import {\n ReactNode,\n useEffect,\n useRef,\n useCallback,\n HTMLAttributes,\n CSSProperties,\n} from '@framework';\nimport { Position, restorePosition, Size, transformSize } from '@embedpdf/models';\nimport { createPointerProvider } from '../utils';\n\nimport { useInteractionManagerCapability, useIsPageExclusive } from '../hooks';\n\ninterface PagePointerProviderProps extends HTMLAttributes<HTMLDivElement> {\n children: ReactNode;\n pageIndex: number;\n pageWidth: number;\n pageHeight: number;\n rotation: number;\n scale: number;\n style?: CSSProperties;\n convertEventToPoint?: (event: PointerEvent, element: HTMLElement) => Position;\n}\n\nexport const PagePointerProvider = ({\n pageIndex,\n children,\n pageWidth,\n pageHeight,\n rotation,\n scale,\n convertEventToPoint,\n style,\n ...props\n}: PagePointerProviderProps) => {\n const ref = useRef<HTMLDivElement>(null);\n const { provides: cap } = useInteractionManagerCapability();\n const isPageExclusive = useIsPageExclusive();\n\n // Memoize the default conversion function\n const defaultConvertEventToPoint = useCallback(\n (event: PointerEvent, element: HTMLElement): Position => {\n const rect = element.getBoundingClientRect();\n const displayPoint = {\n x: event.clientX - rect.left,\n y: event.clientY - rect.top,\n };\n\n const displaySize: Size = transformSize(\n { width: pageWidth, height: pageHeight },\n rotation,\n 1,\n );\n\n return restorePosition(displaySize, displayPoint, rotation, scale);\n },\n [pageWidth, pageHeight, rotation, scale],\n );\n\n useEffect(() => {\n if (!cap || !ref.current) return;\n\n return createPointerProvider(\n cap,\n { type: 'page', pageIndex },\n ref.current,\n convertEventToPoint || defaultConvertEventToPoint,\n );\n }, [cap, pageIndex, convertEventToPoint, defaultConvertEventToPoint]);\n\n return (\n <div\n ref={ref}\n style={{\n position: 'relative',\n width: pageWidth,\n height: pageHeight,\n ...style,\n }}\n {...props}\n >\n {children}\n {isPageExclusive && (\n <div style={{ position: 'absolute', top: 0, left: 0, right: 0, bottom: 0, zIndex: 10 }} />\n )}\n </div>\n );\n};\n"],"names":["state","_a"],"mappings":";;;;;;AASO,MAAM,8BAA8B,MACzC,UAAoC,yBAAyB,EAAE;AAC1D,MAAM,kCAAkC,MAC7C,cAAwC,yBAAyB,EAAE;AAE9D,SAAS,wBAAwB;AAChC,QAAA,EAAE,SAAS,IAAI,gCAAgC;AACrD,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAkC,YAAY;AAExE,YAAU,MAAM;AACd,QAAI,CAAC,SAAU;AACR,WAAA,SAAS,cAAc,CAACA,WAAU;AACvC,eAASA,MAAK;AAAA,IAAA,CACf;AAAA,EAAA,GACA,CAAC,QAAQ,CAAC;AAEN,SAAA;AAAA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src/shared/utils.ts","../../src/shared/components/global-pointer-provider.tsx","../../src/shared/components/page-pointer-provider.tsx"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/@framework';\nimport {\n initialDocumentState,\n InteractionDocumentState,\n InteractionManagerPlugin,\n PointerEventHandlersWithLifecycle,\n} from '@embedpdf/plugin-interaction-manager';\nimport { useState, useEffect } from '@framework';\n\nexport const useInteractionManagerPlugin = () =>\n usePlugin<InteractionManagerPlugin>(InteractionManagerPlugin.id);\nexport const useInteractionManagerCapability = () =>\n useCapability<InteractionManagerPlugin>(InteractionManagerPlugin.id);\n\nexport function useInteractionManager(documentId: string) {\n const { provides } = useInteractionManagerCapability();\n const [state, setState] = useState<InteractionDocumentState>(initialDocumentState);\n\n useEffect(() => {\n if (!provides) return;\n const scope = provides.forDocument(documentId);\n return scope.onStateChange((state) => {\n setState(state);\n });\n }, [provides]);\n\n return {\n provides: provides?.forDocument(documentId) ?? null,\n state,\n };\n}\n\nexport function useCursor(documentId: string) {\n const { provides } = useInteractionManagerCapability();\n return {\n setCursor: (token: string, cursor: string, prio = 0) => {\n if (!provides) return;\n const scope = provides.forDocument(documentId);\n scope.setCursor(token, cursor, prio);\n },\n removeCursor: (token: string) => {\n if (!provides) return;\n const scope = provides.forDocument(documentId);\n scope.removeCursor(token);\n },\n };\n}\n\ninterface UsePointerHandlersOptions {\n modeId?: string | string[];\n pageIndex?: number;\n documentId: string;\n}\n\nexport function usePointerHandlers({ modeId, pageIndex, documentId }: UsePointerHandlersOptions) {\n const { provides } = useInteractionManagerCapability();\n return {\n register: (\n handlers: PointerEventHandlersWithLifecycle,\n options?: { modeId?: string | string[]; pageIndex?: number; documentId?: string },\n ) => {\n // Use provided options or fall back to hook-level options\n const finalModeId = options?.modeId ?? modeId;\n const finalPageIndex = options?.pageIndex ?? pageIndex;\n const finalDocumentId = options?.documentId ?? documentId;\n\n return finalModeId\n ? provides?.registerHandlers({\n modeId: finalModeId,\n handlers,\n pageIndex: finalPageIndex,\n documentId: finalDocumentId,\n })\n : provides?.registerAlways({\n scope:\n finalPageIndex !== undefined\n ? { type: 'page', documentId: finalDocumentId, pageIndex: finalPageIndex }\n : { type: 'global', documentId: finalDocumentId },\n handlers,\n });\n },\n };\n}\n\nexport function useIsPageExclusive(documentId: string) {\n const { provides: cap } = useInteractionManagerCapability();\n\n const [isPageExclusive, setIsPageExclusive] = useState<boolean>(() => {\n if (!cap) return false;\n const scope = cap.forDocument(documentId);\n const m = scope.getActiveInteractionMode();\n return m?.scope === 'page' && !!m.exclusive;\n });\n\n useEffect(() => {\n if (!cap) return;\n\n const scope = cap.forDocument(documentId);\n\n return scope.onModeChange(() => {\n const mode = scope.getActiveInteractionMode();\n setIsPageExclusive(mode?.scope === 'page' && !!mode?.exclusive);\n });\n }, [cap, documentId]);\n\n return isPageExclusive;\n}\n","import { Position } from '@embedpdf/models';\nimport type {\n InteractionManagerCapability,\n InteractionScope,\n PointerEventHandlers,\n EmbedPdfPointerEvent,\n InteractionExclusionRules,\n} from '@embedpdf/plugin-interaction-manager';\n\n/* -------------------------------------------------- */\n/* event → handler key lookup */\n/* -------------------------------------------------- */\ntype K = keyof PointerEventHandlers;\nconst domEventMap: Record<string, K> = {\n pointerdown: 'onPointerDown',\n pointerup: 'onPointerUp',\n pointermove: 'onPointerMove',\n pointerenter: 'onPointerEnter',\n pointerleave: 'onPointerLeave',\n pointercancel: 'onPointerCancel',\n\n mousedown: 'onMouseDown',\n mouseup: 'onMouseUp',\n mousemove: 'onMouseMove',\n mouseenter: 'onMouseEnter',\n mouseleave: 'onMouseLeave',\n mousecancel: 'onMouseCancel',\n\n click: 'onClick',\n dblclick: 'onDoubleClick',\n\n /* touch → pointer fallback for very old browsers */\n touchstart: 'onPointerDown',\n touchend: 'onPointerUp',\n touchmove: 'onPointerMove',\n touchcancel: 'onPointerCancel',\n};\n\nconst pointerEventTypes = [\n 'pointerdown',\n 'pointerup',\n 'pointermove',\n 'pointerenter',\n 'pointerleave',\n 'pointercancel',\n 'mousedown',\n 'mouseup',\n 'mousemove',\n 'mouseenter',\n 'mouseleave',\n 'mousecancel',\n 'click',\n 'dblclick',\n];\n\nconst touchEventTypes = ['touchstart', 'touchend', 'touchmove', 'touchcancel'];\nconst HAS_POINTER = typeof PointerEvent !== 'undefined';\n// If the browser supports Pointer Events, don't attach legacy touch events to avoid double-dispatch.\nconst allEventTypes = HAS_POINTER ? pointerEventTypes : [...pointerEventTypes, ...touchEventTypes];\n\n/* -------------------------------------------------- */\n/* helper: decide listener options per event type */\n/* -------------------------------------------------- */\nfunction listenerOpts(eventType: string, wantsRawTouch: boolean): AddEventListenerOptions {\n // Only touch events are toggled; pointer/mouse stay non-passive\n return eventType.startsWith('touch') ? { passive: !wantsRawTouch } : { passive: false };\n}\n\nfunction isTouchEvent(evt: Event): evt is TouchEvent {\n return typeof TouchEvent !== 'undefined' && evt instanceof TouchEvent;\n}\n\n/**\n * Check if an element should be excluded based on rules\n * This is in the framework layer, not the plugin\n */\nfunction shouldExcludeElement(element: Element | null, rules: InteractionExclusionRules): boolean {\n if (!element) return false;\n\n let current: Element | null = element;\n\n while (current) {\n // Check classes\n if (rules.classes?.length) {\n for (const className of rules.classes) {\n if (current.classList?.contains(className)) {\n return true;\n }\n }\n }\n\n // Check data attributes\n if (rules.dataAttributes?.length) {\n for (const attr of rules.dataAttributes) {\n if (current.hasAttribute(attr)) {\n return true;\n }\n }\n }\n\n // Move up the DOM tree\n current = current.parentElement;\n }\n\n return false;\n}\n\n/* -------------------------------------------------- */\n/* createPointerProvider */\n/* -------------------------------------------------- */\nexport function createPointerProvider(\n cap: InteractionManagerCapability,\n scope: InteractionScope,\n element: HTMLElement,\n convertEventToPoint?: (evt: PointerEvent, host: HTMLElement) => Position,\n) {\n const capScope = cap.forDocument(scope.documentId);\n /* ---------- live handler set --------------------------------------------------- */\n let active: PointerEventHandlers | null = cap.getHandlersForScope(scope);\n\n /* ---------- helper to compute current wantsRawTouch (defaults to true) --------- */\n const wantsRawTouchNow = () => capScope.getActiveInteractionMode()?.wantsRawTouch !== false; // default → true\n\n /* ---------- dynamic listener (re)attachment ------------------------------------ */\n const listeners: Record<string, (evt: Event) => void> = {};\n let attachedWithRawTouch = wantsRawTouchNow(); // remember current mode’s wish\n\n const addListeners = (raw: boolean) => {\n allEventTypes.forEach((type) => {\n const fn = (listeners[type] ??= handleEvent);\n element.addEventListener(type, fn, listenerOpts(type, raw));\n });\n };\n const removeListeners = () => {\n allEventTypes.forEach((type) => {\n const fn = listeners[type];\n if (fn) element.removeEventListener(type, fn);\n });\n };\n\n /* attach for the first time */\n addListeners(attachedWithRawTouch);\n element.style.touchAction = attachedWithRawTouch ? 'none' : '';\n\n /* ---------- mode & handler change hooks --------------------------------------- */\n const stopMode = capScope.onModeChange(() => {\n /* cursor baseline update for global wrapper */\n if (scope.type === 'global') {\n const mode = capScope.getActiveInteractionMode();\n element.style.cursor = mode?.scope === 'global' ? (mode.cursor ?? 'auto') : 'auto';\n }\n\n active = cap.getHandlersForScope(scope);\n\n /* re-attach listeners if wantsRawTouch toggled */\n const raw = wantsRawTouchNow();\n if (raw !== attachedWithRawTouch) {\n removeListeners();\n addListeners(raw);\n attachedWithRawTouch = raw;\n element.style.touchAction = attachedWithRawTouch ? 'none' : '';\n }\n });\n\n const stopHandler = cap.onHandlerChange(() => {\n active = cap.getHandlersForScope(scope);\n });\n\n /* ---------- cursor sync -------------------------------------------------------- */\n const initialMode = capScope.getActiveInteractionMode();\n const initialCursor = capScope.getCurrentCursor();\n element.style.cursor =\n scope.type === 'global' && initialMode?.scope !== 'global' ? 'auto' : initialCursor;\n\n const stopCursor = capScope.onCursorChange((c) => {\n if (scope.type === 'global' && capScope.getActiveInteractionMode()?.scope !== 'global') return;\n element.style.cursor = c;\n });\n\n /* ---------- point conversion --------------------------------------------------- */\n const toPos = (e: { clientX: number; clientY: number }, host: HTMLElement): Position => {\n if (convertEventToPoint) return convertEventToPoint(e as PointerEvent, host);\n const r = host.getBoundingClientRect();\n return { x: e.clientX - r.left, y: e.clientY - r.top };\n };\n\n /* ---------- central event handler --------------------------------------------- */\n function handleEvent(evt: Event) {\n if (cap.isPaused()) return;\n\n // Get exclusion rules from capability and check in framework layer\n const exclusionRules = cap.getExclusionRules();\n if (evt.target && shouldExcludeElement(evt.target as Element, exclusionRules)) {\n return; // Skip processing this event\n }\n\n const handlerKey = domEventMap[evt.type];\n if (!handlerKey || !active?.[handlerKey]) return;\n\n /* preventDefault only when mode really wants raw touch */\n if (\n isTouchEvent(evt) &&\n attachedWithRawTouch &&\n (evt.type === 'touchmove' || evt.type === 'touchcancel')\n ) {\n evt.preventDefault();\n }\n\n // ----- normalise ----------------------------------------------------------------\n let pos!: Position;\n let normEvt!: EmbedPdfPointerEvent & {\n target: EventTarget | null;\n currentTarget: EventTarget | null;\n };\n\n if (isTouchEvent(evt)) {\n const tp =\n evt.type === 'touchend' || evt.type === 'touchcancel'\n ? evt.changedTouches[0]\n : evt.touches[0];\n if (!tp) return;\n\n pos = toPos(tp, element);\n normEvt = {\n clientX: tp.clientX,\n clientY: tp.clientY,\n ctrlKey: evt.ctrlKey,\n shiftKey: evt.shiftKey,\n altKey: evt.altKey,\n metaKey: evt.metaKey,\n target: evt.target,\n currentTarget: evt.currentTarget,\n setPointerCapture: () => {},\n releasePointerCapture: () => {},\n };\n } else {\n const pe = evt as PointerEvent;\n pos = toPos(pe, element);\n normEvt = {\n clientX: pe.clientX,\n clientY: pe.clientY,\n ctrlKey: pe.ctrlKey,\n shiftKey: pe.shiftKey,\n altKey: pe.altKey,\n metaKey: pe.metaKey,\n target: pe.target,\n currentTarget: pe.currentTarget,\n setPointerCapture: () => {\n (pe.target as HTMLElement)?.setPointerCapture?.(pe.pointerId);\n },\n releasePointerCapture: () => {\n (pe.target as HTMLElement)?.releasePointerCapture?.(pe.pointerId);\n },\n };\n }\n\n active[handlerKey]?.(pos, normEvt, capScope.getActiveMode());\n }\n\n /* ---------- teardown ----------------------------------------------------------- */\n return () => {\n removeListeners();\n stopMode();\n stopCursor();\n stopHandler();\n };\n}\n","import { ReactNode, useEffect, useRef, HTMLAttributes, CSSProperties } from '@framework';\nimport { createPointerProvider } from '../utils';\nimport { useInteractionManagerCapability } from '../hooks';\n\ninterface GlobalPointerProviderProps extends HTMLAttributes<HTMLDivElement> {\n children: ReactNode;\n documentId: string;\n style?: CSSProperties;\n}\n\nexport const GlobalPointerProvider = ({\n children,\n documentId,\n style,\n ...props\n}: GlobalPointerProviderProps) => {\n const ref = useRef<HTMLDivElement>(null);\n const { provides: cap } = useInteractionManagerCapability();\n\n useEffect(() => {\n if (!cap || !ref.current) return;\n\n return createPointerProvider(cap, { type: 'global', documentId }, ref.current);\n }, [cap, documentId]);\n\n return (\n <div\n ref={ref}\n style={{\n width: '100%',\n height: '100%',\n ...style,\n }}\n {...props}\n >\n {children}\n </div>\n );\n};\n","import {\n ReactNode,\n useEffect,\n useRef,\n useCallback,\n HTMLAttributes,\n CSSProperties,\n} from '@framework';\nimport { useDocumentState } from '@embedpdf/core/@framework';\nimport { Position, restorePosition, Size, transformSize } from '@embedpdf/models';\nimport { createPointerProvider } from '../utils';\n\nimport { useInteractionManagerCapability, useIsPageExclusive } from '../hooks';\n\ninterface PagePointerProviderProps extends HTMLAttributes<HTMLDivElement> {\n children: ReactNode;\n documentId: string;\n pageIndex: number;\n rotation?: number;\n scale?: number;\n style?: CSSProperties;\n convertEventToPoint?: (event: PointerEvent, element: HTMLElement) => Position;\n}\n\nexport const PagePointerProvider = ({\n documentId,\n pageIndex,\n children,\n rotation: rotationOverride,\n scale: scaleOverride,\n convertEventToPoint,\n style,\n ...props\n}: PagePointerProviderProps) => {\n const ref = useRef<HTMLDivElement>(null);\n const { provides: cap } = useInteractionManagerCapability();\n const isPageExclusive = useIsPageExclusive(documentId);\n const documentState = useDocumentState(documentId);\n\n // Get page dimensions and transformations from document state\n // Calculate inline - this is cheap and memoization isn't necessary\n const page = documentState?.document?.pages?.[pageIndex];\n const naturalPageSize = page?.size ?? { width: 0, height: 0 };\n const rotation = rotationOverride ?? documentState?.rotation ?? 0;\n const scale = scaleOverride ?? documentState?.scale ?? 1;\n const displaySize = transformSize(naturalPageSize, 0, scale);\n\n // Simplified conversion function\n const defaultConvertEventToPoint = useCallback(\n (event: PointerEvent, element: HTMLElement): Position => {\n const rect = element.getBoundingClientRect();\n const displayPoint = {\n x: event.clientX - rect.left,\n y: event.clientY - rect.top,\n };\n\n // Get the rotated natural size (width/height may be swapped, but not scaled)\n const rotatedNaturalSize = transformSize(\n {\n width: displaySize.width,\n height: displaySize.height,\n },\n rotation,\n 1,\n );\n\n return restorePosition(rotatedNaturalSize, displayPoint, rotation, scale);\n },\n [naturalPageSize, rotation, scale],\n );\n\n useEffect(() => {\n if (!cap || !ref.current) return;\n\n return createPointerProvider(\n cap,\n { type: 'page', documentId, pageIndex },\n ref.current,\n convertEventToPoint || defaultConvertEventToPoint,\n );\n }, [cap, documentId, pageIndex, convertEventToPoint, defaultConvertEventToPoint]);\n\n return (\n <div\n ref={ref}\n style={{\n position: 'relative',\n width: displaySize.width,\n height: displaySize.height,\n ...style,\n }}\n {...props}\n >\n {children}\n {isPageExclusive && (\n <div style={{ position: 'absolute', top: 0, left: 0, right: 0, bottom: 0, zIndex: 10 }} />\n )}\n </div>\n );\n};\n"],"names":["state","_a"],"mappings":";;;;;;AASO,MAAM,8BAA8B,MACzC,UAAoC,yBAAyB,EAAE;AAC1D,MAAM,kCAAkC,MAC7C,cAAwC,yBAAyB,EAAE;AAE9D,SAAS,sBAAsB,YAAoB;AACxD,QAAM,EAAE,SAAA,IAAa,gCAAA;AACrB,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAmC,oBAAoB;AAEjF,YAAU,MAAM;AACd,QAAI,CAAC,SAAU;AACf,UAAM,QAAQ,SAAS,YAAY,UAAU;AAC7C,WAAO,MAAM,cAAc,CAACA,WAAU;AACpC,eAASA,MAAK;AAAA,IAChB,CAAC;AAAA,EACH,GAAG,CAAC,QAAQ,CAAC;AAEb,SAAO;AAAA,IACL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A,MAAA;AAGF,aAAO,gBAAgB,oBAAoB,cAAc,UAAU,KAAK;AAAA,IAC1E;AAAA,IACA,CAAC,iBAAiB,UAAU,KAAK;AAAA,EAAA;AAGnC,YAAU,MAAM;AACd,QAAI,CAAC,OAAO,CAAC,IAAI,QAAS;AAE1B,WAAO;AAAA,MACL;AAAA,MACA,EAAE,MAAM,QAAQ,YAAY,UAAA;AAAA,MAC5B,IAAI;AAAA,MACJ,uBAAuB;AAAA,IAAA;AAAA,EAE3B,GAAG,CAAC,KAAK,YAAY,WAAW,qBAAqB,0BAA0B,CAAC;AAEhF,SACE;AAAA,IAAC;AAAA,IAAA;AAAA,MACC;AAAA,MACA,OAAO;AAAA,QACL,UAAU;AAAA,QACV,OAAO,YAAY;AAAA,QACnB,QAAQ,YAAY;AAAA,QACpB,GAAG;AAAA,MAAA;AAAA,MAEJ,GAAG;AAAA,MAEH,UAAA;AAAA,QAAA;AAAA,QACA,mBACC,oBAAC,OAAA,EAAI,OAAO,EAAE,UAAU,YAAY,KAAK,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,GAAG,QAAQ,KAAG,CAAG;AAAA,MAAA;AAAA,IAAA;AAAA,EAAA;AAIhG;"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core/react"),t=require("@embedpdf/plugin-interaction-manager"),n=require("react"),o=require("react/jsx-runtime"),r=require("@embedpdf/models"),i=()=>e.useCapability(t.InteractionManagerPlugin.id);function l(){const{provides:e}=i(),[t,o]=n.useState((()=>{const t=null==e?void 0:e.getActiveInteractionMode();return"page"===(null==t?void 0:t.scope)&&!!t.exclusive}));return n.useEffect((()=>{if(e)return e.onModeChange((()=>{const t=e.getActiveInteractionMode();o("page"===(null==t?void 0:t.scope)&&!!(null==t?void 0:t.exclusive))}))}),[e]),t}const s={pointerdown:"onPointerDown",pointerup:"onPointerUp",pointermove:"onPointerMove",pointerenter:"onPointerEnter",pointerleave:"onPointerLeave",pointercancel:"onPointerCancel",mousedown:"onMouseDown",mouseup:"onMouseUp",mousemove:"onMouseMove",mouseenter:"onMouseEnter",mouseleave:"onMouseLeave",mousecancel:"onMouseCancel",click:"onClick",dblclick:"onDoubleClick",touchstart:"onPointerDown",touchend:"onPointerUp",touchmove:"onPointerMove",touchcancel:"onPointerCancel"},c=["pointerdown","pointerup","pointermove","pointerenter","pointerleave","pointercancel","mousedown","mouseup","mousemove","mouseenter","mouseleave","mousecancel","click","dblclick"],u="undefined"!=typeof PointerEvent?c:[...c,"touchstart","touchend","touchmove","touchcancel"];function a(e){return"undefined"!=typeof TouchEvent&&e instanceof TouchEvent}function d(e,t,n,o){let r=e.getHandlersForScope(t);const i=()=>{var t;return!1!==(null==(t=e.getActiveInteractionMode())?void 0:t.wantsRawTouch)},l={};let c=i();const d=e=>{u.forEach((t=>{const o=l[t]??(l[t]=P);var r;n.addEventListener(t,o,(r=e,t.startsWith("touch")?{passive:!r}:{passive:!1}))}))},p=()=>{u.forEach((e=>{const t=l[e];t&&n.removeEventListener(e,t)}))};d(c),n.style.touchAction=c?"none":"";const g=e.onModeChange((()=>{if("global"===t.type){const t=e.getActiveInteractionMode();n.style.cursor="global"===(null==t?void 0:t.scope)?t.cursor??"auto":"auto"}r=e.getHandlersForScope(t);const o=i();o!==c&&(p(),d(o),c=o,n.style.touchAction=c?"none":"")})),v=e.onHandlerChange((()=>{r=e.getHandlersForScope(t)})),f=e.getActiveInteractionMode(),h=e.getCurrentCursor();n.style.cursor="global"===t.type&&"global"!==(null==f?void 0:f.scope)?"auto":h;const y=e.onCursorChange((o=>{var r;"global"===t.type&&"global"!==(null==(r=e.getActiveInteractionMode())?void 0:r.scope)||(n.style.cursor=o)})),m=(e,t)=>{if(o)return o(e,t);const n=t.getBoundingClientRect();return{x:e.clientX-n.left,y:e.clientY-n.top}};function P(t){var o;if(e.isPaused())return;const i=e.getExclusionRules();if(t.target&&function(e,t){var n,o,r;if(!e)return!1;let i=e;for(;i;){if(null==(n=t.classes)?void 0:n.length)for(const e of t.classes)if(null==(o=i.classList)?void 0:o.contains(e))return!0;if(null==(r=t.dataAttributes)?void 0:r.length)for(const e of t.dataAttributes)if(i.hasAttribute(e))return!0;i=i.parentElement}return!1}(t.target,i))return;const l=s[t.type];if(!l||!(null==r?void 0:r[l]))return;let u,d;if(a(t)&&c&&("touchmove"===t.type||"touchcancel"===t.type)&&t.preventDefault(),a(t)){const e="touchend"===t.type||"touchcancel"===t.type?t.changedTouches[0]:t.touches[0];if(!e)return;u=m(e,n),d={clientX:e.clientX,clientY:e.clientY,ctrlKey:t.ctrlKey,shiftKey:t.shiftKey,altKey:t.altKey,metaKey:t.metaKey,target:t.target,currentTarget:t.currentTarget,setPointerCapture:()=>{},releasePointerCapture:()=>{}}}else{const e=t;u=m(e,n),d={clientX:e.clientX,clientY:e.clientY,ctrlKey:e.ctrlKey,shiftKey:e.shiftKey,altKey:e.altKey,metaKey:e.metaKey,target:e.target,currentTarget:e.currentTarget,setPointerCapture:()=>{var t,n;null==(n=null==(t=e.target)?void 0:t.setPointerCapture)||n.call(t,e.pointerId)},releasePointerCapture:()=>{var t,n;null==(n=null==(t=e.target)?void 0:t.releasePointerCapture)||n.call(t,e.pointerId)}}}null==(o=r[l])||o.call(r,u,d,e.getActiveMode())}return()=>{p(),g(),y(),v()}}exports.GlobalPointerProvider=({children:e,style:t,...r})=>{const l=n.useRef(null),{provides:s}=i();return n.useEffect((()=>{if(s&&l.current)return d(s,{type:"global"},l.current)}),[s]),o.jsx("div",{ref:l,style:{width:"100%",height:"100%",...t},...r,children:e})},exports.PagePointerProvider=({pageIndex:e,children:t,pageWidth:s,pageHeight:c,rotation:u,scale:a,convertEventToPoint:p,style:g,...v})=>{const f=n.useRef(null),{provides:h}=i(),y=l(),m=n.useCallback(((e,t)=>{const n=t.getBoundingClientRect(),o={x:e.clientX-n.left,y:e.clientY-n.top},i=r.transformSize({width:s,height:c},u,1);return r.restorePosition(i,o,u,a)}),[s,c,u,a]);return n.useEffect((()=>{if(h&&f.current)return d(h,{type:"page",pageIndex:e},f.current,p||m)}),[h,e,p,m]),o.jsxs("div",{ref:f,style:{position:"relative",width:s,height:c,...g},...v,children:[t,y&&o.jsx("div",{style:{position:"absolute",top:0,left:0,right:0,bottom:0,zIndex:10}})]})},exports.useCursor=function(){const{provides:e}=i();return{setCursor:(t,n,o=0)=>{null==e||e.setCursor(t,n,o)},removeCursor:t=>{null==e||e.removeCursor(t)}}},exports.useInteractionManager=function(){const{provides:e}=i(),[o,r]=n.useState(t.initialState);return n.useEffect((()=>{if(e)return e.onStateChange((e=>{r(e)}))}),[e]),{provides:e,state:o}},exports.useInteractionManagerCapability=i,exports.useInteractionManagerPlugin=()=>e.usePlugin(t.InteractionManagerPlugin.id),exports.useIsPageExclusive=l,exports.usePointerHandlers=function({modeId:e,pageIndex:t}){const{provides:n}=i();return{register:(o,r)=>{const i=(null==r?void 0:r.modeId)??e,l=(null==r?void 0:r.pageIndex)??t;return i?null==n?void 0:n.registerHandlers({modeId:i,handlers:o,pageIndex:l}):null==n?void 0:n.registerAlways({scope:void 0!==l?{type:"page",pageIndex:l}:{type:"global"},handlers:o})}}},Object.keys(t).forEach((e=>{"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:()=>t[e]})}));
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core/react"),t=require("@embedpdf/plugin-interaction-manager"),n=require("react"),o=require("react/jsx-runtime"),r=require("@embedpdf/models"),i=()=>e.useCapability(t.InteractionManagerPlugin.id);function u(e){const{provides:t}=i(),[o,r]=n.useState(()=>{if(!t)return!1;const n=t.forDocument(e).getActiveInteractionMode();return"page"===(null==n?void 0:n.scope)&&!!n.exclusive});return n.useEffect(()=>{if(!t)return;const n=t.forDocument(e);return n.onModeChange(()=>{const e=n.getActiveInteractionMode();r("page"===(null==e?void 0:e.scope)&&!!(null==e?void 0:e.exclusive))})},[t,e]),o}const c={pointerdown:"onPointerDown",pointerup:"onPointerUp",pointermove:"onPointerMove",pointerenter:"onPointerEnter",pointerleave:"onPointerLeave",pointercancel:"onPointerCancel",mousedown:"onMouseDown",mouseup:"onMouseUp",mousemove:"onMouseMove",mouseenter:"onMouseEnter",mouseleave:"onMouseLeave",mousecancel:"onMouseCancel",click:"onClick",dblclick:"onDoubleClick",touchstart:"onPointerDown",touchend:"onPointerUp",touchmove:"onPointerMove",touchcancel:"onPointerCancel"},l=["pointerdown","pointerup","pointermove","pointerenter","pointerleave","pointercancel","mousedown","mouseup","mousemove","mouseenter","mouseleave","mousecancel","click","dblclick"],s="undefined"!=typeof PointerEvent?l:[...l,"touchstart","touchend","touchmove","touchcancel"];function a(e){return"undefined"!=typeof TouchEvent&&e instanceof TouchEvent}function d(e,t,n,o){const r=e.forDocument(t.documentId);let i=e.getHandlersForScope(t);const u=()=>{var e;return!1!==(null==(e=r.getActiveInteractionMode())?void 0:e.wantsRawTouch)},l={};let d=u();const p=e=>{s.forEach(t=>{const o=l[t]??(l[t]=P);var r;n.addEventListener(t,o,(r=e,t.startsWith("touch")?{passive:!r}:{passive:!1}))})},v=()=>{s.forEach(e=>{const t=l[e];t&&n.removeEventListener(e,t)})};p(d),n.style.touchAction=d?"none":"";const g=r.onModeChange(()=>{if("global"===t.type){const e=r.getActiveInteractionMode();n.style.cursor="global"===(null==e?void 0:e.scope)?e.cursor??"auto":"auto"}i=e.getHandlersForScope(t);const o=u();o!==d&&(v(),p(o),d=o,n.style.touchAction=d?"none":"")}),f=e.onHandlerChange(()=>{i=e.getHandlersForScope(t)}),h=r.getActiveInteractionMode(),m=r.getCurrentCursor();n.style.cursor="global"===t.type&&"global"!==(null==h?void 0:h.scope)?"auto":m;const y=r.onCursorChange(e=>{var o;"global"===t.type&&"global"!==(null==(o=r.getActiveInteractionMode())?void 0:o.scope)||(n.style.cursor=e)}),I=(e,t)=>{if(o)return o(e,t);const n=t.getBoundingClientRect();return{x:e.clientX-n.left,y:e.clientY-n.top}};function P(t){var o;if(e.isPaused())return;const u=e.getExclusionRules();if(t.target&&function(e,t){var n,o,r;if(!e)return!1;let i=e;for(;i;){if(null==(n=t.classes)?void 0:n.length)for(const e of t.classes)if(null==(o=i.classList)?void 0:o.contains(e))return!0;if(null==(r=t.dataAttributes)?void 0:r.length)for(const e of t.dataAttributes)if(i.hasAttribute(e))return!0;i=i.parentElement}return!1}(t.target,u))return;const l=c[t.type];if(!l||!(null==i?void 0:i[l]))return;let s,p;if(a(t)&&d&&("touchmove"===t.type||"touchcancel"===t.type)&&t.preventDefault(),a(t)){const e="touchend"===t.type||"touchcancel"===t.type?t.changedTouches[0]:t.touches[0];if(!e)return;s=I(e,n),p={clientX:e.clientX,clientY:e.clientY,ctrlKey:t.ctrlKey,shiftKey:t.shiftKey,altKey:t.altKey,metaKey:t.metaKey,target:t.target,currentTarget:t.currentTarget,setPointerCapture:()=>{},releasePointerCapture:()=>{}}}else{const e=t;s=I(e,n),p={clientX:e.clientX,clientY:e.clientY,ctrlKey:e.ctrlKey,shiftKey:e.shiftKey,altKey:e.altKey,metaKey:e.metaKey,target:e.target,currentTarget:e.currentTarget,setPointerCapture:()=>{var t,n;null==(n=null==(t=e.target)?void 0:t.setPointerCapture)||n.call(t,e.pointerId)},releasePointerCapture:()=>{var t,n;null==(n=null==(t=e.target)?void 0:t.releasePointerCapture)||n.call(t,e.pointerId)}}}null==(o=i[l])||o.call(i,s,p,r.getActiveMode())}return()=>{v(),g(),y(),f()}}exports.GlobalPointerProvider=({children:e,documentId:t,style:r,...u})=>{const c=n.useRef(null),{provides:l}=i();return n.useEffect(()=>{if(l&&c.current)return d(l,{type:"global",documentId:t},c.current)},[l,t]),o.jsx("div",{ref:c,style:{width:"100%",height:"100%",...r},...u,children:e})},exports.PagePointerProvider=({documentId:t,pageIndex:c,children:l,rotation:s,scale:a,convertEventToPoint:p,style:v,...g})=>{var f,h;const m=n.useRef(null),{provides:y}=i(),I=u(t),P=e.useDocumentState(t),b=null==(h=null==(f=null==P?void 0:P.document)?void 0:f.pages)?void 0:h[c],C=(null==b?void 0:b.size)??{width:0,height:0},x=s??(null==P?void 0:P.rotation)??0,M=a??(null==P?void 0:P.scale)??1,E=r.transformSize(C,0,M),w=n.useCallback((e,t)=>{const n=t.getBoundingClientRect(),o={x:e.clientX-n.left,y:e.clientY-n.top},i=r.transformSize({width:E.width,height:E.height},x,1);return r.restorePosition(i,o,x,M)},[C,x,M]);return n.useEffect(()=>{if(y&&m.current)return d(y,{type:"page",documentId:t,pageIndex:c},m.current,p||w)},[y,t,c,p,w]),o.jsxs("div",{ref:m,style:{position:"relative",width:E.width,height:E.height,...v},...g,children:[l,I&&o.jsx("div",{style:{position:"absolute",top:0,left:0,right:0,bottom:0,zIndex:10}})]})},exports.useCursor=function(e){const{provides:t}=i();return{setCursor:(n,o,r=0)=>{if(!t)return;t.forDocument(e).setCursor(n,o,r)},removeCursor:n=>{if(!t)return;t.forDocument(e).removeCursor(n)}}},exports.useInteractionManager=function(e){const{provides:o}=i(),[r,u]=n.useState(t.initialDocumentState);return n.useEffect(()=>{if(!o)return;return o.forDocument(e).onStateChange(e=>{u(e)})},[o]),{provides:(null==o?void 0:o.forDocument(e))??null,state:r}},exports.useInteractionManagerCapability=i,exports.useInteractionManagerPlugin=()=>e.usePlugin(t.InteractionManagerPlugin.id),exports.useIsPageExclusive=u,exports.usePointerHandlers=function({modeId:e,pageIndex:t,documentId:n}){const{provides:o}=i();return{register:(r,i)=>{const u=(null==i?void 0:i.modeId)??e,c=(null==i?void 0:i.pageIndex)??t,l=(null==i?void 0:i.documentId)??n;return u?null==o?void 0:o.registerHandlers({modeId:u,handlers:r,pageIndex:c,documentId:l}):null==o?void 0:o.registerAlways({scope:void 0!==c?{type:"page",documentId:l,pageIndex:c}:{type:"global",documentId:l},handlers:r})}}},Object.keys(t).forEach(e=>{"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:()=>t[e]})});
2
2
  //# sourceMappingURL=index.cjs.map