@r74tech/docusaurus-plugin-panzoom 2.3.0 → 2.4.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/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ # [2.4.0](https://github.com/r74tech/docusaurus-plugin-panzoom/compare/v2.3.0...v2.4.0) (2025-07-19)
2
+
3
+
4
+ ### Features
5
+
6
+ * add options to better control the zoom ([#7](https://github.com/r74tech/docusaurus-plugin-panzoom/issues/7)) ([4dc537c](https://github.com/r74tech/docusaurus-plugin-panzoom/commit/4dc537c8e059908cc2cae407fc78ae93de34c6dd))
7
+
1
8
  # [2.3.0](https://github.com/r74tech/docusaurus-plugin-panzoom/compare/v2.2.0...v2.3.0) (2025-07-17)
2
9
 
3
10
 
package/dist/PanZoom.js CHANGED
@@ -12,9 +12,10 @@ require("./styles/panzoom.css");
12
12
  const config = require('@generated/docusaurus.config').default;
13
13
  const { themeConfig } = config;
14
14
  const { zoom } = themeConfig;
15
- const { selectors = ['div.mermaid[data-processed="true"]', 'div.docusaurus-mermaid-container', '.drawio'], wrap = true, timeout = 1000, excludeClass = 'panzoom-exclude', toolbar: { enabled = false, position = PanzoomPluginOptions_1.PanZoomPluginToolbarPosition.TopRight, opacity = 0 } = {}, ...panZoomConfig } = zoom;
15
+ const { selectors = ['div.mermaid[data-processed="true"]', 'div.docusaurus-mermaid-container', '.drawio'], wrap = true, timeout = 1000, excludeClass = 'panzoom-exclude', toolbar: { enabled = false, position = PanzoomPluginOptions_1.PanZoomPluginToolbarPosition.TopRight, opacity = 0 } = {}, enableWheelZoom = true, enableWheelZoomWithShift = false, enableDoubleClickResetZoom = true, restrictZoomOutBeyondOrigin = false, ...panZoomConfig } = zoom;
16
16
  /**
17
17
  * Creates a toolbar with zoom controls for a panzoom instance
18
+ *
18
19
  * @param container The container element to append the toolbar to
19
20
  * @param instance The panzoom instance to control
20
21
  * @param position The position of the toolbar
@@ -44,16 +45,72 @@ const createToolbar = (container, instance, position) => {
44
45
  };
45
46
  // Create and append all buttons
46
47
  const buttons = [
47
- createButton(zoom_in_1.default, 'Zoom in', () => instance.zoomIn()),
48
- createButton(zoom_out_1.default, 'Zoom out', () => instance.zoomOut()),
49
- createButton(zoom_reset_1.default, 'Reset zoom', () => instance.reset()),
48
+ // Zoom in
49
+ createButton(zoom_in_1.default, 'Zoom in', () => {
50
+ instance.zoomIn();
51
+ }),
52
+ // Zoom out
53
+ createButton(zoom_out_1.default, 'Zoom out', () => {
54
+ if (!restrictZoomOutBeyondOrigin) {
55
+ instance.zoomOut();
56
+ return;
57
+ }
58
+ if (instance.getScale() > 1) {
59
+ instance.zoomOut();
60
+ }
61
+ }),
62
+ // Reset zoom
63
+ createButton(zoom_reset_1.default, 'Reset zoom', () => {
64
+ instance.reset();
65
+ }),
50
66
  ];
51
67
  buttons.forEach((button) => toolbar.appendChild(button));
52
68
  container.appendChild(toolbar);
53
69
  };
70
+ /**
71
+ * Attach event listeners to the element where panzoom is applied.
72
+ * The listeners to add are based on the configuration options provided.
73
+ *
74
+ * @param element The element to add event listeners to
75
+ * @param instance The panzoom instance to control
76
+ */
77
+ const addEventListeners = (element, instance) => {
78
+ const handleZoomWithWheel = (event) => {
79
+ if (restrictZoomOutBeyondOrigin) {
80
+ // Allow zooming in or zooming out only to the original size
81
+ if (event.deltaY < 0 || (event.deltaY > 0 && instance.getScale() > 1)) {
82
+ instance.zoomWithWheel(event);
83
+ }
84
+ }
85
+ else {
86
+ instance.zoomWithWheel(event);
87
+ }
88
+ };
89
+ // Handle the wheel zoom functionality if at least one of the options is enabled
90
+ if (enableWheelZoom || enableWheelZoomWithShift) {
91
+ element.addEventListener('wheel', (event) => {
92
+ // Handle zoom with shift key
93
+ if (enableWheelZoomWithShift && event.shiftKey) {
94
+ handleZoomWithWheel(event);
95
+ return;
96
+ }
97
+ // Handle regular zoom
98
+ if (enableWheelZoom && !event.shiftKey) {
99
+ handleZoomWithWheel(event);
100
+ }
101
+ });
102
+ }
103
+ // Handle double-click reset zoom
104
+ if (enableDoubleClickResetZoom) {
105
+ element.addEventListener('dblclick', () => {
106
+ instance.reset();
107
+ });
108
+ }
109
+ };
54
110
  /**
55
111
  * Main work method to zoom the set of elements. You can pass in global options to the pan zoom component
56
112
  * as well as control whether the items will be wrapped.
113
+ *
57
114
  * @param selectors
58
115
  */
59
116
  const zoomElements = (selectors) => {
@@ -69,24 +126,14 @@ const zoomElements = (selectors) => {
69
126
  wrapper.setAttribute('style', 'overflow: hidden; position: relative;');
70
127
  element.parentElement?.insertBefore(wrapper, element);
71
128
  wrapper.appendChild(element);
72
- wrapper.addEventListener('wheel', (event) => {
73
- instance.zoomWithWheel(event);
74
- });
75
- wrapper.addEventListener('dblclick', () => {
76
- instance.reset();
77
- });
78
129
  container = wrapper;
79
130
  }
80
131
  else {
81
- element.style.position = 'relative';
82
- element.addEventListener('wheel', (event) => {
83
- instance.zoomWithWheel(event);
84
- });
85
- element.addEventListener('dblclick', () => {
86
- instance.reset();
87
- });
88
- container = element;
132
+ const htmlElement = element;
133
+ htmlElement.style.position = 'relative';
134
+ container = htmlElement;
89
135
  }
136
+ addEventListeners(container, instance);
90
137
  // Add toolbar if enabled
91
138
  if (enabled) {
92
139
  createToolbar(container, instance, position);
@@ -59,4 +59,35 @@ export type PanZoomPluginOptions = PanzoomOptions & {
59
59
  */
60
60
  opacity?: number;
61
61
  };
62
+ /**
63
+ * Whether to enable zooming with the mouse wheel.
64
+ * If true, the user can zoom in and out using the mouse wheel.
65
+ *
66
+ * default: true
67
+ */
68
+ enableWheelZoom?: boolean;
69
+ /**
70
+ * Whether to enable zooming with the mouse wheel while holding the shift key.
71
+ * If true, the user can zoom in and out using the mouse wheel while holding the shift key.
72
+ *
73
+ * This option is independent of `enableWheelZoom`. Meaning, even if `enableWheelZoom` is false,
74
+ * and `enableWheelZoomWithShift` is true, the user can still zoom using shift + mouse whee.
75
+ * Also, `enableWheelZoom` and `enableWheelZoomWithShift` can be used together.
76
+ *
77
+ * default: false
78
+ */
79
+ enableWheelZoomWithShift?: boolean;
80
+ /**
81
+ * Whether to enable double-click to reset zoom.
82
+ * If true, double-clicking on the panzoom element will reset the zoom level.
83
+ *
84
+ * default: true
85
+ */
86
+ enableDoubleClickResetZoom?: boolean;
87
+ /**
88
+ * Whether to restrict zooming out beyond the original size of the element.
89
+ *
90
+ * default: false
91
+ */
92
+ restrictZoomOutBeyondOrigin?: boolean;
62
93
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@r74tech/docusaurus-plugin-panzoom",
3
- "version": "2.3.0",
3
+ "version": "2.4.0",
4
4
  "description": "A plugin to enable the panzoom component on SVG and other elements",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",