Repository Public
1#!/usr/bin/env python32# Author: Simon-Pierre Boucher — contact@spboucher.ai3# File: Scripts/sync-design-tokens.py4# Description: Writes the colour tokens of Visual System V2 « Graphite & Iris · Lumen » as asset catalog colour sets (light / dark, plus high-contrast variants) under Assets.xcassets/Tokens.5#6# Usage: Scripts/sync-design-tokens.py7# The table below is the one of DESIGN-SYSTEM-V2.md (§2 Tokens → Colour). Web and iOS implement the same values.8import json, shutil9from pathlib import Path1011ROOT = Path(__file__).resolve().parent.parent12OUT = ROOT / "SPChat" / "Resources" / "Assets.xcassets" / "Tokens"1314# name: (dark, light) — "#RRGGBB" or ("#RRGGBB", alpha)15TOKENS = {16 "bg": ("#09090B", "#FAFAF8"),17 "bgElev": ("#0E0E11", "#FFFFFF"),18 "surface": ("#141418", "#FFFFFF"),19 "surface2": ("#1B1B20", "#F2F2EF"),20 "border": ("#24242A", "#E5E5E1"),21 "borderStrong": ("#34343C", "#D0D0CA"),22 "text": ("#F2F2F4", "#111113"),23 "text2": ("#B3B3BC", "#45454E"),24 "muted": ("#777782", "#7B7B85"),25 "accent": ("#8F80FF", "#5A45E0"),26 "accentSoft": (("#8F80FF", 0.14), ("#5A45E0", 0.10)),27 "userBubble": ("#1E1B33", "#EFECFF"),28 "ok": ("#4FD1A5", "#1F9D75"),29 "warn": ("#F6C35C", "#B7791F"),30 "danger": ("#FF6B6B", "#D6453D"),31 "lumenHi": ("#B6ACFF", "#B6ACFF"),32 # opaque stand-ins of the floating material when « Increase contrast » / « Reduce transparency » is on33 "floatSolid": ("#16161B", "#FFFFFF"),34}35# Increase Contrast: stronger hairlines and secondary text (contrast ≥ 7:1 on the canvas)36HIGH_CONTRAST = {"border": ("#4A4A55", "#A9A9A2"), "borderStrong": ("#6A6A78", "#77776F"), "text2": ("#D6D6DE", "#26262C"), "muted": ("#A6A6B2", "#55555E")}3738def components(value):39 hexa, alpha = (value, 1.0) if isinstance(value, str) else value40 h = hexa.lstrip("#")41 return {"color-space": "srgb", "components": {"red": f"0x{h[0:2].upper()}", "green": f"0x{h[2:4].upper()}", "blue": f"0x{h[4:6].upper()}", "alpha": f"{alpha:.3f}"}}4243def entry(value, dark=False, contrast=False):44 e = {"idiom": "universal", "color": components(value)}45 app = []46 if dark: app.append({"appearance": "luminosity", "value": "dark"})47 if contrast: app.append({"appearance": "contrast", "value": "high"})48 if app: e["appearances"] = app49 return e5051def main():52 if OUT.exists(): shutil.rmtree(OUT)53 OUT.mkdir(parents=True)54 (OUT / "Contents.json").write_text(json.dumps({"info": {"author": "xcode", "version": 1}, "properties": {"provides-namespace": True}}, indent=2) + "\n")55 for name, (dark, light) in TOKENS.items():56 colors = [entry(light), entry(dark, dark=True)]57 if name in HIGH_CONTRAST:58 hd, hl = HIGH_CONTRAST[name]59 colors += [entry(hl, contrast=True), entry(hd, dark=True, contrast=True)]60 d = OUT / f"{name}.colorset"; d.mkdir()61 (d / "Contents.json").write_text(json.dumps({"colors": colors, "info": {"author": "xcode", "version": 1}}, indent=2) + "\n")62 # the system accent of the app follows the iris token63 acc = ROOT / "SPChat" / "Resources" / "Assets.xcassets" / "AccentColor.colorset"64 acc.mkdir(exist_ok=True)65 dark, light = TOKENS["accent"]66 (acc / "Contents.json").write_text(json.dumps({"colors": [entry(light), entry(dark, dark=True)], "info": {"author": "xcode", "version": 1}}, indent=2) + "\n")67 print(f"{len(TOKENS)} colour tokens → {OUT.relative_to(ROOT)} (+ AccentColor)")6869if __name__ == "__main__":70 main()71