Skip to content

Open-source download manager & offline media toolbox for YouTube, music, social media, learning platforms & 1,800+ sites. Built with Tauri 2.0, Rust & Svelte.

Feat: reader Ctrl+wheel zoom, ebook deletion from library and music player progress bar fixes (#121, #123)

Tonhoea14a36bb0df
diff --git a/src/lib/reader-components/ReaderZoomIndicator.svelte b/src/lib/reader-components/ReaderZoomIndicator.svelte
new file mode 100644
index 00000000..fa9a2966
--- /dev/null
+++ b/src/lib/reader-components/ReaderZoomIndicator.svelte
@@ -0,0 +1,48 @@
+<script lang="ts">
+ let { label }: { label: string } = $props();
+</script>
+
+{#if label}
+ {#key label}
+ <div class="zoom-indicator mono" aria-live="polite">{label}</div>
+ {/key}
+{/if}
+
+<style>
+ .zoom-indicator {
+ position: fixed;
+ top: 64px;
+ left: 50%;
+ transform: translateX(-50%);
+ padding: 6px 14px;
+ background: var(--popup-bg, var(--bg-elevated, var(--bg)));
+ color: var(--text, var(--secondary));
+ border: 1px solid var(--border, var(--content-border));
+ border-radius: 999px;
+ font-size: 13px;
+ font-weight: 600;
+ box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
+ z-index: 60;
+ pointer-events: none;
+ animation: zoom-fade 1.2s ease-out forwards;
+ }
+ .mono {
+ font-family: var(--font-mono, "IBM Plex Mono", ui-monospace, monospace);
+ }
+ @keyframes zoom-fade {
+ 0% {
+ opacity: 1;
+ }
+ 70% {
+ opacity: 1;
+ }
+ 100% {
+ opacity: 0;
+ }
+ }
+ @media (prefers-reduced-motion: reduce) {
+ .zoom-indicator {
+ animation: none;
+ }
+ }
+</style>
diff --git a/src/lib/reader-zoom.ts b/src/lib/reader-zoom.ts
new file mode 100644
index 00000000..efd85692
--- /dev/null
+++ b/src/lib/reader-zoom.ts
@@ -0,0 +1,9 @@
+export function wheelZoomDirection(e: WheelEvent): -1 | 0 | 1 {
+ if (!e.ctrlKey && !e.metaKey) return 0;
+ if (e.deltaY === 0) return 0;
+ return e.deltaY < 0 ? 1 : -1;
+}
+
+export function clampZoom(value: number, min: number, max: number): number {
+ return Math.max(min, Math.min(max, value));
+}
diff --git a/src/lib/study-music-components/ProgressBar.svelte b/src/lib/study-music-components/ProgressBar.svelte
index 9c6f1e8b..8a26c264 100644
--- a/src/lib/study-music-components/ProgressBar.svelte
+++ b/src/lib/study-music-components/ProgressBar.svelte
@@ -1,5 +1,6 @@
<script lang="ts">
import { fmtSecondsToTime } from "$lib/study-music/format";
+ import { t } from "$lib/i18n";
type Props = {
current: number;
@@ -48,6 +49,20 @@
onSeek(dragValue * duration);
(e.currentTarget as HTMLElement).releasePointerCapture(e.pointerId);
}
+
+ function onKeyDown(e: KeyboardEvent) {
+ if (!duration || duration <= 0 || !Number.isFinite(duration)) return;
+ let target: number | null = null;
+ if (e.key === "ArrowLeft" || e.key === "ArrowDown") target = current - 5;
+ else if (e.key === "ArrowRight" || e.key === "ArrowUp") target = current + 5;
+ else if (e.key === "PageDown") target = current - 30;
+ else if (e.key === "PageUp") target = current + 30;
+ else if (e.key === "Home") target = 0;
+ else if (e.key === "End") target = duration;
+ if (target === null) return;
+ e.preventDefault();
+ onSeek(Math.max(0, Math.min(duration, target)));
+ }
</script>
<div class="progress-row">
@@ -56,14 +71,18 @@
{/if}
<div
class="track"
+ class:dragging
bind:this={trackEl}
onpointerdown={onPointerDown}
onpointermove={onPointerMove}
onpointerup={onPointerUp}
+ onkeydown={onKeyDown}
role="slider"
+ aria-label={$t("study.music.seek_aria") as string}
aria-valuemin="0"
aria-valuemax={duration || 0}
aria-valuenow={current}
+ aria-valuetext="{fmtSecondsToTime(displayTime)} / {fmtSecondsToTime(duration)}"
tabindex="0"
>
<div class="bar"></div>
@@ -135,7 +154,15 @@
transition: opacity 120ms ease, background 400ms ease;
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}
- .track:hover .thumb {
+ .track:hover .thumb,
+ .track:focus-visible .thumb,
+ .track.dragging .thumb {
opacity: 1;
}
+ @media (prefers-reduced-motion: reduce) {
+ .filled,
+ .thumb {
+ transition: none;
+ }
+ }
</style>
diff --git a/src/routes/study/music/+layout.svelte b/src/routes/study/music/+layout.svelte
index 88616356..d6a4e1ba 100644
--- a/src/routes/study/music/+layout.svelte
+++ b/src/routes/study/music/+layout.svelte
@@ -103,10 +103,10 @@
class="music-shell"
class:fullscreen={isFullscreen}
data-reduce-animations={reduceAnimationsAttr}
- style:--music-accent={paletteVars?.accent ?? 'transparent'}
+ style:--music-accent={paletteVars?.accent ?? null}
style:--music-accent-mid={paletteVars?.accentMid ?? 'transparent'}
style:--music-accent-soft={paletteVars?.accentSoft ?? 'transparent'}
- style:--music-highlight={paletteVars?.highlight ?? 'transparent'}
+ style:--music-highlight={paletteVars?.highlight ?? null}
style:--music-bg-tint={paletteVars?.bgTint ?? 'transparent'}
style:--music-scrubber-gradient={paletteVars?.scrubberGradient ?? null}
style:--accent={themeAccentOverride ?? null}
diff --git a/src/routes/study/read/+page.svelte b/src/routes/study/read/+page.svelte
index ed9bacb3..798953af 100644
--- a/src/routes/study/read/+page.svelte
+++ b/src/routes/study/read/+page.svelte
@@ -4,6 +4,7 @@
import { goto } from "$app/navigation";
import { pluginInvoke } from "$lib/plugin-invoke";
import { t } from "$lib/i18n";
+ import { showToast } from "$lib/stores/toast-store.svelte";
import SegmentedControl from "$lib/study-components/SegmentedControl.svelte";
import ConfirmDialog from "$lib/study-components/ConfirmDialog.svelte";
@@ -457,6 +458,50 @@
goto(`/study/read/${b.id}`);
}
+ function confirmDeleteBook(b: Book, ev: Event) {
+ ev.stopPropagation();
+ ev.preventDefault();
+ askConfirm(
+ $t("study.read.delete_book_title"),
+ $t("study.read.delete_book_confirm", { title: deriveTitle(b) }),
+ () => void doDeleteBook(b),
+ );
+ }
+
+ async function doDeleteBook(b: Book) {
+ try {
+ const res = await pluginInvoke<{ file_missing?: boolean }>(
+ "study",
+ "study:read:books:delete",
+ { bookId: b.id, deleteFile: true },
+ );
+ books = books.filter((x) => x.id !== b.id);
+ totalBooks = Math.max(0, totalBooks - 1);
+ byFormatCounts = {
+ ...byFormatCounts,
+ [b.format]: Math.max(0, (byFormatCounts[b.format] ?? 1) - 1),
+ };
+ if (tagBook?.id === b.id) tagBook = null;
+ if (enrichBook?.id === b.id) enrichBook = null;
+ showToast(
+ "success",
+ $t(
+ res?.file_missing
+ ? "study.read.delete_book_done_missing"
+ : "study.read.delete_book_done",
+ { title: deriveTitle(b) },
+ ),
+ );
+ } catch (e) {
+ showToast(
+ "error",
+ $t("study.read.delete_book_failed", {
+ err: e instanceof Error ? e.message : String(e),
+ }),
+ );
+ }
+ }
+
type Collection = { id: number; name: string; sort_order: number };
let collections = $state<Collection[]>([]);
let collectionKey = $state<string>("all");
@@ -1005,6 +1050,25 @@
<path d="M11 7v4l3 2" />
</svg>
</span>
+ <span
+ class="card-action-btn danger"
+ role="button"
+ tabindex="0"
+ title={$t("study.read.delete_book_title")}
+ aria-label={$t("study.read.delete_book_title")}
+ onclick={(e) => confirmDeleteBook(b, e)}
+ onkeydown={(e) => {
+ if (e.key === "Enter" || e.key === " ") {
+ confirmDeleteBook(b, e);
+ }
+ }}
+ >
+ <svg viewBox="0 0 24 24" width="12" height="12" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
+ <path d="M3 6h18"></path>
+ <path d="M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"></path>
+ <path d="M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6"></path>
+ </svg>
+ </span>
{#if collectionKey !== "all"}
<span
class="card-action-btn"
@@ -1549,6 +1613,10 @@
border-color: var(--accent);
background: color-mix(in oklab, var(--accent) 18%, var(--primary));
}
+ .card-action-btn.danger:hover {
+ color: var(--error);
+ border-color: var(--error);
+ }
.enrich-list {
list-style: none;
diff --git a/src/routes/study/read/[id]/+page.svelte b/src/routes/study/read/[id]/+page.svelte
index 9154ea45..b2b3c194 100644
--- a/src/routes/study/read/[id]/+page.svelte
+++ b/src/routes/study/read/[id]/+page.svelte
@@ -20,6 +20,8 @@
popReadingTheme,
} from "$lib/reader-theme";
import ReaderThemeMenu from "$lib/reader-components/ReaderThemeMenu.svelte";
+ import ReaderZoomIndicator from "$lib/reader-components/ReaderZoomIndicator.svelte";
+ import { wheelZoomDirection } from "$lib/reader-zoom";
import "$lib/reader-theme.css";
import EpubReader from "./EpubReader.svelte";
import type {
@@ -1333,13 +1335,61 @@
}
}
+ const PDF_ZOOM_KEY = "study.read.pdf_zoom_dpi";
+ const PDF_ZOOM_MIN = 48;
+ const PDF_ZOOM_MAX = 300;
+ const PDF_ZOOM_BASE = 120;
+ let zoomLabel = $state("");
+ let zoomLabelTimer: ReturnType<typeof setTimeout> | null = null;
+ let wheelZoomTarget: number | null = null;
+ let wheelZoomTimer: ReturnType<typeof setTimeout> | null = null;
+
+ function loadZoomDpi() {
+ if (typeof localStorage === "undefined") return;
+ const raw = Number(localStorage.getItem(PDF_ZOOM_KEY));
+ if (Number.isFinite(raw) && raw >= PDF_ZOOM_MIN && raw <= PDF_ZOOM_MAX) {
+ zoomDpi = raw;
+ }
+ }
+
+ $effect(() => {
+ if (typeof localStorage !== "undefined") {
+ localStorage.setItem(PDF_ZOOM_KEY, String(zoomDpi));
+ }
+ });
+
+ function flashZoomLabel(text: string) {
+ zoomLabel = text;
+ if (zoomLabelTimer) clearTimeout(zoomLabelTimer);
+ zoomLabelTimer = setTimeout(() => (zoomLabel = ""), 1200);
+ }
+
+ function onWheelZoom(e: WheelEvent) {
+ if (!meta) return;
+ const dir = wheelZoomDirection(e);
+ if (dir === 0) return;
+ e.preventDefault();
+ const base = wheelZoomTarget ?? zoomDpi;
+ const next = Math.max(PDF_ZOOM_MIN, Math.min(PDF_ZOOM_MAX, base + dir * 15));
+ wheelZoomTarget = next;
+ flashZoomLabel(`${Math.round((next / PDF_ZOOM_BASE) * 100)}%`);
+ if (wheelZoomTimer) clearTimeout(wheelZoomTimer);
+ wheelZoomTimer = setTimeout(() => {
+ const target = wheelZoomTarget;
+ wheelZoomTarget = null;
+ if (target === null || target === zoomDpi) return;
+ zoomDpi = target;
+ if (viewMode === "paged") void renderCurrent();
+ }, 160);
+ }
+
function zoomIn() {
- zoomDpi = Math.min(300, zoomDpi + 30);
+ zoomDpi = Math.min(PDF_ZOOM_MAX, zoomDpi + 30);
renderCurrent();
}
function zoomOut() {
- zoomDpi = Math.max(48, zoomDpi - 30);
+ zoomDpi = Math.max(PDF_ZOOM_MIN, zoomDpi - 30);
renderCurrent();
}
@@ -1514,19 +1564,23 @@
cursorLine = getCursorLine();
viewMode = getViewMode();
loadInkPreferences();
+ loadZoomDpi();
pushReadingTheme();
loadBook();
window.addEventListener("keydown", onKey);
window.addEventListener("mousemove", onMouseMove);
+ window.addEventListener("wheel", onWheelZoom, { passive: false });
return () => {
window.removeEventListener("keydown", onKey);
window.removeEventListener("mousemove", onMouseMove);
+ window.removeEventListener("wheel", onWheelZoom);
};
});
onDestroy(() => {
window.removeEventListener("keydown", onKey);
window.removeEventListener("mousemove", onMouseMove);
+ window.removeEventListener("wheel", onWheelZoom);
applyFocusMode(false);
popReadingTheme();
void session?.stop(false);
@@ -1900,6 +1954,7 @@
{#if exportToast}
<div class="export-toast">{exportToast}</div>
{/if}
+ <ReaderZoomIndicator label={zoomLabel} />
{#if loadingBook}
<p class="state">{$t("study.read.loading_book")}</p>
diff --git a/src/routes/study/read/[id]/CbzReader.svelte b/src/routes/study/read/[id]/CbzReader.svelte
index cd57bf7f..12691452 100644
--- a/src/routes/study/read/[id]/CbzReader.svelte
+++ b/src/routes/study/read/[id]/CbzReader.svelte
@@ -15,6 +15,8 @@
popReadingTheme,
} from "$lib/reader-theme";
import ReaderThemeMenu from "$lib/reader-components/ReaderThemeMenu.svelte";
+ import ReaderZoomIndicator from "$lib/reader-components/ReaderZoomIndicator.svelte";
+ import { wheelZoomDirection } from "$lib/reader-zoom";
import "$lib/reader-theme.css";
type Book = {
@@ -66,6 +68,47 @@
}
});
+ const CBZ_ZOOM_MIN = 0.5;
+ const CBZ_ZOOM_MAX = 3;
+ let imageZoom = $state(1);
+ let zoomLabel = $state("");
+ let zoomLabelTimer: ReturnType<typeof setTimeout> | null = null;
+
+ function zoomKey(bookId: number): string {
+ return `study.read.cbz.zoom.${bookId}`;
+ }
+
+ $effect(() => {
+ if (typeof localStorage === "undefined") return;
+ const raw = Number(localStorage.getItem(zoomKey(book.id)));
+ if (Number.isFinite(raw) && raw >= CBZ_ZOOM_MIN && raw <= CBZ_ZOOM_MAX) {
+ imageZoom = raw;
+ }
+ });
+
+ function flashZoomLabel(value: number) {
+ zoomLabel = `${Math.round(value * 100)}%`;
+ if (zoomLabelTimer) clearTimeout(zoomLabelTimer);
+ zoomLabelTimer = setTimeout(() => (zoomLabel = ""), 1200);
+ }
+
+ function onWheelZoom(e: WheelEvent) {
+ const dir = wheelZoomDirection(e);
+ if (dir === 0) return;
+ e.preventDefault();
+ const next = Math.max(
+ CBZ_ZOOM_MIN,
+ Math.min(CBZ_ZOOM_MAX, Math.round((imageZoom + dir * 0.1) * 10) / 10),
+ );
+ if (next !== imageZoom) {
+ imageZoom = next;
+ if (typeof localStorage !== "undefined") {
+ localStorage.setItem(zoomKey(book.id), String(next));
+ }
+ }
+ flashZoomLabel(next);
+ }
+
function rtlKey(bookId: number): string {
return `study.read.cbz.rtl.${bookId}`;
}
@@ -196,11 +239,13 @@
loadBook();
window.addEventListener("keydown", onKey);
window.addEventListener("mousemove", onMouseMove);
+ window.addEventListener("wheel", onWheelZoom, { passive: false });
});
onDestroy(() => {
window.removeEventListener("keydown", onKey);
window.removeEventListener("mousemove", onMouseMove);
+ window.removeEventListener("wheel", onWheelZoom);
applyFocusMode(false);
popReadingTheme();
void session?.stop(false);
@@ -331,15 +376,17 @@
src={convertFileSrc(page.abs_path)}
alt="page {page.index + 1}"
loading="lazy"
+ style:zoom={imageZoom}
/>
{/each}
</div>
</div>
{:else if meta && imageSrc}
<div class="viewer" class:fit-width={fitMode === "width"}>
- <img class="page-image" src={imageSrc} alt="page {pageIdx + 1}" />
+ <img class="page-image" src={imageSrc} alt="page {pageIdx + 1}" style:zoom={imageZoom} />
</div>
{/if}
+ <ReaderZoomIndicator label={zoomLabel} />
{#if cursorLine && cursorY > 0}
<div class="reader-cursor-line" style:top="{cursorY}px"></div>
{/if}
@@ -484,6 +531,10 @@
box-shadow: 0 4px 18px rgba(0, 0, 0, 0.4);
}
+ .viewer > .page-image {
+ margin: auto;
+ }
+
.viewer.fit-width .page-image {
max-height: none;
max-width: 100%;
diff --git a/src/routes/study/read/[id]/EpubReader.svelte b/src/routes/study/read/[id]/EpubReader.svelte
index d3223a61..869857ae 100644
--- a/src/routes/study/read/[id]/EpubReader.svelte
+++ b/src/routes/study/read/[id]/EpubReader.svelte
@@ -18,6 +18,7 @@
import ReaderTypographyMenu from "$lib/reader-components/ReaderTypographyMenu.svelte";
import {
DEFAULT_TYPOGRAPHY,
+ FONT_LIMITS,
applyIframeTypography,
loadBookSettings,
loadGlobal,
@@ -25,6 +26,8 @@
saveGlobal,
type Typography,
} from "$lib/reader-typography";
+ import ReaderZoomIndicator from "$lib/reader-components/ReaderZoomIndicator.svelte";
+ import { wheelZoomDirection } from "$lib/reader-zoom";
import {
applyHighlight,
captureSelection,
@@ -102,6 +105,29 @@
});
let iframeMouseUpHandler: ((e: MouseEvent) => void) | null = null;
+ let iframeWheelHandler: ((e: WheelEvent) => void) | null = null;
+ let zoomLabel = $state("");
+ let zoomLabelTimer: ReturnType<typeof setTimeout> | null = null;
+
+ function flashZoomLabel(size: number) {
+ zoomLabel = `${Math.round((size / DEFAULT_TYPOGRAPHY.font_size) * 100)}%`;
+ if (zoomLabelTimer) clearTimeout(zoomLabelTimer);
+ zoomLabelTimer = setTimeout(() => (zoomLabel = ""), 1200);
+ }
+
+ function onWheelZoom(e: WheelEvent) {
+ const dir = wheelZoomDirection(e);
+ if (dir === 0) return;
+ e.preventDefault();
+ const next = Math.max(
+ FONT_LIMITS.size.min,
+ Math.min(FONT_LIMITS.size.max, typography.font_size + dir * FONT_LIMITS.size.step),
+ );
+ if (next !== typography.font_size) {
+ typography = { ...typography, font_size: next };
+ }
+ flashZoomLabel(next);
+ }
function currentChapter() {
if (!meta) return null;
@@ -149,6 +175,13 @@
}
iframeMouseUpHandler = (_e) => handleIframeMouseUp();
frameEl.contentDocument.addEventListener("mouseup", iframeMouseUpHandler);
+ if (iframeWheelHandler) {
+ frameEl.contentDocument.removeEventListener("wheel", iframeWheelHandler);
+ }
+ iframeWheelHandler = (e) => onWheelZoom(e);
+ frameEl.contentDocument.addEventListener("wheel", iframeWheelHandler, {
+ passive: false,
+ });
}
}
@@ -326,11 +359,13 @@
loadBook();
window.addEventListener("keydown", onKey);
window.addEventListener("mousemove", onMouseMove);
+ window.addEventListener("wheel", onWheelZoom, { passive: false });
});
onDestroy(() => {
window.removeEventListener("keydown", onKey);
window.removeEventListener("mousemove", onMouseMove);
+ window.removeEventListener("wheel", onWheelZoom);
applyFocusMode(false);
popReadingTheme();
void session?.stop(false);
@@ -428,6 +463,8 @@
{/if}
</header>
+ <ReaderZoomIndicator label={zoomLabel} />
+
{#if cursorLine && cursorY > 0}
<div class="reader-cursor-line" style:top="{cursorY}px"></div>
{/if}
diff --git a/src/routes/study/read/[id]/HtmlReader.svelte b/src/routes/study/read/[id]/HtmlReader.svelte
index 6750a1e6..1aa22241 100644
--- a/src/routes/study/read/[id]/HtmlReader.svelte
+++ b/src/routes/study/read/[id]/HtmlReader.svelte
@@ -18,6 +18,7 @@
import ReaderTypographyMenu from "$lib/reader-components/ReaderTypographyMenu.svelte";
import {
DEFAULT_TYPOGRAPHY,
+ FONT_LIMITS,
applyIframeTypography,
loadBookSettings,
loadGlobal,
@@ -25,6 +26,8 @@
saveGlobal,
type Typography,
} from "$lib/reader-typography";
+ import ReaderZoomIndicator from "$lib/reader-components/ReaderZoomIndicator.svelte";
+ import { wheelZoomDirection } from "$lib/reader-zoom";
import "$lib/reader-theme.css";
type Book = {
@@ -86,6 +89,41 @@
cursorY = e.clientY;
}
+ let iframeWheelHandler: ((e: WheelEvent) => void) | null = null;
+ let zoomLabel = $state("");
+ let zoomLabelTimer: ReturnType<typeof setTimeout> | null = null;
+
+ function flashZoomLabel(size: number) {
+ zoomLabel = `${Math.round((size / DEFAULT_TYPOGRAPHY.font_size) * 100)}%`;
+ if (zoomLabelTimer) clearTimeout(zoomLabelTimer);
+ zoomLabelTimer = setTimeout(() => (zoomLabel = ""), 1200);
+ }
+
+ function onWheelZoom(e: WheelEvent) {
+ const dir = wheelZoomDirection(e);
+ if (dir === 0) return;
+ e.preventDefault();
+ const next = Math.max(
+ FONT_LIMITS.size.min,
+ Math.min(FONT_LIMITS.size.max, typography.font_size + dir * FONT_LIMITS.size.step),
+ );
+ if (next !== typography.font_size) {
+ typography = { ...typography, font_size: next };
+ }
+ flashZoomLabel(next);
+ }
+
+ function onIframeLoaded() {
+ applyIframeTypography(frameEl, typography);
+ const doc = frameEl?.contentDocument;
+ if (!doc) return;
+ if (iframeWheelHandler) {
+ doc.removeEventListener("wheel", iframeWheelHandler);
+ }
+ iframeWheelHandler = (e) => onWheelZoom(e);
+ doc.addEventListener("wheel", iframeWheelHandler, { passive: false });
+ }
+
async function loadBook() {
try {
meta = await pluginInvoke<OpenResult>("study", "study:read:html:open", {
@@ -122,11 +160,13 @@
loadBook();
window.addEventListener("keydown", onKey);
window.addEventListener("mousemove", onMouseMove);
+ window.addEventListener("wheel", onWheelZoom, { passive: false });
});
onDestroy(() => {
window.removeEventListener("keydown", onKey);
window.removeEventListener("mousemove", onMouseMove);
+ window.removeEventListener("wheel", onWheelZoom);
applyFocusMode(false);
popReadingTheme();
void session?.stop(false);
@@ -231,10 +271,11 @@
title={book.title ?? "html"}
sandbox="allow-same-origin"
bind:this={frameEl}
- onload={() => applyIframeTypography(frameEl, typography)}
+ onload={onIframeLoaded}
></iframe>
</div>
{/if}
+ <ReaderZoomIndicator label={zoomLabel} />
{#if cursorLine && cursorY > 0}
<div class="reader-cursor-line" style:top="{cursorY}px"></div>
{/if}
diff --git a/src/routes/study/read/[id]/TxtReader.svelte b/src/routes/study/read/[id]/TxtReader.svelte
index c1def333..5c8a38f6 100644
--- a/src/routes/study/read/[id]/TxtReader.svelte
+++ b/src/routes/study/read/[id]/TxtReader.svelte
@@ -18,6 +18,7 @@
import ReaderTypographyMenu from "$lib/reader-components/ReaderTypographyMenu.svelte";
import {
DEFAULT_TYPOGRAPHY,
+ FONT_LIMITS,
fontStack,
loadBookSettings,
loadGlobal,
@@ -25,6 +26,8 @@
saveGlobal,
type Typography,
} from "$lib/reader-typography";
+ import ReaderZoomIndicator from "$lib/reader-components/ReaderZoomIndicator.svelte";
+ import { wheelZoomDirection } from "$lib/reader-zoom";
import "$lib/reader-theme.css";
type Book = {
@@ -166,6 +169,29 @@
typography = { ...typography, font_size: Math.max(12, typography.font_size - 1) };
}
+ let zoomLabel = $state("");
+ let zoomLabelTimer: ReturnType<typeof setTimeout> | null = null;
+
+ function flashZoomLabel(size: number) {
+ zoomLabel = `${Math.round((size / DEFAULT_TYPOGRAPHY.font_size) * 100)}%`;
+ if (zoomLabelTimer) clearTimeout(zoomLabelTimer);
+ zoomLabelTimer = setTimeout(() => (zoomLabel = ""), 1200);
+ }
+
+ function onWheelZoom(e: WheelEvent) {
+ const dir = wheelZoomDirection(e);
+ if (dir === 0) return;
+ e.preventDefault();
+ const next = Math.max(
+ FONT_LIMITS.size.min,
+ Math.min(FONT_LIMITS.size.max, typography.font_size + dir * FONT_LIMITS.size.step),
+ );
+ if (next !== typography.font_size) {
+ typography = { ...typography, font_size: next };
+ }
+ flashZoomLabel(next);
+ }
+
async function openExternal() {
try {
await invoke("open_path_default", { path: book.file_path });
@@ -182,11 +208,13 @@
loadBook();
window.addEventListener("keydown", onKey);
window.addEventListener("mousemove", onMouseMove);
+ window.addEventListener("wheel", onWheelZoom, { passive: false });
});
onDestroy(() => {
window.removeEventListener("keydown", onKey);
window.removeEventListener("mousemove", onMouseMove);
+ window.removeEventListener("wheel", onWheelZoom);
applyFocusMode(false);
popReadingTheme();
void session?.stop(false);
@@ -313,6 +341,7 @@
</div>
</div>
{/if}
+ <ReaderZoomIndicator label={zoomLabel} />
{#if cursorLine && cursorY > 0}
<div class="reader-cursor-line" style:top="{cursorY}px"></div>
{/if}