diff --git a/README.md b/README.md index e3e96c2..296a1ac 100644 --- a/README.md +++ b/README.md @@ -118,10 +118,11 @@ Place `<%= image[IMG_ID] %>` inside the chapter's content *(HTML string only)*, ### Generate EPUB `*` ```typescript -jepub.generate(type = 'blob') +jepub.generate(type = 'blob', onUpdate?: metadata => void) ``` - **type**: The type of EPUB to return. See [JSZip type option](https://stuk.github.io/jszip/documentation/api_jszip/generate_async.html#type-option). +- **onUpdate**: _(optional)_ Callback function. See [JSZip onUpdate callback](https://stuk.github.io/jszip/documentation/api_jszip/generate_async.html#onupdate-callback). ### Static methods `+` diff --git a/demo/script.js b/demo/script.js index c9fb1d6..7bc3806 100644 --- a/demo/script.js +++ b/demo/script.js @@ -42,7 +42,10 @@ ]); console.log(jepub); - const blob = await jepub.generate(); + const blob = await jepub.generate('blob', metadata => { + console.log('progression: ' + metadata.percent.toFixed(2) + ' %'); + if (metadata.currentFile) console.log('current file = ' + metadata.currentFile); + }); console.log(blob); let url = URL.createObjectURL(blob); diff --git a/src/jepub.js b/src/jepub.js index 31aa75a..06113f2 100644 --- a/src/jepub.js +++ b/src/jepub.js @@ -188,7 +188,7 @@ export default class jEpub { } } - generate(type = 'blob') { + generate(type = 'blob', onUpdate) { if (!JSZip.support[type]) throw `This browser does not support ${type}`; let notes = this._Zip.file('OEBPS/notes.html'); @@ -236,6 +236,6 @@ export default class jEpub { compressionOptions: { level: 9 } - }); + }, onUpdate); } }