Skip to content

armgit / cra

Public Imported from GitHub
0

The open-source Arc replacement for macOS. Spaces, pinned tabs, split view, Little Windows and Arc's shortcuts on Chromium, with your Arc sidebar imported in one go.

Theme editor pairs and Escape as recorded in Arc: Arc's own second colours, Drab as singles, Escape keeps the change (#170)

Victor24e8ae2ef149
diff --git a/Packages/CraCore/Sources/CraCore/SpaceColorPresets.swift b/Packages/CraCore/Sources/CraCore/SpaceColorPresets.swift
index c06bc63..9f283da 100644
--- a/Packages/CraCore/Sources/CraCore/SpaceColorPresets.swift
+++ b/Packages/CraCore/Sources/CraCore/SpaceColorPresets.swift
@@ -4,37 +4,42 @@ import Foundation
/// are named colours in ARCClients_BaseAssets' asset catalog, four groups of nine
/// (ColorPickerBrand1–9, Drab, Pastel, Greyscale), defined in sRGB, extended linear sRGB or
/// Display P3; these are their sRGB values, as Arc writes them to StorableSidebar.json (Brand8 →
-/// 0.4236, 0.7286, 0.8512). A two-colour swatch is a catalog colour with its complementary
-/// colour added (Arc: the preset view's `addComplimentary`).
+/// 0.4236, 0.7286, 0.8512). A two-colour swatch is a catalog colour with its analogous colour added
+/// (Arc: the preset view's `addComplimentary`, saved as an `analogous` wheel).
public enum SpaceColorPresets {
public static let brand = ["#F2EAE4", "#F29BBB", "#A6729D", "#F25E6B", "#FF8558", "#F8D558", "#34E895", "#6CBAD9", "#666789"]
public static let drab = ["#4E3A5A", "#693558", "#8F4042", "#B16D40", "#D7B35D", "#CDCCA4", "#7AA982", "#226149", "#26456B"]
public static let pastel = ["#FEFBFA", "#FFE9F3", "#F1D1EC", "#FFCBD1", "#FFE0D3", "#FFF9E5", "#DEFDEB", "#DCF3FC", "#C5C6E5"]
public static let greyscale = ["#FFFFFF", "#E6E6E6", "#CCCCCC", "#B2B2B2", "#808080", "#666666", "#333333", "#1A1A1A", "#000000"]
+ /// The second colour Arc saves for each Brand pair (offline Arc 1.171, the page-2 swatches pressed over AX:
+ /// `baseColors[1]` in StorableSidebar.json), 29–46° further round the hue wheel.
+ public static let brandPairs = ["#EFF1E3", "#EFB19B", "#A6727F", "#EAAF5A", "#F0E941", "#A4F454", "#38E5E7", "#7F7EDC", "#7F6589"]
- /// One page of nine: a catalog group, alone or with each colour's complement.
+ /// One page of nine: a catalog group, alone or each colour with a second one.
public struct Page: Equatable, Sendable {
/// The catalog group: Brand, Drab, Pastel or Greyscale.
public let group: String
public let colors: [String]
- public let complementary: Bool
+ /// Each swatch's second colour, for a page of pairs.
+ public let seconds: [String]?
/// Arc's asset name of swatch `i` (ColorPickerBrand4), which its accessibility label names.
public func name(_ i: Int) -> String { "ColorPicker\(group)\(i + 1)" }
- /// What each swatch puts on the pad: one colour, or it and its complement.
+ /// What each swatch puts on the pad: one colour, or two.
public var swatches: [[String]] {
- colors.map { complementary ? [$0, SpaceColorWheel.complement(of: $0)] : [$0] }
+ guard let seconds else { return colors.map { [$0] } }
+ return zip(colors, seconds).map { [$0, $1] }
}
}
- /// Arc's five pages: bright singles, bright pairs, pastels, muted pairs, greys.
+ /// Arc's five pages (offline Arc 1.171, AX + captures): Brand, Brand pairs, Pastel, Drab, Greyscale.
public static let pages: [Page] = [
- Page(group: "Brand", colors: brand, complementary: false),
- Page(group: "Brand", colors: brand, complementary: true),
- Page(group: "Pastel", colors: pastel, complementary: false),
- Page(group: "Drab", colors: drab, complementary: true),
- Page(group: "Greyscale", colors: greyscale, complementary: false),
+ Page(group: "Brand", colors: brand, seconds: nil),
+ Page(group: "Brand", colors: brand, seconds: brandPairs),
+ Page(group: "Pastel", colors: pastel, seconds: nil),
+ Page(group: "Drab", colors: drab, seconds: nil),
+ Page(group: "Greyscale", colors: greyscale, seconds: nil),
]
/// The page that holds a theme's pad colours, so the editor opens where they are; nil when
@@ -51,20 +56,14 @@ public enum SpaceColorPresets {
}
/// The editor pad's colour wheel: a colour's place is its HSB hue (angle) and saturation
-/// (distance from the centre). A second and third colour sit `spread`° either side of the first.
+/// (distance from the centre). A second and third colour sit `spread`° either side of the first
+/// (Arc's saved pairs sit 29–46° away).
public enum SpaceColorWheel {
public static let spread = 40.0
/// The hue offset of pad colour `i`: 0 for the first, then +spread, −spread.
public static func offset(_ i: Int) -> Double { i == 0 ? 0 : (i == 1 ? spread : -spread) }
- /// The second colour a swatch or + adds next to `hex`: its hue turned by `spread`, the same
- /// saturation and brightness.
- public static func complement(of hex: String) -> String {
- let (h, s, b) = hsb(hex)
- return self.hex(hue: h + offset(1), saturation: s, brightness: b)
- }
-
public static func hsb(_ hex: String) -> (hue: Double, saturation: Double, brightness: Double) {
let c = HexColor.components(hex) ?? (0.5, 0.5, 0.5)
let mx = max(c.r, c.g, c.b), mn = min(c.r, c.g, c.b), d = mx - mn
diff --git a/Packages/CraCore/Tests/CraCoreTests/SpaceColorPresetsTests.swift b/Packages/CraCore/Tests/CraCoreTests/SpaceColorPresetsTests.swift
index 760fab2..32edf55 100644
--- a/Packages/CraCore/Tests/CraCoreTests/SpaceColorPresetsTests.swift
+++ b/Packages/CraCore/Tests/CraCoreTests/SpaceColorPresetsTests.swift
@@ -15,12 +15,13 @@ struct SpaceColorPresetsTests {
#expect(SpaceColorPresets.greyscale.first == "#FFFFFF" && SpaceColorPresets.greyscale.last == "#000000")
}
- /// Five pages of nine with paging; singles put one colour on the pad, pairs two.
+ /// Five pages of nine as in Arc: Brand, Brand pairs, Pastel, Drab, Greyscale.
@Test func pages() {
- #expect(SpaceColorPresets.pages.count == 5)
+ #expect(SpaceColorPresets.pages.map(\.group) == ["Brand", "Brand", "Pastel", "Drab", "Greyscale"])
+ #expect(SpaceColorPresets.pages.map { $0.seconds != nil } == [false, true, false, false, false])
for page in SpaceColorPresets.pages {
#expect(page.swatches.count == 9)
- #expect(page.swatches.allSatisfy { $0.count == (page.complementary ? 2 : 1) })
+ #expect(page.swatches.allSatisfy { $0.count == (page.seconds == nil ? 1 : 2) })
}
}
@@ -43,14 +44,18 @@ struct SpaceColorPresetsTests {
#expect(theme.isDark == (HexColor.luminance(hex)! < 0.45))
}
- /// The wheel's complement keeps saturation and brightness and turns the hue.
- @Test(arguments: SpaceColorPresets.brand + SpaceColorPresets.drab)
- func complementTurnsTheHue(hex: String) {
- let a = SpaceColorWheel.hsb(hex), b = SpaceColorWheel.hsb(SpaceColorWheel.complement(of: hex))
- #expect(abs(a.saturation - b.saturation) < 0.02 && abs(a.brightness - b.brightness) < 0.01)
+ /// Arc's pairs: each Brand colour with the second colour Arc saved for it, which keeps roughly
+ /// its brightness and lies 29–46° further round the hue wheel.
+ @Test(arguments: 0..<9)
+ func brandPairs(index: Int) {
+ let swatch = SpaceColorPresets.pages[1].swatches[index]
+ #expect(swatch == [SpaceColorPresets.brand[index], SpaceColorPresets.brandPairs[index]])
+ #expect(SpaceColorPresets.brandPairs[3] == "#EAAF5A")
+ let a = SpaceColorWheel.hsb(swatch[0]), b = SpaceColorWheel.hsb(swatch[1])
+ #expect(abs(a.brightness - b.brightness) < 0.06)
if a.saturation > 0.05 {
let turn = (b.hue - a.hue + 360).truncatingRemainder(dividingBy: 360)
- #expect(abs(turn - SpaceColorWheel.spread) < 2)
+ #expect(turn > 25 && turn < 50)
}
}
diff --git a/Sources/Cra/UI/Windows/MainWindowController+SpaceMenu.swift b/Sources/Cra/UI/Windows/MainWindowController+SpaceMenu.swift
index 1da91cd..33fbe4c 100644
--- a/Sources/Cra/UI/Windows/MainWindowController+SpaceMenu.swift
+++ b/Sources/Cra/UI/Windows/MainWindowController+SpaceMenu.swift
@@ -32,8 +32,8 @@ extension MainWindowController {
}
/// Edit Theme Color…: Arc's editor in a panel against the sidebar's edge at the window's top.
- /// Every change shows in the space at once but is written only when the editor commits, as in
- /// Arc: a click anywhere else keeps it, Escape puts the stored theme back.
+ /// Every change shows in the space at once but is written only when the editor closes, as in
+ /// Arc (offline Arc 1.171: StorableSidebar.json changed on Escape, not on the swatch press).
func showSpaceStyleEditor(space: Space, beside anchor: NSView? = nil) {
guard let window else { return }
if let open = window.childWindows?.first(where: { $0 is StyleEditorPanel }) { open.close() }
@@ -44,8 +44,8 @@ extension MainWindowController {
// From a Spaces page card Arc puts it flush with the card's right edge.
let x = (anchor.flatMap { v in v.window.map { $0.convertToScreen(v.convert(v.bounds, to: nil)).maxX } }
?? window.frame.minX + (shell.sidebarVisible ? shell.sidebarWidth : 0)).rounded()
- let panel = StyleEditorPanel(contentRect: NSRect(x: x, y: window.frame.maxY - size.height, width: size.width, height: size.height)) { keep in
- store.endThemePreview(forSpace: id, keep: keep)
+ let panel = StyleEditorPanel(contentRect: NSRect(x: x, y: window.frame.maxY - size.height, width: size.width, height: size.height)) {
+ store.endThemePreview(forSpace: id, keep: true)
}
let host = NSHostingView(rootView: editor.shadow(color: .black.opacity(0.3), radius: 10, y: 4)
.padding(.top, 12).padding(.horizontal, 13.5).padding(.bottom, 19))
@@ -99,16 +99,16 @@ extension MainWindowController {
func showManageSpaces() { showLibrary(.spaces) }
}
-/// The theme editor's window: borderless and see-through around its card. Escape closes it and
-/// drops the change; a click anywhere else in the app, or the app going to the background,
-/// closes it and keeps the change.
+/// The theme editor's window: borderless and see-through around its card. Escape, a click anywhere
+/// else in the app, the app going to the background or the browser window closing closes it and
+/// keeps the change, as Arc's editor does.
final class StyleEditorPanel: NSPanel {
private var monitor: Any?
private var resignObserver: Any?
private var parentObserver: Any?
- private var onClose: ((Bool) -> Void)?
+ private var onClose: (() -> Void)?
- init(contentRect: NSRect, onClose: @escaping (_ keep: Bool) -> Void) {
+ init(contentRect: NSRect, onClose: @escaping () -> Void) {
self.onClose = onClose
super.init(contentRect: contentRect, styleMask: [.borderless, .nonactivatingPanel], backing: .buffered, defer: false)
isOpaque = false
@@ -120,38 +120,33 @@ final class StyleEditorPanel: NSPanel {
if e.type == .keyDown {
// Escape closes it wherever the key goes (SwiftUI keeps it from cancelOperation).
guard e.keyCode == 53 else { return e }
- self.close(keep: false)
+ self.close()
return nil
}
- if e.window !== self { self.close(keep: true) }
+ if e.window !== self { self.close() }
return e
}
resignObserver = NotificationCenter.default.addObserver(forName: NSApplication.didResignActiveNotification, object: nil,
queue: .main) { [weak self] _ in
- MainActor.assumeIsolated { self?.close(keep: true) }
+ MainActor.assumeIsolated { self?.close() }
}
// The browser window closing under it commits too.
parentObserver = NotificationCenter.default.addObserver(forName: NSWindow.willCloseNotification, object: nil,
queue: .main) { [weak self] note in
MainActor.assumeIsolated {
guard let self, let w = note.object as? NSWindow, w === self.parent else { return }
- self.close(keep: true)
+ self.close()
}
}
}
override var canBecomeKey: Bool { true }
- override func cancelOperation(_ sender: Any?) { close(keep: false) }
+ override func cancelOperation(_ sender: Any?) { close() }
- func close(keep: Bool) {
+ override func close() {
let done = onClose
onClose = nil
- done?(keep)
- close()
- }
-
- override func close() {
- if onClose != nil { close(keep: true); return }
+ done?()
if let monitor { NSEvent.removeMonitor(monitor) }
monitor = nil
if let resignObserver { NotificationCenter.default.removeObserver(resignObserver) }
diff --git a/docs/arc-reverse-engineering.md b/docs/arc-reverse-engineering.md
index 5a8f8cd..e52caf2 100644
--- a/docs/arc-reverse-engineering.md
+++ b/docs/arc-reverse-engineering.md
@@ -2771,16 +2771,26 @@ that waits 3 s before answering and then serves a page whose image takes 5 s.
"Move to previous preset page." / "Move to next preset page." (`didTapPreviousPresetPage`, `presetCount`,
`currentPresetPage`, defaults `currentThemeEditorPresetPage`). The editor state has an `undoStack` and a
`didKeyDownEscape` action.
-- [O reporter, #170] Five pages: bright singles, bright pairs, pastels, muted pairs, greys (Brand, Brand +
- complement, Pastel, Drab + complement, Greyscale).
-- Cra: SpaceColorPresets (CraCore) holds the colours and pages; a pair is the colour and the pad's +40° colour
+- [O live] Offline Arc, Spaces ▸ Edit Theme… over AX: all 45 swatches stay in the AX tree whatever page shows, in
+ page order Brand, Brand, Pastel, Drab, Greyscale; the labels read "Set space color to Catalog color:
+ #$assets-arcclients.BaseAssets.resources ColorPickerBrand4" (Pastel, Drab, Greyscale come from
+ `arc.SpaceStyleEditor.resources`). Captures: page 2 is the Brand colours as two-colour gradients, page 4 Drab as
+ single colours (not pairs, as #170 guessed from screenshots).
+- [O live] A page-1 swatch (Brand4) changes the space at once without writing StorableSidebar.json; Escape closes the
+ editor and writes it, keeping the change: one `single` vibrant light `blendedSingleColor` (0.949, 0.369, 0.420),
+ intensity 0.8, noise 0. Closing by deactivating Arc writes it the same way.
+- [O live] A page-2 swatch is saved as a `blendedGradient` with an `analogous` wheel: `baseColors` = [the Brand
+ colour, a second one], `overlayColors` = [clear, a third one the other way round the wheel], vibrant light,
+ intensity 0.8. The second colours for Brand1–9: #EFF1E3 #EFB19B #A6727F #EAAF5A #F0E941 #A4F454 #38E5E7 #7F7EDC
+ #7F6589 (29–46° on in HSB hue, about the same saturation and brightness); Brand9's pair is a `dark` one. The
+ turn isn't one fixed angle in HSB, OKLCH or Lab, so Cra keeps Arc's values (SpaceColorPresets.brandPairs).
+- Cra: SpaceColorPresets (CraCore) holds the colours and pages; a pair is the colour and its complement
(SpaceColorWheel.complement). One colour is saved as Arc's one-dot `single` theme (SpaceTheme.solid, on the side
the colour suits); two or three as before. The Edit Space sheet shows the same card as Edit Theme Color…, and
the list's right-click menu starts with Change Space Icon…, Rename Space…, Edit Theme Color… like the header's.
- Both preview every change without writing it (SidebarStore.previewTheme); Save, or a click outside the card,
- writes it, Cancel or Escape put the stored theme back.
-- [?] Not checked live yet: the exact complement Arc adds for a pair, and whether Escape in Arc's editor reverts
- (Cra reverts, as Victor chose on #170).
+ Both preview every change without writing it (SidebarStore.previewTheme). Edit Theme Color… writes it when it
+ closes (Escape, a click elsewhere, the app deactivating), as Arc does; the sheet writes it on Save and puts the
+ stored theme back on Cancel.
## Little Arc: Copy URL and Shift-click (Arc 1.171, 3 Nov 2026, X DM, offline Arc)