@ng-native/desktop 0.0.0 → 0.24.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 (401) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +52 -0
  3. package/app.plugin.cjs +17 -0
  4. package/bin/app-config.mjs +168 -0
  5. package/bin/autolink.mjs +224 -0
  6. package/bin/cli.mjs +158 -0
  7. package/bin/host.mjs +427 -0
  8. package/bin/ng-native-desktop.mjs +4 -0
  9. package/bin/package.mjs +971 -0
  10. package/bin/plist.mjs +68 -0
  11. package/bin/prebuilt.mjs +328 -0
  12. package/bin/toolchain.mjs +192 -0
  13. package/native/CMakeLists.txt +277 -0
  14. package/native/appkit/CMakeLists.txt +130 -0
  15. package/native/appkit/address-search.h +26 -0
  16. package/native/appkit/address-search.mm +277 -0
  17. package/native/appkit/animation-frames.h +14 -0
  18. package/native/appkit/animation-frames.mm +106 -0
  19. package/native/appkit/app-info.h +12 -0
  20. package/native/appkit/app-info.mm +98 -0
  21. package/native/appkit/app-updater.mm +128 -0
  22. package/native/appkit/app-windows.h +81 -0
  23. package/native/appkit/app-windows.mm +318 -0
  24. package/native/appkit/appkit-backend.h +73 -0
  25. package/native/appkit/appkit-backend.mm +276 -0
  26. package/native/appkit/apple-authentication.h +19 -0
  27. package/native/appkit/apple-authentication.mm +248 -0
  28. package/native/appkit/apple-button-view.h +10 -0
  29. package/native/appkit/apple-button-view.mm +37 -0
  30. package/native/appkit/apple-id-button.h +16 -0
  31. package/native/appkit/apple-id-button.mm +50 -0
  32. package/native/appkit/audio.h +16 -0
  33. package/native/appkit/audio.mm +275 -0
  34. package/native/appkit/battery.h +13 -0
  35. package/native/appkit/battery.mm +92 -0
  36. package/native/appkit/bookmarks.h +17 -0
  37. package/native/appkit/bookmarks.mm +145 -0
  38. package/native/appkit/calendar.h +25 -0
  39. package/native/appkit/calendar.mm +660 -0
  40. package/native/appkit/camera-sheet.h +59 -0
  41. package/native/appkit/camera-sheet.mm +344 -0
  42. package/native/appkit/camera-view.h +15 -0
  43. package/native/appkit/camera-view.mm +134 -0
  44. package/native/appkit/camera.h +61 -0
  45. package/native/appkit/camera.mm +496 -0
  46. package/native/appkit/cg-canvas.h +24 -0
  47. package/native/appkit/cg-canvas.mm +663 -0
  48. package/native/appkit/component-view.h +17 -0
  49. package/native/appkit/crypto.h +19 -0
  50. package/native/appkit/crypto.mm +78 -0
  51. package/native/appkit/desktop-expo.h +29 -0
  52. package/native/appkit/desktop-expo.mm +385 -0
  53. package/native/appkit/expo-image-drawing.h +46 -0
  54. package/native/appkit/expo-image-drawing.mm +131 -0
  55. package/native/appkit/expo-image-view.h +15 -0
  56. package/native/appkit/expo-image-view.mm +182 -0
  57. package/native/appkit/expo-ui-renderer.h +68 -0
  58. package/native/appkit/expo-ui-renderer.mm +101 -0
  59. package/native/appkit/expo-ui-view.h +26 -0
  60. package/native/appkit/expo-ui-view.mm +134 -0
  61. package/native/appkit/expo-ui.swift +1284 -0
  62. package/native/appkit/file-system.h +16 -0
  63. package/native/appkit/file-system.mm +140 -0
  64. package/native/appkit/fonts.h +12 -0
  65. package/native/appkit/fonts.mm +48 -0
  66. package/native/appkit/geocoder.h +19 -0
  67. package/native/appkit/geocoder.mm +101 -0
  68. package/native/appkit/glass-effect.h +22 -0
  69. package/native/appkit/glass-effect.mm +63 -0
  70. package/native/appkit/glass-view.h +8 -0
  71. package/native/appkit/glass-view.mm +65 -0
  72. package/native/appkit/header-toolbar.h +60 -0
  73. package/native/appkit/header-toolbar.mm +632 -0
  74. package/native/appkit/host-view.h +54 -0
  75. package/native/appkit/host-view.mm +1228 -0
  76. package/native/appkit/image-manipulator.h +14 -0
  77. package/native/appkit/image-manipulator.mm +191 -0
  78. package/native/appkit/image-request.h +22 -0
  79. package/native/appkit/image-request.mm +62 -0
  80. package/native/appkit/image-view.h +8 -0
  81. package/native/appkit/image-view.mm +142 -0
  82. package/native/appkit/input-replay.h +25 -0
  83. package/native/appkit/input-replay.mm +418 -0
  84. package/native/appkit/language-model.h +14 -0
  85. package/native/appkit/language-model.mm +99 -0
  86. package/native/appkit/language-model.swift +472 -0
  87. package/native/appkit/local-authentication.h +15 -0
  88. package/native/appkit/local-authentication.mm +133 -0
  89. package/native/appkit/location.h +16 -0
  90. package/native/appkit/location.mm +214 -0
  91. package/native/appkit/main.mm +1475 -0
  92. package/native/appkit/map-view.h +15 -0
  93. package/native/appkit/map-view.mm +109 -0
  94. package/native/appkit/maps.h +35 -0
  95. package/native/appkit/maps.mm +343 -0
  96. package/native/appkit/menu-bar.h +22 -0
  97. package/native/appkit/menu-bar.mm +208 -0
  98. package/native/appkit/modal-focus.h +16 -0
  99. package/native/appkit/modal-focus.mm +26 -0
  100. package/native/appkit/modal-host-view.h +79 -0
  101. package/native/appkit/modal-host-view.mm +442 -0
  102. package/native/appkit/native-controls.h +22 -0
  103. package/native/appkit/native-controls.mm +431 -0
  104. package/native/appkit/network-state.h +12 -0
  105. package/native/appkit/network-state.mm +64 -0
  106. package/native/appkit/network.h +14 -0
  107. package/native/appkit/network.mm +396 -0
  108. package/native/appkit/notifications.h +19 -0
  109. package/native/appkit/notifications.mm +309 -0
  110. package/native/appkit/photo-library.h +33 -0
  111. package/native/appkit/photo-library.mm +548 -0
  112. package/native/appkit/pointer-buttons.h +32 -0
  113. package/native/appkit/presentation-label.h +15 -0
  114. package/native/appkit/presentation-label.mm +12 -0
  115. package/native/appkit/presented-screen.h +19 -0
  116. package/native/appkit/presented-screen.mm +181 -0
  117. package/native/appkit/printing.h +42 -0
  118. package/native/appkit/printing.mm +393 -0
  119. package/native/appkit/push.h +19 -0
  120. package/native/appkit/push.mm +81 -0
  121. package/native/appkit/red-box.h +26 -0
  122. package/native/appkit/red-box.mm +387 -0
  123. package/native/appkit/screen-capture.h +21 -0
  124. package/native/appkit/screen-capture.mm +92 -0
  125. package/native/appkit/scroll-view.h +13 -0
  126. package/native/appkit/scroll-view.mm +251 -0
  127. package/native/appkit/scrollers.h +25 -0
  128. package/native/appkit/scrollers.mm +43 -0
  129. package/native/appkit/search-field.h +34 -0
  130. package/native/appkit/search-field.mm +291 -0
  131. package/native/appkit/search-toolbar-item.h +19 -0
  132. package/native/appkit/search-toolbar-item.mm +269 -0
  133. package/native/appkit/share-picker.h +34 -0
  134. package/native/appkit/share-picker.mm +121 -0
  135. package/native/appkit/split-view.h +77 -0
  136. package/native/appkit/split-view.mm +1206 -0
  137. package/native/appkit/store-review.h +13 -0
  138. package/native/appkit/store-review.mm +28 -0
  139. package/native/appkit/surface-view.h +45 -0
  140. package/native/appkit/surface-view.mm +562 -0
  141. package/native/appkit/svg-view.h +18 -0
  142. package/native/appkit/svg-view.mm +103 -0
  143. package/native/appkit/symbol-drawing.h +24 -0
  144. package/native/appkit/symbol-drawing.mm +117 -0
  145. package/native/appkit/symbol-view.h +8 -0
  146. package/native/appkit/symbol-view.mm +33 -0
  147. package/native/appkit/system-access.h +34 -0
  148. package/native/appkit/system-access.mm +210 -0
  149. package/native/appkit/system.h +24 -0
  150. package/native/appkit/system.mm +403 -0
  151. package/native/appkit/tab-walk.h +31 -0
  152. package/native/appkit/tab-walk.mm +64 -0
  153. package/native/appkit/test-launch.h +36 -0
  154. package/native/appkit/test-launch.mm +115 -0
  155. package/native/appkit/text-input-field.h +81 -0
  156. package/native/appkit/text-input-field.mm +525 -0
  157. package/native/appkit/text-layout.h +58 -0
  158. package/native/appkit/text-layout.mm +485 -0
  159. package/native/appkit/text-recognition.h +13 -0
  160. package/native/appkit/text-recognition.mm +102 -0
  161. package/native/appkit/tracking.h +13 -0
  162. package/native/appkit/tracking.mm +51 -0
  163. package/native/appkit/tray-and-dock.h +45 -0
  164. package/native/appkit/tray-and-dock.mm +130 -0
  165. package/native/appkit/undo.h +23 -0
  166. package/native/appkit/undo.mm +125 -0
  167. package/native/appkit/updates.h +17 -0
  168. package/native/appkit/updates.mm +71 -0
  169. package/native/appkit/video-view.h +10 -0
  170. package/native/appkit/video-view.mm +42 -0
  171. package/native/appkit/video.h +38 -0
  172. package/native/appkit/video.mm +404 -0
  173. package/native/appkit/web-browser.h +12 -0
  174. package/native/appkit/web-browser.mm +97 -0
  175. package/native/appkit/web-view-component.h +10 -0
  176. package/native/appkit/web-view-component.mm +62 -0
  177. package/native/appkit/web-view.h +31 -0
  178. package/native/appkit/web-view.mm +401 -0
  179. package/native/cmake/libraries/react-native-reanimated.cmake +45 -0
  180. package/native/cmake/libraries/react-native-worklets.cmake +46 -0
  181. package/native/cmake/libraries.cmake +109 -0
  182. package/native/cmake/linked-modules.cmake +112 -0
  183. package/native/cmake/react-native.cmake +175 -0
  184. package/native/cmake/runtime-dependencies.cmake +34 -0
  185. package/native/cmake/swift.cmake +43 -0
  186. package/native/cmake/third-party.cmake +74 -0
  187. package/native/core/include/ngn/absent-views.h +27 -0
  188. package/native/core/include/ngn/accessibility.h +140 -0
  189. package/native/core/include/ngn/address-search.h +69 -0
  190. package/native/core/include/ngn/animation-frames.h +39 -0
  191. package/native/core/include/ngn/app-info.h +52 -0
  192. package/native/core/include/ngn/app-menus.h +151 -0
  193. package/native/core/include/ngn/app-windows.h +181 -0
  194. package/native/core/include/ngn/apple-authentication.h +116 -0
  195. package/native/core/include/ngn/asset.h +28 -0
  196. package/native/core/include/ngn/audio.h +125 -0
  197. package/native/core/include/ngn/back-swipe.h +121 -0
  198. package/native/core/include/ngn/battery.h +48 -0
  199. package/native/core/include/ngn/bytes.h +59 -0
  200. package/native/core/include/ngn/calendar.h +180 -0
  201. package/native/core/include/ngn/camera.h +222 -0
  202. package/native/core/include/ngn/control-sizes.h +111 -0
  203. package/native/core/include/ngn/core-modules.h +108 -0
  204. package/native/core/include/ngn/crypto.h +38 -0
  205. package/native/core/include/ngn/default-menu.h +91 -0
  206. package/native/core/include/ngn/desktop-expo.h +193 -0
  207. package/native/core/include/ngn/desktop-modal.h +109 -0
  208. package/native/core/include/ngn/desktop-props.h +75 -0
  209. package/native/core/include/ngn/desktop-view-props.h +110 -0
  210. package/native/core/include/ngn/dev-server.h +33 -0
  211. package/native/core/include/ngn/dom-web-view.h +53 -0
  212. package/native/core/include/ngn/download.h +24 -0
  213. package/native/core/include/ngn/expo-image.h +192 -0
  214. package/native/core/include/ngn/expo-ui.h +133 -0
  215. package/native/core/include/ngn/file-system.h +274 -0
  216. package/native/core/include/ngn/focus-order.h +63 -0
  217. package/native/core/include/ngn/fonts.h +64 -0
  218. package/native/core/include/ngn/gestures.h +305 -0
  219. package/native/core/include/ngn/glass.h +67 -0
  220. package/native/core/include/ngn/header-bar.h +112 -0
  221. package/native/core/include/ngn/host-state.h +243 -0
  222. package/native/core/include/ngn/image-manipulator.h +70 -0
  223. package/native/core/include/ngn/input-dispatcher.h +211 -0
  224. package/native/core/include/ngn/input-script.h +56 -0
  225. package/native/core/include/ngn/input.h +112 -0
  226. package/native/core/include/ngn/key-value-store.h +41 -0
  227. package/native/core/include/ngn/language-model.h +69 -0
  228. package/native/core/include/ngn/launch-frame.h +47 -0
  229. package/native/core/include/ngn/launch-settings.h +98 -0
  230. package/native/core/include/ngn/layout-animations.h +24 -0
  231. package/native/core/include/ngn/library-components.h +13 -0
  232. package/native/core/include/ngn/library-glue.h +53 -0
  233. package/native/core/include/ngn/live-regions.h +54 -0
  234. package/native/core/include/ngn/local-authentication.h +74 -0
  235. package/native/core/include/ngn/location.h +89 -0
  236. package/native/core/include/ngn/maps.h +226 -0
  237. package/native/core/include/ngn/module-registry.h +51 -0
  238. package/native/core/include/ngn/mounting-backend.h +96 -0
  239. package/native/core/include/ngn/mounting-manager.h +155 -0
  240. package/native/core/include/ngn/native-controls.h +161 -0
  241. package/native/core/include/ngn/native-module.h +109 -0
  242. package/native/core/include/ngn/network-state.h +44 -0
  243. package/native/core/include/ngn/network.h +100 -0
  244. package/native/core/include/ngn/notifications.h +185 -0
  245. package/native/core/include/ngn/photo-library.h +134 -0
  246. package/native/core/include/ngn/printing.h +69 -0
  247. package/native/core/include/ngn/processes.h +114 -0
  248. package/native/core/include/ngn/red-box.h +119 -0
  249. package/native/core/include/ngn/reload-thread.h +258 -0
  250. package/native/core/include/ngn/runtime.h +163 -0
  251. package/native/core/include/ngn/safe-areas.h +82 -0
  252. package/native/core/include/ngn/screen-capture.h +35 -0
  253. package/native/core/include/ngn/screen-presentation.h +85 -0
  254. package/native/core/include/ngn/screen-stacks.h +80 -0
  255. package/native/core/include/ngn/scrollers.h +106 -0
  256. package/native/core/include/ngn/sharing.h +39 -0
  257. package/native/core/include/ngn/spawn-rules.h +78 -0
  258. package/native/core/include/ngn/splash-screen.h +41 -0
  259. package/native/core/include/ngn/split-view.h +270 -0
  260. package/native/core/include/ngn/sqlite.h +38 -0
  261. package/native/core/include/ngn/store-review.h +26 -0
  262. package/native/core/include/ngn/surface-book.h +101 -0
  263. package/native/core/include/ngn/surface-metrics.h +51 -0
  264. package/native/core/include/ngn/svg.h +434 -0
  265. package/native/core/include/ngn/symbol.h +90 -0
  266. package/native/core/include/ngn/system.h +102 -0
  267. package/native/core/include/ngn/tabs-host.h +171 -0
  268. package/native/core/include/ngn/text-input.h +134 -0
  269. package/native/core/include/ngn/text-measurer.h +38 -0
  270. package/native/core/include/ngn/text-recognition.h +55 -0
  271. package/native/core/include/ngn/tracking.h +34 -0
  272. package/native/core/include/ngn/tray-and-dock.h +107 -0
  273. package/native/core/include/ngn/undo.h +37 -0
  274. package/native/core/include/ngn/updates.h +253 -0
  275. package/native/core/include/ngn/video.h +126 -0
  276. package/native/core/include/ngn/view-box.h +126 -0
  277. package/native/core/include/ngn/view-transform.h +26 -0
  278. package/native/core/include/ngn/view-tree.h +85 -0
  279. package/native/core/include/ngn/web-browser.h +45 -0
  280. package/native/core/include/ngn/web-view.h +137 -0
  281. package/native/core/include/ngn/worklet-host.h +98 -0
  282. package/native/core/src/absent-views.cpp +41 -0
  283. package/native/core/src/accessibility.cpp +374 -0
  284. package/native/core/src/animation-frames.cpp +49 -0
  285. package/native/core/src/app-menus.cpp +359 -0
  286. package/native/core/src/app-windows.cpp +444 -0
  287. package/native/core/src/back-swipe.cpp +98 -0
  288. package/native/core/src/bytes.cpp +158 -0
  289. package/native/core/src/control-sizes.cpp +232 -0
  290. package/native/core/src/default-menu.cpp +96 -0
  291. package/native/core/src/desktop-modal.cpp +162 -0
  292. package/native/core/src/desktop-view-props.cpp +80 -0
  293. package/native/core/src/dev-server-helper.cpp +152 -0
  294. package/native/core/src/dev-server.cpp +103 -0
  295. package/native/core/src/dom-web-view.cpp +45 -0
  296. package/native/core/src/download.cpp +53 -0
  297. package/native/core/src/expo-image.cpp +548 -0
  298. package/native/core/src/expo-ui.cpp +203 -0
  299. package/native/core/src/focus-order.cpp +441 -0
  300. package/native/core/src/gestures.cpp +1806 -0
  301. package/native/core/src/glass.cpp +49 -0
  302. package/native/core/src/header-bar.cpp +104 -0
  303. package/native/core/src/host-services.cpp +50 -0
  304. package/native/core/src/host-state.cpp +61 -0
  305. package/native/core/src/input-dispatcher.cpp +727 -0
  306. package/native/core/src/input-script.cpp +123 -0
  307. package/native/core/src/key-value-store.cpp +169 -0
  308. package/native/core/src/launch-settings.cpp +148 -0
  309. package/native/core/src/layout-animations.cpp +62 -0
  310. package/native/core/src/libraries/RNCWebViewSpec.cpp +80 -0
  311. package/native/core/src/libraries/react-native-reanimated.cpp +216 -0
  312. package/native/core/src/libraries/react-native-worklets.cpp +192 -0
  313. package/native/core/src/libraries/rnscreens.cpp +125 -0
  314. package/native/core/src/libraries/rnsvg.cpp +358 -0
  315. package/native/core/src/libraries/safeareacontext.cpp +70 -0
  316. package/native/core/src/libraries/worklets-idle-frames.js +70 -0
  317. package/native/core/src/library-glue.cpp +35 -0
  318. package/native/core/src/live-regions.cpp +122 -0
  319. package/native/core/src/module-registry.cpp +50 -0
  320. package/native/core/src/modules/accessibility-manager.cpp +98 -0
  321. package/native/core/src/modules/address-search.cpp +219 -0
  322. package/native/core/src/modules/alert-manager.cpp +140 -0
  323. package/native/core/src/modules/app-info.cpp +74 -0
  324. package/native/core/src/modules/app-modules.cpp +412 -0
  325. package/native/core/src/modules/apple-authentication.cpp +188 -0
  326. package/native/core/src/modules/asset.cpp +111 -0
  327. package/native/core/src/modules/async-storage.cpp +192 -0
  328. package/native/core/src/modules/audio.cpp +541 -0
  329. package/native/core/src/modules/battery.cpp +88 -0
  330. package/native/core/src/modules/calendar.cpp +457 -0
  331. package/native/core/src/modules/camera.cpp +401 -0
  332. package/native/core/src/modules/core-modules.cpp +62 -0
  333. package/native/core/src/modules/crypto.cpp +117 -0
  334. package/native/core/src/modules/desktop-expo.cpp +527 -0
  335. package/native/core/src/modules/file-system.cpp +941 -0
  336. package/native/core/src/modules/fonts.cpp +163 -0
  337. package/native/core/src/modules/image-loader.cpp +105 -0
  338. package/native/core/src/modules/image-manipulator.cpp +305 -0
  339. package/native/core/src/modules/language-model.cpp +195 -0
  340. package/native/core/src/modules/local-authentication.cpp +140 -0
  341. package/native/core/src/modules/location.cpp +186 -0
  342. package/native/core/src/modules/maps.cpp +500 -0
  343. package/native/core/src/modules/network-state.cpp +72 -0
  344. package/native/core/src/modules/networking.cpp +387 -0
  345. package/native/core/src/modules/notifications.cpp +549 -0
  346. package/native/core/src/modules/photo-library.cpp +385 -0
  347. package/native/core/src/modules/printing.cpp +201 -0
  348. package/native/core/src/modules/screen-capture.cpp +71 -0
  349. package/native/core/src/modules/sharing.cpp +59 -0
  350. package/native/core/src/modules/splash-screen.cpp +70 -0
  351. package/native/core/src/modules/sqlite.cpp +421 -0
  352. package/native/core/src/modules/store-review.cpp +23 -0
  353. package/native/core/src/modules/text-recognition.cpp +107 -0
  354. package/native/core/src/modules/tracking.cpp +46 -0
  355. package/native/core/src/modules/undo.cpp +59 -0
  356. package/native/core/src/modules/video.cpp +366 -0
  357. package/native/core/src/modules/web-browser.cpp +100 -0
  358. package/native/core/src/modules/web-socket.cpp +266 -0
  359. package/native/core/src/mounting-manager.cpp +384 -0
  360. package/native/core/src/native-controls.cpp +129 -0
  361. package/native/core/src/native-module.cpp +250 -0
  362. package/native/core/src/network.cpp +219 -0
  363. package/native/core/src/posix-launcher.cpp +366 -0
  364. package/native/core/src/processes.cpp +324 -0
  365. package/native/core/src/red-box-errors.js +83 -0
  366. package/native/core/src/red-box.cpp +306 -0
  367. package/native/core/src/runtime.cpp +420 -0
  368. package/native/core/src/safe-areas.cpp +137 -0
  369. package/native/core/src/screen-presentation.cpp +61 -0
  370. package/native/core/src/screen-stacks.cpp +254 -0
  371. package/native/core/src/scrollers.cpp +181 -0
  372. package/native/core/src/spawn-rules.cpp +292 -0
  373. package/native/core/src/split-view.cpp +343 -0
  374. package/native/core/src/svg.cpp +2190 -0
  375. package/native/core/src/symbol.cpp +94 -0
  376. package/native/core/src/tabs-host.cpp +234 -0
  377. package/native/core/src/text-input.cpp +139 -0
  378. package/native/core/src/text-layout-manager.cpp +63 -0
  379. package/native/core/src/tray-and-dock.cpp +154 -0
  380. package/native/core/src/updates.cpp +965 -0
  381. package/native/core/src/view-box.cpp +788 -0
  382. package/native/core/src/view-transform.cpp +45 -0
  383. package/native/core/src/view-tree.cpp +234 -0
  384. package/native/core/src/web-view.cpp +143 -0
  385. package/native/core/src/worklet-host.cpp +10 -0
  386. package/native/scripts/build-hermes.sh +44 -0
  387. package/native/scripts/build.sh +175 -0
  388. package/native/scripts/cache-dir.sh +18 -0
  389. package/native/scripts/codegen-library.sh +193 -0
  390. package/native/scripts/compiler-launcher.sh +17 -0
  391. package/native/scripts/fetch.sh +174 -0
  392. package/native/scripts/hermes-built.sh +10 -0
  393. package/native/scripts/host-dir.sh +16 -0
  394. package/native/scripts/launch-probe.sh +60 -0
  395. package/native/scripts/macos-target.sh +8 -0
  396. package/native/scripts/make-prebuilt.mjs +360 -0
  397. package/native/scripts/prebuilt-host-cache.mjs +158 -0
  398. package/native/shim/openssl/sha.h +22 -0
  399. package/native/shim/view-platform/react/renderer/components/view/HostPlatformViewTraitsInitializer.h +37 -0
  400. package/package.json +73 -1
  401. package/prebuilt.json +33 -0
@@ -0,0 +1,496 @@
1
+ #import "camera.h"
2
+
3
+ #import <ImageIO/ImageIO.h>
4
+
5
+ #include <atomic>
6
+ #include <cmath>
7
+ #include <optional>
8
+
9
+ // Answers one photo capture: its image and the camera's metadata, or why there is none.
10
+ @interface NGNPhotoCapture : NSObject <AVCapturePhotoCaptureDelegate>
11
+ - (instancetype)initWithDone:(ngn::appkit::PhotoDone)done;
12
+ // Answers that no photo is coming, for a capture the output refused.
13
+ - (void)abandon:(const char *)reason;
14
+ @end
15
+
16
+ @implementation NGNPhotoCapture {
17
+ ngn::appkit::PhotoDone _done;
18
+ NGNPhotoCapture *_keep;
19
+ }
20
+
21
+ - (instancetype)initWithDone:(ngn::appkit::PhotoDone)done {
22
+ if ((self = [super init])) {
23
+ _done = std::move(done);
24
+ _keep = self;
25
+ }
26
+ return self;
27
+ }
28
+
29
+ - (void)abandon:(const char *)reason {
30
+ auto done = std::move(_done);
31
+ _keep = nil;
32
+ if (done) {
33
+ done(nullptr, nil, reason);
34
+ }
35
+ }
36
+
37
+ - (void)captureOutput:(AVCapturePhotoOutput *)output didFinishProcessingPhoto:(AVCapturePhoto *)photo error:(NSError *)error {
38
+ auto done = std::move(_done);
39
+ _keep = nil;
40
+ CGImageRef image = error == nil ? photo.CGImageRepresentation : nullptr;
41
+ if (image == nullptr) {
42
+ done(nullptr, nil, error != nil ? error.localizedDescription.UTF8String : "the camera gave no picture");
43
+ return;
44
+ }
45
+ // macOS has no AVCapturePhoto.metadata: the photo's own file carries it.
46
+ NSDictionary *metadata = nil;
47
+ if (NSData *data = photo.fileDataRepresentation) {
48
+ if (CGImageSourceRef source = CGImageSourceCreateWithData((__bridge CFDataRef)data, nullptr)) {
49
+ metadata = CFBridgingRelease(CGImageSourceCopyPropertiesAtIndex(source, 0, nullptr));
50
+ CFRelease(source);
51
+ }
52
+ }
53
+ done(image, metadata, "");
54
+ }
55
+
56
+ @end
57
+
58
+ // Answers one movie recording once its file is finished. A recording a limit ended is finished
59
+ // well: AVFoundation reports it as an error that says so.
60
+ @interface NGNMovieRecording : NSObject <AVCaptureFileOutputRecordingDelegate>
61
+ - (instancetype)initWithDone:(std::function<void(const std::string &)>)done;
62
+ @end
63
+
64
+ @implementation NGNMovieRecording {
65
+ std::function<void(const std::string &)> _done;
66
+ // The movie output does not keep its delegate, so it keeps itself until the recording ends.
67
+ NGNMovieRecording *_keep;
68
+ }
69
+
70
+ - (instancetype)initWithDone:(std::function<void(const std::string &)>)done {
71
+ if ((self = [super init])) {
72
+ _done = std::move(done);
73
+ _keep = self;
74
+ }
75
+ return self;
76
+ }
77
+
78
+ - (void)captureOutput:(AVCaptureFileOutput *)output
79
+ didFinishRecordingToOutputFileAtURL:(NSURL *)url
80
+ fromConnections:(NSArray<AVCaptureConnection *> *)connections
81
+ error:(NSError *)error {
82
+ bool finished = error == nil || [error.userInfo[AVErrorRecordingSuccessfullyFinishedKey] boolValue];
83
+ auto done = std::move(_done);
84
+ _keep = nil;
85
+ if (done) {
86
+ const char *reason = error.localizedDescription.UTF8String;
87
+ done(finished ? "" : (reason != nullptr ? reason : "the recording failed"));
88
+ }
89
+ }
90
+
91
+ @end
92
+
93
+ namespace ngn::appkit {
94
+
95
+ namespace {
96
+
97
+ using Access = CameraHardware::Access;
98
+
99
+ Access accessOf(AVAuthorizationStatus status) {
100
+ switch (status) {
101
+ case AVAuthorizationStatusAuthorized: return Access::Granted;
102
+ case AVAuthorizationStatusDenied: return Access::Denied;
103
+ case AVAuthorizationStatusRestricted: return Access::Restricted;
104
+ default: return Access::NotDetermined;
105
+ }
106
+ }
107
+
108
+ // Whether the app's Info.plist says why it asks: without the string the OS ends the app.
109
+ bool explains() {
110
+ id reason = NSBundle.mainBundle.infoDictionary[@"NSCameraUsageDescription"];
111
+ return [reason isKindOfClass:NSString.class] && [reason length] > 0;
112
+ }
113
+
114
+ NSArray<AVCaptureDevice *> *cameras() {
115
+ NSMutableArray<AVCaptureDeviceType> *types = [NSMutableArray arrayWithObject:AVCaptureDeviceTypeBuiltInWideAngleCamera];
116
+ if (@available(macOS 14.0, *)) {
117
+ [types addObject:AVCaptureDeviceTypeExternal];
118
+ [types addObject:AVCaptureDeviceTypeContinuityCamera];
119
+ }
120
+ return [AVCaptureDeviceDiscoverySession discoverySessionWithDeviceTypes:types
121
+ mediaType:AVMediaTypeVideo
122
+ position:AVCaptureDevicePositionUnspecified]
123
+ .devices;
124
+ }
125
+
126
+ class AVHardware final : public CameraHardware {
127
+ public:
128
+ Access access() override {
129
+ return accessOf([AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo]);
130
+ }
131
+ void requestAccess(std::function<void(Access)> done) override {
132
+ if (!explains() || access() != Access::NotDetermined) {
133
+ done(access());
134
+ return;
135
+ }
136
+ auto answer = std::make_shared<std::function<void(Access)>>(std::move(done));
137
+ [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo
138
+ completionHandler:^(BOOL granted) { (*answer)(granted ? Access::Granted : Access::Denied); }];
139
+ }
140
+ bool hasCamera() override {
141
+ return cameraFor("front") != nil;
142
+ }
143
+ bool microphoneAllowed() override {
144
+ return [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeAudio] == AVAuthorizationStatusAuthorized &&
145
+ [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeAudio] != nil;
146
+ }
147
+ };
148
+
149
+ // The codec expo-camera names, if AVFoundation has it.
150
+ AVVideoCodecType codecOf(const std::string &name) {
151
+ if (name == "hvc1") return AVVideoCodecTypeHEVC;
152
+ if (name == "avc1") return AVVideoCodecTypeH264;
153
+ if (name == "jpeg") return AVVideoCodecTypeJPEG;
154
+ if (name == "apcn") return AVVideoCodecTypeAppleProRes422;
155
+ if (name == "ap4h") return AVVideoCodecTypeAppleProRes4444;
156
+ return nil;
157
+ }
158
+
159
+ // The session preset a recording request names (CameraRecordingRequest::preset).
160
+ AVCaptureSessionPreset presetOf(const std::string &name) {
161
+ if (name == "Medium") return AVCaptureSessionPresetMedium;
162
+ if (name == "Low") return AVCaptureSessionPresetLow;
163
+ if (name == "640x480") return AVCaptureSessionPreset640x480;
164
+ if (name == "iFrame1280x720") return AVCaptureSessionPresetiFrame1280x720;
165
+ if (name == "iFrame960x540") return AVCaptureSessionPresetiFrame960x540;
166
+ return AVCaptureSessionPresetHigh;
167
+ }
168
+
169
+ // A session set up to record: the movie output and microphone added to it, and the preset it had
170
+ // before. Only touched on the session's queue.
171
+ struct RecordingSetup {
172
+ AVCaptureMovieFileOutput *movie{nil};
173
+ AVCaptureDeviceInput *microphone{nil};
174
+ NSString *before{nil};
175
+ std::string preset;
176
+ bool sound{false};
177
+ };
178
+
179
+ // Takes the setup off the session and puts its preset back.
180
+ void takeDown(AVCaptureSession *session, std::optional<RecordingSetup> &setup) {
181
+ if (!setup) {
182
+ return;
183
+ }
184
+ [session beginConfiguration];
185
+ if (setup->movie != nil) {
186
+ [session removeOutput:setup->movie];
187
+ }
188
+ if (setup->microphone != nil) {
189
+ [session removeInput:setup->microphone];
190
+ }
191
+ if ([session canSetSessionPreset:setup->before]) {
192
+ session.sessionPreset = setup->before;
193
+ }
194
+ [session commitConfiguration];
195
+ setup.reset();
196
+ }
197
+
198
+ // Sets the session up for `request`, unless it already is.
199
+ void setUp(AVCaptureSession *session, const CameraRecordingRequest &request, std::optional<RecordingSetup> &setup) {
200
+ if (setup && setup->preset == request.preset && setup->sound == request.sound) {
201
+ return;
202
+ }
203
+ takeDown(session, setup);
204
+ RecordingSetup made{.before = session.sessionPreset, .preset = request.preset, .sound = request.sound};
205
+ [session beginConfiguration];
206
+ // The preset asked for, or High when this camera has no such preset.
207
+ AVCaptureSessionPreset recordAt = presetOf(request.preset);
208
+ if (![session canSetSessionPreset:recordAt]) {
209
+ recordAt = AVCaptureSessionPresetHigh;
210
+ }
211
+ if ([session canSetSessionPreset:recordAt]) {
212
+ session.sessionPreset = recordAt;
213
+ }
214
+ // Never without the microphone allowed: a microphone input in a session asks for it.
215
+ if (request.sound && [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeAudio] == AVAuthorizationStatusAuthorized) {
216
+ AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeAudio];
217
+ AVCaptureDeviceInput *microphone = device != nil ? [AVCaptureDeviceInput deviceInputWithDevice:device error:nil] : nil;
218
+ if (microphone != nil && [session canAddInput:microphone]) {
219
+ [session addInput:microphone];
220
+ made.microphone = microphone;
221
+ }
222
+ }
223
+ AVCaptureMovieFileOutput *movie = [AVCaptureMovieFileOutput new];
224
+ if ([session canAddOutput:movie]) {
225
+ [session addOutput:movie];
226
+ made.movie = movie;
227
+ }
228
+ [session commitConfiguration];
229
+ setup = made;
230
+ }
231
+
232
+ class AVSessionCapture final : public SessionCapture {
233
+ public:
234
+ AVSessionCapture(AVCaptureSession *session, AVCapturePhotoOutput *output)
235
+ : session_(session), output_(output), queue_(dispatch_queue_create("ngn.camera.session", DISPATCH_QUEUE_SERIAL)) {}
236
+ ~AVSessionCapture() override {
237
+ stop();
238
+ }
239
+ AVCaptureSession *session() const override {
240
+ return session_;
241
+ }
242
+ void start(std::function<void()> running) override {
243
+ AVCaptureSession *session = session_;
244
+ auto ready = std::make_shared<std::function<void()>>(std::move(running));
245
+ dispatch_async(queue_, ^{
246
+ [session startRunning];
247
+ dispatch_async(dispatch_get_main_queue(), ^{
248
+ if (*ready) {
249
+ (*ready)();
250
+ }
251
+ });
252
+ });
253
+ }
254
+ void stop() override {
255
+ stopRecording();
256
+ // The block holds the session, so it stops after this capture has gone.
257
+ AVCaptureSession *session = session_;
258
+ dispatch_async(queue_, ^{
259
+ if (session.running) {
260
+ [session stopRunning];
261
+ }
262
+ });
263
+ }
264
+
265
+ // Reconfiguring a running session restarts the camera's stream, which takes it a moment, so a
266
+ // recording set up only as it starts begins late.
267
+ void prepareRecording(const CameraRecordingRequest &asked) override {
268
+ CameraRecordingRequest request = asked;
269
+ AVCaptureSession *session = session_;
270
+ auto setup = setup_;
271
+ auto recording = recording_;
272
+ dispatch_async(queue_, ^{
273
+ if (!recording->load()) {
274
+ setUp(session, request, *setup);
275
+ }
276
+ });
277
+ }
278
+ void unprepareRecording() override {
279
+ AVCaptureSession *session = session_;
280
+ auto setup = setup_;
281
+ auto recording = recording_;
282
+ dispatch_async(queue_, ^{
283
+ if (!recording->load()) {
284
+ takeDown(session, *setup);
285
+ }
286
+ });
287
+ }
288
+
289
+ // The movie output and, with sound, the microphone are on the session for the recording (added
290
+ // now unless prepareRecording added them) and taken off after it, on the session's queue, since
291
+ // configuring a running session blocks.
292
+ void startRecording(const CameraRecordingRequest &asked, std::function<void(const std::string &)> done) override {
293
+ // The block runs later on the session's queue: a reference it captured would be to the
294
+ // caller's request, gone by then.
295
+ CameraRecordingRequest request = asked;
296
+ if (!session_.running) {
297
+ done("the camera is not running");
298
+ return;
299
+ }
300
+ if (recording_->exchange(true)) {
301
+ done("a recording is already in progress");
302
+ return;
303
+ }
304
+ AVCaptureSession *session = session_;
305
+ auto recording = recording_;
306
+ auto movieHolder = movie_;
307
+ auto setup = setup_;
308
+ auto answer = std::make_shared<std::function<void(const std::string &)>>(std::move(done));
309
+ dispatch_queue_t queue = queue_;
310
+ dispatch_async(queue_, ^{
311
+ setUp(session, request, *setup);
312
+ AVCaptureMovieFileOutput *movie = (*setup)->movie;
313
+ void (^finished)(void) = ^{
314
+ takeDown(session, *setup);
315
+ *movieHolder = nil;
316
+ recording->store(false);
317
+ };
318
+ AVCaptureConnection *video = movie != nil ? [movie connectionWithMediaType:AVMediaTypeVideo] : nil;
319
+ if (video == nil || !video.active || !video.enabled) {
320
+ finished();
321
+ (*answer)("the camera gives no video to record");
322
+ return;
323
+ }
324
+ // The movie is never mirrored, as on iOS, whatever its preview shows.
325
+ if (video.isVideoMirroringSupported) {
326
+ video.automaticallyAdjustsVideoMirroring = NO;
327
+ video.videoMirrored = NO;
328
+ }
329
+ // A codec this Mac cannot write is refused by an exception; the default stays.
330
+ if (AVVideoCodecType codec = codecOf(request.codec)) {
331
+ @try {
332
+ [movie setOutputSettings:@{AVVideoCodecKey : codec} forConnection:video];
333
+ } @catch (NSException *) {
334
+ }
335
+ }
336
+ movie.maxRecordedDuration = request.maxDuration > 0 ? CMTimeMakeWithSeconds(request.maxDuration, 600) : kCMTimeInvalid;
337
+ movie.maxRecordedFileSize = static_cast<int64_t>(request.maxFileSize);
338
+ NSURL *url = [NSURL fileURLWithPath:@(request.path.c_str())];
339
+ [NSFileManager.defaultManager removeItemAtURL:url error:nil];
340
+ *movieHolder = movie;
341
+ // The answer follows the take-down, so a recording asked for at once finds none running.
342
+ NGNMovieRecording *delegate = [[NGNMovieRecording alloc] initWithDone:[answer, finished, queue](const std::string &error) {
343
+ std::string message = error;
344
+ dispatch_async(queue, ^{
345
+ finished();
346
+ (*answer)(message);
347
+ });
348
+ }];
349
+ [movie startRecordingToOutputFileURL:url recordingDelegate:delegate];
350
+ });
351
+ }
352
+
353
+ void stopRecording() override {
354
+ auto movieHolder = movie_;
355
+ dispatch_async(queue_, ^{
356
+ [*movieHolder stopRecording];
357
+ });
358
+ }
359
+
360
+ bool recording() const override {
361
+ return recording_->load();
362
+ }
363
+ void capturePhoto(PhotoDone done) override {
364
+ if (!session_.running) {
365
+ done(nullptr, nil, "the camera is not running");
366
+ return;
367
+ }
368
+ // On the session's queue, after any change to the session queued before it (a recording's setup
369
+ // coming down), which a still taken mid-change would find with no video to take.
370
+ auto answer = std::make_shared<PhotoDone>(std::move(done));
371
+ AVCaptureSession *session = session_;
372
+ AVCapturePhotoOutput *output = output_;
373
+ dispatch_async(queue_, ^{
374
+ if (!session.running) {
375
+ (*answer)(nullptr, nil, "the camera is not running");
376
+ return;
377
+ }
378
+ NGNPhotoCapture *capture = [[NGNPhotoCapture alloc] initWithDone:*answer];
379
+ @try {
380
+ [output capturePhotoWithSettings:[AVCapturePhotoSettings photoSettings] delegate:capture];
381
+ } @catch (NSException *exception) {
382
+ // The output refuses with no active video connection; the delegate never hears.
383
+ const char *reason = exception.reason.UTF8String;
384
+ [capture abandon:reason != nullptr ? reason : "the camera gave no picture"];
385
+ }
386
+ });
387
+ }
388
+
389
+ private:
390
+ AVCaptureSession *session_;
391
+ AVCapturePhotoOutput *output_;
392
+ dispatch_queue_t queue_;
393
+ // Shared with the blocks on the queue, which can outlive the capture: whether a recording runs,
394
+ // and its output while it does (set and read on the queue).
395
+ std::shared_ptr<std::atomic<bool>> recording_ = std::make_shared<std::atomic<bool>>(false);
396
+ std::shared_ptr<AVCaptureMovieFileOutput *> movie_ = std::make_shared<AVCaptureMovieFileOutput *>(nil);
397
+ // What the session is set up to record with, prepared or for the recording running.
398
+ std::shared_ptr<std::optional<RecordingSetup>> setup_ = std::make_shared<std::optional<RecordingSetup>>();
399
+ };
400
+
401
+ } // namespace
402
+
403
+ void SessionCapture::takePicture(const CameraPictureRequest &request, std::function<void(int, int, const std::string &)> done) {
404
+ capturePhoto([request, done = std::move(done)](CGImageRef image, NSDictionary *, const std::string &error) {
405
+ if (image == nullptr) {
406
+ done(0, 0, error);
407
+ } else if (!writePicture(image, request)) {
408
+ done(0, 0, "the picture could not be saved");
409
+ } else {
410
+ done(static_cast<int>(CGImageGetWidth(image)), static_cast<int>(CGImageGetHeight(image)), "");
411
+ }
412
+ });
413
+ }
414
+
415
+ bool writePicture(CGImageRef image, const CameraPictureRequest &request) {
416
+ bool png = request.format == "png";
417
+ NSURL *url = [NSURL fileURLWithPath:@(request.path.c_str())];
418
+ CGImageDestinationRef destination =
419
+ CGImageDestinationCreateWithURL((__bridge CFURLRef)url, png ? CFSTR("public.png") : CFSTR("public.jpeg"), 1, nullptr);
420
+ if (destination == nullptr) {
421
+ return false;
422
+ }
423
+ // A PNG is lossless, so the quality is a JPEG's only, as on iOS.
424
+ NSDictionary *properties = png ? @{} : @{(__bridge NSString *)kCGImageDestinationLossyCompressionQuality : @(request.quality)};
425
+ CGImageDestinationAddImage(destination, image, (__bridge CFDictionaryRef)properties);
426
+ bool written = CGImageDestinationFinalize(destination);
427
+ CFRelease(destination);
428
+ return written;
429
+ }
430
+
431
+ std::optional<CameraClip> movieClip(const std::string &path) {
432
+ AVURLAsset *asset = [AVURLAsset URLAssetWithURL:[NSURL fileURLWithPath:@(path.c_str())] options:nil];
433
+ AVAssetTrack *track = [asset tracksWithMediaType:AVMediaTypeVideo].firstObject;
434
+ if (track == nil) {
435
+ return std::nullopt;
436
+ }
437
+ // A track turned a quarter is its size turned too, which the transform's sign would make negative.
438
+ CGSize size = CGSizeApplyAffineTransform(track.naturalSize, track.preferredTransform);
439
+ return CameraClip{.width = static_cast<int>(std::lround(std::fabs(size.width))),
440
+ .height = static_cast<int>(std::lround(std::fabs(size.height))),
441
+ .duration = CMTimeGetSeconds(asset.duration) * 1000};
442
+ }
443
+
444
+ std::shared_ptr<CameraHardware> makeCameraHardware() {
445
+ return std::make_shared<AVHardware>();
446
+ }
447
+
448
+ AVCaptureDevice *cameraFor(const std::string &facing) {
449
+ NSArray<AVCaptureDevice *> *all = cameras();
450
+ // A Mac's built-in camera faces the user; `front` and `back` both mean it. With the lid closed it
451
+ // is suspended and gives no frames, so another camera is taken, or none.
452
+ std::vector<CameraCandidate> candidates;
453
+ for (AVCaptureDevice *device in all) {
454
+ candidates.push_back({.builtIn = static_cast<bool>([device.deviceType isEqualToString:AVCaptureDeviceTypeBuiltInWideAngleCamera]),
455
+ .suspended = static_cast<bool>(device.suspended)});
456
+ }
457
+ int chosen = chooseCamera(candidates);
458
+ return chosen < 0 ? nil : all[static_cast<NSUInteger>(chosen)];
459
+ }
460
+
461
+ std::shared_ptr<SessionCapture> sessionCapture(AVCaptureSession *session, AVCapturePhotoOutput *output) {
462
+ return std::make_shared<AVSessionCapture>(session, output);
463
+ }
464
+
465
+ std::shared_ptr<SessionCapture> startCapture(AVCaptureDevice *device, std::string &error, std::function<void()> running) {
466
+ if ([AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo] != AVAuthorizationStatusAuthorized) {
467
+ error = cameraMountError(CameraMount::NotPermitted);
468
+ return nullptr;
469
+ }
470
+ if (device == nil) {
471
+ error = cameraMountError(CameraMount::NoCamera);
472
+ return nullptr;
473
+ }
474
+ NSError *failure = nil;
475
+ AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device error:&failure];
476
+ AVCaptureSession *session = [AVCaptureSession new];
477
+ AVCapturePhotoOutput *output = [AVCapturePhotoOutput new];
478
+ [session beginConfiguration];
479
+ session.sessionPreset = AVCaptureSessionPresetPhoto;
480
+ bool ready = input != nil && [session canAddInput:input] && [session canAddOutput:output];
481
+ if (ready) {
482
+ [session addInput:input];
483
+ [session addOutput:output];
484
+ }
485
+ [session commitConfiguration];
486
+ if (!ready) {
487
+ error = std::string("Camera could not be started - ") +
488
+ (failure != nil ? failure.localizedDescription.UTF8String : "the camera cannot be used");
489
+ return nullptr;
490
+ }
491
+ auto capture = sessionCapture(session, output);
492
+ capture->start(std::move(running));
493
+ return capture;
494
+ }
495
+
496
+ } // namespace ngn::appkit
@@ -0,0 +1,24 @@
1
+ // Core Graphics under the core's SvgCanvas: the svg view draws its document with it, and every
2
+ // view draws its box (ngn/view-box.h) with it.
3
+ #pragma once
4
+
5
+ #import <AppKit/AppKit.h>
6
+
7
+ #include "ngn/svg.h"
8
+
9
+ #include <memory>
10
+
11
+ // Both answer a +1 reference the caller releases.
12
+ CGColorRef NGNCreateColor(uint32_t argb, double opacity);
13
+ CGPathRef NGNCreatePath(const ngn::SvgPath &path);
14
+
15
+ // A canvas over `context`, whose coordinates are the view's: top left, y down, in points, `size`
16
+ // big at `scale` pixels a point. `imageLoaded` runs when an image it was asked for has loaded.
17
+ // `viewFor` finds a foreignObject's view by its tag, whose children the canvas draws; without it,
18
+ // a foreignObject draws nothing.
19
+ std::unique_ptr<ngn::SvgCanvas> NGNMakeCGCanvas(
20
+ CGContextRef context,
21
+ CGSize size,
22
+ CGFloat scale,
23
+ void (^imageLoaded)(void),
24
+ NSView * (^viewFor)(ngn::Tag) = nil);