@unicom-cloud/utils 0.1.11 → 0.1.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/date/index.js +22 -0
- package/date.js +9 -0
- package/filesize/src/constants.js +22 -22
- package/filesize/src/filesize.js +32 -33
- package/index.js +56 -54
- package/lunar/index.js +36 -0
- package/lunar/lib/Holiday.js +42 -0
- package/lunar/lib/HolidayUtil.js +128 -0
- package/lunar/lib/I18n.js +1005 -0
- package/lunar/lib/JieQi.js +40 -0
- package/lunar/lib/Lunar.js +1035 -0
- package/lunar/lib/LunarMonth.js +150 -0
- package/lunar/lib/LunarTime.js +138 -0
- package/lunar/lib/LunarUtil.js +1752 -0
- package/lunar/lib/LunarYear.js +616 -0
- package/lunar/lib/ShouXingUtil.js +6915 -0
- package/lunar/lib/Solar.js +311 -0
- package/lunar/lib/SolarHalfYear.js +45 -0
- package/lunar/lib/SolarMonth.js +55 -0
- package/lunar/lib/SolarSeason.js +42 -0
- package/lunar/lib/SolarUtil.js +256 -0
- package/lunar/lib/SolarWeek.js +153 -0
- package/lunar/lib/SolarYear.js +35 -0
- package/lunar/lib/index.js +35 -0
- package/lunar.js +36 -0
- package/package.json +1 -1
- package/snapdom/src/api/preCache.js +27 -37
- package/snapdom/src/api/snapdom.js +75 -58
- package/snapdom/src/core/cache.js +19 -8
- package/snapdom/src/core/capture.js +49 -48
- package/snapdom/src/core/clone.js +96 -31
- package/snapdom/src/core/prepare.js +43 -37
- package/snapdom/src/modules/background.js +29 -20
- package/snapdom/src/modules/fonts.js +94 -104
- package/snapdom/src/modules/iconFonts.js +28 -0
- package/snapdom/src/modules/images.js +6 -6
- package/snapdom/src/modules/pseudo.js +52 -50
- package/snapdom/src/modules/styles.js +26 -6
- package/snapdom/src/modules/svgDefs.js +26 -0
- package/snapdom/src/utils/cssTools.js +41 -41
- package/snapdom/src/utils/helpers.js +128 -84
- package/tinycolor/index.js +46 -0
- package/tinycolor/src/conversion.js +143 -0
- package/tinycolor/src/css-color-names.js +153 -0
- package/tinycolor/src/format-input.js +77 -0
- package/tinycolor/src/from-ratio.js +21 -0
- package/tinycolor/src/index.js +404 -0
- package/tinycolor/src/random.js +221 -0
- package/tinycolor/src/readability.js +37 -0
- package/tinycolor/src/to-ms-filter.js +15 -0
- package/tinycolor/src/util.js +32 -0
- package/tinycolor.js +46 -0
- package/tree/index.js +10 -8
- package/tree/search/index.js +90 -0
- package/tree.js +9 -7
- package/types/date/index.d.ts +4 -0
- package/types/filesize/src/constants.d.ts +12 -12
- package/types/filesize/src/filesize.d.ts +63 -22
- package/types/index.d.ts +4 -3
- package/types/lunar/index.d.ts +3 -0
- package/types/lunar/lib/Holiday.d.ts +17 -0
- package/types/lunar/lib/HolidayUtil.d.ts +23 -0
- package/types/lunar/lib/I18n.d.ts +23 -0
- package/types/lunar/lib/JieQi.d.ts +15 -0
- package/types/lunar/lib/Lunar.d.ts +245 -0
- package/types/lunar/lib/LunarMonth.d.ts +35 -0
- package/types/lunar/lib/LunarTime.d.ts +40 -0
- package/types/lunar/lib/LunarUtil.d.ts +128 -0
- package/types/lunar/lib/LunarYear.d.ts +61 -0
- package/types/lunar/lib/ShouXingUtil.d.ts +38 -0
- package/types/lunar/lib/Solar.d.ts +51 -0
- package/types/lunar/lib/SolarHalfYear.d.ts +15 -0
- package/types/lunar/lib/SolarMonth.d.ts +16 -0
- package/types/lunar/lib/SolarSeason.d.ts +15 -0
- package/types/lunar/lib/SolarUtil.d.ts +20 -0
- package/types/lunar/lib/SolarWeek.d.ts +23 -0
- package/types/lunar/lib/SolarYear.d.ts +12 -0
- package/types/lunar/lib/index.d.ts +17 -0
- package/types/snapdom/src/core/cache.d.ts +17 -11
- package/types/snapdom/src/core/capture.d.ts +4 -0
- package/types/snapdom/src/core/clone.d.ts +4 -5
- package/types/snapdom/src/core/prepare.d.ts +8 -1
- package/types/snapdom/src/modules/background.d.ts +1 -2
- package/types/snapdom/src/modules/fonts.d.ts +1 -3
- package/types/snapdom/src/modules/iconFonts.d.ts +2 -0
- package/types/snapdom/src/modules/pseudo.d.ts +1 -3
- package/types/snapdom/src/modules/styles.d.ts +1 -10
- package/types/snapdom/src/modules/svgDefs.d.ts +19 -0
- package/types/snapdom/src/utils/cssTools.d.ts +1 -2
- package/types/snapdom/src/utils/helpers.d.ts +1 -1
- package/types/tinycolor/index.d.ts +2 -0
- package/types/tinycolor/src/conversion.d.ts +79 -0
- package/types/tinycolor/src/css-color-names.d.ts +4 -0
- package/types/tinycolor/src/format-input.d.ts +38 -0
- package/types/tinycolor/src/from-ratio.d.ts +14 -0
- package/types/tinycolor/src/index.d.ts +214 -0
- package/types/tinycolor/src/interfaces.d.ts +57 -0
- package/types/tinycolor/src/public_api.d.ts +10 -0
- package/types/tinycolor/src/random.d.ts +24 -0
- package/types/tinycolor/src/readability.d.ts +46 -0
- package/types/tinycolor/src/to-ms-filter.d.ts +5 -0
- package/types/tinycolor/src/umd_api.d.ts +22 -0
- package/types/tinycolor/src/util.d.ts +36 -0
- package/types/tree/index.d.ts +1 -0
- package/types/tree/search/index.d.ts +80 -0
- package/types/ui-color/compareColorByRange.d.ts +2 -0
- package/types/ui-color/index.d.ts +208 -0
- package/ui-color/compareColorByRange.js +9 -0
- package/ui-color/index.js +162 -0
- package/uiColor.js +29 -0
- package/convertTime.js +0 -4
- package/dayjs/index.js +0 -15
- package/dayjs.js +0 -5
- package/lunar-converter/index.js +0 -641
- package/lunarConverter.js +0 -4
- package/search-tree/index.js +0 -54
- package/searchTree.js +0 -4
- package/types/dayjs/index.d.ts +0 -1
- package/types/lunar-converter/index.d.ts +0 -113
- package/types/search-tree/index.d.ts +0 -20
- /package/{convert-time/index.js → date/convertTime.js} +0 -0
- /package/types/{convert-time/index.d.ts → date/convertTime.d.ts} +0 -0
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import { CMYK, HSL, HSLA, HSV, HSVA, Numberify, RGB, RGBA } from './interfaces.js';
|
|
2
|
+
export interface TinyColorOptions {
|
|
3
|
+
format: string;
|
|
4
|
+
gradientType: string;
|
|
5
|
+
}
|
|
6
|
+
export type ColorInput = string | number | RGB | RGBA | HSL | HSLA | HSV | HSVA | CMYK | TinyColor | unknown;
|
|
7
|
+
export type ColorFormats = 'rgb' | 'prgb' | 'hex' | 'hex3' | 'hex4' | 'hex6' | 'hex8' | 'name' | 'hsl' | 'hsv' | 'cmyk';
|
|
8
|
+
export declare class TinyColor {
|
|
9
|
+
/** red */
|
|
10
|
+
r: number;
|
|
11
|
+
/** green */
|
|
12
|
+
g: number;
|
|
13
|
+
/** blue */
|
|
14
|
+
b: number;
|
|
15
|
+
/** alpha */
|
|
16
|
+
a: number;
|
|
17
|
+
/** the format used to create the tinycolor instance */
|
|
18
|
+
format: ColorFormats;
|
|
19
|
+
/** input passed into the constructer used to create the tinycolor instance */
|
|
20
|
+
originalInput: ColorInput;
|
|
21
|
+
/** the color was successfully parsed */
|
|
22
|
+
isValid: boolean;
|
|
23
|
+
gradientType?: string;
|
|
24
|
+
/** rounded alpha */
|
|
25
|
+
roundA: number;
|
|
26
|
+
constructor(color?: ColorInput, opts?: Partial<TinyColorOptions>);
|
|
27
|
+
get ok(): boolean;
|
|
28
|
+
isDark(): boolean;
|
|
29
|
+
isLight(): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Returns the perceived brightness of the color, from 0-255.
|
|
32
|
+
*/
|
|
33
|
+
getBrightness(): number;
|
|
34
|
+
/**
|
|
35
|
+
* Returns the perceived luminance of a color, from 0-1.
|
|
36
|
+
*/
|
|
37
|
+
getLuminance(): number;
|
|
38
|
+
/**
|
|
39
|
+
* Returns the alpha value of a color, from 0-1.
|
|
40
|
+
*/
|
|
41
|
+
getAlpha(): number;
|
|
42
|
+
/**
|
|
43
|
+
* Sets the alpha value on the current color.
|
|
44
|
+
*
|
|
45
|
+
* @param alpha - The new alpha value. The accepted range is 0-1.
|
|
46
|
+
*/
|
|
47
|
+
setAlpha(alpha?: string | number): this;
|
|
48
|
+
/**
|
|
49
|
+
* Returns whether the color is monochrome.
|
|
50
|
+
*/
|
|
51
|
+
isMonochrome(): boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Returns the object as a HSVA object.
|
|
54
|
+
*/
|
|
55
|
+
toHsv(): Numberify<HSVA>;
|
|
56
|
+
toHsv_(): Numberify<HSVA>;
|
|
57
|
+
/**
|
|
58
|
+
* Returns the hsva values interpolated into a string with the following format:
|
|
59
|
+
* "hsva(xxx, xxx, xxx, xx)".
|
|
60
|
+
*/
|
|
61
|
+
toHsvString(): string;
|
|
62
|
+
/**
|
|
63
|
+
* Returns the object as a HSLA object.
|
|
64
|
+
*/
|
|
65
|
+
toHsl(): Numberify<HSLA>;
|
|
66
|
+
/**
|
|
67
|
+
* Returns the hsla values interpolated into a string with the following format:
|
|
68
|
+
* "hsla(xxx, xxx, xxx, xx)".
|
|
69
|
+
*/
|
|
70
|
+
toHslString(): string;
|
|
71
|
+
/**
|
|
72
|
+
* Returns the hex value of the color.
|
|
73
|
+
* @param allow3Char will shorten hex value to 3 char if possible
|
|
74
|
+
*/
|
|
75
|
+
toHex(allow3Char?: boolean): string;
|
|
76
|
+
/**
|
|
77
|
+
* Returns the hex value of the color -with a # prefixed.
|
|
78
|
+
* @param allow3Char will shorten hex value to 3 char if possible
|
|
79
|
+
*/
|
|
80
|
+
toHexString(allow3Char?: boolean): string;
|
|
81
|
+
/**
|
|
82
|
+
* Returns the hex 8 value of the color.
|
|
83
|
+
* @param allow4Char will shorten hex value to 4 char if possible
|
|
84
|
+
*/
|
|
85
|
+
toHex8(allow4Char?: boolean): string;
|
|
86
|
+
/**
|
|
87
|
+
* Returns the hex 8 value of the color -with a # prefixed.
|
|
88
|
+
* @param allow4Char will shorten hex value to 4 char if possible
|
|
89
|
+
*/
|
|
90
|
+
toHex8String(allow4Char?: boolean): string;
|
|
91
|
+
/**
|
|
92
|
+
* Returns the shorter hex value of the color depends on its alpha -with a # prefixed.
|
|
93
|
+
* @param allowShortChar will shorten hex value to 3 or 4 char if possible
|
|
94
|
+
*/
|
|
95
|
+
toHexShortString(allowShortChar?: boolean): string;
|
|
96
|
+
/**
|
|
97
|
+
* Returns the object as a RGBA object.
|
|
98
|
+
*/
|
|
99
|
+
toRgb(): Numberify<RGBA>;
|
|
100
|
+
toRgba(): Numberify<RGBA>;
|
|
101
|
+
toRgbArray(): number[];
|
|
102
|
+
toRgbArrayString(): string;
|
|
103
|
+
/**
|
|
104
|
+
* Returns the RGBA values interpolated into a string with the following format:
|
|
105
|
+
* "RGBA(xxx, xxx, xxx, xx)".
|
|
106
|
+
*/
|
|
107
|
+
toRgbString(): string;
|
|
108
|
+
toRgbaString(): string;
|
|
109
|
+
/**
|
|
110
|
+
* Returns the object as a RGBA object.
|
|
111
|
+
*/
|
|
112
|
+
toPercentageRgb(): RGBA;
|
|
113
|
+
/**
|
|
114
|
+
* Returns the RGBA relative values interpolated into a string
|
|
115
|
+
*/
|
|
116
|
+
toPercentageRgbString(): string;
|
|
117
|
+
toCmyk(): Numberify<CMYK>;
|
|
118
|
+
toCmykString(): string;
|
|
119
|
+
/**
|
|
120
|
+
* The 'real' name of the color -if there is one.
|
|
121
|
+
*/
|
|
122
|
+
toName(): string | false;
|
|
123
|
+
/**
|
|
124
|
+
* String representation of the color.
|
|
125
|
+
*
|
|
126
|
+
* @param format - The format to be used when displaying the string representation.
|
|
127
|
+
*/
|
|
128
|
+
toString<T extends 'name'>(format: T): boolean | string;
|
|
129
|
+
toString<T extends ColorFormats>(format?: T): string;
|
|
130
|
+
toNumber(): number;
|
|
131
|
+
clone(): TinyColor;
|
|
132
|
+
/**
|
|
133
|
+
* Lighten the color a given amount. Providing 100 will always return white.
|
|
134
|
+
* @param amount - valid between 1-100
|
|
135
|
+
*/
|
|
136
|
+
lighten(amount?: number): TinyColor;
|
|
137
|
+
/**
|
|
138
|
+
* Brighten the color a given amount, from 0 to 100.
|
|
139
|
+
* @param amount - valid between 1-100
|
|
140
|
+
*/
|
|
141
|
+
brighten(amount?: number): TinyColor;
|
|
142
|
+
/**
|
|
143
|
+
* Darken the color a given amount, from 0 to 100.
|
|
144
|
+
* Providing 100 will always return black.
|
|
145
|
+
* @param amount - valid between 1-100
|
|
146
|
+
*/
|
|
147
|
+
darken(amount?: number): TinyColor;
|
|
148
|
+
/**
|
|
149
|
+
* Mix the color with pure white, from 0 to 100.
|
|
150
|
+
* Providing 0 will do nothing, providing 100 will always return white.
|
|
151
|
+
* @param amount - valid between 1-100
|
|
152
|
+
*/
|
|
153
|
+
tint(amount?: number): TinyColor;
|
|
154
|
+
/**
|
|
155
|
+
* Mix the color with pure black, from 0 to 100.
|
|
156
|
+
* Providing 0 will do nothing, providing 100 will always return black.
|
|
157
|
+
* @param amount - valid between 1-100
|
|
158
|
+
*/
|
|
159
|
+
shade(amount?: number): TinyColor;
|
|
160
|
+
/**
|
|
161
|
+
* Desaturate the color a given amount, from 0 to 100.
|
|
162
|
+
* Providing 100 will is the same as calling greyscale
|
|
163
|
+
* @param amount - valid between 1-100
|
|
164
|
+
*/
|
|
165
|
+
desaturate(amount?: number): TinyColor;
|
|
166
|
+
/**
|
|
167
|
+
* Saturate the color a given amount, from 0 to 100.
|
|
168
|
+
* @param amount - valid between 1-100
|
|
169
|
+
*/
|
|
170
|
+
saturate(amount?: number): TinyColor;
|
|
171
|
+
/**
|
|
172
|
+
* Completely desaturates a color into greyscale.
|
|
173
|
+
* Same as calling `desaturate(100)`
|
|
174
|
+
*/
|
|
175
|
+
greyscale(): TinyColor;
|
|
176
|
+
/**
|
|
177
|
+
* Spin takes a positive or negative amount within [-360, 360] indicating the change of hue.
|
|
178
|
+
* Values outside of this range will be wrapped into this range.
|
|
179
|
+
*/
|
|
180
|
+
spin(amount: number): TinyColor;
|
|
181
|
+
/**
|
|
182
|
+
* Mix the current color a given amount with another color, from 0 to 100.
|
|
183
|
+
* 0 means no mixing (return current color).
|
|
184
|
+
*/
|
|
185
|
+
mix(color: ColorInput, amount?: number): TinyColor;
|
|
186
|
+
analogous(results?: number, slices?: number): TinyColor[];
|
|
187
|
+
/**
|
|
188
|
+
* taken from https://github.com/infusion/jQuery-xcolor/blob/master/jquery.xcolor.js
|
|
189
|
+
*/
|
|
190
|
+
complement(): TinyColor;
|
|
191
|
+
monochromatic(results?: number): TinyColor[];
|
|
192
|
+
splitcomplement(): TinyColor[];
|
|
193
|
+
/**
|
|
194
|
+
* Compute how the color would appear on a background
|
|
195
|
+
*/
|
|
196
|
+
onBackground(background: ColorInput): TinyColor;
|
|
197
|
+
/**
|
|
198
|
+
* Alias for `polyad(3)`
|
|
199
|
+
*/
|
|
200
|
+
triad(): TinyColor[];
|
|
201
|
+
/**
|
|
202
|
+
* Alias for `polyad(4)`
|
|
203
|
+
*/
|
|
204
|
+
tetrad(): TinyColor[];
|
|
205
|
+
/**
|
|
206
|
+
* Get polyad colors, like (for 1, 2, 3, 4, 5, 6, 7, 8, etc...)
|
|
207
|
+
* monad, dyad, triad, tetrad, pentad, hexad, heptad, octad, etc...
|
|
208
|
+
*/
|
|
209
|
+
polyad(n: number): TinyColor[];
|
|
210
|
+
/**
|
|
211
|
+
* compare color vs current color
|
|
212
|
+
*/
|
|
213
|
+
equals(color?: ColorInput): boolean;
|
|
214
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* convert all properties in an interface to a number
|
|
3
|
+
*/
|
|
4
|
+
export type Numberify<T> = {
|
|
5
|
+
[P in keyof T]: number;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* A representation of additive color mixing.
|
|
9
|
+
* Projection of primary color lights on a white screen shows secondary
|
|
10
|
+
* colors where two overlap; the combination of all three of red, green,
|
|
11
|
+
* and blue in equal intensities makes white.
|
|
12
|
+
*/
|
|
13
|
+
export interface RGB {
|
|
14
|
+
r: number | string;
|
|
15
|
+
g: number | string;
|
|
16
|
+
b: number | string;
|
|
17
|
+
}
|
|
18
|
+
export interface RGBA extends RGB {
|
|
19
|
+
a: number;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The HSL model describes colors in terms of hue, saturation,
|
|
23
|
+
* and lightness (also called luminance).
|
|
24
|
+
* @link https://en.wikibooks.org/wiki/Color_Models:_RGB,_HSV,_HSL#HSL
|
|
25
|
+
*/
|
|
26
|
+
export interface HSL {
|
|
27
|
+
h: number | string;
|
|
28
|
+
s: number | string;
|
|
29
|
+
l: number | string;
|
|
30
|
+
}
|
|
31
|
+
export interface HSLA extends HSL {
|
|
32
|
+
a: number;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The HSV, or HSB, model describes colors in terms of
|
|
36
|
+
* hue, saturation, and value (brightness).
|
|
37
|
+
* @link https://en.wikibooks.org/wiki/Color_Models:_RGB,_HSV,_HSL#HSV
|
|
38
|
+
*/
|
|
39
|
+
export interface HSV {
|
|
40
|
+
h: number | string;
|
|
41
|
+
s: number | string;
|
|
42
|
+
v: number | string;
|
|
43
|
+
}
|
|
44
|
+
export interface HSVA extends HSV {
|
|
45
|
+
a: number;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* The CMYK color model is a subtractive color model used in the printing process.
|
|
49
|
+
* It described four ink palettes: Cyan, Magenta, Yellow, and Black.
|
|
50
|
+
* @link https://en.wikipedia.org/wiki/CMYK_color_model
|
|
51
|
+
*/
|
|
52
|
+
export interface CMYK {
|
|
53
|
+
c: number | string;
|
|
54
|
+
m: number | string;
|
|
55
|
+
y: number | string;
|
|
56
|
+
k: number | string;
|
|
57
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from './conversion.js';
|
|
2
|
+
export * from './css-color-names.js';
|
|
3
|
+
export * from './format-input.js';
|
|
4
|
+
export * from './from-ratio.js';
|
|
5
|
+
export * from './index.js';
|
|
6
|
+
export * from './interfaces.js';
|
|
7
|
+
export * from './random.js';
|
|
8
|
+
export * from './readability.js';
|
|
9
|
+
export * from './to-ms-filter.js';
|
|
10
|
+
export * from './util.js';
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { TinyColor } from './index.js';
|
|
2
|
+
export interface RandomOptions {
|
|
3
|
+
seed?: number;
|
|
4
|
+
hue?: number | string | 'red' | 'orange' | 'yellow' | 'green' | 'blue' | 'purple' | 'pink' | 'monochrome';
|
|
5
|
+
luminosity?: 'random' | 'bright' | 'dark' | 'light';
|
|
6
|
+
alpha?: number;
|
|
7
|
+
}
|
|
8
|
+
export interface RandomCountOptions extends RandomOptions {
|
|
9
|
+
count?: number | null;
|
|
10
|
+
}
|
|
11
|
+
export declare function random(options?: RandomOptions): TinyColor;
|
|
12
|
+
export declare function random(options?: RandomCountOptions): TinyColor[];
|
|
13
|
+
/**
|
|
14
|
+
* @hidden
|
|
15
|
+
*/
|
|
16
|
+
export interface ColorBound {
|
|
17
|
+
name: string;
|
|
18
|
+
hueRange: [number, number] | null;
|
|
19
|
+
lowerBounds: Array<[number, number]>;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* @hidden
|
|
23
|
+
*/
|
|
24
|
+
export declare const bounds: ColorBound[];
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { ColorInput, TinyColor } from './index.js';
|
|
2
|
+
/**
|
|
3
|
+
* AKA `contrast`
|
|
4
|
+
*
|
|
5
|
+
* Analyze the 2 colors and returns the color contrast defined by (WCAG Version 2)
|
|
6
|
+
*/
|
|
7
|
+
export declare function readability(color1: ColorInput, color2: ColorInput): number;
|
|
8
|
+
export interface WCAG2Parms {
|
|
9
|
+
level?: 'AA' | 'AAA';
|
|
10
|
+
size?: 'large' | 'small';
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Ensure that foreground and background color combinations meet WCAG2 guidelines.
|
|
14
|
+
* The third argument is an object.
|
|
15
|
+
* the 'level' property states 'AA' or 'AAA' - if missing or invalid, it defaults to 'AA';
|
|
16
|
+
* the 'size' property states 'large' or 'small' - if missing or invalid, it defaults to 'small'.
|
|
17
|
+
* If the entire object is absent, isReadable defaults to {level:"AA",size:"small"}.
|
|
18
|
+
*
|
|
19
|
+
* Example
|
|
20
|
+
* ```ts
|
|
21
|
+
* new TinyColor().isReadable('#000', '#111') => false
|
|
22
|
+
* new TinyColor().isReadable('#000', '#111', { level: 'AA', size: 'large' }) => false
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare function isReadable(color1: ColorInput, color2: ColorInput, wcag2?: WCAG2Parms): boolean;
|
|
26
|
+
export interface WCAG2FallbackParms extends WCAG2Parms {
|
|
27
|
+
includeFallbackColors?: boolean;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Given a base color and a list of possible foreground or background
|
|
31
|
+
* colors for that base, returns the most readable color.
|
|
32
|
+
* Optionally returns Black or White if the most readable color is unreadable.
|
|
33
|
+
*
|
|
34
|
+
* @param baseColor - the base color.
|
|
35
|
+
* @param colorList - array of colors to pick the most readable one from.
|
|
36
|
+
* @param args - and object with extra arguments
|
|
37
|
+
*
|
|
38
|
+
* Example
|
|
39
|
+
* ```ts
|
|
40
|
+
* new TinyColor().mostReadable('#123', ['#124", "#125'], { includeFallbackColors: false }).toHexString(); // "#112255"
|
|
41
|
+
* new TinyColor().mostReadable('#123', ['#124", "#125'],{ includeFallbackColors: true }).toHexString(); // "#ffffff"
|
|
42
|
+
* new TinyColor().mostReadable('#a8015a', ["#faf3f3"], { includeFallbackColors:true, level: 'AAA', size: 'large' }).toHexString(); // "#faf3f3"
|
|
43
|
+
* new TinyColor().mostReadable('#a8015a', ["#faf3f3"], { includeFallbackColors:true, level: 'AAA', size: 'small' }).toHexString(); // "#ffffff"
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export declare function mostReadable(baseColor: ColorInput, colorList: ColorInput[], args?: WCAG2FallbackParms): TinyColor | null;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { names } from './css-color-names.js';
|
|
2
|
+
import { inputToRGB, isValidCSSUnit, stringInputToObject } from './format-input.js';
|
|
3
|
+
import { fromRatio, legacyRandom } from './from-ratio.js';
|
|
4
|
+
import { TinyColor } from './index.js';
|
|
5
|
+
import { random } from './random.js';
|
|
6
|
+
import { mostReadable, readability } from './readability.js';
|
|
7
|
+
import { toMsFilter } from './to-ms-filter.js';
|
|
8
|
+
export interface TinyColorUMD {
|
|
9
|
+
TinyColor: typeof TinyColor;
|
|
10
|
+
readability: typeof readability;
|
|
11
|
+
random: typeof random;
|
|
12
|
+
names: typeof names;
|
|
13
|
+
fromRatio: typeof fromRatio;
|
|
14
|
+
legacyRandom: typeof legacyRandom;
|
|
15
|
+
toMsFilter: typeof toMsFilter;
|
|
16
|
+
inputToRGB: typeof inputToRGB;
|
|
17
|
+
stringInputToObject: typeof stringInputToObject;
|
|
18
|
+
isValidCSSUnit: typeof isValidCSSUnit;
|
|
19
|
+
mostReadable: typeof mostReadable;
|
|
20
|
+
}
|
|
21
|
+
declare const tinycolorumd: TinyColorUMD;
|
|
22
|
+
export default tinycolorumd;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Take input from [0, n] and return it as [0, 1]
|
|
3
|
+
* @hidden
|
|
4
|
+
*/
|
|
5
|
+
export declare function bound01(n: any, max: number): number;
|
|
6
|
+
/**
|
|
7
|
+
* Force a number between 0 and 1
|
|
8
|
+
* @hidden
|
|
9
|
+
*/
|
|
10
|
+
export declare function clamp01(val: number): number;
|
|
11
|
+
/**
|
|
12
|
+
* Need to handle 1.0 as 100%, since once it is a number, there is no difference between it and 1
|
|
13
|
+
* <http://stackoverflow.com/questions/7422072/javascript-how-to-detect-number-as-a-decimal-including-1-0>
|
|
14
|
+
* @hidden
|
|
15
|
+
*/
|
|
16
|
+
export declare function isOnePointZero(n: string | number): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Check to see if string passed in is a percentage
|
|
19
|
+
* @hidden
|
|
20
|
+
*/
|
|
21
|
+
export declare function isPercentage(n: string | number): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Return a valid alpha value [0,1] with all invalid values being set to 1
|
|
24
|
+
* @hidden
|
|
25
|
+
*/
|
|
26
|
+
export declare function boundAlpha(a?: number | string): number;
|
|
27
|
+
/**
|
|
28
|
+
* Replace a decimal with it's percentage value
|
|
29
|
+
* @hidden
|
|
30
|
+
*/
|
|
31
|
+
export declare function convertToPercentage(n: number | string): number | string;
|
|
32
|
+
/**
|
|
33
|
+
* Force a hex value to have 2 characters
|
|
34
|
+
* @hidden
|
|
35
|
+
*/
|
|
36
|
+
export declare function pad2(c: string): string;
|
package/types/tree/index.d.ts
CHANGED
|
@@ -6,3 +6,4 @@ export function getLabelFromDictionaryByValue(a: any, value: any, 保底?: boole
|
|
|
6
6
|
export function getChildWithParentBy(root: any, key: any, value: any, childrenKey?: string): null | undefined;
|
|
7
7
|
export function getItemBy2(root: any, key: any, value: any, childrenKey?: string): any;
|
|
8
8
|
export default getItemBy;
|
|
9
|
+
export { default as searchTree } from "./search";
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 基础原始类型定义(string/number/boolean/symbol/null/undefined)
|
|
3
|
+
*/
|
|
4
|
+
type Primitive = string | number | boolean | symbol | null | undefined;
|
|
5
|
+
/**
|
|
6
|
+
* 条件值类型,可以是:
|
|
7
|
+
* 1. 原始值(Primitive)
|
|
8
|
+
* 2. 判断函数(接收节点值返回boolean)
|
|
9
|
+
* 3. 正则表达式
|
|
10
|
+
* @template T 节点值的泛型类型
|
|
11
|
+
*/
|
|
12
|
+
type ConditionValue<T = unknown> = Primitive | ((value: T) => boolean) | RegExp;
|
|
13
|
+
/**
|
|
14
|
+
* 树搜索配置选项接口
|
|
15
|
+
*/
|
|
16
|
+
interface SearchOptions {
|
|
17
|
+
/**
|
|
18
|
+
* 遍历策略:广度优先(BFS)或深度优先(DFS)
|
|
19
|
+
* @default 'BFS'
|
|
20
|
+
*/
|
|
21
|
+
strategy?: 'BFS' | 'DFS';
|
|
22
|
+
/**
|
|
23
|
+
* 子节点字段名
|
|
24
|
+
* @default 'children'
|
|
25
|
+
*/
|
|
26
|
+
childrenKey?: string;
|
|
27
|
+
/**
|
|
28
|
+
* 是否启用严格模式比较(===)
|
|
29
|
+
* @default false
|
|
30
|
+
*/
|
|
31
|
+
strict?: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* 是否启用字符串模糊匹配
|
|
34
|
+
* @default false
|
|
35
|
+
*/
|
|
36
|
+
fuzzyMatch?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* 是否返回所有匹配结果(否则返回第一个匹配)
|
|
39
|
+
* @default false
|
|
40
|
+
*/
|
|
41
|
+
returnAllMatches?: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* 字符串匹配是否区分大小写
|
|
44
|
+
* @default false
|
|
45
|
+
*/
|
|
46
|
+
caseSensitive?: boolean;
|
|
47
|
+
/**
|
|
48
|
+
* 多条件匹配模式:AND(所有条件需满足)或OR(任一条件满足)
|
|
49
|
+
* @default 'AND'
|
|
50
|
+
*/
|
|
51
|
+
matchMode?: 'AND' | 'OR';
|
|
52
|
+
/**
|
|
53
|
+
* 字符串匹配是否允许空字符
|
|
54
|
+
* @default false
|
|
55
|
+
*/
|
|
56
|
+
allowEmptyString?: boolean;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* 树节点接口定义
|
|
60
|
+
*/
|
|
61
|
+
interface TreeNode {
|
|
62
|
+
/**
|
|
63
|
+
* 动态属性(任意键值对)
|
|
64
|
+
*/
|
|
65
|
+
[key: string]: unknown;
|
|
66
|
+
/**
|
|
67
|
+
* 子节点数组(可选)
|
|
68
|
+
*/
|
|
69
|
+
children?: TreeNode[];
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* 高级树搜索函数
|
|
73
|
+
* @param treeData 要搜索的树数据(必须是数组)
|
|
74
|
+
* @param searchCondition 搜索条件对象(键值对)
|
|
75
|
+
* @param options 搜索配置选项
|
|
76
|
+
* @returns 返回匹配的节点或节点数组(根据returnAllMatches决定)
|
|
77
|
+
* @throws 当参数不符合要求时抛出TypeError或Error
|
|
78
|
+
*/
|
|
79
|
+
declare function searchTree(treeData: TreeNode[], searchCondition: Record<string, ConditionValue>, options?: SearchOptions): TreeNode | TreeNode[] | null;
|
|
80
|
+
export default searchTree;
|