mirror of
https://github.com/penpot/penpot-exporter-figma-plugin.git
synced 2024-12-22 21:53:27 -05:00
3ee244db92
* add figma-create-plugin ui * first attempt * more changes * update packages * fix stuff * implement reload action * simplify code * create wrapper * fix logo * adjust sizes * add changelog * update design again * temporary fix --------- Co-authored-by: Alex Sánchez <sion333@gmail.com>
43 lines
1.1 KiB
TypeScript
43 lines
1.1 KiB
TypeScript
import {
|
|
BASE_WIDTH,
|
|
MISSING_FONTS_TEXT_HEIGHT,
|
|
MISSING_SINGLE_FONT_HEIGHT,
|
|
NORMAL_HEIGHT
|
|
} from './pluginSizes';
|
|
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)
|
|
});
|
|
|
|
const newHeight =
|
|
NORMAL_HEIGHT +
|
|
(fonts.size > 0 ? MISSING_FONTS_TEXT_HEIGHT + fonts.size * MISSING_SINGLE_FONT_HEIGHT : 0);
|
|
|
|
figma.ui.resize(BASE_WIDTH, newHeight);
|
|
figma.currentPage.once('nodechange', registerChange);
|
|
};
|