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 b85a4f7279
Autolayout (#151)
* wip

* added layout sizing

* layout positioning

* fixes

* fixes

* fixes

* fixes

* fixes

* fixes
2024-06-14 10:18:34 +02:00

40 lines
1,016 B
TypeScript

import { isGoogleFont } from '@plugin/translators/text/font/gfonts';
import { isLocalFont } from '@plugin/translators/text/font/local';
import { sleep } from '@plugin/utils';
import { registerChange } from './registerChange';
export const findAllTextNodes = async () => {
const fonts = new Set<string>();
for (const page of figma.root.children) {
await page.loadAsync();
for (const node of page.children) {
if (node.type === 'TEXT') {
extractMissingFonts(node, fonts);
}
await sleep(0);
}
}
figma.ui.postMessage({
type: 'CUSTOM_FONTS',
data: Array.from(fonts)
});
figma.currentPage.once('nodechange', registerChange);
};
const extractMissingFonts = (node: TextNode, fonts: Set<string>) => {
const styledTextSegments = node.getStyledTextSegments(['fontName']);
styledTextSegments.forEach(segment => {
if (isGoogleFont(segment.fontName) || isLocalFont(segment.fontName)) {
return;
}
fonts.add(segment.fontName.family);
});
};