File tree Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -57,10 +57,21 @@ export async function renderMermaid() {
57
57
btn . setAttribute ( 'data-clipboard-text' , source ) ;
58
58
mermaidBlock . append ( btn ) ;
59
59
60
+ const updateIframeHeight = ( ) => {
61
+ iframe . style . height = `${ iframe . contentWindow . document . body . clientHeight } px` ;
62
+ } ;
63
+
64
+ // update height when element's visibility state changes, for example when the diagram is inside
65
+ // a <details> + <summary> block and the <details> block becomes visible upon user interaction, it
66
+ // would initially set a incorrect height and the correct height is set during this callback.
67
+ ( new IntersectionObserver ( ( ) => {
68
+ updateIframeHeight ( ) ;
69
+ } , { root : document . documentElement } ) ) . observe ( iframe ) ;
70
+
60
71
iframe . addEventListener ( 'load' , ( ) => {
61
72
pre . replaceWith ( mermaidBlock ) ;
62
73
mermaidBlock . classList . remove ( 'tw-hidden' ) ;
63
- iframe . style . height = ` ${ iframe . contentWindow . document . body . clientHeight } px` ;
74
+ updateIframeHeight ( ) ;
64
75
setTimeout ( ( ) => { // avoid flash of iframe background
65
76
mermaidBlock . classList . remove ( 'is-loading' ) ;
66
77
iframe . classList . remove ( 'tw-invisible' ) ;
You can’t perform that action at this time.
0 commit comments