@broberg/bodymap 0.3.0 → 0.4.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/dist/three.cjs CHANGED
@@ -84,6 +84,25 @@ function isSelectable(key, config = {}) {
84
84
  if (s?.visible === false) return false;
85
85
  return s?.selectable ?? true;
86
86
  }
87
+ var VIBRATION_PATTERNS = {
88
+ select: [12],
89
+ clear: [8, 40, 8],
90
+ ignore: []
91
+ };
92
+ function requestVibration(pattern, nav = globalThis.navigator) {
93
+ if (pattern.length === 0) return "skipped";
94
+ if (typeof nav?.vibrate !== "function") return "unsupported";
95
+ try {
96
+ return nav.vibrate([...pattern]) ? "requested" : "declined";
97
+ } catch {
98
+ return "declined";
99
+ }
100
+ }
101
+ function emitFeedback(outcome, region, opts = {}) {
102
+ opts.onFeedback?.({ outcome, region });
103
+ if (opts.haptics === false) return "skipped";
104
+ return requestVibration(VIBRATION_PATTERNS[outcome], opts.nav);
105
+ }
87
106
  var defaultUi = {
88
107
  text: "#1e293b",
89
108
  mutedText: "#475569",
@@ -287,6 +306,8 @@ function BodyMap3D(props) {
287
306
  autoRotate = true,
288
307
  canvasHeight = "60vh",
289
308
  showRegionCode = true,
309
+ onFeedback,
310
+ haptics,
290
311
  className
291
312
  } = props;
292
313
  const chrome = uiColors(palette);
@@ -607,6 +628,7 @@ function BodyMap3D(props) {
607
628
  };
608
629
  pickRef.current = (k) => {
609
630
  const what = decidePick(k, reportRef.current, configRef.current ?? {});
631
+ emitFeedback(what, k, { onFeedback, haptics });
610
632
  if (what === "clear") removePain(k);
611
633
  else if (what === "select") setSelected(k);
612
634
  return what;