MCPcopy Create free account
hub / github.com/ecomfe/tempad-dev / getChildren

Function getChildren

packages/extension/utils/component.ts:90–164  ·  view source on GitHub ↗
(node: SceneNode)

Source from the content-addressed store, hash-verified

88}
89
90function getChildren(node: SceneNode): DesignNode[] | null {
91 if (!('children' in node)) {
92 return null
93 }
94
95 const result: DesignNode[] = []
96 for (const child of node.children) {
97 const { visible } = child
98 switch (child.type) {
99 case 'INSTANCE': {
100 const component = getDesignComponent(child)
101 if (component) {
102 result.push(component)
103 }
104 break
105 }
106 case 'TEXT': {
107 result.push({
108 name: child.name,
109 type: 'TEXT',
110 visible,
111 characters: child.characters
112 })
113 break
114 }
115 case 'FRAME':
116 case 'GROUP': {
117 result.push({
118 name: child.name,
119 type: child.type,
120 visible,
121 children: getChildren(child) ?? []
122 })
123 break
124 }
125 case 'VECTOR': {
126 type FillArray = Exclude<typeof child.fills, symbol>
127 if (!Array.isArray(child.fills)) {
128 break
129 }
130 const fills: Fill[] = []
131 ;(child.fills as FillArray).forEach((fill) => {
132 if (fill.type !== 'SOLID') {
133 return
134 }
135
136 const { color: rgb, boundVariables } = fill
137 const hex = rgbToHex(rgb)
138 let color: string | Variable
139
140 if (figma && boundVariables?.color) {
141 const variable = figma.variables.getVariableById(boundVariables.color.id)
142 color = variable ? { name: variable.name, value: hex } : hex
143 } else {
144 color = hex
145 }
146
147 fills.push({ color })

Callers 1

getDesignComponentFunction · 0.85

Calls 2

rgbToHexFunction · 0.90
getDesignComponentFunction · 0.85

Tested by

no test coverage detected