/** 节点布局信息,由 boundingClientRect 回调返回 */ export interface BoundingClientRectResult { /** 节点 id */ id: string; /** 节点 dataset */ dataset: Record; /** 左边界坐标 */ left: number; /** 右边界坐标 */ right: number; /** 上边界坐标 */ top: number; /** 下边界坐标 */ bottom: number; /** 节点宽度 */ width: number; /** 节点高度 */ height: number; } /** 节点滚动位置信息,由 scrollOffset 回调返回 */ export interface ScrollOffsetResult { /** 节点 id */ id: string; /** 节点 dataset */ dataset: Record; /** 横向滚动位置 */ scrollLeft: number; /** 纵向滚动位置 */ scrollTop: number; } /** SelectorQuery 查询链,支持 exec 执行 */ export interface SelectorQueryChain { /** 执行查询 */ exec(callback?: (results: unknown[]) => void): void; } /** 节点引用对象,通过 ty.createSelectorQuery().select() 获取 */ export interface NodesRef { /** 获取节点布局位置(left, right, top, bottom, width, height) */ boundingClientRect(callback?: (result: BoundingClientRectResult) => void): SelectorQueryChain; /** 获取节点滚动位置(scrollLeft, scrollTop) */ scrollOffset(callback?: (result: ScrollOffsetResult) => void): SelectorQueryChain; /** 获取节点指定字段信息 */ fields(fields: Record, callback?: (result: Record) => void): SelectorQueryChain; } /** 节点坐标信息 */ export interface Rect { /** 节点右边界坐标 */ right: number; /** 节点左边界坐标 */ left: number; /** 节点上边界坐标 */ top: number; /** 节点下边界坐标 */ bottom: number; /** 节点宽度 */ width: number; /** 节点高度 */ height: number; } /** * 获取节点的坐标信息 * * @public * @since @ray-js/ray 0.5.10 * @param ref - 通过 getElementById 获取的节点引用 * @returns 包含节点坐标和尺寸信息的 Rect 对象,节点不存在时返回 null * @example 基础用法 * ```tsx * import React, { useState } from 'react'; * import { View, Button, Text, getBoundingClientRect, getElementById } from '@ray-js/ray'; * * export default function Demo() { * const [info, setInfo] = useState(''); * * const handleGetRect = async () => { * const element = await getElementById('targetBox'); * if (element) { * const rect = await getBoundingClientRect(element); * if (rect) { * setInfo(`宽:${rect.width} 高:${rect.height} 左:${rect.left} 上:${rect.top}`); * } * } * }; * * return ( * * * 目标区域 * * * {info && {info}} * * ); * } * ``` */ export default function getBoundingClientRect(ref: NodesRef): Promise;