mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-12 22:17:00 +00:00
refactor(ui): remove unused utility helpers
This commit is contained in:
@@ -533,22 +533,3 @@ export type IconName = keyof typeof icons;
|
||||
export function icon(name: IconName): TemplateResult {
|
||||
return icons[name];
|
||||
}
|
||||
|
||||
export function renderIcon(name: IconName, className = "nav-item__icon"): TemplateResult {
|
||||
return html`<span class=${className} aria-hidden="true">${icons[name]}</span>`;
|
||||
}
|
||||
|
||||
// Legacy function for compatibility
|
||||
export function renderEmojiIcon(
|
||||
iconContent: string | TemplateResult,
|
||||
className: string,
|
||||
): TemplateResult {
|
||||
return html`<span class=${className} aria-hidden="true">${iconContent}</span>`;
|
||||
}
|
||||
|
||||
export function setEmojiIcon(target: HTMLElement | null, iconLocal: string): void {
|
||||
if (!target) {
|
||||
return;
|
||||
}
|
||||
target.textContent = iconLocal;
|
||||
}
|
||||
|
||||
@@ -10,14 +10,6 @@ import {
|
||||
} from "./format.ts";
|
||||
import type { CronJob, GatewaySessionRow, PresenceEntry } from "./types.ts";
|
||||
|
||||
export function formatPresenceSummary(entry: PresenceEntry): string {
|
||||
const host = entry.host ?? "unknown";
|
||||
const ip = entry.ip ? `(${entry.ip})` : "";
|
||||
const mode = entry.mode ?? "";
|
||||
const version = entry.version ?? "";
|
||||
return `${host} ${ip} ${mode} ${version}`.trim();
|
||||
}
|
||||
|
||||
export function formatPresenceAge(entry: PresenceEntry): string {
|
||||
const ts = entry.ts ?? null;
|
||||
return ts ? formatRelativeTimestamp(ts) : t("common.na");
|
||||
|
||||
@@ -279,53 +279,6 @@ export function resolveAssistantTextAvatar(value: string | null | undefined): st
|
||||
return trimmed;
|
||||
}
|
||||
|
||||
function isLikelyEmoji(value: string) {
|
||||
const trimmed = value.trim();
|
||||
if (!trimmed) {
|
||||
return false;
|
||||
}
|
||||
if (trimmed.length > 16) {
|
||||
return false;
|
||||
}
|
||||
let hasNonAscii = false;
|
||||
for (let i = 0; i < trimmed.length; i += 1) {
|
||||
if (trimmed.charCodeAt(i) > 127) {
|
||||
hasNonAscii = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!hasNonAscii) {
|
||||
return false;
|
||||
}
|
||||
if (trimmed.includes("://") || trimmed.includes("/") || trimmed.includes(".")) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
export function resolveAgentEmoji(
|
||||
agent: { identity?: { emoji?: string; avatar?: string } },
|
||||
agentIdentity?: AgentIdentityResult | null,
|
||||
) {
|
||||
const identityEmoji = normalizeOptionalString(agentIdentity?.emoji);
|
||||
if (identityEmoji && isLikelyEmoji(identityEmoji)) {
|
||||
return identityEmoji;
|
||||
}
|
||||
const agentEmoji = normalizeOptionalString(agent.identity?.emoji);
|
||||
if (agentEmoji && isLikelyEmoji(agentEmoji)) {
|
||||
return agentEmoji;
|
||||
}
|
||||
const identityAvatar = normalizeOptionalString(agentIdentity?.avatar);
|
||||
if (identityAvatar && isLikelyEmoji(identityAvatar)) {
|
||||
return identityAvatar;
|
||||
}
|
||||
const avatar = normalizeOptionalString(agent.identity?.avatar);
|
||||
if (avatar && isLikelyEmoji(avatar)) {
|
||||
return avatar;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
function resolveAgentTextAvatar(
|
||||
agent: { identity?: { emoji?: string; avatar?: string } },
|
||||
agentIdentity?: AgentIdentityResult | null,
|
||||
@@ -349,14 +302,6 @@ export function agentBadgeText(agentId: string, defaultId: string | null) {
|
||||
return defaultId && agentId === defaultId ? "default" : null;
|
||||
}
|
||||
|
||||
export function agentAvatarHue(id: string): number {
|
||||
let hash = 0;
|
||||
for (let i = 0; i < id.length; i += 1) {
|
||||
hash = (hash * 31 + id.charCodeAt(i)) | 0;
|
||||
}
|
||||
return ((hash % 360) + 360) % 360;
|
||||
}
|
||||
|
||||
export function formatBytes(bytes?: number) {
|
||||
if (bytes == null || !Number.isFinite(bytes)) {
|
||||
return "-";
|
||||
|
||||
Reference in New Issue
Block a user