mirror of
https://github.com/penpot/penpot-exporter-figma-plugin.git
synced 2024-12-22 21:53:27 -05:00
41 lines
904 B
TypeScript
41 lines
904 B
TypeScript
|
import { isGoogleFont } from './translators/text/gfonts';
|
||
|
import { isLocalFont } from './translators/text/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)
|
||
|
});
|
||
|
|
||
|
const maxHeight = 300;
|
||
|
|
||
|
if (fonts.size === 0) return;
|
||
|
|
||
|
if (fonts.size * 40 > maxHeight) {
|
||
|
figma.ui.resize(400, 300 + maxHeight);
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
figma.ui.resize(400, 300 + fonts.size * 40);
|
||
|
};
|