text: !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).rexbbcodetext=e()}(this,function(){"use strict";function o(t){return(o="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 n(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function s(t,e,i){return e&&n(t.prototype,e),i&&n(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 h(t){return(h=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 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,i,n=h(r);if(a){var s=h(this).constructor;t=Reflect.construct(n,arguments,s)}else t=n.apply(this,arguments);return e=this,!(i=t)||"object"!=typeof i&&"function"!=typeof i?f(e):i}}function r(t){var e=p.create(this),i=e.getContext("2d");t.syncFont(e,i);var n=Math.ceil(i.measureText(t.testString).width*t.baselineX),s=n,r=2*s;s=s*t.baselineY|0,e.width=n,e.height=r,i.fillStyle="#f00",i.fillRect(0,0,n,r),i.font=t._font,i.textBaseline="alphabetic",i.fillStyle="#000",i.fillText(t.testString,0,s);var a={ascent:0,descent:0,fontSize:0};if(!i.getImageData(0,0,n,r))return a.ascent=s,a.descent=s+6,a.fontSize=a.ascent+a.descent,p.remove(e),a;var o,h,l=i.getImageData(0,0,n,r).data,u=l.length,d=4*n,f=0,c=!1;for(o=0;o<s;o++){for(h=0;h<d;h+=4)if(255!==l[f+h]){c=!0;break}if(c)break;f+=d}for(a.ascent=s-o,f=u-d,c=!1,o=r;s<o;o--){for(h=0;h<d;h+=4)if(255!==l[f+h]){c=!0;break}if(c)break;f-=d}return a.descent=o-s,a.fontSize=a.ascent+a.descent,p.remove(e),a}function m(t,e){var i=Array.isArray(t);if(void 0===e?e=i?[]:{}:function(t){if(Array.isArray(t))t.length=0;else for(var e in t)delete t[e]}(e),i){e.length=t.length;for(var n=0,s=t.length;n<s;n++)e[n]=t[n]}else for(var r in t)e[r]=t[r];return e}function a(){}function S(t,e,i,n,s){n<=0&&(i=E);var r=Q;if(Z.pushMultiple(r),!t||!t.length)return r;for(var a,o,h,l=t.split(K),u=0,d=l.length;u<d;u++)if(a=l[u],h=u===d-1?N:V,i!==E){var f,c;if(o=0===u?n-s:n,a.length<=100)if((x=e(a))<=o){r.push(Z.newline(a,x,h));continue}for(var p,g="",y="",v=0,k=0,w=(f=i===q?a.split(" "):a).length;k<w;k++)c=f[k],i===q?(g+=c,k<w-1&&(g+=" ")):g+=c,o<(p=e(g))&&(0===k?r.push(Z.newline("",0,J)):(r.push(Z.newline(y,v,J)),g=c,i===q&&k<w-1&&(g+=" "),p=e(g)),o=n),y=g,v=p;r.push(Z.newline(y,v,h))}else{var x=e(a);r.push(Z.newline(a,x,h))}return r}var l=Phaser.Renderer.WebGL.Utils,u={renderWebGL:function(t,e,i,n,s){if(0!==e.width&&0!==e.height){var r=e.frame,a=r.width,o=r.height,h=l.getTintAppendFloatAlpha;this.pipeline.batchTexture(e,r.glTexture,a,o,e.x,e.y,a/e.style.resolution,o/e.style.resolution,e.scaleX,e.scaleY,e.rotation,e.flipX,e.flipY,e.scrollFactorX,e.scrollFactorY,e.displayOriginX,e.displayOriginY,0,0,a,o,h(e._tintTL,n.alpha*e._alphaTL),h(e._tintTR,n.alpha*e._alphaTR),h(e._tintBL,n.alpha*e._alphaBL),h(e._tintBR,n.alpha*e._alphaBR),e._isTinted&&e.tintFill,0,0,n,s)}},renderCanvas:function(t,e,i,n,s){0!==e.width&&0!==e.height&&t.batchSprite(e,e.frame,n,s)}},p=Phaser.Display.Canvas.CanvasPool,c=0,g=1,y=2,v=0,k=1,w=2,x=/(?:\r\n|\r|\n)/,T=Phaser.Utils.Objects.GetAdvancedValue,P=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 n(t,e){d(this,n),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 i=P(e,"metrics",!1);this.metrics=i?{ascent:P(i,"ascent",0),descent:P(i,"descent",0),fontSize:P(i,"fontSize",0)}:r(this)}return s(n,[{key:"setStyle",value:function(t,e){if(void 0===e&&(e=!0),t&&t.hasOwnProperty("wrap")){var i=t.wrap;if(i.hasOwnProperty("mode")){var n=i.mode;"string"==typeof n&&(i.mode=O[n])}else i.hasOwnProperty("width")&&(i.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?P:T)(t,M[s][0],M[s][1]);var r=P(t,"font",null);this._font=null===r?this.fontStyle+" "+this.fontSize+" "+this.fontFamily:r;var a=P(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=r(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=P(t,"fontFamily","Courier"),this.fontSize=P(t,"fontSize","16px"),this.fontStyle=P(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,i,n,s,r){return void 0===t&&(t=0),void 0===e&&(e=0),void 0===i&&(i="#000"),void 0===n&&(n=0),void 0===s&&(s=!1),void 0===r&&(r=!0),this.shadowOffsetX=t,this.shadowOffsetY=e,this.shadowColor=i,this.shadowBlur=n,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,i){return void 0===t&&(t="#000"),void 0===e&&(e=0),void 0===i&&(i=0),this.underlineColor=t,this.underlineThickness=e,this.underlineOffset=i,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=O[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}}]),n}(),O={none:v,word:k,char:w,character:w},F={draw:function(t,e,i,n){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,d,f,c=a.halign,p=a.valign,g=a.lineHeight,y=s.lines,v=y.length,k=a.maxLines;u=(l=0<k&&k<v?(h=k,"center"===p?Math.floor((v-h)/2):"bottom"===p?v-h:0):(h=v,0))+h,f="center"===p?Math.max((n-h*g)/2,0):"bottom"===p?Math.max(n-h*g-2,0):0,f+=e;for(var w=l;w<u;w++)if(0!==(o=s.getLineWidth(w))){d="center"===c?(i-o)/2:"right"===c?i-o:0,d+=t;for(var x=y[w],m=0,S=x.length;m<S;m++)this.drawPen(x[m],d,f)}r.restore()},drawPen:function(t,e,i){e+=t.x,i+=t.y;var n=this.canvas,s=this.context;s.save();var r=this.parser.propToContextStyle(this.defatultStyle,t.prop);r.buildFont(),r.syncFont(n,s),r.syncStyle(n,s),0<r.underlineThickness&&0<t.width&&this.drawUnderline(e,i,t.width,r),t.isTextPen&&this.drawText(e,i,t.text,r),t.isImagePen&&this.drawImage(e,i,t.prop.img,r),s.restore(),t.hasAreaMarker&&0<t.width&&this.hitAreaManager.add(t.prop.area,e,i-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,i,n){e+=n.underlineOffset-n.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=n.underlineColor,s.lineWidth=n.underlineThickness,s.moveTo(t,e),s.lineTo(t+i,e),s.stroke(),s.lineCap=r},drawText:function(t,e,i,n){this.autoRound&&(t=Math.round(t),e=Math.round(e));var s=this.context;n.strokeThickness&&(n.syncShadow(s,n.shadowStroke),s.strokeText(i,t,e)),n.color&&"none"!==n.color&&(n.syncShadow(s,n.shadowFill),s.fillText(i,t,e))},drawImage:function(t,e,i){var n=this.parent.imageManager,s=n.get(i),r=n.getFrame(i);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)}},C=function(){function t(){d(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}(),L=Phaser.Utils.Objects.GetValue,z=c,W=g,_=function(){function e(t){d(this,e),this.prop={},this.resetFromJSON(t)}return s(e,[{key:"resetFromJSON",value:function(t){this.text=L(t,"text",""),this.x=L(t,"x",0),this.y=L(t,"y",0),this.width=L(t,"width",0);var e=L(t,"prop",null);null===e&&(e={}),this.prop=e,this.newLineMode=L(t,"newLineMode",0),this.startIndex=L(t,"startIndex",0)}},{key:"plainText",get:function(){var t=this.text;return this.newLineMode===W&&(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===W&&(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}(),A=Phaser.Utils.Objects.GetFastValue,B=c,I=y,R=new C,X=new C,H=function(){function o(t){d(this,o),this.pens=[],this.lines=[],this.maxLinesWidth=void 0,this.PensPool=A(t,"pensPool",R),this.LinesPool=A(t,"linesPool",X),this.tagToText=A(t,"tagToText",a),this.tagToTextScope=A(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,i,n,s,r){var a=this.PensPool.pop();return null==a&&(a=new _),Y.text=t,Y.x=e,Y.y=i,Y.width=n,Y.prop=s,Y.newLineMode=r,a.resetFromJSON(Y),this.addPen(a),this}},{key:"addImagePen",value:function(t,e,i,n){return this.addTextPen("",t,e,i,n,B),this}},{key:"addNewLinePen",value:function(){var t=this.lastPen,e=t?t.lastX:0,i=t?t.y:0,n=t?m(t.prop):null;return this.addTextPen("",e,i,0,n,I),this}},{key:"addPen",value:function(t){var e=this.lastPen;t.startIndex=null==e?0:e.endIndex,this.pens.push(t);var i=this.lastLine;null==i&&(i=this.LinesPool.pop()||[],this.lines.push(i)),i.push(t),t.newLineMode!==B&&(i=this.LinesPool.pop()||[],this.lines.push(i)),this.maxLinesWidth=void 0}},{key:"clone",value:function(t){null==t&&(t=new o),t.freePens();for(var e=0,i=this.lines.length;e<i;e++)for(var n=this.lines[e],s=0,r=n.length;s<r;s++){var a=n[s];t.addPen(a.text,a.x,a.y,a.width,m(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,i,n=!1;for(e=t;0<=e&&!(n=null!=(i=this.lines[e])&&0<i.length);e--);return n?i[i.length-1].endIndex:0}},{key:"getLineWidth",value:function(t){var e=this.lines[t];if(!e)return 0;var i=e[e.length-1];return null==i?0:i.lastX}},{key:"getMaxLineWidth",value:function(){if(void 0!==this.maxLinesWidth)return this.maxLinesWidth;for(var t,e=0,i=0,n=this.lines.length;i<n;i++)e<(t=this.getLineWidth(i))&&(e=t);return this.maxLinesWidth=e}},{key:"getLineWidths",value:function(){for(var t=[],e=0,i=this.lines.length;e<i;e++)t.push(this.getLineWidth(e));return t}},{key:"getSliceTagText",value:function(t,e,i){if(void 0===t&&(t=0),void 0===e){var n=this.lastPen;if(null==n)return"";e=n.endIndex}void 0===i&&(i=!1);for(var s,r,a,o,h,l,u="",d=0,f=this.pens.length;d<f&&((o=(s=this.pens[d]).endIndex)<=t||(s=this.pens[d],r=i?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)));d++);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,i=0,n=e.length;i<n;i++)t+=e[i].plainText;return t}},{key:"rawTextLength",get:function(){for(var t=0,e=this.pens,i=0,n=this.pens.length;i<n;i++)t+=e[i].rawTextLength;return t}}]),o}(),Y={},j=Phaser.Geom.Rectangle,G=new C,U=function(){function t(){d(this,t),this.hitAreas=[]}return s(t,[{key:"destroy",value:function(){this.clear()}},{key:"clear",value:function(){return G.pushMultiple(this.hitAreas),this}},{key:"add",value:function(t,e,i,n,s){var r=G.pop();return null===r?r=new j(e,i,n,s):r.setTo(e,i,n,s),r.key=t,this.hitAreas.push(r),this}},{key:"getFirstHitArea",value:function(t,e){for(var i,n=this.hitAreas,s=0,r=n.length;s<r;s++)if((i=n[s]).contains(t,e))return i;return null}},{key:"drawBounds",value:function(t,e,i){void 0===e&&(e=16777215),i&&t.save().scaleCanvas(i.scaleX,i.scaleY).rotateCanvas(i.rotation).translateCanvas(i.x,i.y);for(var n,s=this.hitAreas,r=0,a=s.length;r<a;r++)n=s[r],t.lineStyle(1,e).strokeRect(n.x,n.y,n.width,n.height);return i&&t.restore(),this}}]),t}(),D=function(t,e,i,n){var s=this.hitAreaManager.getFirstHitArea(i,n);if(null!==s){var r=s.key;this.parent.emit("".concat(t,"-").concat(r),e,i,n),this.parent.emit(t,r,e,i,n)}},N=c,V=g,J=y,E=v,q=k,K=x,Q=[],Z=new C;Z.newline=function(t,e,i){var n=this.pop();return null===n&&(n={}),n.text=t,n.width=e,n.newLineMode=i,n};var $=Phaser.Utils.Objects.GetValue,tt=v,et=c,it=function(){function i(t){d(this,i),this.parent=t.parent,this.context=$(t,"context",null),this.canvas=this.context.canvas,this.parser=$(t,"parser",null),this.defatultStyle=$(t,"style",null),this.autoRound=!0,this.pensPool=$(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(i,[{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,i,n,s){if(void 0===s&&(s=this.penManager),s.freePens(),""===t)return s;for(var r,a,o,h,l,u=this.canvas,d=this.context,f=0,c=0,p=this.parser.splitText(t),g=0,y=p.length;g<y;g++)if(r=(h=this.parser.tagTextToProp(p[g],a)).plainText,(a=h.prop).img){var v=this.imageManager.getOuterWidth(a.img);0<i&&e!==tt&&i<f+v&&(s.addNewLinePen(),c+=n,f=0),s.addImagePen(f,c,v,m(a)),f+=v}else if(""!==r){var k;this.context.save(),(o=this.parser.propToContextStyle(this.defatultStyle,a)).buildFont(),o.syncFont(u,d),o.syncStyle(u,d);for(var w=0,x=(l=S(r,this.getTextWidth,e,i,f)).length;w<x;w++)k=l[w],s.addTextPen(k.text,f,c,k.width,m(a),k.newLineMode),k.newLineMode!==et?(f=0,c+=n):f+=k.width;this.context.restore()}return s}},{key:"newPenManager",value:function(){return new H({pensPool:this.pensPool,tagToText:this.parser.propToTagText,tagToTextScope:this.parser})}},{key:"getPlainText",value:function(t,e,i){var n;if(null==t)n=this.penManager.plainText;else{var s=this.parser.splitText(t,1);n="";for(var r=0,a=s.length;r<a;r++)n+=s[r]}return null==e&&null==i||(null==e&&(e=0),null==i&&(i=n.length),n=n.substring(e,i)),n}},{key:"getPenManager",value:function(t,e){if(void 0===t)return this.copyPenManager(e,this.penManager);void 0===e&&(e=this.newPenManager());var i=this.defatultStyle;return this.updatePenManager(t,i.wrapMode,i.wrapWidth,i.lineHeight,e),e}},{key:"getText",value:function(t,e,i,n){if(null==t)return this.penManager.getSliceTagText(e,i,n);var s=this.tmpPenManager,r=this.defatultStyle;return this.updatePenManager(t,r.wrapMode,r.wrapWidth,r.lineHeight,s),s.getSliceTagText(e,i,n)}},{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}}]),i}(),nt={setInteractive:function(){this.parent.on("pointerdown",function(t,e,i,n){D.call(this,"areadown",t,e,i)},this).on("pointerup",function(t,e,i,n){D.call(this,"areaup",t,e,i)},this)}};Object.assign(it.prototype,F,nt);var st,rt=Phaser.Utils.Objects.GetValue,at=function(){function e(t){d(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 i=0,n=(s=t).length;i<n;i++)this._add(s[i]);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 i=e.key,n=e.frame,s=e.width,r=e.height;if(void 0===s||void 0===r){var a=this.textureManager.getFrame(i,n),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:i,frame:n,width:s,height:r,y:rt(e,"y",0),left:rt(e,"left",0),right:rt(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 ot=Phaser.DOM.AddToDOM,ht=Phaser.Display.Canvas.CanvasPool,lt=Phaser.GameObjects.GameObject,ut=Phaser.Utils.Objects.GetValue,dt=Phaser.DOM.RemoveFromDOM,ft=x,ct={},pt=function(){t(u,lt);var l=e(u);function u(t,e,i,n,s,r,a){var o;if(d(this,u),void 0===e&&(e=0),void 0===i&&(i=0),(o=l.call(this,t,r)).renderer=t.sys.game.renderer,o.setPosition(e,i),o.setOrigin(0,0),o.initPipeline(),o.canvas=ht.create(f(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(f(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=t.sys.game.config.resolution),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),ct.hasOwnProperty(r)||(ct[r]=new C),o.canvasText=new it({parent:f(o),context:o.context,parser:a,style:o.style,pensPool:ct[r]}),s&&s.padding&&o.setPadding(s.padding),o.setText(n),t.sys.game.events.on("contextrestored",function(){this.dirty=!0},f(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",ot(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,i,n,s,r){return this.style.setShadow(t,e,i,n,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,i,n){if("object"===o(t)){var s=t,r=ut(s,"x",null);i=null!==r?t=r:(t=ut(s,"left",0),ut(s,"right",t));var a=ut(s,"y",null);n=null!==a?e=a:(e=ut(s,"top",0),ut(s,"bottom",e))}else void 0===t&&(t=0),void 0===e&&(e=t),void 0===i&&(i=t),void 0===n&&(n=e);return this.padding.left=t,this.padding.top=e,this.padding.right=i,this.padding.bottom=n,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,i=this.style;t&&e.updatePenManager(this._text,i.wrapMode,i.wrapWidth,i.lineHeight);var n,s,r=this.padding;0===i.fixedWidth?(this.width=e.linesWidth+r.left+r.right,n=e.linesWidth):(this.width=i.fixedWidth,(n=this.width-r.left-r.right)<e.linesWidth&&(n=e.linesWidth)),0===i.fixedHeight?(this.height=e.linesHeight+r.top+r.bottom,s=e.linesHeight):(this.height=i.fixedHeight,(s=this.height-r.top-r.bottom)<e.linesHeight&&(s=e.linesHeight));var a=this.width,o=this.height;this.updateDisplayOrigin();var h=i.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,n,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 d=this.input;return d&&!d.customHitArea&&(d.hitArea.width=this.width,d.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),ht.remove(this.canvas),this.canvasText.destroy()}},{key:"setInteractive",value:function(t,e,i){return lt.prototype.setInteractive.call(this,t,e,i),this.canvasText.setInteractive(),this}},{key:"getWrappedText",value:function(t,e,i){return(t=this.canvasText.getText(t,e,i,!0)).split(ft)}},{key:"getPlainText",value:function(t,e,i){return this.canvasText.getPlainText(t,e,i)}},{key:"getText",value:function(t,e,i){return this.canvasText.getText(t,e,i,!1)}},{key:"getSubString",value:function(t,e,i){return this.getText(t,e,i)}},{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===st&&(st=new at(t)),st;var t}}]),u}(),gt=Phaser.GameObjects.Components;Phaser.Class.mixin(pt,[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,u]);var yt={plainText:null,prevProp:null},vt=new b,kt={},wt={splitText:function(t,e){for(var i,n,s=[],r=0,a=t.length,o=a;i=St.exec(t);)n=i[0],r<(o=St.lastIndex-n.length)&&s.push(t.substring(r,o)),void 0===e&&s.push(n),r=St.lastIndex;return r<a&&s.push(t.substring(r,a)),s},tagTextToProp:function(t,e){var i,n;null==e&&(e={}),e.img&&xt(e,Ut,"img"),i=Tt.test(t)?(xt(e,Dt,"b",!0),""):Pt.test(t)?(xt(e,Ut,"b"),""):Mt.test(t)?(xt(e,Dt,"i",!0),""):bt.test(t)?(xt(e,Ut,"i"),""):Ot.test(t)?(n=t.match(Ot),xt(e,Dt,"size",n[1]+"px"),""):Ft.test(t)?(xt(e,Ut,"size"),""):Ct.test(t)?(n=t.match(Ct),xt(e,Dt,"color",n[1]),""):Lt.test(t)?(xt(e,Ut,"color"),""):zt.test(t)?(n=t.match(zt),xt(e,Dt,"u",!0),""):Wt.test(t)?(n=t.match(Wt),xt(e,Dt,"u",n[1]),""):_t.test(t)?(xt(e,Ut,"u"),""):At.test(t)?(xt(e,Dt,"shadow",!0),""):Bt.test(t)?(xt(e,Ut,"shadow"),""):It.test(t)?(xt(e,Dt,"stroke",!0),""):Rt.test(t)?(n=t.match(Rt),xt(e,Dt,"stroke",n[1]),""):Xt.test(t)?(xt(e,Ut,"stroke"),""):Ht.test(t)?(n=t.match(Ht),xt(e,Dt,"img",n[1]),""):Yt.test(t)?(xt(e,Ut,"img"),""):jt.test(t)?(n=t.match(jt),xt(e,Dt,"area",n[1]),""):Gt.test(t)?(xt(e,Ut,"area"),""):t;var s=yt;return s.plainText=i,s.prop=e,s},propToContextStyle:function(t,e){var i=vt;if(e.hasOwnProperty("img"))i.image=e.img;else{if(i.image=null,e.hasOwnProperty("family")?i.fontFamily=e.family:i.fontFamily=t.fontFamily,e.hasOwnProperty("size")){var n=e.size;"number"==typeof n&&(n=n.toString()+"px"),i.fontSize=n}else i.fontSize=t.fontSize;i.fontStyle=mt(e.b,e.i),e.hasOwnProperty("color")?i.color=e.color:i.color=t.color,e.hasOwnProperty("stroke")?(!0===e.stroke?i.stroke=t.stroke:i.stroke=e.stroke,i.strokeThickness=t.strokeThickness):(i.stroke=t.stroke,i.strokeThickness=0)}return e.hasOwnProperty("shadow")?(!0===e.shadow?i.shadowColor=t.shadowColor:i.shadowColor=e.shadow,i.shadowOffsetX=t.shadowOffsetX,i.shadowOffsetY=t.shadowOffsetY,i.shadowBlur=t.shadowBlur,i.shadowStroke=!0,i.shadowFill=!0):(i.shadowColor="#000",i.shadowOffsetX=0,i.shadowOffsetY=0,i.shadowBlur=0,i.shadowStroke=!1,i.shadowFill=!1),e.hasOwnProperty("u")?(!0===e.u?i.underlineColor=t.underlineColor:i.underlineColor=e.u,i.underlineThickness=t.underlineThickness,i.underlineOffset=t.underlineOffset):(i.underlineColor="#000",i.underlineThickness=0,i.underlineOffset=0),i},propToTagText:function(t,e,i){for(var n in null==i&&(i=kt),i)e.hasOwnProperty(n)||(t="[/"+n+"]"+t);var s="";for(var n in e)i[n]!==e[n]&&("size"===n?s+="[size="+e[n].replace("px","")+"]":"color"===n||"stroke"===n||"img"===n?s+="["+n+"="+e[n]+"]":"u"===n?!0===e[n]?s+="[u]":s+="[u="+e[n]+"]":s+="["+n+"]");return t=s+t}},xt=function(t,e,i,n){return e===Dt?t[i]=n:t.hasOwnProperty(i)&&delete t[i],t},mt=function(t,e){return t&&e?"bold italic":t?"bold":e?"italic":""},St=/\[b\]|\[\/b\]|\[i\]|\[\/i\]|\[size=(\d+)\]|\[\/size\]|\[color=([a-z]+|#[0-9abcdef]+)\]|\[\/color\]|\[u\]|\[u=([a-z]+|#[0-9abcdef]+)\]|\[\/u\]|\[shadow\]|\[\/shadow\]|\[stroke\]|\[stroke=([a-z]+|#[0-9abcdef]+)\]|\[\/stroke\]|\[img=([^\]]+)\]|\[\/img\]|\[area=([^\]]+)\]|\[\/area\]/gi,Tt=/\[b\]/i,Pt=/\[\/b\]/i,Mt=/\[i\]/i,bt=/\[\/i\]/i,Ot=/\[size=(\d+)\]/i,Ft=/\[\/size\]/i,Ct=/\[color=([a-z]+|#[0-9abcdef]+)\]/i,Lt=/\[\/color\]/i,zt=/\[u\]/i,Wt=/\[u=([a-z]+|#[0-9abcdef]+)\]/i,_t=/\[\/u\]/i,At=/\[shadow\]/i,Bt=/\[\/shadow\]/i,It=/\[stroke\]/i,Rt=/\[stroke=([a-z]+|#[0-9abcdef]+)\]/i,Xt=/\[\/stroke\]/i,Ht=/\[img=([^\]]+)\]/i,Yt=/\[\/img\]/i,jt=/\[area=([^\]]+)\]/i,Gt=/\[\/area\]/i,Ut=!1,Dt=!0;return function(){t(a,pt);var r=e(a);function a(t,e,i,n,s){return d(this,a),r.call(this,t,e,i,n,s,"rexBBCodeText",wt)}return a}()});
  