@galacean/effects-plugin-rich-text 2.7.0 → 2.7.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 +1 -1
- package/dist/alipay.mjs +1 -1
- package/dist/douyin.js +1 -1
- package/dist/douyin.mjs +1 -1
- package/dist/index.js +2 -2
- package/dist/index.min.js +2 -2
- package/dist/index.mjs +2 -2
- package/dist/weapp.js +1 -1
- package/dist/weapp.mjs +1 -1
- package/package.json +2 -2
package/dist/alipay.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@galacean/effects/alipay");function e(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 i=e(t);function n(t,e){return n=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},n(t,e)}function r(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&&n(t,e)}var o,a=function(t){function e(){var e;return(e=t.apply(this,arguments)||this).name="rich-text",e}return r(e,t),e}(t.AbstractPlugin);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 h(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"}(o||(o={}));var l=/^<([a-z]+)(=([^>]+))?>$/,c=/^<\/([a-z]+)>$/,f=[["EscapedChar",/^\\([=<>\\/])/],["ContextStart",/^<[a-z]+(=[^>]+)?>/],["ContextEnd",/^<\/[a-z]+>/],["Text",/^[^</>=\\]+/]],u=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 u(t.slice(2),e.concat({tokenType:"Text",value:r}),i+2)}for(var o,a=h(f);!(o=a()).done;){var s=o.value,l=s[0],c=s[1];if("EscapedChar"!==l){var p=c.exec(t);if(p){var x=p[0],v=x.length;return u(t.slice(v),e.concat({tokenType:l,value:x}),i+v)}}}if(t.length>0)return u(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+'"')},p=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(l);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(c);if(e)return{attributeName:e[1]};throw new Error("Expect an end tag marker at position "+o)}return{}},r=u(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]},h=[];return function t(r,a){for(void 0===r&&(r=[]),void 0===a&&(a="");;){var s=e();if(s)h.push({attributes:r,text:s});else{var l=i(),c=l.attributeName,f=l.attributeParam;if(!c){if(a){var u=n().attributeName;if(!u)throw new Error('Expect an end tag marker "'+a+'" at position '+o+" but found no tag!");if(u!==a)throw new Error('Expect an end tag marker "'+a+'" at position '+o+' but found tag "'+u+'"');return}break}t(r.concat({attributeName:c,attributeParam:null!=f?f:""}),c)}}}(),h};function x(t){return function(e){for(var i,n=h(p(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 v(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 d(t,e){if(void 0===e&&(e=1),"string"!=typeof t||!t)throw new Error("Invalid color string");return t.startsWith("#")?v(t,e):v(function(t){if("string"!=typeof t||!t)throw new Error("Invalid color name provided");if("undefined"==typeof document)throw new 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{e.remove()}throw new Error("Failed to get 2D context for color conversion!")}(t))}"function"==typeof SuppressedError&&SuppressedError;var g=0;exports.RichTextComponent=function(e){function i(t){var i;return(i=e.call(this,t)||this).processedTextOptions=[],i.singleLineHeight=1.571,i.size=null,i.initialized=!1,i.canvasSize=null,i.name="MRichText"+g++,i}r(i,e);var n=i.prototype;return n.generateTextProgram=function(e){var i=this;this.processedTextOptions=[];var n=x((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=d(n.color)),i.processedTextOptions.push(o)}))}));n(e)},n.updateTexture=function(t){if(void 0===t&&(t=!0),this.isDirty&&this.context&&this.canvas){var e=!0===this.textLayout.useLegacyRichText;this.singleLineHeight=e?1.571:1,e?this.updateTextureLegacy(t):this.updateTextureModern(t)}},n.updateTextureLegacy=function(e){var i=this;if(this.isDirty&&this.context&&this.canvas){this.generateTextProgram(this.text);var n=this.textLayout,r=this.textStyle,o=n.overflow,a=n.letterSpace,s=void 0===a?0:a,h=this.context,l=0,c=0;h.save();var f=[],u=r.fontSize*this.textStyle.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,n=t.isNewLine,o=t.fontSize;n&&(f.push(p),l=Math.max(l,p.width),p={richOptions:[],offsetX:[],width:0,lineHeight:u*i.singleLineHeight,offsetY:u*(i.singleLineHeight-1)/2},c+=p.lineHeight),h.font=(t.fontWeight||r.textWeight)+" 10px "+(t.fontFamily||r.fontFamily);var a=h.measureText(e),x=a.width;if(void 0!==a.actualBoundingBoxLeft&&void 0!==a.actualBoundingBoxRight){var v=a.actualBoundingBoxLeft+a.actualBoundingBoxRight;v>0&&(x=Math.max(x,v))}var d=o*i.singleLineHeight*i.textStyle.fontScale;d>p.lineHeight&&(c+=d-p.lineHeight,p.lineHeight=d,p.offsetY=o*i.textStyle.fontScale*(i.singleLineHeight-1)/2),p.offsetX.push(p.width),p.width+=(x<=0?0:x)*o*i.SCALE_FACTOR*i.textStyle.fontScale+e.length*s,p.richOptions.push(t)})),f.push(p),l=Math.max(l,p.width),c+=p.lineHeight,0===l||0===c)return this.isDirty=!1,void h.restore();void 0!==this.size&&null!==this.size||(this.size=this.item.transform.size.clone());var x=this.size,v=x.x,d=void 0===v?1:v,g=x.y,y=void 0===g?1:g;if(!this.initialized){this.canvasSize=this.canvasSize?this.canvasSize:new t.math.Vector2(l,c);var S=this.canvasSize,m=S.x,w=S.y;this.item.transform.size.set(d*m*this.SCALE_FACTOR*this.SCALE_FACTOR,y*w*this.SCALE_FACTOR*this.SCALE_FACTOR),this.size=this.item.transform.size.clone(),this.initialized=!0}t.assertExist(this.canvasSize);var T=this.canvasSize,E=T.x,C=T.y;if(this.textLayout.width=E/r.fontScale,this.textLayout.height=C/r.fontScale,this.canvas.width=E,this.canvas.height=C,h.clearRect(0,0,E,C),h.fillStyle="rgba(255, 255, 255, "+this.ALPHA_FIX_VALUE+")",e||(h.translate(0,C),h.scale(1,-1)),0!==f.length){var L=n.getOffsetY(r,f.length,u*this.singleLineHeight,r.fontSize);f.forEach((function(e,n){var a=e.richOptions,s=e.offsetX,l=e.width,c=l,f=s;if(o===t.spec.TextOverflow.display&&l>E){var u=E/l;c*=u,f=s.map((function(t){return t*u}))}var p=i.textLayout.getOffsetX(r,c);n>0&&(L+=e.lineHeight-e.offsetY),a.forEach((function(e,i){var n=r.fontScale,a=r.textColor,s=r.fontFamily,c=r.textWeight,u=r.fontStyle,x=e.text,v=e.fontSize,d=e.fontColor,g=void 0===d?a:d,y=e.fontFamily,S=void 0===y?s:y,m=e.fontWeight,w=void 0===m?c:m,T=e.fontStyle,C=void 0===T?u:T,z=v;o===t.spec.TextOverflow.display&&l>E&&(z/=l/E);var O=f[i]+p;h.font=C+" "+w+" "+z*n+"px "+S,h.fillStyle="rgba("+g[0]+", "+g[1]+", "+g[2]+", "+g[3]+")",h.fillText(x,O,L)}))}));var z=h.getImageData(0,0,this.canvas.width,this.canvas.height),O=t.Texture.createWithData(this.engine,{data:new Uint8Array(z.data),width:z.width,height:z.height},{flipY:e,magFilter:t.glContext.LINEAR,minFilter:t.glContext.LINEAR,wrapS:t.glContext.CLAMP_TO_EDGE,wrapT:t.glContext.CLAMP_TO_EDGE});this.disposeTextTexture(),this.renderer.texture=O,this.material.setTexture("_MainTex",O),this.isDirty=!1,h.restore()}else h.restore()}},n.updateTextureModern=function(e){var i,n,r=this;this.generateTextProgram(this.text);var o=this.textLayout,a=this.textStyle,s=o.overflow,h=o.letterSpace,l=void 0===h?0:h,c=this.context,f=0,u=0;if(c){c.save();var p=[],x=a.fontSize*this.textStyle.fontScale,v={richOptions:[],offsetX:[],width:0,lineHeight:x*this.singleLineHeight+(this.textLayout.lineGap||0)*this.textStyle.fontScale,offsetY:(this.textLayout.lineGap||0)*this.textStyle.fontScale/2,chars:[]};if(this.processedTextOptions.forEach((function(t){var e=t.text,i=t.isNewLine,n=t.fontSize;i&&(u+=v.lineHeight,p.push(v),f=Math.max(f,v.width),v={richOptions:[],offsetX:[],width:0,lineHeight:x*r.singleLineHeight+(r.textLayout.lineGap||0)*r.textStyle.fontScale,offsetY:(r.textLayout.lineGap||0)*r.textStyle.fontScale/2,chars:[]}),c.font=(t.fontWeight||a.textWeight)+" 10px "+(t.fontFamily||a.fontFamily);var o=n*r.singleLineHeight*r.textStyle.fontScale+(r.textLayout.lineGap||0)*r.textStyle.fontScale;o>v.lineHeight&&(v.lineHeight=o,v.offsetY=(r.textLayout.lineGap||0)*r.textStyle.fontScale/2),v.offsetX.push(v.width);for(var s=0,h=[],d=0;d<e.length;d++){var g=e[d],y=c.measureText(g).width,S=(y<=0?0:y)*n*r.SCALE_FACTOR*r.textStyle.fontScale;h.push({char:g,x:s,width:S}),s+=S+l}v.chars.push(h),v.width+=s,v.richOptions.push(t)})),u+=v.lineHeight,p.push(v),0===(f=Math.max(f,v.width))||0===u)return this.isDirty=!1,void c.restore();void 0!==this.size&&null!==this.size||(this.size=this.item.transform.size.clone());var d=this.size,g=d.x,y=void 0===g?1:g,S=d.y,m=void 0===S?1:S;if(!this.initialized){this.canvasSize=this.canvasSize?this.canvasSize:new t.math.Vector2(f,u);var w=this.canvasSize,T=w.x,E=w.y;this.item.transform.size.set(y*T*this.SCALE_FACTOR*this.SCALE_FACTOR,m*E*this.SCALE_FACTOR*this.SCALE_FACTOR),this.size=this.item.transform.size.clone(),this.initialized=!0}t.assertExist(this.canvasSize);var C=this.canvasSize,L=C.x,z=C.y;if(this.textLayout.width=L/a.fontScale,this.textLayout.height=z/a.fontScale,this.canvas.width=L,this.canvas.height=z,c.clearRect(0,0,L,z),c.fillStyle="rgba(255, 255, 255, "+this.ALPHA_FIX_VALUE+")",e||(c.translate(0,z),c.scale(1,-1)),0!==p.length){var O,b=p.map((function(t){return t.lineHeight})),A=p[0],R=(i=Math).max.apply(i,[].concat(null!=(O=null==A||null==(n=A.richOptions)?void 0:n.map((function(t){return t.fontSize})))?O:[this.textStyle.fontSize]))*this.textStyle.fontScale*this.singleLineHeight,_=o.getOffsetYRich(this.textStyle,b,R);p.forEach((function(e,i){var n=e.richOptions,o=e.offsetX,h=e.width,l=e.chars,f=h,u=o;if(s===t.spec.TextOverflow.display&&h>L){var x=L/h;f*=x,u=o.map((function(t){return t*x})),l.forEach((function(t){t.forEach((function(t){t.x*=x,t.width*=x}))}))}var v=r.textLayout.getOffsetX(a,f);n.forEach((function(i,n){var r=a.fontScale,o=a.textColor,l=a.fontFamily,f=a.textWeight,p=a.fontStyle,x=i.fontSize,d=i.fontColor,g=void 0===d?o:d,y=i.fontFamily,S=void 0===y?l:y,m=i.fontWeight,w=void 0===m?f:m,T=i.fontStyle,E=void 0===T?p:T,C=x;s===t.spec.TextOverflow.display&&h>L&&(C/=h/L);var z=u[n]+v;c.font=E+" "+w+" "+C*r+"px "+S,c.fillStyle="rgba("+g[0]+", "+g[1]+", "+g[2]+", "+g[3]+")",e.chars[n].forEach((function(t){c.fillText(t.char,z+t.x,_)}))})),i<p.length-1&&(_+=b[i+1])}));var H=c.getImageData(0,0,this.canvas.width,this.canvas.height),F=t.Texture.createWithData(this.engine,{data:new Uint8Array(H.data),width:H.width,height:H.height},{flipY:e,magFilter:t.glContext.LINEAR,minFilter:t.glContext.LINEAR,wrapS:t.glContext.CLAMP_TO_EDGE,wrapT:t.glContext.CLAMP_TO_EDGE});this.renderer.texture=F,this.material.setTexture("_MainTex",F),this.isDirty=!1,c.restore()}else c.restore()}},n.setShadowOffsetY=function(t){throw new Error("Method not implemented.")},n.setShadowBlur=function(t){throw new Error("Method not implemented.")},n.setShadowOffsetX=function(t){throw new Error("Method not implemented.")},n.setShadowColor=function(t){throw new Error("Method not implemented.")},n.setOutlineWidth=function(t){throw new Error("Method not implemented.")},n.setAutoWidth=function(t){throw new Error("Method not implemented.")},n.updateWithOptions=function(e){this.textStyle=new t.TextStyle(e),this.textLayout=new t.TextLayout(e),this.textLayout.textBaseline=e.textBaseline||t.spec.TextBaseline.middle,this.text=e.text?e.text.toString():" "},n.renderText=function(e){var i=e.size;i&&(this.canvasSize=new t.math.Vector2(i[0],i[1])),this.updateTexture()},i}(t.TextComponent),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);var y="2.7.0";t.registerPlugin("rich-text",a,t.VFXItem),t.logger.info("Plugin rich text version: 2.7.0."),y!==i.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=a,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=x,exports.isRichText=function(t){var e=u(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(l)[1]:i.match(c)[1]}})))},exports.lexer=u,exports.richTextParser=p,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=y;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@galacean/effects/alipay");function e(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 i=e(t);function n(t,e){return n=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},n(t,e)}function r(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&&n(t,e)}var o,a=function(t){function e(){var e;return(e=t.apply(this,arguments)||this).name="rich-text",e}return r(e,t),e}(t.AbstractPlugin);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 h(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"}(o||(o={}));var l=/^<([a-z]+)(=([^>]+))?>$/,c=/^<\/([a-z]+)>$/,f=[["EscapedChar",/^\\([=<>\\/])/],["ContextStart",/^<[a-z]+(=[^>]+)?>/],["ContextEnd",/^<\/[a-z]+>/],["Text",/^[^</>=\\]+/]],u=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 u(t.slice(2),e.concat({tokenType:"Text",value:r}),i+2)}for(var o,a=h(f);!(o=a()).done;){var s=o.value,l=s[0],c=s[1];if("EscapedChar"!==l){var p=c.exec(t);if(p){var x=p[0],v=x.length;return u(t.slice(v),e.concat({tokenType:l,value:x}),i+v)}}}if(t.length>0)return u(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+'"')},p=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(l);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(c);if(e)return{attributeName:e[1]};throw new Error("Expect an end tag marker at position "+o)}return{}},r=u(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]},h=[];return function t(r,a){for(void 0===r&&(r=[]),void 0===a&&(a="");;){var s=e();if(s)h.push({attributes:r,text:s});else{var l=i(),c=l.attributeName,f=l.attributeParam;if(!c){if(a){var u=n().attributeName;if(!u)throw new Error('Expect an end tag marker "'+a+'" at position '+o+" but found no tag!");if(u!==a)throw new Error('Expect an end tag marker "'+a+'" at position '+o+' but found tag "'+u+'"');return}break}t(r.concat({attributeName:c,attributeParam:null!=f?f:""}),c)}}}(),h};function x(t){return function(e){for(var i,n=h(p(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 v(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 d(t,e){if(void 0===e&&(e=1),"string"!=typeof t||!t)throw new Error("Invalid color string");return t.startsWith("#")?v(t,e):v(function(t){if("string"!=typeof t||!t)throw new Error("Invalid color name provided");if("undefined"==typeof document)throw new 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{e.remove()}throw new Error("Failed to get 2D context for color conversion!")}(t))}"function"==typeof SuppressedError&&SuppressedError;var g=0;exports.RichTextComponent=function(e){function i(t){var i;return(i=e.call(this,t)||this).processedTextOptions=[],i.singleLineHeight=1.571,i.size=null,i.initialized=!1,i.canvasSize=null,i.name="MRichText"+g++,i}r(i,e);var n=i.prototype;return n.generateTextProgram=function(e){var i=this;this.processedTextOptions=[];var n=x((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=d(n.color)),i.processedTextOptions.push(o)}))}));n(e)},n.updateTexture=function(t){if(void 0===t&&(t=!0),this.isDirty&&this.context&&this.canvas){var e=!0===this.textLayout.useLegacyRichText;this.singleLineHeight=e?1.571:1,e?this.updateTextureLegacy(t):this.updateTextureModern(t)}},n.updateTextureLegacy=function(e){var i=this;if(this.isDirty&&this.context&&this.canvas){this.generateTextProgram(this.text);var n=this.textLayout,r=this.textStyle,o=n.overflow,a=n.letterSpace,s=void 0===a?0:a,h=this.context,l=0,c=0;h.save();var f=[],u=r.fontSize*this.textStyle.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,n=t.isNewLine,o=t.fontSize;n&&(f.push(p),l=Math.max(l,p.width),p={richOptions:[],offsetX:[],width:0,lineHeight:u*i.singleLineHeight,offsetY:u*(i.singleLineHeight-1)/2},c+=p.lineHeight),h.font=(t.fontWeight||r.textWeight)+" 10px "+(t.fontFamily||r.fontFamily);var a=h.measureText(e),x=a.width;if(void 0!==a.actualBoundingBoxLeft&&void 0!==a.actualBoundingBoxRight){var v=a.actualBoundingBoxLeft+a.actualBoundingBoxRight;v>0&&(x=Math.max(x,v))}var d=o*i.singleLineHeight*i.textStyle.fontScale;d>p.lineHeight&&(c+=d-p.lineHeight,p.lineHeight=d,p.offsetY=o*i.textStyle.fontScale*(i.singleLineHeight-1)/2),p.offsetX.push(p.width),p.width+=(x<=0?0:x)*o*i.SCALE_FACTOR*i.textStyle.fontScale+e.length*s,p.richOptions.push(t)})),f.push(p),l=Math.max(l,p.width),c+=p.lineHeight,0===l||0===c)return this.isDirty=!1,void h.restore();void 0!==this.size&&null!==this.size||(this.size=this.item.transform.size.clone());var x=this.size,v=x.x,d=void 0===v?1:v,g=x.y,y=void 0===g?1:g;if(!this.initialized){this.canvasSize=this.canvasSize?this.canvasSize:new t.math.Vector2(l,c);var S=this.canvasSize,m=S.x,w=S.y;this.item.transform.size.set(d*m*this.SCALE_FACTOR*this.SCALE_FACTOR,y*w*this.SCALE_FACTOR*this.SCALE_FACTOR),this.size=this.item.transform.size.clone(),this.initialized=!0}t.assertExist(this.canvasSize);var T=this.canvasSize,E=T.x,C=T.y;if(this.textLayout.width=E/r.fontScale,this.textLayout.height=C/r.fontScale,this.canvas.width=E,this.canvas.height=C,h.clearRect(0,0,E,C),h.fillStyle="rgba(255, 255, 255, "+this.ALPHA_FIX_VALUE+")",e||(h.translate(0,C),h.scale(1,-1)),0!==f.length){var L=n.getOffsetY(r,f.length,u*this.singleLineHeight,r.fontSize);f.forEach((function(e,n){var a=e.richOptions,s=e.offsetX,l=e.width,c=l,f=s;if(o===t.spec.TextOverflow.display&&l>E){var u=E/l;c*=u,f=s.map((function(t){return t*u}))}var p=i.textLayout.getOffsetX(r,c);n>0&&(L+=e.lineHeight-e.offsetY),a.forEach((function(e,i){var n=r.fontScale,a=r.textColor,s=r.fontFamily,c=r.textWeight,u=r.fontStyle,x=e.text,v=e.fontSize,d=e.fontColor,g=void 0===d?a:d,y=e.fontFamily,S=void 0===y?s:y,m=e.fontWeight,w=void 0===m?c:m,T=e.fontStyle,C=void 0===T?u:T,z=v;o===t.spec.TextOverflow.display&&l>E&&(z/=l/E);var O=f[i]+p;h.font=C+" "+w+" "+z*n+"px "+S,h.fillStyle="rgba("+g[0]+", "+g[1]+", "+g[2]+", "+g[3]+")",h.fillText(x,O,L)}))}));var z=h.getImageData(0,0,this.canvas.width,this.canvas.height),O=t.Texture.createWithData(this.engine,{data:new Uint8Array(z.data),width:z.width,height:z.height},{flipY:e,magFilter:t.glContext.LINEAR,minFilter:t.glContext.LINEAR,wrapS:t.glContext.CLAMP_TO_EDGE,wrapT:t.glContext.CLAMP_TO_EDGE});this.disposeTextTexture(),this.renderer.texture=O,this.material.setTexture("_MainTex",O),this.isDirty=!1,h.restore()}else h.restore()}},n.updateTextureModern=function(e){var i,n,r=this;this.generateTextProgram(this.text);var o=this.textLayout,a=this.textStyle,s=o.overflow,h=o.letterSpace,l=void 0===h?0:h,c=this.context,f=0,u=0;if(c){c.save();var p=[],x=a.fontSize*this.textStyle.fontScale,v={richOptions:[],offsetX:[],width:0,lineHeight:x*this.singleLineHeight+(this.textLayout.lineGap||0)*this.textStyle.fontScale,offsetY:(this.textLayout.lineGap||0)*this.textStyle.fontScale/2,chars:[]};if(this.processedTextOptions.forEach((function(t){var e=t.text,i=t.isNewLine,n=t.fontSize;i&&(u+=v.lineHeight,p.push(v),f=Math.max(f,v.width),v={richOptions:[],offsetX:[],width:0,lineHeight:x*r.singleLineHeight+(r.textLayout.lineGap||0)*r.textStyle.fontScale,offsetY:(r.textLayout.lineGap||0)*r.textStyle.fontScale/2,chars:[]}),c.font=(t.fontWeight||a.textWeight)+" 10px "+(t.fontFamily||a.fontFamily);var o=n*r.singleLineHeight*r.textStyle.fontScale+(r.textLayout.lineGap||0)*r.textStyle.fontScale;o>v.lineHeight&&(v.lineHeight=o,v.offsetY=(r.textLayout.lineGap||0)*r.textStyle.fontScale/2),v.offsetX.push(v.width);for(var s=0,h=[],d=0;d<e.length;d++){var g=e[d],y=c.measureText(g).width,S=(y<=0?0:y)*n*r.SCALE_FACTOR*r.textStyle.fontScale;h.push({char:g,x:s,width:S}),s+=S+l}v.chars.push(h),v.width+=s,v.richOptions.push(t)})),u+=v.lineHeight,p.push(v),0===(f=Math.max(f,v.width))||0===u)return this.isDirty=!1,void c.restore();void 0!==this.size&&null!==this.size||(this.size=this.item.transform.size.clone());var d=this.size,g=d.x,y=void 0===g?1:g,S=d.y,m=void 0===S?1:S;if(!this.initialized){this.canvasSize=this.canvasSize?this.canvasSize:new t.math.Vector2(f,u);var w=this.canvasSize,T=w.x,E=w.y;this.item.transform.size.set(y*T*this.SCALE_FACTOR*this.SCALE_FACTOR,m*E*this.SCALE_FACTOR*this.SCALE_FACTOR),this.size=this.item.transform.size.clone(),this.initialized=!0}t.assertExist(this.canvasSize);var C=this.canvasSize,L=C.x,z=C.y;if(this.textLayout.width=L/a.fontScale,this.textLayout.height=z/a.fontScale,this.canvas.width=L,this.canvas.height=z,c.clearRect(0,0,L,z),c.fillStyle="rgba(255, 255, 255, "+this.ALPHA_FIX_VALUE+")",e||(c.translate(0,z),c.scale(1,-1)),0!==p.length){var O,b=p.map((function(t){return t.lineHeight})),A=p[0],R=(i=Math).max.apply(i,[].concat(null!=(O=null==A||null==(n=A.richOptions)?void 0:n.map((function(t){return t.fontSize})))?O:[this.textStyle.fontSize]))*this.textStyle.fontScale*this.singleLineHeight,_=o.getOffsetYRich(this.textStyle,b,R);p.forEach((function(e,i){var n=e.richOptions,o=e.offsetX,h=e.width,l=e.chars,f=h,u=o;if(s===t.spec.TextOverflow.display&&h>L){var x=L/h;f*=x,u=o.map((function(t){return t*x})),l.forEach((function(t){t.forEach((function(t){t.x*=x,t.width*=x}))}))}var v=r.textLayout.getOffsetX(a,f);n.forEach((function(i,n){var r=a.fontScale,o=a.textColor,l=a.fontFamily,f=a.textWeight,p=a.fontStyle,x=i.fontSize,d=i.fontColor,g=void 0===d?o:d,y=i.fontFamily,S=void 0===y?l:y,m=i.fontWeight,w=void 0===m?f:m,T=i.fontStyle,E=void 0===T?p:T,C=x;s===t.spec.TextOverflow.display&&h>L&&(C/=h/L);var z=u[n]+v;c.font=E+" "+w+" "+C*r+"px "+S,c.fillStyle="rgba("+g[0]+", "+g[1]+", "+g[2]+", "+g[3]+")",e.chars[n].forEach((function(t){c.fillText(t.char,z+t.x,_)}))})),i<p.length-1&&(_+=b[i+1])}));var H=c.getImageData(0,0,this.canvas.width,this.canvas.height),F=t.Texture.createWithData(this.engine,{data:new Uint8Array(H.data),width:H.width,height:H.height},{flipY:e,magFilter:t.glContext.LINEAR,minFilter:t.glContext.LINEAR,wrapS:t.glContext.CLAMP_TO_EDGE,wrapT:t.glContext.CLAMP_TO_EDGE});this.renderer.texture=F,this.material.setTexture("_MainTex",F),this.isDirty=!1,c.restore()}else c.restore()}},n.setShadowOffsetY=function(t){throw new Error("Method not implemented.")},n.setShadowBlur=function(t){throw new Error("Method not implemented.")},n.setShadowOffsetX=function(t){throw new Error("Method not implemented.")},n.setShadowColor=function(t){throw new Error("Method not implemented.")},n.setOutlineWidth=function(t){throw new Error("Method not implemented.")},n.setAutoWidth=function(t){throw new Error("Method not implemented.")},n.updateWithOptions=function(e){this.textStyle=new t.TextStyle(e),this.textLayout=new t.TextLayout(e),this.textLayout.textBaseline=e.textBaseline||t.spec.TextBaseline.middle,this.text=e.text?e.text.toString():" "},n.renderText=function(e){var i=e.size;i&&(this.canvasSize=new t.math.Vector2(i[0],i[1])),this.updateTexture()},i}(t.TextComponent),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);var y="2.7.2";t.registerPlugin("rich-text",a,t.VFXItem),t.logger.info("Plugin rich text version: 2.7.2."),y!==i.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=a,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=x,exports.isRichText=function(t){var e=u(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(l)[1]:i.match(c)[1]}})))},exports.lexer=u,exports.richTextParser=p,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=y;
|
|
2
2
|
//# sourceMappingURL=alipay.js.map
|
package/dist/alipay.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import*as t from"@galacean/effects/alipay";import{AbstractPlugin as e,effectsClass as i,spec as n,math as r,assertExist as o,Texture as a,glContext as s,TextStyle as h,TextLayout as l,TextComponent as f,registerPlugin as c,VFXItem as u,logger as v}from"@galacean/effects/alipay";function p(t,e){return p=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},p(t,e)}function d(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&&p(t,e)}var x,g=function(t){function e(){var e;return(e=t.apply(this,arguments)||this).name="rich-text",e}return d(e,t),e}(e);function y(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 S(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 y(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)?y(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"}(x||(x={}));var m=/^<([a-z]+)(=([^>]+))?>$/,w=/^<\/([a-z]+)>$/,T=[["EscapedChar",/^\\([=<>\\/])/],["ContextStart",/^<[a-z]+(=[^>]+)?>/],["ContextEnd",/^<\/[a-z]+>/],["Text",/^[^</>=\\]+/]],E=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 E(t.slice(2),e.concat({tokenType:"Text",value:r}),i+2)}for(var o,a=S(T);!(o=a()).done;){var s=o.value,h=s[0],l=s[1];if("EscapedChar"!==h){var f=l.exec(t);if(f){var c=f[0],u=c.length;return E(t.slice(u),e.concat({tokenType:h,value:c}),i+u)}}}if(t.length>0)return E(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+'"')},L=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(m);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(w);if(e)return{attributeName:e[1]};throw new Error("Expect an end tag marker at position "+o)}return{}},r=E(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]},h=[];return function t(r,a){for(void 0===r&&(r=[]),void 0===a&&(a="");;){var s=e();if(s)h.push({attributes:r,text:s});else{var l=i(),f=l.attributeName,c=l.attributeParam;if(!f){if(a){var u=n().attributeName;if(!u)throw new Error('Expect an end tag marker "'+a+'" at position '+o+" but found no tag!");if(u!==a)throw new Error('Expect an end tag marker "'+a+'" at position '+o+' but found tag "'+u+'"');return}break}t(r.concat({attributeName:f,attributeParam:null!=c?c:""}),f)}}}(),h};function z(t){return function(e){for(var i,n=S(L(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 C(t){var e=E(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(m)[1]:i.match(w)[1]}})))}function O(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 b(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 A(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 H(t,e){if(void 0===e&&(e=1),"string"!=typeof t||!t)throw new Error("Invalid color string");return t.startsWith("#")?A(t,e):A(function(t){if("string"!=typeof t||!t)throw new Error("Invalid color name provided");if("undefined"==typeof document)throw new 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{e.remove()}throw new Error("Failed to get 2D context for color conversion!")}(t))}"function"==typeof SuppressedError&&SuppressedError;var _=0,R=function(t){function e(e){var i;return(i=t.call(this,e)||this).processedTextOptions=[],i.singleLineHeight=1.571,i.size=null,i.initialized=!1,i.canvasSize=null,i.name="MRichText"+_++,i}d(e,t);var i=e.prototype;return i.generateTextProgram=function(t){var e=this;this.processedTextOptions=[];var i=z((function(t,i){/^\n+$/.test(t)&&(t=t.replace(/\n/g,"\n ")),t.split("\n").forEach((function(t,r){var o={text:t,fontSize:e.textStyle.fontSize,isNewLine:!1};r>0&&(o.isNewLine=!0),"b"in i&&(o.fontWeight=n.TextWeight.bold),"i"in i&&(o.fontStyle=n.FontStyle.italic),"size"in i&&i.size&&(o.fontSize=parseInt(i.size,10)),"color"in i&&i.color&&(o.fontColor=H(i.color)),e.processedTextOptions.push(o)}))}));i(t)},i.updateTexture=function(t){if(void 0===t&&(t=!0),this.isDirty&&this.context&&this.canvas){var e=!0===this.textLayout.useLegacyRichText;this.singleLineHeight=e?1.571:1,e?this.updateTextureLegacy(t):this.updateTextureModern(t)}},i.updateTextureLegacy=function(t){var e=this;if(this.isDirty&&this.context&&this.canvas){this.generateTextProgram(this.text);var i=this.textLayout,h=this.textStyle,l=i.overflow,f=i.letterSpace,c=void 0===f?0:f,u=this.context,v=0,p=0;u.save();var d=[],x=h.fontSize*this.textStyle.fontScale,g={richOptions:[],offsetX:[],width:0,lineHeight:x*this.singleLineHeight,offsetY:x*(this.singleLineHeight-1)/2};if(this.processedTextOptions.forEach((function(t){var i=t.text,n=t.isNewLine,r=t.fontSize;n&&(d.push(g),v=Math.max(v,g.width),g={richOptions:[],offsetX:[],width:0,lineHeight:x*e.singleLineHeight,offsetY:x*(e.singleLineHeight-1)/2},p+=g.lineHeight),u.font=(t.fontWeight||h.textWeight)+" 10px "+(t.fontFamily||h.fontFamily);var o=u.measureText(i),a=o.width;if(void 0!==o.actualBoundingBoxLeft&&void 0!==o.actualBoundingBoxRight){var s=o.actualBoundingBoxLeft+o.actualBoundingBoxRight;s>0&&(a=Math.max(a,s))}var l=r*e.singleLineHeight*e.textStyle.fontScale;l>g.lineHeight&&(p+=l-g.lineHeight,g.lineHeight=l,g.offsetY=r*e.textStyle.fontScale*(e.singleLineHeight-1)/2),g.offsetX.push(g.width),g.width+=(a<=0?0:a)*r*e.SCALE_FACTOR*e.textStyle.fontScale+i.length*c,g.richOptions.push(t)})),d.push(g),v=Math.max(v,g.width),p+=g.lineHeight,0===v||0===p)return this.isDirty=!1,void u.restore();void 0!==this.size&&null!==this.size||(this.size=this.item.transform.size.clone());var y=this.size,S=y.x,m=void 0===S?1:S,w=y.y,T=void 0===w?1:w;if(!this.initialized){this.canvasSize=this.canvasSize?this.canvasSize:new r.Vector2(v,p);var E=this.canvasSize,L=E.x,z=E.y;this.item.transform.size.set(m*L*this.SCALE_FACTOR*this.SCALE_FACTOR,T*z*this.SCALE_FACTOR*this.SCALE_FACTOR),this.size=this.item.transform.size.clone(),this.initialized=!0}o(this.canvasSize);var C=this.canvasSize,O=C.x,b=C.y;if(this.textLayout.width=O/h.fontScale,this.textLayout.height=b/h.fontScale,this.canvas.width=O,this.canvas.height=b,u.clearRect(0,0,O,b),u.fillStyle="rgba(255, 255, 255, "+this.ALPHA_FIX_VALUE+")",t||(u.translate(0,b),u.scale(1,-1)),0!==d.length){var A=i.getOffsetY(h,d.length,x*this.singleLineHeight,h.fontSize);d.forEach((function(t,i){var r=t.richOptions,o=t.offsetX,a=t.width,s=a,f=o;if(l===n.TextOverflow.display&&a>O){var c=O/a;s*=c,f=o.map((function(t){return t*c}))}var v=e.textLayout.getOffsetX(h,s);i>0&&(A+=t.lineHeight-t.offsetY),r.forEach((function(t,e){var i=h.fontScale,r=h.textColor,o=h.fontFamily,s=h.textWeight,c=h.fontStyle,p=t.text,d=t.fontSize,x=t.fontColor,g=void 0===x?r:x,y=t.fontFamily,S=void 0===y?o:y,m=t.fontWeight,w=void 0===m?s:m,T=t.fontStyle,E=void 0===T?c:T,L=d;l===n.TextOverflow.display&&a>O&&(L/=a/O);var z=f[e]+v;u.font=E+" "+w+" "+L*i+"px "+S,u.fillStyle="rgba("+g[0]+", "+g[1]+", "+g[2]+", "+g[3]+")",u.fillText(p,z,A)}))}));var H=u.getImageData(0,0,this.canvas.width,this.canvas.height),_=a.createWithData(this.engine,{data:new Uint8Array(H.data),width:H.width,height:H.height},{flipY:t,magFilter:s.LINEAR,minFilter:s.LINEAR,wrapS:s.CLAMP_TO_EDGE,wrapT:s.CLAMP_TO_EDGE});this.disposeTextTexture(),this.renderer.texture=_,this.material.setTexture("_MainTex",_),this.isDirty=!1,u.restore()}else u.restore()}},i.updateTextureModern=function(t){var e,i,h=this;this.generateTextProgram(this.text);var l=this.textLayout,f=this.textStyle,c=l.overflow,u=l.letterSpace,v=void 0===u?0:u,p=this.context,d=0,x=0;if(p){p.save();var g=[],y=f.fontSize*this.textStyle.fontScale,S={richOptions:[],offsetX:[],width:0,lineHeight:y*this.singleLineHeight+(this.textLayout.lineGap||0)*this.textStyle.fontScale,offsetY:(this.textLayout.lineGap||0)*this.textStyle.fontScale/2,chars:[]};if(this.processedTextOptions.forEach((function(t){var e=t.text,i=t.isNewLine,n=t.fontSize;i&&(x+=S.lineHeight,g.push(S),d=Math.max(d,S.width),S={richOptions:[],offsetX:[],width:0,lineHeight:y*h.singleLineHeight+(h.textLayout.lineGap||0)*h.textStyle.fontScale,offsetY:(h.textLayout.lineGap||0)*h.textStyle.fontScale/2,chars:[]}),p.font=(t.fontWeight||f.textWeight)+" 10px "+(t.fontFamily||f.fontFamily);var r=n*h.singleLineHeight*h.textStyle.fontScale+(h.textLayout.lineGap||0)*h.textStyle.fontScale;r>S.lineHeight&&(S.lineHeight=r,S.offsetY=(h.textLayout.lineGap||0)*h.textStyle.fontScale/2),S.offsetX.push(S.width);for(var o=0,a=[],s=0;s<e.length;s++){var l=e[s],c=p.measureText(l).width,u=(c<=0?0:c)*n*h.SCALE_FACTOR*h.textStyle.fontScale;a.push({char:l,x:o,width:u}),o+=u+v}S.chars.push(a),S.width+=o,S.richOptions.push(t)})),x+=S.lineHeight,g.push(S),0===(d=Math.max(d,S.width))||0===x)return this.isDirty=!1,void p.restore();void 0!==this.size&&null!==this.size||(this.size=this.item.transform.size.clone());var m=this.size,w=m.x,T=void 0===w?1:w,E=m.y,L=void 0===E?1:E;if(!this.initialized){this.canvasSize=this.canvasSize?this.canvasSize:new r.Vector2(d,x);var z=this.canvasSize,C=z.x,O=z.y;this.item.transform.size.set(T*C*this.SCALE_FACTOR*this.SCALE_FACTOR,L*O*this.SCALE_FACTOR*this.SCALE_FACTOR),this.size=this.item.transform.size.clone(),this.initialized=!0}o(this.canvasSize);var b=this.canvasSize,A=b.x,H=b.y;if(this.textLayout.width=A/f.fontScale,this.textLayout.height=H/f.fontScale,this.canvas.width=A,this.canvas.height=H,p.clearRect(0,0,A,H),p.fillStyle="rgba(255, 255, 255, "+this.ALPHA_FIX_VALUE+")",t||(p.translate(0,H),p.scale(1,-1)),0!==g.length){var _,R=g.map((function(t){return t.lineHeight})),F=g[0],M=(e=Math).max.apply(e,[].concat(null!=(_=null==F||null==(i=F.richOptions)?void 0:i.map((function(t){return t.fontSize})))?_:[this.textStyle.fontSize]))*this.textStyle.fontScale*this.singleLineHeight,k=l.getOffsetYRich(this.textStyle,R,M);g.forEach((function(t,e){var i=t.richOptions,r=t.offsetX,o=t.width,a=t.chars,s=o,l=r;if(c===n.TextOverflow.display&&o>A){var u=A/o;s*=u,l=r.map((function(t){return t*u})),a.forEach((function(t){t.forEach((function(t){t.x*=u,t.width*=u}))}))}var v=h.textLayout.getOffsetX(f,s);i.forEach((function(e,i){var r=f.fontScale,a=f.textColor,s=f.fontFamily,h=f.textWeight,u=f.fontStyle,d=e.fontSize,x=e.fontColor,g=void 0===x?a:x,y=e.fontFamily,S=void 0===y?s:y,m=e.fontWeight,w=void 0===m?h:m,T=e.fontStyle,E=void 0===T?u:T,L=d;c===n.TextOverflow.display&&o>A&&(L/=o/A);var z=l[i]+v;p.font=E+" "+w+" "+L*r+"px "+S,p.fillStyle="rgba("+g[0]+", "+g[1]+", "+g[2]+", "+g[3]+")",t.chars[i].forEach((function(t){p.fillText(t.char,z+t.x,k)}))})),e<g.length-1&&(k+=R[e+1])}));var P=p.getImageData(0,0,this.canvas.width,this.canvas.height),I=a.createWithData(this.engine,{data:new Uint8Array(P.data),width:P.width,height:P.height},{flipY:t,magFilter:s.LINEAR,minFilter:s.LINEAR,wrapS:s.CLAMP_TO_EDGE,wrapT:s.CLAMP_TO_EDGE});this.renderer.texture=I,this.material.setTexture("_MainTex",I),this.isDirty=!1,p.restore()}else p.restore()}},i.setShadowOffsetY=function(t){throw new Error("Method not implemented.")},i.setShadowBlur=function(t){throw new Error("Method not implemented.")},i.setShadowOffsetX=function(t){throw new Error("Method not implemented.")},i.setShadowColor=function(t){throw new Error("Method not implemented.")},i.setOutlineWidth=function(t){throw new Error("Method not implemented.")},i.setAutoWidth=function(t){throw new Error("Method not implemented.")},i.updateWithOptions=function(t){this.textStyle=new h(t),this.textLayout=new l(t),this.textLayout.textBaseline=t.textBaseline||n.TextBaseline.middle,this.text=t.text?t.text.toString():" "},i.renderText=function(t){var e=t.size;e&&(this.canvasSize=new r.Vector2(e[0],e[1])),this.updateTexture()},e}(f);R=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}([i(n.DataType.RichTextComponent)],R);var F="2.7.0";c("rich-text",g,u),v.info("Plugin rich text version: 2.7.0."),F!==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{R as RichTextComponent,g as RichTextLoader,O as escape,z as generateProgram,C as isRichText,E as lexer,L as richTextParser,b as unescape,F as version};
|
|
1
|
+
import*as t from"@galacean/effects/alipay";import{AbstractPlugin as e,effectsClass as i,spec as n,math as r,assertExist as o,Texture as a,glContext as s,TextStyle as h,TextLayout as l,TextComponent as f,registerPlugin as c,VFXItem as u,logger as v}from"@galacean/effects/alipay";function p(t,e){return p=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},p(t,e)}function d(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&&p(t,e)}var x,g=function(t){function e(){var e;return(e=t.apply(this,arguments)||this).name="rich-text",e}return d(e,t),e}(e);function y(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 S(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 y(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)?y(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"}(x||(x={}));var m=/^<([a-z]+)(=([^>]+))?>$/,w=/^<\/([a-z]+)>$/,T=[["EscapedChar",/^\\([=<>\\/])/],["ContextStart",/^<[a-z]+(=[^>]+)?>/],["ContextEnd",/^<\/[a-z]+>/],["Text",/^[^</>=\\]+/]],E=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 E(t.slice(2),e.concat({tokenType:"Text",value:r}),i+2)}for(var o,a=S(T);!(o=a()).done;){var s=o.value,h=s[0],l=s[1];if("EscapedChar"!==h){var f=l.exec(t);if(f){var c=f[0],u=c.length;return E(t.slice(u),e.concat({tokenType:h,value:c}),i+u)}}}if(t.length>0)return E(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+'"')},L=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(m);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(w);if(e)return{attributeName:e[1]};throw new Error("Expect an end tag marker at position "+o)}return{}},r=E(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]},h=[];return function t(r,a){for(void 0===r&&(r=[]),void 0===a&&(a="");;){var s=e();if(s)h.push({attributes:r,text:s});else{var l=i(),f=l.attributeName,c=l.attributeParam;if(!f){if(a){var u=n().attributeName;if(!u)throw new Error('Expect an end tag marker "'+a+'" at position '+o+" but found no tag!");if(u!==a)throw new Error('Expect an end tag marker "'+a+'" at position '+o+' but found tag "'+u+'"');return}break}t(r.concat({attributeName:f,attributeParam:null!=c?c:""}),f)}}}(),h};function z(t){return function(e){for(var i,n=S(L(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 C(t){var e=E(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(m)[1]:i.match(w)[1]}})))}function O(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 b(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 A(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 H(t,e){if(void 0===e&&(e=1),"string"!=typeof t||!t)throw new Error("Invalid color string");return t.startsWith("#")?A(t,e):A(function(t){if("string"!=typeof t||!t)throw new Error("Invalid color name provided");if("undefined"==typeof document)throw new 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{e.remove()}throw new Error("Failed to get 2D context for color conversion!")}(t))}"function"==typeof SuppressedError&&SuppressedError;var _=0,R=function(t){function e(e){var i;return(i=t.call(this,e)||this).processedTextOptions=[],i.singleLineHeight=1.571,i.size=null,i.initialized=!1,i.canvasSize=null,i.name="MRichText"+_++,i}d(e,t);var i=e.prototype;return i.generateTextProgram=function(t){var e=this;this.processedTextOptions=[];var i=z((function(t,i){/^\n+$/.test(t)&&(t=t.replace(/\n/g,"\n ")),t.split("\n").forEach((function(t,r){var o={text:t,fontSize:e.textStyle.fontSize,isNewLine:!1};r>0&&(o.isNewLine=!0),"b"in i&&(o.fontWeight=n.TextWeight.bold),"i"in i&&(o.fontStyle=n.FontStyle.italic),"size"in i&&i.size&&(o.fontSize=parseInt(i.size,10)),"color"in i&&i.color&&(o.fontColor=H(i.color)),e.processedTextOptions.push(o)}))}));i(t)},i.updateTexture=function(t){if(void 0===t&&(t=!0),this.isDirty&&this.context&&this.canvas){var e=!0===this.textLayout.useLegacyRichText;this.singleLineHeight=e?1.571:1,e?this.updateTextureLegacy(t):this.updateTextureModern(t)}},i.updateTextureLegacy=function(t){var e=this;if(this.isDirty&&this.context&&this.canvas){this.generateTextProgram(this.text);var i=this.textLayout,h=this.textStyle,l=i.overflow,f=i.letterSpace,c=void 0===f?0:f,u=this.context,v=0,p=0;u.save();var d=[],x=h.fontSize*this.textStyle.fontScale,g={richOptions:[],offsetX:[],width:0,lineHeight:x*this.singleLineHeight,offsetY:x*(this.singleLineHeight-1)/2};if(this.processedTextOptions.forEach((function(t){var i=t.text,n=t.isNewLine,r=t.fontSize;n&&(d.push(g),v=Math.max(v,g.width),g={richOptions:[],offsetX:[],width:0,lineHeight:x*e.singleLineHeight,offsetY:x*(e.singleLineHeight-1)/2},p+=g.lineHeight),u.font=(t.fontWeight||h.textWeight)+" 10px "+(t.fontFamily||h.fontFamily);var o=u.measureText(i),a=o.width;if(void 0!==o.actualBoundingBoxLeft&&void 0!==o.actualBoundingBoxRight){var s=o.actualBoundingBoxLeft+o.actualBoundingBoxRight;s>0&&(a=Math.max(a,s))}var l=r*e.singleLineHeight*e.textStyle.fontScale;l>g.lineHeight&&(p+=l-g.lineHeight,g.lineHeight=l,g.offsetY=r*e.textStyle.fontScale*(e.singleLineHeight-1)/2),g.offsetX.push(g.width),g.width+=(a<=0?0:a)*r*e.SCALE_FACTOR*e.textStyle.fontScale+i.length*c,g.richOptions.push(t)})),d.push(g),v=Math.max(v,g.width),p+=g.lineHeight,0===v||0===p)return this.isDirty=!1,void u.restore();void 0!==this.size&&null!==this.size||(this.size=this.item.transform.size.clone());var y=this.size,S=y.x,m=void 0===S?1:S,w=y.y,T=void 0===w?1:w;if(!this.initialized){this.canvasSize=this.canvasSize?this.canvasSize:new r.Vector2(v,p);var E=this.canvasSize,L=E.x,z=E.y;this.item.transform.size.set(m*L*this.SCALE_FACTOR*this.SCALE_FACTOR,T*z*this.SCALE_FACTOR*this.SCALE_FACTOR),this.size=this.item.transform.size.clone(),this.initialized=!0}o(this.canvasSize);var C=this.canvasSize,O=C.x,b=C.y;if(this.textLayout.width=O/h.fontScale,this.textLayout.height=b/h.fontScale,this.canvas.width=O,this.canvas.height=b,u.clearRect(0,0,O,b),u.fillStyle="rgba(255, 255, 255, "+this.ALPHA_FIX_VALUE+")",t||(u.translate(0,b),u.scale(1,-1)),0!==d.length){var A=i.getOffsetY(h,d.length,x*this.singleLineHeight,h.fontSize);d.forEach((function(t,i){var r=t.richOptions,o=t.offsetX,a=t.width,s=a,f=o;if(l===n.TextOverflow.display&&a>O){var c=O/a;s*=c,f=o.map((function(t){return t*c}))}var v=e.textLayout.getOffsetX(h,s);i>0&&(A+=t.lineHeight-t.offsetY),r.forEach((function(t,e){var i=h.fontScale,r=h.textColor,o=h.fontFamily,s=h.textWeight,c=h.fontStyle,p=t.text,d=t.fontSize,x=t.fontColor,g=void 0===x?r:x,y=t.fontFamily,S=void 0===y?o:y,m=t.fontWeight,w=void 0===m?s:m,T=t.fontStyle,E=void 0===T?c:T,L=d;l===n.TextOverflow.display&&a>O&&(L/=a/O);var z=f[e]+v;u.font=E+" "+w+" "+L*i+"px "+S,u.fillStyle="rgba("+g[0]+", "+g[1]+", "+g[2]+", "+g[3]+")",u.fillText(p,z,A)}))}));var H=u.getImageData(0,0,this.canvas.width,this.canvas.height),_=a.createWithData(this.engine,{data:new Uint8Array(H.data),width:H.width,height:H.height},{flipY:t,magFilter:s.LINEAR,minFilter:s.LINEAR,wrapS:s.CLAMP_TO_EDGE,wrapT:s.CLAMP_TO_EDGE});this.disposeTextTexture(),this.renderer.texture=_,this.material.setTexture("_MainTex",_),this.isDirty=!1,u.restore()}else u.restore()}},i.updateTextureModern=function(t){var e,i,h=this;this.generateTextProgram(this.text);var l=this.textLayout,f=this.textStyle,c=l.overflow,u=l.letterSpace,v=void 0===u?0:u,p=this.context,d=0,x=0;if(p){p.save();var g=[],y=f.fontSize*this.textStyle.fontScale,S={richOptions:[],offsetX:[],width:0,lineHeight:y*this.singleLineHeight+(this.textLayout.lineGap||0)*this.textStyle.fontScale,offsetY:(this.textLayout.lineGap||0)*this.textStyle.fontScale/2,chars:[]};if(this.processedTextOptions.forEach((function(t){var e=t.text,i=t.isNewLine,n=t.fontSize;i&&(x+=S.lineHeight,g.push(S),d=Math.max(d,S.width),S={richOptions:[],offsetX:[],width:0,lineHeight:y*h.singleLineHeight+(h.textLayout.lineGap||0)*h.textStyle.fontScale,offsetY:(h.textLayout.lineGap||0)*h.textStyle.fontScale/2,chars:[]}),p.font=(t.fontWeight||f.textWeight)+" 10px "+(t.fontFamily||f.fontFamily);var r=n*h.singleLineHeight*h.textStyle.fontScale+(h.textLayout.lineGap||0)*h.textStyle.fontScale;r>S.lineHeight&&(S.lineHeight=r,S.offsetY=(h.textLayout.lineGap||0)*h.textStyle.fontScale/2),S.offsetX.push(S.width);for(var o=0,a=[],s=0;s<e.length;s++){var l=e[s],c=p.measureText(l).width,u=(c<=0?0:c)*n*h.SCALE_FACTOR*h.textStyle.fontScale;a.push({char:l,x:o,width:u}),o+=u+v}S.chars.push(a),S.width+=o,S.richOptions.push(t)})),x+=S.lineHeight,g.push(S),0===(d=Math.max(d,S.width))||0===x)return this.isDirty=!1,void p.restore();void 0!==this.size&&null!==this.size||(this.size=this.item.transform.size.clone());var m=this.size,w=m.x,T=void 0===w?1:w,E=m.y,L=void 0===E?1:E;if(!this.initialized){this.canvasSize=this.canvasSize?this.canvasSize:new r.Vector2(d,x);var z=this.canvasSize,C=z.x,O=z.y;this.item.transform.size.set(T*C*this.SCALE_FACTOR*this.SCALE_FACTOR,L*O*this.SCALE_FACTOR*this.SCALE_FACTOR),this.size=this.item.transform.size.clone(),this.initialized=!0}o(this.canvasSize);var b=this.canvasSize,A=b.x,H=b.y;if(this.textLayout.width=A/f.fontScale,this.textLayout.height=H/f.fontScale,this.canvas.width=A,this.canvas.height=H,p.clearRect(0,0,A,H),p.fillStyle="rgba(255, 255, 255, "+this.ALPHA_FIX_VALUE+")",t||(p.translate(0,H),p.scale(1,-1)),0!==g.length){var _,R=g.map((function(t){return t.lineHeight})),F=g[0],M=(e=Math).max.apply(e,[].concat(null!=(_=null==F||null==(i=F.richOptions)?void 0:i.map((function(t){return t.fontSize})))?_:[this.textStyle.fontSize]))*this.textStyle.fontScale*this.singleLineHeight,k=l.getOffsetYRich(this.textStyle,R,M);g.forEach((function(t,e){var i=t.richOptions,r=t.offsetX,o=t.width,a=t.chars,s=o,l=r;if(c===n.TextOverflow.display&&o>A){var u=A/o;s*=u,l=r.map((function(t){return t*u})),a.forEach((function(t){t.forEach((function(t){t.x*=u,t.width*=u}))}))}var v=h.textLayout.getOffsetX(f,s);i.forEach((function(e,i){var r=f.fontScale,a=f.textColor,s=f.fontFamily,h=f.textWeight,u=f.fontStyle,d=e.fontSize,x=e.fontColor,g=void 0===x?a:x,y=e.fontFamily,S=void 0===y?s:y,m=e.fontWeight,w=void 0===m?h:m,T=e.fontStyle,E=void 0===T?u:T,L=d;c===n.TextOverflow.display&&o>A&&(L/=o/A);var z=l[i]+v;p.font=E+" "+w+" "+L*r+"px "+S,p.fillStyle="rgba("+g[0]+", "+g[1]+", "+g[2]+", "+g[3]+")",t.chars[i].forEach((function(t){p.fillText(t.char,z+t.x,k)}))})),e<g.length-1&&(k+=R[e+1])}));var P=p.getImageData(0,0,this.canvas.width,this.canvas.height),I=a.createWithData(this.engine,{data:new Uint8Array(P.data),width:P.width,height:P.height},{flipY:t,magFilter:s.LINEAR,minFilter:s.LINEAR,wrapS:s.CLAMP_TO_EDGE,wrapT:s.CLAMP_TO_EDGE});this.renderer.texture=I,this.material.setTexture("_MainTex",I),this.isDirty=!1,p.restore()}else p.restore()}},i.setShadowOffsetY=function(t){throw new Error("Method not implemented.")},i.setShadowBlur=function(t){throw new Error("Method not implemented.")},i.setShadowOffsetX=function(t){throw new Error("Method not implemented.")},i.setShadowColor=function(t){throw new Error("Method not implemented.")},i.setOutlineWidth=function(t){throw new Error("Method not implemented.")},i.setAutoWidth=function(t){throw new Error("Method not implemented.")},i.updateWithOptions=function(t){this.textStyle=new h(t),this.textLayout=new l(t),this.textLayout.textBaseline=t.textBaseline||n.TextBaseline.middle,this.text=t.text?t.text.toString():" "},i.renderText=function(t){var e=t.size;e&&(this.canvasSize=new r.Vector2(e[0],e[1])),this.updateTexture()},e}(f);R=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}([i(n.DataType.RichTextComponent)],R);var F="2.7.2";c("rich-text",g,u),v.info("Plugin rich text version: 2.7.2."),F!==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{R as RichTextComponent,g as RichTextLoader,O as escape,z as generateProgram,C as isRichText,E as lexer,L as richTextParser,b as unescape,F 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");function e(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 i=e(t);function n(t,e){return n=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},n(t,e)}function r(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&&n(t,e)}var o,a=function(t){function e(){var e;return(e=t.apply(this,arguments)||this).name="rich-text",e}return r(e,t),e}(t.AbstractPlugin);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 h(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"}(o||(o={}));var l=/^<([a-z]+)(=([^>]+))?>$/,c=/^<\/([a-z]+)>$/,f=[["EscapedChar",/^\\([=<>\\/])/],["ContextStart",/^<[a-z]+(=[^>]+)?>/],["ContextEnd",/^<\/[a-z]+>/],["Text",/^[^</>=\\]+/]],u=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 u(t.slice(2),e.concat({tokenType:"Text",value:r}),i+2)}for(var o,a=h(f);!(o=a()).done;){var s=o.value,l=s[0],c=s[1];if("EscapedChar"!==l){var p=c.exec(t);if(p){var x=p[0],v=x.length;return u(t.slice(v),e.concat({tokenType:l,value:x}),i+v)}}}if(t.length>0)return u(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+'"')},p=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(l);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(c);if(e)return{attributeName:e[1]};throw new Error("Expect an end tag marker at position "+o)}return{}},r=u(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]},h=[];return function t(r,a){for(void 0===r&&(r=[]),void 0===a&&(a="");;){var s=e();if(s)h.push({attributes:r,text:s});else{var l=i(),c=l.attributeName,f=l.attributeParam;if(!c){if(a){var u=n().attributeName;if(!u)throw new Error('Expect an end tag marker "'+a+'" at position '+o+" but found no tag!");if(u!==a)throw new Error('Expect an end tag marker "'+a+'" at position '+o+' but found tag "'+u+'"');return}break}t(r.concat({attributeName:c,attributeParam:null!=f?f:""}),c)}}}(),h};function x(t){return function(e){for(var i,n=h(p(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 v(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 d(t,e){if(void 0===e&&(e=1),"string"!=typeof t||!t)throw new Error("Invalid color string");return t.startsWith("#")?v(t,e):v(function(t){if("string"!=typeof t||!t)throw new Error("Invalid color name provided");if("undefined"==typeof document)throw new 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{e.remove()}throw new Error("Failed to get 2D context for color conversion!")}(t))}"function"==typeof SuppressedError&&SuppressedError;var g=0;exports.RichTextComponent=function(e){function i(t){var i;return(i=e.call(this,t)||this).processedTextOptions=[],i.singleLineHeight=1.571,i.size=null,i.initialized=!1,i.canvasSize=null,i.name="MRichText"+g++,i}r(i,e);var n=i.prototype;return n.generateTextProgram=function(e){var i=this;this.processedTextOptions=[];var n=x((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=d(n.color)),i.processedTextOptions.push(o)}))}));n(e)},n.updateTexture=function(t){if(void 0===t&&(t=!0),this.isDirty&&this.context&&this.canvas){var e=!0===this.textLayout.useLegacyRichText;this.singleLineHeight=e?1.571:1,e?this.updateTextureLegacy(t):this.updateTextureModern(t)}},n.updateTextureLegacy=function(e){var i=this;if(this.isDirty&&this.context&&this.canvas){this.generateTextProgram(this.text);var n=this.textLayout,r=this.textStyle,o=n.overflow,a=n.letterSpace,s=void 0===a?0:a,h=this.context,l=0,c=0;h.save();var f=[],u=r.fontSize*this.textStyle.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,n=t.isNewLine,o=t.fontSize;n&&(f.push(p),l=Math.max(l,p.width),p={richOptions:[],offsetX:[],width:0,lineHeight:u*i.singleLineHeight,offsetY:u*(i.singleLineHeight-1)/2},c+=p.lineHeight),h.font=(t.fontWeight||r.textWeight)+" 10px "+(t.fontFamily||r.fontFamily);var a=h.measureText(e),x=a.width;if(void 0!==a.actualBoundingBoxLeft&&void 0!==a.actualBoundingBoxRight){var v=a.actualBoundingBoxLeft+a.actualBoundingBoxRight;v>0&&(x=Math.max(x,v))}var d=o*i.singleLineHeight*i.textStyle.fontScale;d>p.lineHeight&&(c+=d-p.lineHeight,p.lineHeight=d,p.offsetY=o*i.textStyle.fontScale*(i.singleLineHeight-1)/2),p.offsetX.push(p.width),p.width+=(x<=0?0:x)*o*i.SCALE_FACTOR*i.textStyle.fontScale+e.length*s,p.richOptions.push(t)})),f.push(p),l=Math.max(l,p.width),c+=p.lineHeight,0===l||0===c)return this.isDirty=!1,void h.restore();void 0!==this.size&&null!==this.size||(this.size=this.item.transform.size.clone());var x=this.size,v=x.x,d=void 0===v?1:v,g=x.y,y=void 0===g?1:g;if(!this.initialized){this.canvasSize=this.canvasSize?this.canvasSize:new t.math.Vector2(l,c);var S=this.canvasSize,m=S.x,w=S.y;this.item.transform.size.set(d*m*this.SCALE_FACTOR*this.SCALE_FACTOR,y*w*this.SCALE_FACTOR*this.SCALE_FACTOR),this.size=this.item.transform.size.clone(),this.initialized=!0}t.assertExist(this.canvasSize);var T=this.canvasSize,E=T.x,C=T.y;if(this.textLayout.width=E/r.fontScale,this.textLayout.height=C/r.fontScale,this.canvas.width=E,this.canvas.height=C,h.clearRect(0,0,E,C),h.fillStyle="rgba(255, 255, 255, "+this.ALPHA_FIX_VALUE+")",e||(h.translate(0,C),h.scale(1,-1)),0!==f.length){var L=n.getOffsetY(r,f.length,u*this.singleLineHeight,r.fontSize);f.forEach((function(e,n){var a=e.richOptions,s=e.offsetX,l=e.width,c=l,f=s;if(o===t.spec.TextOverflow.display&&l>E){var u=E/l;c*=u,f=s.map((function(t){return t*u}))}var p=i.textLayout.getOffsetX(r,c);n>0&&(L+=e.lineHeight-e.offsetY),a.forEach((function(e,i){var n=r.fontScale,a=r.textColor,s=r.fontFamily,c=r.textWeight,u=r.fontStyle,x=e.text,v=e.fontSize,d=e.fontColor,g=void 0===d?a:d,y=e.fontFamily,S=void 0===y?s:y,m=e.fontWeight,w=void 0===m?c:m,T=e.fontStyle,C=void 0===T?u:T,z=v;o===t.spec.TextOverflow.display&&l>E&&(z/=l/E);var O=f[i]+p;h.font=C+" "+w+" "+z*n+"px "+S,h.fillStyle="rgba("+g[0]+", "+g[1]+", "+g[2]+", "+g[3]+")",h.fillText(x,O,L)}))}));var z=h.getImageData(0,0,this.canvas.width,this.canvas.height),O=t.Texture.createWithData(this.engine,{data:new Uint8Array(z.data),width:z.width,height:z.height},{flipY:e,magFilter:t.glContext.LINEAR,minFilter:t.glContext.LINEAR,wrapS:t.glContext.CLAMP_TO_EDGE,wrapT:t.glContext.CLAMP_TO_EDGE});this.disposeTextTexture(),this.renderer.texture=O,this.material.setTexture("_MainTex",O),this.isDirty=!1,h.restore()}else h.restore()}},n.updateTextureModern=function(e){var i,n,r=this;this.generateTextProgram(this.text);var o=this.textLayout,a=this.textStyle,s=o.overflow,h=o.letterSpace,l=void 0===h?0:h,c=this.context,f=0,u=0;if(c){c.save();var p=[],x=a.fontSize*this.textStyle.fontScale,v={richOptions:[],offsetX:[],width:0,lineHeight:x*this.singleLineHeight+(this.textLayout.lineGap||0)*this.textStyle.fontScale,offsetY:(this.textLayout.lineGap||0)*this.textStyle.fontScale/2,chars:[]};if(this.processedTextOptions.forEach((function(t){var e=t.text,i=t.isNewLine,n=t.fontSize;i&&(u+=v.lineHeight,p.push(v),f=Math.max(f,v.width),v={richOptions:[],offsetX:[],width:0,lineHeight:x*r.singleLineHeight+(r.textLayout.lineGap||0)*r.textStyle.fontScale,offsetY:(r.textLayout.lineGap||0)*r.textStyle.fontScale/2,chars:[]}),c.font=(t.fontWeight||a.textWeight)+" 10px "+(t.fontFamily||a.fontFamily);var o=n*r.singleLineHeight*r.textStyle.fontScale+(r.textLayout.lineGap||0)*r.textStyle.fontScale;o>v.lineHeight&&(v.lineHeight=o,v.offsetY=(r.textLayout.lineGap||0)*r.textStyle.fontScale/2),v.offsetX.push(v.width);for(var s=0,h=[],d=0;d<e.length;d++){var g=e[d],y=c.measureText(g).width,S=(y<=0?0:y)*n*r.SCALE_FACTOR*r.textStyle.fontScale;h.push({char:g,x:s,width:S}),s+=S+l}v.chars.push(h),v.width+=s,v.richOptions.push(t)})),u+=v.lineHeight,p.push(v),0===(f=Math.max(f,v.width))||0===u)return this.isDirty=!1,void c.restore();void 0!==this.size&&null!==this.size||(this.size=this.item.transform.size.clone());var d=this.size,g=d.x,y=void 0===g?1:g,S=d.y,m=void 0===S?1:S;if(!this.initialized){this.canvasSize=this.canvasSize?this.canvasSize:new t.math.Vector2(f,u);var w=this.canvasSize,T=w.x,E=w.y;this.item.transform.size.set(y*T*this.SCALE_FACTOR*this.SCALE_FACTOR,m*E*this.SCALE_FACTOR*this.SCALE_FACTOR),this.size=this.item.transform.size.clone(),this.initialized=!0}t.assertExist(this.canvasSize);var C=this.canvasSize,L=C.x,z=C.y;if(this.textLayout.width=L/a.fontScale,this.textLayout.height=z/a.fontScale,this.canvas.width=L,this.canvas.height=z,c.clearRect(0,0,L,z),c.fillStyle="rgba(255, 255, 255, "+this.ALPHA_FIX_VALUE+")",e||(c.translate(0,z),c.scale(1,-1)),0!==p.length){var O,b=p.map((function(t){return t.lineHeight})),A=p[0],R=(i=Math).max.apply(i,[].concat(null!=(O=null==A||null==(n=A.richOptions)?void 0:n.map((function(t){return t.fontSize})))?O:[this.textStyle.fontSize]))*this.textStyle.fontScale*this.singleLineHeight,_=o.getOffsetYRich(this.textStyle,b,R);p.forEach((function(e,i){var n=e.richOptions,o=e.offsetX,h=e.width,l=e.chars,f=h,u=o;if(s===t.spec.TextOverflow.display&&h>L){var x=L/h;f*=x,u=o.map((function(t){return t*x})),l.forEach((function(t){t.forEach((function(t){t.x*=x,t.width*=x}))}))}var v=r.textLayout.getOffsetX(a,f);n.forEach((function(i,n){var r=a.fontScale,o=a.textColor,l=a.fontFamily,f=a.textWeight,p=a.fontStyle,x=i.fontSize,d=i.fontColor,g=void 0===d?o:d,y=i.fontFamily,S=void 0===y?l:y,m=i.fontWeight,w=void 0===m?f:m,T=i.fontStyle,E=void 0===T?p:T,C=x;s===t.spec.TextOverflow.display&&h>L&&(C/=h/L);var z=u[n]+v;c.font=E+" "+w+" "+C*r+"px "+S,c.fillStyle="rgba("+g[0]+", "+g[1]+", "+g[2]+", "+g[3]+")",e.chars[n].forEach((function(t){c.fillText(t.char,z+t.x,_)}))})),i<p.length-1&&(_+=b[i+1])}));var H=c.getImageData(0,0,this.canvas.width,this.canvas.height),F=t.Texture.createWithData(this.engine,{data:new Uint8Array(H.data),width:H.width,height:H.height},{flipY:e,magFilter:t.glContext.LINEAR,minFilter:t.glContext.LINEAR,wrapS:t.glContext.CLAMP_TO_EDGE,wrapT:t.glContext.CLAMP_TO_EDGE});this.renderer.texture=F,this.material.setTexture("_MainTex",F),this.isDirty=!1,c.restore()}else c.restore()}},n.setShadowOffsetY=function(t){throw new Error("Method not implemented.")},n.setShadowBlur=function(t){throw new Error("Method not implemented.")},n.setShadowOffsetX=function(t){throw new Error("Method not implemented.")},n.setShadowColor=function(t){throw new Error("Method not implemented.")},n.setOutlineWidth=function(t){throw new Error("Method not implemented.")},n.setAutoWidth=function(t){throw new Error("Method not implemented.")},n.updateWithOptions=function(e){this.textStyle=new t.TextStyle(e),this.textLayout=new t.TextLayout(e),this.textLayout.textBaseline=e.textBaseline||t.spec.TextBaseline.middle,this.text=e.text?e.text.toString():" "},n.renderText=function(e){var i=e.size;i&&(this.canvasSize=new t.math.Vector2(i[0],i[1])),this.updateTexture()},i}(t.TextComponent),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);var y="2.7.0";t.registerPlugin("rich-text",a,t.VFXItem),t.logger.info("Plugin rich text version: 2.7.0."),y!==i.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=a,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=x,exports.isRichText=function(t){var e=u(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(l)[1]:i.match(c)[1]}})))},exports.lexer=u,exports.richTextParser=p,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=y;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@galacean/effects/douyin");function e(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 i=e(t);function n(t,e){return n=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},n(t,e)}function r(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&&n(t,e)}var o,a=function(t){function e(){var e;return(e=t.apply(this,arguments)||this).name="rich-text",e}return r(e,t),e}(t.AbstractPlugin);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 h(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"}(o||(o={}));var l=/^<([a-z]+)(=([^>]+))?>$/,c=/^<\/([a-z]+)>$/,f=[["EscapedChar",/^\\([=<>\\/])/],["ContextStart",/^<[a-z]+(=[^>]+)?>/],["ContextEnd",/^<\/[a-z]+>/],["Text",/^[^</>=\\]+/]],u=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 u(t.slice(2),e.concat({tokenType:"Text",value:r}),i+2)}for(var o,a=h(f);!(o=a()).done;){var s=o.value,l=s[0],c=s[1];if("EscapedChar"!==l){var p=c.exec(t);if(p){var x=p[0],v=x.length;return u(t.slice(v),e.concat({tokenType:l,value:x}),i+v)}}}if(t.length>0)return u(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+'"')},p=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(l);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(c);if(e)return{attributeName:e[1]};throw new Error("Expect an end tag marker at position "+o)}return{}},r=u(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]},h=[];return function t(r,a){for(void 0===r&&(r=[]),void 0===a&&(a="");;){var s=e();if(s)h.push({attributes:r,text:s});else{var l=i(),c=l.attributeName,f=l.attributeParam;if(!c){if(a){var u=n().attributeName;if(!u)throw new Error('Expect an end tag marker "'+a+'" at position '+o+" but found no tag!");if(u!==a)throw new Error('Expect an end tag marker "'+a+'" at position '+o+' but found tag "'+u+'"');return}break}t(r.concat({attributeName:c,attributeParam:null!=f?f:""}),c)}}}(),h};function x(t){return function(e){for(var i,n=h(p(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 v(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 d(t,e){if(void 0===e&&(e=1),"string"!=typeof t||!t)throw new Error("Invalid color string");return t.startsWith("#")?v(t,e):v(function(t){if("string"!=typeof t||!t)throw new Error("Invalid color name provided");if("undefined"==typeof document)throw new 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{e.remove()}throw new Error("Failed to get 2D context for color conversion!")}(t))}"function"==typeof SuppressedError&&SuppressedError;var g=0;exports.RichTextComponent=function(e){function i(t){var i;return(i=e.call(this,t)||this).processedTextOptions=[],i.singleLineHeight=1.571,i.size=null,i.initialized=!1,i.canvasSize=null,i.name="MRichText"+g++,i}r(i,e);var n=i.prototype;return n.generateTextProgram=function(e){var i=this;this.processedTextOptions=[];var n=x((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=d(n.color)),i.processedTextOptions.push(o)}))}));n(e)},n.updateTexture=function(t){if(void 0===t&&(t=!0),this.isDirty&&this.context&&this.canvas){var e=!0===this.textLayout.useLegacyRichText;this.singleLineHeight=e?1.571:1,e?this.updateTextureLegacy(t):this.updateTextureModern(t)}},n.updateTextureLegacy=function(e){var i=this;if(this.isDirty&&this.context&&this.canvas){this.generateTextProgram(this.text);var n=this.textLayout,r=this.textStyle,o=n.overflow,a=n.letterSpace,s=void 0===a?0:a,h=this.context,l=0,c=0;h.save();var f=[],u=r.fontSize*this.textStyle.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,n=t.isNewLine,o=t.fontSize;n&&(f.push(p),l=Math.max(l,p.width),p={richOptions:[],offsetX:[],width:0,lineHeight:u*i.singleLineHeight,offsetY:u*(i.singleLineHeight-1)/2},c+=p.lineHeight),h.font=(t.fontWeight||r.textWeight)+" 10px "+(t.fontFamily||r.fontFamily);var a=h.measureText(e),x=a.width;if(void 0!==a.actualBoundingBoxLeft&&void 0!==a.actualBoundingBoxRight){var v=a.actualBoundingBoxLeft+a.actualBoundingBoxRight;v>0&&(x=Math.max(x,v))}var d=o*i.singleLineHeight*i.textStyle.fontScale;d>p.lineHeight&&(c+=d-p.lineHeight,p.lineHeight=d,p.offsetY=o*i.textStyle.fontScale*(i.singleLineHeight-1)/2),p.offsetX.push(p.width),p.width+=(x<=0?0:x)*o*i.SCALE_FACTOR*i.textStyle.fontScale+e.length*s,p.richOptions.push(t)})),f.push(p),l=Math.max(l,p.width),c+=p.lineHeight,0===l||0===c)return this.isDirty=!1,void h.restore();void 0!==this.size&&null!==this.size||(this.size=this.item.transform.size.clone());var x=this.size,v=x.x,d=void 0===v?1:v,g=x.y,y=void 0===g?1:g;if(!this.initialized){this.canvasSize=this.canvasSize?this.canvasSize:new t.math.Vector2(l,c);var S=this.canvasSize,m=S.x,w=S.y;this.item.transform.size.set(d*m*this.SCALE_FACTOR*this.SCALE_FACTOR,y*w*this.SCALE_FACTOR*this.SCALE_FACTOR),this.size=this.item.transform.size.clone(),this.initialized=!0}t.assertExist(this.canvasSize);var T=this.canvasSize,E=T.x,C=T.y;if(this.textLayout.width=E/r.fontScale,this.textLayout.height=C/r.fontScale,this.canvas.width=E,this.canvas.height=C,h.clearRect(0,0,E,C),h.fillStyle="rgba(255, 255, 255, "+this.ALPHA_FIX_VALUE+")",e||(h.translate(0,C),h.scale(1,-1)),0!==f.length){var L=n.getOffsetY(r,f.length,u*this.singleLineHeight,r.fontSize);f.forEach((function(e,n){var a=e.richOptions,s=e.offsetX,l=e.width,c=l,f=s;if(o===t.spec.TextOverflow.display&&l>E){var u=E/l;c*=u,f=s.map((function(t){return t*u}))}var p=i.textLayout.getOffsetX(r,c);n>0&&(L+=e.lineHeight-e.offsetY),a.forEach((function(e,i){var n=r.fontScale,a=r.textColor,s=r.fontFamily,c=r.textWeight,u=r.fontStyle,x=e.text,v=e.fontSize,d=e.fontColor,g=void 0===d?a:d,y=e.fontFamily,S=void 0===y?s:y,m=e.fontWeight,w=void 0===m?c:m,T=e.fontStyle,C=void 0===T?u:T,z=v;o===t.spec.TextOverflow.display&&l>E&&(z/=l/E);var O=f[i]+p;h.font=C+" "+w+" "+z*n+"px "+S,h.fillStyle="rgba("+g[0]+", "+g[1]+", "+g[2]+", "+g[3]+")",h.fillText(x,O,L)}))}));var z=h.getImageData(0,0,this.canvas.width,this.canvas.height),O=t.Texture.createWithData(this.engine,{data:new Uint8Array(z.data),width:z.width,height:z.height},{flipY:e,magFilter:t.glContext.LINEAR,minFilter:t.glContext.LINEAR,wrapS:t.glContext.CLAMP_TO_EDGE,wrapT:t.glContext.CLAMP_TO_EDGE});this.disposeTextTexture(),this.renderer.texture=O,this.material.setTexture("_MainTex",O),this.isDirty=!1,h.restore()}else h.restore()}},n.updateTextureModern=function(e){var i,n,r=this;this.generateTextProgram(this.text);var o=this.textLayout,a=this.textStyle,s=o.overflow,h=o.letterSpace,l=void 0===h?0:h,c=this.context,f=0,u=0;if(c){c.save();var p=[],x=a.fontSize*this.textStyle.fontScale,v={richOptions:[],offsetX:[],width:0,lineHeight:x*this.singleLineHeight+(this.textLayout.lineGap||0)*this.textStyle.fontScale,offsetY:(this.textLayout.lineGap||0)*this.textStyle.fontScale/2,chars:[]};if(this.processedTextOptions.forEach((function(t){var e=t.text,i=t.isNewLine,n=t.fontSize;i&&(u+=v.lineHeight,p.push(v),f=Math.max(f,v.width),v={richOptions:[],offsetX:[],width:0,lineHeight:x*r.singleLineHeight+(r.textLayout.lineGap||0)*r.textStyle.fontScale,offsetY:(r.textLayout.lineGap||0)*r.textStyle.fontScale/2,chars:[]}),c.font=(t.fontWeight||a.textWeight)+" 10px "+(t.fontFamily||a.fontFamily);var o=n*r.singleLineHeight*r.textStyle.fontScale+(r.textLayout.lineGap||0)*r.textStyle.fontScale;o>v.lineHeight&&(v.lineHeight=o,v.offsetY=(r.textLayout.lineGap||0)*r.textStyle.fontScale/2),v.offsetX.push(v.width);for(var s=0,h=[],d=0;d<e.length;d++){var g=e[d],y=c.measureText(g).width,S=(y<=0?0:y)*n*r.SCALE_FACTOR*r.textStyle.fontScale;h.push({char:g,x:s,width:S}),s+=S+l}v.chars.push(h),v.width+=s,v.richOptions.push(t)})),u+=v.lineHeight,p.push(v),0===(f=Math.max(f,v.width))||0===u)return this.isDirty=!1,void c.restore();void 0!==this.size&&null!==this.size||(this.size=this.item.transform.size.clone());var d=this.size,g=d.x,y=void 0===g?1:g,S=d.y,m=void 0===S?1:S;if(!this.initialized){this.canvasSize=this.canvasSize?this.canvasSize:new t.math.Vector2(f,u);var w=this.canvasSize,T=w.x,E=w.y;this.item.transform.size.set(y*T*this.SCALE_FACTOR*this.SCALE_FACTOR,m*E*this.SCALE_FACTOR*this.SCALE_FACTOR),this.size=this.item.transform.size.clone(),this.initialized=!0}t.assertExist(this.canvasSize);var C=this.canvasSize,L=C.x,z=C.y;if(this.textLayout.width=L/a.fontScale,this.textLayout.height=z/a.fontScale,this.canvas.width=L,this.canvas.height=z,c.clearRect(0,0,L,z),c.fillStyle="rgba(255, 255, 255, "+this.ALPHA_FIX_VALUE+")",e||(c.translate(0,z),c.scale(1,-1)),0!==p.length){var O,b=p.map((function(t){return t.lineHeight})),A=p[0],R=(i=Math).max.apply(i,[].concat(null!=(O=null==A||null==(n=A.richOptions)?void 0:n.map((function(t){return t.fontSize})))?O:[this.textStyle.fontSize]))*this.textStyle.fontScale*this.singleLineHeight,_=o.getOffsetYRich(this.textStyle,b,R);p.forEach((function(e,i){var n=e.richOptions,o=e.offsetX,h=e.width,l=e.chars,f=h,u=o;if(s===t.spec.TextOverflow.display&&h>L){var x=L/h;f*=x,u=o.map((function(t){return t*x})),l.forEach((function(t){t.forEach((function(t){t.x*=x,t.width*=x}))}))}var v=r.textLayout.getOffsetX(a,f);n.forEach((function(i,n){var r=a.fontScale,o=a.textColor,l=a.fontFamily,f=a.textWeight,p=a.fontStyle,x=i.fontSize,d=i.fontColor,g=void 0===d?o:d,y=i.fontFamily,S=void 0===y?l:y,m=i.fontWeight,w=void 0===m?f:m,T=i.fontStyle,E=void 0===T?p:T,C=x;s===t.spec.TextOverflow.display&&h>L&&(C/=h/L);var z=u[n]+v;c.font=E+" "+w+" "+C*r+"px "+S,c.fillStyle="rgba("+g[0]+", "+g[1]+", "+g[2]+", "+g[3]+")",e.chars[n].forEach((function(t){c.fillText(t.char,z+t.x,_)}))})),i<p.length-1&&(_+=b[i+1])}));var H=c.getImageData(0,0,this.canvas.width,this.canvas.height),F=t.Texture.createWithData(this.engine,{data:new Uint8Array(H.data),width:H.width,height:H.height},{flipY:e,magFilter:t.glContext.LINEAR,minFilter:t.glContext.LINEAR,wrapS:t.glContext.CLAMP_TO_EDGE,wrapT:t.glContext.CLAMP_TO_EDGE});this.renderer.texture=F,this.material.setTexture("_MainTex",F),this.isDirty=!1,c.restore()}else c.restore()}},n.setShadowOffsetY=function(t){throw new Error("Method not implemented.")},n.setShadowBlur=function(t){throw new Error("Method not implemented.")},n.setShadowOffsetX=function(t){throw new Error("Method not implemented.")},n.setShadowColor=function(t){throw new Error("Method not implemented.")},n.setOutlineWidth=function(t){throw new Error("Method not implemented.")},n.setAutoWidth=function(t){throw new Error("Method not implemented.")},n.updateWithOptions=function(e){this.textStyle=new t.TextStyle(e),this.textLayout=new t.TextLayout(e),this.textLayout.textBaseline=e.textBaseline||t.spec.TextBaseline.middle,this.text=e.text?e.text.toString():" "},n.renderText=function(e){var i=e.size;i&&(this.canvasSize=new t.math.Vector2(i[0],i[1])),this.updateTexture()},i}(t.TextComponent),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);var y="2.7.2";t.registerPlugin("rich-text",a,t.VFXItem),t.logger.info("Plugin rich text version: 2.7.2."),y!==i.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=a,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=x,exports.isRichText=function(t){var e=u(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(l)[1]:i.match(c)[1]}})))},exports.lexer=u,exports.richTextParser=p,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=y;
|
|
2
2
|
//# sourceMappingURL=douyin.js.map
|
package/dist/douyin.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import*as t from"@galacean/effects/douyin";import{AbstractPlugin as e,effectsClass as i,spec as n,math as r,assertExist as o,Texture as a,glContext as s,TextStyle as h,TextLayout as l,TextComponent as f,registerPlugin as c,VFXItem as u,logger as v}from"@galacean/effects/douyin";function d(t,e){return d=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},d(t,e)}function p(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&&d(t,e)}var x,g=function(t){function e(){var e;return(e=t.apply(this,arguments)||this).name="rich-text",e}return p(e,t),e}(e);function y(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 S(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 y(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)?y(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"}(x||(x={}));var m=/^<([a-z]+)(=([^>]+))?>$/,w=/^<\/([a-z]+)>$/,T=[["EscapedChar",/^\\([=<>\\/])/],["ContextStart",/^<[a-z]+(=[^>]+)?>/],["ContextEnd",/^<\/[a-z]+>/],["Text",/^[^</>=\\]+/]],E=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 E(t.slice(2),e.concat({tokenType:"Text",value:r}),i+2)}for(var o,a=S(T);!(o=a()).done;){var s=o.value,h=s[0],l=s[1];if("EscapedChar"!==h){var f=l.exec(t);if(f){var c=f[0],u=c.length;return E(t.slice(u),e.concat({tokenType:h,value:c}),i+u)}}}if(t.length>0)return E(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+'"')},L=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(m);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(w);if(e)return{attributeName:e[1]};throw new Error("Expect an end tag marker at position "+o)}return{}},r=E(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]},h=[];return function t(r,a){for(void 0===r&&(r=[]),void 0===a&&(a="");;){var s=e();if(s)h.push({attributes:r,text:s});else{var l=i(),f=l.attributeName,c=l.attributeParam;if(!f){if(a){var u=n().attributeName;if(!u)throw new Error('Expect an end tag marker "'+a+'" at position '+o+" but found no tag!");if(u!==a)throw new Error('Expect an end tag marker "'+a+'" at position '+o+' but found tag "'+u+'"');return}break}t(r.concat({attributeName:f,attributeParam:null!=c?c:""}),f)}}}(),h};function z(t){return function(e){for(var i,n=S(L(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 C(t){var e=E(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(m)[1]:i.match(w)[1]}})))}function O(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 b(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 A(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 H(t,e){if(void 0===e&&(e=1),"string"!=typeof t||!t)throw new Error("Invalid color string");return t.startsWith("#")?A(t,e):A(function(t){if("string"!=typeof t||!t)throw new Error("Invalid color name provided");if("undefined"==typeof document)throw new 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{e.remove()}throw new Error("Failed to get 2D context for color conversion!")}(t))}"function"==typeof SuppressedError&&SuppressedError;var _=0,R=function(t){function e(e){var i;return(i=t.call(this,e)||this).processedTextOptions=[],i.singleLineHeight=1.571,i.size=null,i.initialized=!1,i.canvasSize=null,i.name="MRichText"+_++,i}p(e,t);var i=e.prototype;return i.generateTextProgram=function(t){var e=this;this.processedTextOptions=[];var i=z((function(t,i){/^\n+$/.test(t)&&(t=t.replace(/\n/g,"\n ")),t.split("\n").forEach((function(t,r){var o={text:t,fontSize:e.textStyle.fontSize,isNewLine:!1};r>0&&(o.isNewLine=!0),"b"in i&&(o.fontWeight=n.TextWeight.bold),"i"in i&&(o.fontStyle=n.FontStyle.italic),"size"in i&&i.size&&(o.fontSize=parseInt(i.size,10)),"color"in i&&i.color&&(o.fontColor=H(i.color)),e.processedTextOptions.push(o)}))}));i(t)},i.updateTexture=function(t){if(void 0===t&&(t=!0),this.isDirty&&this.context&&this.canvas){var e=!0===this.textLayout.useLegacyRichText;this.singleLineHeight=e?1.571:1,e?this.updateTextureLegacy(t):this.updateTextureModern(t)}},i.updateTextureLegacy=function(t){var e=this;if(this.isDirty&&this.context&&this.canvas){this.generateTextProgram(this.text);var i=this.textLayout,h=this.textStyle,l=i.overflow,f=i.letterSpace,c=void 0===f?0:f,u=this.context,v=0,d=0;u.save();var p=[],x=h.fontSize*this.textStyle.fontScale,g={richOptions:[],offsetX:[],width:0,lineHeight:x*this.singleLineHeight,offsetY:x*(this.singleLineHeight-1)/2};if(this.processedTextOptions.forEach((function(t){var i=t.text,n=t.isNewLine,r=t.fontSize;n&&(p.push(g),v=Math.max(v,g.width),g={richOptions:[],offsetX:[],width:0,lineHeight:x*e.singleLineHeight,offsetY:x*(e.singleLineHeight-1)/2},d+=g.lineHeight),u.font=(t.fontWeight||h.textWeight)+" 10px "+(t.fontFamily||h.fontFamily);var o=u.measureText(i),a=o.width;if(void 0!==o.actualBoundingBoxLeft&&void 0!==o.actualBoundingBoxRight){var s=o.actualBoundingBoxLeft+o.actualBoundingBoxRight;s>0&&(a=Math.max(a,s))}var l=r*e.singleLineHeight*e.textStyle.fontScale;l>g.lineHeight&&(d+=l-g.lineHeight,g.lineHeight=l,g.offsetY=r*e.textStyle.fontScale*(e.singleLineHeight-1)/2),g.offsetX.push(g.width),g.width+=(a<=0?0:a)*r*e.SCALE_FACTOR*e.textStyle.fontScale+i.length*c,g.richOptions.push(t)})),p.push(g),v=Math.max(v,g.width),d+=g.lineHeight,0===v||0===d)return this.isDirty=!1,void u.restore();void 0!==this.size&&null!==this.size||(this.size=this.item.transform.size.clone());var y=this.size,S=y.x,m=void 0===S?1:S,w=y.y,T=void 0===w?1:w;if(!this.initialized){this.canvasSize=this.canvasSize?this.canvasSize:new r.Vector2(v,d);var E=this.canvasSize,L=E.x,z=E.y;this.item.transform.size.set(m*L*this.SCALE_FACTOR*this.SCALE_FACTOR,T*z*this.SCALE_FACTOR*this.SCALE_FACTOR),this.size=this.item.transform.size.clone(),this.initialized=!0}o(this.canvasSize);var C=this.canvasSize,O=C.x,b=C.y;if(this.textLayout.width=O/h.fontScale,this.textLayout.height=b/h.fontScale,this.canvas.width=O,this.canvas.height=b,u.clearRect(0,0,O,b),u.fillStyle="rgba(255, 255, 255, "+this.ALPHA_FIX_VALUE+")",t||(u.translate(0,b),u.scale(1,-1)),0!==p.length){var A=i.getOffsetY(h,p.length,x*this.singleLineHeight,h.fontSize);p.forEach((function(t,i){var r=t.richOptions,o=t.offsetX,a=t.width,s=a,f=o;if(l===n.TextOverflow.display&&a>O){var c=O/a;s*=c,f=o.map((function(t){return t*c}))}var v=e.textLayout.getOffsetX(h,s);i>0&&(A+=t.lineHeight-t.offsetY),r.forEach((function(t,e){var i=h.fontScale,r=h.textColor,o=h.fontFamily,s=h.textWeight,c=h.fontStyle,d=t.text,p=t.fontSize,x=t.fontColor,g=void 0===x?r:x,y=t.fontFamily,S=void 0===y?o:y,m=t.fontWeight,w=void 0===m?s:m,T=t.fontStyle,E=void 0===T?c:T,L=p;l===n.TextOverflow.display&&a>O&&(L/=a/O);var z=f[e]+v;u.font=E+" "+w+" "+L*i+"px "+S,u.fillStyle="rgba("+g[0]+", "+g[1]+", "+g[2]+", "+g[3]+")",u.fillText(d,z,A)}))}));var H=u.getImageData(0,0,this.canvas.width,this.canvas.height),_=a.createWithData(this.engine,{data:new Uint8Array(H.data),width:H.width,height:H.height},{flipY:t,magFilter:s.LINEAR,minFilter:s.LINEAR,wrapS:s.CLAMP_TO_EDGE,wrapT:s.CLAMP_TO_EDGE});this.disposeTextTexture(),this.renderer.texture=_,this.material.setTexture("_MainTex",_),this.isDirty=!1,u.restore()}else u.restore()}},i.updateTextureModern=function(t){var e,i,h=this;this.generateTextProgram(this.text);var l=this.textLayout,f=this.textStyle,c=l.overflow,u=l.letterSpace,v=void 0===u?0:u,d=this.context,p=0,x=0;if(d){d.save();var g=[],y=f.fontSize*this.textStyle.fontScale,S={richOptions:[],offsetX:[],width:0,lineHeight:y*this.singleLineHeight+(this.textLayout.lineGap||0)*this.textStyle.fontScale,offsetY:(this.textLayout.lineGap||0)*this.textStyle.fontScale/2,chars:[]};if(this.processedTextOptions.forEach((function(t){var e=t.text,i=t.isNewLine,n=t.fontSize;i&&(x+=S.lineHeight,g.push(S),p=Math.max(p,S.width),S={richOptions:[],offsetX:[],width:0,lineHeight:y*h.singleLineHeight+(h.textLayout.lineGap||0)*h.textStyle.fontScale,offsetY:(h.textLayout.lineGap||0)*h.textStyle.fontScale/2,chars:[]}),d.font=(t.fontWeight||f.textWeight)+" 10px "+(t.fontFamily||f.fontFamily);var r=n*h.singleLineHeight*h.textStyle.fontScale+(h.textLayout.lineGap||0)*h.textStyle.fontScale;r>S.lineHeight&&(S.lineHeight=r,S.offsetY=(h.textLayout.lineGap||0)*h.textStyle.fontScale/2),S.offsetX.push(S.width);for(var o=0,a=[],s=0;s<e.length;s++){var l=e[s],c=d.measureText(l).width,u=(c<=0?0:c)*n*h.SCALE_FACTOR*h.textStyle.fontScale;a.push({char:l,x:o,width:u}),o+=u+v}S.chars.push(a),S.width+=o,S.richOptions.push(t)})),x+=S.lineHeight,g.push(S),0===(p=Math.max(p,S.width))||0===x)return this.isDirty=!1,void d.restore();void 0!==this.size&&null!==this.size||(this.size=this.item.transform.size.clone());var m=this.size,w=m.x,T=void 0===w?1:w,E=m.y,L=void 0===E?1:E;if(!this.initialized){this.canvasSize=this.canvasSize?this.canvasSize:new r.Vector2(p,x);var z=this.canvasSize,C=z.x,O=z.y;this.item.transform.size.set(T*C*this.SCALE_FACTOR*this.SCALE_FACTOR,L*O*this.SCALE_FACTOR*this.SCALE_FACTOR),this.size=this.item.transform.size.clone(),this.initialized=!0}o(this.canvasSize);var b=this.canvasSize,A=b.x,H=b.y;if(this.textLayout.width=A/f.fontScale,this.textLayout.height=H/f.fontScale,this.canvas.width=A,this.canvas.height=H,d.clearRect(0,0,A,H),d.fillStyle="rgba(255, 255, 255, "+this.ALPHA_FIX_VALUE+")",t||(d.translate(0,H),d.scale(1,-1)),0!==g.length){var _,R=g.map((function(t){return t.lineHeight})),F=g[0],M=(e=Math).max.apply(e,[].concat(null!=(_=null==F||null==(i=F.richOptions)?void 0:i.map((function(t){return t.fontSize})))?_:[this.textStyle.fontSize]))*this.textStyle.fontScale*this.singleLineHeight,k=l.getOffsetYRich(this.textStyle,R,M);g.forEach((function(t,e){var i=t.richOptions,r=t.offsetX,o=t.width,a=t.chars,s=o,l=r;if(c===n.TextOverflow.display&&o>A){var u=A/o;s*=u,l=r.map((function(t){return t*u})),a.forEach((function(t){t.forEach((function(t){t.x*=u,t.width*=u}))}))}var v=h.textLayout.getOffsetX(f,s);i.forEach((function(e,i){var r=f.fontScale,a=f.textColor,s=f.fontFamily,h=f.textWeight,u=f.fontStyle,p=e.fontSize,x=e.fontColor,g=void 0===x?a:x,y=e.fontFamily,S=void 0===y?s:y,m=e.fontWeight,w=void 0===m?h:m,T=e.fontStyle,E=void 0===T?u:T,L=p;c===n.TextOverflow.display&&o>A&&(L/=o/A);var z=l[i]+v;d.font=E+" "+w+" "+L*r+"px "+S,d.fillStyle="rgba("+g[0]+", "+g[1]+", "+g[2]+", "+g[3]+")",t.chars[i].forEach((function(t){d.fillText(t.char,z+t.x,k)}))})),e<g.length-1&&(k+=R[e+1])}));var P=d.getImageData(0,0,this.canvas.width,this.canvas.height),I=a.createWithData(this.engine,{data:new Uint8Array(P.data),width:P.width,height:P.height},{flipY:t,magFilter:s.LINEAR,minFilter:s.LINEAR,wrapS:s.CLAMP_TO_EDGE,wrapT:s.CLAMP_TO_EDGE});this.renderer.texture=I,this.material.setTexture("_MainTex",I),this.isDirty=!1,d.restore()}else d.restore()}},i.setShadowOffsetY=function(t){throw new Error("Method not implemented.")},i.setShadowBlur=function(t){throw new Error("Method not implemented.")},i.setShadowOffsetX=function(t){throw new Error("Method not implemented.")},i.setShadowColor=function(t){throw new Error("Method not implemented.")},i.setOutlineWidth=function(t){throw new Error("Method not implemented.")},i.setAutoWidth=function(t){throw new Error("Method not implemented.")},i.updateWithOptions=function(t){this.textStyle=new h(t),this.textLayout=new l(t),this.textLayout.textBaseline=t.textBaseline||n.TextBaseline.middle,this.text=t.text?t.text.toString():" "},i.renderText=function(t){var e=t.size;e&&(this.canvasSize=new r.Vector2(e[0],e[1])),this.updateTexture()},e}(f);R=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}([i(n.DataType.RichTextComponent)],R);var F="2.7.0";c("rich-text",g,u),v.info("Plugin rich text version: 2.7.0."),F!==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{R as RichTextComponent,g as RichTextLoader,O as escape,z as generateProgram,C as isRichText,E as lexer,L as richTextParser,b as unescape,F as version};
|
|
1
|
+
import*as t from"@galacean/effects/douyin";import{AbstractPlugin as e,effectsClass as i,spec as n,math as r,assertExist as o,Texture as a,glContext as s,TextStyle as h,TextLayout as l,TextComponent as f,registerPlugin as c,VFXItem as u,logger as v}from"@galacean/effects/douyin";function d(t,e){return d=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},d(t,e)}function p(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&&d(t,e)}var x,g=function(t){function e(){var e;return(e=t.apply(this,arguments)||this).name="rich-text",e}return p(e,t),e}(e);function y(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 S(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 y(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)?y(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"}(x||(x={}));var m=/^<([a-z]+)(=([^>]+))?>$/,w=/^<\/([a-z]+)>$/,T=[["EscapedChar",/^\\([=<>\\/])/],["ContextStart",/^<[a-z]+(=[^>]+)?>/],["ContextEnd",/^<\/[a-z]+>/],["Text",/^[^</>=\\]+/]],E=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 E(t.slice(2),e.concat({tokenType:"Text",value:r}),i+2)}for(var o,a=S(T);!(o=a()).done;){var s=o.value,h=s[0],l=s[1];if("EscapedChar"!==h){var f=l.exec(t);if(f){var c=f[0],u=c.length;return E(t.slice(u),e.concat({tokenType:h,value:c}),i+u)}}}if(t.length>0)return E(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+'"')},L=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(m);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(w);if(e)return{attributeName:e[1]};throw new Error("Expect an end tag marker at position "+o)}return{}},r=E(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]},h=[];return function t(r,a){for(void 0===r&&(r=[]),void 0===a&&(a="");;){var s=e();if(s)h.push({attributes:r,text:s});else{var l=i(),f=l.attributeName,c=l.attributeParam;if(!f){if(a){var u=n().attributeName;if(!u)throw new Error('Expect an end tag marker "'+a+'" at position '+o+" but found no tag!");if(u!==a)throw new Error('Expect an end tag marker "'+a+'" at position '+o+' but found tag "'+u+'"');return}break}t(r.concat({attributeName:f,attributeParam:null!=c?c:""}),f)}}}(),h};function z(t){return function(e){for(var i,n=S(L(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 C(t){var e=E(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(m)[1]:i.match(w)[1]}})))}function O(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 b(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 A(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 H(t,e){if(void 0===e&&(e=1),"string"!=typeof t||!t)throw new Error("Invalid color string");return t.startsWith("#")?A(t,e):A(function(t){if("string"!=typeof t||!t)throw new Error("Invalid color name provided");if("undefined"==typeof document)throw new 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{e.remove()}throw new Error("Failed to get 2D context for color conversion!")}(t))}"function"==typeof SuppressedError&&SuppressedError;var _=0,R=function(t){function e(e){var i;return(i=t.call(this,e)||this).processedTextOptions=[],i.singleLineHeight=1.571,i.size=null,i.initialized=!1,i.canvasSize=null,i.name="MRichText"+_++,i}p(e,t);var i=e.prototype;return i.generateTextProgram=function(t){var e=this;this.processedTextOptions=[];var i=z((function(t,i){/^\n+$/.test(t)&&(t=t.replace(/\n/g,"\n ")),t.split("\n").forEach((function(t,r){var o={text:t,fontSize:e.textStyle.fontSize,isNewLine:!1};r>0&&(o.isNewLine=!0),"b"in i&&(o.fontWeight=n.TextWeight.bold),"i"in i&&(o.fontStyle=n.FontStyle.italic),"size"in i&&i.size&&(o.fontSize=parseInt(i.size,10)),"color"in i&&i.color&&(o.fontColor=H(i.color)),e.processedTextOptions.push(o)}))}));i(t)},i.updateTexture=function(t){if(void 0===t&&(t=!0),this.isDirty&&this.context&&this.canvas){var e=!0===this.textLayout.useLegacyRichText;this.singleLineHeight=e?1.571:1,e?this.updateTextureLegacy(t):this.updateTextureModern(t)}},i.updateTextureLegacy=function(t){var e=this;if(this.isDirty&&this.context&&this.canvas){this.generateTextProgram(this.text);var i=this.textLayout,h=this.textStyle,l=i.overflow,f=i.letterSpace,c=void 0===f?0:f,u=this.context,v=0,d=0;u.save();var p=[],x=h.fontSize*this.textStyle.fontScale,g={richOptions:[],offsetX:[],width:0,lineHeight:x*this.singleLineHeight,offsetY:x*(this.singleLineHeight-1)/2};if(this.processedTextOptions.forEach((function(t){var i=t.text,n=t.isNewLine,r=t.fontSize;n&&(p.push(g),v=Math.max(v,g.width),g={richOptions:[],offsetX:[],width:0,lineHeight:x*e.singleLineHeight,offsetY:x*(e.singleLineHeight-1)/2},d+=g.lineHeight),u.font=(t.fontWeight||h.textWeight)+" 10px "+(t.fontFamily||h.fontFamily);var o=u.measureText(i),a=o.width;if(void 0!==o.actualBoundingBoxLeft&&void 0!==o.actualBoundingBoxRight){var s=o.actualBoundingBoxLeft+o.actualBoundingBoxRight;s>0&&(a=Math.max(a,s))}var l=r*e.singleLineHeight*e.textStyle.fontScale;l>g.lineHeight&&(d+=l-g.lineHeight,g.lineHeight=l,g.offsetY=r*e.textStyle.fontScale*(e.singleLineHeight-1)/2),g.offsetX.push(g.width),g.width+=(a<=0?0:a)*r*e.SCALE_FACTOR*e.textStyle.fontScale+i.length*c,g.richOptions.push(t)})),p.push(g),v=Math.max(v,g.width),d+=g.lineHeight,0===v||0===d)return this.isDirty=!1,void u.restore();void 0!==this.size&&null!==this.size||(this.size=this.item.transform.size.clone());var y=this.size,S=y.x,m=void 0===S?1:S,w=y.y,T=void 0===w?1:w;if(!this.initialized){this.canvasSize=this.canvasSize?this.canvasSize:new r.Vector2(v,d);var E=this.canvasSize,L=E.x,z=E.y;this.item.transform.size.set(m*L*this.SCALE_FACTOR*this.SCALE_FACTOR,T*z*this.SCALE_FACTOR*this.SCALE_FACTOR),this.size=this.item.transform.size.clone(),this.initialized=!0}o(this.canvasSize);var C=this.canvasSize,O=C.x,b=C.y;if(this.textLayout.width=O/h.fontScale,this.textLayout.height=b/h.fontScale,this.canvas.width=O,this.canvas.height=b,u.clearRect(0,0,O,b),u.fillStyle="rgba(255, 255, 255, "+this.ALPHA_FIX_VALUE+")",t||(u.translate(0,b),u.scale(1,-1)),0!==p.length){var A=i.getOffsetY(h,p.length,x*this.singleLineHeight,h.fontSize);p.forEach((function(t,i){var r=t.richOptions,o=t.offsetX,a=t.width,s=a,f=o;if(l===n.TextOverflow.display&&a>O){var c=O/a;s*=c,f=o.map((function(t){return t*c}))}var v=e.textLayout.getOffsetX(h,s);i>0&&(A+=t.lineHeight-t.offsetY),r.forEach((function(t,e){var i=h.fontScale,r=h.textColor,o=h.fontFamily,s=h.textWeight,c=h.fontStyle,d=t.text,p=t.fontSize,x=t.fontColor,g=void 0===x?r:x,y=t.fontFamily,S=void 0===y?o:y,m=t.fontWeight,w=void 0===m?s:m,T=t.fontStyle,E=void 0===T?c:T,L=p;l===n.TextOverflow.display&&a>O&&(L/=a/O);var z=f[e]+v;u.font=E+" "+w+" "+L*i+"px "+S,u.fillStyle="rgba("+g[0]+", "+g[1]+", "+g[2]+", "+g[3]+")",u.fillText(d,z,A)}))}));var H=u.getImageData(0,0,this.canvas.width,this.canvas.height),_=a.createWithData(this.engine,{data:new Uint8Array(H.data),width:H.width,height:H.height},{flipY:t,magFilter:s.LINEAR,minFilter:s.LINEAR,wrapS:s.CLAMP_TO_EDGE,wrapT:s.CLAMP_TO_EDGE});this.disposeTextTexture(),this.renderer.texture=_,this.material.setTexture("_MainTex",_),this.isDirty=!1,u.restore()}else u.restore()}},i.updateTextureModern=function(t){var e,i,h=this;this.generateTextProgram(this.text);var l=this.textLayout,f=this.textStyle,c=l.overflow,u=l.letterSpace,v=void 0===u?0:u,d=this.context,p=0,x=0;if(d){d.save();var g=[],y=f.fontSize*this.textStyle.fontScale,S={richOptions:[],offsetX:[],width:0,lineHeight:y*this.singleLineHeight+(this.textLayout.lineGap||0)*this.textStyle.fontScale,offsetY:(this.textLayout.lineGap||0)*this.textStyle.fontScale/2,chars:[]};if(this.processedTextOptions.forEach((function(t){var e=t.text,i=t.isNewLine,n=t.fontSize;i&&(x+=S.lineHeight,g.push(S),p=Math.max(p,S.width),S={richOptions:[],offsetX:[],width:0,lineHeight:y*h.singleLineHeight+(h.textLayout.lineGap||0)*h.textStyle.fontScale,offsetY:(h.textLayout.lineGap||0)*h.textStyle.fontScale/2,chars:[]}),d.font=(t.fontWeight||f.textWeight)+" 10px "+(t.fontFamily||f.fontFamily);var r=n*h.singleLineHeight*h.textStyle.fontScale+(h.textLayout.lineGap||0)*h.textStyle.fontScale;r>S.lineHeight&&(S.lineHeight=r,S.offsetY=(h.textLayout.lineGap||0)*h.textStyle.fontScale/2),S.offsetX.push(S.width);for(var o=0,a=[],s=0;s<e.length;s++){var l=e[s],c=d.measureText(l).width,u=(c<=0?0:c)*n*h.SCALE_FACTOR*h.textStyle.fontScale;a.push({char:l,x:o,width:u}),o+=u+v}S.chars.push(a),S.width+=o,S.richOptions.push(t)})),x+=S.lineHeight,g.push(S),0===(p=Math.max(p,S.width))||0===x)return this.isDirty=!1,void d.restore();void 0!==this.size&&null!==this.size||(this.size=this.item.transform.size.clone());var m=this.size,w=m.x,T=void 0===w?1:w,E=m.y,L=void 0===E?1:E;if(!this.initialized){this.canvasSize=this.canvasSize?this.canvasSize:new r.Vector2(p,x);var z=this.canvasSize,C=z.x,O=z.y;this.item.transform.size.set(T*C*this.SCALE_FACTOR*this.SCALE_FACTOR,L*O*this.SCALE_FACTOR*this.SCALE_FACTOR),this.size=this.item.transform.size.clone(),this.initialized=!0}o(this.canvasSize);var b=this.canvasSize,A=b.x,H=b.y;if(this.textLayout.width=A/f.fontScale,this.textLayout.height=H/f.fontScale,this.canvas.width=A,this.canvas.height=H,d.clearRect(0,0,A,H),d.fillStyle="rgba(255, 255, 255, "+this.ALPHA_FIX_VALUE+")",t||(d.translate(0,H),d.scale(1,-1)),0!==g.length){var _,R=g.map((function(t){return t.lineHeight})),F=g[0],M=(e=Math).max.apply(e,[].concat(null!=(_=null==F||null==(i=F.richOptions)?void 0:i.map((function(t){return t.fontSize})))?_:[this.textStyle.fontSize]))*this.textStyle.fontScale*this.singleLineHeight,k=l.getOffsetYRich(this.textStyle,R,M);g.forEach((function(t,e){var i=t.richOptions,r=t.offsetX,o=t.width,a=t.chars,s=o,l=r;if(c===n.TextOverflow.display&&o>A){var u=A/o;s*=u,l=r.map((function(t){return t*u})),a.forEach((function(t){t.forEach((function(t){t.x*=u,t.width*=u}))}))}var v=h.textLayout.getOffsetX(f,s);i.forEach((function(e,i){var r=f.fontScale,a=f.textColor,s=f.fontFamily,h=f.textWeight,u=f.fontStyle,p=e.fontSize,x=e.fontColor,g=void 0===x?a:x,y=e.fontFamily,S=void 0===y?s:y,m=e.fontWeight,w=void 0===m?h:m,T=e.fontStyle,E=void 0===T?u:T,L=p;c===n.TextOverflow.display&&o>A&&(L/=o/A);var z=l[i]+v;d.font=E+" "+w+" "+L*r+"px "+S,d.fillStyle="rgba("+g[0]+", "+g[1]+", "+g[2]+", "+g[3]+")",t.chars[i].forEach((function(t){d.fillText(t.char,z+t.x,k)}))})),e<g.length-1&&(k+=R[e+1])}));var P=d.getImageData(0,0,this.canvas.width,this.canvas.height),I=a.createWithData(this.engine,{data:new Uint8Array(P.data),width:P.width,height:P.height},{flipY:t,magFilter:s.LINEAR,minFilter:s.LINEAR,wrapS:s.CLAMP_TO_EDGE,wrapT:s.CLAMP_TO_EDGE});this.renderer.texture=I,this.material.setTexture("_MainTex",I),this.isDirty=!1,d.restore()}else d.restore()}},i.setShadowOffsetY=function(t){throw new Error("Method not implemented.")},i.setShadowBlur=function(t){throw new Error("Method not implemented.")},i.setShadowOffsetX=function(t){throw new Error("Method not implemented.")},i.setShadowColor=function(t){throw new Error("Method not implemented.")},i.setOutlineWidth=function(t){throw new Error("Method not implemented.")},i.setAutoWidth=function(t){throw new Error("Method not implemented.")},i.updateWithOptions=function(t){this.textStyle=new h(t),this.textLayout=new l(t),this.textLayout.textBaseline=t.textBaseline||n.TextBaseline.middle,this.text=t.text?t.text.toString():" "},i.renderText=function(t){var e=t.size;e&&(this.canvasSize=new r.Vector2(e[0],e[1])),this.updateTexture()},e}(f);R=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}([i(n.DataType.RichTextComponent)],R);var F="2.7.2";c("rich-text",g,u),v.info("Plugin rich text version: 2.7.2."),F!==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{R as RichTextComponent,g as RichTextLoader,O as escape,z as generateProgram,C as isRichText,E as lexer,L as richTextParser,b as unescape,F 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.7.
|
|
6
|
+
* Version: v2.7.2
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
'use strict';
|
|
@@ -892,7 +892,7 @@ exports.RichTextComponent = __decorate([
|
|
|
892
892
|
|
|
893
893
|
/**
|
|
894
894
|
* 插件版本号
|
|
895
|
-
*/ var version = "2.7.
|
|
895
|
+
*/ var version = "2.7.2";
|
|
896
896
|
EFFECTS.registerPlugin("rich-text", RichTextLoader, EFFECTS.VFXItem);
|
|
897
897
|
EFFECTS.logger.info("Plugin rich text version: " + version + ".");
|
|
898
898
|
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.7.
|
|
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)}var s=function(t){function e(){var e;return e=t.apply(this,arguments)||this,e.name="rich-text",e}return a(e,t),e}(e.AbstractPlugin);function h(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 l(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 h(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 h(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 c=/^<([a-z]+)(=([^>]+))?>$/,f=/^<\/([a-z]+)>$/,u=[["EscapedChar",/^\\([=<>\\/])/],["ContextStart",/^<[a-z]+(=[^>]+)?>/],["ContextEnd",/^<\/[a-z]+>/],["Text",/^[^</>=\\]+/]],p=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 p(t.slice(2),e.concat({tokenType:"Text",value:r}),i+2)}for(var o,a=l(u);!(o=a()).done;){var s=o.value,h=s[0],c=s[1];if("EscapedChar"!==h){var f=c.exec(t);if(f){var d=f[0],x=d.length;return p(t.slice(x),e.concat({tokenType:h,value:d}),i+x)}}}if(t.length>0)return p(t.slice(1),e.concat({tokenType:"Text",value:t[0]}),i+1);throw Error('Unexpected token: "'+t[0]+'" at position '+i+' while reading "'+t+'"')},d=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(c);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(f);if(e)return{attributeName:e[1]};throw Error("Expect an end tag marker at position "+o)}return{}},r=p(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]},h=[];return!function t(r,a){for(void 0===r&&(r=[]),void 0===a&&(a="");;){var s=e();if(s){h.push({attributes:r,text:s});continue}var l=i(),c=l.attributeName,f=l.attributeParam;if(c){t(r.concat({attributeName:c,attributeParam:null!=f?f:""}),c);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}}(),h};function x(t){return function(e){for(var i,n=d(e),r=l(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 g(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"==typeof SuppressedError&&SuppressedError;var v=0;t.RichTextComponent=function(t){function i(e){var i;return(i=t.call(this,e)||this).processedTextOptions=[],i.singleLineHeight=1.571,i.size=null,i.initialized=!1,i.canvasSize=null,i.name="MRichText"+v++,i}a(i,t);var n=i.prototype;return n.generateTextProgram=function(t){var i=this;this.processedTextOptions=[],x(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("#")?g(t,e):g(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{e.remove()}throw Error("Failed to get 2D context for color conversion!")}(t))}(n.color)),i.processedTextOptions.push(o)})})(t)},n.updateTexture=function(t){if(void 0===t&&(t=!0),this.isDirty&&this.context&&this.canvas){var e=!0===this.textLayout.useLegacyRichText;this.singleLineHeight=e?1.571:1,e?this.updateTextureLegacy(t):this.updateTextureModern(t)}},n.updateTextureLegacy=function(t){var i=this;if(this.isDirty&&this.context&&this.canvas){this.generateTextProgram(this.text);var n=this.textLayout,r=this.textStyle,o=n.overflow,a=n.letterSpace,s=void 0===a?0:a,h=this.context,l=0,c=0;h.save();var f=[],u=r.fontSize*this.textStyle.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,n=t.isNewLine,o=t.fontSize;n&&(f.push(p),l=Math.max(l,p.width),p={richOptions:[],offsetX:[],width:0,lineHeight:u*i.singleLineHeight,offsetY:u*(i.singleLineHeight-1)/2},c+=p.lineHeight),h.font=(t.fontWeight||r.textWeight)+" 10px "+(t.fontFamily||r.fontFamily);var a=h.measureText(e),d=a.width;if(void 0!==a.actualBoundingBoxLeft&&void 0!==a.actualBoundingBoxRight){var x=a.actualBoundingBoxLeft+a.actualBoundingBoxRight;x>0&&(d=Math.max(d,x))}var g=o*i.singleLineHeight*i.textStyle.fontScale;g>p.lineHeight&&(c+=g-p.lineHeight,p.lineHeight=g,p.offsetY=o*i.textStyle.fontScale*(i.singleLineHeight-1)/2),p.offsetX.push(p.width),p.width+=(d<=0?0:d)*o*i.SCALE_FACTOR*i.textStyle.fontScale+e.length*s,p.richOptions.push(t)}),f.push(p),l=Math.max(l,p.width),c+=p.lineHeight,0===l||0===c){this.isDirty=!1,h.restore();return}(void 0===this.size||null===this.size)&&(this.size=this.item.transform.size.clone());var d=this.size,x=d.x,g=d.y;if(!this.initialized){this.canvasSize=this.canvasSize?this.canvasSize:new e.math.Vector2(l,c);var v=this.canvasSize,y=v.x,m=v.y;this.item.transform.size.set((void 0===x?1:x)*y*this.SCALE_FACTOR*this.SCALE_FACTOR,(void 0===g?1:g)*m*this.SCALE_FACTOR*this.SCALE_FACTOR),this.size=this.item.transform.size.clone(),this.initialized=!0}e.assertExist(this.canvasSize);var S=this.canvasSize,T=S.x,w=S.y;if(this.textLayout.width=T/r.fontScale,this.textLayout.height=w/r.fontScale,this.canvas.width=T,this.canvas.height=w,h.clearRect(0,0,T,w),h.fillStyle="rgba(255, 255, 255, "+this.ALPHA_FIX_VALUE+")",t||(h.translate(0,w),h.scale(1,-1)),0===f.length){h.restore();return}var E=n.getOffsetY(r,f.length,u*this.singleLineHeight,r.fontSize);f.forEach(function(t,n){var a=t.richOptions,s=t.offsetX,l=t.width,c=l,f=s;if(o===e.spec.TextOverflow.display&&l>T){var u=T/l;c*=u,f=s.map(function(t){return t*u})}var p=i.textLayout.getOffsetX(r,c);n>0&&(E+=t.lineHeight-t.offsetY),a.forEach(function(t,i){var n=r.fontScale,a=r.textColor,s=r.fontFamily,c=r.textWeight,u=r.fontStyle,d=t.text,x=t.fontSize,g=t.fontColor,v=void 0===g?a:g,y=t.fontFamily,m=t.fontWeight,S=t.fontStyle,w=x;o===e.spec.TextOverflow.display&&l>T&&(w/=l/T);var C=f[i]+p;h.font=(void 0===S?u:S)+" "+(void 0===m?c:m)+" "+w*n+"px "+(void 0===y?s:y),h.fillStyle="rgba("+v[0]+", "+v[1]+", "+v[2]+", "+v[3]+")",h.fillText(d,C,E)})});var C=h.getImageData(0,0,this.canvas.width,this.canvas.height),L=e.Texture.createWithData(this.engine,{data:new Uint8Array(C.data),width:C.width,height:C.height},{flipY:t,magFilter:e.glContext.LINEAR,minFilter:e.glContext.LINEAR,wrapS:e.glContext.CLAMP_TO_EDGE,wrapT:e.glContext.CLAMP_TO_EDGE});this.disposeTextTexture(),this.renderer.texture=L,this.material.setTexture("_MainTex",L),this.isDirty=!1,h.restore()}},n.updateTextureModern=function(t){var i,n,r,o=this;this.generateTextProgram(this.text);var a=this.textLayout,s=this.textStyle,h=a.overflow,l=a.letterSpace,c=void 0===l?0:l,f=this.context,u=0,p=0;if(f){f.save();var d=[],x=s.fontSize*this.textStyle.fontScale,g={richOptions:[],offsetX:[],width:0,lineHeight:x*this.singleLineHeight+(this.textLayout.lineGap||0)*this.textStyle.fontScale,offsetY:(this.textLayout.lineGap||0)*this.textStyle.fontScale/2,chars:[]};if(this.processedTextOptions.forEach(function(t){var e=t.text,i=t.isNewLine,n=t.fontSize;i&&(p+=g.lineHeight,d.push(g),u=Math.max(u,g.width),g={richOptions:[],offsetX:[],width:0,lineHeight:x*o.singleLineHeight+(o.textLayout.lineGap||0)*o.textStyle.fontScale,offsetY:(o.textLayout.lineGap||0)*o.textStyle.fontScale/2,chars:[]}),f.font=(t.fontWeight||s.textWeight)+" 10px "+(t.fontFamily||s.fontFamily);var r=n*o.singleLineHeight*o.textStyle.fontScale+(o.textLayout.lineGap||0)*o.textStyle.fontScale;r>g.lineHeight&&(g.lineHeight=r,g.offsetY=(o.textLayout.lineGap||0)*o.textStyle.fontScale/2),g.offsetX.push(g.width);for(var a=0,h=[],l=0;l<e.length;l++){var v=e[l],y=f.measureText(v).width,m=(y<=0?0:y)*n*o.SCALE_FACTOR*o.textStyle.fontScale;h.push({char:v,x:a,width:m}),a+=m+c}g.chars.push(h),g.width+=a,g.richOptions.push(t)}),p+=g.lineHeight,d.push(g),0===(u=Math.max(u,g.width))||0===p){this.isDirty=!1,f.restore();return}(void 0===this.size||null===this.size)&&(this.size=this.item.transform.size.clone());var v=this.size,y=v.x,m=v.y;if(!this.initialized){this.canvasSize=this.canvasSize?this.canvasSize:new e.math.Vector2(u,p);var S=this.canvasSize,T=S.x,w=S.y;this.item.transform.size.set((void 0===y?1:y)*T*this.SCALE_FACTOR*this.SCALE_FACTOR,(void 0===m?1:m)*w*this.SCALE_FACTOR*this.SCALE_FACTOR),this.size=this.item.transform.size.clone(),this.initialized=!0}e.assertExist(this.canvasSize);var E=this.canvasSize,C=E.x,L=E.y;if(this.textLayout.width=C/s.fontScale,this.textLayout.height=L/s.fontScale,this.canvas.width=C,this.canvas.height=L,f.clearRect(0,0,C,L),f.fillStyle="rgba(255, 255, 255, "+this.ALPHA_FIX_VALUE+")",t||(f.translate(0,L),f.scale(1,-1)),0===d.length){f.restore();return}var z=d.map(function(t){return t.lineHeight}),b=d[0],O=(i=Math).max.apply(i,[].concat(null!=(r=null==b?void 0:null==(n=b.richOptions)?void 0:n.map(function(t){return t.fontSize}))?r:[this.textStyle.fontSize]))*this.textStyle.fontScale*this.singleLineHeight,A=a.getOffsetYRich(this.textStyle,z,O);d.forEach(function(t,i){var n=t.richOptions,r=t.offsetX,a=t.width,l=t.chars,c=a,u=r;if(h===e.spec.TextOverflow.display&&a>C){var p=C/a;c*=p,u=r.map(function(t){return t*p}),l.forEach(function(t){t.forEach(function(t){t.x*=p,t.width*=p})})}var x=o.textLayout.getOffsetX(s,c);n.forEach(function(i,n){var r=s.fontScale,o=s.textColor,l=s.fontFamily,c=s.textWeight,p=s.fontStyle,d=i.fontSize,g=i.fontColor,v=void 0===g?o:g,y=i.fontFamily,m=i.fontWeight,S=i.fontStyle,T=d;h===e.spec.TextOverflow.display&&a>C&&(T/=a/C);var w=u[n]+x;f.font=(void 0===S?p:S)+" "+(void 0===m?c:m)+" "+T*r+"px "+(void 0===y?l:y),f.fillStyle="rgba("+v[0]+", "+v[1]+", "+v[2]+", "+v[3]+")",t.chars[n].forEach(function(t){f.fillText(t.char,w+t.x,A)})}),i<d.length-1&&(A+=z[i+1])});var R=f.getImageData(0,0,this.canvas.width,this.canvas.height),_=e.Texture.createWithData(this.engine,{data:new Uint8Array(R.data),width:R.width,height:R.height},{flipY:t,magFilter:e.glContext.LINEAR,minFilter:e.glContext.LINEAR,wrapS:e.glContext.CLAMP_TO_EDGE,wrapT:e.glContext.CLAMP_TO_EDGE});this.renderer.texture=_,this.material.setTexture("_MainTex",_),this.isDirty=!1,f.restore()}},n.setShadowOffsetY=function(t){throw Error("Method not implemented.")},n.setShadowBlur=function(t){throw Error("Method not implemented.")},n.setShadowOffsetX=function(t){throw Error("Method not implemented.")},n.setShadowColor=function(t){throw Error("Method not implemented.")},n.setOutlineWidth=function(t){throw Error("Method not implemented.")},n.setAutoWidth=function(t){throw Error("Method not implemented.")},n.updateWithOptions=function(t){this.textStyle=new e.TextStyle(t),this.textLayout=new e.TextLayout(t),this.textLayout.textBaseline=t.textBaseline||e.spec.TextBaseline.middle,this.text=t.text?t.text.toString():" "},n.renderText=function(t){var i=t.size;i&&(this.canvasSize=new e.math.Vector2(i[0],i[1])),this.updateTexture()},i}(e.TextComponent),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);var y="2.7.0";e.registerPlugin("rich-text",s,e.VFXItem),e.logger.info("Plugin rich text version: "+y+"."),y!==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=s,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=x,t.isRichText=function(t){var e=p(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(c)[1]:i.match(f)[1]}}))},t.lexer=p,t.richTextParser=d,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=y,Object.defineProperty(t,"__esModule",{value:!0})});
|
|
6
|
+
* Version: v2.7.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)}var s=function(t){function e(){var e;return e=t.apply(this,arguments)||this,e.name="rich-text",e}return a(e,t),e}(e.AbstractPlugin);function h(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 l(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 h(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 h(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 c=/^<([a-z]+)(=([^>]+))?>$/,f=/^<\/([a-z]+)>$/,u=[["EscapedChar",/^\\([=<>\\/])/],["ContextStart",/^<[a-z]+(=[^>]+)?>/],["ContextEnd",/^<\/[a-z]+>/],["Text",/^[^</>=\\]+/]],p=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 p(t.slice(2),e.concat({tokenType:"Text",value:r}),i+2)}for(var o,a=l(u);!(o=a()).done;){var s=o.value,h=s[0],c=s[1];if("EscapedChar"!==h){var f=c.exec(t);if(f){var d=f[0],x=d.length;return p(t.slice(x),e.concat({tokenType:h,value:d}),i+x)}}}if(t.length>0)return p(t.slice(1),e.concat({tokenType:"Text",value:t[0]}),i+1);throw Error('Unexpected token: "'+t[0]+'" at position '+i+' while reading "'+t+'"')},d=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(c);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(f);if(e)return{attributeName:e[1]};throw Error("Expect an end tag marker at position "+o)}return{}},r=p(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]},h=[];return!function t(r,a){for(void 0===r&&(r=[]),void 0===a&&(a="");;){var s=e();if(s){h.push({attributes:r,text:s});continue}var l=i(),c=l.attributeName,f=l.attributeParam;if(c){t(r.concat({attributeName:c,attributeParam:null!=f?f:""}),c);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}}(),h};function x(t){return function(e){for(var i,n=d(e),r=l(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 g(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"==typeof SuppressedError&&SuppressedError;var v=0;t.RichTextComponent=function(t){function i(e){var i;return(i=t.call(this,e)||this).processedTextOptions=[],i.singleLineHeight=1.571,i.size=null,i.initialized=!1,i.canvasSize=null,i.name="MRichText"+v++,i}a(i,t);var n=i.prototype;return n.generateTextProgram=function(t){var i=this;this.processedTextOptions=[],x(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("#")?g(t,e):g(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{e.remove()}throw Error("Failed to get 2D context for color conversion!")}(t))}(n.color)),i.processedTextOptions.push(o)})})(t)},n.updateTexture=function(t){if(void 0===t&&(t=!0),this.isDirty&&this.context&&this.canvas){var e=!0===this.textLayout.useLegacyRichText;this.singleLineHeight=e?1.571:1,e?this.updateTextureLegacy(t):this.updateTextureModern(t)}},n.updateTextureLegacy=function(t){var i=this;if(this.isDirty&&this.context&&this.canvas){this.generateTextProgram(this.text);var n=this.textLayout,r=this.textStyle,o=n.overflow,a=n.letterSpace,s=void 0===a?0:a,h=this.context,l=0,c=0;h.save();var f=[],u=r.fontSize*this.textStyle.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,n=t.isNewLine,o=t.fontSize;n&&(f.push(p),l=Math.max(l,p.width),p={richOptions:[],offsetX:[],width:0,lineHeight:u*i.singleLineHeight,offsetY:u*(i.singleLineHeight-1)/2},c+=p.lineHeight),h.font=(t.fontWeight||r.textWeight)+" 10px "+(t.fontFamily||r.fontFamily);var a=h.measureText(e),d=a.width;if(void 0!==a.actualBoundingBoxLeft&&void 0!==a.actualBoundingBoxRight){var x=a.actualBoundingBoxLeft+a.actualBoundingBoxRight;x>0&&(d=Math.max(d,x))}var g=o*i.singleLineHeight*i.textStyle.fontScale;g>p.lineHeight&&(c+=g-p.lineHeight,p.lineHeight=g,p.offsetY=o*i.textStyle.fontScale*(i.singleLineHeight-1)/2),p.offsetX.push(p.width),p.width+=(d<=0?0:d)*o*i.SCALE_FACTOR*i.textStyle.fontScale+e.length*s,p.richOptions.push(t)}),f.push(p),l=Math.max(l,p.width),c+=p.lineHeight,0===l||0===c){this.isDirty=!1,h.restore();return}(void 0===this.size||null===this.size)&&(this.size=this.item.transform.size.clone());var d=this.size,x=d.x,g=d.y;if(!this.initialized){this.canvasSize=this.canvasSize?this.canvasSize:new e.math.Vector2(l,c);var v=this.canvasSize,y=v.x,m=v.y;this.item.transform.size.set((void 0===x?1:x)*y*this.SCALE_FACTOR*this.SCALE_FACTOR,(void 0===g?1:g)*m*this.SCALE_FACTOR*this.SCALE_FACTOR),this.size=this.item.transform.size.clone(),this.initialized=!0}e.assertExist(this.canvasSize);var S=this.canvasSize,T=S.x,w=S.y;if(this.textLayout.width=T/r.fontScale,this.textLayout.height=w/r.fontScale,this.canvas.width=T,this.canvas.height=w,h.clearRect(0,0,T,w),h.fillStyle="rgba(255, 255, 255, "+this.ALPHA_FIX_VALUE+")",t||(h.translate(0,w),h.scale(1,-1)),0===f.length){h.restore();return}var E=n.getOffsetY(r,f.length,u*this.singleLineHeight,r.fontSize);f.forEach(function(t,n){var a=t.richOptions,s=t.offsetX,l=t.width,c=l,f=s;if(o===e.spec.TextOverflow.display&&l>T){var u=T/l;c*=u,f=s.map(function(t){return t*u})}var p=i.textLayout.getOffsetX(r,c);n>0&&(E+=t.lineHeight-t.offsetY),a.forEach(function(t,i){var n=r.fontScale,a=r.textColor,s=r.fontFamily,c=r.textWeight,u=r.fontStyle,d=t.text,x=t.fontSize,g=t.fontColor,v=void 0===g?a:g,y=t.fontFamily,m=t.fontWeight,S=t.fontStyle,w=x;o===e.spec.TextOverflow.display&&l>T&&(w/=l/T);var C=f[i]+p;h.font=(void 0===S?u:S)+" "+(void 0===m?c:m)+" "+w*n+"px "+(void 0===y?s:y),h.fillStyle="rgba("+v[0]+", "+v[1]+", "+v[2]+", "+v[3]+")",h.fillText(d,C,E)})});var C=h.getImageData(0,0,this.canvas.width,this.canvas.height),L=e.Texture.createWithData(this.engine,{data:new Uint8Array(C.data),width:C.width,height:C.height},{flipY:t,magFilter:e.glContext.LINEAR,minFilter:e.glContext.LINEAR,wrapS:e.glContext.CLAMP_TO_EDGE,wrapT:e.glContext.CLAMP_TO_EDGE});this.disposeTextTexture(),this.renderer.texture=L,this.material.setTexture("_MainTex",L),this.isDirty=!1,h.restore()}},n.updateTextureModern=function(t){var i,n,r,o=this;this.generateTextProgram(this.text);var a=this.textLayout,s=this.textStyle,h=a.overflow,l=a.letterSpace,c=void 0===l?0:l,f=this.context,u=0,p=0;if(f){f.save();var d=[],x=s.fontSize*this.textStyle.fontScale,g={richOptions:[],offsetX:[],width:0,lineHeight:x*this.singleLineHeight+(this.textLayout.lineGap||0)*this.textStyle.fontScale,offsetY:(this.textLayout.lineGap||0)*this.textStyle.fontScale/2,chars:[]};if(this.processedTextOptions.forEach(function(t){var e=t.text,i=t.isNewLine,n=t.fontSize;i&&(p+=g.lineHeight,d.push(g),u=Math.max(u,g.width),g={richOptions:[],offsetX:[],width:0,lineHeight:x*o.singleLineHeight+(o.textLayout.lineGap||0)*o.textStyle.fontScale,offsetY:(o.textLayout.lineGap||0)*o.textStyle.fontScale/2,chars:[]}),f.font=(t.fontWeight||s.textWeight)+" 10px "+(t.fontFamily||s.fontFamily);var r=n*o.singleLineHeight*o.textStyle.fontScale+(o.textLayout.lineGap||0)*o.textStyle.fontScale;r>g.lineHeight&&(g.lineHeight=r,g.offsetY=(o.textLayout.lineGap||0)*o.textStyle.fontScale/2),g.offsetX.push(g.width);for(var a=0,h=[],l=0;l<e.length;l++){var v=e[l],y=f.measureText(v).width,m=(y<=0?0:y)*n*o.SCALE_FACTOR*o.textStyle.fontScale;h.push({char:v,x:a,width:m}),a+=m+c}g.chars.push(h),g.width+=a,g.richOptions.push(t)}),p+=g.lineHeight,d.push(g),0===(u=Math.max(u,g.width))||0===p){this.isDirty=!1,f.restore();return}(void 0===this.size||null===this.size)&&(this.size=this.item.transform.size.clone());var v=this.size,y=v.x,m=v.y;if(!this.initialized){this.canvasSize=this.canvasSize?this.canvasSize:new e.math.Vector2(u,p);var S=this.canvasSize,T=S.x,w=S.y;this.item.transform.size.set((void 0===y?1:y)*T*this.SCALE_FACTOR*this.SCALE_FACTOR,(void 0===m?1:m)*w*this.SCALE_FACTOR*this.SCALE_FACTOR),this.size=this.item.transform.size.clone(),this.initialized=!0}e.assertExist(this.canvasSize);var E=this.canvasSize,C=E.x,L=E.y;if(this.textLayout.width=C/s.fontScale,this.textLayout.height=L/s.fontScale,this.canvas.width=C,this.canvas.height=L,f.clearRect(0,0,C,L),f.fillStyle="rgba(255, 255, 255, "+this.ALPHA_FIX_VALUE+")",t||(f.translate(0,L),f.scale(1,-1)),0===d.length){f.restore();return}var z=d.map(function(t){return t.lineHeight}),b=d[0],O=(i=Math).max.apply(i,[].concat(null!=(r=null==b?void 0:null==(n=b.richOptions)?void 0:n.map(function(t){return t.fontSize}))?r:[this.textStyle.fontSize]))*this.textStyle.fontScale*this.singleLineHeight,A=a.getOffsetYRich(this.textStyle,z,O);d.forEach(function(t,i){var n=t.richOptions,r=t.offsetX,a=t.width,l=t.chars,c=a,u=r;if(h===e.spec.TextOverflow.display&&a>C){var p=C/a;c*=p,u=r.map(function(t){return t*p}),l.forEach(function(t){t.forEach(function(t){t.x*=p,t.width*=p})})}var x=o.textLayout.getOffsetX(s,c);n.forEach(function(i,n){var r=s.fontScale,o=s.textColor,l=s.fontFamily,c=s.textWeight,p=s.fontStyle,d=i.fontSize,g=i.fontColor,v=void 0===g?o:g,y=i.fontFamily,m=i.fontWeight,S=i.fontStyle,T=d;h===e.spec.TextOverflow.display&&a>C&&(T/=a/C);var w=u[n]+x;f.font=(void 0===S?p:S)+" "+(void 0===m?c:m)+" "+T*r+"px "+(void 0===y?l:y),f.fillStyle="rgba("+v[0]+", "+v[1]+", "+v[2]+", "+v[3]+")",t.chars[n].forEach(function(t){f.fillText(t.char,w+t.x,A)})}),i<d.length-1&&(A+=z[i+1])});var R=f.getImageData(0,0,this.canvas.width,this.canvas.height),_=e.Texture.createWithData(this.engine,{data:new Uint8Array(R.data),width:R.width,height:R.height},{flipY:t,magFilter:e.glContext.LINEAR,minFilter:e.glContext.LINEAR,wrapS:e.glContext.CLAMP_TO_EDGE,wrapT:e.glContext.CLAMP_TO_EDGE});this.renderer.texture=_,this.material.setTexture("_MainTex",_),this.isDirty=!1,f.restore()}},n.setShadowOffsetY=function(t){throw Error("Method not implemented.")},n.setShadowBlur=function(t){throw Error("Method not implemented.")},n.setShadowOffsetX=function(t){throw Error("Method not implemented.")},n.setShadowColor=function(t){throw Error("Method not implemented.")},n.setOutlineWidth=function(t){throw Error("Method not implemented.")},n.setAutoWidth=function(t){throw Error("Method not implemented.")},n.updateWithOptions=function(t){this.textStyle=new e.TextStyle(t),this.textLayout=new e.TextLayout(t),this.textLayout.textBaseline=t.textBaseline||e.spec.TextBaseline.middle,this.text=t.text?t.text.toString():" "},n.renderText=function(t){var i=t.size;i&&(this.canvasSize=new e.math.Vector2(i[0],i[1])),this.updateTexture()},i}(e.TextComponent),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);var y="2.7.2";e.registerPlugin("rich-text",s,e.VFXItem),e.logger.info("Plugin rich text version: "+y+"."),y!==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=s,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=x,t.isRichText=function(t){var e=p(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(c)[1]:i.match(f)[1]}}))},t.lexer=p,t.richTextParser=d,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=y,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.7.
|
|
6
|
+
* Version: v2.7.2
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import * as EFFECTS from '@galacean/effects';
|
|
@@ -869,7 +869,7 @@ RichTextComponent = __decorate([
|
|
|
869
869
|
|
|
870
870
|
/**
|
|
871
871
|
* 插件版本号
|
|
872
|
-
*/ var version = "2.7.
|
|
872
|
+
*/ var version = "2.7.2";
|
|
873
873
|
registerPlugin("rich-text", RichTextLoader, VFXItem);
|
|
874
874
|
logger.info("Plugin rich text version: " + version + ".");
|
|
875
875
|
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");function e(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 i=e(t);function n(t,e){return n=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},n(t,e)}function r(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&&n(t,e)}var o,a=function(t){function e(){var e;return(e=t.apply(this,arguments)||this).name="rich-text",e}return r(e,t),e}(t.AbstractPlugin);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 h(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"}(o||(o={}));var l=/^<([a-z]+)(=([^>]+))?>$/,c=/^<\/([a-z]+)>$/,f=[["EscapedChar",/^\\([=<>\\/])/],["ContextStart",/^<[a-z]+(=[^>]+)?>/],["ContextEnd",/^<\/[a-z]+>/],["Text",/^[^</>=\\]+/]],u=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 u(t.slice(2),e.concat({tokenType:"Text",value:r}),i+2)}for(var o,a=h(f);!(o=a()).done;){var s=o.value,l=s[0],c=s[1];if("EscapedChar"!==l){var p=c.exec(t);if(p){var x=p[0],v=x.length;return u(t.slice(v),e.concat({tokenType:l,value:x}),i+v)}}}if(t.length>0)return u(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+'"')},p=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(l);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(c);if(e)return{attributeName:e[1]};throw new Error("Expect an end tag marker at position "+o)}return{}},r=u(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]},h=[];return function t(r,a){for(void 0===r&&(r=[]),void 0===a&&(a="");;){var s=e();if(s)h.push({attributes:r,text:s});else{var l=i(),c=l.attributeName,f=l.attributeParam;if(!c){if(a){var u=n().attributeName;if(!u)throw new Error('Expect an end tag marker "'+a+'" at position '+o+" but found no tag!");if(u!==a)throw new Error('Expect an end tag marker "'+a+'" at position '+o+' but found tag "'+u+'"');return}break}t(r.concat({attributeName:c,attributeParam:null!=f?f:""}),c)}}}(),h};function x(t){return function(e){for(var i,n=h(p(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 v(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 d(t,e){if(void 0===e&&(e=1),"string"!=typeof t||!t)throw new Error("Invalid color string");return t.startsWith("#")?v(t,e):v(function(t){if("string"!=typeof t||!t)throw new Error("Invalid color name provided");if("undefined"==typeof document)throw new 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{e.remove()}throw new Error("Failed to get 2D context for color conversion!")}(t))}"function"==typeof SuppressedError&&SuppressedError;var g=0;exports.RichTextComponent=function(e){function i(t){var i;return(i=e.call(this,t)||this).processedTextOptions=[],i.singleLineHeight=1.571,i.size=null,i.initialized=!1,i.canvasSize=null,i.name="MRichText"+g++,i}r(i,e);var n=i.prototype;return n.generateTextProgram=function(e){var i=this;this.processedTextOptions=[];var n=x((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=d(n.color)),i.processedTextOptions.push(o)}))}));n(e)},n.updateTexture=function(t){if(void 0===t&&(t=!0),this.isDirty&&this.context&&this.canvas){var e=!0===this.textLayout.useLegacyRichText;this.singleLineHeight=e?1.571:1,e?this.updateTextureLegacy(t):this.updateTextureModern(t)}},n.updateTextureLegacy=function(e){var i=this;if(this.isDirty&&this.context&&this.canvas){this.generateTextProgram(this.text);var n=this.textLayout,r=this.textStyle,o=n.overflow,a=n.letterSpace,s=void 0===a?0:a,h=this.context,l=0,c=0;h.save();var f=[],u=r.fontSize*this.textStyle.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,n=t.isNewLine,o=t.fontSize;n&&(f.push(p),l=Math.max(l,p.width),p={richOptions:[],offsetX:[],width:0,lineHeight:u*i.singleLineHeight,offsetY:u*(i.singleLineHeight-1)/2},c+=p.lineHeight),h.font=(t.fontWeight||r.textWeight)+" 10px "+(t.fontFamily||r.fontFamily);var a=h.measureText(e),x=a.width;if(void 0!==a.actualBoundingBoxLeft&&void 0!==a.actualBoundingBoxRight){var v=a.actualBoundingBoxLeft+a.actualBoundingBoxRight;v>0&&(x=Math.max(x,v))}var d=o*i.singleLineHeight*i.textStyle.fontScale;d>p.lineHeight&&(c+=d-p.lineHeight,p.lineHeight=d,p.offsetY=o*i.textStyle.fontScale*(i.singleLineHeight-1)/2),p.offsetX.push(p.width),p.width+=(x<=0?0:x)*o*i.SCALE_FACTOR*i.textStyle.fontScale+e.length*s,p.richOptions.push(t)})),f.push(p),l=Math.max(l,p.width),c+=p.lineHeight,0===l||0===c)return this.isDirty=!1,void h.restore();void 0!==this.size&&null!==this.size||(this.size=this.item.transform.size.clone());var x=this.size,v=x.x,d=void 0===v?1:v,g=x.y,y=void 0===g?1:g;if(!this.initialized){this.canvasSize=this.canvasSize?this.canvasSize:new t.math.Vector2(l,c);var S=this.canvasSize,m=S.x,w=S.y;this.item.transform.size.set(d*m*this.SCALE_FACTOR*this.SCALE_FACTOR,y*w*this.SCALE_FACTOR*this.SCALE_FACTOR),this.size=this.item.transform.size.clone(),this.initialized=!0}t.assertExist(this.canvasSize);var T=this.canvasSize,E=T.x,C=T.y;if(this.textLayout.width=E/r.fontScale,this.textLayout.height=C/r.fontScale,this.canvas.width=E,this.canvas.height=C,h.clearRect(0,0,E,C),h.fillStyle="rgba(255, 255, 255, "+this.ALPHA_FIX_VALUE+")",e||(h.translate(0,C),h.scale(1,-1)),0!==f.length){var L=n.getOffsetY(r,f.length,u*this.singleLineHeight,r.fontSize);f.forEach((function(e,n){var a=e.richOptions,s=e.offsetX,l=e.width,c=l,f=s;if(o===t.spec.TextOverflow.display&&l>E){var u=E/l;c*=u,f=s.map((function(t){return t*u}))}var p=i.textLayout.getOffsetX(r,c);n>0&&(L+=e.lineHeight-e.offsetY),a.forEach((function(e,i){var n=r.fontScale,a=r.textColor,s=r.fontFamily,c=r.textWeight,u=r.fontStyle,x=e.text,v=e.fontSize,d=e.fontColor,g=void 0===d?a:d,y=e.fontFamily,S=void 0===y?s:y,m=e.fontWeight,w=void 0===m?c:m,T=e.fontStyle,C=void 0===T?u:T,z=v;o===t.spec.TextOverflow.display&&l>E&&(z/=l/E);var O=f[i]+p;h.font=C+" "+w+" "+z*n+"px "+S,h.fillStyle="rgba("+g[0]+", "+g[1]+", "+g[2]+", "+g[3]+")",h.fillText(x,O,L)}))}));var z=h.getImageData(0,0,this.canvas.width,this.canvas.height),O=t.Texture.createWithData(this.engine,{data:new Uint8Array(z.data),width:z.width,height:z.height},{flipY:e,magFilter:t.glContext.LINEAR,minFilter:t.glContext.LINEAR,wrapS:t.glContext.CLAMP_TO_EDGE,wrapT:t.glContext.CLAMP_TO_EDGE});this.disposeTextTexture(),this.renderer.texture=O,this.material.setTexture("_MainTex",O),this.isDirty=!1,h.restore()}else h.restore()}},n.updateTextureModern=function(e){var i,n,r=this;this.generateTextProgram(this.text);var o=this.textLayout,a=this.textStyle,s=o.overflow,h=o.letterSpace,l=void 0===h?0:h,c=this.context,f=0,u=0;if(c){c.save();var p=[],x=a.fontSize*this.textStyle.fontScale,v={richOptions:[],offsetX:[],width:0,lineHeight:x*this.singleLineHeight+(this.textLayout.lineGap||0)*this.textStyle.fontScale,offsetY:(this.textLayout.lineGap||0)*this.textStyle.fontScale/2,chars:[]};if(this.processedTextOptions.forEach((function(t){var e=t.text,i=t.isNewLine,n=t.fontSize;i&&(u+=v.lineHeight,p.push(v),f=Math.max(f,v.width),v={richOptions:[],offsetX:[],width:0,lineHeight:x*r.singleLineHeight+(r.textLayout.lineGap||0)*r.textStyle.fontScale,offsetY:(r.textLayout.lineGap||0)*r.textStyle.fontScale/2,chars:[]}),c.font=(t.fontWeight||a.textWeight)+" 10px "+(t.fontFamily||a.fontFamily);var o=n*r.singleLineHeight*r.textStyle.fontScale+(r.textLayout.lineGap||0)*r.textStyle.fontScale;o>v.lineHeight&&(v.lineHeight=o,v.offsetY=(r.textLayout.lineGap||0)*r.textStyle.fontScale/2),v.offsetX.push(v.width);for(var s=0,h=[],d=0;d<e.length;d++){var g=e[d],y=c.measureText(g).width,S=(y<=0?0:y)*n*r.SCALE_FACTOR*r.textStyle.fontScale;h.push({char:g,x:s,width:S}),s+=S+l}v.chars.push(h),v.width+=s,v.richOptions.push(t)})),u+=v.lineHeight,p.push(v),0===(f=Math.max(f,v.width))||0===u)return this.isDirty=!1,void c.restore();void 0!==this.size&&null!==this.size||(this.size=this.item.transform.size.clone());var d=this.size,g=d.x,y=void 0===g?1:g,S=d.y,m=void 0===S?1:S;if(!this.initialized){this.canvasSize=this.canvasSize?this.canvasSize:new t.math.Vector2(f,u);var w=this.canvasSize,T=w.x,E=w.y;this.item.transform.size.set(y*T*this.SCALE_FACTOR*this.SCALE_FACTOR,m*E*this.SCALE_FACTOR*this.SCALE_FACTOR),this.size=this.item.transform.size.clone(),this.initialized=!0}t.assertExist(this.canvasSize);var C=this.canvasSize,L=C.x,z=C.y;if(this.textLayout.width=L/a.fontScale,this.textLayout.height=z/a.fontScale,this.canvas.width=L,this.canvas.height=z,c.clearRect(0,0,L,z),c.fillStyle="rgba(255, 255, 255, "+this.ALPHA_FIX_VALUE+")",e||(c.translate(0,z),c.scale(1,-1)),0!==p.length){var O,b=p.map((function(t){return t.lineHeight})),A=p[0],R=(i=Math).max.apply(i,[].concat(null!=(O=null==A||null==(n=A.richOptions)?void 0:n.map((function(t){return t.fontSize})))?O:[this.textStyle.fontSize]))*this.textStyle.fontScale*this.singleLineHeight,_=o.getOffsetYRich(this.textStyle,b,R);p.forEach((function(e,i){var n=e.richOptions,o=e.offsetX,h=e.width,l=e.chars,f=h,u=o;if(s===t.spec.TextOverflow.display&&h>L){var x=L/h;f*=x,u=o.map((function(t){return t*x})),l.forEach((function(t){t.forEach((function(t){t.x*=x,t.width*=x}))}))}var v=r.textLayout.getOffsetX(a,f);n.forEach((function(i,n){var r=a.fontScale,o=a.textColor,l=a.fontFamily,f=a.textWeight,p=a.fontStyle,x=i.fontSize,d=i.fontColor,g=void 0===d?o:d,y=i.fontFamily,S=void 0===y?l:y,m=i.fontWeight,w=void 0===m?f:m,T=i.fontStyle,E=void 0===T?p:T,C=x;s===t.spec.TextOverflow.display&&h>L&&(C/=h/L);var z=u[n]+v;c.font=E+" "+w+" "+C*r+"px "+S,c.fillStyle="rgba("+g[0]+", "+g[1]+", "+g[2]+", "+g[3]+")",e.chars[n].forEach((function(t){c.fillText(t.char,z+t.x,_)}))})),i<p.length-1&&(_+=b[i+1])}));var H=c.getImageData(0,0,this.canvas.width,this.canvas.height),F=t.Texture.createWithData(this.engine,{data:new Uint8Array(H.data),width:H.width,height:H.height},{flipY:e,magFilter:t.glContext.LINEAR,minFilter:t.glContext.LINEAR,wrapS:t.glContext.CLAMP_TO_EDGE,wrapT:t.glContext.CLAMP_TO_EDGE});this.renderer.texture=F,this.material.setTexture("_MainTex",F),this.isDirty=!1,c.restore()}else c.restore()}},n.setShadowOffsetY=function(t){throw new Error("Method not implemented.")},n.setShadowBlur=function(t){throw new Error("Method not implemented.")},n.setShadowOffsetX=function(t){throw new Error("Method not implemented.")},n.setShadowColor=function(t){throw new Error("Method not implemented.")},n.setOutlineWidth=function(t){throw new Error("Method not implemented.")},n.setAutoWidth=function(t){throw new Error("Method not implemented.")},n.updateWithOptions=function(e){this.textStyle=new t.TextStyle(e),this.textLayout=new t.TextLayout(e),this.textLayout.textBaseline=e.textBaseline||t.spec.TextBaseline.middle,this.text=e.text?e.text.toString():" "},n.renderText=function(e){var i=e.size;i&&(this.canvasSize=new t.math.Vector2(i[0],i[1])),this.updateTexture()},i}(t.TextComponent),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);var y="2.7.0";t.registerPlugin("rich-text",a,t.VFXItem),t.logger.info("Plugin rich text version: 2.7.0."),y!==i.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=a,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=x,exports.isRichText=function(t){var e=u(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(l)[1]:i.match(c)[1]}})))},exports.lexer=u,exports.richTextParser=p,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=y;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@galacean/effects/weapp");function e(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 i=e(t);function n(t,e){return n=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},n(t,e)}function r(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&&n(t,e)}var o,a=function(t){function e(){var e;return(e=t.apply(this,arguments)||this).name="rich-text",e}return r(e,t),e}(t.AbstractPlugin);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 h(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"}(o||(o={}));var l=/^<([a-z]+)(=([^>]+))?>$/,c=/^<\/([a-z]+)>$/,f=[["EscapedChar",/^\\([=<>\\/])/],["ContextStart",/^<[a-z]+(=[^>]+)?>/],["ContextEnd",/^<\/[a-z]+>/],["Text",/^[^</>=\\]+/]],u=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 u(t.slice(2),e.concat({tokenType:"Text",value:r}),i+2)}for(var o,a=h(f);!(o=a()).done;){var s=o.value,l=s[0],c=s[1];if("EscapedChar"!==l){var p=c.exec(t);if(p){var x=p[0],v=x.length;return u(t.slice(v),e.concat({tokenType:l,value:x}),i+v)}}}if(t.length>0)return u(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+'"')},p=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(l);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(c);if(e)return{attributeName:e[1]};throw new Error("Expect an end tag marker at position "+o)}return{}},r=u(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]},h=[];return function t(r,a){for(void 0===r&&(r=[]),void 0===a&&(a="");;){var s=e();if(s)h.push({attributes:r,text:s});else{var l=i(),c=l.attributeName,f=l.attributeParam;if(!c){if(a){var u=n().attributeName;if(!u)throw new Error('Expect an end tag marker "'+a+'" at position '+o+" but found no tag!");if(u!==a)throw new Error('Expect an end tag marker "'+a+'" at position '+o+' but found tag "'+u+'"');return}break}t(r.concat({attributeName:c,attributeParam:null!=f?f:""}),c)}}}(),h};function x(t){return function(e){for(var i,n=h(p(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 v(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 d(t,e){if(void 0===e&&(e=1),"string"!=typeof t||!t)throw new Error("Invalid color string");return t.startsWith("#")?v(t,e):v(function(t){if("string"!=typeof t||!t)throw new Error("Invalid color name provided");if("undefined"==typeof document)throw new 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{e.remove()}throw new Error("Failed to get 2D context for color conversion!")}(t))}"function"==typeof SuppressedError&&SuppressedError;var g=0;exports.RichTextComponent=function(e){function i(t){var i;return(i=e.call(this,t)||this).processedTextOptions=[],i.singleLineHeight=1.571,i.size=null,i.initialized=!1,i.canvasSize=null,i.name="MRichText"+g++,i}r(i,e);var n=i.prototype;return n.generateTextProgram=function(e){var i=this;this.processedTextOptions=[];var n=x((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=d(n.color)),i.processedTextOptions.push(o)}))}));n(e)},n.updateTexture=function(t){if(void 0===t&&(t=!0),this.isDirty&&this.context&&this.canvas){var e=!0===this.textLayout.useLegacyRichText;this.singleLineHeight=e?1.571:1,e?this.updateTextureLegacy(t):this.updateTextureModern(t)}},n.updateTextureLegacy=function(e){var i=this;if(this.isDirty&&this.context&&this.canvas){this.generateTextProgram(this.text);var n=this.textLayout,r=this.textStyle,o=n.overflow,a=n.letterSpace,s=void 0===a?0:a,h=this.context,l=0,c=0;h.save();var f=[],u=r.fontSize*this.textStyle.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,n=t.isNewLine,o=t.fontSize;n&&(f.push(p),l=Math.max(l,p.width),p={richOptions:[],offsetX:[],width:0,lineHeight:u*i.singleLineHeight,offsetY:u*(i.singleLineHeight-1)/2},c+=p.lineHeight),h.font=(t.fontWeight||r.textWeight)+" 10px "+(t.fontFamily||r.fontFamily);var a=h.measureText(e),x=a.width;if(void 0!==a.actualBoundingBoxLeft&&void 0!==a.actualBoundingBoxRight){var v=a.actualBoundingBoxLeft+a.actualBoundingBoxRight;v>0&&(x=Math.max(x,v))}var d=o*i.singleLineHeight*i.textStyle.fontScale;d>p.lineHeight&&(c+=d-p.lineHeight,p.lineHeight=d,p.offsetY=o*i.textStyle.fontScale*(i.singleLineHeight-1)/2),p.offsetX.push(p.width),p.width+=(x<=0?0:x)*o*i.SCALE_FACTOR*i.textStyle.fontScale+e.length*s,p.richOptions.push(t)})),f.push(p),l=Math.max(l,p.width),c+=p.lineHeight,0===l||0===c)return this.isDirty=!1,void h.restore();void 0!==this.size&&null!==this.size||(this.size=this.item.transform.size.clone());var x=this.size,v=x.x,d=void 0===v?1:v,g=x.y,y=void 0===g?1:g;if(!this.initialized){this.canvasSize=this.canvasSize?this.canvasSize:new t.math.Vector2(l,c);var S=this.canvasSize,m=S.x,w=S.y;this.item.transform.size.set(d*m*this.SCALE_FACTOR*this.SCALE_FACTOR,y*w*this.SCALE_FACTOR*this.SCALE_FACTOR),this.size=this.item.transform.size.clone(),this.initialized=!0}t.assertExist(this.canvasSize);var T=this.canvasSize,E=T.x,C=T.y;if(this.textLayout.width=E/r.fontScale,this.textLayout.height=C/r.fontScale,this.canvas.width=E,this.canvas.height=C,h.clearRect(0,0,E,C),h.fillStyle="rgba(255, 255, 255, "+this.ALPHA_FIX_VALUE+")",e||(h.translate(0,C),h.scale(1,-1)),0!==f.length){var L=n.getOffsetY(r,f.length,u*this.singleLineHeight,r.fontSize);f.forEach((function(e,n){var a=e.richOptions,s=e.offsetX,l=e.width,c=l,f=s;if(o===t.spec.TextOverflow.display&&l>E){var u=E/l;c*=u,f=s.map((function(t){return t*u}))}var p=i.textLayout.getOffsetX(r,c);n>0&&(L+=e.lineHeight-e.offsetY),a.forEach((function(e,i){var n=r.fontScale,a=r.textColor,s=r.fontFamily,c=r.textWeight,u=r.fontStyle,x=e.text,v=e.fontSize,d=e.fontColor,g=void 0===d?a:d,y=e.fontFamily,S=void 0===y?s:y,m=e.fontWeight,w=void 0===m?c:m,T=e.fontStyle,C=void 0===T?u:T,z=v;o===t.spec.TextOverflow.display&&l>E&&(z/=l/E);var O=f[i]+p;h.font=C+" "+w+" "+z*n+"px "+S,h.fillStyle="rgba("+g[0]+", "+g[1]+", "+g[2]+", "+g[3]+")",h.fillText(x,O,L)}))}));var z=h.getImageData(0,0,this.canvas.width,this.canvas.height),O=t.Texture.createWithData(this.engine,{data:new Uint8Array(z.data),width:z.width,height:z.height},{flipY:e,magFilter:t.glContext.LINEAR,minFilter:t.glContext.LINEAR,wrapS:t.glContext.CLAMP_TO_EDGE,wrapT:t.glContext.CLAMP_TO_EDGE});this.disposeTextTexture(),this.renderer.texture=O,this.material.setTexture("_MainTex",O),this.isDirty=!1,h.restore()}else h.restore()}},n.updateTextureModern=function(e){var i,n,r=this;this.generateTextProgram(this.text);var o=this.textLayout,a=this.textStyle,s=o.overflow,h=o.letterSpace,l=void 0===h?0:h,c=this.context,f=0,u=0;if(c){c.save();var p=[],x=a.fontSize*this.textStyle.fontScale,v={richOptions:[],offsetX:[],width:0,lineHeight:x*this.singleLineHeight+(this.textLayout.lineGap||0)*this.textStyle.fontScale,offsetY:(this.textLayout.lineGap||0)*this.textStyle.fontScale/2,chars:[]};if(this.processedTextOptions.forEach((function(t){var e=t.text,i=t.isNewLine,n=t.fontSize;i&&(u+=v.lineHeight,p.push(v),f=Math.max(f,v.width),v={richOptions:[],offsetX:[],width:0,lineHeight:x*r.singleLineHeight+(r.textLayout.lineGap||0)*r.textStyle.fontScale,offsetY:(r.textLayout.lineGap||0)*r.textStyle.fontScale/2,chars:[]}),c.font=(t.fontWeight||a.textWeight)+" 10px "+(t.fontFamily||a.fontFamily);var o=n*r.singleLineHeight*r.textStyle.fontScale+(r.textLayout.lineGap||0)*r.textStyle.fontScale;o>v.lineHeight&&(v.lineHeight=o,v.offsetY=(r.textLayout.lineGap||0)*r.textStyle.fontScale/2),v.offsetX.push(v.width);for(var s=0,h=[],d=0;d<e.length;d++){var g=e[d],y=c.measureText(g).width,S=(y<=0?0:y)*n*r.SCALE_FACTOR*r.textStyle.fontScale;h.push({char:g,x:s,width:S}),s+=S+l}v.chars.push(h),v.width+=s,v.richOptions.push(t)})),u+=v.lineHeight,p.push(v),0===(f=Math.max(f,v.width))||0===u)return this.isDirty=!1,void c.restore();void 0!==this.size&&null!==this.size||(this.size=this.item.transform.size.clone());var d=this.size,g=d.x,y=void 0===g?1:g,S=d.y,m=void 0===S?1:S;if(!this.initialized){this.canvasSize=this.canvasSize?this.canvasSize:new t.math.Vector2(f,u);var w=this.canvasSize,T=w.x,E=w.y;this.item.transform.size.set(y*T*this.SCALE_FACTOR*this.SCALE_FACTOR,m*E*this.SCALE_FACTOR*this.SCALE_FACTOR),this.size=this.item.transform.size.clone(),this.initialized=!0}t.assertExist(this.canvasSize);var C=this.canvasSize,L=C.x,z=C.y;if(this.textLayout.width=L/a.fontScale,this.textLayout.height=z/a.fontScale,this.canvas.width=L,this.canvas.height=z,c.clearRect(0,0,L,z),c.fillStyle="rgba(255, 255, 255, "+this.ALPHA_FIX_VALUE+")",e||(c.translate(0,z),c.scale(1,-1)),0!==p.length){var O,b=p.map((function(t){return t.lineHeight})),A=p[0],R=(i=Math).max.apply(i,[].concat(null!=(O=null==A||null==(n=A.richOptions)?void 0:n.map((function(t){return t.fontSize})))?O:[this.textStyle.fontSize]))*this.textStyle.fontScale*this.singleLineHeight,_=o.getOffsetYRich(this.textStyle,b,R);p.forEach((function(e,i){var n=e.richOptions,o=e.offsetX,h=e.width,l=e.chars,f=h,u=o;if(s===t.spec.TextOverflow.display&&h>L){var x=L/h;f*=x,u=o.map((function(t){return t*x})),l.forEach((function(t){t.forEach((function(t){t.x*=x,t.width*=x}))}))}var v=r.textLayout.getOffsetX(a,f);n.forEach((function(i,n){var r=a.fontScale,o=a.textColor,l=a.fontFamily,f=a.textWeight,p=a.fontStyle,x=i.fontSize,d=i.fontColor,g=void 0===d?o:d,y=i.fontFamily,S=void 0===y?l:y,m=i.fontWeight,w=void 0===m?f:m,T=i.fontStyle,E=void 0===T?p:T,C=x;s===t.spec.TextOverflow.display&&h>L&&(C/=h/L);var z=u[n]+v;c.font=E+" "+w+" "+C*r+"px "+S,c.fillStyle="rgba("+g[0]+", "+g[1]+", "+g[2]+", "+g[3]+")",e.chars[n].forEach((function(t){c.fillText(t.char,z+t.x,_)}))})),i<p.length-1&&(_+=b[i+1])}));var H=c.getImageData(0,0,this.canvas.width,this.canvas.height),F=t.Texture.createWithData(this.engine,{data:new Uint8Array(H.data),width:H.width,height:H.height},{flipY:e,magFilter:t.glContext.LINEAR,minFilter:t.glContext.LINEAR,wrapS:t.glContext.CLAMP_TO_EDGE,wrapT:t.glContext.CLAMP_TO_EDGE});this.renderer.texture=F,this.material.setTexture("_MainTex",F),this.isDirty=!1,c.restore()}else c.restore()}},n.setShadowOffsetY=function(t){throw new Error("Method not implemented.")},n.setShadowBlur=function(t){throw new Error("Method not implemented.")},n.setShadowOffsetX=function(t){throw new Error("Method not implemented.")},n.setShadowColor=function(t){throw new Error("Method not implemented.")},n.setOutlineWidth=function(t){throw new Error("Method not implemented.")},n.setAutoWidth=function(t){throw new Error("Method not implemented.")},n.updateWithOptions=function(e){this.textStyle=new t.TextStyle(e),this.textLayout=new t.TextLayout(e),this.textLayout.textBaseline=e.textBaseline||t.spec.TextBaseline.middle,this.text=e.text?e.text.toString():" "},n.renderText=function(e){var i=e.size;i&&(this.canvasSize=new t.math.Vector2(i[0],i[1])),this.updateTexture()},i}(t.TextComponent),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);var y="2.7.2";t.registerPlugin("rich-text",a,t.VFXItem),t.logger.info("Plugin rich text version: 2.7.2."),y!==i.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=a,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=x,exports.isRichText=function(t){var e=u(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(l)[1]:i.match(c)[1]}})))},exports.lexer=u,exports.richTextParser=p,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=y;
|
|
2
2
|
//# sourceMappingURL=weapp.js.map
|
package/dist/weapp.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import*as t from"@galacean/effects/weapp";import{AbstractPlugin as e,effectsClass as i,spec as n,math as r,assertExist as o,Texture as a,glContext as s,TextStyle as h,TextLayout as l,TextComponent as f,registerPlugin as c,VFXItem as u,logger as p}from"@galacean/effects/weapp";function v(t,e){return v=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},v(t,e)}function d(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&&v(t,e)}var x,g=function(t){function e(){var e;return(e=t.apply(this,arguments)||this).name="rich-text",e}return d(e,t),e}(e);function y(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 S(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 y(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)?y(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"}(x||(x={}));var m=/^<([a-z]+)(=([^>]+))?>$/,w=/^<\/([a-z]+)>$/,T=[["EscapedChar",/^\\([=<>\\/])/],["ContextStart",/^<[a-z]+(=[^>]+)?>/],["ContextEnd",/^<\/[a-z]+>/],["Text",/^[^</>=\\]+/]],E=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 E(t.slice(2),e.concat({tokenType:"Text",value:r}),i+2)}for(var o,a=S(T);!(o=a()).done;){var s=o.value,h=s[0],l=s[1];if("EscapedChar"!==h){var f=l.exec(t);if(f){var c=f[0],u=c.length;return E(t.slice(u),e.concat({tokenType:h,value:c}),i+u)}}}if(t.length>0)return E(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+'"')},L=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(m);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(w);if(e)return{attributeName:e[1]};throw new Error("Expect an end tag marker at position "+o)}return{}},r=E(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]},h=[];return function t(r,a){for(void 0===r&&(r=[]),void 0===a&&(a="");;){var s=e();if(s)h.push({attributes:r,text:s});else{var l=i(),f=l.attributeName,c=l.attributeParam;if(!f){if(a){var u=n().attributeName;if(!u)throw new Error('Expect an end tag marker "'+a+'" at position '+o+" but found no tag!");if(u!==a)throw new Error('Expect an end tag marker "'+a+'" at position '+o+' but found tag "'+u+'"');return}break}t(r.concat({attributeName:f,attributeParam:null!=c?c:""}),f)}}}(),h};function z(t){return function(e){for(var i,n=S(L(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 C(t){var e=E(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(m)[1]:i.match(w)[1]}})))}function O(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 b(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 A(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 H(t,e){if(void 0===e&&(e=1),"string"!=typeof t||!t)throw new Error("Invalid color string");return t.startsWith("#")?A(t,e):A(function(t){if("string"!=typeof t||!t)throw new Error("Invalid color name provided");if("undefined"==typeof document)throw new 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{e.remove()}throw new Error("Failed to get 2D context for color conversion!")}(t))}"function"==typeof SuppressedError&&SuppressedError;var _=0,R=function(t){function e(e){var i;return(i=t.call(this,e)||this).processedTextOptions=[],i.singleLineHeight=1.571,i.size=null,i.initialized=!1,i.canvasSize=null,i.name="MRichText"+_++,i}d(e,t);var i=e.prototype;return i.generateTextProgram=function(t){var e=this;this.processedTextOptions=[];var i=z((function(t,i){/^\n+$/.test(t)&&(t=t.replace(/\n/g,"\n ")),t.split("\n").forEach((function(t,r){var o={text:t,fontSize:e.textStyle.fontSize,isNewLine:!1};r>0&&(o.isNewLine=!0),"b"in i&&(o.fontWeight=n.TextWeight.bold),"i"in i&&(o.fontStyle=n.FontStyle.italic),"size"in i&&i.size&&(o.fontSize=parseInt(i.size,10)),"color"in i&&i.color&&(o.fontColor=H(i.color)),e.processedTextOptions.push(o)}))}));i(t)},i.updateTexture=function(t){if(void 0===t&&(t=!0),this.isDirty&&this.context&&this.canvas){var e=!0===this.textLayout.useLegacyRichText;this.singleLineHeight=e?1.571:1,e?this.updateTextureLegacy(t):this.updateTextureModern(t)}},i.updateTextureLegacy=function(t){var e=this;if(this.isDirty&&this.context&&this.canvas){this.generateTextProgram(this.text);var i=this.textLayout,h=this.textStyle,l=i.overflow,f=i.letterSpace,c=void 0===f?0:f,u=this.context,p=0,v=0;u.save();var d=[],x=h.fontSize*this.textStyle.fontScale,g={richOptions:[],offsetX:[],width:0,lineHeight:x*this.singleLineHeight,offsetY:x*(this.singleLineHeight-1)/2};if(this.processedTextOptions.forEach((function(t){var i=t.text,n=t.isNewLine,r=t.fontSize;n&&(d.push(g),p=Math.max(p,g.width),g={richOptions:[],offsetX:[],width:0,lineHeight:x*e.singleLineHeight,offsetY:x*(e.singleLineHeight-1)/2},v+=g.lineHeight),u.font=(t.fontWeight||h.textWeight)+" 10px "+(t.fontFamily||h.fontFamily);var o=u.measureText(i),a=o.width;if(void 0!==o.actualBoundingBoxLeft&&void 0!==o.actualBoundingBoxRight){var s=o.actualBoundingBoxLeft+o.actualBoundingBoxRight;s>0&&(a=Math.max(a,s))}var l=r*e.singleLineHeight*e.textStyle.fontScale;l>g.lineHeight&&(v+=l-g.lineHeight,g.lineHeight=l,g.offsetY=r*e.textStyle.fontScale*(e.singleLineHeight-1)/2),g.offsetX.push(g.width),g.width+=(a<=0?0:a)*r*e.SCALE_FACTOR*e.textStyle.fontScale+i.length*c,g.richOptions.push(t)})),d.push(g),p=Math.max(p,g.width),v+=g.lineHeight,0===p||0===v)return this.isDirty=!1,void u.restore();void 0!==this.size&&null!==this.size||(this.size=this.item.transform.size.clone());var y=this.size,S=y.x,m=void 0===S?1:S,w=y.y,T=void 0===w?1:w;if(!this.initialized){this.canvasSize=this.canvasSize?this.canvasSize:new r.Vector2(p,v);var E=this.canvasSize,L=E.x,z=E.y;this.item.transform.size.set(m*L*this.SCALE_FACTOR*this.SCALE_FACTOR,T*z*this.SCALE_FACTOR*this.SCALE_FACTOR),this.size=this.item.transform.size.clone(),this.initialized=!0}o(this.canvasSize);var C=this.canvasSize,O=C.x,b=C.y;if(this.textLayout.width=O/h.fontScale,this.textLayout.height=b/h.fontScale,this.canvas.width=O,this.canvas.height=b,u.clearRect(0,0,O,b),u.fillStyle="rgba(255, 255, 255, "+this.ALPHA_FIX_VALUE+")",t||(u.translate(0,b),u.scale(1,-1)),0!==d.length){var A=i.getOffsetY(h,d.length,x*this.singleLineHeight,h.fontSize);d.forEach((function(t,i){var r=t.richOptions,o=t.offsetX,a=t.width,s=a,f=o;if(l===n.TextOverflow.display&&a>O){var c=O/a;s*=c,f=o.map((function(t){return t*c}))}var p=e.textLayout.getOffsetX(h,s);i>0&&(A+=t.lineHeight-t.offsetY),r.forEach((function(t,e){var i=h.fontScale,r=h.textColor,o=h.fontFamily,s=h.textWeight,c=h.fontStyle,v=t.text,d=t.fontSize,x=t.fontColor,g=void 0===x?r:x,y=t.fontFamily,S=void 0===y?o:y,m=t.fontWeight,w=void 0===m?s:m,T=t.fontStyle,E=void 0===T?c:T,L=d;l===n.TextOverflow.display&&a>O&&(L/=a/O);var z=f[e]+p;u.font=E+" "+w+" "+L*i+"px "+S,u.fillStyle="rgba("+g[0]+", "+g[1]+", "+g[2]+", "+g[3]+")",u.fillText(v,z,A)}))}));var H=u.getImageData(0,0,this.canvas.width,this.canvas.height),_=a.createWithData(this.engine,{data:new Uint8Array(H.data),width:H.width,height:H.height},{flipY:t,magFilter:s.LINEAR,minFilter:s.LINEAR,wrapS:s.CLAMP_TO_EDGE,wrapT:s.CLAMP_TO_EDGE});this.disposeTextTexture(),this.renderer.texture=_,this.material.setTexture("_MainTex",_),this.isDirty=!1,u.restore()}else u.restore()}},i.updateTextureModern=function(t){var e,i,h=this;this.generateTextProgram(this.text);var l=this.textLayout,f=this.textStyle,c=l.overflow,u=l.letterSpace,p=void 0===u?0:u,v=this.context,d=0,x=0;if(v){v.save();var g=[],y=f.fontSize*this.textStyle.fontScale,S={richOptions:[],offsetX:[],width:0,lineHeight:y*this.singleLineHeight+(this.textLayout.lineGap||0)*this.textStyle.fontScale,offsetY:(this.textLayout.lineGap||0)*this.textStyle.fontScale/2,chars:[]};if(this.processedTextOptions.forEach((function(t){var e=t.text,i=t.isNewLine,n=t.fontSize;i&&(x+=S.lineHeight,g.push(S),d=Math.max(d,S.width),S={richOptions:[],offsetX:[],width:0,lineHeight:y*h.singleLineHeight+(h.textLayout.lineGap||0)*h.textStyle.fontScale,offsetY:(h.textLayout.lineGap||0)*h.textStyle.fontScale/2,chars:[]}),v.font=(t.fontWeight||f.textWeight)+" 10px "+(t.fontFamily||f.fontFamily);var r=n*h.singleLineHeight*h.textStyle.fontScale+(h.textLayout.lineGap||0)*h.textStyle.fontScale;r>S.lineHeight&&(S.lineHeight=r,S.offsetY=(h.textLayout.lineGap||0)*h.textStyle.fontScale/2),S.offsetX.push(S.width);for(var o=0,a=[],s=0;s<e.length;s++){var l=e[s],c=v.measureText(l).width,u=(c<=0?0:c)*n*h.SCALE_FACTOR*h.textStyle.fontScale;a.push({char:l,x:o,width:u}),o+=u+p}S.chars.push(a),S.width+=o,S.richOptions.push(t)})),x+=S.lineHeight,g.push(S),0===(d=Math.max(d,S.width))||0===x)return this.isDirty=!1,void v.restore();void 0!==this.size&&null!==this.size||(this.size=this.item.transform.size.clone());var m=this.size,w=m.x,T=void 0===w?1:w,E=m.y,L=void 0===E?1:E;if(!this.initialized){this.canvasSize=this.canvasSize?this.canvasSize:new r.Vector2(d,x);var z=this.canvasSize,C=z.x,O=z.y;this.item.transform.size.set(T*C*this.SCALE_FACTOR*this.SCALE_FACTOR,L*O*this.SCALE_FACTOR*this.SCALE_FACTOR),this.size=this.item.transform.size.clone(),this.initialized=!0}o(this.canvasSize);var b=this.canvasSize,A=b.x,H=b.y;if(this.textLayout.width=A/f.fontScale,this.textLayout.height=H/f.fontScale,this.canvas.width=A,this.canvas.height=H,v.clearRect(0,0,A,H),v.fillStyle="rgba(255, 255, 255, "+this.ALPHA_FIX_VALUE+")",t||(v.translate(0,H),v.scale(1,-1)),0!==g.length){var _,R=g.map((function(t){return t.lineHeight})),F=g[0],M=(e=Math).max.apply(e,[].concat(null!=(_=null==F||null==(i=F.richOptions)?void 0:i.map((function(t){return t.fontSize})))?_:[this.textStyle.fontSize]))*this.textStyle.fontScale*this.singleLineHeight,k=l.getOffsetYRich(this.textStyle,R,M);g.forEach((function(t,e){var i=t.richOptions,r=t.offsetX,o=t.width,a=t.chars,s=o,l=r;if(c===n.TextOverflow.display&&o>A){var u=A/o;s*=u,l=r.map((function(t){return t*u})),a.forEach((function(t){t.forEach((function(t){t.x*=u,t.width*=u}))}))}var p=h.textLayout.getOffsetX(f,s);i.forEach((function(e,i){var r=f.fontScale,a=f.textColor,s=f.fontFamily,h=f.textWeight,u=f.fontStyle,d=e.fontSize,x=e.fontColor,g=void 0===x?a:x,y=e.fontFamily,S=void 0===y?s:y,m=e.fontWeight,w=void 0===m?h:m,T=e.fontStyle,E=void 0===T?u:T,L=d;c===n.TextOverflow.display&&o>A&&(L/=o/A);var z=l[i]+p;v.font=E+" "+w+" "+L*r+"px "+S,v.fillStyle="rgba("+g[0]+", "+g[1]+", "+g[2]+", "+g[3]+")",t.chars[i].forEach((function(t){v.fillText(t.char,z+t.x,k)}))})),e<g.length-1&&(k+=R[e+1])}));var P=v.getImageData(0,0,this.canvas.width,this.canvas.height),I=a.createWithData(this.engine,{data:new Uint8Array(P.data),width:P.width,height:P.height},{flipY:t,magFilter:s.LINEAR,minFilter:s.LINEAR,wrapS:s.CLAMP_TO_EDGE,wrapT:s.CLAMP_TO_EDGE});this.renderer.texture=I,this.material.setTexture("_MainTex",I),this.isDirty=!1,v.restore()}else v.restore()}},i.setShadowOffsetY=function(t){throw new Error("Method not implemented.")},i.setShadowBlur=function(t){throw new Error("Method not implemented.")},i.setShadowOffsetX=function(t){throw new Error("Method not implemented.")},i.setShadowColor=function(t){throw new Error("Method not implemented.")},i.setOutlineWidth=function(t){throw new Error("Method not implemented.")},i.setAutoWidth=function(t){throw new Error("Method not implemented.")},i.updateWithOptions=function(t){this.textStyle=new h(t),this.textLayout=new l(t),this.textLayout.textBaseline=t.textBaseline||n.TextBaseline.middle,this.text=t.text?t.text.toString():" "},i.renderText=function(t){var e=t.size;e&&(this.canvasSize=new r.Vector2(e[0],e[1])),this.updateTexture()},e}(f);R=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}([i(n.DataType.RichTextComponent)],R);var F="2.7.0";c("rich-text",g,u),p.info("Plugin rich text version: 2.7.0."),F!==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{R as RichTextComponent,g as RichTextLoader,O as escape,z as generateProgram,C as isRichText,E as lexer,L as richTextParser,b as unescape,F as version};
|
|
1
|
+
import*as t from"@galacean/effects/weapp";import{AbstractPlugin as e,effectsClass as i,spec as n,math as r,assertExist as o,Texture as a,glContext as s,TextStyle as h,TextLayout as l,TextComponent as f,registerPlugin as c,VFXItem as u,logger as p}from"@galacean/effects/weapp";function v(t,e){return v=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},v(t,e)}function d(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&&v(t,e)}var x,g=function(t){function e(){var e;return(e=t.apply(this,arguments)||this).name="rich-text",e}return d(e,t),e}(e);function y(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 S(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 y(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)?y(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"}(x||(x={}));var m=/^<([a-z]+)(=([^>]+))?>$/,w=/^<\/([a-z]+)>$/,T=[["EscapedChar",/^\\([=<>\\/])/],["ContextStart",/^<[a-z]+(=[^>]+)?>/],["ContextEnd",/^<\/[a-z]+>/],["Text",/^[^</>=\\]+/]],E=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 E(t.slice(2),e.concat({tokenType:"Text",value:r}),i+2)}for(var o,a=S(T);!(o=a()).done;){var s=o.value,h=s[0],l=s[1];if("EscapedChar"!==h){var f=l.exec(t);if(f){var c=f[0],u=c.length;return E(t.slice(u),e.concat({tokenType:h,value:c}),i+u)}}}if(t.length>0)return E(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+'"')},L=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(m);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(w);if(e)return{attributeName:e[1]};throw new Error("Expect an end tag marker at position "+o)}return{}},r=E(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]},h=[];return function t(r,a){for(void 0===r&&(r=[]),void 0===a&&(a="");;){var s=e();if(s)h.push({attributes:r,text:s});else{var l=i(),f=l.attributeName,c=l.attributeParam;if(!f){if(a){var u=n().attributeName;if(!u)throw new Error('Expect an end tag marker "'+a+'" at position '+o+" but found no tag!");if(u!==a)throw new Error('Expect an end tag marker "'+a+'" at position '+o+' but found tag "'+u+'"');return}break}t(r.concat({attributeName:f,attributeParam:null!=c?c:""}),f)}}}(),h};function z(t){return function(e){for(var i,n=S(L(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 C(t){var e=E(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(m)[1]:i.match(w)[1]}})))}function O(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 b(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 A(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 H(t,e){if(void 0===e&&(e=1),"string"!=typeof t||!t)throw new Error("Invalid color string");return t.startsWith("#")?A(t,e):A(function(t){if("string"!=typeof t||!t)throw new Error("Invalid color name provided");if("undefined"==typeof document)throw new 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{e.remove()}throw new Error("Failed to get 2D context for color conversion!")}(t))}"function"==typeof SuppressedError&&SuppressedError;var _=0,R=function(t){function e(e){var i;return(i=t.call(this,e)||this).processedTextOptions=[],i.singleLineHeight=1.571,i.size=null,i.initialized=!1,i.canvasSize=null,i.name="MRichText"+_++,i}d(e,t);var i=e.prototype;return i.generateTextProgram=function(t){var e=this;this.processedTextOptions=[];var i=z((function(t,i){/^\n+$/.test(t)&&(t=t.replace(/\n/g,"\n ")),t.split("\n").forEach((function(t,r){var o={text:t,fontSize:e.textStyle.fontSize,isNewLine:!1};r>0&&(o.isNewLine=!0),"b"in i&&(o.fontWeight=n.TextWeight.bold),"i"in i&&(o.fontStyle=n.FontStyle.italic),"size"in i&&i.size&&(o.fontSize=parseInt(i.size,10)),"color"in i&&i.color&&(o.fontColor=H(i.color)),e.processedTextOptions.push(o)}))}));i(t)},i.updateTexture=function(t){if(void 0===t&&(t=!0),this.isDirty&&this.context&&this.canvas){var e=!0===this.textLayout.useLegacyRichText;this.singleLineHeight=e?1.571:1,e?this.updateTextureLegacy(t):this.updateTextureModern(t)}},i.updateTextureLegacy=function(t){var e=this;if(this.isDirty&&this.context&&this.canvas){this.generateTextProgram(this.text);var i=this.textLayout,h=this.textStyle,l=i.overflow,f=i.letterSpace,c=void 0===f?0:f,u=this.context,p=0,v=0;u.save();var d=[],x=h.fontSize*this.textStyle.fontScale,g={richOptions:[],offsetX:[],width:0,lineHeight:x*this.singleLineHeight,offsetY:x*(this.singleLineHeight-1)/2};if(this.processedTextOptions.forEach((function(t){var i=t.text,n=t.isNewLine,r=t.fontSize;n&&(d.push(g),p=Math.max(p,g.width),g={richOptions:[],offsetX:[],width:0,lineHeight:x*e.singleLineHeight,offsetY:x*(e.singleLineHeight-1)/2},v+=g.lineHeight),u.font=(t.fontWeight||h.textWeight)+" 10px "+(t.fontFamily||h.fontFamily);var o=u.measureText(i),a=o.width;if(void 0!==o.actualBoundingBoxLeft&&void 0!==o.actualBoundingBoxRight){var s=o.actualBoundingBoxLeft+o.actualBoundingBoxRight;s>0&&(a=Math.max(a,s))}var l=r*e.singleLineHeight*e.textStyle.fontScale;l>g.lineHeight&&(v+=l-g.lineHeight,g.lineHeight=l,g.offsetY=r*e.textStyle.fontScale*(e.singleLineHeight-1)/2),g.offsetX.push(g.width),g.width+=(a<=0?0:a)*r*e.SCALE_FACTOR*e.textStyle.fontScale+i.length*c,g.richOptions.push(t)})),d.push(g),p=Math.max(p,g.width),v+=g.lineHeight,0===p||0===v)return this.isDirty=!1,void u.restore();void 0!==this.size&&null!==this.size||(this.size=this.item.transform.size.clone());var y=this.size,S=y.x,m=void 0===S?1:S,w=y.y,T=void 0===w?1:w;if(!this.initialized){this.canvasSize=this.canvasSize?this.canvasSize:new r.Vector2(p,v);var E=this.canvasSize,L=E.x,z=E.y;this.item.transform.size.set(m*L*this.SCALE_FACTOR*this.SCALE_FACTOR,T*z*this.SCALE_FACTOR*this.SCALE_FACTOR),this.size=this.item.transform.size.clone(),this.initialized=!0}o(this.canvasSize);var C=this.canvasSize,O=C.x,b=C.y;if(this.textLayout.width=O/h.fontScale,this.textLayout.height=b/h.fontScale,this.canvas.width=O,this.canvas.height=b,u.clearRect(0,0,O,b),u.fillStyle="rgba(255, 255, 255, "+this.ALPHA_FIX_VALUE+")",t||(u.translate(0,b),u.scale(1,-1)),0!==d.length){var A=i.getOffsetY(h,d.length,x*this.singleLineHeight,h.fontSize);d.forEach((function(t,i){var r=t.richOptions,o=t.offsetX,a=t.width,s=a,f=o;if(l===n.TextOverflow.display&&a>O){var c=O/a;s*=c,f=o.map((function(t){return t*c}))}var p=e.textLayout.getOffsetX(h,s);i>0&&(A+=t.lineHeight-t.offsetY),r.forEach((function(t,e){var i=h.fontScale,r=h.textColor,o=h.fontFamily,s=h.textWeight,c=h.fontStyle,v=t.text,d=t.fontSize,x=t.fontColor,g=void 0===x?r:x,y=t.fontFamily,S=void 0===y?o:y,m=t.fontWeight,w=void 0===m?s:m,T=t.fontStyle,E=void 0===T?c:T,L=d;l===n.TextOverflow.display&&a>O&&(L/=a/O);var z=f[e]+p;u.font=E+" "+w+" "+L*i+"px "+S,u.fillStyle="rgba("+g[0]+", "+g[1]+", "+g[2]+", "+g[3]+")",u.fillText(v,z,A)}))}));var H=u.getImageData(0,0,this.canvas.width,this.canvas.height),_=a.createWithData(this.engine,{data:new Uint8Array(H.data),width:H.width,height:H.height},{flipY:t,magFilter:s.LINEAR,minFilter:s.LINEAR,wrapS:s.CLAMP_TO_EDGE,wrapT:s.CLAMP_TO_EDGE});this.disposeTextTexture(),this.renderer.texture=_,this.material.setTexture("_MainTex",_),this.isDirty=!1,u.restore()}else u.restore()}},i.updateTextureModern=function(t){var e,i,h=this;this.generateTextProgram(this.text);var l=this.textLayout,f=this.textStyle,c=l.overflow,u=l.letterSpace,p=void 0===u?0:u,v=this.context,d=0,x=0;if(v){v.save();var g=[],y=f.fontSize*this.textStyle.fontScale,S={richOptions:[],offsetX:[],width:0,lineHeight:y*this.singleLineHeight+(this.textLayout.lineGap||0)*this.textStyle.fontScale,offsetY:(this.textLayout.lineGap||0)*this.textStyle.fontScale/2,chars:[]};if(this.processedTextOptions.forEach((function(t){var e=t.text,i=t.isNewLine,n=t.fontSize;i&&(x+=S.lineHeight,g.push(S),d=Math.max(d,S.width),S={richOptions:[],offsetX:[],width:0,lineHeight:y*h.singleLineHeight+(h.textLayout.lineGap||0)*h.textStyle.fontScale,offsetY:(h.textLayout.lineGap||0)*h.textStyle.fontScale/2,chars:[]}),v.font=(t.fontWeight||f.textWeight)+" 10px "+(t.fontFamily||f.fontFamily);var r=n*h.singleLineHeight*h.textStyle.fontScale+(h.textLayout.lineGap||0)*h.textStyle.fontScale;r>S.lineHeight&&(S.lineHeight=r,S.offsetY=(h.textLayout.lineGap||0)*h.textStyle.fontScale/2),S.offsetX.push(S.width);for(var o=0,a=[],s=0;s<e.length;s++){var l=e[s],c=v.measureText(l).width,u=(c<=0?0:c)*n*h.SCALE_FACTOR*h.textStyle.fontScale;a.push({char:l,x:o,width:u}),o+=u+p}S.chars.push(a),S.width+=o,S.richOptions.push(t)})),x+=S.lineHeight,g.push(S),0===(d=Math.max(d,S.width))||0===x)return this.isDirty=!1,void v.restore();void 0!==this.size&&null!==this.size||(this.size=this.item.transform.size.clone());var m=this.size,w=m.x,T=void 0===w?1:w,E=m.y,L=void 0===E?1:E;if(!this.initialized){this.canvasSize=this.canvasSize?this.canvasSize:new r.Vector2(d,x);var z=this.canvasSize,C=z.x,O=z.y;this.item.transform.size.set(T*C*this.SCALE_FACTOR*this.SCALE_FACTOR,L*O*this.SCALE_FACTOR*this.SCALE_FACTOR),this.size=this.item.transform.size.clone(),this.initialized=!0}o(this.canvasSize);var b=this.canvasSize,A=b.x,H=b.y;if(this.textLayout.width=A/f.fontScale,this.textLayout.height=H/f.fontScale,this.canvas.width=A,this.canvas.height=H,v.clearRect(0,0,A,H),v.fillStyle="rgba(255, 255, 255, "+this.ALPHA_FIX_VALUE+")",t||(v.translate(0,H),v.scale(1,-1)),0!==g.length){var _,R=g.map((function(t){return t.lineHeight})),F=g[0],M=(e=Math).max.apply(e,[].concat(null!=(_=null==F||null==(i=F.richOptions)?void 0:i.map((function(t){return t.fontSize})))?_:[this.textStyle.fontSize]))*this.textStyle.fontScale*this.singleLineHeight,k=l.getOffsetYRich(this.textStyle,R,M);g.forEach((function(t,e){var i=t.richOptions,r=t.offsetX,o=t.width,a=t.chars,s=o,l=r;if(c===n.TextOverflow.display&&o>A){var u=A/o;s*=u,l=r.map((function(t){return t*u})),a.forEach((function(t){t.forEach((function(t){t.x*=u,t.width*=u}))}))}var p=h.textLayout.getOffsetX(f,s);i.forEach((function(e,i){var r=f.fontScale,a=f.textColor,s=f.fontFamily,h=f.textWeight,u=f.fontStyle,d=e.fontSize,x=e.fontColor,g=void 0===x?a:x,y=e.fontFamily,S=void 0===y?s:y,m=e.fontWeight,w=void 0===m?h:m,T=e.fontStyle,E=void 0===T?u:T,L=d;c===n.TextOverflow.display&&o>A&&(L/=o/A);var z=l[i]+p;v.font=E+" "+w+" "+L*r+"px "+S,v.fillStyle="rgba("+g[0]+", "+g[1]+", "+g[2]+", "+g[3]+")",t.chars[i].forEach((function(t){v.fillText(t.char,z+t.x,k)}))})),e<g.length-1&&(k+=R[e+1])}));var P=v.getImageData(0,0,this.canvas.width,this.canvas.height),I=a.createWithData(this.engine,{data:new Uint8Array(P.data),width:P.width,height:P.height},{flipY:t,magFilter:s.LINEAR,minFilter:s.LINEAR,wrapS:s.CLAMP_TO_EDGE,wrapT:s.CLAMP_TO_EDGE});this.renderer.texture=I,this.material.setTexture("_MainTex",I),this.isDirty=!1,v.restore()}else v.restore()}},i.setShadowOffsetY=function(t){throw new Error("Method not implemented.")},i.setShadowBlur=function(t){throw new Error("Method not implemented.")},i.setShadowOffsetX=function(t){throw new Error("Method not implemented.")},i.setShadowColor=function(t){throw new Error("Method not implemented.")},i.setOutlineWidth=function(t){throw new Error("Method not implemented.")},i.setAutoWidth=function(t){throw new Error("Method not implemented.")},i.updateWithOptions=function(t){this.textStyle=new h(t),this.textLayout=new l(t),this.textLayout.textBaseline=t.textBaseline||n.TextBaseline.middle,this.text=t.text?t.text.toString():" "},i.renderText=function(t){var e=t.size;e&&(this.canvasSize=new r.Vector2(e[0],e[1])),this.updateTexture()},e}(f);R=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}([i(n.DataType.RichTextComponent)],R);var F="2.7.2";c("rich-text",g,u),p.info("Plugin rich text version: 2.7.2."),F!==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{R as RichTextComponent,g as RichTextLoader,O as escape,z as generateProgram,C as isRichText,E as lexer,L as richTextParser,b as unescape,F 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.7.
|
|
3
|
+
"version": "2.7.2",
|
|
4
4
|
"description": "Galacean Effects player rich text plugin",
|
|
5
5
|
"module": "./dist/index.mjs",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"registry": "https://registry.npmjs.org"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@galacean/effects": "2.7.
|
|
46
|
+
"@galacean/effects": "2.7.2"
|
|
47
47
|
},
|
|
48
48
|
"scripts": {
|
|
49
49
|
"dev": "vite",
|