@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.
- package/CHANGELOG.md +9 -0
- package/LICENSE +21 -0
- package/README.md +114 -2
- package/dist/components/accordion.d.ts +82 -0
- package/dist/components/accordion.d.ts.map +1 -0
- package/dist/components/accordion.js +154 -0
- package/dist/components/accordion.js.map +1 -0
- package/dist/components/alert-banner.d.ts +291 -0
- package/dist/components/alert-banner.d.ts.map +1 -0
- package/dist/components/alert-banner.js +529 -0
- package/dist/components/alert-banner.js.map +1 -0
- package/dist/components/avatar.d.ts +45 -0
- package/dist/components/avatar.d.ts.map +1 -0
- package/dist/components/avatar.js +159 -0
- package/dist/components/avatar.js.map +1 -0
- package/dist/components/badge.d.ts +78 -0
- package/dist/components/badge.d.ts.map +1 -0
- package/dist/components/badge.js +32 -0
- package/dist/components/badge.js.map +1 -0
- package/dist/components/body-map.d.ts +51 -0
- package/dist/components/body-map.d.ts.map +1 -0
- package/dist/components/body-map.js +190 -0
- package/dist/components/body-map.js.map +1 -0
- package/dist/components/button.d.ts +260 -0
- package/dist/components/button.d.ts.map +1 -0
- package/dist/components/button.js +609 -0
- package/dist/components/button.js.map +1 -0
- package/dist/components/callout.d.ts +99 -0
- package/dist/components/callout.d.ts.map +1 -0
- package/dist/components/callout.js +285 -0
- package/dist/components/callout.js.map +1 -0
- package/dist/components/card.d.ts +156 -0
- package/dist/components/card.d.ts.map +1 -0
- package/dist/components/card.js +396 -0
- package/dist/components/card.js.map +1 -0
- package/dist/components/care-card.d.ts +182 -0
- package/dist/components/care-card.d.ts.map +1 -0
- package/dist/components/care-card.js +544 -0
- package/dist/components/care-card.js.map +1 -0
- package/dist/components/checkbox.d.ts +58 -0
- package/dist/components/checkbox.d.ts.map +1 -0
- package/dist/components/checkbox.js +167 -0
- package/dist/components/checkbox.js.map +1 -0
- package/dist/components/combobox.d.ts +71 -0
- package/dist/components/combobox.d.ts.map +1 -0
- package/dist/components/combobox.js +204 -0
- package/dist/components/combobox.js.map +1 -0
- package/dist/components/consent-sheet.d.ts +186 -0
- package/dist/components/consent-sheet.d.ts.map +1 -0
- package/dist/components/consent-sheet.js +452 -0
- package/dist/components/consent-sheet.js.map +1 -0
- package/dist/components/dialog.d.ts +108 -0
- package/dist/components/dialog.d.ts.map +1 -0
- package/dist/components/dialog.js +573 -0
- package/dist/components/dialog.js.map +1 -0
- package/dist/components/disclaimer-note.d.ts +144 -0
- package/dist/components/disclaimer-note.d.ts.map +1 -0
- package/dist/components/disclaimer-note.js +486 -0
- package/dist/components/disclaimer-note.js.map +1 -0
- package/dist/components/divider.d.ts +76 -0
- package/dist/components/divider.d.ts.map +1 -0
- package/dist/components/divider.js +101 -0
- package/dist/components/divider.js.map +1 -0
- package/dist/components/dose-tracker.d.ts +137 -0
- package/dist/components/dose-tracker.d.ts.map +1 -0
- package/dist/components/dose-tracker.js +154 -0
- package/dist/components/dose-tracker.js.map +1 -0
- package/dist/components/empty-state.d.ts +171 -0
- package/dist/components/empty-state.d.ts.map +1 -0
- package/dist/components/empty-state.js +387 -0
- package/dist/components/empty-state.js.map +1 -0
- package/dist/components/field.d.ts +195 -0
- package/dist/components/field.d.ts.map +1 -0
- package/dist/components/field.js +282 -0
- package/dist/components/field.js.map +1 -0
- package/dist/components/goal-ring.d.ts +114 -0
- package/dist/components/goal-ring.d.ts.map +1 -0
- package/dist/components/goal-ring.js +254 -0
- package/dist/components/goal-ring.js.map +1 -0
- package/dist/components/icon-button.d.ts +124 -0
- package/dist/components/icon-button.d.ts.map +1 -0
- package/dist/components/icon-button.js +113 -0
- package/dist/components/icon-button.js.map +1 -0
- package/dist/components/link.d.ts +122 -0
- package/dist/components/link.d.ts.map +1 -0
- package/dist/components/link.js +164 -0
- package/dist/components/link.js.map +1 -0
- package/dist/components/log-sheet.d.ts +259 -0
- package/dist/components/log-sheet.d.ts.map +1 -0
- package/dist/components/log-sheet.js +437 -0
- package/dist/components/log-sheet.js.map +1 -0
- package/dist/components/menu.d.ts +69 -0
- package/dist/components/menu.d.ts.map +1 -0
- package/dist/components/menu.js +190 -0
- package/dist/components/menu.js.map +1 -0
- package/dist/components/metric-tile.d.ts +301 -0
- package/dist/components/metric-tile.d.ts.map +1 -0
- package/dist/components/metric-tile.js +533 -0
- package/dist/components/metric-tile.js.map +1 -0
- package/dist/components/number-field.d.ts +62 -0
- package/dist/components/number-field.d.ts.map +1 -0
- package/dist/components/number-field.js +134 -0
- package/dist/components/number-field.js.map +1 -0
- package/dist/components/popover.d.ts +70 -0
- package/dist/components/popover.d.ts.map +1 -0
- package/dist/components/popover.js +174 -0
- package/dist/components/popover.js.map +1 -0
- package/dist/components/progress.d.ts +83 -0
- package/dist/components/progress.d.ts.map +1 -0
- package/dist/components/progress.js +140 -0
- package/dist/components/progress.js.map +1 -0
- package/dist/components/questionnaire.d.ts +123 -0
- package/dist/components/questionnaire.d.ts.map +1 -0
- package/dist/components/questionnaire.js +148 -0
- package/dist/components/questionnaire.js.map +1 -0
- package/dist/components/radio-group.d.ts +66 -0
- package/dist/components/radio-group.d.ts.map +1 -0
- package/dist/components/radio-group.js +186 -0
- package/dist/components/radio-group.js.map +1 -0
- package/dist/components/range-bar.d.ts +172 -0
- package/dist/components/range-bar.d.ts.map +1 -0
- package/dist/components/range-bar.js +578 -0
- package/dist/components/range-bar.js.map +1 -0
- package/dist/components/range-legend.d.ts +97 -0
- package/dist/components/range-legend.d.ts.map +1 -0
- package/dist/components/range-legend.js +166 -0
- package/dist/components/range-legend.js.map +1 -0
- package/dist/components/reading-input.d.ts +225 -0
- package/dist/components/reading-input.d.ts.map +1 -0
- package/dist/components/reading-input.js +651 -0
- package/dist/components/reading-input.js.map +1 -0
- package/dist/components/relative-time.d.ts +177 -0
- package/dist/components/relative-time.d.ts.map +1 -0
- package/dist/components/relative-time.js +603 -0
- package/dist/components/relative-time.js.map +1 -0
- package/dist/components/result-card.d.ts +319 -0
- package/dist/components/result-card.d.ts.map +1 -0
- package/dist/components/result-card.js +614 -0
- package/dist/components/result-card.js.map +1 -0
- package/dist/components/scale-input.d.ts +58 -0
- package/dist/components/scale-input.d.ts.map +1 -0
- package/dist/components/scale-input.js +170 -0
- package/dist/components/scale-input.js.map +1 -0
- package/dist/components/score-dial.d.ts +205 -0
- package/dist/components/score-dial.d.ts.map +1 -0
- package/dist/components/score-dial.js +728 -0
- package/dist/components/score-dial.js.map +1 -0
- package/dist/components/scroll-area.d.ts +38 -0
- package/dist/components/scroll-area.d.ts.map +1 -0
- package/dist/components/scroll-area.js +138 -0
- package/dist/components/scroll-area.js.map +1 -0
- package/dist/components/segmented-control.d.ts +69 -0
- package/dist/components/segmented-control.d.ts.map +1 -0
- package/dist/components/segmented-control.js +259 -0
- package/dist/components/segmented-control.js.map +1 -0
- package/dist/components/select.d.ts +72 -0
- package/dist/components/select.d.ts.map +1 -0
- package/dist/components/select.js +205 -0
- package/dist/components/select.js.map +1 -0
- package/dist/components/sheet.d.ts +192 -0
- package/dist/components/sheet.d.ts.map +1 -0
- package/dist/components/sheet.js +952 -0
- package/dist/components/sheet.js.map +1 -0
- package/dist/components/skeleton.d.ts +104 -0
- package/dist/components/skeleton.d.ts.map +1 -0
- package/dist/components/skeleton.js +266 -0
- package/dist/components/skeleton.js.map +1 -0
- package/dist/components/slider.d.ts +55 -0
- package/dist/components/slider.d.ts.map +1 -0
- package/dist/components/slider.js +170 -0
- package/dist/components/slider.js.map +1 -0
- package/dist/components/source-citation.d.ts +127 -0
- package/dist/components/source-citation.d.ts.map +1 -0
- package/dist/components/source-citation.js +391 -0
- package/dist/components/source-citation.js.map +1 -0
- package/dist/components/spinner.d.ts +86 -0
- package/dist/components/spinner.d.ts.map +1 -0
- package/dist/components/spinner.js +97 -0
- package/dist/components/spinner.js.map +1 -0
- package/dist/components/status-pill.d.ts +90 -0
- package/dist/components/status-pill.d.ts.map +1 -0
- package/dist/components/status-pill.js +259 -0
- package/dist/components/status-pill.js.map +1 -0
- package/dist/components/stepper.d.ts +99 -0
- package/dist/components/stepper.d.ts.map +1 -0
- package/dist/components/stepper.js +152 -0
- package/dist/components/stepper.js.map +1 -0
- package/dist/components/surface.d.ts +92 -0
- package/dist/components/surface.d.ts.map +1 -0
- package/dist/components/surface.js +261 -0
- package/dist/components/surface.js.map +1 -0
- package/dist/components/switch.d.ts +48 -0
- package/dist/components/switch.d.ts.map +1 -0
- package/dist/components/switch.js +152 -0
- package/dist/components/switch.js.map +1 -0
- package/dist/components/symptom-picker.d.ts +69 -0
- package/dist/components/symptom-picker.d.ts.map +1 -0
- package/dist/components/symptom-picker.js +170 -0
- package/dist/components/symptom-picker.js.map +1 -0
- package/dist/components/tab-bar.d.ts +110 -0
- package/dist/components/tab-bar.d.ts.map +1 -0
- package/dist/components/tab-bar.js +118 -0
- package/dist/components/tab-bar.js.map +1 -0
- package/dist/components/table.d.ts +117 -0
- package/dist/components/table.d.ts.map +1 -0
- package/dist/components/table.js +65 -0
- package/dist/components/table.js.map +1 -0
- package/dist/components/tabs.d.ts +106 -0
- package/dist/components/tabs.d.ts.map +1 -0
- package/dist/components/tabs.js +136 -0
- package/dist/components/tabs.js.map +1 -0
- package/dist/components/term.d.ts +243 -0
- package/dist/components/term.d.ts.map +1 -0
- package/dist/components/term.js +562 -0
- package/dist/components/term.js.map +1 -0
- package/dist/components/textarea.d.ts +157 -0
- package/dist/components/textarea.d.ts.map +1 -0
- package/dist/components/textarea.js +66 -0
- package/dist/components/textarea.js.map +1 -0
- package/dist/components/timeline-entry.d.ts +99 -0
- package/dist/components/timeline-entry.d.ts.map +1 -0
- package/dist/components/timeline-entry.js +47 -0
- package/dist/components/timeline-entry.js.map +1 -0
- package/dist/components/toast.d.ts +80 -0
- package/dist/components/toast.d.ts.map +1 -0
- package/dist/components/toast.js +266 -0
- package/dist/components/toast.js.map +1 -0
- package/dist/components/tooltip.d.ts +48 -0
- package/dist/components/tooltip.d.ts.map +1 -0
- package/dist/components/tooltip.js +159 -0
- package/dist/components/tooltip.js.map +1 -0
- package/dist/components/trend-sparkline.d.ts +188 -0
- package/dist/components/trend-sparkline.d.ts.map +1 -0
- package/dist/components/trend-sparkline.js +796 -0
- package/dist/components/trend-sparkline.js.map +1 -0
- package/dist/components/value.d.ts +150 -0
- package/dist/components/value.d.ts.map +1 -0
- package/dist/components/value.js +402 -0
- package/dist/components/value.js.map +1 -0
- package/dist/components/visually-hidden.d.ts +61 -0
- package/dist/components/visually-hidden.d.ts.map +1 -0
- package/dist/components/visually-hidden.js +172 -0
- package/dist/components/visually-hidden.js.map +1 -0
- package/dist/index.d.ts +63 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +72 -0
- package/dist/index.js.map +1 -0
- package/dist/opsinjs.d.ts +443 -0
- package/dist/opsinjs.d.ts.map +1 -0
- package/dist/opsinjs.js +906 -0
- package/dist/opsinjs.js.map +1 -0
- package/dist/status.d.ts +111 -0
- package/dist/status.d.ts.map +1 -0
- package/dist/status.js +125 -0
- package/dist/status.js.map +1 -0
- package/dist/styles.css +2 -0
- package/dist/utils.d.ts +20 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +82 -0
- package/dist/utils.js.map +1 -0
- package/package.json +86 -3
- package/styles/base.css +132 -0
- package/styles/roles.css +412 -0
- package/styles/standalone.css +20 -0
- package/styles/tailwind.css +18 -0
- package/styles/theme.css +309 -0
|
@@ -0,0 +1,562 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
/**
|
|
4
|
+
* Term shows a clinical word with its everyday meaning attached, so a sentence
|
|
5
|
+
* can be read without leaving it.
|
|
6
|
+
*
|
|
7
|
+
* A DEFINITION SAYS WHAT A THING IS. It does not say what the reader should do
|
|
8
|
+
* about theirs, and this file has no way to make it. There is no `status`, no
|
|
9
|
+
* `severity`, no action slot and no `href`: everything Term can render is the
|
|
10
|
+
* word, its full form, and one sentence of plain English that came out of a
|
|
11
|
+
* glossary somebody reviewed. *Chronic means long-lasting* is a translation;
|
|
12
|
+
* *chronic means you will have this for life* is a prognosis, and the shape of
|
|
13
|
+
* the API is the only thing that reliably keeps the second one out.
|
|
14
|
+
*
|
|
15
|
+
* THE THREE PRIMITIVES THAT LOOK RIGHT AND ARE NOT. `term.mdx:118-120` says the
|
|
16
|
+
* definition "is never removed from the accessibility tree by a presentation
|
|
17
|
+
* choice… a reader using speech has no way to know something is there to open",
|
|
18
|
+
* and `term.mdx:205-206` says the word "is never split from its definition in
|
|
19
|
+
* the reading order". Those two sentences rule out every disclosure primitive in
|
|
20
|
+
* `@base-ui/react`, and they rule them out for different reasons:
|
|
21
|
+
*
|
|
22
|
+
* - `preview-card` opens on hover. This is a phone-first system and there is
|
|
23
|
+
* no hover on a phone, which is also why `present` has no `hover` value.
|
|
24
|
+
* - `popover` portals its content to the end of the document and hides it
|
|
25
|
+
* from assistive technology while closed. Both halves fail: the definition
|
|
26
|
+
* leaves the sentence, and a speech reader meets a control with nothing
|
|
27
|
+
* behind it until they guess to press it.
|
|
28
|
+
* - `collapsible` keeps the panel adjacent, which fixes the reading order, but
|
|
29
|
+
* its closed panel carries the `hidden` attribute even with `keepMounted`.
|
|
30
|
+
* `hidden` is exactly what "removed from the accessibility tree" means.
|
|
31
|
+
*
|
|
32
|
+
* So the disclosure here is hand-built, and it is built the other way round: the
|
|
33
|
+
* definition is ALWAYS in the accessibility tree, and the control changes only
|
|
34
|
+
* whether it is on the screen. Collapsed, it is `display: none` and reaches the
|
|
35
|
+
* reader as the trigger's accessible DESCRIPTION. A node referenced by
|
|
36
|
+
* `aria-describedby` is included in the name-and-description computation whether
|
|
37
|
+
* or not it is displayed, which is the one hiding mechanism that keeps a promise
|
|
38
|
+
* instead of breaking it.
|
|
39
|
+
*
|
|
40
|
+
* IT IS A CLIENT COMPONENT, ALL OF IT, AND THAT IS A COST RATHER THAN A CHOICE.
|
|
41
|
+
* Only the disclosure needs state; the inline presentation is a span and two
|
|
42
|
+
* strings. But `"use client"` is a file-level directive and a component is one
|
|
43
|
+
* flat file in `packages/react/src/components/`, so the boundary lands on the
|
|
44
|
+
* whole component or on none of it. Splitting the leaf into a second file would
|
|
45
|
+
* put a non-component into that directory, where the generator registers every
|
|
46
|
+
* file as a component, exports it from the package entry point and publishes it
|
|
47
|
+
* as its own subpath, so half of this one would ship as a component of its own.
|
|
48
|
+
*
|
|
49
|
+
* WHERE THE DEFINITIONS COME FROM, AND WHY NOT FROM A PROP. `term.mdx:155-158`
|
|
50
|
+
* refuses a per-call-site definition outright: definitions live in a glossary so
|
|
51
|
+
* they are consistent across every screen, reviewable in one place, translatable
|
|
52
|
+
* and countable. A product can then ask *how many words are we asking our
|
|
53
|
+
* readers to learn?* and get an answer. So the glossary arrives once, through
|
|
54
|
+
* <TermGlossaryProvider>, and `id` is a key into it.
|
|
55
|
+
*
|
|
56
|
+
* A CONFLICT WITH THE AUTHORED GLOSSARY, PART NOW SETTLED AND PART STILL OPEN.
|
|
57
|
+
* `tokens/glossary.json`'s `policy.rule` reads: "Plain wording is the
|
|
58
|
+
* default and the clinical term is the annotation, never the other way around.
|
|
59
|
+
* `<Term>` renders the plain wording as the visible text and exposes the
|
|
60
|
+
* clinical term on demand; it must not render a clinical term with a tooltip
|
|
61
|
+
* and call that plain English." This file does the reverse: the visible text is
|
|
62
|
+
* the clinical word, and the plain wording is either attached in parentheses or
|
|
63
|
+
* put behind a control. The argument for the implemented direction is the one
|
|
64
|
+
* in `GlossaryEntry.word` below, and the same policy block makes it itself when
|
|
65
|
+
* it explains why `showBoth: "always"` exists. A reader holding a printout has
|
|
66
|
+
* to be able to match it to the screen. Both statements are in the same file and
|
|
67
|
+
* they contradict each other, and neither this component nor the glossary may
|
|
68
|
+
* settle the whole of it alone. The narrower half is now settled: where a call
|
|
69
|
+
* site expresses no preference and leaves the presentation to `auto`, the
|
|
70
|
+
* glossary's `always` governs, so both readings go on the screen inline rather
|
|
71
|
+
* than the plain wording being hidden behind a press. What stays open is the
|
|
72
|
+
* shape itself, whether the visible text should be the plain wording with the
|
|
73
|
+
* clinical spelling as the annotation rather than the other way around. That is
|
|
74
|
+
* a change to this component and to `policy.rule` together, so it is recorded
|
|
75
|
+
* here and on `term.mdx` rather than settled quietly.
|
|
76
|
+
*/
|
|
77
|
+
import { createContext, useContext, useId, useMemo, useState, } from "react";
|
|
78
|
+
import { isDevelopment } from "../opsinjs.js";
|
|
79
|
+
import { cn } from "../utils.js";
|
|
80
|
+
/**
|
|
81
|
+
* The glossary, as a lookup, with an empty one as the default.
|
|
82
|
+
*
|
|
83
|
+
* Empty rather than absent, because the honest behaviour for a Term outside any
|
|
84
|
+
* provider is the same as the behaviour for an id nobody has defined: render the
|
|
85
|
+
* word, mark nothing, and say so in development. A thrown error would take a
|
|
86
|
+
* reader's whole screen down over a missing dictionary entry.
|
|
87
|
+
*/
|
|
88
|
+
const GlossaryContext = createContext(new Map());
|
|
89
|
+
/**
|
|
90
|
+
* Mount this once, around everything that reads.
|
|
91
|
+
*
|
|
92
|
+
* A React context rather than a module-level registry, for two reasons that
|
|
93
|
+
* both matter in a Next.js application. A module singleton exists once per
|
|
94
|
+
* module graph, so a glossary registered on the server is not the glossary a
|
|
95
|
+
* client component sees, and the failure is invisible until a term goes blank in
|
|
96
|
+
* the browser. And a provider nests: a specialist area of a product can supply a
|
|
97
|
+
* second, narrower glossary for its own subtree without editing the first.
|
|
98
|
+
*/
|
|
99
|
+
export function TermGlossaryProvider({ glossary, children, }) {
|
|
100
|
+
const lookup = useMemo(() => {
|
|
101
|
+
const map = new Map();
|
|
102
|
+
for (const entry of glossary) {
|
|
103
|
+
/* A duplicate id is a silent defect otherwise: the second entry wins, the
|
|
104
|
+
first one's definition never appears anywhere, and nothing in the
|
|
105
|
+
interface looks wrong. Both texts are plausible English, so a reviewer
|
|
106
|
+
reading the screen cannot tell which one they are looking at. */
|
|
107
|
+
if (isDevelopment() && map.has(entry.id)) {
|
|
108
|
+
warn(`duplicate:${entry.id}`, `two glossary entries share the id "${entry.id}". The later one wins ` +
|
|
109
|
+
"and the earlier definition is unreachable. Ids are how a call site " +
|
|
110
|
+
"names a definition; two definitions cannot share one.");
|
|
111
|
+
}
|
|
112
|
+
map.set(entry.id, entry);
|
|
113
|
+
}
|
|
114
|
+
return map;
|
|
115
|
+
}, [glossary]);
|
|
116
|
+
return (_jsx(GlossaryContext.Provider, { value: lookup, children: children }));
|
|
117
|
+
}
|
|
118
|
+
/** The point at which the warning channel stops rather than grows. */
|
|
119
|
+
const MAX_WARNED_KEYS = 500;
|
|
120
|
+
/** Not a real key. It only records that the cap notice has been printed. */
|
|
121
|
+
const CAP_KEY = "\u0000cap";
|
|
122
|
+
const warnedKeys = new Set();
|
|
123
|
+
/**
|
|
124
|
+
* The development channel, and it is deliberately not an OPSIN code.
|
|
125
|
+
*
|
|
126
|
+
* `tokens/errors.json` has no entry for a term that is not in the glossary, and
|
|
127
|
+
* a component may not mint one: the codes are a versioned contract and the table
|
|
128
|
+
* on the errors page is generated from that file. Until an entry exists this is
|
|
129
|
+
* the honest channel. It warns and renders; taking a word out of a sentence
|
|
130
|
+
* because its definition is missing would break the sentence as well as the
|
|
131
|
+
* definition.
|
|
132
|
+
*
|
|
133
|
+
* ONCE PER OFFENDING CALL SITE, WHICH IS WHAT THE KEY IS FOR. Every one of
|
|
134
|
+
* these is raised during render, so an unkeyed channel reports a screen's four
|
|
135
|
+
* unresolved terms on every render and twice again under Strict Mode, and a
|
|
136
|
+
* warning channel that degrades into noise is one somebody switches off.
|
|
137
|
+
* `tokens/errors.json`'s policy block, which `../opsinjs.ts` quotes, asks for
|
|
138
|
+
* "once per offending call site". `warnOnce` itself still cannot be reused
|
|
139
|
+
* here, because it is keyed on an `OpsinErrorCode` and there is no code for any
|
|
140
|
+
* of this; but the de-duplication is independent of the code table, so the
|
|
141
|
+
* shape is borrowed rather than the function, cap and all. The cap exists
|
|
142
|
+
* because the set is never cleared and a development session can run for days.
|
|
143
|
+
*/
|
|
144
|
+
function warn(key, message) {
|
|
145
|
+
if (!isDevelopment())
|
|
146
|
+
return;
|
|
147
|
+
if (warnedKeys.has(key))
|
|
148
|
+
return;
|
|
149
|
+
if (warnedKeys.size >= MAX_WARNED_KEYS) {
|
|
150
|
+
if (warnedKeys.has(CAP_KEY))
|
|
151
|
+
return;
|
|
152
|
+
warnedKeys.add(CAP_KEY);
|
|
153
|
+
report(`${MAX_WARNED_KEYS} distinct warnings have been reported in this session, ` +
|
|
154
|
+
"so this channel is now quiet. Fix what is already reported, or reload " +
|
|
155
|
+
"to start counting again.");
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
warnedKeys.add(key);
|
|
159
|
+
report(message);
|
|
160
|
+
}
|
|
161
|
+
function report(message) {
|
|
162
|
+
try {
|
|
163
|
+
console.warn(`[opsinjs] <Term> ${message}`);
|
|
164
|
+
}
|
|
165
|
+
catch {
|
|
166
|
+
/* A patched or absent console is not a reason to take a health product
|
|
167
|
+
down. */
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* An empty string is an absent field, not a present one.
|
|
172
|
+
*
|
|
173
|
+
* `??` catches `null` and `undefined` and nothing else, so a glossary row whose
|
|
174
|
+
* column was exported but never filled in resolves to `""` and is then treated
|
|
175
|
+
* as a value somebody wrote. That is not a hypothetical shape: a spreadsheet
|
|
176
|
+
* export and a half-finished translation pass both produce it, and a
|
|
177
|
+
* product-owned glossary is authored in exactly those two ways. Left alone it
|
|
178
|
+
* renders a bare comma after nothing, or " ()" after a word, or a hole in the
|
|
179
|
+
* middle of a clinical sentence. Trimmed as well as compared, because a cell
|
|
180
|
+
* holding one space is the same defect wearing a different coat.
|
|
181
|
+
*/
|
|
182
|
+
function filled(field) {
|
|
183
|
+
const trimmed = field?.trim();
|
|
184
|
+
return trimmed === undefined || trimmed === "" ? undefined : trimmed;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* How long an attached definition may be before it stops being a parenthetical.
|
|
188
|
+
*
|
|
189
|
+
* A typographic budget, not a clinical threshold. The surface a definition
|
|
190
|
+
* actually lands on is the comfortable measure, `--opsin-measure-comfortable` at
|
|
191
|
+
* 66ch, which the demo and both examples set; the tight measure is for narrower
|
|
192
|
+
* columns this component does not sit in. A parenthetical that occupies up to
|
|
193
|
+
* about one and a quarter lines of that measure still interrupts the sentence it
|
|
194
|
+
* sits in, and past that it replaces it, which is why the budget is 80 rather
|
|
195
|
+
* than the 40 it once was.
|
|
196
|
+
*
|
|
197
|
+
* The number is derived out loud because it is checkable against this
|
|
198
|
+
* repository's own glossary, so read it against the code as it stands rather
|
|
199
|
+
* than against an earlier version of this file. 80 is the threshold on the
|
|
200
|
+
* budget path only, which is an entry the glossary has not marked `always`,
|
|
201
|
+
* because an `always` entry is shown inline whatever its length before the
|
|
202
|
+
* budget is ever consulted (see `resolvePresentation`). Three entries in
|
|
203
|
+
* `tokens/glossary.json` run past 80 counting plain plus expansion: systolic at
|
|
204
|
+
* 90, blood pressure at 88 and diastolic at 85. Of those only blood pressure
|
|
205
|
+
* reaches the budget at all, because systolic and diastolic are `always` and go
|
|
206
|
+
* inline regardless, so run over the whole glossary the auto path puts 35 of the
|
|
207
|
+
* 36 entries inline and leaves exactly one behind a control, blood pressure. The
|
|
208
|
+
* number an author should act on is therefore the budget for an entry the
|
|
209
|
+
* glossary has not marked `always`: keep such a definition inside 80 characters
|
|
210
|
+
* and the reader gets it without pressing anything.
|
|
211
|
+
*
|
|
212
|
+
* It is still counted rather than measured, for the hydration reason argued at
|
|
213
|
+
* `resolvePresentation` below: a width is knowable only in the browser, and
|
|
214
|
+
* measuring after the server has already rendered the other branch is a flash on
|
|
215
|
+
* every phone, while a character count is knowable identically on both sides.
|
|
216
|
+
*/
|
|
217
|
+
const INLINE_BUDGET = 80;
|
|
218
|
+
/**
|
|
219
|
+
* The mark that says an explanation exists.
|
|
220
|
+
*
|
|
221
|
+
* A dotted underline and nothing else. Not a colour: `term.mdx:79-81` puts Term
|
|
222
|
+
* outside both axes, and a word tinted from the category ramp looks like a
|
|
223
|
+
* status while a word tinted from the status ramp IS one. The underline survives
|
|
224
|
+
* greyscale, increased contrast and a black-and-white printout, which is the
|
|
225
|
+
* whole reason it is the carrier.
|
|
226
|
+
*
|
|
227
|
+
* The offset is in `em` and not in pixels, which is the one length in this file
|
|
228
|
+
* that could have opted out of the reader's own text size. A fixed 4px offset
|
|
229
|
+
* against glyphs a low-vision reader has doubled in order to read them puts the
|
|
230
|
+
* rule into the descenders of the word it is marking. The sole affordance, and
|
|
231
|
+
* the sole non-colour carrier, would then degrade precisely for the reader it
|
|
232
|
+
* matters most to. There is no token for an underline offset, so this is a
|
|
233
|
+
* judgement rather than a token lookup.
|
|
234
|
+
*
|
|
235
|
+
* The thickness is in `em` too, and for the same reason. The mark is the sole
|
|
236
|
+
* affordance and the sole non-colour carrier, so it has to stay legible to a
|
|
237
|
+
* reader who has enlarged their type, and the default `auto` thickness pins at
|
|
238
|
+
* roughly one device pixel and barely grows when they do. `decoration-[0.12em]`
|
|
239
|
+
* is about 2px at the 1.0625rem body size and about 4px at 200%, so the rule
|
|
240
|
+
* thickens with the word rather than staying a hairline a phone reader may never
|
|
241
|
+
* notice. There is no token for an underline thickness, so this is a judgement
|
|
242
|
+
* stated as one, the same judgement the `em` offset makes two lines above.
|
|
243
|
+
*
|
|
244
|
+
* The 2026-09-05 audit also asked for a resting `bg-muted` tint on every
|
|
245
|
+
* clinical word, and this file departs from that half of the proposal and says
|
|
246
|
+
* why. A resting tint on every clinical word would stripe a paragraph that holds
|
|
247
|
+
* three of them, which is a worse read for the older reader this finding is
|
|
248
|
+
* about, and a running text peppered with filled boxes is harder to follow than
|
|
249
|
+
* one marked only where the eye needs to stop. The tint is also already
|
|
250
|
+
* spoken for: `TRIGGER_BUTTON` spends three theme fills on hover, press and open,
|
|
251
|
+
* so a fourth fill sitting under the word at rest would compete with the states
|
|
252
|
+
* rather than rest beneath them. So the resting cue is thickness and the tint
|
|
253
|
+
* means state.
|
|
254
|
+
*
|
|
255
|
+
* A press moves the word down by one pixel. The dotted underline is the resting
|
|
256
|
+
* mark, the ring is focus, and `active:translate-y-px` is the press: it is the
|
|
257
|
+
* same one-pixel shift `button.tsx` uses, and it is the only state a thumb can
|
|
258
|
+
* see, because a term sitting inside a paragraph has no hover on a phone. It is a
|
|
259
|
+
* transform and not a fill, so it adds no colour to a word that is deliberately
|
|
260
|
+
* outside both axes.
|
|
261
|
+
*
|
|
262
|
+
* It is dropped in print, where the definition is expanded beside the word and a
|
|
263
|
+
* mark promising something further would be promising nothing.
|
|
264
|
+
*
|
|
265
|
+
* The rule is dotted while the definition is hidden and solid while it is
|
|
266
|
+
* showing: `aria-expanded:decoration-solid` turns the dots into a continuous
|
|
267
|
+
* line the moment the word is opened. The dotted rule is a promise that
|
|
268
|
+
* something further exists, and while the definition is on the screen beside the
|
|
269
|
+
* word that promise has been kept, so the mark stops hinting and settles. This
|
|
270
|
+
* is a change of form and not of colour, so it survives greyscale exactly as the
|
|
271
|
+
* resting mark does, and it never carries the open state alone: `aria-expanded`
|
|
272
|
+
* carries it to assistive technology and the definition appearing beside the
|
|
273
|
+
* word is the primary signal to everyone.
|
|
274
|
+
*/
|
|
275
|
+
const TRIGGER_MARK = "underline decoration-dotted decoration-[0.12em] underline-offset-[0.25em] aria-expanded:decoration-solid active:translate-y-px print:no-underline";
|
|
276
|
+
/**
|
|
277
|
+
* The button, stripped back to the word it contains.
|
|
278
|
+
*
|
|
279
|
+
* A `<button>` does not reliably honour `display: inline`. The engine computes
|
|
280
|
+
* it as an inline-block whatever the class asks for, and the 2026-09-05 layout
|
|
281
|
+
* audit is the proof: the trigger measured 45 by 44 on a 22px line. So vertical
|
|
282
|
+
* padding on it is not free, and none is carried. An earlier version paid that
|
|
283
|
+
* padding in the belief that the box was inline and that the padding left the
|
|
284
|
+
* line box alone; the measurement disproved both, and every line that held a
|
|
285
|
+
* term was taller than its neighbours.
|
|
286
|
+
*
|
|
287
|
+
* The product theme floors every `button` at `--opsin-target-minimum`, and this
|
|
288
|
+
* one is opted out of that floor by name with `[min-block-size:0]` and
|
|
289
|
+
* `[min-inline-size:0]`. It relies on SC 2.5.8's exemption for a target that is
|
|
290
|
+
* inline in a sentence, which `accessibility/target-size-and-motor` asks to be
|
|
291
|
+
* named out loud rather than assumed. The arbitrary-property spelling is
|
|
292
|
+
* deliberate: `[min-block-size:0]` names the very property `base.css` sets, and
|
|
293
|
+
* a Tailwind utility sits in the utilities layer while the floor sits in
|
|
294
|
+
* `@layer base`, so the opt-out wins on layer order rather than on specificity.
|
|
295
|
+
* `min-h-0 min-w-0` is the fallback spelling if the arbitrary form is ever
|
|
296
|
+
* rejected; do not carry both.
|
|
297
|
+
*
|
|
298
|
+
* The hit area therefore does not come from the box. It comes from an absolutely
|
|
299
|
+
* positioned `::before` that takes no part in layout. `before:-inset-y-[0.5em]`
|
|
300
|
+
* grows the target from roughly 20px to roughly 37px tall, in `em` so it scales
|
|
301
|
+
* with the reader's own text against a 1.0625rem body, and because the
|
|
302
|
+
* pseudo-element is out of flow the paragraph's leading is identical on a line
|
|
303
|
+
* that carries a term and a line that does not. The pseudo-element takes pointer
|
|
304
|
+
* events because it is part of the button's own rendering, which is the
|
|
305
|
+
* distinction `accessibility/target-size-and-motor` draws between a real
|
|
306
|
+
* enlarged target and a decorative halo. `px-opsin-0-5` with a cancelling
|
|
307
|
+
* `-mx-opsin-0-5` stays: the 2px of horizontal room is what the tint and the
|
|
308
|
+
* press state paint into so they do not sit flush against the neighbouring
|
|
309
|
+
* glyphs, and the negative margin means the words either side do not move.
|
|
310
|
+
*
|
|
311
|
+
* The second-order effect survives the change, because only its mechanism moved,
|
|
312
|
+
* from padding to pseudo-element. The `::before` reaches past the line box above
|
|
313
|
+
* and below, so two terms on adjacent wrapped lines that sit over one another
|
|
314
|
+
* have targets that overlap, and a reader with a tremor can land on the wrong
|
|
315
|
+
* definition rather than on nothing. SC 2.5.8's inline exemption covers the SIZE
|
|
316
|
+
* of a target and says nothing about two of them meeting. The nightly layout run
|
|
317
|
+
* measures each box and does not measure overlap, so nothing will surface this;
|
|
318
|
+
* it is named on `term.mdx` instead.
|
|
319
|
+
*
|
|
320
|
+
* Hover, press and open each take a neutral fill from the theme, and they take
|
|
321
|
+
* different ones. `hover:bg-state-hover` and `active:bg-state-press` come from
|
|
322
|
+
* the interaction-state roles `roles.css` declares and `theme.css` bridges
|
|
323
|
+
* (`--state-hover` and `--state-press`), which is the same source `button.tsx`
|
|
324
|
+
* draws its hover and press from, and press is a darker step than hover in
|
|
325
|
+
* light and a lighter one in dark, so a tap changes the fill rather than
|
|
326
|
+
* repeating it. The accent and secondary chrome roles live only in the docs
|
|
327
|
+
* stylesheet, so under the product theme they resolve to nothing and this
|
|
328
|
+
* control does not reach for them. The open state keeps the chrome `bg-muted`,
|
|
329
|
+
* a third fill distinct from either transient state, so a word held open never
|
|
330
|
+
* wears the same value as a word merely being pressed. The states are therefore
|
|
331
|
+
* told apart by value as well as by when they happen. `hover:` costs a phone
|
|
332
|
+
* reader nothing, because Tailwind wraps it in a hover-capable query; `active:`
|
|
333
|
+
* is the press feedback a thumb gets on a term sitting in a paragraph;
|
|
334
|
+
* `aria-expanded:bg-muted` holds the word on the open tint for as long as its
|
|
335
|
+
* definition is showing. The tint never carries a state alone: `aria-expanded`
|
|
336
|
+
* carries the open state to assistive technology, the solid rule (see
|
|
337
|
+
* `TRIGGER_MARK`) carries it to a sighted reader, and the definition beside the
|
|
338
|
+
* word is the primary signal.
|
|
339
|
+
*/
|
|
340
|
+
const TRIGGER_BUTTON = "relative inline cursor-pointer appearance-none border-0 bg-transparent " +
|
|
341
|
+
"[min-block-size:0] [min-inline-size:0] px-opsin-0-5 -mx-opsin-0-5 " +
|
|
342
|
+
"[font:inherit] text-inherit rounded-opsin-xs " +
|
|
343
|
+
"hover:bg-state-hover active:bg-state-press aria-expanded:bg-muted " +
|
|
344
|
+
"before:absolute before:content-[''] before:-inset-y-[0.5em] before:-inset-x-opsin-1 " +
|
|
345
|
+
"focus-visible:outline-[length:var(--opsin-border-focus,2px)] focus-visible:outline-offset-[var(--opsin-border-focus-offset,2px)] focus-visible:outline-ring";
|
|
346
|
+
/** The definition itself: quieter than the sentence, never smaller than it. */
|
|
347
|
+
const DEFINITION = "text-muted-foreground";
|
|
348
|
+
/**
|
|
349
|
+
* Which presentation this occurrence gets, and the order is the whole argument.
|
|
350
|
+
*
|
|
351
|
+
* `once` and an explicit `present` come first, because they are the call site's
|
|
352
|
+
* statements about this occurrence and a component does not overrule the surface
|
|
353
|
+
* it stands on. `once` says the reader has already met both readings here, so the
|
|
354
|
+
* repeat goes behind a control; an explicit `present` is a deliberate choice and
|
|
355
|
+
* is returned unchanged.
|
|
356
|
+
*
|
|
357
|
+
* `auto` is the call site expressing no opinion, and that is where the authored
|
|
358
|
+
* glossary gets to govern. An entry the glossary marks `showBoth: "always"` is
|
|
359
|
+
* shown inline whatever its length, both the clinical word and the plain wording
|
|
360
|
+
* together, because that is what the glossary asked for and where nobody at the
|
|
361
|
+
* call site has an opinion the glossary's own policy is a better authority than a
|
|
362
|
+
* character count. Only when the glossary is silent too does the budget decide.
|
|
363
|
+
*
|
|
364
|
+
* The budget chooses by the LENGTH of what would be attached, never by the width
|
|
365
|
+
* available. Width is knowable only by measuring, measuring only happens in the
|
|
366
|
+
* browser, and a component that measures after the server has already rendered
|
|
367
|
+
* the other branch produces a hydration mismatch by construction and a visible
|
|
368
|
+
* flash on every phone. Length is knowable identically on both sides, so `auto`
|
|
369
|
+
* resolves to the same answer in both and there is nothing to reconcile.
|
|
370
|
+
*/
|
|
371
|
+
function resolvePresentation(present, once, showBoth, attached) {
|
|
372
|
+
/* `once` outranks an explicit `inline`, because it is a statement about this
|
|
373
|
+
occurrence and `present` is a statement about the component. A caller who
|
|
374
|
+
asked for both has asked for the definition not to be repeated inline, and
|
|
375
|
+
that is the one of the two that carries information. */
|
|
376
|
+
if (once)
|
|
377
|
+
return "disclosure";
|
|
378
|
+
if (present !== "auto")
|
|
379
|
+
return present;
|
|
380
|
+
/* `auto` with no call-site opinion: the glossary's own policy governs before
|
|
381
|
+
the budget. An `always` entry is shown inline whatever its length. */
|
|
382
|
+
if (showBoth === "always")
|
|
383
|
+
return "inline";
|
|
384
|
+
return attached <= INLINE_BUDGET ? "inline" : "disclosure";
|
|
385
|
+
}
|
|
386
|
+
export function Term({ id, children, present = "auto", once = false, className, }) {
|
|
387
|
+
const glossary = useContext(GlossaryContext);
|
|
388
|
+
const entry = glossary.get(id);
|
|
389
|
+
const definitionId = useId();
|
|
390
|
+
const [open, setOpen] = useState(false);
|
|
391
|
+
/* NO ENTRY, NO MARK. A dotted underline is a promise that pressing or reading
|
|
392
|
+
on will produce an explanation, and a promise with nothing behind it is
|
|
393
|
+
worse than plain text: the reader spends attention on it once and stops
|
|
394
|
+
trusting the mark everywhere else on the screen. The word still renders,
|
|
395
|
+
because the sentence still has to make sense.
|
|
396
|
+
|
|
397
|
+
WHAT RENDERS WITHOUT `children` IS THE KEY, AND THE KEY IS NOT A WORD.
|
|
398
|
+
`<Term id="blood-pressure" />` in an application that has forgotten the
|
|
399
|
+
provider prints "blood-pressure" mid-sentence, and `<Term id="egfr" />`
|
|
400
|
+
prints "egfr". That is the wrong spelling for matching a reader's own
|
|
401
|
+
paperwork, which is the entire reason the clinical word is on the screen at
|
|
402
|
+
all. The alternative is a hole where a word belongs, which breaks the
|
|
403
|
+
sentence for everybody rather than only for the reviewer, so the key stays
|
|
404
|
+
and the behaviour is stated here, in `TermProps.children` and on `term.mdx`
|
|
405
|
+
instead of being discovered. The warning below is development-only by
|
|
406
|
+
policy, so in a build a reader uses there is no signal: the real gate is a
|
|
407
|
+
lint rule over the product's own source, and it does not exist yet. */
|
|
408
|
+
if (entry === undefined) {
|
|
409
|
+
warn(`missing:${id}`, `id="${id}" is not in the glossary this subtree was given. The word is ` +
|
|
410
|
+
"rendered unmarked, and with no `children` to print, the sentence " +
|
|
411
|
+
`shows the raw key "${id}" instead. Add the entry, or drop the ` +
|
|
412
|
+
"<Term> and write the word plainly. There is no third option that is " +
|
|
413
|
+
"honest.");
|
|
414
|
+
return (_jsx("span", { "data-slot": "term", className: className, children: children ?? id }));
|
|
415
|
+
}
|
|
416
|
+
/* Read once, through `filled`, so that an empty column is an absent field
|
|
417
|
+
everywhere in this component rather than in the two places that happened to
|
|
418
|
+
compare against `undefined`. */
|
|
419
|
+
const plain = filled(entry.plain);
|
|
420
|
+
const expansion = filled(entry.expansion);
|
|
421
|
+
const speech = filled(entry.speech);
|
|
422
|
+
/* `plain-only` IS THE GLOSSARY REFUSING. `tokens/glossary.json`'s own policy
|
|
423
|
+
is that plain wording is the default and the clinical term is the
|
|
424
|
+
annotation; a `plain-only` entry says the clinical word is never shown to
|
|
425
|
+
this reader at all and exists so an author can look up what to write
|
|
426
|
+
instead. So there is nothing to explain and nothing to mark. When a call
|
|
427
|
+
site has already written a sentence into `children`, that sentence is what
|
|
428
|
+
renders, because a runtime cannot rewrite a sentence and a gloss dropped
|
|
429
|
+
into a word's slot reads as broken grammar. When there are no children the
|
|
430
|
+
plain wording renders as ordinary text. Either way the contradiction is
|
|
431
|
+
reported rather than hidden. */
|
|
432
|
+
if (entry.showBoth === "plain-only") {
|
|
433
|
+
warn(`plain-only:${id}`, `id="${id}" is marked showBoth: "plain-only", which means its clinical ` +
|
|
434
|
+
"word should never be shown to a reader. Nothing is marked here. Write " +
|
|
435
|
+
"the plain wording directly and drop the <Term>.");
|
|
436
|
+
/* `children` is HONOURED here, not discarded, and the warning is what
|
|
437
|
+
carries the contradiction. `TermProps.children` is where a call site
|
|
438
|
+
writes the clinical word inflected for its own sentence, and this entry's
|
|
439
|
+
entire content is that the clinical word never reaches a reader. The two
|
|
440
|
+
cannot both be satisfied. A runtime cannot rewrite a sentence, and
|
|
441
|
+
printing the gloss where the word belongs produces an ungrammatical
|
|
442
|
+
sentence a reader meets with no signal in the build they use, so the
|
|
443
|
+
component renders what the author actually wrote and reports the conflict
|
|
444
|
+
loudly instead. The cost is real and stays on the record: a reader now
|
|
445
|
+
meets a clinical word the glossary said to keep away from them, but that
|
|
446
|
+
word is visible and reviewable in the source, where a silently garbled
|
|
447
|
+
sentence was neither. The repair is to write the plain wording directly
|
|
448
|
+
and drop the <Term>. */
|
|
449
|
+
if (children !== undefined) {
|
|
450
|
+
warn(`plain-only-children:${id}`, `id="${id}" is marked showBoth: "plain-only", which declares that its ` +
|
|
451
|
+
"clinical word never reaches a reader, and it was given children " +
|
|
452
|
+
"that write the clinical word into a sentence anyway. The component " +
|
|
453
|
+
"cannot rewrite the sentence and will not print a gloss where a word " +
|
|
454
|
+
"belongs, so it renders the children as written and reports this " +
|
|
455
|
+
"contradiction. Write the plain wording directly and drop the " +
|
|
456
|
+
"<Term>.");
|
|
457
|
+
}
|
|
458
|
+
if (children === undefined && plain === undefined) {
|
|
459
|
+
warn(`plain-only-empty:${id}`, `id="${id}" is marked showBoth: "plain-only", has no plain wording, ` +
|
|
460
|
+
"and was given no children. There is nothing this component may " +
|
|
461
|
+
"render: the clinical word is refused by the entry, its replacement " +
|
|
462
|
+
"does not exist, and the call site wrote nothing. Fill the " +
|
|
463
|
+
"definition in.");
|
|
464
|
+
}
|
|
465
|
+
return (_jsx("span", { "data-slot": "term", className: className, children: children ?? plain }));
|
|
466
|
+
}
|
|
467
|
+
/* AN ENTRY WITH NO DEFINITION IS NOT AN ENTRY, and it takes the same exit as
|
|
468
|
+
a missing one for the same reason: a mark promises an explanation, and
|
|
469
|
+
there is nothing here to explain with. Rendering the mark anyway would put
|
|
470
|
+
" ()" after a word, or a control that opens onto an empty pair of brackets,
|
|
471
|
+
which reads as the product having lost the definition rather than as never
|
|
472
|
+
having written one. */
|
|
473
|
+
if (plain === undefined) {
|
|
474
|
+
warn(`empty-plain:${id}`, `id="${id}" has no plain wording: the field is empty or is whitespace. ` +
|
|
475
|
+
"The word is rendered unmarked. A glossary row with no definition is a " +
|
|
476
|
+
"defect in the glossary rather than a presentation to fall back to, " +
|
|
477
|
+
"and an empty column is what a spreadsheet export and an unfinished " +
|
|
478
|
+
"translation pass both produce.");
|
|
479
|
+
return (_jsx("span", { "data-slot": "term", className: className, children: children ?? entry.word }));
|
|
480
|
+
}
|
|
481
|
+
const presentation = resolvePresentation(present, once, entry.showBoth, plain.length + (expansion?.length ?? 0));
|
|
482
|
+
const visible = children ?? entry.word;
|
|
483
|
+
/* `showBoth: "always"` NOW GOVERNS THE `auto` PATH, so the only way an
|
|
484
|
+
`always` entry lands behind a press is a call site that named
|
|
485
|
+
`present="disclosure"` on a first appearance. That is the one case worth a
|
|
486
|
+
warning: the author asked for a disclosure and the glossary asked for both
|
|
487
|
+
on the screen, and the call site is allowed to win, but it is probably a
|
|
488
|
+
mistake. `once` does not warn, because it means the reader has already met
|
|
489
|
+
both readings on this surface, so the glossary's matching argument was
|
|
490
|
+
served by the first occurrence and the repeat going behind a control is not
|
|
491
|
+
a violation. */
|
|
492
|
+
if (!once && present === "disclosure" && entry.showBoth === "always") {
|
|
493
|
+
warn(`always:${id}`, `id="${id}" is marked showBoth: "always", which the glossary defines as ` +
|
|
494
|
+
"showing the clinical word and the plain wording together every time, " +
|
|
495
|
+
"so that a reader holding a printout can match it to the screen. This " +
|
|
496
|
+
'occurrence set present="disclosure", so the plain wording is behind a ' +
|
|
497
|
+
"press against the glossary's policy. Drop the explicit present here, or " +
|
|
498
|
+
'pass present="inline", if both have to be on the screen.');
|
|
499
|
+
}
|
|
500
|
+
/* Expansion first, then definition, then stop. See `term.mdx:279` and `:296`
|
|
501
|
+
onwards. The expansion and the gloss are one apposition and are joined as
|
|
502
|
+
one, because a separator glyph here is punctuation a screen reader either
|
|
503
|
+
skips or reads out, on a component whose entire job is to be heard
|
|
504
|
+
correctly. The comma is the only punctuation this component owns. */
|
|
505
|
+
const definition = (_jsxs(_Fragment, { children: [expansion === undefined ? null : (_jsxs(_Fragment, { children: [_jsx("span", { "data-slot": "term-expansion", children: expansion }), ", "] })), plain] }));
|
|
506
|
+
/* THE NAME COMES FROM THE CONTENT, AND THAT IS THE FIX RATHER THAN THE
|
|
507
|
+
SHORTCUT. An earlier version put `aria-label="What does <spoken> mean?"` on
|
|
508
|
+
the control. `aria-label` REPLACES the accessible name, so the word on the
|
|
509
|
+
screen was not in the name at all: a reader saw "eGFR" and the control was
|
|
510
|
+
called "What does e G F R mean?". That is SC 2.5.3 Label in Name (Level A)
|
|
511
|
+
unmet on every disclosure this component drew, and it is a Voice Control
|
|
512
|
+
user saying "click eGFR" and nothing happening. There was no honest way to
|
|
513
|
+
repair the string either, because `children` is a `ReactNode` and may not be
|
|
514
|
+
a string at all. Content-derived, the name contains the visible word by
|
|
515
|
+
construction, whatever `children` holds.
|
|
516
|
+
|
|
517
|
+
`speech` IS ADDITIVE NOW, NOT SUBSTITUTIVE. It used to be swapped in for the
|
|
518
|
+
written word behind `aria-hidden`, which took the paperwork spelling away
|
|
519
|
+
from precisely the readers who cannot see the screen: a braille reader got
|
|
520
|
+
"S P O 2" and never "SpO2". That spelling is the stated reason `word`
|
|
521
|
+
exists. Both forms are exposed, written first and letters second. The cost
|
|
522
|
+
is that a speech reader hears the synthesiser's attempt at the word before
|
|
523
|
+
the letters, and that is the smaller of the two costs rather than no cost
|
|
524
|
+
at all. It is on `term.mdx`, and no screen reader has been run against
|
|
525
|
+
either shape. */
|
|
526
|
+
const trigger = speech === undefined ? (visible) : (_jsxs(_Fragment, { children: [visible, _jsx("span", { className: "sr-only", children: ` ${speech}` })] }));
|
|
527
|
+
if (presentation === "inline") {
|
|
528
|
+
return (_jsxs("span", { "data-slot": "term", className: className, children: [_jsx("span", { "data-slot": "term-trigger", children: trigger }), _jsxs("span", { "data-slot": "term-definition", className: DEFINITION, children: [" (", definition, ")"] })] }));
|
|
529
|
+
}
|
|
530
|
+
return (_jsxs("span", { "data-slot": "term", className: className, children: [_jsx("button", { type: "button", "data-slot": "term-trigger", "aria-expanded": open, "aria-controls": definitionId, "aria-describedby": definitionId, onClick: () => setOpen((wasOpen) => !wasOpen), onKeyDown: (event) => {
|
|
531
|
+
/* Escape closes it, and focus is already on the control that opened
|
|
532
|
+
it, so there is nothing to return. The component never moves focus:
|
|
533
|
+
opening a definition does not take a reader out of the sentence.
|
|
534
|
+
|
|
535
|
+
preventDefault as well as stopPropagation, because they stop
|
|
536
|
+
different things. stopPropagation ends React's delegated dispatch,
|
|
537
|
+
which is enough inside this system's own Sheet and Dialog, whose
|
|
538
|
+
listeners are React listeners. It does nothing to a native
|
|
539
|
+
<dialog>'s own cancel behaviour, which the user agent performs
|
|
540
|
+
independently. So without preventDefault one Escape closed the
|
|
541
|
+
definition and the dialog around it together. The guard on `open`
|
|
542
|
+
is what keeps the key available to that dialog the rest of the
|
|
543
|
+
time. */
|
|
544
|
+
if (event.key === "Escape" && open) {
|
|
545
|
+
event.preventDefault();
|
|
546
|
+
event.stopPropagation();
|
|
547
|
+
setOpen(false);
|
|
548
|
+
}
|
|
549
|
+
}, className: cn(TRIGGER_BUTTON, TRIGGER_MARK), children: trigger }), _jsxs("span", { id: definitionId, "data-slot": "term-definition", className: cn(DEFINITION,
|
|
550
|
+
/* `hidden` here is Tailwind's `display: none` class rather than the
|
|
551
|
+
HTML attribute, so the print rule beside it can win. The attribute
|
|
552
|
+
would need `!important` to beat, and an element hidden by attribute
|
|
553
|
+
reads as hidden to tooling that never looks at the stylesheet.
|
|
554
|
+
|
|
555
|
+
Print expands the definition beside its word, because a printed page
|
|
556
|
+
has no disclosures and the definition is the part the reader takes
|
|
557
|
+
to the appointment. A repeat occurrence stays closed on paper too:
|
|
558
|
+
`once` means "do not say this again", and paper is where saying it
|
|
559
|
+
four times is most expensive. */
|
|
560
|
+
open ? "inline" : once ? "hidden" : "hidden print:inline"), children: [" (", definition, ")"] })] }));
|
|
561
|
+
}
|
|
562
|
+
//# sourceMappingURL=term.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"term.js","sourceRoot":"","sources":["../../src/components/term.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ;;;;;;;;;;;;;;;;;;;;;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