Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preferences API #106

Draft
wants to merge 141 commits into
base: develop
Choose a base branch
from
Draft

Preferences API #106

wants to merge 141 commits into from

Conversation

JayPanoz
Copy link
Contributor

@JayPanoz JayPanoz commented Feb 7, 2025

This branch is meant to implementing the Preferences API in the ts-toolkit Navigator, bringing it on par with – and taking inspiration from – Readium’s Mobile toolkits.

This will make it a lot easier to implement user settings in apps and is using ReadiumCSS version 2.

It will be merged as a new major version since it will consequently come with breaking changes.

In ReadiumCSS v1, auto pagination was built-in, switching from 1 to 2 columns depending on the window/screen width. This is no longer the case. However, we plan to replace this feature with preferences that can be set:

  • an optimal line length, in ch (number of characters)
  • a minimal line length: can be ch, can be undefined, or null.

The logic is the following:

  • the number of columns is no longer limited to 2. It can be as many as apps see fit
  • the number of columns will be computed based on this optimal line length in auto mode
  • the minimal line length is used to apply a lower bound even if the number of columns is larger than 1, dropping a column in the process if it can’t fit
  • in case this minimal line length is undefined, then optimal line-length is the minimal one
  • in case it’s null then this lower bound is disabled entirely and apps can enforce the number of columns they want

This is currently implemented in Readium/Playground and will be ported back into the ts-toolkit.

These anchor elements are implementation-specific and shouldn’t be forced upon all consumers of the ts-toolkit. An Injectable API should be provided to do this.
So that they stay consistent across the Navigator package
Rewritten as a class whose properties you can update for user settings
Updates from Playground:
- user line length is used instead of optimal if defined
- colCount more than 2
- colCount null instead of auto
- line length getters in px
JayPanoz added 30 commits March 10, 2025 11:22
This.constraint should not be taken into account to size the iframe’s container, which is why we add some gap when constraint was set
We don’t want to mess with fontSize here, it should stay stable unless there is a good reason to change the baseFontSize
To keep container width and column width
Relayout was effectively calling setColCount a second time after userProperties were updated, correcting the first call that used stale fontSize.
Switching fontSize toPercentage so that it works with RCSS FontSize fallback
We need zoomFactor to be taken into account for columns to work properly, but then we need to remove it for the line-length because the zoom is applied into the iframe. This is to be consistent with scroll
This is an attempt to have a good-enough fallback in case fontFamily is not defined in settings, as line-length would therefore be computed based on the CSS spec fallback (0.5em wide ch)
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.

1 participant