@cloudvoyant/helical-ui 0.23.0 → 0.23.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,726 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/command/index.ts
21
+ var command_exports = {};
22
+ __export(command_exports, {
23
+ announceCommandMessage: () => announceCommandMessage,
24
+ commandMenuDialogContentBase: () => commandMenuDialogContentBase,
25
+ commandMenuErrorBase: () => commandMenuErrorBase,
26
+ commandMenuInputVariants: () => commandMenuInputVariants,
27
+ commandMenuItemVariants: () => commandMenuItemVariants,
28
+ commandMenuListVariants: () => commandMenuListVariants,
29
+ commandMenuPositionerBase: () => commandMenuPositionerBase,
30
+ commandMenuPrefixBase: () => commandMenuPrefixBase,
31
+ commandMenuPromptBarVariants: () => commandMenuPromptBarVariants,
32
+ commandMenuStyles: () => commandMenuStyles,
33
+ commandMenuVariants: () => commandMenuVariants,
34
+ commandPaletteBreadcrumbBase: () => commandPaletteBreadcrumbBase,
35
+ commandPaletteDialogContentBase: () => commandPaletteDialogContentBase,
36
+ commandPaletteFooterBase: () => commandPaletteFooterBase,
37
+ commandPaletteHeaderBase: () => commandPaletteHeaderBase,
38
+ commandPaletteInputBase: () => commandPaletteInputBase,
39
+ commandPaletteItemBase: () => commandPaletteItemBase,
40
+ commandPaletteListBase: () => commandPaletteListBase,
41
+ commandPalettePositionerBase: () => commandPalettePositionerBase,
42
+ commandPaletteStyles: () => commandPaletteStyles,
43
+ commandPaletteVariants: () => commandPaletteVariants,
44
+ createCommandTree: () => createCommandTree,
45
+ formatCommandMenuCompletionInput: () => formatCommandMenuCompletionInput,
46
+ matchesCommandHotkey: () => matchesCommandHotkey,
47
+ resolveCommandLevel: () => resolveCommandLevel,
48
+ resolveCommandMenuGridNavigation: () => resolveCommandMenuGridNavigation,
49
+ resolveCommandMenuGridStyle: () => resolveCommandMenuGridStyle,
50
+ resolveCommandMenuState: () => resolveCommandMenuState,
51
+ shouldHandleCommandHotkey: () => shouldHandleCommandHotkey,
52
+ splitHighlightSegments: () => splitHighlightSegments
53
+ });
54
+ module.exports = __toCommonJS(command_exports);
55
+
56
+ // src/command/core.ts
57
+ var import_hotkeys = require("@tanstack/hotkeys");
58
+ var import_collection = require("@zag-js/collection");
59
+ var import_i18n_utils = require("@zag-js/i18n-utils");
60
+ var import_live_region = require("@zag-js/live-region");
61
+ var import_fzf = require("fzf");
62
+ var ROOT_NODE_VALUE = "__root__";
63
+ var DEFAULT_GROUP_LABEL = "Commands";
64
+ var i18nFilter = (0, import_i18n_utils.createFilter)({ sensitivity: "base" });
65
+ var sharedLiveRegion = null;
66
+ function getNodeCommandToken(node) {
67
+ return (node.command ?? node.value).trim();
68
+ }
69
+ function isEditableTarget(target) {
70
+ if (!target || typeof target !== "object") return false;
71
+ const el = target;
72
+ if (el.isContentEditable) return true;
73
+ const tag = el.tagName?.toLowerCase();
74
+ if (tag === "input" || tag === "textarea" || tag === "select") return true;
75
+ if (typeof el.closest === "function" && el.closest('[contenteditable="true"], .ProseMirror')) {
76
+ return true;
77
+ }
78
+ return false;
79
+ }
80
+ function toFlatItem(node, ancestorPath, ancestorLabels, ancestorCommands, tree, fallbackGroup) {
81
+ const cmd = getNodeCommandToken(node);
82
+ const valuePath = [...ancestorPath, node.value];
83
+ const commandTokens = [...ancestorCommands, cmd];
84
+ const isBranch = tree.isBranchNode(node);
85
+ const group = node.group ?? fallbackGroup ?? (ancestorLabels.length > 0 ? ancestorLabels[ancestorLabels.length - 1] : DEFAULT_GROUP_LABEL);
86
+ return {
87
+ value: valuePath.join("/"),
88
+ label: node.label,
89
+ description: node.description,
90
+ group,
91
+ command: cmd,
92
+ fullCommand: `:${commandTokens.join(" ")}`,
93
+ aliases: node.aliases ?? [],
94
+ shortcut: node.shortcut,
95
+ badge: node.badge,
96
+ active: Boolean(node.active),
97
+ disabled: Boolean(node.disabled),
98
+ isBranch,
99
+ valuePath,
100
+ breadcrumbLabels: ancestorLabels,
101
+ node
102
+ };
103
+ }
104
+ function groupCommandItems(items) {
105
+ const map = /* @__PURE__ */ new Map();
106
+ for (const item of items) {
107
+ const groupLabel = item.group || DEFAULT_GROUP_LABEL;
108
+ const list = map.get(groupLabel);
109
+ if (list) {
110
+ list.push(item);
111
+ } else {
112
+ map.set(groupLabel, [item]);
113
+ }
114
+ }
115
+ return Array.from(map.entries()).map(([label, groupItems]) => ({
116
+ label,
117
+ items: groupItems
118
+ }));
119
+ }
120
+ function collectDeepFlatItems(parentNode, ancestorPath, ancestorLabels, ancestorCommands, tree, out) {
121
+ const children = tree.getNodeChildren(parentNode);
122
+ for (const child of children) {
123
+ const flat = toFlatItem(child, ancestorPath, ancestorLabels, ancestorCommands, tree);
124
+ out.push(flat);
125
+ if (tree.isBranchNode(child)) {
126
+ collectDeepFlatItems(
127
+ child,
128
+ [...ancestorPath, child.value],
129
+ [...ancestorLabels, child.label],
130
+ [...ancestorCommands, getNodeCommandToken(child)],
131
+ tree,
132
+ out
133
+ );
134
+ }
135
+ }
136
+ }
137
+ function matchesCommandToken(node, token) {
138
+ const lower = token.toLowerCase();
139
+ const cmd = getNodeCommandToken(node).toLowerCase();
140
+ if (cmd === lower || node.value.toLowerCase() === lower) {
141
+ return true;
142
+ }
143
+ return (node.aliases ?? []).some((alias) => alias.toLowerCase() === lower);
144
+ }
145
+ function isHotkeyAnchorVisible(el) {
146
+ if (el.closest("[hidden]")) return false;
147
+ const fwWrapper = el.closest("[data-fw]");
148
+ const activeFw = el.ownerDocument?.documentElement?.getAttribute("data-framework");
149
+ if (fwWrapper && activeFw && fwWrapper.getAttribute("data-fw") !== activeFw) {
150
+ return false;
151
+ }
152
+ return true;
153
+ }
154
+ function createCommandTree(items) {
155
+ if (items instanceof import_collection.TreeCollection) {
156
+ return items;
157
+ }
158
+ const rootNode = {
159
+ value: ROOT_NODE_VALUE,
160
+ label: "Root",
161
+ children: items ?? []
162
+ };
163
+ return new import_collection.TreeCollection({
164
+ rootNode,
165
+ nodeToValue: (node) => node.value,
166
+ nodeToString: (node) => node.label,
167
+ isNodeDisabled: (node) => Boolean(node.disabled),
168
+ nodeToChildren: (node) => node.children ?? []
169
+ });
170
+ }
171
+ function resolveCommandLevel(tree, activePath = [], query = "", options) {
172
+ const rootChildren = tree.getNodeChildren(tree.rootNode);
173
+ const hasCommands = rootChildren.length > 0;
174
+ if (!hasCommands) {
175
+ return {
176
+ hasCommands: false,
177
+ breadcrumbs: [],
178
+ items: [],
179
+ groups: []
180
+ };
181
+ }
182
+ const breadcrumbs = [];
183
+ const resolvedValuePath = [];
184
+ const resolvedLabels = [];
185
+ const resolvedCommands = [];
186
+ let currentNode = tree.rootNode;
187
+ for (const segment of activePath) {
188
+ const children = tree.getNodeChildren(currentNode);
189
+ const match = children.find((child) => child.value === segment);
190
+ if (!match || !tree.isBranchNode(match)) {
191
+ break;
192
+ }
193
+ const cmd = getNodeCommandToken(match);
194
+ breadcrumbs.push({
195
+ value: match.value,
196
+ label: match.label,
197
+ command: cmd
198
+ });
199
+ resolvedValuePath.push(match.value);
200
+ resolvedLabels.push(match.label);
201
+ resolvedCommands.push(cmd);
202
+ currentNode = match;
203
+ }
204
+ const trimmedQuery = query.trim();
205
+ const directChildren = tree.getNodeChildren(currentNode);
206
+ const directItems = directChildren.map(
207
+ (child) => toFlatItem(child, resolvedValuePath, resolvedLabels, resolvedCommands, tree)
208
+ );
209
+ if (!trimmedQuery) {
210
+ return {
211
+ hasCommands: true,
212
+ breadcrumbs,
213
+ items: directItems,
214
+ groups: groupCommandItems(directItems)
215
+ };
216
+ }
217
+ const normalizedQuery = trimmedQuery.startsWith(":") ? trimmedQuery.slice(1).trim() : trimmedQuery;
218
+ if (!normalizedQuery) {
219
+ return {
220
+ hasCommands: true,
221
+ breadcrumbs,
222
+ items: directItems,
223
+ groups: groupCommandItems(directItems)
224
+ };
225
+ }
226
+ const allowDeepSearch = options?.deepSearch !== false && breadcrumbs.length === 0;
227
+ const candidatePool = [];
228
+ if (allowDeepSearch) {
229
+ collectDeepFlatItems(currentNode, resolvedValuePath, resolvedLabels, resolvedCommands, tree, candidatePool);
230
+ } else {
231
+ candidatePool.push(...directItems);
232
+ }
233
+ const labelFzf = new import_fzf.Fzf(candidatePool, {
234
+ selector: (item) => item.label,
235
+ tiebreakers: [import_fzf.byLengthAsc],
236
+ casing: "case-insensitive"
237
+ });
238
+ const labelResults = labelFzf.find(normalizedQuery);
239
+ const labelMatchMap = /* @__PURE__ */ new Map();
240
+ for (const res of labelResults) {
241
+ labelMatchMap.set(res.item.value, {
242
+ score: res.score,
243
+ positions: Array.from(res.positions).sort((a, b) => a - b)
244
+ });
245
+ }
246
+ const compositeFzf = new import_fzf.Fzf(candidatePool, {
247
+ selector: (item) => [
248
+ item.label,
249
+ item.command,
250
+ item.fullCommand,
251
+ ...item.aliases,
252
+ ...item.breadcrumbLabels,
253
+ item.description ?? "",
254
+ ...item.node.keywords ?? []
255
+ ].join(" "),
256
+ tiebreakers: [import_fzf.byLengthAsc],
257
+ casing: "case-insensitive"
258
+ });
259
+ const compositeResults = compositeFzf.find(normalizedQuery);
260
+ const matchedByValue = /* @__PURE__ */ new Map();
261
+ for (const res of compositeResults) {
262
+ const labelHit = labelMatchMap.get(res.item.value);
263
+ const depthPenalty = (res.item.valuePath.length - 1) * 2;
264
+ const effectiveScore = (labelHit ? labelHit.score + 20 : res.score) - depthPenalty;
265
+ matchedByValue.set(res.item.value, {
266
+ ...res.item,
267
+ matchPositions: labelHit?.positions ?? [],
268
+ score: effectiveScore
269
+ });
270
+ }
271
+ for (const candidate of candidatePool) {
272
+ if (matchedByValue.has(candidate.value)) continue;
273
+ if (i18nFilter.contains(candidate.label, normalizedQuery) || i18nFilter.contains(candidate.command, normalizedQuery)) {
274
+ matchedByValue.set(candidate.value, {
275
+ ...candidate,
276
+ matchPositions: [],
277
+ score: 1
278
+ });
279
+ }
280
+ }
281
+ const rankedItems = Array.from(matchedByValue.values()).sort((a, b) => {
282
+ const scoreDiff = (b.score ?? 0) - (a.score ?? 0);
283
+ if (scoreDiff !== 0) return scoreDiff;
284
+ if (a.valuePath.length !== b.valuePath.length) {
285
+ return a.valuePath.length - b.valuePath.length;
286
+ }
287
+ return a.label.length - b.label.length;
288
+ });
289
+ return {
290
+ hasCommands: true,
291
+ breadcrumbs,
292
+ items: rankedItems,
293
+ groups: groupCommandItems(rankedItems)
294
+ };
295
+ }
296
+ function resolveCommandMenuState(tree, rawInput = "") {
297
+ const rootChildren = tree.getNodeChildren(tree.rootNode);
298
+ const hasCommands = rootChildren.length > 0;
299
+ const withoutColon = rawInput.startsWith(":") ? rawInput.slice(1) : rawInput;
300
+ const normalizedInput = `:${withoutColon}`;
301
+ if (!hasCommands) {
302
+ return {
303
+ hasCommands: false,
304
+ normalizedInput,
305
+ completedTokens: [],
306
+ partialToken: withoutColon.trim(),
307
+ breadcrumbs: [],
308
+ suggestions: [],
309
+ exactNode: null,
310
+ error: null
311
+ };
312
+ }
313
+ const hasTrailingSpace = /\s+$/.test(withoutColon);
314
+ const trimmed = withoutColon.trim();
315
+ const rawTokens = trimmed.length > 0 ? trimmed.split(/\s+/) : [];
316
+ const tokensToWalk = hasTrailingSpace ? rawTokens : rawTokens.slice(0, -1);
317
+ const partialToken = hasTrailingSpace ? "" : rawTokens[rawTokens.length - 1] ?? "";
318
+ const completedTokens = [];
319
+ const breadcrumbs = [];
320
+ const ancestorPath = [];
321
+ const ancestorLabels = [];
322
+ let currentNode = tree.rootNode;
323
+ for (let i = 0; i < tokensToWalk.length; i++) {
324
+ const token = tokensToWalk[i];
325
+ const children = tree.getNodeChildren(currentNode);
326
+ const matchedChild = children.find((child) => matchesCommandToken(child, token));
327
+ if (!matchedChild) {
328
+ return {
329
+ hasCommands: true,
330
+ normalizedInput,
331
+ completedTokens,
332
+ partialToken: rawTokens.slice(i).join(" "),
333
+ breadcrumbs,
334
+ suggestions: [],
335
+ exactNode: null,
336
+ error: `Unknown command: ${token}`
337
+ };
338
+ }
339
+ const canonicalCmd = getNodeCommandToken(matchedChild);
340
+ if (!tree.isBranchNode(matchedChild)) {
341
+ const extraTokens = rawTokens.slice(i + 1);
342
+ const hasExtra = extraTokens.length > 0 || partialToken.length > 0;
343
+ if (hasExtra) {
344
+ return {
345
+ hasCommands: true,
346
+ normalizedInput,
347
+ completedTokens: [...completedTokens, canonicalCmd],
348
+ partialToken,
349
+ breadcrumbs,
350
+ suggestions: [],
351
+ exactNode: null,
352
+ error: `Command ':${[...completedTokens, canonicalCmd].join(" ")}' does not take arguments`
353
+ };
354
+ }
355
+ const exactFlat = toFlatItem(matchedChild, ancestorPath, ancestorLabels, completedTokens, tree);
356
+ return {
357
+ hasCommands: true,
358
+ normalizedInput,
359
+ completedTokens: [...completedTokens, canonicalCmd],
360
+ partialToken: "",
361
+ breadcrumbs,
362
+ suggestions: [exactFlat],
363
+ exactNode: exactFlat,
364
+ error: null
365
+ };
366
+ }
367
+ completedTokens.push(canonicalCmd);
368
+ breadcrumbs.push({
369
+ value: matchedChild.value,
370
+ label: matchedChild.label,
371
+ command: canonicalCmd
372
+ });
373
+ ancestorPath.push(matchedChild.value);
374
+ ancestorLabels.push(matchedChild.label);
375
+ currentNode = matchedChild;
376
+ }
377
+ const branchChildren = tree.getNodeChildren(currentNode);
378
+ const branchItems = branchChildren.map(
379
+ (child) => toFlatItem(child, ancestorPath, ancestorLabels, completedTokens, tree)
380
+ );
381
+ if (!partialToken) {
382
+ return {
383
+ hasCommands: true,
384
+ normalizedInput,
385
+ completedTokens,
386
+ partialToken: "",
387
+ breadcrumbs,
388
+ suggestions: branchItems,
389
+ exactNode: null,
390
+ error: null
391
+ };
392
+ }
393
+ const exactChild = branchItems.find((item) => matchesCommandToken(item.node, partialToken)) ?? null;
394
+ const cmdFzf = new import_fzf.Fzf(branchItems, {
395
+ selector: (item) => item.command,
396
+ tiebreakers: [import_fzf.byLengthAsc],
397
+ casing: "case-insensitive"
398
+ });
399
+ const cmdHits = /* @__PURE__ */ new Map();
400
+ for (const res of cmdFzf.find(partialToken)) {
401
+ cmdHits.set(res.item.value, {
402
+ score: res.score,
403
+ positions: Array.from(res.positions).sort((a, b) => a - b)
404
+ });
405
+ }
406
+ const labelFzf = new import_fzf.Fzf(branchItems, {
407
+ selector: (item) => item.label,
408
+ tiebreakers: [import_fzf.byLengthAsc],
409
+ casing: "case-insensitive"
410
+ });
411
+ const labelHits = /* @__PURE__ */ new Map();
412
+ for (const res of labelFzf.find(partialToken)) {
413
+ labelHits.set(res.item.value, {
414
+ score: res.score,
415
+ positions: Array.from(res.positions).sort((a, b) => a - b)
416
+ });
417
+ }
418
+ const combinedFzf = new import_fzf.Fzf(branchItems, {
419
+ selector: (item) => [item.command, ...item.aliases, item.label, item.description ?? "", ...item.node.keywords ?? []].join(" "),
420
+ tiebreakers: [import_fzf.byLengthAsc],
421
+ casing: "case-insensitive"
422
+ });
423
+ const suggestionMap = /* @__PURE__ */ new Map();
424
+ for (const res of combinedFzf.find(partialToken)) {
425
+ const cmdHit = cmdHits.get(res.item.value);
426
+ const labelHit = labelHits.get(res.item.value);
427
+ const isExact = exactChild?.value === res.item.value;
428
+ const isPrefix = res.item.command.toLowerCase().startsWith(partialToken.toLowerCase());
429
+ const score = (cmdHit ? cmdHit.score + 50 : res.score) + (isExact ? 500 : 0) + (isPrefix ? 100 : 0);
430
+ suggestionMap.set(res.item.value, {
431
+ ...res.item,
432
+ commandMatchPositions: cmdHit?.positions ?? [],
433
+ matchPositions: labelHit?.positions ?? [],
434
+ score
435
+ });
436
+ }
437
+ const suggestions = Array.from(suggestionMap.values()).sort((a, b) => {
438
+ const scoreDiff = (b.score ?? 0) - (a.score ?? 0);
439
+ if (scoreDiff !== 0) return scoreDiff;
440
+ return a.command.length - b.command.length;
441
+ });
442
+ const error = suggestions.length === 0 ? `Unknown command: ${[...completedTokens, partialToken].join(" ")}` : null;
443
+ return {
444
+ hasCommands: true,
445
+ normalizedInput,
446
+ completedTokens,
447
+ partialToken,
448
+ breadcrumbs,
449
+ suggestions,
450
+ exactNode: exactChild ? suggestionMap.get(exactChild.value) ?? exactChild : null,
451
+ error
452
+ };
453
+ }
454
+ function formatCommandMenuCompletionInput(completedTokens, item, appendBranchSpace = true) {
455
+ const nextTokens = [...completedTokens, item.command].join(" ");
456
+ return item.isBranch && appendBranchSpace ? `:${nextTokens} ` : `:${nextTokens}`;
457
+ }
458
+ function splitHighlightSegments(text, matchPositions) {
459
+ if (!text) return [];
460
+ if (!matchPositions || matchPositions.length === 0) {
461
+ return [{ text, highlight: false }];
462
+ }
463
+ const posSet = new Set(matchPositions);
464
+ const segments = [];
465
+ let currentText = "";
466
+ let currentHighlight = posSet.has(0);
467
+ for (let i = 0; i < text.length; i++) {
468
+ const isHighlighted = posSet.has(i);
469
+ if (i > 0 && isHighlighted !== currentHighlight) {
470
+ segments.push({ text: currentText, highlight: currentHighlight });
471
+ currentText = text[i];
472
+ currentHighlight = isHighlighted;
473
+ } else {
474
+ currentText += text[i];
475
+ }
476
+ }
477
+ if (currentText.length > 0) {
478
+ segments.push({ text: currentText, highlight: currentHighlight });
479
+ }
480
+ return segments;
481
+ }
482
+ function announceCommandMessage(message) {
483
+ if (typeof document === "undefined" || !message) return;
484
+ try {
485
+ if (!sharedLiveRegion) {
486
+ sharedLiveRegion = (0, import_live_region.createLiveRegion)({ level: "polite", document });
487
+ }
488
+ sharedLiveRegion.announce(message, 150);
489
+ } catch {
490
+ }
491
+ }
492
+ function matchesCommandHotkey(event, hotkey) {
493
+ if (!hotkey) return false;
494
+ const trimmed = hotkey.trim();
495
+ if (trimmed === ":") {
496
+ if (isEditableTarget(event.target)) return false;
497
+ return !event.metaKey && !event.ctrlKey && !event.altKey && event.key === ":";
498
+ }
499
+ try {
500
+ if ((0, import_hotkeys.matchesKeyboardEvent)(event, hotkey)) {
501
+ return true;
502
+ }
503
+ } catch {
504
+ }
505
+ const normalized = trimmed.toLowerCase();
506
+ if (normalized === "mod+k" || normalized === "cmd+k" || normalized === "ctrl+k") {
507
+ return (event.metaKey || event.ctrlKey) && !event.altKey && event.key.toLowerCase() === "k";
508
+ }
509
+ return false;
510
+ }
511
+ function shouldHandleCommandHotkey(anchorEl, selector) {
512
+ if (!anchorEl || typeof document === "undefined") return true;
513
+ if (!isHotkeyAnchorVisible(anchorEl)) return false;
514
+ const myPreview = anchorEl.closest("[data-example-preview]");
515
+ const activePreview = document.activeElement?.closest?.("[data-example-preview]") ?? null;
516
+ if (activePreview) {
517
+ return myPreview === activePreview;
518
+ }
519
+ if (myPreview) {
520
+ const previewAnchors = Array.from(
521
+ document.querySelectorAll(`[data-example-preview] ${selector}`)
522
+ ).filter(isHotkeyAnchorVisible);
523
+ return previewAnchors[0] === anchorEl;
524
+ }
525
+ return true;
526
+ }
527
+ function resolveCommandMenuGridStyle(columns = "auto", itemCount) {
528
+ if (columns === 1 || itemCount <= 0) {
529
+ return void 0;
530
+ }
531
+ const maxCols = columns === "auto" ? itemCount <= 6 ? 2 : itemCount <= 12 ? 3 : 4 : columns;
532
+ const colCount = Math.max(1, Math.min(maxCols, itemCount));
533
+ const rowCount = Math.max(1, Math.ceil(itemCount / colCount));
534
+ return {
535
+ display: "grid",
536
+ gridAutoFlow: "column",
537
+ gridTemplateRows: `repeat(${rowCount}, minmax(0, auto))`,
538
+ gridTemplateColumns: `repeat(${colCount}, minmax(0, 1fr))`
539
+ };
540
+ }
541
+ function resolveCommandMenuGridNavigation(columns = "auto", itemCount, currentIdx, key) {
542
+ if (itemCount <= 0) return -1;
543
+ const safeIdx = currentIdx >= 0 && currentIdx < itemCount ? currentIdx : 0;
544
+ if (key === "ArrowDown") {
545
+ return (safeIdx + 1) % itemCount;
546
+ }
547
+ if (key === "ArrowUp") {
548
+ return (safeIdx - 1 + itemCount) % itemCount;
549
+ }
550
+ if (columns === 1) {
551
+ return safeIdx;
552
+ }
553
+ const maxCols = columns === "auto" ? itemCount <= 6 ? 2 : itemCount <= 12 ? 3 : 4 : columns;
554
+ const colCount = Math.max(1, Math.min(maxCols, itemCount));
555
+ const rowCount = Math.max(1, Math.ceil(itemCount / colCount));
556
+ const totalCols = Math.max(1, Math.ceil(itemCount / rowCount));
557
+ const row = safeIdx % rowCount;
558
+ const col = Math.floor(safeIdx / rowCount);
559
+ const nextCol = key === "ArrowRight" ? (col + 1) % totalCols : (col - 1 + totalCols) % totalCols;
560
+ return Math.min(nextCol * rowCount + row, itemCount - 1);
561
+ }
562
+
563
+ // src/command/styles.ts
564
+ var import_class_variance_authority = require("class-variance-authority");
565
+ var commandPaletteVariants = (0, import_class_variance_authority.cva)(
566
+ "flex w-full flex-col overflow-hidden rounded-xl border border-border bg-popover text-popover-foreground shadow-2xl outline-none",
567
+ {
568
+ variants: {
569
+ size: {
570
+ sm: "max-w-md",
571
+ md: "max-w-xl",
572
+ lg: "max-w-2xl"
573
+ }
574
+ },
575
+ defaultVariants: {
576
+ size: "md"
577
+ }
578
+ }
579
+ );
580
+ var commandPalettePositionerBase = "items-center justify-center p-4";
581
+ var commandPaletteDialogContentBase = "my-auto gap-0 overflow-hidden p-0 sm:max-w-xl";
582
+ var commandPaletteHeaderBase = "flex items-center gap-2 border-b border-border px-3 py-2.5";
583
+ var commandPaletteBreadcrumbBase = "inline-flex shrink-0 items-center gap-1 rounded-md bg-muted px-2 py-0.5 text-xs font-medium text-muted-foreground transition-colors hover:bg-accent hover:text-accent-foreground";
584
+ var commandPaletteInputBase = "flex-1 border-0 bg-transparent px-1 py-0.5 text-sm text-foreground outline-none placeholder:text-muted-foreground focus-visible:ring-0";
585
+ var commandPaletteListBase = "max-h-80 overflow-y-auto p-1.5 outline-none";
586
+ var commandPaletteItemBase = "group relative flex w-full cursor-pointer select-none items-center justify-between gap-3 rounded-lg px-2.5 py-2 text-sm outline-none transition-colors data-[highlighted]:bg-accent data-[highlighted]:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50";
587
+ var commandPaletteFooterBase = "flex flex-wrap items-center justify-between gap-2 border-t border-border bg-muted/30 px-3 py-2 text-[11px] text-muted-foreground";
588
+ var commandPaletteStyles = {
589
+ root: commandPaletteVariants,
590
+ positioner: commandPalettePositionerBase,
591
+ dialogContent: commandPaletteDialogContentBase,
592
+ header: commandPaletteHeaderBase,
593
+ breadcrumb: commandPaletteBreadcrumbBase,
594
+ input: commandPaletteInputBase,
595
+ list: commandPaletteListBase,
596
+ item: commandPaletteItemBase,
597
+ footer: commandPaletteFooterBase
598
+ };
599
+ var commandMenuVariants = (0, import_class_variance_authority.cva)(
600
+ "flex w-full flex-col overflow-hidden border border-border bg-popover font-mono text-popover-foreground shadow-2xl outline-none",
601
+ {
602
+ variants: {
603
+ size: {
604
+ sm: "text-xs",
605
+ md: "text-sm",
606
+ lg: "text-base"
607
+ }
608
+ },
609
+ defaultVariants: {
610
+ size: "md"
611
+ }
612
+ }
613
+ );
614
+ var commandMenuPositionerBase = "items-end justify-stretch p-0!";
615
+ var commandMenuDialogContentBase = "fixed inset-x-0 bottom-0 top-auto my-0 w-full max-w-none translate-x-0 translate-y-0 gap-0 overflow-hidden rounded-none border-x-0 border-b-0 border-t border-border p-0 shadow-2xl sm:max-w-none sm:rounded-none";
616
+ var commandMenuListVariants = (0, import_class_variance_authority.cva)("overflow-y-auto border-b border-border bg-popover/95 outline-none", {
617
+ variants: {
618
+ columns: {
619
+ auto: "grid! grid-flow-col!",
620
+ 1: "flex flex-col",
621
+ 2: "grid! grid-flow-col!",
622
+ 3: "grid! grid-flow-col!",
623
+ 4: "grid! grid-flow-col!"
624
+ },
625
+ size: {
626
+ sm: "max-h-44 gap-x-2 gap-y-0.5 px-2 py-1",
627
+ md: "max-h-60 gap-x-3 gap-y-1 p-2",
628
+ lg: "max-h-72 gap-x-4 gap-y-1.5 p-3"
629
+ }
630
+ },
631
+ defaultVariants: {
632
+ columns: "auto",
633
+ size: "md"
634
+ }
635
+ });
636
+ var commandMenuItemVariants = (0, import_class_variance_authority.cva)(
637
+ "group relative flex min-w-0 w-full cursor-pointer select-none items-center justify-between gap-2 rounded-md font-mono outline-none transition-colors data-[highlighted]:bg-accent data-[highlighted]:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
638
+ {
639
+ variants: {
640
+ size: {
641
+ sm: "px-1.5 py-0.5 text-[11px] leading-tight",
642
+ md: "px-2.5 py-1.5 text-xs",
643
+ lg: "px-3 py-2 text-sm"
644
+ }
645
+ },
646
+ defaultVariants: {
647
+ size: "md"
648
+ }
649
+ }
650
+ );
651
+ var commandMenuPromptBarVariants = (0, import_class_variance_authority.cva)(
652
+ "flex w-full items-center border-t border-border/60 bg-muted/50 font-mono",
653
+ {
654
+ variants: {
655
+ size: {
656
+ sm: "gap-1 px-2 py-1 text-xs",
657
+ md: "gap-1.5 px-3 py-2 text-sm",
658
+ lg: "gap-2 px-4 py-2.5 text-base"
659
+ }
660
+ },
661
+ defaultVariants: {
662
+ size: "md"
663
+ }
664
+ }
665
+ );
666
+ var commandMenuPrefixBase = "select-none font-mono font-bold text-primary";
667
+ var commandMenuInputVariants = (0, import_class_variance_authority.cva)(
668
+ "flex-1 border-0 bg-transparent font-mono text-foreground outline-none placeholder:text-muted-foreground focus-visible:ring-0",
669
+ {
670
+ variants: {
671
+ size: {
672
+ sm: "px-0.5 py-0 text-xs",
673
+ md: "px-1 py-0.5 text-sm",
674
+ lg: "px-1.5 py-1 text-base"
675
+ }
676
+ },
677
+ defaultVariants: {
678
+ size: "md"
679
+ }
680
+ }
681
+ );
682
+ var commandMenuErrorBase = "flex items-center justify-between gap-2 border-t border-destructive/30 bg-destructive/10 px-3 py-1.5 font-mono text-xs text-destructive";
683
+ var commandMenuStyles = {
684
+ root: commandMenuVariants,
685
+ positioner: commandMenuPositionerBase,
686
+ dialogContent: commandMenuDialogContentBase,
687
+ list: commandMenuListVariants,
688
+ item: commandMenuItemVariants,
689
+ promptBar: commandMenuPromptBarVariants,
690
+ prefix: commandMenuPrefixBase,
691
+ input: commandMenuInputVariants,
692
+ error: commandMenuErrorBase
693
+ };
694
+ // Annotate the CommonJS export names for ESM import in node:
695
+ 0 && (module.exports = {
696
+ announceCommandMessage,
697
+ commandMenuDialogContentBase,
698
+ commandMenuErrorBase,
699
+ commandMenuInputVariants,
700
+ commandMenuItemVariants,
701
+ commandMenuListVariants,
702
+ commandMenuPositionerBase,
703
+ commandMenuPrefixBase,
704
+ commandMenuPromptBarVariants,
705
+ commandMenuStyles,
706
+ commandMenuVariants,
707
+ commandPaletteBreadcrumbBase,
708
+ commandPaletteDialogContentBase,
709
+ commandPaletteFooterBase,
710
+ commandPaletteHeaderBase,
711
+ commandPaletteInputBase,
712
+ commandPaletteItemBase,
713
+ commandPaletteListBase,
714
+ commandPalettePositionerBase,
715
+ commandPaletteStyles,
716
+ commandPaletteVariants,
717
+ createCommandTree,
718
+ formatCommandMenuCompletionInput,
719
+ matchesCommandHotkey,
720
+ resolveCommandLevel,
721
+ resolveCommandMenuGridNavigation,
722
+ resolveCommandMenuGridStyle,
723
+ resolveCommandMenuState,
724
+ shouldHandleCommandHotkey,
725
+ splitHighlightSegments
726
+ });