/** * MainThread element wrapper — provides a high-level API over raw PAPI * element handles for use in main-thread event handlers. * * When a MainThreadRef's `.current` is set, it receives one of these * wrappers so user code can call: * - setStyleProperties({ transform: '...' }) * - getComputedStyleProperty('width') * - animate(keyframes, options) * * These methods call Lynx PAPI directly on the main thread — no cross-thread * round-trip, enabling zero-latency UI updates. */ export interface AnimationKeyframe { [property: string]: string | number; } export interface AnimationOptions { duration?: number; delay?: number; iterations?: number; direction?: 'normal' | 'reverse' | 'alternate' | 'alternate-reverse'; easing?: string; fill?: 'none' | 'forwards' | 'backwards' | 'both'; name?: string; 'play-state'?: 'running' | 'paused'; } export interface Animation { play(): void; pause(): void; cancel(): void; } export declare class MTElementWrapper { /** The raw PAPI element handle. */ readonly _el: MainThreadElement; constructor(el: MainThreadElement); /** * Coalesce multiple element writes into a single `__FlushElementTree()` * call at the end of the current microtask. See `willFlush` doc for the * full rationale; mirrors `Element.flushElementTree` in upstream * `@lynx-js/react`. * * `__FlushElementTree` itself is wrapped by `animated-bridge-mt` to * apply pending `useAnimatedStyle` bindings before the native flush, so * the debounce automatically coalesces SV-binding application too. */ flushElementTree(): void; /** * Synchronously update inline styles on this element. * This bypasses the BG→MT op queue — styles are applied immediately * on the main thread, making it ideal for scroll-driven animations. * * The native `__FlushElementTree` call is microtask-debounced (see * `flushElementTree`), so chaining multiple writes within one tick * pays for a single flush instead of one per call. * * @example * ```ts * ref.current?.setStyleProperties({ * transform: `translateX(${offset}px)`, * opacity: `${1 - ratio}`, * }); * ``` */ setStyleProperties(styles: Record): void; /** * Get a computed style property value from this element. * * @param name - CSS property name in kebab-case (e.g. 'background-color') * @returns The computed value as a string */ getComputedStyleProperty(name: string): string; /** * Get a single attribute value by name. Returns the value as set via * `setAttribute` (or by a parent component); does not resolve aliases. */ getAttribute(name: string): unknown; /** * Get the list of attribute names currently set on this element. */ getAttributeNames(): string[]; /** * Find the first descendant element matching the CSS selector. * Mirrors `Element.prototype.querySelector` from the DOM. * * Returns `null` when no match is found OR when the host runtime does not * provide `__QuerySelector` (older Lynx SDKs). */ querySelector(selector: string): MTElementWrapper | null; /** * Find every descendant element matching the CSS selector. Returns an empty * array when nothing matches OR when the host runtime does not provide * `__QuerySelectorAll`. */ querySelectorAll(selector: string): MTElementWrapper[]; /** * Invoke a UI method exposed by the underlying native element (e.g. * `scrollIntoView` on ``, `scrollToIndex` on ``). * * Resolves with the method's `data` payload on success (`code === 0`); * rejects with an Error containing the JSON-stringified response otherwise. */ invoke(methodName: string, params?: Record): Promise; /** * Start a keyframe animation on this element using the Lynx animation API. * * @param keyframes - Array of keyframe objects * @param options - Animation configuration * @returns Animation controller with play/pause/cancel methods * * @example * ```ts * ref.current?.animate( * [{ opacity: 0 }, { opacity: 1 }], * { duration: 300, easing: 'ease-in-out' } * ); * ``` */ animate(keyframes: AnimationKeyframe[], options?: AnimationOptions): Animation | null; /** * Set a single attribute on this element. Microtask-debounced flush — * see `flushElementTree`. */ setAttribute(key: string, value: unknown): void; /** * Set a single inline style property. Microtask-debounced flush — see * `flushElementTree`. */ setStyleProperty(name: string, value: string | number): void; }