vue-micro-router 1.0.33 → 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,27 +1,44 @@
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, u = {}) {
9
+ async play(o, u = {}) {
10
10
  if (this.stop(), !this.HowlCtor) {
11
- const l = await import("howler");
12
- this.HowlCtor = l.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: u.loop ?? !1,
18
- volume: 0
19
- }), this.sound.play(), this.sound.fade(0, u.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, u = {}) {
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
43
  loop: u.loop ?? !1,
27
44
  volume: 0
@@ -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, u, l) {
61
+ fade(o, u, i) {
45
62
  var e;
46
- (e = this.sound) != null && e.playing() && this.sound.fade(s, u, l);
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";
@@ -65,9 +82,9 @@ function B(t) {
65
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
89
  function x(t) {
73
90
  try {
@@ -86,49 +103,49 @@ async function M(t) {
86
103
  }
87
104
  }
88
105
  function R(t) {
89
- let s = !1;
106
+ let o = !1;
90
107
  const u = (t == null ? void 0 : t.defaultBgm) ?? "";
91
- let l = "";
92
- const e = (t == null ? void 0 : t.adapter) ?? new C(), n = S(""), d = H(() => {
93
- var o;
94
- return (((o = t == null ? void 0 : t.volumeRef) == null ? void 0 : o.value) || 0) / 100;
108
+ let i = "";
109
+ const e = (t == null ? void 0 : t.adapter) ?? new H(), n = S(""), d = g(() => {
110
+ var a;
111
+ return (((a = t == null ? void 0 : t.volumeRef) == null ? void 0 : a.value) || 0) / 100;
95
112
  });
96
- async function c(o, r = !1) {
113
+ async function r(a, l = !1) {
97
114
  try {
98
- const a = o === "default" ? u : o;
99
- if (!a || e.isPlaying() && n.value === a) return;
100
- l = n.value, n.value = a, e.stop(), await e.play(a, { loop: o === "default" ? !0 : r, volume: d.value });
101
- } catch (a) {
102
- console.error("Sound playback failed:", a), 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();
103
120
  }
104
121
  }
105
- function p(o, r = !1) {
122
+ function c(a, l = !1) {
106
123
  try {
107
- const a = o === "default" ? u : o;
108
- if (!a || e.isPlaying() && n.value === a) return;
109
- l = n.value, n.value = a, e.stop();
110
- const i = o === "default" ? !0 : r;
111
- e.playSync ? e.playSync(a, { loop: i, volume: d.value }) : e.play(a, { loop: i, volume: d.value });
112
- } catch (a) {
113
- console.error("Sound playback failed:", a), 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();
114
131
  }
115
132
  }
116
133
  function h() {
117
134
  e.stop();
118
135
  }
119
- async function y(o, r) {
120
- if (r)
136
+ async function y(a, l) {
137
+ if (l)
121
138
  try {
122
- const a = b(o) || "home", i = r.get(a), f = (i == null ? void 0 : i.bgm) || u;
123
- f && l !== f && await c(f, !0);
124
- } catch (a) {
125
- console.error("Error updating background music:", a);
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);
126
143
  }
127
144
  }
128
145
  function m() {
129
146
  if (!(typeof document > "u"))
130
147
  try {
131
- 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);
132
149
  } catch {
133
150
  e.stop();
134
151
  }
@@ -136,11 +153,11 @@ function R(t) {
136
153
  function v() {
137
154
  e.cleanup();
138
155
  }
139
- return g(d, (o, r) => {
140
- e.isPlaying() ? e.fade(r ?? 0, o, 300) : o > 0 && n.value && c(n.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);
141
158
  }), {
142
- playSound: c,
143
- playSoundSync: p,
159
+ playSound: r,
160
+ playSoundSync: c,
144
161
  stopSound: h,
145
162
  updateBackgroundMusic: y,
146
163
  isStarted: () => e.isPlaying() || e.state() === "loaded",
@@ -149,9 +166,9 @@ function R(t) {
149
166
  };
150
167
  }
151
168
  export {
152
- C as H,
169
+ H,
153
170
  L as b,
154
- b as g,
171
+ P as g,
155
172
  A as i,
156
173
  k as n,
157
174
  B as p,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vue-micro-router",
3
- "version": "1.0.33",
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": {