@oscarpalmer/atoms 0.74.1 → 0.76.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/js/array/chunk.cjs +18 -0
- package/dist/js/array/{chunk.mjs → chunk.js} +2 -2
- package/dist/js/array/compact.cjs +6 -0
- package/dist/js/array/{compact.mjs → compact.js} +0 -1
- package/dist/js/array/count.cjs +14 -0
- package/dist/js/array/count.js +14 -0
- package/dist/js/array/exists.cjs +14 -0
- package/dist/js/array/exists.js +14 -0
- package/dist/js/array/filter.cjs +14 -0
- package/dist/js/array/filter.js +14 -0
- package/dist/js/array/find.cjs +14 -0
- package/dist/js/array/find.js +14 -0
- package/dist/js/array/group-by.cjs +35 -0
- package/dist/js/array/group-by.js +35 -0
- package/dist/js/array/index-of.cjs +14 -0
- package/dist/js/array/index-of.js +14 -0
- package/dist/js/array/index.cjs +40 -0
- package/dist/js/array/index.js +34 -381
- package/dist/js/array/insert.cjs +31 -0
- package/dist/js/array/insert.js +31 -0
- package/dist/js/array/models.cjs +1 -0
- package/dist/js/array/models.js +1 -0
- package/dist/js/array/shuffle.cjs +13 -0
- package/dist/js/array/{shuffle.mjs → shuffle.js} +2 -3
- package/dist/js/array/sort.cjs +53 -0
- package/dist/js/array/{sort.mjs → sort.js} +13 -9
- package/dist/js/array/splice.cjs +14 -0
- package/dist/js/array/splice.js +14 -0
- package/dist/js/array/to-map.cjs +27 -0
- package/dist/js/array/to-map.js +27 -0
- package/dist/js/array/to-record.cjs +12 -0
- package/dist/js/array/to-record.js +12 -0
- package/dist/js/array/unique.cjs +7 -0
- package/dist/js/array/unique.js +7 -0
- package/dist/js/colour/base.cjs +18 -0
- package/dist/js/colour/{base.mjs → base.js} +4 -3
- package/dist/js/colour/functions.cjs +96 -0
- package/dist/js/colour/{functions.mjs → functions.js} +18 -19
- package/dist/js/colour/hex.cjs +56 -0
- package/dist/js/colour/{hex.mjs → hex.js} +34 -15
- package/dist/js/colour/hsl.cjs +85 -0
- package/dist/js/colour/{hsl.mjs → hsl.js} +40 -12
- package/dist/js/colour/index.cjs +29 -0
- package/dist/js/colour/index.js +14 -272
- package/dist/js/colour/is.cjs +27 -0
- package/dist/js/colour/{is.mjs → is.js} +7 -6
- package/dist/js/colour/rgb.cjs +87 -0
- package/dist/js/colour/{rgb.mjs → rgb.js} +43 -12
- package/dist/js/{emitter.mjs → emitter.cjs} +88 -56
- package/dist/js/emitter.js +85 -56
- package/dist/js/{function.mjs → function.cjs} +66 -46
- package/dist/js/function.js +61 -48
- package/dist/js/index.cjs +136 -0
- package/dist/js/index.js +133 -1724
- package/dist/js/internal/array/callbacks.cjs +23 -0
- package/dist/js/internal/array/callbacks.js +23 -0
- package/dist/js/internal/array/find.cjs +51 -0
- package/dist/js/internal/array/find.js +51 -0
- package/dist/js/internal/value/handle.cjs +21 -0
- package/dist/js/internal/{value-handle.mjs → value/handle.js} +0 -1
- package/dist/js/{is.mjs → is.cjs} +17 -18
- package/dist/js/is.js +15 -27
- package/dist/js/logger.cjs +108 -0
- package/dist/js/logger.js +44 -8
- package/dist/js/{math.mjs → math.cjs} +7 -8
- package/dist/js/math.js +4 -5
- package/dist/js/models.cjs +1 -0
- package/dist/js/models.js +1 -0
- package/dist/js/{number.mjs → number.cjs} +8 -8
- package/dist/js/number.js +5 -5
- package/dist/js/{query.mjs → query.cjs} +18 -18
- package/dist/js/query.js +17 -86
- package/dist/js/{queue.mjs → queue.cjs} +12 -13
- package/dist/js/queue.js +9 -10
- package/dist/js/{random.mjs → random.cjs} +14 -21
- package/dist/js/random.js +9 -26
- package/dist/js/{sized.mjs → sized.cjs} +68 -33
- package/dist/js/sized.js +66 -38
- package/dist/js/string/case.cjs +41 -0
- package/dist/js/string/{case.mjs → case.js} +13 -9
- package/dist/js/string/index.cjs +59 -0
- package/dist/js/string/index.js +30 -100
- package/dist/js/string/template.cjs +21 -0
- package/dist/js/string/{template.mjs → template.js} +4 -5
- package/dist/js/{touch.mjs → touch.cjs} +4 -7
- package/dist/js/touch.js +3 -5
- package/dist/js/value/clone.cjs +76 -0
- package/dist/js/value/{clone.mjs → clone.js} +5 -6
- package/dist/js/value/compare.cjs +59 -0
- package/dist/js/value/{compare.mjs → compare.js} +4 -6
- package/dist/js/value/diff.cjs +75 -0
- package/dist/js/value/{diff.mjs → diff.js} +13 -11
- package/dist/js/value/equal.cjs +106 -0
- package/dist/js/value/{equal.mjs → equal.js} +13 -8
- package/dist/js/value/get.cjs +21 -0
- package/dist/js/value/{get.mjs → get.js} +9 -4
- package/dist/js/value/index.cjs +30 -0
- package/dist/js/value/index.js +19 -510
- package/dist/js/value/merge.cjs +35 -0
- package/dist/js/value/{merge.mjs → merge.js} +7 -6
- package/dist/js/value/set.cjs +25 -0
- package/dist/js/value/{set.mjs → set.js} +3 -4
- package/dist/js/value/smush.cjs +26 -0
- package/dist/js/value/{smush.mjs → smush.js} +3 -4
- package/dist/js/value/unsmush.cjs +39 -0
- package/dist/js/value/{unsmush.mjs → unsmush.js} +10 -7
- package/package.json +50 -47
- package/src/js/array/chunk.ts +6 -5
- package/src/js/array/compact.ts +8 -10
- package/src/js/array/count.ts +39 -19
- package/src/js/array/exists.ts +39 -15
- package/src/js/array/filter.ts +42 -20
- package/src/js/array/find.ts +45 -20
- package/src/js/array/group-by.ts +158 -27
- package/src/js/array/index-of.ts +40 -18
- package/src/js/array/index.ts +10 -9
- package/src/js/array/insert.ts +28 -14
- package/src/js/array/models.ts +18 -15
- package/src/js/array/shuffle.ts +3 -3
- package/src/js/array/sort.ts +32 -34
- package/src/js/array/splice.ts +22 -26
- package/src/js/array/to-map.ts +133 -45
- package/src/js/array/to-record.ts +137 -39
- package/src/js/array/unique.ts +20 -15
- package/src/js/colour/base.ts +3 -3
- package/src/js/colour/functions.ts +4 -6
- package/src/js/colour/hex.ts +5 -5
- package/src/js/colour/hsl.ts +18 -12
- package/src/js/colour/index.ts +1 -1
- package/src/js/colour/is.ts +3 -3
- package/src/js/colour/rgb.ts +17 -11
- package/src/js/emitter.ts +12 -9
- package/src/js/function.ts +17 -17
- package/src/js/index.ts +16 -16
- package/src/js/internal/array/callbacks.ts +33 -0
- package/src/js/internal/{array-find.ts → array/find.ts} +23 -24
- package/src/js/internal/{value-handle.ts → value/handle.ts} +1 -1
- package/src/js/is.ts +2 -2
- package/src/js/logger.ts +14 -14
- package/src/js/math.ts +1 -1
- package/src/js/models.ts +5 -5
- package/src/js/number.ts +2 -2
- package/src/js/query.ts +6 -10
- package/src/js/queue.ts +1 -1
- package/src/js/random.ts +9 -19
- package/src/js/sized.ts +145 -145
- package/src/js/string/case.ts +1 -1
- package/src/js/string/index.ts +13 -7
- package/src/js/string/template.ts +6 -3
- package/src/js/value/clone.ts +3 -7
- package/src/js/value/compare.ts +3 -5
- package/src/js/value/diff.ts +4 -4
- package/src/js/value/equal.ts +2 -2
- package/src/js/value/get.ts +3 -3
- package/src/js/value/index.ts +2 -2
- package/src/js/value/merge.ts +3 -3
- package/src/js/value/set.ts +3 -4
- package/src/js/value/smush.ts +4 -4
- package/src/js/value/unsmush.ts +4 -4
- package/types/array/chunk.d.cts +8 -0
- package/types/array/chunk.d.ts +2 -2
- package/types/array/compact.d.cts +12 -0
- package/types/array/compact.d.ts +4 -4
- package/types/array/count.d.cts +24 -0
- package/types/array/count.d.ts +13 -7
- package/types/array/exists.d.cts +26 -0
- package/types/array/exists.d.ts +11 -3
- package/types/array/filter.d.cts +26 -0
- package/types/array/filter.d.ts +14 -6
- package/types/array/find.d.cts +26 -0
- package/types/array/find.d.ts +14 -6
- package/types/array/group-by.d.cts +58 -0
- package/types/array/group-by.d.ts +49 -5
- package/types/array/index-of.d.cts +26 -0
- package/types/array/index-of.d.ts +14 -6
- package/types/array/index.d.cts +239 -95
- package/types/array/index.d.ts +7 -6
- package/types/array/insert.d.cts +16 -0
- package/types/array/insert.d.ts +10 -5
- package/types/array/models.d.cts +14 -11
- package/types/array/models.d.ts +14 -12
- package/types/array/shuffle.d.cts +8 -0
- package/types/array/shuffle.d.ts +2 -2
- package/types/array/sort.d.cts +24 -0
- package/types/array/sort.d.ts +10 -10
- package/types/array/splice.d.cts +22 -0
- package/types/array/splice.d.ts +4 -4
- package/types/array/to-map.d.cts +61 -0
- package/types/array/to-map.d.ts +42 -20
- package/types/array/to-record.d.cts +61 -0
- package/types/array/to-record.d.ts +42 -20
- package/types/array/unique.d.cts +21 -0
- package/types/array/unique.d.ts +10 -6
- package/types/colour/base.d.cts +153 -0
- package/types/colour/base.d.ts +2 -2
- package/types/colour/functions.d.cts +173 -0
- package/types/colour/functions.d.ts +3 -3
- package/types/colour/hex.d.cts +157 -0
- package/types/colour/hex.d.ts +4 -4
- package/types/colour/hsl.d.cts +157 -0
- package/types/colour/hsl.d.ts +16 -10
- package/types/colour/index.d.cts +28 -16
- package/types/colour/index.d.ts +1 -1
- package/types/colour/is.d.cts +170 -0
- package/types/colour/is.d.ts +3 -3
- package/types/colour/rgb.d.cts +157 -0
- package/types/colour/rgb.d.ts +15 -9
- package/types/emitter.d.cts +11 -8
- package/types/emitter.d.ts +11 -8
- package/types/function.d.cts +10 -10
- package/types/function.d.ts +11 -11
- package/types/index.d.cts +1120 -736
- package/types/index.d.ts +16 -16
- package/types/internal/array/callbacks.d.cts +11 -0
- package/types/internal/array/callbacks.d.ts +2 -0
- package/types/internal/array/find.d.cts +7 -0
- package/types/internal/array/find.d.ts +3 -0
- package/types/internal/value/handle.d.cts +37 -0
- package/types/internal/{value-handle.d.ts → value/handle.d.ts} +1 -1
- package/types/is.d.ts +1 -1
- package/types/logger.d.cts +13 -21
- package/types/logger.d.ts +13 -21
- package/types/math.d.cts +1 -1
- package/types/math.d.ts +1 -1
- package/types/models.d.cts +4 -4
- package/types/models.d.ts +1 -4
- package/types/number.d.cts +2 -2
- package/types/number.d.ts +2 -2
- package/types/query.d.cts +2 -2
- package/types/query.d.ts +3 -3
- package/types/queue.d.cts +1 -1
- package/types/queue.d.ts +1 -1
- package/types/random.d.cts +8 -12
- package/types/random.d.ts +8 -12
- package/types/sized.d.cts +6 -6
- package/types/sized.d.ts +6 -6
- package/types/string/case.d.cts +28 -0
- package/types/string/index.d.cts +30 -27
- package/types/string/index.d.ts +3 -3
- package/types/string/template.d.cts +50 -0
- package/types/string/template.d.ts +4 -1
- package/types/value/clone.d.cts +8 -0
- package/types/value/clone.d.ts +4 -2
- package/types/value/compare.d.cts +8 -0
- package/types/value/diff.d.cts +25 -0
- package/types/value/equal.d.cts +12 -0
- package/types/value/get.d.cts +1319 -0
- package/types/value/get.d.ts +1 -1
- package/types/value/index.d.cts +8 -6
- package/types/value/index.d.ts +2 -2
- package/types/value/merge.d.cts +72 -0
- package/types/value/merge.d.ts +2 -2
- package/types/value/set.d.cts +1011 -0
- package/types/value/set.d.ts +1 -1
- package/types/value/smush.d.cts +1368 -0
- package/types/value/smush.d.ts +2 -2
- package/types/value/unsmush.d.cts +141 -0
- package/types/value/unsmush.d.ts +2 -2
- package/dist/js/array/count.mjs +0 -8
- package/dist/js/array/exists.mjs +0 -8
- package/dist/js/array/filter.mjs +0 -8
- package/dist/js/array/find.mjs +0 -8
- package/dist/js/array/group-by.mjs +0 -33
- package/dist/js/array/index-of.mjs +0 -8
- package/dist/js/array/index.mjs +0 -34
- package/dist/js/array/insert.mjs +0 -22
- package/dist/js/array/models.mjs +0 -0
- package/dist/js/array/splice.mjs +0 -9
- package/dist/js/array/to-map.mjs +0 -27
- package/dist/js/array/to-record.mjs +0 -8
- package/dist/js/array/unique.mjs +0 -8
- package/dist/js/colour/index.mjs +0 -30
- package/dist/js/index.mjs +0 -17
- package/dist/js/internal/array-callbacks.mjs +0 -19
- package/dist/js/internal/array-find.mjs +0 -51
- package/dist/js/logger.mjs +0 -69
- package/dist/js/models.mjs +0 -0
- package/dist/js/string/index.mjs +0 -44
- package/dist/js/value/index.mjs +0 -23
- package/src/js/internal/array-callbacks.ts +0 -28
- package/types/internal/array-callbacks.d.ts +0 -2
- package/types/internal/array-find.d.ts +0 -4
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { getCallbacks } from "../internal/array/callbacks.js";
|
|
2
|
+
function toMap(array, first, second, third) {
|
|
3
|
+
var _a, _b;
|
|
4
|
+
const asArrays = first === true || second === true || third === true;
|
|
5
|
+
const callbacks = getCallbacks(void 0, first, second);
|
|
6
|
+
const map = /* @__PURE__ */ new Map();
|
|
7
|
+
const { length } = array;
|
|
8
|
+
for (let index = 0; index < length; index += 1) {
|
|
9
|
+
const item = array[index];
|
|
10
|
+
const key = ((_a = callbacks == null ? void 0 : callbacks.key) == null ? void 0 : _a.call(callbacks, item, index, array)) ?? index;
|
|
11
|
+
const value = ((_b = callbacks == null ? void 0 : callbacks.value) == null ? void 0 : _b.call(callbacks, item, index, array)) ?? item;
|
|
12
|
+
if (asArrays) {
|
|
13
|
+
const existing = map.get(key);
|
|
14
|
+
if (existing == null) {
|
|
15
|
+
map.set(key, [value]);
|
|
16
|
+
} else {
|
|
17
|
+
existing.push(value);
|
|
18
|
+
}
|
|
19
|
+
} else {
|
|
20
|
+
map.set(key, value);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return map;
|
|
24
|
+
}
|
|
25
|
+
export {
|
|
26
|
+
toMap
|
|
27
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const array_groupBy = require("./group-by.cjs");
|
|
4
|
+
function toRecord(array, first, second, third) {
|
|
5
|
+
return array_groupBy.groupValues(
|
|
6
|
+
array,
|
|
7
|
+
first,
|
|
8
|
+
second,
|
|
9
|
+
first === true || second === true || third === true
|
|
10
|
+
);
|
|
11
|
+
}
|
|
12
|
+
exports.toRecord = toRecord;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const internal_array_find = require("../internal/array/find.cjs");
|
|
4
|
+
function unique(array, key) {
|
|
5
|
+
return internal_array_find.findValues("unique", array, void 0, key, void 0);
|
|
6
|
+
}
|
|
7
|
+
exports.unique = unique;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const colour_is = require("./is.cjs");
|
|
4
|
+
class Colour {
|
|
5
|
+
/**
|
|
6
|
+
* Get the current value of the colour
|
|
7
|
+
*/
|
|
8
|
+
get value() {
|
|
9
|
+
return { ...this.state.value };
|
|
10
|
+
}
|
|
11
|
+
constructor(type, value, defaults, properties) {
|
|
12
|
+
this.$colour = type;
|
|
13
|
+
this.state = {
|
|
14
|
+
value: colour_is.isColourValue(value, properties) ? { ...value } : { ...defaults }
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.Colour = Colour;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const colour_hex = require("./hex.cjs");
|
|
4
|
+
const colour_hsl = require("./hsl.cjs");
|
|
5
|
+
const colour_rgb = require("./rgb.cjs");
|
|
6
|
+
const number = require("../number.cjs");
|
|
7
|
+
const anyPattern = /^#*([a-f0-9]{3}){1,2}$/i;
|
|
8
|
+
const groupedPattern = /^#*([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})$/i;
|
|
9
|
+
function getNormalisedHex(value) {
|
|
10
|
+
const normalised = value.replace(/^#/, "");
|
|
11
|
+
return normalised.length === 3 ? normalised.split("").map((character) => character.repeat(2)).join("") : normalised;
|
|
12
|
+
}
|
|
13
|
+
function hexToRgb(value) {
|
|
14
|
+
const hex = anyPattern.test(value) ? getNormalisedHex(value) : "";
|
|
15
|
+
const pairs = groupedPattern.exec(hex) ?? [];
|
|
16
|
+
const rgb = [];
|
|
17
|
+
const { length } = pairs;
|
|
18
|
+
for (let index = 1; index < length; index += 1) {
|
|
19
|
+
rgb.push(Number.parseInt(pairs[index], 16));
|
|
20
|
+
}
|
|
21
|
+
return new colour_rgb.RGBColour({
|
|
22
|
+
blue: rgb[2] ?? 0,
|
|
23
|
+
green: rgb[1] ?? 0,
|
|
24
|
+
red: rgb[0] ?? 0
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
function hslToRgb(value) {
|
|
28
|
+
let hue = value.hue % 360;
|
|
29
|
+
if (hue < 0) {
|
|
30
|
+
hue += 360;
|
|
31
|
+
}
|
|
32
|
+
const saturation = value.saturation / 100;
|
|
33
|
+
const lightness = value.lightness / 100;
|
|
34
|
+
function get(value2) {
|
|
35
|
+
const part = (value2 + hue / 30) % 12;
|
|
36
|
+
const mod = saturation * Math.min(lightness, 1 - lightness);
|
|
37
|
+
return lightness - mod * Math.max(-1, Math.min(part - 3, 9 - part, 1));
|
|
38
|
+
}
|
|
39
|
+
return new colour_rgb.RGBColour({
|
|
40
|
+
blue: number.clamp(Math.round(get(4) * 255), 0, 255),
|
|
41
|
+
green: number.clamp(Math.round(get(8) * 255), 0, 255),
|
|
42
|
+
red: number.clamp(Math.round(get(0) * 255), 0, 255)
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
function rgbToHex(value) {
|
|
46
|
+
return new colour_hex.HexColour(
|
|
47
|
+
`${[value.red, value.green, value.blue].map((colour) => {
|
|
48
|
+
const hex = colour.toString(16);
|
|
49
|
+
return hex.length === 1 ? `0${hex}` : hex;
|
|
50
|
+
}).join("")}`
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
function rgbToHsl(rgb) {
|
|
54
|
+
const blue = rgb.blue / 255;
|
|
55
|
+
const green = rgb.green / 255;
|
|
56
|
+
const red = rgb.red / 255;
|
|
57
|
+
const max = Math.max(blue, green, red);
|
|
58
|
+
const min = Math.min(blue, green, red);
|
|
59
|
+
const delta = max - min;
|
|
60
|
+
const lightness = (min + max) / 2;
|
|
61
|
+
let hue = 0;
|
|
62
|
+
let saturation = 0;
|
|
63
|
+
if (delta !== 0) {
|
|
64
|
+
saturation = lightness === 0 || lightness === 1 ? 0 : (max - lightness) / Math.min(lightness, 1 - lightness);
|
|
65
|
+
switch (max) {
|
|
66
|
+
case blue:
|
|
67
|
+
hue = (red - green) / delta + 4;
|
|
68
|
+
break;
|
|
69
|
+
case green:
|
|
70
|
+
hue = (blue - red) / delta + 2;
|
|
71
|
+
break;
|
|
72
|
+
case red:
|
|
73
|
+
hue = (green - blue) / delta + (green < blue ? 6 : 0);
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
hue *= 60;
|
|
77
|
+
}
|
|
78
|
+
if (saturation < 0) {
|
|
79
|
+
hue += 180;
|
|
80
|
+
saturation = Math.abs(saturation);
|
|
81
|
+
}
|
|
82
|
+
if (hue >= 360) {
|
|
83
|
+
hue -= 360;
|
|
84
|
+
}
|
|
85
|
+
return new colour_hsl.HSLColour({
|
|
86
|
+
hue: +hue.toFixed(2),
|
|
87
|
+
lightness: +(lightness * 100).toFixed(2),
|
|
88
|
+
saturation: +(saturation * 100).toFixed(2)
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
exports.anyPattern = anyPattern;
|
|
92
|
+
exports.getNormalisedHex = getNormalisedHex;
|
|
93
|
+
exports.hexToRgb = hexToRgb;
|
|
94
|
+
exports.hslToRgb = hslToRgb;
|
|
95
|
+
exports.rgbToHex = rgbToHex;
|
|
96
|
+
exports.rgbToHsl = rgbToHsl;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
1
|
+
import { HexColour } from "./hex.js";
|
|
2
|
+
import { HSLColour } from "./hsl.js";
|
|
3
|
+
import { RGBColour } from "./rgb.js";
|
|
4
|
+
import { clamp } from "../number.js";
|
|
5
|
+
const anyPattern = /^#*([a-f0-9]{3}){1,2}$/i;
|
|
6
|
+
const groupedPattern = /^#*([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})$/i;
|
|
6
7
|
function getNormalisedHex(value) {
|
|
7
8
|
const normalised = value.replace(/^#/, "");
|
|
8
9
|
return normalised.length === 3 ? normalised.split("").map((character) => character.repeat(2)).join("") : normalised;
|
|
@@ -12,7 +13,7 @@ function hexToRgb(value) {
|
|
|
12
13
|
const pairs = groupedPattern.exec(hex) ?? [];
|
|
13
14
|
const rgb = [];
|
|
14
15
|
const { length } = pairs;
|
|
15
|
-
for (let index = 1;index < length; index += 1) {
|
|
16
|
+
for (let index = 1; index < length; index += 1) {
|
|
16
17
|
rgb.push(Number.parseInt(pairs[index], 16));
|
|
17
18
|
}
|
|
18
19
|
return new RGBColour({
|
|
@@ -40,10 +41,12 @@ function hslToRgb(value) {
|
|
|
40
41
|
});
|
|
41
42
|
}
|
|
42
43
|
function rgbToHex(value) {
|
|
43
|
-
return new HexColour(
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
return new HexColour(
|
|
45
|
+
`${[value.red, value.green, value.blue].map((colour) => {
|
|
46
|
+
const hex = colour.toString(16);
|
|
47
|
+
return hex.length === 1 ? `0${hex}` : hex;
|
|
48
|
+
}).join("")}`
|
|
49
|
+
);
|
|
47
50
|
}
|
|
48
51
|
function rgbToHsl(rgb) {
|
|
49
52
|
const blue = rgb.blue / 255;
|
|
@@ -67,8 +70,6 @@ function rgbToHsl(rgb) {
|
|
|
67
70
|
case red:
|
|
68
71
|
hue = (green - blue) / delta + (green < blue ? 6 : 0);
|
|
69
72
|
break;
|
|
70
|
-
default:
|
|
71
|
-
break;
|
|
72
73
|
}
|
|
73
74
|
hue *= 60;
|
|
74
75
|
}
|
|
@@ -85,13 +86,11 @@ function rgbToHsl(rgb) {
|
|
|
85
86
|
saturation: +(saturation * 100).toFixed(2)
|
|
86
87
|
});
|
|
87
88
|
}
|
|
88
|
-
var anyPattern = /^#*([a-f0-9]{3}){1,2}$/i;
|
|
89
|
-
var groupedPattern = /^#*([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})$/i;
|
|
90
89
|
export {
|
|
91
|
-
|
|
92
|
-
rgbToHex,
|
|
93
|
-
hslToRgb,
|
|
94
|
-
hexToRgb,
|
|
90
|
+
anyPattern,
|
|
95
91
|
getNormalisedHex,
|
|
96
|
-
|
|
92
|
+
hexToRgb,
|
|
93
|
+
hslToRgb,
|
|
94
|
+
rgbToHex,
|
|
95
|
+
rgbToHsl
|
|
97
96
|
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
4
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
6
|
+
const colour_functions = require("./functions.cjs");
|
|
7
|
+
class HexColour {
|
|
8
|
+
constructor(value) {
|
|
9
|
+
__publicField(this, "state");
|
|
10
|
+
this.$colour = "hex";
|
|
11
|
+
this.state = {
|
|
12
|
+
value: typeof value === "string" && colour_functions.anyPattern.test(value) ? colour_functions.getNormalisedHex(value) : "000000"
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Get the value of the colour
|
|
17
|
+
*/
|
|
18
|
+
get value() {
|
|
19
|
+
return `#${this.state.value}`;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Set the value of the colour
|
|
23
|
+
*/
|
|
24
|
+
set value(value) {
|
|
25
|
+
this.state.value = colour_functions.anyPattern.test(value) ? colour_functions.getNormalisedHex(value) : "000000";
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Convert the colour to an RGB-colour
|
|
29
|
+
*/
|
|
30
|
+
toHsl() {
|
|
31
|
+
return HexColour.toRgb(this.value).toHsl();
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Convert the colour to an HSL-colour
|
|
35
|
+
*/
|
|
36
|
+
toRgb() {
|
|
37
|
+
return HexColour.toRgb(this.value);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Get the colour as a string _(prefixed with #)_
|
|
41
|
+
*/
|
|
42
|
+
toString() {
|
|
43
|
+
return this.value;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Convert a hex-colour to an RGB-colour
|
|
47
|
+
*/
|
|
48
|
+
static toRgb(value) {
|
|
49
|
+
return colour_functions.hexToRgb(value);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
function getHexColour(value) {
|
|
53
|
+
return new HexColour(value);
|
|
54
|
+
}
|
|
55
|
+
exports.HexColour = HexColour;
|
|
56
|
+
exports.getHexColour = getHexColour;
|
|
@@ -1,37 +1,56 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
+
import { anyPattern, getNormalisedHex, hexToRgb } from "./functions.js";
|
|
7
5
|
class HexColour {
|
|
8
|
-
state;
|
|
9
|
-
get value() {
|
|
10
|
-
return `#${this.state.value}`;
|
|
11
|
-
}
|
|
12
|
-
set value(value) {
|
|
13
|
-
this.state.value = anyPattern.test(value) ? getNormalisedHex(value) : "000000";
|
|
14
|
-
}
|
|
15
6
|
constructor(value) {
|
|
7
|
+
__publicField(this, "state");
|
|
16
8
|
this.$colour = "hex";
|
|
17
9
|
this.state = {
|
|
18
10
|
value: typeof value === "string" && anyPattern.test(value) ? getNormalisedHex(value) : "000000"
|
|
19
11
|
};
|
|
20
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* Get the value of the colour
|
|
15
|
+
*/
|
|
16
|
+
get value() {
|
|
17
|
+
return `#${this.state.value}`;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Set the value of the colour
|
|
21
|
+
*/
|
|
22
|
+
set value(value) {
|
|
23
|
+
this.state.value = anyPattern.test(value) ? getNormalisedHex(value) : "000000";
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Convert the colour to an RGB-colour
|
|
27
|
+
*/
|
|
21
28
|
toHsl() {
|
|
22
29
|
return HexColour.toRgb(this.value).toHsl();
|
|
23
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* Convert the colour to an HSL-colour
|
|
33
|
+
*/
|
|
24
34
|
toRgb() {
|
|
25
35
|
return HexColour.toRgb(this.value);
|
|
26
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* Get the colour as a string _(prefixed with #)_
|
|
39
|
+
*/
|
|
27
40
|
toString() {
|
|
28
41
|
return this.value;
|
|
29
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Convert a hex-colour to an RGB-colour
|
|
45
|
+
*/
|
|
30
46
|
static toRgb(value) {
|
|
31
47
|
return hexToRgb(value);
|
|
32
48
|
}
|
|
33
49
|
}
|
|
50
|
+
function getHexColour(value) {
|
|
51
|
+
return new HexColour(value);
|
|
52
|
+
}
|
|
34
53
|
export {
|
|
35
|
-
|
|
36
|
-
|
|
54
|
+
HexColour,
|
|
55
|
+
getHexColour
|
|
37
56
|
};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const colour_base = require("./base.cjs");
|
|
4
|
+
const colour_functions = require("./functions.cjs");
|
|
5
|
+
const number = require("../number.cjs");
|
|
6
|
+
class HSLColour extends colour_base.Colour {
|
|
7
|
+
/**
|
|
8
|
+
* Get the current hue
|
|
9
|
+
*/
|
|
10
|
+
get hue() {
|
|
11
|
+
return +this.state.value.hue;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Set the current hue
|
|
15
|
+
*/
|
|
16
|
+
set hue(value) {
|
|
17
|
+
this.state.value.hue = number.clamp(value, 0, 360);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Get the current lightness
|
|
21
|
+
*/
|
|
22
|
+
get lightness() {
|
|
23
|
+
return +this.state.value.lightness;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Set the current lightness
|
|
27
|
+
*/
|
|
28
|
+
set lightness(value) {
|
|
29
|
+
this.state.value.lightness = number.clamp(value, 0, 100);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Get the current saturation
|
|
33
|
+
*/
|
|
34
|
+
get saturation() {
|
|
35
|
+
return +this.state.value.saturation;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Set the current saturation
|
|
39
|
+
*/
|
|
40
|
+
set saturation(value) {
|
|
41
|
+
this.state.value.saturation = number.clamp(value, 0, 100);
|
|
42
|
+
}
|
|
43
|
+
constructor(value) {
|
|
44
|
+
super("hsl", value, defaults, properties);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* @inheritdoc
|
|
48
|
+
*/
|
|
49
|
+
toHex() {
|
|
50
|
+
return HSLColour.toRgb(this.state.value).toHex();
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Convert the colour to an RGB-colour
|
|
54
|
+
*/
|
|
55
|
+
toRgb() {
|
|
56
|
+
return HSLColour.toRgb(this.state.value);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* @inheritdoc
|
|
60
|
+
*/
|
|
61
|
+
toString() {
|
|
62
|
+
return `hsl(${this.state.value.hue}, ${this.state.value.saturation}%, ${this.state.value.lightness}%)`;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Convert an HSL-colour to an RGB-colour
|
|
66
|
+
*/
|
|
67
|
+
static toRgb(value) {
|
|
68
|
+
return colour_functions.hslToRgb(value);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
const defaults = {
|
|
72
|
+
hue: 0,
|
|
73
|
+
lightness: 0,
|
|
74
|
+
saturation: 0
|
|
75
|
+
};
|
|
76
|
+
const properties = [
|
|
77
|
+
"hue",
|
|
78
|
+
"lightness",
|
|
79
|
+
"saturation"
|
|
80
|
+
];
|
|
81
|
+
function getHSLColour(value) {
|
|
82
|
+
return new HSLColour(value);
|
|
83
|
+
}
|
|
84
|
+
exports.HSLColour = HSLColour;
|
|
85
|
+
exports.getHSLColour = getHSLColour;
|
|
@@ -1,57 +1,85 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { hslToRgb } from "./functions";
|
|
5
|
-
function getHSLColour(value) {
|
|
6
|
-
return new HSLColour(value);
|
|
7
|
-
}
|
|
8
|
-
|
|
1
|
+
import { Colour } from "./base.js";
|
|
2
|
+
import { hslToRgb } from "./functions.js";
|
|
3
|
+
import { clamp } from "../number.js";
|
|
9
4
|
class HSLColour extends Colour {
|
|
5
|
+
/**
|
|
6
|
+
* Get the current hue
|
|
7
|
+
*/
|
|
10
8
|
get hue() {
|
|
11
9
|
return +this.state.value.hue;
|
|
12
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* Set the current hue
|
|
13
|
+
*/
|
|
13
14
|
set hue(value) {
|
|
14
15
|
this.state.value.hue = clamp(value, 0, 360);
|
|
15
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* Get the current lightness
|
|
19
|
+
*/
|
|
16
20
|
get lightness() {
|
|
17
21
|
return +this.state.value.lightness;
|
|
18
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* Set the current lightness
|
|
25
|
+
*/
|
|
19
26
|
set lightness(value) {
|
|
20
27
|
this.state.value.lightness = clamp(value, 0, 100);
|
|
21
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* Get the current saturation
|
|
31
|
+
*/
|
|
22
32
|
get saturation() {
|
|
23
33
|
return +this.state.value.saturation;
|
|
24
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* Set the current saturation
|
|
37
|
+
*/
|
|
25
38
|
set saturation(value) {
|
|
26
39
|
this.state.value.saturation = clamp(value, 0, 100);
|
|
27
40
|
}
|
|
28
41
|
constructor(value) {
|
|
29
42
|
super("hsl", value, defaults, properties);
|
|
30
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* @inheritdoc
|
|
46
|
+
*/
|
|
31
47
|
toHex() {
|
|
32
48
|
return HSLColour.toRgb(this.state.value).toHex();
|
|
33
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* Convert the colour to an RGB-colour
|
|
52
|
+
*/
|
|
34
53
|
toRgb() {
|
|
35
54
|
return HSLColour.toRgb(this.state.value);
|
|
36
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* @inheritdoc
|
|
58
|
+
*/
|
|
37
59
|
toString() {
|
|
38
60
|
return `hsl(${this.state.value.hue}, ${this.state.value.saturation}%, ${this.state.value.lightness}%)`;
|
|
39
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* Convert an HSL-colour to an RGB-colour
|
|
64
|
+
*/
|
|
40
65
|
static toRgb(value) {
|
|
41
66
|
return hslToRgb(value);
|
|
42
67
|
}
|
|
43
68
|
}
|
|
44
|
-
|
|
69
|
+
const defaults = {
|
|
45
70
|
hue: 0,
|
|
46
71
|
lightness: 0,
|
|
47
72
|
saturation: 0
|
|
48
73
|
};
|
|
49
|
-
|
|
74
|
+
const properties = [
|
|
50
75
|
"hue",
|
|
51
76
|
"lightness",
|
|
52
77
|
"saturation"
|
|
53
78
|
];
|
|
79
|
+
function getHSLColour(value) {
|
|
80
|
+
return new HSLColour(value);
|
|
81
|
+
}
|
|
54
82
|
export {
|
|
55
|
-
|
|
56
|
-
|
|
83
|
+
HSLColour,
|
|
84
|
+
getHSLColour
|
|
57
85
|
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const colour_hex = require("./hex.cjs");
|
|
4
|
+
const colour_hsl = require("./hsl.cjs");
|
|
5
|
+
const colour_is = require("./is.cjs");
|
|
6
|
+
const colour_rgb = require("./rgb.cjs");
|
|
7
|
+
function getForegroundColour(value) {
|
|
8
|
+
const values = [value.blue / 255, value.green / 255, value.red / 255];
|
|
9
|
+
for (let colour of values) {
|
|
10
|
+
if (colour <= 0.03928) {
|
|
11
|
+
colour /= 12.92;
|
|
12
|
+
} else {
|
|
13
|
+
colour = ((colour + 0.055) / 1.055) ** 2.4;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
const luminance = 0.2126 * values[2] + 0.7152 * values[1] + 0.0722 * values[0];
|
|
17
|
+
return luminance > 0.625 ? "black" : "white";
|
|
18
|
+
}
|
|
19
|
+
exports.HexColour = colour_hex.HexColour;
|
|
20
|
+
exports.getHexColour = colour_hex.getHexColour;
|
|
21
|
+
exports.HSLColour = colour_hsl.HSLColour;
|
|
22
|
+
exports.getHSLColour = colour_hsl.getHSLColour;
|
|
23
|
+
exports.isColour = colour_is.isColour;
|
|
24
|
+
exports.isHSLColour = colour_is.isHSLColour;
|
|
25
|
+
exports.isHexColour = colour_is.isHexColour;
|
|
26
|
+
exports.isRGBColour = colour_is.isRGBColour;
|
|
27
|
+
exports.RGBColour = colour_rgb.RGBColour;
|
|
28
|
+
exports.getRGBColour = colour_rgb.getRGBColour;
|
|
29
|
+
exports.getForegroundColour = getForegroundColour;
|