import 'classlist-polyfill'; import Promise from 'bluebird'; import Markdown from 'markdown'; const md = Markdown.markdown.toHTML; import workText from 'raw-loader!./work.txt'; import pgpText from 'raw-loader!./pgp.txt'; import headerHTML from 'raw-loader!./header.html'; let styleText = [0, 1, 2, 3].map((i) => require('raw-loader!./styles' + i + '.css').default); import preStyles from 'raw-loader!./prestyles.css'; import replaceURLs from './lib/replaceURLs'; import {default as writeChar, writeSimpleChar, handleChar} from './lib/writeChar'; import getPrefix from './lib/getPrefix'; // Vars that will help us get er done const isDev = window.location.hostname === 'localhost'; const speed = isDev ? 0 : 16; let style, styleEl, workEl, pgpEl, skipAnimationEl, pauseEl; let animationSkipped = false, done = false, paused = false; let browserPrefix; // Wait for load to get started. document.addEventListener("DOMContentLoaded", function() { getBrowserPrefix(); populateHeader(); getEls(); createEventHandlers(); startAnimation(); }); async function startAnimation() { try { await writeTo(styleEl, styleText[0], 0, speed, true, 1); await writeTo(workEl, workText, 0, speed, false, 1); await writeTo(styleEl, styleText[1], 0, speed, true, 1); createWorkBox(); await Promise.delay(1000); await writeTo(styleEl, styleText[2], 0, speed, true, 1); await writeTo(pgpEl, pgpText, 0, speed, false, 32); await writeTo(styleEl, styleText[3], 0, speed, true, 1); } // Flow control straight from the ghettos of Milwaukee catch(e) { if (e.message === "SKIP IT") { surprisinglyShortAttentionSpan(); } else { throw e; } } } // Skips all the animations. async function surprisinglyShortAttentionSpan() { if (done) return; done = true; pgpEl.innerHTML = pgpText; let txt = styleText.join('\n'); // The work-text animations are rough style.textContent = "#work-text * { " + browserPrefix + "transition: none; }"; style.textContent += txt; let styleHTML = ""; for(let i = 0; i < txt.length; i++) { styleHTML = handleChar(styleHTML, txt[i]); } styleEl.innerHTML = styleHTML; createWorkBox(); // There's a bit of a scroll problem with this thing let start = Date.now(); while(Date.now() - 1000 > start) { workEl.scrollTop = Infinity; styleEl.scrollTop = pgpEl.scrollTop = Infinity; await Promise.delay(16); } } /** * Helpers */ let endOfSentence = /[\.\?\!]\s$/; let comma = /\D[\,]\s$/; let endOfBlock = /[^\/]\n\n$/; async function writeTo(el, message, index, interval, mirrorToStyle, charsPerInterval){ if (animationSkipped) { // Lol who needs proper flow control throw new Error('SKIP IT'); } // Write a character or multiple characters to the buffer. let chars = message.slice(index, index + charsPerInterval); index += charsPerInterval; // Ensure we stay scrolled to the bottom. el.scrollTop = el.scrollHeight; // If this is going to