flemo 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +44 -0
  3. package/dist/Route.d.ts +10 -0
  4. package/dist/Router.d.ts +11 -0
  5. package/dist/core/TaskManger.d.ts +56 -0
  6. package/dist/history/HistoryListener.d.ts +2 -0
  7. package/dist/history/store.d.ts +16 -0
  8. package/dist/index.d.ts +13 -0
  9. package/dist/index.mjs +1041 -0
  10. package/dist/navigate/store.d.ts +7 -0
  11. package/dist/navigate/useNavigate.d.ts +11 -0
  12. package/dist/navigate/useStep.d.ts +6 -0
  13. package/dist/renderer/Renderer.d.ts +3 -0
  14. package/dist/screen/ParamsProvider/ParamsContext.d.ts +2 -0
  15. package/dist/screen/ParamsProvider/ParamsDispatchContext.d.ts +7 -0
  16. package/dist/screen/ParamsProvider/ParamsProvider.d.ts +6 -0
  17. package/dist/screen/ParamsProvider/ParamsReducer.d.ts +3 -0
  18. package/dist/screen/ParamsProvider/useParams.d.ts +2 -0
  19. package/dist/screen/ParamsProvider/useParamsDispatch.d.ts +1 -0
  20. package/dist/screen/Screen.d.ts +3 -0
  21. package/dist/screen/ScreenContext.d.ts +12 -0
  22. package/dist/screen/ScreenFreeze.d.ts +8 -0
  23. package/dist/screen/ScreenMotion.d.ts +3 -0
  24. package/dist/screen/ScreenMotionDecorator.d.ts +3 -0
  25. package/dist/screen/store.d.ts +6 -0
  26. package/dist/screen/useScreen.d.ts +1 -0
  27. package/dist/transition/createRawTransition.d.ts +18 -0
  28. package/dist/transition/createTransition.d.ts +14 -0
  29. package/dist/transition/cupertino.d.ts +2 -0
  30. package/dist/transition/decorator/createDecorator.d.ts +12 -0
  31. package/dist/transition/decorator/createRawDecorator.d.ts +19 -0
  32. package/dist/transition/decorator/decorator.d.ts +2 -0
  33. package/dist/transition/decorator/overlay.d.ts +2 -0
  34. package/dist/transition/decorator/typing.d.ts +13 -0
  35. package/dist/transition/material.d.ts +2 -0
  36. package/dist/transition/none.d.ts +2 -0
  37. package/dist/transition/store.d.ts +7 -0
  38. package/dist/transition/transition.d.ts +3 -0
  39. package/dist/transition/typing.d.ts +38 -0
  40. package/dist/utils/getParams.d.ts +4 -0
  41. package/dist/utils/isServer.d.ts +1 -0
  42. package/dist/vendor-C8cPYUOQ.js +299 -0
  43. package/package.json +79 -0
package/dist/index.mjs ADDED
@@ -0,0 +1,1041 @@
1
+ import { jsx as P, jsxs as q, Fragment as tt } from "react/jsx-runtime";
2
+ import { useEffect as I, createContext as O, useReducer as et, Children as Y, useContext as b, Suspense as nt, useImperativeHandle as at, useRef as R } from "react";
3
+ import { d as N, c as M } from "./vendor-C8cPYUOQ.js";
4
+ import { animate as st } from "motion";
5
+ import { animate as w, transform as X, useAnimate as j, motion as K, useDragControls as rt } from "motion/react";
6
+ function it(r, e, t) {
7
+ const a = Array.isArray(r) ? r.find((i) => N.pathToRegexp(i).regexp.test(e)) || "" : N.pathToRegexp(r).regexp.test(e) ? r : "", n = N.match(a)(e), s = new URLSearchParams(t), c = Object.fromEntries(s.entries());
8
+ return n ? { ...n.params, ...c } : {};
9
+ }
10
+ function B() {
11
+ return typeof document > "u";
12
+ }
13
+ class ot {
14
+ tasks = /* @__PURE__ */ new Map();
15
+ instanceId = Date.now().toString();
16
+ isLocked = !1;
17
+ currentTaskId = null;
18
+ taskQueue = Promise.resolve();
19
+ signalListeners = /* @__PURE__ */ new Map();
20
+ // 신호 리스너
21
+ async acquireLock(e) {
22
+ for (let n = 0; n < 10; n++) {
23
+ if (!this.isLocked)
24
+ return this.isLocked = !0, this.currentTaskId = e, !0;
25
+ await new Promise((s) => setTimeout(s, 100));
26
+ }
27
+ return !1;
28
+ }
29
+ releaseLock(e) {
30
+ this.currentTaskId === e && (this.isLocked = !1, this.currentTaskId = null);
31
+ }
32
+ generateTaskId() {
33
+ return `${this.instanceId}-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
34
+ }
35
+ emitSignal(e) {
36
+ const t = this.signalListeners.get(e);
37
+ t && (t.forEach((a) => {
38
+ this.resolveTask(a);
39
+ }), this.signalListeners.delete(e));
40
+ }
41
+ async addTask(e, t = {}) {
42
+ const a = t.id || this.generateTaskId();
43
+ return new Promise((n, s) => {
44
+ this.taskQueue = this.taskQueue.then(async () => {
45
+ try {
46
+ const { control: c, validate: i, rollback: p, dependencies: h = [] } = t, o = {
47
+ id: a,
48
+ execute: e,
49
+ timestamp: Date.now(),
50
+ retryCount: 0,
51
+ status: "PENDING",
52
+ dependencies: h,
53
+ instanceId: this.instanceId,
54
+ validate: i,
55
+ rollback: p,
56
+ control: c
57
+ };
58
+ this.tasks.set(o.id, o);
59
+ try {
60
+ if (!await this.acquireLock(o.id))
61
+ throw o.status = "FAILED", new Error("FAILED");
62
+ try {
63
+ o.status = "PROCESSING";
64
+ for (const l of o.dependencies) {
65
+ const g = this.tasks.get(l);
66
+ if (!g || g.status !== "COMPLETED")
67
+ throw o.status = "FAILED", new Error("FAILED");
68
+ }
69
+ if (o.validate && !await o.validate())
70
+ throw o.status = "FAILED", new Error("FAILED");
71
+ const u = await o.execute();
72
+ if (t.control) {
73
+ const l = t.control;
74
+ if (l.delay && l.delay > 0 && await new Promise((g) => setTimeout(g, l.delay)), l.manual) {
75
+ o.status = "MANUAL_PENDING", o.manualResolver = { resolve: n, reject: s, result: u };
76
+ return;
77
+ }
78
+ if (l.signal) {
79
+ o.status = "MANUAL_PENDING", o.manualResolver = { resolve: n, reject: s, result: u }, this.signalListeners.has(l.signal) || this.signalListeners.set(l.signal, /* @__PURE__ */ new Set()), this.signalListeners.get(l.signal).add(o.id);
80
+ return;
81
+ }
82
+ if (l.condition && !await l.condition()) {
83
+ o.status = "MANUAL_PENDING", o.manualResolver = { resolve: n, reject: s, result: u };
84
+ return;
85
+ }
86
+ }
87
+ o.status = "COMPLETED", n({
88
+ success: !0,
89
+ result: u,
90
+ taskId: o.id,
91
+ timestamp: Date.now(),
92
+ instanceId: this.instanceId
93
+ });
94
+ } catch (u) {
95
+ if (o.status = "FAILED", o.rollback)
96
+ try {
97
+ await o.rollback(), o.status = "ROLLEDBACK";
98
+ } catch {
99
+ }
100
+ throw u;
101
+ } finally {
102
+ this.releaseLock(o.id);
103
+ }
104
+ } catch (d) {
105
+ s(d);
106
+ }
107
+ } catch (c) {
108
+ s(c);
109
+ }
110
+ }).catch(s);
111
+ });
112
+ }
113
+ async resolveTask(e) {
114
+ const t = this.tasks.get(e);
115
+ if (!t || t.status !== "MANUAL_PENDING")
116
+ return !1;
117
+ if (t.manualResolver) {
118
+ if (t.control?.condition && !await t.control.condition())
119
+ return !1;
120
+ t.status = "COMPLETED";
121
+ const a = t.manualResolver;
122
+ return a.resolve({
123
+ success: !0,
124
+ result: a.result,
125
+ taskId: t.id,
126
+ timestamp: Date.now(),
127
+ instanceId: this.instanceId
128
+ }), delete t.manualResolver, !0;
129
+ }
130
+ return !1;
131
+ }
132
+ async resolveAllPending() {
133
+ const e = Array.from(this.tasks.values()).filter(
134
+ (t) => ["PENDING", "MANUAL_PENDING"].includes(t.status)
135
+ );
136
+ await Promise.all(e.map((t) => this.resolveTask(t.id)));
137
+ }
138
+ getManualPendingTasks() {
139
+ return Array.from(this.tasks.values()).filter((e) => e.status === "MANUAL_PENDING");
140
+ }
141
+ }
142
+ const f = new ot(), T = M((r) => ({
143
+ index: -1,
144
+ histories: [],
145
+ addHistory: (e) => r((t) => ({
146
+ index: t.index + 1,
147
+ histories: t.histories.concat(e)
148
+ })),
149
+ replaceHistory: (e) => r((t) => (t.histories.splice(e, 1), {
150
+ index: t.index - 1,
151
+ histories: t.histories
152
+ })),
153
+ popHistory: (e) => r((t) => ({
154
+ index: t.index - 1,
155
+ histories: t.histories.filter((a, n) => n !== e)
156
+ }))
157
+ })), k = M((r) => ({
158
+ status: "IDLE",
159
+ setStatus: (e) => r({ status: e })
160
+ }));
161
+ function ct() {
162
+ return I(() => {
163
+ const r = async (e) => {
164
+ await f.resolveAllPending();
165
+ const { index: t, addHistory: a, popHistory: n } = T.getState(), s = k.getState().setStatus, c = e.state?.id, i = e.state?.index, p = e.state?.status, h = e.state?.params, o = e.state?.transitionName, d = i < t, u = p === "PUSHING" && i > t, l = p === "REPLACING" && i > t;
166
+ d ? (await f.addTask(
167
+ async () => (s("POPPING"), async () => {
168
+ n(i + 1), f.getManualPendingTasks().length || s("COMPLETED");
169
+ }),
170
+ {
171
+ id: c,
172
+ control: {
173
+ manual: !0
174
+ }
175
+ }
176
+ ))?.result?.() : u ? (await f.addTask(
177
+ async () => (s("PUSHING"), a({
178
+ id: c,
179
+ pathname: window.location.pathname,
180
+ params: h,
181
+ transitionName: o
182
+ }), async () => {
183
+ f.getManualPendingTasks().length || s("COMPLETED");
184
+ }),
185
+ {
186
+ id: c,
187
+ control: {
188
+ manual: !0
189
+ }
190
+ }
191
+ ))?.result?.() : l && (await f.addTask(
192
+ async () => (s("REPLACING"), a({
193
+ id: c,
194
+ pathname: window.location.pathname,
195
+ params: h,
196
+ transitionName: o
197
+ }), async () => {
198
+ f.getManualPendingTasks().length || s("COMPLETED");
199
+ }),
200
+ {
201
+ id: c,
202
+ control: {
203
+ manual: !0
204
+ }
205
+ }
206
+ ))?.result?.();
207
+ };
208
+ return window.addEventListener("popstate", r), () => {
209
+ window.removeEventListener("popstate", r);
210
+ };
211
+ }, []), null;
212
+ }
213
+ const Q = O({}), V = O(() => {
214
+ });
215
+ function ut(r, e) {
216
+ switch (e.type) {
217
+ case "SET":
218
+ return e.params;
219
+ default:
220
+ return r;
221
+ }
222
+ }
223
+ function lt({
224
+ children: r,
225
+ active: e,
226
+ params: t
227
+ }) {
228
+ const [a, n] = et(ut, t);
229
+ return I(() => {
230
+ const s = (c) => {
231
+ c.state?.step && n({ type: "SET", params: c.state?.params || {} });
232
+ };
233
+ return e && window.addEventListener("popstate", s), () => {
234
+ window.removeEventListener("popstate", s);
235
+ };
236
+ }, [e, n]), /* @__PURE__ */ P(V.Provider, { value: n, children: /* @__PURE__ */ P(Q.Provider, { value: a, children: r }) });
237
+ }
238
+ const W = O({
239
+ id: "",
240
+ isActive: !1,
241
+ isRoot: !0,
242
+ isPrev: !1,
243
+ zIndex: 0,
244
+ pathname: "",
245
+ params: {},
246
+ transitionName: "none",
247
+ prevTransitionName: "none"
248
+ });
249
+ function dt({ children: r }) {
250
+ const e = T((a) => a.index), t = T((a) => a.histories);
251
+ return t.map(
252
+ (a) => Y.toArray(r).filter(
253
+ (n) => N.pathToRegexp(n.props.path).regexp.test(
254
+ a.pathname
255
+ )
256
+ )
257
+ ).map(([a], n) => /* @__PURE__ */ P(
258
+ W.Provider,
259
+ {
260
+ value: {
261
+ id: t[n].id,
262
+ isActive: n === e,
263
+ isRoot: n === 0,
264
+ isPrev: n < e - 1,
265
+ zIndex: n,
266
+ pathname: t[n].pathname,
267
+ params: t[n].params,
268
+ transitionName: t[e].transitionName,
269
+ prevTransitionName: t[e - 1]?.transitionName
270
+ },
271
+ children: /* @__PURE__ */ P(lt, { active: n === e, params: t[n].params, children: a })
272
+ },
273
+ t[n].id
274
+ ));
275
+ }
276
+ function pt({
277
+ name: r,
278
+ initial: e,
279
+ enter: t,
280
+ exit: a,
281
+ options: n
282
+ }) {
283
+ return {
284
+ name: r,
285
+ initial: e,
286
+ variants: {
287
+ "IDLE-true": t,
288
+ "IDLE-false": t,
289
+ "PUSHING-false": a,
290
+ "PUSHING-true": t,
291
+ "REPLACING-false": a,
292
+ "REPLACING-true": t,
293
+ "POPPING-false": t,
294
+ "POPPING-true": t,
295
+ "COMPLETED-false": a,
296
+ "COMPLETED-true": t
297
+ },
298
+ ...n
299
+ };
300
+ }
301
+ const ft = pt({
302
+ name: "overlay",
303
+ initial: {
304
+ opacity: 0,
305
+ backgroundColor: "rgba(0, 0, 0, 0)",
306
+ transition: {
307
+ duration: 0
308
+ }
309
+ },
310
+ enter: {
311
+ value: {
312
+ opacity: 0,
313
+ backgroundColor: "rgba(0, 0, 0, 0.3)"
314
+ },
315
+ options: {
316
+ duration: 0.3
317
+ }
318
+ },
319
+ exit: {
320
+ value: {
321
+ opacity: 1,
322
+ backgroundColor: "rgba(0, 0, 0, 0.3)"
323
+ },
324
+ options: {
325
+ duration: 0.3
326
+ }
327
+ },
328
+ options: {
329
+ onSwipe: (r, { prevDecorator: e }) => st(
330
+ e,
331
+ {
332
+ opacity: Math.max(0, 1 - r / 100)
333
+ },
334
+ {
335
+ duration: 0
336
+ }
337
+ )
338
+ }
339
+ }), H = /* @__PURE__ */ new Map([["overlay", ft]]), C = M((r) => ({
340
+ defaultTransitionName: "cupertino",
341
+ setDefaultTransitionName: (e) => r({ defaultTransitionName: e })
342
+ }));
343
+ function U({
344
+ name: r,
345
+ initial: e,
346
+ idle: t,
347
+ enter: a,
348
+ enterBack: n,
349
+ exit: s,
350
+ exitBack: c,
351
+ options: i
352
+ }) {
353
+ return {
354
+ name: r,
355
+ initial: e,
356
+ variants: {
357
+ "IDLE-true": t,
358
+ "IDLE-false": t,
359
+ "PUSHING-false": s,
360
+ "PUSHING-true": a,
361
+ "REPLACING-false": s,
362
+ "REPLACING-true": a,
363
+ "POPPING-false": c,
364
+ "POPPING-true": n,
365
+ "COMPLETED-false": s,
366
+ "COMPLETED-true": a
367
+ },
368
+ ...i
369
+ };
370
+ }
371
+ const ht = U({
372
+ name: "cupertino",
373
+ initial: {
374
+ x: "100%",
375
+ transition: {
376
+ duration: 0
377
+ }
378
+ },
379
+ idle: {
380
+ value: {
381
+ x: 0
382
+ },
383
+ options: {
384
+ duration: 0
385
+ }
386
+ },
387
+ enter: {
388
+ value: {
389
+ x: 0
390
+ },
391
+ options: {
392
+ duration: 0.3,
393
+ ease: [0.32, 0.72, 0, 1]
394
+ }
395
+ },
396
+ enterBack: {
397
+ value: {
398
+ x: "100%"
399
+ },
400
+ options: {
401
+ duration: 0.3,
402
+ ease: [0.32, 0.72, 0, 1]
403
+ }
404
+ },
405
+ exit: {
406
+ value: {
407
+ x: -100
408
+ },
409
+ options: {
410
+ duration: 0.3,
411
+ ease: [0.32, 0.72, 0, 1]
412
+ }
413
+ },
414
+ exitBack: {
415
+ value: {
416
+ x: 0
417
+ },
418
+ options: {
419
+ duration: 0.3,
420
+ ease: [0.32, 0.72, 0, 1]
421
+ }
422
+ },
423
+ options: {
424
+ decoratorName: "overlay",
425
+ swipeDirection: "x",
426
+ onSwipeStart: async (r, e, { currentScreen: t, dragControls: a }) => {
427
+ const { offset: n } = e;
428
+ n.x < 0 && (a.stop(), w(
429
+ t,
430
+ {
431
+ x: 0
432
+ },
433
+ {
434
+ duration: 0.3
435
+ }
436
+ ));
437
+ },
438
+ onSwipe: (r, e, { currentScreen: t, prevScreen: a }) => {
439
+ const { offset: n } = e, s = n.x, c = X(s, [0, window.innerWidth], [0, 100]);
440
+ return w(
441
+ t,
442
+ {
443
+ x: Math.max(0, s)
444
+ },
445
+ {
446
+ duration: 0
447
+ }
448
+ ), w(
449
+ a,
450
+ {
451
+ x: -100 + c
452
+ },
453
+ {
454
+ duration: 0
455
+ }
456
+ ), c;
457
+ },
458
+ onSwipeEnd: async (r, e, { currentScreen: t, prevScreen: a }) => {
459
+ const { offset: n, velocity: s } = e, i = n.x > 50 || s.x > 20;
460
+ return w(
461
+ t,
462
+ {
463
+ x: i ? "100%" : 0
464
+ },
465
+ {
466
+ duration: 0.3,
467
+ ease: [0.32, 0.72, 0, 1]
468
+ }
469
+ ), w(
470
+ a,
471
+ {
472
+ x: i ? 0 : -100
473
+ },
474
+ {
475
+ duration: 0.3,
476
+ ease: [0.32, 0.72, 0, 1]
477
+ }
478
+ ), i;
479
+ }
480
+ }
481
+ }), mt = U({
482
+ name: "material",
483
+ initial: {
484
+ y: "100%",
485
+ opacity: 0.96,
486
+ transition: {
487
+ duration: 0
488
+ }
489
+ },
490
+ idle: {
491
+ value: {
492
+ y: 0,
493
+ opacity: 1
494
+ },
495
+ options: {
496
+ duration: 0
497
+ }
498
+ },
499
+ enter: {
500
+ value: {
501
+ y: 0,
502
+ opacity: 1
503
+ },
504
+ options: {
505
+ duration: 0.24,
506
+ ease: [0, 0, 0.2, 1]
507
+ }
508
+ },
509
+ enterBack: {
510
+ value: {
511
+ y: "100%",
512
+ opacity: 0.96
513
+ },
514
+ options: {
515
+ duration: 0.22,
516
+ ease: [0.4, 0, 1, 1]
517
+ }
518
+ },
519
+ exit: {
520
+ value: {
521
+ y: -56,
522
+ opacity: 0.96
523
+ },
524
+ options: {
525
+ duration: 0.22,
526
+ ease: [0.4, 0, 1, 1]
527
+ }
528
+ },
529
+ exitBack: {
530
+ value: {
531
+ y: 0,
532
+ opacity: 1
533
+ },
534
+ options: {
535
+ duration: 0.24,
536
+ ease: [0, 0, 0.2, 1]
537
+ }
538
+ },
539
+ options: {
540
+ swipeDirection: "y",
541
+ onSwipeStart: async (r, e, { currentScreen: t, dragControls: a }) => {
542
+ const { offset: n } = e;
543
+ n.y < 0 && (a.stop(), w(
544
+ t,
545
+ {
546
+ y: 0,
547
+ opacity: 1
548
+ },
549
+ {
550
+ duration: 0.24
551
+ }
552
+ ));
553
+ },
554
+ onSwipe: (r, e, { currentScreen: t, prevScreen: a }) => {
555
+ const { offset: n } = e, s = n.y, c = Math.max(0, Math.min(56, s)), i = X(c, [0, 56], [1, 0.96]), p = Math.max(0, s - 56), h = Math.min(1, p / 160), o = Math.sqrt(h) * 12, d = Math.max(0, c + o), u = Math.min(56, d);
556
+ return w(
557
+ t,
558
+ {
559
+ y: d,
560
+ opacity: i
561
+ },
562
+ {
563
+ duration: 0
564
+ }
565
+ ), w(
566
+ a,
567
+ {
568
+ y: -56 + u,
569
+ opacity: u / 56
570
+ },
571
+ { duration: 0 }
572
+ ), u;
573
+ },
574
+ onSwipeEnd: async (r, e, { currentScreen: t, prevScreen: a }) => {
575
+ const { offset: n, velocity: s } = e, i = n.y > 56 || s.y > 20;
576
+ return await Promise.all([
577
+ w(
578
+ t,
579
+ {
580
+ y: i ? "100%" : 0,
581
+ opacity: i ? 0.96 : 1
582
+ },
583
+ {
584
+ duration: i ? 0.22 : 0.24,
585
+ ease: i ? [0.4, 0, 1, 1] : [0, 0, 0.2, 1]
586
+ }
587
+ ),
588
+ w(
589
+ a,
590
+ {
591
+ y: i ? 0 : -56,
592
+ opacity: i ? 1 : 0.96
593
+ },
594
+ {
595
+ duration: i ? 0.22 : 0.24,
596
+ ease: i ? [0, 0, 0.2, 1] : [0.4, 0, 1, 1]
597
+ }
598
+ )
599
+ ]), i;
600
+ }
601
+ }
602
+ }), Pt = U({
603
+ name: "none",
604
+ initial: {
605
+ transition: {
606
+ duration: 0
607
+ }
608
+ },
609
+ idle: {
610
+ value: {},
611
+ options: {
612
+ duration: 0
613
+ }
614
+ },
615
+ enter: {
616
+ value: {},
617
+ options: {
618
+ duration: 0
619
+ }
620
+ },
621
+ enterBack: {
622
+ value: {},
623
+ options: {
624
+ duration: 0
625
+ }
626
+ },
627
+ exit: {
628
+ value: {},
629
+ options: {
630
+ duration: 0
631
+ }
632
+ },
633
+ exitBack: {
634
+ value: {},
635
+ options: {
636
+ duration: 0
637
+ }
638
+ }
639
+ }), A = /* @__PURE__ */ new Map([
640
+ ["none", Pt],
641
+ ["cupertino", ht],
642
+ ["material", mt]
643
+ ]), gt = (() => {
644
+ const r = /* @__PURE__ */ Object.create(null), e = Object.prototype.hasOwnProperty;
645
+ for (const t of A.values()) {
646
+ const a = t.variants["IDLE-true"].value;
647
+ for (const n in a)
648
+ e.call(a, n) && (r[n] = a[n]);
649
+ }
650
+ return r;
651
+ })();
652
+ function kt({
653
+ children: r,
654
+ initPath: e = "/",
655
+ defaultTransitionName: t = "cupertino",
656
+ transitions: a = [],
657
+ decorators: n = []
658
+ }) {
659
+ const s = B() ? e || "/" : window.location.pathname, c = B() ? s.split("?")[1] || "" : window.location.search;
660
+ return C.setState({
661
+ defaultTransitionName: t
662
+ }), T.setState({
663
+ index: 0,
664
+ histories: [
665
+ {
666
+ id: "root",
667
+ pathname: s,
668
+ params: it(
669
+ Y.toArray(r).map((i) => i.props.path).flat(),
670
+ s,
671
+ c
672
+ ),
673
+ transitionName: t
674
+ }
675
+ ]
676
+ }), I(() => {
677
+ a.forEach((i) => A.set(i.name, i));
678
+ }, [a]), I(() => {
679
+ n.forEach((i) => H.set(i.name, i));
680
+ }, [n]), /* @__PURE__ */ q(tt, { children: [
681
+ /* @__PURE__ */ P(ct, {}),
682
+ /* @__PURE__ */ P(dt, { children: r })
683
+ ] });
684
+ }
685
+ function xt({ element: r }) {
686
+ return r;
687
+ }
688
+ function Mt() {
689
+ return {
690
+ push: async (a, n, s = {}) => {
691
+ if (f.getManualPendingTasks().length)
692
+ return;
693
+ const { index: c, addHistory: i } = T.getState(), p = k.getState().setStatus, h = C.getState().defaultTransitionName, { transitionName: o = h } = s, d = f.generateTaskId();
694
+ (await f.addTask(
695
+ async () => {
696
+ p("PUSHING");
697
+ const u = N.compile(a)(n), l = N.parse(a).tokens.filter((E) => E.type === "param").map((E) => E.name), g = Object.fromEntries(
698
+ Object.entries(n).filter(([E]) => !l.includes(E))
699
+ ), D = new URLSearchParams(g).toString(), S = `${u}${D ? `?${D}` : ""}`;
700
+ return window.history.state?.id || window.history.replaceState(
701
+ {
702
+ id: "root",
703
+ index: 0,
704
+ status: "IDLE",
705
+ params: {},
706
+ transitionName: o
707
+ },
708
+ "",
709
+ window.location.pathname
710
+ ), window.history.pushState(
711
+ {
712
+ id: d,
713
+ index: c + 1,
714
+ status: "PUSHING",
715
+ params: n,
716
+ transitionName: o
717
+ },
718
+ "",
719
+ S
720
+ ), i({
721
+ id: d,
722
+ pathname: u,
723
+ params: n,
724
+ transitionName: o
725
+ }), () => {
726
+ f.getManualPendingTasks().length || p("COMPLETED");
727
+ };
728
+ },
729
+ {
730
+ id: d,
731
+ control: {
732
+ manual: !0
733
+ }
734
+ }
735
+ )).result?.();
736
+ },
737
+ replace: async (a, n, s = {}) => {
738
+ if (f.getManualPendingTasks().length)
739
+ return;
740
+ const { index: c, addHistory: i } = T.getState(), p = T.getState().replaceHistory, h = k.getState().setStatus, o = C.getState().defaultTransitionName, { transitionName: d = o } = s, u = f.generateTaskId();
741
+ (await f.addTask(
742
+ async () => {
743
+ h("REPLACING");
744
+ const l = N.compile(a)(n), g = N.parse(a).tokens.filter((v) => v.type === "param").map((v) => v.name), D = Object.fromEntries(
745
+ Object.entries(n).filter(([v]) => !g.includes(v))
746
+ ), S = new URLSearchParams(D).toString(), E = `${l}${S ? `?${S}` : ""}`;
747
+ return window.history.replaceState(
748
+ {
749
+ id: u,
750
+ index: c,
751
+ status: "REPLACING",
752
+ params: n,
753
+ transitionName: d
754
+ },
755
+ "",
756
+ E
757
+ ), i({
758
+ id: u,
759
+ pathname: l,
760
+ params: n,
761
+ transitionName: d
762
+ }), async () => {
763
+ await f.addTask(async () => p(c)), f.getManualPendingTasks().length || h("COMPLETED");
764
+ };
765
+ },
766
+ {
767
+ id: u,
768
+ control: {
769
+ manual: !0
770
+ }
771
+ }
772
+ )).result?.();
773
+ },
774
+ pop: () => {
775
+ f.getManualPendingTasks().length || window.history.back();
776
+ }
777
+ };
778
+ }
779
+ function At() {
780
+ const r = b(V);
781
+ return {
782
+ pushStep: async (n) => {
783
+ f.getManualPendingTasks().length || (await f.addTask(async () => {
784
+ const s = new URLSearchParams(n).toString(), c = `${window.location.pathname}${s ? `?${s}` : ""}`;
785
+ return window.history.state?.step || window.history.replaceState(
786
+ {
787
+ ...window.history.state,
788
+ step: !0
789
+ },
790
+ "",
791
+ window.location.pathname
792
+ ), window.history.pushState(
793
+ {
794
+ ...window.history.state,
795
+ step: !0,
796
+ params: n
797
+ },
798
+ "",
799
+ c
800
+ ), async () => r({ type: "SET", params: n });
801
+ })).result?.();
802
+ },
803
+ replaceStep: async (n) => {
804
+ f.getManualPendingTasks().length || (await f.addTask(async () => {
805
+ const s = new URLSearchParams(n).toString(), c = `${window.location.pathname}${s ? `?${s}` : ""}`;
806
+ return window.history.replaceState(
807
+ {
808
+ ...window.history.state,
809
+ step: !0,
810
+ params: n
811
+ },
812
+ "",
813
+ c
814
+ ), async () => r({ type: "SET", params: n });
815
+ })).result?.();
816
+ },
817
+ popStep: () => {
818
+ f.getManualPendingTasks().length || window.history.back();
819
+ }
820
+ };
821
+ }
822
+ function $() {
823
+ return b(W);
824
+ }
825
+ function Rt() {
826
+ return b(Q);
827
+ }
828
+ function Ct({
829
+ name: r,
830
+ initial: e,
831
+ idle: t,
832
+ pushOnEnter: a,
833
+ pushOnExit: n,
834
+ replaceOnEnter: s,
835
+ replaceOnExit: c,
836
+ popOnEnter: i,
837
+ popOnExit: p,
838
+ completedOnExit: h,
839
+ completedOnEnter: o,
840
+ options: d
841
+ }) {
842
+ return {
843
+ name: r,
844
+ initial: e,
845
+ variants: {
846
+ "IDLE-true": t,
847
+ "IDLE-false": t,
848
+ "PUSHING-false": n,
849
+ "PUSHING-true": a,
850
+ "REPLACING-false": c,
851
+ "REPLACING-true": s,
852
+ "POPPING-false": p,
853
+ "POPPING-true": i,
854
+ "COMPLETED-false": h,
855
+ "COMPLETED-true": o
856
+ },
857
+ ...d
858
+ };
859
+ }
860
+ function Gt({
861
+ name: r,
862
+ initial: e,
863
+ idle: t,
864
+ pushOnEnter: a,
865
+ pushOnExit: n,
866
+ replaceOnEnter: s,
867
+ replaceOnExit: c,
868
+ popOnEnter: i,
869
+ popOnExit: p,
870
+ completedOnEnter: h,
871
+ completedOnExit: o,
872
+ options: d
873
+ }) {
874
+ return {
875
+ name: r,
876
+ initial: e,
877
+ variants: {
878
+ "IDLE-true": t,
879
+ "IDLE-false": t,
880
+ "PUSHING-false": n,
881
+ "PUSHING-true": a,
882
+ "REPLACING-false": c,
883
+ "REPLACING-true": s,
884
+ "POPPING-false": p,
885
+ "POPPING-true": i,
886
+ "COMPLETED-false": o,
887
+ "COMPLETED-true": h
888
+ },
889
+ ...d
890
+ };
891
+ }
892
+ const yt = { then() {
893
+ } };
894
+ function wt({
895
+ freeze: r,
896
+ children: e
897
+ }) {
898
+ if (r)
899
+ throw yt;
900
+ return e;
901
+ }
902
+ function St({ freeze: r, children: e, placeholder: t }) {
903
+ return /* @__PURE__ */ P(nt, { fallback: t, children: /* @__PURE__ */ P(wt, { freeze: r, children: e }) });
904
+ }
905
+ function Et({ children: r, ref: e, ...t }) {
906
+ const { isActive: a, transitionName: n } = $(), [s, c] = j();
907
+ at(e, () => s.current);
908
+ const i = k((u) => u.status), p = A.get(n), { decoratorName: h } = p, { initial: o, variants: d } = H.get(h);
909
+ return I(() => {
910
+ if (!s.current) return;
911
+ const { value: u, options: l } = d[`${i}-${a}`];
912
+ c(s.current, u, l);
913
+ }, [i, a, c, d, s]), /* @__PURE__ */ P(
914
+ K.div,
915
+ {
916
+ ref: s,
917
+ initial: o,
918
+ style: {
919
+ position: "absolute",
920
+ top: 0,
921
+ left: 0,
922
+ width: "100%",
923
+ height: "100%",
924
+ pointerEvents: "none",
925
+ ...t.style
926
+ },
927
+ "data-decorator": !0
928
+ }
929
+ );
930
+ }
931
+ const G = M((r) => ({
932
+ transitionStatus: "IDLE",
933
+ setTransitionStatus: (e) => r({ transitionStatus: e })
934
+ }));
935
+ function vt({ children: r, ...e }) {
936
+ const [t, a] = j(), { id: n, isActive: s, isRoot: c, transitionName: i, prevTransitionName: p } = $(), h = rt(), o = k((m) => m.status), d = G((m) => m.transitionStatus), u = G.getState().setTransitionStatus, l = A.get(i), { variants: g, initial: D, swipeDirection: S, decoratorName: E } = l, v = H.get(E), x = R(null), _ = R(null), F = R(null), J = async (m, y) => {
937
+ S && (x.current = t.current?.previousSibling, F.current = t.current?.previousSibling?.querySelector("& > [data-decorator]"), l?.onSwipeStart(m, y, {
938
+ currentScreen: t.current,
939
+ prevScreen: x.current,
940
+ dragControls: h
941
+ }), u("PENDING"));
942
+ }, Z = (m, y) => {
943
+ if (!S || d !== "PENDING")
944
+ return;
945
+ const L = l?.onSwipe(m, y, {
946
+ currentScreen: t.current,
947
+ prevScreen: x.current,
948
+ dragControls: h
949
+ });
950
+ v?.onSwipe?.(L, {
951
+ currentDecorator: _.current,
952
+ prevDecorator: F.current
953
+ });
954
+ }, z = async (m, y) => {
955
+ if (!S || d !== "PENDING")
956
+ return;
957
+ await l?.onSwipeEnd(m, y, {
958
+ currentScreen: t.current,
959
+ prevScreen: x.current
960
+ }) ? window.history.back() : u("IDLE");
961
+ };
962
+ return I(() => {
963
+ const m = t.current;
964
+ if (!m) return;
965
+ const y = (L) => L.preventDefault();
966
+ return m.addEventListener("touchmove", y), () => {
967
+ m.removeEventListener("touchmove", y);
968
+ };
969
+ }, [t]), I(() => {
970
+ t.current && (async () => {
971
+ const { value: m, options: y } = g[`${o}-${s}`], L = o === "REPLACING" && p !== i;
972
+ !s && L && (u("PENDING"), await a(t.current, gt, {
973
+ duration: 0.01
974
+ })), await a(t.current, m, y), await f.resolveTask(n), !s && !L && u("IDLE");
975
+ })();
976
+ }, [
977
+ o,
978
+ s,
979
+ n,
980
+ p,
981
+ i,
982
+ a,
983
+ t,
984
+ u,
985
+ g
986
+ ]), /* @__PURE__ */ q(
987
+ K.div,
988
+ {
989
+ ref: t,
990
+ initial: D,
991
+ drag: S,
992
+ dragListener: !c && s && o === "COMPLETED" && d === "IDLE",
993
+ dragControls: h,
994
+ onDragStart: J,
995
+ onDrag: Z,
996
+ onDragEnd: z,
997
+ style: {
998
+ position: "absolute",
999
+ top: 0,
1000
+ left: 0,
1001
+ width: "100%",
1002
+ height: "100%",
1003
+ backgroundColor: "white",
1004
+ ...e.style
1005
+ },
1006
+ children: [
1007
+ /* @__PURE__ */ P(
1008
+ "div",
1009
+ {
1010
+ style: {
1011
+ position: "absolute",
1012
+ top: 0,
1013
+ left: 0,
1014
+ width: "100%",
1015
+ height: "100%"
1016
+ },
1017
+ children: r
1018
+ }
1019
+ ),
1020
+ v && /* @__PURE__ */ P(Et, { ref: _ })
1021
+ ]
1022
+ }
1023
+ );
1024
+ }
1025
+ function Ot({ children: r, ...e }) {
1026
+ const { isActive: t, isPrev: a } = $(), n = k((p) => p.status), s = G((p) => p.transitionStatus);
1027
+ return /* @__PURE__ */ P(St, { freeze: !t && (n === "COMPLETED" && s === "IDLE" || a), children: /* @__PURE__ */ P(vt, { ...e, children: r }) });
1028
+ }
1029
+ export {
1030
+ xt as Route,
1031
+ kt as Router,
1032
+ Ot as Screen,
1033
+ pt as createDecorator,
1034
+ Gt as createRawDecorator,
1035
+ Ct as createRawTransition,
1036
+ U as createTransition,
1037
+ Mt as useNavigate,
1038
+ Rt as useParams,
1039
+ $ as useScreen,
1040
+ At as useStep
1041
+ };