tempest-react-sdk 0.19.0 → 0.20.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/vision.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import type * as ort from 'onnxruntime-web';
2
+ import { RefObject } from 'react';
2
3
 
3
4
  /**
4
5
  * Per-class NMS — boxes are suppressed only by other boxes of the same class.
@@ -103,6 +104,18 @@ export declare class Boxes {
103
104
  get data(): Float32Array;
104
105
  }
105
106
 
107
+ /** A classified camera error with a human-readable, English message. */
108
+ export declare interface CameraStreamError {
109
+ kind: CameraStreamErrorKind;
110
+ message: string;
111
+ }
112
+
113
+ /** Classified reason a camera stream could not be acquired. */
114
+ export declare type CameraStreamErrorKind = "unsupported" | "permission-denied" | "no-camera" | "in-use" | "insecure" | "unknown";
115
+
116
+ /** Lifecycle status of the camera stream. */
117
+ export declare type CameraStreamStatus = "idle" | "loading" | "ready" | "error";
118
+
106
119
  /**
107
120
  * Output of an image classification inference.
108
121
  */
@@ -245,6 +258,25 @@ export declare interface ClassProbability {
245
258
  /** COCO 2017 80-class labels in canonical class-id order. */
246
259
  export declare const COCO_CLASSES: readonly string[];
247
260
 
261
+ /**
262
+ * Mean BT.709 luminance (`0.2126*R + 0.7152*G + 0.0722*B`) of a decoded
263
+ * `<img>`, `<video>` or `<canvas>`, scaled to `0..255`.
264
+ *
265
+ * The source is downsampled so its longest edge is at most
266
+ * {@link LUMINANCE_SAMPLE_MAX_EDGE} before pixels are read. The 2D context is
267
+ * created with `willReadFrequently` so repeated sampling (live feedback) stays
268
+ * on the fast path.
269
+ *
270
+ * Pass `reusableCanvas` to avoid allocating a fresh canvas every frame in a hot
271
+ * loop; when omitted a one-shot detached canvas is created.
272
+ *
273
+ * @param source - the image/video/canvas to sample.
274
+ * @param reusableCanvas - optional canvas reused across frames to avoid GC churn.
275
+ * @returns The mean luminance in `0..255`, or `0` when the source is unloaded
276
+ * (zero-sized) or a 2D context is unavailable.
277
+ */
278
+ export declare function computeImageLuminance(source: LuminanceSource, reusableCanvas?: HTMLCanvasElement): number;
279
+
248
280
  export declare interface DecodedAnchors {
249
281
  /** Indices into the original `numAnchors` axis, in descending confidence order. */
250
282
  readonly anchorIndices: Int32Array;
@@ -554,6 +586,20 @@ export declare class ImageLoadError extends OrtVisionError {
554
586
  export declare class InferenceError extends OrtVisionError {
555
587
  }
556
588
 
589
+ /**
590
+ * Whether a measured luminance clears a brightness threshold.
591
+ *
592
+ * `threshold` is intentionally required — a sensible value is
593
+ * application-specific (it depends on the model, the lighting the model was
594
+ * trained on, and the acceptable false-reject rate), so the SDK does not bake
595
+ * in a default.
596
+ *
597
+ * @param luminance - measured mean luminance in `0..255`.
598
+ * @param threshold - minimum acceptable luminance in `0..255`.
599
+ * @returns `true` when `luminance >= threshold`.
600
+ */
601
+ export declare function isLuminanceAcceptable(luminance: number, threshold: number): boolean;
602
+
557
603
  /** Raised when class labels cannot be resolved from the supplied spec. */
558
604
  export declare class LabelMapError extends OrtVisionError {
559
605
  }
@@ -605,6 +651,34 @@ export declare interface LetterboxResult {
605
651
  */
606
652
  export declare function loadImage(source: ImageInput): Promise<RGBImage>;
607
653
 
654
+ /**
655
+ * Error raised when a captured frame is too dark to be analysed reliably.
656
+ * Carries the measured luminance and the threshold it failed so callers can
657
+ * surface actionable feedback.
658
+ */
659
+ export declare class LowLuminanceError extends Error {
660
+ /** Measured mean luminance, `0..255`. */
661
+ readonly luminance: number;
662
+ /** Threshold that was checked against, `0..255`. */
663
+ readonly threshold: number;
664
+ /**
665
+ * @param luminance - the measured mean luminance in `0..255`.
666
+ * @param threshold - the threshold the measurement failed to reach.
667
+ */
668
+ constructor(luminance: number, threshold: number);
669
+ }
670
+
671
+ /**
672
+ * Longest edge (in pixels) the source is downsampled to before sampling.
673
+ * Averaging over a small downsample is statistically equivalent for a
674
+ * brightness threshold and orders of magnitude faster than reading every pixel
675
+ * of a full-resolution camera frame.
676
+ */
677
+ export declare const LUMINANCE_SAMPLE_MAX_EDGE = 256;
678
+
679
+ /** Drawable source we can sample luminance from — image, video, or canvas. */
680
+ export declare type LuminanceSource = HTMLImageElement | HTMLVideoElement | HTMLCanvasElement;
681
+
608
682
  /**
609
683
  * Single-channel binary or grayscale mask, laid out row-major.
610
684
  *
@@ -1018,6 +1092,74 @@ export declare interface LetterboxResult {
1018
1092
  */
1019
1093
  export declare function toTensor(image: RGBImage): Float32Array;
1020
1094
 
1095
+ /**
1096
+ * Acquire a `MediaStream` via `getUserMedia`, attach it to a `<video>` element,
1097
+ * and expose status/error so the page can render permission and error states.
1098
+ * The stream is automatically released on unmount or retry.
1099
+ *
1100
+ * Defaults to the rear ("environment") camera; desktops fall back to whatever
1101
+ * single camera they expose. Pass `options.constraints` to override.
1102
+ *
1103
+ * Implementation notes:
1104
+ * - Cleanup detaches the stream from a *snapshotted* video node, so it releases
1105
+ * the same element it attached to even if the page remounts the `<video>`.
1106
+ * - When `getUserMedia` is missing, an insecure context is the usual cause, so
1107
+ * the hook prefers that (actionable) error; otherwise it reports `unsupported`.
1108
+ * - `video.play()` rejections are swallowed: autoplay may be blocked, but the
1109
+ * user gesture that opened the camera usually counts and playback resumes on
1110
+ * the next interaction.
1111
+ *
1112
+ * @param options - optional configuration (see {@link UseCameraStreamOptions}).
1113
+ * @returns The stream status, classified error, a `videoRef` to attach, and a
1114
+ * `retry()` to re-attempt acquisition.
1115
+ */
1116
+ export declare function useCameraStream(options?: UseCameraStreamOptions): UseCameraStreamApi;
1117
+
1118
+ /** Value returned by {@link useCameraStream}. */
1119
+ export declare interface UseCameraStreamApi {
1120
+ /** Current lifecycle status. */
1121
+ status: CameraStreamStatus;
1122
+ /** The classified error, or `null` while not in the `error` status. */
1123
+ error: CameraStreamError | null;
1124
+ /** Attach to a `<video ref={…} />`. The stream is wired to it once ready. */
1125
+ videoRef: RefObject<HTMLVideoElement | null>;
1126
+ /** Manually re-attempt after an error (e.g. the user changed permissions). */
1127
+ retry: () => void;
1128
+ }
1129
+
1130
+ /** Options for {@link useCameraStream}. */
1131
+ export declare interface UseCameraStreamOptions {
1132
+ /**
1133
+ * Constraints passed to `getUserMedia`. Defaults to the rear
1134
+ * ("environment") camera at Full-HD ideal resolution with audio off.
1135
+ * Read when the stream (re)starts — change it and call `retry()` to apply.
1136
+ */
1137
+ constraints?: MediaStreamConstraints;
1138
+ }
1139
+
1140
+ /**
1141
+ * Sample mean luminance from a `<video>` source on a `requestAnimationFrame`
1142
+ * loop and expose the rolling value. Sampling is throttled by `intervalMs` and
1143
+ * paused whenever `enabled` is `false` or the video is not ready yet
1144
+ * (`readyState < 2` or `videoWidth === 0`).
1145
+ *
1146
+ * One offscreen canvas is reused across frames to avoid GC pressure. Designed
1147
+ * to feed a live brightness bar / border color on a camera page.
1148
+ *
1149
+ * @param videoRef - ref to the `<video>` element to sample.
1150
+ * @param options - optional configuration (see {@link UseLiveLuminanceOptions}).
1151
+ * @returns The rolling mean luminance in `0..255` (`0` until the first sample).
1152
+ */
1153
+ export declare function useLiveLuminance(videoRef: RefObject<HTMLVideoElement | null>, { enabled, intervalMs }?: UseLiveLuminanceOptions): number;
1154
+
1155
+ /** Options for {@link useLiveLuminance}. */
1156
+ export declare interface UseLiveLuminanceOptions {
1157
+ /** When `false` the loop is paused (e.g. while a capture is in flight). Default: `true`. */
1158
+ enabled?: boolean;
1159
+ /** Throttle measurements in milliseconds. Default: `160` (~6 fps), plenty for UX. */
1160
+ intervalMs?: number;
1161
+ }
1162
+
1021
1163
  export declare const VERSION: string;
1022
1164
 
1023
1165
  export declare abstract class VisionTask {