@luxalgo/vela-ui 0.2.0 → 0.3.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 (106) hide show
  1. package/CHANGELOG.md +41 -0
  2. package/dist/badge.js +1 -1
  3. package/dist/bar-chart.d.ts +1 -1
  4. package/dist/bar-chart.js +1 -1
  5. package/dist/button.d.ts +1 -1
  6. package/dist/button.js +4 -4
  7. package/dist/callout-bubble.d.ts +1 -1
  8. package/dist/callout-bubble.js +4 -4
  9. package/dist/card.d.ts +52 -0
  10. package/dist/card.js +179 -0
  11. package/dist/checkbox.js +4 -4
  12. package/dist/{chunk-WGULXRWD.js → chunk-B2EZB5ZG.js} +3 -3
  13. package/dist/{chunk-G7IQLY3A.js → chunk-C3PXY2SW.js} +5 -0
  14. package/dist/{chunk-CC3DDNFC.js → chunk-DXDCKZ2M.js} +4 -4
  15. package/dist/{chunk-WBGSYCV2.js → chunk-IOOYDSSK.js} +3 -3
  16. package/dist/{chunk-B5ZSRUDQ.js → chunk-KKS6NEGI.js} +2 -2
  17. package/dist/{chunk-7VMN7NKJ.js → chunk-OJ2SEMN6.js} +3 -3
  18. package/dist/{chunk-MJ4RUGX7.js → chunk-OQXFQMZM.js} +2 -2
  19. package/dist/{chunk-V2Q4MRMS.js → chunk-TBXUF5YX.js} +12 -0
  20. package/dist/{chunk-WXH3EFV5.js → chunk-UEO6W37Z.js} +3 -3
  21. package/dist/{chunk-Z5PINFQO.js → chunk-WWHNUKSZ.js} +4 -4
  22. package/dist/collapsible.d.ts +1 -1
  23. package/dist/collapsible.js +3 -3
  24. package/dist/color-picker.js +4 -4
  25. package/dist/context-menu.js +4 -4
  26. package/dist/data-table.d.ts +1 -1
  27. package/dist/data-table.js +1 -1
  28. package/dist/date-picker.d.ts +1 -1
  29. package/dist/date-picker.js +2 -2
  30. package/dist/dialog.d.ts +9 -1
  31. package/dist/dialog.js +14 -4
  32. package/dist/donut.d.ts +1 -1
  33. package/dist/donut.js +1 -1
  34. package/dist/drawer.d.ts +1 -1
  35. package/dist/drawer.js +1 -1
  36. package/dist/dropdown-menu.d.ts +1 -1
  37. package/dist/dropdown-menu.js +4 -4
  38. package/dist/empty.d.ts +1 -1
  39. package/dist/empty.js +2 -2
  40. package/dist/field.js +12 -12
  41. package/dist/glyph-select.js +5 -5
  42. package/dist/hover-card.d.ts +1 -1
  43. package/dist/hover-card.js +3 -3
  44. package/dist/icons.js +1 -1
  45. package/dist/index.d.ts +3 -1
  46. package/dist/index.js +3 -3
  47. package/dist/input-group.d.ts +1 -1
  48. package/dist/input-group.js +4 -4
  49. package/dist/input.js +2 -2
  50. package/dist/item.d.ts +1 -1
  51. package/dist/item.js +2 -2
  52. package/dist/kbd.d.ts +1 -1
  53. package/dist/kbd.js +2 -2
  54. package/dist/line-chart.d.ts +1 -1
  55. package/dist/line-chart.js +1 -1
  56. package/dist/manifest.json +618 -1
  57. package/dist/month-grid.js +1 -1
  58. package/dist/number-input.d.ts +1 -1
  59. package/dist/number-input.js +4 -4
  60. package/dist/popover.js +3 -3
  61. package/dist/scatter-chart.d.ts +1 -1
  62. package/dist/scatter-chart.js +1 -1
  63. package/dist/select.js +6 -6
  64. package/dist/slider.d.ts +1 -1
  65. package/dist/slider.js +1 -1
  66. package/dist/sort-button.js +3 -3
  67. package/dist/sparkline.d.ts +1 -1
  68. package/dist/sparkline.js +1 -1
  69. package/dist/stat.d.ts +1 -1
  70. package/dist/stat.js +1 -1
  71. package/dist/switch.d.ts +1 -1
  72. package/dist/switch.js +2 -2
  73. package/dist/tabs.d.ts +1 -1
  74. package/dist/tabs.js +3 -3
  75. package/dist/text-area.d.ts +1 -1
  76. package/dist/text-area.js +2 -2
  77. package/dist/theme-Ct-q58xz.d.ts +341 -0
  78. package/dist/theme.d.ts +42 -192
  79. package/dist/theme.js +1 -1
  80. package/dist/theme.schema.json +292 -1
  81. package/dist/toast.d.ts +49 -0
  82. package/dist/toast.js +463 -0
  83. package/dist/toggle-group.d.ts +1 -1
  84. package/dist/toggle-group.js +3 -3
  85. package/dist/tooltip.js +1 -1
  86. package/dist/treemap.d.ts +80 -0
  87. package/dist/treemap.js +470 -0
  88. package/llms.txt +5 -2
  89. package/package.json +1 -1
  90. package/registry/button.ts +8 -0
  91. package/registry/card.ts +379 -0
  92. package/registry/dialog.ts +16 -0
  93. package/registry/toast.ts +965 -0
  94. package/registry/treemap.ts +847 -0
  95. package/skills/using-vela-ui-components/SKILL.md +4 -2
  96. package/src/components/button.ts +8 -0
  97. package/src/components/card.ts +379 -0
  98. package/src/components/dialog.ts +16 -0
  99. package/src/components/toast.ts +965 -0
  100. package/src/components/treemap.ts +847 -0
  101. package/src/lib/component-index.ts +12 -0
  102. package/src/lib/icons.ts +7 -0
  103. package/src/lib/theme.ts +6 -0
  104. package/dist/{chunk-U3EH42YY.js → chunk-5BJV5FY5.js} +1 -1
  105. package/dist/{chunk-E2FE6V2N.js → chunk-ALAHGSLC.js} +1 -1
  106. package/dist/{chunk-C3ICYMI3.js → chunk-FYVQO5TN.js} +1 -1
@@ -0,0 +1,470 @@
1
+ import { kitTranslator } from './chunk-FVH6L7FM.js';
2
+ import { msg, textOf } from './chunk-FN2BUFNM.js';
3
+ import { showTip } from './chunk-A2FJ7Y7D.js';
4
+ import { h } from './chunk-Q6WTDVH6.js';
5
+ import { t } from './chunk-6QCILIT2.js';
6
+ import { defineComponent } from './chunk-VMCR3S2A.js';
7
+ import { defineStyles, css } from './chunk-XBEL4K33.js';
8
+ import './chunk-2GQIZM5Z.js';
9
+ import './chunk-BXMWQIBO.js';
10
+ import './chunk-X66RJAIS.js';
11
+
12
+ // src/components/treemap.ts
13
+ var treemapDef = defineComponent({
14
+ name: "treemap",
15
+ parts: ["root", "crumbs", "crumb", "map", "group", "group-name", "group-value", "tile", "tile-label", "tile-value", "legend", "legend-bar", "tip"],
16
+ settings: {
17
+ radius: t.radius.sm,
18
+ up: t.up,
19
+ down: t.down,
20
+ "tile-bg": `color-mix(in srgb, ${t.fg.bright} 2.5%, ${t.surface})`,
21
+ "tint-min": "3%",
22
+ "tint-max": "25%",
23
+ "hover-z": "1",
24
+ "tip-radius": t.radius.md,
25
+ "tip-bg": t.surface.elev,
26
+ "tip-shadow": t.shadow,
27
+ "tip-z": "2"
28
+ }
29
+ });
30
+ function squarify(items, bounds) {
31
+ const total = items.reduce((s, item) => s + Math.max(0, item.weight), 0);
32
+ if (!total || bounds.w <= 0 || bounds.h <= 0) return [];
33
+ const scale = bounds.w * bounds.h / total;
34
+ let queue = items.filter((item) => item.weight > 0).map((item) => ({ item, area: item.weight * scale })).sort((a, b) => b.area - a.area);
35
+ let { x, y, w, h: h2 } = bounds;
36
+ const out = [];
37
+ const worst = (row, side) => {
38
+ const sum = row.reduce((s, r) => s + r.area, 0);
39
+ const max = Math.max(...row.map((r) => r.area));
40
+ const min = Math.min(...row.map((r) => r.area));
41
+ return Math.max(side * side * max / (sum * sum), sum * sum / (side * side * min));
42
+ };
43
+ while (queue.length) {
44
+ const side = Math.min(w, h2);
45
+ const row = [queue[0]];
46
+ let i = 1;
47
+ while (i < queue.length && worst([...row, queue[i]], side) <= worst(row, side)) row.push(queue[i++]);
48
+ queue = queue.slice(i);
49
+ const sum = row.reduce((s, r) => s + r.area, 0);
50
+ if (w >= h2) {
51
+ const cw = sum / h2;
52
+ let cy = y;
53
+ for (const r of row) {
54
+ const ch = r.area / cw;
55
+ out.push({ ...r.item, x, y: cy, w: cw, h: ch });
56
+ cy += ch;
57
+ }
58
+ x += cw;
59
+ w -= cw;
60
+ } else {
61
+ const rh = sum / w;
62
+ let cx = x;
63
+ for (const r of row) {
64
+ const rw = r.area / rh;
65
+ out.push({ ...r.item, x: cx, y, w: rw, h: rh });
66
+ cx += rw;
67
+ }
68
+ y += rh;
69
+ h2 -= rh;
70
+ }
71
+ }
72
+ return out;
73
+ }
74
+ var TEXT = {
75
+ all: msg("ui.treemap.all", "All"),
76
+ zoomIn: msg("ui.treemap.zoomIn", "Zoom in")
77
+ };
78
+ var HEADER = 16;
79
+ var HEADED = { w: 80, h: 64 };
80
+ var injectStyles = defineStyles(
81
+ "vela-ui-treemap",
82
+ css`@layer vela.ui{[data-slot=treemap]{width:100%;height:100%;min-height:0;color:${t.fg};font-size:${t.fontSize.sm};position:relative}[data-slot=treemap]:where(:not([hidden])){flex-direction:column;gap:8px;display:flex}[data-slot=treemap-crumbs]{min-height:22px;color:${t.fg.muted};flex-wrap:wrap;align-items:center;gap:2px;font-size:12px;display:flex}[data-slot=treemap-crumb]{all:unset;border-radius:${treemapDef.vars.radius};cursor:pointer;padding:2px 6px}[data-slot=treemap-crumb]:hover{background:${t.hover};color:${t.fg.bright}}[data-slot=treemap-crumb]:focus-visible{outline:2px solid ${t.focus}}[data-slot=treemap-crumb][aria-current]{cursor:default;color:${t.fg.bright};background:0 0;font-weight:600}[data-slot=treemap-crumb]:not(:first-child):before{content:"›";color:${t.fg.faint};margin-inline-end:8px}[data-slot=treemap-map]{isolation:isolate;flex:auto;min-height:0;position:relative}[data-slot=treemap-group]{all:unset;letter-spacing:.06em;text-transform:uppercase;white-space:nowrap;height:16px;color:${t.fg.muted};transition:left ${t.dur.med} ${t.ease}, top ${t.dur.med} ${t.ease}, width ${t.dur.med} ${t.ease};align-items:center;gap:6px;padding-inline:2px;font-size:9px;font-weight:500;display:flex;position:absolute;overflow:hidden}[data-slot=treemap-group][data-drill]{border-radius:${treemapDef.vars.radius};cursor:zoom-in}[data-slot=treemap-group][data-drill]:hover{color:${t.fg.bright};background:${t.hover}}[data-slot=treemap-group]:focus-visible{outline:2px solid ${t.focus}}[data-slot=treemap-group-name]{text-overflow:ellipsis;overflow:hidden}[data-slot=treemap-group-value]{font-variant-numeric:tabular-nums;margin-inline-start:auto}[data-slot=treemap-group-value][data-tone=up]{color:${treemapDef.vars.up}}[data-slot=treemap-group-value][data-tone=down]{color:${treemapDef.vars.down}}[data-slot=treemap-tile]{all:unset;--_tone:${t.fg.muted};--_tint:calc(${treemapDef.vars["tint-min"]} + (${treemapDef.vars["tint-max"]} - ${treemapDef.vars["tint-min"]}) * var(--_level,0));border:1px solid color-mix(in srgb, var(--_tone) calc(var(--_tint) * .8), ${t.border});border-radius:${treemapDef.vars.radius};background:color-mix(in srgb, var(--_tone) var(--_tint), ${treemapDef.vars["tile-bg"]});text-align:center;cursor:pointer;transition:left ${t.dur.med} ${t.ease}, top ${t.dur.med} ${t.ease}, width ${t.dur.med} ${t.ease}, height ${t.dur.med} ${t.ease}, background-color ${t.dur.med} linear, scale ${t.dur.fast} ${t.ease};flex-direction:column;justify-content:center;align-items:center;gap:1px;display:flex;position:absolute;overflow:hidden}[data-slot=treemap-tile][data-tone=up]{--_tone:${treemapDef.vars.up}}[data-slot=treemap-tile][data-tone=down]{--_tone:${treemapDef.vars.down}}[data-slot=treemap-tile][data-tone=custom]{--_tone:var(--_color)}[data-slot=treemap-tile][data-tone=none]{--_tint:0%}[data-slot=treemap-tile]:hover{z-index:${treemapDef.vars["hover-z"]};border-color:${t.fg.bright};scale:1.04}[data-slot=treemap-tile]:focus-visible{z-index:${treemapDef.vars["hover-z"]};outline:2px solid ${t.focus}}[data-slot=treemap-tile][data-selected]{border-color:${t.fg.bright};outline:1px solid ${t.fg.bright}}[data-slot=treemap-tile-label]{text-overflow:ellipsis;white-space:nowrap;max-width:100%;color:${t.fg.bright};font-weight:600;line-height:1.1;overflow:hidden}[data-slot=treemap-tile-value]{white-space:nowrap;font-variant-numeric:tabular-nums;color:${t.fg.bright};opacity:.92}[data-slot=treemap-legend]{font-variant-numeric:tabular-nums;color:${t.fg.muted};grid-template-columns:auto 1fr auto;align-items:center;gap:8px;font-size:10px;display:grid}[data-slot=treemap-legend-bar]{border:1px solid ${t.border};background:linear-gradient(to right, color-mix(in srgb, ${treemapDef.vars.down} 70%, ${treemapDef.vars["tile-bg"]}), ${treemapDef.vars["tile-bg"]}, color-mix(in srgb, ${treemapDef.vars.up} 70%, ${treemapDef.vars["tile-bg"]}));border-radius:999px;height:6px}[data-slot=treemap-tip]{z-index:${treemapDef.vars["tip-z"]};pointer-events:none;border:1px solid ${t.border};border-radius:${treemapDef.vars["tip-radius"]};background:${treemapDef.vars["tip-bg"]};box-shadow:${treemapDef.vars["tip-shadow"]};color:${t.fg.bright};white-space:nowrap;font-variant-numeric:tabular-nums;transition:left ${t.dur.fast} ease-out, top ${t.dur.fast} ease-out;gap:2px;padding:8px;font-size:12px;line-height:1.35;position:absolute;top:0}[data-slot=treemap-tip]:where(:not([hidden])){display:grid}[data-slot=treemap-tip][data-instant]{transition:none}[data-slot=treemap-tip] [data-tone=up]{color:${treemapDef.vars.up}}[data-slot=treemap-tip] [data-tone=down]{color:${treemapDef.vars.down}}[data-slot=treemap-tip] small{color:${t.fg.muted}}}`
83
+ );
84
+ var weightOf = (item) => item.children ? item.children.reduce((s, c) => s + weightOf(c), 0) : Math.max(0, item.weight ?? 1);
85
+ function median(values) {
86
+ if (values.length === 0) return null;
87
+ const sorted = [...values].sort((a, b) => a - b);
88
+ const mid = (sorted.length - 1) / 2;
89
+ return (sorted[Math.floor(mid)] + sorted[Math.ceil(mid)]) / 2;
90
+ }
91
+ var toneOf = (value) => value === null ? "none" : value > 0 ? "up" : value < 0 ? "down" : "flat";
92
+ var defaultFormat = (value) => `${value > 0 ? "+" : ""}${value.toFixed(2)}`;
93
+ var TreemapImpl = class {
94
+ constructor(props) {
95
+ this.props = props;
96
+ this.values = /* @__PURE__ */ new Map();
97
+ this.tiles = /* @__PURE__ */ new Map();
98
+ this.groups = /* @__PURE__ */ new Map();
99
+ /** The zoomed groups' ids, outermost first. */
100
+ this.zoom = [];
101
+ /** The tile that takes the map's tab stop. */
102
+ this.current = null;
103
+ /** The tile the readout describes. */
104
+ this.tipFor = null;
105
+ this.box = { w: 0, h: 0 };
106
+ injectStyles(document);
107
+ this.i18n = props.i18n ?? kitTranslator();
108
+ this.gap = Math.max(0, props.gap ?? 3);
109
+ this.items = props.items ?? [];
110
+ this.selected = props.selected ?? null;
111
+ this.map = h("div", { slot: treemapDef.slot("map"), attrs: { role: "group", dir: "ltr", "aria-label": props.label ?? null } });
112
+ this.tip = h("div", { slot: treemapDef.slot("tip"), attrs: { "aria-hidden": "true" } });
113
+ this.tip.hidden = true;
114
+ this.crumbs = props.drill ? h("nav", { slot: treemapDef.slot("crumbs") }) : null;
115
+ let legendEl = null;
116
+ if (props.legend) {
117
+ const low = h("span");
118
+ const high = h("span");
119
+ legendEl = h("div", { slot: treemapDef.slot("legend"), attrs: { "aria-hidden": "true", dir: "ltr" } }, low, h("i", { slot: treemapDef.slot("legend-bar") }), high);
120
+ this.legend = { low, high };
121
+ } else this.legend = null;
122
+ this.el = h("div", { className: props.className, slot: treemapDef.slot("root") }, this.crumbs, this.map, legendEl, this.tip);
123
+ this.map.addEventListener("keydown", (e) => this.onKey(e));
124
+ this.map.addEventListener("pointerleave", () => this.hideTip());
125
+ this.el.addEventListener("keydown", (e) => {
126
+ if (e.key !== "Escape" || this.zoom.length === 0) return;
127
+ e.preventDefault();
128
+ e.stopPropagation();
129
+ this.setZoom(this.zoom.slice(0, -1), true);
130
+ });
131
+ this.ro = typeof ResizeObserver === "function" ? new ResizeObserver(() => this.measure()) : null;
132
+ this.ro?.observe(this.map);
133
+ this.renderCrumbs();
134
+ this.layout();
135
+ }
136
+ setData(items) {
137
+ this.items = items;
138
+ this.values.clear();
139
+ const zoom = [];
140
+ let level = items;
141
+ for (const id of this.zoom) {
142
+ const group = level.find((item) => item.id === id && item.children);
143
+ if (!group) break;
144
+ zoom.push(id);
145
+ level = group.children;
146
+ }
147
+ const changed = zoom.length !== this.zoom.length;
148
+ this.zoom = zoom;
149
+ this.renderCrumbs();
150
+ this.layout();
151
+ if (changed) this.props.onDrill?.(this.zoomPath());
152
+ }
153
+ setValues(values) {
154
+ const entries = values instanceof Map ? values.entries() : Object.entries(values);
155
+ for (const [id, value] of entries) this.values.set(id, value);
156
+ this.paint();
157
+ }
158
+ setSelected(id) {
159
+ this.selected = id;
160
+ for (const [key, tile] of this.tiles) tile.el.toggleAttribute("data-selected", key === id);
161
+ }
162
+ drillTo(id) {
163
+ if (id === null) {
164
+ this.setZoom([], true);
165
+ return;
166
+ }
167
+ const path = this.pathTo(id, this.items, []);
168
+ if (path) this.setZoom([...path.map((g) => g.id), id], true);
169
+ }
170
+ destroy() {
171
+ this.ro?.disconnect();
172
+ this.el.remove();
173
+ }
174
+ pathTo(id, level, above) {
175
+ for (const item of level) {
176
+ if (!item.children) continue;
177
+ if (item.id === id) return above;
178
+ const found = this.pathTo(id, item.children, [...above, item]);
179
+ if (found) return found;
180
+ }
181
+ return null;
182
+ }
183
+ /** The zoomed groups, outermost first. */
184
+ zoomPath() {
185
+ const path = [];
186
+ let level = this.items;
187
+ for (const id of this.zoom) {
188
+ const group = level.find((item) => item.id === id);
189
+ if (!group?.children) break;
190
+ path.push(group);
191
+ level = group.children;
192
+ }
193
+ return path;
194
+ }
195
+ setZoom(zoom, announce) {
196
+ if (zoom.join("\0") === this.zoom.join("\0")) return;
197
+ this.zoom = zoom;
198
+ this.current = null;
199
+ this.hideTip();
200
+ this.renderCrumbs();
201
+ this.layout();
202
+ if (announce) this.props.onDrill?.(this.zoomPath());
203
+ }
204
+ renderCrumbs() {
205
+ if (!this.crumbs) return;
206
+ const path = this.zoomPath();
207
+ const entries = [{ label: this.props.rootLabel ?? textOf(this.i18n, TEXT.all), zoom: [] }];
208
+ path.forEach((group, i) => entries.push({ label: group.label, zoom: this.zoom.slice(0, i + 1) }));
209
+ this.crumbs.replaceChildren(
210
+ ...entries.map((entry, i) => {
211
+ const last = i === entries.length - 1;
212
+ return h("button", {
213
+ slot: treemapDef.slot("crumb"),
214
+ text: entry.label,
215
+ attrs: { type: "button", "aria-current": last ? "true" : null, tabindex: last ? "-1" : null },
216
+ on: { click: () => !last && this.setZoom(entry.zoom, true) }
217
+ });
218
+ })
219
+ );
220
+ }
221
+ measure() {
222
+ const w = this.map.clientWidth;
223
+ const hh = this.map.clientHeight;
224
+ if (Math.abs(w - this.box.w) < 0.5 && Math.abs(hh - this.box.h) < 0.5) return;
225
+ this.box = { w, h: hh };
226
+ this.layout();
227
+ }
228
+ /** The items on the map: the zoomed group's, or the top level's. */
229
+ level() {
230
+ const path = this.zoomPath();
231
+ return { items: path.length > 0 ? path[path.length - 1].children : this.items, path };
232
+ }
233
+ place(items, bounds, path, groups, tiles) {
234
+ const half = this.gap / 2;
235
+ for (const r of squarify(
236
+ items.map((item) => ({ item, weight: weightOf(item) })),
237
+ bounds
238
+ )) {
239
+ const box = { x: r.x + half, y: r.y + half, w: Math.max(0, r.w - this.gap), h: Math.max(0, r.h - this.gap) };
240
+ if (r.item.children) {
241
+ const headed = box.w >= HEADED.w && box.h >= HEADED.h;
242
+ if (headed) groups.push({ item: r.item, path, ...box, h: HEADER });
243
+ const top = headed ? HEADER : 0;
244
+ this.place(r.item.children, { x: box.x, y: box.y + top, w: box.w, h: box.h - top }, [...path, r.item], groups, tiles);
245
+ } else tiles.push({ item: r.item, path, ...box });
246
+ }
247
+ }
248
+ layout() {
249
+ const level = this.level();
250
+ const groups = [];
251
+ const tiles = [];
252
+ this.place(level.items, { x: 0, y: 0, w: this.box.w, h: this.box.h }, level.path, groups, tiles);
253
+ const nextGroups = /* @__PURE__ */ new Map();
254
+ for (const placed of groups) {
255
+ const view = this.groups.get(placed.item.id) ?? this.groupView(placed);
256
+ view.placed = placed;
257
+ view.el.firstElementChild.textContent = placed.item.label;
258
+ position(view.el, placed);
259
+ nextGroups.set(placed.item.id, view);
260
+ }
261
+ const nextTiles = /* @__PURE__ */ new Map();
262
+ for (const placed of tiles) {
263
+ const old = this.tiles.get(placed.item.id);
264
+ const view = old ?? this.tileView(placed);
265
+ view.placed = placed;
266
+ this.fitTile(view);
267
+ position(view.el, placed);
268
+ nextTiles.set(placed.item.id, view);
269
+ }
270
+ for (const [id, view] of this.groups) if (!nextGroups.has(id)) view.el.remove();
271
+ for (const [id, view] of this.tiles) if (!nextTiles.has(id)) view.el.remove();
272
+ this.groups = nextGroups;
273
+ this.tiles = nextTiles;
274
+ const order = [];
275
+ const headerOf = new Map(groups.map((g) => [g.item.id, nextGroups.get(g.item.id).el]));
276
+ const written = /* @__PURE__ */ new Set();
277
+ for (const placed of tiles) {
278
+ for (const group of placed.path) {
279
+ const header = headerOf.get(group.id);
280
+ if (header && !written.has(group.id)) {
281
+ written.add(group.id);
282
+ order.push(header);
283
+ }
284
+ }
285
+ order.push(nextTiles.get(placed.item.id).el);
286
+ }
287
+ const children = this.map.children;
288
+ const same = children.length === order.length && order.every((node, i) => children[i] === node);
289
+ if (!same) this.map.replaceChildren(...order);
290
+ if (this.current === null || !this.tiles.has(this.current)) this.current = tiles[0]?.item.id ?? null;
291
+ for (const [id, tile] of this.tiles) {
292
+ tile.el.tabIndex = id === this.current ? 0 : -1;
293
+ tile.el.toggleAttribute("data-selected", id === this.selected);
294
+ }
295
+ this.paint();
296
+ }
297
+ groupView(placed) {
298
+ const name = h("span", { slot: treemapDef.slot("group-name") });
299
+ const value = h("span", { slot: treemapDef.slot("group-value") });
300
+ const drill = this.props.drill === true;
301
+ const el = drill ? h(
302
+ "button",
303
+ {
304
+ slot: treemapDef.slot("group"),
305
+ data: { drill: true },
306
+ attrs: { type: "button", title: textOf(this.i18n, TEXT.zoomIn) }
307
+ },
308
+ name,
309
+ value
310
+ ) : h("div", { slot: treemapDef.slot("group") }, name, value);
311
+ const view = { el, value, placed };
312
+ if (drill) el.addEventListener("click", () => this.drillTo(view.placed.item.id));
313
+ return view;
314
+ }
315
+ tileView(placed) {
316
+ const el = h("button", { slot: treemapDef.slot("tile"), attrs: { type: "button" } });
317
+ const view = { el, label: null, value: null, placed };
318
+ el.addEventListener("click", () => this.choose(view));
319
+ el.addEventListener("focus", () => {
320
+ this.current = view.placed.item.id;
321
+ for (const tile of this.tiles.values()) tile.el.tabIndex = tile === view ? 0 : -1;
322
+ this.showTipFor(view);
323
+ });
324
+ el.addEventListener("blur", () => this.hideTip());
325
+ el.addEventListener("pointerenter", () => this.showTipFor(view));
326
+ return view;
327
+ }
328
+ /** Text sized to the tile: the label from a small tile up, the value from a larger one. */
329
+ fitTile(view) {
330
+ const { w, h: ht } = view.placed;
331
+ const font = Math.max(10, Math.min(18, Math.min(w, ht) / 4.2));
332
+ const showLabel = w > 34 && ht > 20;
333
+ const showValue = w > 48 && ht > 38;
334
+ if (showLabel && !view.label) view.label = h("span", { slot: treemapDef.slot("tile-label") });
335
+ if (!showLabel) view.label = null;
336
+ if (showValue && !view.value) view.value = h("span", { slot: treemapDef.slot("tile-value") });
337
+ if (!showValue) view.value = null;
338
+ if (view.label) {
339
+ view.label.textContent = view.placed.item.label;
340
+ view.label.style.fontSize = `${font}px`;
341
+ }
342
+ if (view.value) view.value.style.fontSize = `${Math.max(9.5, font * 0.72)}px`;
343
+ const parts = [view.label, view.value].filter((part) => part !== null);
344
+ if (parts.length !== view.el.childElementCount || parts.some((part, i) => view.el.children[i] !== part)) view.el.replaceChildren(...parts);
345
+ }
346
+ valueOf(item) {
347
+ const value = this.values.has(item.id) ? this.values.get(item.id) : item.value ?? null;
348
+ return value === null || !Number.isFinite(value) ? null : value;
349
+ }
350
+ leafValues(item) {
351
+ if (!item.children) {
352
+ const value = this.valueOf(item);
353
+ return value === null ? [] : [value];
354
+ }
355
+ return item.children.flatMap((child) => this.leafValues(child));
356
+ }
357
+ groupFigure(group) {
358
+ const mode = this.props.groupValue ?? "median";
359
+ if (mode === "none") return null;
360
+ const values = this.leafValues(group);
361
+ if (typeof mode === "function") return mode(values, group);
362
+ if (values.length === 0) return null;
363
+ if (mode === "sum") return values.reduce((s, v) => s + v, 0);
364
+ if (mode === "mean") return values.reduce((s, v) => s + v, 0) / values.length;
365
+ return median(values);
366
+ }
367
+ format(value) {
368
+ return (this.props.format ?? defaultFormat)(value);
369
+ }
370
+ paint() {
371
+ let largest = 0;
372
+ for (const tile of this.tiles.values()) largest = Math.max(largest, Math.abs(this.valueOf(tile.placed.item) ?? 0));
373
+ const domain = this.props.domain !== void 0 && this.props.domain > 0 ? this.props.domain : largest;
374
+ for (const tile of this.tiles.values()) {
375
+ const item = tile.placed.item;
376
+ const value = this.valueOf(item);
377
+ if (item.color !== void 0) {
378
+ tile.el.dataset.tone = "custom";
379
+ tile.el.style.setProperty("--_color", item.color);
380
+ } else tile.el.dataset.tone = toneOf(value);
381
+ tile.el.style.setProperty("--_level", value === null || domain === 0 ? "0" : String(Math.min(Math.abs(value) / domain, 1)));
382
+ const text = value === null ? "" : this.format(value);
383
+ if (tile.value) tile.value.textContent = text;
384
+ tile.el.setAttribute("aria-label", text === "" ? item.label : `${item.label} ${text}`);
385
+ }
386
+ for (const group of this.groups.values()) {
387
+ const figure = this.groupFigure(group.placed.item);
388
+ group.value.textContent = figure === null ? "" : this.format(figure);
389
+ group.value.dataset.tone = toneOf(figure);
390
+ const name = group.placed.item.label;
391
+ group.el.setAttribute("aria-label", figure === null ? name : `${name} ${this.format(figure)}`);
392
+ }
393
+ if (this.legend) {
394
+ this.legend.low.textContent = domain > 0 ? this.format(-domain) : "";
395
+ this.legend.high.textContent = domain > 0 ? this.format(domain) : "";
396
+ }
397
+ const shown = this.tipFor !== null ? this.tiles.get(this.tipFor) : void 0;
398
+ if (shown) this.showTipFor(shown);
399
+ else this.hideTip();
400
+ }
401
+ choose(view) {
402
+ this.props.onSelect?.(view.placed.item, view.placed.path);
403
+ }
404
+ tipContent(view) {
405
+ const { item, path } = view.placed;
406
+ if (this.props.tip === false) return null;
407
+ if (this.props.tip) return this.props.tip(item, path);
408
+ const value = this.valueOf(item);
409
+ return h(
410
+ "div",
411
+ {},
412
+ h("div", {}, h("b", { text: item.label }), value === null ? null : h("span", { text: ` ${this.format(value)}`, data: { tone: toneOf(value) } })),
413
+ path.length > 0 ? h("small", { text: path.map((g) => g.label).join(" \u203A ") }) : null
414
+ );
415
+ }
416
+ showTipFor(view) {
417
+ const content = this.tipContent(view);
418
+ if (content === null) return;
419
+ this.tipFor = view.placed.item.id;
420
+ const { x, y, w, h: ht } = view.placed;
421
+ showTip(this.tip, content, { w: this.el.clientWidth, h: this.el.clientHeight }, this.map.offsetLeft + x + w / 2, this.map.offsetTop + y + ht / 2);
422
+ }
423
+ hideTip() {
424
+ this.tipFor = null;
425
+ this.tip.hidden = true;
426
+ }
427
+ /** Arrows move to the nearest tile that way, Home and End to the first and the last. */
428
+ onKey(e) {
429
+ const from = this.current !== null ? this.tiles.get(this.current) : void 0;
430
+ if (!from || !(e.target instanceof HTMLElement) || e.target.dataset.slot !== treemapDef.slot("tile")) return;
431
+ const list = [...this.tiles.values()];
432
+ let next;
433
+ if (e.key === "Home") next = list[0];
434
+ else if (e.key === "End") next = list[list.length - 1];
435
+ else {
436
+ const dir = { ArrowRight: [1, 0], ArrowLeft: [-1, 0], ArrowDown: [0, 1], ArrowUp: [0, -1] }[e.key];
437
+ if (!dir) return;
438
+ const cx = from.placed.x + from.placed.w / 2;
439
+ const cy = from.placed.y + from.placed.h / 2;
440
+ let best = Infinity;
441
+ for (const tile of list) {
442
+ if (tile === from) continue;
443
+ const dx = tile.placed.x + tile.placed.w / 2 - cx;
444
+ const dy = tile.placed.y + tile.placed.h / 2 - cy;
445
+ const along = dx * dir[0] + dy * dir[1];
446
+ if (along <= 0) continue;
447
+ const across = Math.abs(dx * dir[1] - dy * dir[0]);
448
+ const score = along + across * 2;
449
+ if (score < best) {
450
+ best = score;
451
+ next = tile;
452
+ }
453
+ }
454
+ }
455
+ if (!next) return;
456
+ e.preventDefault();
457
+ next.el.focus();
458
+ }
459
+ };
460
+ function position(el, box) {
461
+ el.style.left = `${box.x}px`;
462
+ el.style.top = `${box.y}px`;
463
+ el.style.width = `${box.w}px`;
464
+ el.style.height = `${box.h}px`;
465
+ }
466
+ function createTreemap(props = {}) {
467
+ return new TreemapImpl(props);
468
+ }
469
+
470
+ export { createTreemap, squarify, treemapDef };
package/llms.txt CHANGED
@@ -1,4 +1,4 @@
1
- # @luxalgo/vela-ui 0.2.0
1
+ # @luxalgo/vela-ui 0.3.0
2
2
 
3
3
  > The component kit of Vela: one file per component, Zag state machines for behavior, CSS in
4
4
  > cascade layers over design tokens, and one typed theme config.
@@ -11,7 +11,7 @@ kit host: `ensureUIHost(el, createTheme())` (`@luxalgo/vela-ui/theme`), or insid
11
11
  ## Skills (agent instructions in this package)
12
12
 
13
13
  - [theming-vela-ui](skills/theming-vela-ui/SKILL.md): Themes and restyles Vela charts and @luxalgo/vela-ui components with createTheme - brand colors, light, dark and custom themes, design tokens, component settings, part-by-part CSS restyles, scrollbars, cascade layers and theme JSON files checked with checkTheme.
14
- - [using-vela-ui-components](skills/using-vela-ui-components/SKILL.md): Builds interface pieces with @luxalgo/vela-ui, the component kit behind Vela charts - buttons, tabs, toggle groups, badges, dialogs, drawers, dropdown and context menus, tooltips, hover cards, popovers, collapsible sections, list rows, form controls (checkbox, switch, slider, input, select, number input, date and color pickers) and data components (data table, sort buttons, month grid, stat, sparkline, bar, line and scatter charts).
14
+ - [using-vela-ui-components](skills/using-vela-ui-components/SKILL.md): Builds interface pieces with @luxalgo/vela-ui, the component kit behind Vela charts - buttons, tabs, toggle groups, badges, dialogs, drawers, dropdown and context menus, tooltips, hover cards, popovers, toasts, collapsible sections, cards, list rows, form controls (checkbox, switch, slider, input, select, number input, date and color pickers) and data components (data table, sort buttons, month grid, stat, sparkline, bar, line and scatter charts, treemap).
15
15
  - [writing-vela-ui-components](skills/writing-vela-ui-components/SKILL.md): Writes new UI components with the @luxalgo/vela-ui authoring helpers (defineComponent, h, css, defineStyles, variants, t), customizes a kit component's markup or behavior by copying its source with "vela-ui add --source", and adds components to the kit itself.
16
16
 
17
17
  Link them into a project's coding agent with `npx skills experimental_sync` once the package is
@@ -36,6 +36,7 @@ installed, or install them from the repository with `npx skills add LuxAlgo/Vela
36
36
  - createBarChart (`@luxalgo/vela-ui/bar-chart`): BarChart: vertical bars around a zero line with a hover readout (daily P&L, a distribution), in the profit tone above zero and the loss tone below unless a bar names its own; optionally a value axis with gridlines and a title, slanted labels, and dashed markers.
37
37
  - createButton (`@luxalgo/vela-ui/button`): Button: a <button> with optional icons and key caps before and after its text (`↵ Open`, `Esc Close` in a picker's footer).
38
38
  - createCalloutBubble (`@luxalgo/vela-ui/callout-bubble`): CalloutBubble: a small tinted circle with a centered icon.
39
+ - createCard (`@luxalgo/vela-ui/card`): Card: a surface for one subject (a panel of figures, a chart, a summary): a header with an eyebrow over the title and a description under it, an action at its end (buttons, a toggle group), then the content and a footer past a line.
39
40
  - createCheckbox (`@luxalgo/vela-ui/checkbox`): Checkbox: a square check toggle, filled with a check mark when on.
40
41
  - createCollapsible (`@luxalgo/vela-ui/collapsible`): Collapsible: a section that shows or hides its content.
41
42
  - createColorField (`@luxalgo/vela-ui/color-picker`): ColorPicker: a swatch grid (grays, then hue × shade), a recents row with a custom "+" chooser, and an opacity slider over a transparency checker; and ColorField, the swatch button that opens it on a popover.
@@ -67,5 +68,7 @@ installed, or install them from the repository with `npx skills add LuxAlgo/Vela
67
68
  - createSwitch (`@luxalgo/vela-ui/switch`): Switch: a sliding on/off toggle, a track with a round thumb, for a setting that applies at once.
68
69
  - createTabs (`@luxalgo/vela-ui/tabs`): Tabs: a tab list over Zag's tabs machine (WAI-ARIA tabs: roving focus, the arrow keys along the orientation, Home/End, automatic or manual activation).
69
70
  - createTextArea (`@luxalgo/vela-ui/text-area`): TextArea: a multi-line text input that commits on blur, and can grow with its content up to a number of lines before it scrolls.
71
+ - createToaster (`@luxalgo/vela-ui/toast`): Toast: short notices that stack in a corner and leave on their own, shaped after shadcn's toast (Sonner).
70
72
  - createToggleGroup (`@luxalgo/vela-ui/toggle-group`): ToggleGroup: a few options side by side on one track, over Zag's toggle-group machine.
71
73
  - createTooltip (`@luxalgo/vela-ui/tooltip`): Tooltip: a floating label over Zag's tooltip machine (floating-ui placement).
74
+ - createTreemap (`@luxalgo/vela-ui/treemap`): Treemap: weighted items laid into a rectangle as tiles close to square, each tinted by its value on a diverging scale (up above zero, down below, stronger as the value grows) and labeled when it has room.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@luxalgo/vela-ui",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "The component kit of Vela: one file per component, Zag state machines for behavior, CSS in cascade layers over design tokens.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "LuxAlgo",
@@ -132,6 +132,14 @@ export const BUTTON_CSS = css`
132
132
  & > [data-keys]:where(:not([hidden])) {
133
133
  display: inline-flex;
134
134
  }
135
+ /* A key cap's own colors vanish on a fill that matches them (the solid
136
+ variants): inside a button it takes the button's text and draws only its outline. */
137
+ & > [data-keys] > [data-slot='kbd'] {
138
+ border-color: ${t.border};
139
+ background: transparent;
140
+ color: inherit;
141
+ box-shadow: none;
142
+ }
135
143
  &[data-size='sm'],
136
144
  &[data-size='icon-sm'] {
137
145
  height: ${buttonDef.vars['height-sm']};