MCPcopy Create free account
hub / github.com/bernaferrari/FigmaToCode / countNodes

Function countNodes

packages/backend/src/code.ts:40–53  ·  view source on GitHub ↗
(nodes: ReadonlyArray<SceneNode>)

Source from the content-addressed store, hash-verified

38 const MAX_NODE_COUNT_PREVIEW = 1200;
39 const MAX_NODE_COUNT_HARD = 4000;
40 const countNodes = (nodes: ReadonlyArray<SceneNode>) => {
41 let count = 0;
42 const stack = [...nodes];
43 while (stack.length > 0) {
44 const node = stack.pop()!;
45 count += 1;
46 if ("children" in node && Array.isArray(node.children)) {
47 for (const child of node.children) {
48 stack.push(child);
49 }
50 }
51 }
52 return count;
53 };
54
55 const nodeCount = countNodes(selection);
56 if (nodeCount > MAX_NODE_COUNT_HARD) {

Callers 1

runFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected