@@ -18,88 +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 (
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 = " "
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 = " "
40+ }
4041 }
41- }
4242
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- }
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+ }
5050
51- /// Predefined device-cmyk color profile.
52- public static let deviceCMYK = ColorProfile ( " device-cmyk " )
51+ /// Predefined device-cmyk color profile.
52+ public static let deviceCMYK = ColorProfile ( " device-cmyk " )
5353
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- }
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+ }
6464
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- }
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+ }
7575
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 " )
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 " )
8181
82- if descriptorString. isEmpty {
83- rawValue = " @color-profile \( name) {} "
84- } else {
85- rawValue = " @color-profile \( name) { \n \( descriptorString) \n } "
82+ if descriptorString. isEmpty {
83+ rawValue = " @color-profile \( name) {} "
84+ } else {
85+ rawValue = " @color-profile \( name) { \n \( descriptorString) \n } "
86+ }
8687 }
87- }
8888}
8989
9090extension ColorProfile {
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 "
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 "
9595
96- /// ICC-absolute colorimetric intent.
97- case absoluteColorimetric = " absolute-colorimetric "
96+ /// ICC-absolute colorimetric intent.
97+ case absoluteColorimetric = " absolute-colorimetric "
9898
99- /// Perceptual rendering intent, often preferred for images.
100- case perceptual
99+ /// Perceptual rendering intent, often preferred for images.
100+ case perceptual
101101
102- /// Saturation rendering intent, preserves relative saturation.
103- case saturation
104- }
102+ /// Saturation rendering intent, preserves relative saturation.
103+ case saturation
104+ }
105105}
0 commit comments