export function part(demo) {
	document.body.innerHTML = `<style>body{margin: 6vh 10vw 2vh 10vw;color:#FFF;background-color:#000;}#Typer{font:2vw AtariLo;height:90vh;overflow:hidden;background:repeating-conic-gradient(#808080 0% 25%, transparent 0% 50%) 50% / 4px 4px;}
	@keyframes opaIn{0%{opacity:0}100%{opacity:1}}
	@keyframes opaOut{0%{opacity:1}100%{opacity:0}}
	.L{animation:opaIn .5s linear 0s normal forwards;}
	</style>
	<pre id="Typer"></pre>`
	const spd = 15
	typer(document.getElementById('Typer'), [
		{c: '', s: spd, t:''},
		{c: '', s: spd, t:'Shadow Party takes place at a very'},
		{c: '', s: spd, t:'special place in france'},
		{c: '', s: spd, t:''},
		{c: '', s: spd, t:'There is a lake and sometimes visitors'},
		{c: '', s: spd, t:'from far far away will show up'},
		{c: '', s: spd, t:''},
		{c: '', s: spd, t:'They are here in their 🛸 again         '},
		{c: '', s: spd, t:'Today the 👽 say thank you for'},
		{c: '', s: spd, t:'a lot of 🥬🥬🥬 with 🍺 and 🌭'},
		{c: '', s: spd, t:''},
		{c: '', s: spd, t:'Catch them and bring them to the corners'},
		{c: '', s: spd, t:'You can carry two items in your hands'},
		{c: '', s: spd, t:''},
		{c: '', s: spd, t:'Play with 🖱️ ⌨️ 🎮 🕹️'},
		{c: '', s: spd, t:'But for fairness in two player mode 🤖🤡'},
		{c: '', s: spd, t:'better use 🎮 or best 🕹️'},
		{c: '', s: spd, t:''},
		{c: '', s: spd, t:'Use 🕹️ or ⌨️ to start two players'},
		{c: '', s: spd, t:''},
		{c: '', s: spd, t:''},
	])
	//setTimeout(()=>{demo.next()},45*1000)
	demo.next()
}

let typeLines = []
function typer(dest, lines) {
	typeLines = lines
	typeLine(dest)
}
function typeLine(dest) {
	if (typeLines.length == 0) return
	const line = typeLines.splice(0,1)[0]
	// start of line
	dest.insertAdjacentHTML('beforeEnd', '<span class="'+line.c+'">')

	function typeLetter(dest, line) {
		//console.log('typeLetter', line)
		if (line.t.length == 0) {
			dest.insertAdjacentHTML('beforeEnd', '</span></br>')
			typeLine(dest)
			return
		}
		let letter = line.t.substring(0, 1)
		// letter can also have class so its a HTML tag, just look for <
		if (letter == '<') {
			let till = line.t.indexOf('>')+1				// end of opening tag
			till += line.t.substring(till).indexOf('>')+1	// end of closing tag
			letter = line.t.substring(0,till)
			line.t = line.t.substring(till)
			dest.insertAdjacentHTML('beforeEnd', letter)
		} else {
			line.t = line.t.substring(1)
			dest.insertAdjacentHTML('beforeEnd', ['<span class="',line.c,'"><span class="L">',letter,'</span>'].join('') )
		}
		dest.scrollTo(0, 9000)
		setTimeout(()=>{
			typeLetter(dest, line)
		},1000/line.s)

	}
	typeLetter(dest, line)
}