Same public API as choo 7.1.0 (use/route/start/mount/toString/emit; choo() callable with or without new, Choo exported). nanobus, nanorouter+wayfarer, nanolru+component cache, nanoraf, nanohref, nanotiming, document-ready and scroll-to-anchor are ported into lib/ with per-file attribution; nanoquery is replaced by URLSearchParams. The v7 node test suite is ported from tape to node:test and passes unchanged in behavior. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014NgfSjHE11oFpoSnLVKLXd
26 lines
740 B
JavaScript
26 lines
740 B
JavaScript
// Ported from document-ready 2.0.1 and scroll-to-anchor 1.0.0 (MIT)
|
|
// https://github.com/bendrucker/document-ready — https://github.com/yoshuawuyts/scroll-to-anchor
|
|
|
|
import { notEqual } from './assert.js'
|
|
|
|
export function documentReady (callback) {
|
|
notEqual(typeof document, 'undefined', 'documentReady only runs in the browser')
|
|
const state = document.readyState
|
|
if (state === 'complete' || state === 'interactive') {
|
|
return setTimeout(callback, 0)
|
|
}
|
|
|
|
document.addEventListener('DOMContentLoaded', function onLoad () {
|
|
callback()
|
|
})
|
|
}
|
|
|
|
export function scrollToAnchor (anchor) {
|
|
if (anchor) {
|
|
try {
|
|
const el = document.querySelector(anchor)
|
|
if (el) el.scrollIntoView(true)
|
|
} catch (e) {}
|
|
}
|
|
}
|