From 6aa9ef24f08ca3f3eac377be7d5c3e5a5d55c667 Mon Sep 17 00:00:00 2001 From: theditor Date: Fri, 22 Dec 2023 18:56:38 +0530 Subject: [PATCH 01/17] feat: update to vue-virtual-scroller 1.1.2 --- .../assets/src/views/PdfRendererIndex.vue | 13 +++++++------ kolibri/plugins/pdf_viewer/package.json | 2 +- yarn.lock | 16 ++++++++-------- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/kolibri/plugins/pdf_viewer/assets/src/views/PdfRendererIndex.vue b/kolibri/plugins/pdf_viewer/assets/src/views/PdfRendererIndex.vue index 6583a97df5b..39f2bf90678 100644 --- a/kolibri/plugins/pdf_viewer/assets/src/views/PdfRendererIndex.vue +++ b/kolibri/plugins/pdf_viewer/assets/src/views/PdfRendererIndex.vue @@ -84,17 +84,18 @@ :layout8="{ span: showSideBar ? 6 : 8 }" :layout12="{ span: showSideBar ? 9 : 12 }" > - - @@ -123,7 +124,7 @@ import throttle from 'lodash/throttle'; import debounce from 'lodash/debounce'; import logger from 'kolibri.lib.logging'; - import { RecycleList } from 'vue-virtual-scroller'; + import { RecycleScroller } from 'vue-virtual-scroller'; import 'vue-virtual-scroller/dist/vue-virtual-scroller.css'; // polyfill necessary for recycle list import 'intersection-observer'; @@ -146,7 +147,7 @@ components: { SideBar, PdfPage, - RecycleList, + RecycleScroller, CoreFullscreen, }, mixins: [responsiveWindowMixin, commonCoreStrings], diff --git a/kolibri/plugins/pdf_viewer/package.json b/kolibri/plugins/pdf_viewer/package.json index 822ada18cb8..2dcfa45540f 100644 --- a/kolibri/plugins/pdf_viewer/package.json +++ b/kolibri/plugins/pdf_viewer/package.json @@ -6,7 +6,7 @@ "dependencies": { "intersection-observer": "0.12.2", "pdfjs-dist": "^2.16.105", - "vue-virtual-scroller": "0.12.0", + "vue-virtual-scroller": "1.1.2", "web-streams-polyfill": "^3.2.1" } } diff --git a/yarn.lock b/yarn.lock index ffdbe66d37c..581785cde4f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -11598,12 +11598,12 @@ vue-meta@^2.4.0: dependencies: deepmerge "^4.2.2" -vue-observe-visibility@^0.4.1: +vue-observe-visibility@^0.4.4: version "0.4.6" resolved "https://registry.yarnpkg.com/vue-observe-visibility/-/vue-observe-visibility-0.4.6.tgz#878cb8ebcf3078e40807af29774e97105ebd519e" integrity sha512-xo0CEVdkjSjhJoDdLSvoZoQrw/H2BlzB5jrCBKGZNXN2zdZgMuZ9BKrxXDjNP2AxlcCoKc8OahI3F3r3JGLv2Q== -vue-resize@^0.4.4: +vue-resize@^0.4.5: version "0.4.5" resolved "https://registry.yarnpkg.com/vue-resize/-/vue-resize-0.4.5.tgz#4777a23042e3c05620d9cbda01c0b3cc5e32dcea" integrity sha512-bhP7MlgJQ8TIkZJXAfDf78uJO+mEI3CaLABLjv0WNzr4CcGRGPIAItyWYnP6LsPA4Oq0WE+suidNs6dgpO4RHg== @@ -11634,14 +11634,14 @@ vue-template-es2015-compiler@^1.6.0, vue-template-es2015-compiler@^1.9.0: resolved "https://registry.yarnpkg.com/vue-template-es2015-compiler/-/vue-template-es2015-compiler-1.9.1.tgz#1ee3bc9a16ecbf5118be334bb15f9c46f82f5825" integrity sha512-4gDntzrifFnCEvyoO8PqyJDmguXgVPxKiIxrBKjIowvL9l+N66196+72XVYR8BBf1Uv1Fgt3bGevJ+sEmxfZzw== -vue-virtual-scroller@0.12.0: - version "0.12.0" - resolved "https://registry.yarnpkg.com/vue-virtual-scroller/-/vue-virtual-scroller-0.12.0.tgz#42f8fd7b299cd4d4fd1f5e14676792c229b890e2" - integrity sha512-01hKN99psA9Hq6zJajQc8H63sgqjpytHC8IyO+WKm6JzdVi8LeJQQqMrz5iUAFW6ZDGk+hvxaAqqcnJv+X8vYg== +vue-virtual-scroller@1.1.2: + version "1.1.2" + resolved "https://registry.yarnpkg.com/vue-virtual-scroller/-/vue-virtual-scroller-1.1.2.tgz#b8a6362f177abf3f2149ce1eac18013c71fe353b" + integrity sha512-SkUyc7QHCJFB5h1Fya7LxVizlVzOZZuFVipBGHYoTK8dwLs08bIz/tclvRApYhksaJIm/nn51inzO2UjpGJPMQ== dependencies: scrollparent "^2.0.1" - vue-observe-visibility "^0.4.1" - vue-resize "^0.4.4" + vue-observe-visibility "^0.4.4" + vue-resize "^0.4.5" vue2-teleport@^1.0.1: version "1.0.1" From d851068575a20aa29d4d2c34918f45f746931a29 Mon Sep 17 00:00:00 2001 From: theditor Date: Fri, 22 Dec 2023 20:48:42 +0530 Subject: [PATCH 02/17] feat: dynamic scroller --- .../assets/src/views/PdfRendererIndex.vue | 53 +++++++++++-------- 1 file changed, 31 insertions(+), 22 deletions(-) diff --git a/kolibri/plugins/pdf_viewer/assets/src/views/PdfRendererIndex.vue b/kolibri/plugins/pdf_viewer/assets/src/views/PdfRendererIndex.vue index 39f2bf90678..53ecc6d60c0 100644 --- a/kolibri/plugins/pdf_viewer/assets/src/views/PdfRendererIndex.vue +++ b/kolibri/plugins/pdf_viewer/assets/src/views/PdfRendererIndex.vue @@ -84,31 +84,39 @@ :layout8="{ span: showSideBar ? 6 : 8 }" :layout12="{ span: showSideBar ? 9 : 12 }" > - - @@ -124,7 +132,7 @@ import throttle from 'lodash/throttle'; import debounce from 'lodash/debounce'; import logger from 'kolibri.lib.logging'; - import { RecycleScroller } from 'vue-virtual-scroller'; + import { DynamicScroller, DynamicScrollerItem } from 'vue-virtual-scroller'; import 'vue-virtual-scroller/dist/vue-virtual-scroller.css'; // polyfill necessary for recycle list import 'intersection-observer'; @@ -145,11 +153,12 @@ export default { name: 'PdfRendererIndex', components: { - SideBar, - PdfPage, - RecycleScroller, - CoreFullscreen, - }, + SideBar, + PdfPage, + DynamicScroller, + CoreFullscreen, + DynamicScrollerItem +}, mixins: [responsiveWindowMixin, commonCoreStrings], data: () => ({ progress: null, From 36c83eb8518b1a2860d0bd2c0b4d2d9bc2bc4d56 Mon Sep 17 00:00:00 2001 From: theditor Date: Fri, 22 Dec 2023 21:09:05 +0530 Subject: [PATCH 03/17] fix: preloading offset pages --- kolibri/plugins/pdf_viewer/assets/src/views/PdfRendererIndex.vue | 1 + 1 file changed, 1 insertion(+) diff --git a/kolibri/plugins/pdf_viewer/assets/src/views/PdfRendererIndex.vue b/kolibri/plugins/pdf_viewer/assets/src/views/PdfRendererIndex.vue index 53ecc6d60c0..02fdb0977fb 100644 --- a/kolibri/plugins/pdf_viewer/assets/src/views/PdfRendererIndex.vue +++ b/kolibri/plugins/pdf_viewer/assets/src/views/PdfRendererIndex.vue @@ -90,6 +90,7 @@ :items="pdfPages" :minItemSize="itemHeight" :emitUpdate="true" + :buffer="1.5 * itemHeight" class="pdf-container scroller-height" keyField="index" @update="handleUpdate" From 4702ab57ae23cf4e3b5b52bd99c6eadc2109daab Mon Sep 17 00:00:00 2001 From: theditor Date: Fri, 22 Dec 2023 23:25:49 +0530 Subject: [PATCH 04/17] chore: add theditor to authors --- AUTHORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS.md b/AUTHORS.md index b7383333720..fd43e7e59a6 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -99,3 +99,4 @@ If you have contributed to Kolibri, feel free to add your name and Github accoun | Kris Katkus | katkuskris | | Garvit Singhal | GarvitSinghal47 | | Mazen Oweiss | moweiss | +| Nikhil Sharma | ThEditor | \ No newline at end of file From 7d8488ee834bac61f6ecf356731bdf0b7c94f5e2 Mon Sep 17 00:00:00 2001 From: theditor Date: Sat, 23 Dec 2023 14:29:47 +0530 Subject: [PATCH 05/17] revert: preloading offset pages --- kolibri/plugins/pdf_viewer/assets/src/views/PdfRendererIndex.vue | 1 - 1 file changed, 1 deletion(-) diff --git a/kolibri/plugins/pdf_viewer/assets/src/views/PdfRendererIndex.vue b/kolibri/plugins/pdf_viewer/assets/src/views/PdfRendererIndex.vue index 02fdb0977fb..53ecc6d60c0 100644 --- a/kolibri/plugins/pdf_viewer/assets/src/views/PdfRendererIndex.vue +++ b/kolibri/plugins/pdf_viewer/assets/src/views/PdfRendererIndex.vue @@ -90,7 +90,6 @@ :items="pdfPages" :minItemSize="itemHeight" :emitUpdate="true" - :buffer="1.5 * itemHeight" class="pdf-container scroller-height" keyField="index" @update="handleUpdate" From 740426b3c31c65f8c39ae58e2a5a77d08316a3ab Mon Sep 17 00:00:00 2001 From: theditor Date: Sat, 30 Dec 2023 02:00:23 +0530 Subject: [PATCH 06/17] chore: variable mode recyclable scroller --- .../assets/src/views/PdfRendererIndex.vue | 58 +- .../assets/src/views/RecyclableScroller.vue | 839 ++++++++++++++++++ yarn.lock | 6 +- 3 files changed, 869 insertions(+), 34 deletions(-) create mode 100644 kolibri/plugins/pdf_viewer/assets/src/views/RecyclableScroller.vue diff --git a/kolibri/plugins/pdf_viewer/assets/src/views/PdfRendererIndex.vue b/kolibri/plugins/pdf_viewer/assets/src/views/PdfRendererIndex.vue index 53ecc6d60c0..b325d29deeb 100644 --- a/kolibri/plugins/pdf_viewer/assets/src/views/PdfRendererIndex.vue +++ b/kolibri/plugins/pdf_viewer/assets/src/views/PdfRendererIndex.vue @@ -84,39 +84,29 @@ :layout8="{ span: showSideBar ? 6 : 8 }" :layout12="{ span: showSideBar ? 9 : 12 }" > - - + @@ -132,8 +122,6 @@ import throttle from 'lodash/throttle'; import debounce from 'lodash/debounce'; import logger from 'kolibri.lib.logging'; - import { DynamicScroller, DynamicScrollerItem } from 'vue-virtual-scroller'; - import 'vue-virtual-scroller/dist/vue-virtual-scroller.css'; // polyfill necessary for recycle list import 'intersection-observer'; import commonCoreStrings from 'kolibri.coreVue.mixins.commonCoreStrings'; @@ -141,6 +129,7 @@ import CoreFullscreen from 'kolibri.coreVue.components.CoreFullscreen'; import '../utils/domPolyfills'; import { EventBus } from '../utils/event_utils'; + import RecyclableScroller from './RecyclableScroller'; import PdfPage from './PdfPage'; import SideBar from './SideBar'; @@ -155,9 +144,10 @@ components: { SideBar, PdfPage, - DynamicScroller, CoreFullscreen, - DynamicScrollerItem + RecyclableScroller, + // DynamicScroller, + // DynamicScrollerItem }, mixins: [responsiveWindowMixin, commonCoreStrings], data: () => ({ @@ -195,9 +185,9 @@ documentLoading() { return this.progress < 1; }, - itemHeight() { - return this.firstPageHeight * this.scale + MARGIN; - }, + // itemHeight() { + // return this.firstPageHeight * this.scale + MARGIN; + // }, savedLocation() { if (this.extraFields && this.extraFields.contentState) { return this.extraFields.contentState.savedLocation; @@ -299,15 +289,21 @@ }; this.eventBus = new EventBus(); this.prepComponentData = loadingPdf.promise - .then(pdfDocument => { + .then(async pdfDocument => { // Get initial info from the loaded pdf document this.pdfDocument = pdfDocument; this.totalPages = this.pdfDocument.numPages; // init pdfPages array for (let i = 0; i < this.totalPages; i++) { + const pageSize = await this.pdfDocument.getPage(i + 1).then(page => { + return page.getViewport({ scale: 1 }).height; + }); this.pdfPages.push({ page: null, resolved: false, + size: () => { + return pageSize * this.scale + MARGIN; + }, index: i, }); } diff --git a/kolibri/plugins/pdf_viewer/assets/src/views/RecyclableScroller.vue b/kolibri/plugins/pdf_viewer/assets/src/views/RecyclableScroller.vue new file mode 100644 index 00000000000..14503b74474 --- /dev/null +++ b/kolibri/plugins/pdf_viewer/assets/src/views/RecyclableScroller.vue @@ -0,0 +1,839 @@ + + + + + \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index 581785cde4f..854d2b878d8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10042,9 +10042,9 @@ screenfull@^5.2.0: integrity sha512-9BakfsO2aUQN2K9Fdbj87RJIEZ82Q9IGim7FqM5OsebfoFC6ZHXgDq/KvniuLTPdeM8wY2o6Dj3WQ7KeQCj3cA== scrollparent@^2.0.1: - version "2.0.1" - resolved "https://registry.yarnpkg.com/scrollparent/-/scrollparent-2.0.1.tgz#715d5b9cc57760fb22bdccc3befb5bfe06b1a317" - integrity sha1-cV1bnMV3YPsivczDvvtb/gaxoxc= + version "2.1.0" + resolved "https://registry.yarnpkg.com/scrollparent/-/scrollparent-2.1.0.tgz#6cae915c953835886a6ba0d77fdc2bb1ed09076d" + integrity sha512-bnnvJL28/Rtz/kz2+4wpBjHzWoEzXhVg/TE8BeVGJHUqE8THNIRnDxDWMktwM+qahvlRdvlLdsQfYe+cuqfZeA== scss-parser@^1.0.6: version "1.0.6" From 5982d4a8634b6392ad57483a0488066a8ad3176a Mon Sep 17 00:00:00 2001 From: theditor Date: Fri, 5 Jan 2024 11:54:55 +0530 Subject: [PATCH 07/17] fix: linting issues --- AUTHORS.md | 2 +- .../assets/src/views/PdfRendererIndex.vue | 14 +- .../assets/src/views/RecyclableScroller.vue | 850 +++++++++--------- 3 files changed, 449 insertions(+), 417 deletions(-) diff --git a/AUTHORS.md b/AUTHORS.md index fd43e7e59a6..82e5b95ac22 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -99,4 +99,4 @@ If you have contributed to Kolibri, feel free to add your name and Github accoun | Kris Katkus | katkuskris | | Garvit Singhal | GarvitSinghal47 | | Mazen Oweiss | moweiss | -| Nikhil Sharma | ThEditor | \ No newline at end of file +| Nikhil Sharma | ThEditor | diff --git a/kolibri/plugins/pdf_viewer/assets/src/views/PdfRendererIndex.vue b/kolibri/plugins/pdf_viewer/assets/src/views/PdfRendererIndex.vue index b325d29deeb..811ee9e5b0c 100644 --- a/kolibri/plugins/pdf_viewer/assets/src/views/PdfRendererIndex.vue +++ b/kolibri/plugins/pdf_viewer/assets/src/views/PdfRendererIndex.vue @@ -142,13 +142,13 @@ export default { name: 'PdfRendererIndex', components: { - SideBar, - PdfPage, - CoreFullscreen, - RecyclableScroller, - // DynamicScroller, - // DynamicScrollerItem -}, + SideBar, + PdfPage, + CoreFullscreen, + RecyclableScroller, + // DynamicScroller, + // DynamicScrollerItem + }, mixins: [responsiveWindowMixin, commonCoreStrings], data: () => ({ progress: null, diff --git a/kolibri/plugins/pdf_viewer/assets/src/views/RecyclableScroller.vue b/kolibri/plugins/pdf_viewer/assets/src/views/RecyclableScroller.vue index 14503b74474..bcdce2c792c 100644 --- a/kolibri/plugins/pdf_viewer/assets/src/views/RecyclableScroller.vue +++ b/kolibri/plugins/pdf_viewer/assets/src/views/RecyclableScroller.vue @@ -1,4 +1,5 @@ - + + - - \ No newline at end of file + \ No newline at end of file From 12490d24673f703b646291c60a554ba4dc57ad7d Mon Sep 17 00:00:00 2001 From: theditor Date: Fri, 5 Jan 2024 12:20:53 +0530 Subject: [PATCH 08/17] chore: add recyclescroller credits --- .../pdf_viewer/assets/src/views/RecyclableScroller.vue | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/kolibri/plugins/pdf_viewer/assets/src/views/RecyclableScroller.vue b/kolibri/plugins/pdf_viewer/assets/src/views/RecyclableScroller.vue index bcdce2c792c..db517532be2 100644 --- a/kolibri/plugins/pdf_viewer/assets/src/views/RecyclableScroller.vue +++ b/kolibri/plugins/pdf_viewer/assets/src/views/RecyclableScroller.vue @@ -1,3 +1,10 @@ + + +