@galacean/effects-plugin-rich-text 0.0.0-experimental-20250512

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs ADDED
@@ -0,0 +1,620 @@
1
+ /*!
2
+ * Name: @galacean/effects-plugin-rich-text
3
+ * Description: Galacean Effects player rich text plugin
4
+ * Author: Ant Group CO., Ltd.
5
+ * Contributors: 云垣
6
+ * Version: v0.0.0-experimental-20250512
7
+ */
8
+
9
+ import * as EFFECTS from '@galacean/effects';
10
+ import { AbstractPlugin, effectsClass, spec, math, assertExist, Texture, glContext, TextStyle, TextLayout, TextComponent, registerPlugin, VFXItem, logger } from '@galacean/effects';
11
+
12
+ function _set_prototype_of(o, p) {
13
+ _set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
14
+ o.__proto__ = p;
15
+ return o;
16
+ };
17
+ return _set_prototype_of(o, p);
18
+ }
19
+
20
+ function _inherits(subClass, superClass) {
21
+ if (typeof superClass !== "function" && superClass !== null) {
22
+ throw new TypeError("Super expression must either be null or a function");
23
+ }
24
+ subClass.prototype = Object.create(superClass && superClass.prototype, {
25
+ constructor: {
26
+ value: subClass,
27
+ writable: true,
28
+ configurable: true
29
+ }
30
+ });
31
+ if (superClass) _set_prototype_of(subClass, superClass);
32
+ }
33
+
34
+ var RichTextLoader = /*#__PURE__*/ function(AbstractPlugin) {
35
+ _inherits(RichTextLoader, AbstractPlugin);
36
+ function RichTextLoader() {
37
+ var _this;
38
+ _this = AbstractPlugin.apply(this, arguments) || this;
39
+ _this.name = "rich-text";
40
+ return _this;
41
+ }
42
+ return RichTextLoader;
43
+ }(AbstractPlugin);
44
+
45
+ function _array_like_to_array(arr, len) {
46
+ if (len == null || len > arr.length) len = arr.length;
47
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
48
+ return arr2;
49
+ }
50
+
51
+ function _unsupported_iterable_to_array(o, minLen) {
52
+ if (!o) return;
53
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
54
+ var n = Object.prototype.toString.call(o).slice(8, -1);
55
+ if (n === "Object" && o.constructor) n = o.constructor.name;
56
+ if (n === "Map" || n === "Set") return Array.from(n);
57
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
58
+ }
59
+
60
+ function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
61
+ var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
62
+ if (it) return (it = it.call(o)).next.bind(it);
63
+ // Fallback for engines without symbol support
64
+ if (Array.isArray(o) || (it = _unsupported_iterable_to_array(o)) || allowArrayLike && o && typeof o.length === "number") {
65
+ if (it) o = it;
66
+ var i = 0;
67
+ return function() {
68
+ if (i >= o.length) return {
69
+ done: true
70
+ };
71
+ return {
72
+ done: false,
73
+ value: o[i++]
74
+ };
75
+ };
76
+ }
77
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
78
+ }
79
+
80
+ var TokenType;
81
+ (function(TokenType) {
82
+ TokenType["ContextStart"] = "ContextStart";
83
+ TokenType["Text"] = "Text";
84
+ TokenType["ContextEnd"] = "ContextEnd";
85
+ })(TokenType || (TokenType = {}));
86
+ var contextStartRegexp = /^<([a-z]+)(=([^>]+))?>$/;
87
+ var contextEndRegexp = /^<\/([a-z]+)>$/;
88
+ var rules = [
89
+ [
90
+ "ContextStart",
91
+ /^<[a-z]+(=[^>]+)?>/
92
+ ],
93
+ [
94
+ "Text",
95
+ /^[^</>=]+/
96
+ ],
97
+ [
98
+ "ContextEnd",
99
+ /^<\/[a-z]+>/
100
+ ]
101
+ ];
102
+ var lexer = function(input, lexed, cursor) {
103
+ if (lexed === void 0) lexed = [];
104
+ if (cursor === void 0) cursor = 0;
105
+ if (!input) {
106
+ return lexed;
107
+ }
108
+ for(var _iterator = _create_for_of_iterator_helper_loose(rules), _step; !(_step = _iterator()).done;){
109
+ var _step_value = _step.value, tokenType = _step_value[0], regex = _step_value[1];
110
+ var _regex_exec;
111
+ var _ref = (_regex_exec = regex.exec(input)) != null ? _regex_exec : [], tokenMatch = _ref[0];
112
+ if (tokenMatch) {
113
+ var len = tokenMatch.length;
114
+ return lexer(input.slice(len), lexed.concat({
115
+ tokenType: tokenType,
116
+ value: tokenMatch
117
+ }), cursor + len);
118
+ }
119
+ }
120
+ throw new Error('Unexpected token: "' + input[0] + '" at position ' + cursor + ' while reading "' + input + '"');
121
+ };
122
+ var richTextParser = function(input) {
123
+ var Text = function Text() {
124
+ var maybeText = peek();
125
+ if ((maybeText == null ? void 0 : maybeText.tokenType) === "Text") {
126
+ shift();
127
+ return maybeText.value;
128
+ }
129
+ return undefined;
130
+ };
131
+ var ContextStart = function ContextStart() {
132
+ var maybeContextStart = peek();
133
+ if ((maybeContextStart == null ? void 0 : maybeContextStart.tokenType) === "ContextStart") {
134
+ shift();
135
+ var matches = maybeContextStart.value.match(contextStartRegexp);
136
+ if (matches) {
137
+ var attributeName = matches[1];
138
+ var _matches_;
139
+ var attributeParam = (_matches_ = matches[3]) != null ? _matches_ : "";
140
+ return {
141
+ attributeName: attributeName,
142
+ attributeParam: attributeParam
143
+ };
144
+ }
145
+ throw new Error("Expected a start tag marker at position " + cursor);
146
+ }
147
+ return {};
148
+ };
149
+ var ContextEnd = function ContextEnd() {
150
+ var maybeContextEnd = peek();
151
+ if ((maybeContextEnd == null ? void 0 : maybeContextEnd.tokenType) === "ContextEnd") {
152
+ shift();
153
+ var matches = maybeContextEnd.value.match(contextEndRegexp);
154
+ if (matches) {
155
+ var attributeName = matches[1];
156
+ return {
157
+ attributeName: attributeName
158
+ };
159
+ }
160
+ throw new Error("Expect an end tag marker at position " + cursor);
161
+ }
162
+ return {};
163
+ };
164
+ var lexed = lexer(input);
165
+ var cursor = 0;
166
+ var shift = function() {
167
+ var shifted = lexed.shift();
168
+ var _shifted_value_length;
169
+ cursor += (_shifted_value_length = shifted == null ? void 0 : shifted.value.length) != null ? _shifted_value_length : 0;
170
+ return shifted;
171
+ };
172
+ var peek = function() {
173
+ return lexed[0];
174
+ };
175
+ var ast = [];
176
+ function Grammar(attributes, expectedEndAttributeName) {
177
+ if (attributes === void 0) attributes = [];
178
+ if (expectedEndAttributeName === void 0) expectedEndAttributeName = "";
179
+ var parsing = true;
180
+ while(parsing){
181
+ var maybeText = Text();
182
+ if (maybeText) {
183
+ ast.push({
184
+ attributes: attributes,
185
+ text: maybeText
186
+ });
187
+ continue;
188
+ }
189
+ var _ContextStart = ContextStart(), attributeName = _ContextStart.attributeName, attributeParam = _ContextStart.attributeParam;
190
+ if (attributeName) {
191
+ Grammar(attributes.concat({
192
+ attributeName: attributeName,
193
+ attributeParam: attributeParam
194
+ }), attributeName);
195
+ continue;
196
+ }
197
+ if (expectedEndAttributeName) {
198
+ var _ContextEnd = ContextEnd(), endAttributeName = _ContextEnd.attributeName;
199
+ if (!endAttributeName) {
200
+ throw new Error('Expect an end tag marker "' + expectedEndAttributeName + '" at position ' + cursor + " but found no tag!");
201
+ }
202
+ if (endAttributeName !== expectedEndAttributeName) {
203
+ throw new Error('Expect an end tag marker "' + expectedEndAttributeName + '" at position ' + cursor + ' but found tag "' + endAttributeName + '"');
204
+ }
205
+ return;
206
+ }
207
+ break;
208
+ }
209
+ }
210
+ Grammar();
211
+ return ast;
212
+ };
213
+ function generateProgram(textHandler) {
214
+ return function(richText) {
215
+ var ast = richTextParser(richText);
216
+ for(var _iterator = _create_for_of_iterator_helper_loose(ast), _step; !(_step = _iterator()).done;){
217
+ var node = _step.value;
218
+ var text = node.text;
219
+ var context = node.attributes.reduce(function(ctx, param) {
220
+ var attributeName = param.attributeName, attributeParam = param.attributeParam;
221
+ if (attributeName) {
222
+ ctx[attributeName] = attributeParam;
223
+ }
224
+ return ctx;
225
+ }, {});
226
+ textHandler(text, context);
227
+ }
228
+ };
229
+ }
230
+ function isRichText(text) {
231
+ var lexed = lexer(text);
232
+ var contextTokens = lexed.filter(function(param) {
233
+ var tokenType = param.tokenType;
234
+ return tokenType === "ContextStart" || tokenType === "ContextEnd";
235
+ });
236
+ var contextStartTokens = contextTokens.filter(function(param) {
237
+ var tokenType = param.tokenType;
238
+ return tokenType === "ContextStart";
239
+ });
240
+ var contextEndTokens = contextTokens.filter(function(param) {
241
+ var tokenType = param.tokenType;
242
+ return tokenType === "ContextEnd";
243
+ });
244
+ if (contextStartTokens.length !== contextEndTokens.length || !contextStartTokens.length) {
245
+ return false;
246
+ }
247
+ var tokensOfAttribute = contextTokens.map(function(param) {
248
+ var tokenType = param.tokenType, value = param.value;
249
+ return {
250
+ tokenType: tokenType,
251
+ value: tokenType === "ContextStart" ? value.match(contextStartRegexp)[1] : value.match(contextEndRegexp)[1]
252
+ };
253
+ });
254
+ function checkPaired(param, startContextAttributes) {
255
+ var token = param[0], restToken = param.slice(1);
256
+ if (startContextAttributes === void 0) startContextAttributes = [];
257
+ if (!token) {
258
+ return startContextAttributes.length === 0;
259
+ }
260
+ if (token.tokenType === "ContextStart") {
261
+ return checkPaired(restToken, startContextAttributes.concat(token.value));
262
+ } else if (token.tokenType === "ContextEnd") {
263
+ var attributeName = startContextAttributes[startContextAttributes.length - 1];
264
+ if (attributeName !== token.value) {
265
+ return false;
266
+ }
267
+ return checkPaired(restToken, startContextAttributes.slice(0, -1));
268
+ }
269
+ throw new Error("Unexpected token: " + token.tokenType);
270
+ }
271
+ return checkPaired(tokensOfAttribute);
272
+ }
273
+
274
+ function __decorate(decorators, target, key, desc) {
275
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
276
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
277
+ else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
278
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
279
+ }
280
+ typeof SuppressedError === "function" ? SuppressedError : function _SuppressedError(error, suppressed, message) {
281
+ var e = new Error(message);
282
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
283
+ };
284
+
285
+ /**
286
+ * 将颜色名称转换为 RGBA
287
+ * @param colorName - 颜色名称
288
+ * @returns RGBA 颜色字符串
289
+ */ function colorNameToRGBA(colorName) {
290
+ if (typeof colorName !== "string" || !colorName) {
291
+ throw new Error("Invalid color name provided");
292
+ }
293
+ if (typeof document === "undefined") {
294
+ throw new Error("This method requires a browser environment");
295
+ }
296
+ var canvas = document.createElement("canvas");
297
+ var context = canvas.getContext("2d");
298
+ if (context) {
299
+ try {
300
+ context.fillStyle = colorName;
301
+ var result = context.fillStyle;
302
+ return result;
303
+ } finally{
304
+ // Clean up DOM element
305
+ canvas.remove();
306
+ }
307
+ }
308
+ throw new Error("Failed to get 2D context for color conversion!");
309
+ }
310
+ /**
311
+ * 将 16 进制颜色转换为 RGBA
312
+ * @param hex - 16 进制颜色
313
+ * @param alpha - 透明度
314
+ * @returns - RGBA 颜色
315
+ */ function hexToRGBA(hex, alpha) {
316
+ if (alpha === void 0) alpha = 1;
317
+ hex = hex.replace(/^#/, "");
318
+ if (hex.length === 3 || hex.length === 4) {
319
+ hex = hex.split("").map(function(char) {
320
+ return char + char;
321
+ }).join("");
322
+ }
323
+ // Handle alpha channel in hex
324
+ if (hex.length === 8) {
325
+ var a = parseInt(hex.slice(6, 8), 16) / 255;
326
+ hex = hex.slice(0, 6);
327
+ alpha = a;
328
+ }
329
+ var bigint = parseInt(hex, 16);
330
+ var r = bigint >> 16 & 255;
331
+ var g = bigint >> 8 & 255;
332
+ var b = bigint & 255;
333
+ return [
334
+ r,
335
+ g,
336
+ b,
337
+ alpha
338
+ ];
339
+ }
340
+ /**
341
+ * 将颜色字符串转换为 RGBA
342
+ * @param color - 颜色字符串
343
+ * @param alpha - 透明度
344
+ * @returns - RGBA 颜色
345
+ */ function toRGBA(color, alpha) {
346
+ if (alpha === void 0) alpha = 1;
347
+ if (typeof color !== "string" || !color) {
348
+ throw new Error("Invalid color string");
349
+ }
350
+ if (color.startsWith("#")) {
351
+ return hexToRGBA(color, alpha);
352
+ } else {
353
+ return hexToRGBA(colorNameToRGBA(color));
354
+ }
355
+ }
356
+
357
+ var seed = 0;
358
+ var RichTextComponent = /*#__PURE__*/ function(TextComponent) {
359
+ _inherits(RichTextComponent, TextComponent);
360
+ function RichTextComponent(engine) {
361
+ var _this;
362
+ _this = TextComponent.call(this, engine) || this;
363
+ _this.processedTextOptions = [];
364
+ _this.singleLineHeight = 1.571;
365
+ _this.size = null;
366
+ /**
367
+ * 获取第一次渲染的 size
368
+ */ _this.initialized = false;
369
+ /**
370
+ * canvas 大小
371
+ */ _this.canvasSize = null;
372
+ _this.name = "MRichText" + seed++;
373
+ return _this;
374
+ }
375
+ var _proto = RichTextComponent.prototype;
376
+ _proto.generateTextProgram = function generateTextProgram(text) {
377
+ var _this = this;
378
+ this.processedTextOptions = [];
379
+ var program = generateProgram(function(text, context) {
380
+ // 如果富文本仅包含换行符,则在每个换行符后添加一个空格
381
+ if (/^\n+$/.test(text)) {
382
+ text = text.replace(/\n/g, "\n ");
383
+ }
384
+ var textArr = text.split("\n");
385
+ textArr.forEach(function(text, index) {
386
+ var options = {
387
+ text: text,
388
+ fontSize: _this.textStyle.fontSize,
389
+ isNewLine: false
390
+ };
391
+ if (index > 0) {
392
+ options.isNewLine = true;
393
+ }
394
+ if ("b" in context) {
395
+ options.fontWeight = spec.TextWeight.bold;
396
+ }
397
+ if ("i" in context) {
398
+ options.fontStyle = spec.FontStyle.italic;
399
+ }
400
+ if ("size" in context && context.size) {
401
+ options.fontSize = parseInt(context.size, 10);
402
+ }
403
+ if ("color" in context && context.color) {
404
+ options.fontColor = toRGBA(context.color);
405
+ }
406
+ _this.processedTextOptions.push(options);
407
+ });
408
+ });
409
+ program(text);
410
+ };
411
+ _proto.updateTexture = function updateTexture(flipY) {
412
+ var _this = this;
413
+ if (flipY === void 0) flipY = true;
414
+ if (!this.isDirty || !this.context || !this.canvas) {
415
+ return;
416
+ }
417
+ this.generateTextProgram(this.text);
418
+ var width = 0, height = 0;
419
+ var _this1 = this, textLayout = _this1.textLayout, textStyle = _this1.textStyle;
420
+ var overflow = textLayout.overflow, _textLayout_letterSpace = textLayout.letterSpace, letterSpace = _textLayout_letterSpace === void 0 ? 0 : _textLayout_letterSpace;
421
+ var context = this.context;
422
+ context.save();
423
+ var charsInfo = [];
424
+ var fontHeight = textStyle.fontSize * this.textStyle.fontScale;
425
+ var charInfo = {
426
+ richOptions: [],
427
+ offsetX: [],
428
+ width: 0,
429
+ lineHeight: fontHeight * this.singleLineHeight,
430
+ offsetY: fontHeight * (this.singleLineHeight - 1) / 2
431
+ };
432
+ this.processedTextOptions.forEach(function(options) {
433
+ var text = options.text, isNewLine = options.isNewLine, fontSize = options.fontSize;
434
+ if (isNewLine) {
435
+ charsInfo.push(charInfo);
436
+ width = Math.max(width, charInfo.width);
437
+ charInfo = {
438
+ richOptions: [],
439
+ offsetX: [],
440
+ width: 0,
441
+ lineHeight: fontHeight * _this.singleLineHeight,
442
+ offsetY: fontHeight * (_this.singleLineHeight - 1) / 2
443
+ };
444
+ height += charInfo.lineHeight;
445
+ }
446
+ //恢复默认设置
447
+ context.font = (options.fontWeight || textStyle.textWeight) + " 10px " + (options.fontFamily || textStyle.fontFamily);
448
+ var textWidth = context.measureText(text).width;
449
+ var textHeight = fontSize * _this.singleLineHeight * _this.textStyle.fontScale;
450
+ if (textHeight > charInfo.lineHeight) {
451
+ height += textHeight - charInfo.lineHeight;
452
+ charInfo.lineHeight = textHeight;
453
+ charInfo.offsetY = fontSize * _this.textStyle.fontScale * (_this.singleLineHeight - 1) / 2;
454
+ }
455
+ charInfo.offsetX.push(charInfo.width);
456
+ charInfo.width += (textWidth <= 0 ? 0 : textWidth) * fontSize * _this.SCALE_FACTOR * _this.textStyle.fontScale + text.length * letterSpace;
457
+ charInfo.richOptions.push(options);
458
+ });
459
+ charsInfo.push(charInfo);
460
+ width = Math.max(width, charInfo.width);
461
+ height += charInfo.lineHeight;
462
+ if (width === 0 || height === 0) {
463
+ this.isDirty = false;
464
+ return;
465
+ }
466
+ if (this.size === undefined || this.size === null) {
467
+ this.size = this.item.transform.size.clone();
468
+ }
469
+ var _this_size = this.size, _this_size_x = _this_size.x, x = _this_size_x === void 0 ? 1 : _this_size_x, _this_size_y = _this_size.y, y = _this_size_y === void 0 ? 1 : _this_size_y;
470
+ if (!this.initialized) {
471
+ this.canvasSize = !this.canvasSize ? new math.Vector2(width, height) : this.canvasSize;
472
+ var _this_canvasSize = this.canvasSize, canvasWidth = _this_canvasSize.x, canvasHeight = _this_canvasSize.y;
473
+ this.item.transform.size.set(x * canvasWidth * this.SCALE_FACTOR * this.SCALE_FACTOR, y * canvasHeight * this.SCALE_FACTOR * this.SCALE_FACTOR);
474
+ this.size = this.item.transform.size.clone();
475
+ this.initialized = true;
476
+ }
477
+ assertExist(this.canvasSize);
478
+ var _this_canvasSize1 = this.canvasSize, canvasWidth1 = _this_canvasSize1.x, canvasHeight1 = _this_canvasSize1.y;
479
+ this.textLayout.width = canvasWidth1 / textStyle.fontScale;
480
+ this.textLayout.height = canvasHeight1 / textStyle.fontScale;
481
+ this.canvas.width = canvasWidth1;
482
+ this.canvas.height = canvasHeight1;
483
+ context.clearRect(0, 0, canvasWidth1, canvasHeight1);
484
+ // fix bug 1/255
485
+ context.fillStyle = "rgba(255, 255, 255, " + this.ALPHA_FIX_VALUE + ")";
486
+ if (!flipY) {
487
+ context.translate(0, canvasHeight1);
488
+ context.scale(1, -1);
489
+ }
490
+ if (charsInfo.length === 0) {
491
+ return;
492
+ }
493
+ var charsLineHeight = textLayout.getOffsetY(textStyle, charsInfo.length, fontHeight * this.singleLineHeight, textStyle.fontSize);
494
+ charsInfo.forEach(function(charInfo, index) {
495
+ var richOptions = charInfo.richOptions, offsetX = charInfo.offsetX, width = charInfo.width;
496
+ var charWidth = width;
497
+ var offset = offsetX;
498
+ if (overflow === spec.TextOverflow.display) {
499
+ if (width > canvasWidth1) {
500
+ var canvasScale = canvasWidth1 / width;
501
+ charWidth *= canvasScale;
502
+ offset = offsetX.map(function(x) {
503
+ return x * canvasScale;
504
+ });
505
+ }
506
+ }
507
+ var x = _this.textLayout.getOffsetX(textStyle, charWidth);
508
+ if (index > 0) {
509
+ charsLineHeight += charInfo.lineHeight - charInfo.offsetY;
510
+ }
511
+ richOptions.forEach(function(options, index) {
512
+ var fontScale = textStyle.fontScale, textColor = textStyle.textColor, textFamily = textStyle.fontFamily, textWeight = textStyle.textWeight, richStyle = textStyle.fontStyle;
513
+ var text = options.text, fontSize = options.fontSize, _options_fontColor = options.fontColor, fontColor = _options_fontColor === void 0 ? textColor : _options_fontColor, _options_fontFamily = options.fontFamily, fontFamily = _options_fontFamily === void 0 ? textFamily : _options_fontFamily, _options_fontWeight = options.fontWeight, fontWeight = _options_fontWeight === void 0 ? textWeight : _options_fontWeight, _options_fontStyle = options.fontStyle, fontStyle = _options_fontStyle === void 0 ? richStyle : _options_fontStyle;
514
+ var textSize = fontSize;
515
+ if (overflow === spec.TextOverflow.display) {
516
+ if (width > canvasWidth1) {
517
+ textSize /= width / canvasWidth1;
518
+ }
519
+ }
520
+ context.font = fontStyle + " " + fontWeight + " " + textSize * fontScale + "px " + fontFamily;
521
+ context.fillStyle = "rgba(" + fontColor[0] + ", " + fontColor[1] + ", " + fontColor[2] + ", " + fontColor[3] + ")";
522
+ var strOffsetX = offset[index] + x;
523
+ if (text === " ") {
524
+ context.fillText(text, offset[index] + x, charsLineHeight);
525
+ } else {
526
+ for(var i = 0; i < text.length; i++){
527
+ var str = text[i];
528
+ var x1 = context.measureText(str).width;
529
+ context.fillText(str, strOffsetX, charsLineHeight);
530
+ strOffsetX += x1 + (i === text.length - 1 || text === " " ? 0 : letterSpace * textSize / fontSize);
531
+ }
532
+ }
533
+ });
534
+ });
535
+ //与 toDataURL() 两种方式都需要像素读取操作
536
+ var imageData = context.getImageData(0, 0, this.canvas.width, this.canvas.height);
537
+ var texture = Texture.createWithData(this.engine, {
538
+ data: new Uint8Array(imageData.data),
539
+ width: imageData.width,
540
+ height: imageData.height
541
+ }, {
542
+ flipY: flipY,
543
+ magFilter: glContext.LINEAR,
544
+ minFilter: glContext.LINEAR,
545
+ wrapS: glContext.CLAMP_TO_EDGE,
546
+ wrapT: glContext.CLAMP_TO_EDGE
547
+ });
548
+ this.renderer.texture = texture;
549
+ this.material.setTexture("_MainTex", texture);
550
+ this.isDirty = false;
551
+ context.restore();
552
+ };
553
+ /**
554
+ * 该方法富文本组件不支持
555
+ * @param value - 水平偏移距离
556
+ * @returns
557
+ */ _proto.setShadowOffsetY = function setShadowOffsetY(value) {
558
+ throw new Error("Method not implemented.");
559
+ };
560
+ /**
561
+ * 该方法富文本组件不支持
562
+ * @param value - 模糊程度
563
+ */ _proto.setShadowBlur = function setShadowBlur(value) {
564
+ throw new Error("Method not implemented.");
565
+ };
566
+ /**
567
+ * 该方法富文本组件不支持
568
+ * @param value - 水平偏移距离
569
+ */ _proto.setShadowOffsetX = function setShadowOffsetX(value) {
570
+ throw new Error("Method not implemented.");
571
+ };
572
+ /**
573
+ * 该方法富文本组件不支持
574
+ * @param value - 阴影颜色
575
+ */ _proto.setShadowColor = function setShadowColor(value) {
576
+ throw new Error("Method not implemented.");
577
+ };
578
+ /**
579
+ * 该方法富文本组件不支持
580
+ * @param value - 外描边宽度
581
+ * @returns
582
+ */ _proto.setOutlineWidth = function setOutlineWidth(value) {
583
+ throw new Error("Method not implemented.");
584
+ };
585
+ /**
586
+ * 该方法富文本组件不支持
587
+ * @param value - 是否自动设置宽度
588
+ */ _proto.setAutoWidth = function setAutoWidth(value) {
589
+ throw new Error("Method not implemented.");
590
+ };
591
+ _proto.updateWithOptions = function updateWithOptions(options) {
592
+ this.textStyle = new TextStyle(options);
593
+ this.textLayout = new TextLayout(options);
594
+ this.textLayout.textBaseline = options.textBaseline || spec.TextBaseline.middle;
595
+ this.text = options.text ? options.text.toString() : " ";
596
+ };
597
+ _proto.renderText = function renderText(options) {
598
+ var size = options.size;
599
+ if (size) {
600
+ this.canvasSize = new math.Vector2(size[0], size[1]);
601
+ }
602
+ this.updateTexture();
603
+ };
604
+ return RichTextComponent;
605
+ }(TextComponent);
606
+ RichTextComponent = __decorate([
607
+ effectsClass(spec.DataType.RichTextComponent)
608
+ ], RichTextComponent);
609
+
610
+ /**
611
+ * 插件版本号
612
+ */ var version = "0.0.0-experimental-20250512";
613
+ registerPlugin("rich-text", RichTextLoader, VFXItem);
614
+ logger.info("Plugin rich text version: " + version + ".");
615
+ if (version !== EFFECTS.version) {
616
+ 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!");
617
+ }
618
+
619
+ export { RichTextComponent, RichTextLoader, generateProgram, isRichText, lexer, richTextParser, version };
620
+ //# sourceMappingURL=index.mjs.map