|
9 | 9 | <link rel="preconnect" crossorigin="anonymous" href="https://fonts.googleapis.com"> |
10 | 10 | <link rel="preconnect" crossorigin="anonymous" href="https://fonts.gstatic.com"> |
11 | 11 | <link rel="stylesheet" crossorigin="anonymous" href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap"> |
| 12 | + |
| 13 | +<style> |
| 14 | + body { |
| 15 | + font-family: Roboto, sans-serif; |
| 16 | + } |
| 17 | + |
| 18 | + .sbdocs-content :is(h1, h2, h3, h4, h5, h6)[id] { |
| 19 | + scroll-margin-top: 8px; |
| 20 | + } |
| 21 | +</style> |
| 22 | + |
| 23 | +<script> |
| 24 | + (function docsAnchorScroll() { |
| 25 | + var ANCHOR_PREFIX = "anchor--"; |
| 26 | + var OBSERVE_MS = 20000; |
| 27 | + var cancelled = false; |
| 28 | + var observer = null; |
| 29 | + var timeoutId = null; |
| 30 | + var rafId = null; |
| 31 | + |
| 32 | + function cleanup() { |
| 33 | + cancelled = true; |
| 34 | + if (observer) { |
| 35 | + observer.disconnect(); |
| 36 | + observer = null; |
| 37 | + } |
| 38 | + if (timeoutId !== null) { |
| 39 | + clearTimeout(timeoutId); |
| 40 | + timeoutId = null; |
| 41 | + } |
| 42 | + if (rafId !== null) { |
| 43 | + cancelAnimationFrame(rafId); |
| 44 | + rafId = null; |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | + function targetIdFromHash() { |
| 49 | + var h = window.location.hash; |
| 50 | + if (!h || h.length < 2) { |
| 51 | + return null; |
| 52 | + } |
| 53 | + var id = decodeURIComponent(h.slice(1)); |
| 54 | + if (id.indexOf(ANCHOR_PREFIX) !== 0) { |
| 55 | + return null; |
| 56 | + } |
| 57 | + return id; |
| 58 | + } |
| 59 | + |
| 60 | + function tryScroll(targetId) { |
| 61 | + var el = document.getElementById(targetId); |
| 62 | + if (!el) { |
| 63 | + return false; |
| 64 | + } |
| 65 | + el.scrollIntoView({ block: "start", inline: "nearest", behavior: "auto" }); |
| 66 | + return true; |
| 67 | + } |
| 68 | + |
| 69 | + function scheduleScrollToHash() { |
| 70 | + cleanup(); |
| 71 | + cancelled = false; |
| 72 | + |
| 73 | + var targetId = targetIdFromHash(); |
| 74 | + if (!targetId) { |
| 75 | + return; |
| 76 | + } |
| 77 | + |
| 78 | + if (tryScroll(targetId)) { |
| 79 | + return; |
| 80 | + } |
| 81 | + |
| 82 | + observer = new MutationObserver(function () { |
| 83 | + if (!cancelled && tryScroll(targetId)) { |
| 84 | + cleanup(); |
| 85 | + } |
| 86 | + }); |
| 87 | + observer.observe(document.documentElement, { childList: true, subtree: true }); |
| 88 | + |
| 89 | + timeoutId = window.setTimeout(function () { |
| 90 | + cleanup(); |
| 91 | + }, OBSERVE_MS); |
| 92 | + |
| 93 | + function poll() { |
| 94 | + if (cancelled) { |
| 95 | + return; |
| 96 | + } |
| 97 | + if (tryScroll(targetId)) { |
| 98 | + cleanup(); |
| 99 | + return; |
| 100 | + } |
| 101 | + rafId = window.requestAnimationFrame(poll); |
| 102 | + } |
| 103 | + rafId = window.requestAnimationFrame(poll); |
| 104 | + } |
| 105 | + |
| 106 | + window.addEventListener("hashchange", scheduleScrollToHash); |
| 107 | + if (document.readyState === "loading") { |
| 108 | + document.addEventListener("DOMContentLoaded", scheduleScrollToHash); |
| 109 | + } else { |
| 110 | + scheduleScrollToHash(); |
| 111 | + } |
| 112 | + })(); |
| 113 | +</script> |
0 commit comments