@galacean/effects-plugin-rich-text 2.8.7 → 2.8.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -23,9 +23,13 @@ export declare class RichTextComponent extends MaskableGraphic implements IRichT
23
23
  context: CanvasRenderingContext2D | null;
24
24
  textLayout: RichTextLayout;
25
25
  processedTextOptions: RichTextOptions[];
26
+ /** @deprecated Use for legacy mode*/
26
27
  private singleLineHeight;
28
+ /** @deprecated Use for legacy mode*/
27
29
  private size;
30
+ /** @deprecated Use for legacy mode*/
28
31
  private initialized;
32
+ /** @deprecated Use for legacy mode*/
29
33
  private canvasSize;
30
34
  private richWrapStrategy;
31
35
  private richOverflowStrategy;
@@ -38,7 +42,7 @@ export declare class RichTextComponent extends MaskableGraphic implements IRichT
38
42
  onDestroy(): void;
39
43
  fromData(data: spec.RichTextComponentData): void;
40
44
  /**
41
- * 使用策略结果绘制文本
45
+ * 根据布局配置更新策略实例
42
46
  */
43
47
  private updateStrategies;
44
48
  private generateTextProgram;
@@ -46,7 +50,6 @@ export declare class RichTextComponent extends MaskableGraphic implements IRichT
46
50
  * 根据配置更新文本样式和布局
47
51
  */
48
52
  protected updateWithOptions(options: spec.RichTextContentOptions): void;
49
- protected renderText(options: spec.RichTextContentOptions): void;
50
53
  /**
51
54
  * 更新文本
52
55
  * @returns
@@ -58,15 +61,19 @@ export declare class RichTextComponent extends MaskableGraphic implements IRichT
58
61
  private updateTextureLegacy;
59
62
  /**
60
63
  * 使用策略管线路径的渲染方法
64
+ *
65
+ * 管线顺序:
66
+ * 1. Wrap → 换行与度量
67
+ * 2. SizeMode → 根据 autoResize 回写帧尺寸
68
+ * 3. ContentScale → 内容缩放(仅 display 模式)
69
+ * 4. Alignment → 在帧坐标系中对齐(不依赖 overflow)
70
+ * 5. Overflow → 画布解析:确定最终画布尺寸与渲染偏移(不依赖对齐模式)
71
+ * 6. Render → 绘制
61
72
  */
62
73
  private updateTextureWithStrategies;
63
- private setCanvasSize;
64
- /**
65
- * 尺寸处理
66
- */
67
- private resolveCanvasSize;
68
74
  /**
69
75
  * 使用策略结果绘制文本
76
+ * 坐标 = 帧坐标(对齐结果) + 渲染偏移(溢出结果)
70
77
  */
71
78
  private drawTextWithStrategies;
72
79
  private unsupported;
@@ -29,7 +29,7 @@ export declare class RichTextLayout implements BaseLayout {
29
29
  * - autoHeight: 根据内容自动扩展高度
30
30
  * - fixed: 使用固定 width / height
31
31
  */
32
- sizeMode: spec.TextSizeMode;
32
+ autoResize: spec.TextSizeMode;
33
33
  /**
34
34
  * 文本行高
35
35
  */
@@ -56,6 +56,7 @@ export declare class RichTextLayout implements BaseLayout {
56
56
  /**
57
57
  * 设置文本框尺寸
58
58
  * - 不包含 fontScale 缩放
59
+ * @deprecated use maxTextWidth / maxTextHeight instead
59
60
  */
60
61
  setSize(width: number, height: number): void;
61
62
  }
@@ -1,10 +1,10 @@
1
1
  import type { TextStyle } from '@galacean/effects';
2
2
  import type { RichTextLayout } from '../../rich-text-layout';
3
- import type { RichLine, HorizontalAlignResult, SizeResult, OverflowResult, RichHorizontalAlignStrategy } from '../rich-text-interfaces';
3
+ import type { RichLine, HorizontalAlignResult, RichHorizontalAlignStrategy } from '../rich-text-interfaces';
4
4
  /**
5
5
  * 富文本水平对齐策略
6
- * 直接使用已缩放的行宽计算偏移量
6
+ * 在帧坐标系中计算每行的水平偏移,不依赖溢出模式
7
7
  */
8
8
  export declare class RichHorizontalAlignStrategyImpl implements RichHorizontalAlignStrategy {
9
- getHorizontalOffsets(lines: RichLine[], sizeResult: SizeResult, overflowResult: OverflowResult, layout: RichTextLayout, style: TextStyle): HorizontalAlignResult;
9
+ getHorizontalOffsets(lines: RichLine[], frameWidth: number, layout: RichTextLayout, style: TextStyle): HorizontalAlignResult;
10
10
  }
@@ -1,10 +1,14 @@
1
- import type { TextStyle } from '@galacean/effects';
2
1
  import type { RichTextLayout } from '../../rich-text-layout';
3
- import type { RichLine, VerticalAlignResult, SizeResult, OverflowResult, RichVerticalAlignStrategy } from '../rich-text-interfaces';
2
+ import type { RichLine, VerticalAlignResult, RichVerticalAlignStrategy } from '../rich-text-interfaces';
4
3
  /**
5
4
  * 富文本垂直对齐策略
6
- * 直接使用已缩放的行高
5
+ * 在帧坐标系中计算基线位置,不依赖溢出模式
6
+ *
7
+ * 算法:
8
+ * 1. 从行数据重建各行基线(baseline[0]=0, baseline[i]=baseline[i-1]+lineHeight[i])
9
+ * 2. 计算 bbox(包含行高边距)
10
+ * 3. 根据 textVerticalAlign 将内容定位到帧中
7
11
  */
8
12
  export declare class RichVerticalAlignStrategyImpl implements RichVerticalAlignStrategy {
9
- getVerticalOffsets(lines: RichLine[], sizeResult: SizeResult, overflowResult: OverflowResult, layout: RichTextLayout, style: TextStyle, singleLineHeight: number): VerticalAlignResult;
13
+ getVerticalOffsets(lines: RichLine[], frameHeight: number, layout: RichTextLayout): VerticalAlignResult;
10
14
  }
@@ -1,10 +1,9 @@
1
- import type { TextStyle } from '@galacean/effects';
2
- import type { RichLine, RichOverflowStrategy, OverflowResult, SizeResult } from '../rich-text-interfaces';
3
- import type { RichTextLayout } from '../../rich-text-layout';
1
+ import type { RichLine, RichOverflowStrategy, OverflowResult, HorizontalAlignResult, VerticalAlignResult } from '../rich-text-interfaces';
4
2
  /**
5
3
  * Clip 溢出策略
6
- * 超出画布部分自然裁切
4
+ * 画布尺寸固定为帧尺寸,超出部分自然裁切
5
+ * 不依赖对齐模式
7
6
  */
8
7
  export declare class RichClippedOverflowStrategy implements RichOverflowStrategy {
9
- apply(lines: RichLine[], sizeResult: SizeResult, layout: RichTextLayout, style: TextStyle): OverflowResult;
8
+ resolveCanvas(lines: RichLine[], frameWidth: number, frameHeight: number, horizontalResult: HorizontalAlignResult, verticalResult: VerticalAlignResult): OverflowResult;
10
9
  }
@@ -0,0 +1,15 @@
1
+ import type { RichLine, RichOverflowStrategy, OverflowResult, HorizontalAlignResult, VerticalAlignResult } from '../rich-text-interfaces';
2
+ /**
3
+ * 扩展画布溢出策略(visible / display 模式共用)
4
+ *
5
+ * 根据对齐后的内容位置检测溢出,对称扩展画布以容纳所有内容。
6
+ * 不依赖对齐模式(textAlign / textVerticalAlign)的枚举值,
7
+ * 仅使用对齐策略输出的位置和行的度量数据。
8
+ *
9
+ * 对称扩展的原因:元素定位以中心点为锚点,
10
+ * 单侧扩展会导致视觉偏移。使用 max(溢出左, 溢出右) 作为双侧扩展量
11
+ * 可以保持中心点稳定并兼容所有对齐模式。
12
+ */
13
+ export declare class RichExpandingOverflowStrategy implements RichOverflowStrategy {
14
+ resolveCanvas(lines: RichLine[], frameWidth: number, frameHeight: number, horizontalResult: HorizontalAlignResult, verticalResult: VerticalAlignResult): OverflowResult;
15
+ }
@@ -3,16 +3,18 @@ import type { RichWrapStrategy, RichOverflowStrategy, RichHorizontalAlignStrateg
3
3
  /**
4
4
  * 富文本策略工厂
5
5
  * 负责创建各种策略实例
6
+ *
7
+ * 管线顺序:Wrap → scaleLinesToFit(display)→ Align → Overflow.resolveCanvas
6
8
  */
7
9
  export declare class RichTextStrategyFactory {
8
10
  /**
9
11
  * 创建换行策略
10
- * 根据wrapEnabled参数决定使用哪种策略
11
12
  */
12
13
  static createWrapStrategy(wrapEnabled?: boolean): RichWrapStrategy;
13
14
  /**
14
- * 创建溢出策略
15
- * 支持三种模式:clip(裁切)、display(行级缩放)、visible(不缩放不裁剪)
15
+ * 创建溢出策略(画布解析)
16
+ * clip:画布=帧,超出裁切
17
+ * display/visible:检测溢出并对称扩展画布
16
18
  */
17
19
  static createOverflowStrategy(mode: spec.TextOverflow): RichOverflowStrategy;
18
20
  /**
@@ -32,26 +32,17 @@ export interface WrapResult {
32
32
  bboxBottom?: number;
33
33
  bboxHeight?: number;
34
34
  }
35
- /**
36
- * 尺寸策略结果
37
- */
38
- export interface SizeResult {
39
- canvasWidth: number;
40
- canvasHeight: number;
41
- contentWidth?: number;
42
- bboxTop?: number;
43
- bboxBottom?: number;
44
- bboxHeight?: number;
45
- baselineCompensationY?: number;
46
- baselineCompensationX?: number;
47
- containerWidth?: number;
48
- lines?: RichLine[];
49
- }
50
35
  /**
51
36
  * 溢出策略结果
37
+ * 包含最终画布尺寸和渲染坐标偏移
52
38
  */
53
39
  export interface OverflowResult {
54
- globalScale?: number;
40
+ canvasWidth: number;
41
+ canvasHeight: number;
42
+ /** 渲染时叠加到所有 X 坐标的偏移(帧→画布坐标系补偿) */
43
+ renderOffsetX: number;
44
+ /** 渲染时叠加到所有 Y 坐标的偏移(帧→画布坐标系补偿) */
45
+ renderOffsetY: number;
55
46
  }
56
47
  /**
57
48
  * 水平对齐策略结果
@@ -66,40 +57,37 @@ export interface VerticalAlignResult {
66
57
  baselineY: number;
67
58
  lineYOffsets: number[];
68
59
  }
69
- /**
70
- * 对齐策略结果(组合水平和垂直对齐)
71
- */
72
- export interface AlignResult {
73
- horizontal: HorizontalAlignResult;
74
- vertical: VerticalAlignResult;
75
- }
76
- /**
77
- * 富文本尺寸策略接口
78
- */
79
- export interface RichSizeStrategy {
80
- calculate(WrapResult: WrapResult, layout: RichTextLayout, style: TextStyle, singleLineHeight: number, fontScale: number): SizeResult;
81
- }
82
60
  /**
83
61
  * 富文本换行策略接口
84
62
  */
85
63
  export interface RichWrapStrategy {
86
- computeLines(processedOptions: RichTextOptions[], context: CanvasRenderingContext2D, style: TextStyle, layout: RichTextLayout, singleLineHeight: number, fontScale: number, letterSpace: number, scaleFactor: number): WrapResult;
64
+ computeLines(processedOptions: RichTextOptions[], context: CanvasRenderingContext2D, style: TextStyle, layout: RichTextLayout, letterSpace: number): WrapResult;
87
65
  }
88
66
  /**
89
- * 富文本溢出策略接口
67
+ * 富文本溢出策略接口(画布解析)
68
+ * 根据对齐后的内容位置确定最终画布尺寸和渲染偏移
69
+ * 不依赖对齐模式(textAlign/textVerticalAlign)的枚举值,
70
+ * 仅使用对齐策略输出的位置数据
90
71
  */
91
72
  export interface RichOverflowStrategy {
92
- apply(lines: RichLine[], sizeResult: SizeResult, layout: RichTextLayout, style: TextStyle): OverflowResult;
73
+ resolveCanvas(lines: RichLine[], frameWidth: number, frameHeight: number, horizontalResult: HorizontalAlignResult, verticalResult: VerticalAlignResult): OverflowResult;
93
74
  }
75
+ /**
76
+ * 将行数据等比缩小以适配帧尺寸(display 模式使用)
77
+ * 只缩小不放大,就地修改行数据
78
+ */
79
+ export declare function scaleLinesToFit(lines: RichLine[], contentWidth: number, contentHeight: number, frameWidth: number, frameHeight: number): void;
94
80
  /**
95
81
  * 富文本水平对齐策略接口
82
+ * 在帧坐标系中定位内容,不依赖溢出模式
96
83
  */
97
84
  export interface RichHorizontalAlignStrategy {
98
- getHorizontalOffsets(lines: RichLine[], sizeResult: SizeResult, overflowResult: OverflowResult, layout: RichTextLayout, style: TextStyle): HorizontalAlignResult;
85
+ getHorizontalOffsets(lines: RichLine[], frameWidth: number, layout: RichTextLayout, style: TextStyle): HorizontalAlignResult;
99
86
  }
100
87
  /**
101
88
  * 富文本垂直对齐策略接口
89
+ * 在帧坐标系中定位内容,不依赖溢出模式
102
90
  */
103
91
  export interface RichVerticalAlignStrategy {
104
- getVerticalOffsets(lines: RichLine[], sizeResult: SizeResult, overflowResult: OverflowResult, layout: RichTextLayout, style: TextStyle, singleLineHeight: number): VerticalAlignResult;
92
+ getVerticalOffsets(lines: RichLine[], frameHeight: number, layout: RichTextLayout): VerticalAlignResult;
105
93
  }
@@ -7,7 +7,7 @@ import type { RichWrapStrategy, WrapResult } from '../rich-text-interfaces';
7
7
  * 实现逻辑:仅基于\n换行,无自动换行
8
8
  */
9
9
  export declare class RichWrapDisabledStrategy implements RichWrapStrategy {
10
- computeLines(processedOptions: RichTextOptions[], context: CanvasRenderingContext2D, style: TextStyle, layout: RichTextLayout, singleLineHeight: number, fontScale: number, letterSpace: number, scaleFactor: number): WrapResult;
10
+ computeLines(processedOptions: RichTextOptions[], context: CanvasRenderingContext2D, style: TextStyle, layout: RichTextLayout, letterSpace: number): WrapResult;
11
11
  /**
12
12
  * 创建新行
13
13
  */
@@ -7,7 +7,7 @@ import type { WrapResult, RichWrapStrategy } from '../rich-text-interfaces';
7
7
  * 实现逻辑:基于\n换行及自动换行
8
8
  */
9
9
  export declare class RichWrapEnabledStrategy implements RichWrapStrategy {
10
- computeLines(processedOptions: RichTextOptions[], context: CanvasRenderingContext2D, style: TextStyle, layout: RichTextLayout, singleLineHeight: number, fontScale: number, letterSpace: number, scaleFactor: number): WrapResult;
10
+ computeLines(processedOptions: RichTextOptions[], context: CanvasRenderingContext2D, style: TextStyle, layout: RichTextLayout, letterSpace: number): WrapResult;
11
11
  /**
12
12
  * 创建新行
13
13
  */
package/dist/weapp.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@galacean/effects/weapp"),e=require("@galacean/appx-adapter/weapp");function i(t){if(t&&t.__esModule)return t;var e=Object.create(null);return t&&Object.keys(t).forEach((function(i){if("default"!==i){var n=Object.getOwnPropertyDescriptor(t,i);Object.defineProperty(e,i,n.get?n:{enumerable:!0,get:function(){return t[i]}})}})),e.default=t,Object.freeze(e)}var n=i(t);function r(t,e){return r=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},r(t,e)}function a(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&r(t,e)}function o(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(o=function(){return!!t})()}function s(t,e,i){return s=o()?Reflect.construct:function(t,e,i){var n=[null];n.push.apply(n,e);var a=new(Function.bind.apply(t,n));return i&&r(a,i.prototype),a},s.apply(null,arguments)}function l(t){return l=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},l(t)}function c(t){var e="function"==typeof Map?new Map:void 0;return c=function(t){if(null===t||(i=t,-1===Function.toString.call(i).indexOf("[native code]")))return t;var i;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,n)}function n(){return s(t,arguments,l(this).constructor)}return n.prototype=Object.create(t.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),r(n,t)},c(t)}var h,u=function(t){function e(){var e;return(e=t.apply(this,arguments)||this).name="rich-text",e}return a(e,t),e}(c(t.Plugin));function f(t,e){(null==e||e>t.length)&&(e=t.length);for(var i=0,n=new Array(e);i<e;i++)n[i]=t[i];return n}function p(t,e){var i="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(i)return(i=i.call(t)).next.bind(i);if(Array.isArray(t)||(i=function(t,e){if(t){if("string"==typeof t)return f(t,e);var i=Object.prototype.toString.call(t).slice(8,-1);return"Object"===i&&t.constructor&&(i=t.constructor.name),"Map"===i||"Set"===i?Array.from(i):"Arguments"===i||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i)?f(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){i&&(t=i);var n=0;return function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}!function(t){t.ContextStart="ContextStart",t.Text="Text",t.ContextEnd="ContextEnd",t.EscapedChar="EscapedChar"}(h||(h={}));var x=/^<([a-z]+)(=([^>]+))?>$/,g=/^<\/([a-z]+)>$/,v=[["EscapedChar",/^\\([=<>\\/])/],["ContextStart",/^<[a-z]+(=[^>]+)?>/],["ContextEnd",/^<\/[a-z]+>/],["Text",/^[^</>=\\]+/]],d=function(t,e,i){if(void 0===e&&(e=[]),void 0===i&&(i=0),!t)return e;var n=/^\\([=<>\\/])/.exec(t);if(n){var r=n[1];return d(t.slice(2),e.concat({tokenType:"Text",value:r}),i+2)}for(var a,o=p(v);!(a=o()).done;){var s=a.value,l=s[0],c=s[1];if("EscapedChar"!==l){var h=c.exec(t);if(h){var u=h[0],f=u.length;return d(t.slice(f),e.concat({tokenType:l,value:u}),i+f)}}}if(t.length>0)return d(t.slice(1),e.concat({tokenType:"Text",value:t[0]}),i+1);throw new Error('Unexpected token: "'+t[0]+'" at position '+i+' while reading "'+t+'"')},m=function(t){var e=function(){for(var t,e="",i=!1;r.length>0&&"Text"===(null==(t=r[0])?void 0:t.tokenType);){var n=o();n&&(e+=n.value,i=!0)}return i?e:void 0},i=function(){var t=s();if("ContextStart"===(null==t?void 0:t.tokenType)){o();var e,i=t.value.match(x);if(i)return{attributeName:i[1],attributeParam:null!=(e=i[3])?e:""};throw new Error("Expected a start tag marker at position "+a)}return{}},n=function(){var t=s();if("ContextEnd"===(null==t?void 0:t.tokenType)){o();var e=t.value.match(g);if(e)return{attributeName:e[1]};throw new Error("Expect an end tag marker at position "+a)}return{}},r=d(t),a=0,o=function(){var t,e=r.shift();return a+=null!=(t=null==e?void 0:e.value.length)?t:0,e},s=function(){return r[0]},l=[];return function t(r,o){for(void 0===r&&(r=[]),void 0===o&&(o="");;){var s=e();if(s)l.push({attributes:r,text:s});else{var c=i(),h=c.attributeName,u=c.attributeParam;if(!h){if(o){var f=n().attributeName;if(!f)throw new Error('Expect an end tag marker "'+o+'" at position '+a+" but found no tag!");if(f!==o)throw new Error('Expect an end tag marker "'+o+'" at position '+a+' but found tag "'+f+'"');return}break}t(r.concat({attributeName:h,attributeParam:null!=u?u:""}),h)}}}(),l};function y(t){return function(e){for(var i,n=p(m(e));!(i=n()).done;){var r=i.value,a=r.text,o=r.attributes.reduce((function(t,e){var i=e.attributeName,n=e.attributeParam;return i&&(t[i]=n),t}),{});t(a,o)}}}"function"==typeof SuppressedError&&SuppressedError;var S=function(){function e(e){this.width=0,this.height=0;var i=e.size,n=e.textOverflow,r=void 0===n?t.spec.TextOverflow.clip:n,a=e.textVerticalAlign,o=void 0===a?t.spec.TextVerticalAlign.middle:a,s=e.textAlign,l=void 0===s?t.spec.TextAlignment.left:s,c=e.letterSpace,h=void 0===c?0:c,u=e.lineHeight,f=void 0===u?.571:u,p=e.wrapEnabled,x=void 0!==p&&p,g=e.maxTextWidth,v=void 0===g?350:g,d=e.maxTextHeight,m=void 0===d?1e3:d,y=e.sizeMode,S=void 0===y?t.spec.TextSizeMode.autoWidth:y,T=e.useLegacyRichText,w=void 0!==T&&T;this.letterSpace=h,this.lineHeight=f,this.useLegacyRichText=w,this.overflow=r,this.textVerticalAlign=o,this.textAlign=l,this.width=i?i[0]:100,this.height=i?i[1]:100,this.wrapEnabled=x,this.maxTextWidth=v,this.maxTextHeight=m,this.sizeMode=S}var i=e.prototype;return i.getOffsetY=function(e,i,n,r,a){var o=e.outlineWidth,s=e.fontScale,l=(n-r)/3,c=r+o*s,h=void 0!==a?a:n*(i-1),u=0;switch(this.textVerticalAlign){case t.spec.TextVerticalAlign.top:u=c+l;break;case t.spec.TextVerticalAlign.middle:u=(this.height*s-h+c)/2;break;case t.spec.TextVerticalAlign.bottom:u=this.height*s-h-l}return u},i.getOffsetX=function(e,i){var n=0;switch(this.textAlign){case t.spec.TextAlignment.left:n=e.outlineWidth*e.fontScale;break;case t.spec.TextAlignment.middle:n=(this.width*e.fontScale-i)/2;break;case t.spec.TextAlignment.right:n=this.width*e.fontScale-i}return n},i.getOffsetYRich=function(e,i,n){if(0===i.length)return 0;var r=e.outlineWidth,a=e.fontScale,o=i.reduce((function(t,e){return t+e}),0),s=(i[0]-n)/3,l=n+r*a,c=o-i[0],h=0;switch(this.textVerticalAlign){case t.spec.TextVerticalAlign.top:h=l+s;break;case t.spec.TextVerticalAlign.middle:h=(this.height*a-o)/2+l;break;case t.spec.TextVerticalAlign.bottom:h=this.height*a-c-s}return h},i.getOffsetXRich=function(e,i,n){switch(this.textAlign){case t.spec.TextAlignment.left:return e.outlineWidth*e.fontScale;case t.spec.TextAlignment.middle:return(i-n)/2;case t.spec.TextAlignment.right:return i-n;default:return 0}},i.setSize=function(t,e){this.width=t,this.height=e},e}();function T(t,e){if(void 0===e&&(e=1),3!==(t=t.replace(/^#/,"")).length&&4!==t.length||(t=t.split("").map((function(t){return t+t})).join("")),8===t.length){var i=parseInt(t.slice(6,8),16)/255;t=t.slice(0,6),e=i}var n=parseInt(t,16);return[n>>16&255,n>>8&255,255&n,e]}function w(t,i){if(void 0===i&&(i=1),"string"!=typeof t||!t)throw new Error("Invalid color string");return t.startsWith("#")?T(t,i):T(function(t){if("string"!=typeof t||!t)throw new Error("Invalid color name provided");if(void 0===e.document)throw new Error("This method requires a browser environment");var i=e.document.createElement("canvas"),n=i.getContext("2d");if(n)try{return n.fillStyle=t,n.fillStyle}finally{null==i.remove||i.remove.call(i)}throw new Error("Failed to get 2D context for color conversion!")}(t))}var b=function(){function t(){}var e=t.prototype;return e.computeLines=function(t,e,i,n,r,a,o,s){var l=this,c=[],h=[],u=(n.lineHeight||0)*a,f=this.createNewLine(),p=0,x=0,g=function(){if(0!==f.chars.length){f.lineHeight=0===c.length?(f.lineAscent||0)+(f.lineDescent||0):u;var t=0===c.length?0:h[h.length-1]+u;h.push(t),x+=f.lineHeight,c.push(f),p=Math.max(p,f.width),f=l.createNewLine()}};t.forEach((function(t){var n=t.text,r=t.isNewLine,l=t.fontSize;r&&g();var c=t.fontStyle||i.fontStyle||"normal";e.font=c+" "+(t.fontWeight||i.textWeight)+" 10px "+(t.fontFamily||i.fontFamily),f.offsetX.push(f.width);for(var h=0,u=[],p=0,x=0,v=0;v<n.length;v++){var d=n[v],m=e.measureText(d),y=m.width,S=(y<=0?0:y)*l*s*a,T=l*a*s,w=m.actualBoundingBoxAscent*T,b=m.actualBoundingBoxDescent*T;p=Math.max(p,w),x=Math.max(x,b),v>0&&(h+=o),u.push({char:d,x:h}),h+=S}f.chars.push(u),f.width+=h,f.richOptions.push(t),f.lineAscent=Math.max(f.lineAscent||0,p),f.lineDescent=Math.max(f.lineDescent||0,x)})),g();var v=1/0,d=-1/0;if(0===c.length)return{lines:c,maxLineWidth:p,totalHeight:x,bboxTop:0,bboxBottom:0,bboxHeight:0};for(var m=0;m<c.length;m++)v=Math.min(v,h[m]-(c[m].lineAscent||0)),d=Math.max(d,h[m]+(c[m].lineDescent||0));return{lines:c,maxLineWidth:p,totalHeight:x,bboxTop:v,bboxBottom:d,bboxHeight:d-v}},e.createNewLine=function(){return{richOptions:[],offsetX:[],width:0,lineHeight:0,offsetY:0,chars:[],lineAscent:0,lineDescent:0}},t}(),A=function(){function t(){}var e=t.prototype;return e.computeLines=function(t,e,i,n,r,a,o,s){var l=this,c=[],h=[],u=(n.lineHeight||0)*a,f=this.createNewLine(),p=0,x=0,g=null,v=0,d=[],m=null,y=function(){if(S(),0!==f.chars.length){f.lineHeight=0===c.length?(f.lineAscent||0)+(f.lineDescent||0):u;var t=0===c.length?0:h[h.length-1]+u;h.push(t),x+=f.lineHeight,c.push(f),p=Math.max(p,f.width),f=l.createNewLine(),g=null,v=0,d=[],m=null}},S=function(){0!==d.length&&(null===g&&(g=f.width),f.offsetX.push(g),f.chars.push(d),m&&f.richOptions.push(m),g=null,v=0,d=[],m=null)};t.forEach((function(t){var r=t.text,l=t.isNewLine,c=t.fontSize,h=t.fontStyle||i.fontStyle||"normal";e.font=h+" "+(t.fontWeight||i.textWeight)+" 10px "+(t.fontFamily||i.fontFamily),l&&(S(),y());for(var u=0;u<r.length;u++){var p=r[u],x=e.measureText(p),T=x.width,w=(T<=0?0:T)*c*s*a,b=c*a*s,A=x.actualBoundingBoxAscent*b,O=x.actualBoundingBoxDescent*b,z=d.length>0?o:0;f.width+z+w>(n.maxTextWidth*a||1/0)&&(S(),y()),null===g&&(g=f.width,m=t),d.length>0&&(v+=o,f.width+=o),d.push({char:p,x:v}),f.lineAscent=Math.max(f.lineAscent||0,A),f.lineDescent=Math.max(f.lineDescent||0,O),v+=w,f.width+=w}S()})),y();for(var T=1/0,w=-1/0,b=0;b<c.length;b++)T=Math.min(T,h[b]-(c[b].lineAscent||0)),w=Math.max(w,h[b]+(c[b].lineDescent||0));return{lines:c,maxLineWidth:p,totalHeight:x,bboxTop:T,bboxBottom:w,bboxHeight:w-T}},e.createNewLine=function(){return{richOptions:[],offsetX:[],width:0,lineHeight:0,offsetY:0,chars:[],lineAscent:0,lineDescent:0}},t}(),O=function(){function t(){}return t.prototype.apply=function(t,e,i,n){var r,a,o=function(t,e){return Math.abs(e)>1e-5?t/e:1},s=i.maxTextWidth*n.fontScale,l=i.maxTextHeight*n.fontScale,c=Math.max(1,null!=(r=e.contentWidth)?r:e.canvasWidth),h=Math.max(1,null!=(a=e.bboxHeight)?a:e.canvasHeight),u=Math.min(1,o(s,c),o(l,h));if(u>.9999)return{globalScale:1};for(var f,x=p(t);!(f=x()).done;){var g=f.value;if(g.width*=u,g.lineHeight*=u,g.offsetX)for(var v=0;v<g.offsetX.length;v++)g.offsetX[v]*=u;for(var d,m=p(g.chars||[]);!(d=m()).done;)for(var y,S=p(d.value);!(y=S()).done;){y.value.x*=u}for(var T,w=p(g.richOptions||[]);!(T=w()).done;){T.value.fontSize*=u}null!=g.lineAscent&&(g.lineAscent*=u),null!=g.lineDescent&&(g.lineDescent*=u)}return{globalScale:u}},t}(),z=function(){function t(){}return t.prototype.apply=function(t,e,i,n){return{globalScale:1}},t}(),C=function(){function t(){}return t.prototype.apply=function(t,e,i,n){return{globalScale:1}},t}(),L=function(){function e(){}return e.prototype.getHorizontalOffsets=function(e,i,n,r,a){var o,s,l=null!=(o=i.containerWidth)?o:r.maxTextWidth*a.fontScale,c=null!=(s=i.baselineCompensationX)?s:0,h=e.map((function(t){return r.getOffsetXRich(a,l,t.width)}));return{lineOffsets:r.overflow===t.spec.TextOverflow.visible?h.map((function(t){return t+c})):h}},e}(),H=function(){function e(){}return e.prototype.getVerticalOffsets=function(e,i,n,r,a,o){var s,l=null!=(s=i.baselineCompensationY)?s:0,c=0;if(0===e.length)return{baselineY:0,lineYOffsets:[]};switch(r.overflow){case t.spec.TextOverflow.visible:var h,u,f,p,x=r.maxTextHeight*a.fontScale,g=null!=(h=i.bboxTop)?h:0,v=null!=(f=i.bboxBottom)?f:g+(null!=(u=i.bboxHeight)?u:0),d=null!=(p=i.bboxHeight)?p:v-g,m=0;switch(r.textVerticalAlign){case t.spec.TextVerticalAlign.top:m=-g;break;case t.spec.TextVerticalAlign.middle:m=(x-d)/2-g;break;case t.spec.TextVerticalAlign.bottom:m=x-d-g}c=m+l;break;case t.spec.TextOverflow.clip:for(var y=r.maxTextHeight*a.fontScale,S=[0],T=1;T<e.length;T++)S[T]=S[T-1]+e[T].lineHeight;for(var w=1/0,b=-1/0,A=0;A<e.length;A++){var O,z,C=null!=(O=e[A].lineAscent)?O:0,L=null!=(z=e[A].lineDescent)?z:0;w=Math.min(w,S[A]-C),b=Math.max(b,S[A]+L)}var H=b-w,E=0;switch(r.textVerticalAlign){case t.spec.TextVerticalAlign.top:E=-w;break;case t.spec.TextVerticalAlign.middle:E=(y-H)/2-w;break;case t.spec.TextVerticalAlign.bottom:E=y-H-w}c=E+l;break;case t.spec.TextOverflow.display:for(var W=r.maxTextHeight*a.fontScale,M=[0],V=1;V<e.length;V++)M[V]=M[V-1]+e[V].lineHeight;for(var k=1/0,R=-1/0,D=0;D<e.length;D++){var F,B,_=null!=(F=e[D].lineAscent)?F:0,P=null!=(B=e[D].lineDescent)?B:0;k=Math.min(k,M[D]-_),R=Math.max(R,M[D]+P)}var X=R-k,Y=0;switch(r.textVerticalAlign){case t.spec.TextVerticalAlign.top:Y=-k;break;case t.spec.TextVerticalAlign.middle:Y=(W-X)/2-k;break;case t.spec.TextVerticalAlign.bottom:Y=W-X-k}for(var j=[],N=Y,I=0;I<e.length;I++)j.push(N),I<e.length-1&&(N+=e[I+1].lineHeight);return{baselineY:Y,lineYOffsets:j}}var U=[],q=c;return e.forEach((function(t,i){U.push(q),i<e.length-1&&(q+=e[i+1].lineHeight)})),{baselineY:c,lineYOffsets:U}},e}(),E=function(){function e(){}return e.createWrapStrategy=function(t){return t?new A:new b},e.createOverflowStrategy=function(e){switch(e){case t.spec.TextOverflow.clip:return new z;case t.spec.TextOverflow.display:return new O;case t.spec.TextOverflow.visible:default:return new C}},e.createHorizontalAlignStrategy=function(){return new L},e.createVerticalAlignStrategy=function(){return new H},e}(),W=0;exports.RichTextComponent=function(e){function i(i){var n;return(n=e.call(this,i)||this).isDirty=!0,n.text="",n.processedTextOptions=[],n.singleLineHeight=1.571,n.size=null,n.initialized=!1,n.canvasSize=null,n.SCALE_FACTOR=.11092565,n.ALPHA_FIX_VALUE=1/255,n.name="MRichText"+W++,n.initTextBase(i),n.richWrapStrategy=E.createWrapStrategy(),n.richOverflowStrategy=E.createOverflowStrategy(t.spec.TextOverflow.display),n.richHorizontalAlignStrategy=E.createHorizontalAlignStrategy(),n.richVerticalAlignStrategy=E.createVerticalAlignStrategy(),n}a(i,e);var n=i.prototype;return n.onUpdate=function(t){e.prototype.onUpdate.call(this,t),this.updateTexture()},n.onDestroy=function(){e.prototype.onDestroy.call(this),this.disposeTextTexture()},n.fromData=function(i){e.prototype.fromData.call(this,i);var n=i.interaction,r=i.options;this.interaction=n,this.textStyle=new t.TextStyle(r),this.textLayout=new S(r),this.text=r.text?r.text.toString():" ",this.textLayout.useLegacyRichText&&(this.textLayout.textVerticalAlign=t.spec.TextVerticalAlign.middle),this.updateStrategies(),this.renderText(r),this.material.setColor("_Color",new t.math.Color(1,1,1,1))},n.updateStrategies=function(){var t=this.textLayout;t&&(this.richWrapStrategy=E.createWrapStrategy(t.wrapEnabled),this.richOverflowStrategy=E.createOverflowStrategy(t.overflow))},n.generateTextProgram=function(e){var i=this;this.processedTextOptions=[];var n=y((function(e,n){/^\n+$/.test(e)&&(e=e.replace(/\n/g,"\n ")),e.split("\n").forEach((function(e,r){var a={text:e,fontSize:i.textStyle.fontSize,isNewLine:!1};r>0&&(a.isNewLine=!0),"b"in n&&(a.fontWeight=t.spec.TextWeight.bold),"i"in n&&(a.fontStyle=t.spec.FontStyle.italic),"size"in n&&n.size&&(a.fontSize=parseInt(n.size,10)),"color"in n&&n.color&&(a.fontColor=w(n.color)),i.processedTextOptions.push(a)}))}));n(e)},n.updateWithOptions=function(e){this.textStyle=new t.TextStyle(e),this.textLayout=new S(e),this.text=e.text?e.text.toString():" ",this.textLayout.useLegacyRichText&&(this.textLayout.textVerticalAlign=t.spec.TextVerticalAlign.middle),this.updateStrategies(),this.isDirty=!0},n.renderText=function(e){var i=e.size;i&&(this.canvasSize=new t.math.Vector2(i[0],i[1])),this.updateTexture()},n.updateTexture=function(t){if(void 0===t&&(t=!0),this.isDirty&&this.context&&this.canvas&&this.textStyle&&this.textLayout){var e=!0===this.textLayout.useLegacyRichText;this.singleLineHeight=e?1.571:1,e?this.updateTextureLegacy(t):this.updateTextureWithStrategies(t)}},n.updateTextureLegacy=function(e){var i=this;if(this.isDirty&&this.context&&this.canvas&&this.textStyle){var n=.1;this.generateTextProgram(this.text);var r=0,a=0,o=this.textLayout,s=this.textStyle,l=o.overflow,c=o.letterSpace,h=void 0===c?0:c,u=this.context,f=[],p=s.fontSize*s.fontScale,x={richOptions:[],offsetX:[],width:0,lineHeight:p*this.singleLineHeight,offsetY:p*(this.singleLineHeight-1)/2};if(this.processedTextOptions.forEach((function(t){var e=t.text,o=t.isNewLine,l=t.fontSize;o&&(f.push(x),r=Math.max(r,x.width),x={richOptions:[],offsetX:[],width:0,lineHeight:p*i.singleLineHeight,offsetY:p*(i.singleLineHeight-1)/2},a+=x.lineHeight),u.font=(t.fontWeight||s.textWeight)+" 10px "+(t.fontFamily||s.fontFamily);var c=u.measureText(e),g=c.width;if(void 0!==c.actualBoundingBoxLeft&&void 0!==c.actualBoundingBoxRight){var v=c.actualBoundingBoxLeft+c.actualBoundingBoxRight;v>0&&(g=Math.max(g,v))}var d=l*i.singleLineHeight*s.fontScale;d>x.lineHeight&&(a+=d-x.lineHeight,x.lineHeight=d,x.offsetY=l*s.fontScale*(i.singleLineHeight-1)/2),x.offsetX.push(x.width),x.width+=(g<=0?0:g)*l*n*s.fontScale+e.length*h,x.richOptions.push(t)})),f.push(x),r=Math.max(r,x.width),a+=x.lineHeight,0!==r&&0!==a){void 0!==this.size&&null!==this.size||(this.size=this.item.transform.size.clone());var g=this.size,v=g.x,d=void 0===v?1:v,m=g.y,y=void 0===m?1:m;if(!this.initialized){this.canvasSize=this.canvasSize?this.canvasSize:new t.math.Vector2(r,a);var S=this.canvasSize,T=S.x,w=S.y;this.item.transform.size.set(d*T*n*n,y*w*n*n),this.size=this.item.transform.size.clone(),this.initialized=!0}t.assertExist(this.canvasSize);var b=this.canvasSize,A=b.x,O=b.y;o.width=A/s.fontScale,o.height=O/s.fontScale,this.renderToTexture(A,O,e,(function(e){if(0!==f.length){var n=o.getOffsetY(s,f.length,p*i.singleLineHeight,s.fontSize);f.forEach((function(i,r){var a=i.richOptions,c=i.offsetX,h=i.width,u=h,f=c;if(l===t.spec.TextOverflow.display&&h>A){var p=A/h;u*=p,f=c.map((function(t){return t*p}))}var x=o.getOffsetX(s,u);r>0&&(n+=i.lineHeight-i.offsetY),a.forEach((function(i,r){var a=s.fontScale,o=s.textColor,c=s.fontFamily,u=s.textWeight,p=s.fontStyle,g=i.text,v=i.fontSize,d=i.fontColor,m=void 0===d?o:d,y=i.fontFamily,S=void 0===y?c:y,T=i.fontWeight,w=void 0===T?u:T,b=i.fontStyle,O=void 0===b?p:b,z=v;l===t.spec.TextOverflow.display&&h>A&&(z/=h/A);var C=f[r]+x;e.font=O+" "+w+" "+z*a+"px "+S;var L=m[0],H=m[1],E=m[2],W=m[3];e.fillStyle="rgba("+L+", "+H+", "+E+", "+W+")",e.fillText(g,C,n)}))}))}}),{disposeOld:!1}),this.isDirty=!1}else this.isDirty=!1}},n.updateTextureWithStrategies=function(e){var i=this;if(this.isDirty&&this.context&&this.canvas){this.generateTextProgram(this.text);var n=this.textLayout,r=n.letterSpace,a=void 0===r?0:r,o=this.context;if(o){var s=this.richWrapStrategy.computeLines(this.processedTextOptions,o,this.textStyle,n,this.singleLineHeight,this.textStyle.fontScale,a,this.SCALE_FACTOR);if(0!==s.lines.length&&0!==s.maxLineWidth&&0!==s.totalHeight){var l=this.resolveCanvasSize(s,n,this.textStyle,this.singleLineHeight);this.setCanvasSize(l);var c=this.richOverflowStrategy.apply(s.lines,l,n,this.textStyle),h=this.richHorizontalAlignStrategy.getHorizontalOffsets(s.lines,l,c,n,this.textStyle),u=this.richVerticalAlignStrategy.getVerticalOffsets(s.lines,l,c,n,this.textStyle,this.singleLineHeight);t.assertExist(this.canvasSize);var f=this.canvasSize,p=f.x,x=f.y,g=Math.max(1,Math.ceil(p)),v=Math.max(1,Math.ceil(x));n.width=g/this.textStyle.fontScale,n.height=v/this.textStyle.fontScale,this.renderToTexture(g,v,e,(function(t){i.drawTextWithStrategies(t,s.lines,h,u,c,i.textStyle)}),{disposeOld:!1}),this.isDirty=!1}else this.isDirty=!1}}},n.setCanvasSize=function(e){var i=this;void 0!==this.size&&null!==this.size||(this.size=this.item.transform.size.clone());var n=this.size,r=n.x,a=void 0===r?1:r,o=n.y,s=void 0===o?1:o,l=this.textLayout,c=this.textStyle.fontScale||1,h=Math.max(1,l.maxTextWidth||0),u=Math.max(1,l.maxTextHeight||0);switch(l.overflow){case t.spec.TextOverflow.visible:var f,p,x,g,v=h*c,d=u*c,m=null!=(f=e.bboxTop)?f:0,y=null!=(x=e.bboxBottom)?x:m+(null!=(p=e.bboxHeight)?p:0),S=null!=(g=e.bboxHeight)?g:y-m,T=0;switch(l.textVerticalAlign){case t.spec.TextVerticalAlign.top:T=-m;break;case t.spec.TextVerticalAlign.middle:T=(d-S)/2-m;break;case t.spec.TextVerticalAlign.bottom:T=d-S-m}var w=T+m,b=T+y,A=Math.max(0,-w),O=Math.max(0,b-d),z=A,C=O;switch(l.textVerticalAlign){case t.spec.TextVerticalAlign.top:z=O,C=O;break;case t.spec.TextVerticalAlign.bottom:z=A,C=A;break;case t.spec.TextVerticalAlign.middle:z=A,C=O}for(var L=z,H=e.lines||[],E=H.map((function(t){return l.getOffsetXRich(i.textStyle,v,t.width)})),W=1/0,M=-1/0,V=0;V<H.length;V++){var k,R,D=null!=(k=E[V])?k:0,F=null!=(R=H[V].width)?R:0;W=Math.min(W,D),M=Math.max(M,D+F)}isFinite(W)||(W=0),isFinite(M)||(M=0);var B,_=Math.max(0,-W),P=Math.max(0,M-v),X=Math.ceil(v+_+P),Y=Math.ceil(d+z+C);e.baselineCompensationX=_,e.baselineCompensationY=L,e.containerWidth=v,e.canvasWidth=X,e.canvasHeight=Y,this.canvasSize=new t.math.Vector2(X,Y);var j=null!=(B=this.size)?B:this.item.transform.size,N=j.x,I=void 0===N?1:N,U=j.y,q=void 0===U?1:U;this.item.transform.size.set(I*X/c*this.SCALE_FACTOR*this.SCALE_FACTOR,q*Y/c*this.SCALE_FACTOR*this.SCALE_FACTOR),this.initialized=!0;break;case t.spec.TextOverflow.clip:var $,G=h*c,J=u*c;e.canvasWidth=G,e.canvasHeight=J,e.baselineCompensationX=0,e.baselineCompensationY=0,this.canvasSize=new t.math.Vector2(G,J),l.width=h,l.height=u;var K=null!=($=this.size)?$:this.item.transform.size,Q=K.x,Z=void 0===Q?1:Q,tt=K.y,et=void 0===tt?1:tt;this.item.transform.size.set(Z*G/c*this.SCALE_FACTOR*this.SCALE_FACTOR,et*J/c*this.SCALE_FACTOR*this.SCALE_FACTOR),this.initialized=!0;break;case t.spec.TextOverflow.display:if(!this.initialized){var it=h*c,nt=u*c;this.canvasSize=new t.math.Vector2(it,nt),this.item.transform.size.set(a*it/c*this.SCALE_FACTOR*this.SCALE_FACTOR,s*nt/c*this.SCALE_FACTOR*this.SCALE_FACTOR),this.initialized=!0}}},n.resolveCanvasSize=function(t,e,i,n){var r=Math.max(1,t.maxLineWidth||0),a=Math.max(1,t.totalHeight||0);return e.width=r/i.fontScale,e.height=a/i.fontScale,{canvasWidth:r,canvasHeight:a,contentWidth:t.maxLineWidth,bboxTop:t.bboxTop,bboxBottom:t.bboxBottom,bboxHeight:t.bboxHeight,lines:t.lines}},n.drawTextWithStrategies=function(t,e,i,n,r,a){var o=n.baselineY,s=i.lineOffsets;e.forEach((function(i,n){var r=i.richOptions,l=i.chars,c=s[n],h=o;r.forEach((function(e,n){var r=a.fontScale,o=a.textColor,s=a.fontFamily,u=a.textWeight,f=a.fontStyle,p=e.fontSize,x=e.fontColor,g=void 0===x?o:x,v=e.fontFamily,d=void 0===v?s:v,m=e.fontWeight,y=void 0===m?u:m,S=e.fontStyle,T=void 0===S?f:S,w=p;t.font=T+" "+y+" "+w*r+"px "+d;var b=g[0],A=g[1],O=g[2],z=g[3];t.fillStyle="rgba("+b+", "+A+", "+O+", "+z+")";var C=i.offsetX&&i.offsetX[n]?i.offsetX[n]:0;l[n].forEach((function(e){t.fillText(e.char,c+C+e.x,h)}))})),n<e.length-1&&(o+=e[n+1].lineHeight)}))},n.unsupported=function(t){throw new Error("RichTextComponent does not support "+t+" at runtime.")},n.setShadowOffsetY=function(t){this.unsupported("setShadowOffsetY")},n.setShadowBlur=function(t){this.unsupported("setShadowBlur")},n.setShadowOffsetX=function(t){this.unsupported("setShadowOffsetX")},n.setShadowColor=function(t){this.unsupported("setShadowColor")},n.setOutlineWidth=function(t){this.unsupported("setOutlineWidth")},n.setAutoWidth=function(t){this.unsupported("setAutoWidth")},n.setFontSize=function(t){this.unsupported("setFontSize")},n.setTextBaseline=function(t){console.warn("setTextBaseline 已废弃,请改用 setTextVerticalAlign。本次调用将转调用 setTextVerticalAlign。"),this.setTextVerticalAlign(t)},i}(t.MaskableGraphic),exports.RichTextComponent=function(t,e,i,n){var r,a=arguments.length,o=a<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,i):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,e,i,n);else for(var s=t.length-1;s>=0;s--)(r=t[s])&&(o=(a<3?r(o):a>3?r(e,i,o):r(e,i))||o);return a>3&&o&&Object.defineProperty(e,i,o),o}([t.effectsClass(t.spec.DataType.RichTextComponent)],exports.RichTextComponent),t.applyMixins(exports.RichTextComponent,[t.TextComponentBase]);var M="2.8.7";t.registerPlugin("rich-text",u),t.logger.info("Plugin rich text version: 2.8.7."),M!==n.version&&console.error("注意:请统一 RichText 插件与 Player 版本,不统一的版本混用会有不可预知的后果!","\nAttention: Please ensure the RichText plugin is synchronized with the Player version. Mixing and matching incompatible versions may result in unpredictable consequences!"),exports.RichTextLoader=u,exports.escape=function(t){if("string"!=typeof t)throw new Error("Input must be a string");return t.replace(/\\/g,"\\\\").replace(/=/g,"\\=").replace(/</g,"\\<").replace(/>/g,"\\>").replace(/\//g,"\\/")},exports.generateProgram=y,exports.isRichText=function(t){var e=d(t).filter((function(t){var e=t.tokenType;return"ContextStart"===e||"ContextEnd"===e})),i=e.filter((function(t){return"ContextStart"===t.tokenType})),n=e.filter((function(t){return"ContextEnd"===t.tokenType}));return!(i.length!==n.length||!i.length)&&function t(e,i){var n=e[0],r=e.slice(1);if(void 0===i&&(i=[]),!n)return 0===i.length;if("ContextStart"===n.tokenType)return t(r,i.concat(n.value));if("ContextEnd"===n.tokenType)return i[i.length-1]===n.value&&t(r,i.slice(0,-1));throw new Error("Unexpected token: "+n.tokenType)}(e.map((function(t){var e=t.tokenType,i=t.value;return{tokenType:e,value:"ContextStart"===e?i.match(x)[1]:i.match(g)[1]}})))},exports.lexer=d,exports.richTextParser=m,exports.unescape=function(t){if("string"!=typeof t)throw new Error("Input must be a string");return t.replace(/\\\//g,"/").replace(/\\>/g,">").replace(/\\</g,"<").replace(/\\=/g,"=").replace(/\\\\/g,"\\")},exports.version=M;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@galacean/effects/weapp"),e=require("@galacean/appx-adapter/weapp");function i(t){if(t&&t.__esModule)return t;var e=Object.create(null);return t&&Object.keys(t).forEach((function(i){if("default"!==i){var n=Object.getOwnPropertyDescriptor(t,i);Object.defineProperty(e,i,n.get?n:{enumerable:!0,get:function(){return t[i]}})}})),e.default=t,Object.freeze(e)}var n=i(t);function r(t,e){return r=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},r(t,e)}function o(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&r(t,e)}function a(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(a=function(){return!!t})()}function s(t,e,i){return s=a()?Reflect.construct:function(t,e,i){var n=[null];n.push.apply(n,e);var o=new(Function.bind.apply(t,n));return i&&r(o,i.prototype),o},s.apply(null,arguments)}function l(t){return l=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},l(t)}function c(t){var e="function"==typeof Map?new Map:void 0;return c=function(t){if(null===t||(i=t,-1===Function.toString.call(i).indexOf("[native code]")))return t;var i;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,n)}function n(){return s(t,arguments,l(this).constructor)}return n.prototype=Object.create(t.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),r(n,t)},c(t)}var h,u=function(t){function e(){var e;return(e=t.apply(this,arguments)||this).name="rich-text",e}return o(e,t),e}(c(t.Plugin));function f(t,e){(null==e||e>t.length)&&(e=t.length);for(var i=0,n=new Array(e);i<e;i++)n[i]=t[i];return n}function p(t,e){var i="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(i)return(i=i.call(t)).next.bind(i);if(Array.isArray(t)||(i=function(t,e){if(t){if("string"==typeof t)return f(t,e);var i=Object.prototype.toString.call(t).slice(8,-1);return"Object"===i&&t.constructor&&(i=t.constructor.name),"Map"===i||"Set"===i?Array.from(i):"Arguments"===i||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i)?f(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){i&&(t=i);var n=0;return function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}!function(t){t.ContextStart="ContextStart",t.Text="Text",t.ContextEnd="ContextEnd",t.EscapedChar="EscapedChar"}(h||(h={}));var x=/^<([a-z]+)(=([^>]+))?>$/,g=/^<\/([a-z]+)>$/,d=[["EscapedChar",/^\\([=<>\\/])/],["ContextStart",/^<[a-z]+(=[^>]+)?>/],["ContextEnd",/^<\/[a-z]+>/],["Text",/^[^</>=\\]+/]],v=function(t,e,i){if(void 0===e&&(e=[]),void 0===i&&(i=0),!t)return e;var n=/^\\([=<>\\/])/.exec(t);if(n){var r=n[1];return v(t.slice(2),e.concat({tokenType:"Text",value:r}),i+2)}for(var o,a=p(d);!(o=a()).done;){var s=o.value,l=s[0],c=s[1];if("EscapedChar"!==l){var h=c.exec(t);if(h){var u=h[0],f=u.length;return v(t.slice(f),e.concat({tokenType:l,value:u}),i+f)}}}if(t.length>0)return v(t.slice(1),e.concat({tokenType:"Text",value:t[0]}),i+1);throw new Error('Unexpected token: "'+t[0]+'" at position '+i+' while reading "'+t+'"')},m=function(t){var e=function(){for(var t,e="",i=!1;r.length>0&&"Text"===(null==(t=r[0])?void 0:t.tokenType);){var n=a();n&&(e+=n.value,i=!0)}return i?e:void 0},i=function(){var t=s();if("ContextStart"===(null==t?void 0:t.tokenType)){a();var e,i=t.value.match(x);if(i)return{attributeName:i[1],attributeParam:null!=(e=i[3])?e:""};throw new Error("Expected a start tag marker at position "+o)}return{}},n=function(){var t=s();if("ContextEnd"===(null==t?void 0:t.tokenType)){a();var e=t.value.match(g);if(e)return{attributeName:e[1]};throw new Error("Expect an end tag marker at position "+o)}return{}},r=v(t),o=0,a=function(){var t,e=r.shift();return o+=null!=(t=null==e?void 0:e.value.length)?t:0,e},s=function(){return r[0]},l=[];return function t(r,a){for(void 0===r&&(r=[]),void 0===a&&(a="");;){var s=e();if(s)l.push({attributes:r,text:s});else{var c=i(),h=c.attributeName,u=c.attributeParam;if(!h){if(a){var f=n().attributeName;if(!f)throw new Error('Expect an end tag marker "'+a+'" at position '+o+" but found no tag!");if(f!==a)throw new Error('Expect an end tag marker "'+a+'" at position '+o+' but found tag "'+f+'"');return}break}t(r.concat({attributeName:h,attributeParam:null!=u?u:""}),h)}}}(),l};function y(t){return function(e){for(var i,n=p(m(e));!(i=n()).done;){var r=i.value,o=r.text,a=r.attributes.reduce((function(t,e){var i=e.attributeName,n=e.attributeParam;return i&&(t[i]=n),t}),{});t(o,a)}}}"function"==typeof SuppressedError&&SuppressedError;var w=function(){function e(e){this.width=0,this.height=0;var i=e.size,n=e.textOverflow,r=void 0===n?t.spec.TextOverflow.clip:n,o=e.textVerticalAlign,a=void 0===o?t.spec.TextVerticalAlign.middle:o,s=e.textAlign,l=void 0===s?t.spec.TextAlignment.left:s,c=e.letterSpace,h=void 0===c?0:c,u=e.lineHeight,f=void 0===u?.571:u,p=e.wrapEnabled,x=void 0!==p&&p,g=e.maxTextWidth,d=void 0===g?350:g,v=e.maxTextHeight,m=void 0===v?1e3:v,y=e.autoResize,w=void 0===y?t.spec.TextSizeMode.autoWidth:y,T=e.useLegacyRichText,S=void 0!==T&&T;this.letterSpace=h,this.lineHeight=f,this.useLegacyRichText=S,this.overflow=r,this.textVerticalAlign=a,this.textAlign=l,this.width=i?i[0]:100,this.height=i?i[1]:100,this.wrapEnabled=x,this.maxTextWidth=d,this.maxTextHeight=m,this.autoResize=w}var i=e.prototype;return i.getOffsetY=function(e,i,n,r,o){var a=e.outlineWidth,s=e.fontScale,l=(n-r)/3,c=r+a*s,h=void 0!==o?o:n*(i-1),u=0;switch(this.textVerticalAlign){case t.spec.TextVerticalAlign.top:u=c+l;break;case t.spec.TextVerticalAlign.middle:u=(this.height*s-h+c)/2;break;case t.spec.TextVerticalAlign.bottom:u=this.height*s-h-l}return u},i.getOffsetX=function(e,i){var n=0;switch(this.textAlign){case t.spec.TextAlignment.left:n=e.outlineWidth*e.fontScale;break;case t.spec.TextAlignment.middle:n=(this.width*e.fontScale-i)/2;break;case t.spec.TextAlignment.right:n=this.width*e.fontScale-i}return n},i.getOffsetYRich=function(e,i,n){if(0===i.length)return 0;var r=e.outlineWidth,o=e.fontScale,a=i.reduce((function(t,e){return t+e}),0),s=(i[0]-n)/3,l=n+r*o,c=a-i[0],h=0;switch(this.textVerticalAlign){case t.spec.TextVerticalAlign.top:h=l+s;break;case t.spec.TextVerticalAlign.middle:h=(this.height*o-a)/2+l;break;case t.spec.TextVerticalAlign.bottom:h=this.height*o-c-s}return h},i.getOffsetXRich=function(e,i,n){switch(this.textAlign){case t.spec.TextAlignment.left:return e.outlineWidth;case t.spec.TextAlignment.middle:return(i-n)/2;case t.spec.TextAlignment.right:return i-n;default:return 0}},i.setSize=function(t,e){this.width=t,this.height=e},e}();function T(t,e){if(void 0===e&&(e=1),3!==(t=t.replace(/^#/,"")).length&&4!==t.length||(t=t.split("").map((function(t){return t+t})).join("")),8===t.length){var i=parseInt(t.slice(6,8),16)/255;t=t.slice(0,6),e=i}var n=parseInt(t,16);return[n>>16&255,n>>8&255,255&n,e]}function S(t,i){if(void 0===i&&(i=1),"string"!=typeof t||!t)throw new Error("Invalid color string");return t.startsWith("#")?T(t,i):T(function(t){if("string"!=typeof t||!t)throw new Error("Invalid color name provided");if(void 0===e.document)throw new Error("This method requires a browser environment");var i=e.document.createElement("canvas"),n=i.getContext("2d");if(n)try{return n.fillStyle=t,n.fillStyle}finally{null==i.remove||i.remove.call(i)}throw new Error("Failed to get 2D context for color conversion!")}(t))}var b=function(){function t(){}var e=t.prototype;return e.computeLines=function(t,e,i,n,r){var o=this,a=[],s=[],l=n.lineHeight||0,c=this.createNewLine(),h=0,u=0,f=function(){if(0!==c.chars.length){c.lineHeight=l;var t=0===a.length?0:s[s.length-1]+l;s.push(t),u+=c.lineHeight,a.push(c),h=Math.max(h,c.width),c=o.createNewLine()}};t.forEach((function(t){var n=t.text,o=t.isNewLine,a=t.fontSize;o&&f();var s=t.fontStyle||i.fontStyle||"normal";e.font=s+" "+(t.fontWeight||i.textWeight)+" 10px "+(t.fontFamily||i.fontFamily),c.offsetX.push(c.width);for(var l=.1*a,h=e.measureText("x"),u=h.fontBoundingBoxAscent*l,p=h.fontBoundingBoxDescent*l,x=0,g=[],d=0;d<n.length;d++){var v=n[d],m=e.measureText(v).width,y=(m<=0?0:m)*l;d>0&&(x+=r),g.push({char:v,x:x}),x+=y}c.chars.push(g),c.width+=x,c.richOptions.push(t),c.lineAscent=Math.max(c.lineAscent||0,u),c.lineDescent=Math.max(c.lineDescent||0,p)})),f();var p=1/0,x=-1/0;if(0===a.length)return{lines:a,maxLineWidth:h,totalHeight:u,bboxTop:0,bboxBottom:0,bboxHeight:0};for(var g=0;g<a.length;g++){var d=a[g].lineAscent||0,v=a[g].lineDescent||0,m=(l-(d+v))/2;p=Math.min(p,s[g]-d-m),x=Math.max(x,s[g]+v+m)}return{lines:a,maxLineWidth:h,totalHeight:u,bboxTop:p,bboxBottom:x,bboxHeight:x-p}},e.createNewLine=function(){return{richOptions:[],offsetX:[],width:0,lineHeight:0,offsetY:0,chars:[],lineAscent:0,lineDescent:0}},t}(),O=function(){function t(){}var e=t.prototype;return e.computeLines=function(t,e,i,n,r){var o=this,a=[],s=[],l=n.lineHeight||0,c=n.maxTextWidth||1/0,h=this.createNewLine(),u=0,f=0,p=null,x=0,g=[],d=null,v=function(){if(m(),0!==h.chars.length){h.lineHeight=l;var t=0===a.length?0:s[s.length-1]+l;s.push(t),f+=h.lineHeight,a.push(h),u=Math.max(u,h.width),h=o.createNewLine(),p=null,x=0,g=[],d=null}},m=function(){0!==g.length&&(null===p&&(p=h.width),h.offsetX.push(p),h.chars.push(g),d&&h.richOptions.push(d),p=null,x=0,g=[],d=null)};t.forEach((function(t){var n=t.text,o=t.isNewLine,a=t.fontSize,s=t.fontStyle||i.fontStyle||"normal";e.font=s+" "+(t.fontWeight||i.textWeight)+" 10px "+(t.fontFamily||i.fontFamily),o&&(m(),v());for(var l=.1*a,u=e.measureText("x"),f=u.fontBoundingBoxAscent*l,y=u.fontBoundingBoxDescent*l,w=0;w<n.length;w++){var T=n[w],S=e.measureText(T).width,b=(S<=0?0:S)*l,O=g.length>0?r:0;h.width+O+b>c&&(m(),v()),null===p&&(p=h.width,d=t),g.length>0&&(x+=r,h.width+=r),g.push({char:T,x:x}),h.lineAscent=Math.max(h.lineAscent||0,f),h.lineDescent=Math.max(h.lineDescent||0,y),x+=b,h.width+=b}m()})),v();var y=1/0,w=-1/0;if(0===a.length)return{lines:a,maxLineWidth:u,totalHeight:f,bboxTop:0,bboxBottom:0,bboxHeight:0};for(var T=0;T<a.length;T++){var S=a[T].lineAscent||0,b=a[T].lineDescent||0,O=(l-(S+b))/2;y=Math.min(y,s[T]-S-O),w=Math.max(w,s[T]+b+O)}return{lines:a,maxLineWidth:u,totalHeight:f,bboxTop:y,bboxBottom:w,bboxHeight:w-y}},e.createNewLine=function(){return{richOptions:[],offsetX:[],width:0,lineHeight:0,offsetY:0,chars:[],lineAscent:0,lineDescent:0}},t}(),A=function(){function t(){}return t.prototype.resolveCanvas=function(t,e,i,n,r){return{canvasWidth:Math.max(1,Math.ceil(e)),canvasHeight:Math.max(1,Math.ceil(i)),renderOffsetX:0,renderOffsetY:0}},t}(),M=function(){function t(){}return t.prototype.resolveCanvas=function(t,e,i,n,r){if(0===t.length)return{canvasWidth:Math.max(1,e),canvasHeight:Math.max(1,i),renderOffsetX:0,renderOffsetY:0};for(var o=1/0,a=-1/0,s=r.baselineY,l=0;l<t.length;l++){var c,h,u=null!=(c=t[l].lineAscent)?c:0,f=null!=(h=t[l].lineDescent)?h:0,p=u+f,x=Math.max(0,(t[l].lineHeight-p)/2);o=Math.min(o,s-u-x),a=Math.max(a,s+f+x),l<t.length-1&&(s+=t[l+1].lineHeight)}for(var g=Math.max(0,-o),d=Math.max(0,a-i),v=Math.max(g,d),m=1/0,y=-1/0,w=0;w<t.length;w++){var T,S,b=null!=(T=n.lineOffsets[w])?T:0,O=null!=(S=t[w].width)?S:0;m=Math.min(m,b),y=Math.max(y,b+O)}isFinite(m)||(m=0),isFinite(y)||(y=0);var A=Math.max(0,-m),M=Math.max(0,y-e),H=Math.max(A,M),z=Math.ceil(e+2*H),E=Math.ceil(i+2*v);return{canvasWidth:Math.max(1,z),canvasHeight:Math.max(1,E),renderOffsetX:H,renderOffsetY:v}},t}(),H=function(){function t(){}return t.prototype.getHorizontalOffsets=function(t,e,i,n){return{lineOffsets:t.map((function(t){return i.getOffsetXRich(n,e,t.width)}))}},t}(),z=function(){function e(){}return e.prototype.getVerticalOffsets=function(e,i,n){if(0===e.length)return{baselineY:0,lineYOffsets:[]};for(var r=[0],o=1;o<e.length;o++)r[o]=r[o-1]+e[o].lineHeight;for(var a=1/0,s=-1/0,l=0;l<e.length;l++){var c,h,u=null!=(c=e[l].lineAscent)?c:0,f=null!=(h=e[l].lineDescent)?h:0,p=u+f,x=(e[l].lineHeight-p)/2;a=Math.min(a,r[l]-u-x),s=Math.max(s,r[l]+f+x)}var g=s-a,d=0;switch(n.textVerticalAlign){case t.spec.TextVerticalAlign.top:d=-a;break;case t.spec.TextVerticalAlign.middle:d=(i-g)/2-a;break;case t.spec.TextVerticalAlign.bottom:d=i-g-a}var v=r.map((function(t){return d+t}));return{baselineY:d,lineYOffsets:v}},e}(),E=function(){function e(){}return e.createWrapStrategy=function(t){return t?new O:new b},e.createOverflowStrategy=function(e){switch(e){case t.spec.TextOverflow.clip:return new A;case t.spec.TextOverflow.display:case t.spec.TextOverflow.visible:default:return new M}},e.createHorizontalAlignStrategy=function(){return new H},e.createVerticalAlignStrategy=function(){return new z},e}();function L(){return L=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var i=arguments[e];for(var n in i)Object.prototype.hasOwnProperty.call(i,n)&&(t[n]=i[n])}return t},L.apply(this,arguments)}var W=0;exports.RichTextComponent=function(e){function i(i){var n;return(n=e.call(this,i)||this).isDirty=!0,n.text="",n.processedTextOptions=[],n.singleLineHeight=1.571,n.size=null,n.initialized=!1,n.canvasSize=null,n.SCALE_FACTOR=.11092565,n.ALPHA_FIX_VALUE=1/255,n.name="MRichText"+W++,n.initTextBase(i),n.richWrapStrategy=E.createWrapStrategy(),n.richOverflowStrategy=E.createOverflowStrategy(t.spec.TextOverflow.display),n.richHorizontalAlignStrategy=E.createHorizontalAlignStrategy(),n.richVerticalAlignStrategy=E.createVerticalAlignStrategy(),n}o(i,e);var n=i.prototype;return n.onUpdate=function(t){e.prototype.onUpdate.call(this,t),this.updateTexture()},n.onDestroy=function(){e.prototype.onDestroy.call(this),this.disposeTextTexture()},n.fromData=function(i){e.prototype.fromData.call(this,i);var n=i.interaction,r=i.options;this.interaction=n,this.textStyle=new t.TextStyle(r),this.textLayout=new w(r),this.text=r.text?r.text.toString():" ",this.textLayout.useLegacyRichText&&(this.textLayout.textVerticalAlign=t.spec.TextVerticalAlign.middle),this.updateStrategies(),this.updateTexture(),this.material.setColor("_Color",new t.math.Color(1,1,1,1))},n.updateStrategies=function(){var t=this.textLayout;t&&(this.richWrapStrategy=E.createWrapStrategy(t.wrapEnabled),this.richOverflowStrategy=E.createOverflowStrategy(t.overflow))},n.generateTextProgram=function(e){var i=this;this.processedTextOptions=[];var n=y((function(e,n){/^\n+$/.test(e)&&(e=e.replace(/\n/g,"\n ")),e.split("\n").forEach((function(e,r){var o={text:e,fontSize:i.textStyle.fontSize,isNewLine:!1};r>0&&(o.isNewLine=!0),"b"in n&&(o.fontWeight=t.spec.TextWeight.bold),"i"in n&&(o.fontStyle=t.spec.FontStyle.italic),"size"in n&&n.size&&(o.fontSize=parseInt(n.size,10)),"color"in n&&n.color&&(o.fontColor=S(n.color)),i.processedTextOptions.push(o)}))}));n(e)},n.updateWithOptions=function(e){this.textStyle=new t.TextStyle(e),this.textLayout=new w(e),this.text=e.text?e.text.toString():" ",this.textLayout.useLegacyRichText&&(this.textLayout.textVerticalAlign=t.spec.TextVerticalAlign.middle),this.updateStrategies(),this.isDirty=!0},n.updateTexture=function(t){if(void 0===t&&(t=!0),this.isDirty&&this.context&&this.canvas&&this.textStyle&&this.textLayout){var e=!0===this.textLayout.useLegacyRichText;this.singleLineHeight=e?1.571:1,e?this.updateTextureLegacy(t):this.updateTextureWithStrategies(t)}},n.updateTextureLegacy=function(e){var i=this;if(this.isDirty&&this.context&&this.canvas&&this.textStyle){var n=.1;this.generateTextProgram(this.text);var r=0,o=0,a=this.textLayout,s=this.textStyle,l=a.overflow,c=a.letterSpace,h=void 0===c?0:c,u=this.context,f=[],p=s.fontSize*s.fontScale,x={richOptions:[],offsetX:[],width:0,lineHeight:p*this.singleLineHeight,offsetY:p*(this.singleLineHeight-1)/2};if(this.processedTextOptions.forEach((function(t){var e=t.text,a=t.isNewLine,l=t.fontSize;a&&(f.push(x),r=Math.max(r,x.width),x={richOptions:[],offsetX:[],width:0,lineHeight:p*i.singleLineHeight,offsetY:p*(i.singleLineHeight-1)/2},o+=x.lineHeight),u.font=(t.fontWeight||s.textWeight)+" 10px "+(t.fontFamily||s.fontFamily);var c=u.measureText(e),g=c.width;if(void 0!==c.actualBoundingBoxLeft&&void 0!==c.actualBoundingBoxRight){var d=c.actualBoundingBoxLeft+c.actualBoundingBoxRight;d>0&&(g=Math.max(g,d))}var v=l*i.singleLineHeight*s.fontScale;v>x.lineHeight&&(o+=v-x.lineHeight,x.lineHeight=v,x.offsetY=l*s.fontScale*(i.singleLineHeight-1)/2),x.offsetX.push(x.width),x.width+=(g<=0?0:g)*l*n*s.fontScale+e.length*h,x.richOptions.push(t)})),f.push(x),r=Math.max(r,x.width),o+=x.lineHeight,0!==r&&0!==o){void 0!==this.size&&null!==this.size||(this.size=this.item.transform.size.clone());var g=this.size,d=g.x,v=void 0===d?1:d,m=g.y,y=void 0===m?1:m;if(!this.initialized){this.canvasSize=this.canvasSize?this.canvasSize:new t.math.Vector2(r,o);var w=this.canvasSize,T=w.x,S=w.y;this.item.transform.size.set(v*T*n*n,y*S*n*n),this.size=this.item.transform.size.clone(),this.initialized=!0}t.assertExist(this.canvasSize);var b=this.canvasSize,O=b.x,A=b.y;a.width=O/s.fontScale,a.height=A/s.fontScale,this.renderToTexture(O,A,e,(function(e){if(0!==f.length){var n=a.getOffsetY(s,f.length,p*i.singleLineHeight,s.fontSize);f.forEach((function(i,r){var o=i.richOptions,c=i.offsetX,h=i.width,u=h,f=c;if(l===t.spec.TextOverflow.display&&h>O){var p=O/h;u*=p,f=c.map((function(t){return t*p}))}var x=a.getOffsetX(s,u);r>0&&(n+=i.lineHeight-i.offsetY),o.forEach((function(i,r){var o=s.fontScale,a=s.textColor,c=s.fontFamily,u=s.textWeight,p=s.fontStyle,g=i.text,d=i.fontSize,v=i.fontColor,m=void 0===v?a:v,y=i.fontFamily,w=void 0===y?c:y,T=i.fontWeight,S=void 0===T?u:T,b=i.fontStyle,A=void 0===b?p:b,M=d;l===t.spec.TextOverflow.display&&h>O&&(M/=h/O);var H=f[r]+x;e.font=A+" "+S+" "+M*o+"px "+w;var z=m[0],E=m[1],L=m[2],W=m[3];e.fillStyle="rgba("+z+", "+E+", "+L+", "+W+")",e.fillText(g,H,n)}))}))}}),{disposeOld:!1}),this.isDirty=!1}else this.isDirty=!1}},n.updateTextureWithStrategies=function(e){var i=this;if(this.isDirty&&this.context&&this.canvas){this.generateTextProgram(this.text);var n=this.textLayout,r=n.letterSpace,o=void 0===r?0:r,a=this.context;if(a){var s=this.textStyle.fontScale;n.autoResize===t.spec.TextSizeMode.autoWidth&&(n.maxTextWidth=Number.MAX_SAFE_INTEGER);var l,c,h=this.richWrapStrategy.computeLines(this.processedTextOptions,a,this.textStyle,n,o);switch(n.autoResize){case t.spec.TextSizeMode.autoWidth:l=Math.max(1,h.maxLineWidth||0),c=Math.max(1,h.totalHeight||0);break;case t.spec.TextSizeMode.autoHeight:l=n.maxTextWidth,c=Math.max(1,h.totalHeight||0);break;case t.spec.TextSizeMode.fixed:default:l=n.maxTextWidth,c=n.maxTextHeight}if(n.overflow===t.spec.TextOverflow.display){var u=Math.max(1,h.maxLineWidth||0),f=Math.max(1,h.totalHeight||0);!function(t,e,i,n,r){var o=function(t,e){return Math.abs(e)>1e-5?t/e:1},a=Math.max(1,e),s=Math.max(1,i),l=Math.min(1,o(n,a),o(r,s));if(!(l>.9999))for(var c,h=p(t);!(c=h()).done;){var u=c.value;if(u.width*=l,u.lineHeight*=l,u.offsetX)for(var f=0;f<u.offsetX.length;f++)u.offsetX[f]*=l;for(var x,g=p(u.chars||[]);!(x=g()).done;)for(var d,v=p(x.value);!(d=v()).done;)d.value.x*=l;for(var m=u.richOptions||[],y=[],w=0;w<m.length;w++)y.push(L({},m[w],{fontSize:m[w].fontSize*l}));u.richOptions=y,null!=u.lineAscent&&(u.lineAscent*=l),null!=u.lineDescent&&(u.lineDescent*=l)}}(h.lines,u,f,l,c)}var x=this.richHorizontalAlignStrategy.getHorizontalOffsets(h.lines,l,n,this.textStyle),g=this.richVerticalAlignStrategy.getVerticalOffsets(h.lines,c,n),d=this.richOverflowStrategy.resolveCanvas(h.lines,l,c,x,g),v=Math.max(1,Math.ceil(d.canvasWidth*s)),m=Math.max(1,Math.ceil(d.canvasHeight*s));this.item.transform.size.set(d.canvasWidth*this.SCALE_FACTOR*this.SCALE_FACTOR,d.canvasHeight*this.SCALE_FACTOR*this.SCALE_FACTOR),n.maxTextWidth=l,n.maxTextHeight=c,n.width=d.canvasWidth,n.height=d.canvasHeight,this.renderToTexture(v,m,e,(function(t){t.scale(s,s),i.drawTextWithStrategies(t,h.lines,x,g,d,i.textStyle)}),{disposeOld:!1}),this.isDirty=!1}}},n.drawTextWithStrategies=function(t,e,i,n,r,o){var a=r.renderOffsetX,s=r.renderOffsetY,l=n.baselineY+s,c=i.lineOffsets;e.forEach((function(i,n){var r=i.richOptions,s=i.chars,h=c[n]+a,u=l;r.forEach((function(e,n){var r=o.textColor,a=o.fontFamily,l=o.textWeight,c=o.fontStyle,f=e.fontSize,p=e.fontColor,x=void 0===p?r:p,g=e.fontFamily,d=void 0===g?a:g,v=e.fontWeight,m=void 0===v?l:v,y=e.fontStyle,w=void 0===y?c:y,T=f;t.font=w+" "+m+" "+T+"px "+d;var S=x[0],b=x[1],O=x[2],A=x[3];t.fillStyle="rgba("+S+", "+b+", "+O+", "+A+")";var M=i.offsetX&&i.offsetX[n]?i.offsetX[n]:0;s[n].forEach((function(e){t.fillText(e.char,h+M+e.x,u)}))})),n<e.length-1&&(l+=e[n+1].lineHeight)}))},n.unsupported=function(t){throw new Error("RichTextComponent does not support "+t+" at runtime.")},n.setShadowOffsetY=function(t){this.unsupported("setShadowOffsetY")},n.setShadowBlur=function(t){this.unsupported("setShadowBlur")},n.setShadowOffsetX=function(t){this.unsupported("setShadowOffsetX")},n.setShadowColor=function(t){this.unsupported("setShadowColor")},n.setOutlineWidth=function(t){this.unsupported("setOutlineWidth")},n.setAutoWidth=function(t){this.unsupported("setAutoWidth")},n.setFontSize=function(t){this.unsupported("setFontSize")},n.setTextBaseline=function(t){console.warn("setTextBaseline 已废弃,请改用 setTextVerticalAlign。本次调用将转调用 setTextVerticalAlign。"),this.setTextVerticalAlign(t)},i}(t.MaskableGraphic),exports.RichTextComponent=function(t,e,i,n){var r,o=arguments.length,a=o<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,i):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(t,e,i,n);else for(var s=t.length-1;s>=0;s--)(r=t[s])&&(a=(o<3?r(a):o>3?r(e,i,a):r(e,i))||a);return o>3&&a&&Object.defineProperty(e,i,a),a}([t.effectsClass(t.spec.DataType.RichTextComponent)],exports.RichTextComponent),t.applyMixins(exports.RichTextComponent,[t.TextComponentBase]);var C="2.8.9";t.registerPlugin("rich-text",u),t.logger.info("Plugin rich text version: 2.8.9."),C!==n.version&&console.error("注意:请统一 RichText 插件与 Player 版本,不统一的版本混用会有不可预知的后果!","\nAttention: Please ensure the RichText plugin is synchronized with the Player version. Mixing and matching incompatible versions may result in unpredictable consequences!"),exports.RichTextLoader=u,exports.escape=function(t){if("string"!=typeof t)throw new Error("Input must be a string");return t.replace(/\\/g,"\\\\").replace(/=/g,"\\=").replace(/</g,"\\<").replace(/>/g,"\\>").replace(/\//g,"\\/")},exports.generateProgram=y,exports.isRichText=function(t){var e=v(t).filter((function(t){var e=t.tokenType;return"ContextStart"===e||"ContextEnd"===e})),i=e.filter((function(t){return"ContextStart"===t.tokenType})),n=e.filter((function(t){return"ContextEnd"===t.tokenType}));return!(i.length!==n.length||!i.length)&&function t(e,i){var n=e[0],r=e.slice(1);if(void 0===i&&(i=[]),!n)return 0===i.length;if("ContextStart"===n.tokenType)return t(r,i.concat(n.value));if("ContextEnd"===n.tokenType)return i[i.length-1]===n.value&&t(r,i.slice(0,-1));throw new Error("Unexpected token: "+n.tokenType)}(e.map((function(t){var e=t.tokenType,i=t.value;return{tokenType:e,value:"ContextStart"===e?i.match(x)[1]:i.match(g)[1]}})))},exports.lexer=v,exports.richTextParser=m,exports.unescape=function(t){if("string"!=typeof t)throw new Error("Input must be a string");return t.replace(/\\\//g,"/").replace(/\\>/g,">").replace(/\\</g,"<").replace(/\\=/g,"=").replace(/\\\\/g,"\\")},exports.version=C;
2
2
  //# sourceMappingURL=weapp.js.map