react-zoom-pan-pinch 4.0.0 → 4.0.2

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 (82) hide show
  1. package/package.json +4 -3
  2. package/src/stories/assets/big-image.jpeg +0 -0
  3. package/src/stories/assets/map.jpg +0 -0
  4. package/src/stories/assets/medium-image.jpg +0 -0
  5. package/src/stories/assets/pin.svg +0 -1
  6. package/src/stories/assets/small-image.jpg +0 -0
  7. package/src/stories/assets/svg-example.svg +0 -14
  8. package/src/stories/docs/DocTable.tsx +0 -59
  9. package/src/stories/docs/HandlerCards.tsx +0 -102
  10. package/src/stories/docs/Introduction.stories.mdx +0 -135
  11. package/src/stories/docs/PropTable.tsx +0 -116
  12. package/src/stories/docs/docs.module.css +0 -370
  13. package/src/stories/docs/handlers.stories.mdx +0 -7
  14. package/src/stories/docs/handlers.tsx +0 -111
  15. package/src/stories/docs/props.stories.mdx +0 -11
  16. package/src/stories/docs/props.tsx +0 -571
  17. package/src/stories/examples/axis-lock/axis-lock.stories.mdx +0 -35
  18. package/src/stories/examples/axis-lock/example.tsx +0 -114
  19. package/src/stories/examples/bounds/bounds.data.tsx +0 -191
  20. package/src/stories/examples/bounds/bounds.stories.mdx +0 -99
  21. package/src/stories/examples/center-zoomed-out/center-zoomed-out.stories.mdx +0 -206
  22. package/src/stories/examples/cinema/cinema-data.tsx +0 -578
  23. package/src/stories/examples/cinema/cinema.stories.mdx +0 -30
  24. package/src/stories/examples/cinema/example.tsx +0 -378
  25. package/src/stories/examples/cinema/image.png +0 -0
  26. package/src/stories/examples/content/content.stories.mdx +0 -172
  27. package/src/stories/examples/content/mixed-content.data.tsx +0 -624
  28. package/src/stories/examples/content-rerendering/content-updating.stories.mdx +0 -34
  29. package/src/stories/examples/content-rerendering/example.tsx +0 -631
  30. package/src/stories/examples/controls/controls.stories.mdx +0 -120
  31. package/src/stories/examples/image/example.tsx +0 -149
  32. package/src/stories/examples/image/image.stories.mdx +0 -46
  33. package/src/stories/examples/image-annotations/example.tsx +0 -1442
  34. package/src/stories/examples/image-annotations/image-annotations.stories.mdx +0 -39
  35. package/src/stories/examples/image-responsive/example.tsx +0 -152
  36. package/src/stories/examples/image-responsive/image-responsive.stories.mdx +0 -51
  37. package/src/stories/examples/image-zoomed-out/image-zoomed-out.stories.mdx +0 -107
  38. package/src/stories/examples/initial-transform/example.tsx +0 -233
  39. package/src/stories/examples/initial-transform/initial-transform.stories.mdx +0 -37
  40. package/src/stories/examples/keep-scale/example.tsx +0 -882
  41. package/src/stories/examples/keep-scale/keep-scale.stories.mdx +0 -30
  42. package/src/stories/examples/keep-scale/map.stories.mdx +0 -28
  43. package/src/stories/examples/medical-viewer/chest-xray.tsx +0 -246
  44. package/src/stories/examples/medical-viewer/example.tsx +0 -690
  45. package/src/stories/examples/medical-viewer/medical-viewer.stories.mdx +0 -49
  46. package/src/stories/examples/mini-map/example.tsx +0 -122
  47. package/src/stories/examples/mini-map/mini-map.stories.mdx +0 -26
  48. package/src/stories/examples/miro/example.tsx +0 -1573
  49. package/src/stories/examples/miro/miro.stories.mdx +0 -31
  50. package/src/stories/examples/padding/example.tsx +0 -147
  51. package/src/stories/examples/padding/padding.stories.mdx +0 -35
  52. package/src/stories/examples/product-card/example.tsx +0 -594
  53. package/src/stories/examples/product-card/product-card.stories.mdx +0 -29
  54. package/src/stories/examples/stadium/example.tsx +0 -1040
  55. package/src/stories/examples/stadium/stadium-data.ts +0 -224
  56. package/src/stories/examples/stadium/stadium.stories.mdx +0 -32
  57. package/src/stories/examples/stress/example.tsx +0 -59
  58. package/src/stories/examples/stress/stress-test.stories.mdx +0 -28
  59. package/src/stories/examples/svg-zoom-to-element/creativity.svg +0 -143
  60. package/src/stories/examples/svg-zoom-to-element/example.tsx +0 -95
  61. package/src/stories/examples/svg-zoom-to-element/svg-zoom-to-element.stories.mdx +0 -28
  62. package/src/stories/examples/text-selection/example.tsx +0 -221
  63. package/src/stories/examples/text-selection/text-selection.stories.mdx +0 -31
  64. package/src/stories/examples/velocity/example.tsx +0 -908
  65. package/src/stories/examples/velocity/velocity.stories.mdx +0 -35
  66. package/src/stories/examples/virtualize/example.tsx +0 -239
  67. package/src/stories/examples/virtualize/virtualize.stories.mdx +0 -84
  68. package/src/stories/examples/zoom-to-element/example.tsx +0 -219
  69. package/src/stories/examples/zoom-to-element/zoom-to-element.stories.mdx +0 -31
  70. package/src/stories/hooks/use-controls.stories.mdx +0 -86
  71. package/src/stories/hooks/use-transform-component.stories.mdx +0 -108
  72. package/src/stories/hooks/use-transform-context.stories.mdx +0 -92
  73. package/src/stories/hooks/use-transform-effect.stories.mdx +0 -114
  74. package/src/stories/hooks/use-transform-init.stories.mdx +0 -105
  75. package/src/stories/types/args.types.ts +0 -192
  76. package/src/stories/utils/args.utils.ts +0 -35
  77. package/src/stories/utils/bounds-overlay.tsx +0 -168
  78. package/src/stories/utils/code.utils.tsx +0 -22
  79. package/src/stories/utils/controls.utils.tsx +0 -347
  80. package/src/stories/utils/index.ts +0 -5
  81. package/src/stories/utils/styles.module.css +0 -223
  82. package/src/stories/utils/viewer.styles.ts +0 -34
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-zoom-pan-pinch",
3
- "version": "4.0.0",
3
+ "version": "4.0.2",
4
4
  "packageManager": "yarn@4.9.2",
5
5
  "description": "Zoom and pan html elements in easy way.",
6
6
  "author": "prc5",
@@ -11,11 +11,12 @@
11
11
  "source": "src/index.ts",
12
12
  "files": [
13
13
  "dist",
14
- "src"
14
+ "src",
15
+ "!src/stories"
15
16
  ],
16
17
  "scripts": {
17
18
  "build": "rollup -c",
18
- "build:docs": "storybook build",
19
+ "build:docs": "STORYBOOK_BASE=/react-zoom-pan-pinch/ storybook build",
19
20
  "start": "cross-env DISABLE_ESLINT_PLUGIN=true yarn storybook dev -p 6006",
20
21
  "test": "jest",
21
22
  "test:debug": "jest-preview",
Binary file
Binary file
Binary file
@@ -1 +0,0 @@
1
- <svg enable-background="new 0 0 24 24" height="512" viewBox="0 0 24 24" width="512" xmlns="http://www.w3.org/2000/svg"><path d="m12 0c-4.962 0-9 4.066-9 9.065 0 7.103 8.154 14.437 8.501 14.745.143.127.321.19.499.19s.356-.063.499-.189c.347-.309 8.501-7.643 8.501-14.746 0-4.999-4.038-9.065-9-9.065zm0 14c-2.757 0-5-2.243-5-5s2.243-5 5-5 5 2.243 5 5-2.243 5-5 5z"/></svg>
Binary file
@@ -1,14 +0,0 @@
1
- <svg version="1.1"
2
- baseProfile="full"
3
- width="300" height="200"
4
- xmlns="http://www.w3.org/2000/svg"
5
- id="example-svg"
6
- >
7
-
8
- <rect width="100%" height="100%" fill="red" />
9
-
10
- <circle cx="150" cy="100" r="80" fill="green" />
11
-
12
- <text x="150" y="125" font-size="30" text-anchor="middle" fill="white" id="text-svg">Example</text>
13
-
14
- </svg>
@@ -1,59 +0,0 @@
1
- /* eslint-disable react/no-array-index-key, no-nested-ternary */
2
- import React from "react";
3
-
4
- import styles from "./docs.module.css";
5
-
6
- export type DocTableColumn = {
7
- header: string;
8
- style?: "name" | "type" | "default" | "text";
9
- };
10
-
11
- export function DocTable({
12
- columns,
13
- rows,
14
- }: {
15
- columns: DocTableColumn[];
16
- rows: string[][];
17
- }) {
18
- return (
19
- <table className={styles.docTable}>
20
- <thead>
21
- <tr className={styles.docTableHeadRow}>
22
- {columns.map((col, i) => (
23
- <th key={i} className={styles.docTableTh}>
24
- {col.header}
25
- </th>
26
- ))}
27
- </tr>
28
- </thead>
29
- <tbody>
30
- {rows.map((row, ri) => (
31
- <tr
32
- key={ri}
33
- className={
34
- ri % 2 === 1 ? styles.docTableRowAlt : styles.docTableRow
35
- }
36
- >
37
- {row.map((cell, ci) => {
38
- const colStyle =
39
- columns[ci]?.style ?? (ci === 0 ? "name" : "text");
40
- const cls =
41
- colStyle === "name"
42
- ? styles.docTableCellName
43
- : colStyle === "type"
44
- ? styles.docTableCellType
45
- : colStyle === "default"
46
- ? styles.docTableCellDefault
47
- : styles.docTableCellText;
48
- return (
49
- <td key={ci} className={cls}>
50
- {cell}
51
- </td>
52
- );
53
- })}
54
- </tr>
55
- ))}
56
- </tbody>
57
- </table>
58
- );
59
- }
@@ -1,102 +0,0 @@
1
- /* eslint-disable react/no-array-index-key */
2
- import React from "react";
3
-
4
- import type { ControlsFnOptionsType } from "./handlers";
5
-
6
- import styles from "./docs.module.css";
7
-
8
- function parseParam(raw: string) {
9
- const eqIdx = raw.indexOf("=");
10
- const colonIdx = raw.indexOf(":");
11
-
12
- if (colonIdx === -1) return { name: raw.trim(), type: "", def: "" };
13
-
14
- const name = raw.slice(0, colonIdx).trim();
15
- let type: string;
16
- let def = "";
17
-
18
- if (eqIdx !== -1 && eqIdx > colonIdx) {
19
- type = raw.slice(colonIdx + 1, eqIdx).trim();
20
- def = raw.slice(eqIdx + 1).trim();
21
- } else {
22
- type = raw.slice(colonIdx + 1).trim();
23
- }
24
-
25
- return { name, type, def };
26
- }
27
-
28
- export function HandlerCards({ rows }: { rows: ControlsFnOptionsType[] }) {
29
- return (
30
- <div className={styles.container}>
31
- <div className={styles.sectionTitle}>
32
- <span className={styles.sectionTitleAccent} />
33
- Handlers
34
- </div>
35
- <p className={styles.handlersIntro}>
36
- Methods available via <strong>render props</strong>,{" "}
37
- <strong>ref</strong>, or the{" "}
38
- <span className={styles.handlersIntroHook}>useControls</span> hook. Each
39
- handler triggers an animated transition on the transform state.
40
- </p>
41
-
42
- <div className={styles.handlerGrid}>
43
- {rows.map((row, i) => (
44
- <div key={i} className={styles.handlerCard}>
45
- <div className={styles.handlerCardHeader}>
46
- <span className={styles.handlerName}>
47
- {row.name}(
48
- {row.parameters && row.parameters.length > 0 && (
49
- <span className={styles.handlerNameParams}>
50
- {"{ "}
51
- {row.parameters
52
- .map((raw) => parseParam(raw).name)
53
- .join(", ")}
54
- {" }"}
55
- </span>
56
- )}
57
- )
58
- </span>
59
- <span className={styles.handlerBadge}>Method</span>
60
- </div>
61
-
62
- <div className={styles.handlerCardBody}>
63
- {row.description && (
64
- <p className={styles.handlerDescription}>{row.description}</p>
65
- )}
66
-
67
- {row.parameters && row.parameters.length > 0 && (
68
- <table className={styles.paramsTable}>
69
- <thead>
70
- <tr>
71
- <th className={styles.paramsTableHeader}>Param</th>
72
- <th className={styles.paramsTableHeader}>Type</th>
73
- <th className={styles.paramsTableHeader}>Default</th>
74
- </tr>
75
- </thead>
76
- <tbody>
77
- {row.parameters.map((raw, j) => {
78
- const p = parseParam(raw);
79
- return (
80
- <tr key={j}>
81
- <td className={styles.paramsTableCellName}>
82
- {p.name}
83
- </td>
84
- <td className={styles.paramsTableCellType}>
85
- {p.type}
86
- </td>
87
- <td className={styles.paramsTableCellDefault}>
88
- {p.def || "—"}
89
- </td>
90
- </tr>
91
- );
92
- })}
93
- </tbody>
94
- </table>
95
- )}
96
- </div>
97
- </div>
98
- ))}
99
- </div>
100
- </div>
101
- );
102
- }
@@ -1,135 +0,0 @@
1
- import { Meta } from "@storybook/blocks";
2
-
3
- <Meta title="Docs/Introduction" />
4
-
5
- # React Zoom Pan Pinch
6
-
7
- <p>
8
- <a href="https://bettertyped.com/">
9
- <img src="https://custom-icon-badges.demolab.com/static/v1?label=&message=BetterTyped&color=333&logo=BT" />
10
- </a>
11
- <a href="https://www.npmjs.com/package/react-zoom-pan-pinch">
12
- <img src="https://custom-icon-badges.demolab.com/npm/v/react-zoom-pan-pinch.svg?logo=npm&color=e22121" />
13
- </a>
14
- <a href="https://github.com/prc5/react-zoom-pan-pinch">
15
- <img src="https://custom-icon-badges.demolab.com/github/stars/prc5/react-zoom-pan-pinch?logo=star" />
16
- </a>
17
- <a href="https://github.com/prc5/react-zoom-pan-pinch/blob/main/License.md">
18
- <img src="https://custom-icon-badges.demolab.com/github/license/prc5/react-zoom-pan-pinch?logo=law&color=yellow" />
19
- </a>
20
- <a href="https://www.npmjs.com/package/react-zoom-pan-pinch">
21
- <img src="https://custom-icon-badges.demolab.com/npm/dm/react-zoom-pan-pinch?logoColor=fff&logo=trending-up" />
22
- </a>
23
- <a href="https://www.npmjs.com/package/react-zoom-pan-pinch">
24
- <img src="https://custom-icon-badges.demolab.com/bundlephobia/minzip/react-zoom-pan-pinch?color=E10098&logo=package" />
25
- </a>
26
- <a href="https://github.com/prc5/react-zoom-pan-pinch">
27
- <img src="https://custom-icon-badges.demolab.com/badge/typescript-%23007ACC.svg?logo=typescript&logoColor=white" />
28
- </a>
29
- </p>
30
-
31
- > Super fast and light React library for zooming, panning, and pinching HTML
32
- > elements with ease.
33
-
34
- ## Key Features
35
-
36
- - **Fast and lightweight** — no external dependencies
37
- - **Touch, trackpad, and mouse** — full gesture support across devices
38
- - **Render props and hooks** — flexible API for any component architecture
39
- - **Highly customizable** — animations, bounds, velocity, padding, and more
40
- - **Advanced components** — `KeepScale`, `MiniMap`, and programmatic controls
41
-
42
- ## Installation
43
-
44
- ```bash
45
- npm install react-zoom-pan-pinch
46
- ```
47
-
48
- or
49
-
50
- ```bash
51
- yarn add react-zoom-pan-pinch
52
- ```
53
-
54
- ## Quick Start
55
-
56
- The simplest setup — wrap any content with `TransformWrapper` and
57
- `TransformComponent`:
58
-
59
- ```tsx
60
- import { TransformWrapper, TransformComponent } from "react-zoom-pan-pinch";
61
-
62
- const App = () => (
63
- <TransformWrapper>
64
- <TransformComponent>
65
- <img src="image.jpg" alt="Zoomable" />
66
- </TransformComponent>
67
- </TransformWrapper>
68
- );
69
- ```
70
-
71
- ## With Controls (Render Props)
72
-
73
- Access zoom/pan handlers through render props:
74
-
75
- ```tsx
76
- import { TransformWrapper, TransformComponent } from "react-zoom-pan-pinch";
77
-
78
- const App = () => (
79
- <TransformWrapper initialScale={1} initialPositionX={200} initialPositionY={100}>
80
- {({ zoomIn, zoomOut, resetTransform }) => (
81
- <>
82
- <div className="tools">
83
- <button onClick={() => zoomIn()}>+</button>
84
- <button onClick={() => zoomOut()}>-</button>
85
- <button onClick={() => resetTransform()}>x</button>
86
- </div>
87
- <TransformComponent>
88
- <img src="image.jpg" alt="Zoomable" />
89
- </TransformComponent>
90
- </>
91
- )}
92
- </TransformWrapper>
93
- );
94
- ```
95
-
96
- ## With Ref and zoomToElement
97
-
98
- Use a ref for imperative access outside of render props:
99
-
100
- ```tsx
101
- import { useRef } from "react";
102
- import {
103
- TransformWrapper,
104
- TransformComponent,
105
- ReactZoomPanPinchRef,
106
- } from "react-zoom-pan-pinch";
107
-
108
- const App = () => {
109
- const ref = useRef<ReactZoomPanPinchRef | null>(null);
110
-
111
- const focusImage = () => {
112
- ref.current?.zoomToElement("imgExample");
113
- };
114
-
115
- return (
116
- <TransformWrapper ref={ref}>
117
- {({ zoomIn, zoomOut, resetTransform }) => (
118
- <>
119
- <button onClick={() => zoomIn()}>+</button>
120
- <button onClick={() => zoomOut()}>-</button>
121
- <button onClick={() => resetTransform()}>x</button>
122
- <TransformComponent>
123
- <img src="image.jpg" alt="Zoomable" id="imgExample" />
124
- <div onClick={focusImage}>Focus image</div>
125
- </TransformComponent>
126
- </>
127
- )}
128
- </TransformWrapper>
129
- );
130
- };
131
- ```
132
-
133
- ## License
134
-
135
- MIT © [prc5](https://github.com/prc5)
@@ -1,116 +0,0 @@
1
- /* eslint-disable react/no-array-index-key, no-nested-ternary, no-plusplus */
2
- import React from "react";
3
-
4
- import type { ControlsOptionsType } from "./props";
5
-
6
- import styles from "./docs.module.css";
7
-
8
- type Group = {
9
- header: ControlsOptionsType | null;
10
- children: ControlsOptionsType[];
11
- };
12
-
13
- export function PropTable({
14
- rows,
15
- title,
16
- }: {
17
- rows: ControlsOptionsType[];
18
- title: string;
19
- }) {
20
- const groups: Group[] = [];
21
- let current: Group | null = null;
22
-
23
- rows.forEach((row) => {
24
- if (row.isObjectRow) {
25
- current = { header: row, children: [] };
26
- groups.push(current);
27
- } else if (current) {
28
- current.children.push(row);
29
- } else {
30
- groups.push({ header: null, children: [row] });
31
- }
32
- });
33
-
34
- let rowIndex = 0;
35
-
36
- return (
37
- <div className={styles.container}>
38
- <div className={styles.sectionTitle}>
39
- <span className={styles.sectionTitleAccent} />
40
- {title}
41
- </div>
42
-
43
- <div className={styles.columnHeader}>
44
- <span>Property</span>
45
- <span>Type</span>
46
- <span>Default</span>
47
- <span>Description</span>
48
- </div>
49
-
50
- {groups.map((group, gi) => {
51
- if (group.header) rowIndex = 0;
52
- return (
53
- <div key={gi}>
54
- {group.header && (
55
- <div className={styles.groupHeader}>
56
- <span className={styles.groupName}>
57
- {typeof group.header.name === "string"
58
- ? group.header.name
59
- : (
60
- group.header.name as React.ReactElement<{
61
- children?: React.ReactNode;
62
- }>
63
- )?.props?.children ?? ""}
64
- </span>
65
- {group.children.length > 0 && (
66
- <span className={styles.groupCount}>
67
- {group.children.length} props
68
- </span>
69
- )}
70
- </div>
71
- )}
72
-
73
- {group.children.map((row, ri) => {
74
- const isNested = !!group.header;
75
- const propName = typeof row.name === "string" ? row.name : null;
76
- const isAlt = rowIndex++ % 2 === 1;
77
-
78
- const rowClass = isNested
79
- ? isAlt
80
- ? styles.propRowNestedAlt
81
- : styles.propRowNested
82
- : isAlt
83
- ? styles.propRowAlt
84
- : styles.propRow;
85
-
86
- return (
87
- <div key={ri} className={rowClass}>
88
- <span className={styles.propName}>
89
- {isNested && <span className={styles.nestDot}>.</span>}
90
- {propName ?? row.name}
91
- </span>
92
-
93
- <span className={styles.typeText}>
94
- {row.type.filter(Boolean).join(" | ")}
95
- </span>
96
-
97
- <span>
98
- {row.defaultValue && row.defaultValue !== "" ? (
99
- <span className={styles.defaultText}>
100
- {row.defaultValue}
101
- </span>
102
- ) : (
103
- <span className={styles.defaultEmpty}>—</span>
104
- )}
105
- </span>
106
-
107
- <span className={styles.description}>{row.description}</span>
108
- </div>
109
- );
110
- })}
111
- </div>
112
- );
113
- })}
114
- </div>
115
- );
116
- }