| 152 | } |
| 153 | |
| 154 | function traverse( |
| 155 | node: any, |
| 156 | visitor: (node: any, path: string, componentName: string) => string | undefined, |
| 157 | path: string = "", |
| 158 | ) { |
| 159 | if (!node || typeof node !== "object") { |
| 160 | return; |
| 161 | } |
| 162 | |
| 163 | const children = node.$$; |
| 164 | if (!Array.isArray(children)) { |
| 165 | return; |
| 166 | } |
| 167 | |
| 168 | const elementCounts = new Map<string, number>(); |
| 169 | |
| 170 | children.forEach((child: any) => { |
| 171 | const elementName = child["#name"]; |
| 172 | |
| 173 | if (!elementName || elementName.startsWith("__")) { |
| 174 | return; |
| 175 | } |
| 176 | |
| 177 | const currentIndex = elementCounts.get(elementName) || 0; |
| 178 | elementCounts.set(elementName, currentIndex + 1); |
| 179 | |
| 180 | const currentPath = path |
| 181 | ? `${path}/${elementName}/${currentIndex}` |
| 182 | : `${elementName}/${currentIndex}`; |
| 183 | |
| 184 | const result = visitor(child, currentPath, elementName); |
| 185 | |
| 186 | if (result !== "SKIP_CHILDREN") { |
| 187 | traverse(child, visitor, currentPath); |
| 188 | } |
| 189 | }); |
| 190 | } |
| 191 | |
| 192 | function getInnerHTML(node: any): string | null { |
| 193 | if (!node.$$ || !Array.isArray(node.$$)) { |