( nodes: ReadonlyArray<SceneNode>, settings: PluginSettings, )
| 631 | * @returns JSON representation of the nodes with parent references |
| 632 | */ |
| 633 | export const nodesToJSON = async ( |
| 634 | nodes: ReadonlyArray<SceneNode>, |
| 635 | settings: PluginSettings, |
| 636 | ): Promise<Node[]> => { |
| 637 | // Reset name counters for each conversion |
| 638 | nodeNameCounters.clear(); |
| 639 | const exportJsonStart = Date.now(); |
| 640 | // First get the JSON representation of nodes with rotation handling |
| 641 | const nodeResults = await Promise.all( |
| 642 | nodes.map(async (node) => { |
| 643 | // Export node to JSON |
| 644 | const nodeDoc = ( |
| 645 | (await node.exportAsync({ |
| 646 | format: "JSON_REST_V1", |
| 647 | })) as any |
| 648 | ).document; |
| 649 | |
| 650 | let nodeCumulativeRotation = 0; |
| 651 | |
| 652 | // Wire GROUPs into FRAME. |
| 653 | if (node.type === "GROUP") { |
| 654 | nodeDoc.type = "FRAME"; |
| 655 | |
| 656 | // Fix rotation for children. |
| 657 | if ("rotation" in nodeDoc && nodeDoc.rotation) { |
| 658 | nodeCumulativeRotation = -nodeDoc.rotation * (180 / Math.PI); |
| 659 | nodeDoc.rotation = 0; |
| 660 | } |
| 661 | } |
| 662 | |
| 663 | return { |
| 664 | nodeDoc, |
| 665 | nodeCumulativeRotation, |
| 666 | }; |
| 667 | }), |
| 668 | ); |
| 669 | |
| 670 | if (nodes.length > 0) { |
| 671 | console.log("[debug] initial node summary", { |
| 672 | id: nodes[0].id, |
| 673 | type: nodes[0].type, |
| 674 | name: nodes[0].name, |
| 675 | }); |
| 676 | } |
| 677 | |
| 678 | console.log( |
| 679 | `[benchmark][inside nodesToJSON] JSON_REST_V1 export: ${Date.now() - exportJsonStart}ms`, |
| 680 | ); |
| 681 | |
| 682 | // Now process each top-level node pair (JSON node + Figma node) |
| 683 | const processNodesStart = Date.now(); |
| 684 | const result: Node[] = []; |
| 685 | |
| 686 | for (let i = 0; i < nodes.length; i++) { |
| 687 | const processedNode = await processNodePair( |
| 688 | nodeResults[i].nodeDoc, |
| 689 | nodes[i], |
| 690 | settings, |
no test coverage detected