/** * @file RichOutline.ts * @description RichText 描边(outline)BBCode 包裹工具 * * 背景: * Cocos Creator 3.x 的 cc.RichText 原生支持 标签: * 文本 * 无需新增组件即可为富文本提供描边能力。 * * 使用: * import { outlineRich } from "./RichOutline"; * this.info_rich.string = outlineRich(desc); // 默认黑色 2px * this.info_rich.string = outlineRich(desc, "#000", 1); // 自定义 * * 注意: * - 为包裹型标签,需成对出现;内部可嵌套 / 等标签。 * - width 为像素宽度(int),color 支持 #RGB/#RRGGBB。 * - 空字符串直接返回,不包裹空标签。 */ /** 默认描边颜色(深黑,深色面板通用) */ export const RICH_OUTLINE_COLOR = "#000000"; /** 默认描边宽度(像素) */ export const RICH_OUTLINE_WIDTH = 2; /** * 为 RichText 富文本串包裹描边标签 * @param text 原始 BBCode 富文本(可为空串) * @param color 描边颜色(默认 #000000) * @param width 描边宽度像素(默认 2) * @returns 包裹 后的富文本串;空串原样返回 */ export function outlineRich(text: string, color: string = RICH_OUTLINE_COLOR, width: number = RICH_OUTLINE_WIDTH): string { if (!text) return text; return `${text}`; }