Skip to content
Myr

custom.js

This file

Path

docs/js/custom.js

105 lines · 3.8 KiB · JavaScript

Last changed by

:sparkles: Add docs for CLI Options with testsSebastián Ramírezbefore adoption9fb09d4

History of this file

Take it

:sparkles: Add termynal for awesome docsSebastián Ramírezbefore adoptionc004fb6

lines 1–2why, one step back
1document.querySelectorAll(".use-termynal").forEach(node => {
2 node.style.display = "block";

:sparkles: Fix Termynal size, update first steps, add fast buttonSebastián Ramírezbefore adoption234e50a

lines 3–5why, one step back
3 new Termynal(node, {
4 lineDelay: 5005 });

:sparkles: Add termynal for awesome docsSebastián Ramírezbefore adoptionc004fb6

lines 6–8why, one step back
6});
7const progressLiteralStart = "---> 100%";8const promptLiteralStart = "$ ";

:sparkles: Add docs for CLI Options with testsSebastián Ramírezbefore adoption9fb09d4

line 9why, one step back
9const customPromptLiteralStart = "# ";

:sparkles: Add termynal for awesome docsSebastián Ramírezbefore adoptionc004fb6

line 10why, one step back
10const termynalActivateClass = "termy";

:sparkles: Fix Termynal size, update first steps, add fast buttonSebastián Ramírezbefore adoption234e50a

line 11why, one step back
11let termynals = [];

:sparkles: Add termynal for awesome docsSebastián Ramírezbefore adoptionc004fb6

line 12why, one step back
12

:sparkles: Fix Termynal size, update first steps, add fast buttonSebastián Ramírezbefore adoption234e50a

line 13why, one step back
13function createTermynals() {

:sparkles: Add termynal for awesome docsSebastián Ramírezbefore adoptionc004fb6

lines 14–16why, one step back
14 document
15 .querySelectorAll(`.${termynalActivateClass} .codehilite`)16 .forEach(node => {

:sparkles: Fix Termynal size, update first steps, add fast buttonSebastián Ramírezbefore adoption234e50a

lines 17–26why, one step back
17 const text = node.textContent;
18 const lines = text.split("\n");19 const useLines = [];20 let buffer = [];21 function saveBuffer() {22 if (buffer.length) {23 let isBlankSpace = true;24 buffer.forEach(line => {25 if (line) {26 isBlankSpace = false;

:sparkles: Add termynal for awesome docsSebastián Ramírezbefore adoptionc004fb6

line 27why, one step back
27 }

:sparkles: Fix Termynal size, update first steps, add fast buttonSebastián Ramírezbefore adoption234e50a

lines 28–31why, one step back
28 });
29 dataValue = {};30 if (isBlankSpace) {31 dataValue["delay"] = 0;

:sparkles: Add termynal for awesome docsSebastián Ramírezbefore adoptionc004fb6

line 32why, one step back
32 }

:sparkles: Add docs for CLI Options with testsSebastián Ramírezbefore adoption9fb09d4

lines 33–34why, one step back
33 if (buffer[buffer.length - 1] === "") {
34 // A last single <br> won't have effect

:sparkles: Fix Termynal size, update first steps, add fast buttonSebastián Ramírezbefore adoption234e50a

lines 35–36why, one step back
35 // so put an additional one
36 buffer.push("");

:sparkles: Add termynal for awesome docsSebastián Ramírezbefore adoptionc004fb6

line 37why, one step back
37 }

:sparkles: Fix Termynal size, update first steps, add fast buttonSebastián Ramírezbefore adoption234e50a

lines 38–41why, one step back
38 const bufferValue = buffer.join("<br>");
39 dataValue["value"] = bufferValue;40 useLines.push(dataValue);41 buffer = [];

:sparkles: Add termynal for awesome docsSebastián Ramírezbefore adoptionc004fb6

lines 42–43why, one step back
42 }
43 }

:sparkles: Fix Termynal size, update first steps, add fast buttonSebastián Ramírezbefore adoption234e50a

lines 44–58why, one step back
44 for (let line of lines) {
45 if (line === progressLiteralStart) {46 saveBuffer();47 useLines.push({48 type: "progress"49 });50 } else if (line.startsWith(promptLiteralStart)) {51 saveBuffer();52 const value = line.replace(promptLiteralStart, "").trimEnd();53 useLines.push({54 type: "input",55 value: value56 });57 } else if (line.startsWith("// ")) {58 saveBuffer();

:sparkles: Add docs for CLI Options with testsSebastián Ramírezbefore adoption9fb09d4

line 59why, one step back
59 const value = "💬 " + line.replace("// ", "").trimEnd();

:sparkles: Fix Termynal size, update first steps, add fast buttonSebastián Ramírezbefore adoption234e50a

lines 60–63why, one step back
60 useLines.push({
61 value: value,62 class: "termynal-comment",63 delay: 0

:sparkles: Add docs for CLI Options with testsSebastián Ramírezbefore adoption9fb09d4

lines 64–76why, one step back
64 });
65 } else if (line.startsWith(customPromptLiteralStart)) {66 saveBuffer();67 const promptStart = line.indexOf(promptLiteralStart);68 if (promptStart === -1) {69 console.error("Custom prompt found but no end delimiter", line)70 }71 const prompt = line.slice(0, promptStart).replace(customPromptLiteralStart, "")72 let value = line.slice(promptStart + promptLiteralStart.length);73 useLines.push({74 type: "input",75 value: value,76 prompt: prompt

:sparkles: Fix Termynal size, update first steps, add fast buttonSebastián Ramírezbefore adoption234e50a

lines 77–90why, one step back
77 });
78 } else {79 buffer.push(line);80 }81 }82 saveBuffer();83 const div = document.createElement("div");84 node.replaceWith(div);85 const termynal = new Termynal(div, {86 lineData: useLines,87 noInit: true,88 lineDelay: 50089 });90 termynals.push(termynal);

:sparkles: Add termynal for awesome docsSebastián Ramírezbefore adoptionc004fb6

lines 91–92why, one step back
91 });
92}

:sparkles: Fix Termynal size, update first steps, add fast buttonSebastián Ramírezbefore adoption234e50a

lines 93–102why, one step back
93
94function loadVisibleTermynals() {95 termynals = termynals.filter(termynal => {96 if (termynal.container.getBoundingClientRect().top - innerHeight <= 0) {97 termynal.init();98 return false;99 }100 return true;101 });102}

:sparkles: Add termynal for awesome docsSebastián Ramírezbefore adoptionc004fb6

line 103why, one step back
103window.addEventListener("scroll", loadVisibleTermynals);

:sparkles: Fix Termynal size, update first steps, add fast buttonSebastián Ramírezbefore adoption234e50a

line 104why, one step back
104createTermynals();

:sparkles: Add termynal for awesome docsSebastián Ramírezbefore adoptionc004fb6

line 105why, one step back
105loadVisibleTermynals();