@galacean/effects-plugin-rich-text 2.7.4 → 2.8.0-alpha.0

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.
@@ -1,8 +1,6 @@
1
- import type { Engine } from '@galacean/effects';
2
- import { spec, TextComponent, TextStyle } from '@galacean/effects';
3
- /**
4
- *
5
- */
1
+ import type { Engine, IRichTextComponent } from '@galacean/effects';
2
+ import { spec, MaskableGraphic, TextStyle, TextComponentBase } from '@galacean/effects';
3
+ import { RichTextLayout } from './rich-text-layout';
6
4
  export interface RichTextOptions {
7
5
  text: string;
8
6
  fontSize: number;
@@ -10,29 +8,61 @@ export interface RichTextOptions {
10
8
  fontWeight?: spec.TextWeight;
11
9
  fontStyle?: spec.FontStyle;
12
10
  fontColor?: spec.vec4;
13
- textStyle?: TextStyle;
14
11
  isNewLine: boolean;
15
12
  }
13
+ export interface RichTextComponent extends TextComponentBase {
14
+ }
16
15
  /**
17
- * RichText component class
16
+ * 富文本组件类
18
17
  */
19
- export declare class RichTextComponent extends TextComponent {
18
+ export declare class RichTextComponent extends MaskableGraphic implements IRichTextComponent {
19
+ isDirty: boolean;
20
+ text: string;
21
+ textStyle: TextStyle;
22
+ canvas: HTMLCanvasElement;
23
+ context: CanvasRenderingContext2D | null;
24
+ textLayout: RichTextLayout;
20
25
  processedTextOptions: RichTextOptions[];
21
26
  private singleLineHeight;
22
27
  private size;
23
- /**
24
- * 获取第一次渲染的 size
25
- */
26
28
  private initialized;
27
- /**
28
- * canvas 大小
29
- */
30
29
  private canvasSize;
30
+ private richWrapStrategy;
31
+ private richOverflowStrategy;
32
+ private richHorizontalAlignStrategy;
33
+ private richVerticalAlignStrategy;
34
+ protected readonly SCALE_FACTOR = 0.1;
35
+ protected readonly ALPHA_FIX_VALUE: number;
31
36
  constructor(engine: Engine);
37
+ onUpdate(dt: number): void;
38
+ onDestroy(): void;
39
+ fromData(data: spec.RichTextComponentData): void;
40
+ /**
41
+ * 使用策略结果绘制文本
42
+ */
43
+ private updateStrategies;
32
44
  private generateTextProgram;
45
+ updateWithOptions(options: spec.RichTextContentOptions): void;
46
+ protected renderText(options: spec.RichTextContentOptions): void;
33
47
  updateTexture(flipY?: boolean): void;
48
+ /**
49
+ * 解析富文本
50
+ */
34
51
  private updateTextureLegacy;
35
- private updateTextureModern;
52
+ /**
53
+ * 使用策略管线路径的渲染方法
54
+ */
55
+ private updateTextureWithStrategies;
56
+ private setCanvasSize;
57
+ /**
58
+ * 尺寸处理
59
+ */
60
+ private resolveCanvasSize;
61
+ /**
62
+ * 使用策略结果绘制文本
63
+ */
64
+ private drawTextWithStrategies;
65
+ private unsupported;
36
66
  /**
37
67
  * 该方法富文本组件不支持
38
68
  * @param value - 水平偏移距离
@@ -65,6 +95,8 @@ export declare class RichTextComponent extends TextComponent {
65
95
  * @param value - 是否自动设置宽度
66
96
  */
67
97
  setAutoWidth(value: boolean): void;
68
- updateWithOptions(options: spec.TextContentOptions): void;
69
- protected renderText(options: spec.RichTextContentOptions): void;
98
+ /**
99
+ * 该方法富文本组件不支持
100
+ */
101
+ setFontSize(value: number): void;
70
102
  }
@@ -0,0 +1,54 @@
1
+ import type { TextStyle, BaseLayout } from '@galacean/effects';
2
+ import { spec } from '@galacean/effects';
3
+ export declare class RichTextLayout implements BaseLayout {
4
+ textVerticalAlign: spec.TextVerticalAlign;
5
+ textAlign: spec.TextAlignment;
6
+ letterSpace: number;
7
+ overflow: spec.TextOverflow;
8
+ width: number;
9
+ height: number;
10
+ /**
11
+ * 是否使用旧版富文本渲染
12
+ */
13
+ useLegacyRichText: boolean;
14
+ /**
15
+ * 文本框是否开启自动换行
16
+ */
17
+ wrapEnabled: boolean;
18
+ /**
19
+ * 文本框最大宽度限制
20
+ */
21
+ maxTextWidth: number;
22
+ /**
23
+ * 文本框最大高度限制
24
+ */
25
+ maxTextHeight: number;
26
+ /**
27
+ * 文本框大小模式
28
+ */
29
+ sizeMode: spec.TextSizeMode;
30
+ /**
31
+ * 文本行高
32
+ */
33
+ lineHeight: number;
34
+ constructor(options: spec.RichTextContentOptions);
35
+ getOffsetY(style: TextStyle, lineCount: number, lineHeight: number, fontSize: number, totalLineHeight?: number): number;
36
+ getOffsetX(style: TextStyle, maxWidth: number): number;
37
+ /**
38
+ * 富文本垂直对齐计算
39
+ * @param style - 字体样式
40
+ * @param lineHeights - 每行高度数组
41
+ * @param fontSize - 字体大小
42
+ * @returns 第一行基线的Y坐标
43
+ */
44
+ getOffsetYRich(style: TextStyle, lineHeights: number[], fontSize: number): number;
45
+ /**
46
+ * 富文本横向对齐计算
47
+ * @param style - 字体样式
48
+ * @param maxWidth - 文本框最大宽度
49
+ * @param contentW - 文本实际宽度
50
+ * @returns 水平偏移量
51
+ */
52
+ getOffsetXRich(style: TextStyle, maxWidth: number, contentW: number): number;
53
+ setSize(width: number, height: number): void;
54
+ }
@@ -0,0 +1,10 @@
1
+ import type { TextStyle } from '@galacean/effects';
2
+ import type { RichTextLayout } from '../../rich-text-layout';
3
+ import type { RichLine, HorizontalAlignResult, SizeResult, OverflowResult, RichHorizontalAlignStrategy } from '../rich-text-interfaces';
4
+ /**
5
+ * 富文本水平对齐策略
6
+ * 直接使用已缩放的行宽计算偏移量
7
+ */
8
+ export declare class RichHorizontalAlignStrategyImpl implements RichHorizontalAlignStrategy {
9
+ getHorizontalOffsets(lines: RichLine[], sizeResult: SizeResult, overflowResult: OverflowResult, layout: RichTextLayout, style: TextStyle): HorizontalAlignResult;
10
+ }
@@ -0,0 +1,10 @@
1
+ import type { TextStyle } from '@galacean/effects';
2
+ import type { RichTextLayout } from '../../rich-text-layout';
3
+ import type { RichLine, VerticalAlignResult, SizeResult, OverflowResult, RichVerticalAlignStrategy } from '../rich-text-interfaces';
4
+ /**
5
+ * 富文本垂直对齐策略
6
+ * 直接使用已缩放的行高
7
+ */
8
+ export declare class RichVerticalAlignStrategyImpl implements RichVerticalAlignStrategy {
9
+ getVerticalOffsets(lines: RichLine[], sizeResult: SizeResult, overflowResult: OverflowResult, layout: RichTextLayout, style: TextStyle, singleLineHeight: number): VerticalAlignResult;
10
+ }
@@ -0,0 +1,10 @@
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';
4
+ /**
5
+ * Clip 溢出策略
6
+ * 超出画布部分自然裁切
7
+ */
8
+ export declare class RichClippedOverflowStrategy implements RichOverflowStrategy {
9
+ apply(lines: RichLine[], sizeResult: SizeResult, layout: RichTextLayout, style: TextStyle): OverflowResult;
10
+ }
@@ -0,0 +1,10 @@
1
+ import type { TextStyle } from '@galacean/effects';
2
+ import type { RichTextLayout } from '../../rich-text-layout';
3
+ import type { RichLine, OverflowResult, SizeResult, RichOverflowStrategy } from '../rich-text-interfaces';
4
+ /**
5
+ * 富文本 Display 溢出策略
6
+ * 在溢出策略中对所有几何量进行一次性缩放
7
+ */
8
+ export declare class RichDisplayOverflowStrategy implements RichOverflowStrategy {
9
+ apply(lines: RichLine[], sizeResult: SizeResult, layout: RichTextLayout, style: TextStyle): OverflowResult;
10
+ }
@@ -0,0 +1,10 @@
1
+ import type { TextStyle } from '@galacean/effects';
2
+ import type { RichTextLayout } from '../../rich-text-layout';
3
+ import type { RichLine, RichOverflowStrategy, OverflowResult, SizeResult } from '../rich-text-interfaces';
4
+ /**
5
+ * Visible 溢出策略
6
+ * 允许内容超出画布可见
7
+ */
8
+ export declare class RichVisibleOverflowStrategy implements RichOverflowStrategy {
9
+ apply(lines: RichLine[], sizeResult: SizeResult, layout: RichTextLayout, style: TextStyle): OverflowResult;
10
+ }
@@ -0,0 +1,26 @@
1
+ import { spec } from '@galacean/effects';
2
+ import type { RichWrapStrategy, RichOverflowStrategy, RichHorizontalAlignStrategy, RichVerticalAlignStrategy } from './rich-text-interfaces';
3
+ /**
4
+ * 富文本策略工厂
5
+ * 负责创建各种策略实例
6
+ */
7
+ export declare class RichTextStrategyFactory {
8
+ /**
9
+ * 创建换行策略
10
+ * 根据wrapEnabled参数决定使用哪种策略
11
+ */
12
+ static createWrapStrategy(wrapEnabled?: boolean): RichWrapStrategy;
13
+ /**
14
+ * 创建溢出策略
15
+ * 支持三种模式:clip(裁切)、display(行级缩放)、visible(不缩放不裁剪)
16
+ */
17
+ static createOverflowStrategy(mode: spec.TextOverflow): RichOverflowStrategy;
18
+ /**
19
+ * 创建水平对齐策略
20
+ */
21
+ static createHorizontalAlignStrategy(): RichHorizontalAlignStrategy;
22
+ /**
23
+ * 创建垂直对齐策略
24
+ */
25
+ static createVerticalAlignStrategy(): RichVerticalAlignStrategy;
26
+ }
@@ -0,0 +1,104 @@
1
+ import type { TextStyle } from '@galacean/effects';
2
+ import type { RichTextLayout } from '../rich-text-layout';
3
+ import type { RichTextOptions } from '../rich-text-component';
4
+ /**
5
+ * 富文本字符详情
6
+ */
7
+ export interface RichCharDetail {
8
+ char: string;
9
+ x: number;
10
+ }
11
+ /**
12
+ * 富文本行信息
13
+ */
14
+ export interface RichLine {
15
+ richOptions: RichTextOptions[];
16
+ offsetX: number[];
17
+ width: number;
18
+ lineHeight: number;
19
+ offsetY: number;
20
+ chars: RichCharDetail[][];
21
+ lineAscent?: number;
22
+ lineDescent?: number;
23
+ }
24
+ /**
25
+ * 换行策略结果
26
+ */
27
+ export interface WrapResult {
28
+ lines: RichLine[];
29
+ maxLineWidth: number;
30
+ totalHeight: number;
31
+ bboxTop?: number;
32
+ bboxBottom?: number;
33
+ bboxHeight?: number;
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
+ lines?: RichLine[];
48
+ }
49
+ /**
50
+ * 溢出策略结果
51
+ */
52
+ export interface OverflowResult {
53
+ globalScale?: number;
54
+ }
55
+ /**
56
+ * 水平对齐策略结果
57
+ */
58
+ export interface HorizontalAlignResult {
59
+ lineOffsets: number[];
60
+ }
61
+ /**
62
+ * 垂直对齐策略结果
63
+ */
64
+ export interface VerticalAlignResult {
65
+ baselineY: number;
66
+ lineYOffsets: number[];
67
+ }
68
+ /**
69
+ * 对齐策略结果(组合水平和垂直对齐)
70
+ */
71
+ export interface AlignResult {
72
+ horizontal: HorizontalAlignResult;
73
+ vertical: VerticalAlignResult;
74
+ }
75
+ /**
76
+ * 富文本尺寸策略接口
77
+ */
78
+ export interface RichSizeStrategy {
79
+ calculate(WrapResult: WrapResult, layout: RichTextLayout, style: TextStyle, singleLineHeight: number, fontScale: number): SizeResult;
80
+ }
81
+ /**
82
+ * 富文本换行策略接口
83
+ */
84
+ export interface RichWrapStrategy {
85
+ computeLines(processedOptions: RichTextOptions[], context: CanvasRenderingContext2D, style: TextStyle, layout: RichTextLayout, singleLineHeight: number, fontScale: number, letterSpace: number, scaleFactor: number): WrapResult;
86
+ }
87
+ /**
88
+ * 富文本溢出策略接口
89
+ */
90
+ export interface RichOverflowStrategy {
91
+ apply(lines: RichLine[], sizeResult: SizeResult, layout: RichTextLayout, style: TextStyle): OverflowResult;
92
+ }
93
+ /**
94
+ * 富文本水平对齐策略接口
95
+ */
96
+ export interface RichHorizontalAlignStrategy {
97
+ getHorizontalOffsets(lines: RichLine[], sizeResult: SizeResult, overflowResult: OverflowResult, layout: RichTextLayout, style: TextStyle): HorizontalAlignResult;
98
+ }
99
+ /**
100
+ * 富文本垂直对齐策略接口
101
+ */
102
+ export interface RichVerticalAlignStrategy {
103
+ getVerticalOffsets(lines: RichLine[], sizeResult: SizeResult, overflowResult: OverflowResult, layout: RichTextLayout, style: TextStyle, singleLineHeight: number): VerticalAlignResult;
104
+ }
@@ -0,0 +1,15 @@
1
+ import type { TextStyle } from '@galacean/effects';
2
+ import type { RichTextLayout } from '../../rich-text-layout';
3
+ import type { RichTextOptions } from '../../rich-text-component';
4
+ import type { RichWrapStrategy, WrapResult } from '../rich-text-interfaces';
5
+ /**
6
+ * 富文本换行禁用策略
7
+ * 实现逻辑:仅基于\n换行,无自动换行
8
+ */
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;
11
+ /**
12
+ * 创建新行
13
+ */
14
+ private createNewLine;
15
+ }
@@ -0,0 +1,15 @@
1
+ import type { TextStyle } from '@galacean/effects';
2
+ import type { RichTextLayout } from '../../rich-text-layout';
3
+ import type { RichTextOptions } from '../../rich-text-component';
4
+ import type { WrapResult, RichWrapStrategy } from '../rich-text-interfaces';
5
+ /**
6
+ * 富文本自动换行策略
7
+ * 实现逻辑:基于\n换行及自动换行
8
+ */
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;
11
+ /**
12
+ * 创建新行
13
+ */
14
+ private createNewLine;
15
+ }
package/dist/weapp.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@galacean/effects/weapp"),e=require("@galacean/appx-adapter/weapp");function i(t){if(t&&t.__esModule)return t;var e=Object.create(null);return t&&Object.keys(t).forEach((function(i){if("default"!==i){var n=Object.getOwnPropertyDescriptor(t,i);Object.defineProperty(e,i,n.get?n:{enumerable:!0,get:function(){return t[i]}})}})),e.default=t,Object.freeze(e)}var n=i(t);function r(t,e){return r=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},r(t,e)}function o(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&r(t,e)}var a,s=function(t){function e(){var e;return(e=t.apply(this,arguments)||this).name="rich-text",e}return o(e,t),e}(t.AbstractPlugin);function h(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 l(t,e){var i="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(i)return(i=i.call(t)).next.bind(i);if(Array.isArray(t)||(i=function(t,e){if(t){if("string"==typeof t)return h(t,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)?h(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"}(a||(a={}));var c=/^<([a-z]+)(=([^>]+))?>$/,f=/^<\/([a-z]+)>$/,u=[["EscapedChar",/^\\([=<>\\/])/],["ContextStart",/^<[a-z]+(=[^>]+)?>/],["ContextEnd",/^<\/[a-z]+>/],["Text",/^[^</>=\\]+/]],p=function(t,e,i){if(void 0===e&&(e=[]),void 0===i&&(i=0),!t)return e;var n=/^\\([=<>\\/])/.exec(t);if(n){var r=n[1];return p(t.slice(2),e.concat({tokenType:"Text",value:r}),i+2)}for(var o,a=l(u);!(o=a()).done;){var s=o.value,h=s[0],c=s[1];if("EscapedChar"!==h){var f=c.exec(t);if(f){var x=f[0],v=x.length;return p(t.slice(v),e.concat({tokenType:h,value:x}),i+v)}}}if(t.length>0)return p(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+'"')},x=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(c);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(f);if(e)return{attributeName:e[1]};throw new Error("Expect an end tag marker at position "+o)}return{}},r=p(t),o=0,a=function(){var t,e=r.shift();return o+=null!=(t=null==e?void 0:e.value.length)?t:0,e},s=function(){return r[0]},h=[];return function t(r,a){for(void 0===r&&(r=[]),void 0===a&&(a="");;){var s=e();if(s)h.push({attributes:r,text:s});else{var l=i(),c=l.attributeName,f=l.attributeParam;if(!c){if(a){var u=n().attributeName;if(!u)throw new Error('Expect an end tag marker "'+a+'" at position '+o+" but found no tag!");if(u!==a)throw new Error('Expect an end tag marker "'+a+'" at position '+o+' but found tag "'+u+'"');return}break}t(r.concat({attributeName:c,attributeParam:null!=f?f:""}),c)}}}(),h};function v(t){return function(e){for(var i,n=l(x(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 d(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 g(t,i){if(void 0===i&&(i=1),"string"!=typeof t||!t)throw new Error("Invalid color string");return t.startsWith("#")?d(t,i):d(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{i.remove()}throw new Error("Failed to get 2D context for color conversion!")}(t))}"function"==typeof SuppressedError&&SuppressedError;var y=0;exports.RichTextComponent=function(e){function i(t){var i;return(i=e.call(this,t)||this).processedTextOptions=[],i.singleLineHeight=1.571,i.size=null,i.initialized=!1,i.canvasSize=null,i.name="MRichText"+y++,i}o(i,e);var n=i.prototype;return n.generateTextProgram=function(e){var i=this;this.processedTextOptions=[];var n=v((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=g(n.color)),i.processedTextOptions.push(o)}))}));n(e)},n.updateTexture=function(t){if(void 0===t&&(t=!0),this.isDirty&&this.context&&this.canvas){var e=!0===this.textLayout.useLegacyRichText;this.singleLineHeight=e?1.571:1,e?this.updateTextureLegacy(t):this.updateTextureModern(t)}},n.updateTextureLegacy=function(e){var i=this;if(this.isDirty&&this.context&&this.canvas){this.generateTextProgram(this.text);var n=this.textLayout,r=this.textStyle,o=n.overflow,a=n.letterSpace,s=void 0===a?0:a,h=this.context,l=0,c=0;h.save();var f=[],u=r.fontSize*this.textStyle.fontScale,p={richOptions:[],offsetX:[],width:0,lineHeight:u*this.singleLineHeight,offsetY:u*(this.singleLineHeight-1)/2};if(this.processedTextOptions.forEach((function(t){var e=t.text,n=t.isNewLine,o=t.fontSize;n&&(f.push(p),l=Math.max(l,p.width),p={richOptions:[],offsetX:[],width:0,lineHeight:u*i.singleLineHeight,offsetY:u*(i.singleLineHeight-1)/2},c+=p.lineHeight),h.font=(t.fontWeight||r.textWeight)+" 10px "+(t.fontFamily||r.fontFamily);var a=h.measureText(e),x=a.width;if(void 0!==a.actualBoundingBoxLeft&&void 0!==a.actualBoundingBoxRight){var v=a.actualBoundingBoxLeft+a.actualBoundingBoxRight;v>0&&(x=Math.max(x,v))}var d=o*i.singleLineHeight*i.textStyle.fontScale;d>p.lineHeight&&(c+=d-p.lineHeight,p.lineHeight=d,p.offsetY=o*i.textStyle.fontScale*(i.singleLineHeight-1)/2),p.offsetX.push(p.width),p.width+=(x<=0?0:x)*o*i.SCALE_FACTOR*i.textStyle.fontScale+e.length*s,p.richOptions.push(t)})),f.push(p),l=Math.max(l,p.width),c+=p.lineHeight,0===l||0===c)return this.isDirty=!1,void h.restore();void 0!==this.size&&null!==this.size||(this.size=this.item.transform.size.clone());var x=this.size,v=x.x,d=void 0===v?1:v,g=x.y,y=void 0===g?1:g;if(!this.initialized){this.canvasSize=this.canvasSize?this.canvasSize:new t.math.Vector2(l,c);var S=this.canvasSize,m=S.x,w=S.y;this.item.transform.size.set(d*m*this.SCALE_FACTOR*this.SCALE_FACTOR,y*w*this.SCALE_FACTOR*this.SCALE_FACTOR),this.size=this.item.transform.size.clone(),this.initialized=!0}t.assertExist(this.canvasSize);var T=this.canvasSize,E=T.x,C=T.y;if(this.textLayout.width=E/r.fontScale,this.textLayout.height=C/r.fontScale,this.canvas.width=E,this.canvas.height=C,h.clearRect(0,0,E,C),h.fillStyle="rgba(255, 255, 255, "+this.ALPHA_FIX_VALUE+")",e||(h.translate(0,C),h.scale(1,-1)),0!==f.length){var L=n.getOffsetY(r,f.length,u*this.singleLineHeight,r.fontSize);f.forEach((function(e,n){var a=e.richOptions,s=e.offsetX,l=e.width,c=l,f=s;if(o===t.spec.TextOverflow.display&&l>E){var u=E/l;c*=u,f=s.map((function(t){return t*u}))}var p=i.textLayout.getOffsetX(r,c);n>0&&(L+=e.lineHeight-e.offsetY),a.forEach((function(e,i){var n=r.fontScale,a=r.textColor,s=r.fontFamily,c=r.textWeight,u=r.fontStyle,x=e.text,v=e.fontSize,d=e.fontColor,g=void 0===d?a:d,y=e.fontFamily,S=void 0===y?s:y,m=e.fontWeight,w=void 0===m?c:m,T=e.fontStyle,C=void 0===T?u:T,z=v;o===t.spec.TextOverflow.display&&l>E&&(z/=l/E);var O=f[i]+p;h.font=C+" "+w+" "+z*n+"px "+S,h.fillStyle="rgba("+g[0]+", "+g[1]+", "+g[2]+", "+g[3]+")",h.fillText(x,O,L)}))}));var z=h.getImageData(0,0,this.canvas.width,this.canvas.height),O=t.Texture.createWithData(this.engine,{data:new Uint8Array(z.data),width:z.width,height:z.height},{flipY:e,magFilter:t.glContext.LINEAR,minFilter:t.glContext.LINEAR,wrapS:t.glContext.CLAMP_TO_EDGE,wrapT:t.glContext.CLAMP_TO_EDGE});this.disposeTextTexture(),this.renderer.texture=O,this.material.setTexture("_MainTex",O),this.isDirty=!1,h.restore()}else h.restore()}},n.updateTextureModern=function(e){var i,n,r=this;this.generateTextProgram(this.text);var o=this.textLayout,a=this.textStyle,s=o.overflow,h=o.letterSpace,l=void 0===h?0:h,c=this.context,f=0,u=0;if(c){c.save();var p=[],x=a.fontSize*this.textStyle.fontScale,v={richOptions:[],offsetX:[],width:0,lineHeight:x*this.singleLineHeight+(this.textLayout.lineGap||0)*this.textStyle.fontScale,offsetY:(this.textLayout.lineGap||0)*this.textStyle.fontScale/2,chars:[]};if(this.processedTextOptions.forEach((function(t){var e=t.text,i=t.isNewLine,n=t.fontSize;i&&(u+=v.lineHeight,p.push(v),f=Math.max(f,v.width),v={richOptions:[],offsetX:[],width:0,lineHeight:x*r.singleLineHeight+(r.textLayout.lineGap||0)*r.textStyle.fontScale,offsetY:(r.textLayout.lineGap||0)*r.textStyle.fontScale/2,chars:[]}),c.font=(t.fontWeight||a.textWeight)+" 10px "+(t.fontFamily||a.fontFamily);var o=n*r.singleLineHeight*r.textStyle.fontScale+(r.textLayout.lineGap||0)*r.textStyle.fontScale;o>v.lineHeight&&(v.lineHeight=o,v.offsetY=(r.textLayout.lineGap||0)*r.textStyle.fontScale/2),v.offsetX.push(v.width);for(var s=0,h=[],d=0;d<e.length;d++){var g=e[d],y=c.measureText(g).width,S=(y<=0?0:y)*n*r.SCALE_FACTOR*r.textStyle.fontScale;h.push({char:g,x:s,width:S}),s+=S+l}v.chars.push(h),v.width+=s,v.richOptions.push(t)})),u+=v.lineHeight,p.push(v),0===(f=Math.max(f,v.width))||0===u)return this.isDirty=!1,void c.restore();void 0!==this.size&&null!==this.size||(this.size=this.item.transform.size.clone());var d=this.size,g=d.x,y=void 0===g?1:g,S=d.y,m=void 0===S?1:S;if(!this.initialized){this.canvasSize=this.canvasSize?this.canvasSize:new t.math.Vector2(f,u);var w=this.canvasSize,T=w.x,E=w.y;this.item.transform.size.set(y*T*this.SCALE_FACTOR*this.SCALE_FACTOR,m*E*this.SCALE_FACTOR*this.SCALE_FACTOR),this.size=this.item.transform.size.clone(),this.initialized=!0}t.assertExist(this.canvasSize);var C=this.canvasSize,L=C.x,z=C.y;if(this.textLayout.width=L/a.fontScale,this.textLayout.height=z/a.fontScale,this.canvas.width=L,this.canvas.height=z,c.clearRect(0,0,L,z),c.fillStyle="rgba(255, 255, 255, "+this.ALPHA_FIX_VALUE+")",e||(c.translate(0,z),c.scale(1,-1)),0!==p.length){var O,b=p.map((function(t){return t.lineHeight})),A=p[0],R=(i=Math).max.apply(i,[].concat(null!=(O=null==A||null==(n=A.richOptions)?void 0:n.map((function(t){return t.fontSize})))?O:[this.textStyle.fontSize]))*this.textStyle.fontScale*this.singleLineHeight,_=o.getOffsetYRich(this.textStyle,b,R);p.forEach((function(e,i){var n=e.richOptions,o=e.offsetX,h=e.width,l=e.chars,f=h,u=o;if(s===t.spec.TextOverflow.display&&h>L){var x=L/h;f*=x,u=o.map((function(t){return t*x})),l.forEach((function(t){t.forEach((function(t){t.x*=x,t.width*=x}))}))}var v=r.textLayout.getOffsetX(a,f);n.forEach((function(i,n){var r=a.fontScale,o=a.textColor,l=a.fontFamily,f=a.textWeight,p=a.fontStyle,x=i.fontSize,d=i.fontColor,g=void 0===d?o:d,y=i.fontFamily,S=void 0===y?l:y,m=i.fontWeight,w=void 0===m?f:m,T=i.fontStyle,E=void 0===T?p:T,C=x;s===t.spec.TextOverflow.display&&h>L&&(C/=h/L);var z=u[n]+v;c.font=E+" "+w+" "+C*r+"px "+S,c.fillStyle="rgba("+g[0]+", "+g[1]+", "+g[2]+", "+g[3]+")",e.chars[n].forEach((function(t){c.fillText(t.char,z+t.x,_)}))})),i<p.length-1&&(_+=b[i+1])}));var H=c.getImageData(0,0,this.canvas.width,this.canvas.height),F=t.Texture.createWithData(this.engine,{data:new Uint8Array(H.data),width:H.width,height:H.height},{flipY:e,magFilter:t.glContext.LINEAR,minFilter:t.glContext.LINEAR,wrapS:t.glContext.CLAMP_TO_EDGE,wrapT:t.glContext.CLAMP_TO_EDGE});this.renderer.texture=F,this.material.setTexture("_MainTex",F),this.isDirty=!1,c.restore()}else c.restore()}},n.setShadowOffsetY=function(t){throw new Error("Method not implemented.")},n.setShadowBlur=function(t){throw new Error("Method not implemented.")},n.setShadowOffsetX=function(t){throw new Error("Method not implemented.")},n.setShadowColor=function(t){throw new Error("Method not implemented.")},n.setOutlineWidth=function(t){throw new Error("Method not implemented.")},n.setAutoWidth=function(t){throw new Error("Method not implemented.")},n.updateWithOptions=function(e){this.textStyle=new t.TextStyle(e),this.textLayout=new t.TextLayout(e),this.textLayout.textBaseline=e.textBaseline||t.spec.TextBaseline.middle,this.text=e.text?e.text.toString():" "},n.renderText=function(e){var i=e.size;i&&(this.canvasSize=new t.math.Vector2(i[0],i[1])),this.updateTexture()},i}(t.TextComponent),exports.RichTextComponent=function(t,e,i,n){var r,o=arguments.length,a=o<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,i):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(t,e,i,n);else for(var s=t.length-1;s>=0;s--)(r=t[s])&&(a=(o<3?r(a):o>3?r(e,i,a):r(e,i))||a);return o>3&&a&&Object.defineProperty(e,i,a),a}([t.effectsClass(t.spec.DataType.RichTextComponent)],exports.RichTextComponent);var S="2.7.4";t.registerPlugin("rich-text",s,t.VFXItem),t.logger.info("Plugin rich text version: 2.7.4."),S!==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=s,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=v,exports.isRichText=function(t){var e=p(t).filter((function(t){var e=t.tokenType;return"ContextStart"===e||"ContextEnd"===e})),i=e.filter((function(t){return"ContextStart"===t.tokenType})),n=e.filter((function(t){return"ContextEnd"===t.tokenType}));return!(i.length!==n.length||!i.length)&&function t(e,i){var n=e[0],r=e.slice(1);if(void 0===i&&(i=[]),!n)return 0===i.length;if("ContextStart"===n.tokenType)return t(r,i.concat(n.value));if("ContextEnd"===n.tokenType)return i[i.length-1]===n.value&&t(r,i.slice(0,-1));throw 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(c)[1]:i.match(f)[1]}})))},exports.lexer=p,exports.richTextParser=x,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=S;
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)}var o,s=function(t){function e(){var e;return(e=t.apply(this,arguments)||this).name="rich-text",e}return a(e,t),e}(t.AbstractPlugin);function l(t,e){(null==e||e>t.length)&&(e=t.length);for(var i=0,n=new Array(e);i<e;i++)n[i]=t[i];return n}function h(t,e){var i="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(i)return(i=i.call(t)).next.bind(i);if(Array.isArray(t)||(i=function(t,e){if(t){if("string"==typeof t)return l(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)?l(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){i&&(t=i);var n=0;return function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}!function(t){t.ContextStart="ContextStart",t.Text="Text",t.ContextEnd="ContextEnd",t.EscapedChar="EscapedChar"}(o||(o={}));var c=/^<([a-z]+)(=([^>]+))?>$/,f=/^<\/([a-z]+)>$/,u=[["EscapedChar",/^\\([=<>\\/])/],["ContextStart",/^<[a-z]+(=[^>]+)?>/],["ContextEnd",/^<\/[a-z]+>/],["Text",/^[^</>=\\]+/]],p=function(t,e,i){if(void 0===e&&(e=[]),void 0===i&&(i=0),!t)return e;var n=/^\\([=<>\\/])/.exec(t);if(n){var r=n[1];return p(t.slice(2),e.concat({tokenType:"Text",value:r}),i+2)}for(var a,o=h(u);!(a=o()).done;){var s=a.value,l=s[0],c=s[1];if("EscapedChar"!==l){var f=c.exec(t);if(f){var x=f[0],g=x.length;return p(t.slice(g),e.concat({tokenType:l,value:x}),i+g)}}}if(t.length>0)return p(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+'"')},x=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(c);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(f);if(e)return{attributeName:e[1]};throw new Error("Expect an end tag marker at position "+a)}return{}},r=p(t),a=0,o=function(){var t,e=r.shift();return a+=null!=(t=null==e?void 0:e.value.length)?t:0,e},s=function(){return r[0]},l=[];return function t(r,o){for(void 0===r&&(r=[]),void 0===o&&(o="");;){var s=e();if(s)l.push({attributes:r,text:s});else{var h=i(),c=h.attributeName,f=h.attributeParam;if(!c){if(o){var u=n().attributeName;if(!u)throw new Error('Expect an end tag marker "'+o+'" at position '+a+" but found no tag!");if(u!==o)throw new Error('Expect an end tag marker "'+o+'" at position '+a+' but found tag "'+u+'"');return}break}t(r.concat({attributeName:c,attributeParam:null!=f?f:""}),c)}}}(),l};function g(t){return function(e){for(var i,n=h(x(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 v=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,h=e.letterSpace,c=void 0===h?0:h,f=e.lineHeight,u=void 0===f?.571:f,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=c,this.lineHeight=300*u,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,h=r+o*s,c=void 0!==a?a:n*(i-1),f=0;switch(this.textVerticalAlign){case t.spec.TextVerticalAlign.top:f=h+l;break;case t.spec.TextVerticalAlign.middle:f=(this.height*s-c+h)/2;break;case t.spec.TextVerticalAlign.bottom:f=this.height*s-c-l}return f},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,h=o-i[0],c=0;switch(this.textVerticalAlign){case t.spec.TextVerticalAlign.top:c=l+s;break;case t.spec.TextVerticalAlign.middle:c=(this.height*a-o)/2+l;break;case t.spec.TextVerticalAlign.bottom:c=this.height*a-h-s}return c},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 d(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 m(t,i){if(void 0===i&&(i=1),"string"!=typeof t||!t)throw new Error("Invalid color string");return t.startsWith("#")?d(t,i):d(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{i.remove()}throw new Error("Failed to get 2D context for color conversion!")}(t))}var y=function(){function t(){}var e=t.prototype;return e.computeLines=function(t,e,i,n,r,a,o,s){var l=this,h=[],c=[],f=(n.lineHeight||0)*a,u=this.createNewLine(),p=0,x=0,g=function(){if(0!==u.chars.length){u.lineHeight=0===h.length?(u.lineAscent||0)+(u.lineDescent||0):f;var t=0===h.length?0:c[c.length-1]+f;c.push(t),x+=u.lineHeight,h.push(u),p=Math.max(p,u.width),u=l.createNewLine()}};t.forEach((function(t){var n=t.text,r=t.isNewLine,l=t.fontSize;r&&g();var h=t.fontStyle||i.fontStyle||"normal";e.font=h+" "+(t.fontWeight||i.textWeight)+" 10px "+(t.fontFamily||i.fontFamily),u.offsetX.push(u.width);for(var c=0,f=[],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&&(c+=o),f.push({char:d,x:c}),c+=S}u.chars.push(f),u.width+=c,u.richOptions.push(t),u.lineAscent=Math.max(u.lineAscent||0,p),u.lineDescent=Math.max(u.lineDescent||0,x)})),g();var v=1/0,d=-1/0;if(0===h.length)return{lines:h,maxLineWidth:p,totalHeight:x,bboxTop:0,bboxBottom:0,bboxHeight:0};for(var m=0;m<h.length;m++)v=Math.min(v,c[m]-(h[m].lineAscent||0)),d=Math.max(d,c[m]+(h[m].lineDescent||0));return{lines:h,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}(),S=function(){function t(){}var e=t.prototype;return e.computeLines=function(t,e,i,n,r,a,o,s){var l=this,h=[],c=[],f=(n.lineHeight||0)*a,u=this.createNewLine(),p=0,x=0,g=null,v=0,d=[],m=null,y=function(){if(S(),0!==u.chars.length){u.lineHeight=0===h.length?(u.lineAscent||0)+(u.lineDescent||0):f;var t=0===h.length?0:c[c.length-1]+f;c.push(t),x+=u.lineHeight,h.push(u),p=Math.max(p,u.width),u=l.createNewLine(),g=null,v=0,d=[],m=null}},S=function(){0!==d.length&&(null===g&&(g=u.width),u.offsetX.push(g),u.chars.push(d),m&&u.richOptions.push(m),g=null,v=0,d=[],m=null)};t.forEach((function(t){var r=t.text,l=t.isNewLine,h=t.fontSize,c=t.fontStyle||i.fontStyle||"normal";e.font=c+" "+(t.fontWeight||i.textWeight)+" 10px "+(t.fontFamily||i.fontFamily),l&&(S(),y());for(var f=0;f<r.length;f++){var p=r[f],x=e.measureText(p),T=x.width,w=(T<=0?0:T)*h*s*a,b=h*a*s,A=x.actualBoundingBoxAscent*b,O=x.actualBoundingBoxDescent*b,z=d.length>0?o:0;u.width+z+w>(n.maxTextWidth||1/0)&&(S(),y()),null===g&&(g=u.width,m=t),d.length>0&&(v+=o,u.width+=o),d.push({char:p,x:v}),u.lineAscent=Math.max(u.lineAscent||0,A),u.lineDescent=Math.max(u.lineDescent||0,O),v+=w,u.width+=w}S()})),y();for(var T=1/0,w=-1/0,b=0;b<h.length;b++)T=Math.min(T,c[b]-(h[b].lineAscent||0)),w=Math.max(w,c[b]+(h[b].lineDescent||0));return{lines:h,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}(),T=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=Math.max(1,i.maxTextWidth||e.canvasWidth),l=Math.max(1,i.maxTextHeight||e.canvasHeight),c=Math.max(1,null!=(r=e.contentWidth)?r:e.canvasWidth),f=Math.max(1,null!=(a=e.bboxHeight)?a:e.canvasHeight),u=Math.min(1,o(s,c),o(l,f));if(u>.9999)return{globalScale:1};for(var p,x=h(t);!(p=x()).done;){var g=p.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=h(g.chars||[]);!(d=m()).done;)for(var y,S=h(d.value);!(y=S()).done;){y.value.x*=u}for(var T,w=h(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}(),w=function(){function t(){}return t.prototype.apply=function(t,e,i,n){return{globalScale:1}},t}(),b=function(){function t(){}return t.prototype.apply=function(t,e,i,n){return{globalScale:1}},t}(),A=function(){function e(){}return e.prototype.getHorizontalOffsets=function(e,i,n,r,a){var o=r.maxTextWidth,s=i.baselineCompensationX||0,l=e.map((function(t){return r.getOffsetXRich(a,o,t.width)}));return{lineOffsets:r.overflow===t.spec.TextOverflow.visible?l.map((function(t){return t+s})):l}},e}(),O=function(){function e(){}return e.prototype.getVerticalOffsets=function(e,i,n,r,a,o){var s=e.map((function(t){return t.lineHeight})),l=i.baselineCompensationY||0,h=0;if(0===e.length)return{baselineY:0,lineYOffsets:[]};switch(r.overflow){case t.spec.TextOverflow.visible:var c,f,u,p,x=r.maxTextHeight,g=null!=(c=i.bboxTop)?c:0,v=null!=(u=i.bboxBottom)?u:g+(null!=(f=i.bboxHeight)?f: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}h=m+l;break;case t.spec.TextOverflow.clip:var y=e[0];if(y){var S,T=y.richOptions.map((function(t){return t.fontSize})),w=(S=Math).max.apply(S,[].concat(T.length?T:[a.fontSize]))*a.fontScale*o;h=r.getOffsetYRich(a,s,w)+l}else h=r.getOffsetYRich(a,s,a.fontSize*a.fontScale)+l;break;case t.spec.TextOverflow.display:for(var b=r.maxTextHeight,A=[0],O=1;O<e.length;O++)A[O]=A[O-1]+e[O].lineHeight;for(var z=1/0,C=-1/0,L=0;L<e.length;L++){var H,E,W=null!=(H=e[L].lineAscent)?H:0,R=null!=(E=e[L].lineDescent)?E:0;z=Math.min(z,A[L]-W),C=Math.max(C,A[L]+R)}var V=C-z,k=0;switch(r.textVerticalAlign){case t.spec.TextVerticalAlign.top:k=-z;break;case t.spec.TextVerticalAlign.middle:k=(b-V)/2-z;break;case t.spec.TextVerticalAlign.bottom:k=b-V-z}for(var M=[],F=k,D=0;D<e.length;D++)M.push(F),D<e.length-1&&(F+=e[D+1].lineHeight);return{baselineY:k,lineYOffsets:M}}var _=[],B=h;return e.forEach((function(t,i){_.push(B),i<e.length-1&&(B+=e[i+1].lineHeight)})),{baselineY:h,lineYOffsets:_}},e}(),z=function(){function e(){}return e.createWrapStrategy=function(t){return t?new S:new y},e.createOverflowStrategy=function(e){switch(e){case t.spec.TextOverflow.clip:return new w;case t.spec.TextOverflow.display:return new T;case t.spec.TextOverflow.visible:default:return new b}},e.createHorizontalAlignStrategy=function(){return new A},e.createVerticalAlignStrategy=function(){return new O},e}(),C=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=.1,n.ALPHA_FIX_VALUE=1/255,n.name="MRichText"+C++,n.initTextBase(i),n.richWrapStrategy=z.createWrapStrategy(),n.richOverflowStrategy=z.createOverflowStrategy(t.spec.TextOverflow.display),n.richHorizontalAlignStrategy=z.createHorizontalAlignStrategy(),n.richVerticalAlignStrategy=z.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 v(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=z.createWrapStrategy(t.wrapEnabled),this.richOverflowStrategy=z.createOverflowStrategy(t.overflow))},n.generateTextProgram=function(e){var i=this;this.processedTextOptions=[];var n=g((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=m(n.color)),i.processedTextOptions.push(a)}))}));n(e)},n.updateWithOptions=function(e){this.textStyle=new t.TextStyle(e),this.textLayout=new v(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){this.generateTextProgram(this.text);var n=0,r=0,a=this.textLayout,o=this.textStyle,s=a.overflow,l=a.letterSpace,h=void 0===l?0:l,c=this.context,f=[],u=o.fontSize*o.fontScale,p={richOptions:[],offsetX:[],width:0,lineHeight:u*this.singleLineHeight,offsetY:u*(this.singleLineHeight-1)/2};if(this.processedTextOptions.forEach((function(t){var e=t.text,a=t.isNewLine,s=t.fontSize;a&&(f.push(p),n=Math.max(n,p.width),p={richOptions:[],offsetX:[],width:0,lineHeight:u*i.singleLineHeight,offsetY:u*(i.singleLineHeight-1)/2},r+=p.lineHeight),c.font=(t.fontWeight||o.textWeight)+" 10px "+(t.fontFamily||o.fontFamily);var l=c.measureText(e),x=l.width;if(void 0!==l.actualBoundingBoxLeft&&void 0!==l.actualBoundingBoxRight){var g=l.actualBoundingBoxLeft+l.actualBoundingBoxRight;g>0&&(x=Math.max(x,g))}var v=s*i.singleLineHeight*o.fontScale;v>p.lineHeight&&(r+=v-p.lineHeight,p.lineHeight=v,p.offsetY=s*o.fontScale*(i.singleLineHeight-1)/2),p.offsetX.push(p.width),p.width+=(x<=0?0:x)*s*i.SCALE_FACTOR*o.fontScale+e.length*h,p.richOptions.push(t)})),f.push(p),n=Math.max(n,p.width),r+=p.lineHeight,0!==n&&0!==r){void 0!==this.size&&null!==this.size||(this.size=this.item.transform.size.clone());var x=this.size,g=x.x,v=void 0===g?1:g,d=x.y,m=void 0===d?1:d;if(!this.initialized){this.canvasSize=this.canvasSize?this.canvasSize:new t.math.Vector2(n,r);var y=this.canvasSize,S=y.x,T=y.y;this.item.transform.size.set(v*S*this.SCALE_FACTOR*this.SCALE_FACTOR,m*T*this.SCALE_FACTOR*this.SCALE_FACTOR),this.size=this.item.transform.size.clone(),this.initialized=!0}t.assertExist(this.canvasSize);var w=this.canvasSize,b=w.x,A=w.y;a.width=b/o.fontScale,a.height=A/o.fontScale,this.renderToTexture(b,A,e,(function(e){if(0!==f.length){var n=a.getOffsetY(o,f.length,u*i.singleLineHeight,o.fontSize);f.forEach((function(i,r){var l=i.richOptions,h=i.offsetX,c=i.width,f=c,u=h;if(s===t.spec.TextOverflow.display&&c>b){var p=b/c;f*=p,u=h.map((function(t){return t*p}))}var x=a.getOffsetX(o,f);r>0&&(n+=i.lineHeight-i.offsetY),l.forEach((function(i,r){var a=o.fontScale,l=o.textColor,h=o.fontFamily,f=o.textWeight,p=o.fontStyle,g=i.text,v=i.fontSize,d=i.fontColor,m=void 0===d?l:d,y=i.fontFamily,S=void 0===y?h:y,T=i.fontWeight,w=void 0===T?f:T,A=i.fontStyle,O=void 0===A?p:A,z=v;s===t.spec.TextOverflow.display&&c>b&&(z/=c/b);var C=u[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 h=this.richOverflowStrategy.apply(s.lines,l,n,this.textStyle),c=this.richHorizontalAlignStrategy.getHorizontalOffsets(s.lines,l,h,n,this.textStyle),f=this.richVerticalAlignStrategy.getVerticalOffsets(s.lines,l,h,n,this.textStyle,this.singleLineHeight);t.assertExist(this.canvasSize);var u=this.canvasSize,p=u.x,x=u.y;n.width=p/this.textStyle.fontScale,n.height=x/this.textStyle.fontScale,this.renderToTexture(p,x,e,(function(t){i.drawTextWithStrategies(t,s.lines,c,f,h,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;switch(l.overflow){case t.spec.TextOverflow.visible:var h,c,f,u,p,x=l.maxTextWidth,g=l.maxTextHeight,v=null!=(c=e.bboxTop)?c:0,d=null!=(u=e.bboxBottom)?u:v+(null!=(f=e.bboxHeight)?f:0),m=null!=(p=e.bboxHeight)?p:d-v,y=0;switch(l.textVerticalAlign){case t.spec.TextVerticalAlign.top:y=-v;break;case t.spec.TextVerticalAlign.middle:y=(g-m)/2-v;break;case t.spec.TextVerticalAlign.bottom:y=g-m-v}var S=y+v,T=y+d,w=Math.max(0,-S),b=Math.max(0,T-g),A=w,O=b;switch(l.textVerticalAlign){case t.spec.TextVerticalAlign.top:A=b,O=b;break;case t.spec.TextVerticalAlign.bottom:A=w,O=w;break;case t.spec.TextVerticalAlign.middle:A=w,O=b}var z,C=A,L=(e.lines||[]).map((function(t){return l.getOffsetXRich(i.textStyle,x,t.width)})),H=L.length>0?(h=Math).min.apply(h,[].concat(L)):0,E=Math.max(0,-H),W=E,R=x+W+E,V=g+A+O;e.baselineCompensationX=W,e.baselineCompensationY=C,e.canvasWidth=R,e.canvasHeight=V,this.canvasSize=new t.math.Vector2(R,V);var k=null!=(z=this.size)?z:this.item.transform.size,M=k.x,F=void 0===M?1:M,D=k.y,_=void 0===D?1:D;this.item.transform.size.set(F*R*this.SCALE_FACTOR*this.SCALE_FACTOR,_*V*this.SCALE_FACTOR*this.SCALE_FACTOR),this.size=this.item.transform.size.clone(),this.initialized=!0;break;case t.spec.TextOverflow.clip:var B,X=l.maxTextWidth,Y=l.maxTextHeight;e.canvasWidth=X,e.canvasHeight=Y,e.baselineCompensationX=0,e.baselineCompensationY=0,this.canvasSize=new t.math.Vector2(X,Y),l.width=X/this.textStyle.fontScale,l.height=Y/this.textStyle.fontScale;var P=null!=(B=this.size)?B:this.item.transform.size,N=P.x,j=void 0===N?1:N,I=P.y,U=void 0===I?1:I;this.item.transform.size.set(j*X*this.SCALE_FACTOR*this.SCALE_FACTOR,U*Y*this.SCALE_FACTOR*this.SCALE_FACTOR),this.size=this.item.transform.size.clone(),this.initialized=!0;break;case t.spec.TextOverflow.display:this.initialized||(this.canvasSize=new t.math.Vector2(l.maxTextWidth,l.maxTextHeight),this.item.transform.size.set(a*this.canvasSize.x*this.SCALE_FACTOR*this.SCALE_FACTOR,s*this.canvasSize.y*this.SCALE_FACTOR*this.SCALE_FACTOR),this.size=this.item.transform.size.clone(),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,h=s[n],c=o;r.forEach((function(e,n){var r=a.fontScale,o=a.textColor,s=a.fontFamily,f=a.textWeight,u=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?f:m,S=e.fontStyle,T=void 0===S?u: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,h+C+e.x,c)}))})),n<e.length-1&&(o+=e[n+1].lineHeight)}))},n.unsupported=function(t){throw new Error("RichTextComponent does not support "+t+" at runtime.")},n.setShadowOffsetY=function(t){this.unsupported("setShadowOffsetY")},n.setShadowBlur=function(t){this.unsupported("setShadowBlur")},n.setShadowOffsetX=function(t){this.unsupported("setShadowOffsetX")},n.setShadowColor=function(t){this.unsupported("setShadowColor")},n.setOutlineWidth=function(t){this.unsupported("setOutlineWidth")},n.setAutoWidth=function(t){this.unsupported("setAutoWidth")},n.setFontSize=function(t){this.unsupported("setFontSize")},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 L="2.8.0-alpha.0";t.registerPlugin("rich-text",s,t.VFXItem),t.logger.info("Plugin rich text version: "+L+"."),L!==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=s,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=g,exports.isRichText=function(t){var e=p(t).filter((function(t){var e=t.tokenType;return"ContextStart"===e||"ContextEnd"===e})),i=e.filter((function(t){return"ContextStart"===t.tokenType})),n=e.filter((function(t){return"ContextEnd"===t.tokenType}));return!(i.length!==n.length||!i.length)&&function t(e,i){var n=e[0],r=e.slice(1);if(void 0===i&&(i=[]),!n)return 0===i.length;if("ContextStart"===n.tokenType)return t(r,i.concat(n.value));if("ContextEnd"===n.tokenType)return i[i.length-1]===n.value&&t(r,i.slice(0,-1));throw 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(c)[1]:i.match(f)[1]}})))},exports.lexer=p,exports.richTextParser=x,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=L;
2
2
  //# sourceMappingURL=weapp.js.map