/** * @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. */ /** * Functions for blending in HCT and CAM16. */ declare class Blend { /** * Blend the design color's HCT hue towards the key color's HCT * hue, in a way that leaves the original color recognizable and * recognizably shifted towards the key color. * * @param designColor ARGB representation of an arbitrary color. * @param sourceColor ARGB representation of the main theme color. * @return The design color with a hue shifted towards the * system's color, a slightly warmer/cooler variant of the design * color's hue. */ static harmonize(designColor: number, sourceColor: number): number; /** * Blends hue from one color into another. The chroma and tone of * the original color are maintained. * * @param from ARGB representation of color * @param to ARGB representation of color * @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. */ static hctHue(from: number, to: number, amount: number): number; /** * Blend in CAM16-UCS space. * * @param from ARGB representation of color * @param to ARGB representation of color * @param amount how much blending to perform; 0.0 >= and <= 1.0 * @return from, blended towards to. Hue, chroma, and tone will * change. */ static cam16Ucs(from: number, to: number, amount: number): number; } /** * @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. */ /** * In traditional color spaces, a color can be identified solely by the * observer's measurement of the color. Color appearance models such as CAM16 * also use information about the environment where the color was * observed, known as the viewing conditions. * * For example, white under the traditional assumption of a midday sun white * point is accurately measured as a slightly chromatic blue by CAM16. (roughly, * hue 203, chroma 3, lightness 100) * * This class caches intermediate values of the CAM16 conversion process that * depend only on viewing conditions, enabling speed ups. */ declare class ViewingConditions { n: number; aw: number; nbb: number; ncb: number; c: number; nc: number; rgbD: number[]; fl: number; fLRoot: number; z: number; /** sRGB-like viewing conditions. */ static DEFAULT: ViewingConditions; /** * Create ViewingConditions from a simple, physically relevant, set of * parameters. * * @param whitePoint White point, measured in the XYZ color space. * default = D65, or sunny day afternoon * @param adaptingLuminance The luminance of the adapting field. Informally, * how bright it is in the room where the color is viewed. Can be * calculated from lux by multiplying lux by 0.0586. default = 11.72, * or 200 lux. * @param backgroundLstar The lightness of the area surrounding the color. * measured by L* in L*a*b*. default = 50.0 * @param surround A general description of the lighting surrounding the * color. 0 is pitch dark, like watching a movie in a theater. 1.0 is a * dimly light room, like watching TV at home at night. 2.0 means there * is no difference between the lighting on the color and around it. * default = 2.0 * @param discountingIlluminant Whether the eye accounts for the tint of the * ambient lighting, such as knowing an apple is still red in green light. * default = false, the eye does not perform this process on * self-luminous objects like displays. */ static make(whitePoint?: number[], adaptingLuminance?: number, backgroundLstar?: number, surround?: number, discountingIlluminant?: boolean): ViewingConditions; /** * Parameters are intermediate values of the CAM16 conversion process. Their * names are shorthand for technical color science terminology, this class * would not benefit from documenting them individually. A brief overview * is available in the CAM16 specification, and a complete overview requires * a color science textbook, such as Fairchild's Color Appearance Models. */ private constructor(); } /** * @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. */ /** * CAM16, a color appearance model. Colors are not just defined by their hex * code, but rather, a hex code and viewing conditions. * * CAM16 instances also have coordinates in the CAM16-UCS space, called J*, a*, * b*, or jstar, astar, bstar in code. CAM16-UCS is included in the CAM16 * specification, and should be used when measuring distances between colors. * * In traditional color spaces, a color can be identified solely by the * observer's measurement of the color. Color appearance models such as CAM16 * also use information about the environment where the color was * observed, known as the viewing conditions. * * For example, white under the traditional assumption of a midday sun white * point is accurately measured as a slightly chromatic blue by CAM16. (roughly, * hue 203, chroma 3, lightness 100) */ declare class Cam16 { readonly hue: number; readonly chroma: number; readonly j: number; readonly q: number; readonly m: number; readonly s: number; readonly jstar: number; readonly astar: number; readonly bstar: number; /** * All of the CAM16 dimensions can be calculated from 3 of the dimensions, in * the following combinations: * - {j or q} and {c, m, or s} and hue * - jstar, astar, bstar * Prefer using a static method that constructs from 3 of those dimensions. * This constructor is intended for those methods to use to return all * possible dimensions. * * @param hue * @param chroma informally, colorfulness / color intensity. like saturation * in HSL, except perceptually accurate. * @param j lightness * @param q brightness; ratio of lightness to white point's lightness * @param m colorfulness * @param s saturation; ratio of chroma to white point's chroma * @param jstar CAM16-UCS J coordinate * @param astar CAM16-UCS a coordinate * @param bstar CAM16-UCS b coordinate */ constructor(hue: number, chroma: number, j: number, q: number, m: number, s: number, jstar: number, astar: number, bstar: number); /** * CAM16 instances also have coordinates in the CAM16-UCS space, called J*, * a*, b*, or jstar, astar, bstar in code. CAM16-UCS is included in the CAM16 * specification, and is used to measure distances between colors. */ distance(other: Cam16): number; /** * @param argb ARGB representation of a color. * @return CAM16 color, assuming the color was viewed in default viewing * conditions. */ static fromInt(argb: number): Cam16; /** * @param argb ARGB representation of a color. * @param viewingConditions Information about the environment where the color * was observed. * @return CAM16 color. */ static fromIntInViewingConditions(argb: number, viewingConditions: ViewingConditions): Cam16; /** * @param j CAM16 lightness * @param c CAM16 chroma * @param h CAM16 hue */ static fromJch(j: number, c: number, h: number): Cam16; /** * @param j CAM16 lightness * @param c CAM16 chroma * @param h CAM16 hue * @param viewingConditions Information about the environment where the color * was observed. */ static fromJchInViewingConditions(j: number, c: number, h: number, viewingConditions: ViewingConditions): Cam16; /** * @param jstar CAM16-UCS lightness. * @param astar CAM16-UCS a dimension. Like a* in L*a*b*, it is a Cartesian * coordinate on the Y axis. * @param bstar CAM16-UCS b dimension. Like a* in L*a*b*, it is a Cartesian * coordinate on the X axis. */ static fromUcs(jstar: number, astar: number, bstar: number): Cam16; /** * @param jstar CAM16-UCS lightness. * @param astar CAM16-UCS a dimension. Like a* in L*a*b*, it is a Cartesian * coordinate on the Y axis. * @param bstar CAM16-UCS b dimension. Like a* in L*a*b*, it is a Cartesian * coordinate on the X axis. * @param viewingConditions Information about the environment where the color * was observed. */ static fromUcsInViewingConditions(jstar: number, astar: number, bstar: number, viewingConditions: ViewingConditions): Cam16; /** * @return ARGB representation of color, assuming the color was viewed in * default viewing conditions, which are near-identical to the default * viewing conditions for sRGB. */ toInt(): number; /** * @param viewingConditions Information about the environment where the color * will be viewed. * @return ARGB representation of color */ viewed(viewingConditions: ViewingConditions): number; } /** * @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. */ /** * HCT, hue, chroma, and tone. A color system that provides a perceptually * accurate color measurement system that can also accurately render what colors * will appear as in different lighting environments. */ declare class Hct { private argb; /** * @param hue 0 <= hue < 360; invalid values are corrected. * @param chroma 0 <= chroma < ?; Informally, colorfulness. The color * returned may be lower than the requested chroma. Chroma has a different * maximum for any given hue and tone. * @param tone 0 <= tone <= 100; invalid values are corrected. * @return HCT representation of a color in default viewing conditions. */ internalHue: number; internalChroma: number; internalTone: number; static from(hue: number, chroma: number, tone: number): Hct; /** * @param argb ARGB representation of a color. * @return HCT representation of a color in default viewing conditions */ static fromInt(argb: number): Hct; toInt(): number; /** * A number, in degrees, representing ex. red, orange, yellow, etc. * Ranges from 0 <= hue < 360. */ get hue(): number; /** * @param newHue 0 <= newHue < 360; invalid values are corrected. * Chroma may decrease because chroma has a different maximum for any given * hue and tone. */ set hue(newHue: number); get chroma(): number; /** * @param newChroma 0 <= newChroma < ? * Chroma may decrease because chroma has a different maximum for any given * hue and tone. */ set chroma(newChroma: number); /** Lightness. Ranges from 0 to 100. */ get tone(): number; /** * @param newTone 0 <= newTone <= 100; invalid valids are corrected. * Chroma may decrease because chroma has a different maximum for any given * hue and tone. */ set tone(newTone: number); private constructor(); private setInternalState; } /** * @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. */ /** * A convenience class for retrieving colors that are constant in hue and * chroma, but vary in tone. */ declare class TonalPalette { readonly hue: number; readonly chroma: number; private readonly cache; /** * @param argb ARGB representation of a color * @return Tones matching that color's hue and chroma. */ static fromInt(argb: number): TonalPalette; /** * @param hue HCT hue * @param chroma HCT chroma * @return Tones matching hue and chroma. */ static fromHueAndChroma(hue: number, chroma: number): TonalPalette; private constructor(); /** * @param tone HCT tone, measured from 0 to 100. * @return ARGB representation of a color with that tone. */ tone(tone: number): number; } /** * @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. */ /** * Set of colors to generate a [CorePalette] from */ interface CorePaletteColors { primary: number; secondary?: number; tertiary?: number; neutral?: number; neutralVariant?: number; error?: number; } /** * 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. */ declare class CorePalette { a1: TonalPalette; a2: TonalPalette; a3: TonalPalette; n1: TonalPalette; n2: TonalPalette; error: TonalPalette; /** * @param argb ARGB representation of a color */ static of(argb: number): CorePalette; /** * @param argb ARGB representation of a color */ static contentOf(argb: number): CorePalette; /** * Create a [CorePalette] from a set of colors */ static fromColors(colors: CorePaletteColors): CorePalette; /** * Create a content [CorePalette] from a set of colors */ static contentFromColors(colors: CorePaletteColors): CorePalette; private static createPaletteFromColors; private constructor(); } /** * @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. */ /** * An image quantizer that improves on the quality of a standard K-Means * algorithm by setting the K-Means initial state to the output of a Wu * quantizer, instead of random centroids. Improves on speed by several * optimizations, as implemented in Wsmeans, or Weighted Square Means, K-Means * with those optimizations. * * 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 */ declare class QuantizerCelebi { /** * @param pixels Colors in ARGB format. * @param maxColors The number of colors to divide the image into. A lower * number of colors may be returned. * @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. */ static quantize(pixels: number[], maxColors: number): Map; } /** * @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. */ /** * Quantizes an image into a map, with keys of ARGB colors, and values of the * number of times that color appears in the image. */ declare class QuantizerMap { /** * @param pixels Colors in ARGB format. * @return A Map with keys of ARGB colors, and values of the number of times * the color appears in the image. */ static quantize(pixels: number[]): Map; } /** * @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. */ /** * An image quantizer that improves on the speed of a standard K-Means algorithm * by implementing several optimizations, including deduping identical pixels * and a triangle inequality rule that reduces the number of comparisons needed * to identify which cluster a point should be moved to. * * Wsmeans stands for Weighted Square Means. * * 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 */ declare class QuantizerWsmeans { /** * @param inputPixels Colors in ARGB format. * @param startingClusters Defines the initial state of the quantizer. Passing * an empty array is fine, the implementation will create its own initial * state that leads to reproducible results for the same inputs. * Passing an array that is the result of Wu quantization leads to higher * quality results. * @param maxColors The number of colors to divide the image into. A lower * number of colors may be returned. * @return Colors in ARGB format. */ static quantize(inputPixels: number[], startingClusters: number[], maxColors: number): Map; } /** * @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. */ /** * An image quantizer that divides the image's pixels into clusters by * recursively cutting an RGB cube, based on the weight of pixels in each area * of the cube. * * The algorithm was described by Xiaolin Wu in Graphic Gems II, published in * 1991. */ declare class QuantizerWu { private weights; private momentsR; private momentsG; private momentsB; private moments; private cubes; constructor(weights?: number[], momentsR?: number[], momentsG?: number[], momentsB?: number[], moments?: number[], cubes?: Box[]); /** * @param pixels Colors in ARGB format. * @param maxColors The number of colors to divide the image into. A lower * number of colors may be returned. * @return Colors in ARGB format. */ quantize(pixels: number[], maxColors: number): number[]; private constructHistogram; private computeMoments; private createBoxes; private createResult; private variance; private cut; private maximize; private volume; private bottom; private top; private getIndex; } /** * Keeps track of the state of each box created as the Wu quantization * algorithm progresses through dividing the image's pixels as plotted in RGB. */ declare class Box { r0: number; r1: number; g0: number; g1: number; b0: number; b1: number; vol: number; constructor(r0?: number, r1?: number, g0?: number, g1?: number, b0?: number, b1?: number, vol?: number); } /** * @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. */ /** * Represents a Material color scheme, a mapping of color roles to colors. */ declare class Scheme { private readonly props; get primary(): number; get onPrimary(): number; get primaryContainer(): number; get onPrimaryContainer(): number; get secondary(): number; get onSecondary(): number; get secondaryContainer(): number; get onSecondaryContainer(): number; get tertiary(): number; get onTertiary(): number; get tertiaryContainer(): number; get onTertiaryContainer(): number; get error(): number; get onError(): number; get errorContainer(): number; get onErrorContainer(): number; get background(): number; get onBackground(): number; get surface(): number; get onSurface(): number; get surfaceVariant(): number; get onSurfaceVariant(): number; get outline(): number; get outlineVariant(): number; get shadow(): number; get scrim(): number; get inverseSurface(): number; get inverseOnSurface(): number; get inversePrimary(): number; /** * @param argb ARGB representation of a color. * @return Light Material color scheme, based on the color's hue. */ static light(argb: number): Scheme; /** * @param argb ARGB representation of a color. * @return Dark Material color scheme, based on the color's hue. */ static dark(argb: number): Scheme; /** * @param argb ARGB representation of a color. * @return Light Material content color scheme, based on the color's hue. */ static lightContent(argb: number): Scheme; /** * @param argb ARGB representation of a color. * @return Dark Material content color scheme, based on the color's hue. */ static darkContent(argb: number): Scheme; /** * Light scheme from core palette */ static lightFromCorePalette(core: CorePalette): Scheme; /** * Dark scheme from core palette */ static darkFromCorePalette(core: CorePalette): Scheme; private constructor(); toJSON(): { primary: number; onPrimary: number; primaryContainer: number; onPrimaryContainer: number; secondary: number; onSecondary: number; secondaryContainer: number; onSecondaryContainer: number; tertiary: number; onTertiary: number; tertiaryContainer: number; onTertiaryContainer: number; error: number; onError: number; errorContainer: number; onErrorContainer: number; background: number; onBackground: number; surface: number; onSurface: number; surfaceVariant: number; onSurfaceVariant: number; outline: number; outlineVariant: number; shadow: number; scrim: number; inverseSurface: number; inverseOnSurface: number; inversePrimary: number; }; } /** * @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. */ /** * Represents an Android 12 color scheme, a mapping of color roles to colors. */ declare class SchemeAndroid { private readonly props; get colorAccentPrimary(): number; get colorAccentPrimaryVariant(): number; get colorAccentSecondary(): number; get colorAccentSecondaryVariant(): number; get colorAccentTertiary(): number; get colorAccentTertiaryVariant(): number; get textColorPrimary(): number; get textColorSecondary(): number; get textColorTertiary(): number; get textColorPrimaryInverse(): number; get textColorSecondaryInverse(): number; get textColorTertiaryInverse(): number; get colorBackground(): number; get colorBackgroundFloating(): number; get colorSurface(): number; get colorSurfaceVariant(): number; get colorSurfaceHighlight(): number; get surfaceHeader(): number; get underSurface(): number; get offState(): number; get accentSurface(): number; get textPrimaryOnAccent(): number; get textSecondaryOnAccent(): number; get volumeBackground(): number; get scrim(): number; /** * @param argb ARGB representation of a color. * @return Light Material color scheme, based on the color's hue. */ static light(argb: number): SchemeAndroid; /** * @param argb ARGB representation of a color. * @return Dark Material color scheme, based on the color's hue. */ static dark(argb: number): SchemeAndroid; /** * @param argb ARGB representation of a color. * @return Light Android color scheme, based on the color's hue. */ static lightContent(argb: number): SchemeAndroid; /** * @param argb ARGB representation of a color. * @return Dark Android color scheme, based on the color's hue. */ static darkContent(argb: number): SchemeAndroid; /** * Light scheme from core palette */ static lightFromCorePalette(core: CorePalette): SchemeAndroid; /** * Dark scheme from core palette */ static darkFromCorePalette(core: CorePalette): SchemeAndroid; private constructor(); toJSON(): { colorAccentPrimary: number; colorAccentPrimaryVariant: number; colorAccentSecondary: number; colorAccentSecondaryVariant: number; colorAccentTertiary: number; colorAccentTertiaryVariant: number; textColorPrimary: number; textColorSecondary: number; textColorTertiary: number; textColorPrimaryInverse: number; textColorSecondaryInverse: number; textColorTertiaryInverse: number; colorBackground: number; colorBackgroundFloating: number; colorSurface: number; colorSurfaceVariant: number; colorSurfaceHighlight: number; surfaceHeader: number; underSurface: number; offState: number; accentSurface: number; textPrimaryOnAccent: number; textSecondaryOnAccent: number; volumeBackground: number; scrim: number; }; } /** * @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. */ /** * 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. */ 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_TONE; 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. * @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, contentColor?: boolean): number[]; private static filter; private static filterContent; } /** * @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. */ /** * Converts a color from RGB components to ARGB format. */ declare function argbFromRgb(red: number, green: number, blue: number): number; /** * Converts a color from linear RGB components to ARGB format. */ declare function argbFromLinrgb(linrgb: number[]): number; /** * Returns the alpha component of a color in ARGB format. */ declare function alphaFromArgb(argb: number): number; /** * Returns the red component of a color in ARGB format. */ declare function redFromArgb(argb: number): number; /** * Returns the green component of a color in ARGB format. */ declare function greenFromArgb(argb: number): number; /** * Returns the blue component of a color in ARGB format. */ declare function blueFromArgb(argb: number): number; /** * Returns whether a color in ARGB format is opaque. */ declare function isOpaque(argb: number): boolean; /** * Converts a color from ARGB to XYZ. */ declare function argbFromXyz(x: number, y: number, z: number): number; /** * Converts a color from XYZ to ARGB. */ declare function xyzFromArgb(argb: number): number[]; /** * Converts a color represented in Lab color space into an ARGB * integer. */ declare function argbFromLab(l: number, a: number, b: number): number; /** * Converts a color from ARGB representation to L*a*b* * representation. * * @param argb the ARGB representation of a color * @return a Lab object representing the color */ declare function labFromArgb(argb: number): number[]; /** * Converts an L* value to an ARGB representation. * * @param lstar L* in L*a*b* * @return ARGB representation of grayscale color with lightness * matching L* */ declare function argbFromLstar(lstar: number): number; /** * Computes the L* value of a color in ARGB representation. * * @param argb ARGB representation of a color * @return L*, from L*a*b*, coordinate of the color */ declare function lstarFromArgb(argb: number): number; /** * Converts an L* value to a Y 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 lstar L* in L*a*b* * @return Y in XYZ */ declare function yFromLstar(lstar: number): number; /** * 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 * @return L* in L*a*b* */ declare function lstarFromY(y: number): number; /** * Linearizes an RGB component. * * @param rgbComponent 0 <= rgb_component <= 255, represents R/G/B * channel * @return 0.0 <= output <= 100.0, color channel converted to * linear RGB space */ declare function linearized(rgbComponent: number): number; /** * Delinearizes an RGB component. * * @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 */ declare function delinearized(rgbComponent: number): number; /** * Returns the standard white point; white on a sunny day. * * @return The white point */ declare function whitePointD65(): number[]; /** * RGBA component * * @param r Red value should be between 0-255 * @param g Green value should be between 0-255 * @param b Blue value should be between 0-255 * @param a Alpha value should be between 0-255 */ interface Rgba { r: number; g: number; b: number; a: number; } /** * Return RGBA from a given int32 color * * @param argb ARGB representation of a int32 color. * @return RGBA representation of a int32 color. */ declare function rgbaFromArgb(argb: number): Rgba; /** * Return int32 color from a given RGBA component * * @param rgba RGBA representation of a int32 color. * @returns ARGB representation of a int32 color. */ declare function argbFromRgba({ r, g, b, a }: Rgba): number; /** * @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. */ /** * Utility methods for mathematical operations. */ /** * The signum function. * * @return 1 if num > 0, -1 if num < 0, and 0 if num = 0 */ declare function signum(num: number): number; /** * The linear interpolation function. * * @return start if amount = 0 and stop if amount = 1 */ declare function lerp(start: number, stop: number, amount: number): number; /** * Clamps an integer between two integers. * * @return input when min <= input <= max, and either min or max * otherwise. */ declare function clampInt(min: number, max: number, input: number): number; /** * Clamps an integer between two floating-point numbers. * * @return input when min <= input <= max, and either min or max * otherwise. */ declare function clampDouble(min: number, max: number, input: number): number; /** * Sanitizes a degree measure as an integer. * * @return a degree measure between 0 (inclusive) and 360 * (exclusive). */ declare function sanitizeDegreesInt(degrees: number): number; /** * Sanitizes a degree measure as a floating-point number. * * @return a degree measure between 0.0 (inclusive) and 360.0 * (exclusive). */ declare function sanitizeDegreesDouble(degrees: number): number; /** * Sign of direction change needed to travel from one angle to * another. * * 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. * @return -1 if decreasing from leads to the shortest travel * distance, 1 if increasing from leads to the shortest travel * distance. */ declare function rotationDirection(from: number, to: number): number; /** * Distance of two points on a circle, represented using degrees. */ declare function differenceDegrees(a: number, b: number): number; /** * Multiplies a 1x3 row vector with a 3x3 matrix. */ declare function matrixMultiply(row: number[], matrix: number[][]): number[]; /** * @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. */ /** * Utility methods for hexadecimal representations of colors. */ /** * @param argb ARGB representation of a color. * @return Hex string representing color, ex. #ff0000 for red. */ declare const hexFromArgb: (argb: number) => string; /** * @param hex String representing color as hex code. Accepts strings with or * without leading #, and string representing the color using 3, 6, or 8 * hex characters. * @return ARGB representation of color. */ declare const argbFromHex: (hex: string) => number; /** * @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. */ /** * Get the source color from an image. * * @param image The image element * @return Source color - the color most suitable for creating a UI theme */ declare function sourceColorFromImage(image: HTMLImageElement): Promise; /** * @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. */ /** * Custom color used to pair with a theme */ interface CustomColor { value: number; name: string; blend: boolean; } /** * Color group */ interface ColorGroup { color: number; onColor: number; colorContainer: number; onColorContainer: number; } /** * Custom Color Group */ interface CustomColorGroup { color: CustomColor; value: number; light: ColorGroup; dark: ColorGroup; } /** * Theme */ interface Theme { source: number; schemes: { light: Scheme; dark: Scheme; }; palettes: { primary: TonalPalette; secondary: TonalPalette; tertiary: TonalPalette; neutral: TonalPalette; neutralVariant: TonalPalette; error: TonalPalette; }; customColors: CustomColorGroup[]; } /** * Generate a theme from a source color * * @param source Source color * @param customColors Array of custom colors * @return Theme object */ declare function themeFromSourceColor(source: number, customColors?: CustomColor[]): Theme; /** * Generate a theme from an image source * * @param image Image element * @param customColors Array of custom colors * @return Theme object */ declare function themeFromImage(image: HTMLImageElement, customColors?: CustomColor[]): Promise; /** * Generate custom color group from source and target color * * @param source Source color * @param color Custom color * @return Custom color group * * @link https://m3.material.io/styles/color/the-color-system/color-roles */ declare function customColor(source: number, color: CustomColor): CustomColorGroup; /** * Apply a theme to an element * * @param theme Theme object * @param options Options */ declare function applyTheme(theme: Theme, options?: { dark?: boolean; target?: HTMLElement; brightnessSuffix?: boolean; paletteTones?: number[]; }): void; /** * @license * Copyright 2022 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. */ /** * Set of themes supported by Dynamic Color. * Instantiate the corresponding subclass, ex. SchemeTonalSpot, to create * colors corresponding to the theme. */ declare enum Variant { MONOCHROME = 0, NEUTRAL = 1, TONAL_SPOT = 2, VIBRANT = 3, EXPRESSIVE = 4 } /** * @license * Copyright 2022 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. */ /** * @param sourceColorArgb The source color of the theme as an ARGB 32-bit * integer. * @param variant The variant, or style, of the theme. * @param contrastLevel Value from -1 to 1. -1 represents minimum contrast, * 0 represents standard (i.e. the design as spec'd), and 1 represents maximum * contrast. * @param isDark Whether the scheme is in dark mode or light mode. * @param primaryPalette Given a tone, produces a color. Hue and chroma of the * color are specified in the design specification of the variant. Usually * colorful. * @param secondaryPalette Given a tone, produces a color. Hue and chroma of * the color are specified in the design specification of the variant. Usually * less colorful. * @param tertiaryPalette Given a tone, produces a color. Hue and chroma of * the color are specified in the design specification of the variant. Usually * a different hue from primary and colorful. * @param neutralPalette Given a tone, produces a color. Hue and chroma of the * color are specified in the design specification of the variant. Usually not * colorful at all, intended for background & surface colors. * @param neutralVariantPalette Given a tone, produces a color. Hue and chroma * of the color are specified in the design specification of the variant. * Usually not colorful, but slightly more colorful than Neutral. Intended for * backgrounds & surfaces. */ interface DynamicSchemeOptions { sourceColorArgb: number; variant: Variant; contrastLevel: number; isDark: boolean; primaryPalette: TonalPalette; secondaryPalette: TonalPalette; tertiaryPalette: TonalPalette; neutralPalette: TonalPalette; neutralVariantPalette: TonalPalette; } /** * Constructed by a set of values representing the current UI state (such as * whether or not its dark theme, what the theme style is, etc.), and * provides a set of TonalPalettes that can create colors that fit in * with the theme style. Used by DynamicColor to resolve into a color. */ declare class DynamicScheme { /** * The source color of the theme as an HCT color. */ sourceColorHct: Hct; /** * Given a tone, produces a reddish, colorful, color. */ errorPalette: TonalPalette; /** The source color of the theme as an ARGB 32-bit integer. */ readonly sourceColorArgb: number; /** The variant, or style, of the theme. */ readonly variant: Variant; /** * Value from -1 to 1. -1 represents minimum contrast. 0 represents standard * (i.e. the design as spec'd), and 1 represents maximum contrast. */ readonly contrastLevel: number; /** Whether the scheme is in dark mode or light mode. */ readonly isDark: boolean; /** * Given a tone, produces a color. Hue and chroma of the * color are specified in the design specification of the variant. Usually * colorful. */ readonly primaryPalette: TonalPalette; /** * Given a tone, produces a color. Hue and chroma of * the color are specified in the design specification of the variant. Usually * less colorful. */ readonly secondaryPalette: TonalPalette; /** * Given a tone, produces a color. Hue and chroma of * the color are specified in the design specification of the variant. Usually * a different hue from primary and colorful. */ readonly tertiaryPalette: TonalPalette; /** * Given a tone, produces a color. Hue and chroma of the * color are specified in the design specification of the variant. Usually not * colorful at all, intended for background & surface colors. */ readonly neutralPalette: TonalPalette; /** * Given a tone, produces a color. Hue and chroma * of the color are specified in the design specification of the variant. * Usually not colorful, but slightly more colorful than Neutral. Intended for * backgrounds & surfaces. */ readonly neutralVariantPalette: TonalPalette; constructor(args: DynamicSchemeOptions); /** * Support design spec'ing Dynamic Color by schemes that specify hue * rotations that should be applied at certain breakpoints. * @param sourceColor the source color of the theme, in HCT. * @param hues The "breakpoints", i.e. the hues at which a rotation should * be apply. * @param rotations The rotation that should be applied when source color's * hue is >= the same index in hues array, and <= the hue at the next index * in hues array. */ static getRotatedHue(sourceColor: Hct, hues: number[], rotations: number[]): number; } /** * @license * Copyright 2022 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. */ /** A Dynamic Color theme that is near grayscale. */ declare class SchemeNeutral extends DynamicScheme { constructor(sourceColorHct: Hct, isDark: boolean, contrastLevel: number); } /** * @license * Copyright 2022 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. */ /** * A Dynamic Color theme that is intentionally detached from the source color. */ declare class SchemeExpressive extends DynamicScheme { /** * Hues (in degrees) used at breakpoints such that designers can specify a * hue rotation that occurs at a given break point. */ private static readonly hues; /** * Hue rotations (in degrees) of the Secondary [TonalPalette], * corresponding to the breakpoints in [hues]. */ private static readonly secondaryRotations; /** * Hue rotations (in degrees) of the Tertiary [TonalPalette], * corresponding to the breakpoints in [hues]. */ private static readonly tertiaryRotations; constructor(sourceColorHct: Hct, isDark: boolean, contrastLevel: number); } /** * @license * Copyright 2022 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. */ /** A Dynamic Color theme that is grayscale. */ declare class SchemeMonochrome extends DynamicScheme { constructor(sourceColorHct: Hct, isDark: boolean, contrastLevel: number); } /** * @license * Copyright 2022 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. */ /** * A Dynamic Color theme with low to medium colorfulness and a Tertiary * TonalPalette with a hue related to the source color. * * The default Material You theme on Android 12 and 13. */ declare class SchemeTonalSpot extends DynamicScheme { constructor(sourceColorHct: Hct, isDark: boolean, contrastLevel: number); } /** * @license * Copyright 2022 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. */ /** * A Dynamic Color theme that maxes out colorfulness at each position in the * Primary Tonal Palette. */ declare class SchemeVibrant extends DynamicScheme { /** * Hues (in degrees) used at breakpoints such that designers can specify a * hue rotation that occurs at a given break point. */ private static readonly hues; /** * Hue rotations (in degrees) of the Secondary [TonalPalette], * corresponding to the breakpoints in [hues]. */ private static readonly secondaryRotations; /** * Hue rotations (in degrees) of the Tertiary [TonalPalette], * corresponding to the breakpoints in [hues]. */ private static readonly tertiaryRotations; constructor(sourceColorHct: Hct, isDark: boolean, contrastLevel: number); } /** * @license * Copyright 2022 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. */ /** * Describes the different in tone between colors. * * If there is no preference, the tones at standard contrast are examined, and * the polarity of those is attempted to be maintained. */ declare type TonePolarity = 'darker' | 'lighter' | 'no-preference'; /** * Documents a constraint between two DynamicColors, in which their tones must * have a certain distance from each other. * * Prefer a DynamicColor with a background, this is for special cases when * designers want tonal distance, literally contrast, between two colors that * don't have a background / foreground relationship or a contrast guarantee. */ declare class ToneDeltaConstraint { readonly delta: number; readonly keepAway: DynamicColor; readonly keepAwayPolarity: TonePolarity; /** * Documents a constraint in tone distance between two DynamicColors. * * @param delta Required difference between tones. Absolute value, negative * values have undefined behavior. * @param keepAway DynamicColor whose tone must be delta from the DynamicColor * constructed with this instance. * @param keepAwayPolarity The polarity of keepAway as compared to the * DynamicColor this constraint is attached to. */ constructor(delta: number, keepAway: DynamicColor, keepAwayPolarity: TonePolarity); } /** * @license * Copyright 2022 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. */ /** * @param palette Function that provides a TonalPalette given * DynamicScheme. A TonalPalette is defined by a hue and chroma, so this * replaces the need to specify hue/chroma. By providing a tonal palette, when * contrast adjustments are made, intended chroma can be preserved. * @param tone Function that provides a tone given DynamicScheme. (useful * for dark vs. light mode) */ interface FromPaletteOptions extends BaseOptions { palette: (scheme: DynamicScheme) => TonalPalette; tone: (scheme: DynamicScheme) => number; } /** * @param hue Function with DynamicScheme input and HCT hue output. * @param chroma Function with DynamicScheme input and HCT chroma output. * @param tone Function with DynamicScheme input and HCT tone output. */ interface FromHueAndChromaOptions extends BaseOptions { hue: (scheme: DynamicScheme) => number; chroma: (scheme: DynamicScheme) => number; tone: (scheme: DynamicScheme) => number; } /** * @param argb Function with DynamicScheme input and ARGB/hex code output. * @param [tone=null] Function with DynamicScheme input and HCT tone output. If * provided, overrides tone of argb parameter. */ interface FromArgbOptions extends BaseOptions { argb: (scheme: DynamicScheme) => number; tone?: (scheme: DynamicScheme) => number; } /** * @param tone The tone standard. * @param scheme The scheme in which to adjust the tone. */ interface ToneContrastOptions extends BaseOptions { tone: (scheme: DynamicScheme) => number; scheme: DynamicScheme; } /** * @param [background=null] Function that provides background * DynamicColor given DynamicScheme. Useful for contrast, given a background, * colors can adjust to increase/decrease contrast. * @param [toneDeltaConstraint=null] Function that provides a * ToneDeltaConstraint given DynamicScheme. Useful for ensuring lightness * difference between colors that don't require contrast or have a formal * background/foreground relationship. */ interface BaseOptions { background?: (scheme: DynamicScheme) => DynamicColor; toneDeltaConstraint?: (scheme: DynamicScheme) => ToneDeltaConstraint; } /** * @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. * @param toneStandard Function with input of DynamicScheme that outputs the * tone to be used at default contrast. * @param toneToJudge Function with input of DynamicColor that outputs tone the * color is in the current UI state. Used to determine the tone of the * background. * @param desiredTone Function with inputs of contrast ratio with background at * default contrast and the background tone at current contrast level. Outputs * tone. * @param [background] Optional, function with input of DynamicScheme that * returns a DynamicColor that is the background of the color whose tone is * being calculated. * @param [constraint] Optional, function with input of DynamicScheme that * returns a ToneDeltaConstraint. If provided, the ToneDeltaConstraint is * enforced. * @param [minRatio] Optional, function with input of DynamicScheme that returns * the minimum contrast ratio between background and the color whose tone is * being calculated. * @param [maxRatio] Optional, function with input of DynamicScheme that returns * the maximum contrast ratio between background and the color whose tone is * being calculated. */ interface CalculateDynamicToneOptions { scheme: DynamicScheme; toneStandard: (scheme: DynamicScheme) => number; toneToJudge: (dynamicColor: DynamicColor) => number; desiredTone: (standardRatio: number, bgTone: number) => number; background?: (scheme: DynamicScheme) => DynamicColor; toneDeltaConstraint?: (scheme: DynamicScheme) => ToneDeltaConstraint; minRatio?: (scheme: number) => number; maxRatio?: (scheme: number) => number; } /** * A color that adjusts itself based on UI state provided by DynamicScheme. * * Colors without backgrounds do not change tone when contrast changes. Colors * with backgrounds become closer to their background as contrast lowers, and * further when contrast increases. * * Prefer static constructors. They require either a hexcode, a palette and * tone, or a hue and chroma. Optionally, they can provide a background * DynamicColor. */ declare class DynamicColor { readonly hue: (scheme: DynamicScheme) => number; readonly chroma: (scheme: DynamicScheme) => number; readonly tone: (scheme: DynamicScheme) => number; readonly toneMinContrast: (scheme: DynamicScheme) => number; readonly toneMaxContrast: (scheme: DynamicScheme) => number; readonly background?: (scheme: DynamicScheme) => DynamicColor; readonly toneDeltaConstraint?: (scheme: DynamicScheme) => ToneDeltaConstraint; private readonly hctCache; /** * Create a DynamicColor defined by a TonalPalette and HCT tone. * * @param args Functions with DynamicScheme as input. Must provide a palette * and tone. May provide a background DynamicColor and ToneDeltaConstraint. */ static fromPalette(args: FromPaletteOptions): DynamicColor; /** * Create a DynamicColor defined by a HCT hue, chroma, and tone. * * @param args Functions with DynamicScheme as input. Must provide hue, * chroma, and tone. May provide background DynamicColor and * ToneDeltaConstraint. */ static fromHueAndChroma(args: FromHueAndChromaOptions): DynamicColor; /** * Create a DynamicColor from a ARGB color (hex code). * * @param args Functions with DynamicScheme as input. Must provide ARGB (hex * code). May provide tone that overrides hex code's, background DynamicColor, * and ToneDeltaConstraint. */ static fromArgb(args: FromArgbOptions): DynamicColor; /** * The base constructor for DynamicColor. * * _Strongly_ prefer using one of the convenience constructors. This class is * arguably too flexible to ensure it can support any scenario. Functional * arguments allow overriding without risks that come with subclasses. * * For example, the default behavior of adjust tone at max contrast * to be at a 7.0 ratio with its background is principled and * matches accessibility guidance. That does not mean it's the desired * approach for _every_ design system, and every color pairing, * always, in every case. * * @param hue given DynamicScheme, return the hue in HCT of the output * color. * @param chroma given DynamicScheme, return chroma in HCT of the output * color. * @param tone given DynamicScheme, return tone in HCT of the output color. * This tone is used for standard contrast. * @param toneMinContrast given DynamicScheme, return tone in HCT this color * should be at minimum contrast. See toneMinContrastDefault for the default * behavior, and strongly consider using it unless you have strong opinions * on color and accessibility. The convenience constructors use it. * @param toneMaxContrast given DynamicScheme, return tone in HCT this color * should be at maximum contrast. See toneMaxContrastDefault for the default * behavior, and strongly consider using it unless you have strong opinions * on color and accessibility. The convenience constructors use it. * @param background given DynamicScheme, return the DynamicColor that is * the background of this DynamicColor. When this is provided, * automated adjustments to lower and raise contrast are made. * @param toneDeltaConstraint given DynamicScheme, return a * ToneDeltaConstraint that describes a requirement that this * DynamicColor must always have some difference in tone from another * DynamicColor. * * Unlikely to be useful unless a design system has some distortions * where colors that don't have a background/foreground relationship * don't want to have a formal relationship or a principled value for their * tone distance based on common contrast / tone delta values, yet, want * tone distance. */ constructor(hue: (scheme: DynamicScheme) => number, chroma: (scheme: DynamicScheme) => number, tone: (scheme: DynamicScheme) => number, toneMinContrast: (scheme: DynamicScheme) => number, toneMaxContrast: (scheme: DynamicScheme) => number, background?: (scheme: DynamicScheme) => DynamicColor, toneDeltaConstraint?: (scheme: DynamicScheme) => ToneDeltaConstraint); /** * Return a ARGB integer (i.e. a hex code). * * @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. */ getArgb(scheme: DynamicScheme): number; /** * Return a color, expressed in the HCT color space, that this * DynamicColor is under the conditions in scheme. * * @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. */ getHct(scheme: DynamicScheme): Hct; /** * Return a tone, T in the HCT color space, that this DynamicColor is under * the conditions in scheme. * * @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. */ getTone(scheme: DynamicScheme): number; /** * Enforce a ToneDeltaConstraint between two DynamicColors. * * @param tone The desired tone of the color. * @param toneStandard The tone of the color at standard contrast. * @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. * @param constraintProvider Given a DynamicScheme, return a * ToneDeltaConstraint or null. * @param toneToDistanceFrom Given a DynamicColor, return a tone that the * ToneDeltaConstraint should enforce a delta from. */ static ensureToneDelta(tone: number, toneStandard: number, scheme: DynamicScheme, constraintProvider?: (scheme: DynamicScheme) => ToneDeltaConstraint | null, toneToDistanceFrom?: (color: DynamicColor) => number): number; /** * Given a background tone, find a foreground tone, while ensuring they reach * a contrast ratio that is as close to [ratio] as possible. * * @param bgTone Tone in HCT. Range is 0 to 100, undefined behavior when it * falls outside that range. * @param ratio The contrast ratio desired between bgTone and the return * value. */ static foregroundTone(bgTone: number, ratio: number): number; /** * Core method for calculating a tone for under dynamic contrast. * * It calculates tone while enforcing these properties: * #1. Desired contrast ratio is reached. * #2. Darken to enable light foregrounds on midtones. * #3. Enforce tone delta constraint, if needed. */ static calculateDynamicTone(args: CalculateDynamicToneOptions): number; /** * Default algorithm for calculating the tone of a color at maximum contrast. * * If the color's background has a background, reach contrast 7.0. * If it doesn't, maintain the original contrast ratio. */ static toneMaxContrastDefault(args: ToneContrastOptions): number; /** * Default algorithm for calculating the tone of a color at minimum contrast. * * If the original contrast ratio was >= 7.0, reach contrast 4.5. * If the original contrast ratio was >= 3.0, reach contrast 3.0. * If the original contrast ratio was < 3.0, reach that ratio. */ static toneMinContrastDefault(args: ToneContrastOptions): number; /** * Returns whether [tone] is <= 60. * * People prefer white foregrounds on ~T60-70. Observed over time, and also * by Andrew Somers during research for APCA. * * T60 used as to create the smallest discontinuity possible when skipping * down to T49 in order to ensure light foregrounds. */ static tonePrefersLightForeground(tone: number): boolean; /** * Returns whether [tone] can reach a contrast ratio of 4.5 with a lighter * color. */ static toneAllowsLightForeground(tone: number): boolean; /** * Adjust a tone such that white has 4.5 contrast, if the tone is * reasonably close to supporting it. */ static enableLightForeground(tone: number): number; } /** * @license * Copyright 2022 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. */ /** * DynamicColors for the colors in the Material Design system. */ declare class MaterialDynamicColors { static contentAccentToneDelta: number; static highestSurface(s: DynamicScheme): DynamicColor; static background: DynamicColor; static onBackground: DynamicColor; static surface: DynamicColor; static surfaceDark: DynamicColor; static surfaceLight: DynamicColor; static surfaceSub2: DynamicColor; static surfaceSub1: DynamicColor; static surfaceContainer: DynamicColor; static surfaceAdd1: DynamicColor; static surfaceAdd2: DynamicColor; static onSurface: DynamicColor; static surfaceVariant: DynamicColor; static onSurfaceVariant: DynamicColor; static outline: DynamicColor; static primary: DynamicColor; static onPrimary: DynamicColor; static primaryContainer: DynamicColor; static onPrimaryContainer: DynamicColor; static secondary: DynamicColor; static onSecondary: DynamicColor; static secondaryContainer: DynamicColor; static onSecondaryContainer: DynamicColor; static tertiary: DynamicColor; static onTertiary: DynamicColor; static tertiaryContainer: DynamicColor; static onTertiaryContainer: DynamicColor; static error: DynamicColor; static onError: DynamicColor; static errorContainer: DynamicColor; static onErrorContainer: DynamicColor; } export { Blend, Cam16, ColorGroup, CorePalette, CorePaletteColors, CustomColor, CustomColorGroup, Hct, MaterialDynamicColors, QuantizerCelebi, QuantizerMap, QuantizerWsmeans, QuantizerWu, Rgba, Scheme, SchemeAndroid, SchemeExpressive, SchemeMonochrome, SchemeNeutral, SchemeTonalSpot, SchemeVibrant, Score, Theme, TonalPalette, Variant, ViewingConditions, alphaFromArgb, applyTheme, argbFromHex, argbFromLab, argbFromLinrgb, argbFromLstar, argbFromRgb, argbFromRgba, argbFromXyz, blueFromArgb, clampDouble, clampInt, customColor, delinearized, differenceDegrees, greenFromArgb, hexFromArgb, isOpaque, labFromArgb, lerp, linearized, lstarFromArgb, lstarFromY, matrixMultiply, redFromArgb, rgbaFromArgb, rotationDirection, sanitizeDegreesDouble, sanitizeDegreesInt, signum, sourceColorFromImage, themeFromImage, themeFromSourceColor, whitePointD65, xyzFromArgb, yFromLstar };