Skip to content

Commit

Permalink
chore: fix build on server
Browse files Browse the repository at this point in the history
  • Loading branch information
onmax committed Apr 25, 2024
1 parent 13b71a2 commit b13546c
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .vitepress/theme/components/DocAsideItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ defineProps<{
function onClick({ target: el }: Event) {
const id = (el as HTMLAnchorElement).href!.split('#')[1]
const heading = document.getElementById(decodeURIComponent(id))
const heading = globalThis.document?.getElementById(decodeURIComponent(id))
heading?.focus({ preventScroll: true })
}
</script>
Expand Down
4 changes: 2 additions & 2 deletions .vitepress/theme/components/Sidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const { sidebarGroups, hasSidebar } = useSidebar() as unknown as { sidebarGroups
// a11y: focus Nav element when menu has opened
const navEl = ref<HTMLElement | null>(null)
const isLocked = useScrollLock(inBrowser ? document.body : null)
const isLocked = useScrollLock(inBrowser ? globalThis.document.body : null)
watch(
[props, navEl],
Expand Down Expand Up @@ -66,7 +66,7 @@ function onSectionTitleClicked(i: number) {

<ul pb-20>
<li v-for="item in group.items" :key="item.text">
<SidebarItem :item="item" :depth="0" :class="item.items ? 'my32' : ''" />
<SidebarItem :item="item" :depth="0" :class="item.items ? 'my-32' : ''" />
</li>
</ul>
</template>
Expand Down
4 changes: 3 additions & 1 deletion .vitepress/theme/components/header/ThemeSwitcher.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<script setup lang="ts">
import { inBrowser } from 'vitepress';
/**
* Credit to [@hooray](https://github.com/hooray)
* @see https://github.com/vuejs/vitepress/pull/2347
Expand All @@ -8,7 +10,7 @@
const { isDark } = useData()
const enableTransitions = () => 'startViewTransition' in document && window.matchMedia('(prefers-reduced-motion: no-preference)').matches
const enableTransitions = () => inBrowser && 'startViewTransition' in globalThis?.document && globalThis?.window.matchMedia('(prefers-reduced-motion: no-preference)').matches
function getHexagonPoints(x: number, y: number, r: number): string {
const angles = [0, 60, 120, 180, 240, 300]
Expand Down
8 changes: 4 additions & 4 deletions .vitepress/theme/composables/icons/icon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ export async function getSvg(icon: string, size = '1em', color = 'currentColor')
export async function getSvgSymbol(icon: string, size = '1em', color = 'currentColor') {
const svgMarkup = await getSvg(icon, size, color)

const symbolElem = document.createElementNS('http://www.w3.org/2000/svg', 'symbol')
const node = document.createElement('div') // Create any old element
const symbolElem = globalThis.document?.createElementNS('http://www.w3.org/2000/svg', 'symbol')
const node = globalThis.document.createElement('div') // Create any old element
node.innerHTML = svgMarkup

// Grab the inner HTML and move into a symbol element
Expand All @@ -79,7 +79,7 @@ export function toComponentName(icon: string) {
}

export function ClearSvg(svgCode: string, reactJSX?: boolean) {
const el = document.createElement('div')
const el = globalThis.document?.createElement('div')
el.innerHTML = svgCode
const svg = el.getElementsByTagName('svg')[0]
const keep = ['viewBox', 'width', 'height', 'focusable', 'xmlns', 'xlink']
Expand Down Expand Up @@ -176,7 +176,7 @@ function convertSvgToPngDataUri(svgString: string, scale=1) {
const img = new Image();

img.onload = function() {
const canvas = document.createElement('canvas');
const canvas = globalThis.document?.createElement('canvas');
canvas.width = img.width * scale;
canvas.height = img.height * scale;
const ctx = canvas.getContext('2d');
Expand Down
4 changes: 2 additions & 2 deletions .vitepress/theme/composables/useIsActive.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { inBrowser } from "vitepress"

export const HASH_RE = /#.*$/
export const EXT_RE = /(index)?\.(md|html)$/

export function normalize(path: string): string {
return decodeURI(path).replace(HASH_RE, '').replace(EXT_RE, '')
}

export const inBrowser = typeof document !== 'undefined'

export function isActive(currentPath: string, matchPath?: string, asRegex: boolean = false): boolean {
if (matchPath === undefined)
return false
Expand Down
6 changes: 3 additions & 3 deletions .vitepress/theme/composables/useOutline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function resolveTitle(theme: DefaultTheme.Config) {

export function getHeaders(range: DefaultTheme.Config['outline']) {
const headers = [
...Array.from(document.querySelectorAll('.prose :where(h1,h2,h3,h4,h5,h6)')),
...Array.from(globalThis.document?.querySelectorAll('.prose :where(h1,h2,h3,h4,h5,h6)')),
]
.filter(el => el.id && el.hasChildNodes())
.map((el) => {
Expand Down Expand Up @@ -132,7 +132,7 @@ export function useActiveAnchor(

const scrollY = window.scrollY
const innerHeight = window.innerHeight
const offsetHeight = document.body.offsetHeight
const offsetHeight = globalThis.document.body.offsetHeight
const isBottom = Math.abs(scrollY + innerHeight - offsetHeight) < 1

// resolvedHeaders may be repositioned, hidden or fix positioned
Expand Down Expand Up @@ -202,7 +202,7 @@ export function useActiveAnchor(

function getAbsoluteTop(element: HTMLElement): number {
let offsetTop = 0
while (element !== document.body) {
while (element !== globalThis.document.body) {
if (element === null) {
// child element is:
// - not attached to the DOM (display: none)
Expand Down
2 changes: 1 addition & 1 deletion .vitepress/theme/composables/useSidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export function useCloseSidebarOnEscape(

watchEffect(() => {
triggerElement = isOpen.value
? (document.activeElement as HTMLButtonElement)
? (globalThis.document?.activeElement as HTMLButtonElement)
: undefined
})

Expand Down
2 changes: 1 addition & 1 deletion build/rpc-docs/.version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.20.3
0.21.0
2 changes: 2 additions & 0 deletions build/ui/design/icons.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ next: false

# Nimiq Icons

<ClientOnly>
<IconSet class="mt-32 pb-96 raw">
<template #learn-how-to-use-the-icons>

Expand Down Expand Up @@ -39,3 +40,4 @@ Check out [this blog](https://antfu.me/posts/journey-with-icons-continues) post

</template>
</IconSet>
</ClientOnly>

0 comments on commit b13546c

Please sign in to comment.