diff --git a/__src/bibi/extensions/extractor/at-once.js b/__src/bibi/extensions/extractor/at-once.js index 68122d2c..9cfefcb6 100644 --- a/__src/bibi/extensions/extractor/at-once.js +++ b/__src/bibi/extensions/extractor/at-once.js @@ -100,8 +100,8 @@ Bibi.x({ Promises.push( BookDataArchive.file(FolderName + FileName).async(IsBin ? 'blob' : 'string').then(FileContent => { const Item = B.Package.Manifest.Items[FileName] = IsBin ? - { Path: FileName, DataType: 'blob', Content: FileContent } : - { Path: FileName, DataType: 'text', Content: FileContent.trim() }; + { Path: FileName, DataType: 'Blob', Content: FileContent } : + { Path: FileName, DataType: 'Text', Content: FileContent.trim() }; for(const FileType in FileTypesToBeCounted) { if(new RegExp('\\.(' + FileTypesToBeCounted[FileType] + ')$', 'i').test(FileName)) { if(!FileCount[FileType]) FileCount[FileType] = 1; else FileCount[FileType]++; diff --git a/__src/bibi/resources/scripts/bibi.heart.js b/__src/bibi/resources/scripts/bibi.heart.js index def5f19a..3639b14c 100644 --- a/__src/bibi/resources/scripts/bibi.heart.js +++ b/__src/bibi/resources/scripts/bibi.heart.js @@ -231,8 +231,8 @@ Bibi.initialize = () => { //const PromiseTryingRangeRequest = O.tryRangeRequest().then(() => true).catch(() => false).then(TF => O.RangeRequest = TF); { // Path / URI O.Origin = location.origin || (location.protocol + '//' + (location.host || (location.hostname + (location.port ? ':' + location.port : '')))); + O.Local = location.protocol == 'file:'; O.RequestedURL = location.href; - O.BookURL = O.Origin + location.pathname + location.search; } { // DOM O.contentWindow = window; @@ -517,7 +517,7 @@ Bibi.openBook = (LayoutOption) => new Promise(resolve => { setTimeout(() => R.turnSpreads(), 123); E.add(['bibi:scrolled', 'bibi:changed-intersection'], () => R.turnSpreads()); } - if(S['resume-from-last-position']) E.add('bibi:changed-intersection', () => { try { O.Biscuits.memorize('Book', { Position: { IIPP: I.PageObserver.getIIPP() } }); } catch(Err) {} }); + if(S['resume-from-last-position']) E.add('bibi:changed-intersection', () => { try { if(O.Biscuits) O.Biscuits.memorize('Book', { Position: { IIPP: I.PageObserver.getIIPP() } }); } catch(Err) {} }); E.add('bibi:commands:move-by', R.moveBy); E.add('bibi:commands:scroll-by', R.scrollBy); E.add('bibi:commands:focus-on', R.focusOn); @@ -666,10 +666,11 @@ L.initializeBook = (Par) => new Promise((resolve, reject) => { let BookData = Par.BookData; const BookDataFormat = typeof BookData == 'string' ? (/^data:/.test(BookData) ? 'Base64' : 'URI') : - typeof BookData == 'object' ? (BookData instanceof File ? 'File' : BookData instanceof Blob ? 'BLOB' : '') : ''; + typeof BookData == 'object' ? (BookData instanceof File ? 'File' : BookData instanceof Blob ? 'Blob' : '') : ''; if(!BookDataFormat) return reject(`Book Data Is Unknown.`); if(BookDataFormat == 'URI') { // Online + if(O.Local) return reject(`Bibi Can't Open Books via URL on Local Mode.`); B.Path = BookData; let RootFile; switch(B.Type) { @@ -727,9 +728,9 @@ L.initializeBook = (Par) => new Promise((resolve, reject) => { } B.Path = '[Base64 Encoded Data]'; } else { - // BLOB of EPUB/Zine Data - if(!S['accept-blob-converted-data']) return reject(`To Open BLOB Converted Data, Changing "accept-blob-converted-data" in default.js Is Required.`); - B.Path = '[BLOB Converted Data]'; + // Blob of EPUB/Zine Data + if(!S['accept-blob-converted-data']) return reject(`To Open Blob Converted Data, Changing "accept-blob-converted-data" in default.js Is Required.`); + B.Path = '[Blob Converted Data]'; } if(!MIMETypeREs['EPUB'].test(BookData.type) && !MIMETypeREs['Zine'].test(BookData.type)) return reject(MIMETypeErrorMessage); FileOrData = 'Data'; @@ -776,6 +777,8 @@ L.loadPackage = () => O.openDocument(B.Package).then(L.loadPackage.process).then // METADATA // -------------------------------------------------------------------------------- const DCNS = _Package.getAttribute('xmlns:dc') || _Metadata.getAttribute('xmlns:dc'); + const UIDID = _Package.getAttribute('unique-identifier'), UIDE = UIDID ? Doc.getElementById(UIDID) : null, UIDTC = UIDE ? UIDE.textContent : ''; + Metadata['unique-identifier'] = UIDTC ? UIDTC.trim() : ''; ['identifier', 'language', 'title', 'creator', 'publisher'].forEach(Pro => sML.forEach(Doc.getElementsByTagNameNS(DCNS, Pro))(_Meta => (Metadata[Pro] ? Metadata[Pro] : Metadata[Pro] = []).push(_Meta.textContent.trim()))); sML.forEach(_Metadata.getElementsByTagName('meta'))(_Meta => { if(_Meta.getAttribute('refines')) return; // Should be solved. @@ -795,7 +798,7 @@ L.loadPackage = () => O.openDocument(B.Package).then(L.loadPackage.process).then } }); // -------------------------------------------------------------------------------- - if(!Metadata['identifier']) Metadata['identifier'] = Metadata['dcterms:identifier'] || [O.BookURL]; + if(!Metadata['identifier']) Metadata['identifier'] = Metadata['dcterms:identifier'] || []; if(!Metadata['language' ]) Metadata['language' ] = Metadata['dcterms:language' ] || ['en']; if(!Metadata['title' ]) Metadata['title' ] = Metadata['dcterms:title' ] || Metadata['identifier']; // -------------------------------------------------------------------------------- @@ -948,8 +951,8 @@ L.loadPackage = () => O.openDocument(B.Package).then(L.loadPackage.process).then // -------------------------------------------------------------------------------- B.FileDigit = (Spine.Items.length + '').length; // ================================================================================ - B.ID = Metadata['identifier'][0]; - B.Language = Metadata['language' ][0].split('-')[0]; + B.ID = Metadata['unique-identifier'] || Metadata['identifier'][0] || ''; + B.Language = Metadata['language'][0].split('-')[0]; B.Title = Metadata['title' ].join(', '); B.Creator = !Metadata['creator' ] ? '' : Metadata['creator' ].join(', '); B.Publisher = !Metadata['publisher' ] ? '' : Metadata['publisher'].join(', '); @@ -1134,7 +1137,7 @@ L.coordinateLinkages = (BasePath, RootElement, InNav) => { }); -L.preprocessResources = () => new Promise((resolve, reject) => { +L.preprocessResources = () => { E.dispatch('bibi:is-going-to:preprocess-resources'); const Promises = [], PreprocessedResources = [], pushItemPreprocessingPromise = (Item, URI) => Promises.push(O.file(Item, { Preprocess: true, URI: URI }).then(() => PreprocessedResources.push(Item))); if(B.ExtractionPolicy) for(const FilePath in B.Package.Manifest.Items) { @@ -1144,7 +1147,7 @@ L.preprocessResources = () => new Promise((resolve, reject) => { pushItemPreprocessingPromise(Item, true); } } - Promise.all(Promises).then(() => {/* + return Promise.all(Promises).then(() => {/* if(B.ExtractionPolicy != 'at-once' && (S.BRL == 'pre-paginated' || (sML.UA.Chromium || sML.UA.WebKit || sML.UA.Gecko))) return resolve(PreprocessedResources); R.Items.forEach(Item => pushItemPreprocessingPromise(Item, O.isBin(Item))); // Spine Items return Promise.all(Promises).then(() => resolve(PreprocessedResources));*/ @@ -1153,9 +1156,8 @@ L.preprocessResources = () => new Promise((resolve, reject) => { O.log(`Preprocessed. (${ PreprocessedResources.length } Resource${ PreprocessedResources.length > 1 ? 's' : '' })`, ''); } E.dispatch('bibi:preprocessed-resources'); - resolve(); }); -}); +}; L.loadSpread = (Spread, Opt = {}) => new Promise((resolve, reject) => { @@ -1187,7 +1189,7 @@ L.loadItem = (Item, Opt = {}) => { // !!!! Don't Call Directly. Use L.loadSpread } ItemBox.classList.remove('loaded'); return new Promise((resolve, reject) => { - if(Item.BlobURL) { + if(Item.ContentURL) { resolve(); } else if(/\.(html?|xht(ml)?|xml)$/i.test(Item.Path)) { // (X)HTML O.file(Item, { @@ -1220,10 +1222,11 @@ L.loadItem = (Item, Opt = {}) => { // !!!! Don't Call Directly. Use L.loadSpread }).then(Source => new Promise(resolve => { const DefaultStyleID = 'bibi-default-style'; Item.setAttribute('sandbox', 'allow-same-origin allow-scripts'); - if(!Item.BlobURL) { + let Promised = null; + if(!Item.ContentURL) { let HTML = typeof Source == 'string' ? Source : `\n