Skip to content

Commit 39d0ce6

Browse files
committed
Update level
1 parent c5f6cc8 commit 39d0ce6

File tree

2 files changed

+22
-33
lines changed

2 files changed

+22
-33
lines changed

src/commands/devup/index.ts

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -49,23 +49,14 @@ export async function exportDevup() {
4949

5050
const typography: Record<string, (null | DevupTypography)[]> = {}
5151
await Promise.all(
52-
texts.map(async (text) => {
53-
if (typeof text.textStyleId !== 'string') return
54-
const style = await figma.getStyleByIdAsync(text.textStyleId)
55-
if (style && ids.has(style.id)) {
56-
const { type, name } = styleNameToTypography(style.name)
57-
if (typography[name]) {
58-
if (type === 'mobile' && typography[name][0]) {
59-
return
60-
}
61-
if (type === 'tablet' && typography[name][2]) {
62-
return
63-
}
64-
if (type === 'desktop' && typography[name][4]) {
65-
return
66-
}
67-
}
68-
const segs = text.getStyledTextSegments([
52+
texts
53+
.filter((text) => typeof text.textStyleId === 'string')
54+
.map(async (text) => {
55+
const style = await figma.getStyleByIdAsync(text.textStyleId as string)
56+
if (!(style && ids.has(style.id))) return
57+
const { level , name } = styleNameToTypography(style.name)
58+
if (typography[name]&&typography[name][level]) return
59+
for (const seg of text.getStyledTextSegments([
6960
'fontName',
7061
'fontWeight',
7162
'fontSize',
@@ -79,21 +70,13 @@ export async function exportDevup() {
7970
'listOptions',
8071
'indentation',
8172
'hyperlink',
82-
])
83-
for (const seg of segs) {
73+
])) {
8474
if (seg) {
8575
const typo = textSegmentToTypography(seg as StyledTextSegment)
86-
typography[name] ??= [null, null, null, null, null]
87-
if (type === 'mobile') {
88-
typography[name][0] = typo
89-
} else if (type === 'tablet') {
90-
typography[name][2] = typo
91-
} else if (type === 'desktop') {
92-
typography[name][4] = typo
93-
}
76+
typography[name] ??= [null, null, null, null, null, null]
77+
typography[name][level] = typo
9478
}
9579
}
96-
}
9780
}),
9881
)
9982
if (Object.keys(typography).length > 0) {
Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
import { toCamel } from './to-camel'
22

33
export function styleNameToTypography(name: string): {
4-
type: 'mobile' | 'tablet' | 'desktop'
4+
level: number
55
name: string
66
} {
77
const lower = name.toLowerCase()
88
if (lower.startsWith('desktop/'))
9-
return { type: 'desktop', name: toCamel(name.slice(8)) }
9+
return { level: 4, name: toCamel(name.slice(8)) }
1010
if (lower.startsWith('tablet/'))
11-
return { type: 'tablet', name: toCamel(name.slice(7)) }
11+
return { level: 2, name: toCamel(name.slice(7)) }
1212
if (lower.startsWith('mobile/'))
13-
return { type: 'mobile', name: toCamel(name.slice(7)) }
14-
return { type: 'mobile', name: toCamel(name) }
13+
return { level: 0, name: toCamel(name.slice(7)) }
14+
if (lower.includes('/')) {
15+
const [type, name] = lower.split('/')
16+
const typeNumber = parseInt(type)
17+
if (!isNaN(typeNumber)) return { level: typeNumber, name: toCamel(name) }
18+
}
19+
20+
return { level: 0, name: toCamel(name) }
1521
}

0 commit comments

Comments
 (0)