vue-micro-router 1.0.31 → 1.0.34

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,31 +1,48 @@
1
- import { markRaw as w, ref as S, computed as H, watch as g } from "vue";
2
- class C {
1
+ import { markRaw as w, ref as S, computed as g, watch as C } from "vue";
2
+ class H {
3
3
  constructor() {
4
- this.sound = null, this.HowlCtor = null, import("howler").then((s) => {
5
- this.HowlCtor = s.Howl;
4
+ this.sound = null, this.HowlCtor = null, import("howler").then((o) => {
5
+ this.HowlCtor = o.Howl;
6
6
  }).catch(() => {
7
7
  });
8
8
  }
9
- async play(s, n = {}) {
9
+ async play(o, u = {}) {
10
10
  if (this.stop(), !this.HowlCtor) {
11
- const i = await import("howler");
12
- this.HowlCtor = i.Howl;
11
+ const n = await import("howler");
12
+ this.HowlCtor = n.Howl;
13
13
  }
14
- this.sound = new this.HowlCtor({
15
- src: [s],
16
- autoplay: !0,
17
- loop: n.loop ?? !1,
18
- volume: 0
19
- }), this.sound.play(), this.sound.fade(0, n.volume ?? 1, 200);
14
+ const i = this.HowlCtor, e = u.volume ?? 1;
15
+ return new Promise((n, d) => {
16
+ this.sound = new i({
17
+ src: [o],
18
+ autoplay: !1,
19
+ loop: u.loop ?? !1,
20
+ volume: 0,
21
+ onplay: () => {
22
+ var r;
23
+ (r = this.sound) == null || r.fade(0, e, 200), n();
24
+ },
25
+ onloaderror: (r, c) => {
26
+ d(new Error(`Failed to load audio: ${c}`));
27
+ },
28
+ onplayerror: () => {
29
+ var r;
30
+ (r = this.sound) == null || r.once("unlock", () => {
31
+ var c;
32
+ (c = this.sound) == null || c.play();
33
+ }), n();
34
+ }
35
+ }), this.sound.play();
36
+ });
20
37
  }
21
38
  /** Fully synchronous play — uses preloaded HowlCtor. No-op if not preloaded yet. */
22
- playSync(s, n = {}) {
39
+ playSync(o, u = {}) {
23
40
  this.HowlCtor && (this.stop(), this.sound = new this.HowlCtor({
24
- src: [s],
41
+ src: [o],
25
42
  autoplay: !0,
26
- loop: n.loop ?? !1,
43
+ loop: u.loop ?? !1,
27
44
  volume: 0
28
- }), this.sound.play(), this.sound.fade(0, n.volume ?? 1, 200));
45
+ }), this.sound.play(), this.sound.fade(0, u.volume ?? 1, 200));
29
46
  }
30
47
  stop() {
31
48
  try {
@@ -35,19 +52,19 @@ class C {
35
52
  }
36
53
  }
37
54
  pause() {
38
- var s;
39
- (s = this.sound) != null && s.playing() && this.sound.pause();
55
+ var o;
56
+ (o = this.sound) != null && o.playing() && this.sound.pause();
40
57
  }
41
58
  resume() {
42
59
  this.sound && this.state() === "loaded" && this.sound.play();
43
60
  }
44
- fade(s, n, i) {
61
+ fade(o, u, i) {
45
62
  var e;
46
- (e = this.sound) != null && e.playing() && this.sound.fade(s, n, i);
63
+ (e = this.sound) != null && e.playing() && this.sound.fade(o, u, i);
47
64
  }
48
65
  isPlaying() {
49
- var s;
50
- return ((s = this.sound) == null ? void 0 : s.playing()) ?? !1;
66
+ var o;
67
+ return ((o = this.sound) == null ? void 0 : o.playing()) ?? !1;
51
68
  }
52
69
  state() {
53
70
  return this.sound ? this.sound.state() : "unloaded";
@@ -62,21 +79,21 @@ function k(t) {
62
79
  function B(t) {
63
80
  return t.split("/").filter(Boolean);
64
81
  }
65
- function x(t) {
82
+ function L(t) {
66
83
  return `/${t.join("/")}`;
67
84
  }
68
- function b(t) {
69
- const s = t.lastIndexOf("/");
70
- return s === -1 ? t : t.substring(s + 1);
85
+ function P(t) {
86
+ const o = t.lastIndexOf("/");
87
+ return o === -1 ? t : t.substring(o + 1);
71
88
  }
72
- function A(t) {
89
+ function x(t) {
73
90
  try {
74
91
  return w(t);
75
92
  } catch {
76
93
  return t;
77
94
  }
78
95
  }
79
- function L(t) {
96
+ function A(t) {
80
97
  return typeof t == "function" && !("__name" in t) && !("setup" in t) && !("render" in t);
81
98
  }
82
99
  async function M(t) {
@@ -86,45 +103,49 @@ async function M(t) {
86
103
  }
87
104
  }
88
105
  function R(t) {
89
- let s = !1;
90
- const n = (t == null ? void 0 : t.defaultBgm) ?? "";
106
+ let o = !1;
107
+ const u = (t == null ? void 0 : t.defaultBgm) ?? "";
91
108
  let i = "";
92
- const e = (t == null ? void 0 : t.adapter) ?? new C(), o = S(""), r = H(() => {
109
+ const e = (t == null ? void 0 : t.adapter) ?? new H(), n = S(""), d = g(() => {
93
110
  var a;
94
111
  return (((a = t == null ? void 0 : t.volumeRef) == null ? void 0 : a.value) || 0) / 100;
95
112
  });
96
- async function d(a, u = !1) {
113
+ async function r(a, l = !1) {
97
114
  try {
98
- if (e.isPlaying() && o.value === a) return;
99
- i = o.value, o.value = a, e.stop(), await e.play(a, { loop: u, volume: r.value });
100
- } catch (l) {
101
- console.error("Sound playback failed:", l), e.stop();
115
+ const s = a === "default" ? u : a;
116
+ if (!s || e.isPlaying() && n.value === s) return;
117
+ i = n.value, n.value = s, e.stop(), await e.play(s, { loop: a === "default" ? !0 : l, volume: d.value });
118
+ } catch (s) {
119
+ console.error("Sound playback failed:", s), e.stop();
102
120
  }
103
121
  }
104
- function f(a, u = !1) {
122
+ function c(a, l = !1) {
105
123
  try {
106
- if (e.isPlaying() && o.value === a) return;
107
- i = o.value, o.value = a, e.stop(), e.playSync ? e.playSync(a, { loop: u, volume: r.value }) : e.play(a, { loop: u, volume: r.value });
108
- } catch (l) {
109
- console.error("Sound playback failed:", l), e.stop();
124
+ const s = a === "default" ? u : a;
125
+ if (!s || e.isPlaying() && n.value === s) return;
126
+ i = n.value, n.value = s, e.stop();
127
+ const p = a === "default" ? !0 : l;
128
+ e.playSync ? e.playSync(s, { loop: p, volume: d.value }) : e.play(s, { loop: p, volume: d.value });
129
+ } catch (s) {
130
+ console.error("Sound playback failed:", s), e.stop();
110
131
  }
111
132
  }
112
- function p() {
133
+ function h() {
113
134
  e.stop();
114
135
  }
115
- async function y(a, u) {
116
- if (u)
136
+ async function y(a, l) {
137
+ if (l)
117
138
  try {
118
- const l = b(a) || "home", c = u.get(l), h = (c == null ? void 0 : c.bgm) || n;
119
- h && i !== h && await d(h, !0);
120
- } catch (l) {
121
- console.error("Error updating background music:", l);
139
+ const s = P(a) || "home", p = l.get(s), f = (p == null ? void 0 : p.bgm) || u;
140
+ f && i !== f && await r(f, !0);
141
+ } catch (s) {
142
+ console.error("Error updating background music:", s);
122
143
  }
123
144
  }
124
145
  function m() {
125
146
  if (!(typeof document > "u"))
126
147
  try {
127
- document.hidden ? e.isPlaying() && (e.pause(), s = !0) : s && e.state() === "loaded" && (e.resume(), s = !1);
148
+ document.hidden ? e.isPlaying() && (e.pause(), o = !0) : o && e.state() === "loaded" && (e.resume(), o = !1);
128
149
  } catch {
129
150
  e.stop();
130
151
  }
@@ -132,12 +153,12 @@ function R(t) {
132
153
  function v() {
133
154
  e.cleanup();
134
155
  }
135
- return g(r, (a, u) => {
136
- e.isPlaying() ? e.fade(u ?? 0, a, 300) : a > 0 && o.value && d(o.value, !0);
156
+ return C(d, (a, l) => {
157
+ e.isPlaying() ? e.fade(l ?? 0, a, 300) : a > 0 && n.value && r(n.value, !0);
137
158
  }), {
138
- playSound: d,
139
- playSoundSync: f,
140
- stopSound: p,
159
+ playSound: r,
160
+ playSoundSync: c,
161
+ stopSound: h,
141
162
  updateBackgroundMusic: y,
142
163
  isStarted: () => e.isPlaying() || e.state() === "loaded",
143
164
  handleVisibilityChange: m,
@@ -145,13 +166,13 @@ function R(t) {
145
166
  };
146
167
  }
147
168
  export {
148
- C as H,
149
- x as b,
150
- b as g,
151
- L as i,
169
+ H,
170
+ L as b,
171
+ P as g,
172
+ A as i,
152
173
  k as n,
153
174
  B as p,
154
- A as s,
175
+ x as s,
155
176
  R as u,
156
177
  M as w
157
178
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vue-micro-router",
3
- "version": "1.0.31",
3
+ "version": "1.0.34",
4
4
  "type": "module",
5
5
  "description": "Mobile-app-style navigation for Vue 3 — animated page stacks, modal dialogs, HUD controls. No URL routing.",
6
6
  "author": {