import { LayoutEdge, type LayoutNode } from './layout/node.js' /** * 返回 yoga 节点的内容宽度(计算宽度减去内边距和边框)。 * * 警告:可能返回比父容器更宽的值。 * 在列方向 flex 父级中,width 是横轴 —— align-items: * stretch 从不将子元素收缩到其内在大小以下,所以文本 * 节点溢出(标准 CSS 行为)。Yoga 以两次 pass 测量叶节点: * AtMost pass 确定宽度,Exactly pass 确定高度。 * getComputedWidth() 反映更宽的 AtMost 结果,而 * getComputedHeight() 反映更窄的 Exactly 结果。 * 使用此函数进行换行的调用者应限制为实际可用的屏幕空间, * 以便渲染的行数与布局高度保持一致。 */ const getMaxWidth = (yogaNode: LayoutNode): number => { return ( yogaNode.getComputedWidth() - yogaNode.getComputedPadding(LayoutEdge.Left) - yogaNode.getComputedPadding(LayoutEdge.Right) - yogaNode.getComputedBorder(LayoutEdge.Left) - yogaNode.getComputedBorder(LayoutEdge.Right) ) } export default getMaxWidth