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.

Space colour is Arc's picker everywhere: Arc's 45 presets, one colour by default, previewed live and written on Save (#170)

Victor8971f107af9a
diff --git a/Packages/CraCore/Sources/CraCore/SpaceColorPresets.swift b/Packages/CraCore/Sources/CraCore/SpaceColorPresets.swift
new file mode 100644
index 0000000..c06bc63
--- /dev/null
+++ b/Packages/CraCore/Sources/CraCore/SpaceColorPresets.swift
@@ -0,0 +1,98 @@
+import Foundation
+
+/// The theme editor's preset swatches (Arc 1.171: SpaceStyleEditor's preset pages). Arc's colours
+/// 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`).
+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"]
+
+ /// One page of nine: a catalog group, alone or with each colour's complement.
+ 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
+
+ /// 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.
+ public var swatches: [[String]] {
+ colors.map { complementary ? [$0, SpaceColorWheel.complement(of: $0)] : [$0] }
+ }
+ }
+
+ /// Arc's five pages: bright singles, bright pairs, pastels, muted pairs, greys.
+ 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),
+ ]
+
+ /// The page that holds a theme's pad colours, so the editor opens where they are; nil when
+ /// they are no preset's.
+ public static func page(of key: [String]) -> Int? {
+ let k = key.map { $0.uppercased() }
+ return pages.firstIndex { $0.swatches.contains(k) }
+ }
+
+ /// A new space's theme: one of Arc's bright colours, one colour on Auto.
+ public static func newSpaceTheme(index: Int = Int.random(in: 0..<9)) -> SpaceTheme {
+ SpaceThemeVariants.theme(key: [brand[index % brand.count]], intensity: 0.8, noise: 0, appearance: "auto")
+ }
+}
+
+/// 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.
+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
+ var h = 0.0
+ if d > 0 {
+ if mx == c.r { h = ((c.g - c.b) / d).truncatingRemainder(dividingBy: 6) }
+ else if mx == c.g { h = (c.b - c.r) / d + 2 }
+ else { h = (c.r - c.g) / d + 4 }
+ h = (h * 60 + 360).truncatingRemainder(dividingBy: 360)
+ }
+ return (h, mx == 0 ? 0 : d / mx, mx)
+ }
+
+ /// `hue` in degrees (any value, wrapped), saturation and brightness 0...1.
+ public static func hex(hue: Double, saturation: Double, brightness: Double) -> String {
+ let h = ((hue.truncatingRemainder(dividingBy: 360)) + 360).truncatingRemainder(dividingBy: 360) / 60
+ let s = max(0, min(1, saturation)), v = max(0, min(1, brightness))
+ let c = v * s, x = c * (1 - abs(h.truncatingRemainder(dividingBy: 2) - 1)), m = v - c
+ let (r, g, b): (Double, Double, Double)
+ switch Int(h) % 6 {
+ case 0: (r, g, b) = (c, x, 0)
+ case 1: (r, g, b) = (x, c, 0)
+ case 2: (r, g, b) = (0, c, x)
+ case 3: (r, g, b) = (0, x, c)
+ case 4: (r, g, b) = (x, 0, c)
+ default: (r, g, b) = (c, 0, x)
+ }
+ func byte(_ v: Double) -> Int { Int(((v + m) * 255).rounded()) }
+ return String(format: "#%02X%02X%02X", byte(r), byte(g), byte(b))
+ }
+}
diff --git a/Packages/CraCore/Sources/CraCore/SpaceThemeVariants.swift b/Packages/CraCore/Sources/CraCore/SpaceThemeVariants.swift
index 69fdb22..5b4f1cf 100644
--- a/Packages/CraCore/Sources/CraCore/SpaceThemeVariants.swift
+++ b/Packages/CraCore/Sources/CraCore/SpaceThemeVariants.swift
@@ -7,6 +7,11 @@ public enum SpaceThemeVariants {
public static func theme(key: [String], intensity: Double, noise: Double, appearance: String) -> SpaceTheme {
var t: SpaceTheme
switch appearance {
+ // One colour on Auto: Arc saves a picked swatch as one `single` theme in that colour, on the
+ // side the colour suits (an imported one reads the same way, ArcThemeImport).
+ case "auto" where key.count == 1:
+ t = SpaceTheme(colors: [key[0], key[0]], intensity: intensity, noise: noise, appearance: "auto", accent: key[0], solid: true)
+ t.appearance = t.isDark ? "dark" : "light"
case "light": t = light(key: key, intensity: intensity, noise: noise)
case "dark": t = dark(key: key, intensity: intensity, noise: noise)
default: t = SpaceTheme(light: light(key: key, intensity: intensity, noise: noise), dark: dark(key: key, intensity: intensity, noise: noise))
@@ -23,11 +28,13 @@ public enum SpaceThemeVariants {
/// The half shown while macOS is light, from the pad's colours: the colours themselves (Arc
/// saves a colour picked in Light as that colour), lifted to Arc's default light half (HSL
- /// lightness 0.9, #8389FF → #C8CAFF) when they would read as a dark theme.
+ /// lightness 0.9, #8389FF → #C8CAFF) when they would read as a dark theme. One colour is Arc's
+ /// one-dot theme (`blendedSingleColor`), a flat fill like an imported one (ArcThemeImport).
public static func light(key: [String], intensity: Double, noise: Double) -> SpaceTheme {
var t = SpaceTheme(colors: key, intensity: intensity, noise: noise, appearance: "auto", accent: key.first)
if t.isDark { t.colors = key.map { shade($0, lightness: 0.9) }; t.accent = t.colors.first }
t.appearance = "light"
+ if t.colors.count == 1 { t.colors.append(t.colors[0]); t.solid = true }
return t
}
@@ -41,7 +48,9 @@ public enum SpaceThemeVariants {
func ch(_ v: Double, _ b: Double) -> Int { Int((v * 255 * 0.27 + b).rounded()) }
return String(format: "#%02X%02X%02X", ch(k.r, 43), ch(k.g, 38), ch(k.b, 50))
}
- return SpaceTheme(colors: colors, intensity: 1, noise: noise, appearance: "dark", accent: base.first)
+ // One colour stays one flat colour, without the gradient a lone stop gets (SpacePalette).
+ return SpaceTheme(colors: colors.count == 1 ? colors + colors : colors, intensity: 1, noise: noise, appearance: "dark",
+ accent: base.first)
}
/// The colour's HSL hue and saturation at another lightness.
diff --git a/Packages/CraCore/Tests/CraCoreTests/ArcThemeImportTests.swift b/Packages/CraCore/Tests/CraCoreTests/ArcThemeImportTests.swift
index 3aa5b7f..6cc6eae 100644
--- a/Packages/CraCore/Tests/CraCoreTests/ArcThemeImportTests.swift
+++ b/Packages/CraCore/Tests/CraCoreTests/ArcThemeImportTests.swift
@@ -206,11 +206,18 @@ struct SpaceThemeAppearanceTests {
guard let a, let x = HexColor.components(a), let y = HexColor.components(b) else { return false }
return max(abs(x.r - y.r), abs(x.g - y.g), abs(x.b - y.b)) * 255 <= 6
}
- let theme = SpaceThemeVariants.theme(key: ["#8389FF"], intensity: 0.5, noise: 0, appearance: "auto")
- #expect(theme.followsSystem && theme.key == ["#8389FF"])
+ let theme = SpaceThemeVariants.theme(key: ["#8389FF", "#FF83C8"], intensity: 0.5, noise: 0, appearance: "auto")
+ #expect(theme.followsSystem && theme.key == ["#8389FF", "#FF83C8"])
let light = theme.resolved(systemDark: false), dark = theme.resolved(systemDark: true)
- #expect(light.colors == ["#8389FF"] && !light.isDark)
+ #expect(light.colors == ["#8389FF", "#FF83C8"] && !light.isDark)
#expect(close(dark.accent, "#01021F") && dark.isDark)
+ // One colour on Auto is Arc's one-dot `single` theme: that colour, flat, on the side it suits (#170).
+ let one = SpaceThemeVariants.theme(key: ["#8389FF"], intensity: 0.5, noise: 0, appearance: "auto")
+ #expect(one.colors == ["#8389FF", "#8389FF"] && one.solid && one.appearance == "light" && one.key == ["#8389FF"])
+ // In Light it is the same flat colour; in Dark one flat colour keeping its hue.
+ #expect(SpaceThemeVariants.theme(key: ["#8389FF"], intensity: 0.5, noise: 0, appearance: "light").solid)
+ let darkOne = SpaceThemeVariants.theme(key: ["#8389FF"], intensity: 0.5, noise: 0, appearance: "dark")
+ #expect(darkOne.isDark && darkOne.colors.count == 2 && darkOne.colors[0] == darkOne.colors[1])
#expect(SpaceThemeVariants.theme(key: ["#8389FF"], intensity: 0.5, noise: 0, appearance: "dark").dark == nil)
// A colour too dark for a light theme is lifted to Arc's default light half.
let lifted = SpaceThemeVariants.light(key: ["#0000F2"], intensity: 0.5, noise: 0)
diff --git a/Packages/CraCore/Tests/CraCoreTests/SpaceColorPresetsTests.swift b/Packages/CraCore/Tests/CraCoreTests/SpaceColorPresetsTests.swift
new file mode 100644
index 0000000..760fab2
--- /dev/null
+++ b/Packages/CraCore/Tests/CraCoreTests/SpaceColorPresetsTests.swift
@@ -0,0 +1,63 @@
+import Testing
+@testable import CraCore
+
+/// The theme editor's presets (#170): Arc's catalog colours on five pages, one colour by default.
+struct SpaceColorPresetsTests {
+ /// Arc's ColorPicker colours as Arc writes them (sRGB): Brand4 is the CloudDev red, Brand8 is
+ /// the 0.4236, 0.7286, 0.8512 Arc saved for a picked swatch.
+ @Test func catalogColours() {
+ for group in [SpaceColorPresets.brand, SpaceColorPresets.drab, SpaceColorPresets.pastel, SpaceColorPresets.greyscale] {
+ #expect(group.count == 9 && Set(group).count == 9)
+ #expect(group.allSatisfy { HexColor.components($0) != nil })
+ }
+ #expect(SpaceColorPresets.brand[3] == "#F25E6B")
+ #expect(SpaceColorPresets.brand[7] == "#6CBAD9")
+ #expect(SpaceColorPresets.greyscale.first == "#FFFFFF" && SpaceColorPresets.greyscale.last == "#000000")
+ }
+
+ /// Five pages of nine with paging; singles put one colour on the pad, pairs two.
+ @Test func pages() {
+ #expect(SpaceColorPresets.pages.count == 5)
+ for page in SpaceColorPresets.pages {
+ #expect(page.swatches.count == 9)
+ #expect(page.swatches.allSatisfy { $0.count == (page.complementary ? 2 : 1) })
+ }
+ }
+
+ /// The editor opens on the page holding the space's colours.
+ @Test func pageOfAKey() {
+ for (i, page) in SpaceColorPresets.pages.enumerated() {
+ for swatch in page.swatches { #expect(SpaceColorPresets.page(of: swatch) == i) }
+ }
+ #expect(SpaceColorPresets.page(of: ["#f25e6b"]) == 0)
+ #expect(SpaceColorPresets.page(of: ["#123456"]) == nil)
+ }
+
+ /// A new space starts on one colour, saved as Arc's one-dot (solid) theme, not a gradient.
+ @Test(arguments: 0..<9)
+ func newSpaceIsOneColour(index: Int) {
+ let theme = SpaceColorPresets.newSpaceTheme(index: index)
+ #expect(theme.key == [SpaceColorPresets.brand[index]])
+ let hex = SpaceColorPresets.brand[index]
+ #expect(theme.solid && theme.colors == [hex, hex] && theme.dark == nil && !theme.followsSystem)
+ #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)
+ if a.saturation > 0.05 {
+ let turn = (b.hue - a.hue + 360).truncatingRemainder(dividingBy: 360)
+ #expect(abs(turn - SpaceColorWheel.spread) < 2)
+ }
+ }
+
+ /// hsb and hex are inverse to the byte.
+ @Test(arguments: SpaceColorPresets.brand + SpaceColorPresets.pastel + SpaceColorPresets.greyscale)
+ func wheelRoundTrips(hex: String) {
+ let w = SpaceColorWheel.hsb(hex)
+ #expect(SpaceColorWheel.hex(hue: w.hue, saturation: w.saturation, brightness: w.brightness) == hex)
+ }
+}
diff --git a/Sources/Cra/Services/SidebarStore.swift b/Sources/Cra/Services/SidebarStore.swift
index 807873d..2e40028 100644
--- a/Sources/Cra/Services/SidebarStore.swift
+++ b/Sources/Cra/Services/SidebarStore.swift
@@ -10,6 +10,9 @@ final class SidebarStore {
// MARK: State
private(set) var spaces: [UUID: Space] = [:]
+ /// The stored theme of a space whose theme an editor is previewing (`previewTheme`): what
+ /// goes to disk until the editor saves, and what Cancel or Escape puts back.
+ @ObservationIgnored private var storedThemes: [UUID: SpaceTheme] = [:]
private(set) var spaceOrder: [UUID] = []
/// Profiles besides Default, in the order they were made.
private(set) var profiles: [BrowserProfile] = []
@@ -621,7 +624,13 @@ final class SidebarStore {
var document: SidebarDocument {
var hidden = Set<UUID>()
for sid in incognitoSpaceIDs { if let s = spaces[sid] { collectSubtree(of: s, into: &hidden) } }
- return SidebarDocument(version: 1, spaceOrder: spaceOrder, spaces: orderedSpaces,
+ // A theme still being previewed goes to disk as it was stored.
+ let saved = storedThemes.isEmpty ? orderedSpaces : orderedSpaces.map { s in
+ var s = s
+ if let t = storedThemes[s.id] { s.theme = t }
+ return s
+ }
+ return SidebarDocument(version: 1, spaceOrder: spaceOrder, spaces: saved,
items: hidden.isEmpty ? Array(items.values) : items.values.filter { !hidden.contains($0.id) },
profiles: profiles, profileFavorites: profileFavorites.isEmpty ? nil : profileFavorites)
}
@@ -1655,10 +1664,31 @@ final class SidebarStore {
func updateSpace(_ space: Space) {
guard spaces[space.id] != nil else { return }
+ storedThemes[space.id] = nil
spaces[space.id] = space
touch()
}
+ /// A theme editor's change: drawn at once wherever the space shows, not written (Arc writes
+ /// StorableSidebar.json when the editor commits). `endThemePreview` keeps or drops it.
+ func previewTheme(_ theme: SpaceTheme, forSpace id: UUID) {
+ guard var s = spaces[id] else { return }
+ if storedThemes[id] == nil { storedThemes[id] = s.theme }
+ s.theme = theme
+ spaces[id] = s
+ }
+
+ /// The editor closed: `keep` writes the previewed theme, otherwise the stored one comes back.
+ func endThemePreview(forSpace id: UUID, keep: Bool) {
+ guard let stored = storedThemes.removeValue(forKey: id), var s = spaces[id] else { return }
+ if keep {
+ if s.theme != stored { touch() }
+ } else if s.theme != stored {
+ s.theme = stored
+ spaces[id] = s
+ }
+ }
+
func deleteSpace(_ id: UUID) {
guard spaceOrder.count > 1, spaceOrder.contains(id), let space = spaces[id] else { return }
// A profile's favorites stay with the profile (Arc).
@@ -1672,6 +1702,7 @@ final class SidebarStore {
items[space.pinnedContainerID] = nil
items[space.todayContainerID] = nil
spaces[id] = nil
+ storedThemes[id] = nil
spaceOrder.removeAll { $0 == id }
var windows = prefs.windows
for i in windows.indices {
diff --git a/Sources/Cra/UI/Sidebar/List/SidebarMenus.swift b/Sources/Cra/UI/Sidebar/List/SidebarMenus.swift
index 2915bb9..439cfa5 100644
--- a/Sources/Cra/UI/Sidebar/List/SidebarMenus.swift
+++ b/Sources/Cra/UI/Sidebar/List/SidebarMenus.swift
@@ -289,6 +289,15 @@ enum SidebarMenus {
let store = list.store, actions = list.actions
let space = list.spaceID
let menu = menu()
+ // Arc's sidebar menu starts with the space's look, as the header's does (#170).
+ if let s = store.space(space) {
+ if let header = list.header, !store.hidesSpaceHeader(space) {
+ add(menu, "Change Space Icon…") { [weak header] in if let header { actions.changeSpaceIcon(s, header) } }
+ add(menu, "Rename Space…") { [weak header] in header?.beginRename() }
+ }
+ add(menu, "Edit Theme Color…") { actions.editSpaceTheme(s) }
+ menu.addItem(.separator())
+ }
add(menu, action: "newTab", "New Tab") { actions.openCommandBar(.newTab) }
add(menu, action: "newFolder") { actions.performAction("newFolder") }
add(menu, action: "newGitHubLiveFolder", enabled: store.liveFolder(.github, inSpace: space) == nil) {
diff --git a/Sources/Cra/UI/Sidebar/List/SpaceColumnView.swift b/Sources/Cra/UI/Sidebar/List/SpaceColumnView.swift
index 6743ac7..ce669fb 100644
--- a/Sources/Cra/UI/Sidebar/List/SpaceColumnView.swift
+++ b/Sources/Cra/UI/Sidebar/List/SpaceColumnView.swift
@@ -29,6 +29,7 @@ final class SpaceColumnView: NSView {
super.init(frame: .zero)
favorites.onHeightChange = { [weak self] animated in self?.relayout(animated: animated) }
header.onHiddenChange = { [weak self] in self?.relayout(animated: true) }
+ list.header = header
addSubview(list)
addSubview(favorites)
addSubview(header)
diff --git a/Sources/Cra/UI/Sidebar/List/SpaceListView.swift b/Sources/Cra/UI/Sidebar/List/SpaceListView.swift
index 58df4ee..1b6c702 100644
--- a/Sources/Cra/UI/Sidebar/List/SpaceListView.swift
+++ b/Sources/Cra/UI/Sidebar/List/SpaceListView.swift
@@ -45,6 +45,8 @@ final class SpaceListView: NSView, NSDraggingSource {
}
let spaceID: UUID
+ /// The column's header: the list's menu opens the icon picker on it and renames there.
+ weak var header: SpaceHeaderView?
let store: SidebarStore
let ui: SidebarUIState
let actions: SidebarActions
diff --git a/Sources/Cra/UI/Windows/MainWindowController+SpaceMenu.swift b/Sources/Cra/UI/Windows/MainWindowController+SpaceMenu.swift
index 774df6e..1da91cd 100644
--- a/Sources/Cra/UI/Windows/MainWindowController+SpaceMenu.swift
+++ b/Sources/Cra/UI/Windows/MainWindowController+SpaceMenu.swift
@@ -7,7 +7,6 @@ extension MainWindowController {
func showSpaceIconPicker(space: Space, anchor: NSView) {
let popover = NSPopover()
popover.behavior = .transient
- popover.appearance = NSAppearance(named: space.theme.palette.isDark ? .darkAqua : .aqua)
let id = space.id, store = self.store
let set: (String, String?) -> Void = { [weak popover] emoji, symbol in
guard var s = store.space(id) else { return }
@@ -32,23 +31,22 @@ extension MainWindowController {
popover.show(relativeTo: rect, of: content, preferredEdge: content.isFlipped ? .maxY : .minY)
}
- /// Edit Theme Color…: Arc's editor in a panel against the sidebar's edge at the window's top,
- /// applying every change at once. Escape or a click outside closes it.
+ /// 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.
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() }
let store = self.store, id = space.id
- let editor = SpaceStyleEditor(theme: space.theme) { theme in
- guard var s = store.space(id) else { return }
- s.theme = theme
- store.updateSpace(s)
- }
+ let editor = SpaceStyleEditor(theme: space.theme) { theme in store.previewTheme(theme, forSpace: id) }
// The card sits 12 pt into its 382 × 534 pt window (19 pt above the bottom), room for the shadow.
let size = NSSize(width: 382, height: 534)
// 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))
+ 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 host = NSHostingView(rootView: editor.shadow(color: .black.opacity(0.3), radius: 10, y: 4)
.padding(.top, 12).padding(.horizontal, 13.5).padding(.bottom, 19))
host.sizingOptions = []
@@ -56,6 +54,7 @@ extension MainWindowController {
window.addChildWindow(panel, ordered: .above)
panel.makeKeyAndOrderFront(nil)
}
+
/// Set Profile ▸ New Profile…: Arc's dialog over the dimmed window; Next asks which spaces use
/// the profile (this one ticked) and Create Profile moves them into it (pages already open
/// reload in it, BrowserManager).
@@ -100,12 +99,17 @@ extension MainWindowController {
func showManageSpaces() { showLibrary(.spaces) }
}
-/// The theme editor's window: borderless and see-through around its card; closes on Escape or a
-/// click anywhere else in the app.
+/// 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.
final class StyleEditorPanel: NSPanel {
private var monitor: Any?
+ private var resignObserver: Any?
+ private var parentObserver: Any?
+ private var onClose: ((Bool) -> Void)?
- init(contentRect: NSRect) {
+ init(contentRect: NSRect, onClose: @escaping (_ keep: Bool) -> Void) {
+ self.onClose = onClose
super.init(contentRect: contentRect, styleMask: [.borderless, .nonactivatingPanel], backing: .buffered, defer: false)
isOpaque = false
backgroundColor = .clear
@@ -116,20 +120,44 @@ 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()
+ self.close(keep: false)
return nil
}
- if e.window !== self { self.close() }
+ if e.window !== self { self.close(keep: true) }
return e
}
+ resignObserver = NotificationCenter.default.addObserver(forName: NSApplication.didResignActiveNotification, object: nil,
+ queue: .main) { [weak self] _ in
+ MainActor.assumeIsolated { self?.close(keep: true) }
+ }
+ // 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)
+ }
+ }
}
override var canBecomeKey: Bool { true }
- override func cancelOperation(_ sender: Any?) { close() }
+ override func cancelOperation(_ sender: Any?) { close(keep: false) }
+
+ func close(keep: Bool) {
+ let done = onClose
+ onClose = nil
+ done?(keep)
+ close()
+ }
override func close() {
+ if onClose != nil { close(keep: true); return }
if let monitor { NSEvent.removeMonitor(monitor) }
monitor = nil
+ if let resignObserver { NotificationCenter.default.removeObserver(resignObserver) }
+ resignObserver = nil
+ if let parentObserver { NotificationCenter.default.removeObserver(parentObserver) }
+ parentObserver = nil
parent?.removeChildWindow(self)
super.close()
}
diff --git a/Sources/Cra/UI/Windows/MainWindowController.swift b/Sources/Cra/UI/Windows/MainWindowController.swift
index b61b1ce..128ec0f 100644
--- a/Sources/Cra/UI/Windows/MainWindowController.swift
+++ b/Sources/Cra/UI/Windows/MainWindowController.swift
@@ -2551,28 +2551,36 @@ final class MainWindowController: NSWindowController, NSWindowDelegate, BrowserM
func showSpaceEditor(space: Space?) {
guard let window else { return }
- let panel = NSPanel(contentRect: NSRect(x: 0, y: 0, width: 520, height: 520), styleMask: [.titled], backing: .buffered, defer: false)
+ let panel = NSPanel(contentRect: NSRect(x: 0, y: 0, width: 651, height: 600), styleMask: [.titled], backing: .buffered, defer: false)
// Arc's New Space starts on the profile of the space it was opened from.
let initialProfile = space == nil && !isIncognito ? SpaceProfiles.forNewSpace(from: store.focusedSpace, profiles: store.profiles) : nil
- let view = SpaceEditorView(existing: space, profiles: store.profiles, initialProfile: initialProfile, onSave: { [weak self, weak panel] title, emoji, theme, profile, newName in
- guard let self else { return }
+ let store = self.store
+ let view = SpaceEditorView(existing: space, profiles: store.profiles, initialProfile: initialProfile, onSave: { [weak panel] title, emoji, theme, profile, newName in
let id: UUID
- if var s = space {
+ if let sid = space?.id, var s = store.space(sid) {
s.title = title; s.emoji = emoji; s.theme = theme
- self.store.updateSpace(s)
+ store.updateSpace(s)
id = s.id
} else {
- id = self.store.createSpace(title: title, emoji: emoji, theme: theme).id
+ id = store.createSpace(title: title, emoji: emoji, theme: theme).id
}
switch profile {
- case .existing(let p): self.store.setProfile(p, forSpace: id)
- case .new: self.store.setProfile(self.store.createProfile(name: newName).id, forSpace: id)
+ case .existing(let p): store.setProfile(p, forSpace: id)
+ case .new: store.setProfile(store.createProfile(name: newName).id, forSpace: id)
}
if let panel { window.endSheet(panel) }
- }, onCancel: { [weak panel] in if let panel { window.endSheet(panel) } })
+ }, onCancel: { [weak panel] in if let panel { window.endSheet(panel) } }, onPreview: { theme in
+ // A new space has nothing to draw on yet; the sheet's own preview shows it.
+ if let sid = space?.id { store.previewTheme(theme, forSpace: sid) }
+ })
panel.contentView = NSHostingView(rootView: view)
spaceEditor = panel
- window.beginSheet(panel) { [weak self] _ in self?.spaceEditor = nil }
+ window.beginSheet(panel) { [weak self] _ in
+ // Closed without Save (Cancel, Escape, cra://dismiss): the stored theme comes back.
+ // Save already wrote it, so this does nothing then.
+ if let sid = space?.id { store.endThemePreview(forSpace: sid, keep: false) }
+ self?.spaceEditor = nil
+ }
}
/// Dia-style import window (UI/Onboarding): browser, spaces, extensions, progress.
diff --git a/Sources/Cra/UI/Windows/SpaceEditorView.swift b/Sources/Cra/UI/Windows/SpaceEditorView.swift
index 907f4f3..136b602 100644
--- a/Sources/Cra/UI/Windows/SpaceEditorView.swift
+++ b/Sources/Cra/UI/Windows/SpaceEditorView.swift
@@ -6,20 +6,20 @@ enum SpaceProfileChoice: Hashable {
case new
}
-/// Create or edit a space: name, emoji, colors, intensity, grain, appearance, profile
-/// (Arc: SpaceCreation + SpaceStyleEditor + SpaceIconPicker + "Edit Space profile").
+/// Create or edit a space: name, emoji, profile and, beside them, Arc's theme editor (the same
+/// card Edit Theme Color… opens: pad, presets, intensity, grain, Auto / Light / Dark). An existing
+/// space shows each change at once (`onPreview`); Cancel puts its theme back, Save writes it.
struct SpaceEditorView: View {
let existing: Space?
let profiles: [BrowserProfile]
/// Title, emoji, theme, profile; a new profile comes with its name.
let onSave: (String, String, SpaceTheme, SpaceProfileChoice, String) -> Void
let onCancel: () -> Void
+ let onPreview: (SpaceTheme) -> Void
@State private var title: String
@State private var emoji: String
@State private var theme: SpaceTheme
- @State private var color1: Color
- @State private var color2: Color
@State private var profile: SpaceProfileChoice
@State private var newProfileName = ""
@@ -28,38 +28,25 @@ struct SpaceEditorView: View {
/// `initialProfile` is a new space's starting profile (Arc: the focused space's).
init(existing: Space?, profiles: [BrowserProfile], initialProfile: UUID? = nil,
- onSave: @escaping (String, String, SpaceTheme, SpaceProfileChoice, String) -> Void, onCancel: @escaping () -> Void) {
+ onSave: @escaping (String, String, SpaceTheme, SpaceProfileChoice, String) -> Void, onCancel: @escaping () -> Void,
+ onPreview: @escaping (SpaceTheme) -> Void = { _ in }) {
self.existing = existing
self.profiles = profiles
_profile = State(initialValue: .existing(existing == nil ? initialProfile : existing?.profileID))
self.onSave = onSave
self.onCancel = onCancel
- let t = existing?.theme ?? SpaceTheme.presets[Int.random(in: 0..<5)]
+ self.onPreview = onPreview
_title = State(initialValue: existing?.title ?? "")
_emoji = State(initialValue: existing?.emoji ?? "🌱")
- _theme = State(initialValue: t)
- _color1 = State(initialValue: Color(hex: t.colors.first ?? "#CCCCCC"))
- _color2 = State(initialValue: Color(hex: t.colors.count > 1 ? t.colors[1] : (t.colors.first ?? "#CCCCCC")))
+ _theme = State(initialValue: existing?.theme ?? SpaceColorPresets.newSpaceTheme())
}
var body: some View {
VStack(spacing: 16) {
Text(existing == nil ? "New Space" : "Edit Space").font(.system(size: 16, weight: .semibold))
- HStack(spacing: 12) {
- // Preview
- ZStack {
- SpaceBackground(palette: theme.palette)
- VStack(spacing: 6) {
- Text(emoji).font(.system(size: 28))
- Text(title.isEmpty ? "Space" : title).font(.system(size: 13, weight: .semibold)).foregroundStyle(theme.palette.textPrimary)
- RoundedRectangle(cornerRadius: 6).fill(theme.palette.selectedFill).frame(width: 100, height: 22)
- RoundedRectangle(cornerRadius: 6).fill(theme.palette.hoverFill).frame(width: 100, height: 22)
- }
- }
- .frame(width: 180, height: 200)
- .clipShape(RoundedRectangle(cornerRadius: 12, style: .continuous))
-
- VStack(alignment: .leading, spacing: 10) {
+ HStack(alignment: .top, spacing: 16) {
+ VStack(alignment: .leading, spacing: 12) {
+ preview
TextField("Name", text: $title).textFieldStyle(.roundedBorder)
LazyVGrid(columns: Array(repeating: GridItem(.fixed(28), spacing: 4), count: 8), spacing: 4) {
ForEach(Self.emojis, id: \.self) { e in
@@ -73,39 +60,16 @@ struct SpaceEditorView: View {
TextField("", text: $emoji).textFieldStyle(.roundedBorder).frame(width: 50)
.onChange(of: emoji) { _, v in if v.count > 2 { emoji = String(v.suffix(2)) } }
}
+ Divider()
+ profileSection
+ Spacer(minLength: 0)
}
- }
- Divider()
- VStack(alignment: .leading, spacing: 8) {
- HStack(spacing: 6) {
- ForEach(SpaceTheme.presets.indices, id: \.self) { i in
- let p = SpaceTheme.presets[i]
- Circle().fill(p.palette.gradient).frame(width: 26, height: 26)
- .overlay(Circle().strokeBorder(Color.primary.opacity(0.15)))
- .onTapGesture {
- theme = p
- color1 = Color(hex: p.colors[0]); color2 = Color(hex: p.colors[1])
- }
- }
- Spacer()
- ColorPicker("", selection: $color1, supportsOpacity: false).labelsHidden()
- ColorPicker("", selection: $color2, supportsOpacity: false).labelsHidden()
- }
- HStack {
- Text("Intensity").frame(width: 70, alignment: .leading)
- Slider(value: $theme.intensity, in: 0...1)
- }
- HStack {
- Text("Grain").frame(width: 70, alignment: .leading)
- Slider(value: $theme.noise, in: 0...1)
- }
- Picker("Appearance", selection: $theme.appearance) {
- Text("Auto").tag("auto"); Text("Light").tag("light"); Text("Dark").tag("dark")
+ .frame(width: 260)
+ SpaceStyleEditor(theme: theme) { t in
+ theme = t
+ onPreview(t)
}
- .pickerStyle(.segmented)
}
- Divider()
- profileSection
HStack {
Button("Cancel") { onCancel() }.keyboardShortcut(.cancelAction)
Spacer()
@@ -117,9 +81,26 @@ struct SpaceEditorView: View {
}
}
.padding(20)
- .frame(width: 520)
- .onChange(of: color1) { _, c in theme.colors = [c.hexString, color2.hexString] }
- .onChange(of: color2) { _, c in theme.colors = [color1.hexString, c.hexString] }
+ .frame(width: 651)
+ }
+
+ /// The space as the sidebar draws it, with the theme being edited.
+ private var preview: some View {
+ ZStack {
+ SpaceBackground(palette: theme.palette)
+ VStack(spacing: 6) {
+ HStack(spacing: 6) {
+ Text(emoji).font(.system(size: 15))
+ Text(title.isEmpty ? "Space" : title).font(.system(size: 13, weight: .semibold)).foregroundStyle(theme.palette.textPrimary)
+ Spacer(minLength: 0)
+ }
+ RoundedRectangle(cornerRadius: 6).fill(theme.palette.selectedFill).frame(height: 24)
+ RoundedRectangle(cornerRadius: 6).fill(theme.palette.hoverFill).frame(height: 24)
+ }
+ .padding(12)
+ }
+ .frame(width: 260, height: 104)
+ .clipShape(RoundedRectangle(cornerRadius: 12, style: .continuous))
}
private var trimmedProfileName: String { newProfileName.trimmingCharacters(in: .whitespaces) }
@@ -128,14 +109,13 @@ struct SpaceEditorView: View {
/// changes profile, "Each Profile has different browser data…".
private var profileSection: some View {
VStack(alignment: .leading, spacing: 6) {
- HStack {
+ VStack(alignment: .leading, spacing: 6) {
Picker("Profile", selection: $profile) {
Text("Default").tag(SpaceProfileChoice.existing(nil))
ForEach(profiles) { p in Text(p.name).tag(SpaceProfileChoice.existing(p.id)) }
Divider()
Text("New Profile…").tag(SpaceProfileChoice.new)
}
- .frame(width: 260)
if profile == .new {
TextField("Profile name", text: $newProfileName).textFieldStyle(.roundedBorder)
}
diff --git a/Sources/Cra/UI/Windows/SpaceStyleEditor.swift b/Sources/Cra/UI/Windows/SpaceStyleEditor.swift
index 95a61ab..3595263 100644
--- a/Sources/Cra/UI/Windows/SpaceStyleEditor.swift
+++ b/Sources/Cra/UI/Windows/SpaceStyleEditor.swift
@@ -2,13 +2,15 @@ import AppKit
import SwiftUI
/// Arc 1.171's theme editor (SpaceStyleEditor), which Edit Theme Color… opens beside the
-/// sidebar. Measured from 2x captures of an offline Arc (1 Nov): a 355 × 503 pt panel, the window
-/// behind it darkened by ~58%; a 340 pt dotted colour pad with Auto / Light / Dark on top and − / +
-/// (one to three colours) at the bottom; nine swatches between paging arrows (single colours, then
-/// two-colour gradients); a wave slider for the intensity and a dotted dial for the grain. Every
-/// change shows in the space at once. Like Arc's editor state it keeps the pad's colours, the
-/// intensity, the grain and Auto / Light / Dark, and builds the theme from them: Auto gets a light
-/// and a dark half and follows macOS, Light and Dark get one (SpaceThemeVariants).
+/// sidebar and the Edit Space sheet shows inline. Measured from 2x captures of an offline Arc
+/// (1 Nov): a 355 × 503 pt card, the window behind it darkened by ~58%; a 340 pt dotted colour pad
+/// with Auto / Light / Dark on top and − / + (one to three colours) at the bottom; nine swatches
+/// between paging arrows, five pages of Arc's catalog colours (SpaceColorPresets); a wave slider
+/// for the intensity and a dotted dial for the grain. Every change goes to `onChange` at once (the
+/// caller previews it); nothing here writes. Like Arc's editor state it keeps the pad's colours,
+/// the intensity, the grain and Auto / Light / Dark, and builds the theme from them
+/// (SpaceThemeVariants): one colour is Arc's one-dot theme, two or three a gradient whose Auto
+/// gets a light and a dark half.
struct SpaceStyleEditor: View {
@State private var theme: SpaceTheme
@State private var pad: PadState
@@ -16,17 +18,18 @@ struct SpaceStyleEditor: View {
init(theme: SpaceTheme, onChange: @escaping (SpaceTheme) -> Void) {
_theme = State(initialValue: theme)
- _pad = State(initialValue: PadState(key: theme.key ?? theme.colors, intensity: theme.intensity, noise: theme.noise,
- appearance: theme.appearance))
+ // A one-colour theme stores its colour twice (a flat fill): one handle on the pad.
+ let key = theme.key ?? (theme.solid || Set(theme.colors).count == 1 ? Array(theme.colors.prefix(1)) : theme.colors)
+ _pad = State(initialValue: PadState(key: key, intensity: theme.intensity, noise: theme.noise, appearance: theme.appearance))
+ // The page with the space's colour, else the one shown last (Arc: currentThemeEditorPresetPage).
+ let last = UserDefaults.standard.integer(forKey: Self.pageKey)
+ _swatchPage = State(initialValue: SpaceColorPresets.page(of: key)
+ ?? (SpaceColorPresets.pages.indices.contains(last) ? last : 0))
self.onChange = onChange
}
- static let swatchPages: [[[String]]] = [
- ["#F1EAE5", "#E69FBA", "#9E749B", "#E1686F", "#EF8C62", "#F2D66D", "#73E59C", "#7FB8D6", "#666786"].map { [$0] },
- [["#DCD2CF", "#C6BBBC"], ["#D397A2", "#BC89A8"], ["#976B86", "#7D617C"], ["#D07E6A", "#BA7087"], ["#DDA361", "#C88274"],
- ["#CACB6A", "#BB8F61"], ["#71CAAD", "#76B789"], ["#7B8FC2", "#7093A3"], ["#6F5F7F", "#646172"]],
- ]
- @State private var swatchPage = 0
+ private static let pageKey = "themeEditorPresetPage"
+ @State private var swatchPage: Int
var body: some View {
VStack(spacing: 0) {
@@ -34,17 +37,23 @@ struct SpaceStyleEditor: View {
.frame(width: 340, height: 340)
.padding(.top, 9)
HStack(spacing: 0) {
- pageArrow("chevron.left", to: swatchPage - 1)
+ pageArrow("chevron.left", to: swatchPage - 1, label: "Move to previous preset page.")
HStack(spacing: 5.5) {
- ForEach(Self.swatchPages[swatchPage], id: \.self) { colors in
+ let page = SpaceColorPresets.pages[swatchPage]
+ ForEach(Array(page.swatches.enumerated()), id: \.offset) { i, colors in
Circle()
.fill(LinearGradient(colors: colors.map { Color(hex: $0) }, startPoint: .topLeading, endPoint: .bottomTrailing))
.frame(width: 24, height: 24)
.contentShape(Circle())
.onTapGesture { pad.key = colors }
+ // Arc: "Set space color to Catalog color: … ColorPickerBrandN".
+ .accessibilityElement()
+ .accessibilityAddTraits(.isButton)
+ .accessibilityLabel("Set space color to \(page.name(i))")
+ .accessibilityAction { pad.key = colors }
}
}
- pageArrow("chevron.right", to: swatchPage + 1)
+ pageArrow("chevron.right", to: swatchPage + 1, label: "Move to next preset page.")
}
.padding(.top, 16.75)
HStack(spacing: 0) {
@@ -75,13 +84,18 @@ struct SpaceStyleEditor: View {
}
}
- private func pageArrow(_ symbol: String, to page: Int) -> some View {
- let ok = Self.swatchPages.indices.contains(page)
- return Button { if ok { swatchPage = page } } label: {
+ private func pageArrow(_ symbol: String, to page: Int, label: String) -> some View {
+ let ok = SpaceColorPresets.pages.indices.contains(page)
+ return Button {
+ guard ok else { return }
+ swatchPage = page
+ UserDefaults.standard.set(page, forKey: Self.pageKey)
+ } label: {
Image(systemName: symbol).font(.system(size: 15, weight: .medium)).frame(width: 36, height: 30)
}
.buttonStyle(.plain)
.foregroundStyle(.white.opacity(ok ? 0.55 : 0.2))
+ .accessibilityLabel(label)
}
}
@@ -100,7 +114,6 @@ struct PadState: Equatable {
private struct ColorPad: View {
@Binding var pad: PadState
private static let reach: CGFloat = 153
- private static let spread: CGFloat = 40
var body: some View {
GeometryReader { geo in
@@ -173,16 +186,15 @@ private struct ColorPad: View {
pad.key.append(Self.hex(hue: h + Self.offset(pad.key.count), saturation: s))
}
- private static func offset(_ i: Int) -> CGFloat { i == 0 ? 0 : (i == 1 ? spread : -spread) }
+ private static func offset(_ i: Int) -> CGFloat { CGFloat(SpaceColorWheel.offset(i)) }
private static func hex(hue: CGFloat, saturation: CGFloat) -> String {
- let h = (hue.truncatingRemainder(dividingBy: 360) + 360).truncatingRemainder(dividingBy: 360) / 360
- return Color(nsColor: NSColor(hue: h, saturation: saturation, brightness: 0.95, alpha: 1)).hexString
+ SpaceColorWheel.hex(hue: Double(hue), saturation: Double(saturation), brightness: 0.95)
}
private static func wheel(_ hex: String) -> (CGFloat, CGFloat) {
- let c = NSColor(Color(hex: hex)).usingColorSpace(.sRGB) ?? .gray
- return (c.hueComponent * 360, c.saturationComponent)
+ let w = SpaceColorWheel.hsb(hex)
+ return (CGFloat(w.hue), CGFloat(w.saturation))
}
static func point(for hex: String, centre c: CGPoint) -> CGPoint {
diff --git a/Tests/StoreTests.swift b/Tests/StoreTests.swift
index 2902a90..58b9544 100644
--- a/Tests/StoreTests.swift
+++ b/Tests/StoreTests.swift
@@ -34,6 +34,7 @@ enum StoreTests {
closeSuccessor()
favoritesEmptyState()
sharedFavorites()
+ themePreview()
print("Store: \(checks) checks passed")
}
@@ -363,6 +364,41 @@ enum StoreTests {
expect(store.integrityProblems().isEmpty, "and the sidebar stays sound")
}
+ /// The theme editor (#170): a change shows at once but goes to disk only when the editor
+ /// commits; Escape or Cancel puts the stored theme back, and a save in between keeps it off disk.
+ @MainActor
+ private static func themePreview() {
+ let store = AppComposition(clock: ManualScheduler()).store
+ let id = store.focusedSpace.id, stored = store.focusedSpace.theme
+ let red = SpaceThemeVariants.theme(key: ["#F25E6B"], intensity: 0.8, noise: 0, appearance: "light")
+ func savedTheme() -> SpaceTheme? {
+ store.save()
+ Thread.sleep(forTimeInterval: 2.5)
+ let d = JSONDecoder()
+ d.dateDecodingStrategy = .iso8601
+ let doc = try? d.decode(SidebarDocument.self, from: Data(contentsOf: AppPaths.file("sidebar.json")))
+ return doc?.spaces.first { $0.id == id }?.theme
+ }
+ store.previewTheme(red, forSpace: id)
+ expect(store.space(id)?.theme == red, "a previewed theme shows at once")
+ store.rename(store.createTab(url: "https://example.com/during").id, to: "During")
+ expect(savedTheme() == stored, "a save while the editor is open writes the stored theme")
+ store.endThemePreview(forSpace: id, keep: false)
+ expect(store.space(id)?.theme == stored, "Escape puts the stored theme back")
+ let blue = SpaceThemeVariants.theme(key: ["#6CBAD9"], intensity: 0.8, noise: 0, appearance: "light")
+ store.previewTheme(red, forSpace: id)
+ store.previewTheme(blue, forSpace: id)
+ store.endThemePreview(forSpace: id, keep: false)
+ expect(store.space(id)?.theme == stored, "several changes undo to the theme from before the editor opened")
+ store.previewTheme(blue, forSpace: id)
+ store.endThemePreview(forSpace: id, keep: true)
+ expect(store.space(id)?.theme == blue && savedTheme() == blue, "a commit keeps the theme and writes it")
+ store.previewTheme(red, forSpace: id)
+ if var s = store.space(id) { s.title = "Saved"; s.theme = red; store.updateSpace(s) }
+ store.endThemePreview(forSpace: id, keep: false)
+ expect(store.space(id)?.theme == red && savedTheme() == red, "Save in the sheet writes the theme and ends the preview")
+ }
+
/// Edit Pinned URL… (#54, PR #55 by Anoninz): a new pinned URL keeps the item's
/// name, icon, colour and place, and survives a relaunch.
@MainActor
diff --git a/docs/arc-reverse-engineering.md b/docs/arc-reverse-engineering.md
index b7d854b..613dfd2 100644
--- a/docs/arc-reverse-engineering.md
+++ b/docs/arc-reverse-engineering.md
@@ -2743,6 +2743,30 @@ that waits 3 s before answering and then serves a page whose image takes 5 s.
- [?] Not worked out: how Arc's editor maps a picked colour to its halves (the pad's `lightnessRange` and the bias
value). Cra's halves are fitted to Arc's default theme only.
+## The theme editor's presets and commit (Arc 1.171, 4 Nov 2026, issue #170, asset catalog + strings)
+- [O static] The swatches are named colours in `ARCClients_BaseAssets.bundle`'s Assets.car (`assetutil --info`),
+ four groups of nine: ColorPickerBrand1–9, Drab1–9, Pastel1–9, Greyscale1–9, defined in sRGB, extended linear
+ sRGB or Display P3. As sRGB (what Arc writes to StorableSidebar.json; Brand8 saved as 0.4236, 0.7286, 0.8512):
+ Brand #F2EAE4 #F29BBB #A6729D #F25E6B #FF8558 #F8D558 #34E895 #6CBAD9 #666789; Drab #4E3A5A #693558 #8F4042
+ #B16D40 #D7B35D #CDCCA4 #7AA982 #226149 #26456B; Pastel #FEFBFA #FFE9F3 #F1D1EC #FFCBD1 #FFE0D3 #FFF9E5 #DEFDEB
+ #DCF3FC #C5C6E5; Greyscale #FFFFFF #E6E6E6 #CCCCCC #B2B2B2 #808080 #666666 #333333 #1A1A1A #000000. The nine
+ swatches sampled from captures on 1 Nov were these Brand colours as drawn (#E1686F for #F25E6B).
+- [O strings] A swatch is a `colorSet` with `addComplimentary` (the preset view's fields), sent as
+ `didSelectColorSet`; its AX label is "Set space color to Catalog color: … ColorPickerBrandN". The arrows are
+ "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
+ (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).
+
## Little Arc: Copy URL and Shift-click (Arc 1.171, 3 Nov 2026, X DM, offline Arc)
An offline Arc (fake home, no network) with a Little Arc on a file:// page, ⇧⌘C and a Shift-click sent as HID