paginar 0.2.3 → 0.2.5
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.
- package/demo/slot/slot-chapter1.html +1 -1
- package/dist/index.es.js +93 -16
- package/dist/index.es.js.map +1 -1
- package/dist/style.css +0 -5
- package/package.json +1 -1
- package/src/components/HeaderSlot/OptionsButton/OptionsColor.vue +4 -4
- package/src/composables/useEstimatePages.js +3 -0
- package/src/composables/usePagination.js +51 -5
- package/src/composables/useReferences.js +17 -5
- package/src/composables/useTextContent.js +18 -1
- package/src/tailwind.css +0 -5
package/dist/style.css
CHANGED
|
@@ -950,11 +950,6 @@ video {
|
|
|
950
950
|
color: rgb(55 65 81 / var(--tw-text-opacity));
|
|
951
951
|
}
|
|
952
952
|
|
|
953
|
-
.text-gray-800 {
|
|
954
|
-
--tw-text-opacity: 1;
|
|
955
|
-
color: rgb(31 41 55 / var(--tw-text-opacity));
|
|
956
|
-
}
|
|
957
|
-
|
|
958
953
|
.text-black {
|
|
959
954
|
--tw-text-opacity: 1;
|
|
960
955
|
color: rgb(0 0 0 / var(--tw-text-opacity));
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"description": "A flipping page web component for reading long texts on the brower",
|
|
5
5
|
"main": "dist/index.es.js",
|
|
6
6
|
"module": "dist/index.es.js",
|
|
7
|
-
"version": "0.2.
|
|
7
|
+
"version": "0.2.5",
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
10
10
|
"url": "git+https://github.com/educkf/paginar.git"
|
|
@@ -10,18 +10,18 @@ const { mode, setMode } = useReaderSettings
|
|
|
10
10
|
<template>
|
|
11
11
|
<button @click.prevent="setMode('light')"
|
|
12
12
|
title="Leitura diurna"
|
|
13
|
-
class="font-light text-base border
|
|
13
|
+
class="font-light text-base border w-full h-10 flex justify-center items-center"
|
|
14
14
|
:class="{
|
|
15
|
-
'bg-primary-extralight text-
|
|
15
|
+
'bg-primary-extralight text-primary border-2 border-primary': mode === 'light'
|
|
16
16
|
}">
|
|
17
17
|
<IconSun class="w-5 h-5" />
|
|
18
18
|
</button>
|
|
19
19
|
|
|
20
20
|
<button @click.prevent="setMode('dark')"
|
|
21
21
|
title="Leitura noturna"
|
|
22
|
-
class="font-light text-base border
|
|
22
|
+
class="font-light text-base border w-full h-10 flex justify-center items-center"
|
|
23
23
|
:class="{
|
|
24
|
-
'bg-primary-extralight text-
|
|
24
|
+
'bg-primary-extralight text-primary border-2 border-primary': mode === 'dark'
|
|
25
25
|
}">
|
|
26
26
|
<IconMoon class="w-5 h-5" />
|
|
27
27
|
</button>
|
|
@@ -11,12 +11,15 @@ function estimate(viewport, content) {
|
|
|
11
11
|
|
|
12
12
|
if (contentWidth > viewportWidth) {
|
|
13
13
|
state.totalPages = Math.ceil(contentWidth / viewportWidth)
|
|
14
|
+
return Math.ceil(contentWidth / viewportWidth)
|
|
14
15
|
|
|
15
16
|
} else {
|
|
16
17
|
state.totalPages = 1
|
|
18
|
+
return 1
|
|
17
19
|
}
|
|
18
20
|
} else {
|
|
19
21
|
state.totalPages = 1
|
|
22
|
+
return 1
|
|
20
23
|
}
|
|
21
24
|
}
|
|
22
25
|
|
|
@@ -3,9 +3,13 @@ import { onKeyStroke } from '@vueuse/core'
|
|
|
3
3
|
|
|
4
4
|
import useReaderSettings from './useReaderSettings'
|
|
5
5
|
import useEstimatePages from './useEstimatePages'
|
|
6
|
+
import useTextContent from './useTextContent'
|
|
6
7
|
|
|
7
8
|
const state = reactive({
|
|
8
|
-
currentPage: 1
|
|
9
|
+
currentPage: 1,
|
|
10
|
+
nextTry: 0,
|
|
11
|
+
prevTry: 0,
|
|
12
|
+
willRedirect: false
|
|
9
13
|
})
|
|
10
14
|
|
|
11
15
|
const currentPage = computed(() => state.currentPage)
|
|
@@ -13,6 +17,18 @@ const totalPages = computed(() => useEstimatePages.totalPages.value)
|
|
|
13
17
|
|
|
14
18
|
function init(viewport, content) {
|
|
15
19
|
useEstimatePages.estimate(viewport, content)
|
|
20
|
+
|
|
21
|
+
// check if there is a query string for oring, and
|
|
22
|
+
// if previews chapter was the next one. If so,
|
|
23
|
+
// start from the end, as we are coming backwards
|
|
24
|
+
const urlParams = new URLSearchParams(window.location.search)
|
|
25
|
+
const origin = urlParams.get('origin')
|
|
26
|
+
if (origin && origin === 'next') {
|
|
27
|
+
setTimeout(() => {
|
|
28
|
+
state.currentPage = totalPages.value
|
|
29
|
+
}, 200)
|
|
30
|
+
}
|
|
31
|
+
|
|
16
32
|
addEventListener('wheel', onWheel)
|
|
17
33
|
|
|
18
34
|
setInterval(() => {
|
|
@@ -29,10 +45,25 @@ watch(totalPages, () => {
|
|
|
29
45
|
})
|
|
30
46
|
|
|
31
47
|
// navigate by increase/decrease value
|
|
32
|
-
function next() {
|
|
48
|
+
function next(usingScroll = false) {
|
|
33
49
|
if (!useReaderSettings.blocked.value) {
|
|
34
50
|
if ((state.currentPage + 1) <= totalPages.value) {
|
|
35
51
|
state.currentPage = state.currentPage + 1
|
|
52
|
+
} else {
|
|
53
|
+
// prevent going too fast to next chapter on
|
|
54
|
+
// stronger scroll
|
|
55
|
+
if (usingScroll && state.nextTry < 4) {
|
|
56
|
+
state.nextTry += 1
|
|
57
|
+
return
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (state.willRedirect === false) {
|
|
61
|
+
const context = useTextContent.context.value
|
|
62
|
+
if (context.surround?.after) {
|
|
63
|
+
window.location.href = context.surround.after.link + (`?origin=prev`)
|
|
64
|
+
state.willRedirect = true
|
|
65
|
+
}
|
|
66
|
+
}
|
|
36
67
|
}
|
|
37
68
|
}
|
|
38
69
|
}
|
|
@@ -43,16 +74,31 @@ onKeyStroke('ArrowRight', (e) => {
|
|
|
43
74
|
|
|
44
75
|
function onWheel(event) {
|
|
45
76
|
if (event.wheelDelta < 0) {
|
|
46
|
-
next()
|
|
77
|
+
next(true)
|
|
47
78
|
} else {
|
|
48
|
-
prev()
|
|
79
|
+
prev(true)
|
|
49
80
|
}
|
|
50
81
|
};
|
|
51
82
|
|
|
52
|
-
function prev() {
|
|
83
|
+
function prev(usingScroll = false) {
|
|
53
84
|
if (!useReaderSettings.blocked.value) {
|
|
54
85
|
if ((state.currentPage - 1) > 0) {
|
|
55
86
|
state.currentPage = state.currentPage - 1
|
|
87
|
+
} else {
|
|
88
|
+
// prevent going too fast to prev chapter on
|
|
89
|
+
// stronger scroll
|
|
90
|
+
if (usingScroll && state.prevTry < 4) {
|
|
91
|
+
state.prevTry += 1
|
|
92
|
+
return
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (state.willRedirect === false) {
|
|
96
|
+
const context = useTextContent.context.value
|
|
97
|
+
if (context.surround?.before) {
|
|
98
|
+
window.location.href = context.surround.before.link + (`?origin=next`)
|
|
99
|
+
}
|
|
100
|
+
state.willRedirect = true
|
|
101
|
+
}
|
|
56
102
|
}
|
|
57
103
|
}
|
|
58
104
|
}
|
|
@@ -28,7 +28,9 @@ function applyReferences(contentRaw) {
|
|
|
28
28
|
const regex = new RegExp(reference.cit, 'g');
|
|
29
29
|
const newContent = content.replace(
|
|
30
30
|
regex,
|
|
31
|
-
`<span class='reference
|
|
31
|
+
`<span class='reference reference-${reference.cit.replaceAll(' ', '')}'>
|
|
32
|
+
${reference.cit}
|
|
33
|
+
</span>`
|
|
32
34
|
)
|
|
33
35
|
return newContent
|
|
34
36
|
}
|
|
@@ -37,12 +39,22 @@ function applyReferences(contentRaw) {
|
|
|
37
39
|
}
|
|
38
40
|
|
|
39
41
|
function applyReference(event) {
|
|
40
|
-
const
|
|
42
|
+
const classList = event.target.closest('.reference')?.classList.value.split(' ')
|
|
41
43
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
44
|
+
if (classList.length === 0)
|
|
45
|
+
return
|
|
46
|
+
|
|
47
|
+
const target = classList.find(item => item.startsWith('reference-'))
|
|
48
|
+
|
|
49
|
+
if (target) {
|
|
50
|
+
const ref = state.references.find(
|
|
51
|
+
item => target && item.cit.replaceAll(' ', '') === target.replace('reference-', '')
|
|
52
|
+
)
|
|
53
|
+
if (ref) {
|
|
54
|
+
state.reference = ref
|
|
55
|
+
}
|
|
45
56
|
}
|
|
57
|
+
|
|
46
58
|
}
|
|
47
59
|
|
|
48
60
|
export default {
|
|
@@ -11,6 +11,22 @@ const state = reactive({
|
|
|
11
11
|
|
|
12
12
|
const content = computed(() => state.content)
|
|
13
13
|
const summary = computed(() => state.summary)
|
|
14
|
+
const context = computed(() => {
|
|
15
|
+
const current = state.summary.findIndex(
|
|
16
|
+
chapter => window.location.href.includes(chapter.link)
|
|
17
|
+
)
|
|
18
|
+
return {
|
|
19
|
+
chapter: state.summary[current],
|
|
20
|
+
surround: {
|
|
21
|
+
before: current - 1 >= 0
|
|
22
|
+
? state.summary[current - 1]
|
|
23
|
+
: null,
|
|
24
|
+
after: current + 1 <= state.summary.length
|
|
25
|
+
? state.summary[current + 1]
|
|
26
|
+
: null,
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
})
|
|
14
30
|
|
|
15
31
|
async function initContent(contentString, contentWrapper) {
|
|
16
32
|
const { setReferences, applyReferences } = useReferences
|
|
@@ -92,5 +108,6 @@ export default {
|
|
|
92
108
|
initContent,
|
|
93
109
|
getContent,
|
|
94
110
|
applyContent,
|
|
95
|
-
listenToClicks
|
|
111
|
+
listenToClicks,
|
|
112
|
+
context
|
|
96
113
|
}
|
package/src/tailwind.css
CHANGED
|
@@ -933,11 +933,6 @@ video {
|
|
|
933
933
|
color: rgb(55 65 81 / var(--tw-text-opacity));
|
|
934
934
|
}
|
|
935
935
|
|
|
936
|
-
.text-gray-800 {
|
|
937
|
-
--tw-text-opacity: 1;
|
|
938
|
-
color: rgb(31 41 55 / var(--tw-text-opacity));
|
|
939
|
-
}
|
|
940
|
-
|
|
941
936
|
.text-black {
|
|
942
937
|
--tw-text-opacity: 1;
|
|
943
938
|
color: rgb(0 0 0 / var(--tw-text-opacity));
|