-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.ts
48 lines (40 loc) · 1.47 KB
/
index.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
import {META, NODE, STYLE} from '../constants.js';
import {Context} from '../context.js';
import {globalStyles} from '../global-styles.js';
import {Styles} from '../types/global.types.js';
import {LazyItem, LazyItemNode} from '../types/lazy-item.types.js';
import {MetaNode} from '../types/meta.types.js';
import {attrToProps} from './attr-to-props.js';
import {inheritStyle} from './inherit-style.js';
import {styleToProps} from './style-to-props.js';
import {getInlineStyles, selectStyles} from './styles.js';
/**
*
* @param item
* @param ctx the context
* @param parentItem? the parent item
*/
export const computeProps = (item: MetaNode<LazyItemNode>, ctx: Context, parentItem?: LazyItem) => {
const el = item[META][NODE];
const styles = ctx.styles;
const rootStyles = styles[':root'] || globalStyles()[':root'];
const attrProps = attrToProps(item, parentItem);
const selectors = attrProps.style || [];
const elementStyles = selectStyles(selectors, styles);
const inheritedStyles = inheritStyle(el, parentItem);
const cssStyles: Styles = Object.assign({}, rootStyles, inheritedStyles, elementStyles, getInlineStyles(el));
const styleProps = styleToProps(item, ctx, cssStyles, rootStyles);
return {
...styleProps,
...attrProps,
[META]: {
...(styleProps[META] || {}),
...(attrProps[META] || {}),
...(item[META] || {}),
[STYLE]: {
...(styleProps[META][STYLE] || {}),
...(attrProps[META][STYLE] || {}),
}
}
};
};