2024-05-09 05:56:45 -05:00
|
|
|
import { registerChange } from './registerChange';
|
2024-05-07 05:18:15 -05:00
|
|
|
import { isGoogleFont } from './translators/text/font/gfonts';
|
|
|
|
import { isLocalFont } from './translators/text/font/local';
|
2024-05-03 06:43:07 -05:00
|
|
|
|
|
|
|
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)
|
|
|
|
});
|
|
|
|
|
2024-05-09 05:56:45 -05:00
|
|
|
figma.currentPage.once('nodechange', registerChange);
|
2024-05-03 06:43:07 -05:00
|
|
|
};
|