@camasuvi/readability-lab-controls
v0.1.1
Published
Embeddable reading-settings web component and headless API using the portable Readability Lab profile format.
Downloads
499
Readme
@camasuvi/readability-lab-controls
Reading settings for publishers, using the portable Readability Lab profile.
npm install @camasuvi/readability-lab-controlsWeb component
<rl-reading-controls target="#story" recipe-src="/recipe.json" storage-key="my-site:reading"></rl-reading-controls>
<script type="module">
import "@camasuvi/readability-lab-controls/element"; // registers <rl-reading-controls>
</script>Without a bundler, load the classic script from the package: @camasuvi/readability-lab-controls/iife (the file dist/reading-controls.iife.js).
- Native, keyboard-operable controls. The layout wraps at any text size, and there are no fixed heights.
- The publisher recipe sets the defaults. Reader changes win, and settings the reader marks to keep survive presets.
- Settings, and whether the reader switched them off, are stored in
localStorageon this device only. Profile files and share codes contain settings only. - It listens for a
readability-lab:profilewindow event. The browser extension sends this only if the reader enables it.
Headless API
import { createReadingPreferences } from "@camasuvi/readability-lab-controls";
const prefs = createReadingPreferences({ target: "#story", recipe });
prefs.subscribe(({ resolution }) => render(resolution.settings));
prefs.set({ fontSizePx: 20 });
prefs.applyPreset("larger-text");
prefs.setEnabled(false); // show the original
prefs.exportJson(); // portable profileThe headless API imports without a DOM, so it can be loaded during server rendering; the element itself needs a browser.
Bundle: about 133 KB minified, 40 KB gzip; most of it is the schema validator. Apache-2.0.
