-
Notifications
You must be signed in to change notification settings - Fork 104
Expand file tree
/
Copy pathstyleUtils.ts
More file actions
119 lines (108 loc) · 2.62 KB
/
styleUtils.ts
File metadata and controls
119 lines (108 loc) · 2.62 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import {Platform} from 'react-native';
import type {MarkdownStyle} from './MarkdownTextInputDecoratorViewNativeComponent';
type PartialMarkdownStyle = Partial<{
[K in keyof MarkdownStyle]: Partial<MarkdownStyle[K]>;
}>;
const FONT_FAMILY_MONOSPACE = Platform.select({
ios: 'Courier',
default: 'monospace',
});
const FONT_FAMILY_EMOJI = Platform.select({
ios: 'System',
android: 'Noto Color Emoji',
default: 'System, Apple Color Emoji, Segoe UI Emoji, Noto Color Emoji',
});
function makeDefaultMarkdownStyle(): MarkdownStyle {
return {
syntax: {
color: 'gray',
},
link: {
color: 'blue',
},
h1: {
fontSize: 25,
lineHeight: -1,
},
emoji: {
fontSize: 20,
fontFamily: FONT_FAMILY_EMOJI,
},
blockquote: {
borderColor: 'gray',
borderWidth: 6,
marginLeft: 6,
paddingLeft: 6,
},
code: {
fontFamily: FONT_FAMILY_MONOSPACE,
fontSize: 20,
color: 'black',
backgroundColor: 'lightgray',
borderColor: 'gray',
borderWidth: 1,
borderRadius: 4,
borderStyle: 'solid',
padding: 0,
},
pre: {
fontFamily: FONT_FAMILY_MONOSPACE,
fontSize: 20,
color: 'black',
backgroundColor: 'lightgray',
borderColor: 'gray',
borderWidth: 1,
borderRadius: 4,
borderStyle: 'solid',
padding: 2,
},
mentionHere: {
color: 'green',
backgroundColor: 'lime',
},
mentionUser: {
color: 'blue',
backgroundColor: 'cyan',
},
mentionReport: {
color: 'red',
backgroundColor: 'pink',
},
inlineImage: {
minWidth: 50,
minHeight: 50,
maxWidth: 150,
maxHeight: 150,
marginTop: 5,
marginBottom: 0,
borderRadius: 5,
},
loadingIndicator: {
primaryColor: 'gray',
secondaryColor: 'lightgray',
},
};
}
function mergeMarkdownStyleWithDefault(input: PartialMarkdownStyle | undefined): MarkdownStyle {
const output = makeDefaultMarkdownStyle();
if (input !== undefined) {
Object.keys(input).forEach((key) => {
if (!(key in output)) {
return;
}
const outputValue = output[key as keyof MarkdownStyle];
if (outputValue) {
Object.assign(outputValue, input[key as keyof MarkdownStyle]);
}
});
}
return output;
}
function parseStringWithUnitToNumber(value: string | number | null): number {
if (typeof value === 'number') {
return value;
}
return value ? parseInt(value.replace('px', ''), 10) : 0;
}
export type {PartialMarkdownStyle};
export {mergeMarkdownStyleWithDefault, parseStringWithUnitToNumber};