@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.
Files changed (77) hide show
  1. package/dist/Game.svelte +154 -129
  2. package/dist/Game.svelte.d.ts +10 -21
  3. package/dist/Layer.svelte +61 -46
  4. package/dist/Layer.svelte.d.ts +9 -20
  5. package/dist/audio/AudioCompressor.svelte +70 -44
  6. package/dist/audio/AudioCompressor.svelte.d.ts +14 -23
  7. package/dist/audio/AudioGain.svelte +33 -20
  8. package/dist/audio/AudioGain.svelte.d.ts +6 -17
  9. package/dist/audio/AudioListenerPosition.svelte +79 -93
  10. package/dist/audio/AudioListenerPosition.svelte.d.ts +6 -16
  11. package/dist/audio/AudioPanner.svelte +33 -20
  12. package/dist/audio/AudioPanner.svelte.d.ts +6 -17
  13. package/dist/audio/BufferedAudioSource.svelte +59 -44
  14. package/dist/audio/BufferedAudioSource.svelte.d.ts +8 -18
  15. package/dist/audio/MediaAudioSource.svelte +56 -35
  16. package/dist/audio/MediaAudioSource.svelte.d.ts +13 -25
  17. package/dist/audio/context.d.ts +1 -1
  18. package/dist/controllers/MouseClickable.svelte +61 -49
  19. package/dist/controllers/MouseClickable.svelte.d.ts +11 -20
  20. package/dist/controllers/MouseEventArea.svelte +71 -55
  21. package/dist/controllers/MouseEventArea.svelte.d.ts +13 -26
  22. package/dist/controllers/motions.d.ts +4 -5
  23. package/dist/drawables/Arc.svelte +48 -30
  24. package/dist/drawables/Arc.svelte.d.ts +9 -19
  25. package/dist/drawables/Circle.svelte +38 -24
  26. package/dist/drawables/Circle.svelte.d.ts +7 -17
  27. package/dist/drawables/DisplayImage.svelte +26 -16
  28. package/dist/drawables/DisplayImage.svelte.d.ts +11 -21
  29. package/dist/drawables/MultiLineText.svelte +75 -45
  30. package/dist/drawables/MultiLineText.svelte.d.ts +14 -24
  31. package/dist/drawables/Rectangle.svelte +35 -22
  32. package/dist/drawables/Rectangle.svelte.d.ts +7 -17
  33. package/dist/drawables/RoundedRectangle.svelte +41 -23
  34. package/dist/drawables/RoundedRectangle.svelte.d.ts +8 -18
  35. package/dist/drawables/Text.svelte +63 -40
  36. package/dist/drawables/Text.svelte.d.ts +13 -23
  37. package/dist/drawables/Tiled.svelte +79 -61
  38. package/dist/drawables/Tiled.svelte.d.ts +10 -20
  39. package/dist/extras/DefaultFontFace.svelte +35 -17
  40. package/dist/extras/DefaultFontFace.svelte.d.ts +15 -24
  41. package/dist/extras/FullScreenEventHandler.svelte +37 -23
  42. package/dist/extras/FullScreenEventHandler.svelte.d.ts +9 -19
  43. package/dist/extras/LayerPortal.svelte +36 -22
  44. package/dist/extras/LayerPortal.svelte.d.ts +6 -17
  45. package/dist/extras/SensibleDefaultStyles.svelte +8 -2
  46. package/dist/extras/SensibleDefaultStyles.svelte.d.ts +5 -17
  47. package/dist/extras/Tweened.svelte +28 -9
  48. package/dist/extras/Tweened.svelte.d.ts +12 -22
  49. package/dist/primitives/Area.svelte +46 -22
  50. package/dist/primitives/Area.svelte.d.ts +14 -24
  51. package/dist/primitives/Empty.svelte +7 -2
  52. package/dist/primitives/Empty.svelte.d.ts +5 -15
  53. package/dist/primitives/Inset.svelte +45 -26
  54. package/dist/primitives/Inset.svelte.d.ts +9 -20
  55. package/dist/primitives/Node.svelte +32 -19
  56. package/dist/primitives/Node.svelte.d.ts +7 -18
  57. package/dist/primitives/Opacity.svelte +34 -22
  58. package/dist/primitives/Opacity.svelte.d.ts +6 -17
  59. package/dist/primitives/Rotate.svelte +33 -22
  60. package/dist/primitives/Rotate.svelte.d.ts +11 -21
  61. package/dist/primitives/Translate.svelte +32 -19
  62. package/dist/primitives/Translate.svelte.d.ts +7 -18
  63. package/dist/resources/AssetPool.svelte +7 -2
  64. package/dist/resources/AssetPool.svelte.d.ts +5 -15
  65. package/dist/resources/AudioBufferedAsset.svelte +14 -6
  66. package/dist/resources/AudioBufferedAsset.svelte.d.ts +5 -15
  67. package/dist/resources/AudioMediaAsset.svelte +10 -2
  68. package/dist/resources/AudioMediaAsset.svelte.d.ts +5 -15
  69. package/dist/resources/ImageAsset.svelte +16 -9
  70. package/dist/resources/ImageAsset.svelte.d.ts +5 -15
  71. package/dist/resources/audio.d.ts +1 -1
  72. package/dist/resources/images.d.ts +1 -1
  73. package/dist/scenes/SceneSwitcher.svelte +27 -16
  74. package/dist/scenes/SceneSwitcher.svelte.d.ts +5 -16
  75. package/dist/scenes/SceneTransition.svelte +47 -36
  76. package/dist/scenes/SceneTransition.svelte.d.ts +6 -20
  77. package/package.json +10 -9
@@ -1,22 +1,35 @@
1
- <script>import { getAudioContext, getConnector } from "./context.js";
2
- import { onMount } from "svelte";
3
- const audioContext = getAudioContext();
4
- export let gain = 1;
5
- let output;
6
- $: {
7
- if (output) {
8
- output.gain.setTargetAtTime(gain, output.context.currentTime, 4e-3);
9
- }
10
- }
11
- const connect = getConnector((node) => {
12
- node.connect(output);
13
- return () => node.disconnect(output);
14
- });
15
- onMount(() => {
16
- const audioCTX = audioContext();
17
- output = audioCTX.createGain();
18
- return connect(output);
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
- <slot />
35
+ {@render children?.()}
@@ -1,18 +1,7 @@
1
- import { SvelteComponent } from "svelte";
2
- declare const __propDef: {
3
- props: {
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
- export {};
5
+ declare const AudioGain: import("svelte").Component<Props, {}, "">;
6
+ type AudioGain = ReturnType<typeof AudioGain>;
7
+ export default AudioGain;
@@ -1,94 +1,80 @@
1
- <script>export let position = [0, 0, 0];
2
- export let orientation = [0, 0, 0];
3
- $:
4
- positionX = position[0];
5
- $:
6
- positionY = position[1];
7
- $:
8
- positionZ = position[2];
9
- $:
10
- roll = orientation[0];
11
- $:
12
- pitch = orientation[1];
13
- $:
14
- yaw = orientation[2];
15
- const dot = ([i, j, k], [x, y, z]) => {
16
- return i * x + j * y + k * z;
17
- };
18
- const cross = ([i, j, k], [x, y, z]) => {
19
- return [
20
- j * z - k * y,
21
- (i * z - k * x) * -1,
22
- i * y - j * x
23
- ];
24
- };
25
- const buildQuaternion = (roll2, pitch2, yaw2) => {
26
- const rdRoll = roll2 / 360 * Math.PI;
27
- const rdPitch = pitch2 / 360 * Math.PI;
28
- const rdYaw = yaw2 / 360 * Math.PI;
29
- const x = Math.sin(rdRoll) * Math.cos(rdPitch) * Math.cos(rdYaw) - Math.cos(rdRoll) * Math.sin(rdPitch) * Math.sin(rdYaw);
30
- const y = Math.cos(rdRoll) * Math.sin(rdPitch) * Math.cos(rdYaw) + Math.sin(rdRoll) * Math.cos(rdPitch) * Math.sin(rdYaw);
31
- const z = Math.cos(rdRoll) * Math.cos(rdPitch) * Math.sin(rdYaw) - Math.sin(rdRoll) * Math.sin(rdPitch) * Math.cos(rdYaw);
32
- const w = Math.cos(rdRoll) * Math.cos(rdPitch) * Math.cos(rdYaw) + Math.sin(rdRoll) * Math.sin(rdPitch) * Math.sin(rdYaw);
33
- return [x, y, z, w];
34
- };
35
- const rotatedVector = ([i, j, k], [x, y, z, w]) => {
36
- const dotUVTimesTwo = dot([x, y, z], [i, j, k]) * 2;
37
- const WxWMinusDotUU = w * w - dot([x, y, z], [x, y, z]);
38
- const crossUV = cross([x, y, z], [i, j, k]);
39
- return [
40
- dotUVTimesTwo * x + WxWMinusDotUU * i + 2 * w * crossUV[0],
41
- dotUVTimesTwo * y + WxWMinusDotUU * j + 2 * w * crossUV[1],
42
- dotUVTimesTwo * z + WxWMinusDotUU * k + 2 * w * crossUV[2]
43
- ];
44
- };
45
- $:
46
- quaterion = buildQuaternion(roll, pitch, yaw);
47
- $:
48
- forward = rotatedVector([1, 0, 0], quaterion);
49
- $:
50
- up = rotatedVector([0, 1, 0], quaterion);
51
- import { getAudioContext } from "./context.js";
52
- import { onMount } from "svelte";
53
- const audioContext = getAudioContext();
54
- let audioCTX = null;
55
- $: {
56
- if (audioCTX)
57
- audioCTX.listener.positionX.value = positionX;
58
- }
59
- $: {
60
- if (audioCTX)
61
- audioCTX.listener.positionY.value = positionY;
62
- }
63
- $: {
64
- if (audioCTX)
65
- audioCTX.listener.positionZ.value = positionZ;
66
- }
67
- $: {
68
- if (audioCTX)
69
- audioCTX.listener.forwardX.value = forward[0];
70
- }
71
- $: {
72
- if (audioCTX)
73
- audioCTX.listener.forwardY.value = forward[1];
74
- }
75
- $: {
76
- if (audioCTX)
77
- audioCTX.listener.forwardZ.value = forward[2];
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
- import { SvelteComponent } from "svelte";
2
- declare const __propDef: {
3
- props: {
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
- export {};
5
+ declare const AudioListenerPosition: import("svelte").Component<Props, {}, "">;
6
+ type AudioListenerPosition = ReturnType<typeof AudioListenerPosition>;
7
+ export default AudioListenerPosition;
@@ -1,22 +1,35 @@
1
- <script>import { getAudioContext, getConnector } from "./context.js";
2
- import { onMount } from "svelte";
3
- const audioContext = getAudioContext();
4
- export let pan = 0;
5
- let output;
6
- $: {
7
- if (output) {
8
- output.pan.value = pan;
9
- }
10
- }
11
- const connect = getConnector((node) => {
12
- node.connect(output);
13
- return () => node.disconnect(output);
14
- });
15
- onMount(() => {
16
- const audioCtx = audioContext();
17
- output = audioCtx.createStereoPanner();
18
- return connect(output);
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
- <slot />
35
+ {@render children?.()}
@@ -1,18 +1,7 @@
1
- import { SvelteComponent } from "svelte";
2
- declare const __propDef: {
3
- props: {
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
- export {};
5
+ declare const AudioPanner: import("svelte").Component<Props, {}, "">;
6
+ type AudioPanner = ReturnType<typeof AudioPanner>;
7
+ export default AudioPanner;
@@ -1,47 +1,62 @@
1
- <script>import { getAudioContext, getConnector } from "./context.js";
2
- import { onMount } from "svelte";
3
- const audioContext = getAudioContext();
4
- export let volume = 1;
5
- export let audioBuffer;
6
- let output;
7
- let audioCTX;
8
- $: {
9
- if (output) {
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
- const connect = getConnector();
35
- onMount(() => {
36
- audioCTX = audioContext();
37
- output = audioCtx.createGain();
38
- const disconnect = connect(output);
39
- return () => {
40
- for (let node of playing) {
41
- node.stop();
42
- node.disconnect(output);
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
- disconnect();
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
- import { SvelteComponent } from "svelte";
2
- declare const __propDef: {
3
- props: {
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
- export {};
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>import { getAudioContext, getConnector } from "./context.js";
2
- import { onMount } from "svelte";
3
- const audioContext = getAudioContext();
4
- export let url;
5
- export let volume = 1;
6
- export let paused = true;
7
- export let playbackPosition;
8
- export let loop = false;
9
- export const playFromStart = () => {
10
- playbackPosition = 0;
11
- paused = false;
12
- };
13
- export const play = () => {
14
- paused = false;
15
- };
16
- export const pause = () => {
17
- paused = true;
18
- };
19
- let output;
20
- let sourceNode;
21
- let element;
22
- $: {
23
- if (output) {
24
- output.gain.setTargetAtTime(volume, output.context.currentTime, 4e-3);
25
- }
26
- }
27
- const connect = getConnector();
28
- onMount(() => {
29
- const audioCTX = audioContext();
30
- sourceNode = audioCTX.createMediaElementSource(element);
31
- output = audioCTX.createGain();
32
- sourceNode.connect(output);
33
- return connect(output);
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
- import { SvelteComponent } from "svelte";
2
- declare const __propDef: {
3
- props: {
4
- url: string;
5
- volume?: number | undefined;
6
- paused?: boolean | undefined;
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
- export {};
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;
@@ -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?: ((node: AudioNode) => DisconnectFunction) | undefined) => (node: AudioNode) => DisconnectFunction;
7
+ export declare const getConnector: (connect?: (node: AudioNode) => DisconnectFunction) => (node: AudioNode) => DisconnectFunction;