@akanjs/next 0.0.52 → 0.0.54

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.
@@ -1,27 +1,16 @@
1
1
  "use client";
2
2
  import {
3
- type CsrContextType,
4
- type CsrTransitionStyles,
5
3
  defaultPageState,
6
4
  device,
7
- LocationState,
8
- PathRoute,
9
- type RouteGuide,
10
- router,
11
- type RouterInstance,
12
- type RouteState,
13
- type TransitionType,
14
- type UseCsrTransition,
5
+ router
15
6
  } from "@akanjs/client";
16
7
  import { App } from "@capacitor/app";
17
8
  import { useSpringValue } from "@react-spring/web";
18
9
  import { useDrag } from "@use-gesture/react";
19
10
  import { useCallback, useEffect, useMemo, useRef, useState } from "react";
20
-
21
11
  import { useHistory } from "./useHistory";
22
12
  import { useLocation } from "./useLocation";
23
-
24
- const useNoneTrans = ({ clientHeight, location, prevLocation }: RouteState): UseCsrTransition => {
13
+ const useNoneTrans = ({ clientHeight, location, prevLocation }) => {
25
14
  const transDirection = "none";
26
15
  const transUnit = useSpringValue(0, { config: { clamp: true } });
27
16
  const transUnitRange = useMemo(() => [0, 0], []);
@@ -29,59 +18,58 @@ const useNoneTrans = ({ clientHeight, location, prevLocation }: RouteState): Use
29
18
  const transPercent = transUnit.to((unit) => 100);
30
19
  const pageState = location.pathRoute.pageState;
31
20
  const prevPageState = prevLocation?.pathRoute.pageState ?? defaultPageState;
32
- const csrTranstionStyles: CsrTransitionStyles = {
21
+ const csrTranstionStyles = {
33
22
  topSafeArea: {
34
23
  containerStyle: {
35
- height: pageState.topSafeArea,
36
- },
24
+ height: pageState.topSafeArea
25
+ }
37
26
  },
38
27
  bottomSafeArea: {
39
28
  containerStyle: {
40
29
  top: clientHeight - pageState.bottomSafeArea,
41
- height: pageState.bottomSafeArea,
42
- },
30
+ height: pageState.bottomSafeArea
31
+ }
43
32
  },
44
33
  page: {
45
34
  containerStyle: {},
46
35
  contentStyle: {
47
36
  paddingTop: pageState.topSafeArea + pageState.topInset,
48
37
  paddingBottom: pageState.bottomInset + pageState.bottomSafeArea,
49
- height: clientHeight,
50
- },
38
+ height: clientHeight
39
+ }
51
40
  },
52
41
  prevPage: {
53
42
  containerStyle: {
54
- paddingTop: prevPageState.topSafeArea + prevPageState.topInset,
43
+ paddingTop: prevPageState.topSafeArea + prevPageState.topInset
55
44
  },
56
- contentStyle: { opacity: 0 },
45
+ contentStyle: { opacity: 0 }
57
46
  },
58
47
  topInset: {
59
48
  containerStyle: {
60
49
  top: pageState.topSafeArea,
61
- height: pageState.topInset,
50
+ height: pageState.topInset
62
51
  },
63
52
  contentStyle: { opacity: 1 },
64
- prevContentStyle: { opacity: 0 },
53
+ prevContentStyle: { opacity: 0 }
65
54
  },
66
55
  topLeftAction: {
67
56
  containerStyle: {
68
57
  top: pageState.topSafeArea,
69
- height: pageState.topInset,
58
+ height: pageState.topInset
70
59
  },
71
60
  contentStyle: { opacity: 1 },
72
- prevContentStyle: { opacity: 0 },
61
+ prevContentStyle: { opacity: 0 }
73
62
  },
74
63
  bottomInset: {
75
64
  containerStyle: {
76
65
  height: pageState.bottomInset,
77
- top: clientHeight - pageState.bottomInset - pageState.bottomSafeArea,
66
+ top: clientHeight - pageState.bottomInset - pageState.bottomSafeArea
78
67
  },
79
68
  contentStyle: { opacity: 1 },
80
- prevContentStyle: { opacity: 0 },
81
- },
69
+ prevContentStyle: { opacity: 0 }
70
+ }
82
71
  };
83
-
84
- const useCsrTransition: UseCsrTransition = {
72
+ const useCsrTransition = {
85
73
  ...csrTranstionStyles,
86
74
  pageBind: () => ({}),
87
75
  pageClassName: "touch-pan-y",
@@ -89,12 +77,11 @@ const useNoneTrans = ({ clientHeight, location, prevLocation }: RouteState): Use
89
77
  transUnitRange,
90
78
  transUnit,
91
79
  transPercent,
92
- transProgress,
80
+ transProgress
93
81
  };
94
82
  return useCsrTransition;
95
83
  };
96
-
97
- const useFadeTrans = ({ clientHeight, location, prevLocation, onBack, history }: RouteState): UseCsrTransition => {
84
+ const useFadeTrans = ({ clientHeight, location, prevLocation, onBack, history }) => {
98
85
  const transDirection = "none";
99
86
  const transUnit = useSpringValue(1, { config: { clamp: true } });
100
87
  const transUnitRange = useMemo(() => [0, 1], []);
@@ -102,7 +89,6 @@ const useFadeTrans = ({ clientHeight, location, prevLocation, onBack, history }:
102
89
  const transPercent = transUnit.to([0, 1], [0, 100], "clamp");
103
90
  const pageState = location.pathRoute.pageState;
104
91
  const prevPageState = prevLocation?.pathRoute.pageState ?? defaultPageState;
105
-
106
92
  useEffect(() => {
107
93
  onBack.current.fade = async () => {
108
94
  await transUnit.start(transUnitRange[0]);
@@ -117,12 +103,11 @@ const useFadeTrans = ({ clientHeight, location, prevLocation, onBack, history }:
117
103
  return;
118
104
  }
119
105
  }, [location.pathname]);
120
-
121
- const csrTranstionStyles: CsrTransitionStyles = {
106
+ const csrTranstionStyles = {
122
107
  topSafeArea: {
123
108
  containerStyle: {
124
- height: transProgress.to([0, 1], [prevPageState.topSafeArea, pageState.topSafeArea]),
125
- },
109
+ height: transProgress.to([0, 1], [prevPageState.topSafeArea, pageState.topSafeArea])
110
+ }
126
111
  },
127
112
  bottomSafeArea: {
128
113
  containerStyle: {
@@ -130,8 +115,8 @@ const useFadeTrans = ({ clientHeight, location, prevLocation, onBack, history }:
130
115
  [0, 1],
131
116
  [clientHeight - prevPageState.bottomSafeArea, clientHeight - pageState.bottomSafeArea]
132
117
  ),
133
- height: transProgress.to([0, 1], [prevPageState.bottomSafeArea, pageState.bottomSafeArea]),
134
- },
118
+ height: transProgress.to([0, 1], [prevPageState.bottomSafeArea, pageState.bottomSafeArea])
119
+ }
135
120
  },
136
121
  page: {
137
122
  containerStyle: {},
@@ -139,39 +124,39 @@ const useFadeTrans = ({ clientHeight, location, prevLocation, onBack, history }:
139
124
  paddingTop: pageState.topSafeArea + pageState.topInset,
140
125
  paddingBottom: pageState.bottomInset + pageState.bottomSafeArea,
141
126
  opacity: transUnit,
142
- height: clientHeight,
143
- },
127
+ height: clientHeight
128
+ }
144
129
  },
145
130
  prevPage: {
146
131
  containerStyle: {
147
132
  paddingTop: prevPageState.topSafeArea + prevPageState.topInset,
148
- opacity: transProgress.to((progress) => 1 - progress),
133
+ opacity: transProgress.to((progress) => 1 - progress)
149
134
  },
150
- contentStyle: {},
135
+ contentStyle: {}
151
136
  },
152
137
  topInset: {
153
138
  containerStyle: {
154
139
  top: transProgress.to([0, 1], [prevPageState.topSafeArea, pageState.topSafeArea]),
155
- height: transProgress.to([0, 1], [prevPageState.topInset, pageState.topInset]),
140
+ height: transProgress.to([0, 1], [prevPageState.topInset, pageState.topInset])
156
141
  },
157
142
  contentStyle: {
158
- opacity: transProgress,
143
+ opacity: transProgress
159
144
  },
160
145
  prevContentStyle: {
161
- opacity: transProgress.to((progress) => 1 - progress),
162
- },
146
+ opacity: transProgress.to((progress) => 1 - progress)
147
+ }
163
148
  },
164
149
  topLeftAction: {
165
150
  containerStyle: {
166
151
  top: transProgress.to([0, 1], [prevPageState.topSafeArea, pageState.topSafeArea]),
167
- height: transProgress.to([0, 1], [prevPageState.topInset, pageState.topInset]),
152
+ height: transProgress.to([0, 1], [prevPageState.topInset, pageState.topInset])
168
153
  },
169
154
  contentStyle: {
170
- opacity: transProgress.to((progress) => progress),
155
+ opacity: transProgress.to((progress) => progress)
171
156
  },
172
157
  prevContentStyle: {
173
- opacity: transProgress.to((progress) => 1 - progress),
174
- },
158
+ opacity: transProgress.to((progress) => 1 - progress)
159
+ }
175
160
  },
176
161
  bottomInset: {
177
162
  containerStyle: {
@@ -180,22 +165,21 @@ const useFadeTrans = ({ clientHeight, location, prevLocation, onBack, history }:
180
165
  [0, 1],
181
166
  [
182
167
  clientHeight - prevPageState.bottomInset - prevPageState.bottomSafeArea,
183
- clientHeight - pageState.bottomInset - pageState.bottomSafeArea,
168
+ clientHeight - pageState.bottomInset - pageState.bottomSafeArea
184
169
  ]
185
- ),
170
+ )
186
171
  },
187
172
  contentStyle: {
188
173
  top: transProgress.to([0, 1], [0, -(pageState.bottomInset - prevPageState.bottomInset) * 2]),
189
- opacity: transProgress.to((progress) => progress),
174
+ opacity: transProgress.to((progress) => progress)
190
175
  },
191
176
  prevContentStyle: {
192
177
  top: transProgress.to([0, 1], [0, -(pageState.bottomInset - prevPageState.bottomInset) * 2]),
193
- opacity: transProgress.to((progress) => 1 - progress),
194
- },
195
- },
178
+ opacity: transProgress.to((progress) => 1 - progress)
179
+ }
180
+ }
196
181
  };
197
-
198
- const useCsrTransition: UseCsrTransition = {
182
+ const useCsrTransition = {
199
183
  ...csrTranstionStyles,
200
184
  pageBind: () => ({}),
201
185
  pageClassName: "",
@@ -203,19 +187,18 @@ const useFadeTrans = ({ clientHeight, location, prevLocation, onBack, history }:
203
187
  transUnitRange,
204
188
  transUnit,
205
189
  transPercent,
206
- transProgress,
190
+ transProgress
207
191
  };
208
192
  return useCsrTransition;
209
193
  };
210
-
211
194
  const useStackTrans = ({
212
195
  clientWidth,
213
196
  clientHeight,
214
197
  location,
215
198
  prevLocation,
216
199
  history,
217
- onBack,
218
- }: RouteState): UseCsrTransition => {
200
+ onBack
201
+ }) => {
219
202
  const transDirection = "horizontal";
220
203
  const transUnit = useSpringValue(0, { config: { clamp: true } });
221
204
  const transUnitRange = useMemo(() => [clientWidth, 0], []);
@@ -242,28 +225,32 @@ const useStackTrans = ({
242
225
  return;
243
226
  }
244
227
  }, [location.pathname]);
245
-
246
228
  const pageBind = useDrag(
247
229
  ({ first, down, last, movement: [mx], initial: [ix], cancel }) => {
248
- if (first) void device.hideKeyboard();
230
+ if (first)
231
+ void device.hideKeyboard();
249
232
  if (ix > initThreshold) {
250
233
  cancel();
251
234
  return;
252
235
  }
253
- if (mx < transUnitRange[1]) void transUnit.start(transUnitRange[1], { immediate: true });
254
- else if (mx > transUnitRange[0]) void transUnit.start(transUnitRange[0], { immediate: true });
255
- else if (!last) void transUnit.start(mx, { immediate: true });
256
- else if (mx < threshold) void transUnit.start(transUnitRange[1]);
257
- if (last && mx > threshold) router.back();
236
+ if (mx < transUnitRange[1])
237
+ void transUnit.start(transUnitRange[1], { immediate: true });
238
+ else if (mx > transUnitRange[0])
239
+ void transUnit.start(transUnitRange[0], { immediate: true });
240
+ else if (!last)
241
+ void transUnit.start(mx, { immediate: true });
242
+ else if (mx < threshold)
243
+ void transUnit.start(transUnitRange[1]);
244
+ if (last && mx > threshold)
245
+ router.back();
258
246
  },
259
247
  { axis: "x", filterTaps: true }
260
248
  );
261
-
262
- const csrTranstionStyles: CsrTransitionStyles = {
249
+ const csrTranstionStyles = {
263
250
  topSafeArea: {
264
251
  containerStyle: {
265
- height: transProgress.to([0, 1], [prevPageState.topSafeArea, pageState.topSafeArea]),
266
- },
252
+ height: transProgress.to([0, 1], [prevPageState.topSafeArea, pageState.topSafeArea])
253
+ }
267
254
  },
268
255
  bottomSafeArea: {
269
256
  containerStyle: {
@@ -271,8 +258,8 @@ const useStackTrans = ({
271
258
  [0, 1],
272
259
  [clientHeight - prevPageState.bottomSafeArea, clientHeight - pageState.bottomSafeArea]
273
260
  ),
274
- height: transProgress.to([0, 1], [prevPageState.bottomSafeArea, pageState.bottomSafeArea]),
275
- },
261
+ height: transProgress.to([0, 1], [prevPageState.bottomSafeArea, pageState.bottomSafeArea])
262
+ }
276
263
  },
277
264
  page: {
278
265
  containerStyle: {},
@@ -280,44 +267,44 @@ const useStackTrans = ({
280
267
  paddingTop: pageState.topSafeArea + pageState.topInset,
281
268
  paddingBottom: pageState.bottomInset + pageState.bottomSafeArea,
282
269
  translateX: transUnit,
283
- height: clientHeight,
284
- },
270
+ height: clientHeight
271
+ }
285
272
  },
286
273
  prevPage: {
287
274
  containerStyle: {
288
275
  paddingTop: prevPageState.topSafeArea + prevPageState.topInset,
289
- translateX: transUnit.to((unit) => (unit - clientWidth) / 5),
276
+ translateX: transUnit.to((unit) => (unit - clientWidth) / 5)
290
277
  },
291
278
  contentStyle: {
292
- opacity: transProgress.to((progress) => 1 - progress / 2),
293
- },
279
+ opacity: transProgress.to((progress) => 1 - progress / 2)
280
+ }
294
281
  },
295
282
  topInset: {
296
283
  containerStyle: {
297
284
  top: transProgress.to([0, 1], [prevPageState.topSafeArea, pageState.topSafeArea]),
298
- height: transProgress.to([0, 1], [prevPageState.topInset, pageState.topInset]),
285
+ height: transProgress.to([0, 1], [prevPageState.topInset, pageState.topInset])
299
286
  },
300
287
  contentStyle: {
301
288
  opacity: transProgress.to((progress) => progress),
302
- translateX: transProgress.to([0, 1], [clientWidth / 5, 0]),
289
+ translateX: transProgress.to([0, 1], [clientWidth / 5, 0])
303
290
  },
304
291
  prevContentStyle: {
305
292
  opacity: transProgress.to((progress) => 1 - progress),
306
- translateX: transProgress.to([0, 1], [0, -clientWidth / 5]),
307
- },
293
+ translateX: transProgress.to([0, 1], [0, -clientWidth / 5])
294
+ }
308
295
  },
309
296
  topLeftAction: {
310
297
  containerStyle: {
311
298
  top: transProgress.to([0, 1], [prevPageState.topSafeArea, pageState.topSafeArea]),
312
299
  height: transProgress.to([0, 1], [prevPageState.topInset, pageState.topInset]),
313
- minWidth: transProgress.to([0, 1], [prevPageState.topInset, pageState.topInset]),
300
+ minWidth: transProgress.to([0, 1], [prevPageState.topInset, pageState.topInset])
314
301
  },
315
302
  contentStyle: {
316
- opacity: transProgress.to((progress) => progress),
303
+ opacity: transProgress.to((progress) => progress)
317
304
  },
318
305
  prevContentStyle: {
319
- opacity: transProgress.to((progress) => 1 - progress),
320
- },
306
+ opacity: transProgress.to((progress) => 1 - progress)
307
+ }
321
308
  },
322
309
  bottomInset: {
323
310
  containerStyle: {
@@ -326,22 +313,21 @@ const useStackTrans = ({
326
313
  [0, 1],
327
314
  [
328
315
  clientHeight - prevPageState.bottomInset - prevPageState.bottomSafeArea,
329
- clientHeight - pageState.bottomInset - pageState.bottomSafeArea,
316
+ clientHeight - pageState.bottomInset - pageState.bottomSafeArea
330
317
  ]
331
- ),
318
+ )
332
319
  },
333
320
  contentStyle: {
334
321
  top: transProgress.to([0, 1], [0, -(pageState.bottomInset - prevPageState.bottomInset) * 2]),
335
- opacity: transProgress.to((progress) => progress),
322
+ opacity: transProgress.to((progress) => progress)
336
323
  },
337
324
  prevContentStyle: {
338
325
  top: transProgress.to([0, 1], [0, -(pageState.bottomInset - prevPageState.bottomInset) * 2]),
339
- opacity: transProgress.to((progress) => 1 - progress),
340
- },
341
- },
326
+ opacity: transProgress.to((progress) => 1 - progress)
327
+ }
328
+ }
342
329
  };
343
-
344
- const useCsrTransition: UseCsrTransition = {
330
+ const useCsrTransition = {
345
331
  ...csrTranstionStyles,
346
332
  pageBind,
347
333
  pageClassName,
@@ -349,19 +335,18 @@ const useStackTrans = ({
349
335
  transUnitRange,
350
336
  transUnit,
351
337
  transPercent,
352
- transProgress,
338
+ transProgress
353
339
  };
354
340
  return useCsrTransition;
355
341
  };
356
-
357
342
  const useBottomUpTrans = ({
358
343
  clientWidth,
359
344
  clientHeight,
360
345
  history,
361
346
  location,
362
347
  prevLocation,
363
- onBack,
364
- }: RouteState): UseCsrTransition => {
348
+ onBack
349
+ }) => {
365
350
  const transDirection = "vertical";
366
351
  const transUnit = useSpringValue(0, { config: { clamp: true } });
367
352
  const transUnitRange = useMemo(() => [clientHeight, 0], []);
@@ -387,28 +372,32 @@ const useBottomUpTrans = ({
387
372
  return;
388
373
  }
389
374
  }, [location.pathname]);
390
-
391
375
  const pageBind = useDrag(
392
376
  ({ first, last, movement: [, my], initial: [, iy], cancel }) => {
393
- if (first) void device.hideKeyboard();
377
+ if (first)
378
+ void device.hideKeyboard();
394
379
  if (iy > initThreshold) {
395
380
  cancel();
396
381
  return;
397
382
  }
398
- if (my < transUnitRange[1]) void transUnit.start(transUnitRange[1], { immediate: true });
399
- else if (my > transUnitRange[0]) void transUnit.start(transUnitRange[0], { immediate: true });
400
- else if (!last) void transUnit.start(my, { immediate: true });
401
- else if (my < threshold) void transUnit.start(transUnitRange[1]);
402
- if (last && my > threshold) router.back();
383
+ if (my < transUnitRange[1])
384
+ void transUnit.start(transUnitRange[1], { immediate: true });
385
+ else if (my > transUnitRange[0])
386
+ void transUnit.start(transUnitRange[0], { immediate: true });
387
+ else if (!last)
388
+ void transUnit.start(my, { immediate: true });
389
+ else if (my < threshold)
390
+ void transUnit.start(transUnitRange[1]);
391
+ if (last && my > threshold)
392
+ router.back();
403
393
  },
404
394
  { axis: "y", filterTaps: true, threshold: 10 }
405
395
  );
406
-
407
- const csrTranstionStyles: CsrTransitionStyles = {
396
+ const csrTranstionStyles = {
408
397
  topSafeArea: {
409
398
  containerStyle: {
410
- height: transProgress.to([0, 1], [prevPageState.topSafeArea, pageState.topSafeArea]),
411
- },
399
+ height: transProgress.to([0, 1], [prevPageState.topSafeArea, pageState.topSafeArea])
400
+ }
412
401
  },
413
402
  bottomSafeArea: {
414
403
  containerStyle: {
@@ -416,8 +405,8 @@ const useBottomUpTrans = ({
416
405
  [0, 1],
417
406
  [clientHeight - prevPageState.bottomSafeArea, clientHeight - pageState.bottomSafeArea]
418
407
  ),
419
- height: transProgress.to([0, 1], [prevPageState.bottomSafeArea, pageState.bottomSafeArea]),
420
- },
408
+ height: transProgress.to([0, 1], [prevPageState.bottomSafeArea, pageState.bottomSafeArea])
409
+ }
421
410
  },
422
411
  page: {
423
412
  containerStyle: {},
@@ -425,43 +414,43 @@ const useBottomUpTrans = ({
425
414
  paddingTop: pageState.topSafeArea + pageState.topInset,
426
415
  paddingBottom: pageState.bottomInset + pageState.bottomSafeArea,
427
416
  translateY: transUnit,
428
- height: clientHeight,
429
- },
417
+ height: clientHeight
418
+ }
430
419
  },
431
420
  prevPage: {
432
421
  containerStyle: {
433
422
  paddingTop: prevPageState.topSafeArea + prevPageState.topInset,
434
- translateY: 0,
423
+ translateY: 0
435
424
  },
436
425
  contentStyle: {
437
- opacity: transProgress.to((progress) => 1 - progress / 2),
438
- },
426
+ opacity: transProgress.to((progress) => 1 - progress / 2)
427
+ }
439
428
  },
440
429
  topInset: {
441
430
  containerStyle: {
442
431
  top: transProgress.to([0, 1], [prevPageState.topSafeArea, pageState.topSafeArea]),
443
- height: transProgress.to([0, 1], [prevPageState.topInset, pageState.topInset]),
432
+ height: transProgress.to([0, 1], [prevPageState.topInset, pageState.topInset])
444
433
  },
445
434
  contentStyle: {
446
- opacity: transProgress.to((progress) => progress),
435
+ opacity: transProgress.to((progress) => progress)
447
436
  // translateX: transProgress.to([0, 1], [clientWidth / 5, 0]),
448
437
  },
449
438
  prevContentStyle: {
450
- opacity: transProgress.to((progress) => 1 - progress),
439
+ opacity: transProgress.to((progress) => 1 - progress)
451
440
  // translateX: transProgress.to([0, 1], [0, -clientWidth / 5]),
452
- },
441
+ }
453
442
  },
454
443
  topLeftAction: {
455
444
  containerStyle: {
456
445
  top: transProgress.to([0, 1], [prevPageState.topSafeArea, pageState.topSafeArea]),
457
- height: transProgress.to([0, 1], [prevPageState.topInset, pageState.topInset]),
446
+ height: transProgress.to([0, 1], [prevPageState.topInset, pageState.topInset])
458
447
  },
459
448
  contentStyle: {
460
- opacity: transProgress.to((progress) => progress),
449
+ opacity: transProgress.to((progress) => progress)
461
450
  },
462
451
  prevContentStyle: {
463
- opacity: transProgress.to((progress) => 1 - progress),
464
- },
452
+ opacity: transProgress.to((progress) => 1 - progress)
453
+ }
465
454
  },
466
455
  bottomInset: {
467
456
  containerStyle: {
@@ -470,22 +459,21 @@ const useBottomUpTrans = ({
470
459
  [0, 1],
471
460
  [
472
461
  clientHeight - prevPageState.bottomInset - prevPageState.bottomSafeArea,
473
- clientHeight - pageState.bottomInset - pageState.bottomSafeArea,
462
+ clientHeight - pageState.bottomInset - pageState.bottomSafeArea
474
463
  ]
475
- ),
464
+ )
476
465
  },
477
466
  contentStyle: {
478
467
  top: transProgress.to([0, 1], [0, -(pageState.bottomInset - prevPageState.bottomInset) * 2]),
479
- opacity: transProgress.to((progress) => progress),
468
+ opacity: transProgress.to((progress) => progress)
480
469
  },
481
470
  prevContentStyle: {
482
471
  top: transProgress.to([0, 1], [0, -(pageState.bottomInset - prevPageState.bottomInset) * 2]),
483
- opacity: transProgress.to((progress) => 1 - progress),
484
- },
485
- },
472
+ opacity: transProgress.to((progress) => 1 - progress)
473
+ }
474
+ }
486
475
  };
487
-
488
- const useCsrTransition: UseCsrTransition = {
476
+ const useCsrTransition = {
489
477
  ...csrTranstionStyles,
490
478
  pageBind,
491
479
  pageClassName: "touch-pan-x",
@@ -493,39 +481,37 @@ const useBottomUpTrans = ({
493
481
  transUnitRange,
494
482
  transUnit,
495
483
  transPercent,
496
- transProgress,
484
+ transProgress
497
485
  };
498
486
  return useCsrTransition;
499
487
  };
500
-
501
- export const useCsrValues = (rootRouteGuide: RouteGuide, pathRoutes: PathRoute[]) => {
488
+ const useCsrValues = (rootRouteGuide, pathRoutes) => {
502
489
  const clientWidth = useRef(window.innerWidth);
503
490
  const clientHeight = useRef(window.innerHeight);
504
- const topSafeAreaRef = useRef<HTMLDivElement>(null);
505
- const bottomSafeAreaRef = useRef<HTMLDivElement>(null);
506
- const pageContentRef = useRef<HTMLDivElement>(null);
507
- const prevPageContentRef = useRef<HTMLDivElement>(null);
508
- const onBack = useRef<{ [K in TransitionType]?: () => Promise<void> }>({});
509
- const frameRootRef = useRef<HTMLDivElement>(null);
510
-
491
+ const topSafeAreaRef = useRef(null);
492
+ const bottomSafeAreaRef = useRef(null);
493
+ const pageContentRef = useRef(null);
494
+ const prevPageContentRef = useRef(null);
495
+ const onBack = useRef({});
496
+ const frameRootRef = useRef(null);
511
497
  const { getLocation } = useLocation({ rootRouteGuide });
512
498
  const { history, setHistoryForward, setHistoryBack, getCurrentLocation, getPrevLocation, getScrollTop } = useHistory([
513
- getLocation(window.location.pathname),
499
+ getLocation(window.location.pathname)
514
500
  ]);
515
- const [{ location, prevLocation }, setLocationState] = useState<LocationState>({
501
+ const [{ location, prevLocation }, setLocationState] = useState({
516
502
  location: getCurrentLocation(),
517
- prevLocation: getPrevLocation(),
503
+ prevLocation: getPrevLocation()
518
504
  });
519
- const getRouter = useCallback((): RouterInstance => {
520
- const router = {
521
- push: (href: string) => {
522
- const location = getCurrentLocation();
505
+ const getRouter = useCallback(() => {
506
+ const router3 = {
507
+ push: (href) => {
508
+ const location2 = getCurrentLocation();
523
509
  const scrollTop = pageContentRef.current?.scrollTop ?? 0;
524
510
  setHistoryForward({ type: "push", location: getLocation(href), scrollTop });
525
- setLocationState({ location: getCurrentLocation(), prevLocation: location });
511
+ setLocationState({ location: getCurrentLocation(), prevLocation: location2 });
526
512
  window.history.pushState({}, "", href);
527
513
  },
528
- replace: (href: string) => {
514
+ replace: (href) => {
529
515
  const scrollTop = pageContentRef.current?.scrollTop ?? 0;
530
516
  setHistoryForward({ type: "replace", location: getLocation(href), scrollTop });
531
517
  setLocationState({ location: getCurrentLocation(), prevLocation });
@@ -535,39 +521,34 @@ export const useCsrValues = (rootRouteGuide: RouteGuide, pathRoutes: PathRoute[]
535
521
  window.location.reload();
536
522
  },
537
523
  back: async () => {
538
- const location = getCurrentLocation();
539
- await onBack.current[location.pathRoute.pageState.transition]?.();
524
+ const location2 = getCurrentLocation();
525
+ await onBack.current[location2.pathRoute.pageState.transition]?.();
540
526
  const scrollTop = pageContentRef.current?.scrollTop ?? 0;
541
- setHistoryBack({ type: "back", location, scrollTop });
527
+ setHistoryBack({ type: "back", location: location2, scrollTop });
542
528
  setLocationState({ location: getCurrentLocation(), prevLocation: getPrevLocation() });
543
529
  window.history.back();
544
- },
530
+ }
545
531
  };
546
- window.onpopstate = async (ev: PopStateEvent) => {
547
- const routeType =
548
- window.location.pathname === getCurrentLocation().pathname && history.current.type !== "back"
549
- ? "forward"
550
- : window.location.pathname === getPrevLocation()?.pathname
551
- ? "back"
552
- : null;
532
+ window.onpopstate = async (ev) => {
533
+ const routeType = window.location.pathname === getCurrentLocation().pathname && history.current.type !== "back" ? "forward" : window.location.pathname === getPrevLocation()?.pathname ? "back" : null;
553
534
  const scrollTop = pageContentRef.current?.scrollTop ?? 0;
554
- if (!routeType) return;
535
+ if (!routeType)
536
+ return;
555
537
  if (routeType === "forward") {
556
- const location = getCurrentLocation();
557
- setHistoryForward({ type: "popForward", location, scrollTop });
558
- setLocationState({ location: getCurrentLocation(), prevLocation: location });
538
+ const location2 = getCurrentLocation();
539
+ setHistoryForward({ type: "popForward", location: location2, scrollTop });
540
+ setLocationState({ location: getCurrentLocation(), prevLocation: location2 });
559
541
  } else {
560
- // back
561
- const location = getCurrentLocation();
562
- await onBack.current[location.pathRoute.pageState.transition]?.();
563
- setHistoryBack({ type: "popBack", location, scrollTop });
542
+ const location2 = getCurrentLocation();
543
+ await onBack.current[location2.pathRoute.pageState.transition]?.();
544
+ setHistoryBack({ type: "popBack", location: location2, scrollTop });
564
545
  setLocationState({ location: getCurrentLocation(), prevLocation: getPrevLocation() });
565
546
  }
566
547
  };
567
- return router;
548
+ return router3;
568
549
  }, [location]);
569
- const router = getRouter();
570
- const routeState: RouteState = {
550
+ const router2 = getRouter();
551
+ const routeState = {
571
552
  clientWidth: clientWidth.current,
572
553
  clientHeight: clientHeight.current,
573
554
  location,
@@ -579,35 +560,37 @@ export const useCsrValues = (rootRouteGuide: RouteGuide, pathRoutes: PathRoute[]
579
560
  pageContentRef,
580
561
  frameRootRef,
581
562
  onBack,
582
- router,
583
- pathRoutes,
563
+ router: router2,
564
+ pathRoutes
584
565
  };
585
566
  const useNonTransition = useNoneTrans(routeState);
586
567
  const useFadeTransition = useFadeTrans(routeState);
587
568
  const useStackTransition = useStackTrans(routeState);
588
569
  const useBottomUpTransition = useBottomUpTrans(routeState);
589
- const useCsrTransitionMap: { [key in TransitionType]: UseCsrTransition } = {
570
+ const useCsrTransitionMap = {
590
571
  none: useNonTransition,
591
572
  fade: useFadeTransition,
592
573
  stack: useStackTransition,
593
574
  bottomUp: useBottomUpTransition,
594
- scaleOut: useNonTransition,
575
+ scaleOut: useNonTransition
595
576
  };
596
-
597
577
  useEffect(() => {
598
- if (pageContentRef.current) pageContentRef.current.scrollTop = getScrollTop(location.pathname);
578
+ if (pageContentRef.current)
579
+ pageContentRef.current.scrollTop = getScrollTop(location.pathname);
599
580
  if (prevPageContentRef.current)
600
581
  prevPageContentRef.current.scrollTop = prevLocation ? getScrollTop(prevLocation.pathname) : 0;
601
582
  void App.addListener("backButton", () => {
602
- router.back();
583
+ router2.back();
603
584
  });
604
585
  return () => {
605
586
  void App.removeAllListeners();
606
587
  };
607
588
  }, [location.pathname]);
608
-
609
589
  return {
610
590
  ...routeState,
611
- ...useCsrTransitionMap[location.pathRoute.pageState.transition],
612
- } satisfies CsrContextType;
591
+ ...useCsrTransitionMap[location.pathRoute.pageState.transition]
592
+ };
593
+ };
594
+ export {
595
+ useCsrValues
613
596
  };