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.
- package/dist/use-audio-manager.mjs +81 -60
- package/package.json +1 -1
|
@@ -1,31 +1,48 @@
|
|
|
1
|
-
import { markRaw as w, ref as S, computed as
|
|
2
|
-
class
|
|
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((
|
|
5
|
-
this.HowlCtor =
|
|
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(
|
|
9
|
+
async play(o, u = {}) {
|
|
10
10
|
if (this.stop(), !this.HowlCtor) {
|
|
11
|
-
const
|
|
12
|
-
this.HowlCtor =
|
|
11
|
+
const n = await import("howler");
|
|
12
|
+
this.HowlCtor = n.Howl;
|
|
13
13
|
}
|
|
14
|
-
this.
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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(
|
|
39
|
+
playSync(o, u = {}) {
|
|
23
40
|
this.HowlCtor && (this.stop(), this.sound = new this.HowlCtor({
|
|
24
|
-
src: [
|
|
41
|
+
src: [o],
|
|
25
42
|
autoplay: !0,
|
|
26
|
-
loop:
|
|
43
|
+
loop: u.loop ?? !1,
|
|
27
44
|
volume: 0
|
|
28
|
-
}), this.sound.play(), this.sound.fade(0,
|
|
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
|
|
39
|
-
(
|
|
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(
|
|
61
|
+
fade(o, u, i) {
|
|
45
62
|
var e;
|
|
46
|
-
(e = this.sound) != null && e.playing() && this.sound.fade(
|
|
63
|
+
(e = this.sound) != null && e.playing() && this.sound.fade(o, u, i);
|
|
47
64
|
}
|
|
48
65
|
isPlaying() {
|
|
49
|
-
var
|
|
50
|
-
return ((
|
|
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
|
|
82
|
+
function L(t) {
|
|
66
83
|
return `/${t.join("/")}`;
|
|
67
84
|
}
|
|
68
|
-
function
|
|
69
|
-
const
|
|
70
|
-
return
|
|
85
|
+
function P(t) {
|
|
86
|
+
const o = t.lastIndexOf("/");
|
|
87
|
+
return o === -1 ? t : t.substring(o + 1);
|
|
71
88
|
}
|
|
72
|
-
function
|
|
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
|
|
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
|
|
90
|
-
const
|
|
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
|
|
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
|
|
113
|
+
async function r(a, l = !1) {
|
|
97
114
|
try {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
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
|
|
122
|
+
function c(a, l = !1) {
|
|
105
123
|
try {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
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
|
|
133
|
+
function h() {
|
|
113
134
|
e.stop();
|
|
114
135
|
}
|
|
115
|
-
async function y(a,
|
|
116
|
-
if (
|
|
136
|
+
async function y(a, l) {
|
|
137
|
+
if (l)
|
|
117
138
|
try {
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
} catch (
|
|
121
|
-
console.error("Error updating background music:",
|
|
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(),
|
|
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
|
|
136
|
-
e.isPlaying() ? e.fade(
|
|
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:
|
|
139
|
-
playSoundSync:
|
|
140
|
-
stopSound:
|
|
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
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
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
|
-
|
|
175
|
+
x as s,
|
|
155
176
|
R as u,
|
|
156
177
|
M as w
|
|
157
178
|
};
|