@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,75 +0,0 @@
1
- import {updateInArray} from '../internal/array/update';
2
- import type {PlainObject} from '../models';
3
-
4
- /**
5
- * Update an item in an array
6
- *
7
- * If the item exists, it will be updated; if it doesn't, it will be added
8
- *
9
- * @param destination Array to update within
10
- * @param updated Updated items
11
- * @param callback Callback to find existing item
12
- * @returns Original array
13
- *
14
- * @example
15
- * ```typescript
16
- * update(
17
- * [{id: 1}, {id: 2}, {id: 3}],
18
- * [{id: 2, name: 'Updated'}, {id: 4, name: 'New'}],
19
- * item => item.id,
20
- * ); // => [{id: 1}, {id: 2, name: 'Updated'}, {id: 3}, {id: 4, name: 'New'}]
21
- * ```
22
- */
23
- export function update<Item>(
24
- destination: Item[],
25
- updated: Item[],
26
- callback: (item: Item, index: number, array: Item[]) => unknown,
27
- ): Item[];
28
-
29
- /**
30
- * Update an item in an array
31
- *
32
- * If the item exists, it will be updated; if it doesn't, it will be added
33
- *
34
- * @param destination Array to update within
35
- * @param updated Updated items
36
- * @param key Key to find existing item
37
- * @returns Original array
38
- *
39
- * @example
40
- * ```typescript
41
- * update(
42
- * [{id: 1}, {id: 2}, {id: 3}],
43
- * [{id: 2, name: 'Updated'}, {id: 4, name: 'New'}],
44
- * 'id',
45
- * ); // => [{id: 1}, {id: 2, name: 'Updated'}, {id: 3}, {id: 4, name: 'New'}]
46
- * ```
47
- */
48
- export function update<Item extends PlainObject, ItemKey extends keyof Item>(
49
- destination: Item[],
50
- updated: Item[],
51
- key: ItemKey,
52
- ): Item[];
53
-
54
- /**
55
- * Update an item in an array
56
- *
57
- * If the item exists, it will be updated; if it doesn't, it will be added
58
- *
59
- * @param destination Array to update within
60
- * @param updated Updated items
61
- * @returns Original array
62
- *
63
- * @example
64
- * ```typescript
65
- * update(
66
- * [1, 2, 3],
67
- * [2, 4],
68
- * ); // => [1, 2, 3, 4]
69
- * ```
70
- */
71
- export function update<Item>(destination: Item[], updated: Item[]): Item[];
72
-
73
- export function update(array: unknown[], values: unknown[], key?: unknown): unknown[] {
74
- return updateInArray(array, values, key, true);
75
- }
package/src/beacon.ts DELETED
@@ -1,378 +0,0 @@
1
- import {noop} from './internal/function/misc';
2
- import {isPlainObject} from './internal/is';
3
- import {
4
- clearSubscriptions,
5
- getSubscription,
6
- getSubscriptions,
7
- type Subscription,
8
- type SubscriptionProperty,
9
- type Subscriptions,
10
- } from './internal/subscription';
11
- import type {PlainObject} from './models';
12
-
13
- // #region Types
14
-
15
- /**
16
- * A beacon is a lighthouse, holding an observable value that can be subscribed to and emitted from
17
- */
18
- export type Beacon<Value> = {
19
- /**
20
- * Is the beacon active?
21
- */
22
- get active(): boolean;
23
-
24
- /**
25
- * The observable that can be subscribed to
26
- */
27
- get observable(): Observable<Value>;
28
-
29
- /**
30
- * The current value
31
- */
32
- get value(): Value;
33
-
34
- /**
35
- * Deactivate the beacon
36
- */
37
- deactivate(): void;
38
-
39
- /**
40
- * Emit a new value
41
- *
42
- * @param value Value to set and emit
43
- * @param finish Finish the beacon after emitting? _(defaults to `false`)_
44
- */
45
- emit(value: Value, finish?: boolean): void;
46
-
47
- /**
48
- * Emit an error
49
- *
50
- * @param value Error to emit
51
- * @param finish Finish the beacon after emitting? _(defaults to `false`)_
52
- */
53
- error(value: Error, finish?: boolean): void;
54
-
55
- /**
56
- * Finish the beacon
57
- */
58
- finish(): void;
59
- };
60
-
61
- export type BeaconOptions<Value> = {
62
- /**
63
- * Method for comparing values for equality
64
- *
65
- * @param first First value
66
- * @param second Second value
67
- * @returns `true` if the values are equal, otherwise `false`
68
- * @default Object.is
69
- */
70
- equal?: (first: Value, second: Value) => boolean;
71
- };
72
-
73
- type BeaconState<Value> = {
74
- active: boolean;
75
- observable: Observable<Value>;
76
- options: Required<BeaconOptions<Value>>;
77
- subscriptions: Subscriptions<Observer<unknown>>;
78
- value: Value;
79
- };
80
-
81
- export type Observable<Value> = {
82
- /**
83
- * Is the observable active?
84
- */
85
- get active(): boolean;
86
-
87
- /**
88
- * Deactivate the observable
89
- */
90
- deactivate(): void;
91
-
92
- /**
93
- * Subscribe to value changes
94
- *
95
- * @param onNext Callback for when the observable receives a new value
96
- * @param onError Callback for when the observable receives an error
97
- * @param onComplete Callback for when the observable is completed
98
- * @returns Subscription to the observable
99
- */
100
- subscribe(
101
- onNext: (value: Value) => void,
102
- onError?: (error: Error) => void,
103
- onComplete?: () => void,
104
- ): Subscription;
105
-
106
- /**
107
- * Subscribe to value changes
108
- *
109
- * @param observer Observer for changes
110
- * @returns Subscription to the observable
111
- */
112
- subscribe(observer: Observer<Value>): Subscription;
113
- };
114
-
115
- type ObservableState<Value> = {
116
- active: boolean;
117
- beacon: BeaconState<Value>;
118
- };
119
-
120
- type Observer<Value> = {
121
- /**
122
- * Callback for when the observable is completed
123
- */
124
- complete?: () => void;
125
- /**
126
- * Callback for when the observable receives an error
127
- */
128
- error?: (error: Error) => void;
129
- /**
130
- * Callback for when the observable receives a new value
131
- */
132
- next?: (value: Value) => void;
133
- };
134
-
135
- // #endregion
136
-
137
- // #region Functions
138
-
139
- /**
140
- * Create a new beacon
141
- *
142
- * @param value Initial value
143
- * @param options Beacon options
144
- * @returns Beacon instance
145
- */
146
- export function beacon<Value>(value: Value, options?: BeaconOptions<Value>): Beacon<Value> {
147
- const state: BeaconState<Value> = {
148
- value,
149
- active: true,
150
- observable: undefined as never,
151
- options: getBeaconOptions(options),
152
- subscriptions: getSubscriptions(),
153
- };
154
-
155
- const instance = {
156
- deactivate: (): void => {
157
- finishBeacon(state, false);
158
- },
159
- emit: (value: Value, finish?: boolean): void => {
160
- update(TYPE_NEXT, state, value, finish);
161
- },
162
- error: (value: Error, finish?: boolean): void => {
163
- update(TYPE_ERROR, state, value, finish);
164
- },
165
- finish: (): void => {
166
- finishBeacon(state, true);
167
- },
168
- };
169
-
170
- Object.defineProperties(instance, {
171
- [KEY_BEACON]: {
172
- enumerable: false,
173
- value: NAME_BEACON,
174
- },
175
- active: {
176
- enumerable: true,
177
- get: () => state.active,
178
- },
179
- observable: {
180
- enumerable: true,
181
- get: () => {
182
- if (!state.active) {
183
- throw new Error(MESSAGE_BEACON);
184
- }
185
-
186
- state.observable ??= observe(state);
187
-
188
- return state.observable;
189
- },
190
- },
191
- value: {
192
- enumerable: true,
193
- get: () => state.value,
194
- },
195
- });
196
-
197
- return Object.freeze(instance) as Beacon<Value>;
198
- }
199
-
200
- function finishBeacon<Value>(state: BeaconState<Value>, emit: boolean): void {
201
- if (!state.active) {
202
- return;
203
- }
204
-
205
- state.active = false;
206
-
207
- for (const [, observer] of state.subscriptions.values.to.any) {
208
- if (emit) {
209
- observer.complete?.();
210
- }
211
- }
212
-
213
- clearSubscriptions(state.subscriptions);
214
-
215
- state.observable?.deactivate();
216
-
217
- state.observable = undefined as never;
218
- }
219
-
220
- function getBeaconOptions<Value>(input?: BeaconOptions<Value>): Required<BeaconOptions<Value>> {
221
- const options: BeaconOptions<Value> = isPlainObject(input) ? (input as PlainObject) : {};
222
-
223
- options.equal = typeof options.equal === 'function' ? options.equal : Object.is;
224
-
225
- return options as Required<BeaconOptions<Value>>;
226
- }
227
-
228
- function getObservableCallback<Callback>(value: Callback): Callback {
229
- return typeof value === 'function' ? value : (noop as Callback);
230
- }
231
-
232
- function getObserver<Value>(
233
- first: Observer<Value> | ((value: Value) => void),
234
- second?: (error: Error) => void,
235
- third?: () => void,
236
- ): Observer<Value> {
237
- let observer: Observer<Value> = {
238
- next: noop,
239
- };
240
-
241
- if (typeof first === 'function') {
242
- observer = {
243
- error: getObservableCallback(second),
244
- next: getObservableCallback(first),
245
- complete: getObservableCallback(third),
246
- };
247
- } else if (typeof first === 'object') {
248
- observer.complete = getObservableCallback(first?.complete);
249
- observer.error = getObservableCallback(first?.error);
250
- observer.next = getObservableCallback(first?.next);
251
- }
252
-
253
- return observer;
254
- }
255
-
256
- /**
257
- * Is the value a beacon?
258
- *
259
- * @param value Value to check
260
- * @returns `true` if the value is a beacon, otherwise `false`
261
- */
262
- export function isBeacon<Value = unknown>(value: unknown): value is Beacon<Value> {
263
- return isBeaconInstance<Beacon<Value>>(NAME_BEACON, value);
264
- }
265
-
266
- function isBeaconInstance<Instance>(name: string, value: unknown): value is Instance {
267
- return isPlainObject(value) && (value as PlainObject)[KEY_BEACON] === name;
268
- }
269
-
270
- /**
271
- * Is the value an observable?
272
- *
273
- * @param value Value to check
274
- * @returns `true` if the value is an observable, otherwise `false`
275
- */
276
- export function isObservable<Value = unknown>(value: unknown): value is Observable<Value> {
277
- return isBeaconInstance<Observable<Value>>(NAME_OBSERVABLE, value);
278
- }
279
-
280
- function observe<Value>(beacon: BeaconState<Value>): Observable<Value> {
281
- const state: ObservableState<Value> = {
282
- beacon,
283
- active: beacon.active,
284
- };
285
-
286
- const instance = {
287
- deactivate: (): void => {
288
- state.active = false;
289
- },
290
- subscribe(
291
- first: Observer<Value> | ((value: Value) => void),
292
- second?: (error: Error) => void,
293
- third?: () => void,
294
- ): Subscription {
295
- if (!beacon.active || !state.active) {
296
- throw new Error(MESSAGE_OBSERVABLE);
297
- }
298
-
299
- const observer = getObserver(first, second, third);
300
-
301
- const subscription = getSubscription({
302
- isActive: () => beacon.active && state.active,
303
- property: beaconSubscription,
304
- subscriptions: beacon.subscriptions,
305
- value: observer,
306
- });
307
-
308
- observer.next?.(beacon.value);
309
-
310
- return subscription;
311
- },
312
- };
313
-
314
- Object.defineProperties(instance, {
315
- [KEY_BEACON]: {
316
- enumerable: false,
317
- value: NAME_OBSERVABLE,
318
- },
319
- active: {
320
- enumerable: true,
321
- get: () => beacon.active && state.active,
322
- },
323
- });
324
-
325
- return Object.freeze(instance) as Observable<Value>;
326
- }
327
-
328
- function update<Value>(
329
- type: keyof Observer<never>,
330
- state: BeaconState<Value>,
331
- value: Error | Value,
332
- finish?: boolean,
333
- ): void {
334
- if (!state.active) {
335
- return;
336
- }
337
-
338
- if (type === TYPE_NEXT) {
339
- if (state.options.equal(state.value, value as Value)) {
340
- return;
341
- }
342
-
343
- state.value = value as Value;
344
- }
345
-
346
- for (const [, observer] of state.subscriptions.values.to.any) {
347
- observer[type]?.(value as never);
348
- }
349
-
350
- if (finish === true) {
351
- finishBeacon(state, true);
352
- }
353
- }
354
-
355
- // #endregion
356
-
357
- // #region Variables
358
-
359
- const KEY_BEACON = '$beacon';
360
-
361
- const MESSAGE_BEACON = 'Cannot retrieve observable from a closed beacon';
362
-
363
- const MESSAGE_OBSERVABLE = 'Cannot subscribe to a closed observable';
364
-
365
- const NAME_BEACON = 'beacon';
366
-
367
- const NAME_OBSERVABLE = 'observable';
368
-
369
- const TYPE_ERROR = 'error';
370
-
371
- const TYPE_NEXT = 'next';
372
-
373
- const beaconSubscription: SubscriptionProperty = {
374
- key: KEY_BEACON,
375
- value: 'subscription',
376
- };
377
-
378
- // #endregion
@@ -1,137 +0,0 @@
1
- import type {
2
- Alpha,
3
- ColorTypeExtended,
4
- HSLAColor,
5
- HSLColor,
6
- HWBAColor,
7
- HWBColor,
8
- RGBAColor,
9
- RGBColor,
10
- } from './models';
11
-
12
- // #region Types
13
-
14
- type ColorTypes = {
15
- all: Set<'alpha' | ColorTypeExtended>;
16
- hex: 'hex';
17
- hexa: 'hexa';
18
- hsl: 'hsl';
19
- hsla: 'hsla';
20
- hwb: 'hwb';
21
- hwba: 'hwba';
22
- rgb: 'rgb';
23
- rgba: 'rgba';
24
- };
25
-
26
- // #endregion
27
-
28
- // #region Variables
29
-
30
- export const COLOR_ALPHA = {
31
- fullHexShort: 'f',
32
- fullHexLong: 'ff',
33
- name: 'alpha',
34
- noneHex: '00',
35
- noneValue: 0,
36
- };
37
-
38
- export const COLOR_DEFAULTS = {
39
- alpha: {
40
- hex: COLOR_ALPHA.fullHexLong,
41
- value: 100,
42
- },
43
- hexBlack: '000000',
44
- hexWhite: 'ffffff',
45
- hsl: {
46
- hue: 0,
47
- saturation: 0,
48
- lightness: 0,
49
- },
50
- hwb: {
51
- hue: 0,
52
- whiteness: 0,
53
- blackness: 100,
54
- },
55
- rgb: {
56
- blue: 0,
57
- green: 0,
58
- red: 0,
59
- },
60
- };
61
-
62
- export const COLOR_EXPRESSION = {
63
- alphaHex: /^([a-f0-9]{1,2})$/i,
64
- hexLong: /^#?([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})?$/i,
65
- hexShort: /^#?([a-f0-9]{3,4})$/i,
66
- prefix: /^#/,
67
- };
68
-
69
- export const COLOR_LENGTHS = {
70
- hexLong: 6,
71
- hexShort: 3,
72
- };
73
-
74
- export const COLOR_KEYS = {
75
- hsl: ['hue', 'saturation', 'lightness'] as Array<keyof HSLColor>,
76
- hsla: [] as Array<keyof HSLAColor>,
77
- hwb: ['hue', 'whiteness', 'blackness'] as Array<keyof HWBColor>,
78
- hwba: [] as Array<keyof HWBAColor>,
79
- rgb: ['red', 'green', 'blue'] as Array<keyof RGBColor>,
80
- rgba: [] as Array<keyof RGBAColor>,
81
- };
82
-
83
- COLOR_KEYS.hsla = [...COLOR_KEYS.hsl, COLOR_ALPHA.name as keyof Alpha] as Array<keyof HSLAColor>;
84
-
85
- COLOR_KEYS.hwba = [...COLOR_KEYS.hwb, COLOR_ALPHA.name as keyof Alpha] as Array<keyof HWBAColor>;
86
-
87
- COLOR_KEYS.rgba = [...COLOR_KEYS.rgb, COLOR_ALPHA.name as keyof Alpha] as Array<keyof RGBAColor>;
88
-
89
- export const COLOR_MAX = {
90
- degree: 360,
91
- hex: 255,
92
- percent: 100,
93
- };
94
-
95
- export const COLOR_PROPERTY = {
96
- name: '$color',
97
- subscription: 'subscription',
98
- };
99
-
100
- export const COLOR_TYPE: ColorTypes = {
101
- all: undefined as unknown as Set<'alpha' | ColorTypeExtended>,
102
- hex: 'hex',
103
- hexa: 'hexa',
104
- hsl: 'hsl',
105
- hsla: 'hsla',
106
- hwb: 'hwb',
107
- hwba: 'hwba',
108
- rgb: 'rgb',
109
- rgba: 'rgba',
110
- };
111
-
112
- COLOR_TYPE.all = new Set([
113
- COLOR_ALPHA.name as 'alpha',
114
- COLOR_TYPE.hex,
115
- COLOR_TYPE.hexa,
116
- COLOR_TYPE.hsl,
117
- COLOR_TYPE.hsla,
118
- COLOR_TYPE.hwb,
119
- COLOR_TYPE.hwba,
120
- COLOR_TYPE.rgb,
121
- COLOR_TYPE.rgba,
122
- ] as Array<'alpha' | ColorTypeExtended>);
123
-
124
- // https://www.w3.org/TR/WCAG20/#relativeluminancedef
125
- export const COLOR_SRGB = {
126
- luminanceBlue: 0.0722,
127
- luminanceExponent: 2.4,
128
- luminanceGreen: 0.7152,
129
- luminanceMinimum: 0.03928,
130
- luminanceModifier: 1.055,
131
- luminanceMultiplier: 12.92,
132
- luminanceOffset: 0.055,
133
- luminanceRed: 0.2126,
134
- luminanceThreshold: 0.625,
135
- };
136
-
137
- // #endregion
@@ -1,83 +0,0 @@
1
- import {color} from './instance';
2
- import {isColor} from './misc/is';
3
- import type {
4
- Color,
5
- ColorType,
6
- ColorTypeExtended,
7
- ColorValue,
8
- ColorValueExtended,
9
- HSLAColor,
10
- HSLColor,
11
- HWBAColor,
12
- HWBColor,
13
- RGBAColor,
14
- RGBColor,
15
- } from './models';
16
-
17
- // #region Functions
18
-
19
- /**
20
- * Get a _Color_ from any kind of value
21
- *
22
- * - Values that can be parsed are: hex(a) color strings, as well as _HSL(A)_, _HWB(A)_, and _RGB(A)_ color objects
23
- * - If the value is unable to be parsed, a black _Color_ will be returned
24
- *
25
- * @param value Original value
26
- * @returns _Color_ instance
27
- */
28
- export function getColor(value: unknown): Color {
29
- return isColor(value) ? value : color(value);
30
- }
31
-
32
- // #endregion
33
-
34
- // #region Exports
35
-
36
- export {
37
- getForegroundColor,
38
- getHexaColor,
39
- getHexColor,
40
- getHslaColor,
41
- getHslColor,
42
- getHwbaColor,
43
- getHwbColor,
44
- getRgbaColor,
45
- getRgbColor,
46
- } from './misc/get';
47
- export {
48
- isColor,
49
- isHexColor,
50
- isHslaColor,
51
- isHslColor,
52
- isHwbaColor,
53
- isHwbColor,
54
- isRgbaColor,
55
- isRgbColor,
56
- } from './misc/is';
57
- export {
58
- getNormalizedHex,
59
- hexToHsl,
60
- hexToHsla,
61
- hexToHwb,
62
- hexToHwba,
63
- hexToRgb,
64
- hexToRgba,
65
- } from './space/hex';
66
- export {hslToHex, hslToHwb, hslToHwba, hslToRgb, hslToRgba} from './space/hsl';
67
- export {hwbToHex, hwbToHsl, hwbToHsla, hwbToRgb, hwbToRgba} from './space/hwb';
68
- export {rgbToHex, rgbToHsl, rgbToHsla, rgbToHwb, rgbToHwba} from './space/rgb';
69
- export type {
70
- Color,
71
- ColorType,
72
- ColorTypeExtended,
73
- ColorValue,
74
- ColorValueExtended,
75
- HSLAColor,
76
- HSLColor,
77
- HWBAColor,
78
- HWBColor,
79
- RGBAColor,
80
- RGBColor,
81
- };
82
-
83
- // #endregion