Commit Graph
35 Commits
Author SHA1 Message Date
john-okeefe fa790c2abb Fix zoom percentage to track relative to fit-page scale
The zoom percentage display had two bugs:
1. Scroll-zoom never updated the status bar percentage because the
   'zoom' event listener was registered inside the magnifier-toggle
   click handler (only added on click, and re-added on each click).
2. After reset (fit-page), the status bar showed '100%' but the
   zoom-in button treated the current scale as 1.0 (absolute), not
   the fit-page scale (e.g. 0.3). This caused a wild zoom jump
   from '100%' to '120%' that was actually a 4x visual change.

Fix by introducing a #baseScale field that captures the fit-page or
fit-width scale whenever the component renders in auto-fit mode. The
new currentScale getter exposes the actual transform scale, and
zoomPercent expresses it as a percentage of baseScale. All zoom-in/
zoom-out handlers (buttons and keyboard) now use currentScale instead
of getAttribute('zoom') || 1, and all percentage displays use
zoomPercent. The zoom event listener is registered once at setup
rather than inside the magnifier toggle handler.

Also removes all diagnostic console.log statements from fixed-layout.js
and reader.js.
2026-04-18 23:04:48 -04:00
john-okeefe 285b6711da Fix keyboard 0 not resetting zoom in fixed-layout books
When pressing 0 to reset zoom, the code was calling
removeAttribute('zoom') on the renderer, which removed the DOM
attribute but left the internal zoom/transform state stale. This meant
subsequent zoom operations would compound on the old hidden state.

Replace with the new resetZoom() method that properly clears the
numeric zoom and triggers a clean re-render.
2026-04-18 22:34:10 -04:00
john-okeefe d5b2e3deda Add magnifier, interaction mode toggle, and zoom percentage display
Magnifier (fixed-layout.js):
- Rewrite magnifier to use CSS background-image for comics (blob URLs
  from iframe img elements) and canvas drawImage for PDFs. Replaces
  broken iframe.cloneNode approach that created empty sandboxed clones.
- Detect which iframe is under the cursor by checking bounding rects,
  so magnifier works on both left and right panes.
- Forward mousemove events from iframe documents to handleMagnifierMove
  so the magnifier follows the cursor inside iframes.
- Add background-repeat: no-repeat to lens styles.
- Add zoomMagnifierEnabled getter for external state checks.

Interaction mode toggle (PDF only):
- Add 'interaction-mode' observed attribute with 'select'/'pan' values.
- In select mode (default for PDFs): mouse events pass through for text
  selection; Shift+drag enables panning as a fallback.
- In pan mode: drag-to-pan works as normal.
- Comic books always use pan mode (no text to select).
- Auto-detect PDF via #isPDF flag set in #showSpread from onZoom presence.
- Add isPDF getter so reader.js can show/hide the toggle button.
- Add toggle button in reader.html, hidden by default, shown for PDFs
  via the view 'load' event.
- Escape key dismisses the magnifier.

Zoom percentage display (reader.js):
- Dispatch 'zoom' CustomEvent from #zoomByRatio with the new scale.
- Listener in reader.js updates the percentage display on scroll zoom.

Also includes minor formatting (line wrapping) in #goLeft/#goRight.
2026-04-18 00:39:15 -04:00
john-okeefe 3f9ab7528b Implement zoom control functionality for fixed-layout e-books
This commit adds comprehensive zoom control capabilities for fixed-layout
e-book content, allowing users to zoom in, out, and reset zoom levels for
better readability and content inspection.

Key features added:
- Zoom control UI with +/- buttons and percentage display
- Keyboard shortcuts for zoom operations (Ctrl/Cmd +, -, 0)
- Mouse wheel zoom with Ctrl/Cmd modifier key
- Drag-to-pan functionality when zoomed in
- Smooth zoom transitions and state management
- Zoom constraints (min/max limits) to prevent over-zooming

Changes include:
- FixedLayout: Enhanced with zoom state management, drag handlers,
  and keyboard/mouse event listeners for intuitive zoom control
- Reader UI: Added zoom control toolbar with visual feedback
- FixedLayout renderer integration with reader zoom controls

The zoom controls provide a seamless experience for users who need to
examine fixed-layout content more closely or adjust content size for
their preferred reading experience.
2026-04-16 21:37:54 -04:00
John Factotum 052123beaf Add an EventTarget for transforming the book
And use it to do paginator-specific CSS replacements.

And use it to catch loading errors in reader.js.

Fixes #14
Closes #18
2025-03-29 15:09:23 +08:00
John Factotum 022ea7da87 Make <foliate-view> handle opening files directly 2024-10-12 10:48:51 +08:00
John Factotum 541bc07b6f EPUB: redo metadata parsing
- Support the `prefix` attribute (for the `property` attr on `<meta>`)
- Localized titles, names (including `sortAs`)
- `belongsTo`, including `calibre:series`
- `altIdentifier`, converted to URN where possible
- Remove `producer`. It's now `contributor` with `role: 'bkp'`.

NOTE: this is a breaking change if you assumed that `title` will always
be a string, `author` will always be an array, etc.
2024-09-18 11:28:08 +08:00
Balki 835b70a840 Reader: allow book urls to be relative (#29) 2024-07-26 14:00:54 +00:00
John Factotum 2a6012d749 Move section marks calculation to view
Also try to fix section mark epsilon
2023-11-02 16:10:40 +08:00
John Factotum a63a68eda0 Add PDF support 2023-10-08 21:27:06 +08:00
John Factotum bcfb942935 Fix module path 2023-10-08 20:44:32 +08:00
John Factotum d5d1541d3b Paginator: use CSS grid
Massively simplify margin/padding and header/footer layout and eliminate
unnecessary resizes and resize loops.

Also remove layout and style API from View, as these are only applicable
to the paginator.
2023-05-28 22:17:56 +08:00
John Factotum d4453bdc5c Add functions for converting Calibre CFI to standard CFI
Also demonstrate showing highlights from Calibre in the reader
2023-05-27 19:34:10 +08:00
John Factotum 0a3f4b8f27 Use Shadow DOM 2023-05-15 20:00:35 +08:00
John Factotum 4acfc050ea Turn View into a custom element, and use DOM events
Also change "relocated" -> "relocate"
2023-05-15 15:27:18 +08:00
John Factotum faaa2f47d4 Reader: update gap to relative
Also: use maxColumns
2023-05-01 23:15:58 +08:00
John Factotum 182ab10182 Remove getPosition()
The original idea of including this function in `./view.js` seems to be
that it's shared between the demo reader and Foliate. But

- It's currently not used in the demo reader any more.
- It works, but it lacks features.
- In any case it's not coupled with anything else in `./view.js`, so at
  best it should be a separate module.

Also: remove unused variable and fix indentation
2023-04-02 00:32:33 +08:00
John Factotum 7d721611fa Improve handling of links
- Remove special handling of footnotes
- Open all links by default
- Reader can return `true` to prevent default action
- Expose link handling as a method, which the reader can use to set up
  links outside renderers (e.g. in popup footnotes)
2023-03-28 16:01:51 +08:00
John Factotum 9949000a9e Use ES modules for zip.js and fflate 2023-03-20 23:49:33 +08:00
John Factotum 514cb81fe6 Reader: allow loading files from URL parameter
Fixes #3
2023-03-15 11:00:21 +08:00
John Factotum b6f514675b Reader: open external links 2022-11-04 14:40:44 +00:00
John Factotum 2b51522c43 Add .eslintrc.json
And fix issues
2022-11-04 14:12:07 +00:00
John Factotum b1ac5a943f Reader: expose the reader object globally
Makes it easier for debugging or exploring the API in the console
2022-11-04 11:00:18 +00:00
John Factotum 2a5ccb93d9 Reader: allow opening unzipped EPUBs 2022-10-27 17:41:26 +00:00
John Factotum 750458d4b7 Reader: avoid overriding the align attribute 2022-10-26 04:24:32 +00:00
John Factotum f2f41e6013 Reader: add unprefixed hyphens 2022-10-25 08:47:52 +00:00
John Factotum 6977ac005d Get rect in reader instead of view
Also expose index in `loaded` event
2022-10-25 05:55:57 +00:00
John Factotum 21bf6499a4 Reader: add progress slider 2022-10-22 18:29:52 +00:00
John Factotum 5103dc9b90 View: make it possible to do things on load
Also refactor reader, and add left/right shortcuts
2022-10-22 12:42:35 +00:00
John Factotum 3c05d0a957 Reader: add footnote popovers
Lacks a "go to" button, but at least shows something instead of nothing
2022-10-21 18:57:26 +00:00
John Factotum f39d74f932 Reader: add layout option 2022-10-21 09:53:00 +00:00
John Factotum fea239a111 Reader: show cover, title, and author in sidebar 2022-10-20 18:16:44 +00:00
John Factotum 84691787fa Reader: add title and file chooser button 2022-10-20 14:28:42 +00:00
John Factotum 9a2bb558fd Reader: add sidebar and TOC 2022-10-20 12:50:37 +00:00
John Factotum d0cd085a22 Add sample reader 2022-10-19 11:04:43 +00:00