@embedpdf/plugin-interaction-manager 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +11 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -2
- package/dist/index.d.ts +9 -2
- package/dist/index.js +9 -2
- package/dist/index.js.map +1 -1
- package/dist/preact/index.cjs +84 -17
- package/dist/preact/index.cjs.map +1 -1
- package/dist/preact/index.d.cts +15 -5
- package/dist/preact/index.d.ts +15 -5
- package/dist/preact/index.js +79 -12
- package/dist/preact/index.js.map +1 -1
- package/dist/react/index.cjs +77 -9
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.cts +15 -5
- package/dist/react/index.d.ts +15 -5
- package/dist/react/index.js +78 -10
- package/dist/react/index.js.map +1 -1
- package/package.json +6 -5
package/dist/react/index.js
CHANGED
|
@@ -5,11 +5,26 @@ import {
|
|
|
5
5
|
// src/react/hooks/use-interaction-manager.ts
|
|
6
6
|
import { useCapability, usePlugin } from "@embedpdf/core/react";
|
|
7
7
|
import {
|
|
8
|
+
initialState,
|
|
8
9
|
InteractionManagerPlugin
|
|
9
10
|
} from "@embedpdf/plugin-interaction-manager";
|
|
10
11
|
import { useState, useEffect } from "react";
|
|
11
|
-
var
|
|
12
|
+
var useInteractionManagerPlugin = () => usePlugin(InteractionManagerPlugin.id);
|
|
12
13
|
var useInteractionManagerCapability = () => useCapability(InteractionManagerPlugin.id);
|
|
14
|
+
function useInteractionManager() {
|
|
15
|
+
const { provides } = useInteractionManagerCapability();
|
|
16
|
+
const [state, setState] = useState(initialState);
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
if (!provides) return;
|
|
19
|
+
return provides.onStateChange((state2) => {
|
|
20
|
+
setState(state2);
|
|
21
|
+
});
|
|
22
|
+
}, [provides]);
|
|
23
|
+
return {
|
|
24
|
+
provides,
|
|
25
|
+
state
|
|
26
|
+
};
|
|
27
|
+
}
|
|
13
28
|
function useCursor() {
|
|
14
29
|
const { provides } = useInteractionManagerCapability();
|
|
15
30
|
return {
|
|
@@ -49,41 +64,93 @@ function useIsPageExclusive() {
|
|
|
49
64
|
// src/react/components/global-pointer-provider.tsx
|
|
50
65
|
import { useEffect as useEffect2, useRef } from "react";
|
|
51
66
|
import { jsx } from "react/jsx-runtime";
|
|
52
|
-
var GlobalPointerProvider = ({
|
|
67
|
+
var GlobalPointerProvider = ({
|
|
68
|
+
children,
|
|
69
|
+
style,
|
|
70
|
+
...props
|
|
71
|
+
}) => {
|
|
53
72
|
const ref = useRef(null);
|
|
54
73
|
const { provides: cap } = useInteractionManagerCapability();
|
|
55
74
|
useEffect2(() => {
|
|
56
75
|
if (!cap || !ref.current) return;
|
|
57
76
|
return createPointerProvider(cap, { type: "global" }, ref.current);
|
|
58
77
|
}, [cap]);
|
|
59
|
-
return /* @__PURE__ */ jsx(
|
|
78
|
+
return /* @__PURE__ */ jsx(
|
|
79
|
+
"div",
|
|
80
|
+
{
|
|
81
|
+
ref,
|
|
82
|
+
style: {
|
|
83
|
+
width: "100%",
|
|
84
|
+
height: "100%",
|
|
85
|
+
...style
|
|
86
|
+
},
|
|
87
|
+
...props,
|
|
88
|
+
children
|
|
89
|
+
}
|
|
90
|
+
);
|
|
60
91
|
};
|
|
61
92
|
|
|
62
93
|
// src/react/components/page-pointer-provider.tsx
|
|
63
|
-
import { useEffect as useEffect3, useRef as useRef2 } from "react";
|
|
94
|
+
import { useEffect as useEffect3, useRef as useRef2, useCallback } from "react";
|
|
95
|
+
import { restorePosition } from "@embedpdf/models";
|
|
64
96
|
import { jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
65
97
|
var PagePointerProvider = ({
|
|
66
98
|
pageIndex,
|
|
67
99
|
children,
|
|
100
|
+
pageWidth,
|
|
101
|
+
pageHeight,
|
|
102
|
+
rotation,
|
|
103
|
+
scale,
|
|
68
104
|
convertEventToPoint,
|
|
105
|
+
style,
|
|
69
106
|
...props
|
|
70
107
|
}) => {
|
|
71
108
|
const ref = useRef2(null);
|
|
72
109
|
const { provides: cap } = useInteractionManagerCapability();
|
|
73
110
|
const isPageExclusive = useIsPageExclusive();
|
|
111
|
+
const defaultConvertEventToPoint = useCallback(
|
|
112
|
+
(event, element) => {
|
|
113
|
+
const rect = element.getBoundingClientRect();
|
|
114
|
+
const displayPoint = {
|
|
115
|
+
x: event.clientX - rect.left,
|
|
116
|
+
y: event.clientY - rect.top
|
|
117
|
+
};
|
|
118
|
+
return restorePosition(
|
|
119
|
+
{ width: pageWidth, height: pageHeight },
|
|
120
|
+
displayPoint,
|
|
121
|
+
rotation,
|
|
122
|
+
scale
|
|
123
|
+
);
|
|
124
|
+
},
|
|
125
|
+
[pageWidth, pageHeight, rotation, scale]
|
|
126
|
+
);
|
|
74
127
|
useEffect3(() => {
|
|
75
128
|
if (!cap || !ref.current) return;
|
|
76
129
|
return createPointerProvider(
|
|
77
130
|
cap,
|
|
78
131
|
{ type: "page", pageIndex },
|
|
79
132
|
ref.current,
|
|
80
|
-
convertEventToPoint
|
|
133
|
+
convertEventToPoint || defaultConvertEventToPoint
|
|
81
134
|
);
|
|
82
|
-
}, [cap, pageIndex, convertEventToPoint]);
|
|
83
|
-
return /* @__PURE__ */ jsxs(
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
135
|
+
}, [cap, pageIndex, convertEventToPoint, defaultConvertEventToPoint]);
|
|
136
|
+
return /* @__PURE__ */ jsxs(
|
|
137
|
+
"div",
|
|
138
|
+
{
|
|
139
|
+
ref,
|
|
140
|
+
style: {
|
|
141
|
+
position: "absolute",
|
|
142
|
+
inset: 0,
|
|
143
|
+
mixBlendMode: "multiply",
|
|
144
|
+
isolation: "isolate",
|
|
145
|
+
...style
|
|
146
|
+
},
|
|
147
|
+
...props,
|
|
148
|
+
children: [
|
|
149
|
+
children,
|
|
150
|
+
isPageExclusive && /* @__PURE__ */ jsx2("div", { style: { position: "absolute", top: 0, left: 0, right: 0, bottom: 0 } })
|
|
151
|
+
]
|
|
152
|
+
}
|
|
153
|
+
);
|
|
87
154
|
};
|
|
88
155
|
export {
|
|
89
156
|
GlobalPointerProvider,
|
|
@@ -91,6 +158,7 @@ export {
|
|
|
91
158
|
useCursor,
|
|
92
159
|
useInteractionManager,
|
|
93
160
|
useInteractionManagerCapability,
|
|
161
|
+
useInteractionManagerPlugin,
|
|
94
162
|
useIsPageExclusive,
|
|
95
163
|
usePointerHandlers
|
|
96
164
|
};
|
package/dist/react/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/react/hooks/use-interaction-manager.ts","../../src/react/components/global-pointer-provider.tsx","../../src/react/components/page-pointer-provider.tsx"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/react';\nimport {\n InteractionManagerPlugin,\n PointerEventHandlers,\n} from '@embedpdf/plugin-interaction-manager';\nimport { useState, useEffect } from 'react';\n\nexport const
|
|
1
|
+
{"version":3,"sources":["../../src/react/hooks/use-interaction-manager.ts","../../src/react/components/global-pointer-provider.tsx","../../src/react/components/page-pointer-provider.tsx"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/react';\nimport {\n initialState,\n InteractionManagerPlugin,\n InteractionManagerState,\n PointerEventHandlers,\n} from '@embedpdf/plugin-interaction-manager';\nimport { useState, useEffect } from 'react';\n\nexport const useInteractionManagerPlugin = () =>\n usePlugin<InteractionManagerPlugin>(InteractionManagerPlugin.id);\nexport const useInteractionManagerCapability = () =>\n useCapability<InteractionManagerPlugin>(InteractionManagerPlugin.id);\n\nexport function useInteractionManager() {\n const { provides } = useInteractionManagerCapability();\n const [state, setState] = useState<InteractionManagerState>(initialState);\n\n useEffect(() => {\n if (!provides) return;\n return provides.onStateChange((state) => {\n setState(state);\n });\n }, [provides]);\n\n return {\n provides,\n state,\n };\n}\n\nexport function useCursor() {\n const { provides } = useInteractionManagerCapability();\n return {\n setCursor: (token: string, cursor: string, prio = 0) => {\n provides?.setCursor(token, cursor, prio);\n },\n removeCursor: (token: string) => {\n provides?.removeCursor(token);\n },\n };\n}\n\ninterface UsePointerHandlersOptions {\n modeId?: string;\n pageIndex?: number;\n}\n\nexport function usePointerHandlers({ modeId, pageIndex }: UsePointerHandlersOptions) {\n const { provides } = useInteractionManagerCapability();\n return {\n register: modeId\n ? (handlers: PointerEventHandlers) =>\n provides?.registerHandlers({ modeId, handlers, pageIndex })\n : (handlers: PointerEventHandlers) =>\n provides?.registerAlways({\n scope: pageIndex !== undefined ? { type: 'page', pageIndex } : { type: 'global' },\n handlers,\n }),\n };\n}\n\nexport function useIsPageExclusive() {\n const { provides: cap } = useInteractionManagerCapability();\n\n const [isPageExclusive, setIsPageExclusive] = useState<boolean>(() => {\n const m = cap?.getActiveInteractionMode();\n return m?.scope === 'page' && !!m.exclusive;\n });\n\n useEffect(() => {\n if (!cap) return;\n\n return cap.onModeChange(() => {\n const mode = cap.getActiveInteractionMode();\n setIsPageExclusive(mode?.scope === 'page' && !!mode?.exclusive);\n });\n }, [cap]);\n\n return isPageExclusive;\n}\n","import { ReactNode, useEffect, useRef } from 'react';\nimport { createPointerProvider } from '../../shared/utils';\n\nimport { useInteractionManagerCapability } from '../hooks';\n\ninterface GlobalPointerProviderProps extends React.HTMLAttributes<HTMLDivElement> {\n children: ReactNode;\n style?: React.CSSProperties;\n}\n\nexport const GlobalPointerProvider = ({\n children,\n style,\n ...props\n}: GlobalPointerProviderProps) => {\n const ref = useRef<HTMLDivElement>(null);\n const { provides: cap } = useInteractionManagerCapability();\n\n useEffect(() => {\n if (!cap || !ref.current) return;\n\n return createPointerProvider(cap, { type: 'global' }, ref.current);\n }, [cap]);\n\n return (\n <div\n ref={ref}\n style={{\n width: '100%',\n height: '100%',\n ...style,\n }}\n {...props}\n >\n {children}\n </div>\n );\n};\n","import { ReactNode, useEffect, useRef, useCallback } from 'react';\nimport { Position, restorePosition } from '@embedpdf/models';\nimport { createPointerProvider } from '../../shared/utils';\n\nimport { useInteractionManagerCapability, useIsPageExclusive } from '../hooks';\n\ninterface PagePointerProviderProps extends React.HTMLAttributes<HTMLDivElement> {\n children: ReactNode;\n pageIndex: number;\n pageWidth: number;\n pageHeight: number;\n rotation: number;\n scale: number;\n style?: React.CSSProperties;\n convertEventToPoint?: (event: PointerEvent, element: HTMLElement) => Position;\n}\n\nexport const PagePointerProvider = ({\n pageIndex,\n children,\n pageWidth,\n pageHeight,\n rotation,\n scale,\n convertEventToPoint,\n style,\n ...props\n}: PagePointerProviderProps) => {\n const ref = useRef<HTMLDivElement>(null);\n const { provides: cap } = useInteractionManagerCapability();\n const isPageExclusive = useIsPageExclusive();\n\n // Memoize the default conversion function\n const defaultConvertEventToPoint = useCallback(\n (event: PointerEvent, element: HTMLElement): Position => {\n const rect = element.getBoundingClientRect();\n const displayPoint = {\n x: event.clientX - rect.left,\n y: event.clientY - rect.top,\n };\n return restorePosition(\n { width: pageWidth, height: pageHeight },\n displayPoint,\n rotation,\n scale,\n );\n },\n [pageWidth, pageHeight, rotation, scale],\n );\n\n useEffect(() => {\n if (!cap || !ref.current) return;\n\n return createPointerProvider(\n cap,\n { type: 'page', pageIndex },\n ref.current,\n convertEventToPoint || defaultConvertEventToPoint,\n );\n }, [cap, pageIndex, convertEventToPoint, defaultConvertEventToPoint]);\n\n return (\n <div\n ref={ref}\n style={{\n position: 'absolute',\n inset: 0,\n mixBlendMode: 'multiply',\n isolation: 'isolate',\n ...style,\n }}\n {...props}\n >\n {children}\n {isPageExclusive && (\n <div style={{ position: 'absolute', top: 0, left: 0, right: 0, bottom: 0 }} />\n )}\n </div>\n );\n};\n"],"mappings":";;;;;AAAA,SAAS,eAAe,iBAAiB;AACzC;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AACP,SAAS,UAAU,iBAAiB;AAE7B,IAAM,8BAA8B,MACzC,UAAoC,yBAAyB,EAAE;AAC1D,IAAM,kCAAkC,MAC7C,cAAwC,yBAAyB,EAAE;AAE9D,SAAS,wBAAwB;AACtC,QAAM,EAAE,SAAS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ACA;AAAA,MACF;AAAA,IACF;AAAA,IACA,CAAC,WAAW,YAAY,UAAU,KAAK;AAAA,EACzC;AAEA,EAAAC,WAAU,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,UAAU;AAAA,QACV,OAAO;AAAA,QACP,cAAc;AAAA,QACd,WAAW;AAAA,QACX,GAAG;AAAA,MACL;AAAA,MACC,GAAG;AAAA,MAEH;AAAA;AAAA,QACA,mBACC,gBAAAF,KAAC,SAAI,OAAO,EAAE,UAAU,YAAY,KAAK,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,EAAE,GAAG;AAAA;AAAA;AAAA,EAEhF;AAEJ;","names":["state","useEffect","useEffect","useEffect","useRef","jsx","useRef","useEffect"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@embedpdf/plugin-interaction-manager",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -22,19 +22,20 @@
|
|
|
22
22
|
"require": "./dist/react/index.cjs"
|
|
23
23
|
}
|
|
24
24
|
},
|
|
25
|
-
"dependencies": {
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@embedpdf/models": "1.0.2"
|
|
27
|
+
},
|
|
26
28
|
"devDependencies": {
|
|
27
29
|
"@types/react": "^18.2.0",
|
|
28
30
|
"tsup": "^8.0.0",
|
|
29
31
|
"typescript": "^5.0.0",
|
|
30
|
-
"@embedpdf/core": "1.0.
|
|
31
|
-
"@embedpdf/models": "1.0.0"
|
|
32
|
+
"@embedpdf/core": "1.0.2"
|
|
32
33
|
},
|
|
33
34
|
"peerDependencies": {
|
|
34
35
|
"react": ">=16.8.0",
|
|
35
36
|
"react-dom": ">=16.8.0",
|
|
36
37
|
"preact": "^10.26.4",
|
|
37
|
-
"@embedpdf/core": "1.0.
|
|
38
|
+
"@embedpdf/core": "1.0.2"
|
|
38
39
|
},
|
|
39
40
|
"files": [
|
|
40
41
|
"dist",
|