/** * Web Component 基类 * 提供 Shadow DOM 隔离 + 主题 CSS 变量注入 + i18n 绑定 * * 所有 UI 组件必须继承此类 */ /** * i18n 翻译函数类型 * 由外部注入,避免硬依赖 i18n 包的具体实现 */ export type TranslateFn = (key: string, params?: Record) => string; /** * 数字格式化函数类型 */ export type FormatNumberFn = (value: number, options?: Intl.NumberFormatOptions) => string; /** * 日期格式化函数类型 */ export type FormatDateFn = (value: Date | string | number, options?: Intl.DateTimeFormatOptions) => string; /** * 货币格式化函数类型 */ export type FormatCurrencyFn = (value: number, currency: string) => string; /** 注入全局 i18n 函数 */ export declare function setI18n(config: { t: TranslateFn; formatNumber?: FormatNumberFn; formatDate?: FormatDateFn; formatCurrency?: FormatCurrencyFn; }): void; /** * BaseComponent - 所有 UI 组件的抽象基类 * * 特性: * - Shadow DOM 隔离 * - 自动注入主题 CSS 变量 * - i18n t() 函数绑定 * - 响应式更新机制 */ export declare abstract class BaseComponent extends HTMLElement { protected shadow: ShadowRoot; protected _errorMessage: string | null; private _retryCallback; constructor(); /** 组件挂载时调用 */ connectedCallback(): void; /** 组件卸载时调用,子类可重写以清理资源 */ disconnectedCallback(): void; /** 属性变更时触发重渲染 */ attributeChangedCallback(_name: string, oldValue: string | null, newValue: string | null): void; /** 子类实现:返回 HTML 模板 */ protected abstract render(): string; /** 子类实现:返回组件专属样式 */ protected abstract styles(): string; /** i18n 翻译 */ protected t(key: string, params?: Record): string; /** 格式化数字 */ protected formatNumber(value: number, options?: Intl.NumberFormatOptions): string; /** 格式化日期 */ protected formatDate(value: Date | string | number, options?: Intl.DateTimeFormatOptions): string; /** 格式化货币 */ protected formatCurrency(value: number, currency: string): string; /** 设置错误状态并触发重渲染 */ setError(message: string, retryCallback?: () => void): void; /** 清除错误状态 */ clearError(): void; /** 渲染错误状态 UI */ protected renderError(): string; /** 错误状态样式 */ protected errorStyles(): string; /** 触发组件重渲染 */ update(): void; /** 绑定错误重试按钮事件 */ private bindErrorRetry; /** 渲染完成后的钩子,子类可重写以绑定事件 */ protected afterRender(): void; /** 在 Shadow DOM 内查询元素 */ protected query(selector: string): T | null; /** 在 Shadow DOM 内查询所有匹配元素 */ protected queryAll(selector: string): NodeListOf; /** 派发自定义事件(冒泡穿透 Shadow DOM) */ protected emit(eventName: string, detail?: T): void; /** HTML 实体转义,防止 XSS */ protected escapeHtml(str: string): string; } //# sourceMappingURL=BaseComponent.d.ts.map