import * as lit from 'lit'; import { LitElement, nothing, PropertyDeclarations, PropertyValues, TemplateResult } from 'lit'; type WidgetMarketStatus = 'pending' | 'open' | 'suspended' | 'resulted' | 'settled' | 'voiding' | 'voided' | 'closed'; type WidgetMarketResult = 'win' | 'lose' | null; type WidgetEventPreset = 'featured' | 'volume' | 'latest' | 'ending'; type WidgetEventSortBy = 'sort_score' | 'created_at' | 'volume' | 'end_date'; type WidgetOddsFormat = 'european' | 'american' | 'asia'; type WidgetTheme = 'light' | 'dark' | 'system'; type EventCardVariant = 'standard' | 'compact' | 'hero'; interface WidgetMarket { id: string; outcome: string; outcomeId: string; status: WidgetMarketStatus; icon: string | null; image: string | null; startDate: string | null; endDate: string | null; result: WidgetMarketResult; sortOrder: number; odds: string | null; oddsUpdatedAtMs: string | null; tradable: boolean; } interface WidgetEvent { id: string; title: string; icon: string | null; image: string | null; description: string | null; startDate: string | null; endDate: string | null; volume: string | null; markets: WidgetMarket[]; } interface WidgetEventPage { items: WidgetEvent[]; nextCursor: string | null; snapshotAt: string; } interface WidgetConfig { siteName: string | null; siteIcon: string | null; defaultTheme: string; defaultLanguage: string; protocolVersion: number; } interface WidgetCategory { code: string; name: string; icon: string | null; isHot: boolean; } interface WidgetEventQuery { preset?: WidgetEventPreset; categoryCode?: string; tag?: string; keyword?: string; sortBy?: WidgetEventSortBy; cursor?: string; limit?: number; locale?: string; } type PredixWidgetErrorType = 'config' | 'auth' | 'http' | 'business' | 'network' | 'market_data'; interface PredixWidgetErrorOptions { type: PredixWidgetErrorType; code: number | string; message: string; retryable: boolean; correlationId?: string | null; cause?: unknown; } declare class PredixWidgetError extends Error { readonly type: PredixWidgetErrorType; readonly code: number | string; readonly retryable: boolean; readonly correlationId: string | null; readonly cause?: unknown; constructor(options: PredixWidgetErrorOptions); } interface WidgetToken { token: string; expiresIn: number; } type WidgetTokenProvider = () => Promise; interface PredixWidgetInitOptions { baseUrl: string; realtimeUrl?: string; tokenProvider: WidgetTokenProvider; theme?: WidgetTheme; locale?: string; timezone?: string; oddsFormat?: WidgetOddsFormat; fetch?: typeof globalThis.fetch; requestTimeoutMs?: number; cacheTtlMs?: number; sessionCache?: boolean; } interface PredixReadyDetail { sdkVersion: string; } interface PredixEventOpenRequestedDetail { eventId: string; outcomeId?: string; } interface PredixErrorDetail { error: PredixWidgetError; } interface PredixHostEventDetailMap { 'predix:ready': PredixReadyDetail; 'predix:event-open-requested': PredixEventOpenRequestedDetail; 'predix:error': PredixErrorDetail; } interface ApiEnvelope { code: number; message: string; data: T | null; detail?: unknown; } interface WidgetOddsUpdate { outcomeId: string; odds: string | null; updatedAtMs: string; source?: string; } interface TokenManagerOptions { tokenProvider: WidgetTokenProvider; document?: Document; onStateChange?: (stale: boolean) => void; onAuthChange?: () => void; onError?: (error: PredixWidgetError) => void; } declare class TokenManager { private token?; private expiresAt?; private refreshAt?; private refreshPromise?; private refreshTimer?; private fingerprintToken?; private fingerprintPromise?; private stale; private destroyed; private readonly tokenProvider; private readonly document?; private readonly onStateChange?; private readonly onAuthChange?; private readonly onError?; constructor(options: TokenManagerOptions); initialize(): Promise; getToken(): string; get isStale(): boolean; getValidToken(): Promise; getCredentialFingerprint(): Promise; refresh(force?: boolean): Promise; setToken(token: string): void; destroy(): void; private performRefresh; private shouldRefresh; private scheduleRefresh; private clearRefreshTimer; private clearFingerprint; private setStale; private assertActive; private readonly handleVisibilityChange; } interface WidgetClientOptions { baseUrl: string; tokenManager: TokenManager; fetch?: typeof globalThis.fetch; timeoutMs?: number; cacheTtlMs?: number; sessionCache?: boolean; sessionStorage?: Storage; } declare class WidgetClient { private readonly apiBaseUrl; private readonly tokenManager; private readonly fetchImpl; private readonly timeoutMs; private readonly cacheTtlMs; private readonly sessionCache?; private readonly cache; private readonly inFlight; private destroyed; constructor(options: WidgetClientOptions); getConfig(): Promise; getEvents(query?: WidgetEventQuery): Promise; getCategories(locale?: string): Promise; clearCache(): void; destroy(): void; private get; private resolveMemoryKey; private request; private fetchWithTimeout; private parseResponse; } type PredixClientOptions = WidgetClientOptions; type EventHandler = (payload?: unknown) => void; /** * SDK 内部事件总线,不向 Agent Host 暴露。 * * 预定义事件: * auth:changed — 宿主注入了新 Token * token:stale-changed — Token 刷新状态变化,payload: boolean * locale:changed — 运行时语言切换,payload: string * odds:updated — 实时赔率归并完成 */ declare class EventBus { private listeners; on(event: string, handler: EventHandler): void; off(event: string, handler: EventHandler): void; emit(event: string, payload?: unknown): void; clear(): void; } type RealtimeOddsHandler = (update: WidgetOddsUpdate) => void; interface RealtimeClientOptions { url?: string; getToken: () => Promise; WebSocketImpl?: typeof WebSocket; } declare class RealtimeClient { private readonly url?; private readonly getToken; private readonly WebSocketImpl?; private readonly topics; private readonly handlers; private readonly lastUpdatedAtMs; private socket?; private reconnectTimer?; private reconnectAttempt; private destroyed; private connected; constructor(options: RealtimeClientOptions); subscribe(outcomeIds: readonly string[], handler: RealtimeOddsHandler): () => void; reconnectWithToken(): Promise; destroy(): void; private connect; private handleMessage; private handleDisconnect; private sendSubscription; private send; private scheduleReconnect; private clearReconnectTimer; private closeSocket; } interface WidgetTokenState { stale: boolean; } interface WidgetDisplayOptions { locale: string; timezone: string; oddsFormat: WidgetOddsFormat; theme: WidgetTheme; } interface PredixContext { client: WidgetClient; config: WidgetConfig; display: WidgetDisplayOptions; token: WidgetTokenState; bus: EventBus; realtime: RealtimeClient; } type PredixInstallationState = 'initializing' | 'ready' | 'error' | 'destroyed'; interface PredixInstallPlacement { scope?: Document | ShadowRoot | HTMLElement; } type PredixInstallationListener = (state: PredixInstallationState, error?: PredixWidgetError) => void; interface PredixInstallation { readonly scope: Document | ShadowRoot | HTMLElement; readonly state: PredixInstallationState; readonly error?: PredixWidgetError; readonly ready: Promise; subscribe(listener: PredixInstallationListener): () => void; setLocale(locale: string): void; setTheme(theme: WidgetTheme): void; setToken(token: string): void; retry(): void; destroy(): void; } declare class PredixWidget { readonly client: WidgetClient; readonly config: PredixContext['config']; readonly display: WidgetDisplayOptions; private readonly tokenManager; private readonly realtimeClient; private readonly bus; private readonly roots; private readonly context; private systemThemeMedia?; private destroyed; static install(options: PredixWidgetInitOptions, placement?: PredixInstallPlacement): PredixInstallation; private constructor(); static init(options: PredixWidgetInitOptions): Promise; connect(root: EventTarget): () => void; setToken(token: string): void; setLocale(locale: string): void; setTheme(theme: WidgetTheme): void; destroy(): void; private disconnect; private applyTheme; private syncSystemThemeListener; private readonly handleSystemThemeChange; private handleAuthChange; private emitError; private readonly handleContextRequest; private assertActive; } declare abstract class PredixElement extends LitElement { private sharedContext?; private contextReady; get context(): PredixContext | undefined; set context(value: PredixContext | undefined); connectedCallback(): void; disconnectedCallback(): void; protected onContextReady(): void; protected onContextReleased(): void; protected emitHostEvent(name: Name, detail: PredixHostEventDetailMap[Name]): void; protected reportError(error: unknown): PredixWidgetError; private initializeContext; private releaseContext; private readonly requestContext; private readonly handleContextAvailable; private readonly handleContextCleared; } declare const PREDIX_EVENT_CARD_TAG = "predix-event-card"; declare class PredixEventCard extends PredixElement { static properties: { event: { attribute: boolean; }; variant: { type: StringConstructor; reflect: boolean; }; locale: { type: StringConstructor; }; timezone: { type: StringConstructor; }; oddsFormat: { type: StringConstructor; attribute: string; }; endsLabel: { state: boolean; }; narrow: { type: BooleanConstructor; state: boolean; }; }; static styles: lit.CSSResult[]; event?: WidgetEvent; variant: EventCardVariant; locale: string; timezone: string; oddsFormat: string; private endsLabel; private narrow; private endsTimerId?; private endsSwitchTimerId?; private mobileViewportQuery?; connectedCallback(): void; protected onContextReady(): void; protected onContextReleased(): void; disconnectedCallback(): void; protected updated(changed: Map): void; render(): typeof nothing | lit.TemplateResult<1>; private get effectiveLocale(); private renderThumb; private renderMarket; private bindMobileViewportListener; private unbindMobileViewportListener; private readonly handleMobileViewportChange; private syncNarrowFromViewport; private syncLayoutAttribute; private readonly openEvent; private readonly handleShowMore; private readonly handleCardKeydown; private openOutcome; private syncLocationParams; private formatOdds; private refreshEndsLabelSchedule; private updateEndsLabel; private getEndMs; private clearEndsTimers; private readonly handleTokenStateChange; } declare function defineEventCard(): void; declare abstract class PredixEventCollection extends PredixElement { static properties: PropertyDeclarations; preset?: WidgetEventPreset; category: string; tag: string; limit: number; cardVariant: EventCardVariant; locale: string; timezone: string; oddsFormat: string; protected loading: boolean; protected events: WidgetEvent[]; protected error?: PredixWidgetError; private requestId; private readyEmitted; private skipNextQueryUpdate; private unsubscribeRealtime?; protected onContextReady(): void; protected onContextReleased(): void; protected willUpdate(changedProperties: PropertyValues): void; protected updated(_changedProperties: PropertyValues): void; render(): TemplateResult; reload(): void; protected abstract renderEvents(): TemplateResult; protected onEventsWillChange(): void; protected get effectiveLocale(): string; protected get effectiveTimezone(): string; protected get effectiveOddsFormat(): string; private get normalizedLimit(); private createQuery; private load; private subscribeRealtime; private readonly handleOddsUpdate; private emitReadyOnce; private readonly retry; private readonly handleRefresh; private readonly handleLocaleChanged; } declare const PREDIX_EVENT_CAROUSEL_TAG = "predix-event-carousel"; declare class PredixEventCarousel extends PredixEventCollection { static properties: { autoplay: { type: BooleanConstructor; }; autoplayIntervalMs: { type: NumberConstructor; attribute: string; }; carouselStepItems: { type: NumberConstructor; attribute: string; }; cardWidth: { attribute: string; }; }; static styles: lit.CSSResult[]; autoplay: boolean; autoplayIntervalMs: number; carouselStepItems: number; cardWidth: number | string; private autoplayTimer?; private manualPauseTimer?; private carouselTransitionTimer?; private carouselIndex; private carouselStep; private carouselDragOffset; private carouselWheelAccum; private carouselInitialized; private carouselOverflowing; private carouselShouldAnimate; private carouselTransitioning; private carouselPointerId?; private carouselPointerStartX; private carouselDragging; private resizeObserver?; private observedViewport?; private wheelViewport?; private blockedClickTarget?; private blockedClickHandler?; private blockedClickCleanupTimer?; disconnectedCallback(): void; protected onContextReleased(): void; protected updated(changedProperties: PropertyValues): void; private syncLayoutProperties; protected renderEvents(): TemplateResult; private renderEventItem; private get carouselEnabled(); private get normalizedCarouselStepItems(); /** Configured page size, or 1 when the viewport only fits ~one card. */ private get effectiveCarouselStepItems(); private get carouselMiddleCopyIndex(); private get carouselTrackRepeatCount(); private get carouselCenterStartIndex(); protected onEventsWillChange(): void; private readonly handleCarouselKeydown; private get isRtl(); private stepCarousel; private resetCarouselPosition; private syncCarousel; private refreshCarouselMetrics; private applyCarouselTransform; private readonly handleCarouselTransitionEnd; private readonly finishCarouselStep; private bindCarouselResize; private readonly handleCarouselWheel; private consumeWheelDelta; private pauseAutoplayTemporarily; private readonly handleCarouselPointerDown; private readonly handleCarouselPointerMove; private readonly handleCarouselPointerUp; private blockNextClick; private clearBlockedClick; private readonly handleCarouselFocusOut; private readonly startAutoplay; private readonly stopAutoplay; private clearManualPauseTimer; private teardownCarousel; private teardownCarouselObserver; } declare function defineEventCarousel(): void; declare const PREDIX_EVENT_LIST_TAG = "predix-event-list"; declare class PredixEventList extends PredixEventCollection { static properties: { gridColumns: { type: NumberConstructor; attribute: string; }; }; static styles: lit.CSSResult[]; gridColumns: number; protected updated(changedProperties: PropertyValues): void; protected renderEvents(): TemplateResult; private syncGridColumns; } declare function defineEventList(): void; declare const PREDIX_WIDGET_TAG = "predix-widget"; interface PredixWidgetProviderEventMap { ready: PredixReadyDetail; open: PredixEventOpenRequestedDetail; error: PredixErrorDetail; } declare class PredixWidgetProvider extends LitElement { static properties: { options: { attribute: boolean; }; baseUrl: { type: StringConstructor; attribute: string; }; realtimeUrl: { type: StringConstructor; attribute: string; }; tokenProvider: { attribute: boolean; }; theme: { type: StringConstructor; }; locale: { type: StringConstructor; }; timezone: { type: StringConstructor; }; oddsFormat: { type: StringConstructor; attribute: string; }; }; static styles: lit.CSSResult; options?: PredixWidgetInitOptions; baseUrl: string; realtimeUrl: string; tokenProvider?: WidgetTokenProvider; theme?: WidgetTheme; locale: string; timezone: string; oddsFormat?: WidgetOddsFormat; installationState: PredixInstallationState | 'idle'; installation?: PredixInstallation; private unsubscribeInstallation?; connectedCallback(): void; disconnectedCallback(): void; protected updated(changedProperties: PropertyValues): void; retry(): void; destroy(): void; render(): lit.TemplateResult<1>; private restartInstallation; private resolveOptions; private disposeInstallation; private setInstallationState; private emitPredixError; private isNearestProvider; private readonly handleReady; private readonly handleOpen; private readonly handleError; private dispatchAlias; } interface PredixWidgetProvider { addEventListener(type: Type, listener: (this: PredixWidgetProvider, event: CustomEvent) => unknown, options?: boolean | AddEventListenerOptions): void; addEventListener(type: Type, listener: (this: HTMLElement, event: HTMLElementEventMap[Type]) => unknown, options?: boolean | AddEventListenerOptions): void; addEventListener(type: string, listener: EventListenerOrEventListenerObject | null, options?: boolean | AddEventListenerOptions): void; removeEventListener(type: Type, listener: (this: PredixWidgetProvider, event: CustomEvent) => unknown, options?: boolean | EventListenerOptions): void; removeEventListener(type: Type, listener: (this: HTMLElement, event: HTMLElementEventMap[Type]) => unknown, options?: boolean | EventListenerOptions): void; removeEventListener(type: string, listener: EventListenerOrEventListenerObject | null, options?: boolean | EventListenerOptions): void; } declare function defineWidgetProvider(): void; type PredixBooleanAttribute = boolean | ''; type PredixNumberAttribute = number | `${number}`; interface PredixDisplayAttributes { locale?: string; timezone?: string; 'odds-format'?: WidgetOddsFormat; } interface PredixEventListAttributes extends PredixDisplayAttributes { preset?: WidgetEventPreset; category?: string; tag?: string; limit?: PredixNumberAttribute; 'card-variant'?: EventCardVariant; 'grid-columns'?: PredixNumberAttribute; } interface PredixEventCarouselAttributes extends PredixDisplayAttributes { preset?: WidgetEventPreset; category?: string; tag?: string; limit?: PredixNumberAttribute; 'card-variant'?: EventCardVariant; autoplay?: PredixBooleanAttribute; 'autoplay-interval-ms'?: PredixNumberAttribute; 'carousel-step-items'?: PredixNumberAttribute; 'card-width'?: number | string; } interface PredixEventCardAttributes extends PredixDisplayAttributes { event?: WidgetEvent; variant?: EventCardVariant; } interface PredixWidgetProviderAttributes extends PredixDisplayAttributes { options?: PredixWidgetInitOptions; 'base-url'?: string; 'realtime-url'?: string; tokenProvider?: WidgetTokenProvider; theme?: WidgetTheme; } declare global { interface HTMLElementTagNameMap { 'predix-event-list': PredixEventList; 'predix-event-carousel': PredixEventCarousel; 'predix-event-card': PredixEventCard; 'predix-widget': PredixWidgetProvider; } interface HTMLElementEventMap { 'predix:ready': CustomEvent; 'predix:event-open-requested': CustomEvent; 'predix:error': CustomEvent; } } export { type ApiEnvelope as A, type PredixWidgetErrorType as B, type PredixWidgetProviderEventMap as C, type TokenManagerOptions as D, type EventCardVariant as E, type WidgetCategory as F, type WidgetClientOptions as G, type WidgetConfig as H, type WidgetEventPage as I, type WidgetEventPreset as J, type WidgetEventQuery as K, type WidgetEventSortBy as L, type WidgetMarketResult as M, type WidgetMarketStatus as N, type WidgetOddsUpdate as O, PredixEventList as P, type WidgetTheme as Q, type WidgetToken as R, type WidgetTokenProvider as S, TokenManager as T, defineEventCard as U, defineEventCarousel as V, type WidgetOddsFormat as W, defineEventList as X, defineWidgetProvider as Y, type PredixEventListAttributes as a, PredixEventCarousel as b, type PredixEventCarouselAttributes as c, PredixEventCard as d, type PredixEventCardAttributes as e, PredixWidgetProvider as f, type PredixWidgetProviderAttributes as g, type PredixReadyDetail as h, type PredixEventOpenRequestedDetail as i, type PredixErrorDetail as j, type PredixWidgetInitOptions as k, type WidgetEvent as l, type WidgetMarket as m, PREDIX_EVENT_CARD_TAG as n, PREDIX_EVENT_CAROUSEL_TAG as o, PREDIX_EVENT_LIST_TAG as p, PREDIX_WIDGET_TAG as q, type PredixBooleanAttribute as r, WidgetClient as s, type PredixClientOptions as t, type PredixDisplayAttributes as u, type PredixHostEventDetailMap as v, type PredixNumberAttribute as w, PredixWidget as x, PredixWidgetError as y, type PredixWidgetErrorOptions as z };