Files
tk-mini-program/unpackage/dist/dev/mp-weixin/TUIKit/components/TUIChat/emoji-config/index.js
pengxiaolong acc81963e9 优化页面
2025-06-20 21:55:09 +08:00

63 lines
2.4 KiB
JavaScript

"use strict";
const common_vendor = require("../../../../common/vendor.js");
const TUIKit_components_TUIChat_emojiConfig_defaultEmoji = require("./default-emoji.js");
const TUIKit_components_TUIChat_emojiConfig_locales_zh_cn = require("./locales/zh_cn.js");
const TUIKit_utils_env = require("../../../utils/env.js");
const BASIC_EMOJI_URL = TUIKit_components_TUIChat_emojiConfig_defaultEmoji.DEFAULT_BASIC_EMOJI_URL;
const BASIC_EMOJI_URL_MAPPING = TUIKit_components_TUIChat_emojiConfig_defaultEmoji.DEFAULT_BASIC_EMOJI_URL_MAPPING;
const convertKeyToEmojiName = (key) => {
return TUIKit_utils_env.isWeChat ? TUIKit_components_TUIChat_emojiConfig_locales_zh_cn.Emoji[key] : common_vendor.Wt.t(`Emoji.${key}`);
};
const transformTextWithKeysToEmojiNames = (text) => {
if (!text) {
return "";
}
const reg = /(\[.+?\])/g;
let txt = text;
if (reg.test(text)) {
txt = text.replace(reg, (match) => BASIC_EMOJI_URL_MAPPING[match] ? convertKeyToEmojiName(match) : match);
}
return txt;
};
const transformTextWithEmojiNamesToKeys = (text) => {
if (!text) {
return "";
}
const reg = /(\[.+?\])/g;
let txt = text;
if (reg.test(text)) {
txt = text.replace(reg, (match) => TUIKit_components_TUIChat_emojiConfig_defaultEmoji.BASIC_EMOJI_NAME_TO_KEY_MAPPING[match] || match);
}
return txt;
};
const parseTextToRenderArray = (text) => {
const emojiRegex = /\[([^\]]+)\]/g;
const result = [];
let match;
let lastIndex = 0;
while ((match = emojiRegex.exec(text)) !== null) {
const startIndex = match.index;
const endIndex = emojiRegex.lastIndex;
const emojiKey = match[0];
if (startIndex > lastIndex) {
result.push({ type: "text", content: text.substring(lastIndex, startIndex) });
}
const emojiUrl = BASIC_EMOJI_URL + BASIC_EMOJI_URL_MAPPING[emojiKey];
if (emojiUrl) {
result.push({ type: "image", content: emojiUrl, emojiKey });
} else {
result.push({ type: "text", content: emojiKey });
}
lastIndex = endIndex;
emojiRegex.lastIndex = lastIndex;
}
if (lastIndex < text.length) {
result.push({ type: "text", content: text.substring(lastIndex) });
}
return result;
};
exports.parseTextToRenderArray = parseTextToRenderArray;
exports.transformTextWithEmojiNamesToKeys = transformTextWithEmojiNamesToKeys;
exports.transformTextWithKeysToEmojiNames = transformTextWithKeysToEmojiNames;
//# sourceMappingURL=../../../../../.sourcemap/mp-weixin/TUIKit/components/TUIChat/emoji-config/index.js.map