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