phaser4-rex-plugins
Version:
8 lines (7 loc) • 49 kB
JavaScript
var t,e;t=void 0,e=function(){var t={renderWebGL:function(t,e,s,r){if(0!==e.width&&0!==e.height){s.camera.addToRenderList(e);var i=e.customRenderNodes,n=e.defaultRenderNodes;(i.Submitter||n.Submitter).run(s,e,r,0,i.Texturer||n.Texturer,i.Transformer||n.Transformer)}},renderCanvas:function(t,e,s,r){0!==e.width&&0!==e.height&&(s.addToRenderList(e),t.batchSprite(e,e.frame,s,r))}};const e=Phaser.Display.Canvas.CanvasPool;var s=!1;!function(t){if(!s){void 0===t&&(t=0);var e=Phaser.VERSION.split("."),r=parseInt(e[0]);if(4===r){var i=parseInt(e[1]);i<t&&console.error(`Minimum supported version : ${r}.${i}`)}else console.error(`Can't supported version : ${r}`);s=!0}}();const r=Phaser.GameObjects.GameObject;class i extends r{setStyle(t){return this.style.setStyle(t)}setFont(t){return this.style.setFont(t)}setFontFamily(t){return this.style.setFontFamily(t)}setFontSize(t){return this.style.setFontSize(t)}setFontStyle(t){return this.style.setFontStyle(t)}setTestString(t){return this.style.setTestString(t)}setFixedSize(t,e){return this.style.setFixedSize(t,e)}setBackgroundColor(t,e,s){return this.style.setBackgroundColor(t,e,s)}setBackgroundStrokeColor(t,e){return this.style.setBackgroundStrokeColor(t,e)}setBackgroundCornerRadius(t,e){return this.style.setBackgroundCornerRadius(t,e)}setFill(t){return this.style.setFill(t)}setColor(t){return this.style.setColor(t)}setStroke(t,e){return this.style.setStroke(t,e)}setShadow(t,e,s,r,i,n){return this.style.setShadow(t,e,s,r,i,n)}setShadowOffset(t,e){return this.style.setShadowOffset(t,e)}setShadowColor(t){return this.style.setShadowColor(t)}setShadowBlur(t){return this.style.setShadowBlur(t)}setShadowStroke(t){return this.style.setShadowStroke(t)}setShadowFill(t){return this.style.setShadowFill(t)}setUnderline(t,e,s){return this.style.setUnderline(t,e,s)}setUnderlineColor(t){return this.style.setUnderlineColor(t)}setUnderlineThickness(t){return this.style.setUnderlineThickness(t)}setUnderlineOffset(t){return this.style.setUnderlineOffset(t)}setStrikethrough(t,e,s){return this.style.setStrikethrough(t,e,s)}setStrikethroughColor(t){return this.style.setStrikethroughColor(t)}setStrikethroughThickness(t){return this.style.setStrikethroughThickness(t)}setStrikethroughOffset(t){return this.style.setStrikethroughOffset(t)}setWrapMode(t){return this.style.setWrapMode(t)}setWrapWidth(t){return this.style.setWrapWidth(t)}setWordWrapWidth(t){return this.style.setWrapWidth(t)}setAlign(t){return this.style.setHAlign(t)}setHAlign(t){return this.style.setHAlign(t)}setVAlign(t){return this.style.setVAlign(t)}get lineSpacing(){return this.style.lineSpacing}set lineSpacing(t){this.style.lineSpacing=t}setLineSpacing(t){return this.style.lineSpacing=t,this.updateText(!0),this}get letterSpacing(){return this.style.letterSpacing}set letterSpacing(t){this.style.letterSpacing=t}setLetterSpacing(t){return this.style.letterSpacing=t,this.updateText(!0),this}setXOffset(t){return this.style.setXOffset(t)}setMaxLines(t){return this.style.setMaxLines(t)}setResolution(t){return this.style.setResolution(t)}getTextMetrics(){return this.style.getTextMetrics()}setTextMetrics(t,e){return this.style.setTextMetrics(t,e)}measureTextMargins(t,s){return function(t,s,r){void 0===r&&(r={});var i=e.create(this),n=i.getContext("2d",{willReadFrequently:!0});t.syncFont(i,n);var a=n.measureText(s),h=Math.ceil(a.width*t.baselineX),o=h,l=2*o;if(o=o*t.baselineY|0,i.width=h,i.height=l,n.fillStyle="#f00",n.fillRect(0,0,h,l),n.font=t._font,n.textBaseline="alphabetic",n.fillStyle="#000",n.fillText(t.testString,0,o),r.left=0,0===h||0===l||!n.getImageData(0,0,h,l))return e.remove(i),r;for(var u=n.getImageData(0,0,h,l).data,d=!1,g=0;g<h;g++){for(var c=0;c<l;c++)if(255!==u[4*(c*h+g)]){r.left=g,d=!0;break}if(d)break}return e.remove(i),r}(this.style,t,s)}}const n=Phaser.GameObjects.Components;Phaser.Class.mixin(i,[n.Alpha,n.BlendMode,n.ComputedSize,n.Crop,n.Depth,n.Flip,n.GetBounds,n.Lighting,n.Mask,n.Origin,n.RenderNodes,n.ScrollFactor,n.Tint,n.Transform,n.Visible,t]);const a=Phaser.Utils.String.Pad;var h=function(t,e,s){if(null==t)return t;switch(typeof t){case"string":default:return t;case"number":return`#${a(Math.floor(t).toString(16),6,"0",1)}`;case"function":return t(e,s);case"object":return t.hasOwnProperty("r")?t.hasOwnProperty("a")?`rgba(${t.r},${t.g},${t.b},${t.a})`:`rgb(${t.r},${t.g},${t.b})`:t.hasOwnProperty("h")?t.hasOwnProperty("a")?`hsla(${t.h},${t.s},${t.l},${t.a})`:`hsl(${t.h},${t.s},${t.l})`:t}},o={backgroundColor:["backgroundColor",null,h],backgroundColor2:["backgroundColor2",null,h],backgroundHorizontalGradient:["backgroundHorizontalGradient",!0,null],backgroundStrokeColor:["backgroundStrokeColor",null,h],backgroundStrokeLineWidth:["backgroundStrokeLineWidth",2,null],backgroundCornerRadius:["backgroundCornerRadius",0,null],backgroundCornerIteration:["backgroundCornerIteration",null,null],fontFamily:["fontFamily","Courier",null],fontSize:["fontSize","16px",null],fontStyle:["fontStyle","",null],color:["color","#fff",h],stroke:["stroke","#fff",h],strokeThickness:["strokeThickness",0,null],shadowOffsetX:["shadow.offsetX",0,null],shadowOffsetY:["shadow.offsetY",0,null],shadowColor:["shadow.color","#000",h],shadowBlur:["shadow.blur",0,null],shadowStroke:["shadow.stroke",!1,null],shadowFill:["shadow.fill",!1,null],underlineColor:["underline.color","#000",h],underlineThickness:["underline.thickness",0,null],underlineOffset:["underline.offset",0,null],strikethroughColor:["strikethrough.color","#000",h],strikethroughThickness:["strikethrough.thickness",0,null],strikethroughOffset:["strikethrough.offset",0,null],halign:["halign","left",null],valign:["valign","top",null],maxLines:["maxLines",0,null],fixedWidth:["fixedWidth",0,null],fixedHeight:["fixedHeight",0,null],resolution:["resolution",0,null],lineSpacing:["lineSpacing",0,null],letterSpacing:["letterSpacing",0,null],xOffset:["xOffset",0,null],rtl:["rtl",!1,null],testString:["testString","|MÉqgy",null],baselineX:["baselineX",1.2,null],baselineY:["baselineY",1.4,null],wrapMode:["wrap.mode",0,null],wrapWidth:["wrap.width",0,null],wrapCallback:["wrap.callback",null],wrapCallbackScope:["wrap.callbackScope",null]};
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2018 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
const l=Phaser.Display.Canvas.CanvasPool;var u=function(t){var e=l.create(this),s=e.getContext("2d",{willReadFrequently:!0});t.syncFont(e,s);var r=s.measureText(t.testString);if("actualBoundingBoxAscent"in r){var i=r.actualBoundingBoxAscent,n=r.actualBoundingBoxDescent,a={ascent:i,descent:n,fontSize:i+n};return l.remove(e),a}var h=Math.ceil(r.width*t.baselineX),o=h,u=2*o;if(o=o*t.baselineY|0,e.width=h,e.height=u,s.fillStyle="#f00",s.fillRect(0,0,h,u),s.font=t._font,s.textBaseline="alphabetic",s.fillStyle="#000",s.fillText(t.testString,0,o),a={ascent:0,descent:0,fontSize:0},!s.getImageData(0,0,h,u))return a.ascent=o,a.descent=o+6,a.fontSize=a.ascent+a.descent,l.remove(e),a;var d,g,c=s.getImageData(0,0,h,u).data,p=c.length,f=4*h,v=0,y=!1;for(d=0;d<o;d++){for(g=0;g<f;g+=4)if(255!==c[v+g]){y=!0;break}if(y)break;v+=f}for(a.ascent=o-d,v=p-f,y=!1,d=u;d>o;d--){for(g=0;g<f;g+=4)if(255!==c[v+g]){y=!0;break}if(y)break;v-=f}return a.descent=d-o,a.fontSize=a.ascent+a.descent,l.remove(e),a},d=0,g=1,c=2,p=0,f=1,v=2,y=/(?:\r\n|\r|\n)/;const x={none:p,word:f,char:v,character:v,mix:3},w=Phaser.Utils.Objects.GetAdvancedValue,k=Phaser.Utils.Objects.GetValue;class S{constructor(t,e,s){this.parent=t,void 0===s&&(s=o),this.propertyMap=s,this.backgroundColor,this.backgroundColor2,this.backgroundHorizontalGradient,this.backgroundStrokeColor,this.backgroundStrokeLineWidth,this.backgroundCornerRadius,this.backgroundCornerIteration,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.strikethroughColor,this.strikethroughThickness,this.strikethroughOffset,this.halign,this.valign,this.maxLines,this.fixedWidth,this.fixedHeight,this.resolution,this.xOffset,this.rtl,this.testString,this.baselineX,this.baselineY,this.wrapMode,this.wrapWidth,this.wrapCallback,this.wrapCallbackScope,this._font,this.setStyle(e,!1,!0)}get isWrapFitMode(){return this.fixedWidth>0&&this.wrapMode!==p&&0===this.wrapWidth}setStyle(t,e,s){if(void 0===e&&(e=!0),void 0===s&&(s=!1),t&&t.hasOwnProperty("wordWrap")){var r=t.wordWrap;r.hasOwnProperty("width")&&(t.wrap={mode:"word",width:r.width})}if(t&&t.hasOwnProperty("wrap")){var i=t.wrap;if(i.hasOwnProperty("mode")){var n=i.mode;"string"==typeof n&&(i.mode=x[n])}else i.hasOwnProperty("width")&&(i.mode=1)}t&&t.rtl&&s&&!t.hasOwnProperty("halign")&&(t.halign="right"),t&&t.hasOwnProperty("fontSize")&&"number"==typeof t.fontSize&&(t.fontSize=t.fontSize.toString()+"px");var a=this.propertyMap;for(var o in a){var l=a[o],d=l[0],g=s?l[1]:this[o],c=l[2];if("wrapCallback"===o||"wrapCallbackScope"===o)this[o]=k(t,d,g);else{var p=w(t,d,g);c&&(p=c(p)),this[o]=p}}var f=k(t,"font",null);this._font=null===f?this.fontStyle+" "+this.fontSize+" "+this.fontFamily:f;var v=k(t,"fill",null);null!==v&&(this.color=h(v));var y=k(t,"metrics",!1);return y?this.metrics={ascent:k(y,"ascent",0),descent:k(y,"descent",0),fontSize:k(y,"fontSize",0)}:!e&&this.metrics||(this.metrics=u(this)),e?this.parent.updateText():this.parent}syncFont(t,e){e.font=this._font}syncStyle(t,e){e.textBaseline="alphabetic",e.fillStyle=this.color,e.strokeStyle=this.stroke,e.lineWidth=this.strokeThickness,e.lineCap="round",e.lineJoin="round"}syncShadow(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)}update(t){return t&&(this._font=`${this.fontStyle} ${this.fontSize} ${this.fontFamily}`.trim(),this.metrics=u(this)),this.parent.updateText(t)}buildFont(){var t=`${this.fontStyle} ${this.fontSize} ${this.fontFamily}`.trim();return t!==this._font&&(this._font=t),this}setFont(t){return"string"==typeof t?(this.fontFamily=t,this.fontSize="",this.fontStyle=""):(this.fontFamily=k(t,"fontFamily","Courier"),this.fontSize=k(t,"fontSize","16px"),this.fontStyle=k(t,"fontStyle","")),this.update(!0)}setFontFamily(t){return this.fontFamily=t,this.update(!0)}setFontStyle(t){return this.fontStyle=t,this.update(!0)}setFontSize(t){return"number"==typeof t&&(t=t.toString()+"px"),this.fontSize=t,this.update(!0)}setTestString(t){return this.testString=t,this.update(!0)}setFixedSize(t,e){return this.fixedWidth=t,this.fixedHeight=e,t&&(this.parent.width=t),e&&(this.parent.height=e),this.update(this.isWrapFitMode)}setResolution(t){return this.resolution=t,this.update(!1)}setXOffset(t){return this.xOffset=t,this.update(!1)}setBackgroundColor(t,e,s){return void 0===s&&(s=!0),this.backgroundColor=h(t,this.parent.canvas,this.parent.context),this.backgroundColor2=h(e,this.parent.canvas,this.parent.context),this.backgroundHorizontalGradient=s,this.update(!1)}setBackgroundStrokeColor(t,e){return this.backgroundStrokeColor=h(t,this.parent.canvas,this.parent.context),this.backgroundStrokeLineWidth=e,this.update(!1)}setBackgroundCornerRadius(t,e){return this.backgroundCornerRadius=t,this.backgroundCornerIteration=e,this.update(!1)}setFill(t){return this.color=h(t,this.parent.canvas,this.parent.context),this.update(!1)}setColor(t){return this.color=h(t,this.parent.canvas,this.parent.context),this.update(!1)}setStroke(t,e){return void 0===t?this.strokeThickness=0:(void 0===e&&(e=this.strokeThickness),this.stroke=h(t,this.parent.canvas,this.parent.context),this.strokeThickness=e),this.update(!0)}setShadow(t,e,s,r,i,n){return void 0===t&&(t=0),void 0===e&&(e=0),void 0===s&&(s="#000"),void 0===r&&(r=0),void 0===i&&(i=!1),void 0===n&&(n=!0),this.shadowOffsetX=t,this.shadowOffsetY=e,this.shadowColor=h(s,this.parent.canvas,this.parent.context),this.shadowBlur=r,this.shadowStroke=i,this.shadowFill=n,this.update(!1)}setShadowOffset(t,e){return void 0===t&&(t=0),void 0===e&&(e=t),this.shadowOffsetX=t,this.shadowOffsetY=e,this.update(!1)}setShadowColor(t){return void 0===t&&(t="#000"),this.shadowColor=h(t,this.parent.canvas,this.parent.context),this.update(!1)}setShadowBlur(t){return void 0===t&&(t=0),this.shadowBlur=t,this.update(!1)}setShadowStroke(t){return this.shadowStroke=t,this.update(!1)}setShadowFill(t){return this.shadowFill=t,this.update(!1)}setUnderline(t,e,s){return void 0===t&&(t="#000"),void 0===e&&(e=0),void 0===s&&(s=0),this.underlineColor=h(t,this.parent.canvas,this.parent.context),this.underlineThickness=e,this.underlineOffset=s,this.update(!1)}setUnderlineColor(t){return void 0===t&&(t="#000"),this.underlineColor=h(t,this.parent.canvas,this.parent.context),this.update(!1)}setUnderlineThickness(t){return void 0===t&&(t=0),this.underlineThickness=t,this.update(!1)}setUnderlineOffset(t){return void 0===t&&(t=0),this.underlineOffset=t,this.update(!1)}setStrikethrough(t,e,s){return void 0===t&&(t="#000"),void 0===e&&(e=0),void 0===s&&(s=0),this.strikethroughColor=h(t,this.parent.canvas,this.parent.context),this.strikethroughThickness=e,this.strikethroughOffset=s,this.update(!1)}setStrikethroughColor(t){return void 0===t&&(t="#000"),this.strikethroughColor=h(t,this.parent.canvas,this.parent.context),this.update(!1)}setStrikethroughThickness(t){return void 0===t&&(t=0),this.strikethroughThickness=t,this.update(!1)}setStrikethroughOffset(t){return void 0===t&&(t=0),this.strikethroughOffset=t,this.update(!1)}setWrapMode(t){return"string"==typeof t&&(t=x[t.toLowerCase()]||0),this.wrapMode=t,this.update(!0)}setWrapWidth(t){return this.wrapWidth=t,this.update(!1)}setAlign(t,e){return void 0===t&&(t="left"),void 0===e&&(e="top"),this.halign=t,this.valign=e,this.update(!1)}setHAlign(t){return void 0===t&&(t="left"),this.halign=t,this.update(!1)}setVAlign(t){return void 0===t&&(t="top"),this.valign=t,this.update(!1)}setMaxLines(t){return void 0===t&&(t=0),this.maxLines=t,this.update(!1)}getTextMetrics(){var t=this.metrics;return{ascent:t.ascent,descent:t.descent,fontSize:t.fontSize}}setTextMetrics(t,e){return this.metrics.ascent=t.ascent,this.metrics.descent=t.descent,this.metrics.fontSize=t.fontSize,e&&("string"==typeof e?(this.fontFamily=e,this.fontSize="",this.fontStyle=""):(this.fontFamily=k(e,"fontFamily",this.fontFamily),this.fontSize=k(e,"fontSize",this.fontSize),this.fontStyle=k(e,"fontStyle",this.fontStyle))),this.parent.updateText(!0)}get lineHeight(){return this.metrics.fontSize+this.parent.lineSpacing}toJSON(){var t={},e=this.propertyMap;for(var s in e)t[s]=this[s];return t.metrics=this.getTextMetrics(),t}destroy(){this.parent=void 0}}const m=Phaser.Utils.Objects.GetValue;class T{constructor(t,e,s,r,i){void 0===t&&(t=0),void 0===e&&(e=t),void 0===s&&(s=0),void 0===r&&(r=0),void 0===i&&(i=0),this.cornerRadius={},this._width=0,this._height=0,this.setTo(t,e,s,r,i)}setTo(t,e,s,r,i){return this.setPosition(t,e),this.setRadius(i),this.setSize(s,r),this}setPosition(t,e){return this.x=t,this.y=e,this}setRadius(t){return void 0===t&&(t=0),this.radius=t,this}setSize(t,e){return this.width=t,this.height=e,this}get minWidth(){var t=this.cornerRadius;return Math.max(t.tl.x+t.tr.x,t.bl.x+t.br.x)}get minHeight(){var t=this.cornerRadius;return Math.max(t.tl.y+t.bl.y,t.tr.y+t.br.y)}get width(){return this._width}set width(t){null==t&&(t=0),this._width=Math.max(t,this.minWidth)}get height(){return this._height}set height(t){null==t&&(t=0),this._height=Math.max(t,this.minHeight)}get radius(){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)}set radius(t){var e,s;"number"==typeof t?(e=t,s=t):(e=m(t,"x",0),s=m(t,"y",0));var r=this.cornerRadius;r.tl=P(m(t,"tl",void 0),e,s),r.tr=P(m(t,"tr",void 0),e,s),r.bl=P(m(t,"bl",void 0),e,s),r.br=P(m(t,"br",void 0),e,s)}get radiusTL(){var t=this.cornerRadius.tl;return Math.max(t.x,t.y)}set radiusTL(t){b(this.cornerRadius.tl,t)}get radiusTR(){var t=this.cornerRadius.tr;return Math.max(t.x,t.y)}set radiusTR(t){b(this.cornerRadius.tr,t)}get radiusBL(){var t=this.cornerRadius.bl;return Math.max(t.x,t.y)}set radiusBL(t){b(this.cornerRadius.bl,t)}get radiusBR(){var t=this.cornerRadius.br;return Math.max(t.x,t.y)}set radiusBR(t){b(this.cornerRadius.br,t)}}var P=function(t,e,s){return void 0===t?t={x:e,y:s}:"number"==typeof t&&(t={x:t,y:t}),O(t),t},b=function(t,e){"number"==typeof e?(t.x=e,t.y=e):(t.x=m(e,"x",0),t.y=m(e,"y",0)),O(t)},O=function(t){t.convex=t.x>=0||t.y>=0,t.x=Math.abs(t.x),t.y=Math.abs(t.y)};const M=Phaser.Math.DegToRad;var C=function(t){return!t.hasOwnProperty("convex")||t.convex},F=function(t){return t.x>0&&t.y>0},L=function(t,e,s,r,i,n,a,h,o){if(h&&a>n?a-=360:!h&&a<n&&(a+=360),n=M(n),a=M(a),null==o)t.ellipse(e,s,r,i,0,n,a,h);else for(var l,u,d,g=(a-n)/(o+=1),c=0;c<=o;c++)d=n+g*c,l=e+r*Math.cos(d),u=s+i*Math.sin(d),t.lineTo(l,u)},W=function(t,e,s,r,i,n,a,h,o,l,u,d,g){var c;(function(t,e,s,r,i,n,a){var h,o,l,u,d,g=new T(e,s,r,i,n),c=g.minWidth,p=g.minHeight,f=r>=c?1:r/c,v=i>=p?1:i/p,y=g.cornerRadius;t.save(),t.beginPath(),t.translate(e,s),h=y.tl,F(h)?(o=h.x*f,l=h.y*v,C(h)?L(t,o,l,o,l,180,270,!1,a):L(t,0,0,o,l,90,0,!0,a),u=0,d=l):(t.lineTo(0,0),u=0,d=0),h=y.tr,F(h)?(o=h.x*f,l=h.y*v,C(h)?L(t,r-o,l,o,l,270,360,!1,a):L(t,r,0,o,l,180,90,!0,a)):t.lineTo(r,0),h=y.br,F(h)?(o=h.x*f,l=h.y*v,C(h)?L(t,r-o,i-l,o,l,0,90,!1,a):L(t,r,i,o,l,270,180,!0,a)):t.lineTo(r,i),h=y.bl,F(h)?(o=h.x*f,l=h.y*v,C(h)?L(t,o,i-l,o,l,90,180,!1,a):L(t,0,i,o,l,360,270,!0,a)):t.lineTo(0,i),t.lineTo(u,d),t.closePath(),t.restore()}(e,s,r,i,n,a,g),null!=h)&&(null!=u&&((c=d?e.createLinearGradient(0,0,i,0):e.createLinearGradient(0,0,0,n)).addColorStop(0,h),c.addColorStop(1,u),h=c),e.fillStyle=h,e.fill());null!=o&&l>0&&(e.strokeStyle=o,e.lineWidth=l,e.stroke())},R={draw(t,e,s,r){var i=this.penManager;this.hitAreaManager.clear();var n=this.context;n.save();var a=this.defaultStyle;this.clear(),function(t,e,s,r,i,n,a,h){if(null!=e||null!=s){var o=t.canvas.width,l=t.canvas.height;null==s&&(r=0);var u=r/2;o=Math.max(1,o-r),l=Math.max(1,l-r),W(t.canvas,t.context,u,u,o,l,i,e,s,r,n,a,h)}}(this,a.backgroundColor,a.backgroundStrokeColor,a.backgroundStrokeLineWidth,a.backgroundCornerRadius,a.backgroundColor2,a.backgroundHorizontalGradient,a.backgroundCornerIteration),t+=this.startXOffset,e+=this.startYOffset;var h,o,l,u,d,g,c=a.halign,p=a.valign,f=a.lineHeight,v=i.lines,y=v.length,x=a.maxLines;x>0&&y>x?(o=x,l="center"===p?Math.floor((y-o)/2):"bottom"===p?y-o:0):(o=y,l=0),u=l+o;var w=this.rtl,k=w?this.parent.width:void 0;g="center"===p?Math.max((r-o*f)/2,0):"bottom"===p?Math.max(r-o*f-2,0):0,g+=e;for(var S=l;S<u;S++)if(0!==(h=i.getLineWidth(S))){for(var m=v[S],T=m.length,P=c,b=0;b<T;b++){var O=m[b].prop.align;if(void 0!==O){P=O;break}}for(d="center"===P?(s-h)/2:"right"===P?w?0:s-h:w?s-h:0,d+=t,b=0;b<T;b++)this.drawPen(m[b],d,g,k)}n.restore()},drawPen(t,e,s,r){e+=t.x,s+=t.y+(t.prop.y||0),void 0!==r&&(e=r-e);var i=this.canvas,n=this.context;n.save();var a=this.parser.propToContextStyle(this.defaultStyle,t.prop);if(null!==a.bgcolor&&t.width>0){var h=this.defaultStyle.metrics,o=s-h.ascent,l=h.fontSize;this.drawRectangle(e,o,t.width,l,a.bgcolor,a)}if(a.underlineThickness>0&&t.width>0){var u=s+a.underlineOffset-a.underlineThickness/2;this.drawLine(e,u,t.width,a.underlineThickness,a.underlineColor,a)}if(t.isTextPen&&(a.buildFont(),a.syncFont(i,n),a.syncStyle(i,n),this.drawText(e,s,t.text,a)),t.isImagePen&&this.drawImage(e,s,t.prop.img,t.prop.color,a),a.strikethroughThickness>0&&t.width>0&&(u=s+a.strikethroughOffset-a.strikethroughThickness/2,this.drawLine(e,u,t.width,a.strikethroughThickness,a.strikethroughColor,a)),n.restore(),t.hasAreaMarker&&t.width>0){var d,g=t.prop.area;if(g)d={key:g};else{var c=t.prop.url;d={key:`url:${c}`,url:c}}this.hitAreaManager.add(e,s-this.startYOffset,t.width,this.defaultStyle.lineHeight,d)}},clear(){var t=this.canvas;this.context.clearRect(0,0,t.width,t.height)},drawRectangle(t,e,s,r,i,n){this.autoRound&&(t=Math.round(t),e=Math.round(e));var a=this.context;a.fillStyle=i,a.fillRect(t,e,s,r)},drawLine(t,e,s,r,i,n){this.autoRound&&(t=Math.round(t),e=Math.round(e));var a=this.context;n.syncShadow(a,n.shadowStroke);var h=a.lineCap;a.lineCap="butt",a.strokeStyle=i,a.lineWidth=r,a.beginPath(),a.moveTo(t,e),a.lineTo(t+s,e),a.stroke(),a.lineCap=h},drawText(t,e,s,r){this.autoRound&&(t=Math.round(t),e=Math.round(e));var i=this.context,n=r.letterSpacing;if(0===n)r.stroke&&"none"!==r.stroke&&r.strokeThickness>0&&(r.syncShadow(i,r.shadowStroke),i.strokeText(s,t,e)),r.color&&"none"!==r.color&&(r.syncShadow(i,r.shadowFill),i.fillText(s,t,e));else for(var a=s.split(""),h=0,o=a.length;h<o;h++){var l=a[h];r.stroke&&"none"!==r.stroke&&r.strokeThickness>0&&(r.syncShadow(i,r.shadowStroke),i.strokeText(l,t,e)),r.color&&"none"!==r.color&&(r.syncShadow(i,r.shadowFill),i.fillText(l,t,e)),t+=i.measureText(l).width+n}},drawImage(t,e,s,r,i){e-=this.startYOffset,this.parent.imageManager.draw(s,this.context,t,e,r,this.autoRound)}};const A=Phaser.Utils.Objects.GetValue,z=d,I=g;class _{constructor(t){this.prop={},this.resetFromJSON(t)}resetFromJSON(t){this.text=A(t,"text",""),this.x=A(t,"x",0),this.y=A(t,"y",0),this.width=A(t,"width",0);var e=A(t,"prop",null);null===e&&(e={}),this.prop=e,this.newLineMode=A(t,"newLineMode",0),this.startIndex=A(t,"startIndex",0)}get plainText(){var t=this.text;return this.newLineMode===I&&(t+="\n"),t}get wrapText(){var t=this.text;return this.newLineMode!==z&&(t+="\n"),t}get rawTextLength(){var t=this.text.length;return this.newLineMode===I&&(t+=1),t}get endIndex(){return this.startIndex+this.rawTextLength}get lastX(){return this.x+this.width}get isTextPen(){return""!==this.text}get isImagePen(){return!!this.prop.img}get hasAreaMarker(){return!!this.prop.area||!!this.prop.url}}var H=function(t,e){var s=Array.isArray(t);if(void 0===e?e=s?[]:{}:function(t){if("object"!=typeof t||null===t)return t;if(Array.isArray(t))t.length=0;else for(var e in t)delete t[e]}(e),s){e.length=t.length;for(var r=0,i=t.length;r<i;r++)e[r]=t[r]}else for(var n in t)e[n]=t[n];return e},B=function(){};const X=Phaser.Utils.Objects.GetFastValue,$=d,Y=c;class j{constructor(t){this.pens=[],this.lines=[],this.maxLinesWidth=void 0,this.pensPool=t.pensPool,this.linesPool=t.linesPool,this.tagToText=X(t,"tagToText",B),this.tagToTextScope=X(t,"tagToTextScope",void 0)}destroy(){this.clear(),this.tagToText=void 0,this.tagToTextScope=void 0}clear(){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}addTextPen(t,e,s,r,i,n){var a=this.pensPool.pop();return null==a&&(a=new _),U.text=t,U.x=e,U.y=s,U.width=r,U.prop=i,U.newLineMode=n,a.resetFromJSON(U),this.addPen(a),this}addImagePen(t,e,s,r){return this.addTextPen("",t,e,s,r,$),this}addNewLinePen(){var t=this.lastPen,e=t?t.lastX:0,s=t?t.y:0,r=t?H(t.prop):null;return this.addTextPen("",e,s,0,r,Y),this}addPen(t){var e=this.lastPen;t.startIndex=null==e?0:e.endIndex,this.pens.push(t);var s=this.lastLine;null==s&&(s=this.linesPool.pop()||[],this.lines.push(s)),s.push(t),t.newLineMode!==$&&(s=this.linesPool.pop()||[],this.lines.push(s)),this.maxLinesWidth=void 0}clone(t){null==t&&(t=new j),t.clear();for(var e=0,s=this.lines.length;e<s;e++)for(var r=this.lines[e],i=0,n=r.length;i<n;i++){var a=r[i];t.addPen(a.text,a.x,a.y,a.width,H(a.prop),a.newLineMode)}return t}get lastPen(){return this.pens[this.pens.length-1]}get lastLine(){return this.lines[this.lines.length-1]}getLineStartIndex(t){if(t>=this.lines.length)return this.getLineEndIndex(t);var e=this.lines[t];return e&&e[0]?e[0].startIndex:0}getLineEndIndex(t){t>=this.lines.length&&(t=this.lines.length-1);var e,s,r=!1;for(e=t;e>=0&&!(r=null!=(s=this.lines[e])&&s.length>0);e--);return r?s[s.length-1].endIndex:0}getLineWidth(t){var e=this.lines[t];if(!e)return 0;var s=e[e.length-1];return null==s?0:s.lastX}getMaxLineWidth(){if(void 0!==this.maxLinesWidth)return this.maxLinesWidth;for(var t,e=0,s=0,r=this.lines.length;s<r;s++)(t=this.getLineWidth(s))>e&&(e=t);return this.maxLinesWidth=e,e}getLineWidths(){for(var t=[],e=0,s=this.lines.length;e<s;e++)t.push(this.getLineWidth(e));return t}get linesCount(){return this.lines.length}get plainText(){for(var t="",e=this.pens,s=0,r=e.length;s<r;s++)t+=e[s].plainText;return t}get rawTextLength(){for(var t=0,e=this.pens,s=0,r=this.pens.length;s<r;s++)t+=e[s].rawTextLength;return t}getSliceTagText(t,e,s){var r=this.lastPen;if(null==r)return"";var i=r.endIndex;void 0!==t&&0!==t||(t=-1),void 0!==e&&e!==i||(e=i+1),void 0===s&&(s=!1);for(var n,a,h,o,l,u,d="",g=0,c=this.pens.length;g<c&&((o=(n=this.pens[g]).endIndex)<=t||(n=this.pens[g],a=s?n.wrapText:n.plainText,l=n.prop,(h=n.startIndex)>=t&&o<=e||(a=a.substring(t-h,e-h)),this.tagToTextScope?d+=this.tagToText.call(this.tagToTextScope,a,l,u):d+=this.tagToText(a,l,u),u=l,!(o>=e)));g++);return d}get length(){return this.lines.length}set length(t){this.clear()}}var U={};class D{constructor(){this.items=[]}destroy(){this.clear(),this.items=void 0}pop(){return this.items.length>0?this.items.pop():null}push(t){return this.items.push(t),this}pushMultiple(t){return this.items.push.apply(this.items,t),t.length=0,this}clear(){return this.items.length=0,this}}const G=Phaser.Geom.Rectangle;var N=new D;class K{constructor(){this.hitAreas=[]}destroy(){this.clear()}clear(){for(var t=0,e=this.hitAreas.length;t<e;t++)this.hitAreas[t].data=null;return N.pushMultiple(this.hitAreas),this}add(t,e,s,r,i){void 0===i&&(i={});var n=N.pop();return null===n?n=new G(t,e,s,r):n.setTo(t,e,s,r),n.data=i,this.hitAreas.push(n),this}getFirst(t,e){for(var s=0,r=this.hitAreas.length;s<r;s++){var i=this.hitAreas[s];if(i.contains(t,e))return i}return null}getByKey(t){for(var e=0,s=this.hitAreas.length;e<s;e++){var r=this.hitAreas[e];if(r.data.key===t)return r}return null}drawBounds(t,e,s){void 0===e&&(e=16777215),s&&t.save().translateCanvas(s.x,s.y).rotateCanvas(s.rotation).scaleCanvas(s.scaleX,s.scaleY);for(var r=0,i=this.hitAreas.length;r<i;r++){var n=this.hitAreas[r];t.lineStyle(1,e).strokeRect(n.x,n.y,n.width,n.height)}return s&&t.restore(),this}}var V=function(t,e,s,r){var i=this.hitAreaManager.getFirst(e,s);if(null!==i){var n=i.data.key;E.call(this,"areadown",n,t,e,s,r),i.data&&(i.data.isDown=!0)}},J=function(t,e,s,r){var i=this.hitAreaManager.getFirst(e,s);if(null!==i){var n=i.data.key;if(E.call(this,"areaup",n,t,e,s,r),i.data){if(i.data.isDown){if(E.call(this,"areaclick",n,t,e,s,r),!i.data)return;var a=i.data.url;a&&window.open(a,"_blank")}i.data.isDown=!1}}},q=function(t,e,s,r){if(null!==e){var i=(a=this.hitAreaManager.getFirst(e,s))?a.data.key:null;if(this.lastHitAreaKey!==i){if(null!==this.lastHitAreaKey){E.call(this,"areaout",this.lastHitAreaKey,t,e,s,r);var n=this.hitAreaManager.getByKey(this.lastHitAreaKey);n&&(this.urlTagCursorStyle&&Q(this.scene,n,""),n.data.isDown=!1)}null!==i&&(E.call(this,"areaover",i,t,e,s,r),a.data&&this.urlTagCursorStyle&&Q(this.scene,a,this.urlTagCursorStyle)),this.lastHitAreaKey=i}}else{var a;null!==this.lastHitAreaKey&&(E.call(this,"areaout",this.lastHitAreaKey,t,e,s,r),(a=this.hitAreaManager.getByKey(this.lastHitAreaKey))&&a.data&&(a.data.isDown=!1),this.lastHitAreaKey=null)}},E=function(t,e,s,r,i,n){this.parent.emit(`${t}-${e}`,s,r,i,n),this.parent.emit(t,e,s,r,i,n)},Q=function(t,e,s){e&&e.data&&e.data.url&&(t.input.manager.canvas.style.cursor=s)};const Z=Phaser.GameObjects.Components.TransformMatrix,tt=Phaser.Math.TransformXY;var et,st,rt={},it=/^[\x00-\x7F]+$/,nt=function(t){return it.test(t)};const at=d,ht=g,ot=c,lt=p,ut=f,dt=v,gt=y;var ct=function(t,e,s,r,i,n,a){r<=0&&(s=lt);var h=[];if(!t||!t.length)return h;for(var o,l,u,d=s===lt,g=t.split(gt),c=0,p=g.length;c<p;c++)if(o=g[c],u=c===p-1?at:ht,d){var f=e.measureText(o).width+i*o.length;h.push(a.getLine(o,f,u))}else{if(l=0===c?r-n:r,o.length<=100&&(f=e.measureText(o).width+i*o.length)<=l){h.push(a.getLine(o,f,u));continue}for(var v,y,x,w=pt(o,s),k="",S=0,m=0,T=w.length;m<T;m++){if(v=w[m],(y=e.measureText(v).width+i*v.length)>r&&ft(v)){""!==k?h.push(a.getLine(k,S,ot)):0===m&&n>0&&h.push(a.getLine("",0,ot)),h.push(...ct(v,e,dt,r,i,0,a));var P=h.pop();k=P.text,S=P.width,a.freeLine(P)," "===k&&(k="",S=0)}else(x=S+y)>l?(h.push(a.getLine(k,S,ot)),k=v,S=y,l=r):(k+=v,S=x);m===T-1&&h.push(a.getLine(k,S,u))}}return h},pt=function(t,e){var s;switch(e){case ut:s=[];for(var r=0,i=(t=t.split(" ")).length;r<i;r++){var n=t[r];r<i-1?s.push(n+" "):""!==n&&s.push(n)}break;case dt:s=t.split("");break;default:for(s=[],r=0,i=(t=t.split(" ")).length;r<i;r++)n=t[r],r<i-1?nt(n)?s.push(n+" "):(s.push(...n.split("")),s.push(" ")):""!==n&&(nt(n)?s.push(n):s.push(...n.split("")))}return s},ft=function(t){switch(t.length){case 1:return!1;case 2:return" "!==t.charAt(1);default:return!0}};const vt=Phaser.Utils.Objects.GetValue,yt=p,xt=d,wt=c;class kt{constructor(t){this.parent=t.parent,this.scene=this.parent.scene,this.context=vt(t,"context",null),this.canvas=this.context.canvas,this.parser=vt(t,"parser",null),this.defaultStyle=vt(t,"style",null),this.autoRound=!0,this.pensPool=t.pensPool,this.linesPool=t.linesPool,this.wrapTextLinesPool=t.wrapTextLinesPool,this.penManager=this.newPenManager(),this._tmpPenManager=null,this.hitAreaManager=new K,this.lastHitAreaKey=null,this.urlTagCursorStyle=null}destroy(){this.parent=void 0,this.scene=void 0,this.context=void 0,this.canvas=void 0,this.parser=void 0,this.defaultStyle=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),this.pensPool=void 0,this.linesPool=void 0,this.wrapTextLinesPool=void 0}updatePenManager(t,e,s,r,i){if(void 0===i&&(i=this.penManager),i.clear(),""===t)return i;var n=this.parent.style;if(n.isWrapFitMode){var a=this.parent.padding;s=n.fixedWidth-a.left-a.right}for(var h,o,l,u,d,g=this.canvas,c=this.context,p=0,f=0,v=n.wrapCallback,y=n.wrapCallbackScope,x=!v,w=!0,k=this.parser.splitText(t),S=this.wrapTextLinesPool,m=0,T=k.length;m<T;m++)if(h=(u=this.parser.tagTextToProp(k[m],o)).plainText,(o=u.prop).img){var P=this.imageManager.getOuterWidth(o.img);s>0&&e!==yt&&s<p+P&&(i.addNewLinePen(),f+=r,p=0),i.addImagePen(p,f,P,H(o)),p+=P}else if(""!==h){if(c.save(),(l=this.parser.propToContextStyle(this.defaultStyle,o)).buildFont(),l.syncFont(g,c),l.syncStyle(g,c),x)d=ct(h,c,e,s,l.letterSpacing,p,S);else{"string"==typeof(d=v.call(y,h,c,s,l.letterSpacing,p))&&(d=d.split("\n"));for(var b=0,O=d.length;b<O;b++)"string"==typeof(M=d[b])?d[b]=S.getLine(M,c.measureText(M).width,b<O-1?wt:xt):w=!1}var M;for(b=0,O=d.length;b<O;b++)M=d[b],i.addTextPen(M.text,p,f,M.width,H(o),M.newLineMode),M.newLineMode!==xt?(p=0,f+=r):p+=M.width;w&&S.freeLines(d),d=null,c.restore()}for(m=0,T=this.lines.length;m<T;m++){var C=this.lines[m],F=C[C.length-1];F&&(F.width+=this.parser.getStrokeThinkness(this.defaultStyle,F.prop),F.width-=this.parser.getLetterSpacing(this.defaultStyle,F.prop))}return i}get startXOffset(){return this.defaultStyle.xOffset}get startYOffset(){return this.defaultStyle.metrics.ascent}get lines(){return this.penManager.lines}get displayLinesCount(){var t=this.penManager.linesCount,e=this.defaultStyle.maxLines;return e>0&&t>e&&(t=e),t}get linesWidth(){return Math.ceil(this.penManager.getMaxLineWidth())}get linesHeight(){var t=this.displayLinesCount,e=this.defaultStyle.lineHeight*t;return t>0&&(e-=this.defaultStyle.lineSpacing),e}get imageManager(){return this.parent.imageManager}get rtl(){return this.parent.style.rtl}newPenManager(){return new j({pensPool:this.pensPool,linesPool:this.linesPool,tagToText:this.parser.propToTagText,tagToTextScope:this.parser})}get tmpPenManager(){return null===this._tmpPenManager&&(this._tmpPenManager=this.newPenManager()),this._tmpPenManager}getPlainText(t,e,s){var r;if(null==t)r=this.penManager.plainText;else{var i=this.parser.splitText(t,1);r="";for(var n=0,a=i.length;n<a;n++)r+=i[n]}return null==e&&null==s||(null==e&&(e=0),null==s&&(s=r.length),r=r.substring(e,s)),r}getPenManager(t,e){if(void 0===t)return this.copyPenManager(e,this.penManager);void 0===e&&(e=this.newPenManager());var s=this.defaultStyle;return this.updatePenManager(t,s.wrapMode,s.wrapWidth,s.lineHeight,e),e}getText(t,e,s,r){if(null==t)return this.penManager.getSliceTagText(e,s,r);var i=this.tmpPenManager,n=this.defaultStyle;return this.updatePenManager(t,n.wrapMode,n.wrapWidth,n.lineHeight,i),i.getSliceTagText(e,s,r)}copyPenManager(t,e){return void 0===e&&(e=this.penManager),e.copy(t)}getTextWidth(t){return void 0===t&&(t=this.penManager),t.getMaxLineWidth()}getLastPen(t){return void 0===t&&(t=this.penManager),t.lastPen}}var St={setInteractive:function(){this.parent.on("pointerdown",V,this).on("pointerup",J,this).on("pointermove",q,this).on("pointerover",q,this).on("pointerout",(function(t,e){q.call(this,t,null,null,e)}),this)},getHitArea:function(t,e,s){var r=function(t,e,s,r,i){void 0===r&&(r=t.scene.cameras.main),void 0===i?i={}:!0===i&&(i=rt);var n=r.scrollX,a=r.scrollY,h=e+n*t.scrollFactorX-n,o=s+a*t.scrollFactorY-a;return t.parentContainer?(void 0===et&&(et=new Z,st=new Z),t.getWorldTransformMatrix(et,st),et.applyInverse(h,o,i)):tt(h,o,t.x,t.y,t.rotation,t.scaleX,t.scaleY,i),i.x+=t.displayOriginX,i.y+=t.displayOriginY,i}(this.parent,t,e,s,!0),i=this.hitAreaManager.getFirst(r.x,r.y);if(null!==i)return i.data.key}};Object.assign(kt.prototype,R,St);class mt extends D{freeLine(t){if(t)return this.push(t),this}freeLines(t){if(t)return this.pushMultiple(t),this}getLine(t,e,s){var r=this.pop();return null===r&&(r={}),r.text=t,r.width=e,r.newLineMode=s,r}}const Tt=Phaser.Utils.Objects.IsPlainObject,Pt=Phaser.Utils.Objects.GetValue;var bt=function(t,e){Tt(t)?t=(e=t).key:void 0===e&&(e={key:t}),e.hasOwnProperty("key")||(e.key=t);var s=e.key,r=e.frame,i=e.width,n=e.height;if(void 0===i||void 0===n){var a=this.textureManager.getFrame(s,r),h=a?a.cutWidth:0,o=a?a.cutHeight:0;void 0===i&&void 0===n?(i=h,n=o):void 0===i?i=h*(n/o):void 0===n&&(n=o*(i/h))}this.images[t]={key:s,frame:r,width:i,height:n,y:Pt(e,"y",0),left:Pt(e,"left",0),right:Pt(e,"right",0),originX:Pt(e,"originX",0),originY:Pt(e,"originY",0),tintFill:Pt(e,"tintFill",!1)}};const Ot=Phaser.Display.Canvas.CanvasPool;class Mt{constructor(t){this.textureManager=t.sys.textures,this.images={}}destroy(){this.textureManager=void 0,this.images=void 0}add(t,e){if("string"==typeof t)bt.call(this,t,e);else if(Array.isArray(t))for(var s=0,r=(i=t).length;s<r;s++)bt.call(this,i[s]);else{var i=t;for(var t in i)bt.call(this,t,i[t])}return this}has(t){return this.images.hasOwnProperty(t)}remove(t){return this.has(t)&&delete this.images[t],this}get(t){return this.has(t)||this.textureManager.exists(t)&&this.add(t),this.images[t]}getOuterWidth(t){var e=this.get(t);return e?e.width+e.left+e.right:0}getFrame(t){var e=this.get(t);return e?this.textureManager.getFrame(e.key,e.frame):void 0}hasTexture(t){return!!this.getFrame(t)}}var Ct={draw:function(t,e,s,r,i,n){var a=this.get(t);if(a){var h=this.textureManager.getFrame(a.key,a.frame),o=a.width,l=a.height;s+=a.left-a.originX*o,r+=a.y-a.originY*l,a.tintFill||(i=void 0),function(t,e,s,r,i,n,a,h){void 0===s&&(s=0),void 0===r&&(r=0),void 0===i&&(i=t.cutWidth),void 0===n&&(n=t.cutHeight),void 0===h&&(h=!1),h&&(s=Math.round(s),r=Math.round(r));var o=e.getContext("2d",{willReadFrequently:!0});if(a){var l=Ot.create(null,i,n,Phaser.CANVAS,!0),u=l.getContext("2d",{willReadFrequently:!0});u.drawImage(t.source.image,t.cutX,t.cutY,t.cutWidth,t.cutHeight,0,0,i,n),u.globalCompositeOperation="source-in",u.fillStyle=a,u.fillRect(0,0,i,n),o.drawImage(l,0,0,i,n,s,r,i,n),Ot.remove(l)}else o.drawImage(t.source.image,t.cutX,t.cutY,t.cutWidth,t.cutHeight,s,r,i,n)}(h,e.canvas,s,r,o,l,i,n)}}};Object.assign(Mt.prototype,Ct);const Ft=Phaser.Utils.Objects.IsPlainObject,Lt=Phaser.DOM.AddToDOM,Wt=Phaser.Display.Canvas.CanvasPool,Rt=Phaser.GameObjects.GameObject,At=Phaser.Utils.Objects.GetValue,zt=Phaser.DOM.RemoveFromDOM,It=y,_t=Phaser.Utils.String.UUID,Ht=Phaser.Renderer.WebGL.RenderNodes.Defaults.DefaultImageNodes;var Bt=null,Xt=null,$t=null;class Yt extends i{constructor(t,e,s,r,i,n,a){if(Ft(e)){var h=e;e=At(h,"x",0),s=At(h,"y",0),r=At(h,"text",""),i=At(h,"style")}if(void 0===e&&(e=0),void 0===s&&(s=0),super(t,n),this.renderer=t.sys.game.renderer,this.setPosition(e,s),this.setOrigin(0,0),this.initRenderNodes(this._defaultRenderNodesMap),this.canvas=Wt.create(this),this._imageManager=void 0,i){if(i.hasOwnProperty("align")){var o=i.align;delete i.align,i.halign=o}i.hasOwnProperty("stroke")&&!i.hasOwnProperty("strokeThickness")&&(i.strokeThickness=1)}this.style=new S(this,i);var l,u,d,g=At(i,"images",void 0);g&&this.addImage(g),this.autoRound=!0,this._text=void 0,this.padding={left:0,right:0,top:0,bottom:0},this.width=1,this.height=1,this.dirty=!1,0===this.style.resolution&&(this.style.resolution=1),this._crop=this.resetCropObject(),this._textureKey=_t(),this.texture=t.sys.textures.addCanvas(this._textureKey,this.canvas),this.context=this.texture.context,this.frame=this.texture.get(),this.frame.source.resolution=this.style.resolution,this.renderer&&this.renderer.gl&&(this.renderer.deleteTexture(this.frame.source.glTexture),this.frame.source.glTexture=null),At(i,"sharedPool",!0)?(Bt||(Bt={},Xt=new D,$t=new mt,this.scene.game.events.once("destroy",(function(){Bt=null,Xt=null,$t=null}))),Bt.hasOwnProperty(n)||(Bt[n]=new D),l=Bt[n],u=Xt,d=$t):(l=new D,u=new D,d=new mt),this.canvasText=new kt({parent:this,context:this.context,parser:a,style:this.style,pensPool:l,linesPool:u,wrapTextLinesPool:d}),this.parser=a,this.initRTL(),i&&i.padding&&this.setPadding(i.padding),this.setText(r),this.setUrlTagCursorStyle(At(i,"urlTagCursorStyle","pointer")),At(i,"interactive",!1)&&this.setInteractive()}get _defaultRenderNodesMap(){return Ht}preDestroy(){zt(this.canvas),this.canvasText.destroy(),this.canvasText=void 0,this._imageManager&&(this._imageManager.destroy(),this._imageManager=void 0),Wt.remove(this.canvas);var t=this.texture;t&&t.destroy()}set text(t){this.setText(t)}get text(){return this._text}initRTL(){this.style.rtl&&(this.canvas.dir="rtl",this.context.direction="rtl",this.canvas.style.display="none",Lt(this.canvas,this.scene.sys.canvas),this.originX=1)}setRTL(t){void 0===t&&(t=!0);var e=this.style;if(e.rtl===t)return this;if(e.rtl=t,t?(this.canvas.dir="rtl",this.context.direction="rtl",this.canvas.style.display="none",Lt(this.canvas,this.scene.sys.canvas)):(this.canvas.dir="ltr",this.context.direction="ltr"),"left"===e.halign?e.halign="right":"right"===e.halign&&(e.halign="left"),this._imageManager){var s=this._imageManager.images;for(var r in s)s[r].originX=1-s[r].originX}return this}setText(t){return(t=function(t){return null==t?t="":Array.isArray(t)?t=t.join("\n"):"number"==typeof t&&(t=t.toString()),t}(t))===this._text||(this._text=t,this.updateText()),this}setPadding(t,e,s,r){if("object"==typeof t){var i=t,n=At(i,"x",null);null!==n?(t=n,s=n):(t=At(i,"left",0),s=At(i,"right",t));var a=At(i,"y",null);null!==a?(e=a,r=a):(e=At(i,"top",0),r=At(i,"bottom",e))}else void 0===t&&(t=0),void 0===e&&(e=t),void 0===s&&(s=t),void 0===r&&(r=e);return this.padding.left=t,this.padding.top=e,this.padding.right=s,this.padding.bottom=r,this.updateText(!1)}updateText(t){void 0===t&&(t=!0);var e=this.canvasText,s=this.style;t&&e.updatePenManager(this._text,s.wrapMode,s.wrapWidth,s.lineHeight);var r,i,n=this.padding,a=Math.ceil(e.linesWidth);0===s.fixedWidth?(this.width=a+n.left+n.right,r=a):(this.width=s.fixedWidth,(r=this.width-n.left-n.right)<a&&(r=a)),0===s.fixedHeight?(this.height=e.linesHeight+n.top+n.bottom,i=e.linesHeight):(this.height=s.fixedHeight,(i=this.height-n.top-n.bottom)<e.linesHeight&&(i=e.linesHeight));var h=this.width,o=this.height;this.updateDisplayOrigin();var l=s.resolution;h*=l,o*=l,h=Math.max(Math.ceil(h),1),o=Math.max(Math.ceil(o),1);var u=this.canvas,d=this.context;u.width!==h||u.height!==o?(u.width=h,u.height=o,this.frame.setSize(h,o),this.frame.source.updateSize(h,o),this.frame.updateUVs()):d.clearRect(0,0,h,o),d.save(),d.scale(l,l);var g=this.style.rtl?n.right:n.left,c=n.top;e.draw(g,c,r,i),d.restore(),this.renderer&&this.renderer.gl&&(this.frame.source.glTexture=this.renderer.canvasToTexture(u,this.frame.source.glTexture,!0),this.frame.glTexture.spectorMetadata={textureKey:"BBCodeText Game Object"}),this.dirty=!0;var p=this.input;return p&&!p.customHitArea&&(p.hitArea.width=this.width,p.hitArea.height=this.height),this}toJSON(){var t=Components.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}setInteractive(t,e,s){var r=!!this.input;return Rt.prototype.setInteractive.call(this,t,e,s),r||this.canvasText.setInteractive(),this}setUrlTagCursorStyle(t){return this.urlTagCursorStyle=t,this}get urlTagCursorStyle(){return this.canvasText.urlTagCursorStyle}set urlTagCursorStyle(t){this.canvasText.urlTagCursorStyle=t}getWrappedText(t,e,s){return"number"==typeof t&&(s=e,e=t,t=void 0),(t=this.canvasText.getText(t,e,s,!0)).split(It)}getPlainText(t,e,s){return"number"==typeof t&&(s=e,e=t,t=void 0),this.canvasText.getPlainText(t,e,s)}getText(t,e,s,r){return"number"==typeof t&&(r=s,s=e,e=t,t=void 0),void 0===r&&(r=!1),this.canvasText.getText(t,e,s,r)}getSubString(t,e,s){return"number"==typeof t&&(s=e,e=t,t=void 0),this.getText(t,e,s)}copyPenManager(t){return this.canvasText.copyPenManager(t)}getPenManager(t,e){return this.canvasText.getPenManager(t,e)}setSize(t,e){return this.setFixedSize(t,e)}resize(t,e){return this.setFixedSize(t,e)}get imageManager(){return this._imageManager||(this._imageManager=new Mt(this.scene)),this._imageManager}addImage(t,e){return this.imageManager.add(t,e),this}drawAreaBounds(t,e){return this.canvasText.hitAreaManager.drawBounds(t,e,this),this}generateTexture(t,e,s,r,i){var n=this.canvas;return void 0===r?r=n.width:r*=this.resolution,void 0===i?i=n.height:i*=this.resolution,function(t,e,s,r,i,n,a){var h,o=t.sys.textures,l=t.renderer;void 0===r&&(r=0),void 0===i&&(i=0),void 0===n&&(n=e.width),void 0===a&&(a=e.height);var u=(h=o.exists(s)?o.get(s):o.createCanvas(s,n,a)).getSourceImage();u.width!==n&&(u.width=n),u.height!==a&&(u.height=a);var d=u.getContext("2d",{willReadFrequently:!0});d.clearRect(0,0,n,a),d.drawImage(e,r,i,n,a),l.gl&&h&&l.canvasToTexture(u,h.source[0].glTexture,!0,0)}(this.scene,n,t,e,s,r,i),this}getHitArea(t,e,s){return this.canvasText.getHitArea(t,e,s)}}var jt={appendText:function(t,e){var s;return t||0===t||(t=""),void 0===e&&(e=!0),Array.isArray(t)&&(t=t.join("\n")),(s=e?`${this.text}\n${t}`:`${this.text}${t}`)!=this.text&&this.setText(s),this}};Object.assign(Yt.prototype,jt);var Ut={plainText:null,prevProp:null},Dt=new S;class Gt{constructor(t){void 0===t&&(t={}),this.tags=t}addTag(t,e){this.tags[t]=e}getTag(t){return this.tags[t]}splitText(t,e){for(var s=[],r=0;;){var i=Vt.exec(t);if(!i)break;var n=i[0],a=Vt.lastIndex-n.length;if(r<a&&s.push(t.substring(r,a)),void 0===e)s.push(n);else if(1===e)if(Jt.test(n)){var h=n.match(qt);s.push(h[2])}else Et.test(n)&&(h=n.match(Qt),s.push(h[2]));r=Vt.lastIndex}var o=t.length;return r<o&&s.push(t.substring(r,o)),s}tagTextToProp(t,e){var s,r;if(Jt.test(t)){if(null!=(a=t.match(qt))){var i=a[1],n=this.tags;(r=n.hasOwnProperty(i)?n[i]:{})._class=i,s=a[2]}}else if(Et.test(t)){var a;if(null!=(a=t.match(Qt))){var h=a[1];(r=Nt(h))._style=h,s=a[2]}}null==s&&(s=t),null==r&&(r={});var o=Ut;return o.plainText=s,o.prop=r,o}propToContextStyle(t,e){var s=Dt;if(e.hasOwnProperty("img"))s.image=e.img;else{if(s.image=null,e.hasOwnProperty("family")||e.hasOwnProperty("fontFamily")||e.hasOwnProperty("font-family")){var r=e.hasOwnProperty("family")?e.family:e.hasOwnProperty("fontFamily")?e.fontFamily:e["font-family"];s.fontFamily=r}else s.fontFamily=t.fontFamily;if(e.hasOwnProperty("size")||e.hasOwnProperty("fontSize")||e.hasOwnProperty("font-size")){var i=e.hasOwnProperty("size")?e.size:e.hasOwnProperty("fontSize")?e.fontSize:e["font-size"];"number"==typeof i&&(i=`${i}px`),s.fontSize=i}else s.fontSize=t.fontSize;if(e.hasOwnProperty("style")||e.hasOwnProperty("fontStyle")||e.hasOwnProperty("font-style")){var n=e.hasOwnProperty("style")?e.style:e.hasOwnProperty("fontStyle")?e.fontStyle:e["font-style"];s.fontStyle=n}else s.fontStyle=t.fontStyle;if(e.hasOwnProperty("color")||e.hasOwnProperty("font-color")){var a=e.hasOwnProperty("color")?e.color:e["font-color"];s.color=a}else s.color=t.color;if(e.hasOwnProperty("stroke")){var h=e.stroke;s.stroke=h.hasOwnProperty("color")?h.color:t.stroke,s.strokeThickness=h.hasOwnProperty("thickness")?h.thickness:t.strokeThickness}else s.stroke=t.stroke,s.strokeThickness=t.strokeThickness}if(e.hasOwnProperty("shadow")){var o=e.shadow;s.shadowColor=o.hasOwnProperty("color")?o.color:t.shadowColor,s.shadowOffsetX=o.hasOwnProperty("offsetX")?o.offsetX:t.shadowOffsetX,s.shadowOffsetY=o.hasOwnProperty("offsetY")?o.offsetY:t.shadowOffsetY,s.shadowBlur=o.hasOwnProperty("blur")?o.blur:t.shadowBlur,s.shadowStroke=!0,s.shadowFill=!0}else s.shadowColor=t.shadowColor,s.shadowOffsetX=t.shadowOffsetX,s.shadowOffsetY=t.shadowOffsetY,s.shadowBlur=t.shadowBlur,s.shadowStroke=t.shadowStroke,s.shadowFill=t.shadowFill;if(e.hasOwnProperty("u")||e.hasOwnProperty("underline")){var l=e.hasOwnProperty("u")?e.u:e.underline;s.underlineColor=l.hasOwnProperty("color")?l.color:t.underlineColor,s.underlineThickness=l.hasOwnProperty("thickness")?l.thickness:t.underlineThickness,s.underlineOffset=l.hasOwnProperty("offset")?l.offset:t.underlineOffset}else s.underlineColor=t.underlineColor,s.underlineThickness=t.underlineThickness,s.underlineOffset=t.underlineOffset;if(e.hasOwnProperty("s")||e.hasOwnProperty("strikethrough")){var u=e.hasOwnProperty("s")?e.s:e.strikethrough;s.strikethroughColor=u.hasOwnProperty("color")?u.color:t.strikethroughColor,s.strikethroughThickness=u.hasOwnProperty("thickness")?u.thickness:t.strikethroughThickness,s.strikethroughOffset=u.hasOwnProperty("offset")?u.offset:t.strikethroughOffset}else s.strikethroughColor=t.strikethroughColor,s.strikethroughThickness=t.strikethroughThickness,s.strikethroughOffset=t.strikethroughOffset;return e.hasOwnProperty("bgcolor")?s.bgcolor=e.bgcolor:s.bgcolor=null,e.hasOwnProperty("spacing")?s.letterSpacing=e.spacing:s.letterSpacing=t.letterSpacing,s}getStrokeThinkness(t,e){var s;if(e.hasOwnProperty("stroke")){var r=e.stroke;s=r.hasOwnProperty("thickness")?r.thickness:t.strokeThickness}else s=t.strokeThickness;return s}getLetterSpacing(t,e){return e.hasOwnProperty("spacing")?e.spacing:t.letterSpacing}propToTagText(t,e,s){return e.hasOwnProperty("_class")?""===t&&this.isTextTag(e._class)?"":`<class='${e._class}'>${t}</class>`:e.hasOwnProperty("_style")?`<style='${e._style}'>${t}</style>`:t}destroy(){this.tags=void 0}isTextTag(t){var e=this.tags[t];return!!e&&null==e.img}}var Nt=function(t){for(var e,s,r,i={},n=0,a=(t=t.split(";")).length;n<a;n++)if(s=(e=t[n].split(":"))[0],r=e[1],!Kt(s)&&!Kt(r)){switch(s){case"stroke":var h=r.split(" ");r={},(o=h.length)>=1&&(r.color=h[0]),o>=2&&(r.thickness=parseInt(h[1].replace("px","")));break;case"shadow":h=r.split(" "),r={},(o=h.length)>=1&&(r.color=h[0]),o>=2&&(r.offsetX=parseInt(h[1].replace("px",""))),o>=3&&(r.offsetY=parseInt(h[2].replace("px",""))),o>=4&&(r.blur=parseInt(h[3].replace("px","")));break;case"u":case"underline":case"s":case"strikethrough":var o;h=r.split(" "),r={},(o=h.length)>=1&&(r.color=h[0]),o>=2&&(r.thickness=parseInt(h[1].replace("px",""))),o>=3&&(r.offset=parseInt(h[2].replace("px",""))),"underline"===s?s="u":"strikethrough"===s&&(s="s");break;case"y":case"spacing":r=parseFloat(r)}i[s]=r}return i},Kt=function(t){return 0===(t=t.replace(Zt,"")).length},Vt=/<\s*class=["|']([^"|']+)["|']\s*\>([\s\S]*?)<\s*\/class\s*\>|<\s*style=["|']([^"|']+)["|']\s*\>([\s\S]*?)<\s*\/style\s*\>/g,Jt=/<\s*class=/i,qt=/<\s*class=["|']([^"|']+)["|']\s*\>([\s\S]*?)<\s*\/class\s*\>/,Et=/<\s*style=/i,Qt=/<\s*style=["|']([^"|']+)["|']\s*\>([\s\S]*?)<\s*\/style\s*\>/,Zt=/^\s+|\s+$/;const te=Phaser.Utils.Objects.GetValue;return class extends Yt{constructor(t,e,s,r,i){var n=te(i,"tags",void 0);super(t,e,s,r,i,"rexTagText",new Gt(n))}addTag(t,e){return this.parser.addTag(t,e),this.updateText(!0)}addTags(t){for(var e in t)this.parser.addTag(e,t[e]);return this.updateText(!0)}getTag(t){return this.parser.getTag(t)}preDestroy(){super.preDestroy(),this.parser.destroy(),this.parser=void 0}}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).rextagtext=e();