From a16ba080b6b24584e83470dd3e7ab1f78e6312cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Satoru=20Matsushima=20=28=E2=84=A0=29?= Date: Tue, 26 May 2020 14:43:26 +0900 Subject: [PATCH 1/4] Update libraries. --- package-lock.json | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index f953974c..f0992fa1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7649,9 +7649,9 @@ "dev": true }, "postcss": { - "version": "7.0.30", - "resolved": "https://registry.npmjs.org/postcss/-/postcss-7.0.30.tgz", - "integrity": "sha512-nu/0m+NtIzoubO+xdAlwZl/u5S5vi/y6BCsoL8D+8IxsD3XvBS8X4YEADNIVXKVuQvduiucnRv+vPIqj56EGMQ==", + "version": "7.0.31", + "resolved": "https://registry.npmjs.org/postcss/-/postcss-7.0.31.tgz", + "integrity": "sha512-a937VDHE1ftkjk+8/7nj/mrjtmkn69xxzJgRETXdAUU+IgOYPQNJF17haGWbeDxSyk++HA14UA98FurvPyBJOA==", "dev": true, "requires": { "chalk": "^2.4.2", diff --git a/package.json b/package.json index 5d47a6a6..68a2e2d6 100644 --- a/package.json +++ b/package.json @@ -57,7 +57,7 @@ "mini-css-extract-plugin": "^0.9.0", "node-sass": "^4.14.1", "npm-run-all": "^4.1.5", - "postcss": "^7.0.30", + "postcss": "^7.0.31", "postcss-cssnext": "^3.1.0", "postcss-loader": "^3.0.0", "sass-loader": "^8.0.2", From aef9a211b790a8c2e015fd75bf9d20808c28605e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Satoru=20Matsushima=20=28=E2=84=A0=29?= Date: Tue, 26 May 2020 19:48:21 +0900 Subject: [PATCH 2/4] Fix history counting of page flipping by Slider UI. --- __src/bibi/resources/scripts/bibi.heart.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/__src/bibi/resources/scripts/bibi.heart.js b/__src/bibi/resources/scripts/bibi.heart.js index def5f19a..54fe6f91 100644 --- a/__src/bibi/resources/scripts/bibi.heart.js +++ b/__src/bibi/resources/scripts/bibi.heart.js @@ -4081,8 +4081,8 @@ I.History = { update: () => I.History.Updaters.forEach(fun => fun()), add: (Opt = {}) => { if(!Opt.UI) Opt.UI = Bibi; - const CurrentPage = Opt.Destination ? R.hatchPage(Opt.Destination) : (() => { I.PageObserver.updateCurrent(); return I.PageObserver.Current.List[0].Page; })(), - LastPage = R.hatchPage(I.History.List.slice(-1)[0]); + const LastPage = R.hatchPage(I.History.List.slice(-1)[0]), + CurrentPage = Opt.Destination ? R.hatchPage(Opt.Destination) : (() => { I.PageObserver.updateCurrent(); return I.PageObserver.Current.List[0].Page; })(); if(CurrentPage != LastPage) { if(Opt.SumUp && I.History.List.slice(-1)[0].UI == Opt.UI) I.History.List.pop(); I.History.List.push({ UI: Opt.UI, IIPP: I.PageObserver.getIIPP(CurrentPage) }); @@ -4157,7 +4157,6 @@ I.Slider = { create: () => { onTouchStart: (Eve) => { I.ScrollObserver.forceStopScrolling(); Eve.preventDefault(); - if(Slider.History) Slider.History.add({ Page: I.PageObserver.Current.List[0].Page }); Slider.Touching = true; Slider.StartedOn = { ThumbBefore: O.getElementCoord(Slider.Thumb)[C.A_AXIS_L], @@ -4197,11 +4196,11 @@ I.Slider = { create: () => { const TouchEndCoord = O.getBibiEventCoord(Eve)[C.A_AXIS_L]; if(TouchEndCoord == Slider.StartedOn.Coord) Slider.StartedOn.Coord = Slider.StartedOn.ThumbBefore + Slider.Thumb.Length / 2; R.DoNotTurn = false; - Slider.flip(TouchEndCoord).then(Destination => { + Slider.flip(TouchEndCoord).then(() => { sML.style(Slider.Thumb, { transform: '' }); sML.style(Slider.RailProgress, { [C.A_SIZE_l]: '' }); Slider.progress(); - if(Slider.History) Slider.History.add(Destination); + if(Slider.History) Slider.History.add(); }); delete Slider.StartedOn; Slider.Timer_onTouchEnd = setTimeout(() => O.HTML.classList.remove('slider-sliding'), 123); @@ -4209,7 +4208,7 @@ I.Slider = { create: () => { flip: (TouchedCoord) => new Promise(resolve => { switch(S.RVM) { case 'paged': const TargetPage = Slider.getPointedPage(TouchedCoord); - return I.PageObserver.Current.Pages.includes(TargetPage) ? resolve() : R.focusOn({ Destination: TargetPage, Duration: 0 }).then(resolve); + return I.PageObserver.Current.Pages.includes(TargetPage) ? resolve() : R.focusOn({ Destination: TargetPage, Duration: 0 }).then(() => resolve()); default: R.Main['scroll' + C.L_OOBL_L] = Slider.StartedOn.MainScrollBefore + (TouchedCoord - Slider.StartedOn.Coord) * (Slider.MainLength / Slider.Edgebar.Length); return resolve(); From f73a08e0b63a95922238dbd3930bd00bcab6bd32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Satoru=20Matsushima=20=28=E2=84=A0=29?= Date: Tue, 26 May 2020 09:49:10 +0900 Subject: [PATCH 3/4] Get unique-identifier more accurately --- __src/bibi/resources/scripts/bibi.heart.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/__src/bibi/resources/scripts/bibi.heart.js b/__src/bibi/resources/scripts/bibi.heart.js index 54fe6f91..0dc3603f 100644 --- a/__src/bibi/resources/scripts/bibi.heart.js +++ b/__src/bibi/resources/scripts/bibi.heart.js @@ -776,6 +776,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 +797,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 +950,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(', '); @@ -5791,7 +5793,11 @@ O.Biscuits = { E.bind('bibi:initialized-book', () => O.Biscuits.initialize('Book')); return null; } - if(Tag != 'Bibi' && Tag != 'Book') return null; + switch(Tag) { + case 'Bibi': break; + case 'Book': if(B.ID) break; + default: return null; + } const Label = O.Biscuits.Labels[Tag] = O.Biscuits.LabelBase + (Tag == 'Book' ? '#' + B.ID.replace(/^urn:uuid:/, '') : ''); const BiscuitsOfTheLabel = localStorage.getItem(Label); O.Biscuits.Memories[Label] = BiscuitsOfTheLabel ? JSON.parse(BiscuitsOfTheLabel) : {}; From 649181f01121ced4598c55f14647824964d7de9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Satoru=20Matsushima=20=28=E2=84=A0=29?= Date: Tue, 26 May 2020 09:52:53 +0900 Subject: [PATCH 4/4] Refactor file processing and recover local-reader-mode. --- __src/bibi/extensions/extractor/at-once.js | 4 +- __src/bibi/resources/scripts/bibi.heart.js | 119 ++++++++++----------- __src/bibi/resources/scripts/bibi.js | 31 +++--- 3 files changed, 75 insertions(+), 79 deletions(-) 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 0dc3603f..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'; @@ -1136,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) { @@ -1146,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));*/ @@ -1155,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) => { @@ -1189,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, { @@ -1222,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${ B.FullTitle } - #${ Item.Index + 1 }/${ R.Items.length }${ Source[0] || '' }${ Source[1] || '' }`; HTML = HTML.replace(/^<\?.+?\?>/, '').replace(/(]+)?>)/i, `$1` + (!Item.Preprocessed ? `` : '')); - if(sML.UA.LINE || sML.UA.Trident || sML.UA.EdgeHTML) { // Legacy Microsoft Browsers do not accept DataURIs for src of