4e2224e9dc
- /voice 页面:中间圆球 + 左右按钮 + 状态图标 + 右下角气泡(进场/淡出/阶梯字号/上限8)+ 噪声门弧线电平,结构类名与原版一致 - s2s WebSocket 客户端 + worklet 音频(mic-capture/audio-playback)+ orb 可视化 - 摄像头实时预览(默认开启)+ 视觉识别状态条(后端 YOLO 推理) - 底部园区概览条(复用 ParkOverviewStrip),orb-wrap 视窗居中 - 页眉复用 ScreenLayout;左右键导航加入 /voice - 文档:docs/voice-integration-plan.md
38 lines
1.1 KiB
JavaScript
38 lines
1.1 KiB
JavaScript
// @ts-check
|
|
/** Small shared helpers used across the UI modules: a strict query selector,
|
|
* HTML escaping for text we drop into innerHTML, error-string trimming, and
|
|
* the opt-in debug flag. */
|
|
|
|
/** Opt-in tracing: `localStorage.setItem("s2s.debug", "1")` then reload. */
|
|
export const DEBUG = (() => {
|
|
try {
|
|
return localStorage.getItem("s2s.debug") === "1";
|
|
} catch {
|
|
return false;
|
|
}
|
|
})();
|
|
|
|
/**
|
|
* Query a single element, throwing if it's missing (so a broken selector fails
|
|
* loudly at startup rather than as a later null-deref).
|
|
* @template {HTMLElement} T
|
|
* @param {string} selector
|
|
* @returns {T}
|
|
*/
|
|
export function $(selector) {
|
|
const el = document.querySelector(selector);
|
|
if (!el) throw new Error(`Missing element: ${selector}`);
|
|
return /** @type {T} */ (el);
|
|
}
|
|
|
|
/** @param {string} s @returns {string} */
|
|
export function escHtml(s) {
|
|
return s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
}
|
|
|
|
/** Trim a long error message to fit the orb caption. @param {string} text */
|
|
export function truncateError(text) {
|
|
if (text.length <= 90) return text;
|
|
return text.slice(0, 87) + "…";
|
|
}
|