@weasel-js/prefs-schema 1.19.1 → 2.0.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/{chunk-SGUOG5QO.js → chunk-DVHFV6JS.js} +76 -50
- package/dist/chunk-DVHFV6JS.js.map +1 -0
- package/dist/index.d.ts +133 -12
- package/dist/index.js +108 -54
- package/dist/index.js.map +1 -1
- package/dist/{internal-Ad6SCtbG.d.ts → internal-DMioFJDY.d.ts} +43 -34
- package/dist/internal.d.ts +2 -1
- package/dist/internal.js +1 -1
- package/package.json +5 -5
- package/dist/chunk-SGUOG5QO.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
|
-
import { P as
|
|
2
|
-
export { B as BuiltinPref, o as PREF_ELSE, p as PREF_KINDS, q as PX_UNIT, r as PrefActionContext, s as PrefActionControl, t as PrefAlias, u as PrefAuto, v as PrefBarLead, w as PrefBarOverflow, x as PrefBase, y as PrefBooleanControl, z as PrefBooleanEncoding, A as PrefBoundAt, C as PrefBoundReader, D as
|
|
1
|
+
import { P as PrefGroup, a as PrefSection, b as PrefCondition, c as PrefLeaf, d as PrefConditionReader, e as PrefNumberBase, f as PrefBoolean, g as PrefString, h as PrefColor, i as PrefEnumBase, j as PrefAction, k as PrefActions, l as PrefLabel, m as PrefSeparator, n as PrefObject } from './internal-DMioFJDY.js';
|
|
2
|
+
export { B as BuiltinPref, o as PREF_ELSE, p as PREF_KINDS, q as PX_UNIT, r as PrefActionContext, s as PrefActionControl, t as PrefAlias, u as PrefAuto, v as PrefBarLead, w as PrefBarOverflow, x as PrefBase, y as PrefBooleanControl, z as PrefBooleanEncoding, A as PrefBoundAt, C as PrefBoundReader, D as PrefConditionFrom, E as PrefConditionValue, F as PrefCustom, G as PrefEnum, H as PrefEnumControl, I as PrefEnumEncoding, J as PrefEnumOption, K as PrefField, L as PrefFunctionUnit, M as PrefGroupAs, N as PrefKind, O as PrefLinearUnit, Q as PrefList, R as PrefListControl, S as PrefMap, T as PrefNumber, U as PrefNumberControl, V as PrefNumberScale, W as PrefNumberUnit, X as PrefOverrides, Y as PrefOverridesLookup, Z as PrefPaint, _ as PrefPair, $ as PrefScope, a0 as PrefScopeSpec, a1 as PrefSectionAs, a2 as PrefSelection, a3 as PrefStringControl, a4 as PrefTest, a5 as PrefUnion, a6 as PrefUnitText, a7 as PrefValueBase, a8 as PrefWeighted, a9 as PrefWeights, aa as ResolvedPrefUnit, ab as VERSION_RECORD, ac as filterPrefSubtree, ad as flattenPrefValues, ae as isBuiltinPref, af as isPrefCondition, ag as isPrefLeaf, ah as isPrefLinearUnit, ai as isPrefScope, aj as isPrefSection, ak as mapPrefConditionPaths, al as nestPrefValues, am as prefAliasName, an as prefAliasTarget, ao as prefAliasedLeaf, ap as prefBoundedNumber, aq as prefClampNumber, ar as prefConditionHolds, as as prefConditionInGroup, at as prefConditionPaths, au as prefConditionReadsItem, av as prefDisplayBounds, aw as prefDrawsAsBox, ax as prefGroupIsPage, ay as prefHoldsValue, az as prefIsEnabled, aA as prefIsShown, aB as prefLeafAt, aC as prefLeaves, aD as prefOverrideOptions, aE as prefOverridesOf, aF as prefPairRows, aG as prefSchemaHolding, aH as prefScopeOptionValue, aI as prefScopeValue, aJ as prefScopedDefault, aK as prefScopesOf, aL as prefSectionLeaves, aM as prefStoredSelectors, aN as prefUnit, aO as prefUnitAccepts, aP as prefValueAt, aQ as prefVariantDefault, aR as prefVariantOf, aS as resolvePrefUnit, aT as visiblePrefSubtree } from './internal-DMioFJDY.js';
|
|
3
3
|
import '@weasel-js/quantity';
|
|
4
4
|
import '@weasel-js/icons';
|
|
5
|
+
import '@weasel-js/registry';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* `schema` with every condition test read from its node's group (`from: 'group'`) read from the root instead: the
|
|
9
|
+
* form the condition readers, the status walks and the store's checks take. The same object comes back for the same
|
|
10
|
+
* schema, and the schema itself where no test reads from its group.
|
|
11
|
+
*/
|
|
12
|
+
declare function resolvePrefGroupConditions<T extends PrefGroup | PrefSection>(schema: T): T;
|
|
5
13
|
|
|
6
14
|
/** Every field a schema node holds a {@link PrefCondition} in. `activeIf` is an action leaf's alone. */
|
|
7
15
|
declare const PREF_CONDITION_FIELDS: readonly ["showIf", "enableIf", "activeIf"];
|
|
@@ -52,7 +60,7 @@ declare const PREF_ENTRY = "*";
|
|
|
52
60
|
*/
|
|
53
61
|
declare const prefSectionPath: (at: string, key: string) => string;
|
|
54
62
|
/** The status a schema's root sits in. */
|
|
55
|
-
declare const
|
|
63
|
+
declare const ROOT_PREF_STATUS: PrefStatus;
|
|
56
64
|
/** The status of `node`, which sits directly under something whose status is `above`. */
|
|
57
65
|
declare function prefStatusUnder(above: PrefStatus, node: {
|
|
58
66
|
showIf?: PrefCondition;
|
|
@@ -150,7 +158,7 @@ interface PrefConditionsOptions {
|
|
|
150
158
|
* looked for in `aliasOver`, and its side is asked of `aliasHolds`.
|
|
151
159
|
* Parts with nothing dropped come back as the objects they were.
|
|
152
160
|
*/
|
|
153
|
-
declare function applyPrefConditions<T extends PrefGroup | PrefSection>(schema: T, holds: PrefConditionJudge, { keepEmpty, keepHidden, aliasOver, aliasHolds }?: PrefConditionsOptions): PrefConditionsApplied<T>;
|
|
161
|
+
declare function applyPrefConditions<T extends PrefGroup | PrefSection>(schema: T, holds: PrefConditionJudge, { keepEmpty, keepHidden, aliasOver: overGiven, aliasHolds }?: PrefConditionsOptions): PrefConditionsApplied<T>;
|
|
154
162
|
/** One entry of a list or a map with the conditions that read it applied. */
|
|
155
163
|
interface PrefEntryApplied {
|
|
156
164
|
/** The item as this entry draws it: without the fields not shown, and the item itself when that is all of them. */
|
|
@@ -174,9 +182,9 @@ declare function applyPrefEntryConditions(item: PrefLeaf, path: string, holds: P
|
|
|
174
182
|
|
|
175
183
|
/** What the control over `leaf` shows for `stored`: what its `encoding` reads it as, else `stored` itself.
|
|
176
184
|
* `siblings` is the object the leaf is a field of. */
|
|
177
|
-
declare function
|
|
185
|
+
declare function prefDecodedValue(leaf: PrefLeaf, stored: unknown, siblings?: Record<string, unknown>): unknown;
|
|
178
186
|
/**
|
|
179
|
-
* `read` with each value handed back as {@link
|
|
187
|
+
* `read` with each value handed back as {@link prefDecodedValue} gives it, for
|
|
180
188
|
* the leaf of `schema` at that path, a field of an `object` or a `union` leaf
|
|
181
189
|
* included. A field's siblings are what `read` finds at its leaf's path. A
|
|
182
190
|
* path read from the entry is held to `item`, the leaf describing that entry.
|
|
@@ -193,7 +201,7 @@ declare function prefValueAbsent(leaf: PrefLeaf, held: unknown): boolean;
|
|
|
193
201
|
* nothing. `unset` is for a surface where holding nothing means the owner has
|
|
194
202
|
* no such property, a scene node's: it shows nothing there too.
|
|
195
203
|
*/
|
|
196
|
-
declare function
|
|
204
|
+
declare function prefValueOrDefault(leaf: PrefLeaf, held: unknown, { unset }?: {
|
|
197
205
|
unset?: boolean;
|
|
198
206
|
}): unknown;
|
|
199
207
|
|
|
@@ -214,8 +222,9 @@ declare const pref: {
|
|
|
214
222
|
section<const M extends Record<string, PrefLeaf | PrefSection>>(name: string, members: M, options?: Omit<PrefSection, "name" | "members">): Omit<PrefSection, "members"> & {
|
|
215
223
|
members: M;
|
|
216
224
|
};
|
|
217
|
-
number: (name: string, def: number, rest?: PrefLeafRest<
|
|
225
|
+
number: (name: string, def: number, rest?: PrefLeafRest<PrefNumberBase>) => PrefNumberBase & {
|
|
218
226
|
default: number;
|
|
227
|
+
clearable?: false;
|
|
219
228
|
};
|
|
220
229
|
boolean: (name: string, def: boolean, rest?: PrefLeafRest<PrefBoolean>) => PrefBoolean;
|
|
221
230
|
string: (name: string, def: string, rest?: PrefLeafRest<PrefString>) => PrefString;
|
|
@@ -235,8 +244,8 @@ declare const pref: {
|
|
|
235
244
|
|
|
236
245
|
/**
|
|
237
246
|
* The object a write to one field of an `object` leaf starts from: `held` itself where it is one. Where it is
|
|
238
|
-
* not, the write has to make a whole object, so it starts from
|
|
239
|
-
* from the leaf's `default`: one field on its own is a stroke with a width and no paint.
|
|
247
|
+
* not, the write has to make a whole object, so it starts from a held scalar lifted by the leaf's `fromScalar`,
|
|
248
|
+
* else from the leaf's `default`: one field on its own is a stroke with a width and no paint.
|
|
240
249
|
*/
|
|
241
250
|
declare function prefObjectBase(pref: PrefObject, held: unknown): Record<string, unknown>;
|
|
242
251
|
/** The value of the field `key` in `held`. A dotted key (`'nib.angle'`) names a field of a field. */
|
|
@@ -270,5 +279,117 @@ interface PresetDescription {
|
|
|
270
279
|
includes: readonly string[];
|
|
271
280
|
}
|
|
272
281
|
|
|
273
|
-
|
|
274
|
-
|
|
282
|
+
/** Every value's dotted path in a `PrefGroup` schema, where a group's key is a
|
|
283
|
+
* segment; an `object` leaf is one path, its fields are not, and an `action`,
|
|
284
|
+
* `actions`, `alias`, `label`, or `separator` leaf, holding no value, has none. A `PrefSection`
|
|
285
|
+
* has no such paths: each of its leaves is addressed by its own key. */
|
|
286
|
+
type PrefPath<G, Prefix extends string = ''> = G extends {
|
|
287
|
+
children: infer C;
|
|
288
|
+
} ? string extends keyof C ? Prefix extends '' ? string : `${Prefix}.${string}` : {
|
|
289
|
+
[K in keyof C & string]: C[K] extends {
|
|
290
|
+
kind: string;
|
|
291
|
+
} ? C[K] extends {
|
|
292
|
+
kind: 'action' | 'actions' | 'alias' | 'label' | 'separator';
|
|
293
|
+
} ? never : Prefix extends '' ? K : `${Prefix}.${K}` : C[K] extends {
|
|
294
|
+
children: Record<string, unknown>;
|
|
295
|
+
} ? PrefPath<C[K], Prefix extends '' ? K : `${Prefix}.${K}`> : never;
|
|
296
|
+
}[keyof C & string] : never;
|
|
297
|
+
/** The leaf at `P`. `unknown` under a group whose keys are not literal, as a
|
|
298
|
+
* schema built at run time has them: nothing says which leaf is there, so
|
|
299
|
+
* its value reads as `unknown`. */
|
|
300
|
+
type PrefAtPath<G, P extends string> = G extends {
|
|
301
|
+
children: infer C;
|
|
302
|
+
} ? string extends keyof C ? unknown : P extends `${infer H}.${infer Rest}` ? H extends keyof C ? C[H] extends {
|
|
303
|
+
kind: string;
|
|
304
|
+
} ? never : PrefAtPath<C[H], Rest> : never : P extends keyof C ? C[P] extends {
|
|
305
|
+
kind: string;
|
|
306
|
+
} ? C[P] : never : never : never;
|
|
307
|
+
/** The fields an `object` leaf's `children` describe, sections folded in. Each is optional: an object may omit any. */
|
|
308
|
+
type PrefFieldsOf<C> = {
|
|
309
|
+
[K in keyof C as C[K] extends {
|
|
310
|
+
kind: string;
|
|
311
|
+
} ? K : never]?: PrefValueOf<C[K]>;
|
|
312
|
+
} & (({
|
|
313
|
+
[K in keyof C]: C[K] extends {
|
|
314
|
+
members: infer M;
|
|
315
|
+
} ? (x: PrefFieldsOf<M>) => void : never;
|
|
316
|
+
}[keyof C]) extends (x: infer I) => void ? I : never);
|
|
317
|
+
/** What a leaf holds: its kind's value type for a built-in kind, the type of
|
|
318
|
+
* its `default` for an app-defined one. A list holds an array of what its
|
|
319
|
+
* `item` holds, a map a record of it, and a union one variant's fields
|
|
320
|
+
* under that variant's tag — where the schema keeps `tag` a literal
|
|
321
|
+
* (`tag: 'type' as const`); one widened to `string` is typed by its default. */
|
|
322
|
+
type PrefValueOf<L> = L extends {
|
|
323
|
+
kind: 'number';
|
|
324
|
+
} ? L extends {
|
|
325
|
+
clearable: true;
|
|
326
|
+
} ? number | undefined : number : L extends {
|
|
327
|
+
kind: 'boolean';
|
|
328
|
+
} ? boolean : L extends {
|
|
329
|
+
kind: 'string' | 'color' | 'field';
|
|
330
|
+
} ? string : L extends {
|
|
331
|
+
kind: 'paint';
|
|
332
|
+
} ? unknown : L extends {
|
|
333
|
+
kind: 'enum';
|
|
334
|
+
options: readonly {
|
|
335
|
+
value: infer T;
|
|
336
|
+
}[];
|
|
337
|
+
} ? L extends {
|
|
338
|
+
clearable: true;
|
|
339
|
+
} ? T | undefined : T : L extends {
|
|
340
|
+
kind: 'list';
|
|
341
|
+
item: infer I;
|
|
342
|
+
} ? PrefValueOf<I>[] : L extends {
|
|
343
|
+
kind: 'map';
|
|
344
|
+
item: infer I;
|
|
345
|
+
} ? Record<string, PrefValueOf<I>> : L extends {
|
|
346
|
+
kind: 'union';
|
|
347
|
+
tag: infer T extends string;
|
|
348
|
+
variants: infer V;
|
|
349
|
+
default: infer D;
|
|
350
|
+
} ? string extends keyof V | T ? D : {
|
|
351
|
+
[K in keyof V & string]: {
|
|
352
|
+
[P in T]: K;
|
|
353
|
+
} & (V[K] extends {
|
|
354
|
+
children: infer C;
|
|
355
|
+
} ? PrefFieldsOf<C> : unknown);
|
|
356
|
+
}[keyof V & string] : L extends {
|
|
357
|
+
default: infer D;
|
|
358
|
+
} ? D : unknown;
|
|
359
|
+
/** What the leaf at `P` holds. */
|
|
360
|
+
type PrefValueAt<G, P extends string> = PrefValueOf<PrefAtPath<G, P>>;
|
|
361
|
+
/** Every group's dotted path in a `PrefGroup` schema: the paths `PrefValuesOf` can be read at. */
|
|
362
|
+
type PrefGroupPath<G, Prefix extends string = ''> = G extends {
|
|
363
|
+
children: infer C;
|
|
364
|
+
} ? string extends keyof C ? Prefix extends '' ? string : `${Prefix}.${string}` : {
|
|
365
|
+
[K in keyof C & string]: C[K] extends {
|
|
366
|
+
kind: string;
|
|
367
|
+
} ? never : C[K] extends {
|
|
368
|
+
children: Record<string, unknown>;
|
|
369
|
+
} ? (Prefix extends '' ? K : `${Prefix}.${K}`) | PrefGroupPath<C[K], Prefix extends '' ? K : `${Prefix}.${K}`> : never;
|
|
370
|
+
}[keyof C & string] : never;
|
|
371
|
+
/** The group at `P`. */
|
|
372
|
+
type PrefGroupAt<G, P extends string> = G extends {
|
|
373
|
+
children: infer C;
|
|
374
|
+
} ? P extends `${infer H}.${infer Rest}` ? H extends keyof C ? PrefGroupAt<C[H], Rest> : never : P extends keyof C ? (C[P] extends {
|
|
375
|
+
kind: string;
|
|
376
|
+
} ? never : C[P]) : never : never;
|
|
377
|
+
/** What a group holds: an object keyed like its `children`, with each leaf's value
|
|
378
|
+
* at its key and each nested group's values under its own. A leaf that holds no
|
|
379
|
+
* value (an action, an alias, a label, a separator) gets no key. */
|
|
380
|
+
type PrefValuesOf<G> = G extends {
|
|
381
|
+
children: infer C;
|
|
382
|
+
} ? {
|
|
383
|
+
-readonly [K in keyof C as C[K] extends {
|
|
384
|
+
kind: 'action' | 'actions' | 'alias' | 'label' | 'separator';
|
|
385
|
+
} ? never : C[K] extends {
|
|
386
|
+
kind: string;
|
|
387
|
+
} | {
|
|
388
|
+
children: unknown;
|
|
389
|
+
} ? K : never]: C[K] extends {
|
|
390
|
+
kind: string;
|
|
391
|
+
} ? PrefValueOf<C[K]> : PrefValuesOf<C[K]>;
|
|
392
|
+
} : never;
|
|
393
|
+
|
|
394
|
+
export { PREF_CONDITION_FIELDS, PREF_ENTRY, PrefAction, PrefActions, PrefBoolean, PrefColor, PrefCondition, PrefConditionReader, PrefEnumBase, PrefGroup, PrefLabel, PrefLeaf, PrefNumberBase, PrefObject, PrefSection, PrefSeparator, PrefString, ROOT_PREF_STATUS, applyPrefConditions, applyPrefEntryConditions, pref, prefDecodedValue, prefJudge, prefObjectBase, prefObjectField, prefObjectWithField, prefReader, prefSectionPath, prefShownReader, prefStatusAt, prefStatusIn, prefStatusUnder, prefValueAbsent, prefValueOrDefault, repairPrefValue, resolvePrefGroupConditions };
|
|
395
|
+
export type { PrefAtPath, PrefConditionField, PrefConditionJudge, PrefConditionsApplied, PrefConditionsOptions, PrefEntry, PrefEntryApplied, PrefFieldsOf, PrefGroupAt, PrefGroupPath, PrefLeafRest, PrefOwner, PrefPath, PrefStatus, PrefStatusAtOptions, PrefValidator, PrefValueAt, PrefValueOf, PrefValuesOf, PresetDescription };
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { prefLeavesHoldingIn, prefLeavesHolding, prefSchemaHolding, UNSEEN, prefConditionHolds,
|
|
2
|
-
export { PREF_ELSE, PREF_KINDS, PX_UNIT, VERSION_RECORD, filterPrefSubtree, flattenPrefValues, isBuiltinPref, isPrefCondition, isPrefLeaf, isPrefLinearUnit, isPrefScope, isPrefSection, mapPrefConditionPaths, nestPrefValues,
|
|
1
|
+
import { isPrefCondition, prefConditionInGroup, prefLeavesHoldingIn, prefLeavesHolding, prefSchemaHolding, UNSEEN, prefConditionHolds, prefValueAt, isPrefSection, prefSectionLeaves, isPrefLeaf, prefConditionPaths, prefLeafAt, setOwnPrefValue, prefConditionReadsItem, prefAliasTarget } from './chunk-DVHFV6JS.js';
|
|
2
|
+
export { PREF_ELSE, PREF_KINDS, PX_UNIT, VERSION_RECORD, filterPrefSubtree, flattenPrefValues, isBuiltinPref, isPrefCondition, isPrefLeaf, isPrefLinearUnit, isPrefScope, isPrefSection, mapPrefConditionPaths, nestPrefValues, prefAliasName, prefAliasTarget, prefAliasedLeaf, prefConditionHolds, prefConditionInGroup, prefConditionPaths, prefConditionReadsItem, prefDisplayBounds, prefHoldsValue, prefIsEnabled, prefIsShown, prefLeafAt, prefLeaves, prefOverrideOptions, prefOverridesOf, prefPairRows, prefSchemaHolding, prefScopeOptionValue, prefScopeValue, prefScopedDefault, prefScopesOf, prefSectionLeaves, prefStoredSelectors, prefUnit, prefUnitAccepts, prefValueAt, resolvePrefUnit, visiblePrefSubtree } from './chunk-DVHFV6JS.js';
|
|
3
3
|
import { endlessAllows } from '@weasel-js/quantity';
|
|
4
|
+
import { createPart, setOwn, getOwn, isPlainObject, codePointFloor } from '@weasel-js/registry';
|
|
4
5
|
import { isPaint, tryParseColor } from '@weasel-js/paint';
|
|
5
|
-
import { isPlainObject, codePointFloor } from '@weasel-js/registry';
|
|
6
6
|
|
|
7
|
-
function
|
|
7
|
+
function prefBoundedNumber(leaf2, read) {
|
|
8
8
|
const { minAt, maxAt, ...rest } = leaf2;
|
|
9
9
|
if (minAt === void 0 && maxAt === void 0) return leaf2;
|
|
10
10
|
const lo = minAt?.(read);
|
|
@@ -22,10 +22,58 @@ function prefClampNumber(leaf2, n) {
|
|
|
22
22
|
if (leaf2.max !== void 0 && v > leaf2.max) v = leaf2.max;
|
|
23
23
|
return v;
|
|
24
24
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
var
|
|
28
|
-
|
|
25
|
+
var CONDITIONS = ["showIf", "enableIf", "activeIf"];
|
|
26
|
+
var isNode = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
27
|
+
var isGroup = (node) => !("kind" in node) && isNode(node.children);
|
|
28
|
+
var under = (path, key) => path === "" ? key : `${path}.${key}`;
|
|
29
|
+
function mapNodes(held, each) {
|
|
30
|
+
let out;
|
|
31
|
+
for (const [key, child] of Object.entries(held)) {
|
|
32
|
+
if (!isNode(child)) continue;
|
|
33
|
+
const next = each(key, child);
|
|
34
|
+
if (next === child) continue;
|
|
35
|
+
out ??= { ...held };
|
|
36
|
+
setOwn(out, key, next);
|
|
37
|
+
}
|
|
38
|
+
return out ?? held;
|
|
39
|
+
}
|
|
40
|
+
function resolveNode(node, group, path) {
|
|
41
|
+
let out;
|
|
42
|
+
const set = (key, value) => {
|
|
43
|
+
out ??= { ...node };
|
|
44
|
+
setOwn(out, key, value);
|
|
45
|
+
};
|
|
46
|
+
for (const key of CONDITIONS) {
|
|
47
|
+
const condition = node[key];
|
|
48
|
+
if (!isPrefCondition(condition)) continue;
|
|
49
|
+
const next = prefConditionInGroup(condition, group);
|
|
50
|
+
if (next !== condition) set(key, next);
|
|
51
|
+
}
|
|
52
|
+
const inGroup = (_key, child) => resolveNode(child, group, path);
|
|
53
|
+
if (isNode(node.children)) {
|
|
54
|
+
const children = isGroup(node) ? mapNodes(node.children, (key, child) => resolveNode(child, path, under(path, key))) : mapNodes(node.children, inGroup);
|
|
55
|
+
if (children !== node.children) set("children", children);
|
|
56
|
+
}
|
|
57
|
+
if (isNode(node.members)) {
|
|
58
|
+
const members = mapNodes(node.members, inGroup);
|
|
59
|
+
if (members !== node.members) set("members", members);
|
|
60
|
+
}
|
|
61
|
+
if (isNode(node.item)) {
|
|
62
|
+
const item = resolveNode(node.item, group, path);
|
|
63
|
+
if (item !== node.item) set("item", item);
|
|
64
|
+
}
|
|
65
|
+
if (isNode(node.variants)) {
|
|
66
|
+
const variants = mapNodes(node.variants, inGroup);
|
|
67
|
+
if (variants !== node.variants) set("variants", variants);
|
|
68
|
+
}
|
|
69
|
+
return out ?? node;
|
|
70
|
+
}
|
|
71
|
+
var resolvedOf = createPart((schema) => resolveNode(schema, "", ""));
|
|
72
|
+
function resolvePrefGroupConditions(schema) {
|
|
73
|
+
return resolvedOf(schema);
|
|
74
|
+
}
|
|
75
|
+
var variantOf = (value, tag) => typeof value === "object" && value !== null ? getOwn(value, tag) : void 0;
|
|
76
|
+
function prefDecodedValue(leaf2, stored, siblings) {
|
|
29
77
|
if (leaf2.kind !== "boolean" && leaf2.kind !== "enum") return stored;
|
|
30
78
|
const { encoding } = leaf2;
|
|
31
79
|
return encoding ? encoding.read(stored, siblings) : stored;
|
|
@@ -38,7 +86,7 @@ function prefShownReader(schema, read, item, over) {
|
|
|
38
86
|
const held = found.find((each) => (each.variants ?? []).every((v) => variantOf(read(v.at, from), v.tag) === v.key));
|
|
39
87
|
if (held === void 0) return stored;
|
|
40
88
|
const object = held.within === void 0 ? void 0 : read(held.within, from);
|
|
41
|
-
return
|
|
89
|
+
return prefDecodedValue(held.leaf, stored, typeof object === "object" && object !== null ? object : void 0);
|
|
42
90
|
};
|
|
43
91
|
}
|
|
44
92
|
|
|
@@ -46,8 +94,8 @@ function prefShownReader(schema, read, item, over) {
|
|
|
46
94
|
var PREF_CONDITION_FIELDS = ["showIf", "enableIf", "activeIf"];
|
|
47
95
|
function entryValue({ item, value }, path) {
|
|
48
96
|
if (path === "") return value !== void 0 ? value : item.default;
|
|
49
|
-
const held =
|
|
50
|
-
return held !== void 0 ? held :
|
|
97
|
+
const held = prefValueAt(value, path);
|
|
98
|
+
return held !== void 0 ? held : prefValueAt(item.default, path);
|
|
51
99
|
}
|
|
52
100
|
function prefJudge(schema, read, entry, over) {
|
|
53
101
|
const stored = (path, from) => from === "item" ? entry && entryValue(entry, path) : read(path);
|
|
@@ -60,15 +108,15 @@ function deferEntryConditions(holds) {
|
|
|
60
108
|
function prefReader(schema, values, over) {
|
|
61
109
|
const beyond = over && prefReader(over, values);
|
|
62
110
|
return (path) => {
|
|
63
|
-
const held =
|
|
111
|
+
const held = prefValueAt(values, path);
|
|
64
112
|
if (held !== void 0) return held;
|
|
65
113
|
if (beyond && prefSchemaHolding(schema, path, over) === over) return beyond(path);
|
|
66
114
|
if (isPrefSection(schema)) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
return
|
|
115
|
+
const leaves = prefSectionLeaves(schema.members);
|
|
116
|
+
const exact = leaves.find(([key]) => key === path);
|
|
117
|
+
if (exact) return exact[1].default;
|
|
118
|
+
const outer = leaves.find(([key]) => path.startsWith(`${key}.`));
|
|
119
|
+
return outer && prefValueAt(outer[1].default, path.slice(outer[0].length + 1));
|
|
72
120
|
}
|
|
73
121
|
const steps = path.split(".");
|
|
74
122
|
let node = schema;
|
|
@@ -76,7 +124,7 @@ function prefReader(schema, values, over) {
|
|
|
76
124
|
if (!Object.hasOwn(node.children, steps[i])) return void 0;
|
|
77
125
|
const child = node.children[steps[i]];
|
|
78
126
|
if (!isPrefLeaf(child)) node = child;
|
|
79
|
-
else return i === steps.length - 1 ? child.default :
|
|
127
|
+
else return i === steps.length - 1 ? child.default : prefValueAt(child.default, steps.slice(i + 1).join("."));
|
|
80
128
|
}
|
|
81
129
|
return void 0;
|
|
82
130
|
};
|
|
@@ -85,7 +133,7 @@ function prefReader(schema, values, over) {
|
|
|
85
133
|
// src/statusAt.ts
|
|
86
134
|
var PREF_ENTRY = "*";
|
|
87
135
|
var prefSectionPath = (at, key) => at === "" ? `#${key}` : `${at}.#${key}`;
|
|
88
|
-
var
|
|
136
|
+
var ROOT_PREF_STATUS = Object.freeze({ shown: true, enabled: true });
|
|
89
137
|
function prefStatusUnder(above, node, holds) {
|
|
90
138
|
const shown = above.shown && (node.showIf === void 0 || holds(node.showIf, "showIf"));
|
|
91
139
|
const enabled = above.enabled && (node.enableIf === void 0 || holds(node.enableIf, "enableIf"));
|
|
@@ -98,16 +146,19 @@ function prefStatusIn(owner, path, holds) {
|
|
|
98
146
|
if (!reads) return status;
|
|
99
147
|
return prefStatusUnder(above, { showIf: node.showIf }, holds);
|
|
100
148
|
}
|
|
101
|
-
var
|
|
149
|
+
var under2 = (prefix, key) => prefix === "" ? key : `${prefix}.${key}`;
|
|
102
150
|
function statusAmong(held, prefix, rest, owner, holds) {
|
|
151
|
+
return statusMatching(held, prefix, rest, owner, holds, true) ?? statusMatching(held, prefix, rest, owner, holds, false);
|
|
152
|
+
}
|
|
153
|
+
function statusMatching(held, prefix, rest, owner, holds, exact) {
|
|
103
154
|
for (const [key, child] of Object.entries(held)) {
|
|
104
155
|
if (!isPrefLeaf(child)) {
|
|
105
|
-
const found =
|
|
156
|
+
const found = statusMatching(child.members, prefix, rest, { node: child, status: prefStatusUnder(owner.status, child, holds), above: owner.status }, holds, exact);
|
|
106
157
|
if (found) return found;
|
|
107
158
|
continue;
|
|
108
159
|
}
|
|
109
|
-
if (rest !== key
|
|
110
|
-
const path =
|
|
160
|
+
if (exact ? rest !== key : !rest.startsWith(`${key}.`)) continue;
|
|
161
|
+
const path = under2(prefix, key);
|
|
111
162
|
const sits = prefStatusIn(owner, path, holds);
|
|
112
163
|
const status = prefStatusUnder(sits, child, holds);
|
|
113
164
|
return rest === key ? status : statusInside(child, path, rest.slice(key.length + 1), { node: child, status, above: sits }, holds);
|
|
@@ -135,7 +186,7 @@ function statusInside(leaf2, path, rest, owner, holds) {
|
|
|
135
186
|
return status;
|
|
136
187
|
}
|
|
137
188
|
function statusAt(schema, path, holds) {
|
|
138
|
-
let owner = { node: schema, status: prefStatusUnder(
|
|
189
|
+
let owner = { node: schema, status: prefStatusUnder(ROOT_PREF_STATUS, schema, holds), above: ROOT_PREF_STATUS };
|
|
139
190
|
if (path === "") return owner.status;
|
|
140
191
|
if (isPrefSection(schema)) return statusAmong(schema.members, "", path, owner, holds) ?? owner.status;
|
|
141
192
|
let node = schema;
|
|
@@ -151,7 +202,8 @@ function statusAt(schema, path, holds) {
|
|
|
151
202
|
}
|
|
152
203
|
return owner.status;
|
|
153
204
|
}
|
|
154
|
-
function prefAliasStatus(own, alias,
|
|
205
|
+
function prefAliasStatus(own, alias, overGiven, holds) {
|
|
206
|
+
const over = resolvePrefGroupConditions(overGiven);
|
|
155
207
|
const target = prefAliasTarget(alias, (path) => prefLeafAt(over, path));
|
|
156
208
|
if (target === void 0) return own;
|
|
157
209
|
const theirs = statusAt(over, target.path, holds);
|
|
@@ -160,13 +212,14 @@ function prefAliasStatus(own, alias, over, holds) {
|
|
|
160
212
|
return shown === own.shown && enabled === own.enabled ? own : { shown, enabled };
|
|
161
213
|
}
|
|
162
214
|
function prefStatusAt(schema, path, holds, { aliasOver, aliasHolds } = {}) {
|
|
215
|
+
schema = resolvePrefGroupConditions(schema);
|
|
163
216
|
const own = statusAt(schema, path, holds);
|
|
164
217
|
const leaf2 = prefLeafAt(schema, path);
|
|
165
218
|
return leaf2?.kind === "alias" ? prefAliasStatus(own, leaf2, aliasOver ?? schema, aliasHolds ?? holds) : own;
|
|
166
219
|
}
|
|
167
220
|
|
|
168
221
|
// src/status.ts
|
|
169
|
-
var
|
|
222
|
+
var under3 = (prefix, key) => prefix === "" ? key : `${prefix}.${key}`;
|
|
170
223
|
function leafWalk({ keepEmpty, keepHidden, inItem, aliasOver, aliasHolds, answers }) {
|
|
171
224
|
const disabled = /* @__PURE__ */ new Set();
|
|
172
225
|
const hidden = /* @__PURE__ */ new Set();
|
|
@@ -189,7 +242,7 @@ function leafWalk({ keepEmpty, keepHidden, inItem, aliasOver, aliasHolds, answer
|
|
|
189
242
|
if (node.kind === "list" || node.kind === "map") {
|
|
190
243
|
const { item } = node;
|
|
191
244
|
if (item === void 0) return node;
|
|
192
|
-
const at =
|
|
245
|
+
const at = under3(path, PREF_ENTRY);
|
|
193
246
|
const entry2 = inside(item, at, prefStatusUnder(status, { enableIf: item.enableIf }, inItem), inItem, status, at);
|
|
194
247
|
return entry2 === item ? node : { ...node, item: entry2 };
|
|
195
248
|
}
|
|
@@ -208,7 +261,7 @@ function leafWalk({ keepEmpty, keepHidden, inItem, aliasOver, aliasHolds, answer
|
|
|
208
261
|
let changed = false;
|
|
209
262
|
const out = {};
|
|
210
263
|
for (const [key, child] of Object.entries(held)) {
|
|
211
|
-
const at =
|
|
264
|
+
const at = under3(prefix, key);
|
|
212
265
|
const kept = isPrefLeaf(child) ? leaf2(child, at, prefStatusIn(owner, at, holds), holds, owner.entry) : section(child, prefix, prefSectionPath(within, key), owner.status, holds, owner.entry);
|
|
213
266
|
changed ||= kept !== child;
|
|
214
267
|
if (kept !== null) setOwnPrefValue(out, key, kept);
|
|
@@ -226,7 +279,9 @@ function leafWalk({ keepEmpty, keepHidden, inItem, aliasOver, aliasHolds, answer
|
|
|
226
279
|
};
|
|
227
280
|
return { disabled, hidden, active, leaf: leaf2, inside, members };
|
|
228
281
|
}
|
|
229
|
-
function applyPrefConditions(schema, holds, { keepEmpty = false, keepHidden = false, aliasOver, aliasHolds } = {}) {
|
|
282
|
+
function applyPrefConditions(schema, holds, { keepEmpty = false, keepHidden = false, aliasOver: overGiven, aliasHolds } = {}) {
|
|
283
|
+
schema = resolvePrefGroupConditions(schema);
|
|
284
|
+
const aliasOver = overGiven && resolvePrefGroupConditions(overGiven);
|
|
230
285
|
const inItem = deferEntryConditions(holds);
|
|
231
286
|
const answers = (condition, by) => by !== inItem || !prefConditionReadsItem(condition);
|
|
232
287
|
const walk = leafWalk({ keepEmpty, keepHidden, inItem, aliasOver: aliasOver ?? schema, aliasHolds, answers });
|
|
@@ -239,7 +294,7 @@ function applyPrefConditions(schema, holds, { keepEmpty = false, keepHidden = fa
|
|
|
239
294
|
let changed = false;
|
|
240
295
|
const children = {};
|
|
241
296
|
for (const [key, child] of Object.entries(node.children)) {
|
|
242
|
-
const at =
|
|
297
|
+
const at = under3(path, key);
|
|
243
298
|
const kept2 = isPrefLeaf(child) ? walk.leaf(child, at, prefStatusIn({ node, status: status2, above }, at, holds), holds) : group(child, at, status2);
|
|
244
299
|
changed ||= kept2 !== child;
|
|
245
300
|
if (kept2 !== null) setOwnPrefValue(children, key, kept2);
|
|
@@ -247,10 +302,10 @@ function applyPrefConditions(schema, holds, { keepEmpty = false, keepHidden = fa
|
|
|
247
302
|
if (!changed) return node;
|
|
248
303
|
return Object.keys(children).length === 0 && !keepEmpty && path !== "" ? null : { ...node, children };
|
|
249
304
|
};
|
|
250
|
-
if (!isPrefSection(schema)) return { shown: group(schema, "",
|
|
251
|
-
const status = prefStatusUnder(
|
|
305
|
+
if (!isPrefSection(schema)) return { shown: group(schema, "", ROOT_PREF_STATUS), disabled, hidden, active };
|
|
306
|
+
const status = prefStatusUnder(ROOT_PREF_STATUS, schema, holds);
|
|
252
307
|
if (!status.shown && !keepHidden) return { shown: null, disabled, hidden, active };
|
|
253
|
-
const kept = walk.members(schema.members, "", { node: schema, status, above:
|
|
308
|
+
const kept = walk.members(schema.members, "", { node: schema, status, above: ROOT_PREF_STATUS }, holds);
|
|
254
309
|
return { shown: kept === schema.members ? schema : { ...schema, members: kept }, disabled, hidden, active };
|
|
255
310
|
}
|
|
256
311
|
var ALWAYS = () => true;
|
|
@@ -258,15 +313,15 @@ function applyPrefEntryConditions(item, path, holds, { keepEmpty = false, keepHi
|
|
|
258
313
|
const asked = (condition, field) => !prefConditionReadsItem(condition) || holds(condition, field);
|
|
259
314
|
const answers = (condition, by) => by === asked && prefConditionReadsItem(condition);
|
|
260
315
|
const walk = leafWalk({ keepEmpty, keepHidden, inItem: ALWAYS, answers });
|
|
261
|
-
const status = prefStatusUnder(
|
|
262
|
-
return { item: walk.inside(item, path, status, asked,
|
|
316
|
+
const status = prefStatusUnder(ROOT_PREF_STATUS, { enableIf: item.enableIf }, asked);
|
|
317
|
+
return { item: walk.inside(item, path, status, asked, ROOT_PREF_STATUS, path), disabled: walk.disabled, hidden: walk.hidden, active: walk.active };
|
|
263
318
|
}
|
|
264
319
|
|
|
265
320
|
// src/leafValue.ts
|
|
266
321
|
function prefValueAbsent(leaf2, held) {
|
|
267
322
|
return held === void 0 || held === null && leaf2.kind !== "paint";
|
|
268
323
|
}
|
|
269
|
-
function
|
|
324
|
+
function prefValueOrDefault(leaf2, held, { unset = false } = {}) {
|
|
270
325
|
if (!prefValueAbsent(leaf2, held)) return held;
|
|
271
326
|
if (unset || leaf2.clearable === true) return void 0;
|
|
272
327
|
return leaf2.default;
|
|
@@ -300,18 +355,17 @@ var pref = {
|
|
|
300
355
|
label: (name, rest) => leaf("label", name, void 0, rest),
|
|
301
356
|
separator: () => leaf("separator", "", void 0, void 0)
|
|
302
357
|
};
|
|
303
|
-
|
|
304
|
-
// src/object.ts
|
|
305
358
|
var isObject = (v) => typeof v === "object" && v !== null;
|
|
306
359
|
function prefObjectBase(pref2, held) {
|
|
307
360
|
if (isObject(held)) return held;
|
|
308
|
-
|
|
361
|
+
const lifted = held === void 0 ? void 0 : pref2.fromScalar?.(held);
|
|
362
|
+
return lifted ?? (isObject(pref2.default) ? pref2.default : {});
|
|
309
363
|
}
|
|
310
364
|
function prefObjectField(held, key) {
|
|
311
365
|
let cursor = held;
|
|
312
366
|
for (const step of key.split(".")) {
|
|
313
367
|
if (!isObject(cursor)) return void 0;
|
|
314
|
-
cursor = cursor
|
|
368
|
+
cursor = getOwn(cursor, step);
|
|
315
369
|
}
|
|
316
370
|
return cursor;
|
|
317
371
|
}
|
|
@@ -319,28 +373,27 @@ function prefObjectWithField(pref2, held, key, value) {
|
|
|
319
373
|
return withField(prefObjectBase(pref2, held), key.split("."), value);
|
|
320
374
|
}
|
|
321
375
|
function withField(base, [step, ...rest], value) {
|
|
322
|
-
const
|
|
376
|
+
const held = getOwn(base, step);
|
|
377
|
+
const next = rest.length === 0 ? value : withField(isObject(held) ? held : {}, rest, value);
|
|
323
378
|
const drops = next === void 0 || rest.length > 0 && Object.keys(next).length === 0;
|
|
324
379
|
if (!drops) return { ...base, [step]: next };
|
|
325
380
|
const { [step]: _dropped, ...kept } = base;
|
|
326
381
|
return kept;
|
|
327
382
|
}
|
|
328
|
-
|
|
329
|
-
// src/union.ts
|
|
330
383
|
function prefVariantOf(leaf2, value) {
|
|
331
384
|
if (value === null || typeof value !== "object" || Array.isArray(value)) return void 0;
|
|
332
|
-
const key = value
|
|
385
|
+
const key = getOwn(value, leaf2.tag);
|
|
333
386
|
if (typeof key !== "string" || !Object.hasOwn(leaf2.variants, key)) return void 0;
|
|
334
387
|
return [key, leaf2.variants[key]];
|
|
335
388
|
}
|
|
336
389
|
function prefVariantDefault(leaf2, key) {
|
|
337
|
-
const held = leaf2.variants
|
|
390
|
+
const held = getOwn(leaf2.variants, key)?.default;
|
|
338
391
|
const fields = held !== null && typeof held === "object" ? held : {};
|
|
339
392
|
return { ...fields, [leaf2.tag]: key };
|
|
340
393
|
}
|
|
341
394
|
|
|
342
395
|
// src/groups.ts
|
|
343
|
-
function
|
|
396
|
+
function prefDrawsAsBox(as) {
|
|
344
397
|
return as === "panel" || as === "menu";
|
|
345
398
|
}
|
|
346
399
|
function prefGroupIsPage(group) {
|
|
@@ -351,7 +404,7 @@ function repairPrefValue(leaf2, stored, validators) {
|
|
|
351
404
|
if (stored === "Infinity") stored = Infinity;
|
|
352
405
|
else if (stored === "-Infinity") stored = -Infinity;
|
|
353
406
|
}
|
|
354
|
-
const validate = validators
|
|
407
|
+
const validate = validators && getOwn(validators, leaf2.kind);
|
|
355
408
|
if (validate) {
|
|
356
409
|
try {
|
|
357
410
|
const out = validate(stored, leaf2);
|
|
@@ -397,13 +450,14 @@ function repairPrefValue(leaf2, stored, validators) {
|
|
|
397
450
|
}
|
|
398
451
|
}
|
|
399
452
|
function repairFields(leaf2, stored, validators) {
|
|
400
|
-
let out;
|
|
453
|
+
let out = stored;
|
|
401
454
|
for (const [key, field] of prefSectionLeaves(leaf2.children)) {
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
455
|
+
const held = prefObjectField(stored, key);
|
|
456
|
+
if (held === void 0) continue;
|
|
457
|
+
const read = repairPrefValue(field, held, validators);
|
|
458
|
+
if (read !== held) out = prefObjectWithField(leaf2, out, key, read);
|
|
405
459
|
}
|
|
406
|
-
return out
|
|
460
|
+
return out;
|
|
407
461
|
}
|
|
408
462
|
function repairMap(leaf2, stored, validators) {
|
|
409
463
|
if (!isPlainObject(stored)) return leaf2.default;
|
|
@@ -411,7 +465,7 @@ function repairMap(leaf2, stored, validators) {
|
|
|
411
465
|
let out;
|
|
412
466
|
for (const [key, value] of Object.entries(held)) {
|
|
413
467
|
const read = repairPrefValue(leaf2.item, value, validators);
|
|
414
|
-
if (read !== value) (out ??= { ...held }
|
|
468
|
+
if (read !== value) setOwn(out ??= { ...held }, key, read);
|
|
415
469
|
}
|
|
416
470
|
return out ?? stored;
|
|
417
471
|
}
|
|
@@ -429,6 +483,6 @@ function repairNumber(leaf2, stored) {
|
|
|
429
483
|
return Number.isFinite(v) ? v : leaf2.default;
|
|
430
484
|
}
|
|
431
485
|
|
|
432
|
-
export { PREF_CONDITION_FIELDS, PREF_ENTRY,
|
|
486
|
+
export { PREF_CONDITION_FIELDS, PREF_ENTRY, ROOT_PREF_STATUS, applyPrefConditions, applyPrefEntryConditions, pref, prefBoundedNumber, prefClampNumber, prefDecodedValue, prefDrawsAsBox, prefGroupIsPage, prefJudge, prefObjectBase, prefObjectField, prefObjectWithField, prefReader, prefSectionPath, prefShownReader, prefStatusAt, prefStatusIn, prefStatusUnder, prefValueAbsent, prefValueOrDefault, prefVariantDefault, prefVariantOf, repairPrefValue, resolvePrefGroupConditions };
|
|
433
487
|
//# sourceMappingURL=index.js.map
|
|
434
488
|
//# sourceMappingURL=index.js.map
|