@meeeetup/camera-web 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.
Files changed (96) hide show
  1. package/LICENSE +29 -0
  2. package/README.md +154 -0
  3. package/dist/camera-loop.d.ts +40 -0
  4. package/dist/camera-loop.d.ts.map +1 -0
  5. package/dist/camera-loop.js +134 -0
  6. package/dist/camera-loop.js.map +1 -0
  7. package/dist/detectors/mediapipe-detector.d.ts +24 -0
  8. package/dist/detectors/mediapipe-detector.d.ts.map +1 -0
  9. package/dist/detectors/mediapipe-detector.js +67 -0
  10. package/dist/detectors/mediapipe-detector.js.map +1 -0
  11. package/dist/detectors/tensorflow-detector.d.ts +20 -0
  12. package/dist/detectors/tensorflow-detector.d.ts.map +1 -0
  13. package/dist/detectors/tensorflow-detector.js +59 -0
  14. package/dist/detectors/tensorflow-detector.js.map +1 -0
  15. package/dist/frame-buffer.d.ts +21 -0
  16. package/dist/frame-buffer.d.ts.map +1 -0
  17. package/dist/frame-buffer.js +47 -0
  18. package/dist/frame-buffer.js.map +1 -0
  19. package/dist/index.d.ts +13 -0
  20. package/dist/index.d.ts.map +1 -0
  21. package/dist/index.js +12 -0
  22. package/dist/index.js.map +1 -0
  23. package/dist/overlay.d.ts +7 -0
  24. package/dist/overlay.d.ts.map +1 -0
  25. package/dist/overlay.js +40 -0
  26. package/dist/overlay.js.map +1 -0
  27. package/dist/react/CircleProgress.d.ts +10 -0
  28. package/dist/react/CircleProgress.d.ts.map +1 -0
  29. package/dist/react/CircleProgress.js +18 -0
  30. package/dist/react/CircleProgress.js.map +1 -0
  31. package/dist/react/components/AlignmentRing.d.ts +3 -0
  32. package/dist/react/components/AlignmentRing.d.ts.map +1 -0
  33. package/dist/react/components/AlignmentRing.js +16 -0
  34. package/dist/react/components/AlignmentRing.js.map +1 -0
  35. package/dist/react/components/CameraToggle.d.ts +6 -0
  36. package/dist/react/components/CameraToggle.d.ts.map +1 -0
  37. package/dist/react/components/CameraToggle.js +10 -0
  38. package/dist/react/components/CameraToggle.js.map +1 -0
  39. package/dist/react/components/CameraViewport.d.ts +10 -0
  40. package/dist/react/components/CameraViewport.d.ts.map +1 -0
  41. package/dist/react/components/CameraViewport.js +75 -0
  42. package/dist/react/components/CameraViewport.js.map +1 -0
  43. package/dist/react/components/CaptureButton.d.ts +6 -0
  44. package/dist/react/components/CaptureButton.d.ts.map +1 -0
  45. package/dist/react/components/CaptureButton.js +15 -0
  46. package/dist/react/components/CaptureButton.js.map +1 -0
  47. package/dist/react/components/DevicePicker.d.ts +6 -0
  48. package/dist/react/components/DevicePicker.d.ts.map +1 -0
  49. package/dist/react/components/DevicePicker.js +11 -0
  50. package/dist/react/components/DevicePicker.js.map +1 -0
  51. package/dist/react/components/FaceCounter.d.ts +6 -0
  52. package/dist/react/components/FaceCounter.d.ts.map +1 -0
  53. package/dist/react/components/FaceCounter.js +11 -0
  54. package/dist/react/components/FaceCounter.js.map +1 -0
  55. package/dist/react/components/FaceGrid.d.ts +5 -0
  56. package/dist/react/components/FaceGrid.d.ts.map +1 -0
  57. package/dist/react/components/FaceGrid.js +127 -0
  58. package/dist/react/components/FaceGrid.js.map +1 -0
  59. package/dist/react/context/MeeeetUpCamContext.d.ts +47 -0
  60. package/dist/react/context/MeeeetUpCamContext.d.ts.map +1 -0
  61. package/dist/react/context/MeeeetUpCamContext.js +3 -0
  62. package/dist/react/context/MeeeetUpCamContext.js.map +1 -0
  63. package/dist/react/context/MeeeetUpCamProvider.d.ts +28 -0
  64. package/dist/react/context/MeeeetUpCamProvider.d.ts.map +1 -0
  65. package/dist/react/context/MeeeetUpCamProvider.js +109 -0
  66. package/dist/react/context/MeeeetUpCamProvider.js.map +1 -0
  67. package/dist/react/context/useMeeeetUpCam.d.ts +15 -0
  68. package/dist/react/context/useMeeeetUpCam.d.ts.map +1 -0
  69. package/dist/react/context/useMeeeetUpCam.js +22 -0
  70. package/dist/react/context/useMeeeetUpCam.js.map +1 -0
  71. package/dist/react/cx.d.ts +4 -0
  72. package/dist/react/cx.d.ts.map +1 -0
  73. package/dist/react/cx.js +6 -0
  74. package/dist/react/cx.js.map +1 -0
  75. package/dist/react/useCameraDevices.d.ts +9 -0
  76. package/dist/react/useCameraDevices.d.ts.map +1 -0
  77. package/dist/react/useCameraDevices.js +27 -0
  78. package/dist/react/useCameraDevices.js.map +1 -0
  79. package/dist/react/useInteractiveCamera.d.ts +39 -0
  80. package/dist/react/useInteractiveCamera.d.ts.map +1 -0
  81. package/dist/react/useInteractiveCamera.js +400 -0
  82. package/dist/react/useInteractiveCamera.js.map +1 -0
  83. package/dist/react/usePassiveCamera.d.ts +37 -0
  84. package/dist/react/usePassiveCamera.d.ts.map +1 -0
  85. package/dist/react/usePassiveCamera.js +130 -0
  86. package/dist/react/usePassiveCamera.js.map +1 -0
  87. package/dist/styles.css +66 -0
  88. package/dist/utils/camera-devices.d.ts +15 -0
  89. package/dist/utils/camera-devices.d.ts.map +1 -0
  90. package/dist/utils/camera-devices.js +37 -0
  91. package/dist/utils/camera-devices.js.map +1 -0
  92. package/dist/utils/compress-image.d.ts +12 -0
  93. package/dist/utils/compress-image.d.ts.map +1 -0
  94. package/dist/utils/compress-image.js +38 -0
  95. package/dist/utils/compress-image.js.map +1 -0
  96. package/package.json +59 -0
package/LICENSE ADDED
@@ -0,0 +1,29 @@
1
+ Copyright (c) 2026 MeeeetUp1120. All rights reserved.
2
+
3
+ PROPRIETARY SOFTWARE LICENCE
4
+
5
+ The `@meeeetup1120/core`, `@meeeetup1120/web` and `@meeeetup1120/react-native`
6
+ packages (the "Software") are proprietary to MeeeetUp1120.
7
+
8
+ Permission to use, copy and integrate the Software into your own application is
9
+ granted solely to parties holding a current written agreement with MeeeetUp1120
10
+ covering the Meeeetup face-identification service, and only for the purpose of
11
+ interoperating with that service. No other rights are granted.
12
+
13
+ You may not, without prior written permission from MeeeetUp1120:
14
+
15
+ - redistribute, sublicense, sell or lease the Software;
16
+ - modify, reverse-engineer, decompile or disassemble the Software, or create
17
+ derivative works from it, except as permitted by applicable law;
18
+ - remove or alter this notice or any copyright notice in the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23
+ MEEEETUP1120 BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
24
+ ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
25
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26
+
27
+ Third-party components retain their own licences. In particular the Software
28
+ loads `@mediapipe/tasks-vision` and its face-detection model at runtime, which
29
+ are licensed by Google under the Apache License 2.0.
package/README.md ADDED
@@ -0,0 +1,154 @@
1
+ # @meeeetup/camera-web
2
+
3
+ Browser face-capture SDK for the Meeeetup face-ID service. Detects faces with
4
+ MediaPipe BlazeFace, tracks them, picks the best-quality frame per person, and
5
+ hands you the images through a callback.
6
+
7
+ **Transport is yours.** The SDK never makes a network request and never holds a
8
+ credential: it calls `onBatchCapture` (passive) or `onCapture` (interactive)
9
+ with base64 JPEG data URLs, and sending them is your code.
10
+
11
+ Requires React 18 or 19. ESM-only. Served over HTTPS or `localhost` —
12
+ `getUserMedia` is a secure-context API.
13
+
14
+ ## Install
15
+
16
+ ```bash
17
+ npm i @meeeetup/camera-web react react-dom
18
+ ```
19
+
20
+ `@meeeetup/camera-core` arrives as a dependency — add it explicitly only if you
21
+ import from it directly (this package already re-exports `SelectedFace`,
22
+ `LiveFacePreview` and `PersonResult`).
23
+
24
+ ```ts
25
+ import "@meeeetup/camera-web/styles.css";
26
+ ```
27
+
28
+ ## Passive capture — continuous, batched
29
+
30
+ Faces are flushed to `onBatchCapture` every 10 s.
31
+
32
+ ```tsx
33
+ import {
34
+ MeeeetUpCamProvider,
35
+ CameraViewport,
36
+ FaceCounter,
37
+ FaceGrid,
38
+ type SelectedFace,
39
+ } from "@meeeetup/camera-web";
40
+
41
+ export function PassiveCamera({ captureKey }: { captureKey: string }) {
42
+ return (
43
+ <MeeeetUpCamProvider
44
+ mode="passive"
45
+ onBatchCapture={async (faces: SelectedFace[]) => {
46
+ const res = await fetch("https://api.example.com/capture", {
47
+ method: "POST",
48
+ headers: {
49
+ Authorization: `Bearer ${captureKey}`,
50
+ "Content-Type": "application/json",
51
+ },
52
+ body: JSON.stringify({
53
+ images: faces.map((f) => ({
54
+ image: f.dataUrl,
55
+ capturedAt: new Date(f.createdAt).toISOString(),
56
+ })),
57
+ }),
58
+ });
59
+ // Throw to report failure. A missing status, <400 or >=500 is retried;
60
+ // 4xx drops that batch (resending an unchanged rejected payload
61
+ // livelocks).
62
+ if (!res.ok) throw Object.assign(new Error("send failed"), { status: res.status });
63
+ }}
64
+ >
65
+ <CameraViewport />
66
+ <FaceCounter />
67
+ <FaceGrid />
68
+ </MeeeetUpCamProvider>
69
+ );
70
+ }
71
+ ```
72
+
73
+ ## Interactive capture — user-triggered
74
+
75
+ ```tsx
76
+ import {
77
+ MeeeetUpCamProvider,
78
+ CameraViewport,
79
+ AlignmentRing,
80
+ CaptureButton,
81
+ } from "@meeeetup/camera-web";
82
+
83
+ export function KioskCamera() {
84
+ return (
85
+ <MeeeetUpCamProvider
86
+ mode="interactive"
87
+ onCapture={async (faceImage, fullCircleImage) => {
88
+ await upload(faceImage, fullCircleImage);
89
+ }}
90
+ >
91
+ <CameraViewport />
92
+ <AlignmentRing />
93
+ <CaptureButton />
94
+ </MeeeetUpCamProvider>
95
+ );
96
+ }
97
+ ```
98
+
99
+ ## Custom UI
100
+
101
+ `useMeeeetUpCam()` exposes everything the built-in components render. Narrow on
102
+ `cam.mode` first; it throws outside a provider.
103
+
104
+ ```tsx
105
+ const cam = useMeeeetUpCam();
106
+ if (cam.mode === "passive") {
107
+ // cam.ready, cam.error, cam.trackedCount, cam.totalCount,
108
+ // cam.selectedFaces, cam.livePreviews, cam.flushBatch()
109
+ }
110
+ ```
111
+
112
+ Shared across modes: `ready`, `error`, `videoRef`, `devices`, `currentDeviceId`,
113
+ `setDeviceId`, `currentFacingMode`, `toggleCamera`.
114
+
115
+ ## Components
116
+
117
+ | Component | Mode | Renders |
118
+ |---|---|---|
119
+ | `CameraViewport` | both | `<video>` + overlay canvas (passive) / circular viewport (interactive) |
120
+ | `FaceCounter` | passive | Tracked + total badge |
121
+ | `FaceGrid` | passive | Grid of selected face crops |
122
+ | `DevicePicker` | both | Camera dropdown |
123
+ | `CameraToggle` | both | Front/back switch |
124
+ | `AlignmentRing` | interactive | Alignment ring, progress, countdown |
125
+ | `CaptureButton` | interactive | Manual capture trigger |
126
+
127
+ Every component except `AlignmentRing` accepts `className`. The skin is CSS
128
+ custom properties (`--mfc-*`) with dark defaults — re-theme by setting them on
129
+ any ancestor.
130
+
131
+ ## Provider props
132
+
133
+ Both modes accept `children`, `mediapipeWasmUrl` and `cooldownMs`.
134
+
135
+ | Prop | Mode | Type | Default |
136
+ |---|---|---|---|
137
+ | `onBatchCapture` | passive | `(faces: SelectedFace[]) => void \| Promise<void>` | required |
138
+ | `onCapture` | interactive | `(faceImage: string, fullCircleImage: string) => void \| Promise<void>` | required |
139
+ | `cooldownMs` | passive | `number` | `10000` — minimum ms between sends for the same face |
140
+ | `mediapipeWasmUrl` | passive | `string` | jsDelivr CDN — point it at a self-hosted WASM directory |
141
+ | `alignmentCaptureDelayMs` | interactive | `number` | `2000` — how long a face must stay aligned before auto-capture |
142
+
143
+ ## Runtime network access
144
+
145
+ MediaPipe assets are fetched on demand, so the browser must reach:
146
+
147
+ - `https://cdn.jsdelivr.net` — WASM runtime (override with `mediapipeWasmUrl`)
148
+ - `https://storage.googleapis.com` — the `.tflite` detection model
149
+
150
+ A strict CSP needs both in `connect-src`, plus `script-src 'wasm-unsafe-eval'`.
151
+
152
+ ## Licence
153
+
154
+ Proprietary — see `LICENSE`. Use requires a current agreement with MeeeetUp1120.
@@ -0,0 +1,40 @@
1
+ import { CanvasFrameBuffer } from "./frame-buffer.js";
2
+ import type { MediapipeDetector } from "./detectors/mediapipe-detector.js";
3
+ import type { TensorFlowDetector } from "./detectors/tensorflow-detector.js";
4
+ import type { Detection } from "@meeeetup/camera-core";
5
+ export type SupportedDetector = MediapipeDetector | TensorFlowDetector;
6
+ export interface CameraLoopCallbacks {
7
+ onFrame: (detections: Detection[], frame: CanvasFrameBuffer, timestampMs: number) => void;
8
+ onTick: () => void;
9
+ }
10
+ /**
11
+ * Manages the getUserMedia stream, offscreen canvas, and per-frame detection
12
+ * scheduling (requestVideoFrameCallback → requestAnimationFrame fallback).
13
+ */
14
+ export declare class CameraLoop {
15
+ private readonly video;
16
+ private readonly detector;
17
+ private readonly callbacks;
18
+ private stream;
19
+ private offscreen;
20
+ private vcbHandle;
21
+ private rafHandle;
22
+ private running;
23
+ constructor(video: HTMLVideoElement, detector: SupportedDetector, callbacks: CameraLoopCallbacks);
24
+ start(deviceId?: string, facingMode?: "user" | "environment"): Promise<void>;
25
+ stop(): void;
26
+ /** Expose the offscreen canvas for overlay coordinate scaling. */
27
+ get offscreenCanvas(): HTMLCanvasElement | null;
28
+ /**
29
+ * Resolve once the element has dimensions. Checking `readyState` first is
30
+ * what makes a remount safe: React StrictMode (and any effect that restarts
31
+ * the loop) can hand us a video that already loaded this stream's metadata,
32
+ * and `loadedmetadata` never fires a second time — waiting only on the event
33
+ * would hang `start()` forever with no error. A stalled stream rejects on a
34
+ * deadline instead of leaving the UI stuck on "connecting".
35
+ */
36
+ private _waitForMetadata;
37
+ private _scheduleDetect;
38
+ private _detectFrame;
39
+ }
40
+ //# sourceMappingURL=camera-loop.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"camera-loop.d.ts","sourceRoot":"","sources":["../src/camera-loop.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM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**
4
+ * Manages the getUserMedia stream, offscreen canvas, and per-frame detection
5
+ * scheduling (requestVideoFrameCallback → requestAnimationFrame fallback).
6
+ */
7
+ export class CameraLoop {
8
+ constructor(video, detector, callbacks) {
9
+ this.video = video;
10
+ this.detector = detector;
11
+ this.callbacks = callbacks;
12
+ this.stream = null;
13
+ this.offscreen = null;
14
+ this.vcbHandle = null;
15
+ this.rafHandle = null;
16
+ this.running = false;
17
+ }
18
+ async start(deviceId, facingMode = "user") {
19
+ let constraint;
20
+ if (deviceId) {
21
+ constraint = { deviceId: { exact: deviceId } };
22
+ }
23
+ else {
24
+ // Prefer an explicit physical device ID so virtual cameras (OBS etc.) are
25
+ // never picked up by the facingMode ideal constraint.
26
+ const physicalId = await findPhysicalCameraId(facingMode);
27
+ constraint = physicalId
28
+ ? { deviceId: { exact: physicalId } }
29
+ : { facingMode, width: { ideal: 1280 }, height: { ideal: 720 } };
30
+ }
31
+ this.stream = await navigator.mediaDevices.getUserMedia({ video: constraint });
32
+ this.video.srcObject = this.stream;
33
+ await this._waitForMetadata();
34
+ await this.video.play();
35
+ const oc = document.createElement("canvas");
36
+ oc.width = this.video.videoWidth || 1280;
37
+ oc.height = this.video.videoHeight || 720;
38
+ this.offscreen = oc;
39
+ this.running = true;
40
+ this._scheduleDetect(this._detectFrame.bind(this));
41
+ // Overlay / tick loop at display refresh rate
42
+ const tickLoop = () => {
43
+ if (!this.running)
44
+ return;
45
+ this.callbacks.onTick();
46
+ this.rafHandle = requestAnimationFrame(tickLoop);
47
+ };
48
+ this.rafHandle = requestAnimationFrame(tickLoop);
49
+ }
50
+ stop() {
51
+ this.running = false;
52
+ if (this.rafHandle)
53
+ cancelAnimationFrame(this.rafHandle);
54
+ if (this.vcbHandle && "cancelVideoFrameCallback" in HTMLVideoElement.prototype) {
55
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
56
+ this.video.cancelVideoFrameCallback(this.vcbHandle);
57
+ }
58
+ else if (this.vcbHandle) {
59
+ cancelAnimationFrame(this.vcbHandle);
60
+ }
61
+ this.stream?.getTracks().forEach((t) => t.stop());
62
+ this.stream = null;
63
+ this.offscreen = null;
64
+ }
65
+ /** Expose the offscreen canvas for overlay coordinate scaling. */
66
+ get offscreenCanvas() { return this.offscreen; }
67
+ /**
68
+ * Resolve once the element has dimensions. Checking `readyState` first is
69
+ * what makes a remount safe: React StrictMode (and any effect that restarts
70
+ * the loop) can hand us a video that already loaded this stream's metadata,
71
+ * and `loadedmetadata` never fires a second time — waiting only on the event
72
+ * would hang `start()` forever with no error. A stalled stream rejects on a
73
+ * deadline instead of leaving the UI stuck on "connecting".
74
+ */
75
+ async _waitForMetadata(timeoutMs = 10000) {
76
+ // HTMLMediaElement.HAVE_METADATA — dimensions and duration are known.
77
+ if (this.video.readyState >= 1)
78
+ return;
79
+ await new Promise((resolve, reject) => {
80
+ const settle = (event) => {
81
+ clearTimeout(timer);
82
+ this.video.removeEventListener("loadedmetadata", settle);
83
+ this.video.removeEventListener("error", settle);
84
+ if (event?.type === "loadedmetadata")
85
+ resolve();
86
+ else if (event)
87
+ reject(new Error("Camera stream failed to load"));
88
+ else
89
+ reject(new Error(`Camera stream produced no metadata within ${timeoutMs}ms`));
90
+ };
91
+ const timer = setTimeout(settle, timeoutMs, null);
92
+ this.video.addEventListener("loadedmetadata", settle);
93
+ this.video.addEventListener("error", settle);
94
+ });
95
+ }
96
+ _scheduleDetect(cb) {
97
+ if (!this.video)
98
+ return;
99
+ if ("requestVideoFrameCallback" in HTMLVideoElement.prototype) {
100
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
101
+ this.vcbHandle = this.video.requestVideoFrameCallback(cb);
102
+ }
103
+ else {
104
+ this.vcbHandle = requestAnimationFrame(cb);
105
+ }
106
+ }
107
+ _detectFrame(nowPerf) {
108
+ if (!this.running || !this.offscreen || !this.video)
109
+ return;
110
+ const vw = this.video.videoWidth || 1280;
111
+ const vh = this.video.videoHeight || 720;
112
+ if (this.offscreen.width !== vw || this.offscreen.height !== vh) {
113
+ this.offscreen.width = vw;
114
+ this.offscreen.height = vh;
115
+ }
116
+ this.offscreen.getContext("2d")?.drawImage(this.video, 0, 0, vw, vh);
117
+ let detections;
118
+ // MediapipeDetector is synchronous; TensorFlowDetector returns a Promise
119
+ const result = this.detector.detectForVideo?.(this.offscreen, nowPerf);
120
+ if (result instanceof Promise) {
121
+ result.then((dets) => {
122
+ if (!this.running)
123
+ return;
124
+ this.callbacks.onFrame(dets, new CanvasFrameBuffer(this.offscreen), nowPerf);
125
+ this._scheduleDetect(this._detectFrame.bind(this));
126
+ });
127
+ return; // don't re-schedule synchronously
128
+ }
129
+ detections = result;
130
+ this.callbacks.onFrame(detections, new CanvasFrameBuffer(this.offscreen), nowPerf);
131
+ this._scheduleDetect(this._detectFrame.bind(this));
132
+ }
133
+ }
134
+ //# sourceMappingURL=camera-loop.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"camera-loop.js","sourceRoot":"","sources":["../src/camera-loop.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAItD,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AASjE;;;GAGG;AACH,MAAM,OAAO,UAAU;IAOrB,YACmB,KAA0B,EAC1B,QAA2B,EAC3B,SAA8B;QAF9B,UAAK,GAAL,KAAK,CAAqB;QAC1B,aAAQ,GAAR,QAAQ,CAAmB;QAC3B,cAAS,GAAT,SAAS,CAAqB;QATzC,WAAM,GAA6B,IAAI,CAAC;QACxC,cAAS,GAA6B,IAAI,CAAC;QAC3C,cAAS,GAA0B,IAAI,CAAC;QACxC,cAAS,GAA0B,IAAI,CAAC;QACxC,YAAO,GAAM,KAAK,CAAC;IAMxB,CAAC;IAEJ,KAAK,CAAC,KAAK,CAAC,QAAiB,EAAE,aAAqC,MAAM;QACxE,IAAI,UAAiC,CAAC;QACtC,IAAI,QAAQ,EAAE,CAAC;YACb,UAAU,GAAG,EAAE,QAAQ,EAAE,EA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AAC,CAAC,CAAC;IACrD,CAAC;CACF"}
@@ -0,0 +1,24 @@
1
+ import type { Detection } from "@meeeetup/camera-core";
2
+ /**
3
+ * Wraps MediaPipe BlazeFace and converts its output to the shared Detection[].
4
+ *
5
+ * MediaPipe keypoint order: [0] rightEye [1] leftEye [2] noseTip [3] mouth
6
+ * [4] rightEar [5] leftEar
7
+ * We keep only [0..2] which matches what getFrontalness() expects.
8
+ */
9
+ export declare class MediapipeDetector {
10
+ private readonly detector;
11
+ private constructor();
12
+ static create(options?: {
13
+ wasmUrl?: string;
14
+ modelUrl?: string;
15
+ minConfidence?: number;
16
+ }): Promise<MediapipeDetector>;
17
+ /**
18
+ * Run detection on a canvas that contains the current video frame.
19
+ * Returns normalised Detection[] ready for the core pipeline.
20
+ */
21
+ detectForVideo(canvas: HTMLCanvasElement, timestampMs: number): Detection[];
22
+ dispose(): void;
23
+ }
24
+ //# sourceMappingURL=mediapipe-detector.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mediapipe-detector.d.ts","sourceRoot":"","sources":["../../src/detectors/mediapipe-detector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAuBvD;;;;;;GAMG;AACH,qBAAa,iBAAiB;IACR,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAA7C,OAAO;WAEM,MAAM,CAAC,OAAO,CAAC,EAAE;QAC5B,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,aAAa,CAAC,EAAE,MAAM,CAAC;KACxB,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAwB9B;;;OAGG;IACH,cAAc,CAAC,MAAM,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,GAAG,SAAS,EAAE;IAsB3E,OAAO,IAAI,IAAI;CAChB"}
@@ -0,0 +1,67 @@
1
+ const DEFAULT_WASM_URL = "https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@latest/wasm";
2
+ const DEFAULT_MODEL_URL = "https://storage.googleapis.com/mediapipe-models/face_detector/blaze_face_full_range/float16/latest/blaze_face_full_range.tflite";
3
+ /**
4
+ * Wraps MediaPipe BlazeFace and converts its output to the shared Detection[].
5
+ *
6
+ * MediaPipe keypoint order: [0] rightEye [1] leftEye [2] noseTip [3] mouth
7
+ * [4] rightEar [5] leftEar
8
+ * We keep only [0..2] which matches what getFrontalness() expects.
9
+ */
10
+ export class MediapipeDetector {
11
+ constructor(detector) {
12
+ this.detector = detector;
13
+ }
14
+ static async create(options) {
15
+ // Dynamic import so the heavy WASM is only loaded on demand
16
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
17
+ const { FaceDetector, FilesetResolver } = await import("@mediapipe/tasks-vision");
18
+ const fileset = await FilesetResolver.forVisionTasks(options?.wasmUrl ?? DEFAULT_WASM_URL);
19
+ const detector = await withSilencedConsole(() => FaceDetector.createFromModelPath(fileset, options?.modelUrl ?? DEFAULT_MODEL_URL));
20
+ detector.setOptions({
21
+ runningMode: "VIDEO",
22
+ minDetectionConfidence: options?.minConfidence ?? 0.5,
23
+ });
24
+ return new MediapipeDetector(detector);
25
+ }
26
+ /**
27
+ * Run detection on a canvas that contains the current video frame.
28
+ * Returns normalised Detection[] ready for the core pipeline.
29
+ */
30
+ detectForVideo(canvas, timestampMs) {
31
+ const result = this.detector.detectForVideo(canvas, timestampMs);
32
+ const W = canvas.width;
33
+ const H = canvas.height;
34
+ return result.detections
35
+ .filter((d) => d.boundingBox)
36
+ .map((d) => ({
37
+ boundingBox: {
38
+ originX: d.boundingBox.originX / W,
39
+ originY: d.boundingBox.originY / H,
40
+ width: d.boundingBox.width / W,
41
+ height: d.boundingBox.height / H,
42
+ },
43
+ keypoints: (d.keypoints ?? []).slice(0, 3).map((kp) => ({
44
+ x: kp.x,
45
+ y: kp.y,
46
+ })),
47
+ score: d.categories?.[0]?.score ?? 1,
48
+ }));
49
+ }
50
+ dispose() { this.detector.close(); }
51
+ }
52
+ async function withSilencedConsole(fn) {
53
+ const noop = () => { };
54
+ const origLog = console.log, origInfo = console.info, origWarn = console.warn;
55
+ console.log = noop;
56
+ console.info = noop;
57
+ console.warn = noop;
58
+ try {
59
+ return await fn();
60
+ }
61
+ finally {
62
+ console.log = origLog;
63
+ console.info = origInfo;
64
+ console.warn = origWarn;
65
+ }
66
+ }
67
+ //# sourceMappingURL=mediapipe-detector.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mediapipe-detector.js","sourceRoot":"","sources":["../../src/detectors/mediapipe-detector.ts"],"names":[],"mappings":"AAiBA,MAAM,gBAAgB,GACpB,kEAAkE,CAAC;AAErE,MAAM,iBAAiB,GACrB,iIAAiI,CAAC;AAEpI;;;;;;GAMG;AACH,MAAM,OAAO,iBAAiB;IAC5B,YAAqC,QAAsB;QAAtB,aAAQ,GAAR,QAAQ,CAAc;IAAG,CAAC;IAE/D,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,OAInB;QACC,4DAA4D;QAC5D,8DAA8D;QAC9D,MAAM,EAAE,YAAY,EAAE,eAAe,EAAE,GAAG,MAAM,MAAM,CAAC,yBAAgC,CAAC,CAAC;QAEzF,MAAM,OAAO,GAAG,MAAM,eAAe,CAAC,cAAc,CAClD,OAAO,EAAE,OAAO,IAAI,gBAAgB,CACrC,CAAC;QAEF,MAAM,QAAQ,GAAiB,MAAM,mBAAmB,CAAC,GAAG,EAAE,CAC5D,YAAY,CAAC,mBAAmB,CAC9B,OAAO,EACP,OAAO,EAAE,QAAQ,IAAI,iBAAiB,CACvC,CACF,CAAC;QAEF,QAAQ,CAAC,UAAU,CAAC;YAClB,WAAW,EAAE,OAAO;YACpB,sBAAsB,EAAE,OAAO,EAAE,aAAa,IAAI,GAAG;SACtD,CAAC,CAAC;QAEH,OAAO,IAAI,iBAAiB,CAAC,QAAQ,CAAC,CAAC;IACzC,CAAC;IAED;;;OAGG;IACH,cAAc,CAAC,MAAyB,EAAE,WAAmB;QAC3D,MA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,GAAG,OAAO,CAAC,IAAI,CAAC;IAC9E,OAAO,CAAC,GAAG,GAAG,IAAI,CAAC;IAAC,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;IAAC,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;IAC7D,IAAI,CAAC;QACH,OAAO,MAAM,EAAE,EAAE,CAAC;IACpB,CAAC;YAAS,CAAC;QACT,OAAO,CAAC,GAAG,GAAG,OAAO,CAAC;QAAC,OAAO,CAAC,IAAI,GAAG,QAAQ,CAAC;QAAC,OAAO,CAAC,IAAI,GAAG,QAAQ,CAAC;IAC1E,CAAC;AACH,CAAC"}
@@ -0,0 +1,20 @@
1
+ import type { Detection } from "@meeeetup/camera-core";
2
+ /**
3
+ * TensorFlow.js BlazeFace adapter.
4
+ *
5
+ * Install peer deps:
6
+ * npm i @tensorflow/tfjs @tensorflow-models/blazeface
7
+ *
8
+ * Same output shape as MediapipeDetector — drop-in swap.
9
+ *
10
+ * BlazeFace keypoint order: [0] rightEye [1] leftEye [2] noseTip
11
+ * [3] mouth [4] rightEar [5] leftEar
12
+ */
13
+ export declare class TensorFlowDetector {
14
+ private readonly model;
15
+ private constructor();
16
+ static create(): Promise<TensorFlowDetector>;
17
+ detectForVideo(canvas: HTMLCanvasElement): Promise<Detection[]>;
18
+ dispose(): void;
19
+ }
20
+ //# sourceMappingURL=tensorflow-detector.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tensorflow-detector.d.ts","sourceRoot":"","sources":["../../src/detectors/tensorflow-detector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAEvD;;;;;;;;;;GAUG;AACH,qBAAa,kBAAkB;IAET,OAAO,CAAC,QAAQ,CAAC,KAAK;IAA1C,OAAO;WAEM,MAAM,IAAI,OAAO,CAAC,kBAAkB,CAAC;IAa5C,cAAc,CAClB,MAAM,EAAE,iBAAiB,GACxB,OAAO,CAAC,SAAS,EAAE,CAAC;IAmCvB,OAAO,IAAI,IAAI;CAGhB"}
@@ -0,0 +1,59 @@
1
+ /**
2
+ * TensorFlow.js BlazeFace adapter.
3
+ *
4
+ * Install peer deps:
5
+ * npm i @tensorflow/tfjs @tensorflow-models/blazeface
6
+ *
7
+ * Same output shape as MediapipeDetector — drop-in swap.
8
+ *
9
+ * BlazeFace keypoint order: [0] rightEye [1] leftEye [2] noseTip
10
+ * [3] mouth [4] rightEar [5] leftEar
11
+ */
12
+ export class TensorFlowDetector {
13
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
14
+ constructor(model) {
15
+ this.model = model;
16
+ }
17
+ static async create() {
18
+ // String split prevents Vite / Rollup from statically resolving these
19
+ // optional peer deps — they are only loaded if this method is called.
20
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
21
+ const [tf, blazeface] = await Promise.all([
22
+ import("@tensorflow" + "/tfjs"),
23
+ import("@tensorflow-models" + "/blazeface"),
24
+ ]);
25
+ await tf.ready();
26
+ const model = await blazeface.load();
27
+ return new TensorFlowDetector(model);
28
+ }
29
+ async detectForVideo(canvas) {
30
+ const W = canvas.width;
31
+ const H = canvas.height;
32
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
33
+ const predictions = await this.model.estimateFaces(canvas, false);
34
+ return predictions.map((p) => {
35
+ const [x1, y1] = p.topLeft;
36
+ const [x2, y2] = p.bottomRight;
37
+ const bw = x2 - x1;
38
+ const bh = y2 - y1;
39
+ return {
40
+ boundingBox: {
41
+ originX: x1 / W,
42
+ originY: y1 / H,
43
+ width: bw / W,
44
+ height: bh / H,
45
+ },
46
+ // BlazeFace landmarks match the same index order as MediaPipe [0..2]
47
+ keypoints: p.landmarks.slice(0, 3).map(([lx, ly]) => ({
48
+ x: lx / W,
49
+ y: ly / H,
50
+ })),
51
+ score: p.probability[0] ?? 1,
52
+ };
53
+ });
54
+ }
55
+ dispose() {
56
+ // TensorFlow.js models don't need explicit disposal in most cases
57
+ }
58
+ }
59
+ //# sourceMappingURL=tensorflow-detector.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tensorflow-detector.js","sourceRoot":"","sources":["../../src/detectors/tensorflow-detector.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AACH,MAAM,OAAO,kBAAkB;IAC7B,8DAA8D;IAC9D,YAAqC,KAAU;QAAV,UAAK,GAAL,KAAK,CAAK;IAAG,CAAC;IAEnD,MAAM,CAAC,KAAK,CAAC,MAAM;QACjB,sEAAsE;QACtE,sEAAsE;QACtE,8DAA8D;QAC9D,MAAM,CAAC,EAAE,EAAE,SAAS,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;YACxC,MAAM,CAAC,aAAa,GAAG,OAAgB,CAAC;YACxC,MAAM,CAAC,oBAAoB,GAAG,YAAqB,CAAC;SACrD,CAAU,CAAC;QACZ,MAAM,EAAE,CAAC,KAAK,EAAE,CAAC;QACjB,MAAM,KAAK,GAAG,MAAM,SAAS,CAAC,IAAI,EAAE,CAAC;QACrC,OAAO,IAAI,kBAAkB,CAAC,KAAK,CAAC,CAAC;IACvC,CAAC;IAED,KAAK,CAAC,cAAc,CAClB,MAAyB;QAEzB,MAAM,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC;QACvB,MAAM,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC;QAExB,8DAA8D;QAC9D,MAAM,WAAW,GAAU,MAAM,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;QAEzE,OAAO,WAAW,CAAC,GAAG,CAAC,CAAC,CAKvB,EAAE,EAAE;YACH,MAAM,CAAC,EAAE,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC;YAC3B,MAAM,CAAC,EAAE,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,WAAW,CAAC;YAC/B,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC;YACnB,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC;YAEnB,OAAO;gBACL,WAAW,EAAE;oBACX,OAAO,EAAE,EAAE,GAAG,CAAC;oBACf,OAAO,EAAE,EAAE,GAAG,CAAC;oBACf,KAAK,EAAI,EAAE,GAAI,CAAC;oBAChB,MAAM,EAAG,EAAE,GAAI,CAAC;iBACjB;gBACD,qEAAqE;gBACrE,SAAS,EAAE,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,CAAmB,EAAE,EAAE,CAAC,CAAC;oBACtE,CAAC,EAAE,EAAE,GAAG,CAAC;oBACT,CAAC,EAAE,EAAE,GAAG,CAAC;iBACV,CAAC,CAAC;gBACH,KAAK,EAAE,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC;aAC7B,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;IAED,OAAO;QACL,kEAAkE;IACpE,CAAC;CACF"}
@@ -0,0 +1,21 @@
1
+ import type { FrameBuffer } from "@meeeetup/camera-core";
2
+ /**
3
+ * Web implementation of FrameBuffer backed by an HTMLCanvasElement.
4
+ * The canvas should contain the current video frame (drawn via drawImage).
5
+ */
6
+ export declare class CanvasFrameBuffer implements FrameBuffer {
7
+ private readonly canvas;
8
+ constructor(canvas: HTMLCanvasElement);
9
+ get width(): number;
10
+ get height(): number;
11
+ toJpegBase64(quality?: number): string;
12
+ /**
13
+ * Crop the face region with asymmetric padding (extra top for hair/forehead)
14
+ * and return a 256×256 JPEG data URL.
15
+ * cx, cy, bw, bh are all normalised (0–1).
16
+ */
17
+ cropFaceJpeg(cx: number, cy: number, bw: number, bh: number, quality?: number): string | null;
18
+ }
19
+ /** Copy src canvas pixels into a new canvas — used to freeze a video frame. */
20
+ export declare function snapshotCanvas(src: HTMLCanvasElement): HTMLCanvasElement;
21
+ //# sourceMappingURL=frame-buffer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"frame-buffer.d.ts","sourceRoot":"","sources":["../src/frame-buffer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEzD;;;GAGG;AACH,qBAAa,iBAAkB,YAAW,WAAW;IACvC,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAN,MAAM,EAAE,iBAAiB;IAEtD,IAAI,KAAK,IAAI,MAAM,CAA+B;IAClD,IAAI,MAAM,IAAI,MAAM,CAA+B;IAEnD,YAAY,CAAC,OAAO,SAAO,GAAG,MAAM;IAIpC;;;;OAIG;IACH,YAAY,CACV,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,MAAM,EACV,OAAO,SAAO,GACb,MAAM,GAAG,IAAI;CAqBjB;AAED,+EAA+E;AAC/E,wBAAgB,cAAc,CAAC,GAAG,EAAE,iBAAiB,GAAG,iBAAiB,CAMxE"}
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Web implementation of FrameBuffer backed by an HTMLCanvasElement.
3
+ * The canvas should contain the current video frame (drawn via drawImage).
4
+ */
5
+ export class CanvasFrameBuffer {
6
+ constructor(canvas) {
7
+ this.canvas = canvas;
8
+ }
9
+ get width() { return this.canvas.width; }
10
+ get height() { return this.canvas.height; }
11
+ toJpegBase64(quality = 0.85) {
12
+ return this.canvas.toDataURL("image/jpeg", quality);
13
+ }
14
+ /**
15
+ * Crop the face region with asymmetric padding (extra top for hair/forehead)
16
+ * and return a 256×256 JPEG data URL.
17
+ * cx, cy, bw, bh are all normalised (0–1).
18
+ */
19
+ cropFaceJpeg(cx, cy, bw, bh, quality = 0.85) {
20
+ const W = this.canvas.width;
21
+ const H = this.canvas.height;
22
+ // Asymmetric padding: MediaPipe box cuts off at forehead
23
+ const PAD_X = 0.4;
24
+ const PAD_TOP = 0.6;
25
+ const PAD_BOTTOM = 0.2;
26
+ const sx = Math.max(0, (cx - bw / 2) * W - bw * W * PAD_X);
27
+ const sy = Math.max(0, (cy - bh / 2) * H - bh * H * PAD_TOP);
28
+ const sw = Math.min(W - sx, bw * W * (1 + PAD_X * 2));
29
+ const sh = Math.min(H - sy, bh * H * (1 + PAD_TOP + PAD_BOTTOM));
30
+ if (sw <= 0 || sh <= 0)
31
+ return null;
32
+ const crop = document.createElement("canvas");
33
+ crop.width = 256;
34
+ crop.height = 256;
35
+ crop.getContext("2d")?.drawImage(this.canvas, sx, sy, sw, sh, 0, 0, 256, 256);
36
+ return crop.toDataURL("image/jpeg", quality);
37
+ }
38
+ }
39
+ /** Copy src canvas pixels into a new canvas — used to freeze a video frame. */
40
+ export function snapshotCanvas(src) {
41
+ const copy = document.createElement("canvas");
42
+ copy.width = src.width;
43
+ copy.height = src.height;
44
+ copy.getContext("2d")?.drawImage(src, 0, 0);
45
+ return copy;
46
+ }
47
+ //# sourceMappingURL=frame-buffer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"frame-buffer.js","sourceRoot":"","sources":["../src/frame-buffer.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,OAAO,iBAAiB;IAC5B,YAA6B,MAAyB;QAAzB,WAAM,GAAN,MAAM,CAAmB;IAAG,CAAC;IAE1D,IAAI,KAAK,KAAc,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IAClD,IAAI,MAAM,KAAa,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;IAEnD,YAAY,CAAC,OAAO,GAAG,IAAI;QACzB,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;IACtD,CAAC;IAED;;;;OAIG;IACH,YAAY,CACV,EAAU,EACV,EAAU,EACV,EAAU,EACV,EAAU,EACV,OAAO,GAAG,IAAI;QAEd,MAAM,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;QAC5B,MAAM,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CA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