@c9up/nebula 0.2.4 → 0.2.5

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 (47) hide show
  1. package/README.md +2 -2
  2. package/dist/atoms/AspectRatio.d.ts +10 -4
  3. package/dist/atoms/AspectRatio.js +21 -6
  4. package/dist/atoms/NativeSelect.d.ts +10 -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/AlertDialog.js +4 -5
  18. package/dist/organisms/Chart.d.ts +103 -15
  19. package/dist/organisms/Chart.js +518 -99
  20. package/dist/organisms/Dialog.js +7 -7
  21. package/dist/organisms/Sidebar.d.ts +5 -7
  22. package/dist/organisms/Sidebar.js +23 -6
  23. package/dist/organisms/Sonner.js +11 -4
  24. package/dist/organisms/index.d.ts +1 -1
  25. package/dist/organisms/index.js +1 -1
  26. package/dist/primitives/menuParts.js +3 -3
  27. package/dist/primitives/portal.d.ts +15 -0
  28. package/dist/primitives/portal.js +18 -1
  29. package/nebula.css +1 -1
  30. package/package.json +1 -1
  31. package/src/atoms/AspectRatio.ts +21 -6
  32. package/src/atoms/NativeSelect.ts +14 -1
  33. package/src/atoms/Progress.ts +21 -5
  34. package/src/atoms/Switch.ts +7 -1
  35. package/src/cli/diff.ts +123 -2
  36. package/src/console/DiffCommand.ts +12 -15
  37. package/src/molecules/Accordion.ts +1 -2
  38. package/src/molecules/Collapsible.ts +1 -3
  39. package/src/molecules/Resizable.ts +8 -2
  40. package/src/organisms/AlertDialog.ts +3 -5
  41. package/src/organisms/Chart.ts +633 -125
  42. package/src/organisms/Dialog.ts +6 -7
  43. package/src/organisms/Sidebar.ts +28 -6
  44. package/src/organisms/Sonner.ts +11 -4
  45. package/src/organisms/index.ts +6 -0
  46. package/src/primitives/menuParts.ts +3 -3
  47. package/src/primitives/portal.ts +27 -1
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  > shadcn/ui, ported to Aurora, organised as atomic design. Zero runtime dependencies, copy-the-source registry, swappable CSS engine.
4
4
 
5
- Part of **[Ream](https://github.com/C9up/ream)** — a Rust-powered, AdonisJS-compatible Node.js framework. Independent, publishable package.
5
+ Part of **[Ream](https://github.com/C9up/ream)** — a Rust-powered Node.js framework. Independent, publishable package.
6
6
 
7
7
  ## What this is
8
8
 
@@ -125,7 +125,7 @@ physical, because that is what the caller means.
125
125
 
126
126
  ## Choose your CSS engine
127
127
 
128
- nebula declares **no CSS engine dependency at all**. You install the engine you want; `config/nebula.ts` names it; nebula generates the matching stubs and build command. Same arrangement AdonisJS uses for its asset bundler.
128
+ nebula declares **no CSS engine dependency at all**. You install the engine you want; `config/nebula.ts` names it; nebula generates the matching stubs and build command. The engine stays the application's own dependency: nebula ships the stubs for it, never the engine.
129
129
 
130
130
  ### The one thing you must install: `tw-animate-css`
131
131
 
@@ -1,10 +1,16 @@
1
1
  /**
2
2
  * AspectRatio — hold a box at a fixed width-to-height ratio.
3
3
  *
4
- * Radix's version predates the CSS `aspect-ratio` property and reproduces it
5
- * with a padding-top percentage trick. That is no longer needed anywhere
6
- * nebula runs, so this is the property, set inline because the value is
7
- * arbitrary and cannot be a utility class.
4
+ * The ratio is arbitrary, so it cannot be a utility class, and it cannot be a
5
+ * `style` attribute either: a Content-Security-Policy without `'unsafe-inline'`
6
+ * blocks those. A `.style` property passes the policy, but the server does not
7
+ * write properties, and the box would collapse until hydration.
8
+ *
9
+ * So the box takes its height from an empty SVG whose `viewBox` carries the
10
+ * ratio: an `<svg>` at full width and automatic height is as tall as its
11
+ * viewBox says, and a `viewBox` is an attribute the policy does not touch. The
12
+ * content sits over it, absolutely positioned — Radix's own structure, with the
13
+ * SVG in place of its padding trick.
8
14
  */
9
15
  import { type Slot } from "../lib/children.js";
10
16
  import { type Reactive } from "../lib/props.js";
@@ -1,19 +1,34 @@
1
1
  /**
2
2
  * AspectRatio — hold a box at a fixed width-to-height ratio.
3
3
  *
4
- * Radix's version predates the CSS `aspect-ratio` property and reproduces it
5
- * with a padding-top percentage trick. That is no longer needed anywhere
6
- * nebula runs, so this is the property, set inline because the value is
7
- * arbitrary and cannot be a utility class.
4
+ * The ratio is arbitrary, so it cannot be a utility class, and it cannot be a
5
+ * `style` attribute either: a Content-Security-Policy without `'unsafe-inline'`
6
+ * blocks those. A `.style` property passes the policy, but the server does not
7
+ * write properties, and the box would collapse until hydration.
8
+ *
9
+ * So the box takes its height from an empty SVG whose `viewBox` carries the
10
+ * ratio: an `<svg>` at full width and automatic height is as tall as its
11
+ * viewBox says, and a `viewBox` is an attribute the policy does not touch. The
12
+ * content sits over it, absolutely positioned — Radix's own structure, with the
13
+ * SVG in place of its padding trick.
8
14
  */
9
15
  import { component, html } from "@c9up/aurora";
10
16
  import { slot } from "../lib/children.js";
11
17
  import { cn } from "../lib/cn.js";
12
18
  import { read, readOr } from "../lib/props.js";
13
19
  export const AspectRatio = component((props) => {
20
+ /** A ratio that is not a positive finite number would make no box at all. */
21
+ const ratio = () => {
22
+ const given = readOr(props.ratio, 1);
23
+ return Number.isFinite(given) && given > 0 ? given : 1;
24
+ };
14
25
  return html `<div
15
26
  data-slot="aspect-ratio"
16
- style="${() => `aspect-ratio: ${readOr(props.ratio, 1)}`}"
17
27
  class="${() => cn("relative w-full", read(props.class))}"
18
- >${slot(props.children)}</div>`;
28
+ ><svg
29
+ aria-hidden="true"
30
+ focusable="false"
31
+ viewBox="${() => `0 0 ${ratio()} 1`}"
32
+ class="block h-auto w-full"
33
+ ></svg><div class="absolute inset-0">${slot(props.children)}</div></div>`;
19
34
  });
@@ -37,7 +37,17 @@ export interface NativeSelectProps {
37
37
  required?: Reactive<boolean>;
38
38
  invalid?: Reactive<boolean>;
39
39
  describedBy?: Reactive<string | undefined>;
40
+ /** Styles the `<select>` itself. To change the control's width, use `wrapperClass`. */
40
41
  class?: Reactive<string>;
42
+ /**
43
+ * Sizes the control: the wrapper the chevron is positioned against.
44
+ *
45
+ * A width through `class` narrows the `<select>` and leaves the chevron at
46
+ * the end of a full-width wrapper, with empty space between the control and
47
+ * its own indicator. Merged over the wrapper's `w-full`, so `w-40` here
48
+ * replaces it rather than competing with it.
49
+ */
50
+ wrapperClass?: Reactive<string>;
41
51
  onValueChange?: (value: string, event: Event) => void;
42
52
  }
43
53
  export declare const NativeSelect: (props?: NativeSelectProps | undefined) => import("@c9up/aurora").TemplateResult;
@@ -65,7 +65,10 @@ export const NativeSelect = component((props) => {
65
65
  >
66
66
  ${option.label}
67
67
  </option>`;
68
- return html `<div data-slot="native-select" class="relative inline-flex w-full items-center">
68
+ return html `<div
69
+ data-slot="native-select"
70
+ class="${() => cn("relative inline-flex w-full items-center", read(props.wrapperClass))}"
71
+ >
69
72
  <select
70
73
  id="${props.id}"
71
74
  name="${props.name}"
@@ -1,11 +1,19 @@
1
1
  /**
2
2
  * Progress — a determinate progress bar.
3
3
  *
4
- * The fill is a full-width child translated left by the remaining percentage,
4
+ * The fill is a full-width shape translated left by the remaining percentage,
5
5
  * rather than a width animation. Transforms are composited off the main
6
6
  * thread; animating `width` relayouts the bar on every frame, which is visible
7
7
  * on a long upload.
8
8
  *
9
+ * The shape is an SVG `<rect>` moved by its `transform` ATTRIBUTE, not a `<div>`
10
+ * moved by a `style` attribute. A Content-Security-Policy without
11
+ * `'unsafe-inline'` blocks every `style` attribute; an SVG presentation
12
+ * attribute is not a style attribute and passes. A `.style` property would pass
13
+ * too, but the server does not write properties, so the bar would read full
14
+ * until hydration — the attribute is in the server's markup, right from the
15
+ * first paint.
16
+ *
9
17
  * A `value` of `null` means indeterminate, and drops `aria-valuenow` — the
10
18
  * ARIA spec is explicit that an absent value is how "unknown progress" is
11
19
  * expressed, and reporting `0` instead tells the user it has not started.
@@ -1,11 +1,19 @@
1
1
  /**
2
2
  * Progress — a determinate progress bar.
3
3
  *
4
- * The fill is a full-width child translated left by the remaining percentage,
4
+ * The fill is a full-width shape translated left by the remaining percentage,
5
5
  * rather than a width animation. Transforms are composited off the main
6
6
  * thread; animating `width` relayouts the bar on every frame, which is visible
7
7
  * on a long upload.
8
8
  *
9
+ * The shape is an SVG `<rect>` moved by its `transform` ATTRIBUTE, not a `<div>`
10
+ * moved by a `style` attribute. A Content-Security-Policy without
11
+ * `'unsafe-inline'` blocks every `style` attribute; an SVG presentation
12
+ * attribute is not a style attribute and passes. A `.style` property would pass
13
+ * too, but the server does not write properties, so the bar would read full
14
+ * until hydration — the attribute is in the server's markup, right from the
15
+ * first paint.
16
+ *
9
17
  * A `value` of `null` means indeterminate, and drops `aria-valuenow` — the
10
18
  * ARIA spec is explicit that an absent value is how "unknown progress" is
11
19
  * expressed, and reporting `0` instead tells the user it has not started.
@@ -39,10 +47,18 @@ export const Progress = component((props) => {
39
47
  aria-label="${() => read(props.label)}"
40
48
  class="${() => cn("bg-primary/20 relative h-2 w-full overflow-hidden rounded-full", read(props.class))}"
41
49
  >
42
- <div
50
+ <svg
43
51
  data-slot="progress-indicator"
44
- class="bg-primary h-full w-full flex-1 transition-transform"
45
- style="${() => `transform: translateX(-${100 - percent()}%)`}"
46
- ></div>
52
+ aria-hidden="true"
53
+ focusable="false"
54
+ viewBox="0 0 100 1"
55
+ preserveAspectRatio="none"
56
+ class="fill-primary block h-full w-full"
57
+ ><rect
58
+ width="100"
59
+ height="1"
60
+ transform="${() => `translate(${percent() - 100} 0)`}"
61
+ class="transition-transform"
62
+ /></svg>
47
63
  </div>`;
48
64
  });
@@ -11,7 +11,13 @@
11
11
  * retune the size without leaving the class string.
12
12
  */
13
13
  import { type Reactive } from "../lib/props.js";
14
- export declare const switchTrackClasses = "peer absolute inset-0 size-full appearance-none rounded-full border border-transparent bg-input shadow-xs outline-none transition-colors dark:bg-input/80 checked:bg-primary focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50";
14
+ /**
15
+ * The off fill names the unchecked state, as upstream's `data-[state=unchecked]:`
16
+ * does. Left bare, `dark:bg-input/80` weighed as much as `checked:bg-primary`
17
+ * and came later in the stylesheet, so a switch that was on looked off in the
18
+ * dark theme.
19
+ */
20
+ export declare const switchTrackClasses = "peer absolute inset-0 size-full appearance-none rounded-full border border-transparent shadow-xs outline-none transition-colors checked:bg-primary not-checked:bg-input dark:not-checked:bg-input/80 focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50";
15
21
  export interface SwitchProps {
16
22
  id?: string;
17
23
  name?: string;
@@ -13,7 +13,13 @@
13
13
  import { component, html } from "@c9up/aurora";
14
14
  import { cn } from "../lib/cn.js";
15
15
  import { accessor, read } from "../lib/props.js";
16
- export const switchTrackClasses = "peer absolute inset-0 size-full appearance-none rounded-full border border-transparent bg-input shadow-xs outline-none transition-colors dark:bg-input/80 checked:bg-primary focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50";
16
+ /**
17
+ * The off fill names the unchecked state, as upstream's `data-[state=unchecked]:`
18
+ * does. Left bare, `dark:bg-input/80` weighed as much as `checked:bg-primary`
19
+ * and came later in the stylesheet, so a switch that was on looked off in the
20
+ * dark theme.
21
+ */
22
+ export const switchTrackClasses = "peer absolute inset-0 size-full appearance-none rounded-full border border-transparent shadow-xs outline-none transition-colors checked:bg-primary not-checked:bg-input dark:not-checked:bg-input/80 focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50";
17
23
  function inputChecked(event) {
18
24
  const target = event.target;
19
25
  return target instanceof HTMLInputElement ? target.checked : false;
@@ -13,6 +13,7 @@
13
13
  * you made from one you have not seen yet.
14
14
  */
15
15
  import { type Language, type NebulaPaths } from "../config.js";
16
+ import { type Registry, type RegistryItem } from "./registry.js";
16
17
  export type DiffState =
17
18
  /** Copy, record and package all agree. */
18
19
  "same"
@@ -36,9 +37,31 @@ export interface DiffOptions {
36
37
  /** The configured language: used when the tree says nothing. */
37
38
  defaultLanguage?: Language;
38
39
  }
40
+ /**
41
+ * How to bring the outdated files up to date with `nebula:add --force`.
42
+ *
43
+ * `nebula:add` takes registry names, never file paths: a shared file such as
44
+ * `lib/icons.ts` or `primitives/menu.ts` has no name of its own and travels
45
+ * with the components that use it. So the outdated files are mapped back to
46
+ * the installed components whose copy would bring them along.
47
+ */
48
+ export interface UpdatePlan {
49
+ /**
50
+ * Registry names to pass to `nebula:add --force`, sorted. Each one re-copies
51
+ * only files that are outdated or untouched — never one you edited, and
52
+ * never one whose history is unknown.
53
+ */
54
+ components: string[];
55
+ /**
56
+ * Outdated files none of those names can reach without overwriting a file
57
+ * you changed, or that no installed component carries any more.
58
+ */
59
+ uncovered: string[];
60
+ }
39
61
  export interface DiffResult {
40
62
  entries: DiffEntry[];
41
63
  language: Language;
64
+ update: UpdatePlan;
42
65
  }
43
66
  /**
44
67
  * Compare every copied component against the installed package.
@@ -47,3 +70,26 @@ export interface DiffResult {
47
70
  * lists everything nebula ships, and a component nobody copied is not news.
48
71
  */
49
72
  export declare function diff(options: DiffOptions): DiffResult;
73
+ export interface PlanOptions {
74
+ /**
75
+ * Whether the project has this component. Its own file — the registry
76
+ * names an item after it — being in the tree is what says so.
77
+ */
78
+ installed: (item: RegistryItem) => boolean;
79
+ /** A registry path (`.ts`) as it is spelled in the copied tree. */
80
+ toCopy: (file: string) => string;
81
+ }
82
+ /**
83
+ * Pick the registry names that update the outdated files, losing nothing.
84
+ *
85
+ * A component qualifies when it is installed and everything `nebula:add
86
+ * --force` would rewrite for it — its files and those of every component it
87
+ * pulls in — is outdated or untouched. One edited, conflicting or unknown file
88
+ * in that set rules it out: the suggestion is printed as safe to run as is.
89
+ *
90
+ * Among those, a greedy cover keeps the command short: the component reaching
91
+ * the most outdated files still left goes first, ties broken by name. A shared
92
+ * file then rides along with a component that needed re-copying anyway, rather
93
+ * than every component that happens to import it being listed.
94
+ */
95
+ export declare function planUpdate(registry: Registry, entries: readonly DiffEntry[], options: PlanOptions): UpdatePlan;
package/dist/cli/diff.js CHANGED
@@ -17,7 +17,7 @@ import { join } from "node:path";
17
17
  import { defaultPaths } from "../config.js";
18
18
  import { detectLanguage } from "./add.js";
19
19
  import { hashOf, readManifest } from "./manifest.js";
20
- import { loadRegistry, packageRoot } from "./registry.js";
20
+ import { loadRegistry, packageRoot, resolveItems, } from "./registry.js";
21
21
  /**
22
22
  * Compare every copied component against the installed package.
23
23
  *
@@ -57,7 +57,78 @@ export function diff(options) {
57
57
  }
58
58
  }
59
59
  entries.sort((a, b) => a.file.localeCompare(b.file));
60
- return { entries, language };
60
+ const toCopy = (file) => language === "ts" ? file : file.replace(/\.ts$/, ".js");
61
+ const update = planUpdate(registry, entries, {
62
+ installed: (item) => existsSync(join(target, toCopy(`${item.layer}/${item.title}.ts`))),
63
+ toCopy,
64
+ });
65
+ return { entries, language, update };
66
+ }
67
+ /**
68
+ * Pick the registry names that update the outdated files, losing nothing.
69
+ *
70
+ * A component qualifies when it is installed and everything `nebula:add
71
+ * --force` would rewrite for it — its files and those of every component it
72
+ * pulls in — is outdated or untouched. One edited, conflicting or unknown file
73
+ * in that set rules it out: the suggestion is printed as safe to run as is.
74
+ *
75
+ * Among those, a greedy cover keeps the command short: the component reaching
76
+ * the most outdated files still left goes first, ties broken by name. A shared
77
+ * file then rides along with a component that needed re-copying anyway, rather
78
+ * than every component that happens to import it being listed.
79
+ */
80
+ export function planUpdate(registry, entries, options) {
81
+ const states = new Map(entries.map((entry) => [entry.file, entry.state]));
82
+ const outdated = new Set(entries
83
+ .filter((entry) => entry.state === "outdated")
84
+ .map((entry) => entry.file));
85
+ const candidates = [];
86
+ for (const item of registry.items) {
87
+ if (!options.installed(item))
88
+ continue;
89
+ const rewritten = new Set(resolveItems(registry, [item.name]).flatMap((entry) => entry.files.map(options.toCopy)));
90
+ const lossy = [...rewritten].some((file) => {
91
+ const state = states.get(file);
92
+ return state !== undefined && state !== "outdated";
93
+ });
94
+ if (lossy)
95
+ continue;
96
+ const reaches = new Set([...rewritten].filter((file) => outdated.has(file)));
97
+ if (reaches.size > 0)
98
+ candidates.push({ name: item.name, reaches });
99
+ }
100
+ const left = new Set(outdated);
101
+ const components = [];
102
+ while (left.size > 0) {
103
+ let best;
104
+ for (const candidate of candidates) {
105
+ let count = 0;
106
+ for (const file of candidate.reaches)
107
+ if (left.has(file))
108
+ count += 1;
109
+ if (count === 0)
110
+ continue;
111
+ if (best === undefined ||
112
+ count > best.count ||
113
+ (count === best.count && candidate.name < best.name)) {
114
+ best = { name: candidate.name, count };
115
+ }
116
+ }
117
+ if (best === undefined)
118
+ break;
119
+ const chosen = best.name;
120
+ components.push(chosen);
121
+ for (const candidate of candidates) {
122
+ if (candidate.name !== chosen)
123
+ continue;
124
+ for (const file of candidate.reaches)
125
+ left.delete(file);
126
+ }
127
+ }
128
+ return {
129
+ components: components.sort(),
130
+ uncovered: [...left].sort(),
131
+ };
61
132
  }
62
133
  function compare(hashes) {
63
134
  const { copy, source, recorded } = hashes;
@@ -62,22 +62,17 @@ export default class NebulaDiffCommand {
62
62
  for (const entry of result.entries) {
63
63
  out.push(` ${entry.state.padEnd(9)} ${entry.file.padEnd(width)} ${EXPLAIN[entry.state]}`);
64
64
  }
65
- const outdated = result.entries.filter((entry) => entry.state === "outdated");
66
- if (outdated.length > 0) {
67
- out.push("", ` ${outdated.length} can be updated with no loss:`, ` ream nebula:add --force ${outdated.map(componentOf).join(" ")}`);
65
+ const { components, uncovered } = result.update;
66
+ if (components.length > 0) {
67
+ out.push("", " Outdated files that can be updated with no loss — the components that carry them:", ` ream nebula:add --force ${components.join(" ")}`);
68
+ }
69
+ if (uncovered.length > 0) {
70
+ out.push("", " Outdated, but no installed component can re-copy them without overwriting", " a file you changed (or none carries them any more). Compare by hand:", ...uncovered.map((file) => ` ${file}`));
68
71
  }
69
72
  out.push("");
70
73
  process.stdout.write(out.join("\n"));
71
74
  }
72
75
  }
73
- /** `molecules/InputGroup.js` → `input-group`, as the registry names it. */
74
- function componentOf(entry) {
75
- const base = entry.file.split("/").pop() ?? entry.file;
76
- return base
77
- .replace(/\.(ts|js)$/, "")
78
- .replace(/([a-z0-9])([A-Z])/g, "$1-$2")
79
- .toLowerCase();
80
- }
81
76
  // Fails the build if the class drifts from what the kernel dispatches against.
82
77
  const _contract = NebulaDiffCommand;
83
78
  void _contract;
@@ -109,8 +109,7 @@ export const AccordionContent = component((props) => {
109
109
  data-state="${() => (item.open() ? "open" : "closed")}"
110
110
  aria-labelledby="${item.triggerId}"
111
111
  ?inert="${() => !item.open()}"
112
- class="grid text-sm transition-[grid-template-rows] duration-200 ease-out motion-reduce:transition-none"
113
- style="${() => `grid-template-rows: ${item.open() ? "1fr" : "0fr"}`}"
112
+ class="grid grid-rows-[0fr] text-sm transition-[grid-template-rows] duration-200 ease-out motion-reduce:transition-none data-[state=open]:grid-rows-[1fr]"
114
113
  ><div class="overflow-hidden"><div
115
114
  class="${() => cn("pt-0 pb-4", read(props.class))}"
116
115
  >${slot(props.children)}</div></div></div>`;
@@ -73,7 +73,6 @@ export const CollapsibleContent = component((props) => {
73
73
  data-state="${() => (collapsible.open() ? "open" : "closed")}"
74
74
  aria-labelledby="${collapsible.triggerId}"
75
75
  ?inert="${() => !collapsible.open()}"
76
- class="grid transition-[grid-template-rows] duration-200 ease-out motion-reduce:transition-none"
77
- style="${() => `grid-template-rows: ${collapsible.open() ? "1fr" : "0fr"}`}"
76
+ class="grid grid-rows-[0fr] transition-[grid-template-rows] duration-200 ease-out motion-reduce:transition-none data-[state=open]:grid-rows-[1fr]"
78
77
  ><div class="${() => cn("overflow-hidden", read(props.class))}">${slot(props.children)}</div></div>`;
79
78
  });
@@ -45,6 +45,12 @@ export interface ResizablePanelProps {
45
45
  * share and the second takes the rest. The parts are upstream's so a layout
46
46
  * written against them reads the same; a third panel would simply have no
47
47
  * share of its own.
48
+ *
49
+ * The share is written through the CSSOM (`.style`), never as a `style`
50
+ * attribute: a Content-Security-Policy without `'unsafe-inline'` blocks the
51
+ * attribute, and the CSSOM is not subject to it. A property is not written by
52
+ * the server, so until hydration both panes carry `flex-1` and split the room
53
+ * evenly — the right layout for the default share, and never a collapsed one.
48
54
  */
49
55
  export declare const ResizablePanel: (props?: ResizablePanelProps | undefined) => import("@c9up/aurora").TemplateResult;
50
56
  export interface ResizableHandleProps {
@@ -67,14 +67,20 @@ export const ResizablePanelGroup = component((props) => {
67
67
  * share and the second takes the rest. The parts are upstream's so a layout
68
68
  * written against them reads the same; a third panel would simply have no
69
69
  * share of its own.
70
+ *
71
+ * The share is written through the CSSOM (`.style`), never as a `style`
72
+ * attribute: a Content-Security-Policy without `'unsafe-inline'` blocks the
73
+ * attribute, and the CSSOM is not subject to it. A property is not written by
74
+ * the server, so until hydration both panes carry `flex-1` and split the room
75
+ * evenly — the right layout for the default share, and never a collapsed one.
70
76
  */
71
77
  export const ResizablePanel = component((props) => {
72
78
  const group = inject(ResizableContext);
73
79
  const first = group.claimPanel() === 1;
74
80
  return html `<div
75
81
  data-slot="resizable-panel"
76
- class="${() => cn("overflow-hidden", first ? "" : "flex-1", read(props.class))}"
77
- style="${() => (first ? `flex: 0 0 ${group.size()}%` : "")}"
82
+ class="${() => cn("flex-1 overflow-hidden", read(props.class))}"
83
+ .style="${() => (first ? `flex: 0 0 ${group.size()}%` : "")}"
78
84
  >${slot(props.children)}</div>`;
79
85
  });
80
86
  /**
@@ -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;