{"version":3,"file":"command-palette-items.cjs","names":[],"sources":["../../../src/overlay/command-palette/command-palette-items.ts"],"sourcesContent":["import type { CommandPaletteItem, CommandPaletteItemInput } from './command-palette.types';\n\n// ── Flat row model ────────────────────────────────────────────────────────────\n// Items are grouped by `group` (preserving first-seen order) and flattened into a\n// single list of rows so the listbox can render group headings inline while\n// keyboard navigation still walks a single, index-addressable sequence.\n\nexport type CommandPaletteRow =\n  | { group: string; type: 'group' }\n  | { idx: number; item: CommandPaletteItem; type: 'item' };\n\nexport function parseSlottedItems(elements: Element[]): CommandPaletteItem[] {\n  return elements\n    .filter((el) => el.localName === 'ore-command-palette-item')\n    .map((el) => ({\n      disabled: el.hasAttribute('disabled'),\n      group: el.getAttribute('group') ?? undefined,\n      icon: el.getAttribute('icon') ?? undefined,\n      keywords: (el.getAttribute('keywords') ?? '')\n        .split(',')\n        .map((term) => term.trim())\n        .filter(Boolean),\n      label:\n        el.getAttribute('label') ||\n        [...el.childNodes]\n          .filter((node) => node.nodeType === Node.TEXT_NODE)\n          .map((node) => node.textContent?.trim())\n          .filter(Boolean)\n          .join(' ') ||\n        '',\n      shortcut: el.getAttribute('shortcut') ?? undefined,\n      value: el.getAttribute('value') ?? '',\n    }));\n}\n\n/**\n * Splits a display-only shortcut hint into individual keys so each can be rendered in its\n * own `<kbd>`. Keys are separated with `+` (e.g. `\"⌘+N\"` → `[\"⌘\", \"N\"]`); a shortcut with no\n * `+` renders as a single key, unchanged. A literal `+` key can't be represented this way —\n * spell it out instead (e.g. `\"Ctrl+Plus\"`).\n */\nexport function splitShortcutKeys(shortcut: string): string[] {\n  return shortcut\n    .split('+')\n    .map((key) => key.trim())\n    .filter(Boolean);\n}\n\nexport function normalizeItem(input: CommandPaletteItemInput): CommandPaletteItem {\n  return {\n    disabled: Boolean(input.disabled),\n    group: input.group,\n    icon: input.icon,\n    keywords: input.keywords ?? [],\n    label: input.label ?? input.value,\n    shortcut: input.shortcut,\n    value: input.value,\n  };\n}\n\nexport function filterItems(items: CommandPaletteItem[], query: string, noFilter: boolean): CommandPaletteItem[] {\n  if (noFilter) return items;\n\n  const normalizedQuery = query.toLowerCase().trim();\n\n  if (!normalizedQuery) return items;\n\n  return items.filter(\n    (item) =>\n      item.label.toLowerCase().includes(normalizedQuery) ||\n      item.value.toLowerCase().includes(normalizedQuery) ||\n      item.keywords.some((keyword) => keyword.toLowerCase().includes(normalizedQuery)),\n  );\n}\n\n/** Groups items by `group` (first-seen order) and flattens into index-addressable rows. */\nexport function buildRows(items: CommandPaletteItem[]): CommandPaletteRow[] {\n  const groups = new Map<string | undefined, CommandPaletteItem[]>();\n\n  for (const item of items) {\n    const key = item.group;\n    let bucket = groups.get(key);\n\n    if (!bucket) {\n      bucket = [];\n      groups.set(key, bucket);\n    }\n\n    bucket.push(item);\n  }\n\n  const rows: CommandPaletteRow[] = [];\n  let idx = 0;\n\n  for (const [group, groupItems] of groups) {\n    if (group !== undefined) rows.push({ group, type: 'group' });\n\n    for (const item of groupItems) rows.push({ idx: idx++, item, type: 'item' });\n  }\n\n  return rows;\n}\n"],"mappings":"AAWA,SAAgB,EAAkB,EAA2C,CAC3E,OAAO,EACJ,OAAQ,GAAO,EAAG,YAAc,0BAA0B,CAAC,CAC3D,IAAK,IAAQ,CACZ,SAAU,EAAG,aAAa,UAAU,EACpC,MAAO,EAAG,aAAa,OAAO,GAAK,IAAA,GACnC,KAAM,EAAG,aAAa,MAAM,GAAK,IAAA,GACjC,UAAW,EAAG,aAAa,UAAU,GAAK,GAAA,CACvC,MAAM,GAAG,CAAC,CACV,IAAK,GAAS,EAAK,KAAK,CAAC,CAAC,CAC1B,OAAO,OAAO,EACjB,MACE,EAAG,aAAa,OAAO,GACvB,CAAC,GAAG,EAAG,UAAU,CAAC,CACf,OAAQ,GAAS,EAAK,WAAa,KAAK,SAAS,CAAC,CAClD,IAAK,GAAS,EAAK,aAAa,KAAK,CAAC,CAAC,CACvC,OAAO,OAAO,CAAC,CACf,KAAK,GAAG,GACX,GACF,SAA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