Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"useTabs": true,
"semi": false,
"printWidth": 140,
"singleQuote": true,
"trailingComma": "all"
}
62 changes: 29 additions & 33 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,24 @@ type CssLocation = {
length: number
}
type UniqueWithLocations = Record<string, CssLocation[]>
type Collection = {
unique: UniqueCount
} | {
uniqueWithLocations: UniqueWithLocations
}
type ItemsPerContext = Record<string, {
unique: Record<string, number>,
uniqueWithLocations?: UniqueWithLocations,
}>
type Collection =
| {
unique: UniqueCount
}
| {
uniqueWithLocations: UniqueWithLocations
}
type ItemsPerContext = Record<
string,
{
unique: Record<string, number>
uniqueWithLocations?: UniqueWithLocations
}
>

type TokenID = string

type Tokens = {
export type Tokens = {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was the change I wanted

color: Record<TokenID, ColorToken>
font_size: Record<TokenID, UnparsedToken | DimensionToken>
font_family: Record<TokenID, FontFamilyToken>
Expand Down Expand Up @@ -114,16 +119,15 @@ export function analysis_to_tokens(analysis: CssAnalysis): Tokens {
let old_properties = colors[name].$extensions[EXTENSION_CSS_PROPERTIES]
colors[name].$extensions[EXTENSION_CSS_PROPERTIES] = Array.from(new Set(old_properties).union(new_properties))
colors[name].$extensions[EXTENSION_USAGE_COUNT] += count
}
else {
} else {
colors[name] = {
$type: 'color',
$value: color_token,
$extensions: {
[EXTENSION_AUTHORED_AS]: color,
[EXTENSION_USAGE_COUNT]: count,
[EXTENSION_CSS_PROPERTIES]: Array.from(new_properties),
}
},
}
}
}
Expand All @@ -148,13 +152,11 @@ export function analysis_to_tokens(analysis: CssAnalysis): Tokens {
$value: font_size,
$extensions: extensions,
}
}
else {
} else {
let name = `fontSize-${hash(parsed.value.toString() + parsed.unit)}`
if (font_sizes[name]) {
font_sizes[name].$extensions[EXTENSION_USAGE_COUNT] += extensions[EXTENSION_USAGE_COUNT]
}
else {
} else {
font_sizes[name] = {
$type: 'dimension',
$value: parsed,
Expand All @@ -177,8 +179,8 @@ export function analysis_to_tokens(analysis: CssAnalysis): Tokens {
$value: parsed,
$extensions: {
[EXTENSION_AUTHORED_AS]: font_family,
[EXTENSION_USAGE_COUNT]: get_count(unique[font_family]!)
}
[EXTENSION_USAGE_COUNT]: get_count(unique[font_family]!),
},
}
}
return families
Expand All @@ -200,35 +202,30 @@ export function analysis_to_tokens(analysis: CssAnalysis): Tokens {
$value: line_height,
$extensions: extensions,
}
}
else if (typeof parsed === 'number') {
} else if (typeof parsed === 'number') {
let name = `lineHeight-${hash(parsed)}`
if (line_heights[name]) {
line_heights[name].$extensions[EXTENSION_USAGE_COUNT] += extensions[EXTENSION_USAGE_COUNT]
}
else {
} else {
line_heights[name] = {
$type: 'number',
$value: parsed,
$extensions: extensions,
}
}
}
else if (typeof parsed === 'object') {
} else if (typeof parsed === 'object') {
if (parsed.unit === 'px' || parsed.unit === 'rem') {
let name = `lineHeight-${hash(parsed.value.toString() + parsed.unit)}`
if (line_heights[name]) {
line_heights[name].$extensions[EXTENSION_USAGE_COUNT] += extensions[EXTENSION_USAGE_COUNT]
}
else {
} else {
line_heights[name] = {
$type: 'dimension',
$value: parsed,
$extensions: extensions,
}
}
}
else {
} else {
let name = `lineHeight-${hash(line_height)}`
line_heights[name] = {
$value: line_height,
Expand Down Expand Up @@ -313,13 +310,12 @@ export function analysis_to_tokens(analysis: CssAnalysis): Tokens {
let name = `duration-${hash(parsed.toString())}`
if (durations[name]) {
durations[name].$extensions[EXTENSION_USAGE_COUNT] += extensions[EXTENSION_USAGE_COUNT]
}
else {
} else {
durations[name] = {
$type: 'duration',
$value: {
value: parsed,
unit: 'ms'
unit: 'ms',
},
$extensions: extensions,
}
Expand Down Expand Up @@ -362,4 +358,4 @@ export function analysis_to_tokens(analysis: CssAnalysis): Tokens {
return easings
})(),
}
}
}