Repository Public
1// Author: Simon-Pierre Boucher — contact@spboucher.ai2// File: Sources/Shared/Design/LabelPalette.swift3// Description: SwiftUI side of the core's ten-hue palette (`SPMailCore.LabelPalette`) and avatar rule (`SPMailCore.AvatarStyle`): the hex values,4// the nearest-hue rule and the FNV-1a hash live in the core; this file only turns them into colour tokens.5import SPMailCore6import SwiftUI78extension LabelPalette {9 private static func rgb(_ hex: String) -> UInt32 { UInt32(hex.trimmingCharacters(in: CharacterSet(charactersIn: "# ")), radix: 16) ?? 0x5c5f66 }10 /// Text / dot colour of a hue: the light value on light surfaces, its lifted variant on dark and midnight.11 static func token(_ index: Int) -> SPToken {12 let l = rgb(hex(index)), d = rgb(hex(index, dark: true))13 return SPToken(l, d, d)14 }15 /// The soft background that goes with `token(index)`.16 static func soft(_ index: Int) -> SPToken {17 let l = rgb(hex(index)), d = rgb(hex(index, dark: true))18 return SPToken(.init(l, 0.12), .init(d, 0.18), .init(d, 0.16))19 }20}2122extension AvatarStyle {23 var token: SPToken { LabelPalette.token(hueIndex) }24 var soft: SPToken { LabelPalette.soft(hueIndex) }25}26