data-bionic-reading 1.0.3 → 1.0.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/README.md CHANGED
@@ -3,6 +3,8 @@
3
3
  Helps developers add support for [bionic reading](https://bionic-reading.com) to
4
4
  their content 📚
5
5
 
6
+ ![](https://github.com/markmead/js-bionic-reading/assets/50486078/ca1eddbd-759f-498e-b368-d5a8a580faad)
7
+
6
8
  ## Install
7
9
 
8
10
  ### With a CDN
@@ -52,8 +54,6 @@ document.addEventListener('DOMContentLoaded', bionicReading())
52
54
  </article>
53
55
  ```
54
56
 
55
- And that's it.
56
-
57
57
  ## Stats
58
58
 
59
59
  ![](https://img.shields.io/bundlephobia/min/data-bionic-reading)
@@ -1 +1 @@
1
- function l(){let r=document.querySelector("[data-bionic-reading]");if(!r)return;[...r.querySelectorAll("h1, h2, h3, h4, h5, p, a, li, blockquote")].forEach(e=>{e.style.fontWeight=400;let i=e.innerText.split(" ").map(t=>{let n=t.length;if(n===1)return`<strong>${t}</strong>`;let a=Math.ceil(n/2);return t.split("").map((o,c)=>c<a?`<strong>${o}</strong>`:o).join("")});e.innerHTML=i.join(" ")})}var f=l;export{f as default};
1
+ function l(){let r=[...document.querySelectorAll("[data-bionic-reading]")];r.length&&r.forEach(i=>{[...i.querySelectorAll("h1, h2, h3, h4, h5, p, a, li, blockquote")].forEach(e=>{e.style.fontWeight=400;let a=e.innerText.split(" ").map(t=>{let n=t.length;if(n===1)return`<strong>${t}</strong>`;let c=Math.ceil(n/2);return t.split("").map((o,s)=>s<c?`<strong>${o}</strong>`:o).join("")});e.innerHTML=a.join(" ")})})}var A=l;export{A as default};
@@ -1 +1 @@
1
- (()=>{function i(){let r=document.querySelector("[data-bionic-reading]");if(!r)return;[...r.querySelectorAll("h1, h2, h3, h4, h5, p, a, li, blockquote")].forEach(e=>{e.style.fontWeight=400;let l=e.innerText.split(" ").map(t=>{let n=t.length;if(n===1)return`<strong>${t}</strong>`;let a=Math.ceil(n/2);return t.split("").map((o,c)=>c<a?`<strong>${o}</strong>`:o).join("")});e.innerHTML=l.join(" ")})}document.addEventListener("DOMContentLoaded",i());})();
1
+ (()=>{function i(){let r=[...document.querySelectorAll("[data-bionic-reading]")];r.length&&r.forEach(l=>{[...l.querySelectorAll("h1, h2, h3, h4, h5, p, a, li, blockquote")].forEach(e=>{e.style.fontWeight=400;let a=e.innerText.split(" ").map(t=>{let n=t.length;if(n===1)return`<strong>${t}</strong>`;let c=Math.ceil(n/2);return t.split("").map((o,s)=>s<c?`<strong>${o}</strong>`:o).join("")});e.innerHTML=a.join(" ")})})}document.addEventListener("DOMContentLoaded",i());})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "data-bionic-reading",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "Helps developers add support for bionic reading to their content 📚",
5
5
  "keywords": [
6
6
  "Bionic Reading"
@@ -11,6 +11,6 @@
11
11
  "build": "node scripts/build.js"
12
12
  },
13
13
  "devDependencies": {
14
- "esbuild": "^0.16.2"
14
+ "esbuild": "^0.18.17"
15
15
  }
16
16
  }
package/src/index.js CHANGED
@@ -1,41 +1,43 @@
1
1
  export default function () {
2
- const articleElement = document.querySelector('[data-bionic-reading]')
2
+ const bionicTargets = [...document.querySelectorAll('[data-bionic-reading]')]
3
3
 
4
- if (!articleElement) {
4
+ if (!bionicTargets.length) {
5
5
  return
6
6
  }
7
7
 
8
- const articleElements = [
9
- ...articleElement.querySelectorAll(
10
- 'h1, h2, h3, h4, h5, p, a, li, blockquote'
11
- ),
12
- ]
8
+ bionicTargets.forEach((bionicTarget) => {
9
+ const articleElements = [
10
+ ...bionicTarget.querySelectorAll(
11
+ 'h1, h2, h3, h4, h5, p, a, li, blockquote'
12
+ ),
13
+ ]
13
14
 
14
- articleElements.forEach((contentElement) => {
15
- contentElement.style.fontWeight = 400
15
+ articleElements.forEach((contentElement) => {
16
+ contentElement.style.fontWeight = 400
16
17
 
17
- const elementText = contentElement.innerText
18
- const elementTextArray = elementText.split(' ')
18
+ const elementText = contentElement.innerText
19
+ const elementTextArray = elementText.split(' ')
19
20
 
20
- const elementTextArrayWithBold = elementTextArray.map((textWord) => {
21
- const wordLength = textWord.length
21
+ const elementTextArrayWithBold = elementTextArray.map((textWord) => {
22
+ const wordLength = textWord.length
22
23
 
23
- if (wordLength === 1) {
24
- return `<strong>${textWord}</strong>`
25
- }
24
+ if (wordLength === 1) {
25
+ return `<strong>${textWord}</strong>`
26
+ }
26
27
 
27
- const wordLengthHalf = Math.ceil(wordLength / 2)
28
+ const wordLengthHalf = Math.ceil(wordLength / 2)
28
29
 
29
- const wordArray = textWord.split('')
30
- const wordArrayWithBold = wordArray.map((wordLetter, letterIndex) => {
31
- return letterIndex < wordLengthHalf
32
- ? `<strong>${wordLetter}</strong>`
33
- : wordLetter
30
+ const wordArray = textWord.split('')
31
+ const wordArrayWithBold = wordArray.map((wordLetter, letterIndex) => {
32
+ return letterIndex < wordLengthHalf
33
+ ? `<strong>${wordLetter}</strong>`
34
+ : wordLetter
35
+ })
36
+
37
+ return wordArrayWithBold.join('')
34
38
  })
35
39
 
36
- return wordArrayWithBold.join('')
40
+ contentElement.innerHTML = elementTextArrayWithBold.join(' ')
37
41
  })
38
-
39
- contentElement.innerHTML = elementTextArrayWithBold.join(' ')
40
42
  })
41
43
  }