/*! * * simple-keyboard v2.13.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,e){"object"===typeof exports&&"object"===typeof module?module.exports=e():"function"===typeof define&&define.amd?define("SimpleKeyboard",[],e):"object"===typeof exports?exports.SimpleKeyboard=e():t.SimpleKeyboard=e()}(window,function(){return function(t){var e={};function n(i){if(e[i])return e[i].exports;var o=e[i]={i:i,l:!1,exports:{}};return t[i].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=t,n.c=e,n.d=function(t,e,i){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:i})},n.r=function(t){"undefined"!==typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"===typeof t&&t&&t.__esModule)return t;var i=Object.create(null);if(n.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)n.d(i,o,function(e){return t[e]}.bind(null,o));return i},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,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=0)}([function(t,e,n){t.exports=n(2)},function(t,e,n){},function(t,e,n){"use strict";n.r(e);n(1);function i(t,e){for(var n=0;n ? {shift}",".com @ {space}"]}}}],(n=null)&&s(e.prototype,n),i&&s(e,i),t}();function u(t){return(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})(t)}function r(t,e){for(var n=0;n0?s=this.removeAt(s,i,o):"{space}"===t?s=this.addStringAt(s," ",i,o):"{tab}"!==t||"boolean"===typeof n.tabCharOnTab&&!1===n.tabCharOnTab?"{enter}"!==t&&"{numpadenter}"!==t||!n.newLineOnEnter?t.includes("numpad")&&Number.isInteger(Number(t[t.length-2]))?s=this.addStringAt(s,t[t.length-2],i,o):"{numpaddivide}"===t?s=this.addStringAt(s,"/",i,o):"{numpadmultiply}"===t?s=this.addStringAt(s,"*",i,o):"{numpadsubtract}"===t?s=this.addStringAt(s,"-",i,o):"{numpadadd}"===t?s=this.addStringAt(s,"+",i,o):"{numpaddecimal}"===t?s=this.addStringAt(s,".",i,o):"{"===t||"}"===t?s=this.addStringAt(s,t,i,o):t.includes("{")||t.includes("}")||(s=this.addStringAt(s,t,i,o)):s=this.addStringAt(s,"\n",i,o):s=this.addStringAt(s,"\t",i,o),s}},{key:"updateCaretPos",value:function(t,e){var n=this.updateCaretPosAction(this.simpleKeyboardInstance,t,e);this.simpleKeyboardInstance.options.syncInstanceInputs&&this.simpleKeyboardInstance.dispatch(function(t){t.caretPosition=n})}},{key:"updateCaretPosAction",value:function(t,e,n){return n?t.caretPosition>0&&(t.caretPosition=t.caretPosition-e):t.caretPosition=t.caretPosition+e,this.simpleKeyboardInstance.options.debug&&console.log("Caret at:",t.caretPosition,"(".concat(t.keyboardDOMClass,")")),t.caretPosition}},{key:"addStringAt",value:function(t,e,n,i){var o;return n||0===n?(o=[t.slice(0,n),e,t.slice(n)].join(""),this.isMaxLengthReached()||i&&this.updateCaretPos(e.length)):o=t+e,o}},{key:"removeAt",value:function(t,e,n){if(0===this.simpleKeyboardInstance.caretPosition)return t;var i,o=/([\uD800-\uDBFF][\uDC00-\uDFFF])/g;return e&&e>=0?t.substring(e-2,e).match(o)?(i=t.substr(0,e-2)+t.substr(e),n&&this.updateCaretPos(2,!0)):(i=t.substr(0,e-1)+t.substr(e),n&&this.updateCaretPos(1,!0)):t.slice(-2).match(o)?(i=t.slice(0,-2),n&&this.updateCaretPos(2,!0)):(i=t.slice(0,-1),n&&this.updateCaretPos(1,!0)),i}},{key:"handleMaxLength",value:function(t,e,n){var i=e.maxLength,o=t[e.inputName],s=o.length===i;if(n.length<=o.length)return!1;if(Number.isInteger(i))return e.debug&&console.log("maxLength (num) reached:",s),s?(this.maxLengthReached=!0,!0):(this.maxLengthReached=!1,!1);if("object"===u(i)){var a=o.length===i[e.inputName];return e.debug&&console.log("maxLength (obj) reached:",a),a?(this.maxLengthReached=!0,!0):(this.maxLengthReached=!1,!1)}}},{key:"isMaxLengthReached",value:function(){return Boolean(this.maxLengthReached)}},{key:"camelCase",value:function(t){return t.toLowerCase().trim().split(/[.\-_\s]/g).reduce(function(t,e){return e.length?t+e[0].toUpperCase()+e.slice(1):t})}},{key:"countInArray",value:function(t,e){return t.reduce(function(t,n){return t+(n===e)},0)}}])&&r(e.prototype,n),i&&r(e,i),t}();function l(t){return(l="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})(t)}function h(t,e){for(var n=0;n1?n:n[0]),e}},{key:"handleCaret",value:function(){this.caretPosition=null;var t=window.SimpleKeyboardInstances;(t&&Object.keys(t)[0]===this.utilities.camelCase(this.keyboardDOMClass)||!t)&&(this.options.debug&&console.log("Caret handling started (".concat(this.keyboardDOMClass,")")),document.addEventListener("keyup",this.caretEventHandler),document.addEventListener("mouseup",this.caretEventHandler),document.addEventListener("touchend",this.caretEventHandler))}},{key:"caretEventHandler",value:function(t){var e;t.target.tagName&&(e=t.target.tagName.toLowerCase()),this.dispatch(function(n){n.isMouseHold&&(n.isMouseHold=!1),"textarea"!==e&&"input"!==e||n.options.disableCaretPositioning||(n.caretPosition=t.target.selectionStart,n.options.debug&&console.log("Caret at: ",t.target.selectionStart,t.target.tagName.toLowerCase(),"(".concat(n.keyboardDOMClass,")")))})}},{key:"onInit",value:function(){this.options.debug&&console.log("".concat(this.keyboardDOMClass," Initialized")),this.handleCaret(),"function"===typeof this.options.onInit&&this.options.onInit()}},{key:"onRender",value:function(){"function"===typeof this.options.onRender&&this.options.onRender()}},{key:"onModulesLoaded",value:function(){"function"===typeof this.options.onModulesLoaded&&this.options.onModulesLoaded()}},{key:"loadModules",value:function(){var t=this;Array.isArray(this.options.modules)&&(this.options.modules.forEach(function(e){var n=new e;if(n.constructor.name&&"Function"!==n.constructor.name){var i="module-".concat(t.utilities.camelCase(n.constructor.name));t.keyboardPluginClasses=t.keyboardPluginClasses+" ".concat(i)}n.init(t)}),this.keyboardPluginClasses=this.keyboardPluginClasses+" modules-loaded",this.render(),this.onModulesLoaded())}},{key:"render",value:function(){var t=this;this.clear();var e="hg-layout-".concat(this.options.layoutName),n=this.options.layout||a.getDefaultLayout(),i=this.options.useTouchEvents||!1,o={};Array.isArray(this.options.buttonTheme)&&this.options.buttonTheme.forEach(function(e){var n;e.buttons&&e.class?("string"===typeof e.buttons&&(n=e.buttons.split(" ")),n&&n.forEach(function(n){var i=o[n];i?t.utilities.countInArray(i.split(" "),e.class)||(o[n]="".concat(i," ").concat(e.class)):o[n]=e.class})):console.warn('buttonTheme row is missing the "buttons" or the "class". Please check the documentation.')}),this.keyboardDOM.className+=" ".concat(this.options.theme," ").concat(e," ").concat(this.keyboardPluginClasses),n[this.options.layoutName].forEach(function(e,n){var s=e.split(" "),a=document.createElement("div");a.className+="hg-row",s.forEach(function(e,s){var u=t.utilities.getButtonClass(e),r=o[e],c=t.utilities.getButtonDisplayName(e,t.options.display,t.options.mergeDisplay),l=t.options.useButtonTag?"button":"div",h=document.createElement(l);h.className+="hg-button ".concat(u).concat(r?" "+r:""),i?(h.ontouchstart=function(n){t.handleButtonClicked(e),t.handleButtonMouseDown(e,n)},h.ontouchend=function(e){return t.handleButtonMouseUp()},h.ontouchcancel=function(e){return t.handleButtonMouseUp()}):(h.onclick=function(){t.isMouseHold=!1,t.handleButtonClicked(e)},h.onmousedown=function(n){t.options.preventMouseDownDefault&&n.preventDefault(),t.handleButtonMouseDown(e,n)}),h.setAttribute("data-skBtn",e);var d="".concat(t.options.layoutName,"-r").concat(n,"b").concat(s);h.setAttribute("data-skBtnUID",d),h.setAttribute("data-displayLabel",c);var p=document.createElement("span");p.innerHTML=c,h.appendChild(p),t.buttonElements[e]||(t.buttonElements[e]=[]),t.buttonElements[e].push(h),a.appendChild(h)}),t.keyboardDOM.appendChild(a)}),this.onRender(),this.initialized||(this.initialized=!0,i||(document.onmouseup=function(){return t.handleButtonMouseUp()}),this.onInit())}}])&&h(e.prototype,n),i&&h(e,i),t}();e.default=p}])}); //# sourceMappingURL=index.js.map