flemo 1.1.3 → 1.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,12 +6,31 @@ interface TaskResult<T> {
6
6
  timestamp?: number;
7
7
  instanceId?: string;
8
8
  }
9
+ type TaskStatus = "PENDING" | "MANUAL_PENDING" | "SIGNAL_PENDING" | "PROCESSING" | "COMPLETED" | "FAILED" | "ROLLEDBACK";
9
10
  interface Control {
10
11
  manual?: boolean;
11
12
  delay?: number;
12
13
  condition?: () => Promise<boolean>;
13
14
  signal?: string;
14
15
  }
16
+ interface Task<T> {
17
+ id: string;
18
+ execute: (abortController: AbortController) => Promise<T>;
19
+ validate?: () => Promise<boolean>;
20
+ rollback?: () => Promise<void>;
21
+ control?: Control;
22
+ timestamp: number;
23
+ retryCount: number;
24
+ status: TaskStatus;
25
+ dependencies: string[];
26
+ instanceId: string;
27
+ abortController?: AbortController;
28
+ manualResolver?: {
29
+ resolve: (value: TaskResult<T>) => void;
30
+ reject: (error: Error) => void;
31
+ result: T;
32
+ };
33
+ }
15
34
  declare class TaskManager {
16
35
  private tasks;
17
36
  private readonly instanceId;
@@ -28,7 +47,7 @@ declare class TaskManager {
28
47
  private processPendingTasks;
29
48
  private waitForPendingTasks;
30
49
  private onTaskStatusChange;
31
- addTask<T>(execute: () => Promise<T>, options?: {
50
+ addTask<T>(execute: Task<T>["execute"], options?: {
32
51
  id?: string;
33
52
  delay?: number;
34
53
  validate?: () => Promise<boolean>;
package/dist/index.mjs CHANGED
@@ -1,11 +1,11 @@
1
- import { jsx as E, jsxs as et } from "react/jsx-runtime";
2
- import { useEffect as G, createContext as X, useReducer as Pt, Children as nt, useContext as q, Suspense as Et, useImperativeHandle as St, useRef as N } from "react";
3
- import { d as A, c as _ } from "./vendor-C8cPYUOQ.js";
1
+ import { jsx as w, jsxs as et } from "react/jsx-runtime";
2
+ import { useEffect as G, createContext as X, useReducer as Pt, Children as nt, useContext as q, Suspense as Et, useImperativeHandle as St, useRef as I } from "react";
3
+ import { d as x, c as _ } from "./vendor-C8cPYUOQ.js";
4
4
  import { animate as F } from "motion";
5
- import { animate as C, transform as st, useAnimate as at, motion as rt, useDragControls as wt } from "motion/react";
5
+ import { animate as A, transform as st, useAnimate as at, motion as rt, useDragControls as wt } from "motion/react";
6
6
  function yt(s, e, t) {
7
- const a = Array.isArray(s) ? s.find((o) => A.pathToRegexp(o).regexp.test(e)) || "" : A.pathToRegexp(s).regexp.test(e) ? s : "", n = A.match(a)(e), r = new URLSearchParams(t), c = Object.fromEntries(r.entries());
8
- return n ? { ...n.params, ...c } : {};
7
+ const a = Array.isArray(s) ? s.find((c) => x.pathToRegexp(c).regexp.test(e)) || "" : x.pathToRegexp(s).regexp.test(e) ? s : "", n = x.match(a)(e), i = new URLSearchParams(t), o = Object.fromEntries(i.entries());
8
+ return n ? { ...n.params, ...o } : {};
9
9
  }
10
10
  function Z() {
11
11
  return typeof document > "u";
@@ -23,7 +23,7 @@ class Lt {
23
23
  for (let n = 0; n < 10; n++) {
24
24
  if (!this.isLocked)
25
25
  return this.isLocked = !0, this.currentTaskId = e, !0;
26
- await new Promise((r) => setTimeout(r, 100));
26
+ await new Promise((i) => setTimeout(i, 100));
27
27
  }
28
28
  return !1;
29
29
  }
@@ -75,10 +75,10 @@ class Lt {
75
75
  }
76
76
  async addTask(e, t = {}) {
77
77
  const a = t.id || this.generateTaskId();
78
- return new Promise((n, r) => {
78
+ return new Promise((n, i) => {
79
79
  this.taskQueue = this.taskQueue.then(async () => {
80
80
  try {
81
- const { control: c, validate: o, rollback: u, dependencies: l = [], delay: f } = t, i = {
81
+ const { control: o, validate: c, rollback: u, dependencies: l = [], delay: p } = t, f = new AbortController(), r = {
82
82
  id: a,
83
83
  execute: e,
84
84
  timestamp: Date.now(),
@@ -86,64 +86,75 @@ class Lt {
86
86
  status: "PENDING",
87
87
  dependencies: l,
88
88
  instanceId: this.instanceId,
89
- validate: o,
89
+ validate: c,
90
90
  rollback: u,
91
- control: c
91
+ control: o,
92
+ abortController: f
92
93
  };
93
- this.tasks.set(i.id, i), this.pendingTaskQueue.length > 0 && (this.pendingTaskQueue.push(i), await this.waitForPendingTasks(), this.pendingTaskQueue = this.pendingTaskQueue.filter((p) => p.id !== i.id));
94
+ this.tasks.set(r.id, r), this.pendingTaskQueue.length > 0 && (this.pendingTaskQueue.push(r), await this.waitForPendingTasks(), this.pendingTaskQueue = this.pendingTaskQueue.filter((P) => P.id !== r.id));
94
95
  try {
95
- if (!await this.acquireLock(i.id))
96
- throw i.status = "FAILED", new Error("FAILED");
96
+ if (!await this.acquireLock(r.id))
97
+ throw r.status = "FAILED", new Error("FAILED");
97
98
  try {
98
- i.status = "PROCESSING";
99
- for (const m of i.dependencies) {
100
- const w = this.tasks.get(m);
101
- if (!w || w.status !== "COMPLETED")
102
- throw i.status = "FAILED", new Error("FAILED");
99
+ r.status = "PROCESSING";
100
+ for (const h of r.dependencies) {
101
+ const m = this.tasks.get(h);
102
+ if (!m || m.status !== "COMPLETED")
103
+ throw r.status = "FAILED", new Error("FAILED");
104
+ }
105
+ if (r.validate && !await r.validate())
106
+ throw r.status = "FAILED", new Error("FAILED");
107
+ p && p > 0 && await new Promise((h) => setTimeout(h, p));
108
+ const E = await r.execute(r.abortController);
109
+ if (r.abortController.signal.aborted) {
110
+ r.status = "COMPLETED", await this.onTaskStatusChange(r.id, "COMPLETED"), n({
111
+ success: !0,
112
+ result: void 0,
113
+ taskId: r.id,
114
+ timestamp: Date.now(),
115
+ instanceId: this.instanceId
116
+ });
117
+ return;
103
118
  }
104
- if (i.validate && !await i.validate())
105
- throw i.status = "FAILED", new Error("FAILED");
106
- f && f > 0 && await new Promise((m) => setTimeout(m, f));
107
- const g = await i.execute();
108
119
  if (t.control) {
109
- const m = t.control;
110
- if (m.delay && m.delay > 0 && await new Promise((w) => setTimeout(w, m.delay)), m.manual) {
111
- i.status = "MANUAL_PENDING", i.manualResolver = { resolve: n, reject: r, result: g }, this.pendingTaskQueue.push(i), await this.onTaskStatusChange(i.id, "MANUAL_PENDING");
120
+ const h = t.control;
121
+ if (h.delay && h.delay > 0 && await new Promise((m) => setTimeout(m, h.delay)), h.manual) {
122
+ r.status = "MANUAL_PENDING", r.manualResolver = { resolve: n, reject: i, result: E }, this.pendingTaskQueue.push(r), await this.onTaskStatusChange(r.id, "MANUAL_PENDING");
112
123
  return;
113
124
  }
114
- if (m.signal) {
115
- i.status = "SIGNAL_PENDING", i.manualResolver = { resolve: n, reject: r, result: g }, this.signalListeners.has(m.signal) || this.signalListeners.set(m.signal, /* @__PURE__ */ new Set()), this.signalListeners.get(m.signal).add(i.id), this.pendingTaskQueue.push(i), await this.onTaskStatusChange(i.id, "SIGNAL_PENDING");
125
+ if (h.signal) {
126
+ r.status = "SIGNAL_PENDING", r.manualResolver = { resolve: n, reject: i, result: E }, this.signalListeners.has(h.signal) || this.signalListeners.set(h.signal, /* @__PURE__ */ new Set()), this.signalListeners.get(h.signal).add(r.id), this.pendingTaskQueue.push(r), await this.onTaskStatusChange(r.id, "SIGNAL_PENDING");
116
127
  return;
117
128
  }
118
- if (m.condition && !await m.condition()) {
119
- i.status = "MANUAL_PENDING", i.manualResolver = { resolve: n, reject: r, result: g }, this.pendingTaskQueue.push(i), await this.onTaskStatusChange(i.id, "MANUAL_PENDING");
129
+ if (h.condition && !await h.condition()) {
130
+ r.status = "MANUAL_PENDING", r.manualResolver = { resolve: n, reject: i, result: E }, this.pendingTaskQueue.push(r), await this.onTaskStatusChange(r.id, "MANUAL_PENDING");
120
131
  return;
121
132
  }
122
133
  }
123
- i.status = "COMPLETED", await this.onTaskStatusChange(i.id, "COMPLETED"), n({
134
+ r.status = "COMPLETED", await this.onTaskStatusChange(r.id, "COMPLETED"), n({
124
135
  success: !0,
125
- result: g,
126
- taskId: i.id,
136
+ result: E,
137
+ taskId: r.id,
127
138
  timestamp: Date.now(),
128
139
  instanceId: this.instanceId
129
140
  });
130
- } catch (g) {
131
- if (i.status = "FAILED", i.rollback)
141
+ } catch (E) {
142
+ if (r.status = "FAILED", r.rollback)
132
143
  try {
133
- await i.rollback(), i.status = "ROLLEDBACK";
144
+ await r.rollback(), r.status = "ROLLEDBACK";
134
145
  } catch {
135
146
  }
136
- throw await this.onTaskStatusChange(i.id, i.status), g;
147
+ throw await this.onTaskStatusChange(r.id, r.status), E;
137
148
  } finally {
138
- this.releaseLock(i.id);
149
+ this.releaseLock(r.id);
139
150
  }
140
- } catch (p) {
141
- r(p);
151
+ } catch (P) {
152
+ i(P);
142
153
  }
143
- } catch (c) {
144
- r(c);
154
+ } catch (o) {
155
+ i(o);
145
156
  }
146
- }).catch(r);
157
+ }).catch(i);
147
158
  });
148
159
  }
149
160
  async resolveTask(e) {
@@ -161,7 +172,7 @@ class Lt {
161
172
  taskId: t.id,
162
173
  timestamp: Date.now(),
163
174
  instanceId: this.instanceId
164
- }), delete t.manualResolver, !0;
175
+ }), delete t.manualResolver, await this.onTaskStatusChange(e, "COMPLETED"), !0;
165
176
  }
166
177
  return !1;
167
178
  }
@@ -172,7 +183,7 @@ class Lt {
172
183
  await Promise.all(e.map((t) => this.resolveTask(t.id)));
173
184
  }
174
185
  }
175
- const I = new Lt(), R = _((s) => ({
186
+ const N = new Lt(), R = _((s) => ({
176
187
  index: -1,
177
188
  histories: [],
178
189
  addHistory: (e) => s((t) => ({
@@ -194,21 +205,28 @@ const I = new Lt(), R = _((s) => ({
194
205
  function Tt() {
195
206
  return G(() => {
196
207
  const s = async (e) => {
197
- const t = e.state?.id, a = e.state?.index, n = e.state?.status, r = e.state?.params, c = e.state?.transitionName, o = T.getState().setStatus, { index: u, addHistory: l, popHistory: f } = R.getState(), i = a < u, h = n === "PUSHING" && a > u, p = n === "REPLACING" && a > u, g = window.location.pathname;
198
- !i && !h && !p || (await I.addTask(
199
- async () => (i ? o("POPPING") : h ? (o("PUSHING"), l({
200
- id: t,
201
- pathname: g,
202
- params: r,
203
- transitionName: c
204
- })) : p && (o("REPLACING"), l({
205
- id: t,
206
- pathname: g,
207
- params: r,
208
- transitionName: c
209
- })), async () => {
210
- i && f(a + 1), o("COMPLETED");
211
- }),
208
+ const t = e.state?.id;
209
+ (await N.addTask(
210
+ async (a) => {
211
+ const n = e.state?.index, i = e.state?.status, o = e.state?.params, c = e.state?.transitionName, u = T.getState().setStatus, { index: l, addHistory: p, popHistory: f } = R.getState(), r = n < l, g = i === "PUSHING" && n > l, P = i === "REPLACING" && n > l, E = window.location.pathname;
212
+ if (!r && !g && !P) {
213
+ a.abort();
214
+ return;
215
+ }
216
+ return r ? u("POPPING") : g ? (u("PUSHING"), p({
217
+ id: t,
218
+ pathname: E,
219
+ params: o,
220
+ transitionName: c
221
+ })) : P && (u("REPLACING"), p({
222
+ id: t,
223
+ pathname: E,
224
+ params: o,
225
+ transitionName: c
226
+ })), async () => {
227
+ r && f(n + 1), u("COMPLETED");
228
+ };
229
+ },
212
230
  {
213
231
  id: t,
214
232
  control: {
@@ -232,22 +250,22 @@ function Dt(s, e) {
232
250
  return s;
233
251
  }
234
252
  }
235
- function Nt({
253
+ function It({
236
254
  children: s,
237
255
  active: e,
238
256
  params: t
239
257
  }) {
240
258
  const [a, n] = Pt(Dt, t);
241
259
  return G(() => {
242
- const r = async (c) => {
243
- c.state?.step && await I.addTask(async () => {
244
- n({ type: "SET", params: c.state?.params || {} });
260
+ const i = async (o) => {
261
+ o.state?.step && await N.addTask(async () => {
262
+ n({ type: "SET", params: o.state?.params || {} });
245
263
  });
246
264
  };
247
- return e && window.addEventListener("popstate", r), () => {
248
- window.removeEventListener("popstate", r);
265
+ return e && window.addEventListener("popstate", i), () => {
266
+ window.removeEventListener("popstate", i);
249
267
  };
250
- }, [e, n]), /* @__PURE__ */ E(ot.Provider, { value: n, children: /* @__PURE__ */ E(it.Provider, { value: a, children: s }) });
268
+ }, [e, n]), /* @__PURE__ */ w(ot.Provider, { value: n, children: /* @__PURE__ */ w(it.Provider, { value: a, children: s }) });
251
269
  }
252
270
  const ct = X({
253
271
  id: "",
@@ -260,15 +278,15 @@ const ct = X({
260
278
  transitionName: "none",
261
279
  prevTransitionName: "none"
262
280
  });
263
- function It({ children: s }) {
281
+ function Nt({ children: s }) {
264
282
  const e = R((a) => a.index), t = R((a) => a.histories);
265
283
  return t.map(
266
284
  (a) => nt.toArray(s).filter(
267
- (n) => A.pathToRegexp(n.props.path).regexp.test(
285
+ (n) => x.pathToRegexp(n.props.path).regexp.test(
268
286
  a.pathname
269
287
  )
270
288
  )
271
- ).map(([a], n) => /* @__PURE__ */ E(
289
+ ).map(([a], n) => /* @__PURE__ */ w(
272
290
  ct.Provider,
273
291
  {
274
292
  value: {
@@ -282,7 +300,7 @@ function It({ children: s }) {
282
300
  transitionName: t[e].transitionName,
283
301
  prevTransitionName: t[e - 1]?.transitionName
284
302
  },
285
- children: /* @__PURE__ */ E(Nt, { active: n === e, params: t[n].params, children: a })
303
+ children: /* @__PURE__ */ w(It, { active: n === e, params: t[n].params, children: a })
286
304
  },
287
305
  t[n].id
288
306
  ));
@@ -378,9 +396,9 @@ function j({
378
396
  idle: t,
379
397
  enter: a,
380
398
  enterBack: n,
381
- exit: r,
382
- exitBack: c,
383
- options: o
399
+ exit: i,
400
+ exitBack: o,
401
+ options: c
384
402
  }) {
385
403
  return {
386
404
  name: s,
@@ -388,16 +406,16 @@ function j({
388
406
  variants: {
389
407
  "IDLE-true": t,
390
408
  "IDLE-false": t,
391
- "PUSHING-false": r,
409
+ "PUSHING-false": i,
392
410
  "PUSHING-true": a,
393
- "REPLACING-false": r,
411
+ "REPLACING-false": i,
394
412
  "REPLACING-true": a,
395
- "POPPING-false": c,
413
+ "POPPING-false": o,
396
414
  "POPPING-true": n,
397
- "COMPLETED-false": r,
415
+ "COMPLETED-false": i,
398
416
  "COMPLETED-true": a
399
417
  },
400
- ...o
418
+ ...c
401
419
  };
402
420
  }
403
421
  const Mt = j({
@@ -457,29 +475,29 @@ const Mt = j({
457
475
  swipeDirection: "x",
458
476
  onSwipeStart: async () => !0,
459
477
  onSwipe: (s, e, { currentScreen: t, prevScreen: a, onProgress: n }) => {
460
- const { offset: r } = e, c = r.x, o = st(c, [0, window.innerWidth], [0, 100]);
461
- return n?.(!0, o), C(
478
+ const { offset: i } = e, o = i.x, c = st(o, [0, window.innerWidth], [0, 100]);
479
+ return n?.(!0, c), A(
462
480
  t,
463
481
  {
464
- x: Math.max(0, c)
482
+ x: Math.max(0, o)
465
483
  },
466
484
  {
467
485
  duration: 0
468
486
  }
469
- ), C(
487
+ ), A(
470
488
  a,
471
489
  {
472
- x: -100 + o
490
+ x: -100 + c
473
491
  },
474
492
  {
475
493
  duration: 0
476
494
  }
477
- ), o;
495
+ ), c;
478
496
  },
479
497
  onSwipeEnd: async (s, e, { currentScreen: t, prevScreen: a, onStart: n }) => {
480
- const { offset: r, velocity: c } = e, u = r.x > 50 || c.x > 20;
498
+ const { offset: i, velocity: o } = e, u = i.x > 50 || o.x > 20;
481
499
  return n?.(u), await Promise.all([
482
- C(
500
+ A(
483
501
  t,
484
502
  {
485
503
  x: u ? "100%" : 0
@@ -489,7 +507,7 @@ const Mt = j({
489
507
  ease: [0.32, 0.72, 0, 1]
490
508
  }
491
509
  ),
492
- C(
510
+ A(
493
511
  a,
494
512
  {
495
513
  x: u ? 0 : -100
@@ -502,7 +520,7 @@ const Mt = j({
502
520
  ]), u;
503
521
  }
504
522
  }
505
- }), xt = j({
523
+ }), Ct = j({
506
524
  name: "material",
507
525
  initial: {
508
526
  y: "100%",
@@ -564,29 +582,29 @@ const Mt = j({
564
582
  swipeDirection: "y",
565
583
  onSwipeStart: async () => !0,
566
584
  onSwipe: (s, e, { currentScreen: t, prevScreen: a, onProgress: n }) => {
567
- const { offset: r } = e, c = r.y, o = Math.max(0, Math.min(56, c)), u = st(o, [0, 56], [1, 0.96]), l = Math.max(0, c - 56), f = Math.min(1, l / 160), i = Math.sqrt(f) * 12, h = Math.max(0, o + i), p = Math.min(56, h);
568
- return n?.(!0, p), C(
585
+ const { offset: i } = e, o = i.y, c = Math.max(0, Math.min(56, o)), u = st(c, [0, 56], [1, 0.96]), l = Math.max(0, o - 56), p = Math.min(1, l / 160), f = Math.sqrt(p) * 12, r = Math.max(0, c + f), g = Math.min(56, r);
586
+ return n?.(!0, g), A(
569
587
  t,
570
588
  {
571
- y: h,
589
+ y: r,
572
590
  opacity: u
573
591
  },
574
592
  {
575
593
  duration: 0
576
594
  }
577
- ), C(
595
+ ), A(
578
596
  a,
579
597
  {
580
- y: -56 + p,
581
- opacity: p / 56
598
+ y: -56 + g,
599
+ opacity: g / 56
582
600
  },
583
601
  { duration: 0 }
584
- ), p;
602
+ ), g;
585
603
  },
586
604
  onSwipeEnd: async (s, e, { currentScreen: t, prevScreen: a, onStart: n }) => {
587
- const { offset: r, velocity: c } = e, u = r.y > 56 || c.y > 20;
605
+ const { offset: i, velocity: o } = e, u = i.y > 56 || o.y > 20;
588
606
  return n?.(u), await Promise.all([
589
- C(
607
+ A(
590
608
  t,
591
609
  {
592
610
  y: u ? "100%" : 0,
@@ -597,7 +615,7 @@ const Mt = j({
597
615
  ease: u ? [0.4, 0, 1, 1] : [0, 0, 0.2, 1]
598
616
  }
599
617
  ),
600
- C(
618
+ A(
601
619
  a,
602
620
  {
603
621
  y: u ? 0 : -56,
@@ -611,7 +629,7 @@ const Mt = j({
611
629
  ]), u;
612
630
  }
613
631
  }
614
- }), At = j({
632
+ }), xt = j({
615
633
  name: "none",
616
634
  initial: {
617
635
  transition: {
@@ -649,10 +667,10 @@ const Mt = j({
649
667
  }
650
668
  }
651
669
  }), Q = /* @__PURE__ */ new Map([
652
- ["none", At],
670
+ ["none", xt],
653
671
  ["cupertino", Mt],
654
- ["material", xt]
655
- ]), Ct = (() => {
672
+ ["material", Ct]
673
+ ]), At = (() => {
656
674
  const s = /* @__PURE__ */ Object.create(null), e = Object.prototype.hasOwnProperty;
657
675
  for (const t of Q.values()) {
658
676
  const a = t.variants["IDLE-true"].value;
@@ -668,7 +686,7 @@ function Yt({
668
686
  transitions: a = [],
669
687
  decorators: n = []
670
688
  }) {
671
- const r = Z() ? e || "/" : window.location.pathname, c = Z() ? r.split("?")[1] || "" : window.location.search;
689
+ const i = Z() ? e || "/" : window.location.pathname, o = Z() ? i.split("?")[1] || "" : window.location.search;
672
690
  return B.setState({
673
691
  defaultTransitionName: t
674
692
  }), R.setState({
@@ -676,19 +694,19 @@ function Yt({
676
694
  histories: [
677
695
  {
678
696
  id: "root",
679
- pathname: r,
697
+ pathname: i,
680
698
  params: yt(
681
- nt.toArray(s).map((o) => o.props.path).flat(),
682
- r,
683
- c
699
+ nt.toArray(s).map((c) => c.props.path).flat(),
700
+ i,
701
+ o
684
702
  ),
685
703
  transitionName: t
686
704
  }
687
705
  ]
688
706
  }), G(() => {
689
- a.forEach((o) => Q.set(o.name, o));
707
+ a.forEach((c) => Q.set(c.name, c));
690
708
  }, [a]), G(() => {
691
- n.forEach((o) => K.set(o.name, o));
709
+ n.forEach((c) => K.set(c.name, c));
692
710
  }, [n]), /* @__PURE__ */ et(
693
711
  "div",
694
712
  {
@@ -700,8 +718,8 @@ function Yt({
700
718
  height: "100%"
701
719
  },
702
720
  children: [
703
- /* @__PURE__ */ E(Tt, {}),
704
- /* @__PURE__ */ E(It, { children: s })
721
+ /* @__PURE__ */ w(Tt, {}),
722
+ /* @__PURE__ */ w(Nt, { children: s })
705
723
  ]
706
724
  }
707
725
  );
@@ -711,86 +729,86 @@ function Xt({ element: s }) {
711
729
  }
712
730
  function qt() {
713
731
  return {
714
- push: async (a, n, r = {}) => {
715
- const { status: c, setStatus: o } = T.getState();
716
- if (c !== "COMPLETED" && c !== "IDLE")
732
+ push: async (a, n, i = {}) => {
733
+ const { status: o, setStatus: c } = T.getState();
734
+ if (o !== "COMPLETED" && o !== "IDLE")
717
735
  return;
718
- const { index: u, addHistory: l } = R.getState(), f = B.getState().defaultTransitionName, { transitionName: i = f } = r, h = I.generateTaskId();
719
- (await I.addTask(
736
+ const { index: u, addHistory: l } = R.getState(), p = B.getState().defaultTransitionName, { transitionName: f = p } = i, r = N.generateTaskId();
737
+ (await N.addTask(
720
738
  async () => {
721
- o("PUSHING");
722
- const p = A.compile(a)(n), g = A.parse(a).tokens.filter((D) => D.type === "param").map((D) => D.name), m = Object.fromEntries(
723
- Object.entries(n).filter(([D]) => !g.includes(D))
724
- ), w = new URLSearchParams(m).toString(), y = `${p}${w ? `?${w}` : ""}`;
739
+ c("PUSHING");
740
+ const g = x.compile(a)(n), P = x.parse(a).tokens.filter((D) => D.type === "param").map((D) => D.name), E = Object.fromEntries(
741
+ Object.entries(n).filter(([D]) => !P.includes(D))
742
+ ), h = new URLSearchParams(E).toString(), m = `${g}${h ? `?${h}` : ""}`;
725
743
  return window.history.state?.id || window.history.replaceState(
726
744
  {
727
745
  id: "root",
728
746
  index: 0,
729
747
  status: "IDLE",
730
748
  params: {},
731
- transitionName: i
749
+ transitionName: f
732
750
  },
733
751
  "",
734
752
  window.location.pathname
735
753
  ), window.history.pushState(
736
754
  {
737
- id: h,
755
+ id: r,
738
756
  index: u + 1,
739
757
  status: "PUSHING",
740
758
  params: n,
741
- transitionName: i
759
+ transitionName: f
742
760
  },
743
761
  "",
744
- y
762
+ m
745
763
  ), l({
746
- id: h,
747
- pathname: p,
764
+ id: r,
765
+ pathname: g,
748
766
  params: n,
749
- transitionName: i
767
+ transitionName: f
750
768
  }), () => {
751
- o("COMPLETED");
769
+ c("COMPLETED");
752
770
  };
753
771
  },
754
772
  {
755
- id: h,
773
+ id: r,
756
774
  control: {
757
775
  manual: !0
758
776
  }
759
777
  }
760
778
  )).result?.();
761
779
  },
762
- replace: async (a, n, r = {}) => {
763
- const { status: c, setStatus: o } = T.getState();
764
- if (c !== "COMPLETED" && c !== "IDLE")
780
+ replace: async (a, n, i = {}) => {
781
+ const { status: o, setStatus: c } = T.getState();
782
+ if (o !== "COMPLETED" && o !== "IDLE")
765
783
  return;
766
- const { index: u, addHistory: l } = R.getState(), f = R.getState().replaceHistory, i = B.getState().defaultTransitionName, { transitionName: h = i } = r, p = I.generateTaskId();
767
- (await I.addTask(
784
+ const { index: u, addHistory: l } = R.getState(), p = R.getState().replaceHistory, f = B.getState().defaultTransitionName, { transitionName: r = f } = i, g = N.generateTaskId();
785
+ (await N.addTask(
768
786
  async () => {
769
- o("REPLACING");
770
- const g = A.compile(a)(n), m = A.parse(a).tokens.filter((L) => L.type === "param").map((L) => L.name), w = Object.fromEntries(
771
- Object.entries(n).filter(([L]) => !m.includes(L))
772
- ), y = new URLSearchParams(w).toString(), D = `${g}${y ? `?${y}` : ""}`;
787
+ c("REPLACING");
788
+ const P = x.compile(a)(n), E = x.parse(a).tokens.filter((L) => L.type === "param").map((L) => L.name), h = Object.fromEntries(
789
+ Object.entries(n).filter(([L]) => !E.includes(L))
790
+ ), m = new URLSearchParams(h).toString(), D = `${P}${m ? `?${m}` : ""}`;
773
791
  return window.history.replaceState(
774
792
  {
775
- id: p,
793
+ id: g,
776
794
  index: u,
777
795
  status: "REPLACING",
778
796
  params: n,
779
- transitionName: h
797
+ transitionName: r
780
798
  },
781
799
  "",
782
800
  D
783
801
  ), l({
784
- id: p,
785
- pathname: g,
802
+ id: g,
803
+ pathname: P,
786
804
  params: n,
787
- transitionName: h
805
+ transitionName: r
788
806
  }), async () => {
789
- f(u), o("COMPLETED");
807
+ p(u), c("COMPLETED");
790
808
  };
791
809
  },
792
810
  {
793
- id: p,
811
+ id: g,
794
812
  control: {
795
813
  manual: !0
796
814
  }
@@ -807,9 +825,9 @@ function Kt() {
807
825
  const s = q(ot);
808
826
  return {
809
827
  pushStep: async (n) => {
810
- const r = T.getState().status;
811
- r !== "COMPLETED" && r !== "IDLE" || (await I.addTask(async () => {
812
- const c = new URLSearchParams(n).toString(), o = `${window.location.pathname}${c ? `?${c}` : ""}`;
828
+ const i = T.getState().status;
829
+ i !== "COMPLETED" && i !== "IDLE" || (await N.addTask(async () => {
830
+ const o = new URLSearchParams(n).toString(), c = `${window.location.pathname}${o ? `?${o}` : ""}`;
813
831
  return window.history.state?.step || window.history.replaceState(
814
832
  {
815
833
  ...window.history.state,
@@ -824,14 +842,14 @@ function Kt() {
824
842
  params: n
825
843
  },
826
844
  "",
827
- o
845
+ c
828
846
  ), async () => s({ type: "SET", params: n });
829
847
  })).result?.();
830
848
  },
831
849
  replaceStep: async (n) => {
832
- const r = T.getState().status;
833
- r !== "COMPLETED" && r !== "IDLE" || (await I.addTask(async () => {
834
- const c = new URLSearchParams(n).toString(), o = `${window.location.pathname}${c ? `?${c}` : ""}`;
850
+ const i = T.getState().status;
851
+ i !== "COMPLETED" && i !== "IDLE" || (await N.addTask(async () => {
852
+ const o = new URLSearchParams(n).toString(), c = `${window.location.pathname}${o ? `?${o}` : ""}`;
835
853
  return window.history.replaceState(
836
854
  {
837
855
  ...window.history.state,
@@ -839,7 +857,7 @@ function Kt() {
839
857
  params: n
840
858
  },
841
859
  "",
842
- o
860
+ c
843
861
  ), async () => s({ type: "SET", params: n });
844
862
  })).result?.();
845
863
  },
@@ -861,13 +879,13 @@ function Vt({
861
879
  idle: t,
862
880
  pushOnEnter: a,
863
881
  pushOnExit: n,
864
- replaceOnEnter: r,
865
- replaceOnExit: c,
866
- popOnEnter: o,
882
+ replaceOnEnter: i,
883
+ replaceOnExit: o,
884
+ popOnEnter: c,
867
885
  popOnExit: u,
868
886
  completedOnExit: l,
869
- completedOnEnter: f,
870
- options: i
887
+ completedOnEnter: p,
888
+ options: f
871
889
  }) {
872
890
  return {
873
891
  name: s,
@@ -877,14 +895,14 @@ function Vt({
877
895
  "IDLE-false": t,
878
896
  "PUSHING-false": n,
879
897
  "PUSHING-true": a,
880
- "REPLACING-false": c,
881
- "REPLACING-true": r,
898
+ "REPLACING-false": o,
899
+ "REPLACING-true": i,
882
900
  "POPPING-false": u,
883
- "POPPING-true": o,
901
+ "POPPING-true": c,
884
902
  "COMPLETED-false": l,
885
- "COMPLETED-true": f
903
+ "COMPLETED-true": p
886
904
  },
887
- ...i
905
+ ...f
888
906
  };
889
907
  }
890
908
  function Wt({
@@ -893,13 +911,13 @@ function Wt({
893
911
  idle: t,
894
912
  pushOnEnter: a,
895
913
  pushOnExit: n,
896
- replaceOnEnter: r,
897
- replaceOnExit: c,
898
- popOnEnter: o,
914
+ replaceOnEnter: i,
915
+ replaceOnExit: o,
916
+ popOnEnter: c,
899
917
  popOnExit: u,
900
918
  completedOnEnter: l,
901
- completedOnExit: f,
902
- options: i
919
+ completedOnExit: p,
920
+ options: f
903
921
  }) {
904
922
  return {
905
923
  name: s,
@@ -909,14 +927,14 @@ function Wt({
909
927
  "IDLE-false": t,
910
928
  "PUSHING-false": n,
911
929
  "PUSHING-true": a,
912
- "REPLACING-false": c,
913
- "REPLACING-true": r,
930
+ "REPLACING-false": o,
931
+ "REPLACING-true": i,
914
932
  "POPPING-false": u,
915
- "POPPING-true": o,
916
- "COMPLETED-false": f,
933
+ "POPPING-true": c,
934
+ "COMPLETED-false": p,
917
935
  "COMPLETED-true": l
918
936
  },
919
- ...i
937
+ ...f
920
938
  };
921
939
  }
922
940
  const Rt = { then() {
@@ -929,29 +947,29 @@ function Gt({
929
947
  throw Rt;
930
948
  return e;
931
949
  }
932
- function Ot({ freeze: s, children: e, placeholder: t }) {
933
- return /* @__PURE__ */ E(Et, { fallback: t, children: /* @__PURE__ */ E(Gt, { freeze: s, children: e }) });
950
+ function bt({ freeze: s, children: e, placeholder: t }) {
951
+ return /* @__PURE__ */ w(Et, { fallback: t, children: /* @__PURE__ */ w(Gt, { freeze: s, children: e }) });
934
952
  }
935
953
  function z(s, e) {
936
954
  const {
937
955
  direction: t = "x",
938
956
  markerSelector: a = "[data-swipe-at-edge]",
939
957
  depthLimit: n = 24,
940
- verifyByScroll: r = !1
941
- } = e ?? {}, c = bt(s);
942
- if (!c) return { element: null, hasMarker: !1 };
943
- const o = c.closest?.(a);
944
- if (o instanceof HTMLElement && Y(o, t) && (!r || tt(o, t)))
945
- return { element: o, hasMarker: !0 };
946
- let u = c, l = 0;
958
+ verifyByScroll: i = !1
959
+ } = e ?? {}, o = Ot(s);
960
+ if (!o) return { element: null, hasMarker: !1 };
961
+ const c = o.closest?.(a);
962
+ if (c instanceof HTMLElement && Y(c, t) && (!i || tt(c, t)))
963
+ return { element: c, hasMarker: !0 };
964
+ let u = o, l = 0;
947
965
  for (; u && u !== document.body && l < n; ) {
948
- if (Y(u, t) && (!r || tt(u, t)))
966
+ if (Y(u, t) && (!i || tt(u, t)))
949
967
  return { element: u, hasMarker: !1 };
950
968
  u = u.parentElement, l++;
951
969
  }
952
970
  return { element: null, hasMarker: !1 };
953
971
  }
954
- function bt(s) {
972
+ function Ot(s) {
955
973
  if (!s) return null;
956
974
  const e = s, t = typeof e.composedPath == "function" ? e.composedPath() : void 0;
957
975
  if (t && t.length) {
@@ -982,18 +1000,18 @@ function tt(s, e) {
982
1000
  }
983
1001
  }
984
1002
  function Ht({ children: s, ref: e, ...t }) {
985
- const { isActive: a, transitionName: n } = V(), [r, c] = at();
986
- St(e, () => r.current);
987
- const o = T((h) => h.status), u = Q.get(n), { decoratorName: l } = u, { initial: f, variants: i } = K.get(l);
1003
+ const { isActive: a, transitionName: n } = V(), [i, o] = at();
1004
+ St(e, () => i.current);
1005
+ const c = T((r) => r.status), u = Q.get(n), { decoratorName: l } = u, { initial: p, variants: f } = K.get(l);
988
1006
  return G(() => {
989
- if (!r.current) return;
990
- const { value: h, options: p } = i[`${o}-${a}`];
991
- c(r.current, h, p);
992
- }, [o, a, c, i, r]), /* @__PURE__ */ E(
1007
+ if (!i.current) return;
1008
+ const { value: r, options: g } = f[`${c}-${a}`];
1009
+ o(i.current, r, g);
1010
+ }, [c, a, o, f, i]), /* @__PURE__ */ w(
993
1011
  rt.div,
994
1012
  {
995
- ref: r,
996
- initial: f,
1013
+ ref: i,
1014
+ initial: p,
997
1015
  style: {
998
1016
  position: "absolute",
999
1017
  top: 0,
@@ -1007,7 +1025,7 @@ function Ht({ children: s, ref: e, ...t }) {
1007
1025
  }
1008
1026
  );
1009
1027
  }
1010
- const b = _((s) => ({
1028
+ const O = _((s) => ({
1011
1029
  dragStatus: "IDLE",
1012
1030
  replaceTransitionStatus: "IDLE",
1013
1031
  setDragStatus: (e) => s({ dragStatus: e }),
@@ -1017,46 +1035,46 @@ function Ut({
1017
1035
  children: s,
1018
1036
  ...e
1019
1037
  }) {
1020
- const [t, a] = at(), { id: n, isActive: r, isRoot: c, transitionName: o, prevTransitionName: u } = V(), l = wt(), f = T((d) => d.status), i = b((d) => d.dragStatus), h = b.getState().setDragStatus, p = b.getState().setReplaceTransitionStatus, g = Q.get(o), { variants: m, initial: w, swipeDirection: y, decoratorName: D } = g, L = K.get(D), H = N(null), U = N(null), $ = N(null), k = N(!1), O = N(!1), v = N({
1038
+ const [t, a] = at(), { id: n, isActive: i, isRoot: o, transitionName: c, prevTransitionName: u } = V(), l = wt(), p = T((d) => d.status), f = O((d) => d.dragStatus), r = O.getState().setDragStatus, g = O.getState().setReplaceTransitionStatus, P = Q.get(c), { variants: E, initial: h, swipeDirection: m, decoratorName: D } = P, L = K.get(D), H = I(null), U = I(null), $ = I(null), k = I(!1), b = I(!1), v = I({
1021
1039
  element: null,
1022
1040
  hasMarker: !1
1023
- }), M = N({ element: null, hasMarker: !1 }), W = N(0), J = N(0), ut = async (d, S) => {
1024
- if (!y)
1041
+ }), M = I({ element: null, hasMarker: !1 }), W = I(0), J = I(0), ut = async (d, y) => {
1042
+ if (!m)
1025
1043
  return;
1026
1044
  H.current = t.current?.previousSibling, $.current = t.current?.previousSibling?.querySelector("[data-decorator]");
1027
- const P = await g?.onSwipeStart(d, S, {
1045
+ const S = await P?.onSwipeStart(d, y, {
1028
1046
  currentScreen: t.current,
1029
1047
  prevScreen: H.current,
1030
1048
  dragControls: l,
1031
- onStart: (x) => L?.onSwipeStart?.(x, {
1049
+ onStart: (C) => L?.onSwipeStart?.(C, {
1032
1050
  currentDecorator: U.current,
1033
1051
  prevDecorator: $.current
1034
1052
  })
1035
1053
  });
1036
- h(P ? "PENDING" : "IDLE");
1037
- }, lt = (d, S) => {
1038
- !y || i !== "PENDING" || g?.onSwipe(d, S, {
1054
+ r(S ? "PENDING" : "IDLE");
1055
+ }, lt = (d, y) => {
1056
+ !m || f !== "PENDING" || P?.onSwipe(d, y, {
1039
1057
  currentScreen: t.current,
1040
1058
  prevScreen: H.current,
1041
1059
  dragControls: l,
1042
- onProgress: (P, x) => L?.onSwipe?.(P, x, {
1060
+ onProgress: (S, C) => L?.onSwipe?.(S, C, {
1043
1061
  currentDecorator: U.current,
1044
1062
  prevDecorator: $.current
1045
1063
  })
1046
1064
  });
1047
- }, dt = async (d, S) => {
1048
- if (!y || i !== "PENDING")
1065
+ }, dt = async (d, y) => {
1066
+ if (!m || f !== "PENDING")
1049
1067
  return;
1050
- await g?.onSwipeEnd(d, S, {
1068
+ await P?.onSwipeEnd(d, y, {
1051
1069
  currentScreen: t.current,
1052
1070
  prevScreen: H.current,
1053
- onStart: (x) => L?.onSwipeEnd?.(x, {
1071
+ onStart: (C) => L?.onSwipeEnd?.(C, {
1054
1072
  currentDecorator: U.current,
1055
1073
  prevDecorator: $.current
1056
1074
  })
1057
- }) ? window.history.back() : h("IDLE");
1075
+ }) ? window.history.back() : r("IDLE");
1058
1076
  }, pt = (d) => {
1059
- if (!(!c && r && f === "COMPLETED" && i === "IDLE" && !!y))
1077
+ if (!(!o && i && p === "COMPLETED" && f === "IDLE" && !!m))
1060
1078
  return;
1061
1079
  v.current = z(d.target, {
1062
1080
  direction: "x"
@@ -1064,52 +1082,52 @@ function Ut({
1064
1082
  direction: "y"
1065
1083
  }), W.current = d.clientX, J.current = d.clientY, (!v.current.element && !M.current.element || v.current.element || M.current.element) && (k.current = !0);
1066
1084
  }, ft = (d) => {
1067
- const S = !v.current.element && !M.current.element;
1068
- if (k.current && S)
1069
- k.current = !1, O.current = !0, l.start(d);
1070
- else if (k.current && !S) {
1071
- const P = d.clientX - W.current, x = d.clientY - J.current, mt = M.current.element && M.current.element.scrollTop <= 0 && M.current.hasMarker, gt = v.current.element && v.current.element.scrollLeft <= 0 && v.current.hasMarker;
1072
- (y === "y" && (mt || v.current.element) && x > 0 && Math.abs(P) < 4 || y === "x" && (gt || M.current.element) && P > 0 && Math.abs(x) < 4) && (k.current = !1, O.current = !0, l.start(d));
1085
+ const y = !v.current.element && !M.current.element;
1086
+ if (k.current && y)
1087
+ k.current = !1, b.current = !0, l.start(d);
1088
+ else if (k.current && !y) {
1089
+ const S = d.clientX - W.current, C = d.clientY - J.current, gt = M.current.element && M.current.element.scrollTop <= 0 && M.current.hasMarker, mt = v.current.element && v.current.element.scrollLeft <= 0 && v.current.hasMarker;
1090
+ (m === "y" && (gt || v.current.element) && C > 0 && Math.abs(S) < 4 || m === "x" && (mt || M.current.element) && S > 0 && Math.abs(C) < 4) && (k.current = !1, b.current = !0, l.start(d));
1073
1091
  }
1074
1092
  }, ht = () => {
1075
- k.current = !1, O.current = !1;
1093
+ k.current = !1, b.current = !1;
1076
1094
  };
1077
1095
  return G(() => {
1078
1096
  const d = t.current;
1079
1097
  if (!d) return;
1080
- const S = (P) => {
1081
- O.current && P.preventDefault(), P.target?.dataset.swipeAtEdgeBar === "true" && P.preventDefault();
1098
+ const y = (S) => {
1099
+ b.current && S.preventDefault(), S.target?.dataset.swipeAtEdgeBar === "true" && S.preventDefault();
1082
1100
  };
1083
- return d.addEventListener("touchmove", S, {
1101
+ return d.addEventListener("touchmove", y, {
1084
1102
  passive: !1
1085
1103
  }), () => {
1086
- d.removeEventListener("touchmove", S);
1104
+ d.removeEventListener("touchmove", y);
1087
1105
  };
1088
1106
  }, [t]), G(() => {
1089
1107
  t.current && (async () => {
1090
- const { value: d, options: S } = m[`${f}-${r}`], P = u !== o;
1091
- !r && f === "REPLACING" && P && (p("PENDING"), await a(t.current, Ct, {
1108
+ const { value: d, options: y } = E[`${p}-${i}`], S = u !== c;
1109
+ !i && p === "REPLACING" && S && (g("PENDING"), await a(t.current, At, {
1092
1110
  duration: 0.1
1093
- })), await a(t.current, d, S), await I.resolveTask(n), !r && P && p("IDLE"), r && f === "COMPLETED" && h("IDLE");
1111
+ })), await a(t.current, d, y), await N.resolveTask(n), !i && S && g("IDLE"), i && p === "COMPLETED" && r("IDLE");
1094
1112
  })();
1095
1113
  }, [
1096
- f,
1097
- r,
1114
+ p,
1115
+ i,
1098
1116
  n,
1099
1117
  u,
1100
- o,
1118
+ c,
1101
1119
  a,
1102
1120
  t,
1103
- m,
1104
- h,
1105
- p
1121
+ E,
1122
+ r,
1123
+ g
1106
1124
  ]), /* @__PURE__ */ et(
1107
1125
  rt.div,
1108
1126
  {
1109
1127
  ref: t,
1110
1128
  ...e,
1111
- initial: w,
1112
- drag: y,
1129
+ initial: h,
1130
+ drag: m,
1113
1131
  dragListener: !1,
1114
1132
  dragControls: l,
1115
1133
  onDragStart: ut,
@@ -1135,7 +1153,7 @@ function Ut({
1135
1153
  ...e.style
1136
1154
  },
1137
1155
  children: [
1138
- /* @__PURE__ */ E(
1156
+ /* @__PURE__ */ w(
1139
1157
  "div",
1140
1158
  {
1141
1159
  "data-swipe-at-edge-bar": !0,
@@ -1149,7 +1167,7 @@ function Ut({
1149
1167
  }
1150
1168
  }
1151
1169
  ),
1152
- /* @__PURE__ */ E(
1170
+ /* @__PURE__ */ w(
1153
1171
  "div",
1154
1172
  {
1155
1173
  style: {
@@ -1162,8 +1180,8 @@ function Ut({
1162
1180
  children: s
1163
1181
  }
1164
1182
  ),
1165
- L && /* @__PURE__ */ E(Ht, { ref: U }),
1166
- /* @__PURE__ */ E(
1183
+ L && /* @__PURE__ */ w(Ht, { ref: U }),
1184
+ /* @__PURE__ */ w(
1167
1185
  "div",
1168
1186
  {
1169
1187
  "data-swipe-at-edge-bar": !0,
@@ -1185,8 +1203,8 @@ function Jt({
1185
1203
  children: s,
1186
1204
  ...e
1187
1205
  }) {
1188
- const { isActive: t, isPrev: a } = V(), n = T((l) => l.status), r = b((l) => l.dragStatus), c = b((l) => l.replaceTransitionStatus);
1189
- return /* @__PURE__ */ E(Ot, { freeze: !t && (n === "COMPLETED" && r === "IDLE" && c === "IDLE" || a && c === "IDLE"), children: /* @__PURE__ */ E(Ut, { ...e, children: s }) });
1206
+ const { isActive: t, isPrev: a } = V(), n = T((l) => l.status), i = O((l) => l.dragStatus), o = O((l) => l.replaceTransitionStatus);
1207
+ return /* @__PURE__ */ w(bt, { freeze: !t && (n === "COMPLETED" && i === "IDLE" && o === "IDLE" || a && o === "IDLE"), children: /* @__PURE__ */ w(Ut, { ...e, children: s }) });
1190
1208
  }
1191
1209
  export {
1192
1210
  Xt as Route,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flemo",
3
- "version": "1.1.3",
3
+ "version": "1.1.4",
4
4
  "description": "A modern React router library with built-in motion animations and smooth transitions",
5
5
  "main": "./dist/index.mjs",
6
6
  "module": "./dist/index.mjs",