@akanjs/next 0.0.53 → 0.0.55

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