// Copyright 2024 The Lynx Authors. All rights reserved. // Licensed under the Apache License Version 2.0 that can be found in the // LICENSE file in the root directory of this source tree. declare const elementHandleKind: unique symbol; export interface ElementRef extends Record { readonly [elementHandleKind]?: 'element'; } export interface ElementTemplateHandle extends Record { readonly [elementHandleKind]: 'element-template'; } declare const composeElementRefBrand: unique symbol; export interface ComposeElementRef { readonly [composeElementRefBrand]: never; } /** A nonnegative, finite size in physical pixels. */ export interface CustomLayoutSize { width: number; height: number; } /** Content bounds in physical pixels. A maximum of -1 means unbounded. */ export type CustomLayoutMeasureCallback = ( minWidth: number, maxWidth: number, minHeight: number, maxHeight: number, ) => CustomLayoutSize; /** Return true to apply recorded placements, or false to cancel placement. */ export type CustomLayoutPlaceCallback = () => boolean; export enum ComposeElementKind { View = 1, Text = 2, Image = 3, Input = 8, Textarea = 9, } /** A detached text measurement in Lynx logical CSS pixels. */ export interface TextElementMeasurement { width: number; height: number; baseline: number; } export interface ComponentElementRef extends ElementRef { } export interface PageElementRef extends ComponentElementRef { } export interface ListElementRef extends ElementRef { } export interface ViewElementRef extends ElementRef { } export interface TextElementRef extends ElementRef { } export interface RawTextElementRef extends ElementRef { } export interface ImageElementRef extends ElementRef { } export interface ScrollElementRef extends ElementRef { } export interface WrapperElementRef extends ElementRef { } export interface NoneElementRef extends ElementRef { } export interface IfElementRef extends ElementRef { } export interface ForElementRef extends ElementRef { } export interface BlockElementRef extends ElementRef { } export interface StyleObjectRef extends ElementRef { } declare const styleSheetHandleKind: unique symbol; /** Opaque handle to a compiled stylesheet loaded by __LoadStyleSheet. */ export interface StyleSheetRef { readonly [styleSheetHandleKind]: 'stylesheet'; } export type ElementInfo = Record; export interface PipelineOptions { pipelineID: string needTimestamps: boolean } export interface SelectorParams { onlyCurrentComponent?: boolean; } export interface DynamicComponentResult { code: number; data: { evalResult: ( url: string ) => { name: string; }; }; } export type ComponentAtIndexCallback = ( listRef: ElementRef, listElementId: number, cellIndex: number, opId: number, enableReuseNotification?: boolean, enableBatchRender?: boolean, asyncFlush?: boolean, ) => number | undefined | Promise export type ComponentAtIndexesCallback = ( listRef: ElementRef, listElementId: number, cellIndexes: number[], opIds: number[], enableReuseNotification: boolean, asyncFlush: boolean, ) => void export type EnqueueComponentCallback = ( listRef: ElementRef, listId: number, eleId: number, ) => void /** * Animation operation types for ElementAnimate function */ export enum AnimationOperation { START = 0, // Start a new animation PLAY = 1, // Play/resume a paused animation PAUSE = 2, // Pause an existing animation CANCEL = 3, // Cancel an animation } /** * Animation timing options configuration */ export interface AnimationTimingOptions { name?: string; // Animation name (optional, auto-generated if not provided) duration?: number | string; // Animation duration delay?: number | string; // Animation delay iterationCount?: number | string; // Number of iterations (can be 'infinite') fillMode?: string; // Animation fill mode timingFunction?: string; // Animation timing function direction?: string; // Animation direction } /** * Keyframe definition for animation */ export type Keyframe = Record; export interface GestureConfig { callbacks: { name: string; callback: unknown; }[]; config?: Record; } export enum ElementEventClosureType { NONE = 0, JS = 1, CORE = 2, CLIENT = 3, } export enum ElementEventBindType { NONE = 0, BUBBLE = 1, CAPTURE = 2, CAPTURE_CATCH = 3, BUBBLE_CATCH = 4, GLOBAL_BIND = 5, } export enum ElementEventType { NONE = 0, TOUCH = 1, KEYBOARD = 2, WHEEL = 3, POINTER = 4, UI = 5, MOUSE = 6, MESSAGE = 7, CUSTOM = 8, } export interface ElementEventRef extends Record { } export interface ElementEvent extends Record { ref?: ElementEventRef; } export type ElementEventCallback = (event: ElementEvent) => void; export interface ElementEventListenerOptions { capture?: boolean; once?: boolean; passive?: boolean; signal?: boolean; closure_type?: ElementEventClosureType.NONE | ElementEventClosureType.CORE | ElementEventClosureType.CLIENT; bind_type?: ElementEventBindType; } export interface ElementEventOptions { capture?: boolean; bubbles?: boolean; cancelable?: boolean; composed?: boolean; } export type SerializableValue = any; export type SerializedTemplateInstance = | SerializedCompiledTemplateInstance | SerializedTypedTemplateInstance; export interface SerializedCompiledTemplateInstance { templateKey: string; bundleUrl?: string; attributeSlots?: SerializableValue[] | null; childSlots?: (SerializedTemplateInstance[] | null | undefined)[] | null; options?: Record | null; uid: number; } export interface SerializedTypedTemplateInstance { tag: string; attributes?: Record | null; childSlots?: (SerializedTemplateInstance[] | null | undefined)[] | null; options?: Record | null; uid: number; } declare global { /** Loads a compiled CSS section from an already loaded bundle. */ function __LoadStyleSheet(sectionName: string, bundleUrl: string): StyleSheetRef | undefined; /** Appends the stylesheet to the page's adopted stylesheets. */ function __AdoptStyleSheet(styleSheet: StyleSheetRef): void; /** * Removes every adoption of this handle from the current page, preserving * the order of other adopted stylesheets and the bundle's base styles. * Returns false for an invalid or unadopted handle. Handles remain reusable. * Existing elements are restyled on the next element-tree flush. * Loaded platform fonts retain their registration/cache lifecycle. */ function __RemoveStyleSheet(styleSheet: StyleSheetRef): boolean; /** * Replaces the page's complete adopted stylesheet set in array order. * Entries are loaded stylesheet handles or raw CSS text. All entries are * validated and CSS text is parsed before the current set is changed. * CSS text requires a base stylesheet with standard CSS selectors enabled; * otherwise the update returns false and preserves the current set. * An empty array clears adopted stylesheets; the bundle's base styles remain. * Returns false for invalid input or the same ordered handle set. * Existing elements are restyled on the next element-tree flush. * Handles remain reusable. Changed keyframe effects require the C++ animation * builder and retain playback time; unrelated effects remain unchanged. * Legacy platform animators may retain cached keyframes. Loaded platform fonts * are not unregistered or refreshed by stylesheet replacement. */ function __ReplaceStyleSheets(styleSheets: (StyleSheetRef | string)[]): boolean; function __CreatePage(componentId: string, cssId: number, info?: ElementInfo): PageElementRef; function __CreateComponent( parentComponentUniId: number, componentId: string, cssId: number, entryName: string, name: string, path: string, config?: Record, info?: ElementInfo, ): ComponentElementRef; function __CreateView(parentComponentUniId: number, info?: ElementInfo): ViewElementRef; function __CreateCompose( parentComponentUniId: number, kind: ComposeElementKind, ): ComposeElementRef; /** * Synchronously measures a detached Compose Text handle in layout-in-element mode. * Width, height, and returned metrics are in logical CSS pixels, not platform layout units. * Modes follow Starlight: 0 = indefinite, 1 = definite, 2 = at most. * Unsupported nodes, modes, or execution contexts return undefined. */ function __MeasureTextElement( current: ComposeElementRef, width: number, widthMode: 0 | 1 | 2, height: number, heightMode: 0 | 1 | 2, ): TextElementMeasurement | undefined; function __CreateScrollView(parentComponentUniId: number, info?: ElementInfo): ScrollElementRef; function __CreateText(parentComponentUniId: number, info?: ElementInfo): TextElementRef; function __CreateRawText(text: string, info?: ElementInfo): RawTextElementRef; function __CreateImage(parentComponentUniId: number, info?: ElementInfo): ImageElementRef; function __CreateWrapperElement(parentComponentUniId: number): WrapperElementRef; function __CreateNonElement(parentComponentUniId: number): ElementRef; function __CreateIf(parentComponentUniId: number, info?: ElementInfo): IfElementRef; function __CreateFor(parentComponentUniId: number, info?: ElementInfo): ForElementRef; function __CreateBlock(parentComponentUniId: number, info?: ElementInfo): BlockElementRef; function __CreateList( parentComponentUniId: number, componentAtIndex: ComponentAtIndexCallback, enqueueComponent: EnqueueComponentCallback, info?: ElementInfo, componentAtIndexes?: ComponentAtIndexesCallback, ): ListElementRef; function __UpdateListCallbacks( node: ListElementRef, componentAtIndex: ComponentAtIndexCallback, enqueueComponent: EnqueueComponentCallback, componentAtIndexes: ComponentAtIndexesCallback, ): void; function __CreateElement(tag: string, comParentUniID: number, info?: ElementInfo): ElementRef; function __AppendElement(parent: ElementRef, current: ElementRef): ElementRef; function __RemoveElement(parent: ElementRef, current: ElementRef): ElementRef; function __InsertElementBefore(parent: ElementRef, current: ElementRef, marker?: ElementRef): ElementRef; function __InsertElementAt( parent: ElementRef | ComposeElementRef, current: ElementRef | ComposeElementRef, index: number, ): void; function __RemoveElementsAt( parent: ElementRef | ComposeElementRef, index: number, count: number, ): void; function __MoveElements( parent: ElementRef | ComposeElementRef, from: number, to: number, count: number, ): void; function __SwapElement(left: ElementRef, right: ElementRef): void; function __ReplaceElement(newElement: ElementRef, oldElement: ElementRef): void; function __ReplaceElements(parent: ElementRef, insertedChildren: ElementRef | ElementRef[] | undefined, removedChildren: ElementRef | ElementRef[] | undefined): void; function __GetParent(current: ElementRef): ElementRef; function __GetChildren(current: ElementRef | ComposeElementRef): ElementRef[]; function __FirstElement(current: ElementRef): ElementRef; function __LastElement(current: ElementRef): ElementRef; function __NextElement(node: ElementRef): ElementRef; function __GetTag(node: ElementRef): string; function __SetAttribute( current: ElementRef | ComposeElementRef, attrName: string, value: any, ): void; function __AddClass(current: ElementRef, className: string): void; function __SetClasses(current: ElementRef, className: string | undefined): void; function __GetClasses(current: ElementRef): string[]; function __SetStaticStyle(node: ElementRef, key: number, value: unknown): void; function __SetInlineStyles(node: ElementRef, value: unknown): void; function __GetInlineStyle(node: ElementRef, propertyId: number): string; function __GetInlineStyles(node: ElementRef): string; function __SetID(node: ElementRef, id: string | null): void; function __GetID(node: ElementRef): string; function __SetCSSId(node: ElementRef | ElementRef[], cssId: number, entryName?: string): void; function __AddEvent(node: ElementRef, type: string, name: string, func: string | Object | undefined): void; function __SetEvents(node: ElementRef, events: Record[] | undefined): void; function __SetComposeModifier( owner: ComposeElementRef, modifier: object | null | undefined, ): void; /** * Installs synchronous measure and placement callbacks on a Compose view. * Requires LepusNG, layout-in-element and enableZIndex. Callback dimensions * and child positions use physical pixels. Clear both callbacks with null. */ function __SetCustomLayout( owner: ComposeElementRef, measure: CustomLayoutMeasureCallback, place: CustomLayoutPlaceCallback, ): void; function __SetCustomLayout( owner: ComposeElementRef, measure: null, place: null, ): void; /** * Measures a direct physical layout child during its owner's measure callback. * A Compose child resolves to its current mount root. Bounds use physical * pixels; minima must be nonnegative, and -1 means an unbounded maximum. */ function __MeasureElement( owner: ComposeElementRef, child: ElementRef | ComposeElementRef, minWidth: number, maxWidth: number, minHeight: number, maxHeight: number, ): CustomLayoutSize; /** * Records a measured child's position during its owner's placement callback. * Coordinates use physical pixels; zIndex must be finite. Equal zIndex values * follow placement call order. Geometry is applied after the callback returns. */ function __PlaceElement( owner: ComposeElementRef, child: ElementRef | ComposeElementRef, x: number, y: number, zIndex: number, ): void; /** * Invalidates an installed policy outside its measure and placement callbacks. * Flush the owning tree to schedule the next layout pass. */ function __InvalidateLayout(owner: ComposeElementRef): void; function __GetEvent(node: ElementRef, name: string, type: string): Record; function __GetEvents(node: ElementRef): Record>; function __AddEventListener( node: ElementRef, name: string, callback: ElementEventCallback | string, options: ElementEventListenerOptions, ): void; function __RemoveEventListener( node: ElementRef, name: string, callback: ElementEventCallback | string, options: ElementEventListenerOptions, ): void; function __RemoveEventListeners(node: ElementRef): void; function __CreateEvent( type: ElementEventType, name: string, options: ElementEventOptions, detail: Record, ): ElementEventRef; function __DispatchEvent(node: ElementRef, event: ElementEventRef): boolean; function __StopPropagation(event: ElementEventRef): void; function __StopImmediatePropagation(event: ElementEventRef): void; function __AddDataset(node: ElementRef, key: string, value: unknown): void; function __SetDataset(node: ElementRef, value: Record | undefined): void; function __GetDataset(node: ElementRef): Record; function __GetDataByKey(node: ElementRef, key: string): any; function __GetElementUniqueID(node: ElementRef): number; function __ElementIsEqual(left: ElementRef, right: ElementRef): boolean; function __UpdateComponentID(node: ElementRef, id: string): void; function __GetComponentID(node: ElementRef): string; function __UpdateComponentInfo( node: ElementRef, params: { componentID?: string; name?: string; path?: string; entry?: string; cssID?: number; config?: Record; } ): void; /** * Synchronously resolves mutations in an attached layout-in-element subtree. * Does not trigger layout, completion callbacks, or UI submission. The caller * must complete the enclosing pipeline. Pass prepareForLayout for content * changed during layout that needs native measurement preparation. */ function __ResolveElementSubtree( element: ElementRef|ComposeElementRef, prepareForLayout?: boolean): void; function __FlushElementTree( element?: ElementRef, options?: { triggerLayout?: boolean; triggerDataUpdated?: boolean; operationID?: number; nativeUpdateDataOrder?: number; __lynx_timing_flag?: string; elementID?: number; reloadTemplate?: boolean; listID?: number; pipelineOptions?: Record; elementIDs?: number[]; operationIDs?: number[]; asyncFlush?: boolean; onLayoutReady?: () => void; emptyPatch?: boolean; } ): void; function __AsyncResolveElement(element: ElementRef): void; function __AsyncResolveSubtree(node: ElementRef): void function __OnLifecycleEvent(args: any[]): void; function _ReportError( err: Error, info: { errorCode: number; } ): void; function __ElementFromBinary(elementTemplateKey: string, parentComponentUniId: number): ElementRef[]; /** * Create a template instance from the complete initial slot state. * `attributeSlots[i]` maps to `attrSlotIndex = i`. * `childSlots[i]` maps to `childSlotIndex = i`. */ function __CreateElementTemplate( templateKey: string, bundleUrl: string | null | undefined, attributeSlots: any[] | null | undefined, childSlots: Array | null | undefined, uid: number, options?: Record | null | undefined, ): ElementTemplateHandle; /** * Create a typed template instance. `childSlots[0]` is mounted as the root element's children. */ function __CreateTypedElementTemplate( tag: string, attributes: Record | null | undefined, childSlots: Array | null | undefined, uid: number, options?: Record | null | undefined, ): ElementTemplateHandle; /** * Synchronously materialize the template instance on demand and return the element targeted by an attribute slot. * Returns null if the slot is absent. Typed instances use slot 0 for their root. * This does not complete pending parent mounts or layout. */ function __GetElementByAttrSlot( templateInstance: ElementTemplateHandle, attributeSlotIndex: number ): ElementRef | null; /** * Update one dynamic attribute slot on an existing compiled template instance. * * For typed template instances, `attributeSlotIndex === 0` applies `value` as * the root spread attributes. Passing `null` or `undefined` clears the * previously applied root spread attributes. */ function __SetAttributeOfElementTemplate( templateInstance: ElementTemplateHandle, attributeSlotIndex: number, value: any, ): void; /** * Insert or move a child into one child slot. * If `referenceChild` is omitted or `null`, append to the slot tail. */ function __InsertNodeToElementTemplate( templateInstance: ElementTemplateHandle, childSlotIndex: number, child: ElementTemplateHandle, referenceChild?: ElementTemplateHandle | null, ): void; /** * Remove a child from one child slot. */ function __RemoveNodeFromElementTemplate( templateInstance: ElementTemplateHandle, childSlotIndex: number, child: ElementTemplateHandle, ): void; /** * Serialize a template instance into a machine-consumable structure used by * hydration and cross-thread transfer. */ function __SerializeElementTemplate( templateInstance: ElementTemplateHandle, ): SerializedTemplateInstance; function __GetTemplateParts(ele: ElementRef): Record; function __CloneElement(ele: ElementRef, options: Record): ElementRef; function __IsTemplateElement(ele: ElementRef): boolean; function __MarkTemplateElement(ele: ElementRef): void; function __MarkPartElement(ele: ElementRef, key: string): void; function __QuerySelector(root: ElementRef, cssSelector: string, params: SelectorParams): ElementRef; function __QuerySelectorAll(root: ElementRef, cssSelector: string, params: SelectorParams): ElementRef[]; function __AddConfig(ele: ElementRef, key: string, value: any): void; function __SetConfig(ele: ElementRef, config: Record): void; function __GetConfig(ele: ElementRef): Record; function __QueryComponent(source: string, callback?: (evalResult: DynamicComponentResult) => void): { evalResult: unknown }; function __AddInlineStyle(e: ElementRef, key: number | string, value: unknown): void; function __GetAttributeByName(e: ElementRef, name: string): any; function __GetAttributeNames(e: ElementRef): string[]; function __GetAttributes(e: ElementRef): Record; function __GetPageElement(): ElementRef; function __InvokeUIMethod(e: ElementRef, method: string, params: Record, callback: (res: { code: number; data: unknown }) => void): ElementRef[]; function __LoadLepusChunk(name: string, cfg: { chunkType: number }): void; function __CreateGestureDetector( node: ElementRef, gestureID: number, gestureType: number, config: GestureConfig, relationMap: Record ): void; function __SetGestureDetector( node: ElementRef, gestureID: number, gestureType: number, config: GestureConfig, relationMap: Record ): void; function __RemoveGestureDetector(node: ElementRef, gestureID: number): void; function __SetGestureState(node: ElementRef, gestureID: number, state: number): void; function __ConsumeGesture(node: ElementRef, gestureID: number, options: Record): void; function __GeneratePipelineOptions(): Record; function __OnPipelineStart(pipeLineId: string, pipeLineOrigin: string): void; function __BindPipelineIDWithTimingFlag(pipeLineId: string, timingFlag: string): void; function __MarkTiming(pipeLineId: string, timingFlag: string): void; function __AddTimingListener(): void; function __SetLepusInitData(initData: Object): void; function __GetElementByUniqueID(elementId: number): ElementRef | undefined; function __UpdateIfNodeIndex(node: IfElementRef, ifIndex: number): void; function __UpdateForChildCount(node: ForElementRef, childCount: number): void; function __CreateStyleObject(styleObject: Object): StyleObjectRef; function __SetStyleObject(elementRef: ElementRef, styleObjects: Array): void; function __UpdateStyleObject(styleObjectRef: StyleObjectRef, styleObject: Object): void; /** * ElementAnimate function - controls animations on DOM elements * @param element - The DOM element to animate (FiberElement reference) * @param args - Animation configuration array * @returns undefined */ function __ElementAnimate( element: ElementRef, args: [ operation: AnimationOperation, // Animation operation type name: string, // Animation name keyframes: Keyframe[], // Array of keyframes options?: AnimationTimingOptions, // Timing and configuration options ] | [ operation: AnimationOperation.PAUSE | AnimationOperation.PLAY | AnimationOperation.CANCEL, name: string, // Animation name to pause/play ], ): void; function __CreateFrame(comParentUniID: number, options?: Record): ElementRef; }