generated from sketch-hq/sketch-assistant-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
30 lines (25 loc) · 1.08 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { RuleDefinition } from '@sketch-hq/sketch-assistant-types'
import FileFormat from '@sketch-hq/sketch-file-format-ts'
export const syncTextStyles: RuleDefinition = {
rule: async (context) => {
type StyleId = string
const { utils } = context
const sharedStyles: Map<StyleId, FileFormat.SharedStyle> = new Map()
for (const sharedStyle of utils.objects.sharedStyle) {
if (typeof sharedStyle.do_objectID === 'string') {
sharedStyles.set(sharedStyle.do_objectID, sharedStyle)
}
}
for (const text of utils.objects.text) {
if (typeof text.sharedStyleID !== 'string') continue
const sharedStyle = sharedStyles.get(text.sharedStyleID)
if (!sharedStyle) continue
if (!utils.textStyleEq(text.style, sharedStyle.value)) {
context.utils.report('\''+ sharedStyle.name + '\' shared style on \''+ text.name +'\' is out of sync', text)
}
}
},
name: 'nds-sketch-theme-assistant/sync-text-styles',
title: 'Text Style is Out of Sync',
description: 'Reports if a text style is out of sync with the shared style.',
}