Add exSTATic support

This commit is contained in:
ZXY101
2024-03-09 12:02:13 +02:00
parent 18f5e3ae46
commit e511a0a39b
5 changed files with 54 additions and 5 deletions

View File

@@ -8,7 +8,7 @@
zoomFitToScreen zoomFitToScreen
} from '$lib/panzoom'; } from '$lib/panzoom';
import { progress, settings, updateProgress, type VolumeSettings } from '$lib/settings'; import { progress, settings, updateProgress, type VolumeSettings } from '$lib/settings';
import { clamp, debounce } from '$lib/util'; import { clamp, debounce, fireExstaticEvent } from '$lib/util';
import { Input, Popover, Range, Spinner } from 'flowbite-svelte'; import { Input, Popover, Range, Spinner } from 'flowbite-svelte';
import MangaPage from './MangaPage.svelte'; import MangaPage from './MangaPage.svelte';
import { import {
@@ -22,6 +22,7 @@
import SettingsButton from './SettingsButton.svelte'; import SettingsButton from './SettingsButton.svelte';
import { getCharCount } from '$lib/util/count-chars'; import { getCharCount } from '$lib/util/count-chars';
import QuickActions from './QuickActions.svelte'; import QuickActions from './QuickActions.svelte';
import { beforeNavigate } from '$app/navigation';
// TODO: Refactor this whole mess // TODO: Refactor this whole mess
export let volumeSettings: VolumeSettings; export let volumeSettings: VolumeSettings;
@@ -65,10 +66,12 @@
return; return;
} }
const pageClamped = clamp(newPage, 1, pages?.length); const pageClamped = clamp(newPage, 1, pages?.length);
const charCount = getCharCount(pages, pageClamped) || 0;
updateProgress( updateProgress(
volume.mokuroData.volume_uuid, volume.mokuroData.volume_uuid,
pageClamped, pageClamped,
getCharCount(pages, pageClamped) || 0, charCount,
pageClamped === pages.length || pageClamped === pages.length - 1 pageClamped === pages.length || pageClamped === pages.length - 1
); );
zoomDefault(); zoomDefault();
@@ -198,6 +201,28 @@
} }
} }
} }
$: {
if (volume) {
fireExstaticEvent('mokuro-reader:page.change', {
title: volume.mokuroData.title,
volumeName: volume.mokuroData.volume,
currentCharCount: charCount || 0,
currentPageNum: page
});
}
}
beforeNavigate(() => {
if (volume) {
fireExstaticEvent('mokuro-reader:reader.closed', {
title: volume.mokuroData.title,
volumeName: volume.mokuroData.volume,
currentCharCount: charCount || 0,
currentPageNum: page
});
}
});
</script> </script>
<svelte:window <svelte:window

View File

@@ -3,11 +3,18 @@
import { isReader } from '$lib/util'; import { isReader } from '$lib/util';
import { Button } from 'flowbite-svelte'; import { Button } from 'flowbite-svelte';
export let hidden = false;
function onClose() {
hidden = true;
history.back();
}
</script> </script>
{#if isReader()} {#if isReader()}
<div class="flex flex-col gap-2"> <div class="flex flex-col gap-2">
<Button color="alternative" on:click={toggleFullScreen}>Toggle fullscreen</Button> <Button color="alternative" on:click={toggleFullScreen}>Toggle fullscreen</Button>
<Button color="alternative" on:click={() => history.back()}>Close reader</Button> <Button color="alternative" on:click={onClose}>Close reader</Button>
</div> </div>
{/if} {/if}

View File

@@ -56,7 +56,7 @@
</div> </div>
<div class="flex flex-col gap-5"> <div class="flex flex-col gap-5">
<Accordion flush> <Accordion flush>
<QuickAccess /> <QuickAccess bind:hidden />
{#if isReader()} {#if isReader()}
<VolumeSettings /> <VolumeSettings />
{:else} {:else}

View File

@@ -12,7 +12,8 @@ import type { Page } from "$lib/types";
export function countChars(line: string) { export function countChars(line: string) {
const isNotJapaneseRegex = /[^0-9A-Z-------\p{Radical}\p{Unified_Ideograph}]+/gimu const isNotJapaneseRegex = /[^0-9A-Z-------\p{Radical}\p{Unified_Ideograph}]+/gimu
const cleaned = line.replace(isNotJapaneseRegex, '') const cleaned = line.replace(isNotJapaneseRegex, '')
return cleaned.length;
return Array.from(cleaned).length;
} }
export function getCharCount(pages: Page[], currentPage?: number) { export function getCharCount(pages: Page[], currentPage?: number) {

View File

@@ -1,6 +1,7 @@
import { page } from "$app/stores"; import { page } from "$app/stores";
import { get } from "svelte/store"; import { get } from "svelte/store";
import { showSnackbar } from "./snackbar"; import { showSnackbar } from "./snackbar";
import { browser } from "$app/environment";
export function clamp(num: number, min: number, max: number) { export function clamp(num: number, min: number, max: number) {
return Math.min(Math.max(num, min), max); return Math.min(Math.max(num, min), max);
@@ -30,4 +31,19 @@ export function toClipboard() {
'pip3 install git+https://github.com/kha-white/mokuro.git@web-reader' 'pip3 install git+https://github.com/kha-white/mokuro.git@web-reader'
); );
showSnackbar('Copied to clipboard'); showSnackbar('Copied to clipboard');
}
type ExtaticPayload = {
title: string;
volumeName: string;
currentCharCount: number;
currentPageNum: number;
}
type ExtaticEvent = 'mokuro-reader:page.change' | 'mokuro-reader:reader.closed'
export function fireExstaticEvent(event: ExtaticEvent, payload: ExtaticPayload) {
if (browser) {
document.dispatchEvent(new CustomEvent(event, { detail: payload }))
}
} }