@symbiote-native/camera 0.0.0-stage → 0.1.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 (132) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +254 -2
  3. package/build/angular/camera-view/index.d.ts +43 -0
  4. package/build/angular/camera-view/index.js +101 -0
  5. package/build/angular/index.d.ts +3 -0
  6. package/build/angular/index.js +4 -0
  7. package/build/angular/services/camera-permissions.service.d.ts +8 -0
  8. package/build/angular/services/camera-permissions.service.js +82 -0
  9. package/build/core/android-barcode.d.ts +50 -0
  10. package/build/core/android-barcode.js +2 -0
  11. package/build/core/camera-api.d.ts +35 -0
  12. package/build/core/camera-api.js +68 -0
  13. package/build/core/camera-view-events.d.ts +3 -0
  14. package/build/core/camera-view-events.js +60 -0
  15. package/build/core/camera-view-handle.d.ts +26 -0
  16. package/build/core/camera-view-handle.js +46 -0
  17. package/build/core/camera-view.d.ts +12 -0
  18. package/build/core/camera-view.js +38 -0
  19. package/build/core/constants.d.ts +6 -0
  20. package/build/core/constants.js +7 -0
  21. package/build/core/index.d.ts +9 -0
  22. package/build/core/index.js +5 -0
  23. package/build/core/native-module.d.ts +28 -0
  24. package/build/core/native-module.js +3 -0
  25. package/build/core/picture-options.d.ts +9 -0
  26. package/build/core/picture-options.js +29 -0
  27. package/build/core/picture-ref.d.ts +2 -0
  28. package/build/core/picture-ref.js +3 -0
  29. package/build/core/props.d.ts +4 -0
  30. package/build/core/props.js +26 -0
  31. package/build/core/types.d.ts +170 -0
  32. package/build/core/types.js +1 -0
  33. package/build/react/camera-view.d.ts +8 -0
  34. package/build/react/camera-view.js +6 -0
  35. package/build/react/index.d.ts +5 -0
  36. package/build/react/index.js +4 -0
  37. package/build/react/use-camera-permissions.d.ts +9 -0
  38. package/build/react/use-camera-permissions.js +5 -0
  39. package/build/solid/camera-view.d.ts +33 -0
  40. package/build/solid/camera-view.js +4 -0
  41. package/build/solid/index.d.ts +4 -0
  42. package/build/solid/index.js +4 -0
  43. package/build/solid/use-camera-permissions.d.ts +10 -0
  44. package/build/solid/use-camera-permissions.js +5 -0
  45. package/build/svelte/camera-view.svelte +32 -0
  46. package/build/svelte/camera-view.svelte.d.ts +22 -0
  47. package/build/svelte/index.d.ts +4 -0
  48. package/build/svelte/index.js +4 -0
  49. package/build/svelte/use-camera-permissions.svelte.d.ts +9 -0
  50. package/build/svelte/use-camera-permissions.svelte.js +5 -0
  51. package/build/vue/camera-view.d.ts +2 -0
  52. package/build/vue/camera-view.js +4 -0
  53. package/build/vue/index.d.ts +4 -0
  54. package/build/vue/index.js +4 -0
  55. package/build/vue/use-camera-permissions.d.ts +10 -0
  56. package/build/vue/use-camera-permissions.js +5 -0
  57. package/build-ngc/angular/camera-view/index.d.ts +46 -0
  58. package/build-ngc/angular/camera-view/index.js +60 -0
  59. package/build-ngc/angular/camera-view/index.js.map +1 -0
  60. package/build-ngc/angular/index.d.ts +3 -0
  61. package/build-ngc/angular/index.js +5 -0
  62. package/build-ngc/angular/index.js.map +1 -0
  63. package/build-ngc/angular/services/camera-permissions.service.d.ts +13 -0
  64. package/build-ngc/angular/services/camera-permissions.service.js +28 -0
  65. package/build-ngc/angular/services/camera-permissions.service.js.map +1 -0
  66. package/build-ngc/core/android-barcode.d.ts +50 -0
  67. package/build-ngc/core/android-barcode.js +3 -0
  68. package/build-ngc/core/android-barcode.js.map +1 -0
  69. package/build-ngc/core/camera-api.d.ts +35 -0
  70. package/build-ngc/core/camera-api.js +69 -0
  71. package/build-ngc/core/camera-api.js.map +1 -0
  72. package/build-ngc/core/camera-view-events.d.ts +3 -0
  73. package/build-ngc/core/camera-view-events.js +61 -0
  74. package/build-ngc/core/camera-view-events.js.map +1 -0
  75. package/build-ngc/core/camera-view-handle.d.ts +26 -0
  76. package/build-ngc/core/camera-view-handle.js +47 -0
  77. package/build-ngc/core/camera-view-handle.js.map +1 -0
  78. package/build-ngc/core/camera-view.d.ts +12 -0
  79. package/build-ngc/core/camera-view.js +39 -0
  80. package/build-ngc/core/camera-view.js.map +1 -0
  81. package/build-ngc/core/constants.d.ts +6 -0
  82. package/build-ngc/core/constants.js +8 -0
  83. package/build-ngc/core/constants.js.map +1 -0
  84. package/build-ngc/core/index.d.ts +9 -0
  85. package/build-ngc/core/index.js +6 -0
  86. package/build-ngc/core/index.js.map +1 -0
  87. package/build-ngc/core/native-module.d.ts +28 -0
  88. package/build-ngc/core/native-module.js +4 -0
  89. package/build-ngc/core/native-module.js.map +1 -0
  90. package/build-ngc/core/picture-options.d.ts +9 -0
  91. package/build-ngc/core/picture-options.js +30 -0
  92. package/build-ngc/core/picture-options.js.map +1 -0
  93. package/build-ngc/core/picture-ref.d.ts +2 -0
  94. package/build-ngc/core/picture-ref.js +4 -0
  95. package/build-ngc/core/picture-ref.js.map +1 -0
  96. package/build-ngc/core/props.d.ts +4 -0
  97. package/build-ngc/core/props.js +27 -0
  98. package/build-ngc/core/props.js.map +1 -0
  99. package/build-ngc/core/types.d.ts +170 -0
  100. package/build-ngc/core/types.js +2 -0
  101. package/build-ngc/core/types.js.map +1 -0
  102. package/native-link.json +22 -0
  103. package/package.json +144 -3
  104. package/src/angular/camera-view/index.ts +95 -0
  105. package/src/angular/index.ts +8 -0
  106. package/src/angular/services/camera-permissions.service.ts +28 -0
  107. package/src/core/android-barcode.ts +51 -0
  108. package/src/core/camera-api.ts +99 -0
  109. package/src/core/camera-view-events.ts +108 -0
  110. package/src/core/camera-view-handle.ts +105 -0
  111. package/src/core/camera-view.ts +56 -0
  112. package/src/core/constants.ts +11 -0
  113. package/src/core/index.ts +57 -0
  114. package/src/core/native-module.ts +58 -0
  115. package/src/core/picture-options.ts +46 -0
  116. package/src/core/picture-ref.ts +4 -0
  117. package/src/core/props.ts +31 -0
  118. package/src/core/types.ts +212 -0
  119. package/src/react/camera-view.ts +17 -0
  120. package/src/react/index.ts +10 -0
  121. package/src/react/use-camera-permissions.ts +21 -0
  122. package/src/solid/camera-view.ts +9 -0
  123. package/src/solid/index.ts +9 -0
  124. package/src/solid/use-camera-permissions.ts +22 -0
  125. package/src/svelte/camera-view.svelte +32 -0
  126. package/src/svelte/index.ts +9 -0
  127. package/src/svelte/svelte-ambient.d.ts +3 -0
  128. package/src/svelte/svelte-compile.test-helper.ts +6 -0
  129. package/src/svelte/use-camera-permissions.svelte.ts +19 -0
  130. package/src/vue/camera-view.ts +8 -0
  131. package/src/vue/index.ts +9 -0
  132. package/src/vue/use-camera-permissions.ts +22 -0
@@ -0,0 +1,68 @@
1
+ import { UnavailabilityError } from 'expo-modules-core';
2
+ import { CAMERA_PACKAGE_NAME, MODERN_SCANNER_EVENT } from './constants.js';
3
+ import { expoCamera } from './native-module.js';
4
+ /** Whether the device has a camera, the permissions are a separate question */
5
+ export async function isCameraAvailableAsync() {
6
+ if (!expoCamera.isAvailableAsync) {
7
+ throw new UnavailabilityError(CAMERA_PACKAGE_NAME, 'isAvailableAsync');
8
+ }
9
+ return expoCamera.isAvailableAsync();
10
+ }
11
+ /** iOS only */
12
+ export async function getAvailableVideoCodecsAsync() {
13
+ if (!expoCamera.getAvailableVideoCodecsAsync) {
14
+ throw new UnavailabilityError('Camera', 'getAvailableVideoCodecsAsync');
15
+ }
16
+ return expoCamera.getAvailableVideoCodecsAsync();
17
+ }
18
+ /** Whether the device has `DataScannerViewController` (iOS 16+) or Google's code scanner */
19
+ export function isModernBarcodeScannerAvailable() {
20
+ return expoCamera.isModernBarcodeScannerAvailable;
21
+ }
22
+ /** A device without the modern scanner does nothing here */
23
+ export async function launchScanner(options = { barcodeTypes: [] }) {
24
+ if (expoCamera.isModernBarcodeScannerAvailable) {
25
+ await expoCamera.launchScanner(options);
26
+ }
27
+ }
28
+ /** Dismisses the scanner on iOS, on Android it closes itself after a scan */
29
+ export async function dismissScanner() {
30
+ if (expoCamera.isModernBarcodeScannerAvailable) {
31
+ await expoCamera.dismissScanner();
32
+ }
33
+ }
34
+ export function onModernBarcodeScanned(listener) {
35
+ return expoCamera.addListener(MODERN_SCANNER_EVENT, listener);
36
+ }
37
+ /** Only QR codes are scanned on iOS */
38
+ export async function scanFromURLAsync(url, barcodeTypes = ['qr']) {
39
+ return expoCamera.scanFromURLAsync(url, barcodeTypes);
40
+ }
41
+ async function getCameraPermissionsAsync() {
42
+ return expoCamera.getCameraPermissionsAsync();
43
+ }
44
+ async function requestCameraPermissionsAsync() {
45
+ return expoCamera.requestCameraPermissionsAsync();
46
+ }
47
+ async function getMicrophonePermissionsAsync() {
48
+ return expoCamera.getMicrophonePermissionsAsync();
49
+ }
50
+ async function requestMicrophonePermissionsAsync() {
51
+ return expoCamera.requestMicrophonePermissionsAsync();
52
+ }
53
+ export const Camera = {
54
+ getCameraPermissionsAsync,
55
+ requestCameraPermissionsAsync,
56
+ getMicrophonePermissionsAsync,
57
+ requestMicrophonePermissionsAsync,
58
+ scanFromURLAsync,
59
+ };
60
+ // What every adapter's `createPermissionHook` binds, `useCameraPermissions` and its twin
61
+ export const cameraPermissionMethods = {
62
+ getMethod: getCameraPermissionsAsync,
63
+ requestMethod: requestCameraPermissionsAsync,
64
+ };
65
+ export const microphonePermissionMethods = {
66
+ getMethod: getMicrophonePermissionsAsync,
67
+ requestMethod: requestMicrophonePermissionsAsync,
68
+ };
@@ -0,0 +1,3 @@
1
+ export type ICameraViewEvents = (props: object) => Record<string, unknown>;
2
+ /** One per view, the throttle of the barcode events belongs to the view */
3
+ export declare function createCameraViewEvents(): ICameraViewEvents;
@@ -0,0 +1,60 @@
1
+ import { BARCODE_EVENT_THROTTLE_MS } from './constants.js';
2
+ import { handlePictureSaved } from './picture-options.js';
3
+ function hasField(value, key, kind) {
4
+ return typeof Reflect.get(Object(value), key) === kind;
5
+ }
6
+ const isMountError = (value) => hasField(value, 'message', 'string');
7
+ const isOrientation = (value) => hasField(value, 'orientation', 'string');
8
+ const isLenses = (value) => Array.isArray(Reflect.get(Object(value), 'lenses'));
9
+ const isScanningResult = (value) => hasField(value, 'type', 'string') && hasField(value, 'data', 'string');
10
+ function isPictureSaved(value) {
11
+ return hasField(value, 'id', 'number') && hasField(value, 'data', 'object');
12
+ }
13
+ // Hands the callback the payload inside the native event, and only when it has the expected shape
14
+ function forward(props, name, isPayload) {
15
+ return (event) => {
16
+ const callback = Reflect.get(props, name);
17
+ if (typeof callback === 'function' && isPayload(event.nativeEvent)) {
18
+ callback(event.nativeEvent);
19
+ }
20
+ };
21
+ }
22
+ /** One per view, the throttle of the barcode events belongs to the view */
23
+ export function createCameraViewEvents() {
24
+ const lastScans = new Map();
25
+ // Equal events of one type inside the window are the same scan seen again
26
+ const throttledScan = (callback) => (event) => {
27
+ const result = event.nativeEvent;
28
+ if (!isScanningResult(result))
29
+ return;
30
+ const json = JSON.stringify(result);
31
+ const now = Date.now();
32
+ const last = lastScans.get(result.type);
33
+ if (last?.json === json && now - last.at < BARCODE_EVENT_THROTTLE_MS) {
34
+ return;
35
+ }
36
+ callback(result);
37
+ lastScans.set(result.type, { json, at: now });
38
+ };
39
+ return props => {
40
+ const onBarcodeScanned = Reflect.get(props, 'onBarcodeScanned');
41
+ const onCameraReady = Reflect.get(props, 'onCameraReady');
42
+ return {
43
+ onCameraReady: () => {
44
+ if (typeof onCameraReady === 'function')
45
+ onCameraReady();
46
+ },
47
+ onMountError: forward(props, 'onMountError', isMountError),
48
+ onBarcodeScanned: typeof onBarcodeScanned === 'function'
49
+ ? throttledScan(result => onBarcodeScanned(result))
50
+ : undefined,
51
+ onAvailableLensesChanged: forward(props, 'onAvailableLensesChanged', isLenses),
52
+ onResponsiveOrientationChanged: forward(props, 'onResponsiveOrientationChanged', isOrientation),
53
+ onPictureSaved: (event) => {
54
+ if (isPictureSaved(event.nativeEvent)) {
55
+ handlePictureSaved({ nativeEvent: event.nativeEvent });
56
+ }
57
+ },
58
+ };
59
+ };
60
+ }
@@ -0,0 +1,26 @@
1
+ import type { ISymbioteNode } from '@symbiote-native/engine';
2
+ import type { ICameraPictureRef } from './native-module';
3
+ import type { ICameraCapturedPicture, ICameraPictureOptions, ICameraRecordingOptions, ICameraSupportedFeatures } from './types';
4
+ export type ICameraViewHandle = {
5
+ /** Waits for `onCameraReady` first. With `pictureRef` it resolves to a native image reference */
6
+ takePictureAsync(options: ICameraPictureOptions & {
7
+ pictureRef: true;
8
+ }): Promise<ICameraPictureRef | undefined>;
9
+ takePictureAsync(options?: ICameraPictureOptions): Promise<ICameraCapturedPicture | undefined>;
10
+ /** Resolves when `stopRecording` runs, a limit is reached or the preview stops */
11
+ recordAsync(options?: ICameraRecordingOptions): Promise<{
12
+ uri: string;
13
+ } | undefined>;
14
+ /** Pauses or resumes the recording, iOS 18 and later on iOS */
15
+ toggleRecordingAsync(): Promise<void>;
16
+ stopRecording(): void;
17
+ pausePreview(): Promise<void>;
18
+ resumePreview(): Promise<void>;
19
+ getAvailablePictureSizesAsync(): Promise<string[]>;
20
+ /** Lenses exist on iOS only */
21
+ getAvailableLensesAsync(): Promise<string[]>;
22
+ getSupportedFeatures(): ICameraSupportedFeatures;
23
+ /** The host node of the mounted view, `createCameraTextureAsync` of a GL view takes it */
24
+ getHostNode(): ISymbioteNode | null;
25
+ };
26
+ export declare function createCameraViewHandle(getNode: () => ISymbioteNode | null | undefined): ICameraViewHandle;
@@ -0,0 +1,46 @@
1
+ import { Platform, requireNativeModule } from 'expo-modules-core';
2
+ import { defineExpoViewMethods, getNativeTag } from '@symbiote-native/engine';
3
+ import { CAMERA_MODULE_NAME } from './constants.js';
4
+ import { expoCamera } from './native-module.js';
5
+ import { ensurePictureOptions, ensureRecordingOptions, } from './picture-options.js';
6
+ const callViewFunction = defineExpoViewMethods(requireNativeModule, CAMERA_MODULE_NAME);
7
+ export function createCameraViewHandle(getNode) {
8
+ // Like upstream's `ref.current?.`, a view that has not committed yet answers nothing
9
+ function call(method, args = []) {
10
+ const node = getNode();
11
+ if (!node || getNativeTag(node) === undefined)
12
+ return undefined;
13
+ return callViewFunction(node, method, args);
14
+ }
15
+ async function takePictureAsync(options) {
16
+ const pictureOptions = ensurePictureOptions(options);
17
+ // The picture ref is an iOS feature, Android answers a plain picture
18
+ if (Platform.select({ ios: Boolean(options?.pictureRef), default: false })) {
19
+ return call('takePictureRef', [
20
+ pictureOptions,
21
+ ]);
22
+ }
23
+ return call('takePicture', [
24
+ pictureOptions,
25
+ ]);
26
+ }
27
+ return {
28
+ takePictureAsync,
29
+ recordAsync: async (options) => call('record', [
30
+ ensureRecordingOptions(options),
31
+ ]),
32
+ toggleRecordingAsync: async () => call('toggleRecording'),
33
+ stopRecording: () => {
34
+ call('stopRecording');
35
+ },
36
+ pausePreview: async () => call('pausePreview'),
37
+ resumePreview: async () => call('resumePreview'),
38
+ getAvailablePictureSizesAsync: async () => (await call('getAvailablePictureSizes')) ?? [],
39
+ getAvailableLensesAsync: async () => (await call('getAvailableLenses')) ?? [],
40
+ getSupportedFeatures: () => ({
41
+ isModernBarcodeScannerAvailable: expoCamera.isModernBarcodeScannerAvailable,
42
+ toggleRecordingAsyncAvailable: expoCamera.toggleRecordingAsyncAvailable,
43
+ }),
44
+ getHostNode: () => getNode() ?? null,
45
+ };
46
+ }
@@ -0,0 +1,12 @@
1
+ import type { IDescriptor } from '@symbiote-native/components';
2
+ import type { ISymbioteNode } from '@symbiote-native/engine';
3
+ import type { ICameraViewHandle } from './camera-view-handle';
4
+ export declare const cameraViewName: () => string;
5
+ export declare const ensureCameraViewRegistered: () => boolean;
6
+ export type ICameraView = {
7
+ handle: ICameraViewHandle;
8
+ /** `null` means the view cannot register and the caller renders nothing */
9
+ render(props: object): IDescriptor | null;
10
+ };
11
+ /** One per mounted view, `getNode` answers the host node once it exists */
12
+ export declare function createCameraView(getNode: () => ISymbioteNode | null | undefined): ICameraView;
@@ -0,0 +1,38 @@
1
+ // Ядро `CameraView`: нативный view камеры, чьи функции вызываются через `ViewPrototypes`
2
+ import { requireNativeViewManager } from 'expo-modules-core';
3
+ import { el } from '@symbiote-native/components';
4
+ import { defineExpoNativeView, isDevBuild } from '@symbiote-native/engine';
5
+ import { createCameraViewEvents } from './camera-view-events.js';
6
+ import { createCameraViewHandle } from './camera-view-handle.js';
7
+ import { CAMERA_MODULE_NAME } from './constants.js';
8
+ import { ensureNativeProps } from './props.js';
9
+ // Регистрация идёт при рендере: побочный эффект барреля теряется в release
10
+ const cameraView = defineExpoNativeView(requireNativeViewManager, CAMERA_MODULE_NAME);
11
+ export const cameraViewName = cameraView.name;
12
+ export const ensureCameraViewRegistered = cameraView.ensureRegistered;
13
+ // What upstream's `defaultProps` gave the class component
14
+ const DEFAULT_VIEW_PROPS = {
15
+ zoom: 0,
16
+ facing: 'back',
17
+ enableTorch: false,
18
+ mode: 'picture',
19
+ flash: 'off',
20
+ };
21
+ /** One per mounted view, `getNode` answers the host node once it exists */
22
+ export function createCameraView(getNode) {
23
+ const toEvents = createCameraViewEvents();
24
+ return {
25
+ handle: createCameraViewHandle(getNode),
26
+ render: props => {
27
+ if (!ensureCameraViewRegistered()) {
28
+ if (isDevBuild())
29
+ console.warn("'CameraView' is not available.");
30
+ return null;
31
+ }
32
+ return el(cameraViewName(), {
33
+ ...ensureNativeProps({ ...DEFAULT_VIEW_PROPS, ...props }),
34
+ ...toEvents(props),
35
+ });
36
+ },
37
+ };
38
+ }
@@ -0,0 +1,6 @@
1
+ export declare const CAMERA_MODULE_NAME = "ExpoCamera";
2
+ /** The label upstream puts into its `UnavailabilityError` */
3
+ export declare const CAMERA_PACKAGE_NAME = "expo-camera";
4
+ /** Equal barcode events of one type inside this window are dropped */
5
+ export declare const BARCODE_EVENT_THROTTLE_MS = 500;
6
+ export declare const MODERN_SCANNER_EVENT = "onModernBarcodeScanned";
@@ -0,0 +1,7 @@
1
+ // Apart from `native-module`, which resolves the module on import: the view needs the name too
2
+ export const CAMERA_MODULE_NAME = 'ExpoCamera';
3
+ /** The label upstream puts into its `UnavailabilityError` */
4
+ export const CAMERA_PACKAGE_NAME = 'expo-camera';
5
+ /** Equal barcode events of one type inside this window are dropped */
6
+ export const BARCODE_EVENT_THROTTLE_MS = 500;
7
+ export const MODERN_SCANNER_EVENT = 'onModernBarcodeScanned';
@@ -0,0 +1,9 @@
1
+ export { Camera, cameraPermissionMethods, dismissScanner, getAvailableVideoCodecsAsync, isCameraAvailableAsync, isModernBarcodeScannerAvailable, launchScanner, microphonePermissionMethods, onModernBarcodeScanned, scanFromURLAsync, } from './camera-api';
2
+ export { cameraViewName, createCameraView, ensureCameraViewRegistered, type ICameraView, } from './camera-view';
3
+ export type { ICameraViewHandle } from './camera-view-handle';
4
+ export { CAMERA_MODULE_NAME } from './constants';
5
+ export type { ICameraPictureRef } from './native-module';
6
+ export { PictureRef } from './picture-ref';
7
+ export type { IAndroidBarcode } from './android-barcode';
8
+ export type { ICameraAvailableLenses, ICameraBarcodeBounds, ICameraBarcodePoint, ICameraBarcodeScanningResult, ICameraBarcodeSettings, ICameraBarcodeType, ICameraCapturedPicture, ICameraFlashMode, ICameraFocusMode, ICameraMode, ICameraMountError, ICameraOrientation, ICameraPhotoResult, ICameraPictureOptions, ICameraRatio, ICameraRecordingOptions, ICameraResponsiveOrientation, ICameraSavePictureOptions, ICameraScanningOptions, ICameraScanningResult, ICameraSupportedFeatures, ICameraType, ICameraVideoCodec, ICameraVideoQuality, ICameraVideoStabilization, ICameraViewProps, } from './types';
9
+ export { PermissionStatus, type EventSubscription, type PermissionExpiration, type PermissionResponse, } from 'expo-modules-core';
@@ -0,0 +1,5 @@
1
+ export { Camera, cameraPermissionMethods, dismissScanner, getAvailableVideoCodecsAsync, isCameraAvailableAsync, isModernBarcodeScannerAvailable, launchScanner, microphonePermissionMethods, onModernBarcodeScanned, scanFromURLAsync, } from './camera-api.js';
2
+ export { cameraViewName, createCameraView, ensureCameraViewRegistered, } from './camera-view.js';
3
+ export { CAMERA_MODULE_NAME } from './constants.js';
4
+ export { PictureRef } from './picture-ref.js';
5
+ export { PermissionStatus, } from 'expo-modules-core';
@@ -0,0 +1,28 @@
1
+ import type { EventSubscription, PermissionResponse, SharedRef } from 'expo-modules-core';
2
+ import type { ICameraBarcodeScanningResult, ICameraBarcodeType, ICameraPhotoResult, ICameraSavePictureOptions, ICameraScanningOptions, ICameraScanningResult, ICameraVideoCodec } from './types';
3
+ /** A reference to a native instance of an image, other Expo packages accept it as is */
4
+ export type ICameraPictureRef = SharedRef<'image'> & {
5
+ width: number;
6
+ height: number;
7
+ /** Saves the image into the cache directory */
8
+ savePictureAsync(options?: ICameraSavePictureOptions): Promise<ICameraPhotoResult>;
9
+ };
10
+ export type ICameraPictureRefClass = abstract new (...args: never[]) => ICameraPictureRef;
11
+ export type ICameraNativeModule = {
12
+ Picture: ICameraPictureRefClass;
13
+ readonly isModernBarcodeScannerAvailable: boolean;
14
+ readonly toggleRecordingAsyncAvailable: boolean;
15
+ readonly Type: Record<string, string>;
16
+ readonly FlashMode: Record<string, string>;
17
+ isAvailableAsync?(): Promise<boolean>;
18
+ launchScanner(options?: ICameraScanningOptions): Promise<void>;
19
+ dismissScanner(): Promise<void>;
20
+ scanFromURLAsync(url: string, barcodeTypes?: ICameraBarcodeType[]): Promise<ICameraBarcodeScanningResult[]>;
21
+ getCameraPermissionsAsync(): Promise<PermissionResponse>;
22
+ requestCameraPermissionsAsync(): Promise<PermissionResponse>;
23
+ getMicrophonePermissionsAsync(): Promise<PermissionResponse>;
24
+ requestMicrophonePermissionsAsync(): Promise<PermissionResponse>;
25
+ getAvailableVideoCodecsAsync?(): Promise<ICameraVideoCodec[]>;
26
+ addListener(eventName: string, listener: (event: ICameraScanningResult) => void): EventSubscription;
27
+ };
28
+ export declare const expoCamera: ICameraNativeModule;
@@ -0,0 +1,3 @@
1
+ import { requireNativeModule } from 'expo-modules-core';
2
+ import { CAMERA_MODULE_NAME } from './constants.js';
3
+ export const expoCamera = requireNativeModule(CAMERA_MODULE_NAME);
@@ -0,0 +1,9 @@
1
+ import type { ICameraCapturedPicture, ICameraPictureOptions, ICameraRecordingOptions } from './types';
2
+ export declare function ensurePictureOptions(options?: ICameraPictureOptions): ICameraPictureOptions;
3
+ export declare function ensureRecordingOptions(options?: ICameraRecordingOptions): ICameraRecordingOptions;
4
+ export declare function handlePictureSaved({ nativeEvent, }: {
5
+ nativeEvent: {
6
+ data: ICameraCapturedPicture;
7
+ id: number;
8
+ };
9
+ }): void;
@@ -0,0 +1,29 @@
1
+ const MIRROR_DEPRECATED = 'The `mirror` option is deprecated. Please use the `mirror` prop on the `CameraView` instead.';
2
+ // The callbacks wait here for the native event that carries their picture
3
+ const pictureSavedCallbacks = new Map();
4
+ let nextPictureId = 1;
5
+ export function ensurePictureOptions(options) {
6
+ if (!options || typeof options !== 'object')
7
+ return {};
8
+ if (options.mirror)
9
+ console.warn(MIRROR_DEPRECATED);
10
+ const { onPictureSaved, ...rest } = options;
11
+ const withQuality = { ...rest, quality: options.quality ?? 1 };
12
+ if (!onPictureSaved)
13
+ return withQuality;
14
+ const id = nextPictureId++;
15
+ pictureSavedCallbacks.set(id, onPictureSaved);
16
+ return { ...withQuality, id, fastMode: true };
17
+ }
18
+ export function ensureRecordingOptions(options = {}) {
19
+ if (options.mirror)
20
+ console.warn(MIRROR_DEPRECATED);
21
+ return options;
22
+ }
23
+ export function handlePictureSaved({ nativeEvent, }) {
24
+ const callback = pictureSavedCallbacks.get(nativeEvent.id);
25
+ if (!callback)
26
+ return;
27
+ pictureSavedCallbacks.delete(nativeEvent.id);
28
+ callback(nativeEvent.data);
29
+ }
@@ -0,0 +1,2 @@
1
+ /** The native image class, `takePictureAsync({ pictureRef: true })` resolves to an instance */
2
+ export declare const PictureRef: import("./native-module").ICameraPictureRefClass;
@@ -0,0 +1,3 @@
1
+ import { expoCamera } from './native-module.js';
2
+ /** The native image class, `takePictureAsync({ pictureRef: true })` resolves to an instance */
3
+ export const PictureRef = expoCamera.Picture;
@@ -0,0 +1,4 @@
1
+ type INativeProps = Record<string, unknown>;
2
+ /** The props the native view takes, built from the friendly ones of the view */
3
+ export declare function ensureNativeProps(props: object): INativeProps;
4
+ export {};
@@ -0,0 +1,26 @@
1
+ import { expoCamera } from './native-module.js';
2
+ // Values under these keys become native options, the tables come from the native module
3
+ function conversionTableFor(key) {
4
+ if (key === 'type')
5
+ return expoCamera.Type;
6
+ if (key === 'flash')
7
+ return expoCamera.FlashMode;
8
+ return undefined;
9
+ }
10
+ function convertNativeProps(props) {
11
+ return Object.fromEntries(Object.entries(props).map(([key, value]) => {
12
+ const table = conversionTableFor(key);
13
+ return [key, typeof value === 'string' && table ? table[value] : value];
14
+ }));
15
+ }
16
+ /** The props the native view takes, built from the friendly ones of the view */
17
+ export function ensureNativeProps(props) {
18
+ const { poster: _poster, ...native } = convertNativeProps(props);
19
+ return {
20
+ ...native,
21
+ barcodeScannerEnabled: Boolean(Reflect.get(props, 'onBarcodeScanned')),
22
+ flashMode: Reflect.get(props, 'flash') ?? 'off',
23
+ mute: Reflect.get(props, 'mute') ?? false,
24
+ autoFocus: Reflect.get(props, 'autofocus') ?? 'off',
25
+ };
26
+ }
@@ -0,0 +1,170 @@
1
+ import type { IAccessibilityProps, IAriaProps, IResponderProps } from '@symbiote-native/components';
2
+ import type { IStyleProp, ISymbioteEvent, IViewStyle } from '@symbiote-native/engine';
3
+ import type { IAndroidBarcode } from './android-barcode';
4
+ export type ICameraType = 'front' | 'back';
5
+ /**
6
+ * `screen` uses the display as the flash of a front camera, on iOS it maps to `on`
7
+ * and Retina Flash fires
8
+ */
9
+ export type ICameraFlashMode = 'off' | 'on' | 'auto' | 'screen';
10
+ /** `on` focuses once and locks, `off` focuses whenever needed */
11
+ export type ICameraFocusMode = 'on' | 'off';
12
+ export type ICameraMode = 'picture' | 'video';
13
+ export type ICameraRatio = '4:3' | '16:9' | '1:1';
14
+ /** The codec of a video recording, iOS only */
15
+ export type ICameraVideoCodec = 'avc1' | 'hvc1' | 'jpeg' | 'apcn' | 'ap4h';
16
+ /** On Android all but `off` turn the stabilization on, the device picks the method */
17
+ export type ICameraVideoStabilization = 'off' | 'standard' | 'cinematic' | 'auto';
18
+ export type ICameraVideoQuality = '2160p' | '1080p' | '720p' | '480p' | '4:3';
19
+ export type ICameraOrientation = 'portrait' | 'portraitUpsideDown' | 'landscapeLeft' | 'landscapeRight';
20
+ export type ICameraBarcodeType = 'aztec' | 'ean13' | 'ean8' | 'qr' | 'pdf417' | 'upc_e' | 'datamatrix' | 'code39' | 'code93' | 'itf14' | 'codabar' | 'code128' | 'upc_a';
21
+ export type ICameraCapturedPicture = {
22
+ width: number;
23
+ height: number;
24
+ format: 'jpg' | 'png';
25
+ uri: string;
26
+ /** Base64 of the JPEG data, present when the `base64` option was set */
27
+ base64?: string;
28
+ /** The EXIF tags and their values, present when the `exif` option was set */
29
+ exif?: Record<string, unknown>;
30
+ };
31
+ export type ICameraPictureOptions = {
32
+ /** From `0` (small) to `1` (best), `1` by default */
33
+ quality?: number;
34
+ base64?: boolean;
35
+ exif?: boolean;
36
+ /** Extra EXIF data, takes effect with `exif` */
37
+ additionalExif?: Record<string, unknown>;
38
+ /**
39
+ * Called when the picture is saved, the promise then resolves at once with no data
40
+ * and the picture goes to this callback
41
+ */
42
+ onPictureSaved?: (picture: ICameraCapturedPicture) => void;
43
+ /** Returns the image as it came from the sensor, `quality` is discarded */
44
+ skipProcessing?: boolean;
45
+ /** @deprecated Use the `mirror` prop of the view */
46
+ mirror?: boolean;
47
+ id?: number;
48
+ fastMode?: boolean;
49
+ maxDownsampling?: number;
50
+ /** `true` by default */
51
+ shutterSound?: boolean;
52
+ /** Resolves to a reference to the native image instead of a file */
53
+ pictureRef?: boolean;
54
+ };
55
+ export type ICameraRecordingOptions = {
56
+ /** In seconds */
57
+ maxDuration?: number;
58
+ /** In bytes */
59
+ maxFileSize?: number;
60
+ /** @deprecated Use the `mirror` prop of the view */
61
+ mirror?: boolean;
62
+ /** iOS only */
63
+ codec?: ICameraVideoCodec;
64
+ };
65
+ export type ICameraAvailableLenses = {
66
+ lenses: string[];
67
+ };
68
+ export type ICameraResponsiveOrientation = {
69
+ orientation: ICameraOrientation;
70
+ };
71
+ export type ICameraMountError = {
72
+ message: string;
73
+ };
74
+ export type ICameraBarcodePoint = {
75
+ x: number;
76
+ y: number;
77
+ };
78
+ export type ICameraBarcodeBounds = {
79
+ origin: ICameraBarcodePoint;
80
+ size: {
81
+ height: number;
82
+ width: number;
83
+ };
84
+ };
85
+ export type ICameraBarcodeScanningResult = {
86
+ type: string;
87
+ /** The parsed information encoded in the barcode */
88
+ data: string;
89
+ /** The raw information, Android only */
90
+ raw?: string;
91
+ /** The order of the points differs per platform, and is empty for some types */
92
+ cornerPoints: ICameraBarcodePoint[];
93
+ bounds: ICameraBarcodeBounds;
94
+ /** Extra information of the type of barcode, Android only */
95
+ extra?: IAndroidBarcode;
96
+ };
97
+ export type ICameraScanningResult = Omit<ICameraBarcodeScanningResult, 'bounds' | 'cornerPoints'>;
98
+ export type ICameraBarcodeSettings = {
99
+ barcodeTypes: ICameraBarcodeType[];
100
+ };
101
+ /** The options of the system scanner, iOS 16+ and Google's code scanner on Android */
102
+ export type ICameraScanningOptions = {
103
+ barcodeTypes: ICameraBarcodeType[];
104
+ /** iOS only, `true` by default */
105
+ isPinchToZoomEnabled?: boolean;
106
+ /** iOS only, `true` by default */
107
+ isGuidanceEnabled?: boolean;
108
+ /** iOS only, `false` by default */
109
+ isHighlightingEnabled?: boolean;
110
+ };
111
+ export type ICameraPhotoResult = {
112
+ uri: string;
113
+ width: number;
114
+ height: number;
115
+ base64?: string;
116
+ };
117
+ export type ICameraSavePictureOptions = {
118
+ quality?: number;
119
+ metadata?: Record<string, unknown>;
120
+ base64?: boolean;
121
+ };
122
+ export type ICameraViewProps = IAccessibilityProps & IAriaProps & IResponderProps & {
123
+ /** `back` by default */
124
+ facing?: ICameraType;
125
+ /** `off` by default */
126
+ flash?: ICameraFlashMode;
127
+ /** From `0` to `1`, a share of the maximum zoom of the device */
128
+ zoom?: number;
129
+ /** `picture` by default */
130
+ mode?: ICameraMode;
131
+ /** Records video with no sound */
132
+ mute?: boolean;
133
+ /** Mirrors the image of the front camera */
134
+ mirror?: boolean;
135
+ /** iOS only, `off` by default */
136
+ autofocus?: ICameraFocusMode;
137
+ /** Stops the session while `false`, iOS only, `true` by default */
138
+ active?: boolean;
139
+ videoQuality?: ICameraVideoQuality;
140
+ /** In bits per second, on iOS needs the codec in `recordAsync` */
141
+ videoBitrate?: number;
142
+ animateShutter?: boolean;
143
+ /** Makes `ratio` ignored, the sizes come from `getAvailablePictureSizesAsync` */
144
+ pictureSize?: string;
145
+ /** iOS only, `builtInWideAngleCamera` by default */
146
+ selectedLens?: string;
147
+ enableTorch?: boolean;
148
+ /** `auto` by default */
149
+ videoStabilizationMode?: ICameraVideoStabilization;
150
+ barcodeScannerSettings?: ICameraBarcodeSettings;
151
+ /** Takes landscape pictures of a portrait-locked app when the device turns, iOS only */
152
+ responsiveOrientationWhenOrientationLocked?: boolean;
153
+ /** Android only, switches the preview from fill to fit */
154
+ ratio?: ICameraRatio;
155
+ onCameraReady?: () => void;
156
+ onMountError?: (event: ICameraMountError) => void;
157
+ onBarcodeScanned?: (result: ICameraBarcodeScanningResult) => void;
158
+ /** iOS only */
159
+ onResponsiveOrientationChanged?: (event: ICameraResponsiveOrientation) => void;
160
+ /** iOS only */
161
+ onAvailableLensesChanged?: (event: ICameraAvailableLenses) => void;
162
+ style?: IStyleProp<IViewStyle>;
163
+ testID?: string;
164
+ nativeID?: string;
165
+ onLayout?: (event: ISymbioteEvent) => void;
166
+ };
167
+ export type ICameraSupportedFeatures = {
168
+ isModernBarcodeScannerAvailable: boolean;
169
+ toggleRecordingAsyncAvailable: boolean;
170
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,8 @@
1
+ import type { ReactElement, Ref } from 'react';
2
+ import type { ICameraViewHandle, ICameraViewProps } from '../core';
3
+ export type ICameraViewReactProps = ICameraViewProps & {
4
+ ref?: Ref<ICameraViewHandle>;
5
+ className?: string;
6
+ };
7
+ /** React twin of `expo-camera`'s `CameraView` */
8
+ export declare function CameraView({ ref, ...props }: ICameraViewReactProps): ReactElement | null;
@@ -0,0 +1,6 @@
1
+ import { useNativeViewController } from '@symbiote-native/react';
2
+ import { createCameraView } from '../core/index.js';
3
+ /** React twin of `expo-camera`'s `CameraView` */
4
+ export function CameraView({ ref, ...props }) {
5
+ return useNativeViewController(ref, createCameraView, props);
6
+ }
@@ -0,0 +1,5 @@
1
+ export { CameraView } from './camera-view';
2
+ export type { ICameraViewReactProps } from './camera-view';
3
+ export { useCameraPermissions, useMicrophonePermissions, } from './use-camera-permissions';
4
+ export type { IUseCameraPermissionsHook } from './use-camera-permissions';
5
+ export * from '../core';
@@ -0,0 +1,4 @@
1
+ // @symbiote-native/camera/react: камера, съёмка, запись видео и сканирование кодов на общем ядре
2
+ export { CameraView } from './camera-view.js';
3
+ export { useCameraPermissions, useMicrophonePermissions, } from './use-camera-permissions.js';
4
+ export * from '../core/index.js';
@@ -0,0 +1,9 @@
1
+ import type { IPermissionHookBehavior } from '@symbiote-native/engine';
2
+ import type { PermissionResponse } from 'expo-modules-core';
3
+ export type IUseCameraPermissionsHook = (options?: IPermissionHookBehavior) => [
4
+ PermissionResponse | null,
5
+ () => Promise<PermissionResponse>,
6
+ () => Promise<PermissionResponse>
7
+ ];
8
+ export declare const useCameraPermissions: IUseCameraPermissionsHook;
9
+ export declare const useMicrophonePermissions: IUseCameraPermissionsHook;
@@ -0,0 +1,5 @@
1
+ import { createPermissionHook } from '@symbiote-native/react';
2
+ import { cameraPermissionMethods, microphonePermissionMethods, } from '../core/camera-api.js';
3
+ // React twin of `expo-camera`'s permission hooks
4
+ export const useCameraPermissions = createPermissionHook(cameraPermissionMethods);
5
+ export const useMicrophonePermissions = createPermissionHook(microphonePermissionMethods);