vue-micro-router 1.0.19 → 1.0.22
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/audio.d.ts +2 -0
- package/dist/audio.mjs +3 -98
- package/dist/index.d.ts +7 -1
- package/dist/index.mjs +355 -342
- package/dist/styles.css +1 -1
- package/dist/use-audio-manager.mjs +119 -0
- package/package.json +1 -1
- package/dist/timer-manager.mjs +0 -20
package/dist/audio.d.ts
CHANGED
|
@@ -33,6 +33,8 @@ export declare interface AudioAdapter {
|
|
|
33
33
|
export declare interface AudioManagerConfig {
|
|
34
34
|
/** Volume ref (0-100). Defaults to 100. */
|
|
35
35
|
volumeRef?: Ref<number>;
|
|
36
|
+
/** Default BGM track name — played on mount and used as fallback. Defaults to 'default'. */
|
|
37
|
+
defaultBgm?: string;
|
|
36
38
|
/** Resolve a sound name to a full URL. Defaults to identity (name returned as-is). */
|
|
37
39
|
urlResolver?: (name: string) => string;
|
|
38
40
|
/** Custom audio adapter. Defaults to HowlerAdapter (requires howler peer dep). */
|
package/dist/audio.mjs
CHANGED
|
@@ -1,100 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { d as S } from "./timer-manager.mjs";
|
|
3
|
-
class b {
|
|
4
|
-
constructor() {
|
|
5
|
-
this.sound = null, this.howlCtorPromise = null;
|
|
6
|
-
}
|
|
7
|
-
/** Lazy-load Howler.js — only imported when first sound is played */
|
|
8
|
-
async getHowlCtor() {
|
|
9
|
-
return this.howlCtorPromise || (this.howlCtorPromise = import("howler").then((s) => s.Howl)), this.howlCtorPromise;
|
|
10
|
-
}
|
|
11
|
-
async play(s, u = {}) {
|
|
12
|
-
this.stop();
|
|
13
|
-
const t = await this.getHowlCtor();
|
|
14
|
-
this.sound = new t({
|
|
15
|
-
src: [s],
|
|
16
|
-
autoplay: !0,
|
|
17
|
-
loop: u.loop ?? !1,
|
|
18
|
-
volume: 0
|
|
19
|
-
}), this.sound.fade(0, u.volume ?? 1, 200);
|
|
20
|
-
}
|
|
21
|
-
stop() {
|
|
22
|
-
try {
|
|
23
|
-
this.sound && (this.sound.stop(), this.sound.off(), this.sound.unload(), this.sound = null);
|
|
24
|
-
} catch {
|
|
25
|
-
this.sound = null;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
pause() {
|
|
29
|
-
var s;
|
|
30
|
-
(s = this.sound) != null && s.playing() && this.sound.pause();
|
|
31
|
-
}
|
|
32
|
-
resume() {
|
|
33
|
-
this.sound && this.state() === "loaded" && this.sound.play();
|
|
34
|
-
}
|
|
35
|
-
fade(s, u, t) {
|
|
36
|
-
var a;
|
|
37
|
-
(a = this.sound) != null && a.playing() && this.sound.fade(s, u, t);
|
|
38
|
-
}
|
|
39
|
-
isPlaying() {
|
|
40
|
-
var s;
|
|
41
|
-
return ((s = this.sound) == null ? void 0 : s.playing()) ?? !1;
|
|
42
|
-
}
|
|
43
|
-
state() {
|
|
44
|
-
return this.sound ? this.sound.state() : "unloaded";
|
|
45
|
-
}
|
|
46
|
-
cleanup() {
|
|
47
|
-
this.stop();
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
function g(o) {
|
|
51
|
-
let s = !1, u = "default";
|
|
52
|
-
const t = (o == null ? void 0 : o.adapter) ?? new b(), a = v("default"), c = (o == null ? void 0 : o.urlResolver) ?? ((e) => e), d = C(() => {
|
|
53
|
-
var e;
|
|
54
|
-
return (((e = o == null ? void 0 : o.volumeRef) == null ? void 0 : e.value) ?? 100) / 100;
|
|
55
|
-
});
|
|
56
|
-
async function h(e, n = !1) {
|
|
57
|
-
try {
|
|
58
|
-
if (t.isPlaying() && a.value === e) return;
|
|
59
|
-
u = a.value, a.value = e, t.stop(), await S(50), await t.play(c(e), { loop: n, volume: d.value });
|
|
60
|
-
} catch (l) {
|
|
61
|
-
console.error("Sound playback failed:", l), t.stop();
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
function f() {
|
|
65
|
-
t.stop();
|
|
66
|
-
}
|
|
67
|
-
async function y(e, n) {
|
|
68
|
-
if (n)
|
|
69
|
-
try {
|
|
70
|
-
const l = e.split("/").pop() || "home", r = n.get(l), i = (r == null ? void 0 : r.bgm) || a.value, p = u;
|
|
71
|
-
p && i && p !== i && await h(i, !0);
|
|
72
|
-
} catch (l) {
|
|
73
|
-
console.error("Error updating background music:", l);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
function m() {
|
|
77
|
-
if (!(typeof document > "u"))
|
|
78
|
-
try {
|
|
79
|
-
document.hidden ? t.isPlaying() && (t.pause(), s = !0) : s && t.state() === "loaded" && (t.resume(), s = !1);
|
|
80
|
-
} catch {
|
|
81
|
-
t.stop();
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
function w() {
|
|
85
|
-
t.cleanup();
|
|
86
|
-
}
|
|
87
|
-
return P(d, (e, n) => {
|
|
88
|
-
t.isPlaying() && t.fade(n ?? 0, e, 300);
|
|
89
|
-
}), {
|
|
90
|
-
playSound: h,
|
|
91
|
-
stopSound: f,
|
|
92
|
-
updateBackgroundMusic: y,
|
|
93
|
-
handleVisibilityChange: m,
|
|
94
|
-
cleanup: w
|
|
95
|
-
};
|
|
96
|
-
}
|
|
1
|
+
import { H as r, u as o } from "./use-audio-manager.mjs";
|
|
97
2
|
export {
|
|
98
|
-
|
|
99
|
-
|
|
3
|
+
r as HowlerAdapter,
|
|
4
|
+
o as useAudioManager
|
|
100
5
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -413,8 +413,12 @@ export declare interface MicroRouterConfig {
|
|
|
413
413
|
};
|
|
414
414
|
/** Analytics hooks for page/dialog/control enter/leave events */
|
|
415
415
|
tracker?: PageTrackerHooks;
|
|
416
|
-
/** Reactive volume ref (0-100) for audio manager.
|
|
416
|
+
/** Reactive volume ref (0-100) for audio manager. Enables built-in BGM when provided. */
|
|
417
417
|
volumeRef?: Ref<number>;
|
|
418
|
+
/** Default BGM track name — used as initial track and fallback when route has no bgm field */
|
|
419
|
+
defaultBgm?: string;
|
|
420
|
+
/** Resolve audio name to URL. Defaults to identity. Example: (name) => `/audios/${name}.mp3` */
|
|
421
|
+
audioUrlResolver?: (name: string) => string;
|
|
418
422
|
}
|
|
419
423
|
|
|
420
424
|
/**
|
|
@@ -559,6 +563,8 @@ export declare interface NavigationState {
|
|
|
559
563
|
getRouteAttrs: (segment: string) => Record<string, unknown> | undefined;
|
|
560
564
|
/** Manually preload an async route component */
|
|
561
565
|
preloadRoute: (segment: string) => Promise<void>;
|
|
566
|
+
/** Registered route definitions — used internally by audio manager for BGM lookup */
|
|
567
|
+
routes: Map<string, MicroRoute>;
|
|
562
568
|
/** Navigation history (only populated when config.history.enabled) */
|
|
563
569
|
history?: NavigationHistory;
|
|
564
570
|
cleanup: () => void;
|