Repository navigation
feat: add marginMarker decoration style - #348
ddfreiling wants to merge 22 commits into
Conversation
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>
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>
|
@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>
I'm checking this out today! |
AndreasLymalmMTM
left a comment
There was a problem hiding this comment.
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:
- Expose the current font size in the API.
- Create a new property on
EPUBPreferences, e.g. a booleanmakeSpaceForMarginDecoration, 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.
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>
|
Thank you @ddfreiling. I tested |
…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
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
MarginMarker,MarginMarkerIconandMarginSide, and an optionalmarkerfield onReaderDecorationStyle, sent as a nested map.applyDecorationsasserts in debug that amarginMarkerdecoration has a marker.boundslayout, page width). The marker floats into the logical start or end margin, so it flips in RTL.data-activablelimits taps to the marker, so taps on the text still reach the highlight.MarginAnchor.text(default) keeps a marker a small gap from the text column;MarginAnchor.pageputs 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.pageList→ labels), and a bookmark marker next to every highlight.applyDecorationsnow skips a decoration it can't parse instead of failing the whole group, matching Android and web.ReaderDecorationStyle.fromJsonnow parsestintas the CSS stringtoJsonsends.ResizeObserverthat fires beforeinnerWidthupdates. The helper script now also relays out on windowresize.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.The built-in icons,
bookmark,noteandstar:Review notes
extras, because ts-toolkit's diffing ignores a template'selement. Without it, a changed label or tint under the same id would not re-render.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.endmarker of the left page and thestartmarker 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.Verification
bookmark and page number → their own groups
bookmark tap not reachable (the example's left-edge page-turn zone)
bin/format,bin/analyze, the platform-interface tests, webbin/typecheckand jest,ktlint, the Android Kotlin compile, the iOS simulator build,bin/changelog check.Not covered
noteandstaricons were checked as rendered SVG and by web unit tests, not in a running reader.assets/helpers/) is a gitignored build output. A stale local build silently falls back to the page edge; re-runbin/installornpm run build:helpers:devafter pulling.makeSpaceForMarginDecorationwas checked on the iPad simulator at font size 2.0 only.🤖 Generated with Claude Code