@embedpdf/plugin-pan 1.0.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 CloudPDF
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/index.cjs ADDED
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ PAN_PLUGIN_ID: () => PAN_PLUGIN_ID,
24
+ PanPlugin: () => PanPlugin,
25
+ PanPluginPackage: () => PanPluginPackage,
26
+ manifest: () => manifest
27
+ });
28
+ module.exports = __toCommonJS(index_exports);
29
+
30
+ // src/lib/pan-plugin.ts
31
+ var import_core = require("@embedpdf/core");
32
+ var import_plugin_interaction_manager = require("@embedpdf/plugin-interaction-manager");
33
+ var PanPlugin = class extends import_core.BasePlugin {
34
+ constructor(id, registry) {
35
+ super(id, registry);
36
+ this.interactionManager = registry.getPlugin(import_plugin_interaction_manager.InteractionManagerPlugin.id)?.provides();
37
+ this.interactionManager.registerMode({
38
+ id: "panMode",
39
+ scope: "global",
40
+ exclusive: false,
41
+ cursor: "grab"
42
+ });
43
+ }
44
+ async initialize(_) {
45
+ }
46
+ buildCapability() {
47
+ return {
48
+ enablePan: () => this.interactionManager.activate("panMode"),
49
+ disablePan: () => this.interactionManager.activate("default")
50
+ };
51
+ }
52
+ };
53
+ PanPlugin.id = "pan";
54
+
55
+ // src/lib/manifest.ts
56
+ var PAN_PLUGIN_ID = "pan";
57
+ var manifest = {
58
+ id: PAN_PLUGIN_ID,
59
+ name: "Pan Plugin",
60
+ version: "1.0.0",
61
+ provides: ["pan"],
62
+ requires: ["interaction-manager"],
63
+ optional: [],
64
+ defaultConfig: {
65
+ enabled: true
66
+ }
67
+ };
68
+
69
+ // src/lib/index.ts
70
+ var PanPluginPackage = {
71
+ manifest,
72
+ create: (registry) => new PanPlugin(PAN_PLUGIN_ID, registry),
73
+ reducer: () => {
74
+ },
75
+ initialState: {}
76
+ };
77
+ // Annotate the CommonJS export names for ESM import in node:
78
+ 0 && (module.exports = {
79
+ PAN_PLUGIN_ID,
80
+ PanPlugin,
81
+ PanPluginPackage,
82
+ manifest
83
+ });
84
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/lib/pan-plugin.ts","../src/lib/manifest.ts","../src/lib/index.ts"],"sourcesContent":["export * from './lib';\n","import { BasePlugin, PluginRegistry } from '@embedpdf/core';\nimport {\n InteractionManagerCapability,\n InteractionManagerPlugin,\n} from '@embedpdf/plugin-interaction-manager';\n\nimport { PanCapability, PanPluginConfig } from './types';\n\nexport class PanPlugin extends BasePlugin<PanPluginConfig, PanCapability> {\n static readonly id = 'pan' as const;\n\n private interactionManager: InteractionManagerCapability;\n\n constructor(id: string, registry: PluginRegistry) {\n super(id, registry);\n\n this.interactionManager = registry\n .getPlugin<InteractionManagerPlugin>(InteractionManagerPlugin.id)\n ?.provides()!;\n\n this.interactionManager.registerMode({\n id: 'panMode',\n scope: 'global',\n exclusive: false,\n cursor: 'grab',\n });\n }\n\n async initialize(_: PanPluginConfig): Promise<void> {}\n\n protected buildCapability(): PanCapability {\n return {\n enablePan: () => this.interactionManager.activate('panMode'),\n disablePan: () => this.interactionManager.activate('default'),\n };\n }\n}\n","import { PluginManifest } from '@embedpdf/core';\nimport { PanPluginConfig } from './types';\n\nexport const PAN_PLUGIN_ID = 'pan';\n\nexport const manifest: PluginManifest<PanPluginConfig> = {\n id: PAN_PLUGIN_ID,\n name: 'Pan Plugin',\n version: '1.0.0',\n provides: ['pan'],\n requires: ['interaction-manager'],\n optional: [],\n defaultConfig: {\n enabled: true,\n },\n};\n","import { PluginPackage } from '@embedpdf/core';\n\nimport { PanPlugin } from './pan-plugin';\nimport { manifest, PAN_PLUGIN_ID } from './manifest';\nimport { PanPluginConfig } from './types';\n\nexport const PanPluginPackage: PluginPackage<PanPlugin, PanPluginConfig> = {\n manifest,\n create: (registry) => new PanPlugin(PAN_PLUGIN_ID, registry),\n reducer: () => {},\n initialState: {},\n};\n\nexport * from './pan-plugin';\nexport * from './types';\nexport * from './manifest';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,kBAA2C;AAC3C,wCAGO;AAIA,IAAM,YAAN,cAAwB,uBAA2C;AAAA,EAKxE,YAAY,IAAY,UAA0B;AAChD,UAAM,IAAI,QAAQ;AAElB,SAAK,qBAAqB,SACvB,UAAoC,2DAAyB,EAAE,GAC9D,SAAS;AAEb,SAAK,mBAAmB,aAAa;AAAA,MACnC,IAAI;AAAA,MACJ,OAAO;AAAA,MACP,WAAW;AAAA,MACX,QAAQ;AAAA,IACV,CAAC;AAAA,EACH;AAAA,EAEA,MAAM,WAAW,GAAmC;AAAA,EAAC;AAAA,EAE3C,kBAAiC;AACzC,WAAO;AAAA,MACL,WAAW,MAAM,KAAK,mBAAmB,SAAS,SAAS;AAAA,MAC3D,YAAY,MAAM,KAAK,mBAAmB,SAAS,SAAS;AAAA,IAC9D;AAAA,EACF;AACF;AA5Ba,UACK,KAAK;;;ACNhB,IAAM,gBAAgB;AAEtB,IAAM,WAA4C;AAAA,EACvD,IAAI;AAAA,EACJ,MAAM;AAAA,EACN,SAAS;AAAA,EACT,UAAU,CAAC,KAAK;AAAA,EAChB,UAAU,CAAC,qBAAqB;AAAA,EAChC,UAAU,CAAC;AAAA,EACX,eAAe;AAAA,IACb,SAAS;AAAA,EACX;AACF;;;ACTO,IAAM,mBAA8D;AAAA,EACzE;AAAA,EACA,QAAQ,CAAC,aAAa,IAAI,UAAU,eAAe,QAAQ;AAAA,EAC3D,SAAS,MAAM;AAAA,EAAC;AAAA,EAChB,cAAc,CAAC;AACjB;","names":[]}
@@ -0,0 +1,23 @@
1
+ import { BasePluginConfig, BasePlugin, PluginRegistry, PluginManifest, PluginPackage } from '@embedpdf/core';
2
+
3
+ interface PanPluginConfig extends BasePluginConfig {
4
+ }
5
+ interface PanCapability {
6
+ enablePan: () => void;
7
+ disablePan: () => void;
8
+ }
9
+
10
+ declare class PanPlugin extends BasePlugin<PanPluginConfig, PanCapability> {
11
+ static readonly id: "pan";
12
+ private interactionManager;
13
+ constructor(id: string, registry: PluginRegistry);
14
+ initialize(_: PanPluginConfig): Promise<void>;
15
+ protected buildCapability(): PanCapability;
16
+ }
17
+
18
+ declare const PAN_PLUGIN_ID = "pan";
19
+ declare const manifest: PluginManifest<PanPluginConfig>;
20
+
21
+ declare const PanPluginPackage: PluginPackage<PanPlugin, PanPluginConfig>;
22
+
23
+ export { PAN_PLUGIN_ID, type PanCapability, PanPlugin, type PanPluginConfig, PanPluginPackage, manifest };
@@ -0,0 +1,23 @@
1
+ import { BasePluginConfig, BasePlugin, PluginRegistry, PluginManifest, PluginPackage } from '@embedpdf/core';
2
+
3
+ interface PanPluginConfig extends BasePluginConfig {
4
+ }
5
+ interface PanCapability {
6
+ enablePan: () => void;
7
+ disablePan: () => void;
8
+ }
9
+
10
+ declare class PanPlugin extends BasePlugin<PanPluginConfig, PanCapability> {
11
+ static readonly id: "pan";
12
+ private interactionManager;
13
+ constructor(id: string, registry: PluginRegistry);
14
+ initialize(_: PanPluginConfig): Promise<void>;
15
+ protected buildCapability(): PanCapability;
16
+ }
17
+
18
+ declare const PAN_PLUGIN_ID = "pan";
19
+ declare const manifest: PluginManifest<PanPluginConfig>;
20
+
21
+ declare const PanPluginPackage: PluginPackage<PanPlugin, PanPluginConfig>;
22
+
23
+ export { PAN_PLUGIN_ID, type PanCapability, PanPlugin, type PanPluginConfig, PanPluginPackage, manifest };
package/dist/index.js ADDED
@@ -0,0 +1,56 @@
1
+ // src/lib/pan-plugin.ts
2
+ import { BasePlugin } from "@embedpdf/core";
3
+ import {
4
+ InteractionManagerPlugin
5
+ } from "@embedpdf/plugin-interaction-manager";
6
+ var PanPlugin = class extends BasePlugin {
7
+ constructor(id, registry) {
8
+ super(id, registry);
9
+ this.interactionManager = registry.getPlugin(InteractionManagerPlugin.id)?.provides();
10
+ this.interactionManager.registerMode({
11
+ id: "panMode",
12
+ scope: "global",
13
+ exclusive: false,
14
+ cursor: "grab"
15
+ });
16
+ }
17
+ async initialize(_) {
18
+ }
19
+ buildCapability() {
20
+ return {
21
+ enablePan: () => this.interactionManager.activate("panMode"),
22
+ disablePan: () => this.interactionManager.activate("default")
23
+ };
24
+ }
25
+ };
26
+ PanPlugin.id = "pan";
27
+
28
+ // src/lib/manifest.ts
29
+ var PAN_PLUGIN_ID = "pan";
30
+ var manifest = {
31
+ id: PAN_PLUGIN_ID,
32
+ name: "Pan Plugin",
33
+ version: "1.0.0",
34
+ provides: ["pan"],
35
+ requires: ["interaction-manager"],
36
+ optional: [],
37
+ defaultConfig: {
38
+ enabled: true
39
+ }
40
+ };
41
+
42
+ // src/lib/index.ts
43
+ var PanPluginPackage = {
44
+ manifest,
45
+ create: (registry) => new PanPlugin(PAN_PLUGIN_ID, registry),
46
+ reducer: () => {
47
+ },
48
+ initialState: {}
49
+ };
50
+ export {
51
+ PAN_PLUGIN_ID,
52
+ PanPlugin,
53
+ PanPluginPackage,
54
+ manifest
55
+ };
56
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/lib/pan-plugin.ts","../src/lib/manifest.ts","../src/lib/index.ts"],"sourcesContent":["import { BasePlugin, PluginRegistry } from '@embedpdf/core';\nimport {\n InteractionManagerCapability,\n InteractionManagerPlugin,\n} from '@embedpdf/plugin-interaction-manager';\n\nimport { PanCapability, PanPluginConfig } from './types';\n\nexport class PanPlugin extends BasePlugin<PanPluginConfig, PanCapability> {\n static readonly id = 'pan' as const;\n\n private interactionManager: InteractionManagerCapability;\n\n constructor(id: string, registry: PluginRegistry) {\n super(id, registry);\n\n this.interactionManager = registry\n .getPlugin<InteractionManagerPlugin>(InteractionManagerPlugin.id)\n ?.provides()!;\n\n this.interactionManager.registerMode({\n id: 'panMode',\n scope: 'global',\n exclusive: false,\n cursor: 'grab',\n });\n }\n\n async initialize(_: PanPluginConfig): Promise<void> {}\n\n protected buildCapability(): PanCapability {\n return {\n enablePan: () => this.interactionManager.activate('panMode'),\n disablePan: () => this.interactionManager.activate('default'),\n };\n }\n}\n","import { PluginManifest } from '@embedpdf/core';\nimport { PanPluginConfig } from './types';\n\nexport const PAN_PLUGIN_ID = 'pan';\n\nexport const manifest: PluginManifest<PanPluginConfig> = {\n id: PAN_PLUGIN_ID,\n name: 'Pan Plugin',\n version: '1.0.0',\n provides: ['pan'],\n requires: ['interaction-manager'],\n optional: [],\n defaultConfig: {\n enabled: true,\n },\n};\n","import { PluginPackage } from '@embedpdf/core';\n\nimport { PanPlugin } from './pan-plugin';\nimport { manifest, PAN_PLUGIN_ID } from './manifest';\nimport { PanPluginConfig } from './types';\n\nexport const PanPluginPackage: PluginPackage<PanPlugin, PanPluginConfig> = {\n manifest,\n create: (registry) => new PanPlugin(PAN_PLUGIN_ID, registry),\n reducer: () => {},\n initialState: {},\n};\n\nexport * from './pan-plugin';\nexport * from './types';\nexport * from './manifest';\n"],"mappings":";AAAA,SAAS,kBAAkC;AAC3C;AAAA,EAEE;AAAA,OACK;AAIA,IAAM,YAAN,cAAwB,WAA2C;AAAA,EAKxE,YAAY,IAAY,UAA0B;AAChD,UAAM,IAAI,QAAQ;AAElB,SAAK,qBAAqB,SACvB,UAAoC,yBAAyB,EAAE,GAC9D,SAAS;AAEb,SAAK,mBAAmB,aAAa;AAAA,MACnC,IAAI;AAAA,MACJ,OAAO;AAAA,MACP,WAAW;AAAA,MACX,QAAQ;AAAA,IACV,CAAC;AAAA,EACH;AAAA,EAEA,MAAM,WAAW,GAAmC;AAAA,EAAC;AAAA,EAE3C,kBAAiC;AACzC,WAAO;AAAA,MACL,WAAW,MAAM,KAAK,mBAAmB,SAAS,SAAS;AAAA,MAC3D,YAAY,MAAM,KAAK,mBAAmB,SAAS,SAAS;AAAA,IAC9D;AAAA,EACF;AACF;AA5Ba,UACK,KAAK;;;ACNhB,IAAM,gBAAgB;AAEtB,IAAM,WAA4C;AAAA,EACvD,IAAI;AAAA,EACJ,MAAM;AAAA,EACN,SAAS;AAAA,EACT,UAAU,CAAC,KAAK;AAAA,EAChB,UAAU,CAAC,qBAAqB;AAAA,EAChC,UAAU,CAAC;AAAA,EACX,eAAe;AAAA,IACb,SAAS;AAAA,EACX;AACF;;;ACTO,IAAM,mBAA8D;AAAA,EACzE;AAAA,EACA,QAAQ,CAAC,aAAa,IAAI,UAAU,eAAe,QAAQ;AAAA,EAC3D,SAAS,MAAM;AAAA,EAAC;AAAA,EAChB,cAAc,CAAC;AACjB;","names":[]}
@@ -0,0 +1,101 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/preact/index.ts
21
+ var preact_exports = {};
22
+ __export(preact_exports, {
23
+ PanMode: () => PanMode,
24
+ usePan: () => usePan,
25
+ usePanCapability: () => usePanCapability
26
+ });
27
+ module.exports = __toCommonJS(preact_exports);
28
+
29
+ // src/preact/hooks/use-pan.ts
30
+ var import_preact = require("@embedpdf/core/preact");
31
+ var import_plugin_pan = require("@embedpdf/plugin-pan");
32
+ var usePan = () => (0, import_preact.usePlugin)(import_plugin_pan.PanPlugin.id);
33
+ var usePanCapability = () => (0, import_preact.useCapability)(import_plugin_pan.PanPlugin.id);
34
+
35
+ // src/preact/components/pan-mode.tsx
36
+ var import_hooks = require("preact/hooks");
37
+ var import_preact2 = require("@embedpdf/plugin-interaction-manager/preact");
38
+ var import_preact3 = require("@embedpdf/plugin-viewport/preact");
39
+ var import_jsx_runtime = require("preact/jsx-runtime");
40
+ var PanMode = () => {
41
+ const { register } = (0, import_preact2.usePointerHandlers)({ modeId: "panMode" });
42
+ const { setCursor, removeCursor } = (0, import_preact2.useCursor)();
43
+ const { provides: viewport } = (0, import_preact3.useViewportCapability)();
44
+ const dragRef = (0, import_hooks.useRef)(null);
45
+ const handlers = (0, import_hooks.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_hooks.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
+ };
95
+ // Annotate the CommonJS export names for ESM import in node:
96
+ 0 && (module.exports = {
97
+ PanMode,
98
+ usePan,
99
+ usePanCapability
100
+ });
101
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +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 usePan = () => 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,SAAS,UAAM,yBAAqB,4BAAU,EAAE;AACtD,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"]}
@@ -0,0 +1,18 @@
1
+ import * as _embedpdf_plugin_pan from '@embedpdf/plugin-pan';
2
+ import { PanPlugin } from '@embedpdf/plugin-pan';
3
+ import * as preact from 'preact';
4
+
5
+ declare const usePan: () => {
6
+ plugin: PanPlugin | null;
7
+ isLoading: boolean;
8
+ ready: Promise<void>;
9
+ };
10
+ declare const usePanCapability: () => {
11
+ provides: Readonly<_embedpdf_plugin_pan.PanCapability> | null;
12
+ isLoading: boolean;
13
+ ready: Promise<void>;
14
+ };
15
+
16
+ declare const PanMode: () => preact.JSX.Element;
17
+
18
+ export { PanMode, usePan, usePanCapability };
@@ -0,0 +1,18 @@
1
+ import * as _embedpdf_plugin_pan from '@embedpdf/plugin-pan';
2
+ import { PanPlugin } from '@embedpdf/plugin-pan';
3
+ import * as preact from 'preact';
4
+
5
+ declare const usePan: () => {
6
+ plugin: PanPlugin | null;
7
+ isLoading: boolean;
8
+ ready: Promise<void>;
9
+ };
10
+ declare const usePanCapability: () => {
11
+ provides: Readonly<_embedpdf_plugin_pan.PanCapability> | null;
12
+ isLoading: boolean;
13
+ ready: Promise<void>;
14
+ };
15
+
16
+ declare const PanMode: () => preact.JSX.Element;
17
+
18
+ export { PanMode, usePan, usePanCapability };
@@ -0,0 +1,72 @@
1
+ // src/preact/hooks/use-pan.ts
2
+ import { useCapability, usePlugin } from "@embedpdf/core/preact";
3
+ import { PanPlugin } from "@embedpdf/plugin-pan";
4
+ var usePan = () => usePlugin(PanPlugin.id);
5
+ var usePanCapability = () => useCapability(PanPlugin.id);
6
+
7
+ // src/preact/components/pan-mode.tsx
8
+ import { useEffect, useMemo, useRef } from "preact/hooks";
9
+ import { useCursor, usePointerHandlers } from "@embedpdf/plugin-interaction-manager/preact";
10
+ import { useViewportCapability } from "@embedpdf/plugin-viewport/preact";
11
+ import { Fragment, jsx } from "preact/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
+ };
67
+ export {
68
+ PanMode,
69
+ usePan,
70
+ usePanCapability
71
+ };
72
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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 usePan = () => 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,SAAS,MAAM,UAAqB,UAAU,EAAE;AACtD,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":[]}
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/react/index.ts
21
+ var react_exports = {};
22
+ __export(react_exports, {
23
+ usePan: () => usePan,
24
+ usePanCapability: () => usePanCapability
25
+ });
26
+ module.exports = __toCommonJS(react_exports);
27
+
28
+ // src/react/hooks/use-pan.ts
29
+ var import_react = require("@embedpdf/core/react");
30
+ var import_plugin_pan = require("@embedpdf/plugin-pan");
31
+ var usePan = () => (0, import_react.usePlugin)(import_plugin_pan.PanPlugin.id);
32
+ var usePanCapability = () => (0, import_react.useCapability)(import_plugin_pan.PanPlugin.id);
33
+ // Annotate the CommonJS export names for ESM import in node:
34
+ 0 && (module.exports = {
35
+ usePan,
36
+ usePanCapability
37
+ });
38
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +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 usePan = () => usePlugin<PanPlugin>(PanPlugin.id);\nexport const usePanCapability = () => useCapability<PanPlugin>(PanPlugin.id);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAAyC;AACzC,wBAA0B;AAEnB,IAAM,SAAS,UAAM,wBAAqB,4BAAU,EAAE;AACtD,IAAM,mBAAmB,UAAM,4BAAyB,4BAAU,EAAE;","names":[]}
@@ -0,0 +1,15 @@
1
+ import * as _embedpdf_plugin_pan from '@embedpdf/plugin-pan';
2
+ import { PanPlugin } from '@embedpdf/plugin-pan';
3
+
4
+ declare const usePan: () => {
5
+ plugin: PanPlugin | null;
6
+ isLoading: boolean;
7
+ ready: Promise<void>;
8
+ };
9
+ declare const usePanCapability: () => {
10
+ provides: Readonly<_embedpdf_plugin_pan.PanCapability> | null;
11
+ isLoading: boolean;
12
+ ready: Promise<void>;
13
+ };
14
+
15
+ export { usePan, usePanCapability };
@@ -0,0 +1,15 @@
1
+ import * as _embedpdf_plugin_pan from '@embedpdf/plugin-pan';
2
+ import { PanPlugin } from '@embedpdf/plugin-pan';
3
+
4
+ declare const usePan: () => {
5
+ plugin: PanPlugin | null;
6
+ isLoading: boolean;
7
+ ready: Promise<void>;
8
+ };
9
+ declare const usePanCapability: () => {
10
+ provides: Readonly<_embedpdf_plugin_pan.PanCapability> | null;
11
+ isLoading: boolean;
12
+ ready: Promise<void>;
13
+ };
14
+
15
+ export { usePan, usePanCapability };
@@ -0,0 +1,10 @@
1
+ // src/react/hooks/use-pan.ts
2
+ import { useCapability, usePlugin } from "@embedpdf/core/react";
3
+ import { PanPlugin } from "@embedpdf/plugin-pan";
4
+ var usePan = () => usePlugin(PanPlugin.id);
5
+ var usePanCapability = () => useCapability(PanPlugin.id);
6
+ export {
7
+ usePan,
8
+ usePanCapability
9
+ };
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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 usePan = () => usePlugin<PanPlugin>(PanPlugin.id);\nexport const usePanCapability = () => useCapability<PanPlugin>(PanPlugin.id);\n"],"mappings":";AAAA,SAAS,eAAe,iBAAiB;AACzC,SAAS,iBAAiB;AAEnB,IAAM,SAAS,MAAM,UAAqB,UAAU,EAAE;AACtD,IAAM,mBAAmB,MAAM,cAAyB,UAAU,EAAE;","names":[]}
package/package.json ADDED
@@ -0,0 +1,66 @@
1
+ {
2
+ "name": "@embedpdf/plugin-pan",
3
+ "version": "1.0.0",
4
+ "type": "module",
5
+ "main": "./dist/index.cjs",
6
+ "module": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js",
12
+ "require": "./dist/index.cjs"
13
+ },
14
+ "./preact": {
15
+ "types": "./dist/preact/index.d.ts",
16
+ "import": "./dist/preact/index.js",
17
+ "require": "./dist/preact/index.cjs"
18
+ },
19
+ "./react": {
20
+ "types": "./dist/react/index.d.ts",
21
+ "import": "./dist/react/index.js",
22
+ "require": "./dist/react/index.cjs"
23
+ }
24
+ },
25
+ "dependencies": {},
26
+ "devDependencies": {
27
+ "@types/react": "^18.2.0",
28
+ "tsup": "^8.0.0",
29
+ "typescript": "^5.0.0",
30
+ "@embedpdf/models": "1.0.0",
31
+ "@embedpdf/plugin-interaction-manager": "1.0.0",
32
+ "@embedpdf/plugin-viewport": "1.0.0"
33
+ },
34
+ "peerDependencies": {
35
+ "react": ">=16.8.0",
36
+ "react-dom": ">=16.8.0",
37
+ "preact": "^10.26.4",
38
+ "@embedpdf/plugin-interaction-manager": "1.0.0",
39
+ "@embedpdf/core": "1.0.0",
40
+ "@embedpdf/plugin-viewport": "1.0.0"
41
+ },
42
+ "files": [
43
+ "dist",
44
+ "README.md"
45
+ ],
46
+ "repository": {
47
+ "type": "git",
48
+ "url": "https://github.com/embedpdf/embed-pdf-viewer",
49
+ "directory": "packages/plugin-pan"
50
+ },
51
+ "homepage": "https://www.embedpdf.com/docs",
52
+ "bugs": {
53
+ "url": "https://github.com/embedpdf/embed-pdf-viewer/issues"
54
+ },
55
+ "publishConfig": {
56
+ "access": "public"
57
+ },
58
+ "scripts": {
59
+ "build": "PROJECT_CWD=$(pwd) pnpm -w p:build",
60
+ "build:watch": "PROJECT_CWD=$(pwd) pnpm -w p:build:watch",
61
+ "clean": "PROJECT_CWD=$(pwd) pnpm -w p:clean",
62
+ "lint": "PROJECT_CWD=$(pwd) pnpm -w p:lint",
63
+ "lint:fix": "PROJECT_CWD=$(pwd) pnpm -w p:lint:fix",
64
+ "typecheck": "PROJECT_CWD=$(pwd) pnpm -w p:typecheck"
65
+ }
66
+ }