text: !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).rexdynamictextplugin=e()}(this,function(){"use strict";function c(t){return(c="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 d(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function s(t,e){for(var i=0;i<e.length;i++){var s=e[i];s.enumerable=s.enumerable||!1,s.configurable=!0,"value"in s&&(s.writable=!0),Object.defineProperty(t,s.key,s)}}function a(t,e,i){return e&&s(t.prototype,e),i&&s(t,i),t}function t(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&&i(t,e)}function o(t){return(o=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function i(t,e){return(i=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function f(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function e(r){var h=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 t,e,i,s=o(r);if(h){var n=o(this).constructor;t=Reflect.construct(s,arguments,n)}else t=s.apply(this,arguments);return e=this,!(i=t)||"object"!=typeof i&&"function"!=typeof i?f(e):i}}function h(t,e,i){return(h="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(t,e,i){var s=function(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=o(t)););return t}(t,e);if(s){var n=Object.getOwnPropertyDescriptor(s,e);return n.get?n.get.call(i):n.value}})(t,e,i||t)}var u=Phaser.Renderer.WebGL.Utils,n={renderWebGL:function(t,e,i,s){if(e.dirty&&(e.updateTexture(),e.dirty=!1),0!==e.width&&0!==e.height){i.addToRenderList(e);var n=e.frame,r=n.width,h=n.height,o=u.getTintAppendFloatAlpha,a=t.pipelines.set(e.pipeline,e),l=a.setTexture2D(n.glTexture,e);t.pipelines.preBatch(e),a.batchTexture(e,n.glTexture,r,h,e.x,e.y,r/e.resolution,h/e.resolution,e.scaleX,e.scaleY,e.rotation,e.flipX,e.flipY,e.scrollFactorX,e.scrollFactorY,e.displayOriginX,e.displayOriginY,0,0,r,h,o(e.tintTopLeft,i.alpha*e._alphaTL),o(e.tintTopRight,i.alpha*e._alphaTR),o(e.tintBottomLeft,i.alpha*e._alphaBL),o(e.tintBottomRight,i.alpha*e._alphaBR),e.tintFill,0,0,i,s,!1,l),t.pipelines.postBatch(e)}},renderCanvas:function(t,e,i,s){e.dirty&&(e.updateTexture(),e.dirty=!1),0!==e.width&&0!==e.height&&(i.addToRenderList(e),t.batchSprite(e,e.frame,i,s))}},r=Phaser.Display.Color,l={clear:function(){return this.context.clearRect(0,0,this.canvas.width,this.canvas.height),this.dirty=!0,this},fill:function(t){return this.context.fillStyle=t,this.context.fillRect(0,0,this.canvas.width,this.canvas.height),this.dirty=!0,this},loadFromURL:function(t,e){var i=this,s=new Image;return s.onload=function(){i.width!==s.width||i.height!==s.height?i.resize(s.width,s.height):i.clear(),i.context.drawImage(s,0,0),i.updateTexture(),e&&e(),s.onload=null,s.src="",s.remove()},s.src=t,this},loadFromURLPromise:function(i){var s=this;return new Promise(function(t,e){s.loadFromURL(i,t)})},getDataURL:function(t,e){return this.canvas.toDataURL(t,e)},getPixel:function(t,e,i){void 0===i&&(i=new r);var s=this.context.getImageData(t,e,1,1);return i.setTo(s.data[0],s.data[1],s.data[2],s.data[3]),i},setPixel:function(t,e,i,s,n,r){if("number"!=typeof i){var h=i;i=h.red,s=h.green,n=h.blue,r=h.alpha}void 0===r&&(r=0!==i||0!==s||0!==n?255:0);var o=this.context.createImageData(1,1);return o.data[0]=i,o.data[1]=s,o.data[2]=n,o.data[3]=r,this.context.putImageData(o,t,e),this.dirty=!0,this}},g={updateTexture:function(t,e){t&&(e?t.call(e,this.canvas,this.context):t(this.canvas,this.context)),this.canvas.width===this.frame.width&&this.canvas.height===this.frame.height||this.frame.setSize(this.canvas.width,this.canvas.height),this.renderer.gl&&(this.frame.source.glTexture=this.renderer.canvasToTexture(this.canvas,this.frame.source.glTexture,!0),this.frame.glTexture=this.frame.source.glTexture),this.dirty=!1;var i=this.input;return i&&!i.customHitArea&&(i.hitArea.width=this.width,i.hitArea.height=this.height),this},generateTexture:function(t,e,i,s,n){var r,h=this.canvas,o=this.scene.sys,a=o.game.renderer;void 0===e&&(e=0),void 0===i&&(i=0),void 0===s?s=h.width:s*=this.resolution,void 0===n?n=h.height:n*=this.resolution;var l=(r=o.textures.exists(t)?o.textures.get(t):o.textures.createCanvas(t,s,n)).getSourceImage();l.width!==s&&(l.width=s),l.height!==n&&(l.height=n);var u=l.getContext("2d");return u.clearRect(0,0,s,n),u.drawImage(h,e,i,s,n),a.gl&&r&&a.canvasToTexture(l,r.source[0].glTexture,!0,0),this},loadTexture:function(t,e){var i=this.scene.textures.getFrame(t,e);return i&&(this.width!==i.cutWidth||this.height!==i.cutHeight?this.resize(i.cutWidth,i.cutHeight):this.clear(),this.context.drawImage(i.source.image,i.cutX,i.cutY,i.cutWidth,i.cutHeight,0,0,this.canvas.width,this.canvas.height),this.dirty=!0),this}},y=Phaser.Display.Canvas.CanvasPool,p=Phaser.GameObjects.GameObject,v=function(){t(o,p);var h=e(o);function o(t,e,i,s,n){var r;return d(this,o),void 0===e&&(e=0),void 0===i&&(i=0),void 0===s&&(s=1),void 0===n&&(n=1),(r=h.call(this,t,"rexCanvas")).renderer=t.sys.game.renderer,r.resolution=1,r._width=s,r._height=n,s=Math.max(Math.ceil(s*r.resolution),1),n=Math.max(Math.ceil(n*r.resolution),1),r.canvas=y.create(f(r),s,n),r.context=r.canvas.getContext("2d"),r.dirty=!1,r.setPosition(e,i),r.setOrigin(.5,.5),r.initPipeline(),r._crop=r.resetCropObject(),r.texture=t.sys.textures.addCanvas(null,r.canvas,!0),r.frame=r.texture.get(),r.frame.source.resolution=r.resolution,r.renderer&&r.renderer.gl&&(r.renderer.deleteTexture(r.frame.source.glTexture),r.frame.source.glTexture=null),r.dirty=!0,t.sys.game.events.on("contextrestored",function(){this.dirty=!0},f(r)),r}return a(o,[{key:"width",get:function(){return this._width},set:function(t){this.setSize(t,this._height)}},{key:"height",get:function(){return this._height},set:function(t){this.setSize(this._width,t)}},{key:"setSize",value:function(t,e){return this._width===t&&this._height===e||(this._width=t,this._height=e,this.updateDisplayOrigin(),t=Math.max(Math.ceil(t*this.resolution),1),e=Math.max(Math.ceil(e*this.resolution),1),this.canvas.width=t,this.canvas.height=e,this.frame.setSize(t,e),this.dirty=!0),this}},{key:"displayWidth",get:function(){return this.scaleX*this._width},set:function(t){this.scaleX=t/this._width}},{key:"displayHeight",get:function(){return this.scaleY*this._height},set:function(t){this.scaleY=t/this._height}},{key:"setDisplaySize",value:function(t,e){return this.displayWidth=t,this.displayHeight=e,this}},{key:"getCanvas",value:function(t){return t||(this.dirty=!0),this.canvas}},{key:"getContext",value:function(t){return t||(this.dirty=!0),this.context}},{key:"needRedraw",value:function(){return this.dirty=!0,this}},{key:"preDestroy",value:function(){y.remove(this.canvas)}},{key:"resize",value:function(t,e){return this.setSize(t,e),this}}]),o}(),k=Phaser.GameObjects.Components;Phaser.Class.mixin(v,[k.Alpha,k.BlendMode,k.Crop,k.Depth,k.Flip,k.GetBounds,k.Mask,k.Origin,k.Pipeline,k.ScrollFactor,k.Tint,k.Transform,k.Visible,n,l,g]);function x(t,e,i){if(null==t)return t;switch(c(t)){case"string":return t;case"number":return"#".concat(A(Math.floor(t).toString(16),6,"0",1));case"function":return t(e,i);case"object":return t.hasOwnProperty("r")?t.hasOwnProperty("a")?"rgba(".concat(t.r,",").concat(t.g,",").concat(t.b,",").concat(t.a,")"):"rgb(".concat(t.r,",").concat(t.g,",").concat(t.b,")"):t.hasOwnProperty("h")?t.hasOwnProperty("a")?"hsla(".concat(t.h,",").concat(t.s,",").concat(t.l,",").concat(t.a,")"):"hsl(".concat(t.h,",").concat(t.s,",").concat(t.l,")"):t;default:return t}}function w(t,e,i,s,n,r,h,o,a,l,u,c,d){var f,g,y,p,v,k,x,w,m,b,O,P,T,_,S,C,A;if(f=e,k=d,P=new R(g=i,y=s,p=n,v=r,h),T=P.minWidth,_=P.minHeight,S=T<=p?1:p/T,C=_<=v?1:v/_,A=P.cornerRadius,f.save(),f.beginPath(),f.translate(g,y),b=p-(w=(x=A.br).x*S),O=v-(m=x.y*C),f.moveTo(p,O),0<w&&0<m?G(f,b,O,w,m,X,Y,k):(f.lineTo(p,v),f.lineTo(b,v)),b=w=(x=A.bl).x*S,O=v-(m=x.y*C),f.lineTo(w,v),0<w&&0<m?G(f,b,O,w,m,Y,j,k):(f.lineTo(0,v),f.lineTo(0,O)),b=w=(x=A.tl).x*S,O=m=x.y*C,f.lineTo(0,O),0<w&&0<m?G(f,b,O,w,m,j,B,k):(f.lineTo(0,0),f.lineTo(b,0)),b=p-(w=(x=A.tr).x*S),O=m=x.y*C,f.lineTo(b,0),0<w&&0<m?G(f,b,O,w,m,B,X,k):(f.lineTo(p,0),f.lineTo(p,O)),f.closePath(),f.restore(),null!=o){var W;if(null!=u)(W=c?e.createLinearGradient(0,0,n,0):e.createLinearGradient(0,0,0,r)).addColorStop(0,o),W.addColorStop(1,u),o=W;e.fillStyle=o,e.fill()}null!=a&&0<l&&(e.strokeStyle=a,e.lineWidth=l,e.stroke())}function m(t,e,i){return e.hasOwnProperty(t)?e[t]:i[t]}function b(t,e){if(!e)return t;for(var i in null==t&&(t={}),e)t.hasOwnProperty(i)||(t[i]=e[i]);return t}function z(t,e,i,s){void 0===s&&(s={word:[],width:0}),s.word.length=0;for(var n=t.length,r=e,h=s.word,o=0;r<n;){var a=t[r];if("text"!==a.type||" "===a.text||"\n"===a.text){r===e&&(h.push(a),o+=a.width);break}if(h.push(a),o+=a.width,r++,i)break}return s.width=o,s}function O(t){var e,i=Q(t,"start",0),s=Q(t,"padding.top",0),n=Q(t,"padding.bottom",0),r=Q(t,"lineHeight",void 0);if(void 0===r)e=Q(t,"maxLines",0),r=0<this.fixedHeight?(h=this.fixedHeight-this.padding.top-this.padding.bottom-s-n)/e:0;else if(0<this.fixedHeight){if(void 0===(e=Q(t,"maxLines",void 0))){var h=this.fixedHeight-this.padding.top-this.padding.bottom-s-n;e=Math.floor(h/r)}}else e=Q(t,"maxLines",0);var o=0===e,a=Q(t,"wrapWidth",void 0);void 0===a&&(a=0<this.fixedWidth?this.fixedWidth-this.padding.left-this.padding.right:1/0);for(var l=Q(t,"letterSpacing",0),u=Q(t,"hAlign",0),c=Q(t,"vAlign",0),d=Q(t,"charWrap",!1),f={start:i,isLastPage:!1,padding:{top:s,bottom:n},lineHeight:r,maxLines:e,wrapWidth:a,letterSpacing:l,hAlign:u,vAlign:c,charWrap:d,children:[],lines:[],maxLineWidth:0,linesHeight:0},g=this.children,y=0,p=g.length;y<p;y++)g[y].setActive(!1);a+=l;for(var v,k=this.padding.left,x=k,w=this.padding.top+r+s,m=a,b=i,O=g.length,P=f.children,T=f.lines,_=[],S=0,C=0;b<O;){var A=(v=z(g,b,d,v)).word,W=A.length,R=v.width+W*l;b+=W;var D=Z(A);if(m<R||D){if(D)(H=A[0]).setActive().setPosition(x,w),P.push(H),_.push(H);if(x=k,w+=r,m=a,T.push({children:_,width:S}),C=Math.max(C,S),S=0,_=[],!o&&T.length===e)break;if(D)continue}m-=R,S+=R;for(y=0,p=A.length;y<p;y++){var H;(H=A[y]).setActive().setPosition(x,w),P.push(H),_.push(H),x+=H.width+l}}0<_.length&&(T.push({children:_,width:S}),C=Math.max(C,S)),f.start+=P.length,f.isLastPage=f.start===O,f.maxLineWidth=C,f.linesHeight=T.length*r+s+n;var X=0<this.fixedWidth?this.fixedWidth:f.maxLineWidth+this.padding.left+this.padding.right,Y=0<this.fixedHeight?this.fixedHeight:f.linesHeight+this.padding.top+this.padding.bottom;return function(t,e,i){var s=t.hAlign,n=t.vAlign;if("string"==typeof s&&(s=q[s],t.hAlign=s),"string"==typeof n&&(n=K[n],t.vAlign=n),0!==s)for(var r=t.lines,h=0,o=r.length;h<o;h++){var a,l=r[h],u=l.width,c=l.children;switch(s){case 1:a=(e-u)/2;break;case 2:a=e-u}for(var d=0,f=c.length;d<f;d++){c[d].x+=a}}if(0!==n){var g,y=t.linesHeight;switch(n){case 1:g=(i-y)/2;break;case 2:g=i-y}for(d=0,f=(c=t.children).length;d<f;d++){c[d].y+=g}}}(f,X-this.padding.left-this.padding.right,h=Y-this.padding.top-this.padding.bottom-s-n),this.setSize(X,Y),f}function P(t){var e,i=$(t,"start",0),s=$(t,"padding.top",0),n=$(t,"padding.bottom",0),r=$(t,"padding.left",0),h=$(t,"padding.right",0),o=$(t,"lineWidth",void 0);if(void 0===o)e=$(t,"maxLines",0),o=0<this.fixedWidth?(a=this.fixedWidth-this.padding.left-this.padding.right-r-h)/e:0;else if(0<this.fixedWidth){if(void 0===(e=$(t,"maxLines",void 0))){var a=this.fixedWidth-this.padding.left-this.padding.right;e=Math.floor(a/o)}}else e=$(t,"maxLines",0);var l=0===e,u=$(t,"fixedChildHeight",void 0);if(void 0===u){var c=$(t,"charPerLine",void 0);if(void 0!==c){var d=this.fixedHeight-this.padding.top-this.padding.bottom-s-n;u=Math.floor(d/c)}}var f=$(t,"wrapHeight",void 0);void 0===f&&(f=0<this.fixedHeight?this.fixedHeight-this.padding.top-this.padding.bottom:1/0);for(var g=$(t,"letterSpacing",0),y=$(t,"rtl",!0),p={start:i,isLastPage:!1,padding:{top:s,bottom:n,left:r,right:h},lineWidth:o,maxLines:e,fixedChildHeight:u,wrapHeight:f,letterSpacing:g,hAlign:$(t,"hAlign",y?2:0),vAlign:$(t,"vAlign",0),rtl:y,children:[],lines:[],maxLineHeight:0,linesWidth:0},v=this.children,k=0,x=v.length;k<x;k++)v[k].setActive(!1);f+=g;for(var w=this.padding.left+r,m=this.padding.top+s,b=w,O=m,P=f,T=i,_=v.length,S=p.children,C=p.lines,A=[],W=0,R=0;T<_;){var D=v[T],H=(void 0!==u?u:D.height)+g;T++;var X=tt(D);if(P<H||X){if(X&&(D.setActive().setPosition(b,O).setOrigin(.5),S.push(D),A.push(D)),b=w,O=m,P=f,C.push({children:A,height:W}),R=Math.max(R,W),W=0,A=[],!l&&C.length===e)break;if(X)continue}P-=H,W+=H,D.setActive().setPosition(b,O).setOrigin(.5),S.push(D),A.push(D),O+=H}0<A.length&&(C.push({children:A,height:W}),R=Math.max(R,W)),p.start+=S.length,p.isLastPage=p.start===_,p.maxLineHeight=R,p.linesWidth=C.length*o+r+h;var Y=0<this.fixedWidth?this.fixedWidth:p.linesWidth+this.padding.left+this.padding.right,z=0<this.fixedHeight?this.fixedHeight:p.maxLineHeight+this.padding.top+this.padding.bottom;return function(t,e,i){var s=t.hAlign,n=t.vAlign;"string"==typeof s&&(s=q[s],t.hAlign=s),"string"==typeof n&&(n=K[n],t.vAlign=n);var r,h=t.rtl,o=t.lines,a=t.lineWidth,l=t.linesWidth;switch(s){case 0:r=0;break;case 1:r=(e-l)/2;break;case 2:r=e-l}h&&(r+=a);for(var u=0,c=o.length;u<c;u++){var d,f=o[h?c-u-1:u],g=f.children,y=f.height;switch(n){case 0:d=0;break;case 1:d=(i-y)/2;break;case 2:d=i-y}for(var p=0,v=g.length;p<v;p++){var k=g[p];k.x+=r,k.y+=d}r+=a}}(p,a=Y-this.padding.left-this.padding.right-r-h,d=z-this.padding.top-this.padding.bottom-s-n),this.setSize(Y,z),p}var T=Phaser.Math.DegToRad,_=Phaser.Math.RadToDeg,S=Phaser.Utils.Objects.GetValue,C=function(){function i(t,e){d(this,i),this.setParent(t),this.type=e,this.setActive().setVisible().setAlpha(1).setPosition(0,0).setRotation(0).setScale(1,1).setOrigin(0).setDrawBelowCallback().setDrawAboveCallback(),this.originX=0,this.offsetX=0,this.offsetY=0}return a(i,[{key:"setParent",value:function(t){return this.parent=t,this}},{key:"scene",get:function(){return this.parent.scene}},{key:"canvas",get:function(){return this.parent?this.parent.canvas:null}},{key:"context",get:function(){return this.parent?this.parent.context:null}},{key:"setDirty",value:function(t){return t&&this.parent&&(this.parent.dirty=!0),this}},{key:"active",get:function(){return this._active},set:function(t){this.setDirty(this._active!=t),this._active=t}},{key:"setActive",value:function(t){return void 0===t&&(t=!0),this.active=t,this}},{key:"visible",get:function(){return this._visible},set:function(t){this.setDirty(this._visible!=t),this._visible=t}},{key:"setVisible",value:function(t){return void 0===t&&(t=!0),this.visible=t,this}},{key:"alpha",get:function(){return this._alpha},set:function(t){this.setDirty(this._alpha!=t),this._alpha=t}},{key:"setAlpha",value:function(t){return this.alpha=t,this}},{key:"x",get:function(){return this._x},set:function(t){this.setDirty(this._x!=t),this._x=t}},{key:"setX",value:function(t){return this.x=t,this}},{key:"y",get:function(){return this._y},set:function(t){this.setDirty(this._y!=t),this._y=t}},{key:"setY",value:function(t){return this.y=t,this}},{key:"setPosition",value:function(t,e){return this.x=t,this.y=e,this}},{key:"rotation",get:function(){return this._rotation},set:function(t){this.setDirty(this._rotation!=t),this._rotation=t}},{key:"setRotation",value:function(t){return this.rotation=t,this}},{key:"angle",get:function(){return _(this._rotation)},set:function(t){this.rotation=T(t)}},{key:"setAngle",value:function(t){return this.angle=t,this}},{key:"scaleX",get:function(){return this._scaleX},set:function(t){this.setDirty(this._scaleX!==t),this._scaleX=t}},{key:"setScaleX",value:function(t){return this.scaleX=t,this}},{key:"width",get:function(){return 0},set:function(){}},{key:"setWidth",value:function(t,e){return void 0===e&&(e=!1),this.width=t,e&&(this.scaleY=this.scaleX),this}},{key:"scaleY",get:function(){return this._scaleY},set:function(t){this.setDirty(this._scaleY!==t),this._scaleY=t}},{key:"setScaleY",value:function(t){return this.scaleY=t,this}},{key:"height",get:function(){return 0},set:function(){}},{key:"setHeight",value:function(t,e){return void 0===e&&(e=!1),this.height=t,e&&(this.scaleX=this.scaleY),this}},{key:"setScale",value:function(t,e){return void 0===e&&(e=t),this.scaleX=t,this.scaleY=e,this}},{key:"modifyPorperties",value:function(t){if(!t)return this;t.hasOwnProperty("x")&&this.setX(t.x),t.hasOwnProperty("y")&&this.setY(t.y),t.hasOwnProperty("rotation")?this.setRotation(t.rotation):t.hasOwnProperty("angle")&&this.setAngle(t.angle),t.hasOwnProperty("alpha")&&this.setAlpha(t.alpha);var e=S(t,"width",void 0),i=S(t,"height",void 0),s=S(t,"scaleX",void 0),n=S(t,"scaleY",void 0);return void 0!==e&&(void 0===i&&void 0===n?this.setWidth(e,!0):this.setWidth(e)),void 0!==i&&(void 0===e&&void 0===s?this.setHeight(i,!0):this.setHeight(i)),void 0!==s&&void 0===e&&this.setScaleX(s),void 0!==n&&void 0===i&&this.setScaleY(n),this}},{key:"setOrigin",value:function(t){return this.originX=t,this}},{key:"setDrawBelowCallback",value:function(t){return this.drawBelowCallback=t,this}},{key:"setDrawAboveCallback",value:function(t){return this.drawAboveCallback=t,this}},{key:"onFree",value:function(){this.setParent().setVisible().setAlpha(1).setPosition(0,0).setRotation(0).setScale(1,1).setOrigin(0).setDrawBelowCallback().setDrawAboveCallback()}},{key:"drawContent",value:function(){}},{key:"draw",value:function(){var t=this.context;t.save();var e=this.x+this.offsetX-this.originX*this.width,i=this.y+this.offsetY;this.autoRound&&(e=Math.round(e),i=Math.round(i)),t.translate(e,i),t.globalAlpha=this.alpha,t.scale(this.scaleX,this.scaleY),t.rotate(this.rotation),this.drawBelowCallback&&this.drawBelowCallback.call(this),this.drawContent(),this.drawAboveCallback&&this.drawAboveCallback.call(this),t.restore()}}]),i}(),A=Phaser.Utils.String.Pad,W=Phaser.Utils.Objects.GetValue,R=function(){function r(t,e,i,s,n){d(this,r),this.cornerRadius={},this._width=0,this._height=0,this.setTo(t,e,i,s,n)}return a(r,[{key:"setTo",value:function(t,e,i,s,n){return this.setPosition(t,e),this.setRadius(n),this.setSize(i,s),this}},{key:"setPosition",value:function(t,e){return void 0===t&&(t=0),void 0===e&&(e=t),this.x=t,this.y=e,this}},{key:"setRadius",value:function(t){var e,i;void 0===t&&(t=0),i="number"==typeof t?e=t:(e=W(t,"x",0),W(t,"y",0));var s=this.cornerRadius;return s.tl=D(W(t,"tl",void 0),e,i),s.tr=D(W(t,"tr",void 0),e,i),s.bl=D(W(t,"bl",void 0),e,i),s.br=D(W(t,"br",void 0),e,i),this}},{key:"setSize",value:function(t,e){return this.width=t,this.height=e,this}},{key:"minWidth",get:function(){var t=this.cornerRadius;return Math.max(t.tl.x+t.tr.x,t.bl.x+t.br.x)}},{key:"minHeight",get:function(){var t=this.cornerRadius;return Math.max(t.tl.y+t.bl.y,t.tr.y+t.br.y)}},{key:"width",get:function(){return this._width},set:function(t){null==t&&(t=0),this._width=Math.max(t,this.minWidth)}},{key:"height",get:function(){return this._height},set:function(t){null==t&&(t=0),this._height=Math.max(t,this.minHeight)}},{key:"radius",get:function(){var t=this.cornerRadius;return Math.max(t.tl.x,t.tl.y,t.tr.x,t.tr.y,t.bl.x,t.bl.y,t.br.x,t.br.y)}}]),r}(),D=function(t,e,i){return void 0===t?{x:e,y:i}:"number"==typeof t?{x:t,y:t}:t},H=Phaser.Math.DegToRad,X=H(0),Y=H(90),j=H(180),B=H(270),G=function(t,e,i,s,n,r,h,o){if(null==o)t.ellipse(e,i,s,n,0,r,h);else for(var a,l,u,c=(h-r)/(o+=1),d=0;d<=o;d++)u=r+c*d,a=e+s*Math.cos(u),l=i+n*Math.sin(u),t.lineTo(a,l)},M=Phaser.Utils.Objects.GetValue,L=function(){t(n,C);var s=e(n);function n(t,e){var i;return d(this,n),(i=s.call(this,t,"background")).setColor(M(e,"color",null),M(e,"color2",null),M(e,"horizontalGradient",!0)),i.setStroke(M(e,"stroke",null),M(e,"strokeThickness",2)),i.setCornerRadius(M(e,"cornerRadius",0),M(e,"cornerIteration",null)),i}return a(n,[{key:"color",get:function(){return this._color},set:function(t){t=x(t,this.canvas,this.context),this.setDirty(this._color!=t),this._color=t}},{key:"color2",get:function(){return this._color2},set:function(t){t=x(t,this.canvas,this.context),this.setDirty(this._color2!=t),this._color2=t}},{key:"horizontalGradient",get:function(){return this._horizontalGradient},set:function(t){this.setDirty(this._horizontalGradient!=t),this._horizontalGradient=t}},{key:"setColor",value:function(t,e,i){return void 0===i&&(i=!0),this.color=t,this.color2=e,this.horizontalGradient=i,this}},{key:"stroke",get:function(){return this._stroke},set:function(t){t=x(t,this.canvas,this.context),this.setDirty(this._stroke!=t),this._stroke=t}},{key:"strokeThickness",get:function(){return this._strokeThickness},set:function(t){this.setDirty(this._strokeThickness!=t),this._strokeThickness=t}},{key:"setStroke",value:function(t,e){return this.stroke=t,this.strokeThickness=e,this}},{key:"cornerRadius",get:function(){return this._cornerRadius},set:function(t){this.setDirty(this._cornerRadius!=t),this._cornerRadius=t}},{key:"cornerIteration",get:function(){return this._cornerIteration},set:function(t){this.setDirty(this._cornerIteration!=t),this._cornerIteration=t}},{key:"setCornerRadius",value:function(t,e){return this.cornerRadius=t,this.cornerIteration=e,this}},{key:"drawContent",value:function(){!function(t,e,i,s,n,r,h,o){if(null!=e||null!=i){var a=t.canvas.width,l=t.canvas.height;null==i&&(s=0);var u=s/2;a-=s,l-=s,w(t.canvas,t.context,u,u,a,l,n,e,i,s,r,h,o)}}(this.parent,this.color,this.stroke,this.strokeThickness,this.cornerRadius,this.color2,this.horizontalGradient,this.cornerIteration)}}]),n}(),F=Phaser.Utils.Objects.GetValue,I=function(){t(n,C);var s=e(n);function n(t,e){var i;return d(this,n),(i=s.call(this,t,"innerbounds")).setColor(F(e,"color",null),F(e,"color2",null),F(e,"horizontalGradient",!0)),i.setStroke(F(e,"stroke",null),F(e,"strokeThickness",2)),i}return a(n,[{key:"color",get:function(){return this._color},set:function(t){t=x(t,this.canvas,this.context),this.setDirty(this._color!=t),this._color=t}},{key:"color2",get:function(){return this._color2},set:function(t){t=x(t,this.canvas,this.context),this.setDirty(this._color2!=t),this._color2=t}},{key:"horizontalGradient",get:function(){return this._horizontalGradient},set:function(t){this.setDirty(this._horizontalGradient!=t),this._horizontalGradient=t}},{key:"setColor",value:function(t,e,i){return void 0===i&&(i=!0),this.color=t,this.color2=e,this.horizontalGradient=i,this}},{key:"stroke",get:function(){return this._stroke},set:function(t){t=x(t,this.canvas,this.context),this.setDirty(this._stroke!=t),this._stroke=t}},{key:"strokeThickness",get:function(){return this._strokeThickness},set:function(t){this.setDirty(this._strokeThickness!=t),this._strokeThickness=t}},{key:"setStroke",value:function(t,e){return this.stroke=t,this.strokeThickness=e,this}},{key:"drawContent",value:function(){var t=this.parent.padding,e=t.left,i=t.top,s=this.parent.width-t.left-t.right,n=this.parent.height-t.top-t.bottom,r=this.context;if(null!=this.color){var h,o;if(null!=this.color2)(o=this.horizontalGradient?r.createLinearGradient(0,0,s,0):r.createLinearGradient(0,0,0,n)).addColorStop(0,this.color),o.addColorStop(1,this.color2),h=o;else h=this.color;r.fillStyle=h,r.fillRect(e,i,s,n)}null!=this.stroke&&0<this.strokeThickness&&(r.strokeStyle=this.stroke,r.lineWidth=this.strokeThickness,r.strokeRect(e,i,s,n))}}]),n}(),U=Phaser.Utils.Objects.GetValue,V=function(){function e(t){d(this,e),this.set(t)}return a(e,[{key:"toJSON",value:function(){return{bold:this.bold,italic:this.italic,fontSize:this.fontSize,fontFamily:this.fontFamily,color:this.color,stroke:this.stroke,strokeThickness:this.strokeThickness,shaodwColor:this.shadowColor,shadowBlur:this.shadowBlur,shadowOffsetX:this.shadowOffsetX,shadowOffsetY:this.shadowOffsetY,offsetX:this.offsetX,offsetY:this.offsetY}}},{key:"set",value:function(t){this.setBold(U(t,"bold",!1)),this.setItalic(U(t,"italic",!1)),this.setFontSize(U(t,"fontSize","16px")),this.setFontFamily(U(t,"fontFamily","Courier")),this.setColor(U(t,"color","#fff")),this.setStrokeStyle(U(t,"stroke","#fff"),U(t,"strokeThickness",0)),this.setShadow(U(t,"shadowColor",null),U(t,"shadowOffsetX",0),U(t,"shadowOffsetY",0),U(t,"shadowBlur",0)),this.setOffset(U(t,"offsetX",0),U(t,"offsetY",0))}},{key:"modify",value:function(t){return t.hasOwnProperty("bold")&&this.setBold(t.bold),t.hasOwnProperty("italic")&&this.setItalic(t.italic),t.hasOwnProperty("fontSize")&&this.setFontSize(t.fontSize),t.hasOwnProperty("fontFamily")&&this.setFontFamily(t.fontFamily),t.hasOwnProperty("color")&&this.setColor(t.color),(t.hasOwnProperty("stroke")||t.hasOwnProperty("strokeThickness"))&&this.setStrokeStyle(m("stroke",t,this),m("strokeThickness",t,this)),(t.hasOwnProperty("shadowColor")||t.hasOwnProperty("shadowBlur")||t.hasOwnProperty("shadowOffsetX")||t.hasOwnProperty("shadowOffsetY"))&&this.setShadow(m("shadowColor",t,this),m("shadowOffsetX",t,this),m("shadowOffsetY",t,this),m("shadowBlur",t,this)),(t.hasOwnProperty("offsetX")||t.hasOwnProperty("offsetY"))&&this.setOffset(m("offsetX",t,this),m("offsetY",t,this)),this}},{key:"setBold",value:function(t){return void 0===t&&(t=!0),this.bold=t,this}},{key:"setItalic",value:function(t){return void 0===t&&(t=!0),this.italic=t,this}},{key:"fontStyle",get:function(){return this.bold&&this.italic?"bold italic":this.bold?"bold":this.italic?"italic":""}},{key:"fontSize",get:function(){return this._fontSize},set:function(t){"number"==typeof t&&(t="".concat(t,"px")),this._fontSize=t}},{key:"setFontSize",value:function(t){return this.fontSize=t,this}},{key:"setFontFamily",value:function(t){return this.fontFamily=t,this}},{key:"font",get:function(){return"".concat(this.fontStyle," ").concat(this.fontSize," ").concat(this.fontFamily)}},{key:"setColor",value:function(t){return this.color=x(t),this}},{key:"setStrokeStyle",value:function(t,e){return null==t&&(e=0),this.stroke=x(t),this.strokeThickness=e,this}},{key:"setShadow",value:function(t,e,i,s){return this.shadowColor=x(t),this.shadowOffsetX=e,this.shadowOffsetY=i,this.shaodwBlur=s,this}},{key:"setOffset",value:function(t,e){return this.offsetX=t,this.offsetY=e,this}},{key:"syncFont",value:function(t){return t.font=this.font,this}},{key:"syncStyle",value:function(t){return t.textBaseline="alphabetic",t.fillStyle=this.color,t.strokeStyle=this.stroke,t.lineWidth=this.strokeThickness,t.lineCap="round",t.lineJoin="round",this}},{key:"syncShadow",value:function(t){null!=t.shadowColor?(t.shadowColor=this.shadowColor,t.shadowOffsetX=this.shadowOffsetX,t.shadowOffsetY=this.shadowOffsetY,t.shadowBlur=this.shadowBlur):(t.shadowColor=0,t.shadowOffsetX=0,t.shadowOffsetY=0,t.shadowBlur=0)}},{key:"getTextMetrics",value:function(t,e){return this.syncFont(t).syncStyle(t),t.measureText(e)}}]),e}(),E=Phaser.Utils.Objects.GetValue,J=function(){t(r,C);var n=e(r);function r(t,e,i){var s;return d(this,r),(s=n.call(this,t,"text")).style=new V(i),s.setText(e),s}return a(r,[{key:"autoRound",get:function(){return this.parent.autoRound}},{key:"offsetX",get:function(){return this.style.offsetX},set:function(){}},{key:"offsetY",get:function(){return this.style.offsetY},set:function(){}},{key:"modifyStyle",value:function(t){return this.setDirty(!0),this.style.modify(t),this}},{key:"modifyPorperties",value:function(t){return t&&(this.modifyStyle(t),h(o(r.prototype),"modifyPorperties",this).call(this,t)),this}},{key:"setText",value:function(t){return this.setDirty(this.text!=t),this.text=t,this.updateTextSize(),this}},{key:"updateTextSize",value:function(){if("\n"===this.text||""===this.text)this.textWidth=0,this.textHeight=0;else{var t,e,i=this.style.getTextMetrics(this.context,this.text);this.textWidth=i.width,e=i.hasOwnProperty("actualBoundingBoxAscent")?(t=i.actualBoundingBoxAscent,i.actualBoundingBoxDescent):t=0,this.textHeight=t+e}return this}},{key:"width",get:function(){return this.textWidth*this.scaleX},set:function(t){0<this.textWidth?this.scaleX=t/this.textWidth:this.scaleX=1}},{key:"height",get:function(){return this.textHeight*this.scaleY},set:function(t){0<this.textHeight?this.scaleY=t/this.textHeight:this.scaleY=1}},{key:"drawContent",value:function(){var t=this.style;if(null!=t.color||null!=t.stroke){var e=this.context;t.syncFont(e).syncStyle(e),t.stroke&&t.strokeThickness&&(t.syncShadow(e),e.strokeText(this.text,0,0)),t.color&&(t.syncShadow(e),e.fillText(this.text,0,0))}}},{key:"draw",value:function(){if(!this.visible||""===this.text||"\n"===this.text)return this;h(o(r.prototype),"draw",this).call(this)}}]),r}(),N=function(){t(r,C);var n=e(r);function r(t,e,i){var s;return d(this,r),(s=n.call(this,t,"image")).setTexture(e,i),s}return a(r,[{key:"frameWidth",get:function(){return this.frameObj?this.frameObj.cutWidth:0}},{key:"frameHeight",get:function(){return this.frameObj?this.frameObj.cutHeight:0}},{key:"offsetY",get:function(){return-this.height},set:function(){}},{key:"setTexture",value:function(t,e){return this.key=t,this.frame=e,this.frameObj=this.scene.textures.getFrame(t,e),this}},{key:"width",get:function(){return this.frameWidth*this.scaleX},set:function(t){this.setDirty(this.width!==t),this.scaleX=t/this.frameWidth}},{key:"height",get:function(){return this.frameHeight*this.scaleY},set:function(t){this.setDirty(this.height!==t),this.scaleY=t/this.frameHeight}},{key:"setHeight",value:function(t,e){return void 0===e&&(e=!1),this.height=t,e&&(this.scaleX=this.scaleY),this}},{key:"drawContent",value:function(){var t=this.context,e=this.frameObj;t.drawImage(e.source.image,e.cutX,e.cutY,e.cutWidth,e.cutHeight)}},{key:"draw",value:function(){if(!this.visible)return this;h(o(r.prototype),"draw",this).call(this)}}]),r}(),q={left:0,center:1,right:2},K={top:0,center:1,bottom:2},Q=Phaser.Utils.Objects.GetValue,Z=function(t){var e=t[0];return"text"===e.type&&"\n"===e.text},$=Phaser.Utils.Objects.GetValue,tt=function(t){return"text"===t.type&&"\n"===t.text},et=Phaser.Utils.Array.GetAll,it={setPadding:function(t,e){var i,s,n,r,h=this.padding,o=h.left,a=h.right,l=h.top,u=h.bottom;return i=this.padding,n=e,"string"===(r=c(s=t))?i[s]=n:"number"===r?(i.left=s,i.right=s,i.top=s,i.bottom=s):(i.left=E(s,"left",0),i.right=E(s,"right",0),i.top=E(s,"top",0),i.bottom=E(s,"bottom",0)),this.dirty=this.dirty||o!=this.padding.left||a!=this.padding.right||l!=this.padding.top||u!=this.padding.bottom,this},getPadding:function(t){return e=this.padding,void 0===(i=t)?e:e[i];var e,i},sodifyTextStyle:function(t){return this.textStyle.modify(t),this},setText:function(t,e){void 0===t&&(t="");var i=this.children.length;return this.poolManager.freeMultiple(this.children),this.children.length=0,this.lastAppendedChildren.length=0,this.appendText(t,e),this.children.length!==i&&(this.dirty=!0),this},appendText:function(t,e){e&&this.textStyle.modify(e);for(var i=this.lastAppendedChildren.length=0,s=t.length;i<s;i++){var n=t.charAt(i),r=this.poolManager.allocate("text");null===r?r=new J(this,n,this.textStyle):r.setParent(this).setActive().modifyStyle(this.textStyle).setText(n),this.children.push(r),this.lastAppendedChildren.push(r)}return this},appendImage:function(t,e,i){var s=this.poolManager.allocate("frame");return null===s?s=new N(this,t,e):s.setParent(this).setActive().setTexture(t,e),s.modifyPorperties(i),this.lastAppendedChildren.length=0,this.children.push(s),this.lastAppendedChildren.push(s),this},setWrapConfig:function(t){return this.wrapConfig=t,this},runWordWrap:function(t){return t=b(t,this.wrapConfig),O.call(this,t)},runVerticalWrap:function(t){return t=b(t,this.wrapConfig),P.call(this,t)},drawContent:function(){var t,e=0<this.fixedWidth?this.fixedWidth:this.width,i=0<this.fixedHeight?this.fixedHeight:this.height;this.setSize(e,i),this.background.active&&this.background.draw();for(var s=0,n=this.children.length;s<n;s++)(t=this.children[s]).active&&t.draw();this.innerBounds.active&&this.innerBounds.draw()},getChildren:function(){return this.children},getLastAppendedChildren:function(){return this.lastAppendedChildren},getActiveChildren:function(){return et(this.children,"active",!0)}},st=function(){function t(){d(this,t),this.items=[]}return a(t,[{key:"destroy",value:function(){this.clear(),this.items=void 0}},{key:"pop",value:function(){return 0<this.items.length?this.items.pop():null}},{key:"push",value:function(t){return this.items.push(t),this}},{key:"pushMultiple",value:function(t){return this.items.push.apply(this.items,t),t.length=0,this}},{key:"clear",value:function(){return this.items.length=0,this}}]),t}(),nt=Phaser.Utils.Objects.GetFastValue,rt={},ht=function(){function e(t){d(this,e),this.pools=nt(t,"pools",rt)}return a(e,[{key:"free",value:function(t){if(!this.pools)return this;var e=t.type;return this.pools.hasOwnProperty(e)||(this.pools[e]=new st),this.pools[e].push(t),t.onFree(),this}},{key:"freeMultiple",value:function(t){if(!this.pools)return this;for(var e=0,i=t.length;e<i;e++)this.free(t[e]);return this}},{key:"allocate",value:function(t){return this.pools&&this.pools.hasOwnProperty(t)?this.pools[t].pop():null}}]),e}(),ot=Phaser.Utils.Objects.IsPlainObject,at=Phaser.Utils.Objects.GetValue,lt=function(){t(u,v);var l=e(u);function u(t,e,i,s,n,r){var h;d(this,u),ot(e)?(e=at(r=e,"x",0),i=at(r,"y",0),s=at(r,"width",0),n=at(r,"height",0)):ot(s)&&(s=at(r=s,"width",0),n=at(r,"height",0));var o=0===s?1:s,a=0===n?1:n;return(h=l.call(this,t,e,i,o,a)).type="rexDynamicCanvasText",h.autoRound=!0,h.padding={},h.textStyle=new V(at(r,"style",void 0)),h.background=new L(f(h),at(r,"background",void 0)),h.innerBounds=new I(f(h),at(r,"innerBounds",void 0)),h.children=[],h.lastAppendedChildren=[],h.poolManager=new ht(r),h.setFixedSize(s,n),h.setPadding(at(r,"padding",0)),h.setWrapConfig(at(r,"wrap",void 0)),h.setText(at(r,"text","")),h}return a(u,[{key:"setFixedSize",value:function(t,e){return void 0===t&&(t=0),void 0===e&&(e=0),0<t&&0<e&&this.fixedWidth===t&&this.fixedHeight===e||(this.dirty=!0),this.fixedWidth=t,this.fixedHeight=e,this}},{key:"updateTexture",value:function(){return this.clear(),this.drawContent(),h(o(u.prototype),"updateTexture",this).call(this),this}}]),u}();function ut(t,e,i,s,n){var r=new lt(this.scene,t,e,i,s,n);return this.scene.add.existing(r),r}Object.assign(lt.prototype,it);var ct=Phaser.Utils.Objects.GetAdvancedValue,dt=Phaser.GameObjects.BuildGameObject;function ft(t,e){void 0===t&&(t={}),void 0!==e&&(t.add=e);var i=ct(t,"width",1),s=ct(t,"height",1),n=new lt(this.scene,0,0,i,s,t);return dt(this.scene,n,t),n}function gt(t){return null==t||""===t||0===t.length}var yt=function(){t(s,Phaser.Plugins.BasePlugin);var i=e(s);function s(t){var e;return d(this,s),e=i.call(this,t),t.registerGameObject("rexDynamicText",ut,ft),e}return a(s,[{key:"start",value:function(){this.game.events.on("destroy",this.destroy,this)}}]),s}();return function(t,e,i){if("object"===c(t)){if(gt(e)){if(null==i)return;"object"===c(i)&&(t=i)}else{"string"==typeof e&&(e=e.split("."));var s=e.pop();(function(t,e,i){var s=t;if(!gt(e)){var n;"string"==typeof e&&(e=e.split("."));for(var r=0,h=e.length;r<h;r++){var o;if(null==s[n=e[r]]||"object"!==c(s[n]))o=r!==h-1||void 0===i?{}:i,s[n]=o;s=s[n]}}return s})(t,e)[s]=i}}}(window,"RexPlugins.GameObjects.DynamicText",lt),yt});
  