react-zoom-pan-pinch 3.7.0 → 4.0.1

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 (58) hide show
  1. package/dist/index.cjs.js +785 -310
  2. package/dist/index.cjs.js.map +1 -1
  3. package/dist/index.d.ts +117 -23
  4. package/dist/index.esm.js +781 -302
  5. package/dist/index.esm.js.map +1 -1
  6. package/package.json +74 -62
  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/styles.css +8 -0
  49. package/src/typings.d.ts +21 -0
  50. package/src/utils/calculations.utils.ts +16 -0
  51. package/src/utils/callback.utils.ts +11 -0
  52. package/src/utils/context.utils.ts +49 -0
  53. package/src/utils/event.utils.ts +38 -0
  54. package/src/utils/helpers.utils.ts +22 -0
  55. package/src/utils/index.ts +8 -0
  56. package/src/utils/ref.utils.ts +32 -0
  57. package/src/utils/state.utils.ts +77 -0
  58. package/src/utils/styles.utils.ts +49 -0
@@ -0,0 +1,30 @@
1
+ import { useEffect, useState } from "react";
2
+
3
+ import { useTransformContext } from "./use-transform-context";
4
+ import { getState } from "utils";
5
+ import { ReactZoomPanPinchContextState } from "../models";
6
+
7
+ export function useTransformComponent<T>(
8
+ callback: (state: ReactZoomPanPinchContextState) => T,
9
+ ): T {
10
+ const libraryContext = useTransformContext();
11
+
12
+ const [transformRender, setTransformRender] = useState<T>(
13
+ callback(getState(libraryContext)),
14
+ );
15
+
16
+ useEffect(() => {
17
+ let mounted = true;
18
+ const unmount = libraryContext.onChange((ref) => {
19
+ if (mounted) {
20
+ setTransformRender(callback(getState(ref.instance)));
21
+ }
22
+ });
23
+ return () => {
24
+ unmount();
25
+ mounted = false;
26
+ };
27
+ }, [callback, libraryContext]);
28
+
29
+ return transformRender;
30
+ }
@@ -0,0 +1,13 @@
1
+ import { useContext } from "react";
2
+
3
+ import { Context } from "components";
4
+
5
+ export const useTransformContext = () => {
6
+ const libraryContext = useContext(Context);
7
+
8
+ if (!libraryContext) {
9
+ throw new Error("Transform context must be placed inside TransformWrapper");
10
+ }
11
+
12
+ return libraryContext;
13
+ };
@@ -0,0 +1,22 @@
1
+ import { useEffect } from "react";
2
+
3
+ import { getState } from "utils";
4
+ import { ReactZoomPanPinchContextState } from "../models";
5
+ import { useTransformContext } from "./use-transform-context";
6
+
7
+ export const useTransformEffect = (
8
+ callback: (ref: ReactZoomPanPinchContextState) => void | (() => void),
9
+ ): void => {
10
+ const libraryContext = useTransformContext();
11
+
12
+ useEffect(() => {
13
+ let unmountCallback: void | (() => void);
14
+ const unmount = libraryContext.onChange((ref) => {
15
+ unmountCallback = callback(getState(ref.instance));
16
+ });
17
+ return () => {
18
+ unmount();
19
+ unmountCallback?.();
20
+ };
21
+ }, [callback, libraryContext]);
22
+ };
@@ -0,0 +1,28 @@
1
+ import { useEffect } from "react";
2
+
3
+ import { getState } from "utils";
4
+ import { ReactZoomPanPinchContextState } from "../models";
5
+ import { useTransformContext } from "./use-transform-context";
6
+
7
+ export const useTransformInit = (
8
+ callback: (ref: ReactZoomPanPinchContextState) => void | (() => void),
9
+ ): void => {
10
+ const libraryContext = useTransformContext();
11
+
12
+ useEffect(() => {
13
+ let unmountCallback: void | (() => void);
14
+ let unmount: void | (() => void);
15
+ if (libraryContext.contentComponent && libraryContext.wrapperComponent) {
16
+ unmountCallback = callback(getState(libraryContext));
17
+ } else {
18
+ unmount = libraryContext.onInit((ref) => {
19
+ unmountCallback = callback(getState(ref.instance));
20
+ });
21
+ }
22
+ return () => {
23
+ unmount?.();
24
+ unmountCallback?.();
25
+ };
26
+ // eslint-disable-next-line react-hooks/exhaustive-deps
27
+ }, []);
28
+ };
@@ -0,0 +1,48 @@
1
+ import { useLayoutEffect, useRef } from "react";
2
+
3
+ import { initialSetup } from "constants/state.constants";
4
+ import { ZoomPanPinch } from "core/instance.core";
5
+ import { ReactZoomPanPinchProps, ReactZoomPanPinchRef } from "models";
6
+
7
+ export const useZoomPanPinch = (props?: ReactZoomPanPinchProps) => {
8
+ const contentRef = useRef<HTMLDivElement>(null);
9
+ const wrapperRef = useRef<HTMLDivElement>(null);
10
+ const instance = useRef(new ZoomPanPinch({ ...initialSetup, ...props }));
11
+
12
+ const useTransformCallback = useRef<
13
+ (data: {
14
+ positionX: number;
15
+ positionY: number;
16
+ scale: number;
17
+ previousScale: number;
18
+ ref: ReactZoomPanPinchRef;
19
+ }) => void
20
+ >(() => {});
21
+
22
+ useLayoutEffect(() => {
23
+ const inst = instance.current;
24
+ if (contentRef.current && wrapperRef.current) {
25
+ inst.init(wrapperRef.current, contentRef.current);
26
+ }
27
+ const unmount = inst.onTransform((data) => {
28
+ useTransformCallback.current(data);
29
+ });
30
+
31
+ return () => {
32
+ inst.cleanupWindowEvents();
33
+ unmount();
34
+ };
35
+ // eslint-disable-next-line react-hooks/exhaustive-deps
36
+ }, []);
37
+
38
+ const useTransform = (callback: typeof useTransformCallback.current) => {
39
+ useTransformCallback.current = callback;
40
+ };
41
+
42
+ return {
43
+ contentRef,
44
+ wrapperRef,
45
+ instance,
46
+ useTransform,
47
+ };
48
+ };
package/src/index.ts ADDED
@@ -0,0 +1,6 @@
1
+ export * from "./hooks";
2
+ export * from "./components";
3
+
4
+ export * from "./utils/styles.utils";
5
+ export * from "./models/context.model";
6
+ export * from "./models/calculations.model";
@@ -0,0 +1,34 @@
1
+ export type SizeType = {
2
+ width: number;
3
+ height: number;
4
+ };
5
+
6
+ export type PositionType = {
7
+ x: number;
8
+ y: number;
9
+ };
10
+
11
+ export type StateType = { scale: number; positionX: number; positionY: number };
12
+
13
+ export type VelocityType = {
14
+ velocityX: number;
15
+ velocityY: number;
16
+ total: number;
17
+ };
18
+
19
+ export type BoundsType = {
20
+ minPositionX: number;
21
+ maxPositionX: number;
22
+ minPositionY: number;
23
+ maxPositionY: number;
24
+ scaleWidthFactor: number;
25
+ scaleHeightFactor: number;
26
+ };
27
+
28
+ export type AnimationType = () => void | number;
29
+
30
+ export enum DeviceType {
31
+ TRACK_PAD = "track_pad",
32
+ MOUSE = "mouse",
33
+ TOUCH = "touch",
34
+ }
@@ -0,0 +1,218 @@
1
+ import React from "react";
2
+
3
+ import { animations } from "../core/animations/animations.constants";
4
+ import { DeepNonNullable } from "./helpers.model";
5
+ import {
6
+ centerView,
7
+ resetTransform,
8
+ setTransform,
9
+ zoomIn,
10
+ zoomOut,
11
+ zoomToElement,
12
+ } from "../core/handlers/handlers.logic";
13
+ import { ZoomPanPinch } from "../core/instance.core";
14
+
15
+ export type ReactZoomPanPinchContext = typeof ZoomPanPinch.prototype;
16
+
17
+ export type ReactZoomPanPinchContextState = {
18
+ instance: ReactZoomPanPinchContext;
19
+ state: ReactZoomPanPinchState;
20
+ };
21
+
22
+ export type ReactZoomPanPinchContentRef = {
23
+ instance: ReactZoomPanPinchContext;
24
+ state: ReactZoomPanPinchState;
25
+ } & ReactZoomPanPinchHandlers;
26
+
27
+ export type ReactZoomPanPinchRef = ReactZoomPanPinchContextState &
28
+ ReactZoomPanPinchHandlers;
29
+
30
+ export type ReactZoomPanPinchState = {
31
+ previousScale: number;
32
+ scale: number;
33
+ positionX: number;
34
+ positionY: number;
35
+ };
36
+
37
+ export type ReactZoomPanPinchHandlers = {
38
+ zoomIn: ReturnType<typeof zoomIn>;
39
+ zoomOut: ReturnType<typeof zoomOut>;
40
+ setTransform: ReturnType<typeof setTransform>;
41
+ resetTransform: ReturnType<typeof resetTransform>;
42
+ centerView: ReturnType<typeof centerView>;
43
+ zoomToElement: ReturnType<typeof zoomToElement>;
44
+ };
45
+
46
+ export type ReactZoomPanPinchRefProps = {
47
+ setRef: (context: ReactZoomPanPinchRef) => void;
48
+ } & Omit<ReactZoomPanPinchProps, "ref">;
49
+
50
+ export type ReactZoomPanPinchProps = {
51
+ children?:
52
+ | React.ReactNode
53
+ | ((ref: ReactZoomPanPinchContentRef) => React.ReactNode);
54
+ ref?: React.Ref<ReactZoomPanPinchRef>;
55
+ detached?: boolean;
56
+ initialScale?: number;
57
+ initialPositionX?: number;
58
+ initialPositionY?: number;
59
+ disabled?: boolean;
60
+ minPositionX?: null | number;
61
+ maxPositionX?: null | number;
62
+ minPositionY?: null | number;
63
+ maxPositionY?: null | number;
64
+ minScale?: number;
65
+ maxScale?: number;
66
+ limitToBounds?: boolean;
67
+ centerZoomedOut?: boolean;
68
+ centerOnInit?: boolean;
69
+ disablePadding?: boolean;
70
+ customTransform?: (x: number, y: number, scale: number) => string;
71
+ smooth?: boolean;
72
+ wheel?: {
73
+ step?: number;
74
+ disabled?: boolean;
75
+ wheelDisabled?: boolean;
76
+ touchPadDisabled?: boolean;
77
+ activationKeys?: string[] | ((keys: string[]) => boolean);
78
+ excluded?: string[];
79
+ };
80
+ panning?: {
81
+ disabled?: boolean;
82
+ velocityDisabled?: boolean;
83
+ lockAxisX?: boolean;
84
+ lockAxisY?: boolean;
85
+ allowLeftClickPan?: boolean;
86
+ allowMiddleClickPan?: boolean;
87
+ allowRightClickPan?: boolean;
88
+ activationKeys?: string[] | ((keys: string[]) => boolean);
89
+ excluded?: string[];
90
+ };
91
+ pinch?: {
92
+ step?: number;
93
+ disabled?: boolean;
94
+ allowPanning?: boolean;
95
+ excluded?: string[];
96
+ };
97
+ trackPadPanning?: {
98
+ disabled?: boolean;
99
+ velocityDisabled?: boolean;
100
+ lockAxisX?: boolean;
101
+ lockAxisY?: boolean;
102
+ activationKeys?: string[] | ((keys: string[]) => boolean);
103
+ excluded?: string[];
104
+ };
105
+ doubleClick?: {
106
+ disabled?: boolean;
107
+ step?: number;
108
+ mode?: "zoomIn" | "zoomOut" | "reset" | "toggle";
109
+ animationTime?: number;
110
+ animationType?: keyof typeof animations;
111
+ excluded?: string[];
112
+ };
113
+ zoomAnimation?: {
114
+ disabled?: boolean;
115
+ size?: number;
116
+ animationTime?: number;
117
+ animationType?: keyof typeof animations;
118
+ };
119
+ autoAlignment?: {
120
+ disabled?: boolean;
121
+ sizeX?: number;
122
+ sizeY?: number;
123
+ animationTime?: number;
124
+ velocityAlignmentTime?: number;
125
+ animationType?: keyof typeof animations;
126
+ };
127
+ velocityAnimation?: {
128
+ disabled?: boolean;
129
+ sensitivityTouch?: number;
130
+ sensitivityMouse?: number;
131
+ maxStrengthMouse?: number;
132
+ maxStrengthTouch?: number;
133
+ inertia?: number;
134
+ animationTime?: number;
135
+ maxAnimationTime?: number;
136
+ animationType?: keyof typeof animations;
137
+ };
138
+ onWheelStart?: (ref: ReactZoomPanPinchRef, event: WheelEvent) => void;
139
+ onWheel?: (ref: ReactZoomPanPinchRef, event: WheelEvent) => void;
140
+ onWheelStop?: (ref: ReactZoomPanPinchRef, event: WheelEvent) => void;
141
+ onPanningStart?: (
142
+ ref: ReactZoomPanPinchRef,
143
+ event: TouchEvent | MouseEvent,
144
+ ) => void;
145
+ onPanning?: (
146
+ ref: ReactZoomPanPinchRef,
147
+ event: TouchEvent | MouseEvent,
148
+ ) => void;
149
+ onPanningStop?: (
150
+ ref: ReactZoomPanPinchRef,
151
+ event: TouchEvent | MouseEvent,
152
+ ) => void;
153
+ onPinchStart?: (ref: ReactZoomPanPinchRef, event: TouchEvent) => void;
154
+ onPinch?: (ref: ReactZoomPanPinchRef, event: TouchEvent) => void;
155
+ onPinchStop?: (ref: ReactZoomPanPinchRef, event: TouchEvent) => void;
156
+ onZoomStart?: (
157
+ ref: ReactZoomPanPinchRef,
158
+ event: TouchEvent | MouseEvent,
159
+ ) => void;
160
+ onZoom?: (ref: ReactZoomPanPinchRef, event: TouchEvent | MouseEvent) => void;
161
+ onZoomStop?: (
162
+ ref: ReactZoomPanPinchRef,
163
+ event: TouchEvent | MouseEvent,
164
+ ) => void;
165
+ onTransform?: (
166
+ ref: ReactZoomPanPinchRef,
167
+ state: { scale: number; positionX: number; positionY: number },
168
+ ) => void;
169
+ onInit?: (ref: ReactZoomPanPinchRef) => void;
170
+ };
171
+
172
+ export type ReactZoomPanPinchComponentHelpers = {
173
+ setComponents: (wrapper: HTMLDivElement, content: HTMLDivElement) => void;
174
+ };
175
+
176
+ export type LibrarySetup = Pick<
177
+ ReactZoomPanPinchProps,
178
+ "minPositionX" | "maxPositionX" | "minPositionY" | "maxPositionY"
179
+ > &
180
+ DeepNonNullable<
181
+ Omit<
182
+ ReactZoomPanPinchProps,
183
+ | "ref"
184
+ | "initialScale"
185
+ | "initialPositionX"
186
+ | "initialPositionY"
187
+ | "minPositionX"
188
+ | "maxPositionX"
189
+ | "minPositionY"
190
+ | "maxPositionY"
191
+ | "children"
192
+ | "defaultPositionX"
193
+ | "defaultPositionY"
194
+ | "defaultScale"
195
+ | "wrapperClass"
196
+ | "contentClass"
197
+ | "onWheelStart"
198
+ | "onWheel"
199
+ | "onWheelStop"
200
+ | "onPanningStart"
201
+ | "onPanning"
202
+ | "onPanningStop"
203
+ | "onPinchStart"
204
+ | "onPinch"
205
+ | "onPinchStop"
206
+ | "onZoomStart"
207
+ | "onZoom"
208
+ | "onZoomStop"
209
+ | "onTransform"
210
+ | "onInit"
211
+ | "customTransform"
212
+ >
213
+ >;
214
+
215
+ export type ReactZoomPanPinchBaseClasses = {
216
+ wrapperClass: string;
217
+ contentClass: string;
218
+ };
@@ -0,0 +1,15 @@
1
+ /* eslint-disable @typescript-eslint/ban-types */
2
+
3
+ export type DeepNonNullable<T> = T extends (...args: any[]) => any
4
+ ? T
5
+ : T extends any[]
6
+ ? DeepNonNullableArray<T[number]>
7
+ : T extends object
8
+ ? DeepNonNullableObject<T>
9
+ : T;
10
+
11
+ export type DeepNonNullableArray<T> = Array<DeepNonNullable<NonNullable<T>>>;
12
+
13
+ export type DeepNonNullableObject<T> = {
14
+ [P in keyof T]-?: DeepNonNullable<NonNullable<T[P]>>;
15
+ };
@@ -0,0 +1,3 @@
1
+ export * from "./context.model";
2
+ export * from "./helpers.model";
3
+ export * from "./calculations.model";
@@ -0,0 +1 @@
1
+ /// <reference types="react-scripts" />
package/src/styles.css ADDED
@@ -0,0 +1,8 @@
1
+ /* add css styles here (optional) */
2
+
3
+ .test {
4
+ display: inline-block;
5
+ margin: 2em auto;
6
+ border: 2px solid #000;
7
+ font-size: 2em;
8
+ }
@@ -0,0 +1,21 @@
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
+ declare module "*.svg" {
10
+ import React = require("react");
11
+
12
+ export const ReactComponent: React.FC<React.SVGProps<SVGSVGElement>>;
13
+ const src: string;
14
+ export default src;
15
+ }
16
+
17
+ declare module "*.jpg";
18
+ declare module "*.jpeg";
19
+ declare module "*.png";
20
+
21
+ type SvgrComponent = React.StatelessComponent<React.SVGAttributes<SVGElement>>;
@@ -0,0 +1,16 @@
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
+ };
@@ -0,0 +1,11 @@
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
+ };
@@ -0,0 +1,49 @@
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
+ state: contextInstance.state,
22
+ zoomIn: zoomIn(contextInstance),
23
+ zoomOut: zoomOut(contextInstance),
24
+ setTransform: setTransform(contextInstance),
25
+ resetTransform: resetTransform(contextInstance),
26
+ centerView: centerView(contextInstance),
27
+ zoomToElement: zoomToElement(contextInstance),
28
+ };
29
+ };
30
+
31
+ export const getState = (
32
+ contextInstance: ReactZoomPanPinchContext,
33
+ ): ReactZoomPanPinchContextState => {
34
+ return {
35
+ instance: contextInstance,
36
+ state: contextInstance.state,
37
+ };
38
+ };
39
+
40
+ export const getContext = (
41
+ contextInstance: ReactZoomPanPinchContext,
42
+ ): ReactZoomPanPinchRef => {
43
+ const ref = {} as ReactZoomPanPinchRef;
44
+
45
+ Object.assign(ref, getState(contextInstance));
46
+ Object.assign(ref, getControls(contextInstance));
47
+
48
+ return ref;
49
+ };
@@ -0,0 +1,38 @@
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
+
4
+ import { DeviceType } from "models";
5
+
6
+ // https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#Safely_detecting_option_support
7
+ let passiveSupported = false;
8
+
9
+ export function makePassiveEventOption(): any {
10
+ try {
11
+ const options = {
12
+ get passive() {
13
+ // This function will be called when the browser
14
+ // attempts to access the passive property.
15
+ passiveSupported = true;
16
+ return false;
17
+ },
18
+ };
19
+
20
+ return options;
21
+ } catch (err) {
22
+ passiveSupported = false;
23
+ return passiveSupported;
24
+ }
25
+ }
26
+
27
+ export function isTrackPad(
28
+ event: WheelEvent & { wheelDeltaY: number },
29
+ ): DeviceType.TRACK_PAD | DeviceType.MOUSE {
30
+ if (event.wheelDeltaY) {
31
+ if (Math.abs(event.wheelDeltaY) !== 120) {
32
+ return DeviceType.TRACK_PAD;
33
+ }
34
+ } else if (event.deltaMode === 0) {
35
+ return DeviceType.TRACK_PAD;
36
+ }
37
+ return DeviceType.MOUSE;
38
+ }
@@ -0,0 +1,22 @@
1
+ import { baseClasses } from "../constants/state.constants";
2
+
3
+ const matchPrefix = `.${baseClasses.wrapperClass}`;
4
+
5
+ export const isExcludedNode = (
6
+ node: HTMLElement,
7
+ excluded: string[],
8
+ ): boolean => {
9
+ return excluded.some((exclude) =>
10
+ node.matches(
11
+ `${matchPrefix} ${exclude}, ${matchPrefix} .${exclude}, ${matchPrefix} ${exclude} *, ${matchPrefix} .${exclude} *`,
12
+ ),
13
+ );
14
+ };
15
+
16
+ export const cancelTimeout = (
17
+ timeout: ReturnType<typeof setTimeout> | null,
18
+ ): void => {
19
+ if (timeout) {
20
+ clearTimeout(timeout);
21
+ }
22
+ };
@@ -0,0 +1,8 @@
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";
@@ -0,0 +1,32 @@
1
+ /* eslint-disable no-param-reassign */
2
+ import type * as React from "react";
3
+
4
+ export function assignRef<T>(
5
+ ref:
6
+ | ((value: T | null) => void)
7
+ | React.MutableRefObject<T | null>
8
+ | null
9
+ | undefined,
10
+ value: T | null,
11
+ ): void {
12
+ if (ref == null) return;
13
+ if (typeof ref === "function") {
14
+ ref(value);
15
+ } else {
16
+ ref.current = value;
17
+ }
18
+ }
19
+
20
+ export function mergeRefs<T = any>(
21
+ refs: Array<React.MutableRefObject<T> | React.LegacyRef<T>>,
22
+ ): React.RefCallback<T> {
23
+ return (value) => {
24
+ refs.forEach((ref) => {
25
+ if (typeof ref === "function") {
26
+ ref(value);
27
+ } else if (ref != null) {
28
+ (ref as React.MutableRefObject<T | null>).current = value;
29
+ }
30
+ });
31
+ };
32
+ }