Update Docs Site (#44)

This commit is contained in:
Ollie Taylor
2023-07-11 22:13:18 +01:00
committed by GitHub
parent 3cb5e8eb46
commit 29ef65733e
80 changed files with 1624 additions and 2381 deletions
+5 -4
View File
@@ -1,8 +1,8 @@
<script>
import { onMount } from 'svelte';
import { get } from 'svelte/store';
import { announce } from '../internal';
import { user_preferences } from '../user';
import { announce } from '../utility';
import { audio_element } from './stores/audio-element';
$: $audio_element;
@@ -24,9 +24,10 @@
<svelte:head>
<style>
:root {
--svpod--font: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI',
Roboto, 'Helvetica Neue', Arial, 'Noto Sans', sans-serif, 'Apple Color Emoji',
'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji';
--svpod--font: ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial,
'Noto Sans', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji',
'Segoe UI Symbol', 'Noto Color Emoji';
--svpod--surface--darker: rgb(0, 0, 0);
--svpod--surface--base: rgb(40, 40, 40);
+3 -1
View File
@@ -17,7 +17,9 @@
$: is_playing = $episode_audio?.is_paused === false;
$: current_time = $episode_progress?.current_time || 0;
$: duration = $episode_audio?.duration || 0;
$: timestamp_hours = Boolean($episode_audio?.duration && $episode_audio.duration >= 3600);
$: timestamp_hours = Boolean(
$episode_audio?.duration && $episode_audio.duration >= 3600,
);
$: timestamp = duration && seconds_to_timestamp(duration);
onMount(() => {
+1 -1
View File
@@ -1,6 +1,6 @@
<script>
import { episode_audio, episode_progress } from '../audio';
import { announce } from '../utility';
import { announce } from '../internal';
export let step = 10;
+4
View File
@@ -39,6 +39,10 @@ export const audio_element = readable(undefined, (set) => {
if (!existing_element) document.body.appendChild(el);
/*
BUG: This is a hack to get around poor types.
The input and output types are correct, so this is safe for now.
*/
// @ts-expect-error - I'm not sure how to fix this using JSDOC
set(el);
});
+29 -25
View File
@@ -1,7 +1,7 @@
import clamp from 'just-clamp';
import { derived, get } from 'svelte/store';
import { user_preferences, user_progress } from '../../user';
import { announce } from '../../utility';
import { announce } from '../../internal';
import { audio_element } from './audio-element';
import { episode_details } from './episode-details';
@@ -29,32 +29,35 @@ const default_episode_state = {
* Episode state store
* @type {import('svelte/store').Readable<EpisodeState | null>}
*/
const episode_state = derived([audio_element, episode_details], ([$audio, $details], set) => {
if (!$audio) return set(null);
const episode_state = derived(
[audio_element, episode_details],
([$audio, $details], set) => {
if (!$audio) return set(null);
function set_value() {
if (!$audio?.src) return null;
set({
...default_episode_state,
src: $audio.src,
duration: $audio.duration,
details: $details,
will_autoplay: $audio.autoplay,
is_paused: $audio.paused,
start_at: user_progress.get($audio.src) ?? 0,
});
}
function set_value() {
if (!$audio?.src) return null;
set({
...default_episode_state,
src: $audio.src,
duration: $audio.duration,
details: $details,
will_autoplay: $audio.autoplay,
is_paused: $audio.paused,
start_at: user_progress.get($audio.src) ?? 0,
});
}
$audio.addEventListener('loadeddata', set_value);
$audio.addEventListener('pause', set_value);
$audio.addEventListener('playing', set_value);
$audio.addEventListener('loadeddata', set_value);
$audio.addEventListener('pause', set_value);
$audio.addEventListener('playing', set_value);
return () => {
$audio.removeEventListener('loadeddata', set_value);
$audio.removeEventListener('pause', set_value);
$audio.removeEventListener('playing', set_value);
};
});
return () => {
$audio.removeEventListener('loadeddata', set_value);
$audio.removeEventListener('pause', set_value);
$audio.removeEventListener('playing', set_value);
};
},
);
/**
* @typedef {'toggle' | 'set'} HANDLE_TYPE
@@ -68,7 +71,8 @@ const episode_state = derived([audio_element, episode_details], ([$audio, $detai
*/
const use_element = (action) => {
const el = get(audio_element);
if (!el) throw announce.warn(`could not ${action} :: no audio element exists yet`);
if (!el)
throw announce.warn(`could not ${action} :: no audio element exists yet`);
return el;
};
+7
View File
@@ -0,0 +1,7 @@
/**
* Utility functions module.
* @module internal
*/
export * from './announce';
export * from './use-url';
+8 -2
View File
@@ -17,7 +17,10 @@ const DEFAULT_USER_PREFERENCES = { playback_rate: 1, volume: 1 };
* The user preferences store
* @type {import('svelte/store').Writable<UserPreferences>}
*/
const USER_PREFERENCES_STORE = persisted('USER_PREFERENCE', DEFAULT_USER_PREFERENCES);
const USER_PREFERENCES_STORE = persisted(
'USER_PREFERENCE',
DEFAULT_USER_PREFERENCES,
);
/**
* Sets the playback rate for the user
@@ -26,7 +29,10 @@ const USER_PREFERENCES_STORE = persisted('USER_PREFERENCE', DEFAULT_USER_PREFERE
*/
const set_playback_rate = (value) => {
const playback_rate = clamp(value, 0.5, 5);
return USER_PREFERENCES_STORE.update((prefs) => ({ ...prefs, playback_rate }));
return USER_PREFERENCES_STORE.update((prefs) => ({
...prefs,
playback_rate,
}));
};
/**
+7 -3
View File
@@ -1,7 +1,7 @@
import { persisted } from 'svelte-local-storage-store';
import { get } from 'svelte/store';
import { episode_audio, episode_progress } from '../audio';
import { announce, use_url } from '../utility';
import { use_url, announce } from '../internal';
/**
* User progress object type.
@@ -34,7 +34,10 @@ const save_user_progress = () => {
const pathname = use_url(audio.src).pathname;
const current_time = get(episode_progress).current_time;
USER_PROGRESS_STORE.update((prev) => ({ ...prev, [pathname]: current_time }));
USER_PROGRESS_STORE.update((prev) => ({
...prev,
[pathname]: current_time,
}));
};
/**
@@ -59,7 +62,8 @@ const get_user_progress = (src) => {
* @function
* @returns {void}
*/
const clear_user_progress = () => USER_PROGRESS_STORE.set(DEFAULT_USER_PROGRESS);
const clear_user_progress = () =>
USER_PROGRESS_STORE.set(DEFAULT_USER_PROGRESS);
/**
* User progress object
-2
View File
@@ -3,6 +3,4 @@
* @module utility
*/
export * from './announce';
export * from './seconds-to-timestamp';
export * from './use-url';