@embedpdf/plugin-pan 1.0.0 → 1.0.1
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/preact/index.cjs +5 -5
- package/dist/preact/index.cjs.map +1 -1
- package/dist/preact/index.d.cts +2 -2
- package/dist/preact/index.d.ts +2 -2
- package/dist/preact/index.js +3 -3
- package/dist/preact/index.js.map +1 -1
- package/dist/react/index.cjs +68 -5
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.cts +5 -2
- package/dist/react/index.d.ts +5 -2
- package/dist/react/index.js +65 -3
- package/dist/react/index.js.map +1 -1
- package/package.json +7 -7
package/dist/preact/index.cjs
CHANGED
|
@@ -21,15 +21,15 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var preact_exports = {};
|
|
22
22
|
__export(preact_exports, {
|
|
23
23
|
PanMode: () => PanMode,
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
usePanCapability: () => usePanCapability,
|
|
25
|
+
usePanPlugin: () => usePanPlugin
|
|
26
26
|
});
|
|
27
27
|
module.exports = __toCommonJS(preact_exports);
|
|
28
28
|
|
|
29
29
|
// src/preact/hooks/use-pan.ts
|
|
30
30
|
var import_preact = require("@embedpdf/core/preact");
|
|
31
31
|
var import_plugin_pan = require("@embedpdf/plugin-pan");
|
|
32
|
-
var
|
|
32
|
+
var usePanPlugin = () => (0, import_preact.usePlugin)(import_plugin_pan.PanPlugin.id);
|
|
33
33
|
var usePanCapability = () => (0, import_preact.useCapability)(import_plugin_pan.PanPlugin.id);
|
|
34
34
|
|
|
35
35
|
// src/preact/components/pan-mode.tsx
|
|
@@ -95,7 +95,7 @@ var PanMode = () => {
|
|
|
95
95
|
// Annotate the CommonJS export names for ESM import in node:
|
|
96
96
|
0 && (module.exports = {
|
|
97
97
|
PanMode,
|
|
98
|
-
|
|
99
|
-
|
|
98
|
+
usePanCapability,
|
|
99
|
+
usePanPlugin
|
|
100
100
|
});
|
|
101
101
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/preact/index.ts","../../src/preact/hooks/use-pan.ts","../../src/preact/components/pan-mode.tsx"],"sourcesContent":["export * from './hooks';\nexport * from './components';\n","import { useCapability, usePlugin } from '@embedpdf/core/preact';\nimport { PanPlugin } from '@embedpdf/plugin-pan';\n\nexport const
|
|
1
|
+
{"version":3,"sources":["../../src/preact/index.ts","../../src/preact/hooks/use-pan.ts","../../src/preact/components/pan-mode.tsx"],"sourcesContent":["export * from './hooks';\nexport * from './components';\n","import { useCapability, usePlugin } from '@embedpdf/core/preact';\nimport { PanPlugin } from '@embedpdf/plugin-pan';\n\nexport const usePanPlugin = () => usePlugin<PanPlugin>(PanPlugin.id);\nexport const usePanCapability = () => useCapability<PanPlugin>(PanPlugin.id);\n","/** @jsxImportSource preact */\nimport { useEffect, useMemo, useRef } from 'preact/hooks';\nimport type { PointerEventHandlers } from '@embedpdf/plugin-interaction-manager';\nimport { useCursor, usePointerHandlers } from '@embedpdf/plugin-interaction-manager/preact';\nimport { useViewportCapability } from '@embedpdf/plugin-viewport/preact';\n\nexport const PanMode = () => {\n const { register } = usePointerHandlers({ modeId: 'panMode' });\n const { setCursor, removeCursor } = useCursor();\n const { provides: viewport } = useViewportCapability();\n\n const dragRef = useRef<{\n startX: number;\n startY: number;\n startLeft: number;\n startTop: number;\n } | null>(null);\n\n const handlers = useMemo(\n (): PointerEventHandlers => ({\n onPointerDown: (_, pe) => {\n if (!viewport) return;\n\n const metrics = viewport.getMetrics();\n\n dragRef.current = {\n startX: pe.clientX,\n startY: pe.clientY,\n startLeft: metrics.scrollLeft,\n startTop: metrics.scrollTop,\n };\n\n setCursor('panMode', 'grabbing', 10);\n },\n onPointerMove: (_, pe) => {\n const drag = dragRef.current;\n if (!drag || !viewport) return;\n\n /* delta between current pointer position and where the drag started */\n const dx = pe.clientX - drag.startX;\n const dy = pe.clientY - drag.startY;\n\n viewport.scrollTo({\n x: drag.startLeft - dx,\n y: drag.startTop - dy,\n });\n },\n onPointerUp: () => {\n const drag = dragRef.current;\n if (!drag) return;\n\n dragRef.current = null;\n removeCursor('panMode');\n },\n onPointerLeave: () => {\n const drag = dragRef.current;\n if (!drag) return;\n\n dragRef.current = null;\n removeCursor('panMode');\n },\n onPointerCancel: () => {\n const drag = dragRef.current;\n if (!drag) return;\n\n dragRef.current = null;\n removeCursor('panMode');\n },\n }),\n [viewport, setCursor, removeCursor],\n );\n\n useEffect(() => {\n if (!register) return;\n return register(handlers);\n }, [register, handlers]);\n\n return <></>;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,oBAAyC;AACzC,wBAA0B;AAEnB,IAAM,eAAe,UAAM,yBAAqB,4BAAU,EAAE;AAC5D,IAAM,mBAAmB,UAAM,6BAAyB,4BAAU,EAAE;;;ACH3E,mBAA2C;AAE3C,IAAAA,iBAA8C;AAC9C,IAAAA,iBAAsC;AAyE7B;AAvEF,IAAM,UAAU,MAAM;AAC3B,QAAM,EAAE,SAAS,QAAI,mCAAmB,EAAE,QAAQ,UAAU,CAAC;AAC7D,QAAM,EAAE,WAAW,aAAa,QAAI,0BAAU;AAC9C,QAAM,EAAE,UAAU,SAAS,QAAI,sCAAsB;AAErD,QAAM,cAAU,qBAKN,IAAI;AAEd,QAAM,eAAW;AAAA,IACf,OAA6B;AAAA,MAC3B,eAAe,CAAC,GAAG,OAAO;AACxB,YAAI,CAAC,SAAU;AAEf,cAAM,UAAU,SAAS,WAAW;AAEpC,gBAAQ,UAAU;AAAA,UAChB,QAAQ,GAAG;AAAA,UACX,QAAQ,GAAG;AAAA,UACX,WAAW,QAAQ;AAAA,UACnB,UAAU,QAAQ;AAAA,QACpB;AAEA,kBAAU,WAAW,YAAY,EAAE;AAAA,MACrC;AAAA,MACA,eAAe,CAAC,GAAG,OAAO;AACxB,cAAM,OAAO,QAAQ;AACrB,YAAI,CAAC,QAAQ,CAAC,SAAU;AAGxB,cAAM,KAAK,GAAG,UAAU,KAAK;AAC7B,cAAM,KAAK,GAAG,UAAU,KAAK;AAE7B,iBAAS,SAAS;AAAA,UAChB,GAAG,KAAK,YAAY;AAAA,UACpB,GAAG,KAAK,WAAW;AAAA,QACrB,CAAC;AAAA,MACH;AAAA,MACA,aAAa,MAAM;AACjB,cAAM,OAAO,QAAQ;AACrB,YAAI,CAAC,KAAM;AAEX,gBAAQ,UAAU;AAClB,qBAAa,SAAS;AAAA,MACxB;AAAA,MACA,gBAAgB,MAAM;AACpB,cAAM,OAAO,QAAQ;AACrB,YAAI,CAAC,KAAM;AAEX,gBAAQ,UAAU;AAClB,qBAAa,SAAS;AAAA,MACxB;AAAA,MACA,iBAAiB,MAAM;AACrB,cAAM,OAAO,QAAQ;AACrB,YAAI,CAAC,KAAM;AAEX,gBAAQ,UAAU;AAClB,qBAAa,SAAS;AAAA,MACxB;AAAA,IACF;AAAA,IACA,CAAC,UAAU,WAAW,YAAY;AAAA,EACpC;AAEA,8BAAU,MAAM;AACd,QAAI,CAAC,SAAU;AACf,WAAO,SAAS,QAAQ;AAAA,EAC1B,GAAG,CAAC,UAAU,QAAQ,CAAC;AAEvB,SAAO,2EAAE;AACX;","names":["import_preact"]}
|
package/dist/preact/index.d.cts
CHANGED
|
@@ -2,7 +2,7 @@ import * as _embedpdf_plugin_pan from '@embedpdf/plugin-pan';
|
|
|
2
2
|
import { PanPlugin } from '@embedpdf/plugin-pan';
|
|
3
3
|
import * as preact from 'preact';
|
|
4
4
|
|
|
5
|
-
declare const
|
|
5
|
+
declare const usePanPlugin: () => {
|
|
6
6
|
plugin: PanPlugin | null;
|
|
7
7
|
isLoading: boolean;
|
|
8
8
|
ready: Promise<void>;
|
|
@@ -15,4 +15,4 @@ declare const usePanCapability: () => {
|
|
|
15
15
|
|
|
16
16
|
declare const PanMode: () => preact.JSX.Element;
|
|
17
17
|
|
|
18
|
-
export { PanMode,
|
|
18
|
+
export { PanMode, usePanCapability, usePanPlugin };
|
package/dist/preact/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import * as _embedpdf_plugin_pan from '@embedpdf/plugin-pan';
|
|
|
2
2
|
import { PanPlugin } from '@embedpdf/plugin-pan';
|
|
3
3
|
import * as preact from 'preact';
|
|
4
4
|
|
|
5
|
-
declare const
|
|
5
|
+
declare const usePanPlugin: () => {
|
|
6
6
|
plugin: PanPlugin | null;
|
|
7
7
|
isLoading: boolean;
|
|
8
8
|
ready: Promise<void>;
|
|
@@ -15,4 +15,4 @@ declare const usePanCapability: () => {
|
|
|
15
15
|
|
|
16
16
|
declare const PanMode: () => preact.JSX.Element;
|
|
17
17
|
|
|
18
|
-
export { PanMode,
|
|
18
|
+
export { PanMode, usePanCapability, usePanPlugin };
|
package/dist/preact/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// src/preact/hooks/use-pan.ts
|
|
2
2
|
import { useCapability, usePlugin } from "@embedpdf/core/preact";
|
|
3
3
|
import { PanPlugin } from "@embedpdf/plugin-pan";
|
|
4
|
-
var
|
|
4
|
+
var usePanPlugin = () => usePlugin(PanPlugin.id);
|
|
5
5
|
var usePanCapability = () => useCapability(PanPlugin.id);
|
|
6
6
|
|
|
7
7
|
// src/preact/components/pan-mode.tsx
|
|
@@ -66,7 +66,7 @@ var PanMode = () => {
|
|
|
66
66
|
};
|
|
67
67
|
export {
|
|
68
68
|
PanMode,
|
|
69
|
-
|
|
70
|
-
|
|
69
|
+
usePanCapability,
|
|
70
|
+
usePanPlugin
|
|
71
71
|
};
|
|
72
72
|
//# sourceMappingURL=index.js.map
|
package/dist/preact/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/preact/hooks/use-pan.ts","../../src/preact/components/pan-mode.tsx"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/preact';\nimport { PanPlugin } from '@embedpdf/plugin-pan';\n\nexport const
|
|
1
|
+
{"version":3,"sources":["../../src/preact/hooks/use-pan.ts","../../src/preact/components/pan-mode.tsx"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/preact';\nimport { PanPlugin } from '@embedpdf/plugin-pan';\n\nexport const usePanPlugin = () => usePlugin<PanPlugin>(PanPlugin.id);\nexport const usePanCapability = () => useCapability<PanPlugin>(PanPlugin.id);\n","/** @jsxImportSource preact */\nimport { useEffect, useMemo, useRef } from 'preact/hooks';\nimport type { PointerEventHandlers } from '@embedpdf/plugin-interaction-manager';\nimport { useCursor, usePointerHandlers } from '@embedpdf/plugin-interaction-manager/preact';\nimport { useViewportCapability } from '@embedpdf/plugin-viewport/preact';\n\nexport const PanMode = () => {\n const { register } = usePointerHandlers({ modeId: 'panMode' });\n const { setCursor, removeCursor } = useCursor();\n const { provides: viewport } = useViewportCapability();\n\n const dragRef = useRef<{\n startX: number;\n startY: number;\n startLeft: number;\n startTop: number;\n } | null>(null);\n\n const handlers = useMemo(\n (): PointerEventHandlers => ({\n onPointerDown: (_, pe) => {\n if (!viewport) return;\n\n const metrics = viewport.getMetrics();\n\n dragRef.current = {\n startX: pe.clientX,\n startY: pe.clientY,\n startLeft: metrics.scrollLeft,\n startTop: metrics.scrollTop,\n };\n\n setCursor('panMode', 'grabbing', 10);\n },\n onPointerMove: (_, pe) => {\n const drag = dragRef.current;\n if (!drag || !viewport) return;\n\n /* delta between current pointer position and where the drag started */\n const dx = pe.clientX - drag.startX;\n const dy = pe.clientY - drag.startY;\n\n viewport.scrollTo({\n x: drag.startLeft - dx,\n y: drag.startTop - dy,\n });\n },\n onPointerUp: () => {\n const drag = dragRef.current;\n if (!drag) return;\n\n dragRef.current = null;\n removeCursor('panMode');\n },\n onPointerLeave: () => {\n const drag = dragRef.current;\n if (!drag) return;\n\n dragRef.current = null;\n removeCursor('panMode');\n },\n onPointerCancel: () => {\n const drag = dragRef.current;\n if (!drag) return;\n\n dragRef.current = null;\n removeCursor('panMode');\n },\n }),\n [viewport, setCursor, removeCursor],\n );\n\n useEffect(() => {\n if (!register) return;\n return register(handlers);\n }, [register, handlers]);\n\n return <></>;\n};\n"],"mappings":";AAAA,SAAS,eAAe,iBAAiB;AACzC,SAAS,iBAAiB;AAEnB,IAAM,eAAe,MAAM,UAAqB,UAAU,EAAE;AAC5D,IAAM,mBAAmB,MAAM,cAAyB,UAAU,EAAE;;;ACH3E,SAAS,WAAW,SAAS,cAAc;AAE3C,SAAS,WAAW,0BAA0B;AAC9C,SAAS,6BAA6B;AAyE7B;AAvEF,IAAM,UAAU,MAAM;AAC3B,QAAM,EAAE,SAAS,IAAI,mBAAmB,EAAE,QAAQ,UAAU,CAAC;AAC7D,QAAM,EAAE,WAAW,aAAa,IAAI,UAAU;AAC9C,QAAM,EAAE,UAAU,SAAS,IAAI,sBAAsB;AAErD,QAAM,UAAU,OAKN,IAAI;AAEd,QAAM,WAAW;AAAA,IACf,OAA6B;AAAA,MAC3B,eAAe,CAAC,GAAG,OAAO;AACxB,YAAI,CAAC,SAAU;AAEf,cAAM,UAAU,SAAS,WAAW;AAEpC,gBAAQ,UAAU;AAAA,UAChB,QAAQ,GAAG;AAAA,UACX,QAAQ,GAAG;AAAA,UACX,WAAW,QAAQ;AAAA,UACnB,UAAU,QAAQ;AAAA,QACpB;AAEA,kBAAU,WAAW,YAAY,EAAE;AAAA,MACrC;AAAA,MACA,eAAe,CAAC,GAAG,OAAO;AACxB,cAAM,OAAO,QAAQ;AACrB,YAAI,CAAC,QAAQ,CAAC,SAAU;AAGxB,cAAM,KAAK,GAAG,UAAU,KAAK;AAC7B,cAAM,KAAK,GAAG,UAAU,KAAK;AAE7B,iBAAS,SAAS;AAAA,UAChB,GAAG,KAAK,YAAY;AAAA,UACpB,GAAG,KAAK,WAAW;AAAA,QACrB,CAAC;AAAA,MACH;AAAA,MACA,aAAa,MAAM;AACjB,cAAM,OAAO,QAAQ;AACrB,YAAI,CAAC,KAAM;AAEX,gBAAQ,UAAU;AAClB,qBAAa,SAAS;AAAA,MACxB;AAAA,MACA,gBAAgB,MAAM;AACpB,cAAM,OAAO,QAAQ;AACrB,YAAI,CAAC,KAAM;AAEX,gBAAQ,UAAU;AAClB,qBAAa,SAAS;AAAA,MACxB;AAAA,MACA,iBAAiB,MAAM;AACrB,cAAM,OAAO,QAAQ;AACrB,YAAI,CAAC,KAAM;AAEX,gBAAQ,UAAU;AAClB,qBAAa,SAAS;AAAA,MACxB;AAAA,IACF;AAAA,IACA,CAAC,UAAU,WAAW,YAAY;AAAA,EACpC;AAEA,YAAU,MAAM;AACd,QAAI,CAAC,SAAU;AACf,WAAO,SAAS,QAAQ;AAAA,EAC1B,GAAG,CAAC,UAAU,QAAQ,CAAC;AAEvB,SAAO,gCAAE;AACX;","names":[]}
|
package/dist/react/index.cjs
CHANGED
|
@@ -20,19 +20,82 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/react/index.ts
|
|
21
21
|
var react_exports = {};
|
|
22
22
|
__export(react_exports, {
|
|
23
|
-
|
|
24
|
-
usePanCapability: () => usePanCapability
|
|
23
|
+
PanMode: () => PanMode,
|
|
24
|
+
usePanCapability: () => usePanCapability,
|
|
25
|
+
usePanPlugin: () => usePanPlugin
|
|
25
26
|
});
|
|
26
27
|
module.exports = __toCommonJS(react_exports);
|
|
27
28
|
|
|
28
29
|
// src/react/hooks/use-pan.ts
|
|
29
30
|
var import_react = require("@embedpdf/core/react");
|
|
30
31
|
var import_plugin_pan = require("@embedpdf/plugin-pan");
|
|
31
|
-
var
|
|
32
|
+
var usePanPlugin = () => (0, import_react.usePlugin)(import_plugin_pan.PanPlugin.id);
|
|
32
33
|
var usePanCapability = () => (0, import_react.useCapability)(import_plugin_pan.PanPlugin.id);
|
|
34
|
+
|
|
35
|
+
// src/react/components/pan-mode.tsx
|
|
36
|
+
var import_react2 = require("react");
|
|
37
|
+
var import_react3 = require("@embedpdf/plugin-interaction-manager/react");
|
|
38
|
+
var import_react4 = require("@embedpdf/plugin-viewport/react");
|
|
39
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
40
|
+
var PanMode = () => {
|
|
41
|
+
const { register } = (0, import_react3.usePointerHandlers)({ modeId: "panMode" });
|
|
42
|
+
const { setCursor, removeCursor } = (0, import_react3.useCursor)();
|
|
43
|
+
const { provides: viewport } = (0, import_react4.useViewportCapability)();
|
|
44
|
+
const dragRef = (0, import_react2.useRef)(null);
|
|
45
|
+
const handlers = (0, import_react2.useMemo)(
|
|
46
|
+
() => ({
|
|
47
|
+
onPointerDown: (_, pe) => {
|
|
48
|
+
if (!viewport) return;
|
|
49
|
+
const metrics = viewport.getMetrics();
|
|
50
|
+
dragRef.current = {
|
|
51
|
+
startX: pe.clientX,
|
|
52
|
+
startY: pe.clientY,
|
|
53
|
+
startLeft: metrics.scrollLeft,
|
|
54
|
+
startTop: metrics.scrollTop
|
|
55
|
+
};
|
|
56
|
+
setCursor("panMode", "grabbing", 10);
|
|
57
|
+
},
|
|
58
|
+
onPointerMove: (_, pe) => {
|
|
59
|
+
const drag = dragRef.current;
|
|
60
|
+
if (!drag || !viewport) return;
|
|
61
|
+
const dx = pe.clientX - drag.startX;
|
|
62
|
+
const dy = pe.clientY - drag.startY;
|
|
63
|
+
viewport.scrollTo({
|
|
64
|
+
x: drag.startLeft - dx,
|
|
65
|
+
y: drag.startTop - dy
|
|
66
|
+
});
|
|
67
|
+
},
|
|
68
|
+
onPointerUp: () => {
|
|
69
|
+
const drag = dragRef.current;
|
|
70
|
+
if (!drag) return;
|
|
71
|
+
dragRef.current = null;
|
|
72
|
+
removeCursor("panMode");
|
|
73
|
+
},
|
|
74
|
+
onPointerLeave: () => {
|
|
75
|
+
const drag = dragRef.current;
|
|
76
|
+
if (!drag) return;
|
|
77
|
+
dragRef.current = null;
|
|
78
|
+
removeCursor("panMode");
|
|
79
|
+
},
|
|
80
|
+
onPointerCancel: () => {
|
|
81
|
+
const drag = dragRef.current;
|
|
82
|
+
if (!drag) return;
|
|
83
|
+
dragRef.current = null;
|
|
84
|
+
removeCursor("panMode");
|
|
85
|
+
}
|
|
86
|
+
}),
|
|
87
|
+
[viewport, setCursor, removeCursor]
|
|
88
|
+
);
|
|
89
|
+
(0, import_react2.useEffect)(() => {
|
|
90
|
+
if (!register) return;
|
|
91
|
+
return register(handlers);
|
|
92
|
+
}, [register, handlers]);
|
|
93
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {});
|
|
94
|
+
};
|
|
33
95
|
// Annotate the CommonJS export names for ESM import in node:
|
|
34
96
|
0 && (module.exports = {
|
|
35
|
-
|
|
36
|
-
usePanCapability
|
|
97
|
+
PanMode,
|
|
98
|
+
usePanCapability,
|
|
99
|
+
usePanPlugin
|
|
37
100
|
});
|
|
38
101
|
//# sourceMappingURL=index.cjs.map
|
package/dist/react/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/react/index.ts","../../src/react/hooks/use-pan.ts"],"sourcesContent":["export * from './hooks';\n","import { useCapability, usePlugin } from '@embedpdf/core/react';\nimport { PanPlugin } from '@embedpdf/plugin-pan';\n\nexport const
|
|
1
|
+
{"version":3,"sources":["../../src/react/index.ts","../../src/react/hooks/use-pan.ts","../../src/react/components/pan-mode.tsx"],"sourcesContent":["export * from './hooks';\nexport * from './components';\n","import { useCapability, usePlugin } from '@embedpdf/core/react';\nimport { PanPlugin } from '@embedpdf/plugin-pan';\n\nexport const usePanPlugin = () => usePlugin<PanPlugin>(PanPlugin.id);\nexport const usePanCapability = () => useCapability<PanPlugin>(PanPlugin.id);\n","import { useEffect, useMemo, useRef } from 'react';\nimport type { PointerEventHandlers } from '@embedpdf/plugin-interaction-manager';\nimport { useCursor, usePointerHandlers } from '@embedpdf/plugin-interaction-manager/react';\nimport { useViewportCapability } from '@embedpdf/plugin-viewport/react';\n\nexport const PanMode = () => {\n const { register } = usePointerHandlers({ modeId: 'panMode' });\n const { setCursor, removeCursor } = useCursor();\n const { provides: viewport } = useViewportCapability();\n\n const dragRef = useRef<{\n startX: number;\n startY: number;\n startLeft: number;\n startTop: number;\n } | null>(null);\n\n const handlers = useMemo(\n (): PointerEventHandlers => ({\n onPointerDown: (_, pe) => {\n if (!viewport) return;\n\n const metrics = viewport.getMetrics();\n\n dragRef.current = {\n startX: pe.clientX,\n startY: pe.clientY,\n startLeft: metrics.scrollLeft,\n startTop: metrics.scrollTop,\n };\n\n setCursor('panMode', 'grabbing', 10);\n },\n onPointerMove: (_, pe) => {\n const drag = dragRef.current;\n if (!drag || !viewport) return;\n\n /* delta between current pointer position and where the drag started */\n const dx = pe.clientX - drag.startX;\n const dy = pe.clientY - drag.startY;\n\n viewport.scrollTo({\n x: drag.startLeft - dx,\n y: drag.startTop - dy,\n });\n },\n onPointerUp: () => {\n const drag = dragRef.current;\n if (!drag) return;\n\n dragRef.current = null;\n removeCursor('panMode');\n },\n onPointerLeave: () => {\n const drag = dragRef.current;\n if (!drag) return;\n\n dragRef.current = null;\n removeCursor('panMode');\n },\n onPointerCancel: () => {\n const drag = dragRef.current;\n if (!drag) return;\n\n dragRef.current = null;\n removeCursor('panMode');\n },\n }),\n [viewport, setCursor, removeCursor],\n );\n\n useEffect(() => {\n if (!register) return;\n return register(handlers);\n }, [register, handlers]);\n\n return <></>;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAAyC;AACzC,wBAA0B;AAEnB,IAAM,eAAe,UAAM,wBAAqB,4BAAU,EAAE;AAC5D,IAAM,mBAAmB,UAAM,4BAAyB,4BAAU,EAAE;;;ACJ3E,IAAAA,gBAA2C;AAE3C,IAAAA,gBAA8C;AAC9C,IAAAA,gBAAsC;AAyE7B;AAvEF,IAAM,UAAU,MAAM;AAC3B,QAAM,EAAE,SAAS,QAAI,kCAAmB,EAAE,QAAQ,UAAU,CAAC;AAC7D,QAAM,EAAE,WAAW,aAAa,QAAI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AE;AACX;","names":["import_react"]}
|
package/dist/react/index.d.cts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import * as _embedpdf_plugin_pan from '@embedpdf/plugin-pan';
|
|
2
2
|
import { PanPlugin } from '@embedpdf/plugin-pan';
|
|
3
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
3
4
|
|
|
4
|
-
declare const
|
|
5
|
+
declare const usePanPlugin: () => {
|
|
5
6
|
plugin: PanPlugin | null;
|
|
6
7
|
isLoading: boolean;
|
|
7
8
|
ready: Promise<void>;
|
|
@@ -12,4 +13,6 @@ declare const usePanCapability: () => {
|
|
|
12
13
|
ready: Promise<void>;
|
|
13
14
|
};
|
|
14
15
|
|
|
15
|
-
|
|
16
|
+
declare const PanMode: () => react_jsx_runtime.JSX.Element;
|
|
17
|
+
|
|
18
|
+
export { PanMode, usePanCapability, usePanPlugin };
|
package/dist/react/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import * as _embedpdf_plugin_pan from '@embedpdf/plugin-pan';
|
|
2
2
|
import { PanPlugin } from '@embedpdf/plugin-pan';
|
|
3
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
3
4
|
|
|
4
|
-
declare const
|
|
5
|
+
declare const usePanPlugin: () => {
|
|
5
6
|
plugin: PanPlugin | null;
|
|
6
7
|
isLoading: boolean;
|
|
7
8
|
ready: Promise<void>;
|
|
@@ -12,4 +13,6 @@ declare const usePanCapability: () => {
|
|
|
12
13
|
ready: Promise<void>;
|
|
13
14
|
};
|
|
14
15
|
|
|
15
|
-
|
|
16
|
+
declare const PanMode: () => react_jsx_runtime.JSX.Element;
|
|
17
|
+
|
|
18
|
+
export { PanMode, usePanCapability, usePanPlugin };
|
package/dist/react/index.js
CHANGED
|
@@ -1,10 +1,72 @@
|
|
|
1
1
|
// src/react/hooks/use-pan.ts
|
|
2
2
|
import { useCapability, usePlugin } from "@embedpdf/core/react";
|
|
3
3
|
import { PanPlugin } from "@embedpdf/plugin-pan";
|
|
4
|
-
var
|
|
4
|
+
var usePanPlugin = () => usePlugin(PanPlugin.id);
|
|
5
5
|
var usePanCapability = () => useCapability(PanPlugin.id);
|
|
6
|
+
|
|
7
|
+
// src/react/components/pan-mode.tsx
|
|
8
|
+
import { useEffect, useMemo, useRef } from "react";
|
|
9
|
+
import { useCursor, usePointerHandlers } from "@embedpdf/plugin-interaction-manager/react";
|
|
10
|
+
import { useViewportCapability } from "@embedpdf/plugin-viewport/react";
|
|
11
|
+
import { Fragment, jsx } from "react/jsx-runtime";
|
|
12
|
+
var PanMode = () => {
|
|
13
|
+
const { register } = usePointerHandlers({ modeId: "panMode" });
|
|
14
|
+
const { setCursor, removeCursor } = useCursor();
|
|
15
|
+
const { provides: viewport } = useViewportCapability();
|
|
16
|
+
const dragRef = useRef(null);
|
|
17
|
+
const handlers = useMemo(
|
|
18
|
+
() => ({
|
|
19
|
+
onPointerDown: (_, pe) => {
|
|
20
|
+
if (!viewport) return;
|
|
21
|
+
const metrics = viewport.getMetrics();
|
|
22
|
+
dragRef.current = {
|
|
23
|
+
startX: pe.clientX,
|
|
24
|
+
startY: pe.clientY,
|
|
25
|
+
startLeft: metrics.scrollLeft,
|
|
26
|
+
startTop: metrics.scrollTop
|
|
27
|
+
};
|
|
28
|
+
setCursor("panMode", "grabbing", 10);
|
|
29
|
+
},
|
|
30
|
+
onPointerMove: (_, pe) => {
|
|
31
|
+
const drag = dragRef.current;
|
|
32
|
+
if (!drag || !viewport) return;
|
|
33
|
+
const dx = pe.clientX - drag.startX;
|
|
34
|
+
const dy = pe.clientY - drag.startY;
|
|
35
|
+
viewport.scrollTo({
|
|
36
|
+
x: drag.startLeft - dx,
|
|
37
|
+
y: drag.startTop - dy
|
|
38
|
+
});
|
|
39
|
+
},
|
|
40
|
+
onPointerUp: () => {
|
|
41
|
+
const drag = dragRef.current;
|
|
42
|
+
if (!drag) return;
|
|
43
|
+
dragRef.current = null;
|
|
44
|
+
removeCursor("panMode");
|
|
45
|
+
},
|
|
46
|
+
onPointerLeave: () => {
|
|
47
|
+
const drag = dragRef.current;
|
|
48
|
+
if (!drag) return;
|
|
49
|
+
dragRef.current = null;
|
|
50
|
+
removeCursor("panMode");
|
|
51
|
+
},
|
|
52
|
+
onPointerCancel: () => {
|
|
53
|
+
const drag = dragRef.current;
|
|
54
|
+
if (!drag) return;
|
|
55
|
+
dragRef.current = null;
|
|
56
|
+
removeCursor("panMode");
|
|
57
|
+
}
|
|
58
|
+
}),
|
|
59
|
+
[viewport, setCursor, removeCursor]
|
|
60
|
+
);
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
if (!register) return;
|
|
63
|
+
return register(handlers);
|
|
64
|
+
}, [register, handlers]);
|
|
65
|
+
return /* @__PURE__ */ jsx(Fragment, {});
|
|
66
|
+
};
|
|
6
67
|
export {
|
|
7
|
-
|
|
8
|
-
usePanCapability
|
|
68
|
+
PanMode,
|
|
69
|
+
usePanCapability,
|
|
70
|
+
usePanPlugin
|
|
9
71
|
};
|
|
10
72
|
//# sourceMappingURL=index.js.map
|
package/dist/react/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/react/hooks/use-pan.ts"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/react';\nimport { PanPlugin } from '@embedpdf/plugin-pan';\n\nexport const
|
|
1
|
+
{"version":3,"sources":["../../src/react/hooks/use-pan.ts","../../src/react/components/pan-mode.tsx"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/react';\nimport { PanPlugin } from '@embedpdf/plugin-pan';\n\nexport const usePanPlugin = () => usePlugin<PanPlugin>(PanPlugin.id);\nexport const usePanCapability = () => useCapability<PanPlugin>(PanPlugin.id);\n","import { useEffect, useMemo, useRef } from 'react';\nimport type { PointerEventHandlers } from '@embedpdf/plugin-interaction-manager';\nimport { useCursor, usePointerHandlers } from '@embedpdf/plugin-interaction-manager/react';\nimport { useViewportCapability } from '@embedpdf/plugin-viewport/react';\n\nexport const PanMode = () => {\n const { register } = usePointerHandlers({ modeId: 'panMode' });\n const { setCursor, removeCursor } = useCursor();\n const { provides: viewport } = useViewportCapability();\n\n const dragRef = useRef<{\n startX: number;\n startY: number;\n startLeft: number;\n startTop: number;\n } | null>(null);\n\n const handlers = useMemo(\n (): PointerEventHandlers => ({\n onPointerDown: (_, pe) => {\n if (!viewport) return;\n\n const metrics = viewport.getMetrics();\n\n dragRef.current = {\n startX: pe.clientX,\n startY: pe.clientY,\n startLeft: metrics.scrollLeft,\n startTop: metrics.scrollTop,\n };\n\n setCursor('panMode', 'grabbing', 10);\n },\n onPointerMove: (_, pe) => {\n const drag = dragRef.current;\n if (!drag || !viewport) return;\n\n /* delta between current pointer position and where the drag started */\n const dx = pe.clientX - drag.startX;\n const dy = pe.clientY - drag.startY;\n\n viewport.scrollTo({\n x: drag.startLeft - dx,\n y: drag.startTop - dy,\n });\n },\n onPointerUp: () => {\n const drag = dragRef.current;\n if (!drag) return;\n\n dragRef.current = null;\n removeCursor('panMode');\n },\n onPointerLeave: () => {\n const drag = dragRef.current;\n if (!drag) return;\n\n dragRef.current = null;\n removeCursor('panMode');\n },\n onPointerCancel: () => {\n const drag = dragRef.current;\n if (!drag) return;\n\n dragRef.current = null;\n removeCursor('panMode');\n },\n }),\n [viewport, setCursor, removeCursor],\n );\n\n useEffect(() => {\n if (!register) return;\n return register(handlers);\n }, [register, handlers]);\n\n return <></>;\n};\n"],"mappings":";AAAA,SAAS,eAAe,iBAAiB;AACzC,SAAS,iBAAiB;AAEnB,IAAM,eAAe,MAAM,UAAqB,UAAU,EAAE;AAC5D,IAAM,mBAAmB,MAAM,cAAyB,UAAU,EAAE;;;ACJ3E,SAAS,WAAW,SAAS,cAAc;AAE3C,SAAS,WAAW,0BAA0B;AAC9C,SAAS,6BAA6B;AAyE7B;AAvEF,IAAM,UAAU,MAAM;AAC3B,QAAM,EAAE,SAAS,IAAI,mBAAmB,EAAE,QAAQ,UAAU,CAAC;AAC7D,Q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,CAAC;AAEvB,SAAO,gCAAE;AACX;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@embedpdf/plugin-pan",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -27,17 +27,17 @@
|
|
|
27
27
|
"@types/react": "^18.2.0",
|
|
28
28
|
"tsup": "^8.0.0",
|
|
29
29
|
"typescript": "^5.0.0",
|
|
30
|
-
"@embedpdf/
|
|
31
|
-
"@embedpdf/
|
|
32
|
-
"@embedpdf/plugin-viewport": "1.0.
|
|
30
|
+
"@embedpdf/plugin-interaction-manager": "1.0.1",
|
|
31
|
+
"@embedpdf/models": "1.0.1",
|
|
32
|
+
"@embedpdf/plugin-viewport": "1.0.1"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
35
|
"react": ">=16.8.0",
|
|
36
36
|
"react-dom": ">=16.8.0",
|
|
37
37
|
"preact": "^10.26.4",
|
|
38
|
-
"@embedpdf/plugin-interaction-manager": "1.0.
|
|
39
|
-
"@embedpdf/core": "1.0.
|
|
40
|
-
"@embedpdf/plugin-viewport": "1.0.
|
|
38
|
+
"@embedpdf/plugin-interaction-manager": "1.0.1",
|
|
39
|
+
"@embedpdf/core": "1.0.1",
|
|
40
|
+
"@embedpdf/plugin-viewport": "1.0.1"
|
|
41
41
|
},
|
|
42
42
|
"files": [
|
|
43
43
|
"dist",
|