@galacean/effects-plugin-rich-text 2.8.8 → 2.8.9
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 +1 -1
- package/dist/alipay.js.map +1 -1
- package/dist/alipay.mjs +1 -1
- package/dist/alipay.mjs.map +1 -1
- package/dist/douyin.js +1 -1
- package/dist/douyin.js.map +1 -1
- package/dist/douyin.mjs +1 -1
- package/dist/douyin.mjs.map +1 -1
- package/dist/index.js +330 -468
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +2 -2
- package/dist/index.min.js.map +1 -1
- package/dist/index.mjs +330 -468
- package/dist/index.mjs.map +1 -1
- package/dist/rich-text-component.d.ts +14 -6
- package/dist/rich-text-layout.d.ts +1 -1
- package/dist/strategies/align/rich-horizontal-align.d.ts +3 -3
- package/dist/strategies/align/rich-vertical-align.d.ts +8 -4
- package/dist/strategies/overflow/rich-clipped-overflow.d.ts +4 -5
- package/dist/strategies/overflow/rich-expanding-overflow.d.ts +15 -0
- package/dist/strategies/rich-text-factory.d.ts +5 -3
- package/dist/strategies/rich-text-interfaces.d.ts +22 -34
- package/dist/strategies/wrap/rich-wrap-disabled.d.ts +1 -1
- package/dist/strategies/wrap/rich-wrap-enabled.d.ts +1 -1
- package/dist/weapp.js +1 -1
- package/dist/weapp.js.map +1 -1
- package/dist/weapp.mjs +1 -1
- package/dist/weapp.mjs.map +1 -1
- package/package.json +2 -2
- package/dist/strategies/overflow/rich-display-overflow.d.ts +0 -10
- package/dist/strategies/overflow/rich-visible-overflow.d.ts +0 -10
package/dist/alipay.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import*as t from"@galacean/effects/alipay";import{Plugin as e,spec as i,effectsClass as n,applyMixins as r,TextComponentBase as a,TextStyle as o,math as l,assertExist as s,MaskableGraphic as h,registerPlugin as c,logger as f}from"@galacean/effects/alipay";import{document as u}from"@galacean/appx-adapter/alipay";function g(t,e){return g=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},g(t,e)}function x(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&g(t,e)}function p(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(p=function(){return!!t})()}function v(t,e,i){return v=p()?Reflect.construct:function(t,e,i){var n=[null];n.push.apply(n,e);var r=new(Function.bind.apply(t,n));return i&&g(r,i.prototype),r},v.apply(null,arguments)}function d(t){return d=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},d(t)}function m(t){var e="function"==typeof Map?new Map:void 0;return m=function(t){if(null===t||(i=t,-1===Function.toString.call(i).indexOf("[native code]")))return t;var i;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,n)}function n(){return v(t,arguments,d(this).constructor)}return n.prototype=Object.create(t.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),g(n,t)},m(t)}var y,S=function(t){function e(){var e;return(e=t.apply(this,arguments)||this).name="rich-text",e}return x(e,t),e}(m(e));function w(t,e){(null==e||e>t.length)&&(e=t.length);for(var i=0,n=new Array(e);i<e;i++)n[i]=t[i];return n}function b(t,e){var i="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(i)return(i=i.call(t)).next.bind(i);if(Array.isArray(t)||(i=function(t,e){if(t){if("string"==typeof t)return w(t,e);var i=Object.prototype.toString.call(t).slice(8,-1);return"Object"===i&&t.constructor&&(i=t.constructor.name),"Map"===i||"Set"===i?Array.from(i):"Arguments"===i||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i)?w(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){i&&(t=i);var n=0;return function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}!function(t){t.ContextStart="ContextStart",t.Text="Text",t.ContextEnd="ContextEnd",t.EscapedChar="EscapedChar"}(y||(y={}));var T=/^<([a-z]+)(=([^>]+))?>$/,A=/^<\/([a-z]+)>$/,O=[["EscapedChar",/^\\([=<>\\/])/],["ContextStart",/^<[a-z]+(=[^>]+)?>/],["ContextEnd",/^<\/[a-z]+>/],["Text",/^[^</>=\\]+/]],z=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 z(t.slice(2),e.concat({tokenType:"Text",value:r}),i+2)}for(var a,o=b(O);!(a=o()).done;){var l=a.value,s=l[0],h=l[1];if("EscapedChar"!==s){var c=h.exec(t);if(c){var f=c[0],u=f.length;return z(t.slice(u),e.concat({tokenType:s,value:f}),i+u)}}}if(t.length>0)return z(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+'"')},C=function(t){var e=function(){for(var t,e="",i=!1;r.length>0&&"Text"===(null==(t=r[0])?void 0:t.tokenType);){var n=o();n&&(e+=n.value,i=!0)}return i?e:void 0},i=function(){var t=l();if("ContextStart"===(null==t?void 0:t.tokenType)){o();var e,i=t.value.match(T);if(i)return{attributeName:i[1],attributeParam:null!=(e=i[3])?e:""};throw new Error("Expected a start tag marker at position "+a)}return{}},n=function(){var t=l();if("ContextEnd"===(null==t?void 0:t.tokenType)){o();var e=t.value.match(A);if(e)return{attributeName:e[1]};throw new Error("Expect an end tag marker at position "+a)}return{}},r=z(t),a=0,o=function(){var t,e=r.shift();return a+=null!=(t=null==e?void 0:e.value.length)?t:0,e},l=function(){return r[0]},s=[];return function t(r,o){for(void 0===r&&(r=[]),void 0===o&&(o="");;){var l=e();if(l)s.push({attributes:r,text:l});else{var h=i(),c=h.attributeName,f=h.attributeParam;if(!c){if(o){var u=n().attributeName;if(!u)throw new Error('Expect an end tag marker "'+o+'" at position '+a+" but found no tag!");if(u!==o)throw new Error('Expect an end tag marker "'+o+'" at position '+a+' but found tag "'+u+'"');return}break}t(r.concat({attributeName:c,attributeParam:null!=f?f:""}),c)}}}(),s};function H(t){return function(e){for(var i,n=b(C(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=z(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(T)[1]:i.match(A)[1]}})))}function E(t){if("string"!=typeof t)throw new Error("Input must be a string");return t.replace(/\\/g,"\\\\").replace(/=/g,"\\=").replace(/</g,"\\<").replace(/>/g,"\\>").replace(/\//g,"\\/")}function W(t){if("string"!=typeof t)throw new Error("Input must be a string");return t.replace(/\\\//g,"/").replace(/\\>/g,">").replace(/\\</g,"<").replace(/\\=/g,"=").replace(/\\\\/g,"\\")}"function"==typeof SuppressedError&&SuppressedError;var V=function(){function t(t){this.width=0,this.height=0;var e=t.size,n=t.textOverflow,r=void 0===n?i.TextOverflow.clip:n,a=t.textVerticalAlign,o=void 0===a?i.TextVerticalAlign.middle:a,l=t.textAlign,s=void 0===l?i.TextAlignment.left:l,h=t.letterSpace,c=void 0===h?0:h,f=t.lineHeight,u=void 0===f?.571:f,g=t.wrapEnabled,x=void 0!==g&&g,p=t.maxTextWidth,v=void 0===p?350:p,d=t.maxTextHeight,m=void 0===d?1e3:d,y=t.sizeMode,S=void 0===y?i.TextSizeMode.autoWidth:y,w=t.useLegacyRichText,b=void 0!==w&&w;this.letterSpace=c,this.lineHeight=u,this.useLegacyRichText=b,this.overflow=r,this.textVerticalAlign=o,this.textAlign=s,this.width=e?e[0]:100,this.height=e?e[1]:100,this.wrapEnabled=x,this.maxTextWidth=v,this.maxTextHeight=m,this.sizeMode=S}var e=t.prototype;return e.getOffsetY=function(t,e,n,r,a){var o=t.outlineWidth,l=t.fontScale,s=(n-r)/3,h=r+o*l,c=void 0!==a?a:n*(e-1),f=0;switch(this.textVerticalAlign){case i.TextVerticalAlign.top:f=h+s;break;case i.TextVerticalAlign.middle:f=(this.height*l-c+h)/2;break;case i.TextVerticalAlign.bottom:f=this.height*l-c-s}return f},e.getOffsetX=function(t,e){var n=0;switch(this.textAlign){case i.TextAlignment.left:n=t.outlineWidth*t.fontScale;break;case i.TextAlignment.middle:n=(this.width*t.fontScale-e)/2;break;case i.TextAlignment.right:n=this.width*t.fontScale-e}return n},e.getOffsetYRich=function(t,e,n){if(0===e.length)return 0;var r=t.outlineWidth,a=t.fontScale,o=e.reduce((function(t,e){return t+e}),0),l=(e[0]-n)/3,s=n+r*a,h=o-e[0],c=0;switch(this.textVerticalAlign){case i.TextVerticalAlign.top:c=s+l;break;case i.TextVerticalAlign.middle:c=(this.height*a-o)/2+s;break;case i.TextVerticalAlign.bottom:c=this.height*a-h-l}return c},e.getOffsetXRich=function(t,e,n){switch(this.textAlign){case i.TextAlignment.left:return t.outlineWidth*t.fontScale;case i.TextAlignment.middle:return(e-n)/2;case i.TextAlignment.right:return e-n;default:return 0}},e.setSize=function(t,e){this.width=t,this.height=e},t}();function M(t,e){if(void 0===e&&(e=1),3!==(t=t.replace(/^#/,"")).length&&4!==t.length||(t=t.split("").map((function(t){return t+t})).join("")),8===t.length){var i=parseInt(t.slice(6,8),16)/255;t=t.slice(0,6),e=i}var n=parseInt(t,16);return[n>>16&255,n>>8&255,255&n,e]}function k(t,e){if(void 0===e&&(e=1),"string"!=typeof t||!t)throw new Error("Invalid color string");return t.startsWith("#")?M(t,e):M(function(t){if("string"!=typeof t||!t)throw new Error("Invalid color name provided");if(void 0===u)throw new Error("This method requires a browser environment");var e=u.createElement("canvas"),i=e.getContext("2d");if(i)try{return i.fillStyle=t,i.fillStyle}finally{null==e.remove||e.remove.call(e)}throw new Error("Failed to get 2D context for color conversion!")}(t))}var R=function(){function t(){}var e=t.prototype;return e.computeLines=function(t,e,i,n,r,a,o){var l=this,s=[],h=[],c=(n.lineHeight||0)*a,f=this.createNewLine(),u=0,g=0,x=function(){if(0!==f.chars.length){f.lineHeight=0===s.length?(f.lineAscent||0)+(f.lineDescent||0):c;var t=0===s.length?0:h[h.length-1]+c;h.push(t),g+=f.lineHeight,s.push(f),u=Math.max(u,f.width),f=l.createNewLine()}};t.forEach((function(t){var n=t.text,r=t.isNewLine,l=t.fontSize;r&&x();var s=t.fontStyle||i.fontStyle||"normal";e.font=s+" "+(t.fontWeight||i.textWeight)+" 10px "+(t.fontFamily||i.fontFamily),f.offsetX.push(f.width);for(var h=0,c=[],u=0,g=0,p=0;p<n.length;p++){var v=n[p],d=e.measureText(v),m=d.width,y=(m<=0?0:m)*l*.1*a,S=l*a*.1,w=d.actualBoundingBoxAscent*S,b=d.actualBoundingBoxDescent*S;u=Math.max(u,w),g=Math.max(g,b),p>0&&(h+=o),c.push({char:v,x:h}),h+=y}f.chars.push(c),f.width+=h,f.richOptions.push(t),f.lineAscent=Math.max(f.lineAscent||0,u),f.lineDescent=Math.max(f.lineDescent||0,g)})),x();var p=1/0,v=-1/0;if(0===s.length)return{lines:s,maxLineWidth:u,totalHeight:g,bboxTop:0,bboxBottom:0,bboxHeight:0};for(var d=0;d<s.length;d++)p=Math.min(p,h[d]-(s[d].lineAscent||0)),v=Math.max(v,h[d]+(s[d].lineDescent||0));return{lines:s,maxLineWidth:u,totalHeight:g,bboxTop:p,bboxBottom:v,bboxHeight:v-p}},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,a,o){var l=this,s=[],h=[],c=(n.lineHeight||0)*a,f=this.createNewLine(),u=0,g=0,x=null,p=0,v=[],d=null,m=function(){if(y(),0!==f.chars.length){f.lineHeight=0===s.length?(f.lineAscent||0)+(f.lineDescent||0):c;var t=0===s.length?0:h[h.length-1]+c;h.push(t),g+=f.lineHeight,s.push(f),u=Math.max(u,f.width),f=l.createNewLine(),x=null,p=0,v=[],d=null}},y=function(){0!==v.length&&(null===x&&(x=f.width),f.offsetX.push(x),f.chars.push(v),d&&f.richOptions.push(d),x=null,p=0,v=[],d=null)};t.forEach((function(t){var r=t.text,l=t.isNewLine,s=t.fontSize,h=t.fontStyle||i.fontStyle||"normal";e.font=h+" "+(t.fontWeight||i.textWeight)+" 10px "+(t.fontFamily||i.fontFamily),l&&(y(),m());for(var c=0;c<r.length;c++){var u=r[c],g=e.measureText(u),S=g.width,w=(S<=0?0:S)*s*.1*a,b=s*a*.1,T=g.actualBoundingBoxAscent*b,A=g.actualBoundingBoxDescent*b,O=v.length>0?o:0;f.width+O+w>(n.maxTextWidth*a||1/0)&&(y(),m()),null===x&&(x=f.width,d=t),v.length>0&&(p+=o,f.width+=o),v.push({char:u,x:p}),f.lineAscent=Math.max(f.lineAscent||0,T),f.lineDescent=Math.max(f.lineDescent||0,A),p+=w,f.width+=w}y()})),m();for(var S=1/0,w=-1/0,b=0;b<s.length;b++)S=Math.min(S,h[b]-(s[b].lineAscent||0)),w=Math.max(w,h[b]+(s[b].lineDescent||0));return{lines:s,maxLineWidth:u,totalHeight:g,bboxTop:S,bboxBottom:w,bboxHeight:w-S}},e.createNewLine=function(){return{richOptions:[],offsetX:[],width:0,lineHeight:0,offsetY:0,chars:[],lineAscent:0,lineDescent:0}},t}(),F=function(){function t(){}return t.prototype.apply=function(t,e,i,n){var r,a,o=function(t,e){return Math.abs(e)>1e-5?t/e:1},l=i.maxTextWidth*n.fontScale,s=i.maxTextHeight*n.fontScale,h=Math.max(1,null!=(r=e.contentWidth)?r:e.canvasWidth),c=Math.max(1,null!=(a=e.bboxHeight)?a:e.canvasHeight),f=Math.min(1,o(l,h),o(s,c));if(f>.9999)return{globalScale:1};for(var u,g=b(t);!(u=g()).done;){var x=u.value;if(x.width*=f,x.lineHeight*=f,x.offsetX)for(var p=0;p<x.offsetX.length;p++)x.offsetX[p]*=f;for(var v,d=b(x.chars||[]);!(v=d()).done;)for(var m,y=b(v.value);!(m=y()).done;){m.value.x*=f}for(var S,w=b(x.richOptions||[]);!(S=w()).done;){S.value.fontSize*=f}null!=x.lineAscent&&(x.lineAscent*=f),null!=x.lineDescent&&(x.lineDescent*=f)}return{globalScale:f}},t}(),B=function(){function t(){}return t.prototype.apply=function(t,e,i,n){return{globalScale:1}},t}(),X=function(){function t(){}return t.prototype.apply=function(t,e,i,n){return{globalScale:1}},t}(),_=function(){function t(){}return t.prototype.getHorizontalOffsets=function(t,e,n,r,a){var o,l,s=null!=(o=e.containerWidth)?o:r.maxTextWidth*a.fontScale,h=null!=(l=e.baselineCompensationX)?l:0,c=t.map((function(t){return r.getOffsetXRich(a,s,t.width)}));return{lineOffsets:r.overflow===i.TextOverflow.visible?c.map((function(t){return t+h})):c}},t}(),Y=function(){function t(){}return t.prototype.getVerticalOffsets=function(t,e,n,r,a,o){var l,s=null!=(l=e.baselineCompensationY)?l:0,h=0;if(0===t.length)return{baselineY:0,lineYOffsets:[]};switch(r.overflow){case i.TextOverflow.visible:var c,f,u,g,x=r.maxTextHeight*a.fontScale,p=null!=(c=e.bboxTop)?c:0,v=null!=(u=e.bboxBottom)?u:p+(null!=(f=e.bboxHeight)?f:0),d=null!=(g=e.bboxHeight)?g:v-p,m=0;switch(r.textVerticalAlign){case i.TextVerticalAlign.top:m=-p;break;case i.TextVerticalAlign.middle:m=(x-d)/2-p;break;case i.TextVerticalAlign.bottom:m=x-d-p}h=m+s;break;case i.TextOverflow.clip:for(var y=r.maxTextHeight*a.fontScale,S=[0],w=1;w<t.length;w++)S[w]=S[w-1]+t[w].lineHeight;for(var b=1/0,T=-1/0,A=0;A<t.length;A++){var O,z,C=null!=(O=t[A].lineAscent)?O:0,H=null!=(z=t[A].lineDescent)?z:0;b=Math.min(b,S[A]-C),T=Math.max(T,S[A]+H)}var L=T-b,E=0;switch(r.textVerticalAlign){case i.TextVerticalAlign.top:E=-b;break;case i.TextVerticalAlign.middle:E=(y-L)/2-b;break;case i.TextVerticalAlign.bottom:E=y-L-b}h=E+s;break;case i.TextOverflow.display:for(var W=r.maxTextHeight*a.fontScale,V=[0],M=1;M<t.length;M++)V[M]=V[M-1]+t[M].lineHeight;for(var k=1/0,R=-1/0,D=0;D<t.length;D++){var F,B,X=null!=(F=t[D].lineAscent)?F:0,_=null!=(B=t[D].lineDescent)?B:0;k=Math.min(k,V[D]-X),R=Math.max(R,V[D]+_)}var Y=R-k,P=0;switch(r.textVerticalAlign){case i.TextVerticalAlign.top:P=-k;break;case i.TextVerticalAlign.middle:P=(W-Y)/2-k;break;case i.TextVerticalAlign.bottom:P=W-Y-k}for(var N=[],j=P,I=0;I<t.length;I++)N.push(j),I<t.length-1&&(j+=t[I+1].lineHeight);return{baselineY:P,lineYOffsets:N}}var U=[],$=h;return t.forEach((function(e,i){U.push($),i<t.length-1&&($+=t[i+1].lineHeight)})),{baselineY:h,lineYOffsets:U}},t}(),P=function(){function t(){}return t.createWrapStrategy=function(t){return t?new D:new R},t.createOverflowStrategy=function(t){switch(t){case i.TextOverflow.clip:return new B;case i.TextOverflow.display:return new F;case i.TextOverflow.visible:default:return new X}},t.createHorizontalAlignStrategy=function(){return new _},t.createVerticalAlignStrategy=function(){return new Y},t}(),N=0,j=function(t){function e(e){var n;return(n=t.call(this,e)||this).isDirty=!0,n.text="",n.processedTextOptions=[],n.singleLineHeight=1.571,n.size=null,n.initialized=!1,n.canvasSize=null,n.SCALE_FACTOR=.11092565,n.ALPHA_FIX_VALUE=1/255,n.name="MRichText"+N++,n.initTextBase(e),n.richWrapStrategy=P.createWrapStrategy(),n.richOverflowStrategy=P.createOverflowStrategy(i.TextOverflow.display),n.richHorizontalAlignStrategy=P.createHorizontalAlignStrategy(),n.richVerticalAlignStrategy=P.createVerticalAlignStrategy(),n}x(e,t);var n=e.prototype;return n.onUpdate=function(e){t.prototype.onUpdate.call(this,e),this.updateTexture()},n.onDestroy=function(){t.prototype.onDestroy.call(this),this.disposeTextTexture()},n.fromData=function(e){t.prototype.fromData.call(this,e);var n=e.interaction,r=e.options;this.interaction=n,this.textStyle=new o(r),this.textLayout=new V(r),this.text=r.text?r.text.toString():" ",this.textLayout.useLegacyRichText&&(this.textLayout.textVerticalAlign=i.TextVerticalAlign.middle),this.updateStrategies(),this.updateTexture(),this.material.setColor("_Color",new l.Color(1,1,1,1))},n.updateStrategies=function(){var t=this.textLayout;t&&(this.richWrapStrategy=P.createWrapStrategy(t.wrapEnabled),this.richOverflowStrategy=P.createOverflowStrategy(t.overflow))},n.generateTextProgram=function(t){var e=this;this.processedTextOptions=[];var n=H((function(t,n){/^\n+$/.test(t)&&(t=t.replace(/\n/g,"\n ")),t.split("\n").forEach((function(t,r){var a={text:t,fontSize:e.textStyle.fontSize,isNewLine:!1};r>0&&(a.isNewLine=!0),"b"in n&&(a.fontWeight=i.TextWeight.bold),"i"in n&&(a.fontStyle=i.FontStyle.italic),"size"in n&&n.size&&(a.fontSize=parseInt(n.size,10)),"color"in n&&n.color&&(a.fontColor=k(n.color)),e.processedTextOptions.push(a)}))}));n(t)},n.updateWithOptions=function(t){this.textStyle=new o(t),this.textLayout=new V(t),this.text=t.text?t.text.toString():" ",this.textLayout.useLegacyRichText&&(this.textLayout.textVerticalAlign=i.TextVerticalAlign.middle),this.updateStrategies(),this.isDirty=!0},n.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,v={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,l=t.fontSize;o&&(x.push(v),r=Math.max(r,v.width),v={richOptions:[],offsetX:[],width:0,lineHeight:p*e.singleLineHeight,offsetY:p*(e.singleLineHeight-1)/2},a+=v.lineHeight),g.font=(t.fontWeight||h.textWeight)+" 10px "+(t.fontFamily||h.fontFamily);var s=g.measureText(i),c=s.width;if(void 0!==s.actualBoundingBoxLeft&&void 0!==s.actualBoundingBoxRight){var f=s.actualBoundingBoxLeft+s.actualBoundingBoxRight;f>0&&(c=Math.max(c,f))}var d=l*e.singleLineHeight*h.fontScale;d>v.lineHeight&&(a+=d-v.lineHeight,v.lineHeight=d,v.offsetY=l*h.fontScale*(e.singleLineHeight-1)/2),v.offsetX.push(v.width),v.width+=(c<=0?0:c)*l*n*h.fontScale+i.length*u,v.richOptions.push(t)})),x.push(v),r=Math.max(r,v.width),a+=v.lineHeight,0!==r&&0!==a){void 0!==this.size&&null!==this.size||(this.size=this.item.transform.size.clone());var d=this.size,m=d.x,y=void 0===m?1:m,S=d.y,w=void 0===S?1:S;if(!this.initialized){this.canvasSize=this.canvasSize?this.canvasSize:new l.Vector2(r,a);var b=this.canvasSize,T=b.x,A=b.y;this.item.transform.size.set(y*T*n*n,w*A*n*n),this.size=this.item.transform.size.clone(),this.initialized=!0}s(this.canvasSize);var O=this.canvasSize,z=O.x,C=O.y;o.width=z/h.fontScale,o.height=C/h.fontScale,this.renderToTexture(z,C,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,l=e.offsetX,s=e.width,f=s,u=l;if(c===i.TextOverflow.display&&s>z){var g=z/s;f*=g,u=l.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,l=h.fontFamily,f=h.textWeight,g=h.fontStyle,p=e.text,v=e.fontSize,d=e.fontColor,m=void 0===d?o:d,y=e.fontFamily,S=void 0===y?l:y,w=e.fontWeight,b=void 0===w?f:w,T=e.fontStyle,A=void 0===T?g:T,O=v;c===i.TextOverflow.display&&s>z&&(O/=s/z);var C=u[r]+x;t.font=A+" "+b+" "+O*a+"px "+S;var H=m[0],L=m[1],E=m[2],W=m[3];t.fillStyle="rgba("+H+", "+L+", "+E+", "+W+")",t.fillText(p,C,n)}))}))}}),{disposeOld:!1}),this.isDirty=!1}else this.isDirty=!1}},n.updateTextureWithStrategies=function(t){var e=this;if(this.isDirty&&this.context&&this.canvas){this.generateTextProgram(this.text);var i=this.textLayout,n=i.letterSpace,r=void 0===n?0:n,a=this.context;if(a){var o=this.richWrapStrategy.computeLines(this.processedTextOptions,a,this.textStyle,i,this.singleLineHeight,this.textStyle.fontScale,r);if(0!==o.lines.length&&0!==o.maxLineWidth&&0!==o.totalHeight){var l=this.resolveCanvasSize(o,i,this.textStyle,this.singleLineHeight);this.setCanvasSize(l);var h=this.richOverflowStrategy.apply(o.lines,l,i,this.textStyle),c=this.richHorizontalAlignStrategy.getHorizontalOffsets(o.lines,l,h,i,this.textStyle),f=this.richVerticalAlignStrategy.getVerticalOffsets(o.lines,l,h,i,this.textStyle,this.singleLineHeight);s(this.canvasSize);var u=this.canvasSize,g=u.x,x=u.y,p=Math.max(1,Math.ceil(g)),v=Math.max(1,Math.ceil(x));i.width=p/this.textStyle.fontScale,i.height=v/this.textStyle.fontScale,this.renderToTexture(p,v,t,(function(t){e.drawTextWithStrategies(t,o.lines,c,f,h,e.textStyle)}),{disposeOld:!1}),this.isDirty=!1}else this.isDirty=!1}}},n.setCanvasSize=function(t){var e=this;void 0!==this.size&&null!==this.size||(this.size=this.item.transform.size.clone());var n=this.size,r=n.x,a=void 0===r?1:r,o=n.y,s=void 0===o?1:o,h=this.textLayout,c=this.textStyle.fontScale||1,f=Math.max(1,h.maxTextWidth||0),u=Math.max(1,h.maxTextHeight||0);switch(h.overflow){case i.TextOverflow.visible:var g,x,p,v,d=f*c,m=u*c,y=null!=(g=t.bboxTop)?g:0,S=null!=(p=t.bboxBottom)?p:y+(null!=(x=t.bboxHeight)?x:0),w=null!=(v=t.bboxHeight)?v:S-y,b=0;switch(h.textVerticalAlign){case i.TextVerticalAlign.top:b=-y;break;case i.TextVerticalAlign.middle:b=(m-w)/2-y;break;case i.TextVerticalAlign.bottom:b=m-w-y}var T=b+y,A=b+S,O=Math.max(0,-T),z=Math.max(0,A-m),C=O,H=z;switch(h.textVerticalAlign){case i.TextVerticalAlign.top:C=z,H=z;break;case i.TextVerticalAlign.bottom:C=O,H=O;break;case i.TextVerticalAlign.middle:C=O,H=z}for(var L=C,E=t.lines||[],W=E.map((function(t){return h.getOffsetXRich(e.textStyle,d,t.width)})),V=1/0,M=-1/0,k=0;k<E.length;k++){var R,D,F=null!=(R=W[k])?R:0,B=null!=(D=E[k].width)?D:0;V=Math.min(V,F),M=Math.max(M,F+B)}isFinite(V)||(V=0),isFinite(M)||(M=0);var X,_=Math.max(0,-V),Y=Math.max(0,M-d),P=Math.ceil(d+_+Y),N=Math.ceil(m+C+H);t.baselineCompensationX=_,t.baselineCompensationY=L,t.containerWidth=d,t.canvasWidth=P,t.canvasHeight=N,this.canvasSize=new l.Vector2(P,N);var j=null!=(X=this.size)?X:this.item.transform.size,I=j.x,U=void 0===I?1:I,$=j.y,q=void 0===$?1:$;this.item.transform.size.set(U*P/c*this.SCALE_FACTOR*this.SCALE_FACTOR,q*N/c*this.SCALE_FACTOR*this.SCALE_FACTOR),this.initialized=!0;break;case i.TextOverflow.clip:var G,J=f*c,K=u*c;t.canvasWidth=J,t.canvasHeight=K,t.baselineCompensationX=0,t.baselineCompensationY=0,this.canvasSize=new l.Vector2(J,K),h.width=f,h.height=u;var Q=null!=(G=this.size)?G:this.item.transform.size,Z=Q.x,tt=void 0===Z?1:Z,et=Q.y,it=void 0===et?1:et;this.item.transform.size.set(tt*J/c*this.SCALE_FACTOR*this.SCALE_FACTOR,it*K/c*this.SCALE_FACTOR*this.SCALE_FACTOR),this.initialized=!0;break;case i.TextOverflow.display:if(!this.initialized){var nt=f*c,rt=u*c;this.canvasSize=new l.Vector2(nt,rt),this.item.transform.size.set(a*nt/c*this.SCALE_FACTOR*this.SCALE_FACTOR,s*rt/c*this.SCALE_FACTOR*this.SCALE_FACTOR),this.initialized=!0}}},n.resolveCanvasSize=function(t,e,i,n){var r=Math.max(1,t.maxLineWidth||0),a=Math.max(1,t.totalHeight||0);return e.width=r/i.fontScale,e.height=a/i.fontScale,{canvasWidth:r,canvasHeight:a,contentWidth:t.maxLineWidth,bboxTop:t.bboxTop,bboxBottom:t.bboxBottom,bboxHeight:t.bboxHeight,lines:t.lines}},n.drawTextWithStrategies=function(t,e,i,n,r,a){var o=n.baselineY,l=i.lineOffsets;e.forEach((function(i,n){var r=i.richOptions,s=i.chars,h=l[n],c=o;r.forEach((function(e,n){var r=a.fontScale,o=a.textColor,l=a.fontFamily,f=a.textWeight,u=a.fontStyle,g=e.fontSize,x=e.fontColor,p=void 0===x?o:x,v=e.fontFamily,d=void 0===v?l:v,m=e.fontWeight,y=void 0===m?f:m,S=e.fontStyle,w=void 0===S?u:S,b=g;t.font=w+" "+y+" "+b*r+"px "+d;var T=p[0],A=p[1],O=p[2],z=p[3];t.fillStyle="rgba("+T+", "+A+", "+O+", "+z+")";var C=i.offsetX&&i.offsetX[n]?i.offsetX[n]:0;s[n].forEach((function(e){t.fillText(e.char,h+C+e.x,c)}))})),n<e.length-1&&(o+=e[n+1].lineHeight)}))},n.unsupported=function(t){throw new Error("RichTextComponent does not support "+t+" at runtime.")},n.setShadowOffsetY=function(t){this.unsupported("setShadowOffsetY")},n.setShadowBlur=function(t){this.unsupported("setShadowBlur")},n.setShadowOffsetX=function(t){this.unsupported("setShadowOffsetX")},n.setShadowColor=function(t){this.unsupported("setShadowColor")},n.setOutlineWidth=function(t){this.unsupported("setOutlineWidth")},n.setAutoWidth=function(t){this.unsupported("setAutoWidth")},n.setFontSize=function(t){this.unsupported("setFontSize")},n.setTextBaseline=function(t){console.warn("setTextBaseline 已废弃,请改用 setTextVerticalAlign。本次调用将转调用 setTextVerticalAlign。"),this.setTextVerticalAlign(t)},e}(h);r(j=function(t,e,i,n){var r,a=arguments.length,o=a<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,i):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,e,i,n);else for(var l=t.length-1;l>=0;l--)(r=t[l])&&(o=(a<3?r(o):a>3?r(e,i,o):r(e,i))||o);return a>3&&o&&Object.defineProperty(e,i,o),o}([n(i.DataType.RichTextComponent)],j),[a]);var I="2.8.8";c("rich-text",S),f.info("Plugin rich text version: 2.8.8."),I!==t.version&&console.error("注意:请统一 RichText 插件与 Player 版本,不统一的版本混用会有不可预知的后果!","\nAttention: Please ensure the RichText plugin is synchronized with the Player version. Mixing and matching incompatible versions may result in unpredictable consequences!");export{j as RichTextComponent,S as RichTextLoader,E as escape,H as generateProgram,L as isRichText,z as lexer,C 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.size,n=t.textOverflow,r=void 0===n?i.TextOverflow.clip:n,a=t.textVerticalAlign,o=void 0===a?i.TextVerticalAlign.middle:a,s=t.textAlign,l=void 0===s?i.TextAlignment.left:s,h=t.letterSpace,c=void 0===h?0:h,f=t.lineHeight,u=void 0===f?.571:f,g=t.wrapEnabled,x=void 0!==g&&g,p=t.maxTextWidth,d=void 0===p?350:p,v=t.maxTextHeight,m=void 0===v?1e3:v,y=t.autoResize,w=void 0===y?i.TextSizeMode.autoWidth:y,S=t.useLegacyRichText,T=void 0!==S&&S;this.letterSpace=c,this.lineHeight=u,this.useLegacyRichText=T,this.overflow=r,this.textVerticalAlign=o,this.textAlign=l,this.width=e?e[0]:100,this.height=e?e[1]:100,this.wrapEnabled=x,this.maxTextWidth=d,this.maxTextHeight=m,this.autoResize=w}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.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.8.9";c("rich-text",w),f.info("Plugin rich text version: 2.8.9."),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
|