@c9up/nebula 0.2.3 → 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 (99) hide show
  1. package/README.md +9 -8
  2. package/dist/atoms/AspectRatio.d.ts +10 -4
  3. package/dist/atoms/AspectRatio.js +21 -6
  4. package/dist/atoms/Avatar.d.ts +14 -0
  5. package/dist/atoms/Avatar.js +46 -8
  6. package/dist/atoms/NativeSelect.d.ts +10 -0
  7. package/dist/atoms/NativeSelect.js +4 -1
  8. package/dist/atoms/Progress.d.ts +9 -1
  9. package/dist/atoms/Progress.js +21 -5
  10. package/dist/atoms/Switch.d.ts +7 -1
  11. package/dist/atoms/Switch.js +7 -1
  12. package/dist/cli/add.d.ts +2 -0
  13. package/dist/cli/add.js +4 -1
  14. package/dist/cli/diff.d.ts +48 -0
  15. package/dist/cli/diff.js +77 -3
  16. package/dist/cli/projectConfig.d.ts +16 -0
  17. package/dist/cli/projectConfig.js +61 -0
  18. package/dist/console/AddCommand.js +6 -1
  19. package/dist/console/DiffCommand.js +12 -12
  20. package/dist/lib/icons.d.ts +8 -0
  21. package/dist/lib/icons.js +8 -0
  22. package/dist/lib/image.js +12 -1
  23. package/dist/molecules/Accordion.js +1 -2
  24. package/dist/molecules/Collapsible.js +1 -2
  25. package/dist/molecules/InputOTP.d.ts +12 -0
  26. package/dist/molecules/InputOTP.js +68 -27
  27. package/dist/molecules/Resizable.d.ts +6 -0
  28. package/dist/molecules/Resizable.js +8 -2
  29. package/dist/molecules/index.d.ts +1 -1
  30. package/dist/molecules/index.js +1 -1
  31. package/dist/organisms/AlertDialog.js +4 -5
  32. package/dist/organisms/Chart.d.ts +103 -15
  33. package/dist/organisms/Chart.js +518 -99
  34. package/dist/organisms/Combobox.d.ts +13 -0
  35. package/dist/organisms/Combobox.js +5 -2
  36. package/dist/organisms/Command.js +56 -8
  37. package/dist/organisms/Dialog.js +7 -7
  38. package/dist/organisms/Form.d.ts +15 -0
  39. package/dist/organisms/Form.js +10 -0
  40. package/dist/organisms/Select.d.ts +6 -4
  41. package/dist/organisms/Select.js +1 -0
  42. package/dist/organisms/Sidebar.d.ts +9 -9
  43. package/dist/organisms/Sidebar.js +77 -32
  44. package/dist/organisms/Sonner.d.ts +243 -0
  45. package/dist/organisms/Sonner.js +916 -0
  46. package/dist/organisms/Toaster.d.ts +9 -0
  47. package/dist/organisms/Toaster.js +28 -5
  48. package/dist/organisms/Tooltip.d.ts +4 -0
  49. package/dist/organisms/index.d.ts +7 -1
  50. package/dist/organisms/index.js +7 -1
  51. package/dist/primitives/dismissable.d.ts +11 -4
  52. package/dist/primitives/dismissable.js +8 -6
  53. package/dist/primitives/floating.d.ts +5 -1
  54. package/dist/primitives/floating.js +8 -1
  55. package/dist/primitives/menu.js +2 -1
  56. package/dist/primitives/menuParts.js +3 -3
  57. package/dist/primitives/modalSurface.js +70 -36
  58. package/dist/primitives/portal.d.ts +15 -0
  59. package/dist/primitives/portal.js +18 -1
  60. package/dist/primitives/presence.js +8 -5
  61. package/nebula.css +2 -2
  62. package/package.json +1 -1
  63. package/registry.json +13 -0
  64. package/src/atoms/AspectRatio.ts +21 -6
  65. package/src/atoms/Avatar.ts +54 -7
  66. package/src/atoms/NativeSelect.ts +14 -1
  67. package/src/atoms/Progress.ts +21 -5
  68. package/src/atoms/Switch.ts +7 -1
  69. package/src/cli/add.ts +7 -1
  70. package/src/cli/diff.ts +130 -3
  71. package/src/cli/projectConfig.ts +71 -0
  72. package/src/console/AddCommand.ts +6 -1
  73. package/src/console/DiffCommand.ts +18 -16
  74. package/src/lib/icons.ts +28 -0
  75. package/src/lib/image.ts +13 -1
  76. package/src/molecules/Accordion.ts +1 -2
  77. package/src/molecules/Collapsible.ts +1 -3
  78. package/src/molecules/InputOTP.ts +81 -27
  79. package/src/molecules/Resizable.ts +8 -2
  80. package/src/molecules/index.ts +3 -0
  81. package/src/organisms/AlertDialog.ts +3 -5
  82. package/src/organisms/Chart.ts +633 -125
  83. package/src/organisms/Combobox.ts +18 -2
  84. package/src/organisms/Command.ts +66 -7
  85. package/src/organisms/Dialog.ts +6 -7
  86. package/src/organisms/Form.ts +21 -0
  87. package/src/organisms/Select.ts +7 -4
  88. package/src/organisms/Sidebar.ts +75 -25
  89. package/src/organisms/Sonner.ts +1373 -0
  90. package/src/organisms/Toaster.ts +30 -6
  91. package/src/organisms/Tooltip.ts +4 -0
  92. package/src/organisms/index.ts +29 -0
  93. package/src/primitives/dismissable.ts +16 -8
  94. package/src/primitives/floating.ts +13 -2
  95. package/src/primitives/menu.ts +2 -1
  96. package/src/primitives/menuParts.ts +3 -3
  97. package/src/primitives/modalSurface.ts +77 -40
  98. package/src/primitives/portal.ts +27 -1
  99. package/src/primitives/presence.ts +12 -9
package/README.md CHANGED
@@ -2,13 +2,13 @@
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
 
9
9
  shadcn/ui is React. [Aurora](https://github.com/C9up/aurora) is a tagged-template DOM runtime with signals and no build step. nebula is the shadcn component set — the same markup, the same Tailwind classes, the same behaviour — written for Aurora.
10
10
 
11
- Seventy-four components across four atomic layers, plus the headless behaviour layer Radix would otherwise provide. Every component in shadcn's registry has a counterpart; several are deliberately narrower, and the [parity section](#parity-with-shadcn) says exactly which.
11
+ Seventy-six components across four atomic layers, plus the headless behaviour layer Radix would otherwise provide. Every component in shadcn's registry has a counterpart; several are deliberately narrower, and the [parity section](#parity-with-shadcn) says exactly which.
12
12
 
13
13
  ## Installation
14
14
 
@@ -67,9 +67,9 @@ shadcn stands on Radix, `clsx`, `tailwind-merge`, `class-variance-authority`, `l
67
67
  | `class-variance-authority` | `lib/cva.ts` — reimplemented, and it runs its result through `cn` |
68
68
  | Radix UI | `primitives/` — focus trap, dismissable layers, roving focus, type-ahead, presence, portals |
69
69
  | `@floating-ui/dom` | `primitives/floating.ts` — offset, flip, shift, arrow, available height |
70
- | `lucide-react` | `lib/icons.ts` — the eighteen glyphs the set needs, inlined |
70
+ | `lucide-react` | `lib/icons.ts` — the twenty-six glyphs the set needs, inlined |
71
71
  | `cmdk` | `organisms/Command.ts` |
72
- | `sonner` | `organisms/Toaster.ts` |
72
+ | `sonner` | `organisms/Sonner.ts` |
73
73
  | `react-day-picker` + `date-fns` | `organisms/Calendar.ts` — `Date` and `Intl` |
74
74
  | `@tanstack/react-table` | `organisms/DataTable.ts` — sort, filter, page, select |
75
75
  | `recharts` | `organisms/Chart.ts` — line, area and bar, as inline SVG |
@@ -90,7 +90,8 @@ Two of shadcn's entries have no direct counterpart on purpose. `DirectionProvide
90
90
  | DataTable | TanStack Table (column grouping, virtualisation, pinning, faceted filters, server-side) | sort, filter, page, select — in memory |
91
91
  | Sidebar | ~15 parts | the parts that are not re-skinned atoms — see below |
92
92
  | Carousel | embla (loop, autoplay, N slides per view) | scroll-snap, one slide per view, no loop or autoplay |
93
- | Toaster | Base UI's manager (display priority, anchored toasts, typed payload) — or sonner, with six positions | five variants, promise toasts, update and dedup by id, action, `onClose`, pause on hover, four corners |
93
+ | Sonner | sonner, in full | sonner's `toast` API and Toaster props, six positions, the stack that fans out on hover, rich colours, `Alt+T`; no swipe to dismiss, no `getHistory`, and `toast.promise` returns `{ id, unwrap }` |
94
+ | Toaster (deprecated) | Base UI's manager (display priority, anchored toasts, typed payload) — shadcn has deprecated it for sonner, and so has nebula | five variants, promise toasts, update and dedup by id, action, `onClose`, pause on hover, four corners |
94
95
  | Resizable | arbitrary nesting, persisted layouts, collapse-to-zero | two panes, one handle |
95
96
  | Combobox | single, multi-select and creatable recipes | single-select |
96
97
  | ScrollArea | scrollbars redrawn by Radix | native scrollbars, styled |
@@ -124,7 +125,7 @@ physical, because that is what the caller means.
124
125
 
125
126
  ## Choose your CSS engine
126
127
 
127
- 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.
128
129
 
129
130
  ### The one thing you must install: `tw-animate-css`
130
131
 
@@ -194,13 +195,13 @@ resources/pages/
194
195
  The rule is composition, not complexity. Slider is an atom though it is interactive, because it is one input. Card is a molecule though it is trivial, because it assembles parts.
195
196
 
196
197
  <details>
197
- <summary><strong>All 75 components</strong></summary>
198
+ <summary><strong>All 76 components</strong></summary>
198
199
 
199
200
  **atoms (22)** — AccessibleIcon, AspectRatio, Avatar, Badge, Button, Checkbox, Image, Input, Kbd, Label, Marker, NativeSelect, Progress, ScrollArea, Separator, Skeleton, Slider, Spinner, Switch, Textarea, Toggle, VisuallyHidden
200
201
 
201
202
  **molecules (24)** — Accordion, Alert, Attachment, Breadcrumb, Bubble, ButtonGroup, Card, Collapsible, Empty, Field, InputGroup, InputOTP, Item, Message, Pagination, Picture, PieceMap, RadioGroup, Resizable, Table, Tabs, ToggleGroup, Toolbar, Typography
202
203
 
203
- **organisms (26)** — AlertDialog, Calendar, Carousel, Chart, Combobox, Command, CommandDialog, ContextMenu, DataTable, DatePicker, DateRangePicker, Dialog, Drawer, DropdownMenu, Form, HoverCard, Menubar, MessageScroller, NavigationMenu, Popover, Questionnaire, Select, Sheet, Sidebar, Toaster, Tooltip
204
+ **organisms (27)** — AlertDialog, Calendar, Carousel, Chart, Combobox, Command, CommandDialog, ContextMenu, DataTable, DatePicker, DateRangePicker, Dialog, Drawer, DropdownMenu, Form, HoverCard, Menubar, MessageScroller, NavigationMenu, Popover, Questionnaire, Select, Sheet, Sidebar, Sonner, Toaster, Tooltip
204
205
 
205
206
  **templates (3)** — AppShell, AuthLayout, SettingsLayout
206
207
 
@@ -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
  });
@@ -26,8 +26,22 @@ export declare const Avatar: (props?: AvatarProps | undefined) => import("@c9up/
26
26
  export interface AvatarImageProps {
27
27
  src?: Reactive<string | undefined>;
28
28
  alt?: Reactive<string>;
29
+ /**
30
+ * Sent with the request for the picture. `"no-referrer"` keeps the page's
31
+ * URL from a host the picture comes from — a user-supplied avatar URL.
32
+ */
33
+ referrerPolicy?: ReferrerPolicy;
34
+ crossOrigin?: "anonymous" | "use-credentials";
29
35
  class?: Reactive<string>;
30
36
  }
37
+ /**
38
+ * The picture, once it has loaded.
39
+ *
40
+ * As Radix's `useImageLoadingStatus`: the source is preloaded off-document,
41
+ * with its referrer policy and CORS mode, and tried again whenever it
42
+ * changes — a broken avatar replaced by a new upload shows the new one. The
43
+ * `<img>` is rendered only once loaded, so a broken picture is never painted.
44
+ */
31
45
  export declare const AvatarImage: (props?: AvatarImageProps | undefined) => import("@c9up/aurora").TemplateResult;
32
46
  export interface AvatarFallbackProps {
33
47
  children?: Slot;
@@ -15,7 +15,7 @@
15
15
  * the fallback reads it, and neither knows the other exists. Radix needs the
16
16
  * same three pieces for the same reason.
17
17
  */
18
- import { component, createContext, html, inject, provide, signal, } from "@c9up/aurora";
18
+ import { component, createContext, effect, html, inject, onMount, provide, signal, } from "@c9up/aurora";
19
19
  import { slot } from "../lib/children.js";
20
20
  import { cn } from "../lib/cn.js";
21
21
  import { read, readOr } from "../lib/props.js";
@@ -35,23 +35,61 @@ export const Avatar = component((props) => {
35
35
  class="${() => cn("group/avatar relative flex size-8 shrink-0 overflow-hidden rounded-full select-none data-[size=lg]:size-10 data-[size=sm]:size-6", read(props.class))}"
36
36
  >${props.children?.()}</span>`;
37
37
  });
38
+ /**
39
+ * The picture, once it has loaded.
40
+ *
41
+ * As Radix's `useImageLoadingStatus`: the source is preloaded off-document,
42
+ * with its referrer policy and CORS mode, and tried again whenever it
43
+ * changes — a broken avatar replaced by a new upload shows the new one. The
44
+ * `<img>` is rendered only once loaded, so a broken picture is never painted.
45
+ */
38
46
  export const AvatarImage = component((props) => {
39
47
  const avatar = inject(AvatarContext);
40
- const hasSrc = () => {
48
+ const source = () => {
41
49
  const src = read(props.src);
42
- return src !== undefined && src !== "";
50
+ return src === undefined || src === "" ? undefined : src;
43
51
  };
44
52
  // Reported during setup, so the fallback built after it already reads the
45
53
  // right state rather than flashing through `absent`.
46
- avatar.setState(hasSrc() ? "pending" : "absent");
47
- return html `${() => hasSrc() && avatar.state() !== "failed"
54
+ avatar.setState(source() === undefined ? "absent" : "pending");
55
+ onMount(() => effect(() => {
56
+ const src = source();
57
+ if (src === undefined) {
58
+ avatar.setState("absent");
59
+ return;
60
+ }
61
+ avatar.setState("pending");
62
+ // A load still in flight for a source it has moved past must not
63
+ // decide the state of the current one.
64
+ let current = true;
65
+ const settle = (next) => {
66
+ if (current)
67
+ avatar.setState(next);
68
+ };
69
+ const image = new Image();
70
+ image.addEventListener("load", () => {
71
+ settle(image.naturalWidth > 0 ? "loaded" : "failed");
72
+ });
73
+ image.addEventListener("error", () => settle("failed"));
74
+ if (props.referrerPolicy !== undefined) {
75
+ image.referrerPolicy = props.referrerPolicy;
76
+ }
77
+ image.crossOrigin = props.crossOrigin ?? null;
78
+ image.src = src;
79
+ if (image.complete && image.naturalWidth > 0)
80
+ settle("loaded");
81
+ return () => {
82
+ current = false;
83
+ };
84
+ }));
85
+ return html `${() => avatar.state() === "loaded"
48
86
  ? html `<img
49
87
  data-slot="avatar-image"
50
- src="${() => read(props.src)}"
88
+ src="${source}"
51
89
  alt="${() => readOr(props.alt, "")}"
90
+ referrerpolicy="${props.referrerPolicy}"
91
+ crossorigin="${props.crossOrigin}"
52
92
  class="${() => cn("aspect-square size-full object-cover", read(props.class))}"
53
- @load="${() => avatar.setState("loaded")}"
54
- @error="${() => avatar.setState("failed")}"
55
93
  />`
56
94
  : null}`;
57
95
  });
@@ -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;
package/dist/cli/add.d.ts CHANGED
@@ -21,6 +21,8 @@ export interface AddOptions {
21
21
  paths?: Partial<NebulaPaths>;
22
22
  /** Overrides both the detected language and the configured one. */
23
23
  language?: Language;
24
+ /** The configured language: used when the tree says nothing. */
25
+ defaultLanguage?: Language;
24
26
  force?: boolean;
25
27
  /** Print what would happen and write nothing. */
26
28
  dryRun?: boolean;
package/dist/cli/add.js CHANGED
@@ -60,7 +60,10 @@ export function add(options) {
60
60
  const registry = loadRegistry(join(root, "registry.json"));
61
61
  const items = resolveItems(registry, options.names);
62
62
  const target = join(options.cwd, options.paths?.components ?? defaultPaths.components);
63
- const language = options.language ?? detectLanguage(target) ?? "js";
63
+ const language = options.language ??
64
+ detectLanguage(target) ??
65
+ options.defaultLanguage ??
66
+ "js";
64
67
  // The compiled output is what a browser can load. It ships in the package
65
68
  // and `prepublishOnly` rebuilds it, so an installed copy always has it;
66
69
  // inside this workspace it needs `pnpm build` first.
@@ -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"
@@ -33,10 +34,34 @@ export interface DiffOptions {
33
34
  cwd: string;
34
35
  paths?: Partial<NebulaPaths>;
35
36
  language?: Language;
37
+ /** The configured language: used when the tree says nothing. */
38
+ defaultLanguage?: Language;
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[];
36
60
  }
37
61
  export interface DiffResult {
38
62
  entries: DiffEntry[];
39
63
  language: Language;
64
+ update: UpdatePlan;
40
65
  }
41
66
  /**
42
67
  * Compare every copied component against the installed package.
@@ -45,3 +70,26 @@ export interface DiffResult {
45
70
  * lists everything nebula ships, and a component nobody copied is not news.
46
71
  */
47
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
  *
@@ -27,7 +27,10 @@ import { loadRegistry, packageRoot } from "./registry.js";
27
27
  export function diff(options) {
28
28
  const paths = { ...defaultPaths, ...options.paths };
29
29
  const target = join(options.cwd, paths.components);
30
- const language = options.language ?? detectLanguage(target) ?? "js";
30
+ const language = options.language ??
31
+ detectLanguage(target) ??
32
+ options.defaultLanguage ??
33
+ "js";
31
34
  const root = packageRoot(join(options.cwd, "package.json"));
32
35
  const sourceRoot = join(root, language === "ts" ? "src" : "dist");
33
36
  const registry = loadRegistry(join(root, "registry.json"));
@@ -54,7 +57,78 @@ export function diff(options) {
54
57
  }
55
58
  }
56
59
  entries.sort((a, b) => a.file.localeCompare(b.file));
57
- 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
+ };
58
132
  }
59
133
  function compare(hashes) {
60
134
  const { copy, source, recorded } = hashes;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * The app's `config/nebula.ts`, as the copying commands read it.
3
+ *
4
+ * shadcn's CLI reads `components.json` on every `add` and `diff`; these read
5
+ * the config file the same way. Imported directly rather than taken from the
6
+ * booted application: the console kernel hands the app — and its config —
7
+ * only to a command that starts it, and starting it opens the connections a
8
+ * file copy has no use for, and fails where they are not running.
9
+ */
10
+ import type { Language, NebulaPaths } from "../config.js";
11
+ export interface ProjectConfig {
12
+ paths?: Partial<NebulaPaths>;
13
+ language?: Language;
14
+ }
15
+ /** The config under `<cwd>/config`, or nothing when the app has none. */
16
+ export declare function loadProjectConfig(cwd: string): Promise<ProjectConfig>;
@@ -0,0 +1,61 @@
1
+ /**
2
+ * The app's `config/nebula.ts`, as the copying commands read it.
3
+ *
4
+ * shadcn's CLI reads `components.json` on every `add` and `diff`; these read
5
+ * the config file the same way. Imported directly rather than taken from the
6
+ * booted application: the console kernel hands the app — and its config —
7
+ * only to a command that starts it, and starting it opens the connections a
8
+ * file copy has no use for, and fails where they are not running.
9
+ */
10
+ import { existsSync } from "node:fs";
11
+ import { join } from "node:path";
12
+ import { pathToFileURL } from "node:url";
13
+ /** Tried in order; the first that exists is the config. */
14
+ const CANDIDATES = ["nebula.ts", "nebula.js", "nebula.mjs"];
15
+ function isRecord(value) {
16
+ return typeof value === "object" && value !== null && !Array.isArray(value);
17
+ }
18
+ function pathsOf(value, file) {
19
+ if (value === undefined)
20
+ return undefined;
21
+ if (!isRecord(value)) {
22
+ throw new Error(`${file}: \`paths\` must be an object.`);
23
+ }
24
+ const paths = {};
25
+ for (const key of ["components", "css", "output"]) {
26
+ const entry = value[key];
27
+ if (entry === undefined)
28
+ continue;
29
+ if (typeof entry !== "string" || entry === "") {
30
+ throw new Error(`${file}: \`paths.${key}\` must be a non-empty string.`);
31
+ }
32
+ paths[key] = entry;
33
+ }
34
+ return paths;
35
+ }
36
+ function languageOf(value, file) {
37
+ if (value === undefined)
38
+ return undefined;
39
+ if (value === "ts" || value === "js")
40
+ return value;
41
+ throw new Error(`${file}: \`language\` must be "ts" or "js".`);
42
+ }
43
+ /** The config under `<cwd>/config`, or nothing when the app has none. */
44
+ export async function loadProjectConfig(cwd) {
45
+ for (const name of CANDIDATES) {
46
+ const file = join(cwd, "config", name);
47
+ if (!existsSync(file))
48
+ continue;
49
+ const label = `config/${name}`;
50
+ const loaded = await import(pathToFileURL(file).href);
51
+ const config = isRecord(loaded) ? loaded.default : undefined;
52
+ if (!isRecord(config)) {
53
+ throw new Error(`${label} must export its config as the default export.`);
54
+ }
55
+ return {
56
+ paths: pathsOf(config.paths, label),
57
+ language: languageOf(config.language, label),
58
+ };
59
+ }
60
+ return {};
61
+ }