@weasel-js/prefs 1.10.1 → 1.11.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/index.d.ts CHANGED
@@ -1,7 +1,11 @@
1
- import { P as PrefLeaf, a as PrefGroup, b as PrefSection, c as PrefNumber, d as PrefList, e as PrefMap, f as PrefCondition, g as PrefConditionReader, h as PrefBoolean, i as PrefString, j as PrefColor, k as PrefEnumBase, l as PrefSelection, m as PrefLocus, n as PrefAlias, o as PrefObject, p as PrefKind } from './open-C83pU7Va.js';
2
- export { B as BuiltinPref, q as PREF_BLENDS, r as PREF_KINDS, s as PrefAction, t as PrefActionContext, u as PrefActionControl, v as PrefAtPath, w as PrefBarOverflow, x as PrefBase, y as PrefBlend, z as PrefBooleanControl, A as PrefBooleanEncoding, C as PrefChange, D as PrefConditionValue, E as PrefCustom, F as PrefEnum, G as PrefEnumControl, H as PrefEnumEncoding, I as PrefField, J as PrefFunctionUnit, K as PrefGroupAs, L as PrefLabel, M as PrefLinearUnit, N as PrefNumberControl, O as PrefNumberUnit, Q as PrefPaint, R as PrefPair, S as PrefPath, T as PrefSectionAs, U as PrefSeparator, V as PrefStringControl, W as PrefTest, X as PrefUnion, Y as PrefValidator, Z as PrefValueAt, _ as PrefValueOf, $ as PrefWeighted, a0 as PrefWeights, a1 as PrefsMigration, a2 as PrefsOptions, a3 as PrefsStore, a4 as ResolvedPrefUnit, a5 as isBuiltinPref, a6 as isPrefCondition, a7 as isPrefLinearUnit, a8 as isPrefLocus, a9 as mapPrefConditionPaths, aa as openPrefs, ab as openPrefsSync, ac as pairRowsOf, ad as prefAliasName, ae as prefAliasTarget, af as prefAliasedLeaf, ag as prefConditionHolds, ah as prefConditionPaths, ai as prefConditionReadsItem, aj as prefGroupIsPage, ak as prefIsEnabled, al as prefIsShown, am as prefLocusMember, an as prefLocusSelectors, ao as prefUnit, ap as prefVariantDefault, aq as prefVariantOf, ar as repairPrefValue, as as resolvePrefUnit } from './open-C83pU7Va.js';
1
+ import { Endless } from '@weasel-js/quantity';
2
+ import { P as PrefLeaf, a as PrefGroup, b as PrefSection, c as PrefNumber, d as PrefList, e as PrefMap, f as PrefCondition, g as PrefConditionReader, h as PrefBoolean, i as PrefString, j as PrefColor, k as PrefEnumBase, l as PrefAction, m as PrefActions, n as PrefLabel, o as PrefSeparator, p as PrefAlias, q as PrefObject, r as PrefKind } from './groups-BDZC-ywb.js';
3
+ export { B as BuiltinPref, s as PREF_KINDS, t as PrefActionContext, u as PrefActionControl, v as PrefBarLead, w as PrefBarOverflow, x as PrefBase, y as PrefBooleanControl, z as PrefBooleanEncoding, A as PrefBoundAt, C as PrefBoundReader, D as PrefConditionValue, E as PrefCustom, F as PrefEnum, G as PrefEnumControl, H as PrefEnumEncoding, I as PrefField, J as PrefFunctionUnit, K as PrefGroupAs, L as PrefLinearUnit, M as PrefLocus, N as PrefNumberBase, O as PrefNumberControl, Q as PrefNumberUnit, R as PrefPaint, S as PrefPair, T as PrefSectionAs, U as PrefSelection, V as PrefStringControl, W as PrefTest, X as PrefUnion, Y as PrefValueBase, Z as PrefWeighted, _ as PrefWeights, $ as ResolvedPrefUnit, a0 as isBuiltinPref, a1 as isPrefCondition, a2 as isPrefLinearUnit, a3 as isPrefLocus, a4 as mapPrefConditionPaths, a5 as pairRowsOf, a6 as prefAliasName, a7 as prefAliasTarget, a8 as prefAliasedLeaf, a9 as prefAsBox, aa as prefClampNumber, ab as prefConditionHolds, ac as prefConditionPaths, ad as prefConditionReadsItem, ae as prefGroupIsPage, af as prefIsEnabled, ag as prefIsShown, ah as prefLocusMember, ai as prefLocusSelectors, aj as prefNumberAt, ak as prefUnit, al as prefUnitAccepts, am as prefVariantDefault, an as prefVariantOf, ao as resolvePrefUnit } from './groups-BDZC-ywb.js';
4
+ export { P as PREF_BLENDS, a as PrefAtPath, b as PrefBlend, c as PrefChange, d as PrefPath, e as PrefValidator, f as PrefValueAt, g as PrefValueOf, h as PrefsMigration, i as PrefsOptions, j as PrefsStore, o as openPrefs, k as openPrefsSync, r as repairPrefValue } from './open-VJ1zlFJz.js';
5
+ import { P as PrefsCssSource, a as PrefsCssOptions } from './css-v-LpmTll.js';
6
+ export { p as prefsCss, b as prefsCssAttributes } from './css-v-LpmTll.js';
7
+ import '@weasel-js/icons';
3
8
  import '@weasel-js/storage';
4
- import '@weasel-js/quantity';
5
9
 
6
10
  /**
7
11
  * A number leaf's bounds in the unit it is displayed in.
@@ -12,16 +16,17 @@ import '@weasel-js/quantity';
12
16
  * `max` are points, so they convert the way the value does; `step` is a
13
17
  * distance, and a unit with an offset maps zero somewhere else, so converting
14
18
  * it as a point would scale it wrong. A decreasing conversion swaps which end
15
- * is the lower one.
19
+ * is the lower one, and which end is `endless`.
16
20
  */
17
21
  declare function prefDisplayBounds(p: PrefNumber): {
18
22
  min?: number;
19
23
  max?: number;
20
24
  step: number;
25
+ endless?: Endless;
21
26
  };
22
27
  /** Distinguishes a leaf from a group or a section while walking a schema tree. */
23
28
  declare function isPrefLeaf(node: PrefLeaf | PrefGroup | PrefSection): node is PrefLeaf;
24
- /** Whether a leaf has a value to store: an `action` is a button and holds none, an `alias` shows another leaf's,
29
+ /** Whether a leaf has a value to store: an `action` is a button and holds none, nor does an `actions` run of them, an `alias` shows another leaf's,
25
30
  * and a `label` and a `separator` are text and a rule. */
26
31
  declare function prefHoldsValue(leaf: PrefLeaf): boolean;
27
32
  /** Distinguishes a section, whose key adds nothing to a path, from a group, whose key is a segment. */
@@ -59,7 +64,7 @@ declare function prefLeaves(schema: PrefGroup): Map<string, PrefLeaf>;
59
64
  declare function flattenPrefValues(schema: PrefGroup, tree: unknown): [string, unknown][];
60
65
  /**
61
66
  * Drop every leaf that does not answer to `query`, pruning groups left empty.
62
- * A group whose own name matches keeps all of its leaves. An empty or
67
+ * A group whose own name or tag matches keeps all of its leaves. An empty or
63
68
  * whitespace query matches everything.
64
69
  *
65
70
  * An alias answers as the row it draws: its target's name and description
@@ -82,13 +87,22 @@ type PrefTabRun<T> = {
82
87
  */
83
88
  declare function prefTabRuns<T>(items: readonly T[], isTab: (item: T) => boolean): PrefTabRun<T>[];
84
89
 
90
+ /** The leaves carrying `tag`, themselves or through a group above them, by
91
+ * path, in schema order. */
92
+ declare function prefLeavesTagged(schema: PrefGroup | PrefSection, tag: string): Map<string, PrefLeaf>;
93
+ /** The tags the leaf at `path` carries: each group's above it, outermost
94
+ * first, then its own. Empty for a path that names no leaf. */
95
+ declare function prefLeafTags(schema: PrefGroup | PrefSection, path: string): readonly string[];
96
+
85
97
  /** One thing wrong with a condition: it is not one, it reads a path no leaf
86
- * holds a value at, it compares a leaf against a value it never holds, it
98
+ * holds a value at, it compares a leaf against a value it never holds — an
99
+ * enum against a string none of its options is being `option`, which a
100
+ * surface may take as a test that never matches — it
87
101
  * never holds whatever the leaf does, as an `in` of no values, it is the
88
102
  * `showIf` of a list's or a map's item, which is drawn with each entry, or
89
103
  * it reads from the entry on a node that no list or map draws. */
90
104
  interface PrefConditionProblem {
91
- code: 'malformed' | 'no-leaf' | 'no-value' | 'value' | 'never' | 'item-show' | 'no-item';
105
+ code: 'malformed' | 'no-leaf' | 'no-value' | 'value' | 'option' | 'never' | 'item-show' | 'no-item';
92
106
  /** The path read, where the problem is with one. */
93
107
  path?: string;
94
108
  problem: string;
@@ -292,8 +306,6 @@ declare function checkPrefSplits(schema: PrefGroup): PrefSplitProblem[];
292
306
 
293
307
  /** What a builder takes after the leaf's name and default: any of the leaf's other fields. */
294
308
  type Rest<L> = Partial<Omit<L, 'kind' | 'name' | 'default'>>;
295
- /** One option of an enum, or its value alone, which is labeled with the value's first letter raised. */
296
- type OptionOf<T extends string> = T | PrefEnumBase<T>['options'][number];
297
309
  /**
298
310
  * Builders for a preferences schema, each returning what the literal would
299
311
  * hold. `pref.group('View', { grid: pref.boolean('Grid', true) })` is
@@ -309,61 +321,39 @@ declare const pref: {
309
321
  section<const M extends Record<string, PrefLeaf | PrefSection>>(name: string, members: M, options?: Omit<PrefSection, "name" | "members">): Omit<PrefSection, "members"> & {
310
322
  members: M;
311
323
  };
312
- number: (name: string, def: number, rest?: Rest<PrefNumber>) => PrefNumber;
324
+ number: (name: string, def: number, rest?: Rest<PrefNumber>) => PrefNumber & {
325
+ default: number;
326
+ };
313
327
  boolean: (name: string, def: boolean, rest?: Rest<PrefBoolean>) => PrefBoolean;
314
328
  string: (name: string, def: string, rest?: Rest<PrefString>) => PrefString;
315
329
  color: (name: string, def: string, rest?: Rest<PrefColor>) => PrefColor;
316
330
  /** A fixed set of choices. An option given as its value alone is labeled with that value, its first letter raised. */
317
- enum<const T extends string>(name: string, def: NoInfer<T>, options: readonly OptionOf<T>[], rest?: Omit<Rest<PrefEnumBase<T>>, "options">): PrefEnumBase<T> & {
331
+ enum<const T extends string>(name: string, def: NoInfer<T>, options: readonly (T | PrefEnumBase<T>["options"][number])[], rest?: Omit<Rest<PrefEnumBase<T>>, "options">): PrefEnumBase<T> & {
318
332
  default: T;
319
333
  clearable?: false;
320
334
  };
335
+ /** A button firing the registered action `action` (`id` or `id:variant`). Its name defaults to empty, which shows the action's own label. */
336
+ action: (action: string, rest?: Partial<Omit<PrefAction, "kind" | "default" | "action">>) => PrefAction;
337
+ /** Every action registered in the action group `group`. */
338
+ actions: (group: string, rest?: Partial<Omit<PrefActions, "kind" | "default" | "group">>) => PrefActions;
339
+ label: (name: string, rest?: Rest<PrefLabel>) => PrefLabel;
340
+ separator: () => PrefSeparator;
321
341
  };
322
342
 
323
- /** How {@link prefsCss} names and writes things. */
324
- interface PrefsCssOptions {
325
- /** The selector of the element the properties are set on, and the selectors' attributes read from. Default `:root`. */
326
- root?: string;
327
- /** The custom property a leaf is written as, or `null` to leave the leaf out. Default: `--`, then the path with
328
- * each `.` and each capital turned into a `-` (`look.gridGap` is `--look-grid-gap`). */
329
- property?: (path: string, leaf: PrefLeaf) => string | null;
330
- /** The attribute a selector's option is read from. Default: `data-`, then the path as a property spells it. */
331
- attribute?: (selector: string) => string;
332
- /** The CSS text of a value, `null` to leave it out, or `undefined` for what its kind writes by itself. */
333
- value?: (value: unknown, leaf: PrefLeaf, path: string) => string | null | undefined;
334
- }
335
- /** What {@link prefsCss} reads of a store: any `PrefsStore` is one. */
336
- interface PrefsCssSource {
337
- schema: PrefGroup;
338
- values(read?: {
339
- at?: PrefSelection;
340
- }): Record<string, unknown>;
341
- locus(path: string): PrefLocus | undefined;
342
- get(path: string): unknown;
343
- }
344
343
  /**
345
- * The store's values as CSS custom properties.
346
- *
347
- * The first block sets every leaf on `root`, a split one at the member the
348
- * selectors' defaults name, so a page that sets no attribute still has a
349
- * value for each. A block follows for each choice of options some value tells
350
- * apart, matched by an attribute per selector on that same element; a selector
351
- * is written under each of its own options too. Every block is inside
352
- * `:where()`, so none outranks another by how many attributes it names, and a
353
- * rule of the page's own wins. Blocks naming more selectors come later.
354
- *
355
- * A number is written in its display unit where the unit's suffix is a CSS
356
- * unit, and bare otherwise; a boolean as `1` or `0`; a color as it is held; an
357
- * enum's option as an identifier; a string quoted. A leaf of any other kind is
358
- * left out unless `value` writes it.
344
+ * A schema's defaults read the way a store at defaults reads them, a split
345
+ * default by its `defaultLocus` — what `prefsCss` needs to write a schema's
346
+ * stylesheet with no store and no storage, at build time say.
359
347
  */
360
- declare function prefsCss(store: PrefsCssSource, options?: PrefsCssOptions): string;
348
+ declare function prefsDefaultsSource(schema: PrefGroup): PrefsCssSource;
349
+
361
350
  /**
362
- * The attribute for each selector and the option it is set to: what to set
363
- * on the `root` element for the blocks of {@link prefsCss} to match the
364
- * store's own choice.
351
+ * `prefsCss` names for the kit's own settings: `tree.typeaheadMs` writes as
352
+ * `--wzl-kit-tree-typeahead-ms`, clear of theme tokens. With `at`, only the
353
+ * leaves under it are written, each named from below it; a selector outside
354
+ * `at` keeps its whole path in its attribute name.
365
355
  */
366
- declare function prefsCssAttributes(store: Pick<PrefsCssSource, 'schema' | 'get'>, options?: Pick<PrefsCssOptions, 'attribute'>): Record<string, string>;
356
+ declare function kitSettingsCssOptions(at?: string): PrefsCssOptions;
367
357
 
368
358
  /**
369
359
  * The schema that answers for the value at `path`: `schema` where a leaf of
@@ -483,4 +473,12 @@ declare function prefDrawsSeveral(leaf: {
483
473
  kind: string;
484
474
  }): boolean;
485
475
 
486
- export { PREF_ENTRY, PREF_KIND_TRAITS, PREF_SCOPE, type PairRun, PrefAlias, type PrefAliasTargets, type PrefAliasTargetsOptions, PrefBoolean, PrefColor, PrefCondition, type PrefConditionField, type PrefConditionJudge, type PrefConditionProblem, PrefConditionReader, type PrefConditionSite, type PrefConditionsApplied, type PrefConditionsOptions, type PrefEntry, type PrefEntryApplied, PrefEnumBase, PrefGroup, PrefKind, type PrefKindTraits, PrefLeaf, PrefList, PrefLocus, PrefMap, PrefNumber, PrefObject, type PrefSchemaConditionProblem, type PrefScope, type PrefScopeAtOptions, PrefSection, PrefSelection, type PrefSplitProblem, PrefString, type PrefTabRun, type PrefsCssOptions, type PrefsCssSource, VERSION_RECORD, applyPrefConditions, applyPrefEntryConditions, checkPrefCondition, checkPrefConditions, checkPrefSplits, filterPrefSubtree, flattenPrefValues, isPrefLeaf, isPrefSection, pairRuns, pref, prefAliasTargets, prefDisplayBounds, prefDrawsSeveral, prefFitsHeading, prefHeadingKey, prefHoldsValue, prefIsCompound, prefJudge, prefLeafAt, prefLeaves, prefObjectBase, prefObjectWithField, prefReader, prefSchemaHolding, prefScopeAt, prefScopeUnder, prefSectionLeaves, prefShownReader, prefShownValue, prefTabRuns, prefType, prefValueAtPath, prefsCss, prefsCssAttributes, visiblePrefSubtree };
476
+ /**
477
+ * One group named `name` holding every child of `groups`. Groups at the same
478
+ * key merge, the first one's own fields kept; a leaf meeting anything at the
479
+ * same key throws. Composes schemas that each add to the same areas, such as
480
+ * the kit settings groups that `ui` and `core` both give a `targets` group.
481
+ */
482
+ declare function mergePrefGroups(name: string, ...groups: readonly PrefGroup[]): PrefGroup;
483
+
484
+ export { PREF_ENTRY, PREF_KIND_TRAITS, PREF_SCOPE, type PairRun, PrefAction, PrefActions, PrefAlias, type PrefAliasTargets, type PrefAliasTargetsOptions, PrefBoolean, PrefColor, PrefCondition, type PrefConditionField, type PrefConditionJudge, type PrefConditionProblem, PrefConditionReader, type PrefConditionSite, type PrefConditionsApplied, type PrefConditionsOptions, type PrefEntry, type PrefEntryApplied, PrefEnumBase, PrefGroup, PrefKind, type PrefKindTraits, PrefLabel, PrefLeaf, PrefList, PrefMap, PrefNumber, PrefObject, type PrefSchemaConditionProblem, type PrefScope, type PrefScopeAtOptions, PrefSection, PrefSeparator, type PrefSplitProblem, PrefString, type PrefTabRun, PrefsCssOptions, PrefsCssSource, VERSION_RECORD, applyPrefConditions, applyPrefEntryConditions, checkPrefCondition, checkPrefConditions, checkPrefSplits, filterPrefSubtree, flattenPrefValues, isPrefLeaf, isPrefSection, kitSettingsCssOptions, mergePrefGroups, pairRuns, pref, prefAliasTargets, prefDisplayBounds, prefDrawsSeveral, prefFitsHeading, prefHeadingKey, prefHoldsValue, prefIsCompound, prefJudge, prefLeafAt, prefLeafTags, prefLeaves, prefLeavesTagged, prefObjectBase, prefObjectWithField, prefReader, prefSchemaHolding, prefScopeAt, prefScopeUnder, prefSectionLeaves, prefShownReader, prefShownValue, prefTabRuns, prefType, prefValueAtPath, prefsDefaultsSource, visiblePrefSubtree };
package/dist/index.js CHANGED
@@ -1,5 +1,9 @@
1
- import { prefLeafHoldingIn, prefLeafHolding, prefSchemaHolding, UNSEEN, prefConditionHolds, prefValueAtPath, isPrefSection, prefSectionLeaves, isPrefLeaf, prefLeafAt, prefLeaves, prefHoldsValue, prefSelectors, prefAliasTarget, prefAliasedLeaf, isBuiltinPref, pairRowsOf, prefConditionReadsItem, visiblePrefSubtree, resolvePrefUnit, isPrefLocus } from './chunk-ASSX3JHY.js';
2
- export { PREF_BLENDS, PREF_KINDS, VERSION_RECORD, checkPrefCondition, checkPrefConditions, checkPrefSplits, filterPrefSubtree, flattenPrefValues, isBuiltinPref, isPrefCondition, isPrefLeaf, isPrefLinearUnit, isPrefLocus, isPrefSection, mapPrefConditionPaths, openPrefs, openPrefsSync, pairRowsOf, prefAliasName, prefAliasTarget, prefAliasedLeaf, prefConditionHolds, prefConditionPaths, prefConditionReadsItem, prefDisplayBounds, prefHoldsValue, prefIsEnabled, prefIsShown, prefLeafAt, prefLeaves, memberAt as prefLocusMember, locusSelectors as prefLocusSelectors, prefSchemaHolding, prefSectionLeaves, prefUnit, prefValueAtPath, prefVariantDefault, prefVariantOf, repairPrefValue, resolvePrefUnit, visiblePrefSubtree } from './chunk-ASSX3JHY.js';
1
+ import { prefLeafHoldingIn, prefLeafHolding, prefSchemaHolding, UNSEEN, prefConditionHolds, isBuiltinPref, pairRowsOf, prefConditionReadsItem } from './chunk-WN6QQICK.js';
2
+ export { PREF_KINDS, checkPrefCondition, checkPrefConditions, isBuiltinPref, isPrefCondition, kitSettingsCssOptions, mapPrefConditionPaths, openPrefs, openPrefsSync, pairRowsOf, prefConditionHolds, prefConditionPaths, prefConditionReadsItem, prefIsEnabled, prefIsShown, prefSchemaHolding } from './chunk-WN6QQICK.js';
3
+ export { prefsDefaultsSource } from './chunk-ZLXZRX73.js';
4
+ import { prefValueAtPath, isPrefSection, prefSectionLeaves, isPrefLeaf, prefLeafAt, prefAliasTarget, prefAliasedLeaf, visiblePrefSubtree } from './chunk-OZFER7VN.js';
5
+ export { PREF_BLENDS, VERSION_RECORD, checkPrefSplits, filterPrefSubtree, flattenPrefValues, isPrefLeaf, isPrefLinearUnit, isPrefLocus, isPrefSection, prefAliasName, prefAliasTarget, prefAliasedLeaf, prefClampNumber, prefDisplayBounds, prefHoldsValue, prefLeafAt, prefLeaves, memberAt as prefLocusMember, locusSelectors as prefLocusSelectors, prefNumberAt, prefSectionLeaves, prefUnit, prefUnitAccepts, prefValueAtPath, prefVariantDefault, prefVariantOf, prefsCss, prefsCssAttributes, repairPrefValue, resolvePrefUnit, visiblePrefSubtree } from './chunk-OZFER7VN.js';
6
+ import { hasTag } from '@weasel-js/registry';
3
7
 
4
8
  // src/tabRuns.ts
5
9
  function prefTabRuns(items, isTab) {
@@ -17,6 +21,26 @@ function prefTabRuns(items, isTab) {
17
21
  }
18
22
  return out;
19
23
  }
24
+ function taggedLeaves(schema) {
25
+ const out = [];
26
+ const walk = (node, prefix, above) => {
27
+ const section = isPrefSection(node);
28
+ for (const [key, child] of Object.entries(section ? node.members : node.children)) {
29
+ const path = section || prefix === "" ? key : `${prefix}.${key}`;
30
+ const tags = child.tags ? [...above, ...child.tags] : above;
31
+ if (isPrefLeaf(child)) out.push([path, child, tags]);
32
+ else walk(child, section ? prefix : path, tags);
33
+ }
34
+ };
35
+ walk(schema, "", schema.tags ?? []);
36
+ return out;
37
+ }
38
+ function prefLeavesTagged(schema, tag) {
39
+ return new Map(taggedLeaves(schema).filter(([, , tags]) => hasTag(tags, tag)).map(([path, leaf2]) => [path, leaf2]));
40
+ }
41
+ function prefLeafTags(schema, path) {
42
+ return taggedLeaves(schema).find(([p]) => p === path)?.[2] ?? [];
43
+ }
20
44
 
21
45
  // src/shown.ts
22
46
  function prefShownValue(leaf2, stored, siblings) {
@@ -243,108 +267,15 @@ var pref = {
243
267
  enum(name, def, options, rest) {
244
268
  const full = options.map((option) => typeof option === "string" ? { value: option, label: labeled(option) } : option);
245
269
  return { kind: "enum", name, description: "", default: def, ...rest, options: full };
246
- }
270
+ },
271
+ /** A button firing the registered action `action` (`id` or `id:variant`). Its name defaults to empty, which shows the action's own label. */
272
+ action: (action, rest) => leaf("action", "", void 0, { action, ...rest }),
273
+ /** Every action registered in the action group `group`. */
274
+ actions: (group, rest) => leaf("actions", "", void 0, { group, ...rest }),
275
+ label: (name, rest) => leaf("label", name, void 0, rest),
276
+ separator: () => leaf("separator", "", void 0, void 0)
247
277
  };
248
278
 
249
- // src/css.ts
250
- var kebab = (path) => path.replace(/\./g, "-").replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);
251
- var CSS_UNITS = {
252
- px: "px",
253
- "%": "%",
254
- em: "em",
255
- rem: "rem",
256
- ch: "ch",
257
- pt: "pt",
258
- vw: "vw",
259
- vh: "vh",
260
- ms: "ms",
261
- s: "s",
262
- "\xB0": "deg",
263
- deg: "deg",
264
- rad: "rad",
265
- turn: "turn"
266
- };
267
- var IDENT = /^-?[A-Za-z_][\w-]*$/;
268
- var quoted = (text) => `'${text.replace(/[\\']/g, "\\$&")}'`;
269
- function cssValue(leaf2, value) {
270
- switch (leaf2.kind) {
271
- case "number": {
272
- if (typeof value !== "number" || !Number.isFinite(value)) return null;
273
- const { unit } = leaf2;
274
- const resolved = unit ? resolvePrefUnit(unit) : void 0;
275
- const shown = resolved ? resolved.toDisplay(value) : value;
276
- const suffix = resolved?.suffix !== void 0 && Object.hasOwn(CSS_UNITS, resolved.suffix) ? CSS_UNITS[resolved.suffix] : "";
277
- return `${Number(shown.toFixed(6))}${suffix}`;
278
- }
279
- case "boolean":
280
- return typeof value === "boolean" ? value ? "1" : "0" : null;
281
- case "color":
282
- return typeof value === "string" && value !== "" ? value : null;
283
- case "enum":
284
- if (typeof value !== "string" || leaf2.encoding) return null;
285
- return IDENT.test(value) ? value : quoted(value);
286
- case "string":
287
- return typeof value === "string" ? quoted(value) : null;
288
- default:
289
- return null;
290
- }
291
- }
292
- function toldApart(held, optionsOf, absent) {
293
- const out = [];
294
- const walk = (value, under2) => {
295
- if (!isPrefLocus(value)) {
296
- out.push({ under: under2, value });
297
- return;
298
- }
299
- for (const option of optionsOf(value.$by)) {
300
- walk(Object.hasOwn(value.$of, option) ? value.$of[option] : absent, [...under2, [value.$by, option]]);
301
- }
302
- };
303
- walk(held, []);
304
- return out;
305
- }
306
- function prefsCss(store, options = {}) {
307
- const root = options.root ?? ":root";
308
- const property = options.property ?? ((path) => `--${kebab(path)}`);
309
- const attribute = options.attribute ?? ((selector) => `data-${kebab(selector)}`);
310
- const leaves = new Map([...prefLeaves(store.schema)].filter(([, leaf2]) => prefHoldsValue(leaf2)));
311
- const selectors = prefSelectors(leaves);
312
- const defaults = Object.fromEntries([...selectors.keys()].map((path) => [path, leaves.get(path).default]));
313
- const base = store.values({ at: defaults });
314
- const blocks = /* @__PURE__ */ new Map();
315
- const declare = (under2, path, leaf2, value) => {
316
- const name = property(path, leaf2);
317
- if (name === null) return;
318
- const given = options.value?.(value, leaf2, path);
319
- const text = given === void 0 ? cssValue(leaf2, value) : given;
320
- if (text === null) return;
321
- const key = under2.map(([selector, option]) => `${selector}=${option}`).join("&");
322
- if (!blocks.has(key)) blocks.set(key, { under: under2, lines: [] });
323
- blocks.get(key).lines.push(` ${name}: ${text};`);
324
- };
325
- for (const [path, leaf2] of leaves) {
326
- declare([], path, leaf2, prefValueAtPath(base, path));
327
- const own = selectors.get(path);
328
- if (own) for (const option of own) declare([[path, option]], path, leaf2, option);
329
- const held = store.locus(path);
330
- if (!held) continue;
331
- for (const { under: under2, value } of toldApart(held, (selector) => selectors.get(selector) ?? [], leaf2.default)) {
332
- declare(under2, path, leaf2, value);
333
- }
334
- }
335
- return [...blocks.values()].map((block, i) => ({ ...block, i })).sort((a, b) => a.under.length - b.under.length || a.i - b.i).map(({ under: under2, lines }) => {
336
- const matched = under2.map(([selector, option]) => `[${attribute(selector)}=${quoted(option)}]`).join("");
337
- return `:where(${root}${matched}) {
338
- ${lines.join("\n")}
339
- }`;
340
- }).join("\n\n");
341
- }
342
- function prefsCssAttributes(store, options = {}) {
343
- const attribute = options.attribute ?? ((selector) => `data-${kebab(selector)}`);
344
- const leaves = prefLeaves(store.schema);
345
- return Object.fromEntries([...prefSelectors(leaves).keys()].map((path) => [attribute(path), store.get(path)]));
346
- }
347
-
348
279
  // src/aliasTargets.ts
349
280
  function visibleFieldsOf(leaf2) {
350
281
  if (leaf2.kind !== "object") return leaf2;
@@ -392,6 +323,9 @@ function prefType(name, leaf2) {
392
323
  }
393
324
 
394
325
  // src/groups.ts
326
+ function prefAsBox(as) {
327
+ return as === "panel" || as === "menu";
328
+ }
395
329
  function prefGroupIsPage(group) {
396
330
  return group.as === void 0 || group.as === "page";
397
331
  }
@@ -441,6 +375,7 @@ var PREF_KIND_TRAITS = {
441
375
  union: MANY,
442
376
  field: ONE,
443
377
  action: { compound: false, several: true },
378
+ actions: { compound: false, several: true },
444
379
  alias: ONE,
445
380
  label: ONE,
446
381
  separator: ONE
@@ -453,6 +388,28 @@ function prefDrawsSeveral(leaf2) {
453
388
  return traitsOf(leaf2).several;
454
389
  }
455
390
 
456
- export { PREF_ENTRY, PREF_KIND_TRAITS, PREF_SCOPE, applyPrefConditions, applyPrefEntryConditions, pairRuns, pref, prefAliasTargets, prefDrawsSeveral, prefFitsHeading, prefGroupIsPage, prefHeadingKey, prefIsCompound, prefJudge, prefObjectBase, prefObjectWithField, prefReader, prefScopeAt, prefScopeUnder, prefShownReader, prefShownValue, prefTabRuns, prefType, prefsCss, prefsCssAttributes };
391
+ // src/merge.ts
392
+ function mergeChildren(into, from, at) {
393
+ for (const [key, child] of Object.entries(from)) {
394
+ const path = at === "" ? key : `${at}.${key}`;
395
+ const held = into[key];
396
+ if (held === void 0) {
397
+ into[key] = child;
398
+ } else if (!isPrefLeaf(held) && !isPrefLeaf(child)) {
399
+ const children = { ...held.children };
400
+ mergeChildren(children, child.children, path);
401
+ into[key] = { ...held, children };
402
+ } else {
403
+ throw new Error(`mergePrefGroups: two groups give "${path}", and one of them is a leaf`);
404
+ }
405
+ }
406
+ }
407
+ function mergePrefGroups(name, ...groups) {
408
+ const children = {};
409
+ for (const group of groups) mergeChildren(children, group.children, "");
410
+ return { name, children };
411
+ }
412
+
413
+ export { PREF_ENTRY, PREF_KIND_TRAITS, PREF_SCOPE, applyPrefConditions, applyPrefEntryConditions, mergePrefGroups, pairRuns, pref, prefAliasTargets, prefAsBox, prefDrawsSeveral, prefFitsHeading, prefGroupIsPage, prefHeadingKey, prefIsCompound, prefJudge, prefLeafTags, prefLeavesTagged, prefObjectBase, prefObjectWithField, prefReader, prefScopeAt, prefScopeUnder, prefShownReader, prefShownValue, prefTabRuns, prefType };
457
414
  //# sourceMappingURL=index.js.map
458
415
  //# sourceMappingURL=index.js.map