@embedpdf/plugin-interaction-manager 1.0.11 → 1.0.13
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.
- package/dist/index.cjs +2 -359
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -177
- package/dist/index.js +42 -42
- package/dist/index.js.map +1 -1
- package/dist/lib/actions.d.ts +28 -0
- package/dist/lib/helper.d.ts +2 -0
- package/dist/lib/index.d.ts +9 -0
- package/dist/lib/interaction-manager-plugin.d.ts +38 -0
- package/dist/lib/manifest.d.ts +4 -0
- package/dist/lib/reducer.d.ts +5 -0
- package/dist/{index.d.cts → lib/types.d.ts} +14 -83
- package/dist/preact/adapter.d.ts +4 -0
- package/dist/preact/core.d.ts +1 -0
- package/dist/preact/index.cjs +2 -258
- package/dist/preact/index.cjs.map +1 -1
- package/dist/preact/index.d.ts +1 -58
- package/dist/preact/index.js +85 -40
- package/dist/preact/index.js.map +1 -1
- package/dist/react/adapter.d.ts +2 -0
- package/dist/react/core.d.ts +1 -0
- package/dist/react/index.cjs +2 -258
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.ts +1 -55
- package/dist/react/index.js +85 -38
- package/dist/react/index.js.map +1 -1
- package/dist/shared-preact/components/global-pointer-provider.d.ts +7 -0
- package/dist/shared-preact/components/index.d.ts +2 -0
- package/dist/shared-preact/components/page-pointer-provider.d.ts +14 -0
- package/dist/shared-preact/hooks/index.d.ts +1 -0
- package/dist/shared-preact/hooks/use-interaction-manager.d.ts +31 -0
- package/dist/shared-preact/index.d.ts +2 -0
- package/dist/shared-preact/utils.d.ts +8 -0
- package/dist/shared-react/components/global-pointer-provider.d.ts +7 -0
- package/dist/shared-react/components/index.d.ts +2 -0
- package/dist/shared-react/components/page-pointer-provider.d.ts +14 -0
- package/dist/shared-react/hooks/index.d.ts +1 -0
- package/dist/shared-react/hooks/use-interaction-manager.d.ts +31 -0
- package/dist/shared-react/index.d.ts +2 -0
- package/dist/shared-react/utils.d.ts +8 -0
- package/dist/shared-vue/utils.d.ts +8 -0
- package/dist/vue/components/global-pointer-provider.vue.d.ts +12 -0
- package/dist/vue/components/index.d.ts +2 -0
- package/dist/vue/components/page-pointer-provider.vue.d.ts +21 -0
- package/dist/vue/hooks/index.d.ts +1 -0
- package/dist/vue/hooks/use-interaction-manager.d.ts +31 -0
- package/dist/vue/index.cjs +2 -0
- package/dist/vue/index.cjs.map +1 -0
- package/dist/vue/index.d.ts +2 -0
- package/dist/vue/index.js +224 -0
- package/dist/vue/index.js.map +1 -0
- package/package.json +19 -11
- package/dist/chunk-Z7V2G6MS.js +0 -64
- package/dist/chunk-Z7V2G6MS.js.map +0 -1
- package/dist/preact/index.d.cts +0 -58
- package/dist/react/index.d.cts +0 -55
package/dist/preact/index.cjs
CHANGED
|
@@ -1,258 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
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"),n=require("preact/hooks"),r=require("preact/jsx-runtime"),o=require("@embedpdf/models"),i=()=>e.useCapability(t.InteractionManagerPlugin.id);function l(){const{provides:e}=i(),[t,r]=n.useState((()=>{const t=null==e?void 0:e.getActiveInteractionMode();return"page"===(null==t?void 0:t.scope)&&!!t.exclusive}));return n.useEffect((()=>{if(e)return e.onModeChange((()=>{const t=e.getActiveInteractionMode();r("page"===(null==t?void 0:t.scope)&&!!(null==t?void 0:t.exclusive))}))}),[e]),t}function s(e,t,n,r){let o=e.getHandlersForScope(t);const i=e.onModeChange((()=>{if("global"===t.type){const t=e.getActiveInteractionMode();n.style.cursor="global"===(null==t?void 0:t.scope)?t.cursor??"auto":"auto"}o=e.getHandlersForScope(t)})),l=e.onHandlerChange((()=>{o=e.getHandlersForScope(t)})),s=e.getActiveInteractionMode(),u=e.getCurrentCursor();"global"===t.type?n.style.cursor="global"===(null==s?void 0:s.scope)?u:"auto":n.style.cursor=u;const c=e.onCursorChange((r=>{var o;if("global"===t.type){if(!("global"===(null==(o=e.getActiveInteractionMode())?void 0:o.scope)))return}n.style.cursor=r})),a={onPointerDown:"pointerdown",onPointerUp:"pointerup",onPointerMove:"pointermove",onPointerEnter:"pointerenter",onPointerLeave:"pointerleave",onPointerCancel:"pointercancel",onClick:"click",onDoubleClick:"dblclick"},d={};return Object.keys(a).forEach((t=>{d[t]=i=>{var l;if(e.isPaused())return;const s=i,u=e.getActiveMode();null==(l=null==o?void 0:o[t])||l.call(o,((e,t)=>{if(r)return r(e,t);const n=t.getBoundingClientRect();return{x:e.clientX-n.left,y:e.clientY-n.top}})(s,n),s,u)},n.addEventListener(a[t],d[t])})),()=>{Object.keys(a).forEach((e=>n.removeEventListener(a[e],d[e]))),i(),c(),l()}}exports.GlobalPointerProvider=({children:e,style:t,...o})=>{const l=n.useRef(null),{provides:u}=i();return n.useEffect((()=>{if(u&&l.current)return s(u,{type:"global"},l.current)}),[u]),r.jsx("div",{ref:l,style:{width:"100%",height:"100%",...t},...o,children:e})},exports.PagePointerProvider=({pageIndex:e,children:t,pageWidth:u,pageHeight:c,rotation:a,scale:d,convertEventToPoint:p,style:g,...v})=>{const f=n.useRef(null),{provides:x}=i(),y=l(),b=n.useCallback(((e,t)=>{const n=t.getBoundingClientRect(),r={x:e.clientX-n.left,y:e.clientY-n.top};return o.restorePosition({width:u,height:c},r,a,d)}),[u,c,a,d]);return n.useEffect((()=>{if(x&&f.current)return s(x,{type:"page",pageIndex:e},f.current,p||b)}),[x,e,p,b]),r.jsxs("div",{ref:f,style:{...g},...v,children:[t,y&&r.jsx("div",{style:{position:"absolute",top:0,left:0,right:0,bottom:0,zIndex:10}})]})},exports.useCursor=function(){const{provides:e}=i();return{setCursor:(t,n,r=0)=>{null==e||e.setCursor(t,n,r)},removeCursor:t=>{null==e||e.removeCursor(t)}}},exports.useInteractionManager=function(){const{provides:e}=i(),[r,o]=n.useState(t.initialState);return n.useEffect((()=>{if(e)return e.onStateChange((e=>{o(e)}))}),[e]),{provides:e,state:r}},exports.useInteractionManagerCapability=i,exports.useInteractionManagerPlugin=()=>e.usePlugin(t.InteractionManagerPlugin.id),exports.useIsPageExclusive=l,exports.usePointerHandlers=function({modeId:e,pageIndex:t}){const{provides:n}=i();return{register:(r,o)=>{const i=(null==o?void 0:o.modeId)??e,l=(null==o?void 0:o.pageIndex)??t;return i?null==n?void 0:n.registerHandlers({modeId:i,handlers:r,pageIndex:l}):null==n?void 0:n.registerAlways({scope:void 0!==l?{type:"page",pageIndex:l}:{type:"global"},handlers:r})}}};
|
|
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,EACxC,CAAC;AAED,QAAM,cAAc,IAAI,gBAAgB,MAAM;AAC5C,aAAS,IAAI,oBAAoB,KAAK;AAAA,EACxC,CAAC;AAKD,QAAM,UAAU,IAAI,yBAAyB;AAC7C,QAAM,YAAY,IAAI,iBAAiB;AAGvC,MAAI,MAAM,SAAS,UAAU;AAE3B,YAAQ,MAAM,SAAS,SAAS,UAAU,WAAW,YAAY;AAAA,EACnE,OAAO;AAEL,YAAQ,MAAM,SAAS;AAAA,EACzB;AAEA,QAAM,aAAa,IAAI,eAAe,CAAC,MAAM;AAO3C,QAAI,MAAM,SAAS,UAAU;AAC3B,YAAM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A,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 onClick: 'click',\n onDoubleClick: 'dblclick',\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","onClick","onDoubleClick","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,OAAsBI,EAAKS,QAAU,OAAU,MAAA,CAErEL,EAAAd,EAAIe,oBAAoBT,EAAK,IAGlCc,EAAcpB,EAAIqB,iBAAgB,KAC7BP,EAAAd,EAAIe,oBAAoBT,EAAK,IAMlCgB,EAAUtB,EAAIK,2BACdkB,EAAYvB,EAAIwB,mBAGH,WAAflB,EAAMW,KAERL,EAAQM,MAAMC,OAA4B,YAAV,MAATG,OAAS,EAAAA,EAAAhB,OAAqBiB,EAAY,OAGjEX,EAAQM,MAAMC,OAASI,EAGzB,MAAME,EA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,GACA,CAAC5F,IAEG,CACLA,WACA4F,QAEJ,gFApB2C,IACzCI,YAAoCnG,EAAAA,yBAAyBC,4DAsCxD,UAA4BmG,OAAEA,EAAQzB,UAAAA,IACrC,MAAAxE,SAAEA,GAAaL,IACd,MAAA,CACLuG,SAAU,CACRC,EACAC,KAGM,MAAAC,SAAcD,WAASH,SAAUA,EACjCK,SAAiBF,WAAS5B,YAAaA,EAEtC,OAAA6B,QACHrG,WAAUuG,iBAAiB,CACzBN,OAAQI,EACRF,WACA3B,UAAW8B,UAEbtG,WAAUwG,eAAe,CACvBjG,WACqB,IAAnB+F,EACI,CAAEpF,KAAM,OAAQsD,UAAW8B,GAC3B,CAAEpF,KAAM,UACdiF,YAAA,EAIZ"}
|
package/dist/preact/index.d.ts
CHANGED
|
@@ -1,58 +1 @@
|
|
|
1
|
-
|
|
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';
|
package/dist/preact/index.js
CHANGED
|
@@ -1,19 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
} from "
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
|
26
|
+
provides == null ? void 0 : provides.setCursor(token, cursor, prio);
|
|
36
27
|
},
|
|
37
28
|
removeCursor: (token) => {
|
|
38
|
-
provides
|
|
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
|
|
47
|
-
const finalPageIndex = options
|
|
48
|
-
return finalModeId ? provides
|
|
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
|
|
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,88 @@ function usePointerHandlers({ modeId, pageIndex }) {
|
|
|
59
50
|
function useIsPageExclusive() {
|
|
60
51
|
const { provides: cap } = useInteractionManagerCapability();
|
|
61
52
|
const [isPageExclusive, setIsPageExclusive] = useState(() => {
|
|
62
|
-
const m = cap
|
|
63
|
-
return m
|
|
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
|
|
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
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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
|
+
onClick: "click",
|
|
100
|
+
onDoubleClick: "dblclick"
|
|
101
|
+
};
|
|
102
|
+
const listeners = {};
|
|
103
|
+
const toPos = (e, host) => {
|
|
104
|
+
if (convertEventToPoint) return convertEventToPoint(e, host);
|
|
105
|
+
const r = host.getBoundingClientRect();
|
|
106
|
+
return { x: e.clientX - r.left, y: e.clientY - r.top };
|
|
107
|
+
};
|
|
108
|
+
Object.keys(domEvent).forEach((k) => {
|
|
109
|
+
listeners[k] = (evt) => {
|
|
110
|
+
var _a;
|
|
111
|
+
if (cap.isPaused()) return;
|
|
112
|
+
const pe = evt;
|
|
113
|
+
const currentModeId = cap.getActiveMode();
|
|
114
|
+
(_a = active == null ? void 0 : active[k]) == null ? void 0 : _a.call(active, toPos(pe, element), pe, currentModeId);
|
|
115
|
+
};
|
|
116
|
+
element.addEventListener(domEvent[k], listeners[k]);
|
|
117
|
+
});
|
|
118
|
+
return () => {
|
|
119
|
+
Object.keys(domEvent).forEach(
|
|
120
|
+
(k) => element.removeEventListener(domEvent[k], listeners[k])
|
|
121
|
+
);
|
|
122
|
+
stopMode();
|
|
123
|
+
stopCursor();
|
|
124
|
+
stopHandler();
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
const GlobalPointerProvider = ({
|
|
78
128
|
children,
|
|
79
129
|
style,
|
|
80
130
|
...props
|
|
81
131
|
}) => {
|
|
82
132
|
const ref = useRef(null);
|
|
83
133
|
const { provides: cap } = useInteractionManagerCapability();
|
|
84
|
-
|
|
134
|
+
useEffect(() => {
|
|
85
135
|
if (!cap || !ref.current) return;
|
|
86
136
|
return createPointerProvider(cap, { type: "global" }, ref.current);
|
|
87
137
|
}, [cap]);
|
|
@@ -99,12 +149,7 @@ var GlobalPointerProvider = ({
|
|
|
99
149
|
}
|
|
100
150
|
);
|
|
101
151
|
};
|
|
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 = ({
|
|
152
|
+
const PagePointerProvider = ({
|
|
108
153
|
pageIndex,
|
|
109
154
|
children,
|
|
110
155
|
pageWidth,
|
|
@@ -115,7 +160,7 @@ var PagePointerProvider = ({
|
|
|
115
160
|
style,
|
|
116
161
|
...props
|
|
117
162
|
}) => {
|
|
118
|
-
const ref =
|
|
163
|
+
const ref = useRef(null);
|
|
119
164
|
const { provides: cap } = useInteractionManagerCapability();
|
|
120
165
|
const isPageExclusive = useIsPageExclusive();
|
|
121
166
|
const defaultConvertEventToPoint = useCallback(
|
|
@@ -134,7 +179,7 @@ var PagePointerProvider = ({
|
|
|
134
179
|
},
|
|
135
180
|
[pageWidth, pageHeight, rotation, scale]
|
|
136
181
|
);
|
|
137
|
-
|
|
182
|
+
useEffect(() => {
|
|
138
183
|
if (!cap || !ref.current) return;
|
|
139
184
|
return createPointerProvider(
|
|
140
185
|
cap,
|
|
@@ -153,7 +198,7 @@ var PagePointerProvider = ({
|
|
|
153
198
|
...props,
|
|
154
199
|
children: [
|
|
155
200
|
children,
|
|
156
|
-
isPageExclusive && /* @__PURE__ */
|
|
201
|
+
isPageExclusive && /* @__PURE__ */ jsx("div", { style: { position: "absolute", top: 0, left: 0, right: 0, bottom: 0, zIndex: 10 } })
|
|
157
202
|
]
|
|
158
203
|
}
|
|
159
204
|
);
|
|
@@ -168,4 +213,4 @@ export {
|
|
|
168
213
|
useIsPageExclusive,
|
|
169
214
|
usePointerHandlers
|
|
170
215
|
};
|
|
171
|
-
//# sourceMappingURL=index.js.map
|
|
216
|
+
//# sourceMappingURL=index.js.map
|