codeburn/mac/Sources/CodeBurnMenubar/Views/FlameWordmark.swift
iamtoruk f0f0ed8874 fix(menubar): keep the wordmark filled under the shimmer and slow the sweep
The letters were only visible through the animated gradient's mask, so any
frame where the mask or gradient was not laid out yet blanked the name at
random. The text now carries a static flame fill under the sweep, which can
only brighten it, and the sweep runs 4 s each way instead of 1.5 s.
2026-09-02 10:34:11 -07:00

64 lines
3 KiB
Swift

import SwiftUI
/// The "CodeBurn" wordmark filled with the website's animated flame gradient.
struct FlameWordmark: View {
@Environment(\.accessibilityReduceMotion) private var reduceMotion
@Environment(AppStore.self) private var store
@State private var sweeping = false
// CSS parity: the site's `.flame-text` uses background-size: 300% with
// `flameShift 3s ease infinite` (keyframes 0%/100% at position 0%, 50% at
// 100%). Here that's a 3x-wide gradient sweeping from its left edge aligned
// with the text to its right edge aligned with the text (a 2x-width shift)
// and back, slowed to a 4s ease-in-out each way, autoreversing.
private static let flameColors: [Color] = [
Color(red: 0xFF / 255.0, green: 0x6A / 255.0, blue: 0x00 / 255.0), // #ff6a00
Color(red: 0xFF / 255.0, green: 0xDA / 255.0, blue: 0x44 / 255.0), // #ffda44
Color(red: 0xE8 / 255.0, green: 0x55 / 255.0, blue: 0x3A / 255.0), // #e8553a
Color(red: 0xFF / 255.0, green: 0x8C / 255.0, blue: 0x00 / 255.0), // #ff8c00
Color(red: 0xFF / 255.0, green: 0xDA / 255.0, blue: 0x44 / 255.0), // #ffda44
Color(red: 0xFF / 255.0, green: 0x6A / 255.0, blue: 0x00 / 255.0) // #ff6a00
]
private var wordmark: some View {
Text("CodeBurn")
.font(.system(size: 13, weight: .semibold))
.tracking(-0.15)
}
var body: some View {
// The letters keep a static flame fill of their own, so the sweep can only
// ever brighten them; a mask that is a frame late no longer blanks the name.
wordmark
.foregroundStyle(
LinearGradient(colors: Self.flameColors, startPoint: .leading, endPoint: .trailing)
)
.overlay {
GeometryReader { geo in
LinearGradient(
colors: Self.flameColors,
startPoint: .leading,
endPoint: .trailing
)
.frame(width: geo.size.width * 3, height: geo.size.height)
.offset(x: sweeping ? -geo.size.width * 2 : 0)
.animation(
reduceMotion || !store.menuPopoverVisible
? nil
: .easeInOut(duration: 4).repeatForever(autoreverses: true),
value: sweeping
)
}
.mask(wordmark)
}
.onAppear { sweeping = store.menuPopoverVisible }
// The hosting view outlives every popover appearance, so the sweep
// starts and stops with visibility instead of running forever in a
// closed popover (5 to 7 percent idle CPU before this gate).
.onChange(of: store.menuPopoverVisible) { _, visible in
sweeping = visible
}
.accessibilityElement(children: .ignore)
.accessibilityLabel("CodeBurn")
}
}