@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,159 @@
1
+ "use client";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ /**
4
+ * Avatar is a picture or initials standing for a person, and never more than
5
+ * that.
6
+ *
7
+ * IT ASSERTS A PERSON, NOT AN AUTHORITY. A face on a message says who, it does
8
+ * not say on whose authority. The component draws the same neutral circle for
9
+ * everyone, so nothing in the styling tells a reader that the person behind an
10
+ * avatar is a clinician, a carer or a stranger. Who wrote a piece of health
11
+ * guidance, and on whose authority, is a claim a product makes in words
12
+ * through a citation, never a claim an avatar makes by looking official.
13
+ * `source-citation` is where that claim belongs.
14
+ *
15
+ * THE NAME DRIVES EVERYTHING, AND IT IS REQUIRED. The `name` is the picture's
16
+ * alt text and the source of the initials at once, so one field feeds both
17
+ * paths and the two can never drift. A missing name is the mistake this
18
+ * component is most likely to be shipped with, because a data layer returns
19
+ * an empty string as readily as a real one, so an empty or whitespace only
20
+ * name warns in development and falls back to a neutral person glyph rather
21
+ * than rendering an unlabelled circle.
22
+ *
23
+ * THE FALLBACK IS A CHAIN, AND EACH STEP ASSERTS LESS THAN THE ONE BEFORE. A
24
+ * supplied picture that loads is the most it can show. A picture that does not
25
+ * load, or was never supplied, falls back to initials derived from the
26
+ * name. A name that yields no initials, because it was empty, falls back to a
27
+ * lucide `User` glyph, which says a person without saying which one. The
28
+ * glyph is the floor, and it is reached only when there is neither a picture
29
+ * nor a usable name.
30
+ *
31
+ * INITIALS ARE DERIVED CAREFULLY, BECAUSE NAMES ARE NOT ALL ONE SHAPE. A
32
+ * two-part name gives the first character of the first part and the first
33
+ * character of the last part. A single name gives a single character. A
34
+ * non-Latin name keeps its own script, because uppercasing is a no-op in a
35
+ * script without case and forcing a transliteration would be a guess. The
36
+ * name is walked by Unicode code point rather than by UTF-16 unit, so a name
37
+ * beginning with an astral character keeps its first character whole instead
38
+ * of splitting a surrogate pair. The known limit is stated honestly here
39
+ * rather than hidden: a grapheme cluster made of a base letter plus a
40
+ * combining mark can still lose the mark, and adopting `Intl.Segmenter` is the
41
+ * fix that has not been made.
42
+ *
43
+ * IT IS NOT A CONTROL. There is no `onClick`, no `href` and no
44
+ * `role="button"`. An avatar presents a person and does nothing when it is
45
+ * tapped. Where an avatar needs to open a menu or a profile, a wrapping
46
+ * button or link owns the press and the focus, and the avatar rides along
47
+ * inside it decoratively. Making the circle itself pressable is how a face
48
+ * quietly becomes a control nobody can find by keyboard, which is why the
49
+ * confused-with routing sends interactivity to `icon-button`.
50
+ *
51
+ * THE CHROME IS NEUTRAL, ON PURPOSE. A muted fill, a hairline boundary and a
52
+ * full radius, and no colour from either health axis. A category tint would
53
+ * say the person is a kind of measurement, and a status tint would say the
54
+ * person is urgent, and a person is neither. The circle is the same neutral
55
+ * mark whoever it stands for.
56
+ *
57
+ * WHAT IT DOES NOT DO. It does not fetch, cache, crop server-side, moderate,
58
+ * or sanitise the `src`; the URL is spread onto a plain `img` and its trust
59
+ * and its content are the product's. It does not animate. It does not measure
60
+ * or gate its own contrast, and the page says the neutral pair it draws from
61
+ * is published while its own rendered pixels are not.
62
+ *
63
+ * IS A CLIENT COMPONENT. It keeps a small piece of state, the `src` that
64
+ * did not load, and handles the image's `onError` event, so it uses a hook
65
+ * and cannot be a server component. That is the only reason.
66
+ */
67
+ import { User } from "lucide-react";
68
+ import { useState } from "react";
69
+ import { isDevelopment } from "../opsinjs.js";
70
+ import { cn } from "../utils.js";
71
+ /**
72
+ * Diameter and initials type step per size. Circle diameters come from the
73
+ * space scale in rem, so an avatar grows with the reader's text size rather
74
+ * than staying put at a pixel diameter. Nothing here is tappable, so no target
75
+ * token is borrowed. Ink is set on the root as an arbitrary property below,
76
+ * not here, so a type step and a colour never land in one tailwind-merge
77
+ * group.
78
+ */
79
+ const SIZE = {
80
+ sm: "size-opsin-8 text-opsin-caption1",
81
+ md: "size-opsin-10 text-opsin-subheadline-emphasis",
82
+ lg: "size-opsin-12 text-opsin-headline",
83
+ };
84
+ /**
85
+ * The person glyph's own size per avatar size, written out because Tailwind
86
+ * reads class names as literal strings.
87
+ */
88
+ const GLYPH_SIZE = {
89
+ sm: "size-opsin-4",
90
+ md: "size-opsin-5",
91
+ lg: "size-opsin-6",
92
+ };
93
+ /**
94
+ * The sizes as the object's own keys, so the runtime guard cannot answer yes
95
+ * to "constructor" the way `size in SIZE` would.
96
+ */
97
+ const SIZE_NAMES = Object.keys(SIZE);
98
+ const MAX_INITIALS = 2;
99
+ /**
100
+ * Initials from a name, code point by code point. A two-part name gives first
101
+ * and last; a single name gives one; a name that trims to nothing gives "".
102
+ * `toLocaleUpperCase` is a no-op in a script without case, which is the
103
+ * intended behaviour for a non-Latin name rather than a bug to work around.
104
+ */
105
+ function initialsFrom(name) {
106
+ const parts = name.trim().split(/\s+/).filter(Boolean);
107
+ if (parts.length === 0)
108
+ return "";
109
+ const first = Array.from(parts[0])[0] ?? "";
110
+ const last = parts.length > 1 ? (Array.from(parts[parts.length - 1])[0] ?? "") : "";
111
+ return (first + last).toLocaleUpperCase().slice(0, MAX_INITIALS);
112
+ }
113
+ /**
114
+ * Development warnings, said once per distinct offender. Nothing here has an
115
+ * `OpsinErrorCode`: the codes in `tokens/errors.json` describe mistakes a
116
+ * consumer makes with the clinical API, and an avatar asserts nothing
117
+ * clinical. `segmented-control.tsx` keeps the same small set for the same
118
+ * reason.
119
+ */
120
+ const warned = new Set();
121
+ function warnDev(key, message) {
122
+ if (!isDevelopment() || warned.has(key))
123
+ return;
124
+ warned.add(key);
125
+ console.warn(message);
126
+ }
127
+ export function Avatar({ name, src, size, className }) {
128
+ const [erroredSrc, setErroredSrc] = useState(null);
129
+ const resolvedSize = size !== undefined && SIZE_NAMES.includes(size) ? size : "md";
130
+ const trimmedName = typeof name === "string" ? name.trim() : "";
131
+ const hasName = trimmedName !== "";
132
+ if (!hasName) {
133
+ warnDev("empty-name", "[opsinjs] <Avatar> was rendered with no name. `name` is both the " +
134
+ "picture's alt text and the source of the initials, and a " +
135
+ "whitespace only string counts as none. It has fallen back to a " +
136
+ "neutral person glyph rather than an unlabelled circle.");
137
+ }
138
+ if (size !== undefined && !SIZE_NAMES.includes(size)) {
139
+ warnDev(`unknown-size-${String(size)}`, `[opsinjs] <Avatar size="${String(size)}"> is not one of "sm", "md" ` +
140
+ 'or "lg". It has fallen back to "md".');
141
+ }
142
+ // `hasName` gates the picture too, not only the initials. Without it, a
143
+ // picture supplied alongside a missing name would render with `alt=""`,
144
+ // which marks an informative photograph as decorative and hides it from a
145
+ // screen reader while a sighted reader still sees a face. Requiring a name
146
+ // before showing the picture keeps the promise above: the fallback chain
147
+ // never renders an unlabelled circle, image tier included.
148
+ const showImage = hasName &&
149
+ typeof src === "string" &&
150
+ src.trim() !== "" &&
151
+ erroredSrc !== src;
152
+ const initials = hasName ? initialsFrom(trimmedName) : "";
153
+ const showInitials = !showImage && initials !== "";
154
+ const labelled = !showImage && hasName;
155
+ return (_jsx("span", { "data-slot": "avatar", role: labelled ? "img" : undefined, "aria-label": labelled ? trimmedName : undefined, className: cn("relative inline-flex shrink-0 select-none items-center justify-center overflow-hidden rounded-full border border-edge bg-muted [color:var(--muted-foreground)]", SIZE[resolvedSize], className), children: showImage ? (
156
+ // eslint-disable-next-line @next/next/no-img-element -- @opsinjs/react does not depend on next, so it renders a plain img rather than importing next/image, which would not work outside a Next.js app
157
+ _jsx("img", { "data-slot": "avatar-image", src: src, alt: trimmedName, className: "size-full rounded-full object-cover", onError: () => setErroredSrc(src ?? null) })) : (_jsx("span", { "data-slot": "avatar-fallback", "aria-hidden": "true", className: "inline-flex items-center justify-center leading-none", children: showInitials ? (initials) : (_jsx(User, { "aria-hidden": "true", className: GLYPH_SIZE[resolvedSize] })) })) }));
158
+ }
159
+ //# sourceMappingURL=avatar.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"avatar.js","sourceRoot":"","sources":["../../src/components/avatar.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+DG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AACnC,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAEhC,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAC7C,OAAO,EAAE,EAAE,EAAE,MAAM,aAAa,CAAA;AAWhC;;;;;;;GAOG;AACH,MAAM,IAAI,GAA+B;IACvC,EAAE,EAAE,kCAAkC;IACtC,EAAE,EAAE,+CAA+C;IACnD,EAAE,EAAE,mCAAmC;CACxC,CAAA;AAED;;;GAGG;AACH,MAAM,UAAU,GAA+B;IAC7C,EAAE,EAAE,cAAc;IAClB,EAAE,EAAE,cAAc;IAClB,EAAE,EAAE,cAAc;CACnB,CAAA;AAED;;;GAGG;AACH,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAiB,CAAA;AAEpD,MAAM,YAAY,GAAG,CAAC,CAAA;AAEtB;;;;;GAKG;AACH,SAAS,YAAY,CAAC,IAAY;IAChC,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;IACtD,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAA;IACjC,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAA;IAC3C,MAAM,IAAI,GACR,KAAK,CAAC,MAAM,GAAG,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AC,CAAC,CACd,QAAQ,CACT,CAAC,CAAC,CAAC,CACF,KAAC,IAAI,mBAAa,MAAM,EAAC,SAAS,EAAE,UAAU,CAAC,YAAY,CAAC,GAAI,CACjE,GACI,CACR,GACI,CACR,CAAA;AACH,CAAC"}
@@ -0,0 +1,78 @@
1
+ /**
2
+ * Badge is a small neutral label attached to something else: a count on a tab,
3
+ * a short word marking a list row, a bare number on an icon. It is the plainest
4
+ * component in the system, and the plainness is the whole point.
5
+ *
6
+ * IT TAKES NEITHER COLOUR AXIS, AND THAT IS THE REASON IT WAS DECLINED FOR SO
7
+ * LONG. A generic badge that could be tinted is exactly how the two colour axes
8
+ * get mixed: a red badge beside a StatusPill reads as a second status, and a
9
+ * heart-tinted badge reads as a category the surface has not claimed. So this
10
+ * component draws only neutral chrome, carries neither `data-status` nor
11
+ * `data-category`, and offers no colour prop at all. Colour that arrives through
12
+ * `className` is the caller's to keep off both axes, and the two-colour-axes
13
+ * rule applies to it in full. When a label has to carry a clinical level, the
14
+ * component is StatusPill, which carries the colour, the icon and the word
15
+ * together; a Badge never stands in for one.
16
+ *
17
+ * IT IS NOT A STATUS SURFACE. It renders no word from the clinical vocabulary of
18
+ * its own accord, reads no reference range, and reaches no verdict. Whatever text
19
+ * a caller places inside it is ordinary content, and a caller who writes a
20
+ * clinical status word into a Badge has reached for the wrong component. The word
21
+ * belongs in StatusPill's `label`, beside the colour and the glyph that make it
22
+ * survive greyscale.
23
+ *
24
+ * IT IS A SERVER COMPONENT, BECAUSE A LABEL HAS NO BEHAVIOUR TO HYDRATE. Making
25
+ * it a client component would ship JavaScript for a piece of text. It takes no
26
+ * focus and captures no key: a badge is content, not a control, and a reader
27
+ * meets it as part of the thing it is attached to rather than as a stop of its
28
+ * own.
29
+ *
30
+ * IT IS DECORATIVE ONLY WHEN ITS CONTENT IS REDUNDANT. A count that repeats a
31
+ * number already spoken beside it is noise to a screen reader, so the caller may
32
+ * label the badge for assistive technology through `srLabel`, which either names
33
+ * what the bare number counts or, set to an empty string, hides a decorative
34
+ * badge from the accessibility tree entirely. The visible text is never hidden by
35
+ * this component on the caller's behalf, because a badge that removed its own
36
+ * words for a sighted reader would be a badge that says nothing.
37
+ *
38
+ * A NAMED BADGE ALSO TAKES `role="img"`, THE SAME PAIRING `avatar.tsx` USES FOR
39
+ * ITS OWN `aria-label`. The root is a plain span, and a plain span carries the
40
+ * ARIA "generic" role, whose accessible name is computed from author markup
41
+ * only when a role that allows naming is present, so an `aria-label` sitting
42
+ * alone on a bare span is not reliably read by assistive technology. Pairing it
43
+ * with `role="img"` makes the override the name a reader actually hears rather
44
+ * than an attribute a screen reader is free to ignore.
45
+ */
46
+ import type { ReactNode } from "react";
47
+ export interface BadgeProps {
48
+ /**
49
+ * The badge's content: a count, a short word, or a small icon-and-count pair.
50
+ * Keep it to a few characters. A badge is a label attached to something else,
51
+ * not a sentence, and long content in a pill wraps into an unreadable lozenge.
52
+ */
53
+ children: ReactNode;
54
+ /**
55
+ * Visual weight only, and both weights are neutral. `soft` is a filled muted
56
+ * chip; `outline` is a hairline chip that sits lighter. Neither takes a status
57
+ * or a category colour, because a Badge is on neither axis. Defaults to `soft`.
58
+ */
59
+ variant?: "soft" | "outline";
60
+ /**
61
+ * What a screen reader should announce in place of the visible content. Give
62
+ * the bare number a noun, "3 unread", so a reader does not hear a lone "3"
63
+ * with no idea what it counts. Set it to an empty string to hide a purely
64
+ * decorative badge, one whose count is already spoken beside it, from the
65
+ * accessibility tree. Omitted, the visible content is what is announced.
66
+ */
67
+ srLabel?: string;
68
+ /**
69
+ * Merged onto the root. Placement, margin and the space around the badge
70
+ * belong here. It is the one route by which colour can reach a Badge, and the
71
+ * two-colour-axes rule applies to it in full: a badge takes neither a status
72
+ * nor a category tint. A class you pass wins over the chip's own where the two
73
+ * conflict, because it is merged last.
74
+ */
75
+ className?: string;
76
+ }
77
+ export declare function Badge({ children, variant, srLabel, className }: BadgeProps): import("react").JSX.Element;
78
+ //# sourceMappingURL=badge.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"badge.d.ts","sourceRoot":"","sources":["../../src/components/badge.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAuCtC,MAAM,WAAW,UAAU;IACzB;;;;OAIG;IACH,QAAQ,EAAE,SAAS,CAAA;IACnB;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC5B;;;;;;OAMG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB;;;;;;OAMG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,wBAAgB,KAAK,CAAC,EAAE,QAAQ,EAAE,OAAgB,EAAE,OAAO,EAAE,SAAS,EAAE,EAAE,UAAU,+BAgBnF"}
@@ -0,0 +1,32 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { cn } from "../utils.js";
3
+ /**
4
+ * The chip per weight, written out as literal class strings because Tailwind
5
+ * reads class names out of source as text and a computed `bg-${x}` generates no
6
+ * CSS. `soft` is a filled muted chip for a count that should read as quiet;
7
+ * `outline` is a hairline chip for a label that should sit lighter still. Both
8
+ * draw only the neutral chrome roles, so neither can be mistaken for a status.
9
+ */
10
+ const VARIANT = {
11
+ soft: "bg-muted [color:var(--muted-foreground)]",
12
+ outline: "border border-border [color:var(--foreground)]",
13
+ };
14
+ /**
15
+ * The chip, spelled once. Inline so it sits on the same line as the thing it is
16
+ * attached to, small so it does not compete with it, and pill-shaped with
17
+ * `rounded-full`, which resolves to the same radius under the docs chrome and at
18
+ * `/view` because it is a Tailwind theme default rather than one of the three
19
+ * radius keys the product theme overrides. The type step is `caption1`, one of
20
+ * the eleven semantic steps, so a reader who has turned their text size up gets a
21
+ * larger badge rather than a pinned pixel size.
22
+ */
23
+ const BADGE = "inline-flex items-center justify-center gap-opsin-1 rounded-full " +
24
+ "px-opsin-2 py-opsin-0-5 align-middle text-opsin-caption1 font-medium " +
25
+ "whitespace-nowrap leading-none";
26
+ export function Badge({ children, variant = "soft", srLabel, className }) {
27
+ const resolved = variant === "outline" ? "outline" : "soft";
28
+ const decorative = srLabel === "";
29
+ const labelled = typeof srLabel === "string" && srLabel !== "";
30
+ return (_jsx("span", { "data-slot": "badge", role: labelled ? "img" : undefined, "aria-hidden": decorative ? "true" : undefined, "aria-label": labelled ? srLabel : undefined, className: cn(BADGE, VARIANT[resolved], className), children: children }));
31
+ }
32
+ //# sourceMappingURL=badge.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"badge.js","sourceRoot":"","sources":["../../src/components/badge.tsx"],"names":[],"mappings":";AAgDA,OAAO,EAAE,EAAE,EAAE,MAAM,aAAa,CAAA;AAWhC;;;;;;GAMG;AACH,MAAM,OAAO,GAAiC;IAC5C,IAAI,EAAE,0CAA0C;IAChD,OAAO,EAAE,gDAAgD;CAC1D,CAAA;AAED;;;;;;;;GAQG;AACH,MAAM,KAAK,GACT,mEAAmE;IACnE,uEAAuE;IACvE,gCAAgC,CAAA;AAiClC,MAAM,UAAU,KAAK,CAAC,EAAE,QAAQ,EAAE,OAAO,GAAG,MAAM,EAAE,OAAO,EAAE,SAAS,EAAc;IAClF,MAAM,QAAQ,GAAiB,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAA;IACzE,MAAM,UAAU,GAAG,OAAO,KAAK,EAAE,CAAA;IACjC,MAAM,QAAQ,GAAG,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,KAAK,EAAE,CAAA;IAE9D,OAAO,CACL,4BACY,OAAO,EACjB,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,iBACrB,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,gBAChC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,EAC1C,SAAS,EAAE,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,QAAQ,CAAC,EAAE,SAAS,CAAC,YAEjD,QAAQ,GACJ,CACR,CAAA;AACH,CAAC"}
@@ -0,0 +1,51 @@
1
+ export interface BodyMapProps {
2
+ /**
3
+ * The controlled vocabulary of regions, in the order they are considered.
4
+ * Each entry is a stable `key` and the visible words the product wants for
5
+ * it. Defaults to the nine generic regions the schematic ships with. Pass
6
+ * your own to subset the regions or to relabel them for your copy or
7
+ * language. A `key` with no built-in place on the figure cannot be drawn:
8
+ * it is warned once in development and skipped on the diagram, because a
9
+ * marker placed at a guessed position would be worse than no marker. The
10
+ * shipped keys are `head`, `chest`, `abdomen`, `left-arm`, `right-arm`,
11
+ * `left-leg`, `right-leg`, `upper-back` and `lower-back`.
12
+ */
13
+ regions?: {
14
+ key: string;
15
+ label: string;
16
+ }[];
17
+ /**
18
+ * The keys currently marked. This is a controlled component with no
19
+ * selection state of its own, so a key here that matches no region simply
20
+ * shows nothing marked for it.
21
+ */
22
+ value: string[];
23
+ /**
24
+ * Called with the next set of marked keys when the reader toggles a region.
25
+ * The caller stores it and passes it back as `value`.
26
+ */
27
+ onValueChange: (value: string[]) => void;
28
+ /**
29
+ * Required. The accessible name for the whole group, applied as
30
+ * `aria-label`. Name it as the question the reader is answering, for
31
+ * example "Where are you noticing something?", so a screen-reader user
32
+ * hears what the regions are for before the regions themselves. There is
33
+ * no default, because a guessed name would describe the wrong thing on
34
+ * most screens.
35
+ */
36
+ label: string;
37
+ /**
38
+ * Which figure or figures to show. `both` draws the front then the back
39
+ * side by side, `front` and `back` draw one. Defaults to `both`. A figure
40
+ * only ever shows the regions whose geometry belongs to that view.
41
+ */
42
+ view?: "front" | "back" | "both";
43
+ /**
44
+ * Merged onto the root group. Layout, width and place in a form belong
45
+ * here. A class you pass wins over the root's own where the two conflict,
46
+ * because it is merged last.
47
+ */
48
+ className?: string;
49
+ }
50
+ export declare function BodyMap({ regions, value, onValueChange, label, view, className, }: BodyMapProps): import("react").JSX.Element;
51
+ //# sourceMappingURL=body-map.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"body-map.d.ts","sourceRoot":"","sources":["../../src/components/body-map.tsx"],"names":[],"mappings":"AAyNA,MAAM,WAAW,YAAY;IAC3B;;;;;;;;;;OAUG;IACH,OAAO,CAAC,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,EAAE,CAAA;IAC1C;;;;OAIG;IACH,KAAK,EAAE,MAAM,EAAE,CAAA;IACf;;;OAGG;IACH,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,IAAI,CAAA;IACxC;;;;;;;OAOG;IACH,KAAK,EAAE,MAAM,CAAA;IACb;;;;OAIG;IACH,IAAI,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,CAAA;IAChC;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,wBAAgB,OAAO,CAAC,EACtB,OAAyB,EACzB,KAAK,EACL,aAAa,EACb,KAAK,EACL,IAAa,EACb,SAAS,GACV,EAAE,YAAY,+BA0Gd"}
@@ -0,0 +1,190 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ /**
4
+ * BodyMap is a neutral body schematic for pointing at where something is, and
5
+ * a controlled multi-select of the regions a reader marks.
6
+ *
7
+ * IT IS A SCHEMATIC, NOT A FIGURE, AND THAT IS THE WHOLE DESIGN. A realistic
8
+ * body diagram has to represent a range of bodies, ages, skin tones and
9
+ * disabilities, or it tells some readers they are not the intended user. So
10
+ * this component draws an abstract, blocky outline that is deliberately not
11
+ * anyone in particular. It refuses realism on purpose, and the page carries
12
+ * the full statement of that limit.
13
+ *
14
+ * IT ASSERTS ONLY THAT THE READER POINTED HERE. It records a set of region
15
+ * keys. It is not a symptom checker, it does not name a symptom, it does not
16
+ * diagnose, it does not grade severity, and it does not decide what a marked
17
+ * region means. The consuming product owns the region vocabulary and every
18
+ * interpretation of a selection.
19
+ *
20
+ * NEITHER COLOUR AXIS. A marked region carries no clinical level and names no
21
+ * category, so the component carries neither `data-status` nor `data-category`
22
+ * and draws only neutral chrome. A selected region is lifted with a muted
23
+ * fill, a hairline and a tick, never a hue, so the selection survives
24
+ * greyscale and the semantic carrier underneath it is `aria-pressed` rather
25
+ * than any pixel. Colouring a region for severity would be the two-axis
26
+ * violation this component exists to refuse.
27
+ *
28
+ * LEFT AND RIGHT ARE THE SUBJECT'S OWN SIDES. Clinical convention names sides
29
+ * from the person's point of view, so on the front figure the `left-arm`
30
+ * marker sits on the viewer's right. This is intended, and the page says so.
31
+ *
32
+ * THE SCHEMATIC OWNS ITS GEOMETRY; THE PRODUCT OWNS THE WORDS. The component
33
+ * ships a fixed set of nine generic region keys, each with a built-in position
34
+ * on the front or back figure. The `regions` prop lets a product subset those
35
+ * regions and relabel them for its own copy or language. A region whose `key`
36
+ * has no built-in geometry cannot be placed on the figure, so it is warned
37
+ * once in development and skipped rather than drawn somewhere arbitrary.
38
+ *
39
+ * THE CHECKBOX LIST IS THE ROBUST PATH. Every region is a real, focusable,
40
+ * labelled button, so the map is keyboard reachable. A map is still a spatial
41
+ * control, so the page pairs it with a plain checkbox list bound to the same
42
+ * value, and a product should ship that list beside the map rather than
43
+ * making the diagram the only way to answer.
44
+ *
45
+ * IT DERIVES NOTHING AND STORES NOTHING. It is controlled: `value` is the
46
+ * selected keys and `onValueChange` reports the next set. The component keeps
47
+ * no selection state of its own.
48
+ *
49
+ * IT IS A CLIENT COMPONENT because it attaches click handlers to each region
50
+ * and the default demo holds its own selection state with `useState`.
51
+ */
52
+ import { isDevelopment } from "../opsinjs.js";
53
+ import { cn } from "../utils.js";
54
+ /**
55
+ * Built-in placement for each shipped region, as a percentage of the figure
56
+ * box. Left and right are the subject's own sides, so the person's left arm
57
+ * is drawn on the viewer's right. A key absent here has no place on the
58
+ * figure and is skipped rather than guessed at.
59
+ */
60
+ const GEOMETRY = {
61
+ head: { view: "front", xPct: 50, yPct: 9.3 },
62
+ chest: { view: "front", xPct: 50, yPct: 25 },
63
+ abdomen: { view: "front", xPct: 50, yPct: 39 },
64
+ "right-arm": { view: "front", xPct: 20.8, yPct: 31.7 },
65
+ "left-arm": { view: "front", xPct: 79.2, yPct: 31.7 },
66
+ "right-leg": { view: "front", xPct: 41.7, yPct: 66.7 },
67
+ "left-leg": { view: "front", xPct: 57.5, yPct: 66.7 },
68
+ "upper-back": { view: "back", xPct: 50, yPct: 26.7 },
69
+ "lower-back": { view: "back", xPct: 50, yPct: 40.7 },
70
+ };
71
+ /** The default region vocabulary, used when `regions` is omitted. */
72
+ const DEFAULT_REGIONS = [
73
+ { key: "head", label: "Head" },
74
+ { key: "chest", label: "Chest" },
75
+ { key: "abdomen", label: "Abdomen" },
76
+ { key: "left-arm", label: "Left arm" },
77
+ { key: "right-arm", label: "Right arm" },
78
+ { key: "left-leg", label: "Left leg" },
79
+ { key: "right-leg", label: "Right leg" },
80
+ { key: "upper-back", label: "Upper back" },
81
+ { key: "lower-back", label: "Lower back" },
82
+ ];
83
+ /** The accessible group name and printed caption for each figure. */
84
+ const VIEW_META = {
85
+ front: { groupLabel: "Front of the body", caption: "Front" },
86
+ back: { groupLabel: "Back of the body", caption: "Back" },
87
+ };
88
+ /**
89
+ * The relative box each figure is drawn into. The silhouette fills it and the
90
+ * region buttons are positioned by percentage over it.
91
+ */
92
+ const FIGURE_BOX = "relative mx-auto aspect-[120/300] w-full max-w-[10rem]";
93
+ /**
94
+ * A region marker, spelled once. The 44pt target floor sits on both axes with
95
+ * the rem fallback, so it grows with the reader's text size. The focus ring is
96
+ * carried here rather than left to the product stylesheet. Neutral chrome
97
+ * only: a hairline in both states, a card fill at rest and a muted fill when
98
+ * selected, and the ink is written as the arbitrary property
99
+ * `[color:var(--foreground)]` rather than `text-foreground`, for the reason
100
+ * `segmented-control.tsx` sets out at length: tailwind-merge files a `text-*`
101
+ * colour in the same conflict group as a `text-opsin-*` type step and drops
102
+ * one of them, where the arbitrary property lands in the `color` group
103
+ * instead.
104
+ */
105
+ const REGION_BASE = "absolute -translate-x-1/2 -translate-y-1/2 inline-flex items-center justify-center " +
106
+ "rounded-full border border-border " +
107
+ "min-h-(--opsin-target-minimum,2.75rem) min-w-(--opsin-target-minimum,2.75rem) " +
108
+ "cursor-pointer transition-colors duration-(--opsin-duration-fast) ease-opsin-standard " +
109
+ "focus-visible:outline-[length:var(--opsin-border-focus,2px)] focus-visible:outline-offset-[var(--opsin-border-focus-offset,2px)] focus-visible:outline-ring";
110
+ const REGION_REST = "bg-card [color:var(--muted-foreground)] hover:bg-state-hover";
111
+ const REGION_SELECTED = "bg-muted [color:var(--foreground)]";
112
+ /**
113
+ * Development warnings, said once per distinct offender. Nothing here has an
114
+ * `OpsinErrorCode`: the codes in `tokens/errors.json` describe mistakes a
115
+ * consumer makes with the clinical API, and BodyMap asserts nothing clinical.
116
+ * `segmented-control.tsx` keeps the same small set for the same reason.
117
+ */
118
+ const warned = new Set();
119
+ function warnDev(key, message) {
120
+ if (!isDevelopment() || warned.has(key))
121
+ return;
122
+ warned.add(key);
123
+ console.warn(message);
124
+ }
125
+ function TickIcon() {
126
+ return (_jsx("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", className: "size-[1.25em]", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: _jsx("path", { d: "M4 12l5 5L20 6" }) }));
127
+ }
128
+ function PlusIcon() {
129
+ return (_jsx("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", className: "size-[1.25em]", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", children: _jsx("path", { d: "M12 5v14M5 12h14" }) }));
130
+ }
131
+ /**
132
+ * The abstract silhouette: a circle for the head and rounded rectangles for
133
+ * the trunk, arms and legs, filled with the muted chrome role and outlined
134
+ * with a hairline. It is `aria-hidden` and `pointer-events-none`, so only the
135
+ * region buttons over it are interactive, and it is the same outline for both
136
+ * views because there are no facial or sex features to differ.
137
+ */
138
+ function renderSilhouette() {
139
+ return (_jsxs("svg", { viewBox: "0 0 120 300", "aria-hidden": "true", className: "pointer-events-none absolute inset-0 h-full w-full [stroke-width:var(--opsin-space-px)] fill-muted stroke-border", children: [_jsx("circle", { cx: "60", cy: "28", r: "18" }), _jsx("rect", { x: "41", y: "49", width: "38", height: "92", rx: "16" }), _jsx("rect", { x: "17", y: "58", width: "16", height: "82", rx: "8" }), _jsx("rect", { x: "87", y: "58", width: "16", height: "82", rx: "8" }), _jsx("rect", { x: "43", y: "138", width: "15", height: "128", rx: "7" }), _jsx("rect", { x: "62", y: "138", width: "15", height: "128", rx: "7" })] }));
140
+ }
141
+ export function BodyMap({ regions = DEFAULT_REGIONS, value, onValueChange, label, view = "both", className, }) {
142
+ if (isDevelopment()) {
143
+ if (typeof label !== "string" || label.trim() === "") {
144
+ warnDev("no-label", "[opsinjs] <BodyMap> was rendered with no `label`. The root is a group " +
145
+ "and needs an accessible name: without one a screen-reader user hears " +
146
+ "a set of regions with no idea what they are for. Pass `label` as the " +
147
+ 'question the reader is answering, such as "Where are you noticing ' +
148
+ 'something?".');
149
+ }
150
+ if (Array.isArray(regions) && regions.length === 0) {
151
+ warnDev("empty-regions", "[opsinjs] <BodyMap> was given an empty `regions` array, so the figure " +
152
+ "draws the silhouette with no markers on it. That is almost never " +
153
+ "intended; omit `regions` to use the nine default regions, or pass " +
154
+ "at least one entry.");
155
+ }
156
+ if (Array.isArray(regions)) {
157
+ for (const region of regions) {
158
+ if (!(region.key in GEOMETRY)) {
159
+ warnDev(`unknown-region:${region.key}`, `[opsinjs] <BodyMap> was given a region with key "${region.key}", ` +
160
+ "which has no built-in place on the shipped schematic, so it is " +
161
+ "skipped on the figure rather than drawn at a guessed position. " +
162
+ "The shipped keys are head, chest, abdomen, left-arm, right-arm, " +
163
+ "left-leg, right-leg, upper-back and lower-back.");
164
+ }
165
+ }
166
+ }
167
+ if (view !== "front" && view !== "back" && view !== "both") {
168
+ warnDev(`unknown-view:${String(view)}`, `[opsinjs] <BodyMap view="${String(view)}"> is not "front", "back" or ` +
169
+ '"both", so it is treated as "both". Pass one of those three values.');
170
+ }
171
+ }
172
+ const safeView = view === "front" || view === "back" ? view : "both";
173
+ const showFront = safeView === "front" || safeView === "both";
174
+ const showBack = safeView === "back" || safeView === "both";
175
+ function toggle(key) {
176
+ const next = value.includes(key) ? value.filter((k) => k !== key) : [...value, key];
177
+ onValueChange(next);
178
+ }
179
+ function renderFigure(v) {
180
+ const meta = VIEW_META[v];
181
+ const here = regions.filter((r) => GEOMETRY[r.key]?.view === v);
182
+ return (_jsxs("div", { "data-slot": "body-map-figure", role: "group", "aria-label": meta.groupLabel, className: "flex flex-col items-center gap-opsin-2", children: [_jsxs("div", { className: FIGURE_BOX, children: [renderSilhouette(), here.map((r) => {
183
+ const g = GEOMETRY[r.key];
184
+ const selected = value.includes(r.key);
185
+ return (_jsx("button", { type: "button", "data-slot": "body-map-region", "aria-pressed": selected, "aria-label": r.label, onClick: () => toggle(r.key), style: { left: `${g.xPct}%`, top: `${g.yPct}%` }, className: cn(REGION_BASE, selected ? REGION_SELECTED : REGION_REST), children: selected ? _jsx(TickIcon, {}) : _jsx(PlusIcon, {}) }, r.key));
186
+ })] }), _jsx("p", { className: "text-opsin-footnote [color:var(--muted-foreground)]", children: meta.caption })] }, v));
187
+ }
188
+ return (_jsxs("div", { "data-slot": "body-map", role: "group", "aria-label": label, className: cn("flex flex-wrap justify-center gap-opsin-8", className), children: [showFront ? renderFigure("front") : null, showBack ? renderFigure("back") : null] }));
189
+ }
190
+ //# sourceMappingURL=body-map.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"body-map.js","sourceRoot":"","sources":["../../src/components/body-map.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AAIH,OA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