@molecule/app-reading-progress-bar-svelte
Feature · reading-progress-bar · App (browser) · v1.1.1 · Apache-2.0
Top-of-page scroll progress bar for article pages
npm install @molecule/app-reading-progress-bar-svelteHow it works
@molecule/app-reading-progress-bar-svelte is a ready-made reading-progress-bar feature for the app (browser) side. It composes the core interfaces it needs, so it works with whichever providers your app has bonded.
<script lang="ts">
import { ReadingProgressBar } from '@molecule/app-reading-progress-bar-svelte'
let article: HTMLElement | undefined = $state()
// `containerRef={{ get current() { return article ?? null } }}` pins to the
// article; without containerRef the bar tracks whole-page scroll.
</script>
<ReadingProgressBar
containerRef={{
get current() {
return article ?? null
},
}}
color="var(--brand)"
thickness={4}
/>
<article bind:this={article}>…long read…</article>Works with: @molecule/app-svelte, @molecule/app-ui, @molecule/app-ui-svelte
Reference
Svelte reading progress bar.
Exports ReadingProgressBar — a thin top-of-page bar that fills as the user
scrolls through an article. Used by blog and news-aggregator article pages.
It is the Svelte counterpart of @molecule/app-reading-progress-bar-react:
same export names, same props, same DOM for the same input.
Auto-generated, AI-first package reference for the molecule.dev ecosystem. It is written to be read by coding agents as much as by people, and is generated from this package's source — edit
src/index.tsJSDoc, not this file.
Quick Start
<script lang="ts">
import { ReadingProgressBar } from '@molecule/app-reading-progress-bar-svelte'
let article: HTMLElement | undefined = $state()
// `containerRef={{ get current() { return article ?? null } }}` pins to the
// article; without containerRef the bar tracks whole-page scroll.
</script>
<ReadingProgressBar
containerRef={{
get current() {
return article ?? null
},
}}
color="var(--brand)"
thickness={4}
/>
<article bind:this={article}>…long read…</article>
Type
feature
Installation
npm install @molecule/app-reading-progress-bar-svelte @molecule/app-svelte @molecule/app-ui @molecule/app-ui-svelte svelte
API
Interfaces
ReadingProgressBarProps
Props accepted by the ReadingProgressBar component.
interface ReadingProgressBarProps {
/**
* Optional ref to the article element. When provided, progress is measured
* against that element's bounding rect (so the bar fills as the user scrolls
* through the article body, not the whole page). When omitted, progress
* falls back to `window` scroll position.
*/
containerRef?: { readonly current?: Element | null }
/** Bar thickness in pixels. Defaults to `3`. */
thickness?: number
/**
* Where the bar pins. Defaults to `'top'`. Both variants render fixed across
* the full viewport width with a high z-index.
*/
position?: 'top' | 'bottom'
/**
* CSS color for the filled portion of the bar. Defaults to `'currentColor'`
* so the bar inherits whatever text color is in scope — letting the
* surrounding theme drive it. Pass a theme-aware color (`'var(--brand)'`,
* etc.) to override.
*/
color?: string
/** Extra classes on the outer wrapper. */
className?: string
/** `data-mol-id` for AI-agent / E2E selectors. */
dataMolId?: string
}
Functions
computeArticleProgress(el, viewportHeight)
Computes the scroll progress (0..1) of an element, measured by how much of the element has scrolled past the top of the viewport.
Returns 0 when the element's top is at or below the viewport top, 1 when
its bottom is at or above the viewport top plus the viewport height (fully
read), and linearly interpolates between those endpoints in the middle. An
element shorter than the viewport counts as fully read once its top reaches
the viewport top.
function computeArticleProgress(el: Element, viewportHeight: number): number
el— The article element whose read-through progress we want.viewportHeight— The viewport height to use as the denominator.
Returns: A number in [0, 1].
computeWindowProgress()
Computes window scroll progress (0..1) using scrollY and the document's
total scrollable height.
function computeWindowProgress(): number
Returns: A number in [0, 1]. Falls back to 0 when there is nothing to scroll (page shorter than the viewport).
Constants
ReadingProgressBar
const ReadingProgressBar: LegacyComponentType
Injection Notes
Requirements
Peer dependencies:
@molecule/app-svelte^3.5.0 || ^4.0.0@molecule/app-ui^1.0.1@molecule/app-ui-svelte^1.1.0svelte^5.0.0
Runtime Dependencies
@molecule/app-svelte@molecule/app-ui@molecule/app-ui-sveltesvelte
Companion locale bond: @molecule/app-locales-reading-progress-bar (the
progressbar aria-label). The fill defaults to currentColor — it inherits
the surrounding text color, so pass color (e.g. var(--color-primary))
when the ambient text color is low-contrast against the page edge. The bar
renders position: fixed at z-index: 1000 spanning the viewport width; it
only listens to window scroll — containerRef changes what is measured,
not which scroller is observed (inner scroll containers won't drive it).
Requires the Svelte binding's i18n provider and a wired ClassMap bond.
Translations
Translation strings are provided by @molecule/app-locales-reading-progress-bar.