UNPKG

phaser3-rex-plugins

Version:
2 lines (1 loc) 9.17 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).rexinputtextplugin=t();}(undefined,(function(){function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e(t)}function t(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function n(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,(i=o.key,r=void 0,"symbol"==typeof(r=function(e,t){if("object"!=typeof e||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var o=n.call(e,t||"default");if("object"!=typeof o)return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return ("string"===t?String:Number)(e)}(i,"string"))?r:String(r)),o);}var i,r;}function o(e,t,o){return t&&n(e.prototype,t),o&&n(e,o),Object.defineProperty(e,"prototype",{writable:!1}),e}function i(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&s(e,t);}function r(e){return r=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},r(e)}function s(e,t){return s=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},s(e,t)}function u(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function c(e){var t=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(e){return !1}}();return function(){var n,o=r(e);if(t){var i=r(this).constructor;n=Reflect.construct(o,arguments,i);}else n=o.apply(this,arguments);return function(e,t){if(t&&("object"==typeof t||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return u(e)}(this,n)}}var l={id:["id",void 0],text:["value",void 0],maxLength:["maxLength",void 0],minLength:["minLength",void 0],placeholder:["placeholder",void 0],tooltip:["title",void 0],readOnly:["readOnly",!1],spellCheck:["spellcheck",!1],autoComplete:["autocomplete","off"]},a={align:["textAlign",void 0],paddingLeft:["padding-left",void 0],paddingRight:["padding-right",void 0],paddingTop:["padding-top",void 0],paddingBottom:["padding-bottom",void 0],fontFamily:["fontFamily",void 0],fontSize:["font-size",void 0],color:["color","#ffffff"],backgroundColor:["backgroundColor","transparent"],border:["border",0],borderColor:["borderColor","transparent"],outline:["outline","none"],direction:["direction",void 0]},d={input:"textchange",click:"click",dblclick:"dblclick",mousedown:"pointerdown",mousemove:"pointermove",mouseup:"pointerup",touchstart:"pointerdown",touchmove:"pointermove",touchend:"pointerup",keydown:"keydown",keyup:"keyup",keypress:"keypress",compositionstart:"compositionStart",compositionend:"compositionEnd",compositionupdate:"compositionUpdate",focus:"focus",blur:"blur",select:"select"},f=Phaser.Utils.Objects.GetValue,h=function(e,t,n){var o,i;for(var r in void 0===n&&(n={}),e)o=e[r],void 0!==(i=f(t,r,o[1]))&&(n[o[0]]=i);return n},p=Phaser.Utils.Objects.GetValue,y=function(e){e.stopPropagation();},v=Phaser.GameObjects.DOMElement,g=Phaser.Utils.Objects.IsPlainObject,b=Phaser.Utils.Objects.GetValue,m=function(e){i(r,e);var n=c(r);function r(e,o,i,s,c,f){var v,m;t(this,r),g(o)?(o=b(f=o,"x",0),i=b(f,"y",0),s=b(f,"width",0),c=b(f,"height",0)):g(s)&&(s=b(f=s,"width",0),c=b(f,"height",0)),void 0===f&&(f={});var k=b(f,"inputType",void 0);void 0===k&&(k=b(f,"type","text")),"textarea"===k?(m=document.createElement("textarea")).style.resize="none":(m=document.createElement("input")).type=k,h(l,f,m);var x=b(f,"style",void 0);x=h(a,f,x);var O=m.style;for(var w in f)w in l||w in a||w in O&&(x[w]=f[w]);return x["box-sizing"]="border-box",(v=n.call(this,e,o,i,m,x)).type="rexInputText",v.resize(s,c),function(e,t,n,o){var i=p(o,"preventDefault",!1),r=p(o,"preTest"),s=function(o){t.addEventListener(o,(function(t){r&&!r(e,o)||e.emit(n[o],e,t),i&&t.preventDefault();}));};for(var u in n)s(u);}(u(v),m,d),function(e){e.addEventListener("touchstart",y,!1),e.addEventListener("touchmove",y,!1),e.addEventListener("touchend",y,!1),e.addEventListener("mousedown",y,!1),e.addEventListener("mouseup",y,!1),e.addEventListener("mousemove",y,!1);}(m),b(f,"selectAll",!1)&&v.selectAll(),v._isFocused=!1,v.on("focus",(function(){this._isFocused=!0;}),u(v)).on("blur",(function(){this._isFocused=!1;}),u(v)),v}return o(r,[{key:"inputType",get:function(){return "textarea"===this.node.tagName.toLowerCase()?"textarea":this.node.type}},{key:"text",get:function(){return this.node.value},set:function(e){this.node.value=e;}},{key:"setText",value:function(e){return this.text=e,this}},{key:"maxLength",get:function(){return this.node.maxLength},set:function(e){this.node.maxLength=e;}},{key:"setMaxLength",value:function(e){return this.maxLength=e,this}},{key:"minLength",get:function(){return this.node.minLength},set:function(e){this.node.minLength=e;}},{key:"setMinLength",value:function(e){return this.minLength=e,this}},{key:"placeholder",get:function(){return this.node.placeholder},set:function(e){this.node.placeholder=e;}},{key:"setPlaceholder",value:function(e){return this.placeholder=e,this}},{key:"selectText",value:function(e,t){return void 0===e?this.node.select():this.node.setSelectionRange(e,t),this}},{key:"selectAll",value:function(){return this.selectText(),this}},{key:"selectionStart",get:function(){return this.node.selectionStart}},{key:"selectionEnd",get:function(){return this.node.selectionEnd}},{key:"selectedText",get:function(){var e=this.node;return e.value.substring(e.selectionStart,e.selectionEnd)}},{key:"cursorPosition",get:function(){return this.node.selectionStart},set:function(e){this.node.setSelectionRange(e,e);}},{key:"setCursorPosition",value:function(e){return void 0===e?e=this.text.length:e<0&&(e=this.text.length+e),this.cursorPosition=e,this}},{key:"tooltip",get:function(){return this.node.title},set:function(e){this.node.title=e;}},{key:"setTooltip",value:function(e){return this.tooltip=e,this}},{key:"setTextChangedCallback",value:function(e){return this.onTextChanged=e,this}},{key:"readOnly",get:function(){return this.node.readOnly},set:function(e){this.node.readOnly=e;}},{key:"setReadOnly",value:function(e){return void 0===e&&(e=!0),this.readOnly=e,this}},{key:"spellCheck",get:function(){return this.node.spellcheck},set:function(e){this.node.spellcheck=e;}},{key:"setSpellCheck",value:function(e){return this.spellCheck=e,this}},{key:"fontColor",get:function(){return this.node.style.color},set:function(e){this.node.style.color=e;}},{key:"setFontColor",value:function(e){return this.fontColor=e,this}},{key:"setStyle",value:function(e,t){return this.node.style[e]=t,this}},{key:"getStyle",value:function(e){return this.node.style[e]}},{key:"scrollToBottom",value:function(){return this.node.scrollTop=this.node.scrollHeight,this}},{key:"setEnabled",value:function(e){return void 0===e&&(e=!0),this.node.disabled=!e,this}},{key:"setBlur",value:function(){return this.node.blur(),this}},{key:"setFocus",value:function(){return this.node.focus(),this}},{key:"isFocused",get:function(){return this._isFocused}}]),r}(v),k={resize:function(e,t){if(this.scene.sys.scale.autoRound&&(e=Math.floor(e),t=Math.floor(t)),this.width===e&&this.height===t)return this;var n=this.node.style;return n.width="".concat(e,"px"),n.height="".concat(t,"px"),this.updateSize(),this}};function x(e,t,n,o,i){var r=new m(this.scene,e,t,n,o,i);return this.scene.add.existing(r),r}Object.assign(m.prototype,k);var O=Phaser.Utils.Objects.GetAdvancedValue,w=Phaser.GameObjects.BuildGameObject;function j(e,t){void 0===e&&(e={}),void 0!==t&&(e.add=t);var n=O(e,"width",void 0),o=O(e,"height",void 0),i=new m(this.scene,0,0,n,o,e);return w(this.scene,i,e),i}var P=function(e){return null==e||""===e||0===e.length},L=function(e){i(r,Phaser.Plugins.BasePlugin);var n=c(r);function r(e){var o;return t(this,r),o=n.call(this,e),e.registerGameObject("rexInputText",x,j),o}return o(r,[{key:"start",value:function(){this.game.events.on("destroy",this.destroy,this);}}]),r}();return function(t,n,o,i){if(void 0===i&&(i="."),"object"===e(t)){if(P(n)){if(null==o)return;"object"===e(o)&&(t=o);}else {"string"==typeof n&&(n=n.split(i));var r=n.pop(),s=function(t,n,o){var i=t;if(P(n));else {var r;"string"==typeof n&&(n=n.split("."));for(var s=0,u=n.length;s<u;s++){var c;null!=i[r=n[s]]&&"object"===e(i[r])||(c=s===u-1?void 0===o?{}:o:{},i[r]=c),i=i[r];}}return i}(t,n);s[r]=o;}}}(window,"RexPlugins.GameObjects.InputText",m),L}));