@g9tm/lynxcontrols-foundation 0.0.0-stage → 1.4.2
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/README.md +4 -2
- package/dist/.tsbuildinfo +1 -0
- package/dist/collections.d.ts +16 -0
- package/dist/collections.d.ts.map +1 -0
- package/dist/collections.js +40 -0
- package/dist/collections.js.map +1 -0
- package/dist/culture/calendar.d.ts +122 -0
- package/dist/culture/calendar.d.ts.map +1 -0
- package/dist/culture/calendar.js +379 -0
- package/dist/culture/calendar.js.map +1 -0
- package/dist/culture/culture.d.ts +91 -0
- package/dist/culture/culture.d.ts.map +1 -0
- package/dist/culture/culture.js +173 -0
- package/dist/culture/culture.js.map +1 -0
- package/dist/culture/date-format.d.ts +19 -0
- package/dist/culture/date-format.d.ts.map +1 -0
- package/dist/culture/date-format.js +101 -0
- package/dist/culture/date-format.js.map +1 -0
- package/dist/culture/digits.d.ts +29 -0
- package/dist/culture/digits.d.ts.map +1 -0
- package/dist/culture/digits.js +43 -0
- package/dist/culture/digits.js.map +1 -0
- package/dist/culture/duration.d.ts +38 -0
- package/dist/culture/duration.d.ts.map +1 -0
- package/dist/culture/duration.js +41 -0
- package/dist/culture/duration.js.map +1 -0
- package/dist/culture/index.d.ts +9 -0
- package/dist/culture/index.d.ts.map +1 -0
- package/dist/culture/index.js +8 -0
- package/dist/culture/numbers.d.ts +38 -0
- package/dist/culture/numbers.d.ts.map +1 -0
- package/dist/culture/numbers.js +64 -0
- package/dist/culture/numbers.js.map +1 -0
- package/dist/culture/relative-time.d.ts +50 -0
- package/dist/culture/relative-time.d.ts.map +1 -0
- package/dist/culture/relative-time.js +63 -0
- package/dist/culture/relative-time.js.map +1 -0
- package/dist/culture/strings.d.ts +145 -0
- package/dist/culture/strings.d.ts.map +1 -0
- package/dist/culture/strings.js +345 -0
- package/dist/culture/strings.js.map +1 -0
- package/dist/enums/index.d.ts +195 -0
- package/dist/enums/index.d.ts.map +1 -0
- package/dist/enums/index.js +130 -0
- package/dist/enums/index.js.map +1 -0
- package/dist/errors.d.ts +10 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +21 -0
- package/dist/errors.js.map +1 -0
- package/dist/exec/diagnostics.d.ts +74 -0
- package/dist/exec/diagnostics.d.ts.map +1 -0
- package/dist/exec/diagnostics.js +73 -0
- package/dist/exec/diagnostics.js.map +1 -0
- package/dist/exec/index.d.ts +5 -0
- package/dist/exec/index.d.ts.map +1 -0
- package/dist/exec/index.js +4 -0
- package/dist/exec/options.d.ts +75 -0
- package/dist/exec/options.d.ts.map +1 -0
- package/dist/exec/options.js +107 -0
- package/dist/exec/options.js.map +1 -0
- package/dist/exec/safe-executor.d.ts +138 -0
- package/dist/exec/safe-executor.d.ts.map +1 -0
- package/dist/exec/safe-executor.js +401 -0
- package/dist/exec/safe-executor.js.map +1 -0
- package/dist/exec/trace.d.ts +59 -0
- package/dist/exec/trace.d.ts.map +1 -0
- package/dist/exec/trace.js +108 -0
- package/dist/exec/trace.js.map +1 -0
- package/dist/icons/generated/glyph-svg.d.ts +37 -0
- package/dist/icons/generated/glyph-svg.d.ts.map +1 -0
- package/dist/icons/generated/glyph-svg.js +33 -0
- package/dist/icons/generated/glyph-svg.js.map +1 -0
- package/dist/icons/glyph-slots.d.ts +79 -0
- package/dist/icons/glyph-slots.d.ts.map +1 -0
- package/dist/icons/glyph-slots.js +50 -0
- package/dist/icons/glyph-slots.js.map +1 -0
- package/dist/icons/glyph.d.ts +76 -0
- package/dist/icons/glyph.d.ts.map +1 -0
- package/dist/icons/glyph.js +42 -0
- package/dist/icons/glyph.js.map +1 -0
- package/dist/icons/icon-fonts.d.ts +55 -0
- package/dist/icons/icon-fonts.d.ts.map +1 -0
- package/dist/icons/icon-fonts.js +74 -0
- package/dist/icons/icon-fonts.js.map +1 -0
- package/dist/icons/icon.d.ts +102 -0
- package/dist/icons/icon.d.ts.map +1 -0
- package/dist/icons/icon.js +132 -0
- package/dist/icons/icon.js.map +1 -0
- package/dist/icons/index.d.ts +7 -0
- package/dist/icons/index.d.ts.map +1 -0
- package/dist/icons/index.js +6 -0
- package/dist/icons/svg.d.ts +28 -0
- package/dist/icons/svg.d.ts.map +1 -0
- package/dist/icons/svg.js +59 -0
- package/dist/icons/svg.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/services/abort.d.ts +31 -0
- package/dist/services/abort.d.ts.map +1 -0
- package/dist/services/abort.js +47 -0
- package/dist/services/abort.js.map +1 -0
- package/dist/services/clock.d.ts +35 -0
- package/dist/services/clock.d.ts.map +1 -0
- package/dist/services/clock.js +37 -0
- package/dist/services/clock.js.map +1 -0
- package/dist/services/contracts.d.ts +200 -0
- package/dist/services/contracts.d.ts.map +1 -0
- package/dist/services/contracts.js +37 -0
- package/dist/services/contracts.js.map +1 -0
- package/dist/services/index.d.ts +5 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/index.js +4 -0
- package/dist/services/preferences.d.ts +105 -0
- package/dist/services/preferences.d.ts.map +1 -0
- package/dist/services/preferences.js +253 -0
- package/dist/services/preferences.js.map +1 -0
- package/dist/theme/color.d.ts +94 -0
- package/dist/theme/color.d.ts.map +1 -0
- package/dist/theme/color.js +150 -0
- package/dist/theme/color.js.map +1 -0
- package/dist/theme/control-colors.d.ts +46 -0
- package/dist/theme/control-colors.d.ts.map +1 -0
- package/dist/theme/control-colors.js +46 -0
- package/dist/theme/control-colors.js.map +1 -0
- package/dist/theme/index.d.ts +5 -0
- package/dist/theme/index.d.ts.map +1 -0
- package/dist/theme/index.js +4 -0
- package/dist/theme/theme.d.ts +88 -0
- package/dist/theme/theme.d.ts.map +1 -0
- package/dist/theme/theme.js +190 -0
- package/dist/theme/theme.js.map +1 -0
- package/dist/theme/variants.d.ts +33 -0
- package/dist/theme/variants.d.ts.map +1 -0
- package/dist/theme/variants.js +53 -0
- package/dist/theme/variants.js.map +1 -0
- package/dist/tokens/css-vars.d.ts +41 -0
- package/dist/tokens/css-vars.d.ts.map +1 -0
- package/dist/tokens/css-vars.js +55 -0
- package/dist/tokens/css-vars.js.map +1 -0
- package/dist/tokens/generated/metrics.d.ts +184 -0
- package/dist/tokens/generated/metrics.d.ts.map +1 -0
- package/dist/tokens/generated/metrics.js +349 -0
- package/dist/tokens/generated/metrics.js.map +1 -0
- package/dist/tokens/generated/palettes.d.ts +113 -0
- package/dist/tokens/generated/palettes.d.ts.map +1 -0
- package/dist/tokens/generated/palettes.js +391 -0
- package/dist/tokens/generated/palettes.js.map +1 -0
- package/dist/tokens/index.d.ts +5 -0
- package/dist/tokens/index.d.ts.map +1 -0
- package/dist/tokens/index.js +4 -0
- package/dist/tokens/layout-metrics.d.ts +120 -0
- package/dist/tokens/layout-metrics.d.ts.map +1 -0
- package/dist/tokens/layout-metrics.js +111 -0
- package/dist/tokens/layout-metrics.js.map +1 -0
- package/docs/api.md +369 -0
- package/docs/foundation.md +370 -0
- package/docs/migration/Core.Controls.Shared.md +475 -0
- package/docs/migration/Core.Helpers.md +132 -0
- package/docs/migration/Core.Icons.md +135 -0
- package/docs/migration/Core.Localization.md +118 -0
- package/docs/migration/Core.Storage.md +54 -0
- package/docs/migration/Core.Theming.md +328 -0
- package/package.json +59 -4
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/** A value or a promise of it: stores may be synchronous (memory) or asynchronous (a native module). */
|
|
2
|
+
export type G9MaybePromise<T> = T | Promise<T>;
|
|
3
|
+
/** What a preference holds: a 32-bit integer or a string (MAUI `IG9PreferenceStore` stores exactly these). */
|
|
4
|
+
export type G9PreferenceValue = number | string;
|
|
5
|
+
/**
|
|
6
|
+
* Where preferences are persisted (MAUI `IG9PreferenceStore`). Keys arrive already prefixed. The app supplies one
|
|
7
|
+
* through the provider: the Lynxtron, Android and iOS adapters (WP12–WP14) and {@link createMemoryPreferenceStore}.
|
|
8
|
+
* A store may throw or reject; {@link createPreferences} guards every call.
|
|
9
|
+
*/
|
|
10
|
+
export interface G9PreferenceStore {
|
|
11
|
+
/** The stored integer, or `defaultValue` when absent or not an integer. */
|
|
12
|
+
getInt(key: string, defaultValue: number): G9MaybePromise<number>;
|
|
13
|
+
/** Writes an integer. */
|
|
14
|
+
setInt(key: string, value: number): G9MaybePromise<void>;
|
|
15
|
+
/** The stored string, or `defaultValue` when absent or not a string. */
|
|
16
|
+
getString(key: string, defaultValue: string | null): G9MaybePromise<string | null>;
|
|
17
|
+
/** Writes a string. `null` removes the key. */
|
|
18
|
+
setString(key: string, value: string | null): G9MaybePromise<void>;
|
|
19
|
+
/** Removes a key. A key that is not present is not an error. */
|
|
20
|
+
remove(key: string): G9MaybePromise<void>;
|
|
21
|
+
/** Every stored entry whose key starts with `prefix` (hydration reads the whole namespace once). */
|
|
22
|
+
entries(prefix: string): G9MaybePromise<ReadonlyArray<readonly [string, G9PreferenceValue]>>;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* An in-memory store (MAUI `G9InMemoryPreferenceStore`): for tests, previews, and apps that opt out of persistence.
|
|
26
|
+
* Synchronous. Values are typed: an integer is not readable as a string and vice versa, as in MAUI.
|
|
27
|
+
*/
|
|
28
|
+
export declare function createMemoryPreferenceStore(initial?: Readonly<Record<string, G9PreferenceValue>>): G9PreferenceStore;
|
|
29
|
+
/** The prefix on every key the controls write (MAUI `G9Preferences.KeyPrefix`). */
|
|
30
|
+
export declare const g9PreferenceKeyPrefix = "g9controls.";
|
|
31
|
+
/** The values of one namespace, keys relative to it. Immutable; a new object after every change. */
|
|
32
|
+
export interface G9PreferencesSnapshot {
|
|
33
|
+
/** `true` once {@link G9Preferences.hydrate} has merged the stored values (also after a failed read). */
|
|
34
|
+
readonly hydrated: boolean;
|
|
35
|
+
readonly values: Readonly<Record<string, G9PreferenceValue>>;
|
|
36
|
+
}
|
|
37
|
+
/** Which store call failed, for {@link G9PreferencesOptions.onStoreError}. */
|
|
38
|
+
export interface G9PreferenceStoreFailure {
|
|
39
|
+
readonly operation: 'entries' | 'setInt' | 'setString' | 'remove';
|
|
40
|
+
/** The full (prefixed) key; the prefix itself for `entries`. */
|
|
41
|
+
readonly key: string;
|
|
42
|
+
}
|
|
43
|
+
/** Options of {@link createPreferences}. */
|
|
44
|
+
export interface G9PreferencesOptions {
|
|
45
|
+
readonly store: G9PreferenceStore;
|
|
46
|
+
/** Prefix of every key. Default {@link g9PreferenceKeyPrefix} (`'g9controls.'`). */
|
|
47
|
+
readonly keyPrefix?: string;
|
|
48
|
+
/**
|
|
49
|
+
* Receives every store failure. Store calls never throw into the caller (MAUI: "a forgotten sheet height is not
|
|
50
|
+
* worth a crash"); this is where they surface. Default: none (the failure only leaves the value unpersisted).
|
|
51
|
+
*/
|
|
52
|
+
readonly onStoreError?: (error: unknown, failure: G9PreferenceStoreFailure) => void;
|
|
53
|
+
}
|
|
54
|
+
/** A typed handle on one key (see {@link G9Preferences.intKey} / {@link G9Preferences.stringKey}). */
|
|
55
|
+
export interface G9PreferenceKey<T> {
|
|
56
|
+
/** The key relative to its namespace. */
|
|
57
|
+
readonly key: string;
|
|
58
|
+
get(): T;
|
|
59
|
+
set(value: T): Promise<void>;
|
|
60
|
+
remove(): Promise<void>;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Typed, namespaced preferences over a store (MAUI `G9Preferences`), read synchronously from a hydrated snapshot.
|
|
64
|
+
* Reads never touch the store: `hydrate()` loads the namespace once; writes update the snapshot immediately, notify
|
|
65
|
+
* subscribers, then write through. A local write made before hydration finishes wins over the stored value.
|
|
66
|
+
*/
|
|
67
|
+
export interface G9Preferences {
|
|
68
|
+
/** The full prefix of this namespace, e.g. `'g9controls.'` or `'g9controls.sheets.'`. */
|
|
69
|
+
readonly keyPrefix: string;
|
|
70
|
+
/** The underlying store. */
|
|
71
|
+
readonly store: G9PreferenceStore;
|
|
72
|
+
/**
|
|
73
|
+
* Loads the stored values once (later calls share the same load; namespaces share it). A store failure is reported
|
|
74
|
+
* to `onStoreError` and still ends hydration (reads keep their defaults); the promise rejects only when a subscriber
|
|
75
|
+
* threw while being notified.
|
|
76
|
+
*/
|
|
77
|
+
hydrate(): Promise<G9PreferencesSnapshot>;
|
|
78
|
+
/** The current snapshot of this namespace; the same object until something in it changes. */
|
|
79
|
+
getSnapshot(): G9PreferencesSnapshot;
|
|
80
|
+
/** Called after each change in this namespace (and once on hydration). Returns an unsubscribe function. */
|
|
81
|
+
subscribe(listener: (snapshot: G9PreferencesSnapshot) => void): () => void;
|
|
82
|
+
/** The integer, or `defaultValue` (0) when absent or not an integer. */
|
|
83
|
+
getInt(key: string, defaultValue?: number): number;
|
|
84
|
+
/**
|
|
85
|
+
* Writes a 32-bit integer: snapshot and subscribers first, then the store. The promise settles when the store write
|
|
86
|
+
* ends and never rejects (failures go to `onStoreError`). Throws synchronously for invalid input
|
|
87
|
+
* ({@link G9Error} `preference-key` / `preference-value`) or, after the write started, a subscriber's first error.
|
|
88
|
+
*/
|
|
89
|
+
setInt(key: string, value: number): Promise<void>;
|
|
90
|
+
/** The string, or `defaultValue` (`null`) when absent or not a string. */
|
|
91
|
+
getString(key: string, defaultValue?: string | null): string | null;
|
|
92
|
+
/** Writes a string; `null` removes the key. Same settlement and errors as {@link G9Preferences.setInt}. */
|
|
93
|
+
setString(key: string, value: string | null): Promise<void>;
|
|
94
|
+
/** Removes a key; absent is not an error. Same settlement as {@link G9Preferences.setInt}. */
|
|
95
|
+
remove(key: string): Promise<void>;
|
|
96
|
+
/** A child namespace: keys are `<keyPrefix><name>.<key>`. Shares the store, snapshot and hydration. */
|
|
97
|
+
namespace(name: string): G9Preferences;
|
|
98
|
+
/** A typed integer handle. */
|
|
99
|
+
intKey(key: string, defaultValue?: number): G9PreferenceKey<number>;
|
|
100
|
+
/** A typed string handle. */
|
|
101
|
+
stringKey(key: string, defaultValue?: string | null): G9PreferenceKey<string | null>;
|
|
102
|
+
}
|
|
103
|
+
/** Creates the root {@link G9Preferences} over a store. One per app; the WP02 provider owns it. */
|
|
104
|
+
export declare function createPreferences(options: G9PreferencesOptions): G9Preferences;
|
|
105
|
+
//# sourceMappingURL=preferences.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"preferences.d.ts","sourceRoot":"","sources":["../../src/services/preferences.ts"],"names":[],"mappings":"AAEA,wGAAwG;AACxG,MAAM,MAAM,cAAc,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;AAE/C,8GAA8G;AAC9G,MAAM,MAAM,iBAAiB,GAAG,MAAM,GAAG,MAAM,CAAC;AAEhD;;;;GAIG;AACH,MAAM,WAAW,iBAAiB;IAChC,2EAA2E;IAC3E,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,cAAc,CAAC,MAAM,CAAC,CAAC;IAClE,yBAAyB;IACzB,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC;IACzD,wEAAwE;IACxE,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,IAAI,GAAG,cAAc,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IACnF,+CAA+C;IAC/C,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC;IACnE,gEAAgE;IAChE,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC;IAC1C,oGAAoG;IACpG,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,cAAc,CAAC,aAAa,CAAC,SAAS,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC,CAAC,CAAC;CAC9F;AA2BD;;;GAGG;AACH,wBAAgB,2BAA2B,CAAC,OAAO,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC,GAAG,iB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= 2147483647;
|
|
4
|
+
function isInt32(value) {
|
|
5
|
+
return 'number' == typeof value && Number.isInteger(value) && value >= INT32_MIN && value <= INT32_MAX;
|
|
6
|
+
}
|
|
7
|
+
function checkKey(key) {
|
|
8
|
+
if ('string' != typeof key || '' === key) throw new G9Error('preference-key', `A preference key must be a non-empty string, got ${String(key)}.`);
|
|
9
|
+
return key;
|
|
10
|
+
}
|
|
11
|
+
function checkInt(key, value) {
|
|
12
|
+
if (!isInt32(value)) throw new G9Error('preference-value', `Preference '${key}' needs a 32-bit integer, got ${String(value)}.`);
|
|
13
|
+
return value;
|
|
14
|
+
}
|
|
15
|
+
function checkString(key, value) {
|
|
16
|
+
if (null !== value && 'string' != typeof value) throw new G9Error('preference-value', `Preference '${key}' needs a string or null, got ${String(value)}.`);
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
19
|
+
function createMemoryPreferenceStore(initial) {
|
|
20
|
+
const values = new Map();
|
|
21
|
+
for (const [key, value] of Object.entries(null != initial ? initial : {}))if ('string' == typeof value) values.set(checkKey(key), value);
|
|
22
|
+
else values.set(checkKey(key), checkInt(key, value));
|
|
23
|
+
return {
|
|
24
|
+
getInt (key, defaultValue) {
|
|
25
|
+
const value = values.get(key);
|
|
26
|
+
return 'number' == typeof value ? value : defaultValue;
|
|
27
|
+
},
|
|
28
|
+
setInt (key, value) {
|
|
29
|
+
values.set(checkKey(key), checkInt(key, value));
|
|
30
|
+
},
|
|
31
|
+
getString (key, defaultValue) {
|
|
32
|
+
const value = values.get(key);
|
|
33
|
+
return 'string' == typeof value ? value : defaultValue;
|
|
34
|
+
},
|
|
35
|
+
setString (key, value) {
|
|
36
|
+
checkKey(key);
|
|
37
|
+
if (null === checkString(key, value)) values.delete(key);
|
|
38
|
+
else values.set(key, value);
|
|
39
|
+
},
|
|
40
|
+
remove (key) {
|
|
41
|
+
values.delete(key);
|
|
42
|
+
},
|
|
43
|
+
entries (prefix) {
|
|
44
|
+
return [
|
|
45
|
+
...values
|
|
46
|
+
].filter(([key])=>key.startsWith(prefix));
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
const g9PreferenceKeyPrefix = 'g9controls.';
|
|
51
|
+
function guard(core, failure, call) {
|
|
52
|
+
const report = (error)=>{
|
|
53
|
+
try {
|
|
54
|
+
var _core_onStoreError;
|
|
55
|
+
null == (_core_onStoreError = core.onStoreError) || _core_onStoreError.call(core, error, failure);
|
|
56
|
+
} catch {}
|
|
57
|
+
};
|
|
58
|
+
try {
|
|
59
|
+
return Promise.resolve(call()).then(()=>void 0, report);
|
|
60
|
+
} catch (error) {
|
|
61
|
+
report(error);
|
|
62
|
+
return Promise.resolve();
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
function commit(core, key, value) {
|
|
66
|
+
if (!core.hydrated) core.writtenBeforeHydration.add(key);
|
|
67
|
+
const current = core.values.get(key);
|
|
68
|
+
if (null === value ? void 0 === current : current === value) return null;
|
|
69
|
+
const next = new Map(core.values);
|
|
70
|
+
if (null === value) next.delete(key);
|
|
71
|
+
else next.set(key, value);
|
|
72
|
+
core.values = next;
|
|
73
|
+
core.version++;
|
|
74
|
+
return notify(core, key);
|
|
75
|
+
}
|
|
76
|
+
function notify(core, changedKey) {
|
|
77
|
+
let first = null;
|
|
78
|
+
for (const listener of [
|
|
79
|
+
...core.listeners
|
|
80
|
+
])try {
|
|
81
|
+
listener(changedKey);
|
|
82
|
+
} catch (error) {
|
|
83
|
+
null != first || (first = {
|
|
84
|
+
error
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
return first;
|
|
88
|
+
}
|
|
89
|
+
function write(core, key, value, failure, call) {
|
|
90
|
+
const listenerError = commit(core, key, value);
|
|
91
|
+
const done = guard(core, failure, call);
|
|
92
|
+
if (listenerError) throw listenerError.error;
|
|
93
|
+
return done;
|
|
94
|
+
}
|
|
95
|
+
function startHydration(core) {
|
|
96
|
+
const merge = (entries)=>{
|
|
97
|
+
const next = new Map(core.values);
|
|
98
|
+
for (const entry of Array.isArray(entries) ? entries : []){
|
|
99
|
+
const [key, value] = entry;
|
|
100
|
+
if (!('string' != typeof key || !key.startsWith(core.rootPrefix) || core.writtenBeforeHydration.has(key))) {
|
|
101
|
+
if ('string' == typeof value || isInt32(value)) next.set(key, value);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
finish(next);
|
|
105
|
+
};
|
|
106
|
+
const fail = (error)=>{
|
|
107
|
+
try {
|
|
108
|
+
var _core_onStoreError;
|
|
109
|
+
null == (_core_onStoreError = core.onStoreError) || _core_onStoreError.call(core, error, {
|
|
110
|
+
operation: 'entries',
|
|
111
|
+
key: core.rootPrefix
|
|
112
|
+
});
|
|
113
|
+
} catch {}
|
|
114
|
+
finish(core.values);
|
|
115
|
+
};
|
|
116
|
+
const finish = (next)=>{
|
|
117
|
+
core.values = next;
|
|
118
|
+
core.hydrated = true;
|
|
119
|
+
core.writtenBeforeHydration.clear();
|
|
120
|
+
core.version++;
|
|
121
|
+
const listenerError = notify(core, null);
|
|
122
|
+
if (listenerError) throw listenerError.error;
|
|
123
|
+
};
|
|
124
|
+
try {
|
|
125
|
+
let result;
|
|
126
|
+
try {
|
|
127
|
+
result = core.store.entries(core.rootPrefix);
|
|
128
|
+
} catch (error) {
|
|
129
|
+
fail(error);
|
|
130
|
+
return Promise.resolve();
|
|
131
|
+
}
|
|
132
|
+
if (result && 'function' == typeof result.then) return result.then(merge, fail);
|
|
133
|
+
merge(result);
|
|
134
|
+
return Promise.resolve();
|
|
135
|
+
} catch (listenerError) {
|
|
136
|
+
return Promise.reject(listenerError);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
function view(core, prefix) {
|
|
140
|
+
let cachedVersion = -1;
|
|
141
|
+
let cached = {
|
|
142
|
+
hydrated: false,
|
|
143
|
+
values: {}
|
|
144
|
+
};
|
|
145
|
+
const full = (key)=>prefix + checkKey(key);
|
|
146
|
+
const snapshot = ()=>{
|
|
147
|
+
if (cachedVersion !== core.version) {
|
|
148
|
+
const values = {};
|
|
149
|
+
for (const [key, value] of core.values)if (key.startsWith(prefix)) values[key.slice(prefix.length)] = value;
|
|
150
|
+
cached = Object.freeze({
|
|
151
|
+
hydrated: core.hydrated,
|
|
152
|
+
values: Object.freeze(values)
|
|
153
|
+
});
|
|
154
|
+
cachedVersion = core.version;
|
|
155
|
+
}
|
|
156
|
+
return cached;
|
|
157
|
+
};
|
|
158
|
+
const self = {
|
|
159
|
+
keyPrefix: prefix,
|
|
160
|
+
store: core.store,
|
|
161
|
+
hydrate () {
|
|
162
|
+
var _core;
|
|
163
|
+
null != (_core = core).hydration || (_core.hydration = startHydration(core));
|
|
164
|
+
return core.hydration.then(snapshot);
|
|
165
|
+
},
|
|
166
|
+
getSnapshot: snapshot,
|
|
167
|
+
subscribe (listener) {
|
|
168
|
+
const wrapped = (changedKey)=>{
|
|
169
|
+
if (null === changedKey || changedKey.startsWith(prefix)) listener(snapshot());
|
|
170
|
+
};
|
|
171
|
+
core.listeners.add(wrapped);
|
|
172
|
+
return ()=>{
|
|
173
|
+
core.listeners.delete(wrapped);
|
|
174
|
+
};
|
|
175
|
+
},
|
|
176
|
+
getInt (key, defaultValue = 0) {
|
|
177
|
+
const value = core.values.get(full(key));
|
|
178
|
+
return 'number' == typeof value ? value : defaultValue;
|
|
179
|
+
},
|
|
180
|
+
setInt (key, value) {
|
|
181
|
+
const k = full(key);
|
|
182
|
+
checkInt(k, value);
|
|
183
|
+
return write(core, k, value, {
|
|
184
|
+
operation: 'setInt',
|
|
185
|
+
key: k
|
|
186
|
+
}, ()=>core.store.setInt(k, value));
|
|
187
|
+
},
|
|
188
|
+
getString (key, defaultValue = null) {
|
|
189
|
+
const value = core.values.get(full(key));
|
|
190
|
+
return 'string' == typeof value ? value : defaultValue;
|
|
191
|
+
},
|
|
192
|
+
setString (key, value) {
|
|
193
|
+
const k = full(key);
|
|
194
|
+
checkString(k, value);
|
|
195
|
+
return write(core, k, value, {
|
|
196
|
+
operation: 'setString',
|
|
197
|
+
key: k
|
|
198
|
+
}, ()=>core.store.setString(k, value));
|
|
199
|
+
},
|
|
200
|
+
remove (key) {
|
|
201
|
+
const k = full(key);
|
|
202
|
+
return write(core, k, null, {
|
|
203
|
+
operation: 'remove',
|
|
204
|
+
key: k
|
|
205
|
+
}, ()=>core.store.remove(k));
|
|
206
|
+
},
|
|
207
|
+
namespace (name) {
|
|
208
|
+
if ('string' != typeof name || '' === name || name.includes('.')) throw new G9Error('preference-key', `A namespace must be a non-empty name without '.', got ${String(name)}.`);
|
|
209
|
+
return view(core, `${prefix}${name}.`);
|
|
210
|
+
},
|
|
211
|
+
intKey (key, defaultValue = 0) {
|
|
212
|
+
checkKey(key);
|
|
213
|
+
return {
|
|
214
|
+
key,
|
|
215
|
+
get: ()=>self.getInt(key, defaultValue),
|
|
216
|
+
set: (value)=>self.setInt(key, value),
|
|
217
|
+
remove: ()=>self.remove(key)
|
|
218
|
+
};
|
|
219
|
+
},
|
|
220
|
+
stringKey (key, defaultValue = null) {
|
|
221
|
+
checkKey(key);
|
|
222
|
+
return {
|
|
223
|
+
key,
|
|
224
|
+
get: ()=>self.getString(key, defaultValue),
|
|
225
|
+
set: (value)=>self.setString(key, value),
|
|
226
|
+
remove: ()=>self.remove(key)
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
return self;
|
|
231
|
+
}
|
|
232
|
+
function createPreferences(options) {
|
|
233
|
+
var _options_keyPrefix;
|
|
234
|
+
const { store } = options;
|
|
235
|
+
if (!store || 'function' != typeof store.entries) throw new G9Error('preference-store', 'createPreferences needs a G9PreferenceStore (with entries()).');
|
|
236
|
+
const keyPrefix = null != (_options_keyPrefix = options.keyPrefix) ? _options_keyPrefix : g9PreferenceKeyPrefix;
|
|
237
|
+
if ('string' != typeof keyPrefix) throw new G9Error('preference-key', 'keyPrefix must be a string.');
|
|
238
|
+
const core = {
|
|
239
|
+
store,
|
|
240
|
+
rootPrefix: keyPrefix,
|
|
241
|
+
values: new Map(),
|
|
242
|
+
hydrated: false,
|
|
243
|
+
version: 0,
|
|
244
|
+
writtenBeforeHydration: new Set(),
|
|
245
|
+
hydration: null,
|
|
246
|
+
listeners: new Set(),
|
|
247
|
+
onStoreError: options.onStoreError
|
|
248
|
+
};
|
|
249
|
+
return view(core, keyPrefix);
|
|
250
|
+
}
|
|
251
|
+
export { createMemoryPreferenceStore, createPreferences, g9PreferenceKeyPrefix };
|
|
252
|
+
|
|
253
|
+
//# sourceMappingURL=preferences.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"services/preferences.js","sources":["../../src/services/preferences.ts"],"sourcesContent":["import { G9Error } from '../errors';\n\n/** A value or a promise of it: stores may be synchronous (memory) or asynchronous (a native module). */\nexport type G9MaybePromise<T> = T | Promise<T>;\n\n/** What a preference holds: a 32-bit integer or a string (MAUI `IG9PreferenceStore` stores exactly these). */\nexport type G9PreferenceValue = number | string;\n\n/**\n * Where preferences are persisted (MAUI `IG9PreferenceStore`). Keys arrive already prefixed. The app supplies one\n * through the provider: the Lynxtron, Android and iOS adapters (WP12–WP14) and {@link createMemoryPreferenceStore}.\n * A store may throw or reject; {@link createPreferences} guards every call.\n */\nexport interface G9PreferenceStore {\n /** The stored integer, or `defaultValue` when absent or not an integer. */\n getInt(key: string, defaultValue: number): G9MaybePromise<number>;\n /** Writes an integer. */\n setInt(key: string, value: number): G9MaybePromise<void>;\n /** The stored string, or `defaultValue` when absent or not a string. */\n getString(key: string, defaultValue: string | null): G9MaybePromise<string | null>;\n /** Writes a string. `null` removes the key. */\n setString(key: string, value: string | null): G9MaybePromise<void>;\n /** Removes a key. A key that is not present is not an error. */\n remove(key: string): G9MaybePromise<void>;\n /** Every stored entry whose key starts with `prefix` (hydration reads the whole namespace once). */\n entries(prefix: string): G9MaybePromise<ReadonlyArray<readonly [string, G9PreferenceValue]>>;\n}\n\nconst INT32_MIN = -2147483648;\nconst INT32_MAX = 2147483647;\n\nfunction isInt32(value: unknown): value is number {\n return typeof value === 'number' && Number.isInteger(value) && value >= INT32_MIN && value <= INT32_MAX;\n}\n\nfunction checkKey(key: unknown): string {\n if (typeof key !== 'string' || key === '')\n throw new G9Error('preference-key', `A preference key must be a non-empty string, got ${String(key)}.`);\n return key;\n}\n\nfunction checkInt(key: string, value: unknown): number {\n if (!isInt32(value))\n throw new G9Error('preference-value', `Preference '${key}' needs a 32-bit integer, got ${String(value)}.`);\n return value;\n}\n\nfunction checkString(key: string, value: unknown): string | null {\n if (value !== null && typeof value !== 'string')\n throw new G9Error('preference-value', `Preference '${key}' needs a string or null, got ${String(value)}.`);\n return value;\n}\n\n/**\n * An in-memory store (MAUI `G9InMemoryPreferenceStore`): for tests, previews, and apps that opt out of persistence.\n * Synchronous. Values are typed: an integer is not readable as a string and vice versa, as in MAUI.\n */\nexport function createMemoryPreferenceStore(initial?: Readonly<Record<string, G9PreferenceValue>>): G9PreferenceStore {\n const values = new Map<string, G9PreferenceValue>();\n for (const [key, value] of Object.entries(initial ?? {})) {\n if (typeof value === 'string') values.set(checkKey(key), value);\n else values.set(checkKey(key), checkInt(key, value));\n }\n return {\n getInt(key, defaultValue) {\n const value = values.get(key);\n return typeof value === 'number' ? value : defaultValue;\n },\n setInt(key, value) {\n values.set(checkKey(key), checkInt(key, value));\n },\n getString(key, defaultValue) {\n const value = values.get(key);\n return typeof value === 'string' ? value : defaultValue;\n },\n setString(key, value) {\n checkKey(key);\n if (checkString(key, value) === null) values.delete(key);\n else values.set(key, value as string);\n },\n remove(key) {\n values.delete(key);\n },\n entries(prefix) {\n return [...values].filter(([key]) => key.startsWith(prefix));\n },\n };\n}\n\n/** The prefix on every key the controls write (MAUI `G9Preferences.KeyPrefix`). */\nexport const g9PreferenceKeyPrefix = 'g9controls.';\n\n/** The values of one namespace, keys relative to it. Immutable; a new object after every change. */\nexport interface G9PreferencesSnapshot {\n /** `true` once {@link G9Preferences.hydrate} has merged the stored values (also after a failed read). */\n readonly hydrated: boolean;\n readonly values: Readonly<Record<string, G9PreferenceValue>>;\n}\n\n/** Which store call failed, for {@link G9PreferencesOptions.onStoreError}. */\nexport interface G9PreferenceStoreFailure {\n readonly operation: 'entries' | 'setInt' | 'setString' | 'remove';\n /** The full (prefixed) key; the prefix itself for `entries`. */\n readonly key: string;\n}\n\n/** Options of {@link createPreferences}. */\nexport interface G9PreferencesOptions {\n readonly store: G9PreferenceStore;\n /** Prefix of every key. Default {@link g9PreferenceKeyPrefix} (`'g9controls.'`). */\n readonly keyPrefix?: string;\n /**\n * Receives every store failure. Store calls never throw into the caller (MAUI: \"a forgotten sheet height is not\n * worth a crash\"); this is where they surface. Default: none (the failure only leaves the value unpersisted).\n */\n readonly onStoreError?: (error: unknown, failure: G9PreferenceStoreFailure) => void;\n}\n\n/** A typed handle on one key (see {@link G9Preferences.intKey} / {@link G9Preferences.stringKey}). */\nexport interface G9PreferenceKey<T> {\n /** The key relative to its namespace. */\n readonly key: string;\n get(): T;\n set(value: T): Promise<void>;\n remove(): Promise<void>;\n}\n\n/**\n * Typed, namespaced preferences over a store (MAUI `G9Preferences`), read synchronously from a hydrated snapshot.\n * Reads never touch the store: `hydrate()` loads the namespace once; writes update the snapshot immediately, notify\n * subscribers, then write through. A local write made before hydration finishes wins over the stored value.\n */\nexport interface G9Preferences {\n /** The full prefix of this namespace, e.g. `'g9controls.'` or `'g9controls.sheets.'`. */\n readonly keyPrefix: string;\n /** The underlying store. */\n readonly store: G9PreferenceStore;\n /**\n * Loads the stored values once (later calls share the same load; namespaces share it). A store failure is reported\n * to `onStoreError` and still ends hydration (reads keep their defaults); the promise rejects only when a subscriber\n * threw while being notified.\n */\n hydrate(): Promise<G9PreferencesSnapshot>;\n /** The current snapshot of this namespace; the same object until something in it changes. */\n getSnapshot(): G9PreferencesSnapshot;\n /** Called after each change in this namespace (and once on hydration). Returns an unsubscribe function. */\n subscribe(listener: (snapshot: G9PreferencesSnapshot) => void): () => void;\n /** The integer, or `defaultValue` (0) when absent or not an integer. */\n getInt(key: string, defaultValue?: number): number;\n /**\n * Writes a 32-bit integer: snapshot and subscribers first, then the store. The promise settles when the store write\n * ends and never rejects (failures go to `onStoreError`). Throws synchronously for invalid input\n * ({@link G9Error} `preference-key` / `preference-value`) or, after the write started, a subscriber's first error.\n */\n setInt(key: string, value: number): Promise<void>;\n /** The string, or `defaultValue` (`null`) when absent or not a string. */\n getString(key: string, defaultValue?: string | null): string | null;\n /** Writes a string; `null` removes the key. Same settlement and errors as {@link G9Preferences.setInt}. */\n setString(key: string, value: string | null): Promise<void>;\n /** Removes a key; absent is not an error. Same settlement as {@link G9Preferences.setInt}. */\n remove(key: string): Promise<void>;\n /** A child namespace: keys are `<keyPrefix><name>.<key>`. Shares the store, snapshot and hydration. */\n namespace(name: string): G9Preferences;\n /** A typed integer handle. */\n intKey(key: string, defaultValue?: number): G9PreferenceKey<number>;\n /** A typed string handle. */\n stringKey(key: string, defaultValue?: string | null): G9PreferenceKey<string | null>;\n}\n\ninterface Core {\n readonly store: G9PreferenceStore;\n readonly rootPrefix: string;\n values: ReadonlyMap<string, G9PreferenceValue>;\n hydrated: boolean;\n version: number;\n readonly writtenBeforeHydration: Set<string>;\n hydration: Promise<void> | null;\n readonly listeners: Set<(changedKey: string | null) => void>;\n readonly onStoreError: G9PreferencesOptions['onStoreError'];\n}\n\nfunction guard(core: Core, failure: G9PreferenceStoreFailure, call: () => G9MaybePromise<unknown>): Promise<void> {\n const report = (error: unknown) => {\n try {\n core.onStoreError?.(error, failure);\n } catch {\n // The error reporter itself failed; nothing further can be done for non-essential state.\n }\n };\n try {\n return Promise.resolve(call()).then(() => undefined, report);\n } catch (error) {\n report(error);\n return Promise.resolve();\n }\n}\n\n/** Applies a local write; returns the first subscriber error (every subscriber still runs). */\nfunction commit(core: Core, key: string, value: G9PreferenceValue | null): { error: unknown } | null {\n if (!core.hydrated) core.writtenBeforeHydration.add(key);\n const current = core.values.get(key);\n if (value === null ? current === undefined : current === value) return null;\n const next = new Map(core.values);\n if (value === null) next.delete(key);\n else next.set(key, value);\n core.values = next;\n core.version++;\n return notify(core, key);\n}\n\nfunction notify(core: Core, changedKey: string | null): { error: unknown } | null {\n let first: { error: unknown } | null = null;\n for (const listener of [...core.listeners]) {\n try {\n listener(changedKey);\n } catch (error) {\n first ??= { error };\n }\n }\n return first;\n}\n\n/** Write-through after the snapshot changed: the store write starts even when a subscriber threw. */\nfunction write(\n core: Core,\n key: string,\n value: G9PreferenceValue | null,\n failure: G9PreferenceStoreFailure,\n call: () => G9MaybePromise<unknown>,\n): Promise<void> {\n const listenerError = commit(core, key, value);\n const done = guard(core, failure, call);\n if (listenerError) throw listenerError.error;\n return done;\n}\n\nfunction startHydration(core: Core): Promise<void> {\n const merge = (entries: ReadonlyArray<readonly [string, G9PreferenceValue]>) => {\n const next = new Map(core.values);\n for (const entry of Array.isArray(entries) ? entries : []) {\n const [key, value] = entry;\n if (typeof key !== 'string' || !key.startsWith(core.rootPrefix) || core.writtenBeforeHydration.has(key)) continue;\n if (typeof value === 'string' || isInt32(value)) next.set(key, value);\n }\n finish(next);\n };\n const fail = (error: unknown) => {\n try {\n core.onStoreError?.(error, { operation: 'entries', key: core.rootPrefix });\n } catch {\n // See guard().\n }\n finish(core.values);\n };\n const finish = (next: ReadonlyMap<string, G9PreferenceValue>) => {\n core.values = next;\n core.hydrated = true;\n core.writtenBeforeHydration.clear();\n core.version++;\n const listenerError = notify(core, null);\n if (listenerError) throw listenerError.error;\n };\n try {\n let result: G9MaybePromise<ReadonlyArray<readonly [string, G9PreferenceValue]>>;\n try {\n result = core.store.entries(core.rootPrefix);\n } catch (error) {\n fail(error);\n return Promise.resolve();\n }\n if (result && typeof (result as Promise<unknown>).then === 'function')\n return (result as Promise<ReadonlyArray<readonly [string, G9PreferenceValue]>>).then(merge, fail);\n // A synchronous store hydrates before hydrate() returns, so the first render already sees stored values.\n merge(result as ReadonlyArray<readonly [string, G9PreferenceValue]>);\n return Promise.resolve();\n } catch (listenerError) {\n return Promise.reject(listenerError);\n }\n}\n\nfunction view(core: Core, prefix: string): G9Preferences {\n let cachedVersion = -1;\n let cached: G9PreferencesSnapshot = { hydrated: false, values: {} };\n const full = (key: string) => prefix + checkKey(key);\n const snapshot = (): G9PreferencesSnapshot => {\n if (cachedVersion !== core.version) {\n const values: Record<string, G9PreferenceValue> = {};\n for (const [key, value] of core.values) if (key.startsWith(prefix)) values[key.slice(prefix.length)] = value;\n cached = Object.freeze({ hydrated: core.hydrated, values: Object.freeze(values) });\n cachedVersion = core.version;\n }\n return cached;\n };\n const self: G9Preferences = {\n keyPrefix: prefix,\n store: core.store,\n hydrate() {\n core.hydration ??= startHydration(core);\n return core.hydration.then(snapshot);\n },\n getSnapshot: snapshot,\n subscribe(listener) {\n const wrapped = (changedKey: string | null) => {\n if (changedKey === null || changedKey.startsWith(prefix)) listener(snapshot());\n };\n core.listeners.add(wrapped);\n return () => {\n core.listeners.delete(wrapped);\n };\n },\n getInt(key, defaultValue = 0) {\n const value = core.values.get(full(key));\n return typeof value === 'number' ? value : defaultValue;\n },\n setInt(key, value) {\n const k = full(key);\n checkInt(k, value);\n return write(core, k, value, { operation: 'setInt', key: k }, () => core.store.setInt(k, value));\n },\n getString(key, defaultValue = null) {\n const value = core.values.get(full(key));\n return typeof value === 'string' ? value : defaultValue;\n },\n setString(key, value) {\n const k = full(key);\n checkString(k, value);\n return write(core, k, value, { operation: 'setString', key: k }, () => core.store.setString(k, value));\n },\n remove(key) {\n const k = full(key);\n return write(core, k, null, { operation: 'remove', key: k }, () => core.store.remove(k));\n },\n namespace(name) {\n if (typeof name !== 'string' || name === '' || name.includes('.'))\n throw new G9Error('preference-key', `A namespace must be a non-empty name without '.', got ${String(name)}.`);\n return view(core, `${prefix}${name}.`);\n },\n intKey(key, defaultValue = 0) {\n checkKey(key);\n return {\n key,\n get: () => self.getInt(key, defaultValue),\n set: (value) => self.setInt(key, value),\n remove: () => self.remove(key),\n };\n },\n stringKey(key, defaultValue = null) {\n checkKey(key);\n return {\n key,\n get: () => self.getString(key, defaultValue),\n set: (value) => self.setString(key, value),\n remove: () => self.remove(key),\n };\n },\n };\n return self;\n}\n\n/** Creates the root {@link G9Preferences} over a store. One per app; the WP02 provider owns it. */\nexport function createPreferences(options: G9PreferencesOptions): G9Preferences {\n const { store } = options;\n if (!store || typeof store.entries !== 'function')\n throw new G9Error('preference-store', 'createPreferences needs a G9PreferenceStore (with entries()).');\n const keyPrefix = options.keyPrefix ?? g9PreferenceKeyPrefix;\n if (typeof keyPrefix !== 'string') throw new G9Error('preference-key', 'keyPrefix must be a string.');\n const core: Core = {\n store,\n rootPrefix: keyPrefix,\n values: new Map(),\n hydrated: false,\n version: 0,\n writtenBeforeHydration: new Set(),\n hydration: null,\n listeners: new Set(),\n onStoreError: options.onStoreError,\n };\n return view(core, keyPrefix);\n}\n"],"names":["INT32_MIN","INT32_MAX","isInt32","value","Number","checkKey","key","G9Error","String","checkInt","checkString","createMemoryPreferenceStore","initial","values","Map","Object","defaultValue","prefix","g9PreferenceKeyPrefix","guard","core","failure","call","report","error","Promise","undefined","commit","current","next","notify","changedKey","first","listener","write","listenerError","done","startHydration","merge","entries","entry","Array","finish","fail","result","view","cachedVersion","cached","full","snapshot","self","_core","wrapped","k","name","createPreferences","options","_options_keyPrefix","store","keyPrefix","Set"],"mappings":";AA4BA,MAAMA,YAAY;AAClB,MAAMC,YAAY;AAElB,SAASC,QAAQC,KAAc;IAC7B,OAAO,AAAiB,YAAjB,OAAOA,SAAsBC,OAAO,SAAS,CAACD,UAAUA,SAASH,aAAaG,SAASF;AAChG;AAEA,SAASI,SAASC,GAAY;IAC5B,IAAI,AAAe,YAAf,OAAOA,OAAoBA,AAAQ,OAARA,KAC7B,MAAM,IAAIC,QAAQ,kBAAkB,CAAC,iDAAiD,EAAEC,OAAOF,KAAK,CAAC,CAAC;IACxG,OAAOA;AACT;AAEA,SAASG,SAASH,GAAW,EAAEH,KAAc;IAC3C,IAAI,CAACD,QAAQC,QACX,MAAM,IAAII,QAAQ,oBAAoB,CAAC,YAAY,EAAED,I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B,KAAK,CAACb,QAAU+C,KAAK,MAAM,CAAC5C,KAAKH;gBACjC,QAAQ,IAAM+C,KAAK,MAAM,CAAC5C;YAC5B;QACF;QACA,WAAUA,GAAG,EAAEU,eAAe,IAAI;YAChCX,SAASC;YACT,OAAO;gBACLA;gBACA,KAAK,IAAM4C,KAAK,SAAS,CAAC5C,KAAKU;gBAC/B,KAAK,CAACb,QAAU+C,KAAK,SAAS,CAAC5C,KAAKH;gBACpC,QAAQ,IAAM+C,KAAK,MAAM,CAAC5C;YAC5B;QACF;IACF;IACA,OAAO4C;AACT;AAGO,SAASK,kBAAkBC,OAA6B;QAI3CC;IAHlB,MAAM,EAAEC,KAAK,EAAE,GAAGF;IAClB,IAAI,CAACE,SAAS,AAAyB,cAAzB,OAAOA,MAAM,OAAO,EAChC,MAAM,IAAInD,QAAQ,oBAAoB;IACxC,MAAMoD,YAAY,QAAAF,CAAAA,qBAAAA,QAAQ,SAAS,AAAD,IAAhBA,qBAAqBvC;IACvC,IAAI,AAAqB,YAArB,OAAOyC,WAAwB,MAAM,IAAIpD,QAAQ,kBAAkB;IACvE,MAAMa,OAAa;QACjBsC;QACA,YAAYC;QACZ,QAAQ,IAAI7C;QACZ,UAAU;QACV,SAAS;QACT,wBAAwB,IAAI8C;QAC5B,WAAW;QACX,WAAW,IAAIA;QACf,cAAcJ,QAAQ,YAAY;IACpC;IACA,OAAOX,KAAKzB,MAAMuC;AACpB"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { G9Error } from '../errors.js';
|
|
2
|
+
/**
|
|
3
|
+
* A CSS colour string, the value type every G9 colour prop takes (plan/specs/03-API-Conventions.md §2). Use
|
|
4
|
+
* {@link g9Token} for a theme token reference such as `var(--g9-primary)`.
|
|
5
|
+
*/
|
|
6
|
+
export type G9Color = string;
|
|
7
|
+
/**
|
|
8
|
+
* A colour as four channels in `0..1`, stored at float32 precision exactly like MAUI `Color`. Colour arithmetic
|
|
9
|
+
* (darken, mix, contrast) runs on this shape so its results match the original helpers bit for bit; format with
|
|
10
|
+
* {@link formatColor} to get a CSS string back.
|
|
11
|
+
*/
|
|
12
|
+
export interface G9Rgba {
|
|
13
|
+
readonly r: number;
|
|
14
|
+
readonly g: number;
|
|
15
|
+
readonly b: number;
|
|
16
|
+
readonly a: number;
|
|
17
|
+
}
|
|
18
|
+
/** Anything the colour helpers accept: a CSS colour string or channels. */
|
|
19
|
+
export type G9ColorInput = G9Color | G9Rgba;
|
|
20
|
+
/** Thrown when a string is not a colour this library can read. */
|
|
21
|
+
export declare class G9ColorFormatError extends G9Error {
|
|
22
|
+
/** The rejected input. */
|
|
23
|
+
readonly input: string;
|
|
24
|
+
constructor(input: string, accepted: string);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Builds channels the way the MAUI `Color(float, float, float, float)` constructor does: each channel is clamped to
|
|
28
|
+
* `0..1` and stored as float32. `NaN` stays `NaN`, as it does in .NET.
|
|
29
|
+
*/
|
|
30
|
+
export declare function rgba(r: number, g: number, b: number, a?: number): G9Rgba;
|
|
31
|
+
/**
|
|
32
|
+
* Parses a colour written the MAUI way: `#rgb`, `#argb`, `#rrggbb` or `#aarrggbb`. Note the **alpha-first** order
|
|
33
|
+
* for 4 and 8 digits, unlike CSS. This is how the MAUI theme dictionaries and `golden/theme-palettes.json` spell
|
|
34
|
+
* colours.
|
|
35
|
+
*/
|
|
36
|
+
export declare function parseMauiColor(hex: string): G9Rgba;
|
|
37
|
+
/**
|
|
38
|
+
* Parses a CSS colour: `#rgb`, `#rgba`, `#rrggbb`, `#rrggbbaa` (CSS order, alpha last), `rgb(r, g, b)`,
|
|
39
|
+
* `rgba(r, g, b, a)` (channels 0–255 or percentages, alpha 0–1 or a percentage) and `transparent`.
|
|
40
|
+
* Named colours other than `transparent` are not accepted: the palette tokens are the names.
|
|
41
|
+
*
|
|
42
|
+
* @throws {G9ColorFormatError} for anything else.
|
|
43
|
+
*/
|
|
44
|
+
export declare function parseColor(value: string): G9Rgba;
|
|
45
|
+
/** {@link parseColor} that returns `undefined` instead of throwing. */
|
|
46
|
+
export declare function tryParseColor(value: string): G9Rgba | undefined;
|
|
47
|
+
/** Normalises a helper input to channels. Strings go through {@link parseColor}. */
|
|
48
|
+
export declare function toRgba(color: G9ColorInput): G9Rgba;
|
|
49
|
+
/**
|
|
50
|
+
* Formats a colour as CSS: `#RRGGBB` when opaque, otherwise `rgba(R, G, B, A)`. Channels are rounded to the nearest
|
|
51
|
+
* byte; the alpha is printed with the fewest digits that parse back to the same float32 value, so
|
|
52
|
+
* `parseColor(formatColor(c))` reproduces the alpha exactly.
|
|
53
|
+
*/
|
|
54
|
+
export declare function formatColor(color: G9ColorInput): G9Color;
|
|
55
|
+
/**
|
|
56
|
+
* MAUI `G9ColorHelper.ToHex`: `#RRGGBB` without alpha, each channel **truncated** after a float32 multiply by 255 —
|
|
57
|
+
* the original's exact arithmetic, kept so derived colours print the same hex as before.
|
|
58
|
+
*/
|
|
59
|
+
export declare function toHex(color: G9ColorInput): string;
|
|
60
|
+
/** The same colour with a new alpha (`MAUI Color.WithAlpha`); `alpha` is clamped to `0..1`. */
|
|
61
|
+
export declare function withAlpha(color: G9ColorInput, alpha: number): G9Rgba;
|
|
62
|
+
/**
|
|
63
|
+
* MAUI `G9ColorHelper.WithOpacity`. `null`/`undefined` returns the colour unchanged; a number or an invariant-culture
|
|
64
|
+
* numeric string sets the alpha, clamped to `0..1`; an unreadable string means opacity `1`.
|
|
65
|
+
*/
|
|
66
|
+
export declare function withOpacity(color: G9ColorInput, opacity: number | string | null | undefined): G9Rgba;
|
|
67
|
+
/**
|
|
68
|
+
* MAUI `G9AlphaConverter.Convert`: applies `alpha` (clamped to `0..1`) when it is a number, otherwise returns the
|
|
69
|
+
* colour unchanged. `ConvertBack` had no behaviour (it threw) and has no counterpart.
|
|
70
|
+
*/
|
|
71
|
+
export declare function applyAlpha(color: G9ColorInput, alpha: number | null | undefined): G9Rgba;
|
|
72
|
+
/** Darkens each RGB channel by `percentage` (`0..1`, clamped); alpha is kept. MAUI `G9ColorHelper.Darken`. */
|
|
73
|
+
export declare function darken(color: G9ColorInput, percentage: number): G9Rgba;
|
|
74
|
+
/** Moves each RGB channel towards white by `percentage` (`0..1`, clamped). MAUI `G9ColorHelper.Lighten`. */
|
|
75
|
+
export declare function lighten(color: G9ColorInput, percentage: number): G9Rgba;
|
|
76
|
+
/** Linear mix of all four channels: `ratio` 0 is all `first`, 1 is all `second` (clamped). MAUI `Mix`. */
|
|
77
|
+
export declare function mix(first: G9ColorInput, second: G9ColorInput, ratio: number): G9Rgba;
|
|
78
|
+
/** 15 % darker: the stock border recipe. MAUI `G9ColorHelper.CreateBorderColor`. */
|
|
79
|
+
export declare const createBorderColor: (base: G9ColorInput) => G9Rgba;
|
|
80
|
+
/** 8 % darker: the stock hover recipe. MAUI `G9ColorHelper.CreateHoverColor`. */
|
|
81
|
+
export declare const createHoverColor: (base: G9ColorInput) => G9Rgba;
|
|
82
|
+
/** 20 % darker: the stock pressed recipe. MAUI `G9ColorHelper.CreatePressedColor`. */
|
|
83
|
+
export declare const createPressedColor: (base: G9ColorInput) => G9Rgba;
|
|
84
|
+
/** WCAG relative luminance, `0` (black) to `1` (white). Alpha is ignored, as in MAUI. */
|
|
85
|
+
export declare function getLuminance(color: G9ColorInput): number;
|
|
86
|
+
/** Black on light backgrounds (luminance above 0.5), white otherwise. MAUI `GetContrastingTextColor`. */
|
|
87
|
+
export declare function getContrastingTextColor(background: G9ColorInput): G9Rgba;
|
|
88
|
+
/** WCAG contrast ratio, `1` to `21`. */
|
|
89
|
+
export declare function getContrastRatio(first: G9ColorInput, second: G9ColorInput): number;
|
|
90
|
+
/** Contrast of at least 4.5:1 (WCAG AA, normal text). */
|
|
91
|
+
export declare const meetsWcagAA: (foreground: G9ColorInput, background: G9ColorInput) => boolean;
|
|
92
|
+
/** Contrast of at least 7:1 (WCAG AAA, normal text). */
|
|
93
|
+
export declare const meetsWcagAAA: (foreground: G9ColorInput, background: G9ColorInput) => boolean;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