UNPKG

react-native-readium

Version:

A react-native wrapper for https://readium.org/

62 lines (61 loc) 1.74 kB
import { Appearance, FontFamily, TextAlignment, ColumnCount } from '../enums'; import { RANGES, indexOfObjectValue, clamp } from '../utils'; /** * A reader settings object with sensible defaults. */ export class Settings { // TODO: // - ligatures // - paraIndent appearance = Appearance.DEFAULT; fontFamily = FontFamily.ORIGINAL; textAlign = TextAlignment.JUSTIFY; colCount = ColumnCount.AUTO; scroll = false; fontOverride = false; verticalScroll = false; bodyHyphens = false; advancedSettings = true; /** * Range: 100.0 - 300.0 */ fontSize = 100; /** * Range: 0.0 - 0.5 */ wordSpacing = 0; /** * Range: 0.0 - 0.5 */ letterSpacing = 0; /** * Range: 0.5 - 4.0 */ pageMargins = 0; /** * Range: 1.0 - 2.0 */ lineHeight = 1; /** * Range: 0.0 - 2.0 */ paragraphMargins = 0; static map(settings) { const defaultValues = new Settings(); const mapped = {}; Object.keys(defaultValues).forEach((key) => { mapped[key] = // @ts-ignore settings[key] !== undefined ? settings[key] : defaultValues[key]; }); mapped.appearance = indexOfObjectValue(Appearance, mapped.appearance); mapped.fontFamily = indexOfObjectValue(FontFamily, mapped.fontFamily); mapped.textAlign = indexOfObjectValue(TextAlignment, mapped.textAlign); mapped.colCount = indexOfObjectValue(ColumnCount, mapped.colCount); Object.keys(RANGES).forEach((key) => { // @ts-ignore mapped[key] = clamp(mapped[key], RANGES[key][0], RANGES[key][1]); }); return mapped; } }