Skip to content

Commit

Permalink
perf: show empty name
Browse files Browse the repository at this point in the history
  • Loading branch information
lisonge committed Jan 23, 2024
1 parent 85ea48e commit 6884103
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/utils/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,16 @@ export const getImageSize = async (src: string) => {
img.src = src;
});
};

const getSafeName = (node: RawNode) => {
const c = node.attr.childCount;
return (node.attr.name || `🐔` + (c > 1 ? `` : ` [${c}]`)).split('.').at(-1)!;
};
const labelKey = Symbol(`labelKey`);
export const getNodeLabel = (node: RawNode): string => {
if (Reflect.has(node, labelKey)) {
return Reflect.get(node, labelKey);
}
let label = node.attr.name?.split(`.`)?.at(-1) || ``;
let label = getSafeName(node);
const length = node.children.length;
if (length > 1) {
label = `${label} [${length}]`;
Expand All @@ -99,7 +102,7 @@ export const getNodeLabel = (node: RawNode): string => {
return label;
};
export const getLimitLabel = (node: RawNode, limit = 15): string => {
let label = node.attr.name?.split(`.`)?.at(-1) || ``;
let label = getSafeName(node);
const length = node.children.length;
if (length > 1) {
label = `${label} [${length}]`;
Expand Down

0 comments on commit 6884103

Please sign in to comment.