// A .cottontool manifest: data describing a tool, never executable code.importCottonValuesimportFoundationimportSwiftUIextensionDefinitionToolPicture {/// What the card draws. A built-in's picture is a photo record that names/// the object the app ships with the same bytes (`{"photo": …, "object":/// "tool-todos"}`): the device draws that object — its prints, its small/// variant, offline — and a photo the owner set, naming no object, is/// drawn from the photo. A picture that only says how a link is drawn is/// no picture.publicvar drawn: ToolPicture? {switchself {case .asset(let object): .asset(object)// An object the app does not ship (a package naming its own picture// as an object) is no object: the photo is drawn.case .photo(let photo): photo.object.flatMap { ToolObjects.ships($0) ? ToolPicture.asset($0) : nil } ?? .photo(photo.photo)case .link: nil } }/// How a card draws a link to one of this table's records.publicvar linkObject: LinkObject? {switchself {case .asset: nilcase .photo(let photo): photo.linkObjectcase .link(let link): link.linkObject } }/// `picture` stored with `linkObject` kept. A shipped object alone is its/// bare name, which carries no link object (the core's form), so only a/// photo or no picture keeps one.init?(_ picture: ToolPicture?, linkObject: LinkObject?) {switch picture {case .asset(let object): self = .asset(object)case .photo(let id):var photo = DefinitionToolPhoto(_generated: (), photo: id) photo.linkObject = linkObjectself = .photo(photo)casenil:guardlet linkObject else { returnnil }self = .link(DefinitionLinkPicture(_generated: (), linkObject: linkObject)) } }}publictypealiasToolDefinition = DefinitionToolDefinitionextensionDefinitionToolDefinition: Identifiable {publictypealiasAuthor = DefinitionToolAuthorpublicinit( id: String, name: String, picture: DefinitionToolPicture? = nil, cardStock: ToolCardTint? = nil, tables: [String], instructions: String, automations: [DefinitionJSONValue], author: Author, signature: String? ) {self.init( _generated: (), id: id, name: name, tables: tables, instructions: instructions, automations: automations, author: author)self.picture = pictureself.cardStock = cardStockself.signature = signature }publicstaticfunc decode(_ data: Data) throws -> Self {try JSONDecoder().decode(Self.self, from: data) }}extensionDefinitionToolAuthor {publicinit(device: String, name: String) { self.init(_generated: (), device: device, name: name) }}/// Synced tools in tool_order order; compiled tools keep their existing slots.publicstructToolDefinitions: Sendable {publicvar all: [ToolDefinition]publicinit(_ all: [ToolDefinition]) { self.all = all }}privatestructToolDefinitionsKey: EnvironmentKey {staticlet defaultValue = ToolDefinitions([])}extensionEnvironmentValues {publicvar toolDefinitions: ToolDefinitions { get { self[ToolDefinitionsKey.self] } set { self[ToolDefinitionsKey.self] = newValue } }}