SPB Git

Repository Public

EditorTokens.swift 3.8 KB 70 lines swift

1// Author: Simon-Pierre Boucher — contact@spboucher.ai2// File: Editor/EditorTokens.swift3// Description: Note Visual System 2.0 inside the AppKit editor: the SPNotesDesign colour tokens as dynamic NSColors, and the metrics of the editor (indents, panels, cards, chips) expressed with the spacing and radius scales.4import AppKit5import SPNotesDesign67public extension NSColor {8    /// A design token as a dynamic colour: one attributed string serves the light and dark appearances.9    static func nv(_ token: NVColor.Token, alpha: CGFloat = 1) -> NSColor {10        NSColor(name: nil) { appearance in11            let rgb = token.rgb(dark: appearance.bestMatch(from: [.darkAqua, .aqua]) == .darkAqua)12            return NSColor(srgbRed: rgb.red, green: rgb.green, blue: rgb.blue, alpha: rgb.alpha * alpha)13        }14    }15}1617/// Tones shared by chips, cards and panels (the editor's view of `NVTone`).18public enum EditorTone: String, Sendable, Equatable, CaseIterable {19    case neutral, accent, ai, success, warning, danger20    public var foreground: NSColor {21        switch self {22        case .neutral: .nv(.fgMuted); case .accent: .nv(.accent); case .ai: .nv(.ai)23        case .success: .nv(.successText); case .warning: .nv(.warningText); case .danger: .nv(.dangerText)24        }25    }26    public var fill: NSColor {27        switch self {28        case .neutral: .nv(.bgHover); case .accent: .nv(.accentSoft); case .ai: .nv(.aiSoft)29        case .success: .nv(.success, alpha: 0.14); case .warning: .nv(.warning, alpha: 0.16); case .danger: .nv(.danger, alpha: 0.13)30        }31    }32    /// The base hue (icons, bars, borders).33    public var hue: NSColor {34        switch self {35        case .neutral: .nv(.lineStrong); case .accent: .nv(.accent); case .ai: .nv(.ai)36        case .success: .nv(.success); case .warning: .nv(.warning); case .danger: .nv(.danger)37        }38    }39}4041/// Every length the editor draws with, from the spacing (2 4 8 12 16 24 32 48 64) and radius (4 6 10 14 20) scales.42public enum EditorMetrics {43    public static let textInset = NVSpace.lg + NVSpace.xxs                // top and bottom of the text column44    public static let minSideInset = NVSpace.xxl - NVSpace.xs            // 28: side margin on a narrow window45    public static let listIndent = NVSpace.xl + NVSpace.xxs              // 26: one list level46    public static let quoteIndent = NVSpace.lg + NVSpace.xxs             // 1847    public static let quoteBarWidth: CGFloat = 348    public static let calloutIndent = NVSpace.xxl + NVSpace.sm           // 40: room for the icon49    public static let calloutIconInset = NVSpace.md50    public static let panelInset = NVSpace.md                            // text inset inside a code / AI panel51    public static let panelRadius = NVRadius.md52    public static let panelGap = NVSpace.md                              // space above and below a panel53    public static let aiHeaderHeight = NVSpace.xl                        // strip « Généré par IA » above the first paragraph54    public static let aiFooterHeight = NVSpace.xl + NVSpace.xs           // source chips under the last paragraph55    public static let cardRadius = NVRadius.md56    public static let cardPadding = NVSpace.md57    public static let cardIcon = NVSpace.xl + NVSpace.xs                 // 28: icon tile58    public static let cardMaxWidth = NVSpace.readingMeasure59    public static let chipHeight = NVSpace.lg + NVSpace.xxs              // 1860    public static let chipPadding = NVSpace.sm - NVSpace.xxs             // 661    public static let chipGap = NVSpace.xs62    public static let chipRadius = NVRadius.xs + 163    public static let pillRadius = NVRadius.xs64    public static let imageRadius = NVRadius.sm65    public static let imageMaxWidth: CGFloat = 72066    public static let checkboxRadius: CGFloat = 3.567    public static let microFontSize: CGFloat = 1168    public static let uiFontSize: CGFloat = 1369}70
Files main
Menu

Theme