diff --git a/build.gradle.kts b/build.gradle.kts index 5df6f67..9fb0eba 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -16,7 +16,6 @@ plugins { apiValidation { ignoredProjects.addAll( listOf( - "material-color-utilities", "composeApp", ), ) diff --git a/demo/composeApp/src/commonMain/kotlin/com/materialkolor/demo/App.kt b/demo/composeApp/src/commonMain/kotlin/com/materialkolor/demo/App.kt index a1e44b6..e1fcec4 100644 --- a/demo/composeApp/src/commonMain/kotlin/com/materialkolor/demo/App.kt +++ b/demo/composeApp/src/commonMain/kotlin/com/materialkolor/demo/App.kt @@ -58,7 +58,6 @@ import com.materialkolor.PaletteStyle import com.materialkolor.demo.theme.AppTheme import com.materialkolor.ktx.fromColor import com.materialkolor.ktx.harmonize -import com.materialkolor.ktx.matchSaturation import com.materialkolor.palettes.TonalPalette val SampleColors = listOf( @@ -109,7 +108,12 @@ internal fun App() { var darkTheme by remember { mutableStateOf(isDarkTheme) } AppTheme(seedColor, style, darkTheme) { - Column(modifier = Modifier.fillMaxSize().padding(8.dp)) { + Column( + modifier = Modifier + .fillMaxSize() + .padding(8.dp) + .verticalScroll(rememberScrollState()), + ) { Box( modifier = Modifier.align(Alignment.End) ) { @@ -160,7 +164,7 @@ internal fun App() { Text(text = "Preview", style = MaterialTheme.typography.headlineSmall) Column( - modifier = Modifier.verticalScroll(rememberScrollState()), + modifier = Modifier, verticalArrangement = Arrangement.spacedBy(8.dp), ) { Column { @@ -207,7 +211,6 @@ internal fun App() { Column( verticalArrangement = Arrangement.spacedBy(8.dp), horizontalAlignment = Alignment.CenterHorizontally, - modifier = Modifier.weight(1f), ) { ExtendedFloatingActionButton({}) { Text("Extended FAB") @@ -261,8 +264,7 @@ internal fun App() { Row { val harmonizedColor = Color.Red - .matchSaturation(colorScheme.primary) - .harmonize(colorScheme.primary) + .harmonize(colorScheme.primary, matchSaturation = true) val harmonizedPalette = TonalPalette.fromColor(harmonizedColor) @@ -298,8 +300,7 @@ internal fun App() { Row { val harmonizedColor = Color.Blue - .matchSaturation(colorScheme.primary) - .harmonize(colorScheme.primary) + .harmonize(colorScheme.primary, matchSaturation = true) val harmonizedPalette = TonalPalette.fromColor(harmonizedColor) diff --git a/material-color-utilities/api/android/material-color-utilities.api b/material-color-utilities/api/android/material-color-utilities.api new file mode 100644 index 0000000..db03789 --- /dev/null +++ b/material-color-utilities/api/android/material-color-utilities.api @@ -0,0 +1,327 @@ +public final class com/materialkolor/blend/Blend { + public static final field INSTANCE Lcom/materialkolor/blend/Blend; + public final fun cam16Ucs (IID)I + public final fun harmonize (II)I + public final fun harmonize (Lcom/materialkolor/hct/Hct;Lcom/materialkolor/hct/Hct;)Lcom/materialkolor/hct/Hct; + public final fun hctHue (IID)I +} + +public final class com/materialkolor/contrast/Contrast { + public static final field INSTANCE Lcom/materialkolor/contrast/Contrast; + public final fun darker (DD)D + public final fun darkerUnsafe (DD)D + public final fun lighter (DD)D + public final fun lighterUnsafe (DD)D + public final fun ratioOfTones (DD)D + public final fun ratioOfYs (DD)D +} + +public final class com/materialkolor/dislike/DislikeAnalyzer { + public static final field INSTANCE Lcom/materialkolor/dislike/DislikeAnalyzer; + public final fun fixIfDisliked (Lcom/materialkolor/hct/Hct;)Lcom/materialkolor/hct/Hct; + public final fun isDisliked (Lcom/materialkolor/hct/Hct;)Z +} + +public final class com/materialkolor/dynamiccolor/ContrastCurve { + public fun (DDDD)V + public final fun get (D)D +} + +public final class com/materialkolor/dynamiccolor/DynamicColor { + public static final field Companion Lcom/materialkolor/dynamiccolor/DynamicColor$Companion; + public fun (Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;ZLkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lcom/materialkolor/dynamiccolor/ContrastCurve;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)V + public synthetic fun (Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;ZLkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lcom/materialkolor/dynamiccolor/ContrastCurve;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public final fun getArgb (Lcom/materialkolor/scheme/DynamicScheme;)I + public final fun getBackground ()Lkotlin/jvm/functions/Function1; + public final fun getContrastCurve ()Lcom/materialkolor/dynamiccolor/ContrastCurve; + public final fun getHct (Lcom/materialkolor/scheme/DynamicScheme;)Lcom/materialkolor/hct/Hct; + public final fun getName ()Ljava/lang/String; + public final fun getOpacity ()Lkotlin/jvm/functions/Function1; + public final fun getPalette ()Lkotlin/jvm/functions/Function1; + public final fun getSecondBackground ()Lkotlin/jvm/functions/Function1; + public final fun getTone ()Lkotlin/jvm/functions/Function1; + public final fun getTone (Lcom/materialkolor/scheme/DynamicScheme;)D + public final fun getToneDeltaPair ()Lkotlin/jvm/functions/Function1; + public final fun isBackground ()Z +} + +public final class com/materialkolor/dynamiccolor/DynamicColor$Companion { + public final fun enableLightForeground (D)D + public final fun foregroundTone (DD)D + public final fun fromArgb (Ljava/lang/String;I)Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun fromPalette (Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun fromPalette (Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Z)Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun toneAllowsLightForeground (D)Z + public final fun tonePrefersLightForeground (D)Z +} + +public final class com/materialkolor/dynamiccolor/MaterialDynamicColors { + public static final field Companion Lcom/materialkolor/dynamiccolor/MaterialDynamicColors$Companion; + public fun ()V + public fun (Z)V + public synthetic fun (ZILkotlin/jvm/internal/DefaultConstructorMarker;)V + public final fun background ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun controlActivated ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun controlHighlight ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun controlNormal ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun error ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun errorContainer ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun highestSurface (Lcom/materialkolor/scheme/DynamicScheme;)Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun inverseOnSurface ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun inversePrimary ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun inverseSurface ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun neutralPaletteKeyColor ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun neutralVariantPaletteKeyColor ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun onBackground ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun onError ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun onErrorContainer ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun onPrimary ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun onPrimaryContainer ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun onPrimaryFixed ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun onPrimaryFixedVariant ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun onSecondary ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun onSecondaryContainer ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun onSecondaryFixed ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun onSecondaryFixedVariant ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun onSurface ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun onSurfaceVariant ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun onTertiary ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun onTertiaryContainer ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun onTertiaryFixed ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun onTertiaryFixedVariant ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun outline ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun outlineVariant ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun primary ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun primaryContainer ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun primaryFixed ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun primaryFixedDim ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun primaryPaletteKeyColor ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun scrim ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun secondary ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun secondaryContainer ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun secondaryFixed ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun secondaryFixedDim ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun secondaryPaletteKeyColor ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun shadow ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun surface ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun surfaceBright ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun surfaceContainer ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun surfaceContainerHigh ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun surfaceContainerHighest ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun surfaceContainerLow ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun surfaceContainerLowest ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun surfaceDim ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun surfaceTint ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun surfaceVariant ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun tertiary ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun tertiaryContainer ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun tertiaryFixed ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun tertiaryFixedDim ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun tertiaryPaletteKeyColor ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun textHintInverse ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun textPrimaryInverse ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun textPrimaryInverseDisableOnly ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun textSecondaryAndTertiaryInverse ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun textSecondaryAndTertiaryInverseDisabled ()Lcom/materialkolor/dynamiccolor/DynamicColor; +} + +public final class com/materialkolor/dynamiccolor/MaterialDynamicColors$Companion { +} + +public final class com/materialkolor/dynamiccolor/ToneDeltaPair { + public fun (Lcom/materialkolor/dynamiccolor/DynamicColor;Lcom/materialkolor/dynamiccolor/DynamicColor;DLcom/materialkolor/dynamiccolor/TonePolarity;Z)V + public final fun getDelta ()D + public final fun getPolarity ()Lcom/materialkolor/dynamiccolor/TonePolarity; + public final fun getRoleA ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun getRoleB ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun getStayTogether ()Z +} + +public final class com/materialkolor/dynamiccolor/TonePolarity : java/lang/Enum { + public static final field DARKER Lcom/materialkolor/dynamiccolor/TonePolarity; + public static final field FARTHER Lcom/materialkolor/dynamiccolor/TonePolarity; + public static final field LIGHTER Lcom/materialkolor/dynamiccolor/TonePolarity; + public static final field NEARER Lcom/materialkolor/dynamiccolor/TonePolarity; + public static fun getEntries ()Lkotlin/enums/EnumEntries; + public static fun valueOf (Ljava/lang/String;)Lcom/materialkolor/dynamiccolor/TonePolarity; + public static fun values ()[Lcom/materialkolor/dynamiccolor/TonePolarity; +} + +public final class com/materialkolor/hct/Hct { + public static final field Companion Lcom/materialkolor/hct/Hct$Companion; + public synthetic fun (ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public final fun getChroma ()D + public final fun getHue ()D + public final fun getTone ()D + public final fun toInt ()I + public final fun withChroma (D)Lcom/materialkolor/hct/Hct; + public final fun withHue (D)Lcom/materialkolor/hct/Hct; + public final fun withTone (D)Lcom/materialkolor/hct/Hct; +} + +public final class com/materialkolor/hct/Hct$Companion { + public final fun from (DDD)Lcom/materialkolor/hct/Hct; + public final fun fromInt (I)Lcom/materialkolor/hct/Hct; +} + +public final class com/materialkolor/hct/HctSolver { + public static final field INSTANCE Lcom/materialkolor/hct/HctSolver; + public final fun solveToInt (DDD)I +} + +public final class com/materialkolor/palettes/CorePalette { + public static final field Companion Lcom/materialkolor/palettes/CorePalette$Companion; + public synthetic fun (IZLkotlin/jvm/internal/DefaultConstructorMarker;)V + public final fun getA1 ()Lcom/materialkolor/palettes/TonalPalette; + public final fun getA2 ()Lcom/materialkolor/palettes/TonalPalette; + public final fun getA3 ()Lcom/materialkolor/palettes/TonalPalette; + public final fun getError ()Lcom/materialkolor/palettes/TonalPalette; + public final fun getN1 ()Lcom/materialkolor/palettes/TonalPalette; + public final fun getN2 ()Lcom/materialkolor/palettes/TonalPalette; + public final fun setA1 (Lcom/materialkolor/palettes/TonalPalette;)V + public final fun setA2 (Lcom/materialkolor/palettes/TonalPalette;)V + public final fun setA3 (Lcom/materialkolor/palettes/TonalPalette;)V + public final fun setError (Lcom/materialkolor/palettes/TonalPalette;)V + public final fun setN1 (Lcom/materialkolor/palettes/TonalPalette;)V + public final fun setN2 (Lcom/materialkolor/palettes/TonalPalette;)V +} + +public final class com/materialkolor/palettes/CorePalette$Companion { + public final fun contentOf (I)Lcom/materialkolor/palettes/CorePalette; + public final fun of (I)Lcom/materialkolor/palettes/CorePalette; +} + +public final class com/materialkolor/palettes/TonalPalette { + public static final field Companion Lcom/materialkolor/palettes/TonalPalette$Companion; + public synthetic fun (DDLcom/materialkolor/hct/Hct;Lkotlin/jvm/internal/DefaultConstructorMarker;)V + public final fun getChroma ()D + public final fun getHct (D)Lcom/materialkolor/hct/Hct; + public final fun getHue ()D + public final fun getKeyColor ()Lcom/materialkolor/hct/Hct; + public final fun tone (I)I +} + +public final class com/materialkolor/palettes/TonalPalette$Companion { + public final fun fromHct (Lcom/materialkolor/hct/Hct;)Lcom/materialkolor/palettes/TonalPalette; + public final fun fromHueAndChroma (DD)Lcom/materialkolor/palettes/TonalPalette; + public final fun fromInt (I)Lcom/materialkolor/palettes/TonalPalette; +} + +public final class com/materialkolor/quantize/QuantizerCelebi { + public static final field INSTANCE Lcom/materialkolor/quantize/QuantizerCelebi; + public final fun quantize ([II)Ljava/util/Map; +} + +public class com/materialkolor/scheme/DynamicScheme { + public static final field Companion Lcom/materialkolor/scheme/DynamicScheme$Companion; + public fun (Lcom/materialkolor/hct/Hct;Lcom/materialkolor/scheme/Variant;ZDLcom/materialkolor/palettes/TonalPalette;Lcom/materialkolor/palettes/TonalPalette;Lcom/materialkolor/palettes/TonalPalette;Lcom/materialkolor/palettes/TonalPalette;Lcom/materialkolor/palettes/TonalPalette;)V + public final fun getContrastLevel ()D + public final fun getErrorPalette ()Lcom/materialkolor/palettes/TonalPalette; + public final fun getNeutralPalette ()Lcom/materialkolor/palettes/TonalPalette; + public final fun getNeutralVariantPalette ()Lcom/materialkolor/palettes/TonalPalette; + public final fun getPrimaryPalette ()Lcom/materialkolor/palettes/TonalPalette; + public final fun getSecondaryPalette ()Lcom/materialkolor/palettes/TonalPalette; + public final fun getSourceColorArgb ()I + public final fun getSourceColorHct ()Lcom/materialkolor/hct/Hct; + public final fun getTertiaryPalette ()Lcom/materialkolor/palettes/TonalPalette; + public final fun getVariant ()Lcom/materialkolor/scheme/Variant; + public final fun isDark ()Z +} + +public final class com/materialkolor/scheme/DynamicScheme$Companion { + public final fun getRotatedHue (Lcom/materialkolor/hct/Hct;[D[D)D +} + +public final class com/materialkolor/scheme/SchemeContent : com/materialkolor/scheme/DynamicScheme { + public fun (Lcom/materialkolor/hct/Hct;ZD)V +} + +public final class com/materialkolor/scheme/SchemeExpressive : com/materialkolor/scheme/DynamicScheme { + public fun (Lcom/materialkolor/hct/Hct;ZD)V +} + +public final class com/materialkolor/scheme/SchemeFidelity : com/materialkolor/scheme/DynamicScheme { + public fun (Lcom/materialkolor/hct/Hct;ZD)V +} + +public final class com/materialkolor/scheme/SchemeFruitSalad : com/materialkolor/scheme/DynamicScheme { + public fun (Lcom/materialkolor/hct/Hct;ZD)V +} + +public final class com/materialkolor/scheme/SchemeMonochrome : com/materialkolor/scheme/DynamicScheme { + public fun (Lcom/materialkolor/hct/Hct;ZD)V +} + +public final class com/materialkolor/scheme/SchemeNeutral : com/materialkolor/scheme/DynamicScheme { + public fun (Lcom/materialkolor/hct/Hct;ZD)V +} + +public final class com/materialkolor/scheme/SchemeRainbow : com/materialkolor/scheme/DynamicScheme { + public fun (Lcom/materialkolor/hct/Hct;ZD)V +} + +public final class com/materialkolor/scheme/SchemeTonalSpot : com/materialkolor/scheme/DynamicScheme { + public fun (Lcom/materialkolor/hct/Hct;ZD)V +} + +public final class com/materialkolor/scheme/SchemeVibrant : com/materialkolor/scheme/DynamicScheme { + public fun (Lcom/materialkolor/hct/Hct;ZD)V +} + +public final class com/materialkolor/scheme/Variant : java/lang/Enum { + public static final field CONTENT Lcom/materialkolor/scheme/Variant; + public static final field EXPRESSIVE Lcom/materialkolor/scheme/Variant; + public static final field FIDELITY Lcom/materialkolor/scheme/Variant; + public static final field FRUIT_SALAD Lcom/materialkolor/scheme/Variant; + public static final field MONOCHROME Lcom/materialkolor/scheme/Variant; + public static final field NEUTRAL Lcom/materialkolor/scheme/Variant; + public static final field RAINBOW Lcom/materialkolor/scheme/Variant; + public static final field TONAL_SPOT Lcom/materialkolor/scheme/Variant; + public static final field VIBRANT Lcom/materialkolor/scheme/Variant; + public static fun getEntries ()Lkotlin/enums/EnumEntries; + public static fun valueOf (Ljava/lang/String;)Lcom/materialkolor/scheme/Variant; + public static fun values ()[Lcom/materialkolor/scheme/Variant; +} + +public final class com/materialkolor/score/Score { + public static final field INSTANCE Lcom/materialkolor/score/Score; + public final fun score (Ljava/util/Map;ILjava/lang/Integer;Z)Ljava/util/List; + public static synthetic fun score$default (Lcom/materialkolor/score/Score;Ljava/util/Map;ILjava/lang/Integer;ZILjava/lang/Object;)Ljava/util/List; +} + +public final class com/materialkolor/temperature/TemperatureCache { + public static final field Companion Lcom/materialkolor/temperature/TemperatureCache$Companion; + public fun (Lcom/materialkolor/hct/Hct;)V + public final fun getAnalogousColors ()Ljava/util/List; + public final fun getAnalogousColors (II)Ljava/util/List; + public final fun getComplement ()Lcom/materialkolor/hct/Hct; + public final fun getRelativeTemperature (Lcom/materialkolor/hct/Hct;)D +} + +public final class com/materialkolor/temperature/TemperatureCache$Companion { + public final fun rawTemperature (Lcom/materialkolor/hct/Hct;)D +} + +public final class com/materialkolor/utils/ColorUtils { + public static final field INSTANCE Lcom/materialkolor/utils/ColorUtils; + public final fun argbFromLab (DDD)I + public final fun argbFromLinrgb ([D)I + public final fun argbFromLstar (D)I + public final fun argbFromRgb (III)I + public final fun argbFromXyz (DDD)I + public final fun blueFromArgb (I)I + public final fun calculateLuminance (I)D + public final fun delinearized (D)I + public final fun greenFromArgb (I)I + public final fun labF (D)D + public final fun labFromArgb (I)[D + public final fun labInvf (D)D + public final fun linearized (I)D + public final fun lstarFromArgb (I)D + public final fun lstarFromY (D)D + public final fun redFromArgb (I)I + public final fun whitePointD65 ()[D + public final fun xyzFromArgb (I)[D + public final fun yFromLstar (D)D +} + diff --git a/material-color-utilities/api/jvm/material-color-utilities.api b/material-color-utilities/api/jvm/material-color-utilities.api new file mode 100644 index 0000000..db03789 --- /dev/null +++ b/material-color-utilities/api/jvm/material-color-utilities.api @@ -0,0 +1,327 @@ +public final class com/materialkolor/blend/Blend { + public static final field INSTANCE Lcom/materialkolor/blend/Blend; + public final fun cam16Ucs (IID)I + public final fun harmonize (II)I + public final fun harmonize (Lcom/materialkolor/hct/Hct;Lcom/materialkolor/hct/Hct;)Lcom/materialkolor/hct/Hct; + public final fun hctHue (IID)I +} + +public final class com/materialkolor/contrast/Contrast { + public static final field INSTANCE Lcom/materialkolor/contrast/Contrast; + public final fun darker (DD)D + public final fun darkerUnsafe (DD)D + public final fun lighter (DD)D + public final fun lighterUnsafe (DD)D + public final fun ratioOfTones (DD)D + public final fun ratioOfYs (DD)D +} + +public final class com/materialkolor/dislike/DislikeAnalyzer { + public static final field INSTANCE Lcom/materialkolor/dislike/DislikeAnalyzer; + public final fun fixIfDisliked (Lcom/materialkolor/hct/Hct;)Lcom/materialkolor/hct/Hct; + public final fun isDisliked (Lcom/materialkolor/hct/Hct;)Z +} + +public final class com/materialkolor/dynamiccolor/ContrastCurve { + public fun (DDDD)V + public final fun get (D)D +} + +public final class com/materialkolor/dynamiccolor/DynamicColor { + public static final field Companion Lcom/materialkolor/dynamiccolor/DynamicColor$Companion; + public fun (Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;ZLkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lcom/materialkolor/dynamiccolor/ContrastCurve;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)V + public synthetic fun (Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;ZLkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lcom/materialkolor/dynamiccolor/ContrastCurve;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public final fun getArgb (Lcom/materialkolor/scheme/DynamicScheme;)I + public final fun getBackground ()Lkotlin/jvm/functions/Function1; + public final fun getContrastCurve ()Lcom/materialkolor/dynamiccolor/ContrastCurve; + public final fun getHct (Lcom/materialkolor/scheme/DynamicScheme;)Lcom/materialkolor/hct/Hct; + public final fun getName ()Ljava/lang/String; + public final fun getOpacity ()Lkotlin/jvm/functions/Function1; + public final fun getPalette ()Lkotlin/jvm/functions/Function1; + public final fun getSecondBackground ()Lkotlin/jvm/functions/Function1; + public final fun getTone ()Lkotlin/jvm/functions/Function1; + public final fun getTone (Lcom/materialkolor/scheme/DynamicScheme;)D + public final fun getToneDeltaPair ()Lkotlin/jvm/functions/Function1; + public final fun isBackground ()Z +} + +public final class com/materialkolor/dynamiccolor/DynamicColor$Companion { + public final fun enableLightForeground (D)D + public final fun foregroundTone (DD)D + public final fun fromArgb (Ljava/lang/String;I)Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun fromPalette (Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun fromPalette (Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Z)Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun toneAllowsLightForeground (D)Z + public final fun tonePrefersLightForeground (D)Z +} + +public final class com/materialkolor/dynamiccolor/MaterialDynamicColors { + public static final field Companion Lcom/materialkolor/dynamiccolor/MaterialDynamicColors$Companion; + public fun ()V + public fun (Z)V + public synthetic fun (ZILkotlin/jvm/internal/DefaultConstructorMarker;)V + public final fun background ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun controlActivated ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun controlHighlight ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun controlNormal ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun error ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun errorContainer ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun highestSurface (Lcom/materialkolor/scheme/DynamicScheme;)Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun inverseOnSurface ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun inversePrimary ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun inverseSurface ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun neutralPaletteKeyColor ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun neutralVariantPaletteKeyColor ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun onBackground ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun onError ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun onErrorContainer ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun onPrimary ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun onPrimaryContainer ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun onPrimaryFixed ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun onPrimaryFixedVariant ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun onSecondary ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun onSecondaryContainer ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun onSecondaryFixed ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun onSecondaryFixedVariant ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun onSurface ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun onSurfaceVariant ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun onTertiary ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun onTertiaryContainer ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun onTertiaryFixed ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun onTertiaryFixedVariant ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun outline ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun outlineVariant ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun primary ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun primaryContainer ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun primaryFixed ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun primaryFixedDim ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun primaryPaletteKeyColor ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun scrim ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun secondary ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun secondaryContainer ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun secondaryFixed ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun secondaryFixedDim ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun secondaryPaletteKeyColor ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun shadow ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun surface ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun surfaceBright ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun surfaceContainer ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun surfaceContainerHigh ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun surfaceContainerHighest ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun surfaceContainerLow ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun surfaceContainerLowest ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun surfaceDim ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun surfaceTint ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun surfaceVariant ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun tertiary ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun tertiaryContainer ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun tertiaryFixed ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun tertiaryFixedDim ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun tertiaryPaletteKeyColor ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun textHintInverse ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun textPrimaryInverse ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun textPrimaryInverseDisableOnly ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun textSecondaryAndTertiaryInverse ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun textSecondaryAndTertiaryInverseDisabled ()Lcom/materialkolor/dynamiccolor/DynamicColor; +} + +public final class com/materialkolor/dynamiccolor/MaterialDynamicColors$Companion { +} + +public final class com/materialkolor/dynamiccolor/ToneDeltaPair { + public fun (Lcom/materialkolor/dynamiccolor/DynamicColor;Lcom/materialkolor/dynamiccolor/DynamicColor;DLcom/materialkolor/dynamiccolor/TonePolarity;Z)V + public final fun getDelta ()D + public final fun getPolarity ()Lcom/materialkolor/dynamiccolor/TonePolarity; + public final fun getRoleA ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun getRoleB ()Lcom/materialkolor/dynamiccolor/DynamicColor; + public final fun getStayTogether ()Z +} + +public final class com/materialkolor/dynamiccolor/TonePolarity : java/lang/Enum { + public static final field DARKER Lcom/materialkolor/dynamiccolor/TonePolarity; + public static final field FARTHER Lcom/materialkolor/dynamiccolor/TonePolarity; + public static final field LIGHTER Lcom/materialkolor/dynamiccolor/TonePolarity; + public static final field NEARER Lcom/materialkolor/dynamiccolor/TonePolarity; + public static fun getEntries ()Lkotlin/enums/EnumEntries; + public static fun valueOf (Ljava/lang/String;)Lcom/materialkolor/dynamiccolor/TonePolarity; + public static fun values ()[Lcom/materialkolor/dynamiccolor/TonePolarity; +} + +public final class com/materialkolor/hct/Hct { + public static final field Companion Lcom/materialkolor/hct/Hct$Companion; + public synthetic fun (ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public final fun getChroma ()D + public final fun getHue ()D + public final fun getTone ()D + public final fun toInt ()I + public final fun withChroma (D)Lcom/materialkolor/hct/Hct; + public final fun withHue (D)Lcom/materialkolor/hct/Hct; + public final fun withTone (D)Lcom/materialkolor/hct/Hct; +} + +public final class com/materialkolor/hct/Hct$Companion { + public final fun from (DDD)Lcom/materialkolor/hct/Hct; + public final fun fromInt (I)Lcom/materialkolor/hct/Hct; +} + +public final class com/materialkolor/hct/HctSolver { + public static final field INSTANCE Lcom/materialkolor/hct/HctSolver; + public final fun solveToInt (DDD)I +} + +public final class com/materialkolor/palettes/CorePalette { + public static final field Companion Lcom/materialkolor/palettes/CorePalette$Companion; + public synthetic fun (IZLkotlin/jvm/internal/DefaultConstructorMarker;)V + public final fun getA1 ()Lcom/materialkolor/palettes/TonalPalette; + public final fun getA2 ()Lcom/materialkolor/palettes/TonalPalette; + public final fun getA3 ()Lcom/materialkolor/palettes/TonalPalette; + public final fun getError ()Lcom/materialkolor/palettes/TonalPalette; + public final fun getN1 ()Lcom/materialkolor/palettes/TonalPalette; + public final fun getN2 ()Lcom/materialkolor/palettes/TonalPalette; + public final fun setA1 (Lcom/materialkolor/palettes/TonalPalette;)V + public final fun setA2 (Lcom/materialkolor/palettes/TonalPalette;)V + public final fun setA3 (Lcom/materialkolor/palettes/TonalPalette;)V + public final fun setError (Lcom/materialkolor/palettes/TonalPalette;)V + public final fun setN1 (Lcom/materialkolor/palettes/TonalPalette;)V + public final fun setN2 (Lcom/materialkolor/palettes/TonalPalette;)V +} + +public final class com/materialkolor/palettes/CorePalette$Companion { + public final fun contentOf (I)Lcom/materialkolor/palettes/CorePalette; + public final fun of (I)Lcom/materialkolor/palettes/CorePalette; +} + +public final class com/materialkolor/palettes/TonalPalette { + public static final field Companion Lcom/materialkolor/palettes/TonalPalette$Companion; + public synthetic fun (DDLcom/materialkolor/hct/Hct;Lkotlin/jvm/internal/DefaultConstructorMarker;)V + public final fun getChroma ()D + public final fun getHct (D)Lcom/materialkolor/hct/Hct; + public final fun getHue ()D + public final fun getKeyColor ()Lcom/materialkolor/hct/Hct; + public final fun tone (I)I +} + +public final class com/materialkolor/palettes/TonalPalette$Companion { + public final fun fromHct (Lcom/materialkolor/hct/Hct;)Lcom/materialkolor/palettes/TonalPalette; + public final fun fromHueAndChroma (DD)Lcom/materialkolor/palettes/TonalPalette; + public final fun fromInt (I)Lcom/materialkolor/palettes/TonalPalette; +} + +public final class com/materialkolor/quantize/QuantizerCelebi { + public static final field INSTANCE Lcom/materialkolor/quantize/QuantizerCelebi; + public final fun quantize ([II)Ljava/util/Map; +} + +public class com/materialkolor/scheme/DynamicScheme { + public static final field Companion Lcom/materialkolor/scheme/DynamicScheme$Companion; + public fun (Lcom/materialkolor/hct/Hct;Lcom/materialkolor/scheme/Variant;ZDLcom/materialkolor/palettes/TonalPalette;Lcom/materialkolor/palettes/TonalPalette;Lcom/materialkolor/palettes/TonalPalette;Lcom/materialkolor/palettes/TonalPalette;Lcom/materialkolor/palettes/TonalPalette;)V + public final fun getContrastLevel ()D + public final fun getErrorPalette ()Lcom/materialkolor/palettes/TonalPalette; + public final fun getNeutralPalette ()Lcom/materialkolor/palettes/TonalPalette; + public final fun getNeutralVariantPalette ()Lcom/materialkolor/palettes/TonalPalette; + public final fun getPrimaryPalette ()Lcom/materialkolor/palettes/TonalPalette; + public final fun getSecondaryPalette ()Lcom/materialkolor/palettes/TonalPalette; + public final fun getSourceColorArgb ()I + public final fun getSourceColorHct ()Lcom/materialkolor/hct/Hct; + public final fun getTertiaryPalette ()Lcom/materialkolor/palettes/TonalPalette; + public final fun getVariant ()Lcom/materialkolor/scheme/Variant; + public final fun isDark ()Z +} + +public final class com/materialkolor/scheme/DynamicScheme$Companion { + public final fun getRotatedHue (Lcom/materialkolor/hct/Hct;[D[D)D +} + +public final class com/materialkolor/scheme/SchemeContent : com/materialkolor/scheme/DynamicScheme { + public fun (Lcom/materialkolor/hct/Hct;ZD)V +} + +public final class com/materialkolor/scheme/SchemeExpressive : com/materialkolor/scheme/DynamicScheme { + public fun (Lcom/materialkolor/hct/Hct;ZD)V +} + +public final class com/materialkolor/scheme/SchemeFidelity : com/materialkolor/scheme/DynamicScheme { + public fun (Lcom/materialkolor/hct/Hct;ZD)V +} + +public final class com/materialkolor/scheme/SchemeFruitSalad : com/materialkolor/scheme/DynamicScheme { + public fun (Lcom/materialkolor/hct/Hct;ZD)V +} + +public final class com/materialkolor/scheme/SchemeMonochrome : com/materialkolor/scheme/DynamicScheme { + public fun (Lcom/materialkolor/hct/Hct;ZD)V +} + +public final class com/materialkolor/scheme/SchemeNeutral : com/materialkolor/scheme/DynamicScheme { + public fun (Lcom/materialkolor/hct/Hct;ZD)V +} + +public final class com/materialkolor/scheme/SchemeRainbow : com/materialkolor/scheme/DynamicScheme { + public fun (Lcom/materialkolor/hct/Hct;ZD)V +} + +public final class com/materialkolor/scheme/SchemeTonalSpot : com/materialkolor/scheme/DynamicScheme { + public fun (Lcom/materialkolor/hct/Hct;ZD)V +} + +public final class com/materialkolor/scheme/SchemeVibrant : com/materialkolor/scheme/DynamicScheme { + public fun (Lcom/materialkolor/hct/Hct;ZD)V +} + +public final class com/materialkolor/scheme/Variant : java/lang/Enum { + public static final field CONTENT Lcom/materialkolor/scheme/Variant; + public static final field EXPRESSIVE Lcom/materialkolor/scheme/Variant; + public static final field FIDELITY Lcom/materialkolor/scheme/Variant; + public static final field FRUIT_SALAD Lcom/materialkolor/scheme/Variant; + public static final field MONOCHROME Lcom/materialkolor/scheme/Variant; + public static final field NEUTRAL Lcom/materialkolor/scheme/Variant; + public static final field RAINBOW Lcom/materialkolor/scheme/Variant; + public static final field TONAL_SPOT Lcom/materialkolor/scheme/Variant; + public static final field VIBRANT Lcom/materialkolor/scheme/Variant; + public static fun getEntries ()Lkotlin/enums/EnumEntries; + public static fun valueOf (Ljava/lang/String;)Lcom/materialkolor/scheme/Variant; + public static fun values ()[Lcom/materialkolor/scheme/Variant; +} + +public final class com/materialkolor/score/Score { + public static final field INSTANCE Lcom/materialkolor/score/Score; + public final fun score (Ljava/util/Map;ILjava/lang/Integer;Z)Ljava/util/List; + public static synthetic fun score$default (Lcom/materialkolor/score/Score;Ljava/util/Map;ILjava/lang/Integer;ZILjava/lang/Object;)Ljava/util/List; +} + +public final class com/materialkolor/temperature/TemperatureCache { + public static final field Companion Lcom/materialkolor/temperature/TemperatureCache$Companion; + public fun (Lcom/materialkolor/hct/Hct;)V + public final fun getAnalogousColors ()Ljava/util/List; + public final fun getAnalogousColors (II)Ljava/util/List; + public final fun getComplement ()Lcom/materialkolor/hct/Hct; + public final fun getRelativeTemperature (Lcom/materialkolor/hct/Hct;)D +} + +public final class com/materialkolor/temperature/TemperatureCache$Companion { + public final fun rawTemperature (Lcom/materialkolor/hct/Hct;)D +} + +public final class com/materialkolor/utils/ColorUtils { + public static final field INSTANCE Lcom/materialkolor/utils/ColorUtils; + public final fun argbFromLab (DDD)I + public final fun argbFromLinrgb ([D)I + public final fun argbFromLstar (D)I + public final fun argbFromRgb (III)I + public final fun argbFromXyz (DDD)I + public final fun blueFromArgb (I)I + public final fun calculateLuminance (I)D + public final fun delinearized (D)I + public final fun greenFromArgb (I)I + public final fun labF (D)D + public final fun labFromArgb (I)[D + public final fun labInvf (D)D + public final fun linearized (I)D + public final fun lstarFromArgb (I)D + public final fun lstarFromY (D)D + public final fun redFromArgb (I)I + public final fun whitePointD65 ()[D + public final fun xyzFromArgb (I)[D + public final fun yFromLstar (D)D +} + diff --git a/material-color-utilities/build.gradle.kts b/material-color-utilities/build.gradle.kts index b7aa4aa..4317103 100644 --- a/material-color-utilities/build.gradle.kts +++ b/material-color-utilities/build.gradle.kts @@ -7,6 +7,8 @@ plugins { } kotlin { + explicitApi() + applyDefaultHierarchyTemplate() androidTarget { diff --git a/material-color-utilities/src/commonMain/kotlin/com/materialkolor/blend/Blend.kt b/material-color-utilities/src/commonMain/kotlin/com/materialkolor/blend/Blend.kt index 977e193..c1a0c9a 100644 --- a/material-color-utilities/src/commonMain/kotlin/com/materialkolor/blend/Blend.kt +++ b/material-color-utilities/src/commonMain/kotlin/com/materialkolor/blend/Blend.kt @@ -24,7 +24,10 @@ import com.materialkolor.utils.MathUtils.rotationDirection import com.materialkolor.utils.MathUtils.sanitizeDegrees import kotlin.math.min -/** Functions for blending in HCT and CAM16. */ +/** + * Functions for blending in HCT and CAM16. + */ +@Suppress("MemberVisibilityCanBePrivate") public object Blend { /** @@ -36,7 +39,7 @@ public object Blend { * @return The design color with a hue shifted towards the system's color, a slightly * warmer/cooler variant of the design color's hue. */ - fun harmonize(designColor: Int, sourceColor: Int): Int { + public fun harmonize(designColor: Int, sourceColor: Int): Int { val fromHct = Hct.fromInt(designColor) val toHct = Hct.fromInt(sourceColor) return harmonize(fromHct, toHct).toInt() @@ -51,7 +54,7 @@ public object Blend { * @return The design color with a hue shifted towards the system's color, a slightly * warmer/cooler variant of the design color's hue. */ - fun harmonize(designColor: Hct, sourceColor: Hct): Hct { + public fun harmonize(designColor: Hct, sourceColor: Hct): Hct { val differenceDegrees = differenceDegrees(designColor.hue, sourceColor.hue) val rotationDegrees: Double = min(differenceDegrees * 0.5, 15.0) val rotationDirection = rotationDirection(designColor.hue, sourceColor.hue) @@ -68,7 +71,7 @@ public object Blend { * @param amount how much blending to perform; 0.0 >= and <= 1.0 * @return from, with a hue blended towards to. Chroma and tone are constant. */ - fun hctHue(from: Int, to: Int, amount: Double): Int { + public fun hctHue(from: Int, to: Int, amount: Double): Int { val ucs = cam16Ucs(from, to, amount) val ucsCam = Cam16.fromInt(ucs) val fromCam = Cam16.fromInt(from) @@ -84,7 +87,7 @@ public object Blend { * @param amount how much blending to perform; 0.0 >= and <= 1.0 * @return from, blended towards to. Hue, chroma, and tone will change. */ - fun cam16Ucs(from: Int, to: Int, amount: Double): Int { + public fun cam16Ucs(from: Int, to: Int, amount: Double): Int { val fromCam = Cam16.fromInt(from) val toCam = Cam16.fromInt(to) val fromJ = fromCam.jstar diff --git a/material-color-utilities/src/commonMain/kotlin/com/materialkolor/contrast/Contrast.kt b/material-color-utilities/src/commonMain/kotlin/com/materialkolor/contrast/Contrast.kt index be85fde..f135838 100644 --- a/material-color-utilities/src/commonMain/kotlin/com/materialkolor/contrast/Contrast.kt +++ b/material-color-utilities/src/commonMain/kotlin/com/materialkolor/contrast/Contrast.kt @@ -32,19 +32,19 @@ import kotlin.math.max * becomes HCT's tone and L*a*b*'s' L*. */ @Suppress("unused", "MemberVisibilityCanBePrivate") -object Contrast { +public object Contrast { // The minimum contrast ratio of two colors. // Contrast ratio equation = lighter + 5 / darker + 5, if lighter == darker, ratio == 1. - const val RATIO_MIN = 1.0 + private const val RATIO_MIN = 1.0 // The maximum contrast ratio of two colors. // Contrast ratio equation = lighter + 5 / darker + 5. Lighter and darker scale from 0 to 100. // If lighter == 100, darker = 0, ratio == 21. - const val RATIO_MAX = 21.0 - const val RATIO_30 = 3.0 - const val RATIO_45 = 4.5 - const val RATIO_70 = 7.0 + private const val RATIO_MAX = 21.0 + private const val RATIO_30 = 3.0 + private const val RATIO_45 = 4.5 + private const val RATIO_70 = 7.0 // Given a color and a contrast ratio to reach, the luminance of a color that reaches that ratio // with the color can be calculated. However, that luminance may not contrast as desired, i.e. the @@ -92,7 +92,7 @@ object Contrast { * * The equation is ratio = lighter Y + 5 / darker Y + 5. */ - fun ratioOfYs(y1: Double, y2: Double): Double { + public fun ratioOfYs(y1: Double, y2: Double): Double { val lighter: Double = max(y1, y2) val darker = if (lighter == y2) y1 else y2 return (lighter + 5.0) / (darker + 5.0) @@ -113,7 +113,7 @@ object Contrast { * color's lightness to in order to reach their desired contrast, instead of guessing & checking * with hex codes. */ - fun ratioOfTones(tone1: Double, tone2: Double): Double { + public fun ratioOfTones(tone1: Double, tone2: Double): Double { return ratioOfYs(yFromLstar(tone1), yFromLstar(tone2)) } @@ -124,7 +124,7 @@ object Contrast { * @param tone Tone return value must contrast with. * @param ratio Desired contrast ratio of return value and tone parameter. */ - fun lighter(tone: Double, ratio: Double): Double { + public fun lighter(tone: Double, ratio: Double): Double { if (tone < 0.0 || tone > 100.0) { return -1.0 } @@ -155,7 +155,7 @@ object Contrast { * @param tone Tone return value must contrast with. * @param ratio Desired contrast ratio of return value and tone parameter. */ - fun lighterUnsafe(tone: Double, ratio: Double): Double { + public fun lighterUnsafe(tone: Double, ratio: Double): Double { val lighterSafe = lighter(tone, ratio) return if (lighterSafe < 0.0) 100.0 else lighterSafe } @@ -167,7 +167,7 @@ object Contrast { * @param tone Tone return value must contrast with. * @param ratio Desired contrast ratio of return value and tone parameter. */ - fun darker(tone: Double, ratio: Double): Double { + public fun darker(tone: Double, ratio: Double): Double { if (tone < 0.0 || tone > 100.0) { return -1.0 } @@ -200,7 +200,7 @@ object Contrast { * @param tone Tone return value must contrast with. * @param ratio Desired contrast ratio of return value and tone parameter. */ - fun darkerUnsafe(tone: Double, ratio: Double): Double { + public fun darkerUnsafe(tone: Double, ratio: Double): Double { val darkerSafe = darker(tone, ratio) return max(0.0, darkerSafe) } diff --git a/material-color-utilities/src/commonMain/kotlin/com/materialkolor/dislike/DislikeAnalyzer.kt b/material-color-utilities/src/commonMain/kotlin/com/materialkolor/dislike/DislikeAnalyzer.kt index bb7653b..1612b5f 100644 --- a/material-color-utilities/src/commonMain/kotlin/com/materialkolor/dislike/DislikeAnalyzer.kt +++ b/material-color-utilities/src/commonMain/kotlin/com/materialkolor/dislike/DislikeAnalyzer.kt @@ -28,24 +28,24 @@ import kotlin.math.round * Psychology (2015). */ @Suppress("MemberVisibilityCanBePrivate") -object DislikeAnalyzer { +public object DislikeAnalyzer { /** * Returns true if color is disliked. * * Disliked is defined as a dark yellow-green that is not neutral. */ - fun isDisliked(hct: Hct): Boolean { + public fun isDisliked(hct: Hct): Boolean { val huePasses = round(hct.hue) in 90.0..111.0 val chromaPasses: Boolean = round(hct.chroma) > 16.0 val tonePasses: Boolean = round(hct.tone) < 65.0 return huePasses && chromaPasses && tonePasses } - /** If color is disliked, lighten it to make it likable. */ - fun fixIfDisliked(hct: Hct): Hct { - return if (isDisliked(hct)) { - Hct.from(hct.hue, hct.chroma, 70.0) - } else hct + /** + * If color is disliked, lighten it to make it likable. + */ + public fun fixIfDisliked(hct: Hct): Hct { + return if (isDisliked(hct)) Hct.from(hct.hue, hct.chroma, 70.0) else hct } } diff --git a/material-color-utilities/src/commonMain/kotlin/com/materialkolor/dynamiccolor/ContrastCurve.kt b/material-color-utilities/src/commonMain/kotlin/com/materialkolor/dynamiccolor/ContrastCurve.kt index 9673a1c..3907d84 100644 --- a/material-color-utilities/src/commonMain/kotlin/com/materialkolor/dynamiccolor/ContrastCurve.kt +++ b/material-color-utilities/src/commonMain/kotlin/com/materialkolor/dynamiccolor/ContrastCurve.kt @@ -30,7 +30,7 @@ import com.materialkolor.utils.MathUtils.lerp * @param medium Value for contrast level 0.5 * @param high Value for contrast level 1.0 */ -class ContrastCurve( +public class ContrastCurve( private val low: Double, private val normal: Double, private val medium: Double, @@ -44,7 +44,7 @@ class ContrastCurve( * is the highest. * @return The value. For contrast ratios, a number between 1.0 and 21.0. */ - fun get(contrastLevel: Double): Double = when { + public fun get(contrastLevel: Double): Double = when { contrastLevel <= -1.0 -> low contrastLevel < 0.0 -> lerp(low, normal, (contrastLevel - -1) / 1) contrastLevel < 0.5 -> lerp(normal, medium, (contrastLevel - 0) / 0.5) diff --git a/material-color-utilities/src/commonMain/kotlin/com/materialkolor/dynamiccolor/DynamicColor.kt b/material-color-utilities/src/commonMain/kotlin/com/materialkolor/dynamiccolor/DynamicColor.kt index d8a75e1..c3b1355 100644 --- a/material-color-utilities/src/commonMain/kotlin/com/materialkolor/dynamiccolor/DynamicColor.kt +++ b/material-color-utilities/src/commonMain/kotlin/com/materialkolor/dynamiccolor/DynamicColor.kt @@ -71,16 +71,16 @@ import kotlin.math.round * @param opacity A function returning the opacity of a color, as a number between 0 and 1. */ @Suppress("MemberVisibilityCanBePrivate", "unused") -class DynamicColor( - val name: String, - val palette: (DynamicScheme) -> TonalPalette, - val tone: (DynamicScheme) -> Double, - val isBackground: Boolean, - val background: ((DynamicScheme) -> DynamicColor)?, - val secondBackground: ((DynamicScheme) -> DynamicColor)?, - val contrastCurve: ContrastCurve?, - val toneDeltaPair: ((DynamicScheme) -> ToneDeltaPair)?, - val opacity: ((DynamicScheme) -> Double)? = null, +public class DynamicColor( + public val name: String, + public val palette: (DynamicScheme) -> TonalPalette, + public val tone: (DynamicScheme) -> Double, + public val isBackground: Boolean, + public val background: ((DynamicScheme) -> DynamicColor)?, + public val secondBackground: ((DynamicScheme) -> DynamicColor)?, + public val contrastCurve: ContrastCurve?, + public val toneDeltaPair: ((DynamicScheme) -> ToneDeltaPair)?, + public val opacity: ((DynamicScheme) -> Double)? = null, ) { private val hctCache: HashMap = HashMap() @@ -91,7 +91,7 @@ class DynamicColor( * @param scheme Defines the conditions of the user interface, for example, whether or not it is * dark mode or light mode, and what the desired contrast level is. */ - fun getArgb(scheme: DynamicScheme): Int { + public fun getArgb(scheme: DynamicScheme): Int { val argb: Int = getHct(scheme).toInt() if (opacity == null) { return argb @@ -107,7 +107,7 @@ class DynamicColor( * @param scheme Defines the conditions of the user interface, for example, whether or not it is * dark mode or light mode, and what the desired contrast level is. */ - fun getHct(scheme: DynamicScheme): Hct { + public fun getHct(scheme: DynamicScheme): Hct { val cachedAnswer = hctCache[scheme] if (cachedAnswer != null) { return cachedAnswer @@ -132,7 +132,7 @@ class DynamicColor( /** * Returns the tone in HCT, ranging from 0 to 100, of the resolved color given scheme. */ - fun getTone(scheme: DynamicScheme): Double { + public fun getTone(scheme: DynamicScheme): Double { val decreasingContrast: Boolean = scheme.contrastLevel < 0 // Case 1: dual foreground, pair of colors with delta constraint. @@ -279,7 +279,7 @@ class DynamicColor( } } - companion object { + public companion object { /** * A convenience constructor for DynamicColor. @@ -302,7 +302,7 @@ class DynamicColor( * a tonal palette, when contrast adjustments are made, intended chroma can be preserved. * @param tone Function that provides a tone, given a DynamicScheme. */ - fun fromPalette( + public fun fromPalette( name: String, palette: (DynamicScheme) -> TonalPalette, tone: (DynamicScheme) -> Double, @@ -340,7 +340,7 @@ class DynamicColor( * @param isBackground Whether this dynamic color is a background, with some other color as the * foreground. */ - fun fromPalette( + public fun fromPalette( name: String, palette: (DynamicScheme) -> TonalPalette, tone: (DynamicScheme) -> Double, @@ -364,7 +364,7 @@ class DynamicColor( * @param name The name of the dynamic color. * @param argb The source color from which to extract the hue and chroma. */ - fun fromArgb(name: String, argb: Int): DynamicColor { + public fun fromArgb(name: String, argb: Int): DynamicColor { val hct: Hct = Hct.fromInt(argb) val palette = TonalPalette.fromInt(argb) return fromPalette(name, { palette }, { hct.tone }) @@ -374,7 +374,7 @@ class DynamicColor( * Given a background tone, find a foreground tone, while ensuring they reach a contrast ratio * that is as close to ratio as possible. */ - fun foregroundTone(bgTone: Double, ratio: Double): Double { + public fun foregroundTone(bgTone: Double, ratio: Double): Double { val lighterTone: Double = Contrast.lighterUnsafe(bgTone, ratio) val darkerTone: Double = Contrast.darkerUnsafe(bgTone, ratio) val lighterRatio: Double = Contrast.ratioOfTones(lighterTone, bgTone) @@ -403,7 +403,7 @@ class DynamicColor( * Adjust a tone down such that white has 4.5 contrast, if the tone is reasonably close to * supporting it. */ - fun enableLightForeground(tone: Double): Double { + public fun enableLightForeground(tone: Double): Double { return if (tonePrefersLightForeground(tone) && !toneAllowsLightForeground(tone)) 49.0 else tone } @@ -418,9 +418,9 @@ class DynamicColor( * Since `tertiaryContainer` in dark monochrome scheme requires a tone of 60, it should not be * adjusted. Therefore, 60 is excluded here. */ - fun tonePrefersLightForeground(tone: Double): Boolean = round(tone) < 60 + public fun tonePrefersLightForeground(tone: Double): Boolean = round(tone) < 60 /** Tones less than ~T50 always permit white at 4.5 contrast. */ - fun toneAllowsLightForeground(tone: Double): Boolean = round(tone) <= 49 + public fun toneAllowsLightForeground(tone: Double): Boolean = round(tone) <= 49 } } diff --git a/material-color-utilities/src/commonMain/kotlin/com/materialkolor/dynamiccolor/MaterialDynamicColors.kt b/material-color-utilities/src/commonMain/kotlin/com/materialkolor/dynamiccolor/MaterialDynamicColors.kt index 69cf9d3..3f1f785 100644 --- a/material-color-utilities/src/commonMain/kotlin/com/materialkolor/dynamiccolor/MaterialDynamicColors.kt +++ b/material-color-utilities/src/commonMain/kotlin/com/materialkolor/dynamiccolor/MaterialDynamicColors.kt @@ -29,46 +29,46 @@ import kotlin.math.max * see [MaterialColorUtilities](https://github.com/material-foundation/material-color-utilities/commit/c3681e12b72202723657b9ce5cf8dfdf7efb0781) */ @Suppress("unused", "MemberVisibilityCanBePrivate") -class MaterialDynamicColors( +public class MaterialDynamicColors( private val isExtendedFidelity: Boolean = false, ) { - fun highestSurface(scheme: DynamicScheme): DynamicColor { + public fun highestSurface(scheme: DynamicScheme): DynamicColor { return if (scheme.isDark) surfaceBright() else surfaceDim() } // Compatibility Keys Colors for Android - fun primaryPaletteKeyColor(): DynamicColor = DynamicColor.fromPalette( + public fun primaryPaletteKeyColor(): DynamicColor = DynamicColor.fromPalette( name = "primary_palette_key_color", palette = { scheme -> scheme.primaryPalette }, tone = { scheme -> scheme.primaryPalette.keyColor.tone }, ) - fun secondaryPaletteKeyColor(): DynamicColor = DynamicColor.fromPalette( + public fun secondaryPaletteKeyColor(): DynamicColor = DynamicColor.fromPalette( name = "secondary_palette_key_color", palette = { scheme -> scheme.secondaryPalette }, tone = { scheme -> scheme.secondaryPalette.keyColor.tone }, ) - fun tertiaryPaletteKeyColor(): DynamicColor = DynamicColor.fromPalette( + public fun tertiaryPaletteKeyColor(): DynamicColor = DynamicColor.fromPalette( name = "tertiary_palette_key_color", palette = { scheme -> scheme.tertiaryPalette }, tone = { scheme -> scheme.tertiaryPalette.keyColor.tone }, ) - fun neutralPaletteKeyColor(): DynamicColor = DynamicColor.fromPalette( + public fun neutralPaletteKeyColor(): DynamicColor = DynamicColor.fromPalette( name = "neutral_palette_key_color", palette = { scheme -> scheme.neutralPalette }, tone = { scheme -> scheme.neutralPalette.keyColor.tone }, ) - fun neutralVariantPaletteKeyColor(): DynamicColor = DynamicColor.fromPalette( + public fun neutralVariantPaletteKeyColor(): DynamicColor = DynamicColor.fromPalette( name = "neutral_variant_palette_key_color", palette = { scheme -> scheme.neutralVariantPalette }, tone = { scheme -> scheme.neutralVariantPalette.keyColor.tone }, ) - fun background(): DynamicColor = DynamicColor( + public fun background(): DynamicColor = DynamicColor( name = "background", palette = { scheme -> scheme.neutralPalette }, tone = { scheme -> if (scheme.isDark) 6.0 else 98.0 }, @@ -79,7 +79,7 @@ class MaterialDynamicColors( toneDeltaPair = null, ) - fun onBackground(): DynamicColor = DynamicColor( + public fun onBackground(): DynamicColor = DynamicColor( name = "on_background", palette = { scheme -> scheme.neutralPalette }, tone = { scheme -> if (scheme.isDark) 90.0 else 10.0 }, @@ -90,7 +90,7 @@ class MaterialDynamicColors( toneDeltaPair = null, ) - fun surface(): DynamicColor = DynamicColor( + public fun surface(): DynamicColor = DynamicColor( name = "surface", palette = { scheme -> scheme.neutralPalette }, tone = { scheme -> if (scheme.isDark) 6.0 else 98.0 }, @@ -101,7 +101,7 @@ class MaterialDynamicColors( toneDeltaPair = null, ) - fun surfaceDim(): DynamicColor = DynamicColor( + public fun surfaceDim(): DynamicColor = DynamicColor( name = "surface_dim", palette = { scheme -> scheme.neutralPalette }, tone = { scheme -> @@ -115,7 +115,7 @@ class MaterialDynamicColors( toneDeltaPair = null, ) - fun surfaceBright(): DynamicColor = DynamicColor( + public fun surfaceBright(): DynamicColor = DynamicColor( name = "surface_bright", palette = { scheme -> scheme.neutralPalette }, tone = { scheme -> @@ -129,7 +129,7 @@ class MaterialDynamicColors( toneDeltaPair = null, ) - fun surfaceContainerLowest(): DynamicColor = DynamicColor( + public fun surfaceContainerLowest(): DynamicColor = DynamicColor( name = "surface_container_lowest", palette = { scheme -> scheme.neutralPalette }, tone = { scheme -> @@ -143,7 +143,7 @@ class MaterialDynamicColors( toneDeltaPair = null, ) - fun surfaceContainerLow(): DynamicColor = DynamicColor( + public fun surfaceContainerLow(): DynamicColor = DynamicColor( name = "surface_container_low", palette = { scheme -> scheme.neutralPalette }, tone = { scheme -> @@ -157,7 +157,7 @@ class MaterialDynamicColors( toneDeltaPair = null, ) - fun surfaceContainer(): DynamicColor = DynamicColor( + public fun surfaceContainer(): DynamicColor = DynamicColor( name = "surface_container", palette = { scheme -> scheme.neutralPalette }, tone = { scheme -> @@ -171,7 +171,7 @@ class MaterialDynamicColors( toneDeltaPair = null, ) - fun surfaceContainerHigh(): DynamicColor = DynamicColor( + public fun surfaceContainerHigh(): DynamicColor = DynamicColor( name = "surface_container_high", palette = { scheme -> scheme.neutralPalette }, tone = { scheme -> @@ -185,7 +185,7 @@ class MaterialDynamicColors( toneDeltaPair = null, ) - fun surfaceContainerHighest(): DynamicColor = DynamicColor( + public fun surfaceContainerHighest(): DynamicColor = DynamicColor( name = "surface_container_highest", palette = { scheme -> scheme.neutralPalette }, tone = { scheme -> @@ -199,7 +199,7 @@ class MaterialDynamicColors( toneDeltaPair = null, ) - fun onSurface(): DynamicColor = DynamicColor( + public fun onSurface(): DynamicColor = DynamicColor( name = "on_surface", palette = { scheme -> scheme.neutralPalette }, tone = { scheme -> if (scheme.isDark) 90.0 else 10.0 }, @@ -210,7 +210,7 @@ class MaterialDynamicColors( toneDeltaPair = null, ) - fun surfaceVariant(): DynamicColor = DynamicColor( + public fun surfaceVariant(): DynamicColor = DynamicColor( name = "surface_variant", palette = { scheme -> scheme.neutralVariantPalette }, tone = { scheme -> if (scheme.isDark) 30.0 else 90.0 }, @@ -221,7 +221,7 @@ class MaterialDynamicColors( toneDeltaPair = null, ) - fun onSurfaceVariant(): DynamicColor = DynamicColor( + public fun onSurfaceVariant(): DynamicColor = DynamicColor( name = "on_surface_variant", palette = { scheme -> scheme.neutralVariantPalette }, tone = { scheme -> if (scheme.isDark) 80.0 else 30.0 }, @@ -232,7 +232,7 @@ class MaterialDynamicColors( toneDeltaPair = null, ) - fun inverseSurface(): DynamicColor = DynamicColor( + public fun inverseSurface(): DynamicColor = DynamicColor( name = "inverse_surface", palette = { scheme -> scheme.neutralPalette }, tone = { scheme -> if (scheme.isDark) 90.0 else 20.0 }, @@ -243,7 +243,7 @@ class MaterialDynamicColors( toneDeltaPair = null, ) - fun inverseOnSurface(): DynamicColor = DynamicColor( + public fun inverseOnSurface(): DynamicColor = DynamicColor( name = "inverse_on_surface", palette = { scheme -> scheme.neutralPalette }, tone = { scheme -> if (scheme.isDark) 20.0 else 95.0 }, @@ -254,7 +254,7 @@ class MaterialDynamicColors( toneDeltaPair = null, ) - fun outline(): DynamicColor = DynamicColor( + public fun outline(): DynamicColor = DynamicColor( name = "outline", palette = { scheme -> scheme.neutralVariantPalette }, tone = { scheme -> if (scheme.isDark) 60.0 else 50.0 }, @@ -265,7 +265,7 @@ class MaterialDynamicColors( toneDeltaPair = null, ) - fun outlineVariant(): DynamicColor = DynamicColor( + public fun outlineVariant(): DynamicColor = DynamicColor( name = "outline_variant", palette = { scheme -> scheme.neutralVariantPalette }, tone = { scheme -> if (scheme.isDark) 30.0 else 80.0 }, @@ -276,7 +276,7 @@ class MaterialDynamicColors( toneDeltaPair = null, ) - fun shadow(): DynamicColor = DynamicColor( + public fun shadow(): DynamicColor = DynamicColor( name = "shadow", palette = { scheme -> scheme.neutralPalette }, tone = { 0.0 }, @@ -287,7 +287,7 @@ class MaterialDynamicColors( toneDeltaPair = null, ) - fun scrim(): DynamicColor = DynamicColor( + public fun scrim(): DynamicColor = DynamicColor( name = "scrim", palette = { scheme -> scheme.neutralPalette }, tone = { 0.0 }, @@ -298,7 +298,7 @@ class MaterialDynamicColors( toneDeltaPair = null, ) - fun surfaceTint(): DynamicColor = DynamicColor( + public fun surfaceTint(): DynamicColor = DynamicColor( name = "surface_tint", palette = { scheme -> scheme.primaryPalette }, tone = { scheme -> if (scheme.isDark) 80.0 else 40.0 }, @@ -309,7 +309,7 @@ class MaterialDynamicColors( toneDeltaPair = null, ) - fun primary(): DynamicColor = DynamicColor( + public fun primary(): DynamicColor = DynamicColor( name = "primary", palette = { scheme -> scheme.primaryPalette }, tone = { scheme -> @@ -333,7 +333,7 @@ class MaterialDynamicColors( }, ) - fun onPrimary(): DynamicColor = DynamicColor( + public fun onPrimary(): DynamicColor = DynamicColor( name = "on_primary", palette = { scheme -> scheme.primaryPalette }, tone = { scheme -> @@ -349,7 +349,7 @@ class MaterialDynamicColors( toneDeltaPair = null, ) - fun primaryContainer(): DynamicColor = DynamicColor( + public fun primaryContainer(): DynamicColor = DynamicColor( name = "primary_container", palette = { scheme -> scheme.primaryPalette }, tone = { scheme -> @@ -374,7 +374,7 @@ class MaterialDynamicColors( } ) - fun onPrimaryContainer(): DynamicColor = DynamicColor( + public fun onPrimaryContainer(): DynamicColor = DynamicColor( name = "on_primary_container", palette = { scheme -> scheme.primaryPalette }, tone = { scheme -> @@ -393,7 +393,7 @@ class MaterialDynamicColors( toneDeltaPair = null, ) - fun inversePrimary(): DynamicColor = DynamicColor( + public fun inversePrimary(): DynamicColor = DynamicColor( name = "inverse_primary", palette = { scheme -> scheme.primaryPalette }, tone = { scheme -> if (scheme.isDark) 40.0 else 80.0 }, @@ -404,7 +404,7 @@ class MaterialDynamicColors( toneDeltaPair = null, ) - fun secondary(): DynamicColor = DynamicColor( + public fun secondary(): DynamicColor = DynamicColor( name = "secondary", palette = { scheme -> scheme.secondaryPalette }, tone = { scheme -> if (scheme.isDark) 80.0 else 40.0 }, @@ -423,7 +423,7 @@ class MaterialDynamicColors( } ) - fun onSecondary(): DynamicColor = DynamicColor( + public fun onSecondary(): DynamicColor = DynamicColor( name = "on_secondary", palette = { scheme -> scheme.secondaryPalette }, tone = { scheme -> @@ -439,7 +439,7 @@ class MaterialDynamicColors( toneDeltaPair = null, ) - fun secondaryContainer(): DynamicColor = DynamicColor( + public fun secondaryContainer(): DynamicColor = DynamicColor( name = "secondary_container", palette = { scheme -> scheme.secondaryPalette }, tone = { scheme -> @@ -470,7 +470,7 @@ class MaterialDynamicColors( } ) - fun onSecondaryContainer(): DynamicColor = DynamicColor( + public fun onSecondaryContainer(): DynamicColor = DynamicColor( name = "on_secondary_container", palette = { scheme -> scheme.secondaryPalette }, tone = { scheme -> @@ -486,7 +486,7 @@ class MaterialDynamicColors( toneDeltaPair = null, ) - fun tertiary(): DynamicColor = DynamicColor( + public fun tertiary(): DynamicColor = DynamicColor( name = "tertiary", palette = { scheme -> scheme.tertiaryPalette }, tone = { scheme -> @@ -510,7 +510,7 @@ class MaterialDynamicColors( } ) - fun onTertiary(): DynamicColor = DynamicColor( + public fun onTertiary(): DynamicColor = DynamicColor( name = "on_tertiary", palette = { scheme -> scheme.tertiaryPalette }, tone = { scheme -> @@ -526,7 +526,7 @@ class MaterialDynamicColors( toneDeltaPair = null, ) - fun tertiaryContainer(): DynamicColor = DynamicColor( + public fun tertiaryContainer(): DynamicColor = DynamicColor( name = "tertiary_container", palette = { scheme -> scheme.tertiaryPalette }, tone = { scheme -> @@ -554,7 +554,7 @@ class MaterialDynamicColors( } ) - fun onTertiaryContainer(): DynamicColor = DynamicColor( + public fun onTertiaryContainer(): DynamicColor = DynamicColor( name = "on_tertiary_container", palette = { scheme -> scheme.tertiaryPalette }, tone = { scheme -> @@ -571,7 +571,7 @@ class MaterialDynamicColors( toneDeltaPair = null, ) - fun error(): DynamicColor = DynamicColor( + public fun error(): DynamicColor = DynamicColor( name = "error", palette = { scheme -> scheme.errorPalette }, tone = { scheme -> if (scheme.isDark) 80.0 else 40.0 }, @@ -590,7 +590,7 @@ class MaterialDynamicColors( }, ) - fun onError(): DynamicColor = DynamicColor( + public fun onError(): DynamicColor = DynamicColor( name = "on_error", palette = { scheme -> scheme.errorPalette }, tone = { scheme -> if (scheme.isDark) 20.0 else 100.0 }, @@ -601,7 +601,7 @@ class MaterialDynamicColors( toneDeltaPair = null, ) - fun errorContainer(): DynamicColor = DynamicColor( + public fun errorContainer(): DynamicColor = DynamicColor( name = "error_container", palette = { scheme -> scheme.errorPalette }, tone = { scheme -> if (scheme.isDark) 30.0 else 90.0 }, @@ -620,7 +620,7 @@ class MaterialDynamicColors( }, ) - fun onErrorContainer(): DynamicColor = DynamicColor( + public fun onErrorContainer(): DynamicColor = DynamicColor( name = "on_error_container", palette = { scheme -> scheme.errorPalette }, tone = { scheme -> if (scheme.isDark) 90.0 else 10.0 }, @@ -631,7 +631,7 @@ class MaterialDynamicColors( toneDeltaPair = null, ) - fun primaryFixed(): DynamicColor = DynamicColor( + public fun primaryFixed(): DynamicColor = DynamicColor( name = "primary_fixed", palette = { scheme -> scheme.primaryPalette }, tone = { scheme -> if (isMonochrome(scheme)) 40.0 else 90.0 }, @@ -650,7 +650,7 @@ class MaterialDynamicColors( } ) - fun primaryFixedDim(): DynamicColor = DynamicColor( + public fun primaryFixedDim(): DynamicColor = DynamicColor( name = "primary_fixed_dim", palette = { scheme -> scheme.primaryPalette }, tone = { scheme -> if (isMonochrome(scheme)) 30.0 else 80.0 }, @@ -669,7 +669,7 @@ class MaterialDynamicColors( } ) - fun onPrimaryFixed(): DynamicColor = DynamicColor( + public fun onPrimaryFixed(): DynamicColor = DynamicColor( name = "on_primary_fixed", palette = { scheme -> scheme.primaryPalette }, tone = { scheme -> if (isMonochrome(scheme)) 100.0 else 10.0 }, @@ -680,7 +680,7 @@ class MaterialDynamicColors( toneDeltaPair = null, ) - fun onPrimaryFixedVariant(): DynamicColor = DynamicColor( + public fun onPrimaryFixedVariant(): DynamicColor = DynamicColor( name = "on_primary_fixed_variant", palette = { scheme -> scheme.primaryPalette }, tone = { scheme -> if (isMonochrome(scheme)) 90.0 else 30.0 }, @@ -691,7 +691,7 @@ class MaterialDynamicColors( toneDeltaPair = null, ) - fun secondaryFixed(): DynamicColor = DynamicColor( + public fun secondaryFixed(): DynamicColor = DynamicColor( name = "secondary_fixed", palette = { scheme -> scheme.secondaryPalette }, tone = { scheme -> if (isMonochrome(scheme)) 80.0 else 90.0 }, @@ -710,7 +710,7 @@ class MaterialDynamicColors( }, ) - fun secondaryFixedDim(): DynamicColor = DynamicColor( + public fun secondaryFixedDim(): DynamicColor = DynamicColor( name = "secondary_fixed_dim", palette = { scheme -> scheme.secondaryPalette }, tone = { scheme -> if (isMonochrome(scheme)) 70.0 else 80.0 }, @@ -729,7 +729,7 @@ class MaterialDynamicColors( } ) - fun onSecondaryFixed(): DynamicColor = DynamicColor( + public fun onSecondaryFixed(): DynamicColor = DynamicColor( name = "on_secondary_fixed", palette = { scheme -> scheme.secondaryPalette }, tone = { 10.0 }, @@ -740,7 +740,7 @@ class MaterialDynamicColors( toneDeltaPair = null, ) - fun onSecondaryFixedVariant(): DynamicColor = DynamicColor( + public fun onSecondaryFixedVariant(): DynamicColor = DynamicColor( name = "on_secondary_fixed_variant", palette = { scheme -> scheme.secondaryPalette }, tone = { scheme -> if (isMonochrome(scheme)) 25.0 else 30.0 }, @@ -751,7 +751,7 @@ class MaterialDynamicColors( toneDeltaPair = null, ) - fun tertiaryFixed(): DynamicColor = DynamicColor( + public fun tertiaryFixed(): DynamicColor = DynamicColor( name = "tertiary_fixed", palette = { scheme -> scheme.tertiaryPalette }, tone = { scheme -> if (isMonochrome(scheme)) 40.0 else 90.0 }, @@ -770,7 +770,7 @@ class MaterialDynamicColors( }, ) - fun tertiaryFixedDim(): DynamicColor = DynamicColor( + public fun tertiaryFixedDim(): DynamicColor = DynamicColor( name = "tertiary_fixed_dim", palette = { scheme -> scheme.tertiaryPalette }, tone = { scheme -> if (isMonochrome(scheme)) 30.0 else 80.0 }, @@ -789,7 +789,7 @@ class MaterialDynamicColors( }, ) - fun onTertiaryFixed(): DynamicColor = DynamicColor( + public fun onTertiaryFixed(): DynamicColor = DynamicColor( name = "on_tertiary_fixed", palette = { scheme -> scheme.tertiaryPalette }, tone = { scheme -> if (isMonochrome(scheme)) 100.0 else 10.0 }, @@ -800,7 +800,7 @@ class MaterialDynamicColors( toneDeltaPair = null, ) - fun onTertiaryFixedVariant(): DynamicColor = DynamicColor( + public fun onTertiaryFixedVariant(): DynamicColor = DynamicColor( name = "on_tertiary_fixed_variant", palette = { scheme -> scheme.tertiaryPalette }, tone = { scheme -> if (isMonochrome(scheme)) 90.0 else 30.0 }, @@ -825,7 +825,7 @@ class MaterialDynamicColors( * For example, if the same color is on a white background _and_ black background, there's no * way to increase contrast with either without losing contrast with the other. */ - fun controlActivated(): DynamicColor = DynamicColor.fromPalette( + public fun controlActivated(): DynamicColor = DynamicColor.fromPalette( name = "control_activated", palette = { scheme -> scheme.primaryPalette }, tone = { scheme -> if (scheme.isDark) 30.0 else 90.0 }, @@ -836,7 +836,7 @@ class MaterialDynamicColors( * In Material, textColorSecondary points to onSurfaceVariant in the non-disabled state, * which is Neutral Variant T30/80 in light/dark. */ - fun controlNormal(): DynamicColor = DynamicColor.fromPalette( + public fun controlNormal(): DynamicColor = DynamicColor.fromPalette( name = "control_normal", palette = { scheme -> scheme.neutralVariantPalette }, tone = { scheme -> if (scheme.isDark) 80.0 else 30.0 }, @@ -855,7 +855,7 @@ class MaterialDynamicColors( * depending on how MDC resolved alpha for the other cases. * Returning black in dark mode, white in light mode. */ - fun controlHighlight(): DynamicColor = DynamicColor( + public fun controlHighlight(): DynamicColor = DynamicColor( name = "control_highlight", palette = { scheme -> scheme.neutralPalette }, tone = { scheme -> if (scheme.isDark) 100.0 else 0.0 }, @@ -869,7 +869,7 @@ class MaterialDynamicColors( /** * textColorPrimaryInverse documented, in both M3 & GM3, documented as N10/N90. */ - fun textPrimaryInverse(): DynamicColor = DynamicColor.fromPalette( + public fun textPrimaryInverse(): DynamicColor = DynamicColor.fromPalette( name = "text_primary_inverse", palette = { scheme -> scheme.neutralPalette }, tone = { scheme -> if (scheme.isDark) 10.0 else 90.0 }, @@ -879,7 +879,7 @@ class MaterialDynamicColors( * textColorSecondaryInverse and textColorTertiaryInverse both documented, in both M3 & GM3, as * V30/NV80 */ - fun textSecondaryAndTertiaryInverse(): DynamicColor = DynamicColor.fromPalette( + public fun textSecondaryAndTertiaryInverse(): DynamicColor = DynamicColor.fromPalette( name = "text_secondary_and_tertiary_inverse", palette = { scheme -> scheme.neutralVariantPalette }, tone = { scheme -> if (scheme.isDark) 30.0 else 80.0 }, @@ -888,7 +888,7 @@ class MaterialDynamicColors( /** * textColorPrimaryInverseDisableOnly documented, in both M3 & GM3, as N10/N90 */ - fun textPrimaryInverseDisableOnly(): DynamicColor = DynamicColor.fromPalette( + public fun textPrimaryInverseDisableOnly(): DynamicColor = DynamicColor.fromPalette( name = "text_primary_inverse_disable_only", palette = { scheme -> scheme.neutralPalette }, tone = { scheme -> if (scheme.isDark) 10.0 else 90.0 }, @@ -898,7 +898,7 @@ class MaterialDynamicColors( * textColorSecondaryInverse and textColorTertiaryInverse in disabled state both documented, * in both M3 & GM3, as N10/N90 */ - fun textSecondaryAndTertiaryInverseDisabled(): DynamicColor = DynamicColor.fromPalette( + public fun textSecondaryAndTertiaryInverseDisabled(): DynamicColor = DynamicColor.fromPalette( name = "text_secondary_and_tertiary_inverse_disabled", palette = { scheme -> scheme.neutralPalette }, tone = { scheme -> if (scheme.isDark) 10.0 else 90.0 }, @@ -907,7 +907,7 @@ class MaterialDynamicColors( /** * textColorHintInverse documented, in both M3 & GM3, as N10/N90 */ - fun textHintInverse(): DynamicColor = DynamicColor.fromPalette( + public fun textHintInverse(): DynamicColor = DynamicColor.fromPalette( name = "text_hint_inverse", palette = { scheme -> scheme.neutralPalette }, tone = { scheme -> if (scheme.isDark) 10.0 else 90.0 }, @@ -922,13 +922,13 @@ class MaterialDynamicColors( return scheme.variant == Variant.FIDELITY || scheme.variant == Variant.CONTENT } - companion object { + public companion object { private fun isMonochrome(scheme: DynamicScheme): Boolean { return scheme.variant === Variant.MONOCHROME } - fun findDesiredChromaByTone( + private fun findDesiredChromaByTone( hue: Double, chroma: Double, tone: Double, diff --git a/material-color-utilities/src/commonMain/kotlin/com/materialkolor/dynamiccolor/ToneDeltaPair.kt b/material-color-utilities/src/commonMain/kotlin/com/materialkolor/dynamiccolor/ToneDeltaPair.kt index 39d4ccd..769ac60 100644 --- a/material-color-utilities/src/commonMain/kotlin/com/materialkolor/dynamiccolor/ToneDeltaPair.kt +++ b/material-color-utilities/src/commonMain/kotlin/com/materialkolor/dynamiccolor/ToneDeltaPair.kt @@ -42,10 +42,10 @@ package com.materialkolor.dynamiccolor * @param stayTogether Whether these two roles should stay on the same side of the "awkward zone" * (T50-59). This is necessary for certain cases where one role has two backgrounds. */ -class ToneDeltaPair( - val roleA: DynamicColor, - val roleB: DynamicColor, - val delta: Double, - val polarity: TonePolarity, - val stayTogether: Boolean, +public class ToneDeltaPair( + public val roleA: DynamicColor, + public val roleB: DynamicColor, + public val delta: Double, + public val polarity: TonePolarity, + public val stayTogether: Boolean, ) diff --git a/material-color-utilities/src/commonMain/kotlin/com/materialkolor/dynamiccolor/TonePolarity.kt b/material-color-utilities/src/commonMain/kotlin/com/materialkolor/dynamiccolor/TonePolarity.kt index da853fb..0687945 100644 --- a/material-color-utilities/src/commonMain/kotlin/com/materialkolor/dynamiccolor/TonePolarity.kt +++ b/material-color-utilities/src/commonMain/kotlin/com/materialkolor/dynamiccolor/TonePolarity.kt @@ -24,7 +24,7 @@ package com.materialkolor.dynamiccolor * * See `ToneDeltaPair` for details. */ -enum class TonePolarity { +public enum class TonePolarity { DARKER, LIGHTER, NEARER, diff --git a/material-color-utilities/src/commonMain/kotlin/com/materialkolor/hct/Hct.kt b/material-color-utilities/src/commonMain/kotlin/com/materialkolor/hct/Hct.kt index e079b1f..9458def 100644 --- a/material-color-utilities/src/commonMain/kotlin/com/materialkolor/hct/Hct.kt +++ b/material-color-utilities/src/commonMain/kotlin/com/materialkolor/hct/Hct.kt @@ -36,13 +36,13 @@ import com.materialkolor.utils.ColorUtils.lstarFromY * lighting environments. */ @Suppress("unused") -class Hct private constructor( +public class Hct private constructor( private val argb: Int, ) { - val hue: Double - val chroma: Double - val tone: Double + public val hue: Double + public val chroma: Double + public val tone: Double init { val cam16 = Cam16.fromInt(argb) @@ -51,7 +51,7 @@ class Hct private constructor( tone = lstarFromArgb(argb) } - fun toInt(): Int = argb + public fun toInt(): Int = argb /** * Set the hue of this color. Chroma may decrease because chroma has a different maximum for any @@ -59,7 +59,7 @@ class Hct private constructor( * * @param newHue 0 <= newHue < 360; invalid values are corrected. */ - fun withHue(newHue: Double): Hct { + public fun withHue(newHue: Double): Hct { return Hct(HctSolver.solveToInt(newHue, chroma, tone)) } @@ -69,7 +69,7 @@ class Hct private constructor( * * @param newChroma 0 <= newChroma < ? */ - fun withChroma(newChroma: Double): Hct { + public fun withChroma(newChroma: Double): Hct { return Hct(HctSolver.solveToInt(hue, newChroma, tone)) } @@ -79,7 +79,7 @@ class Hct private constructor( * * @param newTone 0 <= newTone <= 100; invalid valids are corrected. */ - fun withTone(newTone: Double): Hct { + public fun withTone(newTone: Double): Hct { return Hct(HctSolver.solveToInt(hue, chroma, newTone)) } @@ -115,7 +115,7 @@ class Hct private constructor( return from(recastInVc.hue, recastInVc.chroma, lstarFromY(viewedInVc[1])) } - companion object { + public companion object { /** * Create an HCT color from hue, chroma, and tone. @@ -126,7 +126,7 @@ class Hct private constructor( * @param tone 0 <= tone <= 100; invalid values are corrected. * @return HCT representation of a color in default viewing conditions. */ - fun from(hue: Double, chroma: Double, tone: Double): Hct { + public fun from(hue: Double, chroma: Double, tone: Double): Hct { return Hct(HctSolver.solveToInt(hue, chroma, tone)) } @@ -136,6 +136,6 @@ class Hct private constructor( * @param argb ARGB representation of a color. * @return HCT representation of a color in default viewing conditions */ - fun fromInt(argb: Int): Hct = Hct(argb) + public fun fromInt(argb: Int): Hct = Hct(argb) } } diff --git a/material-color-utilities/src/commonMain/kotlin/com/materialkolor/hct/HctSolver.kt b/material-color-utilities/src/commonMain/kotlin/com/materialkolor/hct/HctSolver.kt index 8eaa2bc..e037b83 100644 --- a/material-color-utilities/src/commonMain/kotlin/com/materialkolor/hct/HctSolver.kt +++ b/material-color-utilities/src/commonMain/kotlin/com/materialkolor/hct/HctSolver.kt @@ -33,9 +33,11 @@ import kotlin.math.pow import kotlin.math.sin import kotlin.math.sqrt -/** A class that solves the HCT equation. */ +/** + * A class that solves the HCT equation. + */ @Suppress("unused") -internal object HctSolver { +public object HctSolver { private val SCALED_DISCOUNT_FROM_LINRGB = arrayOf( doubleArrayOf(0.001200833568784504, 0.002389694492170889, 0.0002795742885861124), @@ -639,7 +641,7 @@ internal object HctSolver { * chroma, and L* to the desired values, if possible; otherwise, the hue and L* will be * sufficiently close, and chroma will be maximized. */ - fun solveToInt(hueDegrees: Double, chroma: Double, lstar: Double): Int { + public fun solveToInt(hueDegrees: Double, chroma: Double, lstar: Double): Int { val hueDegrees1 = sanitizeDegrees(hueDegrees) if (chroma < 0.0001 || lstar < 0.0001 || lstar > 99.9999) { return argbFromLstar(lstar) @@ -664,7 +666,7 @@ internal object HctSolver { * chroma, and L* to the desired values, if possible; otherwise, the hue and L* will be * sufficiently close, and chroma will be maximized. */ - fun solveToCam(hueDegrees: Double, chroma: Double, lstar: Double): Cam16 { + internal fun solveToCam(hueDegrees: Double, chroma: Double, lstar: Double): Cam16 { return Cam16.fromInt(solveToInt(hueDegrees, chroma, lstar)) } } diff --git a/material-color-utilities/src/commonMain/kotlin/com/materialkolor/palettes/CorePalette.kt b/material-color-utilities/src/commonMain/kotlin/com/materialkolor/palettes/CorePalette.kt index 0e114d7..ceb0773 100644 --- a/material-color-utilities/src/commonMain/kotlin/com/materialkolor/palettes/CorePalette.kt +++ b/material-color-utilities/src/commonMain/kotlin/com/materialkolor/palettes/CorePalette.kt @@ -23,14 +23,14 @@ import kotlin.math.min * An intermediate concept between the key color for a UI theme, and a full color scheme. 5 sets of * tones are generated, all except one use the same hue as the key color, and all vary in chroma. */ -class CorePalette private constructor(argb: Int, isContent: Boolean) { +public class CorePalette private constructor(argb: Int, isContent: Boolean) { - var a1: TonalPalette - var a2: TonalPalette - var a3: TonalPalette - var n1: TonalPalette - var n2: TonalPalette - var error: TonalPalette + public var a1: TonalPalette + public var a2: TonalPalette + public var a3: TonalPalette + public var n1: TonalPalette + public var n2: TonalPalette + public var error: TonalPalette init { val hct = Hct.fromInt(argb) @@ -52,20 +52,20 @@ class CorePalette private constructor(argb: Int, isContent: Boolean) { error = TonalPalette.fromHueAndChroma(hue = 25.0, chroma = 84.0) } - companion object { + public companion object { /** * Create key tones from a color. * * @param argb ARGB representation of a color */ - fun of(argb: Int): CorePalette = CorePalette(argb = argb, isContent = false) + public fun of(argb: Int): CorePalette = CorePalette(argb = argb, isContent = false) /** * Create content key tones from a color. * * @param argb ARGB representation of a color */ - fun contentOf(argb: Int): CorePalette = CorePalette(argb = argb, isContent = true) + public fun contentOf(argb: Int): CorePalette = CorePalette(argb = argb, isContent = true) } } diff --git a/material-color-utilities/src/commonMain/kotlin/com/materialkolor/palettes/TonalPalette.kt b/material-color-utilities/src/commonMain/kotlin/com/materialkolor/palettes/TonalPalette.kt index 67f0fef..12d072d 100644 --- a/material-color-utilities/src/commonMain/kotlin/com/materialkolor/palettes/TonalPalette.kt +++ b/material-color-utilities/src/commonMain/kotlin/com/materialkolor/palettes/TonalPalette.kt @@ -26,10 +26,10 @@ import kotlin.math.round * @param[chroma] The chroma of the Tonal Palette, in HCT. Ranges from 0 to ~130 (for sRGB gamut). * @param[keyColor] The key color is the first tone, starting from T50, that matches the palette's chroma. */ -class TonalPalette private constructor( - var hue: Double, - var chroma: Double, - var keyColor: Hct, +public class TonalPalette private constructor( + public val hue: Double, + public val chroma: Double, + public val keyColor: Hct, ) { private var cache: MutableMap = HashMap() @@ -40,7 +40,7 @@ class TonalPalette private constructor( * @param tone HCT tone, measured from 0 to 100. * @return ARGB representation of a color with that tone. */ - fun tone(tone: Int): Int { + public fun tone(tone: Int): Int { var color = cache[tone] if (color == null) { color = Hct.from(hue, chroma, tone.toDouble()).toInt() @@ -53,9 +53,9 @@ class TonalPalette private constructor( /** * Given a tone, use hue and chroma of palette to create a color, and return it as HCT. */ - fun getHct(tone: Double): Hct = Hct.from(hue, chroma, tone) + public fun getHct(tone: Double): Hct = Hct.from(hue, chroma, tone) - companion object { + public companion object { /** * Create tones using the HCT hue and chroma from a color. @@ -63,7 +63,7 @@ class TonalPalette private constructor( * @param argb ARGB representation of a color * @return Tones matching that color's hue and chroma. */ - fun fromInt(argb: Int): TonalPalette { + public fun fromInt(argb: Int): TonalPalette { return fromHct(Hct.fromInt(argb)) } @@ -73,7 +73,7 @@ class TonalPalette private constructor( * @param hct HCT representation of a color. * @return Tones matching that color's hue and chroma. */ - fun fromHct(hct: Hct): TonalPalette { + public fun fromHct(hct: Hct): TonalPalette { return TonalPalette(hct.hue, hct.chroma, hct) } @@ -84,7 +84,7 @@ class TonalPalette private constructor( * @param chroma HCT chroma * @return Tones matching hue and chroma. */ - fun fromHueAndChroma(hue: Double, chroma: Double): TonalPalette { + public fun fromHueAndChroma(hue: Double, chroma: Double): TonalPalette { return TonalPalette(hue, chroma, createKeyColor(hue, chroma)) } diff --git a/material-color-utilities/src/commonMain/kotlin/com/materialkolor/quantize/PointProvider.kt b/material-color-utilities/src/commonMain/kotlin/com/materialkolor/quantize/PointProvider.kt index 505c6b7..20ab877 100644 --- a/material-color-utilities/src/commonMain/kotlin/com/materialkolor/quantize/PointProvider.kt +++ b/material-color-utilities/src/commonMain/kotlin/com/materialkolor/quantize/PointProvider.kt @@ -15,18 +15,34 @@ */ package com.materialkolor.quantize -/** An interface to allow use of different color spaces by quantizers. */ +/** + * An interface to allow use of different color spaces by quantizers. + */ internal interface PointProvider { - /** The four components in the color space of an sRGB color. */ - fun fromInt(argb: Int): DoubleArray? + /** + * The four components in the color space of an sRGB color. + * + * @param[argb] argb The ARGB (i.e. hex code) representation of this color. + * @return The four components in the color space of an sRGB color. + */ + fun fromInt(argb: Int): DoubleArray - /** The ARGB (i.e. hex code) representation of this color. */ - fun toInt(point: DoubleArray?): Int + /** + * The ARGB (i.e. hex code) representation of this color. + * + * @param[point] The four components in the color space of an sRGB color. + * @return The ARGB (i.e. hex code) representation of this color. + */ + fun toInt(point: DoubleArray): Int /** * Squared distance between two colors. Distance is defined by scientific color spaces and * referred to as delta E. + * + * @param[a] The first color. + * @param[b] The second color. + * @return The squared distance between the two colors. */ - fun distance(a: DoubleArray?, b: DoubleArray?): Double + fun distance(a: DoubleArray, b: DoubleArray): Double } diff --git a/material-color-utilities/src/commonMain/kotlin/com/materialkolor/quantize/PointProviderLab.kt b/material-color-utilities/src/commonMain/kotlin/com/materialkolor/quantize/PointProviderLab.kt index bf892ca..662bcde 100644 --- a/material-color-utilities/src/commonMain/kotlin/com/materialkolor/quantize/PointProviderLab.kt +++ b/material-color-utilities/src/commonMain/kotlin/com/materialkolor/quantize/PointProviderLab.kt @@ -27,14 +27,16 @@ internal class PointProviderLab : PointProvider { /** * Convert a color represented in ARGB to a 3-element array of L*a*b* coordinates of the color. */ - override fun fromInt(argb: Int): DoubleArray? { + override fun fromInt(argb: Int): DoubleArray { val lab = labFromArgb(argb) return doubleArrayOf(lab[0], lab[1], lab[2]) } - /** Convert a 3-element array to a color represented in ARGB. */ - override fun toInt(point: DoubleArray?): Int { - return argbFromLab(point!![0], point[1], point[2]) + /** + * Convert a 3-element array to a color represented in ARGB. + */ + override fun toInt(point: DoubleArray): Int { + return argbFromLab(point[0], point[1], point[2]) } /** @@ -42,12 +44,11 @@ internal class PointProviderLab : PointProvider { * used by quantization algorithms to compare distance, and the relative ordering is the same, * with or without a square root. * - * * This relatively minor optimization is helpful because this method is called at least once * for each pixel in an image. */ - override fun distance(a: DoubleArray?, b: DoubleArray?): Double { - val dL = a!![0] - b!![0] + override fun distance(a: DoubleArray, b: DoubleArray): Double { + val dL = a[0] - b[0] val dA = a[1] - b[1] val dB = a[2] - b[2] return dL * dL + dA * dA + dB * dB diff --git a/material-color-utilities/src/commonMain/kotlin/com/materialkolor/quantize/QuantizerCelebi.kt b/material-color-utilities/src/commonMain/kotlin/com/materialkolor/quantize/QuantizerCelebi.kt index 2a1314a..aa7fcf1 100644 --- a/material-color-utilities/src/commonMain/kotlin/com/materialkolor/quantize/QuantizerCelebi.kt +++ b/material-color-utilities/src/commonMain/kotlin/com/materialkolor/quantize/QuantizerCelebi.kt @@ -25,7 +25,7 @@ package com.materialkolor.quantize * This algorithm was designed by M. Emre Celebi, and was found in their 2011 paper, Improving * the Performance of K-Means for Color Quantization. https://arxiv.org/abs/1101.0395 */ -object QuantizerCelebi { +public object QuantizerCelebi { /** * Reduce the number of colors needed to represented the input, minimizing the difference between @@ -37,7 +37,7 @@ object QuantizerCelebi { * @return Map with keys of colors in ARGB format, and values of number of pixels in the original * image that correspond to the color in the quantized image. */ - fun quantize(pixels: IntArray, maxColors: Int): Map { + public fun quantize(pixels: IntArray, maxColors: Int): Map { val wu = QuantizerWu() val wuResult: QuantizerResult = wu.quantize(pixels, maxColors) val wuClustersAsObjects: Set = wuResult.colorToCount.keys diff --git a/material-color-utilities/src/commonMain/kotlin/com/materialkolor/quantize/QuantizerMap.kt b/material-color-utilities/src/commonMain/kotlin/com/materialkolor/quantize/QuantizerMap.kt index b3e84e3..6590642 100644 --- a/material-color-utilities/src/commonMain/kotlin/com/materialkolor/quantize/QuantizerMap.kt +++ b/material-color-utilities/src/commonMain/kotlin/com/materialkolor/quantize/QuantizerMap.kt @@ -15,7 +15,9 @@ */ package com.materialkolor.quantize -/** Creates a dictionary with keys of colors, and values of count of the color */ +/** + * Creates a dictionary with keys of colors, and values of count of the color + */ internal class QuantizerMap : Quantizer { private var colorToCount: Map? = null diff --git a/material-color-utilities/src/commonMain/kotlin/com/materialkolor/quantize/QuantizerResult.kt b/material-color-utilities/src/commonMain/kotlin/com/materialkolor/quantize/QuantizerResult.kt index b5d98d4..517e3a9 100644 --- a/material-color-utilities/src/commonMain/kotlin/com/materialkolor/quantize/QuantizerResult.kt +++ b/material-color-utilities/src/commonMain/kotlin/com/materialkolor/quantize/QuantizerResult.kt @@ -15,5 +15,10 @@ */ package com.materialkolor.quantize -/** Represents result of a quantizer run */ -internal class QuantizerResult internal constructor(val colorToCount: Map) +import kotlin.jvm.JvmInline + +/** + * Represents result of a quantizer run + */ +@JvmInline +internal value class QuantizerResult(val colorToCount: Map) diff --git a/material-color-utilities/src/commonMain/kotlin/com/materialkolor/quantize/QuantizerWsmeans.kt b/material-color-utilities/src/commonMain/kotlin/com/materialkolor/quantize/QuantizerWsmeans.kt index b09fc4d..2a63b1e 100644 --- a/material-color-utilities/src/commonMain/kotlin/com/materialkolor/quantize/QuantizerWsmeans.kt +++ b/material-color-utilities/src/commonMain/kotlin/com/materialkolor/quantize/QuantizerWsmeans.kt @@ -55,8 +55,8 @@ internal object QuantizerWsmeans { inputPixels: IntArray, startingClusters: IntArray, maxColors: Int, ): Map { // Uses a seeded random number generator to ensure consistent results. - val random: Random = Random(0x42688) - val pixelToCount: MutableMap = LinkedHashMap() + val random = Random(0x42688) + val pixelToCount: MutableMap = LinkedHashMap() val points = arrayOfNulls(inputPixels.size) val pixels = IntArray(inputPixels.size) val pointProvider: PointProvider = PointProviderLab() @@ -80,19 +80,12 @@ internal object QuantizerWsmeans { counts[i] = count } var clusterCount: Int = min(maxColors, pointCount) - if (startingClusters.size != 0) { + if (startingClusters.isNotEmpty()) { clusterCount = min(clusterCount, startingClusters.size) } val clusters = arrayOfNulls(clusterCount) - var clustersCreated = 0 for (i in startingClusters.indices) { clusters[i] = pointProvider.fromInt(startingClusters[i]) - clustersCreated++ - } - val additionalClustersNeeded = clusterCount - clustersCreated - if (additionalClustersNeeded > 0) { - for (i in 0 until additionalClustersNeeded) { - } } val clusterIndices = IntArray(pointCount) for (i in 0 until pointCount) { @@ -115,7 +108,7 @@ internal object QuantizerWsmeans { for (iteration in 0 until MAX_ITERATIONS) { for (i in 0 until clusterCount) { for (j in i + 1 until clusterCount) { - val distance = pointProvider.distance(clusters[i], clusters[j]) + val distance = pointProvider.distance(clusters[i]!!, clusters[j]!!) distanceToIndexMatrix[j][i]!!.distance = distance distanceToIndexMatrix[j][i]!!.index = i distanceToIndexMatrix[i][j]!!.distance = distance @@ -129,24 +122,25 @@ internal object QuantizerWsmeans { } var pointsMoved = 0 for (i in 0 until pointCount) { - val point = points[i] + val point = points[i]!! val previousClusterIndex = clusterIndices[i] - val previousCluster = clusters[previousClusterIndex] + val previousCluster = clusters[previousClusterIndex]!! val previousDistance = pointProvider.distance(point, previousCluster) var minimumDistance = previousDistance var newClusterIndex = -1 for (j in 0 until clusterCount) { - if (distanceToIndexMatrix[previousClusterIndex][j]!!.distance >= 4 * previousDistance) { + val previous = distanceToIndexMatrix[previousClusterIndex][j] ?: continue + if (previous.distance >= 4 * previousDistance) { continue } - val distance = pointProvider.distance(point, clusters[j]) + val distance = pointProvider.distance(point, clusters[j]!!) if (distance < minimumDistance) { minimumDistance = distance newClusterIndex = j } } if (newClusterIndex != -1) { - val distanceChange: Double = abs(sqrt(minimumDistance) - sqrt(previousDistance)) + val distanceChange = abs(sqrt(minimumDistance) - sqrt(previousDistance)) if (distanceChange > MIN_MOVEMENT_DISTANCE) { pointsMoved++ clusterIndices[i] = newClusterIndex @@ -183,14 +177,14 @@ internal object QuantizerWsmeans { clusters[i]!![2] = c } } - val argbToPopulation: MutableMap = LinkedHashMap() + val argbToPopulation: MutableMap = LinkedHashMap() for (i in 0 until clusterCount) { val count = pixelCountSums[i] if (count == 0) { continue } - val possibleNewCluster = pointProvider.toInt(clusters[i]) - if (argbToPopulation.containsKey(possibleNewCluster)) { + val possibleNewCluster = clusters[i]?.let { pointProvider.toInt(it) } + if (possibleNewCluster == null || argbToPopulation.containsKey(possibleNewCluster)) { continue } argbToPopulation[possibleNewCluster] = count @@ -198,15 +192,10 @@ internal object QuantizerWsmeans { return argbToPopulation } - private class Distance internal constructor() : Comparable { + private class Distance : Comparable { - var index: Int - var distance: Double - - init { - index = -1 - distance = -1.0 - } + var index: Int = -1 + var distance: Double = -1.0 override operator fun compareTo(other: Distance): Int { return distance.compareTo(other.distance) diff --git a/material-color-utilities/src/commonMain/kotlin/com/materialkolor/quantize/QuantizerWu.kt b/material-color-utilities/src/commonMain/kotlin/com/materialkolor/quantize/QuantizerWu.kt index 36ad309..95f2cbc 100644 --- a/material-color-utilities/src/commonMain/kotlin/com/materialkolor/quantize/QuantizerWu.kt +++ b/material-color-utilities/src/commonMain/kotlin/com/materialkolor/quantize/QuantizerWu.kt @@ -28,12 +28,12 @@ import com.materialkolor.utils.ColorUtils.redFromArgb */ internal class QuantizerWu : Quantizer { - lateinit var weights: IntArray - lateinit var momentsR: IntArray - lateinit var momentsG: IntArray - lateinit var momentsB: IntArray - lateinit var moments: DoubleArray - lateinit var cubes: Array + private lateinit var weights: IntArray + private lateinit var momentsR: IntArray + private lateinit var momentsG: IntArray + private lateinit var momentsB: IntArray + private lateinit var moments: DoubleArray + private lateinit var cubes: Array override fun quantize(pixels: IntArray?, maxColors: Int): QuantizerResult { val mapResult = QuantizerMap().quantize(pixels, maxColors) @@ -48,7 +48,7 @@ internal class QuantizerWu : Quantizer { return QuantizerResult(resultMap) } - fun constructHistogram(pixels: Map) { + private fun constructHistogram(pixels: Map) { weights = IntArray(TOTAL_SIZE) momentsR = IntArray(TOTAL_SIZE) momentsG = IntArray(TOTAL_SIZE) @@ -71,7 +71,7 @@ internal class QuantizerWu : Quantizer { } } - fun createMoments() { + private fun createMoments() { for (r in 1 until INDEX_COUNT) { val area = IntArray(INDEX_COUNT) val areaR = IntArray(INDEX_COUNT) @@ -107,7 +107,7 @@ internal class QuantizerWu : Quantizer { } } - fun createBoxes(maxColorCount: Int): CreateBoxesResult { + private fun createBoxes(maxColorCount: Int): CreateBoxesResult { cubes = arrayOfNulls(maxColorCount) for (i in 0 until maxColorCount) { cubes[i] = Box() @@ -142,11 +142,11 @@ internal class QuantizerWu : Quantizer { } i++ } - return CreateBoxesResult(maxColorCount, generatedColorCount) + return CreateBoxesResult(generatedColorCount) } - fun createResult(colorCount: Int): List { - val colors: MutableList = ArrayList() + private fun createResult(colorCount: Int): List { + val colors: MutableList = ArrayList() for (i in 0 until colorCount) { val cube = cubes[i] val weight = volume(cube, weights) @@ -161,7 +161,7 @@ internal class QuantizerWu : Quantizer { return colors } - fun variance(cube: Box?): Double { + private fun variance(cube: Box?): Double { val dr = volume(cube, momentsR) val dg = volume(cube, momentsG) val db = volume(cube, momentsB) @@ -178,7 +178,7 @@ internal class QuantizerWu : Quantizer { return xx - hypotenuse / volume.toDouble() } - fun cut(one: Box?, two: Box?): Boolean { + private fun cut(one: Box?, two: Box?): Boolean { val wholeR = volume(one, momentsR) val wholeG = volume(one, momentsG) val wholeB = volume(one, momentsB) @@ -228,7 +228,7 @@ internal class QuantizerWu : Quantizer { return true } - fun maximize( + private fun maximize( cube: Box?, direction: Direction, first: Int, @@ -289,7 +289,8 @@ internal class QuantizerWu : Quantizer { var maximum: Double, ) - class CreateBoxesResult internal constructor(var requestedCount: Int, var resultCount: Int) + class CreateBoxesResult internal constructor(var resultCount: Int) + class Box { var r0 = 0 diff --git a/material-color-utilities/src/commonMain/kotlin/com/materialkolor/scheme/DynamicScheme.kt b/material-color-utilities/src/commonMain/kotlin/com/materialkolor/scheme/DynamicScheme.kt index 3bd0323..2ffa33f 100644 --- a/material-color-utilities/src/commonMain/kotlin/com/materialkolor/scheme/DynamicScheme.kt +++ b/material-color-utilities/src/commonMain/kotlin/com/materialkolor/scheme/DynamicScheme.kt @@ -24,22 +24,22 @@ import com.materialkolor.utils.MathUtils * color. (source color) 2. A theme. (Variant) 3. Whether or not its dark mode. 4. Contrast level. * (-1 to 1, currently contrast ratio 3.0 and 7.0) */ -open class DynamicScheme( - val sourceColorHct: Hct, - val variant: Variant, - val isDark: Boolean, - val contrastLevel: Double, - val primaryPalette: TonalPalette, - val secondaryPalette: TonalPalette, - val tertiaryPalette: TonalPalette, - val neutralPalette: TonalPalette, - val neutralVariantPalette: TonalPalette, +public open class DynamicScheme( + public val sourceColorHct: Hct, + public val variant: Variant, + public val isDark: Boolean, + public val contrastLevel: Double, + public val primaryPalette: TonalPalette, + public val secondaryPalette: TonalPalette, + public val tertiaryPalette: TonalPalette, + public val neutralPalette: TonalPalette, + public val neutralVariantPalette: TonalPalette, ) { - val sourceColorArgb: Int = sourceColorHct.toInt() - val errorPalette: TonalPalette = TonalPalette.fromHueAndChroma(hue = 25.0, chroma = 84.0) + public val sourceColorArgb: Int = sourceColorHct.toInt() + public val errorPalette: TonalPalette = TonalPalette.fromHueAndChroma(hue = 25.0, chroma = 84.0) - companion object { + public companion object { /** * Given a set of hues and set of hue rotations, locate which hues the source color's hue is @@ -51,11 +51,16 @@ open class DynamicScheme( * @param rotations A set of hue rotations. * @return Color's hue with a rotation applied. */ - fun getRotatedHue(sourceColorHct: Hct, hues: DoubleArray, rotations: DoubleArray): Double { + public fun getRotatedHue( + sourceColorHct: Hct, + hues: DoubleArray, + rotations: DoubleArray, + ): Double { val sourceHue: Double = sourceColorHct.hue if (rotations.size == 1) { return MathUtils.sanitizeDegrees(sourceHue + rotations[0]) } + val size = hues.size for (i in 0..size - 2) { val thisHue = hues[i] @@ -64,6 +69,7 @@ open class DynamicScheme( return MathUtils.sanitizeDegrees(sourceHue + rotations[i]) } } + // If this statement executes, something is wrong, there should have been a rotation // found using the arrays. return sourceHue diff --git a/material-color-utilities/src/commonMain/kotlin/com/materialkolor/scheme/SchemeContent.kt b/material-color-utilities/src/commonMain/kotlin/com/materialkolor/scheme/SchemeContent.kt index 00def84..bb33e7b 100644 --- a/material-color-utilities/src/commonMain/kotlin/com/materialkolor/scheme/SchemeContent.kt +++ b/material-color-utilities/src/commonMain/kotlin/com/materialkolor/scheme/SchemeContent.kt @@ -33,7 +33,7 @@ import kotlin.math.max * grounded equivalent to rotating hue clockwise by 60 degrees. It also maintains constant * appearance. */ -class SchemeContent( +public class SchemeContent( sourceColorHct: Hct, isDark: Boolean, contrastLevel: Double, diff --git a/material-color-utilities/src/commonMain/kotlin/com/materialkolor/scheme/SchemeExpressive.kt b/material-color-utilities/src/commonMain/kotlin/com/materialkolor/scheme/SchemeExpressive.kt index 1d9947d..6a1649a 100644 --- a/material-color-utilities/src/commonMain/kotlin/com/materialkolor/scheme/SchemeExpressive.kt +++ b/material-color-utilities/src/commonMain/kotlin/com/materialkolor/scheme/SchemeExpressive.kt @@ -22,7 +22,7 @@ import com.materialkolor.utils.MathUtils /** * A playful theme - the source color's hue does not appear in the theme. */ -class SchemeExpressive( +public class SchemeExpressive( sourceColorHct: Hct, isDark: Boolean, contrastLevel: Double, @@ -53,7 +53,7 @@ class SchemeExpressive( ), ) { - companion object { + private companion object { // NOMUTANTS--arbitrary increments/decrements, correctly, still passes tests. private val HUES = doubleArrayOf(0.0, 21.0, 51.0, 121.0, 151.0, 191.0, 271.0, 321.0, 360.0) diff --git a/material-color-utilities/src/commonMain/kotlin/com/materialkolor/scheme/SchemeFidelity.kt b/material-color-utilities/src/commonMain/kotlin/com/materialkolor/scheme/SchemeFidelity.kt index 419afa6..5db2c4f 100644 --- a/material-color-utilities/src/commonMain/kotlin/com/materialkolor/scheme/SchemeFidelity.kt +++ b/material-color-utilities/src/commonMain/kotlin/com/materialkolor/scheme/SchemeFidelity.kt @@ -31,7 +31,11 @@ import kotlin.math.max * Tertiary Container is the complement to the source color, using TemperatureCache. It also * maintains constant appearance. */ -class SchemeFidelity(sourceColorHct: Hct, isDark: Boolean, contrastLevel: Double) : DynamicScheme( +public class SchemeFidelity( + sourceColorHct: Hct, + isDark: Boolean, + contrastLevel: Double, +) : DynamicScheme( sourceColorHct = sourceColorHct, variant = Variant.FIDELITY, isDark = isDark, diff --git a/material-color-utilities/src/commonMain/kotlin/com/materialkolor/scheme/SchemeFruitSalad.kt b/material-color-utilities/src/commonMain/kotlin/com/materialkolor/scheme/SchemeFruitSalad.kt index 04866f4..a3bc109 100644 --- a/material-color-utilities/src/commonMain/kotlin/com/materialkolor/scheme/SchemeFruitSalad.kt +++ b/material-color-utilities/src/commonMain/kotlin/com/materialkolor/scheme/SchemeFruitSalad.kt @@ -22,7 +22,11 @@ import com.materialkolor.utils.MathUtils /** * A playful theme - the source color's hue does not appear in the theme. */ -class SchemeFruitSalad(sourceColorHct: Hct, isDark: Boolean, contrastLevel: Double) : DynamicScheme( +public class SchemeFruitSalad( + sourceColorHct: Hct, + isDark: Boolean, + contrastLevel: Double, +) : DynamicScheme( sourceColorHct = sourceColorHct, variant = Variant.FRUIT_SALAD, isDark = isDark, diff --git a/material-color-utilities/src/commonMain/kotlin/com/materialkolor/scheme/SchemeMonochrome.kt b/material-color-utilities/src/commonMain/kotlin/com/materialkolor/scheme/SchemeMonochrome.kt index b0e9363..bf1e6a0 100644 --- a/material-color-utilities/src/commonMain/kotlin/com/materialkolor/scheme/SchemeMonochrome.kt +++ b/material-color-utilities/src/commonMain/kotlin/com/materialkolor/scheme/SchemeMonochrome.kt @@ -21,7 +21,11 @@ import com.materialkolor.palettes.TonalPalette /** * A monochrome theme, colors are purely black / white / gray. */ -class SchemeMonochrome(sourceColorHct: Hct, isDark: Boolean, contrastLevel: Double) : DynamicScheme( +public class SchemeMonochrome( + sourceColorHct: Hct, + isDark: Boolean, + contrastLevel: Double, +) : DynamicScheme( sourceColorHct = sourceColorHct, variant = Variant.MONOCHROME, isDark = isDark, diff --git a/material-color-utilities/src/commonMain/kotlin/com/materialkolor/scheme/SchemeNeutral.kt b/material-color-utilities/src/commonMain/kotlin/com/materialkolor/scheme/SchemeNeutral.kt index a0772fc..3d51db3 100644 --- a/material-color-utilities/src/commonMain/kotlin/com/materialkolor/scheme/SchemeNeutral.kt +++ b/material-color-utilities/src/commonMain/kotlin/com/materialkolor/scheme/SchemeNeutral.kt @@ -21,7 +21,11 @@ import com.materialkolor.palettes.TonalPalette /** * A theme that's slightly more chromatic than monochrome, which is purely black / white / gray. */ -class SchemeNeutral(sourceColorHct: Hct, isDark: Boolean, contrastLevel: Double) : DynamicScheme( +public class SchemeNeutral( + sourceColorHct: Hct, + isDark: Boolean, + contrastLevel: Double, +) : DynamicScheme( sourceColorHct = sourceColorHct, variant = Variant.NEUTRAL, isDark = isDark, diff --git a/material-color-utilities/src/commonMain/kotlin/com/materialkolor/scheme/SchemeRainbow.kt b/material-color-utilities/src/commonMain/kotlin/com/materialkolor/scheme/SchemeRainbow.kt index 60ed3d7..562f6a8 100644 --- a/material-color-utilities/src/commonMain/kotlin/com/materialkolor/scheme/SchemeRainbow.kt +++ b/material-color-utilities/src/commonMain/kotlin/com/materialkolor/scheme/SchemeRainbow.kt @@ -22,7 +22,11 @@ import com.materialkolor.utils.MathUtils /** * A playful theme - the source color's hue does not appear in the theme. */ -class SchemeRainbow(sourceColorHct: Hct, isDark: Boolean, contrastLevel: Double) : DynamicScheme( +public class SchemeRainbow( + sourceColorHct: Hct, + isDark: Boolean, + contrastLevel: Double, +) : DynamicScheme( sourceColorHct = sourceColorHct, variant = Variant.RAINBOW, isDark = isDark, diff --git a/material-color-utilities/src/commonMain/kotlin/com/materialkolor/scheme/SchemeTonalSpot.kt b/material-color-utilities/src/commonMain/kotlin/com/materialkolor/scheme/SchemeTonalSpot.kt index 2e922a8..725680c 100644 --- a/material-color-utilities/src/commonMain/kotlin/com/materialkolor/scheme/SchemeTonalSpot.kt +++ b/material-color-utilities/src/commonMain/kotlin/com/materialkolor/scheme/SchemeTonalSpot.kt @@ -22,7 +22,11 @@ import com.materialkolor.utils.MathUtils /** * A calm theme, sedated colors that aren't particularly chromatic. */ -class SchemeTonalSpot(sourceColorHct: Hct, isDark: Boolean, contrastLevel: Double) : DynamicScheme( +public class SchemeTonalSpot( + sourceColorHct: Hct, + isDark: Boolean, + contrastLevel: Double, +) : DynamicScheme( sourceColorHct = sourceColorHct, variant = Variant.TONAL_SPOT, isDark = isDark, diff --git a/material-color-utilities/src/commonMain/kotlin/com/materialkolor/scheme/SchemeVibrant.kt b/material-color-utilities/src/commonMain/kotlin/com/materialkolor/scheme/SchemeVibrant.kt index d935ac2..50953c8 100644 --- a/material-color-utilities/src/commonMain/kotlin/com/materialkolor/scheme/SchemeVibrant.kt +++ b/material-color-utilities/src/commonMain/kotlin/com/materialkolor/scheme/SchemeVibrant.kt @@ -21,7 +21,11 @@ import com.materialkolor.palettes.TonalPalette /** * A loud theme, colorfulness is maximum for Primary palette, increased for others. */ -class SchemeVibrant(sourceColorHct: Hct, isDark: Boolean, contrastLevel: Double) : DynamicScheme( +public class SchemeVibrant( + sourceColorHct: Hct, + isDark: Boolean, + contrastLevel: Double, +) : DynamicScheme( sourceColorHct = sourceColorHct, variant = Variant.VIBRANT, isDark = isDark, @@ -39,7 +43,7 @@ class SchemeVibrant(sourceColorHct: Hct, isDark: Boolean, contrastLevel: Double) neutralVariantPalette = TonalPalette.fromHueAndChroma(sourceColorHct.hue, chroma = 12.0), ) { - companion object { + private companion object { private val HUES = doubleArrayOf(0.0, 41.0, 61.0, 101.0, 131.0, 181.0, 251.0, 301.0, 360.0) diff --git a/material-color-utilities/src/commonMain/kotlin/com/materialkolor/scheme/Variant.kt b/material-color-utilities/src/commonMain/kotlin/com/materialkolor/scheme/Variant.kt index d6b2c75..297ade3 100644 --- a/material-color-utilities/src/commonMain/kotlin/com/materialkolor/scheme/Variant.kt +++ b/material-color-utilities/src/commonMain/kotlin/com/materialkolor/scheme/Variant.kt @@ -18,7 +18,7 @@ package com.materialkolor.scheme /** * Themes for Dynamic Color. */ -enum class Variant { +public enum class Variant { /** * A monochrome theme, colors are purely black / white / gray. diff --git a/material-color-utilities/src/commonMain/kotlin/com/materialkolor/score/Score.kt b/material-color-utilities/src/commonMain/kotlin/com/materialkolor/score/Score.kt index 6560588..d1cc65f 100644 --- a/material-color-utilities/src/commonMain/kotlin/com/materialkolor/score/Score.kt +++ b/material-color-utilities/src/commonMain/kotlin/com/materialkolor/score/Score.kt @@ -29,7 +29,7 @@ import kotlin.math.round * muddied, while curating the high cluster count to a much smaller number of appropriate choices. */ @Suppress("unused") -object Score { +public object Score { private const val TARGET_CHROMA = 48.0 // A1 Chroma private const val WEIGHT_PROPORTION = 0.7 @@ -52,7 +52,7 @@ object Score { * the input colors were not suitable for a theme, a default fallback color will be provided, * Google Blue. */ - fun score( + public fun score( colorsToPopulation: Map, desired: Int = 4, fallbackColorArgb: Int? = -0xbd7a0c, diff --git a/material-color-utilities/src/commonMain/kotlin/com/materialkolor/temperature/TemperatureCache.kt b/material-color-utilities/src/commonMain/kotlin/com/materialkolor/temperature/TemperatureCache.kt index 3b730b4..586100a 100644 --- a/material-color-utilities/src/commonMain/kotlin/com/materialkolor/temperature/TemperatureCache.kt +++ b/material-color-utilities/src/commonMain/kotlin/com/materialkolor/temperature/TemperatureCache.kt @@ -52,7 +52,7 @@ public class TemperatureCache(private val input: Hct) { * In art, this is usually described as being across the color wheel. History of this shows * intent as a color that is just as cool-warm as the input color is warm-cool. */ - val complement: Hct + public val complement: Hct get() { if (precomputedComplement != null) { return precomputedComplement!! @@ -97,7 +97,7 @@ public class TemperatureCache(private val input: Hct) { * * The colors are equidistant in temperature and adjacent in hue. */ - val analogousColors: List + public val analogousColors: List get() = getAnalogousColors(5, 12) /** @@ -111,7 +111,7 @@ public class TemperatureCache(private val input: Hct) { * @param count The number of colors to return, includes the input color. * @param divisions The number of divisions on the color wheel. */ - fun getAnalogousColors(count: Int, divisions: Int): List { + public fun getAnalogousColors(count: Int, divisions: Int): List { // The starting hue is the hue of the input color. val startHue = round(input.hue).toInt() val startHct: Hct = hctsByHue!![startHue] @@ -196,7 +196,7 @@ public class TemperatureCache(private val input: Hct) { * @param hct HCT to find the relative temperature of. * @return Value on a scale from 0 to 1. */ - fun getRelativeTemperature(hct: Hct): Double { + public fun getRelativeTemperature(hct: Hct): Double { val range = tempsByHct!![warmest]!! - tempsByHct!![coldest]!! val differenceFromColdest = tempsByHct!![hct]!! - tempsByHct!![coldest]!! // Handle when there's no difference in temperature between warmest and @@ -276,7 +276,7 @@ public class TemperatureCache(private val input: Hct) { private val warmest: Hct get() = hctsByTemp!![hctsByTemp!!.size - 1] - companion object { + public companion object { /** * Value representing cool-warm factor of a color. Values below 0 are considered cool, above, @@ -292,7 +292,7 @@ public class TemperatureCache(private val input: Hct) { * - Lower bound: -9.66. Chroma is infinite. Assuming max of Lab chroma 130. * - Upper bound: 8.61. Chroma is infinite. Assuming max of Lab chroma 130. */ - fun rawTemperature(color: Hct): Double { + public fun rawTemperature(color: Hct): Double { val lab: DoubleArray = ColorUtils.labFromArgb(color.toInt()) val hue = MathUtils.sanitizeDegrees(MathUtils.toDegrees(atan2(lab[2], lab[1]))) val chroma: Double = hypot(lab[1], lab[2]) diff --git a/material-color-utilities/src/commonMain/kotlin/com/materialkolor/utils/ColorUtils.kt b/material-color-utilities/src/commonMain/kotlin/com/materialkolor/utils/ColorUtils.kt index f0737f9..55926be 100644 --- a/material-color-utilities/src/commonMain/kotlin/com/materialkolor/utils/ColorUtils.kt +++ b/material-color-utilities/src/commonMain/kotlin/com/materialkolor/utils/ColorUtils.kt @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -// This file is automatically generated. Do not modify it. + package com.materialkolor.utils import kotlin.math.pow @@ -22,7 +22,6 @@ import kotlin.math.round /** * Color science utilities. * - * * Utility methods for color science constants and color space conversions that aren't HCT or * CAM16. */ @@ -43,36 +42,70 @@ public object ColorUtils { private val WHITE_POINT_D65 = doubleArrayOf(95.047, 100.0, 108.883) - /** Converts a color from RGB components to ARGB format. */ - fun argbFromRgb(red: Int, green: Int, blue: Int): Int { + /** + * Converts a color from RGB components to ARGB format. + * + * @param[red] the red component, in the range [0, 255] + * @param[green] the green component, in the range [0, 255] + * @param[blue] the blue component, in the range [0, 255] + * @return the ARGB representation of the color + */ + public fun argbFromRgb(red: Int, green: Int, blue: Int): Int { return 255 shl 24 or (red and 255 shl 16) or (green and 255 shl 8) or (blue and 255) } - /** Converts a color from linear RGB components to ARGB format. */ - fun argbFromLinrgb(linrgb: DoubleArray): Int { + /** + * Converts a color from linear RGB components to ARGB format. + * + * @param[linrgb] the linear RGB components + * @return the ARGB representation of the color + */ + public fun argbFromLinrgb(linrgb: DoubleArray): Int { val r = delinearized(linrgb[0]) val g = delinearized(linrgb[1]) val b = delinearized(linrgb[2]) return argbFromRgb(r, g, b) } - /** Returns the red component of a color in ARGB format. */ - fun redFromArgb(argb: Int): Int { + /** + * Returns the red component of a color in ARGB format. + * + * @param[argb] the ARGB representation of a color + * @return the red component of the color + */ + public fun redFromArgb(argb: Int): Int { return argb shr 16 and 255 } - /** Returns the green component of a color in ARGB format. */ - fun greenFromArgb(argb: Int): Int { + /** + * Returns the green component of a color in ARGB format. + * + * @param[argb] the ARGB representation of a color + * @return the green component of the color + */ + public fun greenFromArgb(argb: Int): Int { return argb shr 8 and 255 } - /** Returns the blue component of a color in ARGB format. */ - fun blueFromArgb(argb: Int): Int { + /** + * Returns the blue component of a color in ARGB format. + * + * @param[argb] the ARGB representation of a color + * @return the blue component of the color + */ + public fun blueFromArgb(argb: Int): Int { return argb and 255 } - /** Converts a color from ARGB to XYZ. */ - fun argbFromXyz(x: Double, y: Double, z: Double): Int { + /** + * Converts a color from ARGB to XYZ. + * + * @param[x] the X component of the color + * @param[y] the Y component of the color + * @param[z] the Z component of the color + * @return the ARGB representation of the color + */ + public fun argbFromXyz(x: Double, y: Double, z: Double): Int { val matrix = XYZ_TO_SRGB val linearR = matrix[0][0] * x + matrix[0][1] * y + matrix[0][2] * z val linearG = matrix[1][0] * x + matrix[1][1] * y + matrix[1][2] * z @@ -83,16 +116,28 @@ public object ColorUtils { return argbFromRgb(r, g, b) } - /** Converts a color from XYZ to ARGB. */ - fun xyzFromArgb(argb: Int): DoubleArray { + /** + * Converts a color from ARGB to XYZ. + * + * @param[argb] the ARGB representation of a color + * @return the XYZ representation of the color + */ + public fun xyzFromArgb(argb: Int): DoubleArray { val r = linearized(redFromArgb(argb)) val g = linearized(greenFromArgb(argb)) val b = linearized(blueFromArgb(argb)) return MathUtils.matrixMultiply(doubleArrayOf(r, g, b), SRGB_TO_XYZ) } - /** Converts a color represented in Lab color space into an ARGB integer. */ - fun argbFromLab(l: Double, a: Double, b: Double): Int { + /** + * Converts a color represented in Lab color space into an ARGB integer. + * + * @param[l] the L* component of the color + * @param[a] the a* component of the color + * @param[b] the b* component of the color + * @return the ARGB representation of the color + */ + public fun argbFromLab(l: Double, a: Double, b: Double): Int { val whitePoint = WHITE_POINT_D65 val fy = (l + 16.0) / 116.0 val fx = a / 500.0 + fy @@ -109,10 +154,10 @@ public object ColorUtils { /** * Converts a color from ARGB representation to L*a*b* representation. * - * @param argb the ARGB representation of a color + * @param[argb] the ARGB representation of a color * @return a Lab object representing the color */ - fun labFromArgb(argb: Int): DoubleArray { + public fun labFromArgb(argb: Int): DoubleArray { val linearR = linearized(redFromArgb(argb)) val linearG = linearized(greenFromArgb(argb)) val linearB = linearized(blueFromArgb(argb)) @@ -136,10 +181,10 @@ public object ColorUtils { /** * Converts an L* value to an ARGB representation. * - * @param lstar L* in L*a*b* + * @param[lstar] L* in L*a*b* * @return ARGB representation of grayscale color with lightness matching L* */ - fun argbFromLstar(lstar: Double): Int { + public fun argbFromLstar(lstar: Double): Int { val y = yFromLstar(lstar) val component = delinearized(y) return argbFromRgb(component, component, component) @@ -148,10 +193,10 @@ public object ColorUtils { /** * Computes the L* value of a color in ARGB representation. * - * @param argb ARGB representation of a color + * @param[argb] ARGB representation of a color * @return L*, from L*a*b*, coordinate of the color */ - fun lstarFromArgb(argb: Int): Double { + public fun lstarFromArgb(argb: Int): Double { val y = xyzFromArgb(argb)[1] return 116.0 * labF(y / 100.0) - 16.0 } @@ -162,41 +207,38 @@ public object ColorUtils { * * L* in L*a*b* and Y in XYZ measure the same quantity, luminance. * - * * L* measures perceptual luminance, a linear scale. Y in XYZ measures relative luminance, a * logarithmic scale. * - * @param lstar L* in L*a*b* + * @param[lstar] L* in L*a*b* * @return Y in XYZ */ - fun yFromLstar(lstar: Double): Double { + public fun yFromLstar(lstar: Double): Double { return 100.0 * labInvf((lstar + 16.0) / 116.0) } /** * Converts a Y value to an L* value. * - * * L* in L*a*b* and Y in XYZ measure the same quantity, luminance. * - * * L* measures perceptual luminance, a linear scale. Y in XYZ measures relative luminance, a * logarithmic scale. * - * @param y Y in XYZ + * @param[y] Y in XYZ * @return L* in L*a*b* */ - fun lstarFromY(y: Double): Double { + public fun lstarFromY(y: Double): Double { return labF(y / 100.0) * 116.0 - 16.0 } /** * Linearizes an RGB component. * - * @param rgbComponent 0 <= rgb_component <= 255, represents R/G/B channel + * @param[rgbComponent] 0 <= rgb_component <= 255, represents R/G/B channel * @return 0.0 <= output <= 100.0, color channel converted to linear RGB space */ - fun linearized(rgbComponent: Int): Double { + public fun linearized(rgbComponent: Int): Double { val normalized = rgbComponent / 255.0 return if (normalized <= 0.040449936) normalized / 12.92 * 100.0 else (normalized + 0.055 / 1.055).pow(2.4) * 100.0 @@ -205,10 +247,10 @@ public object ColorUtils { /** * Delinearizes an RGB component. * - * @param rgbComponent 0.0 <= rgb_component <= 100.0, represents linear R/G/B channel + * @param[rgbComponent] 0.0 <= rgb_component <= 100.0, represents linear R/G/B channel * @return 0 <= output <= 255, color channel converted to regular RGB space */ - fun delinearized(rgbComponent: Double): Int { + public fun delinearized(rgbComponent: Double): Int { val normalized = rgbComponent / 100.0 val delinearized: Double = if (normalized <= 0.0031308) normalized * 12.92 @@ -222,21 +264,38 @@ public object ColorUtils { * * @return The white point */ - fun whitePointD65(): DoubleArray = WHITE_POINT_D65 + public fun whitePointD65(): DoubleArray = WHITE_POINT_D65 - fun labF(t: Double): Double { + /** + * The labF function. + * + * @param[t] a value in the L*a*b* color space + * @return the result of the labF function + */ + public fun labF(t: Double): Double { val e = 216.0 / 24389.0 val kappa = 24389.0 / 27.0 return if (t > e) t.pow(1.0 / 3.0) else (kappa * t + 16) / 116 } - fun labInvf(ft: Double): Double { + /** + * Inverse of the labF function. + * + * @param[ft] a value in the L*a*b* color space + */ + public fun labInvf(ft: Double): Double { val e = 216.0 / 24389.0 val kappa = 24389.0 / 27.0 val ft3 = ft * ft * ft return if (ft3 > e) ft3 else (116 * ft - 16) / kappa } + /** + * Returns the luminance of a color in ARGB format. + * + * @param[argb] the ARGB representation of a color + * @return the luminance of the color + */ public fun calculateLuminance(argb: Int): Double { val xyz = xyzFromArgb(argb) // Luminance is the Y component diff --git a/material-color-utilities/src/commonMain/kotlin/com/materialkolor/utils/MathUtils.kt b/material-color-utilities/src/commonMain/kotlin/com/materialkolor/utils/MathUtils.kt index 3b11e2c..ec95298 100644 --- a/material-color-utilities/src/commonMain/kotlin/com/materialkolor/utils/MathUtils.kt +++ b/material-color-utilities/src/commonMain/kotlin/com/materialkolor/utils/MathUtils.kt @@ -13,17 +13,19 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -// This file is automatically generated. Do not modify it. package com.materialkolor.utils import kotlin.math.abs -/** Utility methods for mathematical operations. */ +/** + * Utility methods for mathematical operations. + */ internal object MathUtils { /** * The signum function. * + * @param[num] the number to check * @return 1 if num > 0, -1 if num < 0, and 0 if num = 0 */ fun signum(num: Double): Int = when { @@ -35,6 +37,9 @@ internal object MathUtils { /** * The linear interpolation function. * + * @param[start] the start value + * @param[stop] the stop value + * @param[amount] the amount to interpolate * @return start if amount = 0 and stop if amount = 1 */ fun lerp(start: Double, stop: Double, amount: Double): Double { @@ -44,6 +49,7 @@ internal object MathUtils { /** * Sanitizes a degree measure as an integer. * + * @param[degrees] the degree measure to sanitize. * @return a degree measure between 0 (inclusive) and 360 (exclusive). */ fun sanitizeDegrees(degrees: Int): Int { @@ -57,6 +63,7 @@ internal object MathUtils { /** * Sanitizes a degree measure as a floating-point number. * + * @param[degrees] the degree measure to sanitize. * @return a degree measure between 0.0 (inclusive) and 360.0 (exclusive). */ fun sanitizeDegrees(degrees: Double): Double { @@ -74,8 +81,8 @@ internal object MathUtils { * For angles that are 180 degrees apart from each other, both directions have the same travel * distance, so either direction is shortest. The value 1.0 is returned in this case. * - * @param from The angle travel starts from, in degrees. - * @param to The angle travel ends at, in degrees. + * @param[from] The angle travel starts from, in degrees. + * @param[to] The angle travel ends at, in degrees. * @return -1 if decreasing from leads to the shortest travel distance, 1 if increasing from leads * to the shortest travel distance. */ @@ -85,12 +92,24 @@ internal object MathUtils { } - /** Distance of two points on a circle, represented using degrees. */ + /** + * Distance of two points on a circle, represented using degrees. + * + * @param[a] the first point + * @param[b] the second point + * @return the distance between the two points + */ fun differenceDegrees(a: Double, b: Double): Double { return 180.0 - abs(abs(a - b) - 180.0) } - /** Multiplies a 1x3 row vector with a 3x3 matrix. */ + /** + * Multiplies a 1x3 row vector with a 3x3 matrix. + * + * @param[row] the row vector + * @param[matrix] the matrix + * @return the resulting row vector + */ fun matrixMultiply(row: DoubleArray, matrix: Array): DoubleArray { val a = row[0] * matrix[0][0] + row[1] * matrix[0][1] + row[2] * matrix[0][2] val b = row[0] * matrix[1][0] + row[1] * matrix[1][1] + row[2] * matrix[1][2] @@ -98,7 +117,20 @@ internal object MathUtils { return doubleArrayOf(a, b, c) } + /** + * Converts an angle in degrees to radians. + * + * @param[angrad] angle in radians + * @return angle in degrees + */ fun toDegrees(angrad: Double): Double = angrad * 57.29577951308232 + + /** + * Converts an angle in radians to degrees. + * + * @param[angdeg] angle in degrees + * @return angle in radians + */ fun toRadians(angdeg: Double): Double = angdeg * 0.017453292519943295 } diff --git a/material-kolor/api/android/material-kolor.api b/material-kolor/api/android/material-kolor.api index ef12eec..ed88f1b 100644 --- a/material-kolor/api/android/material-kolor.api +++ b/material-kolor/api/android/material-kolor.api @@ -71,6 +71,7 @@ public final class com/materialkolor/ktx/ImageBitmapKt { } public final class com/materialkolor/ktx/TemperatureKt { + public static final fun TemperatureCache-8_81llA (J)Lcom/materialkolor/temperature/TemperatureCache; public static final fun isCool-8_81llA (J)Z public static final fun isWarm-8_81llA (J)Z public static final fun temperature-4WTKRHQ (Lcom/materialkolor/temperature/TemperatureCache$Companion;J)D diff --git a/material-kolor/api/jvm/material-kolor.api b/material-kolor/api/jvm/material-kolor.api index ef12eec..ed88f1b 100644 --- a/material-kolor/api/jvm/material-kolor.api +++ b/material-kolor/api/jvm/material-kolor.api @@ -71,6 +71,7 @@ public final class com/materialkolor/ktx/ImageBitmapKt { } public final class com/materialkolor/ktx/TemperatureKt { + public static final fun TemperatureCache-8_81llA (J)Lcom/materialkolor/temperature/TemperatureCache; public static final fun isCool-8_81llA (J)Z public static final fun isWarm-8_81llA (J)Z public static final fun temperature-4WTKRHQ (Lcom/materialkolor/temperature/TemperatureCache$Companion;J)D diff --git a/material-kolor/src/commonMain/kotlin/com/materialkolor/ktx/Temperature.kt b/material-kolor/src/commonMain/kotlin/com/materialkolor/ktx/Temperature.kt index d62a3f1..2629187 100644 --- a/material-kolor/src/commonMain/kotlin/com/materialkolor/ktx/Temperature.kt +++ b/material-kolor/src/commonMain/kotlin/com/materialkolor/ktx/Temperature.kt @@ -3,6 +3,22 @@ package com.materialkolor.ktx import androidx.compose.ui.graphics.Color import com.materialkolor.temperature.TemperatureCache +/** + * Design utilities using color temperature theory. + * + * Analogous colors, complementary color, and cache to efficiently, lazily, generate data for + * calculations when needed. + * + * Create a cache that allows calculation of ex. complementary and analogous colors. + * + * @param[input] Color to find complement/analogous colors of. Any colors will have the same tone, + * and chroma as the input color, modulo any restrictions due to the other hues having lower + * limits on chroma. + */ +public fun TemperatureCache(input: Color): TemperatureCache { + return TemperatureCache(input.toHct()) +} + /** * Value representing cool-warm factor of a color. *