From 3f6bd71aaac4277d046485fe8ea2a791ea089cd8 Mon Sep 17 00:00:00 2001
From: Wolfgang Müller
Date: Tue, 18 Feb 2025 15:51:14 +0100
Subject: frontend: Migrate PageView to Svelte 5

---
 frontend/src/lib/reader/Reader.svelte | 73 ++---------------------------------
 1 file changed, 3 insertions(+), 70 deletions(-)

(limited to 'frontend/src/lib/reader/Reader.svelte')

diff --git a/frontend/src/lib/reader/Reader.svelte b/frontend/src/lib/reader/Reader.svelte
index b5cc725..2e7e851 100644
--- a/frontend/src/lib/reader/Reader.svelte
+++ b/frontend/src/lib/reader/Reader.svelte
@@ -1,72 +1,10 @@
-<script lang="ts" module>
-	import { Layout, type PageFragment } from '$gql/graphql';
-	import { getContext, setContext } from 'svelte';
-
-	export interface Chunk {
-		main: PageFragment;
-		secondary?: PageFragment;
-		index: number;
-	}
-
-	class ReaderContext {
-		visible = $state(false);
-		sidebar = $state(false);
-		pages: PageFragment[] = $state([]);
-		page = $state(0);
-
-		open = (page: number) => {
-			this.page = page;
-			this.visible = true;
-		};
-	}
-
-	export function initReaderContext() {
-		return setContext<ReaderContext>('reader', new ReaderContext());
-	}
-
-	export function getReaderContext() {
-		return getContext<ReaderContext>('reader');
-	}
-
-	export function partition(pages: PageFragment[], layout: Layout): [Chunk[], number[]] {
-		const single = layout === Layout.Single;
-		const offset = layout === Layout.DoubleOffset;
-
-		const chunks: Chunk[] = [];
-		const lookup: number[] = Array<number>(pages.length);
-
-		for (let chunkIndex = 0, pageIndex = 0; pageIndex < pages.length; chunkIndex++) {
-			const wide = () => pages[pageIndex].image.aspectRatio > 1;
-
-			const nextPage = () => {
-				lookup[pageIndex] = chunkIndex;
-				return pages[pageIndex++];
-			};
-
-			const offsetFirst = pageIndex === 0 && offset;
-			const full = single || wide() || offsetFirst;
-
-			const chunk: Chunk = { index: pageIndex, main: nextPage() };
-
-			if (!full && pageIndex < pages.length) {
-				if (!wide()) {
-					chunk.secondary = nextPage();
-				}
-			}
-
-			chunks.push(chunk);
-		}
-		return [chunks, lookup];
-	}
-</script>
-
 <script lang="ts">
 	import { trapFocus } from '$lib/Actions';
+	import { getReaderContext } from '$lib/Reader.svelte';
 	import { fadeDefault, slideXDefault } from '$lib/Transitions';
 	import type { Snippet } from 'svelte';
 	import { fade, slide } from 'svelte/transition';
 	import CloseReaderButton from './components/CloseReaderButton.svelte';
-	import PageIndicator from './components/PageIndicator.svelte';
 	import ReaderMenuButton from './components/ReaderMenuButton.svelte';
 
 	let { sidebar, children }: { sidebar?: Snippet; children?: Snippet } = $props();
@@ -77,7 +15,7 @@
 {#if reader.visible}
 	<div
 		role="dialog"
-		class="fixed bottom-0 left-0 right-0 top-0 z-10 flex h-full w-full bg-black"
+		class="fixed top-0 right-0 bottom-0 left-0 z-10 flex h-full w-full bg-black"
 		transition:fade={fadeDefault}
 		use:trapFocus
 	>
@@ -95,13 +33,8 @@
 				{/if}
 				<CloseReaderButton />
 			</div>
-			<div class="absolute bottom-0 right-0 z-10 flex p-1 text-lg">
-				<PageIndicator />
-			</div>
 
-			<div class="flex grow">
-				{@render children?.()}
-			</div>
+			{@render children?.()}
 		</main>
 	</div>
 {/if}
-- 
cgit v1.2.3-2-gb3c3

