react-zoom-pan-pinch 3.7.0 → 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 +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 +73 -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/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,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" />
Binary file
@@ -0,0 +1 @@
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>
@@ -0,0 +1,14 @@
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>
@@ -0,0 +1,59 @@
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
+ }
@@ -0,0 +1,102 @@
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
+ }