@kubohiroya/turbowarp-camera-calibration 0.19.0 → 0.19.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/README.ja.md CHANGED
@@ -147,7 +147,7 @@ Node.jsやbuild環境を用意する必要はありません。専用buildのOpe
147
147
  検証済みのversionをexact pinします。
148
148
 
149
149
  ```bash
150
- pnpm add --save-exact @kubohiroya/turbowarp-camera-calibration@0.19.0
150
+ pnpm add --save-exact @kubohiroya/turbowarp-camera-calibration@0.19.1
151
151
  ```
152
152
 
153
153
  standalone bundle:
@@ -159,7 +159,7 @@ node_modules/@kubohiroya/turbowarp-camera-calibration/dist/camera-calibration.js
159
159
  version固定CDN URL:
160
160
 
161
161
  ```text
162
- https://cdn.jsdelivr.net/npm/@kubohiroya/turbowarp-camera-calibration@0.19.0/dist/camera-calibration.js
162
+ https://cdn.jsdelivr.net/npm/@kubohiroya/turbowarp-camera-calibration@0.19.1/dist/camera-calibration.js
163
163
  ```
164
164
 
165
165
  ## クイックスタート
package/README.md CHANGED
@@ -151,7 +151,7 @@ and is about 3.9 MB (about 1.5 MB gzip).
151
151
  Install an exact version that you have reviewed:
152
152
 
153
153
  ```bash
154
- pnpm add --save-exact @kubohiroya/turbowarp-camera-calibration@0.19.0
154
+ pnpm add --save-exact @kubohiroya/turbowarp-camera-calibration@0.19.1
155
155
  ```
156
156
 
157
157
  Load the standalone bundle from:
@@ -163,7 +163,7 @@ node_modules/@kubohiroya/turbowarp-camera-calibration/dist/camera-calibration.js
163
163
  A version-pinned CDN URL is:
164
164
 
165
165
  ```text
166
- https://cdn.jsdelivr.net/npm/@kubohiroya/turbowarp-camera-calibration@0.19.0/dist/camera-calibration.js
166
+ https://cdn.jsdelivr.net/npm/@kubohiroya/turbowarp-camera-calibration@0.19.1/dist/camera-calibration.js
167
167
  ```
168
168
 
169
169
  ## Quick start
@@ -13983,18 +13983,30 @@ function normalizeId(value, fallback = defaultCameraId) {
13983
13983
  var CameraCalibrationExtension = class {
13984
13984
  constructor(options = {}) {
13985
13985
  this.removeFixedEditors = () => {};
13986
+ this.editorsReleased = false;
13986
13987
  this.handleProjectBoundary = () => {
13987
13988
  this.controller.cancelAll();
13988
13989
  };
13989
- this.handleDisposed = () => {
13990
+ this.releaseEditors = () => {
13990
13991
  this.removeFixedEditors();
13991
13992
  this.removeSourceEditors();
13992
- if (this.runtime["kubohiroyaCameraCalibrationCapability"] === this.capability) delete this.runtime[runtimeCapabilityKey];
13993
- this.runtime.off?.("PROJECT_STOP_ALL", this.handleProjectBoundary);
13994
- this.runtime.off?.("PROJECT_LOADED", this.handleProjectBoundary);
13995
- this.runtime.off?.("RUNTIME_DISPOSED", this.handleDisposed);
13993
+ this.editorsReleased = true;
13994
+ };
13995
+ this.restoreEditors = () => {
13996
+ if (!this.editorsReleased) return;
13997
+ this.editorsReleased = false;
13998
+ this.removeSourceEditors = registerSourceEditors(Scratch, this.nowMilliseconds);
13999
+ try {
14000
+ this.removeFixedEditors = registerFixedInputEditors(Scratch, fixedInputEditors, this.runtime);
14001
+ } catch (error) {
14002
+ this.releaseEditors();
14003
+ throw error;
14004
+ }
14005
+ };
14006
+ this.handleDisposed = () => {
13996
14007
  this.controller.cleanupAll();
13997
14008
  };
14009
+ this.nowMilliseconds = options.nowMilliseconds;
13998
14010
  this.removeSourceEditors = registerSourceEditors(Scratch, options.nowMilliseconds);
13999
14011
  this.runtime = options.runtime ?? Scratch.vm.runtime;
14000
14012
  try {
@@ -14009,9 +14021,13 @@ var CameraCalibrationExtension = class {
14009
14021
  this.runtime.on?.("PROJECT_STOP_ALL", this.handleProjectBoundary);
14010
14022
  this.runtime.on?.("PROJECT_LOADED", this.handleProjectBoundary);
14011
14023
  this.runtime.on?.("RUNTIME_DISPOSED", this.handleDisposed);
14024
+ this.runtime.on?.("RUNTIME_DISPOSED", this.releaseEditors);
14025
+ this.runtime.on?.("PROJECT_LOADED", this.restoreEditors);
14012
14026
  } catch (error) {
14013
14027
  this.removeFixedEditors();
14014
14028
  this.removeSourceEditors();
14029
+ this.runtime.off?.("RUNTIME_DISPOSED", this.releaseEditors);
14030
+ this.runtime.off?.("PROJECT_LOADED", this.restoreEditors);
14015
14031
  this.runtime.off?.("PROJECT_STOP_ALL", this.handleProjectBoundary);
14016
14032
  this.runtime.off?.("PROJECT_LOADED", this.handleProjectBoundary);
14017
14033
  this.runtime.off?.("RUNTIME_DISPOSED", this.handleDisposed);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubohiroya/turbowarp-camera-calibration",
3
- "version": "0.19.0",
3
+ "version": "0.19.1",
4
4
  "description": "A TurboWarp extension that calibrates a shared Camera Source camera and publishes its intrinsic calibration profile.",
5
5
  "author": {
6
6
  "name": "Hiroya Kubo",
package/src/extension.ts CHANGED
@@ -61,10 +61,17 @@ export class CameraCalibrationExtension implements TurboWarpExtension {
61
61
  private readonly runtime: TurboWarpRuntime;
62
62
  private capability: CameraCalibrationCapabilityV1 | undefined;
63
63
 
64
- private readonly removeSourceEditors: () => void;
64
+ private removeSourceEditors: () => void;
65
65
  private removeFixedEditors: () => void = () => {};
66
+ private readonly nowMilliseconds: (() => number) | undefined;
67
+ /**
68
+ * Loading a project disposes the runtime, which releases the editor registrations, but the
69
+ * extension stays loaded for the next project. Register them again once that project has loaded.
70
+ */
71
+ private editorsReleased = false;
66
72
 
67
73
  public constructor(options: CameraCalibrationExtensionOptions = {}) {
74
+ this.nowMilliseconds = options.nowMilliseconds;
68
75
  this.removeSourceEditors = registerSourceEditors(Scratch, options.nowMilliseconds);
69
76
  this.runtime = options.runtime ?? Scratch.vm.runtime;
70
77
  try {
@@ -79,9 +86,13 @@ export class CameraCalibrationExtension implements TurboWarpExtension {
79
86
  this.runtime.on?.('PROJECT_STOP_ALL', this.handleProjectBoundary);
80
87
  this.runtime.on?.('PROJECT_LOADED', this.handleProjectBoundary);
81
88
  this.runtime.on?.('RUNTIME_DISPOSED', this.handleDisposed);
89
+ this.runtime.on?.('RUNTIME_DISPOSED', this.releaseEditors);
90
+ this.runtime.on?.('PROJECT_LOADED', this.restoreEditors);
82
91
  } catch (error) {
83
92
  this.removeFixedEditors();
84
93
  this.removeSourceEditors();
94
+ this.runtime.off?.('RUNTIME_DISPOSED', this.releaseEditors);
95
+ this.runtime.off?.('PROJECT_LOADED', this.restoreEditors);
85
96
  this.runtime.off?.('PROJECT_STOP_ALL', this.handleProjectBoundary);
86
97
  this.runtime.off?.('PROJECT_LOADED', this.handleProjectBoundary);
87
98
  this.runtime.off?.('RUNTIME_DISPOSED', this.handleDisposed);
@@ -263,17 +274,31 @@ export class CameraCalibrationExtension implements TurboWarpExtension {
263
274
  void this.controller.cancelAll();
264
275
  };
265
276
 
266
- private readonly handleDisposed = (): void => {
277
+ /** Not final for the editors: they register again with the next project. */
278
+ private readonly releaseEditors = (): void => {
267
279
  this.removeFixedEditors();
268
280
  this.removeSourceEditors();
269
- // Taken down with the runtime it belongs to, so a consumer that outlives
270
- // the VM reads an absent extension rather than driving a dead controller.
271
- if (this.runtime[runtimeCapabilityKey] === this.capability) {
272
- delete this.runtime[runtimeCapabilityKey];
281
+ this.editorsReleased = true;
282
+ };
283
+
284
+ private readonly restoreEditors = (): void => {
285
+ if (!this.editorsReleased) return;
286
+ this.editorsReleased = false;
287
+ this.removeSourceEditors = registerSourceEditors(Scratch, this.nowMilliseconds);
288
+ try {
289
+ this.removeFixedEditors = registerFixedInputEditors(Scratch, fixedInputEditors, this.runtime);
290
+ } catch (error) {
291
+ this.releaseEditors();
292
+ throw error;
273
293
  }
274
- this.runtime.off?.('PROJECT_STOP_ALL', this.handleProjectBoundary);
275
- this.runtime.off?.('PROJECT_LOADED', this.handleProjectBoundary);
276
- this.runtime.off?.('RUNTIME_DISPOSED', this.handleDisposed);
294
+ };
295
+
296
+ /**
297
+ * Every project load disposes the runtime while the extension stays loaded,
298
+ * so this ends only the project's sessions. The capability and the listeners
299
+ * stay for the next project; the controller reopens what it needs on demand.
300
+ */
301
+ private readonly handleDisposed = (): void => {
277
302
  void this.controller.cleanupAll();
278
303
  };
279
304