Manga.ReaderHTML (manga v0.1.0)

Copy Markdown View Source

View module for the paged reader page, plus the canvas/spread helpers the paged engine is built on.

Summary

Functions

Fold a user's chapter page overrides into the natural image list.

Build a %Fresco.Canvas{} containing every page of the chapter laid out side-by-side on a virtual canvas, so the paged reader navigates purely by retargeting fresco's pan/zoom (handle.fitImage("page-N")) — no reload, no DOM mutation.

JSON-encodes the chapter's image list for client-side use: [{url, width, height}, ...] with proxied URLs. JS uses this to build fresco sources for any page without re-hitting the server.

Returns the canonical list of "spread start" page numbers for a chapter in double-page mode. Page 1 is always its own start (solo first spread). Subsequent pages pair up unless one of the pair is wide (>1.2 aspect) or user-marked solo, in which case that page goes solo and pairing resumes after it.

daisyUI button class string for active/inactive switcher buttons.

URL for the same chapter+page with overridden flags — used by the settings toggles (direction, double-page) that require a server-side re-render (the canvas's page-X layout differs by direction).

Public delegate so the images API can build a JSON payload using the SAME proxied URL the server-rendered canvas placed in data-src — keeping the client's applyImageWindow swap-back a no-op identity match instead of a cross-origin re-fetch.

True when the page at index n (1-based) is wider than it is tall (likely a glued-together spread that should be shown solo).

Functions

apply_overrides(images, overrides)

Fold a user's chapter page overrides into the natural image list.

Returns {new_images, solo_set, inserted_set}:

  • new_images — image list with synthetic blanks spliced before each insert_blank_before.page_index (in natural coords). Each synthetic image carries synthetic: true.
  • solo_set — 1-based indices (in the new list) displayed alone in double-page mode (kind = "solo").
  • inserted_set — 1-based indices (in the new list) of the synthetic blanks themselves, handed to the client for styling.

Overrides with page_index outside [1, length(images)] are silently ignored — forgiving when a chapter's page count changes upstream.

fresco_canvas(images, direction, etcher_annotations, current_page, double_page, spread_starts, proxy_url)

Build a %Fresco.Canvas{} containing every page of the chapter laid out side-by-side on a virtual canvas, so the paged reader navigates purely by retargeting fresco's pan/zoom (handle.fitImage("page-N")) — no reload, no DOM mutation.

Pages are ordered along X by reading direction (RTL: page 1 rightmost). Each image carries id = "page-N". Single vs double page is a fit decision, not a layout one. Existing annotations are stashed under the canvas "etcher" extension for hydration.

fresco_images_json(images, proxy_url)

JSON-encodes the chapter's image list for client-side use: [{url, width, height}, ...] with proxied URLs. JS uses this to build fresco sources for any page without re-hitting the server.

fresco_spread_starts(images, solo_set \\ %MapSet{})

Returns the canonical list of "spread start" page numbers for a chapter in double-page mode. Page 1 is always its own start (solo first spread). Subsequent pages pair up unless one of the pair is wide (>1.2 aspect) or user-marked solo, in which case that page goes solo and pairing resumes after it.

paged(assigns)

paged_btn_class(arg)

daisyUI button class string for active/inactive switcher buttons.

paged_self_url(assigns, overrides)

URL for the same chapter+page with overridden flags — used by the settings toggles (direction, double-page) that require a server-side re-render (the canvas's page-X layout differs by direction).

proxied_image_src(img, proxy_url)

Public delegate so the images API can build a JSON payload using the SAME proxied URL the server-rendered canvas placed in data-src — keeping the client's applyImageWindow swap-back a no-op identity match instead of a cross-origin re-fetch.

wide_page?(images, n)

True when the page at index n (1-based) is wider than it is tall (likely a glued-together spread that should be shown solo).