Skip to content

feat: add marginMarker decoration style - #348

Open
ddfreiling wants to merge 22 commits into
Notalib:mainfrom
ddfreiling:docs/margin-marker-decorations-plan
Open

ddfreiling wants to merge 22 commits into
Notalib:mainfrom
ddfreiling:docs/margin-marker-decorations-plan

Conversation

@ddfreiling

@ddfreiling ddfreiling commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

Summary

Clients want small markers in the page margin, level with a text location: printed page numbers from the EPUB pageList, and a bookmark icon next to a highlight. Apps can't add Readium decoration templates themselves (they are registered natively), so the plugin now ships one generic style, DecorationStyle.marginMarker, that shows a text label or a built-in icon. The design and its rationale are in docs/plans/margin-marker-decorations.md.

Change

ReaderDecorationStyle(
  style: DecorationStyle.marginMarker,
  tint: Colors.green,                                  // optional, colours the marker
  marker: MarginMarker.label('12', side: MarginSide.end, anchor: MarginAnchor.page),
  // or: MarginMarker.icon(MarginMarkerIcon.bookmark)  // bookmark | note | star; anchor defaults to text
)

await reader.setEPUBPreferences(prefs.copyWith(makeSpaceForMarginDecoration: true)); // optional
  • Dart: new MarginMarker, MarginMarkerIcon and MarginSide, and an optional marker field on ReaderDecorationStyle, sent as a nested map. applyDecorations asserts in debug that a marginMarker decoration has a marker.
  • iOS / Android / web: each renders the same inline-styled HTML template (bounds layout, page width). The marker floats into the logical start or end margin, so it flips in RTL. data-activable limits taps to the marker, so taps on the text still reach the highlight.
  • Anchor: MarginAnchor.text (default) keeps a marker a small gap from the text column; MarginAnchor.page puts it at the page edge, which suits page numbers. The shared helper script measures the body's inline margin, border and padding and publishes them as CSS variables, so the position follows Readium CSS, publisher CSS, font size and scroll mode on all three platforms.
  • EPUBPreferences.makeSpaceForMarginDecoration (opt-in): widens the side margins with the font size, so a marker never overlaps the text at large font sizes. Suggested in review.
  • Icons are a closed set rendered from built-in SVG paths; apps never send markup. Labels are HTML-escaped.
  • Example app: a "Page numbers in margin" toggle (pageList → labels), and a bookmark marker next to every highlight.
  • Docs: a new margin markers guide and API reference entries.
  • Fixes found on the way:
    • iOS applyDecorations now skips a decoration it can't parse instead of failing the whole group, matching Android and web.
    • ReaderDecorationStyle.fromJson now parses tint as the CSS string toJson sends.
    • Decorations sized to the page width (only margin markers) went stale after an iPad rotation, because the toolkit relays out from a body ResizeObserver that fires before innerWidth updates. The helper script now also relays out on window resize.
    • The Android missing-tint fix is also here; it is split out as fix(android): accept decorations without a tint #352.

Screenshots

iPad simulator. Left: an untinted bookmark anchored to the text next to a highlight; it takes the text colour. Right: printed page numbers from pageList, anchored to the page edge, drawn small and muted.

Highlight with bookmark, page 3 Page 4

The built-in icons, bookmark, note and star:

Review notes

  • Builds on fix(android): accept decorations without a tint #352. Its commit is included so this branch works on Android; it drops out on rebase once fix(android): accept decorations without a tint #352 merges.
  • On web, the marker payload goes into extras, because ts-toolkit's diffing ignores a template's element. Without it, a changed label or tint under the same id would not re-render.
  • Anchoring measures the body in script instead of copying Readium CSS rules into calc(). The copy fails on web in scroll mode, where Readium CSS 2 drops the page gutter, and would break silently on toolkit upgrades. Rationale: plan decision 11.
  • In a two-column spread, the end marker of the left page and the start marker of the right page share the gutter. On narrow phone margins, an icon can touch the text. Both are documented in the guide rather than compensated for.
  • App-supplied icons are deliberately out of scope; a parked plan covers them: docs/plans/todo/margin-marker-custom-icons.md.

Verification

Platform Render Dark theme Taps
iOS simulator ✅ paginated + scroll ✅ ✅ text → highlight,
bookmark and page number → their own groups
Android (S23) ✅ ✅ custom theme ✅ all three targets
Web (Chrome) ✅ incl. two-column spread — ✅ page-number tap;
bookmark tap not reachable (the example's left-edge page-turn zone)
  • Gates: bin/format, bin/analyze, the platform-interface tests, web bin/typecheck and jest, ktlint, the Android Kotlin compile, the iOS simulator build, bin/changelog check.
  • Code review and over-engineering review ran before this; their fixes are in the last commits.

Not covered

  • RTL: no RTL fixture was available, so the logical-side flip is untested on device.
  • The note and star icons were checked as rendered SVG and by web unit tests, not in a running reader.
  • The restyle (no box, muted labels) was checked on the iPad simulator only.
  • Text anchoring was checked on Android in a two-column landscape spread and on the iPad simulator (the screenshots). Web was checked only on an earlier prototype.
  • The helper bundle (assets/helpers/) is a gitignored build output. A stale local build silently falls back to the page edge; re-run bin/install or npm run build:helpers:dev after pulling.
  • makeSpaceForMarginDecoration was checked on the iPad simulator at font size 2.0 only.

🤖 Generated with Claude Code

ddfreiling and others added 14 commits November 18, 2026 14:33
Plan a built-in `marginMarker` decoration style that shows a text
label or built-in icon in the page margin on iOS, Android and web,
with example recipes for pageList page numbers and bookmarked
highlights.

Styles are inline with !important, because ts-toolkit renders
decorations in a shadow root and Readium CSS theme rules beat class
rules on native. Markers need no tap suppression: data-activable keeps
their tap area in the margin. Also covers the Android crash on a
decoration without a tint.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
decorationFromJson called getString("tint"), which throws when the key
is absent, so any decoration style without a tint was dropped even
though tint is optional in the Dart model. Read it as optional.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Add DecorationStyle.marginMarker with MarginMarker (label or built-in
icon, logical side), MarginMarkerIcon and MarginSide, plus an optional
ReaderDecorationStyle.marker. fromString maps the new wire value
instead of falling back to highlight, and copyWith uses the shared
unset sentinel.

FlutterReadium.applyDecorations asserts in debug that marginMarker
decorations carry a marker. Native sides skip such decorations.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Register an HTML decoration template for the marginMarker style. It
floats a label or built-in bookmark icon into the page margin using
inline !important styles, so Readium CSS theme rules cannot hide it,
and marks the span data-activable so text taps still reach the
decoration underneath.

Decoration.Style.init(fromMap:) builds a MarginMarkerConfig from the
marker map and throws for a marker without a label or known icon.
applyDecorations now skips a decoration that fails to parse instead of
dropping the whole group, and setDecorationStyle no longer crashes
(try!) on a style it cannot parse.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Add MarginMarkerStyle and an HTML decoration template that floats a
label or built-in bookmark icon into the page margin. It uses inline
!important styles, so Readium CSS theme rules cannot hide it, and
marks the span data-activable so text taps still reach the decoration
underneath.

decorationFromJson now passes the nested marker object on as a Map, so
decorationStyleFromMap sees the same shape on the applyDecorations and
the TTS setDecorationStyle paths. A marker without a label or known
icon is logged and the decoration skipped. escAttr moves out of the
spotlight template so both templates share it.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Render marginMarker decorations as a bounds/page template in the
decoration's own group, with the same inline !important markup as the
iOS and Android templates. A marker without a label or known icon is
logged and skipped.

The marker payload and tint go into the decoration's extras, because
ts-toolkit ignores a template's element when diffing and a changed
label, icon, side or tint would otherwise never re-render.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Add a "Page numbers in margin" toggle (page_numbers_toggle) to the
player app bar, shown when the publication has a page list. It applies
a page-list group with one end-side label marker per entry.

Each user highlight now also gets a bookmark marker in a
highlight-markers group, on the same locator. Taps on the highlighted
text still reach the highlight decoration.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Add a guide with the page-number and bookmarked-highlight recipes,
and notes on side, tint, taps and margin width. Link it from the
decorations API reference (marginMarker and MarginMarker rows only)
and the highlights guide. Add changelog fragments for both packages.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…Json

toJson sends tint as a CSS colour string, but fromJson cast it to int,
so round-tripping any tinted style threw. Also drop three marker tests
that only re-checked enum names and collection-ifs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Shorten the template doc comments to point at the plan.
- Log unparsable TTS decoration styles on iOS instead of silently
  clearing them.
- Remove an unused import in MarginMarkerStyle.kt.
- Guide: bind locatorFromLink once and link to the API reference
  instead of repeating its field table.
- Move the plan to docs/plans/ as implemented.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MarginMarkerIcon gains note and star next to bookmark. Each platform
now keeps one name -> SVG path map that both the parser and the
template read, so a listed icon can no longer parse but render empty.
On web the lookup uses a Map, so names like "constructor" no longer
resolve through the prototype chain.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ddfreiling ddfreiling changed the title docs(plans): add margin marker decorations plan feat: add marginMarker decoration style Nov 19, 2026
ddfreiling added a commit to ddfreiling/flutter_readium that referenced this pull request Nov 19, 2026
The bordered box made icons look like tiny checkboxes, and its padding
pushed markers into the text on narrow phone margins. Icons now render
at about one body em in the full marker colour; labels stay small and
are muted like printed page numbers. The example's bookmark drops its
green tint, so it takes the text colour and follows the theme.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ddfreiling added a commit to ddfreiling/flutter_readium that referenced this pull request Nov 19, 2026
@ddfreiling

Copy link
Copy Markdown
Member Author

@AndreasLymalmMTM what do you think? Would appreciate feedback and code-review on this 😉

Markers sat 2px from the screen edge, which looked cramped on tablets.
The edge margin is now 1.5% of the page width with a 4px floor, so
phones, whose margins are narrow, don't get pushed into the text.
Labels go from 0.6 to 0.8 opacity, so page numbers read more easily.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ddfreiling added a commit to ddfreiling/flutter_readium that referenced this pull request Nov 19, 2026
@AndreasLymalmMTM

Copy link
Copy Markdown
Contributor

@AndreasLymalmMTM what do you think? Would appreciate feedback and code-review on this 😉

I'm checking this out today!

@AndreasLymalmMTM AndreasLymalmMTM left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested it and it looks good.

But as the docs describe, the margin text/icon may overlap the text. This can be fixed by setting a greater value on EPUBPreferences.pageMargins, but if EPUBPreferences.fontSize is not set, the publication's default font size is used, which is not exposed in the API as far as I can tell. This means that EPUBPreferences.pageMargins can't be reliably calculated to make appropriate spacing. I would suggest either:

  1. Expose the current font size in the API.
  2. Create a new property on EPUBPreferences, e.g. a boolean makeSpaceForMarginDecoration, that enforces a minimum margin space so that the margin decoration always fit.

But that's only my suggestion, and doesn't need to be solved right now.

ddfreiling and others added 5 commits November 23, 2026 23:56
Add MarginMarker.anchor. The default, page, keeps the marker near the
page (or column) edge. The new text anchor keeps it a small gap from
the text column however wide the margin is, which reads better on
wide screens.

flutterReadiumTools.js measures the body's margin, border and padding
and publishes them as --flutter-readium-text-inset-start/end. The
iOS, Android and web templates size a flex cell to that inset and
push the marker against its text side, so a too-narrow margin makes
the marker overflow toward the text, never off the page.

The example app uses the text anchor for bookmarks and keeps page
numbers on the page anchor.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Make MarginAnchor.text the default. On wide screens a page-anchored
marker drifts far from its passage; on narrow margins the two anchors
look the same. A missing or unknown anchor now reads as text on every
platform.

The example app's page numbers opt into MarginAnchor.page; bookmarks
use the default.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The toolkit decorator relays out only from a body ResizeObserver. On
iPad rotation WebKit fires it while window.innerWidth still reports
the old viewport, so `width: page` decorations (margin markers) get
the old page width and position. They stayed stale unless a later
body-size change happened to trigger a second pass.

Relayout every decoration group from the helper script on window
`resize`, which fires with the new viewport size. The helper is
shared, so Android gets the same relayout; kotlin-toolkit's
decorator has the same ResizeObserver-only trigger.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
At large font sizes, or with small page margins, a margin marker
overlaps the text, because the page margin is a fixed gutter that does
not grow with the font.

The opt-in EPUBPreferences.makeSpaceForMarginDecoration widens the
side padding to the largest of the Readium gutter x pageMargins and the
room a marker needs with either anchor: 2 x max(4px, 1.5vw) + 1.3em for
the page anchor, 4px + 0.5em + 1.3em for the text anchor. It never
narrows the margin. The helper stylesheet holds the rule; native
switches it on with a root CSS variable, web with a data attribute
because ts-toolkit strips root style properties it did not set.
Fixed-layout publications ignore it on all platforms.

The example app gets a "Room for margin markers" switch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Text anchoring ships with margin markers in the same release, so it
is part of that feature rather than a change upgraders would notice
on its own.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@AndreasLymalmMTM

Copy link
Copy Markdown
Contributor

Thank you @ddfreiling. I tested makeSpaceForMarginDecoration and anchor. Nice addition! Works well.

@ddfreiling
ddfreiling marked this pull request as ready for review November 30, 2026 14:05
@ddfreiling
ddfreiling requested a review from m-abs November 30, 2026 14:05
…corations-plan

* 'main' of https://github.com/Notalib/flutter_readium: (43 commits)
  fix(web): ignore reader keys pressed with Shift
  chore(doctor): say the fsmonitor daemon is off, not the setting
  fix(web): leave Space to DOM buttons and share reader key teardown
  docs(troubleshooting): run fsmonitor override from the example app
  test(android): assert every state after a paused goToLocator has progressions
  fix(android): publish upstream's landed locator after goToLocator
  fix(web): stop TTS when the speech engine ends without starting
  fix(android): narrow goToLocator result claims and test the false paths
  fix(web): turn one page per Space press, back on Shift+Space
  fix(web): ignore reader key shortcuts meant for the host app
  chore(release): v0.10.2
  fix(android): fill audio locator progression after goToLocator
  chore(doctor): fail when git core.fsmonitor is enabled on macOS
  fix(ios): open publications from file:// URL strings
  fix(web): zoom to the panel of a comic cue that loaded its chapter
  fix(android): percent-encode file paths when opening a publication
  fix(android): return navigation result from goToLocator
  fix(web): keep the newer book open when a superseded open fails
  fix(web): discard visual navigators from a superseded open
  fix(web): skip destroyed frames when reaching reader windows
  ...

# Conflicts:
#	flutter_readium/web/src/__tests__/iframeInjection.test.ts
#	flutter_readium/web/src/utils/iframeInjection.ts

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants