@weasel-js/prefs 1.9.4 → 1.10.1

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.
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/alias.ts","../src/unit.ts","../src/helpers.ts","../src/condition.ts","../src/schema.ts","../src/holding.ts","../src/conditionCheck.ts","../src/locus.ts","../src/blend.ts","../src/splitCheck.ts","../src/union.ts","../src/repair.ts","../src/stamp.ts","../src/migrate.ts","../src/snapshot.ts","../src/storeWrites.ts","../src/store.ts","../src/open.ts"],"names":["under","isPlainObject","read","isVersion","same","member"],"mappings":";;;;;;AAoBO,SAAS,eAAA,CACd,OACA,MAAA,EAC8C;AAC9C,EAAA,MAAM,MAAA,uBAAa,GAAA,EAAY;AAC/B,EAAA,IAAI,OAAO,KAAA,CAAM,EAAA;AACjB,EAAA,WAAS;AACP,IAAA,IAAI,MAAA,CAAO,GAAA,CAAI,IAAI,CAAA,EAAG,OAAO,MAAA;AAC7B,IAAA,MAAA,CAAO,IAAI,IAAI,CAAA;AACf,IAAA,MAAM,IAAA,GAAO,OAAO,IAAI,CAAA;AACxB,IAAA,IAAI,IAAA,KAAS,QAAW,OAAO,MAAA;AAC/B,IAAA,IAAI,KAAK,IAAA,KAAS,OAAA,EAAS,OAAO,EAAE,MAAM,IAAA,EAAK;AAC/C,IAAA,IAAA,GAAQ,IAAA,CAAmB,EAAA;AAAA,EAC7B;AACF;AAOO,SAAS,aAAA,CAAc,OAAkB,MAAA,EAA2B;AACzE,EAAA,IAAI,KAAA,CAAM,IAAA,KAAS,EAAA,EAAI,OAAO,KAAA,CAAM,IAAA;AACpC,EAAA,OAAO,MAAA,KAAW,MAAA,GAAY,OAAA,GAAU,MAAA,CAAO,IAAA;AACjD;AAGO,SAAS,eAAA,CAAgB,OAAkB,MAAA,EAA4B;AAC5E,EAAA,OAAO;AAAA,IACL,GAAG,MAAA;AAAA,IACH,IAAA,EAAM,aAAA,CAAc,KAAA,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ClD,EAAA,OAAO,gBAAA,CAAiB,MAAA,EAAQ,KAAA,EAAO,OAAA,CAAQ,UAAA,EAAY,IAAA,EAAM,OAAA,CAAQ,UAAA,EAAY,MAAA,IAAU,CAAA,EAAG,OAAA,CAAQ,MAAM,CAAA;AAClH;AAIO,SAAS,mBACd,OAAA,EAC+C;AAC/C,EAAA,MAAM,KAAA,GAAQ,gBAAgB,EAAE,OAAA,EAAS,QAAQ,OAAA,EAAS,MAAA,EAAQ,OAAA,CAAQ,MAAA,EAAQ,CAAA;AAClF,EAAA,MAAM,IAAA,GAAO,KAAA,CAAM,KAAA,EAAO,OAAO,CAAA;AACjC,EAAA,IAAI,kBAAA,CAAmB,OAAO,OAAA,CAAQ,UAAA,IAAc,EAAE,CAAA,EAAG,KAAK,KAAA,CAAM,KAAA,EAAM;AAC1E,EAAA,OAAO,EAAE,OAAO,IAAA,EAAK;AACvB;AAKA,IAAM,KAAA,GAAQ,CAAC,KAAA,EAAyB,OAAA,KACtC,kBAAkB,KAAA,EAAO,OAAA,CAAQ,UAAA,IAAc,EAAE,CAAA","file":"chunk-ASSX3JHY.js","sourcesContent":["import type { PrefBase, PrefLeaf } from './schema';\n\n/**\n * A second place for another leaf: its row draws that leaf's control and\n * reads and writes that leaf's value, so one setting can sit on two pages.\n * It holds no value of its own. A store neither reads nor writes one, and\n * its path is not a {@link PrefPath}.\n *\n * `name` and `description` left empty are the target's.\n */\nexport interface PrefAlias extends PrefBase<'alias', undefined> {\n /** The leaf shown here, by the full path its value is read and written at (`'view.grid'`). */\n of: string;\n}\n\n/**\n * The leaf an alias stands for and the path its value lives at, following an\n * alias of an alias to its end. `undefined` when a path along the way names\n * no leaf, or the aliases lead back to one already passed.\n */\nexport function prefAliasTarget(\n alias: PrefAlias,\n leafAt: (path: string) => PrefLeaf | undefined,\n): { path: string; leaf: PrefLeaf } | undefined {\n const passed = new Set<string>();\n let path = alias.of;\n for (;;) {\n if (passed.has(path)) return undefined;\n passed.add(path);\n const leaf = leafAt(path);\n if (leaf === undefined) return undefined;\n if (leaf.kind !== 'alias') return { path, leaf };\n path = (leaf as PrefAlias).of;\n }\n}\n\n/**\n * What an alias is called wherever one is drawn or named: its own name, else\n * that of `target`, the leaf it shows, else `Alias` for one that shows\n * nothing.\n */\nexport function prefAliasName(alias: PrefAlias, target?: PrefLeaf): string {\n if (alias.name !== '') return alias.name;\n return target === undefined ? 'Alias' : target.name;\n}\n\n/** A leaf drawn through an alias: the target, under the alias's own name and description where it gives them. */\nexport function prefAliasedLeaf(alias: PrefAlias, target: PrefLeaf): PrefLeaf {\n return {\n ...target,\n name: prefAliasName(alias, target),\n description: alias.description === '' ? target.description : alias.description,\n };\n}\n","// A number leaf's display unit: the stored value stays canonical (radians, millimeters), and a UI converts\n// at its edge. A unit is data where the conversion is linear, and a pair of functions where it is not.\n\nimport { formatUnit, unitScale, type Unit, type UnitEntry, type UnitScale, type UnitSystem } from '@weasel-js/quantity';\n\n/** What both forms of a unit say about the text around the number. */\ninterface PrefUnitText {\n /** Shown after the input, e.g. `'°'`. */\n suffix?: string;\n /** Suffixes a person may type, each mapped to the scale that turns a\n * number in that unit into a display number: `{ mm: 0.1, cm: 1 }` for a\n * field showing centimeters. A unit that disagrees with the display unit\n * about zero carries an `offset` as well. */\n accepts?: Readonly<Record<string, UnitEntry>>;\n}\n\n/**\n * A display unit as data, for a conversion that is linear: `stored = display * scale + offset`, the direction a\n * `UnitEntry` runs toward its base, so `scale` is what one display unit is worth in stored units. Degrees shown\n * over radians stored is `{ suffix: '°', scale: Math.PI / 180 }`, and `{ scale: 1 }` changes nothing. Being data,\n * it is written to JSON, printed in a schema literal, and edited in `PrefSchemaEditor` like any other attribute.\n */\nexport interface PrefLinearUnit extends PrefUnitText {\n /** Stored units per display unit. Never 0. */\n scale: number;\n /** The stored value a display of 0 stands for. Absent is 0. */\n offset?: number;\n /** Decimal places the shown value is rounded to. Absent, the value shows unrounded and formats to two places.\n * What is typed is stored unrounded either way: a decimal typed at a decimal `scale` is stored as the\n * decimal the two multiply to, without the dust of multiplying them in binary. */\n precision?: number;\n}\n\n/** A display unit as code, for a conversion that is not linear. It cannot be written to JSON or edited as data. */\nexport interface PrefFunctionUnit extends PrefUnitText {\n toDisplay: (stored: number) => number;\n fromDisplay: (display: number) => number;\n /** The stored value as display text, suffix included. */\n format?: (stored: number) => string;\n}\n\n/** Display-unit conversion for number leaves whose stored value uses a\n * canonical unit the user shouldn't see (e.g. radians stored, degrees\n * shown). Read one through {@link resolvePrefUnit}, which answers for both forms. */\nexport type PrefNumberUnit = PrefLinearUnit | PrefFunctionUnit;\n\n/** A unit of either form as the functions that convert and format with it. */\nexport interface ResolvedPrefUnit extends PrefFunctionUnit {\n format: (stored: number) => string;\n}\n\n/** Whether `unit` is the data form, and so can be written out and edited. */\nexport function isPrefLinearUnit(unit: PrefNumberUnit): unit is PrefLinearUnit {\n return typeof (unit as PrefFunctionUnit).toDisplay !== 'function';\n}\n\n/** The name `formatUnit` is asked for a linear unit's one unit by. */\nconst SHOWN = 'shown';\n\n/** The decimal places `n` is written with. Undefined for one written with an exponent, which is no short decimal. */\nfunction decimalPlaces(n: number): number | undefined {\n const text = String(n);\n if (text.includes('e')) return undefined;\n const dot = text.indexOf('.');\n return dot === -1 ? 0 : text.length - dot - 1;\n}\n\n/** Beyond this many places a number is not a decimal someone wrote, and the product is left as computed. */\nconst DECIMAL_PLACES = 12;\n\n/**\n * `shown * scale + offset` as the decimal it is, where all three are short decimals: 33.3 at a scale of 0.01\n * is 0.333, where the product computed in binary is 0.33299999999999996. Nothing is rounded away: the places\n * kept are every place the exact answer has.\n */\nfunction storedOf(shown: number, scale: number, offset: number): number {\n const raw = shown * scale + offset;\n const [a, b, c] = [decimalPlaces(shown), decimalPlaces(scale), decimalPlaces(offset)];\n if (a === undefined || b === undefined || c === undefined || !Number.isFinite(raw)) return raw;\n const places = Math.max(a + b, c);\n return places > DECIMAL_PLACES ? raw : Number(raw.toFixed(places));\n}\n\n/** How to convert and format with `unit`, whichever form it was written in. */\nexport function resolvePrefUnit(unit: PrefNumberUnit): ResolvedPrefUnit {\n if (!isPrefLinearUnit(unit)) {\n return { ...unit, format: unit.format ?? ((stored) => `${unit.toDisplay(stored)}${unit.suffix ?? ''}`) };\n }\n const { scale, offset = 0, precision, suffix, accepts } = unit;\n const round = precision === undefined ? undefined : 10 ** precision;\n const system: UnitSystem = { base: 'stored', units: { [SHOWN]: { factor: scale, offset } } };\n return {\n toDisplay: (stored) => {\n const shown = (stored - offset) / scale;\n return round === undefined ? shown : Math.round(shown * round) / round;\n },\n fromDisplay: (shown) => storedOf(shown, scale, offset),\n format: (stored) => `${formatUnit(stored, SHOWN, system, { precision: precision ?? 2, suffix: false })}${suffix ?? ''}`,\n ...(suffix === undefined ? {} : { suffix }),\n ...(accepts === undefined ? {} : { accepts }),\n };\n}\n\n/**\n * A display unit built from a {@link UnitSystem}: values are stored in the\n * system's base and shown in `display`, rounded to `precision` places when\n * given, and every unit in the system is accepted as typed text. `suffix`\n * defaults to the unit's name and is accepted too. Every unit of a system is\n * linear, so what comes back is data.\n */\nexport function prefUnit(\n system: UnitSystem,\n display: Unit,\n opts?: { precision?: number; suffix?: string },\n): PrefLinearUnit {\n let self: Required<UnitScale>;\n try {\n self = unitScale(system, display);\n } catch (e) {\n throw new Error(`prefUnit: ${e instanceof Error ? e.message : String(e)}`);\n }\n const suffix = opts?.suffix ?? display;\n const accepts: Record<string, UnitEntry> = { [suffix]: 1 };\n for (const name of Object.keys(system.units)) {\n const other = unitScale(system, name);\n // A number typed in `name` reaches display units through base:\n // `(n * factor + offset - self.offset) / self.factor`.\n const factor = other.factor / self.factor;\n const offset = (other.offset - self.offset) / self.factor;\n accepts[name] = offset === 0 ? factor : { factor, offset };\n }\n return {\n suffix,\n scale: self.factor,\n ...(self.offset === 0 ? {} : { offset: self.offset }),\n accepts,\n ...(opts?.precision === undefined ? {} : { precision: opts.precision }),\n };\n}\n","import { prefAliasedLeaf, prefAliasTarget, type PrefAlias } from './alias';\nimport type { PrefGroup, PrefSection } from './groups';\nimport type { PrefLeaf, PrefNumber, PrefObject } from './schema';\nimport { resolvePrefUnit } from './unit';\n\n/**\n * A number leaf's bounds in the unit it is displayed in.\n *\n * Only what the leaf declares converts: an omitted bound has no stored\n * counterpart to put through the conversion, and its fallback — 0..100 for a\n * slider's track, a step of 1 — is a display-space number already. `min` and\n * `max` are points, so they convert the way the value does; `step` is a\n * distance, and a unit with an offset maps zero somewhere else, so converting\n * it as a point would scale it wrong. A decreasing conversion swaps which end\n * is the lower one.\n */\nexport function prefDisplayBounds(\n p: PrefNumber,\n): { min?: number; max?: number; step: number } {\n if (!p.unit) return { min: p.min, max: p.max, step: p.step ?? 1 };\n const { toDisplay } = resolvePrefUnit(p.unit);\n const lo = p.min === undefined ? undefined : toDisplay(p.min);\n const hi = p.max === undefined ? undefined : toDisplay(p.max);\n const flipped = lo !== undefined && hi !== undefined && lo > hi;\n const step = p.step === undefined\n ? 1\n : Math.abs(toDisplay(p.step) - toDisplay(0)) || p.step;\n return { min: flipped ? hi : lo, max: flipped ? lo : hi, step };\n}\n\n/** Distinguishes a leaf from a group or a section while walking a schema tree. */\nexport function isPrefLeaf(node: PrefLeaf | PrefGroup | PrefSection): node is PrefLeaf {\n return 'kind' in node;\n}\n\nconst VALUELESS: ReadonlySet<string> = new Set(['action', 'alias', 'label', 'separator']);\n\n/** Whether a leaf has a value to store: an `action` is a button and holds none, an `alias` shows another leaf's,\n * and a `label` and a `separator` are text and a rule. */\nexport function prefHoldsValue(leaf: PrefLeaf): boolean {\n return !VALUELESS.has(leaf.kind);\n}\n\n/** Distinguishes a section, whose key adds nothing to a path, from a group, whose key is a segment. */\nexport function isPrefSection(node: PrefLeaf | PrefGroup | PrefSection): node is PrefSection {\n return !isPrefLeaf(node) && 'members' in node;\n}\n\n/**\n * Every leaf under a section's `members` or an object leaf's `children`, in\n * schema order, by its own key: the sections between contribute nothing.\n */\nexport function prefSectionLeaves(members: PrefSection['members']): [key: string, leaf: PrefLeaf][] {\n return Object.entries(members).flatMap(([key, child]): [string, PrefLeaf][] =>\n isPrefLeaf(child) ? [[key, child]] : prefSectionLeaves(child.members),\n );\n}\n\n/**\n * The leaf whose value lives at `path`, as the schema's own shape builds\n * paths: a segment per key under a {@link PrefGroup}, the leaf's own key\n * under a {@link PrefSection}. `undefined` for a path that names a group, a\n * field inside an `object` leaf, or nothing.\n */\nexport function prefLeafAt(schema: PrefGroup | PrefSection, path: string): PrefLeaf | undefined {\n if (isPrefSection(schema)) return prefSectionLeaves(schema.members).find(([key]) => key === path)?.[1];\n let node: PrefLeaf | PrefGroup = schema;\n for (const seg of path.split('.')) {\n if (isPrefLeaf(node) || !Object.hasOwn(node.children, seg)) return undefined;\n node = node.children[seg]!;\n }\n return isPrefLeaf(node) ? node : undefined;\n}\n\n/** Get the value at a dotted path inside a nested value tree. Returns\n * `undefined` when a segment is missing or hits a non-object. */\nexport function prefValueAtPath(values: unknown, path: string): unknown {\n let cur: unknown = values;\n for (const seg of path.split('.')) {\n if (cur == null || typeof cur !== 'object' || !Object.hasOwn(cur, seg)) return undefined;\n cur = (cur as Record<string, unknown>)[seg];\n }\n return cur;\n}\n\n/** An object leaf's fields without the `hidden` ones, and without the sections that leaves empty (unless `keepEmpty`). */\nfunction visibleFields(fields: PrefObject['children'], keepEmpty: boolean): PrefObject['children'] {\n const out: PrefObject['children'] = {};\n for (const [key, child] of Object.entries(fields)) {\n if (isPrefLeaf(child)) {\n const kept = visiblePrefSubtree(child, false, keepEmpty);\n if (kept) out[key] = kept;\n continue;\n }\n const members = visibleFields(child.members, keepEmpty);\n if (Object.keys(members).length > 0 || keepEmpty) out[key] = { ...child, members };\n }\n return out;\n}\n\n/**\n * Recursively drop `hidden` leaves (unless `showHidden`), an object leaf's\n * hidden fields among them, pruning groups\n * that end up empty (unless `keepEmpty`). Returns null when the entire\n * subtree is pruned.\n */\nexport function visiblePrefSubtree<T extends PrefLeaf | PrefGroup>(\n node: T,\n showHidden: boolean,\n keepEmpty = false,\n): T | null {\n if (isPrefLeaf(node)) {\n if (node.hidden && !showHidden) return null;\n if (showHidden || node.kind !== 'object') return node;\n return { ...node, children: visibleFields((node as PrefObject).children, keepEmpty) };\n }\n const group = node as PrefGroup;\n const children: Record<string, PrefLeaf | PrefGroup> = {};\n for (const [key, child] of Object.entries(group.children)) {\n const kept = visiblePrefSubtree(child, showHidden, keepEmpty);\n if (kept) children[key] = kept;\n }\n if (Object.keys(children).length === 0 && !keepEmpty) return null;\n return { ...node, children };\n}\n\n/** The record holding the schema version the stored values were written at.\n * Reserved: no top-level schema key may take its name. */\nexport const VERSION_RECORD = '$version';\n\n/** Every leaf under `schema`, by dotted path, in schema order. A group's key\n * is a segment; {@link prefSectionLeaves} is the walk for a section. */\nexport function prefLeaves(schema: PrefGroup): Map<string, PrefLeaf> {\n const out = new Map<string, PrefLeaf>();\n const walk = (group: PrefGroup, prefix: string): void => {\n for (const [key, child] of Object.entries(group.children)) {\n if (key.includes('.')) {\n throw new Error(`[prefs] schema key \"${key}\" contains \".\"; group keys are path segments`);\n }\n if (prefix === '' && key === VERSION_RECORD) {\n throw new Error(`[prefs] schema key \"${VERSION_RECORD}\" is reserved`);\n }\n const path = prefix === '' ? key : `${prefix}.${key}`;\n if (isPrefLeaf(child)) out.set(path, child);\n else walk(child, path);\n }\n };\n walk(schema, '');\n return out;\n}\n\n/** Set `key` on `tree` itself. Plain assignment to `__proto__` replaces the\n * tree's prototype instead, and a schema key or a record name may be one. */\nexport function setOwnPrefValue(tree: Record<string, unknown>, key: string, value: unknown): void {\n Object.defineProperty(tree, key, { value, writable: true, enumerable: true, configurable: true });\n}\n\n/** Set `value` at the dotted `path` in `root` itself, creating missing branches. */\nexport function assignPrefValueAtPath(root: Record<string, unknown>, path: string, value: unknown): void {\n const parts = path.split('.');\n let cursor = root;\n for (const part of parts.slice(0, -1)) {\n if (!Object.hasOwn(cursor, part) || cursor[part] == null) setOwnPrefValue(cursor, part, {});\n cursor = cursor[part] as Record<string, unknown>;\n }\n setOwnPrefValue(cursor, parts[parts.length - 1]!, value);\n}\n\n/** Each of `schema`'s leaves that `tree` holds a value for, as a path and\n * that value — the inverse of building a tree from per-leaf records. */\nexport function flattenPrefValues(schema: PrefGroup, tree: unknown): [string, unknown][] {\n const out: [string, unknown][] = [];\n for (const path of prefLeaves(schema).keys()) {\n const value = prefValueAtPath(tree, path);\n if (value !== undefined) out.push([path, value]);\n }\n return out;\n}\n\n/** Whether one leaf answers to a filter query, by name, description or path. */\nfunction prefLeafMatches(pref: PrefLeaf, path: string, query: string): boolean {\n if (pref.name.toLowerCase().includes(query)) return true;\n if (pref.description?.toLowerCase().includes(query)) return true;\n return path.toLowerCase().includes(query);\n}\n\n/**\n * Drop every leaf that does not answer to `query`, pruning groups left empty.\n * A group whose own name matches keeps all of its leaves. An empty or\n * whitespace query matches everything.\n *\n * An alias answers as the row it draws: its target's name and description\n * where it gives none. That target is looked for in `over`, and in `node`\n * without it; pass the whole schema when `node` is a part of it.\n */\nexport function filterPrefSubtree<T extends PrefLeaf | PrefGroup>(\n node: T,\n query: string,\n path = '',\n over?: PrefGroup | PrefSection,\n): T | null {\n const q = query.trim().toLowerCase();\n if (q === '') return node;\n const within = over ?? (isPrefLeaf(node) ? undefined : (node as PrefGroup));\n const find = (p: string): PrefLeaf | undefined => within && prefLeafAt(within, p);\n if (isPrefLeaf(node)) {\n const target = node.kind === 'alias' ? prefAliasTarget(node as PrefAlias, find) : undefined;\n const drawn = target ? prefAliasedLeaf(node as PrefAlias, target.leaf) : node;\n return prefLeafMatches(drawn, path, q) ? node : null;\n }\n const group = node as PrefGroup;\n if (group.name.toLowerCase().includes(q)) return node;\n const children: Record<string, PrefLeaf | PrefGroup> = {};\n for (const [key, child] of Object.entries(group.children)) {\n const kept = filterPrefSubtree(child, q, path === '' ? key : `${path}.${key}`, within);\n if (kept) children[key] = kept;\n }\n if (Object.keys(children).length === 0) return null;\n return { ...node, children };\n}\n","// A condition over other leaves' values, held as data so a schema carrying\n// one still exports as a literal and survives a draft.\n\nimport { isPlainObject } from '@weasel-js/registry';\n\n/** What a condition can compare a leaf's value against. `null` stands for\n * nothing held: a missing value as well as a stored `null`. */\nexport type PrefConditionValue = string | number | boolean | null;\n\n/**\n * One leaf's value, tested. `path` is the full path the value is read and\n * written at (`'windows.paging'`), a field of an `object` or `union` leaf\n * included (`'stroke.width'`, `'fill.type'`). With `from: 'item'` the path is\n * read from the entry the test's node is drawn in instead: the entry of the\n * nearest list or map the node is the `item` of, or sits inside the item of.\n * `{ from: 'item', path: 'mode' }` on a field of a list's item reads `mode`\n * of the same entry, and an empty path is the entry itself. The value compared is the one\n * the leaf's control shows, where an `encoding` stores another. With\n * several operators it holds while all of them do, so\n * `{ path: 'count', atLeast: 1, below: 10 }` is a range.\n *\n * With no operator it holds while the value is set, which by kind is:\n * a `boolean` that is on; a `number` other than 0; a `string`, a `color`, a\n * `field`, or an `enum`'s option that is not the empty string; a `paint`\n * that is not `null`; a `list` with an entry; a `map` with a key; an\n * `object` or a `union` holding a field. Nothing held is never set, and the\n * value of an app-defined kind is set by whichever of those its shape is,\n * else while it is truthy.\n */\nexport interface PrefTest {\n path: string;\n /** Where `path` is read from: the entry the node is drawn in. Unset: the schema root. */\n from?: 'item';\n is?: PrefConditionValue;\n isNot?: PrefConditionValue;\n /** Holds while the value is any of these. */\n in?: readonly PrefConditionValue[];\n /** The ordering operators hold only for a number. */\n above?: number;\n below?: number;\n atLeast?: number;\n atMost?: number;\n}\n\n/** A condition a schema node holds in `showIf` or `enableIf`. An empty `all`\n * holds and an empty `any` does not. */\nexport type PrefCondition =\n | PrefTest\n | { all: readonly PrefCondition[] }\n | { any: readonly PrefCondition[] }\n | { not: PrefCondition };\n\n/** Reads the value a test compares: at `path` from the schema root, or with `from`, from the entry being drawn. */\nexport type PrefConditionReader = (path: string, from?: 'item') => unknown;\n\nexport const ORDERINGS = ['above', 'below', 'atLeast', 'atMost'] as const;\nconst TEST_KEYS: ReadonlySet<string> = new Set(['path', 'from', 'is', 'isNot', 'in', ...ORDERINGS]);\n\nconst isValue = (v: unknown): v is PrefConditionValue =>\n v === null || typeof v === 'string' || typeof v === 'number' || typeof v === 'boolean';\n\nexport type Form = 'all' | 'any' | 'not' | 'test';\n\n/** Which form `value` is, judged on its own keys and not on what it holds. */\nexport function formOf(value: unknown): Form | undefined {\n if (!isPlainObject(value)) return undefined;\n const keys = Object.keys(value);\n if (keys.length === 1 && (keys[0] === 'all' || keys[0] === 'any')) return Array.isArray(value[keys[0]]) ? keys[0] : undefined;\n if (keys.length === 1 && keys[0] === 'not') return 'not';\n if (typeof value.path !== 'string' || !keys.every((key) => TEST_KEYS.has(key))) return undefined;\n if (value.from !== undefined && value.from !== 'item') return undefined;\n if (value.is !== undefined && !isValue(value.is)) return undefined;\n if (value.isNot !== undefined && !isValue(value.isNot)) return undefined;\n if (value.in !== undefined && !(Array.isArray(value.in) && value.in.every(isValue))) return undefined;\n return ORDERINGS.every((op) => value[op] === undefined || typeof value[op] === 'number') ? 'test' : undefined;\n}\n\n/** The conditions directly inside a combinator; none for a test. */\nexport function partsOf(condition: unknown, form: Form): readonly unknown[] {\n const held = condition as Record<string, unknown>;\n return form === 'test' ? [] : form === 'not' ? [held.not] : (held[form] as unknown[]);\n}\n\n/** Whether `value` is a well-formed condition, all the way down. */\nexport function isPrefCondition(value: unknown): value is PrefCondition {\n const form = formOf(value);\n return form !== undefined && partsOf(value, form).every(isPrefCondition);\n}\n\nconst same = (held: unknown, value: PrefConditionValue): boolean => (value === null ? held == null : held === value);\n\nfunction isSet(held: unknown): boolean {\n if (Array.isArray(held)) return held.length > 0;\n if (isPlainObject(held)) return Object.keys(held).length > 0;\n return Boolean(held);\n}\n\nfunction testHolds(test: PrefTest, held: unknown): boolean {\n const ops = Object.keys(test).filter((key) => key !== 'path' && key !== 'from' && test[key as keyof PrefTest] !== undefined);\n if (ops.length === 0) return isSet(held);\n if (test.is !== undefined && !same(held, test.is)) return false;\n if (test.isNot !== undefined && same(held, test.isNot)) return false;\n if (test.in !== undefined && !test.in.some((value) => same(held, value))) return false;\n if (!ORDERINGS.some((op) => test[op] !== undefined)) return true;\n if (typeof held !== 'number') return false;\n return (\n (test.above === undefined || held > test.above) &&\n (test.below === undefined || held < test.below) &&\n (test.atLeast === undefined || held >= test.atLeast) &&\n (test.atMost === undefined || held <= test.atMost)\n );\n}\n\n/** Whether `condition` holds, given the value `read` finds at each path it names. */\nexport function prefConditionHolds(condition: PrefCondition, read: PrefConditionReader): boolean {\n if ('all' in condition) return condition.all.every((part) => prefConditionHolds(part, read));\n if ('any' in condition) return condition.any.some((part) => prefConditionHolds(part, read));\n if ('not' in condition) return !prefConditionHolds(condition.not, read);\n return testHolds(condition, read(condition.path, condition.from));\n}\n\n/** Whether a node is drawn: its `showIf` holds, or it has none. A node\n * answers for itself only; one inside a group that is not shown is not\n * drawn either. */\nexport function prefIsShown(node: { showIf?: PrefCondition }, read: PrefConditionReader): boolean {\n return node.showIf === undefined || prefConditionHolds(node.showIf, read);\n}\n\n/** Whether a node's controls take input: its `enableIf` holds, or it has\n * none. As {@link prefIsShown}, a node answers for itself only. */\nexport function prefIsEnabled(node: { enableIf?: PrefCondition }, read: PrefConditionReader): boolean {\n return node.enableIf === undefined || prefConditionHolds(node.enableIf, read);\n}\n\n/** Every path `condition` reads from the schema root, or with `from`, from the entry, once each, in the order met. */\nexport function prefConditionPaths(condition: PrefCondition, from?: 'item'): string[] {\n const out = new Set<string>();\n const walk = (c: PrefCondition): void => {\n if ('all' in c) c.all.forEach(walk);\n else if ('any' in c) c.any.forEach(walk);\n else if ('not' in c) walk(c.not);\n else if (c.from === from) out.add(c.path);\n };\n walk(condition);\n return [...out];\n}\n\n/** Whether any test of `condition` reads from the entry, so that it has no answer until an entry is drawn. */\nexport function prefConditionReadsItem(condition: PrefCondition): boolean {\n if ('all' in condition) return condition.all.some(prefConditionReadsItem);\n if ('any' in condition) return condition.any.some(prefConditionReadsItem);\n if ('not' in condition) return prefConditionReadsItem(condition.not);\n return condition.from === 'item';\n}\n\n/**\n * `condition` with every path it reads put through `move`, for following a\n * key that was renamed or a leaf that moved. `move` is told where a path is\n * read from, and what it hands back is read from there too. A condition none\n * of whose paths change comes back as the object it was given, and so does\n * each part of one.\n */\nexport function mapPrefConditionPaths(condition: PrefCondition, move: (path: string, from?: 'item') => string): PrefCondition {\n const each = (parts: readonly PrefCondition[]): readonly PrefCondition[] => {\n const next = parts.map((part) => mapPrefConditionPaths(part, move));\n return next.every((part, i) => part === parts[i]) ? parts : next;\n };\n if ('all' in condition) {\n const all = each(condition.all);\n return all === condition.all ? condition : { all };\n }\n if ('any' in condition) {\n const any = each(condition.any);\n return any === condition.any ? condition : { any };\n }\n if ('not' in condition) {\n const not = mapPrefConditionPaths(condition.not, move);\n return not === condition.not ? condition : { not };\n }\n const path = move(condition.path, condition.from);\n return path === condition.path ? condition : { ...condition, path };\n}\n","// The preferences schema's typed leaves. `groups.ts` holds the branch nodes\n// that arrange them: tools declare their options as a `PrefGroup`, and apps\n// compose those into one registry, which `PrefsForm` renders and `openPrefs`\n// stores.\n\nimport type { PrefAction } from './action';\nimport type { PrefAlias } from './alias';\nimport type { PrefCondition } from './condition';\nimport type { PrefSection } from './groups';\nimport type { PrefLabel, PrefSeparator } from './label';\nimport type { PrefList } from './list';\nimport type { PrefLocus } from './locus';\nimport type { PrefMap } from './map';\nimport type { PrefUnion } from './union';\nimport type { PrefNumberUnit } from './unit';\nimport type { Display, InfinityText } from '@weasel-js/quantity';\n\n/** The value types a built-in pref leaf can hold. */\nexport type PrefKind =\n | 'number' | 'boolean' | 'string' | 'enum' | 'color' | 'paint' | 'object' | 'list' | 'map' | 'union' | 'field' | 'action' | 'alias' | 'label' | 'separator';\n\n/** Leaves that share one row in a compact property UI, declared on the first\n * of them. Purely presentational. */\nexport interface PrefPair {\n /** The other leaves on the row, by the full path their values are read and\n * written at (`'pose.y'`, `'camera.type'`), in order. Each must follow the\n * one before it among its siblings. */\n with: string | readonly string[];\n /** What the row reads. Default: the declaring leaf's `name`. */\n label?: string;\n}\n\n/** The fields every leaf pref shares, keyed by its `kind` and typed by its stored value. */\nexport interface PrefBase<K extends string, Value> {\n kind: K;\n /** Human-readable label. */\n name: string;\n /** Longer help text — shown in tooltips / a settings pane. */\n description: string;\n /** Fallback when nothing is persisted. */\n default: Value;\n /** Hide from a host app's settings UI by default. */\n hidden?: boolean;\n /** Drawn only while this holds. Presentational: the value stays stored\n * and readable while the leaf is not drawn. */\n showIf?: PrefCondition;\n /** Drawn, and disabled while this does not hold. */\n enableIf?: PrefCondition;\n /** Nothing held where this leaf's value is read means `default`, because\n * whoever reads the value takes it that way (`pose.rotation ?? 0`). A\n * surface over sparse settings reads every leaf so already. One over a\n * scene node, where a missing key otherwise means the node has no such\n * property, shows the default only for a leaf that says this, and still\n * writes nothing until an edit. */\n absentIsDefault?: boolean;\n /** Render full-width with no label row in schema-driven settings UIs\n * (weasel-ui `PrefsForm` honors this for leaves whose control brings\n * its own chrome). */\n block?: boolean;\n /** Draw the control in the heading of the group or section holding the\n * leaf, in place of a row of its own. Only a built-in `boolean` or `enum`\n * fits there (`prefFitsHeading`); any other leaf stays a row. Honored by\n * weasel-ui `PrefsForm` and labkit's `ControlPanel`. */\n heading?: boolean;\n /** Glyph naming this leaf in a host UI's icon set (weasel-ui resolves it\n * against `ICON_PATHS`). A plain string because this package ships no\n * icon set and cannot depend on one. Read where a leaf's `name` has nowhere to go — a\n * `pair`ed row is labeled by the pair, so its fields have only the glyph\n * to tell them apart. */\n icon?: string;\n /** Puts this leaf and the ones it names on one row. */\n pair?: PrefPair;\n /** Shorter forms of `name`, longest first. A surface short of room for\n * `name` — a strip of controls on one line, a segment in a `pair`ed row —\n * shows the longest of them that fits. `name` stays the accessible name, so\n * these abbreviate without costing anything. */\n short?: readonly string[];\n /** Never auto. A surface that lets a leaf be left for its owner to decide\n * (weasel-ui `PrefsForm`'s `onAutoChange`, labkit's `ControlPanel`) gives\n * this one no way to. */\n manual?: boolean;\n /** Starts auto, where it would start pinned at `default`. */\n unpinned?: boolean;\n /** What the leaf reads while it is auto, where its owner computes nothing\n * for it. Unset, an auto leaf has no value. */\n autoValue?: Value;\n /** The name of the type this leaf was made from, set by `prefType`. A\n * schema editor shows such a leaf as one closed thing and prints the name\n * in place of its literal. */\n type?: string;\n /** The `enum` leaves this one's value may be split by, each by the full\n * path its value is read at: the value may then be held once per option\n * of any of them (a {@link PrefLocus}), which the store folds into the one\n * value read. Whether it is split is the stored value's to say. The\n * order is the order a value split by several is stored in, the first\n * outermost. Each must be a plain `enum`: not `clearable`, with no\n * `encoding`, and not split itself. */\n splitBy?: readonly string[];\n /** What the leaf holds while nothing is stored for it, where that is a\n * split value: a default that differs by option. Split only by entries of\n * `splitBy`. `default` stays what a member it leaves out reads as, and\n * what the leaf's value type is read from. */\n defaultLocus?: PrefLocus;\n}\n\n/** How a schema-driven UI should present a number pref. */\nexport type PrefNumberControl = 'input' | 'slider';\n/** How a schema-driven UI should present a boolean pref. */\nexport type PrefBooleanControl = 'checkbox' | 'switch' | 'toggle';\n/** How a schema-driven UI should present a string pref. */\nexport type PrefStringControl = 'input' | 'textarea';\n/** How a schema-driven UI should present an enum pref. */\nexport type PrefEnumControl = 'select' | 'radio' | 'toggle' | 'menu';\n\n/** A numeric pref, optionally bounded and stepped, and optionally stored in a\n * different unit from the one shown. */\nexport interface PrefNumber extends PrefBase<'number', number> {\n min?: number;\n max?: number;\n step?: number;\n control?: PrefNumberControl;\n /** How the value shows, speaks and reads back when typed — `compact()`\n * reads `2.00M`. Presentation only: the stored value stays a number. */\n display?: Display;\n unit?: PrefNumberUnit;\n /** Which end of a slider gets a stop for ±Infinity, one step beyond the range. */\n endless?: 'min' | 'max' | 'both';\n /** The word infinity shows as — `'never'`, `'uncapped'`. Default `∞`. */\n infinity?: InfinityText;\n}\n/**\n * Stored-value bridge for a boolean leaf whose field is not a boolean — the\n * flag counterpart of {@link PrefEnumEncoding}. `TextStyle.fontStyle` is\n * the case: it stores `'italic'`, and the control is an Italic toggle.\n */\nexport interface PrefBooleanEncoding {\n /** Whether `stored` reads as on. */\n read: (stored: unknown, siblings: Record<string, unknown> | undefined) => boolean;\n /** What to store for `on`. `undefined` removes the field. */\n write: (on: boolean, siblings: Record<string, unknown> | undefined) => unknown;\n}\n\n/** An on/off pref. */\nexport interface PrefBoolean extends PrefBase<'boolean', boolean> {\n control?: PrefBooleanControl;\n encoding?: PrefBooleanEncoding;\n}\n/** A free-text pref. */\nexport interface PrefString extends PrefBase<'string', string> {\n control?: PrefStringControl;\n}\n/**\n * Stored-value bridge for an enum leaf whose value is not the option string —\n * the counterpart of {@link PrefNumberUnit}, which does the same for a\n * number stored in a canonical unit.\n *\n * A dash array is the case that needs it: `Stroke.dash` stores lengths, and\n * the thing a person chooses is a style. The presets scale by the stroke's\n * width, so both directions are given the object's other fields.\n */\nexport interface PrefEnumEncoding<T extends string = string> {\n /**\n * The option `stored` reads as, or `undefined` for none — which a UI shows\n * the way it shows a mixed selection, by selecting nothing.\n *\n * `siblings` is the object the leaf is a field of, or `undefined` when the\n * node does not hold that object (and for a top-level leaf, which has none).\n */\n read: (stored: unknown, siblings: Record<string, unknown> | undefined) => T | undefined;\n /** What to store for `option`. `undefined` removes the field. */\n write: (option: T, siblings: Record<string, unknown> | undefined) => unknown;\n}\n\n/** What every enum leaf carries; {@link PrefEnum} adds `clearable`. */\nexport interface PrefEnumBase<T extends string = string>\n extends PrefBase<'enum', T | undefined> {\n /** `short` holds shorter forms of `label`, longest first, for a segmented\n * control too narrow for the full one — down to a capital or two. `icon`\n * names a glyph in the host UI's set (weasel-ui resolves it against\n * `ICON_PATHS`), drawn in place of any text form where it resolves. It is\n * a plain string because this package ships no icon set and cannot\n * depend on one. The full `label` stays the accessible name, so neither the abbreviation nor the glyph becomes the only thing naming\n * the option.\n *\n * `disabled` marks an option a control reports but cannot author — the\n * value a stored form reads as when it matches nothing offered. Dropping it\n * from the list instead would leave the control selecting nothing and\n * claiming the field is unset. */\n options: readonly {\n value: T;\n label: string;\n short?: readonly string[];\n icon?: string;\n disabled?: boolean;\n }[];\n control?: PrefEnumControl;\n encoding?: PrefEnumEncoding<T>;\n}\n\n/**\n * A pref with a fixed set of labeled choices.\n *\n * `clearable` says the field may hold none of the options, and that absence\n * is a state of its own rather than a missing value — a script that is\n * neither super nor sub. A toggle control then lets the chosen segment be\n * clicked off, which removes the field. Such a leaf's `default` is\n * `undefined`: a missing value is the only stored form of cleared, so a\n * default would bring an option back the moment the field was cleared.\n */\nexport type PrefEnum<T extends string = string> = PrefEnumBase<T> & (\n | { clearable?: false }\n | { clearable: true; default: undefined }\n);\n\n/** A single color, stored as a hex string. For a value that may also be a\n * gradient or a pattern, use {@link PrefPaint} instead. */\nexport interface PrefColor extends PrefBase<'color', string> {\n /** Value is `#rrggbb`, or `#rrggbbaa` when `alpha` is set (UIs then\n * offer an opacity control). */\n alpha?: boolean;\n}\n\n/**\n * Open leaf: any node with a `kind` outside the built-ins. Schema-driven\n * UIs dispatch it to an app-supplied renderer. Deliberately NOT\n * index-signatured so concrete app interfaces stay assignable.\n */\nexport type PrefCustom = PrefBase<string, unknown>;\n\n/**\n * A whole `Paint`, not a color inside one. Use it wherever the value is\n * the tagged paint union — a solid color, a pattern, a gradient — rather\n * than a hex string.\n *\n * Addressing `…fill.color` instead reads `undefined` off a gradient (so the\n * control shows its default and claims the text is black) and writes a\n * hybrid `{ fill: 'gradient', stops, color }` that the renderer's structural\n * `'color' in paint` checks then paint flat solid. The union has to be\n * edited as a union.\n */\nexport interface PrefPaint extends PrefBase<'paint', unknown> {\n /** Offer an opacity control alongside the color. */\n alpha?: boolean;\n}\n\n/**\n * A leaf whose value is one object, with its own fields hanging off it as\n * `children`; every edit commits the parent object whole. Sibling leaves\n * addressing into the value (`data.stroke.width`, `data.stroke.cap`) would\n * each write one field of a value they can only half see, and writing into\n * something that is not an object yet corrupts it.\n *\n * `children` paths are relative to the object. They are ordinary leaves, so a\n * field that is itself a union (a stroke's `paint`) declares the kind that\n * edits that union. A child may also be a {@link PrefSection}, which\n * organizes the fields under a heading without contributing to the path.\n */\nexport interface PrefObject extends PrefBase<'object', unknown> {\n children: Record<string, PrefLeaf | PrefSection>;\n /**\n * Lift a non-object value into the object form, for a consumer field that\n * may also be held as a scalar. Called before a child edit is applied;\n * without it a scalar-valued leaf shows its children empty, and an edit\n * starts from the leaf's `default`.\n */\n fromScalar?: (value: unknown) => Record<string, unknown>;\n}\n\n/**\n * A reference to another field of the same schema, held as the full path its\n * value is read and written at (`'camera.type'`) — the currency fields refer\n * to each other in. A surface offers the fields it draws as the choices.\n */\nexport interface PrefField extends PrefBase<'field', string> {\n /** Only fields of these kinds may be named. Default: any leaf. */\n kinds?: readonly string[];\n}\n\n/** One built-in pref leaf. `PrefLeaf` widens this to include\n * app-defined kinds. */\nexport type BuiltinPref =\n | PrefNumber\n | PrefBoolean\n | PrefString\n | PrefEnum\n | PrefColor\n | PrefPaint\n | PrefObject\n | PrefList\n | PrefMap\n | PrefUnion\n | PrefField\n | PrefAction\n | PrefAlias\n | PrefLabel\n | PrefSeparator;\n\n// Compile-time tie: every built-in leaf kind must appear in PrefKind\n// and vice versa (PrefBase's K is open for PrefCustom's sake, so\n// the union no longer enforces it).\ntype _BuiltinKindsExact = [BuiltinPref['kind']] extends [PrefKind]\n ? [PrefKind] extends [BuiltinPref['kind']] ? true : never\n : never;\nconst _builtinKindsExact: _BuiltinKindsExact = true;\nvoid _builtinKindsExact;\n\n/**\n * The built-in kinds, as a table. A kind added to {@link PrefKind} is a\n * compile error here, and from here it is one in every renderer's `never`\n * guard.\n */\nexport const PREF_KINDS: Record<PrefKind, true> = {\n number: true,\n boolean: true,\n string: true,\n enum: true,\n color: true,\n paint: true,\n object: true,\n list: true,\n map: true,\n union: true,\n field: true,\n action: true,\n alias: true,\n label: true,\n separator: true,\n};\n\n/** Which row each pairing among `leaves` puts a path on: a `key` the row's\n * members share (the declaring leaf's path) and the `label` it reads. A\n * path no `pair` names is absent. `leaves` are given by the path each\n * surface reads and writes them at, so references resolve in its terms. */\nexport function pairRowsOf(\n leaves: Iterable<readonly [path: string, leaf: PrefLeaf]>,\n): Map<string, { key: string; label: string }> {\n const rows = new Map<string, { key: string; label: string }>();\n for (const [path, leaf] of leaves) {\n if (!leaf.pair || rows.has(path)) continue;\n const row = { key: path, label: leaf.pair.label ?? leaf.name };\n rows.set(path, row);\n const partners = typeof leaf.pair.with === 'string' ? [leaf.pair.with] : leaf.pair.with;\n for (const partner of partners) if (!rows.has(partner)) rows.set(partner, row);\n }\n return rows;\n}\n\n/**\n * Narrows a leaf to the built-in union, so a renderer's switch discriminates\n * on {@link PrefKind} instead of the open `string` that\n * {@link PrefCustom} widens `kind` to. An app-defined kind answers false\n * and belongs to the renderer's custom-renderer path.\n */\nexport function isBuiltinPref(leaf: PrefLeaf): leaf is BuiltinPref {\n return Object.hasOwn(PREF_KINDS, leaf.kind);\n}\n\n/** Built-in or app-defined leaf. */\nexport type PrefLeaf = BuiltinPref | PrefCustom;\n","// Which leaf describes the value at a path, looking inside the leaves whose\n// values are made of fields. What reads a condition's paths against a schema\n// asks here.\n\nimport type { PrefGroup, PrefSection } from './groups';\nimport { isPrefLeaf, isPrefSection, prefSectionLeaves } from './helpers';\nimport { isBuiltinPref, type PrefEnum, type PrefLeaf, type PrefObject } from './schema';\nimport type { PrefUnion } from './union';\n\n/** A value the schema says nothing about: an entry of a list, a field of an app-defined kind. */\nexport const UNSEEN = Symbol('unseen');\n\n/** The leaf describing a value, and the path of the `object` or `union` leaf it is a field of, when it is one. */\nexport interface PrefHeld {\n leaf: PrefLeaf;\n within?: string;\n}\n\nconst under = (at: string, key: string): string => (at === '' ? key : `${at}.${key}`);\n\n/** `at` is the path of the leaf the fields belong to, `undefined` for a section schema's own leaves. */\nfunction amongFields(fields: [key: string, leaf: PrefLeaf][], path: string, at: string | undefined): PrefHeld | typeof UNSEEN | undefined {\n const exact = fields.find(([key]) => key === path);\n if (exact) return { leaf: exact[1], ...(at === undefined ? {} : { within: at }) };\n const outer = fields.find(([key]) => path.startsWith(`${key}.`));\n return outer && insideLeaf(outer[1], path.slice(outer[0].length + 1), under(at ?? '', outer[0]));\n}\n\nfunction insideLeaf(leaf: PrefLeaf, rest: string, at: string): PrefHeld | typeof UNSEEN | undefined {\n if (leaf.kind === 'object') return amongFields(prefSectionLeaves((leaf as PrefObject).children), rest, at);\n if (leaf.kind === 'union') {\n const { tag, variants } = leaf as PrefUnion;\n if (rest === tag) {\n const options = Object.keys(variants).map((value) => ({ value, label: variants[value]!.name }));\n return { leaf: { kind: 'enum', name: tag, description: '', default: undefined, options } as PrefEnum, within: at };\n }\n for (const variant of Object.values(variants)) {\n const found = amongFields(prefSectionLeaves(variant.children), rest, at);\n if (found !== undefined) return found;\n }\n return undefined;\n }\n return !isBuiltinPref(leaf) || leaf.kind === 'list' || leaf.kind === 'map' || leaf.kind === 'paint' ? UNSEEN : undefined;\n}\n\n/** The leaf describing the value at `path`, looking inside `object` and `union` leaves. */\nexport function prefLeafHolding(schema: PrefGroup | PrefSection, path: string): PrefHeld | typeof UNSEEN | undefined {\n if (isPrefSection(schema)) return amongFields(prefSectionLeaves(schema.members), path, undefined);\n const steps = path.split('.');\n let node: PrefLeaf | PrefGroup = schema;\n for (let i = 0; i < steps.length; i++) {\n if (isPrefLeaf(node)) return insideLeaf(node, steps.slice(i).join('.'), steps.slice(0, i).join('.'));\n if (!Object.hasOwn(node.children, steps[i]!)) return undefined;\n node = node.children[steps[i]!]!;\n }\n return isPrefLeaf(node) ? { leaf: node } : undefined;\n}\n\n/**\n * The schema that answers for the value at `path`: `schema` where a leaf of\n * it describes that value, else `over`, the schema `schema` is drawn over.\n * So a path both hold is `schema`'s. Every reader of a condition's paths\n * that takes a second schema asks here which one to read.\n */\nexport function prefSchemaHolding(\n schema: PrefGroup | PrefSection, path: string, over?: PrefGroup | PrefSection,\n): PrefGroup | PrefSection {\n return over === undefined || prefLeafHolding(schema, path) !== undefined ? schema : over;\n}\n\n/**\n * The leaf describing the value at `path` inside one entry of a list or a\n * map whose `item` this is; the empty path is the entry itself. `within` is\n * a path inside the entry too, empty for the entry.\n */\nexport function prefLeafHoldingIn(item: PrefLeaf, path: string): PrefHeld | typeof UNSEEN | undefined {\n return path === '' ? { leaf: item } : insideLeaf(item, path, '');\n}\n","// What is wrong with a condition as one of a schema's: what a store warns of\n// and a schema editor marks.\n\nimport { formOf, ORDERINGS, partsOf, type PrefConditionValue, type PrefTest } from './condition';\nimport type { PrefGroup, PrefSection } from './groups';\nimport { isPrefLeaf, isPrefSection, prefHoldsValue } from './helpers';\nimport { prefLeafHolding, prefLeafHoldingIn, prefSchemaHolding, UNSEEN } from './holding';\nimport type { PrefList } from './list';\nimport type { PrefMap } from './map';\nimport { isBuiltinPref, type PrefEnum, type PrefLeaf, type PrefObject } from './schema';\nimport type { PrefUnion } from './union';\n\n/** One thing wrong with a condition: it is not one, it reads a path no leaf\n * holds a value at, it compares a leaf against a value it never holds, it\n * never holds whatever the leaf does, as an `in` of no values, it is the\n * `showIf` of a list's or a map's item, which is drawn with each entry, or\n * it reads from the entry on a node that no list or map draws. */\nexport interface PrefConditionProblem {\n code: 'malformed' | 'no-leaf' | 'no-value' | 'value' | 'never' | 'item-show' | 'no-item';\n /** The path read, where the problem is with one. */\n path?: string;\n problem: string;\n}\n\n/** A {@link PrefConditionProblem} and the node whose condition has it. */\nexport interface PrefSchemaConditionProblem extends PrefConditionProblem {\n /**\n * Where the node sits: a key per step from the root, `''` for the root\n * itself. An object leaf's fields and sections, a union's variants, and a\n * list's or a map's `item` are steps too, so this is not always a path a\n * value is read at.\n */\n at: string;\n field: 'showIf' | 'enableIf';\n}\n\n/** Where the node holding a condition sits, for what a condition alone does not say. */\nexport interface PrefConditionSite {\n /** The nearest list or map the node is inside an entry of: the one it is the `item` of, or one above it. */\n within?: PrefList | PrefMap;\n /** The condition is the `showIf` of that list's or map's `item` itself. */\n itemShowIf?: boolean;\n}\n\nconst show = (value: unknown): string => (typeof value === 'string' ? `'${value}'` : String(value));\n\n/** Why `leaf` never holds `value`; `undefined` when it may. */\nfunction neverHolds(leaf: PrefLeaf, value: PrefConditionValue): string | undefined {\n if (value === null || !isBuiltinPref(leaf)) return undefined;\n switch (leaf.kind) {\n case 'number':\n return typeof value === 'number' ? undefined : 'it is a number';\n case 'boolean':\n return typeof value === 'boolean' ? undefined : 'it is a boolean';\n case 'string':\n case 'color':\n case 'field':\n return typeof value === 'string' ? undefined : `it is a ${leaf.kind === 'string' ? 'string' : `${leaf.kind}, held as a string`}`;\n case 'enum': {\n const { options } = leaf as PrefEnum;\n if (options.some((option) => option.value === value)) return undefined;\n return `its options are ${options.map((option) => show(option.value)).join(', ')}`;\n }\n case 'object':\n return (leaf as PrefObject).fromScalar ? undefined : 'it is an object';\n default:\n return `it is a ${leaf.kind}`;\n }\n}\n\ntype Schema = PrefGroup | PrefSection;\n\nfunction testProblems(test: PrefTest, schema: Schema, site: PrefConditionSite, over: Schema | undefined): PrefConditionProblem[] {\n const { path } = test;\n if (test.from === 'item' && site.within === undefined) {\n return [{ code: 'no-item', path, problem: `\"${path}\" is read from an entry, and this is inside no list or map` }];\n }\n const found = leafProblems(test, schema, site, over);\n if (test.in?.length !== 0) return found;\n return [...found, { code: 'never', path, problem: `\"${path}\" is one of nothing, which never holds` }];\n}\n\nfunction leafProblems(test: PrefTest, schema: Schema, site: PrefConditionSite, over: Schema | undefined): PrefConditionProblem[] {\n const { path } = test;\n const inEntry = test.from === 'item';\n const held = inEntry ? prefLeafHoldingIn(site.within!.item, path) : prefLeafHolding(prefSchemaHolding(schema, path, over), path);\n if (held === undefined) return [{ code: 'no-leaf', path, problem: `no leaf holds a value at \"${path}\"${inEntry ? ' in the entry' : ''}` }];\n if (held === UNSEEN) return [];\n const { leaf } = held;\n const named = inEntry ? (path === '' ? 'the entry' : `the entry's \"${path}\"`) : `\"${path}\"`;\n if (!prefHoldsValue(leaf)) return [{ code: 'no-value', path, problem: `${named} is a${leaf.kind === 'separator' || leaf.kind === 'label' ? '' : 'n'} ${leaf.kind}, which holds no value` }];\n const out: PrefConditionProblem[] = [];\n const compared = [test.is, test.isNot, ...(test.in ?? [])].filter((value) => value !== undefined);\n for (const value of compared) {\n const why = neverHolds(leaf, value);\n if (why !== undefined) out.push({ code: 'value', path, problem: `${named} never holds ${show(value)}: ${why}` });\n }\n const ordering = ORDERINGS.find((op) => test[op] !== undefined);\n if (ordering !== undefined && isBuiltinPref(leaf) && leaf.kind !== 'number') {\n out.push({ code: 'value', path, problem: `${named} is a${leaf.kind === 'object' || leaf.kind === 'enum' ? 'n' : ''} ${leaf.kind}, and \"${ordering}\" compares numbers` });\n }\n return out;\n}\n\n/**\n * What is wrong with `condition` as one of `schema`'s: every part of it that\n * is not a condition, every path it reads that no leaf holds a value at,\n * every comparison against a value the leaf's kind or options rule out, and\n * every `in` of no values.\n * `null` is never ruled out, and neither is anything under an app-defined\n * kind or inside a list, a map, or a paint, which the schema does not\n * describe. Takes `unknown`, since a schema read from JSON or built without\n * types may hold anything where a condition goes. `site` says where the\n * condition's node sits; without it the node is taken to be outside every\n * list and map. A path read from the entry is held to the `item` of\n * `site.within`, and is a problem where there is none. `over` is the schema\n * `schema` is drawn over: a path no leaf of `schema` holds is held to it,\n * and is a problem only where it holds none either.\n */\nexport function checkPrefCondition(\n condition: unknown,\n schema: PrefGroup | PrefSection,\n site: PrefConditionSite = {},\n over?: PrefGroup | PrefSection,\n): PrefConditionProblem[] {\n if (site.itemShowIf && site.within) {\n const { kind } = site.within;\n const problem = `a ${kind}'s item is drawn with each entry and is never hidden: put the condition on the entry's fields, or on the ${kind}`;\n return [{ code: 'item-show', problem }, ...checkPrefCondition(condition, schema, { within: site.within }, over)];\n }\n const form = formOf(condition);\n if (form === undefined) {\n const shown = typeof condition === 'function' ? 'a function' : JSON.stringify(condition);\n return [{ code: 'malformed', problem: `not a condition: ${shown}` }];\n }\n if (form === 'test') return testProblems(condition as PrefTest, schema, site, over);\n return partsOf(condition, form).flatMap((part) => checkPrefCondition(part, schema, site, over));\n}\n\ntype Conditioned = { showIf?: unknown; enableIf?: unknown };\n\n/** {@link checkPrefCondition} over every `showIf` and `enableIf` in `schema`, in schema order, each held to `over` as well. */\nexport function checkPrefConditions(\n schema: PrefGroup | PrefSection,\n over?: PrefGroup | PrefSection,\n): PrefSchemaConditionProblem[] {\n const out: PrefSchemaConditionProblem[] = [];\n const own = (node: Conditioned, at: string, within: PrefList | PrefMap | undefined, isItem = false): void => {\n for (const field of ['showIf', 'enableIf'] as const) {\n if (node[field] === undefined) continue;\n const site = { ...(within ? { within } : {}), ...(isItem && field === 'showIf' ? { itemShowIf: true } : {}) };\n for (const problem of checkPrefCondition(node[field], schema, site, over)) out.push({ ...problem, at, field });\n }\n };\n const under = (at: string, key: string): string => (at === '' ? key : `${at}.${key}`);\n const leaf = (node: PrefLeaf, at: string, within: PrefList | PrefMap | undefined, isItem = false): void => {\n own(node, at, within, isItem);\n if (node.kind === 'object') members((node as PrefObject).children, at, true, within);\n else if (node.kind === 'list' || node.kind === 'map') {\n const holder = node as PrefList | PrefMap;\n // A leaf an app's renderer draws under a built-in's kind may hold no item.\n if (holder.item !== undefined) leaf(holder.item, under(at, 'item'), holder, true);\n } else if (node.kind === 'union') {\n for (const [key, variant] of Object.entries((node as PrefUnion).variants)) leaf(variant, under(at, key), within);\n }\n };\n /** `nested`: inside an object leaf, where a key is relative to it; a section schema's own keys are whole. */\n const members = (held: PrefSection['members'], at: string, nested: boolean, within: PrefList | PrefMap | undefined): void => {\n for (const [key, child] of Object.entries(held)) {\n const here = nested ? under(at, key) : key;\n if (isPrefLeaf(child)) leaf(child, here, within);\n else {\n own(child, here, within);\n members(child.members, nested ? at : '', nested, within);\n }\n }\n };\n const group = (node: PrefGroup, at: string): void => {\n own(node, at, undefined);\n for (const [key, child] of Object.entries(node.children)) {\n if (isPrefLeaf(child)) leaf(child, under(at, key), undefined);\n else group(child, under(at, key));\n }\n };\n if (isPrefSection(schema)) {\n own(schema, '', undefined);\n members(schema.members, '', false, undefined);\n } else group(schema, '');\n return out;\n}\n","// A value held once per option of an enum leaf: the stored shape, and what\n// reads and rewrites it. Nothing here knows a schema; the store supplies the\n// options, the order, and how a member is repaired and blended.\n\nimport { isPlainObject } from '@weasel-js/registry';\n\n/**\n * A leaf's value split by another leaf: one member for each option of the\n * `enum` leaf at `$by`. A member may itself be a locus, by a second selector.\n * The alternatives are folded by weight when the value is read, and a plain\n * setting of the selector gives one of them all of it.\n */\nexport interface PrefLocus {\n /** The full path of the `enum` leaf whose options key `$of`. */\n $by: string;\n $of: Record<string, unknown>;\n}\n\n/** A value for each selector a read is made under: its path, then the option chosen. */\nexport type PrefSelection = Readonly<Record<string, string>>;\n\n/** A weight for each option of each selector, by the selector's path. An option left out weighs nothing. */\nexport type PrefWeights = Readonly<Record<string, Readonly<Record<string, number>>>>;\n\n/** One alternative of a split value, and its share of the whole. */\nexport interface PrefWeighted {\n value: unknown;\n weight: number;\n}\n\n/** Whether `value` is a {@link PrefLocus}: an object of exactly `$by` and `$of`. */\nexport function isPrefLocus(value: unknown): value is PrefLocus {\n if (!isPlainObject(value)) return false;\n const keys = Object.keys(value);\n return keys.length === 2 && typeof value.$by === 'string' && isPlainObject(value.$of);\n}\n\n/** The weights a plain selection amounts to: all of each selector's on the option chosen. */\nexport function selectionWeights(selection: PrefSelection): PrefWeights {\n return Object.fromEntries(Object.entries(selection).map(([path, option]) => [path, { [option]: 1 }]));\n}\n\nconst member = (locus: PrefLocus, option: string, absent: unknown): unknown =>\n (Object.hasOwn(locus.$of, option) ? locus.$of[option] : absent);\n\n/**\n * Every alternative of `stored` that weighs something under `weights`, each\n * with its share: the product of the weights on the way down to it. An option\n * the locus holds nothing for reads as `absent`. Members come in the order\n * `weights` lists each selector's options.\n */\nexport function weighLocus(stored: unknown, weights: PrefWeights, absent: unknown): PrefWeighted[] {\n const out: PrefWeighted[] = [];\n const walk = (value: unknown, weight: number): void => {\n if (!isPrefLocus(value)) {\n out.push({ value, weight });\n return;\n }\n for (const [option, share] of Object.entries(weights[value.$by] ?? {})) {\n if (share > 0) walk(member(value, option, absent), weight * share);\n }\n };\n walk(stored, 1);\n return out;\n}\n\n/** The one member `selection` names. A selector it leaves out, or an option the locus holds nothing for, reads as `absent`. */\nexport function memberAt(stored: unknown, selection: PrefSelection, absent: unknown): unknown {\n let value = stored;\n while (isPrefLocus(value)) {\n const option = selection[value.$by];\n if (option === undefined) return absent;\n value = member(value, option, absent);\n }\n return value;\n}\n\n/** `stored` with the member `selection` names replaced by `next`. A value that is not split is replaced whole. */\nexport function writeMember(stored: unknown, selection: PrefSelection, next: unknown): unknown {\n if (!isPrefLocus(stored)) return next;\n const option = selection[stored.$by];\n if (option === undefined) return stored;\n return { $by: stored.$by, $of: { ...stored.$of, [option]: writeMember(stored.$of[option], selection, next) } };\n}\n\n/**\n * `stored` split by the selector at `by`, every option starting as the value\n * it had. `order` is the leaf's `splitBy`: a selector earlier in it sits\n * outside a later one, so one meaning has one stored form.\n */\nexport function splitLocus(stored: unknown, by: string, options: readonly string[], order: readonly string[]): unknown {\n const across = (value: unknown): PrefLocus => ({ $by: by, $of: Object.fromEntries(options.map((option) => [option, value])) });\n if (!isPrefLocus(stored)) return across(stored);\n if (stored.$by === by) return stored;\n if (order.indexOf(stored.$by) > order.indexOf(by)) return across(stored);\n return mapMembers(stored, (inner) => splitLocus(inner, by, options, order));\n}\n\n/** `stored` no longer split by the selector at `by`: where it was, the member `selection` names stays. */\nexport function joinLocus(stored: unknown, by: string, selection: PrefSelection, absent: unknown): unknown {\n if (!isPrefLocus(stored)) return stored;\n if (stored.$by !== by) return mapMembers(stored, (inner) => joinLocus(inner, by, selection, absent));\n const option = selection[by];\n return option === undefined ? absent : member(stored, option, absent);\n}\n\nfunction mapMembers(locus: PrefLocus, fn: (member: unknown) => unknown): PrefLocus {\n let out: Record<string, unknown> | undefined;\n for (const [option, value] of Object.entries(locus.$of)) {\n const next = fn(value);\n if (next !== value) (out ??= { ...locus.$of })[option] = next;\n }\n return out ? { $by: locus.$by, $of: out } : locus;\n}\n\n/** `stored` with each alternative mapped, at any depth. The same value when no member changed. */\nexport function mapLocusMembers(stored: unknown, fn: (value: unknown) => unknown): unknown {\n return isPrefLocus(stored) ? mapMembers(stored, (inner) => mapLocusMembers(inner, fn)) : fn(stored);\n}\n\n/** The path of every selector `stored` is split by, outermost first. */\nexport function locusSelectors(stored: unknown): Set<string> {\n const out = new Set<string>();\n const walk = (value: unknown): void => {\n if (!isPrefLocus(value)) return;\n out.add(value.$by);\n for (const inner of Object.values(value.$of)) walk(inner);\n };\n walk(stored);\n return out;\n}\n\n/**\n * What a stored locus reads as: each member repaired, and a key that is none\n * of its selector's options left out. `undefined` when it is split by a\n * selector not in `allowed`, by one `optionsOf` has no options for, or by the\n * same one twice on the way to a member.\n */\nexport function repairLocus(\n stored: unknown,\n allowed: readonly string[],\n optionsOf: (path: string) => readonly string[] | undefined,\n repairMember: (value: unknown) => unknown,\n): unknown {\n const BAD = Symbol('bad');\n const walk = (value: unknown, met: readonly string[]): unknown => {\n if (!isPrefLocus(value)) return repairMember(value);\n const options = allowed.includes(value.$by) && !met.includes(value.$by) ? optionsOf(value.$by) : undefined;\n if (!options) return BAD;\n const of: Record<string, unknown> = {};\n for (const option of options) {\n if (!Object.hasOwn(value.$of, option)) continue;\n const read = walk(value.$of[option], [...met, value.$by]);\n if (read === BAD) return BAD;\n of[option] = read;\n }\n return { $by: value.$by, $of: of };\n };\n const read = walk(stored, []);\n return read === BAD ? undefined : read;\n}\n","// How the alternatives of a split value fold into one, by kind.\n\nimport { hexToRgba, interpolateSrgb, rgbaToHex } from '@weasel-js/paint';\nimport type { PrefWeighted } from './locus';\nimport type { PrefLeaf } from './schema';\n\n/**\n * Folds a split value's alternatives into the one value read. `members` holds\n * two or more, each weighing more than nothing, and their weights need not\n * sum to 1.\n */\nexport type PrefBlend = (members: readonly PrefWeighted[], leaf: PrefLeaf) => unknown;\n\n/** The first of the members that weigh the most. */\nconst heaviest: PrefBlend = (members) => members.reduce((most, m) => (m.weight > most.weight ? m : most)).value;\n\nconst blendNumber: PrefBlend = (members, leaf) => {\n let sum = 0;\n let total = 0;\n for (const { value, weight } of members) {\n if (typeof value !== 'number' || !Number.isFinite(value)) return heaviest(members, leaf);\n sum += value * weight;\n total += weight;\n }\n return sum / total;\n};\n\ntype Rgba = [number, number, number, number];\n\nconst blendColor: PrefBlend = (members, leaf) => {\n let mixed: Rgba | undefined;\n let total = 0;\n for (const { value, weight } of members) {\n let next: Rgba;\n try {\n next = hexToRgba(value as string);\n } catch {\n return heaviest(members, leaf);\n }\n total += weight;\n if (!mixed) {\n mixed = next;\n continue;\n }\n const t = weight / total;\n const [r, g, b] = interpolateSrgb([mixed[0], mixed[1], mixed[2]], [next[0], next[1], next[2]], t, 'oklch');\n mixed = [r, g, b, mixed[3] + (next[3] - mixed[3]) * t];\n }\n return rgbaToHex(mixed!);\n};\n\n/** The blends of the built-in kinds that have one. Every other kind takes its heaviest member. */\nexport const PREF_BLENDS: Readonly<Record<string, PrefBlend>> = { number: blendNumber, color: blendColor };\n\n/**\n * The value `members` fold into for `leaf`: the member itself where one holds\n * all the weight, the leaf's default where none weighs anything, and otherwise\n * what the kind's blend makes of them. `blends` is keyed by `kind`, and one\n * given for a built-in kind replaces that kind's own.\n */\nexport function blendPref(leaf: PrefLeaf, members: readonly PrefWeighted[], blends?: Readonly<Record<string, PrefBlend>>): unknown {\n if (members.length === 0) return leaf.default;\n if (members.length === 1) return members[0]!.value;\n const blend = (blends && Object.hasOwn(blends, leaf.kind) ? blends[leaf.kind] : undefined)\n ?? (Object.hasOwn(PREF_BLENDS, leaf.kind) ? PREF_BLENDS[leaf.kind] : undefined)\n ?? heaviest;\n return blend(members, leaf);\n}\n","// Which leaves a schema lets a value be split by, and what is wrong with a\n// `splitBy` that names something else: what a store warns of.\n\nimport type { PrefGroup } from './groups';\nimport { prefHoldsValue, prefLeaves } from './helpers';\nimport { locusSelectors } from './locus';\nimport type { PrefEnum, PrefLeaf } from './schema';\n\n/** One thing wrong with a leaf's `splitBy`. */\nexport interface PrefSplitProblem {\n code: 'valueless' | 'no-leaf' | 'not-enum' | 'encoded' | 'clearable' | 'split' | 'twice' | 'default';\n /** The path of the leaf whose `splitBy` it is. */\n at: string;\n /** The entry of `splitBy` the problem is with, where it is with one. */\n path?: string;\n problem: string;\n}\n\nconst refusal = (leaf: PrefLeaf | undefined): [PrefSplitProblem['code'], string] | undefined => {\n if (!leaf) return ['no-leaf', 'names no leaf'];\n if (leaf.kind !== 'enum') return ['not-enum', `names a ${leaf.kind} leaf, and only an enum has options to split by`];\n const selector = leaf as PrefEnum;\n if (selector.encoding) return ['encoded', 'names an enum with an encoding, whose stored value is not its option'];\n if (selector.clearable) return ['clearable', 'names a clearable enum, which may hold none of its options'];\n if (selector.splitBy?.length) return ['split', 'names a leaf that may itself be split'];\n return undefined;\n};\n\n/** The options of the leaf at each path some leaf of `leaves` may be split by, for the paths that can be. */\nexport function prefSelectors(leaves: ReadonlyMap<string, PrefLeaf>): Map<string, readonly string[]> {\n const out = new Map<string, readonly string[]>();\n for (const leaf of leaves.values()) {\n for (const path of leaf.splitBy ?? []) {\n const selector = leaves.get(path);\n if (out.has(path) || refusal(selector)) continue;\n out.set(path, (selector as PrefEnum).options.map((option) => option.value));\n }\n }\n return out;\n}\n\n/** Everything wrong with the `splitBy` lists of `schema`'s leaves, in schema order. */\nexport function checkPrefSplits(schema: PrefGroup): PrefSplitProblem[] {\n const leaves = prefLeaves(schema);\n const out: PrefSplitProblem[] = [];\n for (const [at, leaf] of leaves) {\n for (const path of locusSelectors(leaf.defaultLocus)) {\n if (leaf.splitBy?.includes(path)) continue;\n out.push({ code: 'default', at, path, problem: `its defaultLocus is split by \"${path}\", which its splitBy does not list` });\n }\n if (!leaf.splitBy?.length) continue;\n if (!prefHoldsValue(leaf)) {\n out.push({ code: 'valueless', at, problem: `a ${leaf.kind} leaf holds no value to split` });\n continue;\n }\n leaf.splitBy.forEach((path, i) => {\n if (leaf.splitBy!.indexOf(path) !== i) {\n out.push({ code: 'twice', at, path, problem: `\"${path}\" is listed twice` });\n return;\n }\n const why = refusal(leaves.get(path));\n if (why) out.push({ code: why[0], at, path, problem: `\"${path}\" ${why[1]}` });\n });\n }\n return out;\n}\n","import type { PrefBase, PrefObject } from './schema';\n\n/**\n * A leaf whose value is one of several object shapes, told apart by the\n * string its `tag` field holds: `{ type: 'linear', angle: 90 }` or\n * `{ type: 'radial', radius: 1 }` under `tag: 'type'`.\n *\n * Each variant is an `object` leaf keyed by its tag value. Its `children`\n * are the fields beside the tag, its `name` is what a person chooses, and\n * its `default` (without the tag) is what the value becomes when they choose\n * it. A stored value whose tag names no variant reads as the leaf's default.\n */\nexport interface PrefUnion extends PrefBase<'union', unknown> {\n tag: string;\n variants: Record<string, PrefObject>;\n}\n\n/** The variant `value` is, or `undefined` when its tag names none. */\nexport function prefVariantOf(leaf: PrefUnion, value: unknown): [key: string, variant: PrefObject] | undefined {\n if (value === null || typeof value !== 'object' || Array.isArray(value)) return undefined;\n const key = (value as Record<string, unknown>)[leaf.tag];\n if (typeof key !== 'string' || !Object.hasOwn(leaf.variants, key)) return undefined;\n return [key, leaf.variants[key]!];\n}\n\n/** The value a union takes on switching to the variant at `key`: that variant's default, tagged. */\nexport function prefVariantDefault(leaf: PrefUnion, key: string): Record<string, unknown> {\n const held = leaf.variants[key]?.default;\n const fields = held !== null && typeof held === 'object' ? (held as Record<string, unknown>) : {};\n return { ...fields, [leaf.tag]: key };\n}\n","import { isPlainObject } from '@weasel-js/registry';\nimport { prefSectionLeaves } from './helpers';\nimport type { PrefList } from './list';\nimport type { PrefMap } from './map';\nimport { prefVariantOf, type PrefUnion } from './union';\nimport type { PrefBoolean, PrefEnum, PrefLeaf, PrefNumber, PrefObject } from './schema';\n\n/** Decides what a stored value reads as for one kind of leaf: the value to\n * read, or `undefined` for \"invalid, read the default\". */\nexport type PrefValidator = (stored: unknown, leaf: PrefLeaf) => unknown;\n\n/** What `stored` reads as for `leaf`. Never writes anything back: a schema\n * rolled back finds the original still in storage. */\nexport function repairPrefValue(\n leaf: PrefLeaf,\n stored: unknown,\n validators?: Readonly<Record<string, PrefValidator>>,\n): unknown {\n if (leaf.kind === 'number') {\n if (stored === 'Infinity') stored = Infinity;\n else if (stored === '-Infinity') stored = -Infinity;\n }\n const validate = validators?.[leaf.kind];\n if (validate) {\n try {\n const out = validate(stored, leaf);\n return out === undefined ? leaf.default : out;\n } catch {\n return leaf.default;\n }\n }\n switch (leaf.kind) {\n case 'number':\n return repairNumber(leaf as PrefNumber, stored);\n case 'boolean':\n return (leaf as PrefBoolean).encoding || typeof stored === 'boolean' ? stored : leaf.default;\n case 'string':\n case 'color':\n case 'field':\n return typeof stored === 'string' ? stored : leaf.default;\n case 'enum': {\n const e = leaf as PrefEnum;\n if (e.encoding) return stored;\n return e.options.some((o) => o.value === stored) ? stored : leaf.default;\n }\n case 'object':\n if (isPlainObject(stored)) return repairFields(leaf as PrefObject, stored as Record<string, unknown>, validators);\n return (leaf as PrefObject).fromScalar ? stored : leaf.default;\n case 'map':\n return repairMap(leaf as PrefMap, stored, validators);\n case 'union': {\n const variant = prefVariantOf(leaf as PrefUnion, stored);\n return variant ? repairFields(variant[1], stored as Record<string, unknown>, validators) : leaf.default;\n }\n case 'list':\n return repairList(leaf as PrefList, stored, validators);\n default:\n return stored;\n }\n}\n\ntype Validators = Readonly<Record<string, PrefValidator>> | undefined;\n\n/**\n * Each field the object holds reads as its own leaf would. A field it omits\n * stays omitted: absent is a state of its own (no dash, no shadow), and not\n * the field at its default. Fields no leaf describes pass through.\n */\nfunction repairFields(leaf: PrefObject, stored: Record<string, unknown>, validators: Validators): unknown {\n let out: Record<string, unknown> | undefined;\n for (const [key, field] of prefSectionLeaves(leaf.children)) {\n if (!Object.hasOwn(stored, key) || stored[key] === undefined) continue;\n const read = repairPrefValue(field, stored[key], validators);\n if (read !== stored[key]) (out ??= { ...stored })[key] = read;\n }\n return out ?? stored;\n}\n\n/** Each value reads as `item` would on its own, under the key it was stored at. */\nfunction repairMap(leaf: PrefMap, stored: unknown, validators: Validators): unknown {\n if (!isPlainObject(stored)) return leaf.default;\n const held = stored as Record<string, unknown>;\n let out: Record<string, unknown> | undefined;\n for (const [key, value] of Object.entries(held)) {\n const read = repairPrefValue(leaf.item, value, validators);\n if (read !== value) (out ??= { ...held })[key] = read;\n }\n return out ?? stored;\n}\n\n/** Each entry reads as `item` would on its own, so one bad entry costs that entry and not the list. */\nfunction repairList(\n leaf: PrefList,\n stored: unknown,\n validators?: Readonly<Record<string, PrefValidator>>,\n): unknown {\n if (!Array.isArray(stored)) return leaf.default;\n if (leaf.minItems !== undefined && stored.length < leaf.minItems) return leaf.default;\n const kept = leaf.maxItems !== undefined && stored.length > leaf.maxItems ? stored.slice(0, leaf.maxItems) : stored;\n const read = kept.map((entry) => repairPrefValue(leaf.item, entry, validators));\n return kept === stored && read.every((entry, i) => entry === stored[i]) ? stored : read;\n}\n\n\nfunction repairNumber(leaf: PrefNumber, stored: unknown): unknown {\n if (typeof stored !== 'number' || Number.isNaN(stored)) return leaf.default;\n const { endless } = leaf;\n if (stored === Infinity && (endless === 'max' || endless === 'both')) return stored;\n if (stored === -Infinity && (endless === 'min' || endless === 'both')) return stored;\n let v = stored;\n if (leaf.min !== undefined && v < leaf.min) v = leaf.min;\n if (leaf.max !== undefined && v > leaf.max) v = leaf.max;\n return Number.isFinite(v) ? v : leaf.default;\n}\n","/**\n * How a pref is stored: its value, stamped with the schema version it was\n * written at. The stamp is what lets a record be migrated from its own\n * version, whatever the store's version record says by the time it is read.\n */\nexport interface StampedRecord {\n /** The schema version `value` is in the shape of. */\n $at: number;\n value: unknown;\n}\n\nconst isVersion = (v: unknown): v is number => typeof v === 'number' && Number.isInteger(v) && v >= 0;\n\nexport function stampRecord(value: unknown, at: number): StampedRecord {\n return { $at: at, value };\n}\n\nexport function isStampedRecord(record: unknown): record is StampedRecord {\n if (record === null || typeof record !== 'object') return false;\n const keys = Object.keys(record);\n return keys.length === 2 && Object.hasOwn(record, 'value') && isVersion((record as StampedRecord).$at);\n}\n\n/**\n * A stored record's value and the version it is in. One with no stamp was\n * written by a build from before records carried one, and is read as being\n * in `unstamped`, the version the store said it was at.\n */\nexport function readRecord(record: unknown, unstamped: number): { at: number; value: unknown; stamped: boolean } {\n return isStampedRecord(record)\n ? { at: record.$at, value: record.value, stamped: true }\n : { at: unstamped, value: record, stamped: false };\n}\n\n/** A stored record's value, whatever version it is in. */\nexport function recordValue(record: unknown): unknown {\n return isStampedRecord(record) ? record.value : record;\n}\n","import type { OwnedRecordCache } from '@weasel-js/storage';\nimport { VERSION_RECORD } from './helpers';\nimport { readRecord, stampRecord } from './stamp';\n\nconst isVersion = (v: unknown): v is number => typeof v === 'number' && Number.isInteger(v) && v >= 0;\n\n/** Takes stored values from one version to the next: rename, transform or\n * delete entries in `records`, keyed by leaf path. It sees the values, not\n * the stamps they are stored under, and only those at its own version. */\nexport type PrefsMigration = (records: Map<string, unknown>) => void;\n\n/**\n * Bring `cache` up to `migrations.length`, the current version. Each record\n * is migrated from the version it is stamped with, so one already in this\n * build's shape is left alone and one an older writer left is caught up,\n * whatever the store's version record says. A migration is handed the\n * records that are at its version; every one it leaves is written back\n * stamped with the version reached, so it may replace values or mutate them\n * in place. Stops writing, and writes nothing, when the store or a record is\n * newer than this build knows or a migration throws. Returns whether it wrote.\n *\n * `stampAll` also stamps the records that needed no migration and carry no\n * stamp. An open does that; a watcher does not, since an unstamped record\n * arriving from another writer may be in a version it has yet to announce.\n */\nexport function runPrefsMigrations(\n cache: OwnedRecordCache,\n migrations: readonly PrefsMigration[],\n { stampAll = true }: { stampAll?: boolean } = {},\n): boolean {\n const target = migrations.length;\n const raw = cache.get(VERSION_RECORD);\n if (cache.has(VERSION_RECORD) && !isVersion(raw)) {\n console.warn(\n `[prefs] \"${cache.prefix}\" has an unreadable ${VERSION_RECORD} (${JSON.stringify(raw)}); opening read-only`,\n );\n cache.stopWriting();\n return false;\n }\n const stored = cache.has(VERSION_RECORD) ? (raw as number) : 0;\n const held = cache\n .entries()\n .filter(([name]) => name !== VERSION_RECORD)\n .map(([name, record]) => ({ name, ...readRecord(record, Math.min(stored, target)) }));\n const newest = Math.max(stored, ...held.map((r) => r.at));\n if (newest > target) {\n console.warn(\n `[prefs] \"${cache.prefix}\" was written at version ${newest}, newer than this build's ${target}; opening read-only`,\n );\n cache.stopWriting();\n return false;\n }\n if (!cache.writable) return false;\n\n // Where each record now stands, and the records that are behind.\n const at = new Map(held.filter((r) => r.at < target).map((r) => [r.name, r.at]));\n const records = new Map(held.filter((r) => at.has(r.name)).map((r): [string, unknown] => [r.name, structuredClone(r.value)]));\n for (let v = Math.min(target, ...at.values()); v < target; v++) {\n const due = new Map([...records].filter(([name]) => at.get(name)! <= v));\n const before = [...due.keys()];\n try {\n migrations[v]!(due);\n } catch (error) {\n console.warn(\n `[prefs] migration ${v} → ${v + 1} for \"${cache.prefix}\" threw; opening read-only on the unmigrated records`,\n error,\n );\n cache.stopWriting();\n return false;\n }\n for (const name of before) if (!due.has(name)) records.delete(name);\n for (const [name, value] of due) {\n records.set(name, value);\n at.set(name, v + 1);\n }\n }\n let wrote = false;\n for (const r of held) {\n if (at.has(r.name)) {\n if (!records.has(r.name)) cache.delete(r.name);\n wrote = true;\n } else if (stampAll && !r.stamped) {\n cache.set(r.name, stampRecord(r.value, target));\n wrote = true;\n }\n }\n for (const [name, value] of records) {\n if (value === undefined) cache.delete(name);\n else cache.set(name, stampRecord(value, target));\n }\n if (stored !== target) {\n cache.set(VERSION_RECORD, target);\n wrote = true;\n }\n return wrote;\n}\n\n/**\n * Keep `cache` at this build's version while other writers change it. A\n * version past `migrations.length`, from a newer build in another tab, stops\n * persisting: this build would otherwise keep writing the old shape. A record\n * another writer leaves is migrated from the version it is stamped with, as\n * soon as it arrives; one with no stamp, from a build that wrote none, from\n * the version record that writer leaves with it. A version record another\n * writer deleted, a cleared store, is written back. Returns the unsubscribe.\n */\nexport function watchPrefsVersion(\n cache: OwnedRecordCache,\n migrations: readonly PrefsMigration[],\n): () => void {\n const target = migrations.length;\n // Once this cache has held a version, the records it holds are this\n // build's shape, and a missing version record is a cleared store.\n let versioned = cache.has(VERSION_RECORD);\n let stopped = false;\n const migrate = (): void => {\n const cleared = versioned && !cache.has(VERSION_RECORD);\n if (cleared) cache.set(VERSION_RECORD, target);\n else if (!runPrefsMigrations(cache, migrations, { stampAll: false })) return;\n versioned = true;\n void cache.flush();\n };\n // A late first read that finds nothing reports no change to migrate on.\n void cache.whenRead().then(() => {\n if (!stopped && cache.writable) migrate();\n });\n const heard = (version: unknown): void => {\n if (!isVersion(version)) {\n console.warn(\n `[prefs] \"${cache.prefix}\" has an unreadable ${VERSION_RECORD} (${JSON.stringify(version)}) from another writer; no longer persisting`,\n );\n cache.stopWriting();\n } else if (version > target) {\n console.warn(\n `[prefs] \"${cache.prefix}\" was migrated to version ${version} by another writer; this build knows ${target}; no longer persisting`,\n );\n cache.stopWriting();\n }\n };\n // A newer version counts even where this cache kept its own write over it.\n const stopOverruled = cache.onOverruled((changes) => {\n for (const [name, value] of changes) if (name === VERSION_RECORD && value !== undefined) heard(value);\n });\n const stopChanges = cache.subscribe((changes) => {\n const remote = changes.filter((change) => change.origin === 'remote');\n for (const change of remote) {\n if (change.name === VERSION_RECORD && change.value !== undefined) heard(change.value);\n }\n if (remote.length > 0 && cache.writable) migrate();\n versioned ||= cache.has(VERSION_RECORD);\n });\n return () => {\n stopped = true;\n stopOverruled();\n stopChanges();\n };\n}\n","// What a store reads at one moment: every leaf's stored value repaired, and\n// the value each resolves to under the selectors' own values. Rebuilt when a\n// record changes, reusing what it read from the records that did not.\n\nimport type { OwnedRecordCache } from '@weasel-js/storage';\nimport { blendPref, type PrefBlend } from './blend';\nimport { assignPrefValueAtPath } from './helpers';\nimport { isPrefLocus, locusSelectors, repairLocus, selectionWeights, weighLocus, type PrefLocus, type PrefSelection, type PrefWeights } from './locus';\nimport { type PrefValidator, repairPrefValue } from './repair';\nimport type { PrefLeaf } from './schema';\nimport { recordValue } from './stamp';\n\nexport interface Snapshot {\n /** Each leaf's value as read: a split one folded under `selection`. */\n byPath: Map<string, unknown>;\n /** Each leaf's stored value, repaired: a locus where it is split. */\n held: Map<string, unknown>;\n /** What each split leaf holds, by its path. */\n loci: ReadonlyMap<string, PrefLocus>;\n /** The option each selector is set to. */\n selection: PrefSelection;\n /** The leaves split by each selector, by the selector's path. */\n splitBy: Map<string, string[]>;\n tree: Record<string, unknown>;\n unset: ReadonlySet<string>;\n}\n\n/** What a store reads its snapshots from. */\nexport interface SnapshotSource {\n leaves: ReadonlyMap<string, PrefLeaf>;\n cache: OwnedRecordCache;\n /** The options of each leaf a value may be split by. */\n selectors: ReadonlyMap<string, readonly string[]>;\n validators?: Readonly<Record<string, PrefValidator>>;\n blends?: Readonly<Record<string, PrefBlend>>;\n}\n\n/** What `stored` reads as for `leaf`: a locus with each member repaired where the leaf may hold one, else the value repaired. */\nfunction readStored(source: SnapshotSource, leaf: PrefLeaf, stored: unknown): unknown {\n const repair = (value: unknown): unknown => repairPrefValue(leaf, value, source.validators);\n if (!leaf.splitBy?.length || !isPrefLocus(stored)) return repair(stored);\n const read = repairLocus(stored, leaf.splitBy, (path) => source.selectors.get(path), repair);\n return read === undefined ? leaf.default : read;\n}\n\n/** `held` folded under `weights`: itself where it is not split. */\nexport function resolveHeld(source: SnapshotSource, leaf: PrefLeaf, held: unknown, weights: PrefWeights): unknown {\n return isPrefLocus(held) ? blendPref(leaf, weighLocus(held, weights, leaf.default), source.blends) : held;\n}\n\n/** The store's snapshots: `current` builds one when there is none, and `drop` discards it when a record changed. */\nexport function createSnapshots(source: SnapshotSource): { current: () => Snapshot; peek: () => Snapshot | null; drop: () => void } {\n const { leaves, cache, selectors } = source;\n let snapshot: Snapshot | null = null;\n let previous: { raw: Map<string, unknown>; held: Map<string, unknown> } | null = null;\n\n const unsetLoci = new Map<string, unknown>();\n /** What an unset leaf holds: its split default, repaired once, where it has one. */\n const unsetHeld = (path: string, leaf: PrefLeaf): unknown => {\n if (leaf.defaultLocus === undefined) return leaf.default;\n if (!unsetLoci.has(path)) unsetLoci.set(path, readStored(source, leaf, leaf.defaultLocus));\n return unsetLoci.get(path);\n };\n\n const build = (): Snapshot => {\n const held = new Map<string, unknown>();\n const raw = new Map<string, unknown>();\n const unset = new Set<string>();\n for (const [path, leaf] of leaves) {\n if (!cache.has(path)) {\n held.set(path, unsetHeld(path, leaf));\n unset.add(path);\n continue;\n }\n const record = cache.get(path);\n raw.set(path, record);\n const same = previous?.raw.has(path) && previous.raw.get(path) === record;\n held.set(path, same ? previous!.held.get(path) : readStored(source, leaf, recordValue(record)));\n }\n previous = { raw, held };\n\n const selection: Record<string, string> = {};\n for (const path of selectors.keys()) selection[path] = held.get(path) as string;\n const weights = selectionWeights(selection);\n const byPath = new Map<string, unknown>();\n const splitBy = new Map<string, string[]>();\n const loci = new Map<string, PrefLocus>();\n const tree: Record<string, unknown> = {};\n for (const [path, leaf] of leaves) {\n const value = held.get(path);\n if (isPrefLocus(value)) loci.set(path, value);\n for (const selector of locusSelectors(value)) splitBy.set(selector, [...(splitBy.get(selector) ?? []), path]);\n const read = resolveHeld(source, leaf, value, weights);\n byPath.set(path, read);\n assignPrefValueAtPath(tree, path, read);\n }\n return { byPath, held, loci, selection, splitBy, tree, unset };\n };\n\n return {\n current: () => (snapshot ??= build()),\n peek: () => snapshot,\n drop: () => {\n snapshot = null;\n },\n };\n}\n\n/**\n * The weights a read is made under: `given` for each selector it names, the\n * options in the selector's own order, and all of every other selector's on\n * the option `selection` has it at.\n */\nexport function weightsUnder(\n selectors: ReadonlyMap<string, readonly string[]>,\n selection: PrefSelection,\n given: PrefWeights,\n): PrefWeights {\n const out: Record<string, Record<string, number>> = {};\n for (const [path, options] of selectors) {\n const own = Object.hasOwn(given, path) ? given[path] : undefined;\n out[path] = own\n ? Object.fromEntries(options.filter((option) => (own[option] ?? 0) > 0).map((option) => [option, own[option]!]))\n : { [selection[path]!]: 1 };\n }\n return out;\n}\n\n/** `selection` with each selector `at` names set to the option it gives, where that is one of the selector's. */\nexport function selectionAt(\n selectors: ReadonlyMap<string, readonly string[]>,\n selection: PrefSelection,\n at: PrefSelection,\n): PrefSelection {\n const out: Record<string, string> = { ...selection };\n for (const [path, option] of Object.entries(at)) {\n if (selectors.get(path)?.includes(option)) out[path] = option;\n }\n return out;\n}\n","// What a store writes: a value encoded for storage, into the member the\n// selectors name where the leaf is split, and a value split or joined.\n\nimport type { OwnedRecordCache } from '@weasel-js/storage';\nimport { prefSectionLeaves } from './helpers';\nimport type { PrefList } from './list';\nimport { isPrefLocus, joinLocus, mapLocusMembers, repairLocus, splitLocus, writeMember, type PrefSelection } from './locus';\nimport type { PrefMap } from './map';\nimport type { PrefLeaf, PrefObject } from './schema';\nimport { selectionAt } from './snapshot';\nimport { recordValue, stampRecord } from './stamp';\nimport { prefVariantOf, type PrefUnion } from './union';\n\n/** JSON storage cannot keep an infinity; `repairPrefValue` reads these back. */\nconst encodeInfinity = (leaf: PrefLeaf, value: unknown): unknown => {\n if (leaf.kind === 'number') return value === Infinity || value === -Infinity ? String(value) : value;\n if (leaf.kind === 'list' && Array.isArray(value)) {\n const { item } = leaf as PrefList;\n return value.map((entry) => encodeInfinity(item, entry));\n }\n if (value === null || typeof value !== 'object' || Array.isArray(value)) return value;\n const held = value as Record<string, unknown>;\n if (leaf.kind === 'map') {\n const { item } = leaf as PrefMap;\n return Object.fromEntries(Object.entries(held).map(([key, entry]) => [key, encodeInfinity(item, entry)]));\n }\n const fields = leaf.kind === 'union' ? prefVariantOf(leaf as PrefUnion, held)?.[1] : leaf;\n if (fields?.kind !== 'object') return value;\n let out: Record<string, unknown> | undefined;\n for (const [key, field] of prefSectionLeaves((fields as PrefObject).children)) {\n if (!Object.hasOwn(held, key)) continue;\n const encoded = encodeInfinity(field, held[key]);\n if (encoded !== held[key]) (out ??= { ...held })[key] = encoded;\n }\n return out ?? value;\n};\n\n/** What the writes of a store are made over. */\nexport interface PrefWritesSource {\n leaves: ReadonlyMap<string, PrefLeaf>;\n cache: OwnedRecordCache;\n /** The options of each leaf a value may be split by. */\n selectors: ReadonlyMap<string, readonly string[]>;\n /** The schema version a value written is in, stamped on its record. */\n version: number;\n /** The option each selector is set to, read as a write is made. */\n selection: () => PrefSelection;\n warnIfClosed: (path: string | undefined) => void;\n}\n\n/** A store's `set`, `split`, and `join`. */\nexport function prefWrites({ leaves, cache, selectors, version, selection, warnIfClosed }: PrefWritesSource): {\n set: (path: string, value: unknown, write?: { at?: PrefSelection }) => void;\n split: (path: string, by: string) => void;\n join: (path: string, by: string) => void;\n} {\n /** The leaf's split default as stored, where it has one it can hold. */\n const unsetLocus = (leaf: PrefLeaf): unknown => {\n if (leaf.defaultLocus === undefined || !leaf.splitBy?.length) return undefined;\n return repairLocus(leaf.defaultLocus, leaf.splitBy, (by) => selectors.get(by), (member) => encodeInfinity(leaf, member));\n };\n /** What the leaf holds in storage, unrepaired; its default, as stored, where it holds nothing. */\n const rawAt = (path: string, leaf: PrefLeaf): unknown =>\n (cache.has(path) ? recordValue(cache.get(path)) : unsetLocus(leaf) ?? encodeInfinity(leaf, leaf.default));\n const store = (path: string, stored: unknown): void => {\n // Unset is stored as nothing, which a stamp would turn into something.\n cache.set(path, stored === undefined ? undefined : stampRecord(stored, version));\n };\n /** The leaf and the selector's options, for a leaf that may be split by it. */\n const splitOf = (path: string, by: string): { leaf: PrefLeaf; options: readonly string[] } | undefined => {\n warnIfClosed(path);\n const leaf = leaves.get(path);\n const options = selectors.get(by);\n if (leaf?.splitBy?.includes(by) && options) return { leaf, options };\n console.warn(`[prefs] \"${path}\" cannot be split by \"${by}\"; ignoring`);\n return undefined;\n };\n\n const set = (path: string, value: unknown, write?: { at?: PrefSelection }): void => {\n warnIfClosed(path);\n const leaf = leaves.get(path);\n if (!leaf) {\n console.warn(`[prefs] no leaf at \"${path}\"; ignoring the write`);\n return;\n }\n if (leaf.splitBy?.length && isPrefLocus(value)) {\n store(path, mapLocusMembers(value, (member) => encodeInfinity(leaf, member)));\n return;\n }\n const stored = encodeInfinity(leaf, value);\n const had = cache.has(path) ? recordValue(cache.get(path)) : unsetLocus(leaf);\n const intoMember = stored !== undefined && leaf.splitBy?.length && isPrefLocus(had);\n const under = write?.at ? selectionAt(selectors, selection(), write.at) : selection();\n store(path, intoMember ? writeMember(had, under, stored) : stored);\n };\n const split = (path: string, by: string): void => {\n const found = splitOf(path, by);\n if (!found) return;\n const had = rawAt(path, found.leaf);\n const next = splitLocus(had, by, found.options, found.leaf.splitBy!);\n if (next !== had) store(path, next);\n };\n const join = (path: string, by: string): void => {\n const found = splitOf(path, by);\n if (!found) return;\n const had = rawAt(path, found.leaf);\n const next = joinLocus(had, by, selection(), encodeInfinity(found.leaf, found.leaf.default));\n if (next !== had) store(path, next);\n };\n return { set, split, join };\n}\n","import { createEmitter } from '@weasel-js/registry';\nimport type { OwnedRecordCache } from '@weasel-js/storage';\nimport type { PrefBlend } from './blend';\nimport { checkPrefConditions } from './conditionCheck';\nimport { recordValue } from './stamp';\nimport { assignPrefValueAtPath, prefHoldsValue, prefLeaves, setOwnPrefValue, VERSION_RECORD } from './helpers';\nimport { isPrefLocus, selectionWeights, type PrefLocus, type PrefSelection, type PrefWeights } from './locus';\nimport { createSnapshots, resolveHeld, selectionAt, weightsUnder, type SnapshotSource } from './snapshot';\nimport { checkPrefSplits, prefSelectors } from './splitCheck';\nimport type { PrefPath, PrefValueAt } from './paths';\nimport type { PrefValidator } from './repair';\nimport type { PrefGroup } from './groups';\nimport { prefWrites } from './storeWrites';\n\n/** One leaf changing, as a store subscriber hears it: the value readers now\n * see, and whether this store or another writer made the change. */\nexport interface PrefChange {\n path: string;\n value: unknown;\n origin: 'local' | 'remote';\n}\n\n/** Values for one schema, held in memory and persisted behind. */\nexport interface PrefsStore<S extends PrefGroup> {\n readonly schema: S;\n /**\n * The leaf's value, repaired against the schema; its default when unset. A\n * split value is folded: under the selectors' own values it is the member\n * they name, and under `weights` it is the blend its kind makes of the\n * members that weigh something. A selector `weights` leaves out keeps its\n * own value.\n */\n get<P extends PrefPath<S>>(path: P, read?: { weights?: PrefWeights }): PrefValueAt<S, P>;\n /** On a split leaf, writes the member the selectors' own values name, or\n * with `at` the one named with each selector there set to the option given.\n * A {@link PrefLocus} given as the value replaces the whole of what is held. */\n set<P extends PrefPath<S>>(path: P, value: PrefValueAt<S, P> | PrefLocus, write?: { at?: PrefSelection }): void;\n /** Hold the leaf's value once per option of the selector at `by`, one of\n * the leaf's `splitBy`, each option starting as the value it had. */\n split(path: PrefPath<S>, by: string): void;\n /** Stop splitting the leaf's value by the selector at `by`, keeping the\n * member that selector's own value names. */\n join(path: PrefPath<S>, by: string): void;\n /** What the leaf holds where its value is split, each member repaired. */\n locus(path: PrefPath<S>): PrefLocus | undefined;\n /** What every split leaf holds, by its path. The same map until something changes. */\n loci(): ReadonlyMap<string, PrefLocus>;\n /** Unset every leaf at or under `path`; with no path, all. */\n reset(path?: string): void;\n /** Whether the leaf has a value of its own rather than following its default. */\n isSet(path: PrefPath<S>): boolean;\n /** Every leaf's value as a nested tree. The same object until something\n * changes. With `at`, the tree as it would read with each selector named\n * there set to the option given, built for the call. */\n values(read?: { at?: PrefSelection }): Record<string, unknown>;\n /** The leaves following their default. The same set until something changes. */\n unset(): ReadonlySet<string>;\n /** Every stored record as a nested tree, unrepaired, including records no\n * leaf describes. The same object until something changes. */\n stored(): Record<string, unknown>;\n /** `changes` is empty when only records no leaf describes changed. A\n * selector changing is a change to every leaf split by it. */\n subscribe(listener: (changes: PrefChange[]) => void): () => void;\n /** False while the store cannot persist: storage has not been read yet, or\n * was written by a newer schema. Changes still apply for this session, and\n * ones made before a late read lands are persisted when it does. False for\n * good once the store is closed. */\n readonly writable: boolean;\n /** True once `close` was called. A write after that changes what this store\n * reads and reaches neither storage nor its subscribers, and the first one\n * warns. */\n readonly closed: boolean;\n /** Try again now to read storage that could not be read at open, ahead of\n * the store's own retries. Resolves whether storage has been read. */\n read(): Promise<boolean>;\n /** Resolves once storage has been read: at once for a store that opened\n * with its values, and when a later read lands for one that could not. */\n whenRead(): Promise<void>;\n /** Resolves true when every queued write reached storage. */\n flush(): Promise<boolean>;\n close(): Promise<void>;\n}\n\n/** Every record of `cache` but the version's, as a nested tree of unrepaired values. */\nfunction storedRecords(cache: OwnedRecordCache): Record<string, unknown> {\n const tree: Record<string, unknown> = {};\n const branches = new WeakSet<object>([tree]);\n for (const [name, record] of cache.entries()) {\n if (name === VERSION_RECORD) continue;\n const value = recordValue(record);\n const parts = name.split('.');\n let cursor = tree;\n for (const part of parts.slice(0, -1)) {\n const next = cursor[part];\n // A record's own value is never descended into: one named `a` and\n // another `a.b` cannot both show, and the branch wins.\n if (typeof next === 'object' && next !== null && branches.has(next)) {\n cursor = next as Record<string, unknown>;\n } else {\n const branch: Record<string, unknown> = {};\n branches.add(branch);\n setOwnPrefValue(cursor, part, branch);\n cursor = branch;\n }\n }\n const last = parts[parts.length - 1]!;\n if (!branches.has(cursor[last] as object)) setOwnPrefValue(cursor, last, value);\n }\n return tree;\n}\n\n/** A store over an open cache. `openPrefs` / `openPrefsSync` are the usual\n * way in; they run migrations first. */\nexport function createPrefsStore<S extends PrefGroup>(\n schema: S,\n cache: OwnedRecordCache,\n validators?: Readonly<Record<string, PrefValidator>>,\n onClose?: () => void,\n /** The schema version a value set here is in, stamped on its record. */\n version = 0,\n blends?: Readonly<Record<string, PrefBlend>>,\n): PrefsStore<S> {\n const leaves = new Map([...prefLeaves(schema)].filter(([, leaf]) => prefHoldsValue(leaf)));\n for (const { field, at, problem } of checkPrefConditions(schema)) {\n console.warn(`[prefs] ${field} of ${at === '' ? 'the schema' : `\"${at}\"`}: ${problem}`);\n }\n for (const { at, problem } of checkPrefSplits(schema)) console.warn(`[prefs] splitBy of \"${at}\": ${problem}`);\n const source: SnapshotSource = { leaves, cache, selectors: prefSelectors(leaves), validators, blends };\n const { current, peek, drop } = createSnapshots(source);\n\n let storedTree: Record<string, unknown> | null = null;\n\n let changed = createEmitter<[PrefChange[]]>();\n const stopCache = cache.subscribe((changes) => {\n const records = changes.filter((c) => c.name !== VERSION_RECORD);\n if (records.length === 0) return;\n storedTree = null;\n const mine = records.filter((c) => leaves.has(c.name));\n const before = peek();\n if (mine.length > 0) drop();\n const now = current();\n const origins = new Map(mine.map((c) => [c.name, c.origin]));\n for (const c of mine) {\n for (const path of [...(before?.splitBy.get(c.name) ?? []), ...(now.splitBy.get(c.name) ?? [])]) {\n if (!origins.has(path)) origins.set(path, c.origin);\n }\n }\n changed.emit([...origins].map(([path, origin]): PrefChange => ({ path, value: now.byPath.get(path), origin })));\n });\n\n let closed = false;\n let warned = false;\n const warnIfClosed = (path: string | undefined): void => {\n if (!closed || warned) return;\n warned = true;\n console.warn(`[prefs] write to a closed store${path === undefined ? '' : ` at \"${path}\"`}; it will not persist`);\n };\n return {\n schema,\n ...prefWrites({ leaves, cache, selectors: source.selectors, version, selection: () => current().selection, warnIfClosed }),\n get: (path, read) => {\n const now = current();\n if (!read?.weights) return now.byPath.get(path) as never;\n const leaf = leaves.get(path);\n const weights = weightsUnder(source.selectors, now.selection, read.weights);\n return (leaf ? resolveHeld(source, leaf, now.held.get(path), weights) : undefined) as never;\n },\n locus: (path) => {\n const held = current().held.get(path);\n return isPrefLocus(held) ? held : undefined;\n },\n loci: () => current().loci,\n reset: (path) => {\n warnIfClosed(path);\n for (const p of leaves.keys()) {\n if (path === undefined || p === path || p.startsWith(`${path}.`)) cache.delete(p);\n }\n },\n isSet: (path) => cache.has(path),\n values: (read) => {\n const now = current();\n if (!read?.at) return now.tree;\n const selection = selectionAt(source.selectors, now.selection, read.at);\n const weights = selectionWeights(selection);\n const tree: Record<string, unknown> = {};\n for (const [path, leaf] of leaves) {\n const set = source.selectors.has(path) ? selection[path] : resolveHeld(source, leaf, now.held.get(path), weights);\n assignPrefValueAtPath(tree, path, set);\n }\n return tree;\n },\n unset: () => current().unset,\n stored: () => (storedTree ??= storedRecords(cache)),\n subscribe: (listener) => changed.subscribe(listener),\n get writable() {\n return !closed && cache.writable;\n },\n get closed() {\n return closed;\n },\n read: () => cache.read(),\n whenRead: () => cache.whenRead(),\n flush: () => cache.flush(),\n close: async () => {\n closed = true;\n onClose?.();\n stopCache();\n changed = createEmitter();\n await cache.close();\n },\n };\n}\n","import {\n openRecords,\n openRecordsSync,\n type OwnedRecordCache,\n type StorageAdapter,\n type SyncStorageAdapter,\n} from '@weasel-js/storage';\nimport type { PrefBlend } from './blend';\nimport { type PrefsMigration, runPrefsMigrations, watchPrefsVersion } from './migrate';\nimport type { PrefValidator } from './repair';\nimport type { PrefGroup } from './groups';\nimport { createPrefsStore, type PrefsStore } from './store';\n\n/** Options for `openPrefs` and `openPrefsSync`. */\nexport interface PrefsOptions {\n storage: StorageAdapter;\n /** Prepended to every record's key: `'myapp.prefs.'`. */\n prefix: string;\n /** `migrations[i]` takes stored records from version `i` to `i + 1`. The\n * current version is `migrations.length`. */\n migrations?: readonly PrefsMigration[];\n /** Validators for app-defined kinds, keyed by `kind`. One given for a\n * built-in kind replaces that kind's own rule. */\n validators?: Readonly<Record<string, PrefValidator>>;\n /** How a split value's alternatives fold into one for app-defined kinds,\n * keyed by `kind`. One given for a built-in kind replaces that kind's\n * own. A kind with none takes its heaviest alternative. */\n blends?: Readonly<Record<string, PrefBlend>>;\n}\n\n/** Load every stored value for `schema`, migrate it, and return the store. */\nexport async function openPrefs<S extends PrefGroup>(\n schema: S,\n options: PrefsOptions,\n): Promise<PrefsStore<S>> {\n const cache = await openRecords({ storage: options.storage, prefix: options.prefix });\n const stop = watch(cache, options);\n if (runPrefsMigrations(cache, options.migrations ?? [])) await cache.flush();\n return createPrefsStore(schema, cache, options.validators, stop, options.migrations?.length ?? 0, options.blends);\n}\n\n/** `openPrefs` for an adapter that reads synchronously: the store is ready\n * on return, so values can be read before anything renders. */\nexport function openPrefsSync<S extends PrefGroup>(\n schema: S,\n options: PrefsOptions & { storage: SyncStorageAdapter },\n): PrefsStore<S> {\n const { cache, stop } = openPrefsCacheSync(options);\n return createPrefsStore(schema, cache, options.validators, stop, options.migrations?.length ?? 0, options.blends);\n}\n\n/** The migrated cache `openPrefsSync` builds its store over, and what stops\n * its version watch. */\nexport function openPrefsCacheSync(\n options: PrefsOptions & { storage: SyncStorageAdapter },\n): { cache: OwnedRecordCache; stop: () => void } {\n const cache = openRecordsSync({ storage: options.storage, prefix: options.prefix });\n const stop = watch(cache, options);\n if (runPrefsMigrations(cache, options.migrations ?? [])) void cache.flush();\n return { cache, stop };\n}\n\n/** Attached before migrations run, so a peer's version bump during the open's\n * own flush is heard, and on an unread cache too, whose late read reports\n * its records' version the same way. */\nconst watch = (cache: OwnedRecordCache, options: PrefsOptions): (() => void) =>\n watchPrefsVersion(cache, options.migrations ?? []);\n"]}