react-zoom-pan-pinch 3.2.0 → 3.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/dist/index.cjs.js +54 -33
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +6 -0
- package/dist/index.esm.js +54 -33
- package/dist/index.esm.js.map +1 -1
- package/package.json +4 -1
- package/.eslintignore +0 -6
- package/.github/CODEOWNERS +0 -36
- package/.github/FUNDING.yml +0 -13
- package/.github/ISSUE_TEMPLATE/bug_report.md +0 -38
- package/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
- package/.github/workflows/docs.yml +0 -34
- package/.github/workflows/release.yml +0 -46
- package/.github/workflows/tests.yml +0 -42
- package/.prettierrc +0 -10
- package/.releaserc.json +0 -63
- package/.storybook/main.js +0 -23
- package/.storybook/preview-head.html +0 -5
- package/.storybook/preview.js +0 -11
- package/.storybook/theme-overrides.css +0 -49
- package/CHANGELOG.md +0 -26
- package/Code_of_Conduct.md +0 -61
- package/Contributing.md +0 -236
- package/__tests__/features/props.spec.tsx +0 -11
- package/__tests__/features/rendering.spec.tsx +0 -36
- package/__tests__/shared/render.shared.tsx +0 -41
- package/__tests__/utils/controls.utils.tsx +0 -25
- package/__tests__/utils/example.tsx +0 -81
- package/commitlint.config.js +0 -1
- package/dist/__tests__/features/props.spec.d.ts +0 -1
- package/dist/__tests__/features/rendering.spec.d.ts +0 -1
- package/dist/__tests__/shared/render.shared.d.ts +0 -11
- package/dist/__tests__/utils/controls.utils.d.ts +0 -3
- package/dist/__tests__/utils/example.d.ts +0 -6
- package/dist/src/components/index.d.ts +0 -4
- package/dist/src/components/keep-scale/keep-scale.d.ts +0 -2
- package/dist/src/components/mini-map/mini-map.d.ts +0 -8
- package/dist/src/components/mini-map/use-resize.hook.d.ts +0 -8
- package/dist/src/components/transform-component/transform-component.d.ts +0 -12
- package/dist/src/components/transform-wrapper/transform-wrapper.d.ts +0 -5
- package/dist/src/constants/state.constants.d.ts +0 -3
- package/dist/src/core/animations/animations.constants.d.ts +0 -16
- package/dist/src/core/animations/animations.utils.d.ts +0 -4
- package/dist/src/core/bounds/bounds.types.d.ts +0 -8
- package/dist/src/core/bounds/bounds.utils.d.ts +0 -17
- package/dist/src/core/double-click/double-click.logic.d.ts +0 -5
- package/dist/src/core/handlers/handlers.logic.d.ts +0 -8
- package/dist/src/core/handlers/handlers.utils.d.ts +0 -14
- package/dist/src/core/instance.core.d.ts +0 -77
- package/dist/src/core/pan/panning.logic.d.ts +0 -5
- package/dist/src/core/pan/panning.utils.d.ts +0 -10
- package/dist/src/core/pan/velocity.logic.d.ts +0 -5
- package/dist/src/core/pan/velocity.utils.d.ts +0 -5
- package/dist/src/core/pinch/pinch.logic.d.ts +0 -4
- package/dist/src/core/pinch/pinch.utils.d.ts +0 -6
- package/dist/src/core/wheel/wheel.logic.d.ts +0 -4
- package/dist/src/core/wheel/wheel.utils.d.ts +0 -7
- package/dist/src/core/zoom/zoom.logic.d.ts +0 -3
- package/dist/src/core/zoom/zoom.utils.d.ts +0 -3
- package/dist/src/hooks/index.d.ts +0 -4
- package/dist/src/hooks/use-controls.d.ts +0 -2
- package/dist/src/hooks/use-transform-context.d.ts +0 -1
- package/dist/src/hooks/use-transform-effect.d.ts +0 -2
- package/dist/src/hooks/use-transform-init.d.ts +0 -2
- package/dist/src/index.d.ts +0 -5
- package/dist/src/models/calculations.model.d.ts +0 -25
- package/dist/src/models/context.model.d.ts +0 -124
- package/dist/src/models/helpers.model.d.ts +0 -5
- package/dist/src/models/index.d.ts +0 -3
- package/dist/src/stories/docs/handlers.d.ts +0 -12
- package/dist/src/stories/docs/props.d.ts +0 -14
- package/dist/src/stories/examples/content-rerendering/example.d.ts +0 -2
- package/dist/src/stories/examples/image-responsive/example.d.ts +0 -2
- package/dist/src/stories/examples/keep-scale/example.d.ts +0 -2
- package/dist/src/stories/examples/mini-map/example.d.ts +0 -1
- package/dist/src/stories/examples/stress/example.d.ts +0 -2
- package/dist/src/stories/examples/svg-zoom-to-element/example.d.ts +0 -2
- package/dist/src/stories/examples/zoom-to-element/example.d.ts +0 -2
- package/dist/src/stories/types/args.types.d.ts +0 -280
- package/dist/src/stories/utils/args.utils.d.ts +0 -3
- package/dist/src/stories/utils/code.utils.d.ts +0 -6
- package/dist/src/stories/utils/controls.utils.d.ts +0 -3
- package/dist/src/stories/utils/index.d.ts +0 -3
- package/dist/src/utils/calculations.utils.d.ts +0 -11
- package/dist/src/utils/callback.utils.d.ts +0 -2
- package/dist/src/utils/context.utils.d.ts +0 -4
- package/dist/src/utils/event.utils.d.ts +0 -1
- package/dist/src/utils/helpers.utils.d.ts +0 -2
- package/dist/src/utils/index.d.ts +0 -8
- package/dist/src/utils/ref.utils.d.ts +0 -2
- package/dist/src/utils/state.utils.d.ts +0 -3
- package/dist/src/utils/styles.utils.d.ts +0 -4
- package/jest.config.ts +0 -45
- package/rollup.config.js +0 -51
- package/src/.eslintrc.json +0 -90
- package/src/components/index.ts +0 -4
- package/src/components/keep-scale/keep-scale.tsx +0 -28
- package/src/components/mini-map/mini-map.tsx +0 -188
- package/src/components/mini-map/use-resize.hook.ts +0 -69
- package/src/components/transform-component/transform-component.module.css +0 -30
- package/src/components/transform-component/transform-component.tsx +0 -58
- package/src/components/transform-wrapper/transform-wrapper.tsx +0 -42
- package/src/constants/state.constants.ts +0 -74
- package/src/core/animations/animations.constants.ts +0 -78
- package/src/core/animations/animations.utils.ts +0 -114
- package/src/core/bounds/bounds.types.ts +0 -8
- package/src/core/bounds/bounds.utils.ts +0 -198
- package/src/core/double-click/double-click.logic.ts +0 -116
- package/src/core/handlers/handlers.logic.ts +0 -115
- package/src/core/handlers/handlers.utils.ts +0 -195
- package/src/core/instance.core.ts +0 -499
- package/src/core/pan/panning.logic.ts +0 -100
- package/src/core/pan/panning.utils.ts +0 -196
- package/src/core/pan/velocity.logic.ts +0 -149
- package/src/core/pan/velocity.utils.ts +0 -79
- package/src/core/pinch/pinch.logic.ts +0 -81
- package/src/core/pinch/pinch.utils.ts +0 -88
- package/src/core/wheel/wheel.logic.ts +0 -121
- package/src/core/wheel/wheel.utils.ts +0 -122
- package/src/core/zoom/zoom.logic.ts +0 -69
- package/src/core/zoom/zoom.utils.ts +0 -58
- package/src/hooks/index.ts +0 -4
- package/src/hooks/use-controls.tsx +0 -9
- package/src/hooks/use-transform-context.tsx +0 -13
- package/src/hooks/use-transform-effect.tsx +0 -22
- package/src/hooks/use-transform-init.tsx +0 -27
- package/src/index.ts +0 -6
- package/src/models/calculations.model.ts +0 -26
- package/src/models/context.model.ts +0 -196
- package/src/models/helpers.model.ts +0 -15
- package/src/models/index.ts +0 -3
- package/src/react-app-env.d.ts +0 -1
- package/src/stories/assets/big-image.jpeg +0 -0
- package/src/stories/assets/map.jpg +0 -0
- package/src/stories/assets/medium-image.jpg +0 -0
- package/src/stories/assets/pin.svg +0 -1
- package/src/stories/assets/small-image.jpg +0 -0
- package/src/stories/assets/svg-example.svg +0 -14
- package/src/stories/docs/Introduction.stories.mdx +0 -174
- package/src/stories/docs/handlers.stories.mdx +0 -48
- package/src/stories/docs/handlers.tsx +0 -107
- package/src/stories/docs/props.stories.mdx +0 -92
- package/src/stories/docs/props.tsx +0 -508
- package/src/stories/examples/content/content.stories.mdx +0 -121
- package/src/stories/examples/content-rerendering/content-updating.stories.mdx +0 -45
- package/src/stories/examples/content-rerendering/example.tsx +0 -73
- package/src/stories/examples/controls/controls.stories.mdx +0 -71
- package/src/stories/examples/image-big/image-big.stories.mdx +0 -43
- package/src/stories/examples/image-medium/image-medium.stories.mdx +0 -41
- package/src/stories/examples/image-responsive/example.tsx +0 -103
- package/src/stories/examples/image-responsive/image-responsive.stories.mdx +0 -32
- package/src/stories/examples/image-small/image-small.stories.mdx +0 -41
- package/src/stories/examples/image-zoomed-out/image-zoomed-out.stories.mdx +0 -46
- package/src/stories/examples/keep-scale/example.tsx +0 -92
- package/src/stories/examples/keep-scale/keep-scale.stories.mdx +0 -45
- package/src/stories/examples/mini-map/example.tsx +0 -54
- package/src/stories/examples/mini-map/mini-map.stories.mdx +0 -33
- package/src/stories/examples/stress/example.tsx +0 -23
- package/src/stories/examples/stress/stress-test.stories.mdx +0 -28
- package/src/stories/examples/svg-zoom-to-element/creativity.svg +0 -143
- package/src/stories/examples/svg-zoom-to-element/example.tsx +0 -57
- package/src/stories/examples/svg-zoom-to-element/svg-zoom-to-element.stories.mdx +0 -28
- package/src/stories/examples/zoom-to-element/example.tsx +0 -94
- package/src/stories/examples/zoom-to-element/zoom-to-element.stories.mdx +0 -28
- package/src/stories/hooks/use-controls.stories.mdx +0 -24
- package/src/stories/hooks/use-transform-context.stories.mdx +0 -15
- package/src/stories/hooks/use-transform-effect.stories.mdx +0 -29
- package/src/stories/hooks/use-transform-init.stories.mdx +0 -25
- package/src/stories/types/args.types.ts +0 -211
- package/src/stories/utils/args.utils.ts +0 -34
- package/src/stories/utils/code.utils.tsx +0 -24
- package/src/stories/utils/controls.utils.tsx +0 -43
- package/src/stories/utils/index.ts +0 -3
- package/src/stories/utils/styles.module.css +0 -34
- package/src/styles.css +0 -8
- package/src/typings.d.ts +0 -10
- package/src/utils/calculations.utils.ts +0 -16
- package/src/utils/callback.utils.ts +0 -11
- package/src/utils/context.utils.ts +0 -48
- package/src/utils/event.utils.ts +0 -22
- package/src/utils/helpers.utils.ts +0 -27
- package/src/utils/index.ts +0 -8
- package/src/utils/ref.utils.ts +0 -16
- package/src/utils/state.utils.ts +0 -40
- package/src/utils/styles.utils.ts +0 -44
- package/tsconfig.json +0 -33
|
@@ -1,211 +0,0 @@
|
|
|
1
|
-
import { initialSetup } from "../../constants/state.constants";
|
|
2
|
-
|
|
3
|
-
export const argsTypes = {
|
|
4
|
-
wheel: {
|
|
5
|
-
table: {
|
|
6
|
-
disable: true,
|
|
7
|
-
},
|
|
8
|
-
},
|
|
9
|
-
"wheel.step": {
|
|
10
|
-
defaultValue: initialSetup.wheel.step,
|
|
11
|
-
control: {
|
|
12
|
-
type: "number",
|
|
13
|
-
min: 0,
|
|
14
|
-
},
|
|
15
|
-
table: {
|
|
16
|
-
defaultValue: { summary: "0" },
|
|
17
|
-
},
|
|
18
|
-
},
|
|
19
|
-
"wheel.smoothStep": {
|
|
20
|
-
defaultValue: initialSetup.wheel.smoothStep,
|
|
21
|
-
control: {
|
|
22
|
-
type: "number",
|
|
23
|
-
min: 0,
|
|
24
|
-
},
|
|
25
|
-
table: {
|
|
26
|
-
defaultValue: { summary: "0" },
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
"wheel.disabled": {
|
|
30
|
-
defaultValue: initialSetup.wheel.disabled,
|
|
31
|
-
control: { type: "boolean" },
|
|
32
|
-
table: {
|
|
33
|
-
defaultValue: { summary: "false" },
|
|
34
|
-
type: { summary: "boolean" },
|
|
35
|
-
},
|
|
36
|
-
},
|
|
37
|
-
"wheel.wheelDisabled": {
|
|
38
|
-
defaultValue: initialSetup.wheel.wheelDisabled,
|
|
39
|
-
control: { type: "boolean" },
|
|
40
|
-
table: {
|
|
41
|
-
defaultValue: { summary: "false" },
|
|
42
|
-
type: { summary: "boolean" },
|
|
43
|
-
},
|
|
44
|
-
},
|
|
45
|
-
"wheel.touchPadDisabled": {
|
|
46
|
-
defaultValue: initialSetup.wheel.touchPadDisabled,
|
|
47
|
-
control: { type: "boolean" },
|
|
48
|
-
table: {
|
|
49
|
-
defaultValue: { summary: "false" },
|
|
50
|
-
type: { summary: "boolean" },
|
|
51
|
-
},
|
|
52
|
-
},
|
|
53
|
-
"wheel.activationKeys": {
|
|
54
|
-
defaultValue: initialSetup.wheel.activationKeys,
|
|
55
|
-
control: { type: "text" },
|
|
56
|
-
table: {
|
|
57
|
-
defaultValue: { summary: "" },
|
|
58
|
-
type: { summary: "string" },
|
|
59
|
-
},
|
|
60
|
-
},
|
|
61
|
-
"wheel.excluded": {
|
|
62
|
-
defaultValue: initialSetup.wheel.excluded,
|
|
63
|
-
control: { type: "array" },
|
|
64
|
-
table: {
|
|
65
|
-
defaultValue: { summary: "" },
|
|
66
|
-
type: { summary: "array" },
|
|
67
|
-
},
|
|
68
|
-
},
|
|
69
|
-
panning: {
|
|
70
|
-
table: {
|
|
71
|
-
disable: true,
|
|
72
|
-
},
|
|
73
|
-
},
|
|
74
|
-
"panning.disabled": {
|
|
75
|
-
defaultValue: initialSetup.panning.disabled,
|
|
76
|
-
control: { type: "boolean" },
|
|
77
|
-
table: {
|
|
78
|
-
defaultValue: { summary: "false" },
|
|
79
|
-
type: { summary: "boolean" },
|
|
80
|
-
},
|
|
81
|
-
},
|
|
82
|
-
"panning.velocityDisabled": {
|
|
83
|
-
defaultValue: initialSetup.panning.velocityDisabled,
|
|
84
|
-
control: { type: "boolean" },
|
|
85
|
-
table: {
|
|
86
|
-
defaultValue: { summary: "false" },
|
|
87
|
-
type: { summary: "boolean" },
|
|
88
|
-
},
|
|
89
|
-
},
|
|
90
|
-
"panning.lockAxisX": {
|
|
91
|
-
defaultValue: initialSetup.panning.lockAxisX,
|
|
92
|
-
control: { type: "boolean" },
|
|
93
|
-
table: {
|
|
94
|
-
defaultValue: { summary: "false" },
|
|
95
|
-
type: { summary: "boolean" },
|
|
96
|
-
},
|
|
97
|
-
},
|
|
98
|
-
"panning.lockAxisY": {
|
|
99
|
-
defaultValue: initialSetup.panning.lockAxisY,
|
|
100
|
-
control: { type: "boolean" },
|
|
101
|
-
table: {
|
|
102
|
-
defaultValue: { summary: "false" },
|
|
103
|
-
type: { summary: "boolean" },
|
|
104
|
-
},
|
|
105
|
-
},
|
|
106
|
-
"panning.activationKeys": {
|
|
107
|
-
defaultValue: initialSetup.panning.activationKeys,
|
|
108
|
-
control: { type: "text" },
|
|
109
|
-
table: {
|
|
110
|
-
defaultValue: { summary: "" },
|
|
111
|
-
type: { summary: "string" },
|
|
112
|
-
},
|
|
113
|
-
},
|
|
114
|
-
"panning.excluded": {
|
|
115
|
-
defaultValue: initialSetup.panning.excluded,
|
|
116
|
-
control: { type: "array" },
|
|
117
|
-
table: {
|
|
118
|
-
defaultValue: { summary: "" },
|
|
119
|
-
type: { summary: "array" },
|
|
120
|
-
},
|
|
121
|
-
},
|
|
122
|
-
pinch: {
|
|
123
|
-
table: {
|
|
124
|
-
disable: true,
|
|
125
|
-
},
|
|
126
|
-
},
|
|
127
|
-
"pinch.step": {
|
|
128
|
-
defaultValue: initialSetup.pinch.step,
|
|
129
|
-
control: {
|
|
130
|
-
type: "number",
|
|
131
|
-
min: 0,
|
|
132
|
-
},
|
|
133
|
-
table: {
|
|
134
|
-
defaultValue: { summary: "0" },
|
|
135
|
-
},
|
|
136
|
-
},
|
|
137
|
-
"pinch.disabled": {
|
|
138
|
-
defaultValue: initialSetup.pinch.disabled,
|
|
139
|
-
control: { type: "boolean" },
|
|
140
|
-
table: {
|
|
141
|
-
defaultValue: { summary: "false" },
|
|
142
|
-
type: { summary: "boolean" },
|
|
143
|
-
},
|
|
144
|
-
},
|
|
145
|
-
"pinch.excluded": {
|
|
146
|
-
defaultValue: initialSetup.pinch.excluded,
|
|
147
|
-
control: { type: "array" },
|
|
148
|
-
table: {
|
|
149
|
-
defaultValue: { summary: "" },
|
|
150
|
-
type: { summary: "array" },
|
|
151
|
-
},
|
|
152
|
-
},
|
|
153
|
-
doubleClick: {
|
|
154
|
-
table: {
|
|
155
|
-
disable: true,
|
|
156
|
-
},
|
|
157
|
-
},
|
|
158
|
-
"doubleClick.step": {
|
|
159
|
-
defaultValue: initialSetup.doubleClick.step,
|
|
160
|
-
control: {
|
|
161
|
-
type: "number",
|
|
162
|
-
min: 0,
|
|
163
|
-
},
|
|
164
|
-
table: {
|
|
165
|
-
defaultValue: { summary: "0" },
|
|
166
|
-
},
|
|
167
|
-
},
|
|
168
|
-
"doubleClick.disabled": {
|
|
169
|
-
defaultValue: initialSetup.doubleClick.disabled,
|
|
170
|
-
control: { type: "boolean" },
|
|
171
|
-
table: {
|
|
172
|
-
defaultValue: { summary: "false" },
|
|
173
|
-
type: { summary: "boolean" },
|
|
174
|
-
},
|
|
175
|
-
},
|
|
176
|
-
"doubleClick.excluded": {
|
|
177
|
-
defaultValue: initialSetup.doubleClick.excluded,
|
|
178
|
-
control: { type: "array" },
|
|
179
|
-
table: {
|
|
180
|
-
defaultValue: { summary: "" },
|
|
181
|
-
type: { summary: "array" },
|
|
182
|
-
},
|
|
183
|
-
},
|
|
184
|
-
};
|
|
185
|
-
// doubleClick: {
|
|
186
|
-
// disabled: false,
|
|
187
|
-
// step: 20,
|
|
188
|
-
// mode: "zoomIn",
|
|
189
|
-
// animation: true,
|
|
190
|
-
// animationType: "easeOut",
|
|
191
|
-
// animationTime: 200,
|
|
192
|
-
// },
|
|
193
|
-
// zoomAnimation: {
|
|
194
|
-
// disabled: false,
|
|
195
|
-
// size: 0.4,
|
|
196
|
-
// animationTime: 200,
|
|
197
|
-
// animationType: "easeOut",
|
|
198
|
-
// },
|
|
199
|
-
// alignmentAnimation: {
|
|
200
|
-
// disabled: false,
|
|
201
|
-
// size: 30,
|
|
202
|
-
// animationTime: 200,
|
|
203
|
-
// animationType: "easeOut",
|
|
204
|
-
// },
|
|
205
|
-
// velocityAnimation: {
|
|
206
|
-
// disabled: false,
|
|
207
|
-
// sensitivity: 1,
|
|
208
|
-
// animationTime: 600,
|
|
209
|
-
// animationType: "easeOut",
|
|
210
|
-
// equalToMove: true,
|
|
211
|
-
// },
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
export const normalizeArgs = (args: { [key: string]: any }): any => {
|
|
2
|
-
const newArgs = {};
|
|
3
|
-
|
|
4
|
-
Object.keys(args).forEach((key) => {
|
|
5
|
-
const normalizedKey = key.split(".");
|
|
6
|
-
const isNested = normalizedKey.length === 2;
|
|
7
|
-
|
|
8
|
-
if (isNested) {
|
|
9
|
-
if (!newArgs[normalizedKey[0]]) {
|
|
10
|
-
newArgs[normalizedKey[0]] = {};
|
|
11
|
-
}
|
|
12
|
-
newArgs[normalizedKey[0]][normalizedKey[1]] = args[key];
|
|
13
|
-
} else {
|
|
14
|
-
newArgs[key] = args[key];
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
return {
|
|
19
|
-
...newArgs,
|
|
20
|
-
onTransformed: undefined,
|
|
21
|
-
onWheelStart: undefined,
|
|
22
|
-
onWheel: undefined,
|
|
23
|
-
onWheelStop: undefined,
|
|
24
|
-
onZoomStart: undefined,
|
|
25
|
-
onZoom: undefined,
|
|
26
|
-
onZoomStop: undefined,
|
|
27
|
-
onPanningStart: undefined,
|
|
28
|
-
onPanning: undefined,
|
|
29
|
-
onPanningStop: undefined,
|
|
30
|
-
onPinchStart: undefined,
|
|
31
|
-
onPinch: undefined,
|
|
32
|
-
onPinchStop: undefined,
|
|
33
|
-
};
|
|
34
|
-
};
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/* eslint-disable react/no-array-index-key */
|
|
2
|
-
import React from "react";
|
|
3
|
-
import Highlight, { defaultProps } from "prism-react-renderer";
|
|
4
|
-
import vsLight from "prism-react-renderer/themes/vsLight";
|
|
5
|
-
|
|
6
|
-
type Props = { code: string };
|
|
7
|
-
|
|
8
|
-
export const Code: React.FC<Props> = ({ code }: Props) => (
|
|
9
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
10
|
-
// @ts-ignore
|
|
11
|
-
<Highlight {...defaultProps} code={code} theme={vsLight} language="tsx">
|
|
12
|
-
{({ className, style, tokens, getLineProps, getTokenProps }) => (
|
|
13
|
-
<pre className={className} style={style}>
|
|
14
|
-
{tokens.map((line, i) => (
|
|
15
|
-
<div key={i} {...getLineProps({ line, key: i })}>
|
|
16
|
-
{line.map((token, key) => (
|
|
17
|
-
<span key={key} {...getTokenProps({ token, key })} />
|
|
18
|
-
))}
|
|
19
|
-
</div>
|
|
20
|
-
))}
|
|
21
|
-
</pre>
|
|
22
|
-
)}
|
|
23
|
-
</Highlight>
|
|
24
|
-
);
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
|
|
3
|
-
import { ReactZoomPanPinchContentRef } from "../../models/context.model";
|
|
4
|
-
|
|
5
|
-
import styles from "./styles.module.css";
|
|
6
|
-
|
|
7
|
-
export const Controls: React.FC<ReactZoomPanPinchContentRef> = ({
|
|
8
|
-
zoomIn,
|
|
9
|
-
zoomOut,
|
|
10
|
-
resetTransform,
|
|
11
|
-
centerView,
|
|
12
|
-
}: ReactZoomPanPinchContentRef) => (
|
|
13
|
-
<div className={styles.controlPanel}>
|
|
14
|
-
<button
|
|
15
|
-
type="button"
|
|
16
|
-
className={styles.controlBtn}
|
|
17
|
-
onClick={() => zoomIn()}
|
|
18
|
-
>
|
|
19
|
-
Zoom In +
|
|
20
|
-
</button>
|
|
21
|
-
<button
|
|
22
|
-
type="button"
|
|
23
|
-
className={styles.controlBtn}
|
|
24
|
-
onClick={() => zoomOut()}
|
|
25
|
-
>
|
|
26
|
-
Zoom Out -
|
|
27
|
-
</button>
|
|
28
|
-
<button
|
|
29
|
-
type="button"
|
|
30
|
-
className={styles.controlBtn}
|
|
31
|
-
onClick={() => resetTransform()}
|
|
32
|
-
>
|
|
33
|
-
Reset
|
|
34
|
-
</button>
|
|
35
|
-
<button
|
|
36
|
-
type="button"
|
|
37
|
-
className={styles.controlBtn}
|
|
38
|
-
onClick={() => centerView()}
|
|
39
|
-
>
|
|
40
|
-
Center
|
|
41
|
-
</button>
|
|
42
|
-
</div>
|
|
43
|
-
);
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
.controlPanel {
|
|
2
|
-
position: absolute;
|
|
3
|
-
z-index: 2;
|
|
4
|
-
transform: translate(10px, 10px);
|
|
5
|
-
max-width: calc(100% - 20px);
|
|
6
|
-
}
|
|
7
|
-
.controlBtn {
|
|
8
|
-
padding: 6px 12px;
|
|
9
|
-
background: white;
|
|
10
|
-
border: 1px solid grey;
|
|
11
|
-
border-radius: 5px;
|
|
12
|
-
margin-right: 10px;
|
|
13
|
-
font-size: 12px;
|
|
14
|
-
text-transform: uppercase;
|
|
15
|
-
font-weight: 600;
|
|
16
|
-
cursor: pointer;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
.controlBtn:focus {
|
|
20
|
-
filter: brightness(90%);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
.controlBtn:hover {
|
|
24
|
-
filter: brightness(120%);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
.controlBtn:active {
|
|
28
|
-
opacity: 0.9;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
.grid {
|
|
32
|
-
display: grid;
|
|
33
|
-
grid-template-columns: repeat(100, 1fr);
|
|
34
|
-
}
|
package/src/styles.css
DELETED
package/src/typings.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Default CSS definition for typescript,
|
|
3
|
-
* will be overridden with file-specific definitions by rollup
|
|
4
|
-
*/
|
|
5
|
-
declare module "*.css" {
|
|
6
|
-
const content: { [className: string]: string };
|
|
7
|
-
export default content;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
type SvgrComponent = React.StatelessComponent<React.SVGAttributes<SVGElement>>
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Rounds number to given decimal
|
|
3
|
-
* eg. roundNumber(2.34343, 1) => 2.3
|
|
4
|
-
*/
|
|
5
|
-
export const roundNumber = (num: number, decimal: number) => {
|
|
6
|
-
return Number(num.toFixed(decimal));
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Checks if value is number, if not it returns default value
|
|
11
|
-
* 1# eg. checkIsNumber(2, 30) => 2
|
|
12
|
-
* 2# eg. checkIsNumber(null, 30) => 30
|
|
13
|
-
*/
|
|
14
|
-
export const checkIsNumber = (num: any, defaultValue: number) => {
|
|
15
|
-
return typeof num === "number" ? num : defaultValue;
|
|
16
|
-
};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { ReactZoomPanPinchRef } from "../models";
|
|
2
|
-
|
|
3
|
-
export const handleCallback = <T>(
|
|
4
|
-
context: ReactZoomPanPinchRef,
|
|
5
|
-
event: T,
|
|
6
|
-
callback?: (context: ReactZoomPanPinchRef, event: T) => void,
|
|
7
|
-
): void => {
|
|
8
|
-
if (callback && typeof callback === "function") {
|
|
9
|
-
callback(context, event);
|
|
10
|
-
}
|
|
11
|
-
};
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ReactZoomPanPinchContentRef,
|
|
3
|
-
ReactZoomPanPinchContext,
|
|
4
|
-
ReactZoomPanPinchContextState,
|
|
5
|
-
ReactZoomPanPinchRef,
|
|
6
|
-
} from "../models/context.model";
|
|
7
|
-
import {
|
|
8
|
-
zoomIn,
|
|
9
|
-
zoomOut,
|
|
10
|
-
setTransform,
|
|
11
|
-
resetTransform,
|
|
12
|
-
zoomToElement,
|
|
13
|
-
centerView,
|
|
14
|
-
} from "../core/handlers/handlers.logic";
|
|
15
|
-
|
|
16
|
-
export const getControls = (
|
|
17
|
-
contextInstance: ReactZoomPanPinchContext,
|
|
18
|
-
): ReactZoomPanPinchContentRef => {
|
|
19
|
-
return {
|
|
20
|
-
instance: contextInstance,
|
|
21
|
-
zoomIn: zoomIn(contextInstance),
|
|
22
|
-
zoomOut: zoomOut(contextInstance),
|
|
23
|
-
setTransform: setTransform(contextInstance),
|
|
24
|
-
resetTransform: resetTransform(contextInstance),
|
|
25
|
-
centerView: centerView(contextInstance),
|
|
26
|
-
zoomToElement: zoomToElement(contextInstance),
|
|
27
|
-
};
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
export const getState = (
|
|
31
|
-
contextInstance: ReactZoomPanPinchContext,
|
|
32
|
-
): ReactZoomPanPinchContextState => {
|
|
33
|
-
return {
|
|
34
|
-
instance: contextInstance,
|
|
35
|
-
state: contextInstance.transformState,
|
|
36
|
-
};
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
export const getContext = (
|
|
40
|
-
contextInstance: ReactZoomPanPinchContext,
|
|
41
|
-
): ReactZoomPanPinchRef => {
|
|
42
|
-
const ref = {} as ReactZoomPanPinchRef;
|
|
43
|
-
|
|
44
|
-
Object.assign(ref, getState(contextInstance));
|
|
45
|
-
Object.assign(ref, getControls(contextInstance));
|
|
46
|
-
|
|
47
|
-
return ref;
|
|
48
|
-
};
|
package/src/utils/event.utils.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
// We want to make event listeners non-passive, and to do so have to check
|
|
2
|
-
// that browsers support EventListenerOptions in the first place.
|
|
3
|
-
// https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#Safely_detecting_option_support
|
|
4
|
-
let passiveSupported = false;
|
|
5
|
-
|
|
6
|
-
export function makePassiveEventOption(): any {
|
|
7
|
-
try {
|
|
8
|
-
const options = {
|
|
9
|
-
get passive() {
|
|
10
|
-
// This function will be called when the browser
|
|
11
|
-
// attempts to access the passive property.
|
|
12
|
-
passiveSupported = true;
|
|
13
|
-
return false;
|
|
14
|
-
},
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
return options;
|
|
18
|
-
} catch (err) {
|
|
19
|
-
passiveSupported = false;
|
|
20
|
-
return passiveSupported;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
export const isExcludedNode = (
|
|
2
|
-
node: HTMLElement,
|
|
3
|
-
excluded: string[],
|
|
4
|
-
): boolean => {
|
|
5
|
-
const targetTagName = node.tagName.toUpperCase();
|
|
6
|
-
const isExcludedTag = excluded.find(
|
|
7
|
-
(tag) => tag.toUpperCase() === targetTagName,
|
|
8
|
-
);
|
|
9
|
-
|
|
10
|
-
if (isExcludedTag) return true;
|
|
11
|
-
|
|
12
|
-
const isExcludedClassName = excluded.find((className) =>
|
|
13
|
-
node.classList.contains(className),
|
|
14
|
-
);
|
|
15
|
-
|
|
16
|
-
if (isExcludedClassName) return true;
|
|
17
|
-
|
|
18
|
-
return false;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export const cancelTimeout = (
|
|
22
|
-
timeout: ReturnType<typeof setTimeout> | null,
|
|
23
|
-
): void => {
|
|
24
|
-
if (timeout) {
|
|
25
|
-
clearTimeout(timeout);
|
|
26
|
-
}
|
|
27
|
-
};
|
package/src/utils/index.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export * from "./calculations.utils";
|
|
2
|
-
export * from "./callback.utils";
|
|
3
|
-
export * from "./context.utils";
|
|
4
|
-
export * from "./event.utils";
|
|
5
|
-
export * from "./helpers.utils";
|
|
6
|
-
export * from "./state.utils";
|
|
7
|
-
export * from "./styles.utils";
|
|
8
|
-
export * from "./ref.utils";
|
package/src/utils/ref.utils.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-param-reassign */
|
|
2
|
-
import type * as React from "react";
|
|
3
|
-
|
|
4
|
-
export function mergeRefs<T = any>(
|
|
5
|
-
refs: Array<React.MutableRefObject<T> | React.LegacyRef<T>>,
|
|
6
|
-
): React.RefCallback<T> {
|
|
7
|
-
return (value) => {
|
|
8
|
-
refs.forEach((ref) => {
|
|
9
|
-
if (typeof ref === "function") {
|
|
10
|
-
ref(value);
|
|
11
|
-
} else if (ref != null) {
|
|
12
|
-
(ref as React.MutableRefObject<T | null>).current = value;
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
|
-
};
|
|
16
|
-
}
|
package/src/utils/state.utils.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
LibrarySetup,
|
|
3
|
-
ReactZoomPanPinchProps,
|
|
4
|
-
ReactZoomPanPinchState,
|
|
5
|
-
} from "../models/context.model";
|
|
6
|
-
import { initialSetup, initialState } from "../constants/state.constants";
|
|
7
|
-
|
|
8
|
-
export const createState = (
|
|
9
|
-
props: ReactZoomPanPinchProps,
|
|
10
|
-
): ReactZoomPanPinchState => {
|
|
11
|
-
return {
|
|
12
|
-
previousScale: props.initialScale ?? initialState.scale,
|
|
13
|
-
scale: props.initialScale ?? initialState.scale,
|
|
14
|
-
positionX: props.initialPositionX ?? initialState.positionX,
|
|
15
|
-
positionY: props.initialPositionY ?? initialState.positionY,
|
|
16
|
-
};
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export const createSetup = (props: ReactZoomPanPinchProps): LibrarySetup => {
|
|
20
|
-
const newSetup = { ...initialSetup };
|
|
21
|
-
|
|
22
|
-
Object.keys(props).forEach((key) => {
|
|
23
|
-
const validValue = typeof props[key] !== "undefined";
|
|
24
|
-
const validParameter = typeof initialSetup[key] !== "undefined";
|
|
25
|
-
if (validParameter && validValue) {
|
|
26
|
-
const dataType = Object.prototype.toString.call(initialSetup[key]);
|
|
27
|
-
const isObject = dataType === "[object Object]";
|
|
28
|
-
const isArray = dataType === "[object Array]";
|
|
29
|
-
if (isObject) {
|
|
30
|
-
newSetup[key] = { ...initialSetup[key], ...props[key] };
|
|
31
|
-
} else if (isArray) {
|
|
32
|
-
newSetup[key] = [...initialSetup[key], ...props[key]];
|
|
33
|
-
} else {
|
|
34
|
-
newSetup[key] = props[key];
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
return newSetup;
|
|
40
|
-
};
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { StateType } from "models";
|
|
2
|
-
|
|
3
|
-
export const getTransformStyles = (
|
|
4
|
-
x: number,
|
|
5
|
-
y: number,
|
|
6
|
-
scale: number,
|
|
7
|
-
): string => {
|
|
8
|
-
// Standard translate prevents blurry svg on the safari
|
|
9
|
-
return `translate(${x}px, ${y}px) scale(${scale})`;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
export const getMatrixTransformStyles = (
|
|
13
|
-
x: number,
|
|
14
|
-
y: number,
|
|
15
|
-
scale: number,
|
|
16
|
-
): string => {
|
|
17
|
-
// The shorthand for matrix does not work for Safari hence the need to explicitly use matrix3d
|
|
18
|
-
// Refer to https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/matrix
|
|
19
|
-
const a = scale;
|
|
20
|
-
const b = 0;
|
|
21
|
-
const c = 0;
|
|
22
|
-
const d = scale;
|
|
23
|
-
const tx = x;
|
|
24
|
-
const ty = y;
|
|
25
|
-
return `matrix3d(${a}, ${b}, 0, 0, ${c}, ${d}, 0, 0, 0, 0, 1, 0, ${tx}, ${ty}, 0, 1)`;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
export const getCenterPosition = (
|
|
29
|
-
scale: number,
|
|
30
|
-
wrapperComponent: HTMLDivElement,
|
|
31
|
-
contentComponent: HTMLDivElement,
|
|
32
|
-
): StateType => {
|
|
33
|
-
const contentWidth = contentComponent.offsetWidth * scale;
|
|
34
|
-
const contentHeight = contentComponent.offsetHeight * scale;
|
|
35
|
-
|
|
36
|
-
const centerPositionX = (wrapperComponent.offsetWidth - contentWidth) / 2;
|
|
37
|
-
const centerPositionY = (wrapperComponent.offsetHeight - contentHeight) / 2;
|
|
38
|
-
|
|
39
|
-
return {
|
|
40
|
-
scale,
|
|
41
|
-
positionX: centerPositionX,
|
|
42
|
-
positionY: centerPositionY,
|
|
43
|
-
};
|
|
44
|
-
};
|
package/tsconfig.json
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"outDir": "./dist/",
|
|
4
|
-
"module": "esnext",
|
|
5
|
-
"target": "es5",
|
|
6
|
-
"sourceMap": true,
|
|
7
|
-
"allowJs": false,
|
|
8
|
-
"jsx": "react",
|
|
9
|
-
"declaration": true,
|
|
10
|
-
"moduleResolution": "node",
|
|
11
|
-
"forceConsistentCasingInFileNames": true,
|
|
12
|
-
"noImplicitReturns": true,
|
|
13
|
-
"noImplicitThis": true,
|
|
14
|
-
"noImplicitAny": true,
|
|
15
|
-
"strictNullChecks": true,
|
|
16
|
-
"suppressImplicitAnyIndexErrors": true,
|
|
17
|
-
"ignoreDeprecations": "5.0",
|
|
18
|
-
"noUnusedLocals": true,
|
|
19
|
-
"noUnusedParameters": true,
|
|
20
|
-
"allowSyntheticDefaultImports": true,
|
|
21
|
-
"baseUrl": "src",
|
|
22
|
-
"lib": ["dom", "dom.iterable", "esnext"],
|
|
23
|
-
"skipLibCheck": true,
|
|
24
|
-
"esModuleInterop": true,
|
|
25
|
-
"strict": true,
|
|
26
|
-
"noFallthroughCasesInSwitch": true,
|
|
27
|
-
"resolveJsonModule": true,
|
|
28
|
-
"isolatedModules": true,
|
|
29
|
-
"noEmit": true
|
|
30
|
-
},
|
|
31
|
-
"include": ["src", "__tests__"],
|
|
32
|
-
"exclude": ["node_modules", "build", "dist", "rollup.config.js"]
|
|
33
|
-
}
|