refactor: 第三方库替换 & 代码精简 — v5.1.5
- Markdown 解析器:内联正则 → marked 库(完整 GFM 支持) - HTML 净化器:内联 DOM 遍历 → DOMPurify(业界标准) - crypto.ts:删除 sha256js/xorBytes 死代码回退路径 - 消除 5 个文件中 escapeHtml/formatSize 重复定义 - 版本号升级至 5.1.5
This commit is contained in:
@@ -8,6 +8,8 @@ let titleEl: HTMLElement | null = null;
|
||||
let bodyEl: HTMLElement | null = null;
|
||||
let inputEl: HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement | null = null;
|
||||
let okBtn: HTMLButtonElement | null = null;
|
||||
|
||||
import { escapeHtml } from '../utils/utils.js';
|
||||
let cancelBtn: HTMLButtonElement | null = null;
|
||||
let resolveFn: ((value: string | null) => void) | null = null;
|
||||
|
||||
@@ -136,6 +138,4 @@ export function showConfirm(message: string, title = '确认'): Promise<boolean>
|
||||
});
|
||||
}
|
||||
|
||||
function escapeHtml(text: string): string {
|
||||
return text.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
import type { ToolCall } from '../types.js';
|
||||
import { getToolIcon, formatToolName } from '../services/tool-registry.js';
|
||||
import { logDebug, logInfo } from '../services/log-service.js';
|
||||
import { escapeHtml } from '../utils/utils.js';
|
||||
|
||||
let modalEl: HTMLElement | null = null;
|
||||
let resolveConfirm: ((confirmed: boolean) => void) | null = null;
|
||||
@@ -117,7 +118,4 @@ function cancelConfirm(): void {
|
||||
}
|
||||
}
|
||||
|
||||
function escapeHtml(str: string): string {
|
||||
const map: Record<string, string> = { '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' };
|
||||
return str.replace(/[&<>"']/g, c => map[c]);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
*/
|
||||
|
||||
import { logInfo, logError, logDebug } from '../services/log-service.js';
|
||||
import { escapeHtml, formatSize } from '../utils/utils.js';
|
||||
|
||||
// ── 工具卡片类型 ──
|
||||
interface ToolCallRecord {
|
||||
@@ -105,13 +106,6 @@ const ANSI_COLORS: Record<string, string> = {
|
||||
'94': '#8ec8ff', '95': '#e8a0e8', '96': '#5ee8e8', '97': '#fff',
|
||||
};
|
||||
|
||||
function escapeHtml(text: string): string {
|
||||
return text
|
||||
.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/"/g, '"');
|
||||
}
|
||||
|
||||
function ansiToHtml(raw: string): string {
|
||||
// 先转义 HTML
|
||||
@@ -759,12 +753,6 @@ function getFileIcon(name: string): string {
|
||||
return iconMap[ext] || '📄';
|
||||
}
|
||||
|
||||
function formatSize(bytes: number): string {
|
||||
if (bytes < 1024) return bytes + ' B';
|
||||
if (bytes < 1024 * 1024) return (bytes / 1024).toFixed(1) + ' KB';
|
||||
return (bytes / (1024 * 1024)).toFixed(1) + ' MB';
|
||||
}
|
||||
|
||||
// ── 工具调用管理 ──
|
||||
|
||||
/** 是否有命令正在终端中执行 */
|
||||
|
||||
Reference in New Issue
Block a user