@r74tech/docusaurus-plugin-panzoom 2.2.0 → 2.3.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/.prettierrc ADDED
@@ -0,0 +1,12 @@
1
+ {
2
+ "semi": true,
3
+ "tabWidth": 2,
4
+ "printWidth": 120,
5
+ "singleQuote": true,
6
+ "trailingComma": "all",
7
+ "jsxSingleQuote": true,
8
+ "bracketSpacing": true,
9
+ "bracketSameLine": false,
10
+ "endOfLine": "lf",
11
+ "proseWrap": "always"
12
+ }
package/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ # [2.3.0](https://github.com/r74tech/docusaurus-plugin-panzoom/compare/v2.2.0...v2.3.0) (2025-07-17)
2
+
3
+
4
+ ### Features
5
+
6
+ * add toolbar to control zooming (zoom in, zoom out, reset) ([a170e52](https://github.com/r74tech/docusaurus-plugin-panzoom/commit/a170e5253e2bf5b1ddb12bf7b0e648722b053bcb))
7
+ * merge all toolbar props into a single object ([0c32e6c](https://github.com/r74tech/docusaurus-plugin-panzoom/commit/0c32e6c361563ad81517818c99693a9de717f33f))
8
+
1
9
  # [2.2.0](https://github.com/r74tech/docusaurus-plugin-panzoom/compare/v2.1.0...v2.2.0) (2025-07-12)
2
10
 
3
11
 
package/dist/PanZoom.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import type { ClientModule } from '@docusaurus/types';
2
+ import './styles/panzoom.css';
2
3
  /**
3
4
  * Client module implementation. Wait a bit before trying this, some components like mermaid take a second to process / render
4
5
  */
package/dist/PanZoom.js CHANGED
@@ -4,10 +4,53 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const panzoom_1 = __importDefault(require("@panzoom/panzoom"));
7
+ const PanzoomPluginOptions_1 = require("./PanzoomPluginOptions");
8
+ const zoom_in_1 = __importDefault(require("./img/zoom-in"));
9
+ const zoom_out_1 = __importDefault(require("./img/zoom-out"));
10
+ const zoom_reset_1 = __importDefault(require("./img/zoom-reset"));
11
+ require("./styles/panzoom.css");
7
12
  const config = require('@generated/docusaurus.config').default;
8
13
  const { themeConfig } = config;
9
14
  const { zoom } = themeConfig;
10
- const { selectors = ['div.mermaid[data-processed="true"]', 'div.docusaurus-mermaid-container', '.drawio'], wrap = true, timeout = 1000, excludeClass = 'panzoom-exclude', ...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 } = {}, ...panZoomConfig } = zoom;
16
+ /**
17
+ * Creates a toolbar with zoom controls for a panzoom instance
18
+ * @param container The container element to append the toolbar to
19
+ * @param instance The panzoom instance to control
20
+ * @param position The position of the toolbar
21
+ */
22
+ const createToolbar = (container, instance, position) => {
23
+ const toolbar = document.createElement('div');
24
+ toolbar.className = `panzoom-toolbar panzoom-toolbar-${position} ${excludeClass}`;
25
+ // Apply custom opacity from configuration
26
+ toolbar.style.opacity = opacity.toString();
27
+ // Prevent double-click events from bubbling up to the container
28
+ // By default the panzoom library will reset on double click
29
+ toolbar.addEventListener('dblclick', (e) => {
30
+ e.stopPropagation();
31
+ });
32
+ // Helper function to create toolbar buttons
33
+ const createButton = (svg, title, action) => {
34
+ const button = document.createElement('button');
35
+ button.innerHTML = svg;
36
+ button.title = title;
37
+ button.className = excludeClass;
38
+ button.addEventListener('click', (e) => {
39
+ e.preventDefault();
40
+ e.stopPropagation();
41
+ action();
42
+ });
43
+ return button;
44
+ };
45
+ // Create and append all buttons
46
+ 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()),
50
+ ];
51
+ buttons.forEach((button) => toolbar.appendChild(button));
52
+ container.appendChild(toolbar);
53
+ };
11
54
  /**
12
55
  * Main work method to zoom the set of elements. You can pass in global options to the pan zoom component
13
56
  * as well as control whether the items will be wrapped.
@@ -20,25 +63,33 @@ const zoomElements = (selectors) => {
20
63
  });
21
64
  foundElements.forEach((element) => {
22
65
  const instance = (0, panzoom_1.default)(element, { excludeClass, ...panZoomConfig });
66
+ let container;
23
67
  if (wrap) {
24
68
  const wrapper = document.createElement('div');
25
- wrapper.setAttribute('style', "overflow: hidden");
69
+ wrapper.setAttribute('style', 'overflow: hidden; position: relative;');
26
70
  element.parentElement?.insertBefore(wrapper, element);
27
71
  wrapper.appendChild(element);
28
72
  wrapper.addEventListener('wheel', (event) => {
29
73
  instance.zoomWithWheel(event);
30
74
  });
31
- wrapper.addEventListener('dblclick', (event) => {
75
+ wrapper.addEventListener('dblclick', () => {
32
76
  instance.reset();
33
77
  });
78
+ container = wrapper;
34
79
  }
35
- if (!wrap) {
80
+ else {
81
+ element.style.position = 'relative';
36
82
  element.addEventListener('wheel', (event) => {
37
83
  instance.zoomWithWheel(event);
38
84
  });
39
- element.addEventListener('dblclick', (event) => {
85
+ element.addEventListener('dblclick', () => {
40
86
  instance.reset();
41
87
  });
88
+ container = element;
89
+ }
90
+ // Add toolbar if enabled
91
+ if (enabled) {
92
+ createToolbar(container, instance, position);
42
93
  }
43
94
  });
44
95
  };
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.validatedThemeConfig = exports.PanZoomPlugin = void 0;
4
4
  const utils_validation_1 = require("@docusaurus/utils-validation");
5
+ const PanzoomPluginOptions_1 = require("./PanzoomPluginOptions");
5
6
  const path_1 = require("path");
6
7
  /**
7
8
  * Main module for the PanZoom plugin
@@ -11,15 +12,15 @@ const path_1 = require("path");
11
12
  */
12
13
  const PanZoomPlugin = (context, options) => {
13
14
  return {
14
- name: "docusaurus-plugin-panzoom",
15
+ name: 'docusaurus-plugin-panzoom',
15
16
  getClientModules() {
16
- return [
17
- (0, path_1.resolve)(__dirname, "./PanZoom")
18
- ];
19
- }
17
+ return [(0, path_1.resolve)(__dirname, './PanZoom'), (0, path_1.resolve)(__dirname, './styles/panzoom.css')];
18
+ },
20
19
  };
21
20
  };
22
21
  exports.PanZoomPlugin = PanZoomPlugin;
22
+ // Extract the valid toolbar position values from the enum
23
+ const validToolbarPositions = Object.values(PanzoomPluginOptions_1.PanZoomPluginToolbarPosition);
23
24
  /**
24
25
  * Theme validation rules for this plugin
25
26
  */
@@ -29,7 +30,12 @@ const panZoomValidator = utils_validation_1.Joi.object({
29
30
  wrap: utils_validation_1.Joi.boolean(),
30
31
  timeout: utils_validation_1.Joi.number(),
31
32
  excludeClass: utils_validation_1.Joi.string(),
32
- })
33
+ toolbar: utils_validation_1.Joi.object({
34
+ enabled: utils_validation_1.Joi.boolean(),
35
+ position: utils_validation_1.Joi.string().valid(...validToolbarPositions),
36
+ opacity: utils_validation_1.Joi.number().min(0).max(1),
37
+ }),
38
+ }),
33
39
  });
34
40
  /**
35
41
  * Add a validation for the theme configuration
@@ -1,4 +1,10 @@
1
1
  import type { PanzoomOptions } from '@panzoom/panzoom';
2
+ export declare enum PanZoomPluginToolbarPosition {
3
+ TopRight = "top-right",
4
+ TopLeft = "top-left",
5
+ BottomRight = "bottom-right",
6
+ BottomLeft = "bottom-left"
7
+ }
2
8
  export type PanZoomPluginOptions = PanzoomOptions & {
3
9
  /**
4
10
  * A list of selectors to look for elements to enable pan and zoom
@@ -28,4 +34,29 @@ export type PanZoomPluginOptions = PanzoomOptions & {
28
34
  * default: 'panzoom-exclude'
29
35
  */
30
36
  excludeClass?: string;
37
+ /**
38
+ * Toolbar options for the Panzoom plugin.
39
+ */
40
+ toolbar?: {
41
+ /**
42
+ * Whether to enable and show a control toolbar with buttons for zoom in, zoom out, and reset.
43
+ *
44
+ * default: false
45
+ */
46
+ enabled?: boolean;
47
+ /**
48
+ * The toolbar position (top-right, top-left, bottom-right, bottom-left)
49
+ *
50
+ * default: 'top-right'
51
+ */
52
+ position?: PanZoomPluginToolbarPosition;
53
+ /**
54
+ * The toolbar opacity when not hovered (value between 0 and 1)
55
+ * The toolbar will become fully opaque (opacity: 1) when hovered.
56
+ *
57
+ * example: 0.5
58
+ * default: 0
59
+ */
60
+ opacity?: number;
61
+ };
31
62
  };
@@ -1,2 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PanZoomPluginToolbarPosition = void 0;
4
+ var PanZoomPluginToolbarPosition;
5
+ (function (PanZoomPluginToolbarPosition) {
6
+ PanZoomPluginToolbarPosition["TopRight"] = "top-right";
7
+ PanZoomPluginToolbarPosition["TopLeft"] = "top-left";
8
+ PanZoomPluginToolbarPosition["BottomRight"] = "bottom-right";
9
+ PanZoomPluginToolbarPosition["BottomLeft"] = "bottom-left";
10
+ })(PanZoomPluginToolbarPosition = exports.PanZoomPluginToolbarPosition || (exports.PanZoomPluginToolbarPosition = {}));
@@ -0,0 +1,2 @@
1
+ declare const _default: "<svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\" viewBox=\"0 -960 960 960\" width=\"24px\" fill=\"#000\"><path d=\"M450-450H220v-60h230v-230h60v230h230v60H510v230h-60v-230Z\"/></svg>";
2
+ export default _default;
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = '<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#000"><path d="M450-450H220v-60h230v-230h60v230h230v60H510v230h-60v-230Z"/></svg>';
@@ -0,0 +1,2 @@
1
+ declare const _default: "<svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\" viewBox=\"0 -960 960 960\" width=\"24px\" fill=\"#000\"><path d=\"M220-450v-60h520v60H220Z\"/></svg>";
2
+ export default _default;
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = '<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#000"><path d="M220-450v-60h520v60H220Z"/></svg>';
@@ -0,0 +1,2 @@
1
+ declare const _default: "<svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\" viewBox=\"0 -960 960 960\" width=\"24px\" fill=\"#000\"><path d=\"M480-333.85v-91.92q0-22.6 15.82-38.41Q511.63-480 534.23-480h91.92v47.69h-98.46v98.46H480ZM534.23-100q-22.6 0-38.41-15.82Q480-131.64 480-154.23v-91.92h47.69v98.46h98.46V-100h-91.92Zm278.08-233.85v-98.46h-98.46V-480h91.92q22.59 0 38.41 15.82Q860-448.37 860-425.77v91.92h-47.69ZM713.85-100v-47.69h98.46v-98.46H860v91.92q0 22.59-15.82 38.41Q828.36-100 805.77-100h-91.92Zm94.07-467.69h-62.23q-27.54-84.54-99.57-138.43Q574.08-760 480-760q-117 0-198.5 81.5T200-480q0 78.15 38.46 141.81 38.46 63.65 101.54 99.34V-360h60v220H180v-60h113.23q-69.3-45-111.27-118.27Q140-391.54 140-480q0-70.8 26.77-132.63t72.77-107.83q46-46 107.83-72.77Q409.2-820 480-820q118.61 0 208.81 71.42Q779-677.15 807.92-567.69Z\"/></svg>";
2
+ export default _default;
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = '<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#000"><path d="M480-333.85v-91.92q0-22.6 15.82-38.41Q511.63-480 534.23-480h91.92v47.69h-98.46v98.46H480ZM534.23-100q-22.6 0-38.41-15.82Q480-131.64 480-154.23v-91.92h47.69v98.46h98.46V-100h-91.92Zm278.08-233.85v-98.46h-98.46V-480h91.92q22.59 0 38.41 15.82Q860-448.37 860-425.77v91.92h-47.69ZM713.85-100v-47.69h98.46v-98.46H860v91.92q0 22.59-15.82 38.41Q828.36-100 805.77-100h-91.92Zm94.07-467.69h-62.23q-27.54-84.54-99.57-138.43Q574.08-760 480-760q-117 0-198.5 81.5T200-480q0 78.15 38.46 141.81 38.46 63.65 101.54 99.34V-360h60v220H180v-60h113.23q-69.3-45-111.27-118.27Q140-391.54 140-480q0-70.8 26.77-132.63t72.77-107.83q46-46 107.83-72.77Q409.2-820 480-820q118.61 0 208.81 71.42Q779-677.15 807.92-567.69Z"/></svg>';
@@ -0,0 +1,48 @@
1
+ .panzoom-toolbar {
2
+ position: absolute;
3
+ z-index: 10;
4
+ display: flex;
5
+ gap: 5px;
6
+ padding: 5px;
7
+ background: rgba(255, 255, 255, 0.5);
8
+ border-radius: 4px;
9
+ transition: opacity 0.2s ease-in-out;
10
+ }
11
+
12
+ *:hover > .panzoom-toolbar {
13
+ opacity: 1 !important;
14
+ }
15
+
16
+ .panzoom-toolbar-top-right {
17
+ top: 10px;
18
+ right: 10px;
19
+ }
20
+
21
+ .panzoom-toolbar-top-left {
22
+ top: 10px;
23
+ left: 10px;
24
+ }
25
+
26
+ .panzoom-toolbar-bottom-right {
27
+ bottom: 10px;
28
+ right: 10px;
29
+ }
30
+
31
+ .panzoom-toolbar-bottom-left {
32
+ bottom: 10px;
33
+ left: 10px;
34
+ }
35
+
36
+ .panzoom-toolbar button {
37
+ width: 30px;
38
+ height: 30px;
39
+ cursor: pointer;
40
+ border: 1px solid #ddd;
41
+ border-radius: 3px;
42
+ background-color: #fff;
43
+ padding: 0;
44
+ margin: 0;
45
+ display: flex;
46
+ justify-content: center;
47
+ align-items: center;
48
+ }
@@ -0,0 +1,32 @@
1
+ import js from '@eslint/js';
2
+ import tsParser from '@typescript-eslint/parser';
3
+ import tseslint from '@typescript-eslint/eslint-plugin';
4
+ import globals from 'globals';
5
+ import prettierPlugin from 'eslint-plugin-prettier';
6
+
7
+ export default [
8
+ {
9
+ files: ['src/**/*.{ts,css}'],
10
+ ignores: ['**/dist/**', '**/node_modules/**'],
11
+ languageOptions: {
12
+ ecmaVersion: 2020,
13
+ sourceType: 'module',
14
+ globals: {
15
+ ...globals.node,
16
+ ...globals.browser,
17
+ },
18
+ parser: tsParser,
19
+ },
20
+ plugins: {
21
+ '@typescript-eslint': tseslint,
22
+ prettier: prettierPlugin,
23
+ },
24
+ rules: {
25
+ ...js.configs.recommended.rules,
26
+ ...tseslint.configs.recommended.rules,
27
+ 'prettier/prettier': 'error',
28
+ '@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '^_' }],
29
+ '@typescript-eslint/explicit-module-boundary-types': 'off',
30
+ },
31
+ },
32
+ ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@r74tech/docusaurus-plugin-panzoom",
3
- "version": "2.2.0",
3
+ "version": "2.3.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",
@@ -15,8 +15,12 @@
15
15
  "author": "r74tech",
16
16
  "license": "MIT",
17
17
  "scripts": {
18
- "build": "tsc",
19
- "prepublishOnly": "npm run build"
18
+ "build": "tsc && npm run copy-assets",
19
+ "copy-assets": "mkdir -p dist/styles && cp -r src/styles/* dist/styles/",
20
+ "prepublishOnly": "npm run build",
21
+ "lint": "eslint 'src/**/*.{ts,css}' --report-unused-disable-directives --max-warnings 0",
22
+ "lint:fix": "eslint --fix 'src/**/*.{ts,css}'",
23
+ "format": "prettier --write --no-error-on-unmatched-pattern 'src/**/*.{ts,css}' --config ./.prettierrc"
20
24
  },
21
25
  "dependencies": {
22
26
  "@docusaurus/utils-validation": "^3.7.0",
@@ -24,6 +28,8 @@
24
28
  },
25
29
  "devDependencies": {
26
30
  "@docusaurus/types": "^3.7.0",
31
+ "@eslint/compat": "^1.2.3",
32
+ "@eslint/js": "^9.14.0",
27
33
  "@semantic-release/changelog": "^6.0.3",
28
34
  "@semantic-release/commit-analyzer": "^9.0.2",
29
35
  "@semantic-release/git": "^10.0.1",
@@ -32,10 +38,19 @@
32
38
  "@semantic-release/release-notes-generator": "^10.0.3",
33
39
  "@tsconfig/docusaurus": "^1.0.7",
34
40
  "@types/node": "^22.14.0",
41
+ "@typescript-eslint/eslint-plugin": "^8.36.0",
42
+ "@typescript-eslint/parser": "^8.13.0",
43
+ "eslint": "^9.14.0",
44
+ "eslint-config-prettier": "^9.1.0",
45
+ "eslint-plugin-prettier": "^5.5.1",
46
+ "globals": "^15.12.0",
47
+ "lint-staged": "^15.2.10",
48
+ "prettier": "^3.3.3",
35
49
  "react": "^18.3.1",
36
50
  "react-dom": "^18.3.1",
37
51
  "semantic-release": "^24.2.3",
38
- "typescript": "^4.9.5"
52
+ "typescript": "^4.9.5",
53
+ "typescript-eslint": "^8.13.0"
39
54
  },
40
55
  "release": {
41
56
  "plugins": [
@@ -79,5 +94,10 @@
79
94
  "type": "git",
80
95
  "url": "git+https://github.com/r74tech/docusaurus-plugin-panzoom.git"
81
96
  },
82
- "sideEffects": false
97
+ "sideEffects": false,
98
+ "lint-staged": {
99
+ "src/**/*.{ts,css}": [
100
+ "prettier --write --no-error-on-unmatched-pattern --config ./.prettierrc"
101
+ ]
102
+ }
83
103
  }