UNPKG

3.09 kBTypeScriptView Raw
1/*
2Copyright 2020 Adobe. All rights reserved.
3This file is licensed to you under the Apache License, Version 2.0 (the "License");
4you may not use this file except in compliance with the License. You may obtain a copy
5of the License at http://www.apache.org/licenses/LICENSE-2.0
6
7Unless required by applicable law or agreed to in writing, software distributed under
8the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9OF ANY KIND, either express or implied. See the License for the specific language
10governing permissions and limitations under the License.
11*/
12
13export as namespace ContrastColors;
14export = ContrastColors;
15
16declare namespace ContrastColors {
17 type InterpolationColorspace = 'CAM02' | 'CAM02p' | 'LCH' | 'LAB' | 'HSL' | 'HSLuv' | 'RGB' | 'HSV';
18 type Colorspace = 'CAM02' | 'CAM02p' | 'LCH' | 'LAB' | 'HSL' | 'HSLuv' | 'RGB' | 'HSV' | 'HEX';
19
20 type RGBArray = number[];
21
22 type AdaptiveTheme = (brightness: number, constrast?: number) => AdaptiveTheme | ({
23 background: string
24 } | {
25 name: string,
26 values: {
27 name: string,
28 contrast: number,
29 value: string
30 }[]
31 })[];
32
33 interface ColorScale {
34 colorKeys: string[],
35 colorspace: Colorspace,
36 shift: number,
37 colors: string[],
38 scale: ((d: any) => string) | d3.ScaleLinear<number, number>,
39 colorsHex: string[]
40 }
41
42 interface NamedColorScale {
43 name: string,
44 colorKeys: string[],
45 colorspace: InterpolationColorspace,
46 ratios: number[] | { [key: string]: number },
47 smooth?: boolean
48 }
49
50 function createScale({
51 swatches,
52 colorKeys,
53 colorspace,
54 shift,
55 fullScale,
56 smooth
57 }: {
58 swatches: number,
59 colorKeys: string[],
60 colorspace?: InterpolationColorspace,
61 shift?: number,
62 fullScale?: boolean,
63 smooth?: boolean
64 }): ColorScale | never;
65
66 function luminance(r: number, g: number, b: number): number;
67
68 function contrast(color: RGBArray, base: RGBArray, baseV: number): number;
69
70 function binarySearch(list: number[], value: number, baseLum: number): number;
71
72 function generateBaseScale({
73 colorKeys,
74 colorspace,
75 smooth
76 }: {
77 colorKeys: string[],
78 colorspace?: Colorspace,
79 smooth?: boolean
80 }): string[];
81
82 function generateContrastColors({
83 colorKeys,
84 base,
85 ratios,
86 colorspace,
87 smooth,
88 output
89 }: {
90 colorKeys: string[],
91 base: string,
92 ratios: number[],
93 colorspace?: InterpolationColorspace,
94 smooth?: boolean,
95 output?: Colorspace
96 }): string[] | never;
97
98 function minPositive(r: number[]): number | never;
99
100 function ratioName(r: number[]): number[] | never;
101
102 function generateAdaptiveTheme({
103 colorScales,
104 baseScale,
105 brightness,
106 contrast,
107 output
108 }: {
109 colorScales: NamedColorScale[],
110 baseScale: string,
111 brightness?: number,
112 contrast?: number,
113 output?: Colorspace,
114 }): AdaptiveTheme | never;
115
116 function fixColorValue(
117 color: string,
118 format: Colorspace,
119 object?: boolean
120 ): string | { [key: string]: number };
121}
\No newline at end of file