@hi-ashleyj/llama 0.13.2 → 0.14.0
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/Game.svelte +154 -129
- package/dist/Game.svelte.d.ts +10 -21
- package/dist/Layer.svelte +61 -46
- package/dist/Layer.svelte.d.ts +9 -20
- package/dist/audio/AudioCompressor.svelte +70 -44
- package/dist/audio/AudioCompressor.svelte.d.ts +14 -23
- package/dist/audio/AudioGain.svelte +33 -20
- package/dist/audio/AudioGain.svelte.d.ts +6 -17
- package/dist/audio/AudioListenerPosition.svelte +79 -93
- package/dist/audio/AudioListenerPosition.svelte.d.ts +6 -16
- package/dist/audio/AudioPanner.svelte +33 -20
- package/dist/audio/AudioPanner.svelte.d.ts +6 -17
- package/dist/audio/BufferedAudioSource.svelte +59 -44
- package/dist/audio/BufferedAudioSource.svelte.d.ts +8 -18
- package/dist/audio/MediaAudioSource.svelte +56 -35
- package/dist/audio/MediaAudioSource.svelte.d.ts +13 -25
- package/dist/audio/context.d.ts +1 -1
- package/dist/controllers/MouseClickable.svelte +61 -49
- package/dist/controllers/MouseClickable.svelte.d.ts +11 -20
- package/dist/controllers/MouseEventArea.svelte +71 -55
- package/dist/controllers/MouseEventArea.svelte.d.ts +13 -26
- package/dist/controllers/motions.d.ts +4 -5
- package/dist/drawables/Arc.svelte +48 -30
- package/dist/drawables/Arc.svelte.d.ts +9 -19
- package/dist/drawables/Circle.svelte +38 -24
- package/dist/drawables/Circle.svelte.d.ts +7 -17
- package/dist/drawables/DisplayImage.svelte +26 -16
- package/dist/drawables/DisplayImage.svelte.d.ts +11 -21
- package/dist/drawables/MultiLineText.svelte +75 -45
- package/dist/drawables/MultiLineText.svelte.d.ts +14 -24
- package/dist/drawables/Rectangle.svelte +35 -22
- package/dist/drawables/Rectangle.svelte.d.ts +7 -17
- package/dist/drawables/RoundedRectangle.svelte +41 -23
- package/dist/drawables/RoundedRectangle.svelte.d.ts +8 -18
- package/dist/drawables/Text.svelte +63 -40
- package/dist/drawables/Text.svelte.d.ts +13 -23
- package/dist/drawables/Tiled.svelte +79 -61
- package/dist/drawables/Tiled.svelte.d.ts +10 -20
- package/dist/extras/DefaultFontFace.svelte +35 -17
- package/dist/extras/DefaultFontFace.svelte.d.ts +15 -24
- package/dist/extras/FullScreenEventHandler.svelte +37 -23
- package/dist/extras/FullScreenEventHandler.svelte.d.ts +9 -19
- package/dist/extras/LayerPortal.svelte +36 -22
- package/dist/extras/LayerPortal.svelte.d.ts +6 -17
- package/dist/extras/SensibleDefaultStyles.svelte +8 -2
- package/dist/extras/SensibleDefaultStyles.svelte.d.ts +5 -17
- package/dist/extras/Tweened.svelte +28 -9
- package/dist/extras/Tweened.svelte.d.ts +12 -22
- package/dist/primitives/Area.svelte +46 -22
- package/dist/primitives/Area.svelte.d.ts +14 -24
- package/dist/primitives/Empty.svelte +7 -2
- package/dist/primitives/Empty.svelte.d.ts +5 -15
- package/dist/primitives/Inset.svelte +45 -26
- package/dist/primitives/Inset.svelte.d.ts +9 -20
- package/dist/primitives/Node.svelte +32 -19
- package/dist/primitives/Node.svelte.d.ts +7 -18
- package/dist/primitives/Opacity.svelte +34 -22
- package/dist/primitives/Opacity.svelte.d.ts +6 -17
- package/dist/primitives/Rotate.svelte +33 -22
- package/dist/primitives/Rotate.svelte.d.ts +11 -21
- package/dist/primitives/Translate.svelte +32 -19
- package/dist/primitives/Translate.svelte.d.ts +7 -18
- package/dist/resources/AssetPool.svelte +7 -2
- package/dist/resources/AssetPool.svelte.d.ts +5 -15
- package/dist/resources/AudioBufferedAsset.svelte +14 -6
- package/dist/resources/AudioBufferedAsset.svelte.d.ts +5 -15
- package/dist/resources/AudioMediaAsset.svelte +10 -2
- package/dist/resources/AudioMediaAsset.svelte.d.ts +5 -15
- package/dist/resources/ImageAsset.svelte +16 -9
- package/dist/resources/ImageAsset.svelte.d.ts +5 -15
- package/dist/resources/audio.d.ts +1 -1
- package/dist/resources/images.d.ts +1 -1
- package/dist/scenes/SceneSwitcher.svelte +27 -16
- package/dist/scenes/SceneSwitcher.svelte.d.ts +5 -16
- package/dist/scenes/SceneTransition.svelte +47 -36
- package/dist/scenes/SceneTransition.svelte.d.ts +6 -20
- package/package.json +10 -9
|
@@ -1,22 +1,35 @@
|
|
|
1
|
-
<script
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
|
|
3
|
+
import { getAudioContext, getConnector } from "./context.js";
|
|
4
|
+
import { onMount } from "svelte";
|
|
5
|
+
const audioContext = getAudioContext();
|
|
6
|
+
|
|
7
|
+
interface Props {
|
|
8
|
+
gain?: number;
|
|
9
|
+
children?: import('svelte').Snippet;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
let { gain = 1, children }: Props = $props();
|
|
13
|
+
|
|
14
|
+
let output: GainNode = $state();
|
|
15
|
+
|
|
16
|
+
$effect(() => {
|
|
17
|
+
if (output) {
|
|
18
|
+
output.gain.setTargetAtTime(gain, output.context.currentTime, 0.004);
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
const connect = getConnector((node) => {
|
|
23
|
+
node.connect(output);
|
|
24
|
+
return () => node.disconnect(output);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
onMount(() => {
|
|
28
|
+
const audioCTX = audioContext();
|
|
29
|
+
output = audioCTX.createGain();
|
|
30
|
+
return connect(output);
|
|
31
|
+
})
|
|
32
|
+
|
|
20
33
|
</script>
|
|
21
34
|
|
|
22
|
-
|
|
35
|
+
{@render children?.()}
|
|
@@ -1,18 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
gain?: number | undefined;
|
|
5
|
-
};
|
|
6
|
-
events: {
|
|
7
|
-
[evt: string]: CustomEvent<any>;
|
|
8
|
-
};
|
|
9
|
-
slots: {
|
|
10
|
-
default: {};
|
|
11
|
-
};
|
|
12
|
-
};
|
|
13
|
-
export type AudioGainProps = typeof __propDef.props;
|
|
14
|
-
export type AudioGainEvents = typeof __propDef.events;
|
|
15
|
-
export type AudioGainSlots = typeof __propDef.slots;
|
|
16
|
-
export default class AudioGain extends SvelteComponent<AudioGainProps, AudioGainEvents, AudioGainSlots> {
|
|
1
|
+
interface Props {
|
|
2
|
+
gain?: number;
|
|
3
|
+
children?: import('svelte').Snippet;
|
|
17
4
|
}
|
|
18
|
-
|
|
5
|
+
declare const AudioGain: import("svelte").Component<Props, {}, "">;
|
|
6
|
+
type AudioGain = ReturnType<typeof AudioGain>;
|
|
7
|
+
export default AudioGain;
|
|
@@ -1,94 +1,80 @@
|
|
|
1
|
-
<script
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
(
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
audioCTX.listener.
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
audioCTX.listener.
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
if (audioCTX)
|
|
81
|
-
audioCTX.listener.upX.value = up[0];
|
|
82
|
-
}
|
|
83
|
-
$: {
|
|
84
|
-
if (audioCTX)
|
|
85
|
-
audioCTX.listener.upY.value = up[1];
|
|
86
|
-
}
|
|
87
|
-
$: {
|
|
88
|
-
if (audioCTX)
|
|
89
|
-
audioCTX.listener.upZ.value = up[2];
|
|
90
|
-
}
|
|
91
|
-
onMount(() => {
|
|
92
|
-
audioCTX = audioContext();
|
|
93
|
-
});
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
|
|
3
|
+
// Roll, Pitch, Yaw. All between -180 - 180. [ 0, 0, 0 ] faces directly along the X coordinate standing upright.
|
|
4
|
+
// Roll rotates the viewport leftward as it goes negative.
|
|
5
|
+
// Pitch looks downwards as it goes negative.
|
|
6
|
+
// Yaw rotates leftwards as it goes negative (toward -Z)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
const dot = ([i, j, k]: number[], [x, y, z]: number[]): number => {
|
|
10
|
+
return i * x + j * y + k * z;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const cross = ([i, j, k]: number[], [x, y, z]: number[]) => {
|
|
14
|
+
return [
|
|
15
|
+
(j * z) - (k * y),
|
|
16
|
+
((i * z) - (k * x)) * -1,
|
|
17
|
+
(i * y) - (j * x)
|
|
18
|
+
]
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const buildQuaternion = (roll: number, pitch: number, yaw: number) => {
|
|
22
|
+
const rdRoll = roll / 360 * Math.PI;
|
|
23
|
+
const rdPitch = pitch / 360 * Math.PI;
|
|
24
|
+
const rdYaw = yaw / 360 * Math.PI;
|
|
25
|
+
const x = Math.sin(rdRoll) * Math.cos(rdPitch) * Math.cos(rdYaw) - Math.cos(rdRoll) * Math.sin(rdPitch) * Math.sin(rdYaw)
|
|
26
|
+
const y = Math.cos(rdRoll) * Math.sin(rdPitch) * Math.cos(rdYaw) + Math.sin(rdRoll) * Math.cos(rdPitch) * Math.sin(rdYaw)
|
|
27
|
+
const z = Math.cos(rdRoll) * Math.cos(rdPitch) * Math.sin(rdYaw) - Math.sin(rdRoll) * Math.sin(rdPitch) * Math.cos(rdYaw)
|
|
28
|
+
const w = Math.cos(rdRoll) * Math.cos(rdPitch) * Math.cos(rdYaw) + Math.sin(rdRoll) * Math.sin(rdPitch) * Math.sin(rdYaw)
|
|
29
|
+
|
|
30
|
+
return [ x, y, z, w ];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const rotatedVector = ([i, j, k]: number[], [x, y, z, w]: number[]) => {
|
|
34
|
+
const dotUVTimesTwo = dot([x, y, z], [i, j, k]) * 2;
|
|
35
|
+
const WxWMinusDotUU = w * w - dot([x, y, z], [x, y, z]);
|
|
36
|
+
const crossUV = cross([x, y, z], [i, j, k]);
|
|
37
|
+
|
|
38
|
+
return [
|
|
39
|
+
dotUVTimesTwo * x + WxWMinusDotUU * i + 2 * w * crossUV[0],
|
|
40
|
+
dotUVTimesTwo * y + WxWMinusDotUU * j + 2 * w * crossUV[1],
|
|
41
|
+
dotUVTimesTwo * z + WxWMinusDotUU * k + 2 * w * crossUV[2],
|
|
42
|
+
]
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
import { getAudioContext } from "./context.js";
|
|
47
|
+
import { onMount } from "svelte";
|
|
48
|
+
interface Props {
|
|
49
|
+
position?: [ number, number, number ];
|
|
50
|
+
orientation?: [ number, number, number ];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
let { position = [0, 0, 0], orientation = [0, 0, 0] }: Props = $props();
|
|
54
|
+
const audioContext = getAudioContext();
|
|
55
|
+
let audioCTX: AudioContext | null = $state(null);
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
onMount(() => {
|
|
59
|
+
audioCTX = audioContext();
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
let positionX = $derived(position[0]);
|
|
63
|
+
let positionY = $derived(position[1]);
|
|
64
|
+
let positionZ = $derived(position[2]);
|
|
65
|
+
let roll = $derived(orientation[0]);
|
|
66
|
+
let pitch = $derived(orientation[1]);
|
|
67
|
+
let yaw = $derived(orientation[2]);
|
|
68
|
+
let quaterion = $derived(buildQuaternion(roll, pitch, yaw));
|
|
69
|
+
let forward = $derived(rotatedVector([1, 0, 0], quaterion));
|
|
70
|
+
let up = $derived(rotatedVector([0, 1, 0], quaterion));
|
|
71
|
+
$effect(() => { if (audioCTX) audioCTX.listener.positionX.value = positionX });
|
|
72
|
+
$effect(() => { if (audioCTX) audioCTX.listener.positionY.value = positionY });
|
|
73
|
+
$effect(() => { if (audioCTX) audioCTX.listener.positionZ.value = positionZ });
|
|
74
|
+
$effect(() => { if (audioCTX) audioCTX.listener.forwardX.value = forward[0] });
|
|
75
|
+
$effect(() => { if (audioCTX) audioCTX.listener.forwardY.value = forward[1] });
|
|
76
|
+
$effect(() => { if (audioCTX) audioCTX.listener.forwardZ.value = forward[2] });
|
|
77
|
+
$effect(() => { if (audioCTX) audioCTX.listener.upX.value = up[0] });
|
|
78
|
+
$effect(() => { if (audioCTX) audioCTX.listener.upY.value = up[1] });
|
|
79
|
+
$effect(() => { if (audioCTX) audioCTX.listener.upZ.value = up[2] });
|
|
94
80
|
</script>
|
|
@@ -1,17 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
position?: [number, number, number] | undefined;
|
|
5
|
-
orientation?: [number, number, number] | undefined;
|
|
6
|
-
};
|
|
7
|
-
events: {
|
|
8
|
-
[evt: string]: CustomEvent<any>;
|
|
9
|
-
};
|
|
10
|
-
slots: {};
|
|
11
|
-
};
|
|
12
|
-
export type AudioListenerPositionProps = typeof __propDef.props;
|
|
13
|
-
export type AudioListenerPositionEvents = typeof __propDef.events;
|
|
14
|
-
export type AudioListenerPositionSlots = typeof __propDef.slots;
|
|
15
|
-
export default class AudioListenerPosition extends SvelteComponent<AudioListenerPositionProps, AudioListenerPositionEvents, AudioListenerPositionSlots> {
|
|
1
|
+
interface Props {
|
|
2
|
+
position?: [number, number, number];
|
|
3
|
+
orientation?: [number, number, number];
|
|
16
4
|
}
|
|
17
|
-
|
|
5
|
+
declare const AudioListenerPosition: import("svelte").Component<Props, {}, "">;
|
|
6
|
+
type AudioListenerPosition = ReturnType<typeof AudioListenerPosition>;
|
|
7
|
+
export default AudioListenerPosition;
|
|
@@ -1,22 +1,35 @@
|
|
|
1
|
-
<script
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
|
|
3
|
+
import { getAudioContext, getConnector } from "./context.js";
|
|
4
|
+
import { onMount } from "svelte";
|
|
5
|
+
const audioContext = getAudioContext();
|
|
6
|
+
|
|
7
|
+
interface Props {
|
|
8
|
+
pan?: number;
|
|
9
|
+
children?: import('svelte').Snippet;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
let { pan = 0, children }: Props = $props();
|
|
13
|
+
|
|
14
|
+
let output: StereoPannerNode = $state();
|
|
15
|
+
|
|
16
|
+
$effect(() => {
|
|
17
|
+
if (output) {
|
|
18
|
+
output.pan.value = pan;
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
const connect = getConnector((node) => {
|
|
23
|
+
node.connect(output);
|
|
24
|
+
return () => node.disconnect(output);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
onMount(() => {
|
|
28
|
+
const audioCtx = audioContext();
|
|
29
|
+
output = audioCtx.createStereoPanner();
|
|
30
|
+
return connect(output);
|
|
31
|
+
})
|
|
32
|
+
|
|
20
33
|
</script>
|
|
21
34
|
|
|
22
|
-
|
|
35
|
+
{@render children?.()}
|
|
@@ -1,18 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
pan?: number | undefined;
|
|
5
|
-
};
|
|
6
|
-
events: {
|
|
7
|
-
[evt: string]: CustomEvent<any>;
|
|
8
|
-
};
|
|
9
|
-
slots: {
|
|
10
|
-
default: {};
|
|
11
|
-
};
|
|
12
|
-
};
|
|
13
|
-
export type AudioPannerProps = typeof __propDef.props;
|
|
14
|
-
export type AudioPannerEvents = typeof __propDef.events;
|
|
15
|
-
export type AudioPannerSlots = typeof __propDef.slots;
|
|
16
|
-
export default class AudioPanner extends SvelteComponent<AudioPannerProps, AudioPannerEvents, AudioPannerSlots> {
|
|
1
|
+
interface Props {
|
|
2
|
+
pan?: number;
|
|
3
|
+
children?: import('svelte').Snippet;
|
|
17
4
|
}
|
|
18
|
-
|
|
5
|
+
declare const AudioPanner: import("svelte").Component<Props, {}, "">;
|
|
6
|
+
type AudioPanner = ReturnType<typeof AudioPanner>;
|
|
7
|
+
export default AudioPanner;
|
|
@@ -1,47 +1,62 @@
|
|
|
1
|
-
<script
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
output.gain.setTargetAtTime(volume, output.context.currentTime, 4e-3);
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
const playing = /* @__PURE__ */ new Set();
|
|
14
|
-
export const play = () => {
|
|
15
|
-
if (!audioBuffer)
|
|
16
|
-
return;
|
|
17
|
-
const source = audioCTX.createBufferSource();
|
|
18
|
-
source.buffer = audioBuffer;
|
|
19
|
-
source.addEventListener("ended", () => {
|
|
20
|
-
source.disconnect(output);
|
|
21
|
-
playing.delete(source);
|
|
22
|
-
});
|
|
23
|
-
source.connect(output);
|
|
24
|
-
playing.add(source);
|
|
25
|
-
source.start();
|
|
26
|
-
return () => {
|
|
27
|
-
if (playing.has(source)) {
|
|
28
|
-
source.stop();
|
|
29
|
-
source.disconnect(output);
|
|
30
|
-
playing.delete(source);
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
|
|
3
|
+
import { getAudioContext, getConnector } from "./context.js";
|
|
4
|
+
import { onMount } from "svelte";
|
|
5
|
+
const audioContext = getAudioContext();
|
|
6
|
+
|
|
7
|
+
interface Props {
|
|
8
|
+
volume?: number;
|
|
9
|
+
audioBuffer: AudioBuffer;
|
|
31
10
|
}
|
|
32
|
-
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
11
|
+
|
|
12
|
+
let { volume = 1, audioBuffer }: Props = $props();
|
|
13
|
+
|
|
14
|
+
let output: GainNode = $state();
|
|
15
|
+
let audioCTX: AudioContext;
|
|
16
|
+
|
|
17
|
+
$effect(() => {
|
|
18
|
+
if (output) {
|
|
19
|
+
output.gain.setTargetAtTime(volume, output.context.currentTime, 0.004);
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const playing = new Set<AudioBufferSourceNode>();
|
|
24
|
+
|
|
25
|
+
export const play = () => {
|
|
26
|
+
if (!audioBuffer) return;
|
|
27
|
+
const source = audioCTX.createBufferSource();
|
|
28
|
+
source.buffer = audioBuffer;
|
|
29
|
+
source.addEventListener("ended", () => {
|
|
30
|
+
source.disconnect(output);
|
|
31
|
+
playing.delete(source);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
source.connect(output);
|
|
35
|
+
playing.add(source);
|
|
36
|
+
source.start();
|
|
37
|
+
return () => {
|
|
38
|
+
if (playing.has(source)) {
|
|
39
|
+
source.stop();
|
|
40
|
+
source.disconnect(output);
|
|
41
|
+
playing.delete(source);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
43
44
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
|
|
46
|
+
const connect = getConnector();
|
|
47
|
+
|
|
48
|
+
onMount(() => {
|
|
49
|
+
audioCTX = audioContext();
|
|
50
|
+
output = audioCtx.createGain();
|
|
51
|
+
|
|
52
|
+
const disconnect = connect(output);
|
|
53
|
+
return () => {
|
|
54
|
+
for (let node of playing) {
|
|
55
|
+
node.stop();
|
|
56
|
+
node.disconnect(output);
|
|
57
|
+
}
|
|
58
|
+
disconnect();
|
|
59
|
+
}
|
|
60
|
+
})
|
|
61
|
+
|
|
47
62
|
</script>
|
|
@@ -1,19 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
volume?: number | undefined;
|
|
5
|
-
audioBuffer: AudioBuffer;
|
|
6
|
-
play?: (() => (() => void) | undefined) | undefined;
|
|
7
|
-
};
|
|
8
|
-
events: {
|
|
9
|
-
[evt: string]: CustomEvent<any>;
|
|
10
|
-
};
|
|
11
|
-
slots: {};
|
|
12
|
-
};
|
|
13
|
-
export type BufferedAudioSourceProps = typeof __propDef.props;
|
|
14
|
-
export type BufferedAudioSourceEvents = typeof __propDef.events;
|
|
15
|
-
export type BufferedAudioSourceSlots = typeof __propDef.slots;
|
|
16
|
-
export default class BufferedAudioSource extends SvelteComponent<BufferedAudioSourceProps, BufferedAudioSourceEvents, BufferedAudioSourceSlots> {
|
|
17
|
-
get play(): () => (() => void) | undefined;
|
|
1
|
+
interface Props {
|
|
2
|
+
volume?: number;
|
|
3
|
+
audioBuffer: AudioBuffer;
|
|
18
4
|
}
|
|
19
|
-
|
|
5
|
+
declare const BufferedAudioSource: import("svelte").Component<Props, {
|
|
6
|
+
play: () => (() => void) | undefined;
|
|
7
|
+
}, "">;
|
|
8
|
+
type BufferedAudioSource = ReturnType<typeof BufferedAudioSource>;
|
|
9
|
+
export default BufferedAudioSource;
|
|
@@ -1,37 +1,58 @@
|
|
|
1
|
-
<script
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
|
|
3
|
+
import { getAudioContext, getConnector } from "./context.js";
|
|
4
|
+
import { onMount } from "svelte";
|
|
5
|
+
const audioContext = getAudioContext();
|
|
6
|
+
|
|
7
|
+
interface Props {
|
|
8
|
+
url: string;
|
|
9
|
+
volume?: number;
|
|
10
|
+
paused?: boolean;
|
|
11
|
+
playbackPosition: number;
|
|
12
|
+
loop?: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
let {
|
|
16
|
+
url,
|
|
17
|
+
volume = 1,
|
|
18
|
+
paused = $bindable(true),
|
|
19
|
+
playbackPosition = $bindable(),
|
|
20
|
+
loop = false
|
|
21
|
+
}: Props = $props();
|
|
22
|
+
|
|
23
|
+
export const playFromStart = () => {
|
|
24
|
+
playbackPosition = 0;
|
|
25
|
+
paused = false;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const play = () => {
|
|
29
|
+
paused = false;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export const pause = () => {
|
|
33
|
+
paused = true;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
let output: GainNode = $state();
|
|
37
|
+
let sourceNode: MediaElementAudioSourceNode
|
|
38
|
+
let element: HTMLAudioElement = $state();
|
|
39
|
+
|
|
40
|
+
$effect(() => {
|
|
41
|
+
if (output) {
|
|
42
|
+
output.gain.setTargetAtTime(volume, output.context.currentTime, 0.004);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
const connect = getConnector();
|
|
47
|
+
|
|
48
|
+
onMount(() => {
|
|
49
|
+
const audioCTX = audioContext();
|
|
50
|
+
sourceNode = audioCTX.createMediaElementSource(element);
|
|
51
|
+
output = audioCTX.createGain();
|
|
52
|
+
sourceNode.connect(output);
|
|
53
|
+
return connect(output);
|
|
54
|
+
});
|
|
55
|
+
|
|
35
56
|
</script>
|
|
36
57
|
|
|
37
|
-
<audio src={url} hidden loop={loop} bind:paused={paused} bind:currentTime={playbackPosition} bind:this={element}
|
|
58
|
+
<audio src={url} hidden loop={loop} bind:paused={paused} bind:currentTime={playbackPosition} bind:this={element}></audio>
|
|
@@ -1,26 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
playbackPosition: number;
|
|
8
|
-
loop?: boolean | undefined;
|
|
9
|
-
playFromStart?: (() => void) | undefined;
|
|
10
|
-
play?: (() => void) | undefined;
|
|
11
|
-
pause?: (() => void) | undefined;
|
|
12
|
-
};
|
|
13
|
-
events: {
|
|
14
|
-
[evt: string]: CustomEvent<any>;
|
|
15
|
-
};
|
|
16
|
-
slots: {};
|
|
17
|
-
};
|
|
18
|
-
export type MediaAudioSourceProps = typeof __propDef.props;
|
|
19
|
-
export type MediaAudioSourceEvents = typeof __propDef.events;
|
|
20
|
-
export type MediaAudioSourceSlots = typeof __propDef.slots;
|
|
21
|
-
export default class MediaAudioSource extends SvelteComponent<MediaAudioSourceProps, MediaAudioSourceEvents, MediaAudioSourceSlots> {
|
|
22
|
-
get playFromStart(): () => void;
|
|
23
|
-
get play(): () => void;
|
|
24
|
-
get pause(): () => void;
|
|
1
|
+
interface Props {
|
|
2
|
+
url: string;
|
|
3
|
+
volume?: number;
|
|
4
|
+
paused?: boolean;
|
|
5
|
+
playbackPosition: number;
|
|
6
|
+
loop?: boolean;
|
|
25
7
|
}
|
|
26
|
-
|
|
8
|
+
declare const MediaAudioSource: import("svelte").Component<Props, {
|
|
9
|
+
playFromStart: () => void;
|
|
10
|
+
play: () => void;
|
|
11
|
+
pause: () => void;
|
|
12
|
+
}, "paused" | "playbackPosition">;
|
|
13
|
+
type MediaAudioSource = ReturnType<typeof MediaAudioSource>;
|
|
14
|
+
export default MediaAudioSource;
|
package/dist/audio/context.d.ts
CHANGED
|
@@ -4,4 +4,4 @@ export type AudioSvelteContext = {
|
|
|
4
4
|
};
|
|
5
5
|
export declare const getSetupAudio: (connect: (node: AudioNode) => DisconnectFunction) => void;
|
|
6
6
|
export declare const getAudioContext: () => () => AudioContext;
|
|
7
|
-
export declare const getConnector: (connect?: (
|
|
7
|
+
export declare const getConnector: (connect?: (node: AudioNode) => DisconnectFunction) => (node: AudioNode) => DisconnectFunction;
|