diff --git a/src/foliate-js b/src/foliate-js index e94b85ce..ba403301 160000 --- a/src/foliate-js +++ b/src/foliate-js @@ -1 +1 @@ -Subproject commit e94b85ce09520e003d4e4fe84ce7f6d82eb0231e +Subproject commit ba403301a242e9ca4d879408f7bbc827d3fc30b1 diff --git a/src/reader/reader.js b/src/reader/reader.js index 01760a96..5c4731d0 100644 --- a/src/reader/reader.js +++ b/src/reader/reader.js @@ -291,42 +291,7 @@ footnoteDialog.addEventListener('close', () => { footnoteDialog.addEventListener('click', e => e.target === footnoteDialog ? footnoteDialog.close() : null) -class CursorAutohider { - #timeout - #el - #check - #state - constructor(el, check, state = {}) { - this.#el = el - this.#check = check - this.#state = state - if (this.#state.hidden) this.hide() - this.#el.addEventListener('mousemove', ({ screenX, screenY }) => { - // check if it actually moved - if (screenX === this.#state.x && screenY === this.#state.y) return - this.#state.x = screenX, this.#state.y = screenY - this.show() - if (this.#timeout) clearTimeout(this.#timeout) - if (check()) this.#timeout = setTimeout(this.hide.bind(this), 1000) - }, false) - } - cloneFor(el) { - return new CursorAutohider(el, this.#check, this.#state) - } - hide() { - this.#el.style.cursor = 'none' - this.#state.hidden = true - } - show() { - this.#el.style.cursor = 'auto' - this.#state.hidden = false - } -} - class Reader { - autohideCursor - #cursorAutohider = new CursorAutohider( - document.documentElement, () => this.autohideCursor) #footnoteHandler = new FootnoteHandler() style = { spacing: 1.4, @@ -406,7 +371,8 @@ class Reader { renderer.setStyles?.(getCSS(this.style)) } document.body.classList.toggle('invert', this.style.invert) - this.autohideCursor = autohideCursor + if (autohideCursor) this.view?.setAttribute('autohide-cursor', '') + else this.view?.removeAttribute('autohide-cursor') } #handleEvents() { this.view.addEventListener('relocate', e => { @@ -492,8 +458,6 @@ class Reader { const text = sel.toString() this.#showSelection({ index, range, lang, value, pos, text }) }) - - this.#cursorAutohider.cloneFor(doc.documentElement) } #showAnnotation({ index, range, value, pos }) { globalThis.showSelection({ type: 'annotation', value, pos })