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
} from '$lib/panzoom';
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 MangaPage from './MangaPage.svelte';
import {
@@ -22,6 +22,7 @@
import SettingsButton from './SettingsButton.svelte';
import { getCharCount } from '$lib/util/count-chars';
import QuickActions from './QuickActions.svelte';
import { beforeNavigate } from '$app/navigation';
// TODO: Refactor this whole mess
export let volumeSettings: VolumeSettings;
@@ -65,10 +66,12 @@
return;
}
const pageClamped = clamp(newPage, 1, pages?.length);
const charCount = getCharCount(pages, pageClamped) || 0;
updateProgress(
volume.mokuroData.volume_uuid,
pageClamped,
getCharCount(pages, pageClamped) || 0,
charCount,
pageClamped === pages.length || pageClamped === pages.length - 1
);
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>
<svelte:window

View File

@@ -3,11 +3,18 @@
import { isReader } from '$lib/util';
import { Button } from 'flowbite-svelte';
export let hidden = false;
function onClose() {
hidden = true;
history.back();
}
</script>
{#if isReader()}
<div class="flex flex-col gap-2">
<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>
{/if}

View File

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

View File

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

View File

@@ -1,6 +1,7 @@
import { page } from "$app/stores";
import { get } from "svelte/store";
import { showSnackbar } from "./snackbar";
import { browser } from "$app/environment";
export function clamp(num: number, min: number, max: number) {
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'
);
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 }))
}
}