@galacean/effects-plugin-rich-text 2.9.1 → 2.9.2

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]+)>$/,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 a,o=p(d);!(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 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 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=v(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 w=function(){function e(e){this.width=0,this.height=0;var i=e.textOverflow,n=void 0===i?t.spec.TextOverflow.clip:i,r=e.textVerticalAlign,a=void 0===r?t.spec.TextVerticalAlign.middle:r,o=e.textAlign,s=void 0===o?t.spec.TextAlignment.left:o,l=e.letterSpace,c=void 0===l?0:l,h=e.lineHeight,u=void 0===h?.571:h,f=e.wrapEnabled,p=void 0!==f&&f,x=e.maxTextWidth,g=void 0===x?350:x,d=e.maxTextHeight,v=void 0===d?1e3:d,m=e.autoResize,y=void 0===m?t.spec.TextSizeMode.autoWidth:m,w=e.useLegacyRichText,T=void 0!==w&&w;this.letterSpace=c,this.lineHeight=u,this.useLegacyRichText=T,this.overflow=n,this.textVerticalAlign=a,this.textAlign=s,this.width=100,this.height=100,this.wrapEnabled=p,this.maxTextWidth=g,this.maxTextHeight=v,this.autoResize=y}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;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 S(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){var a=this,o=[],s=[],l=n.lineHeight||0,c=this.createNewLine(),h=0,u=0,f=function(){if(0!==c.chars.length){c.lineHeight=l;var t=0===o.length?0:s[s.length-1]+l;s.push(t),u+=c.lineHeight,o.push(c),h=Math.max(h,c.width),c=a.createNewLine()}};t.forEach((function(t){var n=t.text,a=t.isNewLine,o=t.fontSize;a&&f();var s=t.fontStyle||i.fontStyle||"normal";e.font=s+" "+(t.fontWeight||i.textWeight)+" 10px "+(t.fontFamily||i.fontFamily),c.offsetX.push(c.width);for(var l=.1*o,h=e.measureText("x"),u=h.fontBoundingBoxAscent*l,p=h.fontBoundingBoxDescent*l,x=0,g=[],d=0;d<n.length;d++){var v=n[d],m=e.measureText(v).width,y=(m<=0?0:m)*l;d>0&&(x+=r),g.push({char:v,x:x}),x+=y}c.chars.push(g),c.width+=x,c.richOptions.push(t),c.lineAscent=Math.max(c.lineAscent||0,u),c.lineDescent=Math.max(c.lineDescent||0,p)})),f();var p=1/0,x=-1/0;if(0===o.length)return{lines:o,maxLineWidth:h,totalHeight:u,bboxTop:0,bboxBottom:0,bboxHeight:0};for(var g=0;g<o.length;g++){var d=o[g].lineAscent||0,v=o[g].lineDescent||0,m=(l-(d+v))/2;p=Math.min(p,s[g]-d-m),x=Math.max(x,s[g]+v+m)}return{lines:o,maxLineWidth:h,totalHeight:u,bboxTop:p,bboxBottom:x,bboxHeight:x-p}},e.createNewLine=function(){return{richOptions:[],offsetX:[],width:0,lineHeight:0,offsetY:0,chars:[],lineAscent:0,lineDescent:0}},t}(),O=function(){function t(){}var e=t.prototype;return e.computeLines=function(t,e,i,n,r){var a=this,o=[],s=[],l=n.lineHeight||0,c=n.maxTextWidth||1/0,h=this.createNewLine(),u=0,f=0,p=null,x=0,g=[],d=null,v=function(){if(m(),0!==h.chars.length){h.lineHeight=l;var t=0===o.length?0:s[s.length-1]+l;s.push(t),f+=h.lineHeight,o.push(h),u=Math.max(u,h.width),h=a.createNewLine(),p=null,x=0,g=[],d=null}},m=function(){0!==g.length&&(null===p&&(p=h.width),h.offsetX.push(p),h.chars.push(g),d&&h.richOptions.push(d),p=null,x=0,g=[],d=null)};t.forEach((function(t){var n=t.text,a=t.isNewLine,o=t.fontSize,s=t.fontStyle||i.fontStyle||"normal";e.font=s+" "+(t.fontWeight||i.textWeight)+" 10px "+(t.fontFamily||i.fontFamily),a&&(m(),v());for(var l=.1*o,u=e.measureText("x"),f=u.fontBoundingBoxAscent*l,y=u.fontBoundingBoxDescent*l,w=0;w<n.length;w++){var T=n[w],S=e.measureText(T).width,b=(S<=0?0:S)*l,O=g.length>0?r:0;h.width+O+b>c&&(m(),v()),null===p&&(p=h.width,d=t),g.length>0&&(x+=r,h.width+=r),g.push({char:T,x:x}),h.lineAscent=Math.max(h.lineAscent||0,f),h.lineDescent=Math.max(h.lineDescent||0,y),x+=b,h.width+=b}m()})),v();var y=1/0,w=-1/0;if(0===o.length)return{lines:o,maxLineWidth:u,totalHeight:f,bboxTop:0,bboxBottom:0,bboxHeight:0};for(var T=0;T<o.length;T++){var S=o[T].lineAscent||0,b=o[T].lineDescent||0,O=(l-(S+b))/2;y=Math.min(y,s[T]-S-O),w=Math.max(w,s[T]+b+O)}return{lines:o,maxLineWidth:u,totalHeight:f,bboxTop:y,bboxBottom:w,bboxHeight:w-y}},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.resolveCanvas=function(t,e,i,n,r){return{canvasWidth:Math.max(1,Math.ceil(e)),canvasHeight:Math.max(1,Math.ceil(i)),renderOffsetX:0,renderOffsetY:0}},t}(),M=function(){function t(){}return t.prototype.resolveCanvas=function(t,e,i,n,r){if(0===t.length)return{canvasWidth:Math.max(1,e),canvasHeight:Math.max(1,i),renderOffsetX:0,renderOffsetY:0};for(var a=1/0,o=-1/0,s=r.baselineY,l=0;l<t.length;l++){var c,h,u=null!=(c=t[l].lineAscent)?c:0,f=null!=(h=t[l].lineDescent)?h:0,p=u+f,x=Math.max(0,(t[l].lineHeight-p)/2);a=Math.min(a,s-u-x),o=Math.max(o,s+f+x),l<t.length-1&&(s+=t[l+1].lineHeight)}for(var g=Math.max(0,-a),d=Math.max(0,o-i),v=Math.max(g,d),m=1/0,y=-1/0,w=0;w<t.length;w++){var T,S,b=null!=(T=n.lineOffsets[w])?T:0,O=null!=(S=t[w].width)?S:0;m=Math.min(m,b),y=Math.max(y,b+O)}isFinite(m)||(m=0),isFinite(y)||(y=0);var A=Math.max(0,-m),M=Math.max(0,y-e),H=Math.max(A,M),z=Math.ceil(e+2*H),E=Math.ceil(i+2*v);return{canvasWidth:Math.max(1,z),canvasHeight:Math.max(1,E),renderOffsetX:H,renderOffsetY:v}},t}(),H=function(){function t(){}return t.prototype.getHorizontalOffsets=function(t,e,i,n){return{lineOffsets:t.map((function(t){return i.getOffsetXRich(n,e,t.width)}))}},t}(),z=function(){function e(){}return e.prototype.getVerticalOffsets=function(e,i,n){if(0===e.length)return{baselineY:0,lineYOffsets:[]};for(var r=[0],a=1;a<e.length;a++)r[a]=r[a-1]+e[a].lineHeight;for(var o=1/0,s=-1/0,l=0;l<e.length;l++){var c,h,u=null!=(c=e[l].lineAscent)?c:0,f=null!=(h=e[l].lineDescent)?h:0,p=u+f,x=(e[l].lineHeight-p)/2;o=Math.min(o,r[l]-u-x),s=Math.max(s,r[l]+f+x)}var g=s-o,d=0;switch(n.textVerticalAlign){case t.spec.TextVerticalAlign.top:d=-o;break;case t.spec.TextVerticalAlign.middle:d=(i-g)/2-o;break;case t.spec.TextVerticalAlign.bottom:d=i-g-o}var v=r.map((function(t){return d+t}));return{baselineY:d,lineYOffsets:v}},e}(),E=function(){function e(){}return e.createWrapStrategy=function(t){return t?new O:new b},e.createOverflowStrategy=function(e){switch(e){case t.spec.TextOverflow.clip:return new A;case t.spec.TextOverflow.display:case t.spec.TextOverflow.visible:default:return new M}},e.createHorizontalAlignStrategy=function(){return new H},e.createVerticalAlignStrategy=function(){return new z},e}();function L(){return L=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var i=arguments[e];for(var n in i)Object.prototype.hasOwnProperty.call(i,n)&&(t[n]=i[n])}return t},L.apply(this,arguments)}var 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=.11092565,n.ALPHA_FIX_VALUE=1/255,n.name="MRichText"+W++,n.initTextBase(i),n.richWrapStrategy=E.createWrapStrategy(),n.richOverflowStrategy=E.createOverflowStrategy(t.spec.TextOverflow.display),n.richHorizontalAlignStrategy=E.createHorizontalAlignStrategy(),n.richVerticalAlignStrategy=E.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 w(r),this.text=r.text?r.text.toString():" ",this.textLayout.useLegacyRichText&&(this.textLayout.textVerticalAlign=t.spec.TextVerticalAlign.middle),this.updateStrategies(),this.updateTexture(),this.material.setColor("_Color",new t.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(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=S(n.color)),i.processedTextOptions.push(a)}))}));n(e)},n.updateWithOptions=function(e){this.textStyle=new t.TextStyle(e),this.textLayout=new w(e),this.text=e.text?e.text.toString():" ",this.textLayout.useLegacyRichText&&(this.textLayout.textVerticalAlign=t.spec.TextVerticalAlign.middle),this.updateStrategies(),this.isDirty=!0},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){var n=.1;this.generateTextProgram(this.text);var r=0,a=0,o=this.textLayout,s=this.textStyle,l=o.overflow,c=o.letterSpace,h=void 0===c?0:c,u=this.context,f=[],p=s.fontSize*s.fontScale,x={richOptions:[],offsetX:[],width:0,lineHeight:p*this.singleLineHeight,offsetY:p*(this.singleLineHeight-1)/2};if(this.processedTextOptions.forEach((function(t){var e=t.text,o=t.isNewLine,l=t.fontSize;o&&(f.push(x),r=Math.max(r,x.width),x={richOptions:[],offsetX:[],width:0,lineHeight:p*i.singleLineHeight,offsetY:p*(i.singleLineHeight-1)/2},a+=x.lineHeight),u.font=(t.fontWeight||s.textWeight)+" 10px "+(t.fontFamily||s.fontFamily);var c=u.measureText(e),g=c.width;if(void 0!==c.actualBoundingBoxLeft&&void 0!==c.actualBoundingBoxRight){var d=c.actualBoundingBoxLeft+c.actualBoundingBoxRight;d>0&&(g=Math.max(g,d))}var v=l*i.singleLineHeight*s.fontScale;v>x.lineHeight&&(a+=v-x.lineHeight,x.lineHeight=v,x.offsetY=l*s.fontScale*(i.singleLineHeight-1)/2),x.offsetX.push(x.width),x.width+=(g<=0?0:g)*l*n*s.fontScale+e.length*h,x.richOptions.push(t)})),f.push(x),r=Math.max(r,x.width),a+=x.lineHeight,0!==r&&0!==a){void 0!==this.size&&null!==this.size||(this.size=this.item.transform.size.clone());var g=this.size,d=g.x,v=void 0===d?1:d,m=g.y,y=void 0===m?1:m;if(!this.initialized){this.canvasSize=this.canvasSize?this.canvasSize:new t.math.Vector2(r,a);var w=this.canvasSize,T=w.x,S=w.y;this.item.transform.size.set(v*T*n*n,y*S*n*n),this.size=this.item.transform.size.clone(),this.initialized=!0}t.assertExist(this.canvasSize);var b=this.canvasSize,O=b.x,A=b.y;o.width=O/s.fontScale,o.height=A/s.fontScale,this.renderToTexture(O,A,e,(function(e){if(0!==f.length){var n=o.getOffsetY(s,f.length,p*i.singleLineHeight,s.fontSize);f.forEach((function(i,r){var a=i.richOptions,c=i.offsetX,h=i.width,u=h,f=c;if(l===t.spec.TextOverflow.display&&h>O){var p=O/h;u*=p,f=c.map((function(t){return t*p}))}var x=o.getOffsetX(s,u);r>0&&(n+=i.lineHeight-i.offsetY),a.forEach((function(i,r){var a=s.fontScale,o=s.textColor,c=s.fontFamily,u=s.textWeight,p=s.fontStyle,g=i.text,d=i.fontSize,v=i.fontColor,m=void 0===v?o:v,y=i.fontFamily,w=void 0===y?c:y,T=i.fontWeight,S=void 0===T?u:T,b=i.fontStyle,A=void 0===b?p:b,M=d;l===t.spec.TextOverflow.display&&h>O&&(M/=h/O);var H=f[r]+x;e.font=A+" "+S+" "+M*a+"px "+w;var z=m[0],E=m[1],L=m[2],W=m[3];e.fillStyle="rgba("+z+", "+E+", "+L+", "+W+")",e.fillText(g,H,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.updateStrategies(),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.textStyle.fontScale;n.autoResize===t.spec.TextSizeMode.autoWidth&&(n.maxTextWidth=Number.MAX_SAFE_INTEGER);var l,c,h=this.richWrapStrategy.computeLines(this.processedTextOptions,o,this.textStyle,n,a);switch(n.autoResize){case t.spec.TextSizeMode.autoWidth:l=Math.max(1,h.maxLineWidth||0),c=Math.max(1,h.totalHeight||0);break;case t.spec.TextSizeMode.autoHeight:l=n.maxTextWidth,c=Math.max(1,h.totalHeight||0);break;case t.spec.TextSizeMode.fixed:default:l=n.maxTextWidth,c=n.maxTextHeight}if(n.overflow===t.spec.TextOverflow.display){var u=Math.max(1,h.maxLineWidth||0),f=Math.max(1,h.totalHeight||0);!function(t,e,i,n,r){var a=function(t,e){return Math.abs(e)>1e-5?t/e:1},o=Math.max(1,e),s=Math.max(1,i),l=Math.min(1,a(n,o),a(r,s));if(!(l>.9999))for(var c,h=p(t);!(c=h()).done;){var u=c.value;if(u.width*=l,u.lineHeight*=l,u.offsetX)for(var f=0;f<u.offsetX.length;f++)u.offsetX[f]*=l;for(var x,g=p(u.chars||[]);!(x=g()).done;)for(var d,v=p(x.value);!(d=v()).done;)d.value.x*=l;for(var m=u.richOptions||[],y=[],w=0;w<m.length;w++)y.push(L({},m[w],{fontSize:m[w].fontSize*l}));u.richOptions=y,null!=u.lineAscent&&(u.lineAscent*=l),null!=u.lineDescent&&(u.lineDescent*=l)}}(h.lines,u,f,l,c)}var x=this.richHorizontalAlignStrategy.getHorizontalOffsets(h.lines,l,n,this.textStyle),g=this.richVerticalAlignStrategy.getVerticalOffsets(h.lines,c,n),d=this.richOverflowStrategy.resolveCanvas(h.lines,l,c,x,g),v=Math.max(1,Math.ceil(d.canvasWidth*s)),m=Math.max(1,Math.ceil(d.canvasHeight*s));this.item.transform.size.set(d.canvasWidth*this.SCALE_FACTOR*this.SCALE_FACTOR,d.canvasHeight*this.SCALE_FACTOR*this.SCALE_FACTOR),n.maxTextWidth=l,n.maxTextHeight=c,n.width=d.canvasWidth,n.height=d.canvasHeight,this.renderToTexture(v,m,e,(function(t){t.scale(s,s),i.drawTextWithStrategies(t,h.lines,x,g,d,i.textStyle)}),{disposeOld:!1}),this.isDirty=!1}}},n.drawTextWithStrategies=function(t,e,i,n,r,a){var o=r.renderOffsetX,s=r.renderOffsetY,l=n.baselineY+s,c=i.lineOffsets;e.forEach((function(i,n){var r=i.richOptions,s=i.chars,h=c[n]+o,u=l;r.forEach((function(e,n){var r=a.textColor,o=a.fontFamily,l=a.textWeight,c=a.fontStyle,f=e.fontSize,p=e.fontColor,x=void 0===p?r:p,g=e.fontFamily,d=void 0===g?o:g,v=e.fontWeight,m=void 0===v?l:v,y=e.fontStyle,w=void 0===y?c:y,T=f;t.font=w+" "+m+" "+T+"px "+d;var S=x[0],b=x[1],O=x[2],A=x[3];t.fillStyle="rgba("+S+", "+b+", "+O+", "+A+")";var M=i.offsetX&&i.offsetX[n]?i.offsetX[n]:0;s[n].forEach((function(e){t.fillText(e.char,h+M+e.x,u)}))})),n<e.length-1&&(l+=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 C="2.9.1";t.registerPlugin("rich-text",u),t.logger.info("Plugin rich text version: 2.9.1."),C!==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=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 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=v,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=C;
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]+)>$/,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 a,o=p(d);!(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 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 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=v(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 w=function(){function e(e){this.width=0,this.height=0;var i=e.textOverflow,n=void 0===i?t.spec.TextOverflow.clip:i,r=e.textVerticalAlign,a=void 0===r?t.spec.TextVerticalAlign.middle:r,o=e.textAlign,s=void 0===o?t.spec.TextAlignment.left:o,l=e.letterSpace,c=void 0===l?0:l,h=e.lineHeight,u=void 0===h?.571:h,f=e.wrapEnabled,p=void 0!==f&&f,x=e.maxTextWidth,g=void 0===x?350:x,d=e.maxTextHeight,v=void 0===d?1e3:d,m=e.autoResize,y=void 0===m?t.spec.TextSizeMode.autoWidth:m,w=e.useLegacyRichText,T=void 0!==w&&w;this.letterSpace=c,this.lineHeight=u,this.useLegacyRichText=T,this.overflow=n,this.textVerticalAlign=a,this.textAlign=s,this.width=100,this.height=100,this.wrapEnabled=p,this.maxTextWidth=g,this.maxTextHeight=v,this.autoResize=y}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;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 S(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){var a=this,o=[],s=[],l=n.lineHeight||0,c=this.createNewLine(),h=0,u=0,f=function(){if(0!==c.chars.length){c.lineHeight=l;var t=0===o.length?0:s[s.length-1]+l;s.push(t),u+=c.lineHeight,o.push(c),h=Math.max(h,c.width),c=a.createNewLine()}};t.forEach((function(t){var n=t.text,a=t.isNewLine,o=t.fontSize;a&&f();var s=t.fontStyle||i.fontStyle||"normal";e.font=s+" "+(t.fontWeight||i.textWeight)+" 10px "+(t.fontFamily||i.fontFamily),c.offsetX.push(c.width);for(var l=.1*o,h=e.measureText("x"),u=h.fontBoundingBoxAscent*l,p=h.fontBoundingBoxDescent*l,x=0,g=[],d=0;d<n.length;d++){var v=n[d],m=e.measureText(v).width,y=(m<=0?0:m)*l;d>0&&(x+=r),g.push({char:v,x:x}),x+=y}c.chars.push(g),c.width+=x,c.richOptions.push(t),c.lineAscent=Math.max(c.lineAscent||0,u),c.lineDescent=Math.max(c.lineDescent||0,p)})),f();var p=1/0,x=-1/0;if(0===o.length)return{lines:o,maxLineWidth:h,totalHeight:u,bboxTop:0,bboxBottom:0,bboxHeight:0};for(var g=0;g<o.length;g++){var d=o[g].lineAscent||0,v=o[g].lineDescent||0,m=(l-(d+v))/2;p=Math.min(p,s[g]-d-m),x=Math.max(x,s[g]+v+m)}return{lines:o,maxLineWidth:h,totalHeight:u,bboxTop:p,bboxBottom:x,bboxHeight:x-p}},e.createNewLine=function(){return{richOptions:[],offsetX:[],width:0,lineHeight:0,offsetY:0,chars:[],lineAscent:0,lineDescent:0}},t}(),O=function(){function t(){}var e=t.prototype;return e.computeLines=function(t,e,i,n,r){var a=this,o=[],s=[],l=n.lineHeight||0,c=n.maxTextWidth||1/0,h=this.createNewLine(),u=0,f=0,p=null,x=0,g=[],d=null,v=function(){if(m(),0!==h.chars.length){h.lineHeight=l;var t=0===o.length?0:s[s.length-1]+l;s.push(t),f+=h.lineHeight,o.push(h),u=Math.max(u,h.width),h=a.createNewLine(),p=null,x=0,g=[],d=null}},m=function(){0!==g.length&&(null===p&&(p=h.width),h.offsetX.push(p),h.chars.push(g),d&&h.richOptions.push(d),p=null,x=0,g=[],d=null)};t.forEach((function(t){var n=t.text,a=t.isNewLine,o=t.fontSize,s=t.fontStyle||i.fontStyle||"normal";e.font=s+" "+(t.fontWeight||i.textWeight)+" 10px "+(t.fontFamily||i.fontFamily),a&&(m(),v());for(var l=.1*o,u=e.measureText("x"),f=u.fontBoundingBoxAscent*l,y=u.fontBoundingBoxDescent*l,w=0;w<n.length;w++){var T=n[w],S=e.measureText(T).width,b=(S<=0?0:S)*l,O=g.length>0?r:0;h.width+O+b>c&&(m(),v()),null===p&&(p=h.width,d=t),g.length>0&&(x+=r,h.width+=r),g.push({char:T,x:x}),h.lineAscent=Math.max(h.lineAscent||0,f),h.lineDescent=Math.max(h.lineDescent||0,y),x+=b,h.width+=b}m()})),v();var y=1/0,w=-1/0;if(0===o.length)return{lines:o,maxLineWidth:u,totalHeight:f,bboxTop:0,bboxBottom:0,bboxHeight:0};for(var T=0;T<o.length;T++){var S=o[T].lineAscent||0,b=o[T].lineDescent||0,O=(l-(S+b))/2;y=Math.min(y,s[T]-S-O),w=Math.max(w,s[T]+b+O)}return{lines:o,maxLineWidth:u,totalHeight:f,bboxTop:y,bboxBottom:w,bboxHeight:w-y}},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.resolveCanvas=function(t,e,i,n,r){return{canvasWidth:Math.max(1,Math.ceil(e)),canvasHeight:Math.max(1,Math.ceil(i)),renderOffsetX:0,renderOffsetY:0}},t}(),M=function(){function t(){}return t.prototype.resolveCanvas=function(t,e,i,n,r){if(0===t.length)return{canvasWidth:Math.max(1,e),canvasHeight:Math.max(1,i),renderOffsetX:0,renderOffsetY:0};for(var a=1/0,o=-1/0,s=r.baselineY,l=0;l<t.length;l++){var c,h,u=null!=(c=t[l].lineAscent)?c:0,f=null!=(h=t[l].lineDescent)?h:0,p=u+f,x=Math.max(0,(t[l].lineHeight-p)/2);a=Math.min(a,s-u-x),o=Math.max(o,s+f+x),l<t.length-1&&(s+=t[l+1].lineHeight)}for(var g=Math.max(0,-a),d=Math.max(0,o-i),v=Math.max(g,d),m=1/0,y=-1/0,w=0;w<t.length;w++){var T,S,b=null!=(T=n.lineOffsets[w])?T:0,O=null!=(S=t[w].width)?S:0;m=Math.min(m,b),y=Math.max(y,b+O)}isFinite(m)||(m=0),isFinite(y)||(y=0);var A=Math.max(0,-m),M=Math.max(0,y-e),H=Math.max(A,M),z=Math.ceil(e+2*H),E=Math.ceil(i+2*v);return{canvasWidth:Math.max(1,z),canvasHeight:Math.max(1,E),renderOffsetX:H,renderOffsetY:v}},t}(),H=function(){function t(){}return t.prototype.getHorizontalOffsets=function(t,e,i,n){return{lineOffsets:t.map((function(t){return i.getOffsetXRich(n,e,t.width)}))}},t}(),z=function(){function e(){}return e.prototype.getVerticalOffsets=function(e,i,n){if(0===e.length)return{baselineY:0,lineYOffsets:[]};for(var r=[0],a=1;a<e.length;a++)r[a]=r[a-1]+e[a].lineHeight;for(var o=1/0,s=-1/0,l=0;l<e.length;l++){var c,h,u=null!=(c=e[l].lineAscent)?c:0,f=null!=(h=e[l].lineDescent)?h:0,p=u+f,x=(e[l].lineHeight-p)/2;o=Math.min(o,r[l]-u-x),s=Math.max(s,r[l]+f+x)}var g=s-o,d=0;switch(n.textVerticalAlign){case t.spec.TextVerticalAlign.top:d=-o;break;case t.spec.TextVerticalAlign.middle:d=(i-g)/2-o;break;case t.spec.TextVerticalAlign.bottom:d=i-g-o}var v=r.map((function(t){return d+t}));return{baselineY:d,lineYOffsets:v}},e}(),E=function(){function e(){}return e.createWrapStrategy=function(t){return t?new O:new b},e.createOverflowStrategy=function(e){switch(e){case t.spec.TextOverflow.clip:return new A;case t.spec.TextOverflow.display:case t.spec.TextOverflow.visible:default:return new M}},e.createHorizontalAlignStrategy=function(){return new H},e.createVerticalAlignStrategy=function(){return new z},e}();function L(){return L=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var i=arguments[e];for(var n in i)Object.prototype.hasOwnProperty.call(i,n)&&(t[n]=i[n])}return t},L.apply(this,arguments)}var 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=.11092565,n.ALPHA_FIX_VALUE=1/255,n.name="MRichText"+W++,n.initTextBase(i),n.richWrapStrategy=E.createWrapStrategy(),n.richOverflowStrategy=E.createOverflowStrategy(t.spec.TextOverflow.display),n.richHorizontalAlignStrategy=E.createHorizontalAlignStrategy(),n.richVerticalAlignStrategy=E.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 w(r),this.text=r.text?r.text.toString():" ",this.textLayout.useLegacyRichText&&(this.textLayout.textVerticalAlign=t.spec.TextVerticalAlign.middle),this.updateStrategies(),this.updateTexture(),this.material.setColor("_Color",new t.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(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=S(n.color)),i.processedTextOptions.push(a)}))}));n(e)},n.updateWithOptions=function(e){this.textStyle=new t.TextStyle(e),this.textLayout=new w(e),this.text=e.text?e.text.toString():" ",this.textLayout.useLegacyRichText&&(this.textLayout.textVerticalAlign=t.spec.TextVerticalAlign.middle),this.updateStrategies(),this.isDirty=!0},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){var n=.1;this.generateTextProgram(this.text);var r=0,a=0,o=this.textLayout,s=this.textStyle,l=o.overflow,c=o.letterSpace,h=void 0===c?0:c,u=this.context,f=[],p=s.fontSize*s.fontScale,x={richOptions:[],offsetX:[],width:0,lineHeight:p*this.singleLineHeight,offsetY:p*(this.singleLineHeight-1)/2};if(this.processedTextOptions.forEach((function(t){var e=t.text,o=t.isNewLine,l=t.fontSize;o&&(f.push(x),r=Math.max(r,x.width),x={richOptions:[],offsetX:[],width:0,lineHeight:p*i.singleLineHeight,offsetY:p*(i.singleLineHeight-1)/2},a+=x.lineHeight),u.font=(t.fontWeight||s.textWeight)+" 10px "+(t.fontFamily||s.fontFamily);var c=u.measureText(e),g=c.width;if(void 0!==c.actualBoundingBoxLeft&&void 0!==c.actualBoundingBoxRight){var d=c.actualBoundingBoxLeft+c.actualBoundingBoxRight;d>0&&(g=Math.max(g,d))}var v=l*i.singleLineHeight*s.fontScale;v>x.lineHeight&&(a+=v-x.lineHeight,x.lineHeight=v,x.offsetY=l*s.fontScale*(i.singleLineHeight-1)/2),x.offsetX.push(x.width),x.width+=(g<=0?0:g)*l*n*s.fontScale+e.length*h,x.richOptions.push(t)})),f.push(x),r=Math.max(r,x.width),a+=x.lineHeight,0!==r&&0!==a){void 0!==this.size&&null!==this.size||(this.size=this.item.transform.size.clone());var g=this.size,d=g.x,v=void 0===d?1:d,m=g.y,y=void 0===m?1:m;if(!this.initialized){this.canvasSize=this.canvasSize?this.canvasSize:new t.math.Vector2(r,a);var w=this.canvasSize,T=w.x,S=w.y;this.item.transform.size.set(v*T*n*n,y*S*n*n),this.size=this.item.transform.size.clone(),this.initialized=!0}t.assertExist(this.canvasSize);var b=this.canvasSize,O=b.x,A=b.y;o.width=O/s.fontScale,o.height=A/s.fontScale,this.renderToTexture(O,A,e,(function(e){if(0!==f.length){var n=o.getOffsetY(s,f.length,p*i.singleLineHeight,s.fontSize);f.forEach((function(i,r){var a=i.richOptions,c=i.offsetX,h=i.width,u=h,f=c;if(l===t.spec.TextOverflow.display&&h>O){var p=O/h;u*=p,f=c.map((function(t){return t*p}))}var x=o.getOffsetX(s,u);r>0&&(n+=i.lineHeight-i.offsetY),a.forEach((function(i,r){var a=s.fontScale,o=s.textColor,c=s.fontFamily,u=s.textWeight,p=s.fontStyle,g=i.text,d=i.fontSize,v=i.fontColor,m=void 0===v?o:v,y=i.fontFamily,w=void 0===y?c:y,T=i.fontWeight,S=void 0===T?u:T,b=i.fontStyle,A=void 0===b?p:b,M=d;l===t.spec.TextOverflow.display&&h>O&&(M/=h/O);var H=f[r]+x;e.font=A+" "+S+" "+M*a+"px "+w;var z=m[0],E=m[1],L=m[2],W=m[3];e.fillStyle="rgba("+z+", "+E+", "+L+", "+W+")",e.fillText(g,H,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.updateStrategies(),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.textStyle.fontScale;n.autoResize===t.spec.TextSizeMode.autoWidth&&(n.maxTextWidth=Number.MAX_SAFE_INTEGER);var l,c,h=this.richWrapStrategy.computeLines(this.processedTextOptions,o,this.textStyle,n,a);switch(n.autoResize){case t.spec.TextSizeMode.autoWidth:l=Math.max(1,h.maxLineWidth||0),c=Math.max(1,h.totalHeight||0);break;case t.spec.TextSizeMode.autoHeight:l=n.maxTextWidth,c=Math.max(1,h.totalHeight||0);break;case t.spec.TextSizeMode.fixed:default:l=n.maxTextWidth,c=n.maxTextHeight}if(n.overflow===t.spec.TextOverflow.display){var u=Math.max(1,h.maxLineWidth||0),f=Math.max(1,h.totalHeight||0);!function(t,e,i,n,r){var a=function(t,e){return Math.abs(e)>1e-5?t/e:1},o=Math.max(1,e),s=Math.max(1,i),l=Math.min(1,a(n,o),a(r,s));if(!(l>.9999))for(var c,h=p(t);!(c=h()).done;){var u=c.value;if(u.width*=l,u.lineHeight*=l,u.offsetX)for(var f=0;f<u.offsetX.length;f++)u.offsetX[f]*=l;for(var x,g=p(u.chars||[]);!(x=g()).done;)for(var d,v=p(x.value);!(d=v()).done;)d.value.x*=l;for(var m=u.richOptions||[],y=[],w=0;w<m.length;w++)y.push(L({},m[w],{fontSize:m[w].fontSize*l}));u.richOptions=y,null!=u.lineAscent&&(u.lineAscent*=l),null!=u.lineDescent&&(u.lineDescent*=l)}}(h.lines,u,f,l,c)}var x=this.richHorizontalAlignStrategy.getHorizontalOffsets(h.lines,l,n,this.textStyle),g=this.richVerticalAlignStrategy.getVerticalOffsets(h.lines,c,n),d=this.richOverflowStrategy.resolveCanvas(h.lines,l,c,x,g),v=Math.max(1,Math.ceil(d.canvasWidth*s)),m=Math.max(1,Math.ceil(d.canvasHeight*s));this.item.transform.size.set(d.canvasWidth*this.SCALE_FACTOR*this.SCALE_FACTOR,d.canvasHeight*this.SCALE_FACTOR*this.SCALE_FACTOR),n.maxTextWidth=l,n.maxTextHeight=c,n.width=d.canvasWidth,n.height=d.canvasHeight,this.renderToTexture(v,m,e,(function(t){t.scale(s,s),i.drawTextWithStrategies(t,h.lines,x,g,d,i.textStyle)}),{disposeOld:!1}),this.isDirty=!1}}},n.drawTextWithStrategies=function(t,e,i,n,r,a){var o=r.renderOffsetX,s=r.renderOffsetY,l=n.baselineY+s,c=i.lineOffsets;e.forEach((function(i,n){var r=i.richOptions,s=i.chars,h=c[n]+o,u=l;r.forEach((function(e,n){var r=a.textColor,o=a.fontFamily,l=a.textWeight,c=a.fontStyle,f=e.fontSize,p=e.fontColor,x=void 0===p?r:p,g=e.fontFamily,d=void 0===g?o:g,v=e.fontWeight,m=void 0===v?l:v,y=e.fontStyle,w=void 0===y?c:y,T=f;t.font=w+" "+m+" "+T+"px "+d;var S=x[0],b=x[1],O=x[2],A=x[3];t.fillStyle="rgba("+S+", "+b+", "+O+", "+A+")";var M=i.offsetX&&i.offsetX[n]?i.offsetX[n]:0;s[n].forEach((function(e){t.fillText(e.char,h+M+e.x,u)}))})),n<e.length-1&&(l+=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 C="2.9.2";t.registerPlugin("rich-text",u),t.logger.info("Plugin rich text version: 2.9.2."),C!==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=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 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=v,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=C;
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 s,assertExist as l,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 d(t,e,i){return d=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},d.apply(null,arguments)}function v(t){return v=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},v(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 d(t,arguments,v(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,w=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 S(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 S(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)?S(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]+)(=([^>]+))?>$/,O=/^<\/([a-z]+)>$/,A=[["EscapedChar",/^\\([=<>\\/])/],["ContextStart",/^<[a-z]+(=[^>]+)?>/],["ContextEnd",/^<\/[a-z]+>/],["Text",/^[^</>=\\]+/]],H=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 H(t.slice(2),e.concat({tokenType:"Text",value:r}),i+2)}for(var a,o=T(A);!(a=o()).done;){var s=a.value,l=s[0],h=s[1];if("EscapedChar"!==l){var c=h.exec(t);if(c){var f=c[0],u=f.length;return H(t.slice(u),e.concat({tokenType:l,value:f}),i+u)}}}if(t.length>0)return H(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(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=s();if("ContextEnd"===(null==t?void 0:t.tokenType)){o();var e=t.value.match(O);if(e)return{attributeName:e[1]};throw new Error("Expect an end tag marker at position "+a)}return{}},r=H(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 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)}}}(),l};function z(t){return function(e){for(var i,n=T(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 L(t){var e=H(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(O)[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 C=function(){function t(t){this.width=0,this.height=0;var e=t.textOverflow,n=void 0===e?i.TextOverflow.clip:e,r=t.textVerticalAlign,a=void 0===r?i.TextVerticalAlign.middle:r,o=t.textAlign,s=void 0===o?i.TextAlignment.left:o,l=t.letterSpace,h=void 0===l?0:l,c=t.lineHeight,f=void 0===c?.571:c,u=t.wrapEnabled,g=void 0!==u&&u,x=t.maxTextWidth,p=void 0===x?350:x,d=t.maxTextHeight,v=void 0===d?1e3:d,m=t.autoResize,y=void 0===m?i.TextSizeMode.autoWidth:m,w=t.useLegacyRichText,S=void 0!==w&&w;this.letterSpace=h,this.lineHeight=f,this.useLegacyRichText=S,this.overflow=n,this.textVerticalAlign=a,this.textAlign=s,this.width=100,this.height=100,this.wrapEnabled=g,this.maxTextWidth=p,this.maxTextHeight=v,this.autoResize=y}var e=t.prototype;return e.getOffsetY=function(t,e,n,r,a){var o=t.outlineWidth,s=t.fontScale,l=(n-r)/3,h=r+o*s,c=void 0!==a?a:n*(e-1),f=0;switch(this.textVerticalAlign){case i.TextVerticalAlign.top:f=h+l;break;case i.TextVerticalAlign.middle:f=(this.height*s-c+h)/2;break;case i.TextVerticalAlign.bottom:f=this.height*s-c-l}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),s=(e[0]-n)/3,l=n+r*a,h=o-e[0],c=0;switch(this.textVerticalAlign){case i.TextVerticalAlign.top:c=l+s;break;case i.TextVerticalAlign.middle:c=(this.height*a-o)/2+l;break;case i.TextVerticalAlign.bottom:c=this.height*a-h-s}return c},e.getOffsetXRich=function(t,e,n){switch(this.textAlign){case i.TextAlignment.left:return t.outlineWidth;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 k(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 R(t,e){if(void 0===e&&(e=1),"string"!=typeof t||!t)throw new Error("Invalid color string");return t.startsWith("#")?k(t,e):k(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 V=function(){function t(){}var e=t.prototype;return e.computeLines=function(t,e,i,n,r){var a=this,o=[],s=[],l=n.lineHeight||0,h=this.createNewLine(),c=0,f=0,u=function(){if(0!==h.chars.length){h.lineHeight=l;var t=0===o.length?0:s[s.length-1]+l;s.push(t),f+=h.lineHeight,o.push(h),c=Math.max(c,h.width),h=a.createNewLine()}};t.forEach((function(t){var n=t.text,a=t.isNewLine,o=t.fontSize;a&&u();var s=t.fontStyle||i.fontStyle||"normal";e.font=s+" "+(t.fontWeight||i.textWeight)+" 10px "+(t.fontFamily||i.fontFamily),h.offsetX.push(h.width);for(var l=.1*o,c=e.measureText("x"),f=c.fontBoundingBoxAscent*l,g=c.fontBoundingBoxDescent*l,x=0,p=[],d=0;d<n.length;d++){var v=n[d],m=e.measureText(v).width,y=(m<=0?0:m)*l;d>0&&(x+=r),p.push({char:v,x:x}),x+=y}h.chars.push(p),h.width+=x,h.richOptions.push(t),h.lineAscent=Math.max(h.lineAscent||0,f),h.lineDescent=Math.max(h.lineDescent||0,g)})),u();var g=1/0,x=-1/0;if(0===o.length)return{lines:o,maxLineWidth:c,totalHeight:f,bboxTop:0,bboxBottom:0,bboxHeight:0};for(var p=0;p<o.length;p++){var d=o[p].lineAscent||0,v=o[p].lineDescent||0,m=(l-(d+v))/2;g=Math.min(g,s[p]-d-m),x=Math.max(x,s[p]+v+m)}return{lines:o,maxLineWidth:c,totalHeight:f,bboxTop:g,bboxBottom:x,bboxHeight:x-g}},e.createNewLine=function(){return{richOptions:[],offsetX:[],width:0,lineHeight:0,offsetY:0,chars:[],lineAscent:0,lineDescent:0}},t}(),D=function(){function t(){}var e=t.prototype;return e.computeLines=function(t,e,i,n,r){var a=this,o=[],s=[],l=n.lineHeight||0,h=n.maxTextWidth||1/0,c=this.createNewLine(),f=0,u=0,g=null,x=0,p=[],d=null,v=function(){if(m(),0!==c.chars.length){c.lineHeight=l;var t=0===o.length?0:s[s.length-1]+l;s.push(t),u+=c.lineHeight,o.push(c),f=Math.max(f,c.width),c=a.createNewLine(),g=null,x=0,p=[],d=null}},m=function(){0!==p.length&&(null===g&&(g=c.width),c.offsetX.push(g),c.chars.push(p),d&&c.richOptions.push(d),g=null,x=0,p=[],d=null)};t.forEach((function(t){var n=t.text,a=t.isNewLine,o=t.fontSize,s=t.fontStyle||i.fontStyle||"normal";e.font=s+" "+(t.fontWeight||i.textWeight)+" 10px "+(t.fontFamily||i.fontFamily),a&&(m(),v());for(var l=.1*o,f=e.measureText("x"),u=f.fontBoundingBoxAscent*l,y=f.fontBoundingBoxDescent*l,w=0;w<n.length;w++){var S=n[w],T=e.measureText(S).width,b=(T<=0?0:T)*l,O=p.length>0?r:0;c.width+O+b>h&&(m(),v()),null===g&&(g=c.width,d=t),p.length>0&&(x+=r,c.width+=r),p.push({char:S,x:x}),c.lineAscent=Math.max(c.lineAscent||0,u),c.lineDescent=Math.max(c.lineDescent||0,y),x+=b,c.width+=b}m()})),v();var y=1/0,w=-1/0;if(0===o.length)return{lines:o,maxLineWidth:f,totalHeight:u,bboxTop:0,bboxBottom:0,bboxHeight:0};for(var S=0;S<o.length;S++){var T=o[S].lineAscent||0,b=o[S].lineDescent||0,O=(l-(T+b))/2;y=Math.min(y,s[S]-T-O),w=Math.max(w,s[S]+b+O)}return{lines:o,maxLineWidth:f,totalHeight:u,bboxTop:y,bboxBottom:w,bboxHeight:w-y}},e.createNewLine=function(){return{richOptions:[],offsetX:[],width:0,lineHeight:0,offsetY:0,chars:[],lineAscent:0,lineDescent:0}},t}(),B=function(){function t(){}return t.prototype.resolveCanvas=function(t,e,i,n,r){return{canvasWidth:Math.max(1,Math.ceil(e)),canvasHeight:Math.max(1,Math.ceil(i)),renderOffsetX:0,renderOffsetY:0}},t}(),X=function(){function t(){}return t.prototype.resolveCanvas=function(t,e,i,n,r){if(0===t.length)return{canvasWidth:Math.max(1,e),canvasHeight:Math.max(1,i),renderOffsetX:0,renderOffsetY:0};for(var a=1/0,o=-1/0,s=r.baselineY,l=0;l<t.length;l++){var h,c,f=null!=(h=t[l].lineAscent)?h:0,u=null!=(c=t[l].lineDescent)?c:0,g=f+u,x=Math.max(0,(t[l].lineHeight-g)/2);a=Math.min(a,s-f-x),o=Math.max(o,s+u+x),l<t.length-1&&(s+=t[l+1].lineHeight)}for(var p=Math.max(0,-a),d=Math.max(0,o-i),v=Math.max(p,d),m=1/0,y=-1/0,w=0;w<t.length;w++){var S,T,b=null!=(S=n.lineOffsets[w])?S:0,O=null!=(T=t[w].width)?T:0;m=Math.min(m,b),y=Math.max(y,b+O)}isFinite(m)||(m=0),isFinite(y)||(y=0);var A=Math.max(0,-m),H=Math.max(0,y-e),M=Math.max(A,H),z=Math.ceil(e+2*M),L=Math.ceil(i+2*v);return{canvasWidth:Math.max(1,z),canvasHeight:Math.max(1,L),renderOffsetX:M,renderOffsetY:v}},t}(),F=function(){function t(){}return t.prototype.getHorizontalOffsets=function(t,e,i,n){return{lineOffsets:t.map((function(t){return i.getOffsetXRich(n,e,t.width)}))}},t}(),Y=function(){function t(){}return t.prototype.getVerticalOffsets=function(t,e,n){if(0===t.length)return{baselineY:0,lineYOffsets:[]};for(var r=[0],a=1;a<t.length;a++)r[a]=r[a-1]+t[a].lineHeight;for(var o=1/0,s=-1/0,l=0;l<t.length;l++){var h,c,f=null!=(h=t[l].lineAscent)?h:0,u=null!=(c=t[l].lineDescent)?c:0,g=f+u,x=(t[l].lineHeight-g)/2;o=Math.min(o,r[l]-f-x),s=Math.max(s,r[l]+u+x)}var p=s-o,d=0;switch(n.textVerticalAlign){case i.TextVerticalAlign.top:d=-o;break;case i.TextVerticalAlign.middle:d=(e-p)/2-o;break;case i.TextVerticalAlign.bottom:d=e-p-o}var v=r.map((function(t){return d+t}));return{baselineY:d,lineYOffsets:v}},t}(),N=function(){function t(){}return t.createWrapStrategy=function(t){return t?new D:new V},t.createOverflowStrategy=function(t){switch(t){case i.TextOverflow.clip:return new B;case i.TextOverflow.display:case i.TextOverflow.visible:default:return new X}},t.createHorizontalAlignStrategy=function(){return new F},t.createVerticalAlignStrategy=function(){return new Y},t}();function P(){return P=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var i=arguments[e];for(var n in i)Object.prototype.hasOwnProperty.call(i,n)&&(t[n]=i[n])}return t},P.apply(this,arguments)}var _=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=.11092565,n.ALPHA_FIX_VALUE=1/255,n.name="MRichText"+_++,n.initTextBase(e),n.richWrapStrategy=N.createWrapStrategy(),n.richOverflowStrategy=N.createOverflowStrategy(i.TextOverflow.display),n.richHorizontalAlignStrategy=N.createHorizontalAlignStrategy(),n.richVerticalAlignStrategy=N.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 C(r),this.text=r.text?r.text.toString():" ",this.textLayout.useLegacyRichText&&(this.textLayout.textVerticalAlign=i.TextVerticalAlign.middle),this.updateStrategies(),this.updateTexture(),this.material.setColor("_Color",new s.Color(1,1,1,1))},n.updateStrategies=function(){var t=this.textLayout;t&&(this.richWrapStrategy=N.createWrapStrategy(t.wrapEnabled),this.richOverflowStrategy=N.createOverflowStrategy(t.overflow))},n.generateTextProgram=function(t){var e=this;this.processedTextOptions=[];var n=z((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=R(n.color)),e.processedTextOptions.push(a)}))}));n(t)},n.updateWithOptions=function(t){this.textStyle=new o(t),this.textLayout=new C(t),this.text=t.text?t.text.toString():" ",this.textLayout.useLegacyRichText&&(this.textLayout.textVerticalAlign=i.TextVerticalAlign.middle),this.updateStrategies(),this.isDirty=!0},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){var n=.1;this.generateTextProgram(this.text);var r=0,a=0,o=this.textLayout,h=this.textStyle,c=o.overflow,f=o.letterSpace,u=void 0===f?0:f,g=this.context,x=[],p=h.fontSize*h.fontScale,d={richOptions:[],offsetX:[],width:0,lineHeight:p*this.singleLineHeight,offsetY:p*(this.singleLineHeight-1)/2};if(this.processedTextOptions.forEach((function(t){var i=t.text,o=t.isNewLine,s=t.fontSize;o&&(x.push(d),r=Math.max(r,d.width),d={richOptions:[],offsetX:[],width:0,lineHeight:p*e.singleLineHeight,offsetY:p*(e.singleLineHeight-1)/2},a+=d.lineHeight),g.font=(t.fontWeight||h.textWeight)+" 10px "+(t.fontFamily||h.fontFamily);var l=g.measureText(i),c=l.width;if(void 0!==l.actualBoundingBoxLeft&&void 0!==l.actualBoundingBoxRight){var f=l.actualBoundingBoxLeft+l.actualBoundingBoxRight;f>0&&(c=Math.max(c,f))}var v=s*e.singleLineHeight*h.fontScale;v>d.lineHeight&&(a+=v-d.lineHeight,d.lineHeight=v,d.offsetY=s*h.fontScale*(e.singleLineHeight-1)/2),d.offsetX.push(d.width),d.width+=(c<=0?0:c)*s*n*h.fontScale+i.length*u,d.richOptions.push(t)})),x.push(d),r=Math.max(r,d.width),a+=d.lineHeight,0!==r&&0!==a){void 0!==this.size&&null!==this.size||(this.size=this.item.transform.size.clone());var v=this.size,m=v.x,y=void 0===m?1:m,w=v.y,S=void 0===w?1:w;if(!this.initialized){this.canvasSize=this.canvasSize?this.canvasSize:new s.Vector2(r,a);var T=this.canvasSize,b=T.x,O=T.y;this.item.transform.size.set(y*b*n*n,S*O*n*n),this.size=this.item.transform.size.clone(),this.initialized=!0}l(this.canvasSize);var A=this.canvasSize,H=A.x,M=A.y;o.width=H/h.fontScale,o.height=M/h.fontScale,this.renderToTexture(H,M,t,(function(t){if(0!==x.length){var n=o.getOffsetY(h,x.length,p*e.singleLineHeight,h.fontSize);x.forEach((function(e,r){var a=e.richOptions,s=e.offsetX,l=e.width,f=l,u=s;if(c===i.TextOverflow.display&&l>H){var g=H/l;f*=g,u=s.map((function(t){return t*g}))}var x=o.getOffsetX(h,f);r>0&&(n+=e.lineHeight-e.offsetY),a.forEach((function(e,r){var a=h.fontScale,o=h.textColor,s=h.fontFamily,f=h.textWeight,g=h.fontStyle,p=e.text,d=e.fontSize,v=e.fontColor,m=void 0===v?o:v,y=e.fontFamily,w=void 0===y?s:y,S=e.fontWeight,T=void 0===S?f:S,b=e.fontStyle,O=void 0===b?g:b,A=d;c===i.TextOverflow.display&&l>H&&(A/=l/H);var M=u[r]+x;t.font=O+" "+T+" "+A*a+"px "+w;var z=m[0],L=m[1],E=m[2],W=m[3];t.fillStyle="rgba("+z+", "+L+", "+E+", "+W+")",t.fillText(p,M,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.updateStrategies(),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.textStyle.fontScale;n.autoResize===i.TextSizeMode.autoWidth&&(n.maxTextWidth=Number.MAX_SAFE_INTEGER);var l,h,c=this.richWrapStrategy.computeLines(this.processedTextOptions,o,this.textStyle,n,a);switch(n.autoResize){case i.TextSizeMode.autoWidth:l=Math.max(1,c.maxLineWidth||0),h=Math.max(1,c.totalHeight||0);break;case i.TextSizeMode.autoHeight:l=n.maxTextWidth,h=Math.max(1,c.totalHeight||0);break;case i.TextSizeMode.fixed:default:l=n.maxTextWidth,h=n.maxTextHeight}if(n.overflow===i.TextOverflow.display){var f=Math.max(1,c.maxLineWidth||0),u=Math.max(1,c.totalHeight||0);!function(t,e,i,n,r){var a=function(t,e){return Math.abs(e)>1e-5?t/e:1},o=Math.max(1,e),s=Math.max(1,i),l=Math.min(1,a(n,o),a(r,s));if(!(l>.9999))for(var h,c=T(t);!(h=c()).done;){var f=h.value;if(f.width*=l,f.lineHeight*=l,f.offsetX)for(var u=0;u<f.offsetX.length;u++)f.offsetX[u]*=l;for(var g,x=T(f.chars||[]);!(g=x()).done;)for(var p,d=T(g.value);!(p=d()).done;)p.value.x*=l;for(var v=f.richOptions||[],m=[],y=0;y<v.length;y++)m.push(P({},v[y],{fontSize:v[y].fontSize*l}));f.richOptions=m,null!=f.lineAscent&&(f.lineAscent*=l),null!=f.lineDescent&&(f.lineDescent*=l)}}(c.lines,f,u,l,h)}var g=this.richHorizontalAlignStrategy.getHorizontalOffsets(c.lines,l,n,this.textStyle),x=this.richVerticalAlignStrategy.getVerticalOffsets(c.lines,h,n),p=this.richOverflowStrategy.resolveCanvas(c.lines,l,h,g,x),d=Math.max(1,Math.ceil(p.canvasWidth*s)),v=Math.max(1,Math.ceil(p.canvasHeight*s));this.item.transform.size.set(p.canvasWidth*this.SCALE_FACTOR*this.SCALE_FACTOR,p.canvasHeight*this.SCALE_FACTOR*this.SCALE_FACTOR),n.maxTextWidth=l,n.maxTextHeight=h,n.width=p.canvasWidth,n.height=p.canvasHeight,this.renderToTexture(d,v,t,(function(t){t.scale(s,s),e.drawTextWithStrategies(t,c.lines,g,x,p,e.textStyle)}),{disposeOld:!1}),this.isDirty=!1}}},n.drawTextWithStrategies=function(t,e,i,n,r,a){var o=r.renderOffsetX,s=r.renderOffsetY,l=n.baselineY+s,h=i.lineOffsets;e.forEach((function(i,n){var r=i.richOptions,s=i.chars,c=h[n]+o,f=l;r.forEach((function(e,n){var r=a.textColor,o=a.fontFamily,l=a.textWeight,h=a.fontStyle,u=e.fontSize,g=e.fontColor,x=void 0===g?r:g,p=e.fontFamily,d=void 0===p?o:p,v=e.fontWeight,m=void 0===v?l:v,y=e.fontStyle,w=void 0===y?h:y,S=u;t.font=w+" "+m+" "+S+"px "+d;var T=x[0],b=x[1],O=x[2],A=x[3];t.fillStyle="rgba("+T+", "+b+", "+O+", "+A+")";var H=i.offsetX&&i.offsetX[n]?i.offsetX[n]:0;s[n].forEach((function(e){t.fillText(e.char,c+H+e.x,f)}))})),n<e.length-1&&(l+=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 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}([n(i.DataType.RichTextComponent)],j),[a]);var I="2.9.1";c("rich-text",w),f.info("Plugin rich text version: 2.9.1."),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,w as RichTextLoader,E as escape,z as generateProgram,L as isRichText,H as lexer,M 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 s,assertExist as l,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 d(t,e,i){return d=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},d.apply(null,arguments)}function v(t){return v=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},v(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 d(t,arguments,v(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,w=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 S(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 S(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)?S(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]+)(=([^>]+))?>$/,O=/^<\/([a-z]+)>$/,A=[["EscapedChar",/^\\([=<>\\/])/],["ContextStart",/^<[a-z]+(=[^>]+)?>/],["ContextEnd",/^<\/[a-z]+>/],["Text",/^[^</>=\\]+/]],H=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 H(t.slice(2),e.concat({tokenType:"Text",value:r}),i+2)}for(var a,o=T(A);!(a=o()).done;){var s=a.value,l=s[0],h=s[1];if("EscapedChar"!==l){var c=h.exec(t);if(c){var f=c[0],u=f.length;return H(t.slice(u),e.concat({tokenType:l,value:f}),i+u)}}}if(t.length>0)return H(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(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=s();if("ContextEnd"===(null==t?void 0:t.tokenType)){o();var e=t.value.match(O);if(e)return{attributeName:e[1]};throw new Error("Expect an end tag marker at position "+a)}return{}},r=H(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 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)}}}(),l};function z(t){return function(e){for(var i,n=T(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 L(t){var e=H(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(O)[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 C=function(){function t(t){this.width=0,this.height=0;var e=t.textOverflow,n=void 0===e?i.TextOverflow.clip:e,r=t.textVerticalAlign,a=void 0===r?i.TextVerticalAlign.middle:r,o=t.textAlign,s=void 0===o?i.TextAlignment.left:o,l=t.letterSpace,h=void 0===l?0:l,c=t.lineHeight,f=void 0===c?.571:c,u=t.wrapEnabled,g=void 0!==u&&u,x=t.maxTextWidth,p=void 0===x?350:x,d=t.maxTextHeight,v=void 0===d?1e3:d,m=t.autoResize,y=void 0===m?i.TextSizeMode.autoWidth:m,w=t.useLegacyRichText,S=void 0!==w&&w;this.letterSpace=h,this.lineHeight=f,this.useLegacyRichText=S,this.overflow=n,this.textVerticalAlign=a,this.textAlign=s,this.width=100,this.height=100,this.wrapEnabled=g,this.maxTextWidth=p,this.maxTextHeight=v,this.autoResize=y}var e=t.prototype;return e.getOffsetY=function(t,e,n,r,a){var o=t.outlineWidth,s=t.fontScale,l=(n-r)/3,h=r+o*s,c=void 0!==a?a:n*(e-1),f=0;switch(this.textVerticalAlign){case i.TextVerticalAlign.top:f=h+l;break;case i.TextVerticalAlign.middle:f=(this.height*s-c+h)/2;break;case i.TextVerticalAlign.bottom:f=this.height*s-c-l}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),s=(e[0]-n)/3,l=n+r*a,h=o-e[0],c=0;switch(this.textVerticalAlign){case i.TextVerticalAlign.top:c=l+s;break;case i.TextVerticalAlign.middle:c=(this.height*a-o)/2+l;break;case i.TextVerticalAlign.bottom:c=this.height*a-h-s}return c},e.getOffsetXRich=function(t,e,n){switch(this.textAlign){case i.TextAlignment.left:return t.outlineWidth;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 k(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 R(t,e){if(void 0===e&&(e=1),"string"!=typeof t||!t)throw new Error("Invalid color string");return t.startsWith("#")?k(t,e):k(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 V=function(){function t(){}var e=t.prototype;return e.computeLines=function(t,e,i,n,r){var a=this,o=[],s=[],l=n.lineHeight||0,h=this.createNewLine(),c=0,f=0,u=function(){if(0!==h.chars.length){h.lineHeight=l;var t=0===o.length?0:s[s.length-1]+l;s.push(t),f+=h.lineHeight,o.push(h),c=Math.max(c,h.width),h=a.createNewLine()}};t.forEach((function(t){var n=t.text,a=t.isNewLine,o=t.fontSize;a&&u();var s=t.fontStyle||i.fontStyle||"normal";e.font=s+" "+(t.fontWeight||i.textWeight)+" 10px "+(t.fontFamily||i.fontFamily),h.offsetX.push(h.width);for(var l=.1*o,c=e.measureText("x"),f=c.fontBoundingBoxAscent*l,g=c.fontBoundingBoxDescent*l,x=0,p=[],d=0;d<n.length;d++){var v=n[d],m=e.measureText(v).width,y=(m<=0?0:m)*l;d>0&&(x+=r),p.push({char:v,x:x}),x+=y}h.chars.push(p),h.width+=x,h.richOptions.push(t),h.lineAscent=Math.max(h.lineAscent||0,f),h.lineDescent=Math.max(h.lineDescent||0,g)})),u();var g=1/0,x=-1/0;if(0===o.length)return{lines:o,maxLineWidth:c,totalHeight:f,bboxTop:0,bboxBottom:0,bboxHeight:0};for(var p=0;p<o.length;p++){var d=o[p].lineAscent||0,v=o[p].lineDescent||0,m=(l-(d+v))/2;g=Math.min(g,s[p]-d-m),x=Math.max(x,s[p]+v+m)}return{lines:o,maxLineWidth:c,totalHeight:f,bboxTop:g,bboxBottom:x,bboxHeight:x-g}},e.createNewLine=function(){return{richOptions:[],offsetX:[],width:0,lineHeight:0,offsetY:0,chars:[],lineAscent:0,lineDescent:0}},t}(),D=function(){function t(){}var e=t.prototype;return e.computeLines=function(t,e,i,n,r){var a=this,o=[],s=[],l=n.lineHeight||0,h=n.maxTextWidth||1/0,c=this.createNewLine(),f=0,u=0,g=null,x=0,p=[],d=null,v=function(){if(m(),0!==c.chars.length){c.lineHeight=l;var t=0===o.length?0:s[s.length-1]+l;s.push(t),u+=c.lineHeight,o.push(c),f=Math.max(f,c.width),c=a.createNewLine(),g=null,x=0,p=[],d=null}},m=function(){0!==p.length&&(null===g&&(g=c.width),c.offsetX.push(g),c.chars.push(p),d&&c.richOptions.push(d),g=null,x=0,p=[],d=null)};t.forEach((function(t){var n=t.text,a=t.isNewLine,o=t.fontSize,s=t.fontStyle||i.fontStyle||"normal";e.font=s+" "+(t.fontWeight||i.textWeight)+" 10px "+(t.fontFamily||i.fontFamily),a&&(m(),v());for(var l=.1*o,f=e.measureText("x"),u=f.fontBoundingBoxAscent*l,y=f.fontBoundingBoxDescent*l,w=0;w<n.length;w++){var S=n[w],T=e.measureText(S).width,b=(T<=0?0:T)*l,O=p.length>0?r:0;c.width+O+b>h&&(m(),v()),null===g&&(g=c.width,d=t),p.length>0&&(x+=r,c.width+=r),p.push({char:S,x:x}),c.lineAscent=Math.max(c.lineAscent||0,u),c.lineDescent=Math.max(c.lineDescent||0,y),x+=b,c.width+=b}m()})),v();var y=1/0,w=-1/0;if(0===o.length)return{lines:o,maxLineWidth:f,totalHeight:u,bboxTop:0,bboxBottom:0,bboxHeight:0};for(var S=0;S<o.length;S++){var T=o[S].lineAscent||0,b=o[S].lineDescent||0,O=(l-(T+b))/2;y=Math.min(y,s[S]-T-O),w=Math.max(w,s[S]+b+O)}return{lines:o,maxLineWidth:f,totalHeight:u,bboxTop:y,bboxBottom:w,bboxHeight:w-y}},e.createNewLine=function(){return{richOptions:[],offsetX:[],width:0,lineHeight:0,offsetY:0,chars:[],lineAscent:0,lineDescent:0}},t}(),B=function(){function t(){}return t.prototype.resolveCanvas=function(t,e,i,n,r){return{canvasWidth:Math.max(1,Math.ceil(e)),canvasHeight:Math.max(1,Math.ceil(i)),renderOffsetX:0,renderOffsetY:0}},t}(),X=function(){function t(){}return t.prototype.resolveCanvas=function(t,e,i,n,r){if(0===t.length)return{canvasWidth:Math.max(1,e),canvasHeight:Math.max(1,i),renderOffsetX:0,renderOffsetY:0};for(var a=1/0,o=-1/0,s=r.baselineY,l=0;l<t.length;l++){var h,c,f=null!=(h=t[l].lineAscent)?h:0,u=null!=(c=t[l].lineDescent)?c:0,g=f+u,x=Math.max(0,(t[l].lineHeight-g)/2);a=Math.min(a,s-f-x),o=Math.max(o,s+u+x),l<t.length-1&&(s+=t[l+1].lineHeight)}for(var p=Math.max(0,-a),d=Math.max(0,o-i),v=Math.max(p,d),m=1/0,y=-1/0,w=0;w<t.length;w++){var S,T,b=null!=(S=n.lineOffsets[w])?S:0,O=null!=(T=t[w].width)?T:0;m=Math.min(m,b),y=Math.max(y,b+O)}isFinite(m)||(m=0),isFinite(y)||(y=0);var A=Math.max(0,-m),H=Math.max(0,y-e),M=Math.max(A,H),z=Math.ceil(e+2*M),L=Math.ceil(i+2*v);return{canvasWidth:Math.max(1,z),canvasHeight:Math.max(1,L),renderOffsetX:M,renderOffsetY:v}},t}(),F=function(){function t(){}return t.prototype.getHorizontalOffsets=function(t,e,i,n){return{lineOffsets:t.map((function(t){return i.getOffsetXRich(n,e,t.width)}))}},t}(),Y=function(){function t(){}return t.prototype.getVerticalOffsets=function(t,e,n){if(0===t.length)return{baselineY:0,lineYOffsets:[]};for(var r=[0],a=1;a<t.length;a++)r[a]=r[a-1]+t[a].lineHeight;for(var o=1/0,s=-1/0,l=0;l<t.length;l++){var h,c,f=null!=(h=t[l].lineAscent)?h:0,u=null!=(c=t[l].lineDescent)?c:0,g=f+u,x=(t[l].lineHeight-g)/2;o=Math.min(o,r[l]-f-x),s=Math.max(s,r[l]+u+x)}var p=s-o,d=0;switch(n.textVerticalAlign){case i.TextVerticalAlign.top:d=-o;break;case i.TextVerticalAlign.middle:d=(e-p)/2-o;break;case i.TextVerticalAlign.bottom:d=e-p-o}var v=r.map((function(t){return d+t}));return{baselineY:d,lineYOffsets:v}},t}(),N=function(){function t(){}return t.createWrapStrategy=function(t){return t?new D:new V},t.createOverflowStrategy=function(t){switch(t){case i.TextOverflow.clip:return new B;case i.TextOverflow.display:case i.TextOverflow.visible:default:return new X}},t.createHorizontalAlignStrategy=function(){return new F},t.createVerticalAlignStrategy=function(){return new Y},t}();function P(){return P=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var i=arguments[e];for(var n in i)Object.prototype.hasOwnProperty.call(i,n)&&(t[n]=i[n])}return t},P.apply(this,arguments)}var _=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=.11092565,n.ALPHA_FIX_VALUE=1/255,n.name="MRichText"+_++,n.initTextBase(e),n.richWrapStrategy=N.createWrapStrategy(),n.richOverflowStrategy=N.createOverflowStrategy(i.TextOverflow.display),n.richHorizontalAlignStrategy=N.createHorizontalAlignStrategy(),n.richVerticalAlignStrategy=N.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 C(r),this.text=r.text?r.text.toString():" ",this.textLayout.useLegacyRichText&&(this.textLayout.textVerticalAlign=i.TextVerticalAlign.middle),this.updateStrategies(),this.updateTexture(),this.material.setColor("_Color",new s.Color(1,1,1,1))},n.updateStrategies=function(){var t=this.textLayout;t&&(this.richWrapStrategy=N.createWrapStrategy(t.wrapEnabled),this.richOverflowStrategy=N.createOverflowStrategy(t.overflow))},n.generateTextProgram=function(t){var e=this;this.processedTextOptions=[];var n=z((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=R(n.color)),e.processedTextOptions.push(a)}))}));n(t)},n.updateWithOptions=function(t){this.textStyle=new o(t),this.textLayout=new C(t),this.text=t.text?t.text.toString():" ",this.textLayout.useLegacyRichText&&(this.textLayout.textVerticalAlign=i.TextVerticalAlign.middle),this.updateStrategies(),this.isDirty=!0},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){var n=.1;this.generateTextProgram(this.text);var r=0,a=0,o=this.textLayout,h=this.textStyle,c=o.overflow,f=o.letterSpace,u=void 0===f?0:f,g=this.context,x=[],p=h.fontSize*h.fontScale,d={richOptions:[],offsetX:[],width:0,lineHeight:p*this.singleLineHeight,offsetY:p*(this.singleLineHeight-1)/2};if(this.processedTextOptions.forEach((function(t){var i=t.text,o=t.isNewLine,s=t.fontSize;o&&(x.push(d),r=Math.max(r,d.width),d={richOptions:[],offsetX:[],width:0,lineHeight:p*e.singleLineHeight,offsetY:p*(e.singleLineHeight-1)/2},a+=d.lineHeight),g.font=(t.fontWeight||h.textWeight)+" 10px "+(t.fontFamily||h.fontFamily);var l=g.measureText(i),c=l.width;if(void 0!==l.actualBoundingBoxLeft&&void 0!==l.actualBoundingBoxRight){var f=l.actualBoundingBoxLeft+l.actualBoundingBoxRight;f>0&&(c=Math.max(c,f))}var v=s*e.singleLineHeight*h.fontScale;v>d.lineHeight&&(a+=v-d.lineHeight,d.lineHeight=v,d.offsetY=s*h.fontScale*(e.singleLineHeight-1)/2),d.offsetX.push(d.width),d.width+=(c<=0?0:c)*s*n*h.fontScale+i.length*u,d.richOptions.push(t)})),x.push(d),r=Math.max(r,d.width),a+=d.lineHeight,0!==r&&0!==a){void 0!==this.size&&null!==this.size||(this.size=this.item.transform.size.clone());var v=this.size,m=v.x,y=void 0===m?1:m,w=v.y,S=void 0===w?1:w;if(!this.initialized){this.canvasSize=this.canvasSize?this.canvasSize:new s.Vector2(r,a);var T=this.canvasSize,b=T.x,O=T.y;this.item.transform.size.set(y*b*n*n,S*O*n*n),this.size=this.item.transform.size.clone(),this.initialized=!0}l(this.canvasSize);var A=this.canvasSize,H=A.x,M=A.y;o.width=H/h.fontScale,o.height=M/h.fontScale,this.renderToTexture(H,M,t,(function(t){if(0!==x.length){var n=o.getOffsetY(h,x.length,p*e.singleLineHeight,h.fontSize);x.forEach((function(e,r){var a=e.richOptions,s=e.offsetX,l=e.width,f=l,u=s;if(c===i.TextOverflow.display&&l>H){var g=H/l;f*=g,u=s.map((function(t){return t*g}))}var x=o.getOffsetX(h,f);r>0&&(n+=e.lineHeight-e.offsetY),a.forEach((function(e,r){var a=h.fontScale,o=h.textColor,s=h.fontFamily,f=h.textWeight,g=h.fontStyle,p=e.text,d=e.fontSize,v=e.fontColor,m=void 0===v?o:v,y=e.fontFamily,w=void 0===y?s:y,S=e.fontWeight,T=void 0===S?f:S,b=e.fontStyle,O=void 0===b?g:b,A=d;c===i.TextOverflow.display&&l>H&&(A/=l/H);var M=u[r]+x;t.font=O+" "+T+" "+A*a+"px "+w;var z=m[0],L=m[1],E=m[2],W=m[3];t.fillStyle="rgba("+z+", "+L+", "+E+", "+W+")",t.fillText(p,M,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.updateStrategies(),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.textStyle.fontScale;n.autoResize===i.TextSizeMode.autoWidth&&(n.maxTextWidth=Number.MAX_SAFE_INTEGER);var l,h,c=this.richWrapStrategy.computeLines(this.processedTextOptions,o,this.textStyle,n,a);switch(n.autoResize){case i.TextSizeMode.autoWidth:l=Math.max(1,c.maxLineWidth||0),h=Math.max(1,c.totalHeight||0);break;case i.TextSizeMode.autoHeight:l=n.maxTextWidth,h=Math.max(1,c.totalHeight||0);break;case i.TextSizeMode.fixed:default:l=n.maxTextWidth,h=n.maxTextHeight}if(n.overflow===i.TextOverflow.display){var f=Math.max(1,c.maxLineWidth||0),u=Math.max(1,c.totalHeight||0);!function(t,e,i,n,r){var a=function(t,e){return Math.abs(e)>1e-5?t/e:1},o=Math.max(1,e),s=Math.max(1,i),l=Math.min(1,a(n,o),a(r,s));if(!(l>.9999))for(var h,c=T(t);!(h=c()).done;){var f=h.value;if(f.width*=l,f.lineHeight*=l,f.offsetX)for(var u=0;u<f.offsetX.length;u++)f.offsetX[u]*=l;for(var g,x=T(f.chars||[]);!(g=x()).done;)for(var p,d=T(g.value);!(p=d()).done;)p.value.x*=l;for(var v=f.richOptions||[],m=[],y=0;y<v.length;y++)m.push(P({},v[y],{fontSize:v[y].fontSize*l}));f.richOptions=m,null!=f.lineAscent&&(f.lineAscent*=l),null!=f.lineDescent&&(f.lineDescent*=l)}}(c.lines,f,u,l,h)}var g=this.richHorizontalAlignStrategy.getHorizontalOffsets(c.lines,l,n,this.textStyle),x=this.richVerticalAlignStrategy.getVerticalOffsets(c.lines,h,n),p=this.richOverflowStrategy.resolveCanvas(c.lines,l,h,g,x),d=Math.max(1,Math.ceil(p.canvasWidth*s)),v=Math.max(1,Math.ceil(p.canvasHeight*s));this.item.transform.size.set(p.canvasWidth*this.SCALE_FACTOR*this.SCALE_FACTOR,p.canvasHeight*this.SCALE_FACTOR*this.SCALE_FACTOR),n.maxTextWidth=l,n.maxTextHeight=h,n.width=p.canvasWidth,n.height=p.canvasHeight,this.renderToTexture(d,v,t,(function(t){t.scale(s,s),e.drawTextWithStrategies(t,c.lines,g,x,p,e.textStyle)}),{disposeOld:!1}),this.isDirty=!1}}},n.drawTextWithStrategies=function(t,e,i,n,r,a){var o=r.renderOffsetX,s=r.renderOffsetY,l=n.baselineY+s,h=i.lineOffsets;e.forEach((function(i,n){var r=i.richOptions,s=i.chars,c=h[n]+o,f=l;r.forEach((function(e,n){var r=a.textColor,o=a.fontFamily,l=a.textWeight,h=a.fontStyle,u=e.fontSize,g=e.fontColor,x=void 0===g?r:g,p=e.fontFamily,d=void 0===p?o:p,v=e.fontWeight,m=void 0===v?l:v,y=e.fontStyle,w=void 0===y?h:y,S=u;t.font=w+" "+m+" "+S+"px "+d;var T=x[0],b=x[1],O=x[2],A=x[3];t.fillStyle="rgba("+T+", "+b+", "+O+", "+A+")";var H=i.offsetX&&i.offsetX[n]?i.offsetX[n]:0;s[n].forEach((function(e){t.fillText(e.char,c+H+e.x,f)}))})),n<e.length-1&&(l+=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 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}([n(i.DataType.RichTextComponent)],j),[a]);var I="2.9.2";c("rich-text",w),f.info("Plugin rich text version: 2.9.2."),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,w as RichTextLoader,E as escape,z as generateProgram,L as isRichText,H as lexer,M 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]+)>$/,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 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=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});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 w=function(){function e(e){this.width=0,this.height=0;var i=e.textOverflow,n=void 0===i?t.spec.TextOverflow.clip:i,r=e.textVerticalAlign,o=void 0===r?t.spec.TextVerticalAlign.middle:r,a=e.textAlign,s=void 0===a?t.spec.TextAlignment.left:a,l=e.letterSpace,c=void 0===l?0:l,h=e.lineHeight,u=void 0===h?.571:h,f=e.wrapEnabled,p=void 0!==f&&f,x=e.maxTextWidth,g=void 0===x?350:x,d=e.maxTextHeight,v=void 0===d?1e3:d,m=e.autoResize,y=void 0===m?t.spec.TextSizeMode.autoWidth:m,w=e.useLegacyRichText,T=void 0!==w&&w;this.letterSpace=c,this.lineHeight=u,this.useLegacyRichText=T,this.overflow=n,this.textVerticalAlign=o,this.textAlign=s,this.width=100,this.height=100,this.wrapEnabled=p,this.maxTextWidth=g,this.maxTextHeight=v,this.autoResize=y}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;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 S(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){var o=this,a=[],s=[],l=n.lineHeight||0,c=this.createNewLine(),h=0,u=0,f=function(){if(0!==c.chars.length){c.lineHeight=l;var t=0===a.length?0:s[s.length-1]+l;s.push(t),u+=c.lineHeight,a.push(c),h=Math.max(h,c.width),c=o.createNewLine()}};t.forEach((function(t){var n=t.text,o=t.isNewLine,a=t.fontSize;o&&f();var s=t.fontStyle||i.fontStyle||"normal";e.font=s+" "+(t.fontWeight||i.textWeight)+" 10px "+(t.fontFamily||i.fontFamily),c.offsetX.push(c.width);for(var l=.1*a,h=e.measureText("x"),u=h.fontBoundingBoxAscent*l,p=h.fontBoundingBoxDescent*l,x=0,g=[],d=0;d<n.length;d++){var v=n[d],m=e.measureText(v).width,y=(m<=0?0:m)*l;d>0&&(x+=r),g.push({char:v,x:x}),x+=y}c.chars.push(g),c.width+=x,c.richOptions.push(t),c.lineAscent=Math.max(c.lineAscent||0,u),c.lineDescent=Math.max(c.lineDescent||0,p)})),f();var p=1/0,x=-1/0;if(0===a.length)return{lines:a,maxLineWidth:h,totalHeight:u,bboxTop:0,bboxBottom:0,bboxHeight:0};for(var g=0;g<a.length;g++){var d=a[g].lineAscent||0,v=a[g].lineDescent||0,m=(l-(d+v))/2;p=Math.min(p,s[g]-d-m),x=Math.max(x,s[g]+v+m)}return{lines:a,maxLineWidth:h,totalHeight:u,bboxTop:p,bboxBottom:x,bboxHeight:x-p}},e.createNewLine=function(){return{richOptions:[],offsetX:[],width:0,lineHeight:0,offsetY:0,chars:[],lineAscent:0,lineDescent:0}},t}(),O=function(){function t(){}var e=t.prototype;return e.computeLines=function(t,e,i,n,r){var o=this,a=[],s=[],l=n.lineHeight||0,c=n.maxTextWidth||1/0,h=this.createNewLine(),u=0,f=0,p=null,x=0,g=[],d=null,v=function(){if(m(),0!==h.chars.length){h.lineHeight=l;var t=0===a.length?0:s[s.length-1]+l;s.push(t),f+=h.lineHeight,a.push(h),u=Math.max(u,h.width),h=o.createNewLine(),p=null,x=0,g=[],d=null}},m=function(){0!==g.length&&(null===p&&(p=h.width),h.offsetX.push(p),h.chars.push(g),d&&h.richOptions.push(d),p=null,x=0,g=[],d=null)};t.forEach((function(t){var n=t.text,o=t.isNewLine,a=t.fontSize,s=t.fontStyle||i.fontStyle||"normal";e.font=s+" "+(t.fontWeight||i.textWeight)+" 10px "+(t.fontFamily||i.fontFamily),o&&(m(),v());for(var l=.1*a,u=e.measureText("x"),f=u.fontBoundingBoxAscent*l,y=u.fontBoundingBoxDescent*l,w=0;w<n.length;w++){var T=n[w],S=e.measureText(T).width,b=(S<=0?0:S)*l,O=g.length>0?r:0;h.width+O+b>c&&(m(),v()),null===p&&(p=h.width,d=t),g.length>0&&(x+=r,h.width+=r),g.push({char:T,x:x}),h.lineAscent=Math.max(h.lineAscent||0,f),h.lineDescent=Math.max(h.lineDescent||0,y),x+=b,h.width+=b}m()})),v();var y=1/0,w=-1/0;if(0===a.length)return{lines:a,maxLineWidth:u,totalHeight:f,bboxTop:0,bboxBottom:0,bboxHeight:0};for(var T=0;T<a.length;T++){var S=a[T].lineAscent||0,b=a[T].lineDescent||0,O=(l-(S+b))/2;y=Math.min(y,s[T]-S-O),w=Math.max(w,s[T]+b+O)}return{lines:a,maxLineWidth:u,totalHeight:f,bboxTop:y,bboxBottom:w,bboxHeight:w-y}},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.resolveCanvas=function(t,e,i,n,r){return{canvasWidth:Math.max(1,Math.ceil(e)),canvasHeight:Math.max(1,Math.ceil(i)),renderOffsetX:0,renderOffsetY:0}},t}(),M=function(){function t(){}return t.prototype.resolveCanvas=function(t,e,i,n,r){if(0===t.length)return{canvasWidth:Math.max(1,e),canvasHeight:Math.max(1,i),renderOffsetX:0,renderOffsetY:0};for(var o=1/0,a=-1/0,s=r.baselineY,l=0;l<t.length;l++){var c,h,u=null!=(c=t[l].lineAscent)?c:0,f=null!=(h=t[l].lineDescent)?h:0,p=u+f,x=Math.max(0,(t[l].lineHeight-p)/2);o=Math.min(o,s-u-x),a=Math.max(a,s+f+x),l<t.length-1&&(s+=t[l+1].lineHeight)}for(var g=Math.max(0,-o),d=Math.max(0,a-i),v=Math.max(g,d),m=1/0,y=-1/0,w=0;w<t.length;w++){var T,S,b=null!=(T=n.lineOffsets[w])?T:0,O=null!=(S=t[w].width)?S:0;m=Math.min(m,b),y=Math.max(y,b+O)}isFinite(m)||(m=0),isFinite(y)||(y=0);var A=Math.max(0,-m),M=Math.max(0,y-e),H=Math.max(A,M),z=Math.ceil(e+2*H),E=Math.ceil(i+2*v);return{canvasWidth:Math.max(1,z),canvasHeight:Math.max(1,E),renderOffsetX:H,renderOffsetY:v}},t}(),H=function(){function t(){}return t.prototype.getHorizontalOffsets=function(t,e,i,n){return{lineOffsets:t.map((function(t){return i.getOffsetXRich(n,e,t.width)}))}},t}(),z=function(){function e(){}return e.prototype.getVerticalOffsets=function(e,i,n){if(0===e.length)return{baselineY:0,lineYOffsets:[]};for(var r=[0],o=1;o<e.length;o++)r[o]=r[o-1]+e[o].lineHeight;for(var a=1/0,s=-1/0,l=0;l<e.length;l++){var c,h,u=null!=(c=e[l].lineAscent)?c:0,f=null!=(h=e[l].lineDescent)?h:0,p=u+f,x=(e[l].lineHeight-p)/2;a=Math.min(a,r[l]-u-x),s=Math.max(s,r[l]+f+x)}var g=s-a,d=0;switch(n.textVerticalAlign){case t.spec.TextVerticalAlign.top:d=-a;break;case t.spec.TextVerticalAlign.middle:d=(i-g)/2-a;break;case t.spec.TextVerticalAlign.bottom:d=i-g-a}var v=r.map((function(t){return d+t}));return{baselineY:d,lineYOffsets:v}},e}(),E=function(){function e(){}return e.createWrapStrategy=function(t){return t?new O:new b},e.createOverflowStrategy=function(e){switch(e){case t.spec.TextOverflow.clip:return new A;case t.spec.TextOverflow.display:case t.spec.TextOverflow.visible:default:return new M}},e.createHorizontalAlignStrategy=function(){return new H},e.createVerticalAlignStrategy=function(){return new z},e}();function L(){return L=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var i=arguments[e];for(var n in i)Object.prototype.hasOwnProperty.call(i,n)&&(t[n]=i[n])}return t},L.apply(this,arguments)}var 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=.11092565,n.ALPHA_FIX_VALUE=1/255,n.name="MRichText"+W++,n.initTextBase(i),n.richWrapStrategy=E.createWrapStrategy(),n.richOverflowStrategy=E.createOverflowStrategy(t.spec.TextOverflow.display),n.richHorizontalAlignStrategy=E.createHorizontalAlignStrategy(),n.richVerticalAlignStrategy=E.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 w(r),this.text=r.text?r.text.toString():" ",this.textLayout.useLegacyRichText&&(this.textLayout.textVerticalAlign=t.spec.TextVerticalAlign.middle),this.updateStrategies(),this.updateTexture(),this.material.setColor("_Color",new t.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(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=S(n.color)),i.processedTextOptions.push(o)}))}));n(e)},n.updateWithOptions=function(e){this.textStyle=new t.TextStyle(e),this.textLayout=new w(e),this.text=e.text?e.text.toString():" ",this.textLayout.useLegacyRichText&&(this.textLayout.textVerticalAlign=t.spec.TextVerticalAlign.middle),this.updateStrategies(),this.isDirty=!0},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){var n=.1;this.generateTextProgram(this.text);var r=0,o=0,a=this.textLayout,s=this.textStyle,l=a.overflow,c=a.letterSpace,h=void 0===c?0:c,u=this.context,f=[],p=s.fontSize*s.fontScale,x={richOptions:[],offsetX:[],width:0,lineHeight:p*this.singleLineHeight,offsetY:p*(this.singleLineHeight-1)/2};if(this.processedTextOptions.forEach((function(t){var e=t.text,a=t.isNewLine,l=t.fontSize;a&&(f.push(x),r=Math.max(r,x.width),x={richOptions:[],offsetX:[],width:0,lineHeight:p*i.singleLineHeight,offsetY:p*(i.singleLineHeight-1)/2},o+=x.lineHeight),u.font=(t.fontWeight||s.textWeight)+" 10px "+(t.fontFamily||s.fontFamily);var c=u.measureText(e),g=c.width;if(void 0!==c.actualBoundingBoxLeft&&void 0!==c.actualBoundingBoxRight){var d=c.actualBoundingBoxLeft+c.actualBoundingBoxRight;d>0&&(g=Math.max(g,d))}var v=l*i.singleLineHeight*s.fontScale;v>x.lineHeight&&(o+=v-x.lineHeight,x.lineHeight=v,x.offsetY=l*s.fontScale*(i.singleLineHeight-1)/2),x.offsetX.push(x.width),x.width+=(g<=0?0:g)*l*n*s.fontScale+e.length*h,x.richOptions.push(t)})),f.push(x),r=Math.max(r,x.width),o+=x.lineHeight,0!==r&&0!==o){void 0!==this.size&&null!==this.size||(this.size=this.item.transform.size.clone());var g=this.size,d=g.x,v=void 0===d?1:d,m=g.y,y=void 0===m?1:m;if(!this.initialized){this.canvasSize=this.canvasSize?this.canvasSize:new t.math.Vector2(r,o);var w=this.canvasSize,T=w.x,S=w.y;this.item.transform.size.set(v*T*n*n,y*S*n*n),this.size=this.item.transform.size.clone(),this.initialized=!0}t.assertExist(this.canvasSize);var b=this.canvasSize,O=b.x,A=b.y;a.width=O/s.fontScale,a.height=A/s.fontScale,this.renderToTexture(O,A,e,(function(e){if(0!==f.length){var n=a.getOffsetY(s,f.length,p*i.singleLineHeight,s.fontSize);f.forEach((function(i,r){var o=i.richOptions,c=i.offsetX,h=i.width,u=h,f=c;if(l===t.spec.TextOverflow.display&&h>O){var p=O/h;u*=p,f=c.map((function(t){return t*p}))}var x=a.getOffsetX(s,u);r>0&&(n+=i.lineHeight-i.offsetY),o.forEach((function(i,r){var o=s.fontScale,a=s.textColor,c=s.fontFamily,u=s.textWeight,p=s.fontStyle,g=i.text,d=i.fontSize,v=i.fontColor,m=void 0===v?a:v,y=i.fontFamily,w=void 0===y?c:y,T=i.fontWeight,S=void 0===T?u:T,b=i.fontStyle,A=void 0===b?p:b,M=d;l===t.spec.TextOverflow.display&&h>O&&(M/=h/O);var H=f[r]+x;e.font=A+" "+S+" "+M*o+"px "+w;var z=m[0],E=m[1],L=m[2],W=m[3];e.fillStyle="rgba("+z+", "+E+", "+L+", "+W+")",e.fillText(g,H,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.updateStrategies(),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.textStyle.fontScale;n.autoResize===t.spec.TextSizeMode.autoWidth&&(n.maxTextWidth=Number.MAX_SAFE_INTEGER);var l,c,h=this.richWrapStrategy.computeLines(this.processedTextOptions,a,this.textStyle,n,o);switch(n.autoResize){case t.spec.TextSizeMode.autoWidth:l=Math.max(1,h.maxLineWidth||0),c=Math.max(1,h.totalHeight||0);break;case t.spec.TextSizeMode.autoHeight:l=n.maxTextWidth,c=Math.max(1,h.totalHeight||0);break;case t.spec.TextSizeMode.fixed:default:l=n.maxTextWidth,c=n.maxTextHeight}if(n.overflow===t.spec.TextOverflow.display){var u=Math.max(1,h.maxLineWidth||0),f=Math.max(1,h.totalHeight||0);!function(t,e,i,n,r){var o=function(t,e){return Math.abs(e)>1e-5?t/e:1},a=Math.max(1,e),s=Math.max(1,i),l=Math.min(1,o(n,a),o(r,s));if(!(l>.9999))for(var c,h=p(t);!(c=h()).done;){var u=c.value;if(u.width*=l,u.lineHeight*=l,u.offsetX)for(var f=0;f<u.offsetX.length;f++)u.offsetX[f]*=l;for(var x,g=p(u.chars||[]);!(x=g()).done;)for(var d,v=p(x.value);!(d=v()).done;)d.value.x*=l;for(var m=u.richOptions||[],y=[],w=0;w<m.length;w++)y.push(L({},m[w],{fontSize:m[w].fontSize*l}));u.richOptions=y,null!=u.lineAscent&&(u.lineAscent*=l),null!=u.lineDescent&&(u.lineDescent*=l)}}(h.lines,u,f,l,c)}var x=this.richHorizontalAlignStrategy.getHorizontalOffsets(h.lines,l,n,this.textStyle),g=this.richVerticalAlignStrategy.getVerticalOffsets(h.lines,c,n),d=this.richOverflowStrategy.resolveCanvas(h.lines,l,c,x,g),v=Math.max(1,Math.ceil(d.canvasWidth*s)),m=Math.max(1,Math.ceil(d.canvasHeight*s));this.item.transform.size.set(d.canvasWidth*this.SCALE_FACTOR*this.SCALE_FACTOR,d.canvasHeight*this.SCALE_FACTOR*this.SCALE_FACTOR),n.maxTextWidth=l,n.maxTextHeight=c,n.width=d.canvasWidth,n.height=d.canvasHeight,this.renderToTexture(v,m,e,(function(t){t.scale(s,s),i.drawTextWithStrategies(t,h.lines,x,g,d,i.textStyle)}),{disposeOld:!1}),this.isDirty=!1}}},n.drawTextWithStrategies=function(t,e,i,n,r,o){var a=r.renderOffsetX,s=r.renderOffsetY,l=n.baselineY+s,c=i.lineOffsets;e.forEach((function(i,n){var r=i.richOptions,s=i.chars,h=c[n]+a,u=l;r.forEach((function(e,n){var r=o.textColor,a=o.fontFamily,l=o.textWeight,c=o.fontStyle,f=e.fontSize,p=e.fontColor,x=void 0===p?r:p,g=e.fontFamily,d=void 0===g?a:g,v=e.fontWeight,m=void 0===v?l:v,y=e.fontStyle,w=void 0===y?c:y,T=f;t.font=w+" "+m+" "+T+"px "+d;var S=x[0],b=x[1],O=x[2],A=x[3];t.fillStyle="rgba("+S+", "+b+", "+O+", "+A+")";var M=i.offsetX&&i.offsetX[n]?i.offsetX[n]:0;s[n].forEach((function(e){t.fillText(e.char,h+M+e.x,u)}))})),n<e.length-1&&(l+=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 C="2.9.1";t.registerPlugin("rich-text",u),t.logger.info("Plugin rich text version: 2.9.1."),C!==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=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 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=v,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=C;
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]+)>$/,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 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=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});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 w=function(){function e(e){this.width=0,this.height=0;var i=e.textOverflow,n=void 0===i?t.spec.TextOverflow.clip:i,r=e.textVerticalAlign,o=void 0===r?t.spec.TextVerticalAlign.middle:r,a=e.textAlign,s=void 0===a?t.spec.TextAlignment.left:a,l=e.letterSpace,c=void 0===l?0:l,h=e.lineHeight,u=void 0===h?.571:h,f=e.wrapEnabled,p=void 0!==f&&f,x=e.maxTextWidth,g=void 0===x?350:x,d=e.maxTextHeight,v=void 0===d?1e3:d,m=e.autoResize,y=void 0===m?t.spec.TextSizeMode.autoWidth:m,w=e.useLegacyRichText,T=void 0!==w&&w;this.letterSpace=c,this.lineHeight=u,this.useLegacyRichText=T,this.overflow=n,this.textVerticalAlign=o,this.textAlign=s,this.width=100,this.height=100,this.wrapEnabled=p,this.maxTextWidth=g,this.maxTextHeight=v,this.autoResize=y}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;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 S(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){var o=this,a=[],s=[],l=n.lineHeight||0,c=this.createNewLine(),h=0,u=0,f=function(){if(0!==c.chars.length){c.lineHeight=l;var t=0===a.length?0:s[s.length-1]+l;s.push(t),u+=c.lineHeight,a.push(c),h=Math.max(h,c.width),c=o.createNewLine()}};t.forEach((function(t){var n=t.text,o=t.isNewLine,a=t.fontSize;o&&f();var s=t.fontStyle||i.fontStyle||"normal";e.font=s+" "+(t.fontWeight||i.textWeight)+" 10px "+(t.fontFamily||i.fontFamily),c.offsetX.push(c.width);for(var l=.1*a,h=e.measureText("x"),u=h.fontBoundingBoxAscent*l,p=h.fontBoundingBoxDescent*l,x=0,g=[],d=0;d<n.length;d++){var v=n[d],m=e.measureText(v).width,y=(m<=0?0:m)*l;d>0&&(x+=r),g.push({char:v,x:x}),x+=y}c.chars.push(g),c.width+=x,c.richOptions.push(t),c.lineAscent=Math.max(c.lineAscent||0,u),c.lineDescent=Math.max(c.lineDescent||0,p)})),f();var p=1/0,x=-1/0;if(0===a.length)return{lines:a,maxLineWidth:h,totalHeight:u,bboxTop:0,bboxBottom:0,bboxHeight:0};for(var g=0;g<a.length;g++){var d=a[g].lineAscent||0,v=a[g].lineDescent||0,m=(l-(d+v))/2;p=Math.min(p,s[g]-d-m),x=Math.max(x,s[g]+v+m)}return{lines:a,maxLineWidth:h,totalHeight:u,bboxTop:p,bboxBottom:x,bboxHeight:x-p}},e.createNewLine=function(){return{richOptions:[],offsetX:[],width:0,lineHeight:0,offsetY:0,chars:[],lineAscent:0,lineDescent:0}},t}(),O=function(){function t(){}var e=t.prototype;return e.computeLines=function(t,e,i,n,r){var o=this,a=[],s=[],l=n.lineHeight||0,c=n.maxTextWidth||1/0,h=this.createNewLine(),u=0,f=0,p=null,x=0,g=[],d=null,v=function(){if(m(),0!==h.chars.length){h.lineHeight=l;var t=0===a.length?0:s[s.length-1]+l;s.push(t),f+=h.lineHeight,a.push(h),u=Math.max(u,h.width),h=o.createNewLine(),p=null,x=0,g=[],d=null}},m=function(){0!==g.length&&(null===p&&(p=h.width),h.offsetX.push(p),h.chars.push(g),d&&h.richOptions.push(d),p=null,x=0,g=[],d=null)};t.forEach((function(t){var n=t.text,o=t.isNewLine,a=t.fontSize,s=t.fontStyle||i.fontStyle||"normal";e.font=s+" "+(t.fontWeight||i.textWeight)+" 10px "+(t.fontFamily||i.fontFamily),o&&(m(),v());for(var l=.1*a,u=e.measureText("x"),f=u.fontBoundingBoxAscent*l,y=u.fontBoundingBoxDescent*l,w=0;w<n.length;w++){var T=n[w],S=e.measureText(T).width,b=(S<=0?0:S)*l,O=g.length>0?r:0;h.width+O+b>c&&(m(),v()),null===p&&(p=h.width,d=t),g.length>0&&(x+=r,h.width+=r),g.push({char:T,x:x}),h.lineAscent=Math.max(h.lineAscent||0,f),h.lineDescent=Math.max(h.lineDescent||0,y),x+=b,h.width+=b}m()})),v();var y=1/0,w=-1/0;if(0===a.length)return{lines:a,maxLineWidth:u,totalHeight:f,bboxTop:0,bboxBottom:0,bboxHeight:0};for(var T=0;T<a.length;T++){var S=a[T].lineAscent||0,b=a[T].lineDescent||0,O=(l-(S+b))/2;y=Math.min(y,s[T]-S-O),w=Math.max(w,s[T]+b+O)}return{lines:a,maxLineWidth:u,totalHeight:f,bboxTop:y,bboxBottom:w,bboxHeight:w-y}},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.resolveCanvas=function(t,e,i,n,r){return{canvasWidth:Math.max(1,Math.ceil(e)),canvasHeight:Math.max(1,Math.ceil(i)),renderOffsetX:0,renderOffsetY:0}},t}(),M=function(){function t(){}return t.prototype.resolveCanvas=function(t,e,i,n,r){if(0===t.length)return{canvasWidth:Math.max(1,e),canvasHeight:Math.max(1,i),renderOffsetX:0,renderOffsetY:0};for(var o=1/0,a=-1/0,s=r.baselineY,l=0;l<t.length;l++){var c,h,u=null!=(c=t[l].lineAscent)?c:0,f=null!=(h=t[l].lineDescent)?h:0,p=u+f,x=Math.max(0,(t[l].lineHeight-p)/2);o=Math.min(o,s-u-x),a=Math.max(a,s+f+x),l<t.length-1&&(s+=t[l+1].lineHeight)}for(var g=Math.max(0,-o),d=Math.max(0,a-i),v=Math.max(g,d),m=1/0,y=-1/0,w=0;w<t.length;w++){var T,S,b=null!=(T=n.lineOffsets[w])?T:0,O=null!=(S=t[w].width)?S:0;m=Math.min(m,b),y=Math.max(y,b+O)}isFinite(m)||(m=0),isFinite(y)||(y=0);var A=Math.max(0,-m),M=Math.max(0,y-e),H=Math.max(A,M),z=Math.ceil(e+2*H),E=Math.ceil(i+2*v);return{canvasWidth:Math.max(1,z),canvasHeight:Math.max(1,E),renderOffsetX:H,renderOffsetY:v}},t}(),H=function(){function t(){}return t.prototype.getHorizontalOffsets=function(t,e,i,n){return{lineOffsets:t.map((function(t){return i.getOffsetXRich(n,e,t.width)}))}},t}(),z=function(){function e(){}return e.prototype.getVerticalOffsets=function(e,i,n){if(0===e.length)return{baselineY:0,lineYOffsets:[]};for(var r=[0],o=1;o<e.length;o++)r[o]=r[o-1]+e[o].lineHeight;for(var a=1/0,s=-1/0,l=0;l<e.length;l++){var c,h,u=null!=(c=e[l].lineAscent)?c:0,f=null!=(h=e[l].lineDescent)?h:0,p=u+f,x=(e[l].lineHeight-p)/2;a=Math.min(a,r[l]-u-x),s=Math.max(s,r[l]+f+x)}var g=s-a,d=0;switch(n.textVerticalAlign){case t.spec.TextVerticalAlign.top:d=-a;break;case t.spec.TextVerticalAlign.middle:d=(i-g)/2-a;break;case t.spec.TextVerticalAlign.bottom:d=i-g-a}var v=r.map((function(t){return d+t}));return{baselineY:d,lineYOffsets:v}},e}(),E=function(){function e(){}return e.createWrapStrategy=function(t){return t?new O:new b},e.createOverflowStrategy=function(e){switch(e){case t.spec.TextOverflow.clip:return new A;case t.spec.TextOverflow.display:case t.spec.TextOverflow.visible:default:return new M}},e.createHorizontalAlignStrategy=function(){return new H},e.createVerticalAlignStrategy=function(){return new z},e}();function L(){return L=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var i=arguments[e];for(var n in i)Object.prototype.hasOwnProperty.call(i,n)&&(t[n]=i[n])}return t},L.apply(this,arguments)}var 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=.11092565,n.ALPHA_FIX_VALUE=1/255,n.name="MRichText"+W++,n.initTextBase(i),n.richWrapStrategy=E.createWrapStrategy(),n.richOverflowStrategy=E.createOverflowStrategy(t.spec.TextOverflow.display),n.richHorizontalAlignStrategy=E.createHorizontalAlignStrategy(),n.richVerticalAlignStrategy=E.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 w(r),this.text=r.text?r.text.toString():" ",this.textLayout.useLegacyRichText&&(this.textLayout.textVerticalAlign=t.spec.TextVerticalAlign.middle),this.updateStrategies(),this.updateTexture(),this.material.setColor("_Color",new t.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(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=S(n.color)),i.processedTextOptions.push(o)}))}));n(e)},n.updateWithOptions=function(e){this.textStyle=new t.TextStyle(e),this.textLayout=new w(e),this.text=e.text?e.text.toString():" ",this.textLayout.useLegacyRichText&&(this.textLayout.textVerticalAlign=t.spec.TextVerticalAlign.middle),this.updateStrategies(),this.isDirty=!0},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){var n=.1;this.generateTextProgram(this.text);var r=0,o=0,a=this.textLayout,s=this.textStyle,l=a.overflow,c=a.letterSpace,h=void 0===c?0:c,u=this.context,f=[],p=s.fontSize*s.fontScale,x={richOptions:[],offsetX:[],width:0,lineHeight:p*this.singleLineHeight,offsetY:p*(this.singleLineHeight-1)/2};if(this.processedTextOptions.forEach((function(t){var e=t.text,a=t.isNewLine,l=t.fontSize;a&&(f.push(x),r=Math.max(r,x.width),x={richOptions:[],offsetX:[],width:0,lineHeight:p*i.singleLineHeight,offsetY:p*(i.singleLineHeight-1)/2},o+=x.lineHeight),u.font=(t.fontWeight||s.textWeight)+" 10px "+(t.fontFamily||s.fontFamily);var c=u.measureText(e),g=c.width;if(void 0!==c.actualBoundingBoxLeft&&void 0!==c.actualBoundingBoxRight){var d=c.actualBoundingBoxLeft+c.actualBoundingBoxRight;d>0&&(g=Math.max(g,d))}var v=l*i.singleLineHeight*s.fontScale;v>x.lineHeight&&(o+=v-x.lineHeight,x.lineHeight=v,x.offsetY=l*s.fontScale*(i.singleLineHeight-1)/2),x.offsetX.push(x.width),x.width+=(g<=0?0:g)*l*n*s.fontScale+e.length*h,x.richOptions.push(t)})),f.push(x),r=Math.max(r,x.width),o+=x.lineHeight,0!==r&&0!==o){void 0!==this.size&&null!==this.size||(this.size=this.item.transform.size.clone());var g=this.size,d=g.x,v=void 0===d?1:d,m=g.y,y=void 0===m?1:m;if(!this.initialized){this.canvasSize=this.canvasSize?this.canvasSize:new t.math.Vector2(r,o);var w=this.canvasSize,T=w.x,S=w.y;this.item.transform.size.set(v*T*n*n,y*S*n*n),this.size=this.item.transform.size.clone(),this.initialized=!0}t.assertExist(this.canvasSize);var b=this.canvasSize,O=b.x,A=b.y;a.width=O/s.fontScale,a.height=A/s.fontScale,this.renderToTexture(O,A,e,(function(e){if(0!==f.length){var n=a.getOffsetY(s,f.length,p*i.singleLineHeight,s.fontSize);f.forEach((function(i,r){var o=i.richOptions,c=i.offsetX,h=i.width,u=h,f=c;if(l===t.spec.TextOverflow.display&&h>O){var p=O/h;u*=p,f=c.map((function(t){return t*p}))}var x=a.getOffsetX(s,u);r>0&&(n+=i.lineHeight-i.offsetY),o.forEach((function(i,r){var o=s.fontScale,a=s.textColor,c=s.fontFamily,u=s.textWeight,p=s.fontStyle,g=i.text,d=i.fontSize,v=i.fontColor,m=void 0===v?a:v,y=i.fontFamily,w=void 0===y?c:y,T=i.fontWeight,S=void 0===T?u:T,b=i.fontStyle,A=void 0===b?p:b,M=d;l===t.spec.TextOverflow.display&&h>O&&(M/=h/O);var H=f[r]+x;e.font=A+" "+S+" "+M*o+"px "+w;var z=m[0],E=m[1],L=m[2],W=m[3];e.fillStyle="rgba("+z+", "+E+", "+L+", "+W+")",e.fillText(g,H,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.updateStrategies(),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.textStyle.fontScale;n.autoResize===t.spec.TextSizeMode.autoWidth&&(n.maxTextWidth=Number.MAX_SAFE_INTEGER);var l,c,h=this.richWrapStrategy.computeLines(this.processedTextOptions,a,this.textStyle,n,o);switch(n.autoResize){case t.spec.TextSizeMode.autoWidth:l=Math.max(1,h.maxLineWidth||0),c=Math.max(1,h.totalHeight||0);break;case t.spec.TextSizeMode.autoHeight:l=n.maxTextWidth,c=Math.max(1,h.totalHeight||0);break;case t.spec.TextSizeMode.fixed:default:l=n.maxTextWidth,c=n.maxTextHeight}if(n.overflow===t.spec.TextOverflow.display){var u=Math.max(1,h.maxLineWidth||0),f=Math.max(1,h.totalHeight||0);!function(t,e,i,n,r){var o=function(t,e){return Math.abs(e)>1e-5?t/e:1},a=Math.max(1,e),s=Math.max(1,i),l=Math.min(1,o(n,a),o(r,s));if(!(l>.9999))for(var c,h=p(t);!(c=h()).done;){var u=c.value;if(u.width*=l,u.lineHeight*=l,u.offsetX)for(var f=0;f<u.offsetX.length;f++)u.offsetX[f]*=l;for(var x,g=p(u.chars||[]);!(x=g()).done;)for(var d,v=p(x.value);!(d=v()).done;)d.value.x*=l;for(var m=u.richOptions||[],y=[],w=0;w<m.length;w++)y.push(L({},m[w],{fontSize:m[w].fontSize*l}));u.richOptions=y,null!=u.lineAscent&&(u.lineAscent*=l),null!=u.lineDescent&&(u.lineDescent*=l)}}(h.lines,u,f,l,c)}var x=this.richHorizontalAlignStrategy.getHorizontalOffsets(h.lines,l,n,this.textStyle),g=this.richVerticalAlignStrategy.getVerticalOffsets(h.lines,c,n),d=this.richOverflowStrategy.resolveCanvas(h.lines,l,c,x,g),v=Math.max(1,Math.ceil(d.canvasWidth*s)),m=Math.max(1,Math.ceil(d.canvasHeight*s));this.item.transform.size.set(d.canvasWidth*this.SCALE_FACTOR*this.SCALE_FACTOR,d.canvasHeight*this.SCALE_FACTOR*this.SCALE_FACTOR),n.maxTextWidth=l,n.maxTextHeight=c,n.width=d.canvasWidth,n.height=d.canvasHeight,this.renderToTexture(v,m,e,(function(t){t.scale(s,s),i.drawTextWithStrategies(t,h.lines,x,g,d,i.textStyle)}),{disposeOld:!1}),this.isDirty=!1}}},n.drawTextWithStrategies=function(t,e,i,n,r,o){var a=r.renderOffsetX,s=r.renderOffsetY,l=n.baselineY+s,c=i.lineOffsets;e.forEach((function(i,n){var r=i.richOptions,s=i.chars,h=c[n]+a,u=l;r.forEach((function(e,n){var r=o.textColor,a=o.fontFamily,l=o.textWeight,c=o.fontStyle,f=e.fontSize,p=e.fontColor,x=void 0===p?r:p,g=e.fontFamily,d=void 0===g?a:g,v=e.fontWeight,m=void 0===v?l:v,y=e.fontStyle,w=void 0===y?c:y,T=f;t.font=w+" "+m+" "+T+"px "+d;var S=x[0],b=x[1],O=x[2],A=x[3];t.fillStyle="rgba("+S+", "+b+", "+O+", "+A+")";var M=i.offsetX&&i.offsetX[n]?i.offsetX[n]:0;s[n].forEach((function(e){t.fillText(e.char,h+M+e.x,u)}))})),n<e.length-1&&(l+=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 C="2.9.2";t.registerPlugin("rich-text",u),t.logger.info("Plugin rich text version: 2.9.2."),C!==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=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 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=v,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=C;
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 s,assertExist as l,MaskableGraphic as h,registerPlugin as c,logger as f}from"@galacean/effects/douyin";import{document as u}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 d(t,e,i){return d=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},d.apply(null,arguments)}function v(t){return v=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},v(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 d(t,arguments,v(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,w=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 S(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 S(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)?S(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]+)(=([^>]+))?>$/,O=/^<\/([a-z]+)>$/,A=[["EscapedChar",/^\\([=<>\\/])/],["ContextStart",/^<[a-z]+(=[^>]+)?>/],["ContextEnd",/^<\/[a-z]+>/],["Text",/^[^</>=\\]+/]],H=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 H(t.slice(2),e.concat({tokenType:"Text",value:r}),i+2)}for(var a,o=T(A);!(a=o()).done;){var s=a.value,l=s[0],h=s[1];if("EscapedChar"!==l){var c=h.exec(t);if(c){var f=c[0],u=f.length;return H(t.slice(u),e.concat({tokenType:l,value:f}),i+u)}}}if(t.length>0)return H(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(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=s();if("ContextEnd"===(null==t?void 0:t.tokenType)){o();var e=t.value.match(O);if(e)return{attributeName:e[1]};throw new Error("Expect an end tag marker at position "+a)}return{}},r=H(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 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)}}}(),l};function z(t){return function(e){for(var i,n=T(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 L(t){var e=H(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(O)[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 C=function(){function t(t){this.width=0,this.height=0;var e=t.textOverflow,n=void 0===e?i.TextOverflow.clip:e,r=t.textVerticalAlign,a=void 0===r?i.TextVerticalAlign.middle:r,o=t.textAlign,s=void 0===o?i.TextAlignment.left:o,l=t.letterSpace,h=void 0===l?0:l,c=t.lineHeight,f=void 0===c?.571:c,u=t.wrapEnabled,g=void 0!==u&&u,x=t.maxTextWidth,p=void 0===x?350:x,d=t.maxTextHeight,v=void 0===d?1e3:d,m=t.autoResize,y=void 0===m?i.TextSizeMode.autoWidth:m,w=t.useLegacyRichText,S=void 0!==w&&w;this.letterSpace=h,this.lineHeight=f,this.useLegacyRichText=S,this.overflow=n,this.textVerticalAlign=a,this.textAlign=s,this.width=100,this.height=100,this.wrapEnabled=g,this.maxTextWidth=p,this.maxTextHeight=v,this.autoResize=y}var e=t.prototype;return e.getOffsetY=function(t,e,n,r,a){var o=t.outlineWidth,s=t.fontScale,l=(n-r)/3,h=r+o*s,c=void 0!==a?a:n*(e-1),f=0;switch(this.textVerticalAlign){case i.TextVerticalAlign.top:f=h+l;break;case i.TextVerticalAlign.middle:f=(this.height*s-c+h)/2;break;case i.TextVerticalAlign.bottom:f=this.height*s-c-l}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),s=(e[0]-n)/3,l=n+r*a,h=o-e[0],c=0;switch(this.textVerticalAlign){case i.TextVerticalAlign.top:c=l+s;break;case i.TextVerticalAlign.middle:c=(this.height*a-o)/2+l;break;case i.TextVerticalAlign.bottom:c=this.height*a-h-s}return c},e.getOffsetXRich=function(t,e,n){switch(this.textAlign){case i.TextAlignment.left:return t.outlineWidth;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 k(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 R(t,e){if(void 0===e&&(e=1),"string"!=typeof t||!t)throw new Error("Invalid color string");return t.startsWith("#")?k(t,e):k(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 V=function(){function t(){}var e=t.prototype;return e.computeLines=function(t,e,i,n,r){var a=this,o=[],s=[],l=n.lineHeight||0,h=this.createNewLine(),c=0,f=0,u=function(){if(0!==h.chars.length){h.lineHeight=l;var t=0===o.length?0:s[s.length-1]+l;s.push(t),f+=h.lineHeight,o.push(h),c=Math.max(c,h.width),h=a.createNewLine()}};t.forEach((function(t){var n=t.text,a=t.isNewLine,o=t.fontSize;a&&u();var s=t.fontStyle||i.fontStyle||"normal";e.font=s+" "+(t.fontWeight||i.textWeight)+" 10px "+(t.fontFamily||i.fontFamily),h.offsetX.push(h.width);for(var l=.1*o,c=e.measureText("x"),f=c.fontBoundingBoxAscent*l,g=c.fontBoundingBoxDescent*l,x=0,p=[],d=0;d<n.length;d++){var v=n[d],m=e.measureText(v).width,y=(m<=0?0:m)*l;d>0&&(x+=r),p.push({char:v,x:x}),x+=y}h.chars.push(p),h.width+=x,h.richOptions.push(t),h.lineAscent=Math.max(h.lineAscent||0,f),h.lineDescent=Math.max(h.lineDescent||0,g)})),u();var g=1/0,x=-1/0;if(0===o.length)return{lines:o,maxLineWidth:c,totalHeight:f,bboxTop:0,bboxBottom:0,bboxHeight:0};for(var p=0;p<o.length;p++){var d=o[p].lineAscent||0,v=o[p].lineDescent||0,m=(l-(d+v))/2;g=Math.min(g,s[p]-d-m),x=Math.max(x,s[p]+v+m)}return{lines:o,maxLineWidth:c,totalHeight:f,bboxTop:g,bboxBottom:x,bboxHeight:x-g}},e.createNewLine=function(){return{richOptions:[],offsetX:[],width:0,lineHeight:0,offsetY:0,chars:[],lineAscent:0,lineDescent:0}},t}(),D=function(){function t(){}var e=t.prototype;return e.computeLines=function(t,e,i,n,r){var a=this,o=[],s=[],l=n.lineHeight||0,h=n.maxTextWidth||1/0,c=this.createNewLine(),f=0,u=0,g=null,x=0,p=[],d=null,v=function(){if(m(),0!==c.chars.length){c.lineHeight=l;var t=0===o.length?0:s[s.length-1]+l;s.push(t),u+=c.lineHeight,o.push(c),f=Math.max(f,c.width),c=a.createNewLine(),g=null,x=0,p=[],d=null}},m=function(){0!==p.length&&(null===g&&(g=c.width),c.offsetX.push(g),c.chars.push(p),d&&c.richOptions.push(d),g=null,x=0,p=[],d=null)};t.forEach((function(t){var n=t.text,a=t.isNewLine,o=t.fontSize,s=t.fontStyle||i.fontStyle||"normal";e.font=s+" "+(t.fontWeight||i.textWeight)+" 10px "+(t.fontFamily||i.fontFamily),a&&(m(),v());for(var l=.1*o,f=e.measureText("x"),u=f.fontBoundingBoxAscent*l,y=f.fontBoundingBoxDescent*l,w=0;w<n.length;w++){var S=n[w],T=e.measureText(S).width,b=(T<=0?0:T)*l,O=p.length>0?r:0;c.width+O+b>h&&(m(),v()),null===g&&(g=c.width,d=t),p.length>0&&(x+=r,c.width+=r),p.push({char:S,x:x}),c.lineAscent=Math.max(c.lineAscent||0,u),c.lineDescent=Math.max(c.lineDescent||0,y),x+=b,c.width+=b}m()})),v();var y=1/0,w=-1/0;if(0===o.length)return{lines:o,maxLineWidth:f,totalHeight:u,bboxTop:0,bboxBottom:0,bboxHeight:0};for(var S=0;S<o.length;S++){var T=o[S].lineAscent||0,b=o[S].lineDescent||0,O=(l-(T+b))/2;y=Math.min(y,s[S]-T-O),w=Math.max(w,s[S]+b+O)}return{lines:o,maxLineWidth:f,totalHeight:u,bboxTop:y,bboxBottom:w,bboxHeight:w-y}},e.createNewLine=function(){return{richOptions:[],offsetX:[],width:0,lineHeight:0,offsetY:0,chars:[],lineAscent:0,lineDescent:0}},t}(),B=function(){function t(){}return t.prototype.resolveCanvas=function(t,e,i,n,r){return{canvasWidth:Math.max(1,Math.ceil(e)),canvasHeight:Math.max(1,Math.ceil(i)),renderOffsetX:0,renderOffsetY:0}},t}(),X=function(){function t(){}return t.prototype.resolveCanvas=function(t,e,i,n,r){if(0===t.length)return{canvasWidth:Math.max(1,e),canvasHeight:Math.max(1,i),renderOffsetX:0,renderOffsetY:0};for(var a=1/0,o=-1/0,s=r.baselineY,l=0;l<t.length;l++){var h,c,f=null!=(h=t[l].lineAscent)?h:0,u=null!=(c=t[l].lineDescent)?c:0,g=f+u,x=Math.max(0,(t[l].lineHeight-g)/2);a=Math.min(a,s-f-x),o=Math.max(o,s+u+x),l<t.length-1&&(s+=t[l+1].lineHeight)}for(var p=Math.max(0,-a),d=Math.max(0,o-i),v=Math.max(p,d),m=1/0,y=-1/0,w=0;w<t.length;w++){var S,T,b=null!=(S=n.lineOffsets[w])?S:0,O=null!=(T=t[w].width)?T:0;m=Math.min(m,b),y=Math.max(y,b+O)}isFinite(m)||(m=0),isFinite(y)||(y=0);var A=Math.max(0,-m),H=Math.max(0,y-e),M=Math.max(A,H),z=Math.ceil(e+2*M),L=Math.ceil(i+2*v);return{canvasWidth:Math.max(1,z),canvasHeight:Math.max(1,L),renderOffsetX:M,renderOffsetY:v}},t}(),F=function(){function t(){}return t.prototype.getHorizontalOffsets=function(t,e,i,n){return{lineOffsets:t.map((function(t){return i.getOffsetXRich(n,e,t.width)}))}},t}(),Y=function(){function t(){}return t.prototype.getVerticalOffsets=function(t,e,n){if(0===t.length)return{baselineY:0,lineYOffsets:[]};for(var r=[0],a=1;a<t.length;a++)r[a]=r[a-1]+t[a].lineHeight;for(var o=1/0,s=-1/0,l=0;l<t.length;l++){var h,c,f=null!=(h=t[l].lineAscent)?h:0,u=null!=(c=t[l].lineDescent)?c:0,g=f+u,x=(t[l].lineHeight-g)/2;o=Math.min(o,r[l]-f-x),s=Math.max(s,r[l]+u+x)}var p=s-o,d=0;switch(n.textVerticalAlign){case i.TextVerticalAlign.top:d=-o;break;case i.TextVerticalAlign.middle:d=(e-p)/2-o;break;case i.TextVerticalAlign.bottom:d=e-p-o}var v=r.map((function(t){return d+t}));return{baselineY:d,lineYOffsets:v}},t}(),N=function(){function t(){}return t.createWrapStrategy=function(t){return t?new D:new V},t.createOverflowStrategy=function(t){switch(t){case i.TextOverflow.clip:return new B;case i.TextOverflow.display:case i.TextOverflow.visible:default:return new X}},t.createHorizontalAlignStrategy=function(){return new F},t.createVerticalAlignStrategy=function(){return new Y},t}();function P(){return P=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var i=arguments[e];for(var n in i)Object.prototype.hasOwnProperty.call(i,n)&&(t[n]=i[n])}return t},P.apply(this,arguments)}var _=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=.11092565,n.ALPHA_FIX_VALUE=1/255,n.name="MRichText"+_++,n.initTextBase(e),n.richWrapStrategy=N.createWrapStrategy(),n.richOverflowStrategy=N.createOverflowStrategy(i.TextOverflow.display),n.richHorizontalAlignStrategy=N.createHorizontalAlignStrategy(),n.richVerticalAlignStrategy=N.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 C(r),this.text=r.text?r.text.toString():" ",this.textLayout.useLegacyRichText&&(this.textLayout.textVerticalAlign=i.TextVerticalAlign.middle),this.updateStrategies(),this.updateTexture(),this.material.setColor("_Color",new s.Color(1,1,1,1))},n.updateStrategies=function(){var t=this.textLayout;t&&(this.richWrapStrategy=N.createWrapStrategy(t.wrapEnabled),this.richOverflowStrategy=N.createOverflowStrategy(t.overflow))},n.generateTextProgram=function(t){var e=this;this.processedTextOptions=[];var n=z((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=R(n.color)),e.processedTextOptions.push(a)}))}));n(t)},n.updateWithOptions=function(t){this.textStyle=new o(t),this.textLayout=new C(t),this.text=t.text?t.text.toString():" ",this.textLayout.useLegacyRichText&&(this.textLayout.textVerticalAlign=i.TextVerticalAlign.middle),this.updateStrategies(),this.isDirty=!0},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){var n=.1;this.generateTextProgram(this.text);var r=0,a=0,o=this.textLayout,h=this.textStyle,c=o.overflow,f=o.letterSpace,u=void 0===f?0:f,g=this.context,x=[],p=h.fontSize*h.fontScale,d={richOptions:[],offsetX:[],width:0,lineHeight:p*this.singleLineHeight,offsetY:p*(this.singleLineHeight-1)/2};if(this.processedTextOptions.forEach((function(t){var i=t.text,o=t.isNewLine,s=t.fontSize;o&&(x.push(d),r=Math.max(r,d.width),d={richOptions:[],offsetX:[],width:0,lineHeight:p*e.singleLineHeight,offsetY:p*(e.singleLineHeight-1)/2},a+=d.lineHeight),g.font=(t.fontWeight||h.textWeight)+" 10px "+(t.fontFamily||h.fontFamily);var l=g.measureText(i),c=l.width;if(void 0!==l.actualBoundingBoxLeft&&void 0!==l.actualBoundingBoxRight){var f=l.actualBoundingBoxLeft+l.actualBoundingBoxRight;f>0&&(c=Math.max(c,f))}var v=s*e.singleLineHeight*h.fontScale;v>d.lineHeight&&(a+=v-d.lineHeight,d.lineHeight=v,d.offsetY=s*h.fontScale*(e.singleLineHeight-1)/2),d.offsetX.push(d.width),d.width+=(c<=0?0:c)*s*n*h.fontScale+i.length*u,d.richOptions.push(t)})),x.push(d),r=Math.max(r,d.width),a+=d.lineHeight,0!==r&&0!==a){void 0!==this.size&&null!==this.size||(this.size=this.item.transform.size.clone());var v=this.size,m=v.x,y=void 0===m?1:m,w=v.y,S=void 0===w?1:w;if(!this.initialized){this.canvasSize=this.canvasSize?this.canvasSize:new s.Vector2(r,a);var T=this.canvasSize,b=T.x,O=T.y;this.item.transform.size.set(y*b*n*n,S*O*n*n),this.size=this.item.transform.size.clone(),this.initialized=!0}l(this.canvasSize);var A=this.canvasSize,H=A.x,M=A.y;o.width=H/h.fontScale,o.height=M/h.fontScale,this.renderToTexture(H,M,t,(function(t){if(0!==x.length){var n=o.getOffsetY(h,x.length,p*e.singleLineHeight,h.fontSize);x.forEach((function(e,r){var a=e.richOptions,s=e.offsetX,l=e.width,f=l,u=s;if(c===i.TextOverflow.display&&l>H){var g=H/l;f*=g,u=s.map((function(t){return t*g}))}var x=o.getOffsetX(h,f);r>0&&(n+=e.lineHeight-e.offsetY),a.forEach((function(e,r){var a=h.fontScale,o=h.textColor,s=h.fontFamily,f=h.textWeight,g=h.fontStyle,p=e.text,d=e.fontSize,v=e.fontColor,m=void 0===v?o:v,y=e.fontFamily,w=void 0===y?s:y,S=e.fontWeight,T=void 0===S?f:S,b=e.fontStyle,O=void 0===b?g:b,A=d;c===i.TextOverflow.display&&l>H&&(A/=l/H);var M=u[r]+x;t.font=O+" "+T+" "+A*a+"px "+w;var z=m[0],L=m[1],E=m[2],W=m[3];t.fillStyle="rgba("+z+", "+L+", "+E+", "+W+")",t.fillText(p,M,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.updateStrategies(),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.textStyle.fontScale;n.autoResize===i.TextSizeMode.autoWidth&&(n.maxTextWidth=Number.MAX_SAFE_INTEGER);var l,h,c=this.richWrapStrategy.computeLines(this.processedTextOptions,o,this.textStyle,n,a);switch(n.autoResize){case i.TextSizeMode.autoWidth:l=Math.max(1,c.maxLineWidth||0),h=Math.max(1,c.totalHeight||0);break;case i.TextSizeMode.autoHeight:l=n.maxTextWidth,h=Math.max(1,c.totalHeight||0);break;case i.TextSizeMode.fixed:default:l=n.maxTextWidth,h=n.maxTextHeight}if(n.overflow===i.TextOverflow.display){var f=Math.max(1,c.maxLineWidth||0),u=Math.max(1,c.totalHeight||0);!function(t,e,i,n,r){var a=function(t,e){return Math.abs(e)>1e-5?t/e:1},o=Math.max(1,e),s=Math.max(1,i),l=Math.min(1,a(n,o),a(r,s));if(!(l>.9999))for(var h,c=T(t);!(h=c()).done;){var f=h.value;if(f.width*=l,f.lineHeight*=l,f.offsetX)for(var u=0;u<f.offsetX.length;u++)f.offsetX[u]*=l;for(var g,x=T(f.chars||[]);!(g=x()).done;)for(var p,d=T(g.value);!(p=d()).done;)p.value.x*=l;for(var v=f.richOptions||[],m=[],y=0;y<v.length;y++)m.push(P({},v[y],{fontSize:v[y].fontSize*l}));f.richOptions=m,null!=f.lineAscent&&(f.lineAscent*=l),null!=f.lineDescent&&(f.lineDescent*=l)}}(c.lines,f,u,l,h)}var g=this.richHorizontalAlignStrategy.getHorizontalOffsets(c.lines,l,n,this.textStyle),x=this.richVerticalAlignStrategy.getVerticalOffsets(c.lines,h,n),p=this.richOverflowStrategy.resolveCanvas(c.lines,l,h,g,x),d=Math.max(1,Math.ceil(p.canvasWidth*s)),v=Math.max(1,Math.ceil(p.canvasHeight*s));this.item.transform.size.set(p.canvasWidth*this.SCALE_FACTOR*this.SCALE_FACTOR,p.canvasHeight*this.SCALE_FACTOR*this.SCALE_FACTOR),n.maxTextWidth=l,n.maxTextHeight=h,n.width=p.canvasWidth,n.height=p.canvasHeight,this.renderToTexture(d,v,t,(function(t){t.scale(s,s),e.drawTextWithStrategies(t,c.lines,g,x,p,e.textStyle)}),{disposeOld:!1}),this.isDirty=!1}}},n.drawTextWithStrategies=function(t,e,i,n,r,a){var o=r.renderOffsetX,s=r.renderOffsetY,l=n.baselineY+s,h=i.lineOffsets;e.forEach((function(i,n){var r=i.richOptions,s=i.chars,c=h[n]+o,f=l;r.forEach((function(e,n){var r=a.textColor,o=a.fontFamily,l=a.textWeight,h=a.fontStyle,u=e.fontSize,g=e.fontColor,x=void 0===g?r:g,p=e.fontFamily,d=void 0===p?o:p,v=e.fontWeight,m=void 0===v?l:v,y=e.fontStyle,w=void 0===y?h:y,S=u;t.font=w+" "+m+" "+S+"px "+d;var T=x[0],b=x[1],O=x[2],A=x[3];t.fillStyle="rgba("+T+", "+b+", "+O+", "+A+")";var H=i.offsetX&&i.offsetX[n]?i.offsetX[n]:0;s[n].forEach((function(e){t.fillText(e.char,c+H+e.x,f)}))})),n<e.length-1&&(l+=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 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}([n(i.DataType.RichTextComponent)],j),[a]);var I="2.9.1";c("rich-text",w),f.info("Plugin rich text version: 2.9.1."),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,w as RichTextLoader,E as escape,z as generateProgram,L as isRichText,H as lexer,M 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 s,assertExist as l,MaskableGraphic as h,registerPlugin as c,logger as f}from"@galacean/effects/douyin";import{document as u}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 d(t,e,i){return d=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},d.apply(null,arguments)}function v(t){return v=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},v(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 d(t,arguments,v(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,w=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 S(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 S(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)?S(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]+)(=([^>]+))?>$/,O=/^<\/([a-z]+)>$/,A=[["EscapedChar",/^\\([=<>\\/])/],["ContextStart",/^<[a-z]+(=[^>]+)?>/],["ContextEnd",/^<\/[a-z]+>/],["Text",/^[^</>=\\]+/]],H=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 H(t.slice(2),e.concat({tokenType:"Text",value:r}),i+2)}for(var a,o=T(A);!(a=o()).done;){var s=a.value,l=s[0],h=s[1];if("EscapedChar"!==l){var c=h.exec(t);if(c){var f=c[0],u=f.length;return H(t.slice(u),e.concat({tokenType:l,value:f}),i+u)}}}if(t.length>0)return H(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(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=s();if("ContextEnd"===(null==t?void 0:t.tokenType)){o();var e=t.value.match(O);if(e)return{attributeName:e[1]};throw new Error("Expect an end tag marker at position "+a)}return{}},r=H(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 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)}}}(),l};function z(t){return function(e){for(var i,n=T(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 L(t){var e=H(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(O)[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 C=function(){function t(t){this.width=0,this.height=0;var e=t.textOverflow,n=void 0===e?i.TextOverflow.clip:e,r=t.textVerticalAlign,a=void 0===r?i.TextVerticalAlign.middle:r,o=t.textAlign,s=void 0===o?i.TextAlignment.left:o,l=t.letterSpace,h=void 0===l?0:l,c=t.lineHeight,f=void 0===c?.571:c,u=t.wrapEnabled,g=void 0!==u&&u,x=t.maxTextWidth,p=void 0===x?350:x,d=t.maxTextHeight,v=void 0===d?1e3:d,m=t.autoResize,y=void 0===m?i.TextSizeMode.autoWidth:m,w=t.useLegacyRichText,S=void 0!==w&&w;this.letterSpace=h,this.lineHeight=f,this.useLegacyRichText=S,this.overflow=n,this.textVerticalAlign=a,this.textAlign=s,this.width=100,this.height=100,this.wrapEnabled=g,this.maxTextWidth=p,this.maxTextHeight=v,this.autoResize=y}var e=t.prototype;return e.getOffsetY=function(t,e,n,r,a){var o=t.outlineWidth,s=t.fontScale,l=(n-r)/3,h=r+o*s,c=void 0!==a?a:n*(e-1),f=0;switch(this.textVerticalAlign){case i.TextVerticalAlign.top:f=h+l;break;case i.TextVerticalAlign.middle:f=(this.height*s-c+h)/2;break;case i.TextVerticalAlign.bottom:f=this.height*s-c-l}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),s=(e[0]-n)/3,l=n+r*a,h=o-e[0],c=0;switch(this.textVerticalAlign){case i.TextVerticalAlign.top:c=l+s;break;case i.TextVerticalAlign.middle:c=(this.height*a-o)/2+l;break;case i.TextVerticalAlign.bottom:c=this.height*a-h-s}return c},e.getOffsetXRich=function(t,e,n){switch(this.textAlign){case i.TextAlignment.left:return t.outlineWidth;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 k(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 R(t,e){if(void 0===e&&(e=1),"string"!=typeof t||!t)throw new Error("Invalid color string");return t.startsWith("#")?k(t,e):k(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 V=function(){function t(){}var e=t.prototype;return e.computeLines=function(t,e,i,n,r){var a=this,o=[],s=[],l=n.lineHeight||0,h=this.createNewLine(),c=0,f=0,u=function(){if(0!==h.chars.length){h.lineHeight=l;var t=0===o.length?0:s[s.length-1]+l;s.push(t),f+=h.lineHeight,o.push(h),c=Math.max(c,h.width),h=a.createNewLine()}};t.forEach((function(t){var n=t.text,a=t.isNewLine,o=t.fontSize;a&&u();var s=t.fontStyle||i.fontStyle||"normal";e.font=s+" "+(t.fontWeight||i.textWeight)+" 10px "+(t.fontFamily||i.fontFamily),h.offsetX.push(h.width);for(var l=.1*o,c=e.measureText("x"),f=c.fontBoundingBoxAscent*l,g=c.fontBoundingBoxDescent*l,x=0,p=[],d=0;d<n.length;d++){var v=n[d],m=e.measureText(v).width,y=(m<=0?0:m)*l;d>0&&(x+=r),p.push({char:v,x:x}),x+=y}h.chars.push(p),h.width+=x,h.richOptions.push(t),h.lineAscent=Math.max(h.lineAscent||0,f),h.lineDescent=Math.max(h.lineDescent||0,g)})),u();var g=1/0,x=-1/0;if(0===o.length)return{lines:o,maxLineWidth:c,totalHeight:f,bboxTop:0,bboxBottom:0,bboxHeight:0};for(var p=0;p<o.length;p++){var d=o[p].lineAscent||0,v=o[p].lineDescent||0,m=(l-(d+v))/2;g=Math.min(g,s[p]-d-m),x=Math.max(x,s[p]+v+m)}return{lines:o,maxLineWidth:c,totalHeight:f,bboxTop:g,bboxBottom:x,bboxHeight:x-g}},e.createNewLine=function(){return{richOptions:[],offsetX:[],width:0,lineHeight:0,offsetY:0,chars:[],lineAscent:0,lineDescent:0}},t}(),D=function(){function t(){}var e=t.prototype;return e.computeLines=function(t,e,i,n,r){var a=this,o=[],s=[],l=n.lineHeight||0,h=n.maxTextWidth||1/0,c=this.createNewLine(),f=0,u=0,g=null,x=0,p=[],d=null,v=function(){if(m(),0!==c.chars.length){c.lineHeight=l;var t=0===o.length?0:s[s.length-1]+l;s.push(t),u+=c.lineHeight,o.push(c),f=Math.max(f,c.width),c=a.createNewLine(),g=null,x=0,p=[],d=null}},m=function(){0!==p.length&&(null===g&&(g=c.width),c.offsetX.push(g),c.chars.push(p),d&&c.richOptions.push(d),g=null,x=0,p=[],d=null)};t.forEach((function(t){var n=t.text,a=t.isNewLine,o=t.fontSize,s=t.fontStyle||i.fontStyle||"normal";e.font=s+" "+(t.fontWeight||i.textWeight)+" 10px "+(t.fontFamily||i.fontFamily),a&&(m(),v());for(var l=.1*o,f=e.measureText("x"),u=f.fontBoundingBoxAscent*l,y=f.fontBoundingBoxDescent*l,w=0;w<n.length;w++){var S=n[w],T=e.measureText(S).width,b=(T<=0?0:T)*l,O=p.length>0?r:0;c.width+O+b>h&&(m(),v()),null===g&&(g=c.width,d=t),p.length>0&&(x+=r,c.width+=r),p.push({char:S,x:x}),c.lineAscent=Math.max(c.lineAscent||0,u),c.lineDescent=Math.max(c.lineDescent||0,y),x+=b,c.width+=b}m()})),v();var y=1/0,w=-1/0;if(0===o.length)return{lines:o,maxLineWidth:f,totalHeight:u,bboxTop:0,bboxBottom:0,bboxHeight:0};for(var S=0;S<o.length;S++){var T=o[S].lineAscent||0,b=o[S].lineDescent||0,O=(l-(T+b))/2;y=Math.min(y,s[S]-T-O),w=Math.max(w,s[S]+b+O)}return{lines:o,maxLineWidth:f,totalHeight:u,bboxTop:y,bboxBottom:w,bboxHeight:w-y}},e.createNewLine=function(){return{richOptions:[],offsetX:[],width:0,lineHeight:0,offsetY:0,chars:[],lineAscent:0,lineDescent:0}},t}(),B=function(){function t(){}return t.prototype.resolveCanvas=function(t,e,i,n,r){return{canvasWidth:Math.max(1,Math.ceil(e)),canvasHeight:Math.max(1,Math.ceil(i)),renderOffsetX:0,renderOffsetY:0}},t}(),X=function(){function t(){}return t.prototype.resolveCanvas=function(t,e,i,n,r){if(0===t.length)return{canvasWidth:Math.max(1,e),canvasHeight:Math.max(1,i),renderOffsetX:0,renderOffsetY:0};for(var a=1/0,o=-1/0,s=r.baselineY,l=0;l<t.length;l++){var h,c,f=null!=(h=t[l].lineAscent)?h:0,u=null!=(c=t[l].lineDescent)?c:0,g=f+u,x=Math.max(0,(t[l].lineHeight-g)/2);a=Math.min(a,s-f-x),o=Math.max(o,s+u+x),l<t.length-1&&(s+=t[l+1].lineHeight)}for(var p=Math.max(0,-a),d=Math.max(0,o-i),v=Math.max(p,d),m=1/0,y=-1/0,w=0;w<t.length;w++){var S,T,b=null!=(S=n.lineOffsets[w])?S:0,O=null!=(T=t[w].width)?T:0;m=Math.min(m,b),y=Math.max(y,b+O)}isFinite(m)||(m=0),isFinite(y)||(y=0);var A=Math.max(0,-m),H=Math.max(0,y-e),M=Math.max(A,H),z=Math.ceil(e+2*M),L=Math.ceil(i+2*v);return{canvasWidth:Math.max(1,z),canvasHeight:Math.max(1,L),renderOffsetX:M,renderOffsetY:v}},t}(),F=function(){function t(){}return t.prototype.getHorizontalOffsets=function(t,e,i,n){return{lineOffsets:t.map((function(t){return i.getOffsetXRich(n,e,t.width)}))}},t}(),Y=function(){function t(){}return t.prototype.getVerticalOffsets=function(t,e,n){if(0===t.length)return{baselineY:0,lineYOffsets:[]};for(var r=[0],a=1;a<t.length;a++)r[a]=r[a-1]+t[a].lineHeight;for(var o=1/0,s=-1/0,l=0;l<t.length;l++){var h,c,f=null!=(h=t[l].lineAscent)?h:0,u=null!=(c=t[l].lineDescent)?c:0,g=f+u,x=(t[l].lineHeight-g)/2;o=Math.min(o,r[l]-f-x),s=Math.max(s,r[l]+u+x)}var p=s-o,d=0;switch(n.textVerticalAlign){case i.TextVerticalAlign.top:d=-o;break;case i.TextVerticalAlign.middle:d=(e-p)/2-o;break;case i.TextVerticalAlign.bottom:d=e-p-o}var v=r.map((function(t){return d+t}));return{baselineY:d,lineYOffsets:v}},t}(),N=function(){function t(){}return t.createWrapStrategy=function(t){return t?new D:new V},t.createOverflowStrategy=function(t){switch(t){case i.TextOverflow.clip:return new B;case i.TextOverflow.display:case i.TextOverflow.visible:default:return new X}},t.createHorizontalAlignStrategy=function(){return new F},t.createVerticalAlignStrategy=function(){return new Y},t}();function P(){return P=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var i=arguments[e];for(var n in i)Object.prototype.hasOwnProperty.call(i,n)&&(t[n]=i[n])}return t},P.apply(this,arguments)}var _=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=.11092565,n.ALPHA_FIX_VALUE=1/255,n.name="MRichText"+_++,n.initTextBase(e),n.richWrapStrategy=N.createWrapStrategy(),n.richOverflowStrategy=N.createOverflowStrategy(i.TextOverflow.display),n.richHorizontalAlignStrategy=N.createHorizontalAlignStrategy(),n.richVerticalAlignStrategy=N.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 C(r),this.text=r.text?r.text.toString():" ",this.textLayout.useLegacyRichText&&(this.textLayout.textVerticalAlign=i.TextVerticalAlign.middle),this.updateStrategies(),this.updateTexture(),this.material.setColor("_Color",new s.Color(1,1,1,1))},n.updateStrategies=function(){var t=this.textLayout;t&&(this.richWrapStrategy=N.createWrapStrategy(t.wrapEnabled),this.richOverflowStrategy=N.createOverflowStrategy(t.overflow))},n.generateTextProgram=function(t){var e=this;this.processedTextOptions=[];var n=z((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=R(n.color)),e.processedTextOptions.push(a)}))}));n(t)},n.updateWithOptions=function(t){this.textStyle=new o(t),this.textLayout=new C(t),this.text=t.text?t.text.toString():" ",this.textLayout.useLegacyRichText&&(this.textLayout.textVerticalAlign=i.TextVerticalAlign.middle),this.updateStrategies(),this.isDirty=!0},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){var n=.1;this.generateTextProgram(this.text);var r=0,a=0,o=this.textLayout,h=this.textStyle,c=o.overflow,f=o.letterSpace,u=void 0===f?0:f,g=this.context,x=[],p=h.fontSize*h.fontScale,d={richOptions:[],offsetX:[],width:0,lineHeight:p*this.singleLineHeight,offsetY:p*(this.singleLineHeight-1)/2};if(this.processedTextOptions.forEach((function(t){var i=t.text,o=t.isNewLine,s=t.fontSize;o&&(x.push(d),r=Math.max(r,d.width),d={richOptions:[],offsetX:[],width:0,lineHeight:p*e.singleLineHeight,offsetY:p*(e.singleLineHeight-1)/2},a+=d.lineHeight),g.font=(t.fontWeight||h.textWeight)+" 10px "+(t.fontFamily||h.fontFamily);var l=g.measureText(i),c=l.width;if(void 0!==l.actualBoundingBoxLeft&&void 0!==l.actualBoundingBoxRight){var f=l.actualBoundingBoxLeft+l.actualBoundingBoxRight;f>0&&(c=Math.max(c,f))}var v=s*e.singleLineHeight*h.fontScale;v>d.lineHeight&&(a+=v-d.lineHeight,d.lineHeight=v,d.offsetY=s*h.fontScale*(e.singleLineHeight-1)/2),d.offsetX.push(d.width),d.width+=(c<=0?0:c)*s*n*h.fontScale+i.length*u,d.richOptions.push(t)})),x.push(d),r=Math.max(r,d.width),a+=d.lineHeight,0!==r&&0!==a){void 0!==this.size&&null!==this.size||(this.size=this.item.transform.size.clone());var v=this.size,m=v.x,y=void 0===m?1:m,w=v.y,S=void 0===w?1:w;if(!this.initialized){this.canvasSize=this.canvasSize?this.canvasSize:new s.Vector2(r,a);var T=this.canvasSize,b=T.x,O=T.y;this.item.transform.size.set(y*b*n*n,S*O*n*n),this.size=this.item.transform.size.clone(),this.initialized=!0}l(this.canvasSize);var A=this.canvasSize,H=A.x,M=A.y;o.width=H/h.fontScale,o.height=M/h.fontScale,this.renderToTexture(H,M,t,(function(t){if(0!==x.length){var n=o.getOffsetY(h,x.length,p*e.singleLineHeight,h.fontSize);x.forEach((function(e,r){var a=e.richOptions,s=e.offsetX,l=e.width,f=l,u=s;if(c===i.TextOverflow.display&&l>H){var g=H/l;f*=g,u=s.map((function(t){return t*g}))}var x=o.getOffsetX(h,f);r>0&&(n+=e.lineHeight-e.offsetY),a.forEach((function(e,r){var a=h.fontScale,o=h.textColor,s=h.fontFamily,f=h.textWeight,g=h.fontStyle,p=e.text,d=e.fontSize,v=e.fontColor,m=void 0===v?o:v,y=e.fontFamily,w=void 0===y?s:y,S=e.fontWeight,T=void 0===S?f:S,b=e.fontStyle,O=void 0===b?g:b,A=d;c===i.TextOverflow.display&&l>H&&(A/=l/H);var M=u[r]+x;t.font=O+" "+T+" "+A*a+"px "+w;var z=m[0],L=m[1],E=m[2],W=m[3];t.fillStyle="rgba("+z+", "+L+", "+E+", "+W+")",t.fillText(p,M,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.updateStrategies(),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.textStyle.fontScale;n.autoResize===i.TextSizeMode.autoWidth&&(n.maxTextWidth=Number.MAX_SAFE_INTEGER);var l,h,c=this.richWrapStrategy.computeLines(this.processedTextOptions,o,this.textStyle,n,a);switch(n.autoResize){case i.TextSizeMode.autoWidth:l=Math.max(1,c.maxLineWidth||0),h=Math.max(1,c.totalHeight||0);break;case i.TextSizeMode.autoHeight:l=n.maxTextWidth,h=Math.max(1,c.totalHeight||0);break;case i.TextSizeMode.fixed:default:l=n.maxTextWidth,h=n.maxTextHeight}if(n.overflow===i.TextOverflow.display){var f=Math.max(1,c.maxLineWidth||0),u=Math.max(1,c.totalHeight||0);!function(t,e,i,n,r){var a=function(t,e){return Math.abs(e)>1e-5?t/e:1},o=Math.max(1,e),s=Math.max(1,i),l=Math.min(1,a(n,o),a(r,s));if(!(l>.9999))for(var h,c=T(t);!(h=c()).done;){var f=h.value;if(f.width*=l,f.lineHeight*=l,f.offsetX)for(var u=0;u<f.offsetX.length;u++)f.offsetX[u]*=l;for(var g,x=T(f.chars||[]);!(g=x()).done;)for(var p,d=T(g.value);!(p=d()).done;)p.value.x*=l;for(var v=f.richOptions||[],m=[],y=0;y<v.length;y++)m.push(P({},v[y],{fontSize:v[y].fontSize*l}));f.richOptions=m,null!=f.lineAscent&&(f.lineAscent*=l),null!=f.lineDescent&&(f.lineDescent*=l)}}(c.lines,f,u,l,h)}var g=this.richHorizontalAlignStrategy.getHorizontalOffsets(c.lines,l,n,this.textStyle),x=this.richVerticalAlignStrategy.getVerticalOffsets(c.lines,h,n),p=this.richOverflowStrategy.resolveCanvas(c.lines,l,h,g,x),d=Math.max(1,Math.ceil(p.canvasWidth*s)),v=Math.max(1,Math.ceil(p.canvasHeight*s));this.item.transform.size.set(p.canvasWidth*this.SCALE_FACTOR*this.SCALE_FACTOR,p.canvasHeight*this.SCALE_FACTOR*this.SCALE_FACTOR),n.maxTextWidth=l,n.maxTextHeight=h,n.width=p.canvasWidth,n.height=p.canvasHeight,this.renderToTexture(d,v,t,(function(t){t.scale(s,s),e.drawTextWithStrategies(t,c.lines,g,x,p,e.textStyle)}),{disposeOld:!1}),this.isDirty=!1}}},n.drawTextWithStrategies=function(t,e,i,n,r,a){var o=r.renderOffsetX,s=r.renderOffsetY,l=n.baselineY+s,h=i.lineOffsets;e.forEach((function(i,n){var r=i.richOptions,s=i.chars,c=h[n]+o,f=l;r.forEach((function(e,n){var r=a.textColor,o=a.fontFamily,l=a.textWeight,h=a.fontStyle,u=e.fontSize,g=e.fontColor,x=void 0===g?r:g,p=e.fontFamily,d=void 0===p?o:p,v=e.fontWeight,m=void 0===v?l:v,y=e.fontStyle,w=void 0===y?h:y,S=u;t.font=w+" "+m+" "+S+"px "+d;var T=x[0],b=x[1],O=x[2],A=x[3];t.fillStyle="rgba("+T+", "+b+", "+O+", "+A+")";var H=i.offsetX&&i.offsetX[n]?i.offsetX[n]:0;s[n].forEach((function(e){t.fillText(e.char,c+H+e.x,f)}))})),n<e.length-1&&(l+=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 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}([n(i.DataType.RichTextComponent)],j),[a]);var I="2.9.2";c("rich-text",w),f.info("Plugin rich text version: 2.9.2."),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,w as RichTextLoader,E as escape,z as generateProgram,L as isRichText,H as lexer,M 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.9.1
6
+ * Version: v2.9.2
7
7
  */
8
8
 
9
9
  'use strict';
@@ -1606,7 +1606,7 @@ EFFECTS.applyMixins(exports.RichTextComponent, [
1606
1606
 
1607
1607
  /**
1608
1608
  * 插件版本号
1609
- */ var version = "2.9.1";
1609
+ */ var version = "2.9.2";
1610
1610
  EFFECTS.registerPlugin("rich-text", RichTextLoader);
1611
1611
  EFFECTS.logger.info("Plugin rich text version: " + version + ".");
1612
1612
  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.9.1
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 f=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 u(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 u(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 u(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 f=h[0],u=f.length;return v(t.slice(u),e.concat({tokenType:l,value:f}),i+u)}}}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,f=c.attributeParam;if(h){t(r.concat({attributeName:h,attributeParam:null!=f?f:""}),h);continue}if(a){var u=n().attributeName;if(!u)throw Error('Expect an end tag marker "'+a+'" at position '+o+" but found no tag!");if(u!==a)throw Error('Expect an end tag marker "'+a+'" at position '+o+' but found tag "'+u+'"');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 T=function(){function t(t){this.width=0,this.height=0;var i=t.textOverflow,n=void 0===i?e.spec.TextOverflow.clip:i,r=t.textVerticalAlign,o=void 0===r?e.spec.TextVerticalAlign.middle:r,a=t.textAlign,s=void 0===a?e.spec.TextAlignment.left:a,l=t.letterSpace,c=t.lineHeight,h=t.wrapEnabled,f=t.maxTextWidth,u=t.maxTextHeight,p=t.autoResize,g=void 0===p?e.spec.TextSizeMode.autoWidth:p,x=t.useLegacyRichText;this.letterSpace=void 0===l?0:l,this.lineHeight=void 0===c?.571:c,this.useLegacyRichText=void 0!==x&&x,this.overflow=n,this.textVerticalAlign=o,this.textAlign=s,this.width=100,this.height=100,this.wrapEnabled=void 0!==h&&h,this.maxTextWidth=void 0===f?350:f,this.maxTextHeight=void 0===u?1e3:u,this.autoResize=g}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),f=0;switch(this.textVerticalAlign){case e.spec.TextVerticalAlign.top:f=c+l;break;case e.spec.TextVerticalAlign.middle:f=(this.height*s-h+c)/2;break;case e.spec.TextVerticalAlign.bottom:f=this.height*s-h-l}return f},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;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 S(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 w=function(){function t(){}var e=t.prototype;return e.computeLines=function(t,e,i,n,r){var o=this,a=[],s=[],l=n.lineHeight||0,c=this.createNewLine(),h=0,f=0,u=function(){if(0!==c.chars.length){c.lineHeight=l;var t=0===a.length?0:s[s.length-1]+l;s.push(t),f+=c.lineHeight,a.push(c),h=Math.max(h,c.width),c=o.createNewLine()}};t.forEach(function(t){var n=t.text,o=t.isNewLine,a=t.fontSize;o&&u();var s=t.fontStyle||i.fontStyle||"normal";e.font=s+" "+(t.fontWeight||i.textWeight)+" 10px "+(t.fontFamily||i.fontFamily),c.offsetX.push(c.width);for(var l=.1*a,h=e.measureText("x"),f=h.fontBoundingBoxAscent*l,p=h.fontBoundingBoxDescent*l,g=0,x=[],d=0;d<n.length;d++){var v=n[d],m=e.measureText(v).width,y=(m<=0?0:m)*l;d>0&&(g+=r),x.push({char:v,x:g}),g+=y}c.chars.push(x),c.width+=g,c.richOptions.push(t),c.lineAscent=Math.max(c.lineAscent||0,f),c.lineDescent=Math.max(c.lineDescent||0,p)}),u();var p=1/0,g=-1/0;if(0===a.length)return{lines:a,maxLineWidth:h,totalHeight:f,bboxTop:0,bboxBottom:0,bboxHeight:0};for(var x=0;x<a.length;x++){var d=a[x].lineAscent||0,v=a[x].lineDescent||0,m=(l-(d+v))/2;p=Math.min(p,s[x]-d-m),g=Math.max(g,s[x]+v+m)}var y=g-p;return{lines:a,maxLineWidth:h,totalHeight:f,bboxTop:p,bboxBottom:g,bboxHeight:y}},e.createNewLine=function(){return{richOptions:[],offsetX:[],width:0,lineHeight:0,offsetY:0,chars:[],lineAscent:0,lineDescent:0}},t}(),b=function(){function t(){}var e=t.prototype;return e.computeLines=function(t,e,i,n,r){var o=this,a=[],s=[],l=n.lineHeight||0,c=n.maxTextWidth||1/0,h=this.createNewLine(),f=0,u=0,p=null,g=0,x=[],d=null,v=function(){if(m(),0!==h.chars.length){h.lineHeight=l;var t=0===a.length?0:s[s.length-1]+l;s.push(t),u+=h.lineHeight,a.push(h),f=Math.max(f,h.width),h=o.createNewLine(),p=null,g=0,x=[],d=null}},m=function(){0!==x.length&&(null===p&&(p=h.width),h.offsetX.push(p),h.chars.push(x),d&&h.richOptions.push(d),p=null,g=0,x=[],d=null)};t.forEach(function(t){var n=t.text,o=t.isNewLine,a=t.fontSize,s=t.fontStyle||i.fontStyle||"normal";e.font=s+" "+(t.fontWeight||i.textWeight)+" 10px "+(t.fontFamily||i.fontFamily),o&&(m(),v());for(var l=.1*a,f=e.measureText("x"),u=f.fontBoundingBoxAscent*l,y=f.fontBoundingBoxDescent*l,T=0;T<n.length;T++){var S=n[T],w=e.measureText(S).width,b=(w<=0?0:w)*l,O=x.length>0?r:0;h.width+O+b>c&&(m(),v()),null===p&&(p=h.width,d=t),x.length>0&&(g+=r,h.width+=r),x.push({char:S,x:g}),h.lineAscent=Math.max(h.lineAscent||0,u),h.lineDescent=Math.max(h.lineDescent||0,y),g+=b,h.width+=b}m()}),v();var y=1/0,T=-1/0;if(0===a.length)return{lines:a,maxLineWidth:f,totalHeight:u,bboxTop:0,bboxBottom:0,bboxHeight:0};for(var S=0;S<a.length;S++){var w=a[S].lineAscent||0,b=a[S].lineDescent||0,O=(l-(w+b))/2;y=Math.min(y,s[S]-w-O),T=Math.max(T,s[S]+b+O)}var A=T-y;return{lines:a,maxLineWidth:f,totalHeight:u,bboxTop:y,bboxBottom:T,bboxHeight:A}},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.resolveCanvas=function(t,e,i,n,r){return{canvasWidth:Math.max(1,Math.ceil(e)),canvasHeight:Math.max(1,Math.ceil(i)),renderOffsetX:0,renderOffsetY:0}},t}(),A=function(){function t(){}return t.prototype.resolveCanvas=function(t,e,i,n,r){if(0===t.length)return{canvasWidth:Math.max(1,e),canvasHeight:Math.max(1,i),renderOffsetX:0,renderOffsetY:0};for(var o=1/0,a=-1/0,s=r.baselineY,l=0;l<t.length;l++){var c,h,f=null!=(c=t[l].lineAscent)?c:0,u=null!=(h=t[l].lineDescent)?h:0,p=f+u,g=Math.max(0,(t[l].lineHeight-p)/2);o=Math.min(o,s-f-g),a=Math.max(a,s+u+g),l<t.length-1&&(s+=t[l+1].lineHeight)}for(var x=Math.max(Math.max(0,-o),Math.max(0,a-i)),d=1/0,v=-1/0,m=0;m<t.length;m++){var y,T,S=null!=(y=n.lineOffsets[m])?y:0,w=null!=(T=t[m].width)?T:0;d=Math.min(d,S),v=Math.max(v,S+w)}isFinite(d)||(d=0),isFinite(v)||(v=0);var b=Math.max(Math.max(0,-d),Math.max(0,v-e));return{canvasWidth:Math.max(1,Math.ceil(e+2*b)),canvasHeight:Math.max(1,Math.ceil(i+2*x)),renderOffsetX:b,renderOffsetY:x}},t}(),M=function(){function t(){}return t.prototype.getHorizontalOffsets=function(t,e,i,n){return{lineOffsets:t.map(function(t){return i.getOffsetXRich(n,e,t.width)})}},t}(),H=function(){function t(){}return t.prototype.getVerticalOffsets=function(t,i,n){if(0===t.length)return{baselineY:0,lineYOffsets:[]};for(var r=[0],o=1;o<t.length;o++)r[o]=r[o-1]+t[o].lineHeight;for(var a=1/0,s=-1/0,l=0;l<t.length;l++){var c,h,f=null!=(c=t[l].lineAscent)?c:0,u=null!=(h=t[l].lineDescent)?h:0,p=f+u,g=(t[l].lineHeight-p)/2;a=Math.min(a,r[l]-f-g),s=Math.max(s,r[l]+u+g)}var x=s-a,d=0;switch(n.textVerticalAlign){case e.spec.TextVerticalAlign.top:d=-a;break;case e.spec.TextVerticalAlign.middle:d=(i-x)/2-a;break;case e.spec.TextVerticalAlign.bottom:d=i-x-a}var v=r.map(function(t){return d+t});return{baselineY:d,lineYOffsets:v}},t}(),z=function(){function t(){}return t.createWrapStrategy=function(t){return t?new b:new w},t.createOverflowStrategy=function(t){switch(t){case e.spec.TextOverflow.clip:return new O;case e.spec.TextOverflow.display:case e.spec.TextOverflow.visible:default:return new A}},t.createHorizontalAlignStrategy=function(){return new M},t.createVerticalAlignStrategy=function(){return new H},t}();function E(){return(E=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var i=arguments[e];for(var n in i)Object.prototype.hasOwnProperty.call(i,n)&&(t[n]=i[n])}return t}).apply(this,arguments)}var L=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=.11092565,n.ALPHA_FIX_VALUE=1/255,n.name="MRichText"+L++,n.initTextBase(i),n.richWrapStrategy=z.createWrapStrategy(),n.richOverflowStrategy=z.createOverflowStrategy(e.spec.TextOverflow.display),n.richHorizontalAlignStrategy=z.createHorizontalAlignStrategy(),n.richVerticalAlignStrategy=z.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 T(r),this.text=r.text?r.text.toString():" ",this.textLayout.useLegacyRichText&&(this.textLayout.textVerticalAlign=e.spec.TextVerticalAlign.middle),this.updateStrategies(),this.updateTexture(),this.material.setColor("_Color",new e.math.Color(1,1,1,1))},n.updateStrategies=function(){var t=this.textLayout;t&&(this.richWrapStrategy=z.createWrapStrategy(t.wrapEnabled),this.richOverflowStrategy=z.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("#")?S(t,e):S(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 T(t),this.text=t.text?t.text.toString():" ",this.textLayout.useLegacyRichText&&(this.textLayout.textVerticalAlign=e.spec.TextVerticalAlign.middle),this.updateStrategies(),this.isDirty=!0},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,f=[],u=a.fontSize*a.fontScale,p={richOptions:[],offsetX:[],width:0,lineHeight:u*this.singleLineHeight,offsetY:u*(this.singleLineHeight-1)/2};if(this.processedTextOptions.forEach(function(t){var e=t.text,o=t.isNewLine,s=t.fontSize;o&&(f.push(p),n=Math.max(n,p.width),p={richOptions:[],offsetX:[],width:0,lineHeight:u*i.singleLineHeight,offsetY:u*(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*.1*a.fontScale+e.length*c,p.richOptions.push(t)}),f.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*.1*.1,(void 0===d?1:d)*y*.1*.1),this.size=this.item.transform.size.clone(),this.initialized=!0}e.assertExist(this.canvasSize);var T=this.canvasSize,S=T.x,w=T.y;o.width=S/a.fontScale,o.height=w/a.fontScale,this.renderToTexture(S,w,t,function(t){if(0!==f.length){var n=o.getOffsetY(a,f.length,u*i.singleLineHeight,a.fontSize);f.forEach(function(i,r){var l=i.richOptions,c=i.offsetX,h=i.width,f=h,u=c;if(s===e.spec.TextOverflow.display&&h>S){var p=S/h;f*=p,u=c.map(function(t){return t*p})}var g=o.getOffsetX(a,f);r>0&&(n+=i.lineHeight-i.offsetY),l.forEach(function(i,r){var o=a.fontScale,l=a.textColor,c=a.fontFamily,f=a.textWeight,p=a.fontStyle,x=i.text,d=i.fontSize,v=i.fontColor,m=void 0===v?l:v,y=i.fontFamily,T=i.fontWeight,w=i.fontStyle,b=d;s===e.spec.TextOverflow.display&&h>S&&(b/=h/S);var O=u[r]+g;t.font=(void 0===w?p:w)+" "+(void 0===T?f:T)+" "+b*o+"px "+(void 0===y?c:y);var A=m[0],M=m[1],H=m[2],z=m[3];t.fillStyle="rgba("+A+", "+M+", "+H+", "+z+")",t.fillText(x,O,n)})})}},{disposeOld:!1}),this.isDirty=!1}},n.updateTextureWithStrategies=function(t){var i,n,r=this;if(this.isDirty&&this.context&&this.canvas){this.updateStrategies(),this.generateTextProgram(this.text);var o=this.textLayout,a=o.letterSpace,s=this.context;if(s){var l=this.textStyle.fontScale;o.autoResize===e.spec.TextSizeMode.autoWidth&&(o.maxTextWidth=Number.MAX_SAFE_INTEGER);var c=this.richWrapStrategy.computeLines(this.processedTextOptions,s,this.textStyle,o,void 0===a?0:a);switch(o.autoResize){case e.spec.TextSizeMode.autoWidth:i=Math.max(1,c.maxLineWidth||0),n=Math.max(1,c.totalHeight||0);break;case e.spec.TextSizeMode.autoHeight:i=o.maxTextWidth,n=Math.max(1,c.totalHeight||0);break;case e.spec.TextSizeMode.fixed:default:i=o.maxTextWidth,n=o.maxTextHeight}if(o.overflow===e.spec.TextOverflow.display){var h=Math.max(1,c.maxLineWidth||0),f=Math.max(1,c.totalHeight||0);!function(t,e,i,n,r){var o=function(t,e){return Math.abs(e)>1e-5?t/e:1},a=Math.min(1,o(n,Math.max(1,e)),o(r,Math.max(1,i)));if(!(a>.9999))for(var s,l=p(t);!(s=l()).done;){var c=s.value;if(c.width*=a,c.lineHeight*=a,c.offsetX)for(var h=0;h<c.offsetX.length;h++)c.offsetX[h]*=a;for(var f,u=p(c.chars||[]);!(f=u()).done;)for(var g,x=f.value,d=p(x);!(g=d()).done;){var v=g.value;v.x*=a}for(var m=c.richOptions||[],y=[],T=0;T<m.length;T++)y.push(E({},m[T],{fontSize:m[T].fontSize*a}));c.richOptions=y,null!=c.lineAscent&&(c.lineAscent*=a),null!=c.lineDescent&&(c.lineDescent*=a)}}(c.lines,h,f,i,n)}var u=this.richHorizontalAlignStrategy.getHorizontalOffsets(c.lines,i,o,this.textStyle),g=this.richVerticalAlignStrategy.getVerticalOffsets(c.lines,n,o),x=this.richOverflowStrategy.resolveCanvas(c.lines,i,n,u,g),d=Math.max(1,Math.ceil(x.canvasWidth*l)),v=Math.max(1,Math.ceil(x.canvasHeight*l));this.item.transform.size.set(x.canvasWidth*this.SCALE_FACTOR*this.SCALE_FACTOR,x.canvasHeight*this.SCALE_FACTOR*this.SCALE_FACTOR),o.maxTextWidth=i,o.maxTextHeight=n,o.width=x.canvasWidth,o.height=x.canvasHeight,this.renderToTexture(d,v,t,function(t){t.scale(l,l),r.drawTextWithStrategies(t,c.lines,u,g,x,r.textStyle)},{disposeOld:!1}),this.isDirty=!1}}},n.drawTextWithStrategies=function(t,e,i,n,r,o){var a=r.renderOffsetX,s=r.renderOffsetY,l=n.baselineY+s,c=i.lineOffsets;e.forEach(function(i,n){var r=i.richOptions,s=i.chars,h=c[n]+a,f=l;r.forEach(function(e,n){var r=o.textColor,a=o.fontFamily,l=o.textWeight,c=o.fontStyle,u=e.fontSize,p=e.fontColor,g=void 0===p?r:p,x=e.fontFamily,d=e.fontWeight,v=e.fontStyle;t.font=(void 0===v?c:v)+" "+(void 0===d?l:d)+" "+u+"px "+(void 0===x?a:x);var m=g[0],y=g[1],T=g[2],S=g[3];t.fillStyle="rgba("+m+", "+y+", "+T+", "+S+")";var w=i.offsetX&&i.offsetX[n]?i.offsetX[n]:0;s[n].forEach(function(e){t.fillText(e.char,h+w+e.x,f)})}),n<e.length-1&&(l+=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.9.1";e.registerPlugin("rich-text",f),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=f,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.9.2
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 f=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 u(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 u(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 u(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 f=h[0],u=f.length;return v(t.slice(u),e.concat({tokenType:l,value:f}),i+u)}}}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,f=c.attributeParam;if(h){t(r.concat({attributeName:h,attributeParam:null!=f?f:""}),h);continue}if(a){var u=n().attributeName;if(!u)throw Error('Expect an end tag marker "'+a+'" at position '+o+" but found no tag!");if(u!==a)throw Error('Expect an end tag marker "'+a+'" at position '+o+' but found tag "'+u+'"');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 T=function(){function t(t){this.width=0,this.height=0;var i=t.textOverflow,n=void 0===i?e.spec.TextOverflow.clip:i,r=t.textVerticalAlign,o=void 0===r?e.spec.TextVerticalAlign.middle:r,a=t.textAlign,s=void 0===a?e.spec.TextAlignment.left:a,l=t.letterSpace,c=t.lineHeight,h=t.wrapEnabled,f=t.maxTextWidth,u=t.maxTextHeight,p=t.autoResize,g=void 0===p?e.spec.TextSizeMode.autoWidth:p,x=t.useLegacyRichText;this.letterSpace=void 0===l?0:l,this.lineHeight=void 0===c?.571:c,this.useLegacyRichText=void 0!==x&&x,this.overflow=n,this.textVerticalAlign=o,this.textAlign=s,this.width=100,this.height=100,this.wrapEnabled=void 0!==h&&h,this.maxTextWidth=void 0===f?350:f,this.maxTextHeight=void 0===u?1e3:u,this.autoResize=g}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),f=0;switch(this.textVerticalAlign){case e.spec.TextVerticalAlign.top:f=c+l;break;case e.spec.TextVerticalAlign.middle:f=(this.height*s-h+c)/2;break;case e.spec.TextVerticalAlign.bottom:f=this.height*s-h-l}return f},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;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 S(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 w=function(){function t(){}var e=t.prototype;return e.computeLines=function(t,e,i,n,r){var o=this,a=[],s=[],l=n.lineHeight||0,c=this.createNewLine(),h=0,f=0,u=function(){if(0!==c.chars.length){c.lineHeight=l;var t=0===a.length?0:s[s.length-1]+l;s.push(t),f+=c.lineHeight,a.push(c),h=Math.max(h,c.width),c=o.createNewLine()}};t.forEach(function(t){var n=t.text,o=t.isNewLine,a=t.fontSize;o&&u();var s=t.fontStyle||i.fontStyle||"normal";e.font=s+" "+(t.fontWeight||i.textWeight)+" 10px "+(t.fontFamily||i.fontFamily),c.offsetX.push(c.width);for(var l=.1*a,h=e.measureText("x"),f=h.fontBoundingBoxAscent*l,p=h.fontBoundingBoxDescent*l,g=0,x=[],d=0;d<n.length;d++){var v=n[d],m=e.measureText(v).width,y=(m<=0?0:m)*l;d>0&&(g+=r),x.push({char:v,x:g}),g+=y}c.chars.push(x),c.width+=g,c.richOptions.push(t),c.lineAscent=Math.max(c.lineAscent||0,f),c.lineDescent=Math.max(c.lineDescent||0,p)}),u();var p=1/0,g=-1/0;if(0===a.length)return{lines:a,maxLineWidth:h,totalHeight:f,bboxTop:0,bboxBottom:0,bboxHeight:0};for(var x=0;x<a.length;x++){var d=a[x].lineAscent||0,v=a[x].lineDescent||0,m=(l-(d+v))/2;p=Math.min(p,s[x]-d-m),g=Math.max(g,s[x]+v+m)}var y=g-p;return{lines:a,maxLineWidth:h,totalHeight:f,bboxTop:p,bboxBottom:g,bboxHeight:y}},e.createNewLine=function(){return{richOptions:[],offsetX:[],width:0,lineHeight:0,offsetY:0,chars:[],lineAscent:0,lineDescent:0}},t}(),b=function(){function t(){}var e=t.prototype;return e.computeLines=function(t,e,i,n,r){var o=this,a=[],s=[],l=n.lineHeight||0,c=n.maxTextWidth||1/0,h=this.createNewLine(),f=0,u=0,p=null,g=0,x=[],d=null,v=function(){if(m(),0!==h.chars.length){h.lineHeight=l;var t=0===a.length?0:s[s.length-1]+l;s.push(t),u+=h.lineHeight,a.push(h),f=Math.max(f,h.width),h=o.createNewLine(),p=null,g=0,x=[],d=null}},m=function(){0!==x.length&&(null===p&&(p=h.width),h.offsetX.push(p),h.chars.push(x),d&&h.richOptions.push(d),p=null,g=0,x=[],d=null)};t.forEach(function(t){var n=t.text,o=t.isNewLine,a=t.fontSize,s=t.fontStyle||i.fontStyle||"normal";e.font=s+" "+(t.fontWeight||i.textWeight)+" 10px "+(t.fontFamily||i.fontFamily),o&&(m(),v());for(var l=.1*a,f=e.measureText("x"),u=f.fontBoundingBoxAscent*l,y=f.fontBoundingBoxDescent*l,T=0;T<n.length;T++){var S=n[T],w=e.measureText(S).width,b=(w<=0?0:w)*l,O=x.length>0?r:0;h.width+O+b>c&&(m(),v()),null===p&&(p=h.width,d=t),x.length>0&&(g+=r,h.width+=r),x.push({char:S,x:g}),h.lineAscent=Math.max(h.lineAscent||0,u),h.lineDescent=Math.max(h.lineDescent||0,y),g+=b,h.width+=b}m()}),v();var y=1/0,T=-1/0;if(0===a.length)return{lines:a,maxLineWidth:f,totalHeight:u,bboxTop:0,bboxBottom:0,bboxHeight:0};for(var S=0;S<a.length;S++){var w=a[S].lineAscent||0,b=a[S].lineDescent||0,O=(l-(w+b))/2;y=Math.min(y,s[S]-w-O),T=Math.max(T,s[S]+b+O)}var A=T-y;return{lines:a,maxLineWidth:f,totalHeight:u,bboxTop:y,bboxBottom:T,bboxHeight:A}},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.resolveCanvas=function(t,e,i,n,r){return{canvasWidth:Math.max(1,Math.ceil(e)),canvasHeight:Math.max(1,Math.ceil(i)),renderOffsetX:0,renderOffsetY:0}},t}(),A=function(){function t(){}return t.prototype.resolveCanvas=function(t,e,i,n,r){if(0===t.length)return{canvasWidth:Math.max(1,e),canvasHeight:Math.max(1,i),renderOffsetX:0,renderOffsetY:0};for(var o=1/0,a=-1/0,s=r.baselineY,l=0;l<t.length;l++){var c,h,f=null!=(c=t[l].lineAscent)?c:0,u=null!=(h=t[l].lineDescent)?h:0,p=f+u,g=Math.max(0,(t[l].lineHeight-p)/2);o=Math.min(o,s-f-g),a=Math.max(a,s+u+g),l<t.length-1&&(s+=t[l+1].lineHeight)}for(var x=Math.max(Math.max(0,-o),Math.max(0,a-i)),d=1/0,v=-1/0,m=0;m<t.length;m++){var y,T,S=null!=(y=n.lineOffsets[m])?y:0,w=null!=(T=t[m].width)?T:0;d=Math.min(d,S),v=Math.max(v,S+w)}isFinite(d)||(d=0),isFinite(v)||(v=0);var b=Math.max(Math.max(0,-d),Math.max(0,v-e));return{canvasWidth:Math.max(1,Math.ceil(e+2*b)),canvasHeight:Math.max(1,Math.ceil(i+2*x)),renderOffsetX:b,renderOffsetY:x}},t}(),M=function(){function t(){}return t.prototype.getHorizontalOffsets=function(t,e,i,n){return{lineOffsets:t.map(function(t){return i.getOffsetXRich(n,e,t.width)})}},t}(),H=function(){function t(){}return t.prototype.getVerticalOffsets=function(t,i,n){if(0===t.length)return{baselineY:0,lineYOffsets:[]};for(var r=[0],o=1;o<t.length;o++)r[o]=r[o-1]+t[o].lineHeight;for(var a=1/0,s=-1/0,l=0;l<t.length;l++){var c,h,f=null!=(c=t[l].lineAscent)?c:0,u=null!=(h=t[l].lineDescent)?h:0,p=f+u,g=(t[l].lineHeight-p)/2;a=Math.min(a,r[l]-f-g),s=Math.max(s,r[l]+u+g)}var x=s-a,d=0;switch(n.textVerticalAlign){case e.spec.TextVerticalAlign.top:d=-a;break;case e.spec.TextVerticalAlign.middle:d=(i-x)/2-a;break;case e.spec.TextVerticalAlign.bottom:d=i-x-a}var v=r.map(function(t){return d+t});return{baselineY:d,lineYOffsets:v}},t}(),z=function(){function t(){}return t.createWrapStrategy=function(t){return t?new b:new w},t.createOverflowStrategy=function(t){switch(t){case e.spec.TextOverflow.clip:return new O;case e.spec.TextOverflow.display:case e.spec.TextOverflow.visible:default:return new A}},t.createHorizontalAlignStrategy=function(){return new M},t.createVerticalAlignStrategy=function(){return new H},t}();function E(){return(E=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var i=arguments[e];for(var n in i)Object.prototype.hasOwnProperty.call(i,n)&&(t[n]=i[n])}return t}).apply(this,arguments)}var L=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=.11092565,n.ALPHA_FIX_VALUE=1/255,n.name="MRichText"+L++,n.initTextBase(i),n.richWrapStrategy=z.createWrapStrategy(),n.richOverflowStrategy=z.createOverflowStrategy(e.spec.TextOverflow.display),n.richHorizontalAlignStrategy=z.createHorizontalAlignStrategy(),n.richVerticalAlignStrategy=z.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 T(r),this.text=r.text?r.text.toString():" ",this.textLayout.useLegacyRichText&&(this.textLayout.textVerticalAlign=e.spec.TextVerticalAlign.middle),this.updateStrategies(),this.updateTexture(),this.material.setColor("_Color",new e.math.Color(1,1,1,1))},n.updateStrategies=function(){var t=this.textLayout;t&&(this.richWrapStrategy=z.createWrapStrategy(t.wrapEnabled),this.richOverflowStrategy=z.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("#")?S(t,e):S(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 T(t),this.text=t.text?t.text.toString():" ",this.textLayout.useLegacyRichText&&(this.textLayout.textVerticalAlign=e.spec.TextVerticalAlign.middle),this.updateStrategies(),this.isDirty=!0},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,f=[],u=a.fontSize*a.fontScale,p={richOptions:[],offsetX:[],width:0,lineHeight:u*this.singleLineHeight,offsetY:u*(this.singleLineHeight-1)/2};if(this.processedTextOptions.forEach(function(t){var e=t.text,o=t.isNewLine,s=t.fontSize;o&&(f.push(p),n=Math.max(n,p.width),p={richOptions:[],offsetX:[],width:0,lineHeight:u*i.singleLineHeight,offsetY:u*(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*.1*a.fontScale+e.length*c,p.richOptions.push(t)}),f.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*.1*.1,(void 0===d?1:d)*y*.1*.1),this.size=this.item.transform.size.clone(),this.initialized=!0}e.assertExist(this.canvasSize);var T=this.canvasSize,S=T.x,w=T.y;o.width=S/a.fontScale,o.height=w/a.fontScale,this.renderToTexture(S,w,t,function(t){if(0!==f.length){var n=o.getOffsetY(a,f.length,u*i.singleLineHeight,a.fontSize);f.forEach(function(i,r){var l=i.richOptions,c=i.offsetX,h=i.width,f=h,u=c;if(s===e.spec.TextOverflow.display&&h>S){var p=S/h;f*=p,u=c.map(function(t){return t*p})}var g=o.getOffsetX(a,f);r>0&&(n+=i.lineHeight-i.offsetY),l.forEach(function(i,r){var o=a.fontScale,l=a.textColor,c=a.fontFamily,f=a.textWeight,p=a.fontStyle,x=i.text,d=i.fontSize,v=i.fontColor,m=void 0===v?l:v,y=i.fontFamily,T=i.fontWeight,w=i.fontStyle,b=d;s===e.spec.TextOverflow.display&&h>S&&(b/=h/S);var O=u[r]+g;t.font=(void 0===w?p:w)+" "+(void 0===T?f:T)+" "+b*o+"px "+(void 0===y?c:y);var A=m[0],M=m[1],H=m[2],z=m[3];t.fillStyle="rgba("+A+", "+M+", "+H+", "+z+")",t.fillText(x,O,n)})})}},{disposeOld:!1}),this.isDirty=!1}},n.updateTextureWithStrategies=function(t){var i,n,r=this;if(this.isDirty&&this.context&&this.canvas){this.updateStrategies(),this.generateTextProgram(this.text);var o=this.textLayout,a=o.letterSpace,s=this.context;if(s){var l=this.textStyle.fontScale;o.autoResize===e.spec.TextSizeMode.autoWidth&&(o.maxTextWidth=Number.MAX_SAFE_INTEGER);var c=this.richWrapStrategy.computeLines(this.processedTextOptions,s,this.textStyle,o,void 0===a?0:a);switch(o.autoResize){case e.spec.TextSizeMode.autoWidth:i=Math.max(1,c.maxLineWidth||0),n=Math.max(1,c.totalHeight||0);break;case e.spec.TextSizeMode.autoHeight:i=o.maxTextWidth,n=Math.max(1,c.totalHeight||0);break;case e.spec.TextSizeMode.fixed:default:i=o.maxTextWidth,n=o.maxTextHeight}if(o.overflow===e.spec.TextOverflow.display){var h=Math.max(1,c.maxLineWidth||0),f=Math.max(1,c.totalHeight||0);!function(t,e,i,n,r){var o=function(t,e){return Math.abs(e)>1e-5?t/e:1},a=Math.min(1,o(n,Math.max(1,e)),o(r,Math.max(1,i)));if(!(a>.9999))for(var s,l=p(t);!(s=l()).done;){var c=s.value;if(c.width*=a,c.lineHeight*=a,c.offsetX)for(var h=0;h<c.offsetX.length;h++)c.offsetX[h]*=a;for(var f,u=p(c.chars||[]);!(f=u()).done;)for(var g,x=f.value,d=p(x);!(g=d()).done;){var v=g.value;v.x*=a}for(var m=c.richOptions||[],y=[],T=0;T<m.length;T++)y.push(E({},m[T],{fontSize:m[T].fontSize*a}));c.richOptions=y,null!=c.lineAscent&&(c.lineAscent*=a),null!=c.lineDescent&&(c.lineDescent*=a)}}(c.lines,h,f,i,n)}var u=this.richHorizontalAlignStrategy.getHorizontalOffsets(c.lines,i,o,this.textStyle),g=this.richVerticalAlignStrategy.getVerticalOffsets(c.lines,n,o),x=this.richOverflowStrategy.resolveCanvas(c.lines,i,n,u,g),d=Math.max(1,Math.ceil(x.canvasWidth*l)),v=Math.max(1,Math.ceil(x.canvasHeight*l));this.item.transform.size.set(x.canvasWidth*this.SCALE_FACTOR*this.SCALE_FACTOR,x.canvasHeight*this.SCALE_FACTOR*this.SCALE_FACTOR),o.maxTextWidth=i,o.maxTextHeight=n,o.width=x.canvasWidth,o.height=x.canvasHeight,this.renderToTexture(d,v,t,function(t){t.scale(l,l),r.drawTextWithStrategies(t,c.lines,u,g,x,r.textStyle)},{disposeOld:!1}),this.isDirty=!1}}},n.drawTextWithStrategies=function(t,e,i,n,r,o){var a=r.renderOffsetX,s=r.renderOffsetY,l=n.baselineY+s,c=i.lineOffsets;e.forEach(function(i,n){var r=i.richOptions,s=i.chars,h=c[n]+a,f=l;r.forEach(function(e,n){var r=o.textColor,a=o.fontFamily,l=o.textWeight,c=o.fontStyle,u=e.fontSize,p=e.fontColor,g=void 0===p?r:p,x=e.fontFamily,d=e.fontWeight,v=e.fontStyle;t.font=(void 0===v?c:v)+" "+(void 0===d?l:d)+" "+u+"px "+(void 0===x?a:x);var m=g[0],y=g[1],T=g[2],S=g[3];t.fillStyle="rgba("+m+", "+y+", "+T+", "+S+")";var w=i.offsetX&&i.offsetX[n]?i.offsetX[n]:0;s[n].forEach(function(e){t.fillText(e.char,h+w+e.x,f)})}),n<e.length-1&&(l+=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.9.2";e.registerPlugin("rich-text",f),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=f,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.9.1
6
+ * Version: v2.9.2
7
7
  */
8
8
 
9
9
  import * as EFFECTS from '@galacean/effects';
@@ -1583,7 +1583,7 @@ applyMixins(RichTextComponent, [
1583
1583
 
1584
1584
  /**
1585
1585
  * 插件版本号
1586
- */ var version = "2.9.1";
1586
+ */ var version = "2.9.2";
1587
1587
  registerPlugin("rich-text", RichTextLoader);
1588
1588
  logger.info("Plugin rich text version: " + version + ".");
1589
1589
  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 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]+)>$/,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 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=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});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 w=function(){function e(e){this.width=0,this.height=0;var i=e.textOverflow,n=void 0===i?t.spec.TextOverflow.clip:i,r=e.textVerticalAlign,o=void 0===r?t.spec.TextVerticalAlign.middle:r,a=e.textAlign,s=void 0===a?t.spec.TextAlignment.left:a,l=e.letterSpace,c=void 0===l?0:l,h=e.lineHeight,u=void 0===h?.571:h,f=e.wrapEnabled,p=void 0!==f&&f,x=e.maxTextWidth,g=void 0===x?350:x,d=e.maxTextHeight,v=void 0===d?1e3:d,m=e.autoResize,y=void 0===m?t.spec.TextSizeMode.autoWidth:m,w=e.useLegacyRichText,T=void 0!==w&&w;this.letterSpace=c,this.lineHeight=u,this.useLegacyRichText=T,this.overflow=n,this.textVerticalAlign=o,this.textAlign=s,this.width=100,this.height=100,this.wrapEnabled=p,this.maxTextWidth=g,this.maxTextHeight=v,this.autoResize=y}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;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 S(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){var o=this,a=[],s=[],l=n.lineHeight||0,c=this.createNewLine(),h=0,u=0,f=function(){if(0!==c.chars.length){c.lineHeight=l;var t=0===a.length?0:s[s.length-1]+l;s.push(t),u+=c.lineHeight,a.push(c),h=Math.max(h,c.width),c=o.createNewLine()}};t.forEach((function(t){var n=t.text,o=t.isNewLine,a=t.fontSize;o&&f();var s=t.fontStyle||i.fontStyle||"normal";e.font=s+" "+(t.fontWeight||i.textWeight)+" 10px "+(t.fontFamily||i.fontFamily),c.offsetX.push(c.width);for(var l=.1*a,h=e.measureText("x"),u=h.fontBoundingBoxAscent*l,p=h.fontBoundingBoxDescent*l,x=0,g=[],d=0;d<n.length;d++){var v=n[d],m=e.measureText(v).width,y=(m<=0?0:m)*l;d>0&&(x+=r),g.push({char:v,x:x}),x+=y}c.chars.push(g),c.width+=x,c.richOptions.push(t),c.lineAscent=Math.max(c.lineAscent||0,u),c.lineDescent=Math.max(c.lineDescent||0,p)})),f();var p=1/0,x=-1/0;if(0===a.length)return{lines:a,maxLineWidth:h,totalHeight:u,bboxTop:0,bboxBottom:0,bboxHeight:0};for(var g=0;g<a.length;g++){var d=a[g].lineAscent||0,v=a[g].lineDescent||0,m=(l-(d+v))/2;p=Math.min(p,s[g]-d-m),x=Math.max(x,s[g]+v+m)}return{lines:a,maxLineWidth:h,totalHeight:u,bboxTop:p,bboxBottom:x,bboxHeight:x-p}},e.createNewLine=function(){return{richOptions:[],offsetX:[],width:0,lineHeight:0,offsetY:0,chars:[],lineAscent:0,lineDescent:0}},t}(),O=function(){function t(){}var e=t.prototype;return e.computeLines=function(t,e,i,n,r){var o=this,a=[],s=[],l=n.lineHeight||0,c=n.maxTextWidth||1/0,h=this.createNewLine(),u=0,f=0,p=null,x=0,g=[],d=null,v=function(){if(m(),0!==h.chars.length){h.lineHeight=l;var t=0===a.length?0:s[s.length-1]+l;s.push(t),f+=h.lineHeight,a.push(h),u=Math.max(u,h.width),h=o.createNewLine(),p=null,x=0,g=[],d=null}},m=function(){0!==g.length&&(null===p&&(p=h.width),h.offsetX.push(p),h.chars.push(g),d&&h.richOptions.push(d),p=null,x=0,g=[],d=null)};t.forEach((function(t){var n=t.text,o=t.isNewLine,a=t.fontSize,s=t.fontStyle||i.fontStyle||"normal";e.font=s+" "+(t.fontWeight||i.textWeight)+" 10px "+(t.fontFamily||i.fontFamily),o&&(m(),v());for(var l=.1*a,u=e.measureText("x"),f=u.fontBoundingBoxAscent*l,y=u.fontBoundingBoxDescent*l,w=0;w<n.length;w++){var T=n[w],S=e.measureText(T).width,b=(S<=0?0:S)*l,O=g.length>0?r:0;h.width+O+b>c&&(m(),v()),null===p&&(p=h.width,d=t),g.length>0&&(x+=r,h.width+=r),g.push({char:T,x:x}),h.lineAscent=Math.max(h.lineAscent||0,f),h.lineDescent=Math.max(h.lineDescent||0,y),x+=b,h.width+=b}m()})),v();var y=1/0,w=-1/0;if(0===a.length)return{lines:a,maxLineWidth:u,totalHeight:f,bboxTop:0,bboxBottom:0,bboxHeight:0};for(var T=0;T<a.length;T++){var S=a[T].lineAscent||0,b=a[T].lineDescent||0,O=(l-(S+b))/2;y=Math.min(y,s[T]-S-O),w=Math.max(w,s[T]+b+O)}return{lines:a,maxLineWidth:u,totalHeight:f,bboxTop:y,bboxBottom:w,bboxHeight:w-y}},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.resolveCanvas=function(t,e,i,n,r){return{canvasWidth:Math.max(1,Math.ceil(e)),canvasHeight:Math.max(1,Math.ceil(i)),renderOffsetX:0,renderOffsetY:0}},t}(),M=function(){function t(){}return t.prototype.resolveCanvas=function(t,e,i,n,r){if(0===t.length)return{canvasWidth:Math.max(1,e),canvasHeight:Math.max(1,i),renderOffsetX:0,renderOffsetY:0};for(var o=1/0,a=-1/0,s=r.baselineY,l=0;l<t.length;l++){var c,h,u=null!=(c=t[l].lineAscent)?c:0,f=null!=(h=t[l].lineDescent)?h:0,p=u+f,x=Math.max(0,(t[l].lineHeight-p)/2);o=Math.min(o,s-u-x),a=Math.max(a,s+f+x),l<t.length-1&&(s+=t[l+1].lineHeight)}for(var g=Math.max(0,-o),d=Math.max(0,a-i),v=Math.max(g,d),m=1/0,y=-1/0,w=0;w<t.length;w++){var T,S,b=null!=(T=n.lineOffsets[w])?T:0,O=null!=(S=t[w].width)?S:0;m=Math.min(m,b),y=Math.max(y,b+O)}isFinite(m)||(m=0),isFinite(y)||(y=0);var A=Math.max(0,-m),M=Math.max(0,y-e),H=Math.max(A,M),z=Math.ceil(e+2*H),E=Math.ceil(i+2*v);return{canvasWidth:Math.max(1,z),canvasHeight:Math.max(1,E),renderOffsetX:H,renderOffsetY:v}},t}(),H=function(){function t(){}return t.prototype.getHorizontalOffsets=function(t,e,i,n){return{lineOffsets:t.map((function(t){return i.getOffsetXRich(n,e,t.width)}))}},t}(),z=function(){function e(){}return e.prototype.getVerticalOffsets=function(e,i,n){if(0===e.length)return{baselineY:0,lineYOffsets:[]};for(var r=[0],o=1;o<e.length;o++)r[o]=r[o-1]+e[o].lineHeight;for(var a=1/0,s=-1/0,l=0;l<e.length;l++){var c,h,u=null!=(c=e[l].lineAscent)?c:0,f=null!=(h=e[l].lineDescent)?h:0,p=u+f,x=(e[l].lineHeight-p)/2;a=Math.min(a,r[l]-u-x),s=Math.max(s,r[l]+f+x)}var g=s-a,d=0;switch(n.textVerticalAlign){case t.spec.TextVerticalAlign.top:d=-a;break;case t.spec.TextVerticalAlign.middle:d=(i-g)/2-a;break;case t.spec.TextVerticalAlign.bottom:d=i-g-a}var v=r.map((function(t){return d+t}));return{baselineY:d,lineYOffsets:v}},e}(),E=function(){function e(){}return e.createWrapStrategy=function(t){return t?new O:new b},e.createOverflowStrategy=function(e){switch(e){case t.spec.TextOverflow.clip:return new A;case t.spec.TextOverflow.display:case t.spec.TextOverflow.visible:default:return new M}},e.createHorizontalAlignStrategy=function(){return new H},e.createVerticalAlignStrategy=function(){return new z},e}();function L(){return L=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var i=arguments[e];for(var n in i)Object.prototype.hasOwnProperty.call(i,n)&&(t[n]=i[n])}return t},L.apply(this,arguments)}var 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=.11092565,n.ALPHA_FIX_VALUE=1/255,n.name="MRichText"+W++,n.initTextBase(i),n.richWrapStrategy=E.createWrapStrategy(),n.richOverflowStrategy=E.createOverflowStrategy(t.spec.TextOverflow.display),n.richHorizontalAlignStrategy=E.createHorizontalAlignStrategy(),n.richVerticalAlignStrategy=E.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 w(r),this.text=r.text?r.text.toString():" ",this.textLayout.useLegacyRichText&&(this.textLayout.textVerticalAlign=t.spec.TextVerticalAlign.middle),this.updateStrategies(),this.updateTexture(),this.material.setColor("_Color",new t.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(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=S(n.color)),i.processedTextOptions.push(o)}))}));n(e)},n.updateWithOptions=function(e){this.textStyle=new t.TextStyle(e),this.textLayout=new w(e),this.text=e.text?e.text.toString():" ",this.textLayout.useLegacyRichText&&(this.textLayout.textVerticalAlign=t.spec.TextVerticalAlign.middle),this.updateStrategies(),this.isDirty=!0},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){var n=.1;this.generateTextProgram(this.text);var r=0,o=0,a=this.textLayout,s=this.textStyle,l=a.overflow,c=a.letterSpace,h=void 0===c?0:c,u=this.context,f=[],p=s.fontSize*s.fontScale,x={richOptions:[],offsetX:[],width:0,lineHeight:p*this.singleLineHeight,offsetY:p*(this.singleLineHeight-1)/2};if(this.processedTextOptions.forEach((function(t){var e=t.text,a=t.isNewLine,l=t.fontSize;a&&(f.push(x),r=Math.max(r,x.width),x={richOptions:[],offsetX:[],width:0,lineHeight:p*i.singleLineHeight,offsetY:p*(i.singleLineHeight-1)/2},o+=x.lineHeight),u.font=(t.fontWeight||s.textWeight)+" 10px "+(t.fontFamily||s.fontFamily);var c=u.measureText(e),g=c.width;if(void 0!==c.actualBoundingBoxLeft&&void 0!==c.actualBoundingBoxRight){var d=c.actualBoundingBoxLeft+c.actualBoundingBoxRight;d>0&&(g=Math.max(g,d))}var v=l*i.singleLineHeight*s.fontScale;v>x.lineHeight&&(o+=v-x.lineHeight,x.lineHeight=v,x.offsetY=l*s.fontScale*(i.singleLineHeight-1)/2),x.offsetX.push(x.width),x.width+=(g<=0?0:g)*l*n*s.fontScale+e.length*h,x.richOptions.push(t)})),f.push(x),r=Math.max(r,x.width),o+=x.lineHeight,0!==r&&0!==o){void 0!==this.size&&null!==this.size||(this.size=this.item.transform.size.clone());var g=this.size,d=g.x,v=void 0===d?1:d,m=g.y,y=void 0===m?1:m;if(!this.initialized){this.canvasSize=this.canvasSize?this.canvasSize:new t.math.Vector2(r,o);var w=this.canvasSize,T=w.x,S=w.y;this.item.transform.size.set(v*T*n*n,y*S*n*n),this.size=this.item.transform.size.clone(),this.initialized=!0}t.assertExist(this.canvasSize);var b=this.canvasSize,O=b.x,A=b.y;a.width=O/s.fontScale,a.height=A/s.fontScale,this.renderToTexture(O,A,e,(function(e){if(0!==f.length){var n=a.getOffsetY(s,f.length,p*i.singleLineHeight,s.fontSize);f.forEach((function(i,r){var o=i.richOptions,c=i.offsetX,h=i.width,u=h,f=c;if(l===t.spec.TextOverflow.display&&h>O){var p=O/h;u*=p,f=c.map((function(t){return t*p}))}var x=a.getOffsetX(s,u);r>0&&(n+=i.lineHeight-i.offsetY),o.forEach((function(i,r){var o=s.fontScale,a=s.textColor,c=s.fontFamily,u=s.textWeight,p=s.fontStyle,g=i.text,d=i.fontSize,v=i.fontColor,m=void 0===v?a:v,y=i.fontFamily,w=void 0===y?c:y,T=i.fontWeight,S=void 0===T?u:T,b=i.fontStyle,A=void 0===b?p:b,M=d;l===t.spec.TextOverflow.display&&h>O&&(M/=h/O);var H=f[r]+x;e.font=A+" "+S+" "+M*o+"px "+w;var z=m[0],E=m[1],L=m[2],W=m[3];e.fillStyle="rgba("+z+", "+E+", "+L+", "+W+")",e.fillText(g,H,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.updateStrategies(),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.textStyle.fontScale;n.autoResize===t.spec.TextSizeMode.autoWidth&&(n.maxTextWidth=Number.MAX_SAFE_INTEGER);var l,c,h=this.richWrapStrategy.computeLines(this.processedTextOptions,a,this.textStyle,n,o);switch(n.autoResize){case t.spec.TextSizeMode.autoWidth:l=Math.max(1,h.maxLineWidth||0),c=Math.max(1,h.totalHeight||0);break;case t.spec.TextSizeMode.autoHeight:l=n.maxTextWidth,c=Math.max(1,h.totalHeight||0);break;case t.spec.TextSizeMode.fixed:default:l=n.maxTextWidth,c=n.maxTextHeight}if(n.overflow===t.spec.TextOverflow.display){var u=Math.max(1,h.maxLineWidth||0),f=Math.max(1,h.totalHeight||0);!function(t,e,i,n,r){var o=function(t,e){return Math.abs(e)>1e-5?t/e:1},a=Math.max(1,e),s=Math.max(1,i),l=Math.min(1,o(n,a),o(r,s));if(!(l>.9999))for(var c,h=p(t);!(c=h()).done;){var u=c.value;if(u.width*=l,u.lineHeight*=l,u.offsetX)for(var f=0;f<u.offsetX.length;f++)u.offsetX[f]*=l;for(var x,g=p(u.chars||[]);!(x=g()).done;)for(var d,v=p(x.value);!(d=v()).done;)d.value.x*=l;for(var m=u.richOptions||[],y=[],w=0;w<m.length;w++)y.push(L({},m[w],{fontSize:m[w].fontSize*l}));u.richOptions=y,null!=u.lineAscent&&(u.lineAscent*=l),null!=u.lineDescent&&(u.lineDescent*=l)}}(h.lines,u,f,l,c)}var x=this.richHorizontalAlignStrategy.getHorizontalOffsets(h.lines,l,n,this.textStyle),g=this.richVerticalAlignStrategy.getVerticalOffsets(h.lines,c,n),d=this.richOverflowStrategy.resolveCanvas(h.lines,l,c,x,g),v=Math.max(1,Math.ceil(d.canvasWidth*s)),m=Math.max(1,Math.ceil(d.canvasHeight*s));this.item.transform.size.set(d.canvasWidth*this.SCALE_FACTOR*this.SCALE_FACTOR,d.canvasHeight*this.SCALE_FACTOR*this.SCALE_FACTOR),n.maxTextWidth=l,n.maxTextHeight=c,n.width=d.canvasWidth,n.height=d.canvasHeight,this.renderToTexture(v,m,e,(function(t){t.scale(s,s),i.drawTextWithStrategies(t,h.lines,x,g,d,i.textStyle)}),{disposeOld:!1}),this.isDirty=!1}}},n.drawTextWithStrategies=function(t,e,i,n,r,o){var a=r.renderOffsetX,s=r.renderOffsetY,l=n.baselineY+s,c=i.lineOffsets;e.forEach((function(i,n){var r=i.richOptions,s=i.chars,h=c[n]+a,u=l;r.forEach((function(e,n){var r=o.textColor,a=o.fontFamily,l=o.textWeight,c=o.fontStyle,f=e.fontSize,p=e.fontColor,x=void 0===p?r:p,g=e.fontFamily,d=void 0===g?a:g,v=e.fontWeight,m=void 0===v?l:v,y=e.fontStyle,w=void 0===y?c:y,T=f;t.font=w+" "+m+" "+T+"px "+d;var S=x[0],b=x[1],O=x[2],A=x[3];t.fillStyle="rgba("+S+", "+b+", "+O+", "+A+")";var M=i.offsetX&&i.offsetX[n]?i.offsetX[n]:0;s[n].forEach((function(e){t.fillText(e.char,h+M+e.x,u)}))})),n<e.length-1&&(l+=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 C="2.9.1";t.registerPlugin("rich-text",u),t.logger.info("Plugin rich text version: 2.9.1."),C!==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=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 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=v,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=C;
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 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]+)>$/,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 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=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});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 w=function(){function e(e){this.width=0,this.height=0;var i=e.textOverflow,n=void 0===i?t.spec.TextOverflow.clip:i,r=e.textVerticalAlign,o=void 0===r?t.spec.TextVerticalAlign.middle:r,a=e.textAlign,s=void 0===a?t.spec.TextAlignment.left:a,l=e.letterSpace,c=void 0===l?0:l,h=e.lineHeight,u=void 0===h?.571:h,f=e.wrapEnabled,p=void 0!==f&&f,x=e.maxTextWidth,g=void 0===x?350:x,d=e.maxTextHeight,v=void 0===d?1e3:d,m=e.autoResize,y=void 0===m?t.spec.TextSizeMode.autoWidth:m,w=e.useLegacyRichText,T=void 0!==w&&w;this.letterSpace=c,this.lineHeight=u,this.useLegacyRichText=T,this.overflow=n,this.textVerticalAlign=o,this.textAlign=s,this.width=100,this.height=100,this.wrapEnabled=p,this.maxTextWidth=g,this.maxTextHeight=v,this.autoResize=y}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;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 S(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){var o=this,a=[],s=[],l=n.lineHeight||0,c=this.createNewLine(),h=0,u=0,f=function(){if(0!==c.chars.length){c.lineHeight=l;var t=0===a.length?0:s[s.length-1]+l;s.push(t),u+=c.lineHeight,a.push(c),h=Math.max(h,c.width),c=o.createNewLine()}};t.forEach((function(t){var n=t.text,o=t.isNewLine,a=t.fontSize;o&&f();var s=t.fontStyle||i.fontStyle||"normal";e.font=s+" "+(t.fontWeight||i.textWeight)+" 10px "+(t.fontFamily||i.fontFamily),c.offsetX.push(c.width);for(var l=.1*a,h=e.measureText("x"),u=h.fontBoundingBoxAscent*l,p=h.fontBoundingBoxDescent*l,x=0,g=[],d=0;d<n.length;d++){var v=n[d],m=e.measureText(v).width,y=(m<=0?0:m)*l;d>0&&(x+=r),g.push({char:v,x:x}),x+=y}c.chars.push(g),c.width+=x,c.richOptions.push(t),c.lineAscent=Math.max(c.lineAscent||0,u),c.lineDescent=Math.max(c.lineDescent||0,p)})),f();var p=1/0,x=-1/0;if(0===a.length)return{lines:a,maxLineWidth:h,totalHeight:u,bboxTop:0,bboxBottom:0,bboxHeight:0};for(var g=0;g<a.length;g++){var d=a[g].lineAscent||0,v=a[g].lineDescent||0,m=(l-(d+v))/2;p=Math.min(p,s[g]-d-m),x=Math.max(x,s[g]+v+m)}return{lines:a,maxLineWidth:h,totalHeight:u,bboxTop:p,bboxBottom:x,bboxHeight:x-p}},e.createNewLine=function(){return{richOptions:[],offsetX:[],width:0,lineHeight:0,offsetY:0,chars:[],lineAscent:0,lineDescent:0}},t}(),O=function(){function t(){}var e=t.prototype;return e.computeLines=function(t,e,i,n,r){var o=this,a=[],s=[],l=n.lineHeight||0,c=n.maxTextWidth||1/0,h=this.createNewLine(),u=0,f=0,p=null,x=0,g=[],d=null,v=function(){if(m(),0!==h.chars.length){h.lineHeight=l;var t=0===a.length?0:s[s.length-1]+l;s.push(t),f+=h.lineHeight,a.push(h),u=Math.max(u,h.width),h=o.createNewLine(),p=null,x=0,g=[],d=null}},m=function(){0!==g.length&&(null===p&&(p=h.width),h.offsetX.push(p),h.chars.push(g),d&&h.richOptions.push(d),p=null,x=0,g=[],d=null)};t.forEach((function(t){var n=t.text,o=t.isNewLine,a=t.fontSize,s=t.fontStyle||i.fontStyle||"normal";e.font=s+" "+(t.fontWeight||i.textWeight)+" 10px "+(t.fontFamily||i.fontFamily),o&&(m(),v());for(var l=.1*a,u=e.measureText("x"),f=u.fontBoundingBoxAscent*l,y=u.fontBoundingBoxDescent*l,w=0;w<n.length;w++){var T=n[w],S=e.measureText(T).width,b=(S<=0?0:S)*l,O=g.length>0?r:0;h.width+O+b>c&&(m(),v()),null===p&&(p=h.width,d=t),g.length>0&&(x+=r,h.width+=r),g.push({char:T,x:x}),h.lineAscent=Math.max(h.lineAscent||0,f),h.lineDescent=Math.max(h.lineDescent||0,y),x+=b,h.width+=b}m()})),v();var y=1/0,w=-1/0;if(0===a.length)return{lines:a,maxLineWidth:u,totalHeight:f,bboxTop:0,bboxBottom:0,bboxHeight:0};for(var T=0;T<a.length;T++){var S=a[T].lineAscent||0,b=a[T].lineDescent||0,O=(l-(S+b))/2;y=Math.min(y,s[T]-S-O),w=Math.max(w,s[T]+b+O)}return{lines:a,maxLineWidth:u,totalHeight:f,bboxTop:y,bboxBottom:w,bboxHeight:w-y}},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.resolveCanvas=function(t,e,i,n,r){return{canvasWidth:Math.max(1,Math.ceil(e)),canvasHeight:Math.max(1,Math.ceil(i)),renderOffsetX:0,renderOffsetY:0}},t}(),M=function(){function t(){}return t.prototype.resolveCanvas=function(t,e,i,n,r){if(0===t.length)return{canvasWidth:Math.max(1,e),canvasHeight:Math.max(1,i),renderOffsetX:0,renderOffsetY:0};for(var o=1/0,a=-1/0,s=r.baselineY,l=0;l<t.length;l++){var c,h,u=null!=(c=t[l].lineAscent)?c:0,f=null!=(h=t[l].lineDescent)?h:0,p=u+f,x=Math.max(0,(t[l].lineHeight-p)/2);o=Math.min(o,s-u-x),a=Math.max(a,s+f+x),l<t.length-1&&(s+=t[l+1].lineHeight)}for(var g=Math.max(0,-o),d=Math.max(0,a-i),v=Math.max(g,d),m=1/0,y=-1/0,w=0;w<t.length;w++){var T,S,b=null!=(T=n.lineOffsets[w])?T:0,O=null!=(S=t[w].width)?S:0;m=Math.min(m,b),y=Math.max(y,b+O)}isFinite(m)||(m=0),isFinite(y)||(y=0);var A=Math.max(0,-m),M=Math.max(0,y-e),H=Math.max(A,M),z=Math.ceil(e+2*H),E=Math.ceil(i+2*v);return{canvasWidth:Math.max(1,z),canvasHeight:Math.max(1,E),renderOffsetX:H,renderOffsetY:v}},t}(),H=function(){function t(){}return t.prototype.getHorizontalOffsets=function(t,e,i,n){return{lineOffsets:t.map((function(t){return i.getOffsetXRich(n,e,t.width)}))}},t}(),z=function(){function e(){}return e.prototype.getVerticalOffsets=function(e,i,n){if(0===e.length)return{baselineY:0,lineYOffsets:[]};for(var r=[0],o=1;o<e.length;o++)r[o]=r[o-1]+e[o].lineHeight;for(var a=1/0,s=-1/0,l=0;l<e.length;l++){var c,h,u=null!=(c=e[l].lineAscent)?c:0,f=null!=(h=e[l].lineDescent)?h:0,p=u+f,x=(e[l].lineHeight-p)/2;a=Math.min(a,r[l]-u-x),s=Math.max(s,r[l]+f+x)}var g=s-a,d=0;switch(n.textVerticalAlign){case t.spec.TextVerticalAlign.top:d=-a;break;case t.spec.TextVerticalAlign.middle:d=(i-g)/2-a;break;case t.spec.TextVerticalAlign.bottom:d=i-g-a}var v=r.map((function(t){return d+t}));return{baselineY:d,lineYOffsets:v}},e}(),E=function(){function e(){}return e.createWrapStrategy=function(t){return t?new O:new b},e.createOverflowStrategy=function(e){switch(e){case t.spec.TextOverflow.clip:return new A;case t.spec.TextOverflow.display:case t.spec.TextOverflow.visible:default:return new M}},e.createHorizontalAlignStrategy=function(){return new H},e.createVerticalAlignStrategy=function(){return new z},e}();function L(){return L=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var i=arguments[e];for(var n in i)Object.prototype.hasOwnProperty.call(i,n)&&(t[n]=i[n])}return t},L.apply(this,arguments)}var 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=.11092565,n.ALPHA_FIX_VALUE=1/255,n.name="MRichText"+W++,n.initTextBase(i),n.richWrapStrategy=E.createWrapStrategy(),n.richOverflowStrategy=E.createOverflowStrategy(t.spec.TextOverflow.display),n.richHorizontalAlignStrategy=E.createHorizontalAlignStrategy(),n.richVerticalAlignStrategy=E.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 w(r),this.text=r.text?r.text.toString():" ",this.textLayout.useLegacyRichText&&(this.textLayout.textVerticalAlign=t.spec.TextVerticalAlign.middle),this.updateStrategies(),this.updateTexture(),this.material.setColor("_Color",new t.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(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=S(n.color)),i.processedTextOptions.push(o)}))}));n(e)},n.updateWithOptions=function(e){this.textStyle=new t.TextStyle(e),this.textLayout=new w(e),this.text=e.text?e.text.toString():" ",this.textLayout.useLegacyRichText&&(this.textLayout.textVerticalAlign=t.spec.TextVerticalAlign.middle),this.updateStrategies(),this.isDirty=!0},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){var n=.1;this.generateTextProgram(this.text);var r=0,o=0,a=this.textLayout,s=this.textStyle,l=a.overflow,c=a.letterSpace,h=void 0===c?0:c,u=this.context,f=[],p=s.fontSize*s.fontScale,x={richOptions:[],offsetX:[],width:0,lineHeight:p*this.singleLineHeight,offsetY:p*(this.singleLineHeight-1)/2};if(this.processedTextOptions.forEach((function(t){var e=t.text,a=t.isNewLine,l=t.fontSize;a&&(f.push(x),r=Math.max(r,x.width),x={richOptions:[],offsetX:[],width:0,lineHeight:p*i.singleLineHeight,offsetY:p*(i.singleLineHeight-1)/2},o+=x.lineHeight),u.font=(t.fontWeight||s.textWeight)+" 10px "+(t.fontFamily||s.fontFamily);var c=u.measureText(e),g=c.width;if(void 0!==c.actualBoundingBoxLeft&&void 0!==c.actualBoundingBoxRight){var d=c.actualBoundingBoxLeft+c.actualBoundingBoxRight;d>0&&(g=Math.max(g,d))}var v=l*i.singleLineHeight*s.fontScale;v>x.lineHeight&&(o+=v-x.lineHeight,x.lineHeight=v,x.offsetY=l*s.fontScale*(i.singleLineHeight-1)/2),x.offsetX.push(x.width),x.width+=(g<=0?0:g)*l*n*s.fontScale+e.length*h,x.richOptions.push(t)})),f.push(x),r=Math.max(r,x.width),o+=x.lineHeight,0!==r&&0!==o){void 0!==this.size&&null!==this.size||(this.size=this.item.transform.size.clone());var g=this.size,d=g.x,v=void 0===d?1:d,m=g.y,y=void 0===m?1:m;if(!this.initialized){this.canvasSize=this.canvasSize?this.canvasSize:new t.math.Vector2(r,o);var w=this.canvasSize,T=w.x,S=w.y;this.item.transform.size.set(v*T*n*n,y*S*n*n),this.size=this.item.transform.size.clone(),this.initialized=!0}t.assertExist(this.canvasSize);var b=this.canvasSize,O=b.x,A=b.y;a.width=O/s.fontScale,a.height=A/s.fontScale,this.renderToTexture(O,A,e,(function(e){if(0!==f.length){var n=a.getOffsetY(s,f.length,p*i.singleLineHeight,s.fontSize);f.forEach((function(i,r){var o=i.richOptions,c=i.offsetX,h=i.width,u=h,f=c;if(l===t.spec.TextOverflow.display&&h>O){var p=O/h;u*=p,f=c.map((function(t){return t*p}))}var x=a.getOffsetX(s,u);r>0&&(n+=i.lineHeight-i.offsetY),o.forEach((function(i,r){var o=s.fontScale,a=s.textColor,c=s.fontFamily,u=s.textWeight,p=s.fontStyle,g=i.text,d=i.fontSize,v=i.fontColor,m=void 0===v?a:v,y=i.fontFamily,w=void 0===y?c:y,T=i.fontWeight,S=void 0===T?u:T,b=i.fontStyle,A=void 0===b?p:b,M=d;l===t.spec.TextOverflow.display&&h>O&&(M/=h/O);var H=f[r]+x;e.font=A+" "+S+" "+M*o+"px "+w;var z=m[0],E=m[1],L=m[2],W=m[3];e.fillStyle="rgba("+z+", "+E+", "+L+", "+W+")",e.fillText(g,H,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.updateStrategies(),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.textStyle.fontScale;n.autoResize===t.spec.TextSizeMode.autoWidth&&(n.maxTextWidth=Number.MAX_SAFE_INTEGER);var l,c,h=this.richWrapStrategy.computeLines(this.processedTextOptions,a,this.textStyle,n,o);switch(n.autoResize){case t.spec.TextSizeMode.autoWidth:l=Math.max(1,h.maxLineWidth||0),c=Math.max(1,h.totalHeight||0);break;case t.spec.TextSizeMode.autoHeight:l=n.maxTextWidth,c=Math.max(1,h.totalHeight||0);break;case t.spec.TextSizeMode.fixed:default:l=n.maxTextWidth,c=n.maxTextHeight}if(n.overflow===t.spec.TextOverflow.display){var u=Math.max(1,h.maxLineWidth||0),f=Math.max(1,h.totalHeight||0);!function(t,e,i,n,r){var o=function(t,e){return Math.abs(e)>1e-5?t/e:1},a=Math.max(1,e),s=Math.max(1,i),l=Math.min(1,o(n,a),o(r,s));if(!(l>.9999))for(var c,h=p(t);!(c=h()).done;){var u=c.value;if(u.width*=l,u.lineHeight*=l,u.offsetX)for(var f=0;f<u.offsetX.length;f++)u.offsetX[f]*=l;for(var x,g=p(u.chars||[]);!(x=g()).done;)for(var d,v=p(x.value);!(d=v()).done;)d.value.x*=l;for(var m=u.richOptions||[],y=[],w=0;w<m.length;w++)y.push(L({},m[w],{fontSize:m[w].fontSize*l}));u.richOptions=y,null!=u.lineAscent&&(u.lineAscent*=l),null!=u.lineDescent&&(u.lineDescent*=l)}}(h.lines,u,f,l,c)}var x=this.richHorizontalAlignStrategy.getHorizontalOffsets(h.lines,l,n,this.textStyle),g=this.richVerticalAlignStrategy.getVerticalOffsets(h.lines,c,n),d=this.richOverflowStrategy.resolveCanvas(h.lines,l,c,x,g),v=Math.max(1,Math.ceil(d.canvasWidth*s)),m=Math.max(1,Math.ceil(d.canvasHeight*s));this.item.transform.size.set(d.canvasWidth*this.SCALE_FACTOR*this.SCALE_FACTOR,d.canvasHeight*this.SCALE_FACTOR*this.SCALE_FACTOR),n.maxTextWidth=l,n.maxTextHeight=c,n.width=d.canvasWidth,n.height=d.canvasHeight,this.renderToTexture(v,m,e,(function(t){t.scale(s,s),i.drawTextWithStrategies(t,h.lines,x,g,d,i.textStyle)}),{disposeOld:!1}),this.isDirty=!1}}},n.drawTextWithStrategies=function(t,e,i,n,r,o){var a=r.renderOffsetX,s=r.renderOffsetY,l=n.baselineY+s,c=i.lineOffsets;e.forEach((function(i,n){var r=i.richOptions,s=i.chars,h=c[n]+a,u=l;r.forEach((function(e,n){var r=o.textColor,a=o.fontFamily,l=o.textWeight,c=o.fontStyle,f=e.fontSize,p=e.fontColor,x=void 0===p?r:p,g=e.fontFamily,d=void 0===g?a:g,v=e.fontWeight,m=void 0===v?l:v,y=e.fontStyle,w=void 0===y?c:y,T=f;t.font=w+" "+m+" "+T+"px "+d;var S=x[0],b=x[1],O=x[2],A=x[3];t.fillStyle="rgba("+S+", "+b+", "+O+", "+A+")";var M=i.offsetX&&i.offsetX[n]?i.offsetX[n]:0;s[n].forEach((function(e){t.fillText(e.char,h+M+e.x,u)}))})),n<e.length-1&&(l+=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 C="2.9.2";t.registerPlugin("rich-text",u),t.logger.info("Plugin rich text version: 2.9.2."),C!==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=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 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=v,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=C;
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 s,assertExist as l,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 d(t,e,i){return d=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},d.apply(null,arguments)}function v(t){return v=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},v(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 d(t,arguments,v(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,w=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 S(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 S(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)?S(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]+)(=([^>]+))?>$/,O=/^<\/([a-z]+)>$/,A=[["EscapedChar",/^\\([=<>\\/])/],["ContextStart",/^<[a-z]+(=[^>]+)?>/],["ContextEnd",/^<\/[a-z]+>/],["Text",/^[^</>=\\]+/]],H=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 H(t.slice(2),e.concat({tokenType:"Text",value:r}),i+2)}for(var a,o=T(A);!(a=o()).done;){var s=a.value,l=s[0],h=s[1];if("EscapedChar"!==l){var c=h.exec(t);if(c){var f=c[0],u=f.length;return H(t.slice(u),e.concat({tokenType:l,value:f}),i+u)}}}if(t.length>0)return H(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(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=s();if("ContextEnd"===(null==t?void 0:t.tokenType)){o();var e=t.value.match(O);if(e)return{attributeName:e[1]};throw new Error("Expect an end tag marker at position "+a)}return{}},r=H(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 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)}}}(),l};function z(t){return function(e){for(var i,n=T(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 L(t){var e=H(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(O)[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 C=function(){function t(t){this.width=0,this.height=0;var e=t.textOverflow,n=void 0===e?i.TextOverflow.clip:e,r=t.textVerticalAlign,a=void 0===r?i.TextVerticalAlign.middle:r,o=t.textAlign,s=void 0===o?i.TextAlignment.left:o,l=t.letterSpace,h=void 0===l?0:l,c=t.lineHeight,f=void 0===c?.571:c,u=t.wrapEnabled,g=void 0!==u&&u,x=t.maxTextWidth,p=void 0===x?350:x,d=t.maxTextHeight,v=void 0===d?1e3:d,m=t.autoResize,y=void 0===m?i.TextSizeMode.autoWidth:m,w=t.useLegacyRichText,S=void 0!==w&&w;this.letterSpace=h,this.lineHeight=f,this.useLegacyRichText=S,this.overflow=n,this.textVerticalAlign=a,this.textAlign=s,this.width=100,this.height=100,this.wrapEnabled=g,this.maxTextWidth=p,this.maxTextHeight=v,this.autoResize=y}var e=t.prototype;return e.getOffsetY=function(t,e,n,r,a){var o=t.outlineWidth,s=t.fontScale,l=(n-r)/3,h=r+o*s,c=void 0!==a?a:n*(e-1),f=0;switch(this.textVerticalAlign){case i.TextVerticalAlign.top:f=h+l;break;case i.TextVerticalAlign.middle:f=(this.height*s-c+h)/2;break;case i.TextVerticalAlign.bottom:f=this.height*s-c-l}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),s=(e[0]-n)/3,l=n+r*a,h=o-e[0],c=0;switch(this.textVerticalAlign){case i.TextVerticalAlign.top:c=l+s;break;case i.TextVerticalAlign.middle:c=(this.height*a-o)/2+l;break;case i.TextVerticalAlign.bottom:c=this.height*a-h-s}return c},e.getOffsetXRich=function(t,e,n){switch(this.textAlign){case i.TextAlignment.left:return t.outlineWidth;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 k(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 R(t,e){if(void 0===e&&(e=1),"string"!=typeof t||!t)throw new Error("Invalid color string");return t.startsWith("#")?k(t,e):k(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 V=function(){function t(){}var e=t.prototype;return e.computeLines=function(t,e,i,n,r){var a=this,o=[],s=[],l=n.lineHeight||0,h=this.createNewLine(),c=0,f=0,u=function(){if(0!==h.chars.length){h.lineHeight=l;var t=0===o.length?0:s[s.length-1]+l;s.push(t),f+=h.lineHeight,o.push(h),c=Math.max(c,h.width),h=a.createNewLine()}};t.forEach((function(t){var n=t.text,a=t.isNewLine,o=t.fontSize;a&&u();var s=t.fontStyle||i.fontStyle||"normal";e.font=s+" "+(t.fontWeight||i.textWeight)+" 10px "+(t.fontFamily||i.fontFamily),h.offsetX.push(h.width);for(var l=.1*o,c=e.measureText("x"),f=c.fontBoundingBoxAscent*l,g=c.fontBoundingBoxDescent*l,x=0,p=[],d=0;d<n.length;d++){var v=n[d],m=e.measureText(v).width,y=(m<=0?0:m)*l;d>0&&(x+=r),p.push({char:v,x:x}),x+=y}h.chars.push(p),h.width+=x,h.richOptions.push(t),h.lineAscent=Math.max(h.lineAscent||0,f),h.lineDescent=Math.max(h.lineDescent||0,g)})),u();var g=1/0,x=-1/0;if(0===o.length)return{lines:o,maxLineWidth:c,totalHeight:f,bboxTop:0,bboxBottom:0,bboxHeight:0};for(var p=0;p<o.length;p++){var d=o[p].lineAscent||0,v=o[p].lineDescent||0,m=(l-(d+v))/2;g=Math.min(g,s[p]-d-m),x=Math.max(x,s[p]+v+m)}return{lines:o,maxLineWidth:c,totalHeight:f,bboxTop:g,bboxBottom:x,bboxHeight:x-g}},e.createNewLine=function(){return{richOptions:[],offsetX:[],width:0,lineHeight:0,offsetY:0,chars:[],lineAscent:0,lineDescent:0}},t}(),D=function(){function t(){}var e=t.prototype;return e.computeLines=function(t,e,i,n,r){var a=this,o=[],s=[],l=n.lineHeight||0,h=n.maxTextWidth||1/0,c=this.createNewLine(),f=0,u=0,g=null,x=0,p=[],d=null,v=function(){if(m(),0!==c.chars.length){c.lineHeight=l;var t=0===o.length?0:s[s.length-1]+l;s.push(t),u+=c.lineHeight,o.push(c),f=Math.max(f,c.width),c=a.createNewLine(),g=null,x=0,p=[],d=null}},m=function(){0!==p.length&&(null===g&&(g=c.width),c.offsetX.push(g),c.chars.push(p),d&&c.richOptions.push(d),g=null,x=0,p=[],d=null)};t.forEach((function(t){var n=t.text,a=t.isNewLine,o=t.fontSize,s=t.fontStyle||i.fontStyle||"normal";e.font=s+" "+(t.fontWeight||i.textWeight)+" 10px "+(t.fontFamily||i.fontFamily),a&&(m(),v());for(var l=.1*o,f=e.measureText("x"),u=f.fontBoundingBoxAscent*l,y=f.fontBoundingBoxDescent*l,w=0;w<n.length;w++){var S=n[w],T=e.measureText(S).width,b=(T<=0?0:T)*l,O=p.length>0?r:0;c.width+O+b>h&&(m(),v()),null===g&&(g=c.width,d=t),p.length>0&&(x+=r,c.width+=r),p.push({char:S,x:x}),c.lineAscent=Math.max(c.lineAscent||0,u),c.lineDescent=Math.max(c.lineDescent||0,y),x+=b,c.width+=b}m()})),v();var y=1/0,w=-1/0;if(0===o.length)return{lines:o,maxLineWidth:f,totalHeight:u,bboxTop:0,bboxBottom:0,bboxHeight:0};for(var S=0;S<o.length;S++){var T=o[S].lineAscent||0,b=o[S].lineDescent||0,O=(l-(T+b))/2;y=Math.min(y,s[S]-T-O),w=Math.max(w,s[S]+b+O)}return{lines:o,maxLineWidth:f,totalHeight:u,bboxTop:y,bboxBottom:w,bboxHeight:w-y}},e.createNewLine=function(){return{richOptions:[],offsetX:[],width:0,lineHeight:0,offsetY:0,chars:[],lineAscent:0,lineDescent:0}},t}(),B=function(){function t(){}return t.prototype.resolveCanvas=function(t,e,i,n,r){return{canvasWidth:Math.max(1,Math.ceil(e)),canvasHeight:Math.max(1,Math.ceil(i)),renderOffsetX:0,renderOffsetY:0}},t}(),X=function(){function t(){}return t.prototype.resolveCanvas=function(t,e,i,n,r){if(0===t.length)return{canvasWidth:Math.max(1,e),canvasHeight:Math.max(1,i),renderOffsetX:0,renderOffsetY:0};for(var a=1/0,o=-1/0,s=r.baselineY,l=0;l<t.length;l++){var h,c,f=null!=(h=t[l].lineAscent)?h:0,u=null!=(c=t[l].lineDescent)?c:0,g=f+u,x=Math.max(0,(t[l].lineHeight-g)/2);a=Math.min(a,s-f-x),o=Math.max(o,s+u+x),l<t.length-1&&(s+=t[l+1].lineHeight)}for(var p=Math.max(0,-a),d=Math.max(0,o-i),v=Math.max(p,d),m=1/0,y=-1/0,w=0;w<t.length;w++){var S,T,b=null!=(S=n.lineOffsets[w])?S:0,O=null!=(T=t[w].width)?T:0;m=Math.min(m,b),y=Math.max(y,b+O)}isFinite(m)||(m=0),isFinite(y)||(y=0);var A=Math.max(0,-m),H=Math.max(0,y-e),M=Math.max(A,H),z=Math.ceil(e+2*M),L=Math.ceil(i+2*v);return{canvasWidth:Math.max(1,z),canvasHeight:Math.max(1,L),renderOffsetX:M,renderOffsetY:v}},t}(),F=function(){function t(){}return t.prototype.getHorizontalOffsets=function(t,e,i,n){return{lineOffsets:t.map((function(t){return i.getOffsetXRich(n,e,t.width)}))}},t}(),Y=function(){function t(){}return t.prototype.getVerticalOffsets=function(t,e,n){if(0===t.length)return{baselineY:0,lineYOffsets:[]};for(var r=[0],a=1;a<t.length;a++)r[a]=r[a-1]+t[a].lineHeight;for(var o=1/0,s=-1/0,l=0;l<t.length;l++){var h,c,f=null!=(h=t[l].lineAscent)?h:0,u=null!=(c=t[l].lineDescent)?c:0,g=f+u,x=(t[l].lineHeight-g)/2;o=Math.min(o,r[l]-f-x),s=Math.max(s,r[l]+u+x)}var p=s-o,d=0;switch(n.textVerticalAlign){case i.TextVerticalAlign.top:d=-o;break;case i.TextVerticalAlign.middle:d=(e-p)/2-o;break;case i.TextVerticalAlign.bottom:d=e-p-o}var v=r.map((function(t){return d+t}));return{baselineY:d,lineYOffsets:v}},t}(),N=function(){function t(){}return t.createWrapStrategy=function(t){return t?new D:new V},t.createOverflowStrategy=function(t){switch(t){case i.TextOverflow.clip:return new B;case i.TextOverflow.display:case i.TextOverflow.visible:default:return new X}},t.createHorizontalAlignStrategy=function(){return new F},t.createVerticalAlignStrategy=function(){return new Y},t}();function P(){return P=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var i=arguments[e];for(var n in i)Object.prototype.hasOwnProperty.call(i,n)&&(t[n]=i[n])}return t},P.apply(this,arguments)}var _=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=.11092565,n.ALPHA_FIX_VALUE=1/255,n.name="MRichText"+_++,n.initTextBase(e),n.richWrapStrategy=N.createWrapStrategy(),n.richOverflowStrategy=N.createOverflowStrategy(i.TextOverflow.display),n.richHorizontalAlignStrategy=N.createHorizontalAlignStrategy(),n.richVerticalAlignStrategy=N.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 C(r),this.text=r.text?r.text.toString():" ",this.textLayout.useLegacyRichText&&(this.textLayout.textVerticalAlign=i.TextVerticalAlign.middle),this.updateStrategies(),this.updateTexture(),this.material.setColor("_Color",new s.Color(1,1,1,1))},n.updateStrategies=function(){var t=this.textLayout;t&&(this.richWrapStrategy=N.createWrapStrategy(t.wrapEnabled),this.richOverflowStrategy=N.createOverflowStrategy(t.overflow))},n.generateTextProgram=function(t){var e=this;this.processedTextOptions=[];var n=z((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=R(n.color)),e.processedTextOptions.push(a)}))}));n(t)},n.updateWithOptions=function(t){this.textStyle=new o(t),this.textLayout=new C(t),this.text=t.text?t.text.toString():" ",this.textLayout.useLegacyRichText&&(this.textLayout.textVerticalAlign=i.TextVerticalAlign.middle),this.updateStrategies(),this.isDirty=!0},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){var n=.1;this.generateTextProgram(this.text);var r=0,a=0,o=this.textLayout,h=this.textStyle,c=o.overflow,f=o.letterSpace,u=void 0===f?0:f,g=this.context,x=[],p=h.fontSize*h.fontScale,d={richOptions:[],offsetX:[],width:0,lineHeight:p*this.singleLineHeight,offsetY:p*(this.singleLineHeight-1)/2};if(this.processedTextOptions.forEach((function(t){var i=t.text,o=t.isNewLine,s=t.fontSize;o&&(x.push(d),r=Math.max(r,d.width),d={richOptions:[],offsetX:[],width:0,lineHeight:p*e.singleLineHeight,offsetY:p*(e.singleLineHeight-1)/2},a+=d.lineHeight),g.font=(t.fontWeight||h.textWeight)+" 10px "+(t.fontFamily||h.fontFamily);var l=g.measureText(i),c=l.width;if(void 0!==l.actualBoundingBoxLeft&&void 0!==l.actualBoundingBoxRight){var f=l.actualBoundingBoxLeft+l.actualBoundingBoxRight;f>0&&(c=Math.max(c,f))}var v=s*e.singleLineHeight*h.fontScale;v>d.lineHeight&&(a+=v-d.lineHeight,d.lineHeight=v,d.offsetY=s*h.fontScale*(e.singleLineHeight-1)/2),d.offsetX.push(d.width),d.width+=(c<=0?0:c)*s*n*h.fontScale+i.length*u,d.richOptions.push(t)})),x.push(d),r=Math.max(r,d.width),a+=d.lineHeight,0!==r&&0!==a){void 0!==this.size&&null!==this.size||(this.size=this.item.transform.size.clone());var v=this.size,m=v.x,y=void 0===m?1:m,w=v.y,S=void 0===w?1:w;if(!this.initialized){this.canvasSize=this.canvasSize?this.canvasSize:new s.Vector2(r,a);var T=this.canvasSize,b=T.x,O=T.y;this.item.transform.size.set(y*b*n*n,S*O*n*n),this.size=this.item.transform.size.clone(),this.initialized=!0}l(this.canvasSize);var A=this.canvasSize,H=A.x,M=A.y;o.width=H/h.fontScale,o.height=M/h.fontScale,this.renderToTexture(H,M,t,(function(t){if(0!==x.length){var n=o.getOffsetY(h,x.length,p*e.singleLineHeight,h.fontSize);x.forEach((function(e,r){var a=e.richOptions,s=e.offsetX,l=e.width,f=l,u=s;if(c===i.TextOverflow.display&&l>H){var g=H/l;f*=g,u=s.map((function(t){return t*g}))}var x=o.getOffsetX(h,f);r>0&&(n+=e.lineHeight-e.offsetY),a.forEach((function(e,r){var a=h.fontScale,o=h.textColor,s=h.fontFamily,f=h.textWeight,g=h.fontStyle,p=e.text,d=e.fontSize,v=e.fontColor,m=void 0===v?o:v,y=e.fontFamily,w=void 0===y?s:y,S=e.fontWeight,T=void 0===S?f:S,b=e.fontStyle,O=void 0===b?g:b,A=d;c===i.TextOverflow.display&&l>H&&(A/=l/H);var M=u[r]+x;t.font=O+" "+T+" "+A*a+"px "+w;var z=m[0],L=m[1],E=m[2],W=m[3];t.fillStyle="rgba("+z+", "+L+", "+E+", "+W+")",t.fillText(p,M,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.updateStrategies(),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.textStyle.fontScale;n.autoResize===i.TextSizeMode.autoWidth&&(n.maxTextWidth=Number.MAX_SAFE_INTEGER);var l,h,c=this.richWrapStrategy.computeLines(this.processedTextOptions,o,this.textStyle,n,a);switch(n.autoResize){case i.TextSizeMode.autoWidth:l=Math.max(1,c.maxLineWidth||0),h=Math.max(1,c.totalHeight||0);break;case i.TextSizeMode.autoHeight:l=n.maxTextWidth,h=Math.max(1,c.totalHeight||0);break;case i.TextSizeMode.fixed:default:l=n.maxTextWidth,h=n.maxTextHeight}if(n.overflow===i.TextOverflow.display){var f=Math.max(1,c.maxLineWidth||0),u=Math.max(1,c.totalHeight||0);!function(t,e,i,n,r){var a=function(t,e){return Math.abs(e)>1e-5?t/e:1},o=Math.max(1,e),s=Math.max(1,i),l=Math.min(1,a(n,o),a(r,s));if(!(l>.9999))for(var h,c=T(t);!(h=c()).done;){var f=h.value;if(f.width*=l,f.lineHeight*=l,f.offsetX)for(var u=0;u<f.offsetX.length;u++)f.offsetX[u]*=l;for(var g,x=T(f.chars||[]);!(g=x()).done;)for(var p,d=T(g.value);!(p=d()).done;)p.value.x*=l;for(var v=f.richOptions||[],m=[],y=0;y<v.length;y++)m.push(P({},v[y],{fontSize:v[y].fontSize*l}));f.richOptions=m,null!=f.lineAscent&&(f.lineAscent*=l),null!=f.lineDescent&&(f.lineDescent*=l)}}(c.lines,f,u,l,h)}var g=this.richHorizontalAlignStrategy.getHorizontalOffsets(c.lines,l,n,this.textStyle),x=this.richVerticalAlignStrategy.getVerticalOffsets(c.lines,h,n),p=this.richOverflowStrategy.resolveCanvas(c.lines,l,h,g,x),d=Math.max(1,Math.ceil(p.canvasWidth*s)),v=Math.max(1,Math.ceil(p.canvasHeight*s));this.item.transform.size.set(p.canvasWidth*this.SCALE_FACTOR*this.SCALE_FACTOR,p.canvasHeight*this.SCALE_FACTOR*this.SCALE_FACTOR),n.maxTextWidth=l,n.maxTextHeight=h,n.width=p.canvasWidth,n.height=p.canvasHeight,this.renderToTexture(d,v,t,(function(t){t.scale(s,s),e.drawTextWithStrategies(t,c.lines,g,x,p,e.textStyle)}),{disposeOld:!1}),this.isDirty=!1}}},n.drawTextWithStrategies=function(t,e,i,n,r,a){var o=r.renderOffsetX,s=r.renderOffsetY,l=n.baselineY+s,h=i.lineOffsets;e.forEach((function(i,n){var r=i.richOptions,s=i.chars,c=h[n]+o,f=l;r.forEach((function(e,n){var r=a.textColor,o=a.fontFamily,l=a.textWeight,h=a.fontStyle,u=e.fontSize,g=e.fontColor,x=void 0===g?r:g,p=e.fontFamily,d=void 0===p?o:p,v=e.fontWeight,m=void 0===v?l:v,y=e.fontStyle,w=void 0===y?h:y,S=u;t.font=w+" "+m+" "+S+"px "+d;var T=x[0],b=x[1],O=x[2],A=x[3];t.fillStyle="rgba("+T+", "+b+", "+O+", "+A+")";var H=i.offsetX&&i.offsetX[n]?i.offsetX[n]:0;s[n].forEach((function(e){t.fillText(e.char,c+H+e.x,f)}))})),n<e.length-1&&(l+=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 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}([n(i.DataType.RichTextComponent)],j),[a]);var I="2.9.1";c("rich-text",w),f.info("Plugin rich text version: 2.9.1."),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,w as RichTextLoader,E as escape,z as generateProgram,L as isRichText,H as lexer,M 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 s,assertExist as l,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 d(t,e,i){return d=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},d.apply(null,arguments)}function v(t){return v=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},v(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 d(t,arguments,v(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,w=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 S(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 S(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)?S(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]+)(=([^>]+))?>$/,O=/^<\/([a-z]+)>$/,A=[["EscapedChar",/^\\([=<>\\/])/],["ContextStart",/^<[a-z]+(=[^>]+)?>/],["ContextEnd",/^<\/[a-z]+>/],["Text",/^[^</>=\\]+/]],H=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 H(t.slice(2),e.concat({tokenType:"Text",value:r}),i+2)}for(var a,o=T(A);!(a=o()).done;){var s=a.value,l=s[0],h=s[1];if("EscapedChar"!==l){var c=h.exec(t);if(c){var f=c[0],u=f.length;return H(t.slice(u),e.concat({tokenType:l,value:f}),i+u)}}}if(t.length>0)return H(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(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=s();if("ContextEnd"===(null==t?void 0:t.tokenType)){o();var e=t.value.match(O);if(e)return{attributeName:e[1]};throw new Error("Expect an end tag marker at position "+a)}return{}},r=H(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 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)}}}(),l};function z(t){return function(e){for(var i,n=T(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 L(t){var e=H(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(O)[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 C=function(){function t(t){this.width=0,this.height=0;var e=t.textOverflow,n=void 0===e?i.TextOverflow.clip:e,r=t.textVerticalAlign,a=void 0===r?i.TextVerticalAlign.middle:r,o=t.textAlign,s=void 0===o?i.TextAlignment.left:o,l=t.letterSpace,h=void 0===l?0:l,c=t.lineHeight,f=void 0===c?.571:c,u=t.wrapEnabled,g=void 0!==u&&u,x=t.maxTextWidth,p=void 0===x?350:x,d=t.maxTextHeight,v=void 0===d?1e3:d,m=t.autoResize,y=void 0===m?i.TextSizeMode.autoWidth:m,w=t.useLegacyRichText,S=void 0!==w&&w;this.letterSpace=h,this.lineHeight=f,this.useLegacyRichText=S,this.overflow=n,this.textVerticalAlign=a,this.textAlign=s,this.width=100,this.height=100,this.wrapEnabled=g,this.maxTextWidth=p,this.maxTextHeight=v,this.autoResize=y}var e=t.prototype;return e.getOffsetY=function(t,e,n,r,a){var o=t.outlineWidth,s=t.fontScale,l=(n-r)/3,h=r+o*s,c=void 0!==a?a:n*(e-1),f=0;switch(this.textVerticalAlign){case i.TextVerticalAlign.top:f=h+l;break;case i.TextVerticalAlign.middle:f=(this.height*s-c+h)/2;break;case i.TextVerticalAlign.bottom:f=this.height*s-c-l}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),s=(e[0]-n)/3,l=n+r*a,h=o-e[0],c=0;switch(this.textVerticalAlign){case i.TextVerticalAlign.top:c=l+s;break;case i.TextVerticalAlign.middle:c=(this.height*a-o)/2+l;break;case i.TextVerticalAlign.bottom:c=this.height*a-h-s}return c},e.getOffsetXRich=function(t,e,n){switch(this.textAlign){case i.TextAlignment.left:return t.outlineWidth;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 k(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 R(t,e){if(void 0===e&&(e=1),"string"!=typeof t||!t)throw new Error("Invalid color string");return t.startsWith("#")?k(t,e):k(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 V=function(){function t(){}var e=t.prototype;return e.computeLines=function(t,e,i,n,r){var a=this,o=[],s=[],l=n.lineHeight||0,h=this.createNewLine(),c=0,f=0,u=function(){if(0!==h.chars.length){h.lineHeight=l;var t=0===o.length?0:s[s.length-1]+l;s.push(t),f+=h.lineHeight,o.push(h),c=Math.max(c,h.width),h=a.createNewLine()}};t.forEach((function(t){var n=t.text,a=t.isNewLine,o=t.fontSize;a&&u();var s=t.fontStyle||i.fontStyle||"normal";e.font=s+" "+(t.fontWeight||i.textWeight)+" 10px "+(t.fontFamily||i.fontFamily),h.offsetX.push(h.width);for(var l=.1*o,c=e.measureText("x"),f=c.fontBoundingBoxAscent*l,g=c.fontBoundingBoxDescent*l,x=0,p=[],d=0;d<n.length;d++){var v=n[d],m=e.measureText(v).width,y=(m<=0?0:m)*l;d>0&&(x+=r),p.push({char:v,x:x}),x+=y}h.chars.push(p),h.width+=x,h.richOptions.push(t),h.lineAscent=Math.max(h.lineAscent||0,f),h.lineDescent=Math.max(h.lineDescent||0,g)})),u();var g=1/0,x=-1/0;if(0===o.length)return{lines:o,maxLineWidth:c,totalHeight:f,bboxTop:0,bboxBottom:0,bboxHeight:0};for(var p=0;p<o.length;p++){var d=o[p].lineAscent||0,v=o[p].lineDescent||0,m=(l-(d+v))/2;g=Math.min(g,s[p]-d-m),x=Math.max(x,s[p]+v+m)}return{lines:o,maxLineWidth:c,totalHeight:f,bboxTop:g,bboxBottom:x,bboxHeight:x-g}},e.createNewLine=function(){return{richOptions:[],offsetX:[],width:0,lineHeight:0,offsetY:0,chars:[],lineAscent:0,lineDescent:0}},t}(),D=function(){function t(){}var e=t.prototype;return e.computeLines=function(t,e,i,n,r){var a=this,o=[],s=[],l=n.lineHeight||0,h=n.maxTextWidth||1/0,c=this.createNewLine(),f=0,u=0,g=null,x=0,p=[],d=null,v=function(){if(m(),0!==c.chars.length){c.lineHeight=l;var t=0===o.length?0:s[s.length-1]+l;s.push(t),u+=c.lineHeight,o.push(c),f=Math.max(f,c.width),c=a.createNewLine(),g=null,x=0,p=[],d=null}},m=function(){0!==p.length&&(null===g&&(g=c.width),c.offsetX.push(g),c.chars.push(p),d&&c.richOptions.push(d),g=null,x=0,p=[],d=null)};t.forEach((function(t){var n=t.text,a=t.isNewLine,o=t.fontSize,s=t.fontStyle||i.fontStyle||"normal";e.font=s+" "+(t.fontWeight||i.textWeight)+" 10px "+(t.fontFamily||i.fontFamily),a&&(m(),v());for(var l=.1*o,f=e.measureText("x"),u=f.fontBoundingBoxAscent*l,y=f.fontBoundingBoxDescent*l,w=0;w<n.length;w++){var S=n[w],T=e.measureText(S).width,b=(T<=0?0:T)*l,O=p.length>0?r:0;c.width+O+b>h&&(m(),v()),null===g&&(g=c.width,d=t),p.length>0&&(x+=r,c.width+=r),p.push({char:S,x:x}),c.lineAscent=Math.max(c.lineAscent||0,u),c.lineDescent=Math.max(c.lineDescent||0,y),x+=b,c.width+=b}m()})),v();var y=1/0,w=-1/0;if(0===o.length)return{lines:o,maxLineWidth:f,totalHeight:u,bboxTop:0,bboxBottom:0,bboxHeight:0};for(var S=0;S<o.length;S++){var T=o[S].lineAscent||0,b=o[S].lineDescent||0,O=(l-(T+b))/2;y=Math.min(y,s[S]-T-O),w=Math.max(w,s[S]+b+O)}return{lines:o,maxLineWidth:f,totalHeight:u,bboxTop:y,bboxBottom:w,bboxHeight:w-y}},e.createNewLine=function(){return{richOptions:[],offsetX:[],width:0,lineHeight:0,offsetY:0,chars:[],lineAscent:0,lineDescent:0}},t}(),B=function(){function t(){}return t.prototype.resolveCanvas=function(t,e,i,n,r){return{canvasWidth:Math.max(1,Math.ceil(e)),canvasHeight:Math.max(1,Math.ceil(i)),renderOffsetX:0,renderOffsetY:0}},t}(),X=function(){function t(){}return t.prototype.resolveCanvas=function(t,e,i,n,r){if(0===t.length)return{canvasWidth:Math.max(1,e),canvasHeight:Math.max(1,i),renderOffsetX:0,renderOffsetY:0};for(var a=1/0,o=-1/0,s=r.baselineY,l=0;l<t.length;l++){var h,c,f=null!=(h=t[l].lineAscent)?h:0,u=null!=(c=t[l].lineDescent)?c:0,g=f+u,x=Math.max(0,(t[l].lineHeight-g)/2);a=Math.min(a,s-f-x),o=Math.max(o,s+u+x),l<t.length-1&&(s+=t[l+1].lineHeight)}for(var p=Math.max(0,-a),d=Math.max(0,o-i),v=Math.max(p,d),m=1/0,y=-1/0,w=0;w<t.length;w++){var S,T,b=null!=(S=n.lineOffsets[w])?S:0,O=null!=(T=t[w].width)?T:0;m=Math.min(m,b),y=Math.max(y,b+O)}isFinite(m)||(m=0),isFinite(y)||(y=0);var A=Math.max(0,-m),H=Math.max(0,y-e),M=Math.max(A,H),z=Math.ceil(e+2*M),L=Math.ceil(i+2*v);return{canvasWidth:Math.max(1,z),canvasHeight:Math.max(1,L),renderOffsetX:M,renderOffsetY:v}},t}(),F=function(){function t(){}return t.prototype.getHorizontalOffsets=function(t,e,i,n){return{lineOffsets:t.map((function(t){return i.getOffsetXRich(n,e,t.width)}))}},t}(),Y=function(){function t(){}return t.prototype.getVerticalOffsets=function(t,e,n){if(0===t.length)return{baselineY:0,lineYOffsets:[]};for(var r=[0],a=1;a<t.length;a++)r[a]=r[a-1]+t[a].lineHeight;for(var o=1/0,s=-1/0,l=0;l<t.length;l++){var h,c,f=null!=(h=t[l].lineAscent)?h:0,u=null!=(c=t[l].lineDescent)?c:0,g=f+u,x=(t[l].lineHeight-g)/2;o=Math.min(o,r[l]-f-x),s=Math.max(s,r[l]+u+x)}var p=s-o,d=0;switch(n.textVerticalAlign){case i.TextVerticalAlign.top:d=-o;break;case i.TextVerticalAlign.middle:d=(e-p)/2-o;break;case i.TextVerticalAlign.bottom:d=e-p-o}var v=r.map((function(t){return d+t}));return{baselineY:d,lineYOffsets:v}},t}(),N=function(){function t(){}return t.createWrapStrategy=function(t){return t?new D:new V},t.createOverflowStrategy=function(t){switch(t){case i.TextOverflow.clip:return new B;case i.TextOverflow.display:case i.TextOverflow.visible:default:return new X}},t.createHorizontalAlignStrategy=function(){return new F},t.createVerticalAlignStrategy=function(){return new Y},t}();function P(){return P=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var i=arguments[e];for(var n in i)Object.prototype.hasOwnProperty.call(i,n)&&(t[n]=i[n])}return t},P.apply(this,arguments)}var _=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=.11092565,n.ALPHA_FIX_VALUE=1/255,n.name="MRichText"+_++,n.initTextBase(e),n.richWrapStrategy=N.createWrapStrategy(),n.richOverflowStrategy=N.createOverflowStrategy(i.TextOverflow.display),n.richHorizontalAlignStrategy=N.createHorizontalAlignStrategy(),n.richVerticalAlignStrategy=N.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 C(r),this.text=r.text?r.text.toString():" ",this.textLayout.useLegacyRichText&&(this.textLayout.textVerticalAlign=i.TextVerticalAlign.middle),this.updateStrategies(),this.updateTexture(),this.material.setColor("_Color",new s.Color(1,1,1,1))},n.updateStrategies=function(){var t=this.textLayout;t&&(this.richWrapStrategy=N.createWrapStrategy(t.wrapEnabled),this.richOverflowStrategy=N.createOverflowStrategy(t.overflow))},n.generateTextProgram=function(t){var e=this;this.processedTextOptions=[];var n=z((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=R(n.color)),e.processedTextOptions.push(a)}))}));n(t)},n.updateWithOptions=function(t){this.textStyle=new o(t),this.textLayout=new C(t),this.text=t.text?t.text.toString():" ",this.textLayout.useLegacyRichText&&(this.textLayout.textVerticalAlign=i.TextVerticalAlign.middle),this.updateStrategies(),this.isDirty=!0},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){var n=.1;this.generateTextProgram(this.text);var r=0,a=0,o=this.textLayout,h=this.textStyle,c=o.overflow,f=o.letterSpace,u=void 0===f?0:f,g=this.context,x=[],p=h.fontSize*h.fontScale,d={richOptions:[],offsetX:[],width:0,lineHeight:p*this.singleLineHeight,offsetY:p*(this.singleLineHeight-1)/2};if(this.processedTextOptions.forEach((function(t){var i=t.text,o=t.isNewLine,s=t.fontSize;o&&(x.push(d),r=Math.max(r,d.width),d={richOptions:[],offsetX:[],width:0,lineHeight:p*e.singleLineHeight,offsetY:p*(e.singleLineHeight-1)/2},a+=d.lineHeight),g.font=(t.fontWeight||h.textWeight)+" 10px "+(t.fontFamily||h.fontFamily);var l=g.measureText(i),c=l.width;if(void 0!==l.actualBoundingBoxLeft&&void 0!==l.actualBoundingBoxRight){var f=l.actualBoundingBoxLeft+l.actualBoundingBoxRight;f>0&&(c=Math.max(c,f))}var v=s*e.singleLineHeight*h.fontScale;v>d.lineHeight&&(a+=v-d.lineHeight,d.lineHeight=v,d.offsetY=s*h.fontScale*(e.singleLineHeight-1)/2),d.offsetX.push(d.width),d.width+=(c<=0?0:c)*s*n*h.fontScale+i.length*u,d.richOptions.push(t)})),x.push(d),r=Math.max(r,d.width),a+=d.lineHeight,0!==r&&0!==a){void 0!==this.size&&null!==this.size||(this.size=this.item.transform.size.clone());var v=this.size,m=v.x,y=void 0===m?1:m,w=v.y,S=void 0===w?1:w;if(!this.initialized){this.canvasSize=this.canvasSize?this.canvasSize:new s.Vector2(r,a);var T=this.canvasSize,b=T.x,O=T.y;this.item.transform.size.set(y*b*n*n,S*O*n*n),this.size=this.item.transform.size.clone(),this.initialized=!0}l(this.canvasSize);var A=this.canvasSize,H=A.x,M=A.y;o.width=H/h.fontScale,o.height=M/h.fontScale,this.renderToTexture(H,M,t,(function(t){if(0!==x.length){var n=o.getOffsetY(h,x.length,p*e.singleLineHeight,h.fontSize);x.forEach((function(e,r){var a=e.richOptions,s=e.offsetX,l=e.width,f=l,u=s;if(c===i.TextOverflow.display&&l>H){var g=H/l;f*=g,u=s.map((function(t){return t*g}))}var x=o.getOffsetX(h,f);r>0&&(n+=e.lineHeight-e.offsetY),a.forEach((function(e,r){var a=h.fontScale,o=h.textColor,s=h.fontFamily,f=h.textWeight,g=h.fontStyle,p=e.text,d=e.fontSize,v=e.fontColor,m=void 0===v?o:v,y=e.fontFamily,w=void 0===y?s:y,S=e.fontWeight,T=void 0===S?f:S,b=e.fontStyle,O=void 0===b?g:b,A=d;c===i.TextOverflow.display&&l>H&&(A/=l/H);var M=u[r]+x;t.font=O+" "+T+" "+A*a+"px "+w;var z=m[0],L=m[1],E=m[2],W=m[3];t.fillStyle="rgba("+z+", "+L+", "+E+", "+W+")",t.fillText(p,M,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.updateStrategies(),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.textStyle.fontScale;n.autoResize===i.TextSizeMode.autoWidth&&(n.maxTextWidth=Number.MAX_SAFE_INTEGER);var l,h,c=this.richWrapStrategy.computeLines(this.processedTextOptions,o,this.textStyle,n,a);switch(n.autoResize){case i.TextSizeMode.autoWidth:l=Math.max(1,c.maxLineWidth||0),h=Math.max(1,c.totalHeight||0);break;case i.TextSizeMode.autoHeight:l=n.maxTextWidth,h=Math.max(1,c.totalHeight||0);break;case i.TextSizeMode.fixed:default:l=n.maxTextWidth,h=n.maxTextHeight}if(n.overflow===i.TextOverflow.display){var f=Math.max(1,c.maxLineWidth||0),u=Math.max(1,c.totalHeight||0);!function(t,e,i,n,r){var a=function(t,e){return Math.abs(e)>1e-5?t/e:1},o=Math.max(1,e),s=Math.max(1,i),l=Math.min(1,a(n,o),a(r,s));if(!(l>.9999))for(var h,c=T(t);!(h=c()).done;){var f=h.value;if(f.width*=l,f.lineHeight*=l,f.offsetX)for(var u=0;u<f.offsetX.length;u++)f.offsetX[u]*=l;for(var g,x=T(f.chars||[]);!(g=x()).done;)for(var p,d=T(g.value);!(p=d()).done;)p.value.x*=l;for(var v=f.richOptions||[],m=[],y=0;y<v.length;y++)m.push(P({},v[y],{fontSize:v[y].fontSize*l}));f.richOptions=m,null!=f.lineAscent&&(f.lineAscent*=l),null!=f.lineDescent&&(f.lineDescent*=l)}}(c.lines,f,u,l,h)}var g=this.richHorizontalAlignStrategy.getHorizontalOffsets(c.lines,l,n,this.textStyle),x=this.richVerticalAlignStrategy.getVerticalOffsets(c.lines,h,n),p=this.richOverflowStrategy.resolveCanvas(c.lines,l,h,g,x),d=Math.max(1,Math.ceil(p.canvasWidth*s)),v=Math.max(1,Math.ceil(p.canvasHeight*s));this.item.transform.size.set(p.canvasWidth*this.SCALE_FACTOR*this.SCALE_FACTOR,p.canvasHeight*this.SCALE_FACTOR*this.SCALE_FACTOR),n.maxTextWidth=l,n.maxTextHeight=h,n.width=p.canvasWidth,n.height=p.canvasHeight,this.renderToTexture(d,v,t,(function(t){t.scale(s,s),e.drawTextWithStrategies(t,c.lines,g,x,p,e.textStyle)}),{disposeOld:!1}),this.isDirty=!1}}},n.drawTextWithStrategies=function(t,e,i,n,r,a){var o=r.renderOffsetX,s=r.renderOffsetY,l=n.baselineY+s,h=i.lineOffsets;e.forEach((function(i,n){var r=i.richOptions,s=i.chars,c=h[n]+o,f=l;r.forEach((function(e,n){var r=a.textColor,o=a.fontFamily,l=a.textWeight,h=a.fontStyle,u=e.fontSize,g=e.fontColor,x=void 0===g?r:g,p=e.fontFamily,d=void 0===p?o:p,v=e.fontWeight,m=void 0===v?l:v,y=e.fontStyle,w=void 0===y?h:y,S=u;t.font=w+" "+m+" "+S+"px "+d;var T=x[0],b=x[1],O=x[2],A=x[3];t.fillStyle="rgba("+T+", "+b+", "+O+", "+A+")";var H=i.offsetX&&i.offsetX[n]?i.offsetX[n]:0;s[n].forEach((function(e){t.fillText(e.char,c+H+e.x,f)}))})),n<e.length-1&&(l+=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 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}([n(i.DataType.RichTextComponent)],j),[a]);var I="2.9.2";c("rich-text",w),f.info("Plugin rich text version: 2.9.2."),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,w as RichTextLoader,E as escape,z as generateProgram,L as isRichText,H as lexer,M 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.9.1",
3
+ "version": "2.9.2",
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.9.1"
53
+ "@galacean/effects": "2.9.2"
54
54
  },
55
55
  "scripts": {
56
56
  "dev": "vite",