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.
- package/dist/use-audio-manager.mjs +73 -56
- package/package.json +1 -1
|
@@ -1,27 +1,44 @@
|
|
|
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
43
|
loop: u.loop ?? !1,
|
|
27
44
|
volume: 0
|
|
@@ -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";
|
|
@@ -65,9 +82,9 @@ function B(t) {
|
|
|
65
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
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
|
|
106
|
+
let o = !1;
|
|
90
107
|
const u = (t == null ? void 0 : t.defaultBgm) ?? "";
|
|
91
|
-
let
|
|
92
|
-
const e = (t == null ? void 0 : t.adapter) ?? new
|
|
93
|
-
var
|
|
94
|
-
return (((
|
|
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
|
|
113
|
+
async function r(a, l = !1) {
|
|
97
114
|
try {
|
|
98
|
-
const
|
|
99
|
-
if (!
|
|
100
|
-
|
|
101
|
-
} catch (
|
|
102
|
-
console.error("Sound playback failed:",
|
|
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
|
|
122
|
+
function c(a, l = !1) {
|
|
106
123
|
try {
|
|
107
|
-
const
|
|
108
|
-
if (!
|
|
109
|
-
|
|
110
|
-
const
|
|
111
|
-
e.playSync ? e.playSync(
|
|
112
|
-
} catch (
|
|
113
|
-
console.error("Sound playback failed:",
|
|
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(
|
|
120
|
-
if (
|
|
136
|
+
async function y(a, l) {
|
|
137
|
+
if (l)
|
|
121
138
|
try {
|
|
122
|
-
const
|
|
123
|
-
f &&
|
|
124
|
-
} catch (
|
|
125
|
-
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);
|
|
126
143
|
}
|
|
127
144
|
}
|
|
128
145
|
function m() {
|
|
129
146
|
if (!(typeof document > "u"))
|
|
130
147
|
try {
|
|
131
|
-
document.hidden ? e.isPlaying() && (e.pause(),
|
|
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
|
|
140
|
-
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);
|
|
141
158
|
}), {
|
|
142
|
-
playSound:
|
|
143
|
-
playSoundSync:
|
|
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
|
-
|
|
169
|
+
H,
|
|
153
170
|
L as b,
|
|
154
|
-
|
|
171
|
+
P as g,
|
|
155
172
|
A as i,
|
|
156
173
|
k as n,
|
|
157
174
|
B as p,
|