okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
4fb068a8c
main
1/** The default reading size and interface size (owner, 11-01: 12 px and 90%; they were 14 px and 100%). */ 2export const DEFAULT_CONTENT_FS = 12 ; 3export const DEFAULT_UI_SCALE = 0.9 ; 4export const UI_SCALE_CHOICES = [ 0.9 , 1 , 1.1 , 1.25 , 1.5 , 1.75 , 2 ] as const ; 5/** Saves made while the old defaults were in force carry no `sizeDefaults` mark. */ 6export const SIZE_DEFAULTS_VERSION = 2 ; 7const OLD_CONTENT_FS = 14 ; 8const OLD_UI_SCALE = 1 ; 9 10/** The two sizes to use for a saved preferences record. A save without the mark is not a choice when it holds the old default (14 px, 100%): that 11* becomes the new default once. Any other value is a size the person picked and stays. A save with the mark is kept as it is. Nothing saved: the defaults. */ 12export function savedSizes ( saved :{ contentFontSize ?:unknown ; uiScale ?:unknown ; sizeDefaults ?:unknown } | null | undefined , min :number , max :number ) { 13const fs = Number ( saved ?. contentFontSize ), scale = Number ( saved ?. uiScale ); 14const marked = saved ?. sizeDefaults === SIZE_DEFAULTS_VERSION ; 15const fsOk = Number . isFinite ( fs ) && fs > 0 , scaleOk = ( UI_SCALE_CHOICES as readonly number []). includes ( scale ); 16return { 17contentFontSize :! fsOk || ( ! marked && fs === OLD_CONTENT_FS ) ?DEFAULT_CONTENT_FS :Math . min ( max , Math . max ( min , fs )), 18uiScale :! scaleOk || ( ! marked && scale === OLD_UI_SCALE ) ?DEFAULT_UI_SCALE :scale , 19}; 20}