2024-06-26 01:11:57 -05:00
|
|
|
import { toArray } from '@common/map';
|
|
|
|
import { sleep } from '@common/sleep';
|
2024-06-25 09:08:59 -05:00
|
|
|
|
|
|
|
import { sendMessage } from '@ui/context';
|
|
|
|
import { PenpotFile } from '@ui/lib/types/penpotFile';
|
2024-06-26 01:11:57 -05:00
|
|
|
import { typographies } from '@ui/parser';
|
2024-06-25 09:08:59 -05:00
|
|
|
|
|
|
|
export const createTextLibrary = async (file: PenpotFile) => {
|
|
|
|
let librariesBuilt = 1;
|
2024-06-26 01:11:57 -05:00
|
|
|
const libraries = toArray(typographies);
|
2024-06-25 09:08:59 -05:00
|
|
|
|
|
|
|
sendMessage({
|
|
|
|
type: 'PROGRESS_TOTAL_ITEMS',
|
|
|
|
data: libraries.length
|
|
|
|
});
|
|
|
|
|
|
|
|
sendMessage({
|
|
|
|
type: 'PROGRESS_STEP',
|
|
|
|
data: 'typoLibraries'
|
|
|
|
});
|
|
|
|
|
2024-06-26 01:11:57 -05:00
|
|
|
for (const [_, library] of libraries) {
|
2024-06-25 09:08:59 -05:00
|
|
|
file.addLibraryTypography({
|
|
|
|
...library.typography,
|
|
|
|
fontId: library.textStyle.fontId,
|
|
|
|
fontVariantId: library.textStyle.fontVariantId,
|
|
|
|
letterSpacing: library.textStyle.letterSpacing,
|
|
|
|
fontWeight: library.textStyle.fontWeight,
|
|
|
|
fontStyle: library.textStyle.fontStyle,
|
|
|
|
fontFamily: library.textStyle.fontFamily,
|
|
|
|
fontSize: library.textStyle.fontSize,
|
|
|
|
textTransform: library.textStyle.textTransform,
|
|
|
|
lineHeight: library.textStyle.lineHeight
|
|
|
|
});
|
|
|
|
|
|
|
|
sendMessage({
|
|
|
|
type: 'PROGRESS_PROCESSED_ITEMS',
|
|
|
|
data: librariesBuilt++
|
|
|
|
});
|
|
|
|
|
|
|
|
await sleep(0);
|
|
|
|
}
|
|
|
|
};
|