react-zoom-pan-pinch 2.1.2 → 2.2.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 (73) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/README.md +43 -0
  3. package/dist/index.cjs.js +87 -60
  4. package/dist/index.cjs.js.map +1 -1
  5. package/dist/index.d.ts +11 -2
  6. package/dist/index.esm.js +87 -60
  7. package/dist/index.esm.js.map +1 -1
  8. package/package.json +13 -12
  9. package/src/.eslintrc.js +36 -0
  10. package/src/components/transform-component.module.css +30 -0
  11. package/src/components/transform-component.tsx +52 -0
  12. package/src/components/transform-context.tsx +493 -0
  13. package/src/components/transform-wrapper.tsx +18 -0
  14. package/src/constants/state.constants.ts +88 -0
  15. package/src/core/animations/animations.constants.ts +76 -0
  16. package/src/core/animations/animations.utils.ts +109 -0
  17. package/src/core/bounds/bounds.types.ts +8 -0
  18. package/src/core/bounds/bounds.utils.ts +157 -0
  19. package/src/core/double-click/double-click.logic.ts +75 -0
  20. package/src/core/handlers/handlers.logic.ts +112 -0
  21. package/src/core/handlers/handlers.utils.ts +202 -0
  22. package/src/core/pan/panning.logic.ts +99 -0
  23. package/src/core/pan/panning.utils.ts +199 -0
  24. package/src/core/pan/velocity.logic.ts +148 -0
  25. package/src/core/pan/velocity.utils.ts +79 -0
  26. package/src/core/pinch/pinch.logic.ts +83 -0
  27. package/src/core/pinch/pinch.utils.ts +88 -0
  28. package/src/core/wheel/wheel.logic.ts +118 -0
  29. package/src/core/wheel/wheel.utils.ts +121 -0
  30. package/src/core/zoom/zoom.logic.ts +69 -0
  31. package/src/core/zoom/zoom.utils.ts +58 -0
  32. package/src/hooks/use-transform-context.tsx +16 -0
  33. package/src/index.ts +6 -0
  34. package/src/models/calculations.model.ts +26 -0
  35. package/src/models/context.model.ts +179 -0
  36. package/src/models/helpers.model.ts +15 -0
  37. package/src/models/index.ts +3 -0
  38. package/src/react-app-env.d.ts +1 -0
  39. package/src/stories/assets/big-image.jpeg +0 -0
  40. package/src/stories/assets/medium-image.jpg +0 -0
  41. package/src/stories/assets/small-image.jpg +0 -0
  42. package/src/stories/assets/svg-example.svg +14 -0
  43. package/src/stories/docs/Introduction.stories.mdx +97 -0
  44. package/src/stories/docs/handlers.stories.mdx +48 -0
  45. package/src/stories/docs/handlers.tsx +107 -0
  46. package/src/stories/docs/props.stories.mdx +92 -0
  47. package/src/stories/docs/props.tsx +490 -0
  48. package/src/stories/examples/content/content.stories.mdx +122 -0
  49. package/src/stories/examples/content-rerendering/content-updating.stories.mdx +42 -0
  50. package/src/stories/examples/content-rerendering/example.tsx +74 -0
  51. package/src/stories/examples/controls/controls.stories.mdx +71 -0
  52. package/src/stories/examples/image-big/image-big.stories.mdx +44 -0
  53. package/src/stories/examples/image-medium/image-medium.stories.mdx +42 -0
  54. package/src/stories/examples/image-small/image-small.stories.mdx +42 -0
  55. package/src/stories/examples/image-zoomed-out/image-zoomed-out.stories.mdx +47 -0
  56. package/src/stories/examples/zoom-to-element/example.tsx +91 -0
  57. package/src/stories/examples/zoom-to-element/zoom-to-element.stories.mdx +28 -0
  58. package/src/stories/types/args.types.ts +201 -0
  59. package/src/stories/utils/args.utils.ts +34 -0
  60. package/src/stories/utils/code.utils.tsx +21 -0
  61. package/src/stories/utils/controls.utils.tsx +26 -0
  62. package/src/stories/utils/index.ts +3 -0
  63. package/src/stories/utils/styles.module.css +29 -0
  64. package/src/styles.css +8 -0
  65. package/src/typings.d.ts +10 -0
  66. package/src/utils/calculations.utils.ts +16 -0
  67. package/src/utils/callback.utils.ts +11 -0
  68. package/src/utils/context.utils.ts +27 -0
  69. package/src/utils/event.utils.ts +22 -0
  70. package/src/utils/helpers.utils.ts +27 -0
  71. package/src/utils/index.ts +7 -0
  72. package/src/utils/state.utils.ts +40 -0
  73. package/src/utils/styles.utils.ts +27 -0
@@ -0,0 +1,97 @@
1
+ import { Meta } from "@storybook/addon-docs/blocks";
2
+
3
+ <Meta title="Docs/Introduction" />
4
+
5
+ # React-zoom-pan-pinch
6
+
7
+ [![NPM](https://img.shields.io/npm/v/react-zoom-pan-pinch.svg)](https://www.npmjs.com/package/react-zoom-pan-pinch)
8
+ ![npm bundle size](https://img.shields.io/bundlephobia/minzip/react-zoom-pan-pinch)
9
+ [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
10
+ ![NPM](https://img.shields.io/npm/l/react-zoom-pan-pinch)
11
+ ![npm](https://img.shields.io/npm/dm/react-zoom-pan-pinch)
12
+ ![GitHub stars](https://img.shields.io/github/stars/prc5/react-zoom-pan-pinch?style=social)
13
+
14
+ > Super fast and light react npm package for zooming, panning and pinching html
15
+ > elements in easy way
16
+
17
+ <br />
18
+ <br />
19
+
20
+ ## Features
21
+
22
+ - 🚀 Fast and easy to use
23
+ - 🏭 Light, without external dependencies
24
+ - 💎 Mobile gestures, touchpad gestures and desktop mouse events support
25
+ - 🎁 Powerful context usage, which gives you a lot of freedom
26
+ - 🔧 Highly customizable
27
+ - 👑 Animations and many options
28
+
29
+ ## Install
30
+
31
+ ```bash
32
+ npm install --save react-zoom-pan-pinch
33
+ ```
34
+
35
+ or
36
+
37
+ ```bash
38
+ yarn add react-zoom-pan-pinch
39
+ ```
40
+
41
+ ## Usage
42
+
43
+ ```jsx
44
+ import React, { Component } from "react";
45
+
46
+ import { TransformWrapper, TransformComponent } from "react-zoom-pan-pinch";
47
+
48
+ class Example extends Component {
49
+ render() {
50
+ return (
51
+ <TransformWrapper>
52
+ <TransformComponent>
53
+ <img src="image.jpg" alt="test" />
54
+ </TransformComponent>
55
+ </TransformWrapper>
56
+ );
57
+ }
58
+ }
59
+ ```
60
+
61
+ or
62
+
63
+ ```jsx
64
+ import React, { Component } from "react";
65
+
66
+ import { TransformWrapper, TransformComponent } from "react-zoom-pan-pinch";
67
+
68
+ class Example extends Component {
69
+ render() {
70
+ return (
71
+ <TransformWrapper
72
+ initialScale={1}
73
+ initialPositionX={200}
74
+ initialPositionY={100}
75
+ >
76
+ {({ zoomIn, zoomOut, resetTransform, ...rest }) => (
77
+ <React.Fragment>
78
+ <div className="tools">
79
+ <button onClick={() => zoomIn()}>+</button>
80
+ <button onClick={() => zoomOut()}>-</button>
81
+ <button onClick={() => resetTransform()}>x</button>
82
+ </div>
83
+ <TransformComponent>
84
+ <img src="image.jpg" alt="test" />
85
+ <div>Example text</div>
86
+ </TransformComponent>
87
+ </React.Fragment>
88
+ )}
89
+ </TransformWrapper>
90
+ );
91
+ }
92
+ }
93
+ ```
94
+
95
+ ## License
96
+
97
+ MIT © [prc5](https://github.com/prc5)
@@ -0,0 +1,48 @@
1
+ import { Meta } from "@storybook/addon-docs/blocks";
2
+
3
+ import { getHandlersTable } from "./handlers.tsx";
4
+ import { Code } from "../utils";
5
+
6
+ <Meta title="Docs/Handlers" />
7
+
8
+ # Handlers
9
+
10
+ List of additionaly added handlers - you can acces them via ref or render props
11
+
12
+ <table className="handlers-table">
13
+ <thead>
14
+ <tr>
15
+ <th>
16
+ Name
17
+ </th>
18
+ <th>
19
+ Type
20
+ </th>
21
+ <th>
22
+ Default
23
+ </th>
24
+ <th>
25
+ Description
26
+ </th>
27
+ </tr>
28
+ </thead>
29
+ <tbody>
30
+ {getHandlersTable().map(row => (
31
+ <tr className={row.isObjectRow ? "is-object-row" : ""}>
32
+ <td>
33
+ {row.name}
34
+ </td>
35
+ <td>
36
+ {row.type.map(type => (<Code code={type} />))}
37
+ </td>
38
+ <td>
39
+ {row.parameters.map(param => (<Code code={param} />))}
40
+ </td>
41
+ <td>
42
+ {row.description}
43
+ </td>
44
+ </tr>
45
+ ))}
46
+ </tbody>
47
+
48
+ </table>
@@ -0,0 +1,107 @@
1
+ import React from "react";
2
+
3
+ import { ReactZoomPanPinchHandlers } from "../../models/context.model";
4
+
5
+ export type ControlsFnOptionsType = {
6
+ name: React.ReactNode;
7
+ type: string[];
8
+ parameters: string[];
9
+ description: string;
10
+ isObjectRow?: boolean;
11
+ };
12
+
13
+ export type ComponentProps = Record<
14
+ keyof ReactZoomPanPinchHandlers,
15
+ | Omit<ControlsFnOptionsType, "name" | "isObjectRow">
16
+ | Record<string, Omit<ControlsFnOptionsType, "name" | "isObjectRow">>
17
+ >;
18
+
19
+ export const getHandlersTable = (): ControlsFnOptionsType[] => {
20
+ return Object.keys(handlersTable).reduce<ControlsFnOptionsType[]>(
21
+ (acc, key) => {
22
+ if (Array.isArray(handlersTable[key]?.type)) {
23
+ acc.push({
24
+ ...handlersTable[key],
25
+ name: key,
26
+ });
27
+ } else {
28
+ Object.keys(handlersTable[key]).forEach((prop) => {
29
+ acc.push({
30
+ ...handlersTable[key][prop],
31
+ isObjectRow: key === prop,
32
+ name:
33
+ key === prop ? (
34
+ <b>{prop}</b>
35
+ ) : (
36
+ <>
37
+ {key}.<b>{prop}</b>
38
+ </>
39
+ ),
40
+ });
41
+ });
42
+ }
43
+ return acc;
44
+ },
45
+ [],
46
+ );
47
+ };
48
+
49
+ export const handlersTable: ComponentProps = {
50
+ zoomIn: {
51
+ type: ["function(step, animationTime, animationName)"],
52
+ parameters: [
53
+ "step: number = 0.5",
54
+ "animationTime: number = 300",
55
+ "animationName: string = easeOut",
56
+ ],
57
+ description: "Function used for zoom in button",
58
+ },
59
+ zoomOut: {
60
+ type: ["function(step, animationTime, animationName)"],
61
+ parameters: [
62
+ "step: number = 0.5",
63
+ "animationTime: number = 300",
64
+ "animationName: string = easeOut",
65
+ ],
66
+ description: "Function used for zoom out button",
67
+ },
68
+ setTransform: {
69
+ type: ["function(x, y, scale, animationTime, animationName)"],
70
+ parameters: [
71
+ "x: number",
72
+ "y: number",
73
+ "scale: number",
74
+ "animationTime: number = 300",
75
+ "animationName: string = easeOut",
76
+ ],
77
+ description: "Function used for custom transformation animation",
78
+ },
79
+ resetTransform: {
80
+ type: ["function(animationTime, animationName)"],
81
+ parameters: [
82
+ "animationTime: number = 300",
83
+ "animationName: string = easeOut",
84
+ ],
85
+ description: "Function used for reset button",
86
+ },
87
+ centerView: {
88
+ type: ["function(scale, animationTime, animationName)"],
89
+ parameters: [
90
+ "scale: number = undefined",
91
+ "animationTime: number = 300",
92
+ "animationName: string = easeOut",
93
+ ],
94
+ description: "Function used for centering the content component",
95
+ },
96
+ zoomToElement: {
97
+ type: ["function(node, customZoom, animationTime, animationName)"],
98
+ parameters: [
99
+ "node: HTMLElement | string",
100
+ "customScale: number = undefined",
101
+ "animationTime: number = 300",
102
+ "animationName: string = easeOut",
103
+ ],
104
+ description:
105
+ "This function make a transition for certain node provided to the function(as node element or it's id string). It allows only to zoom elements with offsetWidth and offsetHeight properties - since SVG's doesn't have those, it is impossible to perform it on such elements.",
106
+ },
107
+ };
@@ -0,0 +1,92 @@
1
+ import { Meta } from "@storybook/addon-docs/blocks";
2
+
3
+ import { componentProps, wrapperProps } from "./props.tsx";
4
+ import { Code } from "../utils";
5
+
6
+ <Meta title="Docs/Props" />
7
+
8
+ # TransformComponent Props
9
+
10
+ List of props
11
+
12
+ <table className="props-table">
13
+ <thead>
14
+ <tr>
15
+ <th>
16
+ Name
17
+ </th>
18
+ <th>
19
+ Type
20
+ </th>
21
+ <th>
22
+ Default
23
+ </th>
24
+ <th>
25
+ Description
26
+ </th>
27
+ </tr>
28
+ </thead>
29
+ <tbody>
30
+ {componentProps.map(row => (
31
+ <tr className={row.isObjectRow ? "is-object-row" : ""}>
32
+ <td>
33
+ {row.name}
34
+ </td>
35
+ <td>
36
+ {row.type.map(type => (<Code code={type} />))}
37
+ </td>
38
+ <td>
39
+ <Code code={row.defaultValue} />
40
+ </td>
41
+ <td>
42
+ {row.description}
43
+ </td>
44
+ </tr>
45
+ ))}
46
+ </tbody>
47
+
48
+ </table>
49
+
50
+ <br />
51
+
52
+ # TransformWrapper Props
53
+
54
+ List of props
55
+
56
+ <table className="props-table">
57
+ <thead>
58
+ <tr>
59
+ <th>
60
+ Name
61
+ </th>
62
+ <th>
63
+ Type
64
+ </th>
65
+ <th>
66
+ Default
67
+ </th>
68
+ <th>
69
+ Description
70
+ </th>
71
+ </tr>
72
+ </thead>
73
+ <tbody>
74
+ {wrapperProps.map(row => (
75
+ <tr className={row.isObjectRow ? "is-object-row" : ""}>
76
+ <td>
77
+ {row.name}
78
+ </td>
79
+ <td>
80
+ {row.type.map(type => (<Code code={type} />))}
81
+ </td>
82
+ <td>
83
+ <Code code={row.defaultValue} />
84
+ </td>
85
+ <td>
86
+ {row.description}
87
+ </td>
88
+ </tr>
89
+ ))}
90
+ </tbody>
91
+
92
+ </table>