@chipmobilesdk/rn-camera 0.4.0 → 0.5.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 (185) hide show
  1. package/CHANGELOG.md +130 -0
  2. package/README.md +11 -7
  3. package/lib/commonjs/config/types.js +54 -0
  4. package/lib/commonjs/config/types.js.map +1 -0
  5. package/lib/commonjs/core/capabilities.js +45 -0
  6. package/lib/commonjs/core/capabilities.js.map +1 -0
  7. package/lib/commonjs/core/captureController.js +107 -0
  8. package/lib/commonjs/core/captureController.js.map +1 -0
  9. package/lib/commonjs/core/contract.js +16 -0
  10. package/lib/commonjs/core/contract.js.map +1 -0
  11. package/lib/commonjs/core/controller.js +452 -0
  12. package/lib/commonjs/core/controller.js.map +1 -0
  13. package/lib/commonjs/core/sessionMachine.js +116 -0
  14. package/lib/commonjs/core/sessionMachine.js.map +1 -0
  15. package/lib/commonjs/core/sessionRuntime.js +218 -0
  16. package/lib/commonjs/core/sessionRuntime.js.map +1 -0
  17. package/lib/commonjs/diagnostics/errors.js +86 -0
  18. package/lib/commonjs/diagnostics/errors.js.map +1 -0
  19. package/lib/commonjs/diagnostics/logger.js +40 -0
  20. package/lib/commonjs/diagnostics/logger.js.map +1 -0
  21. package/lib/commonjs/geometry/coordinateMapping.js +156 -0
  22. package/lib/commonjs/geometry/coordinateMapping.js.map +1 -0
  23. package/lib/commonjs/index.js +130 -0
  24. package/lib/commonjs/index.js.map +1 -0
  25. package/lib/commonjs/native/cameraEngine.js +86 -0
  26. package/lib/commonjs/native/cameraEngine.js.map +1 -0
  27. package/lib/commonjs/native/visionCameraPeer.js +28 -0
  28. package/lib/commonjs/native/visionCameraPeer.js.map +1 -0
  29. package/lib/commonjs/native/visionSurface.js +38 -0
  30. package/lib/commonjs/native/visionSurface.js.map +1 -0
  31. package/lib/commonjs/package.json +1 -0
  32. package/lib/commonjs/permissions/permissionPort.js +105 -0
  33. package/lib/commonjs/permissions/permissionPort.js.map +1 -0
  34. package/lib/commonjs/react/CameraPreview.js +136 -0
  35. package/lib/commonjs/react/CameraPreview.js.map +1 -0
  36. package/lib/commonjs/react/VisionCameraFeed.js +196 -0
  37. package/lib/commonjs/react/VisionCameraFeed.js.map +1 -0
  38. package/lib/commonjs/react/hooks.js +50 -0
  39. package/lib/commonjs/react/hooks.js.map +1 -0
  40. package/lib/commonjs/storage/artifactStore.js +98 -0
  41. package/lib/commonjs/storage/artifactStore.js.map +1 -0
  42. package/lib/commonjs/testing/conformance.js +109 -0
  43. package/lib/commonjs/testing/conformance.js.map +1 -0
  44. package/lib/commonjs/testing/index.js +50 -0
  45. package/lib/commonjs/testing/index.js.map +1 -0
  46. package/lib/commonjs/testing/testCameraAdapter.js +191 -0
  47. package/lib/commonjs/testing/testCameraAdapter.js.map +1 -0
  48. package/lib/module/config/types.js +49 -0
  49. package/lib/module/config/types.js.map +1 -0
  50. package/lib/module/core/capabilities.js +37 -0
  51. package/lib/module/core/capabilities.js.map +1 -0
  52. package/lib/module/core/captureController.js +98 -0
  53. package/lib/module/core/captureController.js.map +1 -0
  54. package/lib/module/core/contract.js +12 -0
  55. package/lib/module/core/contract.js.map +1 -0
  56. package/lib/module/core/controller.js +442 -0
  57. package/lib/module/core/controller.js.map +1 -0
  58. package/lib/module/core/sessionMachine.js +109 -0
  59. package/lib/module/core/sessionMachine.js.map +1 -0
  60. package/lib/module/core/sessionRuntime.js +215 -0
  61. package/lib/module/core/sessionRuntime.js.map +1 -0
  62. package/lib/module/diagnostics/errors.js +79 -0
  63. package/lib/module/diagnostics/errors.js.map +1 -0
  64. package/lib/module/diagnostics/logger.js +35 -0
  65. package/lib/module/diagnostics/logger.js.map +1 -0
  66. package/lib/module/geometry/coordinateMapping.js +149 -0
  67. package/lib/module/geometry/coordinateMapping.js.map +1 -0
  68. package/lib/module/index.js +44 -0
  69. package/lib/module/index.js.map +1 -0
  70. package/lib/module/native/cameraEngine.js +83 -0
  71. package/lib/module/native/cameraEngine.js.map +1 -0
  72. package/lib/module/native/visionCameraPeer.js +24 -0
  73. package/lib/module/native/visionCameraPeer.js.map +1 -0
  74. package/lib/module/native/visionSurface.js +34 -0
  75. package/lib/module/native/visionSurface.js.map +1 -0
  76. package/lib/module/package.json +1 -0
  77. package/lib/module/permissions/permissionPort.js +101 -0
  78. package/lib/module/permissions/permissionPort.js.map +1 -0
  79. package/lib/module/react/CameraPreview.js +130 -0
  80. package/lib/module/react/CameraPreview.js.map +1 -0
  81. package/lib/module/react/VisionCameraFeed.js +190 -0
  82. package/lib/module/react/VisionCameraFeed.js.map +1 -0
  83. package/lib/module/react/hooks.js +45 -0
  84. package/lib/module/react/hooks.js.map +1 -0
  85. package/lib/module/storage/artifactStore.js +94 -0
  86. package/lib/module/storage/artifactStore.js.map +1 -0
  87. package/lib/module/testing/conformance.js +102 -0
  88. package/lib/module/testing/conformance.js.map +1 -0
  89. package/lib/module/testing/index.js +13 -0
  90. package/lib/module/testing/index.js.map +1 -0
  91. package/lib/module/testing/testCameraAdapter.js +185 -0
  92. package/lib/module/testing/testCameraAdapter.js.map +1 -0
  93. package/lib/typescript/commonjs/config/types.d.ts +122 -0
  94. package/lib/typescript/commonjs/config/types.d.ts.map +1 -0
  95. package/lib/typescript/commonjs/core/capabilities.d.ts +16 -0
  96. package/lib/typescript/commonjs/core/capabilities.d.ts.map +1 -0
  97. package/lib/typescript/commonjs/core/captureController.d.ts +48 -0
  98. package/lib/typescript/commonjs/core/captureController.d.ts.map +1 -0
  99. package/lib/typescript/commonjs/core/contract.d.ts +92 -0
  100. package/lib/typescript/commonjs/core/contract.d.ts.map +1 -0
  101. package/lib/typescript/commonjs/core/controller.d.ts +15 -0
  102. package/lib/typescript/commonjs/core/controller.d.ts.map +1 -0
  103. package/lib/typescript/commonjs/core/sessionMachine.d.ts +46 -0
  104. package/lib/typescript/commonjs/core/sessionMachine.d.ts.map +1 -0
  105. package/lib/typescript/commonjs/core/sessionRuntime.d.ts +64 -0
  106. package/lib/typescript/commonjs/core/sessionRuntime.d.ts.map +1 -0
  107. package/lib/typescript/commonjs/diagnostics/errors.d.ts +24 -0
  108. package/lib/typescript/commonjs/diagnostics/errors.d.ts.map +1 -0
  109. package/lib/typescript/commonjs/diagnostics/logger.d.ts +24 -0
  110. package/lib/typescript/commonjs/diagnostics/logger.d.ts.map +1 -0
  111. package/lib/typescript/commonjs/geometry/coordinateMapping.d.ts +23 -0
  112. package/lib/typescript/commonjs/geometry/coordinateMapping.d.ts.map +1 -0
  113. package/lib/typescript/commonjs/index.d.ts +32 -0
  114. package/lib/typescript/commonjs/index.d.ts.map +1 -0
  115. package/lib/typescript/commonjs/native/cameraEngine.d.ts +50 -0
  116. package/lib/typescript/commonjs/native/cameraEngine.d.ts.map +1 -0
  117. package/lib/typescript/commonjs/native/visionCameraPeer.d.ts +2 -0
  118. package/lib/typescript/commonjs/native/visionCameraPeer.d.ts.map +1 -0
  119. package/lib/typescript/commonjs/native/visionSurface.d.ts +41 -0
  120. package/lib/typescript/commonjs/native/visionSurface.d.ts.map +1 -0
  121. package/lib/typescript/commonjs/package.json +1 -0
  122. package/lib/typescript/commonjs/permissions/permissionPort.d.ts +24 -0
  123. package/lib/typescript/commonjs/permissions/permissionPort.d.ts.map +1 -0
  124. package/lib/typescript/commonjs/react/CameraPreview.d.ts +25 -0
  125. package/lib/typescript/commonjs/react/CameraPreview.d.ts.map +1 -0
  126. package/lib/typescript/commonjs/react/VisionCameraFeed.d.ts +31 -0
  127. package/lib/typescript/commonjs/react/VisionCameraFeed.d.ts.map +1 -0
  128. package/lib/typescript/commonjs/react/hooks.d.ts +12 -0
  129. package/lib/typescript/commonjs/react/hooks.d.ts.map +1 -0
  130. package/lib/typescript/commonjs/storage/artifactStore.d.ts +54 -0
  131. package/lib/typescript/commonjs/storage/artifactStore.d.ts.map +1 -0
  132. package/lib/typescript/commonjs/testing/conformance.d.ts +37 -0
  133. package/lib/typescript/commonjs/testing/conformance.d.ts.map +1 -0
  134. package/lib/typescript/commonjs/testing/index.d.ts +12 -0
  135. package/lib/typescript/commonjs/testing/index.d.ts.map +1 -0
  136. package/lib/typescript/commonjs/testing/testCameraAdapter.d.ts +61 -0
  137. package/lib/typescript/commonjs/testing/testCameraAdapter.d.ts.map +1 -0
  138. package/lib/typescript/module/config/types.d.ts +122 -0
  139. package/lib/typescript/module/config/types.d.ts.map +1 -0
  140. package/lib/typescript/module/core/capabilities.d.ts +16 -0
  141. package/lib/typescript/module/core/capabilities.d.ts.map +1 -0
  142. package/lib/typescript/module/core/captureController.d.ts +48 -0
  143. package/lib/typescript/module/core/captureController.d.ts.map +1 -0
  144. package/lib/typescript/module/core/contract.d.ts +92 -0
  145. package/lib/typescript/module/core/contract.d.ts.map +1 -0
  146. package/lib/typescript/module/core/controller.d.ts +15 -0
  147. package/lib/typescript/module/core/controller.d.ts.map +1 -0
  148. package/lib/typescript/module/core/sessionMachine.d.ts +46 -0
  149. package/lib/typescript/module/core/sessionMachine.d.ts.map +1 -0
  150. package/lib/typescript/module/core/sessionRuntime.d.ts +64 -0
  151. package/lib/typescript/module/core/sessionRuntime.d.ts.map +1 -0
  152. package/lib/typescript/module/diagnostics/errors.d.ts +24 -0
  153. package/lib/typescript/module/diagnostics/errors.d.ts.map +1 -0
  154. package/lib/typescript/module/diagnostics/logger.d.ts +24 -0
  155. package/lib/typescript/module/diagnostics/logger.d.ts.map +1 -0
  156. package/lib/typescript/module/geometry/coordinateMapping.d.ts +23 -0
  157. package/lib/typescript/module/geometry/coordinateMapping.d.ts.map +1 -0
  158. package/lib/typescript/module/index.d.ts +32 -0
  159. package/lib/typescript/module/index.d.ts.map +1 -0
  160. package/lib/typescript/module/native/cameraEngine.d.ts +50 -0
  161. package/lib/typescript/module/native/cameraEngine.d.ts.map +1 -0
  162. package/lib/typescript/module/native/visionCameraPeer.d.ts +2 -0
  163. package/lib/typescript/module/native/visionCameraPeer.d.ts.map +1 -0
  164. package/lib/typescript/module/native/visionSurface.d.ts +41 -0
  165. package/lib/typescript/module/native/visionSurface.d.ts.map +1 -0
  166. package/lib/typescript/module/package.json +1 -0
  167. package/lib/typescript/module/permissions/permissionPort.d.ts +24 -0
  168. package/lib/typescript/module/permissions/permissionPort.d.ts.map +1 -0
  169. package/lib/typescript/module/react/CameraPreview.d.ts +25 -0
  170. package/lib/typescript/module/react/CameraPreview.d.ts.map +1 -0
  171. package/lib/typescript/module/react/VisionCameraFeed.d.ts +31 -0
  172. package/lib/typescript/module/react/VisionCameraFeed.d.ts.map +1 -0
  173. package/lib/typescript/module/react/hooks.d.ts +12 -0
  174. package/lib/typescript/module/react/hooks.d.ts.map +1 -0
  175. package/lib/typescript/module/storage/artifactStore.d.ts +54 -0
  176. package/lib/typescript/module/storage/artifactStore.d.ts.map +1 -0
  177. package/lib/typescript/module/testing/conformance.d.ts +37 -0
  178. package/lib/typescript/module/testing/conformance.d.ts.map +1 -0
  179. package/lib/typescript/module/testing/index.d.ts +12 -0
  180. package/lib/typescript/module/testing/index.d.ts.map +1 -0
  181. package/lib/typescript/module/testing/testCameraAdapter.d.ts +61 -0
  182. package/lib/typescript/module/testing/testCameraAdapter.d.ts.map +1 -0
  183. package/package.json +49 -13
  184. package/skills/sdk-rn-camera/SKILL.md +6 -3
  185. package/src/index.ts +4 -12
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * Capture guards, single-flight enforcement, and metadata assembly
5
+ * (FR-020..FR-026b).
6
+ *
7
+ * The single-flight guard rejects rather than queues or coalesces. A queue
8
+ * turns a double-tapped shutter into two photos the user never asked for, and
9
+ * coalescing hides a deliberate second capture behind an accidental one — so a
10
+ * fast, explicit `captureInProgress` error is the only option that lets the app
11
+ * decide (clarification session 2026-07-26).
12
+ */
13
+
14
+ import { known, unavailable } from "../config/types.js";
15
+ import { CameraError } from "../diagnostics/errors.js";
16
+ import { assertSupported, supportsFlashMode, supportsPosition } from "./capabilities.js";
17
+ import { canCapture } from "./sessionMachine.js";
18
+ export const DEFAULT_QUALITY = 0.9;
19
+ export function clampQuality(quality) {
20
+ if (quality === undefined || Number.isNaN(quality)) {
21
+ return DEFAULT_QUALITY;
22
+ }
23
+ return Math.min(1, Math.max(0, quality));
24
+ }
25
+ export function clampMaxDimension(maxDimension) {
26
+ if (maxDimension === undefined || !Number.isFinite(maxDimension) || maxDimension <= 0) {
27
+ return unavailable();
28
+ }
29
+ return known(Math.floor(maxDimension));
30
+ }
31
+ /**
32
+ * Validates a capture request against permission, readiness, and capability.
33
+ * Throws before any artifact could be created, so a rejected capture never
34
+ * leaves a file behind (FR-020).
35
+ */
36
+ export function assertCaptureAllowed(context, request) {
37
+ if (!context.permissionGranted) {
38
+ throw new CameraError('permissionDenied', 'Camera permission is not granted');
39
+ }
40
+ if (!canCapture(context.sessionStatus)) {
41
+ throw new CameraError('notReady', `Camera is not ready (session: ${context.sessionStatus})`);
42
+ }
43
+ const flashMode = request.flashMode ?? context.flashMode;
44
+ assertSupported(supportsFlashMode(context.capabilities, flashMode), `flash mode "${flashMode}"`);
45
+ const position = request.cameraPosition ?? context.cameraPosition;
46
+ assertSupported(supportsPosition(context.capabilities, position), `${position} camera`);
47
+ if (position !== context.cameraPosition) {
48
+ // The photo would come from the camera that is running, while the
49
+ // metadata said it came from the one that was asked for (CAM-06).
50
+ throw new CameraError('notReady', `The ${context.cameraPosition} camera is running. Call start({ cameraPosition: ` + `'${position}' }) before capturing with the ${position} camera.`);
51
+ }
52
+ }
53
+
54
+ /**
55
+ * Normalizes whatever the engine returned into the published contract, filling
56
+ * in effective hint values and marking undeterminable fields explicitly
57
+ * unavailable rather than guessing them (FR-022, FR-023).
58
+ */
59
+ export function finalizeResult(raw, request, context) {
60
+ const ownership = request.destination ? 'appOwned' : 'packageTemporary';
61
+ return {
62
+ ...raw,
63
+ ownership,
64
+ // The camera that took it, which the guard above has made the running one.
65
+ cameraPosition: raw.cameraPosition ?? context.cameraPosition,
66
+ timestamp: raw.timestamp ?? Date.now(),
67
+ effectiveQuality: raw.effectiveQuality ?? clampQuality(request.quality),
68
+ effectiveMaxDimension: raw.effectiveMaxDimension ?? clampMaxDimension(request.maxDimension),
69
+ fileSize: raw.fileSize ?? unavailable(),
70
+ orientation: raw.orientation ?? unavailable()
71
+ };
72
+ }
73
+
74
+ /**
75
+ * Serializes captures. The slot is taken synchronously, before the operation
76
+ * runs, so two calls in the same tick cannot both pass the check — and the
77
+ * operation's own first `emit()` already sees `busy`. Holding the operation's
78
+ * promise instead set the slot only after that first emit, so `capturing: true`
79
+ * was never published at all.
80
+ */
81
+ export class SingleFlight {
82
+ active = false;
83
+ get busy() {
84
+ return this.active;
85
+ }
86
+ async run(operation) {
87
+ if (this.active) {
88
+ throw new CameraError('captureInProgress', 'A capture is already in progress');
89
+ }
90
+ this.active = true;
91
+ try {
92
+ return await operation();
93
+ } finally {
94
+ this.active = false;
95
+ }
96
+ }
97
+ }
98
+ //# sourceMappingURL=captureController.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["known","unavailable","CameraError","assertSupported","supportsFlashMode","supportsPosition","canCapture","DEFAULT_QUALITY","clampQuality","quality","undefined","Number","isNaN","Math","min","max","clampMaxDimension","maxDimension","isFinite","floor","assertCaptureAllowed","context","request","permissionGranted","sessionStatus","flashMode","capabilities","position","cameraPosition","finalizeResult","raw","ownership","destination","timestamp","Date","now","effectiveQuality","effectiveMaxDimension","fileSize","orientation","SingleFlight","active","busy","run","operation"],"sourceRoot":"../../../src","sources":["core/captureController.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SACCA,KAAK,EACLC,WAAW,QAQL,oBAAiB;AACxB,SAASC,WAAW,QAAQ,0BAAuB;AAEnD,SAASC,eAAe,EAAEC,iBAAiB,EAAEC,gBAAgB,QAAQ,mBAAgB;AACrF,SAASC,UAAU,QAAQ,qBAAkB;AAE7C,OAAO,MAAMC,eAAe,GAAG,GAAG;AAElC,OAAO,SAASC,YAAYA,CAACC,OAA2B,EAAU;EACjE,IAAIA,OAAO,KAAKC,SAAS,IAAIC,M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,GAAG,KAAK;IACpB;EACD;AACD","ignoreList":[]}
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * What a camera controller is, for the app that drives it.
5
+ *
6
+ * The contract lives apart from the orchestration in `controller.ts`: it is
7
+ * what a consumer reads, and what a test double has to satisfy, while the file
8
+ * next to it is how this package happens to satisfy it.
9
+ */
10
+
11
+ export const DEFAULT_TEMPORARY_TTL_MS = 24 * 60 * 60 * 1000;
12
+ //# sourceMappingURL=contract.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["DEFAULT_TEMPORARY_TTL_MS"],"sourceRoot":"../../../src","sources":["core/contract.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;;AAkBA,OAAO,MAAMA,wBAAwB,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI","ignoreList":[]}
@@ -0,0 +1,442 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * Camera controller — the object consuming apps actually drive.
5
+ *
6
+ * It owns observable state and orchestrates the three ports (engine,
7
+ * permissions, artifact store). All I/O lives here; the decisions live in
8
+ * `sessionMachine` and `captureController`, which stay pure so they can be
9
+ * tested without a camera.
10
+ */
11
+
12
+ import { appLifecycle, createListenerSet } from '@chipmobilesdk/rn-core';
13
+ import { CameraError, isCameraError } from "../diagnostics/errors.js";
14
+ import { silentLogger, withSdkSinks } from "../diagnostics/logger.js";
15
+ import { DEFAULT_TEMPORARY_TTL_MS } from "./contract.js";
16
+ import { EMPTY_CAPABILITIES, assertSupported, supportsTorch } from "./capabilities.js";
17
+ import { SingleFlight, assertCaptureAllowed, finalizeResult } from "./captureController.js";
18
+ import { canStart, initialSession, sessionReducer } from "./sessionMachine.js";
19
+ import { createSessionRuntime } from "./sessionRuntime.js";
20
+
21
+ /** 24 hours (FR-029). */
22
+ export { DEFAULT_TEMPORARY_TTL_MS } from "./contract.js";
23
+ function defaultAppStateSubscribe(listener) {
24
+ // rn-core's one lifecycle subscription, shared with every other package; it
25
+ // requires react-native only on first subscribe (PERF-07).
26
+ return appLifecycle().subscribe(state => listener(state === 'active' ? 'active' : 'background'));
27
+ }
28
+
29
+ /** 8 s: a cold camera on a slow device, with room to spare (PERF-001 is 1.5 s). */
30
+ export const DEFAULT_START_TIMEOUT_MS = 8_000;
31
+ export function createCameraController(options) {
32
+ if (!options?.engine || !options?.permissions) {
33
+ // A configuration fault, named as one. The ports are required by the type;
34
+ // this is the answer for a JavaScript caller or a cast.
35
+ throw new CameraError('unsupportedCapability', 'createCameraController requires `engine` and `permissions` ports. Use the ' + 'default adapters, or createTestCamera() in tests.');
36
+ }
37
+ const engine = options.engine;
38
+ const permissions = options.permissions;
39
+ const store = options.store;
40
+ const logger = withSdkSinks(options.logger ?? silentLogger);
41
+ const ttlMs = options.temporaryTtlMs ?? DEFAULT_TEMPORARY_TTL_MS;
42
+ const startTimeoutMs = options.startTimeoutMs ?? DEFAULT_START_TIMEOUT_MS;
43
+ const scheduler = options.scheduler ?? {
44
+ setTimeout: (callback, ms) => setTimeout(callback, ms),
45
+ clearTimeout: handle => clearTimeout(handle)
46
+ };
47
+ let session = initialSession;
48
+ let permission = 'undetermined';
49
+ let capabilities = null;
50
+ let cameraPosition = 'back';
51
+ let flashMode = 'off';
52
+ let torchEnabled = false;
53
+ let surfaceMounted = false;
54
+ let disposed = false;
55
+ let warnedUnmanaged = false;
56
+ let detach = null;
57
+ const capture = new SingleFlight();
58
+ const listeners = createListenerSet({
59
+ onListenerError: () => logger.log({
60
+ type: 'session',
61
+ code: 'listener-threw'
62
+ })
63
+ });
64
+
65
+ /**
66
+ * The session's own I/O (`sessionRuntime`): starting it, waiting for frames,
67
+ * releasing it, following the app in and out of the foreground. It reads and
68
+ * writes the state above through this context, so one snapshot reaches
69
+ * subscribers whichever part changed it.
70
+ */
71
+ const runtime = createSessionRuntime({
72
+ engine,
73
+ logger,
74
+ startTimeoutMs,
75
+ scheduler,
76
+ session: () => session,
77
+ dispatch,
78
+ emit,
79
+ cameraPosition: () => cameraPosition,
80
+ setCameraPosition: position => {
81
+ cameraPosition = position;
82
+ },
83
+ torchEnabled: () => torchEnabled,
84
+ setTorchEnabled: enabled => {
85
+ torchEnabled = enabled;
86
+ },
87
+ surfaceMounted: () => surfaceMounted,
88
+ permissionGranted: () => permission === 'granted',
89
+ disposed: () => disposed
90
+ });
91
+ function snapshot() {
92
+ return {
93
+ session: session.status,
94
+ permission,
95
+ capabilities,
96
+ cameraPosition,
97
+ flashMode,
98
+ torchEnabled,
99
+ capturing: capture.busy,
100
+ // What the mounted preview turned out to be, once it reported: the
101
+ // format's pixel size and the orientation coordinate mapping needs.
102
+ surface: runtime.surfaceInfo(),
103
+ error: session.error ? {
104
+ code: session.error.code,
105
+ recoverable: session.error.recoverable,
106
+ message: session.error.message
107
+ } : null
108
+ };
109
+ }
110
+ let current = snapshot();
111
+ function emit() {
112
+ current = snapshot();
113
+ // Isolated: one throwing subscriber neither starves the others nor unwinds
114
+ // into the transition that emitted, which left the controller half-updated.
115
+ listeners.notify(current);
116
+ }
117
+ function dispatch(event) {
118
+ const next = sessionReducer(session, event);
119
+ if (next !== session) {
120
+ session = next;
121
+ logger.log({
122
+ type: 'session',
123
+ code: session.status,
124
+ recoverable: session.error?.recoverable
125
+ });
126
+ emit();
127
+ }
128
+ }
129
+
130
+ /**
131
+ * Subscribes to permission and app-state changes and runs the sweep, on first
132
+ * use rather than at construction. React may build a controller during a
133
+ * render it then throws away (StrictMode does so on purpose); construction
134
+ * that subscribed leaked a listener pair every time.
135
+ */
136
+ function attach() {
137
+ if (detach || disposed) {
138
+ return;
139
+ }
140
+ const unsubscribePermission = permissions.subscribe(next => {
141
+ permission = next;
142
+ logger.log({
143
+ type: 'permission',
144
+ code: next
145
+ });
146
+ emit();
147
+ // A revocation while running must tear the session down, not leave a
148
+ // frozen preview on screen (FR-007).
149
+ if (next !== 'granted') {
150
+ runtime.armResumeOnForeground();
151
+ if (session.status !== 'idle' && session.status !== 'stopped') {
152
+ runtime.release().catch(() => undefined);
153
+ }
154
+ }
155
+ });
156
+ const unsubscribeAppState = (options.subscribeToAppState ?? defaultAppStateSubscribe)(status => runtime.onAppState(status));
157
+ // The OS can take the camera at any moment — another app, an incoming
158
+ // call, a disconnected device. The session has to go with it (CAM-19).
159
+ const unsubscribeInterruptions = engine.subscribeToInterruptions?.(code => runtime.onInterruption(code)) ?? (() => undefined);
160
+ detach = () => {
161
+ unsubscribePermission();
162
+ unsubscribeAppState();
163
+ unsubscribeInterruptions();
164
+ };
165
+
166
+ // FR-029: sweep our own temp directory once, asynchronously, so it can
167
+ // never add latency to the capture path or the preview start.
168
+ if (store && options.sweepOnInit !== false) {
169
+ store.sweep(ttlMs).then(removed => {
170
+ if (removed > 0) {
171
+ logger.log({
172
+ type: 'cleanup',
173
+ code: `swept:${removed}`
174
+ });
175
+ }
176
+ }).catch(() => {
177
+ // A failed sweep must never block startup.
178
+ });
179
+ }
180
+ }
181
+
182
+ /** Entry guard for operations that need a live controller. */
183
+ function live(operation) {
184
+ if (disposed) {
185
+ throw new CameraError('notReady', `${operation}() called on a disposed camera controller`);
186
+ }
187
+ attach();
188
+ }
189
+
190
+ /**
191
+ * Puts a package-temporary capture under the store so `cleanup()` and the
192
+ * sweep can reach it. Never throws: the capture itself succeeded, and a file
193
+ * the store cannot manage is still a usable photo.
194
+ */
195
+ async function manage(image) {
196
+ if (image.ownership !== 'packageTemporary') {
197
+ return image;
198
+ }
199
+ if (store?.adopt) {
200
+ try {
201
+ return {
202
+ ...image,
203
+ uri: await store.adopt(image.uri)
204
+ };
205
+ } catch {
206
+ logger.log({
207
+ type: 'cleanup',
208
+ code: 'adopt-failed'
209
+ });
210
+ return image;
211
+ }
212
+ }
213
+ if (!store?.owns(image.uri) && !warnedUnmanaged) {
214
+ warnedUnmanaged = true;
215
+ logger.log({
216
+ type: 'cleanup',
217
+ code: store ? 'unmanaged:store-cannot-adopt' : 'unmanaged:no-store'
218
+ });
219
+ }
220
+ return image;
221
+ }
222
+ const controller = {
223
+ get state() {
224
+ return current;
225
+ },
226
+ subscribe(listener) {
227
+ if (disposed) {
228
+ return () => undefined;
229
+ }
230
+ attach();
231
+ return listeners.add(listener);
232
+ },
233
+ async getPermission() {
234
+ live('getPermission');
235
+ permission = await permissions.getStatus();
236
+ emit();
237
+ return permission;
238
+ },
239
+ async requestPermission() {
240
+ live('requestPermission');
241
+ permission = 'requesting';
242
+ emit();
243
+ try {
244
+ permission = await permissions.request();
245
+ } catch (error) {
246
+ // A native call that failed used to leave the state at `requesting`
247
+ // forever, with no way for the app to ask again (CAM-07).
248
+ permission = await permissions.getStatus().catch(() => 'unavailable');
249
+ emit();
250
+ throw isCameraError(error) ? error : new CameraError('permissionDenied', 'The permission request could not be completed');
251
+ }
252
+ emit();
253
+ return permission;
254
+ },
255
+ async start(startOptions = {}) {
256
+ live('start');
257
+ if (permission !== 'granted') {
258
+ dispatch({
259
+ type: 'FAIL',
260
+ code: 'permissionDenied'
261
+ });
262
+ throw new CameraError('permissionDenied', 'Camera permission is not granted');
263
+ }
264
+ if (!canStart(session.status)) {
265
+ throw new CameraError('sessionConflict', `Session already ${session.status}`);
266
+ }
267
+ if (startOptions.cameraPosition) {
268
+ cameraPosition = startOptions.cameraPosition;
269
+ }
270
+ dispatch({
271
+ type: 'START'
272
+ });
273
+ await runtime.start(startOptions);
274
+ if (session.error) {
275
+ throw session.error;
276
+ }
277
+ },
278
+ async pause() {
279
+ if (disposed) {
280
+ return;
281
+ }
282
+ await runtime.forceTorchOff();
283
+ dispatch({
284
+ type: 'PAUSE'
285
+ });
286
+ },
287
+ async resume() {
288
+ live('resume');
289
+ dispatch({
290
+ type: 'RESUME'
291
+ });
292
+ if (session.status === 'starting') {
293
+ await runtime.start();
294
+ }
295
+ },
296
+ async stop() {
297
+ // An explicit stop is the user's decision; foregrounding must not undo it.
298
+ runtime.armResumeOnForeground();
299
+ if (disposed) {
300
+ return;
301
+ }
302
+ await runtime.release();
303
+ },
304
+ async capture(request = {}) {
305
+ live('capture');
306
+ const context = {
307
+ engine,
308
+ sessionStatus: session.status,
309
+ permissionGranted: permission === 'granted',
310
+ capabilities,
311
+ cameraPosition,
312
+ flashMode
313
+ };
314
+ // Guards run before the single-flight slot is taken so a rejected
315
+ // request cannot block a subsequent legal one.
316
+ assertCaptureAllowed(context, request);
317
+ try {
318
+ const result = await capture.run(async () => {
319
+ emit();
320
+ const raw = await engine.capture({
321
+ ...request,
322
+ flashMode: request.flashMode ?? flashMode,
323
+ cameraPosition: request.cameraPosition ?? cameraPosition
324
+ });
325
+ return manage(finalizeResult(raw, request, context));
326
+ });
327
+ logger.log({
328
+ type: 'capture',
329
+ code: 'succeeded'
330
+ });
331
+ return result;
332
+ } catch (error) {
333
+ // The contract promises a CameraError; a raw native error carries
334
+ // no code to branch on and its message may hold a file path.
335
+ const failure = isCameraError(error) ? error : new CameraError('captureFailed', 'The camera failed to capture a photo');
336
+ logger.log({
337
+ type: 'capture',
338
+ code: failure.code,
339
+ recoverable: failure.recoverable
340
+ });
341
+ throw failure;
342
+ } finally {
343
+ // Without this a failed capture left `capturing: true` published
344
+ // until some unrelated change emitted again.
345
+ emit();
346
+ }
347
+ },
348
+ async cleanup(image) {
349
+ const uri = typeof image === 'string' ? image : image.uri;
350
+ if (!store) {
351
+ return;
352
+ }
353
+ // Refuse anything we did not create rather than deleting an arbitrary
354
+ // path, which also covers every appOwned artifact (FR-026b, FR-028).
355
+ if (!store.owns(uri)) {
356
+ logger.log({
357
+ type: 'cleanup',
358
+ code: 'refused-not-owned'
359
+ });
360
+ return;
361
+ }
362
+ await store.remove(uri);
363
+ logger.log({
364
+ type: 'cleanup',
365
+ code: 'removed'
366
+ });
367
+ },
368
+ async getCapabilities() {
369
+ live('getCapabilities');
370
+ try {
371
+ capabilities = await engine.getCapabilities();
372
+ } catch {
373
+ capabilities = EMPTY_CAPABILITIES;
374
+ }
375
+ logger.log({
376
+ type: 'capability',
377
+ code: capabilities.hasCameraHardware ? 'available' : 'no-hardware'
378
+ });
379
+ emit();
380
+ return capabilities;
381
+ },
382
+ setFlashMode(mode) {
383
+ assertSupported(mode === 'off' || capabilities?.hasFlash === true, `flash mode "${mode}"`);
384
+ flashMode = mode;
385
+ emit();
386
+ },
387
+ async setTorch(enabled) {
388
+ if (disposed && !enabled) {
389
+ return;
390
+ }
391
+ live('setTorch');
392
+ if (enabled) {
393
+ assertSupported(supportsTorch(capabilities), 'torch');
394
+ }
395
+ await engine.setTorch(enabled);
396
+ torchEnabled = enabled;
397
+ emit();
398
+ },
399
+ reportSurfaceUnavailable() {
400
+ if (disposed) {
401
+ return;
402
+ }
403
+ logger.log({
404
+ type: 'session',
405
+ code: 'surface-unavailable',
406
+ recoverable: false
407
+ });
408
+ dispatch({
409
+ type: 'FAIL',
410
+ code: 'cameraUnavailable'
411
+ });
412
+ },
413
+ attachSurface(surface) {
414
+ return engine.attachSurface?.(surface) ?? (() => undefined);
415
+ },
416
+ reportSurfaceStarted(info) {
417
+ runtime.reportSurfaceStarted(info);
418
+ },
419
+ reportSurfaceFailed(code) {
420
+ runtime.reportSurfaceFailed(code);
421
+ },
422
+ setSurfaceMounted(mounted) {
423
+ if (disposed) {
424
+ return;
425
+ }
426
+ surfaceMounted = mounted;
427
+ },
428
+ async dispose() {
429
+ if (disposed) {
430
+ return;
431
+ }
432
+ disposed = true;
433
+ runtime.armResumeOnForeground();
434
+ detach?.();
435
+ detach = null;
436
+ await runtime.release();
437
+ listeners.clear();
438
+ }
439
+ };
440
+ return controller;
441
+ }
442
+ //# sourceMappingURL=controller.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["appLifecycle","createListenerSet","CameraError","isCameraError","silentLogger","withSdkSinks","DEFAULT_TEMPORARY_TTL_MS","EMPTY_CAPABILITIES","assertSupported","supportsTorch","SingleFlight","assertCaptureAllowed","finalizeResult","canStart","initialSession","sessionReducer","createSessionRuntime","defaultAppStateSubscribe","listener","subscribe","state","DEFAULT_START_TIMEOUT_MS","createCameraController","options","engine","permissions","store","logger","ttlMs","temporaryTtlMs","startTimeoutMs","scheduler","setTimeout","callback","ms","clearTimeout","handle","session","permission","capabilities","cameraPosition","flashMode","torchEnabled","surfaceMounted","disposed","warnedUnmanaged","detach","capture","listeners","onListenerError","log","type","code","runtime","dispatch","emit","setCameraPosition","position","setTorchEnabled","enabled","permissionGranted","snapshot","status","capturing","busy","surface","surfaceInfo","error","recoverable","message","current","notify","event","next","attach","unsubscribePermission","armResumeOnForeground","release","catch","undefined","unsubscribeAppState","subscribeToAppState","onAppState","unsubscribeInterruptions","subscribeToInterruptions","onInterruption","sweepOnInit","sweep","then","removed","live","operation","manage","image","ownership","adopt","uri","owns","controller","add","getPermission","getStatus","requestPermission","request","start","startOptions","pause","forceTorchOff","resume","stop","context","sessionStatus","result","run","raw","failure","cleanup","remove","getCapabilities","hasCameraHardware","setFlashMode","mode","hasFlash","setTorch","reportSurfaceUnavailable","attachSurface","reportSurfaceStarted","info","reportSurfaceFailed","setSurfaceMounted","mounted","dispose","clear"],"sourceRoot":"../../../src","sources":["core/controller.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,YAAY,EAAEC,iBAAiB,QAAQ,wBAAwB;AAYxE,SAASC,WAAW,EAAEC,aAAa,QAAQ,0BAAuB;AAClE,SAASC,YAAY,EAAEC,YAAY,QAAQ,0BAAuB;AAElE,SACCC,wBAAwB,QAIlB,eAAY;AAEnB,SAASC,kBAAkB,EAAEC,eAAe,EAAEC,aAAa,QAAQ,mBAAgB;AACnF,SACCC,YAAY,EACZC,oBAAoB,EACpBC,cAAc,QAER,wBAAqB;AAC5B,SAASC,QAAQ,EAAEC,cAAc,EAAEC,cAAc,QAA8B,qBAAkB;AACjG,SAASC,oBAAoB,QAAQ,qBAAkB;;AAEvD;AACA,SACCV,wBAAwB,QAIlB,eAAY;AAEnB,SAASW,wBAAwBA,CAACC,QAAqC,EAAc;EACpF;EACA;EACA,OAAOlB,YAAY,CAAC,CAAC,CAACmB,SAAS,CAACC,KAAK,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