@opsinjs/react 0.0.0-stage → 0.1.0

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 (266) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/LICENSE +21 -0
  3. package/README.md +114 -2
  4. package/dist/components/accordion.d.ts +82 -0
  5. package/dist/components/accordion.d.ts.map +1 -0
  6. package/dist/components/accordion.js +154 -0
  7. package/dist/components/accordion.js.map +1 -0
  8. package/dist/components/alert-banner.d.ts +291 -0
  9. package/dist/components/alert-banner.d.ts.map +1 -0
  10. package/dist/components/alert-banner.js +529 -0
  11. package/dist/components/alert-banner.js.map +1 -0
  12. package/dist/components/avatar.d.ts +45 -0
  13. package/dist/components/avatar.d.ts.map +1 -0
  14. package/dist/components/avatar.js +159 -0
  15. package/dist/components/avatar.js.map +1 -0
  16. package/dist/components/badge.d.ts +78 -0
  17. package/dist/components/badge.d.ts.map +1 -0
  18. package/dist/components/badge.js +32 -0
  19. package/dist/components/badge.js.map +1 -0
  20. package/dist/components/body-map.d.ts +51 -0
  21. package/dist/components/body-map.d.ts.map +1 -0
  22. package/dist/components/body-map.js +190 -0
  23. package/dist/components/body-map.js.map +1 -0
  24. package/dist/components/button.d.ts +260 -0
  25. package/dist/components/button.d.ts.map +1 -0
  26. package/dist/components/button.js +609 -0
  27. package/dist/components/button.js.map +1 -0
  28. package/dist/components/callout.d.ts +99 -0
  29. package/dist/components/callout.d.ts.map +1 -0
  30. package/dist/components/callout.js +285 -0
  31. package/dist/components/callout.js.map +1 -0
  32. package/dist/components/card.d.ts +156 -0
  33. package/dist/components/card.d.ts.map +1 -0
  34. package/dist/components/card.js +396 -0
  35. package/dist/components/card.js.map +1 -0
  36. package/dist/components/care-card.d.ts +182 -0
  37. package/dist/components/care-card.d.ts.map +1 -0
  38. package/dist/components/care-card.js +544 -0
  39. package/dist/components/care-card.js.map +1 -0
  40. package/dist/components/checkbox.d.ts +58 -0
  41. package/dist/components/checkbox.d.ts.map +1 -0
  42. package/dist/components/checkbox.js +167 -0
  43. package/dist/components/checkbox.js.map +1 -0
  44. package/dist/components/combobox.d.ts +71 -0
  45. package/dist/components/combobox.d.ts.map +1 -0
  46. package/dist/components/combobox.js +204 -0
  47. package/dist/components/combobox.js.map +1 -0
  48. package/dist/components/consent-sheet.d.ts +186 -0
  49. package/dist/components/consent-sheet.d.ts.map +1 -0
  50. package/dist/components/consent-sheet.js +452 -0
  51. package/dist/components/consent-sheet.js.map +1 -0
  52. package/dist/components/dialog.d.ts +108 -0
  53. package/dist/components/dialog.d.ts.map +1 -0
  54. package/dist/components/dialog.js +573 -0
  55. package/dist/components/dialog.js.map +1 -0
  56. package/dist/components/disclaimer-note.d.ts +144 -0
  57. package/dist/components/disclaimer-note.d.ts.map +1 -0
  58. package/dist/components/disclaimer-note.js +486 -0
  59. package/dist/components/disclaimer-note.js.map +1 -0
  60. package/dist/components/divider.d.ts +76 -0
  61. package/dist/components/divider.d.ts.map +1 -0
  62. package/dist/components/divider.js +101 -0
  63. package/dist/components/divider.js.map +1 -0
  64. package/dist/components/dose-tracker.d.ts +137 -0
  65. package/dist/components/dose-tracker.d.ts.map +1 -0
  66. package/dist/components/dose-tracker.js +154 -0
  67. package/dist/components/dose-tracker.js.map +1 -0
  68. package/dist/components/empty-state.d.ts +171 -0
  69. package/dist/components/empty-state.d.ts.map +1 -0
  70. package/dist/components/empty-state.js +387 -0
  71. package/dist/components/empty-state.js.map +1 -0
  72. package/dist/components/field.d.ts +195 -0
  73. package/dist/components/field.d.ts.map +1 -0
  74. package/dist/components/field.js +282 -0
  75. package/dist/components/field.js.map +1 -0
  76. package/dist/components/goal-ring.d.ts +114 -0
  77. package/dist/components/goal-ring.d.ts.map +1 -0
  78. package/dist/components/goal-ring.js +254 -0
  79. package/dist/components/goal-ring.js.map +1 -0
  80. package/dist/components/icon-button.d.ts +124 -0
  81. package/dist/components/icon-button.d.ts.map +1 -0
  82. package/dist/components/icon-button.js +113 -0
  83. package/dist/components/icon-button.js.map +1 -0
  84. package/dist/components/link.d.ts +122 -0
  85. package/dist/components/link.d.ts.map +1 -0
  86. package/dist/components/link.js +164 -0
  87. package/dist/components/link.js.map +1 -0
  88. package/dist/components/log-sheet.d.ts +259 -0
  89. package/dist/components/log-sheet.d.ts.map +1 -0
  90. package/dist/components/log-sheet.js +437 -0
  91. package/dist/components/log-sheet.js.map +1 -0
  92. package/dist/components/menu.d.ts +69 -0
  93. package/dist/components/menu.d.ts.map +1 -0
  94. package/dist/components/menu.js +190 -0
  95. package/dist/components/menu.js.map +1 -0
  96. package/dist/components/metric-tile.d.ts +301 -0
  97. package/dist/components/metric-tile.d.ts.map +1 -0
  98. package/dist/components/metric-tile.js +533 -0
  99. package/dist/components/metric-tile.js.map +1 -0
  100. package/dist/components/number-field.d.ts +62 -0
  101. package/dist/components/number-field.d.ts.map +1 -0
  102. package/dist/components/number-field.js +134 -0
  103. package/dist/components/number-field.js.map +1 -0
  104. package/dist/components/popover.d.ts +70 -0
  105. package/dist/components/popover.d.ts.map +1 -0
  106. package/dist/components/popover.js +174 -0
  107. package/dist/components/popover.js.map +1 -0
  108. package/dist/components/progress.d.ts +83 -0
  109. package/dist/components/progress.d.ts.map +1 -0
  110. package/dist/components/progress.js +140 -0
  111. package/dist/components/progress.js.map +1 -0
  112. package/dist/components/questionnaire.d.ts +123 -0
  113. package/dist/components/questionnaire.d.ts.map +1 -0
  114. package/dist/components/questionnaire.js +148 -0
  115. package/dist/components/questionnaire.js.map +1 -0
  116. package/dist/components/radio-group.d.ts +66 -0
  117. package/dist/components/radio-group.d.ts.map +1 -0
  118. package/dist/components/radio-group.js +186 -0
  119. package/dist/components/radio-group.js.map +1 -0
  120. package/dist/components/range-bar.d.ts +172 -0
  121. package/dist/components/range-bar.d.ts.map +1 -0
  122. package/dist/components/range-bar.js +578 -0
  123. package/dist/components/range-bar.js.map +1 -0
  124. package/dist/components/range-legend.d.ts +97 -0
  125. package/dist/components/range-legend.d.ts.map +1 -0
  126. package/dist/components/range-legend.js +166 -0
  127. package/dist/components/range-legend.js.map +1 -0
  128. package/dist/components/reading-input.d.ts +225 -0
  129. package/dist/components/reading-input.d.ts.map +1 -0
  130. package/dist/components/reading-input.js +651 -0
  131. package/dist/components/reading-input.js.map +1 -0
  132. package/dist/components/relative-time.d.ts +177 -0
  133. package/dist/components/relative-time.d.ts.map +1 -0
  134. package/dist/components/relative-time.js +603 -0
  135. package/dist/components/relative-time.js.map +1 -0
  136. package/dist/components/result-card.d.ts +319 -0
  137. package/dist/components/result-card.d.ts.map +1 -0
  138. package/dist/components/result-card.js +614 -0
  139. package/dist/components/result-card.js.map +1 -0
  140. package/dist/components/scale-input.d.ts +58 -0
  141. package/dist/components/scale-input.d.ts.map +1 -0
  142. package/dist/components/scale-input.js +170 -0
  143. package/dist/components/scale-input.js.map +1 -0
  144. package/dist/components/score-dial.d.ts +205 -0
  145. package/dist/components/score-dial.d.ts.map +1 -0
  146. package/dist/components/score-dial.js +728 -0
  147. package/dist/components/score-dial.js.map +1 -0
  148. package/dist/components/scroll-area.d.ts +38 -0
  149. package/dist/components/scroll-area.d.ts.map +1 -0
  150. package/dist/components/scroll-area.js +138 -0
  151. package/dist/components/scroll-area.js.map +1 -0
  152. package/dist/components/segmented-control.d.ts +69 -0
  153. package/dist/components/segmented-control.d.ts.map +1 -0
  154. package/dist/components/segmented-control.js +259 -0
  155. package/dist/components/segmented-control.js.map +1 -0
  156. package/dist/components/select.d.ts +72 -0
  157. package/dist/components/select.d.ts.map +1 -0
  158. package/dist/components/select.js +205 -0
  159. package/dist/components/select.js.map +1 -0
  160. package/dist/components/sheet.d.ts +192 -0
  161. package/dist/components/sheet.d.ts.map +1 -0
  162. package/dist/components/sheet.js +952 -0
  163. package/dist/components/sheet.js.map +1 -0
  164. package/dist/components/skeleton.d.ts +104 -0
  165. package/dist/components/skeleton.d.ts.map +1 -0
  166. package/dist/components/skeleton.js +266 -0
  167. package/dist/components/skeleton.js.map +1 -0
  168. package/dist/components/slider.d.ts +55 -0
  169. package/dist/components/slider.d.ts.map +1 -0
  170. package/dist/components/slider.js +170 -0
  171. package/dist/components/slider.js.map +1 -0
  172. package/dist/components/source-citation.d.ts +127 -0
  173. package/dist/components/source-citation.d.ts.map +1 -0
  174. package/dist/components/source-citation.js +391 -0
  175. package/dist/components/source-citation.js.map +1 -0
  176. package/dist/components/spinner.d.ts +86 -0
  177. package/dist/components/spinner.d.ts.map +1 -0
  178. package/dist/components/spinner.js +97 -0
  179. package/dist/components/spinner.js.map +1 -0
  180. package/dist/components/status-pill.d.ts +90 -0
  181. package/dist/components/status-pill.d.ts.map +1 -0
  182. package/dist/components/status-pill.js +259 -0
  183. package/dist/components/status-pill.js.map +1 -0
  184. package/dist/components/stepper.d.ts +99 -0
  185. package/dist/components/stepper.d.ts.map +1 -0
  186. package/dist/components/stepper.js +152 -0
  187. package/dist/components/stepper.js.map +1 -0
  188. package/dist/components/surface.d.ts +92 -0
  189. package/dist/components/surface.d.ts.map +1 -0
  190. package/dist/components/surface.js +261 -0
  191. package/dist/components/surface.js.map +1 -0
  192. package/dist/components/switch.d.ts +48 -0
  193. package/dist/components/switch.d.ts.map +1 -0
  194. package/dist/components/switch.js +152 -0
  195. package/dist/components/switch.js.map +1 -0
  196. package/dist/components/symptom-picker.d.ts +69 -0
  197. package/dist/components/symptom-picker.d.ts.map +1 -0
  198. package/dist/components/symptom-picker.js +170 -0
  199. package/dist/components/symptom-picker.js.map +1 -0
  200. package/dist/components/tab-bar.d.ts +110 -0
  201. package/dist/components/tab-bar.d.ts.map +1 -0
  202. package/dist/components/tab-bar.js +118 -0
  203. package/dist/components/tab-bar.js.map +1 -0
  204. package/dist/components/table.d.ts +117 -0
  205. package/dist/components/table.d.ts.map +1 -0
  206. package/dist/components/table.js +65 -0
  207. package/dist/components/table.js.map +1 -0
  208. package/dist/components/tabs.d.ts +106 -0
  209. package/dist/components/tabs.d.ts.map +1 -0
  210. package/dist/components/tabs.js +136 -0
  211. package/dist/components/tabs.js.map +1 -0
  212. package/dist/components/term.d.ts +243 -0
  213. package/dist/components/term.d.ts.map +1 -0
  214. package/dist/components/term.js +562 -0
  215. package/dist/components/term.js.map +1 -0
  216. package/dist/components/textarea.d.ts +157 -0
  217. package/dist/components/textarea.d.ts.map +1 -0
  218. package/dist/components/textarea.js +66 -0
  219. package/dist/components/textarea.js.map +1 -0
  220. package/dist/components/timeline-entry.d.ts +99 -0
  221. package/dist/components/timeline-entry.d.ts.map +1 -0
  222. package/dist/components/timeline-entry.js +47 -0
  223. package/dist/components/timeline-entry.js.map +1 -0
  224. package/dist/components/toast.d.ts +80 -0
  225. package/dist/components/toast.d.ts.map +1 -0
  226. package/dist/components/toast.js +266 -0
  227. package/dist/components/toast.js.map +1 -0
  228. package/dist/components/tooltip.d.ts +48 -0
  229. package/dist/components/tooltip.d.ts.map +1 -0
  230. package/dist/components/tooltip.js +159 -0
  231. package/dist/components/tooltip.js.map +1 -0
  232. package/dist/components/trend-sparkline.d.ts +188 -0
  233. package/dist/components/trend-sparkline.d.ts.map +1 -0
  234. package/dist/components/trend-sparkline.js +796 -0
  235. package/dist/components/trend-sparkline.js.map +1 -0
  236. package/dist/components/value.d.ts +150 -0
  237. package/dist/components/value.d.ts.map +1 -0
  238. package/dist/components/value.js +402 -0
  239. package/dist/components/value.js.map +1 -0
  240. package/dist/components/visually-hidden.d.ts +61 -0
  241. package/dist/components/visually-hidden.d.ts.map +1 -0
  242. package/dist/components/visually-hidden.js +172 -0
  243. package/dist/components/visually-hidden.js.map +1 -0
  244. package/dist/index.d.ts +63 -0
  245. package/dist/index.d.ts.map +1 -0
  246. package/dist/index.js +72 -0
  247. package/dist/index.js.map +1 -0
  248. package/dist/opsinjs.d.ts +443 -0
  249. package/dist/opsinjs.d.ts.map +1 -0
  250. package/dist/opsinjs.js +906 -0
  251. package/dist/opsinjs.js.map +1 -0
  252. package/dist/status.d.ts +111 -0
  253. package/dist/status.d.ts.map +1 -0
  254. package/dist/status.js +125 -0
  255. package/dist/status.js.map +1 -0
  256. package/dist/styles.css +2 -0
  257. package/dist/utils.d.ts +20 -0
  258. package/dist/utils.d.ts.map +1 -0
  259. package/dist/utils.js +82 -0
  260. package/dist/utils.js.map +1 -0
  261. package/package.json +86 -3
  262. package/styles/base.css +132 -0
  263. package/styles/roles.css +412 -0
  264. package/styles/standalone.css +20 -0
  265. package/styles/tailwind.css +18 -0
  266. package/styles/theme.css +309 -0
@@ -0,0 +1,266 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ /**
4
+ * Toast is a brief, self-dismissing confirmation of the reader's OWN action.
5
+ * "Saved" is the whole of it: a note that the action they took has landed,
6
+ * shown for a few seconds at the edge of the screen and then gone.
7
+ *
8
+ * A MESSAGE THAT REMOVES ITSELF IS THE WRONG SHAPE FOR ANYTHING ABOUT SOMEONE'S
9
+ * HEALTH, AND THAT IS THE ONE RULE THIS COMPONENT EXISTS TO KEEP. The reader who
10
+ * most needs a piece of information is the one most likely to miss it: they look
11
+ * away, the phone is in a pocket, a screen reader is mid-sentence on something
12
+ * else, and the toast has already dismissed itself by the time attention comes
13
+ * back. So a Toast carries a confirmation of an action the reader themselves
14
+ * took, and it never carries a reading, a result, an alert, or anything a reader
15
+ * must not miss. A number they have to see goes on a surface that stays. A thing
16
+ * that needs their attention now is an AlertBanner. A standing explanation is a
17
+ * Callout. This component draws none of those, and its copy owns no clinical word.
18
+ *
19
+ * IT TAKES NEITHER COLOUR AXIS. A toast is a neutral acknowledgement, never a
20
+ * verdict, so it draws only the card material and a hairline and carries neither
21
+ * `data-status` nor `data-category`. A green "Saved" toast and a red error toast
22
+ * are the two ways a confirmation slips onto the status axis, and both are
23
+ * refused here: the surface is the same calm chrome whatever it confirms, and a
24
+ * state a reader must act on does not belong on a surface that erases itself.
25
+ *
26
+ * WHY IT IS A PROVIDER AND A VIEWPORT RATHER THAN A SINGLE ELEMENT. A toast is
27
+ * pushed imperatively, from an event handler, after the save resolves, so there
28
+ * is no element in the tree at the moment the decision to show one is made. Base
29
+ * UI answers that with a manager: `Toast.Provider` holds the queue,
30
+ * `Toast.useToastManager().add()` pushes onto it from anywhere inside the
31
+ * provider, and `Toast.Viewport` is the live region the queue renders into. This
32
+ * component wires all three together and renders its `children` INSIDE the
33
+ * provider, so a child of `<Toast>` can call `useToastManager()` and push a
34
+ * toast. The Root, Title, Description, Close and Action template is spelled once,
35
+ * here, so every toast a product raises looks the same and no caller assembles a
36
+ * surface by hand.
37
+ *
38
+ * WHAT BASE UI CARRIES, AND WHY THIS FILE DOES NOT RESTATE IT. The viewport is
39
+ * `role="region"` with `aria-live="polite"` and its own accessible name, it is
40
+ * reachable with F6, and each Root is a `role="dialog"` labelled by its title,
41
+ * so the close and the action inside it are ordinary focusable controls and
42
+ * Escape dismisses the focused toast. Those are behaviours of the primitive and
43
+ * this file adds nothing to them beyond a translatable name for the region and
44
+ * for the close control, because a hardcoded English word on the reader's way
45
+ * out of a message is a word some readers cannot use.
46
+ *
47
+ * IT IS A CLIENT COMPONENT, because the manager is a hook and the queue is state.
48
+ * A confirmation that appears in response to a click has behaviour to hydrate,
49
+ * which is the one case rule 3 of the source contract adds the directive for.
50
+ */
51
+ import { Toast as ToastPrimitive } from "@base-ui/react/toast";
52
+ import { X } from "lucide-react";
53
+ import { isDevelopment } from "../opsinjs.js";
54
+ import { cn } from "../utils.js";
55
+ /**
56
+ * The viewport placement per position, written out as literal class strings
57
+ * because Tailwind reads class names out of source as text and a computed
58
+ * `bottom-${x}` generates no CSS. Each pins the fixed viewport to an edge and
59
+ * aligns the stack towards that edge, so a toast enters from the side it will
60
+ * rest on. The centre placements translate by half their own width rather than
61
+ * guessing a margin.
62
+ */
63
+ const POSITION = {
64
+ "top-left": "top-0 left-0 items-start",
65
+ "top-center": "top-0 left-1/2 -translate-x-1/2 items-center",
66
+ "top-right": "top-0 right-0 items-end",
67
+ "bottom-left": "bottom-0 left-0 items-start",
68
+ "bottom-center": "bottom-0 left-1/2 -translate-x-1/2 items-center",
69
+ "bottom-right": "bottom-0 right-0 items-end",
70
+ };
71
+ /**
72
+ * The viewport, spelled once. A fixed column of toasts that does not itself
73
+ * capture pointer events, so a press over the empty area falls through to the
74
+ * page beneath rather than being swallowed by a full-height box; each toast
75
+ * turns pointer events back on for its own surface. `max-w-sm` keeps a toast to
76
+ * a readable measure on a wide screen while it fills the width of a phone less
77
+ * its own gutter, and the type step and space tokens let the whole thing grow
78
+ * with the reader's text size.
79
+ */
80
+ const VIEWPORT = "pointer-events-none fixed z-50 flex w-full max-w-sm flex-col gap-opsin-2 p-opsin-4";
81
+ /**
82
+ * One toast, spelled once.
83
+ *
84
+ * It is the `card` material with a hairline and the `overlay` rung's shadow, so
85
+ * it reads as a surface lifted a little off the page rather than as part of it, and
86
+ * it draws only neutral chrome so it can never be mistaken for a status surface.
87
+ * The shadow is a token, so a project installed without the generated token
88
+ * sheet loses the lift and keeps the hairline, which is the honest degradation
89
+ * for a decorative depth cue: the edge still defines the surface.
90
+ *
91
+ * The ink is written as the arbitrary property `[color:var(--foreground)]` and
92
+ * not `text-foreground`, for the reason the exemplars set out at length:
93
+ * tailwind-merge files a `text-*` colour in the same conflict group as a
94
+ * `text-opsin-*` step and drops one of them, and the arbitrary property lands in
95
+ * the `color` group instead so the ink survives beside the size.
96
+ */
97
+ const TOAST_ROOT = "pointer-events-auto flex w-full items-start gap-opsin-3 rounded-opsin-lg " +
98
+ "border border-edge bg-card p-opsin-4 shadow-[var(--opsin-material-raised-shadow)] " +
99
+ "[color:var(--foreground)]";
100
+ /**
101
+ * ARRIVE, the fifth of the five interaction motions (ADR 0031): how a toast
102
+ * comes in, how it follows a finger, and how it goes.
103
+ *
104
+ * It comes forward from the edge it is docked to. It rises a short fixed
105
+ * distance and grows from 0.96 while it fades in, on `spring-settle`, which
106
+ * tokens/motion.json names for chips appearing and disappearing and which
107
+ * passes its target by under 1% of the distance before it settles. The travel
108
+ * is short on purpose: the motion doctrine asks an arriving surface to come
109
+ * forward rather than slide across the screen, and a toast nobody summoned by
110
+ * dragging should not cross the page to get here. Which way it rises is the
111
+ * edge's, in `ARRIVE_FROM` below.
112
+ *
113
+ * While a finger is on it, it follows the finger exactly. Base UI already
114
+ * recognises the swipe and writes the distance into `--toast-swipe-movement-x`
115
+ * and `-y`, and before this file read them nothing on screen moved until the
116
+ * toast was gone, so the reader had no sign the gesture was taking. The
117
+ * resting `translate` is those two variables, and `data-[swiping]` drops the
118
+ * transition to zero so the surface stays under the finger with no lag. Let
119
+ * go short of the threshold and Base UI returns both to zero, so the toast
120
+ * springs home on the same `spring-settle`. Let go past it and the toast
121
+ * leaves the way it was thrown, `ENDING_SWIPE` below, accelerating on
122
+ * `ease-exit` over `duration-fast`, because a reader does not need to watch a
123
+ * dismissal finish. A toast that times out, or is closed with its control,
124
+ * fades and sinks back to 0.96 where it stands on the same exit timing.
125
+ *
126
+ * Nothing here carries meaning. A toast confirms the reader's own action and
127
+ * never a reading, so no motion in it touches a value or a status, and it is
128
+ * the reader's own throw, not the product, that sends it sideways.
129
+ *
130
+ * Under `prefers-reduced-motion: reduce` the arrival's travel and scale are
131
+ * pinned to rest, and `spring-settle` collapses in the generated sheet to a
132
+ * 100ms linear fade, so the toast still announces itself by appearing rather
133
+ * than being removed between frames, which is the fallback the motion
134
+ * doctrine asks for. The exit runs on `duration-fast`, which the product
135
+ * sheet collapses to 1ms, so its travel is never drawn. The finger-follow
136
+ * stays, because a surface moving with the reader's own finger is the
137
+ * reader's motion and not an animation. The travel is an arbitrary value with
138
+ * a literal fallback rather than a space-step utility, so how far the surface
139
+ * moves does not track the reader's density setting and survives a consumer
140
+ * who has no token sheet.
141
+ */
142
+ const MOTION = "[translate:var(--toast-swipe-movement-x,0px)_var(--toast-swipe-movement-y,0px)] " +
143
+ "transition-[opacity,translate,scale] duration-(--opsin-duration-spring-settle) ease-opsin-spring-settle " +
144
+ "data-[swiping]:duration-0 " +
145
+ "data-[starting-style]:opacity-0 data-[starting-style]:scale-96 " +
146
+ "data-[ending-style]:opacity-0 data-[ending-style]:scale-96 " +
147
+ "data-[ending-style]:duration-(--opsin-duration-fast) data-[ending-style]:ease-opsin-exit " +
148
+ "motion-reduce:data-[starting-style]:scale-100 motion-reduce:data-[ending-style]:scale-100";
149
+ /**
150
+ * Where a toast rises from, per edge: up from below for a stack docked to the
151
+ * bottom, down from above for one docked to the top. Spelled as two literal
152
+ * class strings because Tailwind reads class names out of source as text. The
153
+ * reduced-motion arm pins the start to rest, as `MOTION` sets out.
154
+ */
155
+ const ARRIVE_FROM = {
156
+ top: "data-[starting-style]:[translate:0_calc(var(--opsin-space-4,1rem)*-1)] " +
157
+ "motion-reduce:data-[starting-style]:[translate:0_0]",
158
+ bottom: "data-[starting-style]:[translate:0_var(--opsin-space-4,1rem)] " +
159
+ "motion-reduce:data-[starting-style]:[translate:0_0]",
160
+ };
161
+ /**
162
+ * Where a thrown toast goes: its own width or height plus a gutter past where
163
+ * the finger let it go, in the direction Base UI recorded on
164
+ * `data-swipe-direction`. The axis the throw was not along keeps whatever
165
+ * distance the finger had moved on it, so the toast leaves along the line it
166
+ * was travelling rather than snapping back onto the axis first.
167
+ */
168
+ const ENDING_SWIPE = "data-[ending-style]:data-[swipe-direction=right]:[translate:calc(100%+var(--opsin-space-6,1.5rem))_var(--toast-swipe-movement-y,0px)] " +
169
+ "data-[ending-style]:data-[swipe-direction=left]:[translate:calc(-100%-var(--opsin-space-6,1.5rem))_var(--toast-swipe-movement-y,0px)] " +
170
+ "data-[ending-style]:data-[swipe-direction=down]:[translate:var(--toast-swipe-movement-x,0px)_calc(100%+var(--opsin-space-6,1.5rem))] " +
171
+ "data-[ending-style]:data-[swipe-direction=up]:[translate:var(--toast-swipe-movement-x,0px)_calc(-100%-var(--opsin-space-6,1.5rem))]";
172
+ /**
173
+ * The directions a toast may be thrown, per position. Away from the edge it is
174
+ * docked to, never towards the middle of the screen, and sideways towards the
175
+ * corner it sits in; a centred stack can be thrown either way. Base UI's own
176
+ * default is down and right whatever the placement, which sent a toast docked
177
+ * to the top down across the page it was meant to stay out of.
178
+ */
179
+ const SWIPE = {
180
+ "top-left": ["up", "left"],
181
+ "top-center": ["up", "left", "right"],
182
+ "top-right": ["up", "right"],
183
+ "bottom-left": ["down", "left"],
184
+ "bottom-center": ["down", "left", "right"],
185
+ "bottom-right": ["down", "right"],
186
+ };
187
+ /**
188
+ * The press the toast's two controls share, which is Button's (ADR 0031): down
189
+ * to 0.97 on pointer-down over `duration-instant`, back on `spring-snap`, with
190
+ * the hover fill and the ink riding the same timing. It is spelled here rather
191
+ * than borrowed because neither control is a Button. Under reduced motion both
192
+ * durations collapse, so the press is a change of state within one frame.
193
+ */
194
+ const PRESS = "transition-[color,background-color,scale] duration-(--opsin-duration-spring-snap) ease-opsin-spring-snap " +
195
+ "active:scale-97 active:duration-(--opsin-duration-instant) active:ease-opsin-standard";
196
+ /**
197
+ * The optional action inside a toast, such as Undo. It is a quiet text control
198
+ * rather than a filled button, because a toast is a confirmation and its action
199
+ * is a second thought a reader may not take. It still floors its hit area at the
200
+ * 44px target minimum in rem, so it grows with the text size, and it carries its
201
+ * own focus ring so a project without the product stylesheet does not lose it.
202
+ */
203
+ const TOAST_ACTION = "mt-opsin-1 inline-flex items-center self-start rounded-opsin-sm px-opsin-1 " +
204
+ "min-h-(--opsin-target-minimum,2.75rem) text-opsin-footnote font-medium " +
205
+ "underline underline-offset-2 [color:var(--foreground)] cursor-pointer " +
206
+ `${PRESS} hover:bg-state-hover ` +
207
+ "focus-visible:outline-ring focus-visible:outline-[length:var(--opsin-border-focus,2px)] " +
208
+ "focus-visible:outline-offset-[var(--opsin-border-focus-offset,2px)]";
209
+ /**
210
+ * The close control, an icon button carrying the lucide X. Its ink is the muted
211
+ * role at rest and the full foreground on hover, so it sits quietly beside the
212
+ * title until the reader reaches for it. It floors both axes of its hit area at
213
+ * the 44px target minimum in rem, and the negative margins pull the larger box
214
+ * back so its glyph aligns to the title rather than sitting a target's padding
215
+ * out from the panel edge, without shrinking the hit area itself.
216
+ */
217
+ const TOAST_CLOSE = "-mt-opsin-2 -mr-opsin-2 inline-flex shrink-0 items-center justify-center rounded-opsin-sm " +
218
+ "min-h-(--opsin-target-minimum,2.75rem) min-w-(--opsin-target-minimum,2.75rem) " +
219
+ "text-opsin-body [color:var(--muted-foreground)] cursor-pointer " +
220
+ `${PRESS} ` +
221
+ "hover:bg-state-hover hover:[color:var(--foreground)] " +
222
+ "focus-visible:outline-ring focus-visible:outline-[length:var(--opsin-border-focus,2px)] " +
223
+ "focus-visible:outline-offset-[var(--opsin-border-focus-offset,2px)]";
224
+ /**
225
+ * Development warnings, said once per distinct offender. Nothing here has an
226
+ * `OpsinErrorCode`: the codes in `tokens/errors.json` describe mistakes a
227
+ * consumer makes with the clinical API, and a toast asserts nothing clinical, so
228
+ * minting one is not this file's to do. The exemplars keep the same small set
229
+ * for the same reason.
230
+ */
231
+ const warned = new Set();
232
+ function warnDev(key, message) {
233
+ if (!isDevelopment() || warned.has(key))
234
+ return;
235
+ warned.add(key);
236
+ console.warn(message);
237
+ }
238
+ /**
239
+ * The queue, rendered into the viewport. Kept internal rather than exported: it
240
+ * reads `useToastManager()`, which only resolves inside the provider its parent
241
+ * mounts, so it is never useful on its own and a consumer never reaches for it.
242
+ * A title, a description and an action are each drawn only when the pushed toast
243
+ * carries one, so an empty element is never announced.
244
+ */
245
+ function ToastList({ closeLabel, position }) {
246
+ const { toasts } = ToastPrimitive.useToastManager();
247
+ const edge = position.startsWith("top") ? "top" : "bottom";
248
+ return toasts.map((toast) => (_jsxs(ToastPrimitive.Root, { toast: toast, swipeDirection: SWIPE[position], "data-slot": "toast", className: cn(TOAST_ROOT, MOTION, ARRIVE_FROM[edge], ENDING_SWIPE), children: [_jsxs("div", { "data-slot": "toast-body", className: "flex min-w-0 flex-1 flex-col gap-opsin-1", children: [toast.title ? (_jsx(ToastPrimitive.Title, { "data-slot": "toast-title", className: "m-0 text-opsin-callout font-medium [color:var(--foreground)]" })) : null, toast.description ? (_jsx(ToastPrimitive.Description, { "data-slot": "toast-description", className: "m-0 text-opsin-footnote [color:var(--muted-foreground)]" })) : null, toast.actionProps ? (_jsx(ToastPrimitive.Action, { "data-slot": "toast-action", className: TOAST_ACTION })) : null] }), _jsx(ToastPrimitive.Close, { "data-slot": "toast-close", "aria-label": closeLabel, className: TOAST_CLOSE, children: _jsx(X, { "aria-hidden": "true", className: "size-[1em] shrink-0" }) })] }, toast.id)));
249
+ }
250
+ export function Toast({ children, position = "bottom-right", limit, timeout = 5000, label = "Notifications", closeLabel = "Dismiss", className, }) {
251
+ /* The default is applied here rather than in the destructuring above so the
252
+ count is not a bare `name = number` beside a name the threshold gate reads
253
+ as clinical. Three is a queue depth, not a reading, but the gate cannot tell
254
+ the two apart from the name, and it is right not to try. */
255
+ const shownAtOnce = limit ?? 3;
256
+ if (isDevelopment() && timeout === 0) {
257
+ warnDev("timeout-zero", "[opsinjs] <Toast timeout={0}> stops every toast dismissing itself, which " +
258
+ "turns a transient confirmation into a standing surface. A toast is for a " +
259
+ "brief acknowledgement of the reader's own action; a message that must " +
260
+ "stay because the reader has to act on it is an AlertBanner, and a " +
261
+ "standing explanation is a Callout. Leave the default timeout, or reach " +
262
+ "for the component whose job is to persist.");
263
+ }
264
+ return (_jsxs(ToastPrimitive.Provider, { limit: shownAtOnce, timeout: timeout, children: [children, _jsx(ToastPrimitive.Viewport, { "data-slot": "toast-viewport", "aria-label": label, className: cn(VIEWPORT, POSITION[position], className), children: _jsx(ToastList, { closeLabel: closeLabel, position: position }) })] }));
265
+ }
266
+ //# sourceMappingURL=toast.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toast.js","sourceRoot":"","sources":["../../src/components/toast.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AAEH,OAAO,EAAE,KAAK,IAAI,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAC9D,OAAO,EAAE,CAAC,EAA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EAAE,OAAO,aAC1D,QAAQ,EACT,KAAC,cAAc,CAAC,QAAQ,iBACZ,gBAAgB,gBACd,KAAK,EACjB,SAAS,EAAE,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,CAAC,YAEtD,KAAC,SAAS,IAAC,UAAU,EAAE,UAAU,EAAE,QAAQ,EAAE,QAAQ,GAAI,GACjC,IACF,CAC3B,CAAA;AACH,CAAC"}
@@ -0,0 +1,48 @@
1
+ import { type ReactElement, type ReactNode } from "react";
2
+ export interface TooltipProps {
3
+ /**
4
+ * The label the tooltip shows, and the whole of its content. Keep it to a
5
+ * phrase: a tooltip is a supplementary note, not a paragraph, and a long one
6
+ * is a block of text that belongs on the surface. It must be information a
7
+ * reader can do without, because a touch reader never sees it: a phone has no
8
+ * hover, so anything essential goes in the layout where every reader meets it.
9
+ * Required, because a tooltip with no content is a description that announces
10
+ * nothing.
11
+ */
12
+ content: ReactNode;
13
+ /**
14
+ * The trigger, rendered in place rather than wrapped. Whatever element the
15
+ * caller passes becomes the control the tooltip is attached to, keeping its
16
+ * own role, its own focus ring and its own target floor. It must be focusable,
17
+ * because focus is the only way a keyboard reader reaches the tooltip: pass a
18
+ * button, a link or another control, never a bare span of text. An icon-only
19
+ * trigger still needs its own accessible name through `aria-label`, because
20
+ * the tooltip is a description and not a name.
21
+ */
22
+ children: ReactElement;
23
+ /**
24
+ * Which edge of the trigger the popup prefers. Base UI flips to the opposite
25
+ * edge when the preferred one would push the popup off screen, so this is a
26
+ * preference rather than a guarantee. Defaults to `top`, which is the edge
27
+ * least likely to sit under a thumb reaching for the control.
28
+ */
29
+ side?: "top" | "bottom" | "left" | "right";
30
+ /**
31
+ * How long the pointer must rest on the trigger before the tooltip opens, in
32
+ * milliseconds. It does not delay the keyboard, where focus opens the tooltip
33
+ * at once, because a reader who has deliberately moved focus to a control is
34
+ * not resting a pointer by accident. Defaults to 600, which is long enough
35
+ * that a pointer passing across the control does not flash the label.
36
+ */
37
+ delay?: number;
38
+ /**
39
+ * Merged onto the popup surface. Placement offsets, a wider measure and the
40
+ * space around the label belong here. It is the one route by which colour can
41
+ * reach the popup, and the two-colour-axes rule applies to it in full: a
42
+ * tooltip takes neither a status nor a category tint. A class you pass wins
43
+ * over the surface's own where the two conflict, because it is merged last.
44
+ */
45
+ className?: string;
46
+ }
47
+ export declare function Tooltip({ content, children, side, delay, className }: TooltipProps): import("react").JSX.Element;
48
+ //# sourceMappingURL=tooltip.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tooltip.d.ts","sourceRoot":"","sources":["../../src/components/tooltip.tsx"],"names":[],"mappings":"AA8DA,OAAO,EAAE,KAAK,YAAY,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAA;AAgGzD,MAAM,WAAW,YAAY;IAC3B;;;;;;;;OAQG;IACH,OAAO,EAAE,SAAS,CAAA;IAClB;;;;;;;;OAQG;IACH,QAAQ,EAAE,YAAY,CAAA;IACtB;;;;;OAKG;IACH,IAAI,CAAC,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,CAAA;IAC1C;;;;;;OAMG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;IACd;;;;;;OAMG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,wBAAgB,OAAO,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAY,EAAE,KAAW,EAAE,SAAS,EAAE,EAAE,YAAY,+BA2BhG"}
@@ -0,0 +1,159 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ /**
4
+ * Tooltip is a short supplementary label that appears when a pointer rests on a
5
+ * control or a keyboard moves focus to it, and vanishes when either leaves.
6
+ *
7
+ * IT IS FOR THE LABEL YOU COULD DELETE, AND THAT CAVEAT IS THE WHOLE COMPONENT.
8
+ * opsinjs is a phone-first system for patient-facing screens, and a phone has no
9
+ * hover: a touch reader never rests a pointer on anything, so a touch reader
10
+ * never sees a tooltip at all. That is not a rendering gap this file can close,
11
+ * because there is no touch gesture that means "hover" without also meaning
12
+ * "activate". So the rule is stated rather than worked around. A tooltip may
13
+ * carry only information a reader can do without: the expansion of an icon a
14
+ * label already names, a unit already written beside the number, a hint that
15
+ * repeats what the surface says more briefly. Anything a touch reader actually
16
+ * needs goes on the screen, in the layout, where every reader meets it. A
17
+ * tooltip that carries the one fact the control cannot be used without is a
18
+ * defect on the device most readers hold, and no prop makes it safe.
19
+ *
20
+ * IT ADDS A DESCRIPTION, NEVER A NAME. Base UI wires the popup to the trigger
21
+ * through `aria-describedby`, so the label is announced after the control's own
22
+ * name, as a description, which is the register a supplementary note belongs in.
23
+ * The trigger keeps its own accessible name: an icon-only trigger still needs an
24
+ * `aria-label`, because a tooltip that vanished on blur is not a name a reader
25
+ * can rely on. This file cannot supply that name, because the name belongs to
26
+ * the control the caller passes as `children`, so the component documents the
27
+ * requirement and leaves the name where it lives.
28
+ *
29
+ * THE TRIGGER IS THE CALLER'S OWN ELEMENT, RENDERED IN PLACE. `children` is not
30
+ * wrapped in a button this file adds; it becomes the trigger through Base UI's
31
+ * `render` slot, so the pressable element stays the one the caller wrote, with
32
+ * its own focus ring, its own target floor and its own role. The one thing it
33
+ * must be is focusable, because focus is the only way a keyboard reader reaches
34
+ * a tooltip and the only way a reader without a mouse reaches it at all. A span
35
+ * of plain text is not focusable and gets no tooltip on the keyboard, so the
36
+ * caller passes a button, a link or a control, never a bare word.
37
+ *
38
+ * THE PROVIDER SITS INSIDE, ON PURPOSE AND AT A COST. Base UI's own guidance is
39
+ * to mount one `Tooltip.Provider` high in the tree so a shared timer coordinates
40
+ * every tooltip on a screen, and a product that shows many should still do that.
41
+ * This component mounts its own Provider so a single `<Tooltip>` works with
42
+ * nothing above it, which is what makes the demo render at `/view` and what lets
43
+ * a lone tooltip in a product work with nothing hoisted around it. The cost is
44
+ * that two of these standing side by side do not share the grouped-delay
45
+ * behaviour a single Provider would
46
+ * give them, so a screen with a row of them opens each on its own timer. That is
47
+ * named here rather than hidden, and a product with a row of tooltips hoists a
48
+ * Provider of its own above them.
49
+ *
50
+ * NEITHER COLOUR AXIS. A tooltip states nothing clinical: it names no level and
51
+ * no category, so it carries neither `data-status` nor `data-category` and draws
52
+ * only the neutral material surface, a card fill with a hairline. Colour that
53
+ * arrives through `className` is the caller's to keep off both axes, and the
54
+ * two-colour-axes rule applies to it in full.
55
+ *
56
+ * IT IS A CLIENT COMPONENT, because Base UI's tooltip primitive owns hover
57
+ * state, focus state, a delay timer and a portal, none of which exists on the
58
+ * server. There is no server-rendered half worth keeping: a tooltip that never
59
+ * opens is a description that never appears.
60
+ */
61
+ import { Tooltip as TooltipPrimitive } from "@base-ui/react/tooltip";
62
+ import { isDevelopment } from "../opsinjs.js";
63
+ import { cn } from "../utils.js";
64
+ /**
65
+ * UNFOLD, the fourth of the five interaction motions (ADR 0031), shared by every
66
+ * popup in the system so a tooltip opens the way a menu, a select, a combobox, a
67
+ * popover and a tooltip all do.
68
+ *
69
+ * The tooltip grows out of the control that opened it rather than appearing out
70
+ * of nowhere. `origin-(--transform-origin)` reads the point Base UI's
71
+ * positioner computes on the control's side of the popup, so it scales up from
72
+ * there and collapses back into it. It arrives from 0.96 and slightly soft, a
73
+ * 4px blur that clears as it settles, so it comes into focus the way an object
74
+ * does when it is brought close, on `spring-settle`, the spring
75
+ * tokens/motion.json names for popovers, tooltips and menus. It leaves faster
76
+ * than it came, to 0.98 and transparent on `ease-exit` over `duration-fast`,
77
+ * because a reader does not need to watch a dismissal finish. `data-instant`
78
+ * cancels the transition outright, whatever its value. Base UI sets it when a
79
+ * tooltip opens on keyboard focus, when Escape or a press dismisses one, and
80
+ * when the reader moves between neighbouring controls inside the delay
81
+ * window. So a label reached with Tab is there at once, and a row of tooltips
82
+ * read one after another does not unfold again for each one.
83
+ *
84
+ * Under `prefers-reduced-motion: reduce` the scale and the blur are pinned to
85
+ * rest, and `spring-settle` collapses in the generated sheet to a 100ms linear
86
+ * fade, so the tooltip still visibly appears and does not travel. The exit's
87
+ * `duration-fast` collapses to 1ms. A tooltip is a supplementary label and never a reading, so nothing here animates a value.
88
+ */
89
+ const UNFOLD = "origin-(--transform-origin) " +
90
+ "transition-[opacity,scale,filter] duration-(--opsin-duration-spring-settle) ease-opsin-spring-settle " +
91
+ "data-[starting-style]:opacity-0 data-[starting-style]:scale-96 data-[starting-style]:blur-xs " +
92
+ "data-[ending-style]:opacity-0 data-[ending-style]:scale-98 " +
93
+ "data-[ending-style]:duration-(--opsin-duration-fast) data-[ending-style]:ease-opsin-exit " +
94
+ "data-[instant]:transition-none " +
95
+ "motion-reduce:data-[starting-style]:scale-100 motion-reduce:data-[starting-style]:blur-none " +
96
+ "motion-reduce:data-[ending-style]:scale-100";
97
+ /**
98
+ * The popup surface, spelled once. A small raised card: `bg-card` lifts it off
99
+ * whatever it floats over, `border-border` draws its edge for greyscale and for
100
+ * a reader stylesheet that strips fills, and the `overlay` material rung casts
101
+ * the one black-alpha shadow the material ladder publishes for a floating
102
+ * surface, so the label reads as a raised note rather than a flat block.
103
+ * Consuming the material token keeps this file inside the colour contract rather
104
+ * than reaching for a raw shadow value.
105
+ *
106
+ * The type step is `footnote`, one of the eleven semantic steps, so a reader who
107
+ * has turned their text size up gets a larger label rather than a pinned pixel
108
+ * size. The width is capped at the tight measure so a long label wraps into a
109
+ * readable block instead of stretching into a single unreadable line, with a
110
+ * literal `45ch` fallback for a project installed without the generated token
111
+ * sheet.
112
+ *
113
+ * Its entrance and exit are `UNFOLD`, set out above. It is chrome, not a health
114
+ * value, so animating it on open is allowed where animating a reading would not
115
+ * be: there is no number here to count up and no ring to sweep. Under
116
+ * `prefers-reduced-motion` it keeps a 100ms fade rather than appearing between
117
+ * frames, because a label that arrives with no cue at all is easy to miss.
118
+ */
119
+ const POPUP = "max-w-[var(--opsin-measure-tight,45ch)] rounded-opsin-md border border-edge bg-card " +
120
+ "px-opsin-2 py-opsin-1 text-opsin-footnote [color:var(--foreground)] " +
121
+ "shadow-(--opsin-material-raised-shadow) " +
122
+ UNFOLD;
123
+ /**
124
+ * The arrow, a small rotated square that points from the popup back at the
125
+ * trigger. It takes the same `bg-card` fill as the popup so it reads as one
126
+ * material with it, and it carries no hairline of its own: a border on the
127
+ * square would double the popup's own edge where the two meet and leave a seam,
128
+ * so the arrow is a filled notch rather than an outlined diamond. Base UI places
129
+ * and flips it against whichever edge the popup settled on, so this file sets
130
+ * only its shape and its fill. How it reads on each of the four sides and under
131
+ * forced colours has been reasoned from the material rather than measured, which
132
+ * the page lists rather than claims.
133
+ */
134
+ const ARROW = "size-[0.5rem] rotate-45 rounded-opsin-xs bg-card";
135
+ /**
136
+ * Development warnings, said once per distinct offender. Nothing here has an
137
+ * `OpsinErrorCode`: the codes in `tokens/errors.json` describe mistakes a
138
+ * consumer makes with the clinical API, and a tooltip asserts nothing clinical.
139
+ * `divider.tsx` and `segmented-control.tsx` keep the same small set for the same
140
+ * reason, and minting a code for an interface defect is not this file's to do.
141
+ */
142
+ const warned = new Set();
143
+ function warnDev(key, message) {
144
+ if (!isDevelopment() || warned.has(key))
145
+ return;
146
+ warned.add(key);
147
+ console.warn(message);
148
+ }
149
+ export function Tooltip({ content, children, side = "top", delay = 600, className }) {
150
+ if (isDevelopment()) {
151
+ if (content === null || content === undefined || content === "") {
152
+ warnDev("no-content", "[opsinjs] <Tooltip> was rendered with no `content`, so it has nothing to " +
153
+ "show. A tooltip is a supplementary label; supply it through `content`, " +
154
+ "or drop the tooltip and let the control stand on its own.");
155
+ }
156
+ }
157
+ return (_jsx(TooltipPrimitive.Provider, { children: _jsxs(TooltipPrimitive.Root, { children: [_jsx(TooltipPrimitive.Trigger, { "data-slot": "tooltip-trigger", delay: delay, render: children }), _jsx(TooltipPrimitive.Portal, { children: _jsx(TooltipPrimitive.Positioner, { className: "z-50", side: side, sideOffset: 6, children: _jsxs(TooltipPrimitive.Popup, { "data-slot": "tooltip-popup", className: cn(POPUP, className), children: [content, _jsx(TooltipPrimitive.Arrow, { "data-slot": "tooltip-arrow", className: ARROW })] }) }) })] }) }));
158
+ }
159
+ //# sourceMappingURL=tooltip.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tooltip.js","sourceRoot":"","sources":["../../src/components/tooltip.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyDG;AAEH,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AAGpE,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAC7C,OAAO,EAAE,EAAE,EAAE,MAAM,aAAa,CAAA;AAEhC;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,MAAM,GACV,8BAA8B;IAC9B,uGAAuG;IACvG,+FAA+F;IAC/F,6DAA6D;IAC7D,2FAA2F;IAC3F,iCAAiC;IACjC,8FAA8F;IAC9F,6CAA6C,CAAA;AAE/C;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,KAAK,GACT,sFAAsF;IACtF,sEAAsE;IACtE,0CAA0C;IAC1C,MAAM,CAAA;AAER;;;;;;;;;;GAUG;AACH,MAAM,KAAK,GAAG,kDAAkD,CAAA;AAEhE;;;;;;GAMG;AACH,MAAM,MAAM,GAAG,IAAI,GAAG,EAAU,CAAA;AAEhC,SAAS,OAAO,CAAC,GAAW,EAAE,OAAe;IAC3C,IAAI,CAAC,aAAa,EAAE,IAAI,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC;QAAE,OAAM;IAC/C,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;IACf,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;AACvB,CAAC;AAgDD,MAAM,UAAU,OAAO,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,GAAG,KAAK,EAAE,KAAK,GAAG,GAAG,EAAE,SAAS,EAAgB;IAC/F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