Skip to content
Myr

custom.js

This file

Path

docs/js/custom.js

115 lines · 4.3 KiB · JavaScript

Last changed by

👷 Upgrade build docs configs (#914)Sebastián Ramírezbefore adoption5b82463

History of this file

Take it

The walk stopped after 200 commits: lines older than cc27f3d point at it.

🔨 Update docs Termynal scripts to not include line nums for local dev (#882)Sebastián Ramírezbefore adoptioncae23ed

lines 1–6why, one step back
1function setupTermynal() {
2 document.querySelectorAll(".use-termynal").forEach(node => {3 node.style.display = "block";4 new Termynal(node, {5 lineDelay: 5006 });

📝 Update release notesgithub-actionsbefore adoptioncc27f3d

line 7why, one step back
7 });

🔨 Update docs Termynal scripts to not include line nums for local dev (#882)Sebastián Ramírezbefore adoptioncae23ed

lines 8–12why, one step back
8 const progressLiteralStart = "---> 100%";
9 const promptLiteralStart = "$ ";10 const customPromptLiteralStart = "# ";11 const termynalActivateClass = "termy";12 let termynals = [];

📝 Update release notesgithub-actionsbefore adoptioncc27f3d

line 13why, one step back
13

🔨 Update docs Termynal scripts to not include line nums for local dev (#882)Sebastián Ramírezbefore adoptioncae23ed

lines 14–32why, one step back
14 function createTermynals() {
15 document16 .querySelectorAll(`.${termynalActivateClass} .highlight code`)17 .forEach(node => {18 const text = node.textContent;19 const lines = text.split("\n");20 const useLines = [];21 let buffer = [];22 function saveBuffer() {23 if (buffer.length) {24 let isBlankSpace = true;25 buffer.forEach(line => {26 if (line) {27 isBlankSpace = false;28 }29 });30 dataValue = {};31 if (isBlankSpace) {32 dataValue["delay"] = 0;

📝 Update release notesgithub-actionsbefore adoptioncc27f3d

line 33why, one step back
33 }

🔨 Update docs Termynal scripts to not include line nums for local dev (#882)Sebastián Ramírezbefore adoptioncae23ed

lines 34–42why, one step back
34 if (buffer[buffer.length - 1] === "") {
35 // A last single <br> won't have effect36 // so put an additional one37 buffer.push("");38 }39 const bufferValue = buffer.join("<br>");40 dataValue["value"] = bufferValue;41 useLines.push(dataValue);42 buffer = [];

📝 Update release notesgithub-actionsbefore adoptioncc27f3d

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

🔨 Update docs Termynal scripts to not include line nums for local dev (#882)Sebastián Ramírezbefore adoptioncae23ed

lines 45–80why, one step back
45 for (let line of lines) {
46 if (line === progressLiteralStart) {47 saveBuffer();48 useLines.push({49 type: "progress"50 });51 } else if (line.startsWith(promptLiteralStart)) {52 saveBuffer();53 const value = line.replace(promptLiteralStart, "").trimEnd();54 useLines.push({55 type: "input",56 value: value57 });58 } else if (line.startsWith("// ")) {59 saveBuffer();60 const value = "💬 " + line.replace("// ", "").trimEnd();61 useLines.push({62 value: value,63 class: "termynal-comment",64 delay: 065 });66 } else if (line.startsWith(customPromptLiteralStart)) {67 saveBuffer();68 const promptStart = line.indexOf(promptLiteralStart);69 if (promptStart === -1) {70 console.error("Custom prompt found but no end delimiter", line)71 }72 const prompt = line.slice(0, promptStart).replace(customPromptLiteralStart, "")73 let value = line.slice(promptStart + promptLiteralStart.length);74 useLines.push({75 type: "input",76 value: value,77 prompt: prompt78 });79 } else {80 buffer.push(line);

📝 Update release notesgithub-actionsbefore adoptioncc27f3d

lines 81–82why, one step back
81 }
82 }

🔨 Update docs Termynal scripts to not include line nums for local dev (#882)Sebastián Ramírezbefore adoptioncae23ed

lines 83–91why, one step back
83 saveBuffer();
84 const div = document.createElement("div");85 node.replaceWith(div);86 const termynal = new Termynal(div, {87 lineData: useLines,88 noInit: true,89 lineDelay: 50090 });91 termynals.push(termynal);

📝 Update release notesgithub-actionsbefore adoptioncc27f3d

line 92why, one step back
92 });

🔨 Update docs Termynal scripts to not include line nums for local dev (#882)Sebastián Ramírezbefore adoptioncae23ed

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

📝 Update release notesgithub-actionsbefore adoptioncc27f3d

line 102why, one step back
102 });

🔨 Update docs Termynal scripts to not include line nums for local dev (#882)Sebastián Ramírezbefore adoptioncae23ed

lines 103–106why, one step back
103 }
104 window.addEventListener("scroll", loadVisibleTermynals);105 createTermynals();106 loadVisibleTermynals();

📝 Update release notesgithub-actionsbefore adoptioncc27f3d

lines 107–108why, one step back
107}
108

🔨 Update docs Termynal scripts to not include line nums for local dev (#882)Sebastián Ramírezbefore adoptioncae23ed

lines 109–110why, one step back
109async function main() {
110 setupTermynal()

📝 Update release notesgithub-actionsbefore adoptioncc27f3d

line 111why, one step back
111}

🔨 Update docs Termynal scripts to not include line nums for local dev (#882)Sebastián Ramírezbefore adoptioncae23ed

line 112why, one step back
112

👷 Upgrade build docs configs (#914)Sebastián Ramírezbefore adoption5b82463

lines 113–115why, one step back
113document$.subscribe(() => {
114 main()115})