@oscarpalmer/atoms 0.189.1 → 0.191.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 (72) hide show
  1. package/dist/beacon.d.mts +51 -31
  2. package/dist/beacon.mjs +163 -141
  3. package/dist/color/constants.d.mts +7 -1
  4. package/dist/color/constants.mjs +7 -1
  5. package/dist/color/index.d.mts +3 -4
  6. package/dist/color/index.mjs +4 -4
  7. package/dist/color/instance.d.mts +3 -167
  8. package/dist/color/instance.mjs +62 -219
  9. package/dist/color/misc/alpha.d.mts +1 -1
  10. package/dist/color/misc/alpha.mjs +10 -7
  11. package/dist/color/misc/format.d.mts +7 -0
  12. package/dist/color/misc/format.mjs +20 -0
  13. package/dist/color/misc/get.d.mts +1 -2
  14. package/dist/color/misc/get.mjs +19 -19
  15. package/dist/color/misc/is.d.mts +1 -38
  16. package/dist/color/misc/is.mjs +1 -37
  17. package/dist/color/misc/state.d.mts +3 -2
  18. package/dist/color/misc/state.mjs +69 -83
  19. package/dist/color/models.d.mts +185 -6
  20. package/dist/color/space/hex.d.mts +3 -2
  21. package/dist/color/space/hex.mjs +13 -1
  22. package/dist/color/space/hsl.d.mts +3 -2
  23. package/dist/color/space/hsl.mjs +13 -1
  24. package/dist/color/space/hwb.d.mts +3 -2
  25. package/dist/color/space/hwb.mjs +13 -1
  26. package/dist/color/space/rgb.d.mts +3 -2
  27. package/dist/color/space/rgb.mjs +14 -2
  28. package/dist/function/memoize.d.mts +3 -9
  29. package/dist/function/memoize.mjs +43 -90
  30. package/dist/function/once.mjs +16 -4
  31. package/dist/herald.d.mts +19 -15
  32. package/dist/herald.mjs +79 -89
  33. package/dist/index.d.mts +195 -190
  34. package/dist/index.mjs +918 -1149
  35. package/dist/internal/result.d.mts +6 -6
  36. package/dist/internal/result.mjs +1 -1
  37. package/dist/internal/value/has.d.mts +2 -2
  38. package/dist/logger.d.mts +7 -7
  39. package/dist/logger.mjs +72 -51
  40. package/dist/promise/helpers.d.mts +2 -2
  41. package/dist/promise/helpers.mjs +2 -2
  42. package/dist/queue.d.mts +24 -12
  43. package/dist/queue.mjs +288 -346
  44. package/dist/string/fuzzy.d.mts +4 -13
  45. package/dist/string/fuzzy.mjs +15 -41
  46. package/package.json +3 -3
  47. package/src/beacon.ts +262 -160
  48. package/src/color/constants.ts +12 -0
  49. package/src/color/index.ts +32 -14
  50. package/src/color/instance.ts +87 -248
  51. package/src/color/misc/alpha.ts +12 -6
  52. package/src/color/misc/format.ts +29 -0
  53. package/src/color/misc/get.ts +24 -17
  54. package/src/color/misc/is.ts +7 -37
  55. package/src/color/misc/state.ts +115 -127
  56. package/src/color/models.ts +212 -6
  57. package/src/color/space/hex.ts +34 -1
  58. package/src/color/space/hsl.ts +40 -2
  59. package/src/color/space/hwb.ts +32 -2
  60. package/src/color/space/rgb.ts +33 -3
  61. package/src/function/memoize.ts +74 -65
  62. package/src/function/once.ts +4 -0
  63. package/src/herald.ts +136 -94
  64. package/src/internal/result.ts +6 -6
  65. package/src/internal/value/has.ts +2 -2
  66. package/src/logger.ts +93 -42
  67. package/src/promise/helpers.ts +2 -2
  68. package/src/queue.ts +480 -375
  69. package/src/string/fuzzy.ts +36 -31
  70. package/dist/color/misc/index.d.mts +0 -7
  71. package/dist/color/misc/index.mjs +0 -15
  72. package/src/color/misc/index.ts +0 -30
package/dist/beacon.d.mts CHANGED
@@ -2,12 +2,15 @@
2
2
  /**
3
3
  * A beacon is a lighthouse, holding an observable value that can be subscribed to and emitted from
4
4
  */
5
- declare class Beacon<Value> {
6
- #private;
5
+ type Beacon<Value> = {
7
6
  /**
8
7
  * Is the beacon active?
9
8
  */
10
9
  get active(): boolean;
10
+ /**
11
+ * Is the beacon closed?
12
+ */
13
+ get closed(): boolean;
11
14
  /**
12
15
  * The observable that can be subscribed to
13
16
  */
@@ -16,11 +19,10 @@ declare class Beacon<Value> {
16
19
  * The current value
17
20
  */
18
21
  get value(): Value;
19
- constructor(value: Value, options?: BeaconOptions<Value>);
20
22
  /**
21
- * Destroy the beacon
23
+ * Close the beacon
22
24
  */
23
- destroy(): void;
25
+ close(): void;
24
26
  /**
25
27
  * Emit a new value
26
28
  *
@@ -39,7 +41,7 @@ declare class Beacon<Value> {
39
41
  * Finish the beacon
40
42
  */
41
43
  finish(): void;
42
- }
44
+ };
43
45
  /**
44
46
  * Options for Beacon
45
47
  */
@@ -54,16 +56,19 @@ type BeaconOptions<Value> = {
54
56
  */
55
57
  equal?: (first: Value, second: Value) => boolean;
56
58
  };
57
- /**
58
- * An observable holds a value and allows observers to subscribe to changes in that value
59
- */
60
- declare class Observable<Value> {
61
- #private;
62
- constructor(instance: Beacon<Value>, observers: Map<Subscription<Value>, Observer<Value>>);
59
+ type Observable<Value> = {
60
+ /**
61
+ * Is the observable active?
62
+ */
63
+ get active(): boolean;
63
64
  /**
64
- * Destroy the observable
65
+ * Is the observable closed?
65
66
  */
66
- destroy(): void;
67
+ get closed(): boolean;
68
+ /**
69
+ * Close the observable
70
+ */
71
+ close(): void;
67
72
  /**
68
73
  * Subscribe to value changes
69
74
  *
@@ -72,19 +77,14 @@ declare class Observable<Value> {
72
77
  * @param onComplete Callback for when the observable is completed
73
78
  * @returns Subscription to the observable
74
79
  */
75
- subscribe(onNext: (value: Value) => void, onError?: (error: Error) => void, onComplete?: () => void): Subscription<Value>;
80
+ subscribe(onNext: (value: Value) => void, onError?: (error: Error) => void, onComplete?: () => void): Subscription;
76
81
  /**
77
82
  * Subscribe to value changes
78
83
  *
79
84
  * @param observer Observer for changes
80
85
  * @returns Subscription to the observable
81
86
  */
82
- subscribe(observer: Observer<Value>): Subscription<Value>;
83
- }
84
- type ObservableState<Value> = {
85
- beacon: Beacon<Value>;
86
- closed: boolean;
87
- observers: Map<Subscription<Value>, Observer<Value>>;
87
+ subscribe(observer: Observer<Value>): Subscription;
88
88
  };
89
89
  /**
90
90
  * An observer receives notifications from an observable
@@ -103,25 +103,24 @@ type Observer<Value> = {
103
103
  */
104
104
  next?: (value: Value) => void;
105
105
  };
106
- /**
107
- * A subscription represents an active subscription to an observable, holding its state and allowing it to be destroyed or unsubscribed from
108
- */
109
- declare class Subscription<Value> {
110
- #private;
111
- constructor(state: ObservableState<Value>);
106
+ type Subscription = {
107
+ /**
108
+ * Is the subscription active?
109
+ */
110
+ get active(): boolean;
112
111
  /**
113
112
  * Is the subscription closed?
114
113
  */
115
114
  get closed(): boolean;
116
115
  /**
117
- * Destroy the subscription
116
+ * Close the subscription
118
117
  */
119
- destroy(): void;
118
+ close(): void;
120
119
  /**
121
120
  * Unsubscribe from its observable
122
121
  */
123
122
  unsubscribe(): void;
124
- }
123
+ };
125
124
  /**
126
125
  * Create a new beacon
127
126
  *
@@ -130,5 +129,26 @@ declare class Subscription<Value> {
130
129
  * @returns Beacon instance
131
130
  */
132
131
  declare function beacon<Value>(value: Value, options?: BeaconOptions<Value>): Beacon<Value>;
132
+ /**
133
+ * Is the value a beacon?
134
+ *
135
+ * @param value Value to check
136
+ * @returns `true` if the value is a beacon, otherwise `false`
137
+ */
138
+ declare function isBeacon<Value = unknown>(value: unknown): value is Beacon<Value>;
139
+ /**
140
+ * Is the value an observable?
141
+ *
142
+ * @param value Value to check
143
+ * @returns `true` if the value is an observable, otherwise `false`
144
+ */
145
+ declare function isObservable<Value = unknown>(value: unknown): value is Observable<Value>;
146
+ /**
147
+ * Is the value a subscription?
148
+ *
149
+ * @param value Value to check
150
+ * @returns `true` if the value is a subscription, otherwise `false`
151
+ */
152
+ declare function isSubscription(value: unknown): value is Subscription;
133
153
  //#endregion
134
- export { type Beacon, type BeaconOptions, type Observable, type Observer, type Subscription, beacon };
154
+ export { Beacon, BeaconOptions, Observable, Subscription, beacon, isBeacon, isObservable, isSubscription };
package/dist/beacon.mjs CHANGED
@@ -2,141 +2,6 @@ import { noop } from "./internal/function/misc.mjs";
2
2
  import { isPlainObject } from "./internal/is.mjs";
3
3
  //#region src/beacon.ts
4
4
  /**
5
- * A beacon is a lighthouse, holding an observable value that can be subscribed to and emitted from
6
- */
7
- var Beacon = class {
8
- #options;
9
- #state;
10
- /**
11
- * Is the beacon active?
12
- */
13
- get active() {
14
- return this.#state.active;
15
- }
16
- /**
17
- * The observable that can be subscribed to
18
- */
19
- get observable() {
20
- if (!this.#state.active) throw new Error(MESSAGE_BEACON);
21
- return this.#state.observable;
22
- }
23
- /**
24
- * The current value
25
- */
26
- get value() {
27
- return this.#state.value;
28
- }
29
- constructor(value, options) {
30
- const observers = /* @__PURE__ */ new Map();
31
- this.#options = getBeaconOptions(options);
32
- this.#state = {
33
- observers,
34
- value,
35
- active: true,
36
- observable: new Observable(this, observers)
37
- };
38
- }
39
- /**
40
- * Destroy the beacon
41
- */
42
- destroy() {
43
- finishBeacon(this.#state, false);
44
- }
45
- /**
46
- * Emit a new value
47
- *
48
- * @param value Value to set and emit
49
- * @param finish Finish the beacon after emitting? _(defaults to `false`)_
50
- */
51
- emit(value, finish) {
52
- this.#on(TYPE_NEXT, value, finish);
53
- }
54
- /**
55
- * Emit an error
56
- *
57
- * @param value Error to emit
58
- * @param finish Finish the beacon after emitting? _(defaults to `false`)_
59
- */
60
- error(value, finish) {
61
- this.#on(TYPE_ERROR, value, finish);
62
- }
63
- /**
64
- * Finish the beacon
65
- */
66
- finish() {
67
- finishBeacon(this.#state, true);
68
- }
69
- #on(type, value, finish) {
70
- if (!this.#state.active) return;
71
- if (type === TYPE_NEXT) {
72
- if (this.#options.equal(this.#state.value, value)) return;
73
- this.#state.value = value;
74
- }
75
- for (const [, observer] of this.#state.observers) observer[type]?.(value);
76
- if (finish === true) finishBeacon(this.#state, true);
77
- }
78
- };
79
- /**
80
- * An observable holds a value and allows observers to subscribe to changes in that value
81
- */
82
- var Observable = class {
83
- #state;
84
- constructor(instance, observers) {
85
- this.#state = {
86
- observers,
87
- beacon: instance,
88
- closed: false
89
- };
90
- }
91
- /**
92
- * Destroy the observable
93
- */
94
- destroy() {
95
- this.#state.closed = true;
96
- }
97
- subscribe(first, second, third) {
98
- if (this.#state.closed) throw new Error(MESSAGE_OBSERVABLE);
99
- const observer = getObserver(first, second, third);
100
- const instance = new Subscription(this.#state);
101
- this.#state.observers.set(instance, observer);
102
- observer.next?.(this.#state.beacon.value);
103
- return instance;
104
- }
105
- };
106
- /**
107
- * A subscription represents an active subscription to an observable, holding its state and allowing it to be destroyed or unsubscribed from
108
- */
109
- var Subscription = class {
110
- #state;
111
- constructor(state) {
112
- this.#state = {
113
- ...state,
114
- closed: false
115
- };
116
- }
117
- /**
118
- * Is the subscription closed?
119
- */
120
- get closed() {
121
- return this.#state.closed || !this.#state.beacon.active;
122
- }
123
- /**
124
- * Destroy the subscription
125
- */
126
- destroy() {
127
- if (!this.#state.closed) this.unsubscribe();
128
- }
129
- /**
130
- * Unsubscribe from its observable
131
- */
132
- unsubscribe() {
133
- if (!this.#state.closed) {
134
- this.#state.closed = true;
135
- this.#state.observers.delete(this);
136
- }
137
- }
138
- };
139
- /**
140
5
  * Create a new beacon
141
6
  *
142
7
  * @param value Initial value
@@ -144,7 +9,54 @@ var Subscription = class {
144
9
  * @returns Beacon instance
145
10
  */
146
11
  function beacon(value, options) {
147
- return new Beacon(value, options);
12
+ const state = {
13
+ value,
14
+ active: true,
15
+ observable: void 0,
16
+ observers: /* @__PURE__ */ new Map(),
17
+ options: getBeaconOptions(options)
18
+ };
19
+ const instance = {
20
+ close: () => {
21
+ finishBeacon(state, false);
22
+ },
23
+ emit: (value, finish) => {
24
+ update(TYPE_NEXT, state, value, finish);
25
+ },
26
+ error: (value, finish) => {
27
+ update(TYPE_ERROR, state, value, finish);
28
+ },
29
+ finish: () => {
30
+ finishBeacon(state, true);
31
+ }
32
+ };
33
+ Object.defineProperties(instance, {
34
+ [KEY_BEACON]: {
35
+ enumerable: false,
36
+ value: NAME_BEACON
37
+ },
38
+ active: {
39
+ enumerable: true,
40
+ get: () => state.active
41
+ },
42
+ closed: {
43
+ enumerable: true,
44
+ get: () => !state.active
45
+ },
46
+ observable: {
47
+ enumerable: true,
48
+ get: () => {
49
+ if (!state.active) throw new Error(MESSAGE_BEACON);
50
+ state.observable ??= observe(state);
51
+ return state.observable;
52
+ }
53
+ },
54
+ value: {
55
+ enumerable: true,
56
+ get: () => state.value
57
+ }
58
+ });
59
+ return Object.freeze(instance);
148
60
  }
149
61
  function finishBeacon(state, emit) {
150
62
  if (!state.active) return;
@@ -154,10 +66,11 @@ function finishBeacon(state, emit) {
154
66
  for (let index = 0; index < length; index += 1) {
155
67
  const [subscription, observer] = entries[index];
156
68
  if (emit) observer.complete?.();
157
- subscription.destroy();
69
+ subscription.close();
158
70
  }
159
- state.observable?.destroy();
71
+ state.observable?.close();
160
72
  state.observers.clear();
73
+ state.observable = void 0;
161
74
  }
162
75
  function getBeaconOptions(input) {
163
76
  const options = isPlainObject(input) ? input : {};
@@ -181,9 +94,118 @@ function getObserver(first, second, third) {
181
94
  }
182
95
  return observer;
183
96
  }
184
- const MESSAGE_BEACON = "Cannot retrieve observable from a destroyed beacon";
185
- const MESSAGE_OBSERVABLE = "Cannot subscribe to a destroyed observable";
97
+ /**
98
+ * Is the value a beacon?
99
+ *
100
+ * @param value Value to check
101
+ * @returns `true` if the value is a beacon, otherwise `false`
102
+ */
103
+ function isBeacon(value) {
104
+ return isBeaconInstance(NAME_BEACON, value);
105
+ }
106
+ function isBeaconInstance(name, value) {
107
+ return isPlainObject(value) && value[KEY_BEACON] === name;
108
+ }
109
+ /**
110
+ * Is the value an observable?
111
+ *
112
+ * @param value Value to check
113
+ * @returns `true` if the value is an observable, otherwise `false`
114
+ */
115
+ function isObservable(value) {
116
+ return isBeaconInstance(NAME_OBSERVABLE, value);
117
+ }
118
+ /**
119
+ * Is the value a subscription?
120
+ *
121
+ * @param value Value to check
122
+ * @returns `true` if the value is a subscription, otherwise `false`
123
+ */
124
+ function isSubscription(value) {
125
+ return isBeaconInstance(NAME_SUBSCRIPTION, value);
126
+ }
127
+ function observe(beacon) {
128
+ const state = {
129
+ beacon,
130
+ active: beacon.active
131
+ };
132
+ const instance = {
133
+ close: () => {
134
+ state.active = false;
135
+ },
136
+ subscribe(first, second, third) {
137
+ if (!beacon.active || !state.active) throw new Error(MESSAGE_OBSERVABLE);
138
+ const observer = getObserver(first, second, third);
139
+ const subscription = subscribe(state);
140
+ beacon.observers.set(subscription, observer);
141
+ observer.next?.(beacon.value);
142
+ return subscription;
143
+ }
144
+ };
145
+ Object.defineProperties(instance, {
146
+ [KEY_BEACON]: {
147
+ enumerable: false,
148
+ value: NAME_OBSERVABLE
149
+ },
150
+ active: {
151
+ enumerable: true,
152
+ get: () => beacon.active && state.active
153
+ },
154
+ closed: {
155
+ enumerable: true,
156
+ get: () => !beacon.active || !state.active
157
+ }
158
+ });
159
+ return Object.freeze(instance);
160
+ }
161
+ function subscribe(observable) {
162
+ function unsubscribe() {
163
+ if (active) {
164
+ active = false;
165
+ observable.beacon.observers.delete(instance);
166
+ }
167
+ }
168
+ let active = true;
169
+ const instance = {
170
+ close: () => {
171
+ unsubscribe();
172
+ },
173
+ unsubscribe: () => {
174
+ unsubscribe();
175
+ }
176
+ };
177
+ Object.defineProperties(instance, {
178
+ [KEY_BEACON]: {
179
+ enumerable: false,
180
+ value: NAME_SUBSCRIPTION
181
+ },
182
+ active: {
183
+ enumerable: true,
184
+ get: () => observable.beacon.active && observable.active && active
185
+ },
186
+ closed: {
187
+ enumerable: true,
188
+ get: () => !observable.beacon.active || !observable.active || !active
189
+ }
190
+ });
191
+ return Object.freeze(instance);
192
+ }
193
+ function update(type, state, value, finish) {
194
+ if (!state.active) return;
195
+ if (type === TYPE_NEXT) {
196
+ if (state.options.equal(state.value, value)) return;
197
+ state.value = value;
198
+ }
199
+ for (const [, observer] of state.observers) observer[type]?.(value);
200
+ if (finish === true) finishBeacon(state, true);
201
+ }
202
+ const KEY_BEACON = "$beacon";
203
+ const MESSAGE_BEACON = "Cannot retrieve observable from a closed beacon";
204
+ const MESSAGE_OBSERVABLE = "Cannot subscribe to a closed observable";
205
+ const NAME_BEACON = "beacon";
206
+ const NAME_OBSERVABLE = "observable";
207
+ const NAME_SUBSCRIPTION = "subscription";
186
208
  const TYPE_ERROR = "error";
187
209
  const TYPE_NEXT = "next";
188
210
  //#endregion
189
- export { beacon };
211
+ export { beacon, isBeacon, isObservable, isSubscription };
@@ -8,6 +8,7 @@ declare const DEFAULT_ALPHA: Alpha;
8
8
  declare const DEFAULT_HSL: HSLColor;
9
9
  declare const DEFAULT_HWB: HWBColor;
10
10
  declare const DEFAULT_RGB: RGBColor;
11
+ declare const EXPRESSION_ALPHA_HEX: RegExp;
11
12
  declare const EXPRESSION_HEX_LONG: RegExp;
12
13
  declare const EXPRESSION_HEX_SHORT: RegExp;
13
14
  declare const EXPRESSION_PREFIX: RegExp;
@@ -24,6 +25,11 @@ declare const KEYS_RGBA: Array<keyof RGBAColor>;
24
25
  declare const MAX_DEGREE = 360;
25
26
  declare const MAX_HEX = 255;
26
27
  declare const MAX_PERCENT = 100;
28
+ declare const PROPERTY_COLOR = "$color";
29
+ declare const TYPE_HEX = "hex";
30
+ declare const TYPE_HSL = "hsl";
31
+ declare const TYPE_HWB = "hwb";
32
+ declare const TYPE_RGB = "rgb";
27
33
  declare const SRGB_LUMINANCE_BLUE = 0.0722;
28
34
  declare const SRGB_LUMINANCE_EXPONENT = 2.4;
29
35
  declare const SRGB_LUMINANCE_GREEN = 0.7152;
@@ -34,4 +40,4 @@ declare const SRGB_LUMINANCE_OFFSET = 0.055;
34
40
  declare const SRGB_LUMINANCE_RED = 0.2126;
35
41
  declare const SRGB_LUMINANCE_THRESHOLD = 0.625;
36
42
  //#endregion
37
- export { ALPHA_FULL_HEX_LONG, ALPHA_FULL_HEX_SHORT, ALPHA_NONE_HEX, ALPHA_NONE_VALUE, DEFAULT_ALPHA, DEFAULT_HSL, DEFAULT_HWB, DEFAULT_RGB, EXPRESSION_HEX_LONG, EXPRESSION_HEX_SHORT, EXPRESSION_PREFIX, HEX_BLACK, HEX_WHITE, KEYS_HSL, KEYS_HSLA, KEYS_HWB, KEYS_HWBA, KEYS_RGB, KEYS_RGBA, LENGTH_LONG, LENGTH_SHORT, MAX_DEGREE, MAX_HEX, MAX_PERCENT, SRGB_LUMINANCE_BLUE, SRGB_LUMINANCE_EXPONENT, SRGB_LUMINANCE_GREEN, SRGB_LUMINANCE_MINIMUM, SRGB_LUMINANCE_MODIFIER, SRGB_LUMINANCE_MULTIPLIER, SRGB_LUMINANCE_OFFSET, SRGB_LUMINANCE_RED, SRGB_LUMINANCE_THRESHOLD };
43
+ export { ALPHA_FULL_HEX_LONG, ALPHA_FULL_HEX_SHORT, ALPHA_NONE_HEX, ALPHA_NONE_VALUE, DEFAULT_ALPHA, DEFAULT_HSL, DEFAULT_HWB, DEFAULT_RGB, EXPRESSION_ALPHA_HEX, EXPRESSION_HEX_LONG, EXPRESSION_HEX_SHORT, EXPRESSION_PREFIX, HEX_BLACK, HEX_WHITE, KEYS_HSL, KEYS_HSLA, KEYS_HWB, KEYS_HWBA, KEYS_RGB, KEYS_RGBA, LENGTH_LONG, LENGTH_SHORT, MAX_DEGREE, MAX_HEX, MAX_PERCENT, PROPERTY_COLOR, SRGB_LUMINANCE_BLUE, SRGB_LUMINANCE_EXPONENT, SRGB_LUMINANCE_GREEN, SRGB_LUMINANCE_MINIMUM, SRGB_LUMINANCE_MODIFIER, SRGB_LUMINANCE_MULTIPLIER, SRGB_LUMINANCE_OFFSET, SRGB_LUMINANCE_RED, SRGB_LUMINANCE_THRESHOLD, TYPE_HEX, TYPE_HSL, TYPE_HWB, TYPE_RGB };
@@ -22,6 +22,7 @@ const DEFAULT_RGB = {
22
22
  green: 0,
23
23
  red: 0
24
24
  };
25
+ const EXPRESSION_ALPHA_HEX = /^([a-f0-9]{1,2})$/i;
25
26
  const EXPRESSION_HEX_LONG = /^#?([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})?$/i;
26
27
  const EXPRESSION_HEX_SHORT = /^#?([a-f0-9]{3,4})$/i;
27
28
  const EXPRESSION_PREFIX = /^#/;
@@ -50,6 +51,11 @@ const KEYS_RGBA = [...KEYS_RGB, "alpha"];
50
51
  const MAX_DEGREE = 360;
51
52
  const MAX_HEX = 255;
52
53
  const MAX_PERCENT = 100;
54
+ const PROPERTY_COLOR = "$color";
55
+ const TYPE_HEX = "hex";
56
+ const TYPE_HSL = "hsl";
57
+ const TYPE_HWB = "hwb";
58
+ const TYPE_RGB = "rgb";
53
59
  const SRGB_LUMINANCE_BLUE = .0722;
54
60
  const SRGB_LUMINANCE_EXPONENT = 2.4;
55
61
  const SRGB_LUMINANCE_GREEN = .7152;
@@ -60,4 +66,4 @@ const SRGB_LUMINANCE_OFFSET = .055;
60
66
  const SRGB_LUMINANCE_RED = .2126;
61
67
  const SRGB_LUMINANCE_THRESHOLD = .625;
62
68
  //#endregion
63
- export { ALPHA_FULL_HEX_LONG, ALPHA_FULL_HEX_SHORT, ALPHA_NONE_HEX, ALPHA_NONE_VALUE, DEFAULT_ALPHA, DEFAULT_HSL, DEFAULT_HWB, DEFAULT_RGB, EXPRESSION_HEX_LONG, EXPRESSION_HEX_SHORT, EXPRESSION_PREFIX, HEX_BLACK, HEX_WHITE, KEYS_HSL, KEYS_HSLA, KEYS_HWB, KEYS_HWBA, KEYS_RGB, KEYS_RGBA, LENGTH_LONG, LENGTH_SHORT, MAX_DEGREE, MAX_HEX, MAX_PERCENT, SRGB_LUMINANCE_BLUE, SRGB_LUMINANCE_EXPONENT, SRGB_LUMINANCE_GREEN, SRGB_LUMINANCE_MINIMUM, SRGB_LUMINANCE_MODIFIER, SRGB_LUMINANCE_MULTIPLIER, SRGB_LUMINANCE_OFFSET, SRGB_LUMINANCE_RED, SRGB_LUMINANCE_THRESHOLD };
69
+ export { ALPHA_FULL_HEX_LONG, ALPHA_FULL_HEX_SHORT, ALPHA_NONE_HEX, ALPHA_NONE_VALUE, DEFAULT_ALPHA, DEFAULT_HSL, DEFAULT_HWB, DEFAULT_RGB, EXPRESSION_ALPHA_HEX, EXPRESSION_HEX_LONG, EXPRESSION_HEX_SHORT, EXPRESSION_PREFIX, HEX_BLACK, HEX_WHITE, KEYS_HSL, KEYS_HSLA, KEYS_HWB, KEYS_HWBA, KEYS_RGB, KEYS_RGBA, LENGTH_LONG, LENGTH_SHORT, MAX_DEGREE, MAX_HEX, MAX_PERCENT, PROPERTY_COLOR, SRGB_LUMINANCE_BLUE, SRGB_LUMINANCE_EXPONENT, SRGB_LUMINANCE_GREEN, SRGB_LUMINANCE_MINIMUM, SRGB_LUMINANCE_MODIFIER, SRGB_LUMINANCE_MULTIPLIER, SRGB_LUMINANCE_OFFSET, SRGB_LUMINANCE_RED, SRGB_LUMINANCE_THRESHOLD, TYPE_HEX, TYPE_HSL, TYPE_HWB, TYPE_RGB };
@@ -1,7 +1,6 @@
1
- import { HSLAColor, HSLColor, HWBAColor, HWBColor, RGBAColor, RGBColor } from "./models.mjs";
2
- import { Color } from "./instance.mjs";
1
+ import { Color, ColorType, ColorTypeExtended, ColorValue, ColorValueExtended, HSLAColor, HSLColor, HWBAColor, HWBColor, RGBAColor, RGBColor } from "./models.mjs";
3
2
  import { getForegroundColor, getHexColor, getHexaColor, getHslColor, getHslaColor, getHwbColor, getHwbaColor, getRgbColor, getRgbaColor } from "./misc/get.mjs";
4
- import { isColor, isHexColor, isHslColor, isHslLike, isHslaColor, isHwbColor, isHwbLike, isHwbaColor, isHwbaLike, isRgbColor, isRgbLike, isRgbaColor } from "./misc/is.mjs";
3
+ import { isColor, isHexColor, isHslColor, isHslaColor, isHwbColor, isHwbaColor, isRgbColor, isRgbaColor } from "./misc/is.mjs";
5
4
  import { getNormalizedHex, hexToHsl, hexToHsla, hexToHwb, hexToHwba, hexToRgb, hexToRgba } from "./space/hex.mjs";
6
5
  import { hslToHex, hslToHwb, hslToHwba, hslToRgb, hslToRgba } from "./space/hsl.mjs";
7
6
  import { hwbToHex, hwbToHsl, hwbToHsla, hwbToRgb, hwbToRgba } from "./space/hwb.mjs";
@@ -18,4 +17,4 @@ import { rgbToHex, rgbToHsl, rgbToHsla, rgbToHwb, rgbToHwba } from "./space/rgb.
18
17
  */
19
18
  declare function getColor(value: unknown): Color;
20
19
  //#endregion
21
- export { type Color, type HSLAColor, type HSLColor, type HWBAColor, type HWBColor, type RGBAColor, type RGBColor, getColor, getForegroundColor, getHexColor, getHexaColor, getHslColor, getHslaColor, getHwbColor, getHwbaColor, getNormalizedHex, getRgbColor, getRgbaColor, hexToHsl, hexToHsla, hexToHwb, hexToHwba, hexToRgb, hexToRgba, hslToHex, hslToHwb, hslToHwba, hslToRgb, hslToRgba, hwbToHex, hwbToHsl, hwbToHsla, hwbToRgb, hwbToRgba, isColor, isHexColor, isHslColor, isHslLike, isHslaColor, isHwbColor, isHwbLike, isHwbaColor, isHwbaLike, isRgbColor, isRgbLike, isRgbaColor, rgbToHex, rgbToHsl, rgbToHsla, rgbToHwb, rgbToHwba };
20
+ export { type Color, type ColorType, type ColorTypeExtended, type ColorValue, type ColorValueExtended, type HSLAColor, type HSLColor, type HWBAColor, type HWBColor, type RGBAColor, type RGBColor, getColor, getForegroundColor, getHexColor, getHexaColor, getHslColor, getHslaColor, getHwbColor, getHwbaColor, getNormalizedHex, getRgbColor, getRgbaColor, hexToHsl, hexToHsla, hexToHwb, hexToHwba, hexToRgb, hexToRgba, hslToHex, hslToHwb, hslToHwba, hslToRgb, hslToRgba, hwbToHex, hwbToHsl, hwbToHsla, hwbToRgb, hwbToRgba, isColor, isHexColor, isHslColor, isHslaColor, isHwbColor, isHwbaColor, isRgbColor, isRgbaColor, rgbToHex, rgbToHsl, rgbToHsla, rgbToHwb, rgbToHwba };
@@ -1,10 +1,10 @@
1
1
  import { getForegroundColor, getHexColor, getHexaColor, getHslColor, getHslaColor, getHwbColor, getHwbaColor, getRgbColor, getRgbaColor } from "./misc/get.mjs";
2
- import { isColor, isHexColor, isHslColor, isHslLike, isHslaColor, isHwbColor, isHwbLike, isHwbaColor, isHwbaLike, isRgbColor, isRgbLike, isRgbaColor } from "./misc/is.mjs";
2
+ import { isColor, isHexColor, isHslColor, isHslaColor, isHwbColor, isHwbaColor, isRgbColor, isRgbaColor } from "./misc/is.mjs";
3
3
  import { rgbToHex, rgbToHsl, rgbToHsla, rgbToHwb, rgbToHwba } from "./space/rgb.mjs";
4
4
  import { getNormalizedHex, hexToHsl, hexToHsla, hexToHwb, hexToHwba, hexToRgb, hexToRgba } from "./space/hex.mjs";
5
5
  import { hslToHex, hslToHwb, hslToHwba, hslToRgb, hslToRgba } from "./space/hsl.mjs";
6
6
  import { hwbToHex, hwbToHsl, hwbToHsla, hwbToRgb, hwbToRgba } from "./space/hwb.mjs";
7
- import { Color } from "./instance.mjs";
7
+ import { color } from "./instance.mjs";
8
8
  //#region src/color/index.ts
9
9
  /**
10
10
  * Get a _Color_ from any kind of value
@@ -16,7 +16,7 @@ import { Color } from "./instance.mjs";
16
16
  * @returns _Color_ instance
17
17
  */
18
18
  function getColor(value) {
19
- return isColor(value) ? value : new Color(value);
19
+ return isColor(value) ? value : color(value);
20
20
  }
21
21
  //#endregion
22
- export { getColor, getForegroundColor, getHexColor, getHexaColor, getHslColor, getHslaColor, getHwbColor, getHwbaColor, getNormalizedHex, getRgbColor, getRgbaColor, hexToHsl, hexToHsla, hexToHwb, hexToHwba, hexToRgb, hexToRgba, hslToHex, hslToHwb, hslToHwba, hslToRgb, hslToRgba, hwbToHex, hwbToHsl, hwbToHsla, hwbToRgb, hwbToRgba, isColor, isHexColor, isHslColor, isHslLike, isHslaColor, isHwbColor, isHwbLike, isHwbaColor, isHwbaLike, isRgbColor, isRgbLike, isRgbaColor, rgbToHex, rgbToHsl, rgbToHsla, rgbToHwb, rgbToHwba };
22
+ export { getColor, getForegroundColor, getHexColor, getHexaColor, getHslColor, getHslaColor, getHwbColor, getHwbaColor, getNormalizedHex, getRgbColor, getRgbaColor, hexToHsl, hexToHsla, hexToHwb, hexToHwba, hexToRgb, hexToRgba, hslToHex, hslToHwb, hslToHwba, hslToRgb, hslToRgba, hwbToHex, hwbToHsl, hwbToHsla, hwbToRgb, hwbToRgba, isColor, isHexColor, isHslColor, isHslaColor, isHwbColor, isHwbaColor, isRgbColor, isRgbaColor, rgbToHex, rgbToHsl, rgbToHsla, rgbToHwb, rgbToHwba };