@oscarpalmer/atoms 0.157.0 → 0.159.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.
@@ -244,12 +244,12 @@ function findValues(type, array, parameters, mapper) {
244
244
  const { length } = array;
245
245
  const { bool, key, value } = getParameters(parameters);
246
246
  const callbacks = getArrayCallbacks(bool, key);
247
- if (type === FIND_VALUES_UNIQUE && callbacks?.keyed == null && length >= UNIQUE_THRESHOLD) {
247
+ if (type === "unique" && callbacks?.keyed == null && length >= UNIQUE_THRESHOLD) {
248
248
  result.matched = [...new Set(array)];
249
249
  return result;
250
250
  }
251
251
  const mapCallback = typeof mapper === "function" ? mapper : void 0;
252
- if (callbacks?.bool != null || type === FIND_VALUES_ALL && key == null) {
252
+ if (callbacks?.bool != null || type === "all" && key == null) {
253
253
  const callback = callbacks?.bool ?? ((item) => Object.is(item, value));
254
254
  for (let index = 0; index < length; index += 1) {
255
255
  const item = array[index];
@@ -262,7 +262,7 @@ function findValues(type, array, parameters, mapper) {
262
262
  for (let index = 0; index < length; index += 1) {
263
263
  const item = array[index];
264
264
  const keyed = callbacks?.keyed?.(item, index, array) ?? item;
265
- if (type === FIND_VALUES_ALL && Object.is(keyed, value) || type === FIND_VALUES_UNIQUE && !keys.has(keyed)) {
265
+ if (type === "all" && Object.is(keyed, value) || type === "unique" && !keys.has(keyed)) {
266
266
  keys.add(keyed);
267
267
  result.matched.push(mapCallback?.(item, index, array) ?? item);
268
268
  } else result.notMatched.push(item);
@@ -279,7 +279,6 @@ function getParameters(original) {
279
279
  }
280
280
  const FIND_VALUE_INDEX = "index";
281
281
  const FIND_VALUE_VALUE = "value";
282
- const FIND_VALUES_ALL = "all";
283
282
  const FIND_VALUES_UNIQUE = "unique";
284
283
  const UNIQUE_THRESHOLD = 100;
285
284
  function exists(array, ...parameters) {
@@ -287,11 +286,11 @@ function exists(array, ...parameters) {
287
286
  return findValue(FIND_VALUE_INDEX, array, parameters) > -1;
288
287
  }
289
288
  function filter(array, ...parameters) {
290
- return findValues(FIND_VALUES_ALL, array, parameters).matched;
289
+ return findValues("all", array, parameters).matched;
291
290
  }
292
291
  filter.remove = removeFiltered;
293
292
  function removeFiltered(array, ...parameters) {
294
- return findValues(FIND_VALUES_ALL, array, parameters).notMatched;
293
+ return findValues("all", array, parameters).notMatched;
295
294
  }
296
295
  function find(array, ...parameters) {
297
296
  return findValue(FIND_VALUE_VALUE, array, parameters);
@@ -366,7 +365,7 @@ function intersection(first, second, key) {
366
365
  return compareSets(COMPARE_SETS_INTERSECTION, first, second, key);
367
366
  }
368
367
  function partition(array, ...parameters) {
369
- const { matched, notMatched } = findValues(FIND_VALUES_ALL, array, parameters);
368
+ const { matched, notMatched } = findValues("all", array, parameters);
370
369
  return [matched, notMatched];
371
370
  }
372
371
  /**
@@ -379,7 +378,7 @@ function push(array, pushed) {
379
378
  return insertValues("push", array, pushed, array.length, 0);
380
379
  }
381
380
  function select(array, ...parameters) {
382
- return findValues(FIND_VALUES_ALL, array, parameters, parameters.pop()).matched;
381
+ return findValues("all", array, parameters, parameters.pop()).matched;
383
382
  }
384
383
  function drop(array, first, second) {
385
384
  return extract(EXTRACT_DROP, array, first, second);
@@ -1017,6 +1016,159 @@ function memoize(callback, options) {
1017
1016
  }
1018
1017
  const DEFAULT_CACHE_SIZE = 1024;
1019
1018
  /**
1019
+ * Asserts that a condition is true, throwing an error if it is not
1020
+ * @param condition Condition to assert
1021
+ * @param message Error message
1022
+ * @param error Error constructor
1023
+ */
1024
+ function assert(condition, message, error) {
1025
+ if (!condition()) throw new (error ?? Error)(message);
1026
+ }
1027
+ assert.condition = assertCondition;
1028
+ assert.defined = assertDefined;
1029
+ assert.instanceOf = assertInstanceOf;
1030
+ assert.is = assertIs;
1031
+ /**
1032
+ * Creates an asserter that asserts a condition is true, throwing an error if it is not
1033
+ * @param condition Condition to assert
1034
+ * @param message Error message
1035
+ * @param error Error constructor
1036
+ * @returns Asserter
1037
+ */
1038
+ function assertCondition(condition, message, error) {
1039
+ return (value) => {
1040
+ assert(() => condition(value), message, error);
1041
+ };
1042
+ }
1043
+ /**
1044
+ * Asserts that a value is defined throwing an error if it is not
1045
+ * @param value Value to assert
1046
+ * @param message Error message
1047
+ */
1048
+ function assertDefined(value, message) {
1049
+ assert(() => value != null, message ?? MESSAGE_VALUE_DEFINED);
1050
+ }
1051
+ /**
1052
+ * Creates an asserter that asserts a value is an instance of a constructor, throwing an error if it is not
1053
+ * @param constructor Constructor to check against
1054
+ * @param message Error message
1055
+ * @param error Error constructor
1056
+ * @returns Asserter
1057
+ */
1058
+ function assertInstanceOf(constructor, message, error) {
1059
+ return (value) => {
1060
+ assert(() => value instanceof constructor, message, error);
1061
+ };
1062
+ }
1063
+ /**
1064
+ * Creates an asserter that asserts a value is of a specific type, throwing an error if it is not
1065
+ * @param condition Type guard function to check the value
1066
+ * @param message Error message
1067
+ * @param error Error constructor
1068
+ * @returns Asserter
1069
+ */
1070
+ function assertIs(condition, message, error) {
1071
+ return (value) => {
1072
+ assert(() => condition(value), message, error);
1073
+ };
1074
+ }
1075
+ const MESSAGE_VALUE_DEFINED = "Expected value to be defined";
1076
+ /**
1077
+ * Create an asynchronous function that can only be called once, rejecting or resolving the same result on subsequent calls
1078
+ * @param callback Callback to use once
1079
+ * @returns Once callback
1080
+ */
1081
+ function asyncOnce(callback) {
1082
+ assert(() => typeof callback === "function", MESSAGE_EXPECTATION$1);
1083
+ const state = {
1084
+ called: false,
1085
+ cleared: false,
1086
+ error: false,
1087
+ finished: false,
1088
+ items: [],
1089
+ value: void 0
1090
+ };
1091
+ const fn = (...parameters) => {
1092
+ if (state.cleared) return Promise.reject(new Error(MESSAGE_CLEARED));
1093
+ if (state.finished) return state.error ? Promise.reject(state.value) : Promise.resolve(state.value);
1094
+ if (state.called) return new Promise((resolve, reject) => {
1095
+ state.items.push({
1096
+ reject,
1097
+ resolve
1098
+ });
1099
+ });
1100
+ state.called = true;
1101
+ return new Promise((resolve, reject) => {
1102
+ state.items.push({
1103
+ reject,
1104
+ resolve
1105
+ });
1106
+ callback(...parameters).then((value) => {
1107
+ handleResult$1(state, value, false);
1108
+ }).catch((error) => {
1109
+ handleResult$1(state, error, true);
1110
+ });
1111
+ });
1112
+ };
1113
+ Object.defineProperties(fn, {
1114
+ called: { get: () => state.called },
1115
+ cleared: { get: () => state.cleared },
1116
+ error: { get: () => state.error },
1117
+ finished: { get: () => state.finished }
1118
+ });
1119
+ fn.clear = () => {
1120
+ if (!state.called || !state.finished || state.cleared) return;
1121
+ state.cleared = true;
1122
+ state.value = void 0;
1123
+ };
1124
+ return fn;
1125
+ }
1126
+ function handleResult$1(state, value, error) {
1127
+ state.error = error;
1128
+ state.finished = true;
1129
+ state.value = value;
1130
+ const items = state.items.splice(0);
1131
+ const { length } = items;
1132
+ for (let index = 0; index < length; index += 1) {
1133
+ const { reject, resolve } = items[index];
1134
+ if (error) reject(value);
1135
+ else resolve(value);
1136
+ }
1137
+ }
1138
+ /**
1139
+ * Create a function that can only be called once, returning the same value on subsequent calls
1140
+ * @param callback Callback to use once
1141
+ * @returns Once callback
1142
+ */
1143
+ function once(callback) {
1144
+ assert(() => typeof callback === "function", MESSAGE_EXPECTATION$1);
1145
+ const state = {
1146
+ called: false,
1147
+ cleared: false,
1148
+ value: void 0
1149
+ };
1150
+ const fn = (...parameters) => {
1151
+ if (state.cleared) throw new Error(MESSAGE_CLEARED);
1152
+ if (state.called) return state.value;
1153
+ state.called = true;
1154
+ state.value = callback(...parameters);
1155
+ return state.value;
1156
+ };
1157
+ Object.defineProperties(fn, {
1158
+ called: { get: () => state.called },
1159
+ cleared: { get: () => state.cleared }
1160
+ });
1161
+ fn.clear = () => {
1162
+ if (!state.called || state.cleared) return;
1163
+ state.cleared = true;
1164
+ state.value = void 0;
1165
+ };
1166
+ return fn;
1167
+ }
1168
+ once.async = asyncOnce;
1169
+ const MESSAGE_CLEARED = "Once has been cleared";
1170
+ const MESSAGE_EXPECTATION$1 = "Once expected a function";
1171
+ /**
1020
1172
  * Debounce a function, ensuring it is only called after `time` milliseconds have passed
1021
1173
  *
1022
1174
  * On subsequent calls, the timer is reset and will wait another `time` milliseconds _(and so on...)_
@@ -1135,64 +1287,6 @@ function isOk(value) {
1135
1287
  function isResult(value) {
1136
1288
  return _isResult(value, true) || _isResult(value, false);
1137
1289
  }
1138
- /**
1139
- * Asserts that a condition is true, throwing an error if it is not
1140
- * @param condition Condition to assert
1141
- * @param message Error message
1142
- * @param error Error constructor
1143
- */
1144
- function assert(condition, message, error) {
1145
- if (!condition()) throw new (error ?? Error)(message);
1146
- }
1147
- assert.condition = assertCondition;
1148
- assert.defined = assertDefined;
1149
- assert.instanceOf = assertInstanceOf;
1150
- assert.is = assertIs;
1151
- /**
1152
- * Creates an asserter that asserts a condition is true, throwing an error if it is not
1153
- * @param condition Condition to assert
1154
- * @param message Error message
1155
- * @param error Error constructor
1156
- * @returns Asserter
1157
- */
1158
- function assertCondition(condition, message, error) {
1159
- return (value) => {
1160
- assert(() => condition(value), message, error);
1161
- };
1162
- }
1163
- /**
1164
- * Asserts that a value is defined throwing an error if it is not
1165
- * @param value Value to assert
1166
- * @param message Error message
1167
- */
1168
- function assertDefined(value, message) {
1169
- assert(() => value != null, message ?? MESSAGE_VALUE_DEFINED);
1170
- }
1171
- /**
1172
- * Creates an asserter that asserts a value is an instance of a constructor, throwing an error if it is not
1173
- * @param constructor Constructor to check against
1174
- * @param message Error message
1175
- * @param error Error constructor
1176
- * @returns Asserter
1177
- */
1178
- function assertInstanceOf(constructor, message, error) {
1179
- return (value) => {
1180
- assert(() => value instanceof constructor, message, error);
1181
- };
1182
- }
1183
- /**
1184
- * Creates an asserter that asserts a value is of a specific type, throwing an error if it is not
1185
- * @param condition Type guard function to check the value
1186
- * @param message Error message
1187
- * @param error Error constructor
1188
- * @returns Asserter
1189
- */
1190
- function assertIs(condition, message, error) {
1191
- return (value) => {
1192
- assert(() => condition(value), message, error);
1193
- };
1194
- }
1195
- const MESSAGE_VALUE_DEFINED = "Expected value to be defined";
1196
1290
  function asyncFlow(...fns) {
1197
1291
  assertFlowFunctions(fns);
1198
1292
  return (...args) => asyncWork(args.map((value) => {
@@ -2288,14 +2382,10 @@ function getObserver(first, second, third) {
2288
2382
  }
2289
2383
  const MESSAGE_BEACON = "Cannot retrieve observable from a destroyed beacon";
2290
2384
  const MESSAGE_OBSERVABLE = "Cannot subscribe to a destroyed observable";
2291
- const ALPHA_FULL_HEX_SHORT = "f";
2292
- const ALPHA_FULL_HEX_LONG = `${ALPHA_FULL_HEX_SHORT}${ALPHA_FULL_HEX_SHORT}`;
2293
- const ALPHA_FULL_VALUE = 1;
2294
- const ALPHA_NONE_HEX = "00";
2295
- const ALPHA_NONE_VALUE = 0;
2385
+ const ALPHA_FULL_HEX_LONG = `ff`;
2296
2386
  const DEFAULT_ALPHA = {
2297
2387
  hex: ALPHA_FULL_HEX_LONG,
2298
- value: ALPHA_FULL_VALUE
2388
+ value: 1
2299
2389
  };
2300
2390
  const DEFAULT_HSL = {
2301
2391
  hue: 0,
@@ -2312,8 +2402,6 @@ const EXPRESSION_HEX_SHORT = /^#?([a-f0-9]{3,4})$/i;
2312
2402
  const EXPRESSION_PREFIX = /^#/;
2313
2403
  const HEX_BLACK = "000000";
2314
2404
  const HEX_WHITE = "ffffff";
2315
- const LENGTH_LONG = 6;
2316
- const LENGTH_SHORT = 3;
2317
2405
  const KEYS_HSL = [
2318
2406
  "hue",
2319
2407
  "saturation",
@@ -2326,18 +2414,10 @@ const KEYS_RGB = [
2326
2414
  "blue"
2327
2415
  ];
2328
2416
  const KEYS_RGBA = [...KEYS_RGB, "alpha"];
2329
- const MAX_DEGREE = 360;
2330
- const MAX_HEX = 255;
2331
- const MAX_PERCENT = 100;
2332
- const SRGB_LUMINANCE_BLUE = .0722;
2333
2417
  const SRGB_LUMINANCE_EXPONENT = 2.4;
2334
- const SRGB_LUMINANCE_GREEN = .7152;
2335
- const SRGB_LUMINANCE_MINIMUM = .03928;
2336
2418
  const SRGB_LUMINANCE_MODIFIER = 1.055;
2337
2419
  const SRGB_LUMINANCE_MULTIPLIER = 12.92;
2338
2420
  const SRGB_LUMINANCE_OFFSET = .055;
2339
- const SRGB_LUMINANCE_RED = .2126;
2340
- const SRGB_LUMINANCE_THRESHOLD = .625;
2341
2421
  function formatColor(space, color, alpha) {
2342
2422
  const suffix = alpha ? ` / ${color.alpha}` : "";
2343
2423
  const value = color[space];
@@ -2351,14 +2431,14 @@ function getAlpha(value) {
2351
2431
  if (typeof value === "number") return getAlphaFromValue(value);
2352
2432
  if (typeof value === "string" && value !== ALPHA_FULL_HEX_LONG) return {
2353
2433
  hex: value,
2354
- value: Number.parseInt(value, 16) / MAX_HEX
2434
+ value: Number.parseInt(value, 16) / 255
2355
2435
  };
2356
2436
  return { ...DEFAULT_ALPHA };
2357
2437
  }
2358
2438
  function getAlphaHexadecimal(value) {
2359
- if (value === ALPHA_NONE_VALUE) return ALPHA_NONE_HEX;
2360
- if (value === ALPHA_FULL_VALUE) return ALPHA_FULL_HEX_LONG;
2361
- return Math.round(value * MAX_HEX).toString(16);
2439
+ if (value === 0) return "00";
2440
+ if (value === 1) return ALPHA_FULL_HEX_LONG;
2441
+ return Math.round(value * 255).toString(16);
2362
2442
  }
2363
2443
  function getAlphaFromValue(value) {
2364
2444
  const alpha = getAlphaValue(value);
@@ -2368,18 +2448,18 @@ function getAlphaFromValue(value) {
2368
2448
  };
2369
2449
  }
2370
2450
  function getAlphaValue(original) {
2371
- if (Number.isNaN(original) || original >= MAX_PERCENT || original === ALPHA_FULL_VALUE) return ALPHA_FULL_VALUE;
2372
- if (original < ALPHA_NONE_VALUE) return ALPHA_NONE_VALUE;
2373
- return original <= ALPHA_FULL_VALUE ? original : original / MAX_PERCENT;
2451
+ if (Number.isNaN(original) || original >= 100 || original === 1) return 1;
2452
+ if (original < 0) return 0;
2453
+ return original <= 1 ? original : original / 100;
2374
2454
  }
2375
2455
  function hasKeys(value, keys) {
2376
2456
  return typeof value === "object" && value !== null && keys.every((key) => key in value);
2377
2457
  }
2378
2458
  function isAlpha(value) {
2379
- return typeof value === "number" && between(value, ALPHA_NONE_VALUE, ALPHA_FULL_VALUE);
2459
+ return typeof value === "number" && between(value, 0, 1);
2380
2460
  }
2381
2461
  function isBytey(value) {
2382
- return typeof value === "number" && between(value, 0, MAX_HEX);
2462
+ return typeof value === "number" && between(value, 0, 255);
2383
2463
  }
2384
2464
  /**
2385
2465
  * Is the value a Color?
@@ -2401,7 +2481,7 @@ function isColorValue(obj, properties) {
2401
2481
  return true;
2402
2482
  }
2403
2483
  function isDegree(value) {
2404
- return typeof value === "number" && between(value, 0, MAX_DEGREE);
2484
+ return typeof value === "number" && between(value, 0, 360);
2405
2485
  }
2406
2486
  /**
2407
2487
  * Is the value a hex color?
@@ -2412,7 +2492,7 @@ function isDegree(value) {
2412
2492
  function isHexColor(value, alpha) {
2413
2493
  if (typeof value !== "string") return false;
2414
2494
  if (!(EXPRESSION_HEX_SHORT.test(value) || EXPRESSION_HEX_LONG.test(value))) return false;
2415
- if (alpha === false) return value.length === LENGTH_SHORT || value.length === LENGTH_LONG;
2495
+ if (alpha === false) return value.length === 3 || value.length === 6;
2416
2496
  return true;
2417
2497
  }
2418
2498
  /**
@@ -2454,7 +2534,7 @@ function isRgbLike(value) {
2454
2534
  return hasKeys(value, KEYS_RGB);
2455
2535
  }
2456
2536
  function isPercentage(value) {
2457
- return typeof value === "number" && between(value, 0, MAX_PERCENT);
2537
+ return typeof value === "number" && between(value, 0, 100);
2458
2538
  }
2459
2539
  const validators = {
2460
2540
  alpha: isAlpha,
@@ -2476,17 +2556,17 @@ function getClampedValue(value, minimum, maximum) {
2476
2556
  function getForegroundColor(value) {
2477
2557
  const { blue, green, red } = getState(value).rgb;
2478
2558
  const values = [
2479
- blue / MAX_HEX,
2480
- green / MAX_HEX,
2481
- red / MAX_HEX
2559
+ blue / 255,
2560
+ green / 255,
2561
+ red / 255
2482
2562
  ];
2483
2563
  const { length } = values;
2484
2564
  for (let index = 0; index < length; index += 1) {
2485
2565
  const color = values[index];
2486
- if (color <= SRGB_LUMINANCE_MINIMUM) values[index] /= SRGB_LUMINANCE_MULTIPLIER;
2566
+ if (color <= .03928) values[index] /= SRGB_LUMINANCE_MULTIPLIER;
2487
2567
  else values[index] = ((color + SRGB_LUMINANCE_OFFSET) / SRGB_LUMINANCE_MODIFIER) ** SRGB_LUMINANCE_EXPONENT;
2488
2568
  }
2489
- return new Color(SRGB_LUMINANCE_RED * values[2] + SRGB_LUMINANCE_GREEN * values[1] + SRGB_LUMINANCE_BLUE * values[0] > SRGB_LUMINANCE_THRESHOLD ? HEX_BLACK : HEX_WHITE);
2569
+ return new Color(.2126 * values[2] + .7152 * values[1] + .0722 * values[0] > .625 ? HEX_BLACK : HEX_WHITE);
2490
2570
  }
2491
2571
  /**
2492
2572
  * Get the hex color _(with alpha channel)_ from any kind of value
@@ -2506,10 +2586,10 @@ function getHexColor(value) {
2506
2586
  return getState(value).hex;
2507
2587
  }
2508
2588
  function getHexValue(value) {
2509
- return getClampedValue(value, 0, MAX_HEX);
2589
+ return getClampedValue(value, 0, 255);
2510
2590
  }
2511
2591
  function getDegrees(value) {
2512
- return getClampedValue(value, 0, MAX_DEGREE);
2592
+ return getClampedValue(value, 0, 360);
2513
2593
  }
2514
2594
  /**
2515
2595
  * Get the HSLA color from any kind of value
@@ -2532,7 +2612,7 @@ function getHslColor(value) {
2532
2612
  return getState(value).hsl;
2533
2613
  }
2534
2614
  function getPercentage(value) {
2535
- return getClampedValue(value, 0, MAX_PERCENT);
2615
+ return getClampedValue(value, 0, 100);
2536
2616
  }
2537
2617
  /**
2538
2618
  * Get the RGBA color from any kind of value
@@ -2569,9 +2649,9 @@ function convertRgbToHex(rgb, alpha) {
2569
2649
  }
2570
2650
  function convertRgbToHsla(value) {
2571
2651
  const rgb = isRgbLike(value) ? getRgbValue(value) : { ...DEFAULT_RGB };
2572
- const blue = rgb.blue / MAX_HEX;
2573
- const green = rgb.green / MAX_HEX;
2574
- const red = rgb.red / MAX_HEX;
2652
+ const blue = rgb.blue / 255;
2653
+ const green = rgb.green / 255;
2654
+ const red = rgb.red / 255;
2575
2655
  const maxHex = Math.max(blue, green, red);
2576
2656
  const minHex = Math.min(blue, green, red);
2577
2657
  const delta = maxHex - minHex;
@@ -2594,10 +2674,10 @@ function convertRgbToHsla(value) {
2594
2674
  hue *= 60;
2595
2675
  }
2596
2676
  return {
2597
- alpha: getAlphaValue(value.alpha ?? ALPHA_FULL_VALUE),
2677
+ alpha: getAlphaValue(value.alpha ?? 1),
2598
2678
  hue: +hue.toFixed(2),
2599
- lightness: +(lightness * MAX_PERCENT).toFixed(2),
2600
- saturation: +(saturation * MAX_PERCENT).toFixed(2)
2679
+ lightness: +(lightness * 100).toFixed(2),
2680
+ saturation: +(saturation * 100).toFixed(2)
2601
2681
  };
2602
2682
  }
2603
2683
  function getRgbValue(value) {
@@ -2648,7 +2728,7 @@ function convertHexToRgba(value) {
2648
2728
  const { length } = pairs;
2649
2729
  for (let index = 1; index < length; index += 1) values.push(Number.parseInt(pairs[index], 16));
2650
2730
  return {
2651
- alpha: values[3] / MAX_HEX,
2731
+ alpha: values[3] / 255,
2652
2732
  blue: values[2],
2653
2733
  green: values[1],
2654
2734
  red: values[0]
@@ -2664,8 +2744,8 @@ function getNormalizedHex(value, alpha) {
2664
2744
  const includeAlpha = alpha ?? false;
2665
2745
  if (!isHexColor(value)) return `${HEX_BLACK}${includeAlpha ? ALPHA_FULL_HEX_LONG : ""}`;
2666
2746
  const normalized = value.replace(EXPRESSION_PREFIX, "");
2667
- if (normalized.length < LENGTH_LONG) return join(`${normalized.slice(0, LENGTH_SHORT)}${includeAlpha ? normalized[LENGTH_SHORT] ?? ALPHA_FULL_HEX_SHORT : ""}`.split("").map((character) => character.repeat(2)));
2668
- return `${normalized.slice(0, LENGTH_LONG)}${includeAlpha ? normalized.slice(LENGTH_LONG) || ALPHA_FULL_HEX_LONG : ""}`;
2747
+ if (normalized.length < 6) return join(`${normalized.slice(0, 3)}${includeAlpha ? normalized[3] ?? "f" : ""}`.split("").map((character) => character.repeat(2)));
2748
+ return `${normalized.slice(0, 6)}${includeAlpha ? normalized.slice(6) || ALPHA_FULL_HEX_LONG : ""}`;
2669
2749
  }
2670
2750
  function hexToHsl(value) {
2671
2751
  const { hue, lightness, saturation } = hexToHsla(value);
@@ -2701,11 +2781,11 @@ function hexToRgba(value) {
2701
2781
  }
2702
2782
  function convertHslToRgba(value) {
2703
2783
  const hsl = isHslLike(value) ? getHslValue(value) : { ...DEFAULT_HSL };
2704
- const hue = hsl.hue % MAX_DEGREE;
2705
- const saturation = hsl.saturation / MAX_PERCENT;
2706
- const lightness = hsl.lightness / MAX_PERCENT;
2784
+ const hue = hsl.hue % 360;
2785
+ const saturation = hsl.saturation / 100;
2786
+ const lightness = hsl.lightness / 100;
2707
2787
  return {
2708
- alpha: getAlphaValue(value.alpha ?? ALPHA_FULL_VALUE),
2788
+ alpha: getAlphaValue(value.alpha ?? 1),
2709
2789
  blue: getHexValue(Math.round(getHexyValue(hue, lightness, saturation, 4))),
2710
2790
  green: getHexValue(Math.round(getHexyValue(hue, lightness, saturation, 8))),
2711
2791
  red: getHexValue(Math.round(getHexyValue(hue, lightness, saturation, 0)))
@@ -2713,7 +2793,7 @@ function convertHslToRgba(value) {
2713
2793
  }
2714
2794
  function getHexyValue(hue, lightness, saturation, value) {
2715
2795
  const part = (value + hue / 30) % 12;
2716
- return (lightness - saturation * Math.min(lightness, 1 - lightness) * Math.max(-1, Math.min(part - 3, 9 - part, 1))) * MAX_HEX;
2796
+ return (lightness - saturation * Math.min(lightness, 1 - lightness) * Math.max(-1, Math.min(part - 3, 9 - part, 1))) * 255;
2717
2797
  }
2718
2798
  function getHslValue(value) {
2719
2799
  return {
@@ -2753,12 +2833,12 @@ function hslToRgba(hsl) {
2753
2833
  function getState(value) {
2754
2834
  if (typeof value === "string") {
2755
2835
  const normalized = getNormalizedHex(value, true);
2756
- const hex = normalized.slice(0, LENGTH_LONG);
2836
+ const hex = normalized.slice(0, 6);
2757
2837
  const rgb = hexToRgb(hex);
2758
2838
  return {
2759
2839
  hex,
2760
2840
  rgb,
2761
- alpha: getAlpha(normalized.slice(LENGTH_LONG)),
2841
+ alpha: getAlpha(normalized.slice(6)),
2762
2842
  hsl: rgbToHsl(rgb)
2763
2843
  };
2764
2844
  }
@@ -2784,7 +2864,7 @@ function getState(value) {
2784
2864
  return state;
2785
2865
  }
2786
2866
  }
2787
- state.alpha ??= getAlpha(ALPHA_FULL_VALUE);
2867
+ state.alpha ??= getAlpha(1);
2788
2868
  state.hex ??= String(HEX_BLACK);
2789
2869
  state.hsl ??= { ...DEFAULT_HSL };
2790
2870
  state.rgb ??= { ...DEFAULT_RGB };
@@ -2793,12 +2873,12 @@ function getState(value) {
2793
2873
  function setHexColor(state, value, alpha) {
2794
2874
  if (!isHexColor(value) || !alpha && value === state.hex) return;
2795
2875
  const normalized = getNormalizedHex(value, true);
2796
- const hex = normalized.slice(0, LENGTH_LONG);
2876
+ const hex = normalized.slice(0, 6);
2797
2877
  const rgb = hexToRgb(hex);
2798
2878
  state.hex = hex;
2799
2879
  state.hsl = rgbToHsl(rgb);
2800
2880
  state.rgb = rgb;
2801
- if (alpha) state.alpha = getAlpha(normalized.slice(LENGTH_LONG));
2881
+ if (alpha) state.alpha = getAlpha(normalized.slice(6));
2802
2882
  }
2803
2883
  function setHSLColor(state, value, alpha) {
2804
2884
  if (!isHslLike(value)) return;
@@ -3195,6 +3275,105 @@ function roundNumber(callback, value, decimals) {
3195
3275
  function sum(array, key) {
3196
3276
  return getAggregated("sum", array, key);
3197
3277
  }
3278
+ async function asyncMatchResult(result, first, error) {
3279
+ let value;
3280
+ if (typeof result === "function") value = await result();
3281
+ else if (result instanceof Promise) value = await result;
3282
+ else value = result;
3283
+ if (!isResult(value)) throw new Error(MESSAGE_RESULT);
3284
+ const hasObj = typeof first === "object" && first !== null;
3285
+ const okHandler = hasObj ? first.ok : first;
3286
+ const errorHandler = hasObj ? first.error : error;
3287
+ if (isOk(value)) return okHandler(value.value);
3288
+ return errorHandler(value.error, value.original);
3289
+ }
3290
+ function matchResult(result, first, error) {
3291
+ const value = typeof result === "function" ? result() : result;
3292
+ if (!isResult(value)) throw new Error(MESSAGE_RESULT);
3293
+ const hasObj = typeof first === "object" && first !== null;
3294
+ const okHandler = hasObj ? first.ok : first;
3295
+ const errorHandler = hasObj ? first.error : error;
3296
+ if (isOk(value)) return okHandler(value.value);
3297
+ return errorHandler(value.error, value.original);
3298
+ }
3299
+ matchResult.async = asyncMatchResult;
3300
+ const MESSAGE_RESULT = "`result.match` expected a Result or a function that returns a Result";
3301
+ function error(value, original) {
3302
+ return getError(value, original);
3303
+ }
3304
+ function getError(value, original) {
3305
+ const errorResult = {
3306
+ error: value,
3307
+ ok: false
3308
+ };
3309
+ if (original instanceof Error) errorResult.original = original;
3310
+ return errorResult;
3311
+ }
3312
+ /**
3313
+ * Creates an ok result
3314
+ * @param value Value
3315
+ * @returns Ok result
3316
+ */
3317
+ function ok(value) {
3318
+ return {
3319
+ ok: true,
3320
+ value
3321
+ };
3322
+ }
3323
+ /**
3324
+ * Converts a result to a promise
3325
+ *
3326
+ * Resolves if ok, rejects for error
3327
+ * @param result Result to convert
3328
+ * @returns Promised result
3329
+ */
3330
+ async function toPromise(result) {
3331
+ const actual = typeof result === "function" ? result() : result;
3332
+ if (!isResult(actual)) return Promise.reject(new Error(MESSAGE_PROMISE_RESULT));
3333
+ return isOk(actual) ? Promise.resolve(actual.value) : Promise.reject(actual.error);
3334
+ }
3335
+ function unwrap(value, defaultValue) {
3336
+ return isOk(value) ? value.value : defaultValue;
3337
+ }
3338
+ const MESSAGE_PROMISE_RESULT = "toPromise expected to receive a Result";
3339
+ function attemptAsyncFlow(...fns) {
3340
+ let Flow;
3341
+ return (...args) => attempt.async(() => {
3342
+ Flow ??= flow.async(...fns);
3343
+ return Flow(...args.map((value) => {
3344
+ if (isError(value)) throw value.error;
3345
+ return isOk(value) ? value.value : value;
3346
+ }));
3347
+ });
3348
+ }
3349
+ function attemptFlow(...fns) {
3350
+ let Flow;
3351
+ return (...args) => attempt(() => {
3352
+ Flow ??= flow(...fns);
3353
+ return Flow(...args.map((value) => {
3354
+ if (isError(value)) throw value.error;
3355
+ return isOk(value) ? value.value : value;
3356
+ }));
3357
+ });
3358
+ }
3359
+ attemptFlow.async = attemptAsyncFlow;
3360
+ async function attemptAsyncPipe(initial, first, ...seconds) {
3361
+ return attempt.async(() => {
3362
+ if (isError(initial)) throw initial.error;
3363
+ const value = typeof initial === "function" ? initial() : isOk(initial) ? initial.value : initial;
3364
+ if (first == null) return value;
3365
+ return pipe.async(value, ...[first, ...seconds]);
3366
+ });
3367
+ }
3368
+ function attemptPipe(initial, first, ...seconds) {
3369
+ return attempt(() => {
3370
+ if (isError(initial)) throw initial.error;
3371
+ const value = typeof initial === "function" ? initial() : isOk(initial) ? initial.value : initial;
3372
+ if (first == null) return value;
3373
+ return pipe(value, ...[first, ...seconds]);
3374
+ });
3375
+ }
3376
+ attemptPipe.async = attemptAsyncPipe;
3198
3377
  var CancelablePromise = class extends Promise {
3199
3378
  #rejector;
3200
3379
  constructor(executor) {
@@ -3231,6 +3410,60 @@ const PROMISE_STRATEGY_ALL = new Set(["complete", "first"]);
3231
3410
  const PROMISE_STRATEGY_DEFAULT = "complete";
3232
3411
  const PROMISE_TYPE_FULFILLED = "fulfilled";
3233
3412
  const PROMISE_TYPE_REJECTED = "rejected";
3413
+ /**
3414
+ * Create a cancelable promise
3415
+ * @param executor Executor function for the promise
3416
+ * @returns Cancelable promise
3417
+ */
3418
+ function cancelable(executor) {
3419
+ return new CancelablePromise(executor);
3420
+ }
3421
+ function handleResult(status, parameters) {
3422
+ const { abort, complete, data, handlers, index, signal, value } = parameters;
3423
+ if (signal?.aborted ?? false) return;
3424
+ if (!complete && status === "rejected") {
3425
+ settlePromise(abort, handlers.reject, value, signal);
3426
+ return;
3427
+ }
3428
+ data.result[index] = !complete ? value : status === "fulfilled" ? {
3429
+ status,
3430
+ value
3431
+ } : {
3432
+ status,
3433
+ reason: value
3434
+ };
3435
+ if (index === data.last) settlePromise(abort, handlers.resolve, data.result, signal);
3436
+ }
3437
+ function settlePromise(aborter, settler, value, signal) {
3438
+ signal?.removeEventListener(PROMISE_EVENT_NAME, aborter);
3439
+ settler(value);
3440
+ }
3441
+ async function toResult(value) {
3442
+ const actual = typeof value === "function" ? value() : value;
3443
+ if (!(actual instanceof Promise)) return Promise.reject(new TypeError(PROMISE_MESSAGE_EXPECTATION_RESULT));
3444
+ return actual.then((result) => ok(result)).catch((reason) => error(reason));
3445
+ }
3446
+ async function asyncAttempt(value, err) {
3447
+ try {
3448
+ let result = typeof value === "function" ? value() : await value;
3449
+ if (result instanceof Promise) result = await result;
3450
+ return ok(result);
3451
+ } catch (thrown) {
3452
+ return getError(err ?? thrown, err == null ? void 0 : thrown);
3453
+ }
3454
+ }
3455
+ function attempt(callback, err) {
3456
+ try {
3457
+ return ok(callback());
3458
+ } catch (thrown) {
3459
+ return getError(err ?? thrown, err == null ? void 0 : thrown);
3460
+ }
3461
+ }
3462
+ attempt.async = asyncAttempt;
3463
+ attempt.flow = attemptFlow;
3464
+ attempt.match = matchResult;
3465
+ attempt.pipe = attemptPipe;
3466
+ attempt.promise = attemptPromise;
3234
3467
  function getNumberOrDefault$1(value) {
3235
3468
  return typeof value === "number" && value > 0 ? value : 0;
3236
3469
  }
@@ -3258,6 +3491,9 @@ function getPromisesOptions(input) {
3258
3491
  strategy: getStrategyOrDefault(options.strategy)
3259
3492
  };
3260
3493
  }
3494
+ function getResultsFromPromises(promised) {
3495
+ return promised.map((result) => isFulfilled(result) ? ok(result.value) : error(result.reason));
3496
+ }
3261
3497
  function getStrategyOrDefault(value) {
3262
3498
  return PROMISE_STRATEGY_ALL.has(value) ? value : PROMISE_STRATEGY_DEFAULT;
3263
3499
  }
@@ -3280,77 +3516,6 @@ function isRejected(value) {
3280
3516
  function isType(value, type) {
3281
3517
  return typeof value === "object" && value !== null && value.status === type;
3282
3518
  }
3283
- function error(value, original) {
3284
- return getError(value, original);
3285
- }
3286
- function getError(value, original) {
3287
- const errorResult = {
3288
- error: value,
3289
- ok: false
3290
- };
3291
- if (original instanceof Error) errorResult.original = original;
3292
- return errorResult;
3293
- }
3294
- /**
3295
- * Creates an ok result
3296
- * @param value Value
3297
- * @returns Ok result
3298
- */
3299
- function ok(value) {
3300
- return {
3301
- ok: true,
3302
- value
3303
- };
3304
- }
3305
- /**
3306
- * Converts a result to a promise
3307
- *
3308
- * Resolves if ok, rejects for error
3309
- * @param result Result to convert
3310
- * @returns Promised result
3311
- */
3312
- async function toPromise(result) {
3313
- const actual = typeof result === "function" ? result() : result;
3314
- if (!isResult(actual)) return Promise.reject(new Error(MESSAGE_PROMISE_RESULT));
3315
- return isOk(actual) ? Promise.resolve(actual.value) : Promise.reject(actual.error);
3316
- }
3317
- function unwrap(value, defaultValue) {
3318
- return isOk(value) ? value.value : defaultValue;
3319
- }
3320
- const MESSAGE_PROMISE_RESULT = "toPromise expected to receive a Result";
3321
- /**
3322
- * Create a cancelable promise
3323
- * @param executor Executor function for the promise
3324
- * @returns Cancelable promise
3325
- */
3326
- function cancelable(executor) {
3327
- return new CancelablePromise(executor);
3328
- }
3329
- function handleResult(status, parameters) {
3330
- const { abort, complete, data, handlers, index, signal, value } = parameters;
3331
- if (signal?.aborted ?? false) return;
3332
- if (!complete && status === PROMISE_TYPE_REJECTED) {
3333
- settlePromise(abort, handlers.reject, value, signal);
3334
- return;
3335
- }
3336
- data.result[index] = !complete ? value : status === PROMISE_TYPE_FULFILLED ? {
3337
- status,
3338
- value
3339
- } : {
3340
- status,
3341
- reason: value
3342
- };
3343
- if (index === data.last) settlePromise(abort, handlers.resolve, data.result, signal);
3344
- }
3345
- function settlePromise(aborter, settler, value, signal) {
3346
- signal?.removeEventListener(PROMISE_EVENT_NAME, aborter);
3347
- settler(value);
3348
- }
3349
- async function toResult(value) {
3350
- const actual = typeof value === "function" ? value() : value;
3351
- if (!(actual instanceof Promise)) return Promise.reject(new TypeError(PROMISE_MESSAGE_EXPECTATION_RESULT));
3352
- return actual.then((result) => ok(result)).catch((reason) => error(reason));
3353
- }
3354
3519
  async function getTimedPromise(promise, time, signal) {
3355
3520
  function abort() {
3356
3521
  timer.cancel();
@@ -3427,7 +3592,7 @@ async function promises(items, options) {
3427
3592
  if (!Array.isArray(items)) return Promise.reject(new TypeError(PROMISE_MESSAGE_EXPECTATION_PROMISES));
3428
3593
  const actual = items.filter((item) => item instanceof Promise);
3429
3594
  const { length } = actual;
3430
- if (length === 0) return actual;
3595
+ if (length === 0) return Promise.reject(new TypeError(PROMISE_MESSAGE_EXPECTATION_PROMISES));
3431
3596
  const complete = strategy === PROMISE_STRATEGY_DEFAULT;
3432
3597
  function abort() {
3433
3598
  handlers.reject(signal.reason);
@@ -3462,6 +3627,10 @@ async function promises(items, options) {
3462
3627
  }));
3463
3628
  });
3464
3629
  }
3630
+ promises.result = resultPromises;
3631
+ async function resultPromises(items, signal) {
3632
+ return promises(items, signal).then(getResultsFromPromises);
3633
+ }
3465
3634
  /**
3466
3635
  * Convert a query string to a plain _(nested)_ object
3467
3636
  * @param query Query string to convert
@@ -3789,88 +3958,6 @@ const ALPHABET = "abcdefghijklmnopqrstuvwxyz";
3789
3958
  const BOOLEAN_MODIFIER = .5;
3790
3959
  const HEX_CHARACTERS = "0123456789ABCDEF";
3791
3960
  const HEX_MAXIMUM = 15;
3792
- async function asyncMatchResult(result, first, error) {
3793
- let value;
3794
- if (typeof result === "function") value = await result();
3795
- else if (result instanceof Promise) value = await result;
3796
- else value = result;
3797
- if (!isResult(value)) throw new Error(MESSAGE_RESULT);
3798
- const hasObj = typeof first === "object" && first !== null;
3799
- const okHandler = hasObj ? first.ok : first;
3800
- const errorHandler = hasObj ? first.error : error;
3801
- if (isOk(value)) return okHandler(value.value);
3802
- return errorHandler(value.error, value.original);
3803
- }
3804
- function matchResult(result, first, error) {
3805
- const value = typeof result === "function" ? result() : result;
3806
- if (!isResult(value)) throw new Error(MESSAGE_RESULT);
3807
- const hasObj = typeof first === "object" && first !== null;
3808
- const okHandler = hasObj ? first.ok : first;
3809
- const errorHandler = hasObj ? first.error : error;
3810
- if (isOk(value)) return okHandler(value.value);
3811
- return errorHandler(value.error, value.original);
3812
- }
3813
- matchResult.async = asyncMatchResult;
3814
- const MESSAGE_RESULT = "`result.match` expected a Result or a function that returns a Result";
3815
- function attemptAsyncFlow(...fns) {
3816
- let Flow;
3817
- return (...args) => attempt.async(() => {
3818
- Flow ??= flow.async(...fns);
3819
- return Flow(...args.map((value) => {
3820
- if (isError(value)) throw value.error;
3821
- return isOk(value) ? value.value : value;
3822
- }));
3823
- });
3824
- }
3825
- function attemptFlow(...fns) {
3826
- let Flow;
3827
- return (...args) => attempt(() => {
3828
- Flow ??= flow(...fns);
3829
- return Flow(...args.map((value) => {
3830
- if (isError(value)) throw value.error;
3831
- return isOk(value) ? value.value : value;
3832
- }));
3833
- });
3834
- }
3835
- attemptFlow.async = attemptAsyncFlow;
3836
- async function attemptAsyncPipe(initial, first, ...seconds) {
3837
- return attempt.async(() => {
3838
- if (isError(initial)) throw initial.error;
3839
- const value = typeof initial === "function" ? initial() : isOk(initial) ? initial.value : initial;
3840
- if (first == null) return value;
3841
- return pipe.async(value, ...[first, ...seconds]);
3842
- });
3843
- }
3844
- function attemptPipe(initial, first, ...seconds) {
3845
- return attempt(() => {
3846
- if (isError(initial)) throw initial.error;
3847
- const value = typeof initial === "function" ? initial() : isOk(initial) ? initial.value : initial;
3848
- if (first == null) return value;
3849
- return pipe(value, ...[first, ...seconds]);
3850
- });
3851
- }
3852
- attemptPipe.async = attemptAsyncPipe;
3853
- async function asyncAttempt(value, err) {
3854
- try {
3855
- let result = typeof value === "function" ? value() : await value;
3856
- if (result instanceof Promise) result = await result;
3857
- return ok(result);
3858
- } catch (thrown) {
3859
- return getError(err ?? thrown, err == null ? void 0 : thrown);
3860
- }
3861
- }
3862
- function attempt(callback, err) {
3863
- try {
3864
- return ok(callback());
3865
- } catch (thrown) {
3866
- return getError(err ?? thrown, err == null ? void 0 : thrown);
3867
- }
3868
- }
3869
- attempt.async = asyncAttempt;
3870
- attempt.flow = attemptFlow;
3871
- attempt.match = matchResult;
3872
- attempt.pipe = attemptPipe;
3873
- attempt.promise = attemptPromise;
3874
3961
  /**
3875
3962
  * - A Set with a maximum size
3876
3963
  * - Behavior is similar to a _LRU_-cache, where the oldest values are removed
@@ -3923,4 +4010,4 @@ var SizedSet = class extends Set {
3923
4010
  }
3924
4011
  }
3925
4012
  };
3926
- export { CancelablePromise, PromiseTimeoutError, QueueError, RetryError, SizedMap, SizedSet, attempt, attemptPromise, average, beacon, between, camelCase, cancelable, capitalize, ceil, chunk, clamp, clone, compact, compare, count, debounce, delay, diff, difference, drop, endsWith, equal, error, exists, filter, find, flatten, floor, flow, toResult as fromPromise, toResult, fromQuery, toPromise as fromResult, toPromise, getArray, getColor, getForegroundColor, getHexColor, getHexaColor, getHslColor, getHslaColor, getNormalizedHex, getNumber, getRandomBoolean, getRandomCharacters, getRandomColor, getRandomFloat, getRandomHex, getRandomInteger, getRandomItem, getRandomItems, getRgbColor, getRgbaColor, getString, getUuid, getValue, groupBy, hasValue, hexToHsl, hexToHsla, hexToRgb, hexToRgba, hslToHex, hslToRgb, hslToRgba, ignoreKey, includes, indexOf, insert, intersection, isArrayOrPlainObject, isColor, isConstructor, isEmpty, isError, isFulfilled, isHexColor, isHslColor, isHslLike, isHslaColor, isInstanceOf, isKey, isNonNullable, isNullable, isNullableOrEmpty, isNullableOrWhitespace, isNumber, isNumerical, isObject, isOk, isPlainObject, isPrimitive, isRejected, isResult, isRgbColor, isRgbLike, isRgbaColor, isTypedArray, join, kebabCase, logger, lowerCase, max, median, memoize, merge, min, noop, ok, omit, parse, partition, pascalCase, pick, pipe, promises, push, queue, range, retry, rgbToHex, rgbToHsl, rgbToHsla, round, select, setValue, shuffle, slice, smush, snakeCase, sort, splice, startsWith, sum, take, template, throttle, timed, times, titleCase, toMap, toQuery, toRecord, toSet, toggle, trim, truncate, tryDecode, tryEncode, union, unique, unsmush, unwrap, update, upperCase, words };
4013
+ export { CancelablePromise, PromiseTimeoutError, QueueError, RetryError, SizedMap, SizedSet, attempt, attemptPromise, average, beacon, between, camelCase, cancelable, capitalize, ceil, chunk, clamp, clone, compact, compare, count, debounce, delay, diff, difference, drop, endsWith, equal, error, exists, filter, find, flatten, floor, flow, toResult as fromPromise, toResult, fromQuery, toPromise as fromResult, toPromise, getArray, getColor, getForegroundColor, getHexColor, getHexaColor, getHslColor, getHslaColor, getNormalizedHex, getNumber, getRandomBoolean, getRandomCharacters, getRandomColor, getRandomFloat, getRandomHex, getRandomInteger, getRandomItem, getRandomItems, getRgbColor, getRgbaColor, getString, getUuid, getValue, groupBy, hasValue, hexToHsl, hexToHsla, hexToRgb, hexToRgba, hslToHex, hslToRgb, hslToRgba, ignoreKey, includes, indexOf, insert, intersection, isArrayOrPlainObject, isColor, isConstructor, isEmpty, isError, isFulfilled, isHexColor, isHslColor, isHslLike, isHslaColor, isInstanceOf, isKey, isNonNullable, isNullable, isNullableOrEmpty, isNullableOrWhitespace, isNumber, isNumerical, isObject, isOk, isPlainObject, isPrimitive, isRejected, isResult, isRgbColor, isRgbLike, isRgbaColor, isTypedArray, join, kebabCase, logger, lowerCase, max, median, memoize, merge, min, noop, ok, omit, once, parse, partition, pascalCase, pick, pipe, promises, push, queue, range, retry, rgbToHex, rgbToHsl, rgbToHsla, round, select, setValue, shuffle, slice, smush, snakeCase, sort, splice, startsWith, sum, take, template, throttle, timed, times, titleCase, toMap, toQuery, toRecord, toSet, toggle, trim, truncate, tryDecode, tryEncode, union, unique, unsmush, unwrap, update, upperCase, words };