@octane-xplat/camera 0.18.0 → 0.20.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 (67) hide show
  1. package/README.md +2 -132
  2. package/package.json +108 -103
  3. package/platforms/android/java/com/octanexplat/camera/CameraPreviewView.java +24 -0
  4. package/platforms/android/java/com/octanexplat/camera/CameraSessionBridge.java +153 -21
  5. package/platforms/ios/src/XplatSwitchingMovieWriter.swift +557 -0
  6. package/src/CameraView.android.tsrx +194 -118
  7. package/src/CameraView.ios.tsrx +129 -76
  8. package/src/CameraView.macos.tsrx +108 -70
  9. package/src/CameraView.tsrx +2 -0
  10. package/src/CameraView.web.tsrx +160 -125
  11. package/src/CameraView.windows.tsrx +141 -92
  12. package/src/camera-host.macos.ts +1059 -0
  13. package/src/camera-permission.mobile.ts +85 -81
  14. package/src/camera-permission.windows.ts +56 -53
  15. package/src/camera-session.ios.ts +89 -61
  16. package/src/camera-session.macos.ts +51 -49
  17. package/src/camera-session.windows.ts +113 -105
  18. package/src/host-movie.web.ts +266 -222
  19. package/src/index.ts +28 -26
  20. package/src/index.web.ts +27 -25
  21. package/src/layout-child.ts +88 -79
  22. package/src/layout-child.web.ts +57 -51
  23. package/src/layout-child.windows.ts +82 -71
  24. package/src/movie-metadata.web.ts +87 -74
  25. package/src/movie-storage.web.ts +142 -135
  26. package/src/movie-writer.ios.ts +170 -0
  27. package/src/photo-lifecycle.macos.ts +60 -0
  28. package/src/photo-sheet.macos.ts +505 -0
  29. package/src/preview-display.ios.ts +69 -0
  30. package/src/preview-pinch.ts +41 -0
  31. package/src/preview-tap.ts +22 -21
  32. package/src/props.ts +118 -68
  33. package/src/recording-haptics.ios.ts +39 -0
  34. package/src/recording-source.web.ts +159 -0
  35. package/src/session-backend.android.ts +552 -410
  36. package/src/session-backend.ios.ts +1500 -1148
  37. package/src/session-backend.linux.ts +886 -860
  38. package/src/session-backend.macos.ts +697 -679
  39. package/src/session-backend.ts +51 -49
  40. package/src/session-backend.web.ts +1181 -867
  41. package/src/session-backend.windows.ts +1556 -1467
  42. package/src/session-core.ts +925 -711
  43. package/src/session.ts +12 -12
  44. package/src/style-merge.ts +43 -43
  45. package/src/synthetic-session.ts +392 -333
  46. package/src/types.ts +384 -239
  47. package/types/generated/.tsrx-typegen-manifest.json +18 -0
  48. package/types/generated/CameraView.d.ts +2 -0
  49. package/types/generated/CameraView.web.d.ts +4 -0
  50. package/types/generated/camera-host.macos.d.ts +33 -0
  51. package/types/generated/index.d.ts +34 -0
  52. package/types/generated/layout-child.web.d.ts +7 -0
  53. package/types/generated/photo-lifecycle.macos.d.ts +12 -0
  54. package/types/generated/photo-sheet.macos.d.ts +36 -0
  55. package/types/generated/props.d.ts +111 -0
  56. package/types/generated/session-backend.d.ts +6 -0
  57. package/types/{session-core.d.ts → generated/session-core.d.ts} +30 -1
  58. package/types/generated/session.d.ts +16 -0
  59. package/types/{synthetic-session.d.ts → generated/synthetic-session.d.ts} +15 -1
  60. package/types/{types.d.ts → generated/types.d.ts} +145 -2
  61. package/LICENSE +0 -21
  62. package/platforms/macos/src/CameraOwnership.swift +0 -22
  63. package/platforms/macos/src/PhotoCaptureLifecycle.swift +0 -34
  64. package/platforms/macos/src/XplatCameraHost.swift +0 -639
  65. package/platforms/macos/src/XplatPhotoCaptureSheet.swift +0 -192
  66. package/types/index.d.ts +0 -48
  67. package/types/props.d.ts +0 -61
@@ -1,26 +1,33 @@
1
- /** @jsxImportSource @nativescript-community/octane */
1
+ /** @jsxImportSource @octane-xplat/jsx */
2
2
  import { useImperativeHandle, useCallback, useEffect, useRef } from 'octane'
3
3
  import { View } from '@nativescript/core'
4
4
  import { registerElement } from '@nativescript-community/octane'
5
- import type { Attributes } from '@nativescript-community/octane/intrinsics'
5
+ import type { Attributes } from '@octane-xplat/jsx/intrinsics'
6
6
  import type { CameraViewProps } from './props'
7
7
  import { attachSessionPreview } from './session'
8
8
  import { cameraHardwarePresent, ensureCameraPermission } from './camera-permission.windows'
9
9
  import { startCameraPreview } from './camera-session.windows'
10
- import { applyEscapeProps, layoutChildProps, nativeAccessibilityRole, nativeAccessibilityState } from './layout-child.windows'
10
+ import {
11
+ applyEscapeProps,
12
+ layoutChildProps,
13
+ nativeAccessibilityRole,
14
+ nativeAccessibilityState,
15
+ } from './layout-child.windows'
16
+
11
17
  import { observePreviewTap } from './preview-tap'
12
18
 
13
19
  class CameraPreview extends View {
14
- createNativeView() {
15
- const { Microsoft } = globalThis as any
16
- return new Microsoft.UI.Xaml.Controls.CaptureElement()
17
- }
20
+ createNativeView() {
21
+ const { Microsoft } = globalThis as any
22
+
23
+ return new Microsoft.UI.Xaml.Controls.CaptureElement()
24
+ }
18
25
  }
19
26
 
20
- declare module '@nativescript-community/octane/intrinsics' {
21
- interface NativeScriptElements {
22
- camerapreview: Attributes<typeof CameraPreview>
23
- }
27
+ declare module '@octane-xplat/jsx/intrinsics' {
28
+ interface NativeElements<TElement> {
29
+ camerapreview: Attributes<TElement, {}>
30
+ }
24
31
  }
25
32
 
26
33
  registerElement('camerapreview', CameraPreview)
@@ -28,85 +35,127 @@ registerElement('camerapreview', CameraPreview)
28
35
  /** Live Windows preview backed by WinUI `CaptureElement` + `MediaCapture`.
29
36
  * With `session`, the preview attaches to the session-owned capture so
30
37
  * movie recording shares it; without one the view owns its capture. */
31
- export function CameraView(props: CameraViewProps) @{
32
- const host = useRef<any>(null)
33
- const active = props.active !== false
34
- const facing = props.facing ?? 'back'
35
- useImperativeHandle(props.ref, () => ({ native: host.current?.nativeViewProtected }), [])
36
-
37
- const bindHost = useCallback((view: any) => {
38
- host.current = view
39
- }, [])
40
-
41
- useEffect(() => {
42
- const view = host.current
43
- if (!view || !active) return
44
- let disposed = false
45
- let stopPreview: (() => Promise<void>) | undefined
46
- const fail = (message: string) => props.onError?.({ message })
47
-
48
- if (props.session) {
49
- if (props.facing !== undefined) {
50
- fail('camera session conflicts with facing')
51
- return
52
- }
53
-
54
- try {
55
- const detach = attachSessionPreview(props.session, view, {
56
- onReady: () => {
57
- if (!disposed) props.onReady?.()
58
- },
59
- onError: (issue) => {
60
- if (!disposed) fail(issue.message)
61
- },
62
- })
63
-
64
- return () => {
65
- disposed = true
66
- detach()
67
- }
68
- } catch (error: any) {
69
- fail(error?.message ?? 'camera session error')
70
- return
71
- }
72
- }
73
-
74
- if (!cameraHardwarePresent()) {
75
- fail('camera unsupported')
76
- return
77
- }
78
-
79
- ensureCameraPermission().then(async (granted) => {
80
- if (disposed) return
81
- if (!granted) {
82
- fail('camera permission denied')
83
- return
84
- }
85
-
86
- try {
87
- stopPreview = await startCameraPreview(view, facing, () => {
88
- if (!disposed) props.onReady?.()
89
- })
90
- } catch (error: any) {
91
- if (!disposed) fail(error?.message ?? 'camera error')
92
- }
93
- })
94
-
95
- return () => {
96
- disposed = true
97
- void stopPreview?.()
98
- }
99
- }, [active, facing, props.session])
100
-
101
- useEffect(() => {
102
- const view = host.current
103
- if (!view) return
104
- applyEscapeProps(view.nativeViewProtected, props)
105
- }, [props.ref, props.windows])
106
-
107
- useEffect(() => observePreviewTap(host.current, props.onTap), [props.onTap])
108
-
109
- <masonview id={props.id} className={['vx-layers', 'vx-cameraview', props.className]} {...layoutChildProps(props, {display: "grid", gridTemplateRows: "1fr", gridTemplateColumns: "1fr", ...({ backgroundColor: '#000', ...props.style })})} accessible={props.accessible} accessibilityLabel={props.accessibilityLabel} accessibilityRole={nativeAccessibilityRole(props.accessibilityRole) as any} accessibilityHint={props.accessibilityHint} accessibilityValue={props.accessibilityValue} accessibilityState={nativeAccessibilityState(props.accessibilityState) as any} accessibilityLiveRegion={props.accessibilityLiveRegion as any}>
110
- <camerapreview ref={bindHost} style={{gridRow: '1', gridColumn: '1'}} />
111
- </masonview>
38
+ export function CameraView(props: CameraViewProps): unknown @{
39
+ const host = useRef<any>(null)
40
+ const active = props.active !== false
41
+ const facing = props.facing ?? 'back'
42
+
43
+ useImperativeHandle(props.ref, () => ({ native: host.current?.nativeViewProtected }), [])
44
+
45
+ const bindHost = useCallback((view: any) => {
46
+ host.current = view
47
+ }, [])
48
+
49
+ useEffect(() => {
50
+ const view = host.current
51
+
52
+ if (!view || !active) {
53
+ return
54
+ }
55
+
56
+ let disposed = false
57
+ let stopPreview: (() => Promise<void>) | undefined
58
+ const fail = (message: string) => props.onError?.({ message })
59
+
60
+ if (props.session) {
61
+ if (props.facing !== undefined) {
62
+ fail('camera session conflicts with facing')
63
+ return
64
+ }
65
+
66
+ try {
67
+ const detach = attachSessionPreview(props.session, view, {
68
+ onReady: () => {
69
+ if (!disposed) {
70
+ props.onReady?.()
71
+ }
72
+ },
73
+ onDisplayReady: () => {
74
+ if (!disposed) {
75
+ props.onDisplayReady?.()
76
+ }
77
+ },
78
+ onError: (issue) => {
79
+ if (!disposed) {
80
+ fail(issue.message)
81
+ }
82
+ },
83
+ })
84
+
85
+ return () => {
86
+ disposed = true
87
+ detach()
88
+ }
89
+ } catch (error: any) {
90
+ fail(error?.message ?? 'camera session error')
91
+ return
92
+ }
93
+ }
94
+
95
+ if (!cameraHardwarePresent()) {
96
+ fail('camera unsupported')
97
+ return
98
+ }
99
+
100
+ ensureCameraPermission().then(async (granted) => {
101
+ if (disposed) {
102
+ return
103
+ }
104
+
105
+ if (!granted) {
106
+ fail('camera permission denied')
107
+ return
108
+ }
109
+
110
+ try {
111
+ stopPreview = await startCameraPreview(view, facing, () => {
112
+ if (!disposed) {
113
+ props.onReady?.()
114
+ }
115
+ })
116
+ } catch (error: any) {
117
+ if (!disposed) {
118
+ fail(error?.message ?? 'camera error')
119
+ }
120
+ }
121
+ })
122
+
123
+ return () => {
124
+ disposed = true
125
+ void stopPreview?.()
126
+ }
127
+ }, [active, facing, props.session])
128
+
129
+ useEffect(() => {
130
+ const view = host.current
131
+
132
+ if (!view) {
133
+ return
134
+ }
135
+
136
+ applyEscapeProps(view.nativeViewProtected, props)
137
+ }, [props.ref, props.windows])
138
+
139
+ useEffect(() => observePreviewTap(host.current, props.onTap), [props.onTap])
140
+
141
+ <masonview
142
+ id={props.id}
143
+ className={['vx-layers', 'vx-cameraview', props.className]}
144
+ {...layoutChildProps(props, {
145
+ display: 'grid',
146
+ gridTemplateRows: '1fr',
147
+ gridTemplateColumns: '1fr',
148
+ backgroundColor: '#000',
149
+ ...props.style,
150
+ })}
151
+ accessible={props.accessible}
152
+ accessibilityLabel={props.accessibilityLabel}
153
+ accessibilityRole={nativeAccessibilityRole(props.accessibilityRole) as any}
154
+ accessibilityHint={props.accessibilityHint}
155
+ accessibilityValue={props.accessibilityValue}
156
+ accessibilityState={nativeAccessibilityState(props.accessibilityState) as any}
157
+ accessibilityLiveRegion={props.accessibilityLiveRegion as any}
158
+ >
159
+ <camerapreview ref={bindHost} style={{ gridRow: '1', gridColumn: '1' }} />
160
+ </masonview>
112
161
  }