@@ -13,7 +13,7 @@ import { optimizeHex } from '../../utils/optimize-hex'
1313import { downloadDevupXlsx } from './utils/download-devup-xlsx'
1414import { uploadDevupXlsx } from './utils/upload-devup-xlsx'
1515import { textStyleToTypography } from '../../utils/text-style-to-typography'
16- export async function exportDevup ( output : "json" | "excel" ) {
16+ export async function exportDevup ( output : "json" | "excel" , treeshaking : boolean = true ) {
1717 const devup : Devup = { }
1818
1919 const collection = await getDevupColorCollection ( )
@@ -47,7 +47,6 @@ export async function exportDevup(output: "json" | "excel") {
4747
4848 await figma . loadAllPagesAsync ( )
4949
50- const texts = figma . root . findAllWithCriteria ( { types : [ 'TEXT' ] } )
5150 const textStyles = await figma . getLocalTextStylesAsync ( )
5251 const ids = new Set ( )
5352 const styles : Record < string , TextStyle > = { }
@@ -57,38 +56,50 @@ export async function exportDevup(output: "json" | "excel") {
5756 }
5857
5958 const typography : Record < string , ( null | DevupTypography ) [ ] > = { }
60- await Promise . all (
61- texts
62- . filter ( ( text ) => ( typeof text . textStyleId === 'string' && text . textStyleId ) || text . textStyleId === figma . mixed )
63- . map ( async ( text ) => {
64- for ( const seg of text . getStyledTextSegments ( [
65- 'fontName' ,
66- 'fontWeight' ,
67- 'fontSize' ,
68- 'textDecoration' ,
69- 'textCase' ,
70- 'lineHeight' ,
71- 'letterSpacing' ,
72- 'fills' ,
73- 'textStyleId' ,
74- 'fillStyleId' ,
75- 'listOptions' ,
76- 'indentation' ,
77- 'hyperlink' ,
78- ] ) ) {
79- if ( seg && seg . textStyleId ) {
80- const style = await figma . getStyleByIdAsync ( seg . textStyleId )
59+ if ( treeshaking ) {
60+ const texts = figma . root . findAllWithCriteria ( { types : [ 'TEXT' ] } )
61+ await Promise . all (
62+ texts
63+ . filter ( ( text ) => ( typeof text . textStyleId === 'string' && text . textStyleId ) || text . textStyleId === figma . mixed )
64+ . map ( async ( text ) => {
65+ for ( const seg of text . getStyledTextSegments ( [
66+ 'fontName' ,
67+ 'fontWeight' ,
68+ 'fontSize' ,
69+ 'textDecoration' ,
70+ 'textCase' ,
71+ 'lineHeight' ,
72+ 'letterSpacing' ,
73+ 'fills' ,
74+ 'textStyleId' ,
75+ 'fillStyleId' ,
76+ 'listOptions' ,
77+ 'indentation' ,
78+ 'hyperlink' ,
79+ ] ) ) {
80+ if ( seg && seg . textStyleId ) {
81+ const style = await figma . getStyleByIdAsync ( seg . textStyleId )
8182
82- if ( ! ( style && ids . has ( style . id ) ) ) continue
83- const { level, name } = styleNameToTypography ( style . name )
84- const typo = textSegmentToTypography ( seg )
85- if ( typography [ name ] && typography [ name ] [ level ] ) continue
86- typography [ name ] ??= [ null , null , null , null , null , null ]
87- typography [ name ] [ level ] = typo
83+ if ( ! ( style && ids . has ( style . id ) ) ) continue
84+ const { level, name } = styleNameToTypography ( style . name )
85+ const typo = textSegmentToTypography ( seg )
86+ if ( typography [ name ] && typography [ name ] [ level ] ) continue
87+ typography [ name ] ??= [ null , null , null , null , null , null ]
88+ typography [ name ] [ level ] = typo
89+ }
8890 }
89- }
90- } ) ,
91- )
91+ } ) ,
92+ )
93+ }
94+ else {
95+ for ( const [ styleName , style ] of Object . entries ( styles ) ) {
96+ const { level, name } = styleNameToTypography ( styleName )
97+ const typo = textStyleToTypography ( style )
98+ if ( typography [ name ] && typography [ name ] [ level ] ) continue
99+ typography [ name ] ??= [ null , null , null , null , null , null ]
100+ typography [ name ] [ level ] = typo
101+ }
102+ }
92103
93104 for ( const [ name , style ] of Object . entries ( styles ) ) {
94105 const { level, name : styleName } = styleNameToTypography ( name )
0 commit comments