Repository Public
1#!/usr/bin/env python32# =============================================================================3# SP BOUCHER | SOFTWARE & RESEARCH4# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5# =============================================================================6#7# Project : SPB Git for iOS and iPadOS8# File : scripts/generate-colors.py9# Module : Scripts10# Repository : https://git.spboucher.ai/spbgit-ios11# Project Website : Not specified12# Created : 2026-12-0213# Last Modified : 2026-12-0214#15# Author : Simon-Pierre Boucher16# Position : Professor of Finance17# Institution : Université du Québec en Outaouais (UQO)18# Organization : SP Boucher19# Website : https://spboucher.ai20# Git : https://git.spboucher.ai21#22# Preferred Contact: contact@spboucher.ai23# Development : dev@spboucher.ai24# Support : support@spboucher.ai25# Security/Admin : admin@spboucher.ai26#27# Copyright (c) 202628# Simon-Pierre Boucher29# All rights reserved where applicable. This file is governed by the30# applicable project license, copyright notices and relevant law.31# Existing third-party rights and notices remain unaffected.32#33# License : None specified (no license file in this repository)34#35# Do not embed credentials, private keys, access tokens,36# certificates or confidential personal information.37#38# =============================================================================39# END OF SP BOUCHER SOURCE HEADER40# =============================================================================4142"""Generate the colour sets of the SPB Git Design System.4344The table below is the single source of the palette. Each token has four values: light, dark, light with45Increase Contrast, dark with Increase Contrast. Run from the repository root:4647 python3 scripts/generate-colors.py4849It rewrites SPBGit/Resources/Assets.xcassets/Colors/<Token>.colorset/Contents.json and AccentColor.colorset.50`SPBColor` (SPBGit/DesignSystem/Colors/SPBColor.swift) exposes one static property per token; keep both in step.51"""52import json53import pathlib5455ROOT = pathlib.Path(__file__).resolve().parent.parent / "SPBGit" / "Resources" / "Assets.xcassets"5657# token: (light, dark, light high contrast, dark high contrast)58PALETTE = {59 "Background": ("F6F6F3", "0B0C0E", "FFFFFF", "000000"),60 "Surface": ("FFFFFF", "15171A", "FFFFFF", "0E0F11"),61 "SurfaceRaised": ("EDEDE9", "1E2125", "E4E4DF", "25292E"),62 "Separator": ("D8D8D2", "2B2F35", "8C8F94", "70757D"),63 "TextPrimary": ("101214", "F3F3F0", "000000", "FFFFFF"),64 "TextSecondary": ("4C5157", "A9AEB5", "2C3035", "D3D6DA"),65 "TextTertiary": ("6F747B", "7F858D", "4A4F55", "B4B8BE"),66 "Accent": ("0F5BFF", "4F8FFF", "0040C9", "8AB4FF"),67 "AccentSoft": ("E2EBFF", "13244A", "D0DEFF", "1B3266"),68 "OnAccent": ("FFFFFF", "06101F", "FFFFFF", "000000"),69 "Addition": ("1A7F37", "3FB950", "0F5F26", "6FDD8B"),70 "Deletion": ("C9202C", "F85149", "A1121C", "FF8A84"),71 "Warning": ("B35900", "F0883E", "8A4300", "FFB077"),72 "Titanium": ("878C93", "6C727A", "5C6168", "A4A9B0"),73 "CodeBackground": ("EFEFEB", "101214", "F6F6F3", "050506"),74}757677def component(hex_value: str) -> dict:78 return {79 "color-space": "srgb",80 "components": {81 "red": "0x" + hex_value[0:2],82 "green": "0x" + hex_value[2:4],83 "blue": "0x" + hex_value[4:6],84 "alpha": "1.000",85 },86 }878889def colorset(light: str, dark: str, light_hc: str, dark_hc: str) -> dict:90 dark_mode = {"appearance": "luminosity", "value": "dark"}91 high = {"appearance": "contrast", "value": "high"}92 return {93 "colors": [94 {"idiom": "universal", "color": component(light)},95 {"idiom": "universal", "appearances": [dark_mode], "color": component(dark)},96 {"idiom": "universal", "appearances": [high], "color": component(light_hc)},97 {"idiom": "universal", "appearances": [dark_mode, high], "color": component(dark_hc)},98 ],99 "info": {"author": "xcode", "version": 1},100 }101102103def write(path: pathlib.Path, payload: dict) -> None:104 path.parent.mkdir(parents=True, exist_ok=True)105 path.write_text(json.dumps(payload, indent=2) + "\n", encoding="utf-8")106107108def main() -> None:109 info = {"info": {"author": "xcode", "version": 1}}110 write(ROOT / "Contents.json", info)111 write(ROOT / "Colors" / "Contents.json", info)112 for name, values in PALETTE.items():113 if name == "Accent":114 continue # lives in AccentColor.colorset (the global accent); a second set would clash in the generated symbols115 write(ROOT / "Colors" / f"{name}.colorset" / "Contents.json", colorset(*values))116 write(ROOT / "AccentColor.colorset" / "Contents.json", colorset(*PALETTE["Accent"]))117 icon = {118 "images": [{"idiom": "universal", "platform": "ios", "size": "1024x1024"}],119 "info": {"author": "xcode", "version": 1},120 }121 icon_path = ROOT / "AppIcon.appiconset" / "Contents.json"122 if not icon_path.exists():123 write(icon_path, icon)124 print(f"{len(PALETTE)} colour sets written to {ROOT}")125126127if __name__ == "__main__":128 main()129