@weasel-js/routing 1.15.0 → 1.15.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { createDepRegistry, ScopeNode, overrideActionBindings, tuneAction, evaluateEnabled, tunedParams, resolveBindingOverrides, createMenuHost, pushOwner, validateActionId, validateActionDefaultBinding, buildDepsFromRequires, resolveParams } from './chunk-A6MN3I6R.js';
1
+ import { createDepRegistry, ScopeNode, overrideActionBindings, tuneAction, evaluateEnabled, tunedParams, resolveBindingOverrides, createMenuHost, pushOwner, validateActionId, validateActionDefaultBinding, buildDepsFromRequires, resolveParams } from './chunk-Z2BZBJ7W.js';
2
2
  import { createContext, useState, useContext, useEffect, useMemo } from 'react';
3
3
  import { isDev, useLatest } from '@weasel-js/react';
4
4
  import { jsx } from 'react/jsx-runtime';
@@ -125,6 +125,7 @@ var LastOperationKeeper = class {
125
125
  }
126
126
  held.op = { ...held.op, values };
127
127
  this.remember(held.op.id, values);
128
+ held.keep(values);
128
129
  this.listeners.emit();
129
130
  return true;
130
131
  };
@@ -153,7 +154,8 @@ var LastOperationKeeper = class {
153
154
  if (entry !== null && out !== "pass") {
154
155
  const rest = without(given, values);
155
156
  const op = { id: action.id, label: schema.name || action.label, schema, values };
156
- this.hold({ op, entry, stack, history, restore, rerun: (v) => host.rerun(action.id, { ...rest, ...v }) });
157
+ const keep = (v) => host.keep(action.id, v);
158
+ this.hold({ op, entry, stack, history, restore, keep, rerun: (v) => host.rerun(action.id, { ...rest, ...v }) });
157
159
  }
158
160
  return out;
159
161
  };
@@ -165,10 +167,10 @@ var LastOperationKeeper = class {
165
167
  const start = (ctx, opts) => {
166
168
  const history = this.busy ? null : host.history();
167
169
  const restore = history ? host.takeSelection() : null;
170
+ const stack = history ? editStackOf(history) : null;
168
171
  const handle = invoker.start(ctx, opts);
169
172
  const { onEnd, replay } = handle;
170
- if (!history || !onEnd || !replay) return handle;
171
- const stack = editStackOf(history);
173
+ if (!history || !stack || !onEnd || !replay) return handle;
172
174
  const watch = watchEntry(stack);
173
175
  const ended = (endCtx, reason) => {
174
176
  let entry = null;
@@ -178,13 +180,14 @@ var LastOperationKeeper = class {
178
180
  entry = watch.stop();
179
181
  }
180
182
  if (reason !== "commit" || entry === null) return;
181
- const resolved = host.paramsOf(id, resolveParams(opts?.params));
183
+ const resolved = { ...host.paramsOf(id, resolveParams(opts?.params)), ...handle.params?.() };
182
184
  const schema = schemaOf(resolved);
183
185
  if (!schema) return;
184
186
  const values = formValues(schema, resolved);
185
187
  const rest = without(resolved, values);
186
188
  const op = { id, label: schema.name || label, schema, values };
187
- this.hold({ op, entry, stack, history, restore, rerun: (v) => replay.call(handle, { ...rest, ...v }) });
189
+ const keep = (v) => host.keep(id, v);
190
+ this.hold({ op, entry, stack, history, restore, keep, rerun: (v) => replay.call(handle, { ...rest, ...v }) });
188
191
  };
189
192
  return { ...handle, onEnd: ended };
190
193
  };
@@ -279,6 +282,9 @@ var ActionsNode = class extends ScopeNode {
279
282
  if (a?.invoker?.timing !== "immediate") return;
280
283
  const deps = depsFor(a, this.deps());
281
284
  if (evaluateEnabled(a, deps, pointOf(params)).enabled) a.invoker.run(deps, params);
285
+ },
286
+ keep: (id, params) => {
287
+ for (const t of this.tuningsOf(id)) t.keep?.(params);
282
288
  }
283
289
  };
284
290
  }
@@ -512,5 +518,5 @@ function useAction(action) {
512
518
  }
513
519
 
514
520
  export { ActionsContext, ActionsNode, ActionsProvider, DepRegistryContext, DepRegistryProvider, MenuHostContext, actionsNodeOf, useAction, useActionsRegistry, useDepRegistry, useDepSource, useMenuHost, useMenus, useOptionalDepRegistry };
515
- //# sourceMappingURL=chunk-3SPPC6UP.js.map
516
- //# sourceMappingURL=chunk-3SPPC6UP.js.map
521
+ //# sourceMappingURL=chunk-VAUJJODS.js.map
522
+ //# sourceMappingURL=chunk-VAUJJODS.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/interactions/actions/depRegistry.tsx","../src/menus/MenuHostContext.tsx","../src/interactions/actions/lastOperation.ts","../src/interactions/actions/ActionsProvider.tsx"],"names":["createContext","useContext","useEffect","useLatest","jsx"],"mappings":";;;;;;;AAaO,IAAM,kBAAA,GAAqB,cAAkC,IAAI;AAIjE,SAAS,mBAAA,CAAoB,EAAE,QAAA,EAAS,EAA4B;AACzE,EAAA,MAAM,CAAC,QAAQ,CAAA,GAAI,QAAA,CAAS,iBAAiB,CAAA;AAC7C,EAAA,2BAAQ,kBAAA,CAAmB,QAAA,EAAnB,EAA4B,KAAA,EAAO,UAAW,QAAA,EAAS,CAAA;AACjE;AAGO,SAAS,cAAA,GAA8B;AAC5C,EAAA,MAAM,CAAA,GAAI,WAAW,kBAAkB,CAAA;AACvC,EAAA,IAAI,MAAM,IAAA,EAAM;AACd,IAAA,MAAM,IAAI,MAAM,8HAA8H,CAAA;AAAA,EAChJ;AACA,EAAA,OAAO,CAAA;AACT;AAOO,SAAS,sBAAA,GAA6C;AAC3D,EAAA,OAAO,WAAW,kBAAkB,CAAA;AACtC;AAKO,SAAS,YAAA,CAAgC,MAAS,MAAA,EAAsB;AAC7E,EAAA,MAAM,WAAW,cAAA,EAAe;AAChC,EAAA,MAAM,SAAA,GAAY,UAAU,MAAM,CAAA;AAClC,EAAA,SAAA,CAAU,MAAM;AACd,IAAA,OAAO,QAAA,CAAS,SAAS,IAAA,EAAM,CAAC,UAAU,SAAA,CAAU,OAAA,CAAQ,KAAK,CAAC,CAAA;AAAA,EACpE,CAAA,EAAG,CAAC,IAAA,EAAM,QAAA,EAAU,SAAS,CAAC,CAAA;AAChC;AC7CO,IAAM,eAAA,GAAkBA,cAA+B,IAAI;AAI3D,SAAS,WAAA,GAA+B;AAC7C,EAAA,OAAOC,WAAW,eAAe,CAAA;AACnC;AAGO,SAAS,QAAA,CAAS,IAAA,EAA0B,KAAA,GAAuB,IAAA,EAAY;AACpF,EAAA,MAAM,OAAO,WAAA,EAAY;AACzB,EAAAC,UAAU,MAAM;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AAClB","file":"chunk-VAUJJODS.js","sourcesContent":["/** The React seam over the dep registry in `./depNode`: its provider and hooks. */\nimport {\n createContext, useContext, useEffect, useState,\n type ReactNode,\n} from 'react';\nimport type { DepSchema, DepName } from '../../index';\nimport { createDepRegistry, type DepRegistry, type DepSource } from './depNode';\nimport { useLatest } from '@weasel-js/react';\n\nexport type { DepSchema, DepName, DepRegistry, DepSource };\nexport { DepNode, depNodeOf, createDepRegistry } from './depNode';\n\n/** @internal The context `<InputScope>` provides a scope's dep registry through. */\nexport const DepRegistryContext = createContext<DepRegistry | null>(null);\n\n/** Provides the dep registry for a canvas. `<SceneCanvas>` mounts one; a\n * consumer registering its own dep sources must be inside it. */\nexport function DepRegistryProvider({ children }: { children: ReactNode }) {\n const [registry] = useState(createDepRegistry);\n return <DepRegistryContext.Provider value={registry}>{children}</DepRegistryContext.Provider>;\n}\n\n/** The dep registry in scope. Throws outside a `<DepRegistryProvider>`. */\nexport function useDepRegistry(): DepRegistry {\n const r = useContext(DepRegistryContext);\n if (r === null) {\n throw new Error('useDepRegistry: no DepRegistryProvider in scope. Wrap your tree with <DepRegistryProvider> (typically inside <SceneCanvas>).');\n }\n return r;\n}\n\n/**\n * Like `useDepRegistry`, but returns `null` when no `<DepRegistryProvider>` is\n * in scope instead of throwing. Used by `useStandardActions` to preserve its\n * silent-no-op contract when neither provider is present.\n */\nexport function useOptionalDepRegistry(): DepRegistry | null {\n return useContext(DepRegistryContext);\n}\n\n/** Register a live source for `name` for the lifetime of the calling\n * component. The `source` thunk is called at dispatch time and should\n * return the latest value; its `below` reads the source it displaced. */\nexport function useDepSource<K extends DepName>(name: K, source: DepSource<K>) {\n const registry = useDepRegistry();\n const sourceRef = useLatest(source);\n useEffect(() => {\n return registry.register(name, (below) => sourceRef.current(below));\n }, [name, registry, sourceRef]);\n}\n","import { createContext, useContext, useEffect } from 'react';\nimport type { MenuHost } from './menuHost';\nimport type { MenuDef } from './types';\n\nexport const MenuHostContext = createContext<MenuHost | null>(null);\n\n/** The menu host in scope: the nearest `<ActionsProvider>`'s, else the one a\n * canvas with no provider above it makes. Null outside both. */\nexport function useMenuHost(): MenuHost | null {\n return useContext(MenuHostContext);\n}\n\n/** Declare menus for the calling component's lifetime. Memoize `defs`. */\nexport function useMenus(defs: readonly MenuDef[], owner: string | null = null): void {\n const host = useMenuHost();\n useEffect(() => {\n if (!host) return;\n const releases = defs.map((d) => host.define(d, owner));\n return () => { for (const r of releases) r(); };\n }, [host, defs, owner]);\n}\n","/**\n * The last operation: the latest run of an action that declares `params` and\n * committed one history entry, kept so its params can be changed after the\n * fact. A change undoes that entry and runs the action again in its place: an\n * immediate action is run again with the params it was handed, and a gesture\n * is replayed by its handle (`OngoingHandle.replay`).\n */\nimport type { History } from '@weasel-js/history';\nimport { prefLeaves, type PrefGroup } from '@weasel-js/prefs';\nimport { createEmitter } from '@weasel-js/registry';\nimport type { Action } from './action';\nimport { resolveParams, type ImmediateInvoker, type OngoingHandle, type OngoingInvoker } from './invoker';\nimport type { ActionTuning } from './tuning';\n\n/** One operation that can still be adjusted. */\nexport interface LastOperation {\n id: string;\n /** What a panel titles it: the form's name, else the action's label. */\n label: string;\n /** The action's `params` form. */\n schema: PrefGroup;\n /** What it ran with, one value per leaf of `schema`, by the leaf's path. */\n values: Readonly<Record<string, unknown>>;\n}\n\n/** The last operation of one actions tree, and the two things to do with it. */\nexport interface LastOperationStore {\n /** The operation, or `null` once anything else reached the history, or it was dismissed. */\n get(): LastOperation | null;\n subscribe(listener: () => void): () => void;\n /**\n * Undo the operation's entry, put back the selection it ran on, and run it again with `patch` laid over its\n * values (a gesture is replayed by its handle), keeping the entry that makes in place of the old one: the\n * history, or the journal open on it, still holds one entry for it. The merged values become the action's\n * params for the rest of the session, under any tuning, and each tuning that keeps them is handed them\n * (`ActionTuning.keep`). Returns whether it ran.\n */\n adjust(patch: Readonly<Record<string, unknown>>): boolean;\n /** Forget the operation; the scene and the history stay as they are. */\n dismiss(): void;\n}\n\n/** Every selection a host holds, captured: calling what `take` returns puts all of it back. */\nexport interface SelectionSnapshotDep {\n take(): () => void;\n}\n\n/** What the store reads from the scope an operation ran in. */\nexport interface LastOperationHost {\n history(): History | null;\n takeSelection(): (() => void) | null;\n /** The params a run of `id` handed `given` starts with: every tuning's, `given` laid over them. */\n paramsOf(id: string, given: Record<string, unknown> | undefined): Record<string, unknown>;\n /** Run the action live for `id` here with `params`, as `trigger` would. */\n rerun(id: string, params: Record<string, unknown>): void;\n /** Hand `params`, which a panel change made `id`'s for the session, to each tuning of `id` that keeps them. */\n keep(id: string, params: Readonly<Record<string, unknown>>): void;\n}\n\n/** Where an edit lands: the history, or the journal open on it. */\ntype EditStack = Pick<History, 'seal' | 'observe' | 'entries' | 'undo'>;\n\n/** The stack edits on `history` land on now: its active journal while one is open, which takes the entries an\n * edit makes until it commits them to `history` as one. */\nfunction editStackOf(history: History): EditStack {\n const journal = history.activeJournal?.();\n return journal?.isActive() ? journal : history;\n}\n\ninterface Held {\n op: LastOperation;\n entry: number | null;\n /** The stack the operation's entry is on. */\n stack: EditStack;\n /** The history that stack belongs to, any change on which ends the operation. */\n history: History;\n restore: (() => void) | null;\n /** Run the operation again with `values`, laid over what its first run was handed beyond them, such as the\n * point a binding carried. */\n rerun: (values: Record<string, unknown>) => void;\n /** Hand `values` to the tunings that keep the action's params. */\n keep: (values: Readonly<Record<string, unknown>>) => void;\n unobserve: () => void;\n}\n\n/** Watch `stack` from now: `stop` answers the id of the entry pushed meanwhile when exactly one was, later\n * pushes having coalesced into it, and nothing else changed the history. Seals first, so the entry stands alone\n * rather than coalescing into the one before it. */\nfunction watchEntry(stack: EditStack): { stop(): number | null } {\n stack.seal();\n let entry: number | null = null;\n let clean = true;\n const off = stack.observe((step) => {\n if (step.kind === 'push' && entry === null && step.entries.length === 1) entry = step.entries[0]!.id;\n else if (!(step.kind === 'coalesce' && step.entries[0]?.id === entry && entry !== null)) clean = false;\n });\n return {\n stop: () => {\n off();\n return clean ? entry : null;\n },\n };\n}\n\n/** Run `run`, and the id of the entry it pushed as {@link watchEntry} counts it. */\nfunction soleEntry<T>(stack: EditStack, run: () => T): { out: T; entry: number | null } {\n const watch = watchEntry(stack);\n let out: T;\n try {\n out = run();\n } catch (err) {\n watch.stop();\n throw err;\n }\n return { out, entry: watch.stop() };\n}\n\n/** `params`, reduced to the leaves of `schema`, each filled from its default where `params` has none. */\nfunction formValues(schema: PrefGroup, params: Readonly<Record<string, unknown>>): Record<string, unknown> {\n const out: Record<string, unknown> = {};\n for (const [path, leaf] of prefLeaves(schema)) out[path] = params[path] !== undefined ? params[path] : leaf.default;\n return out;\n}\n\nfunction without(params: Record<string, unknown> | undefined, keys: Readonly<Record<string, unknown>>): Record<string, unknown> {\n const out: Record<string, unknown> = {};\n for (const [k, v] of Object.entries(params ?? {})) if (!(k in keys)) out[k] = v;\n return out;\n}\n\n/** The store one actions tree keeps at its root. `onSession` is told when an action's session params change. */\nexport class LastOperationKeeper implements LastOperationStore {\n private held: Held | null = null;\n private busy = false;\n private readonly listeners = createEmitter();\n private readonly session = new Map<string, ActionTuning>();\n\n constructor(private readonly onSession: () => void) {}\n\n readonly get = (): LastOperation | null => this.held?.op ?? null;\n\n readonly subscribe = (listener: () => void): (() => void) => this.listeners.subscribe(listener);\n\n readonly dismiss = (): void => {\n const held = this.held;\n if (!held) return;\n this.held = null;\n held.unobserve();\n this.listeners.emit();\n };\n\n readonly adjust = (patch: Readonly<Record<string, unknown>>): boolean => {\n const held = this.held;\n if (!held || this.busy) return false;\n const { stack } = held;\n const moved = editStackOf(held.history) !== stack;\n if (moved || (held.entry !== null && stack.entries().undo.at(-1)?.id !== held.entry)) {\n this.dismiss();\n return false;\n }\n const values = formValues(held.op.schema, { ...held.op.values, ...patch });\n this.busy = true;\n try {\n if (held.entry !== null) stack.undo();\n held.restore?.();\n held.entry = soleEntry(stack, () => {\n try {\n held.rerun(values);\n } catch (err) {\n console.error(`weasel last operation: rerunning \"${held.op.id}\" threw`, err);\n }\n }).entry;\n } finally {\n this.busy = false;\n }\n held.op = { ...held.op, values };\n this.remember(held.op.id, values);\n held.keep(values);\n this.listeners.emit();\n return true;\n };\n\n /** The tuning holding `id`'s session params, laid under every other; `null` before it has any. */\n sessionTuning(id: string): ActionTuning | null {\n return this.session.get(id) ?? null;\n }\n\n /** `action` with its run kept as the last operation when it commits one entry: an immediate action declaring\n * `params`, or an ongoing one declaring them whose gesture's handle can `replay`, and in either case only a\n * run its `params` answers a form for. Any other action comes back as it is. */\n wrap(action: Action, host: LastOperationHost): Action {\n const { params: form, invoker } = action;\n if (!form || !invoker) return action;\n const schemaOf = typeof form === 'function' ? form : () => form;\n if (invoker.timing === 'ongoing') return { ...action, invoker: this.ongoing(action.id, action.label, schemaOf, invoker, host) };\n const run: ImmediateInvoker['run'] = (deps, given) => {\n const history = this.busy ? null : host.history();\n if (!history) return invoker.run(deps, given);\n const resolved = host.paramsOf(action.id, given);\n const schema = schemaOf(resolved);\n if (!schema) return invoker.run(deps, given);\n const restore = host.takeSelection();\n const values = formValues(schema, resolved);\n const stack = editStackOf(history);\n const { out, entry } = soleEntry(stack, () => invoker.run(deps, given));\n if (entry !== null && out !== 'pass') {\n const rest = without(given, values);\n const op = { id: action.id, label: schema.name || action.label, schema, values };\n const keep = (v: Readonly<Record<string, unknown>>) => host.keep(action.id, v);\n this.hold({ op, entry, stack, history, restore, keep, rerun: (v) => host.rerun(action.id, { ...rest, ...v }) });\n }\n return out;\n };\n return { ...action, invoker: { timing: 'immediate', run } };\n }\n\n /** `invoker` with each gesture whose handle can `replay` kept as the last operation when its commit leaves\n * one entry. The selection is taken at the press and the params at the release, as the commit read them. */\n private ongoing(id: string, label: string, schemaOf: (params: Readonly<Record<string, unknown>>) => PrefGroup | null, invoker: OngoingInvoker, host: LastOperationHost): OngoingInvoker {\n const start: OngoingInvoker['start'] = (ctx, opts) => {\n const history = this.busy ? null : host.history();\n const restore = history ? host.takeSelection() : null;\n // Read before `start`, which may open a journal of its own that lands on this stack as one entry.\n const stack = history ? editStackOf(history) : null;\n const handle = invoker.start(ctx, opts);\n const { onEnd, replay } = handle;\n if (!history || !stack || !onEnd || !replay) return handle;\n const watch = watchEntry(stack);\n const ended: OngoingHandle['onEnd'] = (endCtx, reason) => {\n let entry: number | null = null;\n try {\n onEnd.call(handle, endCtx, reason);\n } finally {\n entry = watch.stop();\n }\n if (reason !== 'commit' || entry === null) return;\n const resolved = { ...host.paramsOf(id, resolveParams(opts?.params)), ...handle.params?.() };\n const schema = schemaOf(resolved);\n if (!schema) return;\n const values = formValues(schema, resolved);\n const rest = without(resolved, values);\n const op = { id, label: schema.name || label, schema, values };\n const keep = (v: Readonly<Record<string, unknown>>) => host.keep(id, v);\n this.hold({ op, entry, stack, history, restore, keep, rerun: (v) => replay.call(handle, { ...rest, ...v }) });\n };\n return { ...handle, onEnd: ended };\n };\n return { ...invoker, start };\n }\n\n private hold(held: Omit<Held, 'unobserve'>): void {\n this.held?.unobserve();\n const ended = () => {\n if (!this.busy) this.dismiss();\n };\n const offs = [held.stack.observe(ended)];\n if (held.stack !== held.history) offs.push(held.history.observe(ended));\n const unobserve = () => { for (const off of offs) off(); };\n this.held = { ...held, unobserve };\n this.remember(held.op.id, held.op.values);\n this.listeners.emit();\n }\n\n private remember(id: string, values: Readonly<Record<string, unknown>>): void {\n this.session.set(id, { params: { ...values } });\n this.onSession();\n }\n}\n","/**\n * The React half of the actions registry: the context, the tree node that\n * owns each id → descriptor stack, the providers that mount nodes, and the two\n * hooks. The store contract it implements is in `registry.ts`.\n */\nimport {\n createContext,\n useContext,\n useEffect,\n useMemo,\n type ReactElement,\n type ReactNode,\n} from 'react';\nimport type { Action } from './action';\nimport { evaluateEnabled } from './actionEnabled';\nimport { useLatest } from '@weasel-js/react';\nimport {\n useOptionalDepRegistry,\n type DepRegistry,\n type DepName,\n} from './depRegistry';\nimport { buildDepsFromRequires } from './buildDeps';\nimport type { ActionDeps, WorldPoint } from './invoker';\nimport type { ImmediateParams } from '../dispatcher/inputFacts';\nimport type { Dispatcher } from '../dispatcher/dispatcher';\nimport { validateActionId, validateActionDefaultBinding, type ActionsRegistry } from './registry';\nimport { createMenuHost, type MenuHost } from '../../menus/menuHost';\nimport { MenuHostContext } from '../../menus/MenuHostContext';\nimport { pushOwner, ScopeNode } from './scopeNode';\nimport { tuneAction, tunedParams, type ActionTuning } from './tuning';\nimport { overrideActionBindings, resolveBindingOverrides, type BindingOverrides, type ResolvedBindingOverrides } from './bindingOverrides';\nimport { isDev } from '@weasel-js/react';\nimport { LastOperationKeeper, type LastOperationHost } from './lastOperation';\nimport type { History } from '@weasel-js/history';\n\n/** @internal Provided by `<ActionsProvider>`, `<InputScope>` and `<Yoke>`. */\nexport const ActionsContext = createContext<ActionsRegistry | null>(null);\n\n/** The deps an action is invoked with: its declared `requires` when it has\n * one, the legacy fixed bag otherwise. The fixed bag has no `applyOps`, so an\n * action that needs the consumer's history must declare it. */\nfunction depsFor(a: Action, r: DepRegistry | null): ActionDeps {\n if (!r) return {};\n if (a.requires) return buildDepsFromRequires(a, r);\n return {\n selection: r.get('selection' as DepName),\n scene: r.get('scene' as DepName),\n history: r.get('history' as DepName),\n view: r.get('view' as DepName),\n activeTool: r.get('activeTool'),\n booleansAdapter: r.get('booleansAdapter' as DepName),\n } as ActionDeps;\n}\n\n/**\n * One node of the actions tree: the actions registered at it, over its\n * parent's. Each id holds a stack of registrants, newest live, so a displaced\n * registrant is restored when the one above it leaves. Every read the registry\n * answers — `list`, `trigger`, `begin` — starts at the node's leaf.\n */\nexport class ActionsNode extends ScopeNode<ActionsNode> {\n private readonly actions = new Map<string, Action[]>();\n private readonly muted = new Map<string, number>();\n private readonly tunings = new Map<string, ActionTuning[]>();\n private readonly overrides: BindingOverrides[] = [];\n private overrideCache: { version: number; resolved: ResolvedBindingOverrides } | null = null;\n private readonly dispatchers: Dispatcher[] = [];\n private cache: { version: number; leaf: ActionsNode; list: readonly Action[] } | null = null;\n private host: MenuHost | null = null;\n /** Called on `activate`, so a scope's dep and tool nodes move with it. */\n readonly onActivate: (() => void)[] = [];\n /** The tree's last operation, kept at its root. */\n readonly lastOperation: LastOperationKeeper;\n private opHost: LastOperationHost | null = null;\n\n constructor(\n parent: ActionsNode | null,\n descends: boolean,\n private readonly contextDeps: () => DepRegistry | null,\n ) {\n super(parent, descends);\n this.lastOperation = parent ? parent.lastOperation : new LastOperationKeeper(() => this.changed());\n NODES.set(this.registry, this);\n }\n\n private resolve(id: string): Action | undefined {\n for (const n of this.chain()) {\n if (n.muted.has(id)) return undefined;\n const a = n.actions.get(id)?.at(-1);\n if (a) return this.tuned(a);\n }\n return undefined;\n }\n\n /** Every tuning for `id` from the root down to here, root first. */\n private tuningsOf(id: string): ActionTuning[] {\n const tunings: ActionTuning[] = [];\n for (const n of this.chain()) {\n const stack = n.tunings.get(id);\n if (stack) tunings.unshift(...stack);\n }\n const session = this.lastOperation.sessionTuning(id);\n if (session) tunings.unshift(session);\n return tunings;\n }\n\n /** `a` under every tuning for its id from the root down to here. */\n private tuned(a: Action): Action {\n const tunings = this.tuningsOf(a.id);\n const tuned = overrideActionBindings(tunings.length ? tuneAction(a, tunings) : a, this.overridesHere());\n return this.lastOperation.wrap(tuned, this.opHost ??= this.lastOperationHost());\n }\n\n /** How the last operation reads and reruns what ran in this scope. */\n private lastOperationHost(): LastOperationHost {\n return {\n history: () => (this.deps()?.get('history' as DepName) as History | undefined) ?? null,\n takeSelection: () => this.deps()?.get('selectionSnapshot')?.take() ?? null,\n paramsOf: (id, given) => tunedParams(this.tuningsOf(id), given),\n rerun: (id, params) => {\n const a = this.resolve(id);\n if (a?.invoker?.timing !== 'immediate') return;\n const deps = depsFor(a, this.deps());\n if (evaluateEnabled(a, deps, pointOf(params)).enabled) a.invoker.run(deps, params);\n },\n keep: (id, params) => { for (const t of this.tuningsOf(id)) t.keep?.(params); },\n };\n }\n\n /** Every binding override from the root down to here, read into specs. */\n private overridesHere(): ResolvedBindingOverrides {\n const cached = this.overrideCache;\n if (cached && cached.version === this.tree.version) return cached.resolved;\n const maps: BindingOverrides[] = [];\n for (const n of this.chain()) maps.unshift(...n.overrides);\n const resolved = resolveBindingOverrides(maps);\n this.overrideCache = { version: this.tree.version, resolved };\n return resolved;\n }\n\n private snapshot(): readonly Action[] {\n const leaf = this.start();\n const cached = this.cache;\n if (cached && cached.version === this.tree.version && cached.leaf === leaf) return cached.list;\n const ids = new Set<string>();\n for (const n of leaf.chain()) for (const id of n.actions.keys()) ids.add(id);\n const out: Action[] = [];\n for (const id of ids) {\n const a = leaf.resolve(id);\n if (a) out.push(a);\n }\n const list = Object.freeze(out);\n this.cache = { version: this.tree.version, leaf, list };\n return list;\n }\n\n private deps(): DepRegistry | null {\n for (const n of this.chain()) {\n const r = n.contextDeps();\n if (r) return r;\n }\n return null;\n }\n\n /** The actions registered at this node itself, live, unmuted and tuned —\n * none from the scopes below it. */\n ownActions(): readonly Action[] {\n const out: Action[] = [];\n for (const [id, stack] of this.actions) {\n if (stack.length > 0 && !this.muted.has(id)) out.push(this.tuned(stack.at(-1)!));\n }\n return out;\n }\n\n /** The deps `a` is invoked with from here: the active scope's, which is\n * what `trigger` and `begin` run it with. */\n depsOf(a: Action): ActionDeps {\n return depsFor(a, this.start().deps());\n }\n\n /** The menu host of this node's tree, made by its root on first ask. Rows\n * resolve and run against the active scope, as chrome's `trigger` does. */\n menuHost(): MenuHost {\n const root = [...this.chain()].at(-1)!;\n return root.host ??= createMenuHost({\n actions: () => root.registry.list(),\n depsFor: (a) => root.depsOf(a),\n trigger: (id, params) => root.registry.trigger(id, params),\n activeTool: () => root.start().deps()?.get('activeTool')?.active ?? null,\n });\n }\n\n private dispatcher(): Dispatcher | null {\n for (const n of this.chain()) {\n const d = n.dispatchers.at(-1);\n if (d) return d;\n }\n return null;\n }\n\n override activate(): void {\n keyHolder = this;\n super.activate();\n for (const f of this.onActivate) f();\n }\n\n readonly registry: ActionsRegistry = {\n register: (action: Action) => {\n validateActionId(action.id);\n validateActionDefaultBinding(action);\n const stack = this.actions.get(action.id);\n if (stack) stack.push(action);\n else this.actions.set(action.id, [action]);\n this.changed();\n let released = false;\n return () => {\n if (released) return;\n released = true;\n const cur = this.actions.get(action.id);\n if (!cur) return;\n // Our own entry, wherever it now sits: a registrant that was already\n // displaced must take itself out without disturbing the one above it.\n const i = cur.lastIndexOf(action);\n if (i === -1) return;\n cur.splice(i, 1);\n // An emptied stack holds the id's place in registration order until\n // the tick ends, so a release followed at once by a register — what\n // `useAction` does when its action object changes — keeps its slot.\n if (cur.length === 0) {\n queueMicrotask(() => {\n if (cur.length === 0 && this.actions.get(action.id) === cur) this.actions.delete(action.id);\n });\n }\n this.changed();\n };\n },\n unregister: (id: string) => {\n if (this.actions.delete(id)) this.changed();\n },\n mute: (id: string) => {\n this.muted.set(id, (this.muted.get(id) ?? 0) + 1);\n this.changed();\n let released = false;\n return () => {\n if (released) return;\n released = true;\n const held = this.muted.get(id);\n if (held === undefined) return;\n if (held > 1) this.muted.set(id, held - 1);\n else this.muted.delete(id);\n this.changed();\n };\n },\n tune: (id: string, tuning: ActionTuning) => {\n let stack = this.tunings.get(id);\n if (!stack) this.tunings.set(id, (stack = []));\n const release = pushOwner(stack, tuning);\n this.changed();\n let released = false;\n return () => {\n if (released) return;\n released = true;\n release();\n if (stack.length === 0) this.tunings.delete(id);\n this.changed();\n };\n },\n paramsOf: (id: string, given?: Record<string, unknown>) => tunedParams(this.tuningsOf(id), given),\n overrideBindings: (overrides: BindingOverrides) => {\n const release = pushOwner(this.overrides, overrides);\n this.changed();\n let released = false;\n return () => {\n if (released) return;\n released = true;\n release();\n this.changed();\n };\n },\n bindingOverrides: () => this.start().overridesHere(),\n list: () => this.snapshot(),\n trigger: (id: string, params?: Record<string, unknown>) => {\n const leaf = this.start();\n const a = leaf.resolve(id);\n if (!a?.invoker || a.invoker.timing !== 'immediate') return false;\n const deps = leaf.depsOf(a);\n if (!evaluateEnabled(a, deps, pointOf(params)).enabled) return false;\n try {\n if (a.invoker.run(deps, params) === 'pass') return false;\n } catch (err) {\n console.error(`weasel ActionsRegistry: action \"${id}\" threw`, err);\n }\n return true;\n },\n preview: (id: string, params?: Record<string, unknown>) => {\n const leaf = this.start();\n const a = leaf.resolve(id);\n if (!a?.preview) return NO_PREVIEW;\n const deps = leaf.depsOf(a);\n if (!evaluateEnabled(a, deps, pointOf(params)).enabled) return NO_PREVIEW;\n let stop: (() => void) | void;\n try {\n stop = a.preview(deps, params);\n } catch (err) {\n console.error(`weasel ActionsRegistry: preview of \"${id}\" threw`, err);\n return NO_PREVIEW;\n }\n if (typeof stop !== 'function') return NO_PREVIEW;\n let down = false;\n return () => {\n if (down) return;\n down = true;\n try {\n stop();\n } catch (err) {\n console.error(`weasel ActionsRegistry: preview of \"${id}\" threw as it ended`, err);\n }\n };\n },\n subscribe: (listener: () => void) => this.tree.listeners.subscribe(listener),\n setDispatcher: (d: Dispatcher | null) => pushOwner(this.dispatchers, d),\n begin: (id: string, params?: Record<string, unknown>) => {\n const leaf = this.start();\n const a = leaf.resolve(id);\n const disp = leaf.dispatcher();\n if (!a || !disp) return null;\n return disp.beginUiOngoing(id, leaf.depsOf(a), params);\n },\n activate: () => this.activate(),\n isActive: () => this.isActive(),\n holdsKeys: () => keyHolder === this,\n dropKeys: () => { if (keyHolder === this) keyHolder = null; },\n };\n}\n\nconst NO_PREVIEW = (): void => {};\n\n/** The world point a trigger's params carry, if any. */\nfunction pointOf(params: Record<string, unknown> | undefined): WorldPoint | undefined {\n return (params as ImmediateParams | undefined)?.world;\n}\n\n/** The node last activated on the page, across every tree: where a key that\n * reaches the page goes. Null until something is pressed or scrolled in. */\nlet keyHolder: ActionsNode | null = null;\n\nconst NODES = new WeakMap<ActionsRegistry, ActionsNode>();\n\n/** The tree node behind `registry`, when it is one of ours. */\nexport function actionsNodeOf(registry: ActionsRegistry | null): ActionsNode | null {\n return registry ? (NODES.get(registry) ?? null) : null;\n}\n\n/**\n * Mounts a root `ActionsRegistry` for its lifetime. Children call\n * `useActionsRegistry()` or `useAction()` to participate. Mounts no input\n * listener of its own — the gesture dispatcher owns input.\n */\nexport function ActionsProvider({ children }: { children: ReactNode }): ReactElement {\n // `trigger` consults the dep registry in scope, so actions can be fired\n // imperatively from ActionBar / palette callers.\n const depReg = useOptionalDepRegistry();\n const depRegRef = useLatest<DepRegistry | null>(depReg);\n const node = useMemo(() => new ActionsNode(null, true, () => depRegRef.current), [depRegRef]);\n return (\n <ActionsContext.Provider value={node.registry}>\n <MenuHostContext.Provider value={node.menuHost()}>{children}</MenuHostContext.Provider>\n </ActionsContext.Provider>\n );\n}\n\nconst IS_DEV = isDev();\n\n/**\n * Returns the `ActionsRegistry` in scope, or `null` when there is none.\n */\nexport function useActionsRegistry(): ActionsRegistry | null {\n return useContext(ActionsContext);\n}\n\n/**\n * Register an `Action` for the lifetime of the calling component. No-op (with\n * a dev-only warning) when no `ActionsProvider` is in scope. Re-registers on\n * `action` reference change (consumers should memoize stable identities to\n * avoid churn).\n */\nexport function useAction(action: Action): void {\n const reg = useActionsRegistry();\n useEffect(() => {\n if (!reg) {\n if (IS_DEV) {\n console.warn(\n `useAction(\"${action.id}\"): no <ActionsProvider> is in scope, so the action was not registered and its bindings will never fire.`,\n );\n }\n return;\n }\n return reg.register(action);\n }, [reg, action]);\n}\n"]}
@@ -353,7 +353,7 @@ function validateActionDefaultBinding(action) {
353
353
  }
354
354
  }
355
355
 
356
- // src/interactions/actions/invoker.ts
356
+ // src/interactions/actions/bindingOpts.ts
357
357
  function resolveParams(params) {
358
358
  if (params === void 0) return void 0;
359
359
  return typeof params === "function" ? params() : params;
@@ -690,6 +690,7 @@ function unionRows(draw, leaf, key, path, off) {
690
690
  key: `${path}/${v2}`,
691
691
  label: variant2.name,
692
692
  checked: v2 === current?.[0],
693
+ radio: true,
693
694
  disabled: frozen || !onChange,
694
695
  run: onChange ? () => onChange(path, prefVariantDefault(leaf, v2)) : noop
695
696
  }));
@@ -713,6 +714,7 @@ function fieldRows(draw, leaf, key, path, off) {
713
714
  key: `${path}/${p}`,
714
715
  label: l.name || p,
715
716
  checked: held === p,
717
+ radio: true,
716
718
  disabled: off || leaf.readout === true || !onChange,
717
719
  run: onChange ? () => onChange(path, p) : noop
718
720
  });
@@ -848,6 +850,7 @@ function enumRows(ctx, leaf, key, path, off) {
848
850
  key: `${key}/${o.value}`,
849
851
  label: o.label,
850
852
  checked: o.value === current,
853
+ radio: true,
851
854
  disabled: off || o.disabled === true,
852
855
  run: () => onChange(path, write(o.value))
853
856
  })),
@@ -1099,5 +1102,5 @@ function createMenuHost(src) {
1099
1102
  }
1100
1103
 
1101
1104
  export { ActionDisabledReason, DepNode, NO_OVERRIDES, ScopeNode, actionBindings, actionCursor, actionItemTitle, actionItems, actionSettingsParams, actionShortcuts, bindingId, buildDepsFromRequires, createDepRegistry, createMenuHost, depNodeOf, evaluateActive, evaluateEnabled, keySpecShortcut, keysHeld, mergeMenuDefs, overriddenBindings, overrideActionBindings, paramsMatch, pickMenu, platformRoleKeys, pushOwner, readActionSettings, resolveBindingOverrides, resolveMenu, resolveParams, resolveRoles, resolveSchemaMenu, roleKeysOf, roleReader, tuneAction, tunedParams, validateActionDefaultBinding, validateActionId };
1102
- //# sourceMappingURL=chunk-A6MN3I6R.js.map
1103
- //# sourceMappingURL=chunk-A6MN3I6R.js.map
1105
+ //# sourceMappingURL=chunk-Z2BZBJ7W.js.map
1106
+ //# sourceMappingURL=chunk-Z2BZBJ7W.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/interactions/actions/actionItems.ts","../src/interactions/actions/actionSettings.ts","../src/interactions/actions/binding.ts","../src/interactions/actions/actionShortcuts.ts","../src/interactions/actions/action.ts","../src/interactions/actions/actionEnabled.ts","../src/interactions/actions/buildDeps.ts","../src/interactions/actions/scopeNode.ts","../src/interactions/actions/depNode.ts","../src/interactions/actions/registry.ts","../src/interactions/actions/bindingOpts.ts","../src/interactions/actions/modifierRoles.ts","../src/interactions/actions/tuning.ts","../src/interactions/actions/bindingOverrides.ts","../src/menus/pickMenu.ts","../src/menus/compoundRows.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K,CAAA;AACf,MAAA,OAAO,MAAM;AACX,QAAA,MAAM,CAAA,GAAI,IAAA,CAAK,OAAA,CAAQ,KAAK,CAAA;AAC5B,QAAA,IAAI,CAAA,IAAK,CAAA,EAAG,IAAA,CAAK,MAAA,CAAO,GAAG,CAAC,CAAA;AAAA,MAC9B,CAAA;AAAA,IACF,CAAA;AAAA,IACA,KAAK,GAAA,EAAK;AACR,MAAA,MAAM,OAAA,GAAU,QAAQ,GAAG,CAAA;AAC3B,MAAA,IAAI,CAAC,QAAQ,MAAA,EAAQ;AACnB,QAAA,KAAA,EAAM;AACN,QAAA,OAAO,KAAA;AAAA,MACT;AACA,MAAA,IAAA,GAAO;AAAA,QACL,KAAK,EAAE,GAAA;AAAA,QAAK,OAAA;AAAA,QAAS,QAAQ,GAAA,CAAI,MAAA;AAAA,QAAQ,OAAO,GAAA,CAAI,KAAA;AAAA,QACpD,GAAI,IAAI,KAAA,GAAQ,EAAE,OAAO,GAAA,CAAI,KAAA,KAAU,EAAC;AAAA,QACxC,GAAI,IAAI,IAAA,GAAO,EAAE,MAAM,GAAA,CAAI,IAAA,KAAS,EAAC;AAAA,QACrC,MAAA,EAAQ,IAAI,MAAA,IAAU;AAAA,OACxB;AACA,MAAA,IAAA,EAAK;AACL,MAAA,OAAO,IAAA;AAAA,IACT,CAAA;AAAA,IACA,KAAK,CAAC,GAAA,KAAQ,OAAA,CAAQ,GAAG,EAAE,MAAA,GAAS,CAAA;AAAA,IACpC,KAAA;AAAA,IACA,SAAS,MAAM,IAAA;AAAA,IACf,UAAU,EAAA,EAAI;AACZ,MAAA,SAAA,CAAU,IAAI,EAAE,CAAA;AAChB,MAAA,OAAO,MAAM;AAAE,QAAA,SAAA,CAAU,OAAO,EAAE,CAAA;AAAA,MAAG,CAAA;AAAA,IACvC;AAAA,GACF;AACF","file":"chunk-Z2BZBJ7W.js","sourcesContent":["/**\n * The entries an action contributes to a bar, menu or palette — one per\n * variant, or the action itself when it declares none.\n */\nimport type { IconRef } from '@weasel-js/icons';\nimport type { Action } from './action';\n\nconst NO_TAGS: readonly string[] = Object.freeze([]);\n\n/** One renderable entry: an action, optionally with params. */\nexport interface ActionItem {\n /** `action.id`, or `action.id:variant.key` — unique across a registry. */\n key: string;\n action: Action;\n label: string;\n icon?: IconRef;\n /** The action's tags, then the variant's own. */\n tags: readonly string[];\n /** What to pass to `trigger(action.id, params)`; absent for a plain action. */\n params?: Readonly<Record<string, unknown>>;\n}\n\n/** Expand `action` into the entries a surface renders. An\n * action without an immediate invoker has none: `trigger` cannot start a\n * drag, so a button for one would do nothing. */\nexport function actionItems(action: Action): ActionItem[] {\n if (action.invoker?.timing !== 'immediate') return [];\n if (!action.variants?.length) {\n return [{ key: action.id, action, label: action.label, icon: action.icon, tags: action.tags ?? NO_TAGS }];\n }\n return action.variants.map((v) => ({\n key: `${action.id}:${v.key}`,\n action,\n label: v.label,\n icon: v.icon ?? action.icon,\n tags: v.tags ? [...(action.tags ?? NO_TAGS), ...v.tags] : action.tags ?? NO_TAGS,\n params: v.params,\n }));\n}\n\n/** How a palette titles `item`: a variant reads as its action's\n * label and its own (\"New: A4\"), unless its label already holds the action's\n * as whole words (\"Zoom In\", \"Reset Zoom\"). */\nexport function actionItemTitle(item: ActionItem): string {\n if (item.key === item.action.id) return item.label;\n const words = (s: string) => s.toLowerCase().match(/[\\p{L}\\p{N}]+/gu) ?? [];\n const head = words(item.action.label);\n const label = words(item.label);\n for (let i = 0; i + head.length <= label.length; i++) {\n if (head.every((w, j) => label[i + j] === w)) return item.label;\n }\n return `${item.action.label}: ${item.label}`;\n}\n","/**\n * A settings form an action carries: what a surface draws in place of a bare\n * trigger for an action whose job is to change settings on the selection.\n */\nimport type { PrefGroup } from '@weasel-js/prefs';\nimport type { Action } from './action';\nimport type { ActionDeps } from './invoker';\n\n/** What a settings form shows for the selection right now. */\nexport interface ActionSettingsState {\n /** The values, nested as the schema's groups nest. */\n values: Record<string, unknown>;\n /** The leaf paths where the selected items disagree. */\n mixed?: readonly string[];\n}\n\n/**\n * The settings form an action carries. A bar or a panel draws the action as a\n * button opening it, a menu as a submenu of its fields, and a palette as a\n * dialog; each change triggers the action with the params it makes.\n */\nexport interface ActionSettings {\n /** The form. Its `name` titles the popover, submenu or dialog. */\n schema: PrefGroup;\n /** The selection's current values, from the deps `enabled` is given. Under\n * `enabled`'s contract: pure, fast, and it must not throw. */\n read(deps: ActionDeps): ActionSettingsState;\n /** The params one field's change triggers the action with, or `null` for\n * none. Default: `{ [path]: value }`. */\n params?(path: string, value: unknown): Record<string, unknown> | null;\n}\n\nconst EMPTY: ActionSettingsState = { values: {} };\n\n/** `action`'s settings as they stand under `deps`, or `null` for an action\n * with no settings. A `read` that throws shows nothing rather than breaking\n * the surface. */\nexport function readActionSettings(action: Action, deps: ActionDeps | undefined): ActionSettingsState | null {\n const settings = action.settings;\n if (!settings) return null;\n try {\n return settings.read(deps ?? {});\n } catch {\n return EMPTY;\n }\n}\n\n/** The params a change of the field at `path` to `value` triggers the action with. */\nexport function actionSettingsParams(\n settings: ActionSettings,\n path: string,\n value: unknown,\n): Record<string, unknown> | null {\n return settings.params ? settings.params(path, value) : { [path]: value };\n}\n","/**\n * GestureBinding — connects a GestureSpec to an Action id (with per-binding\n * options). Tools own arrays of these on their `bindings` field; ambient\n * gesture-bindings are registered globally.\n */\n\nimport type { GestureSpec } from '@weasel-js/gestures';\nimport type { BindingOpts } from './invoker';\n\n/** An interaction: a gesture spec composed with the id of the action it\n * invokes. Tools declare arrays of these; the dispatcher matches an incoming\n * input event against them and runs the winner's action. */\nexport interface GestureBinding {\n spec: GestureSpec;\n actionId: string;\n opts?: BindingOpts;\n}\n\n/**\n * A single entry in `Action.defaultBinding[]`. Either a bare `GestureSpec`\n * (no per-binding opts) or an object form that pairs a spec with\n * `BindingOpts` for parametric actions (e.g. `{ params: { axis: 'x' } }`).\n * Use the object form when two bindings for the same action differ only in\n * a runtime parameter — the dispatcher extracts `opts.params` and passes\n * them to `ImmediateInvoker.run` as its second argument.\n */\nexport type BoundGesture = GestureSpec | { spec: GestureSpec; opts: BindingOpts };\n\n/**\n * The whole of an action `actionBindings` reads. Routing needs this much and\n * none of `Action`'s palette fields, so it is the narrowest type the\n * dispatcher's binding walk can be written against.\n */\nexport interface BindingSource {\n id: string;\n /** The gesture-spec form of the binding, read by the gesture dispatcher.\n * May be a single `GestureSpec`, a bare `GestureSpec[]` (any-of semantics),\n * or a `BoundGesture[]` where each entry is either a bare `GestureSpec` or\n * `{ spec, opts }` — use the object form for parametric actions where two\n * bindings for the same action differ only by `opts.params` (e.g. `flip`\n * with `axis: 'x'` vs `'y'`). The dispatcher extracts `opts.params` and\n * passes them to `ImmediateInvoker.run` as its second argument. */\n defaultBinding?: GestureSpec | BoundGesture[];\n}\n\n/**\n * Flatten an action's `defaultBinding` into `GestureBinding`s. A bare\n * `GestureSpec` has `kind` at top level; the object form has `spec`.\n */\nexport function actionBindings(action: BindingSource): GestureBinding[] {\n const gs = action.defaultBinding;\n if (!gs) return [];\n const raw: BoundGesture[] = Array.isArray(gs) ? gs : [gs as BoundGesture];\n return raw.map((entry) => {\n const isBoundObj = !('kind' in entry);\n const spec = isBoundObj ? (entry as { spec: GestureSpec }).spec : (entry as GestureSpec);\n const opts = isBoundObj ? (entry as { opts: BindingOpts }).opts : undefined;\n return { spec, actionId: action.id, ...(opts !== undefined ? { opts } : {}) };\n });\n}\n","/**\n * Project an action's keyboard bindings into the shape a shortcut chip\n * renders from (`formatShortcut` / `formatShortcutParts` in `@weasel-js/ui`).\n */\nimport type { GestureSpec } from '@weasel-js/gestures';\nimport type { MenuShortcut } from '@weasel-js/menu';\nimport type { Action } from './action';\nimport { actionBindings } from './binding';\n\n/** One keyboard shortcut, flattened for display: the chip a menu row draws\n * (`MenuShortcut` in `@weasel-js/menu`, `ShortcutInput` in `@weasel-js/gestures`). */\nexport type ActionShortcut = MenuShortcut;\n\n/**\n * The chip form of a single gesture spec, or `undefined` when the spec has\n * none.\n *\n * - A spec's `key` may list spellings of one keycap (`['[', '{']` — the\n * shifted bracket reports as `'{'`). The first is the shortcut's name.\n * - A modifier declared `'optional'` matches held or unheld, so it isn't\n * part of what the user has to press.\n *\n * Non-keyboard specs (drag, wheel, click) have no chip form. Neither does a\n * *required* `ctrl` or `meta`: the display shape carries only `mod`.\n */\nexport function keySpecShortcut(spec: GestureSpec): ActionShortcut | undefined {\n if (spec.kind !== 'key' && spec.kind !== 'key-held') return undefined;\n const key = Array.isArray(spec.key) ? spec.key[0] : spec.key;\n if (typeof key !== 'string' || key.length === 0) return undefined;\n const mods = 'mods' in spec ? spec.mods : undefined;\n return {\n key,\n mod: mods?.mod === true,\n alt: mods?.alt === true,\n shift: mods?.shift === true,\n };\n}\n\n/**\n * Every keyboard shortcut an action answers to, in declaration order.\n * Specs `keySpecShortcut` has no chip for are skipped, and bindings it leaves\n * identical are emitted once; an action bound only to those returns empty.\n *\n * With `params` — an `ActionItem`'s — only the bindings that pass those same\n * values count, so each variant of `flip` gets its own key.\n */\nexport function actionShortcuts(\n action: Action,\n params?: Readonly<Record<string, unknown>>,\n): readonly ActionShortcut[] {\n const out: ActionShortcut[] = [];\n const seen = new Set<string>();\n for (const { spec, opts } of actionBindings(action)) {\n if (params && !paramsMatch(opts?.params, params)) continue;\n const shortcut = keySpecShortcut(spec);\n if (!shortcut) continue;\n const token = `${shortcut.key}|${shortcut.mod}|${shortcut.alt}|${shortcut.shift}`;\n if (seen.has(token)) continue;\n seen.add(token);\n out.push(shortcut);\n }\n return out;\n}\n\n/** Whether `bound` (a binding's `opts.params`) carries every value in `wanted`. */\nexport function paramsMatch(bound: unknown, wanted: Readonly<Record<string, unknown>>): boolean {\n if (typeof bound !== 'object' || bound === null) return false;\n return Object.entries(wanted).every(([k, v]) => (bound as Record<string, unknown>)[k] === v);\n}\n","/**\n * The `Action` descriptor, split along the line the dispatcher reads.\n * `ActionDispatch` is everything routing consults to decide whether an action\n * runs and what happens when it does; `ActionPresentation` is what a palette,\n * menu or toolbar renders. `Action` is both.\n */\nimport type { ModifierRoles } from './modifierRoles';\nimport type { IconRef } from '@weasel-js/icons';\nimport type { CursorSpec } from '@weasel-js/cursor';\nimport type { ActionDeps, Invoker } from './invoker';\nimport type { ActionSettings } from './actionSettings';\nimport type { PrefGroup } from '@weasel-js/prefs';\nimport type { BindingSource } from './binding';\nimport type { DepName } from '../../index';\nimport type { IngestItem } from '@weasel-js/gestures';\n\n/** What content being routed brings to `Action.enabled`: a drop's or a\n * paste's items, or a carry's payload with no items. */\nexport interface Carried {\n items: readonly IngestItem[];\n carry?: { type: string; value: unknown };\n}\n\n/**\n * The kit's symbolic reasons an action might report itself as disabled. The\n * consumer (palette, menu, etc.) maps these to display strings via its own\n * label map. An action may also answer with any other string, which is\n * display text and shown as is — see {@link ActionUnavailable}.\n */\nexport const ActionDisabledReason = {\n SelectionRequired: 'selection-required',\n SceneEmpty: 'scene-empty',\n NotApplicable: 'not-applicable',\n /** Sentinel: the predicate threw. Surfaced by `evaluateEnabled`'s catch. */\n PredicateThrew: 'predicate-threw',\n} as const;\n/** Why an action is unavailable right now. */\nexport type ActionDisabledReason =\n (typeof ActionDisabledReason)[keyof typeof ActionDisabledReason];\n\n/** What `enabled` answers with when the action cannot run: one of the\n * symbolic {@link ActionDisabledReason}s, or a sentence to show as it is. */\nexport type ActionUnavailable = ActionDisabledReason | (string & {});\n\n/**\n * What a palette, menu or toolbar renders for an action. No part of this is\n * read during dispatch.\n */\nexport interface ActionPresentation {\n label: string;\n /** The action's icon, by qualified name: `icon('group')` in the package that draws it. */\n icon?: IconRef;\n /** Grouping key for palette/menu surfaces. Free-form string; the kit\n * ships defaults for `'align'` (six edges/centers), `'distribute'`\n * (two axes), and recommends `'pathfinder'` for boolean ops. */\n group?: string;\n /** Words the action is also found by and gathered under. Where `group` is\n * the one place an action sits, an action carries any number of tags: a\n * palette search matches them as it matches the label, and\n * `actionsTagged` / `taggedActionItems` gather every action or entry\n * carrying one, for a bar or a menu built from a tag. */\n tags?: readonly string[];\n /** Display override for the keyboard shortcut. When omitted, palette\n * surfaces derive a label from `defaultBinding` via their own\n * formatter. */\n shortcut?: string;\n /** The distinct things a parametric action does, one per set of params —\n * `flip` flips horizontally or vertically, `reorder.forward` moves one step\n * or all the way. A bar, menu or palette shows one entry per variant and\n * triggers the action with that variant's `params`. Omitted = the action\n * is one entry. See `actionItems`. */\n variants?: readonly ActionVariant[];\n /** A form of the settings the action changes on the selection. A surface\n * draws the action as that form instead of a bare trigger, and each change\n * triggers it with the params `settings.params` makes. Not combined with\n * `variants`. */\n settings?: ActionSettings;\n /** The params the invoker reads, as a form: one leaf per param, keyed by its name, with its label, range,\n * step, and default. A run that commits one history entry is kept as the tree's last operation, which a panel\n * draws as this form so the params can be changed after the fact: any immediate run, and a gesture whose\n * handle can `replay` (see `OngoingHandle.replay`). `ActionParamSchema` stays what types a tuning; this is\n * what a person sees.\n *\n * A function answers the form for one run from the params it resolved, for an action whose params depend\n * on what it was asked to do (`insert`'s on the kind of shape), or `null` for a run with none to show. */\n params?: PrefGroup | ((params: Readonly<Record<string, unknown>>) => PrefGroup | null);\n}\n\n/**\n * One entry a parametric action contributes to a bar, menu or palette.\n */\nexport interface ActionVariant {\n /** Unique within the action; joined to its id to make the entry's key. */\n key: string;\n label: string;\n /** Falls back to the action's own `icon`. */\n icon?: IconRef;\n /** Tags this variant carries besides its action's, which it carries too. */\n tags?: readonly string[];\n /** Passed to `trigger`, and matched against each binding's\n * `opts.params` to find the variant's shortcuts. */\n params: Readonly<Record<string, unknown>>;\n}\n\n/**\n * What routing consults: the bindings that reach the action, the deps its\n * invoker reads, the gates it passes, and the cursors it claims.\n */\nexport interface ActionDispatch extends BindingSource {\n /** Names of the deps this action's invoker reads (keys of `DepSchema`).\n * The dispatcher (and `trigger`, when `requires` is present) resolves\n * each name against the `DepRegistry` at invocation time and passes the\n * resulting bag to the invoker. Dev builds warn when the invoker reads a\n * dep it didn't declare here — see `buildDepsFromRequires`. */\n requires?: readonly DepName[];\n /** Pluggable invocation strategy. The gesture dispatcher routes matched\n * bindings through `invoker.start` / `invoker.run` depending on timing.\n * All kit-standard descriptors ship one; consumer-supplied actions\n * without an invoker can still register but won't be triggered. */\n invoker?: Invoker;\n /** When set to `'hotkey'`, this action's `defaultBinding` rides the hotkey\n * `BindingScope` instead of the ambient scope — meaning it beats any\n * active-tool binding on the same input shape. Use for tool-switch\n * shortcuts and global held-key triggers. Default: ambient. */\n scope?: 'hotkey';\n /**\n * Optional predicate saying whether the action can run right now. Return\n * `true` when it can, or an `ActionDisabledReason` or a sentence of display\n * text when it cannot. The\n * command palette greys out a disabled row, skips it in keyboard nav,\n * ignores clicks, and shows the reason next to the label. The dispatcher\n * skips a disabled action too, on a key as on a pointer, and falls through\n * to the next binding that matches. `ActionsRegistry.trigger` asks too, but\n * with no point, so a `run` whose answer depends on `at` should still\n * self-guard.\n *\n * **Contract:** must be pure (no side effects), fast (< 4ms in dev), and\n * must not throw. A throw is caught and treated as disabled with reason\n * `ActionDisabledReason.PredicateThrew`.\n *\n * The palette evaluates `enabled` once when opened and does NOT re-evaluate\n * on selection changes while open.\n *\n * `deps` is the same bag passed to `ImmediateInvoker.run`.\n *\n * `at` is the world point of the event being routed, when it has one — a\n * click, a press, a long-press. An action that only applies somewhere\n * (on a path segment, say) refuses other points here, so the dispatcher\n * falls through to the next binding and hover prediction shows the\n * action's `cursor` only where it would act. `trigger` passes the\n * `world` its params carry, so a menu row is run under the\n * question it was shown enabled for. Palettes and keystrokes pass no\n * point; treat absent as \"anywhere\".\n *\n * `carried` is what a drop, a paste or a carry being routed brings. For\n * an OS drag still in flight its items hold a MIME and nothing else, since\n * a browser withholds contents until the drop. A carry has no items and\n * hands over its payload whole. An action that takes only some content\n * refuses the rest here, so a drag it would not take is not accepted and a\n * paste it would not take stays the page's.\n */\n enabled?: (\n deps?: ActionDeps,\n at?: { x: number; y: number },\n carried?: Carried,\n ) => true | ActionUnavailable;\n /**\n * Whether the action reads as held down right now: bold on the selected\n * text, snapping switched on. A toolbar button draws it as pressed.\n * Omitted = the action has no pressed state, which is not the same as\n * one that is off. Never read during dispatch.\n *\n * Under the same contract as `enabled`: pure, fast, and it must not\n * throw. `deps` is the bag `enabled` is given.\n */\n active?: (deps?: ActionDeps) => boolean;\n /**\n * Show what running the action now would do, and change nothing: the\n * result an operation would make, drawn over the canvas. A toolbar asks\n * while its button is hovered or focused, through\n * `ActionsRegistry.preview`, and calls what this returns when that ends.\n * Asked only while `enabled` says yes, with the deps and params `run`\n * would get. Omitted = the action has nothing to show.\n */\n preview?: (deps: ActionDeps, params?: Record<string, unknown>) => (() => void) | void;\n /**\n * Declarative eligibility rule, evaluated against the current\n * `RuleCtx` by the dispatcher before invoking `start()`. Omitted =\n * always eligible.\n *\n * Accepts either a fluent `Condition` (callable with `.rule`) or a\n * raw `Rule` tree; the dispatcher normalizes via `.rule` unwrap.\n *\n * Prefer `capability:`-based rules (e.g. `{ capability: 'transforms-selection' }`)\n * over `mode:` rules — capability rules survive new modes being added\n * that allow the same capability.\n */\n eligible?:\n | import('../../eligibility').Rule\n | import('../../eligibility').Condition;\n /**\n * CSS cursor shown while the pointer hovers a spot where this action\n * would win the drag — or, when the drag's winner declares no cursor,\n * the click. The hover-cursor pump runs the same match walk a real press\n * takes, so the hint and the actual target stay in sync. Omitted = no\n * override (the active tool's `Tool.cursor` shows). Affordance hits are\n * resolved earlier in the pump via `AffordanceRegion.cursor` and never\n * reach this field.\n *\n * A function is asked each time with the params the winning binding would\n * start the action with, tunings included, so a cursor can follow them — a\n * brush ring as wide as the brush. Read it through {@link actionCursor}.\n * Prediction runs `enabled()` but cannot run the invoker, so an action that\n * matches yet bails at `start()` (empty handle) may still show its cursor —\n * keep `enabled` accurate for actions that declare one.\n */\n cursor?: CursorSpec | ((params: Record<string, unknown> | undefined) => CursorSpec | undefined);\n /**\n * CSS cursor shown while THIS action's ongoing handle is in flight —\n * grabbing while panning, `move` while dragging a selection, `crosshair`\n * while pulling a marquee.\n *\n * Separate from `cursor` because the two answer different questions:\n * `cursor` is a prediction (\"a drag from here would pan\"), this is a state\n * (\"you are panning\"). An action can declare either, both, or neither;\n * with only `cursor` set, the hover hint holds for the duration of the\n * gesture.\n */\n activeCursor?: CursorSpec;\n /**\n * The modifiers an ongoing action reads while it runs, by role: Shift\n * holding a handle's angle, Alt breaking its mirror. The dispatcher resolves\n * each into `InvocationCtx.roles` on the press, every move, and the release,\n * so a binding's `opts.roles` or a tuning's `roles` can move one to another\n * key. Read them with {@link roleReader}. A binding's own `mods` are matched\n * once, at the press; these are read throughout.\n */\n modifierRoles?: ModifierRoles;\n}\n\n/**\n * Single registered action.\n */\nexport interface Action extends ActionDispatch, ActionPresentation {}\n\n/**\n * The whole of an actions registry the dispatcher reads. It walks the list\n * once per event to build its actionId lookup and never mutates it, so the\n * routing side depends on this rather than on `ActionsRegistry`, whose\n * register / mute / trigger surface is the React provider's.\n */\nexport interface ActionSource {\n list(): readonly Action[];\n}\n\n/** `action`'s hover cursor for an invocation given `params`: its `cursor`,\n * asked when it is a function. */\nexport function actionCursor(\n action: Pick<Action, 'cursor'> | undefined,\n params?: Record<string, unknown>,\n): CursorSpec | undefined {\n const c = action?.cursor;\n return typeof c === 'function' ? c(params) : c;\n}\n","/**\n * Palette-side evaluation of `Action.enabled`. The dispatcher calls the\n * predicate raw as a gate; this is the surface that also enforces the\n * contract the predicate's JSDoc states — no throwing, under 4ms in dev.\n */\nimport type { ActionDeps } from './invoker';\nimport { ActionDisabledReason, type Action, type ActionUnavailable } from './action';\nimport { isDev } from '@weasel-js/react';\n\n/**\n * Result of evaluating an Action's `enabled` predicate.\n */\nexport interface ActionEnabledResult {\n enabled: boolean;\n reason?: ActionUnavailable;\n}\n\nconst enabledSlowWarned = new Set<string>();\nconst enabledThrewWarned = new Set<string>();\nconst ENABLED_BUDGET_MS = 4;\n/**\n * Safely evaluate an action's `enabled` predicate. Returns `{enabled: true}`\n * when no predicate is supplied. Catches throws and treats them as disabled\n * with reason `'(predicate threw)'`. In dev mode, warns once per action id\n * when a single call exceeds 4ms (single frame at 240fps — generous; real\n * predicates should be sub-millisecond).\n */\nexport function evaluateEnabled(\n action: Action,\n deps?: ActionDeps,\n at?: { x: number; y: number },\n): ActionEnabledResult {\n if (!action.enabled) return { enabled: true };\n const dev = isDev();\n const now = (typeof performance !== 'undefined' && typeof performance.now === 'function')\n ? () => performance.now()\n : () => Date.now();\n const start = dev ? now() : 0;\n try {\n const result = action.enabled(deps, at);\n if (dev) {\n const elapsed = now() - start;\n if (elapsed > ENABLED_BUDGET_MS && !enabledSlowWarned.has(action.id)) {\n enabledSlowWarned.add(action.id);\n console.warn(\n `weasel actions: enabled() for action \"${action.id}\" took ${elapsed.toFixed(2)}ms ` +\n `(budget ${ENABLED_BUDGET_MS}ms). The predicate must be pure and fast — see Action.enabled JSDoc.`,\n );\n }\n }\n if (result === true) return { enabled: true };\n return { enabled: false, reason: result };\n } catch (e) {\n if (dev && !enabledThrewWarned.has(action.id)) {\n enabledThrewWarned.add(action.id);\n console.warn(\n `weasel actions: enabled() for action \"${action.id}\" threw; treating as disabled. ` +\n `The predicate must not throw — see Action.enabled JSDoc.`,\n e,\n );\n }\n return { enabled: false, reason: ActionDisabledReason.PredicateThrew };\n }\n}\n\n/**\n * Safely evaluate an action's `active` predicate. `undefined` for an action\n * with no pressed state; a predicate that throws reads as not active.\n */\nexport function evaluateActive(action: Action, deps?: ActionDeps): boolean | undefined {\n if (!action.active) return undefined;\n try {\n return action.active(deps) === true;\n } catch {\n return false;\n }\n}\n","/**\n * Shared dep-bag builder — the single implementation behind both the gesture\n * dispatcher's per-invocation `buildDeps` and `ActionsRegistry.trigger`'s\n * `requires` branch. Reads the action's declared `requires`, resolves each\n * name against the `DepRegistry`, and (dev builds only) wraps the bag in a\n * Proxy that warns on undeclared reads.\n */\nimport type { Action } from './action';\nimport type { DepRegistry } from './depNode';\nimport type { ActionDeps } from './invoker';\nimport { isDev } from '@weasel-js/react';\n\n/** True in dev builds; false in production. Tree-shakes the Proxy out of\n * prod entirely. (Mirrors the dispatcher's own `DEV` const.) */\nconst DEV = isDev();\n\n/** Build the deps bag for an action from its declared `requires`. */\nexport function buildDepsFromRequires(action: Action, depRegistry: DepRegistry): ActionDeps {\n const requires = action.requires ?? [];\n const entries = requires.map((name) => [name, depRegistry.get(name)]);\n const deps = Object.fromEntries(entries) as ActionDeps;\n\n // Dev-only: wrap deps in a Proxy that warns when the invoker reads a\n // key not declared in `requires`. Catches silent-failure-by-typo or\n // forgotten-requires (the #1 bug class in this codebase pre-Phase-14e).\n // Production builds: bypass the Proxy entirely (zero overhead).\n if (DEV) {\n const declared = new Set<string>(requires);\n return new Proxy(deps as Record<string, unknown>, {\n get(target, prop, receiver) {\n if (typeof prop === 'string' && !declared.has(prop) && prop !== 'then') {\n const message =\n `[weasel:dispatcher] action \"${action.id}\" read deps.${prop} but did not declare it in \\`requires\\`. ` +\n `Add \\`requires: [...'${prop}']\\` to the descriptor or the dep will be undefined at runtime.`;\n // Warn first so the console trail survives even when the throw is\n // swallowed by a caller, then throw so the gesture fails visibly\n // instead of silently running without the dep.\n console.warn(message);\n throw new Error(message);\n }\n return Reflect.get(target, prop, receiver);\n },\n }) as ActionDeps;\n }\n return deps;\n}\n","/**\n * The tree both input registries hang on. A provider is a root; every canvas\n * mounts a scope under the registry in scope; a yoke sits between the two. A\n * registration lives in the node it was made in, and a lookup starts at a leaf\n * and walks up, so one canvas never answers for another.\n */\nimport { createEmitter, type Emitter } from '@weasel-js/registry';\n\n/** What every node of one tree shares: a version and the listeners to it. */\nexport interface ScopeTree {\n version: number;\n readonly listeners: Emitter;\n}\n\nexport class ScopeNode<N extends ScopeNode<N>> {\n readonly tree: ScopeTree;\n private readonly children: N[] = [];\n private activeChild: N | null = null;\n\n /** `descends`: whether reads made here answer from the active child down —\n * true for a root or a yoke, which chrome reads through; false for a scope,\n * which answers for itself even with a scope nested inside it. */\n constructor(readonly parent: N | null, readonly descends: boolean) {\n this.tree = parent ? parent.tree : { version: 0, listeners: createEmitter() };\n }\n\n /** Bump the tree's version and tell every listener in it. */\n changed(): void {\n this.tree.version++;\n this.tree.listeners.emit();\n }\n\n /** Join the parent's children, newest last; returns the leave. */\n mount(): () => void {\n const parent = this.parent;\n if (!parent) return () => {};\n parent.children.push(this as unknown as N);\n this.changed();\n let left = false;\n return () => {\n if (left) return;\n left = true;\n const i = parent.children.lastIndexOf(this as unknown as N);\n if (i !== -1) parent.children.splice(i, 1);\n if (parent.activeChild === (this as unknown as N)) parent.activeChild = null;\n this.changed();\n };\n }\n\n /** Make this node the one its ancestors resolve through. */\n activate(): void {\n let moved = false;\n for (let n = this as unknown as N; n.parent; n = n.parent) {\n if (n.parent.activeChild !== n) {\n n.parent.activeChild = n;\n moved = true;\n }\n }\n if (moved) this.changed();\n }\n\n /** The node a lookup made here starts from: down the active children, or the\n * newest where nothing has been activated yet. A yoke with no members yet\n * is passed over — there is no canvas behind it to answer. */\n leaf(): N {\n let n = this as unknown as N;\n for (;;) {\n const next: N | null = n.activeChild ?? n.newestMember();\n if (!next) return n;\n n = next;\n }\n }\n\n private newestMember(): N | null {\n for (let i = this.children.length - 1; i >= 0; i--) {\n const c = this.children[i]!;\n if (!(c.descends && c.children.length === 0)) return c;\n }\n return null;\n }\n\n /** Where a read made through this node starts. */\n start(): N {\n return this.descends ? this.leaf() : (this as unknown as N);\n }\n\n /** Whether this node is on the path a read from the root takes. */\n isActive(): boolean {\n let root = this as unknown as N;\n while (root.parent) root = root.parent;\n for (const n of root.leaf().chain()) if (n === (this as unknown as N)) return true;\n return false;\n }\n\n /** This node, then each ancestor up to the root. */\n *chain(): Generator<N> {\n for (let n: N | null = this as unknown as N; n; n = n.parent) yield n;\n }\n}\n\n/**\n * Push `value` onto an owner stack and hand back its release.\n *\n * Newest wins, but the release takes out *its own* entry wherever it now sits,\n * so a displaced owner leaving cannot disturb the one above it. A `null` value\n * registers nothing and releases to a no-op. Double-release safe.\n */\nexport function pushOwner<T>(stack: T[], value: T | null): () => void {\n if (value === null) return () => {};\n stack.push(value);\n let released = false;\n return () => {\n if (released) return;\n released = true;\n const i = stack.lastIndexOf(value);\n if (i !== -1) stack.splice(i, 1);\n };\n}\n","/**\n * The dep registry: named \"live source\" thunks. Actions declare\n * `requires: ['selection']`; the dispatcher calls `registry.get('selection')`\n * at invocation time to build a typed Deps bag.\n */\nimport type { DepSchema, DepName } from '../../index';\nimport { ScopeNode } from './scopeNode';\n\n/** Holds the live sources an action's declared dependencies resolve to.\n * Sources are thunks, read at invocation time, so an action never captures\n * stale state. */\nexport interface DepRegistry {\n /** Adds a live source for `name` over any already there. `below` answers\n * what the registry would without this source, so one can handle part of\n * a dep and hand the rest to the default it displaced. */\n register<K extends DepName>(name: K, source: DepSource<K>): () => void;\n get<K extends DepName>(name: K): DepSchema[K] | undefined;\n /** Hear that what the registry answers may have changed: a source was\n * registered or released anywhere in its tree, or an owner called\n * {@link DepRegistry.changed}. Returns the unsubscribe. A hand-built\n * registry whose answers never change leaves this and `changed` out. */\n subscribe?(listener: () => void): () => void;\n /** Say that a source's value changed. A source is a thunk read on demand,\n * so its owner is the only one who knows; chrome showing an action's\n * `enabled` or `active` state re-reads on this. */\n changed?(): void;\n /** Every name a `get` here would answer, sorted, with where its live\n * source sits. For inspection; a hand-built registry may leave it out. */\n list?(): readonly DepListing[];\n}\n\n/** A live source for dep `K`: a thunk read at invocation time. `below` reads\n * the source this one displaced, under it in its scope or in a scope above. */\nexport type DepSource<K extends DepName> = (below: () => DepSchema[K] | undefined) => DepSchema[K];\n\n/** One name a dep registry answers, as {@link DepRegistry.list} reports it. */\nexport interface DepListing {\n name: string;\n /** How many scopes above the asking one the live source was registered: 0 for its own. */\n depth: number;\n /** How many sources that scope holds under the name, the live one included. */\n stacked: number;\n}\n\n/** One node of the dep tree: the sources registered at it, over its parent's.\n * Each name holds a stack of sources, newest live, so a displaced source is\n * restored when the one above it leaves. */\nexport class DepNode extends ScopeNode<DepNode> {\n private readonly sources = new Map<string, Source[]>();\n\n readonly registry: DepRegistry = {\n register: <K extends DepName>(name: K, source: DepSource<K>) => {\n const key = name as string;\n const entry = source as Source;\n const stack = this.sources.get(key);\n if (stack) stack.push(entry);\n else this.sources.set(key, [entry]);\n this.changed();\n let released = false;\n return () => {\n if (released) return;\n released = true;\n const cur = this.sources.get(key);\n if (!cur) return;\n // Our own entry, wherever it now sits: a source already displaced must\n // take itself out without disturbing the one above it.\n const i = cur.lastIndexOf(entry);\n if (i === -1) return;\n cur.splice(i, 1);\n if (cur.length === 0) this.sources.delete(key);\n this.changed();\n };\n },\n get: <K extends DepName>(name: K) => {\n const stacks = [...this.start().chain()].map((n) => n.sources.get(name as string) ?? []);\n return readFrom(stacks, 0, (stacks[0]?.length ?? 0) - 1) as DepSchema[K] | undefined;\n },\n subscribe: (listener: () => void) => this.tree.listeners.subscribe(listener),\n list: () => {\n const found = new Map<string, DepListing>();\n let depth = 0;\n for (const n of this.start().chain()) {\n for (const [name, stack] of n.sources) {\n if (!found.has(name)) found.set(name, { name, depth, stacked: stack.length });\n }\n depth++;\n }\n return [...found.values()].sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));\n },\n changed: () => this.changed(),\n };\n\n constructor(parent: DepNode | null, descends: boolean) {\n super(parent, descends);\n NODES.set(this.registry, this);\n }\n}\n\ntype Source = (below: () => unknown) => unknown;\n\n/** The source at `stacks[scope][index]`, or the first one under it, read with\n * its own `below`. `stacks` runs from the asking scope outward. */\nfunction readFrom(stacks: readonly (readonly Source[])[], scope: number, index: number): unknown {\n if (scope >= stacks.length) return undefined;\n if (index < 0) return readFrom(stacks, scope + 1, (stacks[scope + 1]?.length ?? 0) - 1);\n return stacks[scope]![index]!(() => readFrom(stacks, scope, index - 1));\n}\n\nconst NODES = new WeakMap<DepRegistry, DepNode>();\n\n/** The tree node behind `registry`, when it is one of ours. */\nexport function depNodeOf(registry: DepRegistry | null): DepNode | null {\n return registry ? (NODES.get(registry) ?? null) : null;\n}\n\n/**\n * A stock dep registry with no parent: what `<DepRegistryProvider>` mounts,\n * for a dispatcher driven without React. Sources registered under one name\n * stack, newest live, and releasing one restores the one beneath it.\n */\nexport function createDepRegistry(): DepRegistry {\n return new DepNode(null, true).registry;\n}\n","/**\n * The actions store contract and the `actions` prop that seeds it. The\n * provider that implements this lives in `ActionsProvider.tsx`; nothing here\n * touches React.\n */\nimport type { GestureSpec, PhaseSpec } from '@weasel-js/gestures';\nimport type { BoundGesture } from './binding';\nimport type { Action } from './action';\nimport type { ActionTuning } from './tuning';\nimport type { BindingOverrides, ResolvedBindingOverrides } from './bindingOverrides';\nimport { RESERVED_ID_NAMES, RESERVED_ID_PREFIXES, type PhaseAtom } from '../../tools/routing/routeGrammar';\nimport type { Dispatcher, UiOngoingControl } from '../dispatcher/dispatcher';\nexport type { UiOngoingControl } from '../dispatcher/dispatcher';\n\n\n\n\n\n/**\n * Partial override or full descriptor passed via `<SceneCanvas actions={...}>`.\n * `null` disables a default at this id.\n */\nexport type ActionEntry = null | Partial<Action> | Action;\n\n/**\n * Shape of the `actions` prop on `<SceneCanvas>`. `null` disables all defaults.\n */\nexport type ActionsProp = null | Record<string, ActionEntry>;\n\n/**\n * Imperative API exposed by `useActionsRegistry()`.\n */\nexport interface ActionsRegistry {\n /** Add an action and return its release. Registrants for one id stack,\n * newest live, so releasing yours uncovers whoever you displaced. Call it\n * from an effect and release it in that effect's cleanup — registering from\n * a render body pushes an entry per render and releases none. */\n register(action: Action): () => void;\n /** Drop every registrant of `id`. This is the \"this action should not exist\"\n * door, not a release — for that, call what `register` returned. */\n unregister(id: string): void;\n /** Declare `id` not for this scope: it stays registered wherever it was,\n * but here — and in scopes below — it lists as absent and neither\n * `trigger` nor `begin` will fire it. Returns a release. This is the\n * \"not for me\" door — `unregister` is the \"should not exist\" one. */\n mute(id: string): () => void;\n /** Tune `id` here and in scopes below: its params and added bindings\n * apply to whichever descriptor is live for it, registered before the\n * tuning or after. Returns a release. See {@link ActionTuning}. */\n tune(id: string, tuning: ActionTuning): () => void;\n /** The params an invocation of `id` from this scope starts with when it\n * passes `given`: every tuning's params, `given` laid over them. What a\n * tool's chrome reads to show what the action it binds will do. */\n paramsOf(id: string, given?: Record<string, unknown>): Record<string, unknown>;\n /** Replace or remove bindings by id, here and in scopes below. Holders\n * merge: an inner scope's beats an outer one's, and a later one beats an\n * earlier one in the same scope. Returns a release. See {@link BindingOverrides}. */\n overrideBindings(overrides: BindingOverrides): () => void;\n /** Every override in force from this scope, read into specs. */\n bindingOverrides(): ResolvedBindingOverrides;\n list(): readonly Action[];\n /** Fire an immediate-invoker action by id. The optional `params` arg is\n * forwarded to `ImmediateInvoker.run` as its second argument — use it for\n * parametric actions (e.g. `trigger('tool.activate', { toolId: 'rect' })`).\n * Returns whether it ran one: `false` for an unknown id, for an action\n * whose `enabled` refuses or whose `run` returns `'pass'`, and for an\n * ongoing-invoker action, which\n * `trigger` cannot reach (see `begin`). `enabled` is asked at\n * `params.world`, and with no point when that is absent. */\n trigger(id: string, params?: Record<string, unknown>): boolean;\n /** Show what firing `id` with `params` would do, by its `Action.preview`,\n * and return what takes it down; calling that twice is harmless. Shows\n * nothing for an unknown id, one with no preview, and one whose `enabled`\n * refuses, asked as `trigger` asks it. */\n preview(id: string, params?: Record<string, unknown>): () => void;\n /**\n * Subscribe to registry mutations. The callback fires after any\n * `register`/`unregister` that changes the version. Returns an\n * unsubscribe function. Designed for `useSyncExternalStore`-driven\n * surfaces (e.g. `<ActionBar>` in `@weasel-js/ui`) that need to\n * re-render when the action set changes.\n */\n subscribe(listener: () => void): () => void;\n\n /**\n * Start an ongoing action driven by UI (color picker, opacity slider).\n * Returns a control object with `update(params)` and `end(reason)`.\n *\n * Returns `null` if no dispatcher is wired into this registry, the\n * action is unknown, or its invoker is not ongoing.\n *\n * See `Dispatcher.beginUiOngoing` for full semantics including\n * auto-commit when a prior UI handle for the same action is in flight.\n */\n begin(id: string, params?: Record<string, unknown>): UiOngoingControl | null;\n\n /** Wire a dispatcher into the registry so `begin()` can delegate to it.\n * Returns a release that takes out only this dispatcher; a `null` wires\n * nothing. */\n setDispatcher(d: Dispatcher | null): () => void;\n\n /** Make this registry's scope the one chrome above it reaches, and the one\n * keys go to: `trigger`, `begin` and `list` on any ancestor then answer from\n * here. A dispatcher calls it on the pointerdown and wheel that land in its\n * scope; moving DOM focus alone does not. */\n activate(): void;\n\n /** Whether a lookup made from the root of this registry's tree starts here.\n * A dispatcher with no canvas to press in asks this before handling a\n * keystroke. */\n isActive(): boolean;\n\n /** Whether this registry's scope is the one last activated on the page, in\n * any tree: the question a canvas's dispatcher asks before handling a key\n * or a paste that reached the page. No scope holds the keys before the\n * first activation. */\n holdsKeys(): boolean;\n\n /** Let go of the keys if this scope holds them, as its canvas unmounts. */\n dropKeys(): void;\n}\n\n// ─── Registration-time validation ─────────────────────────────────────────\n\n/** Validate that `id` is usable as an action id in the route grammar.\n * Rejects ids that start with a reserved sigil (would shadow future\n * grammar extensions) and ids that collide with phase keywords (would\n * parse as the bare-phase shorthand). Mirrors `defineTool`'s tool-id\n * validation. */\nexport function validateActionId(id: string): void {\n if (id.length === 0) {\n throw new Error(`weasel: action id may not be empty`);\n }\n if (RESERVED_ID_PREFIXES.has(id[0]!)) {\n throw new Error(\n `weasel: action id \"${id}\" starts with reserved sigil \"${id[0]}\" ` +\n `(reserved set: ${[...RESERVED_ID_PREFIXES].join(' ')})`,\n );\n }\n if (RESERVED_ID_NAMES.has(id)) {\n throw new Error(\n `weasel: action id \"${id}\" collides with a reserved phase keyword ` +\n `(reserved: ${[...RESERVED_ID_NAMES].join(', ')})`,\n );\n }\n}\n\n/** Reject any '&'-channel phase atom in an Action's defaultBinding —\n * actions have no owning tool, so '&' can't resolve. Tool-side bindings\n * (Tool.bindings) are the right place for '&' atoms. */\nexport function validateActionDefaultBinding(action: Action): void {\n const gs = action.defaultBinding;\n if (!gs) return;\n const entries: BoundGesture[] = Array.isArray(gs) ? gs : [gs as BoundGesture];\n for (const entry of entries) {\n const spec = ('kind' in entry ? entry : entry.spec) as GestureSpec;\n const phase: PhaseSpec | undefined = spec.phase;\n if (phase === undefined) continue;\n const atoms: readonly PhaseAtom[] = Array.isArray(phase)\n ? phase\n : [{ channel: '&', phase: phase }];\n for (const atom of atoms) {\n if (atom.channel === '&') {\n throw new Error(\n `weasel: action \"${action.id}\" defaultBinding uses '&' channel ` +\n `which has no owning tool to resolve to. Use a named tool channel ` +\n `(e.g. '[rect:engaged]') or '*' instead, or move this binding to ` +\n `the tool's own Tool.bindings.`,\n );\n }\n }\n }\n}\n\n","/**\n * The options a gesture binding hands the action it fires, and reading their params.\n */\nimport type { RoleRebinds } from './modifierRoles';\n\n/** Per-invocation options the dispatcher reads from a `GestureBinding`'s\n * `opts` field and passes to `OngoingInvoker.start`. */\nexport interface BindingOpts {\n /** The id a binding override names this binding by, `<owner>.<role>`:\n * `undo.key`, `rect.drag`, `nudge.left.big`. Without one it is its owner and\n * its position (`<entry>#<n>`, `<action>@<n>`), which moves when the defaults\n * are reordered, so a binding a host may persist an override for declares one. */\n id?: string;\n /** Gesture behaviors the action's own invoker runs. Routing carries the\n * array to the action and never reads an element, so the element type is\n * open here; `@weasel-js/core` narrows it. */\n behaviors?: unknown[];\n /** Per-binding action parameters, which an immediate invoker reads via the\n * second arg to `run`.\n *\n * May also be a thunk evaluated each time the value is needed, so a tool\n * can close over refs that mutate during a gesture (e.g. polygon `sides`\n * adjusted mid-drag via ArrowUp). An ongoing invoker that wants the latest\n * values at commit re-calls it inside `onEnd` via\n * `resolveParams(opts?.params)`. */\n params?: Record<string, unknown> | (() => Record<string, unknown>);\n /**\n * The views this binding is live in, by id, where `null` is the surface's\n * own camera. Omitted means every view.\n *\n * A binding that names the view an input landed in outranks every binding\n * that does not, whatever their scope tiers: naming a view is the most\n * specific thing a binding can say about where it applies. Without that, a\n * drag bound inside a minimap view loses to the active tool's marquee.\n */\n views?: readonly (string | null)[];\n /**\n * Says this binding is declared ahead of another on the same input on\n * purpose: its action declines through `enabled()` when the input is not its\n * to take, and the next binding fires. The dispatcher does that for any\n * binding; this tells the route-conflict check the order is the design.\n */\n yields?: boolean;\n /**\n * For a key binding: live while the pointer is over the surface, whichever\n * canvas holds the keys, and only then. For a key that means \"here\" — a\n * magnifier's peek — on a page with more than one surface that hears it.\n * A held key follows the pointer: one already down when it arrives presses\n * the binding, and leaving releases it.\n */\n over?: boolean;\n /**\n * Keys for some of the action's `modifierRoles` on this binding, by role\n * id, over the action's defaults and any tuning's.\n */\n roles?: RoleRebinds;\n /** Screen travel, in CSS pixels, a drag makes before this binding's ongoing action starts, over the\n * action's own `dragThresholdPx`. See `OngoingInvoker.dragThresholdPx`. */\n dragThresholdPx?: number;\n}\n\n/** Resolve `BindingOpts.params` to a concrete record (calling the thunk if\n * needed). Returns `undefined` for absent params. */\nexport function resolveParams(\n params: BindingOpts['params'],\n): Record<string, unknown> | undefined {\n if (params === undefined) return undefined;\n return typeof params === 'function' ? params() : params;\n}\n","/**\n * Modifier roles: the modifiers an ongoing action reads while it runs, named\n * by what they do rather than which key they are, so a binding or a tuning can\n * move one to another key without forking the action.\n */\nimport { isApplePlatform, type ModifierKey } from '@weasel-js/gestures';\nimport type { ModifierState } from '../../vocabulary';\n\n/** The keys that hold a role: any one of them held holds it. `'mod'` is Cmd\n * on a Mac and Ctrl elsewhere. An empty list never holds it. */\nexport type RoleKeys = readonly ModifierKey[];\n\n/** One modifier an action reads mid-gesture. */\nexport interface ModifierRole {\n label: string;\n /** The keys that hold it unless a tuning or a binding says otherwise. */\n keys: RoleKeys;\n}\n\n/** An action's roles by id, e.g. `'handle.holdAngle'`. */\nexport type ModifierRoles = Readonly<Record<string, ModifierRole>>;\n\n/** Keys a tuning or a binding gives some of an action's roles. */\nexport type RoleRebinds = Readonly<Record<string, RoleKeys>>;\n\n/** Whether any of `keys` is held. */\nexport function keysHeld(keys: RoleKeys, modifiers: ModifierState, isMac: boolean): boolean {\n return keys.some((k) => {\n if (k === 'mod') return isMac ? modifiers.meta : modifiers.ctrl;\n return modifiers[k];\n });\n}\n\n/** The keys each of `roles` answers to with `rebinds` laid over them, or\n * undefined when the action declares none. A rebind naming a role the action\n * does not declare is dropped. */\nexport function roleKeysOf(\n roles: ModifierRoles | undefined,\n rebinds?: RoleRebinds,\n): Readonly<Record<string, RoleKeys>> | undefined {\n if (!roles) return undefined;\n const out: Record<string, RoleKeys> = {};\n for (const id of Object.keys(roles)) out[id] = rebinds?.[id] ?? roles[id].keys;\n return out;\n}\n\n/** `keys` with each `'mod'` written as the key it is on this platform. */\nexport function platformRoleKeys(\n keys: Readonly<Record<string, RoleKeys>>,\n isMac: boolean,\n): Readonly<Record<string, RoleKeys>> {\n const out: Record<string, RoleKeys> = {};\n for (const id of Object.keys(keys)) out[id] = keys[id].map((k) => (k === 'mod' ? (isMac ? 'meta' : 'ctrl') : k));\n return out;\n}\n\n/** Which roles `modifiers` hold. */\nexport function resolveRoles(\n keys: Readonly<Record<string, RoleKeys>>,\n modifiers: ModifierState,\n isMac: boolean,\n): Record<string, boolean> {\n const out: Record<string, boolean> = {};\n for (const id of Object.keys(keys)) out[id] = keysHeld(keys[id], modifiers, isMac);\n return out;\n}\n\n/** `roles` with `rebinds` written into their keys. */\nexport function rebindRoles(roles: ModifierRoles, rebinds: RoleRebinds): ModifierRoles {\n const out: Record<string, ModifierRole> = {};\n for (const id of Object.keys(roles)) {\n out[id] = rebinds[id] ? { ...roles[id], keys: rebinds[id] } : roles[id];\n }\n return out;\n}\n\n/**\n * A reader for an action's own roles. It answers from `ctx.roles`, which the\n * dispatcher resolves on every event, and falls back to the role's default\n * keys where nothing resolved them: an invoker called directly, or a context\n * a cancel-all built with no event.\n */\nexport function roleReader<R extends ModifierRoles>(roles: R) {\n return (ctx: { roles?: Readonly<Record<string, boolean>>; modifiers: ModifierState }, id: keyof R & string): boolean =>\n ctx.roles?.[id] ?? keysHeld(roles[id].keys, ctx.modifiers, isApplePlatform());\n}\n","/**\n * Tuning: what a host changes about an action it did not write — the params\n * every invocation starts from, and bindings added beside the action's own —\n * without restating the descriptor. `ActionsRegistry.tune` holds tunings and\n * applies them to whatever descriptor is live for the id.\n */\nimport type { GestureSpec } from '@weasel-js/gestures';\nimport type { Action } from './action';\nimport type { BoundGesture } from './binding';\nimport { resolveParams, type BindingOpts, type Invoker } from './invoker';\nimport { rebindRoles, type RoleRebinds } from './modifierRoles';\n\n/** An action's params, or a thunk read each time the action asks for them. */\nexport type ActionParams<P = Record<string, unknown>> = Partial<P> | (() => Partial<P>);\n\n/** A binding added for an action: a gesture alone, or a gesture with the\n * options it passes — the {@link BoundGesture} shape, its params typed. */\nexport type TunedBinding<P = Record<string, unknown>> =\n | GestureSpec\n | { spec: GestureSpec; opts: Omit<BindingOpts, 'params'> & { params?: ActionParams<P> } };\n\n/** What a host changes about one action. */\nexport interface ActionTuning<P = Record<string, unknown>> {\n /** Params every invocation starts from. What a binding or a `trigger` call\n * passes is laid over them, so these fill in what it leaves out. A thunk is\n * read on every call, and an ongoing action resolving its `opts.params`\n * mid-gesture sees the value as it is then. */\n params?: ActionParams<P>;\n /** Bindings added after the action's own `defaultBinding`. */\n bindings?: readonly TunedBinding<P>[];\n /** Keys for some of the action's `modifierRoles`, by role id. A binding's\n * own `opts.roles` is laid over these. */\n roles?: RoleRebinds;\n /** Told the params the last-operation panel just set for the action, which hold for the rest of the session.\n * A tuning whose `params` thunk reads a host's store writes the ones it supplies back there, so the store, and\n * whatever draws it, says what the next run will use rather than overriding it. */\n keep?(params: Readonly<Record<string, unknown>>): void;\n}\n\ntype Params = BindingOpts['params'];\n\nconst WRAPS = new WeakMap<Invoker, { inner: Invoker; params: ActionParams }>();\n\nfunction layered(under: ActionParams, over: Params): Params {\n if (typeof under !== 'function' && typeof over !== 'function') return tunedParams([{ params: under }], over);\n return () => tunedParams([{ params: under }], resolveParams(over));\n}\n\nfunction wrapInvoker(invoker: Invoker, params: ActionParams): Invoker {\n for (let w: Invoker | undefined = invoker; w; w = WRAPS.get(w)?.inner) {\n if (WRAPS.get(w)?.params === params) return invoker;\n }\n const base = (given: Record<string, unknown> | undefined) => tunedParams([{ params }], given);\n const wrapped: Invoker = invoker.timing === 'immediate'\n ? { timing: 'immediate', run: (deps, given) => invoker.run(deps, base(given)) }\n : {\n ...invoker,\n start: (ctx, opts) => invoker.start(\n ctx.params ? { ...ctx, params: base(ctx.params) } : ctx,\n { ...opts, params: layered(params, opts?.params) },\n ),\n };\n WRAPS.set(wrapped, { inner: invoker, params });\n return wrapped;\n}\n\nfunction withBindings(\n own: Action['defaultBinding'],\n added: readonly TunedBinding[],\n): BoundGesture[] {\n const base: BoundGesture[] = own === undefined ? [] : Array.isArray(own) ? own : [own];\n return [...base, ...(added as readonly BoundGesture[]).filter((b) => !base.includes(b))];\n}\n\nconst CURSOR_WRAPS = new WeakMap<object, { inner: Action['cursor']; params: ActionParams }>();\n\n/** A cursor that reads params, handed the tuning's under the call's. */\nfunction wrapCursor(cursor: Action['cursor'], params: ActionParams): Action['cursor'] {\n if (typeof cursor !== 'function') return cursor;\n for (let w: Action['cursor'] = cursor; typeof w === 'function'; w = CURSOR_WRAPS.get(w)?.inner) {\n if (CURSOR_WRAPS.get(w)?.params === params) return cursor;\n }\n const wrapped = (given: Record<string, unknown> | undefined) => cursor(tunedParams([{ params }], given));\n CURSOR_WRAPS.set(wrapped, { inner: cursor, params });\n return wrapped;\n}\n\nconst PREVIEW_WRAPS = new WeakMap<object, { inner: Action['preview']; params: ActionParams }>();\n\n/** A preview handed the tuning's params under the call's, as `run` is. */\nfunction wrapPreview(preview: Action['preview'], params: ActionParams): Action['preview'] {\n if (!preview) return preview;\n for (let w: Action['preview'] = preview; w; w = PREVIEW_WRAPS.get(w)?.inner) {\n if (PREVIEW_WRAPS.get(w)?.params === params) return preview;\n }\n const wrapped: NonNullable<Action['preview']> = (deps, given) => preview(deps, tunedParams([{ params }], given));\n PREVIEW_WRAPS.set(wrapped, { inner: preview, params });\n return wrapped;\n}\n\nfunction tuneOnce(action: Action, tuning: ActionTuning): Action {\n const invoker = tuning.params && action.invoker ? wrapInvoker(action.invoker, tuning.params) : action.invoker;\n const cursor = tuning.params ? wrapCursor(action.cursor, tuning.params) : action.cursor;\n const preview = tuning.params ? wrapPreview(action.preview, tuning.params) : action.preview;\n const bindings = tuning.bindings?.length ? withBindings(action.defaultBinding, tuning.bindings) : null;\n const modifierRoles = tuning.roles && action.modifierRoles ? rebindRoles(action.modifierRoles, tuning.roles) : null;\n if (\n invoker === action.invoker && cursor === action.cursor && preview === action.preview &&\n bindings === null && modifierRoles === null\n ) {\n return action;\n }\n return {\n ...action,\n ...(modifierRoles ? { modifierRoles } : {}),\n ...(invoker ? { invoker } : {}),\n ...(cursor ? { cursor } : {}),\n ...(preview ? { preview } : {}),\n ...(bindings ? { defaultBinding: bindings } : {}),\n };\n}\n\n/** The params an invocation passing `given` starts with under `tunings`:\n * each tuning's params over the one before, and `given` over them all. */\nexport function tunedParams(\n tunings: readonly ActionTuning[],\n given?: Record<string, unknown>,\n): Record<string, unknown> {\n let out: Record<string, unknown> = {};\n for (const t of tunings) out = { ...out, ...resolveParams(t.params as Params) };\n return { ...out, ...given };\n}\n\n/** `action` with each tuning applied in turn, a later one's params over an\n * earlier one's. Applying a tuning to a copy it already tuned changes nothing. */\nexport function tuneAction(action: Action, tunings: readonly ActionTuning[]): Action {\n let out = action;\n for (const t of tunings) out = tuneOnce(out, t);\n return out;\n}\n","/**\n * Binding overrides: a host's replacements for bindings it did not write,\n * keyed by binding id. An override replaces or removes one binding, on an\n * action or on a contribution alike; adding a key beside the defaults is\n * `tune`'s job.\n */\nimport { bindingSpec, type BindingOverrideInput, type GestureSpec } from '@weasel-js/gestures';\nimport type { Action } from './action';\nimport { actionBindings, type BoundGesture, type GestureBinding } from './binding';\n\n/** Overrides by binding id: a route string or spec to bind instead, or `null` to unbind. */\nexport type BindingOverrides = Readonly<Record<string, BindingOverrideInput>>;\n\n/** Overrides read into specs, one per binding id. */\nexport type ResolvedBindingOverrides = ReadonlyMap<string, GestureSpec | null>;\n\nexport const NO_OVERRIDES: ResolvedBindingOverrides = new Map();\n\n/** A binding's id: its declared `opts.id`, else its owner and its position\n * there — `<entry>#<n>` for an entry's binding (`ownerId`), `<action>@<n>` for\n * an action's own (`ownerId` null), so an entry and an action of one id never\n * share a derived id. */\nexport function bindingId(b: GestureBinding, ownerId: string | null, index: number): string {\n return b.opts?.id ?? (ownerId === null ? `${b.actionId}@${index}` : `${ownerId}#${index}`);\n}\n\n/** Merge override maps into one, a later map winning per id. A route string\n * that does not parse is skipped with a warning, leaving the binding as it was. */\nexport function resolveBindingOverrides(maps: readonly BindingOverrides[]): ResolvedBindingOverrides {\n if (maps.length === 0) return NO_OVERRIDES;\n const out = new Map<string, GestureSpec | null>();\n for (const map of maps) {\n for (const [id, input] of Object.entries(map)) {\n try {\n out.set(id, bindingSpec(input));\n } catch (err) {\n console.warn(`weasel: binding override \"${id}\" is not a route: ${(err as Error).message}`);\n }\n }\n }\n return out;\n}\n\n/** `b` under its override: the same binding, one with another spec, or `null` when unbound. */\nexport function overridden(\n b: GestureBinding,\n id: string,\n overrides: ResolvedBindingOverrides,\n): GestureBinding | null {\n if (!overrides.has(id)) return b;\n const spec = overrides.get(id)!;\n return spec === null ? null : { ...b, spec };\n}\n\n/** The bindings `ownerId` declares, each under its override, the unbound ones\n * left out: what dispatch routes by. A `null` owner is an action's own. */\nexport function overriddenBindings(\n bindings: readonly GestureBinding[],\n ownerId: string | null,\n overrides: ResolvedBindingOverrides = NO_OVERRIDES,\n): GestureBinding[] {\n const out: GestureBinding[] = [];\n bindings.forEach((b, i) => {\n const next = overridden(b, bindingId(b, ownerId, i), overrides);\n if (next) out.push(next);\n });\n return out;\n}\n\n/** `action` with `overrides` applied to its own bindings, each keeping its id,\n * so every reader of `defaultBinding` — dispatch, menus, chips — sees the same keys. */\nexport function overrideActionBindings(action: Action, overrides: ResolvedBindingOverrides): Action {\n if (overrides.size === 0 || action.defaultBinding === undefined) return action;\n const declared = actionBindings(action);\n if (!declared.some((b, i) => overrides.has(bindingId(b, null, i)))) return action;\n const kept: BoundGesture[] = [];\n declared.forEach((b, i) => {\n const id = bindingId(b, null, i);\n const next = overridden(b, id, overrides);\n if (next) kept.push({ spec: next.spec, opts: { ...next.opts, id } });\n });\n return { ...action, defaultBinding: kept };\n}\n","import type { MenuDef, MenuHit, MenuWhen, OwnedMenuDef } from './types';\n\nconst oneOf = <T>(want: T | readonly T[] | undefined, got: T | undefined) =>\n want === undefined || (Array.isArray(want) ? (want as readonly T[]).includes(got as T) : want === got);\n\nfunction matches(when: MenuWhen, hit: MenuHit): boolean {\n return oneOf(when.bodyTarget, hit.bodyTarget) && oneOf(when.bodyKind, hit.bodyKind);\n}\n\n/** The menus live now: ambient defs, then the active tool's. Defs that share\n * an id become one menu: each contribution's children in turn, with a\n * separator between contributions. Children stay at their own keys, so the\n * paths their values are read at do not move; a key a previous contribution\n * took gets `~n` appended. The first def of an id supplies the schema's\n * name and the def's `when`. */\nexport function mergeMenuDefs(defs: readonly OwnedMenuDef[], activeTool: string | null): MenuDef[] {\n const live = [\n ...defs.filter((d) => d.owner === null),\n ...defs.filter((d) => d.owner !== null && d.owner === activeTool),\n ];\n const byId = new Map<string, { def: MenuDef; parts: number }>();\n for (const { def } of live) {\n const prev = byId.get(def.id);\n if (!prev) {\n byId.set(def.id, { def: { ...def, menu: { ...def.menu, children: { ...def.menu.children } } }, parts: 1 });\n continue;\n }\n const n = prev.parts++;\n const children = prev.def.menu.children;\n children[`~sep${n}`] = { kind: 'separator', name: '', description: '', default: undefined };\n for (const [k, node] of Object.entries(def.menu.children)) {\n children[Object.hasOwn(children, k) ? `${k}~${n}` : k] = node;\n }\n if (!prev.def.when && def.when) prev.def.when = def.when;\n }\n return [...byId.values()].map((m) => m.def);\n}\n\n/** The first def whose `when` matches `hit`. */\nexport function pickMenu(defs: readonly MenuDef[], hit: MenuHit): MenuDef | undefined {\n return defs.find((d) => d.when !== undefined && matches(d.when, hit));\n}\n","import type { MenuEntry } from '@weasel-js/menu';\nimport {\n prefHoldsValue, prefLeaves, prefObjectBase, prefVariantDefault, prefVariantOf,\n type PrefField, type PrefGroup, type PrefLeaf, type PrefList, type PrefMap, type PrefObject, type PrefPaint,\n type PrefUnion,\n} from '@weasel-js/prefs';\n\n/** How values are read and written where a set of rows is drawn. */\nexport interface MenuAccess {\n values(path: string): unknown;\n onChange?: (path: string, value: unknown) => void;\n}\n\n/** What a compound leaf draws its parts with. */\nexport interface MenuDraw {\n /** The schema a `field` leaf offers the fields of. */\n root: PrefGroup;\n access: MenuAccess;\n /** The rows of one leaf at `key`, inside the list or map entry at `entry` when given. */\n leaf(leaf: PrefLeaf, key: string, access: MenuAccess, off: boolean, entry?: string): MenuEntry[];\n /** The rows of an object's fields, whose paths start at `prefix`. */\n fields(fields: PrefObject['children'], prefix: string, access: MenuAccess, off: boolean): MenuEntry[];\n}\n\nconst noop = () => {};\nconst sep = (key: string): MenuEntry => ({ kind: 'separator', key });\nconst isRecord = (v: unknown): v is Record<string, unknown> => typeof v === 'object' && v !== null && !Array.isArray(v);\n\n/** A map key as one segment of a dotted path: a `.` or `\\` in it is escaped with a `\\`. */\nexport function pathSegment(key: string): string {\n return key.replace(/[\\\\.]/g, '\\\\$&');\n}\n\n/** A dotted path's segments, each unescaped: the inverse of joining {@link pathSegment}s with `.`. */\nexport function pathSegments(path: string): string[] {\n const out: string[] = [];\n let seg = '';\n for (let i = 0; i < path.length; i++) {\n const ch = path[i]!;\n if (ch === '\\\\' && i + 1 < path.length) seg += path[++i];\n else if (ch === '.') { out.push(seg); seg = ''; } else seg += ch;\n }\n out.push(seg);\n return out;\n}\n\n/** `container` with the value at `segs` replaced, every container on the way copied. */\nfunction setIn(container: unknown, segs: readonly string[], value: unknown): unknown {\n const [head, ...rest] = segs;\n if (head === undefined) return value;\n if (Array.isArray(container)) {\n const out = [...container];\n out[Number(head)] = setIn(container[Number(head)], rest, value);\n return out;\n }\n const base = isRecord(container) ? container : {};\n const next = setIn(base[head], rest, value);\n if (next !== undefined) return { ...base, [head]: next };\n const { [head]: _dropped, ...kept } = base;\n return kept;\n}\n\n/** Reads and writes below `path` through the value `held` reads, which a write replaces whole. */\nfunction below(outer: MenuAccess, path: string, held: () => unknown, writable: boolean): MenuAccess {\n const inside = (p: string) => p.startsWith(`${path}.`);\n const rel = (p: string) => p.slice(path.length + 1);\n const values = (p: string): unknown => {\n if (!inside(p)) return outer.values(p);\n let cur = held();\n for (const seg of pathSegments(rel(p))) cur = cur !== null && typeof cur === 'object' ? (cur as Record<string, unknown>)[seg] : undefined;\n return cur;\n };\n const { onChange } = outer;\n if (!onChange || !writable) return { values };\n return {\n values,\n onChange: (p, v) => (inside(p) ? onChange(path, setIn(held(), pathSegments(rel(p)), v)) : onChange(p, v)),\n };\n}\n\nfunction submenu(key: string, leaf: PrefLeaf, entries: MenuEntry[]): MenuEntry[] {\n if (entries.length === 0) return [];\n return [{\n kind: 'submenu', key, label: leaf.name, entries,\n ...(leaf.icon ? { icon: leaf.icon } : {}),\n ...(leaf.access ? { access: leaf.access } : {}),\n }];\n}\n\n/** An object as a submenu of its fields; each edit writes the object whole. */\nexport function objectRows(draw: MenuDraw, leaf: PrefObject, key: string, path: string, off: boolean): MenuEntry[] {\n const held = () => prefObjectBase(leaf, draw.access.values(path));\n const access = below(draw.access, path, held, true);\n return submenu(key, leaf, draw.fields(leaf.children, path, access, off || leaf.readout === true));\n}\n\n/** A \"Remove <name>\" submenu of one row per entry, each labeled as `labels` names it, which `drop` removes. */\nfunction removeRows(key: string, name: string, labels: readonly string[], off: boolean, drop: (i: number) => void): MenuEntry {\n return {\n kind: 'submenu', key, label: `Remove ${name}`, ...(off ? { disabled: true } : {}),\n entries: labels.map((label, i): MenuEntry => ({ kind: 'item', key: `${key}/${i}`, label, disabled: off, run: () => drop(i) })),\n };\n}\n\n/** A list as a submenu of its entries, each drawn as its item and named for its place, with a row that adds an\n * entry and a submenu that removes any one, within the list's bounds. */\nexport function listRows(draw: MenuDraw, leaf: PrefList, key: string, path: string, off: boolean): MenuEntry[] {\n const held = (): readonly unknown[] => {\n const v = draw.access.values(path);\n return Array.isArray(v) ? v : Array.isArray(leaf.default) ? leaf.default : [];\n };\n const frozen = off || leaf.readout === true;\n const access = below(draw.access, path, held, true);\n const name = leaf.item.name || leaf.name;\n const items = held();\n const rows = items.flatMap((_, i) =>\n draw.leaf({ ...leaf.item, name: `${name} ${i + 1}` }, `${path}.${i}`, access, frozen, `${path}.${i}`));\n const { onChange } = draw.access;\n if (onChange && !leaf.readout) {\n const n = items.length;\n rows.push(sep(`${path}/±`), {\n kind: 'item', key: `${path}/+`, label: `Add ${name}`,\n disabled: frozen || (leaf.maxItems !== undefined && n >= leaf.maxItems),\n run: () => onChange(path, [...held(), leaf.item.default]),\n });\n if (n > 0) {\n rows.push(removeRows(\n `${path}/-`, name, items.map((_, i) => `${name} ${i + 1}`), frozen || n <= (leaf.minItems ?? 0),\n (i) => onChange(path, held().filter((_, j) => j !== i)),\n ));\n }\n }\n return submenu(key, leaf, rows);\n}\n\n/** A map as a submenu of its entries, each drawn as its item and named for its key, with a text row that adds an\n * entry under the key typed into it and a submenu that removes any one. A key's `.` is escaped in its path. */\nexport function mapRows(draw: MenuDraw, leaf: PrefMap, key: string, path: string, off: boolean): MenuEntry[] {\n const held = (): Record<string, unknown> => {\n const v = draw.access.values(path);\n return isRecord(v) ? v : isRecord(leaf.default) ? leaf.default : {};\n };\n const frozen = off || leaf.readout === true;\n const access = below(draw.access, path, held, true);\n const keys = Object.keys(held());\n const rows = keys.flatMap((k) => {\n const at = `${path}.${pathSegment(k)}`;\n return draw.leaf({ ...leaf.item, name: k }, at, access, frozen, at);\n });\n const { onChange } = draw.access;\n if (onChange && !leaf.readout) {\n const name = leaf.item.name || leaf.name;\n rows.push(sep(`${path}/±`), {\n kind: 'text', key: `${path}/+`, label: `Add ${name}`, value: undefined, ...(frozen ? { disabled: true } : {}),\n set: (k) => {\n const now = held();\n if (k !== '' && !Object.hasOwn(now, k)) onChange(path, { ...now, [k]: leaf.item.default });\n },\n });\n if (keys.length > 0) {\n rows.push(removeRows(`${path}/-`, name, keys, frozen, (i) => {\n const { [keys[i]!]: _dropped, ...kept } = held();\n onChange(path, kept);\n }));\n }\n }\n return submenu(key, leaf, rows);\n}\n\n/** A union as a submenu: its variants as radio rows, then the fields of the variant it holds. Choosing a variant\n * writes that variant's default. */\nexport function unionRows(draw: MenuDraw, leaf: PrefUnion, key: string, path: string, off: boolean): MenuEntry[] {\n const frozen = off || leaf.readout === true;\n const current = prefVariantOf(leaf, draw.access.values(path)) ?? prefVariantOf(leaf, leaf.default);\n const { onChange } = draw.access;\n const choices = Object.entries(leaf.variants).map(([v, variant]): MenuEntry => ({\n kind: 'item', key: `${path}/${v}`, label: variant.name, checked: v === current?.[0], radio: true,\n disabled: frozen || !onChange,\n run: onChange ? () => onChange(path, prefVariantDefault(leaf, v)) : noop,\n }));\n if (!current) return submenu(key, leaf, choices);\n const [v, variant] = current;\n const held = () => {\n const now = draw.access.values(path);\n return prefVariantOf(leaf, now)?.[0] === v ? now : prefVariantDefault(leaf, v);\n };\n const fields = draw.fields(variant.children, path, below(draw.access, path, held, true), frozen);\n return submenu(key, leaf, fields.length ? [...choices, sep(`${path}/|`), ...fields] : choices);\n}\n\n/** A field reference as a submenu of radio rows, one per value-holding leaf of the schema it may name. */\nexport function fieldRows(draw: MenuDraw, leaf: PrefField, key: string, path: string, off: boolean): MenuEntry[] {\n const held = draw.access.values(path);\n const { onChange } = draw.access;\n const rows: MenuEntry[] = [];\n for (const [p, l] of prefLeaves(draw.root)) {\n if (p === path || !prefHoldsValue(l) || (leaf.kinds && !leaf.kinds.includes(l.kind))) continue;\n rows.push({\n kind: 'item', key: `${path}/${p}`, label: l.name || p, checked: held === p, radio: true,\n disabled: off || leaf.readout === true || !onChange,\n run: onChange ? () => onChange(path, p) : noop,\n });\n }\n return submenu(key, leaf, rows);\n}\n\n/** A paint as a color row when it is solid or none, which writes a solid paint keeping its other fields; any other\n * kind reads as its name and kind. */\nexport function paintRows(draw: MenuDraw, leaf: PrefPaint, key: string, path: string, off: boolean): MenuEntry[] {\n const held = draw.access.values(path);\n const access = leaf.access ? { access: leaf.access } : {};\n const solid = isRecord(held) && (held.kind === undefined || held.kind === 'solid') && typeof held.color === 'string';\n if (held != null && !solid) {\n const kind = isRecord(held) && typeof held.kind === 'string' ? held.kind : '—';\n return [{ kind: 'item', key, label: `${leaf.name}: ${kind}`, ...access, disabled: true, run: noop }];\n }\n const { onChange } = draw.access;\n return [{\n kind: 'color', key, label: leaf.name, ...access,\n ...(off ? { disabled: true } : {}),\n value: solid ? (held as { color: string }).color : undefined,\n ...(leaf.alpha ? { alpha: true } : {}),\n ...(leaf.readout || !onChange ? {} : {\n set: (color: string) => onChange(path, { ...(isRecord(held) ? held : {}), color }),\n }),\n }];\n}\n","import type { MenuEntry } from '@weasel-js/menu';\nimport {\n isBuiltinPref, isPrefLeaf, isPrefSection, PREF_SCOPE, prefAliasedLeaf, prefAliasTarget, prefConditionHolds, prefDisplayBounds, prefLeafAt,\n prefNumberAt, prefScopeIn, prefScopeUnder, prefUnitAccepts, prefValueAtPath, resolvePrefUnit,\n type PrefConditionJudge, type PrefOwner,\n type PrefAction, type PrefBoolean, type PrefColor, type PrefConditionReader, type PrefEnum, type PrefGroup,\n type PrefField, type PrefGroupAs, type PrefLeaf, type PrefList, type PrefMap, type PrefNumber, type PrefObject,\n type PrefPaint, type PrefSection, type PrefString, type PrefUnion,\n} from '@weasel-js/prefs';\nimport type { Action } from '../interactions/actions/action';\nimport type { ActionDeps } from '../interactions/actions/invoker';\nimport { actionItems, type ActionItem } from '../interactions/actions/actionItems';\nimport { actionShortcuts } from '../interactions/actions/actionShortcuts';\nimport { evaluateActive, evaluateEnabled } from '../interactions/actions/actionEnabled';\nimport { actionSettingsParams, readActionSettings } from '../interactions/actions/actionSettings';\nimport { endlessAllows } from '@weasel-js/quantity';\nimport { isDev } from '@weasel-js/react';\nimport type { MenuDef } from './types';\nimport {\n fieldRows, listRows, mapRows, objectRows, paintRows, unionRows, type MenuAccess, type MenuDraw,\n} from './compoundRows';\nimport type { Point } from '@weasel-js/geom';\n\n/** What resolving reads: the registered actions, each one's deps, how to run\n * one, and the values behind the schema's value leaves. */\nexport interface MenuSources {\n actions(): readonly Action[];\n depsFor(action: Action): ActionDeps | undefined;\n trigger(id: string, params?: Record<string, unknown>): boolean;\n /** The value at a leaf's dotted path. Booleans, enums, and numbers are left\n * out of a menu without both this and `onChange`, colors and strings without\n * this, and `showIf`/`enableIf` are checked only with it. */\n values?(path: string): unknown;\n onChange?(path: string, value: unknown): void;\n /** The schema an `alias` leaf's `of` is read in. Default: the menu's own. */\n over?: PrefGroup;\n /** The rows of an app-defined leaf, which a menu otherwise leaves out. `values` and `onChange` read and write\n * where the leaf sits, inside an object or a list entry as at the top. */\n customRows?(leaf: PrefLeaf, at: MenuCustomAt): readonly MenuEntry[];\n}\n\n/** Where {@link MenuSources.customRows} draws a leaf: the row key, the value's path, and how to reach it. */\nexport interface MenuCustomAt extends MenuAccess {\n key: string;\n path: string;\n disabled: boolean;\n}\n\ntype Ctx = {\n src: MenuSources;\n byId: Map<string, Action>;\n root: PrefGroup;\n read?: PrefConditionReader;\n at?: Point;\n params?: Record<string, unknown>;\n /** The path of the list or map entry the rows sit in, which a condition reading `from: 'item'` names its paths under. */\n entry?: string;\n};\n\ntype Children = Record<string, PrefLeaf | PrefGroup | PrefSection>;\n\nconst SUBMENU_AS: ReadonlySet<PrefGroupAs | undefined> = new Set(['menu', 'page', 'tab', 'panel']);\nconst noop = () => {};\nconst withAccess = (access?: string): { access?: string } => (access ? { access } : {});\nconst sep = (key: string): MenuEntry => ({ kind: 'separator', key });\n\nfunction itemOf(ctx: Ctx, it: ActionItem, key: string, label: string, off: boolean, access?: string): MenuEntry {\n const deps = ctx.src.depsFor(it.action);\n const point = ctx.at ? { world: ctx.at } : {};\n if (it.action.settings) return settingsOf(ctx, it, key, label, off || !evaluateEnabled(it.action, deps, ctx.at).enabled, access);\n return {\n kind: 'item',\n key,\n label,\n ...withAccess(access),\n icon: it.icon,\n shortcut: actionShortcuts(it.action, it.params)[0],\n disabled: off || !evaluateEnabled(it.action, deps, ctx.at).enabled,\n checked: evaluateActive(it.action, deps),\n run: () => { ctx.src.trigger(it.action.id, { ...ctx.params, ...it.params, ...point }); },\n };\n}\n\n/** An action carrying settings as a submenu of its form's rows, read when the\n * menu resolves; each change triggers the action with the params it makes. */\nfunction settingsOf(ctx: Ctx, it: ActionItem, key: string, label: string, off: boolean, access?: string): MenuEntry {\n const settings = it.action.settings!;\n const state = off ? null : readActionSettings(it.action, ctx.src.depsFor(it.action));\n const mixed = new Set(state?.mixed ?? []);\n const values = (path: string): unknown => (mixed.has(path) ? undefined : prefValueAtPath(state?.values, path));\n const onChange = (path: string, value: unknown): void => {\n const params = actionSettingsParams(settings, path, value);\n if (params) ctx.src.trigger(it.action.id, { ...ctx.params, ...it.params, ...params });\n };\n const form: Ctx = {\n ...ctx,\n src: { ...ctx.src, values, onChange, over: settings.schema },\n root: settings.schema,\n read: (path, from) => (from === 'item' ? undefined : values(path)),\n };\n const entries = state ? tidy(groupRows(form, settings.schema.children, '', ROOT)) : [];\n return {\n kind: 'submenu',\n key,\n label,\n ...(it.icon ? { icon: it.icon } : {}),\n ...withAccess(access),\n ...(entries.length === 0 ? { disabled: true } : {}),\n entries,\n };\n}\n\n/** The items a registry key names: an action's (one per variant), or the one\n * variant `id:variant` picks. */\nfunction itemsNamed(ctx: Ctx, name: string): ActionItem[] {\n const action = ctx.byId.get(name);\n if (action) return actionItems(action);\n const colon = name.indexOf(':');\n const owner = colon > 0 ? ctx.byId.get(name.slice(0, colon)) : undefined;\n return owner ? actionItems(owner).filter((it) => it.key === name) : [];\n}\n\nfunction actionRows(ctx: Ctx, leaf: PrefAction, key: string, off: boolean): MenuEntry[] {\n const own = leaf.label || leaf.name;\n if (leaf.action === undefined) {\n // A menu holds no code, so it can be saved as data: a leaf with only `run` is a dead row.\n if (!own) return [];\n if (isDev()) console.warn(`weasel: menu row \"${key}\" names no registered action, so it does nothing`);\n return [{ kind: 'item', key, label: own, disabled: true, run: noop }];\n }\n const items = itemsNamed(ctx, leaf.action);\n if (items.length === 1) return [itemOf(ctx, items[0]!, key, own || items[0]!.label, off, leaf.access)];\n return items.map((it) => itemOf(ctx, it, `${key}/${it.key}`, it.label, off));\n}\n\nfunction siblingsOf(ctx: Ctx, path: string): Record<string, unknown> | undefined {\n const dot = path.lastIndexOf('.');\n const parent = dot < 0 ? undefined : ctx.src.values!(path.slice(0, dot));\n return parent && typeof parent === 'object' ? parent as Record<string, unknown> : undefined;\n}\n\nfunction booleanRows(ctx: Ctx, leaf: PrefBoolean, key: string, path: string, off: boolean): MenuEntry[] {\n const { values, onChange } = ctx.src;\n if (!values || !onChange) return [];\n const stored = values(path);\n const on = leaf.encoding ? leaf.encoding.read(stored, siblingsOf(ctx, path)) : stored === true;\n const write = (v: boolean) => (leaf.encoding ? leaf.encoding.write(v, siblingsOf(ctx, path)) : v);\n return [{\n kind: 'item', key, label: leaf.name, ...withAccess(leaf.access), checked: on,\n disabled: off || leaf.readout === true,\n run: leaf.readout ? noop : () => onChange(path, write(!on)),\n }];\n}\n\nfunction enumRows(ctx: Ctx, leaf: PrefEnum, key: string, path: string, off: boolean): MenuEntry[] {\n const { values, onChange } = ctx.src;\n if (!values || !onChange) return [];\n const stored = values(path);\n const current = leaf.encoding ? leaf.encoding.read(stored, siblingsOf(ctx, path)) : stored;\n if (leaf.readout) {\n const shown = leaf.options.find((o) => o.value === current)?.label ?? '—';\n return [{ kind: 'item', key, label: `${leaf.name}: ${shown}`, disabled: true, run: noop }];\n }\n const write = (v: string) => (leaf.encoding ? leaf.encoding.write(v, siblingsOf(ctx, path)) : v);\n return [\n sep(`${key}/<`),\n ...leaf.options.map((o): MenuEntry => ({\n kind: 'item', key: `${key}/${o.value}`, label: o.label, checked: o.value === current, radio: true,\n disabled: off || o.disabled === true, run: () => onChange(path, write(o.value)),\n })),\n sep(`${key}/>`),\n ];\n}\n\n/** A number row, in the units the leaf shows: its value, bounds, and step convert from the stored unit, and\n * what is set converts back. An infinity is a value only where an `endless` end stands for it. */\nfunction numberRows(ctx: Ctx, given: PrefNumber, key: string, path: string, off: boolean): MenuEntry[] {\n const { values, onChange } = ctx.src;\n if (!values || !onChange) return [];\n const leaf = prefNumberAt(given, values);\n const unit = leaf.unit && resolvePrefUnit(leaf.unit);\n const stored = values(path);\n const { min, max, step, endless } = prefDisplayBounds(leaf);\n const disabled = off || leaf.readout === true;\n return [{\n kind: 'number', key, label: leaf.name, ...withAccess(leaf.access),\n ...(leaf.icon ? { icon: leaf.icon } : {}),\n ...(disabled ? { disabled } : {}),\n value: typeof stored === 'number' && (Number.isFinite(stored) || endlessAllows(leaf.endless, stored))\n ? (unit ? unit.toDisplay(stored) : stored)\n : undefined,\n ...(min === undefined ? {} : { min }),\n ...(max === undefined ? {} : { max }),\n step,\n ...(unit?.suffix === undefined ? {} : { suffix: unit.suffix }),\n ...(leaf.display ? { display: leaf.display } : {}),\n ...(endless ? { endless } : {}),\n ...(leaf.infinity === undefined ? {} : { infinity: leaf.infinity }),\n ...(unit ? { accepts: prefUnitAccepts(unit) } : {}),\n set: (shown) => onChange(path, unit ? unit.fromDisplay(shown) : shown),\n }];\n}\n\nconst textAt = (ctx: Ctx, path: string): string | undefined => {\n const v = ctx.src.values?.(path);\n return typeof v === 'string' && v !== '' ? v : undefined;\n};\n\n/** A color row, which writes the color unless the leaf is a readout or nothing writes it. */\nfunction colorRows(ctx: Ctx, leaf: PrefColor, key: string, path: string, off: boolean): MenuEntry[] {\n const { values, onChange } = ctx.src;\n if (!values) return [];\n return [{\n kind: 'color', key, label: leaf.name, ...withAccess(leaf.access),\n ...(off ? { disabled: true } : {}),\n value: textAt(ctx, path),\n ...(leaf.alpha ? { alpha: true } : {}),\n ...(leaf.readout || !onChange ? {} : { set: (color: string) => onChange(path, color) }),\n }];\n}\n\n/** A string row is edited in place; a readout, or one nothing writes, reads as its name and value, as an enum readout does. */\nfunction stringRows(ctx: Ctx, leaf: PrefString, key: string, path: string, off: boolean): MenuEntry[] {\n const { values, onChange } = ctx.src;\n if (!values) return [];\n if (leaf.readout || !onChange) {\n return [{ kind: 'item', key, label: `${leaf.name}: ${textAt(ctx, path) ?? '—'}`, ...withAccess(leaf.access), disabled: true, run: noop }];\n }\n const stored = values(path);\n return [{\n kind: 'text', key, label: leaf.name, ...withAccess(leaf.access),\n ...(leaf.icon ? { icon: leaf.icon } : {}),\n ...(off ? { disabled: true } : {}),\n value: typeof stored === 'string' ? stored : undefined,\n set: (text) => onChange(path, text),\n }];\n}\n\n/** `key` names the row; `path` is where its value lives, which differs from\n * `key` only for a leaf reached through an alias. */\nfunction leafRows(ctx: Ctx, leaf: PrefLeaf, key: string, path: string, off: boolean): MenuEntry[] {\n switch (leaf.kind) {\n case 'action': return actionRows(ctx, leaf as PrefAction, key, off);\n case 'actions': {\n const group = (leaf as { group: string }).group;\n return ctx.src.actions()\n .filter((a) => a.group === group)\n .flatMap((a) => actionItems(a).map((it) => itemOf(ctx, it, `${key}/${it.key}`, it.label, off)));\n }\n case 'boolean': return booleanRows(ctx, leaf as PrefBoolean, key, path, off);\n case 'enum': return enumRows(ctx, leaf as PrefEnum, key, path, off);\n case 'number': return numberRows(ctx, leaf as PrefNumber, key, path, off);\n case 'color': return colorRows(ctx, leaf as PrefColor, key, path, off);\n case 'string': return stringRows(ctx, leaf as PrefString, key, path, off);\n case 'object': return objectRows(drawIn(ctx), leaf as PrefObject, key, path, off);\n case 'list': return listRows(drawIn(ctx), leaf as PrefList, key, path, off);\n case 'map': return mapRows(drawIn(ctx), leaf as PrefMap, key, path, off);\n case 'union': return unionRows(drawIn(ctx), leaf as PrefUnion, key, path, off);\n case 'field': return fieldRows(drawIn(ctx), leaf as PrefField, key, path, off);\n case 'paint': return paintRows(drawIn(ctx), leaf as PrefPaint, key, path, off);\n case 'separator': return [sep(key)];\n case 'label':\n return [{ kind: 'item', key, label: leaf.name, ...withAccess(leaf.access), disabled: true, run: noop }];\n case 'alias': {\n const alias = leaf as Parameters<typeof prefAliasTarget>[0];\n const target = prefAliasTarget(alias, (p) => prefLeafAt(ctx.src.over ?? ctx.root, p));\n return target ? leafRows(ctx, prefAliasedLeaf(alias, target.leaf), key, target.path, off) : [];\n }\n default: {\n const { values, onChange, customRows } = ctx.src;\n if (isBuiltinPref(leaf) || !customRows || !values) return [];\n return [...customRows(leaf, { key, path, disabled: off, values, ...(onChange ? { onChange } : {}) })];\n }\n }\n}\n\n/** `ctx` reading and writing through `access`, inside the list or map entry at `entry`. */\nfunction through(ctx: Ctx, access: MenuAccess, entry = ctx.entry): Ctx {\n const { values, onChange } = access;\n const { onChange: _outer, ...src } = ctx.src;\n return {\n ...ctx,\n src: { ...src, values, ...(onChange ? { onChange } : {}) },\n entry,\n read: (p, from) => (from === 'item' ? (entry === undefined ? undefined : values(`${entry}.${p}`)) : values(p)),\n };\n}\n\n/** What a compound leaf drawn in `ctx` draws its parts with. */\nfunction drawIn(ctx: Ctx): MenuDraw {\n const { values, onChange } = ctx.src;\n return {\n root: ctx.src.over ?? ctx.root,\n access: { values: values!, ...(onChange ? { onChange } : {}) },\n leaf: (leaf, key, access, off, entry) => leafRows(through(ctx, access, entry), leaf, key, key, off),\n fields: (fields, prefix, access, off) => {\n const scope = { ...PREF_SCOPE, enabled: !off };\n const inner = through(ctx, access);\n return tidy(groupRows(inner, fields, prefix, { node: {}, scope, above: scope, ...(inner.entry ? { entry: inner.entry } : {}) }));\n },\n };\n}\n\nconst ROOT: PrefOwner = { node: {}, scope: PREF_SCOPE, above: PREF_SCOPE };\n\nfunction groupRows(ctx: Ctx, children: Children, prefix: string, owner: PrefOwner): MenuEntry[] {\n const { read } = ctx;\n const holds: PrefConditionJudge = (condition) => read === undefined || prefConditionHolds(condition, read);\n const out: MenuEntry[] = [];\n for (const [k, node] of Object.entries(children)) {\n const key = prefix ? `${prefix}.${k}` : k;\n // A section's key names its rows but adds nothing to their paths.\n const path = !isPrefLeaf(node) && isPrefSection(node) ? prefix : key;\n const sits = isPrefLeaf(node) ? prefScopeIn(owner, path, holds) : owner.scope;\n const scope = prefScopeUnder(sits, node, holds);\n if (!scope.shown) continue;\n const disabled = !scope.enabled;\n const inner: PrefOwner = { node, scope, above: sits, ...(owner.entry ? { entry: owner.entry } : {}) };\n if (isPrefLeaf(node)) {\n out.push(...leafRows(ctx, node, path, path, disabled));\n continue;\n }\n const kids: Children = isPrefSection(node) ? node.members : node.children;\n if (SUBMENU_AS.has(node.as)) {\n const entries = tidy(groupRows(ctx, kids, path, inner));\n if (entries.length) {\n out.push({ kind: 'submenu', key, label: node.name, ...(node.icon ? { icon: node.icon } : {}), ...withAccess(node.access), entries });\n }\n } else {\n out.push(sep(`${key}/<`), ...groupRows(ctx, kids, path, inner), sep(`${key}/>`));\n }\n }\n return out;\n}\n\n/** Drop leading, trailing, and doubled separators. */\nfunction tidy(entries: MenuEntry[]): MenuEntry[] {\n const out: MenuEntry[] = [];\n for (const e of entries) {\n if (e.kind === 'separator' && (!out.length || out[out.length - 1]!.kind === 'separator')) continue;\n out.push(e);\n }\n if (out[out.length - 1]?.kind === 'separator') out.pop();\n return out;\n}\n\n/**\n * Draw a prefs schema as menu entries. Action leaves become items from the\n * registry (one per variant for a parametric action), an `actions` leaf one\n * item per action in its group, a boolean a checked item, an enum radio\n * rows, and a number, a string and a color a row edited in place (all through `src.values`/`src.onChange`);\n * a color shows read-only, and a string as a disabled row, when it is a readout\n * or nothing writes it. A group drawn `as` a\n * `menu`, `page`, `tab`, or `panel` is a submenu, and any other group's rows\n * sit inline between separators, and so does a section, whose key adds nothing to its rows' paths. An object, a\n * list, a map, a union, and a field reference are each a submenu (see `compoundRows`), and a paint a color row while\n * it is solid or none; an app-defined leaf is drawn by `src.customRows`, and left out without it.\n * `at` is the world point the menu was opened at and reaches `enabled` and\n * every action's params; `params` go to every action, under its own.\n */\nexport function resolveSchemaMenu(\n schema: PrefGroup,\n src: MenuSources,\n at?: Point,\n params?: Record<string, unknown>,\n): MenuEntry[] {\n const values = src.values;\n const ctx: Ctx = {\n src,\n byId: new Map(src.actions().map((a) => [a.id, a])),\n root: schema,\n read: values ? (path, from) => (from === 'item' ? undefined : values(path)) : undefined,\n at,\n params,\n };\n return tidy(groupRows(ctx, schema.children, '', ROOT));\n}\n\n/** Turn a declared menu into model entries; see {@link resolveSchemaMenu}. */\nexport function resolveMenu(\n def: MenuDef,\n src: MenuSources,\n at?: Point,\n params?: Record<string, unknown>,\n): MenuEntry[] {\n return resolveSchemaMenu(def.menu, src, at, params);\n}\n","import type { MenuEntry, MenuSide, Rect } from '@weasel-js/menu';\nimport { mergeMenuDefs, pickMenu } from './pickMenu';\nimport { resolveMenu, type MenuSources } from './resolveMenu';\nimport type { MenuDef, MenuHit, OwnedMenuDef } from './types';\nimport type { Point } from '@weasel-js/geom';\n\n/** Ask to open a menu: by id (chrome) or by what was hit (canvas). */\nexport interface MenuOpenRequest {\n menu?: string;\n hit?: MenuHit;\n /** Viewport point the menu is placed at, unless `under` is set. */\n client: Point;\n /** Viewport rect of the button the menu hangs from: placed below it, or above when below does not fit. */\n under?: Rect;\n /** With `under`: the side of the button it opens on when it fits there, flipping to the opposite side when it does not.\n * Default below. The canvas HUD menu host places below only and ignores it. */\n side?: MenuSide;\n /** World point, passed to `enabled` and to every item. */\n world?: Point;\n params?: Record<string, unknown>;\n source?: 'pointer' | 'keyboard';\n}\n\n/** The menu on screen. `seq` changes on every open, so a renderer remounts. */\nexport interface OpenMenu {\n seq: number;\n entries: readonly MenuEntry[];\n client: Point;\n under?: Rect;\n /** `MenuOpenRequest.side`, carried to the renderer. */\n side?: MenuSide;\n world?: Point;\n source: 'pointer' | 'keyboard';\n}\n\n/** Holds the declared menus and the one open menu. */\nexport interface MenuHost {\n /** Declare a menu; `owner` is a tool id, or `null` for always. Returns a release. */\n define(def: MenuDef, owner?: string | null): () => void;\n /** Pick, resolve and show. False when nothing matched or nothing resolved. */\n open(req: MenuOpenRequest): boolean;\n /** Whether `open(req)` would show anything. Changes no state and notifies no one. */\n has(req: MenuOpenRequest): boolean;\n close(): void;\n current(): OpenMenu | null;\n subscribe(fn: () => void): () => void;\n}\n\n/** Creates the host that decides which context menu is open, from the menus registered to it. */\nexport function createMenuHost(src: MenuSources & { activeTool(): string | null }): MenuHost {\n const defs: OwnedMenuDef[] = [];\n const listeners = new Set<() => void>();\n let open: OpenMenu | null = null;\n let seq = 0;\n const emit = () => { for (const fn of listeners) fn(); };\n\n const close = () => {\n if (!open) return;\n open = null;\n emit();\n };\n\n const resolve = (req: MenuOpenRequest): readonly MenuEntry[] => {\n const live = mergeMenuDefs(defs, src.activeTool());\n const def = req.menu !== undefined\n ? live.find((d) => d.id === req.menu)\n : req.hit ? pickMenu(live, req.hit) : undefined;\n return def ? resolveMenu(def, src, req.world, req.params) : [];\n };\n\n return {\n define(def, owner = null) {\n const entry = { def, owner };\n defs.push(entry);\n return () => {\n const i = defs.indexOf(entry);\n if (i >= 0) defs.splice(i, 1);\n };\n },\n open(req) {\n const entries = resolve(req);\n if (!entries.length) {\n close();\n return false;\n }\n open = {\n seq: ++seq, entries, client: req.client, world: req.world,\n ...(req.under ? { under: req.under } : {}),\n ...(req.side ? { side: req.side } : {}),\n source: req.source ?? 'pointer',\n };\n emit();\n return true;\n },\n has: (req) => resolve(req).length > 0,\n close,\n current: () => open,\n subscribe(fn) {\n listeners.add(fn);\n return () => { listeners.delete(fn); };\n },\n };\n}\n"]}