mirror of
https://github.com/john-okeefe/foliate-js.git
synced 2026-09-09 11:29:14 -04:00
Get rect in reader instead of view
Also expose index in `loaded` event
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/* global zip: false, fflate: false */
|
||||
import { View } from './view.js'
|
||||
import { View, getPosition } from './view.js'
|
||||
import { createTOCView } from './ui/tree.js'
|
||||
import { createMenu } from './ui/menu.js'
|
||||
import { createPopover } from './ui/popover.js'
|
||||
@@ -234,7 +234,8 @@ class Reader {
|
||||
if (tocItem?.href) this.#tocView?.setCurrentHref?.(tocItem.href)
|
||||
}
|
||||
#onReference(obj) {
|
||||
const { content, pos: { point, dir } } = obj
|
||||
const { content, element } = obj
|
||||
const { point, dir } = getPosition(element)
|
||||
const iframe = document.createElement('iframe')
|
||||
iframe.sandbox = 'allow-same-origin'
|
||||
iframe.srcdoc = content
|
||||
|
||||
@@ -194,7 +194,6 @@ export class View {
|
||||
this.emit?.({ type: 'external-link', uri })
|
||||
else if (SSV.isRef(a)) {
|
||||
const { index, anchor } = book.resolveHref(uri)
|
||||
const pos = getPosition(a)
|
||||
Promise.resolve(book.sections[index].createDocument())
|
||||
.then(doc => [anchor(doc), doc.contentType])
|
||||
.then(([el, type]) =>
|
||||
@@ -203,14 +202,14 @@ export class View {
|
||||
? this.emit?.({
|
||||
type: 'reference',
|
||||
href: isNote ? null : uri,
|
||||
content, contentType, pos,
|
||||
content, contentType, element: a,
|
||||
}) : null)
|
||||
.catch(e => console.error(e))
|
||||
return
|
||||
} else this.goTo(uri)
|
||||
})
|
||||
|
||||
this.emit?.({ type: 'loaded', doc })
|
||||
this.emit?.({ type: 'loaded', doc, index })
|
||||
}
|
||||
#drawAnnotation(doc, overlayer, annotation) {
|
||||
const { value } = annotation
|
||||
@@ -230,8 +229,7 @@ export class View {
|
||||
doc.addEventListener('click', e => {
|
||||
const [value, range] = overlayer.hitTest(e)
|
||||
if (value) {
|
||||
const pos = getPosition(range)
|
||||
this.emit?.({ type: 'show-annotation', value, pos })
|
||||
this.emit?.({ type: 'show-annotation', value, range })
|
||||
}
|
||||
}, false)
|
||||
return overlayer
|
||||
@@ -241,8 +239,7 @@ export class View {
|
||||
const { index, anchor } = await this.goTo(value)
|
||||
const { doc } = this.#getOverlayer(index)
|
||||
const range = anchor(doc)
|
||||
const pos = getPosition(range)
|
||||
this.emit?.({ type: 'show-annotation', value, pos })
|
||||
this.emit?.({ type: 'show-annotation', value, range })
|
||||
}
|
||||
getCFI(index, range) {
|
||||
if (!range) return ''
|
||||
|
||||
Reference in New Issue
Block a user