-
Notifications
You must be signed in to change notification settings - Fork 28
/
Settings.ts
85 lines (71 loc) · 1.79 KB
/
Settings.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
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 = Appearance.DEFAULT;
fontFamily: FontFamily = FontFamily.ORIGINAL;
textAlign: TextAlignment = TextAlignment.JUSTIFY;
colCount: ColumnCount = ColumnCount.AUTO;
scroll: boolean = false;
fontOverride: boolean = false;
verticalScroll: boolean = false;
bodyHyphens: boolean = false;
advancedSettings: boolean = true;
/**
* Range: 100.0 - 300.0
*/
fontSize: number = 100;
/**
* Range: 0.0 - 0.5
*/
wordSpacing: number = 0;
/**
* Range: 0.0 - 0.5
*/
letterSpacing: number = 0;
/**
* Range: 0.5 - 4.0
*/
pageMargins: number = 0;
/**
* Range: 1.0 - 2.0
*/
lineHeight: number = 1;
/**
* Range: 0.0 - 2.0
*/
paragraphMargins?: number = 0;
static map(settings: Partial<Settings>): any {
const defaultValues = new Settings();
const mapped: Record<string, any> = {};
Object.keys(defaultValues)
.forEach((key: string) => {
// @ts-ignore
mapped[key] = 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: string) => {
// @ts-ignore
mapped[key] = clamp(mapped[key], RANGES[key][0], RANGES[key][1]);
});
return mapped;
}
}