mirror of
https://github.com/john-okeefe/foliate-js.git
synced 2026-09-09 11:29:14 -04:00
EPUB: fix media: properties
This commit is contained in:
@@ -165,12 +165,23 @@ const getMetadata = opf => {
|
|||||||
: getValue(obj, arr.find(filter))]
|
: getValue(obj, arr.find(filter))]
|
||||||
}))
|
}))
|
||||||
|
|
||||||
const getProperties = prefix => Object.fromEntries($$($metadata, 'meta')
|
const $$meta = $$($metadata, 'meta')
|
||||||
|
const getMetasByPrefix = prefix => $$meta
|
||||||
.filter(filterAttribute('property', x => x?.startsWith(prefix)))
|
.filter(filterAttribute('property', x => x?.startsWith(prefix)))
|
||||||
.map(el => [el.getAttribute('property').replace(prefix, ''),
|
.map(el => [el.getAttribute('property').replace(prefix, ''), el])
|
||||||
getElementText(el)]))
|
|
||||||
const rendition = getProperties('rendition:')
|
const rendition = Object.fromEntries(getMetasByPrefix('rendition:')
|
||||||
const media = getProperties('media:')
|
.map(([k, el]) => [k, getElementText(el)]))
|
||||||
|
|
||||||
|
const media = { narrator: [], duration: {} }
|
||||||
|
for (const [k, el] of getMetasByPrefix('media:')) {
|
||||||
|
const v = getElementText(el)
|
||||||
|
if (k === 'duration') media.duration[
|
||||||
|
el.getAttribute('refines')?.split('#')?.[1] ?? ''] = parseClock(v)
|
||||||
|
else if (k === 'active-class') media.activeClass = v
|
||||||
|
else if (k === 'narrator') media.narrator.push(v)
|
||||||
|
else if (k === 'playback-active-class') media.playbackActiveClass = v
|
||||||
|
}
|
||||||
return { metadata, rendition, media }
|
return { metadata, rendition, media }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -114,7 +114,8 @@ export class View extends HTMLElement {
|
|||||||
this.#root.append(this.renderer)
|
this.#root.append(this.renderer)
|
||||||
|
|
||||||
if (book.sections.some(section => section.mediaOverlay)) {
|
if (book.sections.some(section => section.mediaOverlay)) {
|
||||||
const activeClass = book.media['active-class']
|
book.media.activeClass ||= '-epub-media-overlay-active'
|
||||||
|
const activeClass = book.media.activeClass
|
||||||
this.mediaOverlay = book.getMediaOverlay()
|
this.mediaOverlay = book.getMediaOverlay()
|
||||||
let lastActive
|
let lastActive
|
||||||
this.mediaOverlay.addEventListener('highlight', e => {
|
this.mediaOverlay.addEventListener('highlight', e => {
|
||||||
|
|||||||
Reference in New Issue
Block a user