simple-keyboard/build/index.js
Francisco Hodge 26e7970b41 Build update
2018-09-24 21:26:41 -04:00

13 lines
9.8 KiB
JavaScript

/*!
*
* simple-keyboard v2.4.2
* https://github.com/hodgef/simple-keyboard
*
* Copyright (c) Francisco Hodge (https://github.com/hodgef)
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
!function(t,n){"object"===typeof exports&&"object"===typeof module?module.exports=n():"function"===typeof define&&define.amd?define([],n):"object"===typeof exports?exports.SimpleKeyboard=n():t.SimpleKeyboard=n()}(this,function(){return function(t){function n(o){if(e[o])return e[o].exports;var i=e[o]={i:o,l:!1,exports:{}};return t[o].call(i.exports,i,i.exports,n),i.l=!0,i.exports}var e={};return n.m=t,n.c=e,n.d=function(t,e,o){n.o(t,e)||Object.defineProperty(t,e,{configurable:!1,enumerable:!0,get:o})},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,n){return Object.prototype.hasOwnProperty.call(t,n)},n.p="",n(n.s=0)}([function(t,n,e){t.exports=e(1)},function(t,n,e){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var o=e(2);n.default=o.a},function(t,n,e){"use strict";function o(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")}var i=e(3),a=(e.n(i),e(4)),s=e(5),r=e(6),u="function"===typeof Symbol&&"symbol"===typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"===typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},c=function t(){o(this,t),p.call(this);var n="string"===typeof(arguments.length<=0?void 0:arguments[0])?arguments.length<=0?void 0:arguments[0]:".simple-keyboard",e="object"===u(arguments.length<=0?void 0:arguments[0])?arguments.length<=0?void 0:arguments[0]:arguments.length<=1?void 0:arguments[1];e||(e={}),this.keyboardDOM=document.querySelector(n),this.options=e,this.options.layoutName=this.options.layoutName||"default",this.options.theme=this.options.theme||"hg-theme-default",this.options.inputName=this.options.inputName||"default",this.input={},this.input[this.options.inputName]="",this.keyboardDOMClass=n.split(".").join(""),this.timers={},this.keyboardDOM?this.render():console.error('"'+n+'" was not found in the DOM.'),window.SimpleKeyboardInstances||(window.SimpleKeyboardInstances={}),window.SimpleKeyboardInstances[r.a.camelCase(this.keyboardDOMClass)]=this,this.physicalKeyboardInterface=new a.a(this)},p=function(){var t=this;this.handleButtonClicked=function(n){var e=t.options.debug;if("{//}"===n)return!1;"function"===typeof t.options.onKeyPress&&t.options.onKeyPress(n);var o={newLineOnEnter:!0===t.options.newLineOnEnter};t.input[t.options.inputName]||(t.input[t.options.inputName]="");var i=r.a.getUpdatedInput(n,t.input[t.options.inputName],o);t.input[t.options.inputName]!==i&&(t.input[t.options.inputName]=i,e&&console.log("Input changed:",t.input),t.options.syncInstanceInputs&&t.syncInstanceInputs(t.input),"function"===typeof t.options.onChange&&t.options.onChange(t.input[t.options.inputName])),e&&console.log("Key pressed:",n)},this.syncInstanceInputs=function(){t.dispatch(function(n){n.replaceInput(t.input)})},this.clearInput=function(n){n=n||t.options.inputName,t.input[t.options.inputName]="",t.options.syncInstanceInputs&&t.syncInstanceInputs(t.input)},this.getInput=function(n){return n=n||t.options.inputName,t.options.syncInstanceInputs&&t.syncInstanceInputs(t.input),t.input[t.options.inputName]},this.setInput=function(n,e){e=e||t.options.inputName,t.input[e]=n,t.options.syncInstanceInputs&&t.syncInstanceInputs(t.input)},this.replaceInput=function(n){t.input=n},this.setOptions=function(n){n=n||{},t.options=Object.assign(t.options,n),t.render()},this.clear=function(){t.keyboardDOM.innerHTML="",t.keyboardDOM.className=t.keyboardDOMClass},this.dispatch=function(t){return window.SimpleKeyboardInstances?Object.keys(window.SimpleKeyboardInstances).forEach(function(n){t(window.SimpleKeyboardInstances[n],n)}):(console.error("SimpleKeyboardInstances is not defined. Dispatch cannot be called."),!1)},this.render=function(){t.clear();var n=t.options.layout?"hg-layout-custom":"hg-layout-"+t.options.layoutName,e=t.options.layout||s.a.getLayout(t.options.layoutName),o={};Array.isArray(t.options.buttonTheme)&&t.options.buttonTheme.forEach(function(t){if(t.buttons&&t.class){var n=t.buttons.split(" ");Array.isArray(n)&&n.forEach(function(n){var e=o[n];o[n]=e?e+" "+t.class:t.class})}else console.warn('buttonTheme row is missing the "buttons" or the "class". Please check the documentation.')}),t.keyboardDOM.className+=" "+t.options.theme+" "+n,e[t.options.layoutName].forEach(function(n){var e=n.split(" "),i=document.createElement("div");i.className+="hg-row",e.forEach(function(n){var e=r.a.getButtonClass(n),a=o[n],s=r.a.getButtonDisplayName(n,t.options.display,t.options.mergeDisplay),u=document.createElement("div");u.className+="hg-button "+e+(a?" "+a:""),u.onclick=function(){return t.handleButtonClicked(n)};var c=document.createElement("span");c.innerHTML=s,u.appendChild(c),i.appendChild(u),"function"===typeof t.options.onInit&&t.options.onInit()}),t.keyboardDOM.appendChild(i)})}};n.a=c},function(t,n){},function(t,n,e){"use strict";function o(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")}var i=function t(n){var e=this;if(o(this,t),this.initKeyboardListener=function(){document.addEventListener("keydown",function(t){if(e.simpleKeyboardInstance.options.physicalKeyboardHighlight){var n=e.getSimpleKeyboardLayoutKey(t);e.simpleKeyboardInstance.dispatch(function(t){t.setOptions({buttonTheme:[{class:"hg-selectedButton",buttons:n+" {"+n+"}"}]})})}}),document.addEventListener("keyup",function(t){e.simpleKeyboardInstance.options.physicalKeyboardHighlight&&e.simpleKeyboardInstance.dispatch(function(t){t.setOptions({buttonTheme:[]})})})},this.getSimpleKeyboardLayoutKey=function(t){e.simpleKeyboardInstance.options.debug&&console.log(t);var n=void 0;return n=t.code.includes("Numpad")||t.code.includes("Shift")||t.code.includes("Space")||t.code.includes("Backspace")?t.code:t.key,(n!==n.toUpperCase()||"F"===t.code[0]&&Number.isInteger(Number(t.code[1]))&&t.code.length<=3)&&(n=n.toLowerCase()),n},this.simpleKeyboardInstance=n,window.SimpleKeyboardPhysicalKeyboardInit)return!1;window.SimpleKeyboardPhysicalKeyboardInit=!0,this.initKeyboardListener()};n.a=i},function(t,n,e){"use strict";function o(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")}var i=function t(){o(this,t)};i.getLayout=function(t){return"qwerty"===t?{default:["` 1 2 3 4 5 6 7 8 9 0 - = {bksp}","{tab} q w e r t y u i o p [ ] \\","{lock} a s d f g h j k l ; ' {enter}","{shift} z x c v b n m , . / {shift}",".com @ {space}"],shift:["~ ! @ # $ % ^ & * ( ) _ + {bksp}","{tab} Q W E R T Y U I O P { } |",'{lock} A S D F G H J K L : " {enter}',"{shift} Z X C V B N M < > ? {shift}",".com @ {space}"]}:"numeric"===t?{default:["1 2 3","4 5 6","7 8 9","{//} 0 {bksp}"]}:i.getLayout("qwerty")},n.a=i},function(t,n,e){"use strict";function o(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")}var i=function(){function t(t,n){for(var e=0;e<n.length;e++){var o=n[e];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}return function(n,e,o){return e&&t(n.prototype,e),o&&t(n,o),n}}(),a=function(){function t(){o(this,t)}return i(t,null,[{key:"normalizeString",value:function(t){var n=void 0;return n="@"===t?"at":","===t?"comma":"."===t?"dot":"\\"===t?"backslash":"/"===t?"fordardslash":"*"===t?"asterisk":"&"===t?"ampersand":"$"===t?"dollarsign":"="===t?"equals":"+"===t?"plus":"-"===t?"minus":"'"===t?"apostrophe":";"===t?"colon":"["===t?"openbracket":"]"===t?"closebracket":"//"===t?"emptybutton":".com"===t?"com":"",n?" hg-button-"+n:""}},{key:"getDefaultDiplay",value:function(){return{"{bksp}":"backspace","{backspace}":"backspace","{enter}":"< enter","{shift}":"shift","{shiftleft}":"shift","{shiftright}":"shift","{alt}":"alt","{s}":"shift","{tab}":"tab","{lock}":"caps","{capslock}":"caps","{accept}":"Submit","{space}":" ","{//}":" ","{esc}":"esc","{escape}":"esc","{f1}":"f1","{f2}":"f2","{f3}":"f3","{f4}":"f4","{f5}":"f5","{f6}":"f6","{f7}":"f7","{f8}":"f8","{f9}":"f9","{f10}":"f10","{f11}":"f11","{f12}":"f12","{numpaddivide}":"/","{numlock}":"lock","{arrowup}":"\u2191","{arrowleft}":"\u2190","{arrowdown}":"\u2193","{arrowright}":"\u2192","{prtscr}":"print","{scrolllock}":"scroll","{pause}":"pause","{insert}":"ins","{home}":"home","{pageup}":"up","{delete}":"del","{end}":"end","{pagedown}":"down","{numpadmultiply}":"*","{numpadsubtract}":"-","{numpadadd}":"+","{numpadenter}":"enter","{period}":".","{numpaddecimal}":".","{numpad0}":"0","{numpad1}":"1","{numpad2}":"2","{numpad3}":"3","{numpad4}":"4","{numpad5}":"5","{numpad6}":"6","{numpad7}":"7","{numpad8}":"8","{numpad9}":"9"}}}]),t}();a.getButtonClass=function(t){var n=t.includes("{")&&"{//}"!==t?"functionBtn":"standardBtn",e=t.replace("{","").replace("}","");return"hg-"+n+("standardBtn"===n?a.normalizeString(e):" hg-button-"+e)},a.getButtonDisplayName=function(t,n,e){return n=e?Object.assign({},a.getDefaultDiplay(),n):n||a.getDefaultDiplay(),n[t]||t},a.getUpdatedInput=function(t,n,e){var o=n,i=e.newLineOnEnter;if(("{bksp}"===t||"{backspace}"===t)&&o.length>0){o=o.slice(-2).match(/([\uD800-\uDBFF][\uDC00-\uDFFF])/g)?o.slice(0,-2):o.slice(0,-1)}else"{space}"===t?o+=" ":"{tab}"===t?o+="\t":"{enter}"!==t&&"{numpadenter}"!==t||!i?t.includes("numpad")&&Number.isInteger(Number(t[t.length-2]))?o+=t[t.length-2]:"{numpaddivide}"===t?o+="/":"{numpadmultiply}"===t?o+="*":"{numpadsubtract}"===t?o+="-":"{numpadadd}"===t?o+="+":"{numpadadd}"===t?o+="+":"{numpaddecimal}"===t?o+=".":t.includes("{")||t.includes("}")||(o+=t):o+="\n";return o},a.camelCase=function(t){return t.toLowerCase().trim().split(/[.\-_\s]/g).reduce(function(t,n){return t+n[0].toUpperCase()+n.slice(1)})},n.a=a}])});
//# sourceMappingURL=index.js.map