react-native-screen-transitions 2.0.2 → 2.0.4

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 (77) hide show
  1. package/lib/commonjs/utils/bounds/constants.js +3 -3
  2. package/lib/commonjs/utils/bounds/constants.js.map +1 -1
  3. package/lib/commonjs/utils/bounds/get-bounds.js +3 -3
  4. package/lib/commonjs/utils/bounds/get-bounds.js.map +1 -1
  5. package/lib/module/utils/bounds/constants.js +3 -3
  6. package/lib/module/utils/bounds/constants.js.map +1 -1
  7. package/lib/module/utils/bounds/get-bounds.js +3 -3
  8. package/lib/module/utils/bounds/get-bounds.js.map +1 -1
  9. package/lib/typescript/utils/bounds/_types/get-bounds.d.ts +2 -2
  10. package/lib/typescript/utils/bounds/_types/get-bounds.d.ts.map +1 -1
  11. package/lib/typescript/utils/bounds/constants.d.ts +4 -4
  12. package/lib/typescript/utils/bounds/constants.d.ts.map +1 -1
  13. package/lib/typescript/utils/bounds/get-bounds.d.ts +2 -2
  14. package/lib/typescript/utils/bounds/get-bounds.d.ts.map +1 -1
  15. package/lib/typescript/utils/bounds/index.d.ts +1 -1
  16. package/lib/typescript/utils/bounds/index.d.ts.map +1 -1
  17. package/package.json +4 -2
  18. package/src/__tests__/geometry.test.ts +127 -0
  19. package/src/components/bounds-activator.tsx +29 -0
  20. package/src/components/controllers/screen-lifecycle.tsx +72 -0
  21. package/src/components/create-transition-aware-component.tsx +99 -0
  22. package/src/components/root-transition-aware.tsx +56 -0
  23. package/src/configs/index.ts +2 -0
  24. package/src/configs/presets.ts +227 -0
  25. package/src/configs/specs.ts +9 -0
  26. package/src/hooks/animation/use-associated-style.tsx +28 -0
  27. package/src/hooks/animation/use-screen-animation.tsx +142 -0
  28. package/src/hooks/bounds/use-bound-measurer.tsx +71 -0
  29. package/src/hooks/gestures/use-build-gestures.tsx +369 -0
  30. package/src/hooks/gestures/use-scroll-progress.tsx +60 -0
  31. package/src/hooks/use-stable-callback.tsx +15 -0
  32. package/src/index.ts +32 -0
  33. package/src/integrations/native-stack/navigators/createNativeStackNavigator.tsx +112 -0
  34. package/src/integrations/native-stack/utils/debounce.tsx +14 -0
  35. package/src/integrations/native-stack/utils/getModalRoutesKeys.ts +21 -0
  36. package/src/integrations/native-stack/utils/useAnimatedHeaderHeight.tsx +18 -0
  37. package/src/integrations/native-stack/utils/useDismissedRouteError.tsx +30 -0
  38. package/src/integrations/native-stack/utils/useInvalidPreventRemoveError.tsx +31 -0
  39. package/src/integrations/native-stack/views/FontProcessor.native.tsx +12 -0
  40. package/src/integrations/native-stack/views/FontProcessor.tsx +5 -0
  41. package/src/integrations/native-stack/views/FooterComponent.tsx +10 -0
  42. package/src/integrations/native-stack/views/NativeStackView.native.tsx +657 -0
  43. package/src/integrations/native-stack/views/NativeStackView.tsx +214 -0
  44. package/src/integrations/native-stack/views/useHeaderConfigProps.tsx +295 -0
  45. package/src/providers/gestures.tsx +89 -0
  46. package/src/providers/keys.tsx +38 -0
  47. package/src/stores/animations.ts +45 -0
  48. package/src/stores/bounds.ts +71 -0
  49. package/src/stores/gestures.ts +55 -0
  50. package/src/stores/navigator-dismiss-state.ts +17 -0
  51. package/src/stores/utils/reset-stores-for-screen.ts +14 -0
  52. package/src/types/animation.ts +76 -0
  53. package/src/types/bounds.ts +82 -0
  54. package/src/types/core.ts +50 -0
  55. package/src/types/gesture.ts +33 -0
  56. package/src/types/navigator.ts +744 -0
  57. package/src/types/utils.ts +3 -0
  58. package/src/utils/animation/animate.ts +28 -0
  59. package/src/utils/animation/run-transition.ts +49 -0
  60. package/src/utils/bounds/_types/builder.ts +35 -0
  61. package/src/utils/bounds/_types/geometry.ts +17 -0
  62. package/src/utils/bounds/_types/get-bounds.ts +10 -0
  63. package/src/utils/bounds/build-bound-styles.ts +184 -0
  64. package/src/utils/bounds/constants.ts +25 -0
  65. package/src/utils/bounds/flatten-styles.ts +21 -0
  66. package/src/utils/bounds/geometry.ts +113 -0
  67. package/src/utils/bounds/get-bounds.ts +56 -0
  68. package/src/utils/bounds/index.ts +46 -0
  69. package/src/utils/bounds/style-composers.ts +172 -0
  70. package/src/utils/gesture/apply-gesture-activation-criteria.ts +109 -0
  71. package/src/utils/gesture/map-gesture-to-progress.ts +11 -0
  72. package/src/utils/gesture/normalize-gesture-translation.ts +20 -0
  73. package/src/utils/index.ts +1 -0
  74. package/lib/commonjs/__tests__ /geometry.test.js +0 -178
  75. package/lib/commonjs/__tests__ /geometry.test.js.map +0 -1
  76. package/lib/module/__tests__ /geometry.test.js +0 -178
  77. package/lib/module/__tests__ /geometry.test.js.map +0 -1
@@ -0,0 +1,172 @@
1
+ import type { MeasuredDimensions, StyleProps } from "react-native-reanimated";
2
+ import type { BoundsBuilderOptions } from "./_types/builder";
3
+ import type {
4
+ ContentTransformGeometry,
5
+ RelativeGeometry,
6
+ } from "./_types/geometry";
7
+
8
+ /**
9
+ * Common interpolation helper signature used by composers.
10
+ * It maps from a -> b over the already-determined progress range.
11
+ */
12
+ export type Interp = (a: number, b: number) => number;
13
+
14
+ /**
15
+ * Element-level (relative) params shared by size/transform composers.
16
+ * - start/end: absolute window bounds of the element in previous/next phases
17
+ * - geometry: relative deltas and scales between start/end (dx, dy, scaleX, scaleY, ...)
18
+ * - interp: function to interpolate between numbers using the correct progress range
19
+ */
20
+ export type ElementComposeParams = {
21
+ start: MeasuredDimensions;
22
+ end: MeasuredDimensions;
23
+ geometry: RelativeGeometry;
24
+ interp: Interp;
25
+ computeOptions: BoundsBuilderOptions;
26
+ };
27
+
28
+ /**
29
+ * Screen-level content transform params (for aligning destination bound to source).
30
+ * - start/end: absolute window bounds for the shared id (source/destination)
31
+ * - geometry: precomputed screen-level tx/ty/sx/sy plus ranges/entering
32
+ * - interp: function to interpolate between numbers using the correct progress range
33
+ */
34
+ export type ContentComposeParams = {
35
+ start: MeasuredDimensions;
36
+ end: MeasuredDimensions;
37
+ geometry: ContentTransformGeometry;
38
+ interp: Interp;
39
+ computeOptions: BoundsBuilderOptions;
40
+ };
41
+
42
+ export function composeSizeAbsolute(params: ElementComposeParams): StyleProps {
43
+ "worklet";
44
+ const { start, end, geometry, interp } = params;
45
+
46
+ if (geometry.entering) {
47
+ return {
48
+ width: interp(start.width, end.width),
49
+ height: interp(start.height, end.height),
50
+ transform: [
51
+ { translateX: interp(start.pageX, end.pageX) },
52
+ { translateY: interp(start.pageY, end.pageY) },
53
+ ],
54
+ } satisfies StyleProps;
55
+ }
56
+
57
+ return {
58
+ width: interp(end.width, start.width),
59
+ height: interp(end.height, start.height),
60
+ transform: [
61
+ { translateX: interp(end.pageX, start.pageX) },
62
+ { translateY: interp(end.pageY, start.pageY) },
63
+ ],
64
+ };
65
+ }
66
+
67
+ export function composeSizeRelative(params: ElementComposeParams): StyleProps {
68
+ "worklet";
69
+ const { start, end, geometry, interp } = params;
70
+
71
+ if (geometry.entering) {
72
+ return {
73
+ transform: [
74
+ { translateX: interp(geometry.dx, 0) },
75
+ { translateY: interp(geometry.dy, 0) },
76
+ ],
77
+ width: interp(start.width, end.width),
78
+ height: interp(start.height, end.height),
79
+ };
80
+ }
81
+
82
+ return {
83
+ transform: [
84
+ { translateX: interp(0, -geometry.dx) },
85
+ { translateY: interp(0, -geometry.dy) },
86
+ ],
87
+ width: interp(end.width, start.width),
88
+ height: interp(end.height, start.height),
89
+ };
90
+ }
91
+
92
+ export function composeTransformAbsolute(
93
+ params: ElementComposeParams,
94
+ ): StyleProps {
95
+ "worklet";
96
+ const { start, end, geometry, interp } = params;
97
+
98
+ if (geometry.entering) {
99
+ return {
100
+ transform: [
101
+ { translateX: interp(start.pageX, end.pageX) },
102
+ { translateY: interp(start.pageY, end.pageY) },
103
+ { scaleX: interp(geometry.scaleX, 1) },
104
+ { scaleY: interp(geometry.scaleY, 1) },
105
+ ],
106
+ };
107
+ }
108
+
109
+ return {
110
+ transform: [
111
+ { translateX: interp(end.pageX, start.pageX) },
112
+ { translateY: interp(end.pageY, start.pageY) },
113
+ { scaleX: interp(1, 1 / geometry.scaleX) },
114
+ { scaleY: interp(1, 1 / geometry.scaleY) },
115
+ ],
116
+ };
117
+ }
118
+
119
+ export function composeTransformRelative(
120
+ params: ElementComposeParams,
121
+ ): StyleProps {
122
+ "worklet";
123
+ const { geometry, computeOptions, interp } = params;
124
+
125
+ if (geometry.entering) {
126
+ return {
127
+ transform: [
128
+ { translateX: computeOptions.gestures?.x ?? 0 },
129
+ { translateY: computeOptions.gestures?.y ?? 0 },
130
+ { translateX: interp(geometry.dx, 0) },
131
+ { translateY: interp(geometry.dy, 0) },
132
+ { scaleX: interp(geometry.scaleX, 1) },
133
+ { scaleY: interp(geometry.scaleY, 1) },
134
+ ],
135
+ };
136
+ }
137
+
138
+ return {
139
+ transform: [
140
+ { translateX: computeOptions.gestures?.x ?? 0 },
141
+ { translateY: computeOptions.gestures?.y ?? 0 },
142
+ { translateX: interp(0, -geometry.dx) },
143
+ { translateY: interp(0, -geometry.dy) },
144
+ { scaleX: interp(1, 1 / geometry.scaleX) },
145
+ { scaleY: interp(1, 1 / geometry.scaleY) },
146
+ ],
147
+ };
148
+ }
149
+
150
+ export function composeContentStyle(params: ContentComposeParams): StyleProps {
151
+ "worklet";
152
+ const { geometry, interp } = params;
153
+ const { s, tx, ty, entering } = geometry;
154
+
155
+ if (entering) {
156
+ return {
157
+ transform: [
158
+ { translateX: interp(tx, 0) },
159
+ { translateY: interp(ty, 0) },
160
+ { scale: interp(s, 1) },
161
+ ],
162
+ };
163
+ }
164
+
165
+ return {
166
+ transform: [
167
+ { translateX: interp(0, tx) },
168
+ { translateY: interp(0, ty) },
169
+ { scale: interp(1, s) },
170
+ ],
171
+ };
172
+ }
@@ -0,0 +1,109 @@
1
+ import type { PanGesture } from "react-native-gesture-handler";
2
+ import type { ScreenTransitionConfig } from "../../types/navigator";
3
+
4
+ interface GestureActivationOptions {
5
+ gestureDirection:
6
+ | ScreenTransitionConfig["gestureDirection"]
7
+ | Array<ScreenTransitionConfig["gestureDirection"]>;
8
+ gestureResponseDistance: number;
9
+ panGesture: PanGesture;
10
+ }
11
+
12
+ /**
13
+ * rngh requires this type instead a number[]. We're returning a num[] which is still correct, this is just to remove the type error.
14
+ */
15
+ type OffsetErrorTypeBugFix = [start: number, end: number];
16
+
17
+ export const applyGestureActivationCriteria = ({
18
+ gestureDirection,
19
+ gestureResponseDistance,
20
+ panGesture,
21
+ }: GestureActivationOptions) => {
22
+ const directions = Array.isArray(gestureDirection)
23
+ ? gestureDirection
24
+ : [gestureDirection];
25
+
26
+ if (directions.includes("bidirectional")) {
27
+ return {
28
+ activeOffsetX: [
29
+ -gestureResponseDistance,
30
+ gestureResponseDistance,
31
+ ] as OffsetErrorTypeBugFix,
32
+ activeOffsetY: [
33
+ -gestureResponseDistance,
34
+ gestureResponseDistance,
35
+ ] as OffsetErrorTypeBugFix,
36
+ };
37
+ }
38
+
39
+ const allowedDown = directions.includes("vertical");
40
+ const allowedUp = directions.includes("vertical-inverted");
41
+ const allowedRight = directions.includes("horizontal");
42
+ const allowedLeft = directions.includes("horizontal-inverted");
43
+
44
+ const toleranceX = 15;
45
+ const toleranceY = 20;
46
+ const dist = gestureResponseDistance;
47
+
48
+ const result: {
49
+ activeOffsetX?: number | [number, number];
50
+ failOffsetX?: number | OffsetErrorTypeBugFix;
51
+ activeOffsetY?: number | [number, number];
52
+ failOffsetY?: number | OffsetErrorTypeBugFix;
53
+ } = {};
54
+
55
+ const hasHorizontal = allowedLeft || allowedRight;
56
+ if (hasHorizontal) {
57
+ if (allowedLeft && allowedRight) {
58
+ result.activeOffsetX = [-dist, dist];
59
+ } else if (allowedLeft) {
60
+ result.activeOffsetX = -dist;
61
+ } else if (allowedRight) {
62
+ result.activeOffsetX = dist;
63
+ }
64
+
65
+ if (allowedRight && !allowedLeft) {
66
+ result.failOffsetX = -dist;
67
+ } else if (allowedLeft && !allowedRight) {
68
+ result.failOffsetX = dist;
69
+ }
70
+ } else {
71
+ result.failOffsetX = [-toleranceX, toleranceX] as OffsetErrorTypeBugFix;
72
+ }
73
+
74
+ const hasVertical = allowedUp || allowedDown;
75
+ if (hasVertical) {
76
+ if (allowedUp && allowedDown) {
77
+ result.activeOffsetY = [-dist, dist];
78
+ } else if (allowedUp) {
79
+ result.activeOffsetY = -dist;
80
+ } else if (allowedDown) {
81
+ result.activeOffsetY = dist;
82
+ }
83
+
84
+ if (allowedDown && !allowedUp) {
85
+ result.failOffsetY = -dist;
86
+ } else if (allowedUp && !allowedDown) {
87
+ result.failOffsetY = dist;
88
+ }
89
+ } else {
90
+ result.failOffsetY = [-toleranceY, toleranceY] as OffsetErrorTypeBugFix;
91
+ }
92
+
93
+ if (result?.activeOffsetX) {
94
+ panGesture.activeOffsetX(result.activeOffsetX);
95
+ }
96
+ if (result?.activeOffsetY) {
97
+ panGesture.activeOffsetY(result.activeOffsetY);
98
+ }
99
+ if (result?.failOffsetX) {
100
+ panGesture.failOffsetX(result.failOffsetX);
101
+ }
102
+ if (result?.failOffsetY) {
103
+ panGesture.failOffsetY(result.failOffsetY);
104
+ }
105
+
106
+ panGesture.enableTrackpadTwoFingerGesture(true);
107
+
108
+ return panGesture;
109
+ };
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Utility function to map raw gesture translation to a progress value.
3
+ */
4
+ export const mapGestureToProgress = (
5
+ translation: number,
6
+ dimension: number,
7
+ ) => {
8
+ "worklet";
9
+ const rawProgress = translation / dimension;
10
+ return Math.max(0, Math.min(1, rawProgress));
11
+ };
@@ -0,0 +1,20 @@
1
+ import type { GestureDirection } from "../../types/gesture";
2
+
3
+ /**
4
+ * Utility function to normalize gesture translation based on direction.
5
+ */
6
+ export const normalizeGestureTranslation = (
7
+ translation: number,
8
+ gestureDirection: GestureDirection,
9
+ ) => {
10
+ "worklet";
11
+ const isInverted = gestureDirection.includes("inverted");
12
+
13
+ const translated = Math.abs(translation) * (isInverted ? -1 : 1);
14
+
15
+ if (isInverted) {
16
+ return Math.min(0, translated);
17
+ }
18
+
19
+ return Math.max(0, translated);
20
+ };
@@ -0,0 +1 @@
1
+ export * from "./animation/animate";
@@ -1,178 +0,0 @@
1
- "use strict";
2
-
3
- var _bunTest = require("bun:test");
4
- var _geometry = require("../utils/bounds/geometry");
5
- (0, _bunTest.describe)("computeRelativeGeometry", () => {
6
- (0, _bunTest.it)("calculates correct relative geometry when entering", () => {
7
- const start = {
8
- x: 10,
9
- y: 20,
10
- pageX: 10,
11
- pageY: 20,
12
- width: 100,
13
- height: 200
14
- };
15
- const end = {
16
- x: 50,
17
- y: 100,
18
- pageX: 50,
19
- pageY: 100,
20
- width: 200,
21
- height: 400
22
- };
23
- const result = (0, _geometry.computeRelativeGeometry)({
24
- start,
25
- end,
26
- entering: true
27
- });
28
- (0, _bunTest.expect)(result.dx).toBe(-90); // center diff X
29
- (0, _bunTest.expect)(result.dy).toBe(-180); // center diff Y
30
- (0, _bunTest.expect)(result.scaleX).toBe(0.5); // width ratio
31
- (0, _bunTest.expect)(result.scaleY).toBe(0.5); // height ratio
32
- (0, _bunTest.expect)(result.ranges).toEqual([0, 1]);
33
- (0, _bunTest.expect)(result.entering).toBe(true);
34
- });
35
- (0, _bunTest.it)("calculates correct relative geometry when exiting", () => {
36
- const start = {
37
- x: 0,
38
- y: 0,
39
- pageX: 10,
40
- pageY: 20,
41
- width: 100,
42
- height: 200
43
- };
44
- const end = {
45
- x: 0,
46
- y: 0,
47
- pageX: 50,
48
- pageY: 100,
49
- width: 200,
50
- height: 400
51
- };
52
- const result = (0, _geometry.computeRelativeGeometry)({
53
- start,
54
- end,
55
- entering: false
56
- });
57
- (0, _bunTest.expect)(result.ranges).toEqual([1, 2]);
58
- (0, _bunTest.expect)(result.entering).toBe(false);
59
- });
60
- });
61
- (0, _bunTest.describe)("computeContentTransformGeometry", () => {
62
- const dimensions = {
63
- width: 375,
64
- height: 812,
65
- scale: 1,
66
- fontScale: 1
67
- };
68
- (0, _bunTest.it)("calculates transform with aspectFit mode", () => {
69
- const start = {
70
- x: 0,
71
- y: 0,
72
- pageX: 50,
73
- pageY: 100,
74
- width: 100,
75
- height: 100
76
- };
77
- const end = {
78
- x: 0,
79
- y: 0,
80
- pageX: 100,
81
- pageY: 200,
82
- width: 200,
83
- height: 50
84
- };
85
- const result = (0, _geometry.computeContentTransformGeometry)({
86
- start,
87
- end,
88
- entering: true,
89
- dimensions,
90
- contentScaleMode: "aspectFit"
91
- });
92
- (0, _bunTest.expect)(result.s).toBe(0.5);
93
- (0, _bunTest.expect)(result.entering).toBe(true);
94
- (0, _bunTest.expect)(result.ranges).toEqual([0, 1]);
95
- });
96
- (0, _bunTest.it)("calculates transform with aspectFill mode", () => {
97
- const start = {
98
- x: 0,
99
- y: 0,
100
- pageX: 50,
101
- pageY: 100,
102
- width: 100,
103
- height: 100
104
- };
105
- const end = {
106
- x: 0,
107
- y: 0,
108
- pageX: 100,
109
- pageY: 200,
110
- width: 200,
111
- height: 50
112
- };
113
- const result = (0, _geometry.computeContentTransformGeometry)({
114
- start,
115
- end,
116
- entering: true,
117
- dimensions,
118
- contentScaleMode: "aspectFill"
119
- });
120
- (0, _bunTest.expect)(result.s).toBe(2);
121
- });
122
- (0, _bunTest.it)("handles auto mode based on aspect ratio difference", () => {
123
- const start = {
124
- x: 0,
125
- y: 0,
126
- pageX: 0,
127
- pageY: 0,
128
- width: 100,
129
- height: 100
130
- };
131
- const end = {
132
- x: 0,
133
- y: 0,
134
- pageX: 0,
135
- pageY: 0,
136
- width: 200,
137
- height: 195
138
- };
139
- const result = (0, _geometry.computeContentTransformGeometry)({
140
- start,
141
- end,
142
- entering: true,
143
- dimensions,
144
- contentScaleMode: "auto"
145
- });
146
- (0, _bunTest.expect)(result.s).toBeCloseTo(0.512, 2);
147
- });
148
- (0, _bunTest.it)("handles zero dimensions safely", () => {
149
- const start = {
150
- x: 0,
151
- y: 0,
152
- pageX: 0,
153
- pageY: 0,
154
- width: 0,
155
- height: 100
156
- };
157
- const end = {
158
- x: 0,
159
- y: 0,
160
- pageX: 0,
161
- pageY: 0,
162
- width: 200,
163
- height: 200
164
- };
165
-
166
- // Should not throw and use safe fallback
167
- const result = (0, _geometry.computeContentTransformGeometry)({
168
- start,
169
- end,
170
- entering: true,
171
- dimensions,
172
- contentScaleMode: "aspectFit"
173
- });
174
- (0, _bunTest.expect)(result.s).toBeDefined();
175
- (0, _bunTest.expect)(Number.isFinite(result.s)).toBe(true);
176
- });
177
- });
178
- //# sourceMappingURL=geometry.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["_bunTest","require","_geometry","describe","it","start","x","y","pageX","pageY","width","height","end","result","computeRelativeGeometry","entering","expect","dx","toBe","dy","scaleX","scaleY","ranges","toEqual","dimensions","scale","fontScale","computeContentTransformGeometry","contentScaleMode","s","toBeCloseTo","toBeDefined","Number","isFinite"],"sourceRoot":"../../../src","sources":["__tests__ /geometry.test.ts"],"mappings":";;AAAA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AAKA,IAAAE,iBAAQ,EAAC,yBAAyB,EAAE,MAAM;EACzC,IAAAC,WAAE,EAAC,oDAAoD,EAAE,MAAM;IAC9D,MAAMC,KAAK,GAAG;MACbC,CAAC,EAAE,EAAE;MACLC,CAAC,EAAE,EAAE;MACLC,KAAK,EAAE,EAAE;MACTC,KAAK,EAAE,EAAE;MACTC,KAAK,EAAE,GAAG;MACVC,MAAM,EAAE;IACT,CAAC;IACD,MAAMC,GAAG,GAAG;MACXN,CAAC,EAAE,EAAE;MACLC,CAAC,EAAE,GAAG;MACNC,KAAK,EAAE,EAAE;MACTC,KAAK,EAAE,GAAG;MACVC,KAAK,EAAE,GAAG;MACVC,MAAM,EAAE;IACT,CAAC;IAED,MAAME,MAAM,GAAG,IAAAC,iCAAuB,EAAC;MAAET,KAAK;MAAEO,GAAG;MAAEG,QAAQ,EAAE;IAAK,CAAC,CAAC;IAEtE,IAAAC,eAAM,EAACH,MAAM,CAACI,EAAE,CAAC,CAACC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAC7B,IAAAF,eAAM,EAACH,M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CAAC;MAAEC,KAAK,EAAE,CAAC;MAAEC,KAAK,EAAE,CAAC;MAAEC,MAAM,EAAE;IAAI,CAAC;IACvE,MAAMC,GAAG,GAAG;MAAEN,CAAC,EAAE,CAAC;MAAEC,CAAC,EAAE,CAAC;MAAEC,KAAK,EAAE,CAAC;MAAEC,KAAK,EAAE,CAAC;MAAEC,KAAK,EAAE,GAAG;MAAEC,MAAM,EAAE;IAAI,CAAC;;IAEvE;IACA,MAAME,MAAM,GAAG,IAAAc,yCAA+B,EAAC;MAC9CtB,KAAK;MACLO,GAAG;MACHG,QAAQ,EAAE,IAAI;MACdS,UAAU;MACVI,gBAAgB,EAAE;IACnB,CAAC,CAAC;IAEF,IAAAZ,eAAM,EAACH,MAAM,CAACgB,CAAC,CAAC,CAACE,WAAW,CAAC,CAAC;IAC9B,IAAAf,eAAM,EAACgB,MAAM,CAACC,QAAQ,CAACpB,MAAM,CAACgB,CAAC,CAAC,CAAC,CAACX,IAAI,CAAC,IAAI,CAAC;EAC7C,CAAC,CAAC;AACH,CAAC,CAAC","ignoreList":[]}
@@ -1,178 +0,0 @@
1
- "use strict";
2
-
3
- import { describe, expect, it } from "bun:test";
4
- import { computeContentTransformGeometry, computeRelativeGeometry } from "../utils/bounds/geometry";
5
- describe("computeRelativeGeometry", () => {
6
- it("calculates correct relative geometry when entering", () => {
7
- const start = {
8
- x: 10,
9
- y: 20,
10
- pageX: 10,
11
- pageY: 20,
12
- width: 100,
13
- height: 200
14
- };
15
- const end = {
16
- x: 50,
17
- y: 100,
18
- pageX: 50,
19
- pageY: 100,
20
- width: 200,
21
- height: 400
22
- };
23
- const result = computeRelativeGeometry({
24
- start,
25
- end,
26
- entering: true
27
- });
28
- expect(result.dx).toBe(-90); // center diff X
29
- expect(result.dy).toBe(-180); // center diff Y
30
- expect(result.scaleX).toBe(0.5); // width ratio
31
- expect(result.scaleY).toBe(0.5); // height ratio
32
- expect(result.ranges).toEqual([0, 1]);
33
- expect(result.entering).toBe(true);
34
- });
35
- it("calculates correct relative geometry when exiting", () => {
36
- const start = {
37
- x: 0,
38
- y: 0,
39
- pageX: 10,
40
- pageY: 20,
41
- width: 100,
42
- height: 200
43
- };
44
- const end = {
45
- x: 0,
46
- y: 0,
47
- pageX: 50,
48
- pageY: 100,
49
- width: 200,
50
- height: 400
51
- };
52
- const result = computeRelativeGeometry({
53
- start,
54
- end,
55
- entering: false
56
- });
57
- expect(result.ranges).toEqual([1, 2]);
58
- expect(result.entering).toBe(false);
59
- });
60
- });
61
- describe("computeContentTransformGeometry", () => {
62
- const dimensions = {
63
- width: 375,
64
- height: 812,
65
- scale: 1,
66
- fontScale: 1
67
- };
68
- it("calculates transform with aspectFit mode", () => {
69
- const start = {
70
- x: 0,
71
- y: 0,
72
- pageX: 50,
73
- pageY: 100,
74
- width: 100,
75
- height: 100
76
- };
77
- const end = {
78
- x: 0,
79
- y: 0,
80
- pageX: 100,
81
- pageY: 200,
82
- width: 200,
83
- height: 50
84
- };
85
- const result = computeContentTransformGeometry({
86
- start,
87
- end,
88
- entering: true,
89
- dimensions,
90
- contentScaleMode: "aspectFit"
91
- });
92
- expect(result.s).toBe(0.5);
93
- expect(result.entering).toBe(true);
94
- expect(result.ranges).toEqual([0, 1]);
95
- });
96
- it("calculates transform with aspectFill mode", () => {
97
- const start = {
98
- x: 0,
99
- y: 0,
100
- pageX: 50,
101
- pageY: 100,
102
- width: 100,
103
- height: 100
104
- };
105
- const end = {
106
- x: 0,
107
- y: 0,
108
- pageX: 100,
109
- pageY: 200,
110
- width: 200,
111
- height: 50
112
- };
113
- const result = computeContentTransformGeometry({
114
- start,
115
- end,
116
- entering: true,
117
- dimensions,
118
- contentScaleMode: "aspectFill"
119
- });
120
- expect(result.s).toBe(2);
121
- });
122
- it("handles auto mode based on aspect ratio difference", () => {
123
- const start = {
124
- x: 0,
125
- y: 0,
126
- pageX: 0,
127
- pageY: 0,
128
- width: 100,
129
- height: 100
130
- };
131
- const end = {
132
- x: 0,
133
- y: 0,
134
- pageX: 0,
135
- pageY: 0,
136
- width: 200,
137
- height: 195
138
- };
139
- const result = computeContentTransformGeometry({
140
- start,
141
- end,
142
- entering: true,
143
- dimensions,
144
- contentScaleMode: "auto"
145
- });
146
- expect(result.s).toBeCloseTo(0.512, 2);
147
- });
148
- it("handles zero dimensions safely", () => {
149
- const start = {
150
- x: 0,
151
- y: 0,
152
- pageX: 0,
153
- pageY: 0,
154
- width: 0,
155
- height: 100
156
- };
157
- const end = {
158
- x: 0,
159
- y: 0,
160
- pageX: 0,
161
- pageY: 0,
162
- width: 200,
163
- height: 200
164
- };
165
-
166
- // Should not throw and use safe fallback
167
- const result = computeContentTransformGeometry({
168
- start,
169
- end,
170
- entering: true,
171
- dimensions,
172
- contentScaleMode: "aspectFit"
173
- });
174
- expect(result.s).toBeDefined();
175
- expect(Number.isFinite(result.s)).toBe(true);
176
- });
177
- });
178
- //# sourceMappingURL=geometry.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["describe","expect","it","computeContentTransformGeometry","computeRelativeGeometry","start","x","y","pageX","pageY","width","height","end","result","entering","dx","toBe","dy","scaleX","scaleY","ranges","toEqual","dimensions","scale","fontScale","contentScaleMode","s","toBeCloseTo","toBeDefined","Number","isFinite"],"sourceRoot":"../../../src","sources":["__tests__ /geometry.test.ts"],"mappings":";;AAAA,SAASA,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAQ,UAAU;AAC/C,SACCC,+BAA+B,EAC/BC,uBAAuB,QACjB,0BAA0B;AAEjCJ,QAAQ,CAAC,yBAAyB,EAAE,MAAM;EACzCE,EAAE,CAAC,oDAAoD,EAAE,MAAM;IAC9D,MAAMG,KAAK,GAAG;MACbC,CAAC,EAAE,EAAE;MACLC,CAAC,EAAE,EAAE;MACLC,KAAK,EAAE,EAAE;MACTC,KAAK,EAAE,EAAE;MACTC,KAAK,EAAE,GAAG;MACVC,MAAM,EAAE;IACT,CAAC;IACD,MAAMC,GAAG,GAAG;MACXN,CAAC,EAAE,EAAE;MACL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