pitch = {
var transition = "", extra="", curslide = -1, parent=undefined, timer=undefined, autonext=0, speak='';
var pitch = function(a,...r) {
const div = Object.assign(html`<div>`,{className:'slide '+extra,transition,extra,autonext,speak});
div.appendChild(a instanceof Array?md.apply(this, arguments):a); speak=transition=extra=""; autonext=0; div._parent = parent; parent=undefined;
var container = (this instanceof HTMLElement)?this:Object.assign(html`<DIV></DIV>`,{position:'relative',className:'_slide',onclick:()=>pitch.present(++curslide)}); while(container.firstChild) container.removeChild(container.firstChild); container.appendChild(div); container._div = div;
return container;
};
pitch.img = function(a,...r){extra='img'; return pitch.apply(this,[Object.assign(new Image(),{src:a})]);}
pitch.js = function(a,...r){extra='code'; return pitch.apply(this,[["```javasript\n",...a,"\n```"],"",...r,""]);}
pitch.code = function(a,...r){extra='code'; return pitch.apply(this,[["```\n",...a,"\n```"],"",...r,""]);}
pitch.full = function(){extra='full'; return pitch.apply(this,arguments); };
pitch.inplace = function(x){ parent=x; return pitch; };
pitch.auto = function(x){ autonext=x*1000; return pitch; };
pitch.speak = function(x){ speak=x; return pitch; };
["fade","left","right","blur","sepia"].forEach(x=>pitch.__defineGetter__(x,()=>{transition+=x+" "; return pitch; }));
pitch.present = (x,fast)=>{
if (timer) clearTimeout(timer);
var els = [...document.querySelectorAll("._slide")].map(x=>x._div), el = els[x%els.length]; if (!el) return;
els.forEach(x=>{if(x._parent && x.parentElement != x._parent) { x._parent.insertBefore(x,x._parent.firstChild); x.style.position="absolute"; x.style.top="0px"; x.style.left="0px"; x.style.zIndex=-10;}});
el.scrollIntoView({block:'start',behavior:fast?'instant':'smooth'}); el.parentElement.scrollLeft=0;
[...els].forEach(e=>e.className=(e==el)?'slide '+e.extra:('slide '+e.extra+' '+e.transition));
if (el.autonext) timer = setTimeout(()=>{ pitch.present(++curslide); },el.autonext);
if (el.speak) speechSynthesis.speak(Object.assign(new SpeechSynthesisUtterance(el.speak),{lang:'en-US'}));
}
window.onkeydown = (e)=>{
if (e.keyCode==36) { curslide=0; e.preventDefault(); pitch.present(curslide,true); }
if (~[33,34].indexOf(e.keyCode)) { curslide+=2*(e.keyCode-33.5); e.preventDefault(); pitch.present(curslide) }
}
pitch.styles = html`
<style>
.slide { width: calc(100% + 28px); margin: 0 -14px; padding: 10%;
background: #333; color: #eee; min-height: 65vw; font-size: 5vw; overflow:hidden;
line-height: 1.15; display: flex; align-items: center; box-sizing:border-box;
transition: opacity 1s ease-in-out, margin 1s ease-in-out, padding 1s ease-in-out, filter 1.5s ease-in-out;
}
.slide.fade { opacity: 0; }
.slide.left { margin-left: calc(-100% - 42px); }
.slide.right { padding-left: calc(100% + 42px); overflow:hidden; }
.slide.blur { filter: blur(20px); }
.slide.sepia { filter: sepia(100%); }
.slide.blur.sepia { filter: blur(20px) sepia(100%);}
.slide h1, .slide h2, .slide h3 { color:#eee }
.slide p, .slide pre, .slide img { max-width: 100%; }
.slide blockquote, .slide ol, .slide ul { max-width: none; }
.slide code { font-size: 3vw; }
.slide.code { background: #eee; color: #444; padding-top:0; }
.slide.img { max-height:80vw; overflow:hidden; }
.slide.full { padding:0; background:transparent; }
_slide { overflow:hidden; position:relative; min-height: 65vw; }
</style>`;
return pitch;
}