-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontext.ts
41 lines (31 loc) · 930 Bytes
/
context.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
import {defaultConfig} from './default-config.js';
import {Config} from './types/config.types';
import {CssStyles} from './types/global.types.js';
import {merge} from './utils/merge.js';
export class Context {
public images: Record<string, string> = {};
private _styles: CssStyles | null = null;
private pageStyles: CssStyles = {};
constructor(public readonly config: Config) {
}
get styles(): CssStyles {
if (this._styles) {
return this._styles;
}
this._styles = merge({}, this.config.globalStyles || {}, this.pageStyles, this.config.styles) as CssStyles;
return this._styles;
}
public setPageStyles(styles: CssStyles) {
this.pageStyles = styles;
}
get fonts() {
return this.config.fonts;
}
}
export const createContext = (_config: Partial<Config> = defaultConfig()) => {
const config = {
...defaultConfig(),
..._config
};
return new Context(config);
};