@weasel-js/prefs-schema 1.19.1 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/bounds.ts","../src/shown.ts","../src/judge.ts","../src/statusAt.ts","../src/status.ts","../src/leafValue.ts","../src/build.ts","../src/object.ts","../src/union.ts","../src/groups.ts","../src/repair.ts"],"names":["leaf","under","entry","status","kept","pref","endlessAllows"],"mappings":";;;;;;AAgBO,SAAS,YAAA,CAAaA,OAAkB,IAAA,EAAmC;AAChF,EAAA,MAAM,EAAE,KAAA,EAAO,KAAA,EAAO,GAAG,MAAK,GAAIA,KAAAA;AAClC,EAAA,IAAI,KAAA,KAAU,MAAA,IAAa,KAAA,KAAU,MAAA,EAAW,OAAOA,KAAAA;AACvD,EAAA,MAAM,EAAA,GAAK,QAAQ,IAAI,CAAA;AACvB,EAAA,MAAM,EAAA,GAAK,QAAQ,IAAI,CAAA;AACvB,EAAA,OAAO;AAAA,IACL,GAAG,IAAA;AAAA,IACH,GAAI,EAAA,KAAO,MAAA,GAAY,EAAC,GAAI,EAAE,GAAA,EAAKA,KAAAA,CAAK,GAAA,KAAQ,MAAA,GAAY,KAAK,IAAA,CAAK,GAAA,CAAIA,KAAAA,CAAK,GAAA,EAAK,EAAE,CAAA,EAAE;AAAA,IACxF,GAAI,EAAA,KAAO,MAAA,GAAY,EAAC,GAAI,EAAE,GAAA,EAAKA,KAAAA,CAAK,GAAA,KAAQ,MAAA,GAAY,KAAK,IAAA,CAAK,GAAA,CAAIA,KAAAA,CAAK,GAAA,EAAK,EAAE,CAAA;AAAE,GAC1F;AACF;AAGO,SAAS,eAAA,CAAgBA,OAAkB,CAAA,EAAmB;AACnE,EAAA,IAAI,aAAA,CAAcA,KAAAA,CAAK,OAAA,EAAS,CAAC,GAAG,OAAO,CAAA;AAC3C,EAAA,IAAI,CAAA,GAAI,CAAA;AACR,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AAA,CAAO,MAAM,MAAM,CAAA,SAAUA,KAAAA,CAAK,OAAA;AACpE,EAAA,IAAIM,aAAAA,CAAcN,KAAAA,CAAK,OAAA,EAAS,MAAM,GAAG,OAAO,MAAA;AAChD,EAAA,MAAM,CAAA,GAAI,eAAA,CAAgBA,KAAAA,EAAM,MAAM,CAAA;AACtC,EAAA,OAAO,MAAA,CAAO,QAAA,CAAS,CAAC,CAAA,GAAI,IAAIA,KAAAA,CAAK,OAAA;AACvC","file":"index.js","sourcesContent":["import { endlessAllows } from '@weasel-js/quantity';\nimport type { PrefNumber } from './schema';\n\n/** Reads a value held beside a number leaf, by the path a condition there would name. */\nexport type PrefBoundReader = (path: string) => unknown;\n\n/**\n * A number leaf's bound where its value is held: `undefined` for none. Asked\n * per holder, so each scene node a panel edits can have its own.\n */\nexport type PrefBoundAt = (read: PrefBoundReader) => number | undefined;\n\n/**\n * `leaf` with its `minAt` and `maxAt` read against `read` and folded into\n * `min` and `max`, whichever is tighter. The leaf itself when it has neither.\n */\nexport function prefNumberAt(leaf: PrefNumber, read: PrefBoundReader): PrefNumber {\n const { minAt, maxAt, ...rest } = leaf;\n if (minAt === undefined && maxAt === undefined) return leaf;\n const lo = minAt?.(read);\n const hi = maxAt?.(read);\n return {\n ...rest,\n ...(lo === undefined ? {} : { min: leaf.min === undefined ? lo : Math.max(leaf.min, lo) }),\n ...(hi === undefined ? {} : { max: leaf.max === undefined ? hi : Math.min(leaf.max, hi) }),\n };\n}\n\n/** `n` held to `leaf`'s `min` and `max`, except an infinity an `endless` end stands for. */\nexport function prefClampNumber(leaf: PrefNumber, n: number): number {\n if (endlessAllows(leaf.endless, n)) return n;\n let v = n;\n if (leaf.min !== undefined && v < leaf.min) v = leaf.min;\n if (leaf.max !== undefined && v > leaf.max) v = leaf.max;\n return v;\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 { prefLeavesHolding, prefLeavesHoldingIn, prefSchemaHolding, UNSEEN } from './holding';\nimport type { PrefBoolean, PrefEnum, PrefLeaf } from './schema';\n\ntype Siblings = Record<string, unknown> | undefined;\n\nconst variantOf = (value: unknown, tag: string): unknown =>\n typeof value === 'object' && value !== null ? (value as Record<string, unknown>)[tag] : 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 found = from === 'item' ? item && prefLeavesHoldingIn(item, path) : prefLeavesHolding(prefSchemaHolding(schema, path, over), path);\n if (found === undefined || found === UNSEEN) return stored;\n const held = found.find((each) => (each.variants ?? []).every((v) => variantOf(read(v.at, from), v.tag) === v.key));\n if (held === undefined) 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/** Every field a schema node holds a {@link PrefCondition} in. `activeIf` is an action leaf's alone. */\nexport const PREF_CONDITION_FIELDS = ['showIf', 'enableIf', 'activeIf'] as const;\n\n/** Which of a node's conditions a {@link PrefConditionJudge} is asked about. */\nexport type PrefConditionField = (typeof PREF_CONDITION_FIELDS)[number];\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 status 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 { prefConditionPaths, 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 PrefStatus {\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/**\n * The path a section is named by where a set of paths names it, such as `applyPrefConditions`'s `disabled`: `at`, the\n * path of what holds it, then its key marked so no value path can be the same. `at` is the path of the `object`\n * leaf holding it, empty at a section root, or the path of the section holding it: `'stroke.#edge'`,\n * `'#look.#more'`.\n */\nexport const prefSectionPath = (at: string, key: string): string => (at === '' ? `#${key}` : `${at}.#${key}`);\n\n/** The status a schema's root sits in. */\nexport const PREF_STATUS: PrefStatus = Object.freeze({ shown: true, enabled: true });\n\n/** The status of `node`, which sits directly under something whose status is `above`. */\nexport function prefStatusUnder(\n above: PrefStatus,\n node: { showIf?: PrefCondition; enableIf?: PrefCondition },\n holds: PrefConditionJudge,\n): PrefStatus {\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/** What holds a node: a group, a section, or a leaf with fields, with its own status and the status it sits in. */\nexport interface PrefOwner {\n node: { showIf?: PrefCondition; enableIf?: PrefCondition };\n status: PrefStatus;\n above: PrefStatus;\n /** The path of the list's or the map's entry the owner sits in (`'phases.2'`), under which a condition that reads\n * the entry (`from: 'item'`) names its paths. Unset outside an entry, or where it has no one path. */\n entry?: string;\n}\n\n/**\n * The status a leaf at `path` directly in `owner` sits in: the owner's, except\n * that the owner's own `enableIf` does not disable a leaf it reads. That leaf\n * is the owner's switch, and disabled by its own condition it could never be\n * turned back on. A test that reads the entry reads the leaf at its path\n * under `owner.entry`.\n */\nexport function prefStatusIn(owner: PrefOwner, path: string, holds: PrefConditionJudge): PrefStatus {\n const { node, status, above, entry } = owner;\n if (status.enabled || !above.enabled || node.enableIf === undefined) return status;\n const reads = prefConditionPaths(node.enableIf).includes(path)\n || (entry !== undefined && prefConditionPaths(node.enableIf, 'item').some((p) => `${entry}.${p}` === path));\n if (!reads) return status;\n return prefStatusUnder(above, { showIf: node.showIf }, holds);\n}\n\nconst under = (prefix: string, key: string): string => (prefix === '' ? key : `${prefix}.${key}`);\n\n/** The status of the field at `rest` among the members of `owner`, whose leaves' paths start at `prefix`, or `undefined` when none is there. */\nfunction statusAmong(\n held: PrefSection['members'], prefix: string, rest: string, owner: PrefOwner, holds: PrefConditionJudge,\n): PrefStatus | undefined {\n for (const [key, child] of Object.entries(held)) {\n if (!isPrefLeaf(child)) {\n const found = statusAmong(child.members, prefix, rest, { node: child, status: prefStatusUnder(owner.status, child, holds), above: owner.status }, holds);\n if (found) return found;\n continue;\n }\n if (rest !== key && !rest.startsWith(`${key}.`)) continue;\n const path = under(prefix, key);\n const sits = prefStatusIn(owner, path, holds);\n const status = prefStatusUnder(sits, child, holds);\n return rest === key ? status : statusInside(child, path, rest.slice(key.length + 1), { node: child, status, above: sits }, holds);\n }\n return undefined;\n}\n\n/** The status at `rest` inside `owner`'s leaf, at `path`: that of a field, or the leaf's where `rest` names none. */\nfunction statusInside(leaf: PrefLeaf, path: string, rest: string, owner: PrefOwner, holds: PrefConditionJudge): PrefStatus {\n const { status } = owner;\n if (leaf.kind === 'object') return statusAmong((leaf as PrefObject).children, path, rest, owner, holds) ?? status;\n if (leaf.kind === 'list' || leaf.kind === 'map') {\n const { item } = leaf as Partial<PrefList | PrefMap>;\n if (item === undefined) return status;\n const inItem = deferEntryConditions(holds);\n const entry = prefStatusUnder(status, { enableIf: item.enableIf }, inItem);\n const dot = rest.indexOf('.');\n if (dot < 0) return entry;\n const at = `${path}.${rest.slice(0, dot)}`;\n return statusInside(item, at, rest.slice(dot + 1), { node: { enableIf: item.enableIf }, status: entry, above: status }, inItem);\n }\n if (leaf.kind !== 'union') return status;\n for (const variant of Object.values((leaf as PrefUnion).variants)) {\n const found = statusAmong(variant.children, path, rest, owner, holds);\n if (found) return found;\n }\n return status;\n}\n\nfunction statusAt(schema: PrefGroup | PrefSection, path: string, holds: PrefConditionJudge): PrefStatus {\n let owner: PrefOwner = { node: schema, status: prefStatusUnder(PREF_STATUS, schema, holds), above: PREF_STATUS };\n if (path === '') return owner.status;\n if (isPrefSection(schema)) return statusAmong(schema.members, '', path, owner, holds) ?? owner.status;\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 owner.status;\n const child: PrefLeaf | PrefGroup = node.children[steps[i]!]!;\n const at = steps.slice(0, i + 1).join('.');\n const sits = isPrefLeaf(child) ? prefStatusIn(owner, at, holds) : owner.status;\n owner = { node: child, status: prefStatusUnder(sits, child, holds), above: sits };\n if (isPrefLeaf(child)) return i === steps.length - 1 ? owner.status : statusInside(child, at, steps.slice(i + 1).join('.'), owner, holds);\n node = child;\n }\n return owner.status;\n}\n\n/** `own`, an alias's status by its own conditions, narrowed by that of the leaf it shows in `over`, as `holds` judges `over`. */\nexport function prefAliasStatus(own: PrefStatus, alias: PrefAlias, over: PrefGroup | PrefSection, holds: PrefConditionJudge): PrefStatus {\n const target = prefAliasTarget(alias, (path) => prefLeafAt(over, path));\n if (target === undefined) return own;\n const theirs = statusAt(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 prefStatusAt} is told beyond the schema. */\nexport interface PrefStatusAtOptions {\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 status 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 prefStatusAt(\n schema: PrefGroup | PrefSection, path: string, holds: PrefConditionJudge, { aliasOver, aliasHolds }: PrefStatusAtOptions = {},\n): PrefStatus {\n const own = statusAt(schema, path, holds);\n const leaf = prefLeafAt(schema, path);\n return leaf?.kind === 'alias' ? prefAliasStatus(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 { PrefAction } from './action';\nimport type { PrefAlias } from './alias';\nimport { type PrefCondition, prefConditionReadsItem } from './condition';\nimport type { PrefGroup, PrefSection } from './groups';\nimport { isPrefLeaf, isPrefSection, setOwnPrefValue } 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_STATUS, prefAliasStatus, prefStatusIn, prefStatusUnder, prefSectionPath, type PrefOwner, type PrefStatus } from './statusAt';\nimport type { PrefUnion } from './union';\n\nexport { PREF_CONDITION_FIELDS, prefJudge, prefReader, type PrefConditionField, type PrefConditionJudge, type PrefEntry } from './judge';\nexport { PREF_ENTRY, PREF_STATUS, prefStatusAt, prefStatusIn, prefStatusUnder, prefSectionPath, type PrefOwner, type PrefStatus, type PrefStatusAtOptions } from './statusAt';\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, and of every section by\n * {@link prefSectionPath}. 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 /** The value path of every `action` leaf whose `activeIf` holds, named as `disabled` names what is disabled. */\n active: 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 /** Whether `holds` gives `condition` its real answer, rather than one deferred to another pass. */\n answers: (condition: PrefCondition, holds: PrefConditionJudge) => boolean;\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, answers }: WalkOptions) {\n const disabled = new Set<string>();\n const hidden = new Set<string>();\n const active = new Set<string>();\n\n const leaf = (node: PrefLeaf, path: string, above: PrefStatus, holds: PrefConditionJudge, entry?: string): PrefLeaf | null => {\n const own = prefStatusUnder(above, node, holds);\n const status = node.kind === 'alias' && aliasOver ? prefAliasStatus(own, node as PrefAlias, aliasOver, aliasHolds ?? holds) : own;\n return status.shown || keepHidden ? inside(node, path, status, holds, above, entry) : null;\n };\n\n /** `node`, whose status is `status` in `above`, without what its own value hides: a field, or part of a list's or a\n * map's item. `entry` is the path of the entry it sits in, if any. */\n const inside = (node: PrefLeaf, path: string, status: PrefStatus, holds: PrefConditionJudge, above = status, entry?: string): PrefLeaf => {\n if (!status.shown) hidden.add(path);\n if (!status.enabled) disabled.add(path);\n const { activeIf } = node as Partial<PrefAction>;\n if (node.kind === 'action' && activeIf !== undefined && answers(activeIf, holds) && holds(activeIf, 'activeIf')) active.add(path);\n const owner: PrefOwner = entry === undefined ? { node, status, above } : { node, status, above, entry };\n if (node.kind === 'object') {\n const children = members((node as PrefObject).children, path, owner, 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 at = under(path, PREF_ENTRY);\n const entry = inside(item, at, prefStatusUnder(status, { enableIf: item.enableIf }, inItem), inItem, status, at);\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, owner, holds);\n changed ||= children !== variant.children;\n setOwnPrefValue(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, held by `owner`. `prefix` is the object leaf's path, empty in a\n * section schema, and `within` the path a section among them is named under (`prefSectionPath`). */\n const members = (\n held: PrefSection['members'], prefix: string, owner: PrefOwner, holds: PrefConditionJudge, within = prefix,\n ): PrefSection['members'] => {\n let changed = false;\n const out: PrefSection['members'] = {};\n for (const [key, child] of Object.entries(held)) {\n const at = under(prefix, key);\n const kept = isPrefLeaf(child)\n ? leaf(child, at, prefStatusIn(owner, at, holds), holds, owner.entry)\n : section(child, prefix, prefSectionPath(within, key), owner.status, holds, owner.entry);\n changed ||= kept !== child;\n if (kept !== null) setOwnPrefValue(out, key, kept);\n }\n return changed ? out : held;\n };\n\n const section = (\n node: PrefSection, prefix: string, path: string, above: PrefStatus, holds: PrefConditionJudge, entry?: string,\n ): PrefSection | null => {\n const status = prefStatusUnder(above, node, holds);\n if (!status.shown && !keepHidden) return null;\n if (!status.shown) hidden.add(path);\n if (!status.enabled) disabled.add(path);\n const kept = members(node.members, prefix, entry === undefined ? { node, status, above } : { node, status, above, entry }, holds, path);\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, active, 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 inItem = deferEntryConditions(holds);\n const answers = (condition: PrefCondition, by: PrefConditionJudge): boolean => by !== inItem || !prefConditionReadsItem(condition);\n const walk = leafWalk({ keepEmpty, keepHidden, inItem, aliasOver: aliasOver ?? schema, aliasHolds, answers });\n const { disabled, hidden, active } = walk;\n\n const group = (node: PrefGroup, path: string, above: PrefStatus): PrefGroup | null => {\n const status = prefStatusUnder(above, node, holds);\n if (!status.shown && !keepHidden) return null;\n if (!status.shown && path !== '') hidden.add(path);\n if (!status.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, prefStatusIn({ node, status, above }, at, holds), holds) : group(child, at, status);\n changed ||= kept !== child;\n if (kept !== null) setOwnPrefValue(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_STATUS) as T | null, disabled, hidden, active };\n const status = prefStatusUnder(PREF_STATUS, schema, holds);\n if (!status.shown && !keepHidden) return { shown: null, disabled, hidden, active };\n const kept = walk.members(schema.members, '', { node: schema, status, above: PREF_STATUS }, holds);\n return { shown: kept === schema.members ? schema : { ...schema, members: kept }, disabled, hidden, active };\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 /** The path of every action in the entry whose `activeIf`, which reads the entry, holds. */\n active: 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 answers = (condition: PrefCondition, by: PrefConditionJudge): boolean => by === asked && prefConditionReadsItem(condition);\n const walk = leafWalk({ keepEmpty, keepHidden, inItem: ALWAYS, answers });\n const status = prefStatusUnder(PREF_STATUS, { enableIf: item.enableIf }, asked);\n return { item: walk.inside(item, path, status, asked, PREF_STATUS, path), disabled: walk.disabled, hidden: walk.hidden, active: walk.active };\n}\n","import type { PrefLeaf } from './schema';\n\n/** Whether `held` is no value at all for `leaf`: `undefined`, or `null` except a paint's, which is \"no paint\". */\nexport function prefValueAbsent(leaf: PrefLeaf, held: unknown): boolean {\n return held === undefined || (held === null && leaf.kind !== 'paint');\n}\n\n/**\n * What a params surface shows for the value held at `leaf`: that value, else\n * the leaf's default. A clearable leaf holding nothing is cleared, and shows\n * nothing. `unset` is for a surface where holding nothing means the owner has\n * no such property, a scene node's: it shows nothing there too.\n */\nexport function prefLeafValue(leaf: PrefLeaf, held: unknown, { unset = false }: { unset?: boolean } = {}): unknown {\n if (!prefValueAbsent(leaf, held)) return held;\n if (unset || (leaf as { clearable?: boolean }).clearable === true) return undefined;\n return (leaf as { default?: unknown }).default;\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 { PrefAction, PrefActions } from './action';\nimport type { PrefGroup, PrefSection } from './groups';\nimport type { PrefLabel, PrefSeparator } from './label';\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. */\nexport type PrefLeafRest<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. */\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?: PrefLeafRest<PrefNumber>): PrefNumber & { default: number } =>\n leaf('number', name, def, rest) as PrefNumber & { default: number },\n boolean: (name: string, def: boolean, rest?: PrefLeafRest<PrefBoolean>): PrefBoolean => leaf('boolean', name, def, rest),\n string: (name: string, def: string, rest?: PrefLeafRest<PrefString>): PrefString => leaf('string', name, def, rest),\n color: (name: string, def: string, rest?: PrefLeafRest<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 (T | PrefEnumBase<T>['options'][number])[],\n rest?: Omit<PrefLeafRest<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 button firing the registered action `action` (`id` or `id:variant`). Its name defaults to empty, which shows the action's own label. */\n action: (action: string, rest?: Partial<Omit<PrefAction, 'kind' | 'default' | 'action'>>): PrefAction =>\n leaf('action', '', undefined, { action, ...rest }),\n /** Every action registered in the action group `group`. */\n actions: (group: string, rest?: Partial<Omit<PrefActions, 'kind' | 'default' | 'group'>>): PrefActions =>\n leaf('actions', '', undefined, { group, ...rest }),\n label: (name: string, rest?: PrefLeafRest<PrefLabel>): PrefLabel => leaf('label', name, undefined, rest),\n separator: (): PrefSeparator => leaf('separator', '', undefined, undefined),\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 value of the field `key` in `held`. A dotted key (`'nib.angle'`) names a field of a field. */\nexport function prefObjectField(held: Record<string, unknown> | undefined, key: string): unknown {\n let cursor: unknown = held;\n for (const step of key.split('.')) {\n if (!isObject(cursor)) return undefined;\n cursor = cursor[step];\n }\n return cursor;\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`. A dotted key sets a field of a field, making the objects on\n * the way, and clearing one drops an object it leaves empty. */\nexport function prefObjectWithField(pref: PrefObject, held: unknown, key: string, value: unknown): Record<string, unknown> {\n return withField(prefObjectBase(pref, held), key.split('.'), value);\n}\n\nfunction withField(base: Record<string, unknown>, [step, ...rest]: string[], value: unknown): Record<string, unknown> {\n const next = rest.length === 0 ? value : withField(isObject(base[step]) ? base[step] : {}, rest, value);\n const drops = next === undefined || (rest.length > 0 && Object.keys(next as object).length === 0);\n if (!drops) return { ...base, [step]: next };\n const { [step]: _dropped, ...kept } = base;\n return kept;\n}\n","import type { PrefValueBase, 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 PrefValueBase<'union', unknown> {\n /** The field of the value that names its variant. Not one of `tags`. */\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","// 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 { IconSpec } from '@weasel-js/icons';\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 * `bar` puts its prefs on one line in their bar forms. `menu` is drawn as\n * a menu wherever a menu fits: on a bar, a button opening its contents as a\n * menu; in a menu, a submenu; in a panel, a titled box as `panel` is.\n */\nexport type PrefGroupAs = 'page' | 'tab' | 'panel' | 'section' | 'fragment' | 'bar' | 'menu';\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` asks for its natural length,\n * its lead and every cell, sits at that length where its row is sized to its\n * content, opens the menu only once squeezed shorter, and takes cells back as\n * room returns.\n */\nexport type PrefBarOverflow = 'scroll' | 'menu';\n\n/** What a bar's line starts with, ahead of its cells: `label` puts the bar's name there, and `icon` its `icon`. */\nexport type PrefBarLead = 'label' | 'icon';\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 /** Tags every leaf under the group carries besides its own. A settings\n * search matching one keeps the whole group, as matching its name does. */\n tags?: readonly 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 `as: 'bar'`: what its line starts with. Unset: its first cell. */\n lead?: PrefBarLead;\n /** Glyph naming the group, as a leaf's `icon` names the leaf. A bar drawn\n * with `lead: 'icon'` starts its line with it; the button a bar opens the\n * group from and its submenu row in a menu carry it beside its name. */\n icon?: IconSpec;\n /** The name of the motif its frame is drawn in, where a form draws it framed, defined by an app's `<DefaultMotif\n * named>` (`@weasel-js/ui`). Unset, or a name nothing defines, the form's own look. */\n motif?: string;\n /** The letter that picks this in a menu, and with the menu bar's chord opens a top-level menu. One character; supported, never required. */\n access?: string;\n /** Read on a schema's root only: the selectors a pref's scopes may name\n * that are no pref of the schema, whose option the app names as it reads\n * and writes (`at`): a document, a layout from a server. A scope naming a\n * path that is neither a pref nor admitted here is a schema problem. */\n admits?: readonly string[];\n /** Drawn, with everything under it, only while this holds. */\n showIf?: PrefCondition;\n /** Everything under it is disabled while this does not hold, except a leaf directly in it that this reads: that\n * leaf is the group's switch, often the one marked `heading`, and stays live so the group can be turned back on. */\n enableIf?: PrefCondition;\n /** Its heading offers a reset of every leaf under it, back to what the schema says (`prefResets`). Every\n * leaf's row offers its own reset whether or not this is set. */\n resettable?: boolean;\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 /** As a {@link PrefGroup}'s. */\n tags?: readonly 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 lead?: PrefBarLead;\n /** As a {@link PrefGroup}'s. */\n icon?: IconSpec;\n /** As a {@link PrefGroup}'s. */\n access?: string;\n /** As a {@link PrefGroup}'s. */\n motif?: string;\n /** As a {@link PrefGroup}'s. */\n showIf?: PrefCondition;\n /** As a {@link PrefGroup}'s. */\n enableIf?: PrefCondition;\n /** As a {@link PrefGroup}'s. */\n resettable?: boolean;\n members: Record<string, PrefLeaf | PrefSection>;\n}\n\n/** Whether a panel draws a group or a section drawn `as` this in a bordered, titled box: a `panel`, and a `menu`,\n * which a panel has no menu to open as. */\nexport function prefAsBox(as: PrefGroupAs | undefined): boolean {\n return as === 'panel' || as === 'menu';\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 { isPaint, tryParseColor } from '@weasel-js/paint';\nimport { endlessAllows } from '@weasel-js/quantity';\nimport { codePointFloor, isPlainObject } from '@weasel-js/registry';\nimport { prefClampNumber } from './bounds';\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, PrefString } 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 const { maxLength } = leaf as PrefString;\n if (typeof stored !== 'string') return leaf.default;\n return maxLength !== undefined && stored.length > maxLength ? stored.slice(0, codePointFloor(stored, maxLength)) : stored;\n }\n case 'field':\n return typeof stored === 'string' ? stored : leaf.default;\n case 'color':\n return typeof stored === 'string' && tryParseColor(stored) !== null ? stored : leaf.default;\n case 'paint':\n return stored === null || isPaint(stored) ? 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 if (endlessAllows(leaf.endless, stored)) return stored;\n const v = prefClampNumber(leaf, stored);\n return Number.isFinite(v) ? v : leaf.default;\n}\n"]}
1
+ {"version":3,"sources":["../src/bounds.ts","../src/groupConditions.ts","../src/shown.ts","../src/judge.ts","../src/statusAt.ts","../src/status.ts","../src/leafValue.ts","../src/build.ts","../src/object.ts","../src/union.ts","../src/groups.ts","../src/repair.ts"],"names":["leaf","under","entry","status","kept","pref","getOwn","setOwn","endlessAllows"],"mappings":";;;;;;AAgBO,SAAS,iBAAA,CAAkBA,OAAkB,IAAA,EAAmC;AACrF,EAAA,MAAM,EAAE,KAAA,EAAO,KAAA,EAAO,GAAG,MAAK,GAAIA,KAAAA;AAClC,EAAA,IAAI,KAAA,KAAU,MAAA,IAAa,KAAA,KAAU,MAAA,EAAW,OAAOA,KAAAA;AACvD,EAAA,MAAM,EAAA,GAAK,QAAQ,IAAI,CAAA;AACvB,EAAA,MAAM,EAAA,GAAK,QAAQ,IAAI,CAAA;AACvB,EAAA,OAAO;AAAA,IACL,GAAG,IAAA;AAAA,IACH,GAAI,EAAA,KAAO,MAAA,GAAY,EAAC,GAAI,EAAE,GAAA,EAAKA,KAAAA,CAAK,GAAA,KAAQ,MAAA,GAAY,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,EAAA,MAAM,IAAA,GAAOA,KAAAA,CAAK,QAAA,KAAa,MAAA,IAAa,MAAA,CAAO,MAAA,GAASA,KAAAA,CAAK,QAAA,GAAW,MAAA,CAAO,KAAA,CAAM,CAAA,EAAGA,KAAAA,CAAK,QAAQ,CAAA,GAAI,MAAA;AAC7G,EAAA,MAAM,IAAA,GAAO,IAAA,CAAK,GAAA,CAAI,CAAC,KAAA,KAAU,gBAAgBA,KAAAA,CAAK,IAAA,EAAM,KAAA,EAAO,UAAU,CAAC,CAAA;AAC9E,EAAA,OAAO,IAAA,KAAS,MAAA,IAAU,IAAA,CAAK,KAAA,CAAM,CAAC,KAAA,EAAO,CAAA,KAAM,KAAA,KAAU,MAAA,CAAO,CAAC,CAAC,CAAA,GAAI,MAAA,GAAS,IAAA;AACrF;AAGA,SAAS,YAAA,CAAaA,OAAkB,MAAA,EAA0B;AAChE,EAAA,IAAI,OAAO,WAAW,QAAA,IAAY,MAAA,CAAO,MAAM,MAAM,CAAA,SAAUA,KAAAA,CAAK,OAAA;AACpE,EAAA,IAAIQ,aAAAA,CAAcR,KAAAA,CAAK,OAAA,EAAS,MAAM,GAAG,OAAO,MAAA;AAChD,EAAA,MAAM,CAAA,GAAI,eAAA,CAAgBA,KAAAA,EAAM,MAAM,CAAA;AACtC,EAAA,OAAO,MAAA,CAAO,QAAA,CAAS,CAAC,CAAA,GAAI,IAAIA,KAAAA,CAAK,OAAA;AACvC","file":"index.js","sourcesContent":["import { endlessAllows } from '@weasel-js/quantity';\nimport type { PrefNumber } from './schema';\n\n/** Reads a value held beside a number leaf, by the path a condition there would name. */\nexport type PrefBoundReader = (path: string) => unknown;\n\n/**\n * A number leaf's bound where its value is held: `undefined` for none. Asked\n * per holder, so each scene node a panel edits can have its own.\n */\nexport type PrefBoundAt = (read: PrefBoundReader) => number | undefined;\n\n/**\n * `leaf` with its `minAt` and `maxAt` read against `read` and folded into\n * `min` and `max`, whichever is tighter. The leaf itself when it has neither.\n */\nexport function prefBoundedNumber(leaf: PrefNumber, read: PrefBoundReader): PrefNumber {\n const { minAt, maxAt, ...rest } = leaf;\n if (minAt === undefined && maxAt === undefined) return leaf;\n const lo = minAt?.(read);\n const hi = maxAt?.(read);\n return {\n ...rest,\n ...(lo === undefined ? {} : { min: leaf.min === undefined ? lo : Math.max(leaf.min, lo) }),\n ...(hi === undefined ? {} : { max: leaf.max === undefined ? hi : Math.min(leaf.max, hi) }),\n };\n}\n\n/** `n` held to `leaf`'s `min` and `max`, except an infinity an `endless` end stands for. */\nexport function prefClampNumber(leaf: PrefNumber, n: number): number {\n if (endlessAllows(leaf.endless, n)) return n;\n let v = n;\n if (leaf.min !== undefined && v < leaf.min) v = leaf.min;\n if (leaf.max !== undefined && v > leaf.max) v = leaf.max;\n return v;\n}\n","// Tests a schema reads from a node's own group, turned into tests read from the root, so every reader of conditions\n// sees root paths and a group can be mounted anywhere.\n\nimport { createPart, setOwn } from '@weasel-js/registry';\nimport { isPrefCondition, prefConditionInGroup } from './condition';\nimport type { PrefGroup, PrefSection } from './groups';\n\nconst CONDITIONS = ['showIf', 'enableIf', 'activeIf'] as const;\n\ntype Node = Record<string, unknown>;\n\nconst isNode = (value: unknown): value is Node => typeof value === 'object' && value !== null && !Array.isArray(value);\nconst isGroup = (node: Node): boolean => !('kind' in node) && isNode(node.children);\nconst under = (path: string, key: string): string => (path === '' ? key : `${path}.${key}`);\n\n/** `held` with `each` put through every node in it, the object itself where none changes. */\nfunction mapNodes(held: Node, each: (key: string, node: Node) => Node): Node {\n let out: Node | undefined;\n for (const [key, child] of Object.entries(held)) {\n if (!isNode(child)) continue;\n const next = each(key, child);\n if (next === child) continue;\n out ??= { ...held };\n setOwn(out, key, next);\n }\n return out ?? held;\n}\n\n/**\n * `node`, declared in the group at `group`, with its conditions read from the root, and everything under it likewise.\n * `path` is the node's own path, which a group's children are declared in. Groups sit only in groups; a section's\n * members, a leaf's fields and its item sit in the group their holder does.\n */\nfunction resolveNode(node: Node, group: string, path: string): Node {\n let out: Node | undefined;\n const set = (key: string, value: unknown) => {\n out ??= { ...node };\n setOwn(out, key, value);\n };\n for (const key of CONDITIONS) {\n const condition = node[key];\n // A malformed condition is left as it is, for checkPrefConditions to report.\n if (!isPrefCondition(condition)) continue;\n const next = prefConditionInGroup(condition, group);\n if (next !== condition) set(key, next);\n }\n const inGroup = (_key: string, child: Node) => resolveNode(child, group, path);\n if (isNode(node.children)) {\n const children = isGroup(node)\n ? mapNodes(node.children, (key, child) => resolveNode(child, path, under(path, key)))\n : mapNodes(node.children, inGroup);\n if (children !== node.children) set('children', children);\n }\n if (isNode(node.members)) {\n const members = mapNodes(node.members, inGroup);\n if (members !== node.members) set('members', members);\n }\n if (isNode(node.item)) {\n const item = resolveNode(node.item, group, path);\n if (item !== node.item) set('item', item);\n }\n if (isNode(node.variants)) {\n const variants = mapNodes(node.variants, inGroup);\n if (variants !== node.variants) set('variants', variants);\n }\n return out ?? node;\n}\n\nconst resolvedOf = createPart((schema: object): object => resolveNode(schema as Node, '', ''));\n\n/**\n * `schema` with every condition test read from its node's group (`from: 'group'`) read from the root instead: the\n * form the condition readers, the status walks and the store's checks take. The same object comes back for the same\n * schema, and the schema itself where no test reads from its group.\n */\nexport function resolvePrefGroupConditions<T extends PrefGroup | PrefSection>(schema: T): T {\n return resolvedOf(schema) as T;\n}\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 { getOwn } from '@weasel-js/registry';\nimport type { PrefConditionReader } from './condition';\nimport type { PrefGroup, PrefSection } from './groups';\nimport { prefLeavesHolding, prefLeavesHoldingIn, prefSchemaHolding, UNSEEN } from './holding';\nimport type { PrefBoolean, PrefEnum, PrefLeaf } from './schema';\n\ntype Siblings = Record<string, unknown> | undefined;\n\nconst variantOf = (value: unknown, tag: string): unknown =>\n typeof value === 'object' && value !== null ? getOwn(value as Record<string, unknown>, tag) : 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 prefDecodedValue(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 prefDecodedValue} 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 found = from === 'item' ? item && prefLeavesHoldingIn(item, path) : prefLeavesHolding(prefSchemaHolding(schema, path, over), path);\n if (found === undefined || found === UNSEEN) return stored;\n const held = found.find((each) => (each.variants ?? []).every((v) => variantOf(read(v.at, from), v.tag) === v.key));\n if (held === undefined) return stored;\n const object = held.within === undefined ? undefined : read(held.within, from);\n return prefDecodedValue(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, prefValueAt } from './helpers';\nimport { prefSchemaHolding } from './holding';\nimport type { PrefLeaf } from './schema';\nimport { prefShownReader } from './shown';\n\n/** Every field a schema node holds a {@link PrefCondition} in. `activeIf` is an action leaf's alone. */\nexport const PREF_CONDITION_FIELDS = ['showIf', 'enableIf', 'activeIf'] as const;\n\n/** Which of a node's conditions a {@link PrefConditionJudge} is asked about. */\nexport type PrefConditionField = (typeof PREF_CONDITION_FIELDS)[number];\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 = prefValueAt(value, path);\n return held !== undefined ? held : prefValueAt(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 = prefValueAt(values, path);\n if (held !== undefined) return held;\n if (beyond && prefSchemaHolding(schema, path, over) === over) return beyond(path);\n if (isPrefSection(schema)) {\n const leaves = prefSectionLeaves(schema.members);\n const exact = leaves.find(([key]) => key === path);\n if (exact) return exact[1].default;\n const outer = leaves.find(([key]) => path.startsWith(`${key}.`));\n return outer && prefValueAt(outer[1].default, path.slice(outer[0].length + 1));\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 : prefValueAt(child.default, steps.slice(i + 1).join('.'));\n }\n return undefined;\n };\n}\n","// The status 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 { prefConditionPaths, type PrefCondition } from './condition';\nimport type { PrefGroup, PrefSection } from './groups';\nimport { isPrefLeaf, isPrefSection, prefLeafAt } from './helpers';\nimport { resolvePrefGroupConditions } from './groupConditions';\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 PrefStatus {\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/**\n * The path a section is named by where a set of paths names it, such as `applyPrefConditions`'s `disabled`: `at`, the\n * path of what holds it, then its key marked so no value path can be the same. `at` is the path of the `object`\n * leaf holding it, empty at a section root, or the path of the section holding it: `'stroke.#edge'`,\n * `'#look.#more'`.\n */\nexport const prefSectionPath = (at: string, key: string): string => (at === '' ? `#${key}` : `${at}.#${key}`);\n\n/** The status a schema's root sits in. */\nexport const ROOT_PREF_STATUS: PrefStatus = Object.freeze({ shown: true, enabled: true });\n\n/** The status of `node`, which sits directly under something whose status is `above`. */\nexport function prefStatusUnder(\n above: PrefStatus,\n node: { showIf?: PrefCondition; enableIf?: PrefCondition },\n holds: PrefConditionJudge,\n): PrefStatus {\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/** What holds a node: a group, a section, or a leaf with fields, with its own status and the status it sits in. */\nexport interface PrefOwner {\n node: { showIf?: PrefCondition; enableIf?: PrefCondition };\n status: PrefStatus;\n above: PrefStatus;\n /** The path of the list's or the map's entry the owner sits in (`'phases.2'`), under which a condition that reads\n * the entry (`from: 'item'`) names its paths. Unset outside an entry, or where it has no one path. */\n entry?: string;\n}\n\n/**\n * The status a leaf at `path` directly in `owner` sits in: the owner's, except\n * that the owner's own `enableIf` does not disable a leaf it reads. That leaf\n * is the owner's switch, and disabled by its own condition it could never be\n * turned back on. A test that reads the entry reads the leaf at its path\n * under `owner.entry`.\n */\nexport function prefStatusIn(owner: PrefOwner, path: string, holds: PrefConditionJudge): PrefStatus {\n const { node, status, above, entry } = owner;\n if (status.enabled || !above.enabled || node.enableIf === undefined) return status;\n const reads = prefConditionPaths(node.enableIf).includes(path)\n || (entry !== undefined && prefConditionPaths(node.enableIf, 'item').some((p) => `${entry}.${p}` === path));\n if (!reads) return status;\n return prefStatusUnder(above, { showIf: node.showIf }, holds);\n}\n\nconst under = (prefix: string, key: string): string => (prefix === '' ? key : `${prefix}.${key}`);\n\n/** The status of the field at `rest` among the members of `owner`, whose leaves' paths start at `prefix`, or `undefined` when none is there.\n * A member keyed by all of `rest` answers ahead of one whose key only begins it. */\nfunction statusAmong(\n held: PrefSection['members'], prefix: string, rest: string, owner: PrefOwner, holds: PrefConditionJudge,\n): PrefStatus | undefined {\n return statusMatching(held, prefix, rest, owner, holds, true) ?? statusMatching(held, prefix, rest, owner, holds, false);\n}\n\nfunction statusMatching(\n held: PrefSection['members'], prefix: string, rest: string, owner: PrefOwner, holds: PrefConditionJudge, exact: boolean,\n): PrefStatus | undefined {\n for (const [key, child] of Object.entries(held)) {\n if (!isPrefLeaf(child)) {\n const found = statusMatching(child.members, prefix, rest, { node: child, status: prefStatusUnder(owner.status, child, holds), above: owner.status }, holds, exact);\n if (found) return found;\n continue;\n }\n if (exact ? rest !== key : !rest.startsWith(`${key}.`)) continue;\n const path = under(prefix, key);\n const sits = prefStatusIn(owner, path, holds);\n const status = prefStatusUnder(sits, child, holds);\n return rest === key ? status : statusInside(child, path, rest.slice(key.length + 1), { node: child, status, above: sits }, holds);\n }\n return undefined;\n}\n\n/** The status at `rest` inside `owner`'s leaf, at `path`: that of a field, or the leaf's where `rest` names none. */\nfunction statusInside(leaf: PrefLeaf, path: string, rest: string, owner: PrefOwner, holds: PrefConditionJudge): PrefStatus {\n const { status } = owner;\n if (leaf.kind === 'object') return statusAmong((leaf as PrefObject).children, path, rest, owner, holds) ?? status;\n if (leaf.kind === 'list' || leaf.kind === 'map') {\n const { item } = leaf as Partial<PrefList | PrefMap>;\n if (item === undefined) return status;\n const inItem = deferEntryConditions(holds);\n const entry = prefStatusUnder(status, { enableIf: item.enableIf }, inItem);\n const dot = rest.indexOf('.');\n if (dot < 0) return entry;\n const at = `${path}.${rest.slice(0, dot)}`;\n return statusInside(item, at, rest.slice(dot + 1), { node: { enableIf: item.enableIf }, status: entry, above: status }, inItem);\n }\n if (leaf.kind !== 'union') return status;\n for (const variant of Object.values((leaf as PrefUnion).variants)) {\n const found = statusAmong(variant.children, path, rest, owner, holds);\n if (found) return found;\n }\n return status;\n}\n\nfunction statusAt(schema: PrefGroup | PrefSection, path: string, holds: PrefConditionJudge): PrefStatus {\n let owner: PrefOwner = { node: schema, status: prefStatusUnder(ROOT_PREF_STATUS, schema, holds), above: ROOT_PREF_STATUS };\n if (path === '') return owner.status;\n if (isPrefSection(schema)) return statusAmong(schema.members, '', path, owner, holds) ?? owner.status;\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 owner.status;\n const child: PrefLeaf | PrefGroup = node.children[steps[i]!]!;\n const at = steps.slice(0, i + 1).join('.');\n const sits = isPrefLeaf(child) ? prefStatusIn(owner, at, holds) : owner.status;\n owner = { node: child, status: prefStatusUnder(sits, child, holds), above: sits };\n if (isPrefLeaf(child)) return i === steps.length - 1 ? owner.status : statusInside(child, at, steps.slice(i + 1).join('.'), owner, holds);\n node = child;\n }\n return owner.status;\n}\n\n/** `own`, an alias's status by its own conditions, narrowed by that of the leaf it shows in `over`, as `holds` judges `over`. */\nexport function prefAliasStatus(own: PrefStatus, alias: PrefAlias, overGiven: PrefGroup | PrefSection, holds: PrefConditionJudge): PrefStatus {\n const over = resolvePrefGroupConditions(overGiven);\n const target = prefAliasTarget(alias, (path) => prefLeafAt(over, path));\n if (target === undefined) return own;\n const theirs = statusAt(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 prefStatusAt} is told beyond the schema. */\nexport interface PrefStatusAtOptions {\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 status 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 prefStatusAt(\n schema: PrefGroup | PrefSection, path: string, holds: PrefConditionJudge, { aliasOver, aliasHolds }: PrefStatusAtOptions = {},\n): PrefStatus {\n schema = resolvePrefGroupConditions(schema);\n const own = statusAt(schema, path, holds);\n const leaf = prefLeafAt(schema, path);\n return leaf?.kind === 'alias' ? prefAliasStatus(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 { PrefAction } from './action';\nimport type { PrefAlias } from './alias';\nimport { type PrefCondition, prefConditionReadsItem } from './condition';\nimport type { PrefGroup, PrefSection } from './groups';\nimport { isPrefLeaf, isPrefSection, setOwnPrefValue } from './helpers';\nimport { resolvePrefGroupConditions } from './groupConditions';\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, ROOT_PREF_STATUS, prefAliasStatus, prefStatusIn, prefStatusUnder, prefSectionPath, type PrefOwner, type PrefStatus } from './statusAt';\nimport type { PrefUnion } from './union';\n\nexport { PREF_CONDITION_FIELDS, prefJudge, prefReader, type PrefConditionField, type PrefConditionJudge, type PrefEntry } from './judge';\nexport { PREF_ENTRY, ROOT_PREF_STATUS, prefStatusAt, prefStatusIn, prefStatusUnder, prefSectionPath, type PrefOwner, type PrefStatus, type PrefStatusAtOptions } from './statusAt';\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, and of every section by\n * {@link prefSectionPath}. 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 /** The value path of every `action` leaf whose `activeIf` holds, named as `disabled` names what is disabled. */\n active: 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 /** Whether `holds` gives `condition` its real answer, rather than one deferred to another pass. */\n answers: (condition: PrefCondition, holds: PrefConditionJudge) => boolean;\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, answers }: WalkOptions) {\n const disabled = new Set<string>();\n const hidden = new Set<string>();\n const active = new Set<string>();\n\n const leaf = (node: PrefLeaf, path: string, above: PrefStatus, holds: PrefConditionJudge, entry?: string): PrefLeaf | null => {\n const own = prefStatusUnder(above, node, holds);\n const status = node.kind === 'alias' && aliasOver ? prefAliasStatus(own, node as PrefAlias, aliasOver, aliasHolds ?? holds) : own;\n return status.shown || keepHidden ? inside(node, path, status, holds, above, entry) : null;\n };\n\n /** `node`, whose status is `status` in `above`, without what its own value hides: a field, or part of a list's or a\n * map's item. `entry` is the path of the entry it sits in, if any. */\n const inside = (node: PrefLeaf, path: string, status: PrefStatus, holds: PrefConditionJudge, above = status, entry?: string): PrefLeaf => {\n if (!status.shown) hidden.add(path);\n if (!status.enabled) disabled.add(path);\n const { activeIf } = node as Partial<PrefAction>;\n if (node.kind === 'action' && activeIf !== undefined && answers(activeIf, holds) && holds(activeIf, 'activeIf')) active.add(path);\n const owner: PrefOwner = entry === undefined ? { node, status, above } : { node, status, above, entry };\n if (node.kind === 'object') {\n const children = members((node as PrefObject).children, path, owner, 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 at = under(path, PREF_ENTRY);\n const entry = inside(item, at, prefStatusUnder(status, { enableIf: item.enableIf }, inItem), inItem, status, at);\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, owner, holds);\n changed ||= children !== variant.children;\n setOwnPrefValue(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, held by `owner`. `prefix` is the object leaf's path, empty in a\n * section schema, and `within` the path a section among them is named under (`prefSectionPath`). */\n const members = (\n held: PrefSection['members'], prefix: string, owner: PrefOwner, holds: PrefConditionJudge, within = prefix,\n ): PrefSection['members'] => {\n let changed = false;\n const out: PrefSection['members'] = {};\n for (const [key, child] of Object.entries(held)) {\n const at = under(prefix, key);\n const kept = isPrefLeaf(child)\n ? leaf(child, at, prefStatusIn(owner, at, holds), holds, owner.entry)\n : section(child, prefix, prefSectionPath(within, key), owner.status, holds, owner.entry);\n changed ||= kept !== child;\n if (kept !== null) setOwnPrefValue(out, key, kept);\n }\n return changed ? out : held;\n };\n\n const section = (\n node: PrefSection, prefix: string, path: string, above: PrefStatus, holds: PrefConditionJudge, entry?: string,\n ): PrefSection | null => {\n const status = prefStatusUnder(above, node, holds);\n if (!status.shown && !keepHidden) return null;\n if (!status.shown) hidden.add(path);\n if (!status.enabled) disabled.add(path);\n const kept = members(node.members, prefix, entry === undefined ? { node, status, above } : { node, status, above, entry }, holds, path);\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, active, 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: overGiven, aliasHolds }: PrefConditionsOptions = {},\n): PrefConditionsApplied<T> {\n schema = resolvePrefGroupConditions(schema);\n const aliasOver = overGiven && resolvePrefGroupConditions(overGiven);\n const inItem = deferEntryConditions(holds);\n const answers = (condition: PrefCondition, by: PrefConditionJudge): boolean => by !== inItem || !prefConditionReadsItem(condition);\n const walk = leafWalk({ keepEmpty, keepHidden, inItem, aliasOver: aliasOver ?? schema, aliasHolds, answers });\n const { disabled, hidden, active } = walk;\n\n const group = (node: PrefGroup, path: string, above: PrefStatus): PrefGroup | null => {\n const status = prefStatusUnder(above, node, holds);\n if (!status.shown && !keepHidden) return null;\n if (!status.shown && path !== '') hidden.add(path);\n if (!status.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, prefStatusIn({ node, status, above }, at, holds), holds) : group(child, at, status);\n changed ||= kept !== child;\n if (kept !== null) setOwnPrefValue(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, '', ROOT_PREF_STATUS) as T | null, disabled, hidden, active };\n const status = prefStatusUnder(ROOT_PREF_STATUS, schema, holds);\n if (!status.shown && !keepHidden) return { shown: null, disabled, hidden, active };\n const kept = walk.members(schema.members, '', { node: schema, status, above: ROOT_PREF_STATUS }, holds);\n return { shown: kept === schema.members ? schema : { ...schema, members: kept }, disabled, hidden, active };\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 /** The path of every action in the entry whose `activeIf`, which reads the entry, holds. */\n active: 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 answers = (condition: PrefCondition, by: PrefConditionJudge): boolean => by === asked && prefConditionReadsItem(condition);\n const walk = leafWalk({ keepEmpty, keepHidden, inItem: ALWAYS, answers });\n const status = prefStatusUnder(ROOT_PREF_STATUS, { enableIf: item.enableIf }, asked);\n return { item: walk.inside(item, path, status, asked, ROOT_PREF_STATUS, path), disabled: walk.disabled, hidden: walk.hidden, active: walk.active };\n}\n","import type { PrefLeaf } from './schema';\n\n/** Whether `held` is no value at all for `leaf`: `undefined`, or `null` except a paint's, which is \"no paint\". */\nexport function prefValueAbsent(leaf: PrefLeaf, held: unknown): boolean {\n return held === undefined || (held === null && leaf.kind !== 'paint');\n}\n\n/**\n * What a params surface shows for the value held at `leaf`: that value, else\n * the leaf's default. A clearable leaf holding nothing is cleared, and shows\n * nothing. `unset` is for a surface where holding nothing means the owner has\n * no such property, a scene node's: it shows nothing there too.\n */\nexport function prefValueOrDefault(leaf: PrefLeaf, held: unknown, { unset = false }: { unset?: boolean } = {}): unknown {\n if (!prefValueAbsent(leaf, held)) return held;\n if (unset || (leaf as { clearable?: boolean }).clearable === true) return undefined;\n return (leaf as { default?: unknown }).default;\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 { PrefAction, PrefActions } from './action';\nimport type { PrefGroup, PrefSection } from './groups';\nimport type { PrefLabel, PrefSeparator } from './label';\nimport type { PrefBoolean, PrefColor, PrefEnumBase, PrefLeaf, PrefNumberBase, PrefString } from './schema';\n\n/** What a builder takes after the leaf's name and default: any of the leaf's other fields. */\nexport type PrefLeafRest<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. */\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?: PrefLeafRest<PrefNumberBase>): PrefNumberBase & { default: number; clearable?: false } =>\n leaf('number', name, def, rest) as PrefNumberBase & { default: number; clearable?: false },\n boolean: (name: string, def: boolean, rest?: PrefLeafRest<PrefBoolean>): PrefBoolean => leaf('boolean', name, def, rest),\n string: (name: string, def: string, rest?: PrefLeafRest<PrefString>): PrefString => leaf('string', name, def, rest),\n color: (name: string, def: string, rest?: PrefLeafRest<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 (T | PrefEnumBase<T>['options'][number])[],\n rest?: Omit<PrefLeafRest<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 button firing the registered action `action` (`id` or `id:variant`). Its name defaults to empty, which shows the action's own label. */\n action: (action: string, rest?: Partial<Omit<PrefAction, 'kind' | 'default' | 'action'>>): PrefAction =>\n leaf('action', '', undefined, { action, ...rest }),\n /** Every action registered in the action group `group`. */\n actions: (group: string, rest?: Partial<Omit<PrefActions, 'kind' | 'default' | 'group'>>): PrefActions =>\n leaf('actions', '', undefined, { group, ...rest }),\n label: (name: string, rest?: PrefLeafRest<PrefLabel>): PrefLabel => leaf('label', name, undefined, rest),\n separator: (): PrefSeparator => leaf('separator', '', undefined, undefined),\n};\n","import { getOwn } from '@weasel-js/registry';\nimport 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 a held scalar lifted by the leaf's `fromScalar`,\n * else 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 const lifted = held === undefined ? undefined : pref.fromScalar?.(held);\n return lifted ?? (isObject(pref.default) ? pref.default : {});\n}\n\n/** The value of the field `key` in `held`. A dotted key (`'nib.angle'`) names a field of a field. */\nexport function prefObjectField(held: Record<string, unknown> | undefined, key: string): unknown {\n let cursor: unknown = held;\n for (const step of key.split('.')) {\n if (!isObject(cursor)) return undefined;\n cursor = getOwn(cursor, step);\n }\n return cursor;\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`. A dotted key sets a field of a field, making the objects on\n * the way, and clearing one drops an object it leaves empty. */\nexport function prefObjectWithField(pref: PrefObject, held: unknown, key: string, value: unknown): Record<string, unknown> {\n return withField(prefObjectBase(pref, held), key.split('.'), value);\n}\n\nfunction withField(base: Record<string, unknown>, [step, ...rest]: string[], value: unknown): Record<string, unknown> {\n const held = getOwn(base, step);\n const next = rest.length === 0 ? value : withField(isObject(held) ? held : {}, rest, value);\n const drops = next === undefined || (rest.length > 0 && Object.keys(next as object).length === 0);\n if (!drops) return { ...base, [step]: next };\n const { [step]: _dropped, ...kept } = base;\n return kept;\n}\n","import { getOwn } from '@weasel-js/registry';\nimport type { PrefValueBase, 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 PrefValueBase<'union', unknown> {\n /** The field of the value that names its variant. Not one of `tags`. */\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 = getOwn(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 = getOwn(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","// 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 { IconSpec } from '@weasel-js/icons';\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 * `bar` puts its prefs on one line in their bar forms. `menu` is drawn as\n * a menu wherever a menu fits: on a bar, a button opening its contents as a\n * menu; in a menu, a submenu; in a panel, a titled box as `panel` is.\n */\nexport type PrefGroupAs = 'page' | 'tab' | 'panel' | 'section' | 'fragment' | 'bar' | 'menu';\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` asks for its natural length,\n * its lead and every cell, sits at that length where its row is sized to its\n * content, opens the menu only once squeezed shorter, and takes cells back as\n * room returns.\n */\nexport type PrefBarOverflow = 'scroll' | 'menu';\n\n/** What a bar's line starts with, ahead of its cells: `label` puts the bar's name there, and `icon` its `icon`. */\nexport type PrefBarLead = 'label' | 'icon';\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 /** Tags every leaf under the group carries besides its own. A settings\n * search matching one keeps the whole group, as matching its name does. */\n tags?: readonly 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 `as: 'bar'`: what its line starts with. Unset: its first cell. */\n lead?: PrefBarLead;\n /** Glyph naming the group, as a leaf's `icon` names the leaf. A bar drawn\n * with `lead: 'icon'` starts its line with it; the button a bar opens the\n * group from and its submenu row in a menu carry it beside its name. */\n icon?: IconSpec;\n /** The name of the motif its frame is drawn in, where a form draws it framed, defined by an app's `<DefaultMotif\n * named>` (`@weasel-js/ui`). Unset, or a name nothing defines, the form's own look. */\n motif?: string;\n /** The letter that picks this in a menu, and with the menu bar's chord opens a top-level menu. One character; supported, never required. */\n access?: string;\n /** Read on a schema's root only: the selectors a pref's scopes may name\n * that are no pref of the schema, whose option the app names as it reads\n * and writes (`at`): a document, a layout from a server. A scope naming a\n * path that is neither a pref nor admitted here is a schema problem. */\n admits?: readonly string[];\n /** Drawn, with everything under it, only while this holds. */\n showIf?: PrefCondition;\n /** Everything under it is disabled while this does not hold, except a leaf directly in it that this reads: that\n * leaf is the group's switch, often the one marked `heading`, and stays live so the group can be turned back on. */\n enableIf?: PrefCondition;\n /** Its heading offers a reset of every leaf under it, back to what the schema says (`prefResets`). Every\n * leaf's row offers its own reset whether or not this is set. */\n resettable?: boolean;\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 /** As a {@link PrefGroup}'s. */\n tags?: readonly 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 lead?: PrefBarLead;\n /** As a {@link PrefGroup}'s. */\n icon?: IconSpec;\n /** As a {@link PrefGroup}'s. */\n access?: string;\n /** As a {@link PrefGroup}'s. */\n motif?: string;\n /** As a {@link PrefGroup}'s. */\n showIf?: PrefCondition;\n /** As a {@link PrefGroup}'s. */\n enableIf?: PrefCondition;\n /** As a {@link PrefGroup}'s. */\n resettable?: boolean;\n members: Record<string, PrefLeaf | PrefSection>;\n}\n\n/** Whether a panel draws a group or a section drawn `as` this in a bordered, titled box: a `panel`, and a `menu`,\n * which a panel has no menu to open as. */\nexport function prefDrawsAsBox(as: PrefGroupAs | undefined): boolean {\n return as === 'panel' || as === 'menu';\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 { isPaint, tryParseColor } from '@weasel-js/paint';\nimport { endlessAllows } from '@weasel-js/quantity';\nimport { codePointFloor, getOwn, isPlainObject, setOwn } from '@weasel-js/registry';\nimport { prefClampNumber } from './bounds';\nimport { prefSectionLeaves } from './helpers';\nimport { prefObjectField, prefObjectWithField } from './object';\nimport type { PrefList } from './list';\nimport type { PrefMap } from './map';\nimport { prefVariantOf, type PrefUnion } from './union';\nimport type { PrefBoolean, PrefEnum, PrefLeaf, PrefNumber, PrefObject, PrefString } 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 && getOwn(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 const { maxLength } = leaf as PrefString;\n if (typeof stored !== 'string') return leaf.default;\n return maxLength !== undefined && stored.length > maxLength ? stored.slice(0, codePointFloor(stored, maxLength)) : stored;\n }\n case 'field':\n return typeof stored === 'string' ? stored : leaf.default;\n case 'color':\n return typeof stored === 'string' && tryParseColor(stored) !== null ? stored : leaf.default;\n case 'paint':\n return stored === null || isPaint(stored) ? 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 = stored;\n for (const [key, field] of prefSectionLeaves(leaf.children)) {\n const held = prefObjectField(stored, key);\n if (held === undefined) continue;\n const read = repairPrefValue(field, held, validators);\n if (read !== held) out = prefObjectWithField(leaf, out, key, read);\n }\n return out;\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) setOwn((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 if (endlessAllows(leaf.endless, stored)) return stored;\n const v = prefClampNumber(leaf, stored);\n return Number.isFinite(v) ? v : leaf.default;\n}\n"]}