@oscarpalmer/atoms 0.211.0 → 0.212.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/color/models.d.mts +1 -1
- package/dist/herald.d.mts +2 -1
- package/dist/index.d.mts +33 -31
- package/dist/index.mjs +13 -11
- package/dist/internal/herald.d.mts +2 -38
- package/dist/internal/herald.mjs +4 -14
- package/dist/internal/models/herald.model.d.mts +60 -0
- package/dist/internal/models/herald.model.mjs +15 -0
- package/package.json +1 -1
package/dist/color/models.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Subscription } from "../internal/subscription.mjs";
|
|
2
|
-
import { Herald, HeraldEvents } from "../internal/herald.mjs";
|
|
2
|
+
import { Herald, HeraldEvents } from "../internal/models/herald.model.mjs";
|
|
3
3
|
import { COLOR_SYMBOL } from "./constants.mjs";
|
|
4
4
|
//#region src/color/models.d.ts
|
|
5
5
|
export type Alpha = {
|
package/dist/herald.d.mts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
+
import { Herald, HeraldEvents } from "./internal/models/herald.model.mjs";
|
|
1
2
|
import { herald, isHerald, isHeraldEvents, isHeraldSubscription } from "./internal/herald.mjs";
|
|
2
|
-
export { herald, isHerald, isHeraldEvents, isHeraldSubscription };
|
|
3
|
+
export { type Herald, type HeraldEvents, herald, isHerald, isHeraldEvents, isHeraldSubscription };
|
package/dist/index.d.mts
CHANGED
|
@@ -6795,7 +6795,7 @@ export declare function isBeaconSubscription(value: unknown): value is Subscript
|
|
|
6795
6795
|
*/
|
|
6796
6796
|
export declare function isObservable<Value = unknown>(value: unknown): value is Observable<Value>;
|
|
6797
6797
|
//#endregion
|
|
6798
|
-
//#region src/internal/herald.d.ts
|
|
6798
|
+
//#region src/internal/models/herald.model.d.ts
|
|
6799
6799
|
type Herald<Events extends Record<string, GenericCallback>> = {
|
|
6800
6800
|
readonly events: HeraldEvents<Events>;
|
|
6801
6801
|
/**
|
|
@@ -6833,35 +6833,6 @@ type HeraldOptions<Events extends Record<string, GenericCallback>> = {
|
|
|
6833
6833
|
property?: SubscriptionProperty;
|
|
6834
6834
|
onCreate?: HeraldOnCreate<Events>;
|
|
6835
6835
|
};
|
|
6836
|
-
/**
|
|
6837
|
-
* Create a _Herald_ for announcing named events
|
|
6838
|
-
*
|
|
6839
|
-
* @param names Event names
|
|
6840
|
-
* @param property Optional property for subscription identification _(defaults to `$herald`)_
|
|
6841
|
-
* @returns _Herald_ instance
|
|
6842
|
-
*/
|
|
6843
|
-
export declare function herald<Events extends Record<string, GenericCallback>>(options: HeraldOptions<Events>): Herald<Events>;
|
|
6844
|
-
/**
|
|
6845
|
-
* Is the value a herald?
|
|
6846
|
-
*
|
|
6847
|
-
* @param value Value to check
|
|
6848
|
-
* @returns `true` if the value is a herald, otherwise `false`
|
|
6849
|
-
*/
|
|
6850
|
-
export declare function isHerald<Events extends Record<string, GenericCallback> = Record<string, GenericCallback>>(value: unknown): value is Herald<Events>;
|
|
6851
|
-
/**
|
|
6852
|
-
* Is the value events for a herald?
|
|
6853
|
-
*
|
|
6854
|
-
* @param value Value to check
|
|
6855
|
-
* @returns `true` if the value is events for a herald, otherwise `false`
|
|
6856
|
-
*/
|
|
6857
|
-
export declare function isHeraldEvents<Events extends Record<string, GenericCallback> = Record<string, GenericCallback>>(value: unknown): value is HeraldEvents<Events>;
|
|
6858
|
-
/**
|
|
6859
|
-
* Is the value a herald subscription?
|
|
6860
|
-
*
|
|
6861
|
-
* @param value Value to check
|
|
6862
|
-
* @returns `true` if the value is a herald subscription, otherwise `false`
|
|
6863
|
-
*/
|
|
6864
|
-
export declare function isHeraldSubscription(value: unknown): value is Subscription;
|
|
6865
6836
|
//#endregion
|
|
6866
6837
|
//#region src/color/models.d.ts
|
|
6867
6838
|
/**
|
|
@@ -7539,6 +7510,37 @@ export declare function rgbToHwba(rgb: RGBAColor | RGBColor): HWBAColor;
|
|
|
7539
7510
|
*/
|
|
7540
7511
|
export declare function getColor(value: unknown): Color;
|
|
7541
7512
|
//#endregion
|
|
7513
|
+
//#region src/internal/herald.d.ts
|
|
7514
|
+
/**
|
|
7515
|
+
* Create a _Herald_ for announcing named events
|
|
7516
|
+
*
|
|
7517
|
+
* @param names Event names
|
|
7518
|
+
* @param property Optional property for subscription identification _(defaults to `$herald`)_
|
|
7519
|
+
* @returns _Herald_ instance
|
|
7520
|
+
*/
|
|
7521
|
+
export declare function herald<Events extends Record<string, GenericCallback>>(options: HeraldOptions<Events>): Herald<Events>;
|
|
7522
|
+
/**
|
|
7523
|
+
* Is the value a herald?
|
|
7524
|
+
*
|
|
7525
|
+
* @param value Value to check
|
|
7526
|
+
* @returns `true` if the value is a herald, otherwise `false`
|
|
7527
|
+
*/
|
|
7528
|
+
export declare function isHerald<Events extends Record<string, GenericCallback> = Record<string, GenericCallback>>(value: unknown): value is Herald<Events>;
|
|
7529
|
+
/**
|
|
7530
|
+
* Is the value events for a herald?
|
|
7531
|
+
*
|
|
7532
|
+
* @param value Value to check
|
|
7533
|
+
* @returns `true` if the value is events for a herald, otherwise `false`
|
|
7534
|
+
*/
|
|
7535
|
+
export declare function isHeraldEvents<Events extends Record<string, GenericCallback> = Record<string, GenericCallback>>(value: unknown): value is HeraldEvents<Events>;
|
|
7536
|
+
/**
|
|
7537
|
+
* Is the value a herald subscription?
|
|
7538
|
+
*
|
|
7539
|
+
* @param value Value to check
|
|
7540
|
+
* @returns `true` if the value is a herald subscription, otherwise `false`
|
|
7541
|
+
*/
|
|
7542
|
+
export declare function isHeraldSubscription(value: unknown): value is Subscription;
|
|
7543
|
+
//#endregion
|
|
7542
7544
|
//#region src/internal/is.d.ts
|
|
7543
7545
|
/**
|
|
7544
7546
|
* Is the value an array or a plain object?
|
|
@@ -8508,4 +8510,4 @@ export declare class SizedSet<Value = unknown> extends Set<Value> {
|
|
|
8508
8510
|
get(value: Value, update?: boolean): Value | undefined;
|
|
8509
8511
|
}
|
|
8510
8512
|
//#endregion
|
|
8511
|
-
export { type AsyncLimiter, type AsyncPlan, type Color, type ColorType, type ColorTypeExtended, type ColorValue, type ColorValueExtended, type HSLAColor, type HSLColor, type HWBAColor, type HWBColor, Key$1 as Key, type Limiter, Logger, type Plan, type RGBAColor, type RGBColor, type Shaken, type Smushed, type Subscription, type SubscriptionParameters, type SubscriptionProperty, type Subscriptions, type SubscriptionsParameters, type TimeLogger, type Unsmushed, push as append, filterAndMap as select, toPromise as fromResult, getRandomFloatingNumber as getRandomFloat, isLogger, isTimeLogger, mapAndFilter as reverseSelect };
|
|
8513
|
+
export { type AsyncLimiter, type AsyncPlan, type Color, type ColorType, type ColorTypeExtended, type ColorValue, type ColorValueExtended, type HSLAColor, type HSLColor, type HWBAColor, type HWBColor, type Herald, type HeraldEvents, Key$1 as Key, type Limiter, Logger, type Plan, type RGBAColor, type RGBColor, type Shaken, type Smushed, type Subscription, type SubscriptionParameters, type SubscriptionProperty, type Subscriptions, type SubscriptionsParameters, type TimeLogger, type Unsmushed, push as append, filterAndMap as select, toPromise as fromResult, getRandomFloatingNumber as getRandomFloat, isLogger, isTimeLogger, mapAndFilter as reverseSelect };
|
package/dist/index.mjs
CHANGED
|
@@ -4847,10 +4847,20 @@ const beaconSubscription = {
|
|
|
4847
4847
|
value: SUBSCRIPTION_NAME
|
|
4848
4848
|
};
|
|
4849
4849
|
//#endregion
|
|
4850
|
-
//#region src/internal/herald.ts
|
|
4850
|
+
//#region src/internal/models/herald.model.ts
|
|
4851
|
+
const HERALD_MESSAGE_ARRAY = "Herald requires an array of event names.";
|
|
4852
|
+
const HERALD_MESSAGE_ONCREATE = `Herald requires a valid onCreate callback for subscription creation`;
|
|
4853
|
+
const HERALD_MESSAGE_PROPERTY = `Herald requires valid property information for subscription identification`;
|
|
4851
4854
|
const HERALD_NAME_EVENTS = "events";
|
|
4852
4855
|
const HERALD_NAME_HERALD = "herald";
|
|
4853
4856
|
const HERALD_PROPERTY = "$herald";
|
|
4857
|
+
const HERALD_SYMBOL = Symbol(HERALD_PROPERTY);
|
|
4858
|
+
const heraldSubscription = {
|
|
4859
|
+
key: HERALD_PROPERTY,
|
|
4860
|
+
value: SUBSCRIPTION_NAME
|
|
4861
|
+
};
|
|
4862
|
+
//#endregion
|
|
4863
|
+
//#region src/internal/herald.ts
|
|
4854
4864
|
function Events(herald, state) {
|
|
4855
4865
|
for (const key of state.keys) Object.defineProperty(this, key, { value: (callback, signal) => herald.subscribe(key, callback, signal) });
|
|
4856
4866
|
}
|
|
@@ -4937,7 +4947,7 @@ function isHeraldEvents(value) {
|
|
|
4937
4947
|
return isHeraldInstance(HERALD_NAME_EVENTS, value);
|
|
4938
4948
|
}
|
|
4939
4949
|
function isHeraldInstance(name, value) {
|
|
4940
|
-
return typeof value === "object" && value !== null &&
|
|
4950
|
+
return typeof value === "object" && value !== null && "$herald" in value && value["$herald"] === name;
|
|
4941
4951
|
}
|
|
4942
4952
|
/**
|
|
4943
4953
|
* Is the value a herald subscription?
|
|
@@ -4946,7 +4956,7 @@ function isHeraldInstance(name, value) {
|
|
|
4946
4956
|
* @returns `true` if the value is a herald subscription, otherwise `false`
|
|
4947
4957
|
*/
|
|
4948
4958
|
function isHeraldSubscription(value) {
|
|
4949
|
-
return isSubscription(value) &&
|
|
4959
|
+
return isSubscription(value) && "$herald" in value && value["$herald"] === "subscription";
|
|
4950
4960
|
}
|
|
4951
4961
|
function subscribeToHerald(key, callback, signal) {
|
|
4952
4962
|
const { state } = this[HERALD_SYMBOL];
|
|
@@ -4958,14 +4968,6 @@ function subscribeToHerald(key, callback, signal) {
|
|
|
4958
4968
|
if (!existing) state.onCreate?.(key, callback, subscription);
|
|
4959
4969
|
return subscription;
|
|
4960
4970
|
}
|
|
4961
|
-
const HERALD_MESSAGE_ARRAY = "Herald requires an array of event names.";
|
|
4962
|
-
const HERALD_MESSAGE_ONCREATE = `Herald requires a valid onCreate callback for subscription creation`;
|
|
4963
|
-
const HERALD_MESSAGE_PROPERTY = `Herald requires valid property information for subscription identification`;
|
|
4964
|
-
const HERALD_SYMBOL = Symbol(HERALD_PROPERTY);
|
|
4965
|
-
const heraldSubscription = {
|
|
4966
|
-
key: HERALD_PROPERTY,
|
|
4967
|
-
value: SUBSCRIPTION_NAME
|
|
4968
|
-
};
|
|
4969
4971
|
//#endregion
|
|
4970
4972
|
//#region src/color/constants.ts
|
|
4971
4973
|
const COLOR_ALPHA = {
|
|
@@ -1,43 +1,7 @@
|
|
|
1
1
|
import { GenericCallback } from "../models.mjs";
|
|
2
|
-
import { Subscription
|
|
2
|
+
import { Subscription } from "./subscription.mjs";
|
|
3
|
+
import { Herald, HeraldEvents, HeraldOptions } from "./models/herald.model.mjs";
|
|
3
4
|
//#region src/internal/herald.d.ts
|
|
4
|
-
export type Herald<Events extends Record<string, GenericCallback>> = {
|
|
5
|
-
readonly events: HeraldEvents<Events>;
|
|
6
|
-
/**
|
|
7
|
-
* Remove all event subscribers
|
|
8
|
-
*/
|
|
9
|
-
clear(): void;
|
|
10
|
-
/**
|
|
11
|
-
* Emit an event with parameters
|
|
12
|
-
*
|
|
13
|
-
* @param event Event name
|
|
14
|
-
* @param parameters Event parameters
|
|
15
|
-
*/
|
|
16
|
-
emit<Event extends keyof Events>(event: Event, ...parameters: Parameters<Events[Event]>): void;
|
|
17
|
-
/**
|
|
18
|
-
* Is the event observed by any subscribers?
|
|
19
|
-
*
|
|
20
|
-
* @param event Event name
|
|
21
|
-
* @returns `true` if the event is observed, otherwise `false`
|
|
22
|
-
*/
|
|
23
|
-
observed<Event extends keyof Events>(event: Event): boolean;
|
|
24
|
-
/**
|
|
25
|
-
* Subscribe to an event with a callback
|
|
26
|
-
*
|
|
27
|
-
* @param event Event name
|
|
28
|
-
* @param callback Callback function
|
|
29
|
-
* @param signal Optional abort signal to cancel the subscription
|
|
30
|
-
* @returns Subscription instance
|
|
31
|
-
*/
|
|
32
|
-
subscribe<Event extends keyof Events>(event: Event, callback: Events[Event], signal?: AbortSignal): Subscription;
|
|
33
|
-
};
|
|
34
|
-
export type HeraldEvents<Events extends Record<string, GenericCallback>> = { [Key in keyof Events]: Key extends "*" ? never : (callback: Events[Key], signal?: AbortSignal) => void; };
|
|
35
|
-
type HeraldOnCreate<Events extends Record<string, GenericCallback>> = <Event extends keyof Events>(event: Event, callback: Events[Event], subscription: Subscription) => void;
|
|
36
|
-
export type HeraldOptions<Events extends Record<string, GenericCallback>> = {
|
|
37
|
-
names: Array<keyof Events>;
|
|
38
|
-
property?: SubscriptionProperty;
|
|
39
|
-
onCreate?: HeraldOnCreate<Events>;
|
|
40
|
-
};
|
|
41
5
|
/**
|
|
42
6
|
* Create a _Herald_ for announcing named events
|
|
43
7
|
*
|
package/dist/internal/herald.mjs
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { isPlainObject } from "./is.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { isSubscription, subscriptions } from "./subscription.mjs";
|
|
3
|
+
import { HERALD_MESSAGE_ARRAY, HERALD_MESSAGE_ONCREATE, HERALD_MESSAGE_PROPERTY, HERALD_NAME_EVENTS, HERALD_NAME_HERALD, HERALD_PROPERTY, HERALD_SYMBOL, heraldSubscription } from "./models/herald.model.mjs";
|
|
3
4
|
//#region src/internal/herald.ts
|
|
4
|
-
const HERALD_NAME_EVENTS = "events";
|
|
5
|
-
const HERALD_NAME_HERALD = "herald";
|
|
6
|
-
const HERALD_PROPERTY = "$herald";
|
|
7
5
|
function Events(herald, state) {
|
|
8
6
|
for (const key of state.keys) Object.defineProperty(this, key, { value: (callback, signal) => herald.subscribe(key, callback, signal) });
|
|
9
7
|
}
|
|
@@ -91,7 +89,7 @@ function isHeraldEvents(value) {
|
|
|
91
89
|
return isHeraldInstance(HERALD_NAME_EVENTS, value);
|
|
92
90
|
}
|
|
93
91
|
function isHeraldInstance(name, value) {
|
|
94
|
-
return typeof value === "object" && value !== null &&
|
|
92
|
+
return typeof value === "object" && value !== null && "$herald" in value && value["$herald"] === name;
|
|
95
93
|
}
|
|
96
94
|
/**
|
|
97
95
|
* Is the value a herald subscription?
|
|
@@ -100,7 +98,7 @@ function isHeraldInstance(name, value) {
|
|
|
100
98
|
* @returns `true` if the value is a herald subscription, otherwise `false`
|
|
101
99
|
*/
|
|
102
100
|
function isHeraldSubscription(value) {
|
|
103
|
-
return isSubscription(value) &&
|
|
101
|
+
return isSubscription(value) && "$herald" in value && value["$herald"] === "subscription";
|
|
104
102
|
}
|
|
105
103
|
function subscribeToHerald(key, callback, signal) {
|
|
106
104
|
const { state } = this[HERALD_SYMBOL];
|
|
@@ -112,13 +110,5 @@ function subscribeToHerald(key, callback, signal) {
|
|
|
112
110
|
if (!existing) state.onCreate?.(key, callback, subscription);
|
|
113
111
|
return subscription;
|
|
114
112
|
}
|
|
115
|
-
const HERALD_MESSAGE_ARRAY = "Herald requires an array of event names.";
|
|
116
|
-
const HERALD_MESSAGE_ONCREATE = `Herald requires a valid onCreate callback for subscription creation`;
|
|
117
|
-
const HERALD_MESSAGE_PROPERTY = `Herald requires valid property information for subscription identification`;
|
|
118
|
-
const HERALD_SYMBOL = Symbol(HERALD_PROPERTY);
|
|
119
|
-
const heraldSubscription = {
|
|
120
|
-
key: HERALD_PROPERTY,
|
|
121
|
-
value: SUBSCRIPTION_NAME
|
|
122
|
-
};
|
|
123
113
|
//#endregion
|
|
124
114
|
export { herald, isHerald, isHeraldEvents, isHeraldSubscription };
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { GenericCallback } from "../../models.mjs";
|
|
2
|
+
import { Subscription, SubscriptionProperty, Subscriptions } from "../subscription.mjs";
|
|
3
|
+
//#region src/internal/models/herald.model.d.ts
|
|
4
|
+
export type Herald<Events extends Record<string, GenericCallback>> = {
|
|
5
|
+
readonly events: HeraldEvents<Events>;
|
|
6
|
+
/**
|
|
7
|
+
* Remove all event subscribers
|
|
8
|
+
*/
|
|
9
|
+
clear(): void;
|
|
10
|
+
/**
|
|
11
|
+
* Emit an event with parameters
|
|
12
|
+
*
|
|
13
|
+
* @param event Event name
|
|
14
|
+
* @param parameters Event parameters
|
|
15
|
+
*/
|
|
16
|
+
emit<Event extends keyof Events>(event: Event, ...parameters: Parameters<Events[Event]>): void;
|
|
17
|
+
/**
|
|
18
|
+
* Is the event observed by any subscribers?
|
|
19
|
+
*
|
|
20
|
+
* @param event Event name
|
|
21
|
+
* @returns `true` if the event is observed, otherwise `false`
|
|
22
|
+
*/
|
|
23
|
+
observed<Event extends keyof Events>(event: Event): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Subscribe to an event with a callback
|
|
26
|
+
*
|
|
27
|
+
* @param event Event name
|
|
28
|
+
* @param callback Callback function
|
|
29
|
+
* @param signal Optional abort signal to cancel the subscription
|
|
30
|
+
* @returns Subscription instance
|
|
31
|
+
*/
|
|
32
|
+
subscribe<Event extends keyof Events>(event: Event, callback: Events[Event], signal?: AbortSignal): Subscription;
|
|
33
|
+
};
|
|
34
|
+
export type HeraldEvents<Events extends Record<string, GenericCallback>> = { [Key in keyof Events]: Key extends "*" ? never : (callback: Events[Key], signal?: AbortSignal) => void; };
|
|
35
|
+
export type HeraldOnCreate<Events extends Record<string, GenericCallback>> = <Event extends keyof Events>(event: Event, callback: Events[Event], subscription: Subscription) => void;
|
|
36
|
+
export type HeraldOptions<Events extends Record<string, GenericCallback>> = {
|
|
37
|
+
names: Array<keyof Events>;
|
|
38
|
+
property?: SubscriptionProperty;
|
|
39
|
+
onCreate?: HeraldOnCreate<Events>;
|
|
40
|
+
};
|
|
41
|
+
export type HeraldState = {
|
|
42
|
+
keys: Set<string>;
|
|
43
|
+
store: Subscriptions<GenericCallback>;
|
|
44
|
+
onCreate?: HeraldOnCreate<Record<string, GenericCallback>>;
|
|
45
|
+
};
|
|
46
|
+
export type InternalHerald = {
|
|
47
|
+
[HERALD_SYMBOL]: {
|
|
48
|
+
events: HeraldEvents<Record<string, GenericCallback>>;
|
|
49
|
+
state: HeraldState;
|
|
50
|
+
};
|
|
51
|
+
} & Herald<Record<string, GenericCallback>>;
|
|
52
|
+
export declare const HERALD_MESSAGE_ARRAY = "Herald requires an array of event names.";
|
|
53
|
+
export declare const HERALD_MESSAGE_ONCREATE = "Herald requires a valid onCreate callback for subscription creation";
|
|
54
|
+
export declare const HERALD_MESSAGE_PROPERTY = "Herald requires valid property information for subscription identification";
|
|
55
|
+
export declare const HERALD_NAME_EVENTS = "events";
|
|
56
|
+
export declare const HERALD_NAME_HERALD = "herald";
|
|
57
|
+
export declare const HERALD_PROPERTY = "$herald";
|
|
58
|
+
export declare const HERALD_SYMBOL: unique symbol;
|
|
59
|
+
export declare const heraldSubscription: SubscriptionProperty;
|
|
60
|
+
//#endregion
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { SUBSCRIPTION_NAME } from "../subscription.mjs";
|
|
2
|
+
//#region src/internal/models/herald.model.ts
|
|
3
|
+
const HERALD_MESSAGE_ARRAY = "Herald requires an array of event names.";
|
|
4
|
+
const HERALD_MESSAGE_ONCREATE = `Herald requires a valid onCreate callback for subscription creation`;
|
|
5
|
+
const HERALD_MESSAGE_PROPERTY = `Herald requires valid property information for subscription identification`;
|
|
6
|
+
const HERALD_NAME_EVENTS = "events";
|
|
7
|
+
const HERALD_NAME_HERALD = "herald";
|
|
8
|
+
const HERALD_PROPERTY = "$herald";
|
|
9
|
+
const HERALD_SYMBOL = Symbol(HERALD_PROPERTY);
|
|
10
|
+
const heraldSubscription = {
|
|
11
|
+
key: HERALD_PROPERTY,
|
|
12
|
+
value: SUBSCRIPTION_NAME
|
|
13
|
+
};
|
|
14
|
+
//#endregion
|
|
15
|
+
export { HERALD_MESSAGE_ARRAY, HERALD_MESSAGE_ONCREATE, HERALD_MESSAGE_PROPERTY, HERALD_NAME_EVENTS, HERALD_NAME_HERALD, HERALD_PROPERTY, HERALD_SYMBOL, heraldSubscription };
|