@c9up/nebula 0.1.9 → 0.2.1

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 (132) hide show
  1. package/dist/atoms/Avatar.d.ts +36 -9
  2. package/dist/atoms/Avatar.js +66 -27
  3. package/dist/atoms/index.d.ts +1 -1
  4. package/dist/atoms/index.js +1 -1
  5. package/dist/configure.d.ts +6 -0
  6. package/dist/configure.js +4 -22
  7. package/dist/lib/children.d.ts +30 -0
  8. package/dist/lib/id.d.ts +13 -29
  9. package/dist/lib/id.js +13 -39
  10. package/dist/lib/motion.d.ts +10 -0
  11. package/dist/lib/motion.js +10 -0
  12. package/dist/molecules/Accordion.d.ts +36 -15
  13. package/dist/molecules/Accordion.js +68 -45
  14. package/dist/molecules/Breadcrumb.d.ts +29 -11
  15. package/dist/molecules/Breadcrumb.js +52 -52
  16. package/dist/molecules/Collapsible.d.ts +18 -17
  17. package/dist/molecules/Collapsible.js +42 -34
  18. package/dist/molecules/Field.d.ts +66 -30
  19. package/dist/molecules/Field.js +106 -55
  20. package/dist/molecules/InputGroup.d.ts +39 -21
  21. package/dist/molecules/InputGroup.js +43 -27
  22. package/dist/molecules/InputOTP.d.ts +26 -3
  23. package/dist/molecules/InputOTP.js +109 -76
  24. package/dist/molecules/Message.js +5 -4
  25. package/dist/molecules/Pagination.d.ts +36 -11
  26. package/dist/molecules/Pagination.js +58 -74
  27. package/dist/molecules/RadioGroup.d.ts +25 -17
  28. package/dist/molecules/RadioGroup.js +47 -43
  29. package/dist/molecules/Resizable.d.ts +32 -7
  30. package/dist/molecules/Resizable.js +76 -49
  31. package/dist/molecules/Tabs.d.ts +49 -11
  32. package/dist/molecules/Tabs.js +107 -51
  33. package/dist/molecules/ToggleGroup.d.ts +16 -10
  34. package/dist/molecules/ToggleGroup.js +37 -21
  35. package/dist/molecules/index.d.ts +11 -11
  36. package/dist/molecules/index.js +11 -11
  37. package/dist/organisms/AlertDialog.d.ts +80 -28
  38. package/dist/organisms/AlertDialog.js +192 -67
  39. package/dist/organisms/Carousel.d.ts +25 -3
  40. package/dist/organisms/Carousel.js +75 -43
  41. package/dist/organisms/Combobox.d.ts +2 -1
  42. package/dist/organisms/Combobox.js +46 -16
  43. package/dist/organisms/Command.d.ts +73 -32
  44. package/dist/organisms/Command.js +209 -131
  45. package/dist/organisms/CommandDialog.js +5 -5
  46. package/dist/organisms/ContextMenu.d.ts +41 -19
  47. package/dist/organisms/ContextMenu.js +112 -71
  48. package/dist/organisms/DataTable.js +42 -8
  49. package/dist/organisms/Dialog.d.ts +97 -31
  50. package/dist/organisms/Dialog.js +193 -68
  51. package/dist/organisms/Drawer.d.ts +33 -10
  52. package/dist/organisms/Drawer.js +130 -52
  53. package/dist/organisms/DropdownMenu.d.ts +58 -11
  54. package/dist/organisms/DropdownMenu.js +137 -50
  55. package/dist/organisms/Form.js +9 -11
  56. package/dist/organisms/HoverCard.d.ts +39 -19
  57. package/dist/organisms/HoverCard.js +116 -40
  58. package/dist/organisms/Menubar.d.ts +55 -19
  59. package/dist/organisms/Menubar.js +166 -82
  60. package/dist/organisms/NavigationMenu.d.ts +77 -31
  61. package/dist/organisms/NavigationMenu.js +169 -98
  62. package/dist/organisms/Popover.d.ts +72 -12
  63. package/dist/organisms/Popover.js +132 -25
  64. package/dist/organisms/Questionnaire.js +5 -5
  65. package/dist/organisms/Select.d.ts +99 -18
  66. package/dist/organisms/Select.js +253 -111
  67. package/dist/organisms/Sheet.d.ts +57 -13
  68. package/dist/organisms/Sheet.js +141 -54
  69. package/dist/organisms/Sidebar.d.ts +146 -56
  70. package/dist/organisms/Sidebar.js +236 -128
  71. package/dist/organisms/Tooltip.d.ts +88 -14
  72. package/dist/organisms/Tooltip.js +210 -47
  73. package/dist/organisms/index.d.ts +15 -15
  74. package/dist/organisms/index.js +15 -15
  75. package/dist/primitives/floating.js +25 -0
  76. package/dist/primitives/floatingSurface.d.ts +11 -0
  77. package/dist/primitives/floatingSurface.js +8 -0
  78. package/dist/primitives/menu.d.ts +45 -1
  79. package/dist/primitives/menu.js +45 -14
  80. package/dist/primitives/menuParts.d.ts +113 -0
  81. package/dist/primitives/menuParts.js +207 -0
  82. package/dist/stubs.d.ts +13 -0
  83. package/dist/stubs.js +14 -0
  84. package/nebula.css +1 -1
  85. package/package.json +4 -3
  86. package/registry.json +18 -6
  87. package/src/atoms/Avatar.ts +141 -37
  88. package/src/atoms/index.ts +13 -1
  89. package/src/configure.ts +10 -23
  90. package/src/lib/children.ts +31 -0
  91. package/src/lib/id.ts +11 -39
  92. package/src/lib/motion.ts +12 -0
  93. package/src/molecules/Accordion.ts +120 -60
  94. package/src/molecules/Breadcrumb.ts +77 -76
  95. package/src/molecules/Collapsible.ts +77 -41
  96. package/src/molecules/Field.ts +187 -72
  97. package/src/molecules/InputGroup.ts +88 -35
  98. package/src/molecules/InputOTP.ts +150 -86
  99. package/src/molecules/Message.ts +6 -4
  100. package/src/molecules/Pagination.ts +96 -101
  101. package/src/molecules/RadioGroup.ts +70 -59
  102. package/src/molecules/Resizable.ts +138 -75
  103. package/src/molecules/Tabs.ts +187 -74
  104. package/src/molecules/ToggleGroup.ts +77 -38
  105. package/src/molecules/index.ts +85 -8
  106. package/src/organisms/AlertDialog.ts +319 -82
  107. package/src/organisms/Carousel.ts +129 -52
  108. package/src/organisms/Combobox.ts +64 -19
  109. package/src/organisms/Command.ts +342 -159
  110. package/src/organisms/CommandDialog.ts +6 -6
  111. package/src/organisms/ContextMenu.ts +185 -83
  112. package/src/organisms/DataTable.ts +56 -10
  113. package/src/organisms/Dialog.ts +312 -102
  114. package/src/organisms/Drawer.ts +219 -71
  115. package/src/organisms/DropdownMenu.ts +219 -61
  116. package/src/organisms/Form.ts +48 -34
  117. package/src/organisms/HoverCard.ts +187 -53
  118. package/src/organisms/Menubar.ts +247 -87
  119. package/src/organisms/NavigationMenu.ts +306 -128
  120. package/src/organisms/Popover.ts +215 -39
  121. package/src/organisms/Questionnaire.ts +9 -6
  122. package/src/organisms/Select.ts +397 -130
  123. package/src/organisms/Sheet.ts +252 -83
  124. package/src/organisms/Sidebar.ts +438 -185
  125. package/src/organisms/Tooltip.ts +315 -65
  126. package/src/organisms/index.ts +284 -14
  127. package/src/primitives/floating.ts +33 -0
  128. package/src/primitives/floatingSurface.ts +19 -0
  129. package/src/primitives/menu.ts +79 -18
  130. package/src/primitives/menuParts.ts +371 -0
  131. package/src/stubs.ts +16 -0
  132. package/stubs/config/nebula.stub +21 -0
@@ -1,23 +1,50 @@
1
1
  /**
2
2
  * Avatar — a user's picture, with a fallback when there is none.
3
3
  *
4
- * shadcn splits this into `Avatar` / `AvatarImage` / `AvatarFallback` because
5
- * Radix needs three components to track the image's load state across them.
6
- * nebula tracks it in one signal inside one component, so the API is a `src`
7
- * and a `fallback`.
4
+ * Avatar({ children: () => html`
5
+ * ${AvatarImage({ src: user.photo, alt: user.name })}
6
+ * ${AvatarFallback({ children: initials })}
7
+ * ` })
8
8
  *
9
9
  * Three states, not two. An image that has not loaded *yet* must not show the
10
10
  * fallback — swapping initials in and a photo over them a moment later is the
11
11
  * flicker this component exists to avoid. So the fallback appears only once
12
- * the image has actually failed, or when there was no `src` to begin with.
12
+ * the image has actually failed, or when there is no `AvatarImage` at all.
13
+ *
14
+ * That is what the context carries: the image reports its own load state up,
15
+ * the fallback reads it, and neither knows the other exists. Radix needs the
16
+ * same three pieces for the same reason.
13
17
  */
14
- import { type Slot } from "../lib/children.js";
18
+ import type { Parts, Slot } from "../lib/children.js";
15
19
  import { type Reactive } from "../lib/props.js";
16
20
  export interface AvatarProps {
21
+ size?: "sm" | "default" | "lg";
22
+ class?: Reactive<string>;
23
+ children?: Parts;
24
+ }
25
+ export declare const Avatar: (props?: AvatarProps | undefined) => import("@c9up/aurora").TemplateResult;
26
+ export interface AvatarImageProps {
17
27
  src?: Reactive<string | undefined>;
18
28
  alt?: Reactive<string>;
19
- /** Shown when there is no image, or it failed. Usually initials. */
20
- fallback?: Slot;
21
29
  class?: Reactive<string>;
22
30
  }
23
- export declare const Avatar: (props?: AvatarProps | undefined) => import("@c9up/aurora").TemplateResult;
31
+ export declare const AvatarImage: (props?: AvatarImageProps | undefined) => import("@c9up/aurora").TemplateResult;
32
+ export interface AvatarFallbackProps {
33
+ children?: Slot;
34
+ class?: Reactive<string>;
35
+ }
36
+ export declare const AvatarFallback: (props?: AvatarFallbackProps | undefined) => import("@c9up/aurora").TemplateResult;
37
+ export interface AvatarBadgeProps {
38
+ children?: Slot;
39
+ class?: Reactive<string>;
40
+ }
41
+ /** A status dot in the corner — online, unread, verified. */
42
+ export declare const AvatarBadge: (props?: AvatarBadgeProps | undefined) => import("@c9up/aurora").TemplateResult;
43
+ export interface AvatarGroupProps {
44
+ children?: Slot;
45
+ class?: Reactive<string>;
46
+ }
47
+ /** Overlapping avatars, each ringed so the stack reads as separate faces. */
48
+ export declare const AvatarGroup: (props?: AvatarGroupProps | undefined) => import("@c9up/aurora").TemplateResult;
49
+ /** The "+3" that closes a group. */
50
+ export declare const AvatarGroupCount: (props?: AvatarGroupProps | undefined) => import("@c9up/aurora").TemplateResult;
@@ -1,46 +1,85 @@
1
1
  /**
2
2
  * Avatar — a user's picture, with a fallback when there is none.
3
3
  *
4
- * shadcn splits this into `Avatar` / `AvatarImage` / `AvatarFallback` because
5
- * Radix needs three components to track the image's load state across them.
6
- * nebula tracks it in one signal inside one component, so the API is a `src`
7
- * and a `fallback`.
4
+ * Avatar({ children: () => html`
5
+ * ${AvatarImage({ src: user.photo, alt: user.name })}
6
+ * ${AvatarFallback({ children: initials })}
7
+ * ` })
8
8
  *
9
9
  * Three states, not two. An image that has not loaded *yet* must not show the
10
10
  * fallback — swapping initials in and a photo over them a moment later is the
11
11
  * flicker this component exists to avoid. So the fallback appears only once
12
- * the image has actually failed, or when there was no `src` to begin with.
12
+ * the image has actually failed, or when there is no `AvatarImage` at all.
13
+ *
14
+ * That is what the context carries: the image reports its own load state up,
15
+ * the fallback reads it, and neither knows the other exists. Radix needs the
16
+ * same three pieces for the same reason.
13
17
  */
14
- import { component, html, signal } from "@c9up/aurora";
18
+ import { component, createContext, html, inject, provide, signal, } from "@c9up/aurora";
15
19
  import { slot } from "../lib/children.js";
16
20
  import { cn } from "../lib/cn.js";
17
21
  import { read, readOr } from "../lib/props.js";
22
+ const AvatarContext = createContext("Avatar");
18
23
  export const Avatar = component((props) => {
19
- const state = signal("pending");
24
+ // `absent` until an image says otherwise: an avatar with no `AvatarImage`
25
+ // is a fallback-only avatar, and it must not wait for a load that will
26
+ // never happen.
27
+ const state = signal("absent");
28
+ provide(AvatarContext, {
29
+ state: () => state(),
30
+ setState: (next) => state(next),
31
+ });
32
+ return html `<span
33
+ data-slot="avatar"
34
+ data-size="${props.size ?? "default"}"
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
+ >${props.children?.()}</span>`;
37
+ });
38
+ export const AvatarImage = component((props) => {
39
+ const avatar = inject(AvatarContext);
20
40
  const hasSrc = () => {
21
41
  const src = read(props.src);
22
42
  return src !== undefined && src !== "";
23
43
  };
24
- const showFallback = () => !hasSrc() || state() === "failed";
25
- return html `<span
26
- data-slot="avatar"
27
- class="${() => cn("relative flex size-8 shrink-0 overflow-hidden rounded-full", read(props.class))}"
28
- >
29
- ${() => hasSrc() && state() !== "failed"
44
+ // Reported during setup, so the fallback built after it already reads the
45
+ // right state rather than flashing through `absent`.
46
+ avatar.setState(hasSrc() ? "pending" : "absent");
47
+ return html `${() => hasSrc() && avatar.state() !== "failed"
30
48
  ? html `<img
31
- data-slot="avatar-image"
32
- src="${() => read(props.src)}"
33
- alt="${() => readOr(props.alt, "")}"
34
- class="aspect-square size-full object-cover"
35
- @load="${() => state("loaded")}"
36
- @error="${() => state("failed")}"
37
- />`
38
- : null}
39
- ${() => showFallback()
49
+ data-slot="avatar-image"
50
+ src="${() => read(props.src)}"
51
+ alt="${() => readOr(props.alt, "")}"
52
+ class="${() => cn("aspect-square size-full object-cover", read(props.class))}"
53
+ @load="${() => avatar.setState("loaded")}"
54
+ @error="${() => avatar.setState("failed")}"
55
+ />`
56
+ : null}`;
57
+ });
58
+ export const AvatarFallback = component((props) => {
59
+ const avatar = inject(AvatarContext);
60
+ const show = () => {
61
+ const state = avatar.state();
62
+ return state === "absent" || state === "failed";
63
+ };
64
+ return html `${() => show()
40
65
  ? html `<span
41
- data-slot="avatar-fallback"
42
- class="bg-muted flex size-full items-center justify-center rounded-full text-xs font-medium"
43
- >${slot(props.fallback)}</span>`
44
- : null}
45
- </span>`;
66
+ data-slot="avatar-fallback"
67
+ class="${() => cn("bg-muted text-muted-foreground flex size-full items-center justify-center rounded-full text-sm group-data-[size=sm]/avatar:text-xs", read(props.class))}"
68
+ >${slot(props.children)}</span>`
69
+ : null}`;
46
70
  });
71
+ /** A status dot in the corner — online, unread, verified. */
72
+ export const AvatarBadge = component((props) => html `<span
73
+ data-slot="avatar-badge"
74
+ class="${() => cn("bg-primary text-primary-foreground ring-background absolute right-0 bottom-0 z-10 inline-flex items-center justify-center rounded-full ring-2 select-none", "group-data-[size=sm]/avatar:size-2 group-data-[size=sm]/avatar:[&>svg]:hidden", "group-data-[size=default]/avatar:size-2.5 group-data-[size=default]/avatar:[&>svg]:size-2", "group-data-[size=lg]/avatar:size-3 group-data-[size=lg]/avatar:[&>svg]:size-2", read(props.class))}"
75
+ >${slot(props.children)}</span>`);
76
+ /** Overlapping avatars, each ringed so the stack reads as separate faces. */
77
+ export const AvatarGroup = component((props) => html `<div
78
+ data-slot="avatar-group"
79
+ class="${() => cn("group/avatar-group flex -space-x-2 *:data-[slot=avatar]:ring-2 *:data-[slot=avatar]:ring-background", read(props.class))}"
80
+ >${slot(props.children)}</div>`);
81
+ /** The "+3" that closes a group. */
82
+ export const AvatarGroupCount = component((props) => html `<span
83
+ data-slot="avatar-group-count"
84
+ class="${() => cn("bg-muted text-muted-foreground ring-background relative flex size-8 shrink-0 items-center justify-center rounded-full text-sm ring-2 group-has-data-[size=lg]/avatar-group:size-10 group-has-data-[size=sm]/avatar-group:size-6 [&>svg]:size-4 group-has-data-[size=lg]/avatar-group:[&>svg]:size-5 group-has-data-[size=sm]/avatar-group:[&>svg]:size-3", read(props.class))}"
85
+ >${slot(props.children)}</span>`);
@@ -12,7 +12,7 @@
12
12
  * Slider is an atom despite being interactive, because it is one input.
13
13
  */
14
14
  export { AspectRatio, type AspectRatioProps } from "./AspectRatio.js";
15
- export { Avatar, type AvatarProps } from "./Avatar.js";
15
+ export { Avatar, AvatarBadge, type AvatarBadgeProps, AvatarFallback, type AvatarFallbackProps, AvatarGroup, AvatarGroupCount, type AvatarGroupProps, AvatarImage, type AvatarImageProps, type AvatarProps, } from "./Avatar.js";
16
16
  export { Badge, type BadgeProps, type BadgeVariants, badgeVariants, } from "./Badge.js";
17
17
  export { Button, type ButtonProps, type ButtonVariants, buttonVariants, } from "./Button.js";
18
18
  export { Checkbox, type CheckboxProps, checkboxClasses } from "./Checkbox.js";
@@ -12,7 +12,7 @@
12
12
  * Slider is an atom despite being interactive, because it is one input.
13
13
  */
14
14
  export { AspectRatio } from "./AspectRatio.js";
15
- export { Avatar } from "./Avatar.js";
15
+ export { Avatar, AvatarBadge, AvatarFallback, AvatarGroup, AvatarGroupCount, AvatarImage, } from "./Avatar.js";
16
16
  export { Badge, badgeVariants, } from "./Badge.js";
17
17
  export { Button, buttonVariants, } from "./Button.js";
18
18
  export { Checkbox, checkboxClasses } from "./Checkbox.js";
@@ -29,6 +29,12 @@ interface Codemods {
29
29
  }): Promise<void>;
30
30
  /** Appends to `reamrc.commands` — the channel for package-shipped commands. */
31
31
  registerCommand(importPath: string): Promise<void>;
32
+ makeUsingStub(stubsRoot: string, stubPath: string, state?: Record<string, string | number | boolean>, options?: {
33
+ force?: boolean;
34
+ }): Promise<{
35
+ path: string;
36
+ contents: string;
37
+ }>;
32
38
  }
33
39
  /** Flags forwarded from `ream add` / `ream configure`, as the CLI encodes them. */
34
40
  type Flags = Record<string, string[] | undefined>;
package/dist/configure.js CHANGED
@@ -19,27 +19,7 @@ import { readFile } from "node:fs/promises";
19
19
  import { resolve } from "node:path";
20
20
  import { adapterFor, isAdapterName } from "./adapters/index.js";
21
21
  import { resolveConfig } from "./config.js";
22
- function configFile(adapter) {
23
- return `import { defineConfig } from '@c9up/nebula'
24
-
25
- /**
26
- * nebula — component registry and style adapter.
27
- *
28
- * Changing \`adapter\` and re-running \`ream configure @c9up/nebula\` swaps the
29
- * CSS engine. The components themselves are untouched: all three adapters
30
- * consume the same class names.
31
- */
32
- export default defineConfig({
33
- adapter: '${adapter}',
34
- paths: {
35
- // Where \`ream nebula:add\` copies components. The atomic layers live under it.
36
- components: 'resources/pages',
37
- css: 'resources/css/app.css',
38
- output: 'public/app.css',
39
- },
40
- })
41
- `;
42
- }
22
+ import { stubsRoot } from "./stubs.js";
43
23
  /**
44
24
  * Read the adapter from the forwarded flags.
45
25
  *
@@ -60,7 +40,9 @@ export async function configure(codemods, flags = {}) {
60
40
  const name = adapterFrom(flags);
61
41
  const adapter = adapterFor(name);
62
42
  const config = resolveConfig({ adapter: name });
63
- await codemods.writeFile("config/nebula.ts", configFile(name));
43
+ await codemods.makeUsingStub(stubsRoot, "config/nebula.stub", {
44
+ adapter: name,
45
+ });
64
46
  // `reamrc.commands` is the channel Ream provides for commands a package
65
47
  // ships, which directory discovery cannot see. `ream` forwards any
66
48
  // unrecognised name to the app's console kernel, so these exist without a
@@ -17,6 +17,36 @@ import type { Reactive } from "./props.js";
17
17
  export type Child = TemplateResult | Node | string | number | boolean | null | undefined | readonly Child[];
18
18
  /** Content that may be constant or recomputed. */
19
19
  export type Slot = Reactive<Child>;
20
+ /**
21
+ * The children of a component that PROVIDES context, as a function.
22
+ *
23
+ * A compound component — `Tooltip`, `Select`, `DropdownMenu` — shares its
24
+ * state with its parts through Aurora's context, and context reaches only what
25
+ * the provider creates inside its own setup. Aurora evaluates eagerly, so
26
+ * children handed over already built ran before the provider existed:
27
+ *
28
+ * Tooltip({ children: TooltipTrigger({ … }) }) // ✗ built too early
29
+ * Tooltip({ children: () => TooltipTrigger({ … }) }) // ✓ the setup calls it
30
+ *
31
+ * This is the aurora spelling of what JSX gets from deferring an element tree.
32
+ * `Parts` names it so the type makes the requirement, rather than a blank
33
+ * surface at runtime.
34
+ *
35
+ * Called ONCE, during setup — the structure of a compound component is fixed,
36
+ * and its moving pieces are signals inside the parts.
37
+ *
38
+ * The same rule read from the other end: a part that READS context must be
39
+ * built eagerly too, so it must not be hidden inside a `Slot`. `Slot` exists
40
+ * for content that CHANGES, and the renderer calls it later, by which time
41
+ * there is no context left to read:
42
+ *
43
+ * DialogHeader({ children: html`${DialogTitle(…)}` }) // ✓ a value
44
+ * DialogHeader({ children: () => html`${DialogTitle(…)}` }) // ✗ too late
45
+ *
46
+ * So: write `() =>` for a component that PROVIDES (its type says `Parts`), and
47
+ * a plain value everywhere else unless the content really does change.
48
+ */
49
+ export type Parts = () => Child;
20
50
  /**
21
51
  * Bind content into a template so it stays live.
22
52
  *
package/dist/lib/id.d.ts CHANGED
@@ -1,31 +1,15 @@
1
1
  /**
2
- * Stable element ids.
3
- *
4
- * Radix leans on React's `useId` to wire ARIA relationships — a trigger's
5
- * `aria-controls` has to name the id its content actually carries. Aurora has
6
- * no equivalent, and nebula needs one for two reasons: the ARIA wiring above,
7
- * and element lookup. Aurora templates have no `ref` directive, so a component
8
- * that must measure or focus a node finds it by id inside `onMount()`.
9
- *
10
- * The counter is monotonic per module instance, so the sequence depends only
11
- * on the order components are constructed in. That order is identical on the
12
- * server and in the browser for the same tree, which is what makes the ids
13
- * survive hydration — the same property React's `useId` relies on.
14
- *
15
- * `resetIds()` exists for the server: a long-lived process renders many
16
- * requests, and without a reset the counter climbs forever and every response
17
- * ships different markup, defeating any HTML cache. Call it once per render
18
- * pass, before the tree is built.
19
- */
20
- /** Mint an id unique within this render pass. */
21
- export declare function uid(prefix?: string): string;
22
- /** Restart the sequence. Call once per SSR render, before building the tree. */
23
- export declare function resetIds(): void;
24
- /**
25
- * Look an element up by the id a component minted for it.
26
- *
27
- * Returns `null` off the DOM (SSR) or before mount rather than throwing, so
28
- * callers can run the same code in both environments. Every consumer inside
29
- * nebula is in `onMount`, where the node is live.
2
+ * Stable element ids — aurora's counter, re-exported.
3
+ *
4
+ * It was nebula's own, and that was the bug: aurora resets its sequence at the
5
+ * start of each render pass (`renderPage` server-side, `hydrate` in the
6
+ * browser), and a second counter living here saw none of those resets. A
7
+ * long-lived server therefore shipped `tooltip-trigger-14` while the browser,
8
+ * hydrating from zero, minted `tooltip-trigger-1` and looked it up — so
9
+ * `byId` answered `null`, `floatingSurface` had no anchor, and the tooltip
10
+ * never opened although its mount hook had run and its trigger was wired.
11
+ *
12
+ * Every id nebula mints has to come from the same counter aurora resets; the
13
+ * names are kept so nothing importing them has to change.
30
14
  */
31
- export declare function byId(id: string): HTMLElement | null;
15
+ export { byId, resetIds, uid } from "@c9up/aurora";
package/dist/lib/id.js CHANGED
@@ -1,41 +1,15 @@
1
1
  /**
2
- * Stable element ids.
3
- *
4
- * Radix leans on React's `useId` to wire ARIA relationships — a trigger's
5
- * `aria-controls` has to name the id its content actually carries. Aurora has
6
- * no equivalent, and nebula needs one for two reasons: the ARIA wiring above,
7
- * and element lookup. Aurora templates have no `ref` directive, so a component
8
- * that must measure or focus a node finds it by id inside `onMount()`.
9
- *
10
- * The counter is monotonic per module instance, so the sequence depends only
11
- * on the order components are constructed in. That order is identical on the
12
- * server and in the browser for the same tree, which is what makes the ids
13
- * survive hydration — the same property React's `useId` relies on.
14
- *
15
- * `resetIds()` exists for the server: a long-lived process renders many
16
- * requests, and without a reset the counter climbs forever and every response
17
- * ships different markup, defeating any HTML cache. Call it once per render
18
- * pass, before the tree is built.
19
- */
20
- let counter = 0;
21
- /** Mint an id unique within this render pass. */
22
- export function uid(prefix = "nebula") {
23
- counter += 1;
24
- return `${prefix}-${counter}`;
25
- }
26
- /** Restart the sequence. Call once per SSR render, before building the tree. */
27
- export function resetIds() {
28
- counter = 0;
29
- }
30
- /**
31
- * Look an element up by the id a component minted for it.
32
- *
33
- * Returns `null` off the DOM (SSR) or before mount rather than throwing, so
34
- * callers can run the same code in both environments. Every consumer inside
35
- * nebula is in `onMount`, where the node is live.
2
+ * Stable element ids — aurora's counter, re-exported.
3
+ *
4
+ * It was nebula's own, and that was the bug: aurora resets its sequence at the
5
+ * start of each render pass (`renderPage` server-side, `hydrate` in the
6
+ * browser), and a second counter living here saw none of those resets. A
7
+ * long-lived server therefore shipped `tooltip-trigger-14` while the browser,
8
+ * hydrating from zero, minted `tooltip-trigger-1` and looked it up — so
9
+ * `byId` answered `null`, `floatingSurface` had no anchor, and the tooltip
10
+ * never opened although its mount hook had run and its trigger was wired.
11
+ *
12
+ * Every id nebula mints has to come from the same counter aurora resets; the
13
+ * names are kept so nothing importing them has to change.
36
14
  */
37
- export function byId(id) {
38
- if (typeof document === "undefined")
39
- return null;
40
- return document.getElementById(id);
41
- }
15
+ export { byId, resetIds, uid } from "@c9up/aurora";
@@ -29,6 +29,16 @@ import type { Side } from "../primitives/floating.js";
29
29
  * once, so reduced motion gets an instant close with no branch in the component.
30
30
  */
31
31
  export declare const zoomInOut = "data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=open]:fade-in-0 data-[state=closed]:fade-out-0 data-[state=open]:zoom-in-95 data-[state=closed]:zoom-out-95 motion-reduce:animate-none";
32
+ /**
33
+ * The entrance offset every anchored surface shares.
34
+ *
35
+ * shadcn puts these four on popover, dropdown, select, tooltip, hover card,
36
+ * menubar and context-menu content alike, so the surface slides in from the
37
+ * edge it is anchored against and the motion points back at whatever opened
38
+ * it. `data-side` is written by `autoPosition` after any flip, so a menu that
39
+ * flipped above its trigger slides the other way without a second class.
40
+ */
41
+ export declare const slideInFromSide = "data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2";
32
42
  /** Backdrops and tooltips — no movement, just opacity. */
33
43
  export declare const fadeInOut = "data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=open]:fade-in-0 data-[state=closed]:fade-out-0 motion-reduce:animate-none";
34
44
  /**
@@ -28,6 +28,16 @@
28
28
  * once, so reduced motion gets an instant close with no branch in the component.
29
29
  */
30
30
  export const zoomInOut = "data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=open]:fade-in-0 data-[state=closed]:fade-out-0 data-[state=open]:zoom-in-95 data-[state=closed]:zoom-out-95 motion-reduce:animate-none";
31
+ /**
32
+ * The entrance offset every anchored surface shares.
33
+ *
34
+ * shadcn puts these four on popover, dropdown, select, tooltip, hover card,
35
+ * menubar and context-menu content alike, so the surface slides in from the
36
+ * edge it is anchored against and the motion points back at whatever opened
37
+ * it. `data-side` is written by `autoPosition` after any flip, so a menu that
38
+ * flipped above its trigger slides the other way without a second class.
39
+ */
40
+ export const slideInFromSide = "data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2";
31
41
  /** Backdrops and tooltips — no movement, just opacity. */
32
42
  export const fadeInOut = "data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=open]:fade-in-0 data-[state=closed]:fade-out-0 motion-reduce:animate-none";
33
43
  /**
@@ -1,28 +1,25 @@
1
1
  /**
2
2
  * Accordion — a stack of collapsible sections.
3
3
  *
4
- * Data-driven rather than composed: an accordion is a list, and describing it
5
- * as one is both shorter to write and the only shape that lets the group
6
- * enforce `type: "single"` — which needs to know about every section at once,
7
- * something Radix can only do through context.
4
+ * Accordion({ type: "single", children: () => html`
5
+ * ${AccordionItem({ value: "a", children: () => html`
6
+ * ${AccordionTrigger({ children: "Shipping" })}
7
+ * ${AccordionContent({ children: "Two to four days." })}
8
+ * ` })}
9
+ * ` })
10
+ *
11
+ * `type: "single"` needs to know about every section at once, which is what
12
+ * the context carries: the group owns the open SET and each item asks whether
13
+ * it is in it. Radix does the same, for the same reason.
8
14
  *
9
15
  * The keyboard behaviour is the WAI-ARIA accordion pattern, delegated to
10
16
  * `rovingFocus` over the headers: arrows move between sections, Home and End
11
17
  * jump to the ends, and the headers are one tab stop rather than one each.
12
18
  */
13
- import type { Child, Slot } from "../lib/children.js";
19
+ import type { Parts, Slot } from "../lib/children.js";
14
20
  import { type Reactive } from "../lib/props.js";
15
- export interface AccordionItem {
16
- /** Stable key. Used for the open-state set and for the ARIA ids. */
17
- value: string;
18
- /** The header content. */
19
- trigger: Child;
20
- /** The panel content. */
21
- content: Slot;
22
- disabled?: boolean;
23
- }
24
21
  export interface AccordionProps {
25
- items: readonly AccordionItem[];
22
+ children?: Parts;
26
23
  /** `"single"` closes the open section when another opens. Default `"single"`. */
27
24
  type?: "single" | "multiple";
28
25
  /** Open at first render. A string, or several for `type: "multiple"`. */
@@ -33,3 +30,27 @@ export interface AccordionProps {
33
30
  class?: Reactive<string>;
34
31
  }
35
32
  export declare const Accordion: (props?: AccordionProps | undefined) => import("@c9up/aurora").TemplateResult;
33
+ export interface AccordionItemProps {
34
+ /** Stable key. Used for the open-state set and for the ARIA ids. */
35
+ value: string;
36
+ disabled?: boolean;
37
+ class?: Reactive<string>;
38
+ children?: Parts;
39
+ }
40
+ /**
41
+ * One section.
42
+ *
43
+ * Provides a second context of its own, so the trigger and the panel inside it
44
+ * share their ids without the caller repeating the value on each.
45
+ */
46
+ export declare const AccordionItem: (props?: AccordionItemProps | undefined) => import("@c9up/aurora").TemplateResult;
47
+ export interface AccordionTriggerProps {
48
+ children?: Slot;
49
+ class?: Reactive<string>;
50
+ }
51
+ export declare const AccordionTrigger: (props?: AccordionTriggerProps | undefined) => import("@c9up/aurora").TemplateResult;
52
+ export interface AccordionContentProps {
53
+ children?: Slot;
54
+ class?: Reactive<string>;
55
+ }
56
+ export declare const AccordionContent: (props?: AccordionContentProps | undefined) => import("@c9up/aurora").TemplateResult;