keyboardly
Version:
A keyboardly library
13 lines (12 loc) • 26.8 kB
JavaScript
/*!
* Keyboardly v0.2.1 (https://github.com/victornpb/keyboardly)
* Copyright (c) victornpb
* @license MIT
*/
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).Keyboardly=e()}(this,(function(){"use strict";var t=!1,e="[Keyboardly]";function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function i(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}function r(t,e,n){return e&&i(t.prototype,e),n&&i(t,n),t}function o(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function a(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&u(t,e)}function s(t){return(s=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function u(t,e){return(u=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function l(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function c(t,e){if(e&&("object"==typeof e||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return l(t)}function h(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,i=s(t);if(e){var r=s(this).constructor;n=Reflect.construct(i,arguments,r)}else n=i.apply(this,arguments);return c(this,n)}}function d(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var n=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null==n)return;var i,r,o=[],a=!0,s=!1;try{for(n=n.call(t);!(a=(i=n.next()).done)&&(o.push(i.value),!e||o.length!==e);a=!0);}catch(t){s=!0,r=t}finally{try{a||null==n.return||n.return()}finally{if(s)throw r}}return o}(t,e)||f(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function f(t,e){if(t){if("string"==typeof t)return v(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?v(t,e):void 0}}function v(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,i=new Array(e);n<e;n++)i[n]=t[n];return i}function p(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!n){if(Array.isArray(t)||(n=f(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var i=0,r=function(){};return{s:r,n:function(){return i>=t.length?{done:!0}:{done:!1,value:t[i++]}},e:function(t){throw t},f:r}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,a=!0,s=!1;return{s:function(){n=n.call(t)},n:function(){var t=n.next();return a=t.done,t},e:function(t){s=!0,o=t},f:function(){try{a||null==n.return||n.return()}finally{if(s)throw o}}}}function y(t,e){return function(t,e){if(e.get)return e.get.call(t);return e.value}(t,g(t,e,"get"))}function m(t,e,n){return function(t,e,n){if(e.set)e.set.call(t,n);else{if(!e.writable)throw new TypeError("attempted to set read only private field");e.value=n}}(t,g(t,e,"set"),n),n}function g(t,e,n){if(!e.has(t))throw new TypeError("attempted to "+n+" private field on non-instance");return e.get(t)}function w(t,e,n){!function(t,e){if(e.has(t))throw new TypeError("Cannot initialize the same private elements twice on an object")}(t,e),e.set(t,n)}var b=!!navigator.platform.match(/Mac|iOS|iPod|iPad|Apple/i);function k(t,e,n){var i=!t.disabled,r=t.getAttribute(n);return i&&r&&function(t,e){function n(t,e){var n=t.split(/-|\+/),i=n[n.length-1];return e.ctrlKey===n.includes("ctrl")&&e.shiftKey===n.includes("shift")&&e.altKey===n.includes("alt")&&e.metaKey===n.includes("meta")&&(e.key===i||e.code===i)}b&&(t=(t=t.replace(/cmd|command/g,"meta")).replace(/ctrl/g,"meta"));if(t.includes("|")){var i,r=p(t.split("|"));try{for(r.s();!(i=r.n()).done;){if(n(i.value,e))return!0}}catch(t){r.e(t)}finally{r.f()}return!1}return n(t,e)}(r,e)}var E="data-prevent";function C(n,i,r){var o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:A;if(n){var a=document.activeElement,s="INPUT"===a.nodeName||"TEXTAREA"===a.nodeName,u=Array.from(n.querySelectorAll("[".concat(r,"]"))).filter((function(t){return k(t,i,r)}));if(u.length){if(s&&u.every((function(t){return!t.hasAttribute(E)})))return;u.forEach((function(r){"function"==typeof o&&(t&&console.log(e,"dispatching shortcut...",n,r,i,o),o({container:n,element:r,event:i}))}))}}}function A(t){t.container;var e=t.element,n=t.event;n.preventDefault(),n.stopPropagation(),n.stopImmediatePropagation();try{e.focus()}catch(t){}try{e.click()}catch(t){}}function I(t,e,n){var i,r=t.map(x),o=x(e||t[0]),a=n.shiftKey;if("ArrowUp"===n.key?i=function(t,e,n){var i,r,o=p(e);try{for(o.s();!(r=o.n()).done;){var a=r.value;if(n&&_(a,0),a.element!==t.element)"up"===T(O(t,a))&&(i||(i=a),n&&_(a,1),M(t,a)<M(t,i)&&(i=a))}}catch(t){o.e(t)}finally{o.f()}return i}(o,r,a):"ArrowDown"===n.key?i=function(t,e,n){var i,r,o=p(e);try{for(o.s();!(r=o.n()).done;){var a=r.value;if(n&&_(a,0),a.element!==t.element)"down"===T(O(t,a))&&(i||(i=a),n&&_(a,1),M(t,a)<M(t,i)&&(i=a))}}catch(t){o.e(t)}finally{o.f()}return i}(o,r,a):"ArrowLeft"===n.key?i=function(t,e,n){var i,r,o=p(e);try{for(o.s();!(r=o.n()).done;){var a=r.value;if(n&&_(a,0),a.element!==t.element)"left"===T(O(t,a))&&(i||(i=a),n&&_(a,1),M(t,a)<M(t,i)&&(i=a))}}catch(t){o.e(t)}finally{o.f()}return i}(o,r,a):"ArrowRight"===n.key&&(i=function(t,e,n){var i,r,o=p(e);try{for(o.s();!(r=o.n()).done;){var a=r.value;if(n&&_(a,0),a.element!==t.element)"right"===T(O(t,a))&&(i||(i=a),n&&_(a,1),M(t,a)<M(t,i)&&(i=a))}}catch(t){o.e(t)}finally{o.f()}return i}(o,r,a)),!a)return i?(n.preventDefault(),a&&_(i),i.element):null}function x(t){var e=t.getBoundingClientRect();return{element:t,left:e.left,top:e.top,right:e.right,bottom:e.bottom,width:e.width,height:e.height,x:e.left+Math.floor(e.width/2),y:e.top+Math.floor(e.height/2)}}function T(t){return t>=45&&t<135?"up":t>=135&&t<225?"right":t>=225&&t<315?"down":t>=315||t<45?"left":void 0}function M(t,e){var n=e.x-t.x,i=e.y-t.y;return Math.sqrt(n*n+i*i)}function O(t,e){var n=t.x-e.x,i=t.y-e.y,r=180*Math.atan2(i,n)/Math.PI;return r%360+(r<0?360:0)}function _(e,n){t&&(e.element.style.backgroundColor=n?"#FF0":"#333"),setTimeout((function(){return e.element.style.backgroundColor=""}),3e3)}function P(t){return!(void 0!==t.disabled?t.disabled:t.hasAttribute("disabled"))}var S=new WeakMap,R=new WeakMap,N=new WeakMap,B=function(){function i(){n(this,i),o(this,"ACTIVE_CLASS","focus"),o(this,"COMPONENT_SELECTOR","[data-shortcut-component]"),o(this,"activeComponent",null),w(this,S,{writable:!0,value:null}),w(this,R,{writable:!0,value:null}),w(this,N,{writable:!0,value:null}),m(this,S,this._focusPanelOnClickHandler.bind(this)),m(this,R,this._tabFocusFollowerHandler.bind(this)),m(this,N,this._navigationHandler.bind(this))}return r(i,[{key:"init",value:function(){document.addEventListener("click",y(this,S)),document.addEventListener("focusin",y(this,R)),document.addEventListener("keydown",y(this,N))}},{key:"destroy",value:function(){document.removeEventListener("click",y(this,S)),document.removeEventListener("focusin",y(this,R)),document.removeEventListener("keydown",y(this,N))}},{key:"_focusPanelOnClickHandler",value:function(n){t&&console.log(e,"focusPanelOnClickHandler",n);var i=n.target;this.focusComponentOfTargetElm(i)}},{key:"_tabFocusFollowerHandler",value:function(n){t&&console.log(e,"tabFocusFollowerHandler",n);var i=document.activeElement;this.focusComponentOfTargetElm(i)}},{key:"focusComponentOfTargetElm",value:function(t){var e=t&&t.closest(this.COMPONENT_SELECTOR);return e&&P(e)?e!==this.activeComponent&&this.setCurrentComponent(e):this.unselectCurrentComponent(),e}},{key:"unselectCurrentComponent",value:function(){this.activeComponent&&(document.activeElement===this.activeComponent&&this.activeComponent.blur(),this.blurElm(this.activeComponent),this.activeComponent=null)}},{key:"setCurrentComponent",value:function(t){this.activeComponent&&this.activeComponent!==t&&this.unselectCurrentComponent(),this.activeComponent=t,this.focusElm(this.activeComponent),this.activeComponent.setAttribute("tabindex",0),this.activeComponent.contains(document.activeElement)||this.activeComponent.focus()}},{key:"focusElm",value:function(t){t.classList.add(this.ACTIVE_CLASS)}},{key:"blurElm",value:function(t){t.classList.remove(this.ACTIVE_CLASS)}},{key:"getActiveComponent",value:function(){return this.activeComponent}},{key:"_navigationHandler",value:function(n){if(t&&console.log(e,"navigationHandler",n),!(i=document.activeElement)||"INPUT"!==i.nodeName&&"TEXTAREA"!==i.nodeName){var i,r,o=Array.from(document.querySelectorAll(this.COMPONENT_SELECTOR));o=o.filter(P);var a=this.getActiveComponent();(r=I(o,a,n))&&r!==a&&(n.preventDefault(),n.stopPropagation(),this.setCurrentComponent(r))}}}]),i}(),L=new WeakMap,D=new WeakMap,q=function(){function i(){n(this,i),o(this,"KEYBIDING_ATTR","data-shortcut"),o(this,"mngr",null),w(this,L,{writable:!0,value:!1}),w(this,D,{writable:!0,value:null}),m(this,D,this._shortcutDelegatorHandler.bind(this)),this.mngr=new B,this.init()}return r(i,[{key:"init",value:function(){if(y(this,L))throw new Error("Already initialized!");this.mngr.init(),document.addEventListener("keydown",y(this,D)),m(this,L,!0)}},{key:"destroy",value:function(){this.mngr.destroy(),document.removeEventListener("keydown",y(this,D)),m(this,L,!1)}},{key:"_shortcutDelegatorHandler",value:function(n){t&&console.log(e,"_shortcutDelegatorHandler",n),C(this.mngr.getActiveComponent(),n,this.KEYBIDING_ATTR)}},{key:"getShortcuts",value:function(){var t=this,e=this.mngr.getActiveComponent();return Array.from(e.querySelectorAll("[".concat(this.KEYBIDING_ATTR,"]"))).filter((function(t){return!t.disabled})).map((function(e){return{keyBinding:e.getAttribute(t.KEYBIDING_ATTR),text:e.innerText,title:e.title,elm:e}}))}},{key:"getAllShortcuts",value:function(){var t=this;return Array.from(document.querySelectorAll("[".concat(this.KEYBIDING_ATTR,"]"))).filter((function(t){return!t.disabled})).map((function(e){return{keyBinding:e.getAttribute(t.KEYBIDING_ATTR),text:e.innerText,title:e.title,elm:e}}))}}]),i}(),H=new WeakMap,z=function(){function i(){n(this,i),w(this,H,{writable:!0,value:null}),this.init()}return r(i,[{key:"init",value:function(){if(y(this,H))throw new Error("Already initialized!");m(this,H,this._hotkeysDelegatorHandler.bind(this)),document.addEventListener("keydown",y(this,H))}},{key:"destroy",value:function(){document.removeEventListener("keydown",y(this,H)),m(this,H,null)}},{key:"_hotkeysDelegatorHandler",value:function(n){t&&console.log(e,"hotkeysDelegatorHandler",n),C(document,n,i.KEYBIDING_ATTR)}}]),i}();function K(){return Array.from(document.querySelectorAll("[".concat(z.KEYBIDING_ATTR,"]"))).filter((function(t){return!t.disabled})).map((function(t){return{keyBinding:t.getAttribute(z.KEYBIDING_ATTR),text:t.innerText,title:t.title,elm:t}}))}o(z,"KEYBIDING_ATTR","data-hotkey");var j="tooltip";var F=function(){function t(e){var i=e.target,r=e.html,o=e.margin,a=void 0===o?5:o,s=e.root,u=void 0===s?document.body:s;n(this,t),this.margin=a,this.target=i,this.el=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:document,e="\n position: fixed;\n z-index: 9999999;\n pointer-events: none;\n will-change: top, left, opacity;\n --transition: opacity 250ms ease 100ms;\n font-size: 18px;\n font-family: sans-serif;\n padding: 5px 8px;\n border-radius: 2px;\n background: rgba(218,218,218, 0.85);\n color: rgb(0 0 0);\n box-shadow: rgb(0 0 0 / 20%) 0px 3px 1px -2px, rgb(0 0 0 / 14%) 0px 2px 2px 0px, rgb(0 0 0 / 12%) 0px 1px 5px 0px;\n font-weight: bold;\n min-width: 32px;\n text-align: center;\n text-transform: capitalize;\n top: 0;\n left: 0;\n opacity: 0;\n display: none;\n ",n=t.createElement("div");return n.setAttribute("class","v-".concat(j,"-directive")),n.style.cssText=e,n.id="id_".concat(Math.random()),n.setAttribute("role","tooltip"),n.setAttribute("aria-hidden","true"),n}(this.target.ownerDocument),"string"==typeof u&&(u=document.querySelector(u)),u.appendChild(this.el),this.target.setAttribute("aria-describedby",this.el.id),this.el.setAttribute("aria-hidden","false"),this.update(r)}return r(t,[{key:"update",value:function(t){this.el.innerHTML=t,this.target&&this.target.parentNode&&(!function(t,e){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,i=arguments.length>3?arguments[3]:void 0;"none"===t.style.display&&(t.style.opacity=0,t.style.display="block",t.style.top="".concat(0,"px"),t.style.left="".concat(0,"px"));var r=t.getBoundingClientRect(),o=e.getBoundingClientRect(),a=o.top-n-r.height,s=o.left+o.width/2-r.width/2;a<0&&(a=o.bottom+n),s<0&&(s=o.left);var u=Math.max(i.documentElement.clientWidth||0,window.innerWidth||0);s+r.width>u&&(s=o.right-r.width),t.style.left="".concat(s,"px"),t.style.top="".concat(a,"px")}(this.el,this.target,this.margin,this.el.ownerDocument),this.el.style.opacity=1)}},{key:"destroy",value:function(){this.target&&this.target.parentNode&&this.target.removeAttribute("aria-describedby"),this.el.parentElement&&this.el.parentElement.removeChild(this.el)}}]),t}();
/*!
* FooBar v0.0.0 (https://github.com/username/foo-bar)
* Copyright (c) username
* @license MIT
*/var W="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};var G=function(t,e){return t(e={exports:{}},e.exports),e.exports}((function(t,e){(function(){var e;(function(e){t.exports=e})(e={linear:function(t,e,n,i){return n*t/i+e},easeInQuad:function(t,e,n,i){return n*(t/=i)*t+e},easeOutQuad:function(t,e,n,i){return-n*(t/=i)*(t-2)+e},easeInOutQuad:function(t,e,n,i){return(t/=i/2)<1?n/2*t*t+e:-n/2*(--t*(t-2)-1)+e},easeInCubic:function(t,e,n,i){return n*(t/=i)*t*t+e},easeOutCubic:function(t,e,n,i){return n*((t=t/i-1)*t*t+1)+e},easeInOutCubic:function(t,e,n,i){return(t/=i/2)<1?n/2*t*t*t+e:n/2*((t-=2)*t*t+2)+e},easeInQuart:function(t,e,n,i){return n*(t/=i)*t*t*t+e},easeOutQuart:function(t,e,n,i){return-n*((t=t/i-1)*t*t*t-1)+e},easeInOutQuart:function(t,e,n,i){return(t/=i/2)<1?n/2*t*t*t*t+e:-n/2*((t-=2)*t*t*t-2)+e},easeInQuint:function(t,e,n,i){return n*(t/=i)*t*t*t*t+e},easeOutQuint:function(t,e,n,i){return n*((t=t/i-1)*t*t*t*t+1)+e},easeInOutQuint:function(t,e,n,i){return(t/=i/2)<1?n/2*t*t*t*t*t+e:n/2*((t-=2)*t*t*t*t+2)+e},easeInSine:function(t,e,n,i){return-n*Math.cos(t/i*(Math.PI/2))+n+e},easeOutSine:function(t,e,n,i){return n*Math.sin(t/i*(Math.PI/2))+e},easeInOutSine:function(t,e,n,i){return-n/2*(Math.cos(Math.PI*t/i)-1)+e},easeInExpo:function(t,e,n,i){return 0===t?e:n*Math.pow(2,10*(t/i-1))+e},easeOutExpo:function(t,e,n,i){return t===i?e+n:n*(1-Math.pow(2,-10*t/i))+e},easeInOutExpo:function(t,e,n,i){return(t/=i/2)<1?n/2*Math.pow(2,10*(t-1))+e:n/2*(2-Math.pow(2,-10*--t))+e},easeInCirc:function(t,e,n,i){return-n*(Math.sqrt(1-(t/=i)*t)-1)+e},easeOutCirc:function(t,e,n,i){return n*Math.sqrt(1-(t=t/i-1)*t)+e},easeInOutCirc:function(t,e,n,i){return(t/=i/2)<1?-n/2*(Math.sqrt(1-t*t)-1)+e:n/2*(Math.sqrt(1-(t-=2)*t)+1)+e},easeInElastic:function(t,e,n,i){var r,o,a;return a=1.70158,0===t||(t/=i),(o=0)||(o=.3*i),(r=n)<Math.abs(n)?(r=n,a=o/4):a=o/(2*Math.PI)*Math.asin(n/r),-r*Math.pow(2,10*(t-=1))*Math.sin((t*i-a)*(2*Math.PI)/o)+e},easeOutElastic:function(t,e,n,i){var r,o,a;return a=1.70158,0===t||(t/=i),(o=0)||(o=.3*i),(r=n)<Math.abs(n)?(r=n,a=o/4):a=o/(2*Math.PI)*Math.asin(n/r),r*Math.pow(2,-10*t)*Math.sin((t*i-a)*(2*Math.PI)/o)+n+e},easeInOutElastic:function(t,e,n,i){var r,o,a;return a=1.70158,0===t||(t/=i/2),(o=0)||(o=i*(.3*1.5)),(r=n)<Math.abs(n)?(r=n,a=o/4):a=o/(2*Math.PI)*Math.asin(n/r),t<1?r*Math.pow(2,10*(t-=1))*Math.sin((t*i-a)*(2*Math.PI)/o)*-.5+e:r*Math.pow(2,-10*(t-=1))*Math.sin((t*i-a)*(2*Math.PI)/o)*.5+n+e},easeInBack:function(t,e,n,i,r){return void 0===r&&(r=1.70158),n*(t/=i)*t*((r+1)*t-r)+e},easeOutBack:function(t,e,n,i,r){return void 0===r&&(r=1.70158),n*((t=t/i-1)*t*((r+1)*t+r)+1)+e},easeInOutBack:function(t,e,n,i,r){return void 0===r&&(r=1.70158),(t/=i/2)<1?n/2*(t*t*((1+(r*=1.525))*t-r))+e:n/2*((t-=2)*t*((1+(r*=1.525))*t+r)+2)+e},easeInBounce:function(t,n,i,r){return i-e.easeOutBounce(r-t,0,i,r)+n},easeOutBounce:function(t,e,n,i){return(t/=i)<1/2.75?n*(7.5625*t*t)+e:t<2/2.75?n*(7.5625*(t-=1.5/2.75)*t+.75)+e:t<2.5/2.75?n*(7.5625*(t-=2.25/2.75)*t+.9375)+e:n*(7.5625*(t-=2.625/2.75)*t+.984375)+e},easeInOutBounce:function(t,n,i,r){return t<r/2?.5*e.easeInBounce(2*t,0,i,r)+n:.5*e.easeOutBounce(2*t-r,0,i,r)+.5*i+n}})}).call(W)}));function Y(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,e=arguments.length>1?arguments[1]:void 0,n=arguments.length>2?arguments[2]:void 0,i=arguments.length>3?arguments[3]:void 0,r=arguments.length;if(Array.isArray(t)){r=t.length;var o=t,a=d(o,4);t=a[0],e=a[1],n=a[2],i=a[3]}return 1===r?[t,t,t,t]:2===r?[t,e,t,e]:3===r?[t,e,n,e]:4===r?[t,e,n,i]:[0,0,0,0]}function Q(t,e,n,i,r){var o=arguments.length>5&&void 0!==arguments[5]?arguments[5]:5;function a(t,e,n){var i=(e<n?e:n)/2;return t[0]=t[0]>i?i:t[0],t[1]=t[1]>i?i:t[1],t[2]=t[2]>i?i:t[2],t[3]=t[3]>i?i:t[3],t}o=a(o=Y(o),i,r),t.beginPath(),t.moveTo(e+o[0],n),t.lineTo(e+i-o[1],n),t.quadraticCurveTo(e+i,n,e+i,n+o[1]),t.lineTo(e+i,n+r-o[2]),t.quadraticCurveTo(e+i,n+r,e+i-o[2],n+r),t.lineTo(e+o[3],n+r),t.quadraticCurveTo(e,n+r,e,n+r-o[3]),t.lineTo(e,n+o[0]),t.quadraticCurveTo(e,n,e+o[0],n),t.closePath()}var V=function(){function t(e){n(this,t),o(this,"type",""),o(this,"_stage",null),this._stage=e}return r(t,[{key:"draw",value:function(t){throw"Not implemented"}},{key:"remove",value:function(){this._stage&&(this._stage.removeSpot(this),this._stage=null)}}]),t}(),U=function(t){a(i,t);var e=h(i);function i(t,r,a,s){var u;return n(this,i),o(l(u=e.call(this,t)),"type","circle"),o(l(u),"x",0),o(l(u),"y",0),o(l(u),"radius",0),u.x=r,u.y=a,u.radius=s,u}return r(i,[{key:"draw",value:function(t){t.beginPath(),t.arc(this.x,this.y,this.radius,0,2*Math.PI),t.fill()}}]),i}(V),X=function(t){a(i,t);var e=h(i);function i(t,r,a,s,u){var c;return n(this,i),o(l(c=e.call(this,t)),"type","retangle"),o(l(c),"x",0),o(l(c),"y",0),o(l(c),"width",0),o(l(c),"height",0),c.x=r,c.y=a,c.width=s,c.height=u,c}return r(i,[{key:"draw",value:function(t){t.beginPath(),t.fillRect(this.x,this.y,this.width,this.height)}}]),i}(V),$=function(t){a(i,t);var e=h(i);function i(t,r,a,s,u,c){var h;return n(this,i),o(l(h=e.call(this,t)),"type","round-retangle"),o(l(h),"x",0),o(l(h),"y",0),o(l(h),"width",0),o(l(h),"height",0),o(l(h),"radius",5),h.x=r,h.y=a,h.width=s,h.height=u,h.radius=c,h}return r(i,[{key:"draw",value:function(t){t.beginPath(),Q(t,this.x,this.y,this.width,this.height,this.radius),t.fill()}}]),i}(V),J=function(t){a(i,t);var e=h(i);function i(t,r){var a;return n(this,i),o(l(a=e.call(this,t)),"type","polygon"),o(l(a),"points",[]),a.points=r,a}return r(i,[{key:"draw",value:function(t){t.beginPath(),t.moveTo(this.points[0],this.points[1]);for(var e=2;e<this.points.length;e+=2)t.lineTo(this.points[e],this.points[e+1]);t.closePath(),t.fill()}}]),i}(V),Z=function(t){a(i,t);var e=h(i);function i(t,r,a){var s;return n(this,i),o(l(s=e.call(this,t)),"type","element"),o(l(s),"elm",HTMLElement),o(l(s),"radius",0),o(l(s),"padding",0),s.elm=r,s.radius=a.radius,s.padding=a.padding,s}return r(i,[{key:"draw",value:function(t){var e=this.elm.getBoundingClientRect(),n=Y(this.padding),i=e.left-n[3],r=e.top-n[0],o=e.height+n[0]+n[2],a=e.width+n[3]+n[1];t.beginPath(),this.radius?(Q(t,i,r,a,o,this.radius),t.fill()):t.fillRect(i,r,a,o)}}]),i}(V),tt=new WeakMap,et=new WeakMap,nt=new WeakMap,it=function(){function t(e){var i=this;n(this,t),o(this,"options",{}),o(this,"canvas",void 0),o(this,"spots",[]),o(this,"looping",!1),w(this,tt,{writable:!0,value:void 0}),w(this,et,{writable:!0,value:void 0}),w(this,nt,{writable:!0,value:void 0}),this.options=e||{},this.canvas=void 0,this.spots=[],m(this,tt,(function(){i.isVisible&&i.resize()})),m(this,et,(function(){i.isVisible&&i.redraw()})),m(this,nt,void 0),this.init()}return r(t,[{key:"init",value:function(t){if(this.canvas)throw new Error("Already initialized!");t&&(this.options=t),this.canvas=document.createElement("canvas"),this.canvas.style.position="fixed",this.canvas.style.top=this.options.x||0,this.canvas.style.left=this.options.y||0,this.canvas.style.zIndex=this.options.zIndex||function(){var t,e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"*",n=null,i=p(document.getElementsByTagName(e));try{for(i.s();!(t=i.n()).done;){var r=t.value,o=document.defaultView.getComputedStyle(r,null).getPropertyValue("z-index");"auto"!==o&&((o=parseInt(o,10))>n||null===n)&&(n=o)}}catch(t){i.e(t)}finally{i.f()}return n}()+1,this.canvas.style.pointerEvents="none",(this.options.parent||document.body).appendChild(this.canvas),this.spots=[],window.addEventListener("resize",y(this,tt),{passive:!0}),window.addEventListener("scroll",y(this,et),{passive:!0}),this.resize()}},{key:"resize",value:function(){var t=arguments.length>0&&void 0!==arguments[0]&&arguments[0],e=this.options.width||window.innerWidth,n=this.options.height||window.innerHeight;this.canvas.width=e,this.canvas.height=n,!0===t?this.redrawNow():this.redraw()}},{key:"startLoop",value:function(){var t=this;if(!this.looping)return this.looping=!0,function e(){t.looping&&t.redraw(!1,e)}(),!0}},{key:"stopLoop",value:function(){this.looping=!1,y(this,nt)&&(window.cancelAnimationFrame(y(this,nt)),m(this,nt,void 0))}},{key:"redraw",value:function(t,e){var n=this;if(console.log("redraw"),null!=t?t:this.options.forceSyncRedraw)return this.redrawNow();y(this,nt)||m(this,nt,requestAnimationFrame((function(){m(n,nt,void 0),n.redrawNow(),e&&e(n)})))}},{key:"redrawNow",value:function(){console.log("redraw now!");var t=this.canvas.getContext("2d");t.save(),t.clearRect(0,0,this.canvas.width,this.canvas.height),t.fillStyle=this.options.color||"#000000",t.globalAlpha=this.options.alpha||.8,t.fillRect(0,0,this.canvas.width,this.canvas.height),t.restore(),t.save(),t.globalCompositeOperation="destination-out";var e,n=p(this.spots);try{for(n.s();!(e=n.n()).done;){e.value.draw(t,this.options)}}catch(t){n.e(t)}finally{n.f()}t.restore()}},{key:"clear",value:function(){var t=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];this.spots=[],1==t&&this.resize()}},{key:"addCircle",value:function(t,e,n){var i=!(arguments.length>3&&void 0!==arguments[3])||arguments[3],r=new U(this,t,e,n);return this.spots.push(r),!0===i&&this.redraw(),r}},{key:"addRectangle",value:function(t,e,n,i){var r=!(arguments.length>4&&void 0!==arguments[4])||arguments[4],o=new X(this,t,e,n,i);return this.spots.push(o),!0===r&&this.redraw(),o}},{key:"addRoundRectangle",value:function(t,e,n,i,r){var o=!(arguments.length>5&&void 0!==arguments[5])||arguments[5],a=new $(this,t,e,n,i,r);return this.spots.push(a),!0===o&&this.redraw(),a}},{key:"addPolygon",value:function(t){var e=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],n=new J(this,t);return this.spots.push(n),!0===e&&this.redraw(),n}},{key:"addElement",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=!(arguments.length>2&&void 0!==arguments[2])||arguments[2],i=new Z(this,t,e);return this.spots.push(i),!0===n&&this.redraw(),i}},{key:"addElements",value:function(t,e){var n,i=!(arguments.length>2&&void 0!==arguments[2])||arguments[2],r=[],o=p(t);try{for(o.s();!(n=o.n()).done;){var a=n.value,s=this.addElement(a,e,!1);r.push(s)}}catch(t){o.e(t)}finally{o.f()}return!0===i&&this.redraw(),r}},{key:"removeSpot",value:function(t){var e=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],n=this.spots.indexOf(t);return n>-1&&(this.spots.splice(n,1),!0===e&&this.redraw(),!0)}},{key:"_fade",value:function(t){var e=this;return new Promise((function(n,i){e.request=null;var r=performance.now(),o=r-e.last;e.last=r,t.time+=o;var a=t.end-t.start;t.time>t.duration?(e.canvas.style.opacity=t.end,t.onEnd&&t.onEnd()):(e.canvas.style.opacity=t.ease(t.time,t.start,a,t.duration),e.request=requestAnimationFrame((function(){return e._fade(t)})))}))}},{key:"fadeIn",value:function(t){this.request&&cancelAnimationFrame(this.request);var e=void 0===(t=t||{}).start?0:t.start,n=void 0===t.end?1:t.end,i=t.ease?"string"==typeof t.ease?G[t.ease]:t.ease:G.easeInOutSine,r=t.onEnd;this.canvas.style.opacity=e;var o=t.duration||1e3;return this.last=performance.now(),this.canvas.style.display="block",this.canvas.style.opacity=0,this._fade({time:0,start:e,end:n,duration:o,ease:i,onEnd:r}),this}},{key:"fadeOut",value:function(t){return(t=t||{}).start=void 0===t.start?1:t.start,t.end=void 0===t.end?0:t.end,this.fadeIn(t),this}},{key:"show",value:function(){return this.canvas.style.display="block",this.canvas.style.opacity=1,this}},{key:"hide",value:function(){return this.canvas.style.display="none",this.canvas.style.opacity=0,this}},{key:"isVisible",get:function(){return this.canvas&&"none"!==this.canvas.style.display}},{key:"destroy",value:function(){this.canvas.parentElementNode&&this.canvas.parentElementNode.removeChild(this.canvas),this.canvas=void 0,this.spots=[],y(this,nt)&&(cancelAnimationFrame(y(this,nt)),m(this,nt,void 0)),window.removeEventListener("scroll",y(this,et)),window.removeEventListener("resize",y(this,tt))}}]),t}();window.Spotlight=it;var rt=new Map,ot=new it({zIndex:100});function at(){!function(){var t,e=p(rt.values());try{for(e.s();!(t=e.n()).done;){t.value.destroy()}}catch(t){e.e(t)}finally{e.f()}rt.clear()}();var t,e=[],n=K(),i=p(n);try{for(i.s();!(t=i.n()).done;){var r=t.value,o=new F({target:r.elm,html:r.keyBinding,margin:-5});rt.set(r.elm,o),e.push(o)}}catch(t){i.e(t)}finally{i.f()}return ot.addElements(n.map((function(t){return t.elm})),{padding:-1,radius:9999}),ot.show(),e}return ot.hide(),window.stage=ot,window.announce=at,{Shortcuts:q,ComponentFocusManager:B,Hotkeys:z,announceHotkeys:K,announce:at,setDebug:function(e){return t=e}}}));
//# sourceMappingURL=keyboardly.js.map