{
if(!pages[slug])slug=order[0];
pendingHash=hash||'';
if(slug===current){if(pendingHash)frame.contentWindow.postMessage({hfHash:pendingHash},'*');return}
current=slug;
document.title=pages[slug].title;
frame.srcdoc=expand(pages[slug].raw)
.replace(/]*)\sdata-theme="[^"]*"/i,'{
const d=e.data||{};
if(d.hfTheme&&d.hfTheme!==theme)theme=d.hfTheme;
if(d.hfReady){
frame.contentWindow.postMessage({hfTheme:theme},'*');
if(pendingHash){frame.contentWindow.postMessage({hfHash:pendingHash},'*');pendingHash=''}
}
if(d.hfNav){
const [file,hash]=String(d.hfNav).split('#');
const slug=byFile[file]||order[0];
// The address bar is the only place a plain file can keep history, so the back
// button works through the hash rather than through real navigation.
location.hash=slug+(hash?'/'+hash:'');
}
});
const fromHash=()=>{
const [slug,hash]=decodeURIComponent(location.hash.replace(/^#/,'')).split('/');
show(slug||order[0],hash||'');
};
addEventListener('hashchange',fromHash);
fromHash();
})()