* 创建并显示翻译提示弹窗
(element: HTMLElement, message: string, type: 'translating' | 'success' | 'error')
| 830 | * 创建并显示翻译提示弹窗 |
| 831 | */ |
| 832 | function createTranslationTooltip(element: HTMLElement, message: string, type: 'translating' | 'success' | 'error'): HTMLElement { |
| 833 | // 移除已存在的提示 |
| 834 | removeExistingTooltip(); |
| 835 | |
| 836 | const tooltip = document.createElement('div'); |
| 837 | tooltip.className = `fluent-input-tooltip ${type}`; |
| 838 | tooltip.id = 'fluent-input-translation-tooltip'; |
| 839 | |
| 840 | // 添加图标和文字 |
| 841 | const icon = getTooltipIcon(type); |
| 842 | tooltip.innerHTML = `${icon} ${message}`; |
| 843 | |
| 844 | // 计算位置 |
| 845 | const rect = element.getBoundingClientRect(); |
| 846 | const tooltipTop = rect.bottom + window.scrollY + 12; |
| 847 | const tooltipLeft = rect.left + window.scrollX + (rect.width / 2); |
| 848 | |
| 849 | tooltip.style.top = `${tooltipTop}px`; |
| 850 | tooltip.style.left = `${tooltipLeft}px`; |
| 851 | tooltip.style.transform = 'translateX(-50%)'; |
| 852 | |
| 853 | // 如果禁用动画,直接显示,否则使用淡入效果 |
| 854 | if (!config.animations) { |
| 855 | tooltip.style.opacity = '1'; |
| 856 | tooltip.style.transform = 'translateX(-50%) translateY(0)'; |
| 857 | } else { |
| 858 | tooltip.style.opacity = '0'; |
| 859 | setTimeout(() => { |
| 860 | tooltip.classList.add('show'); |
| 861 | }, 10); |
| 862 | } |
| 863 | |
| 864 | document.body.appendChild(tooltip); |
| 865 | return tooltip; |
| 866 | } |
| 867 | |
| 868 | /** |
| 869 | * 获取提示图标 |
no test coverage detected