@oscarpalmer/atoms 0.188.1 → 0.189.0
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/dist/array/difference.d.mts +0 -1
- package/dist/array/exists.d.mts +0 -1
- package/dist/array/filter.d.mts +0 -1
- package/dist/array/find.d.mts +0 -1
- package/dist/array/first.d.mts +0 -1
- package/dist/array/flatten.d.mts +0 -1
- package/dist/array/get.d.mts +0 -1
- package/dist/array/group-by.d.mts +0 -1
- package/dist/array/last.d.mts +0 -1
- package/dist/array/match.d.mts +0 -1
- package/dist/array/match.mjs +3 -3
- package/dist/array/move.d.mts +0 -1
- package/dist/array/partition.d.mts +0 -1
- package/dist/array/select.d.mts +0 -1
- package/dist/array/select.mjs +2 -1
- package/dist/array/single.d.mts +0 -1
- package/dist/array/slice.d.mts +0 -1
- package/dist/array/sort.d.mts +1 -2
- package/dist/array/sort.mjs +0 -1
- package/dist/array/swap.d.mts +0 -1
- package/dist/array/to-map.d.mts +0 -1
- package/dist/array/to-record.d.mts +0 -1
- package/dist/array/to-set.d.mts +0 -1
- package/dist/array/toggle.d.mts +0 -1
- package/dist/array/unique.d.mts +0 -1
- package/dist/array/update.d.mts +0 -1
- package/dist/color/constants.d.mts +9 -10
- package/dist/color/constants.mjs +15 -7
- package/dist/color/index.d.mts +9 -9
- package/dist/color/index.mjs +8 -7
- package/dist/color/instance.d.mts +35 -8
- package/dist/color/instance.mjs +53 -13
- package/dist/color/misc/alpha.d.mts +0 -1
- package/dist/color/misc/alpha.mjs +5 -5
- package/dist/color/misc/get.d.mts +42 -13
- package/dist/color/misc/get.mjs +45 -24
- package/dist/color/misc/index.d.mts +4 -4
- package/dist/color/misc/index.mjs +12 -12
- package/dist/color/misc/is.d.mts +56 -3
- package/dist/color/misc/is.mjs +72 -4
- package/dist/color/misc/state.d.mts +2 -2
- package/dist/color/misc/state.mjs +79 -43
- package/dist/color/models.d.mts +18 -2
- package/dist/color/space/hex.d.mts +38 -5
- package/dist/color/space/hex.mjs +57 -9
- package/dist/color/space/hsl.d.mts +33 -7
- package/dist/color/space/hsl.mjs +65 -14
- package/dist/color/space/hwb.d.mts +52 -0
- package/dist/color/space/hwb.mjs +99 -0
- package/dist/color/space/rgb.d.mts +26 -5
- package/dist/color/space/rgb.mjs +82 -28
- package/dist/function/assert.d.mts +1 -2
- package/dist/function/limit.d.mts +0 -1
- package/dist/function/memoize.d.mts +0 -1
- package/dist/function/once.d.mts +0 -1
- package/dist/function/retry.d.mts +0 -1
- package/dist/function/work.d.mts +0 -1
- package/dist/herald.d.mts +0 -1
- package/dist/index.d.mts +296 -51
- package/dist/index.mjs +657 -259
- package/dist/internal/array/callbacks.d.mts +0 -1
- package/dist/internal/array/callbacks.mjs +0 -1
- package/dist/internal/array/group.d.mts +0 -1
- package/dist/internal/array/index-of.d.mts +0 -1
- package/dist/internal/function/timer.d.mts +0 -1
- package/dist/internal/is.d.mts +0 -1
- package/dist/internal/is.mjs +1 -1
- package/dist/internal/math/aggregate.d.mts +0 -1
- package/dist/internal/math/misc.d.mts +12 -0
- package/dist/internal/math/misc.mjs +19 -0
- package/dist/internal/result.d.mts +0 -1
- package/dist/internal/value/compare.d.mts +0 -1
- package/dist/internal/value/equal.d.mts +0 -1
- package/dist/internal/value/get.d.mts +0 -1
- package/dist/internal/value/handlers.d.mts +0 -1
- package/dist/internal/value/has.d.mts +0 -1
- package/dist/internal/value/misc.d.mts +0 -1
- package/dist/internal/value/set.d.mts +0 -1
- package/dist/is.d.mts +0 -1
- package/dist/math.d.mts +1 -9
- package/dist/math.mjs +1 -16
- package/dist/models.d.mts +6 -6
- package/dist/promise/delay.d.mts +0 -1
- package/dist/promise/helpers.d.mts +0 -1
- package/dist/promise/index.d.mts +0 -1
- package/dist/promise/misc.d.mts +0 -1
- package/dist/promise/models.d.mts +4 -5
- package/dist/promise/models.mjs +1 -1
- package/dist/promise/timed.d.mts +0 -1
- package/dist/query.d.mts +0 -1
- package/dist/query.mjs +1 -1
- package/dist/queue.d.mts +0 -1
- package/dist/random.d.mts +0 -1
- package/dist/result/index.d.mts +0 -1
- package/dist/result/index.mjs +2 -1
- package/dist/result/match.d.mts +0 -1
- package/dist/result/misc.d.mts +0 -1
- package/dist/result/models.d.mts +0 -1
- package/dist/result/work/flow.d.mts +0 -1
- package/dist/result/work/pipe.d.mts +0 -1
- package/dist/string/fuzzy.d.mts +0 -1
- package/dist/string/index.d.mts +0 -1
- package/dist/string/index.mjs +1 -1
- package/dist/string/template.d.mts +0 -1
- package/dist/value/clone.d.mts +0 -1
- package/dist/value/freeze.d.mts +1 -2
- package/dist/value/merge.d.mts +0 -1
- package/dist/value/omit.d.mts +0 -1
- package/dist/value/pick.d.mts +0 -1
- package/dist/value/shake.d.mts +1 -2
- package/dist/value/smush.d.mts +1 -2
- package/dist/value/transform.d.mts +1 -2
- package/dist/value/unsmush.d.mts +1 -2
- package/package.json +5 -5
- package/src/color/constants.ts +17 -13
- package/src/color/index.ts +21 -6
- package/src/color/instance.ts +67 -14
- package/src/color/misc/alpha.ts +6 -10
- package/src/color/misc/get.ts +70 -16
- package/src/color/misc/index.ts +18 -17
- package/src/color/misc/is.ts +86 -3
- package/src/color/misc/state.ts +126 -40
- package/src/color/models.ts +19 -1
- package/src/color/space/hex.ts +55 -8
- package/src/color/space/hsl.ts +80 -14
- package/src/color/space/hwb.ts +123 -0
- package/src/color/space/rgb.ts +108 -27
- package/src/internal/math/misc.ts +28 -0
- package/src/math.ts +2 -29
package/dist/array/exists.d.mts
CHANGED
package/dist/array/filter.d.mts
CHANGED
package/dist/array/find.d.mts
CHANGED
package/dist/array/first.d.mts
CHANGED
package/dist/array/flatten.d.mts
CHANGED
package/dist/array/get.d.mts
CHANGED
package/dist/array/last.d.mts
CHANGED
package/dist/array/match.d.mts
CHANGED
package/dist/array/match.mjs
CHANGED
|
@@ -49,10 +49,10 @@ const COMPARISON_INVALID = "invalid";
|
|
|
49
49
|
const COMPARISON_OUTSIDE = "outside";
|
|
50
50
|
const COMPARISON_SAME = "same";
|
|
51
51
|
const COMPARISON_START = "start";
|
|
52
|
-
const endings = new Set([COMPARISON_END, COMPARISON_SAME]);
|
|
52
|
+
const endings = /* @__PURE__ */ new Set([COMPARISON_END, COMPARISON_SAME]);
|
|
53
53
|
const invalid = [-1, COMPARISON_INVALID];
|
|
54
54
|
const outside = [-1, COMPARISON_OUTSIDE];
|
|
55
|
-
const outsides = new Set([COMPARISON_INVALID, COMPARISON_OUTSIDE]);
|
|
56
|
-
const starts = new Set([COMPARISON_START, COMPARISON_SAME]);
|
|
55
|
+
const outsides = /* @__PURE__ */ new Set([COMPARISON_INVALID, COMPARISON_OUTSIDE]);
|
|
56
|
+
const starts = /* @__PURE__ */ new Set([COMPARISON_START, COMPARISON_SAME]);
|
|
57
57
|
//#endregion
|
|
58
58
|
export { endsWithArray, getArrayComparison, includesArray, indexOfArray, startsWithArray };
|
package/dist/array/move.d.mts
CHANGED
package/dist/array/select.d.mts
CHANGED
package/dist/array/select.mjs
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { findValues } from "../internal/array/find.mjs";
|
|
2
2
|
//#region src/array/select.ts
|
|
3
3
|
function select(array, ...parameters) {
|
|
4
|
-
|
|
4
|
+
const mapper = parameters.pop();
|
|
5
|
+
return findValues("all", array, parameters, mapper).matched;
|
|
5
6
|
}
|
|
6
7
|
//#endregion
|
|
7
8
|
export { select };
|
package/dist/array/single.d.mts
CHANGED
package/dist/array/slice.d.mts
CHANGED
package/dist/array/sort.d.mts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { PlainObject, Primitive } from "../models.mjs";
|
|
2
|
-
|
|
3
2
|
//#region src/array/sort.d.ts
|
|
4
3
|
/**
|
|
5
4
|
* Sorting information for arrays _(using a comparison callback)_
|
|
@@ -34,7 +33,7 @@ type ArrayKeySorter<Item extends PlainObject, ItemKey extends keyof Item> = {
|
|
|
34
33
|
/**
|
|
35
34
|
* Sorters based on keys in an object
|
|
36
35
|
*/
|
|
37
|
-
type ArrayKeySorters<Item extends PlainObject> = { [ItemKey in keyof Item]: ArrayKeySorter<Item, ItemKey
|
|
36
|
+
type ArrayKeySorters<Item extends PlainObject> = { [ItemKey in keyof Item]: ArrayKeySorter<Item, ItemKey>; }[keyof Item];
|
|
38
37
|
/**
|
|
39
38
|
* Sorter to use for sorting
|
|
40
39
|
*/
|
package/dist/array/sort.mjs
CHANGED
|
@@ -55,7 +55,6 @@ function getSorter(value, modifier) {
|
|
|
55
55
|
case typeof value === "function": return getComparisonSorter(value, modifier);
|
|
56
56
|
case typeof value === "string": return getValueSorter(value, modifier);
|
|
57
57
|
case isPlainObject(value): return getObjectSorter(value, modifier);
|
|
58
|
-
default: break;
|
|
59
58
|
}
|
|
60
59
|
}
|
|
61
60
|
function getSorters(value, modifier) {
|
package/dist/array/swap.d.mts
CHANGED
package/dist/array/to-map.d.mts
CHANGED
package/dist/array/to-set.d.mts
CHANGED
package/dist/array/toggle.d.mts
CHANGED
package/dist/array/unique.d.mts
CHANGED
package/dist/array/update.d.mts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import { Alpha,
|
|
2
|
-
|
|
1
|
+
import { Alpha, HSLAColor, HSLColor, HWBAColor, HWBColor, RGBAColor, RGBColor } from "./models.mjs";
|
|
3
2
|
//#region src/color/constants.d.ts
|
|
4
3
|
declare const ALPHA_FULL_HEX_SHORT = "f";
|
|
5
4
|
declare const ALPHA_FULL_HEX_LONG = "ff";
|
|
6
|
-
declare const ALPHA_FULL_VALUE = 1;
|
|
7
5
|
declare const ALPHA_NONE_HEX = "00";
|
|
8
6
|
declare const ALPHA_NONE_VALUE = 0;
|
|
9
7
|
declare const DEFAULT_ALPHA: Alpha;
|
|
10
8
|
declare const DEFAULT_HSL: HSLColor;
|
|
9
|
+
declare const DEFAULT_HWB: HWBColor;
|
|
11
10
|
declare const DEFAULT_RGB: RGBColor;
|
|
12
11
|
declare const EXPRESSION_HEX_LONG: RegExp;
|
|
13
12
|
declare const EXPRESSION_HEX_SHORT: RegExp;
|
|
@@ -16,15 +15,15 @@ declare const HEX_BLACK = "000000";
|
|
|
16
15
|
declare const HEX_WHITE = "ffffff";
|
|
17
16
|
declare const LENGTH_LONG = 6;
|
|
18
17
|
declare const LENGTH_SHORT = 3;
|
|
19
|
-
declare const KEYS_HSL:
|
|
20
|
-
declare const KEYS_HSLA:
|
|
21
|
-
declare const
|
|
22
|
-
declare const
|
|
18
|
+
declare const KEYS_HSL: Array<keyof HSLColor>;
|
|
19
|
+
declare const KEYS_HSLA: Array<keyof HSLAColor>;
|
|
20
|
+
declare const KEYS_HWB: Array<keyof HWBColor>;
|
|
21
|
+
declare const KEYS_HWBA: Array<keyof HWBAColor>;
|
|
22
|
+
declare const KEYS_RGB: Array<keyof RGBColor>;
|
|
23
|
+
declare const KEYS_RGBA: Array<keyof RGBAColor>;
|
|
23
24
|
declare const MAX_DEGREE = 360;
|
|
24
25
|
declare const MAX_HEX = 255;
|
|
25
26
|
declare const MAX_PERCENT = 100;
|
|
26
|
-
declare const SPACE_HSL: ColorSpace;
|
|
27
|
-
declare const SPACE_RGB: ColorSpace;
|
|
28
27
|
declare const SRGB_LUMINANCE_BLUE = 0.0722;
|
|
29
28
|
declare const SRGB_LUMINANCE_EXPONENT = 2.4;
|
|
30
29
|
declare const SRGB_LUMINANCE_GREEN = 0.7152;
|
|
@@ -35,4 +34,4 @@ declare const SRGB_LUMINANCE_OFFSET = 0.055;
|
|
|
35
34
|
declare const SRGB_LUMINANCE_RED = 0.2126;
|
|
36
35
|
declare const SRGB_LUMINANCE_THRESHOLD = 0.625;
|
|
37
36
|
//#endregion
|
|
38
|
-
export { ALPHA_FULL_HEX_LONG, ALPHA_FULL_HEX_SHORT,
|
|
37
|
+
export { ALPHA_FULL_HEX_LONG, ALPHA_FULL_HEX_SHORT, ALPHA_NONE_HEX, ALPHA_NONE_VALUE, DEFAULT_ALPHA, DEFAULT_HSL, DEFAULT_HWB, DEFAULT_RGB, EXPRESSION_HEX_LONG, EXPRESSION_HEX_SHORT, EXPRESSION_PREFIX, HEX_BLACK, HEX_WHITE, KEYS_HSL, KEYS_HSLA, KEYS_HWB, KEYS_HWBA, KEYS_RGB, KEYS_RGBA, LENGTH_LONG, LENGTH_SHORT, MAX_DEGREE, MAX_HEX, MAX_PERCENT, SRGB_LUMINANCE_BLUE, SRGB_LUMINANCE_EXPONENT, SRGB_LUMINANCE_GREEN, SRGB_LUMINANCE_MINIMUM, SRGB_LUMINANCE_MODIFIER, SRGB_LUMINANCE_MULTIPLIER, SRGB_LUMINANCE_OFFSET, SRGB_LUMINANCE_RED, SRGB_LUMINANCE_THRESHOLD };
|
package/dist/color/constants.mjs
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
//#region src/color/constants.ts
|
|
2
2
|
const ALPHA_FULL_HEX_SHORT = "f";
|
|
3
3
|
const ALPHA_FULL_HEX_LONG = `ff`;
|
|
4
|
-
const ALPHA_FULL_VALUE = 1;
|
|
5
4
|
const ALPHA_NONE_HEX = "00";
|
|
6
5
|
const ALPHA_NONE_VALUE = 0;
|
|
7
6
|
const DEFAULT_ALPHA = {
|
|
8
7
|
hex: ALPHA_FULL_HEX_LONG,
|
|
9
|
-
value:
|
|
8
|
+
value: 100
|
|
10
9
|
};
|
|
11
10
|
const DEFAULT_HSL = {
|
|
12
11
|
hue: 0,
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
saturation: 0,
|
|
13
|
+
lightness: 0
|
|
14
|
+
};
|
|
15
|
+
const DEFAULT_HWB = {
|
|
16
|
+
hue: 0,
|
|
17
|
+
whiteness: 0,
|
|
18
|
+
blackness: 100
|
|
15
19
|
};
|
|
16
20
|
const DEFAULT_RGB = {
|
|
17
21
|
blue: 0,
|
|
@@ -31,6 +35,12 @@ const KEYS_HSL = [
|
|
|
31
35
|
"lightness"
|
|
32
36
|
];
|
|
33
37
|
const KEYS_HSLA = [...KEYS_HSL, "alpha"];
|
|
38
|
+
const KEYS_HWB = [
|
|
39
|
+
"hue",
|
|
40
|
+
"whiteness",
|
|
41
|
+
"blackness"
|
|
42
|
+
];
|
|
43
|
+
const KEYS_HWBA = [...KEYS_HWB, "alpha"];
|
|
34
44
|
const KEYS_RGB = [
|
|
35
45
|
"red",
|
|
36
46
|
"green",
|
|
@@ -40,8 +50,6 @@ const KEYS_RGBA = [...KEYS_RGB, "alpha"];
|
|
|
40
50
|
const MAX_DEGREE = 360;
|
|
41
51
|
const MAX_HEX = 255;
|
|
42
52
|
const MAX_PERCENT = 100;
|
|
43
|
-
const SPACE_HSL = "hsl";
|
|
44
|
-
const SPACE_RGB = "rgb";
|
|
45
53
|
const SRGB_LUMINANCE_BLUE = .0722;
|
|
46
54
|
const SRGB_LUMINANCE_EXPONENT = 2.4;
|
|
47
55
|
const SRGB_LUMINANCE_GREEN = .7152;
|
|
@@ -52,4 +60,4 @@ const SRGB_LUMINANCE_OFFSET = .055;
|
|
|
52
60
|
const SRGB_LUMINANCE_RED = .2126;
|
|
53
61
|
const SRGB_LUMINANCE_THRESHOLD = .625;
|
|
54
62
|
//#endregion
|
|
55
|
-
export { ALPHA_FULL_HEX_LONG, ALPHA_FULL_HEX_SHORT,
|
|
63
|
+
export { ALPHA_FULL_HEX_LONG, ALPHA_FULL_HEX_SHORT, ALPHA_NONE_HEX, ALPHA_NONE_VALUE, DEFAULT_ALPHA, DEFAULT_HSL, DEFAULT_HWB, DEFAULT_RGB, EXPRESSION_HEX_LONG, EXPRESSION_HEX_SHORT, EXPRESSION_PREFIX, HEX_BLACK, HEX_WHITE, KEYS_HSL, KEYS_HSLA, KEYS_HWB, KEYS_HWBA, KEYS_RGB, KEYS_RGBA, LENGTH_LONG, LENGTH_SHORT, MAX_DEGREE, MAX_HEX, MAX_PERCENT, SRGB_LUMINANCE_BLUE, SRGB_LUMINANCE_EXPONENT, SRGB_LUMINANCE_GREEN, SRGB_LUMINANCE_MINIMUM, SRGB_LUMINANCE_MODIFIER, SRGB_LUMINANCE_MULTIPLIER, SRGB_LUMINANCE_OFFSET, SRGB_LUMINANCE_RED, SRGB_LUMINANCE_THRESHOLD };
|
package/dist/color/index.d.mts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { HSLAColor, HSLColor, RGBAColor, RGBColor } from "./models.mjs";
|
|
1
|
+
import { HSLAColor, HSLColor, HWBAColor, HWBColor, RGBAColor, RGBColor } from "./models.mjs";
|
|
2
2
|
import { Color } from "./instance.mjs";
|
|
3
|
-
import { getForegroundColor, getHexColor, getHexaColor, getHslColor, getHslaColor, getRgbColor, getRgbaColor } from "./misc/get.mjs";
|
|
4
|
-
import { isColor, isHexColor, isHslColor, isHslLike, isHslaColor, isRgbColor, isRgbLike, isRgbaColor } from "./misc/is.mjs";
|
|
5
|
-
import { getNormalizedHex, hexToHsl, hexToHsla, hexToRgb, hexToRgba } from "./space/hex.mjs";
|
|
6
|
-
import { hslToHex, hslToRgb, hslToRgba } from "./space/hsl.mjs";
|
|
7
|
-
import {
|
|
8
|
-
|
|
3
|
+
import { getForegroundColor, getHexColor, getHexaColor, getHslColor, getHslaColor, getHwbColor, getHwbaColor, getRgbColor, getRgbaColor } from "./misc/get.mjs";
|
|
4
|
+
import { isColor, isHexColor, isHslColor, isHslLike, isHslaColor, isHwbColor, isHwbLike, isHwbaColor, isHwbaLike, isRgbColor, isRgbLike, isRgbaColor } from "./misc/is.mjs";
|
|
5
|
+
import { getNormalizedHex, hexToHsl, hexToHsla, hexToHwb, hexToHwba, hexToRgb, hexToRgba } from "./space/hex.mjs";
|
|
6
|
+
import { hslToHex, hslToHwb, hslToHwba, hslToRgb, hslToRgba } from "./space/hsl.mjs";
|
|
7
|
+
import { hwbToHex, hwbToHsl, hwbToHsla, hwbToRgb, hwbToRgba } from "./space/hwb.mjs";
|
|
8
|
+
import { rgbToHex, rgbToHsl, rgbToHsla, rgbToHwb, rgbToHwba } from "./space/rgb.mjs";
|
|
9
9
|
//#region src/color/index.d.ts
|
|
10
10
|
/**
|
|
11
11
|
* Get a _Color_ from any kind of value
|
|
12
12
|
*
|
|
13
|
-
* - Values that can be parsed are: hex(a) color strings, _HSL(A)_
|
|
13
|
+
* - Values that can be parsed are: hex(a) color strings, as well as _HSL(A)_, _HWB(A)_, and _RGB(A)_ color objects
|
|
14
14
|
* - If the value is unable to be parsed, a black _Color_ will be returned
|
|
15
15
|
*
|
|
16
16
|
* @param value Original value
|
|
@@ -18,4 +18,4 @@ import { rgbToHex, rgbToHsl, rgbToHsla } from "./space/rgb.mjs";
|
|
|
18
18
|
*/
|
|
19
19
|
declare function getColor(value: unknown): Color;
|
|
20
20
|
//#endregion
|
|
21
|
-
export { type Color, type HSLAColor, type HSLColor, type RGBAColor, type RGBColor, getColor, getForegroundColor, getHexColor, getHexaColor, getHslColor, getHslaColor, getNormalizedHex, getRgbColor, getRgbaColor, hexToHsl, hexToHsla, hexToRgb, hexToRgba, hslToHex, hslToRgb, hslToRgba, isColor, isHexColor, isHslColor, isHslLike, isHslaColor, isRgbColor, isRgbLike, isRgbaColor, rgbToHex, rgbToHsl, rgbToHsla };
|
|
21
|
+
export { type Color, type HSLAColor, type HSLColor, type HWBAColor, type HWBColor, type RGBAColor, type RGBColor, getColor, getForegroundColor, getHexColor, getHexaColor, getHslColor, getHslaColor, getHwbColor, getHwbaColor, getNormalizedHex, getRgbColor, getRgbaColor, hexToHsl, hexToHsla, hexToHwb, hexToHwba, hexToRgb, hexToRgba, hslToHex, hslToHwb, hslToHwba, hslToRgb, hslToRgba, hwbToHex, hwbToHsl, hwbToHsla, hwbToRgb, hwbToRgba, isColor, isHexColor, isHslColor, isHslLike, isHslaColor, isHwbColor, isHwbLike, isHwbaColor, isHwbaLike, isRgbColor, isRgbLike, isRgbaColor, rgbToHex, rgbToHsl, rgbToHsla, rgbToHwb, rgbToHwba };
|
package/dist/color/index.mjs
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { rgbToHex, rgbToHsl, rgbToHsla } from "./space/rgb.mjs";
|
|
4
|
-
import { getNormalizedHex, hexToHsl, hexToHsla, hexToRgb, hexToRgba } from "./space/hex.mjs";
|
|
5
|
-
import { hslToHex, hslToRgb, hslToRgba } from "./space/hsl.mjs";
|
|
1
|
+
import { getForegroundColor, getHexColor, getHexaColor, getHslColor, getHslaColor, getHwbColor, getHwbaColor, getRgbColor, getRgbaColor } from "./misc/get.mjs";
|
|
2
|
+
import { isColor, isHexColor, isHslColor, isHslLike, isHslaColor, isHwbColor, isHwbLike, isHwbaColor, isHwbaLike, isRgbColor, isRgbLike, isRgbaColor } from "./misc/is.mjs";
|
|
3
|
+
import { rgbToHex, rgbToHsl, rgbToHsla, rgbToHwb, rgbToHwba } from "./space/rgb.mjs";
|
|
4
|
+
import { getNormalizedHex, hexToHsl, hexToHsla, hexToHwb, hexToHwba, hexToRgb, hexToRgba } from "./space/hex.mjs";
|
|
5
|
+
import { hslToHex, hslToHwb, hslToHwba, hslToRgb, hslToRgba } from "./space/hsl.mjs";
|
|
6
|
+
import { hwbToHex, hwbToHsl, hwbToHsla, hwbToRgb, hwbToRgba } from "./space/hwb.mjs";
|
|
6
7
|
import { Color } from "./instance.mjs";
|
|
7
8
|
//#region src/color/index.ts
|
|
8
9
|
/**
|
|
9
10
|
* Get a _Color_ from any kind of value
|
|
10
11
|
*
|
|
11
|
-
* - Values that can be parsed are: hex(a) color strings, _HSL(A)_
|
|
12
|
+
* - Values that can be parsed are: hex(a) color strings, as well as _HSL(A)_, _HWB(A)_, and _RGB(A)_ color objects
|
|
12
13
|
* - If the value is unable to be parsed, a black _Color_ will be returned
|
|
13
14
|
*
|
|
14
15
|
* @param value Original value
|
|
@@ -18,4 +19,4 @@ function getColor(value) {
|
|
|
18
19
|
return isColor(value) ? value : new Color(value);
|
|
19
20
|
}
|
|
20
21
|
//#endregion
|
|
21
|
-
export { getColor, getForegroundColor, getHexColor, getHexaColor, getHslColor, getHslaColor, getNormalizedHex, getRgbColor, getRgbaColor, hexToHsl, hexToHsla, hexToRgb, hexToRgba, hslToHex, hslToRgb, hslToRgba, isColor, isHexColor, isHslColor, isHslLike, isHslaColor, isRgbColor, isRgbLike, isRgbaColor, rgbToHex, rgbToHsl, rgbToHsla };
|
|
22
|
+
export { getColor, getForegroundColor, getHexColor, getHexaColor, getHslColor, getHslaColor, getHwbColor, getHwbaColor, getNormalizedHex, getRgbColor, getRgbaColor, hexToHsl, hexToHsla, hexToHwb, hexToHwba, hexToRgb, hexToRgba, hslToHex, hslToHwb, hslToHwba, hslToRgb, hslToRgba, hwbToHex, hwbToHsl, hwbToHsla, hwbToRgb, hwbToRgba, isColor, isHexColor, isHslColor, isHslLike, isHslaColor, isHwbColor, isHwbLike, isHwbaColor, isHwbaLike, isRgbColor, isRgbLike, isRgbaColor, rgbToHex, rgbToHsl, rgbToHsla, rgbToHwb, rgbToHwba };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { HSLAColor, HSLColor, RGBAColor, RGBColor } from "./models.mjs";
|
|
2
|
-
|
|
1
|
+
import { HSLAColor, HSLColor, HWBAColor, HWBColor, RGBAColor, RGBColor } from "./models.mjs";
|
|
3
2
|
//#region src/color/instance.d.ts
|
|
4
3
|
/**
|
|
5
4
|
* A color that is represented in multiple color formats
|
|
@@ -13,16 +12,13 @@ declare class Color {
|
|
|
13
12
|
*/
|
|
14
13
|
private readonly $color;
|
|
15
14
|
/**
|
|
16
|
-
* Get the alpha channel _(opacity)_ of the color
|
|
15
|
+
* Get the alpha channel _(opacity)_ of the color as a percentage between `0` and `100`
|
|
17
16
|
*
|
|
18
|
-
* @returns Current alpha channel value
|
|
17
|
+
* @returns Current alpha channel value
|
|
19
18
|
*/
|
|
20
19
|
get alpha(): number;
|
|
21
20
|
/**
|
|
22
|
-
* Set the alpha channel _(opacity)_ of the color
|
|
23
|
-
*
|
|
24
|
-
* - A number between `0` and `1`, where `0` is fully transparent and `1` is fully opaque
|
|
25
|
-
* - A number between `0` and `100`, where `0` is fully transparent and `100` is fully opaque
|
|
21
|
+
* Set the alpha channel _(opacity)_ of the color as a percentage between `0` and `100`
|
|
26
22
|
*
|
|
27
23
|
* @param value New alpha channel value
|
|
28
24
|
*/
|
|
@@ -85,6 +81,30 @@ declare class Color {
|
|
|
85
81
|
* @param value New _HSLA_ color
|
|
86
82
|
*/
|
|
87
83
|
set hsla(value: HSLAColor);
|
|
84
|
+
/**
|
|
85
|
+
* Get the color as an _HWB_ color
|
|
86
|
+
*
|
|
87
|
+
* @returns Current color as an _HWB_ color
|
|
88
|
+
*/
|
|
89
|
+
get hwb(): HWBColor;
|
|
90
|
+
/**
|
|
91
|
+
* Set colors from an _HWB_ color
|
|
92
|
+
*
|
|
93
|
+
* @param value New _HWB_ color
|
|
94
|
+
*/
|
|
95
|
+
set hwb(value: HWBColor);
|
|
96
|
+
/**
|
|
97
|
+
* Get the color as an _HWBA_ color
|
|
98
|
+
*
|
|
99
|
+
* @returns Current color as an _HWBA_ color
|
|
100
|
+
*/
|
|
101
|
+
get hwba(): HWBAColor;
|
|
102
|
+
/**
|
|
103
|
+
* Set colors and alpha from an _HWBA_ color
|
|
104
|
+
*
|
|
105
|
+
* @param value New _HWBA_ color
|
|
106
|
+
*/
|
|
107
|
+
set hwba(value: HWBAColor);
|
|
88
108
|
/**
|
|
89
109
|
* Get the color as an _RGB_ color
|
|
90
110
|
*
|
|
@@ -124,6 +144,13 @@ declare class Color {
|
|
|
124
144
|
* @returns _HSL(A)_ color string
|
|
125
145
|
*/
|
|
126
146
|
toHslString(alpha?: boolean): string;
|
|
147
|
+
/**
|
|
148
|
+
* Get the color as an _HWB(A)_ string
|
|
149
|
+
*
|
|
150
|
+
* @param alpha Include alpha channel _(opacity)_? _(defaults to `false`)_
|
|
151
|
+
* @returns _HWB(A)_ color string
|
|
152
|
+
*/
|
|
153
|
+
toHwbString(alpha?: boolean): string;
|
|
127
154
|
/**
|
|
128
155
|
* Get the color as an _RGB(A)_ string
|
|
129
156
|
*
|
package/dist/color/instance.mjs
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import "./
|
|
2
|
-
import { formatColor } from "./misc/index.mjs";
|
|
1
|
+
import { formatHslColor, formatHwbColor, formatRgbColor } from "./misc/index.mjs";
|
|
3
2
|
import { getAlpha } from "./misc/alpha.mjs";
|
|
4
|
-
import { getColorState, setHSLColor, setHexColor, setRGBColor } from "./misc/state.mjs";
|
|
3
|
+
import { getColorState, setHSLColor, setHWBColor, setHexColor, setRGBColor } from "./misc/state.mjs";
|
|
5
4
|
//#region src/color/instance.ts
|
|
6
5
|
/**
|
|
7
6
|
* A color that is represented in multiple color formats
|
|
@@ -9,18 +8,15 @@ import { getColorState, setHSLColor, setHexColor, setRGBColor } from "./misc/sta
|
|
|
9
8
|
var Color = class {
|
|
10
9
|
#state;
|
|
11
10
|
/**
|
|
12
|
-
* Get the alpha channel _(opacity)_ of the color
|
|
11
|
+
* Get the alpha channel _(opacity)_ of the color as a percentage between `0` and `100`
|
|
13
12
|
*
|
|
14
|
-
* @returns Current alpha channel value
|
|
13
|
+
* @returns Current alpha channel value
|
|
15
14
|
*/
|
|
16
15
|
get alpha() {
|
|
17
16
|
return this.#state.alpha.value;
|
|
18
17
|
}
|
|
19
18
|
/**
|
|
20
|
-
* Set the alpha channel _(opacity)_ of the color
|
|
21
|
-
*
|
|
22
|
-
* - A number between `0` and `1`, where `0` is fully transparent and `1` is fully opaque
|
|
23
|
-
* - A number between `0` and `100`, where `0` is fully transparent and `100` is fully opaque
|
|
19
|
+
* Set the alpha channel _(opacity)_ of the color as a percentage between `0` and `100`
|
|
24
20
|
*
|
|
25
21
|
* @param value New alpha channel value
|
|
26
22
|
*/
|
|
@@ -75,7 +71,7 @@ var Color = class {
|
|
|
75
71
|
* @returns Current color as an _HSL_ color
|
|
76
72
|
*/
|
|
77
73
|
get hsl() {
|
|
78
|
-
return this.#state.hsl;
|
|
74
|
+
return { ...this.#state.hsl };
|
|
79
75
|
}
|
|
80
76
|
/**
|
|
81
77
|
* Set colors from an _HSL_ color
|
|
@@ -105,12 +101,47 @@ var Color = class {
|
|
|
105
101
|
setHSLColor(this.#state, value, true);
|
|
106
102
|
}
|
|
107
103
|
/**
|
|
104
|
+
* Get the color as an _HWB_ color
|
|
105
|
+
*
|
|
106
|
+
* @returns Current color as an _HWB_ color
|
|
107
|
+
*/
|
|
108
|
+
get hwb() {
|
|
109
|
+
return { ...this.#state.hwb };
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Set colors from an _HWB_ color
|
|
113
|
+
*
|
|
114
|
+
* @param value New _HWB_ color
|
|
115
|
+
*/
|
|
116
|
+
set hwb(value) {
|
|
117
|
+
setHWBColor(this.#state, value, false);
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Get the color as an _HWBA_ color
|
|
121
|
+
*
|
|
122
|
+
* @returns Current color as an _HWBA_ color
|
|
123
|
+
*/
|
|
124
|
+
get hwba() {
|
|
125
|
+
return {
|
|
126
|
+
...this.#state.hwb,
|
|
127
|
+
alpha: this.#state.alpha.value
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Set colors and alpha from an _HWBA_ color
|
|
132
|
+
*
|
|
133
|
+
* @param value New _HWBA_ color
|
|
134
|
+
*/
|
|
135
|
+
set hwba(value) {
|
|
136
|
+
setHWBColor(this.#state, value, true);
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
108
139
|
* Get the color as an _RGB_ color
|
|
109
140
|
*
|
|
110
141
|
* @returns Current color as an _RGB_ color
|
|
111
142
|
*/
|
|
112
143
|
get rgb() {
|
|
113
|
-
return this.#state.rgb;
|
|
144
|
+
return { ...this.#state.rgb };
|
|
114
145
|
}
|
|
115
146
|
/**
|
|
116
147
|
* Set colors from an _RGB_ color
|
|
@@ -159,7 +190,16 @@ var Color = class {
|
|
|
159
190
|
* @returns _HSL(A)_ color string
|
|
160
191
|
*/
|
|
161
192
|
toHslString(alpha) {
|
|
162
|
-
return
|
|
193
|
+
return formatHslColor(this, alpha === true);
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Get the color as an _HWB(A)_ string
|
|
197
|
+
*
|
|
198
|
+
* @param alpha Include alpha channel _(opacity)_? _(defaults to `false`)_
|
|
199
|
+
* @returns _HWB(A)_ color string
|
|
200
|
+
*/
|
|
201
|
+
toHwbString(alpha) {
|
|
202
|
+
return formatHwbColor(this, alpha === true);
|
|
163
203
|
}
|
|
164
204
|
/**
|
|
165
205
|
* Get the color as an _RGB(A)_ string
|
|
@@ -168,7 +208,7 @@ var Color = class {
|
|
|
168
208
|
* @returns _RGB(A)_ color string
|
|
169
209
|
*/
|
|
170
210
|
toRgbString(alpha) {
|
|
171
|
-
return
|
|
211
|
+
return formatRgbColor(this, alpha === true);
|
|
172
212
|
}
|
|
173
213
|
/**
|
|
174
214
|
* Get the color as a hex color string
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { round } from "../../internal/math/misc.mjs";
|
|
1
2
|
import { ALPHA_FULL_HEX_LONG, DEFAULT_ALPHA } from "../constants.mjs";
|
|
2
3
|
//#region src/color/misc/alpha.ts
|
|
3
4
|
function getAlpha(value) {
|
|
@@ -10,8 +11,8 @@ function getAlpha(value) {
|
|
|
10
11
|
}
|
|
11
12
|
function getAlphaHexadecimal(value) {
|
|
12
13
|
if (value === 0) return "00";
|
|
13
|
-
if (value ===
|
|
14
|
-
return
|
|
14
|
+
if (value === 100) return ALPHA_FULL_HEX_LONG;
|
|
15
|
+
return round(value * 255).toString(16);
|
|
15
16
|
}
|
|
16
17
|
function getAlphaFromValue(value) {
|
|
17
18
|
const alpha = getAlphaValue(value);
|
|
@@ -21,9 +22,8 @@ function getAlphaFromValue(value) {
|
|
|
21
22
|
};
|
|
22
23
|
}
|
|
23
24
|
function getAlphaValue(original) {
|
|
24
|
-
if (Number.isNaN(original) || original >= 100
|
|
25
|
-
|
|
26
|
-
return original <= 1 ? original : original / 100;
|
|
25
|
+
if (Number.isNaN(original) || original >= 100) return 100;
|
|
26
|
+
return original <= 0 ? 0 : original;
|
|
27
27
|
}
|
|
28
28
|
//#endregion
|
|
29
29
|
export { getAlpha, getAlphaHexadecimal, getAlphaValue };
|