@@ -31,55 +31,56 @@ export const shapeTpc = function (tpc: Topic, nodeObj: NodeObj) {
31
31
if ( nodeObj . image ) {
32
32
const img = nodeObj . image
33
33
if ( img . url && img . width && img . height ) {
34
- const imgContainer = $d . createElement ( 'img' )
35
- imgContainer . src = img . url
36
- imgContainer . style . width = img . width + 'px'
37
- imgContainer . style . height = img . height + 'px'
38
- tpc . appendChild ( imgContainer )
39
- tpc . image = imgContainer
34
+ const imgEl = $d . createElement ( 'img' )
35
+ imgEl . src = img . url
36
+ imgEl . style . width = img . width + 'px'
37
+ imgEl . style . height = img . height + 'px'
38
+ if ( img . fit ) imgEl . style . objectFit = img . fit
39
+ tpc . appendChild ( imgEl )
40
+ tpc . image = imgEl
40
41
} else {
41
- console . warn ( 'image url/width/height are required' )
42
+ console . warn ( 'Image url/width/height are required' )
42
43
}
43
44
} else if ( tpc . image ) {
44
45
tpc . image = undefined
45
46
}
46
47
47
48
{
48
- const textContainer = $d . createElement ( 'span' )
49
- textContainer . className = 'text'
50
- textContainer . textContent = nodeObj . topic
51
- tpc . appendChild ( textContainer )
52
- tpc . text = textContainer
49
+ const textEl = $d . createElement ( 'span' )
50
+ textEl . className = 'text'
51
+ textEl . textContent = nodeObj . topic
52
+ tpc . appendChild ( textEl )
53
+ tpc . text = textEl
53
54
}
54
55
55
56
if ( nodeObj . hyperLink ) {
56
- const linkContainer = $d . createElement ( 'a' )
57
- linkContainer . className = 'hyper-link'
58
- linkContainer . target = '_blank'
59
- linkContainer . innerText = '🔗'
60
- linkContainer . href = nodeObj . hyperLink
61
- tpc . appendChild ( linkContainer )
62
- tpc . linkContainer = linkContainer
63
- } else if ( tpc . linkContainer ) {
64
- tpc . linkContainer = undefined
57
+ const linkEl = $d . createElement ( 'a' )
58
+ linkEl . className = 'hyper-link'
59
+ linkEl . target = '_blank'
60
+ linkEl . innerText = '🔗'
61
+ linkEl . href = nodeObj . hyperLink
62
+ tpc . appendChild ( linkEl )
63
+ tpc . link = linkEl
64
+ } else if ( tpc . link ) {
65
+ tpc . link = undefined
65
66
}
66
67
67
68
if ( nodeObj . icons && nodeObj . icons . length ) {
68
- const iconsContainer = $d . createElement ( 'span' )
69
- iconsContainer . className = 'icons'
70
- iconsContainer . innerHTML = nodeObj . icons . map ( icon => `<span>${ encodeHTML ( icon ) } </span>` ) . join ( '' )
71
- tpc . appendChild ( iconsContainer )
72
- tpc . icons = iconsContainer
69
+ const iconsEl = $d . createElement ( 'span' )
70
+ iconsEl . className = 'icons'
71
+ iconsEl . innerHTML = nodeObj . icons . map ( icon => `<span>${ encodeHTML ( icon ) } </span>` ) . join ( '' )
72
+ tpc . appendChild ( iconsEl )
73
+ tpc . icons = iconsEl
73
74
} else if ( tpc . icons ) {
74
75
tpc . icons = undefined
75
76
}
76
77
77
78
if ( nodeObj . tags && nodeObj . tags . length ) {
78
- const tagsContainer = $d . createElement ( 'div' )
79
- tagsContainer . className = 'tags'
80
- tagsContainer . innerHTML = nodeObj . tags . map ( tag => `<span>${ encodeHTML ( tag ) } </span>` ) . join ( '' )
81
- tpc . appendChild ( tagsContainer )
82
- tpc . tags = tagsContainer
79
+ const tagsEl = $d . createElement ( 'div' )
80
+ tagsEl . className = 'tags'
81
+ tagsEl . innerHTML = nodeObj . tags . map ( tag => `<span>${ encodeHTML ( tag ) } </span>` ) . join ( '' )
82
+ tpc . appendChild ( tagsEl )
83
+ tpc . tags = tagsEl
83
84
} else if ( tpc . tags ) {
84
85
tpc . tags = undefined
85
86
}
0 commit comments