importFoundation// The theme a database wears, through the boundary: read off the database's// catalogue (`definitions.catalogue`, `DefinitionCatalogues`) and// `definitions.saveTheme` written (design note 26203e21 §6). The row is// handed over as its JSON, because what a row MEANS — families, faces,// palettes — is CottonUI's `Theme.decode`, and this side only carries it./// The theme the shown database wears, as the core answered it.publicstructWornTheme: Sendable, Equatable {/// The row, as JSON — the database's own, or the shipped `paper`.publiclet definition: Data/// Why a row stored here was not drawn, or which family was not.publiclet passedOver: String?/// Whether the row is the database's own (`drawn: "row"`) rather than/// the shipped default (`drawn: "default"`) — what a business flavour's/// look gives way to (`FlavourLook`). An answer that does not say is the/// database's own, so a look never covers a row it cannot tell apart.publiclet own: Boolpublicinit(definition: Data, passedOver: String? = nil, own: Bool = true) {self.definition = definitionself.passedOver = passedOverself.own = own }/// The core's word for the shipped default (`presentation::Drawn`).publicstaticlet defaultDrawn = "default"}publicprotocolThemesCalling: Sendable {/// What the shown database wears.func theme() asyncthrows -> WornTheme/// Wear `definition` (a theme row's JSON) as the database's own row.func save(_ definition: Data) asyncthrows -> ActAnswer/// Take a saved theme back.func takeBack(_ undo: ActUndo) asyncthrows -> ActAnswer}/// The core's own answers.publicstructCoreThemes: ThemesCalling {privatelet core: any CottonCallingpublicinit(core: any CottonCalling) {self.core = core }publicfunc theme() asyncthrows -> WornTheme {tryawaitDefinitionCatalogues.shared.catalogue(core).theme }publicfunc save(_ definition: Data) asyncthrows -> ActAnswer {let row = try JSONDecoder().decode(JSONValue.self, from: definition)defer { DefinitionCatalogues.shared.invalidate(core) }returntryawait core.pageAct(CottonMethod.definitionsSaveTheme, Save(definition: row)) }publicfunc takeBack(_ undo: ActUndo) asyncthrows -> ActAnswer {defer { DefinitionCatalogues.shared.invalidate(core) }returntryawait core.takeBack(undo) }privatestructSave: Encodable { let definition: JSONValue }}