@oscarpalmer/atoms 0.193.0 → 0.194.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.
Files changed (204) hide show
  1. package/dist/array/difference.mjs +2 -2
  2. package/dist/array/intersection.mjs +2 -2
  3. package/dist/array/match.mjs +13 -13
  4. package/dist/array/slice.mjs +5 -5
  5. package/dist/array/sort.d.mts +5 -1
  6. package/dist/array/sort.mjs +4 -2
  7. package/dist/array/union.mjs +2 -2
  8. package/dist/beacon.d.mts +8 -1
  9. package/dist/beacon.mjs +52 -60
  10. package/dist/color/constants.d.mts +1 -1
  11. package/dist/color/constants.mjs +3 -5
  12. package/dist/color/instance.mjs +34 -41
  13. package/dist/color/misc/format.d.mts +3 -2
  14. package/dist/color/misc/format.mjs +4 -1
  15. package/dist/color/misc/is.d.mts +9 -1
  16. package/dist/color/misc/is.mjs +11 -1
  17. package/dist/color/misc/state.d.mts +6 -6
  18. package/dist/color/misc/state.mjs +11 -14
  19. package/dist/color/models.d.mts +23 -68
  20. package/dist/function/assert.mjs +2 -2
  21. package/dist/function/limit.d.mts +0 -6
  22. package/dist/function/limit.mjs +2 -2
  23. package/dist/function/memoize.mjs +19 -32
  24. package/dist/function/once.d.mts +0 -3
  25. package/dist/function/once.mjs +16 -13
  26. package/dist/function/retry.d.mts +1 -24
  27. package/dist/function/retry.mjs +1 -1
  28. package/dist/function/work.mjs +13 -11
  29. package/dist/herald.d.mts +30 -31
  30. package/dist/herald.mjs +74 -56
  31. package/dist/index.d.mts +100 -185
  32. package/dist/index.mjs +680 -702
  33. package/dist/internal/abort.d.mts +10 -0
  34. package/dist/internal/abort.mjs +14 -0
  35. package/dist/internal/array/chunk.mjs +2 -2
  36. package/dist/internal/array/find.mjs +2 -2
  37. package/dist/internal/array/sets.d.mts +4 -4
  38. package/dist/internal/array/sets.mjs +7 -7
  39. package/dist/internal/function/timer.mjs +19 -15
  40. package/dist/internal/number.mjs +7 -7
  41. package/dist/internal/result.mjs +3 -3
  42. package/dist/internal/sized.mjs +4 -4
  43. package/dist/internal/string.mjs +4 -4
  44. package/dist/internal/subscription.d.mts +24 -8
  45. package/dist/internal/subscription.mjs +49 -36
  46. package/dist/internal/value/equal.mjs +6 -6
  47. package/dist/internal/value/misc.mjs +14 -14
  48. package/dist/internal/value/set.mjs +2 -2
  49. package/dist/logger.mjs +15 -39
  50. package/dist/promise/constants.d.mts +17 -0
  51. package/dist/promise/constants.mjs +14 -0
  52. package/dist/promise/delay.mjs +7 -10
  53. package/dist/promise/helpers.mjs +1 -1
  54. package/dist/promise/index.mjs +14 -17
  55. package/dist/promise/misc.d.mts +2 -1
  56. package/dist/promise/misc.mjs +8 -7
  57. package/dist/promise/models.d.mts +4 -16
  58. package/dist/promise/models.mjs +4 -13
  59. package/dist/promise/timed.mjs +9 -10
  60. package/dist/query.mjs +15 -15
  61. package/dist/queue.mjs +103 -116
  62. package/dist/random.mjs +7 -7
  63. package/dist/result/index.d.mts +0 -3
  64. package/dist/result/index.mjs +1 -1
  65. package/dist/result/match.d.mts +0 -3
  66. package/dist/result/match.mjs +4 -4
  67. package/dist/result/misc.mjs +2 -2
  68. package/dist/result/work/flow.d.mts +0 -3
  69. package/dist/result/work/flow.mjs +5 -5
  70. package/dist/result/work/pipe.d.mts +0 -3
  71. package/dist/result/work/pipe.mjs +3 -3
  72. package/dist/string/case.mjs +20 -20
  73. package/dist/string/fuzzy.mjs +23 -18
  74. package/dist/string/index.mjs +7 -7
  75. package/dist/string/normalize.mjs +14 -14
  76. package/dist/string/template.mjs +2 -2
  77. package/dist/value/clone.mjs +10 -10
  78. package/dist/value/smush.mjs +2 -2
  79. package/package.json +13 -5
  80. package/src/array/difference.ts +0 -73
  81. package/src/array/exists.ts +0 -93
  82. package/src/array/filter.ts +0 -182
  83. package/src/array/find.ts +0 -183
  84. package/src/array/first.ts +0 -196
  85. package/src/array/flatten.ts +0 -20
  86. package/src/array/from.ts +0 -129
  87. package/src/array/get.ts +0 -131
  88. package/src/array/group-by.ts +0 -369
  89. package/src/array/index.ts +0 -26
  90. package/src/array/insert.ts +0 -52
  91. package/src/array/intersection.ts +0 -72
  92. package/src/array/last.ts +0 -194
  93. package/src/array/match.ts +0 -436
  94. package/src/array/move.ts +0 -315
  95. package/src/array/partition.ts +0 -91
  96. package/src/array/push.ts +0 -23
  97. package/src/array/reverse.ts +0 -33
  98. package/src/array/select.ts +0 -260
  99. package/src/array/single.ts +0 -93
  100. package/src/array/slice.ts +0 -335
  101. package/src/array/sort.ts +0 -607
  102. package/src/array/splice.ts +0 -106
  103. package/src/array/swap.ts +0 -322
  104. package/src/array/to-map.ts +0 -371
  105. package/src/array/to-record.ts +0 -351
  106. package/src/array/to-set.ts +0 -80
  107. package/src/array/toggle.ts +0 -79
  108. package/src/array/union.ts +0 -72
  109. package/src/array/unique.ts +0 -67
  110. package/src/array/update.ts +0 -75
  111. package/src/beacon.ts +0 -378
  112. package/src/color/constants.ts +0 -137
  113. package/src/color/index.ts +0 -83
  114. package/src/color/instance.ts +0 -162
  115. package/src/color/misc/alpha.ts +0 -56
  116. package/src/color/misc/format.ts +0 -29
  117. package/src/color/misc/get.ts +0 -210
  118. package/src/color/misc/is.ts +0 -221
  119. package/src/color/misc/state.ts +0 -243
  120. package/src/color/models.ts +0 -389
  121. package/src/color/space/hex.ts +0 -184
  122. package/src/color/space/hsl.ts +0 -174
  123. package/src/color/space/hwb.ts +0 -153
  124. package/src/color/space/rgb.ts +0 -240
  125. package/src/function/assert.ts +0 -174
  126. package/src/function/index.ts +0 -2
  127. package/src/function/limit.ts +0 -83
  128. package/src/function/memoize.ts +0 -202
  129. package/src/function/once.ts +0 -200
  130. package/src/function/retry.ts +0 -175
  131. package/src/function/work.ts +0 -1007
  132. package/src/herald.ts +0 -216
  133. package/src/index.ts +0 -68
  134. package/src/internal/array/callbacks.ts +0 -46
  135. package/src/internal/array/chunk.ts +0 -51
  136. package/src/internal/array/compact.ts +0 -56
  137. package/src/internal/array/find.ts +0 -200
  138. package/src/internal/array/group.ts +0 -42
  139. package/src/internal/array/index-of.ts +0 -182
  140. package/src/internal/array/insert.ts +0 -80
  141. package/src/internal/array/overlap.ts +0 -35
  142. package/src/internal/array/sets.ts +0 -74
  143. package/src/internal/array/shuffle.ts +0 -33
  144. package/src/internal/array/update.ts +0 -52
  145. package/src/internal/function/misc.ts +0 -8
  146. package/src/internal/function/timer.ts +0 -168
  147. package/src/internal/is.ts +0 -244
  148. package/src/internal/math/aggregate.ts +0 -164
  149. package/src/internal/math/misc.ts +0 -28
  150. package/src/internal/number.ts +0 -129
  151. package/src/internal/random.ts +0 -49
  152. package/src/internal/result.ts +0 -92
  153. package/src/internal/sized.ts +0 -25
  154. package/src/internal/string.ts +0 -128
  155. package/src/internal/subscription.ts +0 -264
  156. package/src/internal/value/compare.ts +0 -170
  157. package/src/internal/value/equal.ts +0 -465
  158. package/src/internal/value/get.ts +0 -57
  159. package/src/internal/value/handlers.ts +0 -95
  160. package/src/internal/value/has.ts +0 -118
  161. package/src/internal/value/misc.ts +0 -125
  162. package/src/internal/value/partial.ts +0 -46
  163. package/src/internal/value/set.ts +0 -132
  164. package/src/is.ts +0 -182
  165. package/src/logger.ts +0 -230
  166. package/src/math.ts +0 -281
  167. package/src/models.ts +0 -286
  168. package/src/number.ts +0 -1
  169. package/src/promise/delay.ts +0 -62
  170. package/src/promise/helpers.ts +0 -96
  171. package/src/promise/index.ts +0 -300
  172. package/src/promise/misc.ts +0 -96
  173. package/src/promise/models.ts +0 -195
  174. package/src/promise/timed.ts +0 -91
  175. package/src/query.ts +0 -147
  176. package/src/queue.ts +0 -814
  177. package/src/random.ts +0 -125
  178. package/src/result/index.ts +0 -105
  179. package/src/result/match.ts +0 -124
  180. package/src/result/misc.ts +0 -129
  181. package/src/result/models.ts +0 -83
  182. package/src/result/work/flow.ts +0 -488
  183. package/src/result/work/pipe.ts +0 -496
  184. package/src/sized/map.ts +0 -110
  185. package/src/sized/set.ts +0 -107
  186. package/src/string/case.ts +0 -236
  187. package/src/string/fuzzy.ts +0 -444
  188. package/src/string/index.ts +0 -199
  189. package/src/string/match.ts +0 -80
  190. package/src/string/normalize.ts +0 -205
  191. package/src/string/template.ts +0 -161
  192. package/src/value/clone.ts +0 -319
  193. package/src/value/collection.ts +0 -63
  194. package/src/value/diff.ts +0 -232
  195. package/src/value/freeze.ts +0 -322
  196. package/src/value/handle.ts +0 -3
  197. package/src/value/index.ts +0 -5
  198. package/src/value/merge.ts +0 -278
  199. package/src/value/omit.ts +0 -20
  200. package/src/value/pick.ts +0 -20
  201. package/src/value/shake.ts +0 -45
  202. package/src/value/smush.ts +0 -89
  203. package/src/value/transform.ts +0 -153
  204. package/src/value/unsmush.ts +0 -84
@@ -1,7 +1,7 @@
1
- import { COMPARE_SETS_DIFFERENCE, compareSets } from "../internal/array/sets.mjs";
1
+ import { SETS_COMPARE_DIFFERENCE, compareSets } from "../internal/array/sets.mjs";
2
2
  //#region src/array/difference.ts
3
3
  function difference(first, second, key) {
4
- return compareSets(COMPARE_SETS_DIFFERENCE, first, second, key);
4
+ return compareSets(SETS_COMPARE_DIFFERENCE, first, second, key);
5
5
  }
6
6
  //#endregion
7
7
  export { difference };
@@ -1,7 +1,7 @@
1
- import { COMPARE_SETS_INTERSECTION, compareSets } from "../internal/array/sets.mjs";
1
+ import { SETS_COMPARE_INTERSECTION, compareSets } from "../internal/array/sets.mjs";
2
2
  //#region src/array/intersection.ts
3
3
  function intersection(first, second, key) {
4
- return compareSets(COMPARE_SETS_INTERSECTION, first, second, key);
4
+ return compareSets(SETS_COMPARE_INTERSECTION, first, second, key);
5
5
  }
6
6
  //#endregion
7
7
  export { intersection };
@@ -7,8 +7,8 @@ function getArrayComparison(haystack, needle, key) {
7
7
  return getPosition(haystack, needle, key)[1];
8
8
  }
9
9
  function getName(start, haystack, needle) {
10
- if (start === 0) return haystack === needle ? COMPARISON_SAME : COMPARISON_START;
11
- return start + needle === haystack ? COMPARISON_END : COMPARISON_INSIDE;
10
+ if (start === 0) return haystack === needle ? MATCH_COMPARISON_SAME : MATCH_COMPARISON_START;
11
+ return start + needle === haystack ? MATCH_COMPARISON_END : MATCH_COMPARISON_INSIDE;
12
12
  }
13
13
  function getPosition(haystack, needle, key) {
14
14
  if (!Array.isArray(haystack) || !Array.isArray(needle)) return invalid;
@@ -43,16 +43,16 @@ function indexOfArray(haystack, needle, key) {
43
43
  function startsWithArray(haystack, needle, key) {
44
44
  return starts.has(getPosition(haystack, needle, key)[1]);
45
45
  }
46
- const COMPARISON_END = "end";
47
- const COMPARISON_INSIDE = "inside";
48
- const COMPARISON_INVALID = "invalid";
49
- const COMPARISON_OUTSIDE = "outside";
50
- const COMPARISON_SAME = "same";
51
- const COMPARISON_START = "start";
52
- const endings = /* @__PURE__ */ new Set([COMPARISON_END, COMPARISON_SAME]);
53
- const invalid = [-1, COMPARISON_INVALID];
54
- const outside = [-1, COMPARISON_OUTSIDE];
55
- const outsides = /* @__PURE__ */ new Set([COMPARISON_INVALID, COMPARISON_OUTSIDE]);
56
- const starts = /* @__PURE__ */ new Set([COMPARISON_START, COMPARISON_SAME]);
46
+ const MATCH_COMPARISON_END = "end";
47
+ const MATCH_COMPARISON_INSIDE = "inside";
48
+ const MATCH_COMPARISON_INVALID = "invalid";
49
+ const MATCH_COMPARISON_OUTSIDE = "outside";
50
+ const MATCH_COMPARISON_SAME = "same";
51
+ const MATCH_COMPARISON_START = "start";
52
+ const endings = /* @__PURE__ */ new Set([MATCH_COMPARISON_END, MATCH_COMPARISON_SAME]);
53
+ const invalid = [-1, MATCH_COMPARISON_INVALID];
54
+ const outside = [-1, MATCH_COMPARISON_OUTSIDE];
55
+ const outsides = /* @__PURE__ */ new Set([MATCH_COMPARISON_INVALID, MATCH_COMPARISON_OUTSIDE]);
56
+ const starts = /* @__PURE__ */ new Set([MATCH_COMPARISON_START, MATCH_COMPARISON_SAME]);
57
57
  //#endregion
58
58
  export { endsWithArray, getArrayComparison, includesArray, indexOfArray, startsWithArray };
@@ -1,13 +1,13 @@
1
1
  import { getArrayCallbacks } from "../internal/array/callbacks.mjs";
2
2
  //#region src/array/slice.ts
3
3
  function drop(array, first, second) {
4
- return extract(EXTRACT_DROP, array, first, second);
4
+ return extract(SLICE_DROP, array, first, second);
5
5
  }
6
6
  function extract(type, array, first, second) {
7
7
  if (!Array.isArray(array)) return [];
8
8
  const { length } = array;
9
9
  if (length === 0) return [];
10
- const isTake = type === EXTRACT_TAKE;
10
+ const isTake = type === SLICE_TAKE;
11
11
  if (typeof first === "number") {
12
12
  if (Math.abs(first) >= length) return isTake ? array.slice() : [];
13
13
  if (first === 0) return isTake ? [] : array.slice();
@@ -45,9 +45,9 @@ function slice(array, first, second) {
45
45
  return first >= 0 ? array.slice(first, second) : array.slice(array.length + first, array.length + second);
46
46
  }
47
47
  function take(array, first, second) {
48
- return extract(EXTRACT_TAKE, array, first, second);
48
+ return extract(SLICE_TAKE, array, first, second);
49
49
  }
50
- const EXTRACT_DROP = "drop";
51
- const EXTRACT_TAKE = "take";
50
+ const SLICE_DROP = "drop";
51
+ const SLICE_TAKE = "take";
52
52
  //#endregion
53
53
  export { drop, slice, take };
@@ -38,6 +38,10 @@ type ArrayKeySorters<Item extends PlainObject> = { [ItemKey in keyof Item]: Arra
38
38
  * Sorter to use for sorting
39
39
  */
40
40
  type ArraySorter<Item> = Item extends PlainObject ? keyof Item | ArrayComparisonSorter<Item> | ArrayKeySorters<Item> | ArrayValueSorter<Item> | ComparisonSorter<Item> : ArrayComparisonSorter<Item> | ArrayValueSorter<Item> | ComparisonSorter<Item>;
41
+ /**
42
+ * Sorters to use for sorting
43
+ */
44
+ type ArraySorters<Item> = Array<ArraySorter<Item>>;
41
45
  /**
42
46
  * Sorting information for arrays _(using a value callback and built-in comparison)_
43
47
  */
@@ -244,4 +248,4 @@ declare namespace sort {
244
248
  declare const SORT_DIRECTION_ASCENDING: SortDirection;
245
249
  declare const SORT_DIRECTION_DESCENDING: SortDirection;
246
250
  //#endregion
247
- export { ArrayComparisonSorter, ArrayKeySorter, ArrayValueSorter, SORT_DIRECTION_ASCENDING, SORT_DIRECTION_DESCENDING, SortDirection, Sorter, getSortedIndex, initializeSorter, isSorted, sort };
251
+ export { ArrayComparisonSorter, ArrayKeySorter, ArraySorter, ArraySorters, ArrayValueSorter, SORT_DIRECTION_ASCENDING, SORT_DIRECTION_DESCENDING, SortDirection, Sorter, getSortedIndex, initializeSorter, isSorted, sort };
@@ -85,8 +85,10 @@ function getValueSorter(value, modifier) {
85
85
  function initializeSorter(first, second) {
86
86
  const sorters = getSorters(first, getModifier(first, second));
87
87
  const sorter = (array) => sortArray(array, sorters);
88
- sorter.index = (array, item) => getIndex(array, item, sorters);
89
- sorter.is = (array) => isSortedArray(array, sorters);
88
+ Object.defineProperties(sorter, {
89
+ index: { value: (array, item) => getIndex(array, item, sorters) },
90
+ is: { value: (array) => isSortedArray(array, sorters) }
91
+ });
90
92
  return sorter;
91
93
  }
92
94
  function isSorted(array, first, second) {
@@ -1,7 +1,7 @@
1
- import { COMPARE_SETS_UNION, compareSets } from "../internal/array/sets.mjs";
1
+ import { SETS_COMPARE_UNION, compareSets } from "../internal/array/sets.mjs";
2
2
  //#region src/array/union.ts
3
3
  function union(first, second, key) {
4
- return compareSets(COMPARE_SETS_UNION, first, second, key);
4
+ return compareSets(SETS_COMPARE_UNION, first, second, key);
5
5
  }
6
6
  //#endregion
7
7
  export { union };
package/dist/beacon.d.mts CHANGED
@@ -105,6 +105,13 @@ declare function beacon<Value>(value: Value, options?: BeaconOptions<Value>): Be
105
105
  * @returns `true` if the value is a beacon, otherwise `false`
106
106
  */
107
107
  declare function isBeacon<Value = unknown>(value: unknown): value is Beacon<Value>;
108
+ /**
109
+ * Is the value a beacon subscription?
110
+ *
111
+ * @param value Value to check
112
+ * @returns `true` if the value is a beacon subscription, otherwise `false`
113
+ */
114
+ declare function isBeaconSubscription(value: unknown): value is Subscription;
108
115
  /**
109
116
  * Is the value an observable?
110
117
  *
@@ -113,4 +120,4 @@ declare function isBeacon<Value = unknown>(value: unknown): value is Beacon<Valu
113
120
  */
114
121
  declare function isObservable<Value = unknown>(value: unknown): value is Observable<Value>;
115
122
  //#endregion
116
- export { Beacon, BeaconOptions, Observable, beacon, isBeacon, isObservable };
123
+ export { Beacon, BeaconOptions, Observable, beacon, isBeacon, isBeaconSubscription, isObservable };
package/dist/beacon.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { noop } from "./internal/function/misc.mjs";
2
2
  import { isPlainObject } from "./internal/is.mjs";
3
- import { clearSubscriptions, getSubscription, getSubscriptions } from "./internal/subscription.mjs";
3
+ import { createSubscriptions, isSubscription } from "./internal/subscription.mjs";
4
4
  //#region src/beacon.ts
5
5
  /**
6
6
  * Create a new beacon
@@ -15,38 +15,23 @@ function beacon(value, options) {
15
15
  active: true,
16
16
  observable: void 0,
17
17
  options: getBeaconOptions(options),
18
- subscriptions: getSubscriptions()
18
+ subscriptions: createSubscriptions({ property: beaconSubscription })
19
19
  };
20
20
  const instance = {
21
- deactivate: () => {
22
- finishBeacon(state, false);
23
- },
24
- emit: (value, finish) => {
25
- update(TYPE_NEXT, state, value, finish);
26
- },
27
- error: (value, finish) => {
28
- update(TYPE_ERROR, state, value, finish);
29
- },
30
- finish: () => {
31
- finishBeacon(state, true);
32
- }
21
+ deactivate: () => finishBeacon(state, false),
22
+ emit: (value, finish) => updateBeacon(BEACON_TYPE_NEXT, state, value, finish),
23
+ error: (value, finish) => updateBeacon(BEACON_TYPE_ERROR, state, value, finish),
24
+ finish: () => finishBeacon(state, true)
33
25
  };
34
26
  Object.defineProperties(instance, {
35
- [KEY_BEACON]: {
36
- enumerable: false,
37
- value: NAME_BEACON
38
- },
27
+ [BEACON_PROPERTY]: { value: BEACON_NAME },
39
28
  active: {
40
29
  enumerable: true,
41
30
  get: () => state.active
42
31
  },
43
32
  observable: {
44
33
  enumerable: true,
45
- get: () => {
46
- if (!state.active) throw new Error(MESSAGE_BEACON);
47
- state.observable ??= observe(state);
48
- return state.observable;
49
- }
34
+ get: () => getObservable(state)
50
35
  },
51
36
  value: {
52
37
  enumerable: true,
@@ -58,8 +43,8 @@ function beacon(value, options) {
58
43
  function finishBeacon(state, emit) {
59
44
  if (!state.active) return;
60
45
  state.active = false;
61
- for (const [, observer] of state.subscriptions.values.to.any) if (emit) observer.complete?.();
62
- clearSubscriptions(state.subscriptions);
46
+ for (const [, observer] of state.subscriptions.state.values.to.any) if (emit) observer.complete?.();
47
+ state.subscriptions.clear();
63
48
  state.observable?.deactivate();
64
49
  state.observable = void 0;
65
50
  }
@@ -68,6 +53,11 @@ function getBeaconOptions(input) {
68
53
  options.equal = typeof options.equal === "function" ? options.equal : Object.is;
69
54
  return options;
70
55
  }
56
+ function getObservable(state) {
57
+ if (!state.active) throw new Error(BEACON_MESSAGE_RETRIEVE);
58
+ state.observable ??= observeBeacon(state);
59
+ return state.observable;
60
+ }
71
61
  function getObservableCallback(value) {
72
62
  return typeof value === "function" ? value : noop;
73
63
  }
@@ -92,10 +82,19 @@ function getObserver(first, second, third) {
92
82
  * @returns `true` if the value is a beacon, otherwise `false`
93
83
  */
94
84
  function isBeacon(value) {
95
- return isBeaconInstance(NAME_BEACON, value);
85
+ return isBeaconInstance(BEACON_NAME, value);
96
86
  }
97
87
  function isBeaconInstance(name, value) {
98
- return isPlainObject(value) && value[KEY_BEACON] === name;
88
+ return isPlainObject(value) && value[BEACON_PROPERTY] === name;
89
+ }
90
+ /**
91
+ * Is the value a beacon subscription?
92
+ *
93
+ * @param value Value to check
94
+ * @returns `true` if the value is a beacon subscription, otherwise `false`
95
+ */
96
+ function isBeaconSubscription(value) {
97
+ return isSubscription(value) && value[BEACON_PROPERTY] === "subscription";
99
98
  }
100
99
  /**
101
100
  * Is the value an observable?
@@ -104,9 +103,9 @@ function isBeaconInstance(name, value) {
104
103
  * @returns `true` if the value is an observable, otherwise `false`
105
104
  */
106
105
  function isObservable(value) {
107
- return isBeaconInstance(NAME_OBSERVABLE, value);
106
+ return isBeaconInstance(BEACON_OBSERVABLE, value);
108
107
  }
109
- function observe(beacon) {
108
+ function observeBeacon(beacon) {
110
109
  const state = {
111
110
  beacon,
112
111
  active: beacon.active
@@ -115,24 +114,10 @@ function observe(beacon) {
115
114
  deactivate: () => {
116
115
  state.active = false;
117
116
  },
118
- subscribe(first, second, third) {
119
- if (!beacon.active || !state.active) throw new Error(MESSAGE_OBSERVABLE);
120
- const observer = getObserver(first, second, third);
121
- const subscription = getSubscription({
122
- isActive: () => beacon.active && state.active,
123
- property: beaconSubscription,
124
- subscriptions: beacon.subscriptions,
125
- value: observer
126
- });
127
- observer.next?.(beacon.value);
128
- return subscription;
129
- }
117
+ subscribe: (first, second, third) => subscribeToObservable(state, first, second, third)
130
118
  };
131
119
  Object.defineProperties(instance, {
132
- [KEY_BEACON]: {
133
- enumerable: false,
134
- value: NAME_OBSERVABLE
135
- },
120
+ [BEACON_PROPERTY]: { value: BEACON_OBSERVABLE },
136
121
  active: {
137
122
  enumerable: true,
138
123
  get: () => beacon.active && state.active
@@ -140,25 +125,32 @@ function observe(beacon) {
140
125
  });
141
126
  return Object.freeze(instance);
142
127
  }
143
- function update(type, state, value, finish) {
128
+ function subscribeToObservable(state, first, second, third) {
129
+ if (!state.beacon.active || !state.active) throw new Error(BEACON_MESSAGE_SUBSCRIBE);
130
+ const observer = getObserver(first, second, third);
131
+ const [subscription] = state.beacon.subscriptions.create({
132
+ isActive: () => state.beacon.active && state.active,
133
+ value: observer
134
+ });
135
+ observer.next?.(state.beacon.value);
136
+ return subscription;
137
+ }
138
+ function updateBeacon(type, state, value, finish) {
144
139
  if (!state.active) return;
145
- if (type === TYPE_NEXT) {
140
+ if (type === BEACON_TYPE_NEXT) {
146
141
  if (state.options.equal(state.value, value)) return;
147
142
  state.value = value;
148
143
  }
149
- for (const [, observer] of state.subscriptions.values.to.any) observer[type]?.(value);
144
+ for (const [, observer] of state.subscriptions.state.values.to.any) observer[type]?.(value);
150
145
  if (finish === true) finishBeacon(state, true);
151
146
  }
152
- const KEY_BEACON = "$beacon";
153
- const MESSAGE_BEACON = "Cannot retrieve observable from a closed beacon";
154
- const MESSAGE_OBSERVABLE = "Cannot subscribe to a closed observable";
155
- const NAME_BEACON = "beacon";
156
- const NAME_OBSERVABLE = "observable";
157
- const TYPE_ERROR = "error";
158
- const TYPE_NEXT = "next";
159
- const beaconSubscription = {
160
- key: KEY_BEACON,
161
- value: "subscription"
162
- };
147
+ const BEACON_MESSAGE_RETRIEVE = "Cannot retrieve observable from a closed beacon";
148
+ const BEACON_MESSAGE_SUBSCRIBE = "Cannot subscribe to a closed observable";
149
+ const BEACON_PROPERTY = "$beacon";
150
+ const BEACON_NAME = "beacon";
151
+ const BEACON_OBSERVABLE = "observable";
152
+ const BEACON_TYPE_ERROR = "error";
153
+ const BEACON_TYPE_NEXT = "next";
154
+ const beaconSubscription = { key: BEACON_PROPERTY };
163
155
  //#endregion
164
- export { beacon, isBeacon, isObservable };
156
+ export { beacon, isBeacon, isBeaconSubscription, isObservable };
@@ -10,6 +10,7 @@ type ColorTypes = {
10
10
  hwba: 'hwba';
11
11
  rgb: 'rgb';
12
12
  rgba: 'rgba';
13
+ wildcard: '*';
13
14
  };
14
15
  declare const COLOR_ALPHA: {
15
16
  fullHexShort: string;
@@ -66,7 +67,6 @@ declare const COLOR_MAX: {
66
67
  };
67
68
  declare const COLOR_PROPERTY: {
68
69
  name: string;
69
- subscription: string;
70
70
  };
71
71
  declare const COLOR_TYPE: ColorTypes;
72
72
  declare const COLOR_SRGB: {
@@ -67,10 +67,7 @@ const COLOR_MAX = {
67
67
  hex: 255,
68
68
  percent: 100
69
69
  };
70
- const COLOR_PROPERTY = {
71
- name: "$color",
72
- subscription: "subscription"
73
- };
70
+ const COLOR_PROPERTY = { name: "$color" };
74
71
  const COLOR_TYPE = {
75
72
  all: void 0,
76
73
  hex: "hex",
@@ -80,7 +77,8 @@ const COLOR_TYPE = {
80
77
  hwb: "hwb",
81
78
  hwba: "hwba",
82
79
  rgb: "rgb",
83
- rgba: "rgba"
80
+ rgba: "rgba",
81
+ wildcard: "*"
84
82
  };
85
83
  COLOR_TYPE.all = /* @__PURE__ */ new Set([
86
84
  COLOR_ALPHA.name,
@@ -1,55 +1,60 @@
1
- import { clearSubscriptions, getSubscription, getSubscriptions } from "../internal/subscription.mjs";
1
+ import { herald } from "../herald.mjs";
2
2
  import { COLOR_PROPERTY, COLOR_TYPE } from "./constants.mjs";
3
3
  import { getAlpha } from "./misc/alpha.mjs";
4
4
  import { getColorFromState, getColorState, setHSLColor, setHWBColor, setHexColor, setRGBColor } from "./misc/state.mjs";
5
- import { formatHslColor, formatHwbColor, formatRgbColor } from "./misc/format.mjs";
5
+ import { formatHexColor, formatHslColor, formatHwbColor, formatRgbColor } from "./misc/format.mjs";
6
6
  //#region src/color/instance.ts
7
7
  function color(value) {
8
+ const changes = herald({
9
+ names: [COLOR_TYPE.wildcard, ...COLOR_TYPE.all],
10
+ property: colorSubscription,
11
+ onCreate: (event, callback) => onCreateSubscription(instance, event, callback)
12
+ });
8
13
  const state = getColorState(value);
9
- const subscriptions = getSubscriptions(COLOR_TYPE.all);
10
14
  const instance = {
11
- subscribe: (first, second) => subscribeToColor(subscriptions, first, second),
12
- toHexString: (alpha) => `#${alpha === true ? instance.hexa : instance.hex}`,
15
+ subscribe: (callback, signal) => changes.subscribe(COLOR_TYPE.wildcard, callback, signal),
16
+ toHexString: (alpha) => formatHexColor(instance, alpha),
13
17
  toHslString: (alpha) => formatHslColor(state, alpha),
14
18
  toHwbString: (alpha) => formatHwbColor(state, alpha),
15
19
  toRgbString: (alpha) => formatRgbColor(state, alpha),
16
20
  toString: () => instance.toHexString(),
17
- unsubscribe: () => clearSubscriptions(subscriptions)
21
+ unsubscribe: () => changes.clear()
18
22
  };
19
23
  Object.defineProperties(instance, {
20
- [COLOR_PROPERTY.name]: {
21
- enumerable: false,
22
- value: true
23
- },
24
+ [COLOR_PROPERTY.name]: { value: true },
24
25
  alpha: {
25
26
  enumerable: true,
26
27
  get: () => state.alpha.value,
27
28
  set: (value) => setAlphaValue(state, value)
28
29
  },
29
- hex: getProperty(COLOR_TYPE.hex, instance, state, subscriptions, false),
30
- hexa: getProperty(COLOR_TYPE.hex, instance, state, subscriptions, true),
31
- hsl: getProperty(COLOR_TYPE.hsl, instance, state, subscriptions, false),
32
- hsla: getProperty(COLOR_TYPE.hsl, instance, state, subscriptions, true),
33
- hwb: getProperty(COLOR_TYPE.hwb, instance, state, subscriptions, false),
34
- hwba: getProperty(COLOR_TYPE.hwb, instance, state, subscriptions, true),
30
+ changes: {
31
+ enumerable: true,
32
+ value: changes.events
33
+ },
34
+ hex: getColorProperty(COLOR_TYPE.hex, instance, state, changes, false),
35
+ hexa: getColorProperty(COLOR_TYPE.hex, instance, state, changes, true),
36
+ hsl: getColorProperty(COLOR_TYPE.hsl, instance, state, changes, false),
37
+ hsla: getColorProperty(COLOR_TYPE.hsl, instance, state, changes, true),
38
+ hwb: getColorProperty(COLOR_TYPE.hwb, instance, state, changes, false),
39
+ hwba: getColorProperty(COLOR_TYPE.hwb, instance, state, changes, true),
35
40
  origin: {
36
41
  enumerable: true,
37
42
  get: () => state.origin
38
43
  },
39
- rgb: getProperty(COLOR_TYPE.rgb, instance, state, subscriptions, false),
40
- rgba: getProperty(COLOR_TYPE.rgb, instance, state, subscriptions, true)
44
+ rgb: getColorProperty(COLOR_TYPE.rgb, instance, state, changes, false),
45
+ rgba: getColorProperty(COLOR_TYPE.rgb, instance, state, changes, true)
41
46
  });
42
47
  return Object.freeze(instance);
43
48
  }
44
- function getProperty(space, color, state, subscriptions, alpha) {
49
+ function getColorProperty(space, color, state, changes, alpha) {
45
50
  const setValue = setters[space];
46
51
  return {
47
52
  enumerable: true,
48
- get: () => getValue(space, state, alpha),
49
- set: (value) => setValue(color, state, subscriptions, value, alpha)
53
+ get: () => getColorValue(space, state, alpha),
54
+ set: (value) => setValue(color, state, changes, value, alpha)
50
55
  };
51
56
  }
52
- function getValue(space, state, alpha) {
57
+ function getColorValue(space, state, alpha) {
53
58
  const value = getColorFromState(state, space);
54
59
  if (typeof value === "string") return alpha ? `${value}${state.alpha.hex}` : value;
55
60
  return alpha ? {
@@ -57,28 +62,16 @@ function getValue(space, state, alpha) {
57
62
  alpha: state.alpha.value
58
63
  } : { ...value };
59
64
  }
65
+ function onCreateSubscription(instance, event, callback) {
66
+ let value;
67
+ if (event === COLOR_TYPE.wildcard) value = instance;
68
+ else value = instance[event];
69
+ callback(value);
70
+ }
60
71
  function setAlphaValue(state, value) {
61
72
  if (typeof value === "number" && !Number.isNaN(value)) state.alpha = getAlpha(value, false);
62
73
  }
63
- function subscribeToColor(subscriptions, first, second) {
64
- let key;
65
- let value;
66
- if (typeof first === "string") {
67
- key = first;
68
- value = second;
69
- } else if (typeof first === "function") value = first;
70
- if (typeof value !== "function") throw new Error();
71
- return getSubscription({
72
- key,
73
- subscriptions,
74
- value,
75
- property: colorSubscription
76
- });
77
- }
78
- const colorSubscription = {
79
- key: COLOR_PROPERTY.name,
80
- value: COLOR_PROPERTY.subscription
81
- };
74
+ const colorSubscription = { key: COLOR_PROPERTY.name };
82
75
  const setters = {
83
76
  hex: setHexColor,
84
77
  hsl: setHSLColor,
@@ -1,7 +1,8 @@
1
- import { ColorState } from "../models.mjs";
1
+ import { Color, ColorState } from "../models.mjs";
2
2
  //#region src/color/misc/format.d.ts
3
+ declare function formatHexColor(color: Color, alpha?: boolean): string;
3
4
  declare function formatHslColor(state: ColorState, alpha?: boolean): string;
4
5
  declare function formatHwbColor(state: ColorState, alpha?: boolean): string;
5
6
  declare function formatRgbColor(state: ColorState, alpha?: boolean): string;
6
7
  //#endregion
7
- export { formatHslColor, formatHwbColor, formatRgbColor };
8
+ export { formatHexColor, formatHslColor, formatHwbColor, formatRgbColor };
@@ -1,6 +1,9 @@
1
1
  import { COLOR_TYPE } from "../constants.mjs";
2
2
  import { getColorFromState } from "./state.mjs";
3
3
  //#region src/color/misc/format.ts
4
+ function formatHexColor(color, alpha) {
5
+ return `#${alpha === true ? color.hexa : color.hex}`;
6
+ }
4
7
  function formatHslColor(state, alpha) {
5
8
  const { hue, lightness, saturation } = getColorFromState(state, COLOR_TYPE.hsl);
6
9
  return `hsl(${hue}deg ${saturation}% ${lightness}%${getSuffix(state, alpha)})`;
@@ -17,4 +20,4 @@ function getSuffix(state, alpha) {
17
20
  return alpha === true ? ` / ${state.alpha.value}%` : "";
18
21
  }
19
22
  //#endregion
20
- export { formatHslColor, formatHwbColor, formatRgbColor };
23
+ export { formatHexColor, formatHslColor, formatHwbColor, formatRgbColor };
@@ -1,3 +1,4 @@
1
+ import { Subscription } from "../../internal/subscription.mjs";
1
2
  import { Color, HSLAColor, HSLColor, HWBAColor, HWBColor, RGBAColor, RGBColor } from "../models.mjs";
2
3
  //#region src/color/misc/is.d.ts
3
4
  /**
@@ -7,6 +8,13 @@ import { Color, HSLAColor, HSLColor, HWBAColor, HWBColor, RGBAColor, RGBColor }
7
8
  * @returns `true` if the value is a _Color_, otherwise `false`
8
9
  */
9
10
  declare function isColor(value: unknown): value is Color;
11
+ /**
12
+ * Is the value a color subscription?
13
+ *
14
+ * @param value Value to check
15
+ * @returns `true` if the value is a color subscription, otherwise `false`
16
+ */
17
+ declare function isColorSubscription(value: unknown): value is Subscription;
10
18
  /**
11
19
  * Is the value a hex color?
12
20
  *
@@ -73,4 +81,4 @@ declare function isRgbaLike(value: unknown): value is Record<keyof RGBAColor, un
73
81
  declare function isRgbColor(value: unknown): value is RGBColor;
74
82
  declare function isRgbLike(value: unknown): value is Record<keyof RGBColor, unknown>;
75
83
  //#endregion
76
- export { isColor, isHexColor, isHslColor, isHslLike, isHslaColor, isHslaLike, isHwbColor, isHwbLike, isHwbaColor, isHwbaLike, isRgbColor, isRgbLike, isRgbaColor, isRgbaLike };
84
+ export { isColor, isColorSubscription, isHexColor, isHslColor, isHslLike, isHslaColor, isHslaLike, isHwbColor, isHwbLike, isHwbaColor, isHwbaLike, isRgbColor, isRgbLike, isRgbaColor, isRgbaLike };
@@ -1,4 +1,5 @@
1
1
  import { isPlainObject } from "../../internal/is.mjs";
2
+ import { isSubscription } from "../../internal/subscription.mjs";
2
3
  import { between } from "../../internal/number.mjs";
3
4
  import { COLOR_ALPHA, COLOR_EXPRESSION, COLOR_KEYS, COLOR_LENGTHS, COLOR_MAX, COLOR_PROPERTY } from "../constants.mjs";
4
5
  //#region src/color/misc/is.ts
@@ -20,6 +21,15 @@ function isBytey(value) {
20
21
  function isColor(value) {
21
22
  return isPlainObject(value) && COLOR_PROPERTY.name in value && value[COLOR_PROPERTY.name] === true;
22
23
  }
24
+ /**
25
+ * Is the value a color subscription?
26
+ *
27
+ * @param value Value to check
28
+ * @returns `true` if the value is a color subscription, otherwise `false`
29
+ */
30
+ function isColorSubscription(value) {
31
+ return isSubscription(value) && value[COLOR_PROPERTY.name] === "subscription";
32
+ }
23
33
  function isColorValue(obj, properties) {
24
34
  if (typeof obj !== "object" || obj === null) return false;
25
35
  const keys = Object.keys(obj);
@@ -146,4 +156,4 @@ const validators = {
146
156
  whiteness: isPercentage
147
157
  };
148
158
  //#endregion
149
- export { isColor, isHexColor, isHslColor, isHslLike, isHslaColor, isHslaLike, isHwbColor, isHwbLike, isHwbaColor, isHwbaLike, isRgbColor, isRgbLike, isRgbaColor, isRgbaLike };
159
+ export { isColor, isColorSubscription, isHexColor, isHslColor, isHslLike, isHslaColor, isHslaLike, isHwbColor, isHwbLike, isHwbaColor, isHwbaLike, isRgbColor, isRgbLike, isRgbaColor, isRgbaLike };
@@ -1,11 +1,11 @@
1
- import { Subscriptions } from "../../internal/subscription.mjs";
2
- import { Color, ColorState, ColorType } from "../models.mjs";
1
+ import { Herald } from "../../herald.mjs";
2
+ import { Color, ColorChanges, ColorState, ColorType } from "../models.mjs";
3
3
  //#region src/color/misc/state.d.ts
4
4
  declare function getColorFromState<Type extends ColorType>(state: ColorState, type: Type): NonNullable<ColorState[Type]>;
5
5
  declare function getColorState(value: unknown): ColorState;
6
- declare function setHexColor(color: Color, state: ColorState, subscriptions: Subscriptions<Function>, value: string, alpha: boolean): void;
7
- declare function setHSLColor(color: Color, state: ColorState, subscriptions: Subscriptions<Function>, value: unknown, alpha: boolean): void;
8
- declare function setHWBColor(color: Color, state: ColorState, subscriptions: Subscriptions<Function>, value: unknown, alpha: boolean): void;
9
- declare function setRGBColor(color: Color, state: ColorState, subscriptions: Subscriptions<Function>, value: unknown, alpha: boolean): void;
6
+ declare function setHexColor(color: Color, state: ColorState, changes: Herald<ColorChanges>, value: string, alpha: boolean): void;
7
+ declare function setHSLColor(color: Color, state: ColorState, changes: Herald<ColorChanges>, value: unknown, alpha: boolean): void;
8
+ declare function setHWBColor(color: Color, state: ColorState, changes: Herald<ColorChanges>, value: unknown, alpha: boolean): void;
9
+ declare function setRGBColor(color: Color, state: ColorState, changes: Herald<ColorChanges>, value: unknown, alpha: boolean): void;
10
10
  //#endregion
11
11
  export { getColorFromState, getColorState, setHSLColor, setHWBColor, setHexColor, setRGBColor };
@@ -59,7 +59,7 @@ function getDefaultColorState() {
59
59
  origin: COLOR_TYPE.hex
60
60
  };
61
61
  }
62
- function setColorValue(color, state, subscriptions, type, value, alpha) {
62
+ function setColorValue(color, state, changes, type, value, alpha) {
63
63
  state.hex = void 0;
64
64
  state.hsl = void 0;
65
65
  state.hwb = void 0;
@@ -67,36 +67,33 @@ function setColorValue(color, state, subscriptions, type, value, alpha) {
67
67
  state.origin = type;
68
68
  state[type] = value;
69
69
  if (alpha != null) state.alpha = getAlpha(alpha, type === COLOR_TYPE.hex);
70
- for (const type of COLOR_TYPE.all) {
71
- const callbacks = subscriptions.values.to.keyed?.get(type);
72
- if (callbacks != null) for (const callback of callbacks.values()) callback(color[type]);
73
- }
74
- for (const callback of subscriptions.values.to.any.values()) callback(color);
70
+ for (const type of COLOR_TYPE.all) if (changes.observed(type)) changes.emit(type, color[type]);
71
+ changes.emit(COLOR_TYPE.wildcard, color);
75
72
  }
76
- function setHexColor(color, state, subscriptions, value, alpha) {
73
+ function setHexColor(color, state, changes, value, alpha) {
77
74
  if (!isHexColor(value) || !alpha && value === state.hex) return;
78
75
  const normalized = getNormalizedHex(value, true);
79
- setColorValue(color, state, subscriptions, COLOR_TYPE.hex, normalized.slice(0, COLOR_LENGTHS.hexLong), alpha ? normalized.slice(COLOR_LENGTHS.hexLong) : void 0);
76
+ setColorValue(color, state, changes, COLOR_TYPE.hex, normalized.slice(0, COLOR_LENGTHS.hexLong), alpha ? normalized.slice(COLOR_LENGTHS.hexLong) : void 0);
80
77
  }
81
- function setHSLColor(color, state, subscriptions, value, alpha) {
78
+ function setHSLColor(color, state, changes, value, alpha) {
82
79
  if (!isHslLike(value)) return;
83
- setColorValue(color, state, subscriptions, COLOR_TYPE.hsl, {
80
+ setColorValue(color, state, changes, COLOR_TYPE.hsl, {
84
81
  hue: getDegrees(value.hue),
85
82
  saturation: getPercentage(value.saturation),
86
83
  lightness: getPercentage(value.lightness)
87
84
  }, alpha ? value.alpha : void 0);
88
85
  }
89
- function setHWBColor(color, state, subscriptions, value, alpha) {
86
+ function setHWBColor(color, state, changes, value, alpha) {
90
87
  if (!isHwbLike(value)) return;
91
- setColorValue(color, state, subscriptions, COLOR_TYPE.hwb, {
88
+ setColorValue(color, state, changes, COLOR_TYPE.hwb, {
92
89
  hue: getDegrees(value.hue),
93
90
  whiteness: getPercentage(value.whiteness),
94
91
  blackness: getPercentage(value.blackness)
95
92
  }, alpha ? value.alpha : void 0);
96
93
  }
97
- function setRGBColor(color, state, subscriptions, value, alpha) {
94
+ function setRGBColor(color, state, changes, value, alpha) {
98
95
  if (!isRgbLike(value)) return;
99
- setColorValue(color, state, subscriptions, COLOR_TYPE.rgb, {
96
+ setColorValue(color, state, changes, COLOR_TYPE.rgb, {
100
97
  red: getHexValue(value.red),
101
98
  green: getHexValue(value.green),
102
99
  blue: getHexValue(value.blue)