@galacean/effects-plugin-rich-text 2.8.4 → 2.8.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/alipay.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@galacean/effects/alipay"),e=require("@galacean/appx-adapter/alipay");function i(t){if(t&&t.__esModule)return t;var e=Object.create(null);return t&&Object.keys(t).forEach((function(i){if("default"!==i){var n=Object.getOwnPropertyDescriptor(t,i);Object.defineProperty(e,i,n.get?n:{enumerable:!0,get:function(){return t[i]}})}})),e.default=t,Object.freeze(e)}var n=i(t);function r(t,e){return r=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},r(t,e)}function a(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&&r(t,e)}function o(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(o=function(){return!!t})()}function s(t,e,i){return s=o()?Reflect.construct:function(t,e,i){var n=[null];n.push.apply(n,e);var a=new(Function.bind.apply(t,n));return i&&r(a,i.prototype),a},s.apply(null,arguments)}function l(t){return l=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},l(t)}function c(t){var e="function"==typeof Map?new Map:void 0;return c=function(t){if(null===t||(i=t,-1===Function.toString.call(i).indexOf("[native code]")))return t;var i;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,n)}function n(){return s(t,arguments,l(this).constructor)}return n.prototype=Object.create(t.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),r(n,t)},c(t)}var h,u=function(t){function e(){var e;return(e=t.apply(this,arguments)||this).name="rich-text",e}return a(e,t),e}(c(t.Plugin));function f(t,e){(null==e||e>t.length)&&(e=t.length);for(var i=0,n=new Array(e);i<e;i++)n[i]=t[i];return n}function p(t,e){var i="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(i)return(i=i.call(t)).next.bind(i);if(Array.isArray(t)||(i=function(t,e){if(t){if("string"==typeof t)return f(t,e);var i=Object.prototype.toString.call(t).slice(8,-1);return"Object"===i&&t.constructor&&(i=t.constructor.name),"Map"===i||"Set"===i?Array.from(i):"Arguments"===i||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i)?f(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){i&&(t=i);var n=0;return function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}!function(t){t.ContextStart="ContextStart",t.Text="Text",t.ContextEnd="ContextEnd",t.EscapedChar="EscapedChar"}(h||(h={}));var x=/^<([a-z]+)(=([^>]+))?>$/,g=/^<\/([a-z]+)>$/,v=[["EscapedChar",/^\\([=<>\\/])/],["ContextStart",/^<[a-z]+(=[^>]+)?>/],["ContextEnd",/^<\/[a-z]+>/],["Text",/^[^</>=\\]+/]],d=function(t,e,i){if(void 0===e&&(e=[]),void 0===i&&(i=0),!t)return e;var n=/^\\([=<>\\/])/.exec(t);if(n){var r=n[1];return d(t.slice(2),e.concat({tokenType:"Text",value:r}),i+2)}for(var a,o=p(v);!(a=o()).done;){var s=a.value,l=s[0],c=s[1];if("EscapedChar"!==l){var h=c.exec(t);if(h){var u=h[0],f=u.length;return d(t.slice(f),e.concat({tokenType:l,value:u}),i+f)}}}if(t.length>0)return d(t.slice(1),e.concat({tokenType:"Text",value:t[0]}),i+1);throw new Error('Unexpected token: "'+t[0]+'" at position '+i+' while reading "'+t+'"')},m=function(t){var e=function(){for(var t,e="",i=!1;r.length>0&&"Text"===(null==(t=r[0])?void 0:t.tokenType);){var n=o();n&&(e+=n.value,i=!0)}return i?e:void 0},i=function(){var t=s();if("ContextStart"===(null==t?void 0:t.tokenType)){o();var e,i=t.value.match(x);if(i)return{attributeName:i[1],attributeParam:null!=(e=i[3])?e:""};throw new Error("Expected a start tag marker at position "+a)}return{}},n=function(){var t=s();if("ContextEnd"===(null==t?void 0:t.tokenType)){o();var e=t.value.match(g);if(e)return{attributeName:e[1]};throw new Error("Expect an end tag marker at position "+a)}return{}},r=d(t),a=0,o=function(){var t,e=r.shift();return a+=null!=(t=null==e?void 0:e.value.length)?t:0,e},s=function(){return r[0]},l=[];return function t(r,o){for(void 0===r&&(r=[]),void 0===o&&(o="");;){var s=e();if(s)l.push({attributes:r,text:s});else{var c=i(),h=c.attributeName,u=c.attributeParam;if(!h){if(o){var f=n().attributeName;if(!f)throw new Error('Expect an end tag marker "'+o+'" at position '+a+" but found no tag!");if(f!==o)throw new Error('Expect an end tag marker "'+o+'" at position '+a+' but found tag "'+f+'"');return}break}t(r.concat({attributeName:h,attributeParam:null!=u?u:""}),h)}}}(),l};function y(t){return function(e){for(var i,n=p(m(e));!(i=n()).done;){var r=i.value,a=r.text,o=r.attributes.reduce((function(t,e){var i=e.attributeName,n=e.attributeParam;return i&&(t[i]=n),t}),{});t(a,o)}}}"function"==typeof SuppressedError&&SuppressedError;var S=function(){function e(e){this.width=0,this.height=0;var i=e.size,n=e.textOverflow,r=void 0===n?t.spec.TextOverflow.clip:n,a=e.textVerticalAlign,o=void 0===a?t.spec.TextVerticalAlign.middle:a,s=e.textAlign,l=void 0===s?t.spec.TextAlignment.left:s,c=e.letterSpace,h=void 0===c?0:c,u=e.lineHeight,f=void 0===u?.571:u,p=e.wrapEnabled,x=void 0!==p&&p,g=e.maxTextWidth,v=void 0===g?350:g,d=e.maxTextHeight,m=void 0===d?1e3:d,y=e.sizeMode,S=void 0===y?t.spec.TextSizeMode.autoWidth:y,T=e.useLegacyRichText,b=void 0!==T&&T;this.letterSpace=h,this.lineHeight=f,this.useLegacyRichText=b,this.overflow=r,this.textVerticalAlign=o,this.textAlign=l,this.width=i?i[0]:100,this.height=i?i[1]:100,this.wrapEnabled=x;this.maxTextWidth=50*v,this.maxTextHeight=50*m,this.sizeMode=S}var i=e.prototype;return i.getOffsetY=function(e,i,n,r,a){var o=e.outlineWidth,s=e.fontScale,l=(n-r)/3,c=r+o*s,h=void 0!==a?a:n*(i-1),u=0;switch(this.textVerticalAlign){case t.spec.TextVerticalAlign.top:u=c+l;break;case t.spec.TextVerticalAlign.middle:u=(this.height*s-h+c)/2;break;case t.spec.TextVerticalAlign.bottom:u=this.height*s-h-l}return u},i.getOffsetX=function(e,i){var n=0;switch(this.textAlign){case t.spec.TextAlignment.left:n=e.outlineWidth*e.fontScale;break;case t.spec.TextAlignment.middle:n=(this.width*e.fontScale-i)/2;break;case t.spec.TextAlignment.right:n=this.width*e.fontScale-i}return n},i.getOffsetYRich=function(e,i,n){if(0===i.length)return 0;var r=e.outlineWidth,a=e.fontScale,o=i.reduce((function(t,e){return t+e}),0),s=(i[0]-n)/3,l=n+r*a,c=o-i[0],h=0;switch(this.textVerticalAlign){case t.spec.TextVerticalAlign.top:h=l+s;break;case t.spec.TextVerticalAlign.middle:h=(this.height*a-o)/2+l;break;case t.spec.TextVerticalAlign.bottom:h=this.height*a-c-s}return h},i.getOffsetXRich=function(e,i,n){switch(this.textAlign){case t.spec.TextAlignment.left:return e.outlineWidth*e.fontScale;case t.spec.TextAlignment.middle:return(i-n)/2;case t.spec.TextAlignment.right:return i-n;default:return 0}},i.setSize=function(t,e){this.width=t,this.height=e},e}();function T(t,e){if(void 0===e&&(e=1),3!==(t=t.replace(/^#/,"")).length&&4!==t.length||(t=t.split("").map((function(t){return t+t})).join("")),8===t.length){var i=parseInt(t.slice(6,8),16)/255;t=t.slice(0,6),e=i}var n=parseInt(t,16);return[n>>16&255,n>>8&255,255&n,e]}function b(t,i){if(void 0===i&&(i=1),"string"!=typeof t||!t)throw new Error("Invalid color string");return t.startsWith("#")?T(t,i):T(function(t){if("string"!=typeof t||!t)throw new Error("Invalid color name provided");if(void 0===e.document)throw new Error("This method requires a browser environment");var i=e.document.createElement("canvas"),n=i.getContext("2d");if(n)try{return n.fillStyle=t,n.fillStyle}finally{null==i.remove||i.remove.call(i)}throw new Error("Failed to get 2D context for color conversion!")}(t))}var w=function(){function t(){}var e=t.prototype;return e.computeLines=function(t,e,i,n,r,a,o,s){var l=this,c=[],h=[],u=(n.lineHeight||0)*a,f=this.createNewLine(),p=0,x=0,g=function(){if(0!==f.chars.length){f.lineHeight=0===c.length?(f.lineAscent||0)+(f.lineDescent||0):u;var t=0===c.length?0:h[h.length-1]+u;h.push(t),x+=f.lineHeight,c.push(f),p=Math.max(p,f.width),f=l.createNewLine()}};t.forEach((function(t){var n=t.text,r=t.isNewLine,l=t.fontSize;r&&g();var c=t.fontStyle||i.fontStyle||"normal";e.font=c+" "+(t.fontWeight||i.textWeight)+" 10px "+(t.fontFamily||i.fontFamily),f.offsetX.push(f.width);for(var h=0,u=[],p=0,x=0,v=0;v<n.length;v++){var d=n[v],m=e.measureText(d),y=m.width,S=(y<=0?0:y)*l*s*a,T=l*a*s,b=m.actualBoundingBoxAscent*T,w=m.actualBoundingBoxDescent*T;p=Math.max(p,b),x=Math.max(x,w),v>0&&(h+=o),u.push({char:d,x:h}),h+=S}f.chars.push(u),f.width+=h,f.richOptions.push(t),f.lineAscent=Math.max(f.lineAscent||0,p),f.lineDescent=Math.max(f.lineDescent||0,x)})),g();var v=1/0,d=-1/0;if(0===c.length)return{lines:c,maxLineWidth:p,totalHeight:x,bboxTop:0,bboxBottom:0,bboxHeight:0};for(var m=0;m<c.length;m++)v=Math.min(v,h[m]-(c[m].lineAscent||0)),d=Math.max(d,h[m]+(c[m].lineDescent||0));return{lines:c,maxLineWidth:p,totalHeight:x,bboxTop:v,bboxBottom:d,bboxHeight:d-v}},e.createNewLine=function(){return{richOptions:[],offsetX:[],width:0,lineHeight:0,offsetY:0,chars:[],lineAscent:0,lineDescent:0}},t}(),A=function(){function t(){}var e=t.prototype;return e.computeLines=function(t,e,i,n,r,a,o,s){var l=this,c=[],h=[],u=(n.lineHeight||0)*a,f=this.createNewLine(),p=0,x=0,g=null,v=0,d=[],m=null,y=function(){if(S(),0!==f.chars.length){f.lineHeight=0===c.length?(f.lineAscent||0)+(f.lineDescent||0):u;var t=0===c.length?0:h[h.length-1]+u;h.push(t),x+=f.lineHeight,c.push(f),p=Math.max(p,f.width),f=l.createNewLine(),g=null,v=0,d=[],m=null}},S=function(){0!==d.length&&(null===g&&(g=f.width),f.offsetX.push(g),f.chars.push(d),m&&f.richOptions.push(m),g=null,v=0,d=[],m=null)};t.forEach((function(t){var r=t.text,l=t.isNewLine,c=t.fontSize,h=t.fontStyle||i.fontStyle||"normal";e.font=h+" "+(t.fontWeight||i.textWeight)+" 10px "+(t.fontFamily||i.fontFamily),l&&(S(),y());for(var u=0;u<r.length;u++){var p=r[u],x=e.measureText(p),T=x.width,b=(T<=0?0:T)*c*s*a,w=c*a*s,A=x.actualBoundingBoxAscent*w,O=x.actualBoundingBoxDescent*w,C=d.length>0?o:0;f.width+C+b>(n.maxTextWidth||1/0)&&(S(),y()),null===g&&(g=f.width,m=t),d.length>0&&(v+=o,f.width+=o),d.push({char:p,x:v}),f.lineAscent=Math.max(f.lineAscent||0,A),f.lineDescent=Math.max(f.lineDescent||0,O),v+=b,f.width+=b}S()})),y();for(var T=1/0,b=-1/0,w=0;w<c.length;w++)T=Math.min(T,h[w]-(c[w].lineAscent||0)),b=Math.max(b,h[w]+(c[w].lineDescent||0));return{lines:c,maxLineWidth:p,totalHeight:x,bboxTop:T,bboxBottom:b,bboxHeight:b-T}},e.createNewLine=function(){return{richOptions:[],offsetX:[],width:0,lineHeight:0,offsetY:0,chars:[],lineAscent:0,lineDescent:0}},t}(),O=function(){function t(){}return t.prototype.apply=function(t,e,i,n){var r,a,o=function(t,e){return Math.abs(e)>1e-5?t/e:1},s=i.maxTextWidth*n.fontScale,l=i.maxTextHeight*n.fontScale,c=Math.max(1,null!=(r=e.contentWidth)?r:e.canvasWidth),h=Math.max(1,null!=(a=e.bboxHeight)?a:e.canvasHeight),u=Math.min(1,o(s,c),o(l,h));if(u>.9999)return{globalScale:1};for(var f,x=p(t);!(f=x()).done;){var g=f.value;if(g.width*=u,g.lineHeight*=u,g.offsetX)for(var v=0;v<g.offsetX.length;v++)g.offsetX[v]*=u;for(var d,m=p(g.chars||[]);!(d=m()).done;)for(var y,S=p(d.value);!(y=S()).done;){y.value.x*=u}for(var T,b=p(g.richOptions||[]);!(T=b()).done;){T.value.fontSize*=u}null!=g.lineAscent&&(g.lineAscent*=u),null!=g.lineDescent&&(g.lineDescent*=u)}return{globalScale:u}},t}(),C=function(){function t(){}return t.prototype.apply=function(t,e,i,n){return{globalScale:1}},t}(),z=function(){function t(){}return t.prototype.apply=function(t,e,i,n){return{globalScale:1}},t}(),L=function(){function e(){}return e.prototype.getHorizontalOffsets=function(e,i,n,r,a){var o,s,l=null!=(o=i.containerWidth)?o:r.maxTextWidth*a.fontScale,c=null!=(s=i.baselineCompensationX)?s:0,h=e.map((function(t){return r.getOffsetXRich(a,l,t.width)}));return{lineOffsets:r.overflow===t.spec.TextOverflow.visible?h.map((function(t){return t+c})):h}},e}(),E=function(){function e(){}return e.prototype.getVerticalOffsets=function(e,i,n,r,a,o){var s,l=null!=(s=i.baselineCompensationY)?s:0,c=0;if(0===e.length)return{baselineY:0,lineYOffsets:[]};switch(r.overflow){case t.spec.TextOverflow.visible:var h,u,f,p,x=r.maxTextHeight*a.fontScale,g=null!=(h=i.bboxTop)?h:0,v=null!=(f=i.bboxBottom)?f:g+(null!=(u=i.bboxHeight)?u:0),d=null!=(p=i.bboxHeight)?p:v-g,m=0;switch(r.textVerticalAlign){case t.spec.TextVerticalAlign.top:m=-g;break;case t.spec.TextVerticalAlign.middle:m=(x-d)/2-g;break;case t.spec.TextVerticalAlign.bottom:m=x-d-g}c=m+l;break;case t.spec.TextOverflow.clip:for(var y=r.maxTextHeight*a.fontScale,S=[0],T=1;T<e.length;T++)S[T]=S[T-1]+e[T].lineHeight;for(var b=1/0,w=-1/0,A=0;A<e.length;A++){var O,C,z=null!=(O=e[A].lineAscent)?O:0,L=null!=(C=e[A].lineDescent)?C:0;b=Math.min(b,S[A]-z),w=Math.max(w,S[A]+L)}var E=w-b,H=0;switch(r.textVerticalAlign){case t.spec.TextVerticalAlign.top:H=-b;break;case t.spec.TextVerticalAlign.middle:H=(y-E)/2-b;break;case t.spec.TextVerticalAlign.bottom:H=y-E-b}c=H+l;break;case t.spec.TextOverflow.display:for(var W=r.maxTextHeight*a.fontScale,M=[0],V=1;V<e.length;V++)M[V]=M[V-1]+e[V].lineHeight;for(var R=1/0,k=-1/0,F=0;F<e.length;F++){var _,D,B=null!=(_=e[F].lineAscent)?_:0,P=null!=(D=e[F].lineDescent)?D:0;R=Math.min(R,M[F]-B),k=Math.max(k,M[F]+P)}var X=k-R,Y=0;switch(r.textVerticalAlign){case t.spec.TextVerticalAlign.top:Y=-R;break;case t.spec.TextVerticalAlign.middle:Y=(W-X)/2-R;break;case t.spec.TextVerticalAlign.bottom:Y=W-X-R}for(var j=[],N=Y,I=0;I<e.length;I++)j.push(N),I<e.length-1&&(N+=e[I+1].lineHeight);return{baselineY:Y,lineYOffsets:j}}var U=[],q=c;return e.forEach((function(t,i){U.push(q),i<e.length-1&&(q+=e[i+1].lineHeight)})),{baselineY:c,lineYOffsets:U}},e}(),H=function(){function e(){}return e.createWrapStrategy=function(t){return t?new A:new w},e.createOverflowStrategy=function(e){switch(e){case t.spec.TextOverflow.clip:return new C;case t.spec.TextOverflow.display:return new O;case t.spec.TextOverflow.visible:default:return new z}},e.createHorizontalAlignStrategy=function(){return new L},e.createVerticalAlignStrategy=function(){return new E},e}(),W=0;exports.RichTextComponent=function(e){function i(i){var n;return(n=e.call(this,i)||this).isDirty=!0,n.text="",n.processedTextOptions=[],n.singleLineHeight=1.571,n.size=null,n.initialized=!1,n.canvasSize=null,n.SCALE_FACTOR=.1,n.ALPHA_FIX_VALUE=1/255,n.name="MRichText"+W++,n.initTextBase(i),n.richWrapStrategy=H.createWrapStrategy(),n.richOverflowStrategy=H.createOverflowStrategy(t.spec.TextOverflow.display),n.richHorizontalAlignStrategy=H.createHorizontalAlignStrategy(),n.richVerticalAlignStrategy=H.createVerticalAlignStrategy(),n}a(i,e);var n=i.prototype;return n.onUpdate=function(t){e.prototype.onUpdate.call(this,t),this.updateTexture()},n.onDestroy=function(){e.prototype.onDestroy.call(this),this.disposeTextTexture()},n.fromData=function(i){e.prototype.fromData.call(this,i);var n=i.interaction,r=i.options;this.interaction=n,this.textStyle=new t.TextStyle(r),this.textLayout=new S(r),this.text=r.text?r.text.toString():" ",this.textLayout.useLegacyRichText&&(this.textLayout.textVerticalAlign=t.spec.TextVerticalAlign.middle),this.updateStrategies(),this.renderText(r),this.material.setColor("_Color",new t.math.Color(1,1,1,1))},n.updateStrategies=function(){var t=this.textLayout;t&&(this.richWrapStrategy=H.createWrapStrategy(t.wrapEnabled),this.richOverflowStrategy=H.createOverflowStrategy(t.overflow))},n.generateTextProgram=function(e){var i=this;this.processedTextOptions=[];var n=y((function(e,n){/^\n+$/.test(e)&&(e=e.replace(/\n/g,"\n ")),e.split("\n").forEach((function(e,r){var a={text:e,fontSize:i.textStyle.fontSize,isNewLine:!1};r>0&&(a.isNewLine=!0),"b"in n&&(a.fontWeight=t.spec.TextWeight.bold),"i"in n&&(a.fontStyle=t.spec.FontStyle.italic),"size"in n&&n.size&&(a.fontSize=parseInt(n.size,10)),"color"in n&&n.color&&(a.fontColor=b(n.color)),i.processedTextOptions.push(a)}))}));n(e)},n.updateWithOptions=function(e){this.textStyle=new t.TextStyle(e),this.textLayout=new S(e),this.text=e.text?e.text.toString():" ",this.textLayout.useLegacyRichText&&(this.textLayout.textVerticalAlign=t.spec.TextVerticalAlign.middle),this.updateStrategies(),this.isDirty=!0},n.renderText=function(e){var i=e.size;i&&(this.canvasSize=new t.math.Vector2(i[0],i[1])),this.updateTexture()},n.updateTexture=function(t){if(void 0===t&&(t=!0),this.isDirty&&this.context&&this.canvas&&this.textStyle&&this.textLayout){var e=!0===this.textLayout.useLegacyRichText;this.singleLineHeight=e?1.571:1,e?this.updateTextureLegacy(t):this.updateTextureWithStrategies(t)}},n.updateTextureLegacy=function(e){var i=this;if(this.isDirty&&this.context&&this.canvas&&this.textStyle){this.generateTextProgram(this.text);var n=0,r=0,a=this.textLayout,o=this.textStyle,s=a.overflow,l=a.letterSpace,c=void 0===l?0:l,h=this.context,u=[],f=o.fontSize*o.fontScale,p={richOptions:[],offsetX:[],width:0,lineHeight:f*this.singleLineHeight,offsetY:f*(this.singleLineHeight-1)/2};if(this.processedTextOptions.forEach((function(t){var e=t.text,a=t.isNewLine,s=t.fontSize;a&&(u.push(p),n=Math.max(n,p.width),p={richOptions:[],offsetX:[],width:0,lineHeight:f*i.singleLineHeight,offsetY:f*(i.singleLineHeight-1)/2},r+=p.lineHeight),h.font=(t.fontWeight||o.textWeight)+" 10px "+(t.fontFamily||o.fontFamily);var l=h.measureText(e),x=l.width;if(void 0!==l.actualBoundingBoxLeft&&void 0!==l.actualBoundingBoxRight){var g=l.actualBoundingBoxLeft+l.actualBoundingBoxRight;g>0&&(x=Math.max(x,g))}var v=s*i.singleLineHeight*o.fontScale;v>p.lineHeight&&(r+=v-p.lineHeight,p.lineHeight=v,p.offsetY=s*o.fontScale*(i.singleLineHeight-1)/2),p.offsetX.push(p.width),p.width+=(x<=0?0:x)*s*i.SCALE_FACTOR*o.fontScale+e.length*c,p.richOptions.push(t)})),u.push(p),n=Math.max(n,p.width),r+=p.lineHeight,0!==n&&0!==r){void 0!==this.size&&null!==this.size||(this.size=this.item.transform.size.clone());var x=this.size,g=x.x,v=void 0===g?1:g,d=x.y,m=void 0===d?1:d;if(!this.initialized){this.canvasSize=this.canvasSize?this.canvasSize:new t.math.Vector2(n,r);var y=this.canvasSize,S=y.x,T=y.y;this.item.transform.size.set(v*S*this.SCALE_FACTOR*this.SCALE_FACTOR,m*T*this.SCALE_FACTOR*this.SCALE_FACTOR),this.size=this.item.transform.size.clone(),this.initialized=!0}t.assertExist(this.canvasSize);var b=this.canvasSize,w=b.x,A=b.y;a.width=w/o.fontScale,a.height=A/o.fontScale,this.renderToTexture(w,A,e,(function(e){if(0!==u.length){var n=a.getOffsetY(o,u.length,f*i.singleLineHeight,o.fontSize);u.forEach((function(i,r){var l=i.richOptions,c=i.offsetX,h=i.width,u=h,f=c;if(s===t.spec.TextOverflow.display&&h>w){var p=w/h;u*=p,f=c.map((function(t){return t*p}))}var x=a.getOffsetX(o,u);r>0&&(n+=i.lineHeight-i.offsetY),l.forEach((function(i,r){var a=o.fontScale,l=o.textColor,c=o.fontFamily,u=o.textWeight,p=o.fontStyle,g=i.text,v=i.fontSize,d=i.fontColor,m=void 0===d?l:d,y=i.fontFamily,S=void 0===y?c:y,T=i.fontWeight,b=void 0===T?u:T,A=i.fontStyle,O=void 0===A?p:A,C=v;s===t.spec.TextOverflow.display&&h>w&&(C/=h/w);var z=f[r]+x;e.font=O+" "+b+" "+C*a+"px "+S;var L=m[0],E=m[1],H=m[2],W=m[3];e.fillStyle="rgba("+L+", "+E+", "+H+", "+W+")",e.fillText(g,z,n)}))}))}}),{disposeOld:!1}),this.isDirty=!1}else this.isDirty=!1}},n.updateTextureWithStrategies=function(e){var i=this;if(this.isDirty&&this.context&&this.canvas){this.generateTextProgram(this.text);var n=this.textLayout,r=n.letterSpace,a=void 0===r?0:r,o=this.context;if(o){var s=this.richWrapStrategy.computeLines(this.processedTextOptions,o,this.textStyle,n,this.singleLineHeight,this.textStyle.fontScale,a,this.SCALE_FACTOR);if(0!==s.lines.length&&0!==s.maxLineWidth&&0!==s.totalHeight){var l=this.resolveCanvasSize(s,n,this.textStyle,this.singleLineHeight);this.setCanvasSize(l);var c=this.richOverflowStrategy.apply(s.lines,l,n,this.textStyle),h=this.richHorizontalAlignStrategy.getHorizontalOffsets(s.lines,l,c,n,this.textStyle),u=this.richVerticalAlignStrategy.getVerticalOffsets(s.lines,l,c,n,this.textStyle,this.singleLineHeight);t.assertExist(this.canvasSize);var f=this.canvasSize,p=f.x,x=f.y,g=Math.max(1,Math.ceil(p)),v=Math.max(1,Math.ceil(x));n.width=g/this.textStyle.fontScale,n.height=v/this.textStyle.fontScale,this.renderToTexture(g,v,e,(function(t){i.drawTextWithStrategies(t,s.lines,h,u,c,i.textStyle)}),{disposeOld:!1}),this.isDirty=!1}else this.isDirty=!1}}},n.setCanvasSize=function(e){var i=this;void 0!==this.size&&null!==this.size||(this.size=this.item.transform.size.clone());var n=this.size,r=n.x,a=void 0===r?1:r,o=n.y,s=void 0===o?1:o,l=this.textLayout,c=this.textStyle.fontScale||1,h=Math.max(1,l.maxTextWidth||0),u=Math.max(1,l.maxTextHeight||0);switch(l.overflow){case t.spec.TextOverflow.visible:var f,p,x,g,v=h*c,d=u*c,m=null!=(f=e.bboxTop)?f:0,y=null!=(x=e.bboxBottom)?x:m+(null!=(p=e.bboxHeight)?p:0),S=null!=(g=e.bboxHeight)?g:y-m,T=0;switch(l.textVerticalAlign){case t.spec.TextVerticalAlign.top:T=-m;break;case t.spec.TextVerticalAlign.middle:T=(d-S)/2-m;break;case t.spec.TextVerticalAlign.bottom:T=d-S-m}var b=T+m,w=T+y,A=Math.max(0,-b),O=Math.max(0,w-d),C=A,z=O;switch(l.textVerticalAlign){case t.spec.TextVerticalAlign.top:C=O,z=O;break;case t.spec.TextVerticalAlign.bottom:C=A,z=A;break;case t.spec.TextVerticalAlign.middle:C=A,z=O}for(var L=C,E=e.lines||[],H=E.map((function(t){return l.getOffsetXRich(i.textStyle,v,t.width)})),W=1/0,M=-1/0,V=0;V<E.length;V++){var R,k,F=null!=(R=H[V])?R:0,_=null!=(k=E[V].width)?k:0;W=Math.min(W,F),M=Math.max(M,F+_)}isFinite(W)||(W=0),isFinite(M)||(M=0);var D,B=Math.max(0,-W),P=Math.max(0,M-v),X=Math.ceil(v+B+P),Y=Math.ceil(d+C+z);e.baselineCompensationX=B,e.baselineCompensationY=L,e.containerWidth=v,e.canvasWidth=X,e.canvasHeight=Y,this.canvasSize=new t.math.Vector2(X,Y);var j=null!=(D=this.size)?D:this.item.transform.size,N=j.x,I=void 0===N?1:N,U=j.y,q=void 0===U?1:U;this.item.transform.size.set(I*X*this.SCALE_FACTOR*this.SCALE_FACTOR,q*Y*this.SCALE_FACTOR*this.SCALE_FACTOR),this.initialized=!0;break;case t.spec.TextOverflow.clip:var $,G=h*c,J=u*c;e.canvasWidth=G,e.canvasHeight=J,e.baselineCompensationX=0,e.baselineCompensationY=0,this.canvasSize=new t.math.Vector2(G,J),l.width=h,l.height=u;var K=null!=($=this.size)?$:this.item.transform.size,Q=K.x,Z=void 0===Q?1:Q,tt=K.y,et=void 0===tt?1:tt;this.item.transform.size.set(Z*G*this.SCALE_FACTOR*this.SCALE_FACTOR,et*J*this.SCALE_FACTOR*this.SCALE_FACTOR),this.initialized=!0;break;case t.spec.TextOverflow.display:if(!this.initialized){var it=h*c,nt=u*c;this.canvasSize=new t.math.Vector2(it,nt),this.item.transform.size.set(a*it*this.SCALE_FACTOR*this.SCALE_FACTOR,s*nt*this.SCALE_FACTOR*this.SCALE_FACTOR),this.initialized=!0}}},n.resolveCanvasSize=function(t,e,i,n){var r=Math.max(1,t.maxLineWidth||0),a=Math.max(1,t.totalHeight||0);return e.width=r/i.fontScale,e.height=a/i.fontScale,{canvasWidth:r,canvasHeight:a,contentWidth:t.maxLineWidth,bboxTop:t.bboxTop,bboxBottom:t.bboxBottom,bboxHeight:t.bboxHeight,lines:t.lines}},n.drawTextWithStrategies=function(t,e,i,n,r,a){var o=n.baselineY,s=i.lineOffsets;e.forEach((function(i,n){var r=i.richOptions,l=i.chars,c=s[n],h=o;r.forEach((function(e,n){var r=a.fontScale,o=a.textColor,s=a.fontFamily,u=a.textWeight,f=a.fontStyle,p=e.fontSize,x=e.fontColor,g=void 0===x?o:x,v=e.fontFamily,d=void 0===v?s:v,m=e.fontWeight,y=void 0===m?u:m,S=e.fontStyle,T=void 0===S?f:S,b=p;t.font=T+" "+y+" "+b*r+"px "+d;var w=g[0],A=g[1],O=g[2],C=g[3];t.fillStyle="rgba("+w+", "+A+", "+O+", "+C+")";var z=i.offsetX&&i.offsetX[n]?i.offsetX[n]:0;l[n].forEach((function(e){t.fillText(e.char,c+z+e.x,h)}))})),n<e.length-1&&(o+=e[n+1].lineHeight)}))},n.unsupported=function(t){throw new Error("RichTextComponent does not support "+t+" at runtime.")},n.setShadowOffsetY=function(t){this.unsupported("setShadowOffsetY")},n.setShadowBlur=function(t){this.unsupported("setShadowBlur")},n.setShadowOffsetX=function(t){this.unsupported("setShadowOffsetX")},n.setShadowColor=function(t){this.unsupported("setShadowColor")},n.setOutlineWidth=function(t){this.unsupported("setOutlineWidth")},n.setAutoWidth=function(t){this.unsupported("setAutoWidth")},n.setFontSize=function(t){this.unsupported("setFontSize")},n.setTextBaseline=function(t){console.warn("setTextBaseline 已废弃,请改用 setTextVerticalAlign。本次调用将转调用 setTextVerticalAlign。"),this.setTextVerticalAlign(t)},i}(t.MaskableGraphic),exports.RichTextComponent=function(t,e,i,n){var r,a=arguments.length,o=a<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,i):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,e,i,n);else for(var s=t.length-1;s>=0;s--)(r=t[s])&&(o=(a<3?r(o):a>3?r(e,i,o):r(e,i))||o);return a>3&&o&&Object.defineProperty(e,i,o),o}([t.effectsClass(t.spec.DataType.RichTextComponent)],exports.RichTextComponent),t.applyMixins(exports.RichTextComponent,[t.TextComponentBase]);var M="2.8.4";t.registerPlugin("rich-text",u),t.logger.info("Plugin rich text version: 2.8.4."),M!==n.version&&console.error("注意:请统一 RichText 插件与 Player 版本,不统一的版本混用会有不可预知的后果!","\nAttention: Please ensure the RichText plugin is synchronized with the Player version. Mixing and matching incompatible versions may result in unpredictable consequences!"),exports.RichTextLoader=u,exports.escape=function(t){if("string"!=typeof t)throw new Error("Input must be a string");return t.replace(/\\/g,"\\\\").replace(/=/g,"\\=").replace(/</g,"\\<").replace(/>/g,"\\>").replace(/\//g,"\\/")},exports.generateProgram=y,exports.isRichText=function(t){var e=d(t).filter((function(t){var e=t.tokenType;return"ContextStart"===e||"ContextEnd"===e})),i=e.filter((function(t){return"ContextStart"===t.tokenType})),n=e.filter((function(t){return"ContextEnd"===t.tokenType}));return!(i.length!==n.length||!i.length)&&function t(e,i){var n=e[0],r=e.slice(1);if(void 0===i&&(i=[]),!n)return 0===i.length;if("ContextStart"===n.tokenType)return t(r,i.concat(n.value));if("ContextEnd"===n.tokenType)return i[i.length-1]===n.value&&t(r,i.slice(0,-1));throw new Error("Unexpected token: "+n.tokenType)}(e.map((function(t){var e=t.tokenType,i=t.value;return{tokenType:e,value:"ContextStart"===e?i.match(x)[1]:i.match(g)[1]}})))},exports.lexer=d,exports.richTextParser=m,exports.unescape=function(t){if("string"!=typeof t)throw new Error("Input must be a string");return t.replace(/\\\//g,"/").replace(/\\>/g,">").replace(/\\</g,"<").replace(/\\=/g,"=").replace(/\\\\/g,"\\")},exports.version=M;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@galacean/effects/alipay"),e=require("@galacean/appx-adapter/alipay");function i(t){if(t&&t.__esModule)return t;var e=Object.create(null);return t&&Object.keys(t).forEach((function(i){if("default"!==i){var n=Object.getOwnPropertyDescriptor(t,i);Object.defineProperty(e,i,n.get?n:{enumerable:!0,get:function(){return t[i]}})}})),e.default=t,Object.freeze(e)}var n=i(t);function r(t,e){return r=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},r(t,e)}function a(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&&r(t,e)}function o(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(o=function(){return!!t})()}function s(t,e,i){return s=o()?Reflect.construct:function(t,e,i){var n=[null];n.push.apply(n,e);var a=new(Function.bind.apply(t,n));return i&&r(a,i.prototype),a},s.apply(null,arguments)}function l(t){return l=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},l(t)}function c(t){var e="function"==typeof Map?new Map:void 0;return c=function(t){if(null===t||(i=t,-1===Function.toString.call(i).indexOf("[native code]")))return t;var i;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,n)}function n(){return s(t,arguments,l(this).constructor)}return n.prototype=Object.create(t.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),r(n,t)},c(t)}var h,u=function(t){function e(){var e;return(e=t.apply(this,arguments)||this).name="rich-text",e}return a(e,t),e}(c(t.Plugin));function f(t,e){(null==e||e>t.length)&&(e=t.length);for(var i=0,n=new Array(e);i<e;i++)n[i]=t[i];return n}function p(t,e){var i="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(i)return(i=i.call(t)).next.bind(i);if(Array.isArray(t)||(i=function(t,e){if(t){if("string"==typeof t)return f(t,e);var i=Object.prototype.toString.call(t).slice(8,-1);return"Object"===i&&t.constructor&&(i=t.constructor.name),"Map"===i||"Set"===i?Array.from(i):"Arguments"===i||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i)?f(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){i&&(t=i);var n=0;return function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}!function(t){t.ContextStart="ContextStart",t.Text="Text",t.ContextEnd="ContextEnd",t.EscapedChar="EscapedChar"}(h||(h={}));var x=/^<([a-z]+)(=([^>]+))?>$/,g=/^<\/([a-z]+)>$/,v=[["EscapedChar",/^\\([=<>\\/])/],["ContextStart",/^<[a-z]+(=[^>]+)?>/],["ContextEnd",/^<\/[a-z]+>/],["Text",/^[^</>=\\]+/]],d=function(t,e,i){if(void 0===e&&(e=[]),void 0===i&&(i=0),!t)return e;var n=/^\\([=<>\\/])/.exec(t);if(n){var r=n[1];return d(t.slice(2),e.concat({tokenType:"Text",value:r}),i+2)}for(var a,o=p(v);!(a=o()).done;){var s=a.value,l=s[0],c=s[1];if("EscapedChar"!==l){var h=c.exec(t);if(h){var u=h[0],f=u.length;return d(t.slice(f),e.concat({tokenType:l,value:u}),i+f)}}}if(t.length>0)return d(t.slice(1),e.concat({tokenType:"Text",value:t[0]}),i+1);throw new Error('Unexpected token: "'+t[0]+'" at position '+i+' while reading "'+t+'"')},m=function(t){var e=function(){for(var t,e="",i=!1;r.length>0&&"Text"===(null==(t=r[0])?void 0:t.tokenType);){var n=o();n&&(e+=n.value,i=!0)}return i?e:void 0},i=function(){var t=s();if("ContextStart"===(null==t?void 0:t.tokenType)){o();var e,i=t.value.match(x);if(i)return{attributeName:i[1],attributeParam:null!=(e=i[3])?e:""};throw new Error("Expected a start tag marker at position "+a)}return{}},n=function(){var t=s();if("ContextEnd"===(null==t?void 0:t.tokenType)){o();var e=t.value.match(g);if(e)return{attributeName:e[1]};throw new Error("Expect an end tag marker at position "+a)}return{}},r=d(t),a=0,o=function(){var t,e=r.shift();return a+=null!=(t=null==e?void 0:e.value.length)?t:0,e},s=function(){return r[0]},l=[];return function t(r,o){for(void 0===r&&(r=[]),void 0===o&&(o="");;){var s=e();if(s)l.push({attributes:r,text:s});else{var c=i(),h=c.attributeName,u=c.attributeParam;if(!h){if(o){var f=n().attributeName;if(!f)throw new Error('Expect an end tag marker "'+o+'" at position '+a+" but found no tag!");if(f!==o)throw new Error('Expect an end tag marker "'+o+'" at position '+a+' but found tag "'+f+'"');return}break}t(r.concat({attributeName:h,attributeParam:null!=u?u:""}),h)}}}(),l};function y(t){return function(e){for(var i,n=p(m(e));!(i=n()).done;){var r=i.value,a=r.text,o=r.attributes.reduce((function(t,e){var i=e.attributeName,n=e.attributeParam;return i&&(t[i]=n),t}),{});t(a,o)}}}"function"==typeof SuppressedError&&SuppressedError;var S=function(){function e(e){this.width=0,this.height=0;var i=e.size,n=e.textOverflow,r=void 0===n?t.spec.TextOverflow.clip:n,a=e.textVerticalAlign,o=void 0===a?t.spec.TextVerticalAlign.middle:a,s=e.textAlign,l=void 0===s?t.spec.TextAlignment.left:s,c=e.letterSpace,h=void 0===c?0:c,u=e.lineHeight,f=void 0===u?.571:u,p=e.wrapEnabled,x=void 0!==p&&p,g=e.maxTextWidth,v=void 0===g?350:g,d=e.maxTextHeight,m=void 0===d?1e3:d,y=e.sizeMode,S=void 0===y?t.spec.TextSizeMode.autoWidth:y,T=e.useLegacyRichText,b=void 0!==T&&T;this.letterSpace=h,this.lineHeight=f,this.useLegacyRichText=b,this.overflow=r,this.textVerticalAlign=o,this.textAlign=l,this.width=i?i[0]:100,this.height=i?i[1]:100,this.wrapEnabled=x;this.maxTextWidth=50*v,this.maxTextHeight=50*m,this.sizeMode=S}var i=e.prototype;return i.getOffsetY=function(e,i,n,r,a){var o=e.outlineWidth,s=e.fontScale,l=(n-r)/3,c=r+o*s,h=void 0!==a?a:n*(i-1),u=0;switch(this.textVerticalAlign){case t.spec.TextVerticalAlign.top:u=c+l;break;case t.spec.TextVerticalAlign.middle:u=(this.height*s-h+c)/2;break;case t.spec.TextVerticalAlign.bottom:u=this.height*s-h-l}return u},i.getOffsetX=function(e,i){var n=0;switch(this.textAlign){case t.spec.TextAlignment.left:n=e.outlineWidth*e.fontScale;break;case t.spec.TextAlignment.middle:n=(this.width*e.fontScale-i)/2;break;case t.spec.TextAlignment.right:n=this.width*e.fontScale-i}return n},i.getOffsetYRich=function(e,i,n){if(0===i.length)return 0;var r=e.outlineWidth,a=e.fontScale,o=i.reduce((function(t,e){return t+e}),0),s=(i[0]-n)/3,l=n+r*a,c=o-i[0],h=0;switch(this.textVerticalAlign){case t.spec.TextVerticalAlign.top:h=l+s;break;case t.spec.TextVerticalAlign.middle:h=(this.height*a-o)/2+l;break;case t.spec.TextVerticalAlign.bottom:h=this.height*a-c-s}return h},i.getOffsetXRich=function(e,i,n){switch(this.textAlign){case t.spec.TextAlignment.left:return e.outlineWidth*e.fontScale;case t.spec.TextAlignment.middle:return(i-n)/2;case t.spec.TextAlignment.right:return i-n;default:return 0}},i.setSize=function(t,e){this.width=t,this.height=e},e}();function T(t,e){if(void 0===e&&(e=1),3!==(t=t.replace(/^#/,"")).length&&4!==t.length||(t=t.split("").map((function(t){return t+t})).join("")),8===t.length){var i=parseInt(t.slice(6,8),16)/255;t=t.slice(0,6),e=i}var n=parseInt(t,16);return[n>>16&255,n>>8&255,255&n,e]}function b(t,i){if(void 0===i&&(i=1),"string"!=typeof t||!t)throw new Error("Invalid color string");return t.startsWith("#")?T(t,i):T(function(t){if("string"!=typeof t||!t)throw new Error("Invalid color name provided");if(void 0===e.document)throw new Error("This method requires a browser environment");var i=e.document.createElement("canvas"),n=i.getContext("2d");if(n)try{return n.fillStyle=t,n.fillStyle}finally{null==i.remove||i.remove.call(i)}throw new Error("Failed to get 2D context for color conversion!")}(t))}var w=function(){function t(){}var e=t.prototype;return e.computeLines=function(t,e,i,n,r,a,o,s){var l=this,c=[],h=[],u=(n.lineHeight||0)*a,f=this.createNewLine(),p=0,x=0,g=function(){if(0!==f.chars.length){f.lineHeight=0===c.length?(f.lineAscent||0)+(f.lineDescent||0):u;var t=0===c.length?0:h[h.length-1]+u;h.push(t),x+=f.lineHeight,c.push(f),p=Math.max(p,f.width),f=l.createNewLine()}};t.forEach((function(t){var n=t.text,r=t.isNewLine,l=t.fontSize;r&&g();var c=t.fontStyle||i.fontStyle||"normal";e.font=c+" "+(t.fontWeight||i.textWeight)+" 10px "+(t.fontFamily||i.fontFamily),f.offsetX.push(f.width);for(var h=0,u=[],p=0,x=0,v=0;v<n.length;v++){var d=n[v],m=e.measureText(d),y=m.width,S=(y<=0?0:y)*l*s*a,T=l*a*s,b=m.actualBoundingBoxAscent*T,w=m.actualBoundingBoxDescent*T;p=Math.max(p,b),x=Math.max(x,w),v>0&&(h+=o),u.push({char:d,x:h}),h+=S}f.chars.push(u),f.width+=h,f.richOptions.push(t),f.lineAscent=Math.max(f.lineAscent||0,p),f.lineDescent=Math.max(f.lineDescent||0,x)})),g();var v=1/0,d=-1/0;if(0===c.length)return{lines:c,maxLineWidth:p,totalHeight:x,bboxTop:0,bboxBottom:0,bboxHeight:0};for(var m=0;m<c.length;m++)v=Math.min(v,h[m]-(c[m].lineAscent||0)),d=Math.max(d,h[m]+(c[m].lineDescent||0));return{lines:c,maxLineWidth:p,totalHeight:x,bboxTop:v,bboxBottom:d,bboxHeight:d-v}},e.createNewLine=function(){return{richOptions:[],offsetX:[],width:0,lineHeight:0,offsetY:0,chars:[],lineAscent:0,lineDescent:0}},t}(),A=function(){function t(){}var e=t.prototype;return e.computeLines=function(t,e,i,n,r,a,o,s){var l=this,c=[],h=[],u=(n.lineHeight||0)*a,f=this.createNewLine(),p=0,x=0,g=null,v=0,d=[],m=null,y=function(){if(S(),0!==f.chars.length){f.lineHeight=0===c.length?(f.lineAscent||0)+(f.lineDescent||0):u;var t=0===c.length?0:h[h.length-1]+u;h.push(t),x+=f.lineHeight,c.push(f),p=Math.max(p,f.width),f=l.createNewLine(),g=null,v=0,d=[],m=null}},S=function(){0!==d.length&&(null===g&&(g=f.width),f.offsetX.push(g),f.chars.push(d),m&&f.richOptions.push(m),g=null,v=0,d=[],m=null)};t.forEach((function(t){var r=t.text,l=t.isNewLine,c=t.fontSize,h=t.fontStyle||i.fontStyle||"normal";e.font=h+" "+(t.fontWeight||i.textWeight)+" 10px "+(t.fontFamily||i.fontFamily),l&&(S(),y());for(var u=0;u<r.length;u++){var p=r[u],x=e.measureText(p),T=x.width,b=(T<=0?0:T)*c*s*a,w=c*a*s,A=x.actualBoundingBoxAscent*w,O=x.actualBoundingBoxDescent*w,C=d.length>0?o:0;f.width+C+b>(n.maxTextWidth||1/0)&&(S(),y()),null===g&&(g=f.width,m=t),d.length>0&&(v+=o,f.width+=o),d.push({char:p,x:v}),f.lineAscent=Math.max(f.lineAscent||0,A),f.lineDescent=Math.max(f.lineDescent||0,O),v+=b,f.width+=b}S()})),y();for(var T=1/0,b=-1/0,w=0;w<c.length;w++)T=Math.min(T,h[w]-(c[w].lineAscent||0)),b=Math.max(b,h[w]+(c[w].lineDescent||0));return{lines:c,maxLineWidth:p,totalHeight:x,bboxTop:T,bboxBottom:b,bboxHeight:b-T}},e.createNewLine=function(){return{richOptions:[],offsetX:[],width:0,lineHeight:0,offsetY:0,chars:[],lineAscent:0,lineDescent:0}},t}(),O=function(){function t(){}return t.prototype.apply=function(t,e,i,n){var r,a,o=function(t,e){return Math.abs(e)>1e-5?t/e:1},s=i.maxTextWidth*n.fontScale,l=i.maxTextHeight*n.fontScale,c=Math.max(1,null!=(r=e.contentWidth)?r:e.canvasWidth),h=Math.max(1,null!=(a=e.bboxHeight)?a:e.canvasHeight),u=Math.min(1,o(s,c),o(l,h));if(u>.9999)return{globalScale:1};for(var f,x=p(t);!(f=x()).done;){var g=f.value;if(g.width*=u,g.lineHeight*=u,g.offsetX)for(var v=0;v<g.offsetX.length;v++)g.offsetX[v]*=u;for(var d,m=p(g.chars||[]);!(d=m()).done;)for(var y,S=p(d.value);!(y=S()).done;){y.value.x*=u}for(var T,b=p(g.richOptions||[]);!(T=b()).done;){T.value.fontSize*=u}null!=g.lineAscent&&(g.lineAscent*=u),null!=g.lineDescent&&(g.lineDescent*=u)}return{globalScale:u}},t}(),C=function(){function t(){}return t.prototype.apply=function(t,e,i,n){return{globalScale:1}},t}(),z=function(){function t(){}return t.prototype.apply=function(t,e,i,n){return{globalScale:1}},t}(),L=function(){function e(){}return e.prototype.getHorizontalOffsets=function(e,i,n,r,a){var o,s,l=null!=(o=i.containerWidth)?o:r.maxTextWidth*a.fontScale,c=null!=(s=i.baselineCompensationX)?s:0,h=e.map((function(t){return r.getOffsetXRich(a,l,t.width)}));return{lineOffsets:r.overflow===t.spec.TextOverflow.visible?h.map((function(t){return t+c})):h}},e}(),E=function(){function e(){}return e.prototype.getVerticalOffsets=function(e,i,n,r,a,o){var s,l=null!=(s=i.baselineCompensationY)?s:0,c=0;if(0===e.length)return{baselineY:0,lineYOffsets:[]};switch(r.overflow){case t.spec.TextOverflow.visible:var h,u,f,p,x=r.maxTextHeight*a.fontScale,g=null!=(h=i.bboxTop)?h:0,v=null!=(f=i.bboxBottom)?f:g+(null!=(u=i.bboxHeight)?u:0),d=null!=(p=i.bboxHeight)?p:v-g,m=0;switch(r.textVerticalAlign){case t.spec.TextVerticalAlign.top:m=-g;break;case t.spec.TextVerticalAlign.middle:m=(x-d)/2-g;break;case t.spec.TextVerticalAlign.bottom:m=x-d-g}c=m+l;break;case t.spec.TextOverflow.clip:for(var y=r.maxTextHeight*a.fontScale,S=[0],T=1;T<e.length;T++)S[T]=S[T-1]+e[T].lineHeight;for(var b=1/0,w=-1/0,A=0;A<e.length;A++){var O,C,z=null!=(O=e[A].lineAscent)?O:0,L=null!=(C=e[A].lineDescent)?C:0;b=Math.min(b,S[A]-z),w=Math.max(w,S[A]+L)}var E=w-b,H=0;switch(r.textVerticalAlign){case t.spec.TextVerticalAlign.top:H=-b;break;case t.spec.TextVerticalAlign.middle:H=(y-E)/2-b;break;case t.spec.TextVerticalAlign.bottom:H=y-E-b}c=H+l;break;case t.spec.TextOverflow.display:for(var W=r.maxTextHeight*a.fontScale,M=[0],V=1;V<e.length;V++)M[V]=M[V-1]+e[V].lineHeight;for(var R=1/0,k=-1/0,F=0;F<e.length;F++){var _,D,B=null!=(_=e[F].lineAscent)?_:0,P=null!=(D=e[F].lineDescent)?D:0;R=Math.min(R,M[F]-B),k=Math.max(k,M[F]+P)}var X=k-R,Y=0;switch(r.textVerticalAlign){case t.spec.TextVerticalAlign.top:Y=-R;break;case t.spec.TextVerticalAlign.middle:Y=(W-X)/2-R;break;case t.spec.TextVerticalAlign.bottom:Y=W-X-R}for(var j=[],N=Y,I=0;I<e.length;I++)j.push(N),I<e.length-1&&(N+=e[I+1].lineHeight);return{baselineY:Y,lineYOffsets:j}}var U=[],q=c;return e.forEach((function(t,i){U.push(q),i<e.length-1&&(q+=e[i+1].lineHeight)})),{baselineY:c,lineYOffsets:U}},e}(),H=function(){function e(){}return e.createWrapStrategy=function(t){return t?new A:new w},e.createOverflowStrategy=function(e){switch(e){case t.spec.TextOverflow.clip:return new C;case t.spec.TextOverflow.display:return new O;case t.spec.TextOverflow.visible:default:return new z}},e.createHorizontalAlignStrategy=function(){return new L},e.createVerticalAlignStrategy=function(){return new E},e}(),W=0;exports.RichTextComponent=function(e){function i(i){var n;return(n=e.call(this,i)||this).isDirty=!0,n.text="",n.processedTextOptions=[],n.singleLineHeight=1.571,n.size=null,n.initialized=!1,n.canvasSize=null,n.SCALE_FACTOR=.1,n.ALPHA_FIX_VALUE=1/255,n.name="MRichText"+W++,n.initTextBase(i),n.richWrapStrategy=H.createWrapStrategy(),n.richOverflowStrategy=H.createOverflowStrategy(t.spec.TextOverflow.display),n.richHorizontalAlignStrategy=H.createHorizontalAlignStrategy(),n.richVerticalAlignStrategy=H.createVerticalAlignStrategy(),n}a(i,e);var n=i.prototype;return n.onUpdate=function(t){e.prototype.onUpdate.call(this,t),this.updateTexture()},n.onDestroy=function(){e.prototype.onDestroy.call(this),this.disposeTextTexture()},n.fromData=function(i){e.prototype.fromData.call(this,i);var n=i.interaction,r=i.options;this.interaction=n,this.textStyle=new t.TextStyle(r),this.textLayout=new S(r),this.text=r.text?r.text.toString():" ",this.textLayout.useLegacyRichText&&(this.textLayout.textVerticalAlign=t.spec.TextVerticalAlign.middle),this.updateStrategies(),this.renderText(r),this.material.setColor("_Color",new t.math.Color(1,1,1,1))},n.updateStrategies=function(){var t=this.textLayout;t&&(this.richWrapStrategy=H.createWrapStrategy(t.wrapEnabled),this.richOverflowStrategy=H.createOverflowStrategy(t.overflow))},n.generateTextProgram=function(e){var i=this;this.processedTextOptions=[];var n=y((function(e,n){/^\n+$/.test(e)&&(e=e.replace(/\n/g,"\n ")),e.split("\n").forEach((function(e,r){var a={text:e,fontSize:i.textStyle.fontSize,isNewLine:!1};r>0&&(a.isNewLine=!0),"b"in n&&(a.fontWeight=t.spec.TextWeight.bold),"i"in n&&(a.fontStyle=t.spec.FontStyle.italic),"size"in n&&n.size&&(a.fontSize=parseInt(n.size,10)),"color"in n&&n.color&&(a.fontColor=b(n.color)),i.processedTextOptions.push(a)}))}));n(e)},n.updateWithOptions=function(e){this.textStyle=new t.TextStyle(e),this.textLayout=new S(e),this.text=e.text?e.text.toString():" ",this.textLayout.useLegacyRichText&&(this.textLayout.textVerticalAlign=t.spec.TextVerticalAlign.middle),this.updateStrategies(),this.isDirty=!0},n.renderText=function(e){var i=e.size;i&&(this.canvasSize=new t.math.Vector2(i[0],i[1])),this.updateTexture()},n.updateTexture=function(t){if(void 0===t&&(t=!0),this.isDirty&&this.context&&this.canvas&&this.textStyle&&this.textLayout){var e=!0===this.textLayout.useLegacyRichText;this.singleLineHeight=e?1.571:1,e?this.updateTextureLegacy(t):this.updateTextureWithStrategies(t)}},n.updateTextureLegacy=function(e){var i=this;if(this.isDirty&&this.context&&this.canvas&&this.textStyle){this.generateTextProgram(this.text);var n=0,r=0,a=this.textLayout,o=this.textStyle,s=a.overflow,l=a.letterSpace,c=void 0===l?0:l,h=this.context,u=[],f=o.fontSize*o.fontScale,p={richOptions:[],offsetX:[],width:0,lineHeight:f*this.singleLineHeight,offsetY:f*(this.singleLineHeight-1)/2};if(this.processedTextOptions.forEach((function(t){var e=t.text,a=t.isNewLine,s=t.fontSize;a&&(u.push(p),n=Math.max(n,p.width),p={richOptions:[],offsetX:[],width:0,lineHeight:f*i.singleLineHeight,offsetY:f*(i.singleLineHeight-1)/2},r+=p.lineHeight),h.font=(t.fontWeight||o.textWeight)+" 10px "+(t.fontFamily||o.fontFamily);var l=h.measureText(e),x=l.width;if(void 0!==l.actualBoundingBoxLeft&&void 0!==l.actualBoundingBoxRight){var g=l.actualBoundingBoxLeft+l.actualBoundingBoxRight;g>0&&(x=Math.max(x,g))}var v=s*i.singleLineHeight*o.fontScale;v>p.lineHeight&&(r+=v-p.lineHeight,p.lineHeight=v,p.offsetY=s*o.fontScale*(i.singleLineHeight-1)/2),p.offsetX.push(p.width),p.width+=(x<=0?0:x)*s*i.SCALE_FACTOR*o.fontScale+e.length*c,p.richOptions.push(t)})),u.push(p),n=Math.max(n,p.width),r+=p.lineHeight,0!==n&&0!==r){void 0!==this.size&&null!==this.size||(this.size=this.item.transform.size.clone());var x=this.size,g=x.x,v=void 0===g?1:g,d=x.y,m=void 0===d?1:d;if(!this.initialized){this.canvasSize=this.canvasSize?this.canvasSize:new t.math.Vector2(n,r);var y=this.canvasSize,S=y.x,T=y.y;this.item.transform.size.set(v*S*this.SCALE_FACTOR*this.SCALE_FACTOR,m*T*this.SCALE_FACTOR*this.SCALE_FACTOR),this.size=this.item.transform.size.clone(),this.initialized=!0}t.assertExist(this.canvasSize);var b=this.canvasSize,w=b.x,A=b.y;a.width=w/o.fontScale,a.height=A/o.fontScale,this.renderToTexture(w,A,e,(function(e){if(0!==u.length){var n=a.getOffsetY(o,u.length,f*i.singleLineHeight,o.fontSize);u.forEach((function(i,r){var l=i.richOptions,c=i.offsetX,h=i.width,u=h,f=c;if(s===t.spec.TextOverflow.display&&h>w){var p=w/h;u*=p,f=c.map((function(t){return t*p}))}var x=a.getOffsetX(o,u);r>0&&(n+=i.lineHeight-i.offsetY),l.forEach((function(i,r){var a=o.fontScale,l=o.textColor,c=o.fontFamily,u=o.textWeight,p=o.fontStyle,g=i.text,v=i.fontSize,d=i.fontColor,m=void 0===d?l:d,y=i.fontFamily,S=void 0===y?c:y,T=i.fontWeight,b=void 0===T?u:T,A=i.fontStyle,O=void 0===A?p:A,C=v;s===t.spec.TextOverflow.display&&h>w&&(C/=h/w);var z=f[r]+x;e.font=O+" "+b+" "+C*a+"px "+S;var L=m[0],E=m[1],H=m[2],W=m[3];e.fillStyle="rgba("+L+", "+E+", "+H+", "+W+")",e.fillText(g,z,n)}))}))}}),{disposeOld:!1}),this.isDirty=!1}else this.isDirty=!1}},n.updateTextureWithStrategies=function(e){var i=this;if(this.isDirty&&this.context&&this.canvas){this.generateTextProgram(this.text);var n=this.textLayout,r=n.letterSpace,a=void 0===r?0:r,o=this.context;if(o){var s=this.richWrapStrategy.computeLines(this.processedTextOptions,o,this.textStyle,n,this.singleLineHeight,this.textStyle.fontScale,a,this.SCALE_FACTOR);if(0!==s.lines.length&&0!==s.maxLineWidth&&0!==s.totalHeight){var l=this.resolveCanvasSize(s,n,this.textStyle,this.singleLineHeight);this.setCanvasSize(l);var c=this.richOverflowStrategy.apply(s.lines,l,n,this.textStyle),h=this.richHorizontalAlignStrategy.getHorizontalOffsets(s.lines,l,c,n,this.textStyle),u=this.richVerticalAlignStrategy.getVerticalOffsets(s.lines,l,c,n,this.textStyle,this.singleLineHeight);t.assertExist(this.canvasSize);var f=this.canvasSize,p=f.x,x=f.y,g=Math.max(1,Math.ceil(p)),v=Math.max(1,Math.ceil(x));n.width=g/this.textStyle.fontScale,n.height=v/this.textStyle.fontScale,this.renderToTexture(g,v,e,(function(t){i.drawTextWithStrategies(t,s.lines,h,u,c,i.textStyle)}),{disposeOld:!1}),this.isDirty=!1}else this.isDirty=!1}}},n.setCanvasSize=function(e){var i=this;void 0!==this.size&&null!==this.size||(this.size=this.item.transform.size.clone());var n=this.size,r=n.x,a=void 0===r?1:r,o=n.y,s=void 0===o?1:o,l=this.textLayout,c=this.textStyle.fontScale||1,h=Math.max(1,l.maxTextWidth||0),u=Math.max(1,l.maxTextHeight||0);switch(l.overflow){case t.spec.TextOverflow.visible:var f,p,x,g,v=h*c,d=u*c,m=null!=(f=e.bboxTop)?f:0,y=null!=(x=e.bboxBottom)?x:m+(null!=(p=e.bboxHeight)?p:0),S=null!=(g=e.bboxHeight)?g:y-m,T=0;switch(l.textVerticalAlign){case t.spec.TextVerticalAlign.top:T=-m;break;case t.spec.TextVerticalAlign.middle:T=(d-S)/2-m;break;case t.spec.TextVerticalAlign.bottom:T=d-S-m}var b=T+m,w=T+y,A=Math.max(0,-b),O=Math.max(0,w-d),C=A,z=O;switch(l.textVerticalAlign){case t.spec.TextVerticalAlign.top:C=O,z=O;break;case t.spec.TextVerticalAlign.bottom:C=A,z=A;break;case t.spec.TextVerticalAlign.middle:C=A,z=O}for(var L=C,E=e.lines||[],H=E.map((function(t){return l.getOffsetXRich(i.textStyle,v,t.width)})),W=1/0,M=-1/0,V=0;V<E.length;V++){var R,k,F=null!=(R=H[V])?R:0,_=null!=(k=E[V].width)?k:0;W=Math.min(W,F),M=Math.max(M,F+_)}isFinite(W)||(W=0),isFinite(M)||(M=0);var D,B=Math.max(0,-W),P=Math.max(0,M-v),X=Math.ceil(v+B+P),Y=Math.ceil(d+C+z);e.baselineCompensationX=B,e.baselineCompensationY=L,e.containerWidth=v,e.canvasWidth=X,e.canvasHeight=Y,this.canvasSize=new t.math.Vector2(X,Y);var j=null!=(D=this.size)?D:this.item.transform.size,N=j.x,I=void 0===N?1:N,U=j.y,q=void 0===U?1:U;this.item.transform.size.set(I*X*this.SCALE_FACTOR*this.SCALE_FACTOR,q*Y*this.SCALE_FACTOR*this.SCALE_FACTOR),this.initialized=!0;break;case t.spec.TextOverflow.clip:var $,G=h*c,J=u*c;e.canvasWidth=G,e.canvasHeight=J,e.baselineCompensationX=0,e.baselineCompensationY=0,this.canvasSize=new t.math.Vector2(G,J),l.width=h,l.height=u;var K=null!=($=this.size)?$:this.item.transform.size,Q=K.x,Z=void 0===Q?1:Q,tt=K.y,et=void 0===tt?1:tt;this.item.transform.size.set(Z*G*this.SCALE_FACTOR*this.SCALE_FACTOR,et*J*this.SCALE_FACTOR*this.SCALE_FACTOR),this.initialized=!0;break;case t.spec.TextOverflow.display:if(!this.initialized){var it=h*c,nt=u*c;this.canvasSize=new t.math.Vector2(it,nt),this.item.transform.size.set(a*it*this.SCALE_FACTOR*this.SCALE_FACTOR,s*nt*this.SCALE_FACTOR*this.SCALE_FACTOR),this.initialized=!0}}},n.resolveCanvasSize=function(t,e,i,n){var r=Math.max(1,t.maxLineWidth||0),a=Math.max(1,t.totalHeight||0);return e.width=r/i.fontScale,e.height=a/i.fontScale,{canvasWidth:r,canvasHeight:a,contentWidth:t.maxLineWidth,bboxTop:t.bboxTop,bboxBottom:t.bboxBottom,bboxHeight:t.bboxHeight,lines:t.lines}},n.drawTextWithStrategies=function(t,e,i,n,r,a){var o=n.baselineY,s=i.lineOffsets;e.forEach((function(i,n){var r=i.richOptions,l=i.chars,c=s[n],h=o;r.forEach((function(e,n){var r=a.fontScale,o=a.textColor,s=a.fontFamily,u=a.textWeight,f=a.fontStyle,p=e.fontSize,x=e.fontColor,g=void 0===x?o:x,v=e.fontFamily,d=void 0===v?s:v,m=e.fontWeight,y=void 0===m?u:m,S=e.fontStyle,T=void 0===S?f:S,b=p;t.font=T+" "+y+" "+b*r+"px "+d;var w=g[0],A=g[1],O=g[2],C=g[3];t.fillStyle="rgba("+w+", "+A+", "+O+", "+C+")";var z=i.offsetX&&i.offsetX[n]?i.offsetX[n]:0;l[n].forEach((function(e){t.fillText(e.char,c+z+e.x,h)}))})),n<e.length-1&&(o+=e[n+1].lineHeight)}))},n.unsupported=function(t){throw new Error("RichTextComponent does not support "+t+" at runtime.")},n.setShadowOffsetY=function(t){this.unsupported("setShadowOffsetY")},n.setShadowBlur=function(t){this.unsupported("setShadowBlur")},n.setShadowOffsetX=function(t){this.unsupported("setShadowOffsetX")},n.setShadowColor=function(t){this.unsupported("setShadowColor")},n.setOutlineWidth=function(t){this.unsupported("setOutlineWidth")},n.setAutoWidth=function(t){this.unsupported("setAutoWidth")},n.setFontSize=function(t){this.unsupported("setFontSize")},n.setTextBaseline=function(t){console.warn("setTextBaseline 已废弃,请改用 setTextVerticalAlign。本次调用将转调用 setTextVerticalAlign。"),this.setTextVerticalAlign(t)},i}(t.MaskableGraphic),exports.RichTextComponent=function(t,e,i,n){var r,a=arguments.length,o=a<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,i):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,e,i,n);else for(var s=t.length-1;s>=0;s--)(r=t[s])&&(o=(a<3?r(o):a>3?r(e,i,o):r(e,i))||o);return a>3&&o&&Object.defineProperty(e,i,o),o}([t.effectsClass(t.spec.DataType.RichTextComponent)],exports.RichTextComponent),t.applyMixins(exports.RichTextComponent,[t.TextComponentBase]);var M="2.8.6";t.registerPlugin("rich-text",u),t.logger.info("Plugin rich text version: 2.8.6."),M!==n.version&&console.error("注意:请统一 RichText 插件与 Player 版本,不统一的版本混用会有不可预知的后果!","\nAttention: Please ensure the RichText plugin is synchronized with the Player version. Mixing and matching incompatible versions may result in unpredictable consequences!"),exports.RichTextLoader=u,exports.escape=function(t){if("string"!=typeof t)throw new Error("Input must be a string");return t.replace(/\\/g,"\\\\").replace(/=/g,"\\=").replace(/</g,"\\<").replace(/>/g,"\\>").replace(/\//g,"\\/")},exports.generateProgram=y,exports.isRichText=function(t){var e=d(t).filter((function(t){var e=t.tokenType;return"ContextStart"===e||"ContextEnd"===e})),i=e.filter((function(t){return"ContextStart"===t.tokenType})),n=e.filter((function(t){return"ContextEnd"===t.tokenType}));return!(i.length!==n.length||!i.length)&&function t(e,i){var n=e[0],r=e.slice(1);if(void 0===i&&(i=[]),!n)return 0===i.length;if("ContextStart"===n.tokenType)return t(r,i.concat(n.value));if("ContextEnd"===n.tokenType)return i[i.length-1]===n.value&&t(r,i.slice(0,-1));throw new Error("Unexpected token: "+n.tokenType)}(e.map((function(t){var e=t.tokenType,i=t.value;return{tokenType:e,value:"ContextStart"===e?i.match(x)[1]:i.match(g)[1]}})))},exports.lexer=d,exports.richTextParser=m,exports.unescape=function(t){if("string"!=typeof t)throw new Error("Input must be a string");return t.replace(/\\\//g,"/").replace(/\\>/g,">").replace(/\\</g,"<").replace(/\\=/g,"=").replace(/\\\\/g,"\\")},exports.version=M;
2
2
  //# sourceMappingURL=alipay.js.map
package/dist/alipay.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import*as t from"@galacean/effects/alipay";import{Plugin as e,spec as i,effectsClass as n,applyMixins as r,TextComponentBase as a,TextStyle as o,math as l,assertExist as s,MaskableGraphic as h,registerPlugin as c,logger as f}from"@galacean/effects/alipay";import{document as u}from"@galacean/appx-adapter/alipay";function g(t,e){return g=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},g(t,e)}function x(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&&g(t,e)}function p(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(p=function(){return!!t})()}function v(t,e,i){return v=p()?Reflect.construct:function(t,e,i){var n=[null];n.push.apply(n,e);var r=new(Function.bind.apply(t,n));return i&&g(r,i.prototype),r},v.apply(null,arguments)}function d(t){return d=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},d(t)}function m(t){var e="function"==typeof Map?new Map:void 0;return m=function(t){if(null===t||(i=t,-1===Function.toString.call(i).indexOf("[native code]")))return t;var i;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,n)}function n(){return v(t,arguments,d(this).constructor)}return n.prototype=Object.create(t.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),g(n,t)},m(t)}var y,S=function(t){function e(){var e;return(e=t.apply(this,arguments)||this).name="rich-text",e}return x(e,t),e}(m(e));function T(t,e){(null==e||e>t.length)&&(e=t.length);for(var i=0,n=new Array(e);i<e;i++)n[i]=t[i];return n}function w(t,e){var i="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(i)return(i=i.call(t)).next.bind(i);if(Array.isArray(t)||(i=function(t,e){if(t){if("string"==typeof t)return T(t,e);var i=Object.prototype.toString.call(t).slice(8,-1);return"Object"===i&&t.constructor&&(i=t.constructor.name),"Map"===i||"Set"===i?Array.from(i):"Arguments"===i||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i)?T(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){i&&(t=i);var n=0;return function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}!function(t){t.ContextStart="ContextStart",t.Text="Text",t.ContextEnd="ContextEnd",t.EscapedChar="EscapedChar"}(y||(y={}));var b=/^<([a-z]+)(=([^>]+))?>$/,A=/^<\/([a-z]+)>$/,O=[["EscapedChar",/^\\([=<>\\/])/],["ContextStart",/^<[a-z]+(=[^>]+)?>/],["ContextEnd",/^<\/[a-z]+>/],["Text",/^[^</>=\\]+/]],C=function(t,e,i){if(void 0===e&&(e=[]),void 0===i&&(i=0),!t)return e;var n=/^\\([=<>\\/])/.exec(t);if(n){var r=n[1];return C(t.slice(2),e.concat({tokenType:"Text",value:r}),i+2)}for(var a,o=w(O);!(a=o()).done;){var l=a.value,s=l[0],h=l[1];if("EscapedChar"!==s){var c=h.exec(t);if(c){var f=c[0],u=f.length;return C(t.slice(u),e.concat({tokenType:s,value:f}),i+u)}}}if(t.length>0)return C(t.slice(1),e.concat({tokenType:"Text",value:t[0]}),i+1);throw new Error('Unexpected token: "'+t[0]+'" at position '+i+' while reading "'+t+'"')},z=function(t){var e=function(){for(var t,e="",i=!1;r.length>0&&"Text"===(null==(t=r[0])?void 0:t.tokenType);){var n=o();n&&(e+=n.value,i=!0)}return i?e:void 0},i=function(){var t=l();if("ContextStart"===(null==t?void 0:t.tokenType)){o();var e,i=t.value.match(b);if(i)return{attributeName:i[1],attributeParam:null!=(e=i[3])?e:""};throw new Error("Expected a start tag marker at position "+a)}return{}},n=function(){var t=l();if("ContextEnd"===(null==t?void 0:t.tokenType)){o();var e=t.value.match(A);if(e)return{attributeName:e[1]};throw new Error("Expect an end tag marker at position "+a)}return{}},r=C(t),a=0,o=function(){var t,e=r.shift();return a+=null!=(t=null==e?void 0:e.value.length)?t:0,e},l=function(){return r[0]},s=[];return function t(r,o){for(void 0===r&&(r=[]),void 0===o&&(o="");;){var l=e();if(l)s.push({attributes:r,text:l});else{var h=i(),c=h.attributeName,f=h.attributeParam;if(!c){if(o){var u=n().attributeName;if(!u)throw new Error('Expect an end tag marker "'+o+'" at position '+a+" but found no tag!");if(u!==o)throw new Error('Expect an end tag marker "'+o+'" at position '+a+' but found tag "'+u+'"');return}break}t(r.concat({attributeName:c,attributeParam:null!=f?f:""}),c)}}}(),s};function L(t){return function(e){for(var i,n=w(z(e));!(i=n()).done;){var r=i.value,a=r.text,o=r.attributes.reduce((function(t,e){var i=e.attributeName,n=e.attributeParam;return i&&(t[i]=n),t}),{});t(a,o)}}}function H(t){var e=C(t).filter((function(t){var e=t.tokenType;return"ContextStart"===e||"ContextEnd"===e})),i=e.filter((function(t){return"ContextStart"===t.tokenType})),n=e.filter((function(t){return"ContextEnd"===t.tokenType}));if(i.length!==n.length||!i.length)return!1;return function t(e,i){var n=e[0],r=e.slice(1);if(void 0===i&&(i=[]),!n)return 0===i.length;if("ContextStart"===n.tokenType)return t(r,i.concat(n.value));if("ContextEnd"===n.tokenType)return i[i.length-1]===n.value&&t(r,i.slice(0,-1));throw new Error("Unexpected token: "+n.tokenType)}(e.map((function(t){var e=t.tokenType,i=t.value;return{tokenType:e,value:"ContextStart"===e?i.match(b)[1]:i.match(A)[1]}})))}function E(t){if("string"!=typeof t)throw new Error("Input must be a string");return t.replace(/\\/g,"\\\\").replace(/=/g,"\\=").replace(/</g,"\\<").replace(/>/g,"\\>").replace(/\//g,"\\/")}function W(t){if("string"!=typeof t)throw new Error("Input must be a string");return t.replace(/\\\//g,"/").replace(/\\>/g,">").replace(/\\</g,"<").replace(/\\=/g,"=").replace(/\\\\/g,"\\")}"function"==typeof SuppressedError&&SuppressedError;var V=function(){function t(t){this.width=0,this.height=0;var e=t.size,n=t.textOverflow,r=void 0===n?i.TextOverflow.clip:n,a=t.textVerticalAlign,o=void 0===a?i.TextVerticalAlign.middle:a,l=t.textAlign,s=void 0===l?i.TextAlignment.left:l,h=t.letterSpace,c=void 0===h?0:h,f=t.lineHeight,u=void 0===f?.571:f,g=t.wrapEnabled,x=void 0!==g&&g,p=t.maxTextWidth,v=void 0===p?350:p,d=t.maxTextHeight,m=void 0===d?1e3:d,y=t.sizeMode,S=void 0===y?i.TextSizeMode.autoWidth:y,T=t.useLegacyRichText,w=void 0!==T&&T;this.letterSpace=c,this.lineHeight=u,this.useLegacyRichText=w,this.overflow=r,this.textVerticalAlign=o,this.textAlign=s,this.width=e?e[0]:100,this.height=e?e[1]:100,this.wrapEnabled=x;this.maxTextWidth=50*v,this.maxTextHeight=50*m,this.sizeMode=S}var e=t.prototype;return e.getOffsetY=function(t,e,n,r,a){var o=t.outlineWidth,l=t.fontScale,s=(n-r)/3,h=r+o*l,c=void 0!==a?a:n*(e-1),f=0;switch(this.textVerticalAlign){case i.TextVerticalAlign.top:f=h+s;break;case i.TextVerticalAlign.middle:f=(this.height*l-c+h)/2;break;case i.TextVerticalAlign.bottom:f=this.height*l-c-s}return f},e.getOffsetX=function(t,e){var n=0;switch(this.textAlign){case i.TextAlignment.left:n=t.outlineWidth*t.fontScale;break;case i.TextAlignment.middle:n=(this.width*t.fontScale-e)/2;break;case i.TextAlignment.right:n=this.width*t.fontScale-e}return n},e.getOffsetYRich=function(t,e,n){if(0===e.length)return 0;var r=t.outlineWidth,a=t.fontScale,o=e.reduce((function(t,e){return t+e}),0),l=(e[0]-n)/3,s=n+r*a,h=o-e[0],c=0;switch(this.textVerticalAlign){case i.TextVerticalAlign.top:c=s+l;break;case i.TextVerticalAlign.middle:c=(this.height*a-o)/2+s;break;case i.TextVerticalAlign.bottom:c=this.height*a-h-l}return c},e.getOffsetXRich=function(t,e,n){switch(this.textAlign){case i.TextAlignment.left:return t.outlineWidth*t.fontScale;case i.TextAlignment.middle:return(e-n)/2;case i.TextAlignment.right:return e-n;default:return 0}},e.setSize=function(t,e){this.width=t,this.height=e},t}();function M(t,e){if(void 0===e&&(e=1),3!==(t=t.replace(/^#/,"")).length&&4!==t.length||(t=t.split("").map((function(t){return t+t})).join("")),8===t.length){var i=parseInt(t.slice(6,8),16)/255;t=t.slice(0,6),e=i}var n=parseInt(t,16);return[n>>16&255,n>>8&255,255&n,e]}function k(t,e){if(void 0===e&&(e=1),"string"!=typeof t||!t)throw new Error("Invalid color string");return t.startsWith("#")?M(t,e):M(function(t){if("string"!=typeof t||!t)throw new Error("Invalid color name provided");if(void 0===u)throw new Error("This method requires a browser environment");var e=u.createElement("canvas"),i=e.getContext("2d");if(i)try{return i.fillStyle=t,i.fillStyle}finally{null==e.remove||e.remove.call(e)}throw new Error("Failed to get 2D context for color conversion!")}(t))}var R=function(){function t(){}var e=t.prototype;return e.computeLines=function(t,e,i,n,r,a,o,l){var s=this,h=[],c=[],f=(n.lineHeight||0)*a,u=this.createNewLine(),g=0,x=0,p=function(){if(0!==u.chars.length){u.lineHeight=0===h.length?(u.lineAscent||0)+(u.lineDescent||0):f;var t=0===h.length?0:c[c.length-1]+f;c.push(t),x+=u.lineHeight,h.push(u),g=Math.max(g,u.width),u=s.createNewLine()}};t.forEach((function(t){var n=t.text,r=t.isNewLine,s=t.fontSize;r&&p();var h=t.fontStyle||i.fontStyle||"normal";e.font=h+" "+(t.fontWeight||i.textWeight)+" 10px "+(t.fontFamily||i.fontFamily),u.offsetX.push(u.width);for(var c=0,f=[],g=0,x=0,v=0;v<n.length;v++){var d=n[v],m=e.measureText(d),y=m.width,S=(y<=0?0:y)*s*l*a,T=s*a*l,w=m.actualBoundingBoxAscent*T,b=m.actualBoundingBoxDescent*T;g=Math.max(g,w),x=Math.max(x,b),v>0&&(c+=o),f.push({char:d,x:c}),c+=S}u.chars.push(f),u.width+=c,u.richOptions.push(t),u.lineAscent=Math.max(u.lineAscent||0,g),u.lineDescent=Math.max(u.lineDescent||0,x)})),p();var v=1/0,d=-1/0;if(0===h.length)return{lines:h,maxLineWidth:g,totalHeight:x,bboxTop:0,bboxBottom:0,bboxHeight:0};for(var m=0;m<h.length;m++)v=Math.min(v,c[m]-(h[m].lineAscent||0)),d=Math.max(d,c[m]+(h[m].lineDescent||0));return{lines:h,maxLineWidth:g,totalHeight:x,bboxTop:v,bboxBottom:d,bboxHeight:d-v}},e.createNewLine=function(){return{richOptions:[],offsetX:[],width:0,lineHeight:0,offsetY:0,chars:[],lineAscent:0,lineDescent:0}},t}(),F=function(){function t(){}var e=t.prototype;return e.computeLines=function(t,e,i,n,r,a,o,l){var s=this,h=[],c=[],f=(n.lineHeight||0)*a,u=this.createNewLine(),g=0,x=0,p=null,v=0,d=[],m=null,y=function(){if(S(),0!==u.chars.length){u.lineHeight=0===h.length?(u.lineAscent||0)+(u.lineDescent||0):f;var t=0===h.length?0:c[c.length-1]+f;c.push(t),x+=u.lineHeight,h.push(u),g=Math.max(g,u.width),u=s.createNewLine(),p=null,v=0,d=[],m=null}},S=function(){0!==d.length&&(null===p&&(p=u.width),u.offsetX.push(p),u.chars.push(d),m&&u.richOptions.push(m),p=null,v=0,d=[],m=null)};t.forEach((function(t){var r=t.text,s=t.isNewLine,h=t.fontSize,c=t.fontStyle||i.fontStyle||"normal";e.font=c+" "+(t.fontWeight||i.textWeight)+" 10px "+(t.fontFamily||i.fontFamily),s&&(S(),y());for(var f=0;f<r.length;f++){var g=r[f],x=e.measureText(g),T=x.width,w=(T<=0?0:T)*h*l*a,b=h*a*l,A=x.actualBoundingBoxAscent*b,O=x.actualBoundingBoxDescent*b,C=d.length>0?o:0;u.width+C+w>(n.maxTextWidth||1/0)&&(S(),y()),null===p&&(p=u.width,m=t),d.length>0&&(v+=o,u.width+=o),d.push({char:g,x:v}),u.lineAscent=Math.max(u.lineAscent||0,A),u.lineDescent=Math.max(u.lineDescent||0,O),v+=w,u.width+=w}S()})),y();for(var T=1/0,w=-1/0,b=0;b<h.length;b++)T=Math.min(T,c[b]-(h[b].lineAscent||0)),w=Math.max(w,c[b]+(h[b].lineDescent||0));return{lines:h,maxLineWidth:g,totalHeight:x,bboxTop:T,bboxBottom:w,bboxHeight:w-T}},e.createNewLine=function(){return{richOptions:[],offsetX:[],width:0,lineHeight:0,offsetY:0,chars:[],lineAscent:0,lineDescent:0}},t}(),D=function(){function t(){}return t.prototype.apply=function(t,e,i,n){var r,a,o=function(t,e){return Math.abs(e)>1e-5?t/e:1},l=i.maxTextWidth*n.fontScale,s=i.maxTextHeight*n.fontScale,h=Math.max(1,null!=(r=e.contentWidth)?r:e.canvasWidth),c=Math.max(1,null!=(a=e.bboxHeight)?a:e.canvasHeight),f=Math.min(1,o(l,h),o(s,c));if(f>.9999)return{globalScale:1};for(var u,g=w(t);!(u=g()).done;){var x=u.value;if(x.width*=f,x.lineHeight*=f,x.offsetX)for(var p=0;p<x.offsetX.length;p++)x.offsetX[p]*=f;for(var v,d=w(x.chars||[]);!(v=d()).done;)for(var m,y=w(v.value);!(m=y()).done;){m.value.x*=f}for(var S,T=w(x.richOptions||[]);!(S=T()).done;){S.value.fontSize*=f}null!=x.lineAscent&&(x.lineAscent*=f),null!=x.lineDescent&&(x.lineDescent*=f)}return{globalScale:f}},t}(),B=function(){function t(){}return t.prototype.apply=function(t,e,i,n){return{globalScale:1}},t}(),_=function(){function t(){}return t.prototype.apply=function(t,e,i,n){return{globalScale:1}},t}(),X=function(){function t(){}return t.prototype.getHorizontalOffsets=function(t,e,n,r,a){var o,l,s=null!=(o=e.containerWidth)?o:r.maxTextWidth*a.fontScale,h=null!=(l=e.baselineCompensationX)?l:0,c=t.map((function(t){return r.getOffsetXRich(a,s,t.width)}));return{lineOffsets:r.overflow===i.TextOverflow.visible?c.map((function(t){return t+h})):c}},t}(),Y=function(){function t(){}return t.prototype.getVerticalOffsets=function(t,e,n,r,a,o){var l,s=null!=(l=e.baselineCompensationY)?l:0,h=0;if(0===t.length)return{baselineY:0,lineYOffsets:[]};switch(r.overflow){case i.TextOverflow.visible:var c,f,u,g,x=r.maxTextHeight*a.fontScale,p=null!=(c=e.bboxTop)?c:0,v=null!=(u=e.bboxBottom)?u:p+(null!=(f=e.bboxHeight)?f:0),d=null!=(g=e.bboxHeight)?g:v-p,m=0;switch(r.textVerticalAlign){case i.TextVerticalAlign.top:m=-p;break;case i.TextVerticalAlign.middle:m=(x-d)/2-p;break;case i.TextVerticalAlign.bottom:m=x-d-p}h=m+s;break;case i.TextOverflow.clip:for(var y=r.maxTextHeight*a.fontScale,S=[0],T=1;T<t.length;T++)S[T]=S[T-1]+t[T].lineHeight;for(var w=1/0,b=-1/0,A=0;A<t.length;A++){var O,C,z=null!=(O=t[A].lineAscent)?O:0,L=null!=(C=t[A].lineDescent)?C:0;w=Math.min(w,S[A]-z),b=Math.max(b,S[A]+L)}var H=b-w,E=0;switch(r.textVerticalAlign){case i.TextVerticalAlign.top:E=-w;break;case i.TextVerticalAlign.middle:E=(y-H)/2-w;break;case i.TextVerticalAlign.bottom:E=y-H-w}h=E+s;break;case i.TextOverflow.display:for(var W=r.maxTextHeight*a.fontScale,V=[0],M=1;M<t.length;M++)V[M]=V[M-1]+t[M].lineHeight;for(var k=1/0,R=-1/0,F=0;F<t.length;F++){var D,B,_=null!=(D=t[F].lineAscent)?D:0,X=null!=(B=t[F].lineDescent)?B:0;k=Math.min(k,V[F]-_),R=Math.max(R,V[F]+X)}var Y=R-k,P=0;switch(r.textVerticalAlign){case i.TextVerticalAlign.top:P=-k;break;case i.TextVerticalAlign.middle:P=(W-Y)/2-k;break;case i.TextVerticalAlign.bottom:P=W-Y-k}for(var N=[],j=P,I=0;I<t.length;I++)N.push(j),I<t.length-1&&(j+=t[I+1].lineHeight);return{baselineY:P,lineYOffsets:N}}var U=[],$=h;return t.forEach((function(e,i){U.push($),i<t.length-1&&($+=t[i+1].lineHeight)})),{baselineY:h,lineYOffsets:U}},t}(),P=function(){function t(){}return t.createWrapStrategy=function(t){return t?new F:new R},t.createOverflowStrategy=function(t){switch(t){case i.TextOverflow.clip:return new B;case i.TextOverflow.display:return new D;case i.TextOverflow.visible:default:return new _}},t.createHorizontalAlignStrategy=function(){return new X},t.createVerticalAlignStrategy=function(){return new Y},t}(),N=0,j=function(t){function e(e){var n;return(n=t.call(this,e)||this).isDirty=!0,n.text="",n.processedTextOptions=[],n.singleLineHeight=1.571,n.size=null,n.initialized=!1,n.canvasSize=null,n.SCALE_FACTOR=.1,n.ALPHA_FIX_VALUE=1/255,n.name="MRichText"+N++,n.initTextBase(e),n.richWrapStrategy=P.createWrapStrategy(),n.richOverflowStrategy=P.createOverflowStrategy(i.TextOverflow.display),n.richHorizontalAlignStrategy=P.createHorizontalAlignStrategy(),n.richVerticalAlignStrategy=P.createVerticalAlignStrategy(),n}x(e,t);var n=e.prototype;return n.onUpdate=function(e){t.prototype.onUpdate.call(this,e),this.updateTexture()},n.onDestroy=function(){t.prototype.onDestroy.call(this),this.disposeTextTexture()},n.fromData=function(e){t.prototype.fromData.call(this,e);var n=e.interaction,r=e.options;this.interaction=n,this.textStyle=new o(r),this.textLayout=new V(r),this.text=r.text?r.text.toString():" ",this.textLayout.useLegacyRichText&&(this.textLayout.textVerticalAlign=i.TextVerticalAlign.middle),this.updateStrategies(),this.renderText(r),this.material.setColor("_Color",new l.Color(1,1,1,1))},n.updateStrategies=function(){var t=this.textLayout;t&&(this.richWrapStrategy=P.createWrapStrategy(t.wrapEnabled),this.richOverflowStrategy=P.createOverflowStrategy(t.overflow))},n.generateTextProgram=function(t){var e=this;this.processedTextOptions=[];var n=L((function(t,n){/^\n+$/.test(t)&&(t=t.replace(/\n/g,"\n ")),t.split("\n").forEach((function(t,r){var a={text:t,fontSize:e.textStyle.fontSize,isNewLine:!1};r>0&&(a.isNewLine=!0),"b"in n&&(a.fontWeight=i.TextWeight.bold),"i"in n&&(a.fontStyle=i.FontStyle.italic),"size"in n&&n.size&&(a.fontSize=parseInt(n.size,10)),"color"in n&&n.color&&(a.fontColor=k(n.color)),e.processedTextOptions.push(a)}))}));n(t)},n.updateWithOptions=function(t){this.textStyle=new o(t),this.textLayout=new V(t),this.text=t.text?t.text.toString():" ",this.textLayout.useLegacyRichText&&(this.textLayout.textVerticalAlign=i.TextVerticalAlign.middle),this.updateStrategies(),this.isDirty=!0},n.renderText=function(t){var e=t.size;e&&(this.canvasSize=new l.Vector2(e[0],e[1])),this.updateTexture()},n.updateTexture=function(t){if(void 0===t&&(t=!0),this.isDirty&&this.context&&this.canvas&&this.textStyle&&this.textLayout){var e=!0===this.textLayout.useLegacyRichText;this.singleLineHeight=e?1.571:1,e?this.updateTextureLegacy(t):this.updateTextureWithStrategies(t)}},n.updateTextureLegacy=function(t){var e=this;if(this.isDirty&&this.context&&this.canvas&&this.textStyle){this.generateTextProgram(this.text);var n=0,r=0,a=this.textLayout,o=this.textStyle,h=a.overflow,c=a.letterSpace,f=void 0===c?0:c,u=this.context,g=[],x=o.fontSize*o.fontScale,p={richOptions:[],offsetX:[],width:0,lineHeight:x*this.singleLineHeight,offsetY:x*(this.singleLineHeight-1)/2};if(this.processedTextOptions.forEach((function(t){var i=t.text,a=t.isNewLine,l=t.fontSize;a&&(g.push(p),n=Math.max(n,p.width),p={richOptions:[],offsetX:[],width:0,lineHeight:x*e.singleLineHeight,offsetY:x*(e.singleLineHeight-1)/2},r+=p.lineHeight),u.font=(t.fontWeight||o.textWeight)+" 10px "+(t.fontFamily||o.fontFamily);var s=u.measureText(i),h=s.width;if(void 0!==s.actualBoundingBoxLeft&&void 0!==s.actualBoundingBoxRight){var c=s.actualBoundingBoxLeft+s.actualBoundingBoxRight;c>0&&(h=Math.max(h,c))}var v=l*e.singleLineHeight*o.fontScale;v>p.lineHeight&&(r+=v-p.lineHeight,p.lineHeight=v,p.offsetY=l*o.fontScale*(e.singleLineHeight-1)/2),p.offsetX.push(p.width),p.width+=(h<=0?0:h)*l*e.SCALE_FACTOR*o.fontScale+i.length*f,p.richOptions.push(t)})),g.push(p),n=Math.max(n,p.width),r+=p.lineHeight,0!==n&&0!==r){void 0!==this.size&&null!==this.size||(this.size=this.item.transform.size.clone());var v=this.size,d=v.x,m=void 0===d?1:d,y=v.y,S=void 0===y?1:y;if(!this.initialized){this.canvasSize=this.canvasSize?this.canvasSize:new l.Vector2(n,r);var T=this.canvasSize,w=T.x,b=T.y;this.item.transform.size.set(m*w*this.SCALE_FACTOR*this.SCALE_FACTOR,S*b*this.SCALE_FACTOR*this.SCALE_FACTOR),this.size=this.item.transform.size.clone(),this.initialized=!0}s(this.canvasSize);var A=this.canvasSize,O=A.x,C=A.y;a.width=O/o.fontScale,a.height=C/o.fontScale,this.renderToTexture(O,C,t,(function(t){if(0!==g.length){var n=a.getOffsetY(o,g.length,x*e.singleLineHeight,o.fontSize);g.forEach((function(e,r){var l=e.richOptions,s=e.offsetX,c=e.width,f=c,u=s;if(h===i.TextOverflow.display&&c>O){var g=O/c;f*=g,u=s.map((function(t){return t*g}))}var x=a.getOffsetX(o,f);r>0&&(n+=e.lineHeight-e.offsetY),l.forEach((function(e,r){var a=o.fontScale,l=o.textColor,s=o.fontFamily,f=o.textWeight,g=o.fontStyle,p=e.text,v=e.fontSize,d=e.fontColor,m=void 0===d?l:d,y=e.fontFamily,S=void 0===y?s:y,T=e.fontWeight,w=void 0===T?f:T,b=e.fontStyle,A=void 0===b?g:b,C=v;h===i.TextOverflow.display&&c>O&&(C/=c/O);var z=u[r]+x;t.font=A+" "+w+" "+C*a+"px "+S;var L=m[0],H=m[1],E=m[2],W=m[3];t.fillStyle="rgba("+L+", "+H+", "+E+", "+W+")",t.fillText(p,z,n)}))}))}}),{disposeOld:!1}),this.isDirty=!1}else this.isDirty=!1}},n.updateTextureWithStrategies=function(t){var e=this;if(this.isDirty&&this.context&&this.canvas){this.generateTextProgram(this.text);var i=this.textLayout,n=i.letterSpace,r=void 0===n?0:n,a=this.context;if(a){var o=this.richWrapStrategy.computeLines(this.processedTextOptions,a,this.textStyle,i,this.singleLineHeight,this.textStyle.fontScale,r,this.SCALE_FACTOR);if(0!==o.lines.length&&0!==o.maxLineWidth&&0!==o.totalHeight){var l=this.resolveCanvasSize(o,i,this.textStyle,this.singleLineHeight);this.setCanvasSize(l);var h=this.richOverflowStrategy.apply(o.lines,l,i,this.textStyle),c=this.richHorizontalAlignStrategy.getHorizontalOffsets(o.lines,l,h,i,this.textStyle),f=this.richVerticalAlignStrategy.getVerticalOffsets(o.lines,l,h,i,this.textStyle,this.singleLineHeight);s(this.canvasSize);var u=this.canvasSize,g=u.x,x=u.y,p=Math.max(1,Math.ceil(g)),v=Math.max(1,Math.ceil(x));i.width=p/this.textStyle.fontScale,i.height=v/this.textStyle.fontScale,this.renderToTexture(p,v,t,(function(t){e.drawTextWithStrategies(t,o.lines,c,f,h,e.textStyle)}),{disposeOld:!1}),this.isDirty=!1}else this.isDirty=!1}}},n.setCanvasSize=function(t){var e=this;void 0!==this.size&&null!==this.size||(this.size=this.item.transform.size.clone());var n=this.size,r=n.x,a=void 0===r?1:r,o=n.y,s=void 0===o?1:o,h=this.textLayout,c=this.textStyle.fontScale||1,f=Math.max(1,h.maxTextWidth||0),u=Math.max(1,h.maxTextHeight||0);switch(h.overflow){case i.TextOverflow.visible:var g,x,p,v,d=f*c,m=u*c,y=null!=(g=t.bboxTop)?g:0,S=null!=(p=t.bboxBottom)?p:y+(null!=(x=t.bboxHeight)?x:0),T=null!=(v=t.bboxHeight)?v:S-y,w=0;switch(h.textVerticalAlign){case i.TextVerticalAlign.top:w=-y;break;case i.TextVerticalAlign.middle:w=(m-T)/2-y;break;case i.TextVerticalAlign.bottom:w=m-T-y}var b=w+y,A=w+S,O=Math.max(0,-b),C=Math.max(0,A-m),z=O,L=C;switch(h.textVerticalAlign){case i.TextVerticalAlign.top:z=C,L=C;break;case i.TextVerticalAlign.bottom:z=O,L=O;break;case i.TextVerticalAlign.middle:z=O,L=C}for(var H=z,E=t.lines||[],W=E.map((function(t){return h.getOffsetXRich(e.textStyle,d,t.width)})),V=1/0,M=-1/0,k=0;k<E.length;k++){var R,F,D=null!=(R=W[k])?R:0,B=null!=(F=E[k].width)?F:0;V=Math.min(V,D),M=Math.max(M,D+B)}isFinite(V)||(V=0),isFinite(M)||(M=0);var _,X=Math.max(0,-V),Y=Math.max(0,M-d),P=Math.ceil(d+X+Y),N=Math.ceil(m+z+L);t.baselineCompensationX=X,t.baselineCompensationY=H,t.containerWidth=d,t.canvasWidth=P,t.canvasHeight=N,this.canvasSize=new l.Vector2(P,N);var j=null!=(_=this.size)?_:this.item.transform.size,I=j.x,U=void 0===I?1:I,$=j.y,q=void 0===$?1:$;this.item.transform.size.set(U*P*this.SCALE_FACTOR*this.SCALE_FACTOR,q*N*this.SCALE_FACTOR*this.SCALE_FACTOR),this.initialized=!0;break;case i.TextOverflow.clip:var G,J=f*c,K=u*c;t.canvasWidth=J,t.canvasHeight=K,t.baselineCompensationX=0,t.baselineCompensationY=0,this.canvasSize=new l.Vector2(J,K),h.width=f,h.height=u;var Q=null!=(G=this.size)?G:this.item.transform.size,Z=Q.x,tt=void 0===Z?1:Z,et=Q.y,it=void 0===et?1:et;this.item.transform.size.set(tt*J*this.SCALE_FACTOR*this.SCALE_FACTOR,it*K*this.SCALE_FACTOR*this.SCALE_FACTOR),this.initialized=!0;break;case i.TextOverflow.display:if(!this.initialized){var nt=f*c,rt=u*c;this.canvasSize=new l.Vector2(nt,rt),this.item.transform.size.set(a*nt*this.SCALE_FACTOR*this.SCALE_FACTOR,s*rt*this.SCALE_FACTOR*this.SCALE_FACTOR),this.initialized=!0}}},n.resolveCanvasSize=function(t,e,i,n){var r=Math.max(1,t.maxLineWidth||0),a=Math.max(1,t.totalHeight||0);return e.width=r/i.fontScale,e.height=a/i.fontScale,{canvasWidth:r,canvasHeight:a,contentWidth:t.maxLineWidth,bboxTop:t.bboxTop,bboxBottom:t.bboxBottom,bboxHeight:t.bboxHeight,lines:t.lines}},n.drawTextWithStrategies=function(t,e,i,n,r,a){var o=n.baselineY,l=i.lineOffsets;e.forEach((function(i,n){var r=i.richOptions,s=i.chars,h=l[n],c=o;r.forEach((function(e,n){var r=a.fontScale,o=a.textColor,l=a.fontFamily,f=a.textWeight,u=a.fontStyle,g=e.fontSize,x=e.fontColor,p=void 0===x?o:x,v=e.fontFamily,d=void 0===v?l:v,m=e.fontWeight,y=void 0===m?f:m,S=e.fontStyle,T=void 0===S?u:S,w=g;t.font=T+" "+y+" "+w*r+"px "+d;var b=p[0],A=p[1],O=p[2],C=p[3];t.fillStyle="rgba("+b+", "+A+", "+O+", "+C+")";var z=i.offsetX&&i.offsetX[n]?i.offsetX[n]:0;s[n].forEach((function(e){t.fillText(e.char,h+z+e.x,c)}))})),n<e.length-1&&(o+=e[n+1].lineHeight)}))},n.unsupported=function(t){throw new Error("RichTextComponent does not support "+t+" at runtime.")},n.setShadowOffsetY=function(t){this.unsupported("setShadowOffsetY")},n.setShadowBlur=function(t){this.unsupported("setShadowBlur")},n.setShadowOffsetX=function(t){this.unsupported("setShadowOffsetX")},n.setShadowColor=function(t){this.unsupported("setShadowColor")},n.setOutlineWidth=function(t){this.unsupported("setOutlineWidth")},n.setAutoWidth=function(t){this.unsupported("setAutoWidth")},n.setFontSize=function(t){this.unsupported("setFontSize")},n.setTextBaseline=function(t){console.warn("setTextBaseline 已废弃,请改用 setTextVerticalAlign。本次调用将转调用 setTextVerticalAlign。"),this.setTextVerticalAlign(t)},e}(h);r(j=function(t,e,i,n){var r,a=arguments.length,o=a<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,i):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,e,i,n);else for(var l=t.length-1;l>=0;l--)(r=t[l])&&(o=(a<3?r(o):a>3?r(e,i,o):r(e,i))||o);return a>3&&o&&Object.defineProperty(e,i,o),o}([n(i.DataType.RichTextComponent)],j),[a]);var I="2.8.4";c("rich-text",S),f.info("Plugin rich text version: 2.8.4."),I!==t.version&&console.error("注意:请统一 RichText 插件与 Player 版本,不统一的版本混用会有不可预知的后果!","\nAttention: Please ensure the RichText plugin is synchronized with the Player version. Mixing and matching incompatible versions may result in unpredictable consequences!");export{j as RichTextComponent,S as RichTextLoader,E as escape,L as generateProgram,H as isRichText,C as lexer,z as richTextParser,W as unescape,I as version};
1
+ import*as t from"@galacean/effects/alipay";import{Plugin as e,spec as i,effectsClass as n,applyMixins as r,TextComponentBase as a,TextStyle as o,math as l,assertExist as s,MaskableGraphic as h,registerPlugin as c,logger as f}from"@galacean/effects/alipay";import{document as u}from"@galacean/appx-adapter/alipay";function g(t,e){return g=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},g(t,e)}function x(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&&g(t,e)}function p(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(p=function(){return!!t})()}function v(t,e,i){return v=p()?Reflect.construct:function(t,e,i){var n=[null];n.push.apply(n,e);var r=new(Function.bind.apply(t,n));return i&&g(r,i.prototype),r},v.apply(null,arguments)}function d(t){return d=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},d(t)}function m(t){var e="function"==typeof Map?new Map:void 0;return m=function(t){if(null===t||(i=t,-1===Function.toString.call(i).indexOf("[native code]")))return t;var i;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,n)}function n(){return v(t,arguments,d(this).constructor)}return n.prototype=Object.create(t.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),g(n,t)},m(t)}var y,S=function(t){function e(){var e;return(e=t.apply(this,arguments)||this).name="rich-text",e}return x(e,t),e}(m(e));function T(t,e){(null==e||e>t.length)&&(e=t.length);for(var i=0,n=new Array(e);i<e;i++)n[i]=t[i];return n}function w(t,e){var i="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(i)return(i=i.call(t)).next.bind(i);if(Array.isArray(t)||(i=function(t,e){if(t){if("string"==typeof t)return T(t,e);var i=Object.prototype.toString.call(t).slice(8,-1);return"Object"===i&&t.constructor&&(i=t.constructor.name),"Map"===i||"Set"===i?Array.from(i):"Arguments"===i||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i)?T(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){i&&(t=i);var n=0;return function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}!function(t){t.ContextStart="ContextStart",t.Text="Text",t.ContextEnd="ContextEnd",t.EscapedChar="EscapedChar"}(y||(y={}));var b=/^<([a-z]+)(=([^>]+))?>$/,A=/^<\/([a-z]+)>$/,O=[["EscapedChar",/^\\([=<>\\/])/],["ContextStart",/^<[a-z]+(=[^>]+)?>/],["ContextEnd",/^<\/[a-z]+>/],["Text",/^[^</>=\\]+/]],C=function(t,e,i){if(void 0===e&&(e=[]),void 0===i&&(i=0),!t)return e;var n=/^\\([=<>\\/])/.exec(t);if(n){var r=n[1];return C(t.slice(2),e.concat({tokenType:"Text",value:r}),i+2)}for(var a,o=w(O);!(a=o()).done;){var l=a.value,s=l[0],h=l[1];if("EscapedChar"!==s){var c=h.exec(t);if(c){var f=c[0],u=f.length;return C(t.slice(u),e.concat({tokenType:s,value:f}),i+u)}}}if(t.length>0)return C(t.slice(1),e.concat({tokenType:"Text",value:t[0]}),i+1);throw new Error('Unexpected token: "'+t[0]+'" at position '+i+' while reading "'+t+'"')},z=function(t){var e=function(){for(var t,e="",i=!1;r.length>0&&"Text"===(null==(t=r[0])?void 0:t.tokenType);){var n=o();n&&(e+=n.value,i=!0)}return i?e:void 0},i=function(){var t=l();if("ContextStart"===(null==t?void 0:t.tokenType)){o();var e,i=t.value.match(b);if(i)return{attributeName:i[1],attributeParam:null!=(e=i[3])?e:""};throw new Error("Expected a start tag marker at position "+a)}return{}},n=function(){var t=l();if("ContextEnd"===(null==t?void 0:t.tokenType)){o();var e=t.value.match(A);if(e)return{attributeName:e[1]};throw new Error("Expect an end tag marker at position "+a)}return{}},r=C(t),a=0,o=function(){var t,e=r.shift();return a+=null!=(t=null==e?void 0:e.value.length)?t:0,e},l=function(){return r[0]},s=[];return function t(r,o){for(void 0===r&&(r=[]),void 0===o&&(o="");;){var l=e();if(l)s.push({attributes:r,text:l});else{var h=i(),c=h.attributeName,f=h.attributeParam;if(!c){if(o){var u=n().attributeName;if(!u)throw new Error('Expect an end tag marker "'+o+'" at position '+a+" but found no tag!");if(u!==o)throw new Error('Expect an end tag marker "'+o+'" at position '+a+' but found tag "'+u+'"');return}break}t(r.concat({attributeName:c,attributeParam:null!=f?f:""}),c)}}}(),s};function L(t){return function(e){for(var i,n=w(z(e));!(i=n()).done;){var r=i.value,a=r.text,o=r.attributes.reduce((function(t,e){var i=e.attributeName,n=e.attributeParam;return i&&(t[i]=n),t}),{});t(a,o)}}}function H(t){var e=C(t).filter((function(t){var e=t.tokenType;return"ContextStart"===e||"ContextEnd"===e})),i=e.filter((function(t){return"ContextStart"===t.tokenType})),n=e.filter((function(t){return"ContextEnd"===t.tokenType}));if(i.length!==n.length||!i.length)return!1;return function t(e,i){var n=e[0],r=e.slice(1);if(void 0===i&&(i=[]),!n)return 0===i.length;if("ContextStart"===n.tokenType)return t(r,i.concat(n.value));if("ContextEnd"===n.tokenType)return i[i.length-1]===n.value&&t(r,i.slice(0,-1));throw new Error("Unexpected token: "+n.tokenType)}(e.map((function(t){var e=t.tokenType,i=t.value;return{tokenType:e,value:"ContextStart"===e?i.match(b)[1]:i.match(A)[1]}})))}function E(t){if("string"!=typeof t)throw new Error("Input must be a string");return t.replace(/\\/g,"\\\\").replace(/=/g,"\\=").replace(/</g,"\\<").replace(/>/g,"\\>").replace(/\//g,"\\/")}function W(t){if("string"!=typeof t)throw new Error("Input must be a string");return t.replace(/\\\//g,"/").replace(/\\>/g,">").replace(/\\</g,"<").replace(/\\=/g,"=").replace(/\\\\/g,"\\")}"function"==typeof SuppressedError&&SuppressedError;var V=function(){function t(t){this.width=0,this.height=0;var e=t.size,n=t.textOverflow,r=void 0===n?i.TextOverflow.clip:n,a=t.textVerticalAlign,o=void 0===a?i.TextVerticalAlign.middle:a,l=t.textAlign,s=void 0===l?i.TextAlignment.left:l,h=t.letterSpace,c=void 0===h?0:h,f=t.lineHeight,u=void 0===f?.571:f,g=t.wrapEnabled,x=void 0!==g&&g,p=t.maxTextWidth,v=void 0===p?350:p,d=t.maxTextHeight,m=void 0===d?1e3:d,y=t.sizeMode,S=void 0===y?i.TextSizeMode.autoWidth:y,T=t.useLegacyRichText,w=void 0!==T&&T;this.letterSpace=c,this.lineHeight=u,this.useLegacyRichText=w,this.overflow=r,this.textVerticalAlign=o,this.textAlign=s,this.width=e?e[0]:100,this.height=e?e[1]:100,this.wrapEnabled=x;this.maxTextWidth=50*v,this.maxTextHeight=50*m,this.sizeMode=S}var e=t.prototype;return e.getOffsetY=function(t,e,n,r,a){var o=t.outlineWidth,l=t.fontScale,s=(n-r)/3,h=r+o*l,c=void 0!==a?a:n*(e-1),f=0;switch(this.textVerticalAlign){case i.TextVerticalAlign.top:f=h+s;break;case i.TextVerticalAlign.middle:f=(this.height*l-c+h)/2;break;case i.TextVerticalAlign.bottom:f=this.height*l-c-s}return f},e.getOffsetX=function(t,e){var n=0;switch(this.textAlign){case i.TextAlignment.left:n=t.outlineWidth*t.fontScale;break;case i.TextAlignment.middle:n=(this.width*t.fontScale-e)/2;break;case i.TextAlignment.right:n=this.width*t.fontScale-e}return n},e.getOffsetYRich=function(t,e,n){if(0===e.length)return 0;var r=t.outlineWidth,a=t.fontScale,o=e.reduce((function(t,e){return t+e}),0),l=(e[0]-n)/3,s=n+r*a,h=o-e[0],c=0;switch(this.textVerticalAlign){case i.TextVerticalAlign.top:c=s+l;break;case i.TextVerticalAlign.middle:c=(this.height*a-o)/2+s;break;case i.TextVerticalAlign.bottom:c=this.height*a-h-l}return c},e.getOffsetXRich=function(t,e,n){switch(this.textAlign){case i.TextAlignment.left:return t.outlineWidth*t.fontScale;case i.TextAlignment.middle:return(e-n)/2;case i.TextAlignment.right:return e-n;default:return 0}},e.setSize=function(t,e){this.width=t,this.height=e},t}();function M(t,e){if(void 0===e&&(e=1),3!==(t=t.replace(/^#/,"")).length&&4!==t.length||(t=t.split("").map((function(t){return t+t})).join("")),8===t.length){var i=parseInt(t.slice(6,8),16)/255;t=t.slice(0,6),e=i}var n=parseInt(t,16);return[n>>16&255,n>>8&255,255&n,e]}function k(t,e){if(void 0===e&&(e=1),"string"!=typeof t||!t)throw new Error("Invalid color string");return t.startsWith("#")?M(t,e):M(function(t){if("string"!=typeof t||!t)throw new Error("Invalid color name provided");if(void 0===u)throw new Error("This method requires a browser environment");var e=u.createElement("canvas"),i=e.getContext("2d");if(i)try{return i.fillStyle=t,i.fillStyle}finally{null==e.remove||e.remove.call(e)}throw new Error("Failed to get 2D context for color conversion!")}(t))}var R=function(){function t(){}var e=t.prototype;return e.computeLines=function(t,e,i,n,r,a,o,l){var s=this,h=[],c=[],f=(n.lineHeight||0)*a,u=this.createNewLine(),g=0,x=0,p=function(){if(0!==u.chars.length){u.lineHeight=0===h.length?(u.lineAscent||0)+(u.lineDescent||0):f;var t=0===h.length?0:c[c.length-1]+f;c.push(t),x+=u.lineHeight,h.push(u),g=Math.max(g,u.width),u=s.createNewLine()}};t.forEach((function(t){var n=t.text,r=t.isNewLine,s=t.fontSize;r&&p();var h=t.fontStyle||i.fontStyle||"normal";e.font=h+" "+(t.fontWeight||i.textWeight)+" 10px "+(t.fontFamily||i.fontFamily),u.offsetX.push(u.width);for(var c=0,f=[],g=0,x=0,v=0;v<n.length;v++){var d=n[v],m=e.measureText(d),y=m.width,S=(y<=0?0:y)*s*l*a,T=s*a*l,w=m.actualBoundingBoxAscent*T,b=m.actualBoundingBoxDescent*T;g=Math.max(g,w),x=Math.max(x,b),v>0&&(c+=o),f.push({char:d,x:c}),c+=S}u.chars.push(f),u.width+=c,u.richOptions.push(t),u.lineAscent=Math.max(u.lineAscent||0,g),u.lineDescent=Math.max(u.lineDescent||0,x)})),p();var v=1/0,d=-1/0;if(0===h.length)return{lines:h,maxLineWidth:g,totalHeight:x,bboxTop:0,bboxBottom:0,bboxHeight:0};for(var m=0;m<h.length;m++)v=Math.min(v,c[m]-(h[m].lineAscent||0)),d=Math.max(d,c[m]+(h[m].lineDescent||0));return{lines:h,maxLineWidth:g,totalHeight:x,bboxTop:v,bboxBottom:d,bboxHeight:d-v}},e.createNewLine=function(){return{richOptions:[],offsetX:[],width:0,lineHeight:0,offsetY:0,chars:[],lineAscent:0,lineDescent:0}},t}(),F=function(){function t(){}var e=t.prototype;return e.computeLines=function(t,e,i,n,r,a,o,l){var s=this,h=[],c=[],f=(n.lineHeight||0)*a,u=this.createNewLine(),g=0,x=0,p=null,v=0,d=[],m=null,y=function(){if(S(),0!==u.chars.length){u.lineHeight=0===h.length?(u.lineAscent||0)+(u.lineDescent||0):f;var t=0===h.length?0:c[c.length-1]+f;c.push(t),x+=u.lineHeight,h.push(u),g=Math.max(g,u.width),u=s.createNewLine(),p=null,v=0,d=[],m=null}},S=function(){0!==d.length&&(null===p&&(p=u.width),u.offsetX.push(p),u.chars.push(d),m&&u.richOptions.push(m),p=null,v=0,d=[],m=null)};t.forEach((function(t){var r=t.text,s=t.isNewLine,h=t.fontSize,c=t.fontStyle||i.fontStyle||"normal";e.font=c+" "+(t.fontWeight||i.textWeight)+" 10px "+(t.fontFamily||i.fontFamily),s&&(S(),y());for(var f=0;f<r.length;f++){var g=r[f],x=e.measureText(g),T=x.width,w=(T<=0?0:T)*h*l*a,b=h*a*l,A=x.actualBoundingBoxAscent*b,O=x.actualBoundingBoxDescent*b,C=d.length>0?o:0;u.width+C+w>(n.maxTextWidth||1/0)&&(S(),y()),null===p&&(p=u.width,m=t),d.length>0&&(v+=o,u.width+=o),d.push({char:g,x:v}),u.lineAscent=Math.max(u.lineAscent||0,A),u.lineDescent=Math.max(u.lineDescent||0,O),v+=w,u.width+=w}S()})),y();for(var T=1/0,w=-1/0,b=0;b<h.length;b++)T=Math.min(T,c[b]-(h[b].lineAscent||0)),w=Math.max(w,c[b]+(h[b].lineDescent||0));return{lines:h,maxLineWidth:g,totalHeight:x,bboxTop:T,bboxBottom:w,bboxHeight:w-T}},e.createNewLine=function(){return{richOptions:[],offsetX:[],width:0,lineHeight:0,offsetY:0,chars:[],lineAscent:0,lineDescent:0}},t}(),D=function(){function t(){}return t.prototype.apply=function(t,e,i,n){var r,a,o=function(t,e){return Math.abs(e)>1e-5?t/e:1},l=i.maxTextWidth*n.fontScale,s=i.maxTextHeight*n.fontScale,h=Math.max(1,null!=(r=e.contentWidth)?r:e.canvasWidth),c=Math.max(1,null!=(a=e.bboxHeight)?a:e.canvasHeight),f=Math.min(1,o(l,h),o(s,c));if(f>.9999)return{globalScale:1};for(var u,g=w(t);!(u=g()).done;){var x=u.value;if(x.width*=f,x.lineHeight*=f,x.offsetX)for(var p=0;p<x.offsetX.length;p++)x.offsetX[p]*=f;for(var v,d=w(x.chars||[]);!(v=d()).done;)for(var m,y=w(v.value);!(m=y()).done;){m.value.x*=f}for(var S,T=w(x.richOptions||[]);!(S=T()).done;){S.value.fontSize*=f}null!=x.lineAscent&&(x.lineAscent*=f),null!=x.lineDescent&&(x.lineDescent*=f)}return{globalScale:f}},t}(),B=function(){function t(){}return t.prototype.apply=function(t,e,i,n){return{globalScale:1}},t}(),_=function(){function t(){}return t.prototype.apply=function(t,e,i,n){return{globalScale:1}},t}(),X=function(){function t(){}return t.prototype.getHorizontalOffsets=function(t,e,n,r,a){var o,l,s=null!=(o=e.containerWidth)?o:r.maxTextWidth*a.fontScale,h=null!=(l=e.baselineCompensationX)?l:0,c=t.map((function(t){return r.getOffsetXRich(a,s,t.width)}));return{lineOffsets:r.overflow===i.TextOverflow.visible?c.map((function(t){return t+h})):c}},t}(),Y=function(){function t(){}return t.prototype.getVerticalOffsets=function(t,e,n,r,a,o){var l,s=null!=(l=e.baselineCompensationY)?l:0,h=0;if(0===t.length)return{baselineY:0,lineYOffsets:[]};switch(r.overflow){case i.TextOverflow.visible:var c,f,u,g,x=r.maxTextHeight*a.fontScale,p=null!=(c=e.bboxTop)?c:0,v=null!=(u=e.bboxBottom)?u:p+(null!=(f=e.bboxHeight)?f:0),d=null!=(g=e.bboxHeight)?g:v-p,m=0;switch(r.textVerticalAlign){case i.TextVerticalAlign.top:m=-p;break;case i.TextVerticalAlign.middle:m=(x-d)/2-p;break;case i.TextVerticalAlign.bottom:m=x-d-p}h=m+s;break;case i.TextOverflow.clip:for(var y=r.maxTextHeight*a.fontScale,S=[0],T=1;T<t.length;T++)S[T]=S[T-1]+t[T].lineHeight;for(var w=1/0,b=-1/0,A=0;A<t.length;A++){var O,C,z=null!=(O=t[A].lineAscent)?O:0,L=null!=(C=t[A].lineDescent)?C:0;w=Math.min(w,S[A]-z),b=Math.max(b,S[A]+L)}var H=b-w,E=0;switch(r.textVerticalAlign){case i.TextVerticalAlign.top:E=-w;break;case i.TextVerticalAlign.middle:E=(y-H)/2-w;break;case i.TextVerticalAlign.bottom:E=y-H-w}h=E+s;break;case i.TextOverflow.display:for(var W=r.maxTextHeight*a.fontScale,V=[0],M=1;M<t.length;M++)V[M]=V[M-1]+t[M].lineHeight;for(var k=1/0,R=-1/0,F=0;F<t.length;F++){var D,B,_=null!=(D=t[F].lineAscent)?D:0,X=null!=(B=t[F].lineDescent)?B:0;k=Math.min(k,V[F]-_),R=Math.max(R,V[F]+X)}var Y=R-k,P=0;switch(r.textVerticalAlign){case i.TextVerticalAlign.top:P=-k;break;case i.TextVerticalAlign.middle:P=(W-Y)/2-k;break;case i.TextVerticalAlign.bottom:P=W-Y-k}for(var N=[],j=P,I=0;I<t.length;I++)N.push(j),I<t.length-1&&(j+=t[I+1].lineHeight);return{baselineY:P,lineYOffsets:N}}var U=[],$=h;return t.forEach((function(e,i){U.push($),i<t.length-1&&($+=t[i+1].lineHeight)})),{baselineY:h,lineYOffsets:U}},t}(),P=function(){function t(){}return t.createWrapStrategy=function(t){return t?new F:new R},t.createOverflowStrategy=function(t){switch(t){case i.TextOverflow.clip:return new B;case i.TextOverflow.display:return new D;case i.TextOverflow.visible:default:return new _}},t.createHorizontalAlignStrategy=function(){return new X},t.createVerticalAlignStrategy=function(){return new Y},t}(),N=0,j=function(t){function e(e){var n;return(n=t.call(this,e)||this).isDirty=!0,n.text="",n.processedTextOptions=[],n.singleLineHeight=1.571,n.size=null,n.initialized=!1,n.canvasSize=null,n.SCALE_FACTOR=.1,n.ALPHA_FIX_VALUE=1/255,n.name="MRichText"+N++,n.initTextBase(e),n.richWrapStrategy=P.createWrapStrategy(),n.richOverflowStrategy=P.createOverflowStrategy(i.TextOverflow.display),n.richHorizontalAlignStrategy=P.createHorizontalAlignStrategy(),n.richVerticalAlignStrategy=P.createVerticalAlignStrategy(),n}x(e,t);var n=e.prototype;return n.onUpdate=function(e){t.prototype.onUpdate.call(this,e),this.updateTexture()},n.onDestroy=function(){t.prototype.onDestroy.call(this),this.disposeTextTexture()},n.fromData=function(e){t.prototype.fromData.call(this,e);var n=e.interaction,r=e.options;this.interaction=n,this.textStyle=new o(r),this.textLayout=new V(r),this.text=r.text?r.text.toString():" ",this.textLayout.useLegacyRichText&&(this.textLayout.textVerticalAlign=i.TextVerticalAlign.middle),this.updateStrategies(),this.renderText(r),this.material.setColor("_Color",new l.Color(1,1,1,1))},n.updateStrategies=function(){var t=this.textLayout;t&&(this.richWrapStrategy=P.createWrapStrategy(t.wrapEnabled),this.richOverflowStrategy=P.createOverflowStrategy(t.overflow))},n.generateTextProgram=function(t){var e=this;this.processedTextOptions=[];var n=L((function(t,n){/^\n+$/.test(t)&&(t=t.replace(/\n/g,"\n ")),t.split("\n").forEach((function(t,r){var a={text:t,fontSize:e.textStyle.fontSize,isNewLine:!1};r>0&&(a.isNewLine=!0),"b"in n&&(a.fontWeight=i.TextWeight.bold),"i"in n&&(a.fontStyle=i.FontStyle.italic),"size"in n&&n.size&&(a.fontSize=parseInt(n.size,10)),"color"in n&&n.color&&(a.fontColor=k(n.color)),e.processedTextOptions.push(a)}))}));n(t)},n.updateWithOptions=function(t){this.textStyle=new o(t),this.textLayout=new V(t),this.text=t.text?t.text.toString():" ",this.textLayout.useLegacyRichText&&(this.textLayout.textVerticalAlign=i.TextVerticalAlign.middle),this.updateStrategies(),this.isDirty=!0},n.renderText=function(t){var e=t.size;e&&(this.canvasSize=new l.Vector2(e[0],e[1])),this.updateTexture()},n.updateTexture=function(t){if(void 0===t&&(t=!0),this.isDirty&&this.context&&this.canvas&&this.textStyle&&this.textLayout){var e=!0===this.textLayout.useLegacyRichText;this.singleLineHeight=e?1.571:1,e?this.updateTextureLegacy(t):this.updateTextureWithStrategies(t)}},n.updateTextureLegacy=function(t){var e=this;if(this.isDirty&&this.context&&this.canvas&&this.textStyle){this.generateTextProgram(this.text);var n=0,r=0,a=this.textLayout,o=this.textStyle,h=a.overflow,c=a.letterSpace,f=void 0===c?0:c,u=this.context,g=[],x=o.fontSize*o.fontScale,p={richOptions:[],offsetX:[],width:0,lineHeight:x*this.singleLineHeight,offsetY:x*(this.singleLineHeight-1)/2};if(this.processedTextOptions.forEach((function(t){var i=t.text,a=t.isNewLine,l=t.fontSize;a&&(g.push(p),n=Math.max(n,p.width),p={richOptions:[],offsetX:[],width:0,lineHeight:x*e.singleLineHeight,offsetY:x*(e.singleLineHeight-1)/2},r+=p.lineHeight),u.font=(t.fontWeight||o.textWeight)+" 10px "+(t.fontFamily||o.fontFamily);var s=u.measureText(i),h=s.width;if(void 0!==s.actualBoundingBoxLeft&&void 0!==s.actualBoundingBoxRight){var c=s.actualBoundingBoxLeft+s.actualBoundingBoxRight;c>0&&(h=Math.max(h,c))}var v=l*e.singleLineHeight*o.fontScale;v>p.lineHeight&&(r+=v-p.lineHeight,p.lineHeight=v,p.offsetY=l*o.fontScale*(e.singleLineHeight-1)/2),p.offsetX.push(p.width),p.width+=(h<=0?0:h)*l*e.SCALE_FACTOR*o.fontScale+i.length*f,p.richOptions.push(t)})),g.push(p),n=Math.max(n,p.width),r+=p.lineHeight,0!==n&&0!==r){void 0!==this.size&&null!==this.size||(this.size=this.item.transform.size.clone());var v=this.size,d=v.x,m=void 0===d?1:d,y=v.y,S=void 0===y?1:y;if(!this.initialized){this.canvasSize=this.canvasSize?this.canvasSize:new l.Vector2(n,r);var T=this.canvasSize,w=T.x,b=T.y;this.item.transform.size.set(m*w*this.SCALE_FACTOR*this.SCALE_FACTOR,S*b*this.SCALE_FACTOR*this.SCALE_FACTOR),this.size=this.item.transform.size.clone(),this.initialized=!0}s(this.canvasSize);var A=this.canvasSize,O=A.x,C=A.y;a.width=O/o.fontScale,a.height=C/o.fontScale,this.renderToTexture(O,C,t,(function(t){if(0!==g.length){var n=a.getOffsetY(o,g.length,x*e.singleLineHeight,o.fontSize);g.forEach((function(e,r){var l=e.richOptions,s=e.offsetX,c=e.width,f=c,u=s;if(h===i.TextOverflow.display&&c>O){var g=O/c;f*=g,u=s.map((function(t){return t*g}))}var x=a.getOffsetX(o,f);r>0&&(n+=e.lineHeight-e.offsetY),l.forEach((function(e,r){var a=o.fontScale,l=o.textColor,s=o.fontFamily,f=o.textWeight,g=o.fontStyle,p=e.text,v=e.fontSize,d=e.fontColor,m=void 0===d?l:d,y=e.fontFamily,S=void 0===y?s:y,T=e.fontWeight,w=void 0===T?f:T,b=e.fontStyle,A=void 0===b?g:b,C=v;h===i.TextOverflow.display&&c>O&&(C/=c/O);var z=u[r]+x;t.font=A+" "+w+" "+C*a+"px "+S;var L=m[0],H=m[1],E=m[2],W=m[3];t.fillStyle="rgba("+L+", "+H+", "+E+", "+W+")",t.fillText(p,z,n)}))}))}}),{disposeOld:!1}),this.isDirty=!1}else this.isDirty=!1}},n.updateTextureWithStrategies=function(t){var e=this;if(this.isDirty&&this.context&&this.canvas){this.generateTextProgram(this.text);var i=this.textLayout,n=i.letterSpace,r=void 0===n?0:n,a=this.context;if(a){var o=this.richWrapStrategy.computeLines(this.processedTextOptions,a,this.textStyle,i,this.singleLineHeight,this.textStyle.fontScale,r,this.SCALE_FACTOR);if(0!==o.lines.length&&0!==o.maxLineWidth&&0!==o.totalHeight){var l=this.resolveCanvasSize(o,i,this.textStyle,this.singleLineHeight);this.setCanvasSize(l);var h=this.richOverflowStrategy.apply(o.lines,l,i,this.textStyle),c=this.richHorizontalAlignStrategy.getHorizontalOffsets(o.lines,l,h,i,this.textStyle),f=this.richVerticalAlignStrategy.getVerticalOffsets(o.lines,l,h,i,this.textStyle,this.singleLineHeight);s(this.canvasSize);var u=this.canvasSize,g=u.x,x=u.y,p=Math.max(1,Math.ceil(g)),v=Math.max(1,Math.ceil(x));i.width=p/this.textStyle.fontScale,i.height=v/this.textStyle.fontScale,this.renderToTexture(p,v,t,(function(t){e.drawTextWithStrategies(t,o.lines,c,f,h,e.textStyle)}),{disposeOld:!1}),this.isDirty=!1}else this.isDirty=!1}}},n.setCanvasSize=function(t){var e=this;void 0!==this.size&&null!==this.size||(this.size=this.item.transform.size.clone());var n=this.size,r=n.x,a=void 0===r?1:r,o=n.y,s=void 0===o?1:o,h=this.textLayout,c=this.textStyle.fontScale||1,f=Math.max(1,h.maxTextWidth||0),u=Math.max(1,h.maxTextHeight||0);switch(h.overflow){case i.TextOverflow.visible:var g,x,p,v,d=f*c,m=u*c,y=null!=(g=t.bboxTop)?g:0,S=null!=(p=t.bboxBottom)?p:y+(null!=(x=t.bboxHeight)?x:0),T=null!=(v=t.bboxHeight)?v:S-y,w=0;switch(h.textVerticalAlign){case i.TextVerticalAlign.top:w=-y;break;case i.TextVerticalAlign.middle:w=(m-T)/2-y;break;case i.TextVerticalAlign.bottom:w=m-T-y}var b=w+y,A=w+S,O=Math.max(0,-b),C=Math.max(0,A-m),z=O,L=C;switch(h.textVerticalAlign){case i.TextVerticalAlign.top:z=C,L=C;break;case i.TextVerticalAlign.bottom:z=O,L=O;break;case i.TextVerticalAlign.middle:z=O,L=C}for(var H=z,E=t.lines||[],W=E.map((function(t){return h.getOffsetXRich(e.textStyle,d,t.width)})),V=1/0,M=-1/0,k=0;k<E.length;k++){var R,F,D=null!=(R=W[k])?R:0,B=null!=(F=E[k].width)?F:0;V=Math.min(V,D),M=Math.max(M,D+B)}isFinite(V)||(V=0),isFinite(M)||(M=0);var _,X=Math.max(0,-V),Y=Math.max(0,M-d),P=Math.ceil(d+X+Y),N=Math.ceil(m+z+L);t.baselineCompensationX=X,t.baselineCompensationY=H,t.containerWidth=d,t.canvasWidth=P,t.canvasHeight=N,this.canvasSize=new l.Vector2(P,N);var j=null!=(_=this.size)?_:this.item.transform.size,I=j.x,U=void 0===I?1:I,$=j.y,q=void 0===$?1:$;this.item.transform.size.set(U*P*this.SCALE_FACTOR*this.SCALE_FACTOR,q*N*this.SCALE_FACTOR*this.SCALE_FACTOR),this.initialized=!0;break;case i.TextOverflow.clip:var G,J=f*c,K=u*c;t.canvasWidth=J,t.canvasHeight=K,t.baselineCompensationX=0,t.baselineCompensationY=0,this.canvasSize=new l.Vector2(J,K),h.width=f,h.height=u;var Q=null!=(G=this.size)?G:this.item.transform.size,Z=Q.x,tt=void 0===Z?1:Z,et=Q.y,it=void 0===et?1:et;this.item.transform.size.set(tt*J*this.SCALE_FACTOR*this.SCALE_FACTOR,it*K*this.SCALE_FACTOR*this.SCALE_FACTOR),this.initialized=!0;break;case i.TextOverflow.display:if(!this.initialized){var nt=f*c,rt=u*c;this.canvasSize=new l.Vector2(nt,rt),this.item.transform.size.set(a*nt*this.SCALE_FACTOR*this.SCALE_FACTOR,s*rt*this.SCALE_FACTOR*this.SCALE_FACTOR),this.initialized=!0}}},n.resolveCanvasSize=function(t,e,i,n){var r=Math.max(1,t.maxLineWidth||0),a=Math.max(1,t.totalHeight||0);return e.width=r/i.fontScale,e.height=a/i.fontScale,{canvasWidth:r,canvasHeight:a,contentWidth:t.maxLineWidth,bboxTop:t.bboxTop,bboxBottom:t.bboxBottom,bboxHeight:t.bboxHeight,lines:t.lines}},n.drawTextWithStrategies=function(t,e,i,n,r,a){var o=n.baselineY,l=i.lineOffsets;e.forEach((function(i,n){var r=i.richOptions,s=i.chars,h=l[n],c=o;r.forEach((function(e,n){var r=a.fontScale,o=a.textColor,l=a.fontFamily,f=a.textWeight,u=a.fontStyle,g=e.fontSize,x=e.fontColor,p=void 0===x?o:x,v=e.fontFamily,d=void 0===v?l:v,m=e.fontWeight,y=void 0===m?f:m,S=e.fontStyle,T=void 0===S?u:S,w=g;t.font=T+" "+y+" "+w*r+"px "+d;var b=p[0],A=p[1],O=p[2],C=p[3];t.fillStyle="rgba("+b+", "+A+", "+O+", "+C+")";var z=i.offsetX&&i.offsetX[n]?i.offsetX[n]:0;s[n].forEach((function(e){t.fillText(e.char,h+z+e.x,c)}))})),n<e.length-1&&(o+=e[n+1].lineHeight)}))},n.unsupported=function(t){throw new Error("RichTextComponent does not support "+t+" at runtime.")},n.setShadowOffsetY=function(t){this.unsupported("setShadowOffsetY")},n.setShadowBlur=function(t){this.unsupported("setShadowBlur")},n.setShadowOffsetX=function(t){this.unsupported("setShadowOffsetX")},n.setShadowColor=function(t){this.unsupported("setShadowColor")},n.setOutlineWidth=function(t){this.unsupported("setOutlineWidth")},n.setAutoWidth=function(t){this.unsupported("setAutoWidth")},n.setFontSize=function(t){this.unsupported("setFontSize")},n.setTextBaseline=function(t){console.warn("setTextBaseline 已废弃,请改用 setTextVerticalAlign。本次调用将转调用 setTextVerticalAlign。"),this.setTextVerticalAlign(t)},e}(h);r(j=function(t,e,i,n){var r,a=arguments.length,o=a<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,i):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,e,i,n);else for(var l=t.length-1;l>=0;l--)(r=t[l])&&(o=(a<3?r(o):a>3?r(e,i,o):r(e,i))||o);return a>3&&o&&Object.defineProperty(e,i,o),o}([n(i.DataType.RichTextComponent)],j),[a]);var I="2.8.6";c("rich-text",S),f.info("Plugin rich text version: 2.8.6."),I!==t.version&&console.error("注意:请统一 RichText 插件与 Player 版本,不统一的版本混用会有不可预知的后果!","\nAttention: Please ensure the RichText plugin is synchronized with the Player version. Mixing and matching incompatible versions may result in unpredictable consequences!");export{j as RichTextComponent,S as RichTextLoader,E as escape,L as generateProgram,H as isRichText,C as lexer,z as richTextParser,W as unescape,I as version};
2
2
  //# sourceMappingURL=alipay.mjs.map
package/dist/douyin.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@galacean/effects/douyin"),e=require("@galacean/appx-adapter/douyin");function i(t){if(t&&t.__esModule)return t;var e=Object.create(null);return t&&Object.keys(t).forEach((function(i){if("default"!==i){var n=Object.getOwnPropertyDescriptor(t,i);Object.defineProperty(e,i,n.get?n:{enumerable:!0,get:function(){return t[i]}})}})),e.default=t,Object.freeze(e)}var n=i(t);function r(t,e){return r=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},r(t,e)}function o(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&&r(t,e)}function a(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(a=function(){return!!t})()}function s(t,e,i){return s=a()?Reflect.construct:function(t,e,i){var n=[null];n.push.apply(n,e);var o=new(Function.bind.apply(t,n));return i&&r(o,i.prototype),o},s.apply(null,arguments)}function l(t){return l=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},l(t)}function c(t){var e="function"==typeof Map?new Map:void 0;return c=function(t){if(null===t||(i=t,-1===Function.toString.call(i).indexOf("[native code]")))return t;var i;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,n)}function n(){return s(t,arguments,l(this).constructor)}return n.prototype=Object.create(t.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),r(n,t)},c(t)}var h,u=function(t){function e(){var e;return(e=t.apply(this,arguments)||this).name="rich-text",e}return o(e,t),e}(c(t.Plugin));function f(t,e){(null==e||e>t.length)&&(e=t.length);for(var i=0,n=new Array(e);i<e;i++)n[i]=t[i];return n}function p(t,e){var i="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(i)return(i=i.call(t)).next.bind(i);if(Array.isArray(t)||(i=function(t,e){if(t){if("string"==typeof t)return f(t,e);var i=Object.prototype.toString.call(t).slice(8,-1);return"Object"===i&&t.constructor&&(i=t.constructor.name),"Map"===i||"Set"===i?Array.from(i):"Arguments"===i||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i)?f(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){i&&(t=i);var n=0;return function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}!function(t){t.ContextStart="ContextStart",t.Text="Text",t.ContextEnd="ContextEnd",t.EscapedChar="EscapedChar"}(h||(h={}));var x=/^<([a-z]+)(=([^>]+))?>$/,g=/^<\/([a-z]+)>$/,v=[["EscapedChar",/^\\([=<>\\/])/],["ContextStart",/^<[a-z]+(=[^>]+)?>/],["ContextEnd",/^<\/[a-z]+>/],["Text",/^[^</>=\\]+/]],d=function(t,e,i){if(void 0===e&&(e=[]),void 0===i&&(i=0),!t)return e;var n=/^\\([=<>\\/])/.exec(t);if(n){var r=n[1];return d(t.slice(2),e.concat({tokenType:"Text",value:r}),i+2)}for(var o,a=p(v);!(o=a()).done;){var s=o.value,l=s[0],c=s[1];if("EscapedChar"!==l){var h=c.exec(t);if(h){var u=h[0],f=u.length;return d(t.slice(f),e.concat({tokenType:l,value:u}),i+f)}}}if(t.length>0)return d(t.slice(1),e.concat({tokenType:"Text",value:t[0]}),i+1);throw new Error('Unexpected token: "'+t[0]+'" at position '+i+' while reading "'+t+'"')},m=function(t){var e=function(){for(var t,e="",i=!1;r.length>0&&"Text"===(null==(t=r[0])?void 0:t.tokenType);){var n=a();n&&(e+=n.value,i=!0)}return i?e:void 0},i=function(){var t=s();if("ContextStart"===(null==t?void 0:t.tokenType)){a();var e,i=t.value.match(x);if(i)return{attributeName:i[1],attributeParam:null!=(e=i[3])?e:""};throw new Error("Expected a start tag marker at position "+o)}return{}},n=function(){var t=s();if("ContextEnd"===(null==t?void 0:t.tokenType)){a();var e=t.value.match(g);if(e)return{attributeName:e[1]};throw new Error("Expect an end tag marker at position "+o)}return{}},r=d(t),o=0,a=function(){var t,e=r.shift();return o+=null!=(t=null==e?void 0:e.value.length)?t:0,e},s=function(){return r[0]},l=[];return function t(r,a){for(void 0===r&&(r=[]),void 0===a&&(a="");;){var s=e();if(s)l.push({attributes:r,text:s});else{var c=i(),h=c.attributeName,u=c.attributeParam;if(!h){if(a){var f=n().attributeName;if(!f)throw new Error('Expect an end tag marker "'+a+'" at position '+o+" but found no tag!");if(f!==a)throw new Error('Expect an end tag marker "'+a+'" at position '+o+' but found tag "'+f+'"');return}break}t(r.concat({attributeName:h,attributeParam:null!=u?u:""}),h)}}}(),l};function y(t){return function(e){for(var i,n=p(m(e));!(i=n()).done;){var r=i.value,o=r.text,a=r.attributes.reduce((function(t,e){var i=e.attributeName,n=e.attributeParam;return i&&(t[i]=n),t}),{});t(o,a)}}}"function"==typeof SuppressedError&&SuppressedError;var S=function(){function e(e){this.width=0,this.height=0;var i=e.size,n=e.textOverflow,r=void 0===n?t.spec.TextOverflow.clip:n,o=e.textVerticalAlign,a=void 0===o?t.spec.TextVerticalAlign.middle:o,s=e.textAlign,l=void 0===s?t.spec.TextAlignment.left:s,c=e.letterSpace,h=void 0===c?0:c,u=e.lineHeight,f=void 0===u?.571:u,p=e.wrapEnabled,x=void 0!==p&&p,g=e.maxTextWidth,v=void 0===g?350:g,d=e.maxTextHeight,m=void 0===d?1e3:d,y=e.sizeMode,S=void 0===y?t.spec.TextSizeMode.autoWidth:y,T=e.useLegacyRichText,b=void 0!==T&&T;this.letterSpace=h,this.lineHeight=f,this.useLegacyRichText=b,this.overflow=r,this.textVerticalAlign=a,this.textAlign=l,this.width=i?i[0]:100,this.height=i?i[1]:100,this.wrapEnabled=x;this.maxTextWidth=50*v,this.maxTextHeight=50*m,this.sizeMode=S}var i=e.prototype;return i.getOffsetY=function(e,i,n,r,o){var a=e.outlineWidth,s=e.fontScale,l=(n-r)/3,c=r+a*s,h=void 0!==o?o:n*(i-1),u=0;switch(this.textVerticalAlign){case t.spec.TextVerticalAlign.top:u=c+l;break;case t.spec.TextVerticalAlign.middle:u=(this.height*s-h+c)/2;break;case t.spec.TextVerticalAlign.bottom:u=this.height*s-h-l}return u},i.getOffsetX=function(e,i){var n=0;switch(this.textAlign){case t.spec.TextAlignment.left:n=e.outlineWidth*e.fontScale;break;case t.spec.TextAlignment.middle:n=(this.width*e.fontScale-i)/2;break;case t.spec.TextAlignment.right:n=this.width*e.fontScale-i}return n},i.getOffsetYRich=function(e,i,n){if(0===i.length)return 0;var r=e.outlineWidth,o=e.fontScale,a=i.reduce((function(t,e){return t+e}),0),s=(i[0]-n)/3,l=n+r*o,c=a-i[0],h=0;switch(this.textVerticalAlign){case t.spec.TextVerticalAlign.top:h=l+s;break;case t.spec.TextVerticalAlign.middle:h=(this.height*o-a)/2+l;break;case t.spec.TextVerticalAlign.bottom:h=this.height*o-c-s}return h},i.getOffsetXRich=function(e,i,n){switch(this.textAlign){case t.spec.TextAlignment.left:return e.outlineWidth*e.fontScale;case t.spec.TextAlignment.middle:return(i-n)/2;case t.spec.TextAlignment.right:return i-n;default:return 0}},i.setSize=function(t,e){this.width=t,this.height=e},e}();function T(t,e){if(void 0===e&&(e=1),3!==(t=t.replace(/^#/,"")).length&&4!==t.length||(t=t.split("").map((function(t){return t+t})).join("")),8===t.length){var i=parseInt(t.slice(6,8),16)/255;t=t.slice(0,6),e=i}var n=parseInt(t,16);return[n>>16&255,n>>8&255,255&n,e]}function b(t,i){if(void 0===i&&(i=1),"string"!=typeof t||!t)throw new Error("Invalid color string");return t.startsWith("#")?T(t,i):T(function(t){if("string"!=typeof t||!t)throw new Error("Invalid color name provided");if(void 0===e.document)throw new Error("This method requires a browser environment");var i=e.document.createElement("canvas"),n=i.getContext("2d");if(n)try{return n.fillStyle=t,n.fillStyle}finally{null==i.remove||i.remove.call(i)}throw new Error("Failed to get 2D context for color conversion!")}(t))}var w=function(){function t(){}var e=t.prototype;return e.computeLines=function(t,e,i,n,r,o,a,s){var l=this,c=[],h=[],u=(n.lineHeight||0)*o,f=this.createNewLine(),p=0,x=0,g=function(){if(0!==f.chars.length){f.lineHeight=0===c.length?(f.lineAscent||0)+(f.lineDescent||0):u;var t=0===c.length?0:h[h.length-1]+u;h.push(t),x+=f.lineHeight,c.push(f),p=Math.max(p,f.width),f=l.createNewLine()}};t.forEach((function(t){var n=t.text,r=t.isNewLine,l=t.fontSize;r&&g();var c=t.fontStyle||i.fontStyle||"normal";e.font=c+" "+(t.fontWeight||i.textWeight)+" 10px "+(t.fontFamily||i.fontFamily),f.offsetX.push(f.width);for(var h=0,u=[],p=0,x=0,v=0;v<n.length;v++){var d=n[v],m=e.measureText(d),y=m.width,S=(y<=0?0:y)*l*s*o,T=l*o*s,b=m.actualBoundingBoxAscent*T,w=m.actualBoundingBoxDescent*T;p=Math.max(p,b),x=Math.max(x,w),v>0&&(h+=a),u.push({char:d,x:h}),h+=S}f.chars.push(u),f.width+=h,f.richOptions.push(t),f.lineAscent=Math.max(f.lineAscent||0,p),f.lineDescent=Math.max(f.lineDescent||0,x)})),g();var v=1/0,d=-1/0;if(0===c.length)return{lines:c,maxLineWidth:p,totalHeight:x,bboxTop:0,bboxBottom:0,bboxHeight:0};for(var m=0;m<c.length;m++)v=Math.min(v,h[m]-(c[m].lineAscent||0)),d=Math.max(d,h[m]+(c[m].lineDescent||0));return{lines:c,maxLineWidth:p,totalHeight:x,bboxTop:v,bboxBottom:d,bboxHeight:d-v}},e.createNewLine=function(){return{richOptions:[],offsetX:[],width:0,lineHeight:0,offsetY:0,chars:[],lineAscent:0,lineDescent:0}},t}(),A=function(){function t(){}var e=t.prototype;return e.computeLines=function(t,e,i,n,r,o,a,s){var l=this,c=[],h=[],u=(n.lineHeight||0)*o,f=this.createNewLine(),p=0,x=0,g=null,v=0,d=[],m=null,y=function(){if(S(),0!==f.chars.length){f.lineHeight=0===c.length?(f.lineAscent||0)+(f.lineDescent||0):u;var t=0===c.length?0:h[h.length-1]+u;h.push(t),x+=f.lineHeight,c.push(f),p=Math.max(p,f.width),f=l.createNewLine(),g=null,v=0,d=[],m=null}},S=function(){0!==d.length&&(null===g&&(g=f.width),f.offsetX.push(g),f.chars.push(d),m&&f.richOptions.push(m),g=null,v=0,d=[],m=null)};t.forEach((function(t){var r=t.text,l=t.isNewLine,c=t.fontSize,h=t.fontStyle||i.fontStyle||"normal";e.font=h+" "+(t.fontWeight||i.textWeight)+" 10px "+(t.fontFamily||i.fontFamily),l&&(S(),y());for(var u=0;u<r.length;u++){var p=r[u],x=e.measureText(p),T=x.width,b=(T<=0?0:T)*c*s*o,w=c*o*s,A=x.actualBoundingBoxAscent*w,O=x.actualBoundingBoxDescent*w,C=d.length>0?a:0;f.width+C+b>(n.maxTextWidth||1/0)&&(S(),y()),null===g&&(g=f.width,m=t),d.length>0&&(v+=a,f.width+=a),d.push({char:p,x:v}),f.lineAscent=Math.max(f.lineAscent||0,A),f.lineDescent=Math.max(f.lineDescent||0,O),v+=b,f.width+=b}S()})),y();for(var T=1/0,b=-1/0,w=0;w<c.length;w++)T=Math.min(T,h[w]-(c[w].lineAscent||0)),b=Math.max(b,h[w]+(c[w].lineDescent||0));return{lines:c,maxLineWidth:p,totalHeight:x,bboxTop:T,bboxBottom:b,bboxHeight:b-T}},e.createNewLine=function(){return{richOptions:[],offsetX:[],width:0,lineHeight:0,offsetY:0,chars:[],lineAscent:0,lineDescent:0}},t}(),O=function(){function t(){}return t.prototype.apply=function(t,e,i,n){var r,o,a=function(t,e){return Math.abs(e)>1e-5?t/e:1},s=i.maxTextWidth*n.fontScale,l=i.maxTextHeight*n.fontScale,c=Math.max(1,null!=(r=e.contentWidth)?r:e.canvasWidth),h=Math.max(1,null!=(o=e.bboxHeight)?o:e.canvasHeight),u=Math.min(1,a(s,c),a(l,h));if(u>.9999)return{globalScale:1};for(var f,x=p(t);!(f=x()).done;){var g=f.value;if(g.width*=u,g.lineHeight*=u,g.offsetX)for(var v=0;v<g.offsetX.length;v++)g.offsetX[v]*=u;for(var d,m=p(g.chars||[]);!(d=m()).done;)for(var y,S=p(d.value);!(y=S()).done;){y.value.x*=u}for(var T,b=p(g.richOptions||[]);!(T=b()).done;){T.value.fontSize*=u}null!=g.lineAscent&&(g.lineAscent*=u),null!=g.lineDescent&&(g.lineDescent*=u)}return{globalScale:u}},t}(),C=function(){function t(){}return t.prototype.apply=function(t,e,i,n){return{globalScale:1}},t}(),z=function(){function t(){}return t.prototype.apply=function(t,e,i,n){return{globalScale:1}},t}(),L=function(){function e(){}return e.prototype.getHorizontalOffsets=function(e,i,n,r,o){var a,s,l=null!=(a=i.containerWidth)?a:r.maxTextWidth*o.fontScale,c=null!=(s=i.baselineCompensationX)?s:0,h=e.map((function(t){return r.getOffsetXRich(o,l,t.width)}));return{lineOffsets:r.overflow===t.spec.TextOverflow.visible?h.map((function(t){return t+c})):h}},e}(),E=function(){function e(){}return e.prototype.getVerticalOffsets=function(e,i,n,r,o,a){var s,l=null!=(s=i.baselineCompensationY)?s:0,c=0;if(0===e.length)return{baselineY:0,lineYOffsets:[]};switch(r.overflow){case t.spec.TextOverflow.visible:var h,u,f,p,x=r.maxTextHeight*o.fontScale,g=null!=(h=i.bboxTop)?h:0,v=null!=(f=i.bboxBottom)?f:g+(null!=(u=i.bboxHeight)?u:0),d=null!=(p=i.bboxHeight)?p:v-g,m=0;switch(r.textVerticalAlign){case t.spec.TextVerticalAlign.top:m=-g;break;case t.spec.TextVerticalAlign.middle:m=(x-d)/2-g;break;case t.spec.TextVerticalAlign.bottom:m=x-d-g}c=m+l;break;case t.spec.TextOverflow.clip:for(var y=r.maxTextHeight*o.fontScale,S=[0],T=1;T<e.length;T++)S[T]=S[T-1]+e[T].lineHeight;for(var b=1/0,w=-1/0,A=0;A<e.length;A++){var O,C,z=null!=(O=e[A].lineAscent)?O:0,L=null!=(C=e[A].lineDescent)?C:0;b=Math.min(b,S[A]-z),w=Math.max(w,S[A]+L)}var E=w-b,H=0;switch(r.textVerticalAlign){case t.spec.TextVerticalAlign.top:H=-b;break;case t.spec.TextVerticalAlign.middle:H=(y-E)/2-b;break;case t.spec.TextVerticalAlign.bottom:H=y-E-b}c=H+l;break;case t.spec.TextOverflow.display:for(var W=r.maxTextHeight*o.fontScale,M=[0],V=1;V<e.length;V++)M[V]=M[V-1]+e[V].lineHeight;for(var R=1/0,k=-1/0,F=0;F<e.length;F++){var _,D,B=null!=(_=e[F].lineAscent)?_:0,P=null!=(D=e[F].lineDescent)?D:0;R=Math.min(R,M[F]-B),k=Math.max(k,M[F]+P)}var X=k-R,Y=0;switch(r.textVerticalAlign){case t.spec.TextVerticalAlign.top:Y=-R;break;case t.spec.TextVerticalAlign.middle:Y=(W-X)/2-R;break;case t.spec.TextVerticalAlign.bottom:Y=W-X-R}for(var j=[],N=Y,I=0;I<e.length;I++)j.push(N),I<e.length-1&&(N+=e[I+1].lineHeight);return{baselineY:Y,lineYOffsets:j}}var U=[],q=c;return e.forEach((function(t,i){U.push(q),i<e.length-1&&(q+=e[i+1].lineHeight)})),{baselineY:c,lineYOffsets:U}},e}(),H=function(){function e(){}return e.createWrapStrategy=function(t){return t?new A:new w},e.createOverflowStrategy=function(e){switch(e){case t.spec.TextOverflow.clip:return new C;case t.spec.TextOverflow.display:return new O;case t.spec.TextOverflow.visible:default:return new z}},e.createHorizontalAlignStrategy=function(){return new L},e.createVerticalAlignStrategy=function(){return new E},e}(),W=0;exports.RichTextComponent=function(e){function i(i){var n;return(n=e.call(this,i)||this).isDirty=!0,n.text="",n.processedTextOptions=[],n.singleLineHeight=1.571,n.size=null,n.initialized=!1,n.canvasSize=null,n.SCALE_FACTOR=.1,n.ALPHA_FIX_VALUE=1/255,n.name="MRichText"+W++,n.initTextBase(i),n.richWrapStrategy=H.createWrapStrategy(),n.richOverflowStrategy=H.createOverflowStrategy(t.spec.TextOverflow.display),n.richHorizontalAlignStrategy=H.createHorizontalAlignStrategy(),n.richVerticalAlignStrategy=H.createVerticalAlignStrategy(),n}o(i,e);var n=i.prototype;return n.onUpdate=function(t){e.prototype.onUpdate.call(this,t),this.updateTexture()},n.onDestroy=function(){e.prototype.onDestroy.call(this),this.disposeTextTexture()},n.fromData=function(i){e.prototype.fromData.call(this,i);var n=i.interaction,r=i.options;this.interaction=n,this.textStyle=new t.TextStyle(r),this.textLayout=new S(r),this.text=r.text?r.text.toString():" ",this.textLayout.useLegacyRichText&&(this.textLayout.textVerticalAlign=t.spec.TextVerticalAlign.middle),this.updateStrategies(),this.renderText(r),this.material.setColor("_Color",new t.math.Color(1,1,1,1))},n.updateStrategies=function(){var t=this.textLayout;t&&(this.richWrapStrategy=H.createWrapStrategy(t.wrapEnabled),this.richOverflowStrategy=H.createOverflowStrategy(t.overflow))},n.generateTextProgram=function(e){var i=this;this.processedTextOptions=[];var n=y((function(e,n){/^\n+$/.test(e)&&(e=e.replace(/\n/g,"\n ")),e.split("\n").forEach((function(e,r){var o={text:e,fontSize:i.textStyle.fontSize,isNewLine:!1};r>0&&(o.isNewLine=!0),"b"in n&&(o.fontWeight=t.spec.TextWeight.bold),"i"in n&&(o.fontStyle=t.spec.FontStyle.italic),"size"in n&&n.size&&(o.fontSize=parseInt(n.size,10)),"color"in n&&n.color&&(o.fontColor=b(n.color)),i.processedTextOptions.push(o)}))}));n(e)},n.updateWithOptions=function(e){this.textStyle=new t.TextStyle(e),this.textLayout=new S(e),this.text=e.text?e.text.toString():" ",this.textLayout.useLegacyRichText&&(this.textLayout.textVerticalAlign=t.spec.TextVerticalAlign.middle),this.updateStrategies(),this.isDirty=!0},n.renderText=function(e){var i=e.size;i&&(this.canvasSize=new t.math.Vector2(i[0],i[1])),this.updateTexture()},n.updateTexture=function(t){if(void 0===t&&(t=!0),this.isDirty&&this.context&&this.canvas&&this.textStyle&&this.textLayout){var e=!0===this.textLayout.useLegacyRichText;this.singleLineHeight=e?1.571:1,e?this.updateTextureLegacy(t):this.updateTextureWithStrategies(t)}},n.updateTextureLegacy=function(e){var i=this;if(this.isDirty&&this.context&&this.canvas&&this.textStyle){this.generateTextProgram(this.text);var n=0,r=0,o=this.textLayout,a=this.textStyle,s=o.overflow,l=o.letterSpace,c=void 0===l?0:l,h=this.context,u=[],f=a.fontSize*a.fontScale,p={richOptions:[],offsetX:[],width:0,lineHeight:f*this.singleLineHeight,offsetY:f*(this.singleLineHeight-1)/2};if(this.processedTextOptions.forEach((function(t){var e=t.text,o=t.isNewLine,s=t.fontSize;o&&(u.push(p),n=Math.max(n,p.width),p={richOptions:[],offsetX:[],width:0,lineHeight:f*i.singleLineHeight,offsetY:f*(i.singleLineHeight-1)/2},r+=p.lineHeight),h.font=(t.fontWeight||a.textWeight)+" 10px "+(t.fontFamily||a.fontFamily);var l=h.measureText(e),x=l.width;if(void 0!==l.actualBoundingBoxLeft&&void 0!==l.actualBoundingBoxRight){var g=l.actualBoundingBoxLeft+l.actualBoundingBoxRight;g>0&&(x=Math.max(x,g))}var v=s*i.singleLineHeight*a.fontScale;v>p.lineHeight&&(r+=v-p.lineHeight,p.lineHeight=v,p.offsetY=s*a.fontScale*(i.singleLineHeight-1)/2),p.offsetX.push(p.width),p.width+=(x<=0?0:x)*s*i.SCALE_FACTOR*a.fontScale+e.length*c,p.richOptions.push(t)})),u.push(p),n=Math.max(n,p.width),r+=p.lineHeight,0!==n&&0!==r){void 0!==this.size&&null!==this.size||(this.size=this.item.transform.size.clone());var x=this.size,g=x.x,v=void 0===g?1:g,d=x.y,m=void 0===d?1:d;if(!this.initialized){this.canvasSize=this.canvasSize?this.canvasSize:new t.math.Vector2(n,r);var y=this.canvasSize,S=y.x,T=y.y;this.item.transform.size.set(v*S*this.SCALE_FACTOR*this.SCALE_FACTOR,m*T*this.SCALE_FACTOR*this.SCALE_FACTOR),this.size=this.item.transform.size.clone(),this.initialized=!0}t.assertExist(this.canvasSize);var b=this.canvasSize,w=b.x,A=b.y;o.width=w/a.fontScale,o.height=A/a.fontScale,this.renderToTexture(w,A,e,(function(e){if(0!==u.length){var n=o.getOffsetY(a,u.length,f*i.singleLineHeight,a.fontSize);u.forEach((function(i,r){var l=i.richOptions,c=i.offsetX,h=i.width,u=h,f=c;if(s===t.spec.TextOverflow.display&&h>w){var p=w/h;u*=p,f=c.map((function(t){return t*p}))}var x=o.getOffsetX(a,u);r>0&&(n+=i.lineHeight-i.offsetY),l.forEach((function(i,r){var o=a.fontScale,l=a.textColor,c=a.fontFamily,u=a.textWeight,p=a.fontStyle,g=i.text,v=i.fontSize,d=i.fontColor,m=void 0===d?l:d,y=i.fontFamily,S=void 0===y?c:y,T=i.fontWeight,b=void 0===T?u:T,A=i.fontStyle,O=void 0===A?p:A,C=v;s===t.spec.TextOverflow.display&&h>w&&(C/=h/w);var z=f[r]+x;e.font=O+" "+b+" "+C*o+"px "+S;var L=m[0],E=m[1],H=m[2],W=m[3];e.fillStyle="rgba("+L+", "+E+", "+H+", "+W+")",e.fillText(g,z,n)}))}))}}),{disposeOld:!1}),this.isDirty=!1}else this.isDirty=!1}},n.updateTextureWithStrategies=function(e){var i=this;if(this.isDirty&&this.context&&this.canvas){this.generateTextProgram(this.text);var n=this.textLayout,r=n.letterSpace,o=void 0===r?0:r,a=this.context;if(a){var s=this.richWrapStrategy.computeLines(this.processedTextOptions,a,this.textStyle,n,this.singleLineHeight,this.textStyle.fontScale,o,this.SCALE_FACTOR);if(0!==s.lines.length&&0!==s.maxLineWidth&&0!==s.totalHeight){var l=this.resolveCanvasSize(s,n,this.textStyle,this.singleLineHeight);this.setCanvasSize(l);var c=this.richOverflowStrategy.apply(s.lines,l,n,this.textStyle),h=this.richHorizontalAlignStrategy.getHorizontalOffsets(s.lines,l,c,n,this.textStyle),u=this.richVerticalAlignStrategy.getVerticalOffsets(s.lines,l,c,n,this.textStyle,this.singleLineHeight);t.assertExist(this.canvasSize);var f=this.canvasSize,p=f.x,x=f.y,g=Math.max(1,Math.ceil(p)),v=Math.max(1,Math.ceil(x));n.width=g/this.textStyle.fontScale,n.height=v/this.textStyle.fontScale,this.renderToTexture(g,v,e,(function(t){i.drawTextWithStrategies(t,s.lines,h,u,c,i.textStyle)}),{disposeOld:!1}),this.isDirty=!1}else this.isDirty=!1}}},n.setCanvasSize=function(e){var i=this;void 0!==this.size&&null!==this.size||(this.size=this.item.transform.size.clone());var n=this.size,r=n.x,o=void 0===r?1:r,a=n.y,s=void 0===a?1:a,l=this.textLayout,c=this.textStyle.fontScale||1,h=Math.max(1,l.maxTextWidth||0),u=Math.max(1,l.maxTextHeight||0);switch(l.overflow){case t.spec.TextOverflow.visible:var f,p,x,g,v=h*c,d=u*c,m=null!=(f=e.bboxTop)?f:0,y=null!=(x=e.bboxBottom)?x:m+(null!=(p=e.bboxHeight)?p:0),S=null!=(g=e.bboxHeight)?g:y-m,T=0;switch(l.textVerticalAlign){case t.spec.TextVerticalAlign.top:T=-m;break;case t.spec.TextVerticalAlign.middle:T=(d-S)/2-m;break;case t.spec.TextVerticalAlign.bottom:T=d-S-m}var b=T+m,w=T+y,A=Math.max(0,-b),O=Math.max(0,w-d),C=A,z=O;switch(l.textVerticalAlign){case t.spec.TextVerticalAlign.top:C=O,z=O;break;case t.spec.TextVerticalAlign.bottom:C=A,z=A;break;case t.spec.TextVerticalAlign.middle:C=A,z=O}for(var L=C,E=e.lines||[],H=E.map((function(t){return l.getOffsetXRich(i.textStyle,v,t.width)})),W=1/0,M=-1/0,V=0;V<E.length;V++){var R,k,F=null!=(R=H[V])?R:0,_=null!=(k=E[V].width)?k:0;W=Math.min(W,F),M=Math.max(M,F+_)}isFinite(W)||(W=0),isFinite(M)||(M=0);var D,B=Math.max(0,-W),P=Math.max(0,M-v),X=Math.ceil(v+B+P),Y=Math.ceil(d+C+z);e.baselineCompensationX=B,e.baselineCompensationY=L,e.containerWidth=v,e.canvasWidth=X,e.canvasHeight=Y,this.canvasSize=new t.math.Vector2(X,Y);var j=null!=(D=this.size)?D:this.item.transform.size,N=j.x,I=void 0===N?1:N,U=j.y,q=void 0===U?1:U;this.item.transform.size.set(I*X*this.SCALE_FACTOR*this.SCALE_FACTOR,q*Y*this.SCALE_FACTOR*this.SCALE_FACTOR),this.initialized=!0;break;case t.spec.TextOverflow.clip:var $,G=h*c,J=u*c;e.canvasWidth=G,e.canvasHeight=J,e.baselineCompensationX=0,e.baselineCompensationY=0,this.canvasSize=new t.math.Vector2(G,J),l.width=h,l.height=u;var K=null!=($=this.size)?$:this.item.transform.size,Q=K.x,Z=void 0===Q?1:Q,tt=K.y,et=void 0===tt?1:tt;this.item.transform.size.set(Z*G*this.SCALE_FACTOR*this.SCALE_FACTOR,et*J*this.SCALE_FACTOR*this.SCALE_FACTOR),this.initialized=!0;break;case t.spec.TextOverflow.display:if(!this.initialized){var it=h*c,nt=u*c;this.canvasSize=new t.math.Vector2(it,nt),this.item.transform.size.set(o*it*this.SCALE_FACTOR*this.SCALE_FACTOR,s*nt*this.SCALE_FACTOR*this.SCALE_FACTOR),this.initialized=!0}}},n.resolveCanvasSize=function(t,e,i,n){var r=Math.max(1,t.maxLineWidth||0),o=Math.max(1,t.totalHeight||0);return e.width=r/i.fontScale,e.height=o/i.fontScale,{canvasWidth:r,canvasHeight:o,contentWidth:t.maxLineWidth,bboxTop:t.bboxTop,bboxBottom:t.bboxBottom,bboxHeight:t.bboxHeight,lines:t.lines}},n.drawTextWithStrategies=function(t,e,i,n,r,o){var a=n.baselineY,s=i.lineOffsets;e.forEach((function(i,n){var r=i.richOptions,l=i.chars,c=s[n],h=a;r.forEach((function(e,n){var r=o.fontScale,a=o.textColor,s=o.fontFamily,u=o.textWeight,f=o.fontStyle,p=e.fontSize,x=e.fontColor,g=void 0===x?a:x,v=e.fontFamily,d=void 0===v?s:v,m=e.fontWeight,y=void 0===m?u:m,S=e.fontStyle,T=void 0===S?f:S,b=p;t.font=T+" "+y+" "+b*r+"px "+d;var w=g[0],A=g[1],O=g[2],C=g[3];t.fillStyle="rgba("+w+", "+A+", "+O+", "+C+")";var z=i.offsetX&&i.offsetX[n]?i.offsetX[n]:0;l[n].forEach((function(e){t.fillText(e.char,c+z+e.x,h)}))})),n<e.length-1&&(a+=e[n+1].lineHeight)}))},n.unsupported=function(t){throw new Error("RichTextComponent does not support "+t+" at runtime.")},n.setShadowOffsetY=function(t){this.unsupported("setShadowOffsetY")},n.setShadowBlur=function(t){this.unsupported("setShadowBlur")},n.setShadowOffsetX=function(t){this.unsupported("setShadowOffsetX")},n.setShadowColor=function(t){this.unsupported("setShadowColor")},n.setOutlineWidth=function(t){this.unsupported("setOutlineWidth")},n.setAutoWidth=function(t){this.unsupported("setAutoWidth")},n.setFontSize=function(t){this.unsupported("setFontSize")},n.setTextBaseline=function(t){console.warn("setTextBaseline 已废弃,请改用 setTextVerticalAlign。本次调用将转调用 setTextVerticalAlign。"),this.setTextVerticalAlign(t)},i}(t.MaskableGraphic),exports.RichTextComponent=function(t,e,i,n){var r,o=arguments.length,a=o<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,i):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(t,e,i,n);else for(var s=t.length-1;s>=0;s--)(r=t[s])&&(a=(o<3?r(a):o>3?r(e,i,a):r(e,i))||a);return o>3&&a&&Object.defineProperty(e,i,a),a}([t.effectsClass(t.spec.DataType.RichTextComponent)],exports.RichTextComponent),t.applyMixins(exports.RichTextComponent,[t.TextComponentBase]);var M="2.8.4";t.registerPlugin("rich-text",u),t.logger.info("Plugin rich text version: 2.8.4."),M!==n.version&&console.error("注意:请统一 RichText 插件与 Player 版本,不统一的版本混用会有不可预知的后果!","\nAttention: Please ensure the RichText plugin is synchronized with the Player version. Mixing and matching incompatible versions may result in unpredictable consequences!"),exports.RichTextLoader=u,exports.escape=function(t){if("string"!=typeof t)throw new Error("Input must be a string");return t.replace(/\\/g,"\\\\").replace(/=/g,"\\=").replace(/</g,"\\<").replace(/>/g,"\\>").replace(/\//g,"\\/")},exports.generateProgram=y,exports.isRichText=function(t){var e=d(t).filter((function(t){var e=t.tokenType;return"ContextStart"===e||"ContextEnd"===e})),i=e.filter((function(t){return"ContextStart"===t.tokenType})),n=e.filter((function(t){return"ContextEnd"===t.tokenType}));return!(i.length!==n.length||!i.length)&&function t(e,i){var n=e[0],r=e.slice(1);if(void 0===i&&(i=[]),!n)return 0===i.length;if("ContextStart"===n.tokenType)return t(r,i.concat(n.value));if("ContextEnd"===n.tokenType)return i[i.length-1]===n.value&&t(r,i.slice(0,-1));throw new Error("Unexpected token: "+n.tokenType)}(e.map((function(t){var e=t.tokenType,i=t.value;return{tokenType:e,value:"ContextStart"===e?i.match(x)[1]:i.match(g)[1]}})))},exports.lexer=d,exports.richTextParser=m,exports.unescape=function(t){if("string"!=typeof t)throw new Error("Input must be a string");return t.replace(/\\\//g,"/").replace(/\\>/g,">").replace(/\\</g,"<").replace(/\\=/g,"=").replace(/\\\\/g,"\\")},exports.version=M;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@galacean/effects/douyin"),e=require("@galacean/appx-adapter/douyin");function i(t){if(t&&t.__esModule)return t;var e=Object.create(null);return t&&Object.keys(t).forEach((function(i){if("default"!==i){var n=Object.getOwnPropertyDescriptor(t,i);Object.defineProperty(e,i,n.get?n:{enumerable:!0,get:function(){return t[i]}})}})),e.default=t,Object.freeze(e)}var n=i(t);function r(t,e){return r=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},r(t,e)}function o(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&&r(t,e)}function a(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(a=function(){return!!t})()}function s(t,e,i){return s=a()?Reflect.construct:function(t,e,i){var n=[null];n.push.apply(n,e);var o=new(Function.bind.apply(t,n));return i&&r(o,i.prototype),o},s.apply(null,arguments)}function l(t){return l=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},l(t)}function c(t){var e="function"==typeof Map?new Map:void 0;return c=function(t){if(null===t||(i=t,-1===Function.toString.call(i).indexOf("[native code]")))return t;var i;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,n)}function n(){return s(t,arguments,l(this).constructor)}return n.prototype=Object.create(t.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),r(n,t)},c(t)}var h,u=function(t){function e(){var e;return(e=t.apply(this,arguments)||this).name="rich-text",e}return o(e,t),e}(c(t.Plugin));function f(t,e){(null==e||e>t.length)&&(e=t.length);for(var i=0,n=new Array(e);i<e;i++)n[i]=t[i];return n}function p(t,e){var i="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(i)return(i=i.call(t)).next.bind(i);if(Array.isArray(t)||(i=function(t,e){if(t){if("string"==typeof t)return f(t,e);var i=Object.prototype.toString.call(t).slice(8,-1);return"Object"===i&&t.constructor&&(i=t.constructor.name),"Map"===i||"Set"===i?Array.from(i):"Arguments"===i||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i)?f(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){i&&(t=i);var n=0;return function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}!function(t){t.ContextStart="ContextStart",t.Text="Text",t.ContextEnd="ContextEnd",t.EscapedChar="EscapedChar"}(h||(h={}));var x=/^<([a-z]+)(=([^>]+))?>$/,g=/^<\/([a-z]+)>$/,v=[["EscapedChar",/^\\([=<>\\/])/],["ContextStart",/^<[a-z]+(=[^>]+)?>/],["ContextEnd",/^<\/[a-z]+>/],["Text",/^[^</>=\\]+/]],d=function(t,e,i){if(void 0===e&&(e=[]),void 0===i&&(i=0),!t)return e;var n=/^\\([=<>\\/])/.exec(t);if(n){var r=n[1];return d(t.slice(2),e.concat({tokenType:"Text",value:r}),i+2)}for(var o,a=p(v);!(o=a()).done;){var s=o.value,l=s[0],c=s[1];if("EscapedChar"!==l){var h=c.exec(t);if(h){var u=h[0],f=u.length;return d(t.slice(f),e.concat({tokenType:l,value:u}),i+f)}}}if(t.length>0)return d(t.slice(1),e.concat({tokenType:"Text",value:t[0]}),i+1);throw new Error('Unexpected token: "'+t[0]+'" at position '+i+' while reading "'+t+'"')},m=function(t){var e=function(){for(var t,e="",i=!1;r.length>0&&"Text"===(null==(t=r[0])?void 0:t.tokenType);){var n=a();n&&(e+=n.value,i=!0)}return i?e:void 0},i=function(){var t=s();if("ContextStart"===(null==t?void 0:t.tokenType)){a();var e,i=t.value.match(x);if(i)return{attributeName:i[1],attributeParam:null!=(e=i[3])?e:""};throw new Error("Expected a start tag marker at position "+o)}return{}},n=function(){var t=s();if("ContextEnd"===(null==t?void 0:t.tokenType)){a();var e=t.value.match(g);if(e)return{attributeName:e[1]};throw new Error("Expect an end tag marker at position "+o)}return{}},r=d(t),o=0,a=function(){var t,e=r.shift();return o+=null!=(t=null==e?void 0:e.value.length)?t:0,e},s=function(){return r[0]},l=[];return function t(r,a){for(void 0===r&&(r=[]),void 0===a&&(a="");;){var s=e();if(s)l.push({attributes:r,text:s});else{var c=i(),h=c.attributeName,u=c.attributeParam;if(!h){if(a){var f=n().attributeName;if(!f)throw new Error('Expect an end tag marker "'+a+'" at position '+o+" but found no tag!");if(f!==a)throw new Error('Expect an end tag marker "'+a+'" at position '+o+' but found tag "'+f+'"');return}break}t(r.concat({attributeName:h,attributeParam:null!=u?u:""}),h)}}}(),l};function y(t){return function(e){for(var i,n=p(m(e));!(i=n()).done;){var r=i.value,o=r.text,a=r.attributes.reduce((function(t,e){var i=e.attributeName,n=e.attributeParam;return i&&(t[i]=n),t}),{});t(o,a)}}}"function"==typeof SuppressedError&&SuppressedError;var S=function(){function e(e){this.width=0,this.height=0;var i=e.size,n=e.textOverflow,r=void 0===n?t.spec.TextOverflow.clip:n,o=e.textVerticalAlign,a=void 0===o?t.spec.TextVerticalAlign.middle:o,s=e.textAlign,l=void 0===s?t.spec.TextAlignment.left:s,c=e.letterSpace,h=void 0===c?0:c,u=e.lineHeight,f=void 0===u?.571:u,p=e.wrapEnabled,x=void 0!==p&&p,g=e.maxTextWidth,v=void 0===g?350:g,d=e.maxTextHeight,m=void 0===d?1e3:d,y=e.sizeMode,S=void 0===y?t.spec.TextSizeMode.autoWidth:y,T=e.useLegacyRichText,b=void 0!==T&&T;this.letterSpace=h,this.lineHeight=f,this.useLegacyRichText=b,this.overflow=r,this.textVerticalAlign=a,this.textAlign=l,this.width=i?i[0]:100,this.height=i?i[1]:100,this.wrapEnabled=x;this.maxTextWidth=50*v,this.maxTextHeight=50*m,this.sizeMode=S}var i=e.prototype;return i.getOffsetY=function(e,i,n,r,o){var a=e.outlineWidth,s=e.fontScale,l=(n-r)/3,c=r+a*s,h=void 0!==o?o:n*(i-1),u=0;switch(this.textVerticalAlign){case t.spec.TextVerticalAlign.top:u=c+l;break;case t.spec.TextVerticalAlign.middle:u=(this.height*s-h+c)/2;break;case t.spec.TextVerticalAlign.bottom:u=this.height*s-h-l}return u},i.getOffsetX=function(e,i){var n=0;switch(this.textAlign){case t.spec.TextAlignment.left:n=e.outlineWidth*e.fontScale;break;case t.spec.TextAlignment.middle:n=(this.width*e.fontScale-i)/2;break;case t.spec.TextAlignment.right:n=this.width*e.fontScale-i}return n},i.getOffsetYRich=function(e,i,n){if(0===i.length)return 0;var r=e.outlineWidth,o=e.fontScale,a=i.reduce((function(t,e){return t+e}),0),s=(i[0]-n)/3,l=n+r*o,c=a-i[0],h=0;switch(this.textVerticalAlign){case t.spec.TextVerticalAlign.top:h=l+s;break;case t.spec.TextVerticalAlign.middle:h=(this.height*o-a)/2+l;break;case t.spec.TextVerticalAlign.bottom:h=this.height*o-c-s}return h},i.getOffsetXRich=function(e,i,n){switch(this.textAlign){case t.spec.TextAlignment.left:return e.outlineWidth*e.fontScale;case t.spec.TextAlignment.middle:return(i-n)/2;case t.spec.TextAlignment.right:return i-n;default:return 0}},i.setSize=function(t,e){this.width=t,this.height=e},e}();function T(t,e){if(void 0===e&&(e=1),3!==(t=t.replace(/^#/,"")).length&&4!==t.length||(t=t.split("").map((function(t){return t+t})).join("")),8===t.length){var i=parseInt(t.slice(6,8),16)/255;t=t.slice(0,6),e=i}var n=parseInt(t,16);return[n>>16&255,n>>8&255,255&n,e]}function b(t,i){if(void 0===i&&(i=1),"string"!=typeof t||!t)throw new Error("Invalid color string");return t.startsWith("#")?T(t,i):T(function(t){if("string"!=typeof t||!t)throw new Error("Invalid color name provided");if(void 0===e.document)throw new Error("This method requires a browser environment");var i=e.document.createElement("canvas"),n=i.getContext("2d");if(n)try{return n.fillStyle=t,n.fillStyle}finally{null==i.remove||i.remove.call(i)}throw new Error("Failed to get 2D context for color conversion!")}(t))}var w=function(){function t(){}var e=t.prototype;return e.computeLines=function(t,e,i,n,r,o,a,s){var l=this,c=[],h=[],u=(n.lineHeight||0)*o,f=this.createNewLine(),p=0,x=0,g=function(){if(0!==f.chars.length){f.lineHeight=0===c.length?(f.lineAscent||0)+(f.lineDescent||0):u;var t=0===c.length?0:h[h.length-1]+u;h.push(t),x+=f.lineHeight,c.push(f),p=Math.max(p,f.width),f=l.createNewLine()}};t.forEach((function(t){var n=t.text,r=t.isNewLine,l=t.fontSize;r&&g();var c=t.fontStyle||i.fontStyle||"normal";e.font=c+" "+(t.fontWeight||i.textWeight)+" 10px "+(t.fontFamily||i.fontFamily),f.offsetX.push(f.width);for(var h=0,u=[],p=0,x=0,v=0;v<n.length;v++){var d=n[v],m=e.measureText(d),y=m.width,S=(y<=0?0:y)*l*s*o,T=l*o*s,b=m.actualBoundingBoxAscent*T,w=m.actualBoundingBoxDescent*T;p=Math.max(p,b),x=Math.max(x,w),v>0&&(h+=a),u.push({char:d,x:h}),h+=S}f.chars.push(u),f.width+=h,f.richOptions.push(t),f.lineAscent=Math.max(f.lineAscent||0,p),f.lineDescent=Math.max(f.lineDescent||0,x)})),g();var v=1/0,d=-1/0;if(0===c.length)return{lines:c,maxLineWidth:p,totalHeight:x,bboxTop:0,bboxBottom:0,bboxHeight:0};for(var m=0;m<c.length;m++)v=Math.min(v,h[m]-(c[m].lineAscent||0)),d=Math.max(d,h[m]+(c[m].lineDescent||0));return{lines:c,maxLineWidth:p,totalHeight:x,bboxTop:v,bboxBottom:d,bboxHeight:d-v}},e.createNewLine=function(){return{richOptions:[],offsetX:[],width:0,lineHeight:0,offsetY:0,chars:[],lineAscent:0,lineDescent:0}},t}(),A=function(){function t(){}var e=t.prototype;return e.computeLines=function(t,e,i,n,r,o,a,s){var l=this,c=[],h=[],u=(n.lineHeight||0)*o,f=this.createNewLine(),p=0,x=0,g=null,v=0,d=[],m=null,y=function(){if(S(),0!==f.chars.length){f.lineHeight=0===c.length?(f.lineAscent||0)+(f.lineDescent||0):u;var t=0===c.length?0:h[h.length-1]+u;h.push(t),x+=f.lineHeight,c.push(f),p=Math.max(p,f.width),f=l.createNewLine(),g=null,v=0,d=[],m=null}},S=function(){0!==d.length&&(null===g&&(g=f.width),f.offsetX.push(g),f.chars.push(d),m&&f.richOptions.push(m),g=null,v=0,d=[],m=null)};t.forEach((function(t){var r=t.text,l=t.isNewLine,c=t.fontSize,h=t.fontStyle||i.fontStyle||"normal";e.font=h+" "+(t.fontWeight||i.textWeight)+" 10px "+(t.fontFamily||i.fontFamily),l&&(S(),y());for(var u=0;u<r.length;u++){var p=r[u],x=e.measureText(p),T=x.width,b=(T<=0?0:T)*c*s*o,w=c*o*s,A=x.actualBoundingBoxAscent*w,O=x.actualBoundingBoxDescent*w,C=d.length>0?a:0;f.width+C+b>(n.maxTextWidth||1/0)&&(S(),y()),null===g&&(g=f.width,m=t),d.length>0&&(v+=a,f.width+=a),d.push({char:p,x:v}),f.lineAscent=Math.max(f.lineAscent||0,A),f.lineDescent=Math.max(f.lineDescent||0,O),v+=b,f.width+=b}S()})),y();for(var T=1/0,b=-1/0,w=0;w<c.length;w++)T=Math.min(T,h[w]-(c[w].lineAscent||0)),b=Math.max(b,h[w]+(c[w].lineDescent||0));return{lines:c,maxLineWidth:p,totalHeight:x,bboxTop:T,bboxBottom:b,bboxHeight:b-T}},e.createNewLine=function(){return{richOptions:[],offsetX:[],width:0,lineHeight:0,offsetY:0,chars:[],lineAscent:0,lineDescent:0}},t}(),O=function(){function t(){}return t.prototype.apply=function(t,e,i,n){var r,o,a=function(t,e){return Math.abs(e)>1e-5?t/e:1},s=i.maxTextWidth*n.fontScale,l=i.maxTextHeight*n.fontScale,c=Math.max(1,null!=(r=e.contentWidth)?r:e.canvasWidth),h=Math.max(1,null!=(o=e.bboxHeight)?o:e.canvasHeight),u=Math.min(1,a(s,c),a(l,h));if(u>.9999)return{globalScale:1};for(var f,x=p(t);!(f=x()).done;){var g=f.value;if(g.width*=u,g.lineHeight*=u,g.offsetX)for(var v=0;v<g.offsetX.length;v++)g.offsetX[v]*=u;for(var d,m=p(g.chars||[]);!(d=m()).done;)for(var y,S=p(d.value);!(y=S()).done;){y.value.x*=u}for(var T,b=p(g.richOptions||[]);!(T=b()).done;){T.value.fontSize*=u}null!=g.lineAscent&&(g.lineAscent*=u),null!=g.lineDescent&&(g.lineDescent*=u)}return{globalScale:u}},t}(),C=function(){function t(){}return t.prototype.apply=function(t,e,i,n){return{globalScale:1}},t}(),z=function(){function t(){}return t.prototype.apply=function(t,e,i,n){return{globalScale:1}},t}(),L=function(){function e(){}return e.prototype.getHorizontalOffsets=function(e,i,n,r,o){var a,s,l=null!=(a=i.containerWidth)?a:r.maxTextWidth*o.fontScale,c=null!=(s=i.baselineCompensationX)?s:0,h=e.map((function(t){return r.getOffsetXRich(o,l,t.width)}));return{lineOffsets:r.overflow===t.spec.TextOverflow.visible?h.map((function(t){return t+c})):h}},e}(),E=function(){function e(){}return e.prototype.getVerticalOffsets=function(e,i,n,r,o,a){var s,l=null!=(s=i.baselineCompensationY)?s:0,c=0;if(0===e.length)return{baselineY:0,lineYOffsets:[]};switch(r.overflow){case t.spec.TextOverflow.visible:var h,u,f,p,x=r.maxTextHeight*o.fontScale,g=null!=(h=i.bboxTop)?h:0,v=null!=(f=i.bboxBottom)?f:g+(null!=(u=i.bboxHeight)?u:0),d=null!=(p=i.bboxHeight)?p:v-g,m=0;switch(r.textVerticalAlign){case t.spec.TextVerticalAlign.top:m=-g;break;case t.spec.TextVerticalAlign.middle:m=(x-d)/2-g;break;case t.spec.TextVerticalAlign.bottom:m=x-d-g}c=m+l;break;case t.spec.TextOverflow.clip:for(var y=r.maxTextHeight*o.fontScale,S=[0],T=1;T<e.length;T++)S[T]=S[T-1]+e[T].lineHeight;for(var b=1/0,w=-1/0,A=0;A<e.length;A++){var O,C,z=null!=(O=e[A].lineAscent)?O:0,L=null!=(C=e[A].lineDescent)?C:0;b=Math.min(b,S[A]-z),w=Math.max(w,S[A]+L)}var E=w-b,H=0;switch(r.textVerticalAlign){case t.spec.TextVerticalAlign.top:H=-b;break;case t.spec.TextVerticalAlign.middle:H=(y-E)/2-b;break;case t.spec.TextVerticalAlign.bottom:H=y-E-b}c=H+l;break;case t.spec.TextOverflow.display:for(var W=r.maxTextHeight*o.fontScale,M=[0],V=1;V<e.length;V++)M[V]=M[V-1]+e[V].lineHeight;for(var R=1/0,k=-1/0,F=0;F<e.length;F++){var _,D,B=null!=(_=e[F].lineAscent)?_:0,P=null!=(D=e[F].lineDescent)?D:0;R=Math.min(R,M[F]-B),k=Math.max(k,M[F]+P)}var X=k-R,Y=0;switch(r.textVerticalAlign){case t.spec.TextVerticalAlign.top:Y=-R;break;case t.spec.TextVerticalAlign.middle:Y=(W-X)/2-R;break;case t.spec.TextVerticalAlign.bottom:Y=W-X-R}for(var j=[],N=Y,I=0;I<e.length;I++)j.push(N),I<e.length-1&&(N+=e[I+1].lineHeight);return{baselineY:Y,lineYOffsets:j}}var U=[],q=c;return e.forEach((function(t,i){U.push(q),i<e.length-1&&(q+=e[i+1].lineHeight)})),{baselineY:c,lineYOffsets:U}},e}(),H=function(){function e(){}return e.createWrapStrategy=function(t){return t?new A:new w},e.createOverflowStrategy=function(e){switch(e){case t.spec.TextOverflow.clip:return new C;case t.spec.TextOverflow.display:return new O;case t.spec.TextOverflow.visible:default:return new z}},e.createHorizontalAlignStrategy=function(){return new L},e.createVerticalAlignStrategy=function(){return new E},e}(),W=0;exports.RichTextComponent=function(e){function i(i){var n;return(n=e.call(this,i)||this).isDirty=!0,n.text="",n.processedTextOptions=[],n.singleLineHeight=1.571,n.size=null,n.initialized=!1,n.canvasSize=null,n.SCALE_FACTOR=.1,n.ALPHA_FIX_VALUE=1/255,n.name="MRichText"+W++,n.initTextBase(i),n.richWrapStrategy=H.createWrapStrategy(),n.richOverflowStrategy=H.createOverflowStrategy(t.spec.TextOverflow.display),n.richHorizontalAlignStrategy=H.createHorizontalAlignStrategy(),n.richVerticalAlignStrategy=H.createVerticalAlignStrategy(),n}o(i,e);var n=i.prototype;return n.onUpdate=function(t){e.prototype.onUpdate.call(this,t),this.updateTexture()},n.onDestroy=function(){e.prototype.onDestroy.call(this),this.disposeTextTexture()},n.fromData=function(i){e.prototype.fromData.call(this,i);var n=i.interaction,r=i.options;this.interaction=n,this.textStyle=new t.TextStyle(r),this.textLayout=new S(r),this.text=r.text?r.text.toString():" ",this.textLayout.useLegacyRichText&&(this.textLayout.textVerticalAlign=t.spec.TextVerticalAlign.middle),this.updateStrategies(),this.renderText(r),this.material.setColor("_Color",new t.math.Color(1,1,1,1))},n.updateStrategies=function(){var t=this.textLayout;t&&(this.richWrapStrategy=H.createWrapStrategy(t.wrapEnabled),this.richOverflowStrategy=H.createOverflowStrategy(t.overflow))},n.generateTextProgram=function(e){var i=this;this.processedTextOptions=[];var n=y((function(e,n){/^\n+$/.test(e)&&(e=e.replace(/\n/g,"\n ")),e.split("\n").forEach((function(e,r){var o={text:e,fontSize:i.textStyle.fontSize,isNewLine:!1};r>0&&(o.isNewLine=!0),"b"in n&&(o.fontWeight=t.spec.TextWeight.bold),"i"in n&&(o.fontStyle=t.spec.FontStyle.italic),"size"in n&&n.size&&(o.fontSize=parseInt(n.size,10)),"color"in n&&n.color&&(o.fontColor=b(n.color)),i.processedTextOptions.push(o)}))}));n(e)},n.updateWithOptions=function(e){this.textStyle=new t.TextStyle(e),this.textLayout=new S(e),this.text=e.text?e.text.toString():" ",this.textLayout.useLegacyRichText&&(this.textLayout.textVerticalAlign=t.spec.TextVerticalAlign.middle),this.updateStrategies(),this.isDirty=!0},n.renderText=function(e){var i=e.size;i&&(this.canvasSize=new t.math.Vector2(i[0],i[1])),this.updateTexture()},n.updateTexture=function(t){if(void 0===t&&(t=!0),this.isDirty&&this.context&&this.canvas&&this.textStyle&&this.textLayout){var e=!0===this.textLayout.useLegacyRichText;this.singleLineHeight=e?1.571:1,e?this.updateTextureLegacy(t):this.updateTextureWithStrategies(t)}},n.updateTextureLegacy=function(e){var i=this;if(this.isDirty&&this.context&&this.canvas&&this.textStyle){this.generateTextProgram(this.text);var n=0,r=0,o=this.textLayout,a=this.textStyle,s=o.overflow,l=o.letterSpace,c=void 0===l?0:l,h=this.context,u=[],f=a.fontSize*a.fontScale,p={richOptions:[],offsetX:[],width:0,lineHeight:f*this.singleLineHeight,offsetY:f*(this.singleLineHeight-1)/2};if(this.processedTextOptions.forEach((function(t){var e=t.text,o=t.isNewLine,s=t.fontSize;o&&(u.push(p),n=Math.max(n,p.width),p={richOptions:[],offsetX:[],width:0,lineHeight:f*i.singleLineHeight,offsetY:f*(i.singleLineHeight-1)/2},r+=p.lineHeight),h.font=(t.fontWeight||a.textWeight)+" 10px "+(t.fontFamily||a.fontFamily);var l=h.measureText(e),x=l.width;if(void 0!==l.actualBoundingBoxLeft&&void 0!==l.actualBoundingBoxRight){var g=l.actualBoundingBoxLeft+l.actualBoundingBoxRight;g>0&&(x=Math.max(x,g))}var v=s*i.singleLineHeight*a.fontScale;v>p.lineHeight&&(r+=v-p.lineHeight,p.lineHeight=v,p.offsetY=s*a.fontScale*(i.singleLineHeight-1)/2),p.offsetX.push(p.width),p.width+=(x<=0?0:x)*s*i.SCALE_FACTOR*a.fontScale+e.length*c,p.richOptions.push(t)})),u.push(p),n=Math.max(n,p.width),r+=p.lineHeight,0!==n&&0!==r){void 0!==this.size&&null!==this.size||(this.size=this.item.transform.size.clone());var x=this.size,g=x.x,v=void 0===g?1:g,d=x.y,m=void 0===d?1:d;if(!this.initialized){this.canvasSize=this.canvasSize?this.canvasSize:new t.math.Vector2(n,r);var y=this.canvasSize,S=y.x,T=y.y;this.item.transform.size.set(v*S*this.SCALE_FACTOR*this.SCALE_FACTOR,m*T*this.SCALE_FACTOR*this.SCALE_FACTOR),this.size=this.item.transform.size.clone(),this.initialized=!0}t.assertExist(this.canvasSize);var b=this.canvasSize,w=b.x,A=b.y;o.width=w/a.fontScale,o.height=A/a.fontScale,this.renderToTexture(w,A,e,(function(e){if(0!==u.length){var n=o.getOffsetY(a,u.length,f*i.singleLineHeight,a.fontSize);u.forEach((function(i,r){var l=i.richOptions,c=i.offsetX,h=i.width,u=h,f=c;if(s===t.spec.TextOverflow.display&&h>w){var p=w/h;u*=p,f=c.map((function(t){return t*p}))}var x=o.getOffsetX(a,u);r>0&&(n+=i.lineHeight-i.offsetY),l.forEach((function(i,r){var o=a.fontScale,l=a.textColor,c=a.fontFamily,u=a.textWeight,p=a.fontStyle,g=i.text,v=i.fontSize,d=i.fontColor,m=void 0===d?l:d,y=i.fontFamily,S=void 0===y?c:y,T=i.fontWeight,b=void 0===T?u:T,A=i.fontStyle,O=void 0===A?p:A,C=v;s===t.spec.TextOverflow.display&&h>w&&(C/=h/w);var z=f[r]+x;e.font=O+" "+b+" "+C*o+"px "+S;var L=m[0],E=m[1],H=m[2],W=m[3];e.fillStyle="rgba("+L+", "+E+", "+H+", "+W+")",e.fillText(g,z,n)}))}))}}),{disposeOld:!1}),this.isDirty=!1}else this.isDirty=!1}},n.updateTextureWithStrategies=function(e){var i=this;if(this.isDirty&&this.context&&this.canvas){this.generateTextProgram(this.text);var n=this.textLayout,r=n.letterSpace,o=void 0===r?0:r,a=this.context;if(a){var s=this.richWrapStrategy.computeLines(this.processedTextOptions,a,this.textStyle,n,this.singleLineHeight,this.textStyle.fontScale,o,this.SCALE_FACTOR);if(0!==s.lines.length&&0!==s.maxLineWidth&&0!==s.totalHeight){var l=this.resolveCanvasSize(s,n,this.textStyle,this.singleLineHeight);this.setCanvasSize(l);var c=this.richOverflowStrategy.apply(s.lines,l,n,this.textStyle),h=this.richHorizontalAlignStrategy.getHorizontalOffsets(s.lines,l,c,n,this.textStyle),u=this.richVerticalAlignStrategy.getVerticalOffsets(s.lines,l,c,n,this.textStyle,this.singleLineHeight);t.assertExist(this.canvasSize);var f=this.canvasSize,p=f.x,x=f.y,g=Math.max(1,Math.ceil(p)),v=Math.max(1,Math.ceil(x));n.width=g/this.textStyle.fontScale,n.height=v/this.textStyle.fontScale,this.renderToTexture(g,v,e,(function(t){i.drawTextWithStrategies(t,s.lines,h,u,c,i.textStyle)}),{disposeOld:!1}),this.isDirty=!1}else this.isDirty=!1}}},n.setCanvasSize=function(e){var i=this;void 0!==this.size&&null!==this.size||(this.size=this.item.transform.size.clone());var n=this.size,r=n.x,o=void 0===r?1:r,a=n.y,s=void 0===a?1:a,l=this.textLayout,c=this.textStyle.fontScale||1,h=Math.max(1,l.maxTextWidth||0),u=Math.max(1,l.maxTextHeight||0);switch(l.overflow){case t.spec.TextOverflow.visible:var f,p,x,g,v=h*c,d=u*c,m=null!=(f=e.bboxTop)?f:0,y=null!=(x=e.bboxBottom)?x:m+(null!=(p=e.bboxHeight)?p:0),S=null!=(g=e.bboxHeight)?g:y-m,T=0;switch(l.textVerticalAlign){case t.spec.TextVerticalAlign.top:T=-m;break;case t.spec.TextVerticalAlign.middle:T=(d-S)/2-m;break;case t.spec.TextVerticalAlign.bottom:T=d-S-m}var b=T+m,w=T+y,A=Math.max(0,-b),O=Math.max(0,w-d),C=A,z=O;switch(l.textVerticalAlign){case t.spec.TextVerticalAlign.top:C=O,z=O;break;case t.spec.TextVerticalAlign.bottom:C=A,z=A;break;case t.spec.TextVerticalAlign.middle:C=A,z=O}for(var L=C,E=e.lines||[],H=E.map((function(t){return l.getOffsetXRich(i.textStyle,v,t.width)})),W=1/0,M=-1/0,V=0;V<E.length;V++){var R,k,F=null!=(R=H[V])?R:0,_=null!=(k=E[V].width)?k:0;W=Math.min(W,F),M=Math.max(M,F+_)}isFinite(W)||(W=0),isFinite(M)||(M=0);var D,B=Math.max(0,-W),P=Math.max(0,M-v),X=Math.ceil(v+B+P),Y=Math.ceil(d+C+z);e.baselineCompensationX=B,e.baselineCompensationY=L,e.containerWidth=v,e.canvasWidth=X,e.canvasHeight=Y,this.canvasSize=new t.math.Vector2(X,Y);var j=null!=(D=this.size)?D:this.item.transform.size,N=j.x,I=void 0===N?1:N,U=j.y,q=void 0===U?1:U;this.item.transform.size.set(I*X*this.SCALE_FACTOR*this.SCALE_FACTOR,q*Y*this.SCALE_FACTOR*this.SCALE_FACTOR),this.initialized=!0;break;case t.spec.TextOverflow.clip:var $,G=h*c,J=u*c;e.canvasWidth=G,e.canvasHeight=J,e.baselineCompensationX=0,e.baselineCompensationY=0,this.canvasSize=new t.math.Vector2(G,J),l.width=h,l.height=u;var K=null!=($=this.size)?$:this.item.transform.size,Q=K.x,Z=void 0===Q?1:Q,tt=K.y,et=void 0===tt?1:tt;this.item.transform.size.set(Z*G*this.SCALE_FACTOR*this.SCALE_FACTOR,et*J*this.SCALE_FACTOR*this.SCALE_FACTOR),this.initialized=!0;break;case t.spec.TextOverflow.display:if(!this.initialized){var it=h*c,nt=u*c;this.canvasSize=new t.math.Vector2(it,nt),this.item.transform.size.set(o*it*this.SCALE_FACTOR*this.SCALE_FACTOR,s*nt*this.SCALE_FACTOR*this.SCALE_FACTOR),this.initialized=!0}}},n.resolveCanvasSize=function(t,e,i,n){var r=Math.max(1,t.maxLineWidth||0),o=Math.max(1,t.totalHeight||0);return e.width=r/i.fontScale,e.height=o/i.fontScale,{canvasWidth:r,canvasHeight:o,contentWidth:t.maxLineWidth,bboxTop:t.bboxTop,bboxBottom:t.bboxBottom,bboxHeight:t.bboxHeight,lines:t.lines}},n.drawTextWithStrategies=function(t,e,i,n,r,o){var a=n.baselineY,s=i.lineOffsets;e.forEach((function(i,n){var r=i.richOptions,l=i.chars,c=s[n],h=a;r.forEach((function(e,n){var r=o.fontScale,a=o.textColor,s=o.fontFamily,u=o.textWeight,f=o.fontStyle,p=e.fontSize,x=e.fontColor,g=void 0===x?a:x,v=e.fontFamily,d=void 0===v?s:v,m=e.fontWeight,y=void 0===m?u:m,S=e.fontStyle,T=void 0===S?f:S,b=p;t.font=T+" "+y+" "+b*r+"px "+d;var w=g[0],A=g[1],O=g[2],C=g[3];t.fillStyle="rgba("+w+", "+A+", "+O+", "+C+")";var z=i.offsetX&&i.offsetX[n]?i.offsetX[n]:0;l[n].forEach((function(e){t.fillText(e.char,c+z+e.x,h)}))})),n<e.length-1&&(a+=e[n+1].lineHeight)}))},n.unsupported=function(t){throw new Error("RichTextComponent does not support "+t+" at runtime.")},n.setShadowOffsetY=function(t){this.unsupported("setShadowOffsetY")},n.setShadowBlur=function(t){this.unsupported("setShadowBlur")},n.setShadowOffsetX=function(t){this.unsupported("setShadowOffsetX")},n.setShadowColor=function(t){this.unsupported("setShadowColor")},n.setOutlineWidth=function(t){this.unsupported("setOutlineWidth")},n.setAutoWidth=function(t){this.unsupported("setAutoWidth")},n.setFontSize=function(t){this.unsupported("setFontSize")},n.setTextBaseline=function(t){console.warn("setTextBaseline 已废弃,请改用 setTextVerticalAlign。本次调用将转调用 setTextVerticalAlign。"),this.setTextVerticalAlign(t)},i}(t.MaskableGraphic),exports.RichTextComponent=function(t,e,i,n){var r,o=arguments.length,a=o<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,i):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(t,e,i,n);else for(var s=t.length-1;s>=0;s--)(r=t[s])&&(a=(o<3?r(a):o>3?r(e,i,a):r(e,i))||a);return o>3&&a&&Object.defineProperty(e,i,a),a}([t.effectsClass(t.spec.DataType.RichTextComponent)],exports.RichTextComponent),t.applyMixins(exports.RichTextComponent,[t.TextComponentBase]);var M="2.8.6";t.registerPlugin("rich-text",u),t.logger.info("Plugin rich text version: 2.8.6."),M!==n.version&&console.error("注意:请统一 RichText 插件与 Player 版本,不统一的版本混用会有不可预知的后果!","\nAttention: Please ensure the RichText plugin is synchronized with the Player version. Mixing and matching incompatible versions may result in unpredictable consequences!"),exports.RichTextLoader=u,exports.escape=function(t){if("string"!=typeof t)throw new Error("Input must be a string");return t.replace(/\\/g,"\\\\").replace(/=/g,"\\=").replace(/</g,"\\<").replace(/>/g,"\\>").replace(/\//g,"\\/")},exports.generateProgram=y,exports.isRichText=function(t){var e=d(t).filter((function(t){var e=t.tokenType;return"ContextStart"===e||"ContextEnd"===e})),i=e.filter((function(t){return"ContextStart"===t.tokenType})),n=e.filter((function(t){return"ContextEnd"===t.tokenType}));return!(i.length!==n.length||!i.length)&&function t(e,i){var n=e[0],r=e.slice(1);if(void 0===i&&(i=[]),!n)return 0===i.length;if("ContextStart"===n.tokenType)return t(r,i.concat(n.value));if("ContextEnd"===n.tokenType)return i[i.length-1]===n.value&&t(r,i.slice(0,-1));throw new Error("Unexpected token: "+n.tokenType)}(e.map((function(t){var e=t.tokenType,i=t.value;return{tokenType:e,value:"ContextStart"===e?i.match(x)[1]:i.match(g)[1]}})))},exports.lexer=d,exports.richTextParser=m,exports.unescape=function(t){if("string"!=typeof t)throw new Error("Input must be a string");return t.replace(/\\\//g,"/").replace(/\\>/g,">").replace(/\\</g,"<").replace(/\\=/g,"=").replace(/\\\\/g,"\\")},exports.version=M;
2
2
  //# sourceMappingURL=douyin.js.map
package/dist/douyin.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import*as t from"@galacean/effects/douyin";import{Plugin as e,spec as i,effectsClass as n,applyMixins as r,TextComponentBase as a,TextStyle as o,math as l,assertExist as s,MaskableGraphic as h,registerPlugin as c,logger as u}from"@galacean/effects/douyin";import{document as f}from"@galacean/appx-adapter/douyin";function g(t,e){return g=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},g(t,e)}function x(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&&g(t,e)}function p(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(p=function(){return!!t})()}function v(t,e,i){return v=p()?Reflect.construct:function(t,e,i){var n=[null];n.push.apply(n,e);var r=new(Function.bind.apply(t,n));return i&&g(r,i.prototype),r},v.apply(null,arguments)}function d(t){return d=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},d(t)}function m(t){var e="function"==typeof Map?new Map:void 0;return m=function(t){if(null===t||(i=t,-1===Function.toString.call(i).indexOf("[native code]")))return t;var i;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,n)}function n(){return v(t,arguments,d(this).constructor)}return n.prototype=Object.create(t.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),g(n,t)},m(t)}var y,S=function(t){function e(){var e;return(e=t.apply(this,arguments)||this).name="rich-text",e}return x(e,t),e}(m(e));function T(t,e){(null==e||e>t.length)&&(e=t.length);for(var i=0,n=new Array(e);i<e;i++)n[i]=t[i];return n}function w(t,e){var i="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(i)return(i=i.call(t)).next.bind(i);if(Array.isArray(t)||(i=function(t,e){if(t){if("string"==typeof t)return T(t,e);var i=Object.prototype.toString.call(t).slice(8,-1);return"Object"===i&&t.constructor&&(i=t.constructor.name),"Map"===i||"Set"===i?Array.from(i):"Arguments"===i||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i)?T(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){i&&(t=i);var n=0;return function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}!function(t){t.ContextStart="ContextStart",t.Text="Text",t.ContextEnd="ContextEnd",t.EscapedChar="EscapedChar"}(y||(y={}));var b=/^<([a-z]+)(=([^>]+))?>$/,A=/^<\/([a-z]+)>$/,O=[["EscapedChar",/^\\([=<>\\/])/],["ContextStart",/^<[a-z]+(=[^>]+)?>/],["ContextEnd",/^<\/[a-z]+>/],["Text",/^[^</>=\\]+/]],C=function(t,e,i){if(void 0===e&&(e=[]),void 0===i&&(i=0),!t)return e;var n=/^\\([=<>\\/])/.exec(t);if(n){var r=n[1];return C(t.slice(2),e.concat({tokenType:"Text",value:r}),i+2)}for(var a,o=w(O);!(a=o()).done;){var l=a.value,s=l[0],h=l[1];if("EscapedChar"!==s){var c=h.exec(t);if(c){var u=c[0],f=u.length;return C(t.slice(f),e.concat({tokenType:s,value:u}),i+f)}}}if(t.length>0)return C(t.slice(1),e.concat({tokenType:"Text",value:t[0]}),i+1);throw new Error('Unexpected token: "'+t[0]+'" at position '+i+' while reading "'+t+'"')},z=function(t){var e=function(){for(var t,e="",i=!1;r.length>0&&"Text"===(null==(t=r[0])?void 0:t.tokenType);){var n=o();n&&(e+=n.value,i=!0)}return i?e:void 0},i=function(){var t=l();if("ContextStart"===(null==t?void 0:t.tokenType)){o();var e,i=t.value.match(b);if(i)return{attributeName:i[1],attributeParam:null!=(e=i[3])?e:""};throw new Error("Expected a start tag marker at position "+a)}return{}},n=function(){var t=l();if("ContextEnd"===(null==t?void 0:t.tokenType)){o();var e=t.value.match(A);if(e)return{attributeName:e[1]};throw new Error("Expect an end tag marker at position "+a)}return{}},r=C(t),a=0,o=function(){var t,e=r.shift();return a+=null!=(t=null==e?void 0:e.value.length)?t:0,e},l=function(){return r[0]},s=[];return function t(r,o){for(void 0===r&&(r=[]),void 0===o&&(o="");;){var l=e();if(l)s.push({attributes:r,text:l});else{var h=i(),c=h.attributeName,u=h.attributeParam;if(!c){if(o){var f=n().attributeName;if(!f)throw new Error('Expect an end tag marker "'+o+'" at position '+a+" but found no tag!");if(f!==o)throw new Error('Expect an end tag marker "'+o+'" at position '+a+' but found tag "'+f+'"');return}break}t(r.concat({attributeName:c,attributeParam:null!=u?u:""}),c)}}}(),s};function L(t){return function(e){for(var i,n=w(z(e));!(i=n()).done;){var r=i.value,a=r.text,o=r.attributes.reduce((function(t,e){var i=e.attributeName,n=e.attributeParam;return i&&(t[i]=n),t}),{});t(a,o)}}}function H(t){var e=C(t).filter((function(t){var e=t.tokenType;return"ContextStart"===e||"ContextEnd"===e})),i=e.filter((function(t){return"ContextStart"===t.tokenType})),n=e.filter((function(t){return"ContextEnd"===t.tokenType}));if(i.length!==n.length||!i.length)return!1;return function t(e,i){var n=e[0],r=e.slice(1);if(void 0===i&&(i=[]),!n)return 0===i.length;if("ContextStart"===n.tokenType)return t(r,i.concat(n.value));if("ContextEnd"===n.tokenType)return i[i.length-1]===n.value&&t(r,i.slice(0,-1));throw new Error("Unexpected token: "+n.tokenType)}(e.map((function(t){var e=t.tokenType,i=t.value;return{tokenType:e,value:"ContextStart"===e?i.match(b)[1]:i.match(A)[1]}})))}function E(t){if("string"!=typeof t)throw new Error("Input must be a string");return t.replace(/\\/g,"\\\\").replace(/=/g,"\\=").replace(/</g,"\\<").replace(/>/g,"\\>").replace(/\//g,"\\/")}function W(t){if("string"!=typeof t)throw new Error("Input must be a string");return t.replace(/\\\//g,"/").replace(/\\>/g,">").replace(/\\</g,"<").replace(/\\=/g,"=").replace(/\\\\/g,"\\")}"function"==typeof SuppressedError&&SuppressedError;var V=function(){function t(t){this.width=0,this.height=0;var e=t.size,n=t.textOverflow,r=void 0===n?i.TextOverflow.clip:n,a=t.textVerticalAlign,o=void 0===a?i.TextVerticalAlign.middle:a,l=t.textAlign,s=void 0===l?i.TextAlignment.left:l,h=t.letterSpace,c=void 0===h?0:h,u=t.lineHeight,f=void 0===u?.571:u,g=t.wrapEnabled,x=void 0!==g&&g,p=t.maxTextWidth,v=void 0===p?350:p,d=t.maxTextHeight,m=void 0===d?1e3:d,y=t.sizeMode,S=void 0===y?i.TextSizeMode.autoWidth:y,T=t.useLegacyRichText,w=void 0!==T&&T;this.letterSpace=c,this.lineHeight=f,this.useLegacyRichText=w,this.overflow=r,this.textVerticalAlign=o,this.textAlign=s,this.width=e?e[0]:100,this.height=e?e[1]:100,this.wrapEnabled=x;this.maxTextWidth=50*v,this.maxTextHeight=50*m,this.sizeMode=S}var e=t.prototype;return e.getOffsetY=function(t,e,n,r,a){var o=t.outlineWidth,l=t.fontScale,s=(n-r)/3,h=r+o*l,c=void 0!==a?a:n*(e-1),u=0;switch(this.textVerticalAlign){case i.TextVerticalAlign.top:u=h+s;break;case i.TextVerticalAlign.middle:u=(this.height*l-c+h)/2;break;case i.TextVerticalAlign.bottom:u=this.height*l-c-s}return u},e.getOffsetX=function(t,e){var n=0;switch(this.textAlign){case i.TextAlignment.left:n=t.outlineWidth*t.fontScale;break;case i.TextAlignment.middle:n=(this.width*t.fontScale-e)/2;break;case i.TextAlignment.right:n=this.width*t.fontScale-e}return n},e.getOffsetYRich=function(t,e,n){if(0===e.length)return 0;var r=t.outlineWidth,a=t.fontScale,o=e.reduce((function(t,e){return t+e}),0),l=(e[0]-n)/3,s=n+r*a,h=o-e[0],c=0;switch(this.textVerticalAlign){case i.TextVerticalAlign.top:c=s+l;break;case i.TextVerticalAlign.middle:c=(this.height*a-o)/2+s;break;case i.TextVerticalAlign.bottom:c=this.height*a-h-l}return c},e.getOffsetXRich=function(t,e,n){switch(this.textAlign){case i.TextAlignment.left:return t.outlineWidth*t.fontScale;case i.TextAlignment.middle:return(e-n)/2;case i.TextAlignment.right:return e-n;default:return 0}},e.setSize=function(t,e){this.width=t,this.height=e},t}();function M(t,e){if(void 0===e&&(e=1),3!==(t=t.replace(/^#/,"")).length&&4!==t.length||(t=t.split("").map((function(t){return t+t})).join("")),8===t.length){var i=parseInt(t.slice(6,8),16)/255;t=t.slice(0,6),e=i}var n=parseInt(t,16);return[n>>16&255,n>>8&255,255&n,e]}function k(t,e){if(void 0===e&&(e=1),"string"!=typeof t||!t)throw new Error("Invalid color string");return t.startsWith("#")?M(t,e):M(function(t){if("string"!=typeof t||!t)throw new Error("Invalid color name provided");if(void 0===f)throw new Error("This method requires a browser environment");var e=f.createElement("canvas"),i=e.getContext("2d");if(i)try{return i.fillStyle=t,i.fillStyle}finally{null==e.remove||e.remove.call(e)}throw new Error("Failed to get 2D context for color conversion!")}(t))}var R=function(){function t(){}var e=t.prototype;return e.computeLines=function(t,e,i,n,r,a,o,l){var s=this,h=[],c=[],u=(n.lineHeight||0)*a,f=this.createNewLine(),g=0,x=0,p=function(){if(0!==f.chars.length){f.lineHeight=0===h.length?(f.lineAscent||0)+(f.lineDescent||0):u;var t=0===h.length?0:c[c.length-1]+u;c.push(t),x+=f.lineHeight,h.push(f),g=Math.max(g,f.width),f=s.createNewLine()}};t.forEach((function(t){var n=t.text,r=t.isNewLine,s=t.fontSize;r&&p();var h=t.fontStyle||i.fontStyle||"normal";e.font=h+" "+(t.fontWeight||i.textWeight)+" 10px "+(t.fontFamily||i.fontFamily),f.offsetX.push(f.width);for(var c=0,u=[],g=0,x=0,v=0;v<n.length;v++){var d=n[v],m=e.measureText(d),y=m.width,S=(y<=0?0:y)*s*l*a,T=s*a*l,w=m.actualBoundingBoxAscent*T,b=m.actualBoundingBoxDescent*T;g=Math.max(g,w),x=Math.max(x,b),v>0&&(c+=o),u.push({char:d,x:c}),c+=S}f.chars.push(u),f.width+=c,f.richOptions.push(t),f.lineAscent=Math.max(f.lineAscent||0,g),f.lineDescent=Math.max(f.lineDescent||0,x)})),p();var v=1/0,d=-1/0;if(0===h.length)return{lines:h,maxLineWidth:g,totalHeight:x,bboxTop:0,bboxBottom:0,bboxHeight:0};for(var m=0;m<h.length;m++)v=Math.min(v,c[m]-(h[m].lineAscent||0)),d=Math.max(d,c[m]+(h[m].lineDescent||0));return{lines:h,maxLineWidth:g,totalHeight:x,bboxTop:v,bboxBottom:d,bboxHeight:d-v}},e.createNewLine=function(){return{richOptions:[],offsetX:[],width:0,lineHeight:0,offsetY:0,chars:[],lineAscent:0,lineDescent:0}},t}(),F=function(){function t(){}var e=t.prototype;return e.computeLines=function(t,e,i,n,r,a,o,l){var s=this,h=[],c=[],u=(n.lineHeight||0)*a,f=this.createNewLine(),g=0,x=0,p=null,v=0,d=[],m=null,y=function(){if(S(),0!==f.chars.length){f.lineHeight=0===h.length?(f.lineAscent||0)+(f.lineDescent||0):u;var t=0===h.length?0:c[c.length-1]+u;c.push(t),x+=f.lineHeight,h.push(f),g=Math.max(g,f.width),f=s.createNewLine(),p=null,v=0,d=[],m=null}},S=function(){0!==d.length&&(null===p&&(p=f.width),f.offsetX.push(p),f.chars.push(d),m&&f.richOptions.push(m),p=null,v=0,d=[],m=null)};t.forEach((function(t){var r=t.text,s=t.isNewLine,h=t.fontSize,c=t.fontStyle||i.fontStyle||"normal";e.font=c+" "+(t.fontWeight||i.textWeight)+" 10px "+(t.fontFamily||i.fontFamily),s&&(S(),y());for(var u=0;u<r.length;u++){var g=r[u],x=e.measureText(g),T=x.width,w=(T<=0?0:T)*h*l*a,b=h*a*l,A=x.actualBoundingBoxAscent*b,O=x.actualBoundingBoxDescent*b,C=d.length>0?o:0;f.width+C+w>(n.maxTextWidth||1/0)&&(S(),y()),null===p&&(p=f.width,m=t),d.length>0&&(v+=o,f.width+=o),d.push({char:g,x:v}),f.lineAscent=Math.max(f.lineAscent||0,A),f.lineDescent=Math.max(f.lineDescent||0,O),v+=w,f.width+=w}S()})),y();for(var T=1/0,w=-1/0,b=0;b<h.length;b++)T=Math.min(T,c[b]-(h[b].lineAscent||0)),w=Math.max(w,c[b]+(h[b].lineDescent||0));return{lines:h,maxLineWidth:g,totalHeight:x,bboxTop:T,bboxBottom:w,bboxHeight:w-T}},e.createNewLine=function(){return{richOptions:[],offsetX:[],width:0,lineHeight:0,offsetY:0,chars:[],lineAscent:0,lineDescent:0}},t}(),D=function(){function t(){}return t.prototype.apply=function(t,e,i,n){var r,a,o=function(t,e){return Math.abs(e)>1e-5?t/e:1},l=i.maxTextWidth*n.fontScale,s=i.maxTextHeight*n.fontScale,h=Math.max(1,null!=(r=e.contentWidth)?r:e.canvasWidth),c=Math.max(1,null!=(a=e.bboxHeight)?a:e.canvasHeight),u=Math.min(1,o(l,h),o(s,c));if(u>.9999)return{globalScale:1};for(var f,g=w(t);!(f=g()).done;){var x=f.value;if(x.width*=u,x.lineHeight*=u,x.offsetX)for(var p=0;p<x.offsetX.length;p++)x.offsetX[p]*=u;for(var v,d=w(x.chars||[]);!(v=d()).done;)for(var m,y=w(v.value);!(m=y()).done;){m.value.x*=u}for(var S,T=w(x.richOptions||[]);!(S=T()).done;){S.value.fontSize*=u}null!=x.lineAscent&&(x.lineAscent*=u),null!=x.lineDescent&&(x.lineDescent*=u)}return{globalScale:u}},t}(),B=function(){function t(){}return t.prototype.apply=function(t,e,i,n){return{globalScale:1}},t}(),_=function(){function t(){}return t.prototype.apply=function(t,e,i,n){return{globalScale:1}},t}(),X=function(){function t(){}return t.prototype.getHorizontalOffsets=function(t,e,n,r,a){var o,l,s=null!=(o=e.containerWidth)?o:r.maxTextWidth*a.fontScale,h=null!=(l=e.baselineCompensationX)?l:0,c=t.map((function(t){return r.getOffsetXRich(a,s,t.width)}));return{lineOffsets:r.overflow===i.TextOverflow.visible?c.map((function(t){return t+h})):c}},t}(),Y=function(){function t(){}return t.prototype.getVerticalOffsets=function(t,e,n,r,a,o){var l,s=null!=(l=e.baselineCompensationY)?l:0,h=0;if(0===t.length)return{baselineY:0,lineYOffsets:[]};switch(r.overflow){case i.TextOverflow.visible:var c,u,f,g,x=r.maxTextHeight*a.fontScale,p=null!=(c=e.bboxTop)?c:0,v=null!=(f=e.bboxBottom)?f:p+(null!=(u=e.bboxHeight)?u:0),d=null!=(g=e.bboxHeight)?g:v-p,m=0;switch(r.textVerticalAlign){case i.TextVerticalAlign.top:m=-p;break;case i.TextVerticalAlign.middle:m=(x-d)/2-p;break;case i.TextVerticalAlign.bottom:m=x-d-p}h=m+s;break;case i.TextOverflow.clip:for(var y=r.maxTextHeight*a.fontScale,S=[0],T=1;T<t.length;T++)S[T]=S[T-1]+t[T].lineHeight;for(var w=1/0,b=-1/0,A=0;A<t.length;A++){var O,C,z=null!=(O=t[A].lineAscent)?O:0,L=null!=(C=t[A].lineDescent)?C:0;w=Math.min(w,S[A]-z),b=Math.max(b,S[A]+L)}var H=b-w,E=0;switch(r.textVerticalAlign){case i.TextVerticalAlign.top:E=-w;break;case i.TextVerticalAlign.middle:E=(y-H)/2-w;break;case i.TextVerticalAlign.bottom:E=y-H-w}h=E+s;break;case i.TextOverflow.display:for(var W=r.maxTextHeight*a.fontScale,V=[0],M=1;M<t.length;M++)V[M]=V[M-1]+t[M].lineHeight;for(var k=1/0,R=-1/0,F=0;F<t.length;F++){var D,B,_=null!=(D=t[F].lineAscent)?D:0,X=null!=(B=t[F].lineDescent)?B:0;k=Math.min(k,V[F]-_),R=Math.max(R,V[F]+X)}var Y=R-k,P=0;switch(r.textVerticalAlign){case i.TextVerticalAlign.top:P=-k;break;case i.TextVerticalAlign.middle:P=(W-Y)/2-k;break;case i.TextVerticalAlign.bottom:P=W-Y-k}for(var N=[],j=P,I=0;I<t.length;I++)N.push(j),I<t.length-1&&(j+=t[I+1].lineHeight);return{baselineY:P,lineYOffsets:N}}var U=[],$=h;return t.forEach((function(e,i){U.push($),i<t.length-1&&($+=t[i+1].lineHeight)})),{baselineY:h,lineYOffsets:U}},t}(),P=function(){function t(){}return t.createWrapStrategy=function(t){return t?new F:new R},t.createOverflowStrategy=function(t){switch(t){case i.TextOverflow.clip:return new B;case i.TextOverflow.display:return new D;case i.TextOverflow.visible:default:return new _}},t.createHorizontalAlignStrategy=function(){return new X},t.createVerticalAlignStrategy=function(){return new Y},t}(),N=0,j=function(t){function e(e){var n;return(n=t.call(this,e)||this).isDirty=!0,n.text="",n.processedTextOptions=[],n.singleLineHeight=1.571,n.size=null,n.initialized=!1,n.canvasSize=null,n.SCALE_FACTOR=.1,n.ALPHA_FIX_VALUE=1/255,n.name="MRichText"+N++,n.initTextBase(e),n.richWrapStrategy=P.createWrapStrategy(),n.richOverflowStrategy=P.createOverflowStrategy(i.TextOverflow.display),n.richHorizontalAlignStrategy=P.createHorizontalAlignStrategy(),n.richVerticalAlignStrategy=P.createVerticalAlignStrategy(),n}x(e,t);var n=e.prototype;return n.onUpdate=function(e){t.prototype.onUpdate.call(this,e),this.updateTexture()},n.onDestroy=function(){t.prototype.onDestroy.call(this),this.disposeTextTexture()},n.fromData=function(e){t.prototype.fromData.call(this,e);var n=e.interaction,r=e.options;this.interaction=n,this.textStyle=new o(r),this.textLayout=new V(r),this.text=r.text?r.text.toString():" ",this.textLayout.useLegacyRichText&&(this.textLayout.textVerticalAlign=i.TextVerticalAlign.middle),this.updateStrategies(),this.renderText(r),this.material.setColor("_Color",new l.Color(1,1,1,1))},n.updateStrategies=function(){var t=this.textLayout;t&&(this.richWrapStrategy=P.createWrapStrategy(t.wrapEnabled),this.richOverflowStrategy=P.createOverflowStrategy(t.overflow))},n.generateTextProgram=function(t){var e=this;this.processedTextOptions=[];var n=L((function(t,n){/^\n+$/.test(t)&&(t=t.replace(/\n/g,"\n ")),t.split("\n").forEach((function(t,r){var a={text:t,fontSize:e.textStyle.fontSize,isNewLine:!1};r>0&&(a.isNewLine=!0),"b"in n&&(a.fontWeight=i.TextWeight.bold),"i"in n&&(a.fontStyle=i.FontStyle.italic),"size"in n&&n.size&&(a.fontSize=parseInt(n.size,10)),"color"in n&&n.color&&(a.fontColor=k(n.color)),e.processedTextOptions.push(a)}))}));n(t)},n.updateWithOptions=function(t){this.textStyle=new o(t),this.textLayout=new V(t),this.text=t.text?t.text.toString():" ",this.textLayout.useLegacyRichText&&(this.textLayout.textVerticalAlign=i.TextVerticalAlign.middle),this.updateStrategies(),this.isDirty=!0},n.renderText=function(t){var e=t.size;e&&(this.canvasSize=new l.Vector2(e[0],e[1])),this.updateTexture()},n.updateTexture=function(t){if(void 0===t&&(t=!0),this.isDirty&&this.context&&this.canvas&&this.textStyle&&this.textLayout){var e=!0===this.textLayout.useLegacyRichText;this.singleLineHeight=e?1.571:1,e?this.updateTextureLegacy(t):this.updateTextureWithStrategies(t)}},n.updateTextureLegacy=function(t){var e=this;if(this.isDirty&&this.context&&this.canvas&&this.textStyle){this.generateTextProgram(this.text);var n=0,r=0,a=this.textLayout,o=this.textStyle,h=a.overflow,c=a.letterSpace,u=void 0===c?0:c,f=this.context,g=[],x=o.fontSize*o.fontScale,p={richOptions:[],offsetX:[],width:0,lineHeight:x*this.singleLineHeight,offsetY:x*(this.singleLineHeight-1)/2};if(this.processedTextOptions.forEach((function(t){var i=t.text,a=t.isNewLine,l=t.fontSize;a&&(g.push(p),n=Math.max(n,p.width),p={richOptions:[],offsetX:[],width:0,lineHeight:x*e.singleLineHeight,offsetY:x*(e.singleLineHeight-1)/2},r+=p.lineHeight),f.font=(t.fontWeight||o.textWeight)+" 10px "+(t.fontFamily||o.fontFamily);var s=f.measureText(i),h=s.width;if(void 0!==s.actualBoundingBoxLeft&&void 0!==s.actualBoundingBoxRight){var c=s.actualBoundingBoxLeft+s.actualBoundingBoxRight;c>0&&(h=Math.max(h,c))}var v=l*e.singleLineHeight*o.fontScale;v>p.lineHeight&&(r+=v-p.lineHeight,p.lineHeight=v,p.offsetY=l*o.fontScale*(e.singleLineHeight-1)/2),p.offsetX.push(p.width),p.width+=(h<=0?0:h)*l*e.SCALE_FACTOR*o.fontScale+i.length*u,p.richOptions.push(t)})),g.push(p),n=Math.max(n,p.width),r+=p.lineHeight,0!==n&&0!==r){void 0!==this.size&&null!==this.size||(this.size=this.item.transform.size.clone());var v=this.size,d=v.x,m=void 0===d?1:d,y=v.y,S=void 0===y?1:y;if(!this.initialized){this.canvasSize=this.canvasSize?this.canvasSize:new l.Vector2(n,r);var T=this.canvasSize,w=T.x,b=T.y;this.item.transform.size.set(m*w*this.SCALE_FACTOR*this.SCALE_FACTOR,S*b*this.SCALE_FACTOR*this.SCALE_FACTOR),this.size=this.item.transform.size.clone(),this.initialized=!0}s(this.canvasSize);var A=this.canvasSize,O=A.x,C=A.y;a.width=O/o.fontScale,a.height=C/o.fontScale,this.renderToTexture(O,C,t,(function(t){if(0!==g.length){var n=a.getOffsetY(o,g.length,x*e.singleLineHeight,o.fontSize);g.forEach((function(e,r){var l=e.richOptions,s=e.offsetX,c=e.width,u=c,f=s;if(h===i.TextOverflow.display&&c>O){var g=O/c;u*=g,f=s.map((function(t){return t*g}))}var x=a.getOffsetX(o,u);r>0&&(n+=e.lineHeight-e.offsetY),l.forEach((function(e,r){var a=o.fontScale,l=o.textColor,s=o.fontFamily,u=o.textWeight,g=o.fontStyle,p=e.text,v=e.fontSize,d=e.fontColor,m=void 0===d?l:d,y=e.fontFamily,S=void 0===y?s:y,T=e.fontWeight,w=void 0===T?u:T,b=e.fontStyle,A=void 0===b?g:b,C=v;h===i.TextOverflow.display&&c>O&&(C/=c/O);var z=f[r]+x;t.font=A+" "+w+" "+C*a+"px "+S;var L=m[0],H=m[1],E=m[2],W=m[3];t.fillStyle="rgba("+L+", "+H+", "+E+", "+W+")",t.fillText(p,z,n)}))}))}}),{disposeOld:!1}),this.isDirty=!1}else this.isDirty=!1}},n.updateTextureWithStrategies=function(t){var e=this;if(this.isDirty&&this.context&&this.canvas){this.generateTextProgram(this.text);var i=this.textLayout,n=i.letterSpace,r=void 0===n?0:n,a=this.context;if(a){var o=this.richWrapStrategy.computeLines(this.processedTextOptions,a,this.textStyle,i,this.singleLineHeight,this.textStyle.fontScale,r,this.SCALE_FACTOR);if(0!==o.lines.length&&0!==o.maxLineWidth&&0!==o.totalHeight){var l=this.resolveCanvasSize(o,i,this.textStyle,this.singleLineHeight);this.setCanvasSize(l);var h=this.richOverflowStrategy.apply(o.lines,l,i,this.textStyle),c=this.richHorizontalAlignStrategy.getHorizontalOffsets(o.lines,l,h,i,this.textStyle),u=this.richVerticalAlignStrategy.getVerticalOffsets(o.lines,l,h,i,this.textStyle,this.singleLineHeight);s(this.canvasSize);var f=this.canvasSize,g=f.x,x=f.y,p=Math.max(1,Math.ceil(g)),v=Math.max(1,Math.ceil(x));i.width=p/this.textStyle.fontScale,i.height=v/this.textStyle.fontScale,this.renderToTexture(p,v,t,(function(t){e.drawTextWithStrategies(t,o.lines,c,u,h,e.textStyle)}),{disposeOld:!1}),this.isDirty=!1}else this.isDirty=!1}}},n.setCanvasSize=function(t){var e=this;void 0!==this.size&&null!==this.size||(this.size=this.item.transform.size.clone());var n=this.size,r=n.x,a=void 0===r?1:r,o=n.y,s=void 0===o?1:o,h=this.textLayout,c=this.textStyle.fontScale||1,u=Math.max(1,h.maxTextWidth||0),f=Math.max(1,h.maxTextHeight||0);switch(h.overflow){case i.TextOverflow.visible:var g,x,p,v,d=u*c,m=f*c,y=null!=(g=t.bboxTop)?g:0,S=null!=(p=t.bboxBottom)?p:y+(null!=(x=t.bboxHeight)?x:0),T=null!=(v=t.bboxHeight)?v:S-y,w=0;switch(h.textVerticalAlign){case i.TextVerticalAlign.top:w=-y;break;case i.TextVerticalAlign.middle:w=(m-T)/2-y;break;case i.TextVerticalAlign.bottom:w=m-T-y}var b=w+y,A=w+S,O=Math.max(0,-b),C=Math.max(0,A-m),z=O,L=C;switch(h.textVerticalAlign){case i.TextVerticalAlign.top:z=C,L=C;break;case i.TextVerticalAlign.bottom:z=O,L=O;break;case i.TextVerticalAlign.middle:z=O,L=C}for(var H=z,E=t.lines||[],W=E.map((function(t){return h.getOffsetXRich(e.textStyle,d,t.width)})),V=1/0,M=-1/0,k=0;k<E.length;k++){var R,F,D=null!=(R=W[k])?R:0,B=null!=(F=E[k].width)?F:0;V=Math.min(V,D),M=Math.max(M,D+B)}isFinite(V)||(V=0),isFinite(M)||(M=0);var _,X=Math.max(0,-V),Y=Math.max(0,M-d),P=Math.ceil(d+X+Y),N=Math.ceil(m+z+L);t.baselineCompensationX=X,t.baselineCompensationY=H,t.containerWidth=d,t.canvasWidth=P,t.canvasHeight=N,this.canvasSize=new l.Vector2(P,N);var j=null!=(_=this.size)?_:this.item.transform.size,I=j.x,U=void 0===I?1:I,$=j.y,q=void 0===$?1:$;this.item.transform.size.set(U*P*this.SCALE_FACTOR*this.SCALE_FACTOR,q*N*this.SCALE_FACTOR*this.SCALE_FACTOR),this.initialized=!0;break;case i.TextOverflow.clip:var G,J=u*c,K=f*c;t.canvasWidth=J,t.canvasHeight=K,t.baselineCompensationX=0,t.baselineCompensationY=0,this.canvasSize=new l.Vector2(J,K),h.width=u,h.height=f;var Q=null!=(G=this.size)?G:this.item.transform.size,Z=Q.x,tt=void 0===Z?1:Z,et=Q.y,it=void 0===et?1:et;this.item.transform.size.set(tt*J*this.SCALE_FACTOR*this.SCALE_FACTOR,it*K*this.SCALE_FACTOR*this.SCALE_FACTOR),this.initialized=!0;break;case i.TextOverflow.display:if(!this.initialized){var nt=u*c,rt=f*c;this.canvasSize=new l.Vector2(nt,rt),this.item.transform.size.set(a*nt*this.SCALE_FACTOR*this.SCALE_FACTOR,s*rt*this.SCALE_FACTOR*this.SCALE_FACTOR),this.initialized=!0}}},n.resolveCanvasSize=function(t,e,i,n){var r=Math.max(1,t.maxLineWidth||0),a=Math.max(1,t.totalHeight||0);return e.width=r/i.fontScale,e.height=a/i.fontScale,{canvasWidth:r,canvasHeight:a,contentWidth:t.maxLineWidth,bboxTop:t.bboxTop,bboxBottom:t.bboxBottom,bboxHeight:t.bboxHeight,lines:t.lines}},n.drawTextWithStrategies=function(t,e,i,n,r,a){var o=n.baselineY,l=i.lineOffsets;e.forEach((function(i,n){var r=i.richOptions,s=i.chars,h=l[n],c=o;r.forEach((function(e,n){var r=a.fontScale,o=a.textColor,l=a.fontFamily,u=a.textWeight,f=a.fontStyle,g=e.fontSize,x=e.fontColor,p=void 0===x?o:x,v=e.fontFamily,d=void 0===v?l:v,m=e.fontWeight,y=void 0===m?u:m,S=e.fontStyle,T=void 0===S?f:S,w=g;t.font=T+" "+y+" "+w*r+"px "+d;var b=p[0],A=p[1],O=p[2],C=p[3];t.fillStyle="rgba("+b+", "+A+", "+O+", "+C+")";var z=i.offsetX&&i.offsetX[n]?i.offsetX[n]:0;s[n].forEach((function(e){t.fillText(e.char,h+z+e.x,c)}))})),n<e.length-1&&(o+=e[n+1].lineHeight)}))},n.unsupported=function(t){throw new Error("RichTextComponent does not support "+t+" at runtime.")},n.setShadowOffsetY=function(t){this.unsupported("setShadowOffsetY")},n.setShadowBlur=function(t){this.unsupported("setShadowBlur")},n.setShadowOffsetX=function(t){this.unsupported("setShadowOffsetX")},n.setShadowColor=function(t){this.unsupported("setShadowColor")},n.setOutlineWidth=function(t){this.unsupported("setOutlineWidth")},n.setAutoWidth=function(t){this.unsupported("setAutoWidth")},n.setFontSize=function(t){this.unsupported("setFontSize")},n.setTextBaseline=function(t){console.warn("setTextBaseline 已废弃,请改用 setTextVerticalAlign。本次调用将转调用 setTextVerticalAlign。"),this.setTextVerticalAlign(t)},e}(h);r(j=function(t,e,i,n){var r,a=arguments.length,o=a<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,i):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,e,i,n);else for(var l=t.length-1;l>=0;l--)(r=t[l])&&(o=(a<3?r(o):a>3?r(e,i,o):r(e,i))||o);return a>3&&o&&Object.defineProperty(e,i,o),o}([n(i.DataType.RichTextComponent)],j),[a]);var I="2.8.4";c("rich-text",S),u.info("Plugin rich text version: 2.8.4."),I!==t.version&&console.error("注意:请统一 RichText 插件与 Player 版本,不统一的版本混用会有不可预知的后果!","\nAttention: Please ensure the RichText plugin is synchronized with the Player version. Mixing and matching incompatible versions may result in unpredictable consequences!");export{j as RichTextComponent,S as RichTextLoader,E as escape,L as generateProgram,H as isRichText,C as lexer,z as richTextParser,W as unescape,I as version};
1
+ import*as t from"@galacean/effects/douyin";import{Plugin as e,spec as i,effectsClass as n,applyMixins as r,TextComponentBase as a,TextStyle as o,math as l,assertExist as s,MaskableGraphic as h,registerPlugin as c,logger as u}from"@galacean/effects/douyin";import{document as f}from"@galacean/appx-adapter/douyin";function g(t,e){return g=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},g(t,e)}function x(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&&g(t,e)}function p(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(p=function(){return!!t})()}function v(t,e,i){return v=p()?Reflect.construct:function(t,e,i){var n=[null];n.push.apply(n,e);var r=new(Function.bind.apply(t,n));return i&&g(r,i.prototype),r},v.apply(null,arguments)}function d(t){return d=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},d(t)}function m(t){var e="function"==typeof Map?new Map:void 0;return m=function(t){if(null===t||(i=t,-1===Function.toString.call(i).indexOf("[native code]")))return t;var i;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,n)}function n(){return v(t,arguments,d(this).constructor)}return n.prototype=Object.create(t.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),g(n,t)},m(t)}var y,S=function(t){function e(){var e;return(e=t.apply(this,arguments)||this).name="rich-text",e}return x(e,t),e}(m(e));function T(t,e){(null==e||e>t.length)&&(e=t.length);for(var i=0,n=new Array(e);i<e;i++)n[i]=t[i];return n}function w(t,e){var i="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(i)return(i=i.call(t)).next.bind(i);if(Array.isArray(t)||(i=function(t,e){if(t){if("string"==typeof t)return T(t,e);var i=Object.prototype.toString.call(t).slice(8,-1);return"Object"===i&&t.constructor&&(i=t.constructor.name),"Map"===i||"Set"===i?Array.from(i):"Arguments"===i||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i)?T(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){i&&(t=i);var n=0;return function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}!function(t){t.ContextStart="ContextStart",t.Text="Text",t.ContextEnd="ContextEnd",t.EscapedChar="EscapedChar"}(y||(y={}));var b=/^<([a-z]+)(=([^>]+))?>$/,A=/^<\/([a-z]+)>$/,O=[["EscapedChar",/^\\([=<>\\/])/],["ContextStart",/^<[a-z]+(=[^>]+)?>/],["ContextEnd",/^<\/[a-z]+>/],["Text",/^[^</>=\\]+/]],C=function(t,e,i){if(void 0===e&&(e=[]),void 0===i&&(i=0),!t)return e;var n=/^\\([=<>\\/])/.exec(t);if(n){var r=n[1];return C(t.slice(2),e.concat({tokenType:"Text",value:r}),i+2)}for(var a,o=w(O);!(a=o()).done;){var l=a.value,s=l[0],h=l[1];if("EscapedChar"!==s){var c=h.exec(t);if(c){var u=c[0],f=u.length;return C(t.slice(f),e.concat({tokenType:s,value:u}),i+f)}}}if(t.length>0)return C(t.slice(1),e.concat({tokenType:"Text",value:t[0]}),i+1);throw new Error('Unexpected token: "'+t[0]+'" at position '+i+' while reading "'+t+'"')},z=function(t){var e=function(){for(var t,e="",i=!1;r.length>0&&"Text"===(null==(t=r[0])?void 0:t.tokenType);){var n=o();n&&(e+=n.value,i=!0)}return i?e:void 0},i=function(){var t=l();if("ContextStart"===(null==t?void 0:t.tokenType)){o();var e,i=t.value.match(b);if(i)return{attributeName:i[1],attributeParam:null!=(e=i[3])?e:""};throw new Error("Expected a start tag marker at position "+a)}return{}},n=function(){var t=l();if("ContextEnd"===(null==t?void 0:t.tokenType)){o();var e=t.value.match(A);if(e)return{attributeName:e[1]};throw new Error("Expect an end tag marker at position "+a)}return{}},r=C(t),a=0,o=function(){var t,e=r.shift();return a+=null!=(t=null==e?void 0:e.value.length)?t:0,e},l=function(){return r[0]},s=[];return function t(r,o){for(void 0===r&&(r=[]),void 0===o&&(o="");;){var l=e();if(l)s.push({attributes:r,text:l});else{var h=i(),c=h.attributeName,u=h.attributeParam;if(!c){if(o){var f=n().attributeName;if(!f)throw new Error('Expect an end tag marker "'+o+'" at position '+a+" but found no tag!");if(f!==o)throw new Error('Expect an end tag marker "'+o+'" at position '+a+' but found tag "'+f+'"');return}break}t(r.concat({attributeName:c,attributeParam:null!=u?u:""}),c)}}}(),s};function L(t){return function(e){for(var i,n=w(z(e));!(i=n()).done;){var r=i.value,a=r.text,o=r.attributes.reduce((function(t,e){var i=e.attributeName,n=e.attributeParam;return i&&(t[i]=n),t}),{});t(a,o)}}}function H(t){var e=C(t).filter((function(t){var e=t.tokenType;return"ContextStart"===e||"ContextEnd"===e})),i=e.filter((function(t){return"ContextStart"===t.tokenType})),n=e.filter((function(t){return"ContextEnd"===t.tokenType}));if(i.length!==n.length||!i.length)return!1;return function t(e,i){var n=e[0],r=e.slice(1);if(void 0===i&&(i=[]),!n)return 0===i.length;if("ContextStart"===n.tokenType)return t(r,i.concat(n.value));if("ContextEnd"===n.tokenType)return i[i.length-1]===n.value&&t(r,i.slice(0,-1));throw new Error("Unexpected token: "+n.tokenType)}(e.map((function(t){var e=t.tokenType,i=t.value;return{tokenType:e,value:"ContextStart"===e?i.match(b)[1]:i.match(A)[1]}})))}function E(t){if("string"!=typeof t)throw new Error("Input must be a string");return t.replace(/\\/g,"\\\\").replace(/=/g,"\\=").replace(/</g,"\\<").replace(/>/g,"\\>").replace(/\//g,"\\/")}function W(t){if("string"!=typeof t)throw new Error("Input must be a string");return t.replace(/\\\//g,"/").replace(/\\>/g,">").replace(/\\</g,"<").replace(/\\=/g,"=").replace(/\\\\/g,"\\")}"function"==typeof SuppressedError&&SuppressedError;var V=function(){function t(t){this.width=0,this.height=0;var e=t.size,n=t.textOverflow,r=void 0===n?i.TextOverflow.clip:n,a=t.textVerticalAlign,o=void 0===a?i.TextVerticalAlign.middle:a,l=t.textAlign,s=void 0===l?i.TextAlignment.left:l,h=t.letterSpace,c=void 0===h?0:h,u=t.lineHeight,f=void 0===u?.571:u,g=t.wrapEnabled,x=void 0!==g&&g,p=t.maxTextWidth,v=void 0===p?350:p,d=t.maxTextHeight,m=void 0===d?1e3:d,y=t.sizeMode,S=void 0===y?i.TextSizeMode.autoWidth:y,T=t.useLegacyRichText,w=void 0!==T&&T;this.letterSpace=c,this.lineHeight=f,this.useLegacyRichText=w,this.overflow=r,this.textVerticalAlign=o,this.textAlign=s,this.width=e?e[0]:100,this.height=e?e[1]:100,this.wrapEnabled=x;this.maxTextWidth=50*v,this.maxTextHeight=50*m,this.sizeMode=S}var e=t.prototype;return e.getOffsetY=function(t,e,n,r,a){var o=t.outlineWidth,l=t.fontScale,s=(n-r)/3,h=r+o*l,c=void 0!==a?a:n*(e-1),u=0;switch(this.textVerticalAlign){case i.TextVerticalAlign.top:u=h+s;break;case i.TextVerticalAlign.middle:u=(this.height*l-c+h)/2;break;case i.TextVerticalAlign.bottom:u=this.height*l-c-s}return u},e.getOffsetX=function(t,e){var n=0;switch(this.textAlign){case i.TextAlignment.left:n=t.outlineWidth*t.fontScale;break;case i.TextAlignment.middle:n=(this.width*t.fontScale-e)/2;break;case i.TextAlignment.right:n=this.width*t.fontScale-e}return n},e.getOffsetYRich=function(t,e,n){if(0===e.length)return 0;var r=t.outlineWidth,a=t.fontScale,o=e.reduce((function(t,e){return t+e}),0),l=(e[0]-n)/3,s=n+r*a,h=o-e[0],c=0;switch(this.textVerticalAlign){case i.TextVerticalAlign.top:c=s+l;break;case i.TextVerticalAlign.middle:c=(this.height*a-o)/2+s;break;case i.TextVerticalAlign.bottom:c=this.height*a-h-l}return c},e.getOffsetXRich=function(t,e,n){switch(this.textAlign){case i.TextAlignment.left:return t.outlineWidth*t.fontScale;case i.TextAlignment.middle:return(e-n)/2;case i.TextAlignment.right:return e-n;default:return 0}},e.setSize=function(t,e){this.width=t,this.height=e},t}();function M(t,e){if(void 0===e&&(e=1),3!==(t=t.replace(/^#/,"")).length&&4!==t.length||(t=t.split("").map((function(t){return t+t})).join("")),8===t.length){var i=parseInt(t.slice(6,8),16)/255;t=t.slice(0,6),e=i}var n=parseInt(t,16);return[n>>16&255,n>>8&255,255&n,e]}function k(t,e){if(void 0===e&&(e=1),"string"!=typeof t||!t)throw new Error("Invalid color string");return t.startsWith("#")?M(t,e):M(function(t){if("string"!=typeof t||!t)throw new Error("Invalid color name provided");if(void 0===f)throw new Error("This method requires a browser environment");var e=f.createElement("canvas"),i=e.getContext("2d");if(i)try{return i.fillStyle=t,i.fillStyle}finally{null==e.remove||e.remove.call(e)}throw new Error("Failed to get 2D context for color conversion!")}(t))}var R=function(){function t(){}var e=t.prototype;return e.computeLines=function(t,e,i,n,r,a,o,l){var s=this,h=[],c=[],u=(n.lineHeight||0)*a,f=this.createNewLine(),g=0,x=0,p=function(){if(0!==f.chars.length){f.lineHeight=0===h.length?(f.lineAscent||0)+(f.lineDescent||0):u;var t=0===h.length?0:c[c.length-1]+u;c.push(t),x+=f.lineHeight,h.push(f),g=Math.max(g,f.width),f=s.createNewLine()}};t.forEach((function(t){var n=t.text,r=t.isNewLine,s=t.fontSize;r&&p();var h=t.fontStyle||i.fontStyle||"normal";e.font=h+" "+(t.fontWeight||i.textWeight)+" 10px "+(t.fontFamily||i.fontFamily),f.offsetX.push(f.width);for(var c=0,u=[],g=0,x=0,v=0;v<n.length;v++){var d=n[v],m=e.measureText(d),y=m.width,S=(y<=0?0:y)*s*l*a,T=s*a*l,w=m.actualBoundingBoxAscent*T,b=m.actualBoundingBoxDescent*T;g=Math.max(g,w),x=Math.max(x,b),v>0&&(c+=o),u.push({char:d,x:c}),c+=S}f.chars.push(u),f.width+=c,f.richOptions.push(t),f.lineAscent=Math.max(f.lineAscent||0,g),f.lineDescent=Math.max(f.lineDescent||0,x)})),p();var v=1/0,d=-1/0;if(0===h.length)return{lines:h,maxLineWidth:g,totalHeight:x,bboxTop:0,bboxBottom:0,bboxHeight:0};for(var m=0;m<h.length;m++)v=Math.min(v,c[m]-(h[m].lineAscent||0)),d=Math.max(d,c[m]+(h[m].lineDescent||0));return{lines:h,maxLineWidth:g,totalHeight:x,bboxTop:v,bboxBottom:d,bboxHeight:d-v}},e.createNewLine=function(){return{richOptions:[],offsetX:[],width:0,lineHeight:0,offsetY:0,chars:[],lineAscent:0,lineDescent:0}},t}(),F=function(){function t(){}var e=t.prototype;return e.computeLines=function(t,e,i,n,r,a,o,l){var s=this,h=[],c=[],u=(n.lineHeight||0)*a,f=this.createNewLine(),g=0,x=0,p=null,v=0,d=[],m=null,y=function(){if(S(),0!==f.chars.length){f.lineHeight=0===h.length?(f.lineAscent||0)+(f.lineDescent||0):u;var t=0===h.length?0:c[c.length-1]+u;c.push(t),x+=f.lineHeight,h.push(f),g=Math.max(g,f.width),f=s.createNewLine(),p=null,v=0,d=[],m=null}},S=function(){0!==d.length&&(null===p&&(p=f.width),f.offsetX.push(p),f.chars.push(d),m&&f.richOptions.push(m),p=null,v=0,d=[],m=null)};t.forEach((function(t){var r=t.text,s=t.isNewLine,h=t.fontSize,c=t.fontStyle||i.fontStyle||"normal";e.font=c+" "+(t.fontWeight||i.textWeight)+" 10px "+(t.fontFamily||i.fontFamily),s&&(S(),y());for(var u=0;u<r.length;u++){var g=r[u],x=e.measureText(g),T=x.width,w=(T<=0?0:T)*h*l*a,b=h*a*l,A=x.actualBoundingBoxAscent*b,O=x.actualBoundingBoxDescent*b,C=d.length>0?o:0;f.width+C+w>(n.maxTextWidth||1/0)&&(S(),y()),null===p&&(p=f.width,m=t),d.length>0&&(v+=o,f.width+=o),d.push({char:g,x:v}),f.lineAscent=Math.max(f.lineAscent||0,A),f.lineDescent=Math.max(f.lineDescent||0,O),v+=w,f.width+=w}S()})),y();for(var T=1/0,w=-1/0,b=0;b<h.length;b++)T=Math.min(T,c[b]-(h[b].lineAscent||0)),w=Math.max(w,c[b]+(h[b].lineDescent||0));return{lines:h,maxLineWidth:g,totalHeight:x,bboxTop:T,bboxBottom:w,bboxHeight:w-T}},e.createNewLine=function(){return{richOptions:[],offsetX:[],width:0,lineHeight:0,offsetY:0,chars:[],lineAscent:0,lineDescent:0}},t}(),D=function(){function t(){}return t.prototype.apply=function(t,e,i,n){var r,a,o=function(t,e){return Math.abs(e)>1e-5?t/e:1},l=i.maxTextWidth*n.fontScale,s=i.maxTextHeight*n.fontScale,h=Math.max(1,null!=(r=e.contentWidth)?r:e.canvasWidth),c=Math.max(1,null!=(a=e.bboxHeight)?a:e.canvasHeight),u=Math.min(1,o(l,h),o(s,c));if(u>.9999)return{globalScale:1};for(var f,g=w(t);!(f=g()).done;){var x=f.value;if(x.width*=u,x.lineHeight*=u,x.offsetX)for(var p=0;p<x.offsetX.length;p++)x.offsetX[p]*=u;for(var v,d=w(x.chars||[]);!(v=d()).done;)for(var m,y=w(v.value);!(m=y()).done;){m.value.x*=u}for(var S,T=w(x.richOptions||[]);!(S=T()).done;){S.value.fontSize*=u}null!=x.lineAscent&&(x.lineAscent*=u),null!=x.lineDescent&&(x.lineDescent*=u)}return{globalScale:u}},t}(),B=function(){function t(){}return t.prototype.apply=function(t,e,i,n){return{globalScale:1}},t}(),_=function(){function t(){}return t.prototype.apply=function(t,e,i,n){return{globalScale:1}},t}(),X=function(){function t(){}return t.prototype.getHorizontalOffsets=function(t,e,n,r,a){var o,l,s=null!=(o=e.containerWidth)?o:r.maxTextWidth*a.fontScale,h=null!=(l=e.baselineCompensationX)?l:0,c=t.map((function(t){return r.getOffsetXRich(a,s,t.width)}));return{lineOffsets:r.overflow===i.TextOverflow.visible?c.map((function(t){return t+h})):c}},t}(),Y=function(){function t(){}return t.prototype.getVerticalOffsets=function(t,e,n,r,a,o){var l,s=null!=(l=e.baselineCompensationY)?l:0,h=0;if(0===t.length)return{baselineY:0,lineYOffsets:[]};switch(r.overflow){case i.TextOverflow.visible:var c,u,f,g,x=r.maxTextHeight*a.fontScale,p=null!=(c=e.bboxTop)?c:0,v=null!=(f=e.bboxBottom)?f:p+(null!=(u=e.bboxHeight)?u:0),d=null!=(g=e.bboxHeight)?g:v-p,m=0;switch(r.textVerticalAlign){case i.TextVerticalAlign.top:m=-p;break;case i.TextVerticalAlign.middle:m=(x-d)/2-p;break;case i.TextVerticalAlign.bottom:m=x-d-p}h=m+s;break;case i.TextOverflow.clip:for(var y=r.maxTextHeight*a.fontScale,S=[0],T=1;T<t.length;T++)S[T]=S[T-1]+t[T].lineHeight;for(var w=1/0,b=-1/0,A=0;A<t.length;A++){var O,C,z=null!=(O=t[A].lineAscent)?O:0,L=null!=(C=t[A].lineDescent)?C:0;w=Math.min(w,S[A]-z),b=Math.max(b,S[A]+L)}var H=b-w,E=0;switch(r.textVerticalAlign){case i.TextVerticalAlign.top:E=-w;break;case i.TextVerticalAlign.middle:E=(y-H)/2-w;break;case i.TextVerticalAlign.bottom:E=y-H-w}h=E+s;break;case i.TextOverflow.display:for(var W=r.maxTextHeight*a.fontScale,V=[0],M=1;M<t.length;M++)V[M]=V[M-1]+t[M].lineHeight;for(var k=1/0,R=-1/0,F=0;F<t.length;F++){var D,B,_=null!=(D=t[F].lineAscent)?D:0,X=null!=(B=t[F].lineDescent)?B:0;k=Math.min(k,V[F]-_),R=Math.max(R,V[F]+X)}var Y=R-k,P=0;switch(r.textVerticalAlign){case i.TextVerticalAlign.top:P=-k;break;case i.TextVerticalAlign.middle:P=(W-Y)/2-k;break;case i.TextVerticalAlign.bottom:P=W-Y-k}for(var N=[],j=P,I=0;I<t.length;I++)N.push(j),I<t.length-1&&(j+=t[I+1].lineHeight);return{baselineY:P,lineYOffsets:N}}var U=[],$=h;return t.forEach((function(e,i){U.push($),i<t.length-1&&($+=t[i+1].lineHeight)})),{baselineY:h,lineYOffsets:U}},t}(),P=function(){function t(){}return t.createWrapStrategy=function(t){return t?new F:new R},t.createOverflowStrategy=function(t){switch(t){case i.TextOverflow.clip:return new B;case i.TextOverflow.display:return new D;case i.TextOverflow.visible:default:return new _}},t.createHorizontalAlignStrategy=function(){return new X},t.createVerticalAlignStrategy=function(){return new Y},t}(),N=0,j=function(t){function e(e){var n;return(n=t.call(this,e)||this).isDirty=!0,n.text="",n.processedTextOptions=[],n.singleLineHeight=1.571,n.size=null,n.initialized=!1,n.canvasSize=null,n.SCALE_FACTOR=.1,n.ALPHA_FIX_VALUE=1/255,n.name="MRichText"+N++,n.initTextBase(e),n.richWrapStrategy=P.createWrapStrategy(),n.richOverflowStrategy=P.createOverflowStrategy(i.TextOverflow.display),n.richHorizontalAlignStrategy=P.createHorizontalAlignStrategy(),n.richVerticalAlignStrategy=P.createVerticalAlignStrategy(),n}x(e,t);var n=e.prototype;return n.onUpdate=function(e){t.prototype.onUpdate.call(this,e),this.updateTexture()},n.onDestroy=function(){t.prototype.onDestroy.call(this),this.disposeTextTexture()},n.fromData=function(e){t.prototype.fromData.call(this,e);var n=e.interaction,r=e.options;this.interaction=n,this.textStyle=new o(r),this.textLayout=new V(r),this.text=r.text?r.text.toString():" ",this.textLayout.useLegacyRichText&&(this.textLayout.textVerticalAlign=i.TextVerticalAlign.middle),this.updateStrategies(),this.renderText(r),this.material.setColor("_Color",new l.Color(1,1,1,1))},n.updateStrategies=function(){var t=this.textLayout;t&&(this.richWrapStrategy=P.createWrapStrategy(t.wrapEnabled),this.richOverflowStrategy=P.createOverflowStrategy(t.overflow))},n.generateTextProgram=function(t){var e=this;this.processedTextOptions=[];var n=L((function(t,n){/^\n+$/.test(t)&&(t=t.replace(/\n/g,"\n ")),t.split("\n").forEach((function(t,r){var a={text:t,fontSize:e.textStyle.fontSize,isNewLine:!1};r>0&&(a.isNewLine=!0),"b"in n&&(a.fontWeight=i.TextWeight.bold),"i"in n&&(a.fontStyle=i.FontStyle.italic),"size"in n&&n.size&&(a.fontSize=parseInt(n.size,10)),"color"in n&&n.color&&(a.fontColor=k(n.color)),e.processedTextOptions.push(a)}))}));n(t)},n.updateWithOptions=function(t){this.textStyle=new o(t),this.textLayout=new V(t),this.text=t.text?t.text.toString():" ",this.textLayout.useLegacyRichText&&(this.textLayout.textVerticalAlign=i.TextVerticalAlign.middle),this.updateStrategies(),this.isDirty=!0},n.renderText=function(t){var e=t.size;e&&(this.canvasSize=new l.Vector2(e[0],e[1])),this.updateTexture()},n.updateTexture=function(t){if(void 0===t&&(t=!0),this.isDirty&&this.context&&this.canvas&&this.textStyle&&this.textLayout){var e=!0===this.textLayout.useLegacyRichText;this.singleLineHeight=e?1.571:1,e?this.updateTextureLegacy(t):this.updateTextureWithStrategies(t)}},n.updateTextureLegacy=function(t){var e=this;if(this.isDirty&&this.context&&this.canvas&&this.textStyle){this.generateTextProgram(this.text);var n=0,r=0,a=this.textLayout,o=this.textStyle,h=a.overflow,c=a.letterSpace,u=void 0===c?0:c,f=this.context,g=[],x=o.fontSize*o.fontScale,p={richOptions:[],offsetX:[],width:0,lineHeight:x*this.singleLineHeight,offsetY:x*(this.singleLineHeight-1)/2};if(this.processedTextOptions.forEach((function(t){var i=t.text,a=t.isNewLine,l=t.fontSize;a&&(g.push(p),n=Math.max(n,p.width),p={richOptions:[],offsetX:[],width:0,lineHeight:x*e.singleLineHeight,offsetY:x*(e.singleLineHeight-1)/2},r+=p.lineHeight),f.font=(t.fontWeight||o.textWeight)+" 10px "+(t.fontFamily||o.fontFamily);var s=f.measureText(i),h=s.width;if(void 0!==s.actualBoundingBoxLeft&&void 0!==s.actualBoundingBoxRight){var c=s.actualBoundingBoxLeft+s.actualBoundingBoxRight;c>0&&(h=Math.max(h,c))}var v=l*e.singleLineHeight*o.fontScale;v>p.lineHeight&&(r+=v-p.lineHeight,p.lineHeight=v,p.offsetY=l*o.fontScale*(e.singleLineHeight-1)/2),p.offsetX.push(p.width),p.width+=(h<=0?0:h)*l*e.SCALE_FACTOR*o.fontScale+i.length*u,p.richOptions.push(t)})),g.push(p),n=Math.max(n,p.width),r+=p.lineHeight,0!==n&&0!==r){void 0!==this.size&&null!==this.size||(this.size=this.item.transform.size.clone());var v=this.size,d=v.x,m=void 0===d?1:d,y=v.y,S=void 0===y?1:y;if(!this.initialized){this.canvasSize=this.canvasSize?this.canvasSize:new l.Vector2(n,r);var T=this.canvasSize,w=T.x,b=T.y;this.item.transform.size.set(m*w*this.SCALE_FACTOR*this.SCALE_FACTOR,S*b*this.SCALE_FACTOR*this.SCALE_FACTOR),this.size=this.item.transform.size.clone(),this.initialized=!0}s(this.canvasSize);var A=this.canvasSize,O=A.x,C=A.y;a.width=O/o.fontScale,a.height=C/o.fontScale,this.renderToTexture(O,C,t,(function(t){if(0!==g.length){var n=a.getOffsetY(o,g.length,x*e.singleLineHeight,o.fontSize);g.forEach((function(e,r){var l=e.richOptions,s=e.offsetX,c=e.width,u=c,f=s;if(h===i.TextOverflow.display&&c>O){var g=O/c;u*=g,f=s.map((function(t){return t*g}))}var x=a.getOffsetX(o,u);r>0&&(n+=e.lineHeight-e.offsetY),l.forEach((function(e,r){var a=o.fontScale,l=o.textColor,s=o.fontFamily,u=o.textWeight,g=o.fontStyle,p=e.text,v=e.fontSize,d=e.fontColor,m=void 0===d?l:d,y=e.fontFamily,S=void 0===y?s:y,T=e.fontWeight,w=void 0===T?u:T,b=e.fontStyle,A=void 0===b?g:b,C=v;h===i.TextOverflow.display&&c>O&&(C/=c/O);var z=f[r]+x;t.font=A+" "+w+" "+C*a+"px "+S;var L=m[0],H=m[1],E=m[2],W=m[3];t.fillStyle="rgba("+L+", "+H+", "+E+", "+W+")",t.fillText(p,z,n)}))}))}}),{disposeOld:!1}),this.isDirty=!1}else this.isDirty=!1}},n.updateTextureWithStrategies=function(t){var e=this;if(this.isDirty&&this.context&&this.canvas){this.generateTextProgram(this.text);var i=this.textLayout,n=i.letterSpace,r=void 0===n?0:n,a=this.context;if(a){var o=this.richWrapStrategy.computeLines(this.processedTextOptions,a,this.textStyle,i,this.singleLineHeight,this.textStyle.fontScale,r,this.SCALE_FACTOR);if(0!==o.lines.length&&0!==o.maxLineWidth&&0!==o.totalHeight){var l=this.resolveCanvasSize(o,i,this.textStyle,this.singleLineHeight);this.setCanvasSize(l);var h=this.richOverflowStrategy.apply(o.lines,l,i,this.textStyle),c=this.richHorizontalAlignStrategy.getHorizontalOffsets(o.lines,l,h,i,this.textStyle),u=this.richVerticalAlignStrategy.getVerticalOffsets(o.lines,l,h,i,this.textStyle,this.singleLineHeight);s(this.canvasSize);var f=this.canvasSize,g=f.x,x=f.y,p=Math.max(1,Math.ceil(g)),v=Math.max(1,Math.ceil(x));i.width=p/this.textStyle.fontScale,i.height=v/this.textStyle.fontScale,this.renderToTexture(p,v,t,(function(t){e.drawTextWithStrategies(t,o.lines,c,u,h,e.textStyle)}),{disposeOld:!1}),this.isDirty=!1}else this.isDirty=!1}}},n.setCanvasSize=function(t){var e=this;void 0!==this.size&&null!==this.size||(this.size=this.item.transform.size.clone());var n=this.size,r=n.x,a=void 0===r?1:r,o=n.y,s=void 0===o?1:o,h=this.textLayout,c=this.textStyle.fontScale||1,u=Math.max(1,h.maxTextWidth||0),f=Math.max(1,h.maxTextHeight||0);switch(h.overflow){case i.TextOverflow.visible:var g,x,p,v,d=u*c,m=f*c,y=null!=(g=t.bboxTop)?g:0,S=null!=(p=t.bboxBottom)?p:y+(null!=(x=t.bboxHeight)?x:0),T=null!=(v=t.bboxHeight)?v:S-y,w=0;switch(h.textVerticalAlign){case i.TextVerticalAlign.top:w=-y;break;case i.TextVerticalAlign.middle:w=(m-T)/2-y;break;case i.TextVerticalAlign.bottom:w=m-T-y}var b=w+y,A=w+S,O=Math.max(0,-b),C=Math.max(0,A-m),z=O,L=C;switch(h.textVerticalAlign){case i.TextVerticalAlign.top:z=C,L=C;break;case i.TextVerticalAlign.bottom:z=O,L=O;break;case i.TextVerticalAlign.middle:z=O,L=C}for(var H=z,E=t.lines||[],W=E.map((function(t){return h.getOffsetXRich(e.textStyle,d,t.width)})),V=1/0,M=-1/0,k=0;k<E.length;k++){var R,F,D=null!=(R=W[k])?R:0,B=null!=(F=E[k].width)?F:0;V=Math.min(V,D),M=Math.max(M,D+B)}isFinite(V)||(V=0),isFinite(M)||(M=0);var _,X=Math.max(0,-V),Y=Math.max(0,M-d),P=Math.ceil(d+X+Y),N=Math.ceil(m+z+L);t.baselineCompensationX=X,t.baselineCompensationY=H,t.containerWidth=d,t.canvasWidth=P,t.canvasHeight=N,this.canvasSize=new l.Vector2(P,N);var j=null!=(_=this.size)?_:this.item.transform.size,I=j.x,U=void 0===I?1:I,$=j.y,q=void 0===$?1:$;this.item.transform.size.set(U*P*this.SCALE_FACTOR*this.SCALE_FACTOR,q*N*this.SCALE_FACTOR*this.SCALE_FACTOR),this.initialized=!0;break;case i.TextOverflow.clip:var G,J=u*c,K=f*c;t.canvasWidth=J,t.canvasHeight=K,t.baselineCompensationX=0,t.baselineCompensationY=0,this.canvasSize=new l.Vector2(J,K),h.width=u,h.height=f;var Q=null!=(G=this.size)?G:this.item.transform.size,Z=Q.x,tt=void 0===Z?1:Z,et=Q.y,it=void 0===et?1:et;this.item.transform.size.set(tt*J*this.SCALE_FACTOR*this.SCALE_FACTOR,it*K*this.SCALE_FACTOR*this.SCALE_FACTOR),this.initialized=!0;break;case i.TextOverflow.display:if(!this.initialized){var nt=u*c,rt=f*c;this.canvasSize=new l.Vector2(nt,rt),this.item.transform.size.set(a*nt*this.SCALE_FACTOR*this.SCALE_FACTOR,s*rt*this.SCALE_FACTOR*this.SCALE_FACTOR),this.initialized=!0}}},n.resolveCanvasSize=function(t,e,i,n){var r=Math.max(1,t.maxLineWidth||0),a=Math.max(1,t.totalHeight||0);return e.width=r/i.fontScale,e.height=a/i.fontScale,{canvasWidth:r,canvasHeight:a,contentWidth:t.maxLineWidth,bboxTop:t.bboxTop,bboxBottom:t.bboxBottom,bboxHeight:t.bboxHeight,lines:t.lines}},n.drawTextWithStrategies=function(t,e,i,n,r,a){var o=n.baselineY,l=i.lineOffsets;e.forEach((function(i,n){var r=i.richOptions,s=i.chars,h=l[n],c=o;r.forEach((function(e,n){var r=a.fontScale,o=a.textColor,l=a.fontFamily,u=a.textWeight,f=a.fontStyle,g=e.fontSize,x=e.fontColor,p=void 0===x?o:x,v=e.fontFamily,d=void 0===v?l:v,m=e.fontWeight,y=void 0===m?u:m,S=e.fontStyle,T=void 0===S?f:S,w=g;t.font=T+" "+y+" "+w*r+"px "+d;var b=p[0],A=p[1],O=p[2],C=p[3];t.fillStyle="rgba("+b+", "+A+", "+O+", "+C+")";var z=i.offsetX&&i.offsetX[n]?i.offsetX[n]:0;s[n].forEach((function(e){t.fillText(e.char,h+z+e.x,c)}))})),n<e.length-1&&(o+=e[n+1].lineHeight)}))},n.unsupported=function(t){throw new Error("RichTextComponent does not support "+t+" at runtime.")},n.setShadowOffsetY=function(t){this.unsupported("setShadowOffsetY")},n.setShadowBlur=function(t){this.unsupported("setShadowBlur")},n.setShadowOffsetX=function(t){this.unsupported("setShadowOffsetX")},n.setShadowColor=function(t){this.unsupported("setShadowColor")},n.setOutlineWidth=function(t){this.unsupported("setOutlineWidth")},n.setAutoWidth=function(t){this.unsupported("setAutoWidth")},n.setFontSize=function(t){this.unsupported("setFontSize")},n.setTextBaseline=function(t){console.warn("setTextBaseline 已废弃,请改用 setTextVerticalAlign。本次调用将转调用 setTextVerticalAlign。"),this.setTextVerticalAlign(t)},e}(h);r(j=function(t,e,i,n){var r,a=arguments.length,o=a<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,i):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,e,i,n);else for(var l=t.length-1;l>=0;l--)(r=t[l])&&(o=(a<3?r(o):a>3?r(e,i,o):r(e,i))||o);return a>3&&o&&Object.defineProperty(e,i,o),o}([n(i.DataType.RichTextComponent)],j),[a]);var I="2.8.6";c("rich-text",S),u.info("Plugin rich text version: 2.8.6."),I!==t.version&&console.error("注意:请统一 RichText 插件与 Player 版本,不统一的版本混用会有不可预知的后果!","\nAttention: Please ensure the RichText plugin is synchronized with the Player version. Mixing and matching incompatible versions may result in unpredictable consequences!");export{j as RichTextComponent,S as RichTextLoader,E as escape,L as generateProgram,H as isRichText,C as lexer,z as richTextParser,W as unescape,I as version};
2
2
  //# sourceMappingURL=douyin.mjs.map
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@
3
3
  * Description: Galacean Effects player rich text plugin
4
4
  * Author: Ant Group CO., Ltd.
5
5
  * Contributors: 云垣
6
- * Version: v2.8.4
6
+ * Version: v2.8.6
7
7
  */
8
8
 
9
9
  'use strict';
@@ -1746,7 +1746,7 @@ EFFECTS.applyMixins(exports.RichTextComponent, [
1746
1746
 
1747
1747
  /**
1748
1748
  * 插件版本号
1749
- */ var version = "2.8.4";
1749
+ */ var version = "2.8.6";
1750
1750
  EFFECTS.registerPlugin("rich-text", RichTextLoader);
1751
1751
  EFFECTS.logger.info("Plugin rich text version: " + version + ".");
1752
1752
  if (version !== EFFECTS__namespace.version) {
package/dist/index.min.js CHANGED
@@ -3,6 +3,6 @@
3
3
  * Description: Galacean Effects player rich text plugin
4
4
  * Author: Ant Group CO., Ltd.
5
5
  * Contributors: 云垣
6
- * Version: v2.8.4
7
- */function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@galacean/effects")):"function"==typeof define&&define.amd?define(["exports","@galacean/effects"],e):e(((t="undefined"!=typeof globalThis?globalThis:t||self).ge=t.ge||{},t.ge.richTextPlugin={}),t.ge)}(this,function(t,e){"use strict";var i,n,r=function(t){if(t&&t.__esModule)return t;var e=Object.create(null);return t&&Object.keys(t).forEach(function(i){if("default"!==i){var n=Object.getOwnPropertyDescriptor(t,i);Object.defineProperty(e,i,n.get?n:{enumerable:!0,get:function(){return t[i]}})}}),e.default=t,Object.freeze(e)}(e);function o(t,e){return(o=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function a(t,e){if("function"!=typeof e&&null!==e)throw 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&&o(t,e)}function s(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(s=function(){return!!t})()}function l(t,e,i){return(l=s()?Reflect.construct:function(t,e,i){var n=[null];n.push.apply(n,e);var r=new(Function.bind.apply(t,n));return i&&o(r,i.prototype),r}).apply(null,arguments)}function c(t){return(c=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function h(t){var e="function"==typeof Map?new Map:void 0;return(h=function(t){if(null===t||-1===Function.toString.call(t).indexOf("[native code]"))return t;if("function"!=typeof t)throw TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,i)}function i(){return l(t,arguments,c(this).constructor)}return i.prototype=Object.create(t.prototype,{constructor:{value:i,enumerable:!1,writable:!0,configurable:!0}}),o(i,t)})(t)}var u=function(t){function e(){var e;return e=t.apply(this,arguments)||this,e.name="rich-text",e}return a(e,t),e}(h(e.Plugin));function f(t,e){(null==e||e>t.length)&&(e=t.length);for(var i=0,n=Array(e);i<e;i++)n[i]=t[i];return n}function p(t,e){var i="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(i)return(i=i.call(t)).next.bind(i);if(Array.isArray(t)||(i=function(t,e){if(t){if("string"==typeof t)return f(t,void 0);var i=Object.prototype.toString.call(t).slice(8,-1);if("Object"===i&&t.constructor&&(i=t.constructor.name),"Map"===i||"Set"===i)return Array.from(i);if("Arguments"===i||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i))return f(t,void 0)}}(t))||e&&t&&"number"==typeof t.length){i&&(t=i);var n=0;return function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}}}throw TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(i=n||(n={})).ContextStart="ContextStart",i.Text="Text",i.ContextEnd="ContextEnd",i.EscapedChar="EscapedChar";var g=/^<([a-z]+)(=([^>]+))?>$/,x=/^<\/([a-z]+)>$/,d=[["EscapedChar",/^\\([=<>\\/])/],["ContextStart",/^<[a-z]+(=[^>]+)?>/],["ContextEnd",/^<\/[a-z]+>/],["Text",/^[^</>=\\]+/]],v=function(t,e,i){if(void 0===e&&(e=[]),void 0===i&&(i=0),!t)return e;var n=/^\\([=<>\\/])/.exec(t);if(n){var r=n[1];return v(t.slice(2),e.concat({tokenType:"Text",value:r}),i+2)}for(var o,a=p(d);!(o=a()).done;){var s=o.value,l=s[0],c=s[1];if("EscapedChar"!==l){var h=c.exec(t);if(h){var u=h[0],f=u.length;return v(t.slice(f),e.concat({tokenType:l,value:u}),i+f)}}}if(t.length>0)return v(t.slice(1),e.concat({tokenType:"Text",value:t[0]}),i+1);throw Error('Unexpected token: "'+t[0]+'" at position '+i+' while reading "'+t+'"')},m=function(t){var e=function(){for(var t,e="",i=!1;r.length>0&&(null==(t=r[0])?void 0:t.tokenType)==="Text";){var n=a();n&&(e+=n.value,i=!0)}return i?e:void 0},i=function(){var t=s();if((null==t?void 0:t.tokenType)==="ContextStart"){a();var e,i=t.value.match(g);if(i)return{attributeName:i[1],attributeParam:null!=(e=i[3])?e:""};throw Error("Expected a start tag marker at position "+o)}return{}},n=function(){var t=s();if((null==t?void 0:t.tokenType)==="ContextEnd"){a();var e=t.value.match(x);if(e)return{attributeName:e[1]};throw Error("Expect an end tag marker at position "+o)}return{}},r=v(t),o=0,a=function(){var t,e=r.shift();return o+=null!=(t=null==e?void 0:e.value.length)?t:0,e},s=function(){return r[0]},l=[];return!function t(r,a){for(void 0===r&&(r=[]),void 0===a&&(a="");;){var s=e();if(s){l.push({attributes:r,text:s});continue}var c=i(),h=c.attributeName,u=c.attributeParam;if(h){t(r.concat({attributeName:h,attributeParam:null!=u?u:""}),h);continue}if(a){var f=n().attributeName;if(!f)throw Error('Expect an end tag marker "'+a+'" at position '+o+" but found no tag!");if(f!==a)throw Error('Expect an end tag marker "'+a+'" at position '+o+' but found tag "'+f+'"');return}break}}(),l};function y(t){return function(e){for(var i,n=m(e),r=p(n);!(i=r()).done;){var o=i.value;t(o.text,o.attributes.reduce(function(t,e){var i=e.attributeName,n=e.attributeParam;return i&&(t[i]=n),t},{}))}}}"function"==typeof SuppressedError&&SuppressedError;var S=function(){function t(t){this.width=0,this.height=0;var i=t.size,n=t.textOverflow,r=void 0===n?e.spec.TextOverflow.clip:n,o=t.textVerticalAlign,a=void 0===o?e.spec.TextVerticalAlign.middle:o,s=t.textAlign,l=void 0===s?e.spec.TextAlignment.left:s,c=t.letterSpace,h=t.lineHeight,u=t.wrapEnabled,f=t.maxTextWidth,p=t.maxTextHeight,g=t.sizeMode,x=void 0===g?e.spec.TextSizeMode.autoWidth:g,d=t.useLegacyRichText;this.letterSpace=void 0===c?0:c,this.lineHeight=void 0===h?.571:h,this.useLegacyRichText=void 0!==d&&d,this.overflow=r,this.textVerticalAlign=a,this.textAlign=l,this.width=i?i[0]:100,this.height=i?i[1]:100,this.wrapEnabled=void 0!==u&&u,this.maxTextWidth=(void 0===f?350:f)*50,this.maxTextHeight=(void 0===p?1e3:p)*50,this.sizeMode=x}var i=t.prototype;return i.getOffsetY=function(t,i,n,r,o){var a=t.outlineWidth,s=t.fontScale,l=(n-r)/3,c=r+a*s,h=void 0!==o?o:n*(i-1),u=0;switch(this.textVerticalAlign){case e.spec.TextVerticalAlign.top:u=c+l;break;case e.spec.TextVerticalAlign.middle:u=(this.height*s-h+c)/2;break;case e.spec.TextVerticalAlign.bottom:u=this.height*s-h-l}return u},i.getOffsetX=function(t,i){var n=0;switch(this.textAlign){case e.spec.TextAlignment.left:n=t.outlineWidth*t.fontScale;break;case e.spec.TextAlignment.middle:n=(this.width*t.fontScale-i)/2;break;case e.spec.TextAlignment.right:n=this.width*t.fontScale-i}return n},i.getOffsetYRich=function(t,i,n){if(0===i.length)return 0;var r=t.outlineWidth,o=t.fontScale,a=i.reduce(function(t,e){return t+e},0),s=(i[0]-n)/3,l=n+r*o,c=a-i[0],h=0;switch(this.textVerticalAlign){case e.spec.TextVerticalAlign.top:h=l+s;break;case e.spec.TextVerticalAlign.middle:h=(this.height*o-a)/2+l;break;case e.spec.TextVerticalAlign.bottom:h=this.height*o-c-s}return h},i.getOffsetXRich=function(t,i,n){switch(this.textAlign){case e.spec.TextAlignment.left:return t.outlineWidth*t.fontScale;case e.spec.TextAlignment.middle:return(i-n)/2;case e.spec.TextAlignment.right:return i-n;default:return 0}},i.setSize=function(t,e){this.width=t,this.height=e},t}();function T(t,e){if(void 0===e&&(e=1),(3===(t=t.replace(/^#/,"")).length||4===t.length)&&(t=t.split("").map(function(t){return t+t}).join("")),8===t.length){var i=parseInt(t.slice(6,8),16)/255;t=t.slice(0,6),e=i}var n=parseInt(t,16);return[n>>16&255,n>>8&255,255&n,e]}var b=function(){function t(){}var e=t.prototype;return e.computeLines=function(t,e,i,n,r,o,a,s){var l=this,c=[],h=[],u=(n.lineHeight||0)*o,f=this.createNewLine(),p=0,g=0,x=function(){if(0!==f.chars.length){f.lineHeight=0===c.length?(f.lineAscent||0)+(f.lineDescent||0):u;var t=0===c.length?0:h[h.length-1]+u;h.push(t),g+=f.lineHeight,c.push(f),p=Math.max(p,f.width),f=l.createNewLine()}};t.forEach(function(t){var n=t.text,r=t.isNewLine,l=t.fontSize;r&&x();var c=t.fontStyle||i.fontStyle||"normal";e.font=c+" "+(t.fontWeight||i.textWeight)+" 10px "+(t.fontFamily||i.fontFamily),f.offsetX.push(f.width);for(var h=0,u=[],p=0,g=0,d=0;d<n.length;d++){var v=n[d],m=e.measureText(v),y=m.width,S=(y<=0?0:y)*l*s*o,T=l*o*s,b=m.actualBoundingBoxAscent*T,w=m.actualBoundingBoxDescent*T;p=Math.max(p,b),g=Math.max(g,w),d>0&&(h+=a),u.push({char:v,x:h}),h+=S}f.chars.push(u),f.width+=h,f.richOptions.push(t),f.lineAscent=Math.max(f.lineAscent||0,p),f.lineDescent=Math.max(f.lineDescent||0,g)}),x();var d=1/0,v=-1/0;if(0===c.length)return{lines:c,maxLineWidth:p,totalHeight:g,bboxTop:0,bboxBottom:0,bboxHeight:0};for(var m=0;m<c.length;m++)d=Math.min(d,h[m]-(c[m].lineAscent||0)),v=Math.max(v,h[m]+(c[m].lineDescent||0));var y=v-d;return{lines:c,maxLineWidth:p,totalHeight:g,bboxTop:d,bboxBottom:v,bboxHeight:y}},e.createNewLine=function(){return{richOptions:[],offsetX:[],width:0,lineHeight:0,offsetY:0,chars:[],lineAscent:0,lineDescent:0}},t}(),w=function(){function t(){}var e=t.prototype;return e.computeLines=function(t,e,i,n,r,o,a,s){var l=this,c=[],h=[],u=(n.lineHeight||0)*o,f=this.createNewLine(),p=0,g=0,x=null,d=0,v=[],m=null,y=function(){if(S(),0!==f.chars.length){f.lineHeight=0===c.length?(f.lineAscent||0)+(f.lineDescent||0):u;var t=0===c.length?0:h[h.length-1]+u;h.push(t),g+=f.lineHeight,c.push(f),p=Math.max(p,f.width),f=l.createNewLine(),x=null,d=0,v=[],m=null}},S=function(){0!==v.length&&(null===x&&(x=f.width),f.offsetX.push(x),f.chars.push(v),m&&f.richOptions.push(m),x=null,d=0,v=[],m=null)};t.forEach(function(t){var r=t.text,l=t.isNewLine,c=t.fontSize,h=t.fontStyle||i.fontStyle||"normal";e.font=h+" "+(t.fontWeight||i.textWeight)+" 10px "+(t.fontFamily||i.fontFamily),l&&(S(),y());for(var u=0;u<r.length;u++){var p=r[u],g=e.measureText(p),T=g.width,b=(T<=0?0:T)*c*s*o,w=c*o*s,A=g.actualBoundingBoxAscent*w,O=g.actualBoundingBoxDescent*w,C=v.length>0?a:0;f.width+C+b>(n.maxTextWidth||1/0)&&(S(),y()),null===x&&(x=f.width,m=t),v.length>0&&(d+=a,f.width+=a),v.push({char:p,x:d}),f.lineAscent=Math.max(f.lineAscent||0,A),f.lineDescent=Math.max(f.lineDescent||0,O),d+=b,f.width+=b}S()}),y();for(var T=1/0,b=-1/0,w=0;w<c.length;w++)T=Math.min(T,h[w]-(c[w].lineAscent||0)),b=Math.max(b,h[w]+(c[w].lineDescent||0));var A=b-T;return{lines:c,maxLineWidth:p,totalHeight:g,bboxTop:T,bboxBottom:b,bboxHeight:A}},e.createNewLine=function(){return{richOptions:[],offsetX:[],width:0,lineHeight:0,offsetY:0,chars:[],lineAscent:0,lineDescent:0}},t}(),A=function(){function t(){}return t.prototype.apply=function(t,e,i,n){var r=function(t,e){return Math.abs(e)>1e-5?t/e:1},o=i.maxTextWidth*n.fontScale,a=i.maxTextHeight*n.fontScale,s=Math.max(1,null!=(h=e.contentWidth)?h:e.canvasWidth),l=Math.max(1,null!=(u=e.bboxHeight)?u:e.canvasHeight),c=Math.min(1,r(o,s),r(a,l));if(c>.9999)return{globalScale:1};for(var h,u,f,g=p(t);!(f=g()).done;){var x=f.value;if(x.width*=c,x.lineHeight*=c,x.offsetX)for(var d=0;d<x.offsetX.length;d++)x.offsetX[d]*=c;for(var v,m=p(x.chars||[]);!(v=m()).done;)for(var y,S=v.value,T=p(S);!(y=T()).done;){var b=y.value;b.x*=c}for(var w,A=p(x.richOptions||[]);!(w=A()).done;){var O=w.value;O.fontSize*=c}null!=x.lineAscent&&(x.lineAscent*=c),null!=x.lineDescent&&(x.lineDescent*=c)}return{globalScale:c}},t}(),O=function(){function t(){}return t.prototype.apply=function(t,e,i,n){return{globalScale:1}},t}(),C=function(){function t(){}return t.prototype.apply=function(t,e,i,n){return{globalScale:1}},t}(),z=function(){function t(){}return t.prototype.getHorizontalOffsets=function(t,i,n,r,o){var a,s,l=null!=(a=i.containerWidth)?a:r.maxTextWidth*o.fontScale,c=null!=(s=i.baselineCompensationX)?s:0,h=t.map(function(t){return r.getOffsetXRich(o,l,t.width)});return{lineOffsets:r.overflow===e.spec.TextOverflow.visible?h.map(function(t){return t+c}):h}},t}(),L=function(){function t(){}return t.prototype.getVerticalOffsets=function(t,i,n,r,o,a){var s=null!=(c=i.baselineCompensationY)?c:0,l=0;if(0===t.length)return{baselineY:0,lineYOffsets:[]};switch(r.overflow){case e.spec.TextOverflow.visible:var c,h,u,f,p,g=r.maxTextHeight*o.fontScale,x=null!=(h=i.bboxTop)?h:0,d=null!=(f=i.bboxBottom)?f:x+(null!=(u=i.bboxHeight)?u:0),v=null!=(p=i.bboxHeight)?p:d-x,m=0;switch(r.textVerticalAlign){case e.spec.TextVerticalAlign.top:m=-x;break;case e.spec.TextVerticalAlign.middle:m=(g-v)/2-x;break;case e.spec.TextVerticalAlign.bottom:m=g-v-x}l=m+s;break;case e.spec.TextOverflow.clip:for(var y=r.maxTextHeight*o.fontScale,S=[0],T=1;T<t.length;T++)S[T]=S[T-1]+t[T].lineHeight;for(var b=1/0,w=-1/0,A=0;A<t.length;A++){var O,C,z=null!=(O=t[A].lineAscent)?O:0,L=null!=(C=t[A].lineDescent)?C:0;b=Math.min(b,S[A]-z),w=Math.max(w,S[A]+L)}var E=w-b,H=0;switch(r.textVerticalAlign){case e.spec.TextVerticalAlign.top:H=-b;break;case e.spec.TextVerticalAlign.middle:H=(y-E)/2-b;break;case e.spec.TextVerticalAlign.bottom:H=y-E-b}l=H+s;break;case e.spec.TextOverflow.display:for(var W=r.maxTextHeight*o.fontScale,M=[0],V=1;V<t.length;V++)M[V]=M[V-1]+t[V].lineHeight;for(var R=1/0,k=-1/0,F=0;F<t.length;F++){var _,D,B=null!=(_=t[F].lineAscent)?_:0,P=null!=(D=t[F].lineDescent)?D:0;R=Math.min(R,M[F]-B),k=Math.max(k,M[F]+P)}var X=k-R,Y=0;switch(r.textVerticalAlign){case e.spec.TextVerticalAlign.top:Y=-R;break;case e.spec.TextVerticalAlign.middle:Y=(W-X)/2-R;break;case e.spec.TextVerticalAlign.bottom:Y=W-X-R}for(var j=[],N=Y,I=0;I<t.length;I++)j.push(N),I<t.length-1&&(N+=t[I+1].lineHeight);return{baselineY:Y,lineYOffsets:j}}var U=[],$=l;return t.forEach(function(e,i){U.push($),i<t.length-1&&($+=t[i+1].lineHeight)}),{baselineY:l,lineYOffsets:U}},t}(),E=function(){function t(){}return t.createWrapStrategy=function(t){return t?new w:new b},t.createOverflowStrategy=function(t){switch(t){case e.spec.TextOverflow.clip:return new O;case e.spec.TextOverflow.display:return new A;case e.spec.TextOverflow.visible:default:return new C}},t.createHorizontalAlignStrategy=function(){return new z},t.createVerticalAlignStrategy=function(){return new L},t}(),H=0;t.RichTextComponent=function(t){function i(i){var n;return(n=t.call(this,i)||this).isDirty=!0,n.text="",n.processedTextOptions=[],n.singleLineHeight=1.571,n.size=null,n.initialized=!1,n.canvasSize=null,n.SCALE_FACTOR=.1,n.ALPHA_FIX_VALUE=1/255,n.name="MRichText"+H++,n.initTextBase(i),n.richWrapStrategy=E.createWrapStrategy(),n.richOverflowStrategy=E.createOverflowStrategy(e.spec.TextOverflow.display),n.richHorizontalAlignStrategy=E.createHorizontalAlignStrategy(),n.richVerticalAlignStrategy=E.createVerticalAlignStrategy(),n}a(i,t);var n=i.prototype;return n.onUpdate=function(e){t.prototype.onUpdate.call(this,e),this.updateTexture()},n.onDestroy=function(){t.prototype.onDestroy.call(this),this.disposeTextTexture()},n.fromData=function(i){t.prototype.fromData.call(this,i);var n=i.interaction,r=i.options;this.interaction=n,this.textStyle=new e.TextStyle(r),this.textLayout=new S(r),this.text=r.text?r.text.toString():" ",this.textLayout.useLegacyRichText&&(this.textLayout.textVerticalAlign=e.spec.TextVerticalAlign.middle),this.updateStrategies(),this.renderText(r),this.material.setColor("_Color",new e.math.Color(1,1,1,1))},n.updateStrategies=function(){var t=this.textLayout;t&&(this.richWrapStrategy=E.createWrapStrategy(t.wrapEnabled),this.richOverflowStrategy=E.createOverflowStrategy(t.overflow))},n.generateTextProgram=function(t){var i=this;this.processedTextOptions=[],y(function(t,n){/^\n+$/.test(t)&&(t=t.replace(/\n/g,"\n ")),t.split("\n").forEach(function(t,r){var o={text:t,fontSize:i.textStyle.fontSize,isNewLine:!1};r>0&&(o.isNewLine=!0),"b"in n&&(o.fontWeight=e.spec.TextWeight.bold),"i"in n&&(o.fontStyle=e.spec.FontStyle.italic),"size"in n&&n.size&&(o.fontSize=parseInt(n.size,10)),"color"in n&&n.color&&(o.fontColor=function(t,e){if(void 0===e&&(e=1),"string"!=typeof t||!t)throw Error("Invalid color string");return t.startsWith("#")?T(t,e):T(function(t){if("string"!=typeof t||!t)throw Error("Invalid color name provided");if("undefined"==typeof document)throw Error("This method requires a browser environment");var e=document.createElement("canvas"),i=e.getContext("2d");if(i)try{return i.fillStyle=t,i.fillStyle}finally{null==e.remove||e.remove.call(e)}throw Error("Failed to get 2D context for color conversion!")}(t))}(n.color)),i.processedTextOptions.push(o)})})(t)},n.updateWithOptions=function(t){this.textStyle=new e.TextStyle(t),this.textLayout=new S(t),this.text=t.text?t.text.toString():" ",this.textLayout.useLegacyRichText&&(this.textLayout.textVerticalAlign=e.spec.TextVerticalAlign.middle),this.updateStrategies(),this.isDirty=!0},n.renderText=function(t){var i=t.size;i&&(this.canvasSize=new e.math.Vector2(i[0],i[1])),this.updateTexture()},n.updateTexture=function(t){if(void 0===t&&(t=!0),this.isDirty&&this.context&&this.canvas&&this.textStyle&&this.textLayout){var e=!0===this.textLayout.useLegacyRichText;this.singleLineHeight=e?1.571:1,e?this.updateTextureLegacy(t):this.updateTextureWithStrategies(t)}},n.updateTextureLegacy=function(t){var i=this;if(this.isDirty&&this.context&&this.canvas&&this.textStyle){this.generateTextProgram(this.text);var n=0,r=0,o=this.textLayout,a=this.textStyle,s=o.overflow,l=o.letterSpace,c=void 0===l?0:l,h=this.context,u=[],f=a.fontSize*a.fontScale,p={richOptions:[],offsetX:[],width:0,lineHeight:f*this.singleLineHeight,offsetY:f*(this.singleLineHeight-1)/2};if(this.processedTextOptions.forEach(function(t){var e=t.text,o=t.isNewLine,s=t.fontSize;o&&(u.push(p),n=Math.max(n,p.width),p={richOptions:[],offsetX:[],width:0,lineHeight:f*i.singleLineHeight,offsetY:f*(i.singleLineHeight-1)/2},r+=p.lineHeight),h.font=(t.fontWeight||a.textWeight)+" 10px "+(t.fontFamily||a.fontFamily);var l=h.measureText(e),g=l.width;if(void 0!==l.actualBoundingBoxLeft&&void 0!==l.actualBoundingBoxRight){var x=l.actualBoundingBoxLeft+l.actualBoundingBoxRight;x>0&&(g=Math.max(g,x))}var d=s*i.singleLineHeight*a.fontScale;d>p.lineHeight&&(r+=d-p.lineHeight,p.lineHeight=d,p.offsetY=s*a.fontScale*(i.singleLineHeight-1)/2),p.offsetX.push(p.width),p.width+=(g<=0?0:g)*s*i.SCALE_FACTOR*a.fontScale+e.length*c,p.richOptions.push(t)}),u.push(p),n=Math.max(n,p.width),r+=p.lineHeight,0===n||0===r){this.isDirty=!1;return}(void 0===this.size||null===this.size)&&(this.size=this.item.transform.size.clone());var g=this.size,x=g.x,d=g.y;if(!this.initialized){this.canvasSize=this.canvasSize?this.canvasSize:new e.math.Vector2(n,r);var v=this.canvasSize,m=v.x,y=v.y;this.item.transform.size.set((void 0===x?1:x)*m*this.SCALE_FACTOR*this.SCALE_FACTOR,(void 0===d?1:d)*y*this.SCALE_FACTOR*this.SCALE_FACTOR),this.size=this.item.transform.size.clone(),this.initialized=!0}e.assertExist(this.canvasSize);var S=this.canvasSize,T=S.x,b=S.y;o.width=T/a.fontScale,o.height=b/a.fontScale,this.renderToTexture(T,b,t,function(t){if(0!==u.length){var n=o.getOffsetY(a,u.length,f*i.singleLineHeight,a.fontSize);u.forEach(function(i,r){var l=i.richOptions,c=i.offsetX,h=i.width,u=h,f=c;if(s===e.spec.TextOverflow.display&&h>T){var p=T/h;u*=p,f=c.map(function(t){return t*p})}var g=o.getOffsetX(a,u);r>0&&(n+=i.lineHeight-i.offsetY),l.forEach(function(i,r){var o=a.fontScale,l=a.textColor,c=a.fontFamily,u=a.textWeight,p=a.fontStyle,x=i.text,d=i.fontSize,v=i.fontColor,m=void 0===v?l:v,y=i.fontFamily,S=i.fontWeight,b=i.fontStyle,w=d;s===e.spec.TextOverflow.display&&h>T&&(w/=h/T);var A=f[r]+g;t.font=(void 0===b?p:b)+" "+(void 0===S?u:S)+" "+w*o+"px "+(void 0===y?c:y);var O=m[0],C=m[1],z=m[2],L=m[3];t.fillStyle="rgba("+O+", "+C+", "+z+", "+L+")",t.fillText(x,A,n)})})}},{disposeOld:!1}),this.isDirty=!1}},n.updateTextureWithStrategies=function(t){var i=this;if(this.isDirty&&this.context&&this.canvas){this.generateTextProgram(this.text);var n=this.textLayout,r=n.letterSpace,o=this.context;if(o){var a=this.richWrapStrategy.computeLines(this.processedTextOptions,o,this.textStyle,n,this.singleLineHeight,this.textStyle.fontScale,void 0===r?0:r,this.SCALE_FACTOR);if(0===a.lines.length||0===a.maxLineWidth||0===a.totalHeight){this.isDirty=!1;return}var s=this.resolveCanvasSize(a,n,this.textStyle,this.singleLineHeight);this.setCanvasSize(s);var l=this.richOverflowStrategy.apply(a.lines,s,n,this.textStyle),c=this.richHorizontalAlignStrategy.getHorizontalOffsets(a.lines,s,l,n,this.textStyle),h=this.richVerticalAlignStrategy.getVerticalOffsets(a.lines,s,l,n,this.textStyle,this.singleLineHeight);e.assertExist(this.canvasSize);var u=this.canvasSize,f=u.x,p=u.y,g=Math.max(1,Math.ceil(f)),x=Math.max(1,Math.ceil(p));n.width=g/this.textStyle.fontScale,n.height=x/this.textStyle.fontScale,this.renderToTexture(g,x,t,function(t){i.drawTextWithStrategies(t,a.lines,c,h,l,i.textStyle)},{disposeOld:!1}),this.isDirty=!1}}},n.setCanvasSize=function(t){var i=this;(void 0===this.size||null===this.size)&&(this.size=this.item.transform.size.clone());var n=this.size,r=n.x,o=n.y,a=this.textLayout,s=this.textStyle.fontScale||1,l=Math.max(1,a.maxTextWidth||0),c=Math.max(1,a.maxTextHeight||0);switch(a.overflow){case e.spec.TextOverflow.visible:var h,u=l*s,f=c*s,p=null!=(z=t.bboxTop)?z:0,g=null!=(E=t.bboxBottom)?E:p+(null!=(L=t.bboxHeight)?L:0),x=null!=(H=t.bboxHeight)?H:g-p,d=0;switch(a.textVerticalAlign){case e.spec.TextVerticalAlign.top:d=-p;break;case e.spec.TextVerticalAlign.middle:d=(f-x)/2-p;break;case e.spec.TextVerticalAlign.bottom:d=f-x-p}var v=Math.max(0,-(d+p)),m=Math.max(0,d+g-f),y=v,S=m;switch(a.textVerticalAlign){case e.spec.TextVerticalAlign.top:y=m,S=m;break;case e.spec.TextVerticalAlign.bottom:y=v,S=v;break;case e.spec.TextVerticalAlign.middle:y=v,S=m}for(var T=y,b=t.lines||[],w=b.map(function(t){return a.getOffsetXRich(i.textStyle,u,t.width)}),A=1/0,O=-1/0,C=0;C<b.length;C++){var z,L,E,H,W,M,V=null!=(W=w[C])?W:0,R=null!=(M=b[C].width)?M:0;A=Math.min(A,V),O=Math.max(O,V+R)}isFinite(A)||(A=0),isFinite(O)||(O=0);var k=Math.max(0,-A),F=Math.max(0,O-u),_=Math.ceil(u+k+F),D=Math.ceil(f+y+S);t.baselineCompensationX=k,t.baselineCompensationY=T,t.containerWidth=u,t.canvasWidth=_,t.canvasHeight=D,this.canvasSize=new e.math.Vector2(_,D);var B=null!=(h=this.size)?h:this.item.transform.size,P=B.x,X=B.y;this.item.transform.size.set((void 0===P?1:P)*_*this.SCALE_FACTOR*this.SCALE_FACTOR,(void 0===X?1:X)*D*this.SCALE_FACTOR*this.SCALE_FACTOR),this.initialized=!0;break;case e.spec.TextOverflow.clip:var Y,j=l*s,N=c*s;t.canvasWidth=j,t.canvasHeight=N,t.baselineCompensationX=0,t.baselineCompensationY=0,this.canvasSize=new e.math.Vector2(j,N),a.width=l,a.height=c;var I=null!=(Y=this.size)?Y:this.item.transform.size,U=I.x,$=I.y;this.item.transform.size.set((void 0===U?1:U)*j*this.SCALE_FACTOR*this.SCALE_FACTOR,(void 0===$?1:$)*N*this.SCALE_FACTOR*this.SCALE_FACTOR),this.initialized=!0;break;case e.spec.TextOverflow.display:if(!this.initialized){var q=l*s,G=c*s;this.canvasSize=new e.math.Vector2(q,G),this.item.transform.size.set((void 0===r?1:r)*q*this.SCALE_FACTOR*this.SCALE_FACTOR,(void 0===o?1:o)*G*this.SCALE_FACTOR*this.SCALE_FACTOR),this.initialized=!0}}},n.resolveCanvasSize=function(t,e,i,n){var r=Math.max(1,t.maxLineWidth||0),o=Math.max(1,t.totalHeight||0);return e.width=r/i.fontScale,e.height=o/i.fontScale,{canvasWidth:r,canvasHeight:o,contentWidth:t.maxLineWidth,bboxTop:t.bboxTop,bboxBottom:t.bboxBottom,bboxHeight:t.bboxHeight,lines:t.lines}},n.drawTextWithStrategies=function(t,e,i,n,r,o){var a=n.baselineY,s=i.lineOffsets;e.forEach(function(i,n){var r=i.richOptions,l=i.chars,c=s[n],h=a;r.forEach(function(e,n){var r=o.fontScale,a=o.textColor,s=o.fontFamily,u=o.textWeight,f=o.fontStyle,p=e.fontSize,g=e.fontColor,x=void 0===g?a:g,d=e.fontFamily,v=e.fontWeight,m=e.fontStyle;t.font=(void 0===m?f:m)+" "+(void 0===v?u:v)+" "+p*r+"px "+(void 0===d?s:d);var y=x[0],S=x[1],T=x[2],b=x[3];t.fillStyle="rgba("+y+", "+S+", "+T+", "+b+")";var w=i.offsetX&&i.offsetX[n]?i.offsetX[n]:0;l[n].forEach(function(e){t.fillText(e.char,c+w+e.x,h)})}),n<e.length-1&&(a+=e[n+1].lineHeight)})},n.unsupported=function(t){throw Error("RichTextComponent does not support "+t+" at runtime.")},n.setShadowOffsetY=function(t){this.unsupported("setShadowOffsetY")},n.setShadowBlur=function(t){this.unsupported("setShadowBlur")},n.setShadowOffsetX=function(t){this.unsupported("setShadowOffsetX")},n.setShadowColor=function(t){this.unsupported("setShadowColor")},n.setOutlineWidth=function(t){this.unsupported("setOutlineWidth")},n.setAutoWidth=function(t){this.unsupported("setAutoWidth")},n.setFontSize=function(t){this.unsupported("setFontSize")},n.setTextBaseline=function(t){console.warn("setTextBaseline 已废弃,请改用 setTextVerticalAlign。本次调用将转调用 setTextVerticalAlign。"),this.setTextVerticalAlign(t)},i}(e.MaskableGraphic),t.RichTextComponent=function(t,e,i,n){var r,o=arguments.length,a=o<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,i):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(t,e,i,n);else for(var s=t.length-1;s>=0;s--)(r=t[s])&&(a=(o<3?r(a):o>3?r(e,i,a):r(e,i))||a);return o>3&&a&&Object.defineProperty(e,i,a),a}([e.effectsClass(e.spec.DataType.RichTextComponent)],t.RichTextComponent),e.applyMixins(t.RichTextComponent,[e.TextComponentBase]);var W="2.8.4";e.registerPlugin("rich-text",u),e.logger.info("Plugin rich text version: "+W+"."),W!==r.version&&console.error("注意:请统一 RichText 插件与 Player 版本,不统一的版本混用会有不可预知的后果!","\nAttention: Please ensure the RichText plugin is synchronized with the Player version. Mixing and matching incompatible versions may result in unpredictable consequences!"),t.RichTextLoader=u,t.escape=function(t){if("string"!=typeof t)throw Error("Input must be a string");return t.replace(/\\/g,"\\\\").replace(/=/g,"\\=").replace(/</g,"\\<").replace(/>/g,"\\>").replace(/\//g,"\\/")},t.generateProgram=y,t.isRichText=function(t){var e=v(t).filter(function(t){var e=t.tokenType;return"ContextStart"===e||"ContextEnd"===e}),i=e.filter(function(t){return"ContextStart"===t.tokenType}),n=e.filter(function(t){return"ContextEnd"===t.tokenType});return i.length===n.length&&!!i.length&&function t(e,i){var n=e[0],r=e.slice(1);if(void 0===i&&(i=[]),!n)return 0===i.length;if("ContextStart"===n.tokenType)return t(r,i.concat(n.value));if("ContextEnd"===n.tokenType)return i[i.length-1]===n.value&&t(r,i.slice(0,-1));throw Error("Unexpected token: "+n.tokenType)}(e.map(function(t){var e=t.tokenType,i=t.value;return{tokenType:e,value:"ContextStart"===e?i.match(g)[1]:i.match(x)[1]}}))},t.lexer=v,t.richTextParser=m,t.unescape=function(t){if("string"!=typeof t)throw Error("Input must be a string");return t.replace(/\\\//g,"/").replace(/\\>/g,">").replace(/\\</g,"<").replace(/\\=/g,"=").replace(/\\\\/g,"\\")},t.version=W,Object.defineProperty(t,"__esModule",{value:!0})});
6
+ * Version: v2.8.6
7
+ */function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@galacean/effects")):"function"==typeof define&&define.amd?define(["exports","@galacean/effects"],e):e(((t="undefined"!=typeof globalThis?globalThis:t||self).ge=t.ge||{},t.ge.richTextPlugin={}),t.ge)}(this,function(t,e){"use strict";var i,n,r=function(t){if(t&&t.__esModule)return t;var e=Object.create(null);return t&&Object.keys(t).forEach(function(i){if("default"!==i){var n=Object.getOwnPropertyDescriptor(t,i);Object.defineProperty(e,i,n.get?n:{enumerable:!0,get:function(){return t[i]}})}}),e.default=t,Object.freeze(e)}(e);function o(t,e){return(o=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function a(t,e){if("function"!=typeof e&&null!==e)throw 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&&o(t,e)}function s(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(s=function(){return!!t})()}function l(t,e,i){return(l=s()?Reflect.construct:function(t,e,i){var n=[null];n.push.apply(n,e);var r=new(Function.bind.apply(t,n));return i&&o(r,i.prototype),r}).apply(null,arguments)}function c(t){return(c=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function h(t){var e="function"==typeof Map?new Map:void 0;return(h=function(t){if(null===t||-1===Function.toString.call(t).indexOf("[native code]"))return t;if("function"!=typeof t)throw TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,i)}function i(){return l(t,arguments,c(this).constructor)}return i.prototype=Object.create(t.prototype,{constructor:{value:i,enumerable:!1,writable:!0,configurable:!0}}),o(i,t)})(t)}var u=function(t){function e(){var e;return e=t.apply(this,arguments)||this,e.name="rich-text",e}return a(e,t),e}(h(e.Plugin));function f(t,e){(null==e||e>t.length)&&(e=t.length);for(var i=0,n=Array(e);i<e;i++)n[i]=t[i];return n}function p(t,e){var i="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(i)return(i=i.call(t)).next.bind(i);if(Array.isArray(t)||(i=function(t,e){if(t){if("string"==typeof t)return f(t,void 0);var i=Object.prototype.toString.call(t).slice(8,-1);if("Object"===i&&t.constructor&&(i=t.constructor.name),"Map"===i||"Set"===i)return Array.from(i);if("Arguments"===i||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i))return f(t,void 0)}}(t))||e&&t&&"number"==typeof t.length){i&&(t=i);var n=0;return function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}}}throw TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(i=n||(n={})).ContextStart="ContextStart",i.Text="Text",i.ContextEnd="ContextEnd",i.EscapedChar="EscapedChar";var g=/^<([a-z]+)(=([^>]+))?>$/,x=/^<\/([a-z]+)>$/,d=[["EscapedChar",/^\\([=<>\\/])/],["ContextStart",/^<[a-z]+(=[^>]+)?>/],["ContextEnd",/^<\/[a-z]+>/],["Text",/^[^</>=\\]+/]],v=function(t,e,i){if(void 0===e&&(e=[]),void 0===i&&(i=0),!t)return e;var n=/^\\([=<>\\/])/.exec(t);if(n){var r=n[1];return v(t.slice(2),e.concat({tokenType:"Text",value:r}),i+2)}for(var o,a=p(d);!(o=a()).done;){var s=o.value,l=s[0],c=s[1];if("EscapedChar"!==l){var h=c.exec(t);if(h){var u=h[0],f=u.length;return v(t.slice(f),e.concat({tokenType:l,value:u}),i+f)}}}if(t.length>0)return v(t.slice(1),e.concat({tokenType:"Text",value:t[0]}),i+1);throw Error('Unexpected token: "'+t[0]+'" at position '+i+' while reading "'+t+'"')},m=function(t){var e=function(){for(var t,e="",i=!1;r.length>0&&(null==(t=r[0])?void 0:t.tokenType)==="Text";){var n=a();n&&(e+=n.value,i=!0)}return i?e:void 0},i=function(){var t=s();if((null==t?void 0:t.tokenType)==="ContextStart"){a();var e,i=t.value.match(g);if(i)return{attributeName:i[1],attributeParam:null!=(e=i[3])?e:""};throw Error("Expected a start tag marker at position "+o)}return{}},n=function(){var t=s();if((null==t?void 0:t.tokenType)==="ContextEnd"){a();var e=t.value.match(x);if(e)return{attributeName:e[1]};throw Error("Expect an end tag marker at position "+o)}return{}},r=v(t),o=0,a=function(){var t,e=r.shift();return o+=null!=(t=null==e?void 0:e.value.length)?t:0,e},s=function(){return r[0]},l=[];return!function t(r,a){for(void 0===r&&(r=[]),void 0===a&&(a="");;){var s=e();if(s){l.push({attributes:r,text:s});continue}var c=i(),h=c.attributeName,u=c.attributeParam;if(h){t(r.concat({attributeName:h,attributeParam:null!=u?u:""}),h);continue}if(a){var f=n().attributeName;if(!f)throw Error('Expect an end tag marker "'+a+'" at position '+o+" but found no tag!");if(f!==a)throw Error('Expect an end tag marker "'+a+'" at position '+o+' but found tag "'+f+'"');return}break}}(),l};function y(t){return function(e){for(var i,n=m(e),r=p(n);!(i=r()).done;){var o=i.value;t(o.text,o.attributes.reduce(function(t,e){var i=e.attributeName,n=e.attributeParam;return i&&(t[i]=n),t},{}))}}}"function"==typeof SuppressedError&&SuppressedError;var S=function(){function t(t){this.width=0,this.height=0;var i=t.size,n=t.textOverflow,r=void 0===n?e.spec.TextOverflow.clip:n,o=t.textVerticalAlign,a=void 0===o?e.spec.TextVerticalAlign.middle:o,s=t.textAlign,l=void 0===s?e.spec.TextAlignment.left:s,c=t.letterSpace,h=t.lineHeight,u=t.wrapEnabled,f=t.maxTextWidth,p=t.maxTextHeight,g=t.sizeMode,x=void 0===g?e.spec.TextSizeMode.autoWidth:g,d=t.useLegacyRichText;this.letterSpace=void 0===c?0:c,this.lineHeight=void 0===h?.571:h,this.useLegacyRichText=void 0!==d&&d,this.overflow=r,this.textVerticalAlign=a,this.textAlign=l,this.width=i?i[0]:100,this.height=i?i[1]:100,this.wrapEnabled=void 0!==u&&u,this.maxTextWidth=(void 0===f?350:f)*50,this.maxTextHeight=(void 0===p?1e3:p)*50,this.sizeMode=x}var i=t.prototype;return i.getOffsetY=function(t,i,n,r,o){var a=t.outlineWidth,s=t.fontScale,l=(n-r)/3,c=r+a*s,h=void 0!==o?o:n*(i-1),u=0;switch(this.textVerticalAlign){case e.spec.TextVerticalAlign.top:u=c+l;break;case e.spec.TextVerticalAlign.middle:u=(this.height*s-h+c)/2;break;case e.spec.TextVerticalAlign.bottom:u=this.height*s-h-l}return u},i.getOffsetX=function(t,i){var n=0;switch(this.textAlign){case e.spec.TextAlignment.left:n=t.outlineWidth*t.fontScale;break;case e.spec.TextAlignment.middle:n=(this.width*t.fontScale-i)/2;break;case e.spec.TextAlignment.right:n=this.width*t.fontScale-i}return n},i.getOffsetYRich=function(t,i,n){if(0===i.length)return 0;var r=t.outlineWidth,o=t.fontScale,a=i.reduce(function(t,e){return t+e},0),s=(i[0]-n)/3,l=n+r*o,c=a-i[0],h=0;switch(this.textVerticalAlign){case e.spec.TextVerticalAlign.top:h=l+s;break;case e.spec.TextVerticalAlign.middle:h=(this.height*o-a)/2+l;break;case e.spec.TextVerticalAlign.bottom:h=this.height*o-c-s}return h},i.getOffsetXRich=function(t,i,n){switch(this.textAlign){case e.spec.TextAlignment.left:return t.outlineWidth*t.fontScale;case e.spec.TextAlignment.middle:return(i-n)/2;case e.spec.TextAlignment.right:return i-n;default:return 0}},i.setSize=function(t,e){this.width=t,this.height=e},t}();function T(t,e){if(void 0===e&&(e=1),(3===(t=t.replace(/^#/,"")).length||4===t.length)&&(t=t.split("").map(function(t){return t+t}).join("")),8===t.length){var i=parseInt(t.slice(6,8),16)/255;t=t.slice(0,6),e=i}var n=parseInt(t,16);return[n>>16&255,n>>8&255,255&n,e]}var b=function(){function t(){}var e=t.prototype;return e.computeLines=function(t,e,i,n,r,o,a,s){var l=this,c=[],h=[],u=(n.lineHeight||0)*o,f=this.createNewLine(),p=0,g=0,x=function(){if(0!==f.chars.length){f.lineHeight=0===c.length?(f.lineAscent||0)+(f.lineDescent||0):u;var t=0===c.length?0:h[h.length-1]+u;h.push(t),g+=f.lineHeight,c.push(f),p=Math.max(p,f.width),f=l.createNewLine()}};t.forEach(function(t){var n=t.text,r=t.isNewLine,l=t.fontSize;r&&x();var c=t.fontStyle||i.fontStyle||"normal";e.font=c+" "+(t.fontWeight||i.textWeight)+" 10px "+(t.fontFamily||i.fontFamily),f.offsetX.push(f.width);for(var h=0,u=[],p=0,g=0,d=0;d<n.length;d++){var v=n[d],m=e.measureText(v),y=m.width,S=(y<=0?0:y)*l*s*o,T=l*o*s,b=m.actualBoundingBoxAscent*T,w=m.actualBoundingBoxDescent*T;p=Math.max(p,b),g=Math.max(g,w),d>0&&(h+=a),u.push({char:v,x:h}),h+=S}f.chars.push(u),f.width+=h,f.richOptions.push(t),f.lineAscent=Math.max(f.lineAscent||0,p),f.lineDescent=Math.max(f.lineDescent||0,g)}),x();var d=1/0,v=-1/0;if(0===c.length)return{lines:c,maxLineWidth:p,totalHeight:g,bboxTop:0,bboxBottom:0,bboxHeight:0};for(var m=0;m<c.length;m++)d=Math.min(d,h[m]-(c[m].lineAscent||0)),v=Math.max(v,h[m]+(c[m].lineDescent||0));var y=v-d;return{lines:c,maxLineWidth:p,totalHeight:g,bboxTop:d,bboxBottom:v,bboxHeight:y}},e.createNewLine=function(){return{richOptions:[],offsetX:[],width:0,lineHeight:0,offsetY:0,chars:[],lineAscent:0,lineDescent:0}},t}(),w=function(){function t(){}var e=t.prototype;return e.computeLines=function(t,e,i,n,r,o,a,s){var l=this,c=[],h=[],u=(n.lineHeight||0)*o,f=this.createNewLine(),p=0,g=0,x=null,d=0,v=[],m=null,y=function(){if(S(),0!==f.chars.length){f.lineHeight=0===c.length?(f.lineAscent||0)+(f.lineDescent||0):u;var t=0===c.length?0:h[h.length-1]+u;h.push(t),g+=f.lineHeight,c.push(f),p=Math.max(p,f.width),f=l.createNewLine(),x=null,d=0,v=[],m=null}},S=function(){0!==v.length&&(null===x&&(x=f.width),f.offsetX.push(x),f.chars.push(v),m&&f.richOptions.push(m),x=null,d=0,v=[],m=null)};t.forEach(function(t){var r=t.text,l=t.isNewLine,c=t.fontSize,h=t.fontStyle||i.fontStyle||"normal";e.font=h+" "+(t.fontWeight||i.textWeight)+" 10px "+(t.fontFamily||i.fontFamily),l&&(S(),y());for(var u=0;u<r.length;u++){var p=r[u],g=e.measureText(p),T=g.width,b=(T<=0?0:T)*c*s*o,w=c*o*s,A=g.actualBoundingBoxAscent*w,O=g.actualBoundingBoxDescent*w,C=v.length>0?a:0;f.width+C+b>(n.maxTextWidth||1/0)&&(S(),y()),null===x&&(x=f.width,m=t),v.length>0&&(d+=a,f.width+=a),v.push({char:p,x:d}),f.lineAscent=Math.max(f.lineAscent||0,A),f.lineDescent=Math.max(f.lineDescent||0,O),d+=b,f.width+=b}S()}),y();for(var T=1/0,b=-1/0,w=0;w<c.length;w++)T=Math.min(T,h[w]-(c[w].lineAscent||0)),b=Math.max(b,h[w]+(c[w].lineDescent||0));var A=b-T;return{lines:c,maxLineWidth:p,totalHeight:g,bboxTop:T,bboxBottom:b,bboxHeight:A}},e.createNewLine=function(){return{richOptions:[],offsetX:[],width:0,lineHeight:0,offsetY:0,chars:[],lineAscent:0,lineDescent:0}},t}(),A=function(){function t(){}return t.prototype.apply=function(t,e,i,n){var r=function(t,e){return Math.abs(e)>1e-5?t/e:1},o=i.maxTextWidth*n.fontScale,a=i.maxTextHeight*n.fontScale,s=Math.max(1,null!=(h=e.contentWidth)?h:e.canvasWidth),l=Math.max(1,null!=(u=e.bboxHeight)?u:e.canvasHeight),c=Math.min(1,r(o,s),r(a,l));if(c>.9999)return{globalScale:1};for(var h,u,f,g=p(t);!(f=g()).done;){var x=f.value;if(x.width*=c,x.lineHeight*=c,x.offsetX)for(var d=0;d<x.offsetX.length;d++)x.offsetX[d]*=c;for(var v,m=p(x.chars||[]);!(v=m()).done;)for(var y,S=v.value,T=p(S);!(y=T()).done;){var b=y.value;b.x*=c}for(var w,A=p(x.richOptions||[]);!(w=A()).done;){var O=w.value;O.fontSize*=c}null!=x.lineAscent&&(x.lineAscent*=c),null!=x.lineDescent&&(x.lineDescent*=c)}return{globalScale:c}},t}(),O=function(){function t(){}return t.prototype.apply=function(t,e,i,n){return{globalScale:1}},t}(),C=function(){function t(){}return t.prototype.apply=function(t,e,i,n){return{globalScale:1}},t}(),z=function(){function t(){}return t.prototype.getHorizontalOffsets=function(t,i,n,r,o){var a,s,l=null!=(a=i.containerWidth)?a:r.maxTextWidth*o.fontScale,c=null!=(s=i.baselineCompensationX)?s:0,h=t.map(function(t){return r.getOffsetXRich(o,l,t.width)});return{lineOffsets:r.overflow===e.spec.TextOverflow.visible?h.map(function(t){return t+c}):h}},t}(),L=function(){function t(){}return t.prototype.getVerticalOffsets=function(t,i,n,r,o,a){var s=null!=(c=i.baselineCompensationY)?c:0,l=0;if(0===t.length)return{baselineY:0,lineYOffsets:[]};switch(r.overflow){case e.spec.TextOverflow.visible:var c,h,u,f,p,g=r.maxTextHeight*o.fontScale,x=null!=(h=i.bboxTop)?h:0,d=null!=(f=i.bboxBottom)?f:x+(null!=(u=i.bboxHeight)?u:0),v=null!=(p=i.bboxHeight)?p:d-x,m=0;switch(r.textVerticalAlign){case e.spec.TextVerticalAlign.top:m=-x;break;case e.spec.TextVerticalAlign.middle:m=(g-v)/2-x;break;case e.spec.TextVerticalAlign.bottom:m=g-v-x}l=m+s;break;case e.spec.TextOverflow.clip:for(var y=r.maxTextHeight*o.fontScale,S=[0],T=1;T<t.length;T++)S[T]=S[T-1]+t[T].lineHeight;for(var b=1/0,w=-1/0,A=0;A<t.length;A++){var O,C,z=null!=(O=t[A].lineAscent)?O:0,L=null!=(C=t[A].lineDescent)?C:0;b=Math.min(b,S[A]-z),w=Math.max(w,S[A]+L)}var E=w-b,H=0;switch(r.textVerticalAlign){case e.spec.TextVerticalAlign.top:H=-b;break;case e.spec.TextVerticalAlign.middle:H=(y-E)/2-b;break;case e.spec.TextVerticalAlign.bottom:H=y-E-b}l=H+s;break;case e.spec.TextOverflow.display:for(var W=r.maxTextHeight*o.fontScale,M=[0],V=1;V<t.length;V++)M[V]=M[V-1]+t[V].lineHeight;for(var R=1/0,k=-1/0,F=0;F<t.length;F++){var _,D,B=null!=(_=t[F].lineAscent)?_:0,P=null!=(D=t[F].lineDescent)?D:0;R=Math.min(R,M[F]-B),k=Math.max(k,M[F]+P)}var X=k-R,Y=0;switch(r.textVerticalAlign){case e.spec.TextVerticalAlign.top:Y=-R;break;case e.spec.TextVerticalAlign.middle:Y=(W-X)/2-R;break;case e.spec.TextVerticalAlign.bottom:Y=W-X-R}for(var j=[],N=Y,I=0;I<t.length;I++)j.push(N),I<t.length-1&&(N+=t[I+1].lineHeight);return{baselineY:Y,lineYOffsets:j}}var U=[],$=l;return t.forEach(function(e,i){U.push($),i<t.length-1&&($+=t[i+1].lineHeight)}),{baselineY:l,lineYOffsets:U}},t}(),E=function(){function t(){}return t.createWrapStrategy=function(t){return t?new w:new b},t.createOverflowStrategy=function(t){switch(t){case e.spec.TextOverflow.clip:return new O;case e.spec.TextOverflow.display:return new A;case e.spec.TextOverflow.visible:default:return new C}},t.createHorizontalAlignStrategy=function(){return new z},t.createVerticalAlignStrategy=function(){return new L},t}(),H=0;t.RichTextComponent=function(t){function i(i){var n;return(n=t.call(this,i)||this).isDirty=!0,n.text="",n.processedTextOptions=[],n.singleLineHeight=1.571,n.size=null,n.initialized=!1,n.canvasSize=null,n.SCALE_FACTOR=.1,n.ALPHA_FIX_VALUE=1/255,n.name="MRichText"+H++,n.initTextBase(i),n.richWrapStrategy=E.createWrapStrategy(),n.richOverflowStrategy=E.createOverflowStrategy(e.spec.TextOverflow.display),n.richHorizontalAlignStrategy=E.createHorizontalAlignStrategy(),n.richVerticalAlignStrategy=E.createVerticalAlignStrategy(),n}a(i,t);var n=i.prototype;return n.onUpdate=function(e){t.prototype.onUpdate.call(this,e),this.updateTexture()},n.onDestroy=function(){t.prototype.onDestroy.call(this),this.disposeTextTexture()},n.fromData=function(i){t.prototype.fromData.call(this,i);var n=i.interaction,r=i.options;this.interaction=n,this.textStyle=new e.TextStyle(r),this.textLayout=new S(r),this.text=r.text?r.text.toString():" ",this.textLayout.useLegacyRichText&&(this.textLayout.textVerticalAlign=e.spec.TextVerticalAlign.middle),this.updateStrategies(),this.renderText(r),this.material.setColor("_Color",new e.math.Color(1,1,1,1))},n.updateStrategies=function(){var t=this.textLayout;t&&(this.richWrapStrategy=E.createWrapStrategy(t.wrapEnabled),this.richOverflowStrategy=E.createOverflowStrategy(t.overflow))},n.generateTextProgram=function(t){var i=this;this.processedTextOptions=[],y(function(t,n){/^\n+$/.test(t)&&(t=t.replace(/\n/g,"\n ")),t.split("\n").forEach(function(t,r){var o={text:t,fontSize:i.textStyle.fontSize,isNewLine:!1};r>0&&(o.isNewLine=!0),"b"in n&&(o.fontWeight=e.spec.TextWeight.bold),"i"in n&&(o.fontStyle=e.spec.FontStyle.italic),"size"in n&&n.size&&(o.fontSize=parseInt(n.size,10)),"color"in n&&n.color&&(o.fontColor=function(t,e){if(void 0===e&&(e=1),"string"!=typeof t||!t)throw Error("Invalid color string");return t.startsWith("#")?T(t,e):T(function(t){if("string"!=typeof t||!t)throw Error("Invalid color name provided");if("undefined"==typeof document)throw Error("This method requires a browser environment");var e=document.createElement("canvas"),i=e.getContext("2d");if(i)try{return i.fillStyle=t,i.fillStyle}finally{null==e.remove||e.remove.call(e)}throw Error("Failed to get 2D context for color conversion!")}(t))}(n.color)),i.processedTextOptions.push(o)})})(t)},n.updateWithOptions=function(t){this.textStyle=new e.TextStyle(t),this.textLayout=new S(t),this.text=t.text?t.text.toString():" ",this.textLayout.useLegacyRichText&&(this.textLayout.textVerticalAlign=e.spec.TextVerticalAlign.middle),this.updateStrategies(),this.isDirty=!0},n.renderText=function(t){var i=t.size;i&&(this.canvasSize=new e.math.Vector2(i[0],i[1])),this.updateTexture()},n.updateTexture=function(t){if(void 0===t&&(t=!0),this.isDirty&&this.context&&this.canvas&&this.textStyle&&this.textLayout){var e=!0===this.textLayout.useLegacyRichText;this.singleLineHeight=e?1.571:1,e?this.updateTextureLegacy(t):this.updateTextureWithStrategies(t)}},n.updateTextureLegacy=function(t){var i=this;if(this.isDirty&&this.context&&this.canvas&&this.textStyle){this.generateTextProgram(this.text);var n=0,r=0,o=this.textLayout,a=this.textStyle,s=o.overflow,l=o.letterSpace,c=void 0===l?0:l,h=this.context,u=[],f=a.fontSize*a.fontScale,p={richOptions:[],offsetX:[],width:0,lineHeight:f*this.singleLineHeight,offsetY:f*(this.singleLineHeight-1)/2};if(this.processedTextOptions.forEach(function(t){var e=t.text,o=t.isNewLine,s=t.fontSize;o&&(u.push(p),n=Math.max(n,p.width),p={richOptions:[],offsetX:[],width:0,lineHeight:f*i.singleLineHeight,offsetY:f*(i.singleLineHeight-1)/2},r+=p.lineHeight),h.font=(t.fontWeight||a.textWeight)+" 10px "+(t.fontFamily||a.fontFamily);var l=h.measureText(e),g=l.width;if(void 0!==l.actualBoundingBoxLeft&&void 0!==l.actualBoundingBoxRight){var x=l.actualBoundingBoxLeft+l.actualBoundingBoxRight;x>0&&(g=Math.max(g,x))}var d=s*i.singleLineHeight*a.fontScale;d>p.lineHeight&&(r+=d-p.lineHeight,p.lineHeight=d,p.offsetY=s*a.fontScale*(i.singleLineHeight-1)/2),p.offsetX.push(p.width),p.width+=(g<=0?0:g)*s*i.SCALE_FACTOR*a.fontScale+e.length*c,p.richOptions.push(t)}),u.push(p),n=Math.max(n,p.width),r+=p.lineHeight,0===n||0===r){this.isDirty=!1;return}(void 0===this.size||null===this.size)&&(this.size=this.item.transform.size.clone());var g=this.size,x=g.x,d=g.y;if(!this.initialized){this.canvasSize=this.canvasSize?this.canvasSize:new e.math.Vector2(n,r);var v=this.canvasSize,m=v.x,y=v.y;this.item.transform.size.set((void 0===x?1:x)*m*this.SCALE_FACTOR*this.SCALE_FACTOR,(void 0===d?1:d)*y*this.SCALE_FACTOR*this.SCALE_FACTOR),this.size=this.item.transform.size.clone(),this.initialized=!0}e.assertExist(this.canvasSize);var S=this.canvasSize,T=S.x,b=S.y;o.width=T/a.fontScale,o.height=b/a.fontScale,this.renderToTexture(T,b,t,function(t){if(0!==u.length){var n=o.getOffsetY(a,u.length,f*i.singleLineHeight,a.fontSize);u.forEach(function(i,r){var l=i.richOptions,c=i.offsetX,h=i.width,u=h,f=c;if(s===e.spec.TextOverflow.display&&h>T){var p=T/h;u*=p,f=c.map(function(t){return t*p})}var g=o.getOffsetX(a,u);r>0&&(n+=i.lineHeight-i.offsetY),l.forEach(function(i,r){var o=a.fontScale,l=a.textColor,c=a.fontFamily,u=a.textWeight,p=a.fontStyle,x=i.text,d=i.fontSize,v=i.fontColor,m=void 0===v?l:v,y=i.fontFamily,S=i.fontWeight,b=i.fontStyle,w=d;s===e.spec.TextOverflow.display&&h>T&&(w/=h/T);var A=f[r]+g;t.font=(void 0===b?p:b)+" "+(void 0===S?u:S)+" "+w*o+"px "+(void 0===y?c:y);var O=m[0],C=m[1],z=m[2],L=m[3];t.fillStyle="rgba("+O+", "+C+", "+z+", "+L+")",t.fillText(x,A,n)})})}},{disposeOld:!1}),this.isDirty=!1}},n.updateTextureWithStrategies=function(t){var i=this;if(this.isDirty&&this.context&&this.canvas){this.generateTextProgram(this.text);var n=this.textLayout,r=n.letterSpace,o=this.context;if(o){var a=this.richWrapStrategy.computeLines(this.processedTextOptions,o,this.textStyle,n,this.singleLineHeight,this.textStyle.fontScale,void 0===r?0:r,this.SCALE_FACTOR);if(0===a.lines.length||0===a.maxLineWidth||0===a.totalHeight){this.isDirty=!1;return}var s=this.resolveCanvasSize(a,n,this.textStyle,this.singleLineHeight);this.setCanvasSize(s);var l=this.richOverflowStrategy.apply(a.lines,s,n,this.textStyle),c=this.richHorizontalAlignStrategy.getHorizontalOffsets(a.lines,s,l,n,this.textStyle),h=this.richVerticalAlignStrategy.getVerticalOffsets(a.lines,s,l,n,this.textStyle,this.singleLineHeight);e.assertExist(this.canvasSize);var u=this.canvasSize,f=u.x,p=u.y,g=Math.max(1,Math.ceil(f)),x=Math.max(1,Math.ceil(p));n.width=g/this.textStyle.fontScale,n.height=x/this.textStyle.fontScale,this.renderToTexture(g,x,t,function(t){i.drawTextWithStrategies(t,a.lines,c,h,l,i.textStyle)},{disposeOld:!1}),this.isDirty=!1}}},n.setCanvasSize=function(t){var i=this;(void 0===this.size||null===this.size)&&(this.size=this.item.transform.size.clone());var n=this.size,r=n.x,o=n.y,a=this.textLayout,s=this.textStyle.fontScale||1,l=Math.max(1,a.maxTextWidth||0),c=Math.max(1,a.maxTextHeight||0);switch(a.overflow){case e.spec.TextOverflow.visible:var h,u=l*s,f=c*s,p=null!=(z=t.bboxTop)?z:0,g=null!=(E=t.bboxBottom)?E:p+(null!=(L=t.bboxHeight)?L:0),x=null!=(H=t.bboxHeight)?H:g-p,d=0;switch(a.textVerticalAlign){case e.spec.TextVerticalAlign.top:d=-p;break;case e.spec.TextVerticalAlign.middle:d=(f-x)/2-p;break;case e.spec.TextVerticalAlign.bottom:d=f-x-p}var v=Math.max(0,-(d+p)),m=Math.max(0,d+g-f),y=v,S=m;switch(a.textVerticalAlign){case e.spec.TextVerticalAlign.top:y=m,S=m;break;case e.spec.TextVerticalAlign.bottom:y=v,S=v;break;case e.spec.TextVerticalAlign.middle:y=v,S=m}for(var T=y,b=t.lines||[],w=b.map(function(t){return a.getOffsetXRich(i.textStyle,u,t.width)}),A=1/0,O=-1/0,C=0;C<b.length;C++){var z,L,E,H,W,M,V=null!=(W=w[C])?W:0,R=null!=(M=b[C].width)?M:0;A=Math.min(A,V),O=Math.max(O,V+R)}isFinite(A)||(A=0),isFinite(O)||(O=0);var k=Math.max(0,-A),F=Math.max(0,O-u),_=Math.ceil(u+k+F),D=Math.ceil(f+y+S);t.baselineCompensationX=k,t.baselineCompensationY=T,t.containerWidth=u,t.canvasWidth=_,t.canvasHeight=D,this.canvasSize=new e.math.Vector2(_,D);var B=null!=(h=this.size)?h:this.item.transform.size,P=B.x,X=B.y;this.item.transform.size.set((void 0===P?1:P)*_*this.SCALE_FACTOR*this.SCALE_FACTOR,(void 0===X?1:X)*D*this.SCALE_FACTOR*this.SCALE_FACTOR),this.initialized=!0;break;case e.spec.TextOverflow.clip:var Y,j=l*s,N=c*s;t.canvasWidth=j,t.canvasHeight=N,t.baselineCompensationX=0,t.baselineCompensationY=0,this.canvasSize=new e.math.Vector2(j,N),a.width=l,a.height=c;var I=null!=(Y=this.size)?Y:this.item.transform.size,U=I.x,$=I.y;this.item.transform.size.set((void 0===U?1:U)*j*this.SCALE_FACTOR*this.SCALE_FACTOR,(void 0===$?1:$)*N*this.SCALE_FACTOR*this.SCALE_FACTOR),this.initialized=!0;break;case e.spec.TextOverflow.display:if(!this.initialized){var q=l*s,G=c*s;this.canvasSize=new e.math.Vector2(q,G),this.item.transform.size.set((void 0===r?1:r)*q*this.SCALE_FACTOR*this.SCALE_FACTOR,(void 0===o?1:o)*G*this.SCALE_FACTOR*this.SCALE_FACTOR),this.initialized=!0}}},n.resolveCanvasSize=function(t,e,i,n){var r=Math.max(1,t.maxLineWidth||0),o=Math.max(1,t.totalHeight||0);return e.width=r/i.fontScale,e.height=o/i.fontScale,{canvasWidth:r,canvasHeight:o,contentWidth:t.maxLineWidth,bboxTop:t.bboxTop,bboxBottom:t.bboxBottom,bboxHeight:t.bboxHeight,lines:t.lines}},n.drawTextWithStrategies=function(t,e,i,n,r,o){var a=n.baselineY,s=i.lineOffsets;e.forEach(function(i,n){var r=i.richOptions,l=i.chars,c=s[n],h=a;r.forEach(function(e,n){var r=o.fontScale,a=o.textColor,s=o.fontFamily,u=o.textWeight,f=o.fontStyle,p=e.fontSize,g=e.fontColor,x=void 0===g?a:g,d=e.fontFamily,v=e.fontWeight,m=e.fontStyle;t.font=(void 0===m?f:m)+" "+(void 0===v?u:v)+" "+p*r+"px "+(void 0===d?s:d);var y=x[0],S=x[1],T=x[2],b=x[3];t.fillStyle="rgba("+y+", "+S+", "+T+", "+b+")";var w=i.offsetX&&i.offsetX[n]?i.offsetX[n]:0;l[n].forEach(function(e){t.fillText(e.char,c+w+e.x,h)})}),n<e.length-1&&(a+=e[n+1].lineHeight)})},n.unsupported=function(t){throw Error("RichTextComponent does not support "+t+" at runtime.")},n.setShadowOffsetY=function(t){this.unsupported("setShadowOffsetY")},n.setShadowBlur=function(t){this.unsupported("setShadowBlur")},n.setShadowOffsetX=function(t){this.unsupported("setShadowOffsetX")},n.setShadowColor=function(t){this.unsupported("setShadowColor")},n.setOutlineWidth=function(t){this.unsupported("setOutlineWidth")},n.setAutoWidth=function(t){this.unsupported("setAutoWidth")},n.setFontSize=function(t){this.unsupported("setFontSize")},n.setTextBaseline=function(t){console.warn("setTextBaseline 已废弃,请改用 setTextVerticalAlign。本次调用将转调用 setTextVerticalAlign。"),this.setTextVerticalAlign(t)},i}(e.MaskableGraphic),t.RichTextComponent=function(t,e,i,n){var r,o=arguments.length,a=o<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,i):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(t,e,i,n);else for(var s=t.length-1;s>=0;s--)(r=t[s])&&(a=(o<3?r(a):o>3?r(e,i,a):r(e,i))||a);return o>3&&a&&Object.defineProperty(e,i,a),a}([e.effectsClass(e.spec.DataType.RichTextComponent)],t.RichTextComponent),e.applyMixins(t.RichTextComponent,[e.TextComponentBase]);var W="2.8.6";e.registerPlugin("rich-text",u),e.logger.info("Plugin rich text version: "+W+"."),W!==r.version&&console.error("注意:请统一 RichText 插件与 Player 版本,不统一的版本混用会有不可预知的后果!","\nAttention: Please ensure the RichText plugin is synchronized with the Player version. Mixing and matching incompatible versions may result in unpredictable consequences!"),t.RichTextLoader=u,t.escape=function(t){if("string"!=typeof t)throw Error("Input must be a string");return t.replace(/\\/g,"\\\\").replace(/=/g,"\\=").replace(/</g,"\\<").replace(/>/g,"\\>").replace(/\//g,"\\/")},t.generateProgram=y,t.isRichText=function(t){var e=v(t).filter(function(t){var e=t.tokenType;return"ContextStart"===e||"ContextEnd"===e}),i=e.filter(function(t){return"ContextStart"===t.tokenType}),n=e.filter(function(t){return"ContextEnd"===t.tokenType});return i.length===n.length&&!!i.length&&function t(e,i){var n=e[0],r=e.slice(1);if(void 0===i&&(i=[]),!n)return 0===i.length;if("ContextStart"===n.tokenType)return t(r,i.concat(n.value));if("ContextEnd"===n.tokenType)return i[i.length-1]===n.value&&t(r,i.slice(0,-1));throw Error("Unexpected token: "+n.tokenType)}(e.map(function(t){var e=t.tokenType,i=t.value;return{tokenType:e,value:"ContextStart"===e?i.match(g)[1]:i.match(x)[1]}}))},t.lexer=v,t.richTextParser=m,t.unescape=function(t){if("string"!=typeof t)throw Error("Input must be a string");return t.replace(/\\\//g,"/").replace(/\\>/g,">").replace(/\\</g,"<").replace(/\\=/g,"=").replace(/\\\\/g,"\\")},t.version=W,Object.defineProperty(t,"__esModule",{value:!0})});
8
8
  //# sourceMappingURL=index.min.js.map
package/dist/index.mjs CHANGED
@@ -3,7 +3,7 @@
3
3
  * Description: Galacean Effects player rich text plugin
4
4
  * Author: Ant Group CO., Ltd.
5
5
  * Contributors: 云垣
6
- * Version: v2.8.4
6
+ * Version: v2.8.6
7
7
  */
8
8
 
9
9
  import * as EFFECTS from '@galacean/effects';
@@ -1723,7 +1723,7 @@ applyMixins(RichTextComponent, [
1723
1723
 
1724
1724
  /**
1725
1725
  * 插件版本号
1726
- */ var version = "2.8.4";
1726
+ */ var version = "2.8.6";
1727
1727
  registerPlugin("rich-text", RichTextLoader);
1728
1728
  logger.info("Plugin rich text version: " + version + ".");
1729
1729
  if (version !== EFFECTS.version) {
package/dist/weapp.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@galacean/effects/weapp"),e=require("@galacean/appx-adapter/weapp");function i(t){if(t&&t.__esModule)return t;var e=Object.create(null);return t&&Object.keys(t).forEach((function(i){if("default"!==i){var n=Object.getOwnPropertyDescriptor(t,i);Object.defineProperty(e,i,n.get?n:{enumerable:!0,get:function(){return t[i]}})}})),e.default=t,Object.freeze(e)}var n=i(t);function r(t,e){return r=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},r(t,e)}function a(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&&r(t,e)}function o(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(o=function(){return!!t})()}function s(t,e,i){return s=o()?Reflect.construct:function(t,e,i){var n=[null];n.push.apply(n,e);var a=new(Function.bind.apply(t,n));return i&&r(a,i.prototype),a},s.apply(null,arguments)}function l(t){return l=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},l(t)}function c(t){var e="function"==typeof Map?new Map:void 0;return c=function(t){if(null===t||(i=t,-1===Function.toString.call(i).indexOf("[native code]")))return t;var i;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,n)}function n(){return s(t,arguments,l(this).constructor)}return n.prototype=Object.create(t.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),r(n,t)},c(t)}var h,u=function(t){function e(){var e;return(e=t.apply(this,arguments)||this).name="rich-text",e}return a(e,t),e}(c(t.Plugin));function f(t,e){(null==e||e>t.length)&&(e=t.length);for(var i=0,n=new Array(e);i<e;i++)n[i]=t[i];return n}function p(t,e){var i="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(i)return(i=i.call(t)).next.bind(i);if(Array.isArray(t)||(i=function(t,e){if(t){if("string"==typeof t)return f(t,e);var i=Object.prototype.toString.call(t).slice(8,-1);return"Object"===i&&t.constructor&&(i=t.constructor.name),"Map"===i||"Set"===i?Array.from(i):"Arguments"===i||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i)?f(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){i&&(t=i);var n=0;return function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}!function(t){t.ContextStart="ContextStart",t.Text="Text",t.ContextEnd="ContextEnd",t.EscapedChar="EscapedChar"}(h||(h={}));var x=/^<([a-z]+)(=([^>]+))?>$/,g=/^<\/([a-z]+)>$/,v=[["EscapedChar",/^\\([=<>\\/])/],["ContextStart",/^<[a-z]+(=[^>]+)?>/],["ContextEnd",/^<\/[a-z]+>/],["Text",/^[^</>=\\]+/]],d=function(t,e,i){if(void 0===e&&(e=[]),void 0===i&&(i=0),!t)return e;var n=/^\\([=<>\\/])/.exec(t);if(n){var r=n[1];return d(t.slice(2),e.concat({tokenType:"Text",value:r}),i+2)}for(var a,o=p(v);!(a=o()).done;){var s=a.value,l=s[0],c=s[1];if("EscapedChar"!==l){var h=c.exec(t);if(h){var u=h[0],f=u.length;return d(t.slice(f),e.concat({tokenType:l,value:u}),i+f)}}}if(t.length>0)return d(t.slice(1),e.concat({tokenType:"Text",value:t[0]}),i+1);throw new Error('Unexpected token: "'+t[0]+'" at position '+i+' while reading "'+t+'"')},m=function(t){var e=function(){for(var t,e="",i=!1;r.length>0&&"Text"===(null==(t=r[0])?void 0:t.tokenType);){var n=o();n&&(e+=n.value,i=!0)}return i?e:void 0},i=function(){var t=s();if("ContextStart"===(null==t?void 0:t.tokenType)){o();var e,i=t.value.match(x);if(i)return{attributeName:i[1],attributeParam:null!=(e=i[3])?e:""};throw new Error("Expected a start tag marker at position "+a)}return{}},n=function(){var t=s();if("ContextEnd"===(null==t?void 0:t.tokenType)){o();var e=t.value.match(g);if(e)return{attributeName:e[1]};throw new Error("Expect an end tag marker at position "+a)}return{}},r=d(t),a=0,o=function(){var t,e=r.shift();return a+=null!=(t=null==e?void 0:e.value.length)?t:0,e},s=function(){return r[0]},l=[];return function t(r,o){for(void 0===r&&(r=[]),void 0===o&&(o="");;){var s=e();if(s)l.push({attributes:r,text:s});else{var c=i(),h=c.attributeName,u=c.attributeParam;if(!h){if(o){var f=n().attributeName;if(!f)throw new Error('Expect an end tag marker "'+o+'" at position '+a+" but found no tag!");if(f!==o)throw new Error('Expect an end tag marker "'+o+'" at position '+a+' but found tag "'+f+'"');return}break}t(r.concat({attributeName:h,attributeParam:null!=u?u:""}),h)}}}(),l};function y(t){return function(e){for(var i,n=p(m(e));!(i=n()).done;){var r=i.value,a=r.text,o=r.attributes.reduce((function(t,e){var i=e.attributeName,n=e.attributeParam;return i&&(t[i]=n),t}),{});t(a,o)}}}"function"==typeof SuppressedError&&SuppressedError;var S=function(){function e(e){this.width=0,this.height=0;var i=e.size,n=e.textOverflow,r=void 0===n?t.spec.TextOverflow.clip:n,a=e.textVerticalAlign,o=void 0===a?t.spec.TextVerticalAlign.middle:a,s=e.textAlign,l=void 0===s?t.spec.TextAlignment.left:s,c=e.letterSpace,h=void 0===c?0:c,u=e.lineHeight,f=void 0===u?.571:u,p=e.wrapEnabled,x=void 0!==p&&p,g=e.maxTextWidth,v=void 0===g?350:g,d=e.maxTextHeight,m=void 0===d?1e3:d,y=e.sizeMode,S=void 0===y?t.spec.TextSizeMode.autoWidth:y,T=e.useLegacyRichText,w=void 0!==T&&T;this.letterSpace=h,this.lineHeight=f,this.useLegacyRichText=w,this.overflow=r,this.textVerticalAlign=o,this.textAlign=l,this.width=i?i[0]:100,this.height=i?i[1]:100,this.wrapEnabled=x;this.maxTextWidth=50*v,this.maxTextHeight=50*m,this.sizeMode=S}var i=e.prototype;return i.getOffsetY=function(e,i,n,r,a){var o=e.outlineWidth,s=e.fontScale,l=(n-r)/3,c=r+o*s,h=void 0!==a?a:n*(i-1),u=0;switch(this.textVerticalAlign){case t.spec.TextVerticalAlign.top:u=c+l;break;case t.spec.TextVerticalAlign.middle:u=(this.height*s-h+c)/2;break;case t.spec.TextVerticalAlign.bottom:u=this.height*s-h-l}return u},i.getOffsetX=function(e,i){var n=0;switch(this.textAlign){case t.spec.TextAlignment.left:n=e.outlineWidth*e.fontScale;break;case t.spec.TextAlignment.middle:n=(this.width*e.fontScale-i)/2;break;case t.spec.TextAlignment.right:n=this.width*e.fontScale-i}return n},i.getOffsetYRich=function(e,i,n){if(0===i.length)return 0;var r=e.outlineWidth,a=e.fontScale,o=i.reduce((function(t,e){return t+e}),0),s=(i[0]-n)/3,l=n+r*a,c=o-i[0],h=0;switch(this.textVerticalAlign){case t.spec.TextVerticalAlign.top:h=l+s;break;case t.spec.TextVerticalAlign.middle:h=(this.height*a-o)/2+l;break;case t.spec.TextVerticalAlign.bottom:h=this.height*a-c-s}return h},i.getOffsetXRich=function(e,i,n){switch(this.textAlign){case t.spec.TextAlignment.left:return e.outlineWidth*e.fontScale;case t.spec.TextAlignment.middle:return(i-n)/2;case t.spec.TextAlignment.right:return i-n;default:return 0}},i.setSize=function(t,e){this.width=t,this.height=e},e}();function T(t,e){if(void 0===e&&(e=1),3!==(t=t.replace(/^#/,"")).length&&4!==t.length||(t=t.split("").map((function(t){return t+t})).join("")),8===t.length){var i=parseInt(t.slice(6,8),16)/255;t=t.slice(0,6),e=i}var n=parseInt(t,16);return[n>>16&255,n>>8&255,255&n,e]}function w(t,i){if(void 0===i&&(i=1),"string"!=typeof t||!t)throw new Error("Invalid color string");return t.startsWith("#")?T(t,i):T(function(t){if("string"!=typeof t||!t)throw new Error("Invalid color name provided");if(void 0===e.document)throw new Error("This method requires a browser environment");var i=e.document.createElement("canvas"),n=i.getContext("2d");if(n)try{return n.fillStyle=t,n.fillStyle}finally{null==i.remove||i.remove.call(i)}throw new Error("Failed to get 2D context for color conversion!")}(t))}var b=function(){function t(){}var e=t.prototype;return e.computeLines=function(t,e,i,n,r,a,o,s){var l=this,c=[],h=[],u=(n.lineHeight||0)*a,f=this.createNewLine(),p=0,x=0,g=function(){if(0!==f.chars.length){f.lineHeight=0===c.length?(f.lineAscent||0)+(f.lineDescent||0):u;var t=0===c.length?0:h[h.length-1]+u;h.push(t),x+=f.lineHeight,c.push(f),p=Math.max(p,f.width),f=l.createNewLine()}};t.forEach((function(t){var n=t.text,r=t.isNewLine,l=t.fontSize;r&&g();var c=t.fontStyle||i.fontStyle||"normal";e.font=c+" "+(t.fontWeight||i.textWeight)+" 10px "+(t.fontFamily||i.fontFamily),f.offsetX.push(f.width);for(var h=0,u=[],p=0,x=0,v=0;v<n.length;v++){var d=n[v],m=e.measureText(d),y=m.width,S=(y<=0?0:y)*l*s*a,T=l*a*s,w=m.actualBoundingBoxAscent*T,b=m.actualBoundingBoxDescent*T;p=Math.max(p,w),x=Math.max(x,b),v>0&&(h+=o),u.push({char:d,x:h}),h+=S}f.chars.push(u),f.width+=h,f.richOptions.push(t),f.lineAscent=Math.max(f.lineAscent||0,p),f.lineDescent=Math.max(f.lineDescent||0,x)})),g();var v=1/0,d=-1/0;if(0===c.length)return{lines:c,maxLineWidth:p,totalHeight:x,bboxTop:0,bboxBottom:0,bboxHeight:0};for(var m=0;m<c.length;m++)v=Math.min(v,h[m]-(c[m].lineAscent||0)),d=Math.max(d,h[m]+(c[m].lineDescent||0));return{lines:c,maxLineWidth:p,totalHeight:x,bboxTop:v,bboxBottom:d,bboxHeight:d-v}},e.createNewLine=function(){return{richOptions:[],offsetX:[],width:0,lineHeight:0,offsetY:0,chars:[],lineAscent:0,lineDescent:0}},t}(),A=function(){function t(){}var e=t.prototype;return e.computeLines=function(t,e,i,n,r,a,o,s){var l=this,c=[],h=[],u=(n.lineHeight||0)*a,f=this.createNewLine(),p=0,x=0,g=null,v=0,d=[],m=null,y=function(){if(S(),0!==f.chars.length){f.lineHeight=0===c.length?(f.lineAscent||0)+(f.lineDescent||0):u;var t=0===c.length?0:h[h.length-1]+u;h.push(t),x+=f.lineHeight,c.push(f),p=Math.max(p,f.width),f=l.createNewLine(),g=null,v=0,d=[],m=null}},S=function(){0!==d.length&&(null===g&&(g=f.width),f.offsetX.push(g),f.chars.push(d),m&&f.richOptions.push(m),g=null,v=0,d=[],m=null)};t.forEach((function(t){var r=t.text,l=t.isNewLine,c=t.fontSize,h=t.fontStyle||i.fontStyle||"normal";e.font=h+" "+(t.fontWeight||i.textWeight)+" 10px "+(t.fontFamily||i.fontFamily),l&&(S(),y());for(var u=0;u<r.length;u++){var p=r[u],x=e.measureText(p),T=x.width,w=(T<=0?0:T)*c*s*a,b=c*a*s,A=x.actualBoundingBoxAscent*b,O=x.actualBoundingBoxDescent*b,C=d.length>0?o:0;f.width+C+w>(n.maxTextWidth||1/0)&&(S(),y()),null===g&&(g=f.width,m=t),d.length>0&&(v+=o,f.width+=o),d.push({char:p,x:v}),f.lineAscent=Math.max(f.lineAscent||0,A),f.lineDescent=Math.max(f.lineDescent||0,O),v+=w,f.width+=w}S()})),y();for(var T=1/0,w=-1/0,b=0;b<c.length;b++)T=Math.min(T,h[b]-(c[b].lineAscent||0)),w=Math.max(w,h[b]+(c[b].lineDescent||0));return{lines:c,maxLineWidth:p,totalHeight:x,bboxTop:T,bboxBottom:w,bboxHeight:w-T}},e.createNewLine=function(){return{richOptions:[],offsetX:[],width:0,lineHeight:0,offsetY:0,chars:[],lineAscent:0,lineDescent:0}},t}(),O=function(){function t(){}return t.prototype.apply=function(t,e,i,n){var r,a,o=function(t,e){return Math.abs(e)>1e-5?t/e:1},s=i.maxTextWidth*n.fontScale,l=i.maxTextHeight*n.fontScale,c=Math.max(1,null!=(r=e.contentWidth)?r:e.canvasWidth),h=Math.max(1,null!=(a=e.bboxHeight)?a:e.canvasHeight),u=Math.min(1,o(s,c),o(l,h));if(u>.9999)return{globalScale:1};for(var f,x=p(t);!(f=x()).done;){var g=f.value;if(g.width*=u,g.lineHeight*=u,g.offsetX)for(var v=0;v<g.offsetX.length;v++)g.offsetX[v]*=u;for(var d,m=p(g.chars||[]);!(d=m()).done;)for(var y,S=p(d.value);!(y=S()).done;){y.value.x*=u}for(var T,w=p(g.richOptions||[]);!(T=w()).done;){T.value.fontSize*=u}null!=g.lineAscent&&(g.lineAscent*=u),null!=g.lineDescent&&(g.lineDescent*=u)}return{globalScale:u}},t}(),C=function(){function t(){}return t.prototype.apply=function(t,e,i,n){return{globalScale:1}},t}(),z=function(){function t(){}return t.prototype.apply=function(t,e,i,n){return{globalScale:1}},t}(),L=function(){function e(){}return e.prototype.getHorizontalOffsets=function(e,i,n,r,a){var o,s,l=null!=(o=i.containerWidth)?o:r.maxTextWidth*a.fontScale,c=null!=(s=i.baselineCompensationX)?s:0,h=e.map((function(t){return r.getOffsetXRich(a,l,t.width)}));return{lineOffsets:r.overflow===t.spec.TextOverflow.visible?h.map((function(t){return t+c})):h}},e}(),E=function(){function e(){}return e.prototype.getVerticalOffsets=function(e,i,n,r,a,o){var s,l=null!=(s=i.baselineCompensationY)?s:0,c=0;if(0===e.length)return{baselineY:0,lineYOffsets:[]};switch(r.overflow){case t.spec.TextOverflow.visible:var h,u,f,p,x=r.maxTextHeight*a.fontScale,g=null!=(h=i.bboxTop)?h:0,v=null!=(f=i.bboxBottom)?f:g+(null!=(u=i.bboxHeight)?u:0),d=null!=(p=i.bboxHeight)?p:v-g,m=0;switch(r.textVerticalAlign){case t.spec.TextVerticalAlign.top:m=-g;break;case t.spec.TextVerticalAlign.middle:m=(x-d)/2-g;break;case t.spec.TextVerticalAlign.bottom:m=x-d-g}c=m+l;break;case t.spec.TextOverflow.clip:for(var y=r.maxTextHeight*a.fontScale,S=[0],T=1;T<e.length;T++)S[T]=S[T-1]+e[T].lineHeight;for(var w=1/0,b=-1/0,A=0;A<e.length;A++){var O,C,z=null!=(O=e[A].lineAscent)?O:0,L=null!=(C=e[A].lineDescent)?C:0;w=Math.min(w,S[A]-z),b=Math.max(b,S[A]+L)}var E=b-w,H=0;switch(r.textVerticalAlign){case t.spec.TextVerticalAlign.top:H=-w;break;case t.spec.TextVerticalAlign.middle:H=(y-E)/2-w;break;case t.spec.TextVerticalAlign.bottom:H=y-E-w}c=H+l;break;case t.spec.TextOverflow.display:for(var W=r.maxTextHeight*a.fontScale,M=[0],V=1;V<e.length;V++)M[V]=M[V-1]+e[V].lineHeight;for(var R=1/0,k=-1/0,F=0;F<e.length;F++){var _,D,B=null!=(_=e[F].lineAscent)?_:0,P=null!=(D=e[F].lineDescent)?D:0;R=Math.min(R,M[F]-B),k=Math.max(k,M[F]+P)}var X=k-R,Y=0;switch(r.textVerticalAlign){case t.spec.TextVerticalAlign.top:Y=-R;break;case t.spec.TextVerticalAlign.middle:Y=(W-X)/2-R;break;case t.spec.TextVerticalAlign.bottom:Y=W-X-R}for(var j=[],N=Y,I=0;I<e.length;I++)j.push(N),I<e.length-1&&(N+=e[I+1].lineHeight);return{baselineY:Y,lineYOffsets:j}}var U=[],q=c;return e.forEach((function(t,i){U.push(q),i<e.length-1&&(q+=e[i+1].lineHeight)})),{baselineY:c,lineYOffsets:U}},e}(),H=function(){function e(){}return e.createWrapStrategy=function(t){return t?new A:new b},e.createOverflowStrategy=function(e){switch(e){case t.spec.TextOverflow.clip:return new C;case t.spec.TextOverflow.display:return new O;case t.spec.TextOverflow.visible:default:return new z}},e.createHorizontalAlignStrategy=function(){return new L},e.createVerticalAlignStrategy=function(){return new E},e}(),W=0;exports.RichTextComponent=function(e){function i(i){var n;return(n=e.call(this,i)||this).isDirty=!0,n.text="",n.processedTextOptions=[],n.singleLineHeight=1.571,n.size=null,n.initialized=!1,n.canvasSize=null,n.SCALE_FACTOR=.1,n.ALPHA_FIX_VALUE=1/255,n.name="MRichText"+W++,n.initTextBase(i),n.richWrapStrategy=H.createWrapStrategy(),n.richOverflowStrategy=H.createOverflowStrategy(t.spec.TextOverflow.display),n.richHorizontalAlignStrategy=H.createHorizontalAlignStrategy(),n.richVerticalAlignStrategy=H.createVerticalAlignStrategy(),n}a(i,e);var n=i.prototype;return n.onUpdate=function(t){e.prototype.onUpdate.call(this,t),this.updateTexture()},n.onDestroy=function(){e.prototype.onDestroy.call(this),this.disposeTextTexture()},n.fromData=function(i){e.prototype.fromData.call(this,i);var n=i.interaction,r=i.options;this.interaction=n,this.textStyle=new t.TextStyle(r),this.textLayout=new S(r),this.text=r.text?r.text.toString():" ",this.textLayout.useLegacyRichText&&(this.textLayout.textVerticalAlign=t.spec.TextVerticalAlign.middle),this.updateStrategies(),this.renderText(r),this.material.setColor("_Color",new t.math.Color(1,1,1,1))},n.updateStrategies=function(){var t=this.textLayout;t&&(this.richWrapStrategy=H.createWrapStrategy(t.wrapEnabled),this.richOverflowStrategy=H.createOverflowStrategy(t.overflow))},n.generateTextProgram=function(e){var i=this;this.processedTextOptions=[];var n=y((function(e,n){/^\n+$/.test(e)&&(e=e.replace(/\n/g,"\n ")),e.split("\n").forEach((function(e,r){var a={text:e,fontSize:i.textStyle.fontSize,isNewLine:!1};r>0&&(a.isNewLine=!0),"b"in n&&(a.fontWeight=t.spec.TextWeight.bold),"i"in n&&(a.fontStyle=t.spec.FontStyle.italic),"size"in n&&n.size&&(a.fontSize=parseInt(n.size,10)),"color"in n&&n.color&&(a.fontColor=w(n.color)),i.processedTextOptions.push(a)}))}));n(e)},n.updateWithOptions=function(e){this.textStyle=new t.TextStyle(e),this.textLayout=new S(e),this.text=e.text?e.text.toString():" ",this.textLayout.useLegacyRichText&&(this.textLayout.textVerticalAlign=t.spec.TextVerticalAlign.middle),this.updateStrategies(),this.isDirty=!0},n.renderText=function(e){var i=e.size;i&&(this.canvasSize=new t.math.Vector2(i[0],i[1])),this.updateTexture()},n.updateTexture=function(t){if(void 0===t&&(t=!0),this.isDirty&&this.context&&this.canvas&&this.textStyle&&this.textLayout){var e=!0===this.textLayout.useLegacyRichText;this.singleLineHeight=e?1.571:1,e?this.updateTextureLegacy(t):this.updateTextureWithStrategies(t)}},n.updateTextureLegacy=function(e){var i=this;if(this.isDirty&&this.context&&this.canvas&&this.textStyle){this.generateTextProgram(this.text);var n=0,r=0,a=this.textLayout,o=this.textStyle,s=a.overflow,l=a.letterSpace,c=void 0===l?0:l,h=this.context,u=[],f=o.fontSize*o.fontScale,p={richOptions:[],offsetX:[],width:0,lineHeight:f*this.singleLineHeight,offsetY:f*(this.singleLineHeight-1)/2};if(this.processedTextOptions.forEach((function(t){var e=t.text,a=t.isNewLine,s=t.fontSize;a&&(u.push(p),n=Math.max(n,p.width),p={richOptions:[],offsetX:[],width:0,lineHeight:f*i.singleLineHeight,offsetY:f*(i.singleLineHeight-1)/2},r+=p.lineHeight),h.font=(t.fontWeight||o.textWeight)+" 10px "+(t.fontFamily||o.fontFamily);var l=h.measureText(e),x=l.width;if(void 0!==l.actualBoundingBoxLeft&&void 0!==l.actualBoundingBoxRight){var g=l.actualBoundingBoxLeft+l.actualBoundingBoxRight;g>0&&(x=Math.max(x,g))}var v=s*i.singleLineHeight*o.fontScale;v>p.lineHeight&&(r+=v-p.lineHeight,p.lineHeight=v,p.offsetY=s*o.fontScale*(i.singleLineHeight-1)/2),p.offsetX.push(p.width),p.width+=(x<=0?0:x)*s*i.SCALE_FACTOR*o.fontScale+e.length*c,p.richOptions.push(t)})),u.push(p),n=Math.max(n,p.width),r+=p.lineHeight,0!==n&&0!==r){void 0!==this.size&&null!==this.size||(this.size=this.item.transform.size.clone());var x=this.size,g=x.x,v=void 0===g?1:g,d=x.y,m=void 0===d?1:d;if(!this.initialized){this.canvasSize=this.canvasSize?this.canvasSize:new t.math.Vector2(n,r);var y=this.canvasSize,S=y.x,T=y.y;this.item.transform.size.set(v*S*this.SCALE_FACTOR*this.SCALE_FACTOR,m*T*this.SCALE_FACTOR*this.SCALE_FACTOR),this.size=this.item.transform.size.clone(),this.initialized=!0}t.assertExist(this.canvasSize);var w=this.canvasSize,b=w.x,A=w.y;a.width=b/o.fontScale,a.height=A/o.fontScale,this.renderToTexture(b,A,e,(function(e){if(0!==u.length){var n=a.getOffsetY(o,u.length,f*i.singleLineHeight,o.fontSize);u.forEach((function(i,r){var l=i.richOptions,c=i.offsetX,h=i.width,u=h,f=c;if(s===t.spec.TextOverflow.display&&h>b){var p=b/h;u*=p,f=c.map((function(t){return t*p}))}var x=a.getOffsetX(o,u);r>0&&(n+=i.lineHeight-i.offsetY),l.forEach((function(i,r){var a=o.fontScale,l=o.textColor,c=o.fontFamily,u=o.textWeight,p=o.fontStyle,g=i.text,v=i.fontSize,d=i.fontColor,m=void 0===d?l:d,y=i.fontFamily,S=void 0===y?c:y,T=i.fontWeight,w=void 0===T?u:T,A=i.fontStyle,O=void 0===A?p:A,C=v;s===t.spec.TextOverflow.display&&h>b&&(C/=h/b);var z=f[r]+x;e.font=O+" "+w+" "+C*a+"px "+S;var L=m[0],E=m[1],H=m[2],W=m[3];e.fillStyle="rgba("+L+", "+E+", "+H+", "+W+")",e.fillText(g,z,n)}))}))}}),{disposeOld:!1}),this.isDirty=!1}else this.isDirty=!1}},n.updateTextureWithStrategies=function(e){var i=this;if(this.isDirty&&this.context&&this.canvas){this.generateTextProgram(this.text);var n=this.textLayout,r=n.letterSpace,a=void 0===r?0:r,o=this.context;if(o){var s=this.richWrapStrategy.computeLines(this.processedTextOptions,o,this.textStyle,n,this.singleLineHeight,this.textStyle.fontScale,a,this.SCALE_FACTOR);if(0!==s.lines.length&&0!==s.maxLineWidth&&0!==s.totalHeight){var l=this.resolveCanvasSize(s,n,this.textStyle,this.singleLineHeight);this.setCanvasSize(l);var c=this.richOverflowStrategy.apply(s.lines,l,n,this.textStyle),h=this.richHorizontalAlignStrategy.getHorizontalOffsets(s.lines,l,c,n,this.textStyle),u=this.richVerticalAlignStrategy.getVerticalOffsets(s.lines,l,c,n,this.textStyle,this.singleLineHeight);t.assertExist(this.canvasSize);var f=this.canvasSize,p=f.x,x=f.y,g=Math.max(1,Math.ceil(p)),v=Math.max(1,Math.ceil(x));n.width=g/this.textStyle.fontScale,n.height=v/this.textStyle.fontScale,this.renderToTexture(g,v,e,(function(t){i.drawTextWithStrategies(t,s.lines,h,u,c,i.textStyle)}),{disposeOld:!1}),this.isDirty=!1}else this.isDirty=!1}}},n.setCanvasSize=function(e){var i=this;void 0!==this.size&&null!==this.size||(this.size=this.item.transform.size.clone());var n=this.size,r=n.x,a=void 0===r?1:r,o=n.y,s=void 0===o?1:o,l=this.textLayout,c=this.textStyle.fontScale||1,h=Math.max(1,l.maxTextWidth||0),u=Math.max(1,l.maxTextHeight||0);switch(l.overflow){case t.spec.TextOverflow.visible:var f,p,x,g,v=h*c,d=u*c,m=null!=(f=e.bboxTop)?f:0,y=null!=(x=e.bboxBottom)?x:m+(null!=(p=e.bboxHeight)?p:0),S=null!=(g=e.bboxHeight)?g:y-m,T=0;switch(l.textVerticalAlign){case t.spec.TextVerticalAlign.top:T=-m;break;case t.spec.TextVerticalAlign.middle:T=(d-S)/2-m;break;case t.spec.TextVerticalAlign.bottom:T=d-S-m}var w=T+m,b=T+y,A=Math.max(0,-w),O=Math.max(0,b-d),C=A,z=O;switch(l.textVerticalAlign){case t.spec.TextVerticalAlign.top:C=O,z=O;break;case t.spec.TextVerticalAlign.bottom:C=A,z=A;break;case t.spec.TextVerticalAlign.middle:C=A,z=O}for(var L=C,E=e.lines||[],H=E.map((function(t){return l.getOffsetXRich(i.textStyle,v,t.width)})),W=1/0,M=-1/0,V=0;V<E.length;V++){var R,k,F=null!=(R=H[V])?R:0,_=null!=(k=E[V].width)?k:0;W=Math.min(W,F),M=Math.max(M,F+_)}isFinite(W)||(W=0),isFinite(M)||(M=0);var D,B=Math.max(0,-W),P=Math.max(0,M-v),X=Math.ceil(v+B+P),Y=Math.ceil(d+C+z);e.baselineCompensationX=B,e.baselineCompensationY=L,e.containerWidth=v,e.canvasWidth=X,e.canvasHeight=Y,this.canvasSize=new t.math.Vector2(X,Y);var j=null!=(D=this.size)?D:this.item.transform.size,N=j.x,I=void 0===N?1:N,U=j.y,q=void 0===U?1:U;this.item.transform.size.set(I*X*this.SCALE_FACTOR*this.SCALE_FACTOR,q*Y*this.SCALE_FACTOR*this.SCALE_FACTOR),this.initialized=!0;break;case t.spec.TextOverflow.clip:var $,G=h*c,J=u*c;e.canvasWidth=G,e.canvasHeight=J,e.baselineCompensationX=0,e.baselineCompensationY=0,this.canvasSize=new t.math.Vector2(G,J),l.width=h,l.height=u;var K=null!=($=this.size)?$:this.item.transform.size,Q=K.x,Z=void 0===Q?1:Q,tt=K.y,et=void 0===tt?1:tt;this.item.transform.size.set(Z*G*this.SCALE_FACTOR*this.SCALE_FACTOR,et*J*this.SCALE_FACTOR*this.SCALE_FACTOR),this.initialized=!0;break;case t.spec.TextOverflow.display:if(!this.initialized){var it=h*c,nt=u*c;this.canvasSize=new t.math.Vector2(it,nt),this.item.transform.size.set(a*it*this.SCALE_FACTOR*this.SCALE_FACTOR,s*nt*this.SCALE_FACTOR*this.SCALE_FACTOR),this.initialized=!0}}},n.resolveCanvasSize=function(t,e,i,n){var r=Math.max(1,t.maxLineWidth||0),a=Math.max(1,t.totalHeight||0);return e.width=r/i.fontScale,e.height=a/i.fontScale,{canvasWidth:r,canvasHeight:a,contentWidth:t.maxLineWidth,bboxTop:t.bboxTop,bboxBottom:t.bboxBottom,bboxHeight:t.bboxHeight,lines:t.lines}},n.drawTextWithStrategies=function(t,e,i,n,r,a){var o=n.baselineY,s=i.lineOffsets;e.forEach((function(i,n){var r=i.richOptions,l=i.chars,c=s[n],h=o;r.forEach((function(e,n){var r=a.fontScale,o=a.textColor,s=a.fontFamily,u=a.textWeight,f=a.fontStyle,p=e.fontSize,x=e.fontColor,g=void 0===x?o:x,v=e.fontFamily,d=void 0===v?s:v,m=e.fontWeight,y=void 0===m?u:m,S=e.fontStyle,T=void 0===S?f:S,w=p;t.font=T+" "+y+" "+w*r+"px "+d;var b=g[0],A=g[1],O=g[2],C=g[3];t.fillStyle="rgba("+b+", "+A+", "+O+", "+C+")";var z=i.offsetX&&i.offsetX[n]?i.offsetX[n]:0;l[n].forEach((function(e){t.fillText(e.char,c+z+e.x,h)}))})),n<e.length-1&&(o+=e[n+1].lineHeight)}))},n.unsupported=function(t){throw new Error("RichTextComponent does not support "+t+" at runtime.")},n.setShadowOffsetY=function(t){this.unsupported("setShadowOffsetY")},n.setShadowBlur=function(t){this.unsupported("setShadowBlur")},n.setShadowOffsetX=function(t){this.unsupported("setShadowOffsetX")},n.setShadowColor=function(t){this.unsupported("setShadowColor")},n.setOutlineWidth=function(t){this.unsupported("setOutlineWidth")},n.setAutoWidth=function(t){this.unsupported("setAutoWidth")},n.setFontSize=function(t){this.unsupported("setFontSize")},n.setTextBaseline=function(t){console.warn("setTextBaseline 已废弃,请改用 setTextVerticalAlign。本次调用将转调用 setTextVerticalAlign。"),this.setTextVerticalAlign(t)},i}(t.MaskableGraphic),exports.RichTextComponent=function(t,e,i,n){var r,a=arguments.length,o=a<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,i):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,e,i,n);else for(var s=t.length-1;s>=0;s--)(r=t[s])&&(o=(a<3?r(o):a>3?r(e,i,o):r(e,i))||o);return a>3&&o&&Object.defineProperty(e,i,o),o}([t.effectsClass(t.spec.DataType.RichTextComponent)],exports.RichTextComponent),t.applyMixins(exports.RichTextComponent,[t.TextComponentBase]);var M="2.8.4";t.registerPlugin("rich-text",u),t.logger.info("Plugin rich text version: 2.8.4."),M!==n.version&&console.error("注意:请统一 RichText 插件与 Player 版本,不统一的版本混用会有不可预知的后果!","\nAttention: Please ensure the RichText plugin is synchronized with the Player version. Mixing and matching incompatible versions may result in unpredictable consequences!"),exports.RichTextLoader=u,exports.escape=function(t){if("string"!=typeof t)throw new Error("Input must be a string");return t.replace(/\\/g,"\\\\").replace(/=/g,"\\=").replace(/</g,"\\<").replace(/>/g,"\\>").replace(/\//g,"\\/")},exports.generateProgram=y,exports.isRichText=function(t){var e=d(t).filter((function(t){var e=t.tokenType;return"ContextStart"===e||"ContextEnd"===e})),i=e.filter((function(t){return"ContextStart"===t.tokenType})),n=e.filter((function(t){return"ContextEnd"===t.tokenType}));return!(i.length!==n.length||!i.length)&&function t(e,i){var n=e[0],r=e.slice(1);if(void 0===i&&(i=[]),!n)return 0===i.length;if("ContextStart"===n.tokenType)return t(r,i.concat(n.value));if("ContextEnd"===n.tokenType)return i[i.length-1]===n.value&&t(r,i.slice(0,-1));throw new Error("Unexpected token: "+n.tokenType)}(e.map((function(t){var e=t.tokenType,i=t.value;return{tokenType:e,value:"ContextStart"===e?i.match(x)[1]:i.match(g)[1]}})))},exports.lexer=d,exports.richTextParser=m,exports.unescape=function(t){if("string"!=typeof t)throw new Error("Input must be a string");return t.replace(/\\\//g,"/").replace(/\\>/g,">").replace(/\\</g,"<").replace(/\\=/g,"=").replace(/\\\\/g,"\\")},exports.version=M;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@galacean/effects/weapp"),e=require("@galacean/appx-adapter/weapp");function i(t){if(t&&t.__esModule)return t;var e=Object.create(null);return t&&Object.keys(t).forEach((function(i){if("default"!==i){var n=Object.getOwnPropertyDescriptor(t,i);Object.defineProperty(e,i,n.get?n:{enumerable:!0,get:function(){return t[i]}})}})),e.default=t,Object.freeze(e)}var n=i(t);function r(t,e){return r=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},r(t,e)}function a(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&&r(t,e)}function o(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(o=function(){return!!t})()}function s(t,e,i){return s=o()?Reflect.construct:function(t,e,i){var n=[null];n.push.apply(n,e);var a=new(Function.bind.apply(t,n));return i&&r(a,i.prototype),a},s.apply(null,arguments)}function l(t){return l=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},l(t)}function c(t){var e="function"==typeof Map?new Map:void 0;return c=function(t){if(null===t||(i=t,-1===Function.toString.call(i).indexOf("[native code]")))return t;var i;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,n)}function n(){return s(t,arguments,l(this).constructor)}return n.prototype=Object.create(t.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),r(n,t)},c(t)}var h,u=function(t){function e(){var e;return(e=t.apply(this,arguments)||this).name="rich-text",e}return a(e,t),e}(c(t.Plugin));function f(t,e){(null==e||e>t.length)&&(e=t.length);for(var i=0,n=new Array(e);i<e;i++)n[i]=t[i];return n}function p(t,e){var i="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(i)return(i=i.call(t)).next.bind(i);if(Array.isArray(t)||(i=function(t,e){if(t){if("string"==typeof t)return f(t,e);var i=Object.prototype.toString.call(t).slice(8,-1);return"Object"===i&&t.constructor&&(i=t.constructor.name),"Map"===i||"Set"===i?Array.from(i):"Arguments"===i||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i)?f(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){i&&(t=i);var n=0;return function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}!function(t){t.ContextStart="ContextStart",t.Text="Text",t.ContextEnd="ContextEnd",t.EscapedChar="EscapedChar"}(h||(h={}));var x=/^<([a-z]+)(=([^>]+))?>$/,g=/^<\/([a-z]+)>$/,v=[["EscapedChar",/^\\([=<>\\/])/],["ContextStart",/^<[a-z]+(=[^>]+)?>/],["ContextEnd",/^<\/[a-z]+>/],["Text",/^[^</>=\\]+/]],d=function(t,e,i){if(void 0===e&&(e=[]),void 0===i&&(i=0),!t)return e;var n=/^\\([=<>\\/])/.exec(t);if(n){var r=n[1];return d(t.slice(2),e.concat({tokenType:"Text",value:r}),i+2)}for(var a,o=p(v);!(a=o()).done;){var s=a.value,l=s[0],c=s[1];if("EscapedChar"!==l){var h=c.exec(t);if(h){var u=h[0],f=u.length;return d(t.slice(f),e.concat({tokenType:l,value:u}),i+f)}}}if(t.length>0)return d(t.slice(1),e.concat({tokenType:"Text",value:t[0]}),i+1);throw new Error('Unexpected token: "'+t[0]+'" at position '+i+' while reading "'+t+'"')},m=function(t){var e=function(){for(var t,e="",i=!1;r.length>0&&"Text"===(null==(t=r[0])?void 0:t.tokenType);){var n=o();n&&(e+=n.value,i=!0)}return i?e:void 0},i=function(){var t=s();if("ContextStart"===(null==t?void 0:t.tokenType)){o();var e,i=t.value.match(x);if(i)return{attributeName:i[1],attributeParam:null!=(e=i[3])?e:""};throw new Error("Expected a start tag marker at position "+a)}return{}},n=function(){var t=s();if("ContextEnd"===(null==t?void 0:t.tokenType)){o();var e=t.value.match(g);if(e)return{attributeName:e[1]};throw new Error("Expect an end tag marker at position "+a)}return{}},r=d(t),a=0,o=function(){var t,e=r.shift();return a+=null!=(t=null==e?void 0:e.value.length)?t:0,e},s=function(){return r[0]},l=[];return function t(r,o){for(void 0===r&&(r=[]),void 0===o&&(o="");;){var s=e();if(s)l.push({attributes:r,text:s});else{var c=i(),h=c.attributeName,u=c.attributeParam;if(!h){if(o){var f=n().attributeName;if(!f)throw new Error('Expect an end tag marker "'+o+'" at position '+a+" but found no tag!");if(f!==o)throw new Error('Expect an end tag marker "'+o+'" at position '+a+' but found tag "'+f+'"');return}break}t(r.concat({attributeName:h,attributeParam:null!=u?u:""}),h)}}}(),l};function y(t){return function(e){for(var i,n=p(m(e));!(i=n()).done;){var r=i.value,a=r.text,o=r.attributes.reduce((function(t,e){var i=e.attributeName,n=e.attributeParam;return i&&(t[i]=n),t}),{});t(a,o)}}}"function"==typeof SuppressedError&&SuppressedError;var S=function(){function e(e){this.width=0,this.height=0;var i=e.size,n=e.textOverflow,r=void 0===n?t.spec.TextOverflow.clip:n,a=e.textVerticalAlign,o=void 0===a?t.spec.TextVerticalAlign.middle:a,s=e.textAlign,l=void 0===s?t.spec.TextAlignment.left:s,c=e.letterSpace,h=void 0===c?0:c,u=e.lineHeight,f=void 0===u?.571:u,p=e.wrapEnabled,x=void 0!==p&&p,g=e.maxTextWidth,v=void 0===g?350:g,d=e.maxTextHeight,m=void 0===d?1e3:d,y=e.sizeMode,S=void 0===y?t.spec.TextSizeMode.autoWidth:y,T=e.useLegacyRichText,w=void 0!==T&&T;this.letterSpace=h,this.lineHeight=f,this.useLegacyRichText=w,this.overflow=r,this.textVerticalAlign=o,this.textAlign=l,this.width=i?i[0]:100,this.height=i?i[1]:100,this.wrapEnabled=x;this.maxTextWidth=50*v,this.maxTextHeight=50*m,this.sizeMode=S}var i=e.prototype;return i.getOffsetY=function(e,i,n,r,a){var o=e.outlineWidth,s=e.fontScale,l=(n-r)/3,c=r+o*s,h=void 0!==a?a:n*(i-1),u=0;switch(this.textVerticalAlign){case t.spec.TextVerticalAlign.top:u=c+l;break;case t.spec.TextVerticalAlign.middle:u=(this.height*s-h+c)/2;break;case t.spec.TextVerticalAlign.bottom:u=this.height*s-h-l}return u},i.getOffsetX=function(e,i){var n=0;switch(this.textAlign){case t.spec.TextAlignment.left:n=e.outlineWidth*e.fontScale;break;case t.spec.TextAlignment.middle:n=(this.width*e.fontScale-i)/2;break;case t.spec.TextAlignment.right:n=this.width*e.fontScale-i}return n},i.getOffsetYRich=function(e,i,n){if(0===i.length)return 0;var r=e.outlineWidth,a=e.fontScale,o=i.reduce((function(t,e){return t+e}),0),s=(i[0]-n)/3,l=n+r*a,c=o-i[0],h=0;switch(this.textVerticalAlign){case t.spec.TextVerticalAlign.top:h=l+s;break;case t.spec.TextVerticalAlign.middle:h=(this.height*a-o)/2+l;break;case t.spec.TextVerticalAlign.bottom:h=this.height*a-c-s}return h},i.getOffsetXRich=function(e,i,n){switch(this.textAlign){case t.spec.TextAlignment.left:return e.outlineWidth*e.fontScale;case t.spec.TextAlignment.middle:return(i-n)/2;case t.spec.TextAlignment.right:return i-n;default:return 0}},i.setSize=function(t,e){this.width=t,this.height=e},e}();function T(t,e){if(void 0===e&&(e=1),3!==(t=t.replace(/^#/,"")).length&&4!==t.length||(t=t.split("").map((function(t){return t+t})).join("")),8===t.length){var i=parseInt(t.slice(6,8),16)/255;t=t.slice(0,6),e=i}var n=parseInt(t,16);return[n>>16&255,n>>8&255,255&n,e]}function w(t,i){if(void 0===i&&(i=1),"string"!=typeof t||!t)throw new Error("Invalid color string");return t.startsWith("#")?T(t,i):T(function(t){if("string"!=typeof t||!t)throw new Error("Invalid color name provided");if(void 0===e.document)throw new Error("This method requires a browser environment");var i=e.document.createElement("canvas"),n=i.getContext("2d");if(n)try{return n.fillStyle=t,n.fillStyle}finally{null==i.remove||i.remove.call(i)}throw new Error("Failed to get 2D context for color conversion!")}(t))}var b=function(){function t(){}var e=t.prototype;return e.computeLines=function(t,e,i,n,r,a,o,s){var l=this,c=[],h=[],u=(n.lineHeight||0)*a,f=this.createNewLine(),p=0,x=0,g=function(){if(0!==f.chars.length){f.lineHeight=0===c.length?(f.lineAscent||0)+(f.lineDescent||0):u;var t=0===c.length?0:h[h.length-1]+u;h.push(t),x+=f.lineHeight,c.push(f),p=Math.max(p,f.width),f=l.createNewLine()}};t.forEach((function(t){var n=t.text,r=t.isNewLine,l=t.fontSize;r&&g();var c=t.fontStyle||i.fontStyle||"normal";e.font=c+" "+(t.fontWeight||i.textWeight)+" 10px "+(t.fontFamily||i.fontFamily),f.offsetX.push(f.width);for(var h=0,u=[],p=0,x=0,v=0;v<n.length;v++){var d=n[v],m=e.measureText(d),y=m.width,S=(y<=0?0:y)*l*s*a,T=l*a*s,w=m.actualBoundingBoxAscent*T,b=m.actualBoundingBoxDescent*T;p=Math.max(p,w),x=Math.max(x,b),v>0&&(h+=o),u.push({char:d,x:h}),h+=S}f.chars.push(u),f.width+=h,f.richOptions.push(t),f.lineAscent=Math.max(f.lineAscent||0,p),f.lineDescent=Math.max(f.lineDescent||0,x)})),g();var v=1/0,d=-1/0;if(0===c.length)return{lines:c,maxLineWidth:p,totalHeight:x,bboxTop:0,bboxBottom:0,bboxHeight:0};for(var m=0;m<c.length;m++)v=Math.min(v,h[m]-(c[m].lineAscent||0)),d=Math.max(d,h[m]+(c[m].lineDescent||0));return{lines:c,maxLineWidth:p,totalHeight:x,bboxTop:v,bboxBottom:d,bboxHeight:d-v}},e.createNewLine=function(){return{richOptions:[],offsetX:[],width:0,lineHeight:0,offsetY:0,chars:[],lineAscent:0,lineDescent:0}},t}(),A=function(){function t(){}var e=t.prototype;return e.computeLines=function(t,e,i,n,r,a,o,s){var l=this,c=[],h=[],u=(n.lineHeight||0)*a,f=this.createNewLine(),p=0,x=0,g=null,v=0,d=[],m=null,y=function(){if(S(),0!==f.chars.length){f.lineHeight=0===c.length?(f.lineAscent||0)+(f.lineDescent||0):u;var t=0===c.length?0:h[h.length-1]+u;h.push(t),x+=f.lineHeight,c.push(f),p=Math.max(p,f.width),f=l.createNewLine(),g=null,v=0,d=[],m=null}},S=function(){0!==d.length&&(null===g&&(g=f.width),f.offsetX.push(g),f.chars.push(d),m&&f.richOptions.push(m),g=null,v=0,d=[],m=null)};t.forEach((function(t){var r=t.text,l=t.isNewLine,c=t.fontSize,h=t.fontStyle||i.fontStyle||"normal";e.font=h+" "+(t.fontWeight||i.textWeight)+" 10px "+(t.fontFamily||i.fontFamily),l&&(S(),y());for(var u=0;u<r.length;u++){var p=r[u],x=e.measureText(p),T=x.width,w=(T<=0?0:T)*c*s*a,b=c*a*s,A=x.actualBoundingBoxAscent*b,O=x.actualBoundingBoxDescent*b,C=d.length>0?o:0;f.width+C+w>(n.maxTextWidth||1/0)&&(S(),y()),null===g&&(g=f.width,m=t),d.length>0&&(v+=o,f.width+=o),d.push({char:p,x:v}),f.lineAscent=Math.max(f.lineAscent||0,A),f.lineDescent=Math.max(f.lineDescent||0,O),v+=w,f.width+=w}S()})),y();for(var T=1/0,w=-1/0,b=0;b<c.length;b++)T=Math.min(T,h[b]-(c[b].lineAscent||0)),w=Math.max(w,h[b]+(c[b].lineDescent||0));return{lines:c,maxLineWidth:p,totalHeight:x,bboxTop:T,bboxBottom:w,bboxHeight:w-T}},e.createNewLine=function(){return{richOptions:[],offsetX:[],width:0,lineHeight:0,offsetY:0,chars:[],lineAscent:0,lineDescent:0}},t}(),O=function(){function t(){}return t.prototype.apply=function(t,e,i,n){var r,a,o=function(t,e){return Math.abs(e)>1e-5?t/e:1},s=i.maxTextWidth*n.fontScale,l=i.maxTextHeight*n.fontScale,c=Math.max(1,null!=(r=e.contentWidth)?r:e.canvasWidth),h=Math.max(1,null!=(a=e.bboxHeight)?a:e.canvasHeight),u=Math.min(1,o(s,c),o(l,h));if(u>.9999)return{globalScale:1};for(var f,x=p(t);!(f=x()).done;){var g=f.value;if(g.width*=u,g.lineHeight*=u,g.offsetX)for(var v=0;v<g.offsetX.length;v++)g.offsetX[v]*=u;for(var d,m=p(g.chars||[]);!(d=m()).done;)for(var y,S=p(d.value);!(y=S()).done;){y.value.x*=u}for(var T,w=p(g.richOptions||[]);!(T=w()).done;){T.value.fontSize*=u}null!=g.lineAscent&&(g.lineAscent*=u),null!=g.lineDescent&&(g.lineDescent*=u)}return{globalScale:u}},t}(),C=function(){function t(){}return t.prototype.apply=function(t,e,i,n){return{globalScale:1}},t}(),z=function(){function t(){}return t.prototype.apply=function(t,e,i,n){return{globalScale:1}},t}(),L=function(){function e(){}return e.prototype.getHorizontalOffsets=function(e,i,n,r,a){var o,s,l=null!=(o=i.containerWidth)?o:r.maxTextWidth*a.fontScale,c=null!=(s=i.baselineCompensationX)?s:0,h=e.map((function(t){return r.getOffsetXRich(a,l,t.width)}));return{lineOffsets:r.overflow===t.spec.TextOverflow.visible?h.map((function(t){return t+c})):h}},e}(),E=function(){function e(){}return e.prototype.getVerticalOffsets=function(e,i,n,r,a,o){var s,l=null!=(s=i.baselineCompensationY)?s:0,c=0;if(0===e.length)return{baselineY:0,lineYOffsets:[]};switch(r.overflow){case t.spec.TextOverflow.visible:var h,u,f,p,x=r.maxTextHeight*a.fontScale,g=null!=(h=i.bboxTop)?h:0,v=null!=(f=i.bboxBottom)?f:g+(null!=(u=i.bboxHeight)?u:0),d=null!=(p=i.bboxHeight)?p:v-g,m=0;switch(r.textVerticalAlign){case t.spec.TextVerticalAlign.top:m=-g;break;case t.spec.TextVerticalAlign.middle:m=(x-d)/2-g;break;case t.spec.TextVerticalAlign.bottom:m=x-d-g}c=m+l;break;case t.spec.TextOverflow.clip:for(var y=r.maxTextHeight*a.fontScale,S=[0],T=1;T<e.length;T++)S[T]=S[T-1]+e[T].lineHeight;for(var w=1/0,b=-1/0,A=0;A<e.length;A++){var O,C,z=null!=(O=e[A].lineAscent)?O:0,L=null!=(C=e[A].lineDescent)?C:0;w=Math.min(w,S[A]-z),b=Math.max(b,S[A]+L)}var E=b-w,H=0;switch(r.textVerticalAlign){case t.spec.TextVerticalAlign.top:H=-w;break;case t.spec.TextVerticalAlign.middle:H=(y-E)/2-w;break;case t.spec.TextVerticalAlign.bottom:H=y-E-w}c=H+l;break;case t.spec.TextOverflow.display:for(var W=r.maxTextHeight*a.fontScale,M=[0],V=1;V<e.length;V++)M[V]=M[V-1]+e[V].lineHeight;for(var R=1/0,k=-1/0,F=0;F<e.length;F++){var _,D,B=null!=(_=e[F].lineAscent)?_:0,P=null!=(D=e[F].lineDescent)?D:0;R=Math.min(R,M[F]-B),k=Math.max(k,M[F]+P)}var X=k-R,Y=0;switch(r.textVerticalAlign){case t.spec.TextVerticalAlign.top:Y=-R;break;case t.spec.TextVerticalAlign.middle:Y=(W-X)/2-R;break;case t.spec.TextVerticalAlign.bottom:Y=W-X-R}for(var j=[],N=Y,I=0;I<e.length;I++)j.push(N),I<e.length-1&&(N+=e[I+1].lineHeight);return{baselineY:Y,lineYOffsets:j}}var U=[],q=c;return e.forEach((function(t,i){U.push(q),i<e.length-1&&(q+=e[i+1].lineHeight)})),{baselineY:c,lineYOffsets:U}},e}(),H=function(){function e(){}return e.createWrapStrategy=function(t){return t?new A:new b},e.createOverflowStrategy=function(e){switch(e){case t.spec.TextOverflow.clip:return new C;case t.spec.TextOverflow.display:return new O;case t.spec.TextOverflow.visible:default:return new z}},e.createHorizontalAlignStrategy=function(){return new L},e.createVerticalAlignStrategy=function(){return new E},e}(),W=0;exports.RichTextComponent=function(e){function i(i){var n;return(n=e.call(this,i)||this).isDirty=!0,n.text="",n.processedTextOptions=[],n.singleLineHeight=1.571,n.size=null,n.initialized=!1,n.canvasSize=null,n.SCALE_FACTOR=.1,n.ALPHA_FIX_VALUE=1/255,n.name="MRichText"+W++,n.initTextBase(i),n.richWrapStrategy=H.createWrapStrategy(),n.richOverflowStrategy=H.createOverflowStrategy(t.spec.TextOverflow.display),n.richHorizontalAlignStrategy=H.createHorizontalAlignStrategy(),n.richVerticalAlignStrategy=H.createVerticalAlignStrategy(),n}a(i,e);var n=i.prototype;return n.onUpdate=function(t){e.prototype.onUpdate.call(this,t),this.updateTexture()},n.onDestroy=function(){e.prototype.onDestroy.call(this),this.disposeTextTexture()},n.fromData=function(i){e.prototype.fromData.call(this,i);var n=i.interaction,r=i.options;this.interaction=n,this.textStyle=new t.TextStyle(r),this.textLayout=new S(r),this.text=r.text?r.text.toString():" ",this.textLayout.useLegacyRichText&&(this.textLayout.textVerticalAlign=t.spec.TextVerticalAlign.middle),this.updateStrategies(),this.renderText(r),this.material.setColor("_Color",new t.math.Color(1,1,1,1))},n.updateStrategies=function(){var t=this.textLayout;t&&(this.richWrapStrategy=H.createWrapStrategy(t.wrapEnabled),this.richOverflowStrategy=H.createOverflowStrategy(t.overflow))},n.generateTextProgram=function(e){var i=this;this.processedTextOptions=[];var n=y((function(e,n){/^\n+$/.test(e)&&(e=e.replace(/\n/g,"\n ")),e.split("\n").forEach((function(e,r){var a={text:e,fontSize:i.textStyle.fontSize,isNewLine:!1};r>0&&(a.isNewLine=!0),"b"in n&&(a.fontWeight=t.spec.TextWeight.bold),"i"in n&&(a.fontStyle=t.spec.FontStyle.italic),"size"in n&&n.size&&(a.fontSize=parseInt(n.size,10)),"color"in n&&n.color&&(a.fontColor=w(n.color)),i.processedTextOptions.push(a)}))}));n(e)},n.updateWithOptions=function(e){this.textStyle=new t.TextStyle(e),this.textLayout=new S(e),this.text=e.text?e.text.toString():" ",this.textLayout.useLegacyRichText&&(this.textLayout.textVerticalAlign=t.spec.TextVerticalAlign.middle),this.updateStrategies(),this.isDirty=!0},n.renderText=function(e){var i=e.size;i&&(this.canvasSize=new t.math.Vector2(i[0],i[1])),this.updateTexture()},n.updateTexture=function(t){if(void 0===t&&(t=!0),this.isDirty&&this.context&&this.canvas&&this.textStyle&&this.textLayout){var e=!0===this.textLayout.useLegacyRichText;this.singleLineHeight=e?1.571:1,e?this.updateTextureLegacy(t):this.updateTextureWithStrategies(t)}},n.updateTextureLegacy=function(e){var i=this;if(this.isDirty&&this.context&&this.canvas&&this.textStyle){this.generateTextProgram(this.text);var n=0,r=0,a=this.textLayout,o=this.textStyle,s=a.overflow,l=a.letterSpace,c=void 0===l?0:l,h=this.context,u=[],f=o.fontSize*o.fontScale,p={richOptions:[],offsetX:[],width:0,lineHeight:f*this.singleLineHeight,offsetY:f*(this.singleLineHeight-1)/2};if(this.processedTextOptions.forEach((function(t){var e=t.text,a=t.isNewLine,s=t.fontSize;a&&(u.push(p),n=Math.max(n,p.width),p={richOptions:[],offsetX:[],width:0,lineHeight:f*i.singleLineHeight,offsetY:f*(i.singleLineHeight-1)/2},r+=p.lineHeight),h.font=(t.fontWeight||o.textWeight)+" 10px "+(t.fontFamily||o.fontFamily);var l=h.measureText(e),x=l.width;if(void 0!==l.actualBoundingBoxLeft&&void 0!==l.actualBoundingBoxRight){var g=l.actualBoundingBoxLeft+l.actualBoundingBoxRight;g>0&&(x=Math.max(x,g))}var v=s*i.singleLineHeight*o.fontScale;v>p.lineHeight&&(r+=v-p.lineHeight,p.lineHeight=v,p.offsetY=s*o.fontScale*(i.singleLineHeight-1)/2),p.offsetX.push(p.width),p.width+=(x<=0?0:x)*s*i.SCALE_FACTOR*o.fontScale+e.length*c,p.richOptions.push(t)})),u.push(p),n=Math.max(n,p.width),r+=p.lineHeight,0!==n&&0!==r){void 0!==this.size&&null!==this.size||(this.size=this.item.transform.size.clone());var x=this.size,g=x.x,v=void 0===g?1:g,d=x.y,m=void 0===d?1:d;if(!this.initialized){this.canvasSize=this.canvasSize?this.canvasSize:new t.math.Vector2(n,r);var y=this.canvasSize,S=y.x,T=y.y;this.item.transform.size.set(v*S*this.SCALE_FACTOR*this.SCALE_FACTOR,m*T*this.SCALE_FACTOR*this.SCALE_FACTOR),this.size=this.item.transform.size.clone(),this.initialized=!0}t.assertExist(this.canvasSize);var w=this.canvasSize,b=w.x,A=w.y;a.width=b/o.fontScale,a.height=A/o.fontScale,this.renderToTexture(b,A,e,(function(e){if(0!==u.length){var n=a.getOffsetY(o,u.length,f*i.singleLineHeight,o.fontSize);u.forEach((function(i,r){var l=i.richOptions,c=i.offsetX,h=i.width,u=h,f=c;if(s===t.spec.TextOverflow.display&&h>b){var p=b/h;u*=p,f=c.map((function(t){return t*p}))}var x=a.getOffsetX(o,u);r>0&&(n+=i.lineHeight-i.offsetY),l.forEach((function(i,r){var a=o.fontScale,l=o.textColor,c=o.fontFamily,u=o.textWeight,p=o.fontStyle,g=i.text,v=i.fontSize,d=i.fontColor,m=void 0===d?l:d,y=i.fontFamily,S=void 0===y?c:y,T=i.fontWeight,w=void 0===T?u:T,A=i.fontStyle,O=void 0===A?p:A,C=v;s===t.spec.TextOverflow.display&&h>b&&(C/=h/b);var z=f[r]+x;e.font=O+" "+w+" "+C*a+"px "+S;var L=m[0],E=m[1],H=m[2],W=m[3];e.fillStyle="rgba("+L+", "+E+", "+H+", "+W+")",e.fillText(g,z,n)}))}))}}),{disposeOld:!1}),this.isDirty=!1}else this.isDirty=!1}},n.updateTextureWithStrategies=function(e){var i=this;if(this.isDirty&&this.context&&this.canvas){this.generateTextProgram(this.text);var n=this.textLayout,r=n.letterSpace,a=void 0===r?0:r,o=this.context;if(o){var s=this.richWrapStrategy.computeLines(this.processedTextOptions,o,this.textStyle,n,this.singleLineHeight,this.textStyle.fontScale,a,this.SCALE_FACTOR);if(0!==s.lines.length&&0!==s.maxLineWidth&&0!==s.totalHeight){var l=this.resolveCanvasSize(s,n,this.textStyle,this.singleLineHeight);this.setCanvasSize(l);var c=this.richOverflowStrategy.apply(s.lines,l,n,this.textStyle),h=this.richHorizontalAlignStrategy.getHorizontalOffsets(s.lines,l,c,n,this.textStyle),u=this.richVerticalAlignStrategy.getVerticalOffsets(s.lines,l,c,n,this.textStyle,this.singleLineHeight);t.assertExist(this.canvasSize);var f=this.canvasSize,p=f.x,x=f.y,g=Math.max(1,Math.ceil(p)),v=Math.max(1,Math.ceil(x));n.width=g/this.textStyle.fontScale,n.height=v/this.textStyle.fontScale,this.renderToTexture(g,v,e,(function(t){i.drawTextWithStrategies(t,s.lines,h,u,c,i.textStyle)}),{disposeOld:!1}),this.isDirty=!1}else this.isDirty=!1}}},n.setCanvasSize=function(e){var i=this;void 0!==this.size&&null!==this.size||(this.size=this.item.transform.size.clone());var n=this.size,r=n.x,a=void 0===r?1:r,o=n.y,s=void 0===o?1:o,l=this.textLayout,c=this.textStyle.fontScale||1,h=Math.max(1,l.maxTextWidth||0),u=Math.max(1,l.maxTextHeight||0);switch(l.overflow){case t.spec.TextOverflow.visible:var f,p,x,g,v=h*c,d=u*c,m=null!=(f=e.bboxTop)?f:0,y=null!=(x=e.bboxBottom)?x:m+(null!=(p=e.bboxHeight)?p:0),S=null!=(g=e.bboxHeight)?g:y-m,T=0;switch(l.textVerticalAlign){case t.spec.TextVerticalAlign.top:T=-m;break;case t.spec.TextVerticalAlign.middle:T=(d-S)/2-m;break;case t.spec.TextVerticalAlign.bottom:T=d-S-m}var w=T+m,b=T+y,A=Math.max(0,-w),O=Math.max(0,b-d),C=A,z=O;switch(l.textVerticalAlign){case t.spec.TextVerticalAlign.top:C=O,z=O;break;case t.spec.TextVerticalAlign.bottom:C=A,z=A;break;case t.spec.TextVerticalAlign.middle:C=A,z=O}for(var L=C,E=e.lines||[],H=E.map((function(t){return l.getOffsetXRich(i.textStyle,v,t.width)})),W=1/0,M=-1/0,V=0;V<E.length;V++){var R,k,F=null!=(R=H[V])?R:0,_=null!=(k=E[V].width)?k:0;W=Math.min(W,F),M=Math.max(M,F+_)}isFinite(W)||(W=0),isFinite(M)||(M=0);var D,B=Math.max(0,-W),P=Math.max(0,M-v),X=Math.ceil(v+B+P),Y=Math.ceil(d+C+z);e.baselineCompensationX=B,e.baselineCompensationY=L,e.containerWidth=v,e.canvasWidth=X,e.canvasHeight=Y,this.canvasSize=new t.math.Vector2(X,Y);var j=null!=(D=this.size)?D:this.item.transform.size,N=j.x,I=void 0===N?1:N,U=j.y,q=void 0===U?1:U;this.item.transform.size.set(I*X*this.SCALE_FACTOR*this.SCALE_FACTOR,q*Y*this.SCALE_FACTOR*this.SCALE_FACTOR),this.initialized=!0;break;case t.spec.TextOverflow.clip:var $,G=h*c,J=u*c;e.canvasWidth=G,e.canvasHeight=J,e.baselineCompensationX=0,e.baselineCompensationY=0,this.canvasSize=new t.math.Vector2(G,J),l.width=h,l.height=u;var K=null!=($=this.size)?$:this.item.transform.size,Q=K.x,Z=void 0===Q?1:Q,tt=K.y,et=void 0===tt?1:tt;this.item.transform.size.set(Z*G*this.SCALE_FACTOR*this.SCALE_FACTOR,et*J*this.SCALE_FACTOR*this.SCALE_FACTOR),this.initialized=!0;break;case t.spec.TextOverflow.display:if(!this.initialized){var it=h*c,nt=u*c;this.canvasSize=new t.math.Vector2(it,nt),this.item.transform.size.set(a*it*this.SCALE_FACTOR*this.SCALE_FACTOR,s*nt*this.SCALE_FACTOR*this.SCALE_FACTOR),this.initialized=!0}}},n.resolveCanvasSize=function(t,e,i,n){var r=Math.max(1,t.maxLineWidth||0),a=Math.max(1,t.totalHeight||0);return e.width=r/i.fontScale,e.height=a/i.fontScale,{canvasWidth:r,canvasHeight:a,contentWidth:t.maxLineWidth,bboxTop:t.bboxTop,bboxBottom:t.bboxBottom,bboxHeight:t.bboxHeight,lines:t.lines}},n.drawTextWithStrategies=function(t,e,i,n,r,a){var o=n.baselineY,s=i.lineOffsets;e.forEach((function(i,n){var r=i.richOptions,l=i.chars,c=s[n],h=o;r.forEach((function(e,n){var r=a.fontScale,o=a.textColor,s=a.fontFamily,u=a.textWeight,f=a.fontStyle,p=e.fontSize,x=e.fontColor,g=void 0===x?o:x,v=e.fontFamily,d=void 0===v?s:v,m=e.fontWeight,y=void 0===m?u:m,S=e.fontStyle,T=void 0===S?f:S,w=p;t.font=T+" "+y+" "+w*r+"px "+d;var b=g[0],A=g[1],O=g[2],C=g[3];t.fillStyle="rgba("+b+", "+A+", "+O+", "+C+")";var z=i.offsetX&&i.offsetX[n]?i.offsetX[n]:0;l[n].forEach((function(e){t.fillText(e.char,c+z+e.x,h)}))})),n<e.length-1&&(o+=e[n+1].lineHeight)}))},n.unsupported=function(t){throw new Error("RichTextComponent does not support "+t+" at runtime.")},n.setShadowOffsetY=function(t){this.unsupported("setShadowOffsetY")},n.setShadowBlur=function(t){this.unsupported("setShadowBlur")},n.setShadowOffsetX=function(t){this.unsupported("setShadowOffsetX")},n.setShadowColor=function(t){this.unsupported("setShadowColor")},n.setOutlineWidth=function(t){this.unsupported("setOutlineWidth")},n.setAutoWidth=function(t){this.unsupported("setAutoWidth")},n.setFontSize=function(t){this.unsupported("setFontSize")},n.setTextBaseline=function(t){console.warn("setTextBaseline 已废弃,请改用 setTextVerticalAlign。本次调用将转调用 setTextVerticalAlign。"),this.setTextVerticalAlign(t)},i}(t.MaskableGraphic),exports.RichTextComponent=function(t,e,i,n){var r,a=arguments.length,o=a<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,i):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,e,i,n);else for(var s=t.length-1;s>=0;s--)(r=t[s])&&(o=(a<3?r(o):a>3?r(e,i,o):r(e,i))||o);return a>3&&o&&Object.defineProperty(e,i,o),o}([t.effectsClass(t.spec.DataType.RichTextComponent)],exports.RichTextComponent),t.applyMixins(exports.RichTextComponent,[t.TextComponentBase]);var M="2.8.6";t.registerPlugin("rich-text",u),t.logger.info("Plugin rich text version: 2.8.6."),M!==n.version&&console.error("注意:请统一 RichText 插件与 Player 版本,不统一的版本混用会有不可预知的后果!","\nAttention: Please ensure the RichText plugin is synchronized with the Player version. Mixing and matching incompatible versions may result in unpredictable consequences!"),exports.RichTextLoader=u,exports.escape=function(t){if("string"!=typeof t)throw new Error("Input must be a string");return t.replace(/\\/g,"\\\\").replace(/=/g,"\\=").replace(/</g,"\\<").replace(/>/g,"\\>").replace(/\//g,"\\/")},exports.generateProgram=y,exports.isRichText=function(t){var e=d(t).filter((function(t){var e=t.tokenType;return"ContextStart"===e||"ContextEnd"===e})),i=e.filter((function(t){return"ContextStart"===t.tokenType})),n=e.filter((function(t){return"ContextEnd"===t.tokenType}));return!(i.length!==n.length||!i.length)&&function t(e,i){var n=e[0],r=e.slice(1);if(void 0===i&&(i=[]),!n)return 0===i.length;if("ContextStart"===n.tokenType)return t(r,i.concat(n.value));if("ContextEnd"===n.tokenType)return i[i.length-1]===n.value&&t(r,i.slice(0,-1));throw new Error("Unexpected token: "+n.tokenType)}(e.map((function(t){var e=t.tokenType,i=t.value;return{tokenType:e,value:"ContextStart"===e?i.match(x)[1]:i.match(g)[1]}})))},exports.lexer=d,exports.richTextParser=m,exports.unescape=function(t){if("string"!=typeof t)throw new Error("Input must be a string");return t.replace(/\\\//g,"/").replace(/\\>/g,">").replace(/\\</g,"<").replace(/\\=/g,"=").replace(/\\\\/g,"\\")},exports.version=M;
2
2
  //# sourceMappingURL=weapp.js.map
package/dist/weapp.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import*as t from"@galacean/effects/weapp";import{Plugin as e,spec as i,effectsClass as n,applyMixins as r,TextComponentBase as a,TextStyle as o,math as l,assertExist as s,MaskableGraphic as h,registerPlugin as c,logger as f}from"@galacean/effects/weapp";import{document as u}from"@galacean/appx-adapter/weapp";function g(t,e){return g=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},g(t,e)}function x(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&&g(t,e)}function p(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(p=function(){return!!t})()}function v(t,e,i){return v=p()?Reflect.construct:function(t,e,i){var n=[null];n.push.apply(n,e);var r=new(Function.bind.apply(t,n));return i&&g(r,i.prototype),r},v.apply(null,arguments)}function d(t){return d=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},d(t)}function m(t){var e="function"==typeof Map?new Map:void 0;return m=function(t){if(null===t||(i=t,-1===Function.toString.call(i).indexOf("[native code]")))return t;var i;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,n)}function n(){return v(t,arguments,d(this).constructor)}return n.prototype=Object.create(t.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),g(n,t)},m(t)}var y,S=function(t){function e(){var e;return(e=t.apply(this,arguments)||this).name="rich-text",e}return x(e,t),e}(m(e));function w(t,e){(null==e||e>t.length)&&(e=t.length);for(var i=0,n=new Array(e);i<e;i++)n[i]=t[i];return n}function T(t,e){var i="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(i)return(i=i.call(t)).next.bind(i);if(Array.isArray(t)||(i=function(t,e){if(t){if("string"==typeof t)return w(t,e);var i=Object.prototype.toString.call(t).slice(8,-1);return"Object"===i&&t.constructor&&(i=t.constructor.name),"Map"===i||"Set"===i?Array.from(i):"Arguments"===i||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i)?w(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){i&&(t=i);var n=0;return function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}!function(t){t.ContextStart="ContextStart",t.Text="Text",t.ContextEnd="ContextEnd",t.EscapedChar="EscapedChar"}(y||(y={}));var b=/^<([a-z]+)(=([^>]+))?>$/,A=/^<\/([a-z]+)>$/,O=[["EscapedChar",/^\\([=<>\\/])/],["ContextStart",/^<[a-z]+(=[^>]+)?>/],["ContextEnd",/^<\/[a-z]+>/],["Text",/^[^</>=\\]+/]],C=function(t,e,i){if(void 0===e&&(e=[]),void 0===i&&(i=0),!t)return e;var n=/^\\([=<>\\/])/.exec(t);if(n){var r=n[1];return C(t.slice(2),e.concat({tokenType:"Text",value:r}),i+2)}for(var a,o=T(O);!(a=o()).done;){var l=a.value,s=l[0],h=l[1];if("EscapedChar"!==s){var c=h.exec(t);if(c){var f=c[0],u=f.length;return C(t.slice(u),e.concat({tokenType:s,value:f}),i+u)}}}if(t.length>0)return C(t.slice(1),e.concat({tokenType:"Text",value:t[0]}),i+1);throw new Error('Unexpected token: "'+t[0]+'" at position '+i+' while reading "'+t+'"')},z=function(t){var e=function(){for(var t,e="",i=!1;r.length>0&&"Text"===(null==(t=r[0])?void 0:t.tokenType);){var n=o();n&&(e+=n.value,i=!0)}return i?e:void 0},i=function(){var t=l();if("ContextStart"===(null==t?void 0:t.tokenType)){o();var e,i=t.value.match(b);if(i)return{attributeName:i[1],attributeParam:null!=(e=i[3])?e:""};throw new Error("Expected a start tag marker at position "+a)}return{}},n=function(){var t=l();if("ContextEnd"===(null==t?void 0:t.tokenType)){o();var e=t.value.match(A);if(e)return{attributeName:e[1]};throw new Error("Expect an end tag marker at position "+a)}return{}},r=C(t),a=0,o=function(){var t,e=r.shift();return a+=null!=(t=null==e?void 0:e.value.length)?t:0,e},l=function(){return r[0]},s=[];return function t(r,o){for(void 0===r&&(r=[]),void 0===o&&(o="");;){var l=e();if(l)s.push({attributes:r,text:l});else{var h=i(),c=h.attributeName,f=h.attributeParam;if(!c){if(o){var u=n().attributeName;if(!u)throw new Error('Expect an end tag marker "'+o+'" at position '+a+" but found no tag!");if(u!==o)throw new Error('Expect an end tag marker "'+o+'" at position '+a+' but found tag "'+u+'"');return}break}t(r.concat({attributeName:c,attributeParam:null!=f?f:""}),c)}}}(),s};function L(t){return function(e){for(var i,n=T(z(e));!(i=n()).done;){var r=i.value,a=r.text,o=r.attributes.reduce((function(t,e){var i=e.attributeName,n=e.attributeParam;return i&&(t[i]=n),t}),{});t(a,o)}}}function H(t){var e=C(t).filter((function(t){var e=t.tokenType;return"ContextStart"===e||"ContextEnd"===e})),i=e.filter((function(t){return"ContextStart"===t.tokenType})),n=e.filter((function(t){return"ContextEnd"===t.tokenType}));if(i.length!==n.length||!i.length)return!1;return function t(e,i){var n=e[0],r=e.slice(1);if(void 0===i&&(i=[]),!n)return 0===i.length;if("ContextStart"===n.tokenType)return t(r,i.concat(n.value));if("ContextEnd"===n.tokenType)return i[i.length-1]===n.value&&t(r,i.slice(0,-1));throw new Error("Unexpected token: "+n.tokenType)}(e.map((function(t){var e=t.tokenType,i=t.value;return{tokenType:e,value:"ContextStart"===e?i.match(b)[1]:i.match(A)[1]}})))}function E(t){if("string"!=typeof t)throw new Error("Input must be a string");return t.replace(/\\/g,"\\\\").replace(/=/g,"\\=").replace(/</g,"\\<").replace(/>/g,"\\>").replace(/\//g,"\\/")}function W(t){if("string"!=typeof t)throw new Error("Input must be a string");return t.replace(/\\\//g,"/").replace(/\\>/g,">").replace(/\\</g,"<").replace(/\\=/g,"=").replace(/\\\\/g,"\\")}"function"==typeof SuppressedError&&SuppressedError;var V=function(){function t(t){this.width=0,this.height=0;var e=t.size,n=t.textOverflow,r=void 0===n?i.TextOverflow.clip:n,a=t.textVerticalAlign,o=void 0===a?i.TextVerticalAlign.middle:a,l=t.textAlign,s=void 0===l?i.TextAlignment.left:l,h=t.letterSpace,c=void 0===h?0:h,f=t.lineHeight,u=void 0===f?.571:f,g=t.wrapEnabled,x=void 0!==g&&g,p=t.maxTextWidth,v=void 0===p?350:p,d=t.maxTextHeight,m=void 0===d?1e3:d,y=t.sizeMode,S=void 0===y?i.TextSizeMode.autoWidth:y,w=t.useLegacyRichText,T=void 0!==w&&w;this.letterSpace=c,this.lineHeight=u,this.useLegacyRichText=T,this.overflow=r,this.textVerticalAlign=o,this.textAlign=s,this.width=e?e[0]:100,this.height=e?e[1]:100,this.wrapEnabled=x;this.maxTextWidth=50*v,this.maxTextHeight=50*m,this.sizeMode=S}var e=t.prototype;return e.getOffsetY=function(t,e,n,r,a){var o=t.outlineWidth,l=t.fontScale,s=(n-r)/3,h=r+o*l,c=void 0!==a?a:n*(e-1),f=0;switch(this.textVerticalAlign){case i.TextVerticalAlign.top:f=h+s;break;case i.TextVerticalAlign.middle:f=(this.height*l-c+h)/2;break;case i.TextVerticalAlign.bottom:f=this.height*l-c-s}return f},e.getOffsetX=function(t,e){var n=0;switch(this.textAlign){case i.TextAlignment.left:n=t.outlineWidth*t.fontScale;break;case i.TextAlignment.middle:n=(this.width*t.fontScale-e)/2;break;case i.TextAlignment.right:n=this.width*t.fontScale-e}return n},e.getOffsetYRich=function(t,e,n){if(0===e.length)return 0;var r=t.outlineWidth,a=t.fontScale,o=e.reduce((function(t,e){return t+e}),0),l=(e[0]-n)/3,s=n+r*a,h=o-e[0],c=0;switch(this.textVerticalAlign){case i.TextVerticalAlign.top:c=s+l;break;case i.TextVerticalAlign.middle:c=(this.height*a-o)/2+s;break;case i.TextVerticalAlign.bottom:c=this.height*a-h-l}return c},e.getOffsetXRich=function(t,e,n){switch(this.textAlign){case i.TextAlignment.left:return t.outlineWidth*t.fontScale;case i.TextAlignment.middle:return(e-n)/2;case i.TextAlignment.right:return e-n;default:return 0}},e.setSize=function(t,e){this.width=t,this.height=e},t}();function M(t,e){if(void 0===e&&(e=1),3!==(t=t.replace(/^#/,"")).length&&4!==t.length||(t=t.split("").map((function(t){return t+t})).join("")),8===t.length){var i=parseInt(t.slice(6,8),16)/255;t=t.slice(0,6),e=i}var n=parseInt(t,16);return[n>>16&255,n>>8&255,255&n,e]}function k(t,e){if(void 0===e&&(e=1),"string"!=typeof t||!t)throw new Error("Invalid color string");return t.startsWith("#")?M(t,e):M(function(t){if("string"!=typeof t||!t)throw new Error("Invalid color name provided");if(void 0===u)throw new Error("This method requires a browser environment");var e=u.createElement("canvas"),i=e.getContext("2d");if(i)try{return i.fillStyle=t,i.fillStyle}finally{null==e.remove||e.remove.call(e)}throw new Error("Failed to get 2D context for color conversion!")}(t))}var R=function(){function t(){}var e=t.prototype;return e.computeLines=function(t,e,i,n,r,a,o,l){var s=this,h=[],c=[],f=(n.lineHeight||0)*a,u=this.createNewLine(),g=0,x=0,p=function(){if(0!==u.chars.length){u.lineHeight=0===h.length?(u.lineAscent||0)+(u.lineDescent||0):f;var t=0===h.length?0:c[c.length-1]+f;c.push(t),x+=u.lineHeight,h.push(u),g=Math.max(g,u.width),u=s.createNewLine()}};t.forEach((function(t){var n=t.text,r=t.isNewLine,s=t.fontSize;r&&p();var h=t.fontStyle||i.fontStyle||"normal";e.font=h+" "+(t.fontWeight||i.textWeight)+" 10px "+(t.fontFamily||i.fontFamily),u.offsetX.push(u.width);for(var c=0,f=[],g=0,x=0,v=0;v<n.length;v++){var d=n[v],m=e.measureText(d),y=m.width,S=(y<=0?0:y)*s*l*a,w=s*a*l,T=m.actualBoundingBoxAscent*w,b=m.actualBoundingBoxDescent*w;g=Math.max(g,T),x=Math.max(x,b),v>0&&(c+=o),f.push({char:d,x:c}),c+=S}u.chars.push(f),u.width+=c,u.richOptions.push(t),u.lineAscent=Math.max(u.lineAscent||0,g),u.lineDescent=Math.max(u.lineDescent||0,x)})),p();var v=1/0,d=-1/0;if(0===h.length)return{lines:h,maxLineWidth:g,totalHeight:x,bboxTop:0,bboxBottom:0,bboxHeight:0};for(var m=0;m<h.length;m++)v=Math.min(v,c[m]-(h[m].lineAscent||0)),d=Math.max(d,c[m]+(h[m].lineDescent||0));return{lines:h,maxLineWidth:g,totalHeight:x,bboxTop:v,bboxBottom:d,bboxHeight:d-v}},e.createNewLine=function(){return{richOptions:[],offsetX:[],width:0,lineHeight:0,offsetY:0,chars:[],lineAscent:0,lineDescent:0}},t}(),F=function(){function t(){}var e=t.prototype;return e.computeLines=function(t,e,i,n,r,a,o,l){var s=this,h=[],c=[],f=(n.lineHeight||0)*a,u=this.createNewLine(),g=0,x=0,p=null,v=0,d=[],m=null,y=function(){if(S(),0!==u.chars.length){u.lineHeight=0===h.length?(u.lineAscent||0)+(u.lineDescent||0):f;var t=0===h.length?0:c[c.length-1]+f;c.push(t),x+=u.lineHeight,h.push(u),g=Math.max(g,u.width),u=s.createNewLine(),p=null,v=0,d=[],m=null}},S=function(){0!==d.length&&(null===p&&(p=u.width),u.offsetX.push(p),u.chars.push(d),m&&u.richOptions.push(m),p=null,v=0,d=[],m=null)};t.forEach((function(t){var r=t.text,s=t.isNewLine,h=t.fontSize,c=t.fontStyle||i.fontStyle||"normal";e.font=c+" "+(t.fontWeight||i.textWeight)+" 10px "+(t.fontFamily||i.fontFamily),s&&(S(),y());for(var f=0;f<r.length;f++){var g=r[f],x=e.measureText(g),w=x.width,T=(w<=0?0:w)*h*l*a,b=h*a*l,A=x.actualBoundingBoxAscent*b,O=x.actualBoundingBoxDescent*b,C=d.length>0?o:0;u.width+C+T>(n.maxTextWidth||1/0)&&(S(),y()),null===p&&(p=u.width,m=t),d.length>0&&(v+=o,u.width+=o),d.push({char:g,x:v}),u.lineAscent=Math.max(u.lineAscent||0,A),u.lineDescent=Math.max(u.lineDescent||0,O),v+=T,u.width+=T}S()})),y();for(var w=1/0,T=-1/0,b=0;b<h.length;b++)w=Math.min(w,c[b]-(h[b].lineAscent||0)),T=Math.max(T,c[b]+(h[b].lineDescent||0));return{lines:h,maxLineWidth:g,totalHeight:x,bboxTop:w,bboxBottom:T,bboxHeight:T-w}},e.createNewLine=function(){return{richOptions:[],offsetX:[],width:0,lineHeight:0,offsetY:0,chars:[],lineAscent:0,lineDescent:0}},t}(),D=function(){function t(){}return t.prototype.apply=function(t,e,i,n){var r,a,o=function(t,e){return Math.abs(e)>1e-5?t/e:1},l=i.maxTextWidth*n.fontScale,s=i.maxTextHeight*n.fontScale,h=Math.max(1,null!=(r=e.contentWidth)?r:e.canvasWidth),c=Math.max(1,null!=(a=e.bboxHeight)?a:e.canvasHeight),f=Math.min(1,o(l,h),o(s,c));if(f>.9999)return{globalScale:1};for(var u,g=T(t);!(u=g()).done;){var x=u.value;if(x.width*=f,x.lineHeight*=f,x.offsetX)for(var p=0;p<x.offsetX.length;p++)x.offsetX[p]*=f;for(var v,d=T(x.chars||[]);!(v=d()).done;)for(var m,y=T(v.value);!(m=y()).done;){m.value.x*=f}for(var S,w=T(x.richOptions||[]);!(S=w()).done;){S.value.fontSize*=f}null!=x.lineAscent&&(x.lineAscent*=f),null!=x.lineDescent&&(x.lineDescent*=f)}return{globalScale:f}},t}(),B=function(){function t(){}return t.prototype.apply=function(t,e,i,n){return{globalScale:1}},t}(),_=function(){function t(){}return t.prototype.apply=function(t,e,i,n){return{globalScale:1}},t}(),X=function(){function t(){}return t.prototype.getHorizontalOffsets=function(t,e,n,r,a){var o,l,s=null!=(o=e.containerWidth)?o:r.maxTextWidth*a.fontScale,h=null!=(l=e.baselineCompensationX)?l:0,c=t.map((function(t){return r.getOffsetXRich(a,s,t.width)}));return{lineOffsets:r.overflow===i.TextOverflow.visible?c.map((function(t){return t+h})):c}},t}(),Y=function(){function t(){}return t.prototype.getVerticalOffsets=function(t,e,n,r,a,o){var l,s=null!=(l=e.baselineCompensationY)?l:0,h=0;if(0===t.length)return{baselineY:0,lineYOffsets:[]};switch(r.overflow){case i.TextOverflow.visible:var c,f,u,g,x=r.maxTextHeight*a.fontScale,p=null!=(c=e.bboxTop)?c:0,v=null!=(u=e.bboxBottom)?u:p+(null!=(f=e.bboxHeight)?f:0),d=null!=(g=e.bboxHeight)?g:v-p,m=0;switch(r.textVerticalAlign){case i.TextVerticalAlign.top:m=-p;break;case i.TextVerticalAlign.middle:m=(x-d)/2-p;break;case i.TextVerticalAlign.bottom:m=x-d-p}h=m+s;break;case i.TextOverflow.clip:for(var y=r.maxTextHeight*a.fontScale,S=[0],w=1;w<t.length;w++)S[w]=S[w-1]+t[w].lineHeight;for(var T=1/0,b=-1/0,A=0;A<t.length;A++){var O,C,z=null!=(O=t[A].lineAscent)?O:0,L=null!=(C=t[A].lineDescent)?C:0;T=Math.min(T,S[A]-z),b=Math.max(b,S[A]+L)}var H=b-T,E=0;switch(r.textVerticalAlign){case i.TextVerticalAlign.top:E=-T;break;case i.TextVerticalAlign.middle:E=(y-H)/2-T;break;case i.TextVerticalAlign.bottom:E=y-H-T}h=E+s;break;case i.TextOverflow.display:for(var W=r.maxTextHeight*a.fontScale,V=[0],M=1;M<t.length;M++)V[M]=V[M-1]+t[M].lineHeight;for(var k=1/0,R=-1/0,F=0;F<t.length;F++){var D,B,_=null!=(D=t[F].lineAscent)?D:0,X=null!=(B=t[F].lineDescent)?B:0;k=Math.min(k,V[F]-_),R=Math.max(R,V[F]+X)}var Y=R-k,P=0;switch(r.textVerticalAlign){case i.TextVerticalAlign.top:P=-k;break;case i.TextVerticalAlign.middle:P=(W-Y)/2-k;break;case i.TextVerticalAlign.bottom:P=W-Y-k}for(var N=[],j=P,I=0;I<t.length;I++)N.push(j),I<t.length-1&&(j+=t[I+1].lineHeight);return{baselineY:P,lineYOffsets:N}}var U=[],$=h;return t.forEach((function(e,i){U.push($),i<t.length-1&&($+=t[i+1].lineHeight)})),{baselineY:h,lineYOffsets:U}},t}(),P=function(){function t(){}return t.createWrapStrategy=function(t){return t?new F:new R},t.createOverflowStrategy=function(t){switch(t){case i.TextOverflow.clip:return new B;case i.TextOverflow.display:return new D;case i.TextOverflow.visible:default:return new _}},t.createHorizontalAlignStrategy=function(){return new X},t.createVerticalAlignStrategy=function(){return new Y},t}(),N=0,j=function(t){function e(e){var n;return(n=t.call(this,e)||this).isDirty=!0,n.text="",n.processedTextOptions=[],n.singleLineHeight=1.571,n.size=null,n.initialized=!1,n.canvasSize=null,n.SCALE_FACTOR=.1,n.ALPHA_FIX_VALUE=1/255,n.name="MRichText"+N++,n.initTextBase(e),n.richWrapStrategy=P.createWrapStrategy(),n.richOverflowStrategy=P.createOverflowStrategy(i.TextOverflow.display),n.richHorizontalAlignStrategy=P.createHorizontalAlignStrategy(),n.richVerticalAlignStrategy=P.createVerticalAlignStrategy(),n}x(e,t);var n=e.prototype;return n.onUpdate=function(e){t.prototype.onUpdate.call(this,e),this.updateTexture()},n.onDestroy=function(){t.prototype.onDestroy.call(this),this.disposeTextTexture()},n.fromData=function(e){t.prototype.fromData.call(this,e);var n=e.interaction,r=e.options;this.interaction=n,this.textStyle=new o(r),this.textLayout=new V(r),this.text=r.text?r.text.toString():" ",this.textLayout.useLegacyRichText&&(this.textLayout.textVerticalAlign=i.TextVerticalAlign.middle),this.updateStrategies(),this.renderText(r),this.material.setColor("_Color",new l.Color(1,1,1,1))},n.updateStrategies=function(){var t=this.textLayout;t&&(this.richWrapStrategy=P.createWrapStrategy(t.wrapEnabled),this.richOverflowStrategy=P.createOverflowStrategy(t.overflow))},n.generateTextProgram=function(t){var e=this;this.processedTextOptions=[];var n=L((function(t,n){/^\n+$/.test(t)&&(t=t.replace(/\n/g,"\n ")),t.split("\n").forEach((function(t,r){var a={text:t,fontSize:e.textStyle.fontSize,isNewLine:!1};r>0&&(a.isNewLine=!0),"b"in n&&(a.fontWeight=i.TextWeight.bold),"i"in n&&(a.fontStyle=i.FontStyle.italic),"size"in n&&n.size&&(a.fontSize=parseInt(n.size,10)),"color"in n&&n.color&&(a.fontColor=k(n.color)),e.processedTextOptions.push(a)}))}));n(t)},n.updateWithOptions=function(t){this.textStyle=new o(t),this.textLayout=new V(t),this.text=t.text?t.text.toString():" ",this.textLayout.useLegacyRichText&&(this.textLayout.textVerticalAlign=i.TextVerticalAlign.middle),this.updateStrategies(),this.isDirty=!0},n.renderText=function(t){var e=t.size;e&&(this.canvasSize=new l.Vector2(e[0],e[1])),this.updateTexture()},n.updateTexture=function(t){if(void 0===t&&(t=!0),this.isDirty&&this.context&&this.canvas&&this.textStyle&&this.textLayout){var e=!0===this.textLayout.useLegacyRichText;this.singleLineHeight=e?1.571:1,e?this.updateTextureLegacy(t):this.updateTextureWithStrategies(t)}},n.updateTextureLegacy=function(t){var e=this;if(this.isDirty&&this.context&&this.canvas&&this.textStyle){this.generateTextProgram(this.text);var n=0,r=0,a=this.textLayout,o=this.textStyle,h=a.overflow,c=a.letterSpace,f=void 0===c?0:c,u=this.context,g=[],x=o.fontSize*o.fontScale,p={richOptions:[],offsetX:[],width:0,lineHeight:x*this.singleLineHeight,offsetY:x*(this.singleLineHeight-1)/2};if(this.processedTextOptions.forEach((function(t){var i=t.text,a=t.isNewLine,l=t.fontSize;a&&(g.push(p),n=Math.max(n,p.width),p={richOptions:[],offsetX:[],width:0,lineHeight:x*e.singleLineHeight,offsetY:x*(e.singleLineHeight-1)/2},r+=p.lineHeight),u.font=(t.fontWeight||o.textWeight)+" 10px "+(t.fontFamily||o.fontFamily);var s=u.measureText(i),h=s.width;if(void 0!==s.actualBoundingBoxLeft&&void 0!==s.actualBoundingBoxRight){var c=s.actualBoundingBoxLeft+s.actualBoundingBoxRight;c>0&&(h=Math.max(h,c))}var v=l*e.singleLineHeight*o.fontScale;v>p.lineHeight&&(r+=v-p.lineHeight,p.lineHeight=v,p.offsetY=l*o.fontScale*(e.singleLineHeight-1)/2),p.offsetX.push(p.width),p.width+=(h<=0?0:h)*l*e.SCALE_FACTOR*o.fontScale+i.length*f,p.richOptions.push(t)})),g.push(p),n=Math.max(n,p.width),r+=p.lineHeight,0!==n&&0!==r){void 0!==this.size&&null!==this.size||(this.size=this.item.transform.size.clone());var v=this.size,d=v.x,m=void 0===d?1:d,y=v.y,S=void 0===y?1:y;if(!this.initialized){this.canvasSize=this.canvasSize?this.canvasSize:new l.Vector2(n,r);var w=this.canvasSize,T=w.x,b=w.y;this.item.transform.size.set(m*T*this.SCALE_FACTOR*this.SCALE_FACTOR,S*b*this.SCALE_FACTOR*this.SCALE_FACTOR),this.size=this.item.transform.size.clone(),this.initialized=!0}s(this.canvasSize);var A=this.canvasSize,O=A.x,C=A.y;a.width=O/o.fontScale,a.height=C/o.fontScale,this.renderToTexture(O,C,t,(function(t){if(0!==g.length){var n=a.getOffsetY(o,g.length,x*e.singleLineHeight,o.fontSize);g.forEach((function(e,r){var l=e.richOptions,s=e.offsetX,c=e.width,f=c,u=s;if(h===i.TextOverflow.display&&c>O){var g=O/c;f*=g,u=s.map((function(t){return t*g}))}var x=a.getOffsetX(o,f);r>0&&(n+=e.lineHeight-e.offsetY),l.forEach((function(e,r){var a=o.fontScale,l=o.textColor,s=o.fontFamily,f=o.textWeight,g=o.fontStyle,p=e.text,v=e.fontSize,d=e.fontColor,m=void 0===d?l:d,y=e.fontFamily,S=void 0===y?s:y,w=e.fontWeight,T=void 0===w?f:w,b=e.fontStyle,A=void 0===b?g:b,C=v;h===i.TextOverflow.display&&c>O&&(C/=c/O);var z=u[r]+x;t.font=A+" "+T+" "+C*a+"px "+S;var L=m[0],H=m[1],E=m[2],W=m[3];t.fillStyle="rgba("+L+", "+H+", "+E+", "+W+")",t.fillText(p,z,n)}))}))}}),{disposeOld:!1}),this.isDirty=!1}else this.isDirty=!1}},n.updateTextureWithStrategies=function(t){var e=this;if(this.isDirty&&this.context&&this.canvas){this.generateTextProgram(this.text);var i=this.textLayout,n=i.letterSpace,r=void 0===n?0:n,a=this.context;if(a){var o=this.richWrapStrategy.computeLines(this.processedTextOptions,a,this.textStyle,i,this.singleLineHeight,this.textStyle.fontScale,r,this.SCALE_FACTOR);if(0!==o.lines.length&&0!==o.maxLineWidth&&0!==o.totalHeight){var l=this.resolveCanvasSize(o,i,this.textStyle,this.singleLineHeight);this.setCanvasSize(l);var h=this.richOverflowStrategy.apply(o.lines,l,i,this.textStyle),c=this.richHorizontalAlignStrategy.getHorizontalOffsets(o.lines,l,h,i,this.textStyle),f=this.richVerticalAlignStrategy.getVerticalOffsets(o.lines,l,h,i,this.textStyle,this.singleLineHeight);s(this.canvasSize);var u=this.canvasSize,g=u.x,x=u.y,p=Math.max(1,Math.ceil(g)),v=Math.max(1,Math.ceil(x));i.width=p/this.textStyle.fontScale,i.height=v/this.textStyle.fontScale,this.renderToTexture(p,v,t,(function(t){e.drawTextWithStrategies(t,o.lines,c,f,h,e.textStyle)}),{disposeOld:!1}),this.isDirty=!1}else this.isDirty=!1}}},n.setCanvasSize=function(t){var e=this;void 0!==this.size&&null!==this.size||(this.size=this.item.transform.size.clone());var n=this.size,r=n.x,a=void 0===r?1:r,o=n.y,s=void 0===o?1:o,h=this.textLayout,c=this.textStyle.fontScale||1,f=Math.max(1,h.maxTextWidth||0),u=Math.max(1,h.maxTextHeight||0);switch(h.overflow){case i.TextOverflow.visible:var g,x,p,v,d=f*c,m=u*c,y=null!=(g=t.bboxTop)?g:0,S=null!=(p=t.bboxBottom)?p:y+(null!=(x=t.bboxHeight)?x:0),w=null!=(v=t.bboxHeight)?v:S-y,T=0;switch(h.textVerticalAlign){case i.TextVerticalAlign.top:T=-y;break;case i.TextVerticalAlign.middle:T=(m-w)/2-y;break;case i.TextVerticalAlign.bottom:T=m-w-y}var b=T+y,A=T+S,O=Math.max(0,-b),C=Math.max(0,A-m),z=O,L=C;switch(h.textVerticalAlign){case i.TextVerticalAlign.top:z=C,L=C;break;case i.TextVerticalAlign.bottom:z=O,L=O;break;case i.TextVerticalAlign.middle:z=O,L=C}for(var H=z,E=t.lines||[],W=E.map((function(t){return h.getOffsetXRich(e.textStyle,d,t.width)})),V=1/0,M=-1/0,k=0;k<E.length;k++){var R,F,D=null!=(R=W[k])?R:0,B=null!=(F=E[k].width)?F:0;V=Math.min(V,D),M=Math.max(M,D+B)}isFinite(V)||(V=0),isFinite(M)||(M=0);var _,X=Math.max(0,-V),Y=Math.max(0,M-d),P=Math.ceil(d+X+Y),N=Math.ceil(m+z+L);t.baselineCompensationX=X,t.baselineCompensationY=H,t.containerWidth=d,t.canvasWidth=P,t.canvasHeight=N,this.canvasSize=new l.Vector2(P,N);var j=null!=(_=this.size)?_:this.item.transform.size,I=j.x,U=void 0===I?1:I,$=j.y,q=void 0===$?1:$;this.item.transform.size.set(U*P*this.SCALE_FACTOR*this.SCALE_FACTOR,q*N*this.SCALE_FACTOR*this.SCALE_FACTOR),this.initialized=!0;break;case i.TextOverflow.clip:var G,J=f*c,K=u*c;t.canvasWidth=J,t.canvasHeight=K,t.baselineCompensationX=0,t.baselineCompensationY=0,this.canvasSize=new l.Vector2(J,K),h.width=f,h.height=u;var Q=null!=(G=this.size)?G:this.item.transform.size,Z=Q.x,tt=void 0===Z?1:Z,et=Q.y,it=void 0===et?1:et;this.item.transform.size.set(tt*J*this.SCALE_FACTOR*this.SCALE_FACTOR,it*K*this.SCALE_FACTOR*this.SCALE_FACTOR),this.initialized=!0;break;case i.TextOverflow.display:if(!this.initialized){var nt=f*c,rt=u*c;this.canvasSize=new l.Vector2(nt,rt),this.item.transform.size.set(a*nt*this.SCALE_FACTOR*this.SCALE_FACTOR,s*rt*this.SCALE_FACTOR*this.SCALE_FACTOR),this.initialized=!0}}},n.resolveCanvasSize=function(t,e,i,n){var r=Math.max(1,t.maxLineWidth||0),a=Math.max(1,t.totalHeight||0);return e.width=r/i.fontScale,e.height=a/i.fontScale,{canvasWidth:r,canvasHeight:a,contentWidth:t.maxLineWidth,bboxTop:t.bboxTop,bboxBottom:t.bboxBottom,bboxHeight:t.bboxHeight,lines:t.lines}},n.drawTextWithStrategies=function(t,e,i,n,r,a){var o=n.baselineY,l=i.lineOffsets;e.forEach((function(i,n){var r=i.richOptions,s=i.chars,h=l[n],c=o;r.forEach((function(e,n){var r=a.fontScale,o=a.textColor,l=a.fontFamily,f=a.textWeight,u=a.fontStyle,g=e.fontSize,x=e.fontColor,p=void 0===x?o:x,v=e.fontFamily,d=void 0===v?l:v,m=e.fontWeight,y=void 0===m?f:m,S=e.fontStyle,w=void 0===S?u:S,T=g;t.font=w+" "+y+" "+T*r+"px "+d;var b=p[0],A=p[1],O=p[2],C=p[3];t.fillStyle="rgba("+b+", "+A+", "+O+", "+C+")";var z=i.offsetX&&i.offsetX[n]?i.offsetX[n]:0;s[n].forEach((function(e){t.fillText(e.char,h+z+e.x,c)}))})),n<e.length-1&&(o+=e[n+1].lineHeight)}))},n.unsupported=function(t){throw new Error("RichTextComponent does not support "+t+" at runtime.")},n.setShadowOffsetY=function(t){this.unsupported("setShadowOffsetY")},n.setShadowBlur=function(t){this.unsupported("setShadowBlur")},n.setShadowOffsetX=function(t){this.unsupported("setShadowOffsetX")},n.setShadowColor=function(t){this.unsupported("setShadowColor")},n.setOutlineWidth=function(t){this.unsupported("setOutlineWidth")},n.setAutoWidth=function(t){this.unsupported("setAutoWidth")},n.setFontSize=function(t){this.unsupported("setFontSize")},n.setTextBaseline=function(t){console.warn("setTextBaseline 已废弃,请改用 setTextVerticalAlign。本次调用将转调用 setTextVerticalAlign。"),this.setTextVerticalAlign(t)},e}(h);r(j=function(t,e,i,n){var r,a=arguments.length,o=a<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,i):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,e,i,n);else for(var l=t.length-1;l>=0;l--)(r=t[l])&&(o=(a<3?r(o):a>3?r(e,i,o):r(e,i))||o);return a>3&&o&&Object.defineProperty(e,i,o),o}([n(i.DataType.RichTextComponent)],j),[a]);var I="2.8.4";c("rich-text",S),f.info("Plugin rich text version: 2.8.4."),I!==t.version&&console.error("注意:请统一 RichText 插件与 Player 版本,不统一的版本混用会有不可预知的后果!","\nAttention: Please ensure the RichText plugin is synchronized with the Player version. Mixing and matching incompatible versions may result in unpredictable consequences!");export{j as RichTextComponent,S as RichTextLoader,E as escape,L as generateProgram,H as isRichText,C as lexer,z as richTextParser,W as unescape,I as version};
1
+ import*as t from"@galacean/effects/weapp";import{Plugin as e,spec as i,effectsClass as n,applyMixins as r,TextComponentBase as a,TextStyle as o,math as l,assertExist as s,MaskableGraphic as h,registerPlugin as c,logger as f}from"@galacean/effects/weapp";import{document as u}from"@galacean/appx-adapter/weapp";function g(t,e){return g=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},g(t,e)}function x(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&&g(t,e)}function p(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(p=function(){return!!t})()}function v(t,e,i){return v=p()?Reflect.construct:function(t,e,i){var n=[null];n.push.apply(n,e);var r=new(Function.bind.apply(t,n));return i&&g(r,i.prototype),r},v.apply(null,arguments)}function d(t){return d=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},d(t)}function m(t){var e="function"==typeof Map?new Map:void 0;return m=function(t){if(null===t||(i=t,-1===Function.toString.call(i).indexOf("[native code]")))return t;var i;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,n)}function n(){return v(t,arguments,d(this).constructor)}return n.prototype=Object.create(t.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),g(n,t)},m(t)}var y,S=function(t){function e(){var e;return(e=t.apply(this,arguments)||this).name="rich-text",e}return x(e,t),e}(m(e));function w(t,e){(null==e||e>t.length)&&(e=t.length);for(var i=0,n=new Array(e);i<e;i++)n[i]=t[i];return n}function T(t,e){var i="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(i)return(i=i.call(t)).next.bind(i);if(Array.isArray(t)||(i=function(t,e){if(t){if("string"==typeof t)return w(t,e);var i=Object.prototype.toString.call(t).slice(8,-1);return"Object"===i&&t.constructor&&(i=t.constructor.name),"Map"===i||"Set"===i?Array.from(i):"Arguments"===i||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i)?w(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){i&&(t=i);var n=0;return function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}!function(t){t.ContextStart="ContextStart",t.Text="Text",t.ContextEnd="ContextEnd",t.EscapedChar="EscapedChar"}(y||(y={}));var b=/^<([a-z]+)(=([^>]+))?>$/,A=/^<\/([a-z]+)>$/,O=[["EscapedChar",/^\\([=<>\\/])/],["ContextStart",/^<[a-z]+(=[^>]+)?>/],["ContextEnd",/^<\/[a-z]+>/],["Text",/^[^</>=\\]+/]],C=function(t,e,i){if(void 0===e&&(e=[]),void 0===i&&(i=0),!t)return e;var n=/^\\([=<>\\/])/.exec(t);if(n){var r=n[1];return C(t.slice(2),e.concat({tokenType:"Text",value:r}),i+2)}for(var a,o=T(O);!(a=o()).done;){var l=a.value,s=l[0],h=l[1];if("EscapedChar"!==s){var c=h.exec(t);if(c){var f=c[0],u=f.length;return C(t.slice(u),e.concat({tokenType:s,value:f}),i+u)}}}if(t.length>0)return C(t.slice(1),e.concat({tokenType:"Text",value:t[0]}),i+1);throw new Error('Unexpected token: "'+t[0]+'" at position '+i+' while reading "'+t+'"')},z=function(t){var e=function(){for(var t,e="",i=!1;r.length>0&&"Text"===(null==(t=r[0])?void 0:t.tokenType);){var n=o();n&&(e+=n.value,i=!0)}return i?e:void 0},i=function(){var t=l();if("ContextStart"===(null==t?void 0:t.tokenType)){o();var e,i=t.value.match(b);if(i)return{attributeName:i[1],attributeParam:null!=(e=i[3])?e:""};throw new Error("Expected a start tag marker at position "+a)}return{}},n=function(){var t=l();if("ContextEnd"===(null==t?void 0:t.tokenType)){o();var e=t.value.match(A);if(e)return{attributeName:e[1]};throw new Error("Expect an end tag marker at position "+a)}return{}},r=C(t),a=0,o=function(){var t,e=r.shift();return a+=null!=(t=null==e?void 0:e.value.length)?t:0,e},l=function(){return r[0]},s=[];return function t(r,o){for(void 0===r&&(r=[]),void 0===o&&(o="");;){var l=e();if(l)s.push({attributes:r,text:l});else{var h=i(),c=h.attributeName,f=h.attributeParam;if(!c){if(o){var u=n().attributeName;if(!u)throw new Error('Expect an end tag marker "'+o+'" at position '+a+" but found no tag!");if(u!==o)throw new Error('Expect an end tag marker "'+o+'" at position '+a+' but found tag "'+u+'"');return}break}t(r.concat({attributeName:c,attributeParam:null!=f?f:""}),c)}}}(),s};function L(t){return function(e){for(var i,n=T(z(e));!(i=n()).done;){var r=i.value,a=r.text,o=r.attributes.reduce((function(t,e){var i=e.attributeName,n=e.attributeParam;return i&&(t[i]=n),t}),{});t(a,o)}}}function H(t){var e=C(t).filter((function(t){var e=t.tokenType;return"ContextStart"===e||"ContextEnd"===e})),i=e.filter((function(t){return"ContextStart"===t.tokenType})),n=e.filter((function(t){return"ContextEnd"===t.tokenType}));if(i.length!==n.length||!i.length)return!1;return function t(e,i){var n=e[0],r=e.slice(1);if(void 0===i&&(i=[]),!n)return 0===i.length;if("ContextStart"===n.tokenType)return t(r,i.concat(n.value));if("ContextEnd"===n.tokenType)return i[i.length-1]===n.value&&t(r,i.slice(0,-1));throw new Error("Unexpected token: "+n.tokenType)}(e.map((function(t){var e=t.tokenType,i=t.value;return{tokenType:e,value:"ContextStart"===e?i.match(b)[1]:i.match(A)[1]}})))}function E(t){if("string"!=typeof t)throw new Error("Input must be a string");return t.replace(/\\/g,"\\\\").replace(/=/g,"\\=").replace(/</g,"\\<").replace(/>/g,"\\>").replace(/\//g,"\\/")}function W(t){if("string"!=typeof t)throw new Error("Input must be a string");return t.replace(/\\\//g,"/").replace(/\\>/g,">").replace(/\\</g,"<").replace(/\\=/g,"=").replace(/\\\\/g,"\\")}"function"==typeof SuppressedError&&SuppressedError;var V=function(){function t(t){this.width=0,this.height=0;var e=t.size,n=t.textOverflow,r=void 0===n?i.TextOverflow.clip:n,a=t.textVerticalAlign,o=void 0===a?i.TextVerticalAlign.middle:a,l=t.textAlign,s=void 0===l?i.TextAlignment.left:l,h=t.letterSpace,c=void 0===h?0:h,f=t.lineHeight,u=void 0===f?.571:f,g=t.wrapEnabled,x=void 0!==g&&g,p=t.maxTextWidth,v=void 0===p?350:p,d=t.maxTextHeight,m=void 0===d?1e3:d,y=t.sizeMode,S=void 0===y?i.TextSizeMode.autoWidth:y,w=t.useLegacyRichText,T=void 0!==w&&w;this.letterSpace=c,this.lineHeight=u,this.useLegacyRichText=T,this.overflow=r,this.textVerticalAlign=o,this.textAlign=s,this.width=e?e[0]:100,this.height=e?e[1]:100,this.wrapEnabled=x;this.maxTextWidth=50*v,this.maxTextHeight=50*m,this.sizeMode=S}var e=t.prototype;return e.getOffsetY=function(t,e,n,r,a){var o=t.outlineWidth,l=t.fontScale,s=(n-r)/3,h=r+o*l,c=void 0!==a?a:n*(e-1),f=0;switch(this.textVerticalAlign){case i.TextVerticalAlign.top:f=h+s;break;case i.TextVerticalAlign.middle:f=(this.height*l-c+h)/2;break;case i.TextVerticalAlign.bottom:f=this.height*l-c-s}return f},e.getOffsetX=function(t,e){var n=0;switch(this.textAlign){case i.TextAlignment.left:n=t.outlineWidth*t.fontScale;break;case i.TextAlignment.middle:n=(this.width*t.fontScale-e)/2;break;case i.TextAlignment.right:n=this.width*t.fontScale-e}return n},e.getOffsetYRich=function(t,e,n){if(0===e.length)return 0;var r=t.outlineWidth,a=t.fontScale,o=e.reduce((function(t,e){return t+e}),0),l=(e[0]-n)/3,s=n+r*a,h=o-e[0],c=0;switch(this.textVerticalAlign){case i.TextVerticalAlign.top:c=s+l;break;case i.TextVerticalAlign.middle:c=(this.height*a-o)/2+s;break;case i.TextVerticalAlign.bottom:c=this.height*a-h-l}return c},e.getOffsetXRich=function(t,e,n){switch(this.textAlign){case i.TextAlignment.left:return t.outlineWidth*t.fontScale;case i.TextAlignment.middle:return(e-n)/2;case i.TextAlignment.right:return e-n;default:return 0}},e.setSize=function(t,e){this.width=t,this.height=e},t}();function M(t,e){if(void 0===e&&(e=1),3!==(t=t.replace(/^#/,"")).length&&4!==t.length||(t=t.split("").map((function(t){return t+t})).join("")),8===t.length){var i=parseInt(t.slice(6,8),16)/255;t=t.slice(0,6),e=i}var n=parseInt(t,16);return[n>>16&255,n>>8&255,255&n,e]}function k(t,e){if(void 0===e&&(e=1),"string"!=typeof t||!t)throw new Error("Invalid color string");return t.startsWith("#")?M(t,e):M(function(t){if("string"!=typeof t||!t)throw new Error("Invalid color name provided");if(void 0===u)throw new Error("This method requires a browser environment");var e=u.createElement("canvas"),i=e.getContext("2d");if(i)try{return i.fillStyle=t,i.fillStyle}finally{null==e.remove||e.remove.call(e)}throw new Error("Failed to get 2D context for color conversion!")}(t))}var R=function(){function t(){}var e=t.prototype;return e.computeLines=function(t,e,i,n,r,a,o,l){var s=this,h=[],c=[],f=(n.lineHeight||0)*a,u=this.createNewLine(),g=0,x=0,p=function(){if(0!==u.chars.length){u.lineHeight=0===h.length?(u.lineAscent||0)+(u.lineDescent||0):f;var t=0===h.length?0:c[c.length-1]+f;c.push(t),x+=u.lineHeight,h.push(u),g=Math.max(g,u.width),u=s.createNewLine()}};t.forEach((function(t){var n=t.text,r=t.isNewLine,s=t.fontSize;r&&p();var h=t.fontStyle||i.fontStyle||"normal";e.font=h+" "+(t.fontWeight||i.textWeight)+" 10px "+(t.fontFamily||i.fontFamily),u.offsetX.push(u.width);for(var c=0,f=[],g=0,x=0,v=0;v<n.length;v++){var d=n[v],m=e.measureText(d),y=m.width,S=(y<=0?0:y)*s*l*a,w=s*a*l,T=m.actualBoundingBoxAscent*w,b=m.actualBoundingBoxDescent*w;g=Math.max(g,T),x=Math.max(x,b),v>0&&(c+=o),f.push({char:d,x:c}),c+=S}u.chars.push(f),u.width+=c,u.richOptions.push(t),u.lineAscent=Math.max(u.lineAscent||0,g),u.lineDescent=Math.max(u.lineDescent||0,x)})),p();var v=1/0,d=-1/0;if(0===h.length)return{lines:h,maxLineWidth:g,totalHeight:x,bboxTop:0,bboxBottom:0,bboxHeight:0};for(var m=0;m<h.length;m++)v=Math.min(v,c[m]-(h[m].lineAscent||0)),d=Math.max(d,c[m]+(h[m].lineDescent||0));return{lines:h,maxLineWidth:g,totalHeight:x,bboxTop:v,bboxBottom:d,bboxHeight:d-v}},e.createNewLine=function(){return{richOptions:[],offsetX:[],width:0,lineHeight:0,offsetY:0,chars:[],lineAscent:0,lineDescent:0}},t}(),F=function(){function t(){}var e=t.prototype;return e.computeLines=function(t,e,i,n,r,a,o,l){var s=this,h=[],c=[],f=(n.lineHeight||0)*a,u=this.createNewLine(),g=0,x=0,p=null,v=0,d=[],m=null,y=function(){if(S(),0!==u.chars.length){u.lineHeight=0===h.length?(u.lineAscent||0)+(u.lineDescent||0):f;var t=0===h.length?0:c[c.length-1]+f;c.push(t),x+=u.lineHeight,h.push(u),g=Math.max(g,u.width),u=s.createNewLine(),p=null,v=0,d=[],m=null}},S=function(){0!==d.length&&(null===p&&(p=u.width),u.offsetX.push(p),u.chars.push(d),m&&u.richOptions.push(m),p=null,v=0,d=[],m=null)};t.forEach((function(t){var r=t.text,s=t.isNewLine,h=t.fontSize,c=t.fontStyle||i.fontStyle||"normal";e.font=c+" "+(t.fontWeight||i.textWeight)+" 10px "+(t.fontFamily||i.fontFamily),s&&(S(),y());for(var f=0;f<r.length;f++){var g=r[f],x=e.measureText(g),w=x.width,T=(w<=0?0:w)*h*l*a,b=h*a*l,A=x.actualBoundingBoxAscent*b,O=x.actualBoundingBoxDescent*b,C=d.length>0?o:0;u.width+C+T>(n.maxTextWidth||1/0)&&(S(),y()),null===p&&(p=u.width,m=t),d.length>0&&(v+=o,u.width+=o),d.push({char:g,x:v}),u.lineAscent=Math.max(u.lineAscent||0,A),u.lineDescent=Math.max(u.lineDescent||0,O),v+=T,u.width+=T}S()})),y();for(var w=1/0,T=-1/0,b=0;b<h.length;b++)w=Math.min(w,c[b]-(h[b].lineAscent||0)),T=Math.max(T,c[b]+(h[b].lineDescent||0));return{lines:h,maxLineWidth:g,totalHeight:x,bboxTop:w,bboxBottom:T,bboxHeight:T-w}},e.createNewLine=function(){return{richOptions:[],offsetX:[],width:0,lineHeight:0,offsetY:0,chars:[],lineAscent:0,lineDescent:0}},t}(),D=function(){function t(){}return t.prototype.apply=function(t,e,i,n){var r,a,o=function(t,e){return Math.abs(e)>1e-5?t/e:1},l=i.maxTextWidth*n.fontScale,s=i.maxTextHeight*n.fontScale,h=Math.max(1,null!=(r=e.contentWidth)?r:e.canvasWidth),c=Math.max(1,null!=(a=e.bboxHeight)?a:e.canvasHeight),f=Math.min(1,o(l,h),o(s,c));if(f>.9999)return{globalScale:1};for(var u,g=T(t);!(u=g()).done;){var x=u.value;if(x.width*=f,x.lineHeight*=f,x.offsetX)for(var p=0;p<x.offsetX.length;p++)x.offsetX[p]*=f;for(var v,d=T(x.chars||[]);!(v=d()).done;)for(var m,y=T(v.value);!(m=y()).done;){m.value.x*=f}for(var S,w=T(x.richOptions||[]);!(S=w()).done;){S.value.fontSize*=f}null!=x.lineAscent&&(x.lineAscent*=f),null!=x.lineDescent&&(x.lineDescent*=f)}return{globalScale:f}},t}(),B=function(){function t(){}return t.prototype.apply=function(t,e,i,n){return{globalScale:1}},t}(),_=function(){function t(){}return t.prototype.apply=function(t,e,i,n){return{globalScale:1}},t}(),X=function(){function t(){}return t.prototype.getHorizontalOffsets=function(t,e,n,r,a){var o,l,s=null!=(o=e.containerWidth)?o:r.maxTextWidth*a.fontScale,h=null!=(l=e.baselineCompensationX)?l:0,c=t.map((function(t){return r.getOffsetXRich(a,s,t.width)}));return{lineOffsets:r.overflow===i.TextOverflow.visible?c.map((function(t){return t+h})):c}},t}(),Y=function(){function t(){}return t.prototype.getVerticalOffsets=function(t,e,n,r,a,o){var l,s=null!=(l=e.baselineCompensationY)?l:0,h=0;if(0===t.length)return{baselineY:0,lineYOffsets:[]};switch(r.overflow){case i.TextOverflow.visible:var c,f,u,g,x=r.maxTextHeight*a.fontScale,p=null!=(c=e.bboxTop)?c:0,v=null!=(u=e.bboxBottom)?u:p+(null!=(f=e.bboxHeight)?f:0),d=null!=(g=e.bboxHeight)?g:v-p,m=0;switch(r.textVerticalAlign){case i.TextVerticalAlign.top:m=-p;break;case i.TextVerticalAlign.middle:m=(x-d)/2-p;break;case i.TextVerticalAlign.bottom:m=x-d-p}h=m+s;break;case i.TextOverflow.clip:for(var y=r.maxTextHeight*a.fontScale,S=[0],w=1;w<t.length;w++)S[w]=S[w-1]+t[w].lineHeight;for(var T=1/0,b=-1/0,A=0;A<t.length;A++){var O,C,z=null!=(O=t[A].lineAscent)?O:0,L=null!=(C=t[A].lineDescent)?C:0;T=Math.min(T,S[A]-z),b=Math.max(b,S[A]+L)}var H=b-T,E=0;switch(r.textVerticalAlign){case i.TextVerticalAlign.top:E=-T;break;case i.TextVerticalAlign.middle:E=(y-H)/2-T;break;case i.TextVerticalAlign.bottom:E=y-H-T}h=E+s;break;case i.TextOverflow.display:for(var W=r.maxTextHeight*a.fontScale,V=[0],M=1;M<t.length;M++)V[M]=V[M-1]+t[M].lineHeight;for(var k=1/0,R=-1/0,F=0;F<t.length;F++){var D,B,_=null!=(D=t[F].lineAscent)?D:0,X=null!=(B=t[F].lineDescent)?B:0;k=Math.min(k,V[F]-_),R=Math.max(R,V[F]+X)}var Y=R-k,P=0;switch(r.textVerticalAlign){case i.TextVerticalAlign.top:P=-k;break;case i.TextVerticalAlign.middle:P=(W-Y)/2-k;break;case i.TextVerticalAlign.bottom:P=W-Y-k}for(var N=[],j=P,I=0;I<t.length;I++)N.push(j),I<t.length-1&&(j+=t[I+1].lineHeight);return{baselineY:P,lineYOffsets:N}}var U=[],$=h;return t.forEach((function(e,i){U.push($),i<t.length-1&&($+=t[i+1].lineHeight)})),{baselineY:h,lineYOffsets:U}},t}(),P=function(){function t(){}return t.createWrapStrategy=function(t){return t?new F:new R},t.createOverflowStrategy=function(t){switch(t){case i.TextOverflow.clip:return new B;case i.TextOverflow.display:return new D;case i.TextOverflow.visible:default:return new _}},t.createHorizontalAlignStrategy=function(){return new X},t.createVerticalAlignStrategy=function(){return new Y},t}(),N=0,j=function(t){function e(e){var n;return(n=t.call(this,e)||this).isDirty=!0,n.text="",n.processedTextOptions=[],n.singleLineHeight=1.571,n.size=null,n.initialized=!1,n.canvasSize=null,n.SCALE_FACTOR=.1,n.ALPHA_FIX_VALUE=1/255,n.name="MRichText"+N++,n.initTextBase(e),n.richWrapStrategy=P.createWrapStrategy(),n.richOverflowStrategy=P.createOverflowStrategy(i.TextOverflow.display),n.richHorizontalAlignStrategy=P.createHorizontalAlignStrategy(),n.richVerticalAlignStrategy=P.createVerticalAlignStrategy(),n}x(e,t);var n=e.prototype;return n.onUpdate=function(e){t.prototype.onUpdate.call(this,e),this.updateTexture()},n.onDestroy=function(){t.prototype.onDestroy.call(this),this.disposeTextTexture()},n.fromData=function(e){t.prototype.fromData.call(this,e);var n=e.interaction,r=e.options;this.interaction=n,this.textStyle=new o(r),this.textLayout=new V(r),this.text=r.text?r.text.toString():" ",this.textLayout.useLegacyRichText&&(this.textLayout.textVerticalAlign=i.TextVerticalAlign.middle),this.updateStrategies(),this.renderText(r),this.material.setColor("_Color",new l.Color(1,1,1,1))},n.updateStrategies=function(){var t=this.textLayout;t&&(this.richWrapStrategy=P.createWrapStrategy(t.wrapEnabled),this.richOverflowStrategy=P.createOverflowStrategy(t.overflow))},n.generateTextProgram=function(t){var e=this;this.processedTextOptions=[];var n=L((function(t,n){/^\n+$/.test(t)&&(t=t.replace(/\n/g,"\n ")),t.split("\n").forEach((function(t,r){var a={text:t,fontSize:e.textStyle.fontSize,isNewLine:!1};r>0&&(a.isNewLine=!0),"b"in n&&(a.fontWeight=i.TextWeight.bold),"i"in n&&(a.fontStyle=i.FontStyle.italic),"size"in n&&n.size&&(a.fontSize=parseInt(n.size,10)),"color"in n&&n.color&&(a.fontColor=k(n.color)),e.processedTextOptions.push(a)}))}));n(t)},n.updateWithOptions=function(t){this.textStyle=new o(t),this.textLayout=new V(t),this.text=t.text?t.text.toString():" ",this.textLayout.useLegacyRichText&&(this.textLayout.textVerticalAlign=i.TextVerticalAlign.middle),this.updateStrategies(),this.isDirty=!0},n.renderText=function(t){var e=t.size;e&&(this.canvasSize=new l.Vector2(e[0],e[1])),this.updateTexture()},n.updateTexture=function(t){if(void 0===t&&(t=!0),this.isDirty&&this.context&&this.canvas&&this.textStyle&&this.textLayout){var e=!0===this.textLayout.useLegacyRichText;this.singleLineHeight=e?1.571:1,e?this.updateTextureLegacy(t):this.updateTextureWithStrategies(t)}},n.updateTextureLegacy=function(t){var e=this;if(this.isDirty&&this.context&&this.canvas&&this.textStyle){this.generateTextProgram(this.text);var n=0,r=0,a=this.textLayout,o=this.textStyle,h=a.overflow,c=a.letterSpace,f=void 0===c?0:c,u=this.context,g=[],x=o.fontSize*o.fontScale,p={richOptions:[],offsetX:[],width:0,lineHeight:x*this.singleLineHeight,offsetY:x*(this.singleLineHeight-1)/2};if(this.processedTextOptions.forEach((function(t){var i=t.text,a=t.isNewLine,l=t.fontSize;a&&(g.push(p),n=Math.max(n,p.width),p={richOptions:[],offsetX:[],width:0,lineHeight:x*e.singleLineHeight,offsetY:x*(e.singleLineHeight-1)/2},r+=p.lineHeight),u.font=(t.fontWeight||o.textWeight)+" 10px "+(t.fontFamily||o.fontFamily);var s=u.measureText(i),h=s.width;if(void 0!==s.actualBoundingBoxLeft&&void 0!==s.actualBoundingBoxRight){var c=s.actualBoundingBoxLeft+s.actualBoundingBoxRight;c>0&&(h=Math.max(h,c))}var v=l*e.singleLineHeight*o.fontScale;v>p.lineHeight&&(r+=v-p.lineHeight,p.lineHeight=v,p.offsetY=l*o.fontScale*(e.singleLineHeight-1)/2),p.offsetX.push(p.width),p.width+=(h<=0?0:h)*l*e.SCALE_FACTOR*o.fontScale+i.length*f,p.richOptions.push(t)})),g.push(p),n=Math.max(n,p.width),r+=p.lineHeight,0!==n&&0!==r){void 0!==this.size&&null!==this.size||(this.size=this.item.transform.size.clone());var v=this.size,d=v.x,m=void 0===d?1:d,y=v.y,S=void 0===y?1:y;if(!this.initialized){this.canvasSize=this.canvasSize?this.canvasSize:new l.Vector2(n,r);var w=this.canvasSize,T=w.x,b=w.y;this.item.transform.size.set(m*T*this.SCALE_FACTOR*this.SCALE_FACTOR,S*b*this.SCALE_FACTOR*this.SCALE_FACTOR),this.size=this.item.transform.size.clone(),this.initialized=!0}s(this.canvasSize);var A=this.canvasSize,O=A.x,C=A.y;a.width=O/o.fontScale,a.height=C/o.fontScale,this.renderToTexture(O,C,t,(function(t){if(0!==g.length){var n=a.getOffsetY(o,g.length,x*e.singleLineHeight,o.fontSize);g.forEach((function(e,r){var l=e.richOptions,s=e.offsetX,c=e.width,f=c,u=s;if(h===i.TextOverflow.display&&c>O){var g=O/c;f*=g,u=s.map((function(t){return t*g}))}var x=a.getOffsetX(o,f);r>0&&(n+=e.lineHeight-e.offsetY),l.forEach((function(e,r){var a=o.fontScale,l=o.textColor,s=o.fontFamily,f=o.textWeight,g=o.fontStyle,p=e.text,v=e.fontSize,d=e.fontColor,m=void 0===d?l:d,y=e.fontFamily,S=void 0===y?s:y,w=e.fontWeight,T=void 0===w?f:w,b=e.fontStyle,A=void 0===b?g:b,C=v;h===i.TextOverflow.display&&c>O&&(C/=c/O);var z=u[r]+x;t.font=A+" "+T+" "+C*a+"px "+S;var L=m[0],H=m[1],E=m[2],W=m[3];t.fillStyle="rgba("+L+", "+H+", "+E+", "+W+")",t.fillText(p,z,n)}))}))}}),{disposeOld:!1}),this.isDirty=!1}else this.isDirty=!1}},n.updateTextureWithStrategies=function(t){var e=this;if(this.isDirty&&this.context&&this.canvas){this.generateTextProgram(this.text);var i=this.textLayout,n=i.letterSpace,r=void 0===n?0:n,a=this.context;if(a){var o=this.richWrapStrategy.computeLines(this.processedTextOptions,a,this.textStyle,i,this.singleLineHeight,this.textStyle.fontScale,r,this.SCALE_FACTOR);if(0!==o.lines.length&&0!==o.maxLineWidth&&0!==o.totalHeight){var l=this.resolveCanvasSize(o,i,this.textStyle,this.singleLineHeight);this.setCanvasSize(l);var h=this.richOverflowStrategy.apply(o.lines,l,i,this.textStyle),c=this.richHorizontalAlignStrategy.getHorizontalOffsets(o.lines,l,h,i,this.textStyle),f=this.richVerticalAlignStrategy.getVerticalOffsets(o.lines,l,h,i,this.textStyle,this.singleLineHeight);s(this.canvasSize);var u=this.canvasSize,g=u.x,x=u.y,p=Math.max(1,Math.ceil(g)),v=Math.max(1,Math.ceil(x));i.width=p/this.textStyle.fontScale,i.height=v/this.textStyle.fontScale,this.renderToTexture(p,v,t,(function(t){e.drawTextWithStrategies(t,o.lines,c,f,h,e.textStyle)}),{disposeOld:!1}),this.isDirty=!1}else this.isDirty=!1}}},n.setCanvasSize=function(t){var e=this;void 0!==this.size&&null!==this.size||(this.size=this.item.transform.size.clone());var n=this.size,r=n.x,a=void 0===r?1:r,o=n.y,s=void 0===o?1:o,h=this.textLayout,c=this.textStyle.fontScale||1,f=Math.max(1,h.maxTextWidth||0),u=Math.max(1,h.maxTextHeight||0);switch(h.overflow){case i.TextOverflow.visible:var g,x,p,v,d=f*c,m=u*c,y=null!=(g=t.bboxTop)?g:0,S=null!=(p=t.bboxBottom)?p:y+(null!=(x=t.bboxHeight)?x:0),w=null!=(v=t.bboxHeight)?v:S-y,T=0;switch(h.textVerticalAlign){case i.TextVerticalAlign.top:T=-y;break;case i.TextVerticalAlign.middle:T=(m-w)/2-y;break;case i.TextVerticalAlign.bottom:T=m-w-y}var b=T+y,A=T+S,O=Math.max(0,-b),C=Math.max(0,A-m),z=O,L=C;switch(h.textVerticalAlign){case i.TextVerticalAlign.top:z=C,L=C;break;case i.TextVerticalAlign.bottom:z=O,L=O;break;case i.TextVerticalAlign.middle:z=O,L=C}for(var H=z,E=t.lines||[],W=E.map((function(t){return h.getOffsetXRich(e.textStyle,d,t.width)})),V=1/0,M=-1/0,k=0;k<E.length;k++){var R,F,D=null!=(R=W[k])?R:0,B=null!=(F=E[k].width)?F:0;V=Math.min(V,D),M=Math.max(M,D+B)}isFinite(V)||(V=0),isFinite(M)||(M=0);var _,X=Math.max(0,-V),Y=Math.max(0,M-d),P=Math.ceil(d+X+Y),N=Math.ceil(m+z+L);t.baselineCompensationX=X,t.baselineCompensationY=H,t.containerWidth=d,t.canvasWidth=P,t.canvasHeight=N,this.canvasSize=new l.Vector2(P,N);var j=null!=(_=this.size)?_:this.item.transform.size,I=j.x,U=void 0===I?1:I,$=j.y,q=void 0===$?1:$;this.item.transform.size.set(U*P*this.SCALE_FACTOR*this.SCALE_FACTOR,q*N*this.SCALE_FACTOR*this.SCALE_FACTOR),this.initialized=!0;break;case i.TextOverflow.clip:var G,J=f*c,K=u*c;t.canvasWidth=J,t.canvasHeight=K,t.baselineCompensationX=0,t.baselineCompensationY=0,this.canvasSize=new l.Vector2(J,K),h.width=f,h.height=u;var Q=null!=(G=this.size)?G:this.item.transform.size,Z=Q.x,tt=void 0===Z?1:Z,et=Q.y,it=void 0===et?1:et;this.item.transform.size.set(tt*J*this.SCALE_FACTOR*this.SCALE_FACTOR,it*K*this.SCALE_FACTOR*this.SCALE_FACTOR),this.initialized=!0;break;case i.TextOverflow.display:if(!this.initialized){var nt=f*c,rt=u*c;this.canvasSize=new l.Vector2(nt,rt),this.item.transform.size.set(a*nt*this.SCALE_FACTOR*this.SCALE_FACTOR,s*rt*this.SCALE_FACTOR*this.SCALE_FACTOR),this.initialized=!0}}},n.resolveCanvasSize=function(t,e,i,n){var r=Math.max(1,t.maxLineWidth||0),a=Math.max(1,t.totalHeight||0);return e.width=r/i.fontScale,e.height=a/i.fontScale,{canvasWidth:r,canvasHeight:a,contentWidth:t.maxLineWidth,bboxTop:t.bboxTop,bboxBottom:t.bboxBottom,bboxHeight:t.bboxHeight,lines:t.lines}},n.drawTextWithStrategies=function(t,e,i,n,r,a){var o=n.baselineY,l=i.lineOffsets;e.forEach((function(i,n){var r=i.richOptions,s=i.chars,h=l[n],c=o;r.forEach((function(e,n){var r=a.fontScale,o=a.textColor,l=a.fontFamily,f=a.textWeight,u=a.fontStyle,g=e.fontSize,x=e.fontColor,p=void 0===x?o:x,v=e.fontFamily,d=void 0===v?l:v,m=e.fontWeight,y=void 0===m?f:m,S=e.fontStyle,w=void 0===S?u:S,T=g;t.font=w+" "+y+" "+T*r+"px "+d;var b=p[0],A=p[1],O=p[2],C=p[3];t.fillStyle="rgba("+b+", "+A+", "+O+", "+C+")";var z=i.offsetX&&i.offsetX[n]?i.offsetX[n]:0;s[n].forEach((function(e){t.fillText(e.char,h+z+e.x,c)}))})),n<e.length-1&&(o+=e[n+1].lineHeight)}))},n.unsupported=function(t){throw new Error("RichTextComponent does not support "+t+" at runtime.")},n.setShadowOffsetY=function(t){this.unsupported("setShadowOffsetY")},n.setShadowBlur=function(t){this.unsupported("setShadowBlur")},n.setShadowOffsetX=function(t){this.unsupported("setShadowOffsetX")},n.setShadowColor=function(t){this.unsupported("setShadowColor")},n.setOutlineWidth=function(t){this.unsupported("setOutlineWidth")},n.setAutoWidth=function(t){this.unsupported("setAutoWidth")},n.setFontSize=function(t){this.unsupported("setFontSize")},n.setTextBaseline=function(t){console.warn("setTextBaseline 已废弃,请改用 setTextVerticalAlign。本次调用将转调用 setTextVerticalAlign。"),this.setTextVerticalAlign(t)},e}(h);r(j=function(t,e,i,n){var r,a=arguments.length,o=a<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,i):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,e,i,n);else for(var l=t.length-1;l>=0;l--)(r=t[l])&&(o=(a<3?r(o):a>3?r(e,i,o):r(e,i))||o);return a>3&&o&&Object.defineProperty(e,i,o),o}([n(i.DataType.RichTextComponent)],j),[a]);var I="2.8.6";c("rich-text",S),f.info("Plugin rich text version: 2.8.6."),I!==t.version&&console.error("注意:请统一 RichText 插件与 Player 版本,不统一的版本混用会有不可预知的后果!","\nAttention: Please ensure the RichText plugin is synchronized with the Player version. Mixing and matching incompatible versions may result in unpredictable consequences!");export{j as RichTextComponent,S as RichTextLoader,E as escape,L as generateProgram,H as isRichText,C as lexer,z as richTextParser,W as unescape,I as version};
2
2
  //# sourceMappingURL=weapp.mjs.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@galacean/effects-plugin-rich-text",
3
- "version": "2.8.4",
3
+ "version": "2.8.6",
4
4
  "description": "Galacean Effects player rich text plugin",
5
5
  "module": "./dist/index.mjs",
6
6
  "main": "./dist/index.js",
@@ -50,7 +50,7 @@
50
50
  "registry": "https://registry.npmjs.org"
51
51
  },
52
52
  "devDependencies": {
53
- "@galacean/effects": "2.8.4"
53
+ "@galacean/effects": "2.8.6"
54
54
  },
55
55
  "scripts": {
56
56
  "dev": "vite",