@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,192 @@
1
+ // `<expo-image>` on a desktop host: expo-image's view (ViewManagerAdapter_ExpoImage, the component
2
+ // `registerExpoViews('expo-image')` commits) as a Fabric component of the desktop's own.
3
+ //
4
+ // The core reads the props and decides what the backend draws: which `source` fits the view
5
+ // (expo-image's getBestSource), where the image goes in the view (`contentFit` and
6
+ // `contentPosition`, CSS's object-fit and object-position as expo-image's iOS view applies them),
7
+ // the transition, and the placeholder, decoding a blurhash or a thumbhash to pixels. It fetches an
8
+ // image's bytes through the backend's HTTP client and keeps them in an ImageCache, in memory and on
9
+ // disk by `cachePolicy`, so the backend only decodes and draws. The view sends expo-image's
10
+ // events: loadStart, progress, load ({cacheType, source: {url, width, height, mediaType,
11
+ // isAnimated}}), error ({error}) and display.
12
+ #pragma once
13
+
14
+ #include "ngn/desktop-props.h"
15
+ #include "ngn/file-system.h"
16
+ #include "ngn/network.h"
17
+
18
+ #include <react/renderer/components/view/ConcreteViewShadowNode.h>
19
+ #include <react/renderer/components/view/ViewEventEmitter.h>
20
+ #include <react/renderer/components/view/ViewProps.h>
21
+ #include <react/renderer/core/ConcreteComponentDescriptor.h>
22
+ #include <react/renderer/graphics/Color.h>
23
+
24
+ #include <folly/dynamic.h>
25
+
26
+ #include <cstdint>
27
+ #include <functional>
28
+ #include <list>
29
+ #include <map>
30
+ #include <memory>
31
+ #include <mutex>
32
+ #include <optional>
33
+ #include <string>
34
+ #include <vector>
35
+
36
+ namespace ngn {
37
+
38
+ extern const char ExpoImageComponentName[];
39
+
40
+ class ExpoImageProps final : public facebook::react::ViewProps, public HasDesktopProps {
41
+ public:
42
+ ExpoImageProps() = default;
43
+ ExpoImageProps(
44
+ const facebook::react::PropsParserContext &context,
45
+ const ExpoImageProps &sourceProps,
46
+ const facebook::react::RawProps &rawProps);
47
+ // Lists of {uri, width, height, headers, cacheKey}, as expo-image's JavaScript hands them down.
48
+ folly::dynamic source;
49
+ folly::dynamic placeholder;
50
+ std::string contentFit{"cover"};
51
+ std::string placeholderContentFit{"scale-down"};
52
+ // {top, right, bottom, left}, each points or a percentage string; null for the centre.
53
+ folly::dynamic contentPosition;
54
+ // A duration in milliseconds, or {duration, effect, timing}.
55
+ folly::dynamic transition;
56
+ double blurRadius{0};
57
+ facebook::react::SharedColor tintColor;
58
+ // none, disk, memory or memory-disk.
59
+ std::string cachePolicy{"disk"};
60
+ std::string recyclingKey;
61
+ };
62
+
63
+ using ExpoImageShadowNode =
64
+ facebook::react::ConcreteViewShadowNode<ExpoImageComponentName, ExpoImageProps, facebook::react::ViewEventEmitter>;
65
+ using ExpoImageComponentDescriptor = facebook::react::ConcreteComponentDescriptor<ExpoImageShadowNode>;
66
+
67
+ struct ImageSourceRef {
68
+ std::string uri;
69
+ double width{0};
70
+ double height{0};
71
+ std::vector<std::pair<std::string, std::string>> headers;
72
+ std::string cacheKey;
73
+ bool operator==(const ImageSourceRef &) const = default;
74
+ };
75
+
76
+ // Each entry of a `source` list (or a lone object), in order; entries with no uri are left out.
77
+ std::vector<ImageSourceRef> imageSources(const folly::dynamic &list);
78
+
79
+ // The source whose pixel count is nearest the view's at `scale`, as expo-image picks: the only
80
+ // one when there is one, and nothing for a view with no size.
81
+ std::optional<ImageSourceRef> bestImageSource(const std::vector<ImageSourceRef> &sources, double width, double height, double scale);
82
+
83
+ struct ImageRect {
84
+ double x{0}, y{0}, width{0}, height{0};
85
+ bool operator==(const ImageRect &) const = default;
86
+ };
87
+
88
+ // Where an image of `image` size draws in a box of `box` size, from its top left, by `contentFit`
89
+ // (cover, contain, fill, none, scale-down) and `contentPosition`.
90
+ ImageRect placeImage(
91
+ const std::string &contentFit, const folly::dynamic &contentPosition, std::pair<double, double> image, std::pair<double, double> box);
92
+
93
+ struct ImageTransition {
94
+ double duration{0};
95
+ // cross-dissolve, flip-from-left, flip-from-right, flip-from-top, flip-from-bottom,
96
+ // curl-up, curl-down, or none.
97
+ std::string effect{"cross-dissolve"};
98
+ std::string timing{"ease-in-out"};
99
+ bool operator==(const ImageTransition &) const = default;
100
+ };
101
+ // expo-image's transition from its prop: a number is the duration in milliseconds.
102
+ ImageTransition imageTransition(const folly::dynamic &transition);
103
+ // Whether a recycling key going from `before` to `after` clears the image shown, so a reused view
104
+ // never shows the last item's image while its own loads: a key changed from one that was set.
105
+ bool recyclingKeyClears(const std::string &before, const std::string &after);
106
+
107
+ // Which of an image view's loads is current. A new source, no source, or a recycled view
108
+ // supersedes the load running, whose late answer then shows nothing. Main thread.
109
+ class ImageLoads {
110
+ public:
111
+ // The source that fits the view now: the turn of the load it needs when it changed, the turn
112
+ // that shows nothing when it went away.
113
+ std::optional<uint64_t> fit(const std::optional<ImageSourceRef> &source) {
114
+ if (source == source_) {
115
+ return std::nullopt;
116
+ }
117
+ source_ = source;
118
+ return ++turn_;
119
+ }
120
+ // The view was recycled: the same source loads again, and the load running shows nothing.
121
+ void recycle() {
122
+ source_.reset();
123
+ ++turn_;
124
+ }
125
+ bool current(uint64_t turn) const {
126
+ return turn == turn_;
127
+ }
128
+
129
+ private:
130
+ std::optional<ImageSourceRef> source_;
131
+ uint64_t turn_{0};
132
+ };
133
+
134
+ struct DecodedPixels {
135
+ int width{0};
136
+ int height{0};
137
+ // RGBA, 8 bits a channel, unpremultiplied, rows from the top.
138
+ std::vector<uint8_t> rgba;
139
+ };
140
+
141
+ // A blurhash decoded to `width` by `height` pixels, as the reference decoder does. Nothing for a
142
+ // hash that is not one.
143
+ std::optional<DecodedPixels> decodeBlurhash(const std::string &hash, int width, int height, double punch = 1);
144
+ // A thumbhash's bytes decoded to its own small size (32 points on its longer side), as the
145
+ // reference decoder does. Nothing for bytes too short to be one.
146
+ std::optional<DecodedPixels> decodeThumbhash(const std::string &bytes);
147
+
148
+ // A placeholder's uri decoded, when it is a `blurhash:/<hash>/<w>/<h>` or `thumbhash:/<base64>`
149
+ // uri, as expo-image's JavaScript writes them.
150
+ std::optional<DecodedPixels> decodeHashUri(const std::string &uri, double width = 0, double height = 0);
151
+
152
+ // Images' bytes by key, in memory (least recently used dropped past `memoryLimit` bytes) and on
153
+ // disk in `folder`, each by `cachePolicy`. Any thread.
154
+ class ImageCache {
155
+ public:
156
+ enum class Hit { None, Memory, Disk };
157
+ ImageCache(std::string folder, size_t memoryLimit);
158
+ // The bytes kept for `key` where `policy` looks (memory first), or nothing.
159
+ std::optional<std::pair<std::string, Hit>> find(const std::string &key, const std::string &policy);
160
+ void store(const std::string &key, const std::string &bytes, const std::string &policy);
161
+ void clearMemory();
162
+ bool clearDisk();
163
+ // The file `key`'s bytes are kept in on disk.
164
+ std::string diskPath(const std::string &key) const;
165
+ size_t memoryBytes() const;
166
+
167
+ private:
168
+ void remember(const std::string &key, const std::string &bytes);
169
+ std::string folder_;
170
+ size_t limit_;
171
+ mutable std::mutex mutex_;
172
+ std::list<std::pair<std::string, std::string>> recent_;
173
+ std::map<std::string, std::list<std::pair<std::string, std::string>>::iterator> byKey_;
174
+ size_t bytes_{0};
175
+ };
176
+
177
+ // expo-image's name for a cache hit: none, memory or disk.
178
+ const char *cacheTypeName(ImageCache::Hit hit);
179
+
180
+ // Reads `source`'s bytes: from the cache by its cacheKey (or uri) when `policy` keeps it, else
181
+ // through `http` with its headers, then into the cache. `file:` and `data:` sources are read and
182
+ // never cached, a file only inside the file boundary `files` draws (readableSource). Answers once,
183
+ // on any thread: the bytes and the hit, or an error.
184
+ void loadImageBytes(
185
+ const std::shared_ptr<Http> &http,
186
+ const std::shared_ptr<ImageCache> &cache,
187
+ const FileAccess *files,
188
+ const ImageSourceRef &source,
189
+ const std::string &policy,
190
+ std::function<void(std::string bytes, ImageCache::Hit hit, const std::string &error)> done);
191
+
192
+ } // namespace ngn
@@ -0,0 +1,133 @@
1
+ // `@expo/ui` on a desktop host: its SwiftUI views as Fabric components, under the names
2
+ // `registerExpoUiViews` commits on iOS (ViewManagerAdapter_ExpoUI_<view>), with iOS's props.
3
+ //
4
+ // Every one of them is one component class, told apart by its name (the descriptor's flavor), whose
5
+ // props are kept as they arrive: expo/ui's views take an untyped map of props, and each SwiftUI view
6
+ // reads its own. The core keeps the views under each HostView as one tree (ExpoUITrees, below),
7
+ // which the backend's view for the HostView draws in SwiftUI, as expo/ui's HostView does with its
8
+ // children on iOS. Their own views draw nothing. An RNHostView in the tree is the app's own views
9
+ // inside the SwiftUI content: they lay out in Yoga as usual and the toolkit puts its view there.
10
+ //
11
+ // A HostView with `matchContentsHorizontal` or `matchContentsVertical` is sized by its content: the
12
+ // toolkit reports the SwiftUI content's fitting size as the HostView's state, and the HostView takes
13
+ // it on the axes it matches, as expo/ui's `setViewSize` does on iOS.
14
+ #pragma once
15
+
16
+ #include "ngn/view-tree.h"
17
+
18
+ #include <react/renderer/components/view/ConcreteViewShadowNode.h>
19
+ #include <react/renderer/components/view/ViewEventEmitter.h>
20
+ #include <react/renderer/components/view/ViewProps.h>
21
+ #include <react/renderer/componentregistry/ComponentDescriptorProvider.h>
22
+ #include <react/renderer/core/ConcreteComponentDescriptor.h>
23
+ #include <react/renderer/core/EventEmitter.h>
24
+
25
+ #include <folly/dynamic.h>
26
+
27
+ #include <memory>
28
+ #include <optional>
29
+ #include <string>
30
+ #include <string_view>
31
+ #include <unordered_map>
32
+ #include <unordered_set>
33
+ #include <vector>
34
+
35
+ namespace ngn {
36
+
37
+ // The prefix every expo/ui view's component name has: the module's view adapter for `ExpoUI`.
38
+ inline constexpr std::string_view kExpoUIPrefix = "ViewManagerAdapter_ExpoUI_";
39
+
40
+ // The iOS view names the desktop host draws (`EXPO_UI_MACOS` in @ng-native/expo, which a test
41
+ // holds to this list), in no order.
42
+ const std::vector<std::string> &expoUIViews();
43
+
44
+ // `HostView` for `ViewManagerAdapter_ExpoUI_HostView`; nothing for a name that is not one of the
45
+ // expo/ui views the host draws.
46
+ std::optional<std::string> expoUIViewName(std::string_view componentName);
47
+
48
+ class ExpoUIProps final : public facebook::react::ViewProps {
49
+ public:
50
+ ExpoUIProps() = default;
51
+ ExpoUIProps(
52
+ const facebook::react::PropsParserContext &context,
53
+ const ExpoUIProps &sourceProps,
54
+ const facebook::react::RawProps &rawProps);
55
+
56
+ // Every prop as committed, the last value of each: a `null` removes one. Yoga's and the view's
57
+ // own style props are here too, and the SwiftUI views read only their own names.
58
+ folly::dynamic values = folly::dynamic::object();
59
+
60
+ // The HostView's, read here for layout.
61
+ bool matchContentsHorizontal{false};
62
+ bool matchContentsVertical{false};
63
+ // An RNHostView sized from the app's views it holds (`expoInternalSizeFromChildren`, which
64
+ // `matchContents` sets), as iOS measures it, rather than stretched across its container.
65
+ bool sizeFromChildren{false};
66
+ };
67
+
68
+ // The size of a HostView's SwiftUI content, as the toolkit measured it. Zero until it reports.
69
+ struct ExpoUIState {
70
+ facebook::react::Size contentSize{};
71
+ };
72
+
73
+ extern const char ExpoUIComponentName[];
74
+
75
+ class ExpoUIShadowNode final : public facebook::react::ConcreteViewShadowNode<
76
+ ExpoUIComponentName,
77
+ ExpoUIProps,
78
+ facebook::react::ViewEventEmitter,
79
+ ExpoUIState> {
80
+ public:
81
+ using ConcreteViewShadowNode::ConcreteViewShadowNode;
82
+
83
+ // Takes the content size the state holds on each axis the props match, over the style's, and
84
+ // fits a view sized from its children to them.
85
+ void applyContentSize();
86
+ };
87
+
88
+ // One descriptor per expo/ui view name, as its flavor.
89
+ class ExpoUIComponentDescriptor final : public facebook::react::ConcreteComponentDescriptor<ExpoUIShadowNode> {
90
+ public:
91
+ using ConcreteComponentDescriptor::ConcreteComponentDescriptor;
92
+ facebook::react::ComponentHandle getComponentHandle() const override;
93
+ facebook::react::ComponentName getComponentName() const override;
94
+ void adopt(facebook::react::ShadowNode &shadowNode) const override;
95
+ };
96
+
97
+ // A provider for each of expoUIViews(), by its full component name.
98
+ std::vector<facebook::react::ComponentDescriptorProvider> expoUIComponentProviders();
99
+
100
+ // One expo/ui view in a HostView's tree: its iOS name, its props, where its events go, and the
101
+ // expo/ui views under it. An RNHostView has none: what is under it is the app's own.
102
+ struct ExpoUINode {
103
+ facebook::react::Tag tag{-1};
104
+ std::string name;
105
+ folly::dynamic props = folly::dynamic::object();
106
+ facebook::react::SharedEventEmitter eventEmitter;
107
+ std::vector<ExpoUINode> children;
108
+ bool operator==(const ExpoUINode &) const = default;
109
+ };
110
+
111
+ // The HostViews of a surface's views, kept by the mounting manager as it mounts them: which
112
+ // HostView each change belongs to, and each HostView's tree when it changed.
113
+ class ExpoUITrees {
114
+ public:
115
+ // A view was made or its props or event emitter changed, or `tag`'s children changed.
116
+ void changed(const ViewTree &tree, facebook::react::Tag tag);
117
+ void deleted(facebook::react::Tag tag);
118
+
119
+ struct Changed {
120
+ facebook::react::Tag host{-1};
121
+ std::shared_ptr<const ExpoUINode> root;
122
+ };
123
+ // The HostViews whose trees changed since the last call.
124
+ std::vector<Changed> settle(const ViewTree &tree);
125
+
126
+ private:
127
+ std::optional<ExpoUINode> node(const ViewTree &tree, facebook::react::Tag tag) const;
128
+
129
+ std::unordered_set<facebook::react::Tag> dirty_;
130
+ std::unordered_map<facebook::react::Tag, std::shared_ptr<const ExpoUINode>> drawn_;
131
+ };
132
+
133
+ } // namespace ngn
@@ -0,0 +1,274 @@
1
+ // NgNativeFileSystem: files for @ng-native/expo's FileSystem on a desktop OS. A TurboModule cannot
2
+ // hand JavaScript expo-file-system's File and Directory classes, so this answers flat calls over
3
+ // uris (expo-file-system/legacy's, and the service's own readdir, stat and watch), and the desktop
4
+ // loader builds the classes over them.
5
+ //
6
+ // - `paths`: {cache, document, appData, temp, home, desktop, downloads}, each a file:// uri ending
7
+ // in `/`, and each left out where the app cannot reach it. `documentDirectory` and
8
+ // `cacheDirectory` are legacy's two.
9
+ // - readdir(uri): [{name, uri, directory}] by name; stat(uri): {uri, directory, size, modified,
10
+ // created} in ms since 1970, or null where nothing is.
11
+ // - watch(uri): a watch id, or null where nothing is; its changes arrive as `ngNativeFileSystem`
12
+ // on DeviceEventEmitter: {watch, type: created | modified | deleted | renamed, uri, newUri?}, for
13
+ // a file, or for a folder and what is directly in it. unwatch(id) stops one.
14
+ // - readAsStringAsync(uri, {encoding: utf8 | base64}), writeAsStringAsync(uri, text, {encoding,
15
+ // append}), deleteAsync(uri, {idempotent}), makeDirectoryAsync(uri, {intermediates}),
16
+ // moveAsync({from, to}), copyAsync({from, to}) and createFile(folderUri, name): {uri}, empty.
17
+ // - Each of those is synchronous too, with `Async` (or nothing) swapped for `Sync`: statSync,
18
+ // readdirSync, readAsStringSync, writeAsStringSync, deleteSync, makeDirectorySync, moveSync,
19
+ // copySync and createFileSync answer the same value, or throw the failure the promise rejects
20
+ // with. The service's files are synchronous through them, as expo-file-system's are.
21
+ //
22
+ // Every call is checked against FileAccess: the app's own folders and what the user picked can be
23
+ // read and written, and anything else only as the plugin options' `capabilities.paths` declare
24
+ // (`read` or `readwrite`). Symbolic links are followed before the check, so one cannot lead out.
25
+ #pragma once
26
+
27
+ #include "ngn/native-module.h"
28
+
29
+ #include <functional>
30
+ #include <memory>
31
+ #include <mutex>
32
+ #include <optional>
33
+ #include <set>
34
+ #include <stdexcept>
35
+ #include <string>
36
+ #include <vector>
37
+
38
+ namespace ngn {
39
+
40
+ // A path as a file:// uri, percent-encoded as expo-file-system writes them.
41
+ std::string fileUri(const std::string &path);
42
+ // The absolute path a file:// uri or a plain absolute path names, percent-decoded. Nothing for
43
+ // another scheme or a relative path.
44
+ std::optional<std::string> pathOfUri(const std::string &uri);
45
+
46
+ // Writes `bytes` to `path` through a temporary file beside it, renamed over `path` only once the
47
+ // whole write and its close succeeded, so a failed write leaves whatever was at `path` as it was.
48
+ // False when the write failed.
49
+ bool replaceFile(const std::string &path, const std::string &bytes);
50
+
51
+ // The toolkit's security-scoped bookmarks (macOS): what finds a file or folder the user picked
52
+ // again in a later launch, wherever it has moved, and reopens the sandbox to it.
53
+ class Bookmarks {
54
+ public:
55
+ struct Resolved {
56
+ std::string path;
57
+ // The bookmark still resolves but should be made again.
58
+ bool stale{false};
59
+ };
60
+ virtual ~Bookmarks() = default;
61
+ // A bookmark for `path`, or nothing where the toolkit cannot make one.
62
+ virtual std::optional<std::string> make(const std::string &path) = 0;
63
+ // A stale `bookmark` made again for `path`, where it points now, granting what it grants: nothing
64
+ // where the toolkit cannot make one that does, so the stale one, which still resolves, is kept.
65
+ virtual std::optional<std::string> renew(const std::string &bookmark, const std::string &path) {
66
+ (void)bookmark;
67
+ return make(path);
68
+ }
69
+ // Where a bookmark points now, or nothing for one that no longer resolves.
70
+ virtual std::optional<Resolved> resolve(const std::string &bookmark) = 0;
71
+ // Starts and stops using what a bookmark points at. Each start the toolkit agreed to (true) is
72
+ // matched by one stop; starts nest.
73
+ virtual bool startAccess(const std::string &bookmark) = 0;
74
+ virtual void stopAccess(const std::string &bookmark) = 0;
75
+ };
76
+
77
+ // The user's picks, kept across launches: a bookmark for each, stored through `load` and `save`
78
+ // (somewhere JavaScript cannot write, since a bookmark opens the sandbox) as JSON:
79
+ // {"version": 1, "picks": [{"path", "bookmark" (base64)}]}. Any thread.
80
+ class PickStore {
81
+ public:
82
+ struct Persistence {
83
+ std::function<std::optional<std::string>()> load;
84
+ std::function<void(const std::string &)> save;
85
+ };
86
+ PickStore(Persistence persistence, std::shared_ptr<Bookmarks> bookmarks);
87
+
88
+ // The picks of earlier launches that still resolve, each at its path now. A stale bookmark is
89
+ // made again and one that no longer resolves is dropped, and the store is saved when either
90
+ // happens.
91
+ std::vector<std::string> restore();
92
+ // Keeps a pick for later launches; a path kept already gets a new bookmark.
93
+ void remember(const std::string &path);
94
+ // The bookmark of the innermost pick holding `path`.
95
+ std::optional<std::string> bookmarkFor(const std::string &path) const;
96
+ Bookmarks &bookmarks() const {
97
+ return *bookmarks_;
98
+ }
99
+
100
+ private:
101
+ struct Pick {
102
+ std::string path;
103
+ std::string bookmark;
104
+ };
105
+ void save();
106
+
107
+ Persistence persistence_;
108
+ std::shared_ptr<Bookmarks> bookmarks_;
109
+ mutable std::mutex mutex_;
110
+ std::vector<Pick> picks_;
111
+ };
112
+
113
+ // A path JavaScript named that is outside what the app may read (FileAccess::readFor) or write
114
+ // (FileAccess::writeFor).
115
+ class FileRefused : public std::runtime_error {
116
+ public:
117
+ explicit FileRefused(const std::string &path, bool write = false);
118
+ };
119
+
120
+ class FileAccess {
121
+ public:
122
+ enum class Access { None, Read, ReadWrite };
123
+
124
+ struct Folders {
125
+ std::string cache;
126
+ std::string document;
127
+ std::string appData;
128
+ std::string temp;
129
+ // The user's: reachable only as `paths` declares them.
130
+ std::string home;
131
+ std::string desktop;
132
+ std::string downloads;
133
+ // The app bundle's Resources, where a packaged app's assets are: read by the modules that
134
+ // load assets (readFor), never reached by FileSystem.
135
+ std::string bundle;
136
+ };
137
+
138
+ // `declared` is `capabilities.paths`: [{path, access}], `~/` meaning the home folder.
139
+ FileAccess(Folders folders, const folly::dynamic &declared);
140
+
141
+ const Folders &folders() const {
142
+ return folders_;
143
+ }
144
+ // What the app may do at `path`, an absolute path.
145
+ Access accessTo(const std::string &path) const;
146
+ // A file or folder the user chose in a panel: for the rest of the process, and in later
147
+ // launches once picks are kept.
148
+ void allowPicked(const std::string &path);
149
+ // Keeps the picks in `store` from now on, and allows the ones earlier launches kept.
150
+ void keepPicks(std::shared_ptr<PickStore> store);
151
+
152
+ // The pick holding a path opened for as long as this lives: a picked file or folder of an earlier
153
+ // launch is reachable in the sandbox only while its bookmark's access is started.
154
+ class Use {
155
+ public:
156
+ Use() = default;
157
+ Use(std::shared_ptr<PickStore> store, std::string bookmark);
158
+ Use(Use &&other) noexcept;
159
+ Use &operator=(Use &&other) noexcept;
160
+ Use(const Use &) = delete;
161
+ Use &operator=(const Use &) = delete;
162
+ ~Use();
163
+ bool started() const {
164
+ return store_ != nullptr;
165
+ }
166
+
167
+ private:
168
+ void release();
169
+ std::shared_ptr<PickStore> store_;
170
+ std::string bookmark_;
171
+ };
172
+ // A Use for `path`; one that starts nothing outside picks.
173
+ Use use(const std::string &path) const;
174
+ // The one check for a module that reads a file JavaScript names (ImageEditor, TextRecognition,
175
+ // Fonts, Printing, MediaLibrary.createAsset, an XMLHttpRequest body): it may read what accessTo
176
+ // lets FileSystem read, and the app bundle's assets. The Use keeps a pick of an earlier launch
177
+ // open; hold it until the read is done. Throws FileRefused for anything else, in the same words
178
+ // whether or not a file is there.
179
+ std::shared_ptr<Use> readFor(const std::string &path) const;
180
+ // The same check for a module that writes or creates a file where JavaScript says (SQLite's
181
+ // databases): what accessTo lets FileSystem write, never the bundle. Throws FileRefused for
182
+ // anything else, in the same words whether or not a file is there.
183
+ std::shared_ptr<Use> writeFor(const std::string &path) const;
184
+
185
+ private:
186
+ struct Root {
187
+ std::string path;
188
+ Access access;
189
+ };
190
+ void add(const std::string &path, Access access);
191
+
192
+ Folders folders_;
193
+ mutable std::mutex mutex_;
194
+ std::vector<Root> roots_;
195
+ std::shared_ptr<PickStore> picks_;
196
+ };
197
+
198
+ // FileAccess::readFor through `access`, refusing every path when there is none.
199
+ std::shared_ptr<FileAccess::Use> readableFile(const FileAccess *access, const std::string &path);
200
+
201
+ // A source JavaScript hands to something that reads it through a uri (an image, a player, a
202
+ // request's url, a web view's page): the uri to hand on, and the pick it reads, held open.
203
+ struct ReadableSource {
204
+ std::string uri;
205
+ std::shared_ptr<FileAccess::Use> use;
206
+ };
207
+ // A file source (an absolute path, or a uri in the `file:` scheme however it is spelled) checked
208
+ // with readFor and answered as fileUri of the path checked, without its query or fragment, so the
209
+ // loader reads exactly that file. Any other uri is answered as it is. Throws FileRefused for a file
210
+ // outside the boundary, a `file:` uri naming a host or no absolute path, and with no `access`.
211
+ ReadableSource readableSource(const FileAccess *access, const std::string &uri);
212
+ // Whether a uri is in the `file:` scheme, in any case: what a URL loader reads from disk.
213
+ bool isFileScheme(const std::string &uri);
214
+
215
+ // The FileAccess the host made, for what loads a source JavaScript names outside a module (the
216
+ // views drawing an image or a page, a drag out of the app). Without one, every file is refused.
217
+ void useViewFileAccess(std::shared_ptr<FileAccess> access);
218
+ std::shared_ptr<FileAccess> viewFileAccess();
219
+
220
+ // The OS's file events (FSEvents on macOS), for one path at a time.
221
+ class FileWatcher {
222
+ public:
223
+ // One event as the OS reports it; the flags may be several at once, coalesced.
224
+ struct Event {
225
+ std::string path;
226
+ bool created{false};
227
+ bool removed{false};
228
+ bool renamed{false};
229
+ bool modified{false};
230
+ // The OS lost track of what changed under the path (FSEvents' must-scan-subdirs, after events
231
+ // were dropped): the changes are found by listing it again.
232
+ bool rescan{false};
233
+ };
234
+ virtual ~FileWatcher() = default;
235
+ // Starts reporting batches of events under `path`, on any thread, until stop. A handle, or 0
236
+ // when the OS would not start watching.
237
+ virtual int start(const std::string &path, std::function<void(std::vector<Event>)> events) = 0;
238
+ virtual void stop(int handle) = 0;
239
+ };
240
+
241
+ // The changes batches of events make to `watched` (a file, or a folder and what is directly in
242
+ // it), as `ngNativeFileSystem` reports them without the watch id. It remembers the paths it has
243
+ // seen, from those there when the watch began, since FSEvents keeps a file's created flag on its
244
+ // later events. `exists` says whether a path is there now, what coalesced flags cannot, or nothing
245
+ // when it cannot tell (a folder that cannot be searched): that event is left out and the folder
246
+ // listed again at the next one.
247
+ class FileChanges {
248
+ public:
249
+ using Exists = std::function<std::optional<bool>(const std::string &)>;
250
+ FileChanges(std::string watched, const Exists &exists);
251
+ folly::dynamic changes(const std::vector<FileWatcher::Event> &events, const Exists &exists);
252
+ // Whether what was there when the watch began was listed in full: a folder that could not be
253
+ // listed has nothing to tell an entry already there from a new one.
254
+ bool listed() const {
255
+ return listed_;
256
+ }
257
+
258
+ private:
259
+ bool concerns(const std::string &path) const;
260
+ // A rescan's changes: what is there now against what was seen.
261
+ void rescan(folly::dynamic &out, const Exists &exists);
262
+ // Adds the folder's entries to `into`; false when it could not be listed in full.
263
+ bool list(std::set<std::string> &into) const;
264
+ std::string watched_;
265
+ bool folder_{false};
266
+ bool listed_{true};
267
+ // The last listing failed: the next events start with another.
268
+ bool rescanOwed_{false};
269
+ std::set<std::string> seen_;
270
+ };
271
+
272
+ std::shared_ptr<NativeModule> makeFileSystemModule(std::shared_ptr<FileAccess> access, std::shared_ptr<FileWatcher> watcher);
273
+
274
+ } // namespace ngn
@@ -0,0 +1,63 @@
1
+ // Tab order, walked in the core over the committed tree, the same on every toolkit: what Tab and
2
+ // Shift-Tab move the focus to. AppKit's key-view loop is not used.
3
+ //
4
+ // A view is in Tab order when its desktop props say it takes focus (`focusable`, or a `tabIndex`
5
+ // of 0 or more), or when it is a text input or a native control (native-controls.h) that a
6
+ // negative `tabIndex` or `focusable: false` does not take out. Positive `tabIndex` values come
7
+ // first, lowest first, then everything else in tree order, as on the web. Covered screens, views
8
+ // with `display: none` and other containers' content (a popover's, a sheet's) are skipped: the walk
9
+ // stays inside the container it starts in, which keeps Tab inside a modal.
10
+ //
11
+ // A composite widget (a view with the `tablist`, `radiogroup`, `menu`, `menubar`, `listbox` or
12
+ // `grid` role) is one Tab stop, as WAI-ARIA has it: the item in it with the focus, else its
13
+ // selected or checked item, else its first. Arrow keys, Home and End move the focus between its
14
+ // items (compositeMove). A text input inside one keeps a Tab stop of its own.
15
+ #pragma once
16
+
17
+ #include "ngn/view-tree.h"
18
+
19
+ #include <optional>
20
+ #include <vector>
21
+
22
+ namespace ngn {
23
+
24
+ // How far Tab reaches, from the system's keyboard navigation setting: every focusable view, or
25
+ // only text inputs (the Mac's default, where Option-Tab reaches everything).
26
+ enum class TabReach { TextInputs, All };
27
+
28
+ // The views Tab visits in the container `root`, in order. `focused` is the view with the focus,
29
+ // which is a composite widget's stop.
30
+ std::vector<Tag> tabOrder(const ViewTree &tree, Tag root, TabReach reach, std::optional<Tag> focused = std::nullopt);
31
+
32
+ // Where Tab (or Shift-Tab, `backwards`) moves the focus from `from`, wrapping round; the first
33
+ // (or last) view when `from` is not in Tab order. Nothing when no view is.
34
+ std::optional<Tag> nextInTabOrder(
35
+ const ViewTree &tree,
36
+ Tag root,
37
+ std::optional<Tag> from,
38
+ bool backwards,
39
+ TabReach reach);
40
+
41
+ // The keys that move the focus inside a composite widget. Left and Right are as pressed: a
42
+ // right-to-left composite swaps them.
43
+ enum class CompositeKey { Left, Right, Up, Down, Home, End };
44
+
45
+ // Where `key` moves the focus from `focused` inside the nearest composite widget around it, under
46
+ // `root`, as WAI-ARIA's practices have it:
47
+ // - `tablist` and `radiogroup`: every arrow, the previous or the next item, wrapping round;
48
+ // - `menu`: Up and Down, wrapping; `menubar`: Left and Right, wrapping;
49
+ // - `listbox`: Up and Down, stopping at either end;
50
+ // - `grid`: the next cell in the row or the column, stopping at the edges, its `row` views being
51
+ // the rows; Home and End go to the row's ends, and with `control` to the grid's first and last.
52
+ // Home and End go to the first and last item elsewhere. The items are the views with the role the
53
+ // composite takes (`tab`; `radio`; `menuitem`, `menuitemcheckbox` and `menuitemradio`; `option`;
54
+ // `gridcell`, `cell`, `columnheader` and `rowheader`), outside any composite nested in it, focused
55
+ // themselves or, when one takes no focus, through the first view inside it that does. A disabled
56
+ // radio is skipped; other disabled items are not, as WAI-ARIA recommends.
57
+ //
58
+ // The focused view itself at an edge that does not wrap: the key is used and nothing moves.
59
+ // Nothing when the focus is in no composite, the key is not one it uses, or the focus is in a text
60
+ // input or a native control that uses the arrows itself.
61
+ std::optional<Tag> compositeMove(const ViewTree &tree, Tag root, Tag focused, CompositeKey key, bool control);
62
+
63
+ } // namespace ngn