Skip to content

Commit

Permalink
Change visibility of classes and methods to be public in Swift.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 625311264
  • Loading branch information
Material Eng authored and Copybara-Service committed Apr 16, 2024
1 parent 193f145 commit c093082
Show file tree
Hide file tree
Showing 25 changed files with 219 additions and 377 deletions.
8 changes: 4 additions & 4 deletions swift/Sources/MaterialColorUtilities/Blend/Blend.swift
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.

/// Functions for blending in HCT and CAM16.
class Blend {
public class Blend {
/// Blend the design color's HCT hue towards the key color's HCT
/// hue, in a way that leaves the original color recognizable and
/// recognizably shifted towards the key color.
Expand All @@ -23,7 +23,7 @@ class Blend {
/// Returns The design color with a hue shifted towards the
/// system's color, a slightly warmer/cooler variant of the design
/// color's hue.
static func harmonize(_ designColor: Int, _ sourceColor: Int) -> Int {
public static func harmonize(_ designColor: Int, _ sourceColor: Int) -> Int {
let fromHct = Hct.fromInt(designColor)
let toHct = Hct.fromInt(sourceColor)
let differenceDegrees = MathUtils.differenceDegrees(fromHct.hue, toHct.hue)
Expand All @@ -41,7 +41,7 @@ class Blend {
/// [amount] how much blending to perform; 0.0 >= and <= 1.0
/// Returns from, with a hue blended towards to. Chroma and tone
/// are constant.
static func hctHue(_ from: Int, _ to: Int, _ amount: Double) -> Int {
public static func hctHue(_ from: Int, _ to: Int, _ amount: Double) -> Int {
let ucs = cam16Ucs(from, to, amount)
let ucsCam = Cam16.fromInt(ucs)
let fromCam = Cam16.fromInt(from)
Expand All @@ -56,7 +56,7 @@ class Blend {
/// [amount] how much blending to perform; 0.0 >= and <= 1.0
/// Returns from, blended towards to. Hue, chroma, and tone will
/// change.
static func cam16Ucs(_ from: Int, _ to: Int, _ amount: Double) -> Int {
public static func cam16Ucs(_ from: Int, _ to: Int, _ amount: Double) -> Int {
let fromCam = Cam16.fromInt(from)
let toCam = Cam16.fromInt(to)
let fromJ = fromCam.jstar
Expand Down
12 changes: 6 additions & 6 deletions swift/Sources/MaterialColorUtilities/Contrast/Contrast.swift
Expand Up @@ -22,11 +22,11 @@
/// Methods refer to tone, T in the the HCT color space.
/// Tone is equivalent to L* in the L*a*b* color space, or L in the LCH color
/// space.
class Contrast {
public class Contrast {
/// Returns a contrast ratio, which ranges from 1 to 21.
/// [toneA] Tone between 0 and 100. Values outside will be clamped.
/// [toneB] Tone between 0 and 100. Values outside will be clamped.
static func ratioOfTones(_ toneA: Double, _ toneB: Double) -> Double {
public static func ratioOfTones(_ toneA: Double, _ toneB: Double) -> Double {
let toneA = MathUtils.clampDouble(0, 100, toneA)
let toneB = MathUtils.clampDouble(0, 100, toneB)
return ratioOfYs(ColorUtils.yFromLstar(toneA), ColorUtils.yFromLstar(toneB))
Expand All @@ -46,7 +46,7 @@ class Contrast {
/// Range is 0 to 100. Invalid values will result in -1 being returned.
/// [ratio] Contrast ratio of return value and [tone].
/// Range is 1 to 21, invalid values have undefined behavior.
static func lighter(tone: Double, ratio: Double) -> Double {
public static func lighter(tone: Double, ratio: Double) -> Double {
if tone < 0 || tone > 100 {
return -1
}
Expand Down Expand Up @@ -76,7 +76,7 @@ class Contrast {
/// Range is 0 to 100. Invalid values will result in -1 being returned.
/// [ratio] Contrast ratio of return value and [tone].
/// Range is 1 to 21, invalid values have undefined behavior.
static func darker(tone: Double, ratio: Double) -> Double {
public static func darker(tone: Double, ratio: Double) -> Double {
if tone < 0 || tone > 100 {
return -1
}
Expand Down Expand Up @@ -111,7 +111,7 @@ class Contrast {
/// Range is 0 to 100. Invalid values will result in 100 being returned.
/// [ratio] Desired contrast ratio of return value and tone parameter.
/// Range is 1 to 21, invalid values have undefined behavior.
static func lighterUnsafe(tone: Double, ratio: Double) -> Double {
public static func lighterUnsafe(tone: Double, ratio: Double) -> Double {
let lighterSafe = lighter(tone: tone, ratio: ratio)
return lighterSafe < 0 ? 100 : lighterSafe
}
Expand All @@ -128,7 +128,7 @@ class Contrast {
/// Range is 0 to 100. Invalid values will result in 0 being returned.
/// [ratio] Desired contrast ratio of return value and tone parameter.
/// Range is 1 to 21, invalid values have undefined behavior.
static func darkerUnsafe(tone: Double, ratio: Double) -> Double {
public static func darkerUnsafe(tone: Double, ratio: Double) -> Double {
let darkerSafe = darker(tone: tone, ratio: ratio)
return darkerSafe < 0 ? 0 : darkerSafe
}
Expand Down
Expand Up @@ -22,11 +22,11 @@ import Foundation
///
/// See Palmer and Schloss, 2010 or Schloss and Palmer's Chapter 21 in Handbook
/// of Color Psychology (2015).
class DislikeAnalyzer {
public class DislikeAnalyzer {
/// Returns true if [hct] is disliked.
///
/// Disliked is defined as a dark yellow-green that is not neutral.
static func isDisliked(_ hct: Hct) -> Bool {
public static func isDisliked(_ hct: Hct) -> Bool {
let huePasses = round(hct.hue) >= 90 && round(hct.hue) <= 111
let chromaPasses = round(hct.chroma) > 16
let tonePasses = round(hct.tone) < 65
Expand All @@ -35,7 +35,7 @@ class DislikeAnalyzer {
}

/// If [hct] is disliked, lighten it to make it likable.
static func fixIfDisliked(_ hct: Hct) -> Hct {
public static func fixIfDisliked(_ hct: Hct) -> Hct {
if isDisliked(hct) {
return Hct.from(hct.hue, hct.chroma, 70)
}
Expand Down
Expand Up @@ -17,7 +17,7 @@
/// Usually represents the contrast requirements for a dynamic color on its
/// background. The four values correspond to values for contrast levels
/// -1.0, 0.0, 0.5, and 1.0, respectively.
struct ContrastCurve {
public struct ContrastCurve {
let low: Double
let normal: Double
let medium: Double
Expand All @@ -28,7 +28,7 @@ struct ContrastCurve {
/// - normal: Value for contrast level 0.0
/// - medium: Value for contrast level 0.5
/// - high: Value for contrast level 1.0
init(_ low: Double, _ normal: Double, _ medium: Double, _ high: Double) {
public init(_ low: Double, _ normal: Double, _ medium: Double, _ high: Double) {
self.low = low
self.normal = normal
self.medium = medium
Expand All @@ -41,7 +41,7 @@ struct ContrastCurve {
/// -1.0 is the lowest; 1.0 is the highest.
///
/// - Returns: The value. For contrast ratios, a number between 1.0 and 21.0.
func get(_ contrastLevel: Double) -> Double {
public func get(_ contrastLevel: Double) -> Double {
if contrastLevel <= -1.0 {
return self.low
} else if contrastLevel < 0.0 {
Expand Down
Expand Up @@ -14,7 +14,7 @@

import Foundation

typealias DynamicSchemeValue<T> = (DynamicScheme) -> T
public typealias DynamicSchemeValue<T> = (DynamicScheme) -> T

/// A color that adjusts itself based on UI state provided by `DynamicScheme`.
///
Expand Down Expand Up @@ -82,7 +82,7 @@ public class DynamicColor {
/// don't want to have a formal relationship or a principled value for their
/// tone distance based on common contrast / tone delta values, yet, want
/// tone distance.
init(
public init(
name: String,
palette: @escaping DynamicSchemeValue<TonalPalette>,
tone: @escaping DynamicSchemeValue<Double>,
Expand Down Expand Up @@ -133,7 +133,7 @@ public class DynamicColor {
/// contrast level is.
/// - Returns: a tone, T in the HCT color space, that this `DynamicColor` is under
/// the conditions in `scheme`.
func getTone(_ scheme: DynamicScheme) -> Double {
public func getTone(_ scheme: DynamicScheme) -> Double {
let decreasingContrast = scheme.contrastLevel < 0

// Case 1: dual foreground, pair of colors with delta constraint.
Expand Down Expand Up @@ -313,7 +313,7 @@ public class DynamicColor {
/// - ratio: The contrast ratio desired between `bgTone` and the return value.
///
/// - Returns: The desired foreground tone.
static func foregroundTone(_ bgTone: Double, _ ratio: Double) -> Double {
public static func foregroundTone(_ bgTone: Double, _ ratio: Double) -> Double {
let lighterTone = Contrast.lighterUnsafe(tone: bgTone, ratio: ratio)
let darkerTone = Contrast.darkerUnsafe(tone: bgTone, ratio: ratio)
let lighterRatio = Contrast.ratioOfTones(lighterTone, bgTone)
Expand Down Expand Up @@ -345,7 +345,7 @@ public class DynamicColor {
/// reasonably close to supporting it.
/// - Parameter tone: The tone to be adjusted.
/// - Returns: The (possibly updated) tone.
static func enableLightForeground(_ tone: Double) -> Double {
public static func enableLightForeground(_ tone: Double) -> Double {
if tonePrefersLightForeground(tone) && !toneAllowsLightForeground(tone) {
return 49
}
Expand All @@ -365,7 +365,7 @@ public class DynamicColor {
///
/// - Parameter tone: The tone to be judged.
/// - Returns: whether `tone` prefers a light foreground.
static func tonePrefersLightForeground(_ tone: Double) -> Bool {
public static func tonePrefersLightForeground(_ tone: Double) -> Bool {
return round(tone) < 60
}

Expand All @@ -374,7 +374,7 @@ public class DynamicColor {
///
/// - Parameter tone: The tone to be judged.
/// - Returns: whether `tone` allows a light foreground.
static func toneAllowsLightForeground(_ tone: Double) -> Bool {
public static func toneAllowsLightForeground(_ tone: Double) -> Bool {
return round(tone) <= 49
}
}

0 comments on commit c093082

Please sign in to comment.