Skip to main content
Glama

figma-mcp

clean_node.cpython-313.pyc8.18 kB
� l��g�$��P�SSKrSSKrSrSrSrSrSrSrSrS r S r S r g) �Nc��[USS-5n[USS-5n[USS-5nSUSUSUS3$)zO Convert an RGBA dict into a #RRGGBB hex string (ignoring alpha in this demo). �r���g�b�#�02x)�int)�rgbarrrs �J/Users/jasonzhou/Documents/GitHub/figma-mcp-python/figma_mcp/clean_node.py� rgba_to_hexr sU�� �D��I��O��A� �D��I��O��A� �D��I��O��A� �q��g�a��W�Q�s�G� $�$�c��[R"USS9n[R"UR 55R 5$)z> Create a hash from style data to use as a unique identifier. T)� sort_keys)�json�dumps�hashlib�md5�encode� hexdigest)� style_data� style_strs r � style_hashr s5��� � �:��6�I� �;�;�y�'�'�)� *� 4� 4� 6�6rc�4�SSSSS.nURUS5$)z4 Convert Figma alignment values to CSS flex values. z flex-start�centerzflex-endz space-between)�MIN�CENTER�MAX� SPACE_BETWEEN)�get)� figma_val� align_maps r �figma_align_to_flexr#s*�� ���(� �I� �=�=��L� 1�1rc���U(a([U5S:XdUSRSS5S:XagUSnUSS:Xa;USnURS S 5n[U5US .n[U5nXa;aXQU'U$g) z< Process fill styles and add them to the styles dictionary. r�visibleTFN�type�SOLID�color�opacity�)�backgroundColorr))�lenr r r)�fills�styles�fillr(r)r�style_ids r �get_fill_style_idr1 s��� �C��J�!�O�u�Q�x�|�|�I�t�'D��'M�� ��8�D� �F�|�w���W� ���(�(�9�a�(�� +�5�1�� � � �j�)�� � !�)�8� ��� rc�^^ �0nSU;a�USm T S:Xa SUS'SUS'OT S:Xa SUS'SUS'S U;a US S 3US 'S U;a US S 3US 'S U;a US S 3US 'S U;a US S 3US 'SU;a USS 3US'SU;a9USnURSS5nU 4SjnU 4SjnU"U5US'U"U5US'SU;aUSnUSS 3US'USS 3US'[U5nU(aX�S'[U5n U (aX�S'U(a[U5n X�;aX!U 'U $g)z> Process layout styles and add them to the styles dictionary. � layoutMode� HORIZONTAL�flex�display�row� flexDirection�VERTICAL�column� paddingLeft�px� paddingRight� paddingTop� paddingBottom� itemSpacing�gap�primaryAxisAlignItems�counterAxisAlignItemsrc�<>�TS:Xa [U5$[U5$�Nr4�r#��val� layout_modes �r �align_map_primary�.get_layout_style_id.<locals>.align_map_primaryb�!����,�.�.�s�3�3�*�3�/�/rc�<>�TS:Xa [U5$[U5$rErFrGs �r �align_map_counter�.get_layout_style_id.<locals>.align_map_countergrLr�justifyContent� alignItems�absoluteBoundingBox�width�height� borderRadiusN)r �get_border_radius�get_corner_smoothingr) �raw_noder.� layout_style� primary_align� counter_alignrJrN�bbox� border_radius�corner_smoothingr0rIs @r �get_layout_style_idr_>s�����L��x���|�,� � �,� &�&,�L�� #�,1�L�� )� �J� &�&,�L�� #�,4�L�� )� �H� $�-5�m�-D�,E�R�*H�L�� '� �X� %�.6�~�.F�-G�r�+J�L�� (� �8� #�,4�\�,B�+C�2�)F�L�� &� �h� &�/7��/H�.I��,L�L�� )� �H� $�%-�m�%<�$=�R�"@�L�� � #�h� .�$�%<�=�M�$�L�L�)@�%�H�M� 0�  0� .?�}�-M�L�)� *�):�=�)I�L�� &���(��-�.��#'��=�/�� 4� �W��$(��N�#3�2�!6� �X��&�h�/�M��'4�^�$�,�H�5���'7�^�$���l�+�� � !�+�8� ��� rc� �SU;aUSS3$g)z$ Extract border radius from a node. � cornerRadiusr<N��rXs r rVrV�s"����!��>�*�+�2�.�.� rc�2�SU;aUSS:�aUSS3$g)z' Extract corner smoothing from a node. �cornerSmoothingrr<Nrbrcs r rWrW�s0���H�$��2C�)D�q�)H��,�-�.�b�1�1� rc��USS:wdSU;ag0nUSnSU;aUSUS'SU;aUSUS'SU;a USS3US'S U;a US S3US 'S U;a US S3US 'S U;aS SSSS.nURUS S 5US'SU;a,US(a"USSnUSS:Xa[US5US'U(a[U5nXa;aX!U'U$g)z< Process text styles and add them to the styles dictionary. r&�TEXT�styleN� fontFamily� fontWeight�fontSizer<� lineHeightPx� lineHeight� letterSpacing�textAlignHorizontal�leftr�right�justify)�LEFTr�RIGHT� JUSTIFIED� textAlignr-rr'r()r r r)rXr.� text_style� node_styler"r/r0s r �get_text_style_idry�sP�����6�!�W�H�%<���J��'�"�J��z�!�#-�l�#;� �<� ��z�!�#-�l�#;� �<� ��Z��$.�z�$:�#;�2�!>� �:����#�&0��&@�%A��#D� �<� ��*�$�)3�O�)D�(E�R�&H� �?�#�� �*�#�x�'�Xa�b� �"+�-�-� �;P�0Q�SY�"Z� �;���(��x��0��� ��#�� ��<�7� "�"-�d�7�m�"<�J�w� ���j�)�� � !�)�8� ��� rc���USnUSUSUURSS5S.n[URS/5U5nU(aXCS'[X5nU(aXSS '[X5nU(aXcS 'US :XaS U;aUS US 'US :Xa:SU;a4URS/5HnUSS:XdMSU;dMUSUS'M SU;aH/US'USH:nURSS5S:XaM[ X�5n USR U 5 M< SU;aUSUS'SU;aUSUS'SU;aUSUS'SU;aUSUS'SU;aUSUS'SU;aUSUS'U$)z5 Transform a Figma node into a simplified structure. r&�id�namer%T)r{r|r&r%r-� fillStyleId� layoutStyleId� textStyleIdrg� characters� RECTANGLE�IMAGE�imageRef�childrenF�componentPropertyReferences�componentProperties�componentPropertyDefinitions�variantProperties�componentSetId� componentId)r r1r_ry�transform_node�append) rXr.� node_type�node� fill_style_id�layout_style_id� text_style_idr/�child�transformed_childs r r�r��s����� �I��t�n��� ���<�<� �4�0�  �D�&�h�l�l�7�B�&?��H�M��+�]��)�(�;�O�� /�_��%�h�7�M��+�]���F��|�x�7�%�l�3��\���K��G�x�$7��L�L��"�-�D��F�|�w�&�:��+=�#'� �#3��Z� �.� �X����Z���j�)�E��y�y��D�)�U�2�� .�u� =� � �� � #� #�$5� 6� *�%��0�.6�7T�.U�� *�+���(�&.�/D�&E�� "�#�&��1�/7�8V�/W�� +�,��h�&�$,�-@�$A�� �!��8�#�!)�*:�!;�� ���� �&�}�5��]�� �Krc�|�0n[U[5(aSU;a[USU5nO [X5nUUS.$)z8 Transform Figma JSON data into a simplified structure. �document)r�r.)� isinstance�dictr�)�raw_datar.r�s r �transform_figma_jsonr�sL�� �F��(�D�!�!�j�H�&<�!�(�:�"6��?��!�(�3���� �r) rrr rr#r1r_rVrWryr�r�rbrr �<module>r�sB�� ��%�7� 2��<K�Z��)�VH�Tr

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/JayZeeDesign/figma-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server