{"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    // Track propagation state for this event\n    let propagationStopped = false;\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        stopImmediatePropagation: () => {\n          propagationStopped = true;\n        },\n        isImmediatePropagationStopped: () => propagationStopped,\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        stopImmediatePropagation: () => {\n          propagationStopped = true;\n        },\n        isImmediatePropagationStopped: () => propagationStopped,\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  // If override is provided, use it directly (consistent with other layer components)\n  // Otherwise, combine page intrinsic rotation with document rotation\n  const pageRotation = page?.rotation ?? 0;\n  const docRotation = documentState?.rotation ?? 0;\n  const rotation =\n    rotationOverride !== undefined ? rotationOverride : (pageRotation + docRotation) % 4;\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","propagationStopped","tp","changedTouches","touches","ctrlKey","shiftKey","altKey","metaKey","currentTarget","setPointerCapture","releasePointerCapture","stopImmediatePropagation","isImmediatePropagationStopped","pe","call","pointerId","getActiveMode","children","props","ref","useRef","jsx","width","height","pageIndex","rotation","rotationOverride","scale","scaleOverride","documentState","useDocumentState","page","document","pages","naturalPageSize","size","pageRotation","docRotation","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":"0PAWaA,EAAkC,IAC7CC,gBAAwCC,EAAAA,yBAAyBC,IAwE5D,SAASC,EAAmBC,GACjC,MAAQC,SAAUC,GAAQP,KAEnBQ,EAAiBC,GAAsBC,EAAAA,SAAkB,KAC9D,IAAKH,EAAK,OAAO,EACjB,MACMI,EADQJ,EAAIK,YAAYP,GACdQ,2BAChB,MAAoB,UAAb,MAAAF,OAAA,EAAAA,EAAGG,UAAsBH,EAAEI,YAcpC,OAXAC,EAAAA,UAAU,KACR,IAAKT,EAAK,OAEV,MAAMO,EAAQP,EAAIK,YAAYP,GAE9B,OAAOS,EAAMG,aAAa,KACxB,MAAMC,EAAOJ,EAAMD,2BACnBJ,EAAmC,gBAAhBS,WAAMJ,iBAAsBI,WAAMH,eAEtD,CAACR,EAAKF,IAEFG,CACT,CC7FA,MAAMW,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,GACpB,MAA6B,oBAAfC,YAA8BD,aAAeC,UAC7D,CAwCO,SAASC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