From 157bf734c77cf4fbf61a4d81ecf79bedd2eb87b1 Mon Sep 17 00:00:00 2001 From: John O'Keefe Date: Sun, 12 Apr 2026 12:10:02 -0400 Subject: [PATCH] feat: Create minimal reader entry point for foliate-js Create minimal Alpine.js integration for foliate-js reader. This file serves as the entry point that imports foliate-js and provides basic navigation controls. Implementation: 1. Import foliate-js/view.js: - Registers custom element globally - Makes foliate reader functional when element is added to DOM - No explicit EPUB imports needed (foliate detects format automatically) 2. Alpine.js integration: - Create readerShell data object for UI state management - Provide nextPage() and previousPage() methods for button controls - Methods access custom element's API (next(), prev()) - Simple, functional approach (no OOP, follows project guidelines) 3. Init placeholder: - initReader() method for future initialization logic - Currently just logs for debugging - Will be extended with theme switching, progress sync, etc. Design Choices: - Follow project guidelines: No classes, functional/procedural style - Use Alpine.js for UI state (consistent with rest of application) - Defer book loading to foliate's internal format detection - Minimal footprint: Only what's needed to make work Next Steps (Future Commits): - Theme switching logic (apply CSS custom properties) - Progress sync to API (listen to foliate's relocate event) - Book loading integration (open book path, handle CFI locations) - Settings persistence (save theme, font, spacing preferences) File: web/src/reader/reader.ts (31 lines) - Clean separation: Foliate handles rendering, Alpine handles UI state - Type-safe with @ts-ignore for foliate custom element API access --- web/src/reader/reader.ts | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/web/src/reader/reader.ts b/web/src/reader/reader.ts index 345b02c..ee3f989 100644 --- a/web/src/reader/reader.ts +++ b/web/src/reader/reader.ts @@ -1,13 +1,22 @@ -import "../alpine"; +import "foliate-js/view.js"; import { Alpine } from "../alpine"; -// Core utilities (minimal set needed by reader) -import "../api"; // API calls for reading progress -import "../dom"; // DOM helpers -import "../events"; // Event system -import "../storage"; // localStorage helpers -import "../theme"; // Theme support (reader needs theme) -import "../toast"; // Toast notifications -import "../toast-error"; // Error toasts -// Reader functionality -import "./reader-shell"; + +document.addEventListener("alpine:init", () => { + Alpine.data("readerShell", () => ({ + async initReader() { + console.log("Reader initialized"); + }, + nextPage() { + const view = document.querySelector("#reader-view"); + // @ts-ignore - foliate custom element + view?.next?.(); + }, + previousPage() { + const view = document.querySelector("#reader-view"); + // @ts-ignore - foliate custom element + view?.prev?.(); + }, + })); +}); + Alpine.start();