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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/dist/index.cjs +1 -1
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.js +456 -185
  4. package/dist/index.js.map +1 -1
  5. package/dist/lib/actions.d.ts +61 -36
  6. package/dist/lib/interaction-manager-plugin.d.ts +19 -14
  7. package/dist/lib/reducer.d.ts +2 -1
  8. package/dist/lib/types.d.ts +58 -50
  9. package/dist/preact/index.cjs +1 -1
  10. package/dist/preact/index.cjs.map +1 -1
  11. package/dist/preact/index.js +61 -40
  12. package/dist/preact/index.js.map +1 -1
  13. package/dist/react/index.cjs +1 -1
  14. package/dist/react/index.cjs.map +1 -1
  15. package/dist/react/index.js +61 -40
  16. package/dist/react/index.js.map +1 -1
  17. package/dist/shared/components/global-pointer-provider.d.ts +2 -1
  18. package/dist/shared/components/page-pointer-provider.d.ts +4 -5
  19. package/dist/shared/hooks/use-interaction-manager.d.ts +9 -7
  20. package/dist/shared-preact/components/global-pointer-provider.d.ts +2 -1
  21. package/dist/shared-preact/components/page-pointer-provider.d.ts +4 -5
  22. package/dist/shared-preact/hooks/use-interaction-manager.d.ts +9 -7
  23. package/dist/shared-react/components/global-pointer-provider.d.ts +2 -1
  24. package/dist/shared-react/components/page-pointer-provider.d.ts +4 -5
  25. package/dist/shared-react/hooks/use-interaction-manager.d.ts +9 -7
  26. package/dist/svelte/components/GlobalPointerProvider.svelte.d.ts +1 -0
  27. package/dist/svelte/components/PagePointerProvider.svelte.d.ts +4 -5
  28. package/dist/svelte/hooks/use-interaction-manager.svelte.d.ts +10 -8
  29. package/dist/svelte/index.cjs +1 -1
  30. package/dist/svelte/index.cjs.map +1 -1
  31. package/dist/svelte/index.js +128 -56
  32. package/dist/svelte/index.js.map +1 -1
  33. package/dist/vue/components/global-pointer-provider.vue.d.ts +6 -2
  34. package/dist/vue/components/page-pointer-provider.vue.d.ts +7 -7
  35. package/dist/vue/hooks/use-interaction-manager.d.ts +19 -26
  36. package/dist/vue/index.cjs +1 -1
  37. package/dist/vue/index.cjs.map +1 -1
  38. package/dist/vue/index.js +131 -63
  39. package/dist/vue/index.js.map +1 -1
  40. package/package.json +4 -4
@@ -2,13 +2,12 @@ import { ReactNode, HTMLAttributes, CSSProperties } from '../../react/adapter.ts
2
2
  import { Position } from '@embedpdf/models';
3
3
  interface PagePointerProviderProps extends HTMLAttributes<HTMLDivElement> {
4
4
  children: ReactNode;
5
+ documentId: string;
5
6
  pageIndex: number;
6
- pageWidth: number;
7
- pageHeight: number;
8
- rotation: number;
9
- scale: number;
7
+ rotation?: number;
8
+ scale?: number;
10
9
  style?: CSSProperties;
11
10
  convertEventToPoint?: (event: PointerEvent, element: HTMLElement) => Position;
12
11
  }
13
- export declare const PagePointerProvider: ({ pageIndex, children, pageWidth, pageHeight, rotation, scale, convertEventToPoint, style, ...props }: PagePointerProviderProps) => import("react/jsx-runtime").JSX.Element;
12
+ export declare const PagePointerProvider: ({ documentId, pageIndex, children, rotation: rotationOverride, scale: scaleOverride, convertEventToPoint, style, ...props }: PagePointerProviderProps) => import("react/jsx-runtime").JSX.Element;
14
13
  export {};
@@ -1,4 +1,4 @@
1
- import { InteractionManagerPlugin, InteractionManagerState, PointerEventHandlersWithLifecycle } from '../../lib/index.ts';
1
+ import { InteractionDocumentState, InteractionManagerPlugin, PointerEventHandlersWithLifecycle } from '../../lib/index.ts';
2
2
  export declare const useInteractionManagerPlugin: () => {
3
3
  plugin: InteractionManagerPlugin | null;
4
4
  isLoading: boolean;
@@ -9,23 +9,25 @@ export declare const useInteractionManagerCapability: () => {
9
9
  isLoading: boolean;
10
10
  ready: Promise<void>;
11
11
  };
12
- export declare function useInteractionManager(): {
13
- provides: Readonly<import('../../lib/index.ts').InteractionManagerCapability> | null;
14
- state: InteractionManagerState;
12
+ export declare function useInteractionManager(documentId: string): {
13
+ provides: import('../../lib/index.ts').InteractionManagerScope | null;
14
+ state: InteractionDocumentState;
15
15
  };
16
- export declare function useCursor(): {
16
+ export declare function useCursor(documentId: string): {
17
17
  setCursor: (token: string, cursor: string, prio?: number) => void;
18
18
  removeCursor: (token: string) => void;
19
19
  };
20
20
  interface UsePointerHandlersOptions {
21
21
  modeId?: string | string[];
22
22
  pageIndex?: number;
23
+ documentId: string;
23
24
  }
24
- export declare function usePointerHandlers({ modeId, pageIndex }: UsePointerHandlersOptions): {
25
+ export declare function usePointerHandlers({ modeId, pageIndex, documentId }: UsePointerHandlersOptions): {
25
26
  register: (handlers: PointerEventHandlersWithLifecycle, options?: {
26
27
  modeId?: string | string[];
27
28
  pageIndex?: number;
29
+ documentId?: string;
28
30
  }) => (() => void) | undefined;
29
31
  };
30
- export declare function useIsPageExclusive(): boolean;
32
+ export declare function useIsPageExclusive(documentId: string): boolean;
31
33
  export {};
@@ -1,6 +1,7 @@
1
1
  import { Snippet } from 'svelte';
2
2
  import { HTMLAttributes } from 'svelte/elements';
3
3
  interface GlobalPointerProviderProps extends HTMLAttributes<HTMLDivElement> {
4
+ documentId: string;
4
5
  children: Snippet;
5
6
  class?: string;
6
7
  }
@@ -2,12 +2,11 @@ import { Position } from '@embedpdf/models';
2
2
  import { Snippet } from 'svelte';
3
3
  import { HTMLAttributes } from 'svelte/elements';
4
4
  interface PagePointerProviderProps extends HTMLAttributes<HTMLDivElement> {
5
- children: Snippet;
5
+ documentId: string;
6
6
  pageIndex: number;
7
- pageWidth: number;
8
- pageHeight: number;
9
- rotation: number;
10
- scale: number;
7
+ rotation?: number;
8
+ scale?: number;
9
+ children: Snippet;
11
10
  class?: string;
12
11
  convertEventToPoint?: (event: PointerEvent, element: HTMLElement) => Position;
13
12
  }
@@ -1,4 +1,4 @@
1
- import { InteractionManagerPlugin, InteractionManagerState, PointerEventHandlersWithLifecycle } from '../../lib/index.ts';
1
+ import { InteractionDocumentState, InteractionManagerPlugin, PointerEventHandlersWithLifecycle } from '../../lib/index.ts';
2
2
  export declare const useInteractionManagerPlugin: () => {
3
3
  plugin: InteractionManagerPlugin | null;
4
4
  isLoading: boolean;
@@ -9,25 +9,27 @@ export declare const useInteractionManagerCapability: () => {
9
9
  isLoading: boolean;
10
10
  ready: Promise<void>;
11
11
  };
12
- export declare function useInteractionManager(): {
13
- readonly provides: Readonly<import('../../lib/index.ts').InteractionManagerCapability> | null;
14
- state: InteractionManagerState;
12
+ export declare function useInteractionManager(documentId: string): {
13
+ readonly state: InteractionDocumentState;
14
+ readonly provides: import('../../lib/index.ts').InteractionManagerScope | null;
15
15
  };
16
- export declare function useCursor(): {
16
+ export declare function useCursor(documentId: string): {
17
17
  setCursor: (token: string, cursor: string, prio?: number) => void;
18
18
  removeCursor: (token: string) => void;
19
19
  };
20
20
  interface UsePointerHandlersOptions {
21
21
  modeId?: string | string[];
22
22
  pageIndex?: number;
23
+ documentId: string;
23
24
  }
24
- export declare function usePointerHandlers({ modeId, pageIndex }?: UsePointerHandlersOptions): {
25
+ export declare function usePointerHandlers({ modeId, pageIndex, documentId }: UsePointerHandlersOptions): {
25
26
  register: (handlers: PointerEventHandlersWithLifecycle, options?: {
26
27
  modeId?: string | string[];
27
28
  pageIndex?: number;
29
+ documentId?: string;
28
30
  }) => (() => void) | undefined;
29
31
  };
30
- export declare function useIsPageExclusive(): {
31
- isPageExclusive: boolean;
32
+ export declare function useIsPageExclusive(documentId: string): {
33
+ readonly current: boolean;
32
34
  };
33
35
  export {};
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"}),require("svelte/internal/disclose-version");const e=require("svelte/internal/client"),t=require("@embedpdf/plugin-interaction-manager"),n=require("@embedpdf/core/svelte"),o=require("@embedpdf/models");function r(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e)for(const n in e)if("default"!==n){const o=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,o.get?o:{enumerable:!0,get:()=>e[n]})}return t.default=e,Object.freeze(t)}const i=r(e),s=()=>n.useCapability(t.InteractionManagerPlugin.id);function l(){const e=s(),t=i.proxy({isPageExclusive:!1});return i.user_effect((()=>{if(!e.provides)return;const n=e.provides.getActiveInteractionMode();return t.isPageExclusive="page"===(null==n?void 0:n.scope)&&!!n.exclusive,e.provides.onModeChange((()=>{var n;const o=null==(n=e.provides)?void 0:n.getActiveInteractionMode();t.isPageExclusive="page"===(null==o?void 0:o.scope)&&!!(null==o?void 0:o.exclusive)}))})),t}const a={pointerdown:"onPointerDown",pointerup:"onPointerUp",pointermove:"onPointerMove",pointerenter:"onPointerEnter",pointerleave:"onPointerLeave",pointercancel:"onPointerCancel",mousedown:"onMouseDown",mouseup:"onMouseUp",mousemove:"onMouseMove",mouseenter:"onMouseEnter",mouseleave:"onMouseLeave",mousecancel:"onMouseCancel",click:"onClick",dblclick:"onDoubleClick",touchstart:"onPointerDown",touchend:"onPointerUp",touchmove:"onPointerMove",touchcancel:"onPointerCancel"},c=["pointerdown","pointerup","pointermove","pointerenter","pointerleave","pointercancel","mousedown","mouseup","mousemove","mouseenter","mouseleave","mousecancel","click","dblclick"],u="undefined"!=typeof PointerEvent?c:[...c,"touchstart","touchend","touchmove","touchcancel"];function p(e){return"undefined"!=typeof TouchEvent&&e instanceof TouchEvent}function d(e,t,n,o){let r=e.getHandlersForScope(t);const i=()=>{var t;return!1!==(null==(t=e.getActiveInteractionMode())?void 0:t.wantsRawTouch)},s={};let l=i();const c=e=>{u.forEach((t=>{const o=s[t]??(s[t]=P);var r;n.addEventListener(t,o,(r=e,t.startsWith("touch")?{passive:!r}:{passive:!1}))}))},d=()=>{u.forEach((e=>{const t=s[e];t&&n.removeEventListener(e,t)}))};c(l),n.style.touchAction=l?"none":"";const v=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!==l&&(d(),c(o),l=o,n.style.touchAction=l?"none":"")})),g=e.onHandlerChange((()=>{r=e.getHandlersForScope(t)})),f=e.getActiveInteractionMode(),h=e.getCurrentCursor();n.style.cursor="global"===t.type&&"global"!==(null==f?void 0:f.scope)?"auto":h;const y=e.onCursorChange((o=>{var r;"global"===t.type&&"global"!==(null==(r=e.getActiveInteractionMode())?void 0:r.scope)||(n.style.cursor=o)})),m=(e,t)=>{if(o)return o(e,t);const n=t.getBoundingClientRect();return{x:e.clientX-n.left,y:e.clientY-n.top}};function P(t){var o;if(e.isPaused())return;const i=e.getExclusionRules();if(t.target&&function(e,t){var n,o,r;if(!e)return!1;let i=e;for(;i;){if(null==(n=t.classes)?void 0:n.length)for(const e of t.classes)if(null==(o=i.classList)?void 0:o.contains(e))return!0;if(null==(r=t.dataAttributes)?void 0:r.length)for(const e of t.dataAttributes)if(i.hasAttribute(e))return!0;i=i.parentElement}return!1}(t.target,i))return;const s=a[t.type];if(!s||!(null==r?void 0:r[s]))return;let c,u;if(p(t)&&l&&("touchmove"===t.type||"touchcancel"===t.type)&&t.preventDefault(),p(t)){const e="touchend"===t.type||"touchcancel"===t.type?t.changedTouches[0]:t.touches[0];if(!e)return;c=m(e,n),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,setPointerCapture:()=>{},releasePointerCapture:()=>{}}}else{const e=t;c=m(e,n),u={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[s])||o.call(r,c,u,e.getActiveMode())}return()=>{d(),v(),y(),g()}}var v=i.from_html("<div><!></div>");var g=i.from_html("<div></div>"),f=i.from_html("<div><!> <!></div>");exports.GlobalPointerProvider=function(e,t){i.push(t,!0);let n=i.rest_props(t,["$$slots","$$events","$$legacy","children","class"]),o=i.state(null);const r=s();i.user_effect((()=>{if(r.provides&&i.get(o))return d(r.provides,{type:"global"},i.get(o))}));var l=v();i.attribute_effect(l,(()=>({class:t.class,...n,[i.STYLE]:{width:"100%",height:"100%"}})));var a=i.child(l);i.snippet(a,(()=>t.children)),i.reset(l),i.bind_this(l,(e=>i.set(o,e)),(()=>i.get(o))),i.append(e,l),i.pop()},exports.PagePointerProvider=function(e,t){i.push(t,!0);let n=i.rest_props(t,["$$slots","$$events","$$legacy","pageIndex","children","pageWidth","pageHeight","rotation","scale","convertEventToPoint","class"]),r=i.state(null);const a=s(),c=l(),u=i.derived((()=>(e,n)=>{const r=n.getBoundingClientRect(),i={x:e.clientX-r.left,y:e.clientY-r.top},s=o.transformSize({width:t.pageWidth,height:t.pageHeight},t.rotation,1);return o.restorePosition(s,i,t.rotation,t.scale)}));i.user_effect((()=>{if(a.provides&&i.get(r))return d(a.provides,{type:"page",pageIndex:t.pageIndex},i.get(r),t.convertEventToPoint||i.get(u))}));var p=f();i.attribute_effect(p,(e=>({class:t.class,...n,[i.STYLE]:e})),[()=>({position:"relative",width:`${t.pageWidth}px`,height:`${t.pageHeight}px`})]);var v=i.child(p);i.snippet(v,(()=>t.children));var h=i.sibling(v,2),y=e=>{var t=g();i.set_style(t,"",{},{position:"absolute",top:"0",left:"0",right:"0",bottom:"0","z-index":"10"}),i.append(e,t)};i.if(h,(e=>{c&&e(y)})),i.reset(p),i.bind_this(p,(e=>i.set(r,e)),(()=>i.get(r))),i.append(e,p),i.pop()},exports.useCursor=function(){const e=s();return i.proxy({setCursor:(t,n,o=0)=>{var r;null==(r=e.provides)||r.setCursor(t,n,o)},removeCursor:t=>{var n;null==(n=e.provides)||n.removeCursor(t)}})},exports.useInteractionManager=function(){const e=s(),n=i.proxy({get provides(){return e.provides},state:t.initialState});return i.user_effect((()=>{if(e.provides)return e.provides.onStateChange((e=>{n.state=e}))})),n},exports.useInteractionManagerCapability=s,exports.useInteractionManagerPlugin=()=>n.usePlugin(t.InteractionManagerPlugin.id),exports.useIsPageExclusive=l,exports.usePointerHandlers=function({modeId:e,pageIndex:t}={}){const n=s();return{register:(o,r)=>{var i,s;const l=(null==r?void 0:r.modeId)??e,a=(null==r?void 0:r.pageIndex)??t;return l?null==(i=n.provides)?void 0:i.registerHandlers({modeId:l,handlers:o,pageIndex:a}):null==(s=n.provides)?void 0:s.registerAlways({scope:void 0!==a?{type:"page",pageIndex:a}:{type:"global"},handlers:o})}}},Object.keys(t).forEach((e=>{"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:()=>t[e]})}));
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"}),require("svelte/internal/disclose-version");const e=require("svelte/internal/client"),t=require("@embedpdf/core/svelte"),n=require("@embedpdf/plugin-interaction-manager"),o=require("@embedpdf/models");function r(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e)for(const n in e)if("default"!==n){const o=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,o.get?o:{enumerable:!0,get:()=>e[n]})}return t.default=e,Object.freeze(t)}const i=r(e),s=()=>t.useCapability(n.InteractionManagerPlugin.id);function c(e){const t=s();let n=i.state(!1);return i.user_effect(()=>{if(!t.provides)return void i.set(n,!1);const o=t.provides.forDocument(e),r=o.getActiveInteractionMode();return i.set(n,"page"===(null==r?void 0:r.scope)&&!!r.exclusive,!0),o.onModeChange(()=>{const e=o.getActiveInteractionMode();i.set(n,"page"===(null==e?void 0:e.scope)&&!!(null==e?void 0:e.exclusive),!0)})}),{get current(){return i.get(n)}}}const l={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"],a="undefined"!=typeof PointerEvent?u:[...u,"touchstart","touchend","touchmove","touchcancel"];function d(e){return"undefined"!=typeof TouchEvent&&e instanceof TouchEvent}function p(e,t,n,o){const r=e.forDocument(t.documentId);let i=e.getHandlersForScope(t);const s=()=>{var e;return!1!==(null==(e=r.getActiveInteractionMode())?void 0:e.wantsRawTouch)},c={};let u=s();const p=e=>{a.forEach(t=>{const o=c[t]??(c[t]=I);var r;n.addEventListener(t,o,(r=e,t.startsWith("touch")?{passive:!r}:{passive:!1}))})},v=()=>{a.forEach(e=>{const t=c[e];t&&n.removeEventListener(e,t)})};p(u),n.style.touchAction=u?"none":"";const g=r.onModeChange(()=>{if("global"===t.type){const e=r.getActiveInteractionMode();n.style.cursor="global"===(null==e?void 0:e.scope)?e.cursor??"auto":"auto"}i=e.getHandlersForScope(t);const o=s();o!==u&&(v(),p(o),u=o,n.style.touchAction=u?"none":"")}),f=e.onHandlerChange(()=>{i=e.getHandlersForScope(t)}),h=r.getActiveInteractionMode(),m=r.getCurrentCursor();n.style.cursor="global"===t.type&&"global"!==(null==h?void 0:h.scope)?"auto":m;const y=r.onCursorChange(e=>{var o;"global"===t.type&&"global"!==(null==(o=r.getActiveInteractionMode())?void 0:o.scope)||(n.style.cursor=e)}),b=(e,t)=>{if(o)return o(e,t);const n=t.getBoundingClientRect();return{x:e.clientX-n.left,y:e.clientY-n.top}};function I(t){var o;if(e.isPaused())return;const s=e.getExclusionRules();if(t.target&&function(e,t){var n,o,r;if(!e)return!1;let i=e;for(;i;){if(null==(n=t.classes)?void 0:n.length)for(const e of t.classes)if(null==(o=i.classList)?void 0:o.contains(e))return!0;if(null==(r=t.dataAttributes)?void 0:r.length)for(const e of t.dataAttributes)if(i.hasAttribute(e))return!0;i=i.parentElement}return!1}(t.target,s))return;const c=l[t.type];if(!c||!(null==i?void 0:i[c]))return;let a,p;if(d(t)&&u&&("touchmove"===t.type||"touchcancel"===t.type)&&t.preventDefault(),d(t)){const e="touchend"===t.type||"touchcancel"===t.type?t.changedTouches[0]:t.touches[0];if(!e)return;a=b(e,n),p={clientX:e.clientX,clientY:e.clientY,ctrlKey:t.ctrlKey,shiftKey:t.shiftKey,altKey:t.altKey,metaKey:t.metaKey,target:t.target,currentTarget:t.currentTarget,setPointerCapture:()=>{},releasePointerCapture:()=>{}}}else{const e=t;a=b(e,n),p={clientX:e.clientX,clientY:e.clientY,ctrlKey:e.ctrlKey,shiftKey:e.shiftKey,altKey:e.altKey,metaKey:e.metaKey,target:e.target,currentTarget:e.currentTarget,setPointerCapture:()=>{var t,n;null==(n=null==(t=e.target)?void 0:t.setPointerCapture)||n.call(t,e.pointerId)},releasePointerCapture:()=>{var t,n;null==(n=null==(t=e.target)?void 0:t.releasePointerCapture)||n.call(t,e.pointerId)}}}null==(o=i[c])||o.call(i,a,p,r.getActiveMode())}return()=>{v(),g(),y(),f()}}var v=i.from_html("<div><!></div>");var g=i.from_html("<div></div>"),f=i.from_html("<div><!> <!></div>");exports.GlobalPointerProvider=function(e,t){i.push(t,!0);let n=i.rest_props(t,["$$slots","$$events","$$legacy","documentId","children","class"]),o=i.state(null);const r=s();i.user_effect(()=>{if(r.provides&&i.get(o))return p(r.provides,{type:"global",documentId:t.documentId},i.get(o))});var c=v();i.attribute_effect(c,()=>({class:t.class,...n,[i.STYLE]:{width:"100%",height:"100%"}}));var l=i.child(c);i.snippet(l,()=>t.children),i.reset(c),i.bind_this(c,e=>i.set(o,e),()=>i.get(o)),i.append(e,c),i.pop()},exports.PagePointerProvider=function(e,n){i.push(n,!0);let r=i.rest_props(n,["$$slots","$$events","$$legacy","documentId","pageIndex","children","rotation","scale","convertEventToPoint","class"]),l=i.state(null);const u=s(),a=c(n.documentId),d=t.useDocumentState(()=>n.documentId),v=i.derived(()=>{var e,t,o;return null==(o=null==(t=null==(e=d.current)?void 0:e.document)?void 0:t.pages)?void 0:o[n.pageIndex]}),h=i.derived(()=>{var e;return(null==(e=i.get(v))?void 0:e.size)??{width:0,height:0}}),m=i.derived(()=>{var e;return n.rotation??(null==(e=d.current)?void 0:e.rotation)??0}),y=i.derived(()=>{var e;return n.scale??(null==(e=d.current)?void 0:e.scale)??1}),b=i.derived(()=>o.transformSize(i.get(h),0,i.get(y))),I=i.derived(()=>(e,t)=>{const n=t.getBoundingClientRect(),r={x:e.clientX-n.left,y:e.clientY-n.top},s=o.transformSize({width:i.get(b).width,height:i.get(b).height},i.get(m),1);return o.restorePosition(s,r,i.get(m),i.get(y))});i.user_effect(()=>{if(u.provides&&i.get(l))return p(u.provides,{type:"page",documentId:n.documentId,pageIndex:n.pageIndex},i.get(l),n.convertEventToPoint||i.get(I))});var P=f();i.attribute_effect(P,()=>({class:n.class,...r,[i.STYLE]:{position:"relative",width:`${i.get(b).width}px`,height:`${i.get(b).height}px`}}));var x=i.child(P);i.snippet(x,()=>n.children);var C=i.sibling(x,2),M=e=>{var t=g();i.set_style(t,"",{},{position:"absolute",top:"0",left:"0",right:"0",bottom:"0","z-index":"10"}),i.append(e,t)};i.if(C,e=>{a.current&&e(M)}),i.reset(P),i.bind_this(P,e=>i.set(l,e),()=>i.get(l)),i.append(e,P),i.pop()},exports.useCursor=function(e){const t=s();return{setCursor:(n,o,r=0)=>{if(!t.provides)return;t.provides.forDocument(e).setCursor(n,o,r)},removeCursor:n=>{if(!t.provides)return;t.provides.forDocument(e).removeCursor(n)}}},exports.useInteractionManager=function(e){const t=s();let o=i.state(i.proxy(n.initialDocumentState));const r=i.derived(()=>{var n;return(null==(n=t.provides)?void 0:n.forDocument(e))??null});return i.user_effect(()=>{if(!t.provides)return void i.set(o,n.initialDocumentState,!0);const r=t.provides.forDocument(e);return i.set(o,r.getState(),!0),r.onStateChange(e=>{i.set(o,e,!0)})}),{get state(){return i.get(o)},get provides(){return i.get(r)}}},exports.useInteractionManagerCapability=s,exports.useInteractionManagerPlugin=()=>t.usePlugin(n.InteractionManagerPlugin.id),exports.useIsPageExclusive=c,exports.usePointerHandlers=function({modeId:e,pageIndex:t,documentId:n}){const o=s();return{register:(r,i)=>{var s,c;const l=(null==i?void 0:i.modeId)??e,u=(null==i?void 0:i.pageIndex)??t,a=(null==i?void 0:i.documentId)??n;return l?null==(s=o.provides)?void 0:s.registerHandlers({modeId:l,handlers:r,pageIndex:u,documentId:a}):null==(c=o.provides)?void 0:c.registerAlways({scope:void 0!==u?{type:"page",documentId:a,pageIndex:u}:{type:"global",documentId:a},handlers:r})}}},Object.keys(n).forEach(e=>{"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:()=>n[e]})});
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../../src/svelte/hooks/use-interaction-manager.svelte.ts","../../src/shared/utils.ts","../../src/svelte/components/GlobalPointerProvider.svelte","../../src/svelte/components/PagePointerProvider.svelte"],"sourcesContent":["import {\n initialState,\n InteractionManagerPlugin,\n InteractionManagerState,\n PointerEventHandlersWithLifecycle,\n} from '@embedpdf/plugin-interaction-manager';\nimport { useCapability, usePlugin } from '@embedpdf/core/svelte';\n\nexport const useInteractionManagerPlugin = () =>\n usePlugin<InteractionManagerPlugin>(InteractionManagerPlugin.id);\nexport const useInteractionManagerCapability = () =>\n useCapability<InteractionManagerPlugin>(InteractionManagerPlugin.id);\n\nexport function useInteractionManager() {\n const capability = useInteractionManagerCapability();\n\n const state = $state({\n get provides() {\n return capability.provides;\n },\n state: initialState as InteractionManagerState,\n });\n\n $effect(() => {\n if (!capability.provides) return;\n return capability.provides.onStateChange((newState) => {\n state.state = newState;\n });\n });\n\n return state;\n}\n\nexport function useCursor() {\n const capability = useInteractionManagerCapability();\n\n const state = $state({\n setCursor: (token: string, cursor: string, prio = 0) => {\n capability.provides?.setCursor(token, cursor, prio);\n },\n removeCursor: (token: string) => {\n capability.provides?.removeCursor(token);\n },\n });\n\n return state;\n}\n\ninterface UsePointerHandlersOptions {\n modeId?: string | string[];\n pageIndex?: number;\n}\n\nexport function usePointerHandlers({ modeId, pageIndex }: UsePointerHandlersOptions = {}) {\n const capability = useInteractionManagerCapability();\n\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 ? capability.provides?.registerHandlers({\n modeId: finalModeId,\n handlers,\n pageIndex: finalPageIndex,\n })\n : capability.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 capability = useInteractionManagerCapability();\n\n const state = $state({\n isPageExclusive: false,\n });\n\n // Initialize and update on changes\n $effect(() => {\n if (!capability.provides) return;\n\n // Set initial value\n const mode = capability.provides.getActiveInteractionMode();\n state.isPageExclusive = mode?.scope === 'page' && !!mode.exclusive;\n\n // Listen for changes\n return capability.provides.onModeChange(() => {\n const mode = capability.provides?.getActiveInteractionMode();\n state.isPageExclusive = mode?.scope === 'page' && !!mode?.exclusive;\n });\n });\n\n return state;\n}\n","import { Position } from '@embedpdf/models';\nimport type {\n InteractionManagerCapability,\n InteractionScope,\n PointerEventHandlers,\n EmbedPdfPointerEvent,\n InteractionExclusionRules,\n} from '@embedpdf/plugin-interaction-manager';\n\n/* -------------------------------------------------- */\n/* event → handler key lookup */\n/* -------------------------------------------------- */\ntype K = keyof PointerEventHandlers;\nconst domEventMap: Record<string, K> = {\n pointerdown: 'onPointerDown',\n pointerup: 'onPointerUp',\n pointermove: 'onPointerMove',\n pointerenter: 'onPointerEnter',\n pointerleave: 'onPointerLeave',\n pointercancel: 'onPointerCancel',\n\n mousedown: 'onMouseDown',\n mouseup: 'onMouseUp',\n mousemove: 'onMouseMove',\n mouseenter: 'onMouseEnter',\n mouseleave: 'onMouseLeave',\n mousecancel: 'onMouseCancel',\n\n click: 'onClick',\n dblclick: 'onDoubleClick',\n\n /* touch → pointer fallback for very old browsers */\n touchstart: 'onPointerDown',\n touchend: 'onPointerUp',\n touchmove: 'onPointerMove',\n touchcancel: 'onPointerCancel',\n};\n\nconst pointerEventTypes = [\n 'pointerdown',\n 'pointerup',\n 'pointermove',\n 'pointerenter',\n 'pointerleave',\n 'pointercancel',\n 'mousedown',\n 'mouseup',\n 'mousemove',\n 'mouseenter',\n 'mouseleave',\n 'mousecancel',\n 'click',\n 'dblclick',\n];\n\nconst touchEventTypes = ['touchstart', 'touchend', 'touchmove', 'touchcancel'];\nconst HAS_POINTER = typeof PointerEvent !== 'undefined';\n// If the browser supports Pointer Events, don't attach legacy touch events to avoid double-dispatch.\nconst allEventTypes = HAS_POINTER ? pointerEventTypes : [...pointerEventTypes, ...touchEventTypes];\n\n/* -------------------------------------------------- */\n/* helper: decide listener options per event type */\n/* -------------------------------------------------- */\nfunction listenerOpts(eventType: string, wantsRawTouch: boolean): AddEventListenerOptions {\n // Only touch events are toggled; pointer/mouse stay non-passive\n return eventType.startsWith('touch') ? { passive: !wantsRawTouch } : { passive: false };\n}\n\nfunction isTouchEvent(evt: Event): evt is TouchEvent {\n return typeof TouchEvent !== 'undefined' && evt instanceof TouchEvent;\n}\n\n/**\n * Check if an element should be excluded based on rules\n * This is in the framework layer, not the plugin\n */\nfunction shouldExcludeElement(element: Element | null, rules: InteractionExclusionRules): boolean {\n if (!element) return false;\n\n let current: Element | null = element;\n\n while (current) {\n // Check classes\n if (rules.classes?.length) {\n for (const className of rules.classes) {\n if (current.classList?.contains(className)) {\n return true;\n }\n }\n }\n\n // Check data attributes\n if (rules.dataAttributes?.length) {\n for (const attr of rules.dataAttributes) {\n if (current.hasAttribute(attr)) {\n return true;\n }\n }\n }\n\n // Move up the DOM tree\n current = current.parentElement;\n }\n\n return false;\n}\n\n/* -------------------------------------------------- */\n/* createPointerProvider */\n/* -------------------------------------------------- */\nexport function createPointerProvider(\n cap: InteractionManagerCapability,\n scope: InteractionScope,\n element: HTMLElement,\n convertEventToPoint?: (evt: PointerEvent, host: HTMLElement) => Position,\n) {\n /* ---------- live handler set --------------------------------------------------- */\n let active: PointerEventHandlers | null = cap.getHandlersForScope(scope);\n\n /* ---------- helper to compute current wantsRawTouch (defaults to true) --------- */\n const wantsRawTouchNow = () => cap.getActiveInteractionMode()?.wantsRawTouch !== false; // default → true\n\n /* ---------- dynamic listener (re)attachment ------------------------------------ */\n const listeners: Record<string, (evt: Event) => void> = {};\n let attachedWithRawTouch = wantsRawTouchNow(); // remember current mode’s wish\n\n const addListeners = (raw: boolean) => {\n allEventTypes.forEach((type) => {\n const fn = (listeners[type] ??= handleEvent);\n element.addEventListener(type, fn, listenerOpts(type, raw));\n });\n };\n const removeListeners = () => {\n allEventTypes.forEach((type) => {\n const fn = listeners[type];\n if (fn) element.removeEventListener(type, fn);\n });\n };\n\n /* attach for the first time */\n addListeners(attachedWithRawTouch);\n element.style.touchAction = attachedWithRawTouch ? 'none' : '';\n\n /* ---------- mode & handler change hooks --------------------------------------- */\n const stopMode = cap.onModeChange(() => {\n /* cursor baseline update for global wrapper */\n if (scope.type === 'global') {\n const mode = cap.getActiveInteractionMode();\n element.style.cursor = mode?.scope === 'global' ? (mode.cursor ?? 'auto') : 'auto';\n }\n\n active = cap.getHandlersForScope(scope);\n\n /* re-attach listeners if wantsRawTouch toggled */\n const raw = wantsRawTouchNow();\n if (raw !== attachedWithRawTouch) {\n removeListeners();\n addListeners(raw);\n attachedWithRawTouch = raw;\n element.style.touchAction = attachedWithRawTouch ? 'none' : '';\n }\n });\n\n const stopHandler = cap.onHandlerChange(() => {\n active = cap.getHandlersForScope(scope);\n });\n\n /* ---------- cursor sync -------------------------------------------------------- */\n const initialMode = cap.getActiveInteractionMode();\n const initialCursor = cap.getCurrentCursor();\n element.style.cursor =\n scope.type === 'global' && initialMode?.scope !== 'global' ? 'auto' : initialCursor;\n\n const stopCursor = cap.onCursorChange((c) => {\n if (scope.type === 'global' && cap.getActiveInteractionMode()?.scope !== 'global') return;\n element.style.cursor = c;\n });\n\n /* ---------- point conversion --------------------------------------------------- */\n const toPos = (e: { clientX: number; clientY: number }, host: HTMLElement): Position => {\n if (convertEventToPoint) return convertEventToPoint(e as PointerEvent, host);\n const r = host.getBoundingClientRect();\n return { x: e.clientX - r.left, y: e.clientY - r.top };\n };\n\n /* ---------- central event handler --------------------------------------------- */\n function handleEvent(evt: Event) {\n if (cap.isPaused()) return;\n\n // Get exclusion rules from capability and check in framework layer\n const exclusionRules = cap.getExclusionRules();\n if (evt.target && shouldExcludeElement(evt.target as Element, exclusionRules)) {\n return; // Skip processing this event\n }\n\n const handlerKey = domEventMap[evt.type];\n if (!handlerKey || !active?.[handlerKey]) return;\n\n /* preventDefault only when mode really wants raw touch */\n if (\n isTouchEvent(evt) &&\n attachedWithRawTouch &&\n (evt.type === 'touchmove' || evt.type === 'touchcancel')\n ) {\n evt.preventDefault();\n }\n\n // ----- normalise ----------------------------------------------------------------\n let pos!: Position;\n let normEvt!: EmbedPdfPointerEvent & {\n target: EventTarget | null;\n currentTarget: EventTarget | null;\n };\n\n if (isTouchEvent(evt)) {\n const tp =\n evt.type === 'touchend' || evt.type === 'touchcancel'\n ? evt.changedTouches[0]\n : evt.touches[0];\n if (!tp) return;\n\n pos = toPos(tp, element);\n normEvt = {\n clientX: tp.clientX,\n clientY: tp.clientY,\n ctrlKey: evt.ctrlKey,\n shiftKey: evt.shiftKey,\n altKey: evt.altKey,\n metaKey: evt.metaKey,\n target: evt.target,\n currentTarget: evt.currentTarget,\n setPointerCapture: () => {},\n releasePointerCapture: () => {},\n };\n } else {\n const pe = evt as PointerEvent;\n pos = toPos(pe, element);\n normEvt = {\n clientX: pe.clientX,\n clientY: pe.clientY,\n ctrlKey: pe.ctrlKey,\n shiftKey: pe.shiftKey,\n altKey: pe.altKey,\n metaKey: pe.metaKey,\n target: pe.target,\n currentTarget: pe.currentTarget,\n setPointerCapture: () => {\n (pe.target as HTMLElement)?.setPointerCapture?.(pe.pointerId);\n },\n releasePointerCapture: () => {\n (pe.target as HTMLElement)?.releasePointerCapture?.(pe.pointerId);\n },\n };\n }\n\n active[handlerKey]?.(pos, normEvt, cap.getActiveMode());\n }\n\n /* ---------- teardown ----------------------------------------------------------- */\n return () => {\n removeListeners();\n stopMode();\n stopCursor();\n stopHandler();\n };\n}\n","<script lang=\"ts\">\n import type { Snippet } from 'svelte';\n import { useInteractionManagerCapability } from '../hooks';\n import { createPointerProvider } from '../../shared/utils';\n import type { HTMLAttributes } from 'svelte/elements';\n\n interface GlobalPointerProviderProps extends HTMLAttributes<HTMLDivElement> {\n children: Snippet;\n class?: string;\n }\n\n let { children, class: propsClass, ...restProps }: GlobalPointerProviderProps = $props();\n\n let ref = $state<HTMLDivElement | null>(null);\n const interactionManagerCapability = useInteractionManagerCapability();\n\n $effect(() => {\n if (!interactionManagerCapability.provides || !ref) return;\n\n return createPointerProvider(interactionManagerCapability.provides, { type: 'global' }, ref);\n });\n</script>\n\n<div bind:this={ref} style:width=\"100%\" style:height=\"100%\" class={propsClass} {...restProps}>\n {@render children()}\n</div>\n","<script lang=\"ts\">\n import { type Position, restorePosition, type Size, transformSize } from '@embedpdf/models';\n import type { Snippet } from 'svelte';\n import type { HTMLAttributes } from 'svelte/elements';\n import { createPointerProvider } from '../../shared/utils';\n import { useInteractionManagerCapability, useIsPageExclusive } from '../hooks';\n\n interface PagePointerProviderProps extends HTMLAttributes<HTMLDivElement> {\n children: Snippet;\n pageIndex: number;\n pageWidth: number;\n pageHeight: number;\n rotation: number;\n scale: number;\n class?: string;\n convertEventToPoint?: (event: PointerEvent, element: HTMLElement) => Position;\n }\n\n let {\n pageIndex,\n children,\n pageWidth,\n pageHeight,\n rotation,\n scale,\n convertEventToPoint,\n class: propsClass,\n ...restProps\n }: PagePointerProviderProps = $props();\n\n let ref = $state<HTMLDivElement | null>(null);\n\n const interactionManagerCapability = useInteractionManagerCapability();\n const isPageExclusive = useIsPageExclusive();\n\n // Memoize the default conversion function\n const defaultConvertEventToPoint = $derived.by(() => {\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\n const displaySize: Size = transformSize(\n { width: pageWidth, height: pageHeight },\n rotation,\n 1,\n );\n\n return restorePosition(displaySize, displayPoint, rotation, scale);\n };\n });\n\n $effect(() => {\n if (!interactionManagerCapability.provides || !ref) return;\n\n return createPointerProvider(\n interactionManagerCapability.provides,\n { type: 'page', pageIndex },\n ref,\n convertEventToPoint || defaultConvertEventToPoint,\n );\n });\n</script>\n\n<div\n bind:this={ref}\n style:position=\"relative\"\n style:width={`${pageWidth}px`}\n style:height={`${pageHeight}px`}\n class={propsClass}\n {...restProps}\n>\n {@render children()}\n {#if isPageExclusive}\n <div\n style:position=\"absolute\"\n style:top=\"0\"\n style:left=\"0\"\n style:right=\"0\"\n style:bottom=\"0\"\n style:z-index=\"10\"\n ></div>\n {/if}\n</div>\n"],"names":["useInteractionManagerCapability","useCapability","InteractionManagerPlugin","id","useIsPageExclusive","capability","state","isPageExclusive","$","user_effect","provides","mode","getActiveInteractionMode","scope","exclusive","onModeChange","_a","mode2","domEventMap","pointerdown","pointerup","pointermove","pointerenter","pointerleave","pointercancel","mousedown","mouseup","mousemove","mouseenter","mouseleave","mousecancel","click","dblclick","touchstart","touchend","touchmove","touchcancel","pointerEventTypes","allEventTypes","PointerEvent","isTouchEvent","evt","TouchEvent","createPointerProvider","cap","element","convertEventToPoint","active","getHandlersForScope","wantsRawTouchNow","wantsRawTouch","listeners","attachedWithRawTouch","addListeners","raw","forEach","type","fn","handleEvent","addEventListener","startsWith","passive","removeListeners","removeEventListener","style","touchAction","stopMode","cursor","stopHandler","onHandlerChange","initialMode","initialCursor","getCurrentCursor","stopCursor","onCursorChange","c","toPos","e","host","r","getBoundingClientRect","x","clientX","left","y","clientY","top","isPaused","exclusionRules","getExclusionRules","target","rules","current","classes","length","className","_b","classList","contains","_c","dataAttributes","attr","hasAttribute","parentElement","shouldExcludeElement","handlerKey","pos","normEvt","preventDefault","tp","changedTouches","touches","ctrlKey","shiftKey","altKey","metaKey","currentTarget","setPointerCapture","releasePointerCapture","pe","call","pointerId","getActiveMode","restProps","rest_props","$$props","ref","interactionManagerCapability","get","bind_this","div","$$value","set","defaultConvertEventToPoint","derived","event","rect","displayPoint","displaySize","transformSize","width","pageWidth","height","restorePosition","rotation","scale","pageIndex","STYLE","$0","consequent","setCursor","token","prio","removeCursor","initialState","onStateChange","newState","usePlugin","modeId","register","handlers","options","finalModeId","finalPageIndex","registerHandlers","registerAlways"],"mappings":"ijBAUaA,EACX,IAAAC,gBAAwCC,EAAAA,yBAAyBC,IAuEnD,SAAAC,IACR,MAAAC,EAAaL,IAEbM,WACJC,iBAAiB,IAkBZ,OAdPC,EAAAC,kBACO,IAAAJ,EAAWK,SAAU,OAGpB,MAAAC,EAAON,EAAWK,SAASE,2BAI1B,OAHPN,EAAMC,gBAAkC,UAAV,MAANI,OAAM,EAAAA,EAAAE,UAAsBF,EAAKG,UAGlDT,EAAWK,SAASK,yBACnBJ,MAAAA,EAAO,OAAAK,EAAWX,EAAAK,eAAU,EAAAM,EAAAJ,2BAClCN,EAAMC,gBAAkC,UAAV,MAANI,OAAM,EAAAM,EAAAJ,WAA4B,MAANF,OAAM,EAAAM,EAAAH,UAAA,GAC3D,IAGIR,CACT,CC5FA,MAAMY,EAAiC,CACrCC,YAAa,gBACbC,UAAW,cACXC,YAAa,gBACbC,aAAc,iBACdC,aAAc,iBACdC,cAAe,kBAEfC,UAAW,cACXC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ARLsJ,UAAW,CAACC,EAAepF,EAAgBqF,EAAO,WAChD,OAAAxI,EAAAX,EAAWK,WAAXM,EAAqBsI,UAAUC,EAAOpF,EAAQqF,EAAA,EAEhDC,aAAeF,UACF,OAAAvI,EAAAX,EAAAK,aAAU+I,aAAaF,EAAA,GAKxC,gCAjCgB,WACR,MAAAlJ,EAAaL,IAEbM,WACA,YAAAI,GACK,OAAAL,EAAWK,QACpB,EACAJ,MAAOoJ,EAAAA,eAUF,OAPPlJ,EAAAC,kBACO,GAAAJ,EAAWK,SACT,OAAAL,EAAWK,SAASiJ,eAAeC,IACxCtJ,EAAMA,MAAQsJ,CAAA,GACf,IAGItJ,CACT,gFAtBE,IAAAuJ,YAAoC3J,EAAAA,yBAAyBC,4DA4C/C,UAAqB2J,OAAAA,EAAAZ,UAAQA,OACrC,MAAA7I,EAAaL,WAGjB+J,SACE,CAAAC,EACAC,aAGM,MAAAC,SAAcD,WAASH,SAAUA,EACjCK,SAAiBF,WAASf,YAAaA,SAEtCgB,EACH,OAAAlJ,EAAAX,EAAWK,eAAX,EAAAM,EAAqBoJ,iBACnB,CAAAN,OAAQI,EACRF,WACAd,UAAWiB,IAEb,OAAAnE,EAAW3F,EAAAK,mBAAU2J,eAAe,CAClCxJ,WACqB,IAAnBsJ,EACM,CAAA3G,KAAM,OAAQ0F,UAAWiB,GACzB,CAAA3G,KAAM,UACdwG,cAIZ"}
1
+ {"version":3,"file":"index.cjs","sources":["../../src/svelte/hooks/use-interaction-manager.svelte.ts","../../src/shared/utils.ts","../../src/svelte/components/GlobalPointerProvider.svelte","../../src/svelte/components/PagePointerProvider.svelte"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/svelte';\nimport {\n initialDocumentState,\n InteractionDocumentState,\n InteractionManagerPlugin,\n PointerEventHandlersWithLifecycle,\n} from '@embedpdf/plugin-interaction-manager';\n\nexport const useInteractionManagerPlugin = () =>\n usePlugin<InteractionManagerPlugin>(InteractionManagerPlugin.id);\nexport const useInteractionManagerCapability = () =>\n useCapability<InteractionManagerPlugin>(InteractionManagerPlugin.id);\n\nexport function useInteractionManager(documentId: string) {\n const capability = useInteractionManagerCapability();\n\n let state = $state<InteractionDocumentState>(initialDocumentState);\n\n // Derived scoped capability for the specific document\n const scopedProvides = $derived(capability.provides?.forDocument(documentId) ?? null);\n\n $effect(() => {\n if (!capability.provides) {\n state = initialDocumentState;\n return;\n }\n\n const scope = capability.provides.forDocument(documentId);\n\n // Get initial state\n state = scope.getState();\n\n return scope.onStateChange((newState) => {\n state = newState;\n });\n });\n\n return {\n get state() {\n return state;\n },\n get provides() {\n return scopedProvides;\n },\n };\n}\n\nexport function useCursor(documentId: string) {\n const capability = useInteractionManagerCapability();\n\n return {\n setCursor: (token: string, cursor: string, prio = 0) => {\n if (!capability.provides) return;\n const scope = capability.provides.forDocument(documentId);\n scope.setCursor(token, cursor, prio);\n },\n removeCursor: (token: string) => {\n if (!capability.provides) return;\n const scope = capability.provides.forDocument(documentId);\n scope.removeCursor(token);\n },\n };\n}\n\ninterface UsePointerHandlersOptions {\n modeId?: string | string[];\n pageIndex?: number;\n documentId: string;\n}\n\nexport function usePointerHandlers({ modeId, pageIndex, documentId }: UsePointerHandlersOptions) {\n const capability = useInteractionManagerCapability();\n\n return {\n register: (\n handlers: PointerEventHandlersWithLifecycle,\n options?: { modeId?: string | string[]; pageIndex?: number; documentId?: string },\n ) => {\n // Use provided options or fall back to hook-level options\n const finalModeId = options?.modeId ?? modeId;\n const finalPageIndex = options?.pageIndex ?? pageIndex;\n const finalDocumentId = options?.documentId ?? documentId;\n\n return finalModeId\n ? capability.provides?.registerHandlers({\n modeId: finalModeId,\n handlers,\n pageIndex: finalPageIndex,\n documentId: finalDocumentId,\n })\n : capability.provides?.registerAlways({\n scope:\n finalPageIndex !== undefined\n ? { type: 'page', documentId: finalDocumentId, pageIndex: finalPageIndex }\n : { type: 'global', documentId: finalDocumentId },\n handlers,\n });\n },\n };\n}\n\nexport function useIsPageExclusive(documentId: string) {\n const capability = useInteractionManagerCapability();\n\n let isPageExclusive = $state<boolean>(false);\n\n $effect(() => {\n if (!capability.provides) {\n isPageExclusive = false;\n return;\n }\n\n const scope = capability.provides.forDocument(documentId);\n\n // Get initial state\n const m = scope.getActiveInteractionMode();\n isPageExclusive = m?.scope === 'page' && !!m.exclusive;\n\n return scope.onModeChange(() => {\n const mode = scope.getActiveInteractionMode();\n isPageExclusive = mode?.scope === 'page' && !!mode?.exclusive;\n });\n });\n\n return {\n get current() {\n return isPageExclusive;\n },\n };\n}\n","import { Position } from '@embedpdf/models';\nimport type {\n InteractionManagerCapability,\n InteractionScope,\n PointerEventHandlers,\n EmbedPdfPointerEvent,\n InteractionExclusionRules,\n} from '@embedpdf/plugin-interaction-manager';\n\n/* -------------------------------------------------- */\n/* event → handler key lookup */\n/* -------------------------------------------------- */\ntype K = keyof PointerEventHandlers;\nconst domEventMap: Record<string, K> = {\n pointerdown: 'onPointerDown',\n pointerup: 'onPointerUp',\n pointermove: 'onPointerMove',\n pointerenter: 'onPointerEnter',\n pointerleave: 'onPointerLeave',\n pointercancel: 'onPointerCancel',\n\n mousedown: 'onMouseDown',\n mouseup: 'onMouseUp',\n mousemove: 'onMouseMove',\n mouseenter: 'onMouseEnter',\n mouseleave: 'onMouseLeave',\n mousecancel: 'onMouseCancel',\n\n click: 'onClick',\n dblclick: 'onDoubleClick',\n\n /* touch → pointer fallback for very old browsers */\n touchstart: 'onPointerDown',\n touchend: 'onPointerUp',\n touchmove: 'onPointerMove',\n touchcancel: 'onPointerCancel',\n};\n\nconst pointerEventTypes = [\n 'pointerdown',\n 'pointerup',\n 'pointermove',\n 'pointerenter',\n 'pointerleave',\n 'pointercancel',\n 'mousedown',\n 'mouseup',\n 'mousemove',\n 'mouseenter',\n 'mouseleave',\n 'mousecancel',\n 'click',\n 'dblclick',\n];\n\nconst touchEventTypes = ['touchstart', 'touchend', 'touchmove', 'touchcancel'];\nconst HAS_POINTER = typeof PointerEvent !== 'undefined';\n// If the browser supports Pointer Events, don't attach legacy touch events to avoid double-dispatch.\nconst allEventTypes = HAS_POINTER ? pointerEventTypes : [...pointerEventTypes, ...touchEventTypes];\n\n/* -------------------------------------------------- */\n/* helper: decide listener options per event type */\n/* -------------------------------------------------- */\nfunction listenerOpts(eventType: string, wantsRawTouch: boolean): AddEventListenerOptions {\n // Only touch events are toggled; pointer/mouse stay non-passive\n return eventType.startsWith('touch') ? { passive: !wantsRawTouch } : { passive: false };\n}\n\nfunction isTouchEvent(evt: Event): evt is TouchEvent {\n return typeof TouchEvent !== 'undefined' && evt instanceof TouchEvent;\n}\n\n/**\n * Check if an element should be excluded based on rules\n * This is in the framework layer, not the plugin\n */\nfunction shouldExcludeElement(element: Element | null, rules: InteractionExclusionRules): boolean {\n if (!element) return false;\n\n let current: Element | null = element;\n\n while (current) {\n // Check classes\n if (rules.classes?.length) {\n for (const className of rules.classes) {\n if (current.classList?.contains(className)) {\n return true;\n }\n }\n }\n\n // Check data attributes\n if (rules.dataAttributes?.length) {\n for (const attr of rules.dataAttributes) {\n if (current.hasAttribute(attr)) {\n return true;\n }\n }\n }\n\n // Move up the DOM tree\n current = current.parentElement;\n }\n\n return false;\n}\n\n/* -------------------------------------------------- */\n/* createPointerProvider */\n/* -------------------------------------------------- */\nexport function createPointerProvider(\n cap: InteractionManagerCapability,\n scope: InteractionScope,\n element: HTMLElement,\n convertEventToPoint?: (evt: PointerEvent, host: HTMLElement) => Position,\n) {\n const capScope = cap.forDocument(scope.documentId);\n /* ---------- live handler set --------------------------------------------------- */\n let active: PointerEventHandlers | null = cap.getHandlersForScope(scope);\n\n /* ---------- helper to compute current wantsRawTouch (defaults to true) --------- */\n const wantsRawTouchNow = () => capScope.getActiveInteractionMode()?.wantsRawTouch !== false; // default → true\n\n /* ---------- dynamic listener (re)attachment ------------------------------------ */\n const listeners: Record<string, (evt: Event) => void> = {};\n let attachedWithRawTouch = wantsRawTouchNow(); // remember current mode’s wish\n\n const addListeners = (raw: boolean) => {\n allEventTypes.forEach((type) => {\n const fn = (listeners[type] ??= handleEvent);\n element.addEventListener(type, fn, listenerOpts(type, raw));\n });\n };\n const removeListeners = () => {\n allEventTypes.forEach((type) => {\n const fn = listeners[type];\n if (fn) element.removeEventListener(type, fn);\n });\n };\n\n /* attach for the first time */\n addListeners(attachedWithRawTouch);\n element.style.touchAction = attachedWithRawTouch ? 'none' : '';\n\n /* ---------- mode & handler change hooks --------------------------------------- */\n const stopMode = capScope.onModeChange(() => {\n /* cursor baseline update for global wrapper */\n if (scope.type === 'global') {\n const mode = capScope.getActiveInteractionMode();\n element.style.cursor = mode?.scope === 'global' ? (mode.cursor ?? 'auto') : 'auto';\n }\n\n active = cap.getHandlersForScope(scope);\n\n /* re-attach listeners if wantsRawTouch toggled */\n const raw = wantsRawTouchNow();\n if (raw !== attachedWithRawTouch) {\n removeListeners();\n addListeners(raw);\n attachedWithRawTouch = raw;\n element.style.touchAction = attachedWithRawTouch ? 'none' : '';\n }\n });\n\n const stopHandler = cap.onHandlerChange(() => {\n active = cap.getHandlersForScope(scope);\n });\n\n /* ---------- cursor sync -------------------------------------------------------- */\n const initialMode = capScope.getActiveInteractionMode();\n const initialCursor = capScope.getCurrentCursor();\n element.style.cursor =\n scope.type === 'global' && initialMode?.scope !== 'global' ? 'auto' : initialCursor;\n\n const stopCursor = capScope.onCursorChange((c) => {\n if (scope.type === 'global' && capScope.getActiveInteractionMode()?.scope !== 'global') return;\n element.style.cursor = c;\n });\n\n /* ---------- point conversion --------------------------------------------------- */\n const toPos = (e: { clientX: number; clientY: number }, host: HTMLElement): Position => {\n if (convertEventToPoint) return convertEventToPoint(e as PointerEvent, host);\n const r = host.getBoundingClientRect();\n return { x: e.clientX - r.left, y: e.clientY - r.top };\n };\n\n /* ---------- central event handler --------------------------------------------- */\n function handleEvent(evt: Event) {\n if (cap.isPaused()) return;\n\n // Get exclusion rules from capability and check in framework layer\n const exclusionRules = cap.getExclusionRules();\n if (evt.target && shouldExcludeElement(evt.target as Element, exclusionRules)) {\n return; // Skip processing this event\n }\n\n const handlerKey = domEventMap[evt.type];\n if (!handlerKey || !active?.[handlerKey]) return;\n\n /* preventDefault only when mode really wants raw touch */\n if (\n isTouchEvent(evt) &&\n attachedWithRawTouch &&\n (evt.type === 'touchmove' || evt.type === 'touchcancel')\n ) {\n evt.preventDefault();\n }\n\n // ----- normalise ----------------------------------------------------------------\n let pos!: Position;\n let normEvt!: EmbedPdfPointerEvent & {\n target: EventTarget | null;\n currentTarget: EventTarget | null;\n };\n\n if (isTouchEvent(evt)) {\n const tp =\n evt.type === 'touchend' || evt.type === 'touchcancel'\n ? evt.changedTouches[0]\n : evt.touches[0];\n if (!tp) return;\n\n pos = toPos(tp, element);\n normEvt = {\n clientX: tp.clientX,\n clientY: tp.clientY,\n ctrlKey: evt.ctrlKey,\n shiftKey: evt.shiftKey,\n altKey: evt.altKey,\n metaKey: evt.metaKey,\n target: evt.target,\n currentTarget: evt.currentTarget,\n setPointerCapture: () => {},\n releasePointerCapture: () => {},\n };\n } else {\n const pe = evt as PointerEvent;\n pos = toPos(pe, element);\n normEvt = {\n clientX: pe.clientX,\n clientY: pe.clientY,\n ctrlKey: pe.ctrlKey,\n shiftKey: pe.shiftKey,\n altKey: pe.altKey,\n metaKey: pe.metaKey,\n target: pe.target,\n currentTarget: pe.currentTarget,\n setPointerCapture: () => {\n (pe.target as HTMLElement)?.setPointerCapture?.(pe.pointerId);\n },\n releasePointerCapture: () => {\n (pe.target as HTMLElement)?.releasePointerCapture?.(pe.pointerId);\n },\n };\n }\n\n active[handlerKey]?.(pos, normEvt, capScope.getActiveMode());\n }\n\n /* ---------- teardown ----------------------------------------------------------- */\n return () => {\n removeListeners();\n stopMode();\n stopCursor();\n stopHandler();\n };\n}\n","<script lang=\"ts\">\n import type { Snippet } from 'svelte';\n import type { HTMLAttributes } from 'svelte/elements';\n import { useInteractionManagerCapability } from '../hooks';\n import { createPointerProvider } from '../../shared/utils';\n\n interface GlobalPointerProviderProps extends HTMLAttributes<HTMLDivElement> {\n documentId: string;\n children: Snippet;\n class?: string;\n }\n\n let {\n documentId,\n children,\n class: propsClass,\n ...restProps\n }: GlobalPointerProviderProps = $props();\n\n let ref = $state<HTMLDivElement | null>(null);\n const interactionManagerCapability = useInteractionManagerCapability();\n\n $effect(() => {\n if (!interactionManagerCapability.provides || !ref) return;\n\n return createPointerProvider(\n interactionManagerCapability.provides,\n { type: 'global', documentId },\n ref,\n );\n });\n</script>\n\n<div bind:this={ref} style:width=\"100%\" style:height=\"100%\" class={propsClass} {...restProps}>\n {@render children()}\n</div>\n","<script lang=\"ts\">\n import { type Position, restorePosition, transformSize } from '@embedpdf/models';\n import { useDocumentState } from '@embedpdf/core/svelte';\n import type { Snippet } from 'svelte';\n import type { HTMLAttributes } from 'svelte/elements';\n import { createPointerProvider } from '../../shared/utils';\n import { useInteractionManagerCapability, useIsPageExclusive } from '../hooks';\n\n interface PagePointerProviderProps extends HTMLAttributes<HTMLDivElement> {\n documentId: string;\n pageIndex: number;\n rotation?: number;\n scale?: number;\n children: Snippet;\n class?: string;\n convertEventToPoint?: (event: PointerEvent, element: HTMLElement) => Position;\n }\n\n let {\n documentId,\n pageIndex,\n children,\n rotation: rotationOverride,\n scale: scaleOverride,\n convertEventToPoint,\n class: propsClass,\n ...restProps\n }: PagePointerProviderProps = $props();\n\n let ref = $state<HTMLDivElement | null>(null);\n\n const interactionManagerCapability = useInteractionManagerCapability();\n const isPageExclusive = useIsPageExclusive(documentId);\n const documentState = useDocumentState(() => documentId);\n\n // Get page dimensions and transformations from document state\n const page = $derived(documentState.current?.document?.pages?.[pageIndex]);\n const naturalPageSize = $derived(page?.size ?? { width: 0, height: 0 });\n const rotation = $derived(rotationOverride ?? documentState.current?.rotation ?? 0);\n const scale = $derived(scaleOverride ?? documentState.current?.scale ?? 1);\n const displaySize = $derived(transformSize(naturalPageSize, 0, scale));\n\n // Default conversion function\n const defaultConvertEventToPoint = $derived.by(() => {\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\n // Get the rotated natural size (width/height may be swapped, but not scaled)\n const rotatedNaturalSize = transformSize(\n {\n width: displaySize.width,\n height: displaySize.height,\n },\n rotation,\n 1,\n );\n\n return restorePosition(rotatedNaturalSize, displayPoint, rotation, scale);\n };\n });\n\n $effect(() => {\n if (!interactionManagerCapability.provides || !ref) return;\n\n return createPointerProvider(\n interactionManagerCapability.provides,\n { type: 'page', documentId, pageIndex },\n ref,\n convertEventToPoint || defaultConvertEventToPoint,\n );\n });\n</script>\n\n<div\n bind:this={ref}\n style:position=\"relative\"\n style:width={`${displaySize.width}px`}\n style:height={`${displaySize.height}px`}\n class={propsClass}\n {...restProps}\n>\n {@render children()}\n {#if isPageExclusive.current}\n <div\n style:position=\"absolute\"\n style:top=\"0\"\n style:left=\"0\"\n style:right=\"0\"\n style:bottom=\"0\"\n style:z-index=\"10\"\n ></div>\n {/if}\n</div>\n"],"names":["useInteractionManagerCapability","useCapability","InteractionManagerPlugin","id","useIsPageExclusive","documentId","capability","isPageExclusive","$","user_effect","provides","set","scope","forDocument","m","getActiveInteractionMode","exclusive","onModeChange","mode","current","domEventMap","pointerdown","pointerup","pointermove","pointerenter","pointerleave","pointercancel","mousedown","mouseup","mousemove","mouseenter","mouseleave","mousecancel","click","dblclick","touchstart","touchend","touchmove","touchcancel","pointerEventTypes","allEventTypes","PointerEvent","isTouchEvent","evt","TouchEvent","createPointerProvider","cap","element","convertEventToPoint","capScope","active","getHandlersForScope","wantsRawTouchNow","_a","wantsRawTouch","listeners","attachedWithRawTouch","addListeners","raw","forEach","type","fn","handleEvent","addEventListener","startsWith","passive","removeListeners","removeEventListener","style","touchAction","stopMode","cursor","stopHandler","onHandlerChange","initialMode","initialCursor","getCurrentCursor","stopCursor","onCursorChange","c","toPos","e","host","r","getBoundingClientRect","x","clientX","left","y","clientY","top","isPaused","exclusionRules","getExclusionRules","target","rules","classes","length","className","_b","classList","contains","_c","dataAttributes","attr","hasAttribute","parentElement","shouldExcludeElement","handlerKey","pos","normEvt","preventDefault","tp","changedTouches","touches","ctrlKey","shiftKey","altKey","metaKey","currentTarget","setPointerCapture","releasePointerCapture","pe","call","pointerId","getActiveMode","restProps","rest_props","$$props","ref","interactionManagerCapability","get","bind_this","div","$$value","documentState","useDocumentState","page","document","pages","pageIndex","naturalPageSize","derived","size","width","height","rotation","scale","displaySize","transformSize","defaultConvertEventToPoint","event","rect","displayPoint","rotatedNaturalSize","restorePosition","$$render","consequent","setCursor","token","prio","removeCursor","state","initialDocumentState","scopedProvides","getState","onStateChange","newState","usePlugin","modeId","register","handlers","options","finalModeId","finalPageIndex","finalDocumentId","registerHandlers","registerAlways"],"mappings":"ijBAUaA,EAAA,IACXC,gBAAwCC,EAAAA,yBAAyBC,aA0FnDC,EAAmBC,GAC3B,MAAAC,EAAaN,IAEf,IAAAO,WAAkC,UAEtCC,EAAAC,qBACOH,EAAWI,qBACdF,EAAAG,IAAAJ,GAAkB,GAId,MAAAK,EAAQN,EAAWI,SAASG,YAAYR,GAGxCS,EAAIF,EAAMG,wCAChBR,EAA+B,UAAb,MAAAO,OAAA,EAAAA,EAAGF,UAAsBE,EAAEE,WAAA,GAEtCJ,EAAMK,wBACLC,EAAON,EAAMG,iCACnBR,EAAkC,UAAhB,MAAAW,OAAA,EAAAA,EAAMN,WAAsB,MAAAM,OAAA,EAAAA,EAAMF,YAAA,QAKlD,WAAAG,gBACKZ,EACT,EAEJ,CCpHA,MAAMa,EAAiC,CACrCC,YAAa,gBACbC,UAAW,cACXC,YAAa,gBACbC,aAAc,iBACdC,aAAc,iBACdC,cAAe,kBAEfC,UAAW,cACXC,QAAS,YACTC,UAAW,cACXC,WAAY,eACZC,WAAY,eACZC,YAAa,gBAEbC,MAAO,UACPC,SAAU,gBAGVC,WAAY,gBACZC,SAAU,cACVC,UAAW,gBACXC,YAAa,mBAGTC,EAAoB,CACxB,cACA,YACA,cACA,eACA,eACA,gBACA,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aAGM,MAAAC,SAAcD,WAASH,SAAUA,EACjCK,SAAiBF,WAAShC,YAAaA,EACvCmC,SAAkBH,WAASvK,aAAcA,SAExCwK,EACH,OAAAxH,EAAA/C,EAAWI,eAAX,EAAA2C,EAAqB2H,iBAAA,CACnBP,OAAQI,EACRF,WACA/B,UAAWkC,EACXzK,WAAY0K,IAEd,OAAA5E,EAAA7F,EAAWI,eAAX,EAAAyF,EAAqB8E,eAAA,CACnBrK,WACE,IAAAkK,GACMlH,KAAM,OAAQvD,WAAY0K,EAAiBnC,UAAWkC,GACtD,CAAAlH,KAAM,SAAUvD,WAAY0K,GACpCJ,cAIZ"}
@@ -1,69 +1,98 @@
1
1
  import "svelte/internal/disclose-version";
2
2
  import * as $ from "svelte/internal/client";
3
- import { InteractionManagerPlugin, initialState } from "@embedpdf/plugin-interaction-manager";
3
+ import { useCapability, usePlugin, useDocumentState } from "@embedpdf/core/svelte";
4
+ import { InteractionManagerPlugin, initialDocumentState } from "@embedpdf/plugin-interaction-manager";
4
5
  export * from "@embedpdf/plugin-interaction-manager";
5
- import { useCapability, usePlugin } from "@embedpdf/core/svelte";
6
6
  import { transformSize, restorePosition } from "@embedpdf/models";
7
7
  const useInteractionManagerPlugin = () => usePlugin(InteractionManagerPlugin.id);
8
8
  const useInteractionManagerCapability = () => useCapability(InteractionManagerPlugin.id);
9
- function useInteractionManager() {
9
+ function useInteractionManager(documentId) {
10
10
  const capability = useInteractionManagerCapability();
11
- const state = $.proxy({
12
- get provides() {
13
- return capability.provides;
14
- },
15
- state: initialState
11
+ let state = $.state($.proxy(initialDocumentState));
12
+ const scopedProvides = $.derived(() => {
13
+ var _a;
14
+ return ((_a = capability.provides) == null ? void 0 : _a.forDocument(documentId)) ?? null;
16
15
  });
17
16
  $.user_effect(() => {
18
- if (!capability.provides) return;
19
- return capability.provides.onStateChange((newState) => {
20
- state.state = newState;
17
+ if (!capability.provides) {
18
+ $.set(state, initialDocumentState, true);
19
+ return;
20
+ }
21
+ const scope = capability.provides.forDocument(documentId);
22
+ $.set(state, scope.getState(), true);
23
+ return scope.onStateChange((newState) => {
24
+ $.set(state, newState, true);
21
25
  });
22
26
  });
23
- return state;
27
+ return {
28
+ get state() {
29
+ return $.get(state);
30
+ },
31
+ get provides() {
32
+ return $.get(scopedProvides);
33
+ }
34
+ };
24
35
  }
25
- function useCursor() {
36
+ function useCursor(documentId) {
26
37
  const capability = useInteractionManagerCapability();
27
- const state = $.proxy({
38
+ return {
28
39
  setCursor: (token, cursor, prio = 0) => {
29
- var _a;
30
- (_a = capability.provides) == null ? void 0 : _a.setCursor(token, cursor, prio);
40
+ if (!capability.provides) return;
41
+ const scope = capability.provides.forDocument(documentId);
42
+ scope.setCursor(token, cursor, prio);
31
43
  },
32
44
  removeCursor: (token) => {
33
- var _a;
34
- (_a = capability.provides) == null ? void 0 : _a.removeCursor(token);
45
+ if (!capability.provides) return;
46
+ const scope = capability.provides.forDocument(documentId);
47
+ scope.removeCursor(token);
35
48
  }
36
- });
37
- return state;
49
+ };
38
50
  }
39
- function usePointerHandlers({ modeId, pageIndex } = {}) {
51
+ function usePointerHandlers({ modeId, pageIndex, documentId }) {
40
52
  const capability = useInteractionManagerCapability();
41
53
  return {
42
54
  register: (handlers, options) => {
43
55
  var _a, _b;
44
56
  const finalModeId = (options == null ? void 0 : options.modeId) ?? modeId;
45
57
  const finalPageIndex = (options == null ? void 0 : options.pageIndex) ?? pageIndex;
46
- return finalModeId ? (_a = capability.provides) == null ? void 0 : _a.registerHandlers({ modeId: finalModeId, handlers, pageIndex: finalPageIndex }) : (_b = capability.provides) == null ? void 0 : _b.registerAlways({
47
- scope: finalPageIndex !== void 0 ? { type: "page", pageIndex: finalPageIndex } : { type: "global" },
58
+ const finalDocumentId = (options == null ? void 0 : options.documentId) ?? documentId;
59
+ return finalModeId ? (_a = capability.provides) == null ? void 0 : _a.registerHandlers({
60
+ modeId: finalModeId,
61
+ handlers,
62
+ pageIndex: finalPageIndex,
63
+ documentId: finalDocumentId
64
+ }) : (_b = capability.provides) == null ? void 0 : _b.registerAlways({
65
+ scope: finalPageIndex !== void 0 ? {
66
+ type: "page",
67
+ documentId: finalDocumentId,
68
+ pageIndex: finalPageIndex
69
+ } : { type: "global", documentId: finalDocumentId },
48
70
  handlers
49
71
  });
50
72
  }
51
73
  };
52
74
  }
53
- function useIsPageExclusive() {
75
+ function useIsPageExclusive(documentId) {
54
76
  const capability = useInteractionManagerCapability();
55
- const state = $.proxy({ isPageExclusive: false });
77
+ let isPageExclusive = $.state(false);
56
78
  $.user_effect(() => {
57
- if (!capability.provides) return;
58
- const mode = capability.provides.getActiveInteractionMode();
59
- state.isPageExclusive = (mode == null ? void 0 : mode.scope) === "page" && !!mode.exclusive;
60
- return capability.provides.onModeChange(() => {
61
- var _a;
62
- const mode2 = (_a = capability.provides) == null ? void 0 : _a.getActiveInteractionMode();
63
- state.isPageExclusive = (mode2 == null ? void 0 : mode2.scope) === "page" && !!(mode2 == null ? void 0 : mode2.exclusive);
79
+ if (!capability.provides) {
80
+ $.set(isPageExclusive, false);
81
+ return;
82
+ }
83
+ const scope = capability.provides.forDocument(documentId);
84
+ const m = scope.getActiveInteractionMode();
85
+ $.set(isPageExclusive, (m == null ? void 0 : m.scope) === "page" && !!m.exclusive, true);
86
+ return scope.onModeChange(() => {
87
+ const mode = scope.getActiveInteractionMode();
88
+ $.set(isPageExclusive, (mode == null ? void 0 : mode.scope) === "page" && !!(mode == null ? void 0 : mode.exclusive), true);
64
89
  });
65
90
  });
66
- return state;
91
+ return {
92
+ get current() {
93
+ return $.get(isPageExclusive);
94
+ }
95
+ };
67
96
  }
68
97
  const domEventMap = {
69
98
  pointerdown: "onPointerDown",
@@ -135,10 +164,11 @@ function shouldExcludeElement(element, rules) {
135
164
  return false;
136
165
  }
137
166
  function createPointerProvider(cap, scope, element, convertEventToPoint) {
167
+ const capScope = cap.forDocument(scope.documentId);
138
168
  let active = cap.getHandlersForScope(scope);
139
169
  const wantsRawTouchNow = () => {
140
170
  var _a;
141
- return ((_a = cap.getActiveInteractionMode()) == null ? void 0 : _a.wantsRawTouch) !== false;
171
+ return ((_a = capScope.getActiveInteractionMode()) == null ? void 0 : _a.wantsRawTouch) !== false;
142
172
  };
143
173
  const listeners = {};
144
174
  let attachedWithRawTouch = wantsRawTouchNow();
@@ -156,9 +186,9 @@ function createPointerProvider(cap, scope, element, convertEventToPoint) {
156
186
  };
157
187
  addListeners(attachedWithRawTouch);
158
188
  element.style.touchAction = attachedWithRawTouch ? "none" : "";
159
- const stopMode = cap.onModeChange(() => {
189
+ const stopMode = capScope.onModeChange(() => {
160
190
  if (scope.type === "global") {
161
- const mode = cap.getActiveInteractionMode();
191
+ const mode = capScope.getActiveInteractionMode();
162
192
  element.style.cursor = (mode == null ? void 0 : mode.scope) === "global" ? mode.cursor ?? "auto" : "auto";
163
193
  }
164
194
  active = cap.getHandlersForScope(scope);
@@ -173,12 +203,12 @@ function createPointerProvider(cap, scope, element, convertEventToPoint) {
173
203
  const stopHandler = cap.onHandlerChange(() => {
174
204
  active = cap.getHandlersForScope(scope);
175
205
  });
176
- const initialMode = cap.getActiveInteractionMode();
177
- const initialCursor = cap.getCurrentCursor();
206
+ const initialMode = capScope.getActiveInteractionMode();
207
+ const initialCursor = capScope.getCurrentCursor();
178
208
  element.style.cursor = scope.type === "global" && (initialMode == null ? void 0 : initialMode.scope) !== "global" ? "auto" : initialCursor;
179
- const stopCursor = cap.onCursorChange((c) => {
209
+ const stopCursor = capScope.onCursorChange((c) => {
180
210
  var _a;
181
- if (scope.type === "global" && ((_a = cap.getActiveInteractionMode()) == null ? void 0 : _a.scope) !== "global") return;
211
+ if (scope.type === "global" && ((_a = capScope.getActiveInteractionMode()) == null ? void 0 : _a.scope) !== "global") return;
182
212
  element.style.cursor = c;
183
213
  });
184
214
  const toPos = (e, host) => {
@@ -240,7 +270,7 @@ function createPointerProvider(cap, scope, element, convertEventToPoint) {
240
270
  }
241
271
  };
242
272
  }
243
- (_a = active[handlerKey]) == null ? void 0 : _a.call(active, pos, normEvt, cap.getActiveMode());
273
+ (_a = active[handlerKey]) == null ? void 0 : _a.call(active, pos, normEvt, capScope.getActiveMode());
244
274
  }
245
275
  return () => {
246
276
  removeListeners();
@@ -252,12 +282,19 @@ function createPointerProvider(cap, scope, element, convertEventToPoint) {
252
282
  var root$1 = $.from_html(`<div><!></div>`);
253
283
  function GlobalPointerProvider($$anchor, $$props) {
254
284
  $.push($$props, true);
255
- let restProps = $.rest_props($$props, ["$$slots", "$$events", "$$legacy", "children", "class"]);
285
+ let restProps = $.rest_props($$props, [
286
+ "$$slots",
287
+ "$$events",
288
+ "$$legacy",
289
+ "documentId",
290
+ "children",
291
+ "class"
292
+ ]);
256
293
  let ref = $.state(null);
257
294
  const interactionManagerCapability = useInteractionManagerCapability();
258
295
  $.user_effect(() => {
259
296
  if (!interactionManagerCapability.provides || !$.get(ref)) return;
260
- return createPointerProvider(interactionManagerCapability.provides, { type: "global" }, $.get(ref));
297
+ return createPointerProvider(interactionManagerCapability.provides, { type: "global", documentId: $$props.documentId }, $.get(ref));
261
298
  });
262
299
  var div = root$1();
263
300
  $.attribute_effect(div, () => ({
@@ -280,10 +317,9 @@ function PagePointerProvider($$anchor, $$props) {
280
317
  "$$slots",
281
318
  "$$events",
282
319
  "$$legacy",
320
+ "documentId",
283
321
  "pageIndex",
284
322
  "children",
285
- "pageWidth",
286
- "pageHeight",
287
323
  "rotation",
288
324
  "scale",
289
325
  "convertEventToPoint",
@@ -291,27 +327,63 @@ function PagePointerProvider($$anchor, $$props) {
291
327
  ]);
292
328
  let ref = $.state(null);
293
329
  const interactionManagerCapability = useInteractionManagerCapability();
294
- const isPageExclusive = useIsPageExclusive();
330
+ const isPageExclusive = useIsPageExclusive($$props.documentId);
331
+ const documentState = useDocumentState(() => $$props.documentId);
332
+ const page = $.derived(() => {
333
+ var _a, _b, _c;
334
+ return (_c = (_b = (_a = documentState.current) == null ? void 0 : _a.document) == null ? void 0 : _b.pages) == null ? void 0 : _c[$$props.pageIndex];
335
+ });
336
+ const naturalPageSize = $.derived(() => {
337
+ var _a;
338
+ return ((_a = $.get(page)) == null ? void 0 : _a.size) ?? { width: 0, height: 0 };
339
+ });
340
+ const rotation = $.derived(() => {
341
+ var _a;
342
+ return $$props.rotation ?? ((_a = documentState.current) == null ? void 0 : _a.rotation) ?? 0;
343
+ });
344
+ const scale = $.derived(() => {
345
+ var _a;
346
+ return $$props.scale ?? ((_a = documentState.current) == null ? void 0 : _a.scale) ?? 1;
347
+ });
348
+ const displaySize = $.derived(() => transformSize($.get(naturalPageSize), 0, $.get(scale)));
295
349
  const defaultConvertEventToPoint = $.derived(() => {
296
350
  return (event, element) => {
297
351
  const rect = element.getBoundingClientRect();
298
352
  const displayPoint = { x: event.clientX - rect.left, y: event.clientY - rect.top };
299
- const displaySize = transformSize({ width: $$props.pageWidth, height: $$props.pageHeight }, $$props.rotation, 1);
300
- return restorePosition(displaySize, displayPoint, $$props.rotation, $$props.scale);
353
+ const rotatedNaturalSize = transformSize(
354
+ {
355
+ width: $.get(displaySize).width,
356
+ height: $.get(displaySize).height
357
+ },
358
+ $.get(rotation),
359
+ 1
360
+ );
361
+ return restorePosition(rotatedNaturalSize, displayPoint, $.get(rotation), $.get(scale));
301
362
  };
302
363
  });
303
364
  $.user_effect(() => {
304
365
  if (!interactionManagerCapability.provides || !$.get(ref)) return;
305
- return createPointerProvider(interactionManagerCapability.provides, { type: "page", pageIndex: $$props.pageIndex }, $.get(ref), $$props.convertEventToPoint || $.get(defaultConvertEventToPoint));
366
+ return createPointerProvider(
367
+ interactionManagerCapability.provides,
368
+ {
369
+ type: "page",
370
+ documentId: $$props.documentId,
371
+ pageIndex: $$props.pageIndex
372
+ },
373
+ $.get(ref),
374
+ $$props.convertEventToPoint || $.get(defaultConvertEventToPoint)
375
+ );
306
376
  });
307
377
  var div = root();
308
- $.attribute_effect(div, ($0) => ({ class: $$props.class, ...restProps, [$.STYLE]: $0 }), [
309
- () => ({
378
+ $.attribute_effect(div, () => ({
379
+ class: $$props.class,
380
+ ...restProps,
381
+ [$.STYLE]: {
310
382
  position: "relative",
311
- width: `${$$props.pageWidth}px`,
312
- height: `${$$props.pageHeight}px`
313
- })
314
- ]);
383
+ width: `${$.get(displaySize).width}px`,
384
+ height: `${$.get(displaySize).height}px`
385
+ }
386
+ }));
315
387
  var node = $.child(div);
316
388
  $.snippet(node, () => $$props.children);
317
389
  var node_1 = $.sibling(node, 2);
@@ -329,7 +401,7 @@ function PagePointerProvider($$anchor, $$props) {
329
401
  $.append($$anchor2, div_1);
330
402
  };
331
403
  $.if(node_1, ($$render) => {
332
- if (isPageExclusive) $$render(consequent);
404
+ if (isPageExclusive.current) $$render(consequent);
333
405
  });
334
406
  }
335
407
  $.reset(div);