Files
sm-bm-plugin/public/assets/engine-DDeQk6Ow.js

2 lines
2.5 KiB
JavaScript

const P=new Set(["ArrowUp","ArrowDown","PageUp","PageDown"," ","Home","End"]);function y(l){const s=/^#(\d+)(s)?$/.exec(l);return s?{number:Number(s[1]),special:s[2]==="s"}:{number:null,special:!1}}function k(l){const s=l.slides,t=s.length,d=l.mode==="speaker";let a=0,i=!1,m=null,h=!1;function K(e){return t===0?0:Math.max(0,Math.min(t-1,e))}function b(e){const n=s.findIndex(r=>r.number===e);return n>=0?n:e>=1&&e<=t?e-1:0}function S(){const e=s[a];e&&l.history.replaceState(l.history.state,"","#"+e.number)}function c(){l.onChange?.()}function u(e){t!==0&&(a=K(e),i=!1,S(),l.onNavigate?.(a),c())}function f(e){i=!!s[a]?.hasSpecial&&e,c()}const w=y(l.hash??"");w.number!=null&&t>0&&(a=b(w.number),i=w.special&&!!s[a]?.hasSpecial),t>0&&S();function H(){const e=s[a],n=e?.number??0,r=!!e?.hasSpecial,o=i&&r,x=o?`${n} S`:String(n),$=r&&!o?" · S":"",g=e?String(n):"";return{index:a,number:n,total:t,special:o,hasSpecial:r,on:g?[o?`${g}s`:g]:[],metaText:t===0?"":`${x} / ${t}${$}`,metaHTML:t===0?"":`<b>${x}</b> / ${t}${$}`,panel:m,hash:g?`#${n}`:"",toolbarHidden:h,progress:t===0?0:(a+1)/t*100}}function p(e){m=m===e?null:e,c()}function A(e){if(e.ctrlKey||e.metaKey||e.altKey||e.reading)return"ignored";const n=e.key;if(e.targetIsButton&&(n===" "||n==="Enter")||e.targetIsPanel&&P.has(n)||t===0)return"ignored";if(n==="ArrowRight"||n==="ArrowDown"||n==="PageDown"||n===" ")return u(a+1),"handled";if(n==="ArrowLeft"||n==="ArrowUp"||n==="PageUp")return i?f(!1):u(a-1),"handled";if(n==="Home")return u(0),"handled";if(n==="End")return u(t-1),"handled";if(n==="Escape")return i?(f(!1),"handled"):"ignored";const r=n.length===1?n.toLowerCase():"";return r==="n"?(p("notes"),"handled"):r==="z"?(p("srcs"),"handled"):r==="s"?(f(!i),"handled"):r==="h"?(h=!h,c(),"handled"):r==="f"?"fullscreen":d&&r==="p"?(p("say"),"handled"):d&&r==="t"?"pause":d&&r==="c"?"clock":d&&r==="r"?"reset":d&&r==="j"?"scheme":"ignored"}return{snapshot:H,applyKey:A,go:u,next:()=>u(a+1),previous:()=>{i?f(!1):u(a-1)},togglePanel:p,toggleSpecial:()=>f(!i),closeSpecial:()=>f(!1),openSpecial:()=>f(!0),toggleToolbar:()=>{h=!h,c()},onScroll:()=>{},swipe:(e,n)=>n||t===0||Math.abs(e)<=50?!1:(u(a+(e<0?1:-1)),!0),followHash:e=>{const n=y(e);if(n.number==null||t===0)return;const r=b(n.number),o=n.special&&!!s[r]?.hasSpecial;r===a&&o===i||(a=r,i=o,c())},showId:e=>{const n=y("#"+e);if(n.number==null||t===0)return;const r=b(n.number),o=n.special&&!!s[r]?.hasSpecial;r===a&&o===i||(a=r,i=o,S(),c())}}}function E(l,s){return l.applyKey(s)}export{E as a,k as c};