Merge reviewed TV shell focus and text fixes
This commit is contained in:
commit
0c94e8f910
11 changed files with 260 additions and 58 deletions
|
|
@ -21,8 +21,13 @@ def property_name(name: str) -> str:
|
|||
return name.replace("-", "_")
|
||||
|
||||
|
||||
def compose_weight(weight: int) -> str:
|
||||
"""Use the platform bold face for intermediate weights that resolve to Regular in native captures."""
|
||||
return "FontWeight.Bold" if 600 <= weight <= 700 else f"FontWeight({weight})"
|
||||
|
||||
|
||||
def render_tokens(tokens: dict) -> tuple[str, str]:
|
||||
"""Translate typed source values without choosing new design values."""
|
||||
"""Translate locked values into platform-resolvable Compose and CSS tokens."""
|
||||
lines = [
|
||||
"// Generated by generate_tokens.py; edit the JSON sources instead.",
|
||||
"package org.justinvisser.wolfskin.design",
|
||||
|
|
@ -58,11 +63,11 @@ def render_tokens(tokens: dict) -> tuple[str, str]:
|
|||
weight = token.get("weight", token["$value"]["fontWeight"])
|
||||
height = size * token.get("lineHeight", 1.3)
|
||||
tracking = token.get("letterSpacingEm", 0)
|
||||
lines.append(f" val {name} = TextStyle(fontSize = {number(size)}.sp, fontWeight = FontWeight({weight}), lineHeight = {number(height)}.sp, letterSpacing = {number(tracking)}.em)")
|
||||
lines.append(f" val {name} = TextStyle(fontSize = {number(size)}.sp, fontWeight = {compose_weight(weight)}, lineHeight = {number(height)}.sp, letterSpacing = {number(tracking)}.em)")
|
||||
css.append(f" --{group_name}-{name}: {number(token['px'])}px;")
|
||||
elif kind == "typography" and "sizes" in token:
|
||||
for context, pixels in token["sizes"].items():
|
||||
lines.append(f" val {name}{context[0].upper() + context[1:]} = TextStyle(fontSize = {number(pixels / 2)}.sp, fontWeight = FontWeight({token['weight']}))")
|
||||
lines.append(f" val {name}{context[0].upper() + context[1:]} = TextStyle(fontSize = {number(pixels / 2)}.sp, fontWeight = {compose_weight(token['weight'])})")
|
||||
elif kind == "duration":
|
||||
lines.append(f" const val {name} = {int(value.removesuffix('ms'))}")
|
||||
css.append(f" --{group_name}-{name}: {value};")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue