@poupe/material-color-utilities
Version:
Algorithms and utilities that power the Material Design 3 (M3) color system, including choosing theme colors from images and creating tones of colors; all in a new color space.
63 lines (62 loc) • 2.64 kB
TypeScript
/**
* @license
* Copyright 2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Default options for ranking colors based on usage counts.
* desired: is the max count of the colors returned.
* fallbackColorARGB: Is the default color that should be used if no
* other colors are suitable.
* filter: controls if the resulting colors should be filtered to not include
* hues that are not used often enough, and colors that are effectively
* grayscale.
*/
declare interface ScoreOptions {
desired?: number;
fallbackColorARGB?: number;
filter?: boolean;
}
/**
* Given a large set of colors, remove colors that are unsuitable for a UI
* theme, and rank the rest based on suitability.
*
* Enables use of a high cluster count for image quantization, thus ensuring
* colors aren't muddied, while curating the high cluster count to a much
* smaller number of appropriate choices.
*/
export declare class Score {
private static readonly TARGET_CHROMA;
private static readonly WEIGHT_PROPORTION;
private static readonly WEIGHT_CHROMA_ABOVE;
private static readonly WEIGHT_CHROMA_BELOW;
private static readonly CUTOFF_CHROMA;
private static readonly CUTOFF_EXCITED_PROPORTION;
private constructor();
/**
* Given a map with keys of colors and values of how often the color appears,
* rank the colors based on suitability for being used for a UI theme.
*
* @param colorsToPopulation map with keys of colors and values of how often
* the color appears, usually from a source image.
* @param {ScoreOptions} options optional parameters.
* @return Colors sorted by suitability for a UI theme. The most suitable
* color is the first item, the least suitable is the last. There will
* always be at least one color returned. If all the input colors
* were not suitable for a theme, a default fallback color will be
* provided, Google Blue.
*/
static score(colorsToPopulation: Map<number, number>, options?: ScoreOptions): number[];
}
export {};