@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.
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/alias.ts","../src/helpers.ts","../src/object.ts","../src/union.ts","../src/type.ts","../src/groups.ts","../src/stamp.ts","../src/migrate.ts","../src/repair.ts","../src/store.ts","../src/open.ts","../src/kinds.ts","../src/schema.ts"],"names":["isVersion"],"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;AAGO,SAAS,eAAA,CAAgB,OAAkB,MAAA,EAA4B;AAC5E,EAAA,OAAO;AAAA,IACL,GAAG,MAAA;AAAA,IACH,MAAM,KAAA,CAAM,IAAA,KAAS,EAAA,GAAK,MAAA,CAAO,OAAO,KAAA,CAAM,IAAA;AAAA,IAC9C,aAAa,KAAA,CAAM,WAAA,KAAgB,EAAA,GAAK,MAAA,CAAO,cAAc,KAAA,CAAM;AAAA,GACrE;AACF;;;AC5BO,SAAS,kBACd,CAAA,EAC8C;AAC9C,EAAA,IAAI,CAAC,CAAA,CAAE,IAAA,EAAM,OAAO,EAAE,GAAA,EAAK,CAAA,CAAE,GA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,IAAA,CAAK,GAAA,CAAI,IAAI,CAAA,EAAG;AAClC,IAAA,MAAM,GAAA,GAAM,EAAE,GAAA,EAAK,IAAA,EAAM,OAAO,IAAA,CAAK,IAAA,CAAK,KAAA,IAAS,IAAA,CAAK,IAAA,EAAK;AAC7D,IAAA,IAAA,CAAK,GAAA,CAAI,MAAM,GAAG,CAAA;AAClB,IAAA,MAAM,QAAA,GAAW,OAAO,IAAA,CAAK,IAAA,CAAK,IAAA,KAAS,QAAA,GAAW,CAAC,IAAA,CAAK,IAAA,CAAK,IAAI,CAAA,GAAI,IAAA,CAAK,IAAA,CAAK,IAAA;AACnF,IAAA,KAAA,MAAW,OAAA,IAAW,QAAA,EAAU,IAAI,CAAC,IAAA,CAAK,GAAA,CAAI,OAAO,CAAA,EAAG,IAAA,CAAK,GAAA,CAAI,OAAA,EAAS,GAAG,CAAA;AAAA,EAC/E;AACA,EAAA,OAAO,IAAA;AACT;AAQO,SAAS,cAAc,IAAA,EAAqC;AACjE,EAAA,OAAO,MAAA,CAAO,MAAA,CAAO,UAAA,EAAY,IAAA,CAAK,IAAI,CAAA;AAC5C","file":"index.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/** 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: alias.name === '' ? target.name : alias.name,\n description: alias.description === '' ? target.description : alias.description,\n };\n}\n","import { prefAliasedLeaf, prefAliasTarget, type PrefAlias } from './alias';\nimport type { PrefGroup, PrefSection } from './groups';\nimport type { PrefLeaf, PrefNumber, PrefObject } from './schema';\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 } = 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 — a reader who typed\n * the group's name is asking for the group, not for leaves repeating it.\n *\n * An empty or whitespace query matches everything, so a cleared field restores\n * the tree rather than emptying it.\n *\n * An alias answers as the row it draws: its target's name and description\n * where it gives none. `leafAt` finds that target, and defaults to looking in\n * `node`; pass one over 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 leafAt?: (path: string) => PrefLeaf | undefined,\n): T | null {\n const q = query.trim().toLowerCase();\n if (q === '') return node;\n const find = leafAt ?? ((p: string) => (isPrefLeaf(node) ? undefined : prefLeafAt(node as PrefGroup, 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}`, find);\n if (kept) children[key] = kept;\n }\n if (Object.keys(children).length === 0) return null;\n return { ...node, children };\n}\n","import type { PrefObject } from './schema';\n\nconst isObject = (v: unknown): v is Record<string, unknown> => typeof v === 'object' && v !== null;\n\n/**\n * The object a write to one field of an `object` leaf starts from: `held` itself where it is one. Where it is\n * not, the write has to make a whole object, so it starts from the scalar lifted by the leaf's `fromScalar`, else\n * from the leaf's `default`: one field on its own is a stroke with a width and no paint.\n */\nexport function prefObjectBase(pref: PrefObject, held: unknown): Record<string, unknown> {\n if (isObject(held)) return held;\n return pref.fromScalar?.(held) ?? (isObject(pref.default) ? pref.default : {});\n}\n\n/** The object an `object` leaf holds after one of its fields is set: {@link prefObjectBase} with `key` at\n * `value`, or without the key for `undefined`. */\nexport function prefObjectWithField(pref: PrefObject, held: unknown, key: string, value: unknown): Record<string, unknown> {\n const base = prefObjectBase(pref, held);\n if (value !== undefined) return { ...base, [key]: value };\n const { [key]: _dropped, ...rest } = base;\n return rest;\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 type { PrefLeaf } from './schema';\n\n/**\n * `leaf` as a named type: the same leaf carrying `name` in its `type` field.\n * Declared once beside the code that reads its value and used wherever a\n * schema wants one, spread with what that place sets for itself\n * (`{ ...GradientStop, name: 'First stop' }`), or as a list's or a map's\n * `item`. `name` is the identifier the type is exported under, which a schema\n * editor prints in place of the leaf's literal.\n */\nexport function prefType<L extends PrefLeaf>(name: string, leaf: L): L & { type: string } {\n return { ...leaf, type: name };\n}\n","// The two branch nodes of a schema. They differ in whether a key is part of\n// the path a leaf's value lives at, and each holds its members under its own\n// property, so a schema of one kind is neither assignable to nor walkable as\n// the other.\n\nimport type { PrefLeaf } from './schema';\n\n/**\n * How a {@link PrefGroup} is drawn: `page` gets an entry in a form's rail and\n * a pane of its own; `tab` shares a tab strip with the `tab` groups beside it;\n * `panel` is a bordered, titled box; `section` is a heading over its rows;\n * `fragment` draws nothing of its own, so its rows sit among its neighbors'\n * as though they were written there. A fragment exists to hold things\n * together: one key for their values to nest under, one node to move.\n */\nexport type PrefGroupAs = 'page' | 'tab' | 'panel' | 'section' | 'fragment' | 'bar';\n\n/** How a {@link PrefSection} is drawn. */\nexport type PrefSectionAs = Exclude<PrefGroupAs, 'page'>;\n\n/**\n * A group whose key is a path segment: `view` > `gridDensity` is the leaf at\n * `view.gridDensity`, and its value nests the same way. The shape of a\n * preferences schema — what `openPrefs` stores, `PrefsForm` renders, and a\n * tool declares its options as. A key holds no `.`.\n */\nexport interface PrefGroup {\n /** Heading for the group's rows. **Empty means no heading** — for a group\n * that exists to organize, not to name: one whose children are themselves\n * groups carrying the labels a reader needs. Give it a name whenever the\n * name is the referent (a `Border` group over `Top` / `Right` / `Bottom`\n * reads as nothing without it). */\n name: string;\n description?: string;\n /** How the group is drawn. Unset, its depth decides: a top-level group is a\n * `page`, and one inside another is a `section`. */\n as?: PrefGroupAs;\n children: Record<string, PrefLeaf | PrefGroup>;\n}\n\n/**\n * A heading over leaves that adds nothing to their paths: each member is\n * addressed by its own key alone, and the section's key only identifies the\n * section. The shape of a node's property schema, where a leaf's key is the\n * whole dotted node path (`pose.x`, `data.fill`), and of the headings inside\n * a {@link PrefObject}, where a key is relative to the object.\n */\nexport interface PrefSection {\n /** Heading for the section's rows. Empty means no heading, as for a\n * {@link PrefGroup}. */\n name: string;\n description?: string;\n /** How the section is drawn, as a {@link PrefGroup}'s `as` — without\n * `page`, since nothing that draws sections has a rail. Unset: a heading\n * over its rows. */\n as?: PrefSectionAs;\n members: Record<string, PrefLeaf | PrefSection>;\n}\n\n/** Whether a top-level group gets a page of its own, and not a place on the page of the root's own leaves. */\nexport function prefGroupIsPage(group: PrefGroup): boolean {\n return group.as === undefined || group.as === 'page';\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","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","import type { OwnedRecordCache } from '@weasel-js/storage';\nimport { recordValue, stampRecord } from './stamp';\nimport { assignPrefValueAtPath, prefHoldsValue, prefLeaves, prefSectionLeaves, setOwnPrefValue, VERSION_RECORD } from './helpers';\nimport type { PrefList } from './list';\nimport type { PrefMap } from './map';\nimport type { PrefPath, PrefValueAt } from './paths';\nimport { type PrefValidator, repairPrefValue } from './repair';\nimport type { PrefGroup } from './groups';\nimport type { PrefLeaf, PrefObject } from './schema';\nimport { prefVariantOf, type PrefUnion } from './union';\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 /** The leaf's value, repaired against the schema; its default when unset. */\n get<P extends PrefPath<S>>(path: P): PrefValueAt<S, P>;\n set<P extends PrefPath<S>>(path: P, value: PrefValueAt<S, P>): void;\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 changes. */\n values(): 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. */\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. */\n readonly writable: 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\ninterface Snapshot {\n byPath: Map<string, unknown>;\n tree: Record<string, unknown>;\n unset: ReadonlySet<string>;\n}\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/** 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): PrefsStore<S> {\n const leaves = new Map([...prefLeaves(schema)].filter(([, leaf]) => prefHoldsValue(leaf)));\n let snapshot: Snapshot | null = null;\n let previous: { raw: Map<string, unknown>; byPath: Map<string, unknown> } | null = null;\n\n const build = (): Snapshot => {\n const byPath = new Map<string, unknown>();\n const raw = new Map<string, unknown>();\n const unset = new Set<string>();\n const tree: Record<string, unknown> = {};\n for (const [path, leaf] of leaves) {\n const has = cache.has(path);\n let value: unknown;\n if (!has) {\n value = leaf.default;\n unset.add(path);\n } else {\n const record = cache.get(path);\n const stored = recordValue(record);\n raw.set(path, record);\n value =\n previous?.raw.has(path) && previous.raw.get(path) === record\n ? previous.byPath.get(path)\n : repairPrefValue(leaf, stored, validators);\n }\n byPath.set(path, value);\n assignPrefValueAtPath(tree, path, value);\n }\n previous = { raw, byPath };\n return { byPath, tree, unset };\n };\n const current = (): Snapshot => (snapshot ??= build());\n\n let storedTree: Record<string, unknown> | null = null;\n const buildStored = (): 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 const listeners = new Set<(changes: PrefChange[]) => void>();\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 if (mine.length > 0) snapshot = null;\n const now = current();\n const out = mine.map((c): PrefChange => ({ path: c.name, value: now.byPath.get(c.name), origin: c.origin }));\n for (const listener of [...listeners]) listener(out);\n });\n\n return {\n schema,\n get: (path) => current().byPath.get(path) as never,\n set: (path, value) => {\n const leaf = leaves.get(path);\n if (!leaf) {\n console.warn(`[prefs] no leaf at \"${path}\"; ignoring the write`);\n return;\n }\n const stored = encodeInfinity(leaf, value);\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 reset: (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: () => current().tree,\n unset: () => current().unset,\n stored: () => (storedTree ??= buildStored()),\n subscribe: (listener) => {\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n };\n },\n get writable() {\n return cache.writable;\n },\n read: () => cache.read(),\n whenRead: () => cache.whenRead(),\n flush: () => cache.flush(),\n close: async () => {\n onClose?.();\n stopCache();\n listeners.clear();\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 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}\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);\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 = openRecordsSync({ storage: options.storage, prefix: options.prefix });\n const stop = watch(cache, options);\n if (runPrefsMigrations(cache, options.migrations ?? [])) void cache.flush();\n return createPrefsStore(schema, cache, options.validators, stop, options.migrations?.length ?? 0);\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","import type { PrefKind } from './schema';\n\n/** What a surface has to know about a kind before it can lay its control out. */\nexport interface PrefKindTraits {\n /** Its value is made of other leaves' values: too much for one control on a\n * line, so a bar opens it in a popover and a compact panel in a dialog. */\n compound: boolean;\n /** Its control is several controls, or a button. A row drawn as a `<label>`\n * would hand a click on its text to the first of them. */\n several: boolean;\n}\n\nconst ONE: PrefKindTraits = { compound: false, several: false };\nconst MANY: PrefKindTraits = { compound: true, several: true };\n\n/**\n * The traits of every built-in kind. A `Record` over {@link PrefKind}, so a\n * kind added to the union does not compile until it says what it is here:\n * a plain set of kind names lets a new one through to draw inline in a\n * `<label>`, on a bar's line, and with no dialog row.\n */\nexport const PREF_KIND_TRAITS: Record<PrefKind, PrefKindTraits> = {\n number: ONE,\n boolean: ONE,\n string: ONE,\n enum: ONE,\n color: ONE,\n paint: ONE,\n object: MANY,\n list: MANY,\n map: MANY,\n union: MANY,\n field: ONE,\n action: { compound: false, several: true },\n alias: ONE,\n label: ONE,\n separator: ONE,\n};\n\nconst traitsOf = (leaf: { kind: string }): PrefKindTraits =>\n (Object.hasOwn(PREF_KIND_TRAITS, leaf.kind) ? PREF_KIND_TRAITS[leaf.kind as PrefKind] : ONE);\n\n/** Whether a leaf's value is made of other leaves' values. An app-defined kind is not: its renderer is one control. */\nexport function prefIsCompound(leaf: { kind: string }): boolean {\n return traitsOf(leaf).compound;\n}\n\n/** Whether a leaf's control is several controls or a button. */\nexport function prefDrawsSeveral(leaf: { kind: string }): boolean {\n return traitsOf(leaf).several;\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 { formatUnit, unitScale } from '@weasel-js/quantity';\nimport type { PrefAction } from './action';\nimport type { PrefAlias } from './alias';\nimport type { PrefSection } from './groups';\nimport type { PrefLabel, PrefSeparator } from './label';\nimport type { PrefList } from './list';\nimport type { PrefMap } from './map';\nimport type { PrefUnion } from './union';\nimport type { Display, InfinityText, Unit, UnitEntry, UnitScale, UnitSystem } 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/**\n * Leaves that share one row in a compact property UI (weasel-ui\n * `SelectionPanel`, labkit's `ControlPanel`), declared on the first of them.\n * Purely presentational.\n */\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 /** 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 /** 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}\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/** 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). The stored value stays canonical; UIs convert at the edge. */\nexport interface PrefNumberUnit {\n toDisplay: (stored: number) => number;\n fromDisplay: (display: number) => number;\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 /** The stored value as display text, suffix included. */\n format?: (stored: number) => string;\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.\n */\nexport function prefUnit(\n system: UnitSystem,\n display: Unit,\n opts?: { precision?: number; suffix?: string },\n): PrefNumberUnit {\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 scale = opts?.precision === undefined ? undefined : 10 ** opts.precision;\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 const toDisplay = (stored: number) => {\n const shown = (stored - self.offset) / self.factor;\n return scale === undefined ? shown : Math.round(shown * scale) / scale;\n };\n return {\n toDisplay,\n fromDisplay: (shown) => shown * self.factor + self.offset,\n suffix,\n accepts,\n format: (stored) =>\n `${formatUnit(stored, display, system, {\n precision: opts?.precision ?? 2,\n suffix: false,\n })}${suffix}`,\n };\n}\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 — a style is\n * meaningless without the width it is a multiple of.\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 (weasel-ui `PrefsForm` / `SelectionPanel`) dispatch it to an\n * app-supplied renderer. Deliberately NOT index-signatured so concrete\n * app interfaces stay assignable. Mirrors weasel-ui's `PrefCustom`.\n */\nexport type PrefCustom = PrefBase<string, unknown>;\n\n/**\n * A whole `FillStyle`, 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.\n *\n * A compound value — a stroke, a shadow, a pattern spec — could be described\n * as several sibling leaves addressing into it (`data.stroke.width`,\n * `data.stroke.cap`). It shouldn't be: each control would then write one field\n * of a value it can only half see, and writing into something that is not an\n * object yet corrupts it. Here the fields are `children` of one leaf, and\n * every edit commits the parent object whole.\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. A\n * `TextStyle` needs it: its character and paragraph fields belong to one\n * value but read as two lists.\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 — the only thing standing between a new kind and rendering as\n * nothing in four places at once.\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"]}
1
+ {"version":3,"sources":["../src/tabRuns.ts","../src/shown.ts","../src/judge.ts","../src/scopeAt.ts","../src/scope.ts","../src/build.ts","../src/css.ts","../src/aliasTargets.ts","../src/object.ts","../src/type.ts","../src/groups.ts","../src/heading.ts","../src/pair.ts","../src/kinds.ts"],"names":["leaf","scope","kept","under","pref"],"mappings":";;;;AAOO,SAAS,WAAA,CAAe,OAAqB,KAAA,EAA8C;AAChG,EAAA,MAAM,MAAuB,EAAC;AAC9B,EAAA,IAAI,GAAA;AACJ,EAAA,KAAA,MAAW,QAAQ,KAAA,EAAO;AACxB,IAAA,IAAI,CAAC,KAAA,CAAM,IAAI,CAAA,EAAG;AAChB,MAAA,GAAA,GAAM,MAAA;AACN,MAAA,GAAA,CAAI,IAAA,CAAK,EAAE,IAAA,EAAM,CAAA;AAAA,IACnB,WAAW,GAAA,EAAK;AACd,MAAA,GAAA,CAAI,KAAK,IAAI,CAAA;AAAA,IACf,CAAA,MAAO;AACL,MAAA,GAAA,CAAI,KAAK,EAAE,IAAA,EAAO,MAAM,CAAC,IAAI,GAAI,CAAA;AAAA,IACnC;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AAM,gBAAA,GAAqD;AAAA,EAChE,MAAA,EAAQ,GAAA;AAAA,EACR,OAAA,EAAS,GAAA;AAAA,EACT,MAAA,EAAQ,GAAA;AAAA,EACR,IAAA,EAAM,GAAA;AAAA,EACN,KAAA,EAAO,GAAA;AAAA,EACP,KAAA,EAAO,GAAA;AAAA,EACP,MAAA,EAAQ,IAAA;AAAA,EACR,IAAA,EAAM,IAAA;AAAA,EACN,GAAA,EAAK,IAAA;AAAA,EACL,KAAA,EAAO,IAAA;AAAA,EACP,KAAA,EAAO,GAAA;AAAA,EACP,MAAA,EAAQ,EAAE,QAAA,EAAU,KAAA,EAAO,SAAS,IAAA,EAAK;AAAA,EACzC,KAAA,EAAO,GAAA;AAAA,EACP,KAAA,EAAO,GAAA;AAAA,EACP,SAAA,EAAW;AACb;AAEA,IAAM,QAAA,GAAW,CAACA,KAAAA,KACf,MAAA,CAAO,MAAA,CAAO,gBAAA,EAAkBA,KAAAA,CAAK,IAAI,CAAA,GAAI,gBAAA,CAAiBA,KAAAA,CAAK,IAAgB,CAAA,GAAI,GAAA;AAGnF,SAAS,eAAeA,KAAAA,EAAiC;AAC9D,EAAA,OAAO,QAAA,CAASA,KAAI,CAAA,CAAE,QAAA;AACxB;AAGO,SAAS,iBAAiBA,KAAAA,EAAiC;AAChE,EAAA,OAAO,QAAA,CAASA,KAAI,CAAA,CAAE,OAAA;AACxB","file":"index.js","sourcesContent":["/** One step of a walk over a group's children: a child on its own, or the neighboring `tab` children that share one strip. */\nexport type PrefTabRun<T> = { item: T; tabs?: undefined } | { tabs: readonly T[]; item?: undefined };\n\n/**\n * `items` in order, each run of neighbors `isTab` holds for folded into one step. What a surface leaves out of\n * `items` neither joins a run nor ends one, and what it keeps and then declines to draw still holds its run together.\n */\nexport function prefTabRuns<T>(items: readonly T[], isTab: (item: T) => boolean): PrefTabRun<T>[] {\n const out: PrefTabRun<T>[] = [];\n let run: T[] | undefined;\n for (const item of items) {\n if (!isTab(item)) {\n run = undefined;\n out.push({ item });\n } else if (run) {\n run.push(item);\n } else {\n out.push({ tabs: (run = [item]) });\n }\n }\n return out;\n}\n","// A stored value as the control over its leaf shows it. A condition compares\n// that, and not the stored form: a person writes \"is on\" about an Italic\n// toggle, whatever string the toggle stores.\n\nimport type { PrefConditionReader } from './condition';\nimport type { PrefGroup, PrefSection } from './groups';\nimport { prefLeafHolding, prefLeafHoldingIn, prefSchemaHolding, UNSEEN } from './holding';\nimport type { PrefBoolean, PrefEnum, PrefLeaf } from './schema';\n\ntype Siblings = Record<string, unknown> | undefined;\n\n/** What the control over `leaf` shows for `stored`: what its `encoding` reads it as, else `stored` itself.\n * `siblings` is the object the leaf is a field of. */\nexport function prefShownValue(leaf: PrefLeaf, stored: unknown, siblings?: Record<string, unknown>): unknown {\n if (leaf.kind !== 'boolean' && leaf.kind !== 'enum') return stored;\n const { encoding } = leaf as PrefBoolean | PrefEnum;\n return encoding ? (encoding.read as (stored: unknown, siblings: Siblings) => unknown)(stored, siblings) : stored;\n}\n\n/**\n * `read` with each value handed back as {@link prefShownValue} gives it, for\n * the leaf of `schema` at that path, a field of an `object` or a `union` leaf\n * included. A field's siblings are what `read` finds at its leaf's path. A\n * path read from the entry is held to `item`, the leaf describing that entry.\n * A path no leaf of `schema` holds is held to `over`, the schema it is drawn\n * over.\n */\nexport function prefShownReader(\n schema: PrefGroup | PrefSection, read: PrefConditionReader, item?: PrefLeaf, over?: PrefGroup | PrefSection,\n): PrefConditionReader {\n return (path, from) => {\n const stored = read(path, from);\n const held = from === 'item' ? item && prefLeafHoldingIn(item, path) : prefLeafHolding(prefSchemaHolding(schema, path, over), path);\n if (held === undefined || held === UNSEEN) return stored;\n const object = held.within === undefined ? undefined : read(held.within, from);\n return prefShownValue(held.leaf, stored, typeof object === 'object' && object !== null ? (object as Siblings) : undefined);\n };\n}\n","// Who answers a condition: a judge, made from a way to read values.\n\nimport { prefConditionHolds, prefConditionReadsItem, type PrefCondition, type PrefConditionReader } from './condition';\nimport type { PrefGroup, PrefSection } from './groups';\nimport { isPrefLeaf, isPrefSection, prefSectionLeaves, prefValueAtPath } from './helpers';\nimport { prefSchemaHolding } from './holding';\nimport type { PrefLeaf } from './schema';\nimport { prefShownReader } from './shown';\n\n/** Which of a node's two conditions a {@link PrefConditionJudge} is asked about. */\nexport type PrefConditionField = 'showIf' | 'enableIf';\n\n/**\n * Says whether one condition holds. {@link prefJudge} makes one from a value\n * reader; a surface drawing several values at once writes its own, to say\n * what a condition that holds for some and not for others comes to.\n */\nexport type PrefConditionJudge = (condition: PrefCondition, field: PrefConditionField) => boolean;\n\n/** One entry of a list or a map: the `item` leaf describing it, and what it holds. */\nexport interface PrefEntry {\n item: PrefLeaf;\n value: unknown;\n}\n\n/** What `entry` holds at `path`, the empty path being the entry itself: its own value, else that part of the item's default. */\nfunction entryValue({ item, value }: PrefEntry, path: string): unknown {\n if (path === '') return value !== undefined ? value : item.default;\n const held = prefValueAtPath(value, path);\n return held !== undefined ? held : prefValueAtPath(item.default, path);\n}\n\n/**\n * A judge over one set of values, read by path. A condition compares each\n * value as the control over its leaf in `schema` shows it\n * ({@link prefShownReader}), so `read` hands back what is stored. A test\n * that reads from the entry (`from: 'item'`) reads `entry`, and finds nothing\n * held where none is given. `over` is the schema `schema` is drawn over: a\n * path no leaf of `schema` holds is compared as the leaf of `over` there\n * shows it.\n */\nexport function prefJudge(\n schema: PrefGroup | PrefSection, read: (path: string) => unknown, entry?: PrefEntry, over?: PrefGroup | PrefSection,\n): PrefConditionJudge {\n const stored: PrefConditionReader = (path, from) => (from === 'item' ? entry && entryValue(entry, path) : read(path));\n const shown = prefShownReader(schema, stored, entry?.item, over);\n return (condition) => prefConditionHolds(condition, shown);\n}\n\n/**\n * `holds` for every condition but one that reads the entry, which is left\n * unanswered, which is to say holding: what a walk with no entry in hand\n * asks inside the item of a list or a map.\n */\nexport function deferEntryConditions(holds: PrefConditionJudge): PrefConditionJudge {\n return (condition, field) => prefConditionReadsItem(condition) || holds(condition, field);\n}\n\n/**\n * Reads a value by path the way a form over `schema` shows it: what `values`\n * holds there, else the default of the leaf at that path, or the part of a\n * leaf's default the rest of the path names. `over` is the schema `schema`\n * is drawn over: a path no leaf of `schema` holds takes its default there.\n */\nexport function prefReader(schema: PrefGroup | PrefSection, values: unknown, over?: PrefGroup | PrefSection): (path: string) => unknown {\n const beyond = over && prefReader(over, values);\n return (path) => {\n const held = prefValueAtPath(values, path);\n if (held !== undefined) return held;\n if (beyond && prefSchemaHolding(schema, path, over) === over) return beyond(path);\n if (isPrefSection(schema)) {\n for (const [key, leaf] of prefSectionLeaves(schema.members)) {\n if (path === key) return leaf.default;\n if (path.startsWith(`${key}.`)) return prefValueAtPath(leaf.default, path.slice(key.length + 1));\n }\n return undefined;\n }\n const steps = path.split('.');\n let node: PrefGroup = schema;\n for (let i = 0; i < steps.length; i++) {\n if (!Object.hasOwn(node.children, steps[i]!)) return undefined;\n const child: PrefLeaf | PrefGroup = node.children[steps[i]!]!;\n if (!isPrefLeaf(child)) node = child;\n else return i === steps.length - 1 ? child.default : prefValueAtPath(child.default, steps.slice(i + 1).join('.'));\n }\n return undefined;\n };\n}\n","// The scope of one node: whether it is drawn and whether it takes input,\n// with everything above it counted.\n\nimport { prefAliasTarget, type PrefAlias } from './alias';\nimport type { PrefCondition } from './condition';\nimport type { PrefGroup, PrefSection } from './groups';\nimport { isPrefLeaf, isPrefSection, prefLeafAt } from './helpers';\nimport { deferEntryConditions, type PrefConditionJudge } from './judge';\nimport type { PrefList } from './list';\nimport type { PrefMap } from './map';\nimport type { PrefLeaf, PrefObject } from './schema';\nimport type { PrefUnion } from './union';\n\n/** Whether a node is drawn and whether it takes input, with what is above it counted. */\nexport interface PrefScope {\n shown: boolean;\n enabled: boolean;\n}\n\n/** The step that stands for any entry of a `list` or a `map` in a path: `'phases.*.hold'` answers for that field of\n * each, by every condition that comes to the same for every entry. */\nexport const PREF_ENTRY = '*';\n\n/** The scope a schema's root sits in. */\nexport const PREF_SCOPE: PrefScope = Object.freeze({ shown: true, enabled: true });\n\n/** The scope of `node`, which sits directly under something whose scope is `above`. */\nexport function prefScopeUnder(\n above: PrefScope,\n node: { showIf?: PrefCondition; enableIf?: PrefCondition },\n holds: PrefConditionJudge,\n): PrefScope {\n const shown = above.shown && (node.showIf === undefined || holds(node.showIf, 'showIf'));\n const enabled = above.enabled && (node.enableIf === undefined || holds(node.enableIf, 'enableIf'));\n return shown === above.shown && enabled === above.enabled ? above : { shown, enabled };\n}\n\n/** The scope of the field at `rest` among an object leaf's children, or `undefined` when none is there. */\nfunction scopeAmong(\n held: PrefSection['members'], rest: string, above: PrefScope, holds: PrefConditionJudge,\n): PrefScope | undefined {\n for (const [key, child] of Object.entries(held)) {\n if (!isPrefLeaf(child)) {\n const found = scopeAmong(child.members, rest, prefScopeUnder(above, child, holds), holds);\n if (found) return found;\n } else if (rest === key) return prefScopeUnder(above, child, holds);\n else if (rest.startsWith(`${key}.`)) return scopeInside(child, rest.slice(key.length + 1), prefScopeUnder(above, child, holds), holds);\n }\n return undefined;\n}\n\n/** The scope at `rest` inside `leaf`, whose own scope is `scope`: that of a field, or the leaf's where `rest` names none. */\nfunction scopeInside(leaf: PrefLeaf, rest: string, scope: PrefScope, holds: PrefConditionJudge): PrefScope {\n if (leaf.kind === 'object') return scopeAmong((leaf as PrefObject).children, rest, scope, holds) ?? scope;\n if (leaf.kind === 'list' || leaf.kind === 'map') {\n const { item } = leaf as Partial<PrefList | PrefMap>;\n if (item === undefined) return scope;\n const inItem = deferEntryConditions(holds);\n const entry = prefScopeUnder(scope, { enableIf: item.enableIf }, inItem);\n const dot = rest.indexOf('.');\n return dot < 0 ? entry : scopeInside(item, rest.slice(dot + 1), entry, inItem);\n }\n if (leaf.kind !== 'union') return scope;\n for (const variant of Object.values((leaf as PrefUnion).variants)) {\n const found = scopeAmong(variant.children, rest, scope, holds);\n if (found) return found;\n }\n return scope;\n}\n\nfunction scopeAt(schema: PrefGroup | PrefSection, path: string, holds: PrefConditionJudge): PrefScope {\n let scope = prefScopeUnder(PREF_SCOPE, schema, holds);\n if (path === '') return scope;\n if (isPrefSection(schema)) return scopeAmong(schema.members, path, scope, holds) ?? scope;\n let node: PrefGroup = schema;\n const steps = path.split('.');\n for (let i = 0; i < steps.length; i++) {\n if (!Object.hasOwn(node.children, steps[i]!)) return scope;\n const child: PrefLeaf | PrefGroup = node.children[steps[i]!]!;\n scope = prefScopeUnder(scope, child, holds);\n if (isPrefLeaf(child)) return i === steps.length - 1 ? scope : scopeInside(child, steps.slice(i + 1).join('.'), scope, holds);\n node = child;\n }\n return scope;\n}\n\n/** `own`, an alias's scope by its own conditions, narrowed by that of the leaf it shows in `over`, as `holds` judges `over`. */\nexport function prefAliasScope(own: PrefScope, alias: PrefAlias, over: PrefGroup | PrefSection, holds: PrefConditionJudge): PrefScope {\n const target = prefAliasTarget(alias, (path) => prefLeafAt(over, path));\n if (target === undefined) return own;\n const theirs = scopeAt(over, target.path, holds);\n const shown = own.shown && theirs.shown;\n const enabled = own.enabled && theirs.enabled;\n return shown === own.shown && enabled === own.enabled ? own : { shown, enabled };\n}\n\n/** What {@link prefScopeAt} is told beyond the schema. */\nexport interface PrefScopeAtOptions {\n /** The schema an alias's `of` names a leaf of. Default: the schema asked. */\n aliasOver?: PrefGroup | PrefSection;\n /** Says which conditions of `aliasOver` hold, where its values are not the ones `holds` reads. Default: `holds`. */\n aliasHolds?: PrefConditionJudge;\n}\n\n/**\n * The scope of the node at `path`: a group, a leaf, a field of an `object`\n * or a `union` leaf, or an entry of a `list` or a `map`, whose step may be\n * any key. Under a {@link PrefSection} schema a leaf's key is its whole\n * path. A path that runs past the schema answers for the last node it\n * reaches. An alias answers for itself and for the leaf it shows, as\n * `applyPrefConditions` has it. Inside an entry, a condition that reads the\n * entry (`from: 'item'`) is not asked and counts as holding, there being no\n * entry here to read: `applyPrefEntryConditions` answers it.\n */\nexport function prefScopeAt(\n schema: PrefGroup | PrefSection, path: string, holds: PrefConditionJudge, { aliasOver, aliasHolds }: PrefScopeAtOptions = {},\n): PrefScope {\n const own = scopeAt(schema, path, holds);\n const leaf = prefLeafAt(schema, path);\n return leaf?.kind === 'alias' ? prefAliasScope(own, leaf as PrefAlias, aliasOver ?? schema, aliasHolds ?? holds) : own;\n}\n","// What a schema's conditions come to once nesting is counted: a node is drawn\n// only while it and everything above it is shown, and takes input only while\n// it and everything above it is enabled. Every surface that draws a schema\n// asks here.\n\nimport type { PrefAlias } from './alias';\nimport { prefConditionReadsItem } from './condition';\nimport type { PrefGroup, PrefSection } from './groups';\nimport { isPrefLeaf, isPrefSection } from './helpers';\nimport { deferEntryConditions, type PrefConditionJudge } from './judge';\nimport type { PrefList } from './list';\nimport type { PrefMap } from './map';\nimport type { PrefLeaf, PrefObject } from './schema';\nimport { PREF_ENTRY, PREF_SCOPE, prefAliasScope, prefScopeUnder, type PrefScope } from './scopeAt';\nimport type { PrefUnion } from './union';\n\nexport { prefJudge, prefReader, type PrefConditionField, type PrefConditionJudge, type PrefEntry } from './judge';\nexport { PREF_ENTRY, PREF_SCOPE, prefScopeAt, prefScopeUnder, type PrefScope, type PrefScopeAtOptions } from './scopeAt';\n\nconst under = (prefix: string, key: string): string => (prefix === '' ? key : `${prefix}.${key}`);\n\n/** A schema with its conditions applied. */\nexport interface PrefConditionsApplied<T> {\n /** The schema without the nodes that are not shown. The schema itself when\n * that is all of it, and `null` when its root is not shown. */\n shown: T | null;\n /**\n * The value path of every leaf that is disabled, a field of an `object` or\n * a `union` leaf included (`'stroke.width'`), and under a {@link PrefGroup}\n * schema the path of every group that is. A `list`'s or a `map`'s item is\n * named once for every entry, with {@link PREF_ENTRY} as the entry's step:\n * `'phases.*'`, and `'phases.*.hold'` for a field of it.\n */\n disabled: ReadonlySet<string>;\n /**\n * With `keepHidden`, the path of everything `shown` holds that is not\n * shown, named as `disabled` names what is disabled. Empty without it,\n * since `shown` then holds none.\n */\n hidden: ReadonlySet<string>;\n}\n\n/** How {@link applyPrefConditions} treats what it would leave out. */\nexport interface PrefConditionsOptions {\n /** Keep a group or a section that leaves with nothing to draw. */\n keepEmpty?: boolean;\n /**\n * Keep every node whose `showIf` fails, and name it in `hidden`: for a\n * surface that edits the schema, where a node not drawn cannot be picked.\n */\n keepHidden?: boolean;\n /** The schema an alias's `of` names a leaf of. Default: the schema walked. */\n aliasOver?: PrefGroup | PrefSection;\n /** Says which conditions of `aliasOver` hold, where its values are not the ones `holds` reads. Default: `holds`. */\n aliasHolds?: PrefConditionJudge;\n}\n\ninterface WalkOptions {\n keepEmpty: boolean;\n keepHidden: boolean;\n /** Asked inside the item of a list or a map met on the way, whose entries the walk does not have. */\n inItem: PrefConditionJudge;\n aliasOver?: PrefGroup | PrefSection;\n aliasHolds?: PrefConditionJudge;\n}\n\n/** The walk over leaves and what is inside them, which the schema's pass and an entry's share. */\nfunction leafWalk({ keepEmpty, keepHidden, inItem, aliasOver, aliasHolds }: WalkOptions) {\n const disabled = new Set<string>();\n const hidden = new Set<string>();\n\n const leaf = (node: PrefLeaf, path: string, above: PrefScope, holds: PrefConditionJudge): PrefLeaf | null => {\n const own = prefScopeUnder(above, node, holds);\n const scope = node.kind === 'alias' && aliasOver ? prefAliasScope(own, node as PrefAlias, aliasOver, aliasHolds ?? holds) : own;\n return scope.shown || keepHidden ? inside(node, path, scope, holds) : null;\n };\n\n /** `node`, whose scope is `scope`, without what its own value hides: a field, or part of a list's or a map's item. */\n const inside = (node: PrefLeaf, path: string, scope: PrefScope, holds: PrefConditionJudge): PrefLeaf => {\n if (!scope.shown) hidden.add(path);\n if (!scope.enabled) disabled.add(path);\n if (node.kind === 'object') {\n const children = members((node as PrefObject).children, path, scope, holds);\n return children === (node as PrefObject).children ? node : ({ ...node, children } as PrefLeaf);\n }\n if (node.kind === 'list' || node.kind === 'map') {\n const { item } = node as Partial<PrefList | PrefMap>;\n // A leaf an app's renderer draws under a built-in's kind may hold no item.\n if (item === undefined) return node;\n // An item is drawn with its entry, so its own `showIf` is not asked.\n const entry = inside(item, under(path, PREF_ENTRY), prefScopeUnder(scope, { enableIf: item.enableIf }, inItem), inItem);\n return entry === item ? node : ({ ...node, item: entry } as PrefLeaf);\n }\n if (node.kind !== 'union') return node;\n const { variants } = node as PrefUnion;\n let changed = false;\n const next: PrefUnion['variants'] = {};\n for (const [key, variant] of Object.entries(variants)) {\n const children = members(variant.children, path, scope, holds);\n changed ||= children !== variant.children;\n next[key] = children === variant.children ? variant : { ...variant, children };\n }\n return changed ? ({ ...node, variants: next } as PrefLeaf) : node;\n };\n\n /** A section's members or an object leaf's children. `prefix` is the object leaf's path, empty in a section schema. */\n const members = (held: PrefSection['members'], prefix: string, above: PrefScope, holds: PrefConditionJudge): PrefSection['members'] => {\n let changed = false;\n const out: PrefSection['members'] = {};\n for (const [key, child] of Object.entries(held)) {\n const kept = isPrefLeaf(child) ? leaf(child, under(prefix, key), above, holds) : section(child, prefix, above, holds);\n changed ||= kept !== child;\n if (kept !== null) out[key] = kept;\n }\n return changed ? out : held;\n };\n\n const section = (node: PrefSection, prefix: string, above: PrefScope, holds: PrefConditionJudge): PrefSection | null => {\n const scope = prefScopeUnder(above, node, holds);\n if (!scope.shown && !keepHidden) return null;\n const kept = members(node.members, prefix, scope, holds);\n if (kept === node.members) return node;\n return Object.keys(kept).length === 0 && !keepEmpty ? null : { ...node, members: kept };\n };\n\n return { disabled, hidden, leaf, inside, members };\n}\n\n/**\n * `schema` as it is drawn while `holds` says which conditions hold. A node\n * whose `showIf` fails is dropped with everything under it, unless\n * `keepHidden`, and so is a group or a section that leaves with nothing to\n * draw, unless `keepEmpty`. A node\n * whose `enableIf` fails is disabled with everything under it. The item of\n * a `list` or a `map` is walked as its entries are drawn: its fields hide and\n * disable by their conditions, and its own `enableIf` disables every entry.\n * A condition there that reads the entry (`from: 'item'`) has no one answer\n * for every entry and is left holding: {@link applyPrefEntryConditions}\n * answers it for each.\n * An alias is shown only while it and the leaf it shows both are, and enabled\n * only while both are, with everything above that leaf counted. That leaf is\n * looked for in `aliasOver`, and its side is asked of `aliasHolds`.\n * Parts with nothing dropped come back as the objects they were.\n */\nexport function applyPrefConditions<T extends PrefGroup | PrefSection>(\n schema: T,\n holds: PrefConditionJudge,\n { keepEmpty = false, keepHidden = false, aliasOver, aliasHolds }: PrefConditionsOptions = {},\n): PrefConditionsApplied<T> {\n const walk = leafWalk({ keepEmpty, keepHidden, inItem: deferEntryConditions(holds), aliasOver: aliasOver ?? schema, aliasHolds });\n const { disabled, hidden } = walk;\n\n const group = (node: PrefGroup, path: string, above: PrefScope): PrefGroup | null => {\n const scope = prefScopeUnder(above, node, holds);\n if (!scope.shown && !keepHidden) return null;\n if (!scope.shown && path !== '') hidden.add(path);\n if (!scope.enabled && path !== '') disabled.add(path);\n let changed = false;\n const children: PrefGroup['children'] = {};\n for (const [key, child] of Object.entries(node.children)) {\n const at = under(path, key);\n const kept = isPrefLeaf(child) ? walk.leaf(child, at, scope, holds) : group(child, at, scope);\n changed ||= kept !== child;\n if (kept !== null) children[key] = kept;\n }\n if (!changed) return node;\n return Object.keys(children).length === 0 && !keepEmpty && path !== '' ? null : { ...node, children };\n };\n\n if (!isPrefSection(schema)) return { shown: group(schema, '', PREF_SCOPE) as T | null, disabled, hidden };\n const scope = prefScopeUnder(PREF_SCOPE, schema, holds);\n if (!scope.shown && !keepHidden) return { shown: null, disabled, hidden };\n const kept = walk.members(schema.members, '', scope, holds);\n return { shown: kept === schema.members ? schema : { ...schema, members: kept }, disabled, hidden };\n}\n\n/** One entry of a list or a map with the conditions that read it applied. */\nexport interface PrefEntryApplied {\n /** The item as this entry draws it: without the fields not shown, and the item itself when that is all of them. */\n item: PrefLeaf;\n /** The path of the entry, and of every field in it, that is disabled, named as {@link PrefConditionsApplied} names them. */\n disabled: ReadonlySet<string>;\n /** With `keepHidden`, the path of every field of the entry that is not shown. */\n hidden: ReadonlySet<string>;\n}\n\nconst ALWAYS: PrefConditionJudge = () => true;\n\n/**\n * The conditions {@link applyPrefConditions} leaves unanswered, answered for\n * one entry: `item`, as that pass left it, drawn for the entry at `path`\n * (`'phases.2'`) while `holds` says which conditions hold. `holds` reads the\n * entry: `prefJudge` given it. Only a condition that reads the entry is\n * asked, the rest being applied already, and one inside a list or a map\n * within the entry is left for that one's own entries.\n */\nexport function applyPrefEntryConditions(\n item: PrefLeaf,\n path: string,\n holds: PrefConditionJudge,\n { keepEmpty = false, keepHidden = false }: Pick<PrefConditionsOptions, 'keepEmpty' | 'keepHidden'> = {},\n): PrefEntryApplied {\n const asked: PrefConditionJudge = (condition, field) => !prefConditionReadsItem(condition) || holds(condition, field);\n const walk = leafWalk({ keepEmpty, keepHidden, inItem: ALWAYS });\n const scope = prefScopeUnder(PREF_SCOPE, { enableIf: item.enableIf }, asked);\n return { item: walk.inside(item, path, scope, asked), disabled: walk.disabled, hidden: walk.hidden };\n}\n","// Short forms for writing a schema by hand. Each returns the plain data a\n// literal would: nothing reads a schema differently for how it was written.\n\nimport type { PrefGroup, PrefSection } from './groups';\nimport type { PrefBoolean, PrefColor, PrefEnumBase, PrefLeaf, PrefNumber, PrefString } from './schema';\n\n/** What a builder takes after the leaf's name and default: any of the leaf's other fields. */\ntype Rest<L> = Partial<Omit<L, 'kind' | 'name' | 'default'>>;\n\n/** One option of an enum, or its value alone, which is labeled with the value's first letter raised. */\ntype OptionOf<T extends string> = T | PrefEnumBase<T>['options'][number];\n\nconst leaf = <L extends PrefLeaf>(kind: L['kind'], name: string, def: unknown, rest: object | undefined): L =>\n ({ kind, name, description: '', default: def, ...rest }) as L;\n\nconst labeled = (value: string): string => (value === '' ? value : value[0]!.toUpperCase() + value.slice(1));\n\n/**\n * Builders for a preferences schema, each returning what the literal would\n * hold. `pref.group('View', { grid: pref.boolean('Grid', true) })` is\n * `{ name: 'View', children: { grid: { kind: 'boolean', name: 'Grid', description: '', default: true } } }`,\n * and its paths and value types are read from it the same way.\n */\nexport const pref = {\n /** A group: `children` nest under its key, which is a segment of their paths. */\n group<const C extends Record<string, PrefLeaf | PrefGroup>>(\n name: string,\n children: C,\n options?: Omit<PrefGroup, 'name' | 'children'>,\n ): Omit<PrefGroup, 'children'> & { children: C } {\n return { name, ...options, children };\n },\n\n /** A section: a heading over `members`, whose key adds nothing to their paths. */\n section<const M extends Record<string, PrefLeaf | PrefSection>>(\n name: string,\n members: M,\n options?: Omit<PrefSection, 'name' | 'members'>,\n ): Omit<PrefSection, 'members'> & { members: M } {\n return { name, ...options, members };\n },\n\n number: (name: string, def: number, rest?: Rest<PrefNumber>): PrefNumber => leaf('number', name, def, rest),\n boolean: (name: string, def: boolean, rest?: Rest<PrefBoolean>): PrefBoolean => leaf('boolean', name, def, rest),\n string: (name: string, def: string, rest?: Rest<PrefString>): PrefString => leaf('string', name, def, rest),\n color: (name: string, def: string, rest?: Rest<PrefColor>): PrefColor => leaf('color', name, def, rest),\n\n /** A fixed set of choices. An option given as its value alone is labeled with that value, its first letter raised. */\n enum<const T extends string>(\n name: string,\n def: NoInfer<T>,\n options: readonly OptionOf<T>[],\n rest?: Omit<Rest<PrefEnumBase<T>>, 'options'>,\n ): PrefEnumBase<T> & { default: T; clearable?: false } {\n const full = options.map((option) => (typeof option === 'string' ? { value: option, label: labeled(option) } : option));\n return { kind: 'enum', name, description: '', default: def, ...rest, options: full };\n },\n};\n","// A store's values as CSS custom properties: one block for what every choice\n// of the selectors shares, and one for each choice a split value tells apart.\n\nimport type { PrefGroup } from './groups';\nimport { prefHoldsValue, prefLeaves, prefValueAtPath } from './helpers';\nimport { isPrefLocus, type PrefLocus, type PrefSelection } from './locus';\nimport type { PrefEnum, PrefLeaf, PrefNumber } from './schema';\nimport { prefSelectors } from './splitCheck';\nimport { resolvePrefUnit } from './unit';\n\n/** How {@link prefsCss} names and writes things. */\nexport interface PrefsCssOptions {\n /** The selector of the element the properties are set on, and the selectors' attributes read from. Default `:root`. */\n root?: string;\n /** The custom property a leaf is written as, or `null` to leave the leaf out. Default: `--`, then the path with\n * each `.` and each capital turned into a `-` (`look.gridGap` is `--look-grid-gap`). */\n property?: (path: string, leaf: PrefLeaf) => string | null;\n /** The attribute a selector's option is read from. Default: `data-`, then the path as a property spells it. */\n attribute?: (selector: string) => string;\n /** The CSS text of a value, `null` to leave it out, or `undefined` for what its kind writes by itself. */\n value?: (value: unknown, leaf: PrefLeaf, path: string) => string | null | undefined;\n}\n\n/** What {@link prefsCss} reads of a store: any `PrefsStore` is one. */\nexport interface PrefsCssSource {\n schema: PrefGroup;\n values(read?: { at?: PrefSelection }): Record<string, unknown>;\n locus(path: string): PrefLocus | undefined;\n get(path: string): unknown;\n}\n\nconst kebab = (path: string): string => path.replace(/\\./g, '-').replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);\n\n/** The CSS unit a number leaf's suffix names, for the suffixes that name one. */\nconst CSS_UNITS: Readonly<Record<string, string>> = {\n px: 'px', '%': '%', em: 'em', rem: 'rem', ch: 'ch', pt: 'pt', vw: 'vw', vh: 'vh',\n ms: 'ms', s: 's', '°': 'deg', deg: 'deg', rad: 'rad', turn: 'turn',\n};\n\nconst IDENT = /^-?[A-Za-z_][\\w-]*$/;\nconst quoted = (text: string): string => `'${text.replace(/[\\\\']/g, '\\\\$&')}'`;\n\n/** What a value of a built-in kind is written as, `null` for one with no CSS form. */\nfunction cssValue(leaf: PrefLeaf, value: unknown): string | null {\n switch (leaf.kind) {\n case 'number': {\n if (typeof value !== 'number' || !Number.isFinite(value)) return null;\n const { unit } = leaf as PrefNumber;\n const resolved = unit ? resolvePrefUnit(unit) : undefined;\n const shown = resolved ? resolved.toDisplay(value) : value;\n const suffix = resolved?.suffix !== undefined && Object.hasOwn(CSS_UNITS, resolved.suffix) ? CSS_UNITS[resolved.suffix] : '';\n return `${Number(shown.toFixed(6))}${suffix}`;\n }\n case 'boolean':\n return typeof value === 'boolean' ? (value ? '1' : '0') : null;\n case 'color':\n return typeof value === 'string' && value !== '' ? value : null;\n case 'enum':\n if (typeof value !== 'string' || (leaf as PrefEnum).encoding) return null;\n return IDENT.test(value) ? value : quoted(value);\n case 'string':\n return typeof value === 'string' ? quoted(value) : null;\n default:\n return null;\n }\n}\n\n/** One choice of options, a selector's path and its option per step, and the value read under it. */\ntype Told = { under: [selector: string, option: string][]; value: unknown };\n\n/** Every choice of options a held value tells apart, outermost selector first. */\nfunction toldApart(held: unknown, optionsOf: (selector: string) => readonly string[], absent: unknown): Told[] {\n const out: Told[] = [];\n const walk = (value: unknown, under: Told['under']): void => {\n if (!isPrefLocus(value)) {\n out.push({ under, value });\n return;\n }\n for (const option of optionsOf(value.$by)) {\n walk(Object.hasOwn(value.$of, option) ? value.$of[option] : absent, [...under, [value.$by, option]]);\n }\n };\n walk(held, []);\n return out;\n}\n\n/**\n * The store's values as CSS custom properties.\n *\n * The first block sets every leaf on `root`, a split one at the member the\n * selectors' defaults name, so a page that sets no attribute still has a\n * value for each. A block follows for each choice of options some value tells\n * apart, matched by an attribute per selector on that same element; a selector\n * is written under each of its own options too. Every block is inside\n * `:where()`, so none outranks another by how many attributes it names, and a\n * rule of the page's own wins. Blocks naming more selectors come later.\n *\n * A number is written in its display unit where the unit's suffix is a CSS\n * unit, and bare otherwise; a boolean as `1` or `0`; a color as it is held; an\n * enum's option as an identifier; a string quoted. A leaf of any other kind is\n * left out unless `value` writes it.\n */\nexport function prefsCss(store: PrefsCssSource, options: PrefsCssOptions = {}): string {\n const root = options.root ?? ':root';\n const property = options.property ?? ((path: string): string => `--${kebab(path)}`);\n const attribute = options.attribute ?? ((selector: string): string => `data-${kebab(selector)}`);\n const leaves = new Map([...prefLeaves(store.schema)].filter(([, leaf]) => prefHoldsValue(leaf)));\n const selectors = prefSelectors(leaves);\n const defaults = Object.fromEntries([...selectors.keys()].map((path) => [path, leaves.get(path)!.default as string]));\n const base = store.values({ at: defaults });\n\n const blocks = new Map<string, { under: Told['under']; lines: string[] }>();\n const declare = (under: Told['under'], path: string, leaf: PrefLeaf, value: unknown): void => {\n const name = property(path, leaf);\n if (name === null) return;\n const given = options.value?.(value, leaf, path);\n const text = given === undefined ? cssValue(leaf, value) : given;\n if (text === null) return;\n const key = under.map(([selector, option]) => `${selector}=${option}`).join('&');\n if (!blocks.has(key)) blocks.set(key, { under, lines: [] });\n blocks.get(key)!.lines.push(` ${name}: ${text};`);\n };\n\n for (const [path, leaf] of leaves) {\n declare([], path, leaf, prefValueAtPath(base, path));\n const own = selectors.get(path);\n if (own) for (const option of own) declare([[path, option]], path, leaf, option);\n const held = store.locus(path);\n if (!held) continue;\n for (const { under, value } of toldApart(held, (selector) => selectors.get(selector) ?? [], leaf.default)) {\n declare(under, path, leaf, value);\n }\n }\n\n return [...blocks.values()]\n .map((block, i) => ({ ...block, i }))\n .sort((a, b) => a.under.length - b.under.length || a.i - b.i)\n .map(({ under, lines }) => {\n const matched = under.map(([selector, option]) => `[${attribute(selector)}=${quoted(option)}]`).join('');\n return `:where(${root}${matched}) {\\n${lines.join('\\n')}\\n}`;\n })\n .join('\\n\\n');\n}\n\n/**\n * The attribute for each selector and the option it is set to: what to set\n * on the `root` element for the blocks of {@link prefsCss} to match the\n * store's own choice.\n */\nexport function prefsCssAttributes(store: Pick<PrefsCssSource, 'schema' | 'get'>, options: Pick<PrefsCssOptions, 'attribute'> = {}): Record<string, string> {\n const attribute = options.attribute ?? ((selector: string): string => `data-${kebab(selector)}`);\n const leaves = prefLeaves(store.schema);\n return Object.fromEntries([...prefSelectors(leaves).keys()].map((path) => [attribute(path), store.get(path) as string]));\n}\n","// The leaves a surface's aliases show: the schema they point into, as that\n// schema's own conditions leave it. Every surface that draws an alias asks\n// here, whether the schema is its own or another's.\n\nimport { prefAliasedLeaf, prefAliasTarget, type PrefAlias } from './alias';\nimport type { PrefGroup, PrefSection } from './groups';\nimport { prefLeafAt, visiblePrefSubtree } from './helpers';\nimport type { PrefConditionJudge, PrefEntry } from './judge';\nimport type { PrefLeaf, PrefObject } from './schema';\nimport { applyPrefConditions, applyPrefEntryConditions, type PrefConditionsApplied, type PrefEntryApplied } from './scope';\n\n/** What an alias row reads of the leaf it shows: the schema that leaf is in, as that schema's own conditions leave it. */\nexport interface PrefAliasTargets {\n /** Says which conditions of that schema hold. */\n holds: PrefConditionJudge;\n /** The leaf at a path of that schema, without the fields the surface would leave out of the leaf's own row: one\n * marked `hidden`, and one a `showIf` hides, unless the surface draws those. */\n leafAt: (path: string) => PrefLeaf | undefined;\n /** The leaf `alias` is drawn as, under the alias's own name and description where it gives them, and the path\n * its value is read and written at. `undefined` for an alias of nothing. */\n shown: (alias: PrefAlias) => { path: string; leaf: PrefLeaf } | undefined;\n /** Whether the field at a path of that schema is one an `enableIf` disables. */\n disabledAt: (path: string) => boolean;\n /** Whether the field at a path of that schema is one a `showIf` hides, on a surface that draws those. */\n hiddenAt?: (path: string) => boolean;\n /** An entry of a list or a map of that schema, as the conditions that read the entry leave it. */\n entryAt: (item: PrefLeaf, path: string, value: unknown) => PrefEntryApplied;\n}\n\n/** What a surface draws beyond the default, which its alias rows follow. */\nexport interface PrefAliasTargetsOptions {\n /** The surface draws fields marked `hidden`. */\n showHidden?: boolean;\n /** The surface draws what a `showIf` hides, marked. */\n markHidden?: boolean;\n}\n\n/** `leaf` without its fields marked `hidden`. The leaf's own mark is not asked: an alias shows a leaf the surface leaves out. */\nfunction visibleFieldsOf(leaf: PrefLeaf): PrefLeaf {\n if (leaf.kind !== 'object') return leaf;\n const shown = visiblePrefSubtree({ ...leaf, hidden: false }, false, true) as PrefObject;\n return { ...leaf, children: shown.children } as PrefLeaf;\n}\n\n/**\n * {@link PrefAliasTargets} over `over`, the schema a surface's aliases point\n * into: the surface's own, or another's. `judge` answers `over`'s conditions\n * as the surface reads values, for one entry of a list or a map where it is\n * given one: `prefJudge` over `over`. A surface's own pass drops a leaf it\n * leaves out and keeps no path of another schema, so the leaves aliases show\n * are conditioned here, the first time one is asked for.\n */\nexport function prefAliasTargets(\n over: PrefGroup | PrefSection,\n judge: (entry?: PrefEntry) => PrefConditionJudge,\n { showHidden = false, markHidden = false }: PrefAliasTargetsOptions = {},\n): PrefAliasTargets {\n const holds = judge();\n let applied: PrefConditionsApplied<PrefGroup | PrefSection> | undefined;\n const get = (): PrefConditionsApplied<PrefGroup | PrefSection> =>\n (applied ??= applyPrefConditions(over, holds, { keepEmpty: true, keepHidden: markHidden }));\n const leafAt = (path: string): PrefLeaf | undefined => {\n const { shown } = get();\n const leaf = shown === null ? undefined : prefLeafAt(shown, path);\n return leaf === undefined || showHidden ? leaf : visibleFieldsOf(leaf);\n };\n return {\n holds,\n leafAt,\n shown: (alias) => {\n const target = prefAliasTarget(alias, leafAt);\n return target && { path: target.path, leaf: prefAliasedLeaf(alias, target.leaf) };\n },\n disabledAt: (path) => get().disabled.has(path),\n ...(markHidden ? { hiddenAt: (path: string) => get().hidden.has(path) } : {}),\n entryAt: (item, path, value) => applyPrefEntryConditions(item, path, judge({ item, value }), { keepHidden: markHidden }),\n };\n}\n","import type { PrefObject } from './schema';\n\nconst isObject = (v: unknown): v is Record<string, unknown> => typeof v === 'object' && v !== null;\n\n/**\n * The object a write to one field of an `object` leaf starts from: `held` itself where it is one. Where it is\n * not, the write has to make a whole object, so it starts from the scalar lifted by the leaf's `fromScalar`, else\n * from the leaf's `default`: one field on its own is a stroke with a width and no paint.\n */\nexport function prefObjectBase(pref: PrefObject, held: unknown): Record<string, unknown> {\n if (isObject(held)) return held;\n return pref.fromScalar?.(held) ?? (isObject(pref.default) ? pref.default : {});\n}\n\n/** The object an `object` leaf holds after one of its fields is set: {@link prefObjectBase} with `key` at\n * `value`, or without the key for `undefined`. */\nexport function prefObjectWithField(pref: PrefObject, held: unknown, key: string, value: unknown): Record<string, unknown> {\n const base = prefObjectBase(pref, held);\n if (value !== undefined) return { ...base, [key]: value };\n const { [key]: _dropped, ...rest } = base;\n return rest;\n}\n","import type { PrefLeaf } from './schema';\n\n/**\n * `leaf` as a named type: the same leaf carrying `name` in its `type` field.\n * Declared once beside the code that reads its value and used wherever a\n * schema wants one, spread with what that place sets for itself\n * (`{ ...GradientStop, name: 'First stop' }`), or as a list's or a map's\n * `item`. `name` is the identifier the type is exported under, which a schema\n * editor prints in place of the leaf's literal.\n */\nexport function prefType<L extends PrefLeaf>(name: string, leaf: L): L & { type: string } {\n return { ...leaf, type: name };\n}\n","// The two branch nodes of a schema. They differ in whether a key is part of\n// the path a leaf's value lives at, and each holds its members under its own\n// property, so a schema of one kind is neither assignable to nor walkable as\n// the other.\n\nimport type { PrefCondition } from './condition';\nimport type { PrefLeaf } from './schema';\n\n/**\n * How a {@link PrefGroup} is drawn: `page` gets an entry in a form's rail and\n * a pane of its own; `tab` shares a tab strip with the `tab` groups beside it;\n * `panel` is a bordered, titled box; `section` is a heading over its rows;\n * `fragment` draws nothing of its own, so its rows sit among its neighbors'\n * as though they were written there. A fragment exists to hold things\n * together: one key for their values to nest under, one node to move.\n */\nexport type PrefGroupAs = 'page' | 'tab' | 'panel' | 'section' | 'fragment' | 'bar';\n\n/**\n * What a group or a section drawn `as: 'bar'` does with cells its line has no\n * room for: `scroll` keeps them all on it, and `menu` opens the ones past its\n * end from a button there. A bar set to `menu` takes all the room its host\n * has along the line, which is why it is asked for and not the default.\n */\nexport type PrefBarOverflow = 'scroll' | 'menu';\n\n/** How a {@link PrefSection} is drawn. */\nexport type PrefSectionAs = Exclude<PrefGroupAs, 'page'>;\n\n/**\n * A group whose key is a path segment: `view` > `gridDensity` is the leaf at\n * `view.gridDensity`, and its value nests the same way. The shape of a\n * preferences schema — what `openPrefs` stores, `PrefsForm` renders, and a\n * tool declares its options as. A key holds no `.`.\n */\nexport interface PrefGroup {\n /** Heading for the group's rows. **Empty means no heading** — for a group\n * that exists to organize, not to name: one whose children are themselves\n * groups carrying the labels a reader needs. Give it a name whenever the\n * name is the referent (a `Border` group over `Top` / `Right` / `Bottom`\n * reads as nothing without it). */\n name: string;\n description?: string;\n /** How the group is drawn. Unset, its depth decides: a top-level group is a\n * `page`, and one inside another is a `section`. */\n as?: PrefGroupAs;\n /** Drawn `as: 'bar'`: what happens to the cells its line has no room for.\n * Unset: `scroll`. A surface that takes drops keeps every cell on the line\n * whatever this says, so each is there to drop beside. */\n overflow?: PrefBarOverflow;\n /** Drawn, with everything under it, only while this holds. */\n showIf?: PrefCondition;\n /** Everything under it is disabled while this does not hold. */\n enableIf?: PrefCondition;\n children: Record<string, PrefLeaf | PrefGroup>;\n}\n\n/**\n * A heading over leaves that adds nothing to their paths: each member is\n * addressed by its own key alone, and the section's key only identifies the\n * section. The shape of a node's property schema, where a leaf's key is the\n * whole dotted node path (`pose.x`, `data.fill`), and of the headings inside\n * a {@link PrefObject}, where a key is relative to the object.\n */\nexport interface PrefSection {\n /** Heading for the section's rows. Empty means no heading, as for a\n * {@link PrefGroup}. */\n name: string;\n description?: string;\n /** How the section is drawn, as a {@link PrefGroup}'s `as` — without\n * `page`, since nothing that draws sections has a rail. Unset: a heading\n * over its rows. */\n as?: PrefSectionAs;\n /** As a {@link PrefGroup}'s. */\n overflow?: PrefBarOverflow;\n /** As a {@link PrefGroup}'s. */\n showIf?: PrefCondition;\n /** As a {@link PrefGroup}'s. */\n enableIf?: PrefCondition;\n members: Record<string, PrefLeaf | PrefSection>;\n}\n\n/** Whether a top-level group gets a page of its own, and not a place on the page of the root's own leaves. */\nexport function prefGroupIsPage(group: PrefGroup): boolean {\n return group.as === undefined || group.as === 'page';\n}\n","import type { PrefGroup, PrefSection } from './groups';\nimport { isPrefLeaf } from './helpers';\nimport { isBuiltinPref, type PrefLeaf } from './schema';\n\n/** Whether a leaf's control fits beside a heading's words: a built-in `boolean`'s or `enum`'s does. */\nexport function prefFitsHeading(leaf: PrefLeaf): boolean {\n return (leaf.kind === 'boolean' || leaf.kind === 'enum') && isBuiltinPref(leaf);\n}\n\n/**\n * The key of the leaf a group or a section draws in its heading: the first\n * directly in it that is marked `heading` and whose control fits there.\n * Undefined for a node with no name, which has no heading to draw it in.\n */\nexport function prefHeadingKey(node: PrefGroup | PrefSection): string | undefined {\n if (node.name === '') return undefined;\n const held = 'members' in node ? node.members : node.children;\n for (const [key, child] of Object.entries(held)) {\n if (isPrefLeaf(child) && child.heading === true && prefFitsHeading(child)) return key;\n }\n return undefined;\n}\n","import { pairRowsOf, type PrefLeaf } from './schema';\n\n/** Neighboring items one row draws, in {@link pairRuns}' answer. */\nexport interface PairRun<T> {\n items: T[];\n /** The pairing the items share: the path of the leaf that declared it, and what the row reads. Absent on a\n * run of one, which is no pair. */\n pair?: { key: string; label: string };\n}\n\n/**\n * `items` as the rows they draw, in order: each leaf a `pair` names joins the row of the leaf naming it where\n * the two are neighbors, and every other item is a run of its own. `leafOf` gives an item's leaf and the path a\n * `pair` would name it by, or nothing for an item that shares no row, which ends a run.\n */\nexport function pairRuns<T>(\n items: readonly T[],\n leafOf: (item: T) => readonly [path: string, leaf: PrefLeaf] | undefined,\n): PairRun<T>[] {\n const leaves = items.map(leafOf);\n const pairs = pairRowsOf(leaves.filter((entry) => entry !== undefined));\n const keys = leaves.map((entry) => (entry === undefined ? undefined : pairs.get(entry[0])));\n const runs: PairRun<T>[] = [];\n for (let i = 0; i < items.length; ) {\n const pair = keys[i];\n let j = i + 1;\n while (pair !== undefined && keys[j]?.key === pair.key) j += 1;\n runs.push(j - i > 1 ? { items: items.slice(i, j), pair } : { items: [items[i]!] });\n i = j;\n }\n return runs;\n}\n","import type { PrefKind } from './schema';\n\n/** What a surface has to know about a kind before it can lay its control out. */\nexport interface PrefKindTraits {\n /** Its value is made of other leaves' values: too much for one control on a\n * line, so a bar opens it in a popover and a compact panel in a dialog. */\n compound: boolean;\n /** Its control is several controls, or a button. A row drawn as a `<label>`\n * would hand a click on its text to the first of them. */\n several: boolean;\n}\n\nconst ONE: PrefKindTraits = { compound: false, several: false };\nconst MANY: PrefKindTraits = { compound: true, several: true };\n\n/**\n * The traits of every built-in kind. A `Record` over {@link PrefKind}, so a\n * kind added to the union does not compile until it says what it is here:\n * a plain set of kind names lets a new one through to draw inline in a\n * `<label>`, on a bar's line, and with no dialog row.\n */\nexport const PREF_KIND_TRAITS: Record<PrefKind, PrefKindTraits> = {\n number: ONE,\n boolean: ONE,\n string: ONE,\n enum: ONE,\n color: ONE,\n paint: ONE,\n object: MANY,\n list: MANY,\n map: MANY,\n union: MANY,\n field: ONE,\n action: { compound: false, several: true },\n alias: ONE,\n label: ONE,\n separator: ONE,\n};\n\nconst traitsOf = (leaf: { kind: string }): PrefKindTraits =>\n (Object.hasOwn(PREF_KIND_TRAITS, leaf.kind) ? PREF_KIND_TRAITS[leaf.kind as PrefKind] : ONE);\n\n/** Whether a leaf's value is made of other leaves' values. An app-defined kind is not: its renderer is one control. */\nexport function prefIsCompound(leaf: { kind: string }): boolean {\n return traitsOf(leaf).compound;\n}\n\n/** Whether a leaf's control is several controls or a button. */\nexport function prefDrawsSeveral(leaf: { kind: string }): boolean {\n return traitsOf(leaf).several;\n}\n"]}