react-advanced-odontogram 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1382 -0
  3. package/dist/App.d.ts +148 -0
  4. package/dist/DualStateConfirm.d.ts +25 -0
  5. package/dist/ExportOptionsModal.d.ts +26 -0
  6. package/dist/PerioChart.d.ts +67 -0
  7. package/dist/PerioSidebar.d.ts +1 -0
  8. package/dist/SettingsModal.d.ts +84 -0
  9. package/dist/bridgeOverlay.d.ts +116 -0
  10. package/dist/fhir/codesystems.d.ts +51 -0
  11. package/dist/fhir/fieldMappings.d.ts +35 -0
  12. package/dist/fhir/fromFhir.d.ts +7 -0
  13. package/dist/fhir/primitives.d.ts +16 -0
  14. package/dist/fhir/toFhir.d.ts +20 -0
  15. package/dist/fhir/toFhirPerio.d.ts +70 -0
  16. package/dist/fhir/types.d.ts +108 -0
  17. package/dist/i18n/translations.d.ts +27 -0
  18. package/dist/i18n/useI18n.d.ts +39 -0
  19. package/dist/index.d.ts +4 -0
  20. package/dist/odontogram.d.ts +1214 -0
  21. package/dist/odontogram.js +20645 -0
  22. package/dist/odontogram.js.map +1 -0
  23. package/dist/perioClassification.d.ts +90 -0
  24. package/dist/perioExport.d.ts +13 -0
  25. package/dist/perioGraphic.d.ts +496 -0
  26. package/dist/perioIndexNames.d.ts +29 -0
  27. package/dist/perioPdf.d.ts +77 -0
  28. package/dist/plugin.d.ts +63 -0
  29. package/dist/registry/axes.d.ts +9 -0
  30. package/dist/registry/fhir.d.ts +3 -0
  31. package/dist/registry/fromFhir.d.ts +3 -0
  32. package/dist/registry/restorations.d.ts +26 -0
  33. package/dist/registry/svgActivate.d.ts +15 -0
  34. package/dist/registry/svgLayers.d.ts +14 -0
  35. package/dist/registry/types.d.ts +70 -0
  36. package/dist/registry/uiOptions.d.ts +17 -0
  37. package/dist/registry/validate.d.ts +4 -0
  38. package/dist/status_extras.d.ts +58 -0
  39. package/dist/style.css +1 -0
  40. package/dist/theme.d.ts +51 -0
  41. package/dist/tour.d.ts +9 -0
  42. package/dist/utils/numbering.d.ts +23 -0
  43. package/package.json +99 -0
@@ -0,0 +1,90 @@
1
+ /**
2
+ * SP-perio P4b Task 1 — pure 2017 World Workshop periodontal classification
3
+ * derivation core (diagnosis / stage / grade / extent).
4
+ *
5
+ * DELIBERATELY dependency-free: this module imports NOTHING from
6
+ * `odontogram.ts` (or anywhere else in the engine). `derivePerioClassification`
7
+ * is a pure function of its input struct — no module-level state, no `Date`,
8
+ * no `Math.random` — so it is fully deterministic and safe to call from a
9
+ * serialized payload (T3's FHIR Condition builder feeds it exactly that way).
10
+ * The engine-state adapter that BUILDS a {@link PerioDerivationInput} from the
11
+ * live chart (`buildDerivationInputFromState()`) lives in `odontogram.ts`,
12
+ * which is free to import types from here (one-directional dependency).
13
+ */
14
+ /** Per-tooth inputs the derivation needs — already reduced from the raw
15
+ * per-site CAL/PD data (the adapter in `odontogram.ts` does that reduction). */
16
+ export interface ToothDerivationInput {
17
+ toothNo: number;
18
+ /** Worst (max) CAL over the 4 approximal sites (MB/DB/ML/DL). 0 if none
19
+ * charted — the pure function cannot distinguish "charted as 0" from
20
+ * "never charted"; both read as "no interdental attachment loss here". */
21
+ interdentalCal: number;
22
+ /** Worst (max) CAL over the 2 mid sites (B/L) — the 2017 primary-case
23
+ * definition's buccal/oral fallback criterion. */
24
+ buccalOralCal: number;
25
+ /** Worst (max) raw probing depth recorded anywhere on the tooth (any of
26
+ * the 6 sites) — used by the stage-III complexity escalation. */
27
+ maxPd: number;
28
+ /** Whether this FDI position is a real, present tooth (not missing, not
29
+ * an implant) — mirrors `isToothPresent()` in odontogram.ts. */
30
+ present: boolean;
31
+ }
32
+ /** Case-level metadata the derivation needs — the P4a `CaseMeta` shape,
33
+ * duplicated here (not imported) to keep this module dependency-free. */
34
+ export interface PerioMetaInput {
35
+ age: number | null;
36
+ maxRblPercent: number | null;
37
+ toothLossPerio: number | null;
38
+ smokingStatus: "unknown" | "never" | "former" | "current";
39
+ cigarettesPerDay: number | null;
40
+ diabetesStatus: "unknown" | "none" | "present";
41
+ hba1c: number | null;
42
+ }
43
+ /** Full pure input to {@link derivePerioClassification}. */
44
+ export interface PerioDerivationInput {
45
+ teeth: ToothDerivationInput[];
46
+ /** Whole-mouth %BOP (`getPerioSummary().bopPercent`) — drives the
47
+ * gingivitis fallback when there's no periodontitis-qualifying CAL. */
48
+ bopPercent: number;
49
+ /** Highest Glickman furcation grade anywhere in the mouth, or `null` when
50
+ * nothing is graded (`getPerioSummary().maxFurcation`) — one of the
51
+ * stage-III complexity escalation criteria. */
52
+ maxFurcation: number | null;
53
+ meta: PerioMetaInput;
54
+ }
55
+ export type PerioDiagnosis = "health" | "gingivitis" | "periodontitis";
56
+ export type PerioStage = "na" | "I" | "II" | "III" | "IV" | "indeterminate";
57
+ export type PerioGrade = "A" | "B" | "C" | "indeterminate";
58
+ export type PerioExtent = "na" | "localized" | "generalized" | "molar-incisor";
59
+ export interface PerioClassification {
60
+ diagnosis: PerioDiagnosis;
61
+ stage: PerioStage;
62
+ grade: PerioGrade;
63
+ extent: PerioExtent;
64
+ /** Provenance for the final `grade` — the three sub-grades `deriveGrade`
65
+ * computes internally, surfaced (not re-derived) so callers (T3's FHIR
66
+ * evidence) can cite exactly which factor(s) drove the result.
67
+ * `direct` is the raw %RBL÷age band, or `null` when age/RBL is missing
68
+ * (mirrors `grade === "indeterminate"` when no modifiers are known either).
69
+ * `smoking`/`diabetes` are always a concrete bucket (`"A"` when the
70
+ * status is unknown/none/never/former — never `null`, since those
71
+ * statuses are a known "does not escalate" fact, not a missing one). */
72
+ buckets: {
73
+ smoking: "A" | "B" | "C";
74
+ diabetes: "A" | "B" | "C";
75
+ direct: "A" | "B" | "C" | null;
76
+ };
77
+ }
78
+ /** Whether two FDI tooth numbers are arch-adjacent (same-arch consecutive
79
+ * positions, including the 11/21 and 41/31 midline pairs). Exported for
80
+ * tests / potential reuse; the derivation itself only needs the local
81
+ * `archAdjacent` above. */
82
+ export declare function areAdjacent(a: number, b: number): boolean;
83
+ /**
84
+ * Pure derivation of the full 2017 World Workshop periodontal classification
85
+ * (diagnosis/stage/grade/extent) from an already-reduced input struct. No
86
+ * engine state, no Date/random — safe to call repeatedly with the same
87
+ * input and always get the same output (T3 feeds this from a serialized
88
+ * FHIR-export-time snapshot, not live module state).
89
+ */
90
+ export declare function derivePerioClassification(input: PerioDerivationInput): PerioClassification;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * UI-3b Task 4: build the FULL perio chart (teeth graphic + numeric rows +
3
+ * 2017 classification) as ONE standalone vector SVG, from the ACTIVE chart's
4
+ * state — headless, no mounted DOM read. Returns `null` when the shared
5
+ * tooth-template cache (`loadTemplateCache()`, same loader/memoized promise
6
+ * `PerioChart.tsx` awaits) fails to load (templates are inlined, so this is
7
+ * only an internal parse fault — the guard is defensive).
8
+ */
9
+ export declare function buildPerioSvg(): Promise<{
10
+ xml: string;
11
+ width: number;
12
+ height: number;
13
+ } | null>;
@@ -0,0 +1,496 @@
1
+ export type TemplateNo = 11 | 13 | 14 | 16;
2
+ /** Layers that must NEVER appear in a cloned tooth-base group — only the
3
+ * tooth's own crown/root outline (`#tooth-base`) belongs in this read-only
4
+ * chart graphic; gum/bone context, the healthy-pulp glyph, the enamel
5
+ * "beauty" highlight, and the milk-tooth variant are all odontogram-tile
6
+ * concerns, not perio-row concerns. */
7
+ export declare const EXCLUDED_TOOTH_BASE_IDS: readonly string[];
8
+ /**
9
+ * Per-template CEJ (cemento-enamel junction / crown-root boundary) y-anchor,
10
+ * in the FINAL crown-up local coordinate frame `getToothBaseGroupFromCache`
11
+ * renders each tooth group in (i.e. AFTER the internal vertical flip below —
12
+ * see that function's comment for why the flip is needed at all).
13
+ *
14
+ * Measured from each template's `gum-base` geometry (the visible gingival
15
+ * tissue drawn over the cervical/root region — its coronal-most edge, i.e.
16
+ * max-Y in the template's RAW/un-flipped coordinate system, approximates the
17
+ * CEJ/gumline) via a one-off control-point bounding-box script over the
18
+ * path's `d` attribute (a close superset of the true curve bbox — gentle
19
+ * curves here, so this is a good anchor, NOT pixel-exact anatomy). Then
20
+ * converted into the flipped frame via `finalY = viewBoxHeight - rawY`:
21
+ * 11: raw 38.6, viewBox h 70.8 -> 32.2
22
+ * 13: raw 38.6, viewBox h 71.0 -> 32.4
23
+ * 14: raw 39.1, viewBox h 71.2 -> 32.1
24
+ * 16: raw 39.9, viewBox h 70.9 -> 31.0
25
+ * Row-baseline alignment only needs these to be mutually consistent across
26
+ * templates (they are, within ~1 unit) — visual placement should still be
27
+ * confirmed in a browser (see task-2-report.md).
28
+ */
29
+ export declare const CEJ_Y: Record<TemplateNo, number>;
30
+ /**
31
+ * Per-template baseline anchor for an IMPLANT tooth — the implant fixture's
32
+ * neck/platform (its CEJ-equivalent: the coronal collar where the abutment
33
+ * emerges, which should sit on the same row baseline as a natural neighbour's
34
+ * CEJ line). An implant renders the template's `#implant-base` layer (the
35
+ * greyscale fixture body) instead of `#tooth-base`, and `#implant-base`'s
36
+ * platform sits at a slightly different y than the natural CEJ, so it needs its
37
+ * OWN anchor to line up.
38
+ *
39
+ * Measured from `#implant-base`'s coronal-most control point (max-Y in the
40
+ * template's RAW/un-flipped coordinate system — the same one-off control-point
41
+ * bounding-box technique CEJ_Y above was measured with; a close superset of the
42
+ * true platform edge), then converted into the final crown-up flipped frame via
43
+ * `finalY = viewBoxHeight - rawY` (same frame `getToothBaseGroupFromCache`
44
+ * renders in — see that function's flip comment):
45
+ * 11: platform raw 37.8, viewBox h 70.8 -> 33.0
46
+ * 13: platform raw 35.6, viewBox h 71.0 -> 35.4
47
+ * 14: platform raw 36.6, viewBox h 71.2 -> 34.6
48
+ * 16: platform raw 36.6, viewBox h 70.9 -> 34.3
49
+ * As with CEJ_Y, row-baseline alignment only needs these mutually consistent
50
+ * (they place every implant platform on ROW_BASELINE_Y); exact anatomical
51
+ * placement should still be confirmed in a browser (see task-3-implant-report.md).
52
+ */
53
+ export declare const IMPLANT_CEJ_Y: Record<TemplateNo, number>;
54
+ /** Predicate telling the arch builders whether a given tooth is an implant on
55
+ * the active chart, so its graphic uses the implant fixture artwork
56
+ * (`#implant-base`) instead of the natural `#tooth-base`. Injected by the
57
+ * caller (`PerioChart` passes `isToothImplant` from odontogram.ts, reading the
58
+ * SAME active-chart state the number rows read) rather than imported here, so
59
+ * this module stays DOM-free / state-free and unit-testable from a plain
60
+ * template cache. Defaults to "no implants" for every existing caller/test. */
61
+ export type IsImplantFn = (toothNo: number) => boolean;
62
+ export type TemplateDocCache = Map<TemplateNo, Document>;
63
+ /**
64
+ * Parse each of the 4 tooth templates ONCE into a cached `Document` (never
65
+ * re-parsed per tooth — the returned promise is memoized at module scope so
66
+ * concurrent/repeated calls all await the same settled load). `TEMPLATES` now
67
+ * holds inlined SVG *text* (from `odontogram.ts`'s `?raw` imports), so this
68
+ * parses the markup directly — no `fetch()`. Keeps its OWN cache — the live
69
+ * grid's `tplCache` (inside `buildGrid()`) is a function-local variable, not
70
+ * exported/reachable from here.
71
+ */
72
+ export declare function loadTemplateCache(): Promise<TemplateDocCache>;
73
+ /**
74
+ * Build ONE tooth's crown/root artwork group for the perio row: a clone of
75
+ * that tooth's `#tooth-base` (+ any gradients it references), oriented
76
+ * (horizontal mirror only) and size-transformed for its FDI position.
77
+ *
78
+ * Orientation: `TOOTH_TEMPLATE.get(toothNo)` gives `{tpl, rot, mirror}`.
79
+ * This deliberately reads only `tpl`/`mirror` and IGNORES `rot` — using the
80
+ * odontogram's own per-tooth `.rot` (0 for the upper-arch-mapped entries,
81
+ * 180 for the lower-arch-mapped entries in the SAME `tpl`) would make the
82
+ * upper and lower halves of one perio row end up with OPPOSITE vertical
83
+ * orientation (since a 180 rotation flips both axes) — wrong for a perio
84
+ * chart, which wants every tooth crown-up, uniformly, in both arches.
85
+ *
86
+ * Every template's raw/un-rotated artwork is actually root-up / crown-down
87
+ * (verified from 11.svg's own geometry — see the comment at
88
+ * `odontogram.ts` ~line 1839: "the crown/incisal edge sits at LARGER y ...
89
+ * and the root/apex at SMALLER y" for the un-rotated template). So getting
90
+ * a uniformly crown-up row does still need a vertical flip — just ONE
91
+ * fixed, uniform flip applied to every tooth alike (never the per-tooth
92
+ * conditional `.rot`), which is what step 1 below is.
93
+ */
94
+ export declare function getToothBaseGroupFromCache(cache: TemplateDocCache, toothNo: number, opts?: {
95
+ implant?: boolean;
96
+ }): SVGGElement;
97
+ /** Row-local y-coordinate the shared CEJ baseline is placed at, for every
98
+ * tooth in a buccal row (arbitrary but fixed — just needs to leave enough
99
+ * margin above for the tallest crown and below for the longest root; see
100
+ * `bandViewBox`'s viewBox sizing). Exported so the T3 curve overlay
101
+ * (`PerioChart`) uses the SAME baseline the arch teeth are laid out on. */
102
+ export declare const ROW_BASELINE_Y = 40;
103
+ /** mm -> pixel (row-local unit) scale for the T3 curve overlay: how far one
104
+ * millimetre of probing depth / gingival recession moves the curve away from
105
+ * the CEJ baseline. Chosen so a clinically deep pocket (~10 mm) plus its
106
+ * recession still lands within the drawn root region below `ROW_BASELINE_Y`
107
+ * (roots reach row-y ~79, canines ~90) rather than overshooting into the
108
+ * mirrored palatal band. Named constant, not a magic literal — visual scale
109
+ * is confirmed in a browser (see task-3-report.md). */
110
+ export declare const PERIO_MM_PX = 3;
111
+ /** How many 1-mm guide lines the background mm grid draws below the CEJ
112
+ * baseline toward the root (n = 1..PERIO_MM_GRID_MAX). 15 mm covers the full
113
+ * clinical probing-depth range (PD is clamped to 1–15 in the P1 API), so a
114
+ * charted pocket's curve point always has a numbered guide line to read
115
+ * against; every 5th line (5/10/15) is emphasized + labelled. */
116
+ export declare const PERIO_MM_GRID_MAX = 15;
117
+ /** Fixed horizontal footprint (template viewBox width + gap) reused as the
118
+ * per-tooth cursor advance — approximate, uniform spacing (this task draws
119
+ * the row graphic only; T3/T4 own the curve overlay / number-row layout
120
+ * that would react to real per-tooth widths). Tightened from 4 to 2 so the
121
+ * teeth sit denser (T1 polish). */
122
+ export declare const TOOTH_GAP = 2;
123
+ /** Display magnification (px per row-local viewBox unit) the perio chart
124
+ * renders the teeth at. The arch <svg> itself carries NO intrinsic pixel
125
+ * size (it fills its container via CSS `width:100%`, see `buildBandSvg`);
126
+ * the number-row grid columns are widened by this factor
127
+ * (`applyArchColumns` in `PerioChart.tsx`), and since the SVG fills the
128
+ * cell those columns span, every viewBox unit ends up rendered at
129
+ * `PERIO_DISPLAY_SCALE` px — so the teeth read larger while the columns stay
130
+ * locked to them (one shared `archToothLayout`, never two divergent
131
+ * geometries). `> 1` bumps the base scale so the teeth read larger (T1
132
+ * polish); visual size is confirmed in a browser (see task-1-report.md).
133
+ *
134
+ * UI-1 Task 3b (dynamic fill-scale): `applyArchColumns` no longer uses this
135
+ * FIXED value at runtime — it now computes a per-render `fillScale` via
136
+ * {@link computeFillScale} so the chart fills the available container width
137
+ * instead of leaving empty space on a wide screen. This constant is kept as
138
+ * the historical reference/floor value (`MIN_FILL_SCALE` below is set equal
139
+ * to it, so a narrow container reproduces the exact pre-Task-3b layout) —
140
+ * still exported since other modules/tests reference it as "the base display
141
+ * scale", never delete. */
142
+ export declare const PERIO_DISPLAY_SCALE = 1.5;
143
+ /** Floor for the dynamic fill-scale (UI-1 Task 3b) — below this the teeth
144
+ * would read uncomfortably small, so a narrow container instead relies on
145
+ * `.perio-fullgrid-scroll`'s horizontal scrollbar rather than shrinking
146
+ * further. Equal to the legacy `PERIO_DISPLAY_SCALE` so a narrow/unmeasured
147
+ * container (including jsdom, which reports `clientWidth === 0`) renders
148
+ * identically to the pre-Task-3b fixed layout. */
149
+ export declare const MIN_FILL_SCALE = 1.5;
150
+ /** Ceiling for the dynamic fill-scale (UI-1 Task 3b) — caps how large the
151
+ * teeth/number cells grow on an ultra-wide monitor so they don't become
152
+ * absurdly oversized. */
153
+ export declare const MAX_FILL_SCALE = 2.6;
154
+ /**
155
+ * Pure scale-fitting math for the dynamic fill-scale (UI-1 Task 3b, no DOM):
156
+ * given the pixel width available for an arch's tooth columns and the summed
157
+ * base-scale (1x) footprint of that arch's teeth (`ArchLayout.totalWidth`),
158
+ * return the per-tooth column multiplier that makes the columns fill
159
+ * `available`, clamped to `[MIN_FILL_SCALE, MAX_FILL_SCALE]`. Guards against
160
+ * a non-finite/non-positive `baseCols` (empty arch, or the template cache not
161
+ * loaded yet) and a non-finite/negative `available` (unmeasured or
162
+ * over-subtracted container width) by falling back to the floor — the same
163
+ * value the chart always used before this task, so "can't measure" degrades
164
+ * to the historical fixed layout rather than a broken one.
165
+ */
166
+ export declare function computeFillScale(available: number, baseCols: number): number;
167
+ /** One tooth's horizontal footprint within an arch row (row-local x). */
168
+ export interface ArchToothLayout {
169
+ toothNo: number;
170
+ /** Left edge of the tooth's viewBox in the row's coordinate space. */
171
+ x: number;
172
+ /** The tooth template's viewBox width. */
173
+ width: number;
174
+ }
175
+ /** The full geometric layout of one arch row — the SINGLE source of truth for
176
+ * where each tooth sits and where the shared CEJ baseline / palatal mirror
177
+ * axis are. `buildBuccalRowGroup` (the T2 arch artwork) AND the T3 curve
178
+ * overlay both derive their positions from this, so the curve can never drift
179
+ * out of alignment with the teeth. */
180
+ export interface ArchLayout {
181
+ /** Shared CEJ baseline (buccal-row coordinate space). */
182
+ cejY: number;
183
+ /** Total horizontal footprint (last cursor position, incl. trailing gap). */
184
+ totalWidth: number;
185
+ teeth: ArchToothLayout[];
186
+ }
187
+ /**
188
+ * Compute one arch row's per-tooth x-cursor layout — the exact same
189
+ * left-to-right cursor walk `buildBuccalRowGroup` uses to place the teeth
190
+ * (`cursorX += viewBoxWidth + TOOTH_GAP`), extracted so BOTH the arch artwork
191
+ * and the curve overlay read one identical layout (no divergent second
192
+ * hard-coded spacing). Skips any tooth without a `TOOTH_TEMPLATE`/cache entry,
193
+ * exactly like the row builder does.
194
+ */
195
+ export declare function archToothLayout(cache: TemplateDocCache, teeth: readonly number[]): ArchLayout;
196
+ /**
197
+ * Build the BUCCAL-aspect arch as a standalone `<svg>`, oriented crown-DOWN
198
+ * for BOTH arches (uniform — see the section doc comment above): the row
199
+ * builder's raw output is crown-up (per `getToothBaseGroupFromCache`'s own
200
+ * uniform per-tooth flip), so this applies ONE unconditional vertical flip
201
+ * about the CEJ baseline (`matrix(1 0 0 -1 0 2*ROW_BASELINE_Y)` — the exact
202
+ * transform the retired legacy builder used ONLY for the upper arch, now
203
+ * applied to every arch alike) — the baseline itself is the transform's
204
+ * fixed point, so it never moves. Own mm-grid, counter-flipped (`flip:
205
+ * true`) so its numeric labels read upright inside this net-flipped row.
206
+ */
207
+ export declare function buildBuccalArchSvg(cache: TemplateDocCache, teeth: readonly number[], isImplant?: IsImplantFn): SVGSVGElement;
208
+ /**
209
+ * Build the PALATAL/LINGUAL-aspect arch as a standalone `<svg>`, oriented
210
+ * crown-UP for BOTH arches — the vertical mirror of `buildBuccalArchSvg`'s
211
+ * uniform crown-down flip, about the SAME `ROW_BASELINE_Y` fixed point.
212
+ * Mirroring the SAME axis twice cancels back to the identity transform, so
213
+ * "mirror of buccal" here is exactly the row builder's own un-flipped
214
+ * (crown-up) output — i.e. no orientation transform is applied at all; only
215
+ * the horizontal per-tooth mesial/distal mirror (already baked into each
216
+ * tooth group by `getToothBaseGroupFromCache`) and the uniform per-tooth
217
+ * crown-up flip remain. Own mm-grid, NOT counter-flipped (`flip: false`) —
218
+ * this row is never net-flipped, so its labels already read upright.
219
+ */
220
+ export declare function buildPalatalArchSvg(cache: TemplateDocCache, teeth: readonly number[], isImplant?: IsImplantFn): SVGSVGElement;
221
+ /** A single ordered site's PD/GM reading for the curve. `pd` absent/undefined
222
+ * == "not charted" (a gap in the line), matching the P1 omit-when-empty API.
223
+ * `site` is carried only for readability/debugging — the curve math uses the
224
+ * positional index, never the site name. */
225
+ export interface PerioCurveSite {
226
+ site?: string;
227
+ /** Probing depth in mm; undefined/null when the site is not charted. */
228
+ pd?: number | null;
229
+ /** Gingival margin vs CEJ (SIGNED: recession +, coronal −); defaults 0. */
230
+ gm?: number | null;
231
+ }
232
+ export interface CurvePoint {
233
+ x: number;
234
+ y: number;
235
+ }
236
+ export interface PerioCurveResult {
237
+ cejY: number;
238
+ /** Gingival-margin point per input site (null == uncharted gap). */
239
+ marginPts: (CurvePoint | null)[];
240
+ /** Pocket-base point per input site (null == uncharted gap). */
241
+ pocketPts: (CurvePoint | null)[];
242
+ }
243
+ /**
244
+ * Pure curve geometry — turn ordered per-site {pd,gm} readings into the
245
+ * gingival-margin and pocket-base point arrays, in the arch row's LOCAL
246
+ * coordinate space (crown up = smaller y, root down = larger y; the shared
247
+ * CEJ baseline at `opts.cejY`). No DOM.
248
+ *
249
+ * Orientation (buccal row): `y` grows downward toward the root, so
250
+ * marginY = cejY + (gm ?? 0)*mmPx → recession (gm>0) pushes the margin
251
+ * DOWN toward the root; a coronal
252
+ * margin (gm<0) lifts it above the CEJ.
253
+ * pocketY = marginY + pd*mmPx → a deeper pocket dips the pocket line
254
+ * FURTHER from the CEJ toward the root.
255
+ * The palatal row reuses this same buccal-space result; since UI-3a the
256
+ * palatal band renders in its OWN independent SVG (crown-up, identity
257
+ * transform — no net mirror), so "toward the root" stays anatomically
258
+ * consistent on both rows.
259
+ *
260
+ * An uncharted site (`pd` undefined/null) yields `null` at that index in BOTH
261
+ * arrays, so the caller can break the polyline/band there (line gaps).
262
+ */
263
+ export declare function perioCurve(sites: readonly PerioCurveSite[], opts: {
264
+ cejY: number;
265
+ mmPx: number;
266
+ siteX: (i: number) => number;
267
+ }): PerioCurveResult;
268
+ /**
269
+ * Build the curve overlay <g> for ONE row: a red horizontal CEJ line at
270
+ * `cejY`, a filled band `<path>` between the margin and pocket lines, and the
271
+ * margin + pocket polylines — each broken into separate segments at uncharted
272
+ * gaps. Pure DOM (jsdom `document` in tests / the browser at runtime) — no
273
+ * perio-module call, so it is trivially unit-testable and parity-irrelevant
274
+ * (brand-new DOM, never near the live odontogram).
275
+ */
276
+ export declare function buildPerioCurveLayer(curve: PerioCurveResult, opts: {
277
+ width: number;
278
+ className?: string;
279
+ }): SVGGElement;
280
+ /**
281
+ * Build the background mm-grid layer for ONE row: faint horizontal guide lines
282
+ * every 1 mm below the CEJ baseline toward the root (`y = cejY + n*mmPx`, n =
283
+ * 1..maxMm), with every 5th line emphasized (`perio-mm-line-major`) and given a
284
+ * small numeric label ("5"/"10"/"15"). Pure DOM (jsdom in tests / the browser
285
+ * at runtime) — no perio-module call, so it is trivially unit-testable and
286
+ * parity-irrelevant (brand-new DOM, never near the live odontogram).
287
+ *
288
+ * The grid is drawn in the SAME row-local coordinate space as the teeth and the
289
+ * curve (crown up = smaller y, root down = larger y; shared CEJ baseline at
290
+ * `cejY`), so a line at "n mm from the CEJ" lands EXACTLY where an n-mm (gm=0)
291
+ * pocket's curve point lands (`perioCurve` → `pocketY = cejY + n*mmPx`). The
292
+ * caller appends it INTO the SAME oriented/mirrored row group as the teeth
293
+ * (`.perio-tooth-row-buccal` / `.perio-tooth-row-palatal-inner`), so the T1
294
+ * per-arch flip carries the grid along with the teeth — the mm lines stay on the
295
+ * ROOT side of the CEJ (away from the occlusal mid-line) on both arches.
296
+ *
297
+ * `flip`: when the containing row group is NET vertically flipped on screen
298
+ * (the upper arch's crown-down buccal row, or the lower arch's mirrored palatal
299
+ * row), the numeric labels would render upside-down. Passing `flip: true`
300
+ * counter-flips each label about its own baseline (`matrix(1 0 0 -1 0 2y)`) so
301
+ * the digits read upright regardless of the row's orientation — the LINES,
302
+ * being horizontal, are unaffected either way.
303
+ *
304
+ * The whole `<g>` is `aria-hidden` — a decorative measurement guide; the
305
+ * accessible data lives in the number cells/summary alongside the graphic.
306
+ */
307
+ export declare function buildMmGridLayer(opts: {
308
+ cejY: number;
309
+ mmPx: number;
310
+ width: number;
311
+ maxMm?: number;
312
+ flip?: boolean;
313
+ }): SVGGElement;
314
+ /** A single positioned overlay mark (row-local coordinate space). `kind`
315
+ * selects the CSS class / colour: a red BOP dot, a plaque mark, or a
316
+ * pocket-threshold heat spot (`pd5`/`pd6`). */
317
+ export interface OverlayMark {
318
+ x: number;
319
+ y: number;
320
+ kind: "bop" | "plaque" | "pd5" | "pd6" | "heat-shallow" | "heat-moderate" | "heat-deep" | "rt1" | "rt2" | "rt3";
321
+ }
322
+ /** One ordered site's reading for the discrete site-based overlays. `pd`
323
+ * absent/undefined == "not charted" (never marked). Same shape/orientation
324
+ * convention as {@link PerioCurveSite}, plus the site's `x` and its `bop`
325
+ * flag. */
326
+ export interface PerioOverlaySite {
327
+ x: number;
328
+ pd?: number | null;
329
+ gm?: number | null;
330
+ bop?: boolean;
331
+ /** Clinical attachment level (= pd + gm), as returned by `getToothCal`. Only
332
+ * populated/consumed by the PG-B Task 3 CAL heat overlay; every other
333
+ * discrete overlay (bop/pd5/pd6) ignores it. Kept on this shared shape
334
+ * (rather than a parallel interface) since it reuses the exact same x/pd/gm
335
+ * fields `collectOverlayInput` already builds. */
336
+ cal?: number | null;
337
+ }
338
+ /** Discrete overlay layers that are site-based (one mark per probing site). */
339
+ export type SiteOverlayLayer = "bop" | "pd5" | "pd6";
340
+ /**
341
+ * Pure geometry for the site-based discrete overlays. Uses the EXACT same
342
+ * coordinate math as `perioCurve` (`marginY = cejY + gm*mmPx`, `pocketY =
343
+ * marginY + pd*mmPx`), so a mark sits on the same point the curve draws:
344
+ * - `bop` : a dot at the gingival MARGIN of every bleeding, charted
345
+ * site (a bop flag on an uncharted site is ignored, mirroring
346
+ * `getPerioSummary().bopPercent`).
347
+ * - `pd5`/`pd6`: a heat spot at the POCKET BASE of every charted site whose
348
+ * probing depth is >= 5 / >= 6 mm.
349
+ * An uncharted site (`pd` undefined/null) never produces a mark.
350
+ */
351
+ export declare function perioOverlayMarks(layer: SiteOverlayLayer, sites: readonly PerioOverlaySite[], opts: {
352
+ cejY: number;
353
+ mmPx: number;
354
+ }): OverlayMark[];
355
+ /** Severity bucket for a continuous mm heat overlay — shallow/moderate/deep,
356
+ * reused across PD, CAL, and GR (each with its own threshold ramp below). */
357
+ export type MmHeatBucket = "shallow" | "moderate" | "deep";
358
+ /**
359
+ * Pure ramp for a probing-style distance in mm — PD (raw probing depth) or
360
+ * CAL (`pd + gm`, i.e. attachment loss from the CEJ). Thresholds mirror the
361
+ * existing T2 pd5/pd6 discrete-overlay thresholds (>=4mm starts to matter
362
+ * clinically, >=6mm is a deep/severe pocket), so the new heat scale and the
363
+ * old discrete >=5mm/>=6mm highlights read consistently side by side.
364
+ */
365
+ export declare function pdCalHeatBucket(mm: number): MmHeatBucket;
366
+ /**
367
+ * Pure ramp for gingival recession (`gm`, in mm — only meaningful when
368
+ * `gm > 0`; a non-positive `gm` is a pseudopocket/coronal margin, never
369
+ * recession, and must be filtered out by the caller before ramping). Lower
370
+ * thresholds than {@link pdCalHeatBucket}: recession is measured on a
371
+ * shallower clinical scale than pocket/attachment depth.
372
+ */
373
+ export declare function recessionHeatBucket(mm: number): MmHeatBucket;
374
+ /** The 3 continuous mm heat overlay layers. */
375
+ export type MmHeatOverlayLayer = "pd" | "cal" | "gr";
376
+ /**
377
+ * Pure geometry for the continuous mm heat overlays. Reuses the EXACT same
378
+ * coordinate math as `perioCurve`/`perioOverlayMarks` (`marginY = cejY +
379
+ * gm*mmPx`, `pocketY = marginY + pd*mmPx`):
380
+ * - `pd` : every charted site, heat-bucketed by probing depth, marked at the
381
+ * pocket base (same point the pd5/pd6 discrete marks use).
382
+ * - `cal`: every charted site, heat-bucketed by CAL (`site.cal`, falling
383
+ * back to `pd + gm` if the caller didn't attach it — the two are
384
+ * always numerically identical, see `getToothCal`), marked at the
385
+ * SAME pocket-base point (`cejY + cal*mmPx === cejY + (pd+gm)*mmPx`
386
+ * — CAL measured from the CEJ IS the pocket base).
387
+ * - `gr` : only sites with recession (`gm > 0`) are marked, heat-bucketed by
388
+ * `gm` via {@link recessionHeatBucket}, at the gingival margin
389
+ * (the same point the recession sits at — mirrors `bop`'s
390
+ * margin-point placement).
391
+ * An uncharted site (`pd` undefined/null) never produces a mark, matching
392
+ * every other site-based overlay.
393
+ */
394
+ export declare function perioMmHeatMarks(layer: MmHeatOverlayLayer, sites: readonly PerioOverlaySite[], opts: {
395
+ cejY: number;
396
+ mmPx: number;
397
+ }): OverlayMark[];
398
+ /** One tooth's plaque input for {@link perioPlaqueMarks}: its row-local x +
399
+ * viewBox width and the set of O'Leary surfaces that carry plaque. */
400
+ export interface PerioPlaqueTooth {
401
+ x: number;
402
+ width: number;
403
+ surfaces: readonly string[];
404
+ }
405
+ /**
406
+ * Pure geometry for the plaque overlay: one mark per charted O'Leary surface,
407
+ * placed on the tooth's cervical band (at the shared CEJ baseline). Plaque is
408
+ * a whole-tooth, 4-surface index (mesial/distal/buccal/lingual) rather than a
409
+ * per-probing-site reading, so the marks split across the two rows:
410
+ * - the BUCCAL aspect shows mesial/buccal/distal (interproximal + facial),
411
+ * - the PALATAL/LINGUAL aspect shows lingual.
412
+ * This way every charted surface is drawn exactly once across the two rows.
413
+ */
414
+ export declare function perioPlaqueMarks(teeth: readonly PerioPlaqueTooth[], aspect: "buccal" | "palatal", opts: {
415
+ cejY: number;
416
+ mmPx: number;
417
+ }): OverlayMark[];
418
+ /** One tooth's Cairo-overlay input for {@link perioCairoMarks}: its row-local
419
+ * x + viewBox width and its derived recession TYPE (`"none"` -> no mark). */
420
+ export interface PerioCairoTooth {
421
+ x: number;
422
+ width: number;
423
+ rt: "none" | "rt1" | "rt2" | "rt3";
424
+ }
425
+ /**
426
+ * Pure geometry for the Cairo recession-type overlay: one mark per tooth
427
+ * whose derived RT is not `"none"`, centered on the tooth at the shared CEJ
428
+ * baseline (the same `cejY` every other overlay/curve anchors to). A tooth
429
+ * with `"none"` (no buccal recession, or not charted) yields no mark.
430
+ */
431
+ export declare function perioCairoMarks(teeth: readonly PerioCairoTooth[], opts: {
432
+ cejY: number;
433
+ }): OverlayMark[];
434
+ /** One tooth's graded-index input (PI/GI) for {@link perioGradeMarks}: its
435
+ * row-local x + viewBox width and each of the 4 O'Leary surfaces' grade
436
+ * (0-3; 0/absent = healthy/uncharted — matches getPlaqueIndex/
437
+ * getGingivalIndex's own "absence" semantics, never marked). */
438
+ export interface PerioGradeTooth {
439
+ x: number;
440
+ width: number;
441
+ grades: Partial<Record<"mesial" | "distal" | "buccal" | "lingual", 0 | 1 | 2 | 3>>;
442
+ }
443
+ /** Severity bucket for a CHARTED graded per-surface index reading (PI/GI,
444
+ * 1-3) — reuses the same shallow/moderate/deep heat vocabulary as the
445
+ * continuous mm ramps ({@link pdCalHeatBucket}/{@link recessionHeatBucket}).
446
+ * Callers only ever bucket a grade >0 (0/uncharted is filtered out before
447
+ * reaching here, mirroring `perioPlaqueMarks`' presence-only marking). */
448
+ export declare function gradeHeatBucket(grade: 1 | 2 | 3): MmHeatBucket;
449
+ /**
450
+ * Pure geometry for the PI/GI graded-index overlays: one heat-bucketed mark
451
+ * per CHARTED (grade>0) O'Leary surface, at the SAME cervical/CEJ points
452
+ * {@link perioPlaqueMarks} uses — the marks split across the two rows exactly
453
+ * like the plaque overlay (buccal aspect: mesial/buccal/distal; palatal/
454
+ * lingual aspect: lingual), so every charted surface is drawn exactly once.
455
+ */
456
+ export declare function perioGradeMarks(teeth: readonly PerioGradeTooth[], aspect: "buccal" | "palatal", opts: {
457
+ cejY: number;
458
+ }): OverlayMark[];
459
+ /** One tooth's keratinized-gingiva-width input for {@link perioKgMarks}: its
460
+ * row-local x + viewBox width and its KG mm reading (`null` = not charted,
461
+ * never marked). */
462
+ export interface PerioKgTooth {
463
+ x: number;
464
+ width: number;
465
+ kg: number | null;
466
+ }
467
+ /**
468
+ * Pure ramp for keratinized (attached) gingiva width in mm. Unlike a probing
469
+ * depth/CAL ramp, a NARROW band is the mucogingival risk here — the severity
470
+ * direction is inverted: <2mm inadequate ("deep"), <4mm borderline
471
+ * ("moderate"), >=4mm adequate ("shallow" — reusing the shallow/moderate/deep
472
+ * heat vocabulary purely as a severity ramp, not a literal depth reading).
473
+ */
474
+ export declare function kgHeatBucket(mm: number): MmHeatBucket;
475
+ /**
476
+ * Pure geometry for the KG overlay: one heat-bucketed mark per tooth with a
477
+ * charted (non-null) KG reading, centered on the tooth's BUCCAL cervical/CEJ
478
+ * point (KG is specifically a buccal measure — mirrors {@link perioCairoMarks}'
479
+ * buccal-only placement). A tooth with `kg === null` (never charted) yields
480
+ * no mark.
481
+ */
482
+ export declare function perioKgMarks(teeth: readonly PerioKgTooth[], opts: {
483
+ cejY: number;
484
+ }): OverlayMark[];
485
+ /**
486
+ * Build the overlay `<g>` for ONE row from a positioned mark list: an
487
+ * aria-hidden group (decorative — the accessible data lives in the number
488
+ * cells/summary) of one `<circle>` per mark, classed `perio-overlay-{kind}`
489
+ * so CSS colours the BOP dot red, the plaque mark, and the pd5/pd6 heat spots.
490
+ * Pure DOM (jsdom in tests / the browser at runtime) — no perio-module call,
491
+ * so it is trivially unit-testable and parity-irrelevant.
492
+ */
493
+ export declare function buildPerioOverlayLayer(marks: readonly OverlayMark[], opts: {
494
+ width: number;
495
+ className?: string;
496
+ }): SVGGElement;
@@ -0,0 +1,29 @@
1
+ import { type PerioRowId } from "./odontogram";
2
+ /**
3
+ * UI-2 Task 3: translated-vs-canonical periodontal index NAMES.
4
+ *
5
+ * `getPerioIndexNameMode()` (Settings -> Periodontal tab, T1) toggles how
6
+ * every perio-chart index row label is rendered:
7
+ * - "translated" (default): the existing localized `t(...)` string for
8
+ * that row (i18n x9, unchanged from before UI-2).
9
+ * - "canonical": a FIXED English/Latin standard scientific name,
10
+ * regardless of the active UI language. That is the entire point of
11
+ * canonical mode, so `CANONICAL_INDEX_NAMES` below is intentionally
12
+ * NOT routed through `t()` — it is the same text in every language.
13
+ *
14
+ * PD/GM/CAL/BOP are already rendered as a fixed, non-localized abbreviation
15
+ * in every language (see `"perio.pd": "PD"` etc. in translations.ts) — there
16
+ * is nothing left to canonicalize for those four, so their canonical value
17
+ * is unchanged from the translated one by design (both are just "PD" etc.).
18
+ *
19
+ * IMPORTANT: tooltips (`perio.info.*`, the "i" info-button popovers) are
20
+ * COMPLETELY UNRELATED to this mode. Every call site below keeps passing a
21
+ * plain `t("perio.info.<field>")` `infoKey` to `mkRowLabelCell` — never
22
+ * `indexName()` — so tooltip text stays localized in BOTH modes.
23
+ */
24
+ export declare const CANONICAL_INDEX_NAMES: Record<PerioRowId, string>;
25
+ /** The display name for a perio-chart index row, honoring the current
26
+ * `getPerioIndexNameMode()`. NEVER use this for tooltip/info-popover text —
27
+ * those must keep calling `t("perio.info.<field>")` directly regardless of
28
+ * this function's result (see the module doc comment above). */
29
+ export declare function indexName(rowKey: PerioRowId): string;