@broberg/bodymap 0.7.0 → 0.8.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/README.md CHANGED
@@ -251,7 +251,22 @@ const [big, setBig] = useState(false);
251
251
  <button onClick={() => setBig(true)}>Se stor</button>
252
252
  ```
253
253
 
254
- `Escape` leaves it. The pain report is untouched by entering or leaving.
254
+ `Escape` leaves it **but a phone has no Escape**, so there must always be a
255
+ reachable control. That is why the built-in one exists and why switching it off is
256
+ a commitment to supplying your own.
257
+
258
+ ⚠️ **If you supply your own control, render it as a SIBLING of the fullscreen
259
+ surface — not as a child of a container beneath it.** The surface is
260
+ `position: fixed`, so a button positioned `absolute` inside your original box ends
261
+ up *underneath* it. A consumer hit exactly this: their × disappeared under the
262
+ overlay, and because they had already set `showFullscreenButton={false}` there was
263
+ no way out at all. Give yours `position: fixed` and a z-index above the overlay,
264
+ and assert with `document.elementFromPoint()` that the point you can see is the
265
+ button you think it is.
266
+
267
+ The control sits inside the safe area (`env(safe-area-inset-*)` on all four sides),
268
+ and becomes a compact × in fullscreen — a text pill is wide enough to cover half a
269
+ phone's status bar. The pain report is untouched by entering or leaving.
255
270
 
256
271
  **It is a viewport fill, not the browser Fullscreen API — deliberately.** iOS
257
272
  Safari does not support fullscreen on an arbitrary element at all, and a phone is
@@ -335,6 +350,43 @@ heatFor(8, palette); // → "#D61C64" (intensity → heat colour)
335
350
  baseColorFor("chest", palette); // → "#e6e9f2" (per-region override, else body)
336
351
  ```
337
352
 
353
+ ### `ui.stageBg` vs `ui.panelBg` — the stage is not the panel
354
+
355
+ Two different surfaces, and until 0.8.0 they were one field:
356
+
357
+ | | what it paints | default |
358
+ |---|---|---|
359
+ | `ui.stageBg` | the **fullscreen backdrop**, the canvas frame, and the three.js scene behind the body | `#0e1424` |
360
+ | `ui.panelBg` | the **picker card**, its buttons, the empty hint | `#fff` |
361
+
362
+ ```ts
363
+ const palette: BodymapPalette = {
364
+ ...defaultPalette,
365
+ ui: { stageBg: "#0e1424", panelBg: "#fff" },
366
+ };
367
+ ```
368
+
369
+ **⚠️ The fullscreen backdrop changed colour in 0.8.0** — from white to the canvas
370
+ colour. Pass `ui: { stageBg: "#fff" }` to keep the old look.
371
+
372
+ It changed because it was never chosen. The backdrop read `panelBg`, the same
373
+ field as the picker card, so a consumer with a dark canvas got a white void with
374
+ a dark body floating in it — and could not fix it, because darkening `panelBg`
375
+ also darkened the card and hid the 0–10 buttons. One field, two surfaces,
376
+ opposite needs. Fullscreen is a stage around the model, not a panel.
377
+
378
+ `stageBg` is the **single source** for all three stage surfaces, including the
379
+ three.js scene. That matters more than it sounds: if it only repainted the
380
+ backdrop, your colour would surround a canvas that is still ours, and that seam
381
+ is invisible on a desktop monitor and obvious on a phone.
382
+
383
+ 3D only — the 2D renderer has no canvas and no fullscreen, so it ignores it.
384
+
385
+ The **WebGL-unsupported message** deliberately does *not* follow `stageBg`. It is
386
+ a message, not a stage, so it uses `panelBg` + `mutedText` — a pair whose contrast
387
+ the test suite asserts. Tied to the stage it would become unreadable the moment
388
+ you chose a light one, with no prop able to rescue it.
389
+
338
390
  ## Roadmap
339
391
 
340
392
  - True **per-zone mesh segmentation** for the 3D renderer (v0.2.0 assigns each
package/dist/index.cjs CHANGED
@@ -101,10 +101,12 @@ function emitFeedback(outcome, region, opts = {}) {
101
101
  if (opts.haptics === false) return "skipped";
102
102
  return requestVibration(VIBRATION_PATTERNS[outcome], opts.nav);
103
103
  }
104
+ var STAGE_BG = "#0e1424";
104
105
  var defaultUi = {
105
106
  text: "#1e293b",
106
107
  mutedText: "#475569",
107
108
  panelBg: "#fff",
109
+ stageBg: STAGE_BG,
108
110
  border: "#e2e8f0",
109
111
  badgeBg: "#f1f5f9",
110
112
  danger: "#dc2626"
@@ -175,6 +177,7 @@ function deserializeReport(env, now = () => (/* @__PURE__ */ new Date()).toISOSt
175
177
  exports.PAIN_TYPES = PAIN_TYPES;
176
178
  exports.REGIONS = REGIONS;
177
179
  exports.REGION_KEYS = REGION_KEYS;
180
+ exports.STAGE_BG = STAGE_BG;
178
181
  exports.VIBRATION_PATTERNS = VIBRATION_PATTERNS;
179
182
  exports.baseColorFor = baseColorFor;
180
183
  exports.bodymapReportV1Schema = bodymapReportV1Schema;
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"names":["z"],"mappings":";;;;;AA6BO,IAAM,OAAA,GAAiC;AAAA;AAAA,EAE5C,EAAE,GAAA,EAAK,MAAA,EAAQ,KAAA,EAAO,OAAA,EAAS,MAAM,MAAA,EAAO;AAAA,EAC5C,EAAE,GAAA,EAAK,MAAA,EAAQ,KAAA,EAAO,OAAA,EAAS,MAAM,MAAA,EAAO;AAAA,EAC5C,EAAE,GAAA,EAAK,OAAA,EAAS,KAAA,EAAO,OAAA,EAAS,MAAM,OAAA,EAAQ;AAAA,EAC9C,EAAE,GAAA,EAAK,OAAA,EAAS,KAAA,EAAO,wBAAA,EAAuB,MAAM,OAAA,EAAQ;AAAA,EAC5D,EAAE,GAAA,EAAK,QAAA,EAAU,KAAA,EAAO,kBAAA,EAAiB,MAAM,QAAA,EAAS;AAAA,EACxD,EAAE,GAAA,EAAK,OAAA,EAAS,KAAA,EAAO,OAAA,EAAS,MAAM,OAAA,EAAQ;AAAA;AAAA,EAE9C,EAAE,KAAK,eAAA,EAAiB,KAAA,EAAO,oBAAoB,IAAA,EAAM,UAAA,EAAY,MAAM,MAAA,EAAO;AAAA,EAClF,EAAE,KAAK,gBAAA,EAAkB,KAAA,EAAO,qBAAkB,IAAA,EAAM,UAAA,EAAY,MAAM,OAAA,EAAQ;AAAA,EAClF,EAAE,KAAK,WAAA,EAAa,KAAA,EAAO,oBAAoB,IAAA,EAAM,MAAA,EAAQ,MAAM,MAAA,EAAO;AAAA,EAC1E,EAAE,KAAK,YAAA,EAAc,KAAA,EAAO,qBAAkB,IAAA,EAAM,MAAA,EAAQ,MAAM,OAAA,EAAQ;AAAA,EAC1E,EAAE,KAAK,YAAA,EA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MAAA;AAAA,QACrB,IAAA,EAAO,GAAG,IAAA,IAAQ,QAAA;AAAA,QAClB,WAAW,CAAA,CAAE,SAAA;AAAA,QACb,SAAS,CAAA,CAAE;AAAA,OACb;AAAA,IACF,CAAC;AAAA,GACH;AACF;AAIO,SAAS,iBAAA,CACd,KACA,GAAA,GAAoB,MAAA,qBAAU,IAAA,EAAK,EAAE,aAAY,EACrC;AACZ,EAAA,MAAM,MAAA,GAAS,qBAAA,CAAsB,KAAA,CAAM,GAAG,CAAA;AAE9C,EAAA,MAAM,aAAa,IAAI,GAAA;AAAA,IACrB,OAAA,CAAQ,GAAA,CAAI,CAAC,CAAA,KAAM,CAAC,CAAA,EAAG,CAAA,CAAE,IAAI,CAAA,CAAA,EAAI,EAAE,IAAA,IAAQ,QAAQ,CAAA,CAAA,EAAI,CAAA,CAAE,GAAG,CAAU;AAAA,GACxE;AACA,EAAA,MAAM,MAAkB,EAAC;AACzB,EAAA,KAAA,MAAW,EAAA,IAAM,OAAO,MAAA,EAAQ;AAC9B,IAAA,MAAM,GAAA,GAAM,WAAW,GAAA,CAAI,CAAA,EAAG,GAAG,MAAM,CAAA,CAAA,EAAI,EAAA,CAAG,IAAI,CAAA,CAAE,CAAA;AACpD,IAAA,IAAI,CAAC,GAAA,EAAK;AACV,IAAA,GAAA,CAAI,IAAA;AAAA,MACF,gBAAgB,KAAA,CAAM;AAAA,QACpB,MAAA,EAAQ,GAAA;AAAA,QACR,WAAW,EAAA,CAAG,SAAA;AAAA,QACd,MAAM,EAAA,CAAG,OAAA;AAAA,QACT,WAAW,GAAA;AAAI,OAChB;AAAA,KACH;AAAA,EACF;AACA,EAAA,OAAO,GAAA;AACT","file":"index.cjs","sourcesContent":["// @broberg/bodymap — headless core (F052.1).\n//\n// Framework-neutral: the region taxonomy + the PainReport data model (zod) + a\n// selection engine + per-app region config. NO React/Preact/DOM import — the 2D\n// (SVG) and 3D (Three.js) renderers, and all three FD apps, share this one\n// contract. Output is a structured PainReport, never a bare image.\n\nimport { z } from \"zod\";\n\nexport type Side = \"left\" | \"right\";\n\nexport interface BodyRegion {\n /** Stable, unique identifier (snake_case) — the key used in a PainReport. */\n key: string;\n /** Human label (Danish). */\n label: string;\n /** Clinical short code (unique). */\n code: string;\n /** Body side, when the region is paired. */\n side?: Side;\n}\n\n/** The canonical body regions — the AUTHORITATIVE fd-sundhed clinical taxonomy\n * (docs/BODYMAP-TAKSONOMI.md, broberg-ai/fd-sundhed @360842f): 18 SIDE-LESS\n * clinical codes + a separate `side` field (L/R on limbs, C=center on axis\n * regions). The `key` is a unique per-side identifier; `code` is the side-less\n * clinical code that goes on the bodymap/v1 wire. NOT an anatomical atlas —\n * ~30 named surface regions for a pain-map. The 2D front renderer draws the\n * front-visible subset; the 3D body (F052.6) drives them all. */\nexport const REGIONS: readonly BodyRegion[] = [\n // axis / centre-line (serialised side \"center\")\n { key: \"head\", label: \"Hoved\", code: \"HEAD\" },\n { key: \"neck\", label: \"Nakke\", code: \"NECK\" },\n { key: \"chest\", label: \"Bryst\", code: \"CHEST\" },\n { key: \"thora\", label: \"Øvre ryg (thorakal)\", code: \"THORA\" },\n { key: \"lumbar\", label: \"Lænd (lumbal)\", code: \"LUMBAR\" },\n { key: \"groin\", label: \"Lyske\", code: \"GROIN\" },\n // paired limbs / sides (L / R)\n { key: \"shoulder_left\", label: \"Skulder, venstre\", code: \"SHOULDER\", side: \"left\" },\n { key: \"shoulder_right\", label: \"Skulder, højre\", code: \"SHOULDER\", side: \"right\" },\n { key: \"uarm_left\", label: \"Overarm, venstre\", code: \"UARM\", side: \"left\" },\n { key: \"uarm_right\", label: \"Overarm, højre\", code: \"UARM\", side: \"right\" },\n { key: \"elbow_left\", label: \"Albue, venstre\", code: \"ELBOW\", side: \"left\" },\n { key: \"elbow_right\", label: \"Albue, højre\", code: \"ELBOW\", side: \"right\" },\n { key: \"farm_left\", label: \"Underarm, venstre\", code: \"FARM\", side: \"left\" },\n { key: \"farm_right\", label: \"Underarm, højre\", code: \"FARM\", side: \"right\" },\n { key: \"wrist_left\", label: \"Håndled, venstre\", code: \"WRIST\", side: \"left\" },\n { key: \"wrist_right\", label: \"Håndled, højre\", code: \"WRIST\", side: \"right\" },\n { key: \"hand_left\", label: \"Hånd, venstre\", code: \"HAND\", side: \"left\" },\n { key: \"hand_right\", label: \"Hånd, højre\", code: \"HAND\", side: \"right\" },\n { key: \"hip_left\", label: \"Hofte, venstre\", code: \"HIP\", side: \"left\" },\n { key: \"hip_right\", label: \"Hofte, højre\", code: \"HIP\", side: \"right\" },\n { key: \"thigh_left\", label: \"Lår, venstre\", code: \"THIGH\", side: \"left\" },\n { key: \"thigh_right\", label: \"Lår, højre\", code: \"THIGH\", side: \"right\" },\n { key: \"knee_left\", label: \"Knæ, venstre\", code: \"KNEE\", side: \"left\" },\n { key: \"knee_right\", label: \"Knæ, højre\", code: \"KNEE\", side: \"right\" },\n { key: \"lowleg_left\", label: \"Underben, venstre\", code: \"LOWLEG\", side: \"left\" },\n { key: \"lowleg_right\", label: \"Underben, højre\", code: \"LOWLEG\", side: \"right\" },\n { key: \"ankle_left\", label: \"Ankel, venstre\", code: \"ANKLE\", side: \"left\" },\n { key: \"ankle_right\", label: \"Ankel, højre\", code: \"ANKLE\", side: \"right\" },\n { key: \"foot_left\", label: \"Fod, venstre\", code: \"FOOT\", side: \"left\" },\n { key: \"foot_right\", label: \"Fod, højre\", code: \"FOOT\", side: \"right\" },\n];\n\nconst REGION_KEY_SET = new Set(REGIONS.map((r) => r.key));\nexport const REGION_KEYS: readonly string[] = REGIONS.map((r) => r.key);\n\n/** Look up a region by its key. */\nexport function getRegion(key: string): BodyRegion | undefined {\n return REGIONS.find((r) => r.key === key);\n}\n\n// ---- PainReport model ---------------------------------------------------\n\nexport const PAIN_TYPES = [\"stikkende\", \"dump\", \"konstant\", \"jagende\"] as const;\nexport type PainType = (typeof PAIN_TYPES)[number];\n\n/** One marked pain point. `region` MUST be a known region key; `intensity` is a\n * 0-10 integer; `type` is optional but constrained; `timestamp` is an ISO string. */\nexport const painPointSchema = z.object({\n region: z.string().refine((k) => REGION_KEY_SET.has(k), { message: \"unknown region\" }),\n intensity: z.number().int().min(0).max(10),\n type: z.enum(PAIN_TYPES).optional(),\n timestamp: z.string(),\n});\nexport type PainPoint = z.infer<typeof painPointSchema>;\n\nexport const painReportSchema = z.array(painPointSchema);\nexport type PainReport = PainPoint[];\n\n// ---- Selection engine (framework-agnostic) ------------------------------\n\nexport interface PainSelection {\n /** Mark (or update) pain on a region. One point per region — latest wins. */\n set(region: string, intensity: number, type?: PainType): PainPoint;\n remove(region: string): boolean;\n get(region: string): PainPoint | undefined;\n has(region: string): boolean;\n clear(): void;\n /** The current, validated PainReport. */\n getReport(): PainReport;\n}\n\nexport interface PainSelectionOptions {\n /** Injectable clock (ISO string) — defaults to `new Date().toISOString()`. */\n now?: () => string;\n}\n\n/** Create a selection engine seeded with an optional report. Pure state — no\n * DOM, no framework, no network. One point per region. */\nexport function createPainSelection(\n initial: PainReport = [],\n opts: PainSelectionOptions = {},\n): PainSelection {\n const now = opts.now ?? (() => new Date().toISOString());\n const map = new Map<string, PainPoint>();\n for (const p of initial) {\n const v = painPointSchema.parse(p);\n map.set(v.region, v);\n }\n return {\n set(region, intensity, type) {\n const point = painPointSchema.parse({ region, intensity, type, timestamp: now() });\n map.set(point.region, point);\n return point;\n },\n remove: (region) => map.delete(region),\n get: (region) => map.get(region),\n has: (region) => map.has(region),\n clear: () => map.clear(),\n getReport: () => painReportSchema.parse(Array.from(map.values())),\n };\n}\n\n// ---- Per-app region config (the toggle) ---------------------------------\n\nexport interface RegionSetting {\n /** Render this region at all. Default true. */\n visible?: boolean;\n /** Allow marking pain on this region. Default true. */\n selectable?: boolean;\n}\n\n/** Per-app config keyed by region key. An absent key ⇒ visible + selectable. */\nexport type RegionConfig = Record<string, RegionSetting>;\n\n/** The regions an app should render, honouring `visible` (default true). */\nexport function resolveRegions(config: RegionConfig = {}): BodyRegion[] {\n return REGIONS.filter((r) => config[r.key]?.visible ?? true);\n}\n\n/**\n * What a pick on a region should DO (F052.20).\n *\n * Lives in the core because the 2D and 3D renderers share no click code, and a\n * rule written twice is a rule that drifts. This repo measured the cost of that\n * twice on 2026-08-28 alone: a fix applied to one half of a pair, and a sibling\n * branch that carried the same defect with no test on it.\n *\n * \"clear\" the region is already marked → picking it again removes the mark\n * \"select\" unmarked → open it for marking\n * \"ignore\" not selectable (read-only or config) → nothing happens\n *\n * Three outcomes, not a boolean: \"nothing happened because it is locked\" and\n * \"nothing happened because we removed the mark\" must never look alike to a\n * caller.\n */\nexport type PickOutcome = \"clear\" | \"select\" | \"ignore\";\n\nexport function decidePick(\n region: string,\n report: PainReport,\n config: RegionConfig = {},\n): PickOutcome {\n if (!isSelectable(region, config)) return \"ignore\";\n return report.some((p) => p.region === region) ? \"clear\" : \"select\";\n}\n\n/** Whether a region may be marked. A hidden region is never selectable. */\nexport function isSelectable(key: string, config: RegionConfig = {}): boolean {\n const s = config[key];\n if (s?.visible === false) return false;\n return s?.selectable ?? true;\n}\n\n// ---- feedback signal: sound + haptics (F052.22) -----------------------------\n\n/**\n * What a pick did, handed to the consuming app so it can make a sound or a buzz.\n *\n * The outcome is the one `decidePick` ACTUALLY returned, never the intent to tap\n * — so a tap on a locked region can not announce itself as a removal, and a tap\n * the pan/pinch guard swallowed emits nothing at all (it never gets here).\n *\n * It deliberately reuses `PickOutcome` rather than introducing a second\n * three-word vocabulary. Two enums meaning the same thing is a drift bug waiting\n * for the first person who adds a fourth outcome to only one of them.\n */\nexport interface FeedbackSignal {\n outcome: PickOutcome;\n /** The region key that was picked. */\n region: string;\n}\n\nexport type FeedbackFn = (signal: FeedbackSignal) => void;\n\n/**\n * What the BROWSER did with a vibration request.\n *\n * ⚠️ `requested` does NOT mean the phone buzzed. `navigator.vibrate()` returns\n * true for a request it accepted, and all of these accept it and then produce\n * nothing: silent / do-not-disturb mode, a device with no vibration motor (most\n * laptops), a page that has not yet had a qualifying user gesture.\n *\n * Same lesson `@broberg/webpush` 0.3.1 recorded — a push that provably ARRIVED\n * on a device that never SHOWED it. \"Accepted\" and \"happened\" are two claims,\n * and only one of them is observable from here.\n */\nexport type VibrateOutcome = \"unsupported\" | \"skipped\" | \"declined\" | \"requested\";\n\n/**\n * The buzz for each outcome.\n *\n * `ignore` is empty ON PURPOSE: a tap that changed nothing must not feel like it\n * changed something. That is the whole reason this is keyed by outcome and not\n * fired from the tap handler.\n */\nexport const VIBRATION_PATTERNS: Record<PickOutcome, readonly number[]> = {\n select: [12],\n clear: [8, 40, 8],\n ignore: [],\n};\n\ninterface Vibrator {\n vibrate?: (pattern: number | number[]) => boolean;\n}\n\n/**\n * Ask the browser to vibrate. Never throws, never claims delivery.\n *\n * `nav` is injectable so a test can supply all four cases; it defaults to the\n * real `navigator` and is `unsupported` when there is not one (SSR, and every\n * browser on iPhone — WebKit has no `vibrate` at all).\n */\nexport function requestVibration(\n pattern: readonly number[],\n nav: Vibrator | undefined = (globalThis as { navigator?: Vibrator }).navigator,\n): VibrateOutcome {\n if (pattern.length === 0) return \"skipped\";\n if (typeof nav?.vibrate !== \"function\") return \"unsupported\";\n try {\n return nav.vibrate([...pattern]) ? \"requested\" : \"declined\";\n } catch {\n // Embedded webviews and cross-origin iframes throw rather than return false.\n // A refused buzz must never take the pain report down with it.\n return \"declined\";\n }\n}\n\nexport interface FeedbackOptions {\n onFeedback?: FeedbackFn;\n /** Web vibration on select/clear. Default true; inert where the API is absent. */\n haptics?: boolean;\n /** Injectable for tests. */\n nav?: unknown;\n}\n\n/**\n * Emit one pick's feedback: always the signal, optionally the buzz.\n *\n * Lives in the core because the 2D and 3D renderers share no click code, and a\n * rule written twice is a rule that drifts — the same reason `decidePick` is\n * here (F052.20).\n *\n * Sound is NOT here and never will be: `@broberg/soundkit` already exists, and\n * pulling Web Audio into a component that is often rendered read-only (a\n * journal, a PDF, a clinician view) is a cost every consumer would pay for a\n * feature most will not switch on. Wire `onFeedback` to it in four lines.\n */\nexport function emitFeedback(\n outcome: PickOutcome,\n region: string,\n opts: FeedbackOptions = {},\n): VibrateOutcome {\n opts.onFeedback?.({ outcome, region });\n if (opts.haptics === false) return \"skipped\";\n // `undefined` falls through to requestVibration's own default (the real\n // navigator) — so an omitted `nav` and a passed-in one take the same path.\n return requestVibration(VIBRATION_PATTERNS[outcome], opts.nav as Vibrator | undefined);\n}\n\n// ---- palette (consumer-defined colours — shared by the 2D + 3D renderers) ---\n\n/** Colour control for the body renderers. Consumers pass a palette to theme the\n * body base colour, the hover + selected highlights, the pain-heat colours, and\n * optional per-region base colours. All values are CSS/hex colour strings. */\nexport interface BodymapPalette {\n /** Base body colour (an unmarked region). */\n body: string;\n /** Region highlight on hover (before click). */\n hover: string;\n /** A region selected (clicked) but not yet given an intensity. */\n selected: string;\n /** Pain-intensity heat colours: low (0-3), mid (4-6), high (7-10). */\n heat: { low: string; mid: string; high: string };\n /** Optional per-region base-colour overrides (region key → colour). */\n regions?: Record<string, string>;\n /**\n * Optional panel-chrome colours (the selection panel, labels, hint box) —\n * NOT the body itself. All optional; anything omitted falls back to\n * {@link defaultUi}. A palette that only themed the body was half a palette:\n * a consumer passing brand colours still got hardcoded chrome. (F052.19)\n */\n ui?: BodymapUiColors;\n}\n\n/** Panel-chrome colours. Every default is WCAG-AA (>=4.5:1) on its own background. */\nexport interface BodymapUiColors {\n /** Primary text (headings, values). */\n text?: string;\n /** Secondary text — section labels, the empty-state hint. */\n mutedText?: string;\n /** Panel background. */\n panelBg?: string;\n /** Panel + control borders. */\n border?: string;\n /** Background behind the region-code badge. */\n badgeBg?: string;\n /** The destructive action (remove a marked region). */\n danger?: string;\n}\n\n/**\n * Default panel chrome. Contrast against `panelBg` (#fff), asserted by\n * `test/contrast.test.ts`:\n * text #1e293b 14.8:1\n * mutedText #475569 7.6:1 (was #94a3b8 at 2.56:1 — WCAG AA failure)\n * danger #dc2626 4.8:1 (was #ef4444 at 3.76:1 — WCAG AA failure)\n * `mutedText` on `badgeBg` (#f1f5f9) is 6.9:1 (was #64748b at 4.34:1).\n */\nexport const defaultUi: Required<BodymapUiColors> = {\n text: \"#1e293b\",\n mutedText: \"#475569\",\n panelBg: \"#fff\",\n border: \"#e2e8f0\",\n badgeBg: \"#f1f5f9\",\n danger: \"#dc2626\",\n};\n\n/** Resolve a palette's chrome colours, filling every gap from {@link defaultUi}. */\nexport function uiColors(palette?: BodymapPalette): Required<BodymapUiColors> {\n return { ...defaultUi, ...(palette?.ui ?? {}) };\n}\n\n/** The fleet default palette. Override any field per consumer. */\nexport const defaultPalette: BodymapPalette = {\n body: \"#d2d7de\",\n hover: \"#8fd0cd\",\n selected: \"#5cc4b7\",\n heat: { low: \"#fcd34d\", mid: \"#fb923c\", high: \"#ef4444\" },\n};\n\n/** The heat colour for a pain intensity, honouring the palette. */\nexport function heatFor(intensity: number, palette: BodymapPalette = defaultPalette): string {\n return intensity >= 7 ? palette.heat.high : intensity >= 4 ? palette.heat.mid : palette.heat.low;\n}\n\n/** The base colour for a region (a per-region override, else the body colour). */\nexport function baseColorFor(regionKey: string, palette: BodymapPalette = defaultPalette): string {\n return palette.regions?.[regionKey] ?? palette.body;\n}\n\n// ---- bodymap/v1 serialization (the shared cross-app / native wire format) ---\n//\n// The shape every consumer + the native mobile apps read (aligned with\n// fd-sundhed's bodymap/v1: region CODE + side + intensity + quality + view).\n// The internal PainReport keys on the region KEY; this maps key -> clinical CODE\n// so the report is portable and human-readable on the wire.\n\nexport type BodyView = \"front\" | \"back\" | \"left\" | \"right\";\n/** Side in the serialized report — a midline region (no side) becomes \"center\". */\nexport type SerializedSide = \"left\" | \"right\" | \"center\";\n\nexport interface SerializedPainPoint {\n /** Clinical region CODE (e.g. \"LUMB\"). */\n region: string;\n side: SerializedSide;\n intensity: number;\n quality?: PainType;\n}\n\nexport interface BodymapReportV1 {\n schema: \"bodymap/v1\";\n view: BodyView;\n points: SerializedPainPoint[];\n}\n\nexport const bodymapReportV1Schema = z.object({\n schema: z.literal(\"bodymap/v1\"),\n view: z.enum([\"front\", \"back\", \"left\", \"right\"]),\n points: z.array(\n z.object({\n region: z.string(),\n side: z.enum([\"left\", \"right\", \"center\"]),\n intensity: z.number().int().min(0).max(10),\n quality: z.enum(PAIN_TYPES).optional(),\n }),\n ),\n});\n\n/** Serialize a PainReport to the shared `bodymap/v1` wire format. */\nexport function serializeReport(\n report: PainReport,\n opts: { view?: BodyView } = {},\n): BodymapReportV1 {\n return {\n schema: \"bodymap/v1\",\n view: opts.view ?? \"front\",\n points: report.map((p) => {\n const r = getRegion(p.region);\n return {\n region: r?.code ?? p.region,\n side: (r?.side ?? \"center\") as SerializedSide,\n intensity: p.intensity,\n quality: p.type,\n };\n }),\n };\n}\n\n/** Parse a `bodymap/v1` report back into an internal PainReport. Region CODE →\n * key; a point whose code is unknown to this taxonomy is dropped. */\nexport function deserializeReport(\n env: unknown,\n now: () => string = () => new Date().toISOString(),\n): PainReport {\n const parsed = bodymapReportV1Schema.parse(env);\n // code is side-less, so a point is identified by code + side.\n const byCodeSide = new Map(\n REGIONS.map((r) => [`${r.code}|${r.side ?? \"center\"}`, r.key] as const),\n );\n const out: PainReport = [];\n for (const sp of parsed.points) {\n const key = byCodeSide.get(`${sp.region}|${sp.side}`);\n if (!key) continue;\n out.push(\n painPointSchema.parse({\n region: key,\n intensity: sp.intensity,\n type: sp.quality,\n timestamp: now(),\n }),\n );\n }\n return out;\n}\n"]}
1
+ {"version":3,"sources":["../src/index.ts"],"names":["z"],"mappings":";;;;;AA6BO,IAAM,OAAA,GAAiC;AAAA;AAAA,EAE5C,EAAE,GAAA,EAAK,MAAA,EAAQ,KAAA,EAAO,OAAA,EAAS,MAAM,MAAA,EAAO;AAAA,EAC5C,EAAE,GAAA,EAAK,MAAA,EAAQ,KAAA,EAAO,OAAA,EAAS,MAAM,MAAA,EAAO;AAAA,EAC5C,EAAE,GAAA,EAAK,OAAA,EAAS,KAAA,EAAO,OAAA,EAAS,MAAM,OAAA,EAAQ;AAAA,EAC9C,EAAE,GAAA,EAAK,OAAA,EAAS,KAAA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E,GAAG,CAAU;AAAA,GACxE;AACA,EAAA,MAAM,MAAkB,EAAC;AACzB,EAAA,KAAA,MAAW,EAAA,IAAM,OAAO,MAAA,EAAQ;AAC9B,IAAA,MAAM,GAAA,GAAM,WAAW,GAAA,CAAI,CAAA,EAAG,GAAG,MAAM,CAAA,CAAA,EAAI,EAAA,CAAG,IAAI,CAAA,CAAE,CAAA;AACpD,IAAA,IAAI,CAAC,GAAA,EAAK;AACV,IAAA,GAAA,CAAI,IAAA;AAAA,MACF,gBAAgB,KAAA,CAAM;AAAA,QACpB,MAAA,EAAQ,GAAA;AAAA,QACR,WAAW,EAAA,CAAG,SAAA;AAAA,QACd,MAAM,EAAA,CAAG,OAAA;AAAA,QACT,WAAW,GAAA;AAAI,OAChB;AAAA,KACH;AAAA,EACF;AACA,EAAA,OAAO,GAAA;AACT","file":"index.cjs","sourcesContent":["// @broberg/bodymap — headless core (F052.1).\n//\n// Framework-neutral: the region taxonomy + the PainReport data model (zod) + a\n// selection engine + per-app region config. NO React/Preact/DOM import — the 2D\n// (SVG) and 3D (Three.js) renderers, and all three FD apps, share this one\n// contract. Output is a structured PainReport, never a bare image.\n\nimport { z } from \"zod\";\n\nexport type Side = \"left\" | \"right\";\n\nexport interface BodyRegion {\n /** Stable, unique identifier (snake_case) — the key used in a PainReport. */\n key: string;\n /** Human label (Danish). */\n label: string;\n /** Clinical short code (unique). */\n code: string;\n /** Body side, when the region is paired. */\n side?: Side;\n}\n\n/** The canonical body regions — the AUTHORITATIVE fd-sundhed clinical taxonomy\n * (docs/BODYMAP-TAKSONOMI.md, broberg-ai/fd-sundhed @360842f): 18 SIDE-LESS\n * clinical codes + a separate `side` field (L/R on limbs, C=center on axis\n * regions). The `key` is a unique per-side identifier; `code` is the side-less\n * clinical code that goes on the bodymap/v1 wire. NOT an anatomical atlas —\n * ~30 named surface regions for a pain-map. The 2D front renderer draws the\n * front-visible subset; the 3D body (F052.6) drives them all. */\nexport const REGIONS: readonly BodyRegion[] = [\n // axis / centre-line (serialised side \"center\")\n { key: \"head\", label: \"Hoved\", code: \"HEAD\" },\n { key: \"neck\", label: \"Nakke\", code: \"NECK\" },\n { key: \"chest\", label: \"Bryst\", code: \"CHEST\" },\n { key: \"thora\", label: \"Øvre ryg (thorakal)\", code: \"THORA\" },\n { key: \"lumbar\", label: \"Lænd (lumbal)\", code: \"LUMBAR\" },\n { key: \"groin\", label: \"Lyske\", code: \"GROIN\" },\n // paired limbs / sides (L / R)\n { key: \"shoulder_left\", label: \"Skulder, venstre\", code: \"SHOULDER\", side: \"left\" },\n { key: \"shoulder_right\", label: \"Skulder, højre\", code: \"SHOULDER\", side: \"right\" },\n { key: \"uarm_left\", label: \"Overarm, venstre\", code: \"UARM\", side: \"left\" },\n { key: \"uarm_right\", label: \"Overarm, højre\", code: \"UARM\", side: \"right\" },\n { key: \"elbow_left\", label: \"Albue, venstre\", code: \"ELBOW\", side: \"left\" },\n { key: \"elbow_right\", label: \"Albue, højre\", code: \"ELBOW\", side: \"right\" },\n { key: \"farm_left\", label: \"Underarm, venstre\", code: \"FARM\", side: \"left\" },\n { key: \"farm_right\", label: \"Underarm, højre\", code: \"FARM\", side: \"right\" },\n { key: \"wrist_left\", label: \"Håndled, venstre\", code: \"WRIST\", side: \"left\" },\n { key: \"wrist_right\", label: \"Håndled, højre\", code: \"WRIST\", side: \"right\" },\n { key: \"hand_left\", label: \"Hånd, venstre\", code: \"HAND\", side: \"left\" },\n { key: \"hand_right\", label: \"Hånd, højre\", code: \"HAND\", side: \"right\" },\n { key: \"hip_left\", label: \"Hofte, venstre\", code: \"HIP\", side: \"left\" },\n { key: \"hip_right\", label: \"Hofte, højre\", code: \"HIP\", side: \"right\" },\n { key: \"thigh_left\", label: \"Lår, venstre\", code: \"THIGH\", side: \"left\" },\n { key: \"thigh_right\", label: \"Lår, højre\", code: \"THIGH\", side: \"right\" },\n { key: \"knee_left\", label: \"Knæ, venstre\", code: \"KNEE\", side: \"left\" },\n { key: \"knee_right\", label: \"Knæ, højre\", code: \"KNEE\", side: \"right\" },\n { key: \"lowleg_left\", label: \"Underben, venstre\", code: \"LOWLEG\", side: \"left\" },\n { key: \"lowleg_right\", label: \"Underben, højre\", code: \"LOWLEG\", side: \"right\" },\n { key: \"ankle_left\", label: \"Ankel, venstre\", code: \"ANKLE\", side: \"left\" },\n { key: \"ankle_right\", label: \"Ankel, højre\", code: \"ANKLE\", side: \"right\" },\n { key: \"foot_left\", label: \"Fod, venstre\", code: \"FOOT\", side: \"left\" },\n { key: \"foot_right\", label: \"Fod, højre\", code: \"FOOT\", side: \"right\" },\n];\n\nconst REGION_KEY_SET = new Set(REGIONS.map((r) => r.key));\nexport const REGION_KEYS: readonly string[] = REGIONS.map((r) => r.key);\n\n/** Look up a region by its key. */\nexport function getRegion(key: string): BodyRegion | undefined {\n return REGIONS.find((r) => r.key === key);\n}\n\n// ---- PainReport model ---------------------------------------------------\n\nexport const PAIN_TYPES = [\"stikkende\", \"dump\", \"konstant\", \"jagende\"] as const;\nexport type PainType = (typeof PAIN_TYPES)[number];\n\n/** One marked pain point. `region` MUST be a known region key; `intensity` is a\n * 0-10 integer; `type` is optional but constrained; `timestamp` is an ISO string. */\nexport const painPointSchema = z.object({\n region: z.string().refine((k) => REGION_KEY_SET.has(k), { message: \"unknown region\" }),\n intensity: z.number().int().min(0).max(10),\n type: z.enum(PAIN_TYPES).optional(),\n timestamp: z.string(),\n});\nexport type PainPoint = z.infer<typeof painPointSchema>;\n\nexport const painReportSchema = z.array(painPointSchema);\nexport type PainReport = PainPoint[];\n\n// ---- Selection engine (framework-agnostic) ------------------------------\n\nexport interface PainSelection {\n /** Mark (or update) pain on a region. One point per region — latest wins. */\n set(region: string, intensity: number, type?: PainType): PainPoint;\n remove(region: string): boolean;\n get(region: string): PainPoint | undefined;\n has(region: string): boolean;\n clear(): void;\n /** The current, validated PainReport. */\n getReport(): PainReport;\n}\n\nexport interface PainSelectionOptions {\n /** Injectable clock (ISO string) — defaults to `new Date().toISOString()`. */\n now?: () => string;\n}\n\n/** Create a selection engine seeded with an optional report. Pure state — no\n * DOM, no framework, no network. One point per region. */\nexport function createPainSelection(\n initial: PainReport = [],\n opts: PainSelectionOptions = {},\n): PainSelection {\n const now = opts.now ?? (() => new Date().toISOString());\n const map = new Map<string, PainPoint>();\n for (const p of initial) {\n const v = painPointSchema.parse(p);\n map.set(v.region, v);\n }\n return {\n set(region, intensity, type) {\n const point = painPointSchema.parse({ region, intensity, type, timestamp: now() });\n map.set(point.region, point);\n return point;\n },\n remove: (region) => map.delete(region),\n get: (region) => map.get(region),\n has: (region) => map.has(region),\n clear: () => map.clear(),\n getReport: () => painReportSchema.parse(Array.from(map.values())),\n };\n}\n\n// ---- Per-app region config (the toggle) ---------------------------------\n\nexport interface RegionSetting {\n /** Render this region at all. Default true. */\n visible?: boolean;\n /** Allow marking pain on this region. Default true. */\n selectable?: boolean;\n}\n\n/** Per-app config keyed by region key. An absent key ⇒ visible + selectable. */\nexport type RegionConfig = Record<string, RegionSetting>;\n\n/** The regions an app should render, honouring `visible` (default true). */\nexport function resolveRegions(config: RegionConfig = {}): BodyRegion[] {\n return REGIONS.filter((r) => config[r.key]?.visible ?? true);\n}\n\n/**\n * What a pick on a region should DO (F052.20).\n *\n * Lives in the core because the 2D and 3D renderers share no click code, and a\n * rule written twice is a rule that drifts. This repo measured the cost of that\n * twice on 2026-08-28 alone: a fix applied to one half of a pair, and a sibling\n * branch that carried the same defect with no test on it.\n *\n * \"clear\" the region is already marked → picking it again removes the mark\n * \"select\" unmarked → open it for marking\n * \"ignore\" not selectable (read-only or config) → nothing happens\n *\n * Three outcomes, not a boolean: \"nothing happened because it is locked\" and\n * \"nothing happened because we removed the mark\" must never look alike to a\n * caller.\n */\nexport type PickOutcome = \"clear\" | \"select\" | \"ignore\";\n\nexport function decidePick(\n region: string,\n report: PainReport,\n config: RegionConfig = {},\n): PickOutcome {\n if (!isSelectable(region, config)) return \"ignore\";\n return report.some((p) => p.region === region) ? \"clear\" : \"select\";\n}\n\n/** Whether a region may be marked. A hidden region is never selectable. */\nexport function isSelectable(key: string, config: RegionConfig = {}): boolean {\n const s = config[key];\n if (s?.visible === false) return false;\n return s?.selectable ?? true;\n}\n\n// ---- feedback signal: sound + haptics (F052.22) -----------------------------\n\n/**\n * What a pick did, handed to the consuming app so it can make a sound or a buzz.\n *\n * The outcome is the one `decidePick` ACTUALLY returned, never the intent to tap\n * — so a tap on a locked region can not announce itself as a removal, and a tap\n * the pan/pinch guard swallowed emits nothing at all (it never gets here).\n *\n * It deliberately reuses `PickOutcome` rather than introducing a second\n * three-word vocabulary. Two enums meaning the same thing is a drift bug waiting\n * for the first person who adds a fourth outcome to only one of them.\n */\nexport interface FeedbackSignal {\n outcome: PickOutcome;\n /** The region key that was picked. */\n region: string;\n}\n\nexport type FeedbackFn = (signal: FeedbackSignal) => void;\n\n/**\n * What the BROWSER did with a vibration request.\n *\n * ⚠️ `requested` does NOT mean the phone buzzed. `navigator.vibrate()` returns\n * true for a request it accepted, and all of these accept it and then produce\n * nothing: silent / do-not-disturb mode, a device with no vibration motor (most\n * laptops), a page that has not yet had a qualifying user gesture.\n *\n * Same lesson `@broberg/webpush` 0.3.1 recorded — a push that provably ARRIVED\n * on a device that never SHOWED it. \"Accepted\" and \"happened\" are two claims,\n * and only one of them is observable from here.\n */\nexport type VibrateOutcome = \"unsupported\" | \"skipped\" | \"declined\" | \"requested\";\n\n/**\n * The buzz for each outcome.\n *\n * `ignore` is empty ON PURPOSE: a tap that changed nothing must not feel like it\n * changed something. That is the whole reason this is keyed by outcome and not\n * fired from the tap handler.\n */\nexport const VIBRATION_PATTERNS: Record<PickOutcome, readonly number[]> = {\n select: [12],\n clear: [8, 40, 8],\n ignore: [],\n};\n\ninterface Vibrator {\n vibrate?: (pattern: number | number[]) => boolean;\n}\n\n/**\n * Ask the browser to vibrate. Never throws, never claims delivery.\n *\n * `nav` is injectable so a test can supply all four cases; it defaults to the\n * real `navigator` and is `unsupported` when there is not one (SSR, and every\n * browser on iPhone — WebKit has no `vibrate` at all).\n */\nexport function requestVibration(\n pattern: readonly number[],\n nav: Vibrator | undefined = (globalThis as { navigator?: Vibrator }).navigator,\n): VibrateOutcome {\n if (pattern.length === 0) return \"skipped\";\n if (typeof nav?.vibrate !== \"function\") return \"unsupported\";\n try {\n return nav.vibrate([...pattern]) ? \"requested\" : \"declined\";\n } catch {\n // Embedded webviews and cross-origin iframes throw rather than return false.\n // A refused buzz must never take the pain report down with it.\n return \"declined\";\n }\n}\n\nexport interface FeedbackOptions {\n onFeedback?: FeedbackFn;\n /** Web vibration on select/clear. Default true; inert where the API is absent. */\n haptics?: boolean;\n /** Injectable for tests. */\n nav?: unknown;\n}\n\n/**\n * Emit one pick's feedback: always the signal, optionally the buzz.\n *\n * Lives in the core because the 2D and 3D renderers share no click code, and a\n * rule written twice is a rule that drifts — the same reason `decidePick` is\n * here (F052.20).\n *\n * Sound is NOT here and never will be: `@broberg/soundkit` already exists, and\n * pulling Web Audio into a component that is often rendered read-only (a\n * journal, a PDF, a clinician view) is a cost every consumer would pay for a\n * feature most will not switch on. Wire `onFeedback` to it in four lines.\n */\nexport function emitFeedback(\n outcome: PickOutcome,\n region: string,\n opts: FeedbackOptions = {},\n): VibrateOutcome {\n opts.onFeedback?.({ outcome, region });\n if (opts.haptics === false) return \"skipped\";\n // `undefined` falls through to requestVibration's own default (the real\n // navigator) — so an omitted `nav` and a passed-in one take the same path.\n return requestVibration(VIBRATION_PATTERNS[outcome], opts.nav as Vibrator | undefined);\n}\n\n// ---- palette (consumer-defined colours — shared by the 2D + 3D renderers) ---\n\n/** Colour control for the body renderers. Consumers pass a palette to theme the\n * body base colour, the hover + selected highlights, the pain-heat colours, and\n * optional per-region base colours. All values are CSS/hex colour strings. */\nexport interface BodymapPalette {\n /** Base body colour (an unmarked region). */\n body: string;\n /** Region highlight on hover (before click). */\n hover: string;\n /** A region selected (clicked) but not yet given an intensity. */\n selected: string;\n /** Pain-intensity heat colours: low (0-3), mid (4-6), high (7-10). */\n heat: { low: string; mid: string; high: string };\n /** Optional per-region base-colour overrides (region key → colour). */\n regions?: Record<string, string>;\n /**\n * Optional panel-chrome colours (the selection panel, labels, hint box) —\n * NOT the body itself. All optional; anything omitted falls back to\n * {@link defaultUi}. A palette that only themed the body was half a palette:\n * a consumer passing brand colours still got hardcoded chrome. (F052.19)\n */\n ui?: BodymapUiColors;\n}\n\n/** Panel-chrome colours. Every default is WCAG-AA (>=4.5:1) on its own background. */\nexport interface BodymapUiColors {\n /** Primary text (headings, values). */\n text?: string;\n /** Secondary text — section labels, the empty-state hint. */\n mutedText?: string;\n /** Panel background — the card, its buttons, the empty hint. */\n panelBg?: string;\n /**\n * THE STAGE: the fullscreen backdrop, the canvas frame, and the three.js\n * scene behind the body. A different surface from `panelBg` with an opposite\n * need — see F052.29, where one field paints both and no value is right for\n * either.\n *\n * 3D only. The 2D renderer has no canvas and no fullscreen, so it ignores\n * this; it is declared here because a stage is a shared idea, not because\n * every renderer has one.\n *\n * Defaults to {@link STAGE_BG}. Pass `'#fff'` for the pre-0.8.0 white\n * fullscreen backdrop.\n */\n stageBg?: string;\n /** Panel + control borders. */\n border?: string;\n /** Background behind the region-code badge. */\n badgeBg?: string;\n /** The destructive action (remove a marked region). */\n danger?: string;\n}\n\n/**\n * Default panel chrome. Contrast against `panelBg` (#fff), asserted by\n * `test/contrast.test.ts`:\n * text #1e293b 14.8:1\n * mutedText #475569 7.6:1 (was #94a3b8 at 2.56:1 — WCAG AA failure)\n * danger #dc2626 4.8:1 (was #ef4444 at 3.76:1 — WCAG AA failure)\n * `mutedText` on `badgeBg` (#f1f5f9) is 6.9:1 (was #64748b at 4.34:1).\n */\n/**\n * The stage colour — the ONE place this value lives.\n *\n * It used to be a literal in three places in `three.tsx` (the three.js scene,\n * the canvas frame, the unsupported placeholder), which meant a consumer could\n * recolour the backdrop and still get OUR navy inside it. That seam is\n * invisible on a desktop and obvious on a phone. (F052.29)\n */\nexport const STAGE_BG = \"#0e1424\";\n\nexport const defaultUi: Required<BodymapUiColors> = {\n text: \"#1e293b\",\n mutedText: \"#475569\",\n panelBg: \"#fff\",\n stageBg: STAGE_BG,\n border: \"#e2e8f0\",\n badgeBg: \"#f1f5f9\",\n danger: \"#dc2626\",\n};\n\n/** Resolve a palette's chrome colours, filling every gap from {@link defaultUi}. */\nexport function uiColors(palette?: BodymapPalette): Required<BodymapUiColors> {\n return { ...defaultUi, ...(palette?.ui ?? {}) };\n}\n\n/** The fleet default palette. Override any field per consumer. */\nexport const defaultPalette: BodymapPalette = {\n body: \"#d2d7de\",\n hover: \"#8fd0cd\",\n selected: \"#5cc4b7\",\n heat: { low: \"#fcd34d\", mid: \"#fb923c\", high: \"#ef4444\" },\n};\n\n/** The heat colour for a pain intensity, honouring the palette. */\nexport function heatFor(intensity: number, palette: BodymapPalette = defaultPalette): string {\n return intensity >= 7 ? palette.heat.high : intensity >= 4 ? palette.heat.mid : palette.heat.low;\n}\n\n/** The base colour for a region (a per-region override, else the body colour). */\nexport function baseColorFor(regionKey: string, palette: BodymapPalette = defaultPalette): string {\n return palette.regions?.[regionKey] ?? palette.body;\n}\n\n// ---- bodymap/v1 serialization (the shared cross-app / native wire format) ---\n//\n// The shape every consumer + the native mobile apps read (aligned with\n// fd-sundhed's bodymap/v1: region CODE + side + intensity + quality + view).\n// The internal PainReport keys on the region KEY; this maps key -> clinical CODE\n// so the report is portable and human-readable on the wire.\n\nexport type BodyView = \"front\" | \"back\" | \"left\" | \"right\";\n/** Side in the serialized report — a midline region (no side) becomes \"center\". */\nexport type SerializedSide = \"left\" | \"right\" | \"center\";\n\nexport interface SerializedPainPoint {\n /** Clinical region CODE (e.g. \"LUMB\"). */\n region: string;\n side: SerializedSide;\n intensity: number;\n quality?: PainType;\n}\n\nexport interface BodymapReportV1 {\n schema: \"bodymap/v1\";\n view: BodyView;\n points: SerializedPainPoint[];\n}\n\nexport const bodymapReportV1Schema = z.object({\n schema: z.literal(\"bodymap/v1\"),\n view: z.enum([\"front\", \"back\", \"left\", \"right\"]),\n points: z.array(\n z.object({\n region: z.string(),\n side: z.enum([\"left\", \"right\", \"center\"]),\n intensity: z.number().int().min(0).max(10),\n quality: z.enum(PAIN_TYPES).optional(),\n }),\n ),\n});\n\n/** Serialize a PainReport to the shared `bodymap/v1` wire format. */\nexport function serializeReport(\n report: PainReport,\n opts: { view?: BodyView } = {},\n): BodymapReportV1 {\n return {\n schema: \"bodymap/v1\",\n view: opts.view ?? \"front\",\n points: report.map((p) => {\n const r = getRegion(p.region);\n return {\n region: r?.code ?? p.region,\n side: (r?.side ?? \"center\") as SerializedSide,\n intensity: p.intensity,\n quality: p.type,\n };\n }),\n };\n}\n\n/** Parse a `bodymap/v1` report back into an internal PainReport. Region CODE →\n * key; a point whose code is unknown to this taxonomy is dropped. */\nexport function deserializeReport(\n env: unknown,\n now: () => string = () => new Date().toISOString(),\n): PainReport {\n const parsed = bodymapReportV1Schema.parse(env);\n // code is side-less, so a point is identified by code + side.\n const byCodeSide = new Map(\n REGIONS.map((r) => [`${r.code}|${r.side ?? \"center\"}`, r.key] as const),\n );\n const out: PainReport = [];\n for (const sp of parsed.points) {\n const key = byCodeSide.get(`${sp.region}|${sp.side}`);\n if (!key) continue;\n out.push(\n painPointSchema.parse({\n region: key,\n intensity: sp.intensity,\n type: sp.quality,\n timestamp: now(),\n }),\n );\n }\n return out;\n}\n"]}
package/dist/index.d.cts CHANGED
@@ -208,8 +208,22 @@ interface BodymapUiColors {
208
208
  text?: string;
209
209
  /** Secondary text — section labels, the empty-state hint. */
210
210
  mutedText?: string;
211
- /** Panel background. */
211
+ /** Panel background — the card, its buttons, the empty hint. */
212
212
  panelBg?: string;
213
+ /**
214
+ * THE STAGE: the fullscreen backdrop, the canvas frame, and the three.js
215
+ * scene behind the body. A different surface from `panelBg` with an opposite
216
+ * need — see F052.29, where one field paints both and no value is right for
217
+ * either.
218
+ *
219
+ * 3D only. The 2D renderer has no canvas and no fullscreen, so it ignores
220
+ * this; it is declared here because a stage is a shared idea, not because
221
+ * every renderer has one.
222
+ *
223
+ * Defaults to {@link STAGE_BG}. Pass `'#fff'` for the pre-0.8.0 white
224
+ * fullscreen backdrop.
225
+ */
226
+ stageBg?: string;
213
227
  /** Panel + control borders. */
214
228
  border?: string;
215
229
  /** Background behind the region-code badge. */
@@ -225,6 +239,15 @@ interface BodymapUiColors {
225
239
  * danger #dc2626 4.8:1 (was #ef4444 at 3.76:1 — WCAG AA failure)
226
240
  * `mutedText` on `badgeBg` (#f1f5f9) is 6.9:1 (was #64748b at 4.34:1).
227
241
  */
242
+ /**
243
+ * The stage colour — the ONE place this value lives.
244
+ *
245
+ * It used to be a literal in three places in `three.tsx` (the three.js scene,
246
+ * the canvas frame, the unsupported placeholder), which meant a consumer could
247
+ * recolour the backdrop and still get OUR navy inside it. That seam is
248
+ * invisible on a desktop and obvious on a phone. (F052.29)
249
+ */
250
+ declare const STAGE_BG = "#0e1424";
228
251
  declare const defaultUi: Required<BodymapUiColors>;
229
252
  /** Resolve a palette's chrome colours, filling every gap from {@link defaultUi}. */
230
253
  declare function uiColors(palette?: BodymapPalette): Required<BodymapUiColors>;
@@ -295,4 +318,4 @@ declare function serializeReport(report: PainReport, opts?: {
295
318
  * key; a point whose code is unknown to this taxonomy is dropped. */
296
319
  declare function deserializeReport(env: unknown, now?: () => string): PainReport;
297
320
 
298
- export { type BodyRegion, type BodyView, type BodymapPalette, type BodymapReportV1, type BodymapUiColors, type FeedbackFn, type FeedbackOptions, type FeedbackSignal, PAIN_TYPES, type PainPoint, type PainReport, type PainSelection, type PainSelectionOptions, type PainType, type PickOutcome, REGIONS, REGION_KEYS, type RegionConfig, type RegionSetting, type SerializedPainPoint, type SerializedSide, type Side, VIBRATION_PATTERNS, type VibrateOutcome, baseColorFor, bodymapReportV1Schema, createPainSelection, decidePick, defaultPalette, defaultUi, deserializeReport, emitFeedback, getRegion, heatFor, isSelectable, painPointSchema, painReportSchema, requestVibration, resolveRegions, serializeReport, uiColors };
321
+ export { type BodyRegion, type BodyView, type BodymapPalette, type BodymapReportV1, type BodymapUiColors, type FeedbackFn, type FeedbackOptions, type FeedbackSignal, PAIN_TYPES, type PainPoint, type PainReport, type PainSelection, type PainSelectionOptions, type PainType, type PickOutcome, REGIONS, REGION_KEYS, type RegionConfig, type RegionSetting, STAGE_BG, type SerializedPainPoint, type SerializedSide, type Side, VIBRATION_PATTERNS, type VibrateOutcome, baseColorFor, bodymapReportV1Schema, createPainSelection, decidePick, defaultPalette, defaultUi, deserializeReport, emitFeedback, getRegion, heatFor, isSelectable, painPointSchema, painReportSchema, requestVibration, resolveRegions, serializeReport, uiColors };
package/dist/index.d.ts CHANGED
@@ -208,8 +208,22 @@ interface BodymapUiColors {
208
208
  text?: string;
209
209
  /** Secondary text — section labels, the empty-state hint. */
210
210
  mutedText?: string;
211
- /** Panel background. */
211
+ /** Panel background — the card, its buttons, the empty hint. */
212
212
  panelBg?: string;
213
+ /**
214
+ * THE STAGE: the fullscreen backdrop, the canvas frame, and the three.js
215
+ * scene behind the body. A different surface from `panelBg` with an opposite
216
+ * need — see F052.29, where one field paints both and no value is right for
217
+ * either.
218
+ *
219
+ * 3D only. The 2D renderer has no canvas and no fullscreen, so it ignores
220
+ * this; it is declared here because a stage is a shared idea, not because
221
+ * every renderer has one.
222
+ *
223
+ * Defaults to {@link STAGE_BG}. Pass `'#fff'` for the pre-0.8.0 white
224
+ * fullscreen backdrop.
225
+ */
226
+ stageBg?: string;
213
227
  /** Panel + control borders. */
214
228
  border?: string;
215
229
  /** Background behind the region-code badge. */
@@ -225,6 +239,15 @@ interface BodymapUiColors {
225
239
  * danger #dc2626 4.8:1 (was #ef4444 at 3.76:1 — WCAG AA failure)
226
240
  * `mutedText` on `badgeBg` (#f1f5f9) is 6.9:1 (was #64748b at 4.34:1).
227
241
  */
242
+ /**
243
+ * The stage colour — the ONE place this value lives.
244
+ *
245
+ * It used to be a literal in three places in `three.tsx` (the three.js scene,
246
+ * the canvas frame, the unsupported placeholder), which meant a consumer could
247
+ * recolour the backdrop and still get OUR navy inside it. That seam is
248
+ * invisible on a desktop and obvious on a phone. (F052.29)
249
+ */
250
+ declare const STAGE_BG = "#0e1424";
228
251
  declare const defaultUi: Required<BodymapUiColors>;
229
252
  /** Resolve a palette's chrome colours, filling every gap from {@link defaultUi}. */
230
253
  declare function uiColors(palette?: BodymapPalette): Required<BodymapUiColors>;
@@ -295,4 +318,4 @@ declare function serializeReport(report: PainReport, opts?: {
295
318
  * key; a point whose code is unknown to this taxonomy is dropped. */
296
319
  declare function deserializeReport(env: unknown, now?: () => string): PainReport;
297
320
 
298
- export { type BodyRegion, type BodyView, type BodymapPalette, type BodymapReportV1, type BodymapUiColors, type FeedbackFn, type FeedbackOptions, type FeedbackSignal, PAIN_TYPES, type PainPoint, type PainReport, type PainSelection, type PainSelectionOptions, type PainType, type PickOutcome, REGIONS, REGION_KEYS, type RegionConfig, type RegionSetting, type SerializedPainPoint, type SerializedSide, type Side, VIBRATION_PATTERNS, type VibrateOutcome, baseColorFor, bodymapReportV1Schema, createPainSelection, decidePick, defaultPalette, defaultUi, deserializeReport, emitFeedback, getRegion, heatFor, isSelectable, painPointSchema, painReportSchema, requestVibration, resolveRegions, serializeReport, uiColors };
321
+ export { type BodyRegion, type BodyView, type BodymapPalette, type BodymapReportV1, type BodymapUiColors, type FeedbackFn, type FeedbackOptions, type FeedbackSignal, PAIN_TYPES, type PainPoint, type PainReport, type PainSelection, type PainSelectionOptions, type PainType, type PickOutcome, REGIONS, REGION_KEYS, type RegionConfig, type RegionSetting, STAGE_BG, type SerializedPainPoint, type SerializedSide, type Side, VIBRATION_PATTERNS, type VibrateOutcome, baseColorFor, bodymapReportV1Schema, createPainSelection, decidePick, defaultPalette, defaultUi, deserializeReport, emitFeedback, getRegion, heatFor, isSelectable, painPointSchema, painReportSchema, requestVibration, resolveRegions, serializeReport, uiColors };
package/dist/index.js CHANGED
@@ -99,10 +99,12 @@ function emitFeedback(outcome, region, opts = {}) {
99
99
  if (opts.haptics === false) return "skipped";
100
100
  return requestVibration(VIBRATION_PATTERNS[outcome], opts.nav);
101
101
  }
102
+ var STAGE_BG = "#0e1424";
102
103
  var defaultUi = {
103
104
  text: "#1e293b",
104
105
  mutedText: "#475569",
105
106
  panelBg: "#fff",
107
+ stageBg: STAGE_BG,
106
108
  border: "#e2e8f0",
107
109
  badgeBg: "#f1f5f9",
108
110
  danger: "#dc2626"
@@ -170,6 +172,6 @@ function deserializeReport(env, now = () => (/* @__PURE__ */ new Date()).toISOSt
170
172
  return out;
171
173
  }
172
174
 
173
- export { PAIN_TYPES, REGIONS, REGION_KEYS, VIBRATION_PATTERNS, baseColorFor, bodymapReportV1Schema, createPainSelection, decidePick, defaultPalette, defaultUi, deserializeReport, emitFeedback, getRegion, heatFor, isSelectable, painPointSchema, painReportSchema, requestVibration, resolveRegions, serializeReport, uiColors };
175
+ export { PAIN_TYPES, REGIONS, REGION_KEYS, STAGE_BG, VIBRATION_PATTERNS, baseColorFor, bodymapReportV1Schema, createPainSelection, decidePick, defaultPalette, defaultUi, deserializeReport, emitFeedback, getRegion, heatFor, isSelectable, painPointSchema, painReportSchema, requestVibration, resolveRegions, serializeReport, uiColors };
174
176
  //# sourceMappingURL=index.js.map
175
177
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;AA6BO,IAAM,OAAA,GAAiC;AAAA;AAAA,EAE5C,EAAE,GAAA,EAAK,MAAA,EAAQ,KAAA,EAAO,OAAA,EAAS,MAAM,MAAA,EAAO;AAAA,EAC5C,EAAE,GAAA,EAAK,MAAA,EAAQ,KAAA,EAAO,OAAA,EAAS,MAAM,MAAA,EAAO;AAAA,EAC5C,EAAE,GAAA,EAAK,OAAA,EAAS,KAAA,EAAO,OAAA,EAAS,MAAM,OAAA,EAAQ;AAAA,EAC9C,EAAE,GAAA,EAAK,OAAA,EAAS,KAAA,EAAO,wBAAA,EAAuB,MAAM,OAAA,EAAQ;AAAA,EAC5D,EAA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,MAAM,GAAA,GAAM,WAAW,GAAA,CAAI,CAAA,EAAG,GAAG,MAAM,CAAA,CAAA,EAAI,EAAA,CAAG,IAAI,CAAA,CAAE,CAAA;AACpD,IAAA,IAAI,CAAC,GAAA,EAAK;AACV,IAAA,GAAA,CAAI,IAAA;AAAA,MACF,gBAAgB,KAAA,CAAM;AAAA,QACpB,MAAA,EAAQ,GAAA;AAAA,QACR,WAAW,EAAA,CAAG,SAAA;AAAA,QACd,MAAM,EAAA,CAAG,OAAA;AAAA,QACT,WAAW,GAAA;AAAI,OAChB;AAAA,KACH;AAAA,EACF;AACA,EAAA,OAAO,GAAA;AACT","file":"index.js","sourcesContent":["// @broberg/bodymap — headless core (F052.1).\n//\n// Framework-neutral: the region taxonomy + the PainReport data model (zod) + a\n// selection engine + per-app region config. NO React/Preact/DOM import — the 2D\n// (SVG) and 3D (Three.js) renderers, and all three FD apps, share this one\n// contract. Output is a structured PainReport, never a bare image.\n\nimport { z } from \"zod\";\n\nexport type Side = \"left\" | \"right\";\n\nexport interface BodyRegion {\n /** Stable, unique identifier (snake_case) — the key used in a PainReport. */\n key: string;\n /** Human label (Danish). */\n label: string;\n /** Clinical short code (unique). */\n code: string;\n /** Body side, when the region is paired. */\n side?: Side;\n}\n\n/** The canonical body regions — the AUTHORITATIVE fd-sundhed clinical taxonomy\n * (docs/BODYMAP-TAKSONOMI.md, broberg-ai/fd-sundhed @360842f): 18 SIDE-LESS\n * clinical codes + a separate `side` field (L/R on limbs, C=center on axis\n * regions). The `key` is a unique per-side identifier; `code` is the side-less\n * clinical code that goes on the bodymap/v1 wire. NOT an anatomical atlas —\n * ~30 named surface regions for a pain-map. The 2D front renderer draws the\n * front-visible subset; the 3D body (F052.6) drives them all. */\nexport const REGIONS: readonly BodyRegion[] = [\n // axis / centre-line (serialised side \"center\")\n { key: \"head\", label: \"Hoved\", code: \"HEAD\" },\n { key: \"neck\", label: \"Nakke\", code: \"NECK\" },\n { key: \"chest\", label: \"Bryst\", code: \"CHEST\" },\n { key: \"thora\", label: \"Øvre ryg (thorakal)\", code: \"THORA\" },\n { key: \"lumbar\", label: \"Lænd (lumbal)\", code: \"LUMBAR\" },\n { key: \"groin\", label: \"Lyske\", code: \"GROIN\" },\n // paired limbs / sides (L / R)\n { key: \"shoulder_left\", label: \"Skulder, venstre\", code: \"SHOULDER\", side: \"left\" },\n { key: \"shoulder_right\", label: \"Skulder, højre\", code: \"SHOULDER\", side: \"right\" },\n { key: \"uarm_left\", label: \"Overarm, venstre\", code: \"UARM\", side: \"left\" },\n { key: \"uarm_right\", label: \"Overarm, højre\", code: \"UARM\", side: \"right\" },\n { key: \"elbow_left\", label: \"Albue, venstre\", code: \"ELBOW\", side: \"left\" },\n { key: \"elbow_right\", label: \"Albue, højre\", code: \"ELBOW\", side: \"right\" },\n { key: \"farm_left\", label: \"Underarm, venstre\", code: \"FARM\", side: \"left\" },\n { key: \"farm_right\", label: \"Underarm, højre\", code: \"FARM\", side: \"right\" },\n { key: \"wrist_left\", label: \"Håndled, venstre\", code: \"WRIST\", side: \"left\" },\n { key: \"wrist_right\", label: \"Håndled, højre\", code: \"WRIST\", side: \"right\" },\n { key: \"hand_left\", label: \"Hånd, venstre\", code: \"HAND\", side: \"left\" },\n { key: \"hand_right\", label: \"Hånd, højre\", code: \"HAND\", side: \"right\" },\n { key: \"hip_left\", label: \"Hofte, venstre\", code: \"HIP\", side: \"left\" },\n { key: \"hip_right\", label: \"Hofte, højre\", code: \"HIP\", side: \"right\" },\n { key: \"thigh_left\", label: \"Lår, venstre\", code: \"THIGH\", side: \"left\" },\n { key: \"thigh_right\", label: \"Lår, højre\", code: \"THIGH\", side: \"right\" },\n { key: \"knee_left\", label: \"Knæ, venstre\", code: \"KNEE\", side: \"left\" },\n { key: \"knee_right\", label: \"Knæ, højre\", code: \"KNEE\", side: \"right\" },\n { key: \"lowleg_left\", label: \"Underben, venstre\", code: \"LOWLEG\", side: \"left\" },\n { key: \"lowleg_right\", label: \"Underben, højre\", code: \"LOWLEG\", side: \"right\" },\n { key: \"ankle_left\", label: \"Ankel, venstre\", code: \"ANKLE\", side: \"left\" },\n { key: \"ankle_right\", label: \"Ankel, højre\", code: \"ANKLE\", side: \"right\" },\n { key: \"foot_left\", label: \"Fod, venstre\", code: \"FOOT\", side: \"left\" },\n { key: \"foot_right\", label: \"Fod, højre\", code: \"FOOT\", side: \"right\" },\n];\n\nconst REGION_KEY_SET = new Set(REGIONS.map((r) => r.key));\nexport const REGION_KEYS: readonly string[] = REGIONS.map((r) => r.key);\n\n/** Look up a region by its key. */\nexport function getRegion(key: string): BodyRegion | undefined {\n return REGIONS.find((r) => r.key === key);\n}\n\n// ---- PainReport model ---------------------------------------------------\n\nexport const PAIN_TYPES = [\"stikkende\", \"dump\", \"konstant\", \"jagende\"] as const;\nexport type PainType = (typeof PAIN_TYPES)[number];\n\n/** One marked pain point. `region` MUST be a known region key; `intensity` is a\n * 0-10 integer; `type` is optional but constrained; `timestamp` is an ISO string. */\nexport const painPointSchema = z.object({\n region: z.string().refine((k) => REGION_KEY_SET.has(k), { message: \"unknown region\" }),\n intensity: z.number().int().min(0).max(10),\n type: z.enum(PAIN_TYPES).optional(),\n timestamp: z.string(),\n});\nexport type PainPoint = z.infer<typeof painPointSchema>;\n\nexport const painReportSchema = z.array(painPointSchema);\nexport type PainReport = PainPoint[];\n\n// ---- Selection engine (framework-agnostic) ------------------------------\n\nexport interface PainSelection {\n /** Mark (or update) pain on a region. One point per region — latest wins. */\n set(region: string, intensity: number, type?: PainType): PainPoint;\n remove(region: string): boolean;\n get(region: string): PainPoint | undefined;\n has(region: string): boolean;\n clear(): void;\n /** The current, validated PainReport. */\n getReport(): PainReport;\n}\n\nexport interface PainSelectionOptions {\n /** Injectable clock (ISO string) — defaults to `new Date().toISOString()`. */\n now?: () => string;\n}\n\n/** Create a selection engine seeded with an optional report. Pure state — no\n * DOM, no framework, no network. One point per region. */\nexport function createPainSelection(\n initial: PainReport = [],\n opts: PainSelectionOptions = {},\n): PainSelection {\n const now = opts.now ?? (() => new Date().toISOString());\n const map = new Map<string, PainPoint>();\n for (const p of initial) {\n const v = painPointSchema.parse(p);\n map.set(v.region, v);\n }\n return {\n set(region, intensity, type) {\n const point = painPointSchema.parse({ region, intensity, type, timestamp: now() });\n map.set(point.region, point);\n return point;\n },\n remove: (region) => map.delete(region),\n get: (region) => map.get(region),\n has: (region) => map.has(region),\n clear: () => map.clear(),\n getReport: () => painReportSchema.parse(Array.from(map.values())),\n };\n}\n\n// ---- Per-app region config (the toggle) ---------------------------------\n\nexport interface RegionSetting {\n /** Render this region at all. Default true. */\n visible?: boolean;\n /** Allow marking pain on this region. Default true. */\n selectable?: boolean;\n}\n\n/** Per-app config keyed by region key. An absent key ⇒ visible + selectable. */\nexport type RegionConfig = Record<string, RegionSetting>;\n\n/** The regions an app should render, honouring `visible` (default true). */\nexport function resolveRegions(config: RegionConfig = {}): BodyRegion[] {\n return REGIONS.filter((r) => config[r.key]?.visible ?? true);\n}\n\n/**\n * What a pick on a region should DO (F052.20).\n *\n * Lives in the core because the 2D and 3D renderers share no click code, and a\n * rule written twice is a rule that drifts. This repo measured the cost of that\n * twice on 2026-08-28 alone: a fix applied to one half of a pair, and a sibling\n * branch that carried the same defect with no test on it.\n *\n * \"clear\" the region is already marked → picking it again removes the mark\n * \"select\" unmarked → open it for marking\n * \"ignore\" not selectable (read-only or config) → nothing happens\n *\n * Three outcomes, not a boolean: \"nothing happened because it is locked\" and\n * \"nothing happened because we removed the mark\" must never look alike to a\n * caller.\n */\nexport type PickOutcome = \"clear\" | \"select\" | \"ignore\";\n\nexport function decidePick(\n region: string,\n report: PainReport,\n config: RegionConfig = {},\n): PickOutcome {\n if (!isSelectable(region, config)) return \"ignore\";\n return report.some((p) => p.region === region) ? \"clear\" : \"select\";\n}\n\n/** Whether a region may be marked. A hidden region is never selectable. */\nexport function isSelectable(key: string, config: RegionConfig = {}): boolean {\n const s = config[key];\n if (s?.visible === false) return false;\n return s?.selectable ?? true;\n}\n\n// ---- feedback signal: sound + haptics (F052.22) -----------------------------\n\n/**\n * What a pick did, handed to the consuming app so it can make a sound or a buzz.\n *\n * The outcome is the one `decidePick` ACTUALLY returned, never the intent to tap\n * — so a tap on a locked region can not announce itself as a removal, and a tap\n * the pan/pinch guard swallowed emits nothing at all (it never gets here).\n *\n * It deliberately reuses `PickOutcome` rather than introducing a second\n * three-word vocabulary. Two enums meaning the same thing is a drift bug waiting\n * for the first person who adds a fourth outcome to only one of them.\n */\nexport interface FeedbackSignal {\n outcome: PickOutcome;\n /** The region key that was picked. */\n region: string;\n}\n\nexport type FeedbackFn = (signal: FeedbackSignal) => void;\n\n/**\n * What the BROWSER did with a vibration request.\n *\n * ⚠️ `requested` does NOT mean the phone buzzed. `navigator.vibrate()` returns\n * true for a request it accepted, and all of these accept it and then produce\n * nothing: silent / do-not-disturb mode, a device with no vibration motor (most\n * laptops), a page that has not yet had a qualifying user gesture.\n *\n * Same lesson `@broberg/webpush` 0.3.1 recorded — a push that provably ARRIVED\n * on a device that never SHOWED it. \"Accepted\" and \"happened\" are two claims,\n * and only one of them is observable from here.\n */\nexport type VibrateOutcome = \"unsupported\" | \"skipped\" | \"declined\" | \"requested\";\n\n/**\n * The buzz for each outcome.\n *\n * `ignore` is empty ON PURPOSE: a tap that changed nothing must not feel like it\n * changed something. That is the whole reason this is keyed by outcome and not\n * fired from the tap handler.\n */\nexport const VIBRATION_PATTERNS: Record<PickOutcome, readonly number[]> = {\n select: [12],\n clear: [8, 40, 8],\n ignore: [],\n};\n\ninterface Vibrator {\n vibrate?: (pattern: number | number[]) => boolean;\n}\n\n/**\n * Ask the browser to vibrate. Never throws, never claims delivery.\n *\n * `nav` is injectable so a test can supply all four cases; it defaults to the\n * real `navigator` and is `unsupported` when there is not one (SSR, and every\n * browser on iPhone — WebKit has no `vibrate` at all).\n */\nexport function requestVibration(\n pattern: readonly number[],\n nav: Vibrator | undefined = (globalThis as { navigator?: Vibrator }).navigator,\n): VibrateOutcome {\n if (pattern.length === 0) return \"skipped\";\n if (typeof nav?.vibrate !== \"function\") return \"unsupported\";\n try {\n return nav.vibrate([...pattern]) ? \"requested\" : \"declined\";\n } catch {\n // Embedded webviews and cross-origin iframes throw rather than return false.\n // A refused buzz must never take the pain report down with it.\n return \"declined\";\n }\n}\n\nexport interface FeedbackOptions {\n onFeedback?: FeedbackFn;\n /** Web vibration on select/clear. Default true; inert where the API is absent. */\n haptics?: boolean;\n /** Injectable for tests. */\n nav?: unknown;\n}\n\n/**\n * Emit one pick's feedback: always the signal, optionally the buzz.\n *\n * Lives in the core because the 2D and 3D renderers share no click code, and a\n * rule written twice is a rule that drifts — the same reason `decidePick` is\n * here (F052.20).\n *\n * Sound is NOT here and never will be: `@broberg/soundkit` already exists, and\n * pulling Web Audio into a component that is often rendered read-only (a\n * journal, a PDF, a clinician view) is a cost every consumer would pay for a\n * feature most will not switch on. Wire `onFeedback` to it in four lines.\n */\nexport function emitFeedback(\n outcome: PickOutcome,\n region: string,\n opts: FeedbackOptions = {},\n): VibrateOutcome {\n opts.onFeedback?.({ outcome, region });\n if (opts.haptics === false) return \"skipped\";\n // `undefined` falls through to requestVibration's own default (the real\n // navigator) — so an omitted `nav` and a passed-in one take the same path.\n return requestVibration(VIBRATION_PATTERNS[outcome], opts.nav as Vibrator | undefined);\n}\n\n// ---- palette (consumer-defined colours — shared by the 2D + 3D renderers) ---\n\n/** Colour control for the body renderers. Consumers pass a palette to theme the\n * body base colour, the hover + selected highlights, the pain-heat colours, and\n * optional per-region base colours. All values are CSS/hex colour strings. */\nexport interface BodymapPalette {\n /** Base body colour (an unmarked region). */\n body: string;\n /** Region highlight on hover (before click). */\n hover: string;\n /** A region selected (clicked) but not yet given an intensity. */\n selected: string;\n /** Pain-intensity heat colours: low (0-3), mid (4-6), high (7-10). */\n heat: { low: string; mid: string; high: string };\n /** Optional per-region base-colour overrides (region key → colour). */\n regions?: Record<string, string>;\n /**\n * Optional panel-chrome colours (the selection panel, labels, hint box) —\n * NOT the body itself. All optional; anything omitted falls back to\n * {@link defaultUi}. A palette that only themed the body was half a palette:\n * a consumer passing brand colours still got hardcoded chrome. (F052.19)\n */\n ui?: BodymapUiColors;\n}\n\n/** Panel-chrome colours. Every default is WCAG-AA (>=4.5:1) on its own background. */\nexport interface BodymapUiColors {\n /** Primary text (headings, values). */\n text?: string;\n /** Secondary text — section labels, the empty-state hint. */\n mutedText?: string;\n /** Panel background. */\n panelBg?: string;\n /** Panel + control borders. */\n border?: string;\n /** Background behind the region-code badge. */\n badgeBg?: string;\n /** The destructive action (remove a marked region). */\n danger?: string;\n}\n\n/**\n * Default panel chrome. Contrast against `panelBg` (#fff), asserted by\n * `test/contrast.test.ts`:\n * text #1e293b 14.8:1\n * mutedText #475569 7.6:1 (was #94a3b8 at 2.56:1 — WCAG AA failure)\n * danger #dc2626 4.8:1 (was #ef4444 at 3.76:1 — WCAG AA failure)\n * `mutedText` on `badgeBg` (#f1f5f9) is 6.9:1 (was #64748b at 4.34:1).\n */\nexport const defaultUi: Required<BodymapUiColors> = {\n text: \"#1e293b\",\n mutedText: \"#475569\",\n panelBg: \"#fff\",\n border: \"#e2e8f0\",\n badgeBg: \"#f1f5f9\",\n danger: \"#dc2626\",\n};\n\n/** Resolve a palette's chrome colours, filling every gap from {@link defaultUi}. */\nexport function uiColors(palette?: BodymapPalette): Required<BodymapUiColors> {\n return { ...defaultUi, ...(palette?.ui ?? {}) };\n}\n\n/** The fleet default palette. Override any field per consumer. */\nexport const defaultPalette: BodymapPalette = {\n body: \"#d2d7de\",\n hover: \"#8fd0cd\",\n selected: \"#5cc4b7\",\n heat: { low: \"#fcd34d\", mid: \"#fb923c\", high: \"#ef4444\" },\n};\n\n/** The heat colour for a pain intensity, honouring the palette. */\nexport function heatFor(intensity: number, palette: BodymapPalette = defaultPalette): string {\n return intensity >= 7 ? palette.heat.high : intensity >= 4 ? palette.heat.mid : palette.heat.low;\n}\n\n/** The base colour for a region (a per-region override, else the body colour). */\nexport function baseColorFor(regionKey: string, palette: BodymapPalette = defaultPalette): string {\n return palette.regions?.[regionKey] ?? palette.body;\n}\n\n// ---- bodymap/v1 serialization (the shared cross-app / native wire format) ---\n//\n// The shape every consumer + the native mobile apps read (aligned with\n// fd-sundhed's bodymap/v1: region CODE + side + intensity + quality + view).\n// The internal PainReport keys on the region KEY; this maps key -> clinical CODE\n// so the report is portable and human-readable on the wire.\n\nexport type BodyView = \"front\" | \"back\" | \"left\" | \"right\";\n/** Side in the serialized report — a midline region (no side) becomes \"center\". */\nexport type SerializedSide = \"left\" | \"right\" | \"center\";\n\nexport interface SerializedPainPoint {\n /** Clinical region CODE (e.g. \"LUMB\"). */\n region: string;\n side: SerializedSide;\n intensity: number;\n quality?: PainType;\n}\n\nexport interface BodymapReportV1 {\n schema: \"bodymap/v1\";\n view: BodyView;\n points: SerializedPainPoint[];\n}\n\nexport const bodymapReportV1Schema = z.object({\n schema: z.literal(\"bodymap/v1\"),\n view: z.enum([\"front\", \"back\", \"left\", \"right\"]),\n points: z.array(\n z.object({\n region: z.string(),\n side: z.enum([\"left\", \"right\", \"center\"]),\n intensity: z.number().int().min(0).max(10),\n quality: z.enum(PAIN_TYPES).optional(),\n }),\n ),\n});\n\n/** Serialize a PainReport to the shared `bodymap/v1` wire format. */\nexport function serializeReport(\n report: PainReport,\n opts: { view?: BodyView } = {},\n): BodymapReportV1 {\n return {\n schema: \"bodymap/v1\",\n view: opts.view ?? \"front\",\n points: report.map((p) => {\n const r = getRegion(p.region);\n return {\n region: r?.code ?? p.region,\n side: (r?.side ?? \"center\") as SerializedSide,\n intensity: p.intensity,\n quality: p.type,\n };\n }),\n };\n}\n\n/** Parse a `bodymap/v1` report back into an internal PainReport. Region CODE →\n * key; a point whose code is unknown to this taxonomy is dropped. */\nexport function deserializeReport(\n env: unknown,\n now: () => string = () => new Date().toISOString(),\n): PainReport {\n const parsed = bodymapReportV1Schema.parse(env);\n // code is side-less, so a point is identified by code + side.\n const byCodeSide = new Map(\n REGIONS.map((r) => [`${r.code}|${r.side ?? \"center\"}`, r.key] as const),\n );\n const out: PainReport = [];\n for (const sp of parsed.points) {\n const key = byCodeSide.get(`${sp.region}|${sp.side}`);\n if (!key) continue;\n out.push(\n painPointSchema.parse({\n region: key,\n intensity: sp.intensity,\n type: sp.quality,\n timestamp: now(),\n }),\n );\n }\n return out;\n}\n"]}
1
+ {"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;AA6BO,IAAM,OAAA,GAAiC;AAAA;AAAA,EAE5C,EAAE,GAAA,EAAK,MAAA,EAAQ,KAAA,EAAO,OAAA,EAAS,MAAM,MAAA,EAAO;AAAA,EAC5C,EAAE,GAAA,EAAK,MAAA,EAAQ,KAAA,EAAO,OAAA,EAAS,MAAM,MAAA,EAAO;AAAA,EAC5C,EAAE,GAAA,EAAK,OAAA,EAAS,KAAA,EAAO,OAAA,EAAS,MAAM,OAAA,EAAQ;AAAA,EAC9C,EAAE,GAAA,EAAK,OAAA,EAAS,KAAA,EAAO,wBAAA,EAAuB,MAAM,OAAA,EAAQ;AAAA,EAC5D,EAAE,GAAA,EAAK,QAAA,EAAU,KAAA,EAAO,kBAAA,EAAiB,MAAM,QAAA,EAAS;AAAA,EACxD,EAAE,GAAA,EAAK,OAAA,EAAS,KAAA,EAAO,OAAA,EAAS,MAAM,OAAA,EAAQ;AAAA;AAAA,EAE9C,EAAE,KAAK,eAAA,EAAiB,KAAA,EAAO,oBAAoB,IAAA,EAAM,UAAA,EAAY,MAAM,MAAA,EAAO;AAAA,EAClF,EAAE,KAAK,gBAAA,EAAkB,KAAA,EAAO,qBAAkB,IAAA,EAAM,UAAA,EAAY,MAAM,OAAA,EAAQ;AAAA,EAClF,EAAE,KAAK,WAAA,EAAa,KAAA,EAAO,oBAAoB,IAAA,EAAM,MAAA,EAAQ,MAAM,MAAA,EAAO;AAAA,EAC1E,EAAE,KAAK,YAAA,EAAc,KAAA,EAAO,qBAAkB,IAAA,EAAM,MAAA,EAAQ,MAAM,OAAA,EAAQ;AAAA,EAC1E,EAAE,KAAK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,MAAA,EAAQ,CAAA,EAAG,IAAA,IAAQ,CAAA,CAAE,MAAA;AAAA,QACrB,IAAA,EAAO,GAAG,IAAA,IAAQ,QAAA;AAAA,QAClB,WAAW,CAAA,CAAE,SAAA;AAAA,QACb,SAAS,CAAA,CAAE;AAAA,OACb;AAAA,IACF,CAAC;AAAA,GACH;AACF;AAIO,SAAS,iBAAA,CACd,KACA,GAAA,GAAoB,MAAA,qBAAU,IAAA,EAAK,EAAE,aAAY,EACrC;AACZ,EAAA,MAAM,MAAA,GAAS,qBAAA,CAAsB,KAAA,CAAM,GAAG,CAAA;AAE9C,EAAA,MAAM,aAAa,IAAI,GAAA;AAAA,IACrB,OAAA,CAAQ,GAAA,CAAI,CAAC,CAAA,KAAM,CAAC,CAAA,EAAG,CAAA,CAAE,IAAI,CAAA,CAAA,EAAI,EAAE,IAAA,IAAQ,QAAQ,CAAA,CAAA,EAAI,CAAA,CAAE,GAAG,CAAU;AAAA,GACxE;AACA,EAAA,MAAM,MAAkB,EAAC;AACzB,EAAA,KAAA,MAAW,EAAA,IAAM,OAAO,MAAA,EAAQ;AAC9B,IAAA,MAAM,GAAA,GAAM,WAAW,GAAA,CAAI,CAAA,EAAG,GAAG,MAAM,CAAA,CAAA,EAAI,EAAA,CAAG,IAAI,CAAA,CAAE,CAAA;AACpD,IAAA,IAAI,CAAC,GAAA,EAAK;AACV,IAAA,GAAA,CAAI,IAAA;AAAA,MACF,gBAAgB,KAAA,CAAM;AAAA,QACpB,MAAA,EAAQ,GAAA;AAAA,QACR,WAAW,EAAA,CAAG,SAAA;AAAA,QACd,MAAM,EAAA,CAAG,OAAA;AAAA,QACT,WAAW,GAAA;AAAI,OAChB;AAAA,KACH;AAAA,EACF;AACA,EAAA,OAAO,GAAA;AACT","file":"index.js","sourcesContent":["// @broberg/bodymap — headless core (F052.1).\n//\n// Framework-neutral: the region taxonomy + the PainReport data model (zod) + a\n// selection engine + per-app region config. NO React/Preact/DOM import — the 2D\n// (SVG) and 3D (Three.js) renderers, and all three FD apps, share this one\n// contract. Output is a structured PainReport, never a bare image.\n\nimport { z } from \"zod\";\n\nexport type Side = \"left\" | \"right\";\n\nexport interface BodyRegion {\n /** Stable, unique identifier (snake_case) — the key used in a PainReport. */\n key: string;\n /** Human label (Danish). */\n label: string;\n /** Clinical short code (unique). */\n code: string;\n /** Body side, when the region is paired. */\n side?: Side;\n}\n\n/** The canonical body regions — the AUTHORITATIVE fd-sundhed clinical taxonomy\n * (docs/BODYMAP-TAKSONOMI.md, broberg-ai/fd-sundhed @360842f): 18 SIDE-LESS\n * clinical codes + a separate `side` field (L/R on limbs, C=center on axis\n * regions). The `key` is a unique per-side identifier; `code` is the side-less\n * clinical code that goes on the bodymap/v1 wire. NOT an anatomical atlas —\n * ~30 named surface regions for a pain-map. The 2D front renderer draws the\n * front-visible subset; the 3D body (F052.6) drives them all. */\nexport const REGIONS: readonly BodyRegion[] = [\n // axis / centre-line (serialised side \"center\")\n { key: \"head\", label: \"Hoved\", code: \"HEAD\" },\n { key: \"neck\", label: \"Nakke\", code: \"NECK\" },\n { key: \"chest\", label: \"Bryst\", code: \"CHEST\" },\n { key: \"thora\", label: \"Øvre ryg (thorakal)\", code: \"THORA\" },\n { key: \"lumbar\", label: \"Lænd (lumbal)\", code: \"LUMBAR\" },\n { key: \"groin\", label: \"Lyske\", code: \"GROIN\" },\n // paired limbs / sides (L / R)\n { key: \"shoulder_left\", label: \"Skulder, venstre\", code: \"SHOULDER\", side: \"left\" },\n { key: \"shoulder_right\", label: \"Skulder, højre\", code: \"SHOULDER\", side: \"right\" },\n { key: \"uarm_left\", label: \"Overarm, venstre\", code: \"UARM\", side: \"left\" },\n { key: \"uarm_right\", label: \"Overarm, højre\", code: \"UARM\", side: \"right\" },\n { key: \"elbow_left\", label: \"Albue, venstre\", code: \"ELBOW\", side: \"left\" },\n { key: \"elbow_right\", label: \"Albue, højre\", code: \"ELBOW\", side: \"right\" },\n { key: \"farm_left\", label: \"Underarm, venstre\", code: \"FARM\", side: \"left\" },\n { key: \"farm_right\", label: \"Underarm, højre\", code: \"FARM\", side: \"right\" },\n { key: \"wrist_left\", label: \"Håndled, venstre\", code: \"WRIST\", side: \"left\" },\n { key: \"wrist_right\", label: \"Håndled, højre\", code: \"WRIST\", side: \"right\" },\n { key: \"hand_left\", label: \"Hånd, venstre\", code: \"HAND\", side: \"left\" },\n { key: \"hand_right\", label: \"Hånd, højre\", code: \"HAND\", side: \"right\" },\n { key: \"hip_left\", label: \"Hofte, venstre\", code: \"HIP\", side: \"left\" },\n { key: \"hip_right\", label: \"Hofte, højre\", code: \"HIP\", side: \"right\" },\n { key: \"thigh_left\", label: \"Lår, venstre\", code: \"THIGH\", side: \"left\" },\n { key: \"thigh_right\", label: \"Lår, højre\", code: \"THIGH\", side: \"right\" },\n { key: \"knee_left\", label: \"Knæ, venstre\", code: \"KNEE\", side: \"left\" },\n { key: \"knee_right\", label: \"Knæ, højre\", code: \"KNEE\", side: \"right\" },\n { key: \"lowleg_left\", label: \"Underben, venstre\", code: \"LOWLEG\", side: \"left\" },\n { key: \"lowleg_right\", label: \"Underben, højre\", code: \"LOWLEG\", side: \"right\" },\n { key: \"ankle_left\", label: \"Ankel, venstre\", code: \"ANKLE\", side: \"left\" },\n { key: \"ankle_right\", label: \"Ankel, højre\", code: \"ANKLE\", side: \"right\" },\n { key: \"foot_left\", label: \"Fod, venstre\", code: \"FOOT\", side: \"left\" },\n { key: \"foot_right\", label: \"Fod, højre\", code: \"FOOT\", side: \"right\" },\n];\n\nconst REGION_KEY_SET = new Set(REGIONS.map((r) => r.key));\nexport const REGION_KEYS: readonly string[] = REGIONS.map((r) => r.key);\n\n/** Look up a region by its key. */\nexport function getRegion(key: string): BodyRegion | undefined {\n return REGIONS.find((r) => r.key === key);\n}\n\n// ---- PainReport model ---------------------------------------------------\n\nexport const PAIN_TYPES = [\"stikkende\", \"dump\", \"konstant\", \"jagende\"] as const;\nexport type PainType = (typeof PAIN_TYPES)[number];\n\n/** One marked pain point. `region` MUST be a known region key; `intensity` is a\n * 0-10 integer; `type` is optional but constrained; `timestamp` is an ISO string. */\nexport const painPointSchema = z.object({\n region: z.string().refine((k) => REGION_KEY_SET.has(k), { message: \"unknown region\" }),\n intensity: z.number().int().min(0).max(10),\n type: z.enum(PAIN_TYPES).optional(),\n timestamp: z.string(),\n});\nexport type PainPoint = z.infer<typeof painPointSchema>;\n\nexport const painReportSchema = z.array(painPointSchema);\nexport type PainReport = PainPoint[];\n\n// ---- Selection engine (framework-agnostic) ------------------------------\n\nexport interface PainSelection {\n /** Mark (or update) pain on a region. One point per region — latest wins. */\n set(region: string, intensity: number, type?: PainType): PainPoint;\n remove(region: string): boolean;\n get(region: string): PainPoint | undefined;\n has(region: string): boolean;\n clear(): void;\n /** The current, validated PainReport. */\n getReport(): PainReport;\n}\n\nexport interface PainSelectionOptions {\n /** Injectable clock (ISO string) — defaults to `new Date().toISOString()`. */\n now?: () => string;\n}\n\n/** Create a selection engine seeded with an optional report. Pure state — no\n * DOM, no framework, no network. One point per region. */\nexport function createPainSelection(\n initial: PainReport = [],\n opts: PainSelectionOptions = {},\n): PainSelection {\n const now = opts.now ?? (() => new Date().toISOString());\n const map = new Map<string, PainPoint>();\n for (const p of initial) {\n const v = painPointSchema.parse(p);\n map.set(v.region, v);\n }\n return {\n set(region, intensity, type) {\n const point = painPointSchema.parse({ region, intensity, type, timestamp: now() });\n map.set(point.region, point);\n return point;\n },\n remove: (region) => map.delete(region),\n get: (region) => map.get(region),\n has: (region) => map.has(region),\n clear: () => map.clear(),\n getReport: () => painReportSchema.parse(Array.from(map.values())),\n };\n}\n\n// ---- Per-app region config (the toggle) ---------------------------------\n\nexport interface RegionSetting {\n /** Render this region at all. Default true. */\n visible?: boolean;\n /** Allow marking pain on this region. Default true. */\n selectable?: boolean;\n}\n\n/** Per-app config keyed by region key. An absent key ⇒ visible + selectable. */\nexport type RegionConfig = Record<string, RegionSetting>;\n\n/** The regions an app should render, honouring `visible` (default true). */\nexport function resolveRegions(config: RegionConfig = {}): BodyRegion[] {\n return REGIONS.filter((r) => config[r.key]?.visible ?? true);\n}\n\n/**\n * What a pick on a region should DO (F052.20).\n *\n * Lives in the core because the 2D and 3D renderers share no click code, and a\n * rule written twice is a rule that drifts. This repo measured the cost of that\n * twice on 2026-08-28 alone: a fix applied to one half of a pair, and a sibling\n * branch that carried the same defect with no test on it.\n *\n * \"clear\" the region is already marked → picking it again removes the mark\n * \"select\" unmarked → open it for marking\n * \"ignore\" not selectable (read-only or config) → nothing happens\n *\n * Three outcomes, not a boolean: \"nothing happened because it is locked\" and\n * \"nothing happened because we removed the mark\" must never look alike to a\n * caller.\n */\nexport type PickOutcome = \"clear\" | \"select\" | \"ignore\";\n\nexport function decidePick(\n region: string,\n report: PainReport,\n config: RegionConfig = {},\n): PickOutcome {\n if (!isSelectable(region, config)) return \"ignore\";\n return report.some((p) => p.region === region) ? \"clear\" : \"select\";\n}\n\n/** Whether a region may be marked. A hidden region is never selectable. */\nexport function isSelectable(key: string, config: RegionConfig = {}): boolean {\n const s = config[key];\n if (s?.visible === false) return false;\n return s?.selectable ?? true;\n}\n\n// ---- feedback signal: sound + haptics (F052.22) -----------------------------\n\n/**\n * What a pick did, handed to the consuming app so it can make a sound or a buzz.\n *\n * The outcome is the one `decidePick` ACTUALLY returned, never the intent to tap\n * — so a tap on a locked region can not announce itself as a removal, and a tap\n * the pan/pinch guard swallowed emits nothing at all (it never gets here).\n *\n * It deliberately reuses `PickOutcome` rather than introducing a second\n * three-word vocabulary. Two enums meaning the same thing is a drift bug waiting\n * for the first person who adds a fourth outcome to only one of them.\n */\nexport interface FeedbackSignal {\n outcome: PickOutcome;\n /** The region key that was picked. */\n region: string;\n}\n\nexport type FeedbackFn = (signal: FeedbackSignal) => void;\n\n/**\n * What the BROWSER did with a vibration request.\n *\n * ⚠️ `requested` does NOT mean the phone buzzed. `navigator.vibrate()` returns\n * true for a request it accepted, and all of these accept it and then produce\n * nothing: silent / do-not-disturb mode, a device with no vibration motor (most\n * laptops), a page that has not yet had a qualifying user gesture.\n *\n * Same lesson `@broberg/webpush` 0.3.1 recorded — a push that provably ARRIVED\n * on a device that never SHOWED it. \"Accepted\" and \"happened\" are two claims,\n * and only one of them is observable from here.\n */\nexport type VibrateOutcome = \"unsupported\" | \"skipped\" | \"declined\" | \"requested\";\n\n/**\n * The buzz for each outcome.\n *\n * `ignore` is empty ON PURPOSE: a tap that changed nothing must not feel like it\n * changed something. That is the whole reason this is keyed by outcome and not\n * fired from the tap handler.\n */\nexport const VIBRATION_PATTERNS: Record<PickOutcome, readonly number[]> = {\n select: [12],\n clear: [8, 40, 8],\n ignore: [],\n};\n\ninterface Vibrator {\n vibrate?: (pattern: number | number[]) => boolean;\n}\n\n/**\n * Ask the browser to vibrate. Never throws, never claims delivery.\n *\n * `nav` is injectable so a test can supply all four cases; it defaults to the\n * real `navigator` and is `unsupported` when there is not one (SSR, and every\n * browser on iPhone — WebKit has no `vibrate` at all).\n */\nexport function requestVibration(\n pattern: readonly number[],\n nav: Vibrator | undefined = (globalThis as { navigator?: Vibrator }).navigator,\n): VibrateOutcome {\n if (pattern.length === 0) return \"skipped\";\n if (typeof nav?.vibrate !== \"function\") return \"unsupported\";\n try {\n return nav.vibrate([...pattern]) ? \"requested\" : \"declined\";\n } catch {\n // Embedded webviews and cross-origin iframes throw rather than return false.\n // A refused buzz must never take the pain report down with it.\n return \"declined\";\n }\n}\n\nexport interface FeedbackOptions {\n onFeedback?: FeedbackFn;\n /** Web vibration on select/clear. Default true; inert where the API is absent. */\n haptics?: boolean;\n /** Injectable for tests. */\n nav?: unknown;\n}\n\n/**\n * Emit one pick's feedback: always the signal, optionally the buzz.\n *\n * Lives in the core because the 2D and 3D renderers share no click code, and a\n * rule written twice is a rule that drifts — the same reason `decidePick` is\n * here (F052.20).\n *\n * Sound is NOT here and never will be: `@broberg/soundkit` already exists, and\n * pulling Web Audio into a component that is often rendered read-only (a\n * journal, a PDF, a clinician view) is a cost every consumer would pay for a\n * feature most will not switch on. Wire `onFeedback` to it in four lines.\n */\nexport function emitFeedback(\n outcome: PickOutcome,\n region: string,\n opts: FeedbackOptions = {},\n): VibrateOutcome {\n opts.onFeedback?.({ outcome, region });\n if (opts.haptics === false) return \"skipped\";\n // `undefined` falls through to requestVibration's own default (the real\n // navigator) — so an omitted `nav` and a passed-in one take the same path.\n return requestVibration(VIBRATION_PATTERNS[outcome], opts.nav as Vibrator | undefined);\n}\n\n// ---- palette (consumer-defined colours — shared by the 2D + 3D renderers) ---\n\n/** Colour control for the body renderers. Consumers pass a palette to theme the\n * body base colour, the hover + selected highlights, the pain-heat colours, and\n * optional per-region base colours. All values are CSS/hex colour strings. */\nexport interface BodymapPalette {\n /** Base body colour (an unmarked region). */\n body: string;\n /** Region highlight on hover (before click). */\n hover: string;\n /** A region selected (clicked) but not yet given an intensity. */\n selected: string;\n /** Pain-intensity heat colours: low (0-3), mid (4-6), high (7-10). */\n heat: { low: string; mid: string; high: string };\n /** Optional per-region base-colour overrides (region key → colour). */\n regions?: Record<string, string>;\n /**\n * Optional panel-chrome colours (the selection panel, labels, hint box) —\n * NOT the body itself. All optional; anything omitted falls back to\n * {@link defaultUi}. A palette that only themed the body was half a palette:\n * a consumer passing brand colours still got hardcoded chrome. (F052.19)\n */\n ui?: BodymapUiColors;\n}\n\n/** Panel-chrome colours. Every default is WCAG-AA (>=4.5:1) on its own background. */\nexport interface BodymapUiColors {\n /** Primary text (headings, values). */\n text?: string;\n /** Secondary text — section labels, the empty-state hint. */\n mutedText?: string;\n /** Panel background — the card, its buttons, the empty hint. */\n panelBg?: string;\n /**\n * THE STAGE: the fullscreen backdrop, the canvas frame, and the three.js\n * scene behind the body. A different surface from `panelBg` with an opposite\n * need — see F052.29, where one field paints both and no value is right for\n * either.\n *\n * 3D only. The 2D renderer has no canvas and no fullscreen, so it ignores\n * this; it is declared here because a stage is a shared idea, not because\n * every renderer has one.\n *\n * Defaults to {@link STAGE_BG}. Pass `'#fff'` for the pre-0.8.0 white\n * fullscreen backdrop.\n */\n stageBg?: string;\n /** Panel + control borders. */\n border?: string;\n /** Background behind the region-code badge. */\n badgeBg?: string;\n /** The destructive action (remove a marked region). */\n danger?: string;\n}\n\n/**\n * Default panel chrome. Contrast against `panelBg` (#fff), asserted by\n * `test/contrast.test.ts`:\n * text #1e293b 14.8:1\n * mutedText #475569 7.6:1 (was #94a3b8 at 2.56:1 — WCAG AA failure)\n * danger #dc2626 4.8:1 (was #ef4444 at 3.76:1 — WCAG AA failure)\n * `mutedText` on `badgeBg` (#f1f5f9) is 6.9:1 (was #64748b at 4.34:1).\n */\n/**\n * The stage colour — the ONE place this value lives.\n *\n * It used to be a literal in three places in `three.tsx` (the three.js scene,\n * the canvas frame, the unsupported placeholder), which meant a consumer could\n * recolour the backdrop and still get OUR navy inside it. That seam is\n * invisible on a desktop and obvious on a phone. (F052.29)\n */\nexport const STAGE_BG = \"#0e1424\";\n\nexport const defaultUi: Required<BodymapUiColors> = {\n text: \"#1e293b\",\n mutedText: \"#475569\",\n panelBg: \"#fff\",\n stageBg: STAGE_BG,\n border: \"#e2e8f0\",\n badgeBg: \"#f1f5f9\",\n danger: \"#dc2626\",\n};\n\n/** Resolve a palette's chrome colours, filling every gap from {@link defaultUi}. */\nexport function uiColors(palette?: BodymapPalette): Required<BodymapUiColors> {\n return { ...defaultUi, ...(palette?.ui ?? {}) };\n}\n\n/** The fleet default palette. Override any field per consumer. */\nexport const defaultPalette: BodymapPalette = {\n body: \"#d2d7de\",\n hover: \"#8fd0cd\",\n selected: \"#5cc4b7\",\n heat: { low: \"#fcd34d\", mid: \"#fb923c\", high: \"#ef4444\" },\n};\n\n/** The heat colour for a pain intensity, honouring the palette. */\nexport function heatFor(intensity: number, palette: BodymapPalette = defaultPalette): string {\n return intensity >= 7 ? palette.heat.high : intensity >= 4 ? palette.heat.mid : palette.heat.low;\n}\n\n/** The base colour for a region (a per-region override, else the body colour). */\nexport function baseColorFor(regionKey: string, palette: BodymapPalette = defaultPalette): string {\n return palette.regions?.[regionKey] ?? palette.body;\n}\n\n// ---- bodymap/v1 serialization (the shared cross-app / native wire format) ---\n//\n// The shape every consumer + the native mobile apps read (aligned with\n// fd-sundhed's bodymap/v1: region CODE + side + intensity + quality + view).\n// The internal PainReport keys on the region KEY; this maps key -> clinical CODE\n// so the report is portable and human-readable on the wire.\n\nexport type BodyView = \"front\" | \"back\" | \"left\" | \"right\";\n/** Side in the serialized report — a midline region (no side) becomes \"center\". */\nexport type SerializedSide = \"left\" | \"right\" | \"center\";\n\nexport interface SerializedPainPoint {\n /** Clinical region CODE (e.g. \"LUMB\"). */\n region: string;\n side: SerializedSide;\n intensity: number;\n quality?: PainType;\n}\n\nexport interface BodymapReportV1 {\n schema: \"bodymap/v1\";\n view: BodyView;\n points: SerializedPainPoint[];\n}\n\nexport const bodymapReportV1Schema = z.object({\n schema: z.literal(\"bodymap/v1\"),\n view: z.enum([\"front\", \"back\", \"left\", \"right\"]),\n points: z.array(\n z.object({\n region: z.string(),\n side: z.enum([\"left\", \"right\", \"center\"]),\n intensity: z.number().int().min(0).max(10),\n quality: z.enum(PAIN_TYPES).optional(),\n }),\n ),\n});\n\n/** Serialize a PainReport to the shared `bodymap/v1` wire format. */\nexport function serializeReport(\n report: PainReport,\n opts: { view?: BodyView } = {},\n): BodymapReportV1 {\n return {\n schema: \"bodymap/v1\",\n view: opts.view ?? \"front\",\n points: report.map((p) => {\n const r = getRegion(p.region);\n return {\n region: r?.code ?? p.region,\n side: (r?.side ?? \"center\") as SerializedSide,\n intensity: p.intensity,\n quality: p.type,\n };\n }),\n };\n}\n\n/** Parse a `bodymap/v1` report back into an internal PainReport. Region CODE →\n * key; a point whose code is unknown to this taxonomy is dropped. */\nexport function deserializeReport(\n env: unknown,\n now: () => string = () => new Date().toISOString(),\n): PainReport {\n const parsed = bodymapReportV1Schema.parse(env);\n // code is side-less, so a point is identified by code + side.\n const byCodeSide = new Map(\n REGIONS.map((r) => [`${r.code}|${r.side ?? \"center\"}`, r.key] as const),\n );\n const out: PainReport = [];\n for (const sp of parsed.points) {\n const key = byCodeSide.get(`${sp.region}|${sp.side}`);\n if (!key) continue;\n out.push(\n painPointSchema.parse({\n region: key,\n intensity: sp.intensity,\n type: sp.quality,\n timestamp: now(),\n }),\n );\n }\n return out;\n}\n"]}