Cotton code
308 lines · 14.5 KB · SwiftRaw
// GENERATED by pnpm gen:swift-definitions. Never hand-edit.// Inputs: Rust serde types under cotton-core/src/definitions and cotton-rules/src/computed.rs; no product data.// Rust definition type fingerprint: 668aa7aa8f7af1cce6fd728fab23195022658dd5d406f31606f77a5756830377// The look's half (`LOOK_ENUMS`, `LOOK_MODELS`); CottonUI's// `GeneratedDefinitionTypes.swift` holds every other definition type.import Foundation/// A serde_json::Value at the catalogue boundary, including unknown keys.public indirect enum DefinitionJSONValue: Codable, Hashable, Sendable {    case null, bool(Bool), integer(Int64), unsigned(UInt64), number(Double), string(String)    case array([DefinitionJSONValue]), object([String: DefinitionJSONValue])    public init(from decoder: Decoder) throws {        let c = try decoder.singleValueContainer()        if c.decodeNil() { self = .null }        else if let value = try? c.decode(Bool.self) { self = .bool(value) }        else if let value = try? c.decode(Int64.self) { self = .integer(value) }        else if let value = try? c.decode(UInt64.self) { self = .unsigned(value) }        else if let value = try? c.decode(Double.self) { self = .number(value) }        else if let value = try? c.decode(String.self) { self = .string(value) }        else if let value = try? c.decode([DefinitionJSONValue].self) { self = .array(value) }        else { self = .object(try c.decode([String: DefinitionJSONValue].self)) }    }    // JSON numbers have one value regardless of whether a writer spelled an    // integral value with a decimal point. Canonicalize equality/hash without    // rounding a 64-bit integer through Double.    private enum Numeric: Hashable { case signed(Int64), unsigned(UInt64), decimal(Double) }    private var numeric: Numeric? {        switch self {        case .integer(let value): return .signed(value)        case .unsigned(let value): return Int64(exactly: value).map(Numeric.signed) ?? .unsigned(value)        case .number(let value):            if let exact = Int64(exactly: value) { return .signed(exact) }            if let exact = UInt64(exactly: value) { return .unsigned(exact) }            return .decimal(value)        default: return nil        }    }    public static func == (lhs: Self, rhs: Self) -> Bool {        if let a = lhs.numeric, let b = rhs.numeric { return a == b }        switch (lhs, rhs) {        case (.null, .null): return true        case (.bool(let a), .bool(let b)): return a == b        case (.string(let a), .string(let b)): return a == b        case (.array(let a), .array(let b)): return a == b        case (.object(let a), .object(let b)): return a == b        default: return false        }    }    public func hash(into hasher: inout Hasher) {        if let numeric { hasher.combine(2); hasher.combine(numeric); return }        switch self {        case .null: hasher.combine(0)        case .bool(let value): hasher.combine(1); hasher.combine(value)        case .string(let value): hasher.combine(3); hasher.combine(value)        case .array(let value): hasher.combine(4); hasher.combine(value)        case .object(let value): hasher.combine(5); hasher.combine(value)        case .integer, .unsigned, .number: break        }    }    public func encode(to encoder: Encoder) throws {        var c = encoder.singleValueContainer()        switch self {        case .null: try c.encodeNil()        case .bool(let value): try c.encode(value)        case .integer(let value): try c.encode(value)        case .unsigned(let value): try c.encode(value)        case .number(let value): try c.encode(value)        case .string(let value): try c.encode(value)        case .array(let value): try c.encode(value)        case .object(let value): try c.encode(value)        }    }}public struct DefinitionCodingKey: CodingKey {    public let stringValue: String    public var intValue: Int? { nil }    public init(_ value: String) { stringValue = value }    public init?(stringValue: String) { self.stringValue = stringValue }    public init?(intValue: Int) { return nil }}public enum DefinitionCardStock: String, Codable, Hashable, CaseIterable, Sendable {    case cream = "cream"    case sage = "sage"    case rose = "rose"    case slate = "slate"    case tan = "tan"    case grey = "grey"}/// Storage of cotton_core::definitions::ThemeDefinition.public struct DefinitionThemeDefinition: Codable, Hashable, Sendable {    public var formatVersion: Int? = nil    public var id: String? = nil    public var name: String? = nil    public var family: String? = nil    public var description: String? = nil    public var palette: DefinitionThemePalettes? = nil    public var `type`: [String: DefinitionJSONValue]? = nil    public var scale: DefinitionThemeScale? = nil    public var acts: [String: DefinitionJSONValue]? = nil    public var cards: [String: DefinitionJSONValue]? = nil    public var objects: [String: DefinitionJSONValue]? = nil    public var texture: DefinitionThemeTexture? = nil    public var cap: DefinitionThemeCap? = nil    public var baseHash: String? = nil    public var unknown: [String: DefinitionJSONValue] = [:]    public var fallbacks: [String] = []    public init(_generated: Void) {    }    public enum CodingKeys: String, CodingKey, CaseIterable {        case formatVersion = "format_version"        case id = "id"        case name = "name"        case family = "family"        case description = "description"        case palette = "palette"        case `type` = "type"        case scale = "scale"        case acts = "acts"        case cards = "cards"        case objects = "objects"        case texture = "texture"        case cap = "cap"        case baseHash = "base_hash"        case fallbacks = "fallbacks"    }    public init(from decoder: Decoder) throws {        let c = try decoder.container(keyedBy: CodingKeys.self)        formatVersion = try? c.decodeIfPresent(Int.self, forKey: .formatVersion)        id = try? c.decodeIfPresent(String.self, forKey: .id)        name = try? c.decodeIfPresent(String.self, forKey: .name)        family = try? c.decodeIfPresent(String.self, forKey: .family)        description = try? c.decodeIfPresent(String.self, forKey: .description)        palette = try? c.decodeIfPresent(DefinitionThemePalettes.self, forKey: .palette)        `type` = try? c.decodeIfPresent([String: DefinitionJSONValue].self, forKey: .`type`)        scale = try? c.decodeIfPresent(DefinitionThemeScale.self, forKey: .scale)        acts = try? c.decodeIfPresent([String: DefinitionJSONValue].self, forKey: .acts)        cards = try? c.decodeIfPresent([String: DefinitionJSONValue].self, forKey: .cards)        objects = try? c.decodeIfPresent([String: DefinitionJSONValue].self, forKey: .objects)        texture = try? c.decodeIfPresent(DefinitionThemeTexture.self, forKey: .texture)        cap = try? c.decodeIfPresent(DefinitionThemeCap.self, forKey: .cap)        baseHash = try? c.decodeIfPresent(String.self, forKey: .baseHash)        fallbacks = try c.decodeIfPresent([String].self, forKey: .fallbacks) ?? []        let all = try decoder.container(keyedBy: DefinitionCodingKey.self)        let known = Set(CodingKeys.allCases.map(\.rawValue))        for key in all.allKeys where !known.contains(key.stringValue) {            unknown[key.stringValue] = try all.decode(DefinitionJSONValue.self, forKey: key)        }    }    public func encode(to encoder: Encoder) throws {        var c = encoder.container(keyedBy: CodingKeys.self)        try c.encodeIfPresent(formatVersion, forKey: .formatVersion)        try c.encodeIfPresent(id, forKey: .id)        try c.encodeIfPresent(name, forKey: .name)        try c.encodeIfPresent(family, forKey: .family)        try c.encodeIfPresent(description, forKey: .description)        try c.encodeIfPresent(palette, forKey: .palette)        try c.encodeIfPresent(`type`, forKey: .`type`)        try c.encodeIfPresent(scale, forKey: .scale)        try c.encodeIfPresent(acts, forKey: .acts)        try c.encodeIfPresent(cards, forKey: .cards)        try c.encodeIfPresent(objects, forKey: .objects)        try c.encodeIfPresent(texture, forKey: .texture)        try c.encodeIfPresent(cap, forKey: .cap)        try c.encodeIfPresent(baseHash, forKey: .baseHash)        if !fallbacks.isEmpty { try c.encode(fallbacks, forKey: .fallbacks) }        var all = encoder.container(keyedBy: DefinitionCodingKey.self)        let known = Set(CodingKeys.allCases.map(\.rawValue))        for (key, value) in unknown where !known.contains(key) {            try all.encode(value, forKey: DefinitionCodingKey(key))        }    }}/// Storage of cotton_core::definitions::ThemePalettes.public struct DefinitionThemePalettes: Codable, Hashable, Sendable {    public var light: [String: DefinitionJSONValue]? = nil    public var dark: [String: DefinitionJSONValue]? = nil    public var unknown: [String: DefinitionJSONValue] = [:]    public init(_generated: Void) {    }    public enum CodingKeys: String, CodingKey, CaseIterable {        case light = "light"        case dark = "dark"    }    public init(from decoder: Decoder) throws {        let c = try decoder.container(keyedBy: CodingKeys.self)        light = try? c.decodeIfPresent([String: DefinitionJSONValue].self, forKey: .light)        dark = try? c.decodeIfPresent([String: DefinitionJSONValue].self, forKey: .dark)        let all = try decoder.container(keyedBy: DefinitionCodingKey.self)        let known = Set(CodingKeys.allCases.map(\.rawValue))        for key in all.allKeys where !known.contains(key.stringValue) {            unknown[key.stringValue] = try all.decode(DefinitionJSONValue.self, forKey: key)        }    }    public func encode(to encoder: Encoder) throws {        var c = encoder.container(keyedBy: CodingKeys.self)        try c.encodeIfPresent(light, forKey: .light)        try c.encodeIfPresent(dark, forKey: .dark)        var all = encoder.container(keyedBy: DefinitionCodingKey.self)        let known = Set(CodingKeys.allCases.map(\.rawValue))        for (key, value) in unknown where !known.contains(key) {            try all.encode(value, forKey: DefinitionCodingKey(key))        }    }}/// Storage of cotton_core::definitions::ThemeTexture.public struct DefinitionThemeTexture: Codable, Hashable, Sendable {    public var grain: Bool? = nil    public var shadow: String? = nil    public var tilt: Bool? = nil    public var unknown: [String: DefinitionJSONValue] = [:]    public init(_generated: Void) {    }    public enum CodingKeys: String, CodingKey, CaseIterable {        case grain = "grain"        case shadow = "shadow"        case tilt = "tilt"    }    public init(from decoder: Decoder) throws {        let c = try decoder.container(keyedBy: CodingKeys.self)        grain = try? c.decodeIfPresent(Bool.self, forKey: .grain)        shadow = try? c.decodeIfPresent(String.self, forKey: .shadow)        tilt = try? c.decodeIfPresent(Bool.self, forKey: .tilt)        let all = try decoder.container(keyedBy: DefinitionCodingKey.self)        let known = Set(CodingKeys.allCases.map(\.rawValue))        for key in all.allKeys where !known.contains(key.stringValue) {            unknown[key.stringValue] = try all.decode(DefinitionJSONValue.self, forKey: key)        }    }    public func encode(to encoder: Encoder) throws {        var c = encoder.container(keyedBy: CodingKeys.self)        try c.encodeIfPresent(grain, forKey: .grain)        try c.encodeIfPresent(shadow, forKey: .shadow)        try c.encodeIfPresent(tilt, forKey: .tilt)        var all = encoder.container(keyedBy: DefinitionCodingKey.self)        let known = Set(CodingKeys.allCases.map(\.rawValue))        for (key, value) in unknown where !known.contains(key) {            try all.encode(value, forKey: DefinitionCodingKey(key))        }    }}/// Storage of cotton_core::definitions::ThemeCap.public struct DefinitionThemeCap: Codable, Hashable, Sendable {    public var colour: String? = nil    public var texture: String? = nil    public var unknown: [String: DefinitionJSONValue] = [:]    public init(_generated: Void) {    }    public enum CodingKeys: String, CodingKey, CaseIterable {        case colour = "colour"        case texture = "texture"    }    public init(from decoder: Decoder) throws {        let c = try decoder.container(keyedBy: CodingKeys.self)        colour = try? c.decodeIfPresent(String.self, forKey: .colour)        texture = try? c.decodeIfPresent(String.self, forKey: .texture)        let all = try decoder.container(keyedBy: DefinitionCodingKey.self)        let known = Set(CodingKeys.allCases.map(\.rawValue))        for key in all.allKeys where !known.contains(key.stringValue) {            unknown[key.stringValue] = try all.decode(DefinitionJSONValue.self, forKey: key)        }    }    public func encode(to encoder: Encoder) throws {        var c = encoder.container(keyedBy: CodingKeys.self)        try c.encodeIfPresent(colour, forKey: .colour)        try c.encodeIfPresent(texture, forKey: .texture)        var all = encoder.container(keyedBy: DefinitionCodingKey.self)        let known = Set(CodingKeys.allCases.map(\.rawValue))        for (key, value) in unknown where !known.contains(key) {            try all.encode(value, forKey: DefinitionCodingKey(key))        }    }}/// Storage of cotton_core::definitions::ThemeScale.public struct DefinitionThemeScale: Codable, Hashable, Sendable {    public var tokens: [String: DefinitionJSONValue]? = nil    public var unknown: [String: DefinitionJSONValue] = [:]    public init(_generated: Void) {    }    public enum CodingKeys: String, CodingKey, CaseIterable {        case tokens = "tokens"    }    public init(from decoder: Decoder) throws {        let c = try decoder.container(keyedBy: CodingKeys.self)        tokens = try? c.decodeIfPresent([String: DefinitionJSONValue].self, forKey: .tokens)        let all = try decoder.container(keyedBy: DefinitionCodingKey.self)        let known = Set(CodingKeys.allCases.map(\.rawValue))        for key in all.allKeys where !known.contains(key.stringValue) {            unknown[key.stringValue] = try all.decode(DefinitionJSONValue.self, forKey: key)        }    }    public func encode(to encoder: Encoder) throws {        var c = encoder.container(keyedBy: CodingKeys.self)        try c.encodeIfPresent(tokens, forKey: .tokens)        var all = encoder.container(keyedBy: DefinitionCodingKey.self)        let known = Set(CodingKeys.allCases.map(\.rawValue))        for (key, value) in unknown where !known.contains(key) {            try all.encode(value, forKey: DefinitionCodingKey(key))        }    }}