@flemo/react 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.
package/dist/index.mjs ADDED
@@ -0,0 +1,1188 @@
1
+ import { jsx as L, jsxs as At, Fragment as fe } from "react/jsx-runtime";
2
+ import gt, { useEffect as at, createContext as Gt, useContext as Ut, useReducer as me, Children as ee, useInsertionEffect as ye, useRef as N, useImperativeHandle as he, useState as vt, useLayoutEffect as wt } from "react";
3
+ import { consumeSelfInducedPop as ge, TaskManger as G, useNavigateStore as q, useHistoryStore as U, getMatchedPathPattern as we, transitionMap as nt, decoratorMap as lt, isServer as Ht, compileTransitionStyles as Se, useTransitionStore as Ot, getParams as ve, markSelfInducedPop as ne, targetToDecls as Te, easingToCss as Ee, variantHasAnimation as Pe, animationName as xe, collectAnimatedProperties as Ie, findScrollable as zt } from "@flemo/core";
4
+ import { createDecorator as tn, createRawDecorator as en, createRawTransition as nn, createTransition as rn } from "@flemo/core";
5
+ function De() {
6
+ return at(() => {
7
+ const n = async (e) => {
8
+ if (ge())
9
+ return;
10
+ const o = e.state?.id, i = G.generateTaskId();
11
+ (await G.addTask(
12
+ async (u) => {
13
+ const s = e.state?.index, a = e.state?.status, v = e.state?.params, E = e.state?.transitionName, f = e.state?.layoutId, { setStatus: x, setTransitionTaskId: h } = q.getState(), { index: R, addHistory: $, popHistory: C } = U.getState(), b = s < R, X = a === "PUSHING" && s > R, H = a === "REPLACING" && s > R, _ = window.location.pathname;
14
+ if (!b && !X && !H) {
15
+ u.abort();
16
+ return;
17
+ }
18
+ return h(i), b ? x("POPPING") : X ? (x("PUSHING"), $({
19
+ id: o,
20
+ pathname: _,
21
+ params: v,
22
+ transitionName: E,
23
+ layoutId: f
24
+ })) : H && (x("REPLACING"), $({
25
+ id: o,
26
+ pathname: _,
27
+ params: v,
28
+ transitionName: E,
29
+ layoutId: f
30
+ })), async () => {
31
+ b && C(s + 1), x("COMPLETED");
32
+ };
33
+ },
34
+ {
35
+ id: i,
36
+ control: {
37
+ manual: !0
38
+ }
39
+ }
40
+ )).result?.();
41
+ };
42
+ return window.addEventListener("popstate", n), () => {
43
+ window.removeEventListener("popstate", n);
44
+ };
45
+ }, []), null;
46
+ }
47
+ var Y = {}, Kt;
48
+ function Re() {
49
+ if (Kt) return Y;
50
+ Kt = 1, Object.defineProperty(Y, "__esModule", { value: !0 }), Y.PathError = Y.TokenData = void 0, Y.parse = f, Y.compile = x, Y.match = $, Y.pathToRegexp = C, Y.stringify = dt;
51
+ const n = "/", e = (r) => r, o = /^[$_\p{ID_Start}]$/u, i = /^[$\u200c\u200d\p{ID_Continue}]$/u, u = /^[$_\p{ID_Start}][$\u200c\u200d\p{ID_Continue}]*$/u;
52
+ function s(r) {
53
+ return r.replace(/[{}()\[\]+?!:*\\]/g, "\\$&");
54
+ }
55
+ function a(r) {
56
+ return r.replace(/[.+*?^${}()[\]|/\\]/g, "\\$&");
57
+ }
58
+ class v {
59
+ constructor(c, m) {
60
+ this.tokens = c, this.originalPath = m;
61
+ }
62
+ }
63
+ Y.TokenData = v;
64
+ class E extends TypeError {
65
+ constructor(c, m) {
66
+ let p = c;
67
+ m && (p += `: ${m}`), p += "; visit https://git.new/pathToRegexpError for info", super(p), this.originalPath = m;
68
+ }
69
+ }
70
+ Y.PathError = E;
71
+ function f(r, c = {}) {
72
+ const { encodePath: m = e } = c, p = [...r];
73
+ let l = 0;
74
+ function g(d) {
75
+ const P = [];
76
+ let w = "";
77
+ function D() {
78
+ w && (P.push({
79
+ type: "text",
80
+ value: m(w)
81
+ }), w = "");
82
+ }
83
+ for (; l < p.length; ) {
84
+ const I = p[l++];
85
+ if (I === d)
86
+ return D(), P;
87
+ if (I === "\\") {
88
+ if (l === p.length)
89
+ throw new E(`Unexpected end after \\ at index ${l}`, r);
90
+ w += p[l++];
91
+ continue;
92
+ }
93
+ if (I === ":" || I === "*") {
94
+ const M = I === ":" ? "param" : "wildcard";
95
+ let S = "";
96
+ if (o.test(p[l]))
97
+ do
98
+ S += p[l++];
99
+ while (i.test(p[l]));
100
+ else if (p[l] === '"') {
101
+ let k = l;
102
+ for (; l < p.length; ) {
103
+ if (p[++l] === '"') {
104
+ l++, k = 0;
105
+ break;
106
+ }
107
+ p[l] === "\\" && l++, S += p[l];
108
+ }
109
+ if (k)
110
+ throw new E(`Unterminated quote at index ${k}`, r);
111
+ }
112
+ if (!S)
113
+ throw new E(`Missing parameter name at index ${l}`, r);
114
+ D(), P.push({ type: M, name: S });
115
+ continue;
116
+ }
117
+ if (I === "{") {
118
+ D(), P.push({
119
+ type: "group",
120
+ tokens: g("}")
121
+ });
122
+ continue;
123
+ }
124
+ if (I === "}" || I === "(" || I === ")" || I === "[" || I === "]" || I === "+" || I === "?" || I === "!")
125
+ throw new E(`Unexpected ${I} at index ${l - 1}`, r);
126
+ w += I;
127
+ }
128
+ if (d)
129
+ throw new E(`Unexpected end at index ${l}, expected ${d}`, r);
130
+ return D(), P;
131
+ }
132
+ return new v(g(""), r);
133
+ }
134
+ function x(r, c = {}) {
135
+ const { encode: m = encodeURIComponent, delimiter: p = n } = c, l = typeof r == "object" ? r : f(r, c), g = h(l.tokens, p, m);
136
+ return function(P = {}) {
137
+ const w = [], D = g(P, w);
138
+ if (w.length)
139
+ throw new TypeError(`Missing parameters: ${w.join(", ")}`);
140
+ return D;
141
+ };
142
+ }
143
+ function h(r, c, m) {
144
+ const p = r.map((l) => R(l, c, m));
145
+ return (l, g) => {
146
+ let d = "";
147
+ for (const P of p)
148
+ d += P(l, g);
149
+ return d;
150
+ };
151
+ }
152
+ function R(r, c, m) {
153
+ if (r.type === "text")
154
+ return () => r.value;
155
+ if (r.type === "group") {
156
+ const l = h(r.tokens, c, m);
157
+ return (g, d) => {
158
+ const P = d.length, w = l(g, d);
159
+ return d.length === P ? w : (d.length = P, "");
160
+ };
161
+ }
162
+ const p = m || e;
163
+ return r.type === "wildcard" && m !== !1 ? (l, g) => {
164
+ const d = l[r.name];
165
+ if (d == null)
166
+ return g.push(r.name), "";
167
+ if (!Array.isArray(d) || d.length === 0)
168
+ throw new TypeError(`Expected "${r.name}" to be a non-empty array`);
169
+ let P = "";
170
+ for (let w = 0; w < d.length; w++) {
171
+ if (typeof d[w] != "string")
172
+ throw new TypeError(`Expected "${r.name}/${w}" to be a string`);
173
+ w > 0 && (P += c), P += p(d[w]);
174
+ }
175
+ return P;
176
+ } : (l, g) => {
177
+ const d = l[r.name];
178
+ if (d == null)
179
+ return g.push(r.name), "";
180
+ if (typeof d != "string")
181
+ throw new TypeError(`Expected "${r.name}" to be a string`);
182
+ return p(d);
183
+ };
184
+ }
185
+ function $(r, c = {}) {
186
+ const { decode: m = decodeURIComponent, delimiter: p = n } = c, { regexp: l, keys: g } = C(r, c), d = g.map((P) => m === !1 ? e : P.type === "param" ? m : (w) => w.split(p).map(m));
187
+ return function(w) {
188
+ const D = l.exec(w);
189
+ if (!D)
190
+ return !1;
191
+ const I = D[0], M = /* @__PURE__ */ Object.create(null);
192
+ for (let S = 1; S < D.length; S++) {
193
+ if (D[S] === void 0)
194
+ continue;
195
+ const k = g[S - 1], V = d[S - 1];
196
+ M[k.name] = V(D[S]);
197
+ }
198
+ return { path: I, params: M };
199
+ };
200
+ }
201
+ function C(r, c = {}) {
202
+ const { delimiter: m = n, end: p = !0, sensitive: l = !1, trailing: g = !0 } = c, d = [];
203
+ let P = "", w = 0;
204
+ function D(M) {
205
+ if (Array.isArray(M)) {
206
+ for (const k of M)
207
+ D(k);
208
+ return;
209
+ }
210
+ const S = typeof M == "object" ? M : f(M, c);
211
+ b(S.tokens, 0, [], (k) => {
212
+ if (w >= 256)
213
+ throw new E("Too many path combinations", S.originalPath);
214
+ w > 0 && (P += "|"), P += X(k, m, d, S.originalPath), w++;
215
+ });
216
+ }
217
+ D(r);
218
+ let I = `^(?:${P})`;
219
+ return g && (I += "(?:" + a(m) + "$)?"), I += p ? "$" : "(?=" + a(m) + "|$)", { regexp: new RegExp(I, l ? "" : "i"), keys: d };
220
+ }
221
+ function b(r, c, m, p) {
222
+ for (; c < r.length; ) {
223
+ const l = r[c++];
224
+ if (l.type === "group") {
225
+ const g = m.length;
226
+ b(l.tokens, 0, m, (d) => b(r, c, d, p)), m.length = g;
227
+ continue;
228
+ }
229
+ m.push(l);
230
+ }
231
+ p(m);
232
+ }
233
+ function X(r, c, m, p) {
234
+ let l = "", g = "", d = "", P = 0, w = 0, D = 0;
235
+ function I(S, k) {
236
+ for (; S < r.length; ) {
237
+ const V = r[S++];
238
+ if (V.type === k)
239
+ return !0;
240
+ if (V.type === "text" && V.value.includes(c))
241
+ break;
242
+ }
243
+ return !1;
244
+ }
245
+ function M(S) {
246
+ let k = "";
247
+ for (; S < r.length; ) {
248
+ const V = r[S++];
249
+ if (V.type !== "text")
250
+ break;
251
+ k += V.value;
252
+ }
253
+ return k;
254
+ }
255
+ for (; D < r.length; ) {
256
+ const S = r[D++];
257
+ if (S.type === "text") {
258
+ l += a(S.value), g += S.value, P === 2 && (d += S.value), S.value.includes(c) && (w = 0);
259
+ continue;
260
+ }
261
+ if (S.type === "param" || S.type === "wildcard") {
262
+ if (P && !g)
263
+ throw new E(`Missing text before "${S.name}" ${S.type}`, p);
264
+ S.type === "param" ? (l += w & 2 ? `(${H(c, g)}+)` : I(D, "wildcard") ? `(${H(c, M(D))}+)` : w & 1 ? `(${H(c, g)}+|${a(g)})` : `(${H(c, "")}+)`, w |= P = 1) : (l += w & 2 ? `(${H(g, "")}+)` : d ? `(${H(d, "")}+|${H(c, "")}+)` : "([^]+)", d = "", w |= P = 2), m.push(S), g = "";
265
+ continue;
266
+ }
267
+ throw new TypeError(`Unknown token type: ${S.type}`);
268
+ }
269
+ return l;
270
+ }
271
+ function H(r, c) {
272
+ return c.length > r.length ? H(c, r) : (r === c && (c = ""), c.length > 1 ? `(?:(?!${a(r)}|${a(c)})[^])` : r.length > 1 ? `(?:(?!${a(r)})[^${a(c)}])` : `[^${a(r + c)}]`);
273
+ }
274
+ function _(r, c) {
275
+ let m = "";
276
+ for (; c < r.length; ) {
277
+ const p = r[c++];
278
+ if (p.type === "text") {
279
+ m += s(p.value);
280
+ continue;
281
+ }
282
+ if (p.type === "group") {
283
+ m += "{" + _(p.tokens, 0) + "}";
284
+ continue;
285
+ }
286
+ if (p.type === "param") {
287
+ m += ":" + O(p.name, r[c]);
288
+ continue;
289
+ }
290
+ if (p.type === "wildcard") {
291
+ m += "*" + O(p.name, r[c]);
292
+ continue;
293
+ }
294
+ throw new TypeError(`Unknown token type: ${p.type}`);
295
+ }
296
+ return m;
297
+ }
298
+ function dt(r) {
299
+ return _(r.tokens, 0);
300
+ }
301
+ function O(r, c) {
302
+ return !u.test(r) || c?.type === "text" && i.test(c.value[0]) ? JSON.stringify(r) : r;
303
+ }
304
+ return Y;
305
+ }
306
+ var Mt = Re();
307
+ const re = Gt({
308
+ id: "",
309
+ isActive: !1,
310
+ isRoot: !0,
311
+ isPrev: !1,
312
+ zIndex: 0,
313
+ pathname: "",
314
+ params: {},
315
+ transitionName: "none",
316
+ prevTransitionName: "none",
317
+ layoutId: null,
318
+ routePath: ""
319
+ });
320
+ function pt() {
321
+ return Ut(re);
322
+ }
323
+ const oe = Gt({}), ie = Gt(() => {
324
+ });
325
+ function be(n, e) {
326
+ return e.type === "SET" ? e.params : n;
327
+ }
328
+ function Le({ children: n }) {
329
+ const { isActive: e, params: o } = pt(), [i, u] = me(be, o);
330
+ return at(() => {
331
+ const s = async (a) => {
332
+ a.state?.step && await G.addTask(async () => {
333
+ u({ type: "SET", params: a.state?.params || {} });
334
+ });
335
+ };
336
+ return e && window.addEventListener("popstate", s), () => {
337
+ window.removeEventListener("popstate", s);
338
+ };
339
+ }, [e, u]), /* @__PURE__ */ L(ie.Provider, { value: u, children: /* @__PURE__ */ L(oe.Provider, { value: i, children: n }) });
340
+ }
341
+ function $e({ children: n }) {
342
+ const e = U((i) => i.index), o = U((i) => i.histories);
343
+ return o.map(
344
+ (i) => ee.toArray(n).filter(
345
+ (u) => Mt.pathToRegexp(u.props.path).regexp.test(
346
+ i.pathname
347
+ )
348
+ )
349
+ ).map(([i], u) => /* @__PURE__ */ L(
350
+ re.Provider,
351
+ {
352
+ value: {
353
+ id: o[u].id,
354
+ isActive: u === e,
355
+ isRoot: u === 0,
356
+ isPrev: u < e - 1,
357
+ zIndex: u,
358
+ pathname: o[u].pathname,
359
+ params: o[u].params,
360
+ transitionName: o[e].transitionName,
361
+ prevTransitionName: o[e - 1]?.transitionName,
362
+ layoutId: o[u].layoutId,
363
+ routePath: we(
364
+ i.props.path,
365
+ o[u].pathname
366
+ )
367
+ },
368
+ children: /* @__PURE__ */ L(Le, { children: i })
369
+ },
370
+ o[u].id
371
+ ));
372
+ }
373
+ const Wt = "data-flemo", Jt = () => {
374
+ if (Ht()) return;
375
+ const n = Se(nt.values(), lt.values());
376
+ let e = document.head.querySelector(`style[${Wt}]`);
377
+ e || (e = document.createElement("style"), e.setAttribute(Wt, ""), document.head.appendChild(e)), e.textContent !== n && (e.textContent = n);
378
+ };
379
+ function Ne(n, e) {
380
+ ye(() => {
381
+ for (const o of n) nt.set(o.name, o);
382
+ for (const o of e) lt.set(o.name, o);
383
+ return Jt(), () => {
384
+ for (const o of n) nt.delete(o.name);
385
+ for (const o of e) lt.delete(o.name);
386
+ Jt();
387
+ };
388
+ }, [n, e]);
389
+ }
390
+ const Ce = [], ke = [];
391
+ function Be({
392
+ children: n,
393
+ initPath: e = "/",
394
+ defaultTransitionName: o = "cupertino",
395
+ transitions: i = Ce,
396
+ decorators: u = ke
397
+ }) {
398
+ const s = Ht() ? e || "/" : window.location.pathname, a = Ht() ? s.split("?")[1] || "" : window.location.search;
399
+ return Ot.setState({
400
+ defaultTransitionName: o
401
+ }), U.setState({
402
+ index: 0,
403
+ histories: [
404
+ {
405
+ id: "root",
406
+ pathname: s,
407
+ params: ve(
408
+ ee.toArray(n).map((v) => v.props.path).flat(),
409
+ s,
410
+ a
411
+ ),
412
+ transitionName: o,
413
+ layoutId: null
414
+ }
415
+ ]
416
+ }), Ne(i, u), at(() => {
417
+ window.history.state?.index || window.history.replaceState(
418
+ {
419
+ id: "root",
420
+ index: 0,
421
+ status: "IDLE",
422
+ params: {},
423
+ transitionName: o,
424
+ layoutId: null
425
+ },
426
+ "",
427
+ window.location.href
428
+ );
429
+ }, [o]), /* @__PURE__ */ At(fe, { children: [
430
+ /* @__PURE__ */ L(De, {}),
431
+ /* @__PURE__ */ L($e, { children: n })
432
+ ] });
433
+ }
434
+ function qe({ element: n }) {
435
+ return n;
436
+ }
437
+ function Tt(n, e) {
438
+ const o = e ?? {}, i = Mt.compile(n), u = Object.fromEntries(
439
+ Object.entries(o).map(([h, R]) => [h, String(R)])
440
+ ), s = i(u), v = (typeof n == "string" ? Mt.parse(n) : n).tokens.filter((h) => h.type === "param").map((h) => h.name), E = Object.fromEntries(
441
+ Object.entries(o).filter(([h]) => !v.includes(h))
442
+ ), f = new URLSearchParams(E).toString();
443
+ return { pathname: `${s}${f ? `?${f}` : ""}`, toPathname: s };
444
+ }
445
+ function ze() {
446
+ return {
447
+ push: async (i, u, s) => {
448
+ const { status: a } = q.getState();
449
+ if (a !== "COMPLETED" && a !== "IDLE")
450
+ return;
451
+ const { index: v, addHistory: E } = U.getState(), f = Ot.getState().defaultTransitionName, { transitionName: x = f, layoutId: h = null } = s ?? {}, R = G.generateTaskId();
452
+ (await G.addTask(
453
+ async () => {
454
+ const { setStatus: $, setTransitionTaskId: C } = q.getState();
455
+ $("PUSHING"), C(R);
456
+ const { pathname: b, toPathname: X } = Tt(i, u ?? {});
457
+ return window.history.pushState(
458
+ {
459
+ id: R,
460
+ index: v + 1,
461
+ status: "PUSHING",
462
+ params: u,
463
+ transitionName: x,
464
+ layoutId: h
465
+ },
466
+ "",
467
+ b
468
+ ), E({
469
+ id: R,
470
+ pathname: X,
471
+ params: u ?? {},
472
+ transitionName: x,
473
+ layoutId: h
474
+ }), () => {
475
+ $("COMPLETED");
476
+ };
477
+ },
478
+ {
479
+ id: R,
480
+ control: {
481
+ manual: !0
482
+ }
483
+ }
484
+ )).result?.();
485
+ },
486
+ replace: async (i, u, s) => {
487
+ const { status: a } = q.getState();
488
+ if (a !== "COMPLETED" && a !== "IDLE")
489
+ return;
490
+ const { index: v, addHistory: E } = U.getState(), f = U.getState().replaceHistory, x = Ot.getState().defaultTransitionName, { transitionName: h = x, layoutId: R = null } = s ?? {}, $ = G.generateTaskId();
491
+ (await G.addTask(
492
+ async () => {
493
+ const { setStatus: C, setTransitionTaskId: b } = q.getState();
494
+ C("REPLACING"), b($);
495
+ const { pathname: X, toPathname: H } = Tt(i, u ?? {});
496
+ return window.history.replaceState(
497
+ {
498
+ id: $,
499
+ index: v,
500
+ status: "REPLACING",
501
+ params: u,
502
+ transitionName: h,
503
+ layoutId: R
504
+ },
505
+ "",
506
+ X
507
+ ), E({
508
+ id: $,
509
+ pathname: H,
510
+ params: u ?? {},
511
+ transitionName: h,
512
+ layoutId: R
513
+ }), async () => {
514
+ f(v), C("COMPLETED");
515
+ };
516
+ },
517
+ {
518
+ id: $,
519
+ control: {
520
+ manual: !0
521
+ }
522
+ }
523
+ )).result?.();
524
+ },
525
+ pop: async () => {
526
+ const i = G.generateTaskId();
527
+ (await G.addTask(
528
+ async (u) => {
529
+ const { index: s, popHistory: a } = U.getState();
530
+ if (s <= 0) {
531
+ u.abort();
532
+ return;
533
+ }
534
+ const { setStatus: v, setTransitionTaskId: E } = q.getState();
535
+ return v("POPPING"), E(i), ne(), window.history.back(), async () => {
536
+ a(s), v("COMPLETED");
537
+ };
538
+ },
539
+ {
540
+ id: i,
541
+ control: {
542
+ manual: !0
543
+ }
544
+ }
545
+ )).result?.();
546
+ }
547
+ };
548
+ }
549
+ function Ke() {
550
+ const { routePath: n } = pt(), e = Ut(ie);
551
+ return {
552
+ pushStep: async (s) => {
553
+ (await G.addTask(async () => {
554
+ const { pathname: a } = Tt(n, s);
555
+ return window.history.state?.step || window.history.replaceState(
556
+ {
557
+ ...window.history.state,
558
+ step: !0
559
+ },
560
+ "",
561
+ window.location.pathname
562
+ ), window.history.pushState(
563
+ {
564
+ ...window.history.state,
565
+ step: !0,
566
+ params: s
567
+ },
568
+ "",
569
+ a
570
+ ), async () => e({ type: "SET", params: s });
571
+ })).result?.();
572
+ },
573
+ replaceStep: async (s) => {
574
+ (await G.addTask(async () => {
575
+ const { pathname: a } = Tt(n, s);
576
+ return window.history.replaceState(
577
+ {
578
+ ...window.history.state,
579
+ step: !0,
580
+ params: s
581
+ },
582
+ "",
583
+ a
584
+ ), async () => e({ type: "SET", params: s });
585
+ })).result?.();
586
+ },
587
+ popStep: async () => {
588
+ const s = G.generateTaskId();
589
+ (await G.addTask(
590
+ async (a) => {
591
+ const v = new Promise((C) => {
592
+ window.addEventListener(
593
+ "popstate",
594
+ (b) => C(b.state),
595
+ { once: !0 }
596
+ );
597
+ }), E = new Promise(
598
+ (C) => setTimeout(() => C(void 0), 200)
599
+ );
600
+ ne(), window.history.back();
601
+ const f = await Promise.race([
602
+ v,
603
+ E
604
+ ]);
605
+ if (!f) {
606
+ a.abort();
607
+ return;
608
+ }
609
+ if (f.step) {
610
+ e({ type: "SET", params: f.params ?? {} }), a.abort();
611
+ return;
612
+ }
613
+ const { setStatus: x, setTransitionTaskId: h } = q.getState(), { index: R, popHistory: $ } = U.getState();
614
+ return x("POPPING"), h(s), async () => {
615
+ $(R), x("COMPLETED");
616
+ };
617
+ },
618
+ {
619
+ id: s,
620
+ control: {
621
+ manual: !0
622
+ }
623
+ }
624
+ )).result?.();
625
+ }
626
+ };
627
+ }
628
+ function We() {
629
+ return Ut(oe);
630
+ }
631
+ function Ae({ freeze: n, children: e }) {
632
+ const o = N(e);
633
+ return n || (o.current = e), /* @__PURE__ */ L(
634
+ "div",
635
+ {
636
+ style: {
637
+ display: n ? "none" : void 0
638
+ },
639
+ children: o.current
640
+ }
641
+ );
642
+ }
643
+ function He({ ref: n, style: e, ...o }) {
644
+ const { isActive: i, transitionName: u } = pt(), s = N(null);
645
+ he(n, () => s.current);
646
+ const a = q((x) => x.status), v = nt.get(u) ?? nt.get("none"), { decoratorName: E } = v, f = lt.get(E);
647
+ return f ? /* @__PURE__ */ L(
648
+ "div",
649
+ {
650
+ ref: s,
651
+ "data-flemo-decorator": !0,
652
+ "data-flemo-decorator-name": f.name,
653
+ "data-flemo-status": a,
654
+ "data-flemo-active": i ? "true" : "false",
655
+ style: {
656
+ position: "absolute",
657
+ top: 0,
658
+ left: 0,
659
+ width: "100%",
660
+ height: "100%",
661
+ pointerEvents: "none",
662
+ zIndex: 1,
663
+ ...e
664
+ },
665
+ ...o
666
+ }
667
+ ) : null;
668
+ }
669
+ const Qt = (n) => {
670
+ let e;
671
+ const o = /* @__PURE__ */ new Set(), i = (f, x) => {
672
+ const h = typeof f == "function" ? f(e) : f;
673
+ if (!Object.is(h, e)) {
674
+ const R = e;
675
+ e = x ?? (typeof h != "object" || h === null) ? h : Object.assign({}, e, h), o.forEach(($) => $(e, R));
676
+ }
677
+ }, u = () => e, v = { setState: i, getState: u, getInitialState: () => E, subscribe: (f) => (o.add(f), () => o.delete(f)) }, E = e = n(i, u, v);
678
+ return v;
679
+ }, Oe = ((n) => n ? Qt(n) : Qt), Me = (n) => n;
680
+ function Ge(n, e = Me) {
681
+ const o = gt.useSyncExternalStore(
682
+ n.subscribe,
683
+ gt.useCallback(() => e(n.getState()), [n, e]),
684
+ gt.useCallback(() => e(n.getInitialState()), [n, e])
685
+ );
686
+ return gt.useDebugValue(o), o;
687
+ }
688
+ const Zt = (n) => {
689
+ const e = Oe(n), o = (i) => Ge(e, i);
690
+ return Object.assign(o, e), o;
691
+ }, Ue = ((n) => n ? Zt(n) : Zt), et = Ue((n) => ({
692
+ dragStatus: "IDLE",
693
+ replaceTransitionStatus: "IDLE",
694
+ sharedBars: {},
695
+ setDragStatus: (e) => n({ dragStatus: e }),
696
+ setReplaceTransitionStatus: (e) => n({ replaceTransitionStatus: e }),
697
+ registerSharedBars: (e, o) => n((i) => ({ sharedBars: { ...i.sharedBars, [e]: o } })),
698
+ unregisterSharedBars: (e) => n((o) => {
699
+ const i = { ...o.sharedBars };
700
+ return delete i[e], { sharedBars: i };
701
+ })
702
+ }));
703
+ let Ct = 0;
704
+ function Ve() {
705
+ const [n, e] = vt(0), [o, i] = vt(0);
706
+ return at(() => {
707
+ let u = 0;
708
+ const s = () => {
709
+ cancelAnimationFrame(u), u = requestAnimationFrame(() => {
710
+ let a = document.documentElement.scrollHeight - (window.visualViewport?.height || 0);
711
+ a = a < 0 ? 0 : a;
712
+ let v = a - Ct;
713
+ v = v < 0 ? 0 : v, Ct || (Ct = a), i(v), e(a);
714
+ });
715
+ };
716
+ return window.visualViewport?.addEventListener("resize", s), window.visualViewport?.addEventListener("scroll", s), () => {
717
+ cancelAnimationFrame(u), window.visualViewport?.removeEventListener("resize", s), window.visualViewport?.removeEventListener("scroll", s);
718
+ };
719
+ }, []), { viewportScrollHeight: n, changedViewportScrollHeight: o };
720
+ }
721
+ const Ye = (n) => typeof HTMLElement < "u" && n instanceof HTMLElement, St = (n, e) => {
722
+ n.style.transition = "";
723
+ {
724
+ n.style.removeProperty("transform"), n.style.removeProperty("opacity");
725
+ return;
726
+ }
727
+ }, st = (n, e, o = {}) => {
728
+ if (!Ye(n)) return Promise.resolve();
729
+ const i = n, u = Te(e);
730
+ if (u.length === 0) return Promise.resolve();
731
+ const s = typeof o.duration == "number" ? o.duration : 0, a = typeof o.delay == "number" && o.delay > 0 ? o.delay : 0, v = Ee(o.ease);
732
+ if (s <= 0 && a <= 0) {
733
+ i.style.transition = "none";
734
+ for (const f of u) i.style.setProperty(f.property, f.value);
735
+ return Promise.resolve();
736
+ }
737
+ const E = u.map((f) => `${f.property} ${s}s ${v} ${a}s`).join(", ");
738
+ i.style.transition = E, i.offsetWidth;
739
+ for (const f of u) i.style.setProperty(f.property, f.value);
740
+ return new Promise((f) => {
741
+ let x = !1;
742
+ const h = () => {
743
+ x || (x = !0, i.removeEventListener("transitionend", R), f());
744
+ }, R = ($) => {
745
+ $.target === i && h();
746
+ };
747
+ i.addEventListener("transitionend", R), setTimeout(h, (s + a) * 1e3 + 60);
748
+ });
749
+ }, te = q, kt = "data-flemo-skip-animation";
750
+ function _e({
751
+ children: n,
752
+ statusBarHeight: e,
753
+ statusBarColor: o,
754
+ systemNavigationBarHeight: i,
755
+ systemNavigationBarColor: u,
756
+ sharedAppBar: s,
757
+ sharedNavigationBar: a,
758
+ appBar: v,
759
+ navigationBar: E,
760
+ hideStatusBar: f,
761
+ hideSystemNavigationBar: x,
762
+ backgroundColor: h = "white",
763
+ contentScrollable: R = !0,
764
+ ...$
765
+ }) {
766
+ const { id: C, isActive: b, isRoot: X, zIndex: H, transitionName: _, prevTransitionName: dt } = pt(), O = te((t) => t.status), r = et((t) => t.dragStatus), c = et.getState().setDragStatus, m = et.getState().setReplaceTransitionStatus, p = U((t) => t.index), l = nt.get(_) ?? nt.get("none"), { initial: g, swipeDirection: d, decoratorName: P } = l, w = lt.get(P), { viewportScrollHeight: D } = Ve(), I = D > 0, [M, S] = vt(0), [k, V] = vt(0), Vt = N(null), B = N(null), J = N(null), Q = N(null), rt = N(null), z = N(!1), ct = N(!1), Z = N(!1), se = N(0), Et = N({ x: 0, y: 0 }), ft = N({ x: 0, y: 0 }), Pt = N(0), xt = N({ x: 0, y: 0 }), K = N({
767
+ element: null,
768
+ hasMarker: !1
769
+ }), tt = N({ element: null, hasMarker: !1 }), It = N(0), Dt = N(0), Rt = N(null), bt = N(null), Lt = (t) => {
770
+ const y = ft.current;
771
+ return {
772
+ point: { x: t.clientX, y: t.clientY },
773
+ offset: {
774
+ x: t.clientX - Et.current.x,
775
+ y: t.clientY - Et.current.y
776
+ },
777
+ delta: { x: t.clientX - y.x, y: t.clientY - y.y },
778
+ velocity: xt.current
779
+ };
780
+ }, ae = (t) => {
781
+ const y = t.timeStamp, T = Math.max(1, y - Pt.current), A = ft.current;
782
+ xt.current = {
783
+ x: (t.clientX - A.x) / T * 1e3,
784
+ y: (t.clientY - A.y) / T * 1e3
785
+ }, ft.current = { x: t.clientX, y: t.clientY }, Pt.current = y;
786
+ }, mt = async (t) => {
787
+ if (!d || D > 10) return;
788
+ const y = B.current;
789
+ if (!y) return;
790
+ const T = Vt.current?.parentElement?.previousElementSibling;
791
+ if (J.current = T?.querySelector("[data-flemo-screen]") ?? null, rt.current = T?.querySelector("[data-flemo-decorator]") ?? null, !J.current) return;
792
+ Z.current = !0, se.current = t.timeStamp, Et.current = { x: t.clientX, y: t.clientY }, ft.current = { x: t.clientX, y: t.clientY }, Pt.current = t.timeStamp, xt.current = { x: 0, y: 0 }, y.setPointerCapture(t.pointerId), await l?.onSwipeStart(t, Lt(t), {
793
+ animate: st,
794
+ currentScreen: y,
795
+ prevScreen: J.current,
796
+ onStart: (W) => w?.onSwipeStart?.(W, {
797
+ animate: st,
798
+ currentDecorator: Q.current,
799
+ prevDecorator: rt.current
800
+ })
801
+ }) ? c("PENDING") : (c("IDLE"), Z.current = !1);
802
+ }, ce = (t) => {
803
+ !d || !Z.current || D > 10 || (ae(t), l.onSwipe(t, Lt(t), {
804
+ animate: st,
805
+ currentScreen: B.current,
806
+ prevScreen: J.current,
807
+ onProgress: (y, T) => w?.onSwipe?.(y, T, {
808
+ animate: st,
809
+ currentDecorator: Q.current,
810
+ prevDecorator: rt.current
811
+ })
812
+ }));
813
+ }, ue = async (t) => {
814
+ if (!d || !Z.current) return;
815
+ Z.current = !1;
816
+ const y = B.current;
817
+ y && y.hasPointerCapture(t.pointerId) && y.releasePointerCapture(t.pointerId);
818
+ const T = Lt(t);
819
+ await l?.onSwipeEnd(t, T, {
820
+ animate: st,
821
+ currentScreen: B.current,
822
+ prevScreen: J.current,
823
+ onStart: (W) => w?.onSwipeEnd?.(W, {
824
+ animate: st,
825
+ currentDecorator: Q.current,
826
+ prevDecorator: rt.current
827
+ })
828
+ }) ? (B.current?.setAttribute(kt, "true"), Q.current?.setAttribute(kt, "true"), window.history.back()) : (St(B.current), J.current && St(J.current), Q.current && St(Q.current), rt.current && St(rt.current), c("IDLE"));
829
+ }, le = (t) => {
830
+ if (!(!X && b && O === "COMPLETED" && r === "IDLE" && !!d && D < 10))
831
+ return;
832
+ K.current = zt(t.target, {
833
+ direction: "x",
834
+ verifyByScroll: !0
835
+ }), tt.current = zt(t.target, {
836
+ direction: "y",
837
+ verifyByScroll: !0
838
+ }), It.current = t.clientX, Dt.current = t.clientY, (!K.current.element && !tt.current.element || K.current.element || tt.current.element) && (z.current = !0);
839
+ }, pe = (t) => {
840
+ if (D > 10)
841
+ return;
842
+ if (Z.current) {
843
+ ce(t.nativeEvent);
844
+ return;
845
+ }
846
+ const y = !K.current.element && !tt.current.element;
847
+ if (z.current && y) {
848
+ z.current = !1, ct.current = !0;
849
+ const T = t.clientY - Dt.current, A = t.clientX - It.current;
850
+ (d === "y" && T > 0 || d === "x" && A > 0) && mt(t.nativeEvent);
851
+ } else if (z.current && !y) {
852
+ const T = t.clientX - It.current, A = t.clientY - Dt.current, W = tt.current.element && tt.current.element.scrollTop <= 0, ot = K.current.element && K.current.element.scrollLeft <= 0 && K.current.hasMarker;
853
+ (d === "y" && (W || K.current.element) && A > 0 && Math.abs(T) < 2 || d === "x" && (ot || tt.current.element) && T > 0 && Math.abs(A) < 2) && (z.current = !1, ct.current = !0, mt(t.nativeEvent));
854
+ }
855
+ }, Yt = (t) => {
856
+ z.current = !1, ct.current = !1, Z.current && ue(t.nativeEvent);
857
+ };
858
+ at(() => {
859
+ const t = B.current;
860
+ if (!t) return;
861
+ const y = (T) => {
862
+ ct.current && T.preventDefault(), T.target?.dataset.swipeAtEdgeBar === "true" && T.preventDefault();
863
+ };
864
+ return t.addEventListener("touchmove", y, {
865
+ passive: !1
866
+ }), () => {
867
+ t.removeEventListener("touchmove", y);
868
+ };
869
+ }, []), at(() => {
870
+ if (!b) {
871
+ O === "REPLACING" && dt !== _ && m("PENDING");
872
+ return;
873
+ }
874
+ if (O === "COMPLETED") {
875
+ c("IDLE"), m("IDLE");
876
+ return;
877
+ }
878
+ if (O === "IDLE") return;
879
+ const t = B.current;
880
+ if (!t) return;
881
+ const y = () => {
882
+ const j = te.getState().transitionTaskId;
883
+ j && G.resolveTask(j);
884
+ }, T = `${O}-true`;
885
+ if (!(!(t.getAttribute(kt) === "true") && Pe(l, T))) {
886
+ queueMicrotask(y);
887
+ return;
888
+ }
889
+ const ot = xe("screen", _, T), it = (j) => {
890
+ j.target === t && j.animationName === ot && (t.removeEventListener("animationend", it), y());
891
+ };
892
+ return t.addEventListener("animationend", it), () => {
893
+ t.removeEventListener("animationend", it);
894
+ };
895
+ }, [
896
+ O,
897
+ b,
898
+ C,
899
+ dt,
900
+ _,
901
+ l,
902
+ c,
903
+ m
904
+ ]), wt(() => {
905
+ const t = Rt.current;
906
+ if (!t) {
907
+ S(0);
908
+ return;
909
+ }
910
+ S(t.offsetHeight);
911
+ const y = new ResizeObserver(([T]) => {
912
+ S(T.contentRect.height);
913
+ });
914
+ return y.observe(t), () => {
915
+ y.disconnect();
916
+ };
917
+ }, [s]), wt(() => {
918
+ const t = bt.current;
919
+ if (!t) {
920
+ V(0);
921
+ return;
922
+ }
923
+ V(t.offsetHeight);
924
+ const y = new ResizeObserver(([T]) => {
925
+ V(T.contentRect.height);
926
+ });
927
+ return y.observe(t), () => {
928
+ y.disconnect();
929
+ };
930
+ }, [a]), wt(() => {
931
+ const { registerSharedBars: t, unregisterSharedBars: y } = et.getState();
932
+ return t(C, {
933
+ appBar: !!s,
934
+ navigationBar: !!a
935
+ }), () => y(C);
936
+ }, [C, s, a]);
937
+ const _t = O === "PUSHING" || O === "POPPING" || O === "REPLACING" || r === "PENDING", jt = b || H === p - 1, $t = !!s, Nt = !!a;
938
+ wt(() => {
939
+ if (!_t || !jt || !$t && !Nt) return;
940
+ const t = B.current;
941
+ if (!t) return;
942
+ const y = Rt.current, T = bt.current, A = Ie(l);
943
+ if (A.length === 0) return;
944
+ const W = A.join(", "), ot = (F) => {
945
+ F && (F.style.willChange = W);
946
+ }, it = (F) => {
947
+ F && F.style.removeProperty("will-change");
948
+ };
949
+ ot(y), ot(T);
950
+ const j = (F) => {
951
+ if (F)
952
+ for (const yt of A)
953
+ F.style.removeProperty(yt);
954
+ };
955
+ let Ft = 0;
956
+ const Xt = () => {
957
+ const F = b ? U.getState().histories[p - 1]?.id : U.getState().histories[p]?.id, yt = F ? et.getState().sharedBars[F] : void 0, Bt = $t && !yt?.appBar, qt = Nt && !yt?.navigationBar, ht = Bt || qt ? getComputedStyle(t) : null;
958
+ if (y)
959
+ if (Bt && ht)
960
+ for (const ut of A)
961
+ y.style.setProperty(ut, ht.getPropertyValue(ut));
962
+ else
963
+ j(y);
964
+ if (T)
965
+ if (qt && ht)
966
+ for (const ut of A)
967
+ T.style.setProperty(ut, ht.getPropertyValue(ut));
968
+ else
969
+ j(T);
970
+ Ft = requestAnimationFrame(Xt);
971
+ };
972
+ return Xt(), () => {
973
+ cancelAnimationFrame(Ft), j(y), j(T), it(y), it(T);
974
+ };
975
+ }, [
976
+ _t,
977
+ jt,
978
+ $t,
979
+ Nt,
980
+ b,
981
+ p,
982
+ l
983
+ ]);
984
+ const de = (() => {
985
+ if (!b) return {};
986
+ if (O !== "PUSHING" && O !== "REPLACING") return {};
987
+ const t = {};
988
+ return typeof g.x == "number" && (t.transform = `translateX(${g.x}px)`), typeof g.x == "string" && (t.transform = `translateX(${g.x})`), typeof g.y == "number" && (t.transform = `translateY(${g.y}px)`), typeof g.y == "string" && (t.transform = `translateY(${g.y})`), typeof g.opacity == "number" && (t.opacity = `${g.opacity}`), t;
989
+ })();
990
+ return /* @__PURE__ */ At(
991
+ "div",
992
+ {
993
+ ref: Vt,
994
+ style: {
995
+ position: "fixed",
996
+ top: 0,
997
+ left: 0,
998
+ width: "100%",
999
+ height: "100%",
1000
+ display: "flex",
1001
+ // `contain: layout style` keeps layout/style scoped without `paint`,
1002
+ // which would make this element the containing block for `position:
1003
+ // fixed` descendants and trap consumer overlays (e.g. bottom sheets)
1004
+ // inside the screen.
1005
+ contain: "layout style",
1006
+ flexDirection: "column",
1007
+ boxSizing: "border-box",
1008
+ overscrollBehavior: "contain"
1009
+ },
1010
+ children: [
1011
+ /* @__PURE__ */ L(
1012
+ "div",
1013
+ {
1014
+ "data-swipe-at-edge-bar": !0,
1015
+ style: {
1016
+ position: "fixed",
1017
+ top: 0,
1018
+ left: 0,
1019
+ width: 8,
1020
+ height: "100%",
1021
+ zIndex: 1
1022
+ }
1023
+ }
1024
+ ),
1025
+ /* @__PURE__ */ At(
1026
+ "div",
1027
+ {
1028
+ ref: B,
1029
+ ...$,
1030
+ onPointerDown: le,
1031
+ onPointerMove: pe,
1032
+ onPointerUp: Yt,
1033
+ onPointerCancel: Yt,
1034
+ "data-flemo-screen": !0,
1035
+ "data-flemo-transition": _,
1036
+ "data-flemo-status": O,
1037
+ "data-flemo-active": b ? "true" : "false",
1038
+ style: {
1039
+ display: "flex",
1040
+ flexDirection: "column",
1041
+ height: "100%",
1042
+ backgroundColor: h,
1043
+ overflowY: R ? void 0 : "auto",
1044
+ touchAction: d === "x" ? "pan-y" : d === "y" ? "pan-x" : "auto",
1045
+ ...de,
1046
+ ...$.style
1047
+ },
1048
+ children: [
1049
+ !f && e && /* @__PURE__ */ L("div", { style: { minHeight: e }, children: /* @__PURE__ */ L(
1050
+ "div",
1051
+ {
1052
+ style: {
1053
+ position: "fixed",
1054
+ top: 0,
1055
+ width: "100%",
1056
+ minHeight: e,
1057
+ backgroundColor: o
1058
+ }
1059
+ }
1060
+ ) }),
1061
+ s && /* @__PURE__ */ L(
1062
+ "div",
1063
+ {
1064
+ style: {
1065
+ width: "100%",
1066
+ minHeight: M
1067
+ }
1068
+ }
1069
+ ),
1070
+ v,
1071
+ /* @__PURE__ */ L(
1072
+ "div",
1073
+ {
1074
+ style: {
1075
+ display: "flex",
1076
+ flexDirection: "column",
1077
+ flexGrow: 1,
1078
+ overflowY: R ? "auto" : void 0
1079
+ },
1080
+ children: n
1081
+ }
1082
+ ),
1083
+ E,
1084
+ a && /* @__PURE__ */ L(
1085
+ "div",
1086
+ {
1087
+ style: {
1088
+ display: I ? "none" : void 0,
1089
+ width: "100%",
1090
+ minHeight: k
1091
+ }
1092
+ }
1093
+ ),
1094
+ !x && i && /* @__PURE__ */ L(
1095
+ "div",
1096
+ {
1097
+ style: {
1098
+ display: I ? "none" : void 0,
1099
+ minHeight: i
1100
+ },
1101
+ children: /* @__PURE__ */ L(
1102
+ "div",
1103
+ {
1104
+ style: {
1105
+ position: "fixed",
1106
+ bottom: 0,
1107
+ width: "100%",
1108
+ minHeight: i,
1109
+ backgroundColor: u
1110
+ }
1111
+ }
1112
+ )
1113
+ }
1114
+ )
1115
+ ]
1116
+ }
1117
+ ),
1118
+ s && /* @__PURE__ */ L(
1119
+ "div",
1120
+ {
1121
+ ref: Rt,
1122
+ style: {
1123
+ position: "fixed",
1124
+ top: f ? 0 : e,
1125
+ left: 0,
1126
+ width: "100%",
1127
+ zIndex: 1
1128
+ },
1129
+ children: s
1130
+ }
1131
+ ),
1132
+ a && /* @__PURE__ */ L(
1133
+ "div",
1134
+ {
1135
+ ref: bt,
1136
+ style: {
1137
+ display: I ? "none" : void 0,
1138
+ position: "fixed",
1139
+ bottom: x ? 0 : i,
1140
+ left: 0,
1141
+ width: "100%",
1142
+ zIndex: 1
1143
+ },
1144
+ children: a
1145
+ }
1146
+ ),
1147
+ w && /* @__PURE__ */ L(He, { ref: Q }),
1148
+ /* @__PURE__ */ L(
1149
+ "div",
1150
+ {
1151
+ "data-swipe-at-edge-bar": !0,
1152
+ style: {
1153
+ position: "fixed",
1154
+ top: 0,
1155
+ right: 0,
1156
+ width: 8,
1157
+ height: "100%",
1158
+ zIndex: 1
1159
+ }
1160
+ }
1161
+ )
1162
+ ]
1163
+ }
1164
+ );
1165
+ }
1166
+ function Je({ children: n, ...e }) {
1167
+ const { isActive: o, isPrev: i, zIndex: u } = pt(), s = U((h) => h.index), a = q((h) => h.status), v = et((h) => h.dragStatus), E = et((h) => h.replaceTransitionStatus), x = !o && (a === "COMPLETED" && v === "IDLE") || i && s - 2 <= u && E === "IDLE" || i && s - 2 > u;
1168
+ return /* @__PURE__ */ L(Ae, { freeze: x, children: /* @__PURE__ */ L(_e, { ...e, children: n }) });
1169
+ }
1170
+ export {
1171
+ qe as Route,
1172
+ Be as Router,
1173
+ Je as Screen,
1174
+ re as ScreenContext,
1175
+ He as ScreenDecorator,
1176
+ Ae as ScreenFreeze,
1177
+ _e as ScreenMotion,
1178
+ tn as createDecorator,
1179
+ en as createRawDecorator,
1180
+ nn as createRawTransition,
1181
+ rn as createTransition,
1182
+ ze as useNavigate,
1183
+ We as useParams,
1184
+ pt as useScreen,
1185
+ et as useScreenStore,
1186
+ Ke as useStep,
1187
+ Ve as useViewportScrollHeight
1188
+ };