0
Fork 0
mirror of https://github.com/penpot/penpot-exporter-figma-plugin.git synced 2024-12-22 13:43:03 -05:00
penpot-exporter-figma-plugin/plugin-src/findAllTextnodes.ts
Alex Sánchez 8d5c5c15eb
Dynamic plugin size calculation, and cap the height to a safe value (#98)
* dynamic size

* fixes

* fixes

* fix dynamic size

* add changelog

---------

Co-authored-by: Jordi Sala Morales <jordism91@gmail.com>
2024-05-13 10:08:26 +02:00

32 lines
818 B
TypeScript

import { registerChange } from './registerChange';
import { isGoogleFont } from './translators/text/font/gfonts';
import { isLocalFont } from './translators/text/font/local';
export const findAllTextNodes = async () => {
await figma.loadAllPagesAsync();
const nodes = figma.root.findAllWithCriteria({
types: ['TEXT']
});
const fonts = new Set<string>();
nodes.forEach(node => {
const styledTextSegments = node.getStyledTextSegments(['fontName']);
styledTextSegments.forEach(segment => {
if (isGoogleFont(segment.fontName) || isLocalFont(segment.fontName)) {
return;
}
fonts.add(segment.fontName.family);
});
});
figma.ui.postMessage({
type: 'CUSTOM_FONTS',
data: Array.from(fonts)
});
figma.currentPage.once('nodechange', registerChange);
};