@molecule/app-bias-indicator-svelte
v1.1.3
Published
Political-bias / source-credibility indicator (left/right scale + reliability tier) for news article headers
Maintainers
Readme
@molecule/app-bias-indicator-svelte
Svelte political-bias / source-credibility indicator.
Exports BiasIndicator — left/right scale with marker plus optional
reliability dot/chip — for news-aggregator article headers and dense
article lists (compact variant). It is the Svelte counterpart of
@molecule/app-bias-indicator-react: same props and the 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 { BiasIndicator } from '@molecule/app-bias-indicator-svelte'
</script>
<BiasIndicator bias={-0.4} reliability={0.8} sourceLabel="Reuters" />Type
feature
Installation
npm install @molecule/app-bias-indicator-svelte @molecule/app-svelte @molecule/app-ui @molecule/app-ui-svelte svelteAPI
Interfaces
BiasIndicatorProps
Props accepted by the BiasIndicator component.
interface BiasIndicatorProps {
/**
* Bias scalar from `-1` (far left) through `0` (center) to `+1`
* (far right). Values are clamped before rendering.
*/
bias: number
/**
* Optional source-credibility / reliability score from `0` (lowest /
* disputed) to `1` (highest). When omitted, no reliability indicator
* is rendered.
*/
reliability?: number
/**
* Compact variant collapses the scale to a single coloured dot —
* useful for dense lists. Defaults to `false`.
*/
compact?: boolean
/**
* Optional source name (e.g. `'Reuters'`). Renders as a small caption,
* as a snippet or plain text.
*/
sourceLabel?: Snippet | string | number
/** Extra classes to merge onto the root element. */
className?: string
/** `data-mol-id` for AI-agent / E2E selectors. */
dataMolId?: string
}Types
ReliabilityTier
Reliability tier — drives the colour + label of the optional dot/chip.
Mapped from a 0..1 reliability score by reliabilityToTier.
type ReliabilityTier = 'high' | 'medium' | 'low' | 'disputed'BiasBucket
Bias bucket — drives the bias-marker hue and the screen-reader label.
Derived from a -1..1 bias scalar by biasToBucket.
type BiasBucket = 'far-left' | 'left' | 'center' | 'right' | 'far-right'Functions
clamp(value, min, max)
Clamp a number into the inclusive [min, max] range.
function clamp(value: number, min: number, max: number): numbervalue— Value to clamp.min— Lower bound.max— Upper bound.
Returns: The clamped value.
biasToBucket(bias)
Map a -1..1 bias scalar into a coarse five-bucket label used for
accessibility and colouring. Boundaries: <= -0.6 far-left,
<= -0.2 left, < 0.2 center, < 0.6 right, otherwise far-right.
function biasToBucket(bias: number): BiasBucketbias— Bias scalar (clamped to[-1, 1]first).
Returns: The bias bucket.
reliabilityToTier(reliability)
Map a 0..1 reliability score into a four-tier label. Boundaries:
>= 0.75 high, >= 0.5 medium, >= 0.25 low, otherwise disputed.
function reliabilityToTier(reliability: number): ReliabilityTierreliability— Reliability scalar (clamped to[0, 1]first).
Returns: The reliability tier.
biasToPercent(bias)
Convert a -1..1 bias value into a 0..100 percent offset for
absolute positioning along the scale track.
function biasToPercent(bias: number): numberbias— Bias scalar (clamped to[-1, 1]first).
Returns: The percent offset from the left edge of the track.
bucketColor(bucket)
Resolve the marker colour for a given bias bucket. Uses semantic CSS custom properties so swapping themes / styling libraries does not require touching this component.
function bucketColor(bucket: BiasBucket): stringbucket— Bias bucket.
Returns: A var(--…) CSS color string.
tierColor(tier)
Resolve the dot colour for a given reliability tier.
function tierColor(tier: ReliabilityTier): stringtier— Reliability tier.
Returns: A var(--…) CSS color string.
Constants
BiasIndicator
const BiasIndicator: LegacyComponentTypeInjection Notes
Requirements
Peer dependencies:
@molecule/app-svelte^3.13.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-sveltesvelteRequires a bonded ClassMap and an i18n provider (the component reads
useTranslation()), exactly like the React package.Colours come from the per-app semantic CSS custom properties, so themes flow through without code changes.
Translations
Translation strings are provided by @molecule/app-locales-bias-indicator.
