@qikbar/qikbar 0.0.25 → 0.1.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 (89) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +92 -0
  3. package/dist/ai/agent.d.ts +42 -0
  4. package/dist/ai/byok.d.ts +29 -0
  5. package/dist/ai/index.d.ts +8 -0
  6. package/dist/ai/providers.d.ts +82 -0
  7. package/dist/ai/sse.d.ts +9 -0
  8. package/dist/ai.js +36 -0
  9. package/dist/ai.js.map +7 -0
  10. package/dist/chunks/bar-D5CSPT3U.js +2031 -0
  11. package/dist/chunks/bar-D5CSPT3U.js.map +7 -0
  12. package/dist/chunks/chunk-2ADXL7KQ.js +358 -0
  13. package/dist/chunks/chunk-2ADXL7KQ.js.map +7 -0
  14. package/dist/chunks/chunk-6TC6G2C5.js +107 -0
  15. package/dist/chunks/chunk-6TC6G2C5.js.map +7 -0
  16. package/dist/chunks/chunk-HBBSETRF.js +153 -0
  17. package/dist/chunks/chunk-HBBSETRF.js.map +7 -0
  18. package/dist/chunks/chunk-I77YSUJN.js +104 -0
  19. package/dist/chunks/chunk-I77YSUJN.js.map +7 -0
  20. package/dist/chunks/chunk-IJ3WUM3T.js +544 -0
  21. package/dist/chunks/chunk-IJ3WUM3T.js.map +7 -0
  22. package/dist/chunks/chunk-MPTP2EWW.js +8 -0
  23. package/dist/chunks/chunk-MPTP2EWW.js.map +7 -0
  24. package/dist/chunks/chunk-N4Y2Z6YD.js +69 -0
  25. package/dist/chunks/chunk-N4Y2Z6YD.js.map +7 -0
  26. package/dist/chunks/chunk-PQEHV3D4.js +124 -0
  27. package/dist/chunks/chunk-PQEHV3D4.js.map +7 -0
  28. package/dist/chunks/chunk-VXTYD56F.js +453 -0
  29. package/dist/chunks/chunk-VXTYD56F.js.map +7 -0
  30. package/dist/chunks/chunk-YCVJQ7U3.js +52 -0
  31. package/dist/chunks/chunk-YCVJQ7U3.js.map +7 -0
  32. package/dist/core/define.d.ts +40 -0
  33. package/dist/core/frecency.d.ts +16 -0
  34. package/dist/core/hotkeys.d.ts +39 -0
  35. package/dist/core/lazy.d.ts +48 -0
  36. package/dist/core/search.d.ts +42 -0
  37. package/dist/core/storage.d.ts +5 -0
  38. package/dist/core/types.d.ts +601 -0
  39. package/dist/extensions/index.d.ts +30 -0
  40. package/dist/extensions/math.d.ts +14 -0
  41. package/dist/extensions.js +476 -0
  42. package/dist/extensions.js.map +7 -0
  43. package/dist/index.d.ts +27 -0
  44. package/dist/index.js +67 -0
  45. package/dist/index.js.map +7 -0
  46. package/dist/qikbar.global.js +259 -0
  47. package/dist/qikbar.global.js.map +7 -0
  48. package/dist/react/index.d.ts +66 -0
  49. package/dist/react.js +119 -0
  50. package/dist/react.js.map +7 -0
  51. package/dist/server/index.d.ts +47 -0
  52. package/dist/server.js +93 -0
  53. package/dist/server.js.map +7 -0
  54. package/dist/styles.css +222 -0
  55. package/dist/theme.d.ts +5 -0
  56. package/dist/theme.js +20 -0
  57. package/dist/theme.js.map +7 -0
  58. package/dist/ui/bar.d.ts +252 -0
  59. package/dist/ui/dom.d.ts +21 -0
  60. package/dist/ui/icons.d.ts +88 -0
  61. package/dist/ui/markdown.d.ts +8 -0
  62. package/dist/ui/nav.d.ts +8 -0
  63. package/dist/ui/styles.d.ts +6 -0
  64. package/dist/ui/themes.d.ts +27 -0
  65. package/dist/ui/views.d.ts +148 -0
  66. package/dist/utils.d.ts +10 -0
  67. package/dist/utils.js +50 -0
  68. package/dist/utils.js.map +7 -0
  69. package/package.json +88 -43
  70. package/dist/qikbar.es.js +0 -8748
  71. package/dist/qikbar.umd.js +0 -113
  72. package/dist/types/boot.d.ts +0 -72
  73. package/dist/types/index.d.ts +0 -1
  74. package/dist/types/init.d.ts +0 -2
  75. package/dist/types/main.d.ts +0 -4
  76. package/dist/types/shared/AsyncRoot.d.ts +0 -5
  77. package/dist/types/shared/CommandFooter.d.ts +0 -5
  78. package/dist/types/shared/Crumbs.d.ts +0 -6
  79. package/dist/types/shared/Details.d.ts +0 -3
  80. package/dist/types/shared/ErrorBoundary.d.ts +0 -15
  81. package/dist/types/shared/Icon.d.ts +0 -4
  82. package/dist/types/shared/List.d.ts +0 -30
  83. package/dist/types/shared/Qikbar.d.ts +0 -5
  84. package/dist/types/shared/Root.d.ts +0 -4
  85. package/dist/types/shared/Search.d.ts +0 -1
  86. package/dist/types/shared/commandContext.d.ts +0 -8
  87. package/dist/types/shared/useDebounce.d.ts +0 -1
  88. package/dist/types/utils/liquid.d.ts +0 -4
  89. package/dist/types/vite-env.d.ts +0 -1
@@ -0,0 +1,2031 @@
1
+ import {
2
+ createAIClient,
3
+ runAgent
4
+ } from "./chunk-N4Y2Z6YD.js";
5
+ import {
6
+ action
7
+ } from "./chunk-I77YSUJN.js";
8
+ import {
9
+ css,
10
+ cssVarName,
11
+ resolveThemeVars
12
+ } from "./chunk-IJ3WUM3T.js";
13
+ import {
14
+ Frecency,
15
+ copyText,
16
+ defaultNavigate,
17
+ iconSvg,
18
+ matchItem,
19
+ rank,
20
+ renderMarkdown
21
+ } from "./chunk-VXTYD56F.js";
22
+ import {
23
+ defaultStorage,
24
+ scopedStorage
25
+ } from "./chunk-YCVJQ7U3.js";
26
+ import {
27
+ SequenceMatcher,
28
+ allowedInInput,
29
+ formatHotkey,
30
+ isEditable,
31
+ matchesHotkey
32
+ } from "./chunk-PQEHV3D4.js";
33
+ import {
34
+ __publicField
35
+ } from "./chunk-MPTP2EWW.js";
36
+
37
+ // src/ui/dom.ts
38
+ function h(tag, props, ...children) {
39
+ let el = document.createElement(tag);
40
+ if (props)
41
+ for (let key in props) {
42
+ let value = props[key];
43
+ value == null || value === !1 || (key === "class" ? el.className = value : key === "style" && typeof value == "object" ? Object.assign(el.style, value) : key.startsWith("on") && typeof value == "function" ? el.addEventListener(key.slice(2).toLowerCase(), value) : key === "html" ? el.innerHTML = value : key in el && typeof value != "string" ? el[key] = value : el.setAttribute(key, value === !0 ? "" : String(value)));
44
+ }
45
+ return append(el, children), el;
46
+ }
47
+ function append(el, children) {
48
+ for (let child of children)
49
+ Array.isArray(child) ? append(el, child) : child != null && child !== !1 && el.append(child instanceof Node ? child : String(child));
50
+ }
51
+ var URL_RE = /^(https?:|\/|\.\.?\/|data:image\/|blob:)/;
52
+ function renderIcon(icon, size = 16) {
53
+ if (icon == null || icon === "") return null;
54
+ let wrap = h("span", { class: "qb-icon", "aria-hidden": "true" });
55
+ if (typeof icon == "function")
56
+ wrap.append(icon());
57
+ else if (typeof Node < "u" && icon instanceof Node)
58
+ wrap.append(icon.cloneNode(!0));
59
+ else if (typeof icon == "object" && "url" in icon)
60
+ wrap.append(h("img", { src: icon.url, alt: icon.alt ?? "", loading: "lazy", decoding: "async", draggable: "false" }));
61
+ else if (typeof icon == "object" && "color" in icon) {
62
+ wrap.classList.add("qb-icon-tinted"), wrap.style.setProperty("--qb-tint", colorValue(icon.color));
63
+ let inner = renderIcon(icon.icon ?? "dot", size);
64
+ inner && wrap.append(...inner.childNodes);
65
+ } else if (typeof icon == "string") {
66
+ let svg = iconSvg(icon, size);
67
+ svg ? wrap.innerHTML = svg : icon.trimStart().startsWith("<svg") ? wrap.innerHTML = icon : URL_RE.test(icon) ? wrap.append(h("img", { src: icon, alt: "", loading: "lazy", decoding: "async", draggable: "false" })) : (wrap.classList.add("qb-icon-text"), wrap.textContent = icon);
68
+ }
69
+ return wrap;
70
+ }
71
+ function renderKbd(hotkey, className = "qb-kbd") {
72
+ let wrap = h("span", { class: "qb-kbds", "aria-label": hotkey });
73
+ return formatHotkey(hotkey).forEach((combo, i) => {
74
+ i > 0 && wrap.append(h("span", { class: "qb-kbd-then" }, "then"));
75
+ for (let key of combo) wrap.append(h("kbd", { class: className }, key));
76
+ }), wrap;
77
+ }
78
+ function highlight(text, positions) {
79
+ if (!positions || positions.length === 0) return text;
80
+ let frag = document.createDocumentFragment(), last = 0, i = 0;
81
+ for (; i < positions.length; ) {
82
+ let start = positions[i], end = start;
83
+ for (; i + 1 < positions.length && positions[i + 1] === end + 1; )
84
+ i++, end++;
85
+ start > last && frag.append(text.slice(last, start)), frag.append(h("mark", { class: "qb-match" }, text.slice(start, end + 1))), last = end + 1, i++;
86
+ }
87
+ return last < text.length && frag.append(text.slice(last)), frag;
88
+ }
89
+ var NAMED_COLORS = {
90
+ default: "var(--qb-fg-muted)",
91
+ gray: "var(--qb-fg-subtle)",
92
+ blue: "#3b82f6",
93
+ green: "#22c55e",
94
+ yellow: "#eab308",
95
+ orange: "#f97316",
96
+ red: "#ef4444",
97
+ purple: "#a855f7",
98
+ pink: "#ec4899"
99
+ };
100
+ function colorValue(color) {
101
+ return color ? NAMED_COLORS[color] ?? color : NAMED_COLORS.default;
102
+ }
103
+ function renderTag(tag) {
104
+ let value = typeof tag == "string" ? tag : tag.value, color = typeof tag == "string" ? void 0 : tag.color, el = h("span", { class: "qb-tag" }, value);
105
+ return color && el.style.setProperty("--qb-tint", colorValue(color)), el;
106
+ }
107
+ var rtf = typeof Intl < "u" && "RelativeTimeFormat" in Intl ? new Intl.RelativeTimeFormat(void 0, { numeric: "auto", style: "short" }) : null;
108
+ function relativeTime(date) {
109
+ let d = new Date(date), diff = (d.getTime() - Date.now()) / 1e3, abs = Math.abs(diff);
110
+ return rtf ? abs < 60 ? rtf.format(Math.round(diff), "second") : abs < 3600 ? rtf.format(Math.round(diff / 60), "minute") : abs < 86400 ? rtf.format(Math.round(diff / 3600), "hour") : abs < 86400 * 30 ? rtf.format(Math.round(diff / 86400), "day") : abs < 86400 * 365 ? rtf.format(Math.round(diff / (86400 * 30)), "month") : rtf.format(Math.round(diff / (86400 * 365)), "year") : d.toLocaleDateString();
111
+ }
112
+ function renderAccessory(acc) {
113
+ let el = h("span", { class: "qb-accessory", title: acc.tooltip }), icon = renderIcon(acc.icon, 14);
114
+ return icon && el.append(icon), acc.tag && el.append(renderTag(acc.tag)), acc.text && el.append(h("span", null, acc.text)), acc.date != null && el.append(h("time", { datetime: new Date(acc.date).toISOString() }, relativeTime(acc.date))), acc.kbd && el.append(renderKbd(acc.kbd)), el;
115
+ }
116
+ var idCounter = 0;
117
+ function uid(prefix = "qb") {
118
+ return `${prefix}-${(++idCounter).toString(36)}`;
119
+ }
120
+
121
+ // src/ui/views.ts
122
+ var VIRTUAL_THRESHOLD = 150, OVERSCAN = 10, optionId = (bar, key) => `${bar.instanceId}-opt-${key.replace(/[^\w-]/g, "_")}`;
123
+ function px(value, fallback) {
124
+ let n = parseFloat(value);
125
+ return Number.isFinite(n) && n > 0 ? n : fallback;
126
+ }
127
+ var detailCache = /* @__PURE__ */ new WeakMap(), ListRenderer = class {
128
+ constructor(bar, frame) {
129
+ __publicField(this, "bar", bar);
130
+ __publicField(this, "frame", frame);
131
+ __publicField(this, "el");
132
+ __publicField(this, "hasInput", !0);
133
+ __publicField(this, "scroller");
134
+ __publicField(this, "inner");
135
+ __publicField(this, "emptyEl");
136
+ __publicField(this, "detailEl");
137
+ __publicField(this, "cache", /* @__PURE__ */ new Map());
138
+ __publicField(this, "renderedKeys", []);
139
+ __publicField(this, "selectedEl");
140
+ __publicField(this, "virtual", !1);
141
+ __publicField(this, "offsets", []);
142
+ __publicField(this, "rowHeight", 42);
143
+ __publicField(this, "sectionHeight", 30);
144
+ __publicField(this, "rafId", 0);
145
+ __publicField(this, "detailFor");
146
+ __publicField(this, "onScroll", () => {
147
+ !this.virtual || this.rafId || (this.rafId = requestAnimationFrame(() => {
148
+ this.rafId = 0, this.renderWindow();
149
+ }));
150
+ });
151
+ __publicField(this, "onPointerMove", (e) => {
152
+ let el = e.target.closest?.("[data-index]");
153
+ if (!el) return;
154
+ let index = Number(el.dataset.index);
155
+ index !== this.frame.selected && this.select(index, !1);
156
+ });
157
+ __publicField(this, "onClick", (e) => {
158
+ let el = e.target.closest?.("[data-index]");
159
+ el && (this.select(Number(el.dataset.index), !1), this.bar.runPrimary(this.frame, e.metaKey || e.ctrlKey ? 1 : 0));
160
+ });
161
+ this.inner = h("div", { class: "qb-list-inner" }), this.scroller = h(
162
+ "div",
163
+ { class: `${bar.cls("qb-scroll qb-list", "list")}`, role: "listbox", id: `${bar.instanceId}-list`, "aria-label": "Results", tabindex: "-1" },
164
+ this.inner
165
+ ), this.emptyEl = h("div", { class: "qb-empty", hidden: !0 }), frame.view.type === "list" && frame.view.detail ? (this.detailEl = h("div", { class: bar.cls("qb-detail qb-md", "detail") }), this.el = h("div", { class: "qb-split", style: "display:flex;flex:1;min-width:0;position:relative" }, this.scroller, this.detailEl, this.emptyEl)) : this.el = h("div", { style: "display:flex;flex:1;min-width:0;position:relative" }, this.scroller, this.emptyEl), this.scroller.addEventListener("pointermove", this.onPointerMove), this.scroller.addEventListener("click", this.onClick), this.scroller.addEventListener("pointerdown", (e) => e.preventDefault()), this.scroller.addEventListener("scroll", this.onScroll, { passive: !0 });
166
+ }
167
+ measure() {
168
+ let cs = getComputedStyle(this.bar.dom.root);
169
+ this.rowHeight = px(cs.getPropertyValue("--qb-row-height"), 42), this.sectionHeight = px(cs.getPropertyValue("--qb-section-height"), 30);
170
+ }
171
+ update() {
172
+ let rows = this.frame.rows, wasVirtual = this.virtual;
173
+ if (this.virtual = rows.length > VIRTUAL_THRESHOLD, this.virtual) {
174
+ wasVirtual || this.measure();
175
+ let y = 0;
176
+ this.offsets = rows.map((r) => {
177
+ let top = y;
178
+ return y += r.kind === "section" ? this.sectionHeight : this.rowHeight, top;
179
+ }), this.inner.style.height = `${y}px`, this.renderWindow();
180
+ } else {
181
+ if (wasVirtual) {
182
+ this.inner.style.height = "";
183
+ for (let { el } of this.cache.values()) el.style.cssText = "";
184
+ }
185
+ let keys = rows.map((r) => r.key), els = rows.map((r) => this.rowEl(r));
186
+ (!sameKeys(keys, this.renderedKeys) || els.some((el, i) => this.inner.children[i] !== el)) && (this.inner.replaceChildren(...els), this.renderedKeys = keys), this.prune(new Set(keys));
187
+ }
188
+ this.updateSelection(), this.updateEmpty(), this.updateDetail();
189
+ }
190
+ prune(keep) {
191
+ if (!(this.cache.size < 400))
192
+ for (let key of this.cache.keys()) keep.has(key) || this.cache.delete(key);
193
+ }
194
+ renderWindow() {
195
+ let rows = this.frame.rows, top = this.scroller.scrollTop, height = this.scroller.clientHeight || 400, start = bisect(this.offsets, top) - OVERSCAN;
196
+ start = Math.max(0, start);
197
+ let end = bisect(this.offsets, top + height) + OVERSCAN;
198
+ end = Math.min(rows.length, end + 1);
199
+ let els = [], keys = [];
200
+ for (let i = start; i < end; i++) {
201
+ let row = rows[i], el = this.rowEl(row);
202
+ el.style.position = "absolute", el.style.top = `${this.offsets[i]}px`, el.style.left = "0", el.style.right = "0", els.push(el), keys.push(row.key);
203
+ }
204
+ sameKeys(keys, this.renderedKeys) || (this.inner.replaceChildren(...els), this.renderedKeys = keys), this.updateSelection();
205
+ }
206
+ rowSig(row) {
207
+ return row.kind === "section" ? row.title : `${row.index}|${row.positions?.join(",") ?? ""}`;
208
+ }
209
+ rowEl(row) {
210
+ let sig = this.rowSig(row), cached = this.cache.get(row.key);
211
+ if (cached && cached.sig === sig && (row.kind === "section" || cached.el.__item === row.item)) return cached.el;
212
+ let el = row.kind === "section" ? this.sectionEl(row.title) : this.itemEl(row);
213
+ return row.kind === "item" && (el.__item = row.item), this.cache.set(row.key, { el, sig }), el;
214
+ }
215
+ sectionEl(title) {
216
+ return h("div", { class: this.bar.cls("qb-section", "section"), role: "presentation" }, title);
217
+ }
218
+ itemEl(row) {
219
+ let { item } = row, isRoot = this.frame.view.type === "root", right = [];
220
+ return item.accessories?.length ? right.push(h("span", { class: "qb-item-accessories" }, ...item.accessories.map(renderAccessory))) : item.shortcut && right.push(h("span", { class: "qb-item-accessories" }, renderKbd(item.shortcut))), isRoot && !item.accessories?.length && !item.shortcut && right.push(h("span", { class: "qb-item-kind" }, this.kindOf(item))), h(
221
+ "div",
222
+ {
223
+ class: this.bar.cls("qb-item", "item"),
224
+ role: "option",
225
+ id: optionId(this.bar, row.key),
226
+ "aria-selected": "false",
227
+ "data-index": String(row.index)
228
+ },
229
+ h("span", { class: "qb-item-icon" }, renderIcon(item.icon ?? (isRoot ? "command" : void 0), 16)),
230
+ h(
231
+ "span",
232
+ { class: "qb-item-text" },
233
+ h("span", { class: "qb-item-title" }, highlight(item.title, row.positions)),
234
+ item.subtitle ? h("span", { class: "qb-item-subtitle" }, item.subtitle) : null
235
+ ),
236
+ ...right
237
+ );
238
+ }
239
+ kindOf(item) {
240
+ return this.bar.itemExt.get(item) ? "Command" : item.href ? "Page" : item.url ? "Link" : "Command";
241
+ }
242
+ updateSelection() {
243
+ let row = this.frame.itemRows[this.frame.selected], el = row ? this.cache.get(row.key)?.el : void 0;
244
+ this.selectedEl && this.selectedEl !== el && this.selectedEl.setAttribute("aria-selected", "false"), el && el.setAttribute("aria-selected", "true"), this.selectedEl = el;
245
+ }
246
+ updateEmpty() {
247
+ let f = this.frame, empty = f.itemRows.length === 0;
248
+ if (this.scroller.hidden = empty && !this.detailEl, !empty || f.loading > 0 && !f.error) {
249
+ this.emptyEl.hidden = !0;
250
+ return;
251
+ }
252
+ let view = f.view, icon = "search", title = "No results", desc = f.query ? `Nothing matches \u201C${f.query}\u201D` : null;
253
+ f.error ? (icon = "alert", title = "Couldn\u2019t load results", desc = f.error) : view.emptyView ? (icon = view.emptyView.icon ?? icon, title = view.emptyView.title, desc = view.emptyView.description ?? null) : f.view.type === "root" && !f.query && (title = "Start typing to search", desc = null), this.emptyEl.replaceChildren(
254
+ renderIcon(icon, 28) ?? "",
255
+ h("div", { class: "qb-empty-title" }, title),
256
+ desc ? h("div", { class: "qb-empty-desc" }, desc) : ""
257
+ ), this.emptyEl.hidden = !1;
258
+ }
259
+ updateDetail() {
260
+ let pane = this.detailEl;
261
+ if (!pane) return;
262
+ let item = this.bar.selectedItem(this.frame);
263
+ if (item === this.detailFor) return;
264
+ if (this.detailFor = item, !item?.detail) {
265
+ pane.innerHTML = item?.description ? renderMarkdown(item.description) : "";
266
+ return;
267
+ }
268
+ let value = detailCache.get(item);
269
+ if (value === void 0) {
270
+ let d = item.detail;
271
+ value = typeof d == "function" ? Promise.resolve(d()) : d, detailCache.set(item, value);
272
+ }
273
+ typeof value == "string" ? pane.innerHTML = renderMarkdown(value) : (pane.innerHTML = "", value.then(
274
+ (md) => {
275
+ detailCache.set(item, md), this.detailFor === item && (pane.innerHTML = renderMarkdown(md));
276
+ },
277
+ (err) => {
278
+ this.detailFor === item && (pane.textContent = String(err?.message ?? err));
279
+ }
280
+ ));
281
+ }
282
+ select(index, scroll = !0) {
283
+ let n = this.frame.itemRows.length;
284
+ n && (this.frame.selected = (index % n + n) % n, this.frame.selectedKey = this.frame.itemRows[this.frame.selected].key, this.frame.userMoved = !0, scroll && this.ensureVisible(), this.updateSelection(), this.bar.invalidate());
285
+ }
286
+ move(delta) {
287
+ let n = this.frame.itemRows.length;
288
+ if (!n) return;
289
+ let next = this.frame.selected + delta;
290
+ this.select(Math.abs(delta) === 1 ? next : Math.max(0, Math.min(n - 1, next)));
291
+ }
292
+ ensureVisible() {
293
+ let f = this.frame, row = f.itemRows[f.selected];
294
+ if (!row) return;
295
+ let rowIndex = f.rows.indexOf(row), prev = f.rows[rowIndex - 1], top, bottom;
296
+ if (this.virtual)
297
+ top = this.offsets[rowIndex], bottom = top + this.rowHeight, prev?.kind === "section" && (top = this.offsets[rowIndex - 1]);
298
+ else {
299
+ let el = this.cache.get(row.key)?.el;
300
+ if (!el) return;
301
+ if (top = el.offsetTop, bottom = top + el.offsetHeight, prev?.kind === "section") {
302
+ let sec = this.cache.get(prev.key)?.el;
303
+ sec && (top = sec.offsetTop);
304
+ }
305
+ }
306
+ let pad = 8, s = this.scroller;
307
+ f.selected === 0 ? s.scrollTop = 0 : top < s.scrollTop + pad ? s.scrollTop = top - pad : bottom > s.scrollTop + s.clientHeight - pad && (s.scrollTop = bottom - s.clientHeight + pad), this.virtual && this.renderWindow();
308
+ }
309
+ onKey(e) {
310
+ let k = e.key, mod = e.metaKey || e.ctrlKey;
311
+ if (k === "ArrowDown" && mod) return this.select(this.frame.itemRows.length - 1), !0;
312
+ if (k === "ArrowUp" && mod) return this.select(0), !0;
313
+ if (k === "ArrowDown" || e.ctrlKey && !e.metaKey && !e.altKey && (k === "n" || k === "j")) return this.move(1), !0;
314
+ if (k === "ArrowUp" || e.ctrlKey && !e.metaKey && !e.altKey && k === "p") return this.move(-1), !0;
315
+ if (k === "PageDown") return this.move(8), !0;
316
+ if (k === "PageUp") return this.move(-8), !0;
317
+ if (k === "Enter" && !mod && !e.altKey)
318
+ return this.bar.runPrimary(this.frame), !0;
319
+ if (k === "Tab" && !e.shiftKey && !mod && !e.altKey) {
320
+ let item = this.bar.selectedItem(this.frame);
321
+ if (item?.arguments?.length) {
322
+ let act = this.bar.actionsFor(item, this.frame)[0];
323
+ return act && this.bar.runAction(this.frame, item, act), !0;
324
+ }
325
+ return this.frame.view.type === "root" && this.bar.ai && this.bar.ask(this.frame.query), !0;
326
+ }
327
+ return !1;
328
+ }
329
+ scrollTop() {
330
+ return this.scroller.scrollTop;
331
+ }
332
+ restoreScroll(top) {
333
+ this.scroller.scrollTop = top, this.virtual && this.renderWindow();
334
+ }
335
+ resetScroll() {
336
+ this.scroller.scrollTop = 0;
337
+ }
338
+ destroy() {
339
+ cancelAnimationFrame(this.rafId);
340
+ }
341
+ };
342
+ function sameKeys(a, b) {
343
+ if (a.length !== b.length) return !1;
344
+ for (let i = 0; i < a.length; i++) if (a[i] !== b[i]) return !1;
345
+ return !0;
346
+ }
347
+ function bisect(offsets, y) {
348
+ let lo = 0, hi = offsets.length - 1;
349
+ for (; lo < hi; ) {
350
+ let mid = lo + hi + 1 >> 1;
351
+ offsets[mid] <= y ? lo = mid : hi = mid - 1;
352
+ }
353
+ return lo;
354
+ }
355
+ var GridRenderer = class extends ListRenderer {
356
+ constructor(bar, frame) {
357
+ super(bar, frame);
358
+ let v = frame.view;
359
+ this.scroller.className = bar.cls("qb-scroll qb-grid", "grid"), this.scroller.style.setProperty("--qb-columns", String(v.columns ?? 5)), v.aspectRatio && this.scroller.style.setProperty("--qb-aspect", v.aspectRatio), v.fit && this.scroller.style.setProperty("--qb-fit", v.fit), this.inner.style.display = "contents";
360
+ }
361
+ update() {
362
+ let rows = this.frame.rows.slice(0, 600), keys = rows.map((r) => r.key), els = rows.map((r) => this.rowEl(r));
363
+ sameKeys(keys, this.renderedKeys) || (this.inner.replaceChildren(...els), this.renderedKeys = keys), this.updateSelection(), this.updateEmpty();
364
+ }
365
+ itemEl(row) {
366
+ let { item } = row, media = h("div", { class: "qb-cell-media" });
367
+ if (item.image) media.append(h("img", { src: item.image, alt: "", loading: "lazy", decoding: "async", draggable: "false" }));
368
+ else {
369
+ let icon = renderIcon(item.icon, 28);
370
+ icon && media.append(icon);
371
+ }
372
+ return h(
373
+ "div",
374
+ { class: this.bar.cls("qb-cell", "item"), role: "option", id: optionId(this.bar, row.key), "aria-selected": "false", "data-index": String(row.index), title: item.title },
375
+ media,
376
+ h("div", { class: "qb-cell-title" }, highlight(item.title, row.positions)),
377
+ item.subtitle ? h("div", { class: "qb-cell-subtitle" }, item.subtitle) : null
378
+ );
379
+ }
380
+ ensureVisible() {
381
+ let row = this.frame.itemRows[this.frame.selected];
382
+ (row && this.cache.get(row.key)?.el)?.scrollIntoView({ block: "nearest" });
383
+ }
384
+ onKey(e) {
385
+ let cols = this.frame.view.columns ?? 5;
386
+ return e.key === "ArrowRight" && !e.metaKey && !e.ctrlKey ? (this.move(1), !0) : e.key === "ArrowLeft" && !e.metaKey && !e.ctrlKey ? (this.move(-1), !0) : e.key === "ArrowDown" && !e.metaKey && !e.ctrlKey ? (this.step(cols), !0) : e.key === "ArrowUp" && !e.metaKey && !e.ctrlKey ? (this.step(-cols), !0) : super.onKey(e);
387
+ }
388
+ step(delta) {
389
+ let n = this.frame.itemRows.length, next = this.frame.selected + delta;
390
+ next >= 0 && next < n && this.select(next);
391
+ }
392
+ }, DetailRenderer = class {
393
+ constructor(bar, frame) {
394
+ __publicField(this, "bar", bar);
395
+ __publicField(this, "frame", frame);
396
+ __publicField(this, "el");
397
+ __publicField(this, "hasInput", !1);
398
+ __publicField(this, "body");
399
+ __publicField(this, "rendered", "");
400
+ __publicField(this, "raf", 0);
401
+ let v = frame.view;
402
+ this.body = h("div", { class: bar.cls("qb-detail qb-md", "detail"), tabindex: "-1" });
403
+ let children = [this.body];
404
+ v.metadata?.length && children.push(
405
+ h(
406
+ "div",
407
+ { class: "qb-meta" },
408
+ ...v.metadata.map(
409
+ (m) => h(
410
+ "div",
411
+ null,
412
+ h("div", { class: "qb-meta-label" }, m.label),
413
+ h(
414
+ "div",
415
+ { class: "qb-meta-value" },
416
+ renderIcon(m.icon, 14),
417
+ m.tag ? renderTag(m.tag) : null,
418
+ m.href ? h("a", { href: m.href, target: /^https?:/.test(m.href) ? "_blank" : null, rel: "noopener" }, m.value ?? m.href) : m.value ?? null
419
+ )
420
+ )
421
+ )
422
+ )
423
+ ), this.el = h("div", { style: "display:flex;flex:1;min-width:0" }, ...children);
424
+ }
425
+ update() {
426
+ this.raf || (this.raf = requestAnimationFrame(() => {
427
+ this.raf = 0, this.render();
428
+ }));
429
+ }
430
+ render() {
431
+ let d = this.frame.detail;
432
+ if (!d) return;
433
+ let key = `${d.text.length}|${d.done}|${d.error ?? ""}`;
434
+ if (key === this.rendered) return;
435
+ this.rendered = key;
436
+ let stick = this.body.scrollTop + this.body.clientHeight >= this.body.scrollHeight - 24, html = renderMarkdown(d.text);
437
+ d.done || (html += '<span class="qb-caret"></span>'), d.error && (html += `<p class="qb-msg-error">${d.error.replace(/</g, "&lt;")}</p>`), this.body.innerHTML = html, stick && !d.done && (this.body.scrollTop = this.body.scrollHeight);
438
+ }
439
+ onKey(e) {
440
+ return e.key === "ArrowDown" ? (this.body.scrollTop += 40, !0) : e.key === "ArrowUp" ? (this.body.scrollTop -= 40, !0) : e.key === "Enter" && !e.metaKey && !e.ctrlKey ? (this.bar.runPrimary(this.frame), !0) : !1;
441
+ }
442
+ viewActions() {
443
+ let d = this.frame.detail;
444
+ return [
445
+ {
446
+ title: "Copy Content",
447
+ icon: "copy",
448
+ shortcut: "mod+shift+c",
449
+ keepOpen: !0,
450
+ run: async (ctx) => {
451
+ let ok = await ctx.copy(d?.text ?? "");
452
+ return ctx.toast({ title: ok ? "Copied to clipboard" : "Copy failed", style: ok ? "success" : "failure" }), !1;
453
+ }
454
+ }
455
+ ];
456
+ }
457
+ focusTarget() {
458
+ return this.body;
459
+ }
460
+ scrollTop() {
461
+ return this.body.scrollTop;
462
+ }
463
+ restoreScroll(top) {
464
+ this.body.scrollTop = top;
465
+ }
466
+ destroy() {
467
+ cancelAnimationFrame(this.raf);
468
+ }
469
+ }, FormRenderer = class {
470
+ constructor(bar, frame) {
471
+ __publicField(this, "bar", bar);
472
+ __publicField(this, "frame", frame);
473
+ __publicField(this, "el");
474
+ __publicField(this, "hasInput", !1);
475
+ __publicField(this, "inputs", /* @__PURE__ */ new Map());
476
+ __publicField(this, "errors", /* @__PURE__ */ new Map());
477
+ let v = frame.view, children = [];
478
+ for (let field of v.fields) {
479
+ let id = `${bar.instanceId}-f-${field.name}`, label = h("label", { class: "qb-form-label", for: id, "data-required": field.required ? "" : null }, field.type === "checkbox" ? "" : field.label ?? field.name), control = this.control(field, id), error = h("div", { class: "qb-field-error", hidden: !0, id: `${id}-err` });
480
+ this.errors.set(field.name, error), children.push(label, h("div", { class: "qb-field" }, control, field.description ? h("div", { class: "qb-field-desc" }, field.description) : null, error));
481
+ }
482
+ this.el = h("form", { class: bar.cls("qb-form", "form"), novalidate: !0 }, ...children), this.el.addEventListener("submit", (e) => {
483
+ e.preventDefault(), this.submit();
484
+ });
485
+ }
486
+ control(field, id) {
487
+ let values = this.frame.form.values, set = (value) => {
488
+ values[field.name] = value, this.frame.form.errors[field.name] && (delete this.frame.form.errors[field.name], this.showErrors());
489
+ }, el;
490
+ if (field.type === "checkbox") {
491
+ let input = h("input", { type: "checkbox", id, checked: !!values[field.name] });
492
+ return input.addEventListener("change", () => set(input.checked)), this.inputs.set(field.name, input), h("label", { class: "qb-field-check" }, input, h("span", null, field.label ?? field.name));
493
+ }
494
+ if (field.type === "select") {
495
+ let select = h("select", { class: "qb-field-input", id }, ...(field.options ?? []).map((o) => h("option", { value: o.value }, o.title)));
496
+ select.value = String(values[field.name] ?? ""), select.addEventListener("change", () => set(select.value)), el = select;
497
+ } else if (field.type === "textarea") {
498
+ let ta = h("textarea", { class: "qb-field-input", id, placeholder: field.placeholder ?? "", rows: 4 });
499
+ ta.value = String(values[field.name] ?? ""), ta.addEventListener("input", () => set(ta.value)), el = ta;
500
+ } else {
501
+ let input = h("input", {
502
+ class: "qb-field-input",
503
+ id,
504
+ type: field.type ?? "text",
505
+ placeholder: field.placeholder ?? "",
506
+ autocomplete: field.type === "password" ? "off" : "on",
507
+ spellcheck: "false"
508
+ });
509
+ input.value = String(values[field.name] ?? ""), input.addEventListener("input", () => set(field.type === "number" ? input.value === "" ? "" : Number(input.value) : input.value)), el = input;
510
+ }
511
+ return el.setAttribute("aria-describedby", `${id}-err`), this.inputs.set(field.name, el), el;
512
+ }
513
+ showErrors() {
514
+ let errs = this.frame.form.errors;
515
+ for (let [name, el] of this.errors) {
516
+ let msg = errs[name];
517
+ el.hidden = !msg, el.textContent = msg ?? "", this.inputs.get(name)?.setAttribute("aria-invalid", msg ? "true" : "false");
518
+ }
519
+ }
520
+ submit() {
521
+ let v = this.frame.view, form = this.frame.form;
522
+ form.errors = {};
523
+ for (let f of v.fields) {
524
+ let value = form.values[f.name];
525
+ if (f.required && (value === "" || value == null || value === !1)) form.errors[f.name] = `${f.label ?? f.name} is required`;
526
+ else {
527
+ let msg = f.validate?.(value, form.values);
528
+ msg && (form.errors[f.name] = msg);
529
+ }
530
+ }
531
+ this.showErrors();
532
+ let first = Object.keys(form.errors)[0];
533
+ if (first) {
534
+ this.inputs.get(first)?.focus();
535
+ return;
536
+ }
537
+ this.bar.runAction(this.frame, void 0, {
538
+ title: v.submitLabel ?? "Submit",
539
+ run: (ctx) => v.onSubmit({ ...form.values }, ctx)
540
+ });
541
+ }
542
+ update() {
543
+ }
544
+ onKey(e) {
545
+ if (e.key === "Enter" && (e.metaKey || e.ctrlKey))
546
+ return this.submit(), !0;
547
+ let t = e.target;
548
+ return e.key === "Enter" && t.tagName === "INPUT" && t.type !== "checkbox" ? (this.submit(), !0) : !1;
549
+ }
550
+ footerPrimary() {
551
+ return { title: this.frame.view.submitLabel ?? "Submit", hotkey: "mod+enter", run: () => this.submit() };
552
+ }
553
+ focusTarget() {
554
+ return this.el.contains(document.activeElement) ? document.activeElement : this.el.querySelector("input,textarea,select") ?? this.el;
555
+ }
556
+ scrollTop() {
557
+ return this.el.scrollTop;
558
+ }
559
+ restoreScroll(top) {
560
+ this.el.scrollTop = top;
561
+ }
562
+ destroy() {
563
+ }
564
+ }, ChatRenderer = class {
565
+ constructor(bar, frame) {
566
+ __publicField(this, "bar", bar);
567
+ __publicField(this, "frame", frame);
568
+ __publicField(this, "el");
569
+ __publicField(this, "hasInput", !0);
570
+ __publicField(this, "turnEls", []);
571
+ __publicField(this, "emptyEl");
572
+ __publicField(this, "raf", 0);
573
+ this.el = h("div", { class: bar.cls("qb-chat", "chat"), role: "log", "aria-live": "polite", tabindex: "-1" });
574
+ }
575
+ update() {
576
+ this.raf || (this.raf = requestAnimationFrame(() => {
577
+ this.raf = 0, this.render();
578
+ }));
579
+ }
580
+ render() {
581
+ let turns = this.frame.chat?.turns ?? [];
582
+ if (!turns.length) {
583
+ this.emptyEl || (this.emptyEl = this.empty(), this.el.replaceChildren(this.emptyEl));
584
+ return;
585
+ }
586
+ this.emptyEl && (this.emptyEl.remove(), this.emptyEl = void 0);
587
+ let stick = this.el.scrollTop + this.el.clientHeight >= this.el.scrollHeight - 40;
588
+ turns.forEach((turn, i) => {
589
+ let sig = `${turn.text.length}|${turn.streaming}|${turn.error ?? ""}|${turn.tools.map((t) => t.state).join()}`, existing = this.turnEls[i];
590
+ if (existing && existing.sig === sig) return;
591
+ let el;
592
+ if (turn.role === "user") el = h("div", { class: "qb-msg-user" }, turn.text);
593
+ else {
594
+ let head = h("div", { class: "qb-msg-head" }, renderIcon("sparkles", 13), this.bar.aiName), tools = turn.tools.length ? h(
595
+ "div",
596
+ { class: "qb-tools" },
597
+ ...turn.tools.map((t) => {
598
+ let icon = renderIcon(t.state === "running" ? "loader" : t.state === "done" ? "check" : "x", 12);
599
+ return t.state === "running" && icon.classList.add("qb-spin"), h("span", { class: "qb-tool", "data-state": t.state }, icon, t.label);
600
+ })
601
+ ) : null, md = h("div", { class: "qb-md" }), html = renderMarkdown(turn.text);
602
+ turn.streaming && (html += turn.text || !turn.tools.length ? '<span class="qb-caret"></span>' : ""), md.innerHTML = html, el = h("div", { class: "qb-msg-ai" }, head, tools, md, turn.error ? h("div", { class: "qb-msg-error" }, turn.error) : null);
603
+ }
604
+ existing ? existing.el.replaceWith(el) : this.el.append(el), this.turnEls[i] = { el, sig };
605
+ }), stick && (this.el.scrollTop = this.el.scrollHeight);
606
+ }
607
+ empty() {
608
+ let suggestions = this.bar.aiOptions?.suggestions ?? [], defaults = suggestions.length ? suggestions : ["What can I do here?", "Summarize this page"];
609
+ return h(
610
+ "div",
611
+ { class: "qb-chat-empty" },
612
+ renderIcon("sparkles", 26),
613
+ h("div", { class: "qb-empty-title" }, `Ask ${this.bar.aiName} anything`),
614
+ h("div", { class: "qb-empty-desc" }, "Ask a question or tell it what to do, like \u201Ctake me to billing\u201D."),
615
+ h(
616
+ "div",
617
+ { class: "qb-suggestions" },
618
+ ...defaults.map((s) => {
619
+ let b = h("button", { class: "qb-suggestion", type: "button" }, s);
620
+ return b.addEventListener("click", () => this.bar.sendChat(this.frame, s)), b;
621
+ })
622
+ )
623
+ );
624
+ }
625
+ lastAnswer() {
626
+ let turns = this.frame.chat?.turns ?? [];
627
+ for (let i = turns.length - 1; i >= 0; i--) if (turns[i].role === "assistant" && turns[i].text) return turns[i].text;
628
+ return "";
629
+ }
630
+ onKey(e) {
631
+ if (e.key === "Enter" && !e.shiftKey && !e.metaKey && !e.ctrlKey && !e.altKey) {
632
+ let q = this.frame.query.trim();
633
+ return q && this.bar.sendChat(this.frame, q), !0;
634
+ }
635
+ return e.key === "ArrowUp" && !this.frame.query ? (this.el.scrollTop -= 60, !0) : e.key === "ArrowDown" && !this.frame.query ? (this.el.scrollTop += 60, !0) : !1;
636
+ }
637
+ placeholder() {
638
+ return this.frame.chat?.turns.length ?? 0 ? "Ask a follow-up\u2026" : `Ask ${this.bar.aiName} anything\u2026`;
639
+ }
640
+ footerPrimary() {
641
+ return this.frame.chat?.controller ? { title: "Stop", hotkey: "escape", run: () => {
642
+ this.bar.stopChat(this.frame);
643
+ } } : { title: "Send", hotkey: "enter", run: () => this.bar.sendChat(this.frame, this.frame.query) };
644
+ }
645
+ viewActions() {
646
+ let view = this.frame.view;
647
+ return [
648
+ {
649
+ title: "Copy Answer",
650
+ icon: "copy",
651
+ shortcut: "mod+shift+c",
652
+ keepOpen: !0,
653
+ run: async (ctx) => {
654
+ let ok = await copyText(this.lastAnswer());
655
+ return ctx.toast({ title: ok ? "Copied answer" : "Nothing to copy", style: ok ? "success" : "failure" }), !1;
656
+ }
657
+ },
658
+ {
659
+ title: "New Chat",
660
+ icon: "plus",
661
+ shortcut: "mod+shift+o",
662
+ run: (ctx) => (ctx.render({ ...view, type: "chat", prompt: void 0 }), !1)
663
+ }
664
+ ];
665
+ }
666
+ scrollTop() {
667
+ return this.el.scrollTop;
668
+ }
669
+ restoreScroll(top) {
670
+ this.el.scrollTop = top;
671
+ }
672
+ destroy() {
673
+ cancelAnimationFrame(this.raf);
674
+ }
675
+ };
676
+
677
+ // src/ui/bar.ts
678
+ var VIEW_TYPES = /* @__PURE__ */ new Set(["list", "grid", "detail", "form", "chat"]), isView = (x) => !!x && typeof x == "object" && VIEW_TYPES.has(x.type), DEFAULT_LINKS = "nav a[href], header a[href], aside a[href], [data-qikbar-index] a[href]", DEFAULT_ACTIONS_HOTKEY = "mod+.", toolName = (s) => s.replace(/[^a-zA-Z0-9_-]/g, "_").slice(0, 64), frameCounter = 0, Bar = class {
679
+ constructor(config = {}) {
680
+ __publicField(this, "config");
681
+ __publicField(this, "instanceId", uid("qikbar"));
682
+ __publicField(this, "storageAdapter");
683
+ __publicField(this, "storage");
684
+ __publicField(this, "frecency");
685
+ __publicField(this, "registrations", /* @__PURE__ */ new Map());
686
+ __publicField(this, "regCounter", 0);
687
+ __publicField(this, "sources", /* @__PURE__ */ new Set());
688
+ __publicField(this, "sourceExt", /* @__PURE__ */ new WeakMap());
689
+ __publicField(this, "itemExt", /* @__PURE__ */ new WeakMap());
690
+ __publicField(this, "extensions", /* @__PURE__ */ new Map());
691
+ __publicField(this, "configExtensions", []);
692
+ __publicField(this, "configSources", []);
693
+ __publicField(this, "ids", /* @__PURE__ */ new WeakMap());
694
+ __publicField(this, "listeners", /* @__PURE__ */ new Map());
695
+ __publicField(this, "stack", []);
696
+ __publicField(this, "_open", !1);
697
+ __publicField(this, "rootCache", null);
698
+ __publicField(this, "routeItems", []);
699
+ __publicField(this, "autoItems", []);
700
+ __publicField(this, "shortcutItems", []);
701
+ __publicField(this, "aiOptions");
702
+ __publicField(this, "ai");
703
+ __publicField(this, "dom");
704
+ __publicField(this, "renderer");
705
+ __publicField(this, "panel");
706
+ __publicField(this, "toastState");
707
+ __publicField(this, "toastTimer");
708
+ __publicField(this, "toastId", 0);
709
+ __publicField(this, "hud");
710
+ __publicField(this, "confirmState");
711
+ __publicField(this, "argMode");
712
+ __publicField(this, "seq", new SequenceMatcher());
713
+ __publicField(this, "prevFocus", null);
714
+ __publicField(this, "teardown", []);
715
+ __publicField(this, "appliedVars", []);
716
+ __publicField(this, "scheduled", !1);
717
+ __publicField(this, "scrollLock");
718
+ __publicField(this, "closeTimer");
719
+ __publicField(this, "destroyed", !1);
720
+ __publicField(this, "styleEl");
721
+ // ─── Keyboard ────────────────────────────────────────────────────────────
722
+ __publicField(this, "onGlobalKeyDown", (e) => {
723
+ if (this.destroyed || e.defaultPrevented || e.isComposing) return;
724
+ let hotkeys = this.config.hotkey === !1 ? [] : [].concat(this.config.hotkey ?? "mod+k"), inField = isEditable(e.target);
725
+ if (hotkeys.some((hk) => matchesHotkey(e, hk) && (!inField || allowedInInput(hk)))) {
726
+ e.preventDefault(), e.stopPropagation(), this.isInline ? (this.open(), this.focusInput()) : this.toggle();
727
+ return;
728
+ }
729
+ if (this._open && !this.isInline || this.isInline && this.dom?.root.contains(e.target) || this.config.shortcuts === !1 || (this.rootItems(), !this.shortcutItems.length)) return;
730
+ let candidates = this.shortcutItems.map((i) => i.shortcut).filter((s) => !inField || allowedInInput(s)), matched = this.seq.feed(e, candidates);
731
+ if (!matched.length) return;
732
+ let item = this.shortcutItems.find((i) => i.shortcut === matched[0]);
733
+ if (!item) return;
734
+ e.preventDefault();
735
+ let frame = this.createFrame({ type: "root" }), act = this.actionsFor(item, frame)[0];
736
+ act && this.runAction(frame, item, act);
737
+ });
738
+ __publicField(this, "onGlobalClick", (e) => {
739
+ let trigger = e.target?.closest?.("[data-qikbar-open]");
740
+ if (!trigger || this.destroyed) return;
741
+ let target = trigger.getAttribute("data-qikbar-open");
742
+ (target ? target !== this.instanceId && target !== this.config.namespace : this.isInline) || (e.preventDefault(), this.open({ query: trigger.getAttribute("data-qikbar-query") ?? void 0 }));
743
+ });
744
+ __publicField(this, "onDialogKeyDown", (e) => {
745
+ if (e.stopPropagation(), e.isComposing || e.keyCode === 229) return;
746
+ let frame = this.top;
747
+ if (!frame) return;
748
+ if (this.confirmState) {
749
+ if (e.key === "Escape")
750
+ e.preventDefault(), this.confirmState.resolve(!1);
751
+ else if (e.key === "Tab") {
752
+ let buttons = [...this.dom?.layer.querySelectorAll("button") ?? []], i = buttons.indexOf(document.activeElement);
753
+ e.preventDefault(), buttons[(i + (e.shiftKey ? -1 : 1) + buttons.length) % buttons.length]?.focus();
754
+ }
755
+ e.stopPropagation();
756
+ return;
757
+ }
758
+ if (this.panel) {
759
+ this.onPanelKey(e) && (e.preventDefault(), e.stopPropagation());
760
+ return;
761
+ }
762
+ if (this.argMode) {
763
+ if (e.key === "Escape") {
764
+ e.preventDefault(), e.stopPropagation(), this.argMode = void 0, this.flush(), this.focusInput();
765
+ return;
766
+ }
767
+ if (e.key === "Enter") {
768
+ e.preventDefault(), this.submitArgs();
769
+ return;
770
+ }
771
+ return;
772
+ }
773
+ if (e.key === "Escape") {
774
+ e.preventDefault(), e.stopPropagation(), this.escape();
775
+ return;
776
+ }
777
+ if (matchesHotkey(e, this.actionsHotkey)) {
778
+ e.preventDefault(), this.openPanel();
779
+ return;
780
+ }
781
+ if (this.renderer?.onKey(e)) {
782
+ e.preventDefault();
783
+ return;
784
+ }
785
+ let actions = this.actionsFor(this.selectedItem(frame), frame);
786
+ if (e.key === "Enter" && (e.metaKey || e.ctrlKey) && !e.shiftKey && !e.altKey && frame.view.type !== "form") {
787
+ let second = actions[1];
788
+ if (second && !second.shortcut) {
789
+ e.preventDefault(), this.runAction(frame, this.selectedItem(frame), second);
790
+ return;
791
+ }
792
+ }
793
+ for (let act of actions)
794
+ if (act.shortcut && matchesHotkey(e, act.shortcut)) {
795
+ e.preventDefault(), this.runAction(frame, this.selectedItem(frame), act);
796
+ return;
797
+ }
798
+ e.key === "Backspace" && this.stack.length > 1 && e.target === this.dom?.input && !this.dom.input.value && !e.repeat && (e.preventDefault(), this.pop());
799
+ });
800
+ if (this.config = { ...config }, this.storageAdapter = config.storage ?? defaultStorage(), this.storage = scopedStorage(this.storageAdapter, config.namespace ?? "qikbar"), this.frecency = new Frecency(this.storage), this.applyConfig(config, !0), !(typeof document > "u") && (this.listen(document, "keydown", this.onGlobalKeyDown, !0), this.listen(document, "click", this.onGlobalClick, !0), this.inlineTarget())) {
801
+ let start = () => this.open({ focus: !1 });
802
+ document.readyState === "loading" ? this.listen(document, "DOMContentLoaded", start) : start();
803
+ }
804
+ }
805
+ // ─── Public API ──────────────────────────────────────────────────────────
806
+ get isOpen() {
807
+ return this._open;
808
+ }
809
+ get query() {
810
+ return this.top?.query ?? "";
811
+ }
812
+ get top() {
813
+ return this.stack[this.stack.length - 1];
814
+ }
815
+ get isInline() {
816
+ return !!this.config.inline;
817
+ }
818
+ get aiName() {
819
+ return this.aiOptions?.name ?? "AI";
820
+ }
821
+ get actionsHotkey() {
822
+ return this.config.actionsHotkey ?? DEFAULT_ACTIONS_HOTKEY;
823
+ }
824
+ open(options = {}) {
825
+ if (this.destroyed || typeof document > "u") return;
826
+ if (this.mount(), clearTimeout(this.closeTimer), !this._open) {
827
+ this._open = !0, this.prevFocus = document.activeElement, this.rootCache = null, this.autoIndex(), this.resetToRoot(), this.applyTheme();
828
+ let dom = this.dom;
829
+ dom.root.dataset.qbState = "open", dom.overlay.hidden = this.isInline, dom.dialog.hidden = !1, this.isInline || this.lockScroll(), this.emit("open", void 0), this.config.onOpen?.();
830
+ }
831
+ options.view && this.push(options.view), options.query != null && this.setQuery(options.query), this.flush(), options.focus !== !1 && this.focusInput(), this.emitChange();
832
+ }
833
+ close() {
834
+ if (!this._open || !this.dom) return;
835
+ if (this.closePanel(), this.confirmState?.resolve(!1), this.confirmState = void 0, this.argMode = void 0, this.isInline) {
836
+ this.resetToRoot(), this.flush(), document.activeElement?.blur?.(), this.emitChange();
837
+ return;
838
+ }
839
+ this._open = !1;
840
+ let dom = this.dom;
841
+ dom.root.dataset.qbState = "closing";
842
+ let finish = () => {
843
+ if (!this._open) {
844
+ dom.root.dataset.qbState = "closed", dom.dialog.hidden = !0, dom.overlay.hidden = !0, this.renderer?.destroy(), this.renderer = void 0, dom.body.replaceChildren();
845
+ for (let f of this.stack) this.destroyFrame(f);
846
+ this.stack = [];
847
+ }
848
+ };
849
+ typeof matchMedia < "u" && matchMedia("(prefers-reduced-motion: reduce)").matches ? finish() : this.closeTimer = setTimeout(finish, 120), this.unlockScroll();
850
+ let prev = this.prevFocus;
851
+ prev && typeof prev.focus == "function" && document.contains(prev) && prev.focus({ preventScroll: !0 }), this.toastState && this.renderToast(), this.emit("close", void 0), this.config.onClose?.(), this.emitChange();
852
+ }
853
+ toggle() {
854
+ this._open && !this.isInline ? this.close() : this.open();
855
+ }
856
+ register(commands) {
857
+ let id = ++this.regCounter;
858
+ return this.registrations.set(id, Array.isArray(commands) ? commands : [commands]), this.invalidateRoot(), () => {
859
+ this.registrations.delete(id), this.invalidateRoot();
860
+ };
861
+ }
862
+ addSource(source) {
863
+ return this.sources.add(source), () => {
864
+ this.sources.delete(source);
865
+ for (let f of this.stack) f.sourceResults?.delete(source.id);
866
+ this.invalidate();
867
+ };
868
+ }
869
+ use(ext, provided = {}) {
870
+ this.extensions.get(ext.name)?.cleanup?.();
871
+ let storage = scopedStorage(this.storageAdapter, `${this.config.namespace ?? "qikbar"}:ext:${ext.name}`), rt = {
872
+ ext,
873
+ provided,
874
+ storage,
875
+ prefs: () => {
876
+ let stored = storage.get("preferences") ?? {}, out = {};
877
+ for (let p of ext.preferences ?? []) p.default !== void 0 && (out[p.name] = p.default);
878
+ return { ...out, ...stored, ...provided };
879
+ },
880
+ missing: () => {
881
+ let values = rt.prefs();
882
+ return (ext.preferences ?? []).filter((p) => p.required && (values[p.name] === void 0 || values[p.name] === ""));
883
+ }
884
+ }, items = (ext.commands ?? []).map((cmd) => {
885
+ let { name, ...rest } = cmd, item = { section: ext.title, icon: ext.icon, ...rest, id: `${ext.name}.${name}` };
886
+ return this.itemExt.set(item, rt), item;
887
+ }), removeSources = (ext.sources ?? []).map((s) => (this.sourceExt.set(s, rt), this.addSource(s))), setupCleanup;
888
+ try {
889
+ setupCleanup = ext.setup?.({ bar: this, preferences: rt.prefs(), storage });
890
+ } catch (err) {
891
+ console.error(`[qikbar] extension "${ext.name}" setup failed`, err);
892
+ }
893
+ let disposed = !1, entry = {
894
+ rt,
895
+ items,
896
+ cleanup: () => {
897
+ disposed || (disposed = !0, removeSources.forEach((r) => r()), typeof setupCleanup == "function" && setupCleanup(), this.extensions.get(ext.name) === entry && this.extensions.delete(ext.name), this.invalidateRoot());
898
+ }
899
+ };
900
+ return this.extensions.set(ext.name, entry), this.invalidateRoot(), entry.cleanup;
901
+ }
902
+ configure(partial) {
903
+ let prev = this.config;
904
+ this.config = { ...this.config, ...partial }, this.applyConfig(partial, !1, prev), this.dom && (("theme" in partial || "appearance" in partial) && this.applyTheme(), "classNames" in partial && this.applyClassNames(), "dir" in partial && (this.dom.root.dir = this.config.dir ?? "")), this.invalidateRoot();
905
+ }
906
+ push(view, ext) {
907
+ if (!this._open && (this.open(), !this._open))
908
+ return;
909
+ let top = this.top;
910
+ top && this.renderer && (top.scrollTop = this.renderer.scrollTop());
911
+ let frame = this.createFrame(view, ext ?? top?.ext);
912
+ this.stack.push(frame), this.closePanel(), this.argMode = void 0, this.startFrame(frame), this.flush(), this.focusInput(), this.emitChange();
913
+ }
914
+ pop() {
915
+ if (this.stack.length <= 1) return;
916
+ let frame = this.stack.pop();
917
+ this.destroyFrame(frame), this.closePanel(), this.argMode = void 0, this.flush(), this.focusInput(), this.emitChange();
918
+ }
919
+ setQuery(query) {
920
+ let frame = this.top;
921
+ frame && (this.dom && (this.dom.input.value = query), this.onQueryChange(frame, query));
922
+ }
923
+ ask(prompt) {
924
+ if (!this.ai) {
925
+ this.toast({ style: "failure", title: "AI is not configured", message: "Pass `ai` to createQikbar()." });
926
+ return;
927
+ }
928
+ this.push({ type: "chat", prompt: prompt?.trim() || void 0 });
929
+ }
930
+ commands() {
931
+ return this.rootItems();
932
+ }
933
+ on(event, handler) {
934
+ let set = this.listeners.get(event);
935
+ return set || this.listeners.set(event, set = /* @__PURE__ */ new Set()), set.add(handler), () => set.delete(handler);
936
+ }
937
+ preload() {
938
+ return Promise.resolve();
939
+ }
940
+ destroy() {
941
+ this.destroyed = !0, this._open && !this.isInline && this.unlockScroll(), this._open = !1;
942
+ for (let f of this.stack) this.destroyFrame(f);
943
+ this.stack = [];
944
+ for (let e of this.extensions.values()) e.cleanup?.();
945
+ for (let fn of this.teardown) fn();
946
+ this.teardown = [], this.dom?.root.remove(), this.hud?.remove(), this.dom = void 0, this.listeners.clear();
947
+ }
948
+ // ─── Config ──────────────────────────────────────────────────────────────
949
+ applyConfig(partial, initial, prev) {
950
+ if (("routes" in partial || initial) && (this.routeItems = (this.config.routes ?? []).map((r) => ({
951
+ id: `route:${r.path}`,
952
+ title: r.title,
953
+ subtitle: r.subtitle,
954
+ icon: r.icon ?? "arrow-right",
955
+ keywords: [...r.keywords ?? [], r.path],
956
+ section: r.section ?? "Navigation",
957
+ href: r.path,
958
+ shortcut: r.shortcut
959
+ }))), ("sources" in partial || initial) && (initial || prev?.sources !== this.config.sources)) {
960
+ for (let remove of this.configSources) remove();
961
+ this.configSources = (this.config.sources ?? []).map((src) => this.addSource(src));
962
+ }
963
+ if ("ai" in partial || initial) {
964
+ let ai = this.config.ai;
965
+ this.aiOptions = ai ? "stream" in ai ? { provider: ai } : ai : void 0, this.ai = this.aiOptions ? createAIClient(this.aiOptions.provider, this.aiOptions.system) : void 0;
966
+ }
967
+ if ("extensions" in partial || initial) {
968
+ let next = (this.config.extensions ?? []).map((e) => Array.isArray(e) ? { ext: e[0], prefs: e[1] } : { ext: e, prefs: void 0 }), sameRef = !initial && prev?.extensions === this.config.extensions, sameContent = next.length === this.configExtensions.length && next.every((n, i) => n.ext === this.configExtensions[i].ext && shallowEqual(n.prefs, this.configExtensions[i].prefs));
969
+ if (!sameRef && !sameContent) {
970
+ for (let e of this.configExtensions) e.uninstall();
971
+ this.configExtensions = next.map((n) => ({ ...n, uninstall: this.use(n.ext, n.prefs) }));
972
+ }
973
+ }
974
+ }
975
+ inlineTarget() {
976
+ let t = this.config.inline;
977
+ return !t || typeof document > "u" ? null : typeof t == "string" ? document.querySelector(t) : t;
978
+ }
979
+ // ─── Events ──────────────────────────────────────────────────────────────
980
+ emit(event, payload) {
981
+ this.listeners.get(event)?.forEach((fn) => {
982
+ try {
983
+ fn(payload);
984
+ } catch (err) {
985
+ console.error(err);
986
+ }
987
+ });
988
+ }
989
+ emitChange() {
990
+ let state = { open: this._open, query: this.query, depth: this.stack.length, loading: !!this.top?.loading };
991
+ this.emit("change", state);
992
+ }
993
+ listen(target, type, fn, capture = !1) {
994
+ target.addEventListener(type, fn, capture), this.teardown.push(() => target.removeEventListener(type, fn, capture));
995
+ }
996
+ // ─── Root items ──────────────────────────────────────────────────────────
997
+ idOf(item) {
998
+ return item.id ?? this.ids.get(item) ?? item.title;
999
+ }
1000
+ invalidateRoot() {
1001
+ if (this.rootCache = null, this._open) {
1002
+ for (let f of this.stack) f.view.type === "root" && this.computeRows(f);
1003
+ this.invalidate();
1004
+ }
1005
+ }
1006
+ rootItems() {
1007
+ if (this.rootCache) return this.rootCache;
1008
+ let out = [], seen = /* @__PURE__ */ new Set(), add = (item, prefix) => {
1009
+ try {
1010
+ if (item.when && !item.when()) return;
1011
+ } catch {
1012
+ return;
1013
+ }
1014
+ let id = item.id ?? `${prefix}:${item.section ?? ""}:${item.title}`;
1015
+ for (; seen.has(id); ) id += "'";
1016
+ seen.add(id), this.ids.set(item, id), out.push(item);
1017
+ };
1018
+ for (let c of this.config.commands ?? []) add(c, "cmd");
1019
+ for (let c of this.routeItems) add(c, "route");
1020
+ for (let list of this.registrations.values()) for (let c of list) add(c, "reg");
1021
+ for (let e of this.extensions.values()) for (let c of e.items) add(c, "ext");
1022
+ for (let c of this.autoItems) add(c, "auto");
1023
+ return this.ai && this.aiOptions?.fallback !== !1 && add(
1024
+ {
1025
+ id: "qikbar.ask-ai",
1026
+ title: `Ask ${this.aiName}`,
1027
+ subtitle: "Chat, or tell it what to do",
1028
+ icon: "sparkles",
1029
+ section: "AI",
1030
+ keywords: ["chat", "assistant", "ai", "help"],
1031
+ searchOnly: !0,
1032
+ view: { type: "chat" }
1033
+ },
1034
+ "qb"
1035
+ ), this.rootCache = out, this.shortcutItems = out.filter((i) => i.shortcut), out;
1036
+ }
1037
+ autoIndex() {
1038
+ let opt = this.config.autoIndex;
1039
+ if (!opt || typeof document > "u") {
1040
+ this.autoItems.length && (this.autoItems = [], this.rootCache = null);
1041
+ return;
1042
+ }
1043
+ let o = opt === !0 ? {} : opt, items = [], seen = /* @__PURE__ */ new Set();
1044
+ if (o.links !== !1)
1045
+ for (let a of document.querySelectorAll(o.links ?? DEFAULT_LINKS)) {
1046
+ if (a.closest(".qb-root") || a.closest("[data-qikbar-ignore]")) continue;
1047
+ let raw = a.getAttribute("href") ?? "";
1048
+ if (!raw || raw.startsWith("#") && !raw.startsWith("#/") || /^(javascript|mailto|tel):/i.test(raw)) continue;
1049
+ let title = (a.getAttribute("aria-label") || a.textContent || a.title || "").replace(/\s+/g, " ").trim().slice(0, 80);
1050
+ if (!title) continue;
1051
+ let external = a.host !== location.host, href = external ? a.href : raw.startsWith("#") ? raw : a.pathname + a.search + a.hash;
1052
+ if (seen.has(href)) continue;
1053
+ seen.add(href);
1054
+ let sectionEl = a.closest("[data-qikbar-section],nav[aria-label],aside[aria-label]");
1055
+ items.push({
1056
+ id: `auto:${href}`,
1057
+ title,
1058
+ subtitle: external ? a.host : raw.startsWith("#") ? raw : a.pathname,
1059
+ section: sectionEl?.dataset.qikbarSection ?? sectionEl?.getAttribute("aria-label") ?? o.section ?? "Pages",
1060
+ icon: external ? "globe" : "file",
1061
+ keywords: [href],
1062
+ ...external ? { url: href } : { href }
1063
+ });
1064
+ }
1065
+ if (o.elements !== !1)
1066
+ for (let el of document.querySelectorAll("[data-qikbar]")) {
1067
+ if (el.closest(".qb-root")) continue;
1068
+ let title = (el.dataset.qikbar || el.getAttribute("aria-label") || el.textContent || "").replace(/\s+/g, " ").trim().slice(0, 80);
1069
+ title && items.push({
1070
+ id: `el:${el.id || title}`,
1071
+ title,
1072
+ subtitle: el.dataset.qikbarSubtitle,
1073
+ keywords: el.dataset.qikbarKeywords?.split(",").map((k) => k.trim()),
1074
+ section: el.dataset.qikbarSection ?? "Actions",
1075
+ icon: el.dataset.qikbarIcon ?? "zap",
1076
+ shortcut: el.dataset.qikbarShortcut,
1077
+ run: () => {
1078
+ el.click();
1079
+ }
1080
+ });
1081
+ }
1082
+ this.autoItems = items, this.rootCache = null;
1083
+ }
1084
+ // ─── Frames ──────────────────────────────────────────────────────────────
1085
+ createFrame(view, ext, args) {
1086
+ return {
1087
+ id: ++frameCounter,
1088
+ view,
1089
+ query: ("query" in view && typeof view.query == "string" ? view.query : "") || "",
1090
+ selected: 0,
1091
+ rows: [],
1092
+ itemRows: [],
1093
+ loading: 0,
1094
+ controller: new AbortController(),
1095
+ ext,
1096
+ args
1097
+ };
1098
+ }
1099
+ resetToRoot() {
1100
+ for (let f of this.stack) this.destroyFrame(f);
1101
+ let root = this.createFrame({ type: "root" });
1102
+ root.sourceResults = /* @__PURE__ */ new Map(), this.stack = [root], this.renderer?.destroy(), this.renderer = void 0, this.dom && (this.dom.input.value = ""), this.computeRows(root);
1103
+ }
1104
+ destroyFrame(frame) {
1105
+ frame.controller.abort(), frame.queryController?.abort(), frame.chat?.controller?.abort();
1106
+ try {
1107
+ frame.view.onClose?.();
1108
+ } catch (err) {
1109
+ console.error(err);
1110
+ }
1111
+ }
1112
+ /** Start async work for a freshly pushed frame. */
1113
+ startFrame(frame) {
1114
+ let v = frame.view;
1115
+ if (v.type === "list" || v.type === "grid")
1116
+ typeof v.items == "function" && this.loadItems(frame, !0), this.computeRows(frame);
1117
+ else if (v.type === "detail")
1118
+ this.loadDetail(frame, v);
1119
+ else if (v.type === "form") {
1120
+ let values = {};
1121
+ for (let f of v.fields) values[f.name] = f.defaultValue ?? (f.type === "checkbox" ? !1 : f.type === "select" ? f.options?.[0]?.value ?? "" : "");
1122
+ frame.form = { values, errors: {} };
1123
+ } else v.type === "chat" && (frame.chat = { messages: [], turns: [] }, v.prompt && queueMicrotask(() => this.sendChat(frame, v.prompt)));
1124
+ }
1125
+ replaceFrame(frame, view) {
1126
+ let index = this.stack.indexOf(frame);
1127
+ if (index < 0) return;
1128
+ let next = this.createFrame(view, frame.ext, frame.args);
1129
+ view.type === frame.view.type && !("query" in view && view.query != null) && (next.query = frame.query), frame === this.top && this.renderer && (next.scrollTop = this.renderer.scrollTop()), next.selectedKey = frame.itemRows[frame.selected]?.key, next.userMoved = !!next.selectedKey, this.destroyFrame(frame), this.stack[index] = next, this.startFrame(next), this.invalidate();
1130
+ }
1131
+ // ─── Rows ────────────────────────────────────────────────────────────────
1132
+ computeRows(frame) {
1133
+ let v = frame.view, groups;
1134
+ v.type === "root" ? groups = this.rootGroups(frame) : v.type === "list" || v.type === "grid" ? groups = this.listGroups(frame, v) : groups = [];
1135
+ let rows = [], itemRows = [], keys = /* @__PURE__ */ new Set();
1136
+ for (let g of groups)
1137
+ if (g.entries.length) {
1138
+ g.title && rows.push({ kind: "section", key: `s:${g.title}`, title: g.title });
1139
+ for (let e of g.entries) {
1140
+ let key = v.type === "root" ? this.idOf(e.item) : e.item.id ?? `${g.title}:${e.item.title}`;
1141
+ for (; keys.has(key); ) key += "'";
1142
+ keys.add(key);
1143
+ let row = { kind: "item", key, item: e.item, positions: e.positions, index: itemRows.length };
1144
+ rows.push(row), itemRows.push(row);
1145
+ }
1146
+ }
1147
+ if (frame.rows = rows, frame.itemRows = itemRows, frame.userMoved || (frame.selectedKey = void 0, frame.selected = 0), frame.selectedKey) {
1148
+ let idx = itemRows.findIndex((r) => r.key === frame.selectedKey);
1149
+ frame.selected = idx >= 0 ? idx : Math.min(frame.selected, Math.max(0, itemRows.length - 1));
1150
+ } else frame.selected = Math.min(frame.selected, Math.max(0, itemRows.length - 1));
1151
+ frame.selectedKey = itemRows[frame.selected]?.key;
1152
+ }
1153
+ rootGroups(frame) {
1154
+ let q = frame.query.trim(), items = this.rootItems(), groups = [], bySection = /* @__PURE__ */ new Map(), group = (title) => {
1155
+ let g = bySection.get(title);
1156
+ return g || (g = { title, entries: [] }, bySection.set(title, g), groups.push(g)), g;
1157
+ };
1158
+ if (!q) {
1159
+ let shown = /* @__PURE__ */ new Set(), recentsLimit = this.config.recents === !1 ? 0 : typeof this.config.recents == "number" ? this.config.recents : 4;
1160
+ if (recentsLimit) {
1161
+ let byId = new Map(items.map((i) => [this.idOf(i), i]));
1162
+ for (let id of this.frecency.top(recentsLimit * 2)) {
1163
+ let item = byId.get(id);
1164
+ if (!(!item || item.searchOnly) && (group("Recent").entries.push({ item }), shown.add(item), shown.size >= recentsLimit))
1165
+ break;
1166
+ }
1167
+ }
1168
+ for (let item of items)
1169
+ item.searchOnly || shown.has(item) || group(item.section ?? "Commands").entries.push({ item });
1170
+ return groups;
1171
+ }
1172
+ let addSources = (position) => {
1173
+ for (let source of this.sources) {
1174
+ if ((source.position ?? "bottom") !== position) continue;
1175
+ let results = frame.sourceResults?.get(source.id);
1176
+ if (!results?.length) continue;
1177
+ let g = group(source.title ?? "Results"), list = source.filter ? rank(results, q) : results.map((item) => ({ item, positions: matchItem(item, q)?.positions }));
1178
+ for (let r of list.slice(0, source.limit ?? 8)) g.entries.push({ item: r.item, positions: r.positions });
1179
+ }
1180
+ };
1181
+ addSources("top");
1182
+ let ranked = rank(items, q, { boost: (i) => this.frecency.score(this.idOf(i)) * 0.3, limit: 300 });
1183
+ for (let r of ranked) group(r.item.section ?? "Commands").entries.push({ item: r.item, positions: r.positions });
1184
+ addSources("bottom");
1185
+ let fallbacks = (this.config.fallbacks ?? []).map((f, i) => ({ ...f, id: `fallback:${i}`, title: f.title.replaceAll("{query}", q), subtitle: f.subtitle?.replaceAll("{query}", q) }));
1186
+ if (this.ai && this.aiOptions?.fallback !== !1 && fallbacks.unshift({
1187
+ id: "qikbar.ask-ai-fallback",
1188
+ title: `Ask ${this.aiName}`,
1189
+ subtitle: `\u201C${q.length > 60 ? `${q.slice(0, 60)}\u2026` : q}\u201D`,
1190
+ icon: "sparkles",
1191
+ accessories: [{ kbd: "tab" }],
1192
+ noHistory: !0,
1193
+ run: () => ({ type: "chat", prompt: q })
1194
+ }), fallbacks.length) {
1195
+ let g = group(`Use \u201C${q.length > 24 ? `${q.slice(0, 24)}\u2026` : q}\u201D with\u2026`);
1196
+ for (let item of fallbacks) g.entries.push({ item });
1197
+ }
1198
+ return groups;
1199
+ }
1200
+ listGroups(frame, v) {
1201
+ let items = typeof v.items == "function" ? frame.items ?? [] : v.items, q = frame.query.trim(), entries = (v.filter ?? typeof v.items != "function") && q ? rank(items, q).map((r) => ({ item: r.item, positions: r.positions })) : items.map((item) => ({ item })), groups = [], bySection = /* @__PURE__ */ new Map();
1202
+ for (let e of entries) {
1203
+ let title = e.item.section ?? "", g = bySection.get(title);
1204
+ g || (g = { title, entries: [] }, bySection.set(title, g), groups.push(g)), g.entries.push(e);
1205
+ }
1206
+ return groups;
1207
+ }
1208
+ // ─── Loading ─────────────────────────────────────────────────────────────
1209
+ onQueryChange(frame, query) {
1210
+ if (frame.query === query) return;
1211
+ frame.query = query;
1212
+ let v = frame.view;
1213
+ (v.type === "root" || v.type === "list" || v.type === "grid") && (frame.selected = 0, frame.selectedKey = void 0, frame.userMoved = !1, v.type === "root" ? this.searchSources(frame) : typeof v.items == "function" && this.loadItems(frame, !1), this.computeRows(frame), this.renderer?.resetScroll?.()), this.invalidate(), this.emitChange();
1214
+ }
1215
+ searchSources(frame) {
1216
+ frame.queryController?.abort();
1217
+ let controller = new AbortController();
1218
+ frame.queryController = controller;
1219
+ let q = frame.query.trim(), results = frame.sourceResults ?? (frame.sourceResults = /* @__PURE__ */ new Map());
1220
+ for (let source of this.sources) {
1221
+ let prev = results.get(source.id);
1222
+ if (q.length < (source.minQueryLength ?? 1)) {
1223
+ results.delete(source.id);
1224
+ continue;
1225
+ }
1226
+ prev && results.set(source.id, prev.filter((item) => matchItem(item, q)));
1227
+ let run = async () => {
1228
+ if (!controller.signal.aborted) {
1229
+ frame.loading++, this.invalidate();
1230
+ try {
1231
+ let rt = this.sourceExt.get(source), items = await source.search({ query: q, signal: controller.signal, ctx: this.makeContext(frame, { ext: rt, signal: controller.signal }) });
1232
+ if (controller.signal.aborted) return;
1233
+ if (rt) for (let i of items) this.itemExt.set(i, rt);
1234
+ results.set(source.id, items);
1235
+ } catch (err) {
1236
+ controller.signal.aborted || console.error(`[qikbar] source "${source.id}" failed`, err);
1237
+ } finally {
1238
+ frame.loading--, !controller.signal.aborted && this.stack.includes(frame) && this.computeRows(frame), this.invalidate();
1239
+ }
1240
+ }
1241
+ }, delay = source.debounce ?? 150, timer = setTimeout(run, delay);
1242
+ controller.signal.addEventListener("abort", () => clearTimeout(timer));
1243
+ }
1244
+ }
1245
+ loadItems(frame, immediate) {
1246
+ let v = frame.view;
1247
+ if (typeof v.items != "function") return;
1248
+ let loader = v.items;
1249
+ frame.queryController?.abort();
1250
+ let controller = new AbortController();
1251
+ frame.queryController = controller, frame.controller.signal.addEventListener("abort", () => controller.abort());
1252
+ let run = async () => {
1253
+ if (!controller.signal.aborted) {
1254
+ frame.loading++, frame.error = void 0, this.invalidate();
1255
+ try {
1256
+ let result = loader({ query: frame.query, signal: controller.signal, ctx: this.makeContext(frame, { signal: controller.signal }) });
1257
+ if (result && typeof result[Symbol.asyncIterator] == "function")
1258
+ for await (let batch of result) {
1259
+ if (controller.signal.aborted) return;
1260
+ this.setItems(frame, batch);
1261
+ }
1262
+ else {
1263
+ let items = await result;
1264
+ controller.signal.aborted || this.setItems(frame, items);
1265
+ }
1266
+ } catch (err) {
1267
+ controller.signal.aborted || (frame.error = err instanceof Error ? err.message : String(err), frame.items = [], this.computeRows(frame));
1268
+ } finally {
1269
+ frame.loading--, this.invalidate();
1270
+ }
1271
+ }
1272
+ };
1273
+ if (immediate) run();
1274
+ else {
1275
+ let timer = setTimeout(run, v.debounce ?? 120);
1276
+ controller.signal.addEventListener("abort", () => clearTimeout(timer));
1277
+ }
1278
+ }
1279
+ setItems(frame, items) {
1280
+ if (frame.items = items, frame.ext) for (let i of items) this.itemExt.set(i, frame.ext);
1281
+ this.computeRows(frame), this.invalidate();
1282
+ }
1283
+ async loadDetail(frame, v) {
1284
+ frame.detail = { text: "", done: !1 }, frame.loading++;
1285
+ try {
1286
+ let md = v.markdown;
1287
+ if (typeof md == "function" && (md = await md()), typeof md == "string") frame.detail.text = md;
1288
+ else
1289
+ for await (let chunk of md) {
1290
+ if (frame.controller.signal.aborted) return;
1291
+ frame.detail.text += chunk, this.invalidate();
1292
+ }
1293
+ } catch (err) {
1294
+ frame.controller.signal.aborted || (frame.detail.error = err instanceof Error ? err.message : String(err));
1295
+ } finally {
1296
+ frame.detail.done = !0, frame.loading--, this.invalidate();
1297
+ }
1298
+ }
1299
+ // ─── Context ─────────────────────────────────────────────────────────────
1300
+ makeContext(frame, extra = {}) {
1301
+ let ext = extra.ext ?? frame.ext;
1302
+ return {
1303
+ bar: this,
1304
+ get query() {
1305
+ return frame.query;
1306
+ },
1307
+ signal: extra.signal ?? frame.controller.signal,
1308
+ preferences: ext ? ext.prefs() : {},
1309
+ arguments: extra.args ?? frame.args ?? {},
1310
+ storage: ext?.storage ?? this.storage,
1311
+ ai: this.ai,
1312
+ push: (view) => this.push(view, ext),
1313
+ pop: () => this.pop(),
1314
+ render: (view) => {
1315
+ this.stack.includes(frame) ? this.replaceFrame(frame, view) : this.push(view, ext);
1316
+ },
1317
+ close: () => this.close(),
1318
+ navigate: (href, options) => this.navigate(href, options?.newTab ?? !1),
1319
+ openUrl: (url) => {
1320
+ this.close(), window.open(url, "_blank", "noopener,noreferrer");
1321
+ },
1322
+ copy: (text) => copyText(text),
1323
+ toast: (options) => this.toast(options),
1324
+ confirm: (options) => this.confirm(options),
1325
+ setQuery: (q) => {
1326
+ frame === this.top ? this.setQuery(q) : frame.query = q;
1327
+ }
1328
+ };
1329
+ }
1330
+ navigate(href, newTab = !1) {
1331
+ this.isInline || this.close();
1332
+ let nav = this.config.navigate;
1333
+ if (nav) return nav(href, { newTab });
1334
+ defaultNavigate(href, newTab);
1335
+ }
1336
+ // ─── Actions ─────────────────────────────────────────────────────────────
1337
+ actionsFor(item, frame) {
1338
+ let builtIn = this.renderer?.frame === frame ? this.renderer.viewActions?.() ?? [] : [], viewActions = [...frame.view.actions ?? [], ...builtIn];
1339
+ if (!item) return viewActions;
1340
+ frame.actionCache ?? (frame.actionCache = /* @__PURE__ */ new WeakMap());
1341
+ let cached = frame.actionCache.get(item);
1342
+ if (cached) return cached;
1343
+ let acts = [];
1344
+ if (item.run && acts.push({ title: frame.view.type === "root" ? "Run Command" : "Run", icon: "corner-down-left", run: item.run }), item.view) {
1345
+ let view = item.view;
1346
+ acts.push({ title: "Open", icon: "chevron-right", run: (ctx) => typeof view == "function" ? view(ctx) : view });
1347
+ }
1348
+ if (item.href) {
1349
+ let href = item.href;
1350
+ acts.push(action.navigate(href, { title: "Open" })), acts.push(action.navigateNewTab(href)), acts.push(action.copy(() => new URL(href, location.href).href, { title: "Copy Link", icon: "link", shortcut: "mod+shift+c" }));
1351
+ }
1352
+ item.url && (acts.push(action.open(item.url)), acts.push(action.copy(item.url, { title: "Copy URL", icon: "link", shortcut: "mod+shift+c" }))), item.actions && acts.push(...item.actions), acts.push(...viewActions);
1353
+ let rt = this.itemExt.get(item);
1354
+ return frame.view.type === "root" && rt?.ext.preferences?.length && acts.push({
1355
+ title: `Configure ${rt.ext.title}`,
1356
+ icon: "settings",
1357
+ section: "Extension",
1358
+ run: () => this.preferencesForm(rt)
1359
+ }), frame.view.type === "root" && this.frecency.score(this.idOf(item)) > 0 && acts.push({
1360
+ title: "Clear Recent History",
1361
+ icon: "history",
1362
+ section: "History",
1363
+ keepOpen: !0,
1364
+ run: () => (this.frecency.clear(), this.computeRows(frame), this.invalidate(), !1)
1365
+ }), frame.actionCache.set(item, acts), acts;
1366
+ }
1367
+ selectedItem(frame = this.top) {
1368
+ if (frame)
1369
+ return frame.itemRows[frame.selected]?.item;
1370
+ }
1371
+ async runAction(frame, item, act, args) {
1372
+ if (item?.arguments?.length && !args) {
1373
+ this.enterArgMode(frame, item, act);
1374
+ return;
1375
+ }
1376
+ let rt = (item && this.itemExt.get(item)) ?? frame.ext;
1377
+ if (item && rt && rt.missing().length) {
1378
+ this.push(this.preferencesForm(rt, () => this.runAction(frame, item, act, args)), rt);
1379
+ return;
1380
+ }
1381
+ item && frame.view.type === "root" && !item.noHistory && this.frecency.record(this.idOf(item)), item && (this.config.onRun?.(item, act), this.emit("run", { item, action: act }));
1382
+ let handled = !1, base = this.makeContext(frame, { ext: rt, args }), ctx = Object.create(base, {
1383
+ push: { value: (v) => (handled = !0, base.push(v)) },
1384
+ render: { value: (v) => (handled = !0, base.render(v)) },
1385
+ pop: { value: () => (handled = !0, base.pop()) },
1386
+ close: { value: () => (handled = !0, base.close()) },
1387
+ navigate: { value: (href, o) => (handled = !0, base.navigate(href, o)) },
1388
+ openUrl: { value: (url) => (handled = !0, base.openUrl(url)) }
1389
+ });
1390
+ frame.loading++, this.invalidate();
1391
+ try {
1392
+ let result = await act.run(ctx);
1393
+ isView(result) ? this.push(result, rt) : result === !1 || act.keepOpen || handled || this.close();
1394
+ } catch (err) {
1395
+ console.error(err), this.toast({ style: "failure", title: "Something went wrong", message: err instanceof Error ? err.message : String(err) });
1396
+ } finally {
1397
+ frame.loading--, this.invalidate();
1398
+ }
1399
+ }
1400
+ runPrimary(frame = this.top, index = 0) {
1401
+ if (!frame) return;
1402
+ let item = this.selectedItem(frame), act = this.actionsFor(item, frame)[index];
1403
+ act && this.runAction(frame, item, act);
1404
+ }
1405
+ preferencesForm(rt, then) {
1406
+ let values = rt.prefs();
1407
+ return {
1408
+ type: "form",
1409
+ title: `Configure ${rt.ext.title}`,
1410
+ submitLabel: then ? "Save and Continue" : "Save",
1411
+ fields: (rt.ext.preferences ?? []).map((p) => ({
1412
+ name: p.name,
1413
+ label: p.title,
1414
+ description: p.description,
1415
+ type: p.type === "text" ? "text" : p.type,
1416
+ required: p.required,
1417
+ placeholder: p.placeholder,
1418
+ options: p.options,
1419
+ defaultValue: values[p.name] ?? p.default
1420
+ })),
1421
+ onSubmit: (vals) => {
1422
+ let stored = rt.storage.get("preferences") ?? {};
1423
+ return rt.storage.set("preferences", { ...stored, ...vals }), this.toast({ style: "success", title: "Preferences saved" }), this.pop(), then?.(), !1;
1424
+ }
1425
+ };
1426
+ }
1427
+ // ─── Arguments ───────────────────────────────────────────────────────────
1428
+ enterArgMode(frame, item, act) {
1429
+ this.argMode = { item, action: act, frame, values: {} }, this.closePanel(), this.flush(), this.dom?.args.querySelector("input,select")?.focus();
1430
+ }
1431
+ submitArgs() {
1432
+ let m = this.argMode;
1433
+ if (!m || !this.dom) return;
1434
+ let missing = (m.item.arguments ?? []).find((a) => a.required && !m.values[a.name]?.trim());
1435
+ if (missing) {
1436
+ this.dom.args.querySelector(`[name="${CSS.escape(missing.name)}"]`)?.focus();
1437
+ return;
1438
+ }
1439
+ this.argMode = void 0, this.runAction(m.frame, m.item, m.action, m.values), this.flush();
1440
+ }
1441
+ // ─── AI chat ─────────────────────────────────────────────────────────────
1442
+ sendChat(frame, text) {
1443
+ let chat = frame.chat;
1444
+ if (!chat || !this.aiOptions || !text.trim() || chat.controller && !chat.controller.signal.aborted) return;
1445
+ let controller = new AbortController();
1446
+ frame.controller.signal.addEventListener("abort", () => controller.abort()), chat.controller = controller, chat.messages.push({ role: "user", content: text }), chat.turns.push({ role: "user", text, tools: [] });
1447
+ let turn = { role: "assistant", text: "", tools: [], streaming: !0 };
1448
+ chat.turns.push(turn), frame === this.top && this.dom && (this.dom.input.value = "", frame.query = ""), frame.loading++, this.invalidate();
1449
+ let view = frame.view, useTools = view.tools !== !1 && this.aiOptions.tools !== !1;
1450
+ (async () => {
1451
+ try {
1452
+ for await (let ev of runAgent({
1453
+ provider: this.aiOptions.provider,
1454
+ messages: chat.messages,
1455
+ system: view.system ?? this.systemPrompt(useTools),
1456
+ tools: useTools ? this.agentTools(frame) : [],
1457
+ maxSteps: this.aiOptions.maxSteps ?? 6,
1458
+ signal: controller.signal
1459
+ })) {
1460
+ if (ev.type === "text") turn.text += ev.text;
1461
+ else if (ev.type === "message") chat.messages.push(ev.message);
1462
+ else if (ev.type === "tool_start")
1463
+ turn.text && !/\n\s*$/.test(turn.text) && (turn.text += `
1464
+
1465
+ `), turn.tools.push({ label: ev.label, state: "running" });
1466
+ else if (ev.type === "tool_end") {
1467
+ let t = turn.tools.find((x) => x.state === "running");
1468
+ t && (t.state = ev.ok ? "done" : "error");
1469
+ } else ev.type === "error" && (turn.error = ev.error);
1470
+ this.invalidate();
1471
+ }
1472
+ } catch (err) {
1473
+ controller.signal.aborted || (turn.error = err instanceof Error ? err.message : String(err));
1474
+ } finally {
1475
+ turn.streaming = !1;
1476
+ for (let t of turn.tools) t.state === "running" && (t.state = "error");
1477
+ frame.loading--, chat.controller = void 0, this.invalidate();
1478
+ }
1479
+ })();
1480
+ }
1481
+ stopChat(frame) {
1482
+ let c = frame.chat?.controller;
1483
+ return c && !c.signal.aborted ? (c.abort(), !0) : !1;
1484
+ }
1485
+ systemPrompt(withTools) {
1486
+ let lines = [
1487
+ `You are ${this.aiName}, the assistant built into this web app's command bar.`,
1488
+ "Answer concisely in Markdown. Prefer short paragraphs and lists."
1489
+ ];
1490
+ if (typeof document < "u" && lines.push(`The user is on the page "${document.title}" (${location.pathname}).`), withTools) {
1491
+ let items = this.rootItems().filter((i) => !i.id?.startsWith("qikbar."));
1492
+ lines.push(
1493
+ "",
1494
+ "You can act inside the app:",
1495
+ "- Call `run` with an item id to open a page or run a command when the user asks you to go somewhere or do something.",
1496
+ "- Call `search` to find commands, pages and records that are not listed below.",
1497
+ "Only call tools when the user wants something done or found in the app; otherwise just answer. After acting, confirm briefly what you did.",
1498
+ "",
1499
+ "Available items (id | title | section):",
1500
+ ...items.slice(0, 80).map((i) => `${this.idOf(i)} | ${i.title}${i.subtitle ? ` \u2014 ${i.subtitle}` : ""} | ${i.section ?? "Commands"}`)
1501
+ ), items.length > 80 && lines.push(`\u2026and ${items.length - 80} more (use search).`);
1502
+ }
1503
+ return this.aiOptions?.system && lines.push("", this.aiOptions.system), lines.join(`
1504
+ `);
1505
+ }
1506
+ agentTools(chatFrame) {
1507
+ let found = /* @__PURE__ */ new Map(), lookup = (id) => found.get(id) ?? this.rootItems().find((i) => this.idOf(i) === id), tools = [
1508
+ {
1509
+ definition: {
1510
+ name: "search",
1511
+ description: "Search the app's commands, pages and records (including results from connected data sources). Returns matching items with ids you can pass to `run`.",
1512
+ parameters: { type: "object", properties: { query: { type: "string", description: "What to look for" } }, required: ["query"] }
1513
+ },
1514
+ label: (a) => `Searching \u201C${String(a.query ?? "")}\u201D`,
1515
+ run: async (args, signal) => {
1516
+ let q = String(args.query ?? ""), local = rank(this.rootItems(), q, { limit: 10 }).map((r) => r.item), remote = await Promise.all(
1517
+ [...this.sources].map(async (s) => {
1518
+ if (q.length < (s.minQueryLength ?? 1)) return [];
1519
+ try {
1520
+ let rt = this.sourceExt.get(s), items = await withTimeout(s.search({ query: q, signal, ctx: this.makeContext(chatFrame, { ext: rt, signal }) }), 6e3);
1521
+ if (rt) for (let i of items) this.itemExt.set(i, rt);
1522
+ return items.slice(0, s.limit ?? 8).map((i) => ({ item: i, section: s.title ?? s.id }));
1523
+ } catch {
1524
+ return [];
1525
+ }
1526
+ })
1527
+ ), all = [...local.map((item) => ({ item, section: item.section ?? "Commands" })), ...remote.flat()];
1528
+ return all.length ? all.map(({ item, section }, n) => {
1529
+ let id = item.id && !found.has(item.id) ? item.id : `${section}#${n}`;
1530
+ return found.set(id, item), { id, title: item.title, subtitle: item.subtitle, section, description: item.description, href: item.href ?? item.url };
1531
+ }) : "No results.";
1532
+ }
1533
+ },
1534
+ {
1535
+ definition: {
1536
+ name: "run",
1537
+ description: "Open or run an item (page, command or record) by id. Use ids from the system prompt or from `search`.",
1538
+ parameters: {
1539
+ type: "object",
1540
+ properties: {
1541
+ id: { type: "string" },
1542
+ arguments: { type: "object", description: "Values for the command arguments, if it has any.", additionalProperties: { type: "string" } }
1543
+ },
1544
+ required: ["id"]
1545
+ }
1546
+ },
1547
+ label: (a) => {
1548
+ let item = lookup(String(a.id ?? ""));
1549
+ return item ? `Opening ${item.title}` : `Running ${String(a.id ?? "")}`;
1550
+ },
1551
+ run: async (args) => {
1552
+ let item = lookup(String(args.id ?? ""));
1553
+ if (!item) throw new Error(`No item with id "${String(args.id)}". Use search first.`);
1554
+ let rt = this.itemExt.get(item);
1555
+ if (rt?.missing().length) throw new Error(`${rt.ext.title} needs to be configured first. Ask the user to open it from the command bar.`);
1556
+ let act = this.actionsFor(item, this.stack[0] ?? chatFrame)[0];
1557
+ if (!act) throw new Error("This item has no action.");
1558
+ if (act.style === "destructive" && !await this.confirm({ title: `${act.title}?`, message: item.title, destructive: !0, confirmLabel: act.title }))
1559
+ return "The user cancelled.";
1560
+ if (item.href) {
1561
+ let nav = this.config.navigate;
1562
+ return nav ? nav(item.href, { newTab: !1 }) : defaultNavigate(item.href, !1), this.frecency.record(this.idOf(item)), `Navigated to ${item.href}.`;
1563
+ }
1564
+ if (item.url)
1565
+ return window.open(item.url, "_blank", "noopener,noreferrer"), `Opened ${item.url} in a new tab.`;
1566
+ let strArgs = Object.fromEntries(Object.entries(args.arguments ?? {}).map(([k, v]) => [k, String(v)])), ctx = Object.create(this.makeContext(chatFrame, { ext: rt, args: strArgs }), {
1567
+ close: { value: () => {
1568
+ } }
1569
+ }), result = await act.run(ctx);
1570
+ return this.frecency.record(this.idOf(item)), isView(result) ? (this.push(result, rt), `Opened the "${item.title}" view for the user.`) : `Ran "${item.title}".`;
1571
+ }
1572
+ }
1573
+ ];
1574
+ this.aiOptions?.pageContext !== !1 && typeof document < "u" && tools.push({
1575
+ definition: {
1576
+ name: "read_page",
1577
+ description: 'Read the visible text of the page the user is currently on. Use it when the user asks about "this page" or its content.',
1578
+ parameters: { type: "object", properties: {} }
1579
+ },
1580
+ label: () => "Reading this page",
1581
+ run: async () => {
1582
+ let text = (document.querySelector("main, [role=main], article") ?? document.body).innerText.replace(/\n{3,}/g, `
1583
+
1584
+ `).trim();
1585
+ return `# ${document.title}
1586
+ URL: ${location.href}
1587
+
1588
+ ${text.slice(0, 2e4)}`;
1589
+ }
1590
+ });
1591
+ let addTools = (list, rt, prefix) => {
1592
+ for (let tool of list)
1593
+ tools.push({
1594
+ definition: {
1595
+ name: toolName(prefix ? `${prefix}__${tool.name}` : tool.name),
1596
+ description: tool.description,
1597
+ parameters: tool.parameters ?? { type: "object", properties: {} }
1598
+ },
1599
+ label: () => tool.description.split(/[.\n]/)[0].slice(0, 60),
1600
+ run: async (args) => {
1601
+ if (tool.confirm) {
1602
+ let msg = typeof tool.confirm == "function" ? tool.confirm(args) : `Allow ${this.aiName} to ${tool.name}?`;
1603
+ if (!await this.confirm({ title: msg, confirmLabel: "Allow" })) return "The user declined.";
1604
+ }
1605
+ return tool.run(args, this.makeContext(chatFrame, { ext: rt }));
1606
+ }
1607
+ });
1608
+ };
1609
+ addTools(this.config.tools ?? [], void 0, "");
1610
+ for (let e of this.extensions.values()) addTools(e.rt.ext.tools ?? [], e.rt, e.rt.ext.name);
1611
+ return tools;
1612
+ }
1613
+ // ─── Toasts & confirm ────────────────────────────────────────────────────
1614
+ toast(options) {
1615
+ let opts = typeof options == "string" ? { title: options } : options, id = ++this.toastId, schedule = () => {
1616
+ clearTimeout(this.toastTimer);
1617
+ let s = this.toastState;
1618
+ if (!s) return;
1619
+ let duration = s.duration ?? (s.style === "loading" ? 0 : 2600);
1620
+ duration > 0 && (this.toastTimer = setTimeout(() => hide(), duration));
1621
+ }, hide = () => {
1622
+ this.toastState?.id === id && (this.toastState = void 0, this.renderToast());
1623
+ };
1624
+ return this.toastState = { ...opts, id }, schedule(), this.renderToast(), {
1625
+ update: (p) => {
1626
+ this.toastState?.id === id && (this.toastState = { ...this.toastState, ...p }, schedule(), this.renderToast());
1627
+ },
1628
+ hide
1629
+ };
1630
+ }
1631
+ confirm(options) {
1632
+ let opts = typeof options == "string" ? { title: options } : options;
1633
+ return !this._open || !this.dom ? Promise.resolve(typeof window < "u" ? window.confirm(opts.message ? `${opts.title}
1634
+
1635
+ ${opts.message}` : opts.title) : !1) : (this.confirmState?.resolve(!1), new Promise((resolve) => {
1636
+ this.confirmState = {
1637
+ ...opts,
1638
+ resolve: (ok) => {
1639
+ this.confirmState = void 0, this.renderLayer(), this.focusInput(), resolve(ok);
1640
+ }
1641
+ }, this.renderLayer();
1642
+ }));
1643
+ }
1644
+ escape() {
1645
+ let frame = this.top;
1646
+ if (frame && !(frame.chat && this.stopChat(frame))) {
1647
+ if (this.stack.length > 1) return this.pop();
1648
+ if (frame.query) return this.setQuery("");
1649
+ this.close();
1650
+ }
1651
+ }
1652
+ // ─── Action panel ────────────────────────────────────────────────────────
1653
+ openPanel() {
1654
+ let frame = this.top;
1655
+ if (!frame || !this.dom) return;
1656
+ if (this.panel) return this.closePanel();
1657
+ let item = this.selectedItem(frame), actions = this.actionsFor(item, frame);
1658
+ actions.length && (this.panel = { item, actions, filter: "", selected: 0 }, this.renderPanel());
1659
+ }
1660
+ closePanel() {
1661
+ this.panel && (this.panel.el?.remove(), this.panel = void 0, this.focusInput());
1662
+ }
1663
+ panelActions() {
1664
+ let p = this.panel;
1665
+ return p.filter ? rank(p.actions, p.filter).map((r) => r.item) : p.actions;
1666
+ }
1667
+ onPanelKey(e) {
1668
+ let p = this.panel, list = this.panelActions();
1669
+ if (e.key === "Escape" || matchesHotkey(e, this.actionsHotkey))
1670
+ return this.closePanel(), !0;
1671
+ if (e.key === "ArrowDown" || e.ctrlKey && e.key === "n")
1672
+ return p.selected = (p.selected + 1) % Math.max(1, list.length), this.renderPanel(), !0;
1673
+ if (e.key === "ArrowUp" || e.ctrlKey && e.key === "p")
1674
+ return p.selected = (p.selected - 1 + list.length) % Math.max(1, list.length), this.renderPanel(), !0;
1675
+ if (e.key === "Enter") {
1676
+ let act = list[p.selected];
1677
+ return act && this.runFromPanel(act), !0;
1678
+ }
1679
+ for (let act of p.actions)
1680
+ if (act.shortcut && matchesHotkey(e, act.shortcut))
1681
+ return this.runFromPanel(act), !0;
1682
+ return !1;
1683
+ }
1684
+ runFromPanel(act) {
1685
+ let item = this.panel?.item, frame = this.top;
1686
+ this.closePanel(), this.runAction(frame, item, act);
1687
+ }
1688
+ renderPanel() {
1689
+ let p = this.panel, dom = this.dom;
1690
+ if (!p || !dom) return;
1691
+ p.el || (p.list = h("div", { class: "qb-actions-list", role: "listbox", id: `${this.instanceId}-actions` }), p.input = h("input", {
1692
+ class: "qb-actions-input",
1693
+ placeholder: "Search for actions\u2026",
1694
+ "aria-label": "Search actions",
1695
+ autocomplete: "off",
1696
+ spellcheck: "false",
1697
+ onInput: () => {
1698
+ p.filter = p.input.value, p.selected = 0, this.renderPanel();
1699
+ }
1700
+ }), p.el = h(
1701
+ "div",
1702
+ { class: this.cls("qb-actions", "actions"), role: "dialog", "aria-label": "Actions" },
1703
+ h("div", { class: "qb-actions-title" }, p.item?.title ?? "Actions"),
1704
+ p.list,
1705
+ p.input
1706
+ ), p.el.addEventListener("pointerdown", (e) => {
1707
+ e.target !== p.input && e.preventDefault();
1708
+ }), dom.dialog.append(p.el), p.input.focus());
1709
+ let list = this.panelActions();
1710
+ p.selected = Math.min(p.selected, Math.max(0, list.length - 1));
1711
+ let children = [], section;
1712
+ list.forEach((act, i) => {
1713
+ !p.filter && act.section && act.section !== section && children.push(h("div", { class: "qb-section" }, act.section)), section = act.section;
1714
+ let shortcut = act.shortcut ?? (i === 0 && !p.filter ? "enter" : i === 1 && !p.filter ? "mod+enter" : void 0), el = h(
1715
+ "div",
1716
+ {
1717
+ class: "qb-action",
1718
+ role: "option",
1719
+ id: `${this.instanceId}-action-${i}`,
1720
+ "aria-selected": i === p.selected ? "true" : "false",
1721
+ "data-style": act.style ?? "default",
1722
+ onClick: () => this.runFromPanel(act),
1723
+ onPointermove: () => {
1724
+ p.selected !== i && (p.selected = i, this.renderPanel());
1725
+ }
1726
+ },
1727
+ renderIcon(act.icon ?? "dot", 15),
1728
+ h("span", { class: "qb-action-title" }, act.title),
1729
+ shortcut ? renderKbd(shortcut) : null
1730
+ );
1731
+ children.push(el);
1732
+ }), list.length || children.push(h("div", { class: "qb-empty-desc", style: "padding:10px 8px" }, "No matching actions")), p.list.replaceChildren(...children), p.input.setAttribute("aria-activedescendant", `${this.instanceId}-action-${p.selected}`), p.list.querySelector("[aria-selected=true]")?.scrollIntoView({ block: "nearest" });
1733
+ }
1734
+ // ─── DOM ─────────────────────────────────────────────────────────────────
1735
+ cls(base, slot) {
1736
+ let extra = this.config.classNames?.[slot];
1737
+ return extra ? `${base} ${extra}` : base;
1738
+ }
1739
+ injectStyles() {
1740
+ if (this.config.unstyled || typeof document > "u" || document.getElementById("qikbar-styles")) return;
1741
+ let style = document.createElement("style");
1742
+ style.id = "qikbar-styles", this.config.nonce && (style.nonce = this.config.nonce), style.textContent = css, document.head.append(style), this.styleEl = style;
1743
+ }
1744
+ mount() {
1745
+ if (this.dom || typeof document > "u") return;
1746
+ this.injectStyles();
1747
+ let id = this.instanceId, input = h("input", {
1748
+ class: this.cls("qb-input", "input"),
1749
+ type: "text",
1750
+ role: "combobox",
1751
+ autocomplete: "off",
1752
+ autocorrect: "off",
1753
+ autocapitalize: "off",
1754
+ spellcheck: "false",
1755
+ enterkeyhint: "go",
1756
+ "aria-autocomplete": "list",
1757
+ "aria-expanded": "true",
1758
+ "aria-controls": `${id}-list`,
1759
+ "aria-label": "Search"
1760
+ });
1761
+ input.addEventListener("input", () => {
1762
+ let frame = this.top;
1763
+ frame && this.onQueryChange(frame, input.value);
1764
+ });
1765
+ let back = h("button", { class: "qb-back", type: "button", "aria-label": "Back", title: "Back", html: "" });
1766
+ back.append(renderIcon("arrow-left", 15)), back.addEventListener("click", () => this.pop());
1767
+ let hint = h("button", { class: "qb-hint", type: "button" });
1768
+ hint.addEventListener("click", () => this.ask(this.top?.query));
1769
+ let progress = h("div", { class: "qb-progress", "aria-hidden": "true" }), header = h(
1770
+ "div",
1771
+ { class: this.cls("qb-header", "header") },
1772
+ back,
1773
+ h("div", { class: "qb-crumb" }),
1774
+ h("span", { class: "qb-header-icon" }, renderIcon("search", 18)),
1775
+ input,
1776
+ h("div", { class: "qb-args", style: "display:contents" }),
1777
+ h("div", { class: "qb-title" }),
1778
+ hint,
1779
+ progress
1780
+ ), body = h("div", { class: "qb-body" }), footerLeft = h("div", { class: "qb-footer-left", "aria-live": "polite" }), footerRight = h("div", { class: "qb-footer-right" }), footer = h("div", { class: this.cls("qb-footer", "footer") }, footerLeft, footerRight), layer = h("div", { style: "display:contents" }), dialog = h(
1781
+ "div",
1782
+ { class: this.cls("qb-dialog", "dialog"), role: "dialog", "aria-modal": this.isInline ? "false" : "true", "aria-label": "Command bar", tabindex: "-1", hidden: !0 },
1783
+ header,
1784
+ body,
1785
+ footer,
1786
+ layer
1787
+ ), overlay = h("div", { class: this.cls("qb-overlay", "overlay"), hidden: !0 });
1788
+ overlay.addEventListener("pointerdown", (e) => {
1789
+ e.preventDefault(), this.close();
1790
+ });
1791
+ let live = h("div", { class: "qb-sr-only", "aria-live": "polite" }), root = h("div", { class: this.cls("qb-root", "root"), "data-qb-state": "closed", id }, overlay, dialog, live);
1792
+ this.config.dir && (root.dir = this.config.dir), dialog.addEventListener("keydown", this.onDialogKeyDown), dialog.addEventListener("click", (e) => {
1793
+ let btn = e.target.closest?.("[data-qb-copy]");
1794
+ if (btn) {
1795
+ let code = btn.closest(".qb-code")?.querySelector("code")?.textContent ?? "";
1796
+ copyText(code).then((ok) => {
1797
+ btn.textContent = ok ? "Copied" : "Failed", setTimeout(() => btn.textContent = "Copy", 1200);
1798
+ });
1799
+ }
1800
+ this.panel && !e.target.closest?.(".qb-actions") && !e.target.closest?.(".qb-footer-btn") && this.closePanel();
1801
+ });
1802
+ let inline = this.inlineTarget();
1803
+ inline ? (root.dataset.qbInline = "", inline.append(root)) : (this.config.container ?? document.body).append(root), this.dom = {
1804
+ root,
1805
+ overlay,
1806
+ dialog,
1807
+ header,
1808
+ back,
1809
+ crumb: header.querySelector(".qb-crumb"),
1810
+ searchIcon: header.querySelector(".qb-header-icon"),
1811
+ input,
1812
+ args: header.querySelector(".qb-args"),
1813
+ title: header.querySelector(".qb-title"),
1814
+ hint,
1815
+ progress,
1816
+ body,
1817
+ footer,
1818
+ footerLeft,
1819
+ footerRight,
1820
+ layer,
1821
+ live
1822
+ }, this.applyTheme(), this.watchAppearance(), this.listen(document, "focusin", ((e) => {
1823
+ this._open && !this.isInline && this.dom && !this.dom.root.contains(e.target) && this.focusInput();
1824
+ }));
1825
+ }
1826
+ applyClassNames() {
1827
+ let d = this.dom;
1828
+ d && (d.root.className = this.cls("qb-root", "root"), d.overlay.className = this.cls("qb-overlay", "overlay"), d.dialog.className = this.cls("qb-dialog", "dialog"), d.header.className = this.cls("qb-header", "header"), d.input.className = this.cls("qb-input", "input"), d.footer.className = this.cls("qb-footer", "footer"), this.renderer && (this.renderer.destroy(), this.renderer = void 0, this.flush()));
1829
+ }
1830
+ resolveAppearance() {
1831
+ let a = this.config.appearance ?? "auto";
1832
+ if (typeof a == "function") return a();
1833
+ if (a !== "auto") return a;
1834
+ let html = document.documentElement, body = document.body, darkAttr = (el) => !!el && (el.classList.contains("dark") || el.dataset.theme === "dark" || el.dataset.mode === "dark" || el.dataset.colorScheme === "dark" || el.dataset.bsTheme === "dark"), lightAttr = (el) => !!el && (el.classList.contains("light") || el.dataset.theme === "light" || el.dataset.mode === "light" || el.dataset.colorScheme === "light" || el.dataset.bsTheme === "light");
1835
+ if (darkAttr(html) || darkAttr(body)) return "dark";
1836
+ if (lightAttr(html) || lightAttr(body)) return "light";
1837
+ let scheme = html.style.colorScheme || getComputedStyle(html).colorScheme;
1838
+ return scheme === "dark" ? "dark" : scheme === "light" ? "light" : typeof matchMedia < "u" && matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
1839
+ }
1840
+ applyTheme() {
1841
+ let root = this.dom?.root;
1842
+ if (!root) return;
1843
+ let { vars, appearance } = resolveThemeVars(this.config.theme, this.resolveAppearance());
1844
+ root.dataset.qbAppearance = appearance;
1845
+ let preset = typeof this.config.theme == "string" ? this.config.theme : this.config.theme?.preset;
1846
+ preset ? root.dataset.qbTheme = preset : delete root.dataset.qbTheme;
1847
+ for (let name of this.appliedVars) root.style.removeProperty(name);
1848
+ this.appliedVars = [];
1849
+ for (let [k, v] of Object.entries(vars)) {
1850
+ if (v == null || v === "") continue;
1851
+ let name = cssVarName(k);
1852
+ root.style.setProperty(name, v), this.appliedVars.push(name);
1853
+ }
1854
+ }
1855
+ watchAppearance() {
1856
+ if (typeof MutationObserver > "u") return;
1857
+ let update = () => {
1858
+ this.dom && (this.config.appearance ?? "auto") === "auto" && this.applyTheme();
1859
+ }, mo = new MutationObserver(update);
1860
+ if (mo.observe(document.documentElement, { attributes: !0, attributeFilter: ["class", "data-theme", "data-mode", "data-color-scheme", "data-bs-theme", "style"] }), document.body && mo.observe(document.body, { attributes: !0, attributeFilter: ["class", "data-theme", "data-mode"] }), this.teardown.push(() => mo.disconnect()), typeof matchMedia < "u") {
1861
+ let mq = matchMedia("(prefers-color-scheme: dark)");
1862
+ mq.addEventListener?.("change", update), this.teardown.push(() => mq.removeEventListener?.("change", update));
1863
+ }
1864
+ }
1865
+ lockScroll() {
1866
+ let html = document.documentElement, scrollbar = window.innerWidth - html.clientWidth;
1867
+ this.scrollLock = { overflow: html.style.overflow, paddingRight: html.style.paddingRight }, html.style.overflow = "hidden", scrollbar > 0 && (html.style.paddingRight = `${scrollbar}px`);
1868
+ }
1869
+ unlockScroll() {
1870
+ if (!this.scrollLock) return;
1871
+ let html = document.documentElement;
1872
+ html.style.overflow = this.scrollLock.overflow, html.style.paddingRight = this.scrollLock.paddingRight, this.scrollLock = void 0;
1873
+ }
1874
+ focusInput() {
1875
+ if (!this.dom || !this._open) return;
1876
+ let target = this.renderer?.focusTarget?.() ?? (this.dom.input.hidden ? this.dom.dialog : this.dom.input);
1877
+ document.activeElement !== target && target.focus({ preventScroll: !0 });
1878
+ }
1879
+ // ─── Rendering ───────────────────────────────────────────────────────────
1880
+ invalidate() {
1881
+ this.scheduled || !this.dom || (this.scheduled = !0, queueMicrotask(() => {
1882
+ this.scheduled = !1, this.flush();
1883
+ }));
1884
+ }
1885
+ flush() {
1886
+ let dom = this.dom, frame = this.top;
1887
+ !dom || !frame || !this._open && !this.isInline || (!this.renderer || this.renderer.frame !== frame ? (this.renderer?.destroy(), this.renderer = this.createRenderer(frame), dom.body.replaceChildren(this.renderer.el), this.renderer.update(), frame.scrollTop && this.renderer.restoreScroll(frame.scrollTop), frame.selected > 0 && this.renderer.ensureVisible?.()) : this.renderer.update(), this.renderHeader(frame), this.renderFooter(frame), this.renderLayer(), this.panel && this.renderPanel());
1888
+ }
1889
+ createRenderer(frame) {
1890
+ switch (frame.view.type) {
1891
+ case "grid":
1892
+ return new GridRenderer(this, frame);
1893
+ case "detail":
1894
+ return new DetailRenderer(this, frame);
1895
+ case "form":
1896
+ return new FormRenderer(this, frame);
1897
+ case "chat":
1898
+ return new ChatRenderer(this, frame);
1899
+ default:
1900
+ return new ListRenderer(this, frame);
1901
+ }
1902
+ }
1903
+ renderHeader(frame) {
1904
+ let dom = this.dom, v = frame.view, depth = this.stack.length, hasInput = this.renderer?.hasInput ?? !0;
1905
+ dom.back.hidden = depth <= 1;
1906
+ let crumbTitle = depth > 1 ? v.title ?? (v.type === "chat" ? this.aiName : void 0) : void 0;
1907
+ if (dom.crumb.hidden = !crumbTitle || !hasInput, crumbTitle && hasInput && dom.crumb.replaceChildren(...[renderIcon(frame.ext?.ext.icon, 13), h("span", null, crumbTitle)].filter(Boolean)), dom.searchIcon.hidden = depth > 1 || !!this.argMode, this.argMode) {
1908
+ let m = this.argMode;
1909
+ if (dom.input.hidden = !0, dom.title.hidden = !0, dom.args.dataset.for !== this.idOf(m.item)) {
1910
+ dom.args.dataset.for = this.idOf(m.item);
1911
+ let fields = (m.item.arguments ?? []).map((a) => {
1912
+ if (a.type === "dropdown") {
1913
+ let sel = h(
1914
+ "select",
1915
+ { class: "qb-arg", name: a.name, "aria-label": a.placeholder ?? a.name },
1916
+ ...(a.options ?? []).map((o) => h("option", { value: o.value }, o.title))
1917
+ );
1918
+ return m.values[a.name] = sel.value, sel.addEventListener("change", () => m.values[a.name] = sel.value), sel;
1919
+ }
1920
+ let inp = h("input", {
1921
+ class: "qb-arg",
1922
+ name: a.name,
1923
+ type: a.type === "password" ? "password" : "text",
1924
+ placeholder: `${a.placeholder ?? a.name}${a.required ? "" : " (optional)"}`,
1925
+ "aria-label": a.placeholder ?? a.name,
1926
+ autocomplete: "off",
1927
+ spellcheck: "false"
1928
+ });
1929
+ return inp.addEventListener("input", () => m.values[a.name] = inp.value), inp;
1930
+ });
1931
+ dom.args.replaceChildren(h("span", { class: "qb-arg-cmd" }, renderIcon(m.item.icon, 16), m.item.title), ...fields);
1932
+ }
1933
+ dom.args.hidden = !1;
1934
+ } else {
1935
+ dom.args.hidden = !0, delete dom.args.dataset.for, dom.args.replaceChildren(), dom.input.hidden = !hasInput, dom.title.hidden = hasInput, hasInput || (dom.title.textContent = v.title ?? "");
1936
+ let placeholder = this.renderer?.placeholder?.() ?? v.placeholder ?? (v.type === "root" ? this.config.placeholder ?? "Search for commands, pages and more\u2026" : "Search\u2026");
1937
+ dom.input.placeholder !== placeholder && (dom.input.placeholder = placeholder), dom.input.value !== frame.query && (dom.input.value = frame.query);
1938
+ }
1939
+ let selected = frame.itemRows[frame.selected];
1940
+ selected && (v.type === "root" || v.type === "list" || v.type === "grid") ? dom.input.setAttribute("aria-activedescendant", `${this.instanceId}-opt-${selected.key.replace(/[^\w-]/g, "_")}`) : dom.input.removeAttribute("aria-activedescendant");
1941
+ let showHint = !!this.ai && v.type === "root" && !this.argMode && this.aiOptions?.fallback !== !1;
1942
+ dom.hint.hidden = !showHint, showHint && !dom.hint.childElementCount && dom.hint.append(h("span", null, `Ask ${this.aiName}`), renderKbd("tab")), frame.loading > 0 ? dom.progress.dataset.active = "" : delete dom.progress.dataset.active;
1943
+ }
1944
+ renderFooter(frame) {
1945
+ let dom = this.dom;
1946
+ !this.toastState || !this._open ? this.renderFooterLeft(frame) : this.renderToast();
1947
+ let right = [], custom = this.renderer?.footerPrimary?.(), actions = this.actionsFor(this.selectedItem(frame), frame), primary = custom ?? (actions[0] ? { title: actions[0].title, hotkey: "enter", run: () => this.runPrimary(frame) } : void 0);
1948
+ this.argMode ? right.push(this.footerButton(`Run ${this.argMode.item.title}`, "enter", () => this.submitArgs(), !0)) : primary && right.push(this.footerButton(primary.title, primary.hotkey, primary.run, !0)), actions.length > (custom ? 0 : 1) && !this.argMode && right.push(h("span", { class: "qb-footer-sep" }), this.footerButton("Actions", this.actionsHotkey, () => this.openPanel())), dom.footerRight.replaceChildren(...right);
1949
+ }
1950
+ renderFooterLeft(frame) {
1951
+ let dom = this.dom, v = frame.view, left = [];
1952
+ if (this.stack.length > 1 && v.title) {
1953
+ let icon = renderIcon(frame.ext?.ext.icon ?? "layers", 14);
1954
+ icon && left.push(icon), left.push(h("span", null, v.title));
1955
+ } else if (this.config.footer) left.push(h("span", null, this.config.footer));
1956
+ else if (this.config.branding) {
1957
+ let a = h("a", { class: "qb-brand", href: "https://qikbar.com", target: "_blank", rel: "noopener" }, renderIcon("command", 13), "qikbar");
1958
+ left.push(a);
1959
+ }
1960
+ dom.footerLeft.replaceChildren(...left);
1961
+ }
1962
+ footerButton(title, hotkey, run, primary = !1) {
1963
+ let btn = h("button", { class: `qb-footer-btn${primary ? " qb-primary" : ""}`, type: "button" }, h("span", null, title), renderKbd(hotkey));
1964
+ return btn.addEventListener("pointerdown", (e) => e.preventDefault()), btn.addEventListener("click", run), btn;
1965
+ }
1966
+ renderToast() {
1967
+ let t = this.toastState, iconFor = (style) => style === "success" ? "check-circle" : style === "failure" ? "x-circle" : style === "loading" ? "loader" : "info", build = (cls) => {
1968
+ let icon = renderIcon(iconFor(t.style), 14);
1969
+ return t.style === "loading" && icon.classList.add("qb-spin"), h(
1970
+ "div",
1971
+ { class: this.cls(cls, "toast"), "data-style": t.style ?? "info", role: "status" },
1972
+ icon,
1973
+ h("span", { class: "qb-toast-title" }, t.title),
1974
+ t.message ? h("span", { class: "qb-toast-msg" }, t.message) : null
1975
+ );
1976
+ };
1977
+ if (this._open && this.dom) {
1978
+ this.hud?.remove(), this.hud = void 0, t ? this.dom.footerLeft.replaceChildren(build("qb-toast")) : this.top && this.renderFooterLeft(this.top);
1979
+ return;
1980
+ }
1981
+ typeof document > "u" || (this.mount(), this.hud?.remove(), this.hud = void 0, !(!t || !this.dom) && (this.applyTheme(), this.hud = build("qb-hud"), this.dom.root.append(this.hud)));
1982
+ }
1983
+ renderLayer() {
1984
+ let dom = this.dom;
1985
+ if (!dom) return;
1986
+ let c = this.confirmState;
1987
+ if (!c) {
1988
+ dom.layer.replaceChildren();
1989
+ return;
1990
+ }
1991
+ if (dom.layer.firstChild) return;
1992
+ let cancel = h("button", { class: "qb-btn", type: "button" }, c.cancelLabel ?? "Cancel"), ok = h("button", { class: `qb-btn ${c.destructive ? "qb-btn-danger" : "qb-btn-primary"}`, type: "button" }, c.confirmLabel ?? "Confirm", renderKbd("enter"));
1993
+ cancel.addEventListener("click", () => c.resolve(!1)), ok.addEventListener("click", () => c.resolve(!0)), ok.addEventListener("keydown", (e) => {
1994
+ e.key === "Enter" && (e.preventDefault(), c.resolve(!0));
1995
+ }), dom.layer.append(
1996
+ h(
1997
+ "div",
1998
+ { class: "qb-confirm-layer" },
1999
+ h(
2000
+ "div",
2001
+ { class: "qb-confirm", role: "alertdialog", "aria-modal": "true", "aria-label": c.title },
2002
+ h("div", { class: "qb-confirm-title" }, c.title),
2003
+ c.message ? h("div", { class: "qb-confirm-msg" }, c.message) : null,
2004
+ h("div", { class: "qb-confirm-buttons" }, cancel, ok)
2005
+ )
2006
+ )
2007
+ ), ok.focus();
2008
+ }
2009
+ announce(text) {
2010
+ this.dom && (this.dom.live.textContent = text);
2011
+ }
2012
+ };
2013
+ function shallowEqual(a, b) {
2014
+ if (a === b) return !0;
2015
+ if (!a || !b) return !1;
2016
+ let ka = Object.keys(a);
2017
+ return ka.length !== Object.keys(b).length ? !1 : ka.every((k) => a[k] === b[k]);
2018
+ }
2019
+ async function withTimeout(p, ms) {
2020
+ let timer;
2021
+ try {
2022
+ return await Promise.race([Promise.resolve(p), new Promise((_, reject) => timer = setTimeout(() => reject(new Error("timeout")), ms))]);
2023
+ } finally {
2024
+ clearTimeout(timer);
2025
+ }
2026
+ }
2027
+ export {
2028
+ Bar,
2029
+ isView
2030
+ };
2031
+ //# sourceMappingURL=bar-D5CSPT3U.js.map