fix(flutter): handle nested colors split in tokens.json codegen

Web tokens.json was reshaped for the SPA theme toggle (#362) with
colors split into dark/light/flat blocks. gen_tokens.dart still
expected a flat string map and threw _Map<String,dynamic> cast
errors in the flutter CI workflow. Read colors.dark + colors.flat
and merge into the existing flat namespace; light variants will be
emitted when the Flutter client gains a theme toggle as part of
#356 parity work. Adds hyphen→camelCase normalization so the new
on-action token surfaces as onAction.
This commit is contained in:
2026-05-03 14:46:27 -04:00
parent 7faa7b4e1f
commit 7d82be864d
3 changed files with 52 additions and 30 deletions
+1
View File
@@ -17,6 +17,7 @@ class FabledSwordTokens {
static const Color error = Color(0xFFC04A1F); static const Color error = Color(0xFFC04A1F);
static const Color info = Color(0xFF3D5A6E); static const Color info = Color(0xFF3D5A6E);
static const Color accent = Color(0xFF4A6B5C); static const Color accent = Color(0xFF4A6B5C);
static const Color onAction = Color(0xFFE8E4D8);
static const double radiusSm = 4; static const double radiusSm = 4;
static const double radiusMd = 8; static const double radiusMd = 8;
static const double radiusLg = 12; static const double radiusLg = 12;
+30 -25
View File
@@ -1,31 +1,36 @@
{ {
"colors": { "colors": {
"obsidian": "#14171A", "dark": {
"iron": "#1E2228", "obsidian": "#14171A",
"slate": "#2C313A", "iron": "#1E2228",
"pewter": "#3F4651", "slate": "#2C313A",
"parchment": "#E8E4D8", "pewter": "#3F4651",
"vellum": "#C2BFB4", "parchment": "#E8E4D8",
"ash": "#9C9A92", "vellum": "#C2BFB4",
"moss": "#4A5D3F", "ash": "#9C9A92"
"bronze": "#8B7355", },
"oxblood": "#6B2118", "light": {
"warning": "#8B6F1E", "obsidian": "#F8F5EE",
"error": "#C04A1F", "iron": "#ECE6D5",
"info": "#3D5A6E", "slate": "#DCD3BD",
"accent": "#4A6B5C" "pewter": "#B8AE94",
}, "parchment": "#14171A",
"radii": { "vellum": "#2C313A",
"sm": "4px", "ash": "#5C6068"
"md": "8px", },
"lg": "12px", "flat": {
"xl": "16px" "moss": "#4A5D3F",
}, "bronze": "#8B7355",
"fonts": { "oxblood": "#6B2118",
"display": "Fraunces", "warning": "#8B6F1E",
"body": "Inter", "error": "#C04A1F",
"mono": "JetBrains Mono" "info": "#3D5A6E",
"accent": "#4A6B5C",
"on-action": "#E8E4D8"
}
}, },
"radii": { "sm": "4px", "md": "8px", "lg": "12px", "xl": "16px" },
"fonts": { "display": "Fraunces", "body": "Inter", "mono": "JetBrains Mono" },
"fontStacks": { "fontStacks": {
"display": "'Fraunces', Georgia, serif", "display": "'Fraunces', Georgia, serif",
"body": "'Inter', system-ui, sans-serif", "body": "'Inter', system-ui, sans-serif",
+21 -5
View File
@@ -1,15 +1,25 @@
// Reads shared/fabledsword.tokens.json and emits lib/theme/tokens.dart. // Reads shared/fabledsword.tokens.json and emits lib/theme/tokens.dart.
// Run via `dart run tool/gen_tokens.dart`. The generated file is // Run via `dart run tool/gen_tokens.dart`. The generated file is
// committed (CI validates it matches the JSON to catch drift). // committed (CI validates it matches the JSON to catch drift).
//
// Web tokens.json splits colors into `dark`, `light`, and `flat` blocks
// for the SPA's theme toggle. Flutter v1 ships dark-only, so we merge
// dark + flat into a single flat namespace. Light variants will be
// emitted alongside as part of the Flutter theme-toggle parity work.
import 'dart:convert'; import 'dart:convert';
import 'dart:io'; import 'dart:io';
void main() { void main() {
final jsonFile = File('shared/fabledsword.tokens.json'); final jsonFile = File('shared/fabledsword.tokens.json');
final tokens = jsonDecode(jsonFile.readAsStringSync()) as Map<String, dynamic>; final tokens = jsonDecode(jsonFile.readAsStringSync()) as Map<String, dynamic>;
final colors = (tokens['colors'] as Map).cast<String, String>();
final radii = (tokens['radii'] as Map).cast<String, String>(); final colorsRoot = (tokens['colors'] as Map).cast<String, dynamic>();
final fonts = (tokens['fonts'] as Map).cast<String, String>(); final dark = (colorsRoot['dark'] as Map).cast<String, String>();
final flat = (colorsRoot['flat'] as Map).cast<String, String>();
final colors = <String, String>{...dark, ...flat};
final radii = (tokens['radii'] as Map).cast<String, String>();
final fonts = (tokens['fonts'] as Map).cast<String, String>();
final out = StringBuffer() final out = StringBuffer()
..writeln('// GENERATED — do not edit. Source: shared/fabledsword.tokens.json') ..writeln('// GENERATED — do not edit. Source: shared/fabledsword.tokens.json')
@@ -38,5 +48,11 @@ void main() {
stdout.writeln('wrote lib/theme/tokens.dart'); stdout.writeln('wrote lib/theme/tokens.dart');
} }
String _camel(String s) => s; // tokens are already lowerCamel-friendly // Hyphens become camelCase boundaries: on-action → onAction.
String _pascal(String s) => s[0].toUpperCase() + s.substring(1); String _camel(String s) {
final parts = s.split('-');
return parts.first +
parts.skip(1).map((p) => p[0].toUpperCase() + p.substring(1)).join();
}
String _pascal(String s) => s[0].toUpperCase() + s.substring(1);