@c9up/nebula 0.2.4 → 0.2.6

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 (53) hide show
  1. package/README.md +4 -4
  2. package/dist/atoms/AspectRatio.d.ts +10 -4
  3. package/dist/atoms/AspectRatio.js +21 -6
  4. package/dist/atoms/NativeSelect.d.ts +16 -0
  5. package/dist/atoms/NativeSelect.js +4 -1
  6. package/dist/atoms/Progress.d.ts +9 -1
  7. package/dist/atoms/Progress.js +21 -5
  8. package/dist/atoms/Switch.d.ts +7 -1
  9. package/dist/atoms/Switch.js +7 -1
  10. package/dist/cli/diff.d.ts +46 -0
  11. package/dist/cli/diff.js +73 -2
  12. package/dist/console/DiffCommand.js +6 -11
  13. package/dist/molecules/Accordion.js +1 -2
  14. package/dist/molecules/Collapsible.js +1 -2
  15. package/dist/molecules/Resizable.d.ts +6 -0
  16. package/dist/molecules/Resizable.js +8 -2
  17. package/dist/organisms/Agenda.d.ts +200 -0
  18. package/dist/organisms/Agenda.js +762 -0
  19. package/dist/organisms/AlertDialog.js +4 -5
  20. package/dist/organisms/Chart.d.ts +103 -15
  21. package/dist/organisms/Chart.js +518 -99
  22. package/dist/organisms/Dialog.js +7 -7
  23. package/dist/organisms/Sidebar.d.ts +5 -7
  24. package/dist/organisms/Sidebar.js +23 -6
  25. package/dist/organisms/Sonner.js +11 -4
  26. package/dist/organisms/index.d.ts +2 -1
  27. package/dist/organisms/index.js +2 -1
  28. package/dist/primitives/floatingSurface.js +60 -36
  29. package/dist/primitives/menuParts.js +3 -3
  30. package/dist/primitives/portal.d.ts +15 -0
  31. package/dist/primitives/portal.js +18 -1
  32. package/nebula.css +1 -1
  33. package/package.json +1 -1
  34. package/registry.json +13 -0
  35. package/src/atoms/AspectRatio.ts +21 -6
  36. package/src/atoms/NativeSelect.ts +20 -1
  37. package/src/atoms/Progress.ts +21 -5
  38. package/src/atoms/Switch.ts +7 -1
  39. package/src/cli/diff.ts +123 -2
  40. package/src/console/DiffCommand.ts +12 -15
  41. package/src/molecules/Accordion.ts +1 -2
  42. package/src/molecules/Collapsible.ts +1 -3
  43. package/src/molecules/Resizable.ts +8 -2
  44. package/src/organisms/Agenda.ts +1061 -0
  45. package/src/organisms/AlertDialog.ts +3 -5
  46. package/src/organisms/Chart.ts +633 -125
  47. package/src/organisms/Dialog.ts +6 -7
  48. package/src/organisms/Sidebar.ts +28 -6
  49. package/src/organisms/Sonner.ts +11 -4
  50. package/src/organisms/index.ts +26 -0
  51. package/src/primitives/floatingSurface.ts +74 -40
  52. package/src/primitives/menuParts.ts +3 -3
  53. package/src/primitives/portal.ts +27 -1
@@ -27,7 +27,7 @@
27
27
  * Escape still closes, and it cancels rather than confirms — it is the
28
28
  * keyboard spelling of the same safe way out.
29
29
  */
30
- import { component, createContext, html, inject, onUnmount, provide, } from "@c9up/aurora";
30
+ import { component, createContext, html, inject, provide, } from "@c9up/aurora";
31
31
  import { buttonVariants } from "../atoms/Button.js";
32
32
  import { slot } from "../lib/children.js";
33
33
  import { cn } from "../lib/cn.js";
@@ -36,7 +36,7 @@ import { fadeInOut, zoomInOut } from "../lib/motion.js";
36
36
  import { read } from "../lib/props.js";
37
37
  import { controllable } from "../primitives/controllable.js";
38
38
  import { modalSurface } from "../primitives/modalSurface.js";
39
- import { portal } from "../primitives/portal.js";
39
+ import { portalOnMount } from "../primitives/portal.js";
40
40
  import { dialogBackdropClasses } from "./Dialog.js";
41
41
  const panelClasses = "group/alert-dialog-content bg-background fixed top-1/2 left-1/2 z-50 grid w-full max-w-[calc(100%-2rem)] -translate-x-1/2 -translate-y-1/2 gap-4 rounded-lg border p-6 shadow-lg duration-200 outline-none data-[size=sm]:max-w-xs sm:max-w-lg";
42
42
  const AlertDialogContext = createContext("AlertDialog");
@@ -141,11 +141,10 @@ export const AlertDialogOverlay = component((props) => html `<div
141
141
  * than standing in as a passthrough.
142
142
  */
143
143
  export const AlertDialogPortal = component((props) => {
144
- const mounted = portal(html `${slot(props.children)}`, {
144
+ portalOnMount(html `${slot(props.children)}`, {
145
145
  container: props.container,
146
+ slot: "alert-dialog-portal",
146
147
  });
147
- mounted.host.setAttribute("data-slot", "alert-dialog-portal");
148
- onUnmount(() => mounted.close());
149
148
  return html ``;
150
149
  });
151
150
  export const AlertDialogHeader = component((props) => html `<div
@@ -8,17 +8,32 @@
8
8
  * the shadcn chart examples are and what dashboards overwhelmingly need.
9
9
  *
10
10
  * Anything beyond that — stacked bars with negative values, dual axes, brushes,
11
- * candlesticks — is a charting library's job, and an app needing one should
12
- * install one rather than have this component grow into a bad copy.
11
+ * candlesticks, horizontal bars, heatmaps, funnels — is a charting library's
12
+ * job, and an app needing one should install one rather than have this
13
+ * component grow into a bad copy.
13
14
  *
14
15
  * The colours come from `--chart-1` … `--chart-5`, so a chart re-themes with
15
16
  * the rest of the design system instead of carrying its own palette.
16
17
  *
17
- * An SVG chart is invisible to a screen reader whatever ARIA is put on it, so
18
- * the same data is emitted as a real `<table>`, visually hidden. That is the
19
- * only approach that actually works: the reader gets rows and values it can
20
- * navigate, not a described picture.
18
+ * **Geometry.** Text is never stretched. The drawing is two SVGs in pixel
19
+ * space — the value axis in a fixed gutter, the plot at full width — with
20
+ * every horizontal position written as a percentage of the plot's width and
21
+ * every vertical one in pixels. Only the curves and bars live in a nested SVG
22
+ * stretched to the plot (`preserveAspectRatio="none"`), with strokes that do
23
+ * not scale. Everything is an attribute: no `style` attribute, which a strict
24
+ * Content-Security-Policy blocks, and the server's markup is the chart.
25
+ *
26
+ * **Missing values.** A value that is absent, `null` or not a finite number is
27
+ * a gap: the line breaks, the area stops, no bar is drawn, and the table says
28
+ * so. Drawing it as `0` would invent a number.
29
+ *
30
+ * **Reading it.** An SVG chart is invisible to a screen reader whatever ARIA is
31
+ * put on it, so the same data is emitted as a real `<table>`, visually hidden.
32
+ * The plot also takes focus: the arrow keys walk the categories, and what the
33
+ * pointer or the keyboard points at is shown in a tooltip and announced in a
34
+ * live region.
21
35
  */
36
+ import { type TemplateResult } from "@c9up/aurora";
22
37
  import { type Reactive } from "../lib/props.js";
23
38
  export interface ChartSeries {
24
39
  key: string;
@@ -26,30 +41,103 @@ export interface ChartSeries {
26
41
  /** Any CSS colour. Defaults to `--chart-1`…`--chart-5` by position. */
27
42
  color?: string;
28
43
  }
29
- /** One row: a category plus one numeric value per series key. */
30
- export type ChartDatum = Record<string, string | number>;
44
+ /** A category label as a datum may hold it. */
45
+ export type ChartCategory = string | number | Date;
46
+ /**
47
+ * One row: a category plus one numeric value per series key. A value that is
48
+ * missing, `null` or not a finite number is a gap.
49
+ */
50
+ export type ChartDatum = Record<string, string | number | Date | null | undefined>;
51
+ /** One end of the value axis: a number, or `"auto"` to fit the data. */
52
+ export type ChartBound = number | "auto";
31
53
  export interface ChartProps {
32
54
  data: readonly ChartDatum[];
33
55
  series: readonly ChartSeries[];
34
56
  /** Key in each datum holding the category label. */
35
57
  categoryKey: string;
36
58
  type?: "line" | "area" | "bar";
59
+ /** The chart's height in pixels, category labels included. Default `240`. */
37
60
  height?: number;
38
61
  /** Announced as the chart's name, and used as the data table's caption. */
39
62
  label: string;
40
- /** Draw horizontal gridlines. Default `true`. */
63
+ /** Draw a horizontal gridline at each value tick. Default `true`. */
41
64
  grid?: boolean;
65
+ /**
66
+ * The value axis' range, `[min, max]`. Each end is a number, or `"auto"` to
67
+ * fit the data and round outwards to a tick. Default `["auto", "auto"]`.
68
+ */
69
+ domain?: readonly [ChartBound, ChartBound];
70
+ /**
71
+ * Stretch an `"auto"` end to include zero. Default `true`. Always on for
72
+ * bars: a bar is measured from zero, and one that starts elsewhere
73
+ * exaggerates every difference.
74
+ */
75
+ zero?: boolean;
76
+ /** Draw the smallest value at the top — a ranking, where 1 is best. */
77
+ reversed?: boolean;
78
+ /** About how many ticks the value axis gets. Default `5`. */
79
+ tickCount?: number;
80
+ /** Formats a value on the axis, in the tooltip and in the table. */
81
+ formatValue?: (value: number) => string;
82
+ /** Formats a category on the axis, in the tooltip and in the table. */
83
+ formatCategory?: (category: ChartCategory) => string;
84
+ /** BCP 47 locale for the default formatters. Default: the runtime's own. */
85
+ locale?: string;
86
+ /** What a screen reader calls the plot. Default `"chart"`. */
87
+ roleDescription?: string;
88
+ /**
89
+ * How a screen reader is told to read the plot. Default `"Arrow keys read
90
+ * each category."`.
91
+ */
92
+ keyboardHint?: string;
42
93
  class?: Reactive<string>;
43
94
  }
44
95
  /**
45
- * The value range the Y axis covers.
96
+ * The range the data covers.
97
+ *
98
+ * Gaps are skipped. With `zero` (the default), the range always includes zero.
99
+ * A flat range is widened — to `0`–`1` when it sits on zero, by a tenth of its
100
+ * value either side otherwise — so there is always something to scale
101
+ * against, and no data at all reads as `0`–`1`.
102
+ */
103
+ export declare function valueRange(data: readonly ChartDatum[], series: readonly ChartSeries[], options?: {
104
+ zero?: boolean;
105
+ }): {
106
+ min: number;
107
+ max: number;
108
+ };
109
+ /**
110
+ * Round ticks covering `min`–`max`, about `count` of them.
46
111
  *
47
- * Anchored at zero whenever the data is non-negative. A bar chart whose axis
48
- * starts at the minimum value exaggerates every difference — the classic
49
- * misleading chart — and it is not a choice worth exposing as an option.
112
+ * The range is widened outwards to the nearest tick, so the first and last
113
+ * ticks are the axis' ends.
50
114
  */
51
- export declare function valueRange(data: readonly ChartDatum[], series: readonly ChartSeries[]): {
115
+ export declare function niceTicks(min: number, max: number, count?: number): {
52
116
  min: number;
53
117
  max: number;
118
+ step: number;
119
+ ticks: number[];
54
120
  };
55
- export declare const Chart: (props?: ChartProps | undefined) => import("@c9up/aurora").TemplateResult;
121
+ export interface ValueAxisOptions {
122
+ domain?: readonly [ChartBound, ChartBound];
123
+ zero?: boolean;
124
+ tickCount?: number;
125
+ }
126
+ /**
127
+ * The value axis a chart draws: its ends and its ticks.
128
+ *
129
+ * An `"auto"` end fits the data and is rounded outwards to a tick. A number is
130
+ * kept exactly and is a tick itself, with any round tick too close to it
131
+ * dropped so the two labels do not collide.
132
+ */
133
+ export declare function valueAxis(data: readonly ChartDatum[], series: readonly ChartSeries[], options?: ValueAxisOptions): {
134
+ min: number;
135
+ max: number;
136
+ ticks: number[];
137
+ };
138
+ /**
139
+ * Which category labels fit: every `step`-th one, the smallest step at which
140
+ * the widest label no longer reaches its neighbour.
141
+ */
142
+ export declare function visibleCategories(count: number, widestLabel: number, plotWidth: number): number[];
143
+ export declare const Chart: (props?: ChartProps | undefined) => TemplateResult;