paginar 0.2.3 → 0.2.4

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/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.3",
7
+ "version": "0.2.4",
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 border-urucum w-full h-10 flex justify-center items-center"
13
+ class="font-light text-base border w-full h-10 flex justify-center items-center"
14
14
  :class="{
15
- 'bg-primary-extralight text-gray-800 border-2 border-primary': mode === 'light'
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 border-urucum w-full h-10 flex justify-center items-center"
22
+ class="font-light text-base border w-full h-10 flex justify-center items-center"
23
23
  :class="{
24
- 'bg-primary-extralight text-gray-800 border-2 border-primary': mode === 'dark'
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,12 @@ 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
9
12
  })
10
13
 
11
14
  const currentPage = computed(() => state.currentPage)
@@ -13,6 +16,18 @@ const totalPages = computed(() => useEstimatePages.totalPages.value)
13
16
 
14
17
  function init(viewport, content) {
15
18
  useEstimatePages.estimate(viewport, content)
19
+
20
+ // check if there is a query string for oring, and
21
+ // if previews chapter was the next one. If so,
22
+ // start from the end, as we are coming backwards
23
+ const urlParams = new URLSearchParams(window.location.search)
24
+ const origin = urlParams.get('origin')
25
+ if (origin && origin === 'next') {
26
+ setTimeout(() => {
27
+ state.currentPage = totalPages.value
28
+ }, 200)
29
+ }
30
+
16
31
  addEventListener('wheel', onWheel)
17
32
 
18
33
  setInterval(() => {
@@ -33,6 +48,17 @@ function next() {
33
48
  if (!useReaderSettings.blocked.value) {
34
49
  if ((state.currentPage + 1) <= totalPages.value) {
35
50
  state.currentPage = state.currentPage + 1
51
+ } else {
52
+ // prevent going too fast to next chapter on
53
+ // stronger scroll
54
+ if (state.nextTry < 4) {
55
+ state.nextTry += 1
56
+ return
57
+ }
58
+ const context = useTextContent.context.value
59
+ if (context.surround?.after) {
60
+ window.location.href = context.surround.after.link + (`?origin=prev`)
61
+ }
36
62
  }
37
63
  }
38
64
  }
@@ -53,6 +79,17 @@ function prev() {
53
79
  if (!useReaderSettings.blocked.value) {
54
80
  if ((state.currentPage - 1) > 0) {
55
81
  state.currentPage = state.currentPage - 1
82
+ } else {
83
+ // prevent going too fast to prev chapter on
84
+ // stronger scroll
85
+ if (state.prevTry < 4) {
86
+ state.prevTry += 1
87
+ return
88
+ }
89
+ const context = useTextContent.context.value
90
+ if (context.surround?.before) {
91
+ window.location.href = context.surround.before.link + (`?origin=next`)
92
+ }
56
93
  }
57
94
  }
58
95
  }
@@ -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' data-ref='${reference.cit}'>${reference.cit}</span>`
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 target = event.target.closest('.reference')?.getAttribute("data-ref")
42
+ const classList = event.target.closest('.reference')?.classList.value.split(' ')
41
43
 
42
- const ref = state.references.find(item => target && item.cit === target)
43
- if (ref) {
44
- state.reference = ref
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));