@kubohiroya/turbowarp-teachable-machine 3.4.0 → 3.4.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.
package/dist/tm.js CHANGED
@@ -553,7 +553,7 @@
553
553
  }
554
554
  var package_default = {
555
555
  name: "@kubohiroya/turbowarp-teachable-machine",
556
- version: "3.4.0",
556
+ version: "3.4.1",
557
557
  description: "A TurboWarp extension for recognition using Teachable Machine pose, image, and audio models.",
558
558
  author: "Hiroya Kubo <hiroya@cuc.ac.jp>",
559
559
  license: "MPL-2.0",
@@ -1214,6 +1214,7 @@
1214
1214
  const constraints = lease ? void 0 : cameraConstraints(this.resolvedCameraSelection());
1215
1215
  if (constraints) await this.webcam.setup(constraints);
1216
1216
  else await this.webcam.setup();
1217
+ this.ensureCameraCanvas();
1217
1218
  initializeCameraReadbackContext(this.webcam.canvas);
1218
1219
  if (!lease) await this.webcam.play();
1219
1220
  this.attachPreviewToStage();
@@ -1231,6 +1232,23 @@
1231
1232
  }
1232
1233
  }
1233
1234
  /**
1235
+ * Give the camera the readback canvas `setup()` did not build.
1236
+ *
1237
+ * Upstream creates that canvas inside the same branch that opens the camera, so an injected
1238
+ * element skips the canvas with the `getUserMedia` call. 3.4.0 shipped assuming the two were
1239
+ * separate, and every leased start then failed at the first context request with "Webcam canvas
1240
+ * does not provide a 2D context" -- which is to say pose recognition did not start at all
1241
+ * wherever Camera Source was present. The canvas built here is the one upstream would have
1242
+ * built, so the mirrored centre crop every downstream reader expects is unchanged.
1243
+ */
1244
+ ensureCameraCanvas() {
1245
+ if (!this.webcam || this.webcam.canvas) return;
1246
+ const canvas = document.createElement("canvas");
1247
+ canvas.width = this.webcam.width ?? 320;
1248
+ canvas.height = this.webcam.height ?? 240;
1249
+ this.webcam.canvas = canvas;
1250
+ }
1251
+ /**
1234
1252
  * A lease on the shared camera, or null when Camera Source is not loaded.
1235
1253
  *
1236
1254
  * Camera Source owns the device and decides when a stream stops, which is what lets one camera
@@ -5,6 +5,9 @@ export declare const EXTENSION_ID = "kubohiroyatm";
5
5
  export declare const VERSION: string;
6
6
  export declare const DOCS_URI = "https://kubohiroya.github.io/turbowarp-teachable-machine/";
7
7
  export declare const ACCUMULATED_POSE_CHANGED_EVENT = "TM_ACCUMULATED_POSE_CHANGED";
8
+ /** The readback canvas size every downstream frame reader is written against. */
9
+ export declare const CAMERA_FRAME_WIDTH = 320;
10
+ export declare const CAMERA_FRAME_HEIGHT = 240;
8
11
  export declare const BLOCK_ICON_URI: string;
9
12
  export type RecognitionMode = 'pose' | 'image' | 'audio';
10
13
  export interface TeachableMachineRuntime {
@@ -152,6 +155,17 @@ export declare class TMExtension {
152
155
  ensureLibrariesLoaded(): Promise<void>;
153
156
  cleanupCameraResources(): void;
154
157
  startCamera(): Promise<void>;
158
+ /**
159
+ * Give the camera the readback canvas `setup()` did not build.
160
+ *
161
+ * Upstream creates that canvas inside the same branch that opens the camera, so an injected
162
+ * element skips the canvas with the `getUserMedia` call. 3.4.0 shipped assuming the two were
163
+ * separate, and every leased start then failed at the first context request with "Webcam canvas
164
+ * does not provide a 2D context" -- which is to say pose recognition did not start at all
165
+ * wherever Camera Source was present. The canvas built here is the one upstream would have
166
+ * built, so the mirrored centre crop every downstream reader expects is unchanged.
167
+ */
168
+ ensureCameraCanvas(): void;
155
169
  /**
156
170
  * A lease on the shared camera, or null when Camera Source is not loaded.
157
171
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubohiroya/turbowarp-teachable-machine",
3
- "version": "3.4.0",
3
+ "version": "3.4.1",
4
4
  "description": "A TurboWarp extension for recognition using Teachable Machine pose, image, and audio models.",
5
5
  "author": "Hiroya Kubo <hiroya@cuc.ac.jp>",
6
6
  "license": "MPL-2.0",