@embedpdf/plugin-zoom 2.0.0-next.2 → 2.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.
Files changed (64) hide show
  1. package/dist/preact/adapter.d.ts +1 -1
  2. package/dist/preact/index.cjs +1 -1
  3. package/dist/preact/index.cjs.map +1 -1
  4. package/dist/preact/index.js +217 -71
  5. package/dist/preact/index.js.map +1 -1
  6. package/dist/preact/viewport.d.ts +1 -0
  7. package/dist/react/adapter.d.ts +1 -1
  8. package/dist/react/index.cjs +1 -1
  9. package/dist/react/index.cjs.map +1 -1
  10. package/dist/react/index.js +217 -71
  11. package/dist/react/index.js.map +1 -1
  12. package/dist/react/viewport.d.ts +1 -0
  13. package/dist/shared/components/index.d.ts +1 -1
  14. package/dist/shared/components/zoom-gesture-wrapper.d.ts +12 -0
  15. package/dist/shared/hooks/index.d.ts +1 -1
  16. package/dist/shared/hooks/use-pinch-zoom.d.ts +3 -1
  17. package/dist/shared/hooks/use-zoom-gesture.d.ts +5 -0
  18. package/dist/shared/utils/pinch-zoom-logic.d.ts +11 -2
  19. package/dist/shared/utils/zoom-gesture-logic.d.ts +18 -0
  20. package/dist/shared-preact/components/index.d.ts +1 -1
  21. package/dist/shared-preact/components/zoom-gesture-wrapper.d.ts +12 -0
  22. package/dist/shared-preact/hooks/index.d.ts +1 -1
  23. package/dist/shared-preact/hooks/use-pinch-zoom.d.ts +3 -1
  24. package/dist/shared-preact/hooks/use-zoom-gesture.d.ts +5 -0
  25. package/dist/shared-preact/utils/pinch-zoom-logic.d.ts +11 -2
  26. package/dist/shared-preact/utils/zoom-gesture-logic.d.ts +18 -0
  27. package/dist/shared-react/components/index.d.ts +1 -1
  28. package/dist/shared-react/components/zoom-gesture-wrapper.d.ts +12 -0
  29. package/dist/shared-react/hooks/index.d.ts +1 -1
  30. package/dist/shared-react/hooks/use-pinch-zoom.d.ts +3 -1
  31. package/dist/shared-react/hooks/use-zoom-gesture.d.ts +5 -0
  32. package/dist/shared-react/utils/pinch-zoom-logic.d.ts +11 -2
  33. package/dist/shared-react/utils/zoom-gesture-logic.d.ts +18 -0
  34. package/dist/shared-svelte/utils/zoom-gesture-logic.d.ts +18 -0
  35. package/dist/shared-vue/utils/zoom-gesture-logic.d.ts +18 -0
  36. package/dist/svelte/components/ZoomGestureWrapper.svelte.d.ts +14 -0
  37. package/dist/svelte/components/index.d.ts +1 -1
  38. package/dist/svelte/hooks/index.d.ts +1 -1
  39. package/dist/svelte/hooks/use-pinch-zoom.svelte.d.ts +11 -2
  40. package/dist/svelte/hooks/use-zoom-gesture.svelte.d.ts +16 -0
  41. package/dist/svelte/index.cjs +1 -1
  42. package/dist/svelte/index.cjs.map +1 -1
  43. package/dist/svelte/index.js +214 -71
  44. package/dist/svelte/index.js.map +1 -1
  45. package/dist/vue/components/index.d.ts +1 -1
  46. package/dist/vue/components/{pinch-wrapper.vue.d.ts → zoom-gesture-wrapper.vue.d.ts} +8 -1
  47. package/dist/vue/hooks/index.d.ts +1 -1
  48. package/dist/vue/hooks/use-zoom-gesture.d.ts +17 -0
  49. package/dist/vue/index.cjs +1 -1
  50. package/dist/vue/index.cjs.map +1 -1
  51. package/dist/vue/index.js +211 -72
  52. package/dist/vue/index.js.map +1 -1
  53. package/package.json +10 -12
  54. package/dist/hammer-DhVzwxwy.cjs +0 -7
  55. package/dist/hammer-DhVzwxwy.cjs.map +0 -1
  56. package/dist/hammer-e1aXHboh.js +0 -1810
  57. package/dist/hammer-e1aXHboh.js.map +0 -1
  58. package/dist/shared/components/pinch-wrapper.d.ts +0 -8
  59. package/dist/shared-preact/components/pinch-wrapper.d.ts +0 -8
  60. package/dist/shared-react/components/pinch-wrapper.d.ts +0 -8
  61. package/dist/shared-svelte/utils/pinch-zoom-logic.d.ts +0 -9
  62. package/dist/shared-vue/utils/pinch-zoom-logic.d.ts +0 -9
  63. package/dist/svelte/components/PinchWrapper.svelte.d.ts +0 -10
  64. package/dist/vue/hooks/use-pinch-zoom.d.ts +0 -8
@@ -2,6 +2,7 @@ import * as $ from "svelte/internal/client";
2
2
  import { useCapability, usePlugin, useDocumentState } from "@embedpdf/core/svelte";
3
3
  import { ZoomPlugin, initialDocumentState } from "@embedpdf/plugin-zoom";
4
4
  export * from "@embedpdf/plugin-zoom";
5
+ import { getContext } from "svelte";
5
6
  import "svelte/internal/disclose-version";
6
7
  const useZoomCapability = () => useCapability(ZoomPlugin.id);
7
8
  const useZoomPlugin = () => usePlugin(ZoomPlugin.id);
@@ -32,110 +33,249 @@ const useZoom = (getDocumentId) => {
32
33
  }
33
34
  };
34
35
  };
35
- function setupPinchZoom({
36
+ function getTouchDistance(touches) {
37
+ const [t1, t2] = [touches[0], touches[1]];
38
+ const dx = t2.clientX - t1.clientX;
39
+ const dy = t2.clientY - t1.clientY;
40
+ return Math.hypot(dx, dy);
41
+ }
42
+ function getTouchCenter(touches) {
43
+ const [t1, t2] = [touches[0], touches[1]];
44
+ return {
45
+ x: (t1.clientX + t2.clientX) / 2,
46
+ y: (t1.clientY + t2.clientY) / 2
47
+ };
48
+ }
49
+ function setupZoomGestures({
36
50
  element,
51
+ container,
37
52
  documentId,
38
- viewportProvides,
39
- zoomProvides
53
+ zoomProvides,
54
+ viewportGap = 0,
55
+ options = {}
40
56
  }) {
57
+ const { enablePinch = true, enableWheel = true } = options;
41
58
  if (typeof window === "undefined") {
42
59
  return () => {
43
60
  };
44
61
  }
45
- let hammer;
46
- let initialZoom = 0;
47
- let lastCenter = { x: 0, y: 0 };
48
- const viewportScope = viewportProvides.forDocument(documentId);
49
62
  const zoomScope = zoomProvides.forDocument(documentId);
50
63
  const getState = () => zoomScope.getState();
64
+ let initialZoom = 0;
65
+ let currentScale = 1;
66
+ let isPinching = false;
67
+ let initialDistance = 0;
68
+ let wheelZoomTimeout = null;
69
+ let accumulatedWheelScale = 1;
70
+ let initialElementWidth = 0;
71
+ let initialElementHeight = 0;
72
+ let initialElementLeft = 0;
73
+ let initialElementTop = 0;
74
+ let containerRectWidth = 0;
75
+ let containerRectHeight = 0;
76
+ let layoutWidth = 0;
77
+ let layoutCenterX = 0;
78
+ let pointerLocalY = 0;
79
+ let pointerContainerX = 0;
80
+ let pointerContainerY = 0;
81
+ let currentGap = 0;
82
+ let pivotLocalX = 0;
83
+ const clamp = (val, min, max) => Math.min(Math.max(val, min), max);
84
+ const updateMargin = () => {
85
+ const availableWidth = container.clientWidth - 2 * viewportGap;
86
+ const elementWidth = element.offsetWidth;
87
+ const newMargin = elementWidth < availableWidth ? (availableWidth - elementWidth) / 2 : 0;
88
+ element.style.marginLeft = `${newMargin}px`;
89
+ };
90
+ const calculateTransform = (scale) => {
91
+ const finalWidth = initialElementWidth * scale;
92
+ const finalHeight = initialElementHeight * scale;
93
+ let ty = pointerLocalY * (1 - scale);
94
+ const targetX = layoutCenterX - finalWidth / 2;
95
+ const txCenter = targetX - initialElementLeft;
96
+ const txMouse = pointerContainerX - pivotLocalX * scale - initialElementLeft;
97
+ const overflow = Math.max(0, finalWidth - layoutWidth);
98
+ const blendRange = layoutWidth * 0.3;
99
+ const blend = Math.min(1, overflow / blendRange);
100
+ let tx = txCenter + (txMouse - txCenter) * blend;
101
+ const safeHeight = containerRectHeight - currentGap * 2;
102
+ if (finalHeight > safeHeight) {
103
+ const currentTop = initialElementTop + ty;
104
+ const maxTop = currentGap;
105
+ const minTop = containerRectHeight - currentGap - finalHeight;
106
+ const constrainedTop = clamp(currentTop, minTop, maxTop);
107
+ ty = constrainedTop - initialElementTop;
108
+ }
109
+ const safeWidth = containerRectWidth - currentGap * 2;
110
+ if (finalWidth > safeWidth) {
111
+ const currentLeft = initialElementLeft + tx;
112
+ const maxLeft = currentGap;
113
+ const minLeft = containerRectWidth - currentGap - finalWidth;
114
+ const constrainedLeft = clamp(currentLeft, minLeft, maxLeft);
115
+ tx = constrainedLeft - initialElementLeft;
116
+ }
117
+ return { tx, ty, blend, finalWidth };
118
+ };
51
119
  const updateTransform = (scale) => {
52
- element.style.transform = `scale(${scale})`;
120
+ currentScale = scale;
121
+ const { tx, ty } = calculateTransform(scale);
122
+ element.style.transformOrigin = "0 0";
123
+ element.style.transform = `translate(${tx}px, ${ty}px) scale(${scale})`;
53
124
  };
54
125
  const resetTransform = () => {
55
126
  element.style.transform = "none";
56
127
  element.style.transformOrigin = "0 0";
128
+ currentScale = 1;
57
129
  };
58
- const pinchStart = (e) => {
59
- var _a;
60
- initialZoom = getState().currentZoomLevel;
61
- const contRect = viewportScope.getBoundingRect();
62
- lastCenter = {
63
- x: e.center.x - contRect.origin.x,
64
- y: e.center.y - contRect.origin.y
65
- };
66
- const innerRect = element.getBoundingClientRect();
67
- element.style.transformOrigin = `${e.center.x - innerRect.left}px ${e.center.y - innerRect.top}px`;
68
- if ((_a = e.srcEvent) == null ? void 0 : _a.cancelable) {
69
- e.srcEvent.preventDefault();
70
- e.srcEvent.stopPropagation();
130
+ const commitZoom = () => {
131
+ const { tx, finalWidth } = calculateTransform(currentScale);
132
+ const delta = (currentScale - 1) * initialZoom;
133
+ let anchorX;
134
+ let anchorY = pointerContainerY;
135
+ if (finalWidth <= layoutWidth) {
136
+ anchorX = layoutCenterX;
137
+ } else {
138
+ const scaleDiff = 1 - currentScale;
139
+ anchorX = Math.abs(scaleDiff) > 1e-3 ? initialElementLeft + tx / scaleDiff : pointerContainerX;
71
140
  }
141
+ zoomScope.requestZoomBy(delta, { vx: anchorX, vy: anchorY });
142
+ resetTransform();
143
+ initialZoom = 0;
72
144
  };
73
- const pinchMove = (e) => {
74
- var _a;
75
- updateTransform(e.scale);
76
- if ((_a = e.srcEvent) == null ? void 0 : _a.cancelable) {
77
- e.srcEvent.preventDefault();
78
- e.srcEvent.stopPropagation();
145
+ const initializeGestureState = (clientX, clientY) => {
146
+ const containerRect = container.getBoundingClientRect();
147
+ const innerRect = element.getBoundingClientRect();
148
+ currentGap = viewportGap;
149
+ initialElementWidth = innerRect.width;
150
+ initialElementHeight = innerRect.height;
151
+ initialElementLeft = innerRect.left - containerRect.left;
152
+ initialElementTop = innerRect.top - containerRect.top;
153
+ containerRectWidth = containerRect.width;
154
+ containerRectHeight = containerRect.height;
155
+ layoutWidth = container.clientWidth;
156
+ layoutCenterX = container.clientLeft + layoutWidth / 2;
157
+ const rawPointerLocalX = clientX - innerRect.left;
158
+ pointerLocalY = clientY - innerRect.top;
159
+ pointerContainerX = clientX - containerRect.left;
160
+ pointerContainerY = clientY - containerRect.top;
161
+ if (initialElementWidth < layoutWidth) {
162
+ pivotLocalX = pointerContainerX * initialElementWidth / layoutWidth;
163
+ } else {
164
+ pivotLocalX = rawPointerLocalX;
79
165
  }
80
166
  };
81
- const pinchEnd = (e) => {
82
- const delta = (e.scale - 1) * initialZoom;
83
- zoomScope.requestZoomBy(delta, { vx: lastCenter.x, vy: lastCenter.y });
84
- resetTransform();
85
- initialZoom = 0;
167
+ const handleTouchStart = (e) => {
168
+ if (e.touches.length !== 2) return;
169
+ isPinching = true;
170
+ initialZoom = getState().currentZoomLevel;
171
+ initialDistance = getTouchDistance(e.touches);
172
+ const center = getTouchCenter(e.touches);
173
+ initializeGestureState(center.x, center.y);
174
+ e.preventDefault();
86
175
  };
87
- const setupHammer = async () => {
88
- try {
89
- const Hammer = (await import("../hammer-e1aXHboh.js").then((n) => n.h)).default;
90
- const inputClass = (() => {
91
- const MOBILE_REGEX = /mobile|tablet|ip(ad|hone|od)|android/i;
92
- const SUPPORT_TOUCH = "ontouchstart" in window || navigator.maxTouchPoints > 0;
93
- const SUPPORT_ONLY_TOUCH = SUPPORT_TOUCH && MOBILE_REGEX.test(navigator.userAgent);
94
- if (SUPPORT_ONLY_TOUCH) return Hammer.TouchInput;
95
- if (!SUPPORT_TOUCH) return Hammer.MouseInput;
96
- return Hammer.TouchMouseInput;
97
- })();
98
- hammer = new Hammer(element, {
99
- touchAction: "pan-x pan-y",
100
- inputClass
101
- });
102
- hammer.get("pinch").set({ enable: true, pointers: 2, threshold: 0.1 });
103
- hammer.on("pinchstart", pinchStart);
104
- hammer.on("pinchmove", pinchMove);
105
- hammer.on("pinchend", pinchEnd);
106
- } catch (error) {
107
- console.warn("Failed to load HammerJS:", error);
176
+ const handleTouchMove = (e) => {
177
+ if (!isPinching || e.touches.length !== 2) return;
178
+ const currentDistance = getTouchDistance(e.touches);
179
+ const scale = currentDistance / initialDistance;
180
+ updateTransform(scale);
181
+ e.preventDefault();
182
+ };
183
+ const handleTouchEnd = (e) => {
184
+ if (!isPinching) return;
185
+ if (e.touches.length >= 2) return;
186
+ isPinching = false;
187
+ commitZoom();
188
+ };
189
+ const handleWheel = (e) => {
190
+ if (!e.ctrlKey && !e.metaKey) return;
191
+ e.preventDefault();
192
+ if (wheelZoomTimeout === null) {
193
+ initialZoom = getState().currentZoomLevel;
194
+ accumulatedWheelScale = 1;
195
+ initializeGestureState(e.clientX, e.clientY);
196
+ } else {
197
+ clearTimeout(wheelZoomTimeout);
108
198
  }
199
+ const zoomFactor = 1 - e.deltaY * 0.01;
200
+ accumulatedWheelScale *= zoomFactor;
201
+ accumulatedWheelScale = Math.max(0.1, Math.min(10, accumulatedWheelScale));
202
+ updateTransform(accumulatedWheelScale);
203
+ wheelZoomTimeout = setTimeout(() => {
204
+ wheelZoomTimeout = null;
205
+ commitZoom();
206
+ accumulatedWheelScale = 1;
207
+ }, 150);
109
208
  };
110
- setupHammer();
209
+ const unsubZoom = zoomScope.onStateChange(() => updateMargin());
210
+ const resizeObserver = new ResizeObserver(() => updateMargin());
211
+ resizeObserver.observe(element);
212
+ resizeObserver.observe(container);
213
+ updateMargin();
214
+ if (enablePinch) {
215
+ container.addEventListener("touchstart", handleTouchStart, { passive: false });
216
+ container.addEventListener("touchmove", handleTouchMove, { passive: false });
217
+ container.addEventListener("touchend", handleTouchEnd);
218
+ container.addEventListener("touchcancel", handleTouchEnd);
219
+ }
220
+ if (enableWheel) {
221
+ container.addEventListener("wheel", handleWheel, { passive: false });
222
+ }
111
223
  return () => {
112
- hammer == null ? void 0 : hammer.destroy();
224
+ if (enablePinch) {
225
+ container.removeEventListener("touchstart", handleTouchStart);
226
+ container.removeEventListener("touchmove", handleTouchMove);
227
+ container.removeEventListener("touchend", handleTouchEnd);
228
+ container.removeEventListener("touchcancel", handleTouchEnd);
229
+ }
230
+ if (enableWheel) {
231
+ container.removeEventListener("wheel", handleWheel);
232
+ }
233
+ if (wheelZoomTimeout) {
234
+ clearTimeout(wheelZoomTimeout);
235
+ }
236
+ unsubZoom();
237
+ resizeObserver.disconnect();
113
238
  resetTransform();
239
+ element.style.marginLeft = "";
114
240
  };
115
241
  }
116
- function usePinch(getDocumentId) {
242
+ function useZoomGesture(getDocumentId, options = {}) {
117
243
  const viewportCapability = useCapability("viewport");
118
244
  const zoomCapability = useZoomCapability();
245
+ const viewportElementCtx = getContext("viewport-element");
119
246
  let elementRef = $.state(null);
120
247
  let cleanup;
121
248
  const documentId = $.derived(getDocumentId);
249
+ const enablePinch = $.derived(() => {
250
+ var _a;
251
+ return ((_a = options.enablePinch) == null ? void 0 : _a.call(options)) ?? true;
252
+ });
253
+ const enableWheel = $.derived(() => {
254
+ var _a;
255
+ return ((_a = options.enableWheel) == null ? void 0 : _a.call(options)) ?? true;
256
+ });
122
257
  $.user_effect(() => {
123
258
  const element = $.get(elementRef);
259
+ const container = viewportElementCtx == null ? void 0 : viewportElementCtx.current;
124
260
  const viewport = viewportCapability.provides;
125
261
  const zoom = zoomCapability.provides;
126
262
  const docId = $.get(documentId);
263
+ const pinchEnabled = $.get(enablePinch);
264
+ const wheelEnabled = $.get(enableWheel);
127
265
  if (cleanup) {
128
266
  cleanup();
129
267
  cleanup = void 0;
130
268
  }
131
- if (!element || !viewport || !zoom || !docId) {
269
+ if (!element || !container || !zoom || !docId) {
132
270
  return;
133
271
  }
134
- cleanup = setupPinchZoom({
272
+ cleanup = setupZoomGestures({
135
273
  element,
274
+ container,
136
275
  documentId: docId,
137
- viewportProvides: viewport,
138
- zoomProvides: zoom
276
+ zoomProvides: zoom,
277
+ viewportGap: (viewport == null ? void 0 : viewport.getViewportGap()) || 0,
278
+ options: { enablePinch: pinchEnabled, enableWheel: wheelEnabled }
139
279
  });
140
280
  return () => {
141
281
  if (cleanup) {
@@ -210,42 +350,45 @@ function MarqueeZoom($$anchor, $$props) {
210
350
  $.pop();
211
351
  }
212
352
  var root = $.from_html(`<div><!></div>`);
213
- function PinchWrapper($$anchor, $$props) {
353
+ function ZoomGestureWrapper($$anchor, $$props) {
214
354
  $.push($$props, true);
215
- let restProps = $.rest_props($$props, [
355
+ let enablePinch = $.prop($$props, "enablePinch", 3, true), enableWheel = $.prop($$props, "enableWheel", 3, true), restProps = $.rest_props($$props, [
216
356
  "$$slots",
217
357
  "$$events",
218
358
  "$$legacy",
219
359
  "documentId",
220
360
  "children",
221
- "class"
361
+ "class",
362
+ "enablePinch",
363
+ "enableWheel"
222
364
  ]);
223
- const pinch = usePinch(() => $$props.documentId);
365
+ const zoomGesture = useZoomGesture(() => $$props.documentId, {
366
+ enablePinch: () => enablePinch(),
367
+ enableWheel: () => enableWheel()
368
+ });
224
369
  var div = root();
225
370
  $.attribute_effect(div, () => ({
226
371
  ...restProps,
227
372
  class: $$props.class,
228
373
  [$.STYLE]: {
229
- display: "block",
230
- width: "fit-content",
374
+ display: "inline-block",
231
375
  overflow: "visible",
232
- "box-sizing": "border-box",
233
- margin: "0px auto"
376
+ "box-sizing": "border-box"
234
377
  }
235
378
  }));
236
379
  var node = $.child(div);
237
380
  $.snippet(node, () => $$props.children);
238
381
  $.reset(div);
239
- $.bind_this(div, ($$value) => pinch.elementRef = $$value, () => pinch == null ? void 0 : pinch.elementRef);
382
+ $.bind_this(div, ($$value) => zoomGesture.elementRef = $$value, () => zoomGesture == null ? void 0 : zoomGesture.elementRef);
240
383
  $.append($$anchor, div);
241
384
  $.pop();
242
385
  }
243
386
  export {
244
387
  MarqueeZoom,
245
- PinchWrapper,
246
- usePinch,
388
+ ZoomGestureWrapper,
247
389
  useZoom,
248
390
  useZoomCapability,
391
+ useZoomGesture,
249
392
  useZoomPlugin
250
393
  };
251
394
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/svelte/hooks/use-zoom.svelte.ts","../../src/shared/utils/pinch-zoom-logic.ts","../../src/svelte/hooks/use-pinch-zoom.svelte.ts","../../src/svelte/components/MarqueeZoom.svelte","../../src/svelte/components/PinchWrapper.svelte"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/svelte';\nimport {\n initialDocumentState,\n ZoomDocumentState,\n ZoomPlugin,\n ZoomScope,\n} from '@embedpdf/plugin-zoom';\n\nexport const useZoomCapability = () => useCapability<ZoomPlugin>(ZoomPlugin.id);\nexport const useZoomPlugin = () => usePlugin<ZoomPlugin>(ZoomPlugin.id);\n\n// Define the return type explicitly to maintain type safety\ninterface UseZoomReturn {\n provides: ZoomScope | null;\n state: ZoomDocumentState;\n}\n\n/**\n * Hook for zoom state for a specific document\n * @param getDocumentId Function that returns the document ID\n */\nexport const useZoom = (getDocumentId: () => string | null): UseZoomReturn => {\n const capability = useZoomCapability();\n\n let state = $state<ZoomDocumentState>(initialDocumentState);\n\n // Reactive documentId\n const documentId = $derived(getDocumentId());\n\n // Scoped capability for current docId\n const scopedProvides = $derived(\n capability.provides && documentId ? capability.provides.forDocument(documentId) : null,\n );\n\n $effect(() => {\n const provides = capability.provides;\n const docId = documentId;\n\n if (!provides || !docId) {\n state = initialDocumentState;\n return;\n }\n\n const scope = provides.forDocument(docId);\n\n // Get initial state\n state = scope.getState();\n\n // Subscribe to state changes for this document\n return scope.onStateChange((newState) => {\n state = newState;\n });\n });\n\n return {\n get provides() {\n return scopedProvides;\n },\n get state() {\n return state;\n },\n };\n};\n","import type { ViewportCapability } from '@embedpdf/plugin-viewport';\nimport type { ZoomCapability } from '@embedpdf/plugin-zoom';\n\nexport interface PinchZoomDeps {\n element: HTMLDivElement;\n documentId: string;\n viewportProvides: ViewportCapability;\n zoomProvides: ZoomCapability;\n}\n\nexport function setupPinchZoom({\n element,\n documentId,\n viewportProvides,\n zoomProvides,\n}: PinchZoomDeps) {\n if (typeof window === 'undefined') {\n return () => {};\n }\n\n let hammer: any | undefined;\n let initialZoom = 0;\n let lastCenter = { x: 0, y: 0 };\n\n const viewportScope = viewportProvides.forDocument(documentId);\n const zoomScope = zoomProvides.forDocument(documentId);\n\n const getState = () => zoomScope.getState();\n\n const updateTransform = (scale: number) => {\n element.style.transform = `scale(${scale})`;\n };\n\n const resetTransform = () => {\n element.style.transform = 'none';\n element.style.transformOrigin = '0 0';\n };\n\n const pinchStart = (e: HammerInput) => {\n initialZoom = getState().currentZoomLevel;\n\n const contRect = viewportScope.getBoundingRect();\n\n lastCenter = {\n x: e.center.x - contRect.origin.x,\n y: e.center.y - contRect.origin.y,\n };\n\n const innerRect = element.getBoundingClientRect();\n element.style.transformOrigin = `${e.center.x - innerRect.left}px ${e.center.y - innerRect.top}px`;\n\n if (e.srcEvent?.cancelable) {\n e.srcEvent.preventDefault();\n e.srcEvent.stopPropagation();\n }\n };\n\n const pinchMove = (e: HammerInput) => {\n updateTransform(e.scale);\n if (e.srcEvent?.cancelable) {\n e.srcEvent.preventDefault();\n e.srcEvent.stopPropagation();\n }\n };\n\n const pinchEnd = (e: HammerInput) => {\n const delta = (e.scale - 1) * initialZoom;\n zoomScope.requestZoomBy(delta, { vx: lastCenter.x, vy: lastCenter.y });\n\n resetTransform();\n initialZoom = 0;\n };\n\n const setupHammer = async () => {\n try {\n const Hammer = (await import('hammerjs')).default;\n\n const inputClass = (() => {\n const MOBILE_REGEX = /mobile|tablet|ip(ad|hone|od)|android/i;\n const SUPPORT_TOUCH = 'ontouchstart' in window || navigator.maxTouchPoints > 0;\n const SUPPORT_ONLY_TOUCH = SUPPORT_TOUCH && MOBILE_REGEX.test(navigator.userAgent);\n if (SUPPORT_ONLY_TOUCH) return Hammer.TouchInput;\n if (!SUPPORT_TOUCH) return Hammer.MouseInput;\n return Hammer.TouchMouseInput;\n })();\n\n hammer = new Hammer(element, {\n touchAction: 'pan-x pan-y',\n inputClass,\n });\n\n hammer.get('pinch').set({ enable: true, pointers: 2, threshold: 0.1 });\n\n hammer.on('pinchstart', pinchStart);\n hammer.on('pinchmove', pinchMove);\n hammer.on('pinchend', pinchEnd);\n } catch (error) {\n console.warn('Failed to load HammerJS:', error);\n }\n };\n\n setupHammer();\n\n return () => {\n hammer?.destroy();\n resetTransform();\n };\n}\n","import { useCapability } from '@embedpdf/core/svelte';\nimport type { ViewportPlugin } from '@embedpdf/plugin-viewport';\nimport { setupPinchZoom } from '../../shared/utils/pinch-zoom-logic';\nimport { useZoomCapability } from './use-zoom.svelte';\n\n/**\n * Hook for setting up pinch-to-zoom functionality on an element\n * @param getDocumentId Function that returns the document ID\n */\nexport function usePinch(getDocumentId: () => string | null) {\n const viewportCapability = useCapability<ViewportPlugin>('viewport');\n const zoomCapability = useZoomCapability();\n\n let elementRef = $state<HTMLDivElement | null>(null);\n let cleanup: (() => void) | undefined;\n\n // Reactive documentId\n const documentId = $derived(getDocumentId());\n\n $effect(() => {\n const element = elementRef;\n const viewport = viewportCapability.provides;\n const zoom = zoomCapability.provides;\n const docId = documentId;\n\n // Clean up previous setup\n if (cleanup) {\n cleanup();\n cleanup = undefined;\n }\n\n // Setup new pinch zoom if all dependencies are available\n if (!element || !viewport || !zoom || !docId) {\n return;\n }\n\n cleanup = setupPinchZoom({\n element,\n documentId: docId,\n viewportProvides: viewport,\n zoomProvides: zoom,\n });\n\n return () => {\n if (cleanup) {\n cleanup();\n cleanup = undefined;\n }\n };\n });\n\n return {\n get elementRef() {\n return elementRef;\n },\n set elementRef(value: HTMLDivElement | null) {\n elementRef = value;\n },\n };\n}\n","<script lang=\"ts\">\n import type { Rect } from '@embedpdf/models';\n import { useDocumentState } from '@embedpdf/core/svelte';\n import { useZoomCapability } from '../hooks/use-zoom.svelte';\n\n interface MarqueeZoomProps {\n /** The ID of the document */\n documentId: string;\n /** Index of the page this layer lives on */\n pageIndex: number;\n /** Scale of the page */\n scale?: number;\n /** Optional CSS class applied to the marquee rectangle */\n class?: string;\n /** Stroke / fill colours (defaults below) */\n stroke?: string;\n fill?: string;\n }\n\n let {\n documentId,\n pageIndex,\n scale: scaleOverride,\n class: propsClass,\n stroke = 'rgba(33,150,243,0.8)',\n fill = 'rgba(33,150,243,0.15)',\n }: MarqueeZoomProps = $props();\n\n const zoomCapability = useZoomCapability();\n const documentState = useDocumentState(() => documentId);\n\n let rect = $state<Rect | null>(null);\n\n const actualScale = $derived(\n scaleOverride !== undefined ? scaleOverride : (documentState.current?.scale ?? 1),\n );\n\n $effect(() => {\n rect = null;\n\n if (!zoomCapability.provides) {\n return;\n }\n\n return zoomCapability.provides.registerMarqueeOnPage({\n documentId,\n pageIndex,\n scale: actualScale,\n callback: {\n onPreview: (newRect) => {\n rect = newRect;\n },\n },\n });\n });\n</script>\n\n{#if rect}\n <div\n style:position=\"absolute\"\n style:pointer-events=\"none\"\n style:left={`${rect.origin.x * actualScale}px`}\n style:top={`${rect.origin.y * actualScale}px`}\n style:width={`${rect.size.width * actualScale}px`}\n style:height={`${rect.size.height * actualScale}px`}\n style:border={`1px solid ${stroke}`}\n style:background={fill}\n style:box-sizing=\"border-box\"\n class={propsClass}\n ></div>\n{/if}\n","<script lang=\"ts\">\n import { usePinch } from '../hooks';\n import type { Snippet } from 'svelte';\n import type { HTMLAttributes } from 'svelte/elements';\n\n type PinchWrapperProps = Omit<HTMLAttributes<HTMLDivElement>, 'style'> & {\n documentId: string;\n children: Snippet;\n class?: string;\n };\n\n let { documentId, children, class: propsClass, ...restProps }: PinchWrapperProps = $props();\n const pinch = usePinch(() => documentId);\n</script>\n\n<div\n bind:this={pinch.elementRef}\n {...restProps}\n style:display=\"block\"\n style:width=\"fit-content\"\n style:overflow=\"visible\"\n style:box-sizing=\"border-box\"\n style:margin=\"0px auto\"\n class={propsClass}\n>\n {@render children()}\n</div>\n"],"names":[],"mappings":";;;;;AAQa,MAAA,oBAAA,MAA0B,cAA0B,WAAW,EAAE;AACjE,MAAA,gBAAA,MAAsB,UAAsB,W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AAU;;IAE9B;WAEO,eAAe,SAAS,sBAAqB;AAAA,MAClD,YAAU,QAAA;AAAA,MACV,WAAS,QAAA;AAAA,MACT,aAAO,WAAW;AAAA,MAClB,UAAQ;AAAA,QACN,WAAS,CAAG,YAAY;AACtB,YAAA,IAAA,MAAO,SAAO,IAAA;AAAA,QAChB;AAAA;;EAGN,CAAC;;;;;;;;;;;;UAOgB,MAAA,GAAA,EAAA,IAAA,IAAI,EAAC,OAAO,UAAI,WAAW,CAAA;AAAA,UAC5B,KAAA,GAAA,EAAA,IAAA,IAAI,EAAC,OAAO,UAAI,WAAW,CAAA;AAAA,UACzB,OAAA,GAAA,EAAA,IAAA,IAAI,EAAC,KAAK,cAAQ,WAAW,CAAA;AAAA,UAC5B,QAAA,GAAA,EAAA,IAAA,IAAI,EAAC,KAAK,eAAS,WAAW,CAAA;AAAA,+BACpB,OAAM,CAAA;AAAA,sBACf,KAAI;AAAA;;;;;;gBATrB,IAAI,EAAA,UAAA,UAAA;AAAA;;;;AAFT;;yCCvDA;;MAWoD,YAAS,EAAA,WAAA,SAAA;AAAA;;;;;;;AACrD,QAAA,QAAQ,SAAQ,MAAA,QAAA,UAAA;;;OAKlB;AAAA;;;;;;;;;;;;AADO,IAAA,UAAA,KAAA,CAAA,YAAA,MAAM,aAAU,SAAA,MAAhB,+BAAM,UAAU;;;AAH7B;"}
1
+ {"version":3,"file":"index.js","sources":["../../src/svelte/hooks/use-zoom.svelte.ts","../../src/shared/utils/zoom-gesture-logic.ts","../../src/svelte/hooks/use-zoom-gesture.svelte.ts","../../src/svelte/components/MarqueeZoom.svelte","../../src/svelte/components/ZoomGestureWrapper.svelte"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/svelte';\nimport {\n initialDocumentState,\n ZoomDocumentState,\n ZoomPlugin,\n ZoomScope,\n} from '@embedpdf/plugin-zoom';\n\nexport const useZoomCapability = () => useCapability<ZoomPlugin>(ZoomPlugin.id);\nexport const useZoomPlugin = () => usePlugin<ZoomPlugin>(ZoomPlugin.id);\n\n// Define the return type explicitly to maintain type safety\ninterface UseZoomReturn {\n provides: ZoomScope | null;\n state: ZoomDocumentState;\n}\n\n/**\n * Hook for zoom state for a specific document\n * @param getDocumentId Function that returns the document ID\n */\nexport const useZoom = (getDocumentId: () => string | null): UseZoomReturn => {\n const capability = useZoomCapability();\n\n let state = $state<ZoomDocumentState>(initialDocumentState);\n\n // Reactive documentId\n const documentId = $derived(getDocumentId());\n\n // Scoped capability for current docId\n const scopedProvides = $derived(\n capability.provides && documentId ? capability.provides.forDocument(documentId) : null,\n );\n\n $effect(() => {\n const provides = capability.provides;\n const docId = documentId;\n\n if (!provides || !docId) {\n state = initialDocumentState;\n return;\n }\n\n const scope = provides.forDocument(docId);\n\n // Get initial state\n state = scope.getState();\n\n // Subscribe to state changes for this document\n return scope.onStateChange((newState) => {\n state = newState;\n });\n });\n\n return {\n get provides() {\n return scopedProvides;\n },\n get state() {\n return state;\n },\n };\n};\n","import type { ZoomCapability } from '@embedpdf/plugin-zoom';\n\nexport interface ZoomGestureOptions {\n /** Enable pinch-to-zoom gesture (default: true) */\n enablePinch?: boolean;\n /** Enable wheel zoom with ctrl/cmd key (default: true) */\n enableWheel?: boolean;\n}\n\nexport interface ZoomGestureDeps {\n element: HTMLDivElement;\n /** Viewport container element for attaching events */\n container: HTMLElement;\n documentId: string;\n zoomProvides: ZoomCapability;\n /** Viewport gap in pixels (default: 0) */\n viewportGap?: number;\n options?: ZoomGestureOptions;\n}\n\nfunction getTouchDistance(touches: TouchList): number {\n const [t1, t2] = [touches[0], touches[1]];\n const dx = t2.clientX - t1.clientX;\n const dy = t2.clientY - t1.clientY;\n return Math.hypot(dx, dy);\n}\n\nfunction getTouchCenter(touches: TouchList): { x: number; y: number } {\n const [t1, t2] = [touches[0], touches[1]];\n return {\n x: (t1.clientX + t2.clientX) / 2,\n y: (t1.clientY + t2.clientY) / 2,\n };\n}\n\nexport function setupZoomGestures({\n element,\n container,\n documentId,\n zoomProvides,\n viewportGap = 0,\n options = {},\n}: ZoomGestureDeps) {\n const { enablePinch = true, enableWheel = true } = options;\n if (typeof window === 'undefined') {\n return () => {};\n }\n\n const zoomScope = zoomProvides.forDocument(documentId);\n const getState = () => zoomScope.getState();\n\n // Shared state\n let initialZoom = 0;\n let currentScale = 1;\n let isPinching = false;\n let initialDistance = 0;\n\n // Wheel state\n let wheelZoomTimeout: ReturnType<typeof setTimeout> | null = null;\n let accumulatedWheelScale = 1;\n\n // Gesture state\n let initialElementWidth = 0;\n let initialElementHeight = 0;\n let initialElementLeft = 0;\n let initialElementTop = 0;\n\n // Container Dimensions (Bounding Box)\n let containerRectWidth = 0;\n let containerRectHeight = 0;\n\n // Layout Dimensions (Client Box from Metrics)\n let layoutWidth = 0;\n let layoutCenterX = 0;\n\n let pointerLocalY = 0;\n let pointerContainerX = 0;\n let pointerContainerY = 0;\n\n let currentGap = 0;\n let pivotLocalX = 0;\n\n const clamp = (val: number, min: number, max: number) => Math.min(Math.max(val, min), max);\n\n // --- Margin calculation ---\n const updateMargin = () => {\n const availableWidth = container.clientWidth - 2 * viewportGap;\n const elementWidth = element.offsetWidth;\n\n const newMargin = elementWidth < availableWidth ? (availableWidth - elementWidth) / 2 : 0;\n element.style.marginLeft = `${newMargin}px`;\n };\n\n const calculateTransform = (scale: number) => {\n const finalWidth = initialElementWidth * scale;\n const finalHeight = initialElementHeight * scale;\n\n let ty = pointerLocalY * (1 - scale);\n\n const targetX = layoutCenterX - finalWidth / 2;\n const txCenter = targetX - initialElementLeft;\n const txMouse = pointerContainerX - pivotLocalX * scale - initialElementLeft;\n\n const overflow = Math.max(0, finalWidth - layoutWidth);\n const blendRange = layoutWidth * 0.3;\n const blend = Math.min(1, overflow / blendRange);\n\n let tx = txCenter + (txMouse - txCenter) * blend;\n\n const safeHeight = containerRectHeight - currentGap * 2;\n if (finalHeight > safeHeight) {\n const currentTop = initialElementTop + ty;\n const maxTop = currentGap;\n const minTop = containerRectHeight - currentGap - finalHeight;\n const constrainedTop = clamp(currentTop, minTop, maxTop);\n ty = constrainedTop - initialElementTop;\n }\n\n const safeWidth = containerRectWidth - currentGap * 2;\n if (finalWidth > safeWidth) {\n const currentLeft = initialElementLeft + tx;\n const maxLeft = currentGap;\n const minLeft = containerRectWidth - currentGap - finalWidth;\n const constrainedLeft = clamp(currentLeft, minLeft, maxLeft);\n tx = constrainedLeft - initialElementLeft;\n }\n\n return { tx, ty, blend, finalWidth };\n };\n\n const updateTransform = (scale: number) => {\n currentScale = scale;\n const { tx, ty } = calculateTransform(scale);\n element.style.transformOrigin = '0 0';\n element.style.transform = `translate(${tx}px, ${ty}px) scale(${scale})`;\n };\n\n const resetTransform = () => {\n element.style.transform = 'none';\n element.style.transformOrigin = '0 0';\n currentScale = 1;\n };\n\n const commitZoom = () => {\n const { tx, finalWidth } = calculateTransform(currentScale);\n const delta = (currentScale - 1) * initialZoom;\n\n let anchorX: number;\n let anchorY: number = pointerContainerY;\n\n if (finalWidth <= layoutWidth) {\n anchorX = layoutCenterX;\n } else {\n const scaleDiff = 1 - currentScale;\n anchorX =\n Math.abs(scaleDiff) > 0.001 ? initialElementLeft + tx / scaleDiff : pointerContainerX;\n }\n\n zoomScope.requestZoomBy(delta, { vx: anchorX, vy: anchorY });\n resetTransform();\n initialZoom = 0;\n };\n\n const initializeGestureState = (clientX: number, clientY: number) => {\n const containerRect = container.getBoundingClientRect();\n const innerRect = element.getBoundingClientRect();\n\n currentGap = viewportGap;\n initialElementWidth = innerRect.width;\n initialElementHeight = innerRect.height;\n initialElementLeft = innerRect.left - containerRect.left;\n initialElementTop = innerRect.top - containerRect.top;\n\n containerRectWidth = containerRect.width;\n containerRectHeight = containerRect.height;\n\n // Layout dimensions from container's client area\n layoutWidth = container.clientWidth;\n layoutCenterX = container.clientLeft + layoutWidth / 2;\n\n const rawPointerLocalX = clientX - innerRect.left;\n pointerLocalY = clientY - innerRect.top;\n pointerContainerX = clientX - containerRect.left;\n pointerContainerY = clientY - containerRect.top;\n\n if (initialElementWidth < layoutWidth) {\n pivotLocalX = (pointerContainerX * initialElementWidth) / layoutWidth;\n } else {\n pivotLocalX = rawPointerLocalX;\n }\n };\n\n // --- Handlers ---\n const handleTouchStart = (e: TouchEvent) => {\n if (e.touches.length !== 2) return;\n isPinching = true;\n initialZoom = getState().currentZoomLevel;\n initialDistance = getTouchDistance(e.touches);\n const center = getTouchCenter(e.touches);\n initializeGestureState(center.x, center.y);\n e.preventDefault();\n };\n\n const handleTouchMove = (e: TouchEvent) => {\n if (!isPinching || e.touches.length !== 2) return;\n const currentDistance = getTouchDistance(e.touches);\n const scale = currentDistance / initialDistance;\n updateTransform(scale);\n e.preventDefault();\n };\n\n const handleTouchEnd = (e: TouchEvent) => {\n if (!isPinching) return;\n if (e.touches.length >= 2) return;\n isPinching = false;\n commitZoom();\n };\n\n const handleWheel = (e: WheelEvent) => {\n if (!e.ctrlKey && !e.metaKey) return;\n e.preventDefault();\n\n if (wheelZoomTimeout === null) {\n initialZoom = getState().currentZoomLevel;\n accumulatedWheelScale = 1;\n initializeGestureState(e.clientX, e.clientY);\n } else {\n clearTimeout(wheelZoomTimeout);\n }\n\n const zoomFactor = 1 - e.deltaY * 0.01;\n accumulatedWheelScale *= zoomFactor;\n accumulatedWheelScale = Math.max(0.1, Math.min(10, accumulatedWheelScale));\n updateTransform(accumulatedWheelScale);\n\n wheelZoomTimeout = setTimeout(() => {\n wheelZoomTimeout = null;\n commitZoom();\n accumulatedWheelScale = 1;\n }, 150);\n };\n\n // Subscribe to zoom changes to update margin\n const unsubZoom = zoomScope.onStateChange(() => updateMargin());\n\n // Use ResizeObserver to update margin when element or container size changes\n const resizeObserver = new ResizeObserver(() => updateMargin());\n resizeObserver.observe(element);\n resizeObserver.observe(container);\n\n // Initial margin calculation\n updateMargin();\n\n // Attach events to the viewport container for better UX\n // (gestures work anywhere in viewport, not just on the PDF)\n if (enablePinch) {\n container.addEventListener('touchstart', handleTouchStart, { passive: false });\n container.addEventListener('touchmove', handleTouchMove, { passive: false });\n container.addEventListener('touchend', handleTouchEnd);\n container.addEventListener('touchcancel', handleTouchEnd);\n }\n if (enableWheel) {\n container.addEventListener('wheel', handleWheel, { passive: false });\n }\n\n return () => {\n if (enablePinch) {\n container.removeEventListener('touchstart', handleTouchStart);\n container.removeEventListener('touchmove', handleTouchMove);\n container.removeEventListener('touchend', handleTouchEnd);\n container.removeEventListener('touchcancel', handleTouchEnd);\n }\n if (enableWheel) {\n container.removeEventListener('wheel', handleWheel);\n }\n if (wheelZoomTimeout) {\n clearTimeout(wheelZoomTimeout);\n }\n unsubZoom();\n resizeObserver.disconnect();\n resetTransform();\n element.style.marginLeft = '';\n };\n}\n","import { getContext } from 'svelte';\nimport { useCapability } from '@embedpdf/core/svelte';\nimport type { ViewportPlugin } from '@embedpdf/plugin-viewport';\nimport { setupZoomGestures, type ZoomGestureOptions } from '../../shared/utils/zoom-gesture-logic';\nimport { useZoomCapability } from './use-zoom.svelte';\n\nexport type { ZoomGestureOptions };\n\n/** Context type for viewport element */\ntype ViewportElementContext = { readonly current: HTMLDivElement | null };\n\nexport interface UseZoomGestureOptions {\n /** Enable pinch-to-zoom gesture (default: true) */\n enablePinch?: () => boolean;\n /** Enable wheel zoom with ctrl/cmd key (default: true) */\n enableWheel?: () => boolean;\n}\n\n/**\n * Hook for setting up zoom gesture functionality (pinch and wheel zoom) on an element\n * @param getDocumentId Function that returns the document ID\n * @param options Optional configuration for enabling/disabling gestures\n */\nexport function useZoomGesture(\n getDocumentId: () => string | null,\n options: UseZoomGestureOptions = {},\n) {\n const viewportCapability = useCapability<ViewportPlugin>('viewport');\n const zoomCapability = useZoomCapability();\n const viewportElementCtx = getContext<ViewportElementContext | undefined>('viewport-element');\n\n let elementRef = $state<HTMLDivElement | null>(null);\n let cleanup: (() => void) | undefined;\n\n // Reactive documentId and options\n const documentId = $derived(getDocumentId());\n const enablePinch = $derived(options.enablePinch?.() ?? true);\n const enableWheel = $derived(options.enableWheel?.() ?? true);\n\n $effect(() => {\n const element = elementRef;\n const container = viewportElementCtx?.current;\n const viewport = viewportCapability.provides;\n const zoom = zoomCapability.provides;\n const docId = documentId;\n const pinchEnabled = enablePinch;\n const wheelEnabled = enableWheel;\n\n // Clean up previous setup\n if (cleanup) {\n cleanup();\n cleanup = undefined;\n }\n\n // Setup new zoom gestures if all dependencies are available\n if (!element || !container || !zoom || !docId) {\n return;\n }\n\n cleanup = setupZoomGestures({\n element,\n container,\n documentId: docId,\n zoomProvides: zoom,\n viewportGap: viewport?.getViewportGap() || 0,\n options: { enablePinch: pinchEnabled, enableWheel: wheelEnabled },\n });\n\n return () => {\n if (cleanup) {\n cleanup();\n cleanup = undefined;\n }\n };\n });\n\n return {\n get elementRef() {\n return elementRef;\n },\n set elementRef(value: HTMLDivElement | null) {\n elementRef = value;\n },\n };\n}\n","<script lang=\"ts\">\n import type { Rect } from '@embedpdf/models';\n import { useDocumentState } from '@embedpdf/core/svelte';\n import { useZoomCapability } from '../hooks/use-zoom.svelte';\n\n interface MarqueeZoomProps {\n /** The ID of the document */\n documentId: string;\n /** Index of the page this layer lives on */\n pageIndex: number;\n /** Scale of the page */\n scale?: number;\n /** Optional CSS class applied to the marquee rectangle */\n class?: string;\n /** Stroke / fill colours (defaults below) */\n stroke?: string;\n fill?: string;\n }\n\n let {\n documentId,\n pageIndex,\n scale: scaleOverride,\n class: propsClass,\n stroke = 'rgba(33,150,243,0.8)',\n fill = 'rgba(33,150,243,0.15)',\n }: MarqueeZoomProps = $props();\n\n const zoomCapability = useZoomCapability();\n const documentState = useDocumentState(() => documentId);\n\n let rect = $state<Rect | null>(null);\n\n const actualScale = $derived(\n scaleOverride !== undefined ? scaleOverride : (documentState.current?.scale ?? 1),\n );\n\n $effect(() => {\n rect = null;\n\n if (!zoomCapability.provides) {\n return;\n }\n\n return zoomCapability.provides.registerMarqueeOnPage({\n documentId,\n pageIndex,\n scale: actualScale,\n callback: {\n onPreview: (newRect) => {\n rect = newRect;\n },\n },\n });\n });\n</script>\n\n{#if rect}\n <div\n style:position=\"absolute\"\n style:pointer-events=\"none\"\n style:left={`${rect.origin.x * actualScale}px`}\n style:top={`${rect.origin.y * actualScale}px`}\n style:width={`${rect.size.width * actualScale}px`}\n style:height={`${rect.size.height * actualScale}px`}\n style:border={`1px solid ${stroke}`}\n style:background={fill}\n style:box-sizing=\"border-box\"\n class={propsClass}\n ></div>\n{/if}\n","<script lang=\"ts\">\n import { useZoomGesture } from '../hooks';\n import type { Snippet } from 'svelte';\n import type { HTMLAttributes } from 'svelte/elements';\n\n type ZoomGestureWrapperProps = Omit<HTMLAttributes<HTMLDivElement>, 'style'> & {\n documentId: string;\n children: Snippet;\n class?: string;\n /** Enable pinch-to-zoom gesture (default: true) */\n enablePinch?: boolean;\n /** Enable wheel zoom with ctrl/cmd key (default: true) */\n enableWheel?: boolean;\n };\n\n let {\n documentId,\n children,\n class: propsClass,\n enablePinch = true,\n enableWheel = true,\n ...restProps\n }: ZoomGestureWrapperProps = $props();\n\n const zoomGesture = useZoomGesture(() => documentId, {\n enablePinch: () => enablePinch,\n enableWheel: () => enableWheel,\n });\n</script>\n\n<div\n bind:this={zoomGesture.elementRef}\n {...restProps}\n style:display=\"inline-block\"\n style:overflow=\"visible\"\n style:box-sizing=\"border-box\"\n class={propsClass}\n>\n {@render children()}\n</div>\n"],"names":[],"mappings":";;;;;;AAQa,MAAA,oBAAA,MAA0B,cAA0B,WAAW,EAAE;AACjE,MAAA,gBAAA,MAAsB,UAAsB,WAAW,EAAE;MAYzD,UAAA,CAAW,kBAAsD;AACtE,QAAA,aAAa,kBAAA;AAEf,MAAA,wBAAkC,oBAAoB,CAAA;AAGpD,QAAA,uBAAsB,aAAA;AAGtB,QAAA,iBAAA,EAAA,QAAA,MACJ,WAAW,kBAAY,UAAA,IAAa,WAAW,SAAS,kBAAY,UAAU,CAAA,IAAI,IAAA;AAGpF,IAAA,kBAAc;UACN,WAAW,WAAW;AACtB,UAAA,cAAQ,UAAA;SAET,YAAA,CAAa,OAAO;AACvB,QAAA,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AAC,OAAO,UAAI,WAAW,CAAA;AAAA,UACzB,OAAA,GAAA,EAAA,IAAA,IAAI,EAAC,KAAK,cAAQ,WAAW,CAAA;AAAA,UAC5B,QAAA,GAAA,EAAA,IAAA,IAAI,EAAC,KAAK,eAAS,WAAW,CAAA;AAAA,+BACpB,OAAM,CAAA;AAAA,sBACf,KAAI;AAAA;;;;;;gBATrB,IAAI,EAAA,UAAA,UAAA;AAAA;;;;AAFT;;+CCvDA;;AAmBI,MAAA,gDAAc,IAAI,GAClB,gDAAc,IAAI,GACf,YAAQ,EAAA,WAAA,SAAA;AAAA;;;;;;;;;AAGP,QAAA,cAAc,eAAc,MAAA,QAAA,YAAA;AAAA,IAChC,mBAAmB,YAAW;AAAA,IAC9B,mBAAmB,YAAW;AAAA;;;OAM5B;AAAA;;;;;;;;;;AADO,IAAA,UAAA,KAAA,CAAA,YAAA,YAAY,aAAU,SAAA,MAAtB,2CAAY,UAAU;;;AAHnC;"}
@@ -1,2 +1,2 @@
1
1
  export { default as MarqueeZoom } from './marquee-zoom.vue';
2
- export { default as PinchWrapper } from './pinch-wrapper.vue';
2
+ export { default as ZoomGestureWrapper } from './zoom-gesture-wrapper.vue';
@@ -1,11 +1,18 @@
1
1
  interface Props {
2
2
  documentId: string;
3
+ /** Enable pinch-to-zoom gesture (default: true) */
4
+ enablePinch?: boolean;
5
+ /** Enable wheel zoom with ctrl/cmd key (default: true) */
6
+ enableWheel?: boolean;
3
7
  }
4
8
  declare var __VLS_1: {};
5
9
  type __VLS_Slots = {} & {
6
10
  default?: (props: typeof __VLS_1) => any;
7
11
  };
8
- declare const __VLS_base: import('vue').DefineComponent<Props, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<Props> & Readonly<{}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
12
+ declare const __VLS_base: import('vue').DefineComponent<Props, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<Props> & Readonly<{}>, {
13
+ enablePinch: boolean;
14
+ enableWheel: boolean;
15
+ }, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
9
16
  declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
10
17
  declare const _default: typeof __VLS_export;
11
18
  export default _default;
@@ -1,2 +1,2 @@
1
1
  export * from './use-zoom';
2
- export * from './use-pinch-zoom';
2
+ export * from './use-zoom-gesture';
@@ -0,0 +1,17 @@
1
+ import { MaybeRefOrGetter, Ref } from 'vue';
2
+ import { ZoomGestureOptions } from '../../shared-vue/utils/zoom-gesture-logic';
3
+ export type { ZoomGestureOptions };
4
+ export interface UseZoomGestureOptions {
5
+ /** Enable pinch-to-zoom gesture (default: true) */
6
+ enablePinch?: MaybeRefOrGetter<boolean>;
7
+ /** Enable wheel zoom with ctrl/cmd key (default: true) */
8
+ enableWheel?: MaybeRefOrGetter<boolean>;
9
+ }
10
+ /**
11
+ * Hook for setting up zoom gesture functionality (pinch and wheel zoom) on an element
12
+ * @param documentId Document ID (can be ref, computed, getter, or plain value)
13
+ * @param options Optional configuration for enabling/disabling gestures
14
+ */
15
+ export declare function useZoomGesture(documentId: MaybeRefOrGetter<string>, options?: UseZoomGestureOptions): {
16
+ elementRef: Ref<HTMLDivElement | null, HTMLDivElement | null>;
17
+ };
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),t=require("@embedpdf/core/vue"),o=require("@embedpdf/plugin-zoom"),n=()=>t.useCapability(o.ZoomPlugin.id);function r({element:e,documentId:t,viewportProvides:o,zoomProvides:n}){if("undefined"==typeof window)return()=>{};let r,a=0,l={x:0,y:0};const i=o.forDocument(t),s=n.forDocument(t),u=()=>{e.style.transform="none",e.style.transformOrigin="0 0"},c=t=>{var o;a=s.getState().currentZoomLevel;const n=i.getBoundingRect();l={x:t.center.x-n.origin.x,y:t.center.y-n.origin.y};const r=e.getBoundingClientRect();e.style.transformOrigin=`${t.center.x-r.left}px ${t.center.y-r.top}px`,(null==(o=t.srcEvent)?void 0:o.cancelable)&&(t.srcEvent.preventDefault(),t.srcEvent.stopPropagation())},d=t=>{var o,n;n=t.scale,e.style.transform=`scale(${n})`,(null==(o=t.srcEvent)?void 0:o.cancelable)&&(t.srcEvent.preventDefault(),t.srcEvent.stopPropagation())},p=e=>{const t=(e.scale-1)*a;s.requestZoomBy(t,{vx:l.x,vy:l.y}),u(),a=0};return(async()=>{try{const t=(await Promise.resolve().then(()=>require("../hammer-DhVzwxwy.cjs")).then(e=>e.hammer)).default,o=(()=>{const e="ontouchstart"in window||navigator.maxTouchPoints>0;return e&&/mobile|tablet|ip(ad|hone|od)|android/i.test(navigator.userAgent)?t.TouchInput:e?t.TouchMouseInput:t.MouseInput})();r=new t(e,{touchAction:"pan-x pan-y",inputClass:o}),r.get("pinch").set({enable:!0,pointers:2,threshold:.1}),r.on("pinchstart",c),r.on("pinchmove",d),r.on("pinchend",p)}catch(t){console.warn("Failed to load HammerJS:",t)}})(),()=>{null==r||r.destroy(),u()}}function a(o){const{provides:a}=t.useCapability("viewport"),{provides:l}=n(),i=e.ref(null);let s;return e.watch([i,a,l,()=>e.toValue(o)],([e,t,o,n])=>{s&&(s(),s=void 0),e&&t&&o&&(s=r({element:e,documentId:n,viewportProvides:t,zoomProvides:o}))},{immediate:!0}),{elementRef:i}}const l=e.defineComponent({__name:"marquee-zoom",props:{documentId:{},pageIndex:{},scale:{},className:{},stroke:{default:"rgba(33,150,243,0.8)"},fill:{default:"rgba(33,150,243,0.15)"}},setup(o){const r=o,{provides:a}=n(),l=t.useDocumentState(()=>r.documentId),i=e.ref(null),s=e.computed(()=>{var e;return void 0!==r.scale?r.scale:(null==(e=l.value)?void 0:e.scale)??1});return e.watch([a,()=>r.documentId,()=>r.pageIndex,s],([e,t,o,n],r,a)=>{if(!e)return void(i.value=null);const l=e.registerMarqueeOnPage({documentId:t,pageIndex:o,scale:n,callback:{onPreview:e=>{i.value=e}}});a(()=>{null==l||l()})},{immediate:!0}),(t,n)=>i.value?(e.openBlock(),e.createElementBlock("div",{key:0,style:e.normalizeStyle({position:"absolute",pointerEvents:"none",left:i.value.origin.x*s.value+"px",top:i.value.origin.y*s.value+"px",width:i.value.size.width*s.value+"px",height:i.value.size.height*s.value+"px",border:`1px solid ${o.stroke}`,background:o.fill,boxSizing:"border-box"}),class:e.normalizeClass(o.className)},null,6)):e.createCommentVNode("",!0)}}),i=e.defineComponent({__name:"pinch-wrapper",props:{documentId:{}},setup(t){const o=t,{elementRef:n}=a(o.documentId);return(t,o)=>(e.openBlock(),e.createElementBlock("div",e.mergeProps({ref_key:"elementRef",ref:n,style:{display:"block",width:"fit-content",overflow:"visible",boxSizing:"border-box",margin:"0px auto"}},t.$attrs),[e.renderSlot(t.$slots,"default")],16))}});exports.MarqueeZoom=l,exports.PinchWrapper=i,exports.usePinch=a,exports.useZoom=t=>{const{provides:r}=n(),a=e.ref(o.initialDocumentState);e.watch([r,()=>e.toValue(t)],([e,t],n,r)=>{if(!e)return void(a.value=o.initialDocumentState);const l=e.forDocument(t);a.value=l.getState();r(l.onStateChange(e=>{a.value=e}))},{immediate:!0});const l=e.computed(()=>{var o;const n=e.toValue(t);return(null==(o=r.value)?void 0:o.forDocument(n))??null});return{state:e.readonly(a),provides:l}},exports.useZoomCapability=n,exports.useZoomPlugin=()=>t.usePlugin(o.ZoomPlugin.id),Object.keys(o).forEach(e=>{"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:()=>o[e]})});
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),t=require("@embedpdf/core/vue"),n=require("@embedpdf/plugin-zoom"),o=()=>t.useCapability(n.ZoomPlugin.id);function l(e){const[t,n]=[e[0],e[1]],o=n.clientX-t.clientX,l=n.clientY-t.clientY;return Math.hypot(o,l)}function r(n,r={}){const{provides:i}=t.useCapability("viewport"),{provides:a}=o(),s=e.inject("viewport-element"),u=e.ref(null);let c;return e.watch([u,i,a,()=>e.toValue(n),()=>e.toValue(r.enablePinch??!0),()=>e.toValue(r.enableWheel??!0)],([e,t,n,o,r,i])=>{c&&(c(),c=void 0);const a=null==s?void 0:s.value;e&&a&&n&&(c=function({element:e,container:t,documentId:n,zoomProvides:o,viewportGap:r=0,options:i={}}){const{enablePinch:a=!0,enableWheel:s=!0}=i;if("undefined"==typeof window)return()=>{};const u=o.forDocument(n),c=()=>u.getState();let d=0,m=1,p=!1,v=0,h=null,f=1,b=0,g=0,y=0,x=0,w=0,P=0,L=0,E=0,S=0,k=0,z=0,W=0,C=0;const I=(e,t,n)=>Math.min(Math.max(e,t),n),M=()=>{const n=t.clientWidth-2*r,o=e.offsetWidth,l=o<n?(n-o)/2:0;e.style.marginLeft=`${l}px`},Z=e=>{const t=b*e,n=g*e;let o=S*(1-e);const l=E-t/2-y,r=k-C*e-y,i=Math.max(0,t-L),a=.3*L,s=Math.min(1,i/a);let u=l+(r-l)*s;return n>P-2*W&&(o=I(x+o,P-W-n,W)-x),t>w-2*W&&(u=I(y+u,w-W-t,W)-y),{tx:u,ty:o,blend:s,finalWidth:t}},B=t=>{m=t;const{tx:n,ty:o}=Z(t);e.style.transformOrigin="0 0",e.style.transform=`translate(${n}px, ${o}px) scale(${t})`},D=()=>{e.style.transform="none",e.style.transformOrigin="0 0",m=1},O=()=>{const{tx:e,finalWidth:t}=Z(m),n=(m-1)*d;let o,l=z;if(t<=L)o=E;else{const t=1-m;o=Math.abs(t)>.001?y+e/t:k}u.requestZoomBy(n,{vx:o,vy:l}),D(),d=0},R=(n,o)=>{const l=t.getBoundingClientRect(),i=e.getBoundingClientRect();W=r,b=i.width,g=i.height,y=i.left-l.left,x=i.top-l.top,w=l.width,P=l.height,L=t.clientWidth,E=t.clientLeft+L/2;const a=n-i.left;S=o-i.top,k=n-l.left,z=o-l.top,C=b<L?k*b/L:a},q=e=>{if(2!==e.touches.length)return;p=!0,d=c().currentZoomLevel,v=l(e.touches);const t=function(e){const[t,n]=[e[0],e[1]];return{x:(t.clientX+n.clientX)/2,y:(t.clientY+n.clientY)/2}}(e.touches);R(t.x,t.y),e.preventDefault()},V=e=>{if(!p||2!==e.touches.length)return;const t=l(e.touches);B(t/v),e.preventDefault()},$=e=>{p&&(e.touches.length>=2||(p=!1,O()))},Y=e=>{if(!e.ctrlKey&&!e.metaKey)return;e.preventDefault(),null===h?(d=c().currentZoomLevel,f=1,R(e.clientX,e.clientY)):clearTimeout(h);const t=1-.01*e.deltaY;f*=t,f=Math.max(.1,Math.min(10,f)),B(f),h=setTimeout(()=>{h=null,O(),f=1},150)},j=u.onStateChange(()=>M()),G=new ResizeObserver(()=>M());return G.observe(e),G.observe(t),M(),a&&(t.addEventListener("touchstart",q,{passive:!1}),t.addEventListener("touchmove",V,{passive:!1}),t.addEventListener("touchend",$),t.addEventListener("touchcancel",$)),s&&t.addEventListener("wheel",Y,{passive:!1}),()=>{a&&(t.removeEventListener("touchstart",q),t.removeEventListener("touchmove",V),t.removeEventListener("touchend",$),t.removeEventListener("touchcancel",$)),s&&t.removeEventListener("wheel",Y),h&&clearTimeout(h),j(),G.disconnect(),D(),e.style.marginLeft=""}}({element:e,container:a,documentId:o,zoomProvides:n,viewportGap:(null==t?void 0:t.getViewportGap())||0,options:{enablePinch:r,enableWheel:i}}))},{immediate:!0}),{elementRef:u}}const i=e.defineComponent({__name:"marquee-zoom",props:{documentId:{},pageIndex:{},scale:{},className:{},stroke:{default:"rgba(33,150,243,0.8)"},fill:{default:"rgba(33,150,243,0.15)"}},setup(n){const l=n,{provides:r}=o(),i=t.useDocumentState(()=>l.documentId),a=e.ref(null),s=e.computed(()=>{var e;return void 0!==l.scale?l.scale:(null==(e=i.value)?void 0:e.scale)??1});return e.watch([r,()=>l.documentId,()=>l.pageIndex,s],([e,t,n,o],l,r)=>{if(!e)return void(a.value=null);const i=e.registerMarqueeOnPage({documentId:t,pageIndex:n,scale:o,callback:{onPreview:e=>{a.value=e}}});r(()=>{null==i||i()})},{immediate:!0}),(t,o)=>a.value?(e.openBlock(),e.createElementBlock("div",{key:0,style:e.normalizeStyle({position:"absolute",pointerEvents:"none",left:a.value.origin.x*s.value+"px",top:a.value.origin.y*s.value+"px",width:a.value.size.width*s.value+"px",height:a.value.size.height*s.value+"px",border:`1px solid ${n.stroke}`,background:n.fill,boxSizing:"border-box"}),class:e.normalizeClass(n.className)},null,6)):e.createCommentVNode("",!0)}}),a=e.defineComponent({__name:"zoom-gesture-wrapper",props:{documentId:{},enablePinch:{type:Boolean,default:!0},enableWheel:{type:Boolean,default:!0}},setup(t){const n=t,{elementRef:o}=r(()=>n.documentId,{enablePinch:e.toRef(()=>n.enablePinch),enableWheel:e.toRef(()=>n.enableWheel)});return(t,n)=>(e.openBlock(),e.createElementBlock("div",e.mergeProps({ref_key:"elementRef",ref:o,style:{display:"inline-block",overflow:"visible",boxSizing:"border-box"}},t.$attrs),[e.renderSlot(t.$slots,"default")],16))}});exports.MarqueeZoom=i,exports.ZoomGestureWrapper=a,exports.useZoom=t=>{const{provides:l}=o(),r=e.ref(n.initialDocumentState);e.watch([l,()=>e.toValue(t)],([e,t],o,l)=>{if(!e)return void(r.value=n.initialDocumentState);const i=e.forDocument(t);r.value=i.getState();l(i.onStateChange(e=>{r.value=e}))},{immediate:!0});const i=e.computed(()=>{var n;const o=e.toValue(t);return(null==(n=l.value)?void 0:n.forDocument(o))??null});return{state:e.readonly(r),provides:i}},exports.useZoomCapability=o,exports.useZoomGesture=r,exports.useZoomPlugin=()=>t.usePlugin(n.ZoomPlugin.id),Object.keys(n).forEach(e=>{"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:()=>n[e]})});
2
2
  //# sourceMappingURL=index.cjs.map