@tempots/std 0.9.6 → 0.9.7
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/arrays.d.ts +49 -0
- package/arrays.js +249 -0
- package/async-result.d.ts +37 -0
- package/async-result.js +75 -0
- package/bigint.d.ts +18 -0
- package/bigint.js +110 -0
- package/booleans.d.ts +23 -0
- package/{src/booleans.ts → booleans.js} +33 -38
- package/colors/cmyk.d.ts +21 -0
- package/colors/cmyk.js +54 -0
- package/colors/convert.d.ts +283 -0
- package/colors/convert.js +742 -0
- package/colors/hsl.d.ts +24 -0
- package/colors/hsl.js +56 -0
- package/colors/hsla.d.ts +18 -0
- package/colors/hsla.js +35 -0
- package/colors/hsluv.d.ts +24 -0
- package/colors/hsluv.js +56 -0
- package/colors/hsv.d.ts +24 -0
- package/colors/hsv.js +54 -0
- package/colors/lab.d.ts +24 -0
- package/colors/lab.js +54 -0
- package/colors/lch.d.ts +19 -0
- package/colors/lch.js +44 -0
- package/colors/luv.d.ts +19 -0
- package/colors/luv.js +45 -0
- package/colors/rgb.d.ts +13 -0
- package/colors/rgb.js +47 -0
- package/colors/rgba.d.ts +12 -0
- package/colors/rgba.js +44 -0
- package/colors/srgb.d.ts +24 -0
- package/colors/srgb.js +51 -0
- package/colors/xyz.d.ts +19 -0
- package/colors/xyz.js +41 -0
- package/edit.d.ts +20 -0
- package/edit.js +29 -0
- package/equals.d.ts +3 -0
- package/equals.js +122 -0
- package/functions.d.ts +20 -0
- package/functions.js +38 -0
- package/json.d.ts +14 -0
- package/json.js +33 -0
- package/match.d.ts +16 -0
- package/match.js +45 -0
- package/maybe.d.ts +9 -0
- package/{src/maybe.ts → maybe.js} +11 -18
- package/memoize.d.ts +1 -0
- package/memoize.js +9 -0
- package/newtype.d.ts +28 -0
- package/newtype.js +29 -0
- package/numbers.d.ts +104 -0
- package/numbers.js +183 -0
- package/objects.d.ts +9 -0
- package/objects.js +33 -0
- package/ord.d.ts +19 -0
- package/ord.js +73 -0
- package/package.json +2 -2
- package/reg-exps.d.ts +10 -0
- package/{src/reg-exps.ts → reg-exps.js} +19 -24
- package/result.d.ts +31 -0
- package/result.js +95 -0
- package/strings.d.ts +314 -0
- package/strings.js +685 -0
- package/types/assert.d.ts +12 -0
- package/types/assert.js +13 -0
- package/types/differentiate.d.ts +13 -0
- package/types/differentiate.js +14 -0
- package/types/functions.d.ts +22 -0
- package/types/functions.js +13 -0
- package/types/generic.d.ts +9 -0
- package/types/generic.js +13 -0
- package/types/objects.d.ts +50 -0
- package/types/objects.js +13 -0
- package/types/tuples.d.ts +44 -0
- package/types/tuples.js +24 -0
- package/{src/types/utility.ts → types/utility.d.ts} +2 -3
- package/types/utility.js +1 -0
- package/uuid.d.ts +13 -0
- package/uuid.js +56 -0
- package/validation.d.ts +23 -0
- package/validation.js +44 -0
- package/src/arrays.ts +0 -296
- package/src/async-result.ts +0 -103
- package/src/bigint.ts +0 -111
- package/src/colors/cmyk.ts +0 -84
- package/src/colors/convert.ts +0 -1093
- package/src/colors/hsl.ts +0 -73
- package/src/colors/hsla.ts +0 -45
- package/src/colors/hsluv.ts +0 -73
- package/src/colors/hsv.ts +0 -75
- package/src/colors/lab.ts +0 -69
- package/src/colors/lch.ts +0 -53
- package/src/colors/luv.ts +0 -56
- package/src/colors/rgb.ts +0 -55
- package/src/colors/rgba.ts +0 -53
- package/src/colors/srgb.ts +0 -72
- package/src/colors/xyz.ts +0 -52
- package/src/edit.ts +0 -29
- package/src/equals.ts +0 -116
- package/src/functions.ts +0 -108
- package/src/json.ts +0 -52
- package/src/match.ts +0 -88
- package/src/memoize.ts +0 -9
- package/src/newtype.ts +0 -59
- package/src/numbers.ts +0 -222
- package/src/objects.ts +0 -47
- package/src/ord.ts +0 -79
- package/src/result.ts +0 -140
- package/src/strings.ts +0 -768
- package/src/types/assert.ts +0 -96
- package/src/types/differentiate.ts +0 -89
- package/src/types/functions.ts +0 -114
- package/src/types/generic.ts +0 -42
- package/src/types/objects.ts +0 -212
- package/src/types/tuples.ts +0 -244
- package/src/uuid.ts +0 -61
- package/src/validation.ts +0 -69
- package/test/arrays.spec.ts +0 -410
- package/test/colors.spec.ts +0 -406
- package/test/commmon.ts +0 -9
- package/test/equals.spec.ts +0 -165
- package/test/functions.spec.ts +0 -9
- package/test/index.d.ts +0 -20
- package/test/objects.spec.ts +0 -22
- package/test/reg-exps.spec.ts +0 -33
- package/test/strings.spec.ts +0 -333
- package/test/uuid.spec.ts +0 -35
- package/tsconfig.json +0 -19
package/src/colors/hsl.ts
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { clamp, nearEquals } from '../numbers'
|
|
2
|
-
|
|
3
|
-
const TOLLERANCE = 0.0001
|
|
4
|
-
|
|
5
|
-
export class HSL {
|
|
6
|
-
static fromString (s: string): HSL {
|
|
7
|
-
const m = s.match(
|
|
8
|
-
/^hsl\((\d+)(deg)?, ?(\d+(?:\.\d+)?)%?, ?(\d+(?:\.\d+)?)%?\)$/
|
|
9
|
-
)
|
|
10
|
-
if (m != null) {
|
|
11
|
-
const [, h, , s, l] = m
|
|
12
|
-
return new HSL(parseFloat(h), parseFloat(s), parseFloat(l))
|
|
13
|
-
} else {
|
|
14
|
-
throw new Error(`Invalid HSL string: ${s}`)
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
static ofChannels ([hue, saturation, lightness]: [
|
|
19
|
-
hue: number,
|
|
20
|
-
saturation: number,
|
|
21
|
-
lightness: number
|
|
22
|
-
]): HSL {
|
|
23
|
-
return new HSL(hue, saturation * 100, lightness * 100)
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
readonly hue: number
|
|
27
|
-
readonly saturation: number
|
|
28
|
-
readonly lightness: number
|
|
29
|
-
/**
|
|
30
|
-
*
|
|
31
|
-
* @param hue Angle in degrees (0-360)
|
|
32
|
-
* @param saturation Percentage (0-100)
|
|
33
|
-
* @param lightness Percentage (0-100)
|
|
34
|
-
*/
|
|
35
|
-
constructor (hue: number, saturation = 50, lightness = 50) {
|
|
36
|
-
this.hue = hue % 360.0
|
|
37
|
-
this.saturation = clamp(saturation, 0, 100)
|
|
38
|
-
this.lightness = clamp(lightness, 0, 100)
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
withHue (hue: number): HSL {
|
|
42
|
-
return new HSL(hue, this.saturation, this.lightness)
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
withSaturation (saturation: number): HSL {
|
|
46
|
-
return new HSL(this.hue, saturation, this.lightness)
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
withLightness (lightness: number): HSL {
|
|
50
|
-
return new HSL(this.hue, this.saturation, lightness)
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
toChannels (): [number, number, number] {
|
|
54
|
-
return [this.hue, this.saturation / 100, this.lightness / 100]
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
toString (): string {
|
|
58
|
-
return `hsl(${this.hue}deg, ${this.saturation}%, ${this.lightness}%)`
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
equals (other: HSL, tollerance = TOLLERANCE): boolean {
|
|
62
|
-
if (
|
|
63
|
-
(nearEquals(this.lightness, other.lightness, tollerance) &&
|
|
64
|
-
nearEquals(this.saturation, 0, tollerance)) ||
|
|
65
|
-
nearEquals(this.saturation, 100, tollerance)
|
|
66
|
-
) { return true }
|
|
67
|
-
return (
|
|
68
|
-
nearEquals(this.hue, other.hue, tollerance) &&
|
|
69
|
-
nearEquals(this.saturation, other.saturation, tollerance) &&
|
|
70
|
-
nearEquals(this.lightness, other.lightness, tollerance)
|
|
71
|
-
)
|
|
72
|
-
}
|
|
73
|
-
}
|
package/src/colors/hsla.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { clamp, nearEquals } from '../numbers'
|
|
2
|
-
import { HSL } from './hsl'
|
|
3
|
-
|
|
4
|
-
const TOLLERANCE = 0.0001
|
|
5
|
-
|
|
6
|
-
export class HSLA extends HSL {
|
|
7
|
-
readonly alpha: number
|
|
8
|
-
/**
|
|
9
|
-
*
|
|
10
|
-
* @param hue Angle in degrees (0-360)
|
|
11
|
-
* @param saturation Percentage (0-100)
|
|
12
|
-
* @param lightness Percentage (0-100)
|
|
13
|
-
* @param alpha Percentage (0-100)
|
|
14
|
-
*/
|
|
15
|
-
constructor (hue: number, saturation = 50, lightness = 50, alpha = 100) {
|
|
16
|
-
super(hue, saturation, lightness)
|
|
17
|
-
this.alpha = clamp(0, 1, alpha)
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
override withHue (hue: number): HSLA {
|
|
21
|
-
return new HSLA(hue, this.saturation, this.lightness, this.alpha)
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
override withSaturation (saturation: number): HSLA {
|
|
25
|
-
return new HSLA(this.hue, saturation, this.lightness, this.alpha)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
override withLightness (lightness: number): HSLA {
|
|
29
|
-
return new HSLA(this.hue, this.saturation, lightness, this.alpha)
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
withAlpha (alpha: number): HSLA {
|
|
33
|
-
return new HSLA(this.hue, this.saturation, this.lightness, alpha)
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
override toString (): string {
|
|
37
|
-
return `hsla(${this.hue}deg, ${this.saturation}%, ${this.lightness}%, ${
|
|
38
|
-
this.alpha / 100
|
|
39
|
-
})`
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
override equals (other: HSLA, tollerance = TOLLERANCE): boolean {
|
|
43
|
-
return super.equals(other, tollerance) && nearEquals(this.alpha, other.alpha, tollerance)
|
|
44
|
-
}
|
|
45
|
-
}
|
package/src/colors/hsluv.ts
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { nearEquals } from '../numbers'
|
|
2
|
-
|
|
3
|
-
const TOLLERANCE = 0.0001
|
|
4
|
-
|
|
5
|
-
export class HSLuv {
|
|
6
|
-
static fromString (s: string): HSLuv {
|
|
7
|
-
const m = s.match(
|
|
8
|
-
/^hsluv\((\d+)(deg)?, ?(\d+(?:\.\d+)?)%?, ?(\d+(?:\.\d+)?)%?\)$/
|
|
9
|
-
)
|
|
10
|
-
if (m != null) {
|
|
11
|
-
const [, h, , s, l] = m
|
|
12
|
-
return new HSLuv(parseFloat(h), parseFloat(s), parseFloat(l))
|
|
13
|
-
} else {
|
|
14
|
-
throw new Error(`Invalid HSLuv string: ${s}`)
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
static ofChannels ([hue, saturation, lightness]: [
|
|
19
|
-
hue: number,
|
|
20
|
-
saturation: number,
|
|
21
|
-
lightness: number
|
|
22
|
-
]): HSLuv {
|
|
23
|
-
return new HSLuv(hue, saturation, lightness)
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
readonly hue: number
|
|
27
|
-
readonly saturation: number
|
|
28
|
-
readonly lightness: number
|
|
29
|
-
/**
|
|
30
|
-
*
|
|
31
|
-
* @param hue Angle in degrees (0-360)
|
|
32
|
-
* @param saturation
|
|
33
|
-
* @param lightness
|
|
34
|
-
*/
|
|
35
|
-
constructor (hue: number, saturation: number, lightness: number) {
|
|
36
|
-
this.hue = hue % 360.0
|
|
37
|
-
this.saturation = saturation
|
|
38
|
-
this.lightness = lightness
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
withHue (hue: number): HSLuv {
|
|
42
|
-
return new HSLuv(hue, this.saturation, this.lightness)
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
withSaturation (saturation: number): HSLuv {
|
|
46
|
-
return new HSLuv(this.hue, saturation, this.lightness)
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
withLightness (lightness: number): HSLuv {
|
|
50
|
-
return new HSLuv(this.hue, this.saturation, lightness)
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
toChannels (): [number, number, number] {
|
|
54
|
-
return [this.hue, this.saturation, this.lightness]
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
toString (): string {
|
|
58
|
-
return `hsluv(${this.hue}deg, ${this.saturation}%, ${this.lightness}%)`
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
equals (other: HSLuv, tollerance = TOLLERANCE): boolean {
|
|
62
|
-
if (
|
|
63
|
-
(nearEquals(this.lightness, other.lightness, tollerance) &&
|
|
64
|
-
nearEquals(this.saturation, 0, tollerance)) ||
|
|
65
|
-
nearEquals(this.saturation, 100, tollerance)
|
|
66
|
-
) { return true }
|
|
67
|
-
return (
|
|
68
|
-
nearEquals(this.hue, other.hue, tollerance) &&
|
|
69
|
-
nearEquals(this.saturation, other.saturation, tollerance) &&
|
|
70
|
-
nearEquals(this.lightness, other.lightness, tollerance)
|
|
71
|
-
)
|
|
72
|
-
}
|
|
73
|
-
}
|
package/src/colors/hsv.ts
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { clamp, nearEquals } from '../numbers'
|
|
2
|
-
|
|
3
|
-
const TOLLERANCE = 0.0001
|
|
4
|
-
|
|
5
|
-
export class HSV {
|
|
6
|
-
static fromString (s: string): HSV {
|
|
7
|
-
const m = s.match(
|
|
8
|
-
/^hsv\((\d+(?:\.\d+)?)%, ?(\d+(?:\.\d+)?)%, ?(\d+(?:\.\d+)?)%\)$/i
|
|
9
|
-
)
|
|
10
|
-
if (m != null) {
|
|
11
|
-
const [, h, s, v] = m
|
|
12
|
-
return new HSV(parseFloat(h), parseFloat(s), parseFloat(v))
|
|
13
|
-
} else {
|
|
14
|
-
throw new Error(`Invalid HSV string: ${s}`)
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
static ofChannels ([hue, saturation, value]: [
|
|
19
|
-
hue: number,
|
|
20
|
-
saturation: number,
|
|
21
|
-
value: number
|
|
22
|
-
]): HSV {
|
|
23
|
-
return new HSV(
|
|
24
|
-
hue % 360.0,
|
|
25
|
-
clamp(saturation * 100, 0, 100),
|
|
26
|
-
clamp(value * 100, 0, 100)
|
|
27
|
-
)
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
readonly hue: number
|
|
31
|
-
readonly saturation: number
|
|
32
|
-
readonly value: number
|
|
33
|
-
/**
|
|
34
|
-
*
|
|
35
|
-
* @param hue Angle in degrees (0-360)
|
|
36
|
-
* @param saturation Percentage (0-100)
|
|
37
|
-
* @param value Percentage (0-100)
|
|
38
|
-
*/
|
|
39
|
-
constructor (hue: number, saturation: number, value: number) {
|
|
40
|
-
this.hue = hue
|
|
41
|
-
this.saturation = saturation
|
|
42
|
-
this.value = value
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
withHue (h: number): HSV {
|
|
46
|
-
return new HSV(h, this.saturation, this.value)
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
withSaturation (s: number): HSV {
|
|
50
|
-
return new HSV(this.hue, s, this.value)
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
withValue (v: number): HSV {
|
|
54
|
-
return new HSV(this.hue, this.saturation, v)
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
toChannels (): [number, number, number] {
|
|
58
|
-
return [this.hue, this.saturation / 100, this.value / 100]
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
toString (): string {
|
|
62
|
-
return `hsv(${this.hue}, ${this.saturation}, ${this.value})`
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
equals (other: HSV, tollerance = TOLLERANCE): boolean {
|
|
66
|
-
if (
|
|
67
|
-
nearEquals(this.value, other.value, tollerance) && (nearEquals(this.saturation, 0, tollerance) || nearEquals(this.saturation, 100, tollerance))
|
|
68
|
-
) { return true }
|
|
69
|
-
return (
|
|
70
|
-
nearEquals(this.hue, other.hue, tollerance) &&
|
|
71
|
-
nearEquals(this.saturation, other.saturation, tollerance) &&
|
|
72
|
-
nearEquals(this.value, other.value, tollerance)
|
|
73
|
-
)
|
|
74
|
-
}
|
|
75
|
-
}
|
package/src/colors/lab.ts
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { clamp, nearEquals } from '../numbers'
|
|
2
|
-
|
|
3
|
-
const TOLLERANCE = 0.0001
|
|
4
|
-
|
|
5
|
-
export class LAB {
|
|
6
|
-
static fromString (s: string): LAB {
|
|
7
|
-
const m = s.match(
|
|
8
|
-
/^lab\((\d+(?:\.\d+)?)°, ?(\d+(?:\.\d+)?)°, ?(\d+(?:\.\d+)?)°\)$/
|
|
9
|
-
)
|
|
10
|
-
if (m != null) {
|
|
11
|
-
const [, lightness, a, b] = m
|
|
12
|
-
return new LAB(parseFloat(lightness), parseFloat(a), parseFloat(b))
|
|
13
|
-
} else {
|
|
14
|
-
throw new Error(`Invalid LAB string: ${s}`)
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
static ofChannels ([lightness, a, b]: [
|
|
19
|
-
lightness: number,
|
|
20
|
-
a: number,
|
|
21
|
-
b: number
|
|
22
|
-
]): LAB {
|
|
23
|
-
return new LAB(lightness, a, b)
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
readonly lightness: number
|
|
27
|
-
readonly a: number
|
|
28
|
-
readonly b: number
|
|
29
|
-
/**
|
|
30
|
-
*
|
|
31
|
-
* @param lightness Lightness in range (0, 100)
|
|
32
|
-
* @param a usually in the range (~-150, ~+150) - not clamped
|
|
33
|
-
* @param b usually in the range (~-150, ~+150) - not clamped
|
|
34
|
-
*/
|
|
35
|
-
constructor (lightness: number, a: number, b: number) {
|
|
36
|
-
this.lightness = clamp(lightness, 0, 100)
|
|
37
|
-
this.a = a
|
|
38
|
-
this.b = b
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
withL (l: number): LAB {
|
|
42
|
-
return new LAB(l, this.a, this.b)
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
withA (a: number): LAB {
|
|
46
|
-
return new LAB(this.lightness, a, this.b)
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
withB (b: number): LAB {
|
|
50
|
-
return new LAB(this.lightness, this.a, b)
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
toChannels (): [number, number, number] {
|
|
54
|
-
return [this.lightness, this.a, this.b]
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
toString (): string {
|
|
58
|
-
return `lab(${this.lightness}, ${this.a}, ${this.b})`
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
equals (other: LAB, tollerance = TOLLERANCE): boolean {
|
|
62
|
-
if (nearEquals(this.lightness, other.lightness, tollerance) && ((nearEquals(this.lightness, 100, tollerance)) || nearEquals(this.lightness, 0, tollerance))) { return true }
|
|
63
|
-
return (
|
|
64
|
-
nearEquals(this.lightness, other.lightness, tollerance) &&
|
|
65
|
-
nearEquals(this.a, other.a, tollerance) &&
|
|
66
|
-
nearEquals(this.b, other.b, tollerance)
|
|
67
|
-
)
|
|
68
|
-
}
|
|
69
|
-
}
|
package/src/colors/lch.ts
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { nearEquals } from '../numbers'
|
|
2
|
-
|
|
3
|
-
const TOLLERANCE = 0.0001
|
|
4
|
-
|
|
5
|
-
export class LCH {
|
|
6
|
-
static ofChannels ([l, c, h]: [l: number, c: number, h: number]): LCH {
|
|
7
|
-
return new LCH(l, c, h)
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
readonly luminance: number
|
|
11
|
-
readonly chroma: number
|
|
12
|
-
readonly hue: number
|
|
13
|
-
/**
|
|
14
|
-
*
|
|
15
|
-
* @param luminance Luminance in cd/m^2
|
|
16
|
-
* @param chroma
|
|
17
|
-
* @param hue Angle in degrees (0-360)
|
|
18
|
-
*/
|
|
19
|
-
constructor (luminance: number, chroma: number, hue: number) {
|
|
20
|
-
this.luminance = luminance < 0 ? 0 : luminance
|
|
21
|
-
this.chroma = chroma
|
|
22
|
-
this.hue = hue % 360
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
withLightness (l: number): LCH {
|
|
26
|
-
return new LCH(l, this.chroma, this.hue)
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
withChroma (c: number): LCH {
|
|
30
|
-
return new LCH(this.luminance, c, this.hue)
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
withHue (h: number): LCH {
|
|
34
|
-
return new LCH(this.luminance, this.chroma, h)
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
toChannels (): [number, number, number] {
|
|
38
|
-
return [this.luminance, this.chroma, this.hue]
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
toString (): string {
|
|
42
|
-
return `lch(${this.luminance}, ${this.chroma}, ${this.hue})`
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
equals (other: LCH, tollerance = TOLLERANCE): boolean {
|
|
46
|
-
if (nearEquals(this.luminance, other.luminance, tollerance) && ((nearEquals(this.luminance, 100, tollerance)) || nearEquals(this.luminance, 0, tollerance))) { return true }
|
|
47
|
-
return (
|
|
48
|
-
nearEquals(this.luminance, other.luminance, tollerance) &&
|
|
49
|
-
nearEquals(this.chroma, other.chroma, tollerance) &&
|
|
50
|
-
nearEquals(this.hue, other.hue, tollerance)
|
|
51
|
-
)
|
|
52
|
-
}
|
|
53
|
-
}
|
package/src/colors/luv.ts
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { nearEquals } from '../numbers'
|
|
2
|
-
|
|
3
|
-
const TOLLERANCE = 0.0001
|
|
4
|
-
|
|
5
|
-
export class LUV {
|
|
6
|
-
static ofChannels ([l, u, v]: [l: number, u: number, v: number]): LUV {
|
|
7
|
-
return new LUV(l, u, v)
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
readonly l: number
|
|
11
|
-
readonly u: number
|
|
12
|
-
readonly v: number
|
|
13
|
-
/**
|
|
14
|
-
*
|
|
15
|
-
* @param l
|
|
16
|
-
* @param u range (0, 1)
|
|
17
|
-
* @param v range (0, 1)
|
|
18
|
-
*/
|
|
19
|
-
constructor (l: number, u: number, v: number) {
|
|
20
|
-
this.l = l
|
|
21
|
-
this.u = u
|
|
22
|
-
this.v = v
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
withL (l: number): LUV {
|
|
26
|
-
return new LUV(l, this.u, this.v)
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
withU (u: number): LUV {
|
|
30
|
-
return new LUV(this.l, u, this.v)
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
withV (v: number): LUV {
|
|
34
|
-
return new LUV(this.l, this.u, v)
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
toChannels (): [number, number, number] {
|
|
38
|
-
return [this.l, this.u, this.v]
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
toString (): string {
|
|
42
|
-
return `luv(${this.l}, ${this.u}, ${this.v})`
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
equals (other: LUV, tollerance = TOLLERANCE): boolean {
|
|
46
|
-
if (
|
|
47
|
-
(nearEquals(this.l, other.l, tollerance) && nearEquals(this.l, 1, tollerance)) ||
|
|
48
|
-
nearEquals(this.l, 0, tollerance)
|
|
49
|
-
) { return true }
|
|
50
|
-
return (
|
|
51
|
-
nearEquals(this.l, other.l, tollerance) &&
|
|
52
|
-
nearEquals(this.u, other.u, tollerance) &&
|
|
53
|
-
nearEquals(this.v, other.v, tollerance)
|
|
54
|
-
)
|
|
55
|
-
}
|
|
56
|
-
}
|
package/src/colors/rgb.ts
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { clampInt } from '../numbers'
|
|
2
|
-
|
|
3
|
-
export class RGB {
|
|
4
|
-
static fromString (s: string): RGB {
|
|
5
|
-
const m = s.match(/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i)
|
|
6
|
-
if (m != null) {
|
|
7
|
-
const r = parseInt(m[1], 16)
|
|
8
|
-
const g = parseInt(m[2], 16)
|
|
9
|
-
const b = parseInt(m[3], 16)
|
|
10
|
-
return RGB.fromRGB(r, g, b)
|
|
11
|
-
} else {
|
|
12
|
-
throw new Error(`Invalid RGB string: ${s}`)
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
static fromRGB (r: number, g: number, b: number): RGB {
|
|
17
|
-
return new RGB(
|
|
18
|
-
(clampInt(Math.round(r), 0, 255) << 16) |
|
|
19
|
-
(clampInt(Math.round(g), 0, 255) << 8) |
|
|
20
|
-
clampInt(Math.round(b), 0, 255)
|
|
21
|
-
)
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
static ofChannels ([r, g, b]: [r: number, g: number, b: number]): RGB {
|
|
25
|
-
return RGB.fromRGB(r * 255, g * 255, b * 255)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
constructor (readonly value: number) {}
|
|
29
|
-
|
|
30
|
-
get red (): number {
|
|
31
|
-
return (this.value >> 16) & 0xff
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
get green (): number {
|
|
35
|
-
return (this.value >> 8) & 0xff
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
get blue (): number {
|
|
39
|
-
return this.value & 0xff
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
toChannels (): [number, number, number] {
|
|
43
|
-
return [this.red / 255, this.green / 255, this.blue / 255]
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
toString (): string {
|
|
47
|
-
return `#${this.red.toString(16).padStart(2, '0')}${this.green
|
|
48
|
-
.toString(16)
|
|
49
|
-
.padStart(2, '0')}${this.blue.toString(16).padStart(2, '0')}`
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
equals (other: RGB): boolean {
|
|
53
|
-
return this.value === other.value
|
|
54
|
-
}
|
|
55
|
-
}
|
package/src/colors/rgba.ts
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { clampInt } from '../numbers'
|
|
2
|
-
|
|
3
|
-
export class RGBA {
|
|
4
|
-
static fromString (s: string): RGBA {
|
|
5
|
-
const m = s.match(
|
|
6
|
-
/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i
|
|
7
|
-
)
|
|
8
|
-
if (m != null) {
|
|
9
|
-
const r = parseInt(m[1], 16)
|
|
10
|
-
const g = parseInt(m[2], 16)
|
|
11
|
-
const b = parseInt(m[3], 16)
|
|
12
|
-
const a = parseInt(m[4], 16)
|
|
13
|
-
return RGBA.fromRGBA(r, g, b, a)
|
|
14
|
-
} else {
|
|
15
|
-
throw new Error(`Invalid RGBA string: ${s}`)
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
static fromRGBA (r: number, g: number, b: number, a: number): RGBA {
|
|
20
|
-
return new RGBA(
|
|
21
|
-
(clampInt(r, 0, 255) << 24) |
|
|
22
|
-
(clampInt(g, 0, 255) << 16) |
|
|
23
|
-
(clampInt(b, 0, 255) << 8) |
|
|
24
|
-
clampInt(a, 0, 255)
|
|
25
|
-
)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
constructor (readonly value: number) {}
|
|
29
|
-
|
|
30
|
-
get red (): number {
|
|
31
|
-
return (this.value >> 24) & 0xff
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
get green (): number {
|
|
35
|
-
return (this.value >> 16) & 0xff
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
get blue (): number {
|
|
39
|
-
return (this.value >> 8) & 0xff
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
get alpha (): number {
|
|
43
|
-
return this.value & 0xff
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
toString (): string {
|
|
47
|
-
return `rgba(${this.red}, ${this.green}, ${this.blue}, ${this.alpha / 256})`
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
equals (other: RGBA): boolean {
|
|
51
|
-
return this.value === other.value
|
|
52
|
-
}
|
|
53
|
-
}
|
package/src/colors/srgb.ts
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { clamp, nearEquals } from '../numbers'
|
|
2
|
-
|
|
3
|
-
const TOLLERANCE = 0.001
|
|
4
|
-
|
|
5
|
-
export class SRGB {
|
|
6
|
-
static fromString (s: string): SRGB {
|
|
7
|
-
const m = s.match(
|
|
8
|
-
/^rgb\((\d+(?:\.\d+)?)%, ?(\d+(?:\.\d+)?)%, ?(\d+(?:\.\d+)?)%\)$/
|
|
9
|
-
)
|
|
10
|
-
if (m != null) {
|
|
11
|
-
const [, red, blue, green] = m
|
|
12
|
-
return new SRGB(parseFloat(red), parseFloat(blue), parseFloat(green))
|
|
13
|
-
} else {
|
|
14
|
-
throw new Error(`Invalid RGB string: ${s}`)
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
static ofChannels ([red, blue, green]: [
|
|
19
|
-
red: number,
|
|
20
|
-
blue: number,
|
|
21
|
-
green: number
|
|
22
|
-
]): SRGB {
|
|
23
|
-
return new SRGB(
|
|
24
|
-
clamp(red * 100, 0, 100),
|
|
25
|
-
clamp(blue * 100, 0, 100),
|
|
26
|
-
clamp(green * 100, 0, 100)
|
|
27
|
-
)
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
readonly red: number
|
|
31
|
-
readonly blue: number
|
|
32
|
-
readonly green: number
|
|
33
|
-
/**
|
|
34
|
-
*
|
|
35
|
-
* @param red Percentage (0-100)
|
|
36
|
-
* @param blue Percentage (0-100)
|
|
37
|
-
* @param green Percentage (0-100)
|
|
38
|
-
*/
|
|
39
|
-
constructor (red: number, blue: number, green: number) {
|
|
40
|
-
this.red = clamp(red, 0, 100)
|
|
41
|
-
this.blue = clamp(blue, 0, 100)
|
|
42
|
-
this.green = clamp(green, 0, 100)
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
withRed (red: number): SRGB {
|
|
46
|
-
return new SRGB(red, this.blue, this.green)
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
withBlue (blue: number): SRGB {
|
|
50
|
-
return new SRGB(this.red, blue, this.green)
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
withGreen (green: number): SRGB {
|
|
54
|
-
return new SRGB(this.red, this.blue, green)
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
toString (): string {
|
|
58
|
-
return `rgb(${this.red}%, ${this.blue}%, ${this.green}%)`
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
toChannels (): [number, number, number] {
|
|
62
|
-
return [this.red / 100, this.blue / 100, this.green / 100]
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
equals (other: SRGB, tollerance = TOLLERANCE): boolean {
|
|
66
|
-
return (
|
|
67
|
-
nearEquals(this.red, other.red, tollerance) &&
|
|
68
|
-
nearEquals(this.blue, other.blue, tollerance) &&
|
|
69
|
-
nearEquals(this.green, other.green, tollerance)
|
|
70
|
-
)
|
|
71
|
-
}
|
|
72
|
-
}
|
package/src/colors/xyz.ts
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { nearEquals } from '../numbers'
|
|
2
|
-
|
|
3
|
-
const TOLLERANCE = 0.0001
|
|
4
|
-
|
|
5
|
-
export class XYZ {
|
|
6
|
-
static ofChannels ([x, y, z]: [x: number, y: number, z: number]): XYZ {
|
|
7
|
-
return new XYZ(x, y, z)
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
readonly x: number
|
|
11
|
-
readonly y: number
|
|
12
|
-
readonly z: number
|
|
13
|
-
/**
|
|
14
|
-
*
|
|
15
|
-
* @param x
|
|
16
|
-
* @param y 100 is the brightest white
|
|
17
|
-
* @param z
|
|
18
|
-
*/
|
|
19
|
-
constructor (x: number, y: number, z: number) {
|
|
20
|
-
this.x = x
|
|
21
|
-
this.y = y
|
|
22
|
-
this.z = z
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
withX (x: number): XYZ {
|
|
26
|
-
return new XYZ(x, this.y, this.z)
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
withY (y: number): XYZ {
|
|
30
|
-
return new XYZ(this.x, y, this.z)
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
withZ (z: number): XYZ {
|
|
34
|
-
return new XYZ(this.x, this.y, z)
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
toString (): string {
|
|
38
|
-
return `XYZ(${this.x}, ${this.y}, ${this.z})`
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
toChannels (): [number, number, number] {
|
|
42
|
-
return [this.x, this.y, this.z]
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
equals (other: XYZ, tollerance = TOLLERANCE): boolean {
|
|
46
|
-
return (
|
|
47
|
-
nearEquals(this.x, other.x, tollerance) &&
|
|
48
|
-
nearEquals(this.y, other.y, tollerance) &&
|
|
49
|
-
nearEquals(this.z, other.z, tollerance)
|
|
50
|
-
)
|
|
51
|
-
}
|
|
52
|
-
}
|