@rxflow/base
Version:
BaseFlow - 核心 Flow 组件库
96 lines (93 loc) • 2.24 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getNodeHeight = getNodeHeight;
exports.getNodeWidth = getNodeWidth;
/*
* @author: yanxianliang
* @date: 2025-05-17 22:24
* @desc: dimension 计算 utils
*
* Copyright (c) 2025 by yanxianliang, All Rights Reserved.
*/
/**
* 计算节点的宽度
* @param node
* @param nodeTypes
* @param theme
* @param nodeLookup
*/
function getNodeWidth(node, nodeTypes, theme, nodeLookup) {
// 优先级,lookup > node measured 配置>size>calc
if (nodeLookup && nodeLookup.has(node.id)) {
const lookup = nodeLookup.get(node.id);
if (typeof lookup?.measured?.width === 'number') {
return lookup?.measured?.width; // 实际的高度
}
}
const {
type,
measured,
width
} = node;
if (typeof measured?.width === 'number') {
return measured.width;
}
if (typeof width === 'number') {
return width;
}
if (!type || !nodeTypes?.[type] || !nodeTypes?.[type].defaultSize) {
return 1;
}
const ctr = nodeTypes[type];
const defaults = ctr.defaultSize;
if (defaults.width) {
if (typeof defaults.width === 'number') {
return defaults.width;
}
return defaults.width(node, theme);
} else {
return 1;
}
}
/**
* 计算节点的高度
* @param node
* @param nodeTypes
* @param theme
* @param nodeLookup
*/
function getNodeHeight(node, nodeTypes, theme, nodeLookup) {
// 优先级,lookup > node measured 配置>size>calc
if (nodeLookup && nodeLookup.has(node.id)) {
const lookup = nodeLookup.get(node.id);
if (typeof lookup?.measured?.height === 'number') {
return lookup?.measured?.height; // 实际的高度
}
}
const {
type,
measured,
height
} = node;
if (typeof measured?.height === 'number') {
return measured.height;
}
if (typeof height === 'number') {
return height;
}
if (!type || !nodeTypes?.[type] || !nodeTypes?.[type].defaultSize) {
return 1;
}
const ctr = nodeTypes[type];
const defaults = ctr?.defaultSize;
if (defaults.height) {
if (typeof defaults.height === 'number') {
return defaults.height;
}
return defaults.height(node, theme);
} else {
return 1;
}
}