@embedpdf/plugin-interaction-manager 1.0.11 → 1.0.12

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 (56) hide show
  1. package/dist/index.cjs +2 -359
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.d.ts +1 -177
  4. package/dist/index.js +39 -41
  5. package/dist/index.js.map +1 -1
  6. package/dist/lib/actions.d.ts +28 -0
  7. package/dist/lib/helper.d.ts +2 -0
  8. package/dist/lib/index.d.ts +9 -0
  9. package/dist/lib/interaction-manager-plugin.d.ts +38 -0
  10. package/dist/lib/manifest.d.ts +4 -0
  11. package/dist/lib/reducer.d.ts +5 -0
  12. package/dist/{index.d.cts → lib/types.d.ts} +12 -83
  13. package/dist/preact/adapter.d.ts +4 -0
  14. package/dist/preact/core.d.ts +1 -0
  15. package/dist/preact/index.cjs +2 -258
  16. package/dist/preact/index.cjs.map +1 -1
  17. package/dist/preact/index.d.ts +1 -58
  18. package/dist/preact/index.js +83 -40
  19. package/dist/preact/index.js.map +1 -1
  20. package/dist/react/adapter.d.ts +2 -0
  21. package/dist/react/core.d.ts +1 -0
  22. package/dist/react/index.cjs +2 -258
  23. package/dist/react/index.cjs.map +1 -1
  24. package/dist/react/index.d.ts +1 -55
  25. package/dist/react/index.js +83 -38
  26. package/dist/react/index.js.map +1 -1
  27. package/dist/shared-preact/components/global-pointer-provider.d.ts +7 -0
  28. package/dist/shared-preact/components/index.d.ts +2 -0
  29. package/dist/shared-preact/components/page-pointer-provider.d.ts +14 -0
  30. package/dist/shared-preact/hooks/index.d.ts +1 -0
  31. package/dist/shared-preact/hooks/use-interaction-manager.d.ts +31 -0
  32. package/dist/shared-preact/index.d.ts +2 -0
  33. package/dist/shared-preact/utils.d.ts +8 -0
  34. package/dist/shared-react/components/global-pointer-provider.d.ts +7 -0
  35. package/dist/shared-react/components/index.d.ts +2 -0
  36. package/dist/shared-react/components/page-pointer-provider.d.ts +14 -0
  37. package/dist/shared-react/hooks/index.d.ts +1 -0
  38. package/dist/shared-react/hooks/use-interaction-manager.d.ts +31 -0
  39. package/dist/shared-react/index.d.ts +2 -0
  40. package/dist/shared-react/utils.d.ts +8 -0
  41. package/dist/shared-vue/utils.d.ts +8 -0
  42. package/dist/vue/components/global-pointer-provider.vue.d.ts +12 -0
  43. package/dist/vue/components/index.d.ts +2 -0
  44. package/dist/vue/components/page-pointer-provider.vue.d.ts +21 -0
  45. package/dist/vue/hooks/index.d.ts +1 -0
  46. package/dist/vue/hooks/use-interaction-manager.d.ts +31 -0
  47. package/dist/vue/index.cjs +2 -0
  48. package/dist/vue/index.cjs.map +1 -0
  49. package/dist/vue/index.d.ts +2 -0
  50. package/dist/vue/index.js +222 -0
  51. package/dist/vue/index.js.map +1 -0
  52. package/package.json +19 -11
  53. package/dist/chunk-Z7V2G6MS.js +0 -64
  54. package/dist/chunk-Z7V2G6MS.js.map +0 -1
  55. package/dist/preact/index.d.cts +0 -58
  56. package/dist/react/index.d.cts +0 -55
@@ -1,258 +1,2 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/preact/index.ts
21
- var preact_exports = {};
22
- __export(preact_exports, {
23
- GlobalPointerProvider: () => GlobalPointerProvider,
24
- PagePointerProvider: () => PagePointerProvider,
25
- useCursor: () => useCursor,
26
- useInteractionManager: () => useInteractionManager,
27
- useInteractionManagerCapability: () => useInteractionManagerCapability,
28
- useInteractionManagerPlugin: () => useInteractionManagerPlugin,
29
- useIsPageExclusive: () => useIsPageExclusive,
30
- usePointerHandlers: () => usePointerHandlers
31
- });
32
- module.exports = __toCommonJS(preact_exports);
33
-
34
- // src/preact/components/global-pointer-provider.tsx
35
- var import_hooks2 = require("preact/hooks");
36
-
37
- // src/shared/utils.ts
38
- function createPointerProvider(cap, scope, element, convertEventToPoint) {
39
- let active = cap.getHandlersForScope(scope);
40
- const stopMode = cap.onModeChange(() => {
41
- if (scope.type === "global") {
42
- const mode = cap.getActiveInteractionMode();
43
- element.style.cursor = mode?.scope === "global" ? mode.cursor ?? "auto" : "auto";
44
- }
45
- active = cap.getHandlersForScope(scope);
46
- });
47
- const stopHandler = cap.onHandlerChange(() => {
48
- active = cap.getHandlersForScope(scope);
49
- });
50
- const modeNow = cap.getActiveInteractionMode();
51
- const cursorNow = cap.getCurrentCursor();
52
- if (scope.type === "global") {
53
- element.style.cursor = modeNow?.scope === "global" ? cursorNow : "auto";
54
- } else {
55
- element.style.cursor = cursorNow;
56
- }
57
- const stopCursor = cap.onCursorChange((c) => {
58
- if (scope.type === "global") {
59
- const isGlobalMode = cap.getActiveInteractionMode()?.scope === "global";
60
- if (!isGlobalMode) return;
61
- }
62
- element.style.cursor = c;
63
- });
64
- const domEvent = {
65
- onPointerDown: "pointerdown",
66
- onPointerUp: "pointerup",
67
- onPointerMove: "pointermove",
68
- onPointerEnter: "pointerenter",
69
- onPointerLeave: "pointerleave",
70
- onPointerCancel: "pointercancel"
71
- };
72
- const listeners = {};
73
- const toPos = (e, host) => {
74
- if (convertEventToPoint) return convertEventToPoint(e, host);
75
- const r = host.getBoundingClientRect();
76
- return { x: e.clientX - r.left, y: e.clientY - r.top };
77
- };
78
- Object.keys(domEvent).forEach((k) => {
79
- listeners[k] = (evt) => {
80
- if (cap.isPaused()) return;
81
- const pe = evt;
82
- const currentModeId = cap.getActiveMode();
83
- active?.[k]?.(toPos(pe, element), pe, currentModeId);
84
- };
85
- element.addEventListener(domEvent[k], listeners[k]);
86
- });
87
- return () => {
88
- Object.keys(domEvent).forEach(
89
- (k) => element.removeEventListener(domEvent[k], listeners[k])
90
- );
91
- stopMode();
92
- stopCursor();
93
- stopHandler();
94
- };
95
- }
96
-
97
- // src/preact/hooks/use-interaction-manager.ts
98
- var import_preact = require("@embedpdf/core/preact");
99
- var import_plugin_interaction_manager = require("@embedpdf/plugin-interaction-manager");
100
- var import_hooks = require("preact/hooks");
101
- var useInteractionManagerPlugin = () => (0, import_preact.usePlugin)(import_plugin_interaction_manager.InteractionManagerPlugin.id);
102
- var useInteractionManagerCapability = () => (0, import_preact.useCapability)(import_plugin_interaction_manager.InteractionManagerPlugin.id);
103
- function useInteractionManager() {
104
- const { provides } = useInteractionManagerCapability();
105
- const [state, setState] = (0, import_hooks.useState)(import_plugin_interaction_manager.initialState);
106
- (0, import_hooks.useEffect)(() => {
107
- if (!provides) return;
108
- return provides.onStateChange((state2) => {
109
- setState(state2);
110
- });
111
- }, [provides]);
112
- return {
113
- provides,
114
- state
115
- };
116
- }
117
- function useCursor() {
118
- const { provides } = useInteractionManagerCapability();
119
- return {
120
- setCursor: (token, cursor, prio = 0) => {
121
- provides?.setCursor(token, cursor, prio);
122
- },
123
- removeCursor: (token) => {
124
- provides?.removeCursor(token);
125
- }
126
- };
127
- }
128
- function usePointerHandlers({ modeId, pageIndex }) {
129
- const { provides } = useInteractionManagerCapability();
130
- return {
131
- register: (handlers, options) => {
132
- const finalModeId = options?.modeId ?? modeId;
133
- const finalPageIndex = options?.pageIndex ?? pageIndex;
134
- return finalModeId ? provides?.registerHandlers({
135
- modeId: finalModeId,
136
- handlers,
137
- pageIndex: finalPageIndex
138
- }) : provides?.registerAlways({
139
- scope: finalPageIndex !== void 0 ? { type: "page", pageIndex: finalPageIndex } : { type: "global" },
140
- handlers
141
- });
142
- }
143
- };
144
- }
145
- function useIsPageExclusive() {
146
- const { provides: cap } = useInteractionManagerCapability();
147
- const [isPageExclusive, setIsPageExclusive] = (0, import_hooks.useState)(() => {
148
- const m = cap?.getActiveInteractionMode();
149
- return m?.scope === "page" && !!m.exclusive;
150
- });
151
- (0, import_hooks.useEffect)(() => {
152
- if (!cap) return;
153
- return cap.onModeChange(() => {
154
- const mode = cap.getActiveInteractionMode();
155
- setIsPageExclusive(mode?.scope === "page" && !!mode?.exclusive);
156
- });
157
- }, [cap]);
158
- return isPageExclusive;
159
- }
160
-
161
- // src/preact/components/global-pointer-provider.tsx
162
- var import_jsx_runtime = require("preact/jsx-runtime");
163
- var GlobalPointerProvider = ({
164
- children,
165
- style,
166
- ...props
167
- }) => {
168
- const ref = (0, import_hooks2.useRef)(null);
169
- const { provides: cap } = useInteractionManagerCapability();
170
- (0, import_hooks2.useEffect)(() => {
171
- if (!cap || !ref.current) return;
172
- return createPointerProvider(cap, { type: "global" }, ref.current);
173
- }, [cap]);
174
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
175
- "div",
176
- {
177
- ref,
178
- style: {
179
- width: "100%",
180
- height: "100%",
181
- ...style
182
- },
183
- ...props,
184
- children
185
- }
186
- );
187
- };
188
-
189
- // src/preact/components/page-pointer-provider.tsx
190
- var import_hooks4 = require("preact/hooks");
191
- var import_models = require("@embedpdf/models");
192
- var import_jsx_runtime2 = require("preact/jsx-runtime");
193
- var PagePointerProvider = ({
194
- pageIndex,
195
- children,
196
- pageWidth,
197
- pageHeight,
198
- rotation,
199
- scale,
200
- convertEventToPoint,
201
- style,
202
- ...props
203
- }) => {
204
- const ref = (0, import_hooks4.useRef)(null);
205
- const { provides: cap } = useInteractionManagerCapability();
206
- const isPageExclusive = useIsPageExclusive();
207
- const defaultConvertEventToPoint = (0, import_hooks4.useCallback)(
208
- (event, element) => {
209
- const rect = element.getBoundingClientRect();
210
- const displayPoint = {
211
- x: event.clientX - rect.left,
212
- y: event.clientY - rect.top
213
- };
214
- return (0, import_models.restorePosition)(
215
- { width: pageWidth, height: pageHeight },
216
- displayPoint,
217
- rotation,
218
- scale
219
- );
220
- },
221
- [pageWidth, pageHeight, rotation, scale]
222
- );
223
- (0, import_hooks4.useEffect)(() => {
224
- if (!cap || !ref.current) return;
225
- return createPointerProvider(
226
- cap,
227
- { type: "page", pageIndex },
228
- ref.current,
229
- convertEventToPoint || defaultConvertEventToPoint
230
- );
231
- }, [cap, pageIndex, convertEventToPoint, defaultConvertEventToPoint]);
232
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
233
- "div",
234
- {
235
- ref,
236
- style: {
237
- ...style
238
- },
239
- ...props,
240
- children: [
241
- children,
242
- isPageExclusive && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { style: { position: "absolute", top: 0, left: 0, right: 0, bottom: 0, zIndex: 10 } })
243
- ]
244
- }
245
- );
246
- };
247
- // Annotate the CommonJS export names for ESM import in node:
248
- 0 && (module.exports = {
249
- GlobalPointerProvider,
250
- PagePointerProvider,
251
- useCursor,
252
- useInteractionManager,
253
- useInteractionManagerCapability,
254
- useInteractionManagerPlugin,
255
- useIsPageExclusive,
256
- usePointerHandlers
257
- });
258
- //# sourceMappingURL=index.cjs.map
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core/preact"),t=require("@embedpdf/plugin-interaction-manager"),r=require("preact/hooks"),n=require("preact/jsx-runtime"),o=require("@embedpdf/models"),i=()=>e.useCapability(t.InteractionManagerPlugin.id);function s(){const{provides:e}=i(),[t,n]=r.useState((()=>{const t=null==e?void 0:e.getActiveInteractionMode();return"page"===(null==t?void 0:t.scope)&&!!t.exclusive}));return r.useEffect((()=>{if(e)return e.onModeChange((()=>{const t=e.getActiveInteractionMode();n("page"===(null==t?void 0:t.scope)&&!!(null==t?void 0:t.exclusive))}))}),[e]),t}function l(e,t,r,n){let o=e.getHandlersForScope(t);const i=e.onModeChange((()=>{if("global"===t.type){const t=e.getActiveInteractionMode();r.style.cursor="global"===(null==t?void 0:t.scope)?t.cursor??"auto":"auto"}o=e.getHandlersForScope(t)})),s=e.onHandlerChange((()=>{o=e.getHandlersForScope(t)})),l=e.getActiveInteractionMode(),u=e.getCurrentCursor();"global"===t.type?r.style.cursor="global"===(null==l?void 0:l.scope)?u:"auto":r.style.cursor=u;const a=e.onCursorChange((n=>{var o;if("global"===t.type){if(!("global"===(null==(o=e.getActiveInteractionMode())?void 0:o.scope)))return}r.style.cursor=n})),c={onPointerDown:"pointerdown",onPointerUp:"pointerup",onPointerMove:"pointermove",onPointerEnter:"pointerenter",onPointerLeave:"pointerleave",onPointerCancel:"pointercancel"},d={};return Object.keys(c).forEach((t=>{d[t]=i=>{var s;if(e.isPaused())return;const l=i,u=e.getActiveMode();null==(s=null==o?void 0:o[t])||s.call(o,((e,t)=>{if(n)return n(e,t);const r=t.getBoundingClientRect();return{x:e.clientX-r.left,y:e.clientY-r.top}})(l,r),l,u)},r.addEventListener(c[t],d[t])})),()=>{Object.keys(c).forEach((e=>r.removeEventListener(c[e],d[e]))),i(),a(),s()}}exports.GlobalPointerProvider=({children:e,style:t,...o})=>{const s=r.useRef(null),{provides:u}=i();return r.useEffect((()=>{if(u&&s.current)return l(u,{type:"global"},s.current)}),[u]),n.jsx("div",{ref:s,style:{width:"100%",height:"100%",...t},...o,children:e})},exports.PagePointerProvider=({pageIndex:e,children:t,pageWidth:u,pageHeight:a,rotation:c,scale:d,convertEventToPoint:p,style:g,...v})=>{const f=r.useRef(null),{provides:x}=i(),y=s(),h=r.useCallback(((e,t)=>{const r=t.getBoundingClientRect(),n={x:e.clientX-r.left,y:e.clientY-r.top};return o.restorePosition({width:u,height:a},n,c,d)}),[u,a,c,d]);return r.useEffect((()=>{if(x&&f.current)return l(x,{type:"page",pageIndex:e},f.current,p||h)}),[x,e,p,h]),n.jsxs("div",{ref:f,style:{...g},...v,children:[t,y&&n.jsx("div",{style:{position:"absolute",top:0,left:0,right:0,bottom:0,zIndex:10}})]})},exports.useCursor=function(){const{provides:e}=i();return{setCursor:(t,r,n=0)=>{null==e||e.setCursor(t,r,n)},removeCursor:t=>{null==e||e.removeCursor(t)}}},exports.useInteractionManager=function(){const{provides:e}=i(),[n,o]=r.useState(t.initialState);return r.useEffect((()=>{if(e)return e.onStateChange((e=>{o(e)}))}),[e]),{provides:e,state:n}},exports.useInteractionManagerCapability=i,exports.useInteractionManagerPlugin=()=>e.usePlugin(t.InteractionManagerPlugin.id),exports.useIsPageExclusive=s,exports.usePointerHandlers=function({modeId:e,pageIndex:t}){const{provides:r}=i();return{register:(n,o)=>{const i=(null==o?void 0:o.modeId)??e,s=(null==o?void 0:o.pageIndex)??t;return i?null==r?void 0:r.registerHandlers({modeId:i,handlers:n,pageIndex:s}):null==r?void 0:r.registerAlways({scope:void 0!==s?{type:"page",pageIndex:s}:{type:"global"},handlers:n})}}};
2
+ //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/preact/index.ts","../../src/preact/components/global-pointer-provider.tsx","../../src/shared/utils.ts","../../src/preact/hooks/use-interaction-manager.ts","../../src/preact/components/page-pointer-provider.tsx"],"sourcesContent":["export * from './components';\nexport * from './hooks';\n","/** @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 { 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 if (cap.isPaused()) return;\n\n const pe = evt as PointerEvent; // safe – we only attach to pointer*\n const currentModeId = cap.getActiveMode();\n active?.[k]?.(toPos(pe, element), pe, currentModeId);\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 { useCapability, usePlugin } from '@embedpdf/core/preact';\nimport {\n initialState,\n InteractionManagerPlugin,\n InteractionManagerState,\n PointerEventHandlers,\n PointerEventHandlersWithLifecycle,\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 | string[];\n pageIndex?: number;\n}\n\nexport function usePointerHandlers({ modeId, pageIndex }: UsePointerHandlersOptions) {\n const { provides } = useInteractionManagerCapability();\n return {\n register: (\n handlers: PointerEventHandlersWithLifecycle,\n options?: { modeId?: string | string[]; pageIndex?: number },\n ) => {\n // Use provided options or fall back to hook-level options\n const finalModeId = options?.modeId ?? modeId;\n const finalPageIndex = options?.pageIndex ?? pageIndex;\n\n return finalModeId\n ? provides?.registerHandlers({\n modeId: finalModeId,\n handlers,\n pageIndex: finalPageIndex,\n })\n : provides?.registerAlways({\n scope:\n finalPageIndex !== undefined\n ? { type: 'page', pageIndex: finalPageIndex }\n : { type: 'global' },\n handlers,\n });\n },\n };\n}\n\nexport function useIsPageExclusive() {\n const { provides: cap } = useInteractionManagerCapability();\n\n const [isPageExclusive, setIsPageExclusive] = useState<boolean>(() => {\n const m = cap?.getActiveInteractionMode();\n return m?.scope === 'page' && !!m.exclusive;\n });\n\n useEffect(() => {\n if (!cap) return;\n\n return cap.onModeChange(() => {\n const mode = cap.getActiveInteractionMode();\n setIsPageExclusive(mode?.scope === 'page' && !!mode?.exclusive);\n });\n }, [cap]);\n\n return isPageExclusive;\n}\n","/** @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 ...style,\n }}\n {...props}\n >\n {children}\n {isPageExclusive && (\n <div style={{ position: 'absolute', top: 0, left: 0, right: 0, bottom: 0, zIndex: 10 }} />\n )}\n </div>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEA,IAAAA,gBAAkC;;;ACU3B,SAAS,sBACd,KACA,OACA,SACA,qBACA;AAIA,MAAI,SAAsC,IAAI,oBAAoB,KAAK;AAEvE,QAAM,WAAW,IAAI,aAAa,MAAM;AACtC,QAAI,MAAM,SAAS,UAAU;AAC3B,YAAM,OAAO,IAAI,yBAAyB;AAC1C,cAAQ,MAAM,SAAS,MAAM,UAAU,WAAY,KAAK,UAAU,SAAU;AAAA,IAC9E;AACA,aAAS,IAAI,oBAAoB,KAAK;AAAA,E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GAAG;AACL,MAAgC;AAC9B,QAAM,UAAM,sBAAuB,IAAI;AACvC,QAAM,EAAE,UAAU,IAAI,IAAI,gCAAgC;AAC1D,QAAM,kBAAkB,mBAAmB;AAE3C,QAAM,iCAA6B;AAAA,IACjC,CAAC,OAAqB,YAAmC;AACvD,YAAM,OAAO,QAAQ,sBAAsB;AAC3C,YAAM,eAAe;AAAA,QACnB,GAAG,MAAM,UAAU,KAAK;AAAA,QACxB,GAAG,MAAM,UAAU,KAAK;AAAA,MAC1B;AACA,iBAAO;AAAA,QACL,EAAE,OAAO,WAAW,QAAQ,WAAW;AAAA,QACvC;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAAA,IACA,CAAC,WAAW,YAAY,UAAU,KAAK;AAAA,EACzC;AAEA,+BAAU,MAAM;AACd,QAAI,CAAC,OAAO,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,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,GAAG,QAAQ,GAAG,GAAG;AAAA;AAAA;AAAA,EAE5F;AAEJ;","names":["import_hooks","state","import_hooks","import_jsx_runtime"]}
1
+ {"version":3,"file":"index.cjs","sources":["../../src/shared/hooks/use-interaction-manager.ts","../../src/shared/utils.ts","../../src/shared/components/global-pointer-provider.tsx","../../src/shared/components/page-pointer-provider.tsx"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/@framework';\nimport {\n initialState,\n InteractionManagerPlugin,\n InteractionManagerState,\n PointerEventHandlers,\n PointerEventHandlersWithLifecycle,\n} from '@embedpdf/plugin-interaction-manager';\nimport { useState, useEffect } from '@framework';\n\nexport const useInteractionManagerPlugin = () =>\n usePlugin<InteractionManagerPlugin>(InteractionManagerPlugin.id);\nexport const useInteractionManagerCapability = () =>\n useCapability<InteractionManagerPlugin>(InteractionManagerPlugin.id);\n\nexport function useInteractionManager() {\n const { provides } = useInteractionManagerCapability();\n const [state, setState] = useState<InteractionManagerState>(initialState);\n\n useEffect(() => {\n if (!provides) return;\n return provides.onStateChange((state) => {\n setState(state);\n });\n }, [provides]);\n\n return {\n provides,\n state,\n };\n}\n\nexport function useCursor() {\n const { provides } = useInteractionManagerCapability();\n return {\n setCursor: (token: string, cursor: string, prio = 0) => {\n provides?.setCursor(token, cursor, prio);\n },\n removeCursor: (token: string) => {\n provides?.removeCursor(token);\n },\n };\n}\n\ninterface UsePointerHandlersOptions {\n modeId?: string | string[];\n pageIndex?: number;\n}\n\nexport function usePointerHandlers({ modeId, pageIndex }: UsePointerHandlersOptions) {\n const { provides } = useInteractionManagerCapability();\n return {\n register: (\n handlers: PointerEventHandlersWithLifecycle,\n options?: { modeId?: string | string[]; pageIndex?: number },\n ) => {\n // Use provided options or fall back to hook-level options\n const finalModeId = options?.modeId ?? modeId;\n const finalPageIndex = options?.pageIndex ?? pageIndex;\n\n return finalModeId\n ? provides?.registerHandlers({\n modeId: finalModeId,\n handlers,\n pageIndex: finalPageIndex,\n })\n : provides?.registerAlways({\n scope:\n finalPageIndex !== undefined\n ? { type: 'page', pageIndex: finalPageIndex }\n : { type: 'global' },\n handlers,\n });\n },\n };\n}\n\nexport function useIsPageExclusive() {\n const { provides: cap } = useInteractionManagerCapability();\n\n const [isPageExclusive, setIsPageExclusive] = useState<boolean>(() => {\n const m = cap?.getActiveInteractionMode();\n return m?.scope === 'page' && !!m.exclusive;\n });\n\n useEffect(() => {\n if (!cap) return;\n\n return cap.onModeChange(() => {\n const mode = cap.getActiveInteractionMode();\n setIsPageExclusive(mode?.scope === 'page' && !!mode?.exclusive);\n });\n }, [cap]);\n\n return isPageExclusive;\n}\n","import { Position } from '@embedpdf/models';\nimport type {\n InteractionManagerCapability,\n InteractionScope,\n PointerEventHandlers,\n} 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 if (cap.isPaused()) return;\n\n const pe = evt as PointerEvent; // safe – we only attach to pointer*\n const currentModeId = cap.getActiveMode();\n active?.[k]?.(toPos(pe, element), pe, currentModeId);\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, HTMLAttributes, CSSProperties } from '@framework';\nimport { createPointerProvider } from '../utils';\n\nimport { useInteractionManagerCapability } from '../hooks';\n\ninterface GlobalPointerProviderProps extends HTMLAttributes<HTMLDivElement> {\n children: ReactNode;\n style?: CSSProperties;\n}\n\nexport const GlobalPointerProvider = ({\n children,\n style,\n ...props\n}: GlobalPointerProviderProps) => {\n const ref = useRef<HTMLDivElement>(null);\n const { provides: cap } = useInteractionManagerCapability();\n\n useEffect(() => {\n if (!cap || !ref.current) return;\n\n return createPointerProvider(cap, { type: 'global' }, ref.current);\n }, [cap]);\n\n return (\n <div\n ref={ref}\n style={{\n width: '100%',\n height: '100%',\n ...style,\n }}\n {...props}\n >\n {children}\n </div>\n );\n};\n","import {\n ReactNode,\n useEffect,\n useRef,\n useCallback,\n HTMLAttributes,\n CSSProperties,\n} from '@framework';\nimport { Position, restorePosition } from '@embedpdf/models';\nimport { createPointerProvider } from '../utils';\n\nimport { useInteractionManagerCapability, useIsPageExclusive } from '../hooks';\n\ninterface PagePointerProviderProps extends HTMLAttributes<HTMLDivElement> {\n children: ReactNode;\n pageIndex: number;\n pageWidth: number;\n pageHeight: number;\n rotation: number;\n scale: number;\n style?: CSSProperties;\n convertEventToPoint?: (event: PointerEvent, element: HTMLElement) => Position;\n}\n\nexport const PagePointerProvider = ({\n pageIndex,\n children,\n pageWidth,\n pageHeight,\n rotation,\n scale,\n convertEventToPoint,\n style,\n ...props\n}: PagePointerProviderProps) => {\n const ref = useRef<HTMLDivElement>(null);\n const { provides: cap } = useInteractionManagerCapability();\n const isPageExclusive = useIsPageExclusive();\n\n // Memoize the default conversion function\n const defaultConvertEventToPoint = useCallback(\n (event: PointerEvent, element: HTMLElement): Position => {\n const rect = element.getBoundingClientRect();\n const displayPoint = {\n x: event.clientX - rect.left,\n y: event.clientY - rect.top,\n };\n return restorePosition(\n { width: pageWidth, height: pageHeight },\n displayPoint,\n rotation,\n scale,\n );\n },\n [pageWidth, pageHeight, rotation, scale],\n );\n\n useEffect(() => {\n if (!cap || !ref.current) return;\n\n return createPointerProvider(\n cap,\n { type: 'page', pageIndex },\n ref.current,\n convertEventToPoint || defaultConvertEventToPoint,\n );\n }, [cap, pageIndex, convertEventToPoint, defaultConvertEventToPoint]);\n\n return (\n <div\n ref={ref}\n style={{\n ...style,\n }}\n {...props}\n >\n {children}\n {isPageExclusive && (\n <div style={{ position: 'absolute', top: 0, left: 0, right: 0, bottom: 0, zIndex: 10 }} />\n )}\n </div>\n );\n};\n"],"names":["useInteractionManagerCapability","useCapability","InteractionManagerPlugin","id","useIsPageExclusive","provides","cap","isPageExclusive","setIsPageExclusive","useState","m","getActiveInteractionMode","scope","exclusive","useEffect","onModeChange","mode","createPointerProvider","element","convertEventToPoint","active","getHandlersForScope","stopMode","type","style","cursor","stopHandler","onHandlerChange","modeNow","cursorNow","getCurrentCursor","stopCursor","onCursorChange","c","_a","domEvent","onPointerDown","onPointerUp","onPointerMove","onPointerEnter","onPointerLeave","onPointerCancel","listeners","Object","keys","forEach","k","evt","isPaused","pe","currentModeId","getActiveMode","call","e","host","r","getBoundingClientRect","x","clientX","left","y","clientY","top","toPos","addEventListener","removeEventListener","children","props","ref","useRef","current","jsxRuntime","jsx","width","height","pageIndex","pageWidth","pageHeight","rotation","scale","defaultConvertEventToPoint","useCallback","event","rect","displayPoint","restorePosition","jsxs","position","right","bottom","zIndex","setCursor","token","prio","removeCursor","state","setState","initialState","onStateChange","usePlugin","modeId","register","handlers","options","finalModeId","finalPageIndex","registerHandlers","registerAlways"],"mappings":"mQAYaA,EAAkC,IAC7CC,gBAAwCC,EAAAA,yBAAyBC,IAgE5D,SAASC,IACd,MAAQC,SAAUC,GAAQN,KAEnBO,EAAiBC,GAAsBC,YAAkB,KACxD,MAAAC,EAAS,MAALJ,OAAK,EAAAA,EAAAK,2BACf,MAAoB,UAAV,MAAHD,OAAG,EAAAA,EAAAE,UAAsBF,EAAEG,SAAA,IAY7B,OATPC,EAAAA,WAAU,KACR,GAAKR,EAEE,OAAAA,EAAIS,cAAa,KAChB,MAAAC,EAAOV,EAAIK,2BACjBH,EAAmC,gBAAhBQ,WAAMJ,iBAAsBI,WAAMH,WAAS,GAC/D,GACA,CAACP,IAEGC,CACT,CCnFO,SAASU,EACdX,EACAM,EACAM,EACAC,GAKI,IAAAC,EAAsCd,EAAIe,oBAAoBT,GAE5D,MAAAU,EAAWhB,EAAIS,cAAa,KAC5B,GAAe,WAAfH,EAAMW,KAAmB,CACrB,MAAAP,EAAOV,EAAIK,2BACjBO,EAAQM,MAAMC,OAAyB,YAAhB,MAAAT,OAAA,EAAAA,EAAMJ,OA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AgBoE,EAAO,KACtC,MAAAxF,GAAAA,EAAAsF,UAAUC,EAAOnE,EAAQoE,EAAA,EAErCC,aAAeF,IACb,MAAAvF,GAAAA,EAAUyF,aAAaF,EAAA,EAG7B,gCA3BO,WACC,MAAAvF,SAAEA,GAAaL,KACd+F,EAAOC,GAAYvF,EAAAA,SAAkCwF,EAAAA,cASrD,OAPPnF,EAAAA,WAAU,KACR,GAAKT,EACE,OAAAA,EAAS6F,eAAeH,IAC7BC,EAASD,EAAK,GACf,GACA,CAAC1F,IAEG,CACLA,WACA0F,QAEJ,gFApB2C,IACzCI,YAAoCjG,EAAAA,yBAAyBC,4DAsCxD,UAA4BiG,OAAEA,EAAQzB,UAAAA,IACrC,MAAAtE,SAAEA,GAAaL,IACd,MAAA,CACLqG,SAAU,CACRC,EACAC,KAGM,MAAAC,SAAcD,WAASH,SAAUA,EACjCK,SAAiBF,WAAS5B,YAAaA,EAEtC,OAAA6B,QACHnG,WAAUqG,iBAAiB,CACzBN,OAAQI,EACRF,WACA3B,UAAW8B,UAEbpG,WAAUsG,eAAe,CACvB/F,WACqB,IAAnB6F,EACI,CAAElF,KAAM,OAAQoD,UAAW8B,GAC3B,CAAElF,KAAM,UACd+E,YAAA,EAIZ"}
@@ -1,58 +1 @@
1
- import { JSX, ComponentChildren } from 'preact';
2
- import { Position } from '@embedpdf/models';
3
- import * as _embedpdf_plugin_interaction_manager from '@embedpdf/plugin-interaction-manager';
4
- import { InteractionManagerPlugin, InteractionManagerState, PointerEventHandlersWithLifecycle } from '@embedpdf/plugin-interaction-manager';
5
-
6
- /** @jsxImportSource preact */
7
-
8
- interface GlobalPointerProviderProps extends JSX.HTMLAttributes<HTMLDivElement> {
9
- children: ComponentChildren;
10
- style?: JSX.CSSProperties;
11
- }
12
- declare const GlobalPointerProvider: ({ children, style, ...props }: GlobalPointerProviderProps) => JSX.Element;
13
-
14
- /** @jsxImportSource preact */
15
-
16
- interface PagePointerProviderProps extends JSX.HTMLAttributes<HTMLDivElement> {
17
- children: ComponentChildren;
18
- pageIndex: number;
19
- pageWidth: number;
20
- pageHeight: number;
21
- rotation: number;
22
- scale: number;
23
- style?: JSX.CSSProperties;
24
- convertEventToPoint?: (event: PointerEvent, element: HTMLElement) => Position;
25
- }
26
- declare const PagePointerProvider: ({ pageIndex, children, pageWidth, pageHeight, rotation, scale, convertEventToPoint, style, ...props }: PagePointerProviderProps) => JSX.Element;
27
-
28
- declare const useInteractionManagerPlugin: () => {
29
- plugin: InteractionManagerPlugin | null;
30
- isLoading: boolean;
31
- ready: Promise<void>;
32
- };
33
- declare const useInteractionManagerCapability: () => {
34
- provides: Readonly<_embedpdf_plugin_interaction_manager.InteractionManagerCapability> | null;
35
- isLoading: boolean;
36
- ready: Promise<void>;
37
- };
38
- declare function useInteractionManager(): {
39
- provides: Readonly<_embedpdf_plugin_interaction_manager.InteractionManagerCapability> | null;
40
- state: InteractionManagerState;
41
- };
42
- declare function useCursor(): {
43
- setCursor: (token: string, cursor: string, prio?: number) => void;
44
- removeCursor: (token: string) => void;
45
- };
46
- interface UsePointerHandlersOptions {
47
- modeId?: string | string[];
48
- pageIndex?: number;
49
- }
50
- declare function usePointerHandlers({ modeId, pageIndex }: UsePointerHandlersOptions): {
51
- register: (handlers: PointerEventHandlersWithLifecycle, options?: {
52
- modeId?: string | string[];
53
- pageIndex?: number;
54
- }) => (() => void) | undefined;
55
- };
56
- declare function useIsPageExclusive(): boolean;
57
-
58
- export { GlobalPointerProvider, PagePointerProvider, useCursor, useInteractionManager, useInteractionManagerCapability, useInteractionManagerPlugin, useIsPageExclusive, usePointerHandlers };
1
+ export * from '../shared-preact';
@@ -1,19 +1,10 @@
1
- import {
2
- createPointerProvider
3
- } from "../chunk-Z7V2G6MS.js";
4
-
5
- // src/preact/components/global-pointer-provider.tsx
6
- import { useEffect as useEffect2, useRef } from "preact/hooks";
7
-
8
- // src/preact/hooks/use-interaction-manager.ts
9
- import { useCapability, usePlugin } from "@embedpdf/core/preact";
10
- import {
11
- initialState,
12
- InteractionManagerPlugin
13
- } from "@embedpdf/plugin-interaction-manager";
14
- import { useState, useEffect } from "preact/hooks";
15
- var useInteractionManagerPlugin = () => usePlugin(InteractionManagerPlugin.id);
16
- var useInteractionManagerCapability = () => useCapability(InteractionManagerPlugin.id);
1
+ import { usePlugin, useCapability } from "@embedpdf/core/preact";
2
+ import { InteractionManagerPlugin, initialState } from "@embedpdf/plugin-interaction-manager";
3
+ import { useState, useEffect, useRef, useCallback } from "preact/hooks";
4
+ import { jsx, jsxs } from "preact/jsx-runtime";
5
+ import { restorePosition } from "@embedpdf/models";
6
+ const useInteractionManagerPlugin = () => usePlugin(InteractionManagerPlugin.id);
7
+ const useInteractionManagerCapability = () => useCapability(InteractionManagerPlugin.id);
17
8
  function useInteractionManager() {
18
9
  const { provides } = useInteractionManagerCapability();
19
10
  const [state, setState] = useState(initialState);
@@ -32,10 +23,10 @@ function useCursor() {
32
23
  const { provides } = useInteractionManagerCapability();
33
24
  return {
34
25
  setCursor: (token, cursor, prio = 0) => {
35
- provides?.setCursor(token, cursor, prio);
26
+ provides == null ? void 0 : provides.setCursor(token, cursor, prio);
36
27
  },
37
28
  removeCursor: (token) => {
38
- provides?.removeCursor(token);
29
+ provides == null ? void 0 : provides.removeCursor(token);
39
30
  }
40
31
  };
41
32
  }
@@ -43,13 +34,13 @@ function usePointerHandlers({ modeId, pageIndex }) {
43
34
  const { provides } = useInteractionManagerCapability();
44
35
  return {
45
36
  register: (handlers, options) => {
46
- const finalModeId = options?.modeId ?? modeId;
47
- const finalPageIndex = options?.pageIndex ?? pageIndex;
48
- return finalModeId ? provides?.registerHandlers({
37
+ const finalModeId = (options == null ? void 0 : options.modeId) ?? modeId;
38
+ const finalPageIndex = (options == null ? void 0 : options.pageIndex) ?? pageIndex;
39
+ return finalModeId ? provides == null ? void 0 : provides.registerHandlers({
49
40
  modeId: finalModeId,
50
41
  handlers,
51
42
  pageIndex: finalPageIndex
52
- }) : provides?.registerAlways({
43
+ }) : provides == null ? void 0 : provides.registerAlways({
53
44
  scope: finalPageIndex !== void 0 ? { type: "page", pageIndex: finalPageIndex } : { type: "global" },
54
45
  handlers
55
46
  });
@@ -59,29 +50,86 @@ function usePointerHandlers({ modeId, pageIndex }) {
59
50
  function useIsPageExclusive() {
60
51
  const { provides: cap } = useInteractionManagerCapability();
61
52
  const [isPageExclusive, setIsPageExclusive] = useState(() => {
62
- const m = cap?.getActiveInteractionMode();
63
- return m?.scope === "page" && !!m.exclusive;
53
+ const m = cap == null ? void 0 : cap.getActiveInteractionMode();
54
+ return (m == null ? void 0 : m.scope) === "page" && !!m.exclusive;
64
55
  });
65
56
  useEffect(() => {
66
57
  if (!cap) return;
67
58
  return cap.onModeChange(() => {
68
59
  const mode = cap.getActiveInteractionMode();
69
- setIsPageExclusive(mode?.scope === "page" && !!mode?.exclusive);
60
+ setIsPageExclusive((mode == null ? void 0 : mode.scope) === "page" && !!(mode == null ? void 0 : mode.exclusive));
70
61
  });
71
62
  }, [cap]);
72
63
  return isPageExclusive;
73
64
  }
74
-
75
- // src/preact/components/global-pointer-provider.tsx
76
- import { jsx } from "preact/jsx-runtime";
77
- var GlobalPointerProvider = ({
65
+ function createPointerProvider(cap, scope, element, convertEventToPoint) {
66
+ let active = cap.getHandlersForScope(scope);
67
+ const stopMode = cap.onModeChange(() => {
68
+ if (scope.type === "global") {
69
+ const mode = cap.getActiveInteractionMode();
70
+ element.style.cursor = (mode == null ? void 0 : mode.scope) === "global" ? mode.cursor ?? "auto" : "auto";
71
+ }
72
+ active = cap.getHandlersForScope(scope);
73
+ });
74
+ const stopHandler = cap.onHandlerChange(() => {
75
+ active = cap.getHandlersForScope(scope);
76
+ });
77
+ const modeNow = cap.getActiveInteractionMode();
78
+ const cursorNow = cap.getCurrentCursor();
79
+ if (scope.type === "global") {
80
+ element.style.cursor = (modeNow == null ? void 0 : modeNow.scope) === "global" ? cursorNow : "auto";
81
+ } else {
82
+ element.style.cursor = cursorNow;
83
+ }
84
+ const stopCursor = cap.onCursorChange((c) => {
85
+ var _a;
86
+ if (scope.type === "global") {
87
+ const isGlobalMode = ((_a = cap.getActiveInteractionMode()) == null ? void 0 : _a.scope) === "global";
88
+ if (!isGlobalMode) return;
89
+ }
90
+ element.style.cursor = c;
91
+ });
92
+ const domEvent = {
93
+ onPointerDown: "pointerdown",
94
+ onPointerUp: "pointerup",
95
+ onPointerMove: "pointermove",
96
+ onPointerEnter: "pointerenter",
97
+ onPointerLeave: "pointerleave",
98
+ onPointerCancel: "pointercancel"
99
+ };
100
+ const listeners = {};
101
+ const toPos = (e, host) => {
102
+ if (convertEventToPoint) return convertEventToPoint(e, host);
103
+ const r = host.getBoundingClientRect();
104
+ return { x: e.clientX - r.left, y: e.clientY - r.top };
105
+ };
106
+ Object.keys(domEvent).forEach((k) => {
107
+ listeners[k] = (evt) => {
108
+ var _a;
109
+ if (cap.isPaused()) return;
110
+ const pe = evt;
111
+ const currentModeId = cap.getActiveMode();
112
+ (_a = active == null ? void 0 : active[k]) == null ? void 0 : _a.call(active, toPos(pe, element), pe, currentModeId);
113
+ };
114
+ element.addEventListener(domEvent[k], listeners[k]);
115
+ });
116
+ return () => {
117
+ Object.keys(domEvent).forEach(
118
+ (k) => element.removeEventListener(domEvent[k], listeners[k])
119
+ );
120
+ stopMode();
121
+ stopCursor();
122
+ stopHandler();
123
+ };
124
+ }
125
+ const GlobalPointerProvider = ({
78
126
  children,
79
127
  style,
80
128
  ...props
81
129
  }) => {
82
130
  const ref = useRef(null);
83
131
  const { provides: cap } = useInteractionManagerCapability();
84
- useEffect2(() => {
132
+ useEffect(() => {
85
133
  if (!cap || !ref.current) return;
86
134
  return createPointerProvider(cap, { type: "global" }, ref.current);
87
135
  }, [cap]);
@@ -99,12 +147,7 @@ var GlobalPointerProvider = ({
99
147
  }
100
148
  );
101
149
  };
102
-
103
- // src/preact/components/page-pointer-provider.tsx
104
- import { useCallback, useEffect as useEffect3, useRef as useRef2 } from "preact/hooks";
105
- import { restorePosition } from "@embedpdf/models";
106
- import { jsx as jsx2, jsxs } from "preact/jsx-runtime";
107
- var PagePointerProvider = ({
150
+ const PagePointerProvider = ({
108
151
  pageIndex,
109
152
  children,
110
153
  pageWidth,
@@ -115,7 +158,7 @@ var PagePointerProvider = ({
115
158
  style,
116
159
  ...props
117
160
  }) => {
118
- const ref = useRef2(null);
161
+ const ref = useRef(null);
119
162
  const { provides: cap } = useInteractionManagerCapability();
120
163
  const isPageExclusive = useIsPageExclusive();
121
164
  const defaultConvertEventToPoint = useCallback(
@@ -134,7 +177,7 @@ var PagePointerProvider = ({
134
177
  },
135
178
  [pageWidth, pageHeight, rotation, scale]
136
179
  );
137
- useEffect3(() => {
180
+ useEffect(() => {
138
181
  if (!cap || !ref.current) return;
139
182
  return createPointerProvider(
140
183
  cap,
@@ -153,7 +196,7 @@ var PagePointerProvider = ({
153
196
  ...props,
154
197
  children: [
155
198
  children,
156
- isPageExclusive && /* @__PURE__ */ jsx2("div", { style: { position: "absolute", top: 0, left: 0, right: 0, bottom: 0, zIndex: 10 } })
199
+ isPageExclusive && /* @__PURE__ */ jsx("div", { style: { position: "absolute", top: 0, left: 0, right: 0, bottom: 0, zIndex: 10 } })
157
200
  ]
158
201
  }
159
202
  );
@@ -168,4 +211,4 @@ export {
168
211
  useIsPageExclusive,
169
212
  usePointerHandlers
170
213
  };
171
- //# sourceMappingURL=index.js.map
214
+ //# sourceMappingURL=index.js.map