@embedpdf/plugin-interaction-manager 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,23 +1,29 @@
1
1
  import { JSX, ComponentChildren } from 'preact';
2
2
  import { Position } from '@embedpdf/models';
3
3
  import * as _embedpdf_plugin_interaction_manager from '@embedpdf/plugin-interaction-manager';
4
- import { InteractionManagerPlugin, PointerEventHandlers } from '@embedpdf/plugin-interaction-manager';
4
+ import { InteractionManagerPlugin, InteractionManagerState, PointerEventHandlers } from '@embedpdf/plugin-interaction-manager';
5
5
 
6
6
  /** @jsxImportSource preact */
7
7
 
8
8
  interface GlobalPointerProviderProps extends JSX.HTMLAttributes<HTMLDivElement> {
9
9
  children: ComponentChildren;
10
+ style?: JSX.CSSProperties;
10
11
  }
11
- declare const GlobalPointerProvider: ({ children, ...props }: GlobalPointerProviderProps) => JSX.Element;
12
+ declare const GlobalPointerProvider: ({ children, style, ...props }: GlobalPointerProviderProps) => JSX.Element;
12
13
 
13
14
  /** @jsxImportSource preact */
14
15
 
15
16
  interface PagePointerProviderProps extends JSX.HTMLAttributes<HTMLDivElement> {
16
17
  children: ComponentChildren;
17
18
  pageIndex: number;
19
+ pageWidth: number;
20
+ pageHeight: number;
21
+ rotation: number;
22
+ scale: number;
23
+ style?: JSX.CSSProperties;
18
24
  convertEventToPoint?: (event: PointerEvent, element: HTMLElement) => Position;
19
25
  }
20
- declare const PagePointerProvider: ({ pageIndex, children, convertEventToPoint, ...props }: PagePointerProviderProps) => JSX.Element;
26
+ declare const PagePointerProvider: ({ pageIndex, children, pageWidth, pageHeight, rotation, scale, convertEventToPoint, style, ...props }: PagePointerProviderProps) => JSX.Element;
21
27
 
22
28
  declare const useInteractionManagerPlugin: () => {
23
29
  plugin: InteractionManagerPlugin | null;
@@ -29,6 +35,10 @@ declare const useInteractionManagerCapability: () => {
29
35
  isLoading: boolean;
30
36
  ready: Promise<void>;
31
37
  };
38
+ declare function useInteractionManager(): {
39
+ provides: Readonly<_embedpdf_plugin_interaction_manager.InteractionManagerCapability> | null;
40
+ state: InteractionManagerState;
41
+ };
32
42
  declare function useCursor(): {
33
43
  setCursor: (token: string, cursor: string, prio?: number) => void;
34
44
  removeCursor: (token: string) => void;
@@ -42,4 +52,4 @@ declare function usePointerHandlers({ modeId, pageIndex }: UsePointerHandlersOpt
42
52
  };
43
53
  declare function useIsPageExclusive(): boolean;
44
54
 
45
- export { GlobalPointerProvider, PagePointerProvider, useCursor, useInteractionManagerCapability, useInteractionManagerPlugin, useIsPageExclusive, usePointerHandlers };
55
+ export { GlobalPointerProvider, PagePointerProvider, useCursor, useInteractionManager, useInteractionManagerCapability, useInteractionManagerPlugin, useIsPageExclusive, usePointerHandlers };
@@ -8,12 +8,26 @@ import { useEffect as useEffect2, useRef } from "preact/hooks";
8
8
  // src/preact/hooks/use-interaction-manager.ts
9
9
  import { useCapability, usePlugin } from "@embedpdf/core/preact";
10
10
  import {
11
+ initialState,
11
12
  InteractionManagerPlugin
12
13
  } from "@embedpdf/plugin-interaction-manager";
13
- import { useState } from "preact/hooks";
14
- import { useEffect } from "preact/hooks";
14
+ import { useState, useEffect } from "preact/hooks";
15
15
  var useInteractionManagerPlugin = () => usePlugin(InteractionManagerPlugin.id);
16
16
  var useInteractionManagerCapability = () => useCapability(InteractionManagerPlugin.id);
17
+ function useInteractionManager() {
18
+ const { provides } = useInteractionManagerCapability();
19
+ const [state, setState] = useState(initialState);
20
+ useEffect(() => {
21
+ if (!provides) return;
22
+ return provides.onStateChange((state2) => {
23
+ setState(state2);
24
+ });
25
+ }, [provides]);
26
+ return {
27
+ provides,
28
+ state
29
+ };
30
+ }
17
31
  function useCursor() {
18
32
  const { provides } = useInteractionManagerCapability();
19
33
  return {
@@ -52,46 +66,99 @@ function useIsPageExclusive() {
52
66
 
53
67
  // src/preact/components/global-pointer-provider.tsx
54
68
  import { jsx } from "preact/jsx-runtime";
55
- var GlobalPointerProvider = ({ children, ...props }) => {
69
+ var GlobalPointerProvider = ({
70
+ children,
71
+ style,
72
+ ...props
73
+ }) => {
56
74
  const ref = useRef(null);
57
75
  const { provides: cap } = useInteractionManagerCapability();
58
76
  useEffect2(() => {
59
77
  if (!cap || !ref.current) return;
60
78
  return createPointerProvider(cap, { type: "global" }, ref.current);
61
79
  }, [cap]);
62
- return /* @__PURE__ */ jsx("div", { ref, ...props, children });
80
+ return /* @__PURE__ */ jsx(
81
+ "div",
82
+ {
83
+ ref,
84
+ style: {
85
+ width: "100%",
86
+ height: "100%",
87
+ ...style
88
+ },
89
+ ...props,
90
+ children
91
+ }
92
+ );
63
93
  };
64
94
 
65
95
  // src/preact/components/page-pointer-provider.tsx
66
- import { useEffect as useEffect3, useRef as useRef2 } from "preact/hooks";
96
+ import { useCallback, useEffect as useEffect3, useRef as useRef2 } from "preact/hooks";
97
+ import { restorePosition } from "@embedpdf/models";
67
98
  import { jsx as jsx2, jsxs } from "preact/jsx-runtime";
68
99
  var PagePointerProvider = ({
69
100
  pageIndex,
70
101
  children,
102
+ pageWidth,
103
+ pageHeight,
104
+ rotation,
105
+ scale,
71
106
  convertEventToPoint,
107
+ style,
72
108
  ...props
73
109
  }) => {
74
110
  const ref = useRef2(null);
75
111
  const { provides: cap } = useInteractionManagerCapability();
76
112
  const isPageExclusive = useIsPageExclusive();
113
+ const defaultConvertEventToPoint = useCallback(
114
+ (event, element) => {
115
+ const rect = element.getBoundingClientRect();
116
+ const displayPoint = {
117
+ x: event.clientX - rect.left,
118
+ y: event.clientY - rect.top
119
+ };
120
+ return restorePosition(
121
+ { width: pageWidth, height: pageHeight },
122
+ displayPoint,
123
+ rotation,
124
+ scale
125
+ );
126
+ },
127
+ [pageWidth, pageHeight, rotation, scale]
128
+ );
77
129
  useEffect3(() => {
78
130
  if (!cap || !ref.current) return;
79
131
  return createPointerProvider(
80
132
  cap,
81
133
  { type: "page", pageIndex },
82
134
  ref.current,
83
- convertEventToPoint
135
+ convertEventToPoint || defaultConvertEventToPoint
84
136
  );
85
- }, [cap, pageIndex, convertEventToPoint]);
86
- return /* @__PURE__ */ jsxs("div", { ref, ...props, children: [
87
- children,
88
- isPageExclusive && /* @__PURE__ */ jsx2("div", { style: { position: "absolute", top: 0, left: 0, right: 0, bottom: 0 } })
89
- ] });
137
+ }, [cap, pageIndex, convertEventToPoint, defaultConvertEventToPoint]);
138
+ return /* @__PURE__ */ jsxs(
139
+ "div",
140
+ {
141
+ ref,
142
+ style: {
143
+ position: "absolute",
144
+ inset: 0,
145
+ mixBlendMode: "multiply",
146
+ isolation: "isolate",
147
+ ...style
148
+ },
149
+ ...props,
150
+ children: [
151
+ children,
152
+ isPageExclusive && /* @__PURE__ */ jsx2("div", { style: { position: "absolute", top: 0, left: 0, right: 0, bottom: 0 } })
153
+ ]
154
+ }
155
+ );
90
156
  };
91
157
  export {
92
158
  GlobalPointerProvider,
93
159
  PagePointerProvider,
94
160
  useCursor,
161
+ useInteractionManager,
95
162
  useInteractionManagerCapability,
96
163
  useInteractionManagerPlugin,
97
164
  useIsPageExclusive,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/preact/components/global-pointer-provider.tsx","../../src/preact/hooks/use-interaction-manager.ts","../../src/preact/components/page-pointer-provider.tsx"],"sourcesContent":["/** @jsxImportSource preact */\nimport { ComponentChildren, JSX } from 'preact';\nimport { useEffect, useRef } from 'preact/hooks';\nimport { createPointerProvider } from '../../shared/utils';\n\nimport { useInteractionManagerCapability } from '../hooks';\n\ninterface GlobalPointerProviderProps extends JSX.HTMLAttributes<HTMLDivElement> {\n children: ComponentChildren;\n}\n\nexport const GlobalPointerProvider = ({ children, ...props }: 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 ref={ref} {...props}>\n {children}\n </div>\n );\n};\n","import { useCapability, usePlugin } from '@embedpdf/core/preact';\nimport {\n InteractionManagerPlugin,\n PointerEventHandlers,\n} from '@embedpdf/plugin-interaction-manager';\nimport { useState } from 'preact/hooks';\nimport { useEffect } from 'preact/hooks';\n\nexport const useInteractionManagerPlugin = () =>\n usePlugin<InteractionManagerPlugin>(InteractionManagerPlugin.id);\nexport const useInteractionManagerCapability = () =>\n useCapability<InteractionManagerPlugin>(InteractionManagerPlugin.id);\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;\n pageIndex?: number;\n}\n\nexport function usePointerHandlers({ modeId, pageIndex }: UsePointerHandlersOptions) {\n const { provides } = useInteractionManagerCapability();\n return {\n register: modeId\n ? (handlers: PointerEventHandlers) =>\n provides?.registerHandlers({ modeId, handlers, pageIndex })\n : (handlers: PointerEventHandlers) =>\n provides?.registerAlways({\n scope: pageIndex !== undefined ? { type: 'page', pageIndex } : { type: 'global' },\n handlers,\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","/** @jsxImportSource preact */\nimport { ComponentChildren, JSX } from 'preact';\nimport { useEffect, useRef } from 'preact/hooks';\nimport { Position } from '@embedpdf/models';\nimport { createPointerProvider } from '../../shared/utils';\n\nimport { useInteractionManagerCapability, useIsPageExclusive } from '../hooks';\n\ninterface PagePointerProviderProps extends JSX.HTMLAttributes<HTMLDivElement> {\n children: ComponentChildren;\n pageIndex: number;\n convertEventToPoint?: (event: PointerEvent, element: HTMLElement) => Position;\n}\n\nexport const PagePointerProvider = ({\n pageIndex,\n children,\n convertEventToPoint,\n ...props\n}: PagePointerProviderProps) => {\n const ref = useRef<HTMLDivElement>(null);\n const { provides: cap } = useInteractionManagerCapability();\n const isPageExclusive = useIsPageExclusive();\n\n useEffect(() => {\n if (!cap || !ref.current) return;\n\n return createPointerProvider(\n cap,\n { type: 'page', pageIndex },\n ref.current,\n convertEventToPoint,\n );\n }, [cap, pageIndex, convertEventToPoint]);\n\n return (\n <div ref={ref} {...props}>\n {children}\n {isPageExclusive && (\n <div style={{ position: 'absolute', top: 0, left: 0, right: 0, bottom: 0 }} />\n )}\n </div>\n );\n};\n"],"mappings":";;;;;AAEA,SAAS,aAAAA,YAAW,cAAc;;;ACFlC,SAAS,eAAe,iBAAiB;AACzC;AAAA,EACE;AAAA,OAEK;AACP,SAAS,gBAAgB;AACzB,SAAS,iBAAiB;AAEnB,IAAM,8BAA8B,MACzC,UAAoC,yBAAyB,EAAE;AAC1D,IAAM,kCAAkC,MAC7C,cAAwC,yBAAyB,EAAE;AAE9D,SAAS,YAAY;AAC1B,QAAM,EAAE,SAAS,IAAI,gCAAgC;AACrD,SAAO;AAAA,IACL,WAAW,CAAC,OAAe,QAAgB,OAAO,MAAM;AACtD,gBAAU,UAAU,OAAO,QAAQ,IAAI;AAAA,IACzC;AAAA,IACA,cAAc,CAAC,UAAkB;AAC/B,gBAAU,aAAa,KAAK;AAAA,IAC9B;AAAA,EACF;AACF;AAOO,SAAS,mBAAmB,EAAE,QAAQ,UAAU,GAA8B;AACnF,QAAM,EAAE,SAAS,IAAI,gCAAgC;AACrD,SAAO;AAAA,IACL,UAAU,SACN,CAAC,aACC,UAAU,iBAAiB,EAAE,QAAQ,UAAU,UAAU,CAAC,IAC5D,CAAC,aACC,UAAU,eAAe;AAAA,MACvB,OAAO,cAAc,SAAY,EAAE,MAAM,QAAQ,UAAU,IAA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,MACL;AAAA,MACA,EAAE,MAAM,QAAQ,UAAU;AAAA,MAC1B,IAAI;AAAA,MACJ;AAAA,IACF;AAAA,EACF,GAAG,CAAC,KAAK,WAAW,mBAAmB,CAAC;AAExC,SACE,qBAAC,SAAI,KAAW,GAAG,OAChB;AAAA;AAAA,IACA,mBACC,gBAAAF,KAAC,SAAI,OAAO,EAAE,UAAU,YAAY,KAAK,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,EAAE,GAAG;AAAA,KAEhF;AAEJ;","names":["useEffect","useEffect","useEffect","useRef","jsx","useRef","useEffect"]}
1
+ {"version":3,"sources":["../../src/preact/components/global-pointer-provider.tsx","../../src/preact/hooks/use-interaction-manager.ts","../../src/preact/components/page-pointer-provider.tsx"],"sourcesContent":["/** @jsxImportSource preact */\nimport { ComponentChildren, JSX } from 'preact';\nimport { useEffect, useRef } from 'preact/hooks';\nimport { createPointerProvider } from '../../shared/utils';\n\nimport { useInteractionManagerCapability } from '../hooks';\n\ninterface GlobalPointerProviderProps extends JSX.HTMLAttributes<HTMLDivElement> {\n children: ComponentChildren;\n style?: JSX.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 { useCapability, usePlugin } from '@embedpdf/core/preact';\nimport {\n initialState,\n InteractionManagerPlugin,\n InteractionManagerState,\n PointerEventHandlers,\n} from '@embedpdf/plugin-interaction-manager';\nimport { useState, useEffect } from 'preact/hooks';\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;\n pageIndex?: number;\n}\n\nexport function usePointerHandlers({ modeId, pageIndex }: UsePointerHandlersOptions) {\n const { provides } = useInteractionManagerCapability();\n return {\n register: modeId\n ? (handlers: PointerEventHandlers) =>\n provides?.registerHandlers({ modeId, handlers, pageIndex })\n : (handlers: PointerEventHandlers) =>\n provides?.registerAlways({\n scope: pageIndex !== undefined ? { type: 'page', pageIndex } : { type: 'global' },\n handlers,\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","/** @jsxImportSource preact */\nimport { ComponentChildren, JSX } from 'preact';\nimport { useCallback, useEffect, useRef } from 'preact/hooks';\nimport { Position, restorePosition } from '@embedpdf/models';\nimport { createPointerProvider } from '../../shared/utils';\n\nimport { useInteractionManagerCapability, useIsPageExclusive } from '../hooks';\n\ninterface PagePointerProviderProps extends JSX.HTMLAttributes<HTMLDivElement> {\n children: ComponentChildren;\n pageIndex: number;\n pageWidth: number;\n pageHeight: number;\n rotation: number;\n scale: number;\n style?: JSX.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 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 position: 'absolute',\n inset: 0,\n mixBlendMode: 'multiply',\n isolation: 'isolate',\n ...style,\n }}\n {...props}\n >\n {children}\n {isPageExclusive && (\n <div style={{ position: 'absolute', top: 0, left: 0, right: 0, bottom: 0 }} />\n )}\n </div>\n );\n};\n"],"mappings":";;;;;AAEA,SAAS,aAAAA,YAAW,cAAc;;;ACFlC,SAAS,eAAe,iBAAiB;AACzC;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AACP,SAAS,UAAU,iBAAiB;AAE7B,IAAM,8BAA8B,MACzC,UAAoC,yBAAyB,EAAE;AAC1D,IAAM,kCAAkC,MAC7C,cAAwC,yBAAyB,EAAE;AAE9D,SAAS,wBAAwB;AACtC,QAAM,EAAE,SAAS,IAAI,gCAAgC;AACrD,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAkC,YAAY;AAExE,YAAU,MAAM;AAC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CAAC,IAAI,QAAS;AAE1B,WAAO;AAAA,MACL;AAAA,MACA,EAAE,MAAM,QAAQ,UAAU;AAAA,MAC1B,IAAI;AAAA,MACJ,uBAAuB;AAAA,IACzB;AAAA,EACF,GAAG,CAAC,KAAK,WAAW,qBAAqB,0BAA0B,CAAC;AAEpE,SACE;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA,OAAO;AAAA,QACL,UAAU;AAAA,QACV,OAAO;AAAA,QACP,cAAc;AAAA,QACd,WAAW;AAAA,QACX,GAAG;AAAA,MACL;AAAA,MACC,GAAG;AAAA,MAEH;AAAA;AAAA,QACA,mBACC,gBAAAF,KAAC,SAAI,OAAO,EAAE,UAAU,YAAY,KAAK,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,EAAE,GAAG;AAAA;AAAA;AAAA,EAEhF;AAEJ;","names":["useEffect","state","useEffect","useEffect","useRef","jsx","useRef","useEffect"]}
@@ -23,6 +23,7 @@ __export(react_exports, {
23
23
  GlobalPointerProvider: () => GlobalPointerProvider,
24
24
  PagePointerProvider: () => PagePointerProvider,
25
25
  useCursor: () => useCursor,
26
+ useInteractionManager: () => useInteractionManager,
26
27
  useInteractionManagerCapability: () => useInteractionManagerCapability,
27
28
  useInteractionManagerPlugin: () => useInteractionManagerPlugin,
28
29
  useIsPageExclusive: () => useIsPageExclusive,
@@ -36,6 +37,20 @@ var import_plugin_interaction_manager = require("@embedpdf/plugin-interaction-ma
36
37
  var import_react2 = require("react");
37
38
  var useInteractionManagerPlugin = () => (0, import_react.usePlugin)(import_plugin_interaction_manager.InteractionManagerPlugin.id);
38
39
  var useInteractionManagerCapability = () => (0, import_react.useCapability)(import_plugin_interaction_manager.InteractionManagerPlugin.id);
40
+ function useInteractionManager() {
41
+ const { provides } = useInteractionManagerCapability();
42
+ const [state, setState] = (0, import_react2.useState)(import_plugin_interaction_manager.initialState);
43
+ (0, import_react2.useEffect)(() => {
44
+ if (!provides) return;
45
+ return provides.onStateChange((state2) => {
46
+ setState(state2);
47
+ });
48
+ }, [provides]);
49
+ return {
50
+ provides,
51
+ state
52
+ };
53
+ }
39
54
  function useCursor() {
40
55
  const { provides } = useInteractionManagerCapability();
41
56
  return {
@@ -135,47 +150,100 @@ function createPointerProvider(cap, scope, element, convertEventToPoint) {
135
150
 
136
151
  // src/react/components/global-pointer-provider.tsx
137
152
  var import_jsx_runtime = require("react/jsx-runtime");
138
- var GlobalPointerProvider = ({ children, ...props }) => {
153
+ var GlobalPointerProvider = ({
154
+ children,
155
+ style,
156
+ ...props
157
+ }) => {
139
158
  const ref = (0, import_react3.useRef)(null);
140
159
  const { provides: cap } = useInteractionManagerCapability();
141
160
  (0, import_react3.useEffect)(() => {
142
161
  if (!cap || !ref.current) return;
143
162
  return createPointerProvider(cap, { type: "global" }, ref.current);
144
163
  }, [cap]);
145
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { ref, ...props, children });
164
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
165
+ "div",
166
+ {
167
+ ref,
168
+ style: {
169
+ width: "100%",
170
+ height: "100%",
171
+ ...style
172
+ },
173
+ ...props,
174
+ children
175
+ }
176
+ );
146
177
  };
147
178
 
148
179
  // src/react/components/page-pointer-provider.tsx
149
180
  var import_react4 = require("react");
181
+ var import_models = require("@embedpdf/models");
150
182
  var import_jsx_runtime2 = require("react/jsx-runtime");
151
183
  var PagePointerProvider = ({
152
184
  pageIndex,
153
185
  children,
186
+ pageWidth,
187
+ pageHeight,
188
+ rotation,
189
+ scale,
154
190
  convertEventToPoint,
191
+ style,
155
192
  ...props
156
193
  }) => {
157
194
  const ref = (0, import_react4.useRef)(null);
158
195
  const { provides: cap } = useInteractionManagerCapability();
159
196
  const isPageExclusive = useIsPageExclusive();
197
+ const defaultConvertEventToPoint = (0, import_react4.useCallback)(
198
+ (event, element) => {
199
+ const rect = element.getBoundingClientRect();
200
+ const displayPoint = {
201
+ x: event.clientX - rect.left,
202
+ y: event.clientY - rect.top
203
+ };
204
+ return (0, import_models.restorePosition)(
205
+ { width: pageWidth, height: pageHeight },
206
+ displayPoint,
207
+ rotation,
208
+ scale
209
+ );
210
+ },
211
+ [pageWidth, pageHeight, rotation, scale]
212
+ );
160
213
  (0, import_react4.useEffect)(() => {
161
214
  if (!cap || !ref.current) return;
162
215
  return createPointerProvider(
163
216
  cap,
164
217
  { type: "page", pageIndex },
165
218
  ref.current,
166
- convertEventToPoint
219
+ convertEventToPoint || defaultConvertEventToPoint
167
220
  );
168
- }, [cap, pageIndex, convertEventToPoint]);
169
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { ref, ...props, children: [
170
- children,
171
- isPageExclusive && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { style: { position: "absolute", top: 0, left: 0, right: 0, bottom: 0 } })
172
- ] });
221
+ }, [cap, pageIndex, convertEventToPoint, defaultConvertEventToPoint]);
222
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
223
+ "div",
224
+ {
225
+ ref,
226
+ style: {
227
+ position: "absolute",
228
+ inset: 0,
229
+ mixBlendMode: "multiply",
230
+ isolation: "isolate",
231
+ ...style
232
+ },
233
+ ...props,
234
+ children: [
235
+ children,
236
+ isPageExclusive && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { style: { position: "absolute", top: 0, left: 0, right: 0, bottom: 0 } })
237
+ ]
238
+ }
239
+ );
173
240
  };
174
241
  // Annotate the CommonJS export names for ESM import in node:
175
242
  0 && (module.exports = {
176
243
  GlobalPointerProvider,
177
244
  PagePointerProvider,
178
245
  useCursor,
246
+ useInteractionManager,
179
247
  useInteractionManagerCapability,
180
248
  useInteractionManagerPlugin,
181
249
  useIsPageExclusive,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/react/index.ts","../../src/react/hooks/use-interaction-manager.ts","../../src/react/components/global-pointer-provider.tsx","../../src/shared/utils.ts","../../src/react/components/page-pointer-provider.tsx"],"sourcesContent":["export * from './hooks';\nexport * from './components';\n","import { useCapability, usePlugin } from '@embedpdf/core/react';\nimport {\n InteractionManagerPlugin,\n PointerEventHandlers,\n} from '@embedpdf/plugin-interaction-manager';\nimport { useState, useEffect } from 'react';\n\nexport const useInteractionManagerPlugin = () =>\n usePlugin<InteractionManagerPlugin>(InteractionManagerPlugin.id);\nexport const useInteractionManagerCapability = () =>\n useCapability<InteractionManagerPlugin>(InteractionManagerPlugin.id);\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;\n pageIndex?: number;\n}\n\nexport function usePointerHandlers({ modeId, pageIndex }: UsePointerHandlersOptions) {\n const { provides } = useInteractionManagerCapability();\n return {\n register: modeId\n ? (handlers: PointerEventHandlers) =>\n provides?.registerHandlers({ modeId, handlers, pageIndex })\n : (handlers: PointerEventHandlers) =>\n provides?.registerAlways({\n scope: pageIndex !== undefined ? { type: 'page', pageIndex } : { type: 'global' },\n handlers,\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 { ReactNode, useEffect, useRef } from 'react';\nimport { createPointerProvider } from '../../shared/utils';\n\nimport { useInteractionManagerCapability } from '../hooks';\n\ninterface GlobalPointerProviderProps extends React.HTMLAttributes<HTMLDivElement> {\n children: ReactNode;\n}\n\nexport const GlobalPointerProvider = ({ children, ...props }: 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 ref={ref} {...props}>\n {children}\n </div>\n );\n};\n","import { Position } from '@embedpdf/models';\nimport type {\n InteractionManagerCapability,\n InteractionScope,\n PointerEventHandlers,\n} from '@embedpdf/plugin-interaction-manager';\n\n/**\n * Hook one DOM element into the interaction-manager.\n * – keeps handlers & cursor in-sync with the current mode\n * – returns a teardown fn for React/Preact effects\n */\nexport function createPointerProvider(\n cap: InteractionManagerCapability,\n scope: InteractionScope,\n element: HTMLElement,\n convertEventToPoint?: (evt: PointerEvent, host: HTMLElement) => Position,\n) {\n /* ------------------------------------------------------------------ */\n /* active handler set – hot-swapped on every mode change */\n /* ------------------------------------------------------------------ */\n let active: PointerEventHandlers | null = cap.getHandlersForScope(scope);\n\n const stopMode = cap.onModeChange(() => {\n if (scope.type === 'global') {\n const mode = cap.getActiveInteractionMode();\n element.style.cursor = mode?.scope === 'global' ? (mode.cursor ?? 'auto') : 'auto';\n }\n active = cap.getHandlersForScope(scope);\n });\n\n const stopHandler = cap.onHandlerChange(() => {\n active = cap.getHandlersForScope(scope);\n });\n\n /* ------------------------------------------------------------------ */\n /* cursor */\n /* ------------------------------------------------------------------ */\n const modeNow = cap.getActiveInteractionMode();\n const cursorNow = cap.getCurrentCursor();\n\n /** initial cursor -------------------------------------------------- */\n if (scope.type === 'global') {\n // global wrapper only shows the cursor while a *global* mode is active\n element.style.cursor = modeNow?.scope === 'global' ? cursorNow : 'auto';\n } else {\n // page wrappers always mirror the latest cursor\n element.style.cursor = cursorNow;\n }\n\n const stopCursor = cap.onCursorChange((c) => {\n /** ❖ Propagation rule\n * ─────────────────\n * • global provider updates its cursor *only* while the active\n * mode itself is ‘global’.\n * • page providers always sync (so they show the cursor during\n * a global mode as well). */\n if (scope.type === 'global') {\n const isGlobalMode = cap.getActiveInteractionMode()?.scope === 'global';\n if (!isGlobalMode) return; // active mode is page-scoped → ignore\n }\n element.style.cursor = c;\n });\n\n /* ------------------------------------------------------------------ */\n /* event wiring */\n /* ------------------------------------------------------------------ */\n type K = keyof PointerEventHandlers;\n const domEvent: Record<K, keyof HTMLElementEventMap> = {\n onPointerDown: 'pointerdown',\n onPointerUp: 'pointerup',\n onPointerMove: 'pointermove',\n onPointerEnter: 'pointerenter',\n onPointerLeave: 'pointerleave',\n onPointerCancel: 'pointercancel',\n };\n\n /* one stable EventListener per key -> needed for removeEventListener */\n const listeners: Partial<Record<K, EventListener>> = {};\n\n const toPos = (e: PointerEvent, host: HTMLElement): Position => {\n if (convertEventToPoint) return convertEventToPoint(e, host);\n const r = host.getBoundingClientRect();\n return { x: e.clientX - r.left, y: e.clientY - r.top };\n };\n\n (Object.keys(domEvent) as K[]).forEach((k) => {\n listeners[k] = (evt: Event) => {\n const pe = evt as PointerEvent; // safe – we only attach to pointer*\n active?.[k]?.(toPos(pe, element), pe);\n /* if you need to stop default behaviour when no handler is active:\n * if (!active?.[k]) pe.preventDefault(); */\n };\n element.addEventListener(domEvent[k], listeners[k]!);\n });\n\n /* ------------------------------------------------------------------ */\n /* teardown */\n /* ------------------------------------------------------------------ */\n return () => {\n (Object.keys(domEvent) as K[]).forEach((k) =>\n element.removeEventListener(domEvent[k], listeners[k]!),\n );\n stopMode();\n stopCursor();\n stopHandler();\n };\n}\n","import { ReactNode, useEffect, useRef } from 'react';\nimport { Position } from '@embedpdf/models';\nimport { createPointerProvider } from '../../shared/utils';\n\nimport { useInteractionManagerCapability, useIsPageExclusive } from '../hooks';\n\ninterface PagePointerProviderProps extends React.HTMLAttributes<HTMLDivElement> {\n children: ReactNode;\n pageIndex: number;\n convertEventToPoint?: (event: PointerEvent, element: HTMLElement) => Position;\n}\n\nexport const PagePointerProvider = ({\n pageIndex,\n children,\n convertEventToPoint,\n ...props\n}: PagePointerProviderProps) => {\n const ref = useRef<HTMLDivElement>(null);\n const { provides: cap } = useInteractionManagerCapability();\n const isPageExclusive = useIsPageExclusive();\n\n useEffect(() => {\n if (!cap || !ref.current) return;\n\n return createPointerProvider(\n cap,\n { type: 'page', pageIndex },\n ref.current,\n convertEventToPoint,\n );\n }, [cap, pageIndex, convertEventToPoint]);\n\n return (\n <div ref={ref} {...props}>\n {children}\n {isPageExclusive && (\n <div style={{ position: 'absolute', top: 0, left: 0, right: 0, bottom: 0 }} />\n )}\n </div>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAAyC;AACzC,wCAGO;AACP,IAAAA,gBAAoC;AAE7B,IAAM,8BAA8B,UACzC,wBAAoC,2DAAyB,EAAE;AAC1D,IAAM,kCAAkC,UAC7C,4BAAwC,2DAAyB,EAAE;AAE9D,SAAS,YAAY;AAC1B,QAAM,EAAE,SAAS,IAAI,gCAAgC;AACrD,SAAO;AAAA,IACL,WAAW,CAAC,OAAe,QAAgB,OAAO,MAAM;AACtD,gBAAU,UAAU,OAAO,QAAQ,IAAI;AAAA,IACzC;AAAA,IACA,cAAc,CAAC,UAAkB;AAC/B,gBAAU,aAAa,KAAK;AAAA,IAC9B;AAAA,EACF;AACF;AAOO,SAAS,mBAAmB,EAAE,QAAQ,UAAU,GAA8B;AACnF,QAAM,EAAE,SAAS,IAAI,gCAAgC;AACrD,SAAO;AAAA,IACL,UAAU,SACN,CAAC,aACC,UAAU,iBAAiB,EAAE,QAAQ,UAAU,UAAU,CAAC,IAC5D,CAAC,aACC,UAAU,eAAe;AAAA,MACvB,OAAO,cAAc,SAAY,EAAE,MAAM,QAAQ,UAAU,IAAI,EAAE,MAAM,SAAS;AAAA,MAChF;AAAA,IACF,CAAC;AAAA,EACT;AACF;AAEO,SAAS,qBAAqB;AACnC,QAAM,EAAE,UAAU,IAAI,IAAI,gCAAgC;AAE1D,QAAM,CAAC,iBAAiB,kBAAkB,QAAI,wBAAkB,MAAM;AACpE,UAAM,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C;AAC9B,QAAM,UAAM,sBAAuB,IAAI;AACvC,QAAM,EAAE,UAAU,IAAI,IAAI,gCAAgC;AAC1D,QAAM,kBAAkB,mBAAmB;AAE3C,+BAAU,MAAM;AACd,QAAI,CAAC,OAAO,CAAC,IAAI,QAAS;AAE1B,WAAO;AAAA,MACL;AAAA,MACA,EAAE,MAAM,QAAQ,UAAU;AAAA,MAC1B,IAAI;AAAA,MACJ;AAAA,IACF;AAAA,EACF,GAAG,CAAC,KAAK,WAAW,mBAAmB,CAAC;AAExC,SACE,8CAAC,SAAI,KAAW,GAAG,OAChB;AAAA;AAAA,IACA,mBACC,6CAAC,SAAI,OAAO,EAAE,UAAU,YAAY,KAAK,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,EAAE,GAAG;AAAA,KAEhF;AAEJ;","names":["import_react","import_react","import_react","import_jsx_runtime"]}
1
+ {"version":3,"sources":["../../src/react/index.ts","../../src/react/hooks/use-interaction-manager.ts","../../src/react/components/global-pointer-provider.tsx","../../src/shared/utils.ts","../../src/react/components/page-pointer-provider.tsx"],"sourcesContent":["export * from './hooks';\nexport * from './components';\n","import { useCapability, usePlugin } from '@embedpdf/core/react';\nimport {\n initialState,\n InteractionManagerPlugin,\n InteractionManagerState,\n PointerEventHandlers,\n} from '@embedpdf/plugin-interaction-manager';\nimport { useState, useEffect } from 'react';\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;\n pageIndex?: number;\n}\n\nexport function usePointerHandlers({ modeId, pageIndex }: UsePointerHandlersOptions) {\n const { provides } = useInteractionManagerCapability();\n return {\n register: modeId\n ? (handlers: PointerEventHandlers) =>\n provides?.registerHandlers({ modeId, handlers, pageIndex })\n : (handlers: PointerEventHandlers) =>\n provides?.registerAlways({\n scope: pageIndex !== undefined ? { type: 'page', pageIndex } : { type: 'global' },\n handlers,\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 { ReactNode, useEffect, useRef } from 'react';\nimport { createPointerProvider } from '../../shared/utils';\n\nimport { useInteractionManagerCapability } from '../hooks';\n\ninterface GlobalPointerProviderProps extends React.HTMLAttributes<HTMLDivElement> {\n children: ReactNode;\n style?: React.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 { Position } from '@embedpdf/models';\nimport type {\n InteractionManagerCapability,\n InteractionScope,\n PointerEventHandlers,\n} from '@embedpdf/plugin-interaction-manager';\n\n/**\n * Hook one DOM element into the interaction-manager.\n * – keeps handlers & cursor in-sync with the current mode\n * – returns a teardown fn for React/Preact effects\n */\nexport function createPointerProvider(\n cap: InteractionManagerCapability,\n scope: InteractionScope,\n element: HTMLElement,\n convertEventToPoint?: (evt: PointerEvent, host: HTMLElement) => Position,\n) {\n /* ------------------------------------------------------------------ */\n /* active handler set – hot-swapped on every mode change */\n /* ------------------------------------------------------------------ */\n let active: PointerEventHandlers | null = cap.getHandlersForScope(scope);\n\n const stopMode = cap.onModeChange(() => {\n if (scope.type === 'global') {\n const mode = cap.getActiveInteractionMode();\n element.style.cursor = mode?.scope === 'global' ? (mode.cursor ?? 'auto') : 'auto';\n }\n active = cap.getHandlersForScope(scope);\n });\n\n const stopHandler = cap.onHandlerChange(() => {\n active = cap.getHandlersForScope(scope);\n });\n\n /* ------------------------------------------------------------------ */\n /* cursor */\n /* ------------------------------------------------------------------ */\n const modeNow = cap.getActiveInteractionMode();\n const cursorNow = cap.getCurrentCursor();\n\n /** initial cursor -------------------------------------------------- */\n if (scope.type === 'global') {\n // global wrapper only shows the cursor while a *global* mode is active\n element.style.cursor = modeNow?.scope === 'global' ? cursorNow : 'auto';\n } else {\n // page wrappers always mirror the latest cursor\n element.style.cursor = cursorNow;\n }\n\n const stopCursor = cap.onCursorChange((c) => {\n /** ❖ Propagation rule\n * ─────────────────\n * • global provider updates its cursor *only* while the active\n * mode itself is ‘global’.\n * • page providers always sync (so they show the cursor during\n * a global mode as well). */\n if (scope.type === 'global') {\n const isGlobalMode = cap.getActiveInteractionMode()?.scope === 'global';\n if (!isGlobalMode) return; // active mode is page-scoped → ignore\n }\n element.style.cursor = c;\n });\n\n /* ------------------------------------------------------------------ */\n /* event wiring */\n /* ------------------------------------------------------------------ */\n type K = keyof PointerEventHandlers;\n const domEvent: Record<K, keyof HTMLElementEventMap> = {\n onPointerDown: 'pointerdown',\n onPointerUp: 'pointerup',\n onPointerMove: 'pointermove',\n onPointerEnter: 'pointerenter',\n onPointerLeave: 'pointerleave',\n onPointerCancel: 'pointercancel',\n };\n\n /* one stable EventListener per key -> needed for removeEventListener */\n const listeners: Partial<Record<K, EventListener>> = {};\n\n const toPos = (e: PointerEvent, host: HTMLElement): Position => {\n if (convertEventToPoint) return convertEventToPoint(e, host);\n const r = host.getBoundingClientRect();\n return { x: e.clientX - r.left, y: e.clientY - r.top };\n };\n\n (Object.keys(domEvent) as K[]).forEach((k) => {\n listeners[k] = (evt: Event) => {\n const pe = evt as PointerEvent; // safe – we only attach to pointer*\n active?.[k]?.(toPos(pe, element), pe);\n /* if you need to stop default behaviour when no handler is active:\n * if (!active?.[k]) pe.preventDefault(); */\n };\n element.addEventListener(domEvent[k], listeners[k]!);\n });\n\n /* ------------------------------------------------------------------ */\n /* teardown */\n /* ------------------------------------------------------------------ */\n return () => {\n (Object.keys(domEvent) as K[]).forEach((k) =>\n element.removeEventListener(domEvent[k], listeners[k]!),\n );\n stopMode();\n stopCursor();\n stopHandler();\n };\n}\n","import { ReactNode, useEffect, useRef, useCallback } from 'react';\nimport { Position, restorePosition } from '@embedpdf/models';\nimport { createPointerProvider } from '../../shared/utils';\n\nimport { useInteractionManagerCapability, useIsPageExclusive } from '../hooks';\n\ninterface PagePointerProviderProps extends React.HTMLAttributes<HTMLDivElement> {\n children: ReactNode;\n pageIndex: number;\n pageWidth: number;\n pageHeight: number;\n rotation: number;\n scale: number;\n style?: React.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 position: 'absolute',\n inset: 0,\n mixBlendMode: 'multiply',\n isolation: 'isolate',\n ...style,\n }}\n {...props}\n >\n {children}\n {isPageExclusive && (\n <div style={{ position: 'absolute', top: 0, left: 0, right: 0, bottom: 0 }} />\n )}\n </div>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAAyC;AACzC,wCAKO;AACP,IAAAA,gBAAoC;AAE7B,IAAM,8BAA8B,UACzC,wBAAoC,2DAAyB,EAAE;AAC1D,IAAM,kCAAkC,UAC7C,4BAAwC,2DAAyB,EAAE;AAE9D,SAAS,wBAAwB;AACtC,QAAM,EAAE,SAAS,IAAI,gCAAgC;AACrD,QAAM,CAAC,OAAO,QAAQ,QAAI,wBAAkC,8CAAY;AAExE,+BAAU,MAAM;AACd,QAAI,CAAC,SAAU;AACf,WAAO,SAAS,cAAc,CAACC,WAAU;AACvC,eAASA,MAAK;AAAA,IAChB,CAAC;AAAA,EACH,GAAG,CAAC,QAAQ,CAAC;AAEb,SAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;AAEO,SAAS,YAAY;AAC1B,QAAM,EAAE,SAAS,IAAI,gCAAgC;AACrD,SAAO;AAAA,IACL,WAAW,CAAC,OAAe,QAAgB,OAAO,MAAM;AACtD,gBAAU,UAAU,OAAO,QAAQ,IAAI;AAAA,IACzC;AAAA,IACA,cAAc,CAAC,UAAkB;AAC/B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IAAI,QAAS;AAE1B,WAAO;AAAA,MACL;AAAA,MACA,EAAE,MAAM,QAAQ,UAAU;AAAA,MAC1B,IAAI;AAAA,MACJ,uBAAuB;AAAA,IACzB;AAAA,EACF,GAAG,CAAC,KAAK,WAAW,qBAAqB,0BAA0B,CAAC;AAEpE,SACE;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA,OAAO;AAAA,QACL,UAAU;AAAA,QACV,OAAO;AAAA,QACP,cAAc;AAAA,QACd,WAAW;AAAA,QACX,GAAG;AAAA,MACL;AAAA,MACC,GAAG;AAAA,MAEH;AAAA;AAAA,QACA,mBACC,6CAAC,SAAI,OAAO,EAAE,UAAU,YAAY,KAAK,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,EAAE,GAAG;AAAA;AAAA;AAAA,EAEhF;AAEJ;","names":["import_react","state","import_react","import_react","import_jsx_runtime"]}
@@ -1,5 +1,5 @@
1
1
  import * as _embedpdf_plugin_interaction_manager from '@embedpdf/plugin-interaction-manager';
2
- import { InteractionManagerPlugin, PointerEventHandlers } from '@embedpdf/plugin-interaction-manager';
2
+ import { InteractionManagerPlugin, InteractionManagerState, PointerEventHandlers } from '@embedpdf/plugin-interaction-manager';
3
3
  import * as react_jsx_runtime from 'react/jsx-runtime';
4
4
  import { ReactNode } from 'react';
5
5
  import { Position } from '@embedpdf/models';
@@ -14,6 +14,10 @@ declare const useInteractionManagerCapability: () => {
14
14
  isLoading: boolean;
15
15
  ready: Promise<void>;
16
16
  };
17
+ declare function useInteractionManager(): {
18
+ provides: Readonly<_embedpdf_plugin_interaction_manager.InteractionManagerCapability> | null;
19
+ state: InteractionManagerState;
20
+ };
17
21
  declare function useCursor(): {
18
22
  setCursor: (token: string, cursor: string, prio?: number) => void;
19
23
  removeCursor: (token: string) => void;
@@ -29,14 +33,20 @@ declare function useIsPageExclusive(): boolean;
29
33
 
30
34
  interface GlobalPointerProviderProps extends React.HTMLAttributes<HTMLDivElement> {
31
35
  children: ReactNode;
36
+ style?: React.CSSProperties;
32
37
  }
33
- declare const GlobalPointerProvider: ({ children, ...props }: GlobalPointerProviderProps) => react_jsx_runtime.JSX.Element;
38
+ declare const GlobalPointerProvider: ({ children, style, ...props }: GlobalPointerProviderProps) => react_jsx_runtime.JSX.Element;
34
39
 
35
40
  interface PagePointerProviderProps extends React.HTMLAttributes<HTMLDivElement> {
36
41
  children: ReactNode;
37
42
  pageIndex: number;
43
+ pageWidth: number;
44
+ pageHeight: number;
45
+ rotation: number;
46
+ scale: number;
47
+ style?: React.CSSProperties;
38
48
  convertEventToPoint?: (event: PointerEvent, element: HTMLElement) => Position;
39
49
  }
40
- declare const PagePointerProvider: ({ pageIndex, children, convertEventToPoint, ...props }: PagePointerProviderProps) => react_jsx_runtime.JSX.Element;
50
+ declare const PagePointerProvider: ({ pageIndex, children, pageWidth, pageHeight, rotation, scale, convertEventToPoint, style, ...props }: PagePointerProviderProps) => react_jsx_runtime.JSX.Element;
41
51
 
42
- export { GlobalPointerProvider, PagePointerProvider, useCursor, useInteractionManagerCapability, useInteractionManagerPlugin, useIsPageExclusive, usePointerHandlers };
52
+ export { GlobalPointerProvider, PagePointerProvider, useCursor, useInteractionManager, useInteractionManagerCapability, useInteractionManagerPlugin, useIsPageExclusive, usePointerHandlers };
@@ -1,5 +1,5 @@
1
1
  import * as _embedpdf_plugin_interaction_manager from '@embedpdf/plugin-interaction-manager';
2
- import { InteractionManagerPlugin, PointerEventHandlers } from '@embedpdf/plugin-interaction-manager';
2
+ import { InteractionManagerPlugin, InteractionManagerState, PointerEventHandlers } from '@embedpdf/plugin-interaction-manager';
3
3
  import * as react_jsx_runtime from 'react/jsx-runtime';
4
4
  import { ReactNode } from 'react';
5
5
  import { Position } from '@embedpdf/models';
@@ -14,6 +14,10 @@ declare const useInteractionManagerCapability: () => {
14
14
  isLoading: boolean;
15
15
  ready: Promise<void>;
16
16
  };
17
+ declare function useInteractionManager(): {
18
+ provides: Readonly<_embedpdf_plugin_interaction_manager.InteractionManagerCapability> | null;
19
+ state: InteractionManagerState;
20
+ };
17
21
  declare function useCursor(): {
18
22
  setCursor: (token: string, cursor: string, prio?: number) => void;
19
23
  removeCursor: (token: string) => void;
@@ -29,14 +33,20 @@ declare function useIsPageExclusive(): boolean;
29
33
 
30
34
  interface GlobalPointerProviderProps extends React.HTMLAttributes<HTMLDivElement> {
31
35
  children: ReactNode;
36
+ style?: React.CSSProperties;
32
37
  }
33
- declare const GlobalPointerProvider: ({ children, ...props }: GlobalPointerProviderProps) => react_jsx_runtime.JSX.Element;
38
+ declare const GlobalPointerProvider: ({ children, style, ...props }: GlobalPointerProviderProps) => react_jsx_runtime.JSX.Element;
34
39
 
35
40
  interface PagePointerProviderProps extends React.HTMLAttributes<HTMLDivElement> {
36
41
  children: ReactNode;
37
42
  pageIndex: number;
43
+ pageWidth: number;
44
+ pageHeight: number;
45
+ rotation: number;
46
+ scale: number;
47
+ style?: React.CSSProperties;
38
48
  convertEventToPoint?: (event: PointerEvent, element: HTMLElement) => Position;
39
49
  }
40
- declare const PagePointerProvider: ({ pageIndex, children, convertEventToPoint, ...props }: PagePointerProviderProps) => react_jsx_runtime.JSX.Element;
50
+ declare const PagePointerProvider: ({ pageIndex, children, pageWidth, pageHeight, rotation, scale, convertEventToPoint, style, ...props }: PagePointerProviderProps) => react_jsx_runtime.JSX.Element;
41
51
 
42
- export { GlobalPointerProvider, PagePointerProvider, useCursor, useInteractionManagerCapability, useInteractionManagerPlugin, useIsPageExclusive, usePointerHandlers };
52
+ export { GlobalPointerProvider, PagePointerProvider, useCursor, useInteractionManager, useInteractionManagerCapability, useInteractionManagerPlugin, useIsPageExclusive, usePointerHandlers };
@@ -5,11 +5,26 @@ import {
5
5
  // src/react/hooks/use-interaction-manager.ts
6
6
  import { useCapability, usePlugin } from "@embedpdf/core/react";
7
7
  import {
8
+ initialState,
8
9
  InteractionManagerPlugin
9
10
  } from "@embedpdf/plugin-interaction-manager";
10
11
  import { useState, useEffect } from "react";
11
12
  var useInteractionManagerPlugin = () => usePlugin(InteractionManagerPlugin.id);
12
13
  var useInteractionManagerCapability = () => useCapability(InteractionManagerPlugin.id);
14
+ function useInteractionManager() {
15
+ const { provides } = useInteractionManagerCapability();
16
+ const [state, setState] = useState(initialState);
17
+ useEffect(() => {
18
+ if (!provides) return;
19
+ return provides.onStateChange((state2) => {
20
+ setState(state2);
21
+ });
22
+ }, [provides]);
23
+ return {
24
+ provides,
25
+ state
26
+ };
27
+ }
13
28
  function useCursor() {
14
29
  const { provides } = useInteractionManagerCapability();
15
30
  return {
@@ -49,46 +64,99 @@ function useIsPageExclusive() {
49
64
  // src/react/components/global-pointer-provider.tsx
50
65
  import { useEffect as useEffect2, useRef } from "react";
51
66
  import { jsx } from "react/jsx-runtime";
52
- var GlobalPointerProvider = ({ children, ...props }) => {
67
+ var GlobalPointerProvider = ({
68
+ children,
69
+ style,
70
+ ...props
71
+ }) => {
53
72
  const ref = useRef(null);
54
73
  const { provides: cap } = useInteractionManagerCapability();
55
74
  useEffect2(() => {
56
75
  if (!cap || !ref.current) return;
57
76
  return createPointerProvider(cap, { type: "global" }, ref.current);
58
77
  }, [cap]);
59
- return /* @__PURE__ */ jsx("div", { ref, ...props, children });
78
+ return /* @__PURE__ */ jsx(
79
+ "div",
80
+ {
81
+ ref,
82
+ style: {
83
+ width: "100%",
84
+ height: "100%",
85
+ ...style
86
+ },
87
+ ...props,
88
+ children
89
+ }
90
+ );
60
91
  };
61
92
 
62
93
  // src/react/components/page-pointer-provider.tsx
63
- import { useEffect as useEffect3, useRef as useRef2 } from "react";
94
+ import { useEffect as useEffect3, useRef as useRef2, useCallback } from "react";
95
+ import { restorePosition } from "@embedpdf/models";
64
96
  import { jsx as jsx2, jsxs } from "react/jsx-runtime";
65
97
  var PagePointerProvider = ({
66
98
  pageIndex,
67
99
  children,
100
+ pageWidth,
101
+ pageHeight,
102
+ rotation,
103
+ scale,
68
104
  convertEventToPoint,
105
+ style,
69
106
  ...props
70
107
  }) => {
71
108
  const ref = useRef2(null);
72
109
  const { provides: cap } = useInteractionManagerCapability();
73
110
  const isPageExclusive = useIsPageExclusive();
111
+ const defaultConvertEventToPoint = useCallback(
112
+ (event, element) => {
113
+ const rect = element.getBoundingClientRect();
114
+ const displayPoint = {
115
+ x: event.clientX - rect.left,
116
+ y: event.clientY - rect.top
117
+ };
118
+ return restorePosition(
119
+ { width: pageWidth, height: pageHeight },
120
+ displayPoint,
121
+ rotation,
122
+ scale
123
+ );
124
+ },
125
+ [pageWidth, pageHeight, rotation, scale]
126
+ );
74
127
  useEffect3(() => {
75
128
  if (!cap || !ref.current) return;
76
129
  return createPointerProvider(
77
130
  cap,
78
131
  { type: "page", pageIndex },
79
132
  ref.current,
80
- convertEventToPoint
133
+ convertEventToPoint || defaultConvertEventToPoint
81
134
  );
82
- }, [cap, pageIndex, convertEventToPoint]);
83
- return /* @__PURE__ */ jsxs("div", { ref, ...props, children: [
84
- children,
85
- isPageExclusive && /* @__PURE__ */ jsx2("div", { style: { position: "absolute", top: 0, left: 0, right: 0, bottom: 0 } })
86
- ] });
135
+ }, [cap, pageIndex, convertEventToPoint, defaultConvertEventToPoint]);
136
+ return /* @__PURE__ */ jsxs(
137
+ "div",
138
+ {
139
+ ref,
140
+ style: {
141
+ position: "absolute",
142
+ inset: 0,
143
+ mixBlendMode: "multiply",
144
+ isolation: "isolate",
145
+ ...style
146
+ },
147
+ ...props,
148
+ children: [
149
+ children,
150
+ isPageExclusive && /* @__PURE__ */ jsx2("div", { style: { position: "absolute", top: 0, left: 0, right: 0, bottom: 0 } })
151
+ ]
152
+ }
153
+ );
87
154
  };
88
155
  export {
89
156
  GlobalPointerProvider,
90
157
  PagePointerProvider,
91
158
  useCursor,
159
+ useInteractionManager,
92
160
  useInteractionManagerCapability,
93
161
  useInteractionManagerPlugin,
94
162
  useIsPageExclusive,