feat: RTL布局支持 — close动画方向自动适配语言方向

This commit is contained in:
tianhao
2026-06-16 13:01:25 +08:00
parent fc3132f330
commit 88ae899d96
+4 -3
View File
@@ -9,7 +9,7 @@ import { generateId, escapeHTML } from './utils.js';
import { DEFAULTS, ICONS, TYPE_COLORS, THEMES } from './constants.js';
import { injectStyles } from './styles.js';
import { getTheme, applyTheme } from './themes.js';
import { t as i18nT, setCurrentLocale } from './i18n.js';
import { t as i18nT, setCurrentLocale, getLocaleDirection, getCurrentLocale } from './i18n.js';
// 模块级共享容器缓存,所有 Toast 实例共用
// 使用 Map 而非 WeakMapdocument.body 在页面存活期间永不被 GC,
@@ -493,10 +493,11 @@ class Toast {
el.classList.remove('met-show');
const pos = this.config.position || 'top-right';
const isRTL = getLocaleDirection(getCurrentLocale()) === 'rtl';
let transform = 'scale(.96)';
if (pos.includes('right')) transform = 'translateX(120%)';
else if (pos.includes('left')) transform = 'translateX(-120%)';
if (pos.includes('right')) transform = isRTL ? 'translateX(-120%)' : 'translateX(120%)';
else if (pos.includes('left')) transform = isRTL ? 'translateX(120%)' : 'translateX(-120%)';
else if (pos.startsWith('top')) transform = 'translateY(-20px)';
else transform = 'translateY(20px)';