// RigFileDocument.swift // Lyrebird // // Copyright (c) 2026 Joshua Parmenter / realizedsound // SPDX-License-Identifier: MIT import SwiftUI import UniformTypeIdentifiers /// A minimal JSON `FileDocument` wrapping a ShoeGaze rig's encoded bytes. /// /// Used by ``ShoeGazeBuilderView``'s iOS `.fileExporter` to write the result of /// `ShoeGaze.rigData()` to a user-chosen location. macOS uses an `NSSavePanel` directly and does /// not need this type. struct RigFileDocument: FileDocument { /// The rig presets are plain JSON. static var readableContentTypes: [UTType] { [.json] } /// Encoded rig JSON. let data: Data /// Creates a document from already-encoded rig JSON. init(data: Data) { self.data = data } /// Decodes an existing document's bytes (required by `FileDocument`, unused by the exporter). init(configuration: ReadConfiguration) throws { self.data = configuration.file.regularFileContents ?? Data() } /// Writes the rig JSON into a file wrapper for export. func fileWrapper(configuration: WriteConfiguration) throws -> FileWrapper { FileWrapper(regularFileWithContents: data) } }