meowtail 0.4.0-alpha.0 → 0.4.0-alpha.2

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 (147) hide show
  1. package/ASSISTANT.md +2 -2
  2. package/AUTHORING.md +268 -0
  3. package/CHANGELOG.md +116 -0
  4. package/COMPONENTS.md +182 -140
  5. package/README.md +145 -34
  6. package/dist/src/chat/assistant-content.js +3 -1
  7. package/dist/src/chat/assistant-markdown.d.ts +8 -5
  8. package/dist/src/chat/assistant-markdown.js +11 -26
  9. package/dist/src/components/autocomplete.d.ts +47 -0
  10. package/dist/src/components/autocomplete.js +169 -0
  11. package/dist/src/components/card-title.d.ts +1 -0
  12. package/dist/src/components/card-title.js +2 -1
  13. package/dist/src/components/chart-scale.d.ts +46 -0
  14. package/dist/src/components/chart-scale.js +118 -0
  15. package/dist/src/components/chart.d.ts +38 -0
  16. package/dist/src/components/chart.js +210 -0
  17. package/dist/src/components/choice-group.js +2 -2
  18. package/dist/src/components/choice-select.js +2 -2
  19. package/dist/src/components/code-block.d.ts +3 -1
  20. package/dist/src/components/code-block.js +75 -16
  21. package/dist/src/components/command-palette.d.ts +44 -0
  22. package/dist/src/components/command-palette.js +198 -0
  23. package/dist/src/components/context-menu.d.ts +2 -1
  24. package/dist/src/components/context-menu.js +2 -1
  25. package/dist/src/components/credential-source.d.ts +2 -1
  26. package/dist/src/components/credential-source.js +2 -1
  27. package/dist/src/components/detail-section.d.ts +2 -1
  28. package/dist/src/components/detail-section.js +8 -3
  29. package/dist/src/components/dialog.d.ts +4 -1
  30. package/dist/src/components/dialog.js +7 -2
  31. package/dist/src/components/entry.d.ts +45 -0
  32. package/dist/src/components/entry.js +38 -0
  33. package/dist/src/components/entry.options.d.ts +4 -0
  34. package/dist/src/components/entry.options.js +3 -0
  35. package/dist/src/components/field-group.js +2 -2
  36. package/dist/src/components/field.d.ts +4 -0
  37. package/dist/src/components/field.js +15 -3
  38. package/dist/src/components/form.d.ts +34 -0
  39. package/dist/src/components/form.js +58 -0
  40. package/dist/src/components/heading-level.d.ts +9 -0
  41. package/dist/src/components/heading-level.js +12 -0
  42. package/dist/src/components/hover-card.d.ts +3 -2
  43. package/dist/src/components/hover-card.js +50 -15
  44. package/dist/src/components/index.d.ts +11 -1
  45. package/dist/src/components/index.js +11 -1
  46. package/dist/src/components/markdown-blocks.d.ts +27 -0
  47. package/dist/src/components/markdown-blocks.js +141 -0
  48. package/dist/src/components/markdown.d.ts +35 -0
  49. package/dist/src/components/markdown.js +35 -0
  50. package/dist/src/components/menu-button.d.ts +2 -1
  51. package/dist/src/components/menu.d.ts +2 -1
  52. package/dist/src/components/menu.js +2 -1
  53. package/dist/src/components/modal.js +2 -2
  54. package/dist/src/components/page.js +1 -1
  55. package/dist/src/components/pagination.d.ts +52 -0
  56. package/dist/src/components/pagination.js +89 -0
  57. package/dist/src/components/path-label.js +5 -27
  58. package/dist/src/components/popover.d.ts +2 -1
  59. package/dist/src/components/popover.js +33 -6
  60. package/dist/src/components/resource-card.d.ts +4 -1
  61. package/dist/src/components/resource-card.js +7 -2
  62. package/dist/src/components/risk-confirmation.d.ts +2 -1
  63. package/dist/src/components/risk-confirmation.js +2 -1
  64. package/dist/src/components/section.d.ts +1 -7
  65. package/dist/src/components/section.js +3 -8
  66. package/dist/src/components/segmented-control.d.ts +2 -1
  67. package/dist/src/components/segmented-control.js +2 -1
  68. package/dist/src/components/tabs.d.ts +2 -1
  69. package/dist/src/components/tabs.js +2 -1
  70. package/dist/src/components/token-field.d.ts +45 -0
  71. package/dist/src/components/token-field.js +175 -0
  72. package/dist/src/components/tooltip.d.ts +2 -1
  73. package/dist/src/components/tooltip.js +2 -1
  74. package/dist/src/components/tree-view.d.ts +39 -0
  75. package/dist/src/components/tree-view.js +244 -0
  76. package/dist/src/components/tree-view.options.d.ts +2 -0
  77. package/dist/src/components/tree-view.options.js +3 -0
  78. package/dist/src/icons/README.md +11 -10
  79. package/dist/src/icons/icon.d.ts +1 -0
  80. package/dist/src/icons/icon.js +2 -1
  81. package/dist/src/icons/index.d.ts +0 -1
  82. package/dist/src/icons/index.js +0 -1
  83. package/dist/src/registry/index.d.ts +41 -1
  84. package/dist/src/registry/index.js +20 -0
  85. package/dist/src/shared/element-id.d.ts +6 -0
  86. package/dist/src/shared/element-id.js +10 -0
  87. package/dist/src/shared/page-attribute.d.ts +5 -0
  88. package/dist/src/shared/page-attribute.js +5 -0
  89. package/dist/src/theme/base.styles.d.ts +2 -0
  90. package/dist/src/theme/base.styles.js +41 -4
  91. package/dist/src/theme/chat/assistant.styles.js +21 -1
  92. package/dist/src/theme/chat/attachments.styles.js +35 -6
  93. package/dist/src/theme/chat/composer.styles.js +30 -3
  94. package/dist/src/theme/chat/conversation.styles.js +13 -1
  95. package/dist/src/theme/chat/records.styles.js +10 -5
  96. package/dist/src/theme/components/autocomplete.styles.d.ts +1 -0
  97. package/dist/src/theme/components/autocomplete.styles.js +68 -0
  98. package/dist/src/theme/components/button.styles.js +0 -1
  99. package/dist/src/theme/components/card.styles.js +2 -1
  100. package/dist/src/theme/components/chart.styles.d.ts +1 -0
  101. package/dist/src/theme/components/chart.styles.js +173 -0
  102. package/dist/src/theme/components/code-block.styles.js +79 -38
  103. package/dist/src/theme/components/command-palette.styles.d.ts +1 -0
  104. package/dist/src/theme/components/command-palette.styles.js +143 -0
  105. package/dist/src/theme/components/dialog.styles.js +2 -1
  106. package/dist/src/theme/components/empty-state.styles.js +2 -1
  107. package/dist/src/theme/components/entry.styles.d.ts +1 -0
  108. package/dist/src/theme/components/entry.styles.js +86 -0
  109. package/dist/src/theme/components/form.styles.d.ts +1 -0
  110. package/dist/src/theme/components/form.styles.js +32 -0
  111. package/dist/src/theme/components/hover-card.styles.js +57 -12
  112. package/dist/src/theme/components/image-preview.styles.js +25 -0
  113. package/dist/src/theme/components/layout.styles.js +6 -0
  114. package/dist/src/theme/components/markdown.styles.d.ts +1 -0
  115. package/dist/src/theme/components/markdown.styles.js +10 -0
  116. package/dist/src/theme/components/nav-list.styles.js +6 -7
  117. package/dist/src/theme/components/pagination.styles.d.ts +1 -0
  118. package/dist/src/theme/components/pagination.styles.js +103 -0
  119. package/dist/src/theme/components/path-label.styles.js +19 -6
  120. package/dist/src/theme/components/resource-card.styles.js +2 -1
  121. package/dist/src/theme/components/search-input.styles.js +23 -0
  122. package/dist/src/theme/components/slider.styles.js +4 -0
  123. package/dist/src/theme/components/token-field.styles.d.ts +1 -0
  124. package/dist/src/theme/components/token-field.styles.js +109 -0
  125. package/dist/src/theme/components/tree-view.styles.d.ts +1 -0
  126. package/dist/src/theme/components/tree-view.styles.js +104 -0
  127. package/dist/src/theme/icons/icons.styles.js +0 -18
  128. package/dist/src/theme/index.d.ts +446 -9
  129. package/dist/src/theme/index.js +58 -1
  130. package/dist/src/theme/journal.tokens.d.ts +389 -0
  131. package/dist/src/theme/journal.tokens.js +181 -0
  132. package/dist/src/theme/meow.tokens.d.ts +362 -0
  133. package/dist/src/theme/meow.tokens.js +91 -0
  134. package/dist/src/theme/shared/field-surface.styles.js +11 -7
  135. package/dist/src/theme/shared/prose.styles.js +12 -4
  136. package/dist/src/theme/tokens.d.ts +286 -7
  137. package/dist/src/theme/tokens.js +15 -2
  138. package/dist/src/theme/utilities.js +4 -4
  139. package/dist/src/web/focus-modality.d.ts +20 -0
  140. package/dist/src/web/focus-modality.js +72 -0
  141. package/dist/src/web/index.d.ts +2 -0
  142. package/dist/src/web/index.js +2 -0
  143. package/dist/src/web/theme-plugin.d.ts +33 -0
  144. package/dist/src/web/theme-plugin.js +93 -0
  145. package/package.json +14 -6
  146. package/dist/src/icons/doodle-cat.d.ts +0 -5
  147. package/dist/src/icons/doodle-cat.js +0 -8
@@ -0,0 +1,169 @@
1
+ import { h, keyed } from "meowjsx";
2
+ import { derived, signal, unwrap } from "meowjsx/signal";
3
+ import { Popover } from "./popover.js";
4
+ import { elementByIdInRoot } from "../shared/dom-root.js";
5
+ import { elementId } from "../shared/element-id.js";
6
+ /**
7
+ * A text field that offers host suggestions without constraining the text. Focus stays in the
8
+ * input; the list is a popup listbox driven by the arrow keys.
9
+ */
10
+ export function Autocomplete({ id = elementId("autocomplete"), value, defaultValue = "", onValueChange, suggestions, onAccept, loading, loadingMessage = "Loading suggestions", listLabel = "Suggestions", emptyMessage, name, disabled = false, required = false, placeholder, className, ref, ...props }, context) {
11
+ const local = signal(defaultValue);
12
+ const current = value !== undefined ? value : local;
13
+ const listId = `${id}-list`;
14
+ // The reader asked for the list; it shows only when there is something to show.
15
+ const wanted = signal(false);
16
+ const active = signal(undefined);
17
+ let input;
18
+ let alive = true;
19
+ context.onCleanup(() => {
20
+ alive = false;
21
+ });
22
+ const optionIds = new Map();
23
+ const optionId = (key) => {
24
+ let known = optionIds.get(key);
25
+ if (!known)
26
+ optionIds.set(key, (known = elementId(`${id}-option`)));
27
+ return known;
28
+ };
29
+ const list = () => unwrap(suggestions);
30
+ const showEmpty = derived(() => emptyMessage !== undefined &&
31
+ loading !== undefined &&
32
+ !unwrap(loading) &&
33
+ list().length === 0 &&
34
+ unwrap(current).trim() !== "");
35
+ const open = derived(() => wanted.value &&
36
+ !unwrap(disabled) &&
37
+ (list().length > 0 || Boolean(unwrap(loading)) || showEmpty.value));
38
+ // An active value that left the list is no longer active.
39
+ const activeValue = derived(() => open.value && list().some((item) => item.value === active.value) ? active.value : undefined);
40
+ const write = (text) => {
41
+ if (value === undefined)
42
+ local.value = text;
43
+ onValueChange?.(text);
44
+ };
45
+ const close = () => {
46
+ wanted.value = false;
47
+ active.value = undefined;
48
+ };
49
+ const accept = (suggestion) => {
50
+ write(suggestion.value);
51
+ // A controlled host that ignores the change still sees the input match its own value.
52
+ if (input)
53
+ input.value = unwrap(current);
54
+ close();
55
+ onAccept?.(suggestion);
56
+ };
57
+ const reveal = (key) => {
58
+ queueMicrotask(() => {
59
+ if (!alive || !input)
60
+ return;
61
+ elementByIdInRoot(input, optionId(key))?.scrollIntoView?.({ block: "nearest" });
62
+ });
63
+ };
64
+ const move = (step) => {
65
+ const items = list();
66
+ if (items.length === 0)
67
+ return;
68
+ const index = items.findIndex((item) => item.value === activeValue.value);
69
+ const next = step === "first"
70
+ ? 0
71
+ : step === "last"
72
+ ? items.length - 1
73
+ : index < 0
74
+ ? step === 1
75
+ ? 0
76
+ : items.length - 1
77
+ : (index + step + items.length) % items.length;
78
+ active.value = items[next].value;
79
+ reveal(items[next].value);
80
+ };
81
+ const keydown = (event) => {
82
+ if (event.isComposing || unwrap(disabled))
83
+ return;
84
+ if (event.key === "ArrowDown" || event.key === "ArrowUp") {
85
+ event.preventDefault();
86
+ if (!open.value) {
87
+ wanted.value = true;
88
+ if (event.altKey)
89
+ return;
90
+ }
91
+ move(event.key === "ArrowDown" ? 1 : -1);
92
+ }
93
+ else if ((event.key === "Home" || event.key === "End") && activeValue.value !== undefined) {
94
+ event.preventDefault();
95
+ move(event.key === "Home" ? "first" : "last");
96
+ }
97
+ else if (event.key === "Enter") {
98
+ const chosen = list().find((item) => item.value === activeValue.value);
99
+ // Without an active option Enter belongs to the form.
100
+ if (!chosen)
101
+ return;
102
+ event.preventDefault();
103
+ accept(chosen);
104
+ }
105
+ else if (event.key === "Escape") {
106
+ if (!open.value)
107
+ return;
108
+ event.preventDefault();
109
+ close();
110
+ }
111
+ else if (event.key === "Tab") {
112
+ close();
113
+ }
114
+ };
115
+ return (h("div", { className: className, ref: [context.parts.root] }, h(Popover, {
116
+ id: `${id}-popup`,
117
+ triggerId: id,
118
+ open,
119
+ onOpenChange: (next) => {
120
+ if (!next)
121
+ close();
122
+ },
123
+ matchTriggerWidth: true,
124
+ trigger: (bindings) => (h("input", { ...props, id: bindings.id, type: "text", role: "combobox", name: name, required: required, disabled: disabled, placeholder: placeholder, autoComplete: "off", "aria-autocomplete": "list", "aria-haspopup": "listbox", "aria-expanded": derived(() => String(open.value)), "aria-controls": listId, "aria-activedescendant": derived(() => activeValue.value === undefined ? undefined : optionId(activeValue.value)), value: current, onInput: (event) => {
125
+ write(event.currentTarget.value);
126
+ active.value = undefined;
127
+ wanted.value = true;
128
+ }, onKeyDown: keydown, onBlur: () => close(), ref: [
129
+ context.parts.input,
130
+ ref,
131
+ (element) => {
132
+ input = element;
133
+ const form = element.form;
134
+ if (!form)
135
+ return;
136
+ let timer;
137
+ // Native reset restores the attribute default; the owner signal follows it.
138
+ const reset = (event) => {
139
+ clearTimeout(timer);
140
+ timer = setTimeout(() => {
141
+ if (!alive || event.defaultPrevented)
142
+ return;
143
+ // A controlled host learns about the reset through the usual callback.
144
+ write(defaultValue);
145
+ element.value = unwrap(current);
146
+ close();
147
+ }, 0);
148
+ };
149
+ form.addEventListener("reset", reset);
150
+ return () => {
151
+ clearTimeout(timer);
152
+ form.removeEventListener("reset", reset);
153
+ };
154
+ },
155
+ ] })),
156
+ children: [
157
+ h("div", { id: listId, role: "listbox", "aria-label": listLabel, ref: context.parts.list }, keyed(suggestions, (item) => item.value, (item) => (h("div", { id: optionId(item.value.value), role: "option", "aria-selected": derived(() => String(activeValue.value === item.value.value)),
158
+ // Keep focus in the input; a pointer choice does not blur it.
159
+ onMouseDown: (event) => event.preventDefault(), onClick: () => accept(item.value), ref: context.parts.option },
160
+ h("span", { ref: context.parts.label }, derived(() => item.value.label ?? item.value.value)),
161
+ h("span", { hidden: derived(() => !item.value.description), ref: context.parts.description }, derived(() => item.value.description ?? "")))))),
162
+ h("p", { role: "status", hidden: derived(() => !unwrap(loading) && !showEmpty.value), ref: context.parts.status }, derived(() => (unwrap(loading) ? loadingMessage : (emptyMessage ?? "")))),
163
+ ],
164
+ })));
165
+ }
166
+ Autocomplete.meta = {
167
+ name: "autocomplete",
168
+ parts: ["root", "input", "list", "option", "label", "description", "status"],
169
+ };
@@ -1,5 +1,6 @@
1
1
  import { type Props, type Context } from "meowjsx";
2
2
  export interface CardTitleProps extends Props {
3
+ /** Defaults to one level below the surrounding `Page` or `Section` heading (h2 at the top). */
3
4
  as?: "h2" | "h3" | "h4" | "h5" | "h6";
4
5
  className?: Props["className"];
5
6
  }
@@ -1,6 +1,7 @@
1
1
  import { h } from "meowjsx";
2
+ import { nestedHeadingLevel } from "./heading-level.js";
2
3
  /** The title of a card. */
3
- export function CardTitle({ as = "h2", children, className, ...props }, context) {
4
+ export function CardTitle({ as = `h${nestedHeadingLevel()}`, children, className, ...props }, context) {
4
5
  return h(as, { ...props, className, ref: [context.parts.root, props.ref] }, children);
5
6
  }
6
7
  CardTitle.meta = { name: "card-title", parts: ["root"] };
@@ -0,0 +1,46 @@
1
+ /** Pure chart geometry: nice ticks, series admission and the band layout. No DOM. */
2
+ export interface ChartSeries {
3
+ /** Unique in the chart; keeps the series' color slot and marks across updates. */
4
+ id: string;
5
+ label: string;
6
+ /** One value per category; null is a missing value. */
7
+ values: readonly (number | null)[];
8
+ }
9
+ /** The categorical slots in `chartTokens`; a series takes the next and keeps it. */
10
+ export declare const chartSeriesLimit = 8;
11
+ /**
12
+ * The series a chart draws: at most eight, each with exactly one value per category. Extra
13
+ * values are cut, missing ones become null and non-finite numbers are treated as missing.
14
+ */
15
+ export declare function admitSeries(series: readonly ChartSeries[], categoryCount: number): readonly ChartSeries[];
16
+ /**
17
+ * Round tick values covering [min, max] with about `count` steps. A flat or empty range still
18
+ * yields a usable axis.
19
+ */
20
+ export declare function niceTicks(min: number, max: number, count?: number): readonly number[];
21
+ /** The value domain: bars always include zero so their lengths compare honestly. */
22
+ export declare function valueDomain(series: readonly ChartSeries[], includeZero: boolean): readonly number[];
23
+ export interface ChartFrame {
24
+ width: number;
25
+ height: number;
26
+ left: number;
27
+ right: number;
28
+ top: number;
29
+ bottom: number;
30
+ }
31
+ /** The vertical position of a value inside the plot area. */
32
+ export declare function valueY(frame: ChartFrame, ticks: readonly number[], value: number): number;
33
+ /** The center of a category band. */
34
+ export declare function bandCenter(frame: ChartFrame, count: number, index: number): number;
35
+ export declare function bandWidth(frame: ChartFrame, count: number): number;
36
+ /** One rect per value: series side by side inside each band, 70% of the band in all. */
37
+ export declare function barRect(frame: ChartFrame, ticks: readonly number[], categoryCount: number, seriesCount: number, categoryIndex: number, seriesIndex: number, value: number | null): {
38
+ x: number;
39
+ y: number;
40
+ width: number;
41
+ height: number;
42
+ };
43
+ /** An SVG path through the points, broken at missing values. */
44
+ export declare function linePath(frame: ChartFrame, ticks: readonly number[], values: readonly (number | null)[]): string;
45
+ /** Point markers that differ by shape as well as color, one per series slot. */
46
+ export declare function markerPath(slot: number, x: number, y: number, size?: number): string;
@@ -0,0 +1,118 @@
1
+ /** Pure chart geometry: nice ticks, series admission and the band layout. No DOM. */
2
+ /** The categorical slots in `chartTokens`; a series takes the next and keeps it. */
3
+ export const chartSeriesLimit = 8;
4
+ /**
5
+ * The series a chart draws: at most eight, each with exactly one value per category. Extra
6
+ * values are cut, missing ones become null and non-finite numbers are treated as missing.
7
+ */
8
+ export function admitSeries(series, categoryCount) {
9
+ return series.slice(0, chartSeriesLimit).map((entry) => ({
10
+ ...entry,
11
+ values: Array.from({ length: categoryCount }, (_, index) => {
12
+ const value = entry.values[index];
13
+ return typeof value === "number" && Number.isFinite(value) ? value : null;
14
+ }),
15
+ }));
16
+ }
17
+ function niceStep(rough) {
18
+ const power = 10 ** Math.floor(Math.log10(rough));
19
+ const fraction = rough / power;
20
+ const nice = fraction <= 1 ? 1 : fraction <= 2 ? 2 : fraction <= 2.5 ? 2.5 : fraction <= 5 ? 5 : 10;
21
+ return nice * power;
22
+ }
23
+ /**
24
+ * Round tick values covering [min, max] with about `count` steps. A flat or empty range still
25
+ * yields a usable axis.
26
+ */
27
+ export function niceTicks(min, max, count = 5) {
28
+ if (!Number.isFinite(min) || !Number.isFinite(max))
29
+ return [0, 1];
30
+ if (min === max) {
31
+ if (min === 0)
32
+ return [0, 1];
33
+ const pad = Math.abs(min) / 2;
34
+ return niceTicks(min - pad, max + pad, count);
35
+ }
36
+ const step = niceStep((max - min) / Math.max(1, count - 1));
37
+ const start = Math.floor(min / step) * step;
38
+ const end = Math.ceil(max / step) * step;
39
+ const ticks = [];
40
+ // Rounding keeps 0.1 + 0.2 from printing as 0.30000000000000004.
41
+ const digits = Math.max(0, -Math.floor(Math.log10(step)) + 1);
42
+ for (let value = start; value <= end + step / 2; value += step)
43
+ ticks.push(Number(value.toFixed(digits)));
44
+ return ticks;
45
+ }
46
+ /** The value domain: bars always include zero so their lengths compare honestly. */
47
+ export function valueDomain(series, includeZero) {
48
+ const values = series.flatMap((entry) => entry.values.filter((value) => value !== null));
49
+ if (values.length === 0)
50
+ return niceTicks(0, 1);
51
+ let min = Math.min(...values);
52
+ let max = Math.max(...values);
53
+ if (includeZero) {
54
+ min = Math.min(0, min);
55
+ max = Math.max(0, max);
56
+ }
57
+ return niceTicks(min, max);
58
+ }
59
+ /** The vertical position of a value inside the plot area. */
60
+ export function valueY(frame, ticks, value) {
61
+ const low = ticks[0];
62
+ const high = ticks.at(-1);
63
+ const plot = frame.height - frame.top - frame.bottom;
64
+ return frame.top + plot * (1 - (value - low) / (high - low || 1));
65
+ }
66
+ /** The center of a category band. */
67
+ export function bandCenter(frame, count, index) {
68
+ const band = (frame.width - frame.left - frame.right) / Math.max(1, count);
69
+ return frame.left + band * (index + 0.5);
70
+ }
71
+ export function bandWidth(frame, count) {
72
+ return (frame.width - frame.left - frame.right) / Math.max(1, count);
73
+ }
74
+ /** One rect per value: series side by side inside each band, 70% of the band in all. */
75
+ export function barRect(frame, ticks, categoryCount, seriesCount, categoryIndex, seriesIndex, value) {
76
+ const band = bandWidth(frame, categoryCount);
77
+ const group = band * 0.7;
78
+ const width = Math.max(1, group / Math.max(1, seriesCount) - (seriesCount > 1 ? 2 : 0));
79
+ const x = frame.left +
80
+ band * categoryIndex +
81
+ (band - group) / 2 +
82
+ (group / Math.max(1, seriesCount)) * seriesIndex;
83
+ if (value === null)
84
+ return { x, y: valueY(frame, ticks, 0), width, height: 0 };
85
+ const zero = valueY(frame, ticks, Math.min(Math.max(0, ticks[0]), ticks.at(-1)));
86
+ const end = valueY(frame, ticks, value);
87
+ return { x, y: Math.min(zero, end), width, height: Math.abs(zero - end) };
88
+ }
89
+ /** An SVG path through the points, broken at missing values. */
90
+ export function linePath(frame, ticks, values) {
91
+ let path = "";
92
+ let drawing = false;
93
+ values.forEach((value, index) => {
94
+ if (value === null) {
95
+ drawing = false;
96
+ return;
97
+ }
98
+ const x = bandCenter(frame, values.length, index).toFixed(1);
99
+ const y = valueY(frame, ticks, value).toFixed(1);
100
+ path += `${drawing ? "L" : "M"}${x} ${y}`;
101
+ drawing = true;
102
+ });
103
+ return path;
104
+ }
105
+ /** Point markers that differ by shape as well as color, one per series slot. */
106
+ export function markerPath(slot, x, y, size = 4) {
107
+ const s = size;
108
+ switch (slot % 4) {
109
+ case 0:
110
+ return `M${x - s} ${y}a${s} ${s} 0 1 0 ${2 * s} 0a${s} ${s} 0 1 0 ${-2 * s} 0`;
111
+ case 1:
112
+ return `M${x - s} ${y - s}h${2 * s}v${2 * s}h${-2 * s}z`;
113
+ case 2:
114
+ return `M${x} ${y - s * 1.2}L${x + s * 1.2} ${y + s}H${x - s * 1.2}z`;
115
+ default:
116
+ return `M${x} ${y - s * 1.3}L${x + s * 1.3} ${y}L${x} ${y + s * 1.3}L${x - s * 1.3} ${y}z`;
117
+ }
118
+ }
@@ -0,0 +1,38 @@
1
+ import { type Context, type Props } from "meowjsx";
2
+ import { type MaybeSignal } from "meowjsx/signal";
3
+ import { type ChartSeries } from "./chart-scale.js";
4
+ export { admitSeries, chartSeriesLimit, niceTicks, type ChartSeries } from "./chart-scale.js";
5
+ export interface ChartProps extends Props {
6
+ /** Bars compare categories; a line follows a trend. Fixed for the mount. */
7
+ type: "bar" | "line";
8
+ /** Names the figure; shown as its caption. */
9
+ label: string;
10
+ description?: string;
11
+ categories: MaybeSignal<readonly string[]>;
12
+ /** At most eight series, in the fixed color order; later ones are not drawn. */
13
+ series: MaybeSignal<readonly ChartSeries[]>;
14
+ /** Appended to every value, for example "%" or " ms". */
15
+ unit?: string;
16
+ /** Formats ticks, the inspection readout and the table. Overrides `unit`. */
17
+ formatValue?: (value: number) => string;
18
+ /** Plot height in px. The width follows the container. */
19
+ height?: number;
20
+ missingLabel?: string;
21
+ dataLabel?: string;
22
+ /** Header of the table's first column. */
23
+ categoryLabel?: string;
24
+ /** How to read values with the keyboard, read when the plot takes focus. */
25
+ hint?: string;
26
+ className?: Props["className"];
27
+ }
28
+ /**
29
+ * A bar or line chart of host data. Color is never the only cue: a legend names every series,
30
+ * line markers differ by shape, and a data table carries every value.
31
+ */
32
+ export declare function Chart({ type, label, description, categories, series, unit, formatValue, height, missingLabel, dataLabel, categoryLabel, hint, className, ref, ...props }: ChartProps, context: Context<typeof Chart>): import("meowjsx").VNode;
33
+ export declare namespace Chart {
34
+ var meta: {
35
+ readonly name: "chart";
36
+ readonly parts: readonly ["root", "caption", "title", "description", "legend", "legendItem", "swatch", "plot", "svg", "grid", "gridLine", "tick", "cursor", "bar", "series", "line", "marker", "category", "tooltip", "live", "data", "dataToggle"];
37
+ };
38
+ }
@@ -0,0 +1,210 @@
1
+ import { h, keyed } from "meowjsx";
2
+ import { derived, signal, unwrap } from "meowjsx/signal";
3
+ import { Table } from "./table.js";
4
+ import { elementId } from "../shared/element-id.js";
5
+ import { admitSeries, barRect, bandCenter, chartSeriesLimit, linePath, markerPath, valueDomain, valueY, } from "./chart-scale.js";
6
+ export { admitSeries, chartSeriesLimit, niceTicks } from "./chart-scale.js";
7
+ const defaultWidth = 600;
8
+ /**
9
+ * A bar or line chart of host data. Color is never the only cue: a legend names every series,
10
+ * line markers differ by shape, and a data table carries every value.
11
+ */
12
+ export function Chart({ type, label, description, categories, series, unit = "", formatValue, height = 240, missingLabel = "No value", dataLabel = "Show data", categoryLabel = "Category", hint = "Use the left and right arrow keys to read each category.", className, ref, ...props }, context) {
13
+ const numbers = new Intl.NumberFormat(undefined, { maximumFractionDigits: 2 });
14
+ const format = formatValue ?? ((value) => `${numbers.format(value)}${unit}`);
15
+ const width = signal(defaultWidth);
16
+ const hintId = elementId("chart-hint");
17
+ const cursor = signal(undefined);
18
+ let warned = false;
19
+ const names = derived(() => unwrap(categories));
20
+ const admitted = derived(() => {
21
+ const given = unwrap(series);
22
+ if (given.length > chartSeriesLimit && !warned) {
23
+ warned = true;
24
+ console.warn(`Chart "${label}" draws ${chartSeriesLimit} series; the rest are left out.`);
25
+ }
26
+ return admitSeries(given, names.value.length);
27
+ });
28
+ const ticks = derived(() => valueDomain(admitted.value, type === "bar"));
29
+ const frame = derived(() => {
30
+ const longest = Math.max(...ticks.value.map((tick) => format(tick).length));
31
+ return {
32
+ width: width.value,
33
+ height,
34
+ // Room for the longest tick label at the caption size.
35
+ left: Math.min(96, 12 + longest * 7),
36
+ right: 12,
37
+ top: 12,
38
+ bottom: 28,
39
+ };
40
+ });
41
+ // Category labels thin out when the bands are narrower than the labels.
42
+ const labelStep = derived(() => {
43
+ const count = names.value.length;
44
+ const band = (frame.value.width - frame.value.left - frame.value.right) / Math.max(1, count);
45
+ const longest = Math.max(1, ...names.value.map((name) => name.length));
46
+ return Math.max(1, Math.ceil((longest * 7 + 8) / Math.max(1, band)));
47
+ });
48
+ const readout = derived(() => {
49
+ const index = cursor.value;
50
+ if (index === undefined || index >= names.value.length)
51
+ return "";
52
+ const values = admitted.value.map((entry) => `${entry.label}: ${entry.values[index] === null ? missingLabel : format(entry.values[index])}`);
53
+ return `${names.value[index]}. ${values.join(", ")}`;
54
+ });
55
+ const move = (index) => {
56
+ const count = names.value.length;
57
+ if (count === 0)
58
+ return;
59
+ cursor.value = Math.min(count - 1, Math.max(0, index));
60
+ };
61
+ const keydown = (event) => {
62
+ const index = cursor.value;
63
+ const last = names.value.length - 1;
64
+ const next = event.key === "ArrowRight"
65
+ ? index === undefined
66
+ ? 0
67
+ : index + 1
68
+ : event.key === "ArrowLeft"
69
+ ? index === undefined
70
+ ? last
71
+ : index - 1
72
+ : event.key === "Home"
73
+ ? 0
74
+ : event.key === "End"
75
+ ? last
76
+ : undefined;
77
+ if (next === undefined) {
78
+ if (event.key === "Escape" && cursor.value !== undefined) {
79
+ event.preventDefault();
80
+ cursor.value = undefined;
81
+ }
82
+ return;
83
+ }
84
+ event.preventDefault();
85
+ move(next);
86
+ };
87
+ const pointer = (event) => {
88
+ const target = event.currentTarget;
89
+ const bounds = target.getBoundingClientRect();
90
+ const x = ((event.clientX - bounds.left) / bounds.width) * frame.value.width;
91
+ const plot = frame.value.width - frame.value.left - frame.value.right;
92
+ const count = names.value.length;
93
+ if (count === 0 || x < frame.value.left || x > frame.value.left + plot) {
94
+ cursor.value = undefined;
95
+ return;
96
+ }
97
+ move(Math.floor(((x - frame.value.left) / plot) * count));
98
+ };
99
+ const categoryEntries = derived(() => names.value.map((name, index) => ({ key: index, name, index })));
100
+ const seriesEntries = derived(() => admitted.value.map((entry, slot) => ({ key: entry.id, entry, slot })));
101
+ const barEntries = derived(() => admitted.value.flatMap((entry, slot) => entry.values.map((value, index) => ({ key: `${entry.id}:${index}`, slot, index, value }))));
102
+ const tableColumns = derived(() => admitted.value.map((entry) => `${entry.id}\u0000${entry.label}`).join("\u0001"));
103
+ const tableRows = derived(() => names.value.map((name, index) => ({
104
+ id: String(index),
105
+ cells: [
106
+ name,
107
+ ...admitted.value.map((entry) => entry.values[index] === null ? missingLabel : format(entry.values[index])),
108
+ ],
109
+ })));
110
+ return (h("figure", { ...props, className: className, ref: [context.parts.root, ref] },
111
+ h("figcaption", { ref: context.parts.caption },
112
+ h("span", { ref: context.parts.title }, label),
113
+ description ? h("span", { ref: context.parts.description }, description) : null),
114
+ h("ul", { "aria-label": "Legend", hidden: derived(() => admitted.value.length < 2), ref: context.parts.legend }, keyed(seriesEntries, (item) => item.key, (item) => (h("li", { ref: context.parts.legendItem },
115
+ h("svg", { viewBox: "0 0 12 12", width: "12", height: "12", "aria-hidden": "true", "data-series": derived(() => String(item.value.slot + 1)), ref: context.parts.swatch }, type === "line" ? (h("path", { d: derived(() => markerPath(item.value.slot, 6, 6, 4)) })) : (h("rect", { x: "1", y: "1", width: "10", height: "10", rx: "2" }))),
116
+ h("span", null, derived(() => item.value.entry.label)))))),
117
+ h("div", { role: "group", "aria-label": label, "aria-describedby": hintId, tabIndex: 0, onKeyDown: keydown, onPointerMove: pointer, onPointerLeave: (event) => {
118
+ if (event.currentTarget !== event.currentTarget.ownerDocument.activeElement)
119
+ cursor.value = undefined;
120
+ }, onBlur: () => {
121
+ cursor.value = undefined;
122
+ }, ref: [
123
+ context.parts.plot,
124
+ (element) => {
125
+ const measure = () => {
126
+ const next = Math.round(element.clientWidth);
127
+ if (next > 0 && next !== width.value)
128
+ width.value = next;
129
+ };
130
+ measure();
131
+ if (typeof ResizeObserver === "undefined")
132
+ return;
133
+ const observer = new ResizeObserver(measure);
134
+ observer.observe(element);
135
+ return () => observer.disconnect();
136
+ },
137
+ ] },
138
+ h("svg", { "aria-hidden": "true", width: "100%", height: String(height), viewBox: derived(() => `0 0 ${frame.value.width} ${height}`), preserveAspectRatio: "none", ref: context.parts.svg },
139
+ h("g", { ref: context.parts.grid }, keyed(ticks, (tick) => tick, (tick) => {
140
+ const y = derived(() => valueY(frame.value, ticks.value, tick.value).toFixed(1));
141
+ return (h("g", null,
142
+ h("line", { x1: derived(() => String(frame.value.left)), x2: derived(() => String(frame.value.width - frame.value.right)), y1: y, y2: y, "data-zero": derived(() => (tick.value === 0 ? "true" : undefined)), ref: context.parts.gridLine }),
143
+ h("text", { x: derived(() => String(frame.value.left - 8)), y: y, "text-anchor": "end", "dominant-baseline": "middle", ref: context.parts.tick }, derived(() => format(tick.value)))));
144
+ })),
145
+ h("line", { y1: derived(() => String(frame.value.top)), y2: derived(() => String(frame.value.height - frame.value.bottom)), x1: derived(() => cursor.value === undefined
146
+ ? "0"
147
+ : bandCenter(frame.value, names.value.length, cursor.value).toFixed(1)), x2: derived(() => cursor.value === undefined
148
+ ? "0"
149
+ : bandCenter(frame.value, names.value.length, cursor.value).toFixed(1)), visibility: derived(() => (cursor.value === undefined ? "hidden" : "visible")), ref: context.parts.cursor }),
150
+ h("g", null, type === "bar"
151
+ ? keyed(barEntries, (item) => item.key, (item) => {
152
+ const rect = derived(() => barRect(frame.value, ticks.value, names.value.length, admitted.value.length, item.value.index, item.value.slot, item.value.value));
153
+ return (h("rect", { x: derived(() => rect.value.x.toFixed(1)), y: derived(() => rect.value.y.toFixed(1)), width: derived(() => rect.value.width.toFixed(1)), height: derived(() => rect.value.height.toFixed(1)), rx: "2", "data-series": derived(() => String(item.value.slot + 1)), "data-active": derived(() => cursor.value === item.value.index ? "true" : undefined), ref: context.parts.bar }));
154
+ })
155
+ : keyed(seriesEntries, (item) => item.key, (item) => (h("g", { "data-series": derived(() => String(item.value.slot + 1)), ref: context.parts.series },
156
+ h("path", { d: derived(() => linePath(frame.value, ticks.value, item.value.entry.values)), fill: "none", ref: context.parts.line }),
157
+ h("path", { d: derived(() => item.value.entry.values
158
+ .map((value, index) => value === null
159
+ ? ""
160
+ : markerPath(item.value.slot, bandCenter(frame.value, names.value.length, index), valueY(frame.value, ticks.value, value), cursor.value === index ? 5 : 3.5))
161
+ .join("")), ref: context.parts.marker }))))),
162
+ h("g", null, keyed(categoryEntries, (item) => item.key, (item) => (h("text", { x: derived(() => bandCenter(frame.value, names.value.length, item.value.index).toFixed(1)), y: String(height - 8), "text-anchor": "middle", visibility: derived(() => item.value.index % labelStep.value === 0 ? "visible" : "hidden"), ref: context.parts.category }, derived(() => item.value.name)))))),
163
+ h("div", { "aria-hidden": "true", hidden: derived(() => cursor.value === undefined), style: derived(() => {
164
+ const index = cursor.value ?? 0;
165
+ const x = bandCenter(frame.value, names.value.length, index);
166
+ const left = (x / frame.value.width) * 100;
167
+ // Near an edge the readout grows inward so it never leaves the plot.
168
+ const shift = left < 25 ? "-12px" : left > 75 ? "calc(12px - 100%)" : "-50%";
169
+ return `left: ${left.toFixed(2)}%; transform: translateX(${shift})`;
170
+ }), ref: context.parts.tooltip }, derived(() => readout.value))),
171
+ h("span", { id: hintId, hidden: true }, hint),
172
+ h("p", { role: "status", ref: context.parts.live }, readout),
173
+ h("details", { ref: context.parts.data },
174
+ h("summary", { ref: context.parts.dataToggle }, dataLabel),
175
+ keyed(derived(() => [tableColumns.value]), (signature) => signature, () => (h(Table, { label: label, columns: [
176
+ { id: "category", header: categoryLabel },
177
+ ...admitted.value.map((entry) => ({
178
+ id: entry.id,
179
+ header: entry.label,
180
+ align: "end",
181
+ })),
182
+ ], rows: tableRows }))))));
183
+ }
184
+ Chart.meta = {
185
+ name: "chart",
186
+ parts: [
187
+ "root",
188
+ "caption",
189
+ "title",
190
+ "description",
191
+ "legend",
192
+ "legendItem",
193
+ "swatch",
194
+ "plot",
195
+ "svg",
196
+ "grid",
197
+ "gridLine",
198
+ "tick",
199
+ "cursor",
200
+ "bar",
201
+ "series",
202
+ "line",
203
+ "marker",
204
+ "category",
205
+ "tooltip",
206
+ "live",
207
+ "data",
208
+ "dataToggle",
209
+ ],
210
+ };
@@ -1,8 +1,8 @@
1
1
  import { h } from "meowjsx";
2
2
  import { derived, signal, unwrap } from "meowjsx/signal";
3
- let nextChoiceGroupId = 0;
3
+ import { elementId } from "../shared/element-id.js";
4
4
  /** Visible single choices with native radio keyboard, validation and form semantics. */
5
- export function ChoiceGroup({ options, label, hideLabel = false, id = `choice-group-${++nextChoiceGroupId}`, name = id, form, value, defaultValue = "", onValueChange, disabled = false, required = false, className, ...props }, context) {
5
+ export function ChoiceGroup({ options, label, hideLabel = false, id = elementId("choice-group"), name = id, form, value, defaultValue = "", onValueChange, disabled = false, required = false, className, ...props }, context) {
6
6
  const local = signal(defaultValue);
7
7
  const current = value !== undefined ? value : local;
8
8
  const readValue = () => unwrap(current);
@@ -3,9 +3,9 @@ import { derived, signal, unwrap } from "meowjsx/signal";
3
3
  import { Popover } from "./popover.js";
4
4
  import { Icon } from "../icons/icon.js";
5
5
  import { elementByIdInRoot } from "../shared/dom-root.js";
6
- let nextChoiceId = 0;
6
+ import { elementId } from "../shared/element-id.js";
7
7
  /** Single-choice listbox. Form participation remains native; data fetching belongs to callers. */
8
- export function ChoiceSelect({ options, hidden, value, defaultValue = "", onValueChange, name, id = `choice-${++nextChoiceId}`, disabled = false, required = false, placeholder = "Select an option", searchable = false, searchPlaceholder = "Search options", emptyMessage = "No matching options", className, placement = "bottom", align = "start", matchTriggerWidth = true, ...props }, context) {
8
+ export function ChoiceSelect({ options, hidden, value, defaultValue = "", onValueChange, name, id = elementId("choice"), disabled = false, required = false, placeholder = "Select an option", searchable = false, searchPlaceholder = "Search options", emptyMessage = "No matching options", className, placement = "bottom", align = "start", matchTriggerWidth = true, ...props }, context) {
9
9
  const local = signal(defaultValue);
10
10
  const current = value !== undefined ? value : local;
11
11
  const readValue = () => unwrap(current);
@@ -1,5 +1,7 @@
1
1
  import { type Child, type Props, type Context } from "meowjsx";
2
2
  import { type MaybeSignal } from "meowjsx/signal";
3
+ /** The reader-facing name of a language id: `ts` reads TypeScript; unknown ids stay as given. */
4
+ export declare function codeLanguageName(language: string | undefined): string;
3
5
  export interface CodeBlockProps extends Props {
4
6
  code: MaybeSignal<string>;
5
7
  language?: MaybeSignal<string | undefined>;
@@ -30,6 +32,6 @@ export declare function CodeBlock({ code, language, title, caption, actions, def
30
32
  export declare namespace CodeBlock {
31
33
  var meta: {
32
34
  readonly name: "code-block";
33
- readonly parts: readonly ["root", "header", "title", "caption", "language", "actions", "content", "code", "feedback"];
35
+ readonly parts: readonly ["root", "header", "heading", "title", "caption", "language", "actions", "copyIcon", "copiedIcon", "content", "code", "feedback"];
34
36
  };
35
37
  }