@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,6 +1,23 @@
1
1
  /**
2
2
  * Tooltip — a label that appears on hover or focus.
3
3
  *
4
+ * Four parts, as upstream: a `TooltipProvider` that owns the timing for a
5
+ * group, a `Tooltip` that owns one tooltip's state, a `TooltipTrigger` and a
6
+ * `TooltipContent`. The state lives in the middle and both ends read it
7
+ * through context, which is why the trigger can describe content it never
8
+ * sees.
9
+ *
10
+ * TooltipProvider({ children: () => html`
11
+ * ${Tooltip({ children: () => html`
12
+ * ${TooltipTrigger({ children: () => Button({ children: "Save" }) })}
13
+ * ${TooltipContent({ children: "Saves and closes" })}
14
+ * ` })}
15
+ * ` })
16
+ *
17
+ * The `() =>` is not decoration. Aurora builds eagerly, so children handed
18
+ * over already built would have run before the provider existed and found no
19
+ * context — see `Parts`.
20
+ *
4
21
  * Three rules separate a usable tooltip from an irritating one, and all three
5
22
  * are about time rather than appearance:
6
23
  *
@@ -11,8 +28,9 @@
11
28
  * halfway.
12
29
  * - **No delay between neighbours.** Once one tooltip is showing, the next one
13
30
  * appears instantly; the user has clearly decided to browse the toolbar, and
14
- * re-serving the delay each time makes the interface feel stuck. That is why
15
- * `lastClosedAt` is module state and not per-component.
31
+ * re-serving the delay each time makes the interface feel stuck. That is
32
+ * what `skipDelayDuration` bounds, and why the window belongs to the
33
+ * provider rather than to either tooltip.
16
34
  *
17
35
  * Focus opens it with no delay at all. A keyboard user landing on a control
18
36
  * has already committed to it, and a delay just looks like lag.
@@ -22,103 +40,335 @@
22
40
  * only by its tooltip is unlabelled to anything that does not hover.
23
41
  */
24
42
 
25
- import { component, html, onUnmount, signal } from "@c9up/aurora";
26
- import type { Child } from "../lib/children.js";
27
- import { type Slot, slot } from "../lib/children.js";
43
+ import {
44
+ component,
45
+ createContext,
46
+ html,
47
+ inject,
48
+ onUnmount,
49
+ provide,
50
+ signal,
51
+ type TemplateResult,
52
+ } from "@c9up/aurora";
53
+ import type { Child, Parts, Slot } from "../lib/children.js";
54
+ import { slot } from "../lib/children.js";
28
55
  import { cn } from "../lib/cn.js";
29
56
  import { uid } from "../lib/id.js";
30
- import { fadeInOut } from "../lib/motion.js";
57
+ import { slideInFromSide, zoomInOut } from "../lib/motion.js";
31
58
  import { type Reactive, read } from "../lib/props.js";
32
- import type { Placement } from "../primitives/floating.js";
59
+ import type { Align, Placement, Side } from "../primitives/floating.js";
33
60
  import { floatingSurface } from "../primitives/floatingSurface.js";
34
61
 
35
- const OPEN_DELAY_MS = 500;
62
+ /** Upstream's default once shadcn has overridden Radix's 700ms. */
63
+ const DEFAULT_DELAY_MS = 0;
64
+ /** Radix's `skipDelayDuration`. */
65
+ const DEFAULT_SKIP_DELAY_MS = 300;
36
66
  const CLOSE_DELAY_MS = 150;
37
- /** How long after one closes that the next opens instantly. */
38
- const GRACE_MS = 300;
39
67
 
40
- /** Shared across every tooltip on the page — see the "no delay" rule above. */
41
- let lastClosedAt = 0;
68
+ interface TooltipGroup {
69
+ readonly delayDuration: number;
70
+ readonly skipDelayDuration: number;
71
+ readonly disableHoverableContent: boolean;
72
+ /** When the last tooltip in this group closed — the skip window. */
73
+ lastClosedAt: number;
74
+ }
75
+
76
+ /**
77
+ * NAMED DEVIATION — a default, where Radix throws without a `TooltipProvider`.
78
+ *
79
+ * Radix raises so the skip-delay grouping is always an explicit choice. Here
80
+ * the default IS a group: one page-wide window, which is what nebula did
81
+ * before the parts were split out and what a single tooltip on a page wants.
82
+ * Wrapping a toolbar in a provider still gives it a window of its own, so
83
+ * nothing is lost — only the raise.
84
+ */
85
+ const TooltipProviderContext = createContext<TooltipGroup>("TooltipProvider", {
86
+ delayDuration: DEFAULT_DELAY_MS,
87
+ skipDelayDuration: DEFAULT_SKIP_DELAY_MS,
88
+ disableHoverableContent: false,
89
+ lastClosedAt: 0,
90
+ });
91
+
92
+ interface RegisteredContent {
93
+ readonly render: () => Child;
94
+ readonly side: Side;
95
+ readonly align: Align;
96
+ readonly sideOffset: number;
97
+ readonly class?: Reactive<string>;
98
+ }
99
+
100
+ interface TooltipApi {
101
+ readonly triggerId: string;
102
+ readonly contentId: string;
103
+ /** An accessor, not a signal: controlled tooltips read the caller's prop. */
104
+ readonly open: () => boolean;
105
+ /** Hover opens after the group's delay; focus opens at once. */
106
+ requestOpen(immediate: boolean): void;
107
+ requestClose(): void;
108
+ cancelPending(): void;
109
+ register(content: RegisteredContent): void;
110
+ }
111
+
112
+ const TooltipContext = createContext<TooltipApi>("Tooltip");
113
+
114
+ export interface TooltipProviderProps {
115
+ /** Hover delay before opening, in ms. */
116
+ delayDuration?: number;
117
+ /** How long after one closes that the next in the group opens instantly. */
118
+ skipDelayDuration?: number;
119
+ /** Close as soon as the pointer leaves the trigger, even towards the tooltip. */
120
+ disableHoverableContent?: boolean;
121
+ children?: Parts;
122
+ }
123
+
124
+ /**
125
+ * Timing shared by every tooltip inside it.
126
+ *
127
+ * Renders no element of its own, exactly as upstream: it is a context holder,
128
+ * and giving it a wrapper would put a box into a layout that did not ask for
129
+ * one. `data-slot="tooltip-provider"` is inert upstream for the same reason.
130
+ */
131
+ export const TooltipProvider = component<TooltipProviderProps>((props) => {
132
+ provide<TooltipGroup>(TooltipProviderContext, {
133
+ delayDuration: props.delayDuration ?? DEFAULT_DELAY_MS,
134
+ skipDelayDuration: props.skipDelayDuration ?? DEFAULT_SKIP_DELAY_MS,
135
+ disableHoverableContent: props.disableHoverableContent ?? false,
136
+ lastClosedAt: 0,
137
+ });
138
+ return html`${props.children?.()}`;
139
+ });
42
140
 
43
141
  export interface TooltipProps {
44
- /** The control being described. */
45
- trigger?: Slot;
46
- /** The tooltip text. Keep it to a phrase. */
47
- content?: Child;
48
- placement?: Placement;
49
- openDelay?: number;
50
- closeDelay?: number;
51
- class?: Reactive<string>;
52
- contentClass?: Reactive<string>;
142
+ /** Controlled state. Omit to let the tooltip own it. */
143
+ open?: Reactive<boolean>;
144
+ defaultOpen?: boolean;
145
+ onOpenChange?: (open: boolean) => void;
146
+ /** Overrides the provider's delay for this tooltip only. */
147
+ delayDuration?: number;
148
+ disableHoverableContent?: boolean;
149
+ children?: Parts;
53
150
  }
54
151
 
152
+ /**
153
+ * One tooltip: the state its trigger and its content both read.
154
+ *
155
+ * Renders no element of its own — see `TooltipProvider`. The parts are built
156
+ * here, inside setup, which is what puts the context within their reach; the
157
+ * content registers itself during that call, so the floating surface can be
158
+ * wired straight afterwards.
159
+ */
55
160
  export const Tooltip = component<TooltipProps>((props) => {
161
+ const group = inject(TooltipProviderContext);
56
162
  const triggerId = uid("tooltip-trigger");
57
163
  const contentId = uid("tooltip-content");
58
- const open = signal(false);
59
-
164
+ const internal = signal(props.defaultOpen ?? false);
165
+ let content: RegisteredContent | undefined;
60
166
  let timer: ReturnType<typeof setTimeout> | undefined;
61
167
 
62
- function clear(): void {
168
+ /** Controlled when `open` reads as anything but `undefined`, on every read. */
169
+ function isOpen(): boolean {
170
+ const external = read(props.open);
171
+ return external === undefined ? internal() : external;
172
+ }
173
+
174
+ function setOpen(next: boolean): void {
175
+ // Written even when controlled: the caller may ignore `onOpenChange` and
176
+ // leave its own state put, and the internal value has to stay in step for
177
+ // the moment it stops controlling.
178
+ internal(next);
179
+ props.onOpenChange?.(next);
180
+ }
181
+
182
+ function cancelPending(): void {
63
183
  if (timer !== undefined) clearTimeout(timer);
64
184
  timer = undefined;
65
185
  }
66
186
 
67
- function scheduleOpen(immediate: boolean): void {
68
- clear();
69
- const withinGrace = Date.now() - lastClosedAt < GRACE_MS;
187
+ function requestOpen(immediate: boolean): void {
188
+ cancelPending();
189
+ const withinSkipWindow =
190
+ Date.now() - group.lastClosedAt < group.skipDelayDuration;
70
191
  const delay =
71
- immediate || withinGrace ? 0 : (props.openDelay ?? OPEN_DELAY_MS);
192
+ immediate || withinSkipWindow
193
+ ? 0
194
+ : (props.delayDuration ?? group.delayDuration);
72
195
  if (delay === 0) {
73
- open(true);
196
+ setOpen(true);
74
197
  return;
75
198
  }
76
- timer = setTimeout(() => open(true), delay);
199
+ timer = setTimeout(() => setOpen(true), delay);
77
200
  }
78
201
 
79
- function scheduleClose(): void {
80
- clear();
202
+ function requestClose(): void {
203
+ cancelPending();
81
204
  timer = setTimeout(() => {
82
- open(false);
83
- lastClosedAt = Date.now();
84
- }, props.closeDelay ?? CLOSE_DELAY_MS);
205
+ setOpen(false);
206
+ group.lastClosedAt = Date.now();
207
+ }, CLOSE_DELAY_MS);
85
208
  }
86
209
 
87
- onUnmount(clear);
210
+ onUnmount(cancelPending);
88
211
 
89
- floatingSurface({
90
- anchor: () => document.getElementById(triggerId),
91
- open: () => open(),
92
- onClose: () => {
93
- clear();
94
- open(false);
212
+ provide<TooltipApi>(TooltipContext, {
213
+ triggerId,
214
+ contentId,
215
+ open: isOpen,
216
+ requestOpen,
217
+ requestClose,
218
+ cancelPending,
219
+ register(registered) {
220
+ content = registered;
95
221
  },
96
- placement: props.placement ?? "top",
97
- offset: 6,
98
- outsidePointer: false,
99
- content: () =>
100
- html`<div
101
- data-slot="tooltip-content"
102
- id="${contentId}"
103
- role="tooltip"
104
- class="${cn(
105
- "bg-primary text-primary-foreground z-50 w-fit rounded-md px-3 py-1.5 text-xs text-balance",
106
- fadeInOut,
107
- read(props.contentClass),
108
- )}"
109
- @pointerenter="${clear}"
110
- @pointerleave="${scheduleClose}"
111
- >${props.content}</div>`,
112
222
  });
113
223
 
224
+ // Built HERE so the parts see the context, and so the content has
225
+ // registered by the time the surface below needs it.
226
+ const parts = props.children?.();
227
+
228
+ if (content !== undefined) {
229
+ const registered = content;
230
+ const placement: Placement =
231
+ registered.align === "center"
232
+ ? registered.side
233
+ : `${registered.side}-${registered.align}`;
234
+ floatingSurface({
235
+ anchor: () => document.getElementById(triggerId),
236
+ open: isOpen,
237
+ onClose: () => {
238
+ cancelPending();
239
+ setOpen(false);
240
+ },
241
+ placement,
242
+ offset: registered.sideOffset,
243
+ arrowSize: ARROW_SIZE_PX,
244
+ arrow: (element) => element.querySelector('[data-slot="tooltip-arrow"]'),
245
+ // A tooltip is not a layer the pointer dismisses: it closes because
246
+ // the pointer left, which the trigger's own handlers already say.
247
+ outsidePointer: false,
248
+ content: () =>
249
+ renderContent(registered, contentId, {
250
+ hoverable: !(
251
+ props.disableHoverableContent ?? group.disableHoverableContent
252
+ ),
253
+ cancelPending,
254
+ requestClose,
255
+ }),
256
+ });
257
+ }
258
+
259
+ return html`${parts}`;
260
+ });
261
+
262
+ export interface TooltipTriggerProps {
263
+ children?: Slot;
264
+ class?: Reactive<string>;
265
+ }
266
+
267
+ /**
268
+ * The control being described.
269
+ *
270
+ * NAMED DEVIATION — a wrapping `<span>`, where upstream is used as
271
+ * `<TooltipTrigger asChild>` and merges onto the control itself. `asChild`
272
+ * needs an element to merge INTO, and Aurora has no element until the template
273
+ * is rendered; a `<button>` wrapper would nest a button inside a button, which
274
+ * is invalid and unfocusable. `inline-flex` keeps the wrapper out of the
275
+ * layout. Focus still opens it because `focusin` bubbles out of the control.
276
+ */
277
+ export const TooltipTrigger = component<TooltipTriggerProps>((props) => {
278
+ const tooltip = inject(TooltipContext);
114
279
  return html`<span
115
280
  data-slot="tooltip-trigger"
116
- id="${triggerId}"
117
- aria-describedby="${() => (open() ? contentId : undefined)}"
281
+ id="${tooltip.triggerId}"
282
+ data-state="${() => (tooltip.open() ? "open" : "closed")}"
283
+ aria-describedby="${() => (tooltip.open() ? tooltip.contentId : undefined)}"
118
284
  class="${() => cn("inline-flex", read(props.class))}"
119
- @pointerenter="${() => scheduleOpen(false)}"
120
- @pointerleave="${scheduleClose}"
121
- @focusin="${() => scheduleOpen(true)}"
122
- @focusout="${scheduleClose}"
123
- >${slot(props.trigger)}</span>`;
285
+ @pointerenter="${() => tooltip.requestOpen(false)}"
286
+ @pointerleave="${() => tooltip.requestClose()}"
287
+ @focusin="${() => tooltip.requestOpen(true)}"
288
+ @focusout="${() => tooltip.requestClose()}"
289
+ >${slot(props.children)}</span>`;
290
+ });
291
+
292
+ export interface TooltipContentProps {
293
+ children?: Child;
294
+ /** Which edge of the trigger to sit on. Flips when there is no room. */
295
+ side?: Side;
296
+ align?: Align;
297
+ sideOffset?: number;
298
+ class?: Reactive<string>;
299
+ }
300
+
301
+ /**
302
+ * The label itself.
303
+ *
304
+ * Renders nothing where it is written: the tooltip portals its content out of
305
+ * the tree when it opens, so this registers what to build and returns an empty
306
+ * template. Writing it inside `Tooltip` — rather than passing content as a
307
+ * prop — is what keeps the call site shaped like the thing it describes.
308
+ */
309
+ export const TooltipContent = component<TooltipContentProps>((props) => {
310
+ const tooltip = inject(TooltipContext);
311
+ tooltip.register({
312
+ render: () => props.children,
313
+ side: props.side ?? "top",
314
+ align: props.align ?? "center",
315
+ sideOffset: props.sideOffset ?? 0,
316
+ class: props.class,
317
+ });
318
+ return html``;
124
319
  });
320
+
321
+ /** `size-2.5` in pixels — what the positioner centres on the anchor. */
322
+ const ARROW_SIZE_PX = 10;
323
+
324
+ const CONTENT_CLASSES =
325
+ "bg-foreground text-background z-50 w-fit origin-(--nebula-transform-origin) rounded-md px-3 py-1.5 text-xs text-balance";
326
+
327
+ /**
328
+ * NAMED DEVIATION — the arrow is placed per side here, where shadcn writes one
329
+ * `translate-y`. Radix wraps its arrow in a span the popper rotates to face the
330
+ * anchor, so upstream's single nudge is applied in an already-oriented frame.
331
+ * `autoPosition` positions the arrow along the CROSS axis only, by design, and
332
+ * leaves the facing edge to CSS — so the edge has to be named for each side.
333
+ * The look is upstream's: a 10px square, rotated, softly rounded.
334
+ */
335
+ const ARROW_CLASSES = [
336
+ "bg-foreground fill-foreground absolute z-50 size-2.5 rotate-45 rounded-[2px]",
337
+ "data-[side=top]:bottom-0 data-[side=top]:translate-y-[calc(50%_-_2px)]",
338
+ "data-[side=bottom]:top-0 data-[side=bottom]:translate-y-[calc(-50%_+_2px)]",
339
+ "data-[side=left]:right-0 data-[side=left]:translate-x-[calc(50%_-_2px)]",
340
+ "data-[side=right]:left-0 data-[side=right]:translate-x-[calc(-50%_+_2px)]",
341
+ ].join(" ");
342
+
343
+ interface ContentHandlers {
344
+ readonly hoverable: boolean;
345
+ cancelPending(): void;
346
+ requestClose(): void;
347
+ }
348
+
349
+ function renderContent(
350
+ registered: RegisteredContent,
351
+ contentId: string,
352
+ handlers: ContentHandlers,
353
+ ): TemplateResult {
354
+ // Hoverable content keeps the tooltip open while the pointer is inside it,
355
+ // which is the only way to read a long one or click a link in it.
356
+ const enter = handlers.hoverable ? () => handlers.cancelPending() : undefined;
357
+ const leave = handlers.hoverable ? () => handlers.requestClose() : undefined;
358
+ return html`<div
359
+ data-slot="tooltip-content"
360
+ id="${contentId}"
361
+ role="tooltip"
362
+ class="${cn(
363
+ CONTENT_CLASSES,
364
+ zoomInOut,
365
+ slideInFromSide,
366
+ read(registered.class),
367
+ )}"
368
+ @pointerenter="${enter}"
369
+ @pointerleave="${leave}"
370
+ >${registered.render()}<span
371
+ data-slot="tooltip-arrow"
372
+ class="${ARROW_CLASSES}"
373
+ ></span></div>`;
374
+ }