UNPKG

phaser3-rex-plugins

Version:
2 lines (1 loc) 14.6 kB
!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).rextexteditplugin=e();}(undefined,(function(){function t(e){return t="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(e)}function e(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function n(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,(o=i.key,r=void 0,"symbol"==typeof(r=function(t,e){if("object"!=typeof t||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var i=n.call(t,e||"default");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return ("string"===e?String:Number)(t)}(o,"string"))?r:String(r)),i);}var o,r;}function i(t,e,i){return e&&n(t.prototype,e),i&&n(t,i),Object.defineProperty(t,"prototype",{writable:!1}),t}function o(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}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&s(t,e);}function r(t){return r=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},r(t)}function s(t,e){return s=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},s(t,e)}function u(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function c(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=r(t);if(e){var o=r(this).constructor;n=Reflect.construct(i,arguments,o);}else n=i.apply(this,arguments);return function(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 u(t)}(this,n)}}function l(){return l="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(t,e,n){var i=function(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=r(t)););return t}(t,e);if(i){var o=Object.getOwnPropertyDescriptor(i,e);return o.get?o.get.call(arguments.length<3?t:n):o.value}},l.apply(this,arguments)}var a={setEventEmitter:function(t,e){return void 0===e&&(e=Phaser.Events.EventEmitter),this._privateEE=!0===t||void 0===t,this._eventEmitter=this._privateEE?new e:t,this},destroyEventEmitter:function(){return this._eventEmitter&&this._privateEE&&this._eventEmitter.shutdown(),this},getEventEmitter:function(){return this._eventEmitter},on:function(){return this._eventEmitter&&this._eventEmitter.on.apply(this._eventEmitter,arguments),this},once:function(){return this._eventEmitter&&this._eventEmitter.once.apply(this._eventEmitter,arguments),this},off:function(){return this._eventEmitter&&this._eventEmitter.off.apply(this._eventEmitter,arguments),this},emit:function(t){return this._eventEmitter&&t&&this._eventEmitter.emit.apply(this._eventEmitter,arguments),this},addListener:function(){return this._eventEmitter&&this._eventEmitter.addListener.apply(this._eventEmitter,arguments),this},removeListener:function(){return this._eventEmitter&&this._eventEmitter.removeListener.apply(this._eventEmitter,arguments),this},removeAllListeners:function(){return this._eventEmitter&&this._eventEmitter.removeAllListeners.apply(this._eventEmitter,arguments),this},listenerCount:function(){return this._eventEmitter?this._eventEmitter.listenerCount.apply(this._eventEmitter,arguments):0},listeners:function(){return this._eventEmitter?this._eventEmitter.listeners.apply(this._eventEmitter,arguments):[]},eventNames:function(){return this._eventEmitter?this._eventEmitter.eventNames.apply(this._eventEmitter,arguments):[]}},h=Phaser.Scene,d=function(t){return t instanceof h},f=Phaser.Game,p=function(t){return t instanceof f},v=Phaser.Utils.Objects.GetValue,y=function(){function n(t,i){e(this,n),this.setParent(t),this.isShutdown=!1,this.setEventEmitter(v(i,"eventEmitter",!0)),this.parent&&(this.parent===this.scene?this.scene.sys.events.once("shutdown",this.onEnvDestroy,this):this.parent===this.game?this.game.events.once("shutdown",this.onEnvDestroy,this):this.parent.once&&this.parent.once("destroy",this.onParentDestroy,this));}return i(n,[{key:"shutdown",value:function(t){this.isShutdown||(this.parent&&(this.parent===this.scene?this.scene.sys.events.off("shutdown",this.onEnvDestroy,this):this.parent===this.game?this.game.events.off("shutdown",this.onEnvDestroy,this):this.parent.once&&this.parent.off("destroy",this.onParentDestroy,this)),this.destroyEventEmitter(),this.parent=void 0,this.scene=void 0,this.game=void 0,this.isShutdown=!0);}},{key:"destroy",value:function(t){this.shutdown(t);}},{key:"onEnvDestroy",value:function(){this.destroy(!0);}},{key:"onParentDestroy",value:function(t,e){this.destroy(e);}},{key:"setParent",value:function(e){var n;return this.parent=e,this.scene=null==(n=e)||"object"!==t(n)?null:d(n)?n:n.scene&&d(n.scene)?n.scene:n.parent&&n.parent.scene&&d(n.parent.scene)?n.parent.scene:null,this.game=function(e){return null==e||"object"!==t(e)?null:p(e)?e:p(e.game)?e.game:d(e)?e.sys.game:d(e.scene)?e.scene.sys.game:void 0}(e),this}}]),n}();Object.assign(y.prototype,a);var m=void 0,g={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"]},b={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]},E={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"},k=Phaser.Utils.Objects.GetValue,x=function(t,e,n){var i,o;for(var r in void 0===n&&(n={}),t)i=t[r],void 0!==(o=k(e,r,i[1]))&&(n[i[0]]=o);return n},w=Phaser.Utils.Objects.GetValue,_=function(t){t.stopPropagation();},O=Phaser.GameObjects.DOMElement,P=Phaser.Utils.Objects.IsPlainObject,C=Phaser.Utils.Objects.GetValue,j=function(t){o(r,t);var n=c(r);function r(t,i,o,s,c,l){var a,h;e(this,r),P(i)?(i=C(l=i,"x",0),o=C(l,"y",0),s=C(l,"width",0),c=C(l,"height",0)):P(s)&&(s=C(l=s,"width",0),c=C(l,"height",0)),void 0===l&&(l={});var d=C(l,"inputType",void 0);void 0===d&&(d=C(l,"type","text")),"textarea"===d?(h=document.createElement("textarea")).style.resize="none":(h=document.createElement("input")).type=d,x(g,l,h);var f=C(l,"style",void 0);f=x(b,l,f);var p=h.style;for(var v in l)v in g||v in b||v in p&&(f[v]=l[v]);return f["box-sizing"]="border-box",(a=n.call(this,t,i,o,h,f)).type="rexInputText",a.resize(s,c),function(t,e,n,i){var o=w(i,"preventDefault",!1),r=w(i,"preTest"),s=function(i){e.addEventListener(i,(function(e){r&&!r(t,i)||t.emit(n[i],t,e),o&&e.preventDefault();}));};for(var u in n)s(u);}(u(a),h,E),function(t){t.addEventListener("touchstart",_,!1),t.addEventListener("touchmove",_,!1),t.addEventListener("touchend",_,!1),t.addEventListener("mousedown",_,!1),t.addEventListener("mouseup",_,!1),t.addEventListener("mousemove",_,!1);}(h),C(l,"selectAll",!1)&&a.selectAll(),a._isFocused=!1,a.on("focus",(function(){this._isFocused=!0;}),u(a)).on("blur",(function(){this._isFocused=!1;}),u(a)),a}return i(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(t){this.node.value=t;}},{key:"setText",value:function(t){return this.text=t,this}},{key:"maxLength",get:function(){return this.node.maxLength},set:function(t){this.node.maxLength=t;}},{key:"setMaxLength",value:function(t){return this.maxLength=t,this}},{key:"minLength",get:function(){return this.node.minLength},set:function(t){this.node.minLength=t;}},{key:"setMinLength",value:function(t){return this.minLength=t,this}},{key:"placeholder",get:function(){return this.node.placeholder},set:function(t){this.node.placeholder=t;}},{key:"setPlaceholder",value:function(t){return this.placeholder=t,this}},{key:"selectText",value:function(t,e){return void 0===t?this.node.select():this.node.setSelectionRange(t,e),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 t=this.node;return t.value.substring(t.selectionStart,t.selectionEnd)}},{key:"cursorPosition",get:function(){return this.node.selectionStart},set:function(t){this.node.setSelectionRange(t,t);}},{key:"setCursorPosition",value:function(t){return void 0===t?t=this.text.length:t<0&&(t=this.text.length+t),this.cursorPosition=t,this}},{key:"tooltip",get:function(){return this.node.title},set:function(t){this.node.title=t;}},{key:"setTooltip",value:function(t){return this.tooltip=t,this}},{key:"setTextChangedCallback",value:function(t){return this.onTextChanged=t,this}},{key:"readOnly",get:function(){return this.node.readOnly},set:function(t){this.node.readOnly=t;}},{key:"setReadOnly",value:function(t){return void 0===t&&(t=!0),this.readOnly=t,this}},{key:"spellCheck",get:function(){return this.node.spellcheck},set:function(t){this.node.spellcheck=t;}},{key:"setSpellCheck",value:function(t){return this.spellCheck=t,this}},{key:"fontColor",get:function(){return this.node.style.color},set:function(t){this.node.style.color=t;}},{key:"setFontColor",value:function(t){return this.fontColor=t,this}},{key:"setStyle",value:function(t,e){return this.node.style[t]=e,this}},{key:"getStyle",value:function(t){return this.node.style[t]}},{key:"scrollToBottom",value:function(){return this.node.scrollTop=this.node.scrollHeight,this}},{key:"setEnabled",value:function(t){return void 0===t&&(t=!0),this.node.disabled=!t,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}(O),T={resize:function(t,e){if(this.scene.sys.scale.autoRound&&(t=Math.floor(t),e=Math.floor(e)),this.width===t&&this.height===e)return this;var n=this.node.style;return n.width="".concat(t,"px"),n.height="".concat(e,"px"),this.updateSize(),this}};Object.assign(j.prototype,T);var S=Phaser.GameObjects.Text,L=Phaser.Utils.Objects.GetValue,F=Phaser.Utils.Objects.Clone,R=function(t,e){void 0===e&&(e={}),e=F(e);var n=t.scene,i=t.style,o=L(e,"backgroundColor",i.backgroundColor);null===o&&(o="transparent"),e.text=L(e,"text",t.text),e.fontFamily=L(e,"fontFamily",i.fontFamily),e.fontSize=L(e,"fontSize",i.fontSize),e.color=L(e,"color",i.color),e.backgroundColor=o,e.direction=L(e,"rtl",i.rtl)?"rtl":"ltr",e.align=L(e,"align",D(i)),"rtl"===e.direction&&t instanceof S&&(e.align="right");var r=new j(n,t.x,t.y,L(e,"width",t.width),L(e,"height",t.height),e);r.setOrigin(t.originX,t.originY).setScrollFactor(t.scrollFactorX,t.scrollFactorY);var s=t.parentContainer;return s?s.add(r):n.add.existing(r),r},D=function(t){return t.hasOwnProperty("align")?t.align:t.hasOwnProperty("halign")?t.halign:"left"},U=Phaser.Utils.Objects.GetValue,z=Phaser.Utils.Objects.Merge,G={open:function(t,e){var n,i;void 0===t&&(t={}),t=z(t,this.openConfig),(n=this)!==m&&(void 0!==m&&m.close(),m=n),(i=t)&&"function"==typeof i&&(e=t,t=void 0);var o=U(t,"inputType",void 0);void 0===o&&(o=U(t,"type","text")),void 0===e&&(e=U(t,"onClose",void 0));var r=U(t,"onOpen",void 0),s=U(t,"onTextChanged",void 0);return this.inputText=R(this.parent,t).on("textchange",(function(t){var e=t.text;s?s(this.parent,e):this.parent.text=e;}),this).setFocus(),this.parent.setVisible(!1),this.onClose=e,U(t,"enterClose","textarea"!==o)&&this.scene.input.keyboard.once("keydown-ENTER",this.close,this),this.delayCall=function(t,e,n){return t.time.delayedCall(0,e,[],n)}(this.scene,(function(){this.scene.input.once("pointerdown",this.close,this),r&&r(this.parent),this.emit("open",this.parent);}),this),this},close:function(){return this===m&&(m=void 0),this.parent.setVisible(!0),this.inputText&&(this.inputText.destroy(),this.inputText=void 0),this.delayCall&&(this.delayCall.remove(),this.delayCall=void 0),this.scene.input.keyboard.off("keydown-ENTER",this.close,this),this.scene.input.off("pointerdown",this.close,this),this.onClose&&this.onClose(this.parent),this.emit("close",this.parent),this}},V=Phaser.Utils.Objects.GetValue,A=function(t){o(s,t);var n=c(s);function s(t,i){var o;return e(this,s),(o=n.call(this,t)).inputText=void 0,o.onClose=void 0,o.delayCall=void 0,o.setOpenConfig(i),V(i,"clickEnable",!0)&&t.on("pointerdown",(function(){this.open();}),u(o)).setInteractive(),o}return i(s,[{key:"shutdown",value:function(t){this.isShutdown||(this.close(),l(r(s.prototype),"shutdown",this).call(this,t));}},{key:"setOpenConfig",value:function(t){return void 0===t&&(t={}),this.openConfig=t,this}},{key:"isOpened",get:function(){return void 0!==this.inputText}},{key:"text",get:function(){return this.isOpened?this.inputText.text:this.parent.text}}]),s}(y);Object.assign(A.prototype,G);var B=function(t){o(r,Phaser.Plugins.BasePlugin);var n=c(r);function r(t){return e(this,r),n.call(this,t)}return i(r,[{key:"start",value:function(){this.game.events.on("destroy",this.destroy,this);}},{key:"add",value:function(t,e){return new A(t,e)}}]),r}(),M={edit:function(t,e,n){return t._edit||(t._edit=new A(t,{clickEnable:!1})),t._edit.open(e,n),t._edit}};return Object.assign(B.prototype,M),B}));