diff --git a/Sources/FigmaAPI/Model/Node.swift b/Sources/FigmaAPI/Model/Node.swift index d49ca20b..b8deee82 100644 --- a/Sources/FigmaAPI/Model/Node.swift +++ b/Sources/FigmaAPI/Model/Node.swift @@ -38,10 +38,37 @@ public struct Document: Decodable { public let style: TypeStyle? } +// https://www.figma.com/plugin-docs/api/Paint/ public struct Paint: Decodable { - public let type: String + public let type: PaintType + public let opacity: Double? + public let color: PaintColor? + + public var asSolid: SolidPaint? { + return SolidPaint(self) + } +} + +public enum PaintType: String, Decodable { + case solid = "SOLID" + case image = "IMAGE" + case rectangle = "RECTANGLE" + case gradientLinear = "GRADIENT_LINEAR" + case gradientRadial = "GRADIENT_RADIAL" + case gradientAngular = "GRADIENT_ANGULAR" + case gradientDiamond = "GRADIENT_DIAMOND" +} + +public struct SolidPaint: Decodable { public let opacity: Double? public let color: PaintColor + + public init?(_ paint: Paint) { + guard paint.type == .solid else { return nil } + guard let color = paint.color else { return nil } + self.opacity = paint.opacity + self.color = color + } } public struct PaintColor: Decodable { diff --git a/Sources/FigmaExport/Loaders/ColorsLoader.swift b/Sources/FigmaExport/Loaders/ColorsLoader.swift index 289442fd..dc6cb0e5 100644 --- a/Sources/FigmaExport/Loaders/ColorsLoader.swift +++ b/Sources/FigmaExport/Loaders/ColorsLoader.swift @@ -34,8 +34,8 @@ final class ColorsLoader { /// Соотносит массив Style и Node чтобы получит массив Color private func nodesAndStylesToColors(nodes: [NodeId: Node], styles: [Style]) -> [Color] { return styles.compactMap { style -> Color? in - guard let node = nodes[style.nodeId] else { return nil} - guard let fill = node.document.fills.first else { return nil } + guard let node = nodes[style.nodeId] else { return nil } + guard let fill = node.document.fills.first?.asSolid else { return nil } let alpha: Double = fill.opacity ?? fill.color.a let platform = Platform(rawValue: style.description)