@viji-dev/core 0.7.0 → 0.7.4

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.
@@ -559,15 +559,25 @@ declare global {
559
559
  }
560
560
 
561
561
  /**
562
- * One detected face produced by the video CV pipeline. Always carries `id`,
563
- * `bounds`, `center`, and `confidence`; the rest is populated only when the
564
- * matching CV feature is enabled (face mesh for `landmarks` and `headPose`,
565
- * emotion detection for `expressions` and `blendshapes`).
562
+ * One detected face produced by the video CV pipeline. Each field is
563
+ * populated only by its source model; fields whose source model is not
564
+ * enabled read as `null` so the absence is loud rather than silent. Enable
565
+ * the relevant `enable*` verb on `viji.video.cv` to populate each group:
566
+ *
567
+ * - `bounds`, `center`, `confidence`: populated by `enableFaceDetection(true)`.
568
+ * - `landmarks`: populated by `enableFaceMesh(true)` (empty array otherwise).
569
+ * - `headPose`: populated by `enableFaceMesh(true)`.
570
+ * - `blendshapes`, `expressions`: populated by `enableEmotionDetection(true)`.
571
+ *
572
+ * If a field is `null`, call the corresponding `enable*` verb on
573
+ * `viji.video.cv` to populate it. Each active CV feature consumes its own
574
+ * WebGL context for MediaPipe; enabling many at once on lower-end hardware
575
+ * can hit context limits.
566
576
  */
567
577
  interface FaceData {
568
578
  /** Index-based face identifier (`0`, `1`, …). Stable within a single frame, may change between frames. */
569
579
  id: number;
570
- /** Bounding box, all components normalized to 0..1 of the source frame. */
580
+ /** Bounding box, all components normalized to 0..1 of the source frame. `null` unless face detection is enabled. */
571
581
  bounds: {
572
582
  /** Left edge of the face bounding box, normalized 0..1. */
573
583
  x: number;
@@ -577,16 +587,16 @@ declare global {
577
587
  width: number;
578
588
  /** Height of the face bounding box, normalized 0..1. */
579
589
  height: number;
580
- };
581
- /** Center of the bounding box, normalized 0..1. */
590
+ } | null;
591
+ /** Center of the bounding box, normalized 0..1. `null` unless face detection is enabled. */
582
592
  center: {
583
593
  /** Horizontal center of the face, normalized 0..1. */
584
594
  x: number;
585
595
  /** Vertical center of the face, normalized 0..1. */
586
596
  y: number;
587
- };
588
- /** Detection confidence in 0..1. */
589
- confidence: number;
597
+ } | null;
598
+ /** Detection confidence in 0..1. `null` unless face detection is enabled. */
599
+ confidence: number | null;
590
600
  /** 468 normalized face mesh landmarks when face mesh is enabled; empty array otherwise. */
591
601
  landmarks: {
592
602
  /** Horizontal landmark coordinate, normalized 0..1. */
@@ -596,7 +606,16 @@ declare global {
596
606
  /** Optional depth (relative). */
597
607
  z?: number;
598
608
  }[];
599
- /** Seven expression confidence scores in 0..1. All zero unless emotion detection is enabled. */
609
+ /** Estimated head rotation in degrees. `null` unless face mesh is enabled. */
610
+ headPose: {
611
+ /** Up/down rotation in degrees (-90..90). Positive = head looking up, negative = looking down. */
612
+ pitch: number;
613
+ /** Left/right rotation in degrees (-90..90). Positive = head turned to the subject's right, negative = to the left. */
614
+ yaw: number;
615
+ /** Tilt rotation in degrees (-180..180). Positive = head tilted to the subject's right (right ear toward right shoulder). */
616
+ roll: number;
617
+ } | null;
618
+ /** Seven expression confidence scores in 0..1. `null` unless emotion detection is enabled. */
600
619
  expressions: {
601
620
  /** Confidence (0..1) of a neutral expression. */
602
621
  neutral: number;
@@ -612,18 +631,9 @@ declare global {
612
631
  disgusted: number;
613
632
  /** Confidence (0..1) of a fearful expression. */
614
633
  fearful: number;
615
- };
616
- /** Estimated head rotation. All zero unless face mesh is enabled. */
617
- headPose: {
618
- /** Up/down rotation in degrees (-90..90). Positive = head looking up, negative = looking down. */
619
- pitch: number;
620
- /** Left/right rotation in degrees (-90..90). Positive = head turned to the subject's right, negative = to the left. */
621
- yaw: number;
622
- /** Tilt rotation in degrees (-180..180). Positive = head tilted to the subject's right (right ear toward right shoulder). */
623
- roll: number;
624
- };
625
- /** 52 ARKit-compatible facial muscle coefficients. All zero unless emotion detection is enabled. */
626
- blendshapes: FaceBlendshapes;
634
+ } | null;
635
+ /** 52 ARKit-compatible facial muscle coefficients. `null` unless emotion detection is enabled. */
636
+ blendshapes: FaceBlendshapes | null;
627
637
  }
628
638
 
629
639
  /**
@@ -1211,7 +1221,7 @@ declare global {
1211
1221
  isEnding: boolean;
1212
1222
  }
1213
1223
 
1214
- const VERSION = "0.7.0";
1224
+ const VERSION = "0.7.4";
1215
1225
 
1216
1226
  /**
1217
1227
  * Real-time video API: drawable frame, dimensions, and the source-side
@@ -1320,35 +1330,73 @@ declare global {
1320
1330
  /** Body segmentation mask, or `null` when segmentation is off. */
1321
1331
  segmentation: SegmentationData | null;
1322
1332
  /**
1323
- * Toggle face detection (bounding box, center, confidence, id).
1333
+ * Toggle face detection. Populates `face.bounds`, `face.center`,
1334
+ * `face.confidence` on each detected face. Independent of face mesh and
1335
+ * emotion detection.
1336
+ *
1337
+ * Safe to call from module scope as well as from inside `render()`. The
1338
+ * verb is idempotent and reference-counted; per-frame calls inside
1339
+ * `render()` (the canonical toggle-gated pattern) are cheap.
1340
+ *
1324
1341
  * @returns Resolves once the underlying pipeline has finished switching.
1325
1342
  */
1326
1343
  enableFaceDetection(enabled: boolean): Promise<void>;
1327
1344
  /**
1328
- * Toggle 468-point face mesh + head pose (`pitch`, `yaw`, `roll`). Implies
1329
- * face detection.
1345
+ * Toggle 468-point face mesh and computed head pose (`pitch`, `yaw`,
1346
+ * `roll`). Populates `face.landmarks` and `face.headPose` on the face
1347
+ * entry. Does NOT populate `face.bounds` / `face.center` / `face.confidence`
1348
+ * — those are produced only by face detection. Enable both if you need
1349
+ * both, or compute bounds from `face.landmarks` min/max yourself.
1350
+ *
1351
+ * Safe to call from module scope as well as from inside `render()`. The
1352
+ * verb is idempotent and reference-counted.
1353
+ *
1330
1354
  * @returns Resolves once the pipeline has finished switching.
1331
1355
  */
1332
1356
  enableFaceMesh(enabled: boolean): Promise<void>;
1333
1357
  /**
1334
1358
  * Toggle 7 expressions + 52 ARKit blendshape coefficients on each face.
1335
- * Implies face mesh.
1359
+ * Populates `face.blendshapes` and `face.expressions`. Internally requires
1360
+ * the face landmarker model (loads it alongside `enableFaceMesh` if both
1361
+ * are enabled; loads it on its own otherwise so `face.landmarks` and
1362
+ * `face.headPose` are also populated). Does NOT populate
1363
+ * `face.bounds` / `face.center` / `face.confidence` — enable face
1364
+ * detection for those.
1365
+ *
1366
+ * Safe to call from module scope as well as from inside `render()`. The
1367
+ * verb is idempotent and reference-counted.
1368
+ *
1336
1369
  * @returns Resolves once the pipeline has finished switching.
1337
1370
  */
1338
1371
  enableEmotionDetection(enabled: boolean): Promise<void>;
1339
1372
  /**
1340
- * Toggle 21-point hand landmarks + ML-classified gesture confidences for up
1341
- * to two hands.
1373
+ * Toggle 21-point hand landmarks and ML-classified gesture confidences
1374
+ * for up to two hands. Populates `viji.video.cv.hands[]` with `landmarks`,
1375
+ * `palm`, `bounds` (computed from landmarks), and `gestures`.
1376
+ *
1377
+ * Safe to call from module scope as well as from inside `render()`. The
1378
+ * verb is idempotent and reference-counted.
1379
+ *
1342
1380
  * @returns Resolves once the pipeline has finished switching.
1343
1381
  */
1344
1382
  enableHandTracking(enabled: boolean): Promise<void>;
1345
1383
  /**
1346
1384
  * Toggle 33-point BlazePose body landmarks (face / torso / arms / legs).
1385
+ * Populates `viji.video.cv.pose`.
1386
+ *
1387
+ * Safe to call from module scope as well as from inside `render()`. The
1388
+ * verb is idempotent and reference-counted.
1389
+ *
1347
1390
  * @returns Resolves once the pipeline has finished switching.
1348
1391
  */
1349
1392
  enablePoseDetection(enabled: boolean): Promise<void>;
1350
1393
  /**
1351
- * Toggle per-pixel person/background segmentation mask.
1394
+ * Toggle per-pixel person/background segmentation mask. Populates
1395
+ * `viji.video.cv.segmentation`.
1396
+ *
1397
+ * Safe to call from module scope as well as from inside `render()`. The
1398
+ * verb is idempotent and reference-counted.
1399
+ *
1352
1400
  * @returns Resolves once the pipeline has finished switching.
1353
1401
  */
1354
1402
  enableBodySegmentation(enabled: boolean): Promise<void>;
@@ -362,23 +362,27 @@
362
362
  */
363
363
 
364
364
  /**
365
- * One detected face produced by the video CV pipeline. Always carries `id`, `bounds`, `center`, and `confidence`; the rest is populated only when the matching CV feature is enabled (face mesh for `landmarks` and `headPose`, emotion detection for `expressions` and `blendshapes`).
365
+ * One detected face produced by the video CV pipeline. Each field is populated only by its source model; fields whose source model is not enabled read as `null` so the absence is loud rather than silent. Enable the relevant `enable*` verb on `viji.video.cv` to populate each group: - `bounds`, `center`, `confidence`: populated by `enableFaceDetection(true)`. - `landmarks`: populated by `enableFaceMesh(true)` (empty array otherwise). - `headPose`: populated by `enableFaceMesh(true)`. - `blendshapes`, `expressions`: populated by `enableEmotionDetection(true)`. If a field is `null`, call the corresponding `enable*` verb on `viji.video.cv` to populate it. Each active CV feature consumes its own WebGL context for MediaPipe; enabling many at once on lower-end hardware can hit context limits.
366
366
  * @typedef {Object} FaceData
367
367
  * @property {number} id - Index-based face identifier (`0`, `1`, …). Stable within a single frame, may change between frames.
368
- * @property {Object} bounds - Bounding box, all components normalized to 0..1 of the source frame.
368
+ * @property {Object} bounds - Bounding box, all components normalized to 0..1 of the source frame. `null` unless face detection is enabled.
369
369
  * @property {number} bounds.x - Left edge of the face bounding box, normalized 0..1.
370
370
  * @property {number} bounds.y - Top edge of the face bounding box, normalized 0..1.
371
371
  * @property {number} bounds.width - Width of the face bounding box, normalized 0..1.
372
372
  * @property {number} bounds.height - Height of the face bounding box, normalized 0..1.
373
- * @property {Object} center - Center of the bounding box, normalized 0..1.
373
+ * @property {Object} center - Center of the bounding box, normalized 0..1. `null` unless face detection is enabled.
374
374
  * @property {number} center.x - Horizontal center of the face, normalized 0..1.
375
375
  * @property {number} center.y - Vertical center of the face, normalized 0..1.
376
- * @property {number} confidence - Detection confidence in 0..1.
376
+ * @property {number |null} confidence - Detection confidence in 0..1. `null` unless face detection is enabled.
377
377
  * @property {Object} landmarks - 468 normalized face mesh landmarks when face mesh is enabled; empty array otherwise.
378
378
  * @property {number} landmarks.x - Horizontal landmark coordinate, normalized 0..1.
379
379
  * @property {number} landmarks.y - Vertical landmark coordinate, normalized 0..1.
380
380
  * @property {number} landmarks.z - Optional depth (relative).
381
- * @property {Object} expressions - Seven expression confidence scores in 0..1. All zero unless emotion detection is enabled.
381
+ * @property {Object} headPose - Estimated head rotation in degrees. `null` unless face mesh is enabled.
382
+ * @property {number} headPose.pitch - Up/down rotation in degrees (-90..90). Positive = head looking up, negative = looking down.
383
+ * @property {number} headPose.yaw - Left/right rotation in degrees (-90..90). Positive = head turned to the subject's right, negative = to the left.
384
+ * @property {number} headPose.roll - Tilt rotation in degrees (-180..180). Positive = head tilted to the subject's right (right ear toward right shoulder).
385
+ * @property {Object} expressions - Seven expression confidence scores in 0..1. `null` unless emotion detection is enabled.
382
386
  * @property {number} expressions.neutral - Confidence (0..1) of a neutral expression.
383
387
  * @property {number} expressions.happy - Confidence (0..1) of a happy / smiling expression.
384
388
  * @property {number} expressions.sad - Confidence (0..1) of a sad expression.
@@ -386,11 +390,7 @@
386
390
  * @property {number} expressions.surprised - Confidence (0..1) of a surprised expression.
387
391
  * @property {number} expressions.disgusted - Confidence (0..1) of a disgusted expression.
388
392
  * @property {number} expressions.fearful - Confidence (0..1) of a fearful expression.
389
- * @property {Object} headPose - Estimated head rotation. All zero unless face mesh is enabled.
390
- * @property {number} headPose.pitch - Up/down rotation in degrees (-90..90). Positive = head looking up, negative = looking down.
391
- * @property {number} headPose.yaw - Left/right rotation in degrees (-90..90). Positive = head turned to the subject's right, negative = to the left.
392
- * @property {number} headPose.roll - Tilt rotation in degrees (-180..180). Positive = head tilted to the subject's right (right ear toward right shoulder).
393
- * @property {FaceBlendshapes} blendshapes - 52 ARKit-compatible facial muscle coefficients. All zero unless emotion detection is enabled.
393
+ * @property {FaceBlendshapes |null} blendshapes - 52 ARKit-compatible facial muscle coefficients. `null` unless emotion detection is enabled.
394
394
  */
395
395
 
396
396
  /**