@pritzlaff/nano-app 0.0.0-stage → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/AGENTS.md +66 -0
  2. package/LICENSE +21 -0
  3. package/README.md +6 -2
  4. package/app/app.css +160 -0
  5. package/app/bundle/nano-ui.js +2553 -0
  6. package/app/examples/auth/example.auth.js +6 -0
  7. package/app/examples/auth/nano.json +46 -0
  8. package/app/examples/chat/example.chat.js +6 -0
  9. package/app/examples/chat/example.messaging.js +3 -0
  10. package/app/examples/chat/nano.json +115 -0
  11. package/app/examples/drift/example.drift.js +3 -0
  12. package/app/examples/drift/nano.json +31 -0
  13. package/app/examples/kv/example.kv.js +3 -0
  14. package/app/examples/nano.json +353 -0
  15. package/app/examples/originkey/_nano/bundle/nano-ui.js +212 -0
  16. package/app/examples/originkey/_nano/sandbox/boot.js +1 -0
  17. package/app/examples/originkey/_nano/shared/chunks/nano-core-2gg2vg5g.js +2 -0
  18. package/app/examples/originkey/_nano/shared/chunks/nano-core-5h5dssvv.js +3 -0
  19. package/app/examples/originkey/_nano/shared/chunks/nano-core-72b5e6vd.js +17 -0
  20. package/app/examples/originkey/_nano/shared/chunks/nano-core-87v2yejk.js +2 -0
  21. package/app/examples/originkey/_nano/shared/chunks/nano-core-hm29e227.js +7 -0
  22. package/app/examples/originkey/_nano/shared/chunks/nano-core-jtgk4ch8.js +2 -0
  23. package/app/examples/originkey/_nano/shared/chunks/nano-core-mqaje7vc.js +2 -0
  24. package/app/examples/originkey/_nano/shared/chunks/nano-core-mxgap7rs.js +2 -0
  25. package/app/examples/originkey/_nano/shared/chunks/nano-core-qy0mwf7y.js +1 -0
  26. package/app/examples/originkey/_nano/shared/chunks/nano-core-wanb7xw1.js +1 -0
  27. package/app/examples/originkey/_nano/shared/lit-class-map.js +1 -0
  28. package/app/examples/originkey/_nano/shared/lit-decorators.js +1 -0
  29. package/app/examples/originkey/_nano/shared/lit-directive.js +1 -0
  30. package/app/examples/originkey/_nano/shared/lit-if-defined.js +1 -0
  31. package/app/examples/originkey/_nano/shared/lit-ref.js +1 -0
  32. package/app/examples/originkey/_nano/shared/lit-repeat.js +1 -0
  33. package/app/examples/originkey/_nano/shared/lit-style-map.js +1 -0
  34. package/app/examples/originkey/_nano/shared/lit.js +1 -0
  35. package/app/examples/originkey/_nano/shared/nano-core.js +1 -0
  36. package/app/examples/originkey/_nano/shared/nano-elements.js +280 -0
  37. package/app/examples/originkey/_nano/shared/typebox-value.js +1 -0
  38. package/app/examples/originkey/_nano/shared/typebox.js +1 -0
  39. package/app/examples/originkey/example.originkey.js +6 -0
  40. package/app/examples/originkey/frame.html +1 -0
  41. package/app/examples/originkey/nano.json +50 -0
  42. package/app/examples/raft/example.raft.js +30 -0
  43. package/app/examples/raft/nano.json +74 -0
  44. package/app/examples/slice/nano.json +63 -0
  45. package/app/examples/slice/shout.js +14 -0
  46. package/app/examples/template/acme.template.js +11 -0
  47. package/app/examples/template/index.js +194 -0
  48. package/app/examples/template/nano.json +32 -0
  49. package/app/examples/todo/example.todo.js +8 -0
  50. package/app/examples/todo/nano.json +77 -0
  51. package/app/examples/typing/nano.json +33 -0
  52. package/app/favicon.svg +1 -0
  53. package/app/index.html +152 -0
  54. package/app/main.js +15906 -0
  55. package/app/react/index.html +50 -0
  56. package/app/react/main.js +9 -0
  57. package/app/sandbox/boot.js +980 -0
  58. package/app/shared/chunks/nano-core-296y9rgd.js +4321 -0
  59. package/app/shared/chunks/nano-core-2zz7d74m.js +16 -0
  60. package/app/shared/chunks/nano-core-35ryhkm1.js +33 -0
  61. package/app/shared/chunks/nano-core-5a3r312d.js +866 -0
  62. package/app/shared/chunks/nano-core-89mtxedm.js +186 -0
  63. package/app/shared/chunks/nano-core-bf13r20v.js +77 -0
  64. package/app/shared/chunks/nano-core-g3414rnc.js +248 -0
  65. package/app/shared/chunks/nano-core-hyg0qdwg.js +547 -0
  66. package/app/shared/chunks/nano-core-sxgrxy03.js +53 -0
  67. package/app/shared/chunks/nano-core-wg5c961d.js +4564 -0
  68. package/app/shared/lit-class-map.js +60 -0
  69. package/app/shared/lit-decorators.js +228 -0
  70. package/app/shared/lit-directive.js +11 -0
  71. package/app/shared/lit-if-defined.js +10 -0
  72. package/app/shared/lit-ref.js +12 -0
  73. package/app/shared/lit-repeat.js +141 -0
  74. package/app/shared/lit-style-map.js +67 -0
  75. package/app/shared/lit.js +47 -0
  76. package/app/shared/nano-core.js +2348 -0
  77. package/app/shared/nano-elements.js +1178 -0
  78. package/app/shared/typebox-value.js +78 -0
  79. package/app/shared/typebox.js +580 -0
  80. package/app/shared/versions.json +6 -0
  81. package/bin/nano-app.ts +34 -0
  82. package/package.json +22 -4
  83. package/src/events.ts +11 -0
  84. package/src/serve.ts +68 -0
  85. package/src/watch.ts +27 -0
@@ -0,0 +1,1178 @@
1
+ import {
2
+ ref
3
+ } from "./chunks/nano-core-89mtxedm.js";
4
+ import {
5
+ LitElement
6
+ } from "./chunks/nano-core-bf13r20v.js";
7
+ import {
8
+ css,
9
+ unsafeCSS
10
+ } from "./chunks/nano-core-hyg0qdwg.js";
11
+ import"./chunks/nano-core-sxgrxy03.js";
12
+ import {
13
+ html,
14
+ nothing
15
+ } from "./chunks/nano-core-5a3r312d.js";
16
+ import"./chunks/nano-core-35ryhkm1.js";
17
+ import"./chunks/nano-core-2zz7d74m.js";
18
+
19
+ // ../elements/src/tokens.ts
20
+ var NANO_TOKENS = {
21
+ bg: "#0D0F13",
22
+ surface: "#14171D",
23
+ "surface-2": "#212632",
24
+ border: "#2A303C",
25
+ "border-strong": "#3A4150",
26
+ fg: "#E7E9EE",
27
+ "fg-2": "#C9CED6",
28
+ muted: "#A3AAB8",
29
+ "on-accent": "#0D0F13",
30
+ accent: "#6FA8FF",
31
+ "accent-soft": "#1C2A44",
32
+ focus: "#6FA8FF",
33
+ good: "#7EE787",
34
+ "good-bg": "#12301C",
35
+ bad: "#FFB4A8",
36
+ "bad-bg": "#3A1D1D",
37
+ warn: "#F2CC60",
38
+ "warn-bg": "#3A3016",
39
+ font: "Inter, system-ui, sans-serif",
40
+ "font-display": "Inter, system-ui, sans-serif",
41
+ "font-mono": "'JetBrains Mono', ui-monospace, monospace",
42
+ radius: "8px",
43
+ "radius-s": "6px",
44
+ s1: "#7EE787",
45
+ s2: "#F5A524",
46
+ s3: "#4CC2FF",
47
+ s4: "#FF7AB6",
48
+ s5: "#D2A8FF",
49
+ s6: "#FFA657",
50
+ s7: "#79C0FF",
51
+ s8: "#F2CC60"
52
+ };
53
+ var t = (name) => unsafeCSS(`var(--nano-${name}, ${NANO_TOKENS[name]})`);
54
+ var tv = (name) => `var(--nano-${name}, ${NANO_TOKENS[name]})`;
55
+
56
+ // ../elements/src/styles.ts
57
+ var base = css`
58
+ :host { display: block; font-family: ${t("font")}; font-size: 13px; color: ${t("fg")} }
59
+ :focus-visible { outline: 2px solid ${t("focus")}; outline-offset: 1px }
60
+
61
+ /* buttons */
62
+ button, .btn { font: inherit; font-size: 12px; color: ${t("fg")}; background: transparent; border: 1px solid ${t("border-strong")};
63
+ border-radius: ${t("radius-s")}; padding: 5px 10px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px }
64
+ button:hover, .btn:hover { background: ${t("surface-2")} }
65
+ button:disabled, .btn:disabled { opacity: .5; cursor: not-allowed }
66
+ button.primary, .btn.primary { color: ${t("on-accent")}; background: ${t("accent")}; border-color: ${t("accent")}; font-weight: 600 }
67
+ button.danger, .btn.danger { color: ${t("bad")}; border-color: ${t("bad")} }
68
+ button.dashed, .btn.dashed { border-style: dashed; font-weight: 600 }
69
+ .btn.small { font-size: 11px; padding: 2px 7px }
70
+ .icon-btn { border: 0; background: transparent; padding: 4px; border-radius: ${t("radius-s")}; color: ${t("muted")} }
71
+ .icon-btn:hover { color: ${t("fg")}; background: ${t("surface-2")} }
72
+ button[aria-pressed='true'], .btn[aria-pressed='true'] { background: ${t("surface-2")}; border-color: ${t("accent")} }
73
+
74
+ /* labels */
75
+ .badge { display: inline-block; padding: 1px 7px; border-radius: 999px; font-size: 11px; font-weight: 600; background: ${t("surface-2")}; color: ${t("fg-2")} }
76
+ .badge.good { background: ${t("good-bg")}; color: ${t("good")} } .badge.bad { background: ${t("bad-bg")}; color: ${t("bad")} }
77
+ .badge.warn { background: ${t("warn-bg")}; color: ${t("warn")} } .badge.accent { background: ${t("accent-soft")}; color: ${t("accent")} }
78
+ .chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border: 1px solid ${t("border")}; border-radius: ${t("radius-s")}; font-size: 12px }
79
+ .pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; background: ${t("surface-2")}; font-size: 12px }
80
+ .pill::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: currentColor }
81
+
82
+ /* containers and states */
83
+ .card { background: ${t("surface")}; border: 1px solid ${t("border")}; border-radius: ${t("radius")}; padding: 12px }
84
+ .alert { padding: 8px 12px; border-radius: ${t("radius-s")}; border: 1px solid ${t("border")}; background: ${t("surface-2")} }
85
+ .alert.good { background: ${t("good-bg")}; color: ${t("good")}; border-color: transparent }
86
+ .alert.bad, .problem { color: ${t("bad")} } .alert.bad { background: ${t("bad-bg")}; border-color: transparent }
87
+ .problem { font-size: 12px }
88
+
89
+ /* forms */
90
+ input, select, textarea, .input { font: inherit; font-size: 12px; color: ${t("fg")}; background: ${t("bg")}; border: 1px solid ${t("border-strong")};
91
+ border-radius: ${t("radius-s")}; padding: 4px 6px }
92
+ input[type='range'], input[type='checkbox'] { accent-color: ${t("accent")}; padding: 0 }
93
+ .field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: ${t("muted")} }
94
+ /* where the browser allows it, a bare select's open list takes the theme too */
95
+ @supports (appearance: base-select) {
96
+ select, ::picker(select) { appearance: base-select }
97
+ ::picker(select) { background: ${t("surface")}; color: ${t("fg")}; border: 1px solid ${t("border")}; border-radius: ${t("radius-s")};
98
+ padding: 4px; margin-top: 4px; box-shadow: 0 4px 16px color-mix(in srgb, ${t("bg")} 40%, transparent) }
99
+ select::picker-icon { color: ${t("muted")} }
100
+ option { padding: 5px 8px; border-radius: ${t("radius-s")} }
101
+ option:is(:hover, :focus-visible) { background: ${t("surface-2")}; outline: 0 }
102
+ option:checked { font-weight: 600 }
103
+ }
104
+ .meter { height: 6px; border-radius: 3px; background: ${t("surface-2")}; overflow: hidden }
105
+ .meter > span { display: block; height: 100%; background: ${t("accent")} }
106
+
107
+ /* data */
108
+ .table { width: 100%; border-collapse: collapse } .table th, .table td { text-align: left; padding: 5px 8px; border-bottom: 1px solid ${t("border")} }
109
+ .table th { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: ${t("muted")} }
110
+ .tabs { display: flex; gap: 2px; border-bottom: 1px solid ${t("border")} }
111
+ .tabs > button { border: 0; border-radius: 0; border-bottom: 2px solid transparent; background: none; color: ${t("muted")} }
112
+ .tabs > button:is([aria-selected='true'], [aria-pressed='true']) { color: ${t("fg")}; border-bottom-color: ${t("accent")} }
113
+ .list-row { display: flex; align-items: center; gap: 10px; padding: 8px 4px; border-bottom: 1px solid ${t("border")} }
114
+
115
+ /* type */
116
+ .kicker { font-size: 11px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: ${t("muted")} }
117
+ .display-s, .display-m, .display-l { font-family: ${t("font-display")}; font-weight: 600; letter-spacing: -.01em; margin: 0 }
118
+ .display-s { font-size: 18px } .display-m { font-size: 24px } .display-l { font-size: 34px }
119
+ .muted { color: ${t("muted")} }
120
+ .mono { font-family: ${t("font-mono")}; font-size: 11px }
121
+
122
+ /* layout */
123
+ .row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap }
124
+ .col { display: flex; flex-direction: column; gap: 8px }
125
+ .grid-auto { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px }
126
+ `;
127
+ // ../elements/src/kit.ts
128
+ var shadow = css`0 8px 24px color-mix(in srgb, black 18%, transparent), 0 1px 3px color-mix(in srgb, black 10%, transparent)`;
129
+ var kit = css`
130
+ /* people and messages */
131
+ .avatar { display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; overflow: hidden; flex: none;
132
+ background: ${t("surface-2")}; color: ${t("fg-2")}; font-size: 12px; font-weight: 600 }
133
+ .avatar > img { width: 100%; height: 100%; object-fit: cover }
134
+ .avatar.small { width: 24px; height: 24px; font-size: 10px } .avatar.large { width: 40px; height: 40px; font-size: 14px }
135
+ .avatar-stack { display: inline-flex } .avatar-stack > .avatar { box-shadow: 0 0 0 2px ${t("bg")} } .avatar-stack > .avatar + .avatar { margin-left: -8px }
136
+ .bubble { max-width: 75%; width: fit-content; padding: 8px 12px; border-radius: ${t("radius")}; background: ${t("surface-2")}; color: ${t("fg")}; line-height: 1.45 }
137
+ .bubble.mine { margin-left: auto; background: ${t("accent")}; color: ${t("on-accent")} }
138
+ .kbd { display: inline-flex; align-items: center; justify-content: center; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 4px;
139
+ border: 1px solid ${t("border")}; background: ${t("surface-2")}; color: ${t("muted")}; font: 500 11px ${t("font-mono")} }
140
+ .code { font: 12px/1.55 ${t("font-mono")}; background: ${t("surface-2")}; border: 1px solid ${t("border")}; border-radius: ${t("radius-s")};
141
+ padding: 10px 12px; margin: 0; overflow: auto; white-space: pre; color: ${t("fg")} }
142
+
143
+ /* inputs */
144
+ .input-group { display: flex; align-items: center; border: 1px solid ${t("border-strong")}; border-radius: ${t("radius-s")}; background: ${t("bg")} }
145
+ .input-group:focus-within { outline: 2px solid ${t("focus")}; outline-offset: 1px }
146
+ .input-group > input, .input-group > .input { flex: 1; min-width: 0; border: 0; background: transparent; outline: 0 }
147
+ .input-group > .addon { padding: 0 8px; color: ${t("muted")}; font-size: 12px; white-space: nowrap }
148
+ .input-group > button { border: 0; border-radius: 0; align-self: stretch }
149
+ .toggle { border-color: transparent } .toggle:hover { color: ${t("fg")} }
150
+ .toggle[aria-pressed='true'] { background: ${t("surface-2")}; border-color: transparent; color: ${t("fg")} }
151
+ .toggle-group { display: inline-flex; border: 1px solid ${t("border")}; border-radius: ${t("radius-s")}; overflow: hidden }
152
+ .toggle-group > button { border: 0; border-radius: 0 } .toggle-group > button + button { border-left: 1px solid ${t("border")} }
153
+ input[type='checkbox'].switch { appearance: none; width: 32px; height: 18px; border-radius: 999px; border: 0; padding: 0; cursor: pointer;
154
+ background: radial-gradient(circle at 9px 50%, ${t("bg")} 6px, transparent 7px), ${t("border-strong")}; transition: background-position .15s }
155
+ input[type='checkbox'].switch:checked { background: radial-gradient(circle at calc(100% - 9px) 50%, ${t("on-accent")} 6px, transparent 7px), ${t("accent")} }
156
+
157
+ /* overlays: native <dialog> (showModal()) and [popover] surfaces */
158
+ dialog.dialog, dialog.drawer { box-sizing: border-box; color: ${t("fg")}; background: ${t("surface")}; border: 1px solid ${t("border")}; box-shadow: ${shadow}; padding: 20px }
159
+ dialog.dialog { border-radius: ${t("radius")}; width: min(480px, calc(100vw - 32px)) }
160
+ dialog.drawer { margin: 0 0 0 auto; height: 100dvh; max-height: none; width: min(380px, 90vw); border-width: 0 0 0 1px; animation: nano-in-right .2s ease-out }
161
+ dialog.drawer.bottom { margin: auto 0 0; width: 100%; max-width: none; height: auto; max-height: 80dvh; border-width: 1px 0 0;
162
+ border-radius: ${t("radius")} ${t("radius")} 0 0; animation-name: nano-in-up }
163
+ dialog::backdrop { background: color-mix(in srgb, black 50%, transparent) }
164
+ dialog > header { margin-bottom: 12px } dialog > header > h2 { margin: 0 0 4px; font: 600 16px ${t("font-display")} }
165
+ dialog > header > p { margin: 0; color: ${t("muted")} }
166
+ dialog > footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px }
167
+ @keyframes nano-in-right { from { transform: translateX(100%) } }
168
+ @keyframes nano-in-up { from { transform: translateY(100%) } }
169
+ .pop { position: fixed; inset: auto; margin: 0; min-width: 8rem; padding: 4px; color: ${t("fg")}; background: ${t("surface")};
170
+ border: 1px solid ${t("border")}; border-radius: ${t("radius-s")}; box-shadow: ${shadow}; font-family: ${t("font")}; font-size: 13px }
171
+ .menu-item { display: flex; align-items: center; gap: 8px; width: 100%; padding: 6px 8px; border: 0; border-radius: ${t("radius-s")};
172
+ background: none; color: inherit; font: inherit; text-align: left; cursor: default; justify-content: flex-start }
173
+ .menu-item:is(:hover, .active) { background: ${t("surface-2")} }
174
+ .menu-item.danger { color: ${t("bad")} } .menu-item[aria-disabled='true'] { opacity: .5 }
175
+ .menu-sep { height: 1px; margin: 4px -4px; background: ${t("border")} }
176
+ .menu-label { padding: 6px 8px 2px; font-size: 11px; font-weight: 600; color: ${t("muted")} }
177
+ .shortcut { margin-left: auto; font-size: 11px; letter-spacing: .08em; color: ${t("muted")} }
178
+
179
+ /* toast */
180
+ .toast { display: flex; gap: 10px; align-items: flex-start; width: min(356px, calc(100vw - 32px)); padding: 12px 14px; color: ${t("fg")};
181
+ background: ${t("surface")}; border: 1px solid ${t("border")}; border-radius: ${t("radius")}; box-shadow: ${shadow}; animation: nano-in-up .2s ease-out }
182
+ .toast > .body { flex: 1 } .toast .title { font-weight: 600 } .toast .desc { color: ${t("muted")}; margin-top: 2px }
183
+ .toast.good { border-left: 3px solid ${t("good")} } .toast.bad { border-left: 3px solid ${t("bad")} } .toast.warn { border-left: 3px solid ${t("warn")} }
184
+ `;
185
+ // ../elements/src/kit/popup.ts
186
+ function place(pop, anchor, at) {
187
+ try {
188
+ pop.showPopover?.();
189
+ } catch {}
190
+ const r = at ? { left: at.x, top: at.y, bottom: at.y, width: 0 } : anchor.getBoundingClientRect();
191
+ const { offsetWidth: w, offsetHeight: h } = pop;
192
+ pop.style.minWidth = r.width ? `${r.width}px` : "";
193
+ pop.style.left = `${Math.max(4, Math.min(r.left, innerWidth - w - 4))}px`;
194
+ pop.style.top = `${r.bottom + 4 + h > innerHeight && r.top - h - 4 > 0 ? r.top - h - 4 : r.bottom + 4}px`;
195
+ }
196
+ var hide = (pop) => {
197
+ try {
198
+ pop.hidePopover?.();
199
+ } catch {}
200
+ };
201
+
202
+ // ../elements/src/kit/select.ts
203
+ var labelOf = (i) => i.label ?? i.value;
204
+ var CHECK = html`<svg viewBox="0 0 16 16" width="14" height="14" aria-hidden="true"><path d="M3 8.5l3 3 7-7" fill="none" stroke="currentColor" stroke-width="2"/></svg>`;
205
+ var ids = 0;
206
+
207
+ class NanoCommand extends LitElement {
208
+ static shadowRootOptions = { ...LitElement.shadowRootOptions, delegatesFocus: true };
209
+ static properties = { items: { attribute: false }, selected: { attribute: false }, placeholder: {}, q: { state: true }, active: { state: true } };
210
+ static styles = [base, kit, css`
211
+ :host { display: block; min-width: 220px }
212
+ .search { display: flex; align-items: center; gap: 6px; padding: 0 8px; border-bottom: 1px solid ${t("border")}; color: ${t("muted")} }
213
+ .search input { flex: 1; border: 0; background: none; outline: 0; padding: 9px 0; font-size: 13px }
214
+ [role='listbox'] { max-height: 260px; overflow: auto; padding: 4px }
215
+ .menu-item .check { width: 14px; display: inline-flex }
216
+ .menu-item[aria-disabled='true'] { pointer-events: none }
217
+ .empty { padding: 18px 8px; text-align: center; color: ${t("muted")} }`];
218
+ uid = `c${++ids}`;
219
+ constructor() {
220
+ super();
221
+ this.items = [];
222
+ this.selected = [];
223
+ this.placeholder = "Search…";
224
+ this.q = "";
225
+ this.active = 0;
226
+ }
227
+ get shown() {
228
+ const q = this.q.toLowerCase();
229
+ return this.items.filter((i) => labelOf(i).toLowerCase().includes(q));
230
+ }
231
+ reset() {
232
+ this.q = "";
233
+ this.active = 0;
234
+ }
235
+ pick(i) {
236
+ if (i && !i.disabled)
237
+ this.dispatchEvent(new CustomEvent("pick", { detail: i, bubbles: true, composed: true }));
238
+ }
239
+ onKey(e) {
240
+ const n = this.shown.length;
241
+ if (e.key === "ArrowDown" || e.key === "ArrowUp") {
242
+ e.preventDefault();
243
+ if (n)
244
+ this.active = (this.active + (e.key === "ArrowDown" ? 1 : -1) + n) % n;
245
+ } else if (e.key === "Enter") {
246
+ e.preventDefault();
247
+ this.pick(this.shown[this.active]);
248
+ }
249
+ }
250
+ updated() {
251
+ this.renderRoot.querySelector(".active")?.scrollIntoView?.({ block: "nearest" });
252
+ }
253
+ render() {
254
+ const shown = this.shown;
255
+ let group;
256
+ return html`<div class="search"><svg viewBox="0 0 16 16" width="14" height="14" aria-hidden="true"><circle cx="7" cy="7" r="4.5" fill="none" stroke="currentColor" stroke-width="1.5"/><path d="M10.5 10.5L14 14" stroke="currentColor" stroke-width="1.5"/></svg>
257
+ <input role="combobox" aria-expanded="true" aria-controls=${`${this.uid}-list`} aria-autocomplete="list" placeholder=${this.placeholder} .value=${this.q}
258
+ aria-activedescendant=${shown.length ? `${this.uid}-${this.active}` : nothing}
259
+ @input=${(e) => {
260
+ this.q = e.target.value;
261
+ this.active = 0;
262
+ }} @keydown=${this.onKey}></div>
263
+ <div role="listbox" id=${`${this.uid}-list`} aria-multiselectable=${this.selected.length > 1 ? "true" : nothing}>
264
+ ${shown.length ? shown.map((i, n) => {
265
+ const head = i.group && i.group !== group ? html`<div class="menu-label" role="presentation">${i.group}</div>` : nothing;
266
+ group = i.group;
267
+ return html`${head}<div role="option" id=${`${this.uid}-${n}`} data-value=${i.value} class="menu-item ${n === this.active ? "active" : ""}"
268
+ aria-selected=${String(this.selected.includes(i.value))} aria-disabled=${i.disabled ? "true" : nothing}
269
+ @pointermove=${() => {
270
+ this.active = n;
271
+ }} @click=${() => this.pick(i)}>
272
+ <span class="check">${this.selected.includes(i.value) ? CHECK : nothing}</span>${labelOf(i)}${i.shortcut ? html`<span class="shortcut">${i.shortcut}</span>` : nothing}</div>`;
273
+ }) : html`<div class="empty">No results.</div>`}</div>`;
274
+ }
275
+ }
276
+
277
+ class NanoSelect extends LitElement {
278
+ static properties = { options: { attribute: false }, value: { attribute: false }, multiple: { type: Boolean }, placeholder: {}, label: {}, open: { state: true } };
279
+ static styles = [base, kit, css`
280
+ :host { display: inline-block; min-width: 180px }
281
+ [role='combobox'] { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; min-height: 30px; padding: 3px 8px; cursor: pointer;
282
+ border: 1px solid ${t("border-strong")}; border-radius: ${t("radius-s")}; background: ${t("bg")}; font-size: 12px }
283
+ .placeholder { color: ${t("muted")} } .chev { margin-left: auto; color: ${t("muted")} }
284
+ .chip { padding: 0 2px 0 6px; background: ${t("surface-2")}; border-color: transparent }
285
+ .chip button { border: 0; padding: 0 4px; background: none; color: ${t("muted")} }
286
+ .pop { padding: 0 }`];
287
+ constructor() {
288
+ super();
289
+ this.options = [];
290
+ this.value = "";
291
+ this.multiple = false;
292
+ this.placeholder = "Select…";
293
+ this.label = "";
294
+ this.open = false;
295
+ }
296
+ get items() {
297
+ return this.options.map((o) => typeof o === "string" ? { value: o } : o);
298
+ }
299
+ get chosen() {
300
+ return Array.isArray(this.value) ? this.value : this.value ? [this.value] : [];
301
+ }
302
+ labelFor = (v) => labelOf(this.items.find((i) => i.value === v) ?? { value: v });
303
+ get pop() {
304
+ return this.renderRoot.querySelector(".pop");
305
+ }
306
+ get trigger() {
307
+ return this.renderRoot.querySelector('[role="combobox"]');
308
+ }
309
+ set(v) {
310
+ this.value = v;
311
+ this.dispatchEvent(new Event("change", { bubbles: true, composed: true }));
312
+ }
313
+ show(on) {
314
+ if (on === this.open)
315
+ return;
316
+ this.open = on;
317
+ const cmd = this.renderRoot.querySelector("nano-command");
318
+ if (on) {
319
+ cmd.reset();
320
+ place(this.pop, this.trigger);
321
+ cmd.focus();
322
+ } else {
323
+ hide(this.pop);
324
+ this.trigger.focus();
325
+ }
326
+ }
327
+ onPick(e) {
328
+ const v = e.detail.value;
329
+ if (!this.multiple) {
330
+ this.set(v);
331
+ this.show(false);
332
+ return;
333
+ }
334
+ this.set(this.chosen.includes(v) ? this.chosen.filter((x) => x !== v) : [...this.chosen, v]);
335
+ }
336
+ onKey(e) {
337
+ if (e.key === "Escape") {
338
+ e.preventDefault();
339
+ this.show(false);
340
+ } else if (e.target === this.trigger && ["ArrowDown", "Enter", " "].includes(e.key)) {
341
+ e.preventDefault();
342
+ this.show(true);
343
+ } else if (e.target === this.trigger && e.key === "Backspace" && this.multiple && this.chosen.length)
344
+ this.set(this.chosen.slice(0, -1));
345
+ }
346
+ render() {
347
+ const chosen = this.chosen;
348
+ const shown = !chosen.length ? html`<span class="placeholder">${this.placeholder}</span>` : this.multiple ? chosen.map((v) => html`<span class="chip">${this.labelFor(v)}<button tabindex="-1" aria-label=${`Remove ${this.labelFor(v)}`}
349
+ @click=${(e) => {
350
+ e.stopPropagation();
351
+ this.set(chosen.filter((x) => x !== v));
352
+ }}>×</button></span>`) : this.labelFor(chosen[0]);
353
+ return html`<div role="combobox" tabindex="0" aria-label=${this.label || nothing} aria-haspopup="listbox" aria-expanded=${String(this.open)} @click=${() => this.show(!this.open)} @keydown=${this.onKey}>
354
+ ${shown}<svg class="chev" viewBox="0 0 16 16" width="14" height="14" aria-hidden="true"><path d="M4 6l4 4 4-4" fill="none" stroke="currentColor" stroke-width="1.5"/></svg></div>
355
+ <div class="pop" popover="auto" @toggle=${(e) => {
356
+ if (e.newState === "closed")
357
+ this.open = false;
358
+ }} @keydown=${this.onKey}>
359
+ <nano-command .items=${this.items} .selected=${chosen} @pick=${this.onPick}></nano-command></div>`;
360
+ }
361
+ }
362
+ for (const [tag, cls] of [["nano-command", NanoCommand], ["nano-select", NanoSelect]])
363
+ if (globalThis.customElements && !customElements.get(tag))
364
+ customElements.define(tag, cls);
365
+ // ../elements/src/kit/calendar.ts
366
+ var pad = (n) => String(n).padStart(2, "0");
367
+ var iso = (d) => `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`;
368
+ var parse = (s) => {
369
+ const [y, m, d] = s.split("-").map(Number);
370
+ return y && m && d ? new Date(y, m - 1, d) : undefined;
371
+ };
372
+ var addDays = (s, n) => {
373
+ const d = parse(s);
374
+ d.setDate(d.getDate() + n);
375
+ return iso(d);
376
+ };
377
+ var DOW = ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"];
378
+ var chevron = (d) => html`<svg viewBox="0 0 16 16" width="14" height="14" aria-hidden="true"><path d=${d} fill="none" stroke="currentColor" stroke-width="1.5"/></svg>`;
379
+
380
+ class NanoCalendar extends LitElement {
381
+ static properties = { value: {}, view: { state: true }, focusDate: { state: true } };
382
+ static styles = [base, kit, css`
383
+ :host { display: inline-block; padding: 8px }
384
+ .head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px }
385
+ .caption { font-weight: 600 } .head .icon-btn { width: 28px; height: 28px; border: 1px solid ${t("border")} }
386
+ table { border-collapse: collapse } th { width: 32px; font-size: 11px; font-weight: 400; color: ${t("muted")}; padding-bottom: 4px }
387
+ td { padding: 1px } td button { width: 32px; height: 32px; padding: 0; border: 0; border-radius: ${t("radius-s")}; font-size: 12px }
388
+ button.outside { color: ${t("muted")}; opacity: .6 } button.today { background: ${t("surface-2")} }
389
+ button[aria-selected='true'] { background: ${t("accent")}; color: ${t("on-accent")}; opacity: 1 }`];
390
+ constructor() {
391
+ super();
392
+ this.value = "";
393
+ const now = new Date;
394
+ this.view = { y: now.getFullYear(), m: now.getMonth() };
395
+ this.focusDate = "";
396
+ }
397
+ willUpdate(changed) {
398
+ const d = parse(this.value);
399
+ if (changed.has("value") && d) {
400
+ this.view = { y: d.getFullYear(), m: d.getMonth() };
401
+ this.focusDate = this.value;
402
+ }
403
+ }
404
+ shift(n) {
405
+ const d = new Date(this.view.y, this.view.m + n, 1);
406
+ this.view = { y: d.getFullYear(), m: d.getMonth() };
407
+ this.focusDate = iso(d);
408
+ }
409
+ focus() {
410
+ this.renderRoot.querySelector('[tabindex="0"]')?.focus();
411
+ }
412
+ pick(date) {
413
+ this.value = date;
414
+ this.dispatchEvent(new Event("change", { bubbles: true, composed: true }));
415
+ }
416
+ onKey(e) {
417
+ const step = { ArrowLeft: -1, ArrowRight: 1, ArrowUp: -7, ArrowDown: 7 }[e.key];
418
+ const from = this.focusDate || iso(new Date(this.view.y, this.view.m, 1));
419
+ if (step) {
420
+ e.preventDefault();
421
+ this.focusDate = addDays(from, step);
422
+ const d = parse(this.focusDate);
423
+ this.view = { y: d.getFullYear(), m: d.getMonth() };
424
+ this.updateComplete.then(() => this.renderRoot.querySelector('[tabindex="0"]')?.focus());
425
+ } else if (e.key === "Enter" || e.key === " ") {
426
+ e.preventDefault();
427
+ this.pick(from);
428
+ }
429
+ }
430
+ render() {
431
+ const { y, m } = this.view;
432
+ const first = new Date(y, m, 1);
433
+ const days = Array.from({ length: 42 }, (_, i) => new Date(y, m, 1 - first.getDay() + i));
434
+ const today = iso(new Date);
435
+ const focus = this.focusDate.startsWith(`${y}-${pad(m + 1)}-`) ? this.focusDate : iso(first);
436
+ return html`<div class="head">
437
+ <button class="icon-btn" aria-label="Previous month" @click=${() => this.shift(-1)}>${chevron("M10 4L6 8l4 4")}</button>
438
+ <span class="caption" aria-live="polite">${first.toLocaleString("en", { month: "long" })} ${y}</span>
439
+ <button class="icon-btn" aria-label="Next month" @click=${() => this.shift(1)}>${chevron("M6 4l4 4-4 4")}</button></div>
440
+ <table role="grid" @keydown=${this.onKey}><thead><tr>${DOW.map((d) => html`<th scope="col">${d}</th>`)}</tr></thead><tbody>
441
+ ${[0, 1, 2, 3, 4, 5].map((w) => html`<tr>${days.slice(w * 7, w * 7 + 7).map((d) => {
442
+ const s = iso(d);
443
+ return html`<td role="gridcell"><button data-date=${s} tabindex=${s === focus ? "0" : "-1"} aria-selected=${s === this.value ? "true" : nothing}
444
+ class="${d.getMonth() !== m ? "outside" : ""} ${s === today ? "today" : ""}" @click=${() => {
445
+ this.focusDate = s;
446
+ this.pick(s);
447
+ }}>${d.getDate()}</button></td>`;
448
+ })}</tr>`)}</tbody></table>`;
449
+ }
450
+ }
451
+
452
+ class NanoDatePicker extends LitElement {
453
+ static properties = { value: {}, placeholder: {}, open: { state: true } };
454
+ static styles = [base, kit, css`
455
+ :host { display: inline-block } .trigger { min-width: 200px; justify-content: flex-start; background: ${t("bg")} }
456
+ .trigger .muted { font-weight: 400 } .pop { padding: 0 }`];
457
+ constructor() {
458
+ super();
459
+ this.value = "";
460
+ this.placeholder = "Pick a date";
461
+ this.open = false;
462
+ }
463
+ get pop() {
464
+ return this.renderRoot.querySelector(".pop");
465
+ }
466
+ get trigger() {
467
+ return this.renderRoot.querySelector(".trigger");
468
+ }
469
+ show(on) {
470
+ this.open = on;
471
+ if (on) {
472
+ place(this.pop, this.trigger);
473
+ this.renderRoot.querySelector("nano-calendar").focus();
474
+ } else
475
+ hide(this.pop);
476
+ }
477
+ onChange(e) {
478
+ e.stopPropagation();
479
+ this.value = e.target.value;
480
+ this.dispatchEvent(new Event("change", { bubbles: true, composed: true }));
481
+ this.show(false);
482
+ this.trigger.focus();
483
+ }
484
+ render() {
485
+ const d = parse(this.value);
486
+ return html`<button class="trigger" aria-haspopup="dialog" aria-expanded=${String(this.open)} @click=${() => this.show(!this.open)}>
487
+ <svg viewBox="0 0 16 16" width="14" height="14" aria-hidden="true"><rect x="2" y="3" width="12" height="11" rx="2" fill="none" stroke="currentColor" stroke-width="1.3"/><path d="M2 6.5h12M5 1.5v3M11 1.5v3" stroke="currentColor" stroke-width="1.3"/></svg>
488
+ ${d ? d.toLocaleDateString("en", { month: "short", day: "numeric", year: "numeric" }) : html`<span class="muted">${this.placeholder}</span>`}</button>
489
+ <div class="pop" popover="auto" role="dialog" aria-label="Choose a date" @toggle=${(e) => {
490
+ if (e.newState === "closed")
491
+ this.open = false;
492
+ }}
493
+ @keydown=${(e) => {
494
+ if (e.key === "Escape") {
495
+ e.preventDefault();
496
+ this.show(false);
497
+ }
498
+ }}>
499
+ <nano-calendar .value=${this.value} @change=${this.onChange}></nano-calendar></div>`;
500
+ }
501
+ }
502
+ for (const [tag, cls] of [["nano-calendar", NanoCalendar], ["nano-date-picker", NanoDatePicker]])
503
+ if (globalThis.customElements && !customElements.get(tag))
504
+ customElements.define(tag, cls);
505
+ // ../elements/src/kit/overlays.ts
506
+ var pickable = (i) => ("label" in i) && !i.disabled;
507
+ var menus = 0;
508
+ var define = (tag, cls) => {
509
+ if (globalThis.customElements && !customElements.get(tag))
510
+ customElements.define(tag, cls);
511
+ };
512
+
513
+ class NanoMenu extends LitElement {
514
+ static properties = { items: { attribute: false }, open: { type: Boolean, reflect: true }, active: { state: true } };
515
+ static styles = [base, kit, css`:host { display: contents } [role='menu'] { outline: 0; min-width: 12rem }`];
516
+ constructor() {
517
+ super();
518
+ this.items = [];
519
+ this.open = false;
520
+ this.active = -1;
521
+ this.addEventListener("contextmenu", (e) => {
522
+ e.preventDefault();
523
+ this.show({ x: e.clientX, y: e.clientY });
524
+ });
525
+ }
526
+ uid = `m${++menus}`;
527
+ get menu() {
528
+ return this.renderRoot.querySelector('[role="menu"]');
529
+ }
530
+ async show(at) {
531
+ this.open = true;
532
+ this.active = this.items.findIndex(pickable);
533
+ await this.updateComplete;
534
+ place(this.menu, this, at);
535
+ this.menu.focus();
536
+ }
537
+ close() {
538
+ this.open = false;
539
+ hide(this.menu);
540
+ }
541
+ pick(i) {
542
+ if (!i || !pickable(i))
543
+ return;
544
+ this.dispatchEvent(new CustomEvent("pick", { detail: i, bubbles: true, composed: true }));
545
+ this.close();
546
+ }
547
+ onKey(e) {
548
+ const step = e.key === "ArrowDown" ? 1 : e.key === "ArrowUp" ? -1 : 0;
549
+ if (step) {
550
+ e.preventDefault();
551
+ for (let n = 1, len = this.items.length;n <= len; n++) {
552
+ const i = (this.active + step * n + len) % len;
553
+ if (pickable(this.items[i])) {
554
+ this.active = i;
555
+ break;
556
+ }
557
+ }
558
+ } else if (e.key === "Enter" || e.key === " ") {
559
+ e.preventDefault();
560
+ this.pick(this.items[this.active]);
561
+ } else if (e.key === "Escape") {
562
+ e.preventDefault();
563
+ this.close();
564
+ }
565
+ }
566
+ render() {
567
+ return html`<slot></slot><div class="pop" popover="auto" role="menu" tabindex="-1" aria-activedescendant=${this.active >= 0 ? `${this.uid}-${this.active}` : nothing} @keydown=${this.onKey}
568
+ @toggle=${(e) => {
569
+ if (e.newState === "closed")
570
+ this.open = false;
571
+ }}>
572
+ ${this.items.map((i, n) => ("separator" in i) ? html`<div class="menu-sep" role="separator"></div>` : ("heading" in i) ? html`<div class="menu-label">${i.heading}</div>` : html`<div role="menuitem" id=${`${this.uid}-${n}`} class="menu-item ${i.danger ? "danger" : ""} ${n === this.active ? "active" : ""}" aria-disabled=${i.disabled ? "true" : nothing}
573
+ @pointermove=${() => {
574
+ if (!i.disabled)
575
+ this.active = n;
576
+ }} @click=${() => this.pick(i)}>${i.label}${i.shortcut ? html`<span class="shortcut">${i.shortcut}</span>` : nothing}</div>`)}</div>`;
577
+ }
578
+ }
579
+
580
+ class NanoHoverCard extends LitElement {
581
+ static properties = { open: { type: Boolean, reflect: true }, openDelay: { type: Number, attribute: "open-delay" }, closeDelay: { type: Number, attribute: "close-delay" } };
582
+ static styles = [base, kit, css`:host { display: inline-block } .pop { width: 280px; padding: 14px }`];
583
+ timer;
584
+ constructor() {
585
+ super();
586
+ this.open = false;
587
+ this.openDelay = 500;
588
+ this.closeDelay = 200;
589
+ }
590
+ later(open) {
591
+ clearTimeout(this.timer);
592
+ this.timer = setTimeout(() => {
593
+ this.open = open;
594
+ }, open ? this.openDelay : this.closeDelay);
595
+ }
596
+ updated(changed) {
597
+ if (!changed.has("open"))
598
+ return;
599
+ const pop = this.renderRoot.querySelector(".pop");
600
+ if (this.open)
601
+ place(pop, this.renderRoot.querySelector(".trigger"));
602
+ else
603
+ hide(pop);
604
+ pop.style.minWidth = "";
605
+ }
606
+ render() {
607
+ const on = () => this.later(true), off = () => this.later(false);
608
+ return html`<span class="trigger" @pointerenter=${on} @pointerleave=${off} @focusin=${on} @focusout=${off}><slot></slot></span>
609
+ <div class="pop" popover="manual" @pointerenter=${on} @pointerleave=${off}><slot name="card"></slot></div>`;
610
+ }
611
+ }
612
+ var toastIds = 0;
613
+
614
+ class NanoToaster extends LitElement {
615
+ static properties = { toasts: { state: true } };
616
+ static styles = [base, kit, css`:host { position: fixed; right: 16px; bottom: 16px; z-index: 1000 } ol { display: flex; flex-direction: column; gap: 8px; margin: 0; padding: 0; list-style: none }`];
617
+ constructor() {
618
+ super();
619
+ this.toasts = [];
620
+ }
621
+ add(toast) {
622
+ this.toasts = [...this.toasts, toast];
623
+ if (toast.duration !== 0)
624
+ setTimeout(() => this.dismiss(toast.id), toast.duration ?? 4000);
625
+ }
626
+ dismiss(id) {
627
+ this.toasts = this.toasts.filter((x) => x.id !== id);
628
+ }
629
+ render() {
630
+ return html`<ol aria-live="polite">${this.toasts.map((x) => html`<li class="toast ${x.variant ?? ""}" role="status">
631
+ <div class="body"><div class="title">${x.title}</div>${x.description ? html`<div class="desc">${x.description}</div>` : nothing}</div>
632
+ <button class="icon-btn" aria-label="Close" @click=${() => this.dismiss(x.id)}>✕</button></li>`)}</ol>`;
633
+ }
634
+ }
635
+ function toast(title, opts = {}) {
636
+ const el = document.querySelector("nano-toaster") ?? document.body.appendChild(document.createElement("nano-toaster"));
637
+ const id = ++toastIds;
638
+ el.add({ id, title, ...opts });
639
+ return id;
640
+ }
641
+
642
+ class NanoCodeBlock extends LitElement {
643
+ static properties = { code: {}, language: {}, copied: { state: true } };
644
+ static styles = [base, kit, css`
645
+ .frame { position: relative } .bar { position: absolute; top: 4px; right: 4px; display: flex; align-items: center; gap: 6px }
646
+ .lang { font-size: 11px; color: ${t("muted")} } pre.code { padding-right: 90px }`];
647
+ constructor() {
648
+ super();
649
+ this.code = "";
650
+ this.language = "";
651
+ this.copied = false;
652
+ }
653
+ async copy() {
654
+ await navigator.clipboard?.writeText(this.code);
655
+ this.copied = true;
656
+ setTimeout(() => {
657
+ this.copied = false;
658
+ }, 1500);
659
+ }
660
+ render() {
661
+ return html`<div class="frame"><pre class="code">${this.code}</pre><div class="bar"><span class="lang">${this.language}</span>
662
+ <button class="icon-btn" aria-label="Copy" @click=${this.copy}>${this.copied ? "✓ Copied" : "Copy"}</button></div></div>`;
663
+ }
664
+ }
665
+ define("nano-menu", NanoMenu);
666
+ define("nano-hover-card", NanoHoverCard);
667
+ define("nano-toaster", NanoToaster);
668
+ define("nano-code-block", NanoCodeBlock);
669
+ // ../elements/src/attrs.ts
670
+ var was = new WeakMap;
671
+ function setAttrs(el, all = {}) {
672
+ if (!el)
673
+ return;
674
+ const attrs = Object.fromEntries(Object.entries(all).filter(([k]) => /^[a-z][a-z0-9-]*$/.test(k)));
675
+ for (const k of was.get(el) ?? [])
676
+ if (!(k in attrs))
677
+ el.removeAttribute(k);
678
+ for (const [k, v] of Object.entries(attrs))
679
+ v === undefined ? el.removeAttribute(k) : el.setAttribute(k, v);
680
+ was.set(el, Object.keys(attrs));
681
+ }
682
+
683
+ // ../elements/src/kit/data-table.ts
684
+ var STEP = 10;
685
+ var cell = (r, k) => String(r[k] ?? "");
686
+ var compare = (a, b) => typeof a === "number" && typeof b === "number" ? a - b : String(a ?? "").localeCompare(String(b ?? ""), undefined, { numeric: true });
687
+
688
+ class NanoDataTable extends LitElement {
689
+ static properties = {
690
+ columns: { attribute: false },
691
+ rowAttrs: { attribute: false },
692
+ rows: { attribute: false },
693
+ filter: { type: Boolean },
694
+ selectable: { type: Boolean },
695
+ pageSize: { type: Number, attribute: "page-size" },
696
+ widths: { state: true },
697
+ q: { state: true },
698
+ sort: { state: true },
699
+ page: { state: true },
700
+ picked: { state: true }
701
+ };
702
+ static styles = [base, kit, css`
703
+ .frame { border: 1px solid ${t("border")}; border-radius: ${t("radius")}; overflow: auto }
704
+ .table { margin: 0 } .table tr:last-child td { border-bottom: 0 } .table tbody tr:hover { background: ${t("surface-2")} }
705
+ .table tr[data-mark] { background: ${t("warn-bg")}; box-shadow: inset 3px 0 ${t("warn")} } .table tr[aria-selected='true'] { background: ${t("surface-2")} } .table .right { text-align: right } .table .tick { width: 28px }
706
+ th button { border: 0; padding: 0; background: none; font: inherit; color: inherit; letter-spacing: inherit; text-transform: inherit }
707
+ .filter { width: min(280px, 100%); margin-bottom: 10px } .empty { text-align: center; padding: 24px; color: ${t("muted")} }
708
+ th { position: relative } .fixed { table-layout: fixed } .fixed td, .fixed th { overflow: hidden; text-overflow: ellipsis }
709
+ .resize { position: absolute; top: 0; right: 0; bottom: 0; width: 6px; cursor: col-resize; touch-action: none }
710
+ .resize:hover, .resize:focus-visible { background: ${t("border")}; outline: none }
711
+ .foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 10px; color: ${t("muted")}; font-size: 12px }`];
712
+ constructor() {
713
+ super();
714
+ this.columns = [];
715
+ this.rows = [];
716
+ this.filter = false;
717
+ this.selectable = false;
718
+ this.pageSize = 0;
719
+ this.widths = {};
720
+ this.q = "";
721
+ this.page = 0;
722
+ this.picked = new Set;
723
+ }
724
+ get shown() {
725
+ const q = this.q.toLowerCase();
726
+ const rows = q ? this.rows.filter((r) => this.columns.some((c) => cell(r, c.key).toLowerCase().includes(q))) : [...this.rows];
727
+ const s = this.sort;
728
+ return s ? rows.sort((a, b) => compare(a[s.key], b[s.key]) * s.dir) : rows;
729
+ }
730
+ measured = {};
731
+ updated() {
732
+ if (this.isFixed())
733
+ return;
734
+ let moved = false;
735
+ for (const c of this.columns) {
736
+ const w = this.renderRoot.querySelector(`th[data-key="${c.key}"]`)?.offsetWidth || 120;
737
+ if (this.measured[c.key] !== w) {
738
+ this.measured[c.key] = w;
739
+ moved = true;
740
+ }
741
+ }
742
+ if (moved)
743
+ this.requestUpdate();
744
+ }
745
+ isFixed() {
746
+ return this.columns.some((c) => (this.widths[c.key] ?? c.width) !== undefined);
747
+ }
748
+ widthOf(c) {
749
+ return this.widths[c.key] ?? c.width ?? this.measured[c.key] ?? 120;
750
+ }
751
+ resize(c, px) {
752
+ const all = this.isFixed() ? this.widths : Object.fromEntries(this.columns.map((x) => [x.key, this.widthOf(x)]));
753
+ this.widths = { ...all, [c.key]: Math.max(c.minWidth ?? 60, Math.round(px)) };
754
+ }
755
+ drag(c, e) {
756
+ e.preventDefault();
757
+ e.stopPropagation();
758
+ const x0 = e.clientX, w0 = this.widthOf(c);
759
+ const move = (m) => this.resize(c, w0 + m.clientX - x0);
760
+ const up = () => {
761
+ removeEventListener("pointermove", move);
762
+ removeEventListener("pointerup", up);
763
+ };
764
+ addEventListener("pointermove", move);
765
+ addEventListener("pointerup", up);
766
+ }
767
+ nudge(c, e) {
768
+ const d = e.key === "ArrowRight" ? STEP : e.key === "ArrowLeft" ? -STEP : 0;
769
+ if (d) {
770
+ e.preventDefault();
771
+ this.resize(c, this.widthOf(c) + d);
772
+ }
773
+ }
774
+ sortBy(key) {
775
+ this.sort = this.sort?.key === key && this.sort.dir === 1 ? { key, dir: -1 } : { key, dir: 1 };
776
+ }
777
+ pick(rows, on) {
778
+ const next = new Set(this.picked);
779
+ for (const r of rows)
780
+ on ? next.add(r) : next.delete(r);
781
+ this.picked = next;
782
+ this.dispatchEvent(new CustomEvent("selection", { detail: this.rows.filter((r) => next.has(r)), bubbles: true, composed: true }));
783
+ }
784
+ render() {
785
+ const all = this.shown, size = this.pageSize || all.length || 1, pages = Math.max(1, Math.ceil(all.length / size));
786
+ const page = Math.min(this.page, pages - 1), rows = all.slice(page * size, page * size + size);
787
+ const fixed = this.isFixed();
788
+ const total = this.columns.reduce((n, c) => n + this.widthOf(c), this.selectable ? 28 : 0);
789
+ const allPicked = rows.length > 0 && rows.every((r) => this.picked.has(r));
790
+ const head = (c) => {
791
+ const sorted = this.sort?.key === c.key ? this.sort.dir === 1 ? "ascending" : "descending" : undefined;
792
+ return html`<th data-key=${c.key} class=${c.align ?? ""} aria-sort=${c.sortable ? sorted ?? "none" : nothing}>${c.sortable ? html`<button @click=${() => this.sortBy(c.key)}>${c.label} ${sorted === "ascending" ? "↑" : sorted === "descending" ? "↓" : "↕"}</button>` : c.label}<span
793
+ class="resize" role="separator" aria-orientation="vertical" tabindex="0" aria-label="Resize ${c.label}" aria-valuemin=${c.minWidth ?? 60}
794
+ aria-valuenow=${this.widthOf(c)} @pointerdown=${(e) => this.drag(c, e)} @keydown=${(e) => this.nudge(c, e)}
795
+ @click=${(e) => e.stopPropagation()}></span></th>`;
796
+ };
797
+ return html`${this.filter ? html`<input class="input filter" placeholder="Filter…" aria-label="Filter rows" .value=${this.q}
798
+ @input=${(e) => {
799
+ this.q = e.target.value;
800
+ this.page = 0;
801
+ }}>` : nothing}
802
+ <div class="frame"><table class="table ${fixed ? "fixed" : ""}" style=${fixed ? `width: ${total}px` : ""}>${fixed ? html`<colgroup>${this.selectable ? html`<col style="width: 28px">` : nothing}
803
+ ${this.columns.map((c) => html`<col style="width: ${this.widthOf(c)}px">`)}</colgroup>` : nothing}<thead><tr>
804
+ ${this.selectable ? html`<th class="tick"><input type="checkbox" aria-label="Select all" .checked=${allPicked} @click=${() => this.pick(rows, !allPicked)}></th>` : nothing}
805
+ ${this.columns.map(head)}</tr></thead><tbody>
806
+ ${rows.length ? rows.map((r) => html`<tr aria-selected=${this.selectable ? String(this.picked.has(r)) : nothing} ${ref((el) => setAttrs(el, this.rowAttrs?.(r)))}>
807
+ ${this.selectable ? html`<td class="tick"><input type="checkbox" aria-label="Select row" .checked=${this.picked.has(r)} @click=${() => this.pick([r], !this.picked.has(r))}></td>` : nothing}
808
+ ${this.columns.map((c) => html`<td data-key=${c.key} class=${c.align ?? ""}>${c.render ? c.render(r) : cell(r, c.key)}</td>`)}</tr>`) : html`<tr><td class="empty" colspan=${this.columns.length + (this.selectable ? 1 : 0)}>No results.</td></tr>`}</tbody></table></div>
809
+ ${this.selectable || this.pageSize ? html`<div class="foot"><span>${this.selectable ? `${this.picked.size} of ${this.rows.length} row(s) selected.` : ""}</span>
810
+ ${this.pageSize ? html`<span class="pages row">Page ${page + 1} of ${pages}
811
+ <button class="btn small" aria-label="Previous page" ?disabled=${page === 0} @click=${() => {
812
+ this.page = page - 1;
813
+ }}>‹</button>
814
+ <button class="btn small" aria-label="Next page" ?disabled=${page >= pages - 1} @click=${() => {
815
+ this.page = page + 1;
816
+ }}>›</button></span>` : nothing}</div>` : nothing}`;
817
+ }
818
+ }
819
+ if (globalThis.customElements && !customElements.get("nano-data-table"))
820
+ customElements.define("nano-data-table", NanoDataTable);
821
+ // ../elements/src/agent/parts.ts
822
+ var json = (v) => typeof v === "string" ? v : JSON.stringify(v, null, 2);
823
+ var STATE = { "input-streaming": ["Pending", ""], "input-available": ["Running", "accent"], "output-available": ["Completed", "good"], "output-error": ["Error", "bad"] };
824
+ var AGENT = { running: ["Running", "accent"], completed: ["Completed", "good"], error: ["Error", "bad"] };
825
+ var ITEM = { completed: "✓", in_progress: "◐", pending: "○" };
826
+ var define2 = (tag, cls) => {
827
+ if (globalThis.customElements && !customElements.get(tag))
828
+ customElements.define(tag, cls);
829
+ };
830
+ var agentStyles = css`
831
+ details.card { padding: 0 } details.card > summary { display: flex; align-items: center; gap: 8px; padding: 9px 12px; cursor: pointer; list-style: none }
832
+ details.card > summary::-webkit-details-marker { display: none }
833
+ details.card > summary::after { content: '▾'; margin-left: 8px; color: ${t("muted")}; transition: transform .15s } details.card:not([open]) > summary::after { transform: rotate(-90deg) }
834
+ details.card > summary .badge { margin-left: auto } .body { padding: 0 12px 12px; display: flex; flex-direction: column; gap: 10px }
835
+ .name { font-weight: 600 } .kicker { margin-bottom: 4px } .code { max-height: 220px }`;
836
+
837
+ class NanoTool extends LitElement {
838
+ static properties = { tool: { attribute: false } };
839
+ static styles = [base, kit, agentStyles];
840
+ render() {
841
+ const p = this.tool;
842
+ if (!p)
843
+ return nothing;
844
+ const [label, tone] = STATE[p.state];
845
+ return html`<details class="card" ?open=${p.state === "output-error"}><summary>
846
+ <svg viewBox="0 0 16 16" width="14" height="14" aria-hidden="true"><path d="M10.5 2.5a3 3 0 0 0-3.9 3.9L2.5 10.5l3 3 4.1-4.1a3 3 0 0 0 3.9-3.9l-2 2-2-2z" fill="none" stroke="currentColor" stroke-width="1.3"/></svg>
847
+ <span class="name">${p.toolName ?? p.type.replace(/^tool-/, "")}</span><span class="badge ${tone}">${label}</span></summary>
848
+ <div class="body">
849
+ <div data-part="input"><div class="kicker">Parameters</div><pre class="code">${json(p.input ?? {})}</pre></div>
850
+ ${p.state === "output-available" ? html`<div data-part="output"><div class="kicker">Result</div><pre class="code">${json(p.output)}</pre></div>` : nothing}
851
+ ${p.state === "output-error" ? html`<div class="alert bad">${p.errorText ?? "The tool failed."}</div>` : nothing}</div></details>`;
852
+ }
853
+ }
854
+
855
+ class NanoTask extends LitElement {
856
+ static properties = { task: { attribute: false } };
857
+ static styles = [base, kit, agentStyles, css`
858
+ ul { list-style: none; margin: 0; padding: 0 12px 12px; display: flex; flex-direction: column; gap: 6px }
859
+ li { display: flex; gap: 8px; align-items: baseline } .icon { width: 14px; color: ${t("muted")} }
860
+ li[data-status='completed'] { color: ${t("muted")} } li[data-status='completed'] .icon { color: ${t("good")} } li[data-status='in_progress'] .icon { color: ${t("accent")} }
861
+ .file { margin-left: 4px } .count { color: ${t("muted")}; font-size: 12px; margin-left: auto } .count + .badge { margin-left: 0 }`];
862
+ render() {
863
+ const k = this.task;
864
+ if (!k)
865
+ return nothing;
866
+ const done = k.items.filter((i) => i.status === "completed").length;
867
+ return html`<details class="card" open><summary><span class="title name">${k.title}</span><span class="count">${done}/${k.items.length}</span></summary>
868
+ <ul>${k.items.map((i) => html`<li data-status=${i.status ?? "pending"}><span class="icon" aria-hidden="true">${ITEM[i.status ?? "pending"]}</span>
869
+ <span>${i.text}${i.file ? html`<span class="chip mono file">${i.file.name}</span>` : nothing}</span></li>`)}</ul></details>`;
870
+ }
871
+ }
872
+
873
+ class NanoSubagent extends LitElement {
874
+ static properties = { agent: { attribute: false } };
875
+ static styles = [base, kit, agentStyles, css`.desc { color: ${t("muted")}; font-size: 12px } .body { border-left: 2px solid ${t("border")}; margin-left: 18px; padding-left: 12px }`];
876
+ render() {
877
+ const a = this.agent;
878
+ if (!a)
879
+ return nothing;
880
+ const [label, tone] = AGENT[a.status];
881
+ return html`<details class="card" open><summary><span class="avatar small" aria-hidden="true">${a.name.slice(0, 2).toUpperCase()}</span>
882
+ <span class="col" style="gap:0"><span class="name">${a.name}</span>${a.description ? html`<span class="desc">${a.description}</span>` : nothing}</span>
883
+ <span class="badge ${tone}">${label}</span></summary>
884
+ <div class="body">${a.parts.map((p) => html`<nano-tool .tool=${p}></nano-tool>`)}${a.result ? html`<div class="bubble">${a.result}</div>` : nothing}</div></details>`;
885
+ }
886
+ }
887
+
888
+ class NanoCli extends LitElement {
889
+ static properties = { runs: { attribute: false } };
890
+ static styles = [base, kit, css`
891
+ .term { font: 12px/1.6 ${t("font-mono")}; background: ${t("surface-2")}; border: 1px solid ${t("border")}; border-radius: ${t("radius")}; padding: 10px 12px; overflow: auto }
892
+ .run + .run { margin-top: 10px } .line { display: flex; gap: 8px; align-items: center } .prompt { color: ${t("accent")} } .cmd { font-weight: 600 }
893
+ .cwd { color: ${t("muted")} } .exit { margin-left: auto } pre { margin: 2px 0 0; white-space: pre-wrap; color: ${t("fg-2")} }`];
894
+ constructor() {
895
+ super();
896
+ this.runs = [];
897
+ }
898
+ render() {
899
+ return html`<div class="term">${this.runs.map((r) => html`<div class="run"><div class="line">${r.cwd ? html`<span class="cwd">${r.cwd}</span>` : nothing}
900
+ <span class="prompt">$</span><span class="cmd">${r.command}</span>
901
+ <span class="exit badge ${r.running ? "accent" : r.exitCode === 0 ? "good" : r.exitCode === undefined ? "" : "bad"}">${r.running ? "running…" : r.exitCode === undefined ? "" : `exit ${r.exitCode}`}</span></div>
902
+ ${r.output ? html`<pre>${r.output}</pre>` : nothing}</div>`)}</div>`;
903
+ }
904
+ }
905
+ define2("nano-tool", NanoTool);
906
+ define2("nano-task", NanoTask);
907
+ define2("nano-subagent", NanoSubagent);
908
+ define2("nano-cli", NanoCli);
909
+ // ../elements/src/agent/timeline.ts
910
+ var ms = (n) => n < 1000 ? `${Math.round(n)}ms` : `${(n / 1000).toFixed(2)}s`;
911
+ var pct = (n) => `${+n.toFixed(2)}%`;
912
+ var ordered = (spans) => {
913
+ const ids2 = new Set(spans.map((s) => s.spanId)), out = [];
914
+ const walk = (parent, depth) => spans.filter((s) => parent === undefined ? !s.parentSpanId || !ids2.has(s.parentSpanId) : s.parentSpanId === parent).sort((a, b) => a.startTime - b.startTime).forEach((s) => {
915
+ out.push({ span: s, depth });
916
+ walk(s.spanId, depth + 1);
917
+ });
918
+ walk(undefined, 0);
919
+ return out;
920
+ };
921
+
922
+ class NanoTrace extends LitElement {
923
+ static properties = { spans: { attribute: false } };
924
+ static styles = [base, kit, css`
925
+ .frame { border: 1px solid ${t("border")}; border-radius: ${t("radius")}; padding: 8px 0 }
926
+ .head, .span { display: grid; grid-template-columns: minmax(120px, 30%) 1fr 64px; align-items: center; gap: 8px; padding: 3px 12px }
927
+ .head { color: ${t("muted")}; font-size: 11px; border-bottom: 1px solid ${t("border")}; padding-bottom: 6px; margin-bottom: 4px }
928
+ .span:hover { background: ${t("surface-2")} } .label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis }
929
+ .track { position: relative; height: 14px } .bar { position: absolute; top: 2px; bottom: 2px; min-width: 2px; border-radius: 3px }
930
+ .bar.bad { background: ${t("bad")} !important } .dur, .total { text-align: right; color: ${t("muted")}; font: 11px ${t("font-mono")} }`];
931
+ constructor() {
932
+ super();
933
+ this.spans = [];
934
+ }
935
+ render() {
936
+ if (!this.spans.length)
937
+ return nothing;
938
+ const t0 = Math.min(...this.spans.map((s) => s.startTime)), total = Math.max(...this.spans.map((s) => s.endTime)) - t0 || 1;
939
+ return html`<div class="frame"><div class="head"><span>Span</span><span>Timeline</span><span class="total">${ms(total)}</span></div>
940
+ ${ordered(this.spans).map(({ span: s, depth }) => html`<div class="span" data-depth=${depth} title=${`${s.name}: ${ms(s.endTime - s.startTime)}`}>
941
+ <span class="label" style=${`padding-left:${depth * 14}px`}>${s.name}</span>
942
+ <span class="track"><span class="bar ${s.status === "error" ? "bad" : ""}" style=${`left:${pct((s.startTime - t0) / total * 100)};width:${pct((s.endTime - s.startTime) / total * 100)};background:${tv(`s${depth % 8 + 1}`)}`}></span></span>
943
+ <span class="dur">${ms(s.endTime - s.startTime)}</span></div>`)}</div>`;
944
+ }
945
+ }
946
+ var MARK = { passed: "✓", failed: "✕", skipped: "–" };
947
+
948
+ class NanoTestResults extends LitElement {
949
+ static properties = { results: { attribute: false } };
950
+ static styles = [base, kit, agentStyles, css`
951
+ .summary { display: flex; align-items: center; gap: 8px; margin-bottom: 8px } .dur { margin-left: auto; color: ${t("muted")}; font: 11px ${t("font-mono")} }
952
+ .bar { display: flex; height: 6px; border-radius: 3px; overflow: hidden; background: ${t("surface-2")}; margin-bottom: 12px }
953
+ .seg.passed { background: ${t("good")} } .seg.failed { background: ${t("bad")} } .seg.skipped { background: ${t("muted")} }
954
+ .suites { display: flex; flex-direction: column; gap: 8px } .tests { list-style: none; margin: 0; padding: 0 12px 10px }
955
+ .test { display: grid; grid-template-columns: 16px 1fr auto; gap: 6px; padding: 3px 0 } .test .alert { grid-column: 2 / -1; font: 11px ${t("font-mono")}; white-space: pre-wrap }
956
+ .test.passed .mark { color: ${t("good")} } .test.failed .mark { color: ${t("bad")} } .test.skipped { color: ${t("muted")} }
957
+ .test .ms { color: ${t("muted")}; font: 11px ${t("font-mono")} } summary .muted { font-size: 12px }`];
958
+ render() {
959
+ const r = this.results;
960
+ if (!r)
961
+ return nothing;
962
+ const { summary: s } = r, tone = { passed: "good", failed: "bad", skipped: "" };
963
+ return html`<div class="summary">${["passed", "failed", "skipped"].map((k) => html`<span class="badge ${tone[k]}" data-count=${k}>${s[k]} ${k}</span>`)}
964
+ ${s.duration !== undefined ? html`<span class="dur">${ms(s.duration)}</span>` : nothing}</div>
965
+ <div class="bar" role="img" aria-label=${`${s.passed} passed, ${s.failed} failed, ${s.skipped} skipped of ${s.total}`}>
966
+ ${["passed", "failed", "skipped"].map((k) => html`<span class="seg ${k}" style=${`width:${pct(s[k] / (s.total || 1) * 100)}`}></span>`)}</div>
967
+ <div class="suites">${r.suites.map((suite) => {
968
+ const failed = suite.tests.filter((x) => x.status === "failed").length;
969
+ return html`<details class="card suite" ?open=${failed > 0}><summary><span class="name">${suite.name}</span>
970
+ <span class="muted">${suite.tests.length - failed}/${suite.tests.length}</span>${failed ? html`<span class="badge bad">${failed} failed</span>` : nothing}</summary>
971
+ <ul class="tests">${suite.tests.map((x) => html`<li class="test ${x.status}"><span class="mark" aria-label=${x.status}>${MARK[x.status]}</span><span>${x.name}</span>
972
+ <span class="ms">${x.duration !== undefined ? ms(x.duration) : ""}</span>${x.error ? html`<div class="alert bad">${x.error.message}</div>` : nothing}</li>`)}</ul></details>`;
973
+ })}</div>`;
974
+ }
975
+ }
976
+ for (const [tag, cls] of [["nano-trace", NanoTrace], ["nano-test-results", NanoTestResults]])
977
+ if (globalThis.customElements && !customElements.get(tag))
978
+ customElements.define(tag, cls);
979
+ // ../elements/src/kit/tree-styles.ts
980
+ var treeStyles = css`
981
+ :host { display: block } ul { list-style: none; margin: 0; padding: 0 }
982
+ ul.group { margin-left: 15px; padding-left: 8px; border-left: 1px solid ${t("border")} }
983
+ li[role='treeitem'] { outline: 0 } li[role='treeitem']:focus-visible > .line { outline: 2px solid ${t("focus")}; outline-offset: -2px }
984
+ .line { display: flex; align-items: center; gap: 6px; padding: 5px 8px; margin: 1px 0; border-radius: ${t("radius-s")}; cursor: pointer; min-width: 0 }
985
+ .line:hover { background: ${t("surface-2")} } li[aria-selected='true'] > .line { background: ${t("accent-soft")} }
986
+ .chev { flex: none; width: 16px; cursor: pointer; text-align: center; color: ${t("muted")}; transition: transform .15s; user-select: none }
987
+ li[data-mark] > .line { background: ${t("warn-bg")}; box-shadow: inset 3px 0 ${t("warn")} } li[data-mark][aria-selected='true'] > .line { background: ${t("accent-soft")} }
988
+ li[aria-expanded='true'] > .line .chev { transform: rotate(90deg) }
989
+ .label { overflow-wrap: anywhere } .kind { color: ${t("muted")}; font-size: 11px; letter-spacing: .06em; text-transform: uppercase }
990
+ .count { color: ${t("muted")}; font-size: 11px; font-variant-numeric: tabular-nums }
991
+ .tag { font-size: 11px; padding: 2px 7px; border-radius: ${t("radius-s")}; background: ${t("accent-soft")}; white-space: nowrap }
992
+ .icon { flex: none; display: inline-flex; align-items: center; gap: 4px } .end { margin-left: auto; display: inline-flex; align-items: center; gap: 4px }
993
+ .body { padding: 2px 8px 6px 30px; color: ${t("muted")}; font-size: 12px }
994
+ mark { background: ${t("warn-bg")}; color: inherit; border-radius: 2px } .empty { color: ${t("muted")}; padding: 12px }
995
+ @media (pointer: coarse) { .line { min-height: 44px } }`;
996
+
997
+ // ../elements/src/kit/tree.ts
998
+ var has = (n, q) => [n.label, ...n.terms ?? []].some((s) => s.toLowerCase().includes(q));
999
+ var prune = (nodes, q, all) => nodes.flatMap((node) => {
1000
+ const hit = all || has(node, q), kids = prune(node.children ?? [], q, hit);
1001
+ return hit || kids.length ? [{ node, kids }] : [];
1002
+ });
1003
+ var pathTo = (nodes, id) => {
1004
+ for (const n of nodes) {
1005
+ if (n.id === id)
1006
+ return [id];
1007
+ const rest = pathTo(n.children ?? [], id);
1008
+ if (rest.length)
1009
+ return [n.id, ...rest];
1010
+ }
1011
+ return [];
1012
+ };
1013
+
1014
+ class NanoTree extends LitElement {
1015
+ static properties = {
1016
+ nodes: { attribute: false },
1017
+ query: {},
1018
+ selected: {},
1019
+ openDepth: { type: Number, attribute: "open-depth" },
1020
+ icon: { attribute: false },
1021
+ flipped: { state: true },
1022
+ focused: { state: true }
1023
+ };
1024
+ static styles = [base, kit, treeStyles];
1025
+ #rows = [];
1026
+ constructor() {
1027
+ super();
1028
+ this.nodes = [];
1029
+ this.query = "";
1030
+ this.selected = null;
1031
+ this.openDepth = 0;
1032
+ this.flipped = new Set;
1033
+ this.focused = null;
1034
+ }
1035
+ get #q() {
1036
+ return this.query.trim().toLowerCase();
1037
+ }
1038
+ #isOpen(id, depth) {
1039
+ return this.#q !== "" || depth < this.openDepth !== this.flipped.has(id);
1040
+ }
1041
+ #flip(id) {
1042
+ const f = new Set(this.flipped);
1043
+ f.has(id) ? f.delete(id) : f.add(id);
1044
+ this.flipped = f;
1045
+ }
1046
+ #setOpen(row, open) {
1047
+ if (row.can && row.open !== open && !this.#q)
1048
+ this.#flip(row.id);
1049
+ }
1050
+ reveal(id, { focus = true } = {}) {
1051
+ const path = pathTo(this.nodes, id);
1052
+ path.slice(0, -1).forEach((a, depth) => {
1053
+ if (!this.#isOpen(a, depth))
1054
+ this.#flip(a);
1055
+ });
1056
+ if (path.length)
1057
+ this.#focus(id, focus);
1058
+ }
1059
+ async#focus(id, focus = true) {
1060
+ this.focused = id;
1061
+ await this.updateComplete;
1062
+ const li = this.renderRoot.querySelector(`[role='treeitem'][data-id="${CSS.escape(id)}"]`);
1063
+ if (focus)
1064
+ li?.focus();
1065
+ li?.querySelector(".line")?.scrollIntoView?.({ block: "nearest" });
1066
+ }
1067
+ #choose(id) {
1068
+ const go = this.dispatchEvent(new CustomEvent("select", { detail: { id }, cancelable: true, bubbles: true, composed: true }));
1069
+ if (go)
1070
+ this.selected = id;
1071
+ }
1072
+ #click(e, row) {
1073
+ const el = e.target;
1074
+ if (el.closest(".chev")) {
1075
+ this.#setOpen(row, !row.open);
1076
+ return;
1077
+ }
1078
+ if (el.closest("button, a, input, select, textarea, label"))
1079
+ return;
1080
+ this.#choose(row.id);
1081
+ this.#focus(row.id);
1082
+ }
1083
+ #key(e) {
1084
+ const li = e.target;
1085
+ if (li.getAttribute("role") !== "treeitem" || e.altKey || e.ctrlKey || e.metaKey)
1086
+ return;
1087
+ const rows = this.#rows, i = rows.findIndex((r) => r.id === li.dataset.id), row = rows[i];
1088
+ if (!row)
1089
+ return;
1090
+ const to = (r) => {
1091
+ if (r)
1092
+ this.#focus(r.id);
1093
+ };
1094
+ const k = e.key;
1095
+ if (k === "ArrowDown")
1096
+ to(rows[i + 1]);
1097
+ else if (k === "ArrowUp")
1098
+ to(rows[i - 1]);
1099
+ else if (k === "Home")
1100
+ to(rows[0]);
1101
+ else if (k === "End")
1102
+ to(rows.at(-1));
1103
+ else if (k === "ArrowRight")
1104
+ row.can && !row.open ? this.#setOpen(row, true) : rows[i + 1]?.parent === row.id && to(rows[i + 1]);
1105
+ else if (k === "ArrowLeft")
1106
+ row.can && row.open && !this.#q ? this.#setOpen(row, false) : to(rows.find((r) => r.id === row.parent));
1107
+ else if (k === "Enter" || k === " ")
1108
+ this.#choose(row.id);
1109
+ else if (k.length === 1 && k.trim()) {
1110
+ const c = k.toLowerCase();
1111
+ to([...rows.slice(i + 1), ...rows.slice(0, i)].find((r) => r.label.toLowerCase().startsWith(c)));
1112
+ } else
1113
+ return;
1114
+ e.preventDefault();
1115
+ }
1116
+ #label(s) {
1117
+ const q = this.#q, i = q ? s.toLowerCase().indexOf(q) : -1;
1118
+ return i < 0 ? s : html`${s.slice(0, i)}<mark>${s.slice(i, i + q.length)}</mark>${s.slice(i + q.length)}`;
1119
+ }
1120
+ #item(s, depth, byId, tab) {
1121
+ const n = s.node, ic = this.icon?.(n), row = byId.get(n.id), { can, open } = row;
1122
+ return html`<li role="treeitem" data-id=${n.id} aria-level=${depth + 1} aria-expanded=${can ? String(open) : nothing}
1123
+ aria-selected=${this.selected === n.id ? "true" : nothing} tabindex=${n.id === tab ? 0 : -1}
1124
+ ${ref((el) => setAttrs(el, n.data && Object.fromEntries(Object.entries(n.data).map(([k, v]) => [`data-${k}`, v]))))}>
1125
+ <div class="line" @click=${(e) => this.#click(e, row)}>
1126
+ <span class="chev" data-toggle=${n.id} aria-hidden="true">${can ? "▸" : ""}</span>
1127
+ ${ic ? html`<span class="icon" title=${n.kind ?? nothing}>${ic}</span>` : nothing}<span class="label">${this.#label(n.label)}</span>
1128
+ ${n.kind && !ic ? html`<span class="kind">${n.kind}</span>` : nothing}${n.count !== undefined ? html`<span class="count">${n.count}</span>` : nothing}
1129
+ ${n.badge ? html`<span class="tag">${n.badge}</span>` : nothing}${n.end !== undefined ? html`<span class="end">${n.end}</span>` : nothing}
1130
+ </div>
1131
+ ${open ? html`${n.body !== undefined ? html`<div class="body">${n.body}</div>` : nothing}
1132
+ ${s.kids.length ? html`<ul class="group" role="group">${s.kids.map((k) => this.#item(k, depth + 1, byId, tab))}</ul>` : nothing}` : nothing}
1133
+ </li>`;
1134
+ }
1135
+ render() {
1136
+ const shown = prune(this.nodes, this.#q, this.#q === "");
1137
+ const rows = [];
1138
+ const walk = (list, depth, parent) => list.forEach((s) => {
1139
+ const can = s.kids.length > 0 || s.node.body !== undefined, open = can && this.#isOpen(s.node.id, depth);
1140
+ rows.push({ id: s.node.id, label: s.node.label, parent, can, open });
1141
+ if (open)
1142
+ walk(s.kids, depth + 1, s.node.id);
1143
+ });
1144
+ walk(shown, 0);
1145
+ this.#rows = rows;
1146
+ if (!rows.length)
1147
+ return html`<div class="empty">${this.#q ? `Nothing matches “${this.query.trim()}”.` : "Nothing here."}</div>`;
1148
+ const ids2 = new Set(rows.map((r) => r.id));
1149
+ const tab = [this.focused, this.selected].find((id) => id && ids2.has(id)) ?? rows[0].id;
1150
+ return html`<ul role="tree" @keydown=${(e) => this.#key(e)}>${shown.map((s) => this.#item(s, 0, new Map(rows.map((r) => [r.id, r])), tab))}</ul>`;
1151
+ }
1152
+ }
1153
+ if (globalThis.customElements && !customElements.get("nano-tree"))
1154
+ customElements.define("nano-tree", NanoTree);
1155
+ export {
1156
+ tv,
1157
+ toast,
1158
+ t,
1159
+ kit,
1160
+ base,
1161
+ NanoTree,
1162
+ NanoTrace,
1163
+ NanoTool,
1164
+ NanoToaster,
1165
+ NanoTestResults,
1166
+ NanoTask,
1167
+ NanoSubagent,
1168
+ NanoSelect,
1169
+ NanoMenu,
1170
+ NanoHoverCard,
1171
+ NanoDatePicker,
1172
+ NanoDataTable,
1173
+ NanoCommand,
1174
+ NanoCodeBlock,
1175
+ NanoCli,
1176
+ NanoCalendar,
1177
+ NANO_TOKENS
1178
+ };