|
| 1 | +// |
| 2 | +// Copyright © 2025 Darren Ford. All rights reserved. |
| 3 | +// |
| 4 | +// MIT license |
| 5 | +// |
| 6 | +// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated |
| 7 | +// documentation files (the "Software"), to deal in the Software without restriction, including without limitation the |
| 8 | +// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to |
| 9 | +// permit persons to whom the Software is furnished to do so, subject to the following conditions: |
| 10 | +// |
| 11 | +// The above copyright notice and this permission notice shall be included in all copies or substantial |
| 12 | +// portions of the Software. |
| 13 | +// |
| 14 | +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE |
| 15 | +// WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS |
| 16 | +// OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
| 17 | +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 18 | +// |
| 19 | + |
| 20 | +// PAL.Color Support for CoreTransferable and the `Transferable` protocol |
| 21 | + |
| 22 | +#if canImport(UniformTypeIdentifiers) |
| 23 | + |
| 24 | +import Foundation |
| 25 | +import UniformTypeIdentifiers |
| 26 | + |
| 27 | +@available(macOS 11, iOS 14, tvOS 14, watchOS 7, *) |
| 28 | +public extension UTType { |
| 29 | + /// The UTType for a JSON encoded `PAL.Color` value |
| 30 | + static let palColor = UTType(exportedAs: "public.dagronf.colorpalette.color", conformingTo: UTType.json) |
| 31 | + static let systemColor = UTType("com.apple.cocoa.pasteboard.color")! |
| 32 | +} |
| 33 | + |
| 34 | +#if canImport(SwiftUI) |
| 35 | +import SwiftUI |
| 36 | +import CoreTransferable |
| 37 | + |
| 38 | +@available(macOS 13, iOS 16, tvOS 16, watchOS 9, *) |
| 39 | +extension PAL.Color: Transferable { |
| 40 | + |
| 41 | + private var swcolor: SwiftUI.Color { self.SwiftUIColor ?? .black } |
| 42 | + |
| 43 | + public static var transferRepresentation: some TransferRepresentation { |
| 44 | + // Add the basic transfer representation for a SwiftUI.Color |
| 45 | + ProxyRepresentation(exporting: \.swcolor) |
| 46 | + // Add PAL.Color as a codable type |
| 47 | + CodableRepresentation(contentType: .palColor) |
| 48 | + } |
| 49 | +} |
| 50 | + |
| 51 | +#endif |
| 52 | +#endif |
0 commit comments