File tree Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Original file line number Diff line number Diff line change @@ -57,10 +57,19 @@ 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 becomes visible, for example when the diagram is inside a details+summary block
65
+ ( new IntersectionObserver ( ( ) => {
66
+ updateIframeHeight ( ) ;
67
+ } , { root : document . documentElement } ) ) . observe ( iframe ) ;
68
+
60
69
iframe . addEventListener ( 'load' , ( ) => {
61
70
pre . replaceWith ( mermaidBlock ) ;
62
71
mermaidBlock . classList . remove ( 'tw-hidden' ) ;
63
- iframe . style . height = ` ${ iframe . contentWindow . document . body . clientHeight } px` ;
72
+ updateIframeHeight ( ) ;
64
73
setTimeout ( ( ) => { // avoid flash of iframe background
65
74
mermaidBlock . classList . remove ( 'is-loading' ) ;
66
75
iframe . classList . remove ( 'tw-invisible' ) ;
You can’t perform that action at this time.
0 commit comments