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 @@ -56,10 +56,21 @@ export async function renderMermaid() {
5656 btn . setAttribute ( 'data-clipboard-text' , source ) ;
5757 mermaidBlock . append ( btn ) ;
5858
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+
5970 iframe . addEventListener ( 'load' , ( ) => {
6071 pre . replaceWith ( mermaidBlock ) ;
6172 mermaidBlock . classList . remove ( 'tw-hidden' ) ;
62- iframe . style . height = ` ${ iframe . contentWindow . document . body . clientHeight } px` ;
73+ updateIframeHeight ( ) ;
6374 setTimeout ( ( ) => { // avoid flash of iframe background
6475 mermaidBlock . classList . remove ( 'is-loading' ) ;
6576 iframe . classList . remove ( 'tw-invisible' ) ;
You can’t perform that action at this time.
0 commit comments