@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
package/dist/opsinjs.js
ADDED
|
@@ -0,0 +1,906 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* packages/react/src/opsinjs.ts is the shared substrate every opsinjs component
|
|
3
|
+
* imports.
|
|
4
|
+
*
|
|
5
|
+
* WHY THIS FILE EXISTS
|
|
6
|
+
* Every component under `packages/react/src/components/` is published in
|
|
7
|
+
* @opsinjs/react, and a consumer installs that package and updates it by
|
|
8
|
+
* version. Anything a component imports has to be inside the package or among
|
|
9
|
+
* its declared dependencies, or the published build will not compile, and a
|
|
10
|
+
* component that compiles here and breaks there is worse than no component at
|
|
11
|
+
* all. So the shared modules a component imports are exactly two: `../utils.ts`
|
|
12
|
+
* for `cn`, and this one, imported as `../opsinjs.ts`. There is no third. Not
|
|
13
|
+
* `@/components/*`, not `@/registry/*`, not `@/app/*`, not `@/tokens/*`. Those
|
|
14
|
+
* paths belong to the documentation site in `apps/www` and are not in the
|
|
15
|
+
* package. A component that composes another imports it as a sibling,
|
|
16
|
+
* `./<id>.tsx`.
|
|
17
|
+
*
|
|
18
|
+
* Every one of these is a relative specifier with no alias, so it names the
|
|
19
|
+
* same file when the documentation site reads these sources through its
|
|
20
|
+
* tsconfig paths and when `tsc` compiles them into the package's `dist`, where
|
|
21
|
+
* `rewriteRelativeImportExtensions` turns each `.ts` into `.js`. Nothing is
|
|
22
|
+
* rewritten by hand at either end.
|
|
23
|
+
*
|
|
24
|
+
* IT RE-EXPORTS AND IT NEVER RE-DECLARES. The clinical vocabulary lives in
|
|
25
|
+
* `packages/react/src/status.ts`, which is the module the documentation chrome,
|
|
26
|
+
* the section contracts and `assert-ia.mts` already read through the site's
|
|
27
|
+
* `lib/status.ts`. A second copy of `CLINICAL_STATUSES` here would be a second
|
|
28
|
+
* copy that can drift, and the two axes are the one thing in this system that
|
|
29
|
+
* must never say two different things. `status.ts` is published beside this
|
|
30
|
+
* file in @opsinjs/react for the same reason.
|
|
31
|
+
*
|
|
32
|
+
* WHAT IS DECLARED HERE, AND WHY IT IS HERE RATHER THAN IN A COMPONENT
|
|
33
|
+
* Only the shapes that more than one component has to agree on: a reference
|
|
34
|
+
* range, a point on a trend, a sheet detent, a material rung, and the one string
|
|
35
|
+
* every example is allowed to cite as its source. A shape used by exactly one
|
|
36
|
+
* component belongs in that component's own file, because a type nobody else
|
|
37
|
+
* consumes is not substrate, it is that component's API.
|
|
38
|
+
*
|
|
39
|
+
* CONSTRAINTS THIS FILE IS UNDER
|
|
40
|
+
* No JSX and no non-erasable TypeScript, so no `enum`, no parameter properties
|
|
41
|
+
* and no `namespace`. Every relative import carries an explicit `.ts` extension,
|
|
42
|
+
* because `apps/www/scripts/*.mts` run under plain Node 24 with native type
|
|
43
|
+
* stripping and some of them reach this file through the site's `lib/`
|
|
44
|
+
* re-exports, with no resolver hook. The same rule holds for `status.ts` and
|
|
45
|
+
* `utils.ts` beside this file, and on the site for `lib/catalogue.ts`,
|
|
46
|
+
* `lib/routes.ts` and `registry/catalogue.ts`.
|
|
47
|
+
*
|
|
48
|
+
* `apps/www/scripts/build-reference.mts` scans this file beside the site's
|
|
49
|
+
* `lib/` and turns every exported type and interface into a row of the
|
|
50
|
+
* generated types reference, taking the first sentence of the doc comment
|
|
51
|
+
* directly above the declaration as the summary. The same comments also reach
|
|
52
|
+
* every consumer through the package's type declarations. They are therefore
|
|
53
|
+
* published documentation, not notes to the next reader of the source.
|
|
54
|
+
*
|
|
55
|
+
* THREE REGIONS OF THIS FILE ARE GENERATED, each between a marker pair that
|
|
56
|
+
* `apps/www/scripts/build-tokens.mts` replaces wholesale on `pnpm run generate`.
|
|
57
|
+
* The `OPSIN_ERRORS` table sits between the `opsinjs:errors` markers near the
|
|
58
|
+
* bottom and is emitted from `tokens/errors.json`. The unit table sits between
|
|
59
|
+
* the `opsinjs:units` markers and is emitted from `tokens/units.json`. The
|
|
60
|
+
* banned-word table sits between the `opsinjs:banned` markers and is emitted
|
|
61
|
+
* from `tokens/glossary.json`. Edit the JSON, never a region.
|
|
62
|
+
*
|
|
63
|
+
* Everything outside those three marker pairs is hand-written, `warnOnce()`
|
|
64
|
+
* included, and the generator leaves it alone.
|
|
65
|
+
*
|
|
66
|
+
* It is generated INTO this file rather than into the site's `lib/generated/`
|
|
67
|
+
* for the reason the first paragraph gives: `lib/generated/` belongs to the
|
|
68
|
+
* documentation site and is not in @opsinjs/react, so `warnOnce()` importing
|
|
69
|
+
* the error table from there would compile in this repository and fail for
|
|
70
|
+
* every consumer who installed the package. The same table is also emitted into
|
|
71
|
+
* `lib/generated/tokens.ts` as `OPSIN_ERROR_CODES` for the documentation site,
|
|
72
|
+
* which is not a second copy anybody maintains: both are written by one script,
|
|
73
|
+
* from one source, in one run, and `node scripts/build-tokens.mts --check` fails
|
|
74
|
+
* on either drifting.
|
|
75
|
+
*/
|
|
76
|
+
/* ------------------------------------------------------------------ *
|
|
77
|
+
* The clinical vocabulary, re-exported from status.ts *
|
|
78
|
+
* *
|
|
79
|
+
* A component imports these from `../opsinjs.ts` and never from *
|
|
80
|
+
* `../status.ts` directly. Both files are published, so either would *
|
|
81
|
+
* resolve, but one import surface is what makes the substrate *
|
|
82
|
+
* reviewable. A consumer imports the same names from @opsinjs/react, *
|
|
83
|
+
* the specifier every component page's `## Usage` block prints. *
|
|
84
|
+
* ------------------------------------------------------------------ */
|
|
85
|
+
export { CLINICAL_STATUSES, CLINICAL_STATUS_META, HEALTH_CATEGORIES, HEALTH_CATEGORY_LABELS, isClinicalStatus, isHealthCategory, axisConflict, } from "./status.js";
|
|
86
|
+
/* opsinjs:banned:begin. Replaced by scripts/build-tokens.mts from tokens/glossary.json */
|
|
87
|
+
/** Words a component's copy must not use, with the replacement and the reason. Generated from `tokens/glossary.json`. */
|
|
88
|
+
export const BANNED_WORDS = [
|
|
89
|
+
{
|
|
90
|
+
word: "abnormal",
|
|
91
|
+
instead: "outside the usual range",
|
|
92
|
+
reason: "The counterpart of the same problem, and the version that frightens people.",
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
word: "bad",
|
|
96
|
+
instead: "the specific finding, stated plainly",
|
|
97
|
+
reason: "Carries a verdict the system is not entitled to give.",
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
word: "diagnosis",
|
|
101
|
+
instead: "say what the reading is and who can interpret it",
|
|
102
|
+
reason: "opsinjs components never diagnose. Using the word implies they do.",
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
word: "don't worry",
|
|
106
|
+
instead: "state what the reading means and what happens next",
|
|
107
|
+
reason: "Reassurance the system cannot back up, and it reads as a reason to worry.",
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
word: "elevated",
|
|
111
|
+
instead: "higher than",
|
|
112
|
+
reason: "Clinical register; means little to a lay reader, and it sounds like a verdict to the readers who do recognise it.",
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
word: "failed",
|
|
116
|
+
instead: "outside the range we expected",
|
|
117
|
+
reason: "A reading is not a test the reader sat.",
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
word: "good",
|
|
121
|
+
instead: "say the direction - higher, or lower",
|
|
122
|
+
reason: "Moral framing of something largely outside the reader's control.",
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
word: "healthy",
|
|
126
|
+
instead: "in the usual range",
|
|
127
|
+
reason: "A verdict on a life, from one number. A reading can sit inside a range while the person is unwell, and outside it while they are fine.",
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
word: "just",
|
|
131
|
+
instead: "delete it",
|
|
132
|
+
reason: "'Just a bit high' minimises a reading the reader may need to act on.",
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
word: "negative",
|
|
136
|
+
instead: "the test did not find <what it looked for>",
|
|
137
|
+
reason: "Same collision, in the other direction.",
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
word: "normal",
|
|
141
|
+
instead: "in the usual range, or the expected range for you",
|
|
142
|
+
reason: "Outside a reference range is not abnormal in the everyday sense of the word, and inside one is not a clean bill of health. 'Normal' also carries a judgement about the person rather than about the reading. This word is banned outright across the system, including in code identifiers.",
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
word: "optimal",
|
|
146
|
+
instead: "in the usual range",
|
|
147
|
+
reason: "Sets up every future reading as a decline, in the register of a fitness tracker rather than a clinic.",
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
word: "perfect",
|
|
151
|
+
instead: "in the usual range",
|
|
152
|
+
reason: "Sets up every future reading as a decline.",
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
word: "poor",
|
|
156
|
+
instead: "lower than the range for you",
|
|
157
|
+
reason: "Judges the person, not the measurement.",
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
word: "positive",
|
|
161
|
+
instead: "the test found <what it found>",
|
|
162
|
+
reason: "In everyday English 'positive' means good news. In a test result it usually means the opposite, and the collision is dangerous.",
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
word: "unhealthy",
|
|
166
|
+
instead: "higher than the usual range",
|
|
167
|
+
reason: "The same verdict in the other direction. Say which way the reading sits and against whose range; the replacement wording assumes the common case, so where the reading is low, say 'lower than the usual range'.",
|
|
168
|
+
},
|
|
169
|
+
];
|
|
170
|
+
/* opsinjs:banned:end */
|
|
171
|
+
/* ------------------------------------------------------------------ *
|
|
172
|
+
* Example data *
|
|
173
|
+
* ------------------------------------------------------------------ */
|
|
174
|
+
/**
|
|
175
|
+
* The only citation an opsinjs example, demo or preview may carry.
|
|
176
|
+
*
|
|
177
|
+
* Every component has a zero-prop demo in apps/www/registry/demos that renders
|
|
178
|
+
* in the docs, and every one of those renders a measurement. A plausible
|
|
179
|
+
* reference range in a demo is a reference range somebody will read as theirs,
|
|
180
|
+
* so the demos cite this string instead: one literal, shared by all of them,
|
|
181
|
+
* saying in the reader's own language that the numbers beside it mean nothing.
|
|
182
|
+
* `ReferenceRange.source` in an example is always this and never a laboratory,
|
|
183
|
+
* a guideline body, a device manufacturer or a study.
|
|
184
|
+
*/
|
|
185
|
+
export const EXAMPLE_SOURCE = "Example data. Not a reference range";
|
|
186
|
+
/** Every unit this system can speak, sorted by id. Generated from `tokens/units.json`. */
|
|
187
|
+
export const UNITS = [
|
|
188
|
+
{
|
|
189
|
+
id: "beat-per-minute",
|
|
190
|
+
symbol: "bpm",
|
|
191
|
+
spoken: "beat per minute",
|
|
192
|
+
plural: "beats per minute",
|
|
193
|
+
measures: "rate",
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
id: "celsius",
|
|
197
|
+
symbol: "°C",
|
|
198
|
+
spoken: "degree Celsius",
|
|
199
|
+
plural: "degrees Celsius",
|
|
200
|
+
measures: "temperature",
|
|
201
|
+
joined: true,
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
id: "centimetre",
|
|
205
|
+
symbol: "cm",
|
|
206
|
+
spoken: "centimetre",
|
|
207
|
+
plural: "centimetres",
|
|
208
|
+
measures: "length",
|
|
209
|
+
},
|
|
210
|
+
{
|
|
211
|
+
id: "fahrenheit",
|
|
212
|
+
symbol: "°F",
|
|
213
|
+
spoken: "degree Fahrenheit",
|
|
214
|
+
plural: "degrees Fahrenheit",
|
|
215
|
+
measures: "temperature",
|
|
216
|
+
joined: true,
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
id: "foot",
|
|
220
|
+
symbol: "ft",
|
|
221
|
+
spoken: "foot",
|
|
222
|
+
plural: "feet",
|
|
223
|
+
measures: "length",
|
|
224
|
+
},
|
|
225
|
+
{
|
|
226
|
+
id: "gram",
|
|
227
|
+
symbol: "g",
|
|
228
|
+
spoken: "gram",
|
|
229
|
+
plural: "grams",
|
|
230
|
+
measures: "mass",
|
|
231
|
+
},
|
|
232
|
+
{
|
|
233
|
+
id: "inch",
|
|
234
|
+
symbol: "in",
|
|
235
|
+
spoken: "inch",
|
|
236
|
+
plural: "inches",
|
|
237
|
+
measures: "length",
|
|
238
|
+
},
|
|
239
|
+
{
|
|
240
|
+
id: "kilocalorie",
|
|
241
|
+
symbol: "kcal",
|
|
242
|
+
spoken: "kilocalorie",
|
|
243
|
+
plural: "kilocalories",
|
|
244
|
+
measures: "energy",
|
|
245
|
+
},
|
|
246
|
+
{
|
|
247
|
+
id: "kilogram",
|
|
248
|
+
symbol: "kg",
|
|
249
|
+
spoken: "kilogram",
|
|
250
|
+
plural: "kilograms",
|
|
251
|
+
measures: "mass",
|
|
252
|
+
},
|
|
253
|
+
{
|
|
254
|
+
id: "kilojoule",
|
|
255
|
+
symbol: "kJ",
|
|
256
|
+
spoken: "kilojoule",
|
|
257
|
+
plural: "kilojoules",
|
|
258
|
+
measures: "energy",
|
|
259
|
+
},
|
|
260
|
+
{
|
|
261
|
+
id: "kilometre",
|
|
262
|
+
symbol: "km",
|
|
263
|
+
spoken: "kilometre",
|
|
264
|
+
plural: "kilometres",
|
|
265
|
+
measures: "length",
|
|
266
|
+
},
|
|
267
|
+
{
|
|
268
|
+
id: "metre",
|
|
269
|
+
symbol: "m",
|
|
270
|
+
spoken: "metre",
|
|
271
|
+
plural: "metres",
|
|
272
|
+
measures: "length",
|
|
273
|
+
},
|
|
274
|
+
{
|
|
275
|
+
id: "microgram-per-litre",
|
|
276
|
+
symbol: "µg/L",
|
|
277
|
+
spoken: "microgram per litre",
|
|
278
|
+
plural: "micrograms per litre",
|
|
279
|
+
measures: "mass concentration",
|
|
280
|
+
},
|
|
281
|
+
{
|
|
282
|
+
id: "mile",
|
|
283
|
+
symbol: "mi",
|
|
284
|
+
spoken: "mile",
|
|
285
|
+
plural: "miles",
|
|
286
|
+
measures: "length",
|
|
287
|
+
},
|
|
288
|
+
{
|
|
289
|
+
id: "milligram-per-decilitre",
|
|
290
|
+
symbol: "mg/dL",
|
|
291
|
+
spoken: "milligram per decilitre",
|
|
292
|
+
plural: "milligrams per decilitre",
|
|
293
|
+
measures: "mass concentration",
|
|
294
|
+
},
|
|
295
|
+
{
|
|
296
|
+
id: "millimetre-of-mercury",
|
|
297
|
+
symbol: "mmHg",
|
|
298
|
+
spoken: "millimetre of mercury",
|
|
299
|
+
plural: "millimetres of mercury",
|
|
300
|
+
measures: "pressure",
|
|
301
|
+
},
|
|
302
|
+
{
|
|
303
|
+
id: "millimole-per-litre",
|
|
304
|
+
symbol: "mmol/L",
|
|
305
|
+
spoken: "millimole per litre",
|
|
306
|
+
plural: "millimoles per litre",
|
|
307
|
+
measures: "amount-of-substance concentration",
|
|
308
|
+
},
|
|
309
|
+
{
|
|
310
|
+
id: "millimole-per-mole",
|
|
311
|
+
symbol: "mmol/mol",
|
|
312
|
+
spoken: "millimole per mole",
|
|
313
|
+
plural: "millimoles per mole",
|
|
314
|
+
measures: "amount-of-substance ratio",
|
|
315
|
+
},
|
|
316
|
+
{
|
|
317
|
+
id: "per-cent",
|
|
318
|
+
symbol: "%",
|
|
319
|
+
spoken: "per cent",
|
|
320
|
+
plural: "per cent",
|
|
321
|
+
measures: "proportion",
|
|
322
|
+
joined: true,
|
|
323
|
+
},
|
|
324
|
+
{
|
|
325
|
+
id: "pound",
|
|
326
|
+
symbol: "lb",
|
|
327
|
+
spoken: "pound",
|
|
328
|
+
plural: "pounds",
|
|
329
|
+
measures: "mass",
|
|
330
|
+
},
|
|
331
|
+
{
|
|
332
|
+
id: "step",
|
|
333
|
+
symbol: "steps",
|
|
334
|
+
spoken: "step",
|
|
335
|
+
plural: "steps",
|
|
336
|
+
measures: "count",
|
|
337
|
+
},
|
|
338
|
+
{
|
|
339
|
+
id: "stone",
|
|
340
|
+
symbol: "st",
|
|
341
|
+
spoken: "stone",
|
|
342
|
+
plural: "stone",
|
|
343
|
+
measures: "mass",
|
|
344
|
+
},
|
|
345
|
+
];
|
|
346
|
+
/**
|
|
347
|
+
* The lookup `findUnit()` reads, derived from `UNITS` rather than emitted twice.
|
|
348
|
+
*
|
|
349
|
+
* Keyed by the exact symbol, case included. There is no fuzzy matching, because
|
|
350
|
+
* a table that guesses which unit somebody meant is a table that will one day
|
|
351
|
+
* guess wrong about a concentration.
|
|
352
|
+
*/
|
|
353
|
+
export const UNITS_BY_SYMBOL = Object.fromEntries(UNITS.map((unit) => [unit.symbol, unit]));
|
|
354
|
+
/** Every convertible ordered pair, composed by the generator. Never authored by hand. */
|
|
355
|
+
export const UNIT_CONVERSIONS = [
|
|
356
|
+
{
|
|
357
|
+
from: "°C",
|
|
358
|
+
to: "°F",
|
|
359
|
+
numerator: 9,
|
|
360
|
+
denominator: 5,
|
|
361
|
+
offsetNumerator: 32,
|
|
362
|
+
offsetDenominator: 1,
|
|
363
|
+
basis: ["The Fahrenheit scale is defined against Celsius: a Fahrenheit degree is exactly five ninths of a Celsius degree and the scales meet where 32 °F is 0 °C, so °C = °F × 5/9 − 160/9. This conversion is affine rather than a ratio, which is why a temperature and a temperature DIFFERENCE do not convert the same way. 2 °C of change is 3.6 °F of change, not 35.6 °F."],
|
|
364
|
+
},
|
|
365
|
+
{
|
|
366
|
+
from: "°F",
|
|
367
|
+
to: "°C",
|
|
368
|
+
numerator: 5,
|
|
369
|
+
denominator: 9,
|
|
370
|
+
offsetNumerator: -160,
|
|
371
|
+
offsetDenominator: 9,
|
|
372
|
+
basis: ["The Fahrenheit scale is defined against Celsius: a Fahrenheit degree is exactly five ninths of a Celsius degree and the scales meet where 32 °F is 0 °C, so °C = °F × 5/9 − 160/9. This conversion is affine rather than a ratio, which is why a temperature and a temperature DIFFERENCE do not convert the same way. 2 °C of change is 3.6 °F of change, not 35.6 °F."],
|
|
373
|
+
},
|
|
374
|
+
{
|
|
375
|
+
from: "g",
|
|
376
|
+
to: "kg",
|
|
377
|
+
numerator: 1,
|
|
378
|
+
denominator: 1000,
|
|
379
|
+
offsetNumerator: 0,
|
|
380
|
+
offsetDenominator: 1,
|
|
381
|
+
basis: ["The SI prefix 'kilo' is exactly one thousand. This is a definition of the prefix, not a measurement of anything."],
|
|
382
|
+
},
|
|
383
|
+
{
|
|
384
|
+
from: "g",
|
|
385
|
+
to: "lb",
|
|
386
|
+
numerator: 100000,
|
|
387
|
+
denominator: 45359237,
|
|
388
|
+
offsetNumerator: 0,
|
|
389
|
+
offsetDenominator: 1,
|
|
390
|
+
basis: ["The SI prefix 'kilo' is exactly one thousand. This is a definition of the prefix, not a measurement of anything.", "The international avoirdupois pound is defined as exactly 0.45359237 kilograms by the 1959 international yard and pound agreement. An exact definition, adopted by every signatory, and not a rounded measurement."],
|
|
391
|
+
},
|
|
392
|
+
{
|
|
393
|
+
from: "g",
|
|
394
|
+
to: "st",
|
|
395
|
+
numerator: 50000,
|
|
396
|
+
denominator: 317514659,
|
|
397
|
+
offsetNumerator: 0,
|
|
398
|
+
offsetDenominator: 1,
|
|
399
|
+
basis: ["The SI prefix 'kilo' is exactly one thousand. This is a definition of the prefix, not a measurement of anything.", "One stone is exactly fourteen avoirdupois pounds, and one pound is exactly 0.45359237 kilograms; fourteen times that is 6.35029318 kilograms exactly. Two definitions composed, no measurement involved. Note the plural: British body weight is 'eleven stone', not 'eleven stones'."],
|
|
400
|
+
},
|
|
401
|
+
{
|
|
402
|
+
from: "kg",
|
|
403
|
+
to: "g",
|
|
404
|
+
numerator: 1000,
|
|
405
|
+
denominator: 1,
|
|
406
|
+
offsetNumerator: 0,
|
|
407
|
+
offsetDenominator: 1,
|
|
408
|
+
basis: ["The SI prefix 'kilo' is exactly one thousand. This is a definition of the prefix, not a measurement of anything."],
|
|
409
|
+
},
|
|
410
|
+
{
|
|
411
|
+
from: "kg",
|
|
412
|
+
to: "lb",
|
|
413
|
+
numerator: 100000000,
|
|
414
|
+
denominator: 45359237,
|
|
415
|
+
offsetNumerator: 0,
|
|
416
|
+
offsetDenominator: 1,
|
|
417
|
+
basis: ["The international avoirdupois pound is defined as exactly 0.45359237 kilograms by the 1959 international yard and pound agreement. An exact definition, adopted by every signatory, and not a rounded measurement."],
|
|
418
|
+
},
|
|
419
|
+
{
|
|
420
|
+
from: "kg",
|
|
421
|
+
to: "st",
|
|
422
|
+
numerator: 50000000,
|
|
423
|
+
denominator: 317514659,
|
|
424
|
+
offsetNumerator: 0,
|
|
425
|
+
offsetDenominator: 1,
|
|
426
|
+
basis: ["One stone is exactly fourteen avoirdupois pounds, and one pound is exactly 0.45359237 kilograms; fourteen times that is 6.35029318 kilograms exactly. Two definitions composed, no measurement involved. Note the plural: British body weight is 'eleven stone', not 'eleven stones'."],
|
|
427
|
+
},
|
|
428
|
+
{
|
|
429
|
+
from: "lb",
|
|
430
|
+
to: "g",
|
|
431
|
+
numerator: 45359237,
|
|
432
|
+
denominator: 100000,
|
|
433
|
+
offsetNumerator: 0,
|
|
434
|
+
offsetDenominator: 1,
|
|
435
|
+
basis: ["The international avoirdupois pound is defined as exactly 0.45359237 kilograms by the 1959 international yard and pound agreement. An exact definition, adopted by every signatory, and not a rounded measurement.", "The SI prefix 'kilo' is exactly one thousand. This is a definition of the prefix, not a measurement of anything."],
|
|
436
|
+
},
|
|
437
|
+
{
|
|
438
|
+
from: "lb",
|
|
439
|
+
to: "kg",
|
|
440
|
+
numerator: 45359237,
|
|
441
|
+
denominator: 100000000,
|
|
442
|
+
offsetNumerator: 0,
|
|
443
|
+
offsetDenominator: 1,
|
|
444
|
+
basis: ["The international avoirdupois pound is defined as exactly 0.45359237 kilograms by the 1959 international yard and pound agreement. An exact definition, adopted by every signatory, and not a rounded measurement."],
|
|
445
|
+
},
|
|
446
|
+
{
|
|
447
|
+
from: "lb",
|
|
448
|
+
to: "st",
|
|
449
|
+
numerator: 1,
|
|
450
|
+
denominator: 14,
|
|
451
|
+
offsetNumerator: 0,
|
|
452
|
+
offsetDenominator: 1,
|
|
453
|
+
basis: ["The international avoirdupois pound is defined as exactly 0.45359237 kilograms by the 1959 international yard and pound agreement. An exact definition, adopted by every signatory, and not a rounded measurement.", "One stone is exactly fourteen avoirdupois pounds, and one pound is exactly 0.45359237 kilograms; fourteen times that is 6.35029318 kilograms exactly. Two definitions composed, no measurement involved. Note the plural: British body weight is 'eleven stone', not 'eleven stones'."],
|
|
454
|
+
},
|
|
455
|
+
{
|
|
456
|
+
from: "st",
|
|
457
|
+
to: "g",
|
|
458
|
+
numerator: 317514659,
|
|
459
|
+
denominator: 50000,
|
|
460
|
+
offsetNumerator: 0,
|
|
461
|
+
offsetDenominator: 1,
|
|
462
|
+
basis: ["One stone is exactly fourteen avoirdupois pounds, and one pound is exactly 0.45359237 kilograms; fourteen times that is 6.35029318 kilograms exactly. Two definitions composed, no measurement involved. Note the plural: British body weight is 'eleven stone', not 'eleven stones'.", "The SI prefix 'kilo' is exactly one thousand. This is a definition of the prefix, not a measurement of anything."],
|
|
463
|
+
},
|
|
464
|
+
{
|
|
465
|
+
from: "st",
|
|
466
|
+
to: "kg",
|
|
467
|
+
numerator: 317514659,
|
|
468
|
+
denominator: 50000000,
|
|
469
|
+
offsetNumerator: 0,
|
|
470
|
+
offsetDenominator: 1,
|
|
471
|
+
basis: ["One stone is exactly fourteen avoirdupois pounds, and one pound is exactly 0.45359237 kilograms; fourteen times that is 6.35029318 kilograms exactly. Two definitions composed, no measurement involved. Note the plural: British body weight is 'eleven stone', not 'eleven stones'."],
|
|
472
|
+
},
|
|
473
|
+
{
|
|
474
|
+
from: "st",
|
|
475
|
+
to: "lb",
|
|
476
|
+
numerator: 14,
|
|
477
|
+
denominator: 1,
|
|
478
|
+
offsetNumerator: 0,
|
|
479
|
+
offsetDenominator: 1,
|
|
480
|
+
basis: ["One stone is exactly fourteen avoirdupois pounds, and one pound is exactly 0.45359237 kilograms; fourteen times that is 6.35029318 kilograms exactly. Two definitions composed, no measurement involved. Note the plural: British body weight is 'eleven stone', not 'eleven stones'.", "The international avoirdupois pound is defined as exactly 0.45359237 kilograms by the 1959 international yard and pound agreement. An exact definition, adopted by every signatory, and not a rounded measurement."],
|
|
481
|
+
},
|
|
482
|
+
];
|
|
483
|
+
/** Conversions this system refuses to publish, and why. Generated from `tokens/units.json`. */
|
|
484
|
+
export const REFUSED_CONVERSIONS = [
|
|
485
|
+
{
|
|
486
|
+
between: ["kcal", "kJ"],
|
|
487
|
+
reason: "There is more than one calorie. The thermochemical calorie is exactly 4.184 joules and the fifteen-degree calorie is not, and food energy labelling picks one by regulation rather than by physics. Naming a single factor here would hide which calorie was meant, so the pair is refused until this file can carry the choice explicitly.",
|
|
488
|
+
docs: "health/numbers",
|
|
489
|
+
},
|
|
490
|
+
{
|
|
491
|
+
between: ["mmol/L", "mg/dL"],
|
|
492
|
+
reason: "Molar concentration and mass concentration are related by the molar mass of the substance being measured, which is a property of the SUBSTANCE and not of either unit. Glucose, cholesterol and creatinine each carry a different factor, and this table does not know which analyte a reading is. A single published factor here would be applied to all three by somebody in a hurry, and the answer would be wrong by a multiple rather than by a rounding.",
|
|
493
|
+
docs: "health/numbers",
|
|
494
|
+
},
|
|
495
|
+
{
|
|
496
|
+
between: ["mmol/mol", "%"],
|
|
497
|
+
reason: "The two ways of reporting HbA1c are related by a fitted regression between two assay standardisations, not by an exact definition. A regression is a measurement with a residual, it is periodically re-fitted, and it belongs to the laboratory that reports the result. This table carries definitions only.",
|
|
498
|
+
docs: "health/numbers",
|
|
499
|
+
},
|
|
500
|
+
];
|
|
501
|
+
/**
|
|
502
|
+
* The unit a symbol names, or `undefined` when this system has never heard of it.
|
|
503
|
+
*
|
|
504
|
+
* `undefined` rather than a fabricated entry, because the caller's honest
|
|
505
|
+
* response to an unknown symbol is to render it as written - awkward to listen
|
|
506
|
+
* to, but true - and never to guess at a pronunciation.
|
|
507
|
+
*/
|
|
508
|
+
export function findUnit(symbol) {
|
|
509
|
+
return Object.prototype.hasOwnProperty.call(UNITS_BY_SYMBOL, symbol)
|
|
510
|
+
? UNITS_BY_SYMBOL[symbol]
|
|
511
|
+
: undefined;
|
|
512
|
+
}
|
|
513
|
+
/**
|
|
514
|
+
* How a screen reader should say this unit for this count.
|
|
515
|
+
*
|
|
516
|
+
* `count` is the value as DISPLAYED, after any rounding, because the words
|
|
517
|
+
* follow what is on the screen rather than what was in the database. English
|
|
518
|
+
* takes the singular for exactly one and the plural for everything else, zero
|
|
519
|
+
* included: "0 kilograms", "1 kilogram", "1.5 kilograms".
|
|
520
|
+
*
|
|
521
|
+
* The known limit, stated rather than hidden: a value shown as "1.0" because
|
|
522
|
+
* its measurement has one decimal place is still counted as one and is spoken
|
|
523
|
+
* "1.0 kilogram". Both wordings are defensible in English and neither is
|
|
524
|
+
* unsafe. The larger limit is that these words are British English in every
|
|
525
|
+
* locale; `tokens/units.json` has no translations yet and does not pretend to.
|
|
526
|
+
*/
|
|
527
|
+
export function spokenUnit(symbol, count) {
|
|
528
|
+
const unit = findUnit(symbol);
|
|
529
|
+
if (unit === undefined)
|
|
530
|
+
return undefined;
|
|
531
|
+
return Math.abs(count) === 1 ? unit.spoken : unit.plural;
|
|
532
|
+
}
|
|
533
|
+
/** The authored conversion between two symbols, or `undefined` when there is none. */
|
|
534
|
+
export function unitConversion(from, to) {
|
|
535
|
+
return UNIT_CONVERSIONS.find((row) => row.from === from && row.to === to);
|
|
536
|
+
}
|
|
537
|
+
/**
|
|
538
|
+
* One value in another unit, or `undefined` when this system does not own the factor.
|
|
539
|
+
*
|
|
540
|
+
* `undefined` is the whole contract. mmol/L to mg/dL is not here, and it is
|
|
541
|
+
* not here because the factor depends on the molar mass of the substance being
|
|
542
|
+
* measured rather than on either unit - so a component that substituted a
|
|
543
|
+
* default would be converting cholesterol with the factor for glucose. Render
|
|
544
|
+
* "we do not have this"; never a number.
|
|
545
|
+
*/
|
|
546
|
+
export function convertUnit(value, from, to) {
|
|
547
|
+
const conversion = unitConversion(from, to);
|
|
548
|
+
if (conversion === undefined)
|
|
549
|
+
return undefined;
|
|
550
|
+
return ((value * conversion.numerator) / conversion.denominator +
|
|
551
|
+
conversion.offsetNumerator / conversion.offsetDenominator);
|
|
552
|
+
}
|
|
553
|
+
/** The table `warnOnce()` reads. Generated from `tokens/errors.json`. */
|
|
554
|
+
export const OPSIN_ERRORS = {
|
|
555
|
+
"OPSIN-0001": {
|
|
556
|
+
code: "OPSIN-0001",
|
|
557
|
+
severity: "safety",
|
|
558
|
+
title: "Both a category and a status were given to one surface",
|
|
559
|
+
message: "<{component}> received both `category=\"{category}\"` and `status=\"{status}\"`. A surface carries one axis. Set the category on the surface and render the status as a StatusPill inside it.",
|
|
560
|
+
docs: "health/two-colour-axes",
|
|
561
|
+
params: ["component", "category", "status"],
|
|
562
|
+
},
|
|
563
|
+
"OPSIN-0002": {
|
|
564
|
+
code: "OPSIN-0002",
|
|
565
|
+
severity: "safety",
|
|
566
|
+
title: "A status was rendered without a word",
|
|
567
|
+
message: "<{component}> has `status=\"{status}\"` and no accessible label. Status is carried by colour, icon and word together; colour alone does not survive grayscale, colour-vision deficiency or a black-and-white printout.",
|
|
568
|
+
docs: "health/two-colour-axes",
|
|
569
|
+
params: ["component", "status"],
|
|
570
|
+
},
|
|
571
|
+
"OPSIN-0003": {
|
|
572
|
+
code: "OPSIN-0003",
|
|
573
|
+
severity: "safety",
|
|
574
|
+
title: "A value was rendered without a unit",
|
|
575
|
+
message: "<Value> received `{value}` with no `unit`. A bare number in a health context is ambiguous between unit systems: the same digits are one reading in mmol/L and a very different one in mg/dL, and nothing on the surface tells the reader which was meant. Pass the unit the reading was measured in. If the number has no unit by design, such as a composite score, pass `unit={null}` to say so; the warning stays for a caller who simply forgot.",
|
|
576
|
+
docs: "health/numbers",
|
|
577
|
+
params: ["value", "null"],
|
|
578
|
+
},
|
|
579
|
+
"OPSIN-0004": {
|
|
580
|
+
code: "OPSIN-0004",
|
|
581
|
+
severity: "safety",
|
|
582
|
+
title: "A reference range was rendered without a source",
|
|
583
|
+
message: "<{component}> was given a `range` with no `range.source`. Name whose range it is: a laboratory, a device maker, or a clinician. A range is a comparison somebody chose and not a fact about the reader.",
|
|
584
|
+
docs: "health/reference-ranges",
|
|
585
|
+
params: ["component"],
|
|
586
|
+
},
|
|
587
|
+
"OPSIN-0005": {
|
|
588
|
+
code: "OPSIN-0005",
|
|
589
|
+
severity: "safety",
|
|
590
|
+
title: "More than one urgent surface on a screen",
|
|
591
|
+
message: "{count} surfaces on this screen have `status=\"urgent\"`. The escalation budget is one. When everything is urgent, nothing is.",
|
|
592
|
+
docs: "health/alerts",
|
|
593
|
+
params: ["count"],
|
|
594
|
+
},
|
|
595
|
+
"OPSIN-0006": {
|
|
596
|
+
code: "OPSIN-0006",
|
|
597
|
+
severity: "safety",
|
|
598
|
+
title: "A banned word appeared in a component's copy",
|
|
599
|
+
message: "The string \"{text}\" contains \"{word}\", which this system does not use. Write \"{replacement}\" instead.",
|
|
600
|
+
docs: "reference/plain-english",
|
|
601
|
+
params: ["text", "word", "replacement"],
|
|
602
|
+
},
|
|
603
|
+
"OPSIN-0007": {
|
|
604
|
+
code: "OPSIN-0007",
|
|
605
|
+
severity: "safety",
|
|
606
|
+
title: "A health value was animated",
|
|
607
|
+
message: "<{component}> is animating a health value with `{token}`. A value that overshoots has displayed, for one frame, a number that is not true. Use `spring-calm`, or render the final value immediately.",
|
|
608
|
+
docs: "health/alerts",
|
|
609
|
+
params: ["component", "token"],
|
|
610
|
+
},
|
|
611
|
+
"OPSIN-0008": {
|
|
612
|
+
code: "OPSIN-0008",
|
|
613
|
+
severity: "correctness",
|
|
614
|
+
title: "A raw colour value was passed where a token is required",
|
|
615
|
+
message: "<{component}> received `{prop}=\"{value}\"`. Components take a category or a status, never a colour. A raw value cannot be re-derived for dark mode, for Display-P3, or for a reader who has asked for more contrast.",
|
|
616
|
+
docs: "theming",
|
|
617
|
+
params: ["component", "prop", "value"],
|
|
618
|
+
},
|
|
619
|
+
"OPSIN-0009": {
|
|
620
|
+
code: "OPSIN-0009",
|
|
621
|
+
severity: "correctness",
|
|
622
|
+
title: "A primitive token was referenced from a component",
|
|
623
|
+
message: "`{token}` is a primitive-tier token. Components consume roles. Primitives may be re-tuned in a minor release; roles are covered by the versioning policy.",
|
|
624
|
+
docs: "theming",
|
|
625
|
+
params: ["token"],
|
|
626
|
+
},
|
|
627
|
+
"OPSIN-0010": {
|
|
628
|
+
code: "OPSIN-0010",
|
|
629
|
+
severity: "correctness",
|
|
630
|
+
title: "An unknown category was requested",
|
|
631
|
+
message: "`category=\"{category}\"` is not one of {known}. Adding a category means adding a ramp, not passing a new string.",
|
|
632
|
+
docs: "theming",
|
|
633
|
+
params: ["category", "known"],
|
|
634
|
+
},
|
|
635
|
+
"OPSIN-0011": {
|
|
636
|
+
code: "OPSIN-0011",
|
|
637
|
+
severity: "correctness",
|
|
638
|
+
title: "`unknown` was used as a status level",
|
|
639
|
+
message: "`unknown` is the absence of an assertion, not a fifth level. Use it when there is no reading or no range; do not use it to mean 'probably fine'.",
|
|
640
|
+
docs: "health/trends",
|
|
641
|
+
params: [],
|
|
642
|
+
},
|
|
643
|
+
"OPSIN-0012": {
|
|
644
|
+
code: "OPSIN-0012",
|
|
645
|
+
severity: "correctness",
|
|
646
|
+
title: "A trend was drawn from too few points",
|
|
647
|
+
message: "<TrendSparkline> received {count} points and `minimumPoints` is {minimum}. Two readings are not a trend, and drawing one implies a direction the data does not support.",
|
|
648
|
+
docs: "health/trends",
|
|
649
|
+
params: ["count", "minimum"],
|
|
650
|
+
},
|
|
651
|
+
"OPSIN-0013": {
|
|
652
|
+
code: "OPSIN-0013",
|
|
653
|
+
severity: "correctness",
|
|
654
|
+
title: "A chart's y-axis was truncated",
|
|
655
|
+
message: "<{component}> has `yAxisMin={min}` on a health value. Truncating the axis exaggerates change; a 2% move drawn across the full height of a card reads as a crisis.",
|
|
656
|
+
docs: "foundations/data-visualisation",
|
|
657
|
+
params: ["component", "min"],
|
|
658
|
+
},
|
|
659
|
+
"OPSIN-0014": {
|
|
660
|
+
code: "OPSIN-0014",
|
|
661
|
+
severity: "correctness",
|
|
662
|
+
title: "Category colours were used as chart series colours",
|
|
663
|
+
message: "This chart is colouring {count} series from the category ramps. Category colours identify what a reading is about; using them for series turns an identity into an arbitrary label.",
|
|
664
|
+
docs: "foundations/data-visualisation",
|
|
665
|
+
params: ["count"],
|
|
666
|
+
},
|
|
667
|
+
"OPSIN-0015": {
|
|
668
|
+
code: "OPSIN-0015",
|
|
669
|
+
severity: "correctness",
|
|
670
|
+
title: "A touch target is below the floor",
|
|
671
|
+
message: "<{component}> renders a {width}x{height} hit area. The floor is 44x44, applied to the hit area rather than to the visible box.",
|
|
672
|
+
docs: "foundations/accessibility",
|
|
673
|
+
params: ["component", "width", "height"],
|
|
674
|
+
},
|
|
675
|
+
"OPSIN-0016": {
|
|
676
|
+
code: "OPSIN-0016",
|
|
677
|
+
severity: "correctness",
|
|
678
|
+
title: "A stale reading was rendered as current",
|
|
679
|
+
message: "<{component}> was given a reading from {age} ago with no staleness treatment. A number with no time attached is read as 'now'.",
|
|
680
|
+
docs: "health/trends",
|
|
681
|
+
params: ["component", "age"],
|
|
682
|
+
},
|
|
683
|
+
"OPSIN-0017": {
|
|
684
|
+
code: "OPSIN-0017",
|
|
685
|
+
severity: "hygiene",
|
|
686
|
+
title: "More than three translucent surfaces are composited",
|
|
687
|
+
message: "{count} translucent material rungs are visible at once; the budget is 3. Beyond three the blur cost is measurable on mid-range devices and the backdrop is unreadable anyway.",
|
|
688
|
+
docs: "foundations/materials",
|
|
689
|
+
params: ["count"],
|
|
690
|
+
},
|
|
691
|
+
"OPSIN-0018": {
|
|
692
|
+
code: "OPSIN-0018",
|
|
693
|
+
severity: "hygiene",
|
|
694
|
+
title: "A deprecated token was referenced",
|
|
695
|
+
message: "`{token}` was deprecated in {version} and is replaced by `{replacement}`. It will be removed in {removal}.",
|
|
696
|
+
docs: "changelog",
|
|
697
|
+
params: ["token", "version", "replacement", "removal"],
|
|
698
|
+
},
|
|
699
|
+
"OPSIN-0019": {
|
|
700
|
+
code: "OPSIN-0019",
|
|
701
|
+
severity: "hygiene",
|
|
702
|
+
title: "The token stylesheet was not loaded",
|
|
703
|
+
message: "`--opsin-tokens-generated` is not set on :root. @opsinjs/tokens/tokens.css has not been loaded, so every component is falling back to authored defaults. Import @opsinjs/react/styles.css, or @opsinjs/react/tailwind.css after Tailwind.",
|
|
704
|
+
docs: "theming",
|
|
705
|
+
params: [],
|
|
706
|
+
},
|
|
707
|
+
"OPSIN-0020": {
|
|
708
|
+
code: "OPSIN-0020",
|
|
709
|
+
severity: "hygiene",
|
|
710
|
+
title: "Two theme providers are mounted",
|
|
711
|
+
message: "More than one theme provider is writing the `dark` class. Two providers race on first paint and produce a flash of the wrong theme.",
|
|
712
|
+
docs: "theming",
|
|
713
|
+
params: [],
|
|
714
|
+
},
|
|
715
|
+
"OPSIN-0021": {
|
|
716
|
+
code: "OPSIN-0021",
|
|
717
|
+
severity: "safety",
|
|
718
|
+
title: "A status outside the four levels was passed",
|
|
719
|
+
message: "<{component}> received `status=\"{status}\"`, which is not one of the four levels. The vocabulary is fixed at steady, watch, attention and urgent; a component that accepted a fifth would be inventing a verdict. Nothing was rendered.",
|
|
720
|
+
docs: "health/two-colour-axes",
|
|
721
|
+
params: ["component", "status"],
|
|
722
|
+
},
|
|
723
|
+
};
|
|
724
|
+
/**
|
|
725
|
+
* Where a code's page lives: the canonical origin and the docs base, hardcoded
|
|
726
|
+
* on purpose. This file is published in @opsinjs/react and runs in projects
|
|
727
|
+
* that have no `lib/routes.ts` and no way to resolve a page id, and a warning
|
|
728
|
+
* whose link is a bare slug sends the reader nowhere.
|
|
729
|
+
*/
|
|
730
|
+
const OPSIN_DOCS_BASE = "https://opsinjs.pensievelabs.org/docs/";
|
|
731
|
+
/**
|
|
732
|
+
* Every message already emitted this session.
|
|
733
|
+
*
|
|
734
|
+
* Declared but not created. In a production bundle the guard at the top of
|
|
735
|
+
* `warnOnce` is statically false, the body is dead code, and this stays
|
|
736
|
+
* `undefined`, so the set is not merely unused in production. It is never
|
|
737
|
+
* allocated and can never retain a string. In development it is created on the
|
|
738
|
+
* first warning and lives for the session, which is what "once" means.
|
|
739
|
+
*/
|
|
740
|
+
let warnedKeys;
|
|
741
|
+
/**
|
|
742
|
+
* The parameters that identify WHO raised a warning, as opposed to what they
|
|
743
|
+
* happened to be holding when they raised it. Only these take part in the
|
|
744
|
+
* de-duplication key.
|
|
745
|
+
*
|
|
746
|
+
* `count`, `value`, `text`, `width`, `height`, `age`, `minimum`, `min`, `known`,
|
|
747
|
+
* `version`, `removal` and `replacement` are all deliberately absent: each of
|
|
748
|
+
* them either varies per render or is derived from the table itself, and
|
|
749
|
+
* including any one of them turns "warn once" into "warn every frame".
|
|
750
|
+
*/
|
|
751
|
+
const IDENTITY_PARAMS = [
|
|
752
|
+
"component",
|
|
753
|
+
"prop",
|
|
754
|
+
"slot",
|
|
755
|
+
"token",
|
|
756
|
+
"category",
|
|
757
|
+
"status",
|
|
758
|
+
"word",
|
|
759
|
+
];
|
|
760
|
+
/**
|
|
761
|
+
* True in development, and false wherever that cannot be established.
|
|
762
|
+
*
|
|
763
|
+
* Exported because a component must never reach for `process` itself: this is
|
|
764
|
+
* the one place in the shipped substrate that knows how the environment is
|
|
765
|
+
* detected, and a component that guessed differently would log in production.
|
|
766
|
+
*
|
|
767
|
+
* WRITE THE LAST TERM AS A PLAIN MEMBER EXPRESSION. `process.env.NODE_ENV` is
|
|
768
|
+
* the exact text a bundler's define plugin substitutes; `process?.env?.NODE_ENV`
|
|
769
|
+
* and `process.env?.NODE_ENV` are not, so they survive into the browser bundle
|
|
770
|
+
* and are then evaluated against a bundler's empty `process` shim, which says
|
|
771
|
+
* "not production" and turns every development reproach into console output an
|
|
772
|
+
* end user sees. That is not hypothetical: it is what this line did until it was
|
|
773
|
+
* written this way. The two `typeof` guards ahead of it are for the environment
|
|
774
|
+
* a bundler never touched, meaning a plain ESM import with no build step, where
|
|
775
|
+
* `process` really is absent and the bare member expression would throw.
|
|
776
|
+
*/
|
|
777
|
+
export function isDevelopment() {
|
|
778
|
+
return (typeof process !== "undefined" &&
|
|
779
|
+
typeof process.env !== "undefined" &&
|
|
780
|
+
process.env.NODE_ENV !== "production");
|
|
781
|
+
}
|
|
782
|
+
/** The point at which the warning channel stops rather than grows. */
|
|
783
|
+
const MAX_WARNED_KEYS = 500;
|
|
784
|
+
/** Not a real key. It only records that the cap notice has been printed. */
|
|
785
|
+
const CAP_KEY = "\u0000cap";
|
|
786
|
+
/**
|
|
787
|
+
* Report a defect in development, once, and never do anything else.
|
|
788
|
+
*
|
|
789
|
+
* `tokens/errors.json`'s own policy block is the specification, and it is
|
|
790
|
+
* quoted here so the next reader does not have to relitigate it:
|
|
791
|
+
*
|
|
792
|
+
* "Warnings are emitted in development only, once per offending call site,
|
|
793
|
+
* through console.warn. Nothing in this list throws, and nothing in this list
|
|
794
|
+
* is emitted in production: a health product must not be made to crash by a
|
|
795
|
+
* documentation-quality complaint."
|
|
796
|
+
*
|
|
797
|
+
* So: several component specifications say a violation "should fail loudly in
|
|
798
|
+
* development". Loudly, yes. Fail, no. This function warns and returns, in
|
|
799
|
+
* every case, including the cases where it has itself been called wrongly.
|
|
800
|
+
*
|
|
801
|
+
* WHAT "ONCE PER CALL SITE" MEANS AT RUNTIME. A call site is not observable
|
|
802
|
+
* from inside a function. The only handle on one is a stack trace, and a stack
|
|
803
|
+
* trace is minified in one build, source-mapped in another and absent on the
|
|
804
|
+
* server, which would make the de-duplication key differ between environments
|
|
805
|
+
* that are meant to behave the same. The key used instead is the code plus the
|
|
806
|
+
* IDENTIFYING parameters listed in `IDENTITY_PARAMS` below.
|
|
807
|
+
*
|
|
808
|
+
* It is deliberately NOT the filled message. A third of the codes in the table
|
|
809
|
+
* carry a parameter that changes on every render, such as `{count}` in
|
|
810
|
+
* OPSIN-0005, `{value}` in OPSIN-0003 and `{age}` in OPSIN-0016, so keying on the message
|
|
811
|
+
* would make a `safety` warning fire on every frame of a screen that is already
|
|
812
|
+
* misbehaving, and would grow the key set without bound in a long session. The
|
|
813
|
+
* identifying parameters are the ones that name WHO is at fault rather than what
|
|
814
|
+
* they happened to be holding at the time.
|
|
815
|
+
*
|
|
816
|
+
* Two consequences worth stating rather than leaving to be discovered. A caller
|
|
817
|
+
* may pass `component` even for a code whose message never interpolates it, and
|
|
818
|
+
* doing so buys per-component granularity for free, so components should. And for
|
|
819
|
+
* the three codes that take no parameters, and for any caller that supplies
|
|
820
|
+
* none, the key collapses to the code alone: one warning per session for the
|
|
821
|
+
* whole application. That is coarser than "per call site". It is the most this
|
|
822
|
+
* function can honestly promise without a call site to key on, and it is still
|
|
823
|
+
* the right trade, because a repeated identical complaint teaches nothing and
|
|
824
|
+
* drowns the next one.
|
|
825
|
+
*
|
|
826
|
+
* It survives React's Strict Mode, which invokes a render twice on purpose: the
|
|
827
|
+
* second invocation computes the same key, finds it, and returns without
|
|
828
|
+
* printing.
|
|
829
|
+
*
|
|
830
|
+
* AN UNFILLED PLACEHOLDER IS A DEFECT, AND IT IS NOT THIS FUNCTION'S. A missing
|
|
831
|
+
* parameter leaves its `{brace}` in the message and adds a line saying which
|
|
832
|
+
* ones were not supplied. It does not throw, and it does not swallow the
|
|
833
|
+
* warning: the underlying complaint may be about a reading a person is about to
|
|
834
|
+
* act on, and losing it to a second bug in the component that raised it is the
|
|
835
|
+
* worse of the two outcomes. The visible `{brace}` is the report.
|
|
836
|
+
*/
|
|
837
|
+
export function warnOnce(code, params = {}) {
|
|
838
|
+
/* Fail closed. Every bundler this system supports replaces
|
|
839
|
+
`process.env.NODE_ENV` at build time, so in a production bundle the whole
|
|
840
|
+
body below is dead code and is removed. Where `process` does not exist at
|
|
841
|
+
all, the answer is silence rather than a guess: an environment this file
|
|
842
|
+
cannot identify is not one it may decide to log in. */
|
|
843
|
+
if (!isDevelopment())
|
|
844
|
+
return;
|
|
845
|
+
const error = OPSIN_ERRORS[code];
|
|
846
|
+
if (error === undefined)
|
|
847
|
+
return;
|
|
848
|
+
/* The default parameter covers `undefined` and nothing else, and this file
|
|
849
|
+
ships into JavaScript projects where the types are advice rather than a
|
|
850
|
+
guarantee. A caller who passes `null` gets a warning with its braces
|
|
851
|
+
unfilled, which is the report; a TypeError raised inside the warning
|
|
852
|
+
channel would be the channel breaking the product it is complaining to. */
|
|
853
|
+
const supplied = params ?? {};
|
|
854
|
+
/* The same pattern `placeholders()` in scripts/build-tokens.mts extracts
|
|
855
|
+
with, so what the table says a message needs is what this fills. */
|
|
856
|
+
const missing = [];
|
|
857
|
+
const message = error.message.replace(/\{([A-Za-z][A-Za-z0-9]*)\}/g, (span, name) => {
|
|
858
|
+
const value = supplied[name];
|
|
859
|
+
if (value === undefined) {
|
|
860
|
+
missing.push(name);
|
|
861
|
+
return span;
|
|
862
|
+
}
|
|
863
|
+
return String(value);
|
|
864
|
+
});
|
|
865
|
+
const key = [code, ...IDENTITY_PARAMS.map((name) => supplied[name] ?? "")].join("\u0000");
|
|
866
|
+
if (warnedKeys === undefined)
|
|
867
|
+
warnedKeys = new Set();
|
|
868
|
+
if (warnedKeys.has(key))
|
|
869
|
+
return;
|
|
870
|
+
/* Bounded, because this set is never cleared and a development session can run
|
|
871
|
+
for days. At the cap the channel says so once and then goes quiet, rather
|
|
872
|
+
than either leaking or reverting to warning on every render. A warning
|
|
873
|
+
channel that degrades into noise is one somebody switches off. */
|
|
874
|
+
if (warnedKeys.size >= MAX_WARNED_KEYS) {
|
|
875
|
+
if (!warnedKeys.has(CAP_KEY)) {
|
|
876
|
+
warnedKeys.add(CAP_KEY);
|
|
877
|
+
try {
|
|
878
|
+
console.warn(`[opsinjs] ${MAX_WARNED_KEYS} distinct warnings have been reported in this ` +
|
|
879
|
+
"session, so this channel is now quiet. Fix what is already reported, or " +
|
|
880
|
+
"reload to start counting again.");
|
|
881
|
+
}
|
|
882
|
+
catch {
|
|
883
|
+
/* A patched console is not a reason to take a health product down. */
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
return;
|
|
887
|
+
}
|
|
888
|
+
warnedKeys.add(key);
|
|
889
|
+
const lines = [`[opsinjs] ${code} (${error.severity}): ${message}`];
|
|
890
|
+
if (error.docs !== "")
|
|
891
|
+
lines.push(` → ${OPSIN_DOCS_BASE}${error.docs}`);
|
|
892
|
+
if (missing.length > 0) {
|
|
893
|
+
lines.push(` No value was supplied for ${missing.map((name) => `{${name}}`).join(", ")}. ` +
|
|
894
|
+
"That is a defect in the component that raised this warning, not in the " +
|
|
895
|
+
"code the warning is about.");
|
|
896
|
+
}
|
|
897
|
+
try {
|
|
898
|
+
console.warn(lines.join("\n"));
|
|
899
|
+
}
|
|
900
|
+
catch {
|
|
901
|
+
/* A patched or absent console is not a reason to take a health product
|
|
902
|
+
down. Nothing in this channel throws, including the part that reports
|
|
903
|
+
that the channel is broken. */
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
//# sourceMappingURL=opsinjs.js.map
|