Search by

phil / reading-progress

phil

Resume a long text where the reader stopped, even after it is edited, and keep the furthest percent read, with one event at the start and one at completion.

0.1.0-alpha 2026-11-29 22:00 UTC

This package is auto-updated.

Last update: 2026-11-30 02:53:01 UTC


README

Resume a long text where the reader stopped, even after the text changes, and know how far each reader got.

phil/reading-progress is a plain PHP library for long reading: a course chapter, a guide, a book read online, a long article. The page reports where the reader is; the library turns it into a percent read, keeps the furthest percent and the last position, gives one event when the reading starts and one when it is complete, and finds the last position again once the text has been edited. The application keeps the text, the readers and the stored progress.

  • A position that survives edits: a block identifier, an offset in characters and a short quote of the text. Once the text changes, the quote finds the place again in its block, or in another block when the block is gone.
  • A percent read that never goes back: going back to reread keeps the furthest percent; a figure without a caption still counts as a step.
  • Completion once: at 100 %, or at a lower percent for a page whose last blocks a reader seldom scrolls to; one ReadingStarted and one ReadingCompleted event, with identifiers only, for a course, a quest or a badge to count.
  • Two devices: a position recorded late by a device that synchronises after another one counts for the furthest percent and does not replace the newer position.
  • No reading history: the last position, the furthest percent and two instants, nothing minute by minute.
  • The time left: the characters after a position and the minutes left at the reader's speed.
  • A progress bar without JavaScript: a CSS recipe on scroll-driven animations, hidden from assistive technologies and stopped when the reader asks for reduced motion.
  • Stored progress that fails loudly: a short JSON text within a size limit; a damaged text is refused rather than read as a reading not started, which would announce the start again.
  • Bounded and worker-safe: documents of at most 20,000 blocks and 4,000,000 characters, and immutable values only, so one long-running worker serves any number of readers.

Status

Part State
Documents, blocks and positions Implemented and tested
Percent read, characters and minutes left Implemented and tested
Recording, events, late positions Implemented and tested
Finding a position again after edits Implemented and tested
Stored progress Implemented and tested, fuzzed
Progress bar recipe Documented

Documentation

Document What it covers
Installation Requirements, installing, a first document.
Documents and positions Blocks, positions, the percent read, the time left, and finding a position again.
Progress Recording a position, the events, two devices, resuming and storing.
Progress bar A reading bar in CSS, without JavaScript, and the percent in words.
Extension points What an application may replace or add, and what is stable.
Testing The tests, the fuzz target and the benchmark.
Reference Every public type, with its role.

Quick start

composer require phil/reading-progress
use Phil\ReadingProgress\Block;
use Phil\ReadingProgress\Document;
use Phil\ReadingProgress\Progress;

$document = new Document('chapter-3', [
    new Block('intro', 'Fermentation turns sugar into acid, gas or alcohol.'),
    new Block('figure-1'),                       // an image without a caption
    new Block('steps', 'Weigh the vegetables, then add two percent of salt.'),
]);

// The page reports the block in view and the offset in its text.
$position = $document->positionAt($request->blockId, $request->offset);

$update = Progress::fromString($row->progress)->record($document, $readerId, $position, $clock->now());
$row->progress = $update->progress->toString();

foreach ($update->events as $event) {
    $dispatcher->dispatch($event);              // ReadingStarted, ReadingCompleted
}

$update->progress->furthestPercent;              // 0 to 100
$update->progress->resume($document)->position;  // "Continue where you left off"

Requirements

PHP 8.5 or later, with the mbstring extension.

Contributing

Contributions are welcome on the PHIL monorepo: read the contribution guide and the code of conduct. Report a vulnerability privately, as the security policy explains, never in a public issue.

License

MIT, © Philippe Gamache, doing business as Le Gnome Archiviste; a Parler Haut Interagir Librement project. See LICENSE.