mirror of
https://github.com/john-okeefe/foliate-js.git
synced 2026-09-09 11:29:14 -04:00
Add destroy method
Which revokes all blob URLs and removes the element from document.
This commit is contained in:
@@ -611,6 +611,9 @@ class Loader {
|
||||
unloadItem(item) {
|
||||
this.unref(item?.href)
|
||||
}
|
||||
destroy() {
|
||||
for (const url of this.#cache.values()) URL.revokeObjectURL(url)
|
||||
}
|
||||
}
|
||||
|
||||
const getHTMLFragment = (doc, id) => doc.getElementById(id)
|
||||
@@ -628,6 +631,7 @@ const getPageSpread = properties => {
|
||||
|
||||
export class EPUB {
|
||||
parser = new DOMParser()
|
||||
#loader
|
||||
#encryption
|
||||
constructor({ loadText, loadBlob, getSize, sha1 }) {
|
||||
this.loadText = loadText
|
||||
@@ -662,7 +666,7 @@ export class EPUB {
|
||||
opf,
|
||||
resolveHref: url => resolveURL(url, opfPath),
|
||||
})
|
||||
const loader = new Loader({
|
||||
this.#loader = new Loader({
|
||||
loadText: this.loadText,
|
||||
loadBlob: uri => Promise.resolve(this.loadBlob(uri))
|
||||
.then(this.#encryption.getDecoder(uri)),
|
||||
@@ -677,8 +681,8 @@ export class EPUB {
|
||||
}
|
||||
return {
|
||||
id: this.resources.getItemByID(idref)?.href,
|
||||
load: () => loader.loadItem(item),
|
||||
unload: () => loader.unloadItem(item),
|
||||
load: () => this.#loader.loadItem(item),
|
||||
unload: () => this.#loader.unloadItem(item),
|
||||
createDocument: () => this.loadDocument(item),
|
||||
size: this.getSize(item.href),
|
||||
cfi: this.resources.cfis[index],
|
||||
@@ -805,4 +809,7 @@ export class EPUB {
|
||||
return JSON.parse(json)
|
||||
}
|
||||
}
|
||||
destroy() {
|
||||
this.#loader?.destroy()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user