@pixerate/editor 0.21.0 → 0.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. package/README.md +100 -13
  2. package/THIRD_PARTY_NOTICES.md +88 -0
  3. package/dist/agent/index.cjs +86 -111
  4. package/dist/agent/index.cjs.map +1 -1
  5. package/dist/agent/index.d.cts +69 -211
  6. package/dist/agent/index.d.ts +69 -211
  7. package/dist/agent/index.js +77 -102
  8. package/dist/agent/index.js.map +1 -1
  9. package/dist/arrangeShortcuts-B8O3f8-P.d.cts +184 -0
  10. package/dist/arrangeShortcuts-sLlD2rSX.d.ts +184 -0
  11. package/dist/canvas/index.cjs +2112 -60
  12. package/dist/canvas/index.cjs.map +1 -1
  13. package/dist/canvas/index.d.cts +712 -181
  14. package/dist/canvas/index.d.ts +712 -181
  15. package/dist/canvas/index.js +2105 -53
  16. package/dist/canvas/index.js.map +1 -1
  17. package/dist/chunk-26BVFKHU.cjs +453 -0
  18. package/dist/chunk-26BVFKHU.cjs.map +1 -0
  19. package/dist/chunk-2H7ZHPEJ.js +762 -0
  20. package/dist/chunk-2H7ZHPEJ.js.map +1 -0
  21. package/dist/chunk-7DWMJCAT.js +453 -0
  22. package/dist/chunk-7DWMJCAT.js.map +1 -0
  23. package/dist/{chunk-TVRC4KVT.cjs → chunk-AA4ZEVCC.cjs} +845 -90
  24. package/dist/chunk-AA4ZEVCC.cjs.map +1 -0
  25. package/dist/chunk-ARRTP33I.js +101 -0
  26. package/dist/chunk-ARRTP33I.js.map +1 -0
  27. package/dist/{chunk-LA7PEGU3.cjs → chunk-CL37JGFW.cjs} +4 -4
  28. package/dist/{chunk-LA7PEGU3.cjs.map → chunk-CL37JGFW.cjs.map} +1 -1
  29. package/dist/chunk-CPOKFNBG.cjs +101 -0
  30. package/dist/chunk-CPOKFNBG.cjs.map +1 -0
  31. package/dist/chunk-G2I4QJOT.cjs +762 -0
  32. package/dist/chunk-G2I4QJOT.cjs.map +1 -0
  33. package/dist/{chunk-4QPLEUL2.cjs → chunk-GVSMRPHB.cjs} +1046 -54
  34. package/dist/chunk-GVSMRPHB.cjs.map +1 -0
  35. package/dist/{chunk-KYRZDWM4.js → chunk-JJDLPEWL.js} +2 -2
  36. package/dist/{chunk-GVW4P7BG.js → chunk-K3R5NG2D.js} +448 -54
  37. package/dist/chunk-K3R5NG2D.js.map +1 -0
  38. package/dist/{chunk-3TYMNULT.js → chunk-MJZBNWG7.js} +807 -52
  39. package/dist/chunk-MJZBNWG7.js.map +1 -0
  40. package/dist/{chunk-A7DKIA72.js → chunk-QBJ22YZR.js} +1059 -93
  41. package/dist/chunk-QBJ22YZR.js.map +1 -0
  42. package/dist/{chunk-CYFJCKC4.js → chunk-QGHGJ56O.js} +997 -5
  43. package/dist/chunk-QGHGJ56O.js.map +1 -0
  44. package/dist/{chunk-JYRIOFEN.cjs → chunk-RIKBJLS2.cjs} +1064 -98
  45. package/dist/chunk-RIKBJLS2.cjs.map +1 -0
  46. package/dist/{chunk-U6NDQFOK.cjs → chunk-XDMXXC4Z.cjs} +569 -175
  47. package/dist/chunk-XDMXXC4Z.cjs.map +1 -0
  48. package/dist/commands/index.cjs +860 -0
  49. package/dist/commands/index.cjs.map +1 -0
  50. package/dist/commands/index.d.cts +592 -0
  51. package/dist/commands/index.d.ts +592 -0
  52. package/dist/commands/index.js +860 -0
  53. package/dist/commands/index.js.map +1 -0
  54. package/dist/{controller-OUdxPY-X.d.ts → controller-pePCJLT1.d.cts} +216 -11
  55. package/dist/{controller-OUdxPY-X.d.cts → controller-pePCJLT1.d.ts} +216 -11
  56. package/dist/extensions/index.cjs +14 -4
  57. package/dist/extensions/index.cjs.map +1 -1
  58. package/dist/extensions/index.d.cts +3 -3
  59. package/dist/extensions/index.d.ts +3 -3
  60. package/dist/extensions/index.js +13 -3
  61. package/dist/history/index.cjs +12 -2
  62. package/dist/history/index.cjs.map +1 -1
  63. package/dist/history/index.d.cts +211 -7
  64. package/dist/history/index.d.ts +211 -7
  65. package/dist/history/index.js +13 -3
  66. package/dist/image-editor/index.cjs +418 -13
  67. package/dist/image-editor/index.cjs.map +1 -1
  68. package/dist/image-editor/index.d.cts +154 -3
  69. package/dist/image-editor/index.d.ts +154 -3
  70. package/dist/image-editor/index.js +417 -12
  71. package/dist/image-editor/index.js.map +1 -1
  72. package/dist/{index-k3mFbPx_.d.cts → index-CCr_z9kF.d.cts} +3 -3
  73. package/dist/{index-Ng1pG7JE.d.ts → index-Ck6ajwXh.d.ts} +3 -3
  74. package/dist/index.cjs +275 -83
  75. package/dist/index.cjs.map +1 -1
  76. package/dist/index.d.cts +296 -47
  77. package/dist/index.d.ts +296 -47
  78. package/dist/index.js +266 -74
  79. package/dist/index.js.map +1 -1
  80. package/dist/registry-D5-R90p0.d.cts +209 -0
  81. package/dist/registry-D5-R90p0.d.ts +209 -0
  82. package/dist/{registry-iAHbqkYt.d.cts → registry-GJI4gToU.d.cts} +15 -4
  83. package/dist/{registry-iAHbqkYt.d.ts → registry-GJI4gToU.d.ts} +15 -4
  84. package/dist/serializers/index.cjs +3 -3
  85. package/dist/serializers/index.d.cts +1 -1
  86. package/dist/serializers/index.d.ts +1 -1
  87. package/dist/serializers/index.js +2 -2
  88. package/dist/spreadsheet/index.cjs +23 -3
  89. package/dist/spreadsheet/index.cjs.map +1 -1
  90. package/dist/spreadsheet/index.d.cts +97 -10
  91. package/dist/spreadsheet/index.d.ts +97 -10
  92. package/dist/spreadsheet/index.js +22 -2
  93. package/dist/{track-changes-G8JcWB8b.d.cts → track-changes-BSF58RK0.d.cts} +92 -9
  94. package/dist/{track-changes-G8JcWB8b.d.ts → track-changes-BSF58RK0.d.ts} +92 -9
  95. package/dist/{types-DMe0vFB1.d.cts → types-DX4Mh4SL.d.cts} +1 -1
  96. package/dist/{types-DMe0vFB1.d.ts → types-DX4Mh4SL.d.ts} +1 -1
  97. package/dist/types-GT5a5YAX.d.cts +86 -0
  98. package/dist/types-GT5a5YAX.d.ts +86 -0
  99. package/package.json +8 -2
  100. package/dist/chunk-2TWGLC5K.cjs +0 -262
  101. package/dist/chunk-2TWGLC5K.cjs.map +0 -1
  102. package/dist/chunk-3TYMNULT.js.map +0 -1
  103. package/dist/chunk-4QPLEUL2.cjs.map +0 -1
  104. package/dist/chunk-A7DKIA72.js.map +0 -1
  105. package/dist/chunk-CYFJCKC4.js.map +0 -1
  106. package/dist/chunk-GVW4P7BG.js.map +0 -1
  107. package/dist/chunk-JYRIOFEN.cjs.map +0 -1
  108. package/dist/chunk-KAADNAPF.js +0 -262
  109. package/dist/chunk-KAADNAPF.js.map +0 -1
  110. package/dist/chunk-TVRC4KVT.cjs.map +0 -1
  111. package/dist/chunk-U6NDQFOK.cjs.map +0 -1
  112. package/dist/types-BZgcDsC5.d.cts +0 -42
  113. package/dist/types-BZgcDsC5.d.ts +0 -42
  114. /package/dist/{chunk-KYRZDWM4.js.map → chunk-JJDLPEWL.js.map} +0 -0
@@ -0,0 +1,592 @@
1
+ import { J as JsonSchema, S as SchemaValidationError, A as AgentToolProvider } from '../registry-D5-R90p0.js';
2
+ import { H as HistoryState } from '../types-GT5a5YAX.js';
3
+ import { C as CanvasArrangeAction, A as AlignEdge, D as DistributeAxis, a as DistributeMode, Z as ZOrderOperation } from '../arrangeShortcuts-sLlD2rSX.js';
4
+ import '../types-DX4Mh4SL.js';
5
+
6
+ /**
7
+ * Keyboard chords in a platform-neutral notation.
8
+ *
9
+ * | token | macOS | Windows / Linux |
10
+ * |---|---|---|
11
+ * | `Mod` | ⌘ Command | Ctrl |
12
+ * | `Ctrl` | ⌃ Control | Ctrl (same key as `Mod`: conflicts are reported) |
13
+ * | `Meta` / `Cmd` | ⌘ Command | Win / Super |
14
+ * | `Alt` / `Option` | ⌥ Option | Alt |
15
+ * | `Shift` | ⇧ Shift | Shift |
16
+ *
17
+ * Keys are stored as `KeyboardEvent.code` values (`KeyZ`, `Digit1`, `BracketRight`,
18
+ * `PageDown`), so Option/Alt chords work on macOS (where Option changes `event.key`).
19
+ */
20
+ type Platform = 'mac' | 'windows' | 'linux';
21
+ declare const PLATFORMS: readonly Platform[];
22
+ /** A parsed chord. `mod` is the platform's primary modifier. */
23
+ interface Chord {
24
+ /** `KeyboardEvent.code` of the key, e.g. `KeyZ`. */
25
+ key: string;
26
+ mod?: boolean;
27
+ ctrl?: boolean;
28
+ meta?: boolean;
29
+ alt?: boolean;
30
+ shift?: boolean;
31
+ }
32
+ /** The modifiers a chord needs on one platform (`mod` resolved to `meta` or `ctrl`). */
33
+ interface EffectiveChord {
34
+ key: string;
35
+ ctrl: boolean;
36
+ meta: boolean;
37
+ alt: boolean;
38
+ shift: boolean;
39
+ }
40
+ /** The current platform from `navigator` (`linux` when unknown, e.g. in Node). */
41
+ declare function detectPlatform(): Platform;
42
+ /** `KeyboardEvent.code` for a key token (`Z`, `1`, `]`, `PageDown`, `F5`, `KeyZ`), or `null`. */
43
+ declare function keyToCode(token: string): string | null;
44
+ /** Neutral text for a code: `KeyZ` → `Z`, `BracketRight` → `]`, `ArrowUp` → `Up`. */
45
+ declare function codeToKeyText(code: string): string;
46
+ /**
47
+ * Parses chord text (`Mod+Shift+Z`, `Alt+]`, `⌥⇧⌘K`, `CmdOrCtrl+K`). Throws on unknown
48
+ * modifiers or keys. The last `+`-separated token is the key (`+` itself is `Plus`).
49
+ */
50
+ declare function parseChord(text: string): Chord;
51
+ /** Canonical platform-neutral text: `Mod+Ctrl+Meta+Alt+Shift+<key>`. */
52
+ declare function chordToString(chord: Chord): string;
53
+ /** Canonical spelling of chord text (`shift+cmdorctrl+z` → `Mod+Shift+Z`). Throws when invalid. */
54
+ declare function normalizeChord(text: string): string;
55
+ /** The modifiers a chord needs on `platform`: `Mod` is ⌘ (meta) on macOS and Ctrl elsewhere. */
56
+ declare function effectiveChord(chord: string | Chord, platform: Platform): EffectiveChord;
57
+ /** Identity of an effective chord, for conflict detection (`Ctrl+Shift+KeyZ`). */
58
+ declare function effectiveChordKey(chord: string | Chord, platform: Platform): string;
59
+ /**
60
+ * Display text: `⌥⇧⌘K` on macOS, `Ctrl+Alt+Shift+K` on Windows / Linux (`Meta` shows as
61
+ * `Win` / `Super`). Invalid text is returned unchanged.
62
+ */
63
+ declare function formatShortcut(chord: string | Chord, platform?: Platform): string;
64
+ /** Minimal keyboard event surface (DOM `KeyboardEvent` satisfies it). */
65
+ interface KeyboardEventLike {
66
+ key?: string;
67
+ code?: string;
68
+ ctrlKey?: boolean;
69
+ metaKey?: boolean;
70
+ altKey?: boolean;
71
+ shiftKey?: boolean;
72
+ target?: EventTarget | null | unknown;
73
+ defaultPrevented?: boolean;
74
+ preventDefault?: () => void;
75
+ }
76
+ /** `event.code`, or one derived from `event.key` for synthetic events without a code. */
77
+ declare function eventCode(event: KeyboardEventLike): string;
78
+ /**
79
+ * The key code a shortcut event is matched by: `event.code` (layout-independent, so
80
+ * Option/Alt chords work on macOS and punctuation chords follow the physical key),
81
+ * except that a letter key producing a different Latin letter without Alt (AZERTY,
82
+ * QWERTZ, Dvorak) uses the produced letter, as browsers and operating systems do.
83
+ */
84
+ declare function shortcutCode(event: KeyboardEventLike): string;
85
+ /** The code a printable `event.key` names on a US layout (`z` → `KeyZ`, `]` → `BracketRight`). */
86
+ declare function codeFromKey(key: string): string | null;
87
+ /**
88
+ * Whether a keyboard event comes from a text-entry element: `<input>`, `<textarea>`,
89
+ * `<select>`, a `contenteditable` element (or a descendant) or a ProseMirror editor.
90
+ * Falls back to `document.activeElement` when the event has no element target.
91
+ */
92
+ declare function isEditableEventTarget(event: {
93
+ target?: unknown;
94
+ }): boolean;
95
+
96
+ /** One key binding: a chord that runs `command`, optionally only in one scope / on some platforms. */
97
+ interface ShortcutBinding {
98
+ command: string;
99
+ /** Chord text (`Mod+Shift+Z`) or a parsed chord. */
100
+ chord: string | Chord;
101
+ /** Scope (e.g. `canvas`, `spreadsheet`); scoped bindings win over global ones. Omit for global. */
102
+ scope?: string;
103
+ /** Platforms the binding exists on (default: all). E.g. `Mod+Y` redo only off macOS. */
104
+ platforms?: readonly Platform[];
105
+ /** Also fire while focus is in an input, textarea or contenteditable (default `false`). */
106
+ allowInEditable?: boolean;
107
+ }
108
+ /** Shortcut declaration on a command: chord text, or an object for platform / scope specifics. */
109
+ type ShortcutInput = string | Omit<ShortcutBinding, 'command'> | ReadonlyArray<string | Omit<ShortcutBinding, 'command'>>;
110
+ /** Expands a command's `shortcut` declaration into bindings. */
111
+ declare function toShortcutBindings(command: string, input: ShortcutInput | undefined, scope?: string): ShortcutBinding[];
112
+ interface ShortcutConflict {
113
+ /** Scope shared by the bindings (`undefined` = global). */
114
+ scope?: string;
115
+ /** Effective chord, e.g. `Ctrl+KeyZ`. */
116
+ chord: string;
117
+ /** Commands bound to it (two or more). */
118
+ commands: string[];
119
+ }
120
+ interface ShortcutMatch {
121
+ command: string;
122
+ binding: ShortcutBinding;
123
+ }
124
+ interface ShortcutResolveOptions {
125
+ /** Active scopes, most specific first. Bindings in these scopes win over global ones. */
126
+ scopes?: string | readonly string[];
127
+ /** Resolve even when the event comes from a text input (default: per binding). */
128
+ allowInEditable?: boolean;
129
+ /** Override the map's platform. */
130
+ platform?: Platform;
131
+ }
132
+ interface ShortcutMapOptions {
133
+ /** Platform used to resolve `Mod` (default: detected from `navigator` on every resolve). */
134
+ platform?: Platform;
135
+ /**
136
+ * `platform` (default): `Mod` means ⌘ on macOS and Ctrl elsewhere, exactly.
137
+ * `either`: `Mod` (and `Ctrl` / `Meta`) match ⌘ or Ctrl on every platform.
138
+ */
139
+ modifierMode?: 'platform' | 'either';
140
+ }
141
+ /**
142
+ * Keyboard shortcuts as data: default bindings plus user overrides, resolved from
143
+ * `KeyboardEvent`s by `event.code` (so Option/Alt chords work on macOS), with scopes
144
+ * (scoped bindings win), conflict detection per platform and display formatting.
145
+ */
146
+ declare class ShortcutMap {
147
+ private defaults;
148
+ private overrides;
149
+ private readonly listeners;
150
+ private readonly options;
151
+ constructor(bindings?: readonly ShortcutBinding[], options?: ShortcutMapOptions);
152
+ get platform(): Platform;
153
+ private entry;
154
+ private changed;
155
+ /** Subscribes to binding changes. Returns an unsubscribe function. */
156
+ subscribe(listener: () => void): () => void;
157
+ /** Adds default bindings (throws on invalid chord text). Returns a function removing them. */
158
+ bind(bindings: ShortcutBinding | readonly ShortcutBinding[]): () => void;
159
+ /**
160
+ * User override for a command: replaces all of its default bindings with `chords`
161
+ * (an empty list unbinds it). Throws on invalid chord text.
162
+ */
163
+ setOverride(command: string, chords: string | Chord | ReadonlyArray<string | Chord | Omit<ShortcutBinding, 'command'>>): void;
164
+ /** Removes a user override (the defaults apply again). */
165
+ clearOverride(command: string): void;
166
+ /** User overrides as plain data (`{ command: ['Mod+K'] }`), e.g. to persist them. */
167
+ getOverrides(): Record<string, string[]>;
168
+ /** Restores overrides saved with `getOverrides` (replacing the current ones). */
169
+ setOverrides(overrides: Record<string, readonly string[]>): void;
170
+ private active;
171
+ /** Effective bindings on `platform` (defaults without overridden commands, plus overrides). */
172
+ bindings(platform?: Platform): ShortcutBinding[];
173
+ /** Canonical chord text bound to `command` on `platform` (first = primary). */
174
+ forCommand(command: string, platform?: Platform): string[];
175
+ /**
176
+ * The command a keydown event runs, or `null`. Events from text inputs are ignored
177
+ * unless the binding (or `options`) allows them. Bindings in the active scopes
178
+ * (in order) win over global bindings; bindings in other scopes never match.
179
+ * Keys are matched by `event.code`, except that a letter key producing another Latin
180
+ * letter (AZERTY, QWERTZ, Dvorak) matches that letter when Alt is not held, so
181
+ * `Mod+Z` follows the Z label (see `shortcutCode`).
182
+ */
183
+ resolve(event: KeyboardEventLike, options?: ShortcutResolveOptions): ShortcutMatch | null;
184
+ private matches;
185
+ /**
186
+ * Groups of bindings that share an effective chord in one scope on `platform`
187
+ * (e.g. `Mod+Y` and `Ctrl+Y` collide off macOS). A scoped binding shadowing a
188
+ * global one is not a conflict.
189
+ */
190
+ findConflicts(platform?: Platform): ShortcutConflict[];
191
+ /** Conflicts on every platform, keyed by platform (only platforms with conflicts). */
192
+ findAllConflicts(): Partial<Record<Platform, ShortcutConflict[]>>;
193
+ }
194
+
195
+ /** Object JSON Schema describing a command's parameters. */
196
+ type CommandParamsSchema = JsonSchema & {
197
+ type: 'object';
198
+ };
199
+ /**
200
+ * Metadata and implementation of one command. Menus, shortcuts, the palette and agent
201
+ * tools all run commands by id, so every entry point shares enablement and validation.
202
+ */
203
+ interface CommandSpec<TContext = any, TParams = any, TResult = unknown> {
204
+ /** Unique id, e.g. `history.undo` or `canvas.alignLeft`. */
205
+ id: string;
206
+ label: string;
207
+ /** Group / menu name shown next to the label, e.g. `Edit` or `Arrange`. */
208
+ group?: string;
209
+ /** Extra search terms for the palette. */
210
+ keywords?: readonly string[];
211
+ description?: string;
212
+ /** Object JSON Schema for `params`. Unknown keys are rejected unless `additionalProperties` allows them. */
213
+ params?: CommandParamsSchema;
214
+ /** Default shortcut(s): platform-neutral chord text such as `Mod+Shift+Z`. */
215
+ shortcut?: ShortcutInput;
216
+ /** Scope the command (and its shortcuts) belong to, e.g. `canvas`. Omit for global commands. */
217
+ scope?: string;
218
+ /**
219
+ * Whether the command can run: `true` (or `undefined`), `false`, or a reason string
220
+ * ("Nothing to undo"). Receives the params a caller named, so a command acting on the
221
+ * selection can still run on targets passed explicitly (`params` is `undefined` for menus).
222
+ */
223
+ enabled?: (context: TContext, params: TParams | undefined) => boolean | string | undefined;
224
+ run: (context: TContext, params: TParams) => TResult;
225
+ /**
226
+ * Runs inside the registry's `history.batch(label, …)`, so all history entries the
227
+ * command records become one undo step and a throw rolls back its partial changes.
228
+ */
229
+ undoable?: boolean;
230
+ /** The command only reads state (agent tools mark it read-only). */
231
+ readOnly?: boolean;
232
+ /** Hide from the palette and `list()` unless `includeHidden` (still runnable by id). */
233
+ hidden?: boolean;
234
+ }
235
+ type CommandErrorCode = 'unknown_command' | 'disabled' | 'invalid_params' | 'failed';
236
+ type CommandResult<T = unknown> = {
237
+ ok: true;
238
+ id: string;
239
+ result: T;
240
+ } | {
241
+ ok: false;
242
+ id: string;
243
+ code: CommandErrorCode;
244
+ message: string;
245
+ details?: SchemaValidationError[];
246
+ };
247
+ /** A command as listed for menus, palettes and agents. */
248
+ interface CommandEntry {
249
+ id: string;
250
+ label: string;
251
+ group?: string;
252
+ keywords?: readonly string[];
253
+ description?: string;
254
+ params?: CommandParamsSchema;
255
+ scope?: string;
256
+ /** Canonical chord text bound on the registry's platform (first = primary). */
257
+ shortcuts: string[];
258
+ enabled: boolean;
259
+ /** Why the command is disabled (only when `enabled` is false). */
260
+ disabledReason?: string;
261
+ undoable: boolean;
262
+ readOnly: boolean;
263
+ }
264
+ interface CommandListOptions<TContext = any> {
265
+ /** Only global commands plus commands of these scopes. */
266
+ scope?: string | readonly string[];
267
+ enabledOnly?: boolean;
268
+ includeHidden?: boolean;
269
+ /** Context for the enablement check (default: the registry's context). */
270
+ context?: TContext;
271
+ }
272
+ /** Minimal history surface (`HistoryManager` satisfies it). */
273
+ interface CommandHistoryTarget {
274
+ batch(name: string, fn: () => void): void;
275
+ }
276
+ interface CommandRegistryOptions<TContext = any> {
277
+ /** Default context passed to `enabled` / `run` (a value or a getter). */
278
+ context?: TContext | (() => TContext);
279
+ /** Wraps `undoable` commands in one history step (see `CommandSpec.undoable`). */
280
+ history?: CommandHistoryTarget;
281
+ /** Options for the registry's `ShortcutMap`. */
282
+ shortcuts?: ShortcutMapOptions;
283
+ }
284
+ declare class CommandRegistryError extends Error {
285
+ readonly code: 'duplicate_command' | 'invalid_command';
286
+ constructor(code: CommandRegistryError['code'], message: string);
287
+ }
288
+ /**
289
+ * Registry of commands: one id per action, shared by shortcuts (`shortcuts`), the
290
+ * command palette (`list` + `rankCommands`) and agent tools (`createCommandToolProvider`).
291
+ */
292
+ declare class CommandRegistry<TContext = any> {
293
+ /** Shortcut bindings of the registered commands (plus any user overrides). */
294
+ readonly shortcuts: ShortcutMap;
295
+ private readonly commands;
296
+ private readonly listeners;
297
+ private readonly options;
298
+ private version;
299
+ private muted;
300
+ constructor(options?: CommandRegistryOptions<TContext>);
301
+ /** Monotonic counter bumped on every change (useful as a snapshot key). */
302
+ getVersion(): number;
303
+ /** The default context. */
304
+ get context(): TContext;
305
+ /**
306
+ * Registers a command (or several) and returns a function that unregisters it.
307
+ * Throws a `CommandRegistryError` for a duplicate or invalid id, or invalid chord text.
308
+ */
309
+ register(spec: CommandSpec<TContext> | readonly CommandSpec<TContext>[]): () => void;
310
+ /** Removes a command by id. Returns whether it was registered. */
311
+ unregister(id: string): boolean;
312
+ private unbindQuietly;
313
+ has(id: string): boolean;
314
+ get(id: string): CommandSpec<TContext> | undefined;
315
+ /** Registered ids in registration order. */
316
+ ids(): string[];
317
+ /** Whether `id` can run now (`{ enabled, reason }`); `params` are the targets a caller named. */
318
+ isEnabled(id: string, params?: unknown, context?: TContext): {
319
+ enabled: boolean;
320
+ reason?: string;
321
+ };
322
+ /** Commands for menus, palettes and agents, with their current enablement. */
323
+ list(options?: CommandListOptions<TContext>): CommandEntry[];
324
+ private check;
325
+ private invoke;
326
+ /**
327
+ * Runs a command synchronously and returns a structured result; never throws.
328
+ * A command whose `run` returns a promise yields `{ ok: true, result: promise }`
329
+ * (use `executeAsync` to await it and catch its rejection).
330
+ */
331
+ execute<T = unknown>(id: string, params?: unknown, context?: TContext): CommandResult<T>;
332
+ /** Like `execute`, but awaits async commands (rejections become `failed` results). */
333
+ executeAsync<T = unknown>(id: string, params?: unknown, context?: TContext): Promise<CommandResult<T>>;
334
+ /**
335
+ * Resolves a keydown event to a command (see `ShortcutMap.resolve`) and runs it when
336
+ * enabled, calling `preventDefault()`. Disabled commands leave the event alone, so the
337
+ * browser or a focused editor can still handle it. Returns the result, or `null`.
338
+ */
339
+ handleKeyDown(event: KeyboardEventLike, options?: ShortcutResolveOptions & {
340
+ context?: TContext;
341
+ }): CommandResult | null;
342
+ /** Display-ready primary shortcut of a command (`⇧⌘Z` / `Ctrl+Shift+Z`), or `undefined`. */
343
+ shortcutFor(id: string, platform?: Platform): string | undefined;
344
+ /**
345
+ * Subscribes to changes: commands registered or removed, shortcut overrides, executed
346
+ * commands and `invalidate()` calls (e.g. when enablement inputs change).
347
+ */
348
+ subscribe(listener: () => void): () => void;
349
+ /** Tells subscribers that enablement may have changed (e.g. the selection changed). */
350
+ invalidate(): void;
351
+ private notify;
352
+ }
353
+ declare function createCommandRegistry<TContext = any>(options?: CommandRegistryOptions<TContext>): CommandRegistry<TContext>;
354
+ /** Identity helper that types a command spec. */
355
+ declare function defineCommand<TContext = any, TParams = any, TResult = unknown>(spec: CommandSpec<TContext, TParams, TResult>): CommandSpec<TContext, TParams, TResult>;
356
+
357
+ /** The fields `rankCommands` searches (a `CommandEntry` satisfies it). */
358
+ interface RankableCommand {
359
+ id: string;
360
+ label: string;
361
+ group?: string;
362
+ keywords?: readonly string[];
363
+ enabled?: boolean;
364
+ }
365
+ interface FuzzyMatch {
366
+ score: number;
367
+ /** Indices of the matched characters in the text (for highlighting). */
368
+ indices: number[];
369
+ }
370
+ /**
371
+ * Subsequence fuzzy match: every query character must appear in order. Consecutive
372
+ * matches score 8, others 1; a match at a word start adds 5; longer texts lose
373
+ * `length / 8`. Case-insensitive. Returns `null` when the query does not match.
374
+ */
375
+ declare function fuzzyMatch(query: string, text: string): FuzzyMatch | null;
376
+ /** `fuzzyMatch(query, text)?.score ?? null`. */
377
+ declare function fuzzyScore(query: string, text: string): number | null;
378
+ /**
379
+ * Bonus that puts a command whose name is exactly the query ahead of every fuzzy match
380
+ * ("undo" finds Undo before "Undo Selection Change"). Trailing ellipses are ignored.
381
+ */
382
+ declare function exactBonus(query: string, names: readonly string[]): number;
383
+ /** Default number of recently run commands a palette remembers. */
384
+ declare const DEFAULT_RECENT_LIMIT = 8;
385
+ /** Moves `id` to the front of `list` (deduplicated, newest first, at most `cap`). Returns a new array. */
386
+ declare function pushRecent(list: readonly string[], id: string, cap?: number): string[];
387
+ interface RankedCommand<T extends RankableCommand = RankableCommand> {
388
+ entry: T;
389
+ score: number;
390
+ /** Matched character indices in `entry.label` (empty when another field matched). */
391
+ labelIndices: number[];
392
+ /** The entry was shown because it was run recently (empty query). */
393
+ recent: boolean;
394
+ }
395
+ interface RankCommandsOptions {
396
+ /** Recently run ids, newest first. Shown first for an empty query and boosted slightly otherwise. */
397
+ recents?: readonly string[];
398
+ /** Maximum number of recents shown for an empty query (default 8). */
399
+ recentLimit?: number;
400
+ /** Maximum number of results. */
401
+ limit?: number;
402
+ /** Sort disabled commands after enabled ones (default `true`). */
403
+ disabledLast?: boolean;
404
+ /** With an empty query: `all` (default) lists recents then every other command; `recents` lists only recents. */
405
+ emptyQuery?: 'all' | 'recents';
406
+ }
407
+ /**
408
+ * Ranks commands for a palette query. Searches the label, `group label`, keywords and id;
409
+ * an exact label or keyword match always wins. An empty query lists recent commands
410
+ * first (deduplicated and capped), then the rest in their original order.
411
+ */
412
+ declare function rankCommands<T extends RankableCommand>(query: string, entries: readonly T[], options?: RankCommandsOptions): RankedCommand<T>[];
413
+
414
+ /** One palette row. */
415
+ interface CommandPaletteItem extends RankedCommand<CommandEntry> {
416
+ id: string;
417
+ label: string;
418
+ group?: string;
419
+ /** Display-ready primary shortcut (`⇧⌘Z` / `Ctrl+Shift+Z`). */
420
+ shortcut?: string;
421
+ enabled: boolean;
422
+ disabledReason?: string;
423
+ }
424
+ interface CommandPaletteState {
425
+ open: boolean;
426
+ query: string;
427
+ activeIndex: number;
428
+ items: CommandPaletteItem[];
429
+ recents: string[];
430
+ /** Result of the last command the palette ran. */
431
+ lastResult: CommandResult | null;
432
+ }
433
+ interface CommandPaletteOptions<TContext = any> {
434
+ /** Context for enablement and runs (default: the registry's). */
435
+ context?: TContext | (() => TContext);
436
+ /** Only global commands plus these scopes. */
437
+ scope?: string | readonly string[] | (() => string | readonly string[] | undefined);
438
+ /** Initial recently run ids (newest first), e.g. restored from storage. */
439
+ recents?: readonly string[];
440
+ /** Called whenever the recents change, e.g. to persist them. */
441
+ onRecentsChange?: (recents: string[]) => void;
442
+ recentLimit?: number;
443
+ /** Maximum rows (default 50). */
444
+ limit?: number;
445
+ /** Platform for shortcut display (default: detected). */
446
+ platform?: Platform;
447
+ /** Called after a command ran from the palette. */
448
+ onRun?: (result: CommandResult) => void;
449
+ }
450
+ /**
451
+ * Framework-agnostic command palette state (open, query, ranked rows, active row and
452
+ * recents) over a `CommandRegistry`. The React hook and Svelte rune wrap it.
453
+ */
454
+ declare function createCommandPaletteController<TContext = any>(registry: CommandRegistry<TContext>, options?: CommandPaletteOptions<TContext>): {
455
+ getState: () => CommandPaletteState;
456
+ subscribe(listener: (state: CommandPaletteState) => void): () => void;
457
+ setOpen(next: boolean): void;
458
+ toggle(): void;
459
+ setQuery(next: string): void;
460
+ setActiveIndex(index: number): void;
461
+ /** Moves the active row by `delta`, wrapping around. */
462
+ move(delta: number): void;
463
+ /** Runs a command by id, closes the palette and records it as recent. Disabled commands do nothing. */
464
+ run(id: string): CommandResult | null;
465
+ runActive(): CommandResult | null;
466
+ /**
467
+ * Keyboard handling for the palette input: ArrowUp/ArrowDown (wrap), Home/End,
468
+ * Enter (run the active row) and Escape (close). Returns whether it handled the key.
469
+ */
470
+ handleKeyDown(event: KeyboardEventLike): boolean;
471
+ /** Re-reads commands and enablement. */
472
+ refresh(): void;
473
+ destroy(): void;
474
+ };
475
+ type CommandPaletteController = ReturnType<typeof createCommandPaletteController>;
476
+ /**
477
+ * Matches a global "open palette" hotkey (e.g. `Mod+K`), also while typing in inputs.
478
+ * Returns `true` when `event` is the hotkey.
479
+ */
480
+ declare function matchPaletteHotkey(event: KeyboardEventLike, hotkey: string, platform?: Platform): boolean;
481
+
482
+ interface CommandToolProviderOptions<TContext = any> {
483
+ /** Provider id (default `commands`). */
484
+ id?: string;
485
+ /** Always prefix the tool names with `<namespace>__`. */
486
+ namespace?: string;
487
+ /** Context for enablement and runs (default: the registry's). */
488
+ context?: TContext | (() => TContext);
489
+ /** Only expose global commands plus these scopes. */
490
+ scope?: string | readonly string[];
491
+ /** Commands agents may not see or run (e.g. ones that open dialogs). */
492
+ exclude?: (id: string) => boolean;
493
+ }
494
+ /**
495
+ * Exposes a `CommandRegistry` to agents through a `ToolRegistry`:
496
+ *
497
+ * - `list_commands {query?, enabledOnly?}`: ids, labels, params schemas, shortcuts and
498
+ * enablement (with the reason a command is disabled).
499
+ * - `run_command {id, params?}`: runs one command; disabled commands, unknown params and
500
+ * failures come back as `isError` results with a `{code, message}` error.
501
+ * - `run_commands {steps: [{id, params?}], stopOnError?}`: runs steps **in order**, each as
502
+ * its own command (and undo step). It is not atomic: steps that succeeded before a failure
503
+ * stay applied. For all-or-nothing behaviour, register a command that runs the steps
504
+ * inside `HistoryManager.batch` (or mark it `undoable` on a registry with `history`).
505
+ *
506
+ * The id enum in `run_command`'s schema follows the registered commands, so the
507
+ * `ToolRegistry` announces `listChanged` when commands are added or removed.
508
+ */
509
+ declare function createCommandToolProvider<TContext = any>(registry: CommandRegistry<TContext>, options?: CommandToolProviderOptions<TContext>): AgentToolProvider;
510
+
511
+ /** Minimal history surface (`HistoryManager` satisfies it). */
512
+ interface HistoryCommandTarget {
513
+ undo(): boolean | void;
514
+ redo(): boolean | void;
515
+ getState(): Pick<HistoryState, 'canUndo' | 'canRedo'> & Partial<Pick<HistoryState, 'undoName' | 'redoName'>>;
516
+ }
517
+ /** Default history bindings: `Mod+Z` undo; `Mod+Shift+Z` redo, plus `Mod+Y` off macOS. */
518
+ declare const DEFAULT_HISTORY_SHORTCUTS: readonly ShortcutBinding[];
519
+ interface HistoryCommandOptions {
520
+ /** Id prefix (default `history.`). */
521
+ prefix?: string;
522
+ group?: string;
523
+ scope?: string;
524
+ }
525
+ /** `history.undo` / `history.redo` commands for a `HistoryManager` (disabled with a reason when empty). */
526
+ declare function createHistoryCommands(history: HistoryCommandTarget, options?: HistoryCommandOptions): CommandSpec[];
527
+ /**
528
+ * Resolves a keydown event to `undo` / `redo` with the default history bindings
529
+ * (`Mod` is ⌘ on macOS and Ctrl elsewhere). Events from text inputs and
530
+ * contenteditable elements are ignored unless `allowInEditable`.
531
+ */
532
+ declare function matchHistoryShortcut(event: KeyboardEventLike, options?: {
533
+ platform?: Platform;
534
+ allowInEditable?: boolean;
535
+ }): 'undo' | 'redo' | null;
536
+ /** Minimal arrange controller surface (`createCanvasArrangeController` satisfies it). */
537
+ interface ArrangeCommandTarget {
538
+ align(edge: AlignEdge, ids?: Iterable<string>): unknown;
539
+ distribute(axis: DistributeAxis, mode?: DistributeMode, ids?: Iterable<string>): unknown;
540
+ reorder(operation: ZOrderOperation, ids?: Iterable<string>): unknown;
541
+ lock(ids?: Iterable<string>): unknown;
542
+ unlock(ids?: Iterable<string>): unknown;
543
+ }
544
+ interface ArrangeCommandOptions {
545
+ /** Id prefix (default `canvas.`). */
546
+ prefix?: string;
547
+ group?: string;
548
+ /** Scope of the commands and their shortcuts (default `canvas`). Pass `null` for global. */
549
+ scope?: string | null;
550
+ /** Current selection, used for enablement ("Select at least two nodes"). */
551
+ getSelectedIds?: () => string[];
552
+ /** Scene navigation (`nextScene` / `previousScene`); those commands are only added when given. */
553
+ scenes?: {
554
+ next(): unknown;
555
+ previous(): unknown;
556
+ };
557
+ /** Use these bindings instead of `DEFAULT_ARRANGE_SHORTCUTS`. */
558
+ bindings?: readonly {
559
+ action: CanvasArrangeAction;
560
+ label: string;
561
+ }[];
562
+ }
563
+ /**
564
+ * Commands for the canvas arrange actions (`canvas.alignLeft`, `canvas.bringToFront`, …)
565
+ * with the default arrange shortcuts. Each accepts `{ ids? }`; enablement checks the
566
+ * named ids, or the selection when none are named.
567
+ */
568
+ declare function createArrangeCommands(controller: ArrangeCommandTarget, options?: ArrangeCommandOptions): CommandSpec[];
569
+ /** Spreadsheet controller surface used by `createSpreadsheetCommands`. */
570
+ interface SpreadsheetCommandTarget {
571
+ selectedRange: unknown;
572
+ getFilterState(): {
573
+ enabled: boolean;
574
+ rules: readonly unknown[];
575
+ };
576
+ toggleFilters(): void;
577
+ clearFilters(): void;
578
+ unhideAll(): void;
579
+ mergeCells(): boolean;
580
+ unmergeCells(): boolean;
581
+ transposeRange(): boolean;
582
+ }
583
+ interface SpreadsheetCommandOptions {
584
+ /** Id prefix (default `spreadsheet.`). */
585
+ prefix?: string;
586
+ /** Scope (default `spreadsheet`). Pass `null` for global. */
587
+ scope?: string | null;
588
+ }
589
+ /** Palette / agent commands for common spreadsheet table actions (no default shortcuts). */
590
+ declare function createSpreadsheetCommands(controller: SpreadsheetCommandTarget, options?: SpreadsheetCommandOptions): CommandSpec[];
591
+
592
+ export { type ArrangeCommandOptions, type ArrangeCommandTarget, type Chord, type CommandEntry, type CommandErrorCode, type CommandHistoryTarget, type CommandListOptions, type CommandPaletteController, type CommandPaletteItem, type CommandPaletteOptions, type CommandPaletteState, type CommandParamsSchema, CommandRegistry, CommandRegistryError, type CommandRegistryOptions, type CommandResult, type CommandSpec, type CommandToolProviderOptions, DEFAULT_HISTORY_SHORTCUTS, DEFAULT_RECENT_LIMIT, type EffectiveChord, type FuzzyMatch, type HistoryCommandOptions, type HistoryCommandTarget, type KeyboardEventLike, PLATFORMS, type Platform, type RankCommandsOptions, type RankableCommand, type RankedCommand, type ShortcutBinding, type ShortcutConflict, type ShortcutInput, ShortcutMap, type ShortcutMapOptions, type ShortcutMatch, type ShortcutResolveOptions, type SpreadsheetCommandOptions, type SpreadsheetCommandTarget, chordToString, codeFromKey, codeToKeyText, createArrangeCommands, createCommandPaletteController, createCommandRegistry, createCommandToolProvider, createHistoryCommands, createSpreadsheetCommands, defineCommand, detectPlatform, effectiveChord, effectiveChordKey, eventCode, exactBonus, formatShortcut, fuzzyMatch, fuzzyScore, isEditableEventTarget, keyToCode, matchHistoryShortcut, matchPaletteHotkey, normalizeChord, parseChord, pushRecent, rankCommands, shortcutCode, toShortcutBindings };