|
| 1 | +import type { PageTemplate } from '@purestack/ts-common' |
| 2 | +import { h } from '@purestack/ts-html' |
| 3 | + |
| 4 | +const previewStyles = ` |
| 5 | +html,body{margin:0;min-height:0;height:auto} |
| 6 | +body.preview{display:block;min-height:0!important;padding:8px;box-sizing:border-box} |
| 7 | +.site-guide-samples{display:grid;grid-template-columns:repeat(auto-fit,minmax(min(100%,16rem),1fr));gap:1rem} |
| 8 | +.site-guide-sample{min-width:0} |
| 9 | +.site-guide-sample>code{display:block;margin:0 0 1rem} |
| 10 | +.site-guide-sample iframe{width:100%;border:0;display:block} |
| 11 | +.preview .nav__menu,.preview .page-toc{position:static!important;width:100%!important;max-height:none!important} |
| 12 | +.preview .page-toc__panel-toggle,.preview .page-toc__restore-toggle,.preview .nav__panel-toggle,.preview .nav__collapse-toggle{display:none!important} |
| 13 | +.site-guide-sample .consent{position:static!important;pointer-events:auto!important} |
| 14 | +.site-guide-sample .consent__banner{position:static!important;display:block!important;max-width:none!important;width:100%!important} |
| 15 | +.site-guide-sample .consent__panel,.site-guide-sample [data-consent-settings]{display:none!important} |
| 16 | +.site-guide-sample .site-footer{margin:0;padding:1rem} |
| 17 | +.site-guide-sample .site-footer__inner{padding:0} |
| 18 | +.site-guide-sample .site-footer__bottom{flex-direction:column!important;align-items:start!important} |
| 19 | +.site-guide-sample .sign-in__panel{position:static!important;transform:none!important;min-width:0!important;width:100%!important} |
| 20 | +.site-guide-sample .sign-in{width:100%} |
| 21 | +.preview .topbar{position:static!important;padding:.5rem!important} |
| 22 | +.site-guide-sample .topbar__search{min-width:0} |
| 23 | +.site-guide-sample .text-title{font-size:1.15rem;line-height:1.35} |
| 24 | +.site-guide-sample .site-logo{max-width:100%} |
| 25 | +` |
| 26 | + |
| 27 | +// Presentation only: page head, assets, and component runtimes come from PureStack. |
| 28 | +const frameScript = ` |
| 29 | +document.querySelectorAll('.site-guide-sample details.sign-in').forEach(menu=>menu.open=true); |
| 30 | +document.querySelectorAll('.site-guide-sample .consent__banner').forEach(banner=>{banner.hidden=false;banner.removeAttribute('aria-hidden')}); |
| 31 | +if(window.parent!==window){ |
| 32 | + const sync=()=>{document.documentElement.dataset.theme=parent.document.documentElement.dataset.theme||'light';document.documentElement.setAttribute('data-theme-ready','true')}; |
| 33 | + sync(); |
| 34 | + new MutationObserver(sync).observe(parent.document.documentElement,{attributes:true,attributeFilter:['data-theme']}); |
| 35 | + const minimumHeight=frameElement ? parseFloat(frameElement.style.height)||0 : 0; |
| 36 | + const resize=()=>{if(frameElement)frameElement.style.height=Math.max(minimumHeight,Math.ceil(document.body.getBoundingClientRect().height))+'px'}; |
| 37 | + new ResizeObserver(resize).observe(document.body); |
| 38 | + addEventListener('load',resize); |
| 39 | +} |
| 40 | +` |
| 41 | + |
| 42 | +export const previewTemplate: PageTemplate = ({ head, bodyHtml, pageInfo }) => { |
| 43 | + head.push(h('style').raw(previewStyles)) |
| 44 | + return h('html') |
| 45 | + .attr({ lang: pageInfo.locale ?? 'en' }) |
| 46 | + .push( |
| 47 | + head, |
| 48 | + h('body') |
| 49 | + .class('preview template-doc doc-content tone--neutral') |
| 50 | + .raw(bodyHtml) |
| 51 | + .push(h('script').raw(frameScript)), |
| 52 | + ) |
| 53 | +} |
0 commit comments