react-native-screen-transitions 3.3.0-beta.2 → 3.3.0-beta.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.
- package/README.md +95 -31
- package/lib/commonjs/shared/animation/snap-to.js +17 -10
- package/lib/commonjs/shared/animation/snap-to.js.map +1 -1
- package/lib/commonjs/shared/components/create-transition-aware-component.js +20 -18
- package/lib/commonjs/shared/components/create-transition-aware-component.js.map +1 -1
- package/lib/commonjs/shared/components/screen-container.js +68 -9
- package/lib/commonjs/shared/components/screen-container.js.map +1 -1
- package/lib/commonjs/shared/constants.js +8 -1
- package/lib/commonjs/shared/constants.js.map +1 -1
- package/lib/commonjs/shared/hooks/gestures/use-build-gestures.js +49 -39
- package/lib/commonjs/shared/hooks/gestures/use-build-gestures.js.map +1 -1
- package/lib/commonjs/shared/hooks/gestures/use-screen-gesture-handlers.js +110 -61
- package/lib/commonjs/shared/hooks/gestures/use-screen-gesture-handlers.js.map +1 -1
- package/lib/commonjs/shared/hooks/gestures/use-scroll-registry.js +67 -70
- package/lib/commonjs/shared/hooks/gestures/use-scroll-registry.js.map +1 -1
- package/lib/commonjs/shared/providers/gestures.provider.js +113 -25
- package/lib/commonjs/shared/providers/gestures.provider.js.map +1 -1
- package/lib/commonjs/shared/types/ownership.types.js +71 -0
- package/lib/commonjs/shared/types/ownership.types.js.map +1 -0
- package/lib/commonjs/shared/utils/gesture/check-gesture-activation.js +72 -128
- package/lib/commonjs/shared/utils/gesture/check-gesture-activation.js.map +1 -1
- package/lib/commonjs/shared/utils/gesture/compute-claimed-directions.js +81 -0
- package/lib/commonjs/shared/utils/gesture/compute-claimed-directions.js.map +1 -0
- package/lib/commonjs/shared/utils/gesture/determine-snap-target.js +1 -1
- package/lib/commonjs/shared/utils/gesture/determine-snap-target.js.map +1 -1
- package/lib/commonjs/shared/utils/gesture/find-collapse-target.js +48 -0
- package/lib/commonjs/shared/utils/gesture/find-collapse-target.js.map +1 -0
- package/lib/commonjs/shared/utils/gesture/resolve-ownership.js +87 -0
- package/lib/commonjs/shared/utils/gesture/resolve-ownership.js.map +1 -0
- package/lib/commonjs/shared/utils/gesture/velocity.js +16 -5
- package/lib/commonjs/shared/utils/gesture/velocity.js.map +1 -1
- package/lib/module/shared/animation/snap-to.js +16 -10
- package/lib/module/shared/animation/snap-to.js.map +1 -1
- package/lib/module/shared/components/create-transition-aware-component.js +20 -18
- package/lib/module/shared/components/create-transition-aware-component.js.map +1 -1
- package/lib/module/shared/components/screen-container.js +68 -10
- package/lib/module/shared/components/screen-container.js.map +1 -1
- package/lib/module/shared/constants.js +7 -0
- package/lib/module/shared/constants.js.map +1 -1
- package/lib/module/shared/hooks/gestures/use-build-gestures.js +49 -39
- package/lib/module/shared/hooks/gestures/use-build-gestures.js.map +1 -1
- package/lib/module/shared/hooks/gestures/use-screen-gesture-handlers.js +112 -63
- package/lib/module/shared/hooks/gestures/use-screen-gesture-handlers.js.map +1 -1
- package/lib/module/shared/hooks/gestures/use-scroll-registry.js +68 -70
- package/lib/module/shared/hooks/gestures/use-scroll-registry.js.map +1 -1
- package/lib/module/shared/providers/gestures.provider.js +113 -25
- package/lib/module/shared/providers/gestures.provider.js.map +1 -1
- package/lib/module/shared/types/ownership.types.js +67 -0
- package/lib/module/shared/types/ownership.types.js.map +1 -0
- package/lib/module/shared/utils/gesture/check-gesture-activation.js +70 -126
- package/lib/module/shared/utils/gesture/check-gesture-activation.js.map +1 -1
- package/lib/module/shared/utils/gesture/compute-claimed-directions.js +77 -0
- package/lib/module/shared/utils/gesture/compute-claimed-directions.js.map +1 -0
- package/lib/module/shared/utils/gesture/determine-snap-target.js +1 -1
- package/lib/module/shared/utils/gesture/determine-snap-target.js.map +1 -1
- package/lib/module/shared/utils/gesture/find-collapse-target.js +44 -0
- package/lib/module/shared/utils/gesture/find-collapse-target.js.map +1 -0
- package/lib/module/shared/utils/gesture/resolve-ownership.js +83 -0
- package/lib/module/shared/utils/gesture/resolve-ownership.js.map +1 -0
- package/lib/module/shared/utils/gesture/velocity.js +16 -5
- package/lib/module/shared/utils/gesture/velocity.js.map +1 -1
- package/lib/typescript/shared/animation/snap-to.d.ts.map +1 -1
- package/lib/typescript/shared/components/create-transition-aware-component.d.ts.map +1 -1
- package/lib/typescript/shared/components/screen-container.d.ts.map +1 -1
- package/lib/typescript/shared/constants.d.ts +6 -0
- package/lib/typescript/shared/constants.d.ts.map +1 -1
- package/lib/typescript/shared/hooks/gestures/use-build-gestures.d.ts +15 -3
- package/lib/typescript/shared/hooks/gestures/use-build-gestures.d.ts.map +1 -1
- package/lib/typescript/shared/hooks/gestures/use-screen-gesture-handlers.d.ts +52 -2
- package/lib/typescript/shared/hooks/gestures/use-screen-gesture-handlers.d.ts.map +1 -1
- package/lib/typescript/shared/hooks/gestures/use-scroll-registry.d.ts +11 -6
- package/lib/typescript/shared/hooks/gestures/use-scroll-registry.d.ts.map +1 -1
- package/lib/typescript/shared/hooks/use-backdrop-pointer-events.d.ts +1 -1
- package/lib/typescript/shared/hooks/use-backdrop-pointer-events.d.ts.map +1 -1
- package/lib/typescript/shared/providers/gestures.provider.d.ts +28 -3
- package/lib/typescript/shared/providers/gestures.provider.d.ts.map +1 -1
- package/lib/typescript/shared/types/ownership.types.d.ts +52 -0
- package/lib/typescript/shared/types/ownership.types.d.ts.map +1 -0
- package/lib/typescript/shared/types/screen.types.d.ts +22 -1
- package/lib/typescript/shared/types/screen.types.d.ts.map +1 -1
- package/lib/typescript/shared/utils/gesture/check-gesture-activation.d.ts +23 -19
- package/lib/typescript/shared/utils/gesture/check-gesture-activation.d.ts.map +1 -1
- package/lib/typescript/shared/utils/gesture/compute-claimed-directions.d.ts +23 -0
- package/lib/typescript/shared/utils/gesture/compute-claimed-directions.d.ts.map +1 -0
- package/lib/typescript/shared/utils/gesture/determine-snap-target.d.ts +5 -1
- package/lib/typescript/shared/utils/gesture/determine-snap-target.d.ts.map +1 -1
- package/lib/typescript/shared/utils/gesture/find-collapse-target.d.ts +17 -0
- package/lib/typescript/shared/utils/gesture/find-collapse-target.d.ts.map +1 -0
- package/lib/typescript/shared/utils/gesture/resolve-ownership.d.ts +36 -0
- package/lib/typescript/shared/utils/gesture/resolve-ownership.d.ts.map +1 -0
- package/lib/typescript/shared/utils/gesture/velocity.d.ts.map +1 -1
- package/package.json +121 -120
- package/src/shared/animation/snap-to.ts +17 -11
- package/src/shared/components/create-transition-aware-component.tsx +28 -25
- package/src/shared/components/screen-container.tsx +79 -12
- package/src/shared/constants.ts +7 -0
- package/src/shared/hooks/gestures/use-build-gestures.tsx +80 -44
- package/src/shared/hooks/gestures/use-screen-gesture-handlers.ts +147 -71
- package/src/shared/hooks/gestures/use-scroll-registry.tsx +94 -86
- package/src/shared/hooks/use-backdrop-pointer-events.ts +1 -1
- package/src/shared/providers/gestures.provider.tsx +168 -25
- package/src/shared/types/ownership.types.ts +77 -0
- package/src/shared/types/screen.types.ts +24 -1
- package/src/shared/utils/gesture/check-gesture-activation.ts +82 -116
- package/src/shared/utils/gesture/compute-claimed-directions.ts +93 -0
- package/src/shared/utils/gesture/determine-snap-target.ts +6 -2
- package/src/shared/utils/gesture/find-collapse-target.ts +42 -0
- package/src/shared/utils/gesture/resolve-ownership.ts +110 -0
- package/src/shared/utils/gesture/velocity.ts +16 -6
- package/src/shared/__tests__/bounds.store.test.ts +0 -394
- package/src/shared/__tests__/derivations.test.ts +0 -156
- package/src/shared/__tests__/determine-dismissal.test.ts +0 -111
- package/src/shared/__tests__/determine-snap-target.test.ts +0 -268
- package/src/shared/__tests__/geometry.test.ts +0 -130
- package/src/shared/__tests__/gesture-activation.test.ts +0 -471
- package/src/shared/__tests__/gesture.velocity.test.ts +0 -131
- package/src/shared/__tests__/history.store.test.ts +0 -550
- package/src/shared/__tests__/sync-routes-with-removed.test.ts +0 -137
- package/src/shared/__tests__/validate-snap-points.test.ts +0 -125
|
@@ -1,268 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "bun:test";
|
|
2
|
-
import { determineSnapTarget } from "../utils/gesture/determine-snap-target";
|
|
3
|
-
|
|
4
|
-
describe("determineSnapTarget", () => {
|
|
5
|
-
const dimension = 800; // screen height
|
|
6
|
-
const snapPoints = [0.3, 0.6, 1]; // 3 snap points
|
|
7
|
-
|
|
8
|
-
describe("basic snapping without velocity", () => {
|
|
9
|
-
it("snaps to nearest snap point when exactly at a snap point", () => {
|
|
10
|
-
const result = determineSnapTarget({
|
|
11
|
-
currentProgress: 0.6,
|
|
12
|
-
snapPoints,
|
|
13
|
-
velocity: 0,
|
|
14
|
-
dimension,
|
|
15
|
-
});
|
|
16
|
-
expect(result.targetProgress).toBe(0.6);
|
|
17
|
-
expect(result.shouldDismiss).toBe(false);
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it("snaps to lower snap point when below midpoint", () => {
|
|
21
|
-
// Midpoint between 0.3 and 0.6 is 0.45
|
|
22
|
-
const result = determineSnapTarget({
|
|
23
|
-
currentProgress: 0.4,
|
|
24
|
-
snapPoints,
|
|
25
|
-
velocity: 0,
|
|
26
|
-
dimension,
|
|
27
|
-
});
|
|
28
|
-
expect(result.targetProgress).toBe(0.3);
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it("snaps to higher snap point when above midpoint", () => {
|
|
32
|
-
// Midpoint between 0.3 and 0.6 is 0.45
|
|
33
|
-
const result = determineSnapTarget({
|
|
34
|
-
currentProgress: 0.5,
|
|
35
|
-
snapPoints,
|
|
36
|
-
velocity: 0,
|
|
37
|
-
dimension,
|
|
38
|
-
});
|
|
39
|
-
expect(result.targetProgress).toBe(0.6);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it("snaps to highest point when above all snap points", () => {
|
|
43
|
-
const result = determineSnapTarget({
|
|
44
|
-
currentProgress: 1.2,
|
|
45
|
-
snapPoints,
|
|
46
|
-
velocity: 0,
|
|
47
|
-
dimension,
|
|
48
|
-
});
|
|
49
|
-
expect(result.targetProgress).toBe(1);
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
describe("velocity influence", () => {
|
|
54
|
-
it("velocity toward dismiss pushes toward lower snap point", () => {
|
|
55
|
-
// At 0.5 (above midpoint 0.45), normally would snap to 0.6
|
|
56
|
-
// But positive velocity (toward dismiss) should push toward 0.3
|
|
57
|
-
const result = determineSnapTarget({
|
|
58
|
-
currentProgress: 0.5,
|
|
59
|
-
snapPoints,
|
|
60
|
-
velocity: 800, // Strong velocity toward dismiss
|
|
61
|
-
dimension,
|
|
62
|
-
velocityFactor: 0.15,
|
|
63
|
-
});
|
|
64
|
-
expect(result.targetProgress).toBe(0.3);
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
it("velocity toward expand pushes toward higher snap point", () => {
|
|
68
|
-
// At 0.4 (below midpoint 0.45), normally would snap to 0.3
|
|
69
|
-
// But negative velocity (toward expand) should push toward 0.6
|
|
70
|
-
const result = determineSnapTarget({
|
|
71
|
-
currentProgress: 0.4,
|
|
72
|
-
snapPoints,
|
|
73
|
-
velocity: -800, // Strong velocity toward expand
|
|
74
|
-
dimension,
|
|
75
|
-
velocityFactor: 0.15,
|
|
76
|
-
});
|
|
77
|
-
expect(result.targetProgress).toBe(0.6);
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it("weak velocity does not override position", () => {
|
|
81
|
-
// At 0.55 (above midpoint), weak velocity shouldn't change target
|
|
82
|
-
const result = determineSnapTarget({
|
|
83
|
-
currentProgress: 0.55,
|
|
84
|
-
snapPoints,
|
|
85
|
-
velocity: 100, // Weak velocity
|
|
86
|
-
dimension,
|
|
87
|
-
velocityFactor: 0.15,
|
|
88
|
-
});
|
|
89
|
-
expect(result.targetProgress).toBe(0.6);
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
it("respects custom velocityFactor", () => {
|
|
93
|
-
// Higher velocityFactor = velocity has more influence
|
|
94
|
-
const result = determineSnapTarget({
|
|
95
|
-
currentProgress: 0.5,
|
|
96
|
-
snapPoints,
|
|
97
|
-
velocity: 400,
|
|
98
|
-
dimension,
|
|
99
|
-
velocityFactor: 0.5, // High factor
|
|
100
|
-
});
|
|
101
|
-
expect(result.targetProgress).toBe(0.3);
|
|
102
|
-
});
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
describe("dismiss behavior", () => {
|
|
106
|
-
it("allows dismiss when canDismiss is true and near 0", () => {
|
|
107
|
-
const result = determineSnapTarget({
|
|
108
|
-
currentProgress: 0.1,
|
|
109
|
-
snapPoints,
|
|
110
|
-
velocity: 500,
|
|
111
|
-
dimension,
|
|
112
|
-
canDismiss: true,
|
|
113
|
-
});
|
|
114
|
-
expect(result.targetProgress).toBe(0);
|
|
115
|
-
expect(result.shouldDismiss).toBe(true);
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
it("prevents dismiss when canDismiss is false", () => {
|
|
119
|
-
const result = determineSnapTarget({
|
|
120
|
-
currentProgress: 0.1,
|
|
121
|
-
snapPoints,
|
|
122
|
-
velocity: 1000, // Strong dismiss velocity
|
|
123
|
-
dimension,
|
|
124
|
-
canDismiss: false,
|
|
125
|
-
});
|
|
126
|
-
expect(result.targetProgress).toBe(0.3); // First snap point
|
|
127
|
-
expect(result.shouldDismiss).toBe(false);
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
it("defaults canDismiss to true", () => {
|
|
131
|
-
const result = determineSnapTarget({
|
|
132
|
-
currentProgress: 0.1,
|
|
133
|
-
snapPoints,
|
|
134
|
-
velocity: 500,
|
|
135
|
-
dimension,
|
|
136
|
-
});
|
|
137
|
-
expect(result.shouldDismiss).toBe(true);
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
it("shouldDismiss is false when snapping to any snap point", () => {
|
|
141
|
-
const result = determineSnapTarget({
|
|
142
|
-
currentProgress: 0.5,
|
|
143
|
-
snapPoints,
|
|
144
|
-
velocity: 0,
|
|
145
|
-
dimension,
|
|
146
|
-
});
|
|
147
|
-
expect(result.shouldDismiss).toBe(false);
|
|
148
|
-
});
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
describe("edge cases", () => {
|
|
152
|
-
it("handles single snap point", () => {
|
|
153
|
-
const result = determineSnapTarget({
|
|
154
|
-
currentProgress: 0.3,
|
|
155
|
-
snapPoints: [0.5],
|
|
156
|
-
velocity: 0,
|
|
157
|
-
dimension,
|
|
158
|
-
});
|
|
159
|
-
expect(result.targetProgress).toBe(0.5);
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
it("handles unsorted snap points", () => {
|
|
163
|
-
const result = determineSnapTarget({
|
|
164
|
-
currentProgress: 0.5,
|
|
165
|
-
snapPoints: [1, 0.3, 0.6], // Unsorted
|
|
166
|
-
velocity: 0,
|
|
167
|
-
dimension,
|
|
168
|
-
});
|
|
169
|
-
// After sorting: [0.3, 0.6, 1], midpoint 0.3-0.6 is 0.45
|
|
170
|
-
expect(result.targetProgress).toBe(0.6);
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
it("handles progress at exactly 0", () => {
|
|
174
|
-
const result = determineSnapTarget({
|
|
175
|
-
currentProgress: 0,
|
|
176
|
-
snapPoints,
|
|
177
|
-
velocity: 0,
|
|
178
|
-
dimension,
|
|
179
|
-
canDismiss: true,
|
|
180
|
-
});
|
|
181
|
-
expect(result.targetProgress).toBe(0);
|
|
182
|
-
expect(result.shouldDismiss).toBe(true);
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
it("handles negative progress", () => {
|
|
186
|
-
const result = determineSnapTarget({
|
|
187
|
-
currentProgress: -0.1,
|
|
188
|
-
snapPoints,
|
|
189
|
-
velocity: 0,
|
|
190
|
-
dimension,
|
|
191
|
-
canDismiss: true,
|
|
192
|
-
});
|
|
193
|
-
expect(result.targetProgress).toBe(0);
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
it("handles very high velocity", () => {
|
|
197
|
-
const result = determineSnapTarget({
|
|
198
|
-
currentProgress: 0.9,
|
|
199
|
-
snapPoints,
|
|
200
|
-
velocity: 5000, // Very high velocity
|
|
201
|
-
dimension,
|
|
202
|
-
canDismiss: true,
|
|
203
|
-
});
|
|
204
|
-
expect(result.targetProgress).toBe(0);
|
|
205
|
-
expect(result.shouldDismiss).toBe(true);
|
|
206
|
-
});
|
|
207
|
-
|
|
208
|
-
it("handles snap points not starting at typical values", () => {
|
|
209
|
-
const result = determineSnapTarget({
|
|
210
|
-
currentProgress: 0.7,
|
|
211
|
-
snapPoints: [0.5, 0.75, 1],
|
|
212
|
-
velocity: 0,
|
|
213
|
-
dimension,
|
|
214
|
-
});
|
|
215
|
-
// Midpoint between 0.5 and 0.75 is 0.625
|
|
216
|
-
// 0.7 is above 0.625, so should snap to 0.75
|
|
217
|
-
expect(result.targetProgress).toBe(0.75);
|
|
218
|
-
});
|
|
219
|
-
|
|
220
|
-
it("handles two snap points", () => {
|
|
221
|
-
const result = determineSnapTarget({
|
|
222
|
-
currentProgress: 0.4,
|
|
223
|
-
snapPoints: [0.3, 1],
|
|
224
|
-
velocity: 0,
|
|
225
|
-
dimension,
|
|
226
|
-
});
|
|
227
|
-
// Midpoint is 0.65, 0.4 is below, so snap to 0.3
|
|
228
|
-
expect(result.targetProgress).toBe(0.3);
|
|
229
|
-
});
|
|
230
|
-
});
|
|
231
|
-
|
|
232
|
-
describe("zone boundaries", () => {
|
|
233
|
-
it("snaps to higher at exact midpoint (uses < not <=)", () => {
|
|
234
|
-
// Midpoint between 0 and 0.3 is 0.15
|
|
235
|
-
// The algorithm uses `<` so at exact midpoint, it snaps to higher
|
|
236
|
-
const result = determineSnapTarget({
|
|
237
|
-
currentProgress: 0.15,
|
|
238
|
-
snapPoints,
|
|
239
|
-
velocity: 0,
|
|
240
|
-
dimension,
|
|
241
|
-
canDismiss: true,
|
|
242
|
-
});
|
|
243
|
-
expect(result.targetProgress).toBe(0.3);
|
|
244
|
-
});
|
|
245
|
-
|
|
246
|
-
it("snaps to lower just below midpoint", () => {
|
|
247
|
-
const result = determineSnapTarget({
|
|
248
|
-
currentProgress: 0.149,
|
|
249
|
-
snapPoints,
|
|
250
|
-
velocity: 0,
|
|
251
|
-
dimension,
|
|
252
|
-
canDismiss: true,
|
|
253
|
-
});
|
|
254
|
-
expect(result.targetProgress).toBe(0);
|
|
255
|
-
});
|
|
256
|
-
|
|
257
|
-
it("snaps to higher just above midpoint", () => {
|
|
258
|
-
const result = determineSnapTarget({
|
|
259
|
-
currentProgress: 0.151,
|
|
260
|
-
snapPoints,
|
|
261
|
-
velocity: 0,
|
|
262
|
-
dimension,
|
|
263
|
-
canDismiss: true,
|
|
264
|
-
});
|
|
265
|
-
expect(result.targetProgress).toBe(0.3);
|
|
266
|
-
});
|
|
267
|
-
});
|
|
268
|
-
});
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "bun:test";
|
|
2
|
-
import {
|
|
3
|
-
computeContentTransformGeometry,
|
|
4
|
-
computeRelativeGeometry,
|
|
5
|
-
} from "../utils/bounds/helpers/geometry";
|
|
6
|
-
|
|
7
|
-
describe("computeRelativeGeometry", () => {
|
|
8
|
-
it("calculates correct relative geometry when entering", () => {
|
|
9
|
-
const start = {
|
|
10
|
-
x: 10,
|
|
11
|
-
y: 20,
|
|
12
|
-
pageX: 10,
|
|
13
|
-
pageY: 20,
|
|
14
|
-
width: 100,
|
|
15
|
-
height: 200,
|
|
16
|
-
};
|
|
17
|
-
const end = {
|
|
18
|
-
x: 50,
|
|
19
|
-
y: 100,
|
|
20
|
-
pageX: 50,
|
|
21
|
-
pageY: 100,
|
|
22
|
-
width: 200,
|
|
23
|
-
height: 400,
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
const result = computeRelativeGeometry({ start, end, 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.entering).toBe(true);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it("calculates correct relative geometry when exiting", () => {
|
|
36
|
-
const start = { x: 0, y: 0, pageX: 10, pageY: 20, width: 100, height: 200 };
|
|
37
|
-
const end = { x: 0, y: 0, pageX: 50, pageY: 100, width: 200, height: 400 };
|
|
38
|
-
|
|
39
|
-
const result = computeRelativeGeometry({ start, end, entering: false });
|
|
40
|
-
|
|
41
|
-
expect(result.entering).toBe(false);
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
describe("computeContentTransformGeometry", () => {
|
|
46
|
-
const dimensions = { width: 375, height: 812, scale: 1, fontScale: 1 };
|
|
47
|
-
|
|
48
|
-
it("uniform chooses min scale when aspect ratio differs significantly", () => {
|
|
49
|
-
const start = {
|
|
50
|
-
x: 0,
|
|
51
|
-
y: 0,
|
|
52
|
-
pageX: 50,
|
|
53
|
-
pageY: 100,
|
|
54
|
-
width: 100,
|
|
55
|
-
height: 100,
|
|
56
|
-
};
|
|
57
|
-
const end = { x: 0, y: 0, pageX: 100, pageY: 200, width: 200, height: 50 };
|
|
58
|
-
|
|
59
|
-
const result = computeContentTransformGeometry({
|
|
60
|
-
start,
|
|
61
|
-
end,
|
|
62
|
-
entering: true,
|
|
63
|
-
dimensions,
|
|
64
|
-
anchor: "center",
|
|
65
|
-
scaleMode: "uniform",
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
expect(result.s).toBe(0.5);
|
|
69
|
-
expect(result.entering).toBe(true);
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it("calculates transform with match mode (average of sx/sy)", () => {
|
|
73
|
-
const start = {
|
|
74
|
-
x: 0,
|
|
75
|
-
y: 0,
|
|
76
|
-
pageX: 50,
|
|
77
|
-
pageY: 100,
|
|
78
|
-
width: 100,
|
|
79
|
-
height: 100,
|
|
80
|
-
};
|
|
81
|
-
const end = { x: 0, y: 0, pageX: 100, pageY: 200, width: 200, height: 50 };
|
|
82
|
-
|
|
83
|
-
const result = computeContentTransformGeometry({
|
|
84
|
-
start,
|
|
85
|
-
end,
|
|
86
|
-
entering: true,
|
|
87
|
-
dimensions,
|
|
88
|
-
anchor: "center",
|
|
89
|
-
// match mode uses the average of sx and sy
|
|
90
|
-
scaleMode: "match",
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
// sx = 100/200 = 0.5, sy = 100/50 = 2 -> (0.5 + 2) / 2 = 1.25
|
|
94
|
-
expect(result.s).toBeCloseTo(1.25, 5);
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
it("uniform chooses max scale when aspect ratios are similar", () => {
|
|
98
|
-
const start = { x: 0, y: 0, pageX: 0, pageY: 0, width: 100, height: 100 };
|
|
99
|
-
const end = { x: 0, y: 0, pageX: 0, pageY: 0, width: 200, height: 195 };
|
|
100
|
-
|
|
101
|
-
const result = computeContentTransformGeometry({
|
|
102
|
-
start,
|
|
103
|
-
end,
|
|
104
|
-
entering: true,
|
|
105
|
-
dimensions,
|
|
106
|
-
anchor: "center",
|
|
107
|
-
scaleMode: "uniform",
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
expect(result.s).toBeCloseTo(0.512, 2);
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
it("handles zero dimensions safely", () => {
|
|
114
|
-
const start = { x: 0, y: 0, pageX: 0, pageY: 0, width: 0, height: 100 };
|
|
115
|
-
const end = { x: 0, y: 0, pageX: 0, pageY: 0, width: 200, height: 200 };
|
|
116
|
-
|
|
117
|
-
// Should not throw and use safe fallback
|
|
118
|
-
const result = computeContentTransformGeometry({
|
|
119
|
-
start,
|
|
120
|
-
end,
|
|
121
|
-
entering: true,
|
|
122
|
-
dimensions,
|
|
123
|
-
anchor: "center",
|
|
124
|
-
scaleMode: "uniform",
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
expect(result.s).toBeDefined();
|
|
128
|
-
expect(Number.isFinite(result.s)).toBe(true);
|
|
129
|
-
});
|
|
130
|
-
});
|