@embedpdf/plugin-interaction-manager 1.0.17 → 1.0.19

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.
@@ -33,6 +33,10 @@ export interface EmbedPdfPointerEvent {
33
33
  shiftKey: boolean;
34
34
  altKey: boolean;
35
35
  metaKey: boolean;
36
+ target: any;
37
+ currentTarget: any;
38
+ setPointerCapture?(): void;
39
+ releasePointerCapture?(): void;
36
40
  }
37
41
  export interface PointerEventHandlers<T = EmbedPdfPointerEvent> {
38
42
  onPointerDown?(pos: Position, evt: T, modeId: string): void;
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core/preact"),t=require("@embedpdf/plugin-interaction-manager"),o=require("preact/hooks"),n=require("preact/jsx-runtime"),r=require("@embedpdf/models"),i=()=>e.useCapability(t.InteractionManagerPlugin.id);function c(){const{provides:e}=i(),[t,n]=o.useState((()=>{const t=null==e?void 0:e.getActiveInteractionMode();return"page"===(null==t?void 0:t.scope)&&!!t.exclusive}));return o.useEffect((()=>{if(e)return e.onModeChange((()=>{const t=e.getActiveInteractionMode();n("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"},u=["pointerdown","pointerup","pointermove","pointerenter","pointerleave","pointercancel","mousedown","mouseup","mousemove","mouseenter","mouseleave","mousecancel","click","dblclick","touchstart","touchend","touchmove","touchcancel"];function l(e,t,o,n){let r=e.getHandlersForScope(t);const i=()=>{var t;return!1!==(null==(t=e.getActiveInteractionMode())?void 0:t.wantsRawTouch)},c={};let l=i();const a=e=>{u.forEach((t=>{const n=c[t]??(c[t]=y);var r;o.addEventListener(t,n,(r=e,t.startsWith("touch")?{passive:!r}:{passive:!1}))}))},d=()=>{u.forEach((e=>{const t=c[e];t&&o.removeEventListener(e,t)}))};a(l);const p=e.onModeChange((()=>{if("global"===t.type){const t=e.getActiveInteractionMode();o.style.cursor="global"===(null==t?void 0:t.scope)?t.cursor??"auto":"auto"}r=e.getHandlersForScope(t);const n=i();n!==l&&(d(),a(n),l=n)})),v=e.onHandlerChange((()=>{r=e.getHandlersForScope(t)})),g=e.getActiveInteractionMode(),h=e.getCurrentCursor();o.style.cursor="global"===t.type&&"global"!==(null==g?void 0:g.scope)?"auto":h;const f=e.onCursorChange((n=>{var r;"global"===t.type&&"global"!==(null==(r=e.getActiveInteractionMode())?void 0:r.scope)||(o.style.cursor=n)})),m=(e,t)=>{if(n)return n(e,t);const o=t.getBoundingClientRect();return{x:e.clientX-o.left,y:e.clientY-o.top}};function y(t){var n;if(e.isPaused())return;const i=s[t.type];if(!i||!(null==r?void 0:r[i]))return;let c,u;if(t instanceof TouchEvent&&l&&("touchmove"===t.type||"touchcancel"===t.type)&&t.preventDefault(),t instanceof TouchEvent){const e="touchend"===t.type||"touchcancel"===t.type?t.changedTouches[0]:t.touches[0];if(!e)return;c=m(e,o),u={clientX:e.clientX,clientY:e.clientY,ctrlKey:t.ctrlKey,shiftKey:t.shiftKey,altKey:t.altKey,metaKey:t.metaKey,target:t.target,currentTarget:t.currentTarget}}else{const e=t;c=m(e,o),u=e}null==(n=r[i])||n.call(r,c,u,e.getActiveMode())}return()=>{d(),p(),f(),v()}}exports.GlobalPointerProvider=({children:e,style:t,...r})=>{const c=o.useRef(null),{provides:s}=i();return o.useEffect((()=>{if(s&&c.current)return l(s,{type:"global"},c.current)}),[s]),n.jsx("div",{ref:c,style:{width:"100%",height:"100%",...t},...r,children:e})},exports.PagePointerProvider=({pageIndex:e,children:t,pageWidth:s,pageHeight:u,rotation:a,scale:d,convertEventToPoint:p,style:v,...g})=>{const h=o.useRef(null),{provides:f}=i(),m=c(),y=o.useCallback(((e,t)=>{const o=t.getBoundingClientRect(),n={x:e.clientX-o.left,y:e.clientY-o.top};return r.restorePosition({width:s,height:u},n,a,d)}),[s,u,a,d]);return o.useEffect((()=>{if(f&&h.current)return l(f,{type:"page",pageIndex:e},h.current,p||y)}),[f,e,p,y]),n.jsxs("div",{ref:h,style:{...v},...g,children:[t,m&&n.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,o,n=0)=>{null==e||e.setCursor(t,o,n)},removeCursor:t=>{null==e||e.removeCursor(t)}}},exports.useInteractionManager=function(){const{provides:e}=i(),[n,r]=o.useState(t.initialState);return o.useEffect((()=>{if(e)return e.onStateChange((e=>{r(e)}))}),[e]),{provides:e,state:n}},exports.useInteractionManagerCapability=i,exports.useInteractionManagerPlugin=()=>e.usePlugin(t.InteractionManagerPlugin.id),exports.useIsPageExclusive=c,exports.usePointerHandlers=function({modeId:e,pageIndex:t}){const{provides:o}=i();return{register:(n,r)=>{const i=(null==r?void 0:r.modeId)??e,c=(null==r?void 0:r.pageIndex)??t;return i?null==o?void 0:o.registerHandlers({modeId:i,handlers:n,pageIndex:c}):null==o?void 0:o.registerAlways({scope:void 0!==c?{type:"page",pageIndex:c}:{type:"global"},handlers:n})}}};
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core/preact"),t=require("@embedpdf/plugin-interaction-manager"),n=require("preact/hooks"),o=require("preact/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 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"},s=["pointerdown","pointerup","pointermove","pointerenter","pointerleave","pointercancel","mousedown","mouseup","mousemove","mouseenter","mouseleave","mousecancel","click","dblclick","touchstart","touchend","touchmove","touchcancel"];function u(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 u=i();const a=e=>{s.forEach((t=>{const o=l[t]??(l[t]=m);var r;n.addEventListener(t,o,(r=e,t.startsWith("touch")?{passive:!r}:{passive:!1}))}))},d=()=>{s.forEach((e=>{const t=l[e];t&&n.removeEventListener(e,t)}))};a(u);const p=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!==u&&(d(),a(o),u=o)})),g=e.onHandlerChange((()=>{r=e.getHandlersForScope(t)})),v=e.getActiveInteractionMode(),h=e.getCurrentCursor();n.style.cursor="global"===t.type&&"global"!==(null==v?void 0:v.scope)?"auto":h;const f=e.onCursorChange((o=>{var r;"global"===t.type&&"global"!==(null==(r=e.getActiveInteractionMode())?void 0:r.scope)||(n.style.cursor=o)})),y=(e,t)=>{if(o)return o(e,t);const n=t.getBoundingClientRect();return{x:e.clientX-n.left,y:e.clientY-n.top}};function m(t){var o;if(e.isPaused())return;const i=c[t.type];if(!i||!(null==r?void 0:r[i]))return;let l,s;if(t instanceof TouchEvent&&u&&("touchmove"===t.type||"touchcancel"===t.type)&&t.preventDefault(),t instanceof TouchEvent){const e="touchend"===t.type||"touchcancel"===t.type?t.changedTouches[0]:t.touches[0];if(!e)return;l=y(e,n),s={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;l=y(e,n),s={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[i])||o.call(r,l,s,e.getActiveMode())}return()=>{d(),p(),f(),g()}}exports.GlobalPointerProvider=({children:e,style:t,...r})=>{const l=n.useRef(null),{provides:c}=i();return n.useEffect((()=>{if(c&&l.current)return u(c,{type:"global"},l.current)}),[c]),o.jsx("div",{ref:l,style:{width:"100%",height:"100%",...t},...r,children:e})},exports.PagePointerProvider=({pageIndex:e,children:t,pageWidth:c,pageHeight:s,rotation:a,scale:d,convertEventToPoint:p,style:g,...v})=>{const h=n.useRef(null),{provides:f}=i(),y=l(),m=n.useCallback(((e,t)=>{const n=t.getBoundingClientRect(),o={x:e.clientX-n.left,y:e.clientY-n.top};return r.restorePosition({width:c,height:s},o,a,d)}),[c,s,a,d]);return n.useEffect((()=>{if(f&&h.current)return u(f,{type:"page",pageIndex:e},h.current,p||m)}),[f,e,p,m]),o.jsxs("div",{ref:h,style:{...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})}}};
2
2
  //# sourceMappingURL=index.cjs.map
@@ -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 PointerEventHandlers,\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} 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 allEventTypes = [...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\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\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 }\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 const handlerKey = domEventMap[evt.type];\n if (!handlerKey || !active?.[handlerKey]) return;\n\n /* preventDefault only when mode really wants raw touch */\n if (\n evt instanceof TouchEvent &&\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 (evt instanceof TouchEvent) {\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 };\n } else {\n const pe = evt as PointerEvent;\n pos = toPos(pe, element);\n normEvt = pe;\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 } 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 return restorePosition(\n { width: pageWidth, height: pageHeight },\n displayPoint,\n rotation,\n scale,\n );\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 ...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","allEventTypes","createPointerProvider","element","convertEventToPoint","active","getHandlersForScope","wantsRawTouchNow","_a","wantsRawTouch","listeners","attachedWithRawTouch","addListeners","raw","forEach","type","fn","handleEvent","addEventListener","startsWith","passive","removeListeners","removeEventListener","stopMode","style","cursor","stopHandler","onHandlerChange","initialMode","initialCursor","getCurrentCursor","stopCursor","onCursorChange","c","toPos","e","host","r","getBoundingClientRect","x","clientX","left","y","clientY","top","evt","isPaused","handlerKey","pos","normEvt","TouchEvent","preventDefault","tp","changedTouches","touches","ctrlKey","shiftKey","altKey","metaKey","target","currentTarget","pe","call","getActiveMode","children","props","ref","useRef","current","jsxRuntime","jsx","width","height","pageIndex","pageWidth","pageHeight","rotation","scale","defaultConvertEventToPoint","useCallback","event","rect","displayPoint","restorePosition","jsxs","position","right","bottom","zIndex","setCursor","token","prio","removeCursor","state","setState","initialState","onStateChange","usePlugin","modeId","register","handlers","options","finalModeId","finalPageIndex","registerHandlers","registerAlways"],"mappings":"mQAYaA,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,CCnFA,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,mBAqBTC,EAAgB,CAjBpB,cACA,YACA,cACA,eACA,eACA,gBACA,YACA,UACA,YACA,aACA,aAC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H,GAAAA,EAAU0H,aAAaF,EAAA,EAG7B,gCA3BO,WACC,MAAAxH,SAAEA,GAAaL,KACdgI,EAAOC,GAAYxH,EAAAA,SAAkCyH,EAAAA,cASrD,OAPPpH,EAAAA,WAAU,KACR,GAAKT,EACE,OAAAA,EAAS8H,eAAeH,IAC7BC,EAASD,EAAK,GACf,GACA,CAAC3H,IAEG,CACLA,WACA2H,QAEJ,gFApB2C,IACzCI,YAAoClI,EAAAA,yBAAyBC,4DAsCxD,UAA4BkI,OAAEA,EAAQzB,UAAAA,IACrC,MAAAvG,SAAEA,GAAaL,IACd,MAAA,CACLsI,SAAU,CACRC,EACAC,KAGM,MAAAC,SAAcD,WAASH,SAAUA,EACjCK,SAAiBF,WAAS5B,YAAaA,EAEtC,OAAA6B,QACHpI,WAAUsI,iBAAiB,CACzBN,OAAQI,EACRF,WACA3B,UAAW8B,UAEbrI,WAAUuI,eAAe,CACvBhI,WACqB,IAAnB8H,EACI,CAAExF,KAAM,OAAQ0D,UAAW8B,GAC3B,CAAExF,KAAM,UACdqF,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 initialState,\n InteractionManagerPlugin,\n InteractionManagerState,\n PointerEventHandlers,\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} 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 allEventTypes = [...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\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\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 }\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 const handlerKey = domEventMap[evt.type];\n if (!handlerKey || !active?.[handlerKey]) return;\n\n /* preventDefault only when mode really wants raw touch */\n if (\n evt instanceof TouchEvent &&\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 (evt instanceof TouchEvent) {\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 } 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 return restorePosition(\n { width: pageWidth, height: pageHeight },\n displayPoint,\n rotation,\n scale,\n );\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 ...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","allEventTypes","createPointerProvider","element","convertEventToPoint","active","getHandlersForScope","wantsRawTouchNow","_a","wantsRawTouch","listeners","attachedWithRawTouch","addListeners","raw","forEach","type","fn","handleEvent","addEventListener","startsWith","passive","removeListeners","removeEventListener","stopMode","style","cursor","stopHandler","onHandlerChange","initialMode","initialCursor","getCurrentCursor","stopCursor","onCursorChange","c","toPos","e","host","r","getBoundingClientRect","x","clientX","left","y","clientY","top","evt","isPaused","handlerKey","pos","normEvt","TouchEvent","preventDefault","tp","changedTouches","touches","ctrlKey","shiftKey","altKey","metaKey","target","currentTarget","setPointerCapture","releasePointerCapture","pe","_b","call","pointerId","getActiveMode","children","props","ref","useRef","current","jsxRuntime","jsx","width","height","pageIndex","pageWidth","pageHeight","rotation","scale","defaultConvertEventToPoint","useCallback","event","rect","displayPoint","restorePosition","jsxs","position","right","bottom","zIndex","setCursor","token","prio","removeCursor","state","setState","initialState","onStateChange","usePlugin","modeId","register","handlers","options","finalModeId","finalPageIndex","registerHandlers","registerAlways"],"mappings":"mQAYaA,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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MAAA,CACL0I,SAAU,CACRC,EACAC,KAGM,MAAAC,SAAcD,WAASH,SAAUA,EACjCK,SAAiBF,WAAS5B,YAAaA,EAEtC,OAAA6B,QACHxI,WAAU0I,iBAAiB,CACzBN,OAAQI,EACRF,WACA3B,UAAW8B,UAEbzI,WAAU2I,eAAe,CACvBpI,WACqB,IAAnBkI,EACI,CAAE5F,KAAM,OAAQ8D,UAAW8B,GAC3B,CAAE5F,KAAM,UACdyF,YAAA,EAIZ"}
@@ -176,12 +176,33 @@ function createPointerProvider(cap, scope, element, convertEventToPoint) {
176
176
  altKey: evt.altKey,
177
177
  metaKey: evt.metaKey,
178
178
  target: evt.target,
179
- currentTarget: evt.currentTarget
179
+ currentTarget: evt.currentTarget,
180
+ setPointerCapture: () => {
181
+ },
182
+ releasePointerCapture: () => {
183
+ }
180
184
  };
181
185
  } else {
182
186
  const pe = evt;
183
187
  pos = toPos(pe, element);
184
- normEvt = pe;
188
+ normEvt = {
189
+ clientX: pe.clientX,
190
+ clientY: pe.clientY,
191
+ ctrlKey: pe.ctrlKey,
192
+ shiftKey: pe.shiftKey,
193
+ altKey: pe.altKey,
194
+ metaKey: pe.metaKey,
195
+ target: pe.target,
196
+ currentTarget: pe.currentTarget,
197
+ setPointerCapture: () => {
198
+ var _a2, _b;
199
+ (_b = (_a2 = pe.target) == null ? void 0 : _a2.setPointerCapture) == null ? void 0 : _b.call(_a2, pe.pointerId);
200
+ },
201
+ releasePointerCapture: () => {
202
+ var _a2, _b;
203
+ (_b = (_a2 = pe.target) == null ? void 0 : _a2.releasePointerCapture) == null ? void 0 : _b.call(_a2, pe.pointerId);
204
+ }
205
+ };
185
206
  }
186
207
  (_a = active[handlerKey]) == null ? void 0 : _a.call(active, pos, normEvt, cap.getActiveMode());
187
208
  }
@@ -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 PointerEventHandlers,\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} 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 allEventTypes = [...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\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\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 }\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 const handlerKey = domEventMap[evt.type];\n if (!handlerKey || !active?.[handlerKey]) return;\n\n /* preventDefault only when mode really wants raw touch */\n if (\n evt instanceof TouchEvent &&\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 (evt instanceof TouchEvent) {\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 };\n } else {\n const pe = evt as PointerEvent;\n pos = toPos(pe, element);\n normEvt = pe;\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 } 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 return restorePosition(\n { width: pageWidth, height: pageHeight },\n displayPoint,\n rotation,\n scale,\n );\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 ...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"],"mappings":";;;;;AAUO,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,IACL;AAAA,IACA;AAAA,EACF;AACF;AAEO,SAAS,YAAY;AACpB,QAAA,EAAE,SAAS,IAAI,gCAAgC;AAC9C,SAAA;AAAA,IACL,WAAW,CAAC,OAAe,QAAgB,OAAO,MAAM;AAC5C,2CAAA,UAAU,OAAO,QAAQ;AAAA,IACrC;AAAA,IACA,cAAc,CAAC,UAAkB;AAC/B,2CAAU,aAAa;AAAA,IAAK;AAAA,EAEhC;AACF;AAOO,SAAS,mBAAmB,EAAE,QAAQ,aAAwC;AAC7E,QAAA,EAAE,SAAS,IAAI,gCAAgC;AAC9C,SAAA;AAAA,IACL,UAAU,CACR,UACA,YACG;AAEG,YAAA,eAAc,mCAAS,WAAU;AACjC,YAAA,kBAAiB,mCAAS,cAAa;AAEtC,aAAA,cACH,qCAAU,iBAAiB;AAAA,QACzB,QAAQ;AAAA,QACR;AAAA,QACA,WAAW;AAAA,MAAA,KAEb,qCAAU,eAAe;AAAA,QACvB,OACE,mBAAmB,SACf,EAAE,MAAM,QAAQ,WAAW,eAAe,IAC1C,EAAE,MAAM,SAAS;AAAA,QACvB;AAAA,MAAA;AA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AA;AAAA,IAAC;AAAA,IAAA;AAAA,MACC;AAAA,MACA,OAAO;AAAA,QACL,GAAG;AAAA,MACL;AAAA,MACC,GAAG;AAAA,MAEH,UAAA;AAAA,QAAA;AAAA,QACA,mBACE,oBAAA,OAAA,EAAI,OAAO,EAAE,UAAU,YAAY,KAAK,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,GAAG,QAAQ,KAAM,CAAA;AAAA,MAAA;AAAA,IAAA;AAAA,EAE5F;AAEJ;"}
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 PointerEventHandlers,\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} 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 allEventTypes = [...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\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\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 }\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 const handlerKey = domEventMap[evt.type];\n if (!handlerKey || !active?.[handlerKey]) return;\n\n /* preventDefault only when mode really wants raw touch */\n if (\n evt instanceof TouchEvent &&\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 (evt instanceof TouchEvent) {\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 } 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 return restorePosition(\n { width: pageWidth, height: pageHeight },\n displayPoint,\n rotation,\n scale,\n );\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 ...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":";;;;;AAUO,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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AAC;AAGlE,SAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACC;AAAA,MACA,OAAO;AAAA,QACL,GAAG;AAAA,MACL;AAAA,MACC,GAAG;AAAA,MAEH,UAAA;AAAA,QAAA;AAAA,QACA,mBACE,oBAAA,OAAA,EAAI,OAAO,EAAE,UAAU,YAAY,KAAK,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,GAAG,QAAQ,KAAM,CAAA;AAAA,MAAA;AAAA,IAAA;AAAA,EAE5F;AAEJ;"}
@@ -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"),o=require("react"),n=require("react/jsx-runtime"),r=require("@embedpdf/models"),i=()=>e.useCapability(t.InteractionManagerPlugin.id);function c(){const{provides:e}=i(),[t,n]=o.useState((()=>{const t=null==e?void 0:e.getActiveInteractionMode();return"page"===(null==t?void 0:t.scope)&&!!t.exclusive}));return o.useEffect((()=>{if(e)return e.onModeChange((()=>{const t=e.getActiveInteractionMode();n("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"},u=["pointerdown","pointerup","pointermove","pointerenter","pointerleave","pointercancel","mousedown","mouseup","mousemove","mouseenter","mouseleave","mousecancel","click","dblclick","touchstart","touchend","touchmove","touchcancel"];function l(e,t,o,n){let r=e.getHandlersForScope(t);const i=()=>{var t;return!1!==(null==(t=e.getActiveInteractionMode())?void 0:t.wantsRawTouch)},c={};let l=i();const a=e=>{u.forEach((t=>{const n=c[t]??(c[t]=y);var r;o.addEventListener(t,n,(r=e,t.startsWith("touch")?{passive:!r}:{passive:!1}))}))},d=()=>{u.forEach((e=>{const t=c[e];t&&o.removeEventListener(e,t)}))};a(l);const p=e.onModeChange((()=>{if("global"===t.type){const t=e.getActiveInteractionMode();o.style.cursor="global"===(null==t?void 0:t.scope)?t.cursor??"auto":"auto"}r=e.getHandlersForScope(t);const n=i();n!==l&&(d(),a(n),l=n)})),v=e.onHandlerChange((()=>{r=e.getHandlersForScope(t)})),g=e.getActiveInteractionMode(),h=e.getCurrentCursor();o.style.cursor="global"===t.type&&"global"!==(null==g?void 0:g.scope)?"auto":h;const f=e.onCursorChange((n=>{var r;"global"===t.type&&"global"!==(null==(r=e.getActiveInteractionMode())?void 0:r.scope)||(o.style.cursor=n)})),m=(e,t)=>{if(n)return n(e,t);const o=t.getBoundingClientRect();return{x:e.clientX-o.left,y:e.clientY-o.top}};function y(t){var n;if(e.isPaused())return;const i=s[t.type];if(!i||!(null==r?void 0:r[i]))return;let c,u;if(t instanceof TouchEvent&&l&&("touchmove"===t.type||"touchcancel"===t.type)&&t.preventDefault(),t instanceof TouchEvent){const e="touchend"===t.type||"touchcancel"===t.type?t.changedTouches[0]:t.touches[0];if(!e)return;c=m(e,o),u={clientX:e.clientX,clientY:e.clientY,ctrlKey:t.ctrlKey,shiftKey:t.shiftKey,altKey:t.altKey,metaKey:t.metaKey,target:t.target,currentTarget:t.currentTarget}}else{const e=t;c=m(e,o),u=e}null==(n=r[i])||n.call(r,c,u,e.getActiveMode())}return()=>{d(),p(),f(),v()}}exports.GlobalPointerProvider=({children:e,style:t,...r})=>{const c=o.useRef(null),{provides:s}=i();return o.useEffect((()=>{if(s&&c.current)return l(s,{type:"global"},c.current)}),[s]),n.jsx("div",{ref:c,style:{width:"100%",height:"100%",...t},...r,children:e})},exports.PagePointerProvider=({pageIndex:e,children:t,pageWidth:s,pageHeight:u,rotation:a,scale:d,convertEventToPoint:p,style:v,...g})=>{const h=o.useRef(null),{provides:f}=i(),m=c(),y=o.useCallback(((e,t)=>{const o=t.getBoundingClientRect(),n={x:e.clientX-o.left,y:e.clientY-o.top};return r.restorePosition({width:s,height:u},n,a,d)}),[s,u,a,d]);return o.useEffect((()=>{if(f&&h.current)return l(f,{type:"page",pageIndex:e},h.current,p||y)}),[f,e,p,y]),n.jsxs("div",{ref:h,style:{...v},...g,children:[t,m&&n.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,o,n=0)=>{null==e||e.setCursor(t,o,n)},removeCursor:t=>{null==e||e.removeCursor(t)}}},exports.useInteractionManager=function(){const{provides:e}=i(),[n,r]=o.useState(t.initialState);return o.useEffect((()=>{if(e)return e.onStateChange((e=>{r(e)}))}),[e]),{provides:e,state:n}},exports.useInteractionManagerCapability=i,exports.useInteractionManagerPlugin=()=>e.usePlugin(t.InteractionManagerPlugin.id),exports.useIsPageExclusive=c,exports.usePointerHandlers=function({modeId:e,pageIndex:t}){const{provides:o}=i();return{register:(n,r)=>{const i=(null==r?void 0:r.modeId)??e,c=(null==r?void 0:r.pageIndex)??t;return i?null==o?void 0:o.registerHandlers({modeId:i,handlers:n,pageIndex:c}):null==o?void 0:o.registerAlways({scope:void 0!==c?{type:"page",pageIndex:c}:{type:"global"},handlers:n})}}};
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 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"},s=["pointerdown","pointerup","pointermove","pointerenter","pointerleave","pointercancel","mousedown","mouseup","mousemove","mouseenter","mouseleave","mousecancel","click","dblclick","touchstart","touchend","touchmove","touchcancel"];function u(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 u=i();const a=e=>{s.forEach((t=>{const o=l[t]??(l[t]=m);var r;n.addEventListener(t,o,(r=e,t.startsWith("touch")?{passive:!r}:{passive:!1}))}))},d=()=>{s.forEach((e=>{const t=l[e];t&&n.removeEventListener(e,t)}))};a(u);const p=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!==u&&(d(),a(o),u=o)})),g=e.onHandlerChange((()=>{r=e.getHandlersForScope(t)})),v=e.getActiveInteractionMode(),h=e.getCurrentCursor();n.style.cursor="global"===t.type&&"global"!==(null==v?void 0:v.scope)?"auto":h;const f=e.onCursorChange((o=>{var r;"global"===t.type&&"global"!==(null==(r=e.getActiveInteractionMode())?void 0:r.scope)||(n.style.cursor=o)})),y=(e,t)=>{if(o)return o(e,t);const n=t.getBoundingClientRect();return{x:e.clientX-n.left,y:e.clientY-n.top}};function m(t){var o;if(e.isPaused())return;const i=c[t.type];if(!i||!(null==r?void 0:r[i]))return;let l,s;if(t instanceof TouchEvent&&u&&("touchmove"===t.type||"touchcancel"===t.type)&&t.preventDefault(),t instanceof TouchEvent){const e="touchend"===t.type||"touchcancel"===t.type?t.changedTouches[0]:t.touches[0];if(!e)return;l=y(e,n),s={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;l=y(e,n),s={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[i])||o.call(r,l,s,e.getActiveMode())}return()=>{d(),p(),f(),g()}}exports.GlobalPointerProvider=({children:e,style:t,...r})=>{const l=n.useRef(null),{provides:c}=i();return n.useEffect((()=>{if(c&&l.current)return u(c,{type:"global"},l.current)}),[c]),o.jsx("div",{ref:l,style:{width:"100%",height:"100%",...t},...r,children:e})},exports.PagePointerProvider=({pageIndex:e,children:t,pageWidth:c,pageHeight:s,rotation:a,scale:d,convertEventToPoint:p,style:g,...v})=>{const h=n.useRef(null),{provides:f}=i(),y=l(),m=n.useCallback(((e,t)=>{const n=t.getBoundingClientRect(),o={x:e.clientX-n.left,y:e.clientY-n.top};return r.restorePosition({width:c,height:s},o,a,d)}),[c,s,a,d]);return n.useEffect((()=>{if(f&&h.current)return u(f,{type:"page",pageIndex:e},h.current,p||m)}),[f,e,p,m]),o.jsxs("div",{ref:h,style:{...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})}}};
2
2
  //# sourceMappingURL=index.cjs.map
@@ -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 PointerEventHandlers,\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} 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 allEventTypes = [...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\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\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 }\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 const handlerKey = domEventMap[evt.type];\n if (!handlerKey || !active?.[handlerKey]) return;\n\n /* preventDefault only when mode really wants raw touch */\n if (\n evt instanceof TouchEvent &&\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 (evt instanceof TouchEvent) {\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 };\n } else {\n const pe = evt as PointerEvent;\n pos = toPos(pe, element);\n normEvt = pe;\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 } 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 return restorePosition(\n { width: pageWidth, height: pageHeight },\n displayPoint,\n rotation,\n scale,\n );\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 ...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","allEventTypes","createPointerProvider","element","convertEventToPoint","active","getHandlersForScope","wantsRawTouchNow","_a","wantsRawTouch","listeners","attachedWithRawTouch","addListeners","raw","forEach","type","fn","handleEvent","addEventListener","startsWith","passive","removeListeners","removeEventListener","stopMode","style","cursor","stopHandler","onHandlerChange","initialMode","initialCursor","getCurrentCursor","stopCursor","onCursorChange","c","toPos","e","host","r","getBoundingClientRect","x","clientX","left","y","clientY","top","evt","isPaused","handlerKey","pos","normEvt","TouchEvent","preventDefault","tp","changedTouches","touches","ctrlKey","shiftKey","altKey","metaKey","target","currentTarget","pe","call","getActiveMode","children","props","ref","useRef","current","jsxRuntime","jsx","width","height","pageIndex","pageWidth","pageHeight","rotation","scale","defaultConvertEventToPoint","useCallback","event","rect","displayPoint","restorePosition","jsxs","position","right","bottom","zIndex","setCursor","token","prio","removeCursor","state","setState","initialState","onStateChange","usePlugin","modeId","register","handlers","options","finalModeId","finalPageIndex","registerHandlers","registerAlways"],"mappings":"0PAYaA,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,CCnFA,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,mBAqBTC,EAAgB,CAjBpB,cACA,YACA,cACA,eACA,eACA,gBACA,YACA,UACA,YACA,aACA,aACA,cACA,QACA,WAGuB,aAAc,WAAY,YAAa,eAczD,SAASC,EACd/B,EACAM,EACA0B,EAC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L,KACdgI,EAAOC,GAAYxH,EAAAA,SAAkCyH,EAAAA,cASrD,OAPPpH,EAAAA,WAAU,KACR,GAAKT,EACE,OAAAA,EAAS8H,eAAeH,IAC7BC,EAASD,EAAK,GACf,GACA,CAAC3H,IAEG,CACLA,WACA2H,QAEJ,gFApB2C,IACzCI,YAAoClI,EAAAA,yBAAyBC,4DAsCxD,UAA4BkI,OAAEA,EAAQzB,UAAAA,IACrC,MAAAvG,SAAEA,GAAaL,IACd,MAAA,CACLsI,SAAU,CACRC,EACAC,KAGM,MAAAC,SAAcD,WAASH,SAAUA,EACjCK,SAAiBF,WAAS5B,YAAaA,EAEtC,OAAA6B,QACHpI,WAAUsI,iBAAiB,CACzBN,OAAQI,EACRF,WACA3B,UAAW8B,UAEbrI,WAAUuI,eAAe,CACvBhI,WACqB,IAAnB8H,EACI,CAAExF,KAAM,OAAQ0D,UAAW8B,GAC3B,CAAExF,KAAM,UACdqF,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 initialState,\n InteractionManagerPlugin,\n InteractionManagerState,\n PointerEventHandlers,\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} 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 allEventTypes = [...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\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\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 }\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 const handlerKey = domEventMap[evt.type];\n if (!handlerKey || !active?.[handlerKey]) return;\n\n /* preventDefault only when mode really wants raw touch */\n if (\n evt instanceof TouchEvent &&\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 (evt instanceof TouchEvent) {\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 } 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 return restorePosition(\n { width: pageWidth, height: pageHeight },\n displayPoint,\n rotation,\n scale,\n );\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 ...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","allEventTypes","createPointerProvider","element","convertEventToPoint","active","getHandlersForScope","wantsRawTouchNow","_a","wantsRawTouch","listeners","attachedWithRawTouch","addListeners","raw","forEach","type","fn","handleEvent","addEventListener","startsWith","passive","removeListeners","removeEventListener","stopMode","style","cursor","stopHandler","onHandlerChange","initialMode","initialCursor","getCurrentCursor","stopCursor","onCursorChange","c","toPos","e","host","r","getBoundingClientRect","x","clientX","left","y","clientY","top","evt","isPaused","handlerKey","pos","normEvt","TouchEvent","preventDefault","tp","changedTouches","touches","ctrlKey","shiftKey","altKey","metaKey","target","currentTarget","setPointerCapture","releasePointerCapture","pe","_b","call","pointerId","getActiveMode","children","props","ref","useRef","current","jsxRuntime","jsx","width","height","pageIndex","pageWidth","pageHeight","rotation","scale","defaultConvertEventToPoint","useCallback","event","rect","displayPoint","restorePosition","jsxs","position","right","bottom","zIndex","setCursor","token","prio","removeCursor","state","setState","initialState","onStateChange","usePlugin","modeId","register","handlers","options","finalModeId","finalPageIndex","registerHandlers","registerAlways"],"mappings":"0PAYaA,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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SAAiBF,WAAS5B,YAAaA,EAEtC,OAAA6B,QACHxI,WAAU0I,iBAAiB,CACzBN,OAAQI,EACRF,WACA3B,UAAW8B,UAEbzI,WAAU2I,eAAe,CACvBpI,WACqB,IAAnBkI,EACI,CAAE5F,KAAM,OAAQ8D,UAAW8B,GAC3B,CAAE5F,KAAM,UACdyF,YAAA,EAIZ"}
@@ -176,12 +176,33 @@ function createPointerProvider(cap, scope, element, convertEventToPoint) {
176
176
  altKey: evt.altKey,
177
177
  metaKey: evt.metaKey,
178
178
  target: evt.target,
179
- currentTarget: evt.currentTarget
179
+ currentTarget: evt.currentTarget,
180
+ setPointerCapture: () => {
181
+ },
182
+ releasePointerCapture: () => {
183
+ }
180
184
  };
181
185
  } else {
182
186
  const pe = evt;
183
187
  pos = toPos(pe, element);
184
- normEvt = pe;
188
+ normEvt = {
189
+ clientX: pe.clientX,
190
+ clientY: pe.clientY,
191
+ ctrlKey: pe.ctrlKey,
192
+ shiftKey: pe.shiftKey,
193
+ altKey: pe.altKey,
194
+ metaKey: pe.metaKey,
195
+ target: pe.target,
196
+ currentTarget: pe.currentTarget,
197
+ setPointerCapture: () => {
198
+ var _a2, _b;
199
+ (_b = (_a2 = pe.target) == null ? void 0 : _a2.setPointerCapture) == null ? void 0 : _b.call(_a2, pe.pointerId);
200
+ },
201
+ releasePointerCapture: () => {
202
+ var _a2, _b;
203
+ (_b = (_a2 = pe.target) == null ? void 0 : _a2.releasePointerCapture) == null ? void 0 : _b.call(_a2, pe.pointerId);
204
+ }
205
+ };
185
206
  }
186
207
  (_a = active[handlerKey]) == null ? void 0 : _a.call(active, pos, normEvt, cap.getActiveMode());
187
208
  }
@@ -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 PointerEventHandlers,\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} 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 allEventTypes = [...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\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\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 }\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 const handlerKey = domEventMap[evt.type];\n if (!handlerKey || !active?.[handlerKey]) return;\n\n /* preventDefault only when mode really wants raw touch */\n if (\n evt instanceof TouchEvent &&\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 (evt instanceof TouchEvent) {\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 };\n } else {\n const pe = evt as PointerEvent;\n pos = toPos(pe, element);\n normEvt = pe;\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 } 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 return restorePosition(\n { width: pageWidth, height: pageHeight },\n displayPoint,\n rotation,\n scale,\n );\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 ...style,\n }}\n {...props}\n >\n {children}\n {isPageExclusive && (\n <div style={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AAAA,MACL;AAAA,MACC,GAAG;AAAA,MAEH,UAAA;AAAA,QAAA;AAAA,QACA,mBACE,oBAAA,OAAA,EAAI,OAAO,EAAE,UAAU,YAAY,KAAK,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,GAAG,QAAQ,KAAM,CAAA;AAAA,MAAA;AAAA,IAAA;AAAA,EAE5F;AAEJ;"}
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 PointerEventHandlers,\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} 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 allEventTypes = [...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\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\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 }\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 const handlerKey = domEventMap[evt.type];\n if (!handlerKey || !active?.[handlerKey]) return;\n\n /* preventDefault only when mode really wants raw touch */\n if (\n evt instanceof TouchEvent &&\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 (evt instanceof TouchEvent) {\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 } 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 return restorePosition(\n { width: pageWidth, height: pageHeight },\n displayPoint,\n rotation,\n scale,\n );\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 ...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":";;;;;AAUO,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,IACL;AAAA,IACA;AAAA,EACF;AACF;AA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AA,QACL,GAAG;AAAA,MACL;AAAA,MACC,GAAG;AAAA,MAEH,UAAA;AAAA,QAAA;AAAA,QACA,mBACE,oBAAA,OAAA,EAAI,OAAO,EAAE,UAAU,YAAY,KAAK,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,GAAG,QAAQ,KAAM,CAAA;AAAA,MAAA;AAAA,IAAA;AAAA,EAE5F;AAEJ;"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),t=require("@embedpdf/core/vue"),o=require("@embedpdf/plugin-interaction-manager"),n=require("@embedpdf/models"),r={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","touchstart","touchend","touchmove","touchcancel"];function a(e,t,o,n){let a=e.getHandlersForScope(t);const i=()=>{var t;return!1!==(null==(t=e.getActiveInteractionMode())?void 0:t.wantsRawTouch)},c={};let u=i();const s=e=>{l.forEach((t=>{const n=c[t]??(c[t]=y);var r;o.addEventListener(t,n,(r=e,t.startsWith("touch")?{passive:!r}:{passive:!1}))}))},p=()=>{l.forEach((e=>{const t=c[e];t&&o.removeEventListener(e,t)}))};s(u);const v=e.onModeChange((()=>{if("global"===t.type){const t=e.getActiveInteractionMode();o.style.cursor="global"===(null==t?void 0:t.scope)?t.cursor??"auto":"auto"}a=e.getHandlersForScope(t);const n=i();n!==u&&(p(),s(n),u=n)})),d=e.onHandlerChange((()=>{a=e.getHandlersForScope(t)})),g=e.getActiveInteractionMode(),f=e.getCurrentCursor();o.style.cursor="global"===t.type&&"global"!==(null==g?void 0:g.scope)?"auto":f;const h=e.onCursorChange((n=>{var r;"global"===t.type&&"global"!==(null==(r=e.getActiveInteractionMode())?void 0:r.scope)||(o.style.cursor=n)})),m=(e,t)=>{if(n)return n(e,t);const o=t.getBoundingClientRect();return{x:e.clientX-o.left,y:e.clientY-o.top}};function y(t){var n;if(e.isPaused())return;const l=r[t.type];if(!l||!(null==a?void 0:a[l]))return;let i,c;if(t instanceof TouchEvent&&u&&("touchmove"===t.type||"touchcancel"===t.type)&&t.preventDefault(),t instanceof TouchEvent){const e="touchend"===t.type||"touchcancel"===t.type?t.changedTouches[0]:t.touches[0];if(!e)return;i=m(e,o),c={clientX:e.clientX,clientY:e.clientY,ctrlKey:t.ctrlKey,shiftKey:t.shiftKey,altKey:t.altKey,metaKey:t.metaKey,target:t.target,currentTarget:t.currentTarget}}else{const e=t;i=m(e,o),c=e}null==(n=a[l])||n.call(a,i,c,e.getActiveMode())}return()=>{p(),v(),h(),d()}}const i=()=>t.useCapability(o.InteractionManagerPlugin.id);function c(){const{provides:t}=i(),o=e.ref(!1);return e.watchEffect((e=>{if(t.value){const n=t.value.getActiveInteractionMode();o.value="page"===(null==n?void 0:n.scope)&&!!(null==n?void 0:n.exclusive);e(t.value.onModeChange((()=>{if(!t.value)return;const e=t.value.getActiveInteractionMode();o.value="page"===(null==e?void 0:e.scope)&&!!(null==e?void 0:e.exclusive)})))}})),e.readonly(o)}const u=e.defineComponent({__name:"global-pointer-provider",setup(t){const o=e.ref(null),{provides:n}=i();return e.watchEffect((e=>{if(n.value&&o.value){e(a(n.value,{type:"global"},o.value))}})),(t,n)=>(e.openBlock(),e.createElementBlock("div",{ref_key:"divRef",ref:o,style:{width:"100%",height:"100%"}},[e.renderSlot(t.$slots,"default")],512))}}),s={key:0,style:{position:"absolute",top:0,left:0,right:0,bottom:0,zIndex:10}},p=e.defineComponent({__name:"page-pointer-provider",props:{pageIndex:{},pageWidth:{},pageHeight:{},rotation:{},scale:{},convertEventToPoint:{type:Function}},setup(t){const o=t,r=e.ref(null),{provides:l}=i(),u=c(),p=e.computed((()=>(e,t)=>{const r=t.getBoundingClientRect(),l={x:e.clientX-r.left,y:e.clientY-r.top};return n.restorePosition({width:o.pageWidth,height:o.pageHeight},l,o.rotation,o.scale)}));return e.watchEffect((e=>{if(l.value&&r.value){e(a(l.value,{type:"page",pageIndex:o.pageIndex},r.value,o.convertEventToPoint||p.value))}})),(t,o)=>(e.openBlock(),e.createElementBlock("div",{ref_key:"divRef",ref:r},[e.renderSlot(t.$slots,"default"),e.unref(u)?(e.openBlock(),e.createElementBlock("div",s)):e.createCommentVNode("",!0)],512))}});exports.GlobalPointerProvider=u,exports.PagePointerProvider=p,exports.useCursor=function(){const{provides:e}=i();return{setCursor:(t,o,n=0)=>{var r;null==(r=e.value)||r.setCursor(t,o,n)},removeCursor:t=>{var o;null==(o=e.value)||o.removeCursor(t)}}},exports.useInteractionManager=function(){const{provides:t}=i(),n=e.ref(o.initialState);return e.watchEffect((e=>{if(t.value){e(t.value.onStateChange((e=>{n.value=e})))}})),{provides:t,state:e.readonly(n)}},exports.useInteractionManagerCapability=i,exports.useInteractionManagerPlugin=()=>t.usePlugin(o.InteractionManagerPlugin.id),exports.useIsPageExclusive=c,exports.usePointerHandlers=function({modeId:e,pageIndex:t}){const{provides:o}=i();return{register:(n,r)=>{const l=(null==r?void 0:r.modeId)??e,a=(null==r?void 0:r.pageIndex)??t;if(o.value)return l?o.value.registerHandlers({modeId:l,handlers:n,pageIndex:a}):o.value.registerAlways({scope:void 0!==a?{type:"page",pageIndex:a}:{type:"global"},handlers:n})}}};
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),t=require("@embedpdf/core/vue"),o=require("@embedpdf/plugin-interaction-manager"),n=require("@embedpdf/models"),r={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","touchstart","touchend","touchmove","touchcancel"];function a(e,t,o,n){let a=e.getHandlersForScope(t);const i=()=>{var t;return!1!==(null==(t=e.getActiveInteractionMode())?void 0:t.wantsRawTouch)},c={};let u=i();const s=e=>{l.forEach((t=>{const n=c[t]??(c[t]=y);var r;o.addEventListener(t,n,(r=e,t.startsWith("touch")?{passive:!r}:{passive:!1}))}))},p=()=>{l.forEach((e=>{const t=c[e];t&&o.removeEventListener(e,t)}))};s(u);const v=e.onModeChange((()=>{if("global"===t.type){const t=e.getActiveInteractionMode();o.style.cursor="global"===(null==t?void 0:t.scope)?t.cursor??"auto":"auto"}a=e.getHandlersForScope(t);const n=i();n!==u&&(p(),s(n),u=n)})),d=e.onHandlerChange((()=>{a=e.getHandlersForScope(t)})),g=e.getActiveInteractionMode(),f=e.getCurrentCursor();o.style.cursor="global"===t.type&&"global"!==(null==g?void 0:g.scope)?"auto":f;const h=e.onCursorChange((n=>{var r;"global"===t.type&&"global"!==(null==(r=e.getActiveInteractionMode())?void 0:r.scope)||(o.style.cursor=n)})),m=(e,t)=>{if(n)return n(e,t);const o=t.getBoundingClientRect();return{x:e.clientX-o.left,y:e.clientY-o.top}};function y(t){var n;if(e.isPaused())return;const l=r[t.type];if(!l||!(null==a?void 0:a[l]))return;let i,c;if(t instanceof TouchEvent&&u&&("touchmove"===t.type||"touchcancel"===t.type)&&t.preventDefault(),t instanceof TouchEvent){const e="touchend"===t.type||"touchcancel"===t.type?t.changedTouches[0]:t.touches[0];if(!e)return;i=m(e,o),c={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;i=m(e,o),c={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,o;null==(o=null==(t=e.target)?void 0:t.setPointerCapture)||o.call(t,e.pointerId)},releasePointerCapture:()=>{var t,o;null==(o=null==(t=e.target)?void 0:t.releasePointerCapture)||o.call(t,e.pointerId)}}}null==(n=a[l])||n.call(a,i,c,e.getActiveMode())}return()=>{p(),v(),h(),d()}}const i=()=>t.useCapability(o.InteractionManagerPlugin.id);function c(){const{provides:t}=i(),o=e.ref(!1);return e.watchEffect((e=>{if(t.value){const n=t.value.getActiveInteractionMode();o.value="page"===(null==n?void 0:n.scope)&&!!(null==n?void 0:n.exclusive);e(t.value.onModeChange((()=>{if(!t.value)return;const e=t.value.getActiveInteractionMode();o.value="page"===(null==e?void 0:e.scope)&&!!(null==e?void 0:e.exclusive)})))}})),e.readonly(o)}const u=e.defineComponent({__name:"global-pointer-provider",setup(t){const o=e.ref(null),{provides:n}=i();return e.watchEffect((e=>{if(n.value&&o.value){e(a(n.value,{type:"global"},o.value))}})),(t,n)=>(e.openBlock(),e.createElementBlock("div",{ref_key:"divRef",ref:o,style:{width:"100%",height:"100%"}},[e.renderSlot(t.$slots,"default")],512))}}),s={key:0,style:{position:"absolute",top:0,left:0,right:0,bottom:0,zIndex:10}},p=e.defineComponent({__name:"page-pointer-provider",props:{pageIndex:{},pageWidth:{},pageHeight:{},rotation:{},scale:{},convertEventToPoint:{type:Function}},setup(t){const o=t,r=e.ref(null),{provides:l}=i(),u=c(),p=e.computed((()=>(e,t)=>{const r=t.getBoundingClientRect(),l={x:e.clientX-r.left,y:e.clientY-r.top};return n.restorePosition({width:o.pageWidth,height:o.pageHeight},l,o.rotation,o.scale)}));return e.watchEffect((e=>{if(l.value&&r.value){e(a(l.value,{type:"page",pageIndex:o.pageIndex},r.value,o.convertEventToPoint||p.value))}})),(t,o)=>(e.openBlock(),e.createElementBlock("div",{ref_key:"divRef",ref:r},[e.renderSlot(t.$slots,"default"),e.unref(u)?(e.openBlock(),e.createElementBlock("div",s)):e.createCommentVNode("",!0)],512))}});exports.GlobalPointerProvider=u,exports.PagePointerProvider=p,exports.useCursor=function(){const{provides:e}=i();return{setCursor:(t,o,n=0)=>{var r;null==(r=e.value)||r.setCursor(t,o,n)},removeCursor:t=>{var o;null==(o=e.value)||o.removeCursor(t)}}},exports.useInteractionManager=function(){const{provides:t}=i(),n=e.ref(o.initialState);return e.watchEffect((e=>{if(t.value){e(t.value.onStateChange((e=>{n.value=e})))}})),{provides:t,state:e.readonly(n)}},exports.useInteractionManagerCapability=i,exports.useInteractionManagerPlugin=()=>t.usePlugin(o.InteractionManagerPlugin.id),exports.useIsPageExclusive=c,exports.usePointerHandlers=function({modeId:e,pageIndex:t}){const{provides:o}=i();return{register:(n,r)=>{const l=(null==r?void 0:r.modeId)??e,a=(null==r?void 0:r.pageIndex)??t;if(o.value)return l?o.value.registerHandlers({modeId:l,handlers:n,pageIndex:a}):o.value.registerAlways({scope:void 0!==a?{type:"page",pageIndex:a}:{type:"global"},handlers:n})}}};
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../../src/shared/utils.ts","../../src/vue/hooks/use-interaction-manager.ts","../../src/vue/components/global-pointer-provider.vue","../../src/vue/components/page-pointer-provider.vue"],"sourcesContent":["import { Position } from '@embedpdf/models';\nimport type {\n InteractionManagerCapability,\n InteractionScope,\n PointerEventHandlers,\n EmbedPdfPointerEvent,\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 allEventTypes = [...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\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\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 }\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 const handlerKey = domEventMap[evt.type];\n if (!handlerKey || !active?.[handlerKey]) return;\n\n /* preventDefault only when mode really wants raw touch */\n if (\n evt instanceof TouchEvent &&\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 (evt instanceof TouchEvent) {\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 };\n } else {\n const pe = evt as PointerEvent;\n pos = toPos(pe, element);\n normEvt = pe;\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 { useCapability, usePlugin } from '@embedpdf/core/vue';\nimport {\n initialState,\n InteractionManagerPlugin,\n InteractionManagerState,\n PointerEventHandlersWithLifecycle,\n} from '@embedpdf/plugin-interaction-manager';\nimport { ref, watchEffect, readonly } from 'vue';\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 = ref<InteractionManagerState>(initialState);\n\n watchEffect((onCleanup) => {\n if (provides.value) {\n // onStateChange is a BehaviorEmitter, so it emits the current state upon subscription\n const unsubscribe = provides.value.onStateChange((newState) => {\n state.value = newState;\n });\n onCleanup(unsubscribe);\n }\n });\n\n return {\n provides,\n state: readonly(state),\n };\n}\n\nexport function useCursor() {\n const { provides } = useInteractionManagerCapability();\n return {\n setCursor: (token: string, cursor: string, prio = 0) => {\n provides.value?.setCursor(token, cursor, prio);\n },\n removeCursor: (token: string) => {\n provides.value?.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 if (!provides.value) return;\n\n return finalModeId\n ? provides.value.registerHandlers({\n modeId: finalModeId,\n handlers,\n pageIndex: finalPageIndex,\n })\n : provides.value.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 const isPageExclusive = ref<boolean>(false);\n\n watchEffect((onCleanup) => {\n if (cap.value) {\n const mode = cap.value.getActiveInteractionMode();\n isPageExclusive.value = mode?.scope === 'page' && !!mode?.exclusive;\n\n const unsubscribe = cap.value.onModeChange(() => {\n if (!cap.value) return;\n const newMode = cap.value.getActiveInteractionMode();\n isPageExclusive.value = newMode?.scope === 'page' && !!newMode?.exclusive;\n });\n onCleanup(unsubscribe);\n }\n });\n\n return readonly(isPageExclusive);\n}\n","<script setup lang=\"ts\">\nimport { ref, watchEffect } from 'vue';\nimport { createPointerProvider } from '../../shared/utils';\nimport { useInteractionManagerCapability } from '../hooks';\n\nconst divRef = ref<HTMLDivElement | null>(null);\nconst { provides: cap } = useInteractionManagerCapability();\n\n// watchEffect automatically handles setup and teardown when capability or element is ready\nwatchEffect((onCleanup) => {\n if (cap.value && divRef.value) {\n const cleanup = createPointerProvider(cap.value, { type: 'global' }, divRef.value);\n onCleanup(cleanup);\n }\n});\n</script>\n\n<template>\n <div\n ref=\"divRef\"\n :style=\"{\n width: '100%',\n height: '100%',\n }\"\n >\n <slot />\n </div>\n</template>\n","<script setup lang=\"ts\">\nimport { ref, watchEffect, computed, StyleValue } from 'vue';\nimport { Position, restorePosition } from '@embedpdf/models';\nimport { createPointerProvider } from '../../shared/utils';\nimport { useInteractionManagerCapability, useIsPageExclusive } from '../hooks';\n\ninterface Props {\n pageIndex: number;\n pageWidth: number;\n pageHeight: number;\n rotation: number;\n scale: number;\n convertEventToPoint?: (event: PointerEvent, element: HTMLElement) => Position;\n}\n\nconst props = defineProps<Props>();\n\nconst divRef = ref<HTMLDivElement | null>(null);\nconst { provides: cap } = useInteractionManagerCapability();\nconst isPageExclusive = useIsPageExclusive();\n\nconst defaultConvertEventToPoint = computed(() => {\n return (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 return restorePosition(\n { width: props.pageWidth, height: props.pageHeight },\n displayPoint,\n props.rotation,\n props.scale,\n );\n };\n});\n\nwatchEffect((onCleanup) => {\n if (cap.value && divRef.value) {\n const cleanup = createPointerProvider(\n cap.value,\n { type: 'page', pageIndex: props.pageIndex },\n divRef.value,\n props.convertEventToPoint || defaultConvertEventToPoint.value,\n );\n onCleanup(cleanup);\n }\n});\n</script>\n\n<template>\n <div ref=\"divRef\">\n <slot />\n <div\n v-if=\"isPageExclusive\"\n :style=\"{ position: 'absolute', top: 0, left: 0, right: 0, bottom: 0, zIndex: 10 }\"\n />\n </div>\n</template>\n"],"names":["domEventMap","pointerdown","pointerup","pointermove","pointerenter","pointerleave","pointercancel","mousedown","mouseup","mousemove","mouseenter","mouseleave","mousecancel","click","dblclick","touchstart","touchend","touchmove","touchcancel","allEventTypes","createPointerProvider","cap","scope","element","convertEventToPoint","active","getHandlersForScope","wantsRawTouchNow","_a","getActiveInteractionMode","wantsRawTouch","listeners","attachedWithRawTouch","addListeners","raw","forEach","type","fn","handleEvent","addEventListener","startsWith","passive","removeListeners","removeEventListener","stopMode","onModeChange","mode","style","cursor","stopHandler","onHandlerChange","initialMode","initialCursor","getCurrentCursor","stopCursor","onCursorChange","c","toPos","e","host","r","getBoundingClientRect","x","clientX","left","y","clientY","top","evt","isPaused","handlerKey","pos","normEvt","TouchEvent","preventDefault","tp","changedTouches","touches","ctrlKey","shiftKey","altKey","metaKey","target","currentTarget","pe","call","getActiveMode","useInteractionManagerCapability","useCapability","InteractionManagerPlugin","id","useIsPageExclusive","provides","isPageExclusive","ref","readonly","vue$1","watchEffect","onCleanup","value","exclusive","newMode","divRef","_createElementBlock","createElementBlock","_renderSlot","_ctx","$slots","props","__props","defaultConvertEventToPoint","computed","event","rect","displayPoint","restorePosition","width","pageWidth","height","pageHeight","rotation","scale","pageIndex","_unref","_openBlock","_hoisted_1","setCursor","token","prio","removeCursor","state","initialState","onStateChange","newState","usePlugin","modeId","register","handlers","options","finalModeId","finalPageIndex","registerHandlers","registerAlways"],"mappings":"uNAYMA,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,mBAqBTC,EAAgB,CAjBpB,cACA,YACA,cACA,eACA,eACA,gBACA,YACA,UACA,YACA,aACA,aACA,cACA,QACA,WAGuB,aAAc,WAAY,YAAa,eAczD,SAASC,EACdC,EACAC,EACAC,EACAC,GAGI,IAAAC,EAAsCJ,EAAIK,oBAAoBJ,GAGlE,MAAMK,EAAmB,WAAU,OAA8C,KAAl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AA,WAEAgB,QAAe9B,IADvB+B,EAAAA,YAAArB,EAAAA,mBAGE,MAHFsB,0HFnBG,WACC,MAAAjC,SAAEA,GAAaL,IACd,MAAA,CACLuC,UAAW,CAACC,EAAe/E,EAAgBgF,EAAO,WAChD,OAAApG,EAAAgE,EAASO,QAATvE,EAAgBkG,UAAUC,EAAO/E,EAAQgF,EAAA,EAE3CC,aAAeF,UACJ,OAAAnG,EAAAgE,EAAAO,UAAO8B,aAAaF,EAAA,EAGnC,gCA9BO,WACC,MAAAnC,SAAEA,GAAaL,IACf2C,EAAQpC,MAA6BqC,gBAYpC,OAVPnC,EAAAC,aAAaC,IACX,GAAIN,EAASO,MAAO,CAKlBD,EAHoBN,EAASO,MAAMiC,eAAeC,IAChDH,EAAM/B,MAAQkC,CAAA,IAEK,KAIlB,CACLzC,WACAsC,MAAOnC,WAASmC,GAEpB,gFAvB2C,IACzCI,YAAoC7C,EAAAA,yBAAyBC,4DAyCxD,UAA4B6C,OAAEA,EAAQb,UAAAA,IACrC,MAAA9B,SAAEA,GAAaL,IACd,MAAA,CACLiD,SAAU,CACRC,EACAC,KAGM,MAAAC,SAAcD,WAASH,SAAUA,EACjCK,SAAiBF,WAAShB,YAAaA,EAEzC,GAAC9B,EAASO,MAEP,OAAAwC,EACH/C,EAASO,MAAM0C,iBAAiB,CAC9BN,OAAQI,EACRF,WACAf,UAAWkB,IAEbhD,EAASO,MAAM2C,eAAe,CAC5BxH,WACqB,IAAnBsH,EACI,CAAExG,KAAM,OAAQsF,UAAWkB,GAC3B,CAAExG,KAAM,UACdqG,YACD,EAGX"}
1
+ {"version":3,"file":"index.cjs","sources":["../../src/shared/utils.ts","../../src/vue/hooks/use-interaction-manager.ts","../../src/vue/components/global-pointer-provider.vue","../../src/vue/components/page-pointer-provider.vue"],"sourcesContent":["import { Position } from '@embedpdf/models';\nimport type {\n InteractionManagerCapability,\n InteractionScope,\n PointerEventHandlers,\n EmbedPdfPointerEvent,\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 allEventTypes = [...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\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\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 }\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 const handlerKey = domEventMap[evt.type];\n if (!handlerKey || !active?.[handlerKey]) return;\n\n /* preventDefault only when mode really wants raw touch */\n if (\n evt instanceof TouchEvent &&\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 (evt instanceof TouchEvent) {\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 { useCapability, usePlugin } from '@embedpdf/core/vue';\nimport {\n initialState,\n InteractionManagerPlugin,\n InteractionManagerState,\n PointerEventHandlersWithLifecycle,\n} from '@embedpdf/plugin-interaction-manager';\nimport { ref, watchEffect, readonly } from 'vue';\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 = ref<InteractionManagerState>(initialState);\n\n watchEffect((onCleanup) => {\n if (provides.value) {\n // onStateChange is a BehaviorEmitter, so it emits the current state upon subscription\n const unsubscribe = provides.value.onStateChange((newState) => {\n state.value = newState;\n });\n onCleanup(unsubscribe);\n }\n });\n\n return {\n provides,\n state: readonly(state),\n };\n}\n\nexport function useCursor() {\n const { provides } = useInteractionManagerCapability();\n return {\n setCursor: (token: string, cursor: string, prio = 0) => {\n provides.value?.setCursor(token, cursor, prio);\n },\n removeCursor: (token: string) => {\n provides.value?.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 if (!provides.value) return;\n\n return finalModeId\n ? provides.value.registerHandlers({\n modeId: finalModeId,\n handlers,\n pageIndex: finalPageIndex,\n })\n : provides.value.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 const isPageExclusive = ref<boolean>(false);\n\n watchEffect((onCleanup) => {\n if (cap.value) {\n const mode = cap.value.getActiveInteractionMode();\n isPageExclusive.value = mode?.scope === 'page' && !!mode?.exclusive;\n\n const unsubscribe = cap.value.onModeChange(() => {\n if (!cap.value) return;\n const newMode = cap.value.getActiveInteractionMode();\n isPageExclusive.value = newMode?.scope === 'page' && !!newMode?.exclusive;\n });\n onCleanup(unsubscribe);\n }\n });\n\n return readonly(isPageExclusive);\n}\n","<script setup lang=\"ts\">\nimport { ref, watchEffect } from 'vue';\nimport { createPointerProvider } from '../../shared/utils';\nimport { useInteractionManagerCapability } from '../hooks';\n\nconst divRef = ref<HTMLDivElement | null>(null);\nconst { provides: cap } = useInteractionManagerCapability();\n\n// watchEffect automatically handles setup and teardown when capability or element is ready\nwatchEffect((onCleanup) => {\n if (cap.value && divRef.value) {\n const cleanup = createPointerProvider(cap.value, { type: 'global' }, divRef.value);\n onCleanup(cleanup);\n }\n});\n</script>\n\n<template>\n <div\n ref=\"divRef\"\n :style=\"{\n width: '100%',\n height: '100%',\n }\"\n >\n <slot />\n </div>\n</template>\n","<script setup lang=\"ts\">\nimport { ref, watchEffect, computed, StyleValue } from 'vue';\nimport { Position, restorePosition } from '@embedpdf/models';\nimport { createPointerProvider } from '../../shared/utils';\nimport { useInteractionManagerCapability, useIsPageExclusive } from '../hooks';\n\ninterface Props {\n pageIndex: number;\n pageWidth: number;\n pageHeight: number;\n rotation: number;\n scale: number;\n convertEventToPoint?: (event: PointerEvent, element: HTMLElement) => Position;\n}\n\nconst props = defineProps<Props>();\n\nconst divRef = ref<HTMLDivElement | null>(null);\nconst { provides: cap } = useInteractionManagerCapability();\nconst isPageExclusive = useIsPageExclusive();\n\nconst defaultConvertEventToPoint = computed(() => {\n return (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 return restorePosition(\n { width: props.pageWidth, height: props.pageHeight },\n displayPoint,\n props.rotation,\n props.scale,\n );\n };\n});\n\nwatchEffect((onCleanup) => {\n if (cap.value && divRef.value) {\n const cleanup = createPointerProvider(\n cap.value,\n { type: 'page', pageIndex: props.pageIndex },\n divRef.value,\n props.convertEventToPoint || defaultConvertEventToPoint.value,\n );\n onCleanup(cleanup);\n }\n});\n</script>\n\n<template>\n <div ref=\"divRef\">\n <slot />\n <div\n v-if=\"isPageExclusive\"\n :style=\"{ position: 'absolute', top: 0, left: 0, right: 0, bottom: 0, zIndex: 10 }\"\n />\n </div>\n</template>\n"],"names":["domEventMap","pointerdown","pointerup","pointermove","pointerenter","pointerleave","pointercancel","mousedown","mouseup","mousemove","mouseenter","mouseleave","mousecancel","click","dblclick","touchstart","touchend","touchmove","touchcancel","allEventTypes","createPointerProvider","cap","scope","element","convertEventToPoint","active","getHandlersForScope","wantsRawTouchNow","_a","getActiveInteractionMode","wantsRawTouch","listeners","attachedWithRawTouch","addListeners","raw","forEach","type","fn","handleEvent","addEventListener","startsWith","passive","removeListeners","removeEventListener","stopMode","onModeChange","mode","style","cursor","stopHandler","onHandlerChange","initialMode","initialCursor","getCurrentCursor","stopCursor","onCursorChange","c","toPos","e","host","r","getBoundingClientRect","x","clientX","left","y","clientY","top","evt","isPaused","handlerKey","pos","normEvt","TouchEvent","preventDefault","tp","changedTouches","touches","ctrlKey","shiftKey","altKey","metaKey","target","currentTarget","setPointerCapture","releasePointerCapture","pe","_b","call","pointerId","getActiveMode","useInteractionManagerCapability","useCapability","InteractionManagerPlugin","id","useIsPageExclusive","provides","isPageExclusive","ref","readonly","vue$1","watchEffect","onCleanup","value","exclusive","newMode","divRef","_createElementBlock","createElementBlock","_renderSlot","_ctx","$slots","props","__props","defaultConvertEventToPoint","computed","event","rect","displayPoint","restorePosition","width","pageWidth","height","pageHeight","rotation","scale","pageIndex","_unref","_openBlock","_hoisted_1","setCursor","token","prio","removeCursor","state","initialState","onStateChange","newState","usePlugin","modeId","register","handlers","options","finalModeId","finalPageIndex","registerHandlers","registerAlways"],"mappings":"uNAYMA,EAAiC,CACrCC,YAAa,gBACbC,UAAW,cACXC,YAAa,gBACbC,aAAc,iBACdC,aAAc,iBACdC,cAAe,kBAEfC,UAAW,cACXC,QAAS,YACTC,U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MAAO,CAKlBD,EAHoBN,EAASO,MAAMiC,eAAeC,IAChDH,EAAM/B,MAAQkC,CAAA,IAEK,KAIlB,CACLzC,WACAsC,MAAOnC,WAASmC,GAEpB,gFAvB2C,IACzCI,YAAoC7C,EAAAA,yBAAyBC,4DAyCxD,UAA4B6C,OAAEA,EAAQb,UAAAA,IACrC,MAAA9B,SAAEA,GAAaL,IACd,MAAA,CACLiD,SAAU,CACRC,EACAC,KAGM,MAAAC,SAAcD,WAASH,SAAUA,EACjCK,SAAiBF,WAAShB,YAAaA,EAEzC,GAAC9B,EAASO,MAEP,OAAAwC,EACH/C,EAASO,MAAM0C,iBAAiB,CAC9BN,OAAQI,EACRF,WACAf,UAAWkB,IAEbhD,EAASO,MAAM2C,eAAe,CAC5B5H,WACqB,IAAnB0H,EACI,CAAE5G,KAAM,OAAQ0F,UAAWkB,GAC3B,CAAE5G,KAAM,UACdyG,YACD,EAGX"}
package/dist/vue/index.js CHANGED
@@ -116,12 +116,33 @@ function createPointerProvider(cap, scope, element, convertEventToPoint) {
116
116
  altKey: evt.altKey,
117
117
  metaKey: evt.metaKey,
118
118
  target: evt.target,
119
- currentTarget: evt.currentTarget
119
+ currentTarget: evt.currentTarget,
120
+ setPointerCapture: () => {
121
+ },
122
+ releasePointerCapture: () => {
123
+ }
120
124
  };
121
125
  } else {
122
126
  const pe = evt;
123
127
  pos = toPos(pe, element);
124
- normEvt = pe;
128
+ normEvt = {
129
+ clientX: pe.clientX,
130
+ clientY: pe.clientY,
131
+ ctrlKey: pe.ctrlKey,
132
+ shiftKey: pe.shiftKey,
133
+ altKey: pe.altKey,
134
+ metaKey: pe.metaKey,
135
+ target: pe.target,
136
+ currentTarget: pe.currentTarget,
137
+ setPointerCapture: () => {
138
+ var _a2, _b;
139
+ (_b = (_a2 = pe.target) == null ? void 0 : _a2.setPointerCapture) == null ? void 0 : _b.call(_a2, pe.pointerId);
140
+ },
141
+ releasePointerCapture: () => {
142
+ var _a2, _b;
143
+ (_b = (_a2 = pe.target) == null ? void 0 : _a2.releasePointerCapture) == null ? void 0 : _b.call(_a2, pe.pointerId);
144
+ }
145
+ };
125
146
  }
126
147
  (_a = active[handlerKey]) == null ? void 0 : _a.call(active, pos, normEvt, cap.getActiveMode());
127
148
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/shared/utils.ts","../../src/vue/hooks/use-interaction-manager.ts","../../src/vue/components/global-pointer-provider.vue","../../src/vue/components/page-pointer-provider.vue"],"sourcesContent":["import { Position } from '@embedpdf/models';\nimport type {\n InteractionManagerCapability,\n InteractionScope,\n PointerEventHandlers,\n EmbedPdfPointerEvent,\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 allEventTypes = [...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\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\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 }\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 const handlerKey = domEventMap[evt.type];\n if (!handlerKey || !active?.[handlerKey]) return;\n\n /* preventDefault only when mode really wants raw touch */\n if (\n evt instanceof TouchEvent &&\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 (evt instanceof TouchEvent) {\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 };\n } else {\n const pe = evt as PointerEvent;\n pos = toPos(pe, element);\n normEvt = pe;\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 { useCapability, usePlugin } from '@embedpdf/core/vue';\nimport {\n initialState,\n InteractionManagerPlugin,\n InteractionManagerState,\n PointerEventHandlersWithLifecycle,\n} from '@embedpdf/plugin-interaction-manager';\nimport { ref, watchEffect, readonly } from 'vue';\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 = ref<InteractionManagerState>(initialState);\n\n watchEffect((onCleanup) => {\n if (provides.value) {\n // onStateChange is a BehaviorEmitter, so it emits the current state upon subscription\n const unsubscribe = provides.value.onStateChange((newState) => {\n state.value = newState;\n });\n onCleanup(unsubscribe);\n }\n });\n\n return {\n provides,\n state: readonly(state),\n };\n}\n\nexport function useCursor() {\n const { provides } = useInteractionManagerCapability();\n return {\n setCursor: (token: string, cursor: string, prio = 0) => {\n provides.value?.setCursor(token, cursor, prio);\n },\n removeCursor: (token: string) => {\n provides.value?.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 if (!provides.value) return;\n\n return finalModeId\n ? provides.value.registerHandlers({\n modeId: finalModeId,\n handlers,\n pageIndex: finalPageIndex,\n })\n : provides.value.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 const isPageExclusive = ref<boolean>(false);\n\n watchEffect((onCleanup) => {\n if (cap.value) {\n const mode = cap.value.getActiveInteractionMode();\n isPageExclusive.value = mode?.scope === 'page' && !!mode?.exclusive;\n\n const unsubscribe = cap.value.onModeChange(() => {\n if (!cap.value) return;\n const newMode = cap.value.getActiveInteractionMode();\n isPageExclusive.value = newMode?.scope === 'page' && !!newMode?.exclusive;\n });\n onCleanup(unsubscribe);\n }\n });\n\n return readonly(isPageExclusive);\n}\n","<script setup lang=\"ts\">\nimport { ref, watchEffect } from 'vue';\nimport { createPointerProvider } from '../../shared/utils';\nimport { useInteractionManagerCapability } from '../hooks';\n\nconst divRef = ref<HTMLDivElement | null>(null);\nconst { provides: cap } = useInteractionManagerCapability();\n\n// watchEffect automatically handles setup and teardown when capability or element is ready\nwatchEffect((onCleanup) => {\n if (cap.value && divRef.value) {\n const cleanup = createPointerProvider(cap.value, { type: 'global' }, divRef.value);\n onCleanup(cleanup);\n }\n});\n</script>\n\n<template>\n <div\n ref=\"divRef\"\n :style=\"{\n width: '100%',\n height: '100%',\n }\"\n >\n <slot />\n </div>\n</template>\n","<script setup lang=\"ts\">\nimport { ref, watchEffect, computed, StyleValue } from 'vue';\nimport { Position, restorePosition } from '@embedpdf/models';\nimport { createPointerProvider } from '../../shared/utils';\nimport { useInteractionManagerCapability, useIsPageExclusive } from '../hooks';\n\ninterface Props {\n pageIndex: number;\n pageWidth: number;\n pageHeight: number;\n rotation: number;\n scale: number;\n convertEventToPoint?: (event: PointerEvent, element: HTMLElement) => Position;\n}\n\nconst props = defineProps<Props>();\n\nconst divRef = ref<HTMLDivElement | null>(null);\nconst { provides: cap } = useInteractionManagerCapability();\nconst isPageExclusive = useIsPageExclusive();\n\nconst defaultConvertEventToPoint = computed(() => {\n return (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 return restorePosition(\n { width: props.pageWidth, height: props.pageHeight },\n displayPoint,\n props.rotation,\n props.scale,\n );\n };\n});\n\nwatchEffect((onCleanup) => {\n if (cap.value && divRef.value) {\n const cleanup = createPointerProvider(\n cap.value,\n { type: 'page', pageIndex: props.pageIndex },\n divRef.value,\n props.convertEventToPoint || defaultConvertEventToPoint.value,\n );\n onCleanup(cleanup);\n }\n});\n</script>\n\n<template>\n <div ref=\"divRef\">\n <slot />\n <div\n v-if=\"isPageExclusive\"\n :style=\"{ position: 'absolute', top: 0, left: 0, right: 0, bottom: 0, zIndex: 10 }\"\n />\n </div>\n</template>\n"],"names":["_createElementBlock","_renderSlot","_unref","_openBlock"],"mappings":";;;;AAYA,MAAM,cAAiC;AAAA,EACrC,aAAa;AAAA,EACb,WAAW;AAAA,EACX,aAAa;AAAA,EACb,cAAc;AAAA,EACd,cAAc;AAAA,EACd,eAAe;AAAA,EAEf,WAAW;AAAA,EACX,SAAS;AAAA,EACT,WAAW;AAAA,EACX,YAAY;AAAA,EACZ,YAAY;AAAA,EACZ,aAAa;AAAA,EAEb,OAAO;AAAA,EACP,UAAU;AAAA;AAAA,EAGV,YAAY;AAAA,EACZ,UAAU;AAAA,EACV,WAAW;AAAA,EACX,aAAa;AACf;AAEA,MAAM,oBAAoB;AAAA,EACxB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEA,MAAM,kBAAkB,CAAC,cAAc,YAAY,aAAa,aAAa;AAC7E,MAAM,gBAAgB,CAAC,GAAG,mBAAmB,GAAG,eAAe;AAK/D,SAAS,aAAa,WAAmB,eAAiD;AAEjF,SAAA,UAAU,WAAW,OAAO,IAAI,EAAE,SAAS,CAAC,cAAc,IAAI,EAAE,SAAS,MAAM;AACxF;AAKO,SAAS,sBACd,KACA,OACA,SACA,qBACA;AAEI,MAAA,SAAsC,IAAI,oBAAoB,KAAK;AAGvE,QAAM,mBAAmB,MAAM;;AAAA,sBAAI,+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cAAM,UAAU;AAAA,UACd,IAAI;AAAA,UACJ,EAAE,MAAM,QAAQ,WAAW,MAAM,UAAU;AAAA,UAC3C,OAAO;AAAA,UACP,MAAM,uBAAuB,2BAA2B;AAAA,QAC1D;AACA,kBAAU,OAAO;AAAA,MAAA;AAAA,IACnB,CACD;;0BAICD,mBAMM,OAAA;AAAA,iBANG;AAAA,QAAJ,KAAI;AAAA,MAAA;QACPC,WAAQ,KAAA,QAAA,SAAA;AAAA,QAEAC,MAAe,eAAA,KADvBC,aAAAH,mBAGE,OAHF,UAGE;;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../../src/shared/utils.ts","../../src/vue/hooks/use-interaction-manager.ts","../../src/vue/components/global-pointer-provider.vue","../../src/vue/components/page-pointer-provider.vue"],"sourcesContent":["import { Position } from '@embedpdf/models';\nimport type {\n InteractionManagerCapability,\n InteractionScope,\n PointerEventHandlers,\n EmbedPdfPointerEvent,\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 allEventTypes = [...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\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\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 }\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 const handlerKey = domEventMap[evt.type];\n if (!handlerKey || !active?.[handlerKey]) return;\n\n /* preventDefault only when mode really wants raw touch */\n if (\n evt instanceof TouchEvent &&\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 (evt instanceof TouchEvent) {\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 { useCapability, usePlugin } from '@embedpdf/core/vue';\nimport {\n initialState,\n InteractionManagerPlugin,\n InteractionManagerState,\n PointerEventHandlersWithLifecycle,\n} from '@embedpdf/plugin-interaction-manager';\nimport { ref, watchEffect, readonly } from 'vue';\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 = ref<InteractionManagerState>(initialState);\n\n watchEffect((onCleanup) => {\n if (provides.value) {\n // onStateChange is a BehaviorEmitter, so it emits the current state upon subscription\n const unsubscribe = provides.value.onStateChange((newState) => {\n state.value = newState;\n });\n onCleanup(unsubscribe);\n }\n });\n\n return {\n provides,\n state: readonly(state),\n };\n}\n\nexport function useCursor() {\n const { provides } = useInteractionManagerCapability();\n return {\n setCursor: (token: string, cursor: string, prio = 0) => {\n provides.value?.setCursor(token, cursor, prio);\n },\n removeCursor: (token: string) => {\n provides.value?.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 if (!provides.value) return;\n\n return finalModeId\n ? provides.value.registerHandlers({\n modeId: finalModeId,\n handlers,\n pageIndex: finalPageIndex,\n })\n : provides.value.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 const isPageExclusive = ref<boolean>(false);\n\n watchEffect((onCleanup) => {\n if (cap.value) {\n const mode = cap.value.getActiveInteractionMode();\n isPageExclusive.value = mode?.scope === 'page' && !!mode?.exclusive;\n\n const unsubscribe = cap.value.onModeChange(() => {\n if (!cap.value) return;\n const newMode = cap.value.getActiveInteractionMode();\n isPageExclusive.value = newMode?.scope === 'page' && !!newMode?.exclusive;\n });\n onCleanup(unsubscribe);\n }\n });\n\n return readonly(isPageExclusive);\n}\n","<script setup lang=\"ts\">\nimport { ref, watchEffect } from 'vue';\nimport { createPointerProvider } from '../../shared/utils';\nimport { useInteractionManagerCapability } from '../hooks';\n\nconst divRef = ref<HTMLDivElement | null>(null);\nconst { provides: cap } = useInteractionManagerCapability();\n\n// watchEffect automatically handles setup and teardown when capability or element is ready\nwatchEffect((onCleanup) => {\n if (cap.value && divRef.value) {\n const cleanup = createPointerProvider(cap.value, { type: 'global' }, divRef.value);\n onCleanup(cleanup);\n }\n});\n</script>\n\n<template>\n <div\n ref=\"divRef\"\n :style=\"{\n width: '100%',\n height: '100%',\n }\"\n >\n <slot />\n </div>\n</template>\n","<script setup lang=\"ts\">\nimport { ref, watchEffect, computed, StyleValue } from 'vue';\nimport { Position, restorePosition } from '@embedpdf/models';\nimport { createPointerProvider } from '../../shared/utils';\nimport { useInteractionManagerCapability, useIsPageExclusive } from '../hooks';\n\ninterface Props {\n pageIndex: number;\n pageWidth: number;\n pageHeight: number;\n rotation: number;\n scale: number;\n convertEventToPoint?: (event: PointerEvent, element: HTMLElement) => Position;\n}\n\nconst props = defineProps<Props>();\n\nconst divRef = ref<HTMLDivElement | null>(null);\nconst { provides: cap } = useInteractionManagerCapability();\nconst isPageExclusive = useIsPageExclusive();\n\nconst defaultConvertEventToPoint = computed(() => {\n return (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 return restorePosition(\n { width: props.pageWidth, height: props.pageHeight },\n displayPoint,\n props.rotation,\n props.scale,\n );\n };\n});\n\nwatchEffect((onCleanup) => {\n if (cap.value && divRef.value) {\n const cleanup = createPointerProvider(\n cap.value,\n { type: 'page', pageIndex: props.pageIndex },\n divRef.value,\n props.convertEventToPoint || defaultConvertEventToPoint.value,\n );\n onCleanup(cleanup);\n }\n});\n</script>\n\n<template>\n <div ref=\"divRef\">\n <slot />\n <div\n v-if=\"isPageExclusive\"\n :style=\"{ position: 'absolute', top: 0, left: 0, right: 0, bottom: 0, zIndex: 10 }\"\n />\n </div>\n</template>\n"],"names":["_a","_createElementBlock","_renderSlot","_unref","_openBlock"],"mappings":";;;;AAYA,MAAM,cAAiC;AAAA,EACrC,aAAa;AAAA,EACb,WAAW;AAAA,EACX,aAAa;AAAA,EACb,cAAc;AAAA,EACd,cAAc;AAAA,EACd,eAAe;AAAA,EAEf,WAAW;AAAA,EACX,SAAS;AAAA,EACT,WAAW;AAAA,EACX,YAAY;AAAA,EACZ,YAAY;AAAA,EACZ,aAAa;AAAA,EAEb,OAAO;AAAA,EACP,UAAU;AAAA;AAAA,EAGV,YAAY;AAAA,EACZ,UAAU;AAAA,EACV,WAAW;AAAA,EACX,aAAa;AACf;AAEA,MAAM,oBAAoB;AAAA,EACxB;AAAA,EACA;AA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QAAJ,KAAI;AAAA,MAAA;QACPC,WAAQ,KAAA,QAAA,SAAA;AAAA,QAEAC,MAAe,eAAA,KADvBC,aAAAH,mBAGE,OAHF,UAGE;;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@embedpdf/plugin-interaction-manager",
3
- "version": "1.0.17",
3
+ "version": "1.0.19",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
@@ -28,20 +28,20 @@
28
28
  }
29
29
  },
30
30
  "dependencies": {
31
- "@embedpdf/models": "1.0.17"
31
+ "@embedpdf/models": "1.0.19"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@types/react": "^18.2.0",
35
35
  "typescript": "^5.0.0",
36
- "@embedpdf/core": "1.0.17",
37
- "@embedpdf/build": "1.0.0"
36
+ "@embedpdf/build": "1.0.0",
37
+ "@embedpdf/core": "1.0.19"
38
38
  },
39
39
  "peerDependencies": {
40
40
  "react": ">=16.8.0",
41
41
  "react-dom": ">=16.8.0",
42
42
  "preact": "^10.26.4",
43
43
  "vue": ">=3.2.0",
44
- "@embedpdf/core": "1.0.17"
44
+ "@embedpdf/core": "1.0.19"
45
45
  },
46
46
  "files": [
47
47
  "dist",