-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.ts
57 lines (49 loc) · 1.29 KB
/
options.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
import { Options, PluginOptions } from './types'
import { defaultTheme } from './theme/default'
import { log } from './helper'
export const defaultOptions: Options = {
arrow: {
position: 'center',
icon: 'arrow-rounded',
color: '#000000',
},
color: '#FFFFFF',
width: '20px',
click: {
denominator: 2,
},
hideScrollbar: true,
moveStylesToWrapper: false,
}
export const getOptions = (options: PluginOptions = {}) => {
const shallowMerge = {
...defaultOptions,
...options,
}
// Manually deep merge where necessary, to avoid adding dependency for this.
if (typeof shallowMerge.arrow === 'object') {
shallowMerge.arrow = {
...defaultOptions.arrow,
...shallowMerge.arrow,
}
}
if (typeof shallowMerge.click === 'object') {
shallowMerge.click = {
...defaultOptions.click,
...shallowMerge.click,
}
}
if (shallowMerge.arrow === true) {
shallowMerge.arrow = defaultOptions.arrow
}
if (shallowMerge.click === true) {
shallowMerge.click = defaultOptions.click
}
if (shallowMerge.theme && typeof shallowMerge.theme !== 'object') {
log('InvalidTheme', { theme: shallowMerge.theme })
delete shallowMerge.theme
} else if (!shallowMerge.theme) {
shallowMerge.theme = defaultTheme
}
return shallowMerge
}