@viji-dev/core 0.4.6 → 0.5.1

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.
@@ -1211,14 +1211,16 @@ declare global {
1211
1211
  isEnding: boolean;
1212
1212
  }
1213
1213
 
1214
- const VERSION = "0.4.5";
1214
+ const VERSION = "0.5.1";
1215
1215
 
1216
1216
  /**
1217
- * Real-time video API: drawable frame, dimensions, and computer-vision results
1218
- * (faces, hands, pose, segmentation). Activate individual CV features through `cv.*`.
1217
+ * Real-time video API: drawable frame, dimensions, and the source-side
1218
+ * properties of the connected stream. All computer-vision data and controls
1219
+ * (faces, hands, pose, segmentation, the analysed frame, and feature
1220
+ * enable/disable verbs) live on `viji.video.cv`.
1219
1221
  *
1220
- * When `isConnected` is `false`, `currentFrame` is `null`, all dimensions are `0`,
1221
- * and CV result fields hold their empty defaults.
1222
+ * When `isConnected` is `false`, `currentFrame` is `null`, all dimensions are
1223
+ * `0`, and every member of `cv` holds its empty default.
1222
1224
  */
1223
1225
  interface VideoAPI {
1224
1226
  /** `true` when a video stream is connected. When `false`, all other fields hold their default empty values. */
@@ -1237,6 +1239,78 @@ declare global {
1237
1239
  * use only when you need to read individual pixel values.
1238
1240
  */
1239
1241
  getFrameData: () => ImageData | null;
1242
+ /**
1243
+ * Computer-vision surface for this video stream. Holds both the data
1244
+ * outputs (`faces`, `hands`, `pose`, `segmentation`, `analysedFrame`,
1245
+ * `getAnalysedFrameData`) and the verbs that activate them
1246
+ * (`enable*`/`disable*`/`getActiveFeatures`/`isProcessing`).
1247
+ *
1248
+ * Multiple features can be active simultaneously, but each adds CPU/GPU
1249
+ * and WebGL-context cost; toggle only what you need.
1250
+ *
1251
+ * `analysedFrame` and the result fields refresh together once per host
1252
+ * frame as an atomic snapshot: within a single `render()` call they are
1253
+ * always paired.
1254
+ */
1255
+ cv: VideoCVAPI;
1256
+ }
1257
+
1258
+ /**
1259
+ * Computer-vision surface attached to a `VideoAPI`. Combines paired CV data
1260
+ * outputs (the analysed frame and its detection / segmentation results) with
1261
+ * the verbs that activate the underlying MediaPipe pipelines.
1262
+ *
1263
+ * Available only on the main video stream (`viji.video.cv`). Additional
1264
+ * streams (`viji.videoStreams[i].cv`) and device videos
1265
+ * (`viji.devices[i].video.cv`) do not run CV; their `cv` surface exists for
1266
+ * API consistency but the data fields stay at their empty defaults and the
1267
+ * `enable*` verbs are no-ops.
1268
+ */
1269
+ interface VideoCVAPI {
1270
+ /**
1271
+ * The exact video frame that produced the current `faces` / `hands` /
1272
+ * `pose` / `segmentation` results: the frame MediaPipe actually analysed.
1273
+ *
1274
+ * Choose between `analysedFrame` and `viji.video.currentFrame` by asking
1275
+ * whether the effect reads pixels from the displayed frame at CV-derived
1276
+ * positions. Reach for `analysedFrame` when the answer is yes
1277
+ * (compositing the segmentation mask onto the body, sampling skin tone
1278
+ * under a face landmark, warping the face along its mesh, texture-mapped
1279
+ * face filters): pairing the displayed frame with the CV results is
1280
+ * required for those effects. Stay on `currentFrame` when the answer is
1281
+ * no (drawing landmark dots, particles, debug overlays, geometry driven
1282
+ * by CV positions): `analysedFrame` only refreshes when MediaPipe
1283
+ * completes an inference, which is not every frame, so reaching for it
1284
+ * without a reason makes the displayed video stutter or hold between
1285
+ * inferences.
1286
+ *
1287
+ * Pairing guarantee: within a single `render()` call, `analysedFrame`
1288
+ * is paired with the values of `faces`, `hands`, `pose`, `segmentation`
1289
+ * read in the same call.
1290
+ *
1291
+ * `null` until the first CV inference completes after a feature is
1292
+ * enabled, after the video disconnects, or after a CV-feature toggle
1293
+ * clears state. A common pattern is
1294
+ * `viji.video.cv.analysedFrame ?? viji.video.currentFrame` to fall back
1295
+ * to the live feed during the brief startup window; expect a small
1296
+ * visual hitch when the source switches as the first inference lands.
1297
+ *
1298
+ * Read-only: this `OffscreenCanvas` is owned by the engine. Do not
1299
+ * mutate it (no `getContext`-and-paint, no `transferToImageBitmap`).
1300
+ * Drawing it as a source (`ctx.drawImage`, `gl.texImage2D`,
1301
+ * `p5.image(...)`) is the only supported usage.
1302
+ */
1303
+ analysedFrame: OffscreenCanvas | null;
1304
+ /**
1305
+ * Returns `analysedFrame` as raw RGBA `ImageData` for per-pixel CPU
1306
+ * analysis, or `null` when no CV result has landed yet (or the stream is
1307
+ * disconnected). Cached: re-extracted only when a new CV result arrives,
1308
+ * so multiple readers within a render share one allocation. Slow
1309
+ * compared to drawing `analysedFrame` directly. Use only when you need
1310
+ * pixel values aligned with CV landmark positions (e.g. sampling skin
1311
+ * colour at a face landmark).
1312
+ */
1313
+ getAnalysedFrameData: () => ImageData | null;
1240
1314
  /** Detected faces (empty array when face detection is off or no faces are visible). */
1241
1315
  faces: FaceData[];
1242
1316
  /** Detected hands (up to 2; empty array when hand tracking is off or no hands are visible). */
@@ -1246,50 +1320,42 @@ declare global {
1246
1320
  /** Body segmentation mask, or `null` when segmentation is off. */
1247
1321
  segmentation: SegmentationData | null;
1248
1322
  /**
1249
- * Computer-vision feature control. Each `enable*` method toggles a specific CV
1250
- * pipeline; results land in the corresponding `faces` / `hands` / `pose` /
1251
- * `segmentation` field on the next available frame. Multiple features can be
1252
- * active simultaneously, but each adds CPU/GPU and WebGL-context cost.
1323
+ * Toggle face detection (bounding box, center, confidence, id).
1324
+ * @returns Resolves once the underlying pipeline has finished switching.
1253
1325
  */
1254
- cv: {
1255
- /**
1256
- * Toggle face detection (bounding box, center, confidence, id).
1257
- * @returns Resolves once the underlying pipeline has finished switching.
1258
- */
1259
- enableFaceDetection(enabled: boolean): Promise<void>;
1260
- /**
1261
- * Toggle 468-point face mesh + head pose (`pitch`, `yaw`, `roll`). Implies
1262
- * face detection.
1263
- * @returns Resolves once the pipeline has finished switching.
1264
- */
1265
- enableFaceMesh(enabled: boolean): Promise<void>;
1266
- /**
1267
- * Toggle 7 expressions + 52 ARKit blendshape coefficients on each face.
1268
- * Implies face mesh.
1269
- * @returns Resolves once the pipeline has finished switching.
1270
- */
1271
- enableEmotionDetection(enabled: boolean): Promise<void>;
1272
- /**
1273
- * Toggle 21-point hand landmarks + ML-classified gesture confidences for up
1274
- * to two hands.
1275
- * @returns Resolves once the pipeline has finished switching.
1276
- */
1277
- enableHandTracking(enabled: boolean): Promise<void>;
1278
- /**
1279
- * Toggle 33-point BlazePose body landmarks (face / torso / arms / legs).
1280
- * @returns Resolves once the pipeline has finished switching.
1281
- */
1282
- enablePoseDetection(enabled: boolean): Promise<void>;
1283
- /**
1284
- * Toggle per-pixel person/background segmentation mask.
1285
- * @returns Resolves once the pipeline has finished switching.
1286
- */
1287
- enableBodySegmentation(enabled: boolean): Promise<void>;
1288
- /** Returns the list of CV features currently enabled on this stream. */
1289
- getActiveFeatures(): CVFeature[];
1290
- /** Returns `true` if the CV worker is actively processing frames. */
1291
- isProcessing(): boolean;
1292
- };
1326
+ enableFaceDetection(enabled: boolean): Promise<void>;
1327
+ /**
1328
+ * Toggle 468-point face mesh + head pose (`pitch`, `yaw`, `roll`). Implies
1329
+ * face detection.
1330
+ * @returns Resolves once the pipeline has finished switching.
1331
+ */
1332
+ enableFaceMesh(enabled: boolean): Promise<void>;
1333
+ /**
1334
+ * Toggle 7 expressions + 52 ARKit blendshape coefficients on each face.
1335
+ * Implies face mesh.
1336
+ * @returns Resolves once the pipeline has finished switching.
1337
+ */
1338
+ enableEmotionDetection(enabled: boolean): Promise<void>;
1339
+ /**
1340
+ * Toggle 21-point hand landmarks + ML-classified gesture confidences for up
1341
+ * to two hands.
1342
+ * @returns Resolves once the pipeline has finished switching.
1343
+ */
1344
+ enableHandTracking(enabled: boolean): Promise<void>;
1345
+ /**
1346
+ * Toggle 33-point BlazePose body landmarks (face / torso / arms / legs).
1347
+ * @returns Resolves once the pipeline has finished switching.
1348
+ */
1349
+ enablePoseDetection(enabled: boolean): Promise<void>;
1350
+ /**
1351
+ * Toggle per-pixel person/background segmentation mask.
1352
+ * @returns Resolves once the pipeline has finished switching.
1353
+ */
1354
+ enableBodySegmentation(enabled: boolean): Promise<void>;
1355
+ /** Returns the list of CV features currently enabled on this stream. */
1356
+ getActiveFeatures(): CVFeature[];
1357
+ /** Returns `true` if the CV worker is actively processing frames. */
1358
+ isProcessing(): boolean;
1293
1359
  }
1294
1360
 
1295
1361
  /**
@@ -265,7 +265,7 @@
265
265
  */
266
266
 
267
267
  /**
268
- * Real-time video API: drawable frame, dimensions, and computer-vision results (faces, hands, pose, segmentation). Activate individual CV features through `cv.*`. When `isConnected` is `false`, `currentFrame` is `null`, all dimensions are `0`, and CV result fields hold their empty defaults.
268
+ * Real-time video API: drawable frame, dimensions, and the source-side properties of the connected stream. All computer-vision data and controls (faces, hands, pose, segmentation, the analysed frame, and feature enable/disable verbs) live on `viji.video.cv`. When `isConnected` is `false`, `currentFrame` is `null`, all dimensions are `0`, and every member of `cv` holds its empty default.
269
269
  * @typedef {Object} VideoAPI
270
270
  * @property {boolean} isConnected - `true` when a video stream is connected. When `false`, all other fields hold their default empty values.
271
271
  * @property {OffscreenCanvas | ImageBitmap |null} currentFrame - Latest video frame, drawable directly with `ctx.drawImage()`. `null` when disconnected.
@@ -273,11 +273,7 @@
273
273
  * @property {number} frameHeight - Source video frame height in pixels. `0` when disconnected.
274
274
  * @property {number} frameRate - Source video frame rate in Hz (frames per second). `0` when disconnected.
275
275
  * @property {() => ImageData |null} getFrameData - Returns the latest frame as raw RGBA `ImageData` for per-pixel CPU analysis, or `null` when disconnected. Slow compared to drawing `currentFrame` directly; use only when you need to read individual pixel values.
276
- * @property {FaceData[]} faces - Detected faces (empty array when face detection is off or no faces are visible).
277
- * @property {HandData[]} hands - Detected hands (up to 2; empty array when hand tracking is off or no hands are visible).
278
- * @property {PoseData |null} pose - Detected body pose, or `null` when pose detection is off or no pose is visible.
279
- * @property {SegmentationData |null} segmentation - Body segmentation mask, or `null` when segmentation is off.
280
- * @property {Object} cv - Computer-vision feature control. Each `enable*` method toggles a specific CV pipeline; results land in the corresponding `faces` / `hands` / `pose` / `segmentation` field on the next available frame. Multiple features can be active simultaneously, but each adds CPU/GPU and WebGL-context cost.
276
+ * @property {VideoCVAPI} cv - Computer-vision surface for this video stream. Holds both the data outputs (`faces`, `hands`, `pose`, `segmentation`, `analysedFrame`, `getAnalysedFrameData`) and the verbs that activate them (`enable*`/`disable*`/`getActiveFeatures`/`isProcessing`). Multiple features can be active simultaneously, but each adds CPU/GPU and WebGL-context cost; toggle only what you need. `analysedFrame` and the result fields refresh together once per host frame as an atomic snapshot: within a single `render()` call they are always paired.
281
277
  */
282
278
 
283
279
  /**