From e65dc6db778be6acf2e3bb33622f403bf4e22d79 Mon Sep 17 00:00:00 2001 From: phirox Date: Sat, 14 Mar 2026 21:50:55 +0100 Subject: [PATCH] Allow inline horizontal alignment of BBText --- .../pixi-multistyle-text/dist/pixi-multistyle-text.umd.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Extensions/BBText/pixi-multistyle-text/dist/pixi-multistyle-text.umd.js b/Extensions/BBText/pixi-multistyle-text/dist/pixi-multistyle-text.umd.js index 6023d2cb6101..650fdab10aac 100644 --- a/Extensions/BBText/pixi-multistyle-text/dist/pixi-multistyle-text.umd.js +++ b/Extensions/BBText/pixi-multistyle-text/dist/pixi-multistyle-text.umd.js @@ -1 +1 @@ -!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("pixi.js")):"function"==typeof define&&define.amd?define(["pixi.js"],e):(t="undefined"!=typeof globalThis?globalThis:t||self).MultiStyleText=e(t.PIXI)}(this,(function(t){"use strict";function e(t){if(t&&t.__esModule)return t;var e=Object.create(null);return t&&Object.keys(t).forEach((function(s){if("default"!==s){var i=Object.getOwnPropertyDescriptor(t,s);Object.defineProperty(e,s,i.get?i:{enumerable:!0,get:function(){return t[s]}})}})),e.default=t,Object.freeze(e)}var s=e(t);if(parseInt(s.VERSION.split(".")[0],10)<5)throw new Error(`Detected Pixi.js version ${s.VERSION}. pixi-multistyle-text supports Pixi.js version 5+. (Please use v0.8.0 for Pixi 4 support.)`);const i=["pointerover","pointerenter","pointerdown","pointermove","pointerup","pointercancel","pointerout","pointerleave","gotpointercapture","lostpointercapture","mouseover","mouseenter","mousedown","mousemove","mouseup","mousecancel","mouseout","mouseleave","touchover","touchenter","touchdown","touchmove","touchup","touchcancel","touchout","touchleave"],o="bbcode",n={bbcode:["[","]"],xml:["<",">"]};class h extends s.Text{constructor(t,e){super(t),this.styles=e,i.forEach((t=>{this.on(t,(t=>this.handleInteraction(t)))}))}handleInteraction(t){let e=t,s=t.data.getLocalPosition(this),i=this.hitboxes.reduce(((t,e)=>void 0!==t?t:e.hitbox.contains(s.x,s.y)?e:void 0),void 0);e.targetTag=void 0===i?void 0:i.tag}set styles(t){this.textStyles={},this.textStyles.default=this.assign({},h.DEFAULT_TAG_STYLE);for(let e in t)"default"===e?this.assign(this.textStyles.default,t[e]):this.textStyles[e]=this.assign({},t[e]);this.textStyles.default.tagStyle===o&&(this.textStyles.b=this.assign({},{fontStyle:"bold"}),this.textStyles.i=this.assign({},{fontStyle:"italic"}),this.textStyles.color=this.assign({},{fill:""}),this.textStyles.outline=this.assign({},{stroke:"",strokeThickness:6}),this.textStyles.font=this.assign({},{fontFamily:""}),this.textStyles.shadow=this.assign({},{dropShadowColor:"",dropShadow:!0,dropShadowBlur:3,dropShadowDistance:3,dropShadowAngle:2}),this.textStyles.size=this.assign({},{fontSize:"px"}),this.textStyles.spacing=this.assign({},{letterSpacing:""}),this.textStyles.align=this.assign({},{align:""})),this.withPrivateMembers()._style=new s.TextStyle(this.textStyles.default),this.withPrivateMembers().dirty=!0}setTagStyle(t,e){t in this.textStyles?this.assign(this.textStyles[t],e):this.textStyles[t]=this.assign({},e),this.withPrivateMembers()._style=new s.TextStyle(this.textStyles.default),this.withPrivateMembers().dirty=!0}deleteTagStyle(t){"default"===t?this.textStyles.default=this.assign({},h.DEFAULT_TAG_STYLE):delete this.textStyles[t],this.withPrivateMembers()._style=new s.TextStyle(this.textStyles.default),this.withPrivateMembers().dirty=!0}getTagRegex(t,e){let s=Object.keys(this.textStyles).join("|");const{tagStyle:i}=this.textStyles.default;s=t?`(${s})`:`(?:${s})`;let h=i===o?`\\${n.bbcode[0]}${s}(?:\\=(?:[A-Za-z0-9_\\-\\#]+|'(?:[^']+|\\\\')*'))*\\s*\\${n.bbcode[1]}|\\${n.bbcode[0]}\\/${s}\\s*\\${n.bbcode[1]}`:`\\${n.xml[0]}${s}(?:\\s+[A-Za-z0-9_\\-]+=(?:"(?:[^"]+|\\\\")*"|'(?:[^']+|\\\\')*'))*\\s*\\${n.xml[1]}|\\${n.xml[0]}\\/${s}\\s*\\${n.xml[1]}`;return e&&(h=`(${h})`),new RegExp(h,"g")}getPropertyRegex(){return new RegExp("([A-Za-z0-9_\\-]+)=(?:\"((?:[^\"]+|\\\\\")*)\"|'((?:[^']+|\\\\')*)')","g")}getBBcodePropertyRegex(){return new RegExp("[A-Za-z0-9_\\-]+=([A-Za-z0-9_\\-\\#]+)","g")}_getTextDataPerLine(t){let e=[],s=this.getTagRegex(!0,!1),i=[this.assign({},this.textStyles.default)],h=[{name:"default",properties:{}}];for(let n=0;ne&&l.push(this.createTextData(t[n].substring(e,a[s].index),i[i.length-1],h[h.length-1])),"/"===a[s][0][1])i.length>1&&(i.pop(),h.pop());else{let t,e={},n=this.getPropertyRegex();for(;t=n.exec(a[s][0]);)e[t[1]]=t[2]||t[3];h.push({name:a[s][1],properties:e});const{tagStyle:r}=this.textStyles.default;if(r===o&&a[s][0].includes("=")&&this.textStyles[a[s][1]]){const t=this.getBBcodePropertyRegex().exec(a[s][0]);let e={};Object.entries(this.textStyles[a[s][1]]).forEach((s=>{e[s[0]]="string"!=typeof s[1]?s[1]:t[1]+s[1]})),i.push(this.assign({},i[i.length-1],e))}else i.push(this.assign({},i[i.length-1],this.textStyles[a[s][1]]))}e=a[s].index+a[s][0].length}if(e{t.text.includes(n[r][0])&&(t.text=t.text.match(r===o?/^(.*)\[/:/^(.*)\{let{dropShadowDistance:i,dropShadowBlur:o}=this.textStyles[s];t=Math.max(t,i||0),e=Math.max(e,o||0)})),t+e}withPrivateMembers(){return this}updateText(){if(!this.withPrivateMembers().dirty)return;this.hitboxes=[],this.texture.baseTexture.resolution=this.resolution;let t=this.textStyles,e=this.text;this.withPrivateMembers()._style.wordWrap&&(e=this.wordWrap(this.text));let i=e.split(/(?:\r\n|\r|\n)/),o=this._getTextDataPerLine(i),n=[],r=[],l=[],a=0;for(let t=0;t0&&(e+=r.letterSpacing/2),nt[e])).reduce(((t,e)=>Math.max(t,e.strokeThickness||0)),0),d=this.getDropShadowPadding(),x=a+2*c+2*d,g=l.reduce(((t,e)=>t+e),0)-r.reduce(((t,e)=>t+e),0)+2*c+2*d;this.canvas.width=x*this.resolution,this.canvas.height=g*this.resolution,this.context.scale(this.resolution,this.resolution),this.context.textBaseline="alphabetic",this.context.lineJoin="round";let p=d+c,u=[];for(let t=0;t0||i>0)&&(e+=o.letterSpacing/2);let r=this.context.measureText(n.charAt(t)).width;u.push({text:n.charAt(t),style:o,x:e,y:x,width:r,ascent:h.ascent,descent:h.descent,tag:d}),e+=r,(t{if(!t.dropShadow)return;this.context.font=this.getFontString(t);let n=t.dropShadowColor;"number"==typeof n&&(n=s.utils.hex2string(n)),this.context.shadowColor=n,this.context.shadowBlur=t.dropShadowBlur,this.context.shadowOffsetX=Math.cos(t.dropShadowAngle)*t.dropShadowDistance*this.resolution,this.context.shadowOffsetY=Math.sin(t.dropShadowAngle)*t.dropShadowDistance*this.resolution,this.context.fillText(e,i,o)})),this.context.restore(),u.forEach((({style:t,text:e,x:i,y:o,width:n,ascent:h,descent:r,tag:l})=>{if(void 0===t.stroke||!t.strokeThickness)return;this.context.font=this.getFontString(t);let a=t.stroke;"number"==typeof a&&(a=s.utils.hex2string(a)),this.context.strokeStyle=a,this.context.lineWidth=t.strokeThickness,this.context.strokeText(e,i,o)})),u.forEach((({style:t,text:e,x:i,y:o,width:n,ascent:h,descent:r,tag:l})=>{if(void 0===t.fill)return;this.context.font=this.getFontString(t);let a=t.fill;if("number"==typeof a)a=s.utils.hex2string(a);else if(Array.isArray(a))for(let t=0;t{let c=-this.withPrivateMembers()._style.padding-this.getDropShadowPadding();this.hitboxes.push({tag:a,hitbox:new s.Rectangle(i+c,o-r+c,n,r+l)}),(void 0===t.debug?h.debugOptions.spans.enabled:t.debug)&&(this.context.lineWidth=1,h.debugOptions.spans.bounding&&(this.context.fillStyle=h.debugOptions.spans.bounding,this.context.strokeStyle=h.debugOptions.spans.bounding,this.context.beginPath(),this.context.rect(i,o-r,n,r+l),this.context.fill(),this.context.stroke(),this.context.stroke()),h.debugOptions.spans.baseline&&(this.context.strokeStyle=h.debugOptions.spans.baseline,this.context.beginPath(),this.context.moveTo(i,o),this.context.lineTo(i+n,o),this.context.closePath(),this.context.stroke()),h.debugOptions.spans.top&&(this.context.strokeStyle=h.debugOptions.spans.top,this.context.beginPath(),this.context.moveTo(i,o-r),this.context.lineTo(i+n,o-r),this.context.closePath(),this.context.stroke()),h.debugOptions.spans.bottom&&(this.context.strokeStyle=h.debugOptions.spans.bottom,this.context.beginPath(),this.context.moveTo(i,o+l),this.context.lineTo(i+n,o+l),this.context.closePath(),this.context.stroke()),h.debugOptions.spans.text&&(this.context.fillStyle="#ffffff",this.context.strokeStyle="#000000",this.context.lineWidth=2,this.context.font="8px monospace",this.context.strokeText(a.name,i,o-r+8),this.context.fillText(a.name,i,o-r+8),this.context.strokeText(`${n.toFixed(2)}x${(r+l).toFixed(2)}`,i,o-r+16),this.context.fillText(`${n.toFixed(2)}x${(r+l).toFixed(2)}`,i,o-r+16)))})),h.debugOptions.objects.enabled&&(h.debugOptions.objects.bounding&&(this.context.fillStyle=h.debugOptions.objects.bounding,this.context.beginPath(),this.context.rect(0,0,x,g),this.context.fill()),h.debugOptions.objects.text&&(this.context.fillStyle="#ffffff",this.context.strokeStyle="#000000",this.context.lineWidth=2,this.context.font="8px monospace",this.context.strokeText(`${x.toFixed(2)}x${g.toFixed(2)}`,0,8,x),this.context.fillText(`${x.toFixed(2)}x${g.toFixed(2)}`,0,8,x))),this.updateTexture()}wordWrap(t){let e="",s=this.getTagRegex(!0,!0);const i=t.split("\n"),o=this.withPrivateMembers()._style.wordWrapWidth;let n=[this.assign({},this.textStyles.default)];this.context.font=this.getFontString(this.textStyles.default);for(let t=0;th){const i=s[t].split("");t>0&&(e+=" ",h-=this.context.measureText(" ").width);for(let t=0;th?(e+=`\n${i[t]}`,h=o-s):(e+=i[t],h-=s)}}else if(this.withPrivateMembers()._style.breakWords)e+=s[t],h-=i;else{const n=i+(t>0?this.context.measureText(" ").width:0);n>h?(l||(e+="\n"),e+=s[t],h=o-i):(h-=n,t>0&&(e+=" "),e+=s[t])}l=!1}}t"]};class h extends s.Text{constructor(t,e){super(t),this.styles=e,i.forEach((t=>{this.on(t,(t=>this.handleInteraction(t)))}))}handleInteraction(t){let e=t,s=t.data.getLocalPosition(this),i=this.hitboxes.reduce(((t,e)=>void 0!==t?t:e.hitbox.contains(s.x,s.y)?e:void 0),void 0);e.targetTag=void 0===i?void 0:i.tag}set styles(t){this.textStyles={},this.textStyles.default=this.assign({},h.DEFAULT_TAG_STYLE);for(let e in t)"default"===e?this.assign(this.textStyles.default,t[e]):this.textStyles[e]=this.assign({},t[e]);this.textStyles.default.tagStyle===o&&(this.textStyles.b=this.assign({},{fontStyle:"bold"}),this.textStyles.i=this.assign({},{fontStyle:"italic"}),this.textStyles.color=this.assign({},{fill:""}),this.textStyles.outline=this.assign({},{stroke:"",strokeThickness:6}),this.textStyles.font=this.assign({},{fontFamily:""}),this.textStyles.shadow=this.assign({},{dropShadowColor:"",dropShadow:!0,dropShadowBlur:3,dropShadowDistance:3,dropShadowAngle:2}),this.textStyles.size=this.assign({},{fontSize:"px"}),this.textStyles.spacing=this.assign({},{letterSpacing:""}),this.textStyles.align=this.assign({},{align:""})),this.withPrivateMembers()._style=new s.TextStyle(this.textStyles.default),this.withPrivateMembers().dirty=!0}setTagStyle(t,e){t in this.textStyles?this.assign(this.textStyles[t],e):this.textStyles[t]=this.assign({},e),this.withPrivateMembers()._style=new s.TextStyle(this.textStyles.default),this.withPrivateMembers().dirty=!0}deleteTagStyle(t){"default"===t?this.textStyles.default=this.assign({},h.DEFAULT_TAG_STYLE):delete this.textStyles[t],this.withPrivateMembers()._style=new s.TextStyle(this.textStyles.default),this.withPrivateMembers().dirty=!0}getTagRegex(t,e){let s=Object.keys(this.textStyles).join("|");const{tagStyle:i}=this.textStyles.default;s=t?`(${s})`:`(?:${s})`;let h=i===o?`\\${n.bbcode[0]}${s}(?:\\=(?:[A-Za-z0-9_\\-\\#]+|'(?:[^']+|\\\\')*'))*\\s*\\${n.bbcode[1]}|\\${n.bbcode[0]}\\/${s}\\s*\\${n.bbcode[1]}`:`\\${n.xml[0]}${s}(?:\\s+[A-Za-z0-9_\\-]+=(?:"(?:[^"]+|\\\\")*"|'(?:[^']+|\\\\')*'))*\\s*\\${n.xml[1]}|\\${n.xml[0]}\\/${s}\\s*\\${n.xml[1]}`;return e&&(h=`(${h})`),new RegExp(h,"g")}getPropertyRegex(){return new RegExp("([A-Za-z0-9_\\-]+)=(?:\"((?:[^\"]+|\\\\\")*)\"|'((?:[^']+|\\\\')*)')","g")}getBBcodePropertyRegex(){return new RegExp("[A-Za-z0-9_\\-]+=([A-Za-z0-9_\\-\\#]+)","g")}_getTextDataPerLine(t){let e=[],s=this.getTagRegex(!0,!1),i=[this.assign({},this.textStyles.default)],h=[{name:"default",properties:{}}];for(let n=0;ne&&l.push(this.createTextData(t[n].substring(e,a[s].index),i[i.length-1],h[h.length-1])),"/"===a[s][0][1])i.length>1&&(i.pop(),h.pop());else{let t,e={},n=this.getPropertyRegex();for(;t=n.exec(a[s][0]);)e[t[1]]=t[2]||t[3];h.push({name:a[s][1],properties:e});const{tagStyle:r}=this.textStyles.default;if(r===o&&a[s][0].includes("=")&&this.textStyles[a[s][1]]){const t=this.getBBcodePropertyRegex().exec(a[s][0]);let e={};Object.entries(this.textStyles[a[s][1]]).forEach((s=>{e[s[0]]="string"!=typeof s[1]?s[1]:t[1]+s[1]})),i.push(this.assign({},i[i.length-1],e))}else i.push(this.assign({},i[i.length-1],this.textStyles[a[s][1]]))}e=a[s].index+a[s][0].length}if(e{t.text.includes(n[r][0])&&(t.text=t.text.match(r===o?/^(.*)\[/:/^(.*)\{let{dropShadowDistance:i,dropShadowBlur:o}=this.textStyles[s];t=Math.max(t,i||0),e=Math.max(e,o||0)})),t+e}withPrivateMembers(){return this}updateText(){if(!this.withPrivateMembers().dirty)return;this.hitboxes=[],this.texture.baseTexture.resolution=this.resolution;let t=this.textStyles,e=this.text;this.withPrivateMembers()._style.wordWrap&&(e=this.wordWrap(this.text));let i=e.split(/(?:\r\n|\r|\n)/),o=this._getTextDataPerLine(i),n=[],r=[],l=[],a=0;for(let t=0;t0&&(e+=r.letterSpacing/2),nt[e])).reduce(((t,e)=>Math.max(t,e.strokeThickness||0)),0),d=this.getDropShadowPadding(),x=a+2*c+2*d,g=l.reduce(((t,e)=>t+e),0)-r.reduce(((t,e)=>t+e),0)+2*c+2*d;this.canvas.width=x*this.resolution,this.canvas.height=g*this.resolution,this.context.scale(this.resolution,this.resolution),this.context.textBaseline="alphabetic",this.context.lineJoin="round";let p=d+c,u=[];for(let t=0;t0||i>0)&&(e+=o.letterSpacing/2);let r=this.context.measureText(n.charAt(t)).width;u.push({text:n.charAt(t),style:o,x:e,y:x,width:r,ascent:h.ascent,descent:h.descent,tag:d}),e+=r,(t{if(!t.dropShadow)return;this.context.font=this.getFontString(t);let n=t.dropShadowColor;"number"==typeof n&&(n=s.utils.hex2string(n)),this.context.shadowColor=n,this.context.shadowBlur=t.dropShadowBlur,this.context.shadowOffsetX=Math.cos(t.dropShadowAngle)*t.dropShadowDistance*this.resolution,this.context.shadowOffsetY=Math.sin(t.dropShadowAngle)*t.dropShadowDistance*this.resolution,this.context.fillText(e,i,o)})),this.context.restore(),u.forEach((({style:t,text:e,x:i,y:o,width:n,ascent:h,descent:r,tag:l})=>{if(void 0===t.stroke||!t.strokeThickness)return;this.context.font=this.getFontString(t);let a=t.stroke;"number"==typeof a&&(a=s.utils.hex2string(a)),this.context.strokeStyle=a,this.context.lineWidth=t.strokeThickness,this.context.strokeText(e,i,o)})),u.forEach((({style:t,text:e,x:i,y:o,width:n,ascent:h,descent:r,tag:l})=>{if(void 0===t.fill)return;this.context.font=this.getFontString(t);let a=t.fill;if("number"==typeof a)a=s.utils.hex2string(a);else if(Array.isArray(a))for(let t=0;t{let c=-this.withPrivateMembers()._style.padding-this.getDropShadowPadding();this.hitboxes.push({tag:a,hitbox:new s.Rectangle(i+c,o-r+c,n,r+l)}),(void 0===t.debug?h.debugOptions.spans.enabled:t.debug)&&(this.context.lineWidth=1,h.debugOptions.spans.bounding&&(this.context.fillStyle=h.debugOptions.spans.bounding,this.context.strokeStyle=h.debugOptions.spans.bounding,this.context.beginPath(),this.context.rect(i,o-r,n,r+l),this.context.fill(),this.context.stroke(),this.context.stroke()),h.debugOptions.spans.baseline&&(this.context.strokeStyle=h.debugOptions.spans.baseline,this.context.beginPath(),this.context.moveTo(i,o),this.context.lineTo(i+n,o),this.context.closePath(),this.context.stroke()),h.debugOptions.spans.top&&(this.context.strokeStyle=h.debugOptions.spans.top,this.context.beginPath(),this.context.moveTo(i,o-r),this.context.lineTo(i+n,o-r),this.context.closePath(),this.context.stroke()),h.debugOptions.spans.bottom&&(this.context.strokeStyle=h.debugOptions.spans.bottom,this.context.beginPath(),this.context.moveTo(i,o+l),this.context.lineTo(i+n,o+l),this.context.closePath(),this.context.stroke()),h.debugOptions.spans.text&&(this.context.fillStyle="#ffffff",this.context.strokeStyle="#000000",this.context.lineWidth=2,this.context.font="8px monospace",this.context.strokeText(a.name,i,o-r+8),this.context.fillText(a.name,i,o-r+8),this.context.strokeText(`${n.toFixed(2)}x${(r+l).toFixed(2)}`,i,o-r+16),this.context.fillText(`${n.toFixed(2)}x${(r+l).toFixed(2)}`,i,o-r+16)))})),h.debugOptions.objects.enabled&&(h.debugOptions.objects.bounding&&(this.context.fillStyle=h.debugOptions.objects.bounding,this.context.beginPath(),this.context.rect(0,0,x,g),this.context.fill()),h.debugOptions.objects.text&&(this.context.fillStyle="#ffffff",this.context.strokeStyle="#000000",this.context.lineWidth=2,this.context.font="8px monospace",this.context.strokeText(`${x.toFixed(2)}x${g.toFixed(2)}`,0,8,x),this.context.fillText(`${x.toFixed(2)}x${g.toFixed(2)}`,0,8,x))),this.updateTexture()}wordWrap(t){let e="",s=this.getTagRegex(!0,!0);const i=t.split("\n"),o=this.withPrivateMembers()._style.wordWrapWidth;let n=[this.assign({},this.textStyles.default)];this.context.font=this.getFontString(this.textStyles.default);for(let t=0;th){const i=s[t].split("");t>0&&(e+=" ",h-=this.context.measureText(" ").width);for(let t=0;th?(e+=`\n${i[t]}`,h=o-s):(e+=i[t],h-=s)}}else if(this.withPrivateMembers()._style.breakWords)e+=s[t],h-=i;else{const n=i+(t>0?this.context.measureText(" ").width:0);n>h?(l||(e+="\n"),e+=s[t],h=o-i):(h-=n,t>0&&(e+=" "),e+=s[t])}l=!1}}t