!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).rextagtextplugin=e()}(this,function(){"use strict";function h(t){return(h="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 f(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function i(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,i.key,i)}}function s(t,e,n){return e&&i(t.prototype,e),n&&i(t,n),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&&n(t,e)}function o(t){return(o=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function n(t,e){return(n=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function d(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function e(r){var a=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(t){return!1}}();return function(){var t,e,n,i=o(r);if(a){var s=o(this).constructor;t=Reflect.construct(i,arguments,s)}else t=i.apply(this,arguments);return e=this,!(n=t)||"object"!=typeof n&&"function"!=typeof n?d(e):n}}function r(t,e,n){return(r="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(t,e,n){var i=function(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=o(t)););return t}(t,e);if(i){var s=Object.getOwnPropertyDescriptor(i,e);return s.get?s.get.call(n):s.value}})(t,e,n||t)}function a(t){var e=v.create(this),n=e.getContext("2d");t.syncFont(e,n);var i=n.measureText(t.testString);if(i.hasOwnProperty("actualBoundingBoxAscent")&&i.hasOwnProperty("actualBoundingBoxDescent")){var s=i.actualBoundingBoxAscent,r=i.actualBoundingBoxDescent,a={ascent:s,descent:r,fontSize:s+r};return v.remove(e),a}var o=Math.ceil(i.width*t.baselineX),h=o,l=2*h;if(h=h*t.baselineY|0,e.width=o,e.height=l,n.fillStyle="#f00",n.fillRect(0,0,o,l),n.font=t._font,n.textBaseline="alphabetic",n.fillStyle="#000",n.fillText(t.testString,0,h),a={ascent:0,descent:0,fontSize:0},!n.getImageData(0,0,o,l))return a.ascent=h,a.descent=h+6,a.fontSize=a.ascent+a.descent,v.remove(e),a;var u,f,d=n.getImageData(0,0,o,l).data,c=d.length,p=4*o,y=0,g=!1;for(u=0;u<h;u++){for(f=0;f<p;f+=4)if(255!==d[y+f]){g=!0;break}if(g)break;y+=p}for(a.ascent=h-u,y=c-p,g=!1,u=l;h<u;u--){for(f=0;f<p;f+=4)if(255!==d[y+f]){g=!0;break}if(g)break;y-=p}return a.descent=u-h,a.fontSize=a.ascent+a.descent,v.remove(e),a}function T(t,e){var n=Array.isArray(t);if(void 0===e?e=n?[]:{}:function(t){if(Array.isArray(t))t.length=0;else for(var e in t)delete t[e]}(e),n){e.length=t.length;for(var i=0,s=t.length;i<s;i++)e[i]=t[i]}else for(var r in t)e[r]=t[r];return e}function l(){}function m(t,e,n,i,s){i<=0&&(n=q);var r=Q;if(Z.pushMultiple(r),!t||!t.length)return r;for(var a,o,h,l=t.split(K),u=0,f=l.length;u<f;u++)if(a=l[u],h=u===f-1?N:J,n!==q){var d,c;if(o=0===u?i-s:i,a.length<=100)if((x=e(a))<=o){r.push(Z.newline(a,x,h));continue}for(var p,y="",g="",v=0,w=0,k=(d=n===$?a.split(" "):a).length;w<k;w++)c=d[w],n===$?(y+=c,w<k-1&&(y+=" ")):y+=c,o<(p=e(y))&&(0===w?r.push(Z.newline("",0,E)):(r.push(Z.newline(g,v,E)),y=c,n===$&&w<k-1&&(y+=" "),p=e(y)),o=i),g=y,v=p;r.push(Z.newline(g,v,h))}else{var x=e(a);r.push(Z.newline(a,x,h))}return r}var u=Phaser.Renderer.WebGL.Utils,c={renderWebGL:function(t,e,n,i){if(0!==e.width&&0!==e.height){var s=e.frame,r=s.width,a=s.height,o=u.getTintAppendFloatAlpha,h=t.pipelines.set(this.pipeline,e),l=h.setTexture2D(s.glTexture,e);h.batchTexture(e,s.glTexture,r,a,e.x,e.y,r/e.style.resolution,a/e.style.resolution,e.scaleX,e.scaleY,e.rotation,e.flipX,e.flipY,e.scrollFactorX,e.scrollFactorY,e.displayOriginX,e.displayOriginY,0,0,r,a,o(e.tintTopLeft,n.alpha*e._alphaTL),o(e.tintTopRight,n.alpha*e._alphaTR),o(e.tintBottomLeft,n.alpha*e._alphaBL),o(e.tintBottomRight,n.alpha*e._alphaBR),e.tintFill,0,0,n,i,!1,l)}},renderCanvas:function(t,e,n,i){0!==e.width&&0!==e.height&&t.batchSprite(e,e.frame,n,i)}},v=Phaser.Display.Canvas.CanvasPool,p=0,y=1,g=2,w=0,k=1,x=2,S=/(?:\r\n|\r|\n)/,P=Phaser.Utils.Objects.GetAdvancedValue,O=Phaser.Utils.Objects.GetValue,M={backgroundColor:["backgroundColor",null],fontFamily:["fontFamily","Courier"],fontSize:["fontSize","16px"],fontStyle:["fontStyle",""],color:["color","#fff"],stroke:["stroke","#fff"],strokeThickness:["strokeThickness",0],shadowOffsetX:["shadow.offsetX",0],shadowOffsetY:["shadow.offsetY",0],shadowColor:["shadow.color","#000"],shadowBlur:["shadow.blur",0],shadowStroke:["shadow.stroke",!1],shadowFill:["shadow.fill",!1],underlineColor:["underline.color","#000"],underlineThickness:["underline.thickness",0],underlineOffset:["underline.offset",0],halign:["halign","left"],valign:["valign","top"],maxLines:["maxLines",0],fixedWidth:["fixedWidth",0],fixedHeight:["fixedHeight",0],resolution:["resolution",0],lineSpacing:["lineSpacing",0],rtl:["rtl",!1],testString:["testString","|MÃ‰qgy"],baselineX:["baselineX",1.2],baselineY:["baselineY",1.4],wrapMode:["wrap.mode",1],wrapWidth:["wrap.width",0]},b=function(){function i(t,e){f(this,i),this.parent=t,this.backgroundColor,this.fontFamily,this.fontSize,this.fontStyle,this.color,this.stroke,this.strokeThickness,this.shadowOffsetX,this.shadowOffsetY,this.shadowColor,this.shadowBlur,this.shadowStroke,this.shadowFill,this.underlineColor,this.underlineThickness,this.underlineOffset,this.halign,this.valign,this.maxLines,this.fixedWidth,this.fixedHeight,this.resolution,this.lineSpacing,this.rtl,this.testString,this.baselineX,this.baselineY,this._font,this.setStyle(e,!1);var n=O(e,"metrics",!1);this.metrics=n?{ascent:O(n,"ascent",0),descent:O(n,"descent",0),fontSize:O(n,"fontSize",0)}:a(this)}return s(i,[{key:"setStyle",value:function(t,e){if(void 0===e&&(e=!0),t&&t.hasOwnProperty("wrap")){var n=t.wrap;if(n.hasOwnProperty("mode")){var i=n.mode;"string"==typeof i&&(n.mode=F[i])}else n.hasOwnProperty("width")&&(n.mode=1)}for(var s in t&&t.hasOwnProperty("fontSize")&&"number"==typeof t.fontSize&&(t.fontSize=t.fontSize.toString()+"px"),M)this[s]=("wrapCallback"===s||"wrapCallbackScope"===s?O:P)(t,M[s][0],M[s][1]);var r=O(t,"font",null);this._font=null===r?this.fontStyle+" "+this.fontSize+" "+this.fontFamily:r;var a=O(t,"fill",null);return null!==a&&(this.color=a),e?this.update(!0):this.parent}},{key:"syncFont",value:function(t,e){e.font=this._font}},{key:"syncStyle",value:function(t,e){e.textBaseline="alphabetic",e.fillStyle=this.color,e.strokeStyle=this.stroke,e.lineWidth=this.strokeThickness,e.lineCap="round",e.lineJoin="round"}},{key:"syncShadow",value:function(t,e){e?(t.shadowOffsetX=this.shadowOffsetX,t.shadowOffsetY=this.shadowOffsetY,t.shadowColor=this.shadowColor,t.shadowBlur=this.shadowBlur):(t.shadowOffsetX=0,t.shadowOffsetY=0,t.shadowColor=0,t.shadowBlur=0)}},{key:"update",value:function(t){return t&&(this._font=this.fontStyle+" "+this.fontSize+" "+this.fontFamily,this.metrics=a(this)),this.parent.updateText(t)}},{key:"buildFont",value:function(){var t=this.fontStyle+" "+this.fontSize+" "+this.fontFamily;return t!==this._font&&(this._font=t),this}},{key:"setFont",value:function(t){return"string"==typeof t?(this.fontFamily=t,this.fontSize="",this.fontStyle=""):(this.fontFamily=O(t,"fontFamily","Courier"),this.fontSize=O(t,"fontSize","16px"),this.fontStyle=O(t,"fontStyle","")),this.update(!0)}},{key:"setFontFamily",value:function(t){return this.fontFamily=t,this.update(!0)}},{key:"setFontStyle",value:function(t){return this.fontStyle=t,this.update(!0)}},{key:"setFontSize",value:function(t){return"number"==typeof t&&(t=t.toString()+"px"),this.fontSize=t,this.update(!0)}},{key:"setTestString",value:function(t){return this.testString=t,this.update(!0)}},{key:"setFixedSize",value:function(t,e){return this.fixedWidth=t,this.fixedHeight=e,t&&(this.parent.width=t),e&&(this.parent.height=e),this.update(!1)}},{key:"setResolution",value:function(t){return this.resolution=t,this.update(!1)}},{key:"setLineSpacing",value:function(t){return this.lineSpacing=t,this.update(!1)}},{key:"setBackgroundColor",value:function(t){return this.backgroundColor=t,this.update(!1)}},{key:"setFill",value:function(t){return this.color=t,this.update(!1)}},{key:"setColor",value:function(t){return this.color=t,this.update(!1)}},{key:"setStroke",value:function(t,e){return void 0===t?this.strokeThickness=0:(void 0===e&&(e=this.strokeThickness),this.stroke=t,this.strokeThickness=e),this.update(!0)}},{key:"setShadow",value:function(t,e,n,i,s,r){return void 0===t&&(t=0),void 0===e&&(e=0),void 0===n&&(n="#000"),void 0===i&&(i=0),void 0===s&&(s=!1),void 0===r&&(r=!0),this.shadowOffsetX=t,this.shadowOffsetY=e,this.shadowColor=n,this.shadowBlur=i,this.shadowStroke=s,this.shadowFill=r,this.update(!1)}},{key:"setShadowOffset",value:function(t,e){return void 0===t&&(t=0),void 0===e&&(e=t),this.shadowOffsetX=t,this.shadowOffsetY=e,this.update(!1)}},{key:"setShadowColor",value:function(t){return void 0===t&&(t="#000"),this.shadowColor=t,this.update(!1)}},{key:"setShadowBlur",value:function(t){return void 0===t&&(t=0),this.shadowBlur=t,this.update(!1)}},{key:"setShadowStroke",value:function(t){return this.shadowStroke=t,this.update(!1)}},{key:"setShadowFill",value:function(t){return this.shadowFill=t,this.update(!1)}},{key:"setUnderline",value:function(t,e,n){return void 0===t&&(t="#000"),void 0===e&&(e=0),void 0===n&&(n=0),this.underlineColor=t,this.underlineThickness=e,this.underlineOffset=n,this.update(!1)}},{key:"setUnderlineColor",value:function(t){return void 0===t&&(t="#000"),this.underlineColor=t,this.update(!1)}},{key:"setUnderlineThickness",value:function(t){return void 0===t&&(t=0),this.underlineThickness=t,this.update(!1)}},{key:"setUnderlineOffset",value:function(t){return void 0===t&&(t=0),this.underlineOffset=t,this.update(!1)}},{key:"setWrapMode",value:function(t){return"string"==typeof t&&(t=F[t.toLowerCase()]||0),this.wrapMode=t,this.update(!0)}},{key:"setWrapWidth",value:function(t){return this.wrapWidth=t,this.update(!1)}},{key:"setAlign",value:function(t,e){return void 0===t&&(t="left"),void 0===e&&(e="top"),this.halign=t,this.valign=e,this.update(!1)}},{key:"setHAlign",value:function(t){return void 0===t&&(t="left"),this.halign=t,this.update(!1)}},{key:"setVAlign",value:function(t){return void 0===t&&(t="top"),this.valign=t,this.update(!1)}},{key:"setMaxLines",value:function(t){return void 0===t&&(t=0),this.maxLines=t,this.update(!1)}},{key:"getTextMetrics",value:function(){var t=this.metrics;return{ascent:t.ascent,descent:t.descent,fontSize:t.fontSize}}},{key:"toJSON",value:function(){var t={};for(var e in M)t[e]=this[e];return t.metrics=this.getTextMetrics(),t}},{key:"destroy",value:function(){this.parent=void 0}},{key:"lineHeight",get:function(){return this.metrics.fontSize+this.strokeThickness+this.lineSpacing}}]),i}(),F={none:w,word:k,char:x,character:x},C={draw:function(t,e,n,i){var s=this.penManager;this.hitAreaManager.clear();var r=this.context;r.save(),this.drawBackground(this.defatultStyle.backgroundColor);var a=this.defatultStyle;t+=this.startXOffset,e+=this.startYOffset;var o,h,l,u,f,d,c=a.halign,p=a.valign,y=a.lineHeight,g=s.lines,v=g.length,w=a.maxLines;u=(l=0<w&&w<v?(h=w,"center"===p?Math.floor((v-h)/2):"bottom"===p?v-h:0):(h=v,0))+h,d="center"===p?Math.max((i-h*y)/2,0):"bottom"===p?Math.max(i-h*y-2,0):0,d+=e;for(var k=l;k<u;k++)if(0!==(o=s.getLineWidth(k))){f="center"===c?(n-o)/2:"right"===c?n-o:0,f+=t;for(var x=g[k],T=0,m=x.length;T<m;T++)this.drawPen(x[T],f,d)}r.restore()},drawPen:function(t,e,n){e+=t.x,n+=t.y;var i=this.canvas,s=this.context;s.save();var r=this.parser.propToContextStyle(this.defatultStyle,t.prop);r.buildFont(),r.syncFont(i,s),r.syncStyle(i,s),0<r.underlineThickness&&0<t.width&&this.drawUnderline(e,n,t.width,r),t.isTextPen&&this.drawText(e,n,t.text,r),t.isImagePen&&this.drawImage(e,n,t.prop.img,r),s.restore(),t.hasAreaMarker&&0<t.width&&this.hitAreaManager.add(t.prop.area,e,n-this.startYOffset,t.width,this.defatultStyle.lineHeight)},clear:function(){var t=this.canvas;this.context.clearRect(0,0,t.width,t.height)},drawBackground:function(t){null!==t&&(this.context.fillStyle=t,this.context.fillRect(0,0,this.canvas.width,this.canvas.height))},drawUnderline:function(t,e,n,i){e+=i.underlineOffset-i.underlineThickness/2,this.autoRound&&(t=Math.round(t),e=Math.round(e));var s=this.context,r=s.lineCap;s.lineCap="butt",s.beginPath(),s.strokeStyle=i.underlineColor,s.lineWidth=i.underlineThickness,s.moveTo(t,e),s.lineTo(t+n,e),s.stroke(),s.lineCap=r},drawText:function(t,e,n,i){this.autoRound&&(t=Math.round(t),e=Math.round(e));var s=this.context;i.strokeThickness&&(i.syncShadow(s,i.shadowStroke),s.strokeText(n,t,e)),i.color&&"none"!==i.color&&(i.syncShadow(s,i.shadowFill),s.fillText(n,t,e))},drawImage:function(t,e,n){var i=this.parent.imageManager,s=i.get(n),r=i.getFrame(n);t+=s.left,e+=-this.startYOffset+s.y,this.autoRound&&(t=Math.round(t),e=Math.round(e)),this.context.drawImage(r.source.image,r.cutX,r.cutY,r.cutWidth,r.cutHeight,t,e,s.width,s.height)}},L=function(){function t(){f(this,t),this.items=[]}return s(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}(),W=Phaser.Utils.Objects.GetValue,z=p,_=y,A=function(){function e(t){f(this,e),this.prop={},this.resetFromJSON(t)}return s(e,[{key:"resetFromJSON",value:function(t){this.text=W(t,"text",""),this.x=W(t,"x",0),this.y=W(t,"y",0),this.width=W(t,"width",0);var e=W(t,"prop",null);null===e&&(e={}),this.prop=e,this.newLineMode=W(t,"newLineMode",0),this.startIndex=W(t,"startIndex",0)}},{key:"plainText",get:function(){var t=this.text;return this.newLineMode===_&&(t+="\n"),t}},{key:"wrapText",get:function(){var t=this.text;return this.newLineMode!==z&&(t+="\n"),t}},{key:"rawTextLength",get:function(){var t=this.text.length;return this.newLineMode===_&&(t+=1),t}},{key:"endIndex",get:function(){return this.startIndex+this.rawTextLength}},{key:"lastX",get:function(){return this.x+this.width}},{key:"isTextPen",get:function(){return""!==this.text}},{key:"isImagePen",get:function(){return!!this.prop.img}},{key:"hasAreaMarker",get:function(){return!!this.prop.area}}]),e}(),B=Phaser.Utils.Objects.GetFastValue,I=p,R=g,j=new L,X=new L,Y=function(){function o(t){f(this,o),this.pens=[],this.lines=[],this.maxLinesWidth=void 0,this.PensPool=B(t,"pensPool",j),this.LinesPool=B(t,"linesPool",X),this.tagToText=B(t,"tagToText",l),this.tagToTextScope=B(t,"tagToTextScope",void 0)}return s(o,[{key:"destroy",value:function(){this.freePens(),this.tagToText=void 0,this.tagToTextScope=void 0}},{key:"freePens",value:function(){for(var t=0,e=this.lines.length;t<e;t++)this.lines[t].length=0;this.PensPool.pushMultiple(this.pens),this.LinesPool.pushMultiple(this.lines),this.maxLinesWidth=void 0}},{key:"addTextPen",value:function(t,e,n,i,s,r){var a=this.PensPool.pop();return null==a&&(a=new A),H.text=t,H.x=e,H.y=n,H.width=i,H.prop=s,H.newLineMode=r,a.resetFromJSON(H),this.addPen(a),this}},{key:"addImagePen",value:function(t,e,n,i){return this.addTextPen("",t,e,n,i,I),this}},{key:"addNewLinePen",value:function(){var t=this.lastPen,e=t?t.lastX:0,n=t?t.y:0,i=t?T(t.prop):null;return this.addTextPen("",e,n,0,i,R),this}},{key:"addPen",value:function(t){var e=this.lastPen;t.startIndex=null==e?0:e.endIndex,this.pens.push(t);var n=this.lastLine;null==n&&(n=this.LinesPool.pop()||[],this.lines.push(n)),n.push(t),t.newLineMode!==I&&(n=this.LinesPool.pop()||[],this.lines.push(n)),this.maxLinesWidth=void 0}},{key:"clone",value:function(t){null==t&&(t=new o),t.freePens();for(var e=0,n=this.lines.length;e<n;e++)for(var i=this.lines[e],s=0,r=i.length;s<r;s++){var a=i[s];t.addPen(a.text,a.x,a.y,a.width,T(a.prop),a.newLineMode)}return t}},{key:"getLineStartIndex",value:function(t){if(t>=this.lines.length)return this.getLineEndIndex(t);var e=this.lines[t];return e&&e[0]?e[0].startIndex:0}},{key:"getLineEndIndex",value:function(t){t>=this.lines.length&&(t=this.lines.length-1);var e,n,i=!1;for(e=t;0<=e&&!(i=null!=(n=this.lines[e])&&0<n.length);e--);return i?n[n.length-1].endIndex:0}},{key:"getLineWidth",value:function(t){var e=this.lines[t];if(!e)return 0;var n=e[e.length-1];return null==n?0:n.lastX}},{key:"getMaxLineWidth",value:function(){if(void 0!==this.maxLinesWidth)return this.maxLinesWidth;for(var t,e=0,n=0,i=this.lines.length;n<i;n++)e<(t=this.getLineWidth(n))&&(e=t);return this.maxLinesWidth=e}},{key:"getLineWidths",value:function(){for(var t=[],e=0,n=this.lines.length;e<n;e++)t.push(this.getLineWidth(e));return t}},{key:"getSliceTagText",value:function(t,e,n){if(void 0===t&&(t=0),void 0===e){var i=this.lastPen;if(null==i)return"";e=i.endIndex}void 0===n&&(n=!1);for(var s,r,a,o,h,l,u="",f=0,d=this.pens.length;f<d&&((o=(s=this.pens[f]).endIndex)<=t||(s=this.pens[f],r=n?s.wrapText:s.plainText,h=s.prop,t<=(a=s.startIndex)&&o<=e||(r=r.substring(t-a,e-a)),this.tagToTextScope?u+=this.tagToText.call(this.tagToTextScope,r,h,l):u+=this.tagToText(r,h,l),l=h,!(e<=o)));f++);return u}},{key:"lastPen",get:function(){return this.pens[this.pens.length-1]}},{key:"lastLine",get:function(){return this.lines[this.lines.length-1]}},{key:"linesCount",get:function(){return this.lines.length}},{key:"plainText",get:function(){for(var t="",e=this.pens,n=0,i=e.length;n<i;n++)t+=e[n].plainText;return t}},{key:"rawTextLength",get:function(){for(var t=0,e=this.pens,n=0,i=this.pens.length;n<i;n++)t+=e[n].rawTextLength;return t}}]),o}(),H={},G=Phaser.Geom.Rectangle,D=new L,U=function(){function t(){f(this,t),this.hitAreas=[]}return s(t,[{key:"destroy",value:function(){this.clear()}},{key:"clear",value:function(){return D.pushMultiple(this.hitAreas),this}},{key:"add",value:function(t,e,n,i,s){var r=D.pop();return null===r?r=new G(e,n,i,s):r.setTo(e,n,i,s),r.key=t,this.hitAreas.push(r),this}},{key:"getFirstHitArea",value:function(t,e){for(var n,i=this.hitAreas,s=0,r=i.length;s<r;s++)if((n=i[s]).contains(t,e))return n;return null}},{key:"drawBounds",value:function(t,e,n){void 0===e&&(e=16777215),n&&t.save().scaleCanvas(n.scaleX,n.scaleY).rotateCanvas(n.rotation).translateCanvas(n.x,n.y);for(var i,s=this.hitAreas,r=0,a=s.length;r<a;r++)i=s[r],t.lineStyle(1,e).strokeRect(i.x,i.y,i.width,i.height);return n&&t.restore(),this}}]),t}(),V=function(t,e,n,i){var s=this.hitAreaManager.getFirstHitArea(n,i);if(null!==s){var r=s.key;this.parent.emit("".concat(t,"-").concat(r),e,n,i),this.parent.emit(t,r,e,n,i)}},N=p,J=y,E=g,q=w,$=k,K=S,Q=[],Z=new L;Z.newline=function(t,e,n){var i=this.pop();return null===i&&(i={}),i.text=t,i.width=e,i.newLineMode=n,i};var tt=Phaser.Utils.Objects.GetValue,et=w,nt=p,it=function(){function n(t){f(this,n),this.parent=t.parent,this.context=tt(t,"context",null),this.canvas=this.context.canvas,this.parser=tt(t,"parser",null),this.defatultStyle=tt(t,"style",null),this.autoRound=!0,this.pensPool=tt(t,"pensPool",null),this.penManager=this.newPenManager(),this._tmpPenManager=null,this.hitAreaManager=new U;var e=this.context;this.getTextWidth=function(t){return e.measureText(t).width}}return s(n,[{key:"destroy",value:function(){this.context=void 0,this.canvas=void 0,this.parser=void 0,this.defatultStyle=void 0,this.penManager&&(this.penManager.destroy(),this.penManager=void 0),this._tmpPenManager&&(this._tmpPenManager.destroy(),this._tmpPenManager=void 0),this.hitAreaManager&&(this.hitAreaManager.destroy(),this.hitAreaManager=void 0)}},{key:"updatePenManager",value:function(t,e,n,i,s){if(void 0===s&&(s=this.penManager),s.freePens(),""===t)return s;for(var r,a,o,h,l,u=this.canvas,f=this.context,d=0,c=0,p=this.parser.splitText(t),y=0,g=p.length;y<g;y++)if(r=(h=this.parser.tagTextToProp(p[y],a)).plainText,(a=h.prop).img){var v=this.imageManager.getOuterWidth(a.img);0<n&&e!==et&&n<d+v&&(s.addNewLinePen(),c+=i,d=0),s.addImagePen(d,c,v,T(a)),d+=v}else if(""!==r){var w;this.context.save(),(o=this.parser.propToContextStyle(this.defatultStyle,a)).buildFont(),o.syncFont(u,f),o.syncStyle(u,f);for(var k=0,x=(l=m(r,this.getTextWidth,e,n,d)).length;k<x;k++)w=l[k],s.addTextPen(w.text,d,c,w.width,T(a),w.newLineMode),w.newLineMode!==nt?(d=0,c+=i):d+=w.width;this.context.restore()}return s}},{key:"newPenManager",value:function(){return new Y({pensPool:this.pensPool,tagToText:this.parser.propToTagText,tagToTextScope:this.parser})}},{key:"getPlainText",value:function(t,e,n){var i;if(null==t)i=this.penManager.plainText;else{var s=this.parser.splitText(t,1);i="";for(var r=0,a=s.length;r<a;r++)i+=s[r]}return null==e&&null==n||(null==e&&(e=0),null==n&&(n=i.length),i=i.substring(e,n)),i}},{key:"getPenManager",value:function(t,e){if(void 0===t)return this.copyPenManager(e,this.penManager);void 0===e&&(e=this.newPenManager());var n=this.defatultStyle;return this.updatePenManager(t,n.wrapMode,n.wrapWidth,n.lineHeight,e),e}},{key:"getText",value:function(t,e,n,i){if(null==t)return this.penManager.getSliceTagText(e,n,i);var s=this.tmpPenManager,r=this.defatultStyle;return this.updatePenManager(t,r.wrapMode,r.wrapWidth,r.lineHeight,s),s.getSliceTagText(e,n,i)}},{key:"copyPenManager",value:function(t,e){return void 0===e&&(e=this.penManager),e.copy(t)}},{key:"getTextWidth",value:function(t){return void 0===t&&(t=this.penManager),t.getMaxLineWidth()}},{key:"getLastPen",value:function(t){return void 0===t&&(t=this.penManager),t.lastPen}},{key:"startXOffset",get:function(){return this.defatultStyle.strokeThickness/2}},{key:"startYOffset",get:function(){var t=this.defatultStyle;return t.strokeThickness/2+t.metrics.ascent}},{key:"lines",get:function(){return this.penManager.lines}},{key:"desplayLinesCount",get:function(){var t=this.penManager.linesCount,e=this.defatultStyle.maxLines;return 0<e&&e<t&&(t=e),t}},{key:"linesWidth",get:function(){return this.penManager.getMaxLineWidth()}},{key:"linesHeight",get:function(){var t=this.desplayLinesCount,e=this.defatultStyle.lineHeight*t;return 0<t&&(e-=this.defatultStyle.lineSpacing),e}},{key:"imageManager",get:function(){return this.parent.imageManager}},{key:"tmpPenManager",get:function(){return null===this._tmpPenManager&&(this._tmpPenManager=this.newPenManager()),this._tmpPenManager}}]),n}(),st={setInteractive:function(){this.parent.on("pointerdown",function(t,e,n,i){V.call(this,"areadown",t,e,n)},this).on("pointerup",function(t,e,n,i){V.call(this,"areaup",t,e,n)},this)}};Object.assign(it.prototype,C,st);var rt,at=Phaser.Utils.Objects.GetValue,ot=function(){function e(t){f(this,e),this.textureManager=t,this.images={}}return s(e,[{key:"add",value:function(t,e){if("string"==typeof t)this._add(t,e);else if(Array.isArray(t))for(var n=0,i=(s=t).length;n<i;n++)this._add(s[n]);else{var s=t;for(var t in s)this._add(t,s[t])}return this}},{key:"_add",value:function(t,e){void 0===e&&(e={key:t});var n=e.key,i=e.frame,s=e.width,r=e.height;if(void 0===s||void 0===r){var a=this.textureManager.getFrame(n,i),o=a?a.cutWidth:0,h=a?a.cutHeight:0;void 0===s&&void 0===r?(s=o,r=h):void 0===s?s=o*(r/h):void 0===r&&(r=h*(s/o))}this.images[t]={key:n,frame:i,width:s,height:r,y:at(e,"y",0),left:at(e,"left",0),right:at(e,"right",0)}}},{key:"remove",value:function(t){return this.images.hasOwnProperty(t)&&delete this.images[t],this}},{key:"get",value:function(t){return this.images.hasOwnProperty(t)||this.textureManager.exists(t)&&this.add(t),this.images[t]}},{key:"getOuterWidth",value:function(t){var e=this.get(t);return e?e.width+e.left+e.right:0}},{key:"getFrame",value:function(t){var e=this.get(t);return e?this.textureManager.getFrame(e.key,e.frame):void 0}},{key:"hasTexture",value:function(t){return!!this.getFrame(t)}}]),e}();var ht=Phaser.DOM.AddToDOM,lt=Phaser.Display.Canvas.CanvasPool,ut=Phaser.GameObjects.GameObject,ft=Phaser.Utils.Objects.GetValue,dt=Phaser.DOM.RemoveFromDOM,ct=S,pt={},yt=function(){t(u,ut);var l=e(u);function u(t,e,n,i,s,r,a){var o;if(f(this,u),void 0===e&&(e=0),void 0===n&&(n=0),(o=l.call(this,t,r)).renderer=t.sys.game.renderer,o.setPosition(e,n),o.setOrigin(0,0),o.initPipeline(),o.canvas=lt.create(d(o)),o.context=o.canvas.getContext("2d"),s){if(s.hasOwnProperty("align")){var h=s.align;delete s.align,s.halign=h}s.hasOwnProperty("stroke")&&!s.hasOwnProperty("strokeThickness")&&(s.strokeThickness=1)}return o.style=new b(d(o),s),o.autoRound=!0,o._text=void 0,o.padding={left:0,right:0,top:0,bottom:0},o.width=1,o.height=1,o.dirty=!1,0===o.style.resolution&&(o.style.resolution=1),o._crop=o.resetCropObject(),o.texture=t.sys.textures.addCanvas(null,o.canvas,!0),o.frame=o.texture.get(),o.frame.source.resolution=o.style.resolution,o.renderer.gl&&(o.renderer.deleteTexture(o.frame.source.glTexture),o.frame.source.glTexture=null),pt.hasOwnProperty(r)||(pt[r]=new L),o.canvasText=new it({parent:d(o),context:o.context,parser:a,style:o.style,pensPool:pt[r]}),s&&s.padding&&o.setPadding(s.padding),o.setText(i),t.sys.game.events.on("contextrestored",function(){this.dirty=!0},d(o)),o}return s(u,[{key:"initRTL",value:function(){this.style.rtl&&(this.canvas.dir="rtl",this.context.direction="rtl",this.canvas.style.display="none",ht(this.canvas,this.scene.sys.canvas),this.originX=1)}},{key:"setText",value:function(t){return t||0===t||(t=""),Array.isArray(t)&&(t=t.join("\n")),t!==this._text&&(this._text=t.toString(),this.updateText()),this}},{key:"setStyle",value:function(t){return this.style.setStyle(t)}},{key:"setFont",value:function(t){return this.style.setFont(t)}},{key:"setFontFamily",value:function(t){return this.style.setFontFamily(t)}},{key:"setFontSize",value:function(t){return this.style.setFontSize(t)}},{key:"setFontStyle",value:function(t){return this.style.setFontStyle(t)}},{key:"setFixedSize",value:function(t,e){return this.style.setFixedSize(t,e)}},{key:"setBackgroundColor",value:function(t){return this.style.setBackgroundColor(t)}},{key:"setFill",value:function(t){return this.style.setFill(t)}},{key:"setColor",value:function(t){return this.style.setColor(t)}},{key:"setStroke",value:function(t,e){return this.style.setStroke(t,e)}},{key:"setShadow",value:function(t,e,n,i,s,r){return this.style.setShadow(t,e,n,i,s,r)}},{key:"setShadowOffset",value:function(t,e){return this.style.setShadowOffset(t,e)}},{key:"setShadowColor",value:function(t){return this.style.setShadowColor(t)}},{key:"setShadowBlur",value:function(t){return this.style.setShadowBlur(t)}},{key:"setShadowStroke",value:function(t){return this.style.setShadowStroke(t)}},{key:"setShadowFill",value:function(t){return this.style.setShadowFill(t)}},{key:"setWrapMode",value:function(t){return this.style.setWrapMode(t)}},{key:"setWrapWidth",value:function(t){return this.style.setWrapWidth(t)}},{key:"setAlign",value:function(t){return this.style.setHAlign(t)}},{key:"setLineSpacing",value:function(t){return this.style.setLineSpacing(t)}},{key:"setPadding",value:function(t,e,n,i){if("object"===h(t)){var s=t,r=ft(s,"x",null);n=null!==r?t=r:(t=ft(s,"left",0),ft(s,"right",t));var a=ft(s,"y",null);i=null!==a?e=a:(e=ft(s,"top",0),ft(s,"bottom",e))}else void 0===t&&(t=0),void 0===e&&(e=t),void 0===n&&(n=t),void 0===i&&(i=e);return this.padding.left=t,this.padding.top=e,this.padding.right=n,this.padding.bottom=i,this.updateText(!1)}},{key:"setResolution",value:function(t){return this.style.setResolution(t)}},{key:"setMaxLines",value:function(t){return this.style.setMaxLines(t)}},{key:"updateText",value:function(t){void 0===t&&(t=!0);var e=this.canvasText,n=this.style;t&&e.updatePenManager(this._text,n.wrapMode,n.wrapWidth,n.lineHeight);var i,s,r=this.padding;0===n.fixedWidth?(this.width=e.linesWidth+r.left+r.right,i=e.linesWidth):(this.width=n.fixedWidth,(i=this.width-r.left-r.right)<e.linesWidth&&(i=e.linesWidth)),0===n.fixedHeight?(this.height=e.linesHeight+r.top+r.bottom,s=e.linesHeight):(this.height=n.fixedHeight,(s=this.height-r.top-r.bottom)<e.linesHeight&&(s=e.linesHeight));var a=this.width,o=this.height;this.updateDisplayOrigin();var h=n.resolution;a*=h,o*=h,a=Math.max(Math.ceil(a),1),o=Math.max(Math.ceil(o),1);var l=this.canvas,u=this.context;l.width!==a||l.height!==o?(l.width=a,l.height=o,this.frame.setSize(a,o)):u.clearRect(0,0,a,o),u.save(),u.scale(h,h),e.draw(r.left,r.top,i,s),u.restore(),this.renderer.gl&&(this.frame.source.glTexture=this.renderer.canvasToTexture(l,this.frame.source.glTexture,!0),this.frame.glTexture=this.frame.source.glTexture),this.dirty=!0;var f=this.input;return f&&!f.customHitArea&&(f.hitArea.width=this.width,f.hitArea.height=this.height),this}},{key:"getTextMetrics",value:function(){return this.style.getTextMetrics()}},{key:"toJSON",value:function(){var t=gt.ToJSON(this),e={autoRound:this.autoRound,text:this._text,style:this.style.toJSON(),resolution:this.resolution,padding:{left:this.padding.left,right:this.padding.right,top:this.padding.top,bottom:this.padding.bottom}};return t.data=e,t}},{key:"preDestroy",value:function(){this.style.rtl&&dt(this.canvas),lt.remove(this.canvas),this.canvasText.destroy()}},{key:"setInteractive",value:function(t,e,n){return ut.prototype.setInteractive.call(this,t,e,n),this.canvasText.setInteractive(),this}},{key:"getWrappedText",value:function(t,e,n){return(t=this.canvasText.getText(t,e,n,!0)).split(ct)}},{key:"getPlainText",value:function(t,e,n){return this.canvasText.getPlainText(t,e,n)}},{key:"getText",value:function(t,e,n){return this.canvasText.getText(t,e,n,!1)}},{key:"getSubString",value:function(t,e,n){return this.getText(t,e,n)}},{key:"copyPenManager",value:function(t){return this.canvasText.copyPenManager(t)}},{key:"getPenManager",value:function(t,e){return this.canvasText.getPenManager(t,e)}},{key:"setSize",value:function(t,e){return this.setFixedSize(t,e)}},{key:"resize",value:function(t,e){return this.setFixedSize(t,e)}},{key:"addImage",value:function(t,e){return this.imageManager.add(t,e),this}},{key:"drawAreaBounds",value:function(t,e){return this.canvasText.hitAreaManager.drawBounds(t,e,this),this}},{key:"text",set:function(t){this.setText(t)},get:function(){return this._text}},{key:"lineSpacing",set:function(t){this.setLineSpacing(t)},get:function(){return this.style.lineSpacing}},{key:"imageManager",get:function(){return t=this.scene.textures,void 0===rt&&(rt=new ot(t)),rt;var t}}]),u}(),gt=Phaser.GameObjects.Components;Phaser.Class.mixin(yt,[gt.Alpha,gt.BlendMode,gt.ComputedSize,gt.Crop,gt.Depth,gt.Flip,gt.GetBounds,gt.Mask,gt.Origin,gt.Pipeline,gt.ScrollFactor,gt.Tint,gt.Transform,gt.Visible,c]);var vt={plainText:null,prevProp:null},wt=new b,kt=function(){function e(t){f(this,e),void 0===t&&(t={}),this.tags=t}return s(e,[{key:"addTag",value:function(t,e){this.tags[t]=e}},{key:"splitText",value:function(t,e){for(var n=[],i=0;;){var s=mt.exec(t);if(!s){var r=t.length;return i<r&&n.push(t.substring(i,r)),n}var a=s[0],o=mt.lastIndex-a.length;if(i<o&&n.push(t.substring(i,o)),void 0===e)n.push(a);else if(1===e)if(St.test(a)){var h=a.match(Pt);n.push(h[2])}else if(Ot.test(a)){h=a.match(Mt);n.push(h[2])}i=mt.lastIndex}}},{key:"tagTextToProp",value:function(t){var e,n;if(St.test(t)){if(null!=(r=t.match(Pt))){var i=r[1],s=this.tags;(n=s.hasOwnProperty(i)?s[i]:{})._class=i,e=r[2]}}else if(Ot.test(t)){var r;if(null!=(r=t.match(Mt))){var a=r[1];(n=xt(a))._style=a,e=r[2]}}null==e&&(e=t),null==n&&(n={});var o=vt;return o.plainText=e,o.prop=n,o}},{key:"propToContextStyle",value:function(t,e){var n=wt;if(e.hasOwnProperty("img"))n.image=e.img;else{if(n.image=null,e.hasOwnProperty("family")||e.hasOwnProperty("fontFamily")||e.hasOwnProperty("font-family")){var i=e.hasOwnProperty("family")?e.family:e.hasOwnProperty("fontFamily")?e.fontFamily:e["font-family"];n.fontFamily=i}else n.fontFamily=t.fontFamily;if(e.hasOwnProperty("size")||e.hasOwnProperty("fontSize")||e.hasOwnProperty("font-size")){var s=e.hasOwnProperty("size")?e.size:e.hasOwnProperty("fontSize")?e.fontSize:e["font-size"];"number"==typeof s&&(s=s.toString()+"px"),n.fontSize=s}else n.fontSize=t.fontSize;if(e.hasOwnProperty("style")||e.hasOwnProperty("fontStyle")||e.hasOwnProperty("font-style")){var r=e.hasOwnProperty("style")?e.style:e.hasOwnProperty("fontStyle")?e.fontStyle:e["font-style"];n.fontStyle=r}else n.fontStyle=t.fontStyle;if(e.hasOwnProperty("color")||e.hasOwnProperty("font-color")){var a=e.hasOwnProperty("color")?e.color:e["font-color"];n.color=a}else n.color=t.color;if(e.hasOwnProperty("stroke")){var o=e.stroke;n.stroke=o.hasOwnProperty("color")?o.color:t.stroke,n.strokeThickness=o.hasOwnProperty("thinkness")?o.thinkness:t.strokeThickness}else n.stroke=t.stroke,n.strokeThickness=t.strokeThickness}if(e.hasOwnProperty("shadow")){var h=e.shadow;n.shadowColor=h.hasOwnProperty("color")?h.color:t.shadowColor,n.shadowOffsetX=h.hasOwnProperty("offsetX")?h.offsetX:t.shadowOffsetX,n.shadowOffsetY=h.hasOwnProperty("offsetY")?h.offsetY:t.shadowOffsetY,n.shadowBlur=h.hasOwnProperty("blur")?h.blur:t.shadowBlur,n.shadowStroke=!0,n.shadowFill=!0}else n.shadowColor=t.shadowColor,n.shadowOffsetX=t.shadowOffsetX,n.shadowOffsetY=t.shadowOffsetY,n.shadowBlur=t.shadowBlur,n.shadowStroke=t.shadowStroke,n.shadowFill=t.shadowFill;if(e.hasOwnProperty("u")||e.hasOwnProperty("underline")){var l=e.hasOwnProperty("u")?e.u:e.underline;n.underlineColor=l.hasOwnProperty("color")?l.color:t.underlineColor,n.underlineThickness=l.hasOwnProperty("thinkness")?l.thinkness:t.underlineThickness,n.underlineOffset=l.hasOwnProperty("offset")?l.offset:t.underlineOffset}else n.underlineColor=t.underlineColor,n.underlineThickness=t.underlineThickness,n.underlineOffset=t.underlineOffset;return n}},{key:"propToTagText",value:function(t,e){return e.hasOwnProperty("_class")?""===t&&this.isTextTag(e._class)?"":"<class='"+e._class+"'>"+t+"</class>":e.hasOwnProperty("_style")?"<style='"+e._style+"'>"+t+"</style>":void 0}},{key:"destroy",value:function(){this.tags=void 0}},{key:"isTextTag",value:function(t){var e=this.tags[t];return!!e&&null==e.img}}]),e}(),xt=function(t){for(var e,n,i,s={},r=0,a=(t=t.split(";")).length;r<a;r++)if(n=(e=t[r].split(":"))[0],i=e[1],!Tt(n)&&!Tt(i)){switch(n){case"stroke":var o=i.split(" ");i={},1<=(l=o.length)&&(i.color=o[0]),2<=l&&(i.thinkness=parseInt(o[1].replace("px","")));break;case"shadow":var h=i.split(" ");i={},1<=(l=h.length)&&(i.color=h[0]),2<=l&&(i.offsetX=parseInt(h[1].replace("px",""))),3<=l&&(i.offsetY=parseInt(h[2].replace("px",""))),4<=l&&(i.blur=parseInt(h[3].replace("px","")));break;case"u":case"underline":var l,u=i.split(" ");i={},1<=(l=u.length)&&(i.color=u[0]),2<=l&&(i.thinkness=parseInt(u[1].replace("px",""))),3<=l&&(i.offset=parseInt(u[2].replace("px","")))}s[n]=i}return s},Tt=function(t){return 0===(t=t.replace(bt,"")).length},mt=/<\s*class=["|']([^"|']+)["|']\s*\>([\s\S]*?)<\s*\/class\s*\>|<\s*style=["|']([^"|']+)["|']\s*\>([\s\S]*?)<\s*\/style\s*\>/g,St=/<\s*class=/i,Pt=/<\s*class=["|']([^"|']+)["|']\s*\>([\s\S]*?)<\s*\/class\s*\>/,Ot=/<\s*style=/i,Mt=/<\s*style=["|']([^"|']+)["|']\s*\>([\s\S]*?)<\s*\/style\s*\>/,bt=/^\s+|\s+$/,Ft=Phaser.Utils.Objects.GetValue,Ct=function(){t(l,yt);var h=e(l);function l(t,e,n,i,s){var r;f(this,l);var a=Ft(s,"tags",void 0),o=new kt(a);return(r=h.call(this,t,e,n,i,s,"rexTagText",o)).parser=o,r}return s(l,[{key:"addTag",value:function(t,e){return this.parser.addTag(t,e),this.updateText(!0)}},{key:"addTags",value:function(t){for(var e in t)this.parser.addTag(e,t[e]);return this.updateText(!0)}},{key:"preDestroy",value:function(){r(o(l.prototype),"preDestroy",this).call(this),this.parser.destroy(),this.parser=void 0}}]),l}();function Lt(t,e,n,i){var s=new Ct(this.scene,t,e,n,i);return this.scene.add.existing(s),s}var Wt=Phaser.Utils.Objects.GetAdvancedValue,zt=Phaser.GameObjects.BuildGameObject;function _t(t,e){void 0===t&&(t={}),void 0!==e&&(t.add=e);var n=Wt(t,"text",""),i=Wt(t,"style",null),s=Wt(t,"padding",null);null!==s&&(i.padding=s);var r=new Ct(this.scene,0,0,n,i);return zt(this.scene,r,t),r.autoRound=Wt(t,"autoRound",!0),r}function At(t){return null==t||""===t||0===t.length}var Bt=function(){t(i,Phaser.Plugins.BasePlugin);var n=e(i);function i(t){var e;return f(this,i),e=n.call(this,t),t.registerGameObject("rexTagText",Lt,_t),e}return s(i,[{key:"start",value:function(){this.game.events.on("destroy",this.destroy,this)}}]),i}();return function(t,e,n){if("object"===h(t)){if(At(e)){if(null==n)return;"object"===h(n)&&(t=n)}else{"string"==typeof e&&(e=e.split("."));var i=e.pop();(function(t,e,n){var i=t;if(!At(e)){var s;"string"==typeof e&&(e=e.split("."));for(var r=0,a=e.length;r<a;r++){var o;if(null==i[s=e[r]]||"object"!==h(i[s]))o=r!==a-1||void 0===n?{}:n,i[s]=o;i=i[s]}}return i})(t,e)[i]=n}}}(window,"RexPlugins.GameObjects.TagText",Ct),Bt});
