Diff
diff --git a/docs/plugins/sidebyside.js b/docs/plugins/sidebyside.js
index 2d45b9c..33caa8b 100644
--- a/docs/plugins/sidebyside.js
+++ b/docs/plugins/sidebyside.js
@@ -2,23 +2,65 @@
- let body = document.querySelector("body");
- let sideCont = document.createElement("div");
- sideCont.id = "sidebyside";
- let pre = document.querySelectorAll("pre");
- let main = document.querySelector("main");
-
- style(main, {
- width: "50%",
- overflowY: "auto",
- height: "calc(100vh - 156px)",
- margin: "0",
- paddingBottom: "100px",
- });
-
- style(body, { overflowY: "hidden" });
-
- style(sideCont, {
- width: "50%",
- position: "fixed",
- right: "0",
- top: "0",
- height: "100vh",
- overflowY: "auto",
+ let body = document.querySelector("body");
+ let sideCont = document.createElement("div");
+ let pre = document.querySelectorAll("pre");
+ let main = document.querySelector("main");
+
+ style(main, {
+ width: "50%",
+ overflowY: "auto",
+ height: "calc(100vh - 156px)",
+ margin: "0",
+ paddingBottom: "100px",
+ });
+
+ style(body, { overflowY: "hidden" });
+
+ style(sideCont, {
+ width: "50%",
+ position: "fixed",
+ right: "0",
+ top: "0",
+ height: "100vh",
+ overflowY: "auto",
+ });
+
+ body.appendChild(sideCont);
+
+ let markedItems = [...document.querySelectorAll("blockquote > p")];
+ let documents = [...pre].map(getText);
+
+ window.highlights = [];
+ window.current = 0;
+
+ for (let i = 0; i < markedItems.length; i++) {
+ const text = markedItems[i].innerText;
+ let found = find(text, documents);
+ if (found[0] == 0 && found[1] == Infinity && found[0] == 0) {
+ markedItems.splice(i, 1);
+ i--;
+ } else {
+ window.highlights.push(found);
+ sideCont.appendChild(pre[found[2]]);
+ style(pre[found[2]], { display: "none" });
+ markedItems[i].dataset.index = window.highlights.length - 1;
+ style(markedItems[i], {
+ color: "transparent",
+ height: "0px",
+ overflow: "hidden",
+ });
+ }
+ }
+
+ style(pre[window.highlights[0][2]], { display: "block" });
+ let currentItem = -1;
+ main.onscroll = (e) => {
+ let closestItem;
+ let minDistance = Infinity;
+
+ markedItems.forEach((item, i) => {
+ if (isInViewport(item) || i == markedItems.length - 1) {
+ const distance = Math.abs(item.getBoundingClientRect().top);
+ if (distance < minDistance) {
+ minDistance = distance;
+ closestItem = item;
+ }
+ }
@@ -27,25 +69,12 @@
- body.appendChild(sideCont);
-
- let markedItems = [...document.querySelectorAll("blockquote > p")];
- let documents = [...pre].map(getText);
-
- window.highlights = [];
- window.current = 0;
-
- for (let i = 0; i < markedItems.length; i++) {
- const text = markedItems[i].innerText;
- let found = find(text, documents);
- if (found[0] == 0 && found[1] == Infinity && found[0] == 0) {
- markedItems.splice(i, 1);
- i--;
- } else {
- window.highlights.push(found);
- sideCont.appendChild(pre[found[2]]);
- style(pre[found[2]], { display: "none" });
- markedItems[i].dataset.index = window.highlights.length - 1;
- style(markedItems[i], {
- color: "transparent",
- height: "0px",
- overflow: "hidden",
- });
- }
+ let found = window.highlights[parseInt(closestItem.dataset.index)];
+ if (currentItem != parseInt(closestItem.dataset.index)) {
+ for (let i = 0; i < window.highlights.length; i++) {
+ const element = window.highlights[i];
+ unHighlight(pre[element[2]], element);
+ style(pre[element[2]], { display: "none" });
+ }
+
+ style(pre[found[2]], { display: "block" });
+ highlight(pre[found[2]], found);
+ view(sideCont, pre[found[2]], found);
+ currentItem = parseInt(closestItem.dataset.index);
@@ -52,0 +82,2 @@
+ };
+ let padding = document.createElement("div");
@@ -54,31 +85,3 @@
- style(pre[window.highlights[0][2]], { display: "block" });
- let currentItem = -1;
- main.onscroll = (e) => {
- let closestItem;
- let minDistance = Infinity;
-
- markedItems.forEach((item, i) => {
- if (isInViewport(item) || i == markedItems.length - 1) {
- const distance = Math.abs(item.getBoundingClientRect().top);
- if (distance < minDistance) {
- minDistance = distance;
- closestItem = item;
- }
- }
- });
-
- let found = window.highlights[parseInt(closestItem.dataset.index)];
- if (currentItem != parseInt(closestItem.dataset.index)) {
- for (let i = 0; i < window.highlights.length; i++) {
- const element = window.highlights[i];
- unHighlight(pre[element[2]], element);
- style(pre[element[2]], { display: "none" });
- }
-
- style(pre[found[2]], { display: "block" });
- highlight(pre[found[2]], found);
- view(sideCont, pre[found[2]], found);
- currentItem = parseInt(closestItem.dataset.index);
- }
- };
- let padding = document.createElement("div");
+ style(padding, {
+ height: "100vh",
+ });
@@ -86,5 +89 @@
- style(padding, {
- height: "100vh",
- });
-
- main.appendChild(padding);
+ main.appendChild(padding);
@@ -94,3 +93,3 @@ function style(el, styles) {
- for (const key in styles) {
- el.style[key] = styles[key];
- }
+ for (const key in styles) {
+ el.style[key] = styles[key];
+ }
@@ -100,2 +99,2 @@ function getText(el) {
- let t = "";
- let code = el.querySelector("code");
+ let t = "";
+ let code = el.querySelector("code");
@@ -103,5 +102,4 @@ function getText(el) {
- if (code) {
- for (let a = 0; a < code.children.length; a++) {
- const element = code.children[a];
- t += element.children[1].innerText;
- }
+ if (code) {
+ for (let a = 0; a < code.children.length; a++) {
+ const element = code.children[a];
+ t += element.children[1].innerText;
@@ -109 +107,2 @@ function getText(el) {
- return t;
+ }
+ return t;
@@ -113,34 +112,20 @@ function find(text, documents) {
- let q = text.replace(/\s/g, "");
-
- let index = 0;
- let start = 0;
- let end = Infinity;
-
- for (let i = 0; i < documents.length; i++) {
- const d = documents[i].replace(/\s/g, "");
- if (d.indexOf(q) != -1) {
- let lines = documents[i].split("\n");
- for (let a = 0; a < lines.length; a++) {
- if (
- lines
- .slice(0, a)
- .join("\n")
- .replace(/\s/g, "")
- .indexOf(q) != -1
- ) {
- end = a;
- for (let b = 0; b < a + 1; b++) {
- if (
- lines
- .slice(b, a)
- .join("\n")
- .replace(/\s/g, "")
- .indexOf(q) == -1
- ) {
- start = b;
- index = i;
- break;
- }
- }
- break;
- }
+ let q = text.replace(/\s/g, "");
+
+ let index = 0;
+ let start = 0;
+ let end = Infinity;
+
+ for (let i = 0; i < documents.length; i++) {
+ const d = documents[i].replace(/\s/g, "");
+ if (d.indexOf(q) != -1) {
+ let lines = documents[i].split("\n");
+ for (let a = 0; a < lines.length; a++) {
+ if (lines.slice(0, a).join("\n").replace(/\s/g, "").indexOf(q) != -1) {
+ end = a;
+ for (let b = 0; b < a + 1; b++) {
+ if (
+ lines.slice(b, a).join("\n").replace(/\s/g, "").indexOf(q) == -1
+ ) {
+ start = b;
+ index = i;
+ break;
@@ -147,0 +133,2 @@ function find(text, documents) {
+ }
+ break;
@@ -148,0 +136 @@ function find(text, documents) {
+ }
@@ -150 +138,2 @@ function find(text, documents) {
- return [start, end, index];
+ }
+ return [start, end, index];
@@ -154 +143 @@ function highlight(el, lines) {
- let code = el.querySelector("code");
+ let code = el.querySelector("code");
@@ -156,6 +145,6 @@ function highlight(el, lines) {
- for (let a = lines[0] - 1; a < lines[1]; a++) {
- const element = code.children[a];
- style(element, {
- background: "#d2dc0024",
- });
- }
+ for (let a = lines[0] - 1; a < lines[1]; a++) {
+ const element = code.children[a];
+ style(element, {
+ background: "#d2dc0024",
+ });
+ }
@@ -165 +154 @@ function unHighlight(el, lines) {
- let code = el.querySelector("code");
+ let code = el.querySelector("code");
@@ -167,6 +156,6 @@ function unHighlight(el, lines) {
- for (let a = lines[0] - 1; a < lines[1]; a++) {
- const element = code.children[a];
- style(element, {
- background: "",
- });
- }
+ for (let a = lines[0] - 1; a < lines[1]; a++) {
+ const element = code.children[a];
+ style(element, {
+ background: "",
+ });
+ }
@@ -176,9 +165,8 @@ function isInViewport(element) {
- const rect = element.getBoundingClientRect();
- return (
- rect.top >= 0 &&
- rect.left >= 0 &&
- rect.bottom <=
- (window.innerHeight || document.documentElement.clientHeight) &&
- rect.right <=
- (window.innerWidth || document.documentElement.clientWidth)
- );
+ const rect = element.getBoundingClientRect();
+ return (
+ rect.top >= 0 &&
+ rect.left >= 0 &&
+ rect.bottom <=
+ (window.innerHeight || document.documentElement.clientHeight) &&
+ rect.right <= (window.innerWidth || document.documentElement.clientWidth)
+ );
@@ -188,17 +176,15 @@ function view(parentElement, el, lines) {
- let code = el.querySelector("code");
- let childElement = code.children[lines[0] - 1];
- const parentRect = parentElement.getBoundingClientRect();
- const childRect = childElement.getBoundingClientRect();
- const parentScrollTop = parentElement.scrollTop;
-
- // Calculate the vertical position to scroll to center the child element
- const targetScrollTop =
- childRect.top -
- parentRect.top -
- (parentRect.height - childRect.height) / 2;
-
- // Scroll the parent element to the calculated position
- parentElement.scrollTo({
- top: parentScrollTop + targetScrollTop,
- behavior: "smooth", // Optional: for smooth scrolling
- });
+ let code = el.querySelector("code");
+ let childElement = code.children[lines[0] - 1];
+ const parentRect = parentElement.getBoundingClientRect();
+ const childRect = childElement.getBoundingClientRect();
+ const parentScrollTop = parentElement.scrollTop;
+
+ // Calculate the vertical position to scroll to center the child element
+ const targetScrollTop =
+ childRect.top - parentRect.top - (parentRect.height - childRect.height) / 2;
+
+ // Scroll the parent element to the calculated position
+ parentElement.scrollTo({
+ top: parentScrollTop + targetScrollTop,
+ behavior: "smooth", // Optional: for smooth scrolling
+ });