@galacean/effects-plugin-rich-text 2.5.5 → 2.5.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/alipay.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@galacean/effects/alipay");function e(t){if(t&&t.__esModule)return t;var e=Object.create(null);return t&&Object.keys(t).forEach((function(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,r.get?r:{enumerable:!0,get:function(){return t[n]}})}})),e.default=t,Object.freeze(e)}var n=e(t);function r(t,e){return r=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},r(t,e)}function i(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&r(t,e)}var o,a=function(t){function e(){var e;return(e=t.apply(this,arguments)||this).name="rich-text",e}return i(e,t),e}(t.AbstractPlugin);function s(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function l(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(n)return(n=n.call(t)).next.bind(n);if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return s(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(n):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?s(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var r=0;return function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}}}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"}(o||(o={}));var c=/^<([a-z]+)(=([^>]+))?>$/,u=/^<\/([a-z]+)>$/,h=[["ContextStart",/^<[a-z]+(=[^>]+)?>/],["Text",/^[^</>=]+/],["ContextEnd",/^<\/[a-z]+>/]],f=function(t,e,n){if(void 0===e&&(e=[]),void 0===n&&(n=0),!t)return e;for(var r,i=l(h);!(r=i()).done;){var o,a=r.value,s=a[0],c=(null!=(o=a[1].exec(t))?o:[])[0];if(c){var u=c.length;return f(t.slice(u),e.concat({tokenType:s,value:c}),n+u)}}throw new Error('Unexpected token: "'+t[0]+'" at position '+n+' while reading "'+t+'"')},p=function(t){var e=function(){var t=s();if("Text"===(null==t?void 0:t.tokenType))return a(),t.value},n=function(){var t=s();if("ContextStart"===(null==t?void 0:t.tokenType)){a();var e,n=t.value.match(c);if(n)return{attributeName:n[1],attributeParam:null!=(e=n[3])?e:""};throw new Error("Expected a start tag marker at position "+o)}return{}},r=function(){var t=s();if("ContextEnd"===(null==t?void 0:t.tokenType)){a();var e=t.value.match(u);if(e)return{attributeName:e[1]};throw new Error("Expect an end tag marker at position "+o)}return{}},i=f(t),o=0,a=function(){var t,e=i.shift();return o+=null!=(t=null==e?void 0:e.value.length)?t:0,e},s=function(){return i[0]},l=[];return function t(i,a){for(void 0===i&&(i=[]),void 0===a&&(a="");;){var s=e();if(s)l.push({attributes:i,text:s});else{var c=n(),u=c.attributeName,h=c.attributeParam;if(!u){if(a){var f=r().attributeName;if(!f)throw new Error('Expect an end tag marker "'+a+'" at position '+o+" but found no tag!");if(f!==a)throw new Error('Expect an end tag marker "'+a+'" at position '+o+' but found tag "'+f+'"');return}break}t(i.concat({attributeName:u,attributeParam:h}),u)}}}(),l};function d(t){return function(e){for(var n,r=l(p(e));!(n=r()).done;){var i=n.value,o=i.text,a=i.attributes.reduce((function(t,e){var n=e.attributeName,r=e.attributeParam;return n&&(t[n]=r),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 n=parseInt(t.slice(6,8),16)/255;t=t.slice(0,6),e=n}var r=parseInt(t,16);return[r>>16&255,r>>8&255,255&r,e]}function x(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"),n=e.getContext("2d");if(n)try{return n.fillStyle=t,n.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 n(t){var n;return(n=e.call(this,t)||this).processedTextOptions=[],n.singleLineHeight=1.571,n.size=null,n.initialized=!1,n.canvasSize=null,n.name="MRichText"+g++,n}i(n,e);var r=n.prototype;return r.generateTextProgram=function(e){var n=this;this.processedTextOptions=[];var r=d((function(e,r){/^\n+$/.test(e)&&(e=e.replace(/\n/g,"\n ")),e.split("\n").forEach((function(e,i){var o={text:e,fontSize:n.textStyle.fontSize,isNewLine:!1};i>0&&(o.isNewLine=!0),"b"in r&&(o.fontWeight=t.spec.TextWeight.bold),"i"in r&&(o.fontStyle=t.spec.FontStyle.italic),"size"in r&&r.size&&(o.fontSize=parseInt(r.size,10)),"color"in r&&r.color&&(o.fontColor=x(r.color)),n.processedTextOptions.push(o)}))}));r(e)},r.updateTexture=function(e){var n=this;if(void 0===e&&(e=!0),this.isDirty&&this.context&&this.canvas){this.generateTextProgram(this.text);var r=0,i=0,o=this.textLayout,a=this.textStyle,s=o.overflow,l=o.letterSpace,c=void 0===l?0:l,u=this.context;u.save();var h=[],f=a.fontSize*this.textStyle.fontScale,p={richOptions:[],offsetX:[],width:0,lineHeight:f*this.singleLineHeight,offsetY:f*(this.singleLineHeight-1)/2};if(this.processedTextOptions.forEach((function(t){var e=t.text,o=t.isNewLine,s=t.fontSize;o&&(h.push(p),r=Math.max(r,p.width),p={richOptions:[],offsetX:[],width:0,lineHeight:f*n.singleLineHeight,offsetY:f*(n.singleLineHeight-1)/2},i+=p.lineHeight),u.font=(t.fontWeight||a.textWeight)+" 10px "+(t.fontFamily||a.fontFamily);var l=u.measureText(e),d=l.width;if(void 0!==l.actualBoundingBoxLeft&&void 0!==l.actualBoundingBoxRight){var v=l.actualBoundingBoxLeft+l.actualBoundingBoxRight;v>0&&(d=Math.max(d,v))}var x=s*n.singleLineHeight*n.textStyle.fontScale;x>p.lineHeight&&(i+=x-p.lineHeight,p.lineHeight=x,p.offsetY=s*n.textStyle.fontScale*(n.singleLineHeight-1)/2),p.offsetX.push(p.width),p.width+=(d<=0?0:d)*s*n.SCALE_FACTOR*n.textStyle.fontScale+e.length*c,p.richOptions.push(t)})),h.push(p),r=Math.max(r,p.width),i+=p.lineHeight,0!==r&&0!==i){void 0!==this.size&&null!==this.size||(this.size=this.item.transform.size.clone());var d=this.size,v=d.x,x=void 0===v?1:v,g=d.y,y=void 0===g?1:g;if(!this.initialized){this.canvasSize=this.canvasSize?this.canvasSize:new t.math.Vector2(r,i);var m=this.canvasSize,w=m.x,S=m.y;this.item.transform.size.set(x*w*this.SCALE_FACTOR*this.SCALE_FACTOR,y*S*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,b=T.y;if(this.textLayout.width=E/a.fontScale,this.textLayout.height=b/a.fontScale,this.canvas.width=E,this.canvas.height=b,u.clearRect(0,0,E,b),u.fillStyle="rgba(255, 255, 255, "+this.ALPHA_FIX_VALUE+")",e||(u.translate(0,b),u.scale(1,-1)),0!==h.length){var C=o.getOffsetY(a,h.length,f*this.singleLineHeight,a.fontSize);h.forEach((function(e,r){var i=e.richOptions,o=e.offsetX,l=e.width,c=l,h=o;if(s===t.spec.TextOverflow.display&&l>E){var f=E/l;c*=f,h=o.map((function(t){return t*f}))}var p=n.textLayout.getOffsetX(a,c);r>0&&(C+=e.lineHeight-e.offsetY),i.forEach((function(e,n){var r=a.fontScale,i=a.textColor,o=a.fontFamily,c=a.textWeight,f=a.fontStyle,d=e.text,v=e.fontSize,x=e.fontColor,g=void 0===x?i:x,y=e.fontFamily,m=void 0===y?o:y,w=e.fontWeight,S=void 0===w?c:w,T=e.fontStyle,b=void 0===T?f:T,O=v;s===t.spec.TextOverflow.display&&l>E&&(O/=l/E);var z=h[n]+p;u.font=b+" "+S+" "+O*r+"px "+m,u.fillStyle="rgba("+g[0]+", "+g[1]+", "+g[2]+", "+g[3]+")",u.fillText(d,z,C)}))}));var O=u.getImageData(0,0,this.canvas.width,this.canvas.height),z=t.Texture.createWithData(this.engine,{data:new Uint8Array(O.data),width:O.width,height:O.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=z,this.material.setTexture("_MainTex",z),this.isDirty=!1,u.restore()}}else this.isDirty=!1}},r.setShadowOffsetY=function(t){throw new Error("Method not implemented.")},r.setShadowBlur=function(t){throw new Error("Method not implemented.")},r.setShadowOffsetX=function(t){throw new Error("Method not implemented.")},r.setShadowColor=function(t){throw new Error("Method not implemented.")},r.setOutlineWidth=function(t){throw new Error("Method not implemented.")},r.setAutoWidth=function(t){throw new Error("Method not implemented.")},r.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():" "},r.renderText=function(e){var n=e.size;n&&(this.canvasSize=new t.math.Vector2(n[0],n[1])),this.updateTexture()},n}(t.TextComponent),exports.RichTextComponent=function(t,e,n,r){var i,o=arguments.length,a=o<3?e:null===r?r=Object.getOwnPropertyDescriptor(e,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(t,e,n,r);else for(var s=t.length-1;s>=0;s--)(i=t[s])&&(a=(o<3?i(a):o>3?i(e,n,a):i(e,n))||a);return o>3&&a&&Object.defineProperty(e,n,a),a}([t.effectsClass(t.spec.DataType.RichTextComponent)],exports.RichTextComponent);var y="2.5.5";t.registerPlugin("rich-text",a,t.VFXItem),t.logger.info("Plugin rich text version: 2.5.5."),y!==n.version&&console.error("注意:请统一 RichText 插件与 Player 版本,不统一的版本混用会有不可预知的后果!","\nAttention: Please ensure the RichText plugin is synchronized with the Player version. Mixing and matching incompatible versions may result in unpredictable consequences!"),exports.RichTextLoader=a,exports.generateProgram=d,exports.isRichText=function(t){var e=f(t).filter((function(t){var e=t.tokenType;return"ContextStart"===e||"ContextEnd"===e})),n=e.filter((function(t){return"ContextStart"===t.tokenType})),r=e.filter((function(t){return"ContextEnd"===t.tokenType}));return!(n.length!==r.length||!n.length)&&function t(e,n){var r=e[0],i=e.slice(1);if(void 0===n&&(n=[]),!r)return 0===n.length;if("ContextStart"===r.tokenType)return t(i,n.concat(r.value));if("ContextEnd"===r.tokenType)return n[n.length-1]===r.value&&t(i,n.slice(0,-1));throw new Error("Unexpected token: "+r.tokenType)}(e.map((function(t){var e=t.tokenType,n=t.value;return{tokenType:e,value:"ContextStart"===e?n.match(c)[1]:n.match(u)[1]}})))},exports.lexer=f,exports.richTextParser=p,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(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,r.get?r:{enumerable:!0,get:function(){return t[n]}})}})),e.default=t,Object.freeze(e)}var n=e(t);function r(t,e){return r=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},r(t,e)}function i(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&r(t,e)}var o,a=function(t){function e(){var e;return(e=t.apply(this,arguments)||this).name="rich-text",e}return i(e,t),e}(t.AbstractPlugin);function s(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function l(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(n)return(n=n.call(t)).next.bind(n);if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return s(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(n):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?s(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var r=0;return function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}}}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"}(o||(o={}));var c=/^<([a-z]+)(=([^>]+))?>$/,u=/^<\/([a-z]+)>$/,h=[["ContextStart",/^<[a-z]+(=[^>]+)?>/],["Text",/^[^</>=]+/],["ContextEnd",/^<\/[a-z]+>/]],f=function(t,e,n){if(void 0===e&&(e=[]),void 0===n&&(n=0),!t)return e;for(var r,i=l(h);!(r=i()).done;){var o,a=r.value,s=a[0],c=(null!=(o=a[1].exec(t))?o:[])[0];if(c){var u=c.length;return f(t.slice(u),e.concat({tokenType:s,value:c}),n+u)}}throw new Error('Unexpected token: "'+t[0]+'" at position '+n+' while reading "'+t+'"')},p=function(t){var e=function(){var t=s();if("Text"===(null==t?void 0:t.tokenType))return a(),t.value},n=function(){var t=s();if("ContextStart"===(null==t?void 0:t.tokenType)){a();var e,n=t.value.match(c);if(n)return{attributeName:n[1],attributeParam:null!=(e=n[3])?e:""};throw new Error("Expected a start tag marker at position "+o)}return{}},r=function(){var t=s();if("ContextEnd"===(null==t?void 0:t.tokenType)){a();var e=t.value.match(u);if(e)return{attributeName:e[1]};throw new Error("Expect an end tag marker at position "+o)}return{}},i=f(t),o=0,a=function(){var t,e=i.shift();return o+=null!=(t=null==e?void 0:e.value.length)?t:0,e},s=function(){return i[0]},l=[];return function t(i,a){for(void 0===i&&(i=[]),void 0===a&&(a="");;){var s=e();if(s)l.push({attributes:i,text:s});else{var c=n(),u=c.attributeName,h=c.attributeParam;if(!u){if(a){var f=r().attributeName;if(!f)throw new Error('Expect an end tag marker "'+a+'" at position '+o+" but found no tag!");if(f!==a)throw new Error('Expect an end tag marker "'+a+'" at position '+o+' but found tag "'+f+'"');return}break}t(i.concat({attributeName:u,attributeParam:h}),u)}}}(),l};function d(t){return function(e){for(var n,r=l(p(e));!(n=r()).done;){var i=n.value,o=i.text,a=i.attributes.reduce((function(t,e){var n=e.attributeName,r=e.attributeParam;return n&&(t[n]=r),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 n=parseInt(t.slice(6,8),16)/255;t=t.slice(0,6),e=n}var r=parseInt(t,16);return[r>>16&255,r>>8&255,255&r,e]}function x(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"),n=e.getContext("2d");if(n)try{return n.fillStyle=t,n.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 n(t){var n;return(n=e.call(this,t)||this).processedTextOptions=[],n.singleLineHeight=1.571,n.size=null,n.initialized=!1,n.canvasSize=null,n.name="MRichText"+g++,n}i(n,e);var r=n.prototype;return r.generateTextProgram=function(e){var n=this;this.processedTextOptions=[];var r=d((function(e,r){/^\n+$/.test(e)&&(e=e.replace(/\n/g,"\n ")),e.split("\n").forEach((function(e,i){var o={text:e,fontSize:n.textStyle.fontSize,isNewLine:!1};i>0&&(o.isNewLine=!0),"b"in r&&(o.fontWeight=t.spec.TextWeight.bold),"i"in r&&(o.fontStyle=t.spec.FontStyle.italic),"size"in r&&r.size&&(o.fontSize=parseInt(r.size,10)),"color"in r&&r.color&&(o.fontColor=x(r.color)),n.processedTextOptions.push(o)}))}));r(e)},r.updateTexture=function(e){var n=this;if(void 0===e&&(e=!0),this.isDirty&&this.context&&this.canvas){this.generateTextProgram(this.text);var r=0,i=0,o=this.textLayout,a=this.textStyle,s=o.overflow,l=o.letterSpace,c=void 0===l?0:l,u=this.context;u.save();var h=[],f=a.fontSize*this.textStyle.fontScale,p={richOptions:[],offsetX:[],width:0,lineHeight:f*this.singleLineHeight,offsetY:f*(this.singleLineHeight-1)/2};if(this.processedTextOptions.forEach((function(t){var e=t.text,o=t.isNewLine,s=t.fontSize;o&&(h.push(p),r=Math.max(r,p.width),p={richOptions:[],offsetX:[],width:0,lineHeight:f*n.singleLineHeight,offsetY:f*(n.singleLineHeight-1)/2},i+=p.lineHeight),u.font=(t.fontWeight||a.textWeight)+" 10px "+(t.fontFamily||a.fontFamily);var l=u.measureText(e),d=l.width;if(void 0!==l.actualBoundingBoxLeft&&void 0!==l.actualBoundingBoxRight){var v=l.actualBoundingBoxLeft+l.actualBoundingBoxRight;v>0&&(d=Math.max(d,v))}var x=s*n.singleLineHeight*n.textStyle.fontScale;x>p.lineHeight&&(i+=x-p.lineHeight,p.lineHeight=x,p.offsetY=s*n.textStyle.fontScale*(n.singleLineHeight-1)/2),p.offsetX.push(p.width),p.width+=(d<=0?0:d)*s*n.SCALE_FACTOR*n.textStyle.fontScale+e.length*c,p.richOptions.push(t)})),h.push(p),r=Math.max(r,p.width),i+=p.lineHeight,0!==r&&0!==i){void 0!==this.size&&null!==this.size||(this.size=this.item.transform.size.clone());var d=this.size,v=d.x,x=void 0===v?1:v,g=d.y,y=void 0===g?1:g;if(!this.initialized){this.canvasSize=this.canvasSize?this.canvasSize:new t.math.Vector2(r,i);var m=this.canvasSize,w=m.x,S=m.y;this.item.transform.size.set(x*w*this.SCALE_FACTOR*this.SCALE_FACTOR,y*S*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,b=T.y;if(this.textLayout.width=E/a.fontScale,this.textLayout.height=b/a.fontScale,this.canvas.width=E,this.canvas.height=b,u.clearRect(0,0,E,b),u.fillStyle="rgba(255, 255, 255, "+this.ALPHA_FIX_VALUE+")",e||(u.translate(0,b),u.scale(1,-1)),0!==h.length){var C=o.getOffsetY(a,h.length,f*this.singleLineHeight,a.fontSize);h.forEach((function(e,r){var i=e.richOptions,o=e.offsetX,l=e.width,c=l,h=o;if(s===t.spec.TextOverflow.display&&l>E){var f=E/l;c*=f,h=o.map((function(t){return t*f}))}var p=n.textLayout.getOffsetX(a,c);r>0&&(C+=e.lineHeight-e.offsetY),i.forEach((function(e,n){var r=a.fontScale,i=a.textColor,o=a.fontFamily,c=a.textWeight,f=a.fontStyle,d=e.text,v=e.fontSize,x=e.fontColor,g=void 0===x?i:x,y=e.fontFamily,m=void 0===y?o:y,w=e.fontWeight,S=void 0===w?c:w,T=e.fontStyle,b=void 0===T?f:T,O=v;s===t.spec.TextOverflow.display&&l>E&&(O/=l/E);var z=h[n]+p;u.font=b+" "+S+" "+O*r+"px "+m,u.fillStyle="rgba("+g[0]+", "+g[1]+", "+g[2]+", "+g[3]+")",u.fillText(d,z,C)}))}));var O=u.getImageData(0,0,this.canvas.width,this.canvas.height),z=t.Texture.createWithData(this.engine,{data:new Uint8Array(O.data),width:O.width,height:O.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=z,this.material.setTexture("_MainTex",z),this.isDirty=!1,u.restore()}}else this.isDirty=!1}},r.setShadowOffsetY=function(t){throw new Error("Method not implemented.")},r.setShadowBlur=function(t){throw new Error("Method not implemented.")},r.setShadowOffsetX=function(t){throw new Error("Method not implemented.")},r.setShadowColor=function(t){throw new Error("Method not implemented.")},r.setOutlineWidth=function(t){throw new Error("Method not implemented.")},r.setAutoWidth=function(t){throw new Error("Method not implemented.")},r.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():" "},r.renderText=function(e){var n=e.size;n&&(this.canvasSize=new t.math.Vector2(n[0],n[1])),this.updateTexture()},n}(t.TextComponent),exports.RichTextComponent=function(t,e,n,r){var i,o=arguments.length,a=o<3?e:null===r?r=Object.getOwnPropertyDescriptor(e,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(t,e,n,r);else for(var s=t.length-1;s>=0;s--)(i=t[s])&&(a=(o<3?i(a):o>3?i(e,n,a):i(e,n))||a);return o>3&&a&&Object.defineProperty(e,n,a),a}([t.effectsClass(t.spec.DataType.RichTextComponent)],exports.RichTextComponent);var y="2.5.6";t.registerPlugin("rich-text",a,t.VFXItem),t.logger.info("Plugin rich text version: 2.5.6."),y!==n.version&&console.error("注意:请统一 RichText 插件与 Player 版本,不统一的版本混用会有不可预知的后果!","\nAttention: Please ensure the RichText plugin is synchronized with the Player version. Mixing and matching incompatible versions may result in unpredictable consequences!"),exports.RichTextLoader=a,exports.generateProgram=d,exports.isRichText=function(t){var e=f(t).filter((function(t){var e=t.tokenType;return"ContextStart"===e||"ContextEnd"===e})),n=e.filter((function(t){return"ContextStart"===t.tokenType})),r=e.filter((function(t){return"ContextEnd"===t.tokenType}));return!(n.length!==r.length||!n.length)&&function t(e,n){var r=e[0],i=e.slice(1);if(void 0===n&&(n=[]),!r)return 0===n.length;if("ContextStart"===r.tokenType)return t(i,n.concat(r.value));if("ContextEnd"===r.tokenType)return n[n.length-1]===r.value&&t(i,n.slice(0,-1));throw new Error("Unexpected token: "+r.tokenType)}(e.map((function(t){var e=t.tokenType,n=t.value;return{tokenType:e,value:"ContextStart"===e?n.match(c)[1]:n.match(u)[1]}})))},exports.lexer=f,exports.richTextParser=p,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 n,spec as i,math as r,assertExist as o,Texture as a,glContext as s,TextStyle as l,TextLayout as h,TextComponent as f,registerPlugin as u,VFXItem as c,logger as d}from"@galacean/effects/alipay";function v(t,e){return v=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},v(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&&v(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 n=0,i=new Array(e);n<e;n++)i[n]=t[n];return i}function m(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(n)return(n=n.call(t)).next.bind(n);if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return y(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(n):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?y(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var i=0;return function(){return i>=t.length?{done:!0}:{done:!1,value:t[i++]}}}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"}(x||(x={}));var w=/^<([a-z]+)(=([^>]+))?>$/,S=/^<\/([a-z]+)>$/,T=[["ContextStart",/^<[a-z]+(=[^>]+)?>/],["Text",/^[^</>=]+/],["ContextEnd",/^<\/[a-z]+>/]],E=function(t,e,n){if(void 0===e&&(e=[]),void 0===n&&(n=0),!t)return e;for(var i,r=m(T);!(i=r()).done;){var o,a=i.value,s=a[0],l=(null!=(o=a[1].exec(t))?o:[])[0];if(l){var h=l.length;return E(t.slice(h),e.concat({tokenType:s,value:l}),n+h)}}throw new Error('Unexpected token: "'+t[0]+'" at position '+n+' while reading "'+t+'"')},b=function(t){var e=function(){var t=s();if("Text"===(null==t?void 0:t.tokenType))return a(),t.value},n=function(){var t=s();if("ContextStart"===(null==t?void 0:t.tokenType)){a();var e,n=t.value.match(w);if(n)return{attributeName:n[1],attributeParam:null!=(e=n[3])?e:""};throw new Error("Expected a start tag marker at position "+o)}return{}},i=function(){var t=s();if("ContextEnd"===(null==t?void 0:t.tokenType)){a();var e=t.value.match(S);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]},l=[];return function t(r,a){for(void 0===r&&(r=[]),void 0===a&&(a="");;){var s=e();if(s)l.push({attributes:r,text:s});else{var h=n(),f=h.attributeName,u=h.attributeParam;if(!f){if(a){var c=i().attributeName;if(!c)throw new Error('Expect an end tag marker "'+a+'" at position '+o+" but found no tag!");if(c!==a)throw new Error('Expect an end tag marker "'+a+'" at position '+o+' but found tag "'+c+'"');return}break}t(r.concat({attributeName:f,attributeParam:u}),f)}}}(),l};function z(t){return function(e){for(var n,i=m(b(e));!(n=i()).done;){var r=n.value,o=r.text,a=r.attributes.reduce((function(t,e){var n=e.attributeName,i=e.attributeParam;return n&&(t[n]=i),t}),{});t(o,a)}}}function C(t){var e=E(t).filter((function(t){var e=t.tokenType;return"ContextStart"===e||"ContextEnd"===e})),n=e.filter((function(t){return"ContextStart"===t.tokenType})),i=e.filter((function(t){return"ContextEnd"===t.tokenType}));if(n.length!==i.length||!n.length)return!1;return function t(e,n){var i=e[0],r=e.slice(1);if(void 0===n&&(n=[]),!i)return 0===n.length;if("ContextStart"===i.tokenType)return t(r,n.concat(i.value));if("ContextEnd"===i.tokenType)return n[n.length-1]===i.value&&t(r,n.slice(0,-1));throw new Error("Unexpected token: "+i.tokenType)}(e.map((function(t){var e=t.tokenType,n=t.value;return{tokenType:e,value:"ContextStart"===e?n.match(w)[1]:n.match(S)[1]}})))}function O(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 n=parseInt(t.slice(6,8),16)/255;t=t.slice(0,6),e=n}var i=parseInt(t,16);return[i>>16&255,i>>8&255,255&i,e]}function L(t,e){if(void 0===e&&(e=1),"string"!=typeof t||!t)throw new Error("Invalid color string");return t.startsWith("#")?O(t,e):O(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"),n=e.getContext("2d");if(n)try{return n.fillStyle=t,n.fillStyle}finally{e.remove()}throw new Error("Failed to get 2D context for color conversion!")}(t))}"function"==typeof SuppressedError&&SuppressedError;var A=0,k=function(t){function e(e){var n;return(n=t.call(this,e)||this).processedTextOptions=[],n.singleLineHeight=1.571,n.size=null,n.initialized=!1,n.canvasSize=null,n.name="MRichText"+A++,n}p(e,t);var n=e.prototype;return n.generateTextProgram=function(t){var e=this;this.processedTextOptions=[];var n=z((function(t,n){/^\n+$/.test(t)&&(t=t.replace(/\n/g,"\n ")),t.split("\n").forEach((function(t,r){var o={text:t,fontSize:e.textStyle.fontSize,isNewLine:!1};r>0&&(o.isNewLine=!0),"b"in n&&(o.fontWeight=i.TextWeight.bold),"i"in n&&(o.fontStyle=i.FontStyle.italic),"size"in n&&n.size&&(o.fontSize=parseInt(n.size,10)),"color"in n&&n.color&&(o.fontColor=L(n.color)),e.processedTextOptions.push(o)}))}));n(t)},n.updateTexture=function(t){var e=this;if(void 0===t&&(t=!0),this.isDirty&&this.context&&this.canvas){this.generateTextProgram(this.text);var n=0,l=0,h=this.textLayout,f=this.textStyle,u=h.overflow,c=h.letterSpace,d=void 0===c?0:c,v=this.context;v.save();var p=[],x=f.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,r=t.isNewLine,o=t.fontSize;r&&(p.push(g),n=Math.max(n,g.width),g={richOptions:[],offsetX:[],width:0,lineHeight:x*e.singleLineHeight,offsetY:x*(e.singleLineHeight-1)/2},l+=g.lineHeight),v.font=(t.fontWeight||f.textWeight)+" 10px "+(t.fontFamily||f.fontFamily);var a=v.measureText(i),s=a.width;if(void 0!==a.actualBoundingBoxLeft&&void 0!==a.actualBoundingBoxRight){var h=a.actualBoundingBoxLeft+a.actualBoundingBoxRight;h>0&&(s=Math.max(s,h))}var u=o*e.singleLineHeight*e.textStyle.fontScale;u>g.lineHeight&&(l+=u-g.lineHeight,g.lineHeight=u,g.offsetY=o*e.textStyle.fontScale*(e.singleLineHeight-1)/2),g.offsetX.push(g.width),g.width+=(s<=0?0:s)*o*e.SCALE_FACTOR*e.textStyle.fontScale+i.length*d,g.richOptions.push(t)})),p.push(g),n=Math.max(n,g.width),l+=g.lineHeight,0!==n&&0!==l){void 0!==this.size&&null!==this.size||(this.size=this.item.transform.size.clone());var y=this.size,m=y.x,w=void 0===m?1:m,S=y.y,T=void 0===S?1:S;if(!this.initialized){this.canvasSize=this.canvasSize?this.canvasSize:new r.Vector2(n,l);var E=this.canvasSize,b=E.x,z=E.y;this.item.transform.size.set(w*b*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,L=C.y;if(this.textLayout.width=O/f.fontScale,this.textLayout.height=L/f.fontScale,this.canvas.width=O,this.canvas.height=L,v.clearRect(0,0,O,L),v.fillStyle="rgba(255, 255, 255, "+this.ALPHA_FIX_VALUE+")",t||(v.translate(0,L),v.scale(1,-1)),0!==p.length){var A=h.getOffsetY(f,p.length,x*this.singleLineHeight,f.fontSize);p.forEach((function(t,n){var r=t.richOptions,o=t.offsetX,a=t.width,s=a,l=o;if(u===i.TextOverflow.display&&a>O){var h=O/a;s*=h,l=o.map((function(t){return t*h}))}var c=e.textLayout.getOffsetX(f,s);n>0&&(A+=t.lineHeight-t.offsetY),r.forEach((function(t,e){var n=f.fontScale,r=f.textColor,o=f.fontFamily,s=f.textWeight,h=f.fontStyle,d=t.text,p=t.fontSize,x=t.fontColor,g=void 0===x?r:x,y=t.fontFamily,m=void 0===y?o:y,w=t.fontWeight,S=void 0===w?s:w,T=t.fontStyle,E=void 0===T?h:T,b=p;u===i.TextOverflow.display&&a>O&&(b/=a/O);var z=l[e]+c;v.font=E+" "+S+" "+b*n+"px "+m,v.fillStyle="rgba("+g[0]+", "+g[1]+", "+g[2]+", "+g[3]+")",v.fillText(d,z,A)}))}));var k=v.getImageData(0,0,this.canvas.width,this.canvas.height),H=a.createWithData(this.engine,{data:new Uint8Array(k.data),width:k.width,height:k.height},{flipY:t,magFilter:s.LINEAR,minFilter:s.LINEAR,wrapS:s.CLAMP_TO_EDGE,wrapT:s.CLAMP_TO_EDGE});this.renderer.texture=H,this.material.setTexture("_MainTex",H),this.isDirty=!1,v.restore()}}else this.isDirty=!1}},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(t){this.textStyle=new l(t),this.textLayout=new h(t),this.textLayout.textBaseline=t.textBaseline||i.TextBaseline.middle,this.text=t.text?t.text.toString():" "},n.renderText=function(t){var e=t.size;e&&(this.canvasSize=new r.Vector2(e[0],e[1])),this.updateTexture()},e}(f);k=function(t,e,n,i){var r,o=arguments.length,a=o<3?e:null===i?i=Object.getOwnPropertyDescriptor(e,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(t,e,n,i);else for(var s=t.length-1;s>=0;s--)(r=t[s])&&(a=(o<3?r(a):o>3?r(e,n,a):r(e,n))||a);return o>3&&a&&Object.defineProperty(e,n,a),a}([n(i.DataType.RichTextComponent)],k);var H="2.5.5";u("rich-text",g,c),d.info("Plugin rich text version: 2.5.5."),H!==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{k as RichTextComponent,g as RichTextLoader,z as generateProgram,C as isRichText,E as lexer,b as richTextParser,H as version};
1
+ import*as t from"@galacean/effects/alipay";import{AbstractPlugin as e,effectsClass as n,spec as i,math as r,assertExist as o,Texture as a,glContext as s,TextStyle as l,TextLayout as h,TextComponent as f,registerPlugin as u,VFXItem as c,logger as d}from"@galacean/effects/alipay";function v(t,e){return v=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},v(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&&v(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 n=0,i=new Array(e);n<e;n++)i[n]=t[n];return i}function m(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(n)return(n=n.call(t)).next.bind(n);if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return y(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(n):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?y(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var i=0;return function(){return i>=t.length?{done:!0}:{done:!1,value:t[i++]}}}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"}(x||(x={}));var w=/^<([a-z]+)(=([^>]+))?>$/,S=/^<\/([a-z]+)>$/,T=[["ContextStart",/^<[a-z]+(=[^>]+)?>/],["Text",/^[^</>=]+/],["ContextEnd",/^<\/[a-z]+>/]],E=function(t,e,n){if(void 0===e&&(e=[]),void 0===n&&(n=0),!t)return e;for(var i,r=m(T);!(i=r()).done;){var o,a=i.value,s=a[0],l=(null!=(o=a[1].exec(t))?o:[])[0];if(l){var h=l.length;return E(t.slice(h),e.concat({tokenType:s,value:l}),n+h)}}throw new Error('Unexpected token: "'+t[0]+'" at position '+n+' while reading "'+t+'"')},b=function(t){var e=function(){var t=s();if("Text"===(null==t?void 0:t.tokenType))return a(),t.value},n=function(){var t=s();if("ContextStart"===(null==t?void 0:t.tokenType)){a();var e,n=t.value.match(w);if(n)return{attributeName:n[1],attributeParam:null!=(e=n[3])?e:""};throw new Error("Expected a start tag marker at position "+o)}return{}},i=function(){var t=s();if("ContextEnd"===(null==t?void 0:t.tokenType)){a();var e=t.value.match(S);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]},l=[];return function t(r,a){for(void 0===r&&(r=[]),void 0===a&&(a="");;){var s=e();if(s)l.push({attributes:r,text:s});else{var h=n(),f=h.attributeName,u=h.attributeParam;if(!f){if(a){var c=i().attributeName;if(!c)throw new Error('Expect an end tag marker "'+a+'" at position '+o+" but found no tag!");if(c!==a)throw new Error('Expect an end tag marker "'+a+'" at position '+o+' but found tag "'+c+'"');return}break}t(r.concat({attributeName:f,attributeParam:u}),f)}}}(),l};function z(t){return function(e){for(var n,i=m(b(e));!(n=i()).done;){var r=n.value,o=r.text,a=r.attributes.reduce((function(t,e){var n=e.attributeName,i=e.attributeParam;return n&&(t[n]=i),t}),{});t(o,a)}}}function C(t){var e=E(t).filter((function(t){var e=t.tokenType;return"ContextStart"===e||"ContextEnd"===e})),n=e.filter((function(t){return"ContextStart"===t.tokenType})),i=e.filter((function(t){return"ContextEnd"===t.tokenType}));if(n.length!==i.length||!n.length)return!1;return function t(e,n){var i=e[0],r=e.slice(1);if(void 0===n&&(n=[]),!i)return 0===n.length;if("ContextStart"===i.tokenType)return t(r,n.concat(i.value));if("ContextEnd"===i.tokenType)return n[n.length-1]===i.value&&t(r,n.slice(0,-1));throw new Error("Unexpected token: "+i.tokenType)}(e.map((function(t){var e=t.tokenType,n=t.value;return{tokenType:e,value:"ContextStart"===e?n.match(w)[1]:n.match(S)[1]}})))}function O(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 n=parseInt(t.slice(6,8),16)/255;t=t.slice(0,6),e=n}var i=parseInt(t,16);return[i>>16&255,i>>8&255,255&i,e]}function L(t,e){if(void 0===e&&(e=1),"string"!=typeof t||!t)throw new Error("Invalid color string");return t.startsWith("#")?O(t,e):O(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"),n=e.getContext("2d");if(n)try{return n.fillStyle=t,n.fillStyle}finally{e.remove()}throw new Error("Failed to get 2D context for color conversion!")}(t))}"function"==typeof SuppressedError&&SuppressedError;var A=0,k=function(t){function e(e){var n;return(n=t.call(this,e)||this).processedTextOptions=[],n.singleLineHeight=1.571,n.size=null,n.initialized=!1,n.canvasSize=null,n.name="MRichText"+A++,n}p(e,t);var n=e.prototype;return n.generateTextProgram=function(t){var e=this;this.processedTextOptions=[];var n=z((function(t,n){/^\n+$/.test(t)&&(t=t.replace(/\n/g,"\n ")),t.split("\n").forEach((function(t,r){var o={text:t,fontSize:e.textStyle.fontSize,isNewLine:!1};r>0&&(o.isNewLine=!0),"b"in n&&(o.fontWeight=i.TextWeight.bold),"i"in n&&(o.fontStyle=i.FontStyle.italic),"size"in n&&n.size&&(o.fontSize=parseInt(n.size,10)),"color"in n&&n.color&&(o.fontColor=L(n.color)),e.processedTextOptions.push(o)}))}));n(t)},n.updateTexture=function(t){var e=this;if(void 0===t&&(t=!0),this.isDirty&&this.context&&this.canvas){this.generateTextProgram(this.text);var n=0,l=0,h=this.textLayout,f=this.textStyle,u=h.overflow,c=h.letterSpace,d=void 0===c?0:c,v=this.context;v.save();var p=[],x=f.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,r=t.isNewLine,o=t.fontSize;r&&(p.push(g),n=Math.max(n,g.width),g={richOptions:[],offsetX:[],width:0,lineHeight:x*e.singleLineHeight,offsetY:x*(e.singleLineHeight-1)/2},l+=g.lineHeight),v.font=(t.fontWeight||f.textWeight)+" 10px "+(t.fontFamily||f.fontFamily);var a=v.measureText(i),s=a.width;if(void 0!==a.actualBoundingBoxLeft&&void 0!==a.actualBoundingBoxRight){var h=a.actualBoundingBoxLeft+a.actualBoundingBoxRight;h>0&&(s=Math.max(s,h))}var u=o*e.singleLineHeight*e.textStyle.fontScale;u>g.lineHeight&&(l+=u-g.lineHeight,g.lineHeight=u,g.offsetY=o*e.textStyle.fontScale*(e.singleLineHeight-1)/2),g.offsetX.push(g.width),g.width+=(s<=0?0:s)*o*e.SCALE_FACTOR*e.textStyle.fontScale+i.length*d,g.richOptions.push(t)})),p.push(g),n=Math.max(n,g.width),l+=g.lineHeight,0!==n&&0!==l){void 0!==this.size&&null!==this.size||(this.size=this.item.transform.size.clone());var y=this.size,m=y.x,w=void 0===m?1:m,S=y.y,T=void 0===S?1:S;if(!this.initialized){this.canvasSize=this.canvasSize?this.canvasSize:new r.Vector2(n,l);var E=this.canvasSize,b=E.x,z=E.y;this.item.transform.size.set(w*b*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,L=C.y;if(this.textLayout.width=O/f.fontScale,this.textLayout.height=L/f.fontScale,this.canvas.width=O,this.canvas.height=L,v.clearRect(0,0,O,L),v.fillStyle="rgba(255, 255, 255, "+this.ALPHA_FIX_VALUE+")",t||(v.translate(0,L),v.scale(1,-1)),0!==p.length){var A=h.getOffsetY(f,p.length,x*this.singleLineHeight,f.fontSize);p.forEach((function(t,n){var r=t.richOptions,o=t.offsetX,a=t.width,s=a,l=o;if(u===i.TextOverflow.display&&a>O){var h=O/a;s*=h,l=o.map((function(t){return t*h}))}var c=e.textLayout.getOffsetX(f,s);n>0&&(A+=t.lineHeight-t.offsetY),r.forEach((function(t,e){var n=f.fontScale,r=f.textColor,o=f.fontFamily,s=f.textWeight,h=f.fontStyle,d=t.text,p=t.fontSize,x=t.fontColor,g=void 0===x?r:x,y=t.fontFamily,m=void 0===y?o:y,w=t.fontWeight,S=void 0===w?s:w,T=t.fontStyle,E=void 0===T?h:T,b=p;u===i.TextOverflow.display&&a>O&&(b/=a/O);var z=l[e]+c;v.font=E+" "+S+" "+b*n+"px "+m,v.fillStyle="rgba("+g[0]+", "+g[1]+", "+g[2]+", "+g[3]+")",v.fillText(d,z,A)}))}));var k=v.getImageData(0,0,this.canvas.width,this.canvas.height),H=a.createWithData(this.engine,{data:new Uint8Array(k.data),width:k.width,height:k.height},{flipY:t,magFilter:s.LINEAR,minFilter:s.LINEAR,wrapS:s.CLAMP_TO_EDGE,wrapT:s.CLAMP_TO_EDGE});this.renderer.texture=H,this.material.setTexture("_MainTex",H),this.isDirty=!1,v.restore()}}else this.isDirty=!1}},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(t){this.textStyle=new l(t),this.textLayout=new h(t),this.textLayout.textBaseline=t.textBaseline||i.TextBaseline.middle,this.text=t.text?t.text.toString():" "},n.renderText=function(t){var e=t.size;e&&(this.canvasSize=new r.Vector2(e[0],e[1])),this.updateTexture()},e}(f);k=function(t,e,n,i){var r,o=arguments.length,a=o<3?e:null===i?i=Object.getOwnPropertyDescriptor(e,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(t,e,n,i);else for(var s=t.length-1;s>=0;s--)(r=t[s])&&(a=(o<3?r(a):o>3?r(e,n,a):r(e,n))||a);return o>3&&a&&Object.defineProperty(e,n,a),a}([n(i.DataType.RichTextComponent)],k);var H="2.5.6";u("rich-text",g,c),d.info("Plugin rich text version: 2.5.6."),H!==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{k as RichTextComponent,g as RichTextLoader,z as generateProgram,C as isRichText,E as lexer,b as richTextParser,H 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(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,r.get?r:{enumerable:!0,get:function(){return t[n]}})}})),e.default=t,Object.freeze(e)}var n=e(t);function r(t,e){return r=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},r(t,e)}function i(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&r(t,e)}var o,a=function(t){function e(){var e;return(e=t.apply(this,arguments)||this).name="rich-text",e}return i(e,t),e}(t.AbstractPlugin);function s(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function l(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(n)return(n=n.call(t)).next.bind(n);if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return s(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(n):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?s(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var r=0;return function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}}}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"}(o||(o={}));var u=/^<([a-z]+)(=([^>]+))?>$/,c=/^<\/([a-z]+)>$/,h=[["ContextStart",/^<[a-z]+(=[^>]+)?>/],["Text",/^[^</>=]+/],["ContextEnd",/^<\/[a-z]+>/]],f=function(t,e,n){if(void 0===e&&(e=[]),void 0===n&&(n=0),!t)return e;for(var r,i=l(h);!(r=i()).done;){var o,a=r.value,s=a[0],u=(null!=(o=a[1].exec(t))?o:[])[0];if(u){var c=u.length;return f(t.slice(c),e.concat({tokenType:s,value:u}),n+c)}}throw new Error('Unexpected token: "'+t[0]+'" at position '+n+' while reading "'+t+'"')},p=function(t){var e=function(){var t=s();if("Text"===(null==t?void 0:t.tokenType))return a(),t.value},n=function(){var t=s();if("ContextStart"===(null==t?void 0:t.tokenType)){a();var e,n=t.value.match(u);if(n)return{attributeName:n[1],attributeParam:null!=(e=n[3])?e:""};throw new Error("Expected a start tag marker at position "+o)}return{}},r=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{}},i=f(t),o=0,a=function(){var t,e=i.shift();return o+=null!=(t=null==e?void 0:e.value.length)?t:0,e},s=function(){return i[0]},l=[];return function t(i,a){for(void 0===i&&(i=[]),void 0===a&&(a="");;){var s=e();if(s)l.push({attributes:i,text:s});else{var u=n(),c=u.attributeName,h=u.attributeParam;if(!c){if(a){var f=r().attributeName;if(!f)throw new Error('Expect an end tag marker "'+a+'" at position '+o+" but found no tag!");if(f!==a)throw new Error('Expect an end tag marker "'+a+'" at position '+o+' but found tag "'+f+'"');return}break}t(i.concat({attributeName:c,attributeParam:h}),c)}}}(),l};function d(t){return function(e){for(var n,r=l(p(e));!(n=r()).done;){var i=n.value,o=i.text,a=i.attributes.reduce((function(t,e){var n=e.attributeName,r=e.attributeParam;return n&&(t[n]=r),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 n=parseInt(t.slice(6,8),16)/255;t=t.slice(0,6),e=n}var r=parseInt(t,16);return[r>>16&255,r>>8&255,255&r,e]}function x(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"),n=e.getContext("2d");if(n)try{return n.fillStyle=t,n.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 n(t){var n;return(n=e.call(this,t)||this).processedTextOptions=[],n.singleLineHeight=1.571,n.size=null,n.initialized=!1,n.canvasSize=null,n.name="MRichText"+g++,n}i(n,e);var r=n.prototype;return r.generateTextProgram=function(e){var n=this;this.processedTextOptions=[];var r=d((function(e,r){/^\n+$/.test(e)&&(e=e.replace(/\n/g,"\n ")),e.split("\n").forEach((function(e,i){var o={text:e,fontSize:n.textStyle.fontSize,isNewLine:!1};i>0&&(o.isNewLine=!0),"b"in r&&(o.fontWeight=t.spec.TextWeight.bold),"i"in r&&(o.fontStyle=t.spec.FontStyle.italic),"size"in r&&r.size&&(o.fontSize=parseInt(r.size,10)),"color"in r&&r.color&&(o.fontColor=x(r.color)),n.processedTextOptions.push(o)}))}));r(e)},r.updateTexture=function(e){var n=this;if(void 0===e&&(e=!0),this.isDirty&&this.context&&this.canvas){this.generateTextProgram(this.text);var r=0,i=0,o=this.textLayout,a=this.textStyle,s=o.overflow,l=o.letterSpace,u=void 0===l?0:l,c=this.context;c.save();var h=[],f=a.fontSize*this.textStyle.fontScale,p={richOptions:[],offsetX:[],width:0,lineHeight:f*this.singleLineHeight,offsetY:f*(this.singleLineHeight-1)/2};if(this.processedTextOptions.forEach((function(t){var e=t.text,o=t.isNewLine,s=t.fontSize;o&&(h.push(p),r=Math.max(r,p.width),p={richOptions:[],offsetX:[],width:0,lineHeight:f*n.singleLineHeight,offsetY:f*(n.singleLineHeight-1)/2},i+=p.lineHeight),c.font=(t.fontWeight||a.textWeight)+" 10px "+(t.fontFamily||a.fontFamily);var l=c.measureText(e),d=l.width;if(void 0!==l.actualBoundingBoxLeft&&void 0!==l.actualBoundingBoxRight){var v=l.actualBoundingBoxLeft+l.actualBoundingBoxRight;v>0&&(d=Math.max(d,v))}var x=s*n.singleLineHeight*n.textStyle.fontScale;x>p.lineHeight&&(i+=x-p.lineHeight,p.lineHeight=x,p.offsetY=s*n.textStyle.fontScale*(n.singleLineHeight-1)/2),p.offsetX.push(p.width),p.width+=(d<=0?0:d)*s*n.SCALE_FACTOR*n.textStyle.fontScale+e.length*u,p.richOptions.push(t)})),h.push(p),r=Math.max(r,p.width),i+=p.lineHeight,0!==r&&0!==i){void 0!==this.size&&null!==this.size||(this.size=this.item.transform.size.clone());var d=this.size,v=d.x,x=void 0===v?1:v,g=d.y,y=void 0===g?1:g;if(!this.initialized){this.canvasSize=this.canvasSize?this.canvasSize:new t.math.Vector2(r,i);var m=this.canvasSize,w=m.x,S=m.y;this.item.transform.size.set(x*w*this.SCALE_FACTOR*this.SCALE_FACTOR,y*S*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,b=T.y;if(this.textLayout.width=E/a.fontScale,this.textLayout.height=b/a.fontScale,this.canvas.width=E,this.canvas.height=b,c.clearRect(0,0,E,b),c.fillStyle="rgba(255, 255, 255, "+this.ALPHA_FIX_VALUE+")",e||(c.translate(0,b),c.scale(1,-1)),0!==h.length){var C=o.getOffsetY(a,h.length,f*this.singleLineHeight,a.fontSize);h.forEach((function(e,r){var i=e.richOptions,o=e.offsetX,l=e.width,u=l,h=o;if(s===t.spec.TextOverflow.display&&l>E){var f=E/l;u*=f,h=o.map((function(t){return t*f}))}var p=n.textLayout.getOffsetX(a,u);r>0&&(C+=e.lineHeight-e.offsetY),i.forEach((function(e,n){var r=a.fontScale,i=a.textColor,o=a.fontFamily,u=a.textWeight,f=a.fontStyle,d=e.text,v=e.fontSize,x=e.fontColor,g=void 0===x?i:x,y=e.fontFamily,m=void 0===y?o:y,w=e.fontWeight,S=void 0===w?u:w,T=e.fontStyle,b=void 0===T?f:T,O=v;s===t.spec.TextOverflow.display&&l>E&&(O/=l/E);var z=h[n]+p;c.font=b+" "+S+" "+O*r+"px "+m,c.fillStyle="rgba("+g[0]+", "+g[1]+", "+g[2]+", "+g[3]+")",c.fillText(d,z,C)}))}));var O=c.getImageData(0,0,this.canvas.width,this.canvas.height),z=t.Texture.createWithData(this.engine,{data:new Uint8Array(O.data),width:O.width,height:O.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=z,this.material.setTexture("_MainTex",z),this.isDirty=!1,c.restore()}}else this.isDirty=!1}},r.setShadowOffsetY=function(t){throw new Error("Method not implemented.")},r.setShadowBlur=function(t){throw new Error("Method not implemented.")},r.setShadowOffsetX=function(t){throw new Error("Method not implemented.")},r.setShadowColor=function(t){throw new Error("Method not implemented.")},r.setOutlineWidth=function(t){throw new Error("Method not implemented.")},r.setAutoWidth=function(t){throw new Error("Method not implemented.")},r.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():" "},r.renderText=function(e){var n=e.size;n&&(this.canvasSize=new t.math.Vector2(n[0],n[1])),this.updateTexture()},n}(t.TextComponent),exports.RichTextComponent=function(t,e,n,r){var i,o=arguments.length,a=o<3?e:null===r?r=Object.getOwnPropertyDescriptor(e,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(t,e,n,r);else for(var s=t.length-1;s>=0;s--)(i=t[s])&&(a=(o<3?i(a):o>3?i(e,n,a):i(e,n))||a);return o>3&&a&&Object.defineProperty(e,n,a),a}([t.effectsClass(t.spec.DataType.RichTextComponent)],exports.RichTextComponent);var y="2.5.5";t.registerPlugin("rich-text",a,t.VFXItem),t.logger.info("Plugin rich text version: 2.5.5."),y!==n.version&&console.error("注意:请统一 RichText 插件与 Player 版本,不统一的版本混用会有不可预知的后果!","\nAttention: Please ensure the RichText plugin is synchronized with the Player version. Mixing and matching incompatible versions may result in unpredictable consequences!"),exports.RichTextLoader=a,exports.generateProgram=d,exports.isRichText=function(t){var e=f(t).filter((function(t){var e=t.tokenType;return"ContextStart"===e||"ContextEnd"===e})),n=e.filter((function(t){return"ContextStart"===t.tokenType})),r=e.filter((function(t){return"ContextEnd"===t.tokenType}));return!(n.length!==r.length||!n.length)&&function t(e,n){var r=e[0],i=e.slice(1);if(void 0===n&&(n=[]),!r)return 0===n.length;if("ContextStart"===r.tokenType)return t(i,n.concat(r.value));if("ContextEnd"===r.tokenType)return n[n.length-1]===r.value&&t(i,n.slice(0,-1));throw new Error("Unexpected token: "+r.tokenType)}(e.map((function(t){var e=t.tokenType,n=t.value;return{tokenType:e,value:"ContextStart"===e?n.match(u)[1]:n.match(c)[1]}})))},exports.lexer=f,exports.richTextParser=p,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(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,r.get?r:{enumerable:!0,get:function(){return t[n]}})}})),e.default=t,Object.freeze(e)}var n=e(t);function r(t,e){return r=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},r(t,e)}function i(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&r(t,e)}var o,a=function(t){function e(){var e;return(e=t.apply(this,arguments)||this).name="rich-text",e}return i(e,t),e}(t.AbstractPlugin);function s(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function l(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(n)return(n=n.call(t)).next.bind(n);if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return s(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(n):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?s(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var r=0;return function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}}}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"}(o||(o={}));var u=/^<([a-z]+)(=([^>]+))?>$/,c=/^<\/([a-z]+)>$/,h=[["ContextStart",/^<[a-z]+(=[^>]+)?>/],["Text",/^[^</>=]+/],["ContextEnd",/^<\/[a-z]+>/]],f=function(t,e,n){if(void 0===e&&(e=[]),void 0===n&&(n=0),!t)return e;for(var r,i=l(h);!(r=i()).done;){var o,a=r.value,s=a[0],u=(null!=(o=a[1].exec(t))?o:[])[0];if(u){var c=u.length;return f(t.slice(c),e.concat({tokenType:s,value:u}),n+c)}}throw new Error('Unexpected token: "'+t[0]+'" at position '+n+' while reading "'+t+'"')},p=function(t){var e=function(){var t=s();if("Text"===(null==t?void 0:t.tokenType))return a(),t.value},n=function(){var t=s();if("ContextStart"===(null==t?void 0:t.tokenType)){a();var e,n=t.value.match(u);if(n)return{attributeName:n[1],attributeParam:null!=(e=n[3])?e:""};throw new Error("Expected a start tag marker at position "+o)}return{}},r=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{}},i=f(t),o=0,a=function(){var t,e=i.shift();return o+=null!=(t=null==e?void 0:e.value.length)?t:0,e},s=function(){return i[0]},l=[];return function t(i,a){for(void 0===i&&(i=[]),void 0===a&&(a="");;){var s=e();if(s)l.push({attributes:i,text:s});else{var u=n(),c=u.attributeName,h=u.attributeParam;if(!c){if(a){var f=r().attributeName;if(!f)throw new Error('Expect an end tag marker "'+a+'" at position '+o+" but found no tag!");if(f!==a)throw new Error('Expect an end tag marker "'+a+'" at position '+o+' but found tag "'+f+'"');return}break}t(i.concat({attributeName:c,attributeParam:h}),c)}}}(),l};function d(t){return function(e){for(var n,r=l(p(e));!(n=r()).done;){var i=n.value,o=i.text,a=i.attributes.reduce((function(t,e){var n=e.attributeName,r=e.attributeParam;return n&&(t[n]=r),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 n=parseInt(t.slice(6,8),16)/255;t=t.slice(0,6),e=n}var r=parseInt(t,16);return[r>>16&255,r>>8&255,255&r,e]}function x(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"),n=e.getContext("2d");if(n)try{return n.fillStyle=t,n.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 n(t){var n;return(n=e.call(this,t)||this).processedTextOptions=[],n.singleLineHeight=1.571,n.size=null,n.initialized=!1,n.canvasSize=null,n.name="MRichText"+g++,n}i(n,e);var r=n.prototype;return r.generateTextProgram=function(e){var n=this;this.processedTextOptions=[];var r=d((function(e,r){/^\n+$/.test(e)&&(e=e.replace(/\n/g,"\n ")),e.split("\n").forEach((function(e,i){var o={text:e,fontSize:n.textStyle.fontSize,isNewLine:!1};i>0&&(o.isNewLine=!0),"b"in r&&(o.fontWeight=t.spec.TextWeight.bold),"i"in r&&(o.fontStyle=t.spec.FontStyle.italic),"size"in r&&r.size&&(o.fontSize=parseInt(r.size,10)),"color"in r&&r.color&&(o.fontColor=x(r.color)),n.processedTextOptions.push(o)}))}));r(e)},r.updateTexture=function(e){var n=this;if(void 0===e&&(e=!0),this.isDirty&&this.context&&this.canvas){this.generateTextProgram(this.text);var r=0,i=0,o=this.textLayout,a=this.textStyle,s=o.overflow,l=o.letterSpace,u=void 0===l?0:l,c=this.context;c.save();var h=[],f=a.fontSize*this.textStyle.fontScale,p={richOptions:[],offsetX:[],width:0,lineHeight:f*this.singleLineHeight,offsetY:f*(this.singleLineHeight-1)/2};if(this.processedTextOptions.forEach((function(t){var e=t.text,o=t.isNewLine,s=t.fontSize;o&&(h.push(p),r=Math.max(r,p.width),p={richOptions:[],offsetX:[],width:0,lineHeight:f*n.singleLineHeight,offsetY:f*(n.singleLineHeight-1)/2},i+=p.lineHeight),c.font=(t.fontWeight||a.textWeight)+" 10px "+(t.fontFamily||a.fontFamily);var l=c.measureText(e),d=l.width;if(void 0!==l.actualBoundingBoxLeft&&void 0!==l.actualBoundingBoxRight){var v=l.actualBoundingBoxLeft+l.actualBoundingBoxRight;v>0&&(d=Math.max(d,v))}var x=s*n.singleLineHeight*n.textStyle.fontScale;x>p.lineHeight&&(i+=x-p.lineHeight,p.lineHeight=x,p.offsetY=s*n.textStyle.fontScale*(n.singleLineHeight-1)/2),p.offsetX.push(p.width),p.width+=(d<=0?0:d)*s*n.SCALE_FACTOR*n.textStyle.fontScale+e.length*u,p.richOptions.push(t)})),h.push(p),r=Math.max(r,p.width),i+=p.lineHeight,0!==r&&0!==i){void 0!==this.size&&null!==this.size||(this.size=this.item.transform.size.clone());var d=this.size,v=d.x,x=void 0===v?1:v,g=d.y,y=void 0===g?1:g;if(!this.initialized){this.canvasSize=this.canvasSize?this.canvasSize:new t.math.Vector2(r,i);var m=this.canvasSize,w=m.x,S=m.y;this.item.transform.size.set(x*w*this.SCALE_FACTOR*this.SCALE_FACTOR,y*S*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,b=T.y;if(this.textLayout.width=E/a.fontScale,this.textLayout.height=b/a.fontScale,this.canvas.width=E,this.canvas.height=b,c.clearRect(0,0,E,b),c.fillStyle="rgba(255, 255, 255, "+this.ALPHA_FIX_VALUE+")",e||(c.translate(0,b),c.scale(1,-1)),0!==h.length){var C=o.getOffsetY(a,h.length,f*this.singleLineHeight,a.fontSize);h.forEach((function(e,r){var i=e.richOptions,o=e.offsetX,l=e.width,u=l,h=o;if(s===t.spec.TextOverflow.display&&l>E){var f=E/l;u*=f,h=o.map((function(t){return t*f}))}var p=n.textLayout.getOffsetX(a,u);r>0&&(C+=e.lineHeight-e.offsetY),i.forEach((function(e,n){var r=a.fontScale,i=a.textColor,o=a.fontFamily,u=a.textWeight,f=a.fontStyle,d=e.text,v=e.fontSize,x=e.fontColor,g=void 0===x?i:x,y=e.fontFamily,m=void 0===y?o:y,w=e.fontWeight,S=void 0===w?u:w,T=e.fontStyle,b=void 0===T?f:T,O=v;s===t.spec.TextOverflow.display&&l>E&&(O/=l/E);var z=h[n]+p;c.font=b+" "+S+" "+O*r+"px "+m,c.fillStyle="rgba("+g[0]+", "+g[1]+", "+g[2]+", "+g[3]+")",c.fillText(d,z,C)}))}));var O=c.getImageData(0,0,this.canvas.width,this.canvas.height),z=t.Texture.createWithData(this.engine,{data:new Uint8Array(O.data),width:O.width,height:O.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=z,this.material.setTexture("_MainTex",z),this.isDirty=!1,c.restore()}}else this.isDirty=!1}},r.setShadowOffsetY=function(t){throw new Error("Method not implemented.")},r.setShadowBlur=function(t){throw new Error("Method not implemented.")},r.setShadowOffsetX=function(t){throw new Error("Method not implemented.")},r.setShadowColor=function(t){throw new Error("Method not implemented.")},r.setOutlineWidth=function(t){throw new Error("Method not implemented.")},r.setAutoWidth=function(t){throw new Error("Method not implemented.")},r.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():" "},r.renderText=function(e){var n=e.size;n&&(this.canvasSize=new t.math.Vector2(n[0],n[1])),this.updateTexture()},n}(t.TextComponent),exports.RichTextComponent=function(t,e,n,r){var i,o=arguments.length,a=o<3?e:null===r?r=Object.getOwnPropertyDescriptor(e,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(t,e,n,r);else for(var s=t.length-1;s>=0;s--)(i=t[s])&&(a=(o<3?i(a):o>3?i(e,n,a):i(e,n))||a);return o>3&&a&&Object.defineProperty(e,n,a),a}([t.effectsClass(t.spec.DataType.RichTextComponent)],exports.RichTextComponent);var y="2.5.6";t.registerPlugin("rich-text",a,t.VFXItem),t.logger.info("Plugin rich text version: 2.5.6."),y!==n.version&&console.error("注意:请统一 RichText 插件与 Player 版本,不统一的版本混用会有不可预知的后果!","\nAttention: Please ensure the RichText plugin is synchronized with the Player version. Mixing and matching incompatible versions may result in unpredictable consequences!"),exports.RichTextLoader=a,exports.generateProgram=d,exports.isRichText=function(t){var e=f(t).filter((function(t){var e=t.tokenType;return"ContextStart"===e||"ContextEnd"===e})),n=e.filter((function(t){return"ContextStart"===t.tokenType})),r=e.filter((function(t){return"ContextEnd"===t.tokenType}));return!(n.length!==r.length||!n.length)&&function t(e,n){var r=e[0],i=e.slice(1);if(void 0===n&&(n=[]),!r)return 0===n.length;if("ContextStart"===r.tokenType)return t(i,n.concat(r.value));if("ContextEnd"===r.tokenType)return n[n.length-1]===r.value&&t(i,n.slice(0,-1));throw new Error("Unexpected token: "+r.tokenType)}(e.map((function(t){var e=t.tokenType,n=t.value;return{tokenType:e,value:"ContextStart"===e?n.match(u)[1]:n.match(c)[1]}})))},exports.lexer=f,exports.richTextParser=p,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 n,spec as i,math as r,assertExist as o,Texture as a,glContext as s,TextStyle as l,TextLayout as h,TextComponent as f,registerPlugin as u,VFXItem as c,logger as d}from"@galacean/effects/douyin";function v(t,e){return v=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},v(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&&v(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 n=0,i=new Array(e);n<e;n++)i[n]=t[n];return i}function m(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(n)return(n=n.call(t)).next.bind(n);if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return y(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(n):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?y(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var i=0;return function(){return i>=t.length?{done:!0}:{done:!1,value:t[i++]}}}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"}(x||(x={}));var w=/^<([a-z]+)(=([^>]+))?>$/,S=/^<\/([a-z]+)>$/,T=[["ContextStart",/^<[a-z]+(=[^>]+)?>/],["Text",/^[^</>=]+/],["ContextEnd",/^<\/[a-z]+>/]],E=function(t,e,n){if(void 0===e&&(e=[]),void 0===n&&(n=0),!t)return e;for(var i,r=m(T);!(i=r()).done;){var o,a=i.value,s=a[0],l=(null!=(o=a[1].exec(t))?o:[])[0];if(l){var h=l.length;return E(t.slice(h),e.concat({tokenType:s,value:l}),n+h)}}throw new Error('Unexpected token: "'+t[0]+'" at position '+n+' while reading "'+t+'"')},b=function(t){var e=function(){var t=s();if("Text"===(null==t?void 0:t.tokenType))return a(),t.value},n=function(){var t=s();if("ContextStart"===(null==t?void 0:t.tokenType)){a();var e,n=t.value.match(w);if(n)return{attributeName:n[1],attributeParam:null!=(e=n[3])?e:""};throw new Error("Expected a start tag marker at position "+o)}return{}},i=function(){var t=s();if("ContextEnd"===(null==t?void 0:t.tokenType)){a();var e=t.value.match(S);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]},l=[];return function t(r,a){for(void 0===r&&(r=[]),void 0===a&&(a="");;){var s=e();if(s)l.push({attributes:r,text:s});else{var h=n(),f=h.attributeName,u=h.attributeParam;if(!f){if(a){var c=i().attributeName;if(!c)throw new Error('Expect an end tag marker "'+a+'" at position '+o+" but found no tag!");if(c!==a)throw new Error('Expect an end tag marker "'+a+'" at position '+o+' but found tag "'+c+'"');return}break}t(r.concat({attributeName:f,attributeParam:u}),f)}}}(),l};function z(t){return function(e){for(var n,i=m(b(e));!(n=i()).done;){var r=n.value,o=r.text,a=r.attributes.reduce((function(t,e){var n=e.attributeName,i=e.attributeParam;return n&&(t[n]=i),t}),{});t(o,a)}}}function C(t){var e=E(t).filter((function(t){var e=t.tokenType;return"ContextStart"===e||"ContextEnd"===e})),n=e.filter((function(t){return"ContextStart"===t.tokenType})),i=e.filter((function(t){return"ContextEnd"===t.tokenType}));if(n.length!==i.length||!n.length)return!1;return function t(e,n){var i=e[0],r=e.slice(1);if(void 0===n&&(n=[]),!i)return 0===n.length;if("ContextStart"===i.tokenType)return t(r,n.concat(i.value));if("ContextEnd"===i.tokenType)return n[n.length-1]===i.value&&t(r,n.slice(0,-1));throw new Error("Unexpected token: "+i.tokenType)}(e.map((function(t){var e=t.tokenType,n=t.value;return{tokenType:e,value:"ContextStart"===e?n.match(w)[1]:n.match(S)[1]}})))}function O(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 n=parseInt(t.slice(6,8),16)/255;t=t.slice(0,6),e=n}var i=parseInt(t,16);return[i>>16&255,i>>8&255,255&i,e]}function L(t,e){if(void 0===e&&(e=1),"string"!=typeof t||!t)throw new Error("Invalid color string");return t.startsWith("#")?O(t,e):O(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"),n=e.getContext("2d");if(n)try{return n.fillStyle=t,n.fillStyle}finally{e.remove()}throw new Error("Failed to get 2D context for color conversion!")}(t))}"function"==typeof SuppressedError&&SuppressedError;var A=0,k=function(t){function e(e){var n;return(n=t.call(this,e)||this).processedTextOptions=[],n.singleLineHeight=1.571,n.size=null,n.initialized=!1,n.canvasSize=null,n.name="MRichText"+A++,n}p(e,t);var n=e.prototype;return n.generateTextProgram=function(t){var e=this;this.processedTextOptions=[];var n=z((function(t,n){/^\n+$/.test(t)&&(t=t.replace(/\n/g,"\n ")),t.split("\n").forEach((function(t,r){var o={text:t,fontSize:e.textStyle.fontSize,isNewLine:!1};r>0&&(o.isNewLine=!0),"b"in n&&(o.fontWeight=i.TextWeight.bold),"i"in n&&(o.fontStyle=i.FontStyle.italic),"size"in n&&n.size&&(o.fontSize=parseInt(n.size,10)),"color"in n&&n.color&&(o.fontColor=L(n.color)),e.processedTextOptions.push(o)}))}));n(t)},n.updateTexture=function(t){var e=this;if(void 0===t&&(t=!0),this.isDirty&&this.context&&this.canvas){this.generateTextProgram(this.text);var n=0,l=0,h=this.textLayout,f=this.textStyle,u=h.overflow,c=h.letterSpace,d=void 0===c?0:c,v=this.context;v.save();var p=[],x=f.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,r=t.isNewLine,o=t.fontSize;r&&(p.push(g),n=Math.max(n,g.width),g={richOptions:[],offsetX:[],width:0,lineHeight:x*e.singleLineHeight,offsetY:x*(e.singleLineHeight-1)/2},l+=g.lineHeight),v.font=(t.fontWeight||f.textWeight)+" 10px "+(t.fontFamily||f.fontFamily);var a=v.measureText(i),s=a.width;if(void 0!==a.actualBoundingBoxLeft&&void 0!==a.actualBoundingBoxRight){var h=a.actualBoundingBoxLeft+a.actualBoundingBoxRight;h>0&&(s=Math.max(s,h))}var u=o*e.singleLineHeight*e.textStyle.fontScale;u>g.lineHeight&&(l+=u-g.lineHeight,g.lineHeight=u,g.offsetY=o*e.textStyle.fontScale*(e.singleLineHeight-1)/2),g.offsetX.push(g.width),g.width+=(s<=0?0:s)*o*e.SCALE_FACTOR*e.textStyle.fontScale+i.length*d,g.richOptions.push(t)})),p.push(g),n=Math.max(n,g.width),l+=g.lineHeight,0!==n&&0!==l){void 0!==this.size&&null!==this.size||(this.size=this.item.transform.size.clone());var y=this.size,m=y.x,w=void 0===m?1:m,S=y.y,T=void 0===S?1:S;if(!this.initialized){this.canvasSize=this.canvasSize?this.canvasSize:new r.Vector2(n,l);var E=this.canvasSize,b=E.x,z=E.y;this.item.transform.size.set(w*b*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,L=C.y;if(this.textLayout.width=O/f.fontScale,this.textLayout.height=L/f.fontScale,this.canvas.width=O,this.canvas.height=L,v.clearRect(0,0,O,L),v.fillStyle="rgba(255, 255, 255, "+this.ALPHA_FIX_VALUE+")",t||(v.translate(0,L),v.scale(1,-1)),0!==p.length){var A=h.getOffsetY(f,p.length,x*this.singleLineHeight,f.fontSize);p.forEach((function(t,n){var r=t.richOptions,o=t.offsetX,a=t.width,s=a,l=o;if(u===i.TextOverflow.display&&a>O){var h=O/a;s*=h,l=o.map((function(t){return t*h}))}var c=e.textLayout.getOffsetX(f,s);n>0&&(A+=t.lineHeight-t.offsetY),r.forEach((function(t,e){var n=f.fontScale,r=f.textColor,o=f.fontFamily,s=f.textWeight,h=f.fontStyle,d=t.text,p=t.fontSize,x=t.fontColor,g=void 0===x?r:x,y=t.fontFamily,m=void 0===y?o:y,w=t.fontWeight,S=void 0===w?s:w,T=t.fontStyle,E=void 0===T?h:T,b=p;u===i.TextOverflow.display&&a>O&&(b/=a/O);var z=l[e]+c;v.font=E+" "+S+" "+b*n+"px "+m,v.fillStyle="rgba("+g[0]+", "+g[1]+", "+g[2]+", "+g[3]+")",v.fillText(d,z,A)}))}));var k=v.getImageData(0,0,this.canvas.width,this.canvas.height),H=a.createWithData(this.engine,{data:new Uint8Array(k.data),width:k.width,height:k.height},{flipY:t,magFilter:s.LINEAR,minFilter:s.LINEAR,wrapS:s.CLAMP_TO_EDGE,wrapT:s.CLAMP_TO_EDGE});this.renderer.texture=H,this.material.setTexture("_MainTex",H),this.isDirty=!1,v.restore()}}else this.isDirty=!1}},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(t){this.textStyle=new l(t),this.textLayout=new h(t),this.textLayout.textBaseline=t.textBaseline||i.TextBaseline.middle,this.text=t.text?t.text.toString():" "},n.renderText=function(t){var e=t.size;e&&(this.canvasSize=new r.Vector2(e[0],e[1])),this.updateTexture()},e}(f);k=function(t,e,n,i){var r,o=arguments.length,a=o<3?e:null===i?i=Object.getOwnPropertyDescriptor(e,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(t,e,n,i);else for(var s=t.length-1;s>=0;s--)(r=t[s])&&(a=(o<3?r(a):o>3?r(e,n,a):r(e,n))||a);return o>3&&a&&Object.defineProperty(e,n,a),a}([n(i.DataType.RichTextComponent)],k);var H="2.5.5";u("rich-text",g,c),d.info("Plugin rich text version: 2.5.5."),H!==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{k as RichTextComponent,g as RichTextLoader,z as generateProgram,C as isRichText,E as lexer,b as richTextParser,H as version};
1
+ import*as t from"@galacean/effects/douyin";import{AbstractPlugin as e,effectsClass as n,spec as i,math as r,assertExist as o,Texture as a,glContext as s,TextStyle as l,TextLayout as h,TextComponent as f,registerPlugin as u,VFXItem as c,logger as d}from"@galacean/effects/douyin";function v(t,e){return v=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},v(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&&v(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 n=0,i=new Array(e);n<e;n++)i[n]=t[n];return i}function m(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(n)return(n=n.call(t)).next.bind(n);if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return y(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(n):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?y(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var i=0;return function(){return i>=t.length?{done:!0}:{done:!1,value:t[i++]}}}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"}(x||(x={}));var w=/^<([a-z]+)(=([^>]+))?>$/,S=/^<\/([a-z]+)>$/,T=[["ContextStart",/^<[a-z]+(=[^>]+)?>/],["Text",/^[^</>=]+/],["ContextEnd",/^<\/[a-z]+>/]],E=function(t,e,n){if(void 0===e&&(e=[]),void 0===n&&(n=0),!t)return e;for(var i,r=m(T);!(i=r()).done;){var o,a=i.value,s=a[0],l=(null!=(o=a[1].exec(t))?o:[])[0];if(l){var h=l.length;return E(t.slice(h),e.concat({tokenType:s,value:l}),n+h)}}throw new Error('Unexpected token: "'+t[0]+'" at position '+n+' while reading "'+t+'"')},b=function(t){var e=function(){var t=s();if("Text"===(null==t?void 0:t.tokenType))return a(),t.value},n=function(){var t=s();if("ContextStart"===(null==t?void 0:t.tokenType)){a();var e,n=t.value.match(w);if(n)return{attributeName:n[1],attributeParam:null!=(e=n[3])?e:""};throw new Error("Expected a start tag marker at position "+o)}return{}},i=function(){var t=s();if("ContextEnd"===(null==t?void 0:t.tokenType)){a();var e=t.value.match(S);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]},l=[];return function t(r,a){for(void 0===r&&(r=[]),void 0===a&&(a="");;){var s=e();if(s)l.push({attributes:r,text:s});else{var h=n(),f=h.attributeName,u=h.attributeParam;if(!f){if(a){var c=i().attributeName;if(!c)throw new Error('Expect an end tag marker "'+a+'" at position '+o+" but found no tag!");if(c!==a)throw new Error('Expect an end tag marker "'+a+'" at position '+o+' but found tag "'+c+'"');return}break}t(r.concat({attributeName:f,attributeParam:u}),f)}}}(),l};function z(t){return function(e){for(var n,i=m(b(e));!(n=i()).done;){var r=n.value,o=r.text,a=r.attributes.reduce((function(t,e){var n=e.attributeName,i=e.attributeParam;return n&&(t[n]=i),t}),{});t(o,a)}}}function C(t){var e=E(t).filter((function(t){var e=t.tokenType;return"ContextStart"===e||"ContextEnd"===e})),n=e.filter((function(t){return"ContextStart"===t.tokenType})),i=e.filter((function(t){return"ContextEnd"===t.tokenType}));if(n.length!==i.length||!n.length)return!1;return function t(e,n){var i=e[0],r=e.slice(1);if(void 0===n&&(n=[]),!i)return 0===n.length;if("ContextStart"===i.tokenType)return t(r,n.concat(i.value));if("ContextEnd"===i.tokenType)return n[n.length-1]===i.value&&t(r,n.slice(0,-1));throw new Error("Unexpected token: "+i.tokenType)}(e.map((function(t){var e=t.tokenType,n=t.value;return{tokenType:e,value:"ContextStart"===e?n.match(w)[1]:n.match(S)[1]}})))}function O(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 n=parseInt(t.slice(6,8),16)/255;t=t.slice(0,6),e=n}var i=parseInt(t,16);return[i>>16&255,i>>8&255,255&i,e]}function L(t,e){if(void 0===e&&(e=1),"string"!=typeof t||!t)throw new Error("Invalid color string");return t.startsWith("#")?O(t,e):O(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"),n=e.getContext("2d");if(n)try{return n.fillStyle=t,n.fillStyle}finally{e.remove()}throw new Error("Failed to get 2D context for color conversion!")}(t))}"function"==typeof SuppressedError&&SuppressedError;var A=0,k=function(t){function e(e){var n;return(n=t.call(this,e)||this).processedTextOptions=[],n.singleLineHeight=1.571,n.size=null,n.initialized=!1,n.canvasSize=null,n.name="MRichText"+A++,n}p(e,t);var n=e.prototype;return n.generateTextProgram=function(t){var e=this;this.processedTextOptions=[];var n=z((function(t,n){/^\n+$/.test(t)&&(t=t.replace(/\n/g,"\n ")),t.split("\n").forEach((function(t,r){var o={text:t,fontSize:e.textStyle.fontSize,isNewLine:!1};r>0&&(o.isNewLine=!0),"b"in n&&(o.fontWeight=i.TextWeight.bold),"i"in n&&(o.fontStyle=i.FontStyle.italic),"size"in n&&n.size&&(o.fontSize=parseInt(n.size,10)),"color"in n&&n.color&&(o.fontColor=L(n.color)),e.processedTextOptions.push(o)}))}));n(t)},n.updateTexture=function(t){var e=this;if(void 0===t&&(t=!0),this.isDirty&&this.context&&this.canvas){this.generateTextProgram(this.text);var n=0,l=0,h=this.textLayout,f=this.textStyle,u=h.overflow,c=h.letterSpace,d=void 0===c?0:c,v=this.context;v.save();var p=[],x=f.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,r=t.isNewLine,o=t.fontSize;r&&(p.push(g),n=Math.max(n,g.width),g={richOptions:[],offsetX:[],width:0,lineHeight:x*e.singleLineHeight,offsetY:x*(e.singleLineHeight-1)/2},l+=g.lineHeight),v.font=(t.fontWeight||f.textWeight)+" 10px "+(t.fontFamily||f.fontFamily);var a=v.measureText(i),s=a.width;if(void 0!==a.actualBoundingBoxLeft&&void 0!==a.actualBoundingBoxRight){var h=a.actualBoundingBoxLeft+a.actualBoundingBoxRight;h>0&&(s=Math.max(s,h))}var u=o*e.singleLineHeight*e.textStyle.fontScale;u>g.lineHeight&&(l+=u-g.lineHeight,g.lineHeight=u,g.offsetY=o*e.textStyle.fontScale*(e.singleLineHeight-1)/2),g.offsetX.push(g.width),g.width+=(s<=0?0:s)*o*e.SCALE_FACTOR*e.textStyle.fontScale+i.length*d,g.richOptions.push(t)})),p.push(g),n=Math.max(n,g.width),l+=g.lineHeight,0!==n&&0!==l){void 0!==this.size&&null!==this.size||(this.size=this.item.transform.size.clone());var y=this.size,m=y.x,w=void 0===m?1:m,S=y.y,T=void 0===S?1:S;if(!this.initialized){this.canvasSize=this.canvasSize?this.canvasSize:new r.Vector2(n,l);var E=this.canvasSize,b=E.x,z=E.y;this.item.transform.size.set(w*b*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,L=C.y;if(this.textLayout.width=O/f.fontScale,this.textLayout.height=L/f.fontScale,this.canvas.width=O,this.canvas.height=L,v.clearRect(0,0,O,L),v.fillStyle="rgba(255, 255, 255, "+this.ALPHA_FIX_VALUE+")",t||(v.translate(0,L),v.scale(1,-1)),0!==p.length){var A=h.getOffsetY(f,p.length,x*this.singleLineHeight,f.fontSize);p.forEach((function(t,n){var r=t.richOptions,o=t.offsetX,a=t.width,s=a,l=o;if(u===i.TextOverflow.display&&a>O){var h=O/a;s*=h,l=o.map((function(t){return t*h}))}var c=e.textLayout.getOffsetX(f,s);n>0&&(A+=t.lineHeight-t.offsetY),r.forEach((function(t,e){var n=f.fontScale,r=f.textColor,o=f.fontFamily,s=f.textWeight,h=f.fontStyle,d=t.text,p=t.fontSize,x=t.fontColor,g=void 0===x?r:x,y=t.fontFamily,m=void 0===y?o:y,w=t.fontWeight,S=void 0===w?s:w,T=t.fontStyle,E=void 0===T?h:T,b=p;u===i.TextOverflow.display&&a>O&&(b/=a/O);var z=l[e]+c;v.font=E+" "+S+" "+b*n+"px "+m,v.fillStyle="rgba("+g[0]+", "+g[1]+", "+g[2]+", "+g[3]+")",v.fillText(d,z,A)}))}));var k=v.getImageData(0,0,this.canvas.width,this.canvas.height),H=a.createWithData(this.engine,{data:new Uint8Array(k.data),width:k.width,height:k.height},{flipY:t,magFilter:s.LINEAR,minFilter:s.LINEAR,wrapS:s.CLAMP_TO_EDGE,wrapT:s.CLAMP_TO_EDGE});this.renderer.texture=H,this.material.setTexture("_MainTex",H),this.isDirty=!1,v.restore()}}else this.isDirty=!1}},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(t){this.textStyle=new l(t),this.textLayout=new h(t),this.textLayout.textBaseline=t.textBaseline||i.TextBaseline.middle,this.text=t.text?t.text.toString():" "},n.renderText=function(t){var e=t.size;e&&(this.canvasSize=new r.Vector2(e[0],e[1])),this.updateTexture()},e}(f);k=function(t,e,n,i){var r,o=arguments.length,a=o<3?e:null===i?i=Object.getOwnPropertyDescriptor(e,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(t,e,n,i);else for(var s=t.length-1;s>=0;s--)(r=t[s])&&(a=(o<3?r(a):o>3?r(e,n,a):r(e,n))||a);return o>3&&a&&Object.defineProperty(e,n,a),a}([n(i.DataType.RichTextComponent)],k);var H="2.5.6";u("rich-text",g,c),d.info("Plugin rich text version: 2.5.6."),H!==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{k as RichTextComponent,g as RichTextLoader,z as generateProgram,C as isRichText,E as lexer,b as richTextParser,H 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.5.5
6
+ * Version: v2.5.6
7
7
  */
8
8
 
9
9
  'use strict';
@@ -642,7 +642,7 @@ exports.RichTextComponent = __decorate([
642
642
 
643
643
  /**
644
644
  * 插件版本号
645
- */ var version = "2.5.5";
645
+ */ var version = "2.5.6";
646
646
  EFFECTS.registerPlugin("rich-text", RichTextLoader, EFFECTS.VFXItem);
647
647
  EFFECTS.logger.info("Plugin rich text version: " + version + ".");
648
648
  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.5.5
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 n,i,r=function(t){if(t&&t.__esModule)return t;var e=Object.create(null);return t&&Object.keys(t).forEach(function(n){if("default"!==n){var i=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,i.get?i:{enumerable:!0,get:function(){return t[n]}})}}),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 l(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,i=Array(e);n<e;n++)i[n]=t[n];return i}function f(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(n)return(n=n.call(t)).next.bind(n);if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return l(t,void 0);var n=Object.prototype.toString.call(t).slice(8,-1);if("Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return l(t,void 0)}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var i=0;return function(){return i>=t.length?{done:!0}:{done:!1,value:t[i++]}}}throw TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(n=i||(i={})).ContextStart="ContextStart",n.Text="Text",n.ContextEnd="ContextEnd";var u=/^<([a-z]+)(=([^>]+))?>$/,c=/^<\/([a-z]+)>$/,h=[["ContextStart",/^<[a-z]+(=[^>]+)?>/],["Text",/^[^</>=]+/],["ContextEnd",/^<\/[a-z]+>/]],d=function(t,e,n){if(void 0===e&&(e=[]),void 0===n&&(n=0),!t)return e;for(var i,r=f(h);!(i=r()).done;){var o,a=i.value,s=a[0],l=(null!=(o=a[1].exec(t))?o:[])[0];if(l){var u=l.length;return d(t.slice(u),e.concat({tokenType:s,value:l}),n+u)}}throw Error('Unexpected token: "'+t[0]+'" at position '+n+' while reading "'+t+'"')},p=function(t){var e=function(){var t=s();if((null==t?void 0:t.tokenType)==="Text")return a(),t.value},n=function(){var t=s();if((null==t?void 0:t.tokenType)==="ContextStart"){a();var e,n=t.value.match(u);if(n)return{attributeName:n[1],attributeParam:null!=(e=n[3])?e:""};throw Error("Expected a start tag marker at position "+o)}return{}},i=function(){var t=s();if((null==t?void 0:t.tokenType)==="ContextEnd"){a();var e=t.value.match(c);if(e)return{attributeName:e[1]};throw Error("Expect an end tag marker at position "+o)}return{}},r=d(t),o=0,a=function(){var t,e=r.shift();return o+=null!=(t=null==e?void 0:e.value.length)?t:0,e},s=function(){return r[0]},l=[];return!function t(r,a){for(void 0===r&&(r=[]),void 0===a&&(a="");;){var s=e();if(s){l.push({attributes:r,text:s});continue}var f=n(),u=f.attributeName,c=f.attributeParam;if(u){t(r.concat({attributeName:u,attributeParam:c}),u);continue}if(a){var h=i().attributeName;if(!h)throw Error('Expect an end tag marker "'+a+'" at position '+o+" but found no tag!");if(h!==a)throw Error('Expect an end tag marker "'+a+'" at position '+o+' but found tag "'+h+'"');return}break}}(),l};function v(t){return function(e){for(var n,i=p(e),r=f(i);!(n=r()).done;){var o=n.value;t(o.text,o.attributes.reduce(function(t,e){var n=e.attributeName,i=e.attributeParam;return n&&(t[n]=i),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 n=parseInt(t.slice(6,8),16)/255;t=t.slice(0,6),e=n}var i=parseInt(t,16);return[i>>16&255,i>>8&255,255&i,e]}"function"==typeof SuppressedError&&SuppressedError;var x=0;t.RichTextComponent=function(t){function n(e){var n;return(n=t.call(this,e)||this).processedTextOptions=[],n.singleLineHeight=1.571,n.size=null,n.initialized=!1,n.canvasSize=null,n.name="MRichText"+x++,n}a(n,t);var i=n.prototype;return i.generateTextProgram=function(t){var n=this;this.processedTextOptions=[],v(function(t,i){/^\n+$/.test(t)&&(t=t.replace(/\n/g,"\n ")),t.split("\n").forEach(function(t,r){var o={text:t,fontSize:n.textStyle.fontSize,isNewLine:!1};r>0&&(o.isNewLine=!0),"b"in i&&(o.fontWeight=e.spec.TextWeight.bold),"i"in i&&(o.fontStyle=e.spec.FontStyle.italic),"size"in i&&i.size&&(o.fontSize=parseInt(i.size,10)),"color"in i&&i.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"),n=e.getContext("2d");if(n)try{return n.fillStyle=t,n.fillStyle}finally{e.remove()}throw Error("Failed to get 2D context for color conversion!")}(t))}(i.color)),n.processedTextOptions.push(o)})})(t)},i.updateTexture=function(t){var n=this;if(void 0===t&&(t=!0),this.isDirty&&this.context&&this.canvas){this.generateTextProgram(this.text);var i=0,r=0,o=this.textLayout,a=this.textStyle,s=o.overflow,l=o.letterSpace,f=void 0===l?0:l,u=this.context;u.save();var c=[],h=a.fontSize*this.textStyle.fontScale,d={richOptions:[],offsetX:[],width:0,lineHeight:h*this.singleLineHeight,offsetY:h*(this.singleLineHeight-1)/2};if(this.processedTextOptions.forEach(function(t){var e=t.text,o=t.isNewLine,s=t.fontSize;o&&(c.push(d),i=Math.max(i,d.width),d={richOptions:[],offsetX:[],width:0,lineHeight:h*n.singleLineHeight,offsetY:h*(n.singleLineHeight-1)/2},r+=d.lineHeight),u.font=(t.fontWeight||a.textWeight)+" 10px "+(t.fontFamily||a.fontFamily);var l=u.measureText(e),p=l.width;if(void 0!==l.actualBoundingBoxLeft&&void 0!==l.actualBoundingBoxRight){var v=l.actualBoundingBoxLeft+l.actualBoundingBoxRight;v>0&&(p=Math.max(p,v))}var g=s*n.singleLineHeight*n.textStyle.fontScale;g>d.lineHeight&&(r+=g-d.lineHeight,d.lineHeight=g,d.offsetY=s*n.textStyle.fontScale*(n.singleLineHeight-1)/2),d.offsetX.push(d.width),d.width+=(p<=0?0:p)*s*n.SCALE_FACTOR*n.textStyle.fontScale+e.length*f,d.richOptions.push(t)}),c.push(d),i=Math.max(i,d.width),r+=d.lineHeight,0===i||0===r){this.isDirty=!1;return}(void 0===this.size||null===this.size)&&(this.size=this.item.transform.size.clone());var p=this.size,v=p.x,g=p.y;if(!this.initialized){this.canvasSize=this.canvasSize?this.canvasSize:new e.math.Vector2(i,r);var x=this.canvasSize,y=x.x,m=x.y;this.item.transform.size.set((void 0===v?1:v)*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/a.fontScale,this.textLayout.height=w/a.fontScale,this.canvas.width=T,this.canvas.height=w,u.clearRect(0,0,T,w),u.fillStyle="rgba(255, 255, 255, "+this.ALPHA_FIX_VALUE+")",t||(u.translate(0,w),u.scale(1,-1)),0!==c.length){var b=o.getOffsetY(a,c.length,h*this.singleLineHeight,a.fontSize);c.forEach(function(t,i){var r=t.richOptions,o=t.offsetX,l=t.width,f=l,c=o;if(s===e.spec.TextOverflow.display&&l>T){var h=T/l;f*=h,c=o.map(function(t){return t*h})}var d=n.textLayout.getOffsetX(a,f);i>0&&(b+=t.lineHeight-t.offsetY),r.forEach(function(t,n){var i=a.fontScale,r=a.textColor,o=a.fontFamily,f=a.textWeight,h=a.fontStyle,p=t.text,v=t.fontSize,g=t.fontColor,x=void 0===g?r:g,y=t.fontFamily,m=t.fontWeight,S=t.fontStyle,w=v;s===e.spec.TextOverflow.display&&l>T&&(w/=l/T);var E=c[n]+d;u.font=(void 0===S?h:S)+" "+(void 0===m?f:m)+" "+w*i+"px "+(void 0===y?o:y),u.fillStyle="rgba("+x[0]+", "+x[1]+", "+x[2]+", "+x[3]+")",u.fillText(p,E,b)})});var E=u.getImageData(0,0,this.canvas.width,this.canvas.height),C=e.Texture.createWithData(this.engine,{data:new Uint8Array(E.data),width:E.width,height:E.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=C,this.material.setTexture("_MainTex",C),this.isDirty=!1,u.restore()}}},i.setShadowOffsetY=function(t){throw Error("Method not implemented.")},i.setShadowBlur=function(t){throw Error("Method not implemented.")},i.setShadowOffsetX=function(t){throw Error("Method not implemented.")},i.setShadowColor=function(t){throw Error("Method not implemented.")},i.setOutlineWidth=function(t){throw Error("Method not implemented.")},i.setAutoWidth=function(t){throw Error("Method not implemented.")},i.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():" "},i.renderText=function(t){var n=t.size;n&&(this.canvasSize=new e.math.Vector2(n[0],n[1])),this.updateTexture()},n}(e.TextComponent),t.RichTextComponent=function(t,e,n,i){var r,o=arguments.length,a=o<3?e:null===i?i=Object.getOwnPropertyDescriptor(e,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(t,e,n,i);else for(var s=t.length-1;s>=0;s--)(r=t[s])&&(a=(o<3?r(a):o>3?r(e,n,a):r(e,n))||a);return o>3&&a&&Object.defineProperty(e,n,a),a}([e.effectsClass(e.spec.DataType.RichTextComponent)],t.RichTextComponent);var y="2.5.5";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.generateProgram=v,t.isRichText=function(t){var e=d(t).filter(function(t){var e=t.tokenType;return"ContextStart"===e||"ContextEnd"===e}),n=e.filter(function(t){return"ContextStart"===t.tokenType}),i=e.filter(function(t){return"ContextEnd"===t.tokenType});return n.length===i.length&&!!n.length&&function t(e,n){var i=e[0],r=e.slice(1);if(void 0===n&&(n=[]),!i)return 0===n.length;if("ContextStart"===i.tokenType)return t(r,n.concat(i.value));if("ContextEnd"===i.tokenType)return n[n.length-1]===i.value&&t(r,n.slice(0,-1));throw Error("Unexpected token: "+i.tokenType)}(e.map(function(t){var e=t.tokenType,n=t.value;return{tokenType:e,value:"ContextStart"===e?n.match(u)[1]:n.match(c)[1]}}))},t.lexer=d,t.richTextParser=p,t.version=y,Object.defineProperty(t,"__esModule",{value:!0})});
6
+ * Version: v2.5.6
7
+ */function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@galacean/effects")):"function"==typeof define&&define.amd?define(["exports","@galacean/effects"],e):e(((t="undefined"!=typeof globalThis?globalThis:t||self).ge=t.ge||{},t.ge.richTextPlugin={}),t.ge)}(this,function(t,e){"use strict";var n,i,r=function(t){if(t&&t.__esModule)return t;var e=Object.create(null);return t&&Object.keys(t).forEach(function(n){if("default"!==n){var i=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,i.get?i:{enumerable:!0,get:function(){return t[n]}})}}),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 l(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,i=Array(e);n<e;n++)i[n]=t[n];return i}function f(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(n)return(n=n.call(t)).next.bind(n);if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return l(t,void 0);var n=Object.prototype.toString.call(t).slice(8,-1);if("Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return l(t,void 0)}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var i=0;return function(){return i>=t.length?{done:!0}:{done:!1,value:t[i++]}}}throw TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(n=i||(i={})).ContextStart="ContextStart",n.Text="Text",n.ContextEnd="ContextEnd";var u=/^<([a-z]+)(=([^>]+))?>$/,c=/^<\/([a-z]+)>$/,h=[["ContextStart",/^<[a-z]+(=[^>]+)?>/],["Text",/^[^</>=]+/],["ContextEnd",/^<\/[a-z]+>/]],d=function(t,e,n){if(void 0===e&&(e=[]),void 0===n&&(n=0),!t)return e;for(var i,r=f(h);!(i=r()).done;){var o,a=i.value,s=a[0],l=(null!=(o=a[1].exec(t))?o:[])[0];if(l){var u=l.length;return d(t.slice(u),e.concat({tokenType:s,value:l}),n+u)}}throw Error('Unexpected token: "'+t[0]+'" at position '+n+' while reading "'+t+'"')},p=function(t){var e=function(){var t=s();if((null==t?void 0:t.tokenType)==="Text")return a(),t.value},n=function(){var t=s();if((null==t?void 0:t.tokenType)==="ContextStart"){a();var e,n=t.value.match(u);if(n)return{attributeName:n[1],attributeParam:null!=(e=n[3])?e:""};throw Error("Expected a start tag marker at position "+o)}return{}},i=function(){var t=s();if((null==t?void 0:t.tokenType)==="ContextEnd"){a();var e=t.value.match(c);if(e)return{attributeName:e[1]};throw Error("Expect an end tag marker at position "+o)}return{}},r=d(t),o=0,a=function(){var t,e=r.shift();return o+=null!=(t=null==e?void 0:e.value.length)?t:0,e},s=function(){return r[0]},l=[];return!function t(r,a){for(void 0===r&&(r=[]),void 0===a&&(a="");;){var s=e();if(s){l.push({attributes:r,text:s});continue}var f=n(),u=f.attributeName,c=f.attributeParam;if(u){t(r.concat({attributeName:u,attributeParam:c}),u);continue}if(a){var h=i().attributeName;if(!h)throw Error('Expect an end tag marker "'+a+'" at position '+o+" but found no tag!");if(h!==a)throw Error('Expect an end tag marker "'+a+'" at position '+o+' but found tag "'+h+'"');return}break}}(),l};function v(t){return function(e){for(var n,i=p(e),r=f(i);!(n=r()).done;){var o=n.value;t(o.text,o.attributes.reduce(function(t,e){var n=e.attributeName,i=e.attributeParam;return n&&(t[n]=i),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 n=parseInt(t.slice(6,8),16)/255;t=t.slice(0,6),e=n}var i=parseInt(t,16);return[i>>16&255,i>>8&255,255&i,e]}"function"==typeof SuppressedError&&SuppressedError;var x=0;t.RichTextComponent=function(t){function n(e){var n;return(n=t.call(this,e)||this).processedTextOptions=[],n.singleLineHeight=1.571,n.size=null,n.initialized=!1,n.canvasSize=null,n.name="MRichText"+x++,n}a(n,t);var i=n.prototype;return i.generateTextProgram=function(t){var n=this;this.processedTextOptions=[],v(function(t,i){/^\n+$/.test(t)&&(t=t.replace(/\n/g,"\n ")),t.split("\n").forEach(function(t,r){var o={text:t,fontSize:n.textStyle.fontSize,isNewLine:!1};r>0&&(o.isNewLine=!0),"b"in i&&(o.fontWeight=e.spec.TextWeight.bold),"i"in i&&(o.fontStyle=e.spec.FontStyle.italic),"size"in i&&i.size&&(o.fontSize=parseInt(i.size,10)),"color"in i&&i.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"),n=e.getContext("2d");if(n)try{return n.fillStyle=t,n.fillStyle}finally{e.remove()}throw Error("Failed to get 2D context for color conversion!")}(t))}(i.color)),n.processedTextOptions.push(o)})})(t)},i.updateTexture=function(t){var n=this;if(void 0===t&&(t=!0),this.isDirty&&this.context&&this.canvas){this.generateTextProgram(this.text);var i=0,r=0,o=this.textLayout,a=this.textStyle,s=o.overflow,l=o.letterSpace,f=void 0===l?0:l,u=this.context;u.save();var c=[],h=a.fontSize*this.textStyle.fontScale,d={richOptions:[],offsetX:[],width:0,lineHeight:h*this.singleLineHeight,offsetY:h*(this.singleLineHeight-1)/2};if(this.processedTextOptions.forEach(function(t){var e=t.text,o=t.isNewLine,s=t.fontSize;o&&(c.push(d),i=Math.max(i,d.width),d={richOptions:[],offsetX:[],width:0,lineHeight:h*n.singleLineHeight,offsetY:h*(n.singleLineHeight-1)/2},r+=d.lineHeight),u.font=(t.fontWeight||a.textWeight)+" 10px "+(t.fontFamily||a.fontFamily);var l=u.measureText(e),p=l.width;if(void 0!==l.actualBoundingBoxLeft&&void 0!==l.actualBoundingBoxRight){var v=l.actualBoundingBoxLeft+l.actualBoundingBoxRight;v>0&&(p=Math.max(p,v))}var g=s*n.singleLineHeight*n.textStyle.fontScale;g>d.lineHeight&&(r+=g-d.lineHeight,d.lineHeight=g,d.offsetY=s*n.textStyle.fontScale*(n.singleLineHeight-1)/2),d.offsetX.push(d.width),d.width+=(p<=0?0:p)*s*n.SCALE_FACTOR*n.textStyle.fontScale+e.length*f,d.richOptions.push(t)}),c.push(d),i=Math.max(i,d.width),r+=d.lineHeight,0===i||0===r){this.isDirty=!1;return}(void 0===this.size||null===this.size)&&(this.size=this.item.transform.size.clone());var p=this.size,v=p.x,g=p.y;if(!this.initialized){this.canvasSize=this.canvasSize?this.canvasSize:new e.math.Vector2(i,r);var x=this.canvasSize,y=x.x,m=x.y;this.item.transform.size.set((void 0===v?1:v)*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/a.fontScale,this.textLayout.height=w/a.fontScale,this.canvas.width=T,this.canvas.height=w,u.clearRect(0,0,T,w),u.fillStyle="rgba(255, 255, 255, "+this.ALPHA_FIX_VALUE+")",t||(u.translate(0,w),u.scale(1,-1)),0!==c.length){var b=o.getOffsetY(a,c.length,h*this.singleLineHeight,a.fontSize);c.forEach(function(t,i){var r=t.richOptions,o=t.offsetX,l=t.width,f=l,c=o;if(s===e.spec.TextOverflow.display&&l>T){var h=T/l;f*=h,c=o.map(function(t){return t*h})}var d=n.textLayout.getOffsetX(a,f);i>0&&(b+=t.lineHeight-t.offsetY),r.forEach(function(t,n){var i=a.fontScale,r=a.textColor,o=a.fontFamily,f=a.textWeight,h=a.fontStyle,p=t.text,v=t.fontSize,g=t.fontColor,x=void 0===g?r:g,y=t.fontFamily,m=t.fontWeight,S=t.fontStyle,w=v;s===e.spec.TextOverflow.display&&l>T&&(w/=l/T);var E=c[n]+d;u.font=(void 0===S?h:S)+" "+(void 0===m?f:m)+" "+w*i+"px "+(void 0===y?o:y),u.fillStyle="rgba("+x[0]+", "+x[1]+", "+x[2]+", "+x[3]+")",u.fillText(p,E,b)})});var E=u.getImageData(0,0,this.canvas.width,this.canvas.height),C=e.Texture.createWithData(this.engine,{data:new Uint8Array(E.data),width:E.width,height:E.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=C,this.material.setTexture("_MainTex",C),this.isDirty=!1,u.restore()}}},i.setShadowOffsetY=function(t){throw Error("Method not implemented.")},i.setShadowBlur=function(t){throw Error("Method not implemented.")},i.setShadowOffsetX=function(t){throw Error("Method not implemented.")},i.setShadowColor=function(t){throw Error("Method not implemented.")},i.setOutlineWidth=function(t){throw Error("Method not implemented.")},i.setAutoWidth=function(t){throw Error("Method not implemented.")},i.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():" "},i.renderText=function(t){var n=t.size;n&&(this.canvasSize=new e.math.Vector2(n[0],n[1])),this.updateTexture()},n}(e.TextComponent),t.RichTextComponent=function(t,e,n,i){var r,o=arguments.length,a=o<3?e:null===i?i=Object.getOwnPropertyDescriptor(e,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(t,e,n,i);else for(var s=t.length-1;s>=0;s--)(r=t[s])&&(a=(o<3?r(a):o>3?r(e,n,a):r(e,n))||a);return o>3&&a&&Object.defineProperty(e,n,a),a}([e.effectsClass(e.spec.DataType.RichTextComponent)],t.RichTextComponent);var y="2.5.6";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.generateProgram=v,t.isRichText=function(t){var e=d(t).filter(function(t){var e=t.tokenType;return"ContextStart"===e||"ContextEnd"===e}),n=e.filter(function(t){return"ContextStart"===t.tokenType}),i=e.filter(function(t){return"ContextEnd"===t.tokenType});return n.length===i.length&&!!n.length&&function t(e,n){var i=e[0],r=e.slice(1);if(void 0===n&&(n=[]),!i)return 0===n.length;if("ContextStart"===i.tokenType)return t(r,n.concat(i.value));if("ContextEnd"===i.tokenType)return n[n.length-1]===i.value&&t(r,n.slice(0,-1));throw Error("Unexpected token: "+i.tokenType)}(e.map(function(t){var e=t.tokenType,n=t.value;return{tokenType:e,value:"ContextStart"===e?n.match(u)[1]:n.match(c)[1]}}))},t.lexer=d,t.richTextParser=p,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.5.5
6
+ * Version: v2.5.6
7
7
  */
8
8
 
9
9
  import * as EFFECTS from '@galacean/effects';
@@ -619,7 +619,7 @@ RichTextComponent = __decorate([
619
619
 
620
620
  /**
621
621
  * 插件版本号
622
- */ var version = "2.5.5";
622
+ */ var version = "2.5.6";
623
623
  registerPlugin("rich-text", RichTextLoader, VFXItem);
624
624
  logger.info("Plugin rich text version: " + version + ".");
625
625
  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(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,r.get?r:{enumerable:!0,get:function(){return t[n]}})}})),e.default=t,Object.freeze(e)}var n=e(t);function r(t,e){return r=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},r(t,e)}function i(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&r(t,e)}var o,a=function(t){function e(){var e;return(e=t.apply(this,arguments)||this).name="rich-text",e}return i(e,t),e}(t.AbstractPlugin);function s(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function l(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(n)return(n=n.call(t)).next.bind(n);if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return s(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(n):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?s(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var r=0;return function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}}}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"}(o||(o={}));var c=/^<([a-z]+)(=([^>]+))?>$/,u=/^<\/([a-z]+)>$/,h=[["ContextStart",/^<[a-z]+(=[^>]+)?>/],["Text",/^[^</>=]+/],["ContextEnd",/^<\/[a-z]+>/]],f=function(t,e,n){if(void 0===e&&(e=[]),void 0===n&&(n=0),!t)return e;for(var r,i=l(h);!(r=i()).done;){var o,a=r.value,s=a[0],c=(null!=(o=a[1].exec(t))?o:[])[0];if(c){var u=c.length;return f(t.slice(u),e.concat({tokenType:s,value:c}),n+u)}}throw new Error('Unexpected token: "'+t[0]+'" at position '+n+' while reading "'+t+'"')},p=function(t){var e=function(){var t=s();if("Text"===(null==t?void 0:t.tokenType))return a(),t.value},n=function(){var t=s();if("ContextStart"===(null==t?void 0:t.tokenType)){a();var e,n=t.value.match(c);if(n)return{attributeName:n[1],attributeParam:null!=(e=n[3])?e:""};throw new Error("Expected a start tag marker at position "+o)}return{}},r=function(){var t=s();if("ContextEnd"===(null==t?void 0:t.tokenType)){a();var e=t.value.match(u);if(e)return{attributeName:e[1]};throw new Error("Expect an end tag marker at position "+o)}return{}},i=f(t),o=0,a=function(){var t,e=i.shift();return o+=null!=(t=null==e?void 0:e.value.length)?t:0,e},s=function(){return i[0]},l=[];return function t(i,a){for(void 0===i&&(i=[]),void 0===a&&(a="");;){var s=e();if(s)l.push({attributes:i,text:s});else{var c=n(),u=c.attributeName,h=c.attributeParam;if(!u){if(a){var f=r().attributeName;if(!f)throw new Error('Expect an end tag marker "'+a+'" at position '+o+" but found no tag!");if(f!==a)throw new Error('Expect an end tag marker "'+a+'" at position '+o+' but found tag "'+f+'"');return}break}t(i.concat({attributeName:u,attributeParam:h}),u)}}}(),l};function d(t){return function(e){for(var n,r=l(p(e));!(n=r()).done;){var i=n.value,o=i.text,a=i.attributes.reduce((function(t,e){var n=e.attributeName,r=e.attributeParam;return n&&(t[n]=r),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 n=parseInt(t.slice(6,8),16)/255;t=t.slice(0,6),e=n}var r=parseInt(t,16);return[r>>16&255,r>>8&255,255&r,e]}function x(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"),n=e.getContext("2d");if(n)try{return n.fillStyle=t,n.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 n(t){var n;return(n=e.call(this,t)||this).processedTextOptions=[],n.singleLineHeight=1.571,n.size=null,n.initialized=!1,n.canvasSize=null,n.name="MRichText"+g++,n}i(n,e);var r=n.prototype;return r.generateTextProgram=function(e){var n=this;this.processedTextOptions=[];var r=d((function(e,r){/^\n+$/.test(e)&&(e=e.replace(/\n/g,"\n ")),e.split("\n").forEach((function(e,i){var o={text:e,fontSize:n.textStyle.fontSize,isNewLine:!1};i>0&&(o.isNewLine=!0),"b"in r&&(o.fontWeight=t.spec.TextWeight.bold),"i"in r&&(o.fontStyle=t.spec.FontStyle.italic),"size"in r&&r.size&&(o.fontSize=parseInt(r.size,10)),"color"in r&&r.color&&(o.fontColor=x(r.color)),n.processedTextOptions.push(o)}))}));r(e)},r.updateTexture=function(e){var n=this;if(void 0===e&&(e=!0),this.isDirty&&this.context&&this.canvas){this.generateTextProgram(this.text);var r=0,i=0,o=this.textLayout,a=this.textStyle,s=o.overflow,l=o.letterSpace,c=void 0===l?0:l,u=this.context;u.save();var h=[],f=a.fontSize*this.textStyle.fontScale,p={richOptions:[],offsetX:[],width:0,lineHeight:f*this.singleLineHeight,offsetY:f*(this.singleLineHeight-1)/2};if(this.processedTextOptions.forEach((function(t){var e=t.text,o=t.isNewLine,s=t.fontSize;o&&(h.push(p),r=Math.max(r,p.width),p={richOptions:[],offsetX:[],width:0,lineHeight:f*n.singleLineHeight,offsetY:f*(n.singleLineHeight-1)/2},i+=p.lineHeight),u.font=(t.fontWeight||a.textWeight)+" 10px "+(t.fontFamily||a.fontFamily);var l=u.measureText(e),d=l.width;if(void 0!==l.actualBoundingBoxLeft&&void 0!==l.actualBoundingBoxRight){var v=l.actualBoundingBoxLeft+l.actualBoundingBoxRight;v>0&&(d=Math.max(d,v))}var x=s*n.singleLineHeight*n.textStyle.fontScale;x>p.lineHeight&&(i+=x-p.lineHeight,p.lineHeight=x,p.offsetY=s*n.textStyle.fontScale*(n.singleLineHeight-1)/2),p.offsetX.push(p.width),p.width+=(d<=0?0:d)*s*n.SCALE_FACTOR*n.textStyle.fontScale+e.length*c,p.richOptions.push(t)})),h.push(p),r=Math.max(r,p.width),i+=p.lineHeight,0!==r&&0!==i){void 0!==this.size&&null!==this.size||(this.size=this.item.transform.size.clone());var d=this.size,v=d.x,x=void 0===v?1:v,g=d.y,m=void 0===g?1:g;if(!this.initialized){this.canvasSize=this.canvasSize?this.canvasSize:new t.math.Vector2(r,i);var y=this.canvasSize,w=y.x,S=y.y;this.item.transform.size.set(x*w*this.SCALE_FACTOR*this.SCALE_FACTOR,m*S*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,b=T.y;if(this.textLayout.width=E/a.fontScale,this.textLayout.height=b/a.fontScale,this.canvas.width=E,this.canvas.height=b,u.clearRect(0,0,E,b),u.fillStyle="rgba(255, 255, 255, "+this.ALPHA_FIX_VALUE+")",e||(u.translate(0,b),u.scale(1,-1)),0!==h.length){var C=o.getOffsetY(a,h.length,f*this.singleLineHeight,a.fontSize);h.forEach((function(e,r){var i=e.richOptions,o=e.offsetX,l=e.width,c=l,h=o;if(s===t.spec.TextOverflow.display&&l>E){var f=E/l;c*=f,h=o.map((function(t){return t*f}))}var p=n.textLayout.getOffsetX(a,c);r>0&&(C+=e.lineHeight-e.offsetY),i.forEach((function(e,n){var r=a.fontScale,i=a.textColor,o=a.fontFamily,c=a.textWeight,f=a.fontStyle,d=e.text,v=e.fontSize,x=e.fontColor,g=void 0===x?i:x,m=e.fontFamily,y=void 0===m?o:m,w=e.fontWeight,S=void 0===w?c:w,T=e.fontStyle,b=void 0===T?f:T,O=v;s===t.spec.TextOverflow.display&&l>E&&(O/=l/E);var z=h[n]+p;u.font=b+" "+S+" "+O*r+"px "+y,u.fillStyle="rgba("+g[0]+", "+g[1]+", "+g[2]+", "+g[3]+")",u.fillText(d,z,C)}))}));var O=u.getImageData(0,0,this.canvas.width,this.canvas.height),z=t.Texture.createWithData(this.engine,{data:new Uint8Array(O.data),width:O.width,height:O.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=z,this.material.setTexture("_MainTex",z),this.isDirty=!1,u.restore()}}else this.isDirty=!1}},r.setShadowOffsetY=function(t){throw new Error("Method not implemented.")},r.setShadowBlur=function(t){throw new Error("Method not implemented.")},r.setShadowOffsetX=function(t){throw new Error("Method not implemented.")},r.setShadowColor=function(t){throw new Error("Method not implemented.")},r.setOutlineWidth=function(t){throw new Error("Method not implemented.")},r.setAutoWidth=function(t){throw new Error("Method not implemented.")},r.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():" "},r.renderText=function(e){var n=e.size;n&&(this.canvasSize=new t.math.Vector2(n[0],n[1])),this.updateTexture()},n}(t.TextComponent),exports.RichTextComponent=function(t,e,n,r){var i,o=arguments.length,a=o<3?e:null===r?r=Object.getOwnPropertyDescriptor(e,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(t,e,n,r);else for(var s=t.length-1;s>=0;s--)(i=t[s])&&(a=(o<3?i(a):o>3?i(e,n,a):i(e,n))||a);return o>3&&a&&Object.defineProperty(e,n,a),a}([t.effectsClass(t.spec.DataType.RichTextComponent)],exports.RichTextComponent);var m="2.5.5";t.registerPlugin("rich-text",a,t.VFXItem),t.logger.info("Plugin rich text version: 2.5.5."),m!==n.version&&console.error("注意:请统一 RichText 插件与 Player 版本,不统一的版本混用会有不可预知的后果!","\nAttention: Please ensure the RichText plugin is synchronized with the Player version. Mixing and matching incompatible versions may result in unpredictable consequences!"),exports.RichTextLoader=a,exports.generateProgram=d,exports.isRichText=function(t){var e=f(t).filter((function(t){var e=t.tokenType;return"ContextStart"===e||"ContextEnd"===e})),n=e.filter((function(t){return"ContextStart"===t.tokenType})),r=e.filter((function(t){return"ContextEnd"===t.tokenType}));return!(n.length!==r.length||!n.length)&&function t(e,n){var r=e[0],i=e.slice(1);if(void 0===n&&(n=[]),!r)return 0===n.length;if("ContextStart"===r.tokenType)return t(i,n.concat(r.value));if("ContextEnd"===r.tokenType)return n[n.length-1]===r.value&&t(i,n.slice(0,-1));throw new Error("Unexpected token: "+r.tokenType)}(e.map((function(t){var e=t.tokenType,n=t.value;return{tokenType:e,value:"ContextStart"===e?n.match(c)[1]:n.match(u)[1]}})))},exports.lexer=f,exports.richTextParser=p,exports.version=m;
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(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,r.get?r:{enumerable:!0,get:function(){return t[n]}})}})),e.default=t,Object.freeze(e)}var n=e(t);function r(t,e){return r=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},r(t,e)}function i(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&r(t,e)}var o,a=function(t){function e(){var e;return(e=t.apply(this,arguments)||this).name="rich-text",e}return i(e,t),e}(t.AbstractPlugin);function s(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function l(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(n)return(n=n.call(t)).next.bind(n);if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return s(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(n):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?s(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var r=0;return function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}}}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"}(o||(o={}));var c=/^<([a-z]+)(=([^>]+))?>$/,u=/^<\/([a-z]+)>$/,h=[["ContextStart",/^<[a-z]+(=[^>]+)?>/],["Text",/^[^</>=]+/],["ContextEnd",/^<\/[a-z]+>/]],f=function(t,e,n){if(void 0===e&&(e=[]),void 0===n&&(n=0),!t)return e;for(var r,i=l(h);!(r=i()).done;){var o,a=r.value,s=a[0],c=(null!=(o=a[1].exec(t))?o:[])[0];if(c){var u=c.length;return f(t.slice(u),e.concat({tokenType:s,value:c}),n+u)}}throw new Error('Unexpected token: "'+t[0]+'" at position '+n+' while reading "'+t+'"')},p=function(t){var e=function(){var t=s();if("Text"===(null==t?void 0:t.tokenType))return a(),t.value},n=function(){var t=s();if("ContextStart"===(null==t?void 0:t.tokenType)){a();var e,n=t.value.match(c);if(n)return{attributeName:n[1],attributeParam:null!=(e=n[3])?e:""};throw new Error("Expected a start tag marker at position "+o)}return{}},r=function(){var t=s();if("ContextEnd"===(null==t?void 0:t.tokenType)){a();var e=t.value.match(u);if(e)return{attributeName:e[1]};throw new Error("Expect an end tag marker at position "+o)}return{}},i=f(t),o=0,a=function(){var t,e=i.shift();return o+=null!=(t=null==e?void 0:e.value.length)?t:0,e},s=function(){return i[0]},l=[];return function t(i,a){for(void 0===i&&(i=[]),void 0===a&&(a="");;){var s=e();if(s)l.push({attributes:i,text:s});else{var c=n(),u=c.attributeName,h=c.attributeParam;if(!u){if(a){var f=r().attributeName;if(!f)throw new Error('Expect an end tag marker "'+a+'" at position '+o+" but found no tag!");if(f!==a)throw new Error('Expect an end tag marker "'+a+'" at position '+o+' but found tag "'+f+'"');return}break}t(i.concat({attributeName:u,attributeParam:h}),u)}}}(),l};function d(t){return function(e){for(var n,r=l(p(e));!(n=r()).done;){var i=n.value,o=i.text,a=i.attributes.reduce((function(t,e){var n=e.attributeName,r=e.attributeParam;return n&&(t[n]=r),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 n=parseInt(t.slice(6,8),16)/255;t=t.slice(0,6),e=n}var r=parseInt(t,16);return[r>>16&255,r>>8&255,255&r,e]}function x(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"),n=e.getContext("2d");if(n)try{return n.fillStyle=t,n.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 n(t){var n;return(n=e.call(this,t)||this).processedTextOptions=[],n.singleLineHeight=1.571,n.size=null,n.initialized=!1,n.canvasSize=null,n.name="MRichText"+g++,n}i(n,e);var r=n.prototype;return r.generateTextProgram=function(e){var n=this;this.processedTextOptions=[];var r=d((function(e,r){/^\n+$/.test(e)&&(e=e.replace(/\n/g,"\n ")),e.split("\n").forEach((function(e,i){var o={text:e,fontSize:n.textStyle.fontSize,isNewLine:!1};i>0&&(o.isNewLine=!0),"b"in r&&(o.fontWeight=t.spec.TextWeight.bold),"i"in r&&(o.fontStyle=t.spec.FontStyle.italic),"size"in r&&r.size&&(o.fontSize=parseInt(r.size,10)),"color"in r&&r.color&&(o.fontColor=x(r.color)),n.processedTextOptions.push(o)}))}));r(e)},r.updateTexture=function(e){var n=this;if(void 0===e&&(e=!0),this.isDirty&&this.context&&this.canvas){this.generateTextProgram(this.text);var r=0,i=0,o=this.textLayout,a=this.textStyle,s=o.overflow,l=o.letterSpace,c=void 0===l?0:l,u=this.context;u.save();var h=[],f=a.fontSize*this.textStyle.fontScale,p={richOptions:[],offsetX:[],width:0,lineHeight:f*this.singleLineHeight,offsetY:f*(this.singleLineHeight-1)/2};if(this.processedTextOptions.forEach((function(t){var e=t.text,o=t.isNewLine,s=t.fontSize;o&&(h.push(p),r=Math.max(r,p.width),p={richOptions:[],offsetX:[],width:0,lineHeight:f*n.singleLineHeight,offsetY:f*(n.singleLineHeight-1)/2},i+=p.lineHeight),u.font=(t.fontWeight||a.textWeight)+" 10px "+(t.fontFamily||a.fontFamily);var l=u.measureText(e),d=l.width;if(void 0!==l.actualBoundingBoxLeft&&void 0!==l.actualBoundingBoxRight){var v=l.actualBoundingBoxLeft+l.actualBoundingBoxRight;v>0&&(d=Math.max(d,v))}var x=s*n.singleLineHeight*n.textStyle.fontScale;x>p.lineHeight&&(i+=x-p.lineHeight,p.lineHeight=x,p.offsetY=s*n.textStyle.fontScale*(n.singleLineHeight-1)/2),p.offsetX.push(p.width),p.width+=(d<=0?0:d)*s*n.SCALE_FACTOR*n.textStyle.fontScale+e.length*c,p.richOptions.push(t)})),h.push(p),r=Math.max(r,p.width),i+=p.lineHeight,0!==r&&0!==i){void 0!==this.size&&null!==this.size||(this.size=this.item.transform.size.clone());var d=this.size,v=d.x,x=void 0===v?1:v,g=d.y,m=void 0===g?1:g;if(!this.initialized){this.canvasSize=this.canvasSize?this.canvasSize:new t.math.Vector2(r,i);var y=this.canvasSize,w=y.x,S=y.y;this.item.transform.size.set(x*w*this.SCALE_FACTOR*this.SCALE_FACTOR,m*S*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,b=T.y;if(this.textLayout.width=E/a.fontScale,this.textLayout.height=b/a.fontScale,this.canvas.width=E,this.canvas.height=b,u.clearRect(0,0,E,b),u.fillStyle="rgba(255, 255, 255, "+this.ALPHA_FIX_VALUE+")",e||(u.translate(0,b),u.scale(1,-1)),0!==h.length){var C=o.getOffsetY(a,h.length,f*this.singleLineHeight,a.fontSize);h.forEach((function(e,r){var i=e.richOptions,o=e.offsetX,l=e.width,c=l,h=o;if(s===t.spec.TextOverflow.display&&l>E){var f=E/l;c*=f,h=o.map((function(t){return t*f}))}var p=n.textLayout.getOffsetX(a,c);r>0&&(C+=e.lineHeight-e.offsetY),i.forEach((function(e,n){var r=a.fontScale,i=a.textColor,o=a.fontFamily,c=a.textWeight,f=a.fontStyle,d=e.text,v=e.fontSize,x=e.fontColor,g=void 0===x?i:x,m=e.fontFamily,y=void 0===m?o:m,w=e.fontWeight,S=void 0===w?c:w,T=e.fontStyle,b=void 0===T?f:T,O=v;s===t.spec.TextOverflow.display&&l>E&&(O/=l/E);var z=h[n]+p;u.font=b+" "+S+" "+O*r+"px "+y,u.fillStyle="rgba("+g[0]+", "+g[1]+", "+g[2]+", "+g[3]+")",u.fillText(d,z,C)}))}));var O=u.getImageData(0,0,this.canvas.width,this.canvas.height),z=t.Texture.createWithData(this.engine,{data:new Uint8Array(O.data),width:O.width,height:O.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=z,this.material.setTexture("_MainTex",z),this.isDirty=!1,u.restore()}}else this.isDirty=!1}},r.setShadowOffsetY=function(t){throw new Error("Method not implemented.")},r.setShadowBlur=function(t){throw new Error("Method not implemented.")},r.setShadowOffsetX=function(t){throw new Error("Method not implemented.")},r.setShadowColor=function(t){throw new Error("Method not implemented.")},r.setOutlineWidth=function(t){throw new Error("Method not implemented.")},r.setAutoWidth=function(t){throw new Error("Method not implemented.")},r.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():" "},r.renderText=function(e){var n=e.size;n&&(this.canvasSize=new t.math.Vector2(n[0],n[1])),this.updateTexture()},n}(t.TextComponent),exports.RichTextComponent=function(t,e,n,r){var i,o=arguments.length,a=o<3?e:null===r?r=Object.getOwnPropertyDescriptor(e,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(t,e,n,r);else for(var s=t.length-1;s>=0;s--)(i=t[s])&&(a=(o<3?i(a):o>3?i(e,n,a):i(e,n))||a);return o>3&&a&&Object.defineProperty(e,n,a),a}([t.effectsClass(t.spec.DataType.RichTextComponent)],exports.RichTextComponent);var m="2.5.6";t.registerPlugin("rich-text",a,t.VFXItem),t.logger.info("Plugin rich text version: 2.5.6."),m!==n.version&&console.error("注意:请统一 RichText 插件与 Player 版本,不统一的版本混用会有不可预知的后果!","\nAttention: Please ensure the RichText plugin is synchronized with the Player version. Mixing and matching incompatible versions may result in unpredictable consequences!"),exports.RichTextLoader=a,exports.generateProgram=d,exports.isRichText=function(t){var e=f(t).filter((function(t){var e=t.tokenType;return"ContextStart"===e||"ContextEnd"===e})),n=e.filter((function(t){return"ContextStart"===t.tokenType})),r=e.filter((function(t){return"ContextEnd"===t.tokenType}));return!(n.length!==r.length||!n.length)&&function t(e,n){var r=e[0],i=e.slice(1);if(void 0===n&&(n=[]),!r)return 0===n.length;if("ContextStart"===r.tokenType)return t(i,n.concat(r.value));if("ContextEnd"===r.tokenType)return n[n.length-1]===r.value&&t(i,n.slice(0,-1));throw new Error("Unexpected token: "+r.tokenType)}(e.map((function(t){var e=t.tokenType,n=t.value;return{tokenType:e,value:"ContextStart"===e?n.match(c)[1]:n.match(u)[1]}})))},exports.lexer=f,exports.richTextParser=p,exports.version=m;
2
2
  //# sourceMappingURL=weapp.js.map
package/dist/weapp.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import*as t from"@galacean/effects/weapp";import{AbstractPlugin as e,effectsClass as n,spec as i,math as r,assertExist as o,Texture as a,glContext as s,TextStyle as l,TextLayout as h,TextComponent as f,registerPlugin as u,VFXItem as c,logger as d}from"@galacean/effects/weapp";function v(t,e){return v=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},v(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&&v(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 m(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,i=new Array(e);n<e;n++)i[n]=t[n];return i}function y(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(n)return(n=n.call(t)).next.bind(n);if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return m(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(n):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?m(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var i=0;return function(){return i>=t.length?{done:!0}:{done:!1,value:t[i++]}}}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"}(x||(x={}));var w=/^<([a-z]+)(=([^>]+))?>$/,S=/^<\/([a-z]+)>$/,T=[["ContextStart",/^<[a-z]+(=[^>]+)?>/],["Text",/^[^</>=]+/],["ContextEnd",/^<\/[a-z]+>/]],E=function(t,e,n){if(void 0===e&&(e=[]),void 0===n&&(n=0),!t)return e;for(var i,r=y(T);!(i=r()).done;){var o,a=i.value,s=a[0],l=(null!=(o=a[1].exec(t))?o:[])[0];if(l){var h=l.length;return E(t.slice(h),e.concat({tokenType:s,value:l}),n+h)}}throw new Error('Unexpected token: "'+t[0]+'" at position '+n+' while reading "'+t+'"')},b=function(t){var e=function(){var t=s();if("Text"===(null==t?void 0:t.tokenType))return a(),t.value},n=function(){var t=s();if("ContextStart"===(null==t?void 0:t.tokenType)){a();var e,n=t.value.match(w);if(n)return{attributeName:n[1],attributeParam:null!=(e=n[3])?e:""};throw new Error("Expected a start tag marker at position "+o)}return{}},i=function(){var t=s();if("ContextEnd"===(null==t?void 0:t.tokenType)){a();var e=t.value.match(S);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]},l=[];return function t(r,a){for(void 0===r&&(r=[]),void 0===a&&(a="");;){var s=e();if(s)l.push({attributes:r,text:s});else{var h=n(),f=h.attributeName,u=h.attributeParam;if(!f){if(a){var c=i().attributeName;if(!c)throw new Error('Expect an end tag marker "'+a+'" at position '+o+" but found no tag!");if(c!==a)throw new Error('Expect an end tag marker "'+a+'" at position '+o+' but found tag "'+c+'"');return}break}t(r.concat({attributeName:f,attributeParam:u}),f)}}}(),l};function z(t){return function(e){for(var n,i=y(b(e));!(n=i()).done;){var r=n.value,o=r.text,a=r.attributes.reduce((function(t,e){var n=e.attributeName,i=e.attributeParam;return n&&(t[n]=i),t}),{});t(o,a)}}}function C(t){var e=E(t).filter((function(t){var e=t.tokenType;return"ContextStart"===e||"ContextEnd"===e})),n=e.filter((function(t){return"ContextStart"===t.tokenType})),i=e.filter((function(t){return"ContextEnd"===t.tokenType}));if(n.length!==i.length||!n.length)return!1;return function t(e,n){var i=e[0],r=e.slice(1);if(void 0===n&&(n=[]),!i)return 0===n.length;if("ContextStart"===i.tokenType)return t(r,n.concat(i.value));if("ContextEnd"===i.tokenType)return n[n.length-1]===i.value&&t(r,n.slice(0,-1));throw new Error("Unexpected token: "+i.tokenType)}(e.map((function(t){var e=t.tokenType,n=t.value;return{tokenType:e,value:"ContextStart"===e?n.match(w)[1]:n.match(S)[1]}})))}function O(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 n=parseInt(t.slice(6,8),16)/255;t=t.slice(0,6),e=n}var i=parseInt(t,16);return[i>>16&255,i>>8&255,255&i,e]}function L(t,e){if(void 0===e&&(e=1),"string"!=typeof t||!t)throw new Error("Invalid color string");return t.startsWith("#")?O(t,e):O(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"),n=e.getContext("2d");if(n)try{return n.fillStyle=t,n.fillStyle}finally{e.remove()}throw new Error("Failed to get 2D context for color conversion!")}(t))}"function"==typeof SuppressedError&&SuppressedError;var A=0,k=function(t){function e(e){var n;return(n=t.call(this,e)||this).processedTextOptions=[],n.singleLineHeight=1.571,n.size=null,n.initialized=!1,n.canvasSize=null,n.name="MRichText"+A++,n}p(e,t);var n=e.prototype;return n.generateTextProgram=function(t){var e=this;this.processedTextOptions=[];var n=z((function(t,n){/^\n+$/.test(t)&&(t=t.replace(/\n/g,"\n ")),t.split("\n").forEach((function(t,r){var o={text:t,fontSize:e.textStyle.fontSize,isNewLine:!1};r>0&&(o.isNewLine=!0),"b"in n&&(o.fontWeight=i.TextWeight.bold),"i"in n&&(o.fontStyle=i.FontStyle.italic),"size"in n&&n.size&&(o.fontSize=parseInt(n.size,10)),"color"in n&&n.color&&(o.fontColor=L(n.color)),e.processedTextOptions.push(o)}))}));n(t)},n.updateTexture=function(t){var e=this;if(void 0===t&&(t=!0),this.isDirty&&this.context&&this.canvas){this.generateTextProgram(this.text);var n=0,l=0,h=this.textLayout,f=this.textStyle,u=h.overflow,c=h.letterSpace,d=void 0===c?0:c,v=this.context;v.save();var p=[],x=f.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,r=t.isNewLine,o=t.fontSize;r&&(p.push(g),n=Math.max(n,g.width),g={richOptions:[],offsetX:[],width:0,lineHeight:x*e.singleLineHeight,offsetY:x*(e.singleLineHeight-1)/2},l+=g.lineHeight),v.font=(t.fontWeight||f.textWeight)+" 10px "+(t.fontFamily||f.fontFamily);var a=v.measureText(i),s=a.width;if(void 0!==a.actualBoundingBoxLeft&&void 0!==a.actualBoundingBoxRight){var h=a.actualBoundingBoxLeft+a.actualBoundingBoxRight;h>0&&(s=Math.max(s,h))}var u=o*e.singleLineHeight*e.textStyle.fontScale;u>g.lineHeight&&(l+=u-g.lineHeight,g.lineHeight=u,g.offsetY=o*e.textStyle.fontScale*(e.singleLineHeight-1)/2),g.offsetX.push(g.width),g.width+=(s<=0?0:s)*o*e.SCALE_FACTOR*e.textStyle.fontScale+i.length*d,g.richOptions.push(t)})),p.push(g),n=Math.max(n,g.width),l+=g.lineHeight,0!==n&&0!==l){void 0!==this.size&&null!==this.size||(this.size=this.item.transform.size.clone());var m=this.size,y=m.x,w=void 0===y?1:y,S=m.y,T=void 0===S?1:S;if(!this.initialized){this.canvasSize=this.canvasSize?this.canvasSize:new r.Vector2(n,l);var E=this.canvasSize,b=E.x,z=E.y;this.item.transform.size.set(w*b*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,L=C.y;if(this.textLayout.width=O/f.fontScale,this.textLayout.height=L/f.fontScale,this.canvas.width=O,this.canvas.height=L,v.clearRect(0,0,O,L),v.fillStyle="rgba(255, 255, 255, "+this.ALPHA_FIX_VALUE+")",t||(v.translate(0,L),v.scale(1,-1)),0!==p.length){var A=h.getOffsetY(f,p.length,x*this.singleLineHeight,f.fontSize);p.forEach((function(t,n){var r=t.richOptions,o=t.offsetX,a=t.width,s=a,l=o;if(u===i.TextOverflow.display&&a>O){var h=O/a;s*=h,l=o.map((function(t){return t*h}))}var c=e.textLayout.getOffsetX(f,s);n>0&&(A+=t.lineHeight-t.offsetY),r.forEach((function(t,e){var n=f.fontScale,r=f.textColor,o=f.fontFamily,s=f.textWeight,h=f.fontStyle,d=t.text,p=t.fontSize,x=t.fontColor,g=void 0===x?r:x,m=t.fontFamily,y=void 0===m?o:m,w=t.fontWeight,S=void 0===w?s:w,T=t.fontStyle,E=void 0===T?h:T,b=p;u===i.TextOverflow.display&&a>O&&(b/=a/O);var z=l[e]+c;v.font=E+" "+S+" "+b*n+"px "+y,v.fillStyle="rgba("+g[0]+", "+g[1]+", "+g[2]+", "+g[3]+")",v.fillText(d,z,A)}))}));var k=v.getImageData(0,0,this.canvas.width,this.canvas.height),H=a.createWithData(this.engine,{data:new Uint8Array(k.data),width:k.width,height:k.height},{flipY:t,magFilter:s.LINEAR,minFilter:s.LINEAR,wrapS:s.CLAMP_TO_EDGE,wrapT:s.CLAMP_TO_EDGE});this.renderer.texture=H,this.material.setTexture("_MainTex",H),this.isDirty=!1,v.restore()}}else this.isDirty=!1}},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(t){this.textStyle=new l(t),this.textLayout=new h(t),this.textLayout.textBaseline=t.textBaseline||i.TextBaseline.middle,this.text=t.text?t.text.toString():" "},n.renderText=function(t){var e=t.size;e&&(this.canvasSize=new r.Vector2(e[0],e[1])),this.updateTexture()},e}(f);k=function(t,e,n,i){var r,o=arguments.length,a=o<3?e:null===i?i=Object.getOwnPropertyDescriptor(e,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(t,e,n,i);else for(var s=t.length-1;s>=0;s--)(r=t[s])&&(a=(o<3?r(a):o>3?r(e,n,a):r(e,n))||a);return o>3&&a&&Object.defineProperty(e,n,a),a}([n(i.DataType.RichTextComponent)],k);var H="2.5.5";u("rich-text",g,c),d.info("Plugin rich text version: 2.5.5."),H!==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{k as RichTextComponent,g as RichTextLoader,z as generateProgram,C as isRichText,E as lexer,b as richTextParser,H as version};
1
+ import*as t from"@galacean/effects/weapp";import{AbstractPlugin as e,effectsClass as n,spec as i,math as r,assertExist as o,Texture as a,glContext as s,TextStyle as l,TextLayout as h,TextComponent as f,registerPlugin as u,VFXItem as c,logger as d}from"@galacean/effects/weapp";function v(t,e){return v=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},v(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&&v(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 m(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,i=new Array(e);n<e;n++)i[n]=t[n];return i}function y(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(n)return(n=n.call(t)).next.bind(n);if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return m(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(n):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?m(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var i=0;return function(){return i>=t.length?{done:!0}:{done:!1,value:t[i++]}}}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"}(x||(x={}));var w=/^<([a-z]+)(=([^>]+))?>$/,S=/^<\/([a-z]+)>$/,T=[["ContextStart",/^<[a-z]+(=[^>]+)?>/],["Text",/^[^</>=]+/],["ContextEnd",/^<\/[a-z]+>/]],E=function(t,e,n){if(void 0===e&&(e=[]),void 0===n&&(n=0),!t)return e;for(var i,r=y(T);!(i=r()).done;){var o,a=i.value,s=a[0],l=(null!=(o=a[1].exec(t))?o:[])[0];if(l){var h=l.length;return E(t.slice(h),e.concat({tokenType:s,value:l}),n+h)}}throw new Error('Unexpected token: "'+t[0]+'" at position '+n+' while reading "'+t+'"')},b=function(t){var e=function(){var t=s();if("Text"===(null==t?void 0:t.tokenType))return a(),t.value},n=function(){var t=s();if("ContextStart"===(null==t?void 0:t.tokenType)){a();var e,n=t.value.match(w);if(n)return{attributeName:n[1],attributeParam:null!=(e=n[3])?e:""};throw new Error("Expected a start tag marker at position "+o)}return{}},i=function(){var t=s();if("ContextEnd"===(null==t?void 0:t.tokenType)){a();var e=t.value.match(S);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]},l=[];return function t(r,a){for(void 0===r&&(r=[]),void 0===a&&(a="");;){var s=e();if(s)l.push({attributes:r,text:s});else{var h=n(),f=h.attributeName,u=h.attributeParam;if(!f){if(a){var c=i().attributeName;if(!c)throw new Error('Expect an end tag marker "'+a+'" at position '+o+" but found no tag!");if(c!==a)throw new Error('Expect an end tag marker "'+a+'" at position '+o+' but found tag "'+c+'"');return}break}t(r.concat({attributeName:f,attributeParam:u}),f)}}}(),l};function z(t){return function(e){for(var n,i=y(b(e));!(n=i()).done;){var r=n.value,o=r.text,a=r.attributes.reduce((function(t,e){var n=e.attributeName,i=e.attributeParam;return n&&(t[n]=i),t}),{});t(o,a)}}}function C(t){var e=E(t).filter((function(t){var e=t.tokenType;return"ContextStart"===e||"ContextEnd"===e})),n=e.filter((function(t){return"ContextStart"===t.tokenType})),i=e.filter((function(t){return"ContextEnd"===t.tokenType}));if(n.length!==i.length||!n.length)return!1;return function t(e,n){var i=e[0],r=e.slice(1);if(void 0===n&&(n=[]),!i)return 0===n.length;if("ContextStart"===i.tokenType)return t(r,n.concat(i.value));if("ContextEnd"===i.tokenType)return n[n.length-1]===i.value&&t(r,n.slice(0,-1));throw new Error("Unexpected token: "+i.tokenType)}(e.map((function(t){var e=t.tokenType,n=t.value;return{tokenType:e,value:"ContextStart"===e?n.match(w)[1]:n.match(S)[1]}})))}function O(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 n=parseInt(t.slice(6,8),16)/255;t=t.slice(0,6),e=n}var i=parseInt(t,16);return[i>>16&255,i>>8&255,255&i,e]}function L(t,e){if(void 0===e&&(e=1),"string"!=typeof t||!t)throw new Error("Invalid color string");return t.startsWith("#")?O(t,e):O(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"),n=e.getContext("2d");if(n)try{return n.fillStyle=t,n.fillStyle}finally{e.remove()}throw new Error("Failed to get 2D context for color conversion!")}(t))}"function"==typeof SuppressedError&&SuppressedError;var A=0,k=function(t){function e(e){var n;return(n=t.call(this,e)||this).processedTextOptions=[],n.singleLineHeight=1.571,n.size=null,n.initialized=!1,n.canvasSize=null,n.name="MRichText"+A++,n}p(e,t);var n=e.prototype;return n.generateTextProgram=function(t){var e=this;this.processedTextOptions=[];var n=z((function(t,n){/^\n+$/.test(t)&&(t=t.replace(/\n/g,"\n ")),t.split("\n").forEach((function(t,r){var o={text:t,fontSize:e.textStyle.fontSize,isNewLine:!1};r>0&&(o.isNewLine=!0),"b"in n&&(o.fontWeight=i.TextWeight.bold),"i"in n&&(o.fontStyle=i.FontStyle.italic),"size"in n&&n.size&&(o.fontSize=parseInt(n.size,10)),"color"in n&&n.color&&(o.fontColor=L(n.color)),e.processedTextOptions.push(o)}))}));n(t)},n.updateTexture=function(t){var e=this;if(void 0===t&&(t=!0),this.isDirty&&this.context&&this.canvas){this.generateTextProgram(this.text);var n=0,l=0,h=this.textLayout,f=this.textStyle,u=h.overflow,c=h.letterSpace,d=void 0===c?0:c,v=this.context;v.save();var p=[],x=f.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,r=t.isNewLine,o=t.fontSize;r&&(p.push(g),n=Math.max(n,g.width),g={richOptions:[],offsetX:[],width:0,lineHeight:x*e.singleLineHeight,offsetY:x*(e.singleLineHeight-1)/2},l+=g.lineHeight),v.font=(t.fontWeight||f.textWeight)+" 10px "+(t.fontFamily||f.fontFamily);var a=v.measureText(i),s=a.width;if(void 0!==a.actualBoundingBoxLeft&&void 0!==a.actualBoundingBoxRight){var h=a.actualBoundingBoxLeft+a.actualBoundingBoxRight;h>0&&(s=Math.max(s,h))}var u=o*e.singleLineHeight*e.textStyle.fontScale;u>g.lineHeight&&(l+=u-g.lineHeight,g.lineHeight=u,g.offsetY=o*e.textStyle.fontScale*(e.singleLineHeight-1)/2),g.offsetX.push(g.width),g.width+=(s<=0?0:s)*o*e.SCALE_FACTOR*e.textStyle.fontScale+i.length*d,g.richOptions.push(t)})),p.push(g),n=Math.max(n,g.width),l+=g.lineHeight,0!==n&&0!==l){void 0!==this.size&&null!==this.size||(this.size=this.item.transform.size.clone());var m=this.size,y=m.x,w=void 0===y?1:y,S=m.y,T=void 0===S?1:S;if(!this.initialized){this.canvasSize=this.canvasSize?this.canvasSize:new r.Vector2(n,l);var E=this.canvasSize,b=E.x,z=E.y;this.item.transform.size.set(w*b*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,L=C.y;if(this.textLayout.width=O/f.fontScale,this.textLayout.height=L/f.fontScale,this.canvas.width=O,this.canvas.height=L,v.clearRect(0,0,O,L),v.fillStyle="rgba(255, 255, 255, "+this.ALPHA_FIX_VALUE+")",t||(v.translate(0,L),v.scale(1,-1)),0!==p.length){var A=h.getOffsetY(f,p.length,x*this.singleLineHeight,f.fontSize);p.forEach((function(t,n){var r=t.richOptions,o=t.offsetX,a=t.width,s=a,l=o;if(u===i.TextOverflow.display&&a>O){var h=O/a;s*=h,l=o.map((function(t){return t*h}))}var c=e.textLayout.getOffsetX(f,s);n>0&&(A+=t.lineHeight-t.offsetY),r.forEach((function(t,e){var n=f.fontScale,r=f.textColor,o=f.fontFamily,s=f.textWeight,h=f.fontStyle,d=t.text,p=t.fontSize,x=t.fontColor,g=void 0===x?r:x,m=t.fontFamily,y=void 0===m?o:m,w=t.fontWeight,S=void 0===w?s:w,T=t.fontStyle,E=void 0===T?h:T,b=p;u===i.TextOverflow.display&&a>O&&(b/=a/O);var z=l[e]+c;v.font=E+" "+S+" "+b*n+"px "+y,v.fillStyle="rgba("+g[0]+", "+g[1]+", "+g[2]+", "+g[3]+")",v.fillText(d,z,A)}))}));var k=v.getImageData(0,0,this.canvas.width,this.canvas.height),H=a.createWithData(this.engine,{data:new Uint8Array(k.data),width:k.width,height:k.height},{flipY:t,magFilter:s.LINEAR,minFilter:s.LINEAR,wrapS:s.CLAMP_TO_EDGE,wrapT:s.CLAMP_TO_EDGE});this.renderer.texture=H,this.material.setTexture("_MainTex",H),this.isDirty=!1,v.restore()}}else this.isDirty=!1}},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(t){this.textStyle=new l(t),this.textLayout=new h(t),this.textLayout.textBaseline=t.textBaseline||i.TextBaseline.middle,this.text=t.text?t.text.toString():" "},n.renderText=function(t){var e=t.size;e&&(this.canvasSize=new r.Vector2(e[0],e[1])),this.updateTexture()},e}(f);k=function(t,e,n,i){var r,o=arguments.length,a=o<3?e:null===i?i=Object.getOwnPropertyDescriptor(e,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(t,e,n,i);else for(var s=t.length-1;s>=0;s--)(r=t[s])&&(a=(o<3?r(a):o>3?r(e,n,a):r(e,n))||a);return o>3&&a&&Object.defineProperty(e,n,a),a}([n(i.DataType.RichTextComponent)],k);var H="2.5.6";u("rich-text",g,c),d.info("Plugin rich text version: 2.5.6."),H!==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{k as RichTextComponent,g as RichTextLoader,z as generateProgram,C as isRichText,E as lexer,b as richTextParser,H 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.5.5",
3
+ "version": "2.5.6",
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.5.5"
46
+ "@galacean/effects": "2.5.6"
47
47
  },
48
48
  "scripts": {
49
49
  "dev": "vite",