react-zoom-pan-pinch 3.6.1 → 4.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 (139) hide show
  1. package/dist/index.cjs.js +770 -277
  2. package/dist/index.cjs.js.map +1 -1
  3. package/dist/index.d.ts +116 -22
  4. package/dist/index.esm.js +766 -269
  5. package/dist/index.esm.js.map +1 -1
  6. package/package.json +73 -60
  7. package/src/components/index.ts +5 -0
  8. package/src/components/keep-scale/keep-scale.tsx +28 -0
  9. package/src/components/mini-map/mini-map.tsx +292 -0
  10. package/src/components/mini-map/use-resize.hook.ts +74 -0
  11. package/src/components/transform-component/transform-component.module.css +43 -0
  12. package/src/components/transform-component/transform-component.tsx +96 -0
  13. package/src/components/transform-wrapper/transform-wrapper.tsx +39 -0
  14. package/src/components/virtualize/virtualize.tsx +133 -0
  15. package/src/components/virtualize/virtualize.utils.ts +104 -0
  16. package/src/constants/state.constants.ts +99 -0
  17. package/src/core/animations/animations.constants.ts +78 -0
  18. package/src/core/animations/animations.utils.ts +115 -0
  19. package/src/core/bounds/bounds.types.ts +8 -0
  20. package/src/core/bounds/bounds.utils.ts +226 -0
  21. package/src/core/double-click/double-click.logic.ts +127 -0
  22. package/src/core/handlers/handlers.logic.ts +122 -0
  23. package/src/core/handlers/handlers.utils.ts +243 -0
  24. package/src/core/instance.core.ts +704 -0
  25. package/src/core/pan/panning.logic.ts +122 -0
  26. package/src/core/pan/panning.utils.ts +216 -0
  27. package/src/core/pan/velocity.logic.ts +187 -0
  28. package/src/core/pan/velocity.utils.ts +83 -0
  29. package/src/core/pinch/pinch.logic.ts +139 -0
  30. package/src/core/pinch/pinch.utils.ts +95 -0
  31. package/src/core/wheel/wheel.logic.ts +161 -0
  32. package/src/core/wheel/wheel.utils.ts +157 -0
  33. package/src/core/zoom/zoom.logic.ts +71 -0
  34. package/src/core/zoom/zoom.utils.ts +62 -0
  35. package/src/hooks/index.ts +5 -0
  36. package/src/hooks/use-controls.tsx +9 -0
  37. package/src/hooks/use-transform-component.tsx +30 -0
  38. package/src/hooks/use-transform-context.tsx +13 -0
  39. package/src/hooks/use-transform-effect.tsx +22 -0
  40. package/src/hooks/use-transform-init.tsx +28 -0
  41. package/src/hooks/use-zoom-pan-pinch.tsx +48 -0
  42. package/src/index.ts +6 -0
  43. package/src/models/calculations.model.ts +34 -0
  44. package/src/models/context.model.ts +218 -0
  45. package/src/models/helpers.model.ts +15 -0
  46. package/src/models/index.ts +3 -0
  47. package/src/react-app-env.d.ts +1 -0
  48. package/src/stories/assets/big-image.jpeg +0 -0
  49. package/src/stories/assets/map.jpg +0 -0
  50. package/src/stories/assets/medium-image.jpg +0 -0
  51. package/src/stories/assets/pin.svg +1 -0
  52. package/src/stories/assets/small-image.jpg +0 -0
  53. package/src/stories/assets/svg-example.svg +14 -0
  54. package/src/stories/docs/DocTable.tsx +59 -0
  55. package/src/stories/docs/HandlerCards.tsx +102 -0
  56. package/src/stories/docs/Introduction.stories.mdx +135 -0
  57. package/src/stories/docs/PropTable.tsx +116 -0
  58. package/src/stories/docs/docs.module.css +370 -0
  59. package/src/stories/docs/handlers.stories.mdx +7 -0
  60. package/src/stories/docs/handlers.tsx +111 -0
  61. package/src/stories/docs/props.stories.mdx +11 -0
  62. package/src/stories/docs/props.tsx +571 -0
  63. package/src/stories/examples/axis-lock/axis-lock.stories.mdx +35 -0
  64. package/src/stories/examples/axis-lock/example.tsx +114 -0
  65. package/src/stories/examples/bounds/bounds.data.tsx +191 -0
  66. package/src/stories/examples/bounds/bounds.stories.mdx +99 -0
  67. package/src/stories/examples/center-zoomed-out/center-zoomed-out.stories.mdx +206 -0
  68. package/src/stories/examples/cinema/cinema-data.tsx +578 -0
  69. package/src/stories/examples/cinema/cinema.stories.mdx +30 -0
  70. package/src/stories/examples/cinema/example.tsx +378 -0
  71. package/src/stories/examples/cinema/image.png +0 -0
  72. package/src/stories/examples/content/content.stories.mdx +172 -0
  73. package/src/stories/examples/content/mixed-content.data.tsx +624 -0
  74. package/src/stories/examples/content-rerendering/content-updating.stories.mdx +34 -0
  75. package/src/stories/examples/content-rerendering/example.tsx +631 -0
  76. package/src/stories/examples/controls/controls.stories.mdx +120 -0
  77. package/src/stories/examples/image/example.tsx +149 -0
  78. package/src/stories/examples/image/image.stories.mdx +46 -0
  79. package/src/stories/examples/image-annotations/example.tsx +1442 -0
  80. package/src/stories/examples/image-annotations/image-annotations.stories.mdx +39 -0
  81. package/src/stories/examples/image-responsive/example.tsx +152 -0
  82. package/src/stories/examples/image-responsive/image-responsive.stories.mdx +51 -0
  83. package/src/stories/examples/image-zoomed-out/image-zoomed-out.stories.mdx +107 -0
  84. package/src/stories/examples/initial-transform/example.tsx +233 -0
  85. package/src/stories/examples/initial-transform/initial-transform.stories.mdx +37 -0
  86. package/src/stories/examples/keep-scale/example.tsx +882 -0
  87. package/src/stories/examples/keep-scale/keep-scale.stories.mdx +30 -0
  88. package/src/stories/examples/keep-scale/map.stories.mdx +28 -0
  89. package/src/stories/examples/medical-viewer/chest-xray.tsx +246 -0
  90. package/src/stories/examples/medical-viewer/example.tsx +690 -0
  91. package/src/stories/examples/medical-viewer/medical-viewer.stories.mdx +49 -0
  92. package/src/stories/examples/mini-map/example.tsx +122 -0
  93. package/src/stories/examples/mini-map/mini-map.stories.mdx +26 -0
  94. package/src/stories/examples/miro/example.tsx +1573 -0
  95. package/src/stories/examples/miro/miro.stories.mdx +31 -0
  96. package/src/stories/examples/padding/example.tsx +147 -0
  97. package/src/stories/examples/padding/padding.stories.mdx +35 -0
  98. package/src/stories/examples/product-card/example.tsx +594 -0
  99. package/src/stories/examples/product-card/product-card.stories.mdx +29 -0
  100. package/src/stories/examples/stadium/example.tsx +1040 -0
  101. package/src/stories/examples/stadium/stadium-data.ts +224 -0
  102. package/src/stories/examples/stadium/stadium.stories.mdx +32 -0
  103. package/src/stories/examples/stress/example.tsx +59 -0
  104. package/src/stories/examples/stress/stress-test.stories.mdx +28 -0
  105. package/src/stories/examples/svg-zoom-to-element/creativity.svg +143 -0
  106. package/src/stories/examples/svg-zoom-to-element/example.tsx +95 -0
  107. package/src/stories/examples/svg-zoom-to-element/svg-zoom-to-element.stories.mdx +28 -0
  108. package/src/stories/examples/text-selection/example.tsx +221 -0
  109. package/src/stories/examples/text-selection/text-selection.stories.mdx +31 -0
  110. package/src/stories/examples/velocity/example.tsx +908 -0
  111. package/src/stories/examples/velocity/velocity.stories.mdx +35 -0
  112. package/src/stories/examples/virtualize/example.tsx +239 -0
  113. package/src/stories/examples/virtualize/virtualize.stories.mdx +84 -0
  114. package/src/stories/examples/zoom-to-element/example.tsx +219 -0
  115. package/src/stories/examples/zoom-to-element/zoom-to-element.stories.mdx +31 -0
  116. package/src/stories/hooks/use-controls.stories.mdx +86 -0
  117. package/src/stories/hooks/use-transform-component.stories.mdx +108 -0
  118. package/src/stories/hooks/use-transform-context.stories.mdx +92 -0
  119. package/src/stories/hooks/use-transform-effect.stories.mdx +114 -0
  120. package/src/stories/hooks/use-transform-init.stories.mdx +105 -0
  121. package/src/stories/types/args.types.ts +192 -0
  122. package/src/stories/utils/args.utils.ts +35 -0
  123. package/src/stories/utils/bounds-overlay.tsx +168 -0
  124. package/src/stories/utils/code.utils.tsx +22 -0
  125. package/src/stories/utils/controls.utils.tsx +347 -0
  126. package/src/stories/utils/index.ts +5 -0
  127. package/src/stories/utils/styles.module.css +223 -0
  128. package/src/stories/utils/viewer.styles.ts +34 -0
  129. package/src/styles.css +8 -0
  130. package/src/typings.d.ts +21 -0
  131. package/src/utils/calculations.utils.ts +16 -0
  132. package/src/utils/callback.utils.ts +11 -0
  133. package/src/utils/context.utils.ts +49 -0
  134. package/src/utils/event.utils.ts +38 -0
  135. package/src/utils/helpers.utils.ts +22 -0
  136. package/src/utils/index.ts +8 -0
  137. package/src/utils/ref.utils.ts +32 -0
  138. package/src/utils/state.utils.ts +77 -0
  139. package/src/utils/styles.utils.ts +49 -0
@@ -0,0 +1,31 @@
1
+ import { Meta, Story, ArgsTable, Canvas } from "@storybook/blocks";
2
+
3
+ import { TransformWrapper } from "../../../components";
4
+ import { argsTypes } from "../../types/args.types.ts";
5
+ import { Example } from "./example";
6
+
7
+ export const Template = (args) => <Example {...args} />;
8
+
9
+ <Meta title="Examples/Miro" component={TransformWrapper} argTypes={argsTypes} />
10
+
11
+ # Miro
12
+
13
+ A **Miro-style** canvas interaction: hold `Cmd` (or `Ctrl`) and scroll to
14
+ zoom, or use the trackpad freely to pan. The `activationKeys` option accepts
15
+ a function that receives the currently held keys, letting you create
16
+ conditional gesture activation.
17
+
18
+ The board below is built with HTML/CSS (sticky notes, frames, flow steps, and a
19
+ light dot grid) on a **large infinite-style canvas** so zoom and pan feel like a
20
+ real whiteboard tool.
21
+
22
+ This pattern separates zoom from scroll — ideal for infinite canvas apps
23
+ where the default scroll behavior should pan, not zoom.
24
+
25
+ <Canvas>
26
+ <Story name="Miro">{(args) => <Template {...args} />}</Story>
27
+ </Canvas>
28
+
29
+ ## Component API
30
+
31
+ <ArgsTable story="Miro" />
@@ -0,0 +1,147 @@
1
+ import React, { useState } from "react";
2
+
3
+ import { TransformWrapper, TransformComponent } from "../../../components";
4
+ import { Controls, ToggleIcon, normalizeArgs, viewerChrome } from "../../utils";
5
+ import { useTransformComponent } from "../../../hooks";
6
+ import exampleImg from "../../assets/medium-image.jpg";
7
+
8
+ function ModeBadge({ disabled }: { disabled: boolean }) {
9
+ return (
10
+ <div
11
+ style={{
12
+ position: "absolute",
13
+ top: 16,
14
+ right: 16,
15
+ zIndex: 10,
16
+ padding: "5px 12px",
17
+ borderRadius: 8,
18
+ background: "rgba(10, 10, 18, 0.78)",
19
+ backdropFilter: "blur(12px)",
20
+ WebkitBackdropFilter: "blur(12px)",
21
+ border: `1px solid ${disabled ? "rgba(239, 68, 68, 0.3)" : "rgba(52, 211, 153, 0.3)"}`,
22
+ display: "flex",
23
+ alignItems: "center",
24
+ gap: 8,
25
+ fontFamily: "system-ui, -apple-system, sans-serif",
26
+ userSelect: "none",
27
+ pointerEvents: "none",
28
+ }}
29
+ >
30
+ <span
31
+ style={{
32
+ width: 6,
33
+ height: 6,
34
+ borderRadius: "50%",
35
+ background: disabled ? "#ef4444" : "#34d399",
36
+ boxShadow: `0 0 8px ${disabled ? "rgba(239,68,68,0.5)" : "rgba(52,211,153,0.5)"}`,
37
+ }}
38
+ />
39
+ <span
40
+ style={{
41
+ fontSize: 11,
42
+ fontWeight: 600,
43
+ color: disabled ? "rgba(239,68,68,0.8)" : "rgba(52,211,153,0.8)",
44
+ letterSpacing: "0.04em",
45
+ }}
46
+ >
47
+ Padding {disabled ? "OFF" : "ON"}
48
+ </span>
49
+ </div>
50
+ );
51
+ }
52
+
53
+ function ScaleBadge() {
54
+ return useTransformComponent(({ state }) => (
55
+ <div
56
+ style={{
57
+ position: "absolute",
58
+ bottom: 16,
59
+ right: 16,
60
+ zIndex: 10,
61
+ padding: "5px 12px",
62
+ borderRadius: 8,
63
+ background: "rgba(10, 10, 18, 0.78)",
64
+ backdropFilter: "blur(12px)",
65
+ WebkitBackdropFilter: "blur(12px)",
66
+ border: "1px solid rgba(255,255,255,0.1)",
67
+ color: "rgba(255,255,255,0.7)",
68
+ fontSize: 11,
69
+ fontWeight: 600,
70
+ fontFamily: "system-ui, -apple-system, sans-serif",
71
+ letterSpacing: "0.02em",
72
+ userSelect: "none",
73
+ pointerEvents: "none",
74
+ }}
75
+ >
76
+ {state.scale.toFixed(2)}x
77
+ </div>
78
+ ));
79
+ }
80
+
81
+ export const Example: React.FC<any> = (args: any) => {
82
+ const [disablePadding, setDisablePadding] = useState(false);
83
+
84
+ return (
85
+ <div style={{ fontFamily: "system-ui, -apple-system, sans-serif" }}>
86
+ <TransformWrapper
87
+ {...normalizeArgs(args)}
88
+ disablePadding={disablePadding}
89
+ key={String(disablePadding)}
90
+ >
91
+ {(utils) => (
92
+ <>
93
+ <Controls
94
+ {...utils}
95
+ extraButtons={[
96
+ {
97
+ label: disablePadding ? "Enable padding" : "Disable padding",
98
+ icon: <ToggleIcon />,
99
+ onClick: () => setDisablePadding((prev) => !prev),
100
+ },
101
+ ]}
102
+ />
103
+ <ModeBadge disabled={disablePadding} />
104
+ <div style={{ position: "relative", display: "inline-block" }}>
105
+ <TransformComponent
106
+ wrapperStyle={{
107
+ ...viewerChrome,
108
+ width: "500px",
109
+ height: "500px",
110
+ maxWidth: "80vw",
111
+ maxHeight: "75vh",
112
+ }}
113
+ >
114
+ <img src={exampleImg} alt="" style={{ display: "block" }} />
115
+ </TransformComponent>
116
+ <ScaleBadge />
117
+ </div>
118
+ </>
119
+ )}
120
+ </TransformWrapper>
121
+ <p
122
+ style={{
123
+ fontSize: "13px",
124
+ color: "#888",
125
+ marginTop: "12px",
126
+ maxWidth: "500px",
127
+ lineHeight: 1.5,
128
+ }}
129
+ >
130
+ {disablePadding ? (
131
+ <>
132
+ <strong>Padding is OFF.</strong> Zoom is strictly clamped — you
133
+ cannot zoom past the content boundaries. The content snaps to the
134
+ edge immediately.
135
+ </>
136
+ ) : (
137
+ <>
138
+ <strong>Padding is ON</strong> (default). When zooming past the
139
+ content boundaries, you get an elastic &ldquo;overscroll&rdquo;
140
+ effect — the content stretches slightly beyond the limit, then snaps
141
+ back with a smooth animation.
142
+ </>
143
+ )}
144
+ </p>
145
+ </div>
146
+ );
147
+ };
@@ -0,0 +1,35 @@
1
+ import { Meta, Story, ArgsTable, Canvas } from "@storybook/blocks";
2
+
3
+ import { TransformWrapper } from "../../../components";
4
+ import { argsTypes } from "../../types/args.types.ts";
5
+ import { Example } from "./example";
6
+
7
+ export const Template = (args) => <Example {...args} />;
8
+
9
+ <Meta
10
+ title="Basic/Padding"
11
+ component={TransformWrapper}
12
+ argTypes={argsTypes}
13
+ />
14
+
15
+ # Padding
16
+
17
+ The **padding** effect controls what happens when the user zooms past the
18
+ content boundaries. By default (`disablePadding: false`), the library allows a
19
+ small elastic overscroll — the content stretches slightly beyond the limit, then
20
+ snaps back with a smooth animation. This gives a natural, tactile feel similar
21
+ to iOS scroll bounce.
22
+
23
+ When `disablePadding` is set to `true`, the zoom is strictly clamped: the
24
+ content stops exactly at the boundary with no overscroll or snap-back animation.
25
+
26
+ Use the **toggle button** in the control bar to switch between the two modes in
27
+ real time and feel the difference. The status badge shows the current mode.
28
+
29
+ <Canvas>
30
+ <Story name="Padding">{(args) => <Template {...args} />}</Story>
31
+ </Canvas>
32
+
33
+ ## Component API
34
+
35
+ <ArgsTable story="Padding" />