@@ -18,85 +18,88 @@ import Foundation
1818/// .renderingIntent(.perceptual)
1919/// ```
2020public struct ColorProfile : AtRule {
21- public static let identifier : String = " color-profile "
21+ public static let identifier : String = " color-profile "
2222
23- public var rawValue : String
24- private var name : String
25- private var descriptors : [ String : String ] = [ : ]
23+ public var rawValue : String
24+ private var name : String
25+ private var descriptors : [ String : String ] = [ : ]
2626
27- public init ( rawValue: String ) {
28- self . rawValue = rawValue
29- // Extract name from rawValue for future reference
30- // This is a simplified implementation; a proper parser would be more complex
31- if let nameRange = rawValue. range ( of: " @color-profile \\ s+(--[ \\ w-]+|device-cmyk) \\ s* \\ { " , options: . regularExpression) {
32- let nameString = String ( rawValue [ nameRange] )
33- let parts = nameString. components ( separatedBy: CharacterSet . whitespacesAndNewlines)
34- self . name = parts. dropFirst ( ) . first ?? " "
35- } else {
36- self . name = " "
37- }
27+ public init ( rawValue: String ) {
28+ self . rawValue = rawValue
29+ // Extract name from rawValue for future reference
30+ // This is a simplified implementation; a proper parser would be more complex
31+ if let nameRange = rawValue. range (
32+ of: " @color-profile \\ s+(--[ \\ w-]+|device-cmyk) \\ s* \\ { " ,
33+ options: . regularExpression
34+ ) {
35+ let nameString = String ( rawValue [ nameRange] )
36+ let parts = nameString. components ( separatedBy: CharacterSet . whitespacesAndNewlines)
37+ self . name = parts. dropFirst ( ) . first ?? " "
38+ } else {
39+ self . name = " "
3840 }
41+ }
3942
40- /// Creates a color profile with the specified name.
41- ///
42- /// - Parameter name: The name of the color profile. Must start with `--` or be `device-cmyk`.
43- public init ( _ name: String ) {
44- self . name = name
45- self . rawValue = " @color-profile \( name) {} "
46- }
43+ /// Creates a color profile with the specified name.
44+ ///
45+ /// - Parameter name: The name of the color profile. Must start with `--` or be `device-cmyk`.
46+ public init ( _ name: String ) {
47+ self . name = name
48+ self . rawValue = " @color-profile \( name) {} "
49+ }
4750
48- /// Predefined device-cmyk color profile.
49- public static let deviceCMYK = ColorProfile ( " device-cmyk " )
51+ /// Predefined device-cmyk color profile.
52+ public static let deviceCMYK = ColorProfile ( " device-cmyk " )
5053
51- /// Sets the source URL for the color profile.
52- ///
53- /// - Parameter url: The URL to retrieve the color profile information from.
54- /// - Returns: An updated ColorProfile instance.
55- public func src( _ url: String ) -> ColorProfile {
56- var profile = self
57- profile. descriptors [ " src " ] = " url( \" \( url) \" ) "
58- profile. updateRawValue ( )
59- return profile
60- }
54+ /// Sets the source URL for the color profile.
55+ ///
56+ /// - Parameter url: The URL to retrieve the color profile information from.
57+ /// - Returns: An updated ColorProfile instance.
58+ public func src( _ url: String ) -> ColorProfile {
59+ var profile = self
60+ profile. descriptors [ " src " ] = " url( \" \( url) \" ) "
61+ profile. updateRawValue ( )
62+ return profile
63+ }
6164
62- /// Sets the rendering intent for the color profile.
63- ///
64- /// - Parameter intent: The rendering intent to use.
65- /// - Returns: An updated ColorProfile instance.
66- public func renderingIntent( _ intent: RenderingIntent ) -> ColorProfile {
67- var profile = self
68- profile. descriptors [ " rendering-intent " ] = intent. rawValue
69- profile. updateRawValue ( )
70- return profile
71- }
65+ /// Sets the rendering intent for the color profile.
66+ ///
67+ /// - Parameter intent: The rendering intent to use.
68+ /// - Returns: An updated ColorProfile instance.
69+ public func renderingIntent( _ intent: RenderingIntent ) -> ColorProfile {
70+ var profile = self
71+ profile. descriptors [ " rendering-intent " ] = intent. rawValue
72+ profile. updateRawValue ( )
73+ return profile
74+ }
7275
73- /// Updates the raw value based on the current descriptors.
74- private mutating func updateRawValue( ) {
75- let descriptorString = descriptors. map { key, value in
76- " \( key) : \( value) ; "
77- } . joined ( separator: " \n " )
76+ /// Updates the raw value based on the current descriptors.
77+ private mutating func updateRawValue( ) {
78+ let descriptorString = descriptors. map { key, value in
79+ " \( key) : \( value) ; "
80+ } . joined ( separator: " \n " )
7881
79- if descriptorString. isEmpty {
80- rawValue = " @color-profile \( name) {} "
81- } else {
82- rawValue = " @color-profile \( name) { \n \( descriptorString) \n } "
83- }
82+ if descriptorString. isEmpty {
83+ rawValue = " @color-profile \( name) {} "
84+ } else {
85+ rawValue = " @color-profile \( name) { \n \( descriptorString) \n } "
8486 }
87+ }
8588}
8689
8790extension ColorProfile {
88- /// Represents rendering intent options for color profiles.
89- public enum RenderingIntent : String , Hashable , Sendable {
90- /// Media-relative colorimetric intent.
91- case relativeColorimetric = " relative-colorimetric "
91+ /// Represents rendering intent options for color profiles.
92+ public enum RenderingIntent : String , Hashable , Sendable {
93+ /// Media-relative colorimetric intent.
94+ case relativeColorimetric = " relative-colorimetric "
9295
93- /// ICC-absolute colorimetric intent.
94- case absoluteColorimetric = " absolute-colorimetric "
96+ /// ICC-absolute colorimetric intent.
97+ case absoluteColorimetric = " absolute-colorimetric "
9598
96- /// Perceptual rendering intent, often preferred for images.
97- case perceptual
99+ /// Perceptual rendering intent, often preferred for images.
100+ case perceptual
98101
99- /// Saturation rendering intent, preserves relative saturation.
100- case saturation
101- }
102+ /// Saturation rendering intent, preserves relative saturation.
103+ case saturation
104+ }
102105}
0 commit comments