How to get the text styles from our local library

Hi All,

I’m trying to build a lorem ipsum plugin to be used within my organization. For this I’d like my users to be able to select the text-styles the design system provides in the token library. I could redefine them all in my plugin but this seems like a waste of resources (also no fun when the library itself changes and my plugin does not).

Is there a way to retrieve the tokens text styles programmatically? I can’t seem to find it in the API docs.

Thanks in advance!

Use figma.getLocalTextStyles() (figma | Plugin API) to get the styles in the library file, then save them to client storage, then retrieve these styles in any other file using figma.importStyleByKeyAsync() figma | Plugin API

Thanks for your responce @Gleb - I did see the getLocalTextStyles in the docs - when I run this in a file I’d like to place some lorem ipsum I’m getting an empty array back. Just checked in the file where we define the text style (component), here I do get all the proper information back.

I found the importStyleByKeyAsync call in the docs, now I am able to retrieve them one by one, which seems a hassle as I have to create a list of keys and use those (and also - if we introduce a new text style this won’t show up untill I update the plugin, becoming a single point of failure :-))

Or you can ask the user to update the library manually if you save the keys to the clientstorage instead of hardcoding them into the plugin code.

this is the only way

To exclude publishing plugin updates from this path, then you can create a file that lists all the style keys, host it on the web, and then make a network request to it. That is, you will only have to modify the file with the listed keys.