paginar 0.3.0 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/.editorconfig +13 -13
  2. package/.env +1 -1
  3. package/.vscode/extensions.json +3 -3
  4. package/LICENSE.md +21 -21
  5. package/README.md +244 -244
  6. package/demo/slot/slot-chapter1.html +384 -384
  7. package/demo/slot/slot-chapter2.html +366 -366
  8. package/demo/slot/slot-chapter3.html +265 -265
  9. package/demo/summary/_content/1chapter.html +100 -100
  10. package/demo/summary/_content/2chapter.html +311 -311
  11. package/demo/summary/_content/3chapter.html +211 -211
  12. package/demo/summary/index.html +134 -134
  13. package/dist/index.es.js +849 -840
  14. package/dist/index.es.js.map +1 -1
  15. package/dist/style.css +9 -9
  16. package/index.html +18 -18
  17. package/package.json +1 -1
  18. package/src/App.ce.vue +148 -148
  19. package/src/assets/main.css +392 -392
  20. package/src/components/BookContent.vue +23 -23
  21. package/src/components/FooterSlot.vue +32 -32
  22. package/src/components/FootnotesAside.vue +123 -123
  23. package/src/components/HeaderSlot/HeaderSlot.vue +30 -30
  24. package/src/components/HeaderSlot/OptionsButton/OptionsButton.vue +67 -67
  25. package/src/components/HeaderSlot/OptionsButton/OptionsColor.vue +28 -28
  26. package/src/components/HeaderSlot/OptionsButton/OptionsColumns.vue +51 -51
  27. package/src/components/HeaderSlot/OptionsButton/OptionsDropdown.vue +59 -59
  28. package/src/components/HeaderSlot/OptionsButton/OptionsFontFamily.vue +17 -17
  29. package/src/components/HeaderSlot/OptionsButton/OptionsFontSize.vue +17 -17
  30. package/src/components/HeaderSlot/SummaryButton/SummaryButton.vue +70 -70
  31. package/src/components/HeaderSlot/SummaryButton/SummaryDropdown.vue +6 -6
  32. package/src/components/ReaderWrapper.vue +37 -37
  33. package/src/components/ReferencePopup.vue +36 -36
  34. package/src/components/icons/Close.vue +6 -6
  35. package/src/components/icons/DoubleColumn.vue +15 -15
  36. package/src/components/icons/Expand.vue +7 -7
  37. package/src/components/icons/Eye.vue +9 -9
  38. package/src/components/icons/Footnote.vue +5 -5
  39. package/src/components/icons/Home.vue +6 -6
  40. package/src/components/icons/Moon.vue +5 -5
  41. package/src/components/icons/Notes.vue +5 -5
  42. package/src/components/icons/SingleColumn.vue +3 -3
  43. package/src/components/icons/Summary.vue +10 -10
  44. package/src/components/icons/Sun.vue +5 -5
  45. package/src/components/icons/ThreeDots.vue +8 -8
  46. package/src/composables/useBrowser.js +16 -16
  47. package/src/composables/useFootnotes.js +50 -50
  48. package/src/composables/usePagination.js +125 -125
  49. package/src/composables/useReaderSettings.js +174 -174
  50. package/src/composables/useReferences.js +67 -67
  51. package/src/composables/useStyles.js +60 -60
  52. package/src/composables/useTextContent.js +113 -113
  53. package/src/main.js +19 -19
  54. package/tailwind.config.js +16 -16
  55. package/vite.config.js +36 -36
@@ -1,7 +1,7 @@
1
- <script setup></script>
2
- <template>
3
- <svg fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
4
- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
5
- d="M4 8V4m0 0h4M4 4l5 5m11-1V4m0 0h-4m4 0l-5 5M4 16v4m0 0h4m-4 0l5-5m11 5l-5-5m5 5v-4m0 4h-4"></path>
6
- </svg>
7
- </template>
1
+ <script setup></script>
2
+ <template>
3
+ <svg fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
4
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
5
+ d="M4 8V4m0 0h4M4 4l5 5m11-1V4m0 0h-4m4 0l-5 5M4 16v4m0 0h4m-4 0l5-5m11 5l-5-5m5 5v-4m0 4h-4"></path>
6
+ </svg>
7
+ </template>
@@ -1,9 +1,9 @@
1
- <script setup></script>
2
- <template>
3
- <svg fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
4
- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"></path>
5
- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
6
- d="M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z">
7
- </path>
8
- </svg>
9
- </template>
1
+ <script setup></script>
2
+ <template>
3
+ <svg fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
4
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"></path>
5
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
6
+ d="M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z">
7
+ </path>
8
+ </svg>
9
+ </template>
@@ -1,5 +1,5 @@
1
- <template>
2
- <svg fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
3
- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
4
- </svg>
5
- </template>
1
+ <template>
2
+ <svg fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
3
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
4
+ </svg>
5
+ </template>
@@ -1,6 +1,6 @@
1
- <template>
2
- <svg fill="none" stroke="currentColor" viewBox="0 0 20 22" xmlns="http://www.w3.org/2000/svg">
3
- <path d="M1 8L10 1L19 8V19C19 19.5304 18.7893 20.0391 18.4142 20.4142C18.0391 20.7893 17.5304 21 17 21H3C2.46957 21 1.96086 20.7893 1.58579 20.4142C1.21071 20.0391 1 19.5304 1 19V8Z" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
4
- <path d="M7 21V11H13V21" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
5
- </svg>
6
- </template>
1
+ <template>
2
+ <svg fill="none" stroke="currentColor" viewBox="0 0 20 22" xmlns="http://www.w3.org/2000/svg">
3
+ <path d="M1 8L10 1L19 8V19C19 19.5304 18.7893 20.0391 18.4142 20.4142C18.0391 20.7893 17.5304 21 17 21H3C2.46957 21 1.96086 20.7893 1.58579 20.4142C1.21071 20.0391 1 19.5304 1 19V8Z" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
4
+ <path d="M7 21V11H13V21" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
5
+ </svg>
6
+ </template>
@@ -1,5 +1,5 @@
1
- <template>
2
- <svg fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
3
- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M20.354 15.354A9 9 0 018.646 3.646 9.003 9.003 0 0012 21a9.003 9.003 0 008.354-5.646z"></path>
4
- </svg>
5
- </template>
1
+ <template>
2
+ <svg fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
3
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M20.354 15.354A9 9 0 018.646 3.646 9.003 9.003 0 0012 21a9.003 9.003 0 008.354-5.646z"></path>
4
+ </svg>
5
+ </template>
@@ -1,5 +1,5 @@
1
- <template>
2
- <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
3
- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z" />
4
- </svg>
5
- </template>
1
+ <template>
2
+ <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
3
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z" />
4
+ </svg>
5
+ </template>
@@ -1,3 +1,3 @@
1
- <template>
2
- <svg viewBox="0 0 341.5 441.2" fill="currentColor"><rect data-v-acadaaca="" x="73.2" y="143.7" width="195.2" height="20"></rect><rect data-v-acadaaca="" x="73.2" y="82.7" width="195.2" height="20"></rect><rect data-v-acadaaca="" x="73.2" y="203.7" width="195.2" height="20"></rect><rect data-v-acadaaca="" x="73.2" y="263.7" width="195.2" height="20"></rect><rect data-v-acadaaca="" x="73.2" y="319" width="195.2" height="20"></rect><rect data-v-acadaaca="" x="0" y="-0.6" width="332.3" height="15"></rect><rect data-v-acadaaca="" x="0" y="426.2" width="332.3" height="15"></rect><rect data-v-acadaaca="" x="-209.4" y="216.2" transform="matrix(6.123234e-17 -1 1 6.123234e-17 -216.2339 231.2339)" width="433.7" height="15"></rect><rect data-v-acadaaca="" x="108" y="211.9" transform="matrix(6.123234e-17 -1 1 6.123234e-17 105.4808 544.1859)" width="433.7" height="15"></rect></svg>
3
- </template>
1
+ <template>
2
+ <svg viewBox="0 0 341.5 441.2" fill="currentColor"><rect data-v-acadaaca="" x="73.2" y="143.7" width="195.2" height="20"></rect><rect data-v-acadaaca="" x="73.2" y="82.7" width="195.2" height="20"></rect><rect data-v-acadaaca="" x="73.2" y="203.7" width="195.2" height="20"></rect><rect data-v-acadaaca="" x="73.2" y="263.7" width="195.2" height="20"></rect><rect data-v-acadaaca="" x="73.2" y="319" width="195.2" height="20"></rect><rect data-v-acadaaca="" x="0" y="-0.6" width="332.3" height="15"></rect><rect data-v-acadaaca="" x="0" y="426.2" width="332.3" height="15"></rect><rect data-v-acadaaca="" x="-209.4" y="216.2" transform="matrix(6.123234e-17 -1 1 6.123234e-17 -216.2339 231.2339)" width="433.7" height="15"></rect><rect data-v-acadaaca="" x="108" y="211.9" transform="matrix(6.123234e-17 -1 1 6.123234e-17 105.4808 544.1859)" width="433.7" height="15"></rect></svg>
3
+ </template>
@@ -1,10 +1,10 @@
1
- <template>
2
- <svg width="24" height="19" viewBox="0 0 24 19" fill="none" stroke="currentColor" xmlns="http://www.w3.org/2000/svg">
3
- <line x1="5" y1="1.08447" x2="1" y2="1.08447" stroke-width="2" stroke-linecap="round"/>
4
- <line x1="23" y1="1.04248" x2="11" y2="1.04248" stroke-width="2" stroke-linecap="round"/>
5
- <line x1="23" y1="9.08447" x2="14" y2="9.08447" stroke-width="2" stroke-linecap="round"/>
6
- <line x1="8" y1="9.14905" x2="4" y2="9.14905" stroke-width="2" stroke-linecap="round"/>
7
- <line x1="23" y1="17.149" x2="10.9993" y2="17.149" stroke-width="2" stroke-linecap="round"/>
8
- <line x1="5" y1="17.2429" x2="1" y2="17.2429" stroke-width="2" stroke-linecap="round"/>
9
- </svg>
10
- </template>
1
+ <template>
2
+ <svg width="24" height="19" viewBox="0 0 24 19" fill="none" stroke="currentColor" xmlns="http://www.w3.org/2000/svg">
3
+ <line x1="5" y1="1.08447" x2="1" y2="1.08447" stroke-width="2" stroke-linecap="round"/>
4
+ <line x1="23" y1="1.04248" x2="11" y2="1.04248" stroke-width="2" stroke-linecap="round"/>
5
+ <line x1="23" y1="9.08447" x2="14" y2="9.08447" stroke-width="2" stroke-linecap="round"/>
6
+ <line x1="8" y1="9.14905" x2="4" y2="9.14905" stroke-width="2" stroke-linecap="round"/>
7
+ <line x1="23" y1="17.149" x2="10.9993" y2="17.149" stroke-width="2" stroke-linecap="round"/>
8
+ <line x1="5" y1="17.2429" x2="1" y2="17.2429" stroke-width="2" stroke-linecap="round"/>
9
+ </svg>
10
+ </template>
@@ -1,5 +1,5 @@
1
- <template>
2
- <svg fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
3
- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 3v1m0 16v1m9-9h-1M4 12H3m15.364 6.364l-.707-.707M6.343 6.343l-.707-.707m12.728 0l-.707.707M6.343 17.657l-.707.707M16 12a4 4 0 11-8 0 4 4 0 018 0z"></path>
4
- </svg>
5
- </template>
1
+ <template>
2
+ <svg fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
3
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 3v1m0 16v1m9-9h-1M4 12H3m15.364 6.364l-.707-.707M6.343 6.343l-.707-.707m12.728 0l-.707.707M6.343 17.657l-.707.707M16 12a4 4 0 11-8 0 4 4 0 018 0z"></path>
4
+ </svg>
5
+ </template>
@@ -1,8 +1,8 @@
1
- <script setup></script>
2
- <template>
3
- <svg fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
4
- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
5
- d="M5 12h.01M12 12h.01M19 12h.01M6 12a1 1 0 11-2 0 1 1 0 012 0zm7 0a1 1 0 11-2 0 1 1 0 012 0zm7 0a1 1 0 11-2 0 1 1 0 012 0z">
6
- </path>
7
- </svg>
8
- </template>
1
+ <script setup></script>
2
+ <template>
3
+ <svg fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
4
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
5
+ d="M5 12h.01M12 12h.01M19 12h.01M6 12a1 1 0 11-2 0 1 1 0 012 0zm7 0a1 1 0 11-2 0 1 1 0 012 0zm7 0a1 1 0 11-2 0 1 1 0 012 0z">
6
+ </path>
7
+ </svg>
8
+ </template>
@@ -1,16 +1,16 @@
1
- const isSafari = [
2
- 'iPad Simulator',
3
- 'iPhone Simulator',
4
- 'iPod Simulator',
5
- 'iPad',
6
- 'iPhone',
7
- 'iPod'
8
- ].includes(navigator.platform)
9
- || (navigator.userAgent.includes("Mac") && "ontouchend" in document)
10
-
11
- const isApple = /(Mac|iPhone|iPod|iPad)/i.test(navigator.platform);
12
-
13
- export default {
14
- isSafari,
15
- isApple
16
- }
1
+ const isSafari = [
2
+ 'iPad Simulator',
3
+ 'iPhone Simulator',
4
+ 'iPod Simulator',
5
+ 'iPad',
6
+ 'iPhone',
7
+ 'iPod'
8
+ ].includes(navigator.platform)
9
+ || (navigator.userAgent.includes("Mac") && "ontouchend" in document)
10
+
11
+ const isApple = /(Mac|iPhone|iPod|iPad)/i.test(navigator.platform);
12
+
13
+ export default {
14
+ isSafari,
15
+ isApple
16
+ }
@@ -1,50 +1,50 @@
1
- import { computed, reactive } from 'vue'
2
-
3
- const state = reactive({
4
- footnotes: [],
5
- showFootnotes: false,
6
- footnote: null
7
- })
8
-
9
- const footnotes = computed(() => state.footnotes)
10
- function setFootnotes(footnotes) {
11
- state.footnotes = footnotes
12
- }
13
-
14
- const showFootnotes = computed(() => state.showFootnotes)
15
- function setShowFootnotes(value) {
16
- state.showFootnotes = value
17
- }
18
-
19
- const footnote = computed(() => state.footnote)
20
- function setHighlightedFootnote(footnote) {
21
- state.footnote = footnote
22
- }
23
-
24
- function applyFootnote(event) {
25
- const classList = event.target.closest('.footnote')?.classList.value.split(' ')
26
-
27
- if (classList.length === 0)
28
- return
29
-
30
- const footnoteTarget = classList.find(
31
- item => item.includes('footnote') && item !== 'footnote'
32
- )
33
-
34
- if (footnoteTarget) {
35
- const ref = state.footnotes.find(item => item.id === footnoteTarget)
36
- if (ref) {
37
- state.footnote = ref
38
- }
39
- }
40
- }
41
-
42
- export default {
43
- footnotes,
44
- footnote,
45
- setFootnotes,
46
- applyFootnote,
47
- setHighlightedFootnote,
48
- setShowFootnotes,
49
- showFootnotes
50
- }
1
+ import { computed, reactive } from 'vue'
2
+
3
+ const state = reactive({
4
+ footnotes: [],
5
+ showFootnotes: false,
6
+ footnote: null
7
+ })
8
+
9
+ const footnotes = computed(() => state.footnotes)
10
+ function setFootnotes(footnotes) {
11
+ state.footnotes = footnotes
12
+ }
13
+
14
+ const showFootnotes = computed(() => state.showFootnotes)
15
+ function setShowFootnotes(value) {
16
+ state.showFootnotes = value
17
+ }
18
+
19
+ const footnote = computed(() => state.footnote)
20
+ function setHighlightedFootnote(footnote) {
21
+ state.footnote = footnote
22
+ }
23
+
24
+ function applyFootnote(event) {
25
+ const classList = event.target.closest('.footnote')?.classList.value.split(' ')
26
+
27
+ if (classList.length === 0)
28
+ return
29
+
30
+ const footnoteTarget = classList.find(
31
+ item => item.includes('footnote') && item !== 'footnote'
32
+ )
33
+
34
+ if (footnoteTarget) {
35
+ const ref = state.footnotes.find(item => item.id === footnoteTarget)
36
+ if (ref) {
37
+ state.footnote = ref
38
+ }
39
+ }
40
+ }
41
+
42
+ export default {
43
+ footnotes,
44
+ footnote,
45
+ setFootnotes,
46
+ applyFootnote,
47
+ setHighlightedFootnote,
48
+ setShowFootnotes,
49
+ showFootnotes
50
+ }
@@ -1,125 +1,125 @@
1
- import { reactive, computed, watch } from 'vue'
2
- import { onKeyStroke } from '@vueuse/core'
3
-
4
- import useReaderSettings from './useReaderSettings'
5
- import useEstimatePages from './useEstimatePages'
6
- import useTextContent from './useTextContent'
7
- import useBrowser from './useBrowser'
8
-
9
- const state = reactive({
10
- currentPage: 1,
11
- nextTry: 0,
12
- prevTry: 0,
13
- willRedirect: false
14
- })
15
-
16
- const currentPage = computed(() => state.currentPage)
17
- const totalPages = computed(() => useEstimatePages.totalPages.value)
18
-
19
- function init(viewport, content) {
20
- useEstimatePages.estimate(viewport, content)
21
-
22
- // check if there is a query string for oring, and
23
- // if previews chapter was the next one. If so,
24
- // start from the end, as we are coming backwards
25
- const urlParams = new URLSearchParams(window.location.search)
26
- const origin = urlParams.get('origin')
27
- if (origin && origin === 'next') {
28
- setTimeout(() => {
29
- state.currentPage = totalPages.value
30
- }, 200)
31
- }
32
-
33
- if (!useBrowser.isApple && !useBrowser.isSafari) {
34
- addEventListener('wheel', onWheel)
35
- }
36
-
37
- setInterval(() => {
38
- useEstimatePages.estimate(viewport, content)
39
- }, 5000)
40
- }
41
-
42
- // when resizing the viewport, totalPages change
43
- // this watch is to currentPage inside totalPages range
44
- watch(totalPages, () => {
45
- if (totalPages.value < currentPage.value) {
46
- set(totalPages.value)
47
- }
48
- })
49
-
50
- // navigate by increase/decrease value
51
- function next(usingScroll = false) {
52
- if (!useReaderSettings.blocked.value) {
53
- if ((state.currentPage + 1) <= totalPages.value) {
54
- state.currentPage = state.currentPage + 1
55
- } else {
56
- // prevent going too fast to next chapter on
57
- // stronger scroll
58
- if (usingScroll && state.nextTry < 4) {
59
- state.nextTry += 1
60
- return
61
- }
62
-
63
- if (state.willRedirect === false) {
64
- const context = useTextContent.context.value
65
- if (context.surround?.after) {
66
- window.location.href = context.surround.after.link + (`?origin=prev`)
67
- state.willRedirect = true
68
- }
69
- }
70
- }
71
- }
72
- }
73
- onKeyStroke('ArrowRight', (e) => {
74
- e.preventDefault()
75
- next()
76
- })
77
-
78
- function onWheel(event) {
79
- if (event.wheelDelta < 0) {
80
- next(true)
81
- } else {
82
- prev(true)
83
- }
84
- };
85
-
86
- function prev(usingScroll = false) {
87
- if (!useReaderSettings.blocked.value) {
88
- if ((state.currentPage - 1) > 0) {
89
- state.currentPage = state.currentPage - 1
90
- } else {
91
- // prevent going too fast to prev chapter on
92
- // stronger scroll
93
- if (usingScroll && state.prevTry < 4) {
94
- state.prevTry += 1
95
- return
96
- }
97
-
98
- if (state.willRedirect === false) {
99
- const context = useTextContent.context.value
100
- if (context.surround?.before) {
101
- window.location.href = context.surround.before.link + (`?origin=next`)
102
- }
103
- state.willRedirect = true
104
- }
105
- }
106
- }
107
- }
108
- onKeyStroke('ArrowLeft', (e) => {
109
- e.preventDefault()
110
- prev()
111
- })
112
-
113
- // navigate to specific page
114
- function set(val) {
115
- state.currentPage = val
116
- }
117
-
118
- export default {
119
- currentPage,
120
- totalPages,
121
- next,
122
- prev,
123
- init,
124
- set
125
- }
1
+ import { reactive, computed, watch } from 'vue'
2
+ import { onKeyStroke } from '@vueuse/core'
3
+
4
+ import useReaderSettings from './useReaderSettings'
5
+ import useEstimatePages from './useEstimatePages'
6
+ import useTextContent from './useTextContent'
7
+ import useBrowser from './useBrowser'
8
+
9
+ const state = reactive({
10
+ currentPage: 1,
11
+ nextTry: 0,
12
+ prevTry: 0,
13
+ willRedirect: false
14
+ })
15
+
16
+ const currentPage = computed(() => state.currentPage)
17
+ const totalPages = computed(() => useEstimatePages.totalPages.value)
18
+
19
+ function init(viewport, content) {
20
+ useEstimatePages.estimate(viewport, content)
21
+
22
+ // check if there is a query string for oring, and
23
+ // if previews chapter was the next one. If so,
24
+ // start from the end, as we are coming backwards
25
+ const urlParams = new URLSearchParams(window.location.search)
26
+ const origin = urlParams.get('origin')
27
+ if (origin && origin === 'next') {
28
+ setTimeout(() => {
29
+ state.currentPage = totalPages.value
30
+ }, 200)
31
+ }
32
+
33
+ if (!useBrowser.isApple && !useBrowser.isSafari) {
34
+ addEventListener('wheel', onWheel)
35
+ }
36
+
37
+ setInterval(() => {
38
+ useEstimatePages.estimate(viewport, content)
39
+ }, 5000)
40
+ }
41
+
42
+ // when resizing the viewport, totalPages change
43
+ // this watch is to currentPage inside totalPages range
44
+ watch(totalPages, () => {
45
+ if (totalPages.value < currentPage.value) {
46
+ set(totalPages.value)
47
+ }
48
+ })
49
+
50
+ // navigate by increase/decrease value
51
+ function next(usingScroll = false) {
52
+ if (!useReaderSettings.blocked.value) {
53
+ if ((state.currentPage + 1) <= totalPages.value) {
54
+ state.currentPage = state.currentPage + 1
55
+ } else {
56
+ // prevent going too fast to next chapter on
57
+ // stronger scroll
58
+ if (usingScroll && state.nextTry < 4) {
59
+ state.nextTry += 1
60
+ return
61
+ }
62
+
63
+ if (state.willRedirect === false) {
64
+ const context = useTextContent.context.value
65
+ if (context.surround?.after) {
66
+ window.location.href = context.surround.after.link + (`?origin=prev`)
67
+ state.willRedirect = true
68
+ }
69
+ }
70
+ }
71
+ }
72
+ }
73
+ onKeyStroke('ArrowRight', (e) => {
74
+ e.preventDefault()
75
+ next()
76
+ })
77
+
78
+ function onWheel(event) {
79
+ if (event.wheelDelta < 0) {
80
+ next(true)
81
+ } else {
82
+ prev(true)
83
+ }
84
+ };
85
+
86
+ function prev(usingScroll = false) {
87
+ if (!useReaderSettings.blocked.value) {
88
+ if ((state.currentPage - 1) > 0) {
89
+ state.currentPage = state.currentPage - 1
90
+ } else {
91
+ // prevent going too fast to prev chapter on
92
+ // stronger scroll
93
+ if (usingScroll && state.prevTry < 4) {
94
+ state.prevTry += 1
95
+ return
96
+ }
97
+
98
+ if (state.willRedirect === false) {
99
+ const context = useTextContent.context.value
100
+ if (context.surround?.before) {
101
+ window.location.href = context.surround.before.link + (`?origin=next`)
102
+ }
103
+ state.willRedirect = true
104
+ }
105
+ }
106
+ }
107
+ }
108
+ onKeyStroke('ArrowLeft', (e) => {
109
+ e.preventDefault()
110
+ prev()
111
+ })
112
+
113
+ // navigate to specific page
114
+ function set(val) {
115
+ state.currentPage = val
116
+ }
117
+
118
+ export default {
119
+ currentPage,
120
+ totalPages,
121
+ next,
122
+ prev,
123
+ init,
124
+ set
125
+ }