svelte-attach-sound 0.1.1 → 0.1.3
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/index.cjs +16 -22
- package/dist/index.d.cts +0 -4
- package/dist/index.d.mts +0 -4
- package/dist/index.mjs +16 -22
- package/package.json +9 -9
package/dist/index.cjs
CHANGED
|
@@ -1,38 +1,32 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let svelte_events = require("svelte/events");
|
|
2
3
|
//#region src/index.ts
|
|
3
4
|
/**
|
|
4
5
|
* A class representing a synthetic sound.
|
|
5
6
|
* Can be used standalone for programmatic playback without any DOM dependency.
|
|
6
7
|
*/
|
|
7
8
|
var Sound = class {
|
|
8
|
-
config;
|
|
9
9
|
howl;
|
|
10
|
-
ready;
|
|
11
10
|
constructor(src, options = {}) {
|
|
12
|
-
this.
|
|
11
|
+
this.howl = import("howler/src/howler.core").then(({ Howl }) => new Howl({
|
|
13
12
|
...options,
|
|
14
13
|
src
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
this.ready.then(fn).catch(() => {});
|
|
20
|
-
}
|
|
21
|
-
async create() {
|
|
22
|
-
const { Howl } = await import("howler/src/howler.core");
|
|
23
|
-
this.howl = new Howl(this.config);
|
|
14
|
+
})).catch((e) => {
|
|
15
|
+
console.warn("[svelte-attach-sound] Failed to load sound:", e);
|
|
16
|
+
throw e;
|
|
17
|
+
});
|
|
24
18
|
}
|
|
25
19
|
play() {
|
|
26
|
-
this.
|
|
20
|
+
this.howl.then((h) => h.play()).catch(() => {});
|
|
27
21
|
}
|
|
28
22
|
stop() {
|
|
29
|
-
this.
|
|
23
|
+
this.howl.then((h) => h.stop()).catch(() => {});
|
|
30
24
|
}
|
|
31
25
|
destroy() {
|
|
32
|
-
this.
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
});
|
|
26
|
+
this.howl.then((h) => {
|
|
27
|
+
h.stop();
|
|
28
|
+
h.unload();
|
|
29
|
+
}).catch(() => {});
|
|
36
30
|
}
|
|
37
31
|
};
|
|
38
32
|
/**
|
|
@@ -58,11 +52,11 @@ function sound(options) {
|
|
|
58
52
|
const instance = new Sound(src, howlOptions);
|
|
59
53
|
const handlePlay = () => instance.play();
|
|
60
54
|
const handleStop = () => instance.stop();
|
|
61
|
-
|
|
62
|
-
|
|
55
|
+
const offPlay = (0, svelte_events.on)(element, playEvent, handlePlay);
|
|
56
|
+
const offStop = stopEvent ? (0, svelte_events.on)(element, stopEvent, handleStop) : null;
|
|
63
57
|
return () => {
|
|
64
|
-
|
|
65
|
-
|
|
58
|
+
offPlay();
|
|
59
|
+
offStop?.();
|
|
66
60
|
instance.destroy();
|
|
67
61
|
};
|
|
68
62
|
};
|
package/dist/index.d.cts
CHANGED
|
@@ -16,12 +16,8 @@ type Options = {
|
|
|
16
16
|
* Can be used standalone for programmatic playback without any DOM dependency.
|
|
17
17
|
*/
|
|
18
18
|
declare class Sound {
|
|
19
|
-
private config;
|
|
20
19
|
private howl;
|
|
21
|
-
private ready;
|
|
22
20
|
constructor(src: SoundSource, options?: SoundOptions);
|
|
23
|
-
private whenReady;
|
|
24
|
-
private create;
|
|
25
21
|
play(): void;
|
|
26
22
|
stop(): void;
|
|
27
23
|
destroy(): void;
|
package/dist/index.d.mts
CHANGED
|
@@ -16,12 +16,8 @@ type Options = {
|
|
|
16
16
|
* Can be used standalone for programmatic playback without any DOM dependency.
|
|
17
17
|
*/
|
|
18
18
|
declare class Sound {
|
|
19
|
-
private config;
|
|
20
19
|
private howl;
|
|
21
|
-
private ready;
|
|
22
20
|
constructor(src: SoundSource, options?: SoundOptions);
|
|
23
|
-
private whenReady;
|
|
24
|
-
private create;
|
|
25
21
|
play(): void;
|
|
26
22
|
stop(): void;
|
|
27
23
|
destroy(): void;
|
package/dist/index.mjs
CHANGED
|
@@ -1,37 +1,31 @@
|
|
|
1
|
+
import { on } from "svelte/events";
|
|
1
2
|
//#region src/index.ts
|
|
2
3
|
/**
|
|
3
4
|
* A class representing a synthetic sound.
|
|
4
5
|
* Can be used standalone for programmatic playback without any DOM dependency.
|
|
5
6
|
*/
|
|
6
7
|
var Sound = class {
|
|
7
|
-
config;
|
|
8
8
|
howl;
|
|
9
|
-
ready;
|
|
10
9
|
constructor(src, options = {}) {
|
|
11
|
-
this.
|
|
10
|
+
this.howl = import("howler/src/howler.core").then(({ Howl }) => new Howl({
|
|
12
11
|
...options,
|
|
13
12
|
src
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
this.ready.then(fn).catch(() => {});
|
|
19
|
-
}
|
|
20
|
-
async create() {
|
|
21
|
-
const { Howl } = await import("howler/src/howler.core");
|
|
22
|
-
this.howl = new Howl(this.config);
|
|
13
|
+
})).catch((e) => {
|
|
14
|
+
console.warn("[svelte-attach-sound] Failed to load sound:", e);
|
|
15
|
+
throw e;
|
|
16
|
+
});
|
|
23
17
|
}
|
|
24
18
|
play() {
|
|
25
|
-
this.
|
|
19
|
+
this.howl.then((h) => h.play()).catch(() => {});
|
|
26
20
|
}
|
|
27
21
|
stop() {
|
|
28
|
-
this.
|
|
22
|
+
this.howl.then((h) => h.stop()).catch(() => {});
|
|
29
23
|
}
|
|
30
24
|
destroy() {
|
|
31
|
-
this.
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
});
|
|
25
|
+
this.howl.then((h) => {
|
|
26
|
+
h.stop();
|
|
27
|
+
h.unload();
|
|
28
|
+
}).catch(() => {});
|
|
35
29
|
}
|
|
36
30
|
};
|
|
37
31
|
/**
|
|
@@ -57,11 +51,11 @@ function sound(options) {
|
|
|
57
51
|
const instance = new Sound(src, howlOptions);
|
|
58
52
|
const handlePlay = () => instance.play();
|
|
59
53
|
const handleStop = () => instance.stop();
|
|
60
|
-
element
|
|
61
|
-
|
|
54
|
+
const offPlay = on(element, playEvent, handlePlay);
|
|
55
|
+
const offStop = stopEvent ? on(element, stopEvent, handleStop) : null;
|
|
62
56
|
return () => {
|
|
63
|
-
|
|
64
|
-
|
|
57
|
+
offPlay();
|
|
58
|
+
offStop?.();
|
|
65
59
|
instance.destroy();
|
|
66
60
|
};
|
|
67
61
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "svelte-attach-sound",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "A Svelte attachment for binding sound playback to DOM events using Howler.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"attachment",
|
|
@@ -43,17 +43,17 @@
|
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@types/howler": "^2.2.12",
|
|
45
45
|
"@types/node": "^25.0.3",
|
|
46
|
-
"bumpp": "^
|
|
46
|
+
"bumpp": "^11.0.1",
|
|
47
47
|
"howler": "^2.2.4",
|
|
48
|
-
"oxfmt": "^0.
|
|
49
|
-
"oxlint": "^1.
|
|
50
|
-
"svelte": "^5.
|
|
51
|
-
"tsdown": "^0.21.
|
|
52
|
-
"typescript": "^
|
|
53
|
-
"vitest": "^4.
|
|
48
|
+
"oxfmt": "^0.41.0",
|
|
49
|
+
"oxlint": "^1.56.0",
|
|
50
|
+
"svelte": "^5.55.0",
|
|
51
|
+
"tsdown": "^0.21.4",
|
|
52
|
+
"typescript": "^6.0.2",
|
|
53
|
+
"vitest": "^4.1.1"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
56
|
"howler": ">=2.0.0",
|
|
57
|
-
"svelte": ">=5.
|
|
57
|
+
"svelte": ">=5.55.0"
|
|
58
58
|
}
|
|
59
59
|
}
|