@ng-native/desktop 0.0.0-stage → 0.23.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 (393) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +51 -2
  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 +276 -0
  14. package/native/appkit/CMakeLists.txt +109 -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-view.h +15 -0
  41. package/native/appkit/camera-view.mm +130 -0
  42. package/native/appkit/camera.h +39 -0
  43. package/native/appkit/camera.mm +362 -0
  44. package/native/appkit/cg-canvas.h +17 -0
  45. package/native/appkit/cg-canvas.mm +518 -0
  46. package/native/appkit/component-view.h +17 -0
  47. package/native/appkit/crypto.h +19 -0
  48. package/native/appkit/crypto.mm +78 -0
  49. package/native/appkit/desktop-expo.h +29 -0
  50. package/native/appkit/desktop-expo.mm +385 -0
  51. package/native/appkit/expo-image-drawing.h +46 -0
  52. package/native/appkit/expo-image-drawing.mm +131 -0
  53. package/native/appkit/expo-image-view.h +15 -0
  54. package/native/appkit/expo-image-view.mm +182 -0
  55. package/native/appkit/expo-ui-renderer.h +68 -0
  56. package/native/appkit/expo-ui-renderer.mm +101 -0
  57. package/native/appkit/expo-ui-view.h +26 -0
  58. package/native/appkit/expo-ui-view.mm +134 -0
  59. package/native/appkit/expo-ui.swift +1284 -0
  60. package/native/appkit/file-system.h +16 -0
  61. package/native/appkit/file-system.mm +140 -0
  62. package/native/appkit/fonts.h +12 -0
  63. package/native/appkit/fonts.mm +48 -0
  64. package/native/appkit/geocoder.h +19 -0
  65. package/native/appkit/geocoder.mm +101 -0
  66. package/native/appkit/glass-effect.h +22 -0
  67. package/native/appkit/glass-effect.mm +63 -0
  68. package/native/appkit/glass-view.h +8 -0
  69. package/native/appkit/glass-view.mm +65 -0
  70. package/native/appkit/header-toolbar.h +60 -0
  71. package/native/appkit/header-toolbar.mm +629 -0
  72. package/native/appkit/host-view.h +54 -0
  73. package/native/appkit/host-view.mm +1200 -0
  74. package/native/appkit/image-manipulator.h +14 -0
  75. package/native/appkit/image-manipulator.mm +191 -0
  76. package/native/appkit/image-request.h +22 -0
  77. package/native/appkit/image-request.mm +62 -0
  78. package/native/appkit/image-view.h +8 -0
  79. package/native/appkit/image-view.mm +142 -0
  80. package/native/appkit/input-replay.h +25 -0
  81. package/native/appkit/input-replay.mm +418 -0
  82. package/native/appkit/language-model.h +14 -0
  83. package/native/appkit/language-model.mm +99 -0
  84. package/native/appkit/language-model.swift +472 -0
  85. package/native/appkit/local-authentication.h +15 -0
  86. package/native/appkit/local-authentication.mm +133 -0
  87. package/native/appkit/location.h +16 -0
  88. package/native/appkit/location.mm +214 -0
  89. package/native/appkit/main.mm +1515 -0
  90. package/native/appkit/map-view.h +15 -0
  91. package/native/appkit/map-view.mm +109 -0
  92. package/native/appkit/maps.h +35 -0
  93. package/native/appkit/maps.mm +343 -0
  94. package/native/appkit/menu-bar.h +22 -0
  95. package/native/appkit/menu-bar.mm +208 -0
  96. package/native/appkit/modal-focus.h +16 -0
  97. package/native/appkit/modal-focus.mm +26 -0
  98. package/native/appkit/modal-host-view.h +79 -0
  99. package/native/appkit/modal-host-view.mm +442 -0
  100. package/native/appkit/native-controls.h +22 -0
  101. package/native/appkit/native-controls.mm +431 -0
  102. package/native/appkit/network-state.h +12 -0
  103. package/native/appkit/network-state.mm +64 -0
  104. package/native/appkit/network.h +14 -0
  105. package/native/appkit/network.mm +396 -0
  106. package/native/appkit/notifications.h +19 -0
  107. package/native/appkit/notifications.mm +309 -0
  108. package/native/appkit/photo-library.h +33 -0
  109. package/native/appkit/photo-library.mm +548 -0
  110. package/native/appkit/pointer-buttons.h +32 -0
  111. package/native/appkit/presentation-label.h +15 -0
  112. package/native/appkit/presentation-label.mm +12 -0
  113. package/native/appkit/presented-screen.h +19 -0
  114. package/native/appkit/presented-screen.mm +181 -0
  115. package/native/appkit/printing.h +42 -0
  116. package/native/appkit/printing.mm +393 -0
  117. package/native/appkit/push.h +19 -0
  118. package/native/appkit/push.mm +81 -0
  119. package/native/appkit/red-box.h +26 -0
  120. package/native/appkit/red-box.mm +387 -0
  121. package/native/appkit/screen-capture.h +21 -0
  122. package/native/appkit/screen-capture.mm +92 -0
  123. package/native/appkit/scroll-view.h +13 -0
  124. package/native/appkit/scroll-view.mm +251 -0
  125. package/native/appkit/scrollers.h +25 -0
  126. package/native/appkit/scrollers.mm +43 -0
  127. package/native/appkit/search-field.h +34 -0
  128. package/native/appkit/search-field.mm +291 -0
  129. package/native/appkit/search-toolbar-item.h +19 -0
  130. package/native/appkit/search-toolbar-item.mm +269 -0
  131. package/native/appkit/share-picker.h +34 -0
  132. package/native/appkit/share-picker.mm +121 -0
  133. package/native/appkit/split-view.h +77 -0
  134. package/native/appkit/split-view.mm +1206 -0
  135. package/native/appkit/store-review.h +13 -0
  136. package/native/appkit/store-review.mm +28 -0
  137. package/native/appkit/surface-view.h +45 -0
  138. package/native/appkit/surface-view.mm +558 -0
  139. package/native/appkit/svg-view.h +17 -0
  140. package/native/appkit/svg-view.mm +57 -0
  141. package/native/appkit/symbol-drawing.h +24 -0
  142. package/native/appkit/symbol-drawing.mm +117 -0
  143. package/native/appkit/symbol-view.h +8 -0
  144. package/native/appkit/symbol-view.mm +33 -0
  145. package/native/appkit/system-access.h +34 -0
  146. package/native/appkit/system-access.mm +210 -0
  147. package/native/appkit/system.h +24 -0
  148. package/native/appkit/system.mm +403 -0
  149. package/native/appkit/test-launch.h +36 -0
  150. package/native/appkit/test-launch.mm +115 -0
  151. package/native/appkit/text-input-field.h +76 -0
  152. package/native/appkit/text-input-field.mm +444 -0
  153. package/native/appkit/text-layout.h +58 -0
  154. package/native/appkit/text-layout.mm +477 -0
  155. package/native/appkit/text-recognition.h +13 -0
  156. package/native/appkit/text-recognition.mm +102 -0
  157. package/native/appkit/tracking.h +13 -0
  158. package/native/appkit/tracking.mm +51 -0
  159. package/native/appkit/tray-and-dock.h +45 -0
  160. package/native/appkit/tray-and-dock.mm +130 -0
  161. package/native/appkit/undo.h +23 -0
  162. package/native/appkit/undo.mm +125 -0
  163. package/native/appkit/updates.h +17 -0
  164. package/native/appkit/updates.mm +71 -0
  165. package/native/appkit/video-view.h +10 -0
  166. package/native/appkit/video-view.mm +42 -0
  167. package/native/appkit/video.h +38 -0
  168. package/native/appkit/video.mm +404 -0
  169. package/native/appkit/web-browser.h +12 -0
  170. package/native/appkit/web-browser.mm +97 -0
  171. package/native/appkit/web-view-component.h +9 -0
  172. package/native/appkit/web-view-component.mm +56 -0
  173. package/native/appkit/web-view.h +31 -0
  174. package/native/appkit/web-view.mm +394 -0
  175. package/native/cmake/libraries/react-native-reanimated.cmake +45 -0
  176. package/native/cmake/libraries/react-native-worklets.cmake +46 -0
  177. package/native/cmake/libraries.cmake +109 -0
  178. package/native/cmake/linked-modules.cmake +112 -0
  179. package/native/cmake/react-native.cmake +175 -0
  180. package/native/cmake/runtime-dependencies.cmake +34 -0
  181. package/native/cmake/swift.cmake +43 -0
  182. package/native/cmake/third-party.cmake +74 -0
  183. package/native/core/include/ngn/absent-views.h +27 -0
  184. package/native/core/include/ngn/accessibility.h +140 -0
  185. package/native/core/include/ngn/address-search.h +69 -0
  186. package/native/core/include/ngn/animation-frames.h +39 -0
  187. package/native/core/include/ngn/app-info.h +52 -0
  188. package/native/core/include/ngn/app-menus.h +146 -0
  189. package/native/core/include/ngn/app-windows.h +181 -0
  190. package/native/core/include/ngn/apple-authentication.h +116 -0
  191. package/native/core/include/ngn/asset.h +28 -0
  192. package/native/core/include/ngn/audio.h +125 -0
  193. package/native/core/include/ngn/back-swipe.h +112 -0
  194. package/native/core/include/ngn/battery.h +48 -0
  195. package/native/core/include/ngn/bytes.h +59 -0
  196. package/native/core/include/ngn/calendar.h +180 -0
  197. package/native/core/include/ngn/camera.h +128 -0
  198. package/native/core/include/ngn/control-sizes.h +111 -0
  199. package/native/core/include/ngn/core-modules.h +105 -0
  200. package/native/core/include/ngn/crypto.h +38 -0
  201. package/native/core/include/ngn/default-menu.h +91 -0
  202. package/native/core/include/ngn/desktop-expo.h +193 -0
  203. package/native/core/include/ngn/desktop-modal.h +109 -0
  204. package/native/core/include/ngn/desktop-props.h +75 -0
  205. package/native/core/include/ngn/desktop-view-props.h +110 -0
  206. package/native/core/include/ngn/dev-server.h +33 -0
  207. package/native/core/include/ngn/download.h +24 -0
  208. package/native/core/include/ngn/expo-image.h +192 -0
  209. package/native/core/include/ngn/expo-ui.h +133 -0
  210. package/native/core/include/ngn/file-system.h +274 -0
  211. package/native/core/include/ngn/focus-order.h +63 -0
  212. package/native/core/include/ngn/fonts.h +64 -0
  213. package/native/core/include/ngn/gestures.h +305 -0
  214. package/native/core/include/ngn/glass.h +67 -0
  215. package/native/core/include/ngn/header-bar.h +112 -0
  216. package/native/core/include/ngn/host-state.h +243 -0
  217. package/native/core/include/ngn/image-manipulator.h +70 -0
  218. package/native/core/include/ngn/input-dispatcher.h +211 -0
  219. package/native/core/include/ngn/input-script.h +56 -0
  220. package/native/core/include/ngn/input.h +112 -0
  221. package/native/core/include/ngn/key-value-store.h +41 -0
  222. package/native/core/include/ngn/language-model.h +69 -0
  223. package/native/core/include/ngn/launch-frame.h +47 -0
  224. package/native/core/include/ngn/launch-settings.h +98 -0
  225. package/native/core/include/ngn/layout-animations.h +24 -0
  226. package/native/core/include/ngn/library-components.h +13 -0
  227. package/native/core/include/ngn/library-glue.h +53 -0
  228. package/native/core/include/ngn/live-regions.h +54 -0
  229. package/native/core/include/ngn/local-authentication.h +74 -0
  230. package/native/core/include/ngn/location.h +89 -0
  231. package/native/core/include/ngn/maps.h +226 -0
  232. package/native/core/include/ngn/module-registry.h +51 -0
  233. package/native/core/include/ngn/mounting-backend.h +96 -0
  234. package/native/core/include/ngn/mounting-manager.h +155 -0
  235. package/native/core/include/ngn/native-controls.h +161 -0
  236. package/native/core/include/ngn/native-module.h +109 -0
  237. package/native/core/include/ngn/network-state.h +44 -0
  238. package/native/core/include/ngn/network.h +100 -0
  239. package/native/core/include/ngn/notifications.h +185 -0
  240. package/native/core/include/ngn/photo-library.h +130 -0
  241. package/native/core/include/ngn/printing.h +69 -0
  242. package/native/core/include/ngn/processes.h +114 -0
  243. package/native/core/include/ngn/red-box.h +119 -0
  244. package/native/core/include/ngn/reload-thread.h +258 -0
  245. package/native/core/include/ngn/runtime.h +161 -0
  246. package/native/core/include/ngn/safe-areas.h +77 -0
  247. package/native/core/include/ngn/screen-capture.h +35 -0
  248. package/native/core/include/ngn/screen-presentation.h +85 -0
  249. package/native/core/include/ngn/screen-stacks.h +80 -0
  250. package/native/core/include/ngn/scrollers.h +106 -0
  251. package/native/core/include/ngn/sharing.h +39 -0
  252. package/native/core/include/ngn/spawn-rules.h +78 -0
  253. package/native/core/include/ngn/splash-screen.h +41 -0
  254. package/native/core/include/ngn/split-view.h +270 -0
  255. package/native/core/include/ngn/sqlite.h +38 -0
  256. package/native/core/include/ngn/store-review.h +26 -0
  257. package/native/core/include/ngn/surface-book.h +101 -0
  258. package/native/core/include/ngn/svg.h +393 -0
  259. package/native/core/include/ngn/symbol.h +90 -0
  260. package/native/core/include/ngn/system.h +102 -0
  261. package/native/core/include/ngn/tabs-host.h +171 -0
  262. package/native/core/include/ngn/text-input.h +125 -0
  263. package/native/core/include/ngn/text-measurer.h +38 -0
  264. package/native/core/include/ngn/text-recognition.h +55 -0
  265. package/native/core/include/ngn/tracking.h +34 -0
  266. package/native/core/include/ngn/tray-and-dock.h +107 -0
  267. package/native/core/include/ngn/undo.h +37 -0
  268. package/native/core/include/ngn/updates.h +253 -0
  269. package/native/core/include/ngn/video.h +126 -0
  270. package/native/core/include/ngn/view-box.h +126 -0
  271. package/native/core/include/ngn/view-transform.h +26 -0
  272. package/native/core/include/ngn/view-tree.h +85 -0
  273. package/native/core/include/ngn/web-browser.h +45 -0
  274. package/native/core/include/ngn/web-view.h +133 -0
  275. package/native/core/include/ngn/worklet-host.h +98 -0
  276. package/native/core/src/absent-views.cpp +41 -0
  277. package/native/core/src/accessibility.cpp +374 -0
  278. package/native/core/src/animation-frames.cpp +49 -0
  279. package/native/core/src/app-menus.cpp +352 -0
  280. package/native/core/src/app-windows.cpp +444 -0
  281. package/native/core/src/back-swipe.cpp +91 -0
  282. package/native/core/src/bytes.cpp +158 -0
  283. package/native/core/src/control-sizes.cpp +232 -0
  284. package/native/core/src/default-menu.cpp +96 -0
  285. package/native/core/src/desktop-modal.cpp +162 -0
  286. package/native/core/src/desktop-view-props.cpp +80 -0
  287. package/native/core/src/dev-server-helper.cpp +152 -0
  288. package/native/core/src/dev-server.cpp +103 -0
  289. package/native/core/src/download.cpp +53 -0
  290. package/native/core/src/expo-image.cpp +548 -0
  291. package/native/core/src/expo-ui.cpp +203 -0
  292. package/native/core/src/focus-order.cpp +441 -0
  293. package/native/core/src/gestures.cpp +1806 -0
  294. package/native/core/src/glass.cpp +49 -0
  295. package/native/core/src/header-bar.cpp +104 -0
  296. package/native/core/src/host-services.cpp +50 -0
  297. package/native/core/src/host-state.cpp +61 -0
  298. package/native/core/src/input-dispatcher.cpp +727 -0
  299. package/native/core/src/input-script.cpp +123 -0
  300. package/native/core/src/key-value-store.cpp +169 -0
  301. package/native/core/src/launch-settings.cpp +148 -0
  302. package/native/core/src/layout-animations.cpp +62 -0
  303. package/native/core/src/libraries/RNCWebViewSpec.cpp +80 -0
  304. package/native/core/src/libraries/react-native-reanimated.cpp +216 -0
  305. package/native/core/src/libraries/react-native-worklets.cpp +192 -0
  306. package/native/core/src/libraries/rnscreens.cpp +125 -0
  307. package/native/core/src/libraries/rnsvg.cpp +345 -0
  308. package/native/core/src/libraries/safeareacontext.cpp +70 -0
  309. package/native/core/src/libraries/worklets-idle-frames.js +70 -0
  310. package/native/core/src/library-glue.cpp +35 -0
  311. package/native/core/src/live-regions.cpp +122 -0
  312. package/native/core/src/module-registry.cpp +50 -0
  313. package/native/core/src/modules/accessibility-manager.cpp +98 -0
  314. package/native/core/src/modules/address-search.cpp +219 -0
  315. package/native/core/src/modules/alert-manager.cpp +140 -0
  316. package/native/core/src/modules/app-info.cpp +74 -0
  317. package/native/core/src/modules/app-modules.cpp +405 -0
  318. package/native/core/src/modules/apple-authentication.cpp +188 -0
  319. package/native/core/src/modules/asset.cpp +111 -0
  320. package/native/core/src/modules/async-storage.cpp +192 -0
  321. package/native/core/src/modules/audio.cpp +541 -0
  322. package/native/core/src/modules/battery.cpp +88 -0
  323. package/native/core/src/modules/calendar.cpp +457 -0
  324. package/native/core/src/modules/camera.cpp +221 -0
  325. package/native/core/src/modules/core-modules.cpp +62 -0
  326. package/native/core/src/modules/crypto.cpp +117 -0
  327. package/native/core/src/modules/desktop-expo.cpp +527 -0
  328. package/native/core/src/modules/file-system.cpp +941 -0
  329. package/native/core/src/modules/fonts.cpp +163 -0
  330. package/native/core/src/modules/image-loader.cpp +105 -0
  331. package/native/core/src/modules/image-manipulator.cpp +305 -0
  332. package/native/core/src/modules/language-model.cpp +195 -0
  333. package/native/core/src/modules/local-authentication.cpp +140 -0
  334. package/native/core/src/modules/location.cpp +186 -0
  335. package/native/core/src/modules/maps.cpp +500 -0
  336. package/native/core/src/modules/network-state.cpp +72 -0
  337. package/native/core/src/modules/networking.cpp +387 -0
  338. package/native/core/src/modules/notifications.cpp +549 -0
  339. package/native/core/src/modules/photo-library.cpp +371 -0
  340. package/native/core/src/modules/printing.cpp +201 -0
  341. package/native/core/src/modules/screen-capture.cpp +71 -0
  342. package/native/core/src/modules/sharing.cpp +59 -0
  343. package/native/core/src/modules/splash-screen.cpp +70 -0
  344. package/native/core/src/modules/sqlite.cpp +421 -0
  345. package/native/core/src/modules/store-review.cpp +23 -0
  346. package/native/core/src/modules/text-recognition.cpp +107 -0
  347. package/native/core/src/modules/tracking.cpp +46 -0
  348. package/native/core/src/modules/undo.cpp +59 -0
  349. package/native/core/src/modules/video.cpp +366 -0
  350. package/native/core/src/modules/web-browser.cpp +100 -0
  351. package/native/core/src/modules/web-socket.cpp +266 -0
  352. package/native/core/src/mounting-manager.cpp +380 -0
  353. package/native/core/src/native-controls.cpp +129 -0
  354. package/native/core/src/native-module.cpp +250 -0
  355. package/native/core/src/network.cpp +219 -0
  356. package/native/core/src/posix-launcher.cpp +366 -0
  357. package/native/core/src/processes.cpp +324 -0
  358. package/native/core/src/red-box-errors.js +83 -0
  359. package/native/core/src/red-box.cpp +306 -0
  360. package/native/core/src/runtime.cpp +422 -0
  361. package/native/core/src/safe-areas.cpp +130 -0
  362. package/native/core/src/screen-presentation.cpp +61 -0
  363. package/native/core/src/screen-stacks.cpp +254 -0
  364. package/native/core/src/scrollers.cpp +181 -0
  365. package/native/core/src/spawn-rules.cpp +292 -0
  366. package/native/core/src/split-view.cpp +343 -0
  367. package/native/core/src/svg.cpp +1883 -0
  368. package/native/core/src/symbol.cpp +94 -0
  369. package/native/core/src/tabs-host.cpp +234 -0
  370. package/native/core/src/text-input.cpp +126 -0
  371. package/native/core/src/text-layout-manager.cpp +63 -0
  372. package/native/core/src/tray-and-dock.cpp +154 -0
  373. package/native/core/src/updates.cpp +965 -0
  374. package/native/core/src/view-box.cpp +788 -0
  375. package/native/core/src/view-transform.cpp +45 -0
  376. package/native/core/src/view-tree.cpp +234 -0
  377. package/native/core/src/web-view.cpp +143 -0
  378. package/native/core/src/worklet-host.cpp +10 -0
  379. package/native/scripts/build-hermes.sh +44 -0
  380. package/native/scripts/build.sh +171 -0
  381. package/native/scripts/cache-dir.sh +18 -0
  382. package/native/scripts/codegen-library.sh +193 -0
  383. package/native/scripts/compiler-launcher.sh +17 -0
  384. package/native/scripts/fetch.sh +174 -0
  385. package/native/scripts/hermes-built.sh +10 -0
  386. package/native/scripts/host-dir.sh +16 -0
  387. package/native/scripts/macos-target.sh +8 -0
  388. package/native/scripts/make-prebuilt.mjs +360 -0
  389. package/native/scripts/prebuilt-host-cache.mjs +158 -0
  390. package/native/shim/openssl/sha.h +22 -0
  391. package/native/shim/view-platform/react/renderer/components/view/HostPlatformViewTraitsInitializer.h +37 -0
  392. package/package.json +70 -3
  393. package/prebuilt.json +33 -0
@@ -0,0 +1,101 @@
1
+ // The surfaces a runtime has, kept apart from the runtime so a reload never makes the UI thread
2
+ // wait. While a reload runs, a surface started, stopped or resized is only written down here, and
3
+ // the reload brings the new runtime to match the book, step by step, before it ends. Not locked:
4
+ // the runtime holds its own lock around each call. Header-only, and toolkit-free.
5
+ #pragma once
6
+
7
+ #include <react/renderer/core/ReactPrimitives.h>
8
+
9
+ #include <map>
10
+ #include <optional>
11
+ #include <set>
12
+ #include <vector>
13
+
14
+ namespace ngn {
15
+
16
+ template <class Surface>
17
+ class SurfaceBook {
18
+ public:
19
+ // Each answers whether the caller should apply the change to the runtime now: not during a
20
+ // reload, which applies it.
21
+ bool start(facebook::react::SurfaceId id, Surface surface) {
22
+ surfaces_[id] = std::move(surface);
23
+ if (reloading_) {
24
+ changed_.insert(id);
25
+ }
26
+ return !reloading_;
27
+ }
28
+ bool stop(facebook::react::SurfaceId id) {
29
+ return surfaces_.erase(id) != 0 && !reloading_;
30
+ }
31
+ // Changes a surface the book has with `change`.
32
+ template <class Change>
33
+ bool update(facebook::react::SurfaceId id, Change change) {
34
+ auto it = surfaces_.find(id);
35
+ if (it == surfaces_.end()) {
36
+ return false;
37
+ }
38
+ change(it->second);
39
+ if (reloading_) {
40
+ changed_.insert(id);
41
+ }
42
+ return !reloading_;
43
+ }
44
+
45
+ bool reloading() const {
46
+ return reloading_;
47
+ }
48
+ // False when a reload is running already.
49
+ bool beginReload() {
50
+ if (reloading_) {
51
+ return false;
52
+ }
53
+ reloading_ = true;
54
+ return true;
55
+ }
56
+
57
+ struct Step {
58
+ std::vector<std::pair<facebook::react::SurfaceId, Surface>> start;
59
+ std::vector<facebook::react::SurfaceId> stop;
60
+ // Running surfaces the book changed since the reload started them, to apply as they are now.
61
+ std::vector<std::pair<facebook::react::SurfaceId, Surface>> update;
62
+ };
63
+ // What the reloaded runtime, running `started`, must start, stop and update to match the book.
64
+ // Nothing when it matches, which ends the reload: from then on changes are applied by their
65
+ // callers.
66
+ std::optional<Step> settle(const std::set<facebook::react::SurfaceId> &started) {
67
+ Step step;
68
+ for (const auto &[id, surface] : surfaces_) {
69
+ if (!started.contains(id)) {
70
+ step.start.emplace_back(id, surface);
71
+ } else if (changed_.contains(id)) {
72
+ step.update.emplace_back(id, surface);
73
+ }
74
+ }
75
+ for (auto id : started) {
76
+ if (!surfaces_.contains(id)) {
77
+ step.stop.push_back(id);
78
+ }
79
+ }
80
+ // A start or an update carries every change so far.
81
+ changed_.clear();
82
+ if (step.start.empty() && step.stop.empty() && step.update.empty()) {
83
+ reloading_ = false;
84
+ return std::nullopt;
85
+ }
86
+ return step;
87
+ }
88
+
89
+ // Every surface, for a reload with no runtime to restart them on.
90
+ const std::map<facebook::react::SurfaceId, Surface> &surfaces() const {
91
+ return surfaces_;
92
+ }
93
+
94
+ private:
95
+ std::map<facebook::react::SurfaceId, Surface> surfaces_;
96
+ // Surfaces started or changed during the reload, since the last step.
97
+ std::set<facebook::react::SurfaceId> changed_;
98
+ bool reloading_{false};
99
+ };
100
+
101
+ } // namespace ngn
@@ -0,0 +1,393 @@
1
+ // SVG as react-native-svg commits it: its host components' props read into a toolkit-free model,
2
+ // the path and paint model, and the drawing of a document onto a narrow canvas.
3
+ //
4
+ // react-native-svg mounts one view per element (RNSVGSvgView with RNSVGGroup, RNSVGPath and the
5
+ // rest under it). The core keeps each svg's elements as a document (SvgDrawings, below), and the
6
+ // backend's view for the RNSVGSvgView draws it by calling drawSvg with an SvgCanvas over its own
7
+ // graphics context. Everything SVG means (inheritance through `propList`, `currentColor`,
8
+ // lengths and percentages, the viewBox, path data and arcs, gradients and their units, clip
9
+ // paths, masks, `use` and `symbol`, markers, patterns and filters) is decided here; the canvas only
10
+ // draws paths, gradients, images and runs of text, tiles a pattern's tile, and runs a filter's
11
+ // steps over pixels with runSvgFilter.
12
+ #pragma once
13
+
14
+ #include "ngn/view-tree.h"
15
+
16
+ #include <react/renderer/core/Props.h>
17
+
18
+ #include <folly/dynamic.h>
19
+
20
+ #include <array>
21
+ #include <cstdint>
22
+ #include <functional>
23
+ #include <map>
24
+ #include <memory>
25
+ #include <optional>
26
+ #include <string>
27
+ #include <unordered_map>
28
+ #include <unordered_set>
29
+ #include <vector>
30
+
31
+ namespace ngn {
32
+
33
+ // An affine transform, as SVG's matrix(a b c d e f): x' = a*x + c*y + e, y' = b*x + d*y + f.
34
+ struct SvgMatrix {
35
+ double a{1}, b{0}, c{0}, d{1}, e{0}, f{0};
36
+
37
+ static SvgMatrix translate(double x, double y) { return {1, 0, 0, 1, x, y}; }
38
+ static SvgMatrix scale(double x, double y) { return {x, 0, 0, y, 0, 0}; }
39
+ // This transform applied after `inner`: (this * inner)(p) == this(inner(p)).
40
+ SvgMatrix operator*(const SvgMatrix &inner) const;
41
+ std::pair<double, double> apply(double x, double y) const;
42
+ bool operator==(const SvgMatrix &) const = default;
43
+ };
44
+
45
+ struct SvgRect {
46
+ double x{0}, y{0}, width{0}, height{0};
47
+ bool operator==(const SvgRect &) const = default;
48
+ };
49
+
50
+ // A path as moves, lines, cubic curves and closes: quadratics, smooth curves and arcs are
51
+ // converted as they are parsed.
52
+ struct SvgPath {
53
+ enum class Op { Move, Line, Cubic, Close };
54
+ struct Segment {
55
+ Op op;
56
+ // One point for Move and Line, three for Cubic (two controls, then the end), none for Close.
57
+ double points[6]{};
58
+ bool operator==(const Segment &) const = default;
59
+ };
60
+ std::vector<Segment> segments;
61
+
62
+ void moveTo(double x, double y);
63
+ void lineTo(double x, double y);
64
+ void cubicTo(double x1, double y1, double x2, double y2, double x, double y);
65
+ void close();
66
+ void append(const SvgPath &other, const SvgMatrix &transform);
67
+ bool empty() const { return segments.empty(); }
68
+ // The control-point bounds, which contain the curve; nothing for a path with no points.
69
+ std::optional<SvgRect> bounds() const;
70
+ bool operator==(const SvgPath &) const = default;
71
+ };
72
+
73
+ // SVG path data (`d`). Parsing stops at the first error, keeping what came before it, as browsers
74
+ // draw a path up to its first bad command.
75
+ SvgPath parseSvgPath(const std::string &d);
76
+
77
+ // A length as react-native-svg sends one: a number in user units, or a string with a unit.
78
+ struct SvgLength {
79
+ enum class Unit { User, Percent, Em };
80
+ double value{0};
81
+ Unit unit{Unit::User};
82
+ bool set{false};
83
+ bool operator==(const SvgLength &) const = default;
84
+ };
85
+ SvgLength svgLength(const folly::dynamic &value);
86
+ std::vector<SvgLength> svgLengths(const folly::dynamic &value);
87
+
88
+ // A fill or stroke: react-native-svg's brush ({type: 0, payload: color}, {type: 1, brushRef},
89
+ // {type: 2} for currentColor), or nothing set.
90
+ struct SvgBrush {
91
+ enum class Type { Unset, None, Color, CurrentColor, Ref };
92
+ Type type{Type::Unset};
93
+ uint32_t argb{0xff000000};
94
+ std::string ref;
95
+ bool operator==(const SvgBrush &) const = default;
96
+ };
97
+ SvgBrush svgBrush(const folly::dynamic &value);
98
+
99
+ enum class SvgKind {
100
+ Svg,
101
+ Group,
102
+ Path,
103
+ Rect,
104
+ Circle,
105
+ Ellipse,
106
+ Line,
107
+ Use,
108
+ Defs,
109
+ LinearGradient,
110
+ RadialGradient,
111
+ ClipPath,
112
+ Mask,
113
+ Symbol,
114
+ Image,
115
+ Text,
116
+ TSpan,
117
+ Marker,
118
+ Pattern,
119
+ Filter,
120
+ // A filter's steps.
121
+ FeGaussianBlur,
122
+ FeOffset,
123
+ FeColorMatrix,
124
+ FeFlood,
125
+ FeComposite,
126
+ FeMerge,
127
+ };
128
+
129
+ // One element's props, from its host component's.
130
+ struct SvgElement {
131
+ SvgKind kind{SvgKind::Group};
132
+ std::string name;
133
+
134
+ // Presentation. An attribute in `propList` is the element's own; any other is inherited from
135
+ // its parent where the parent has it, as react-native-svg merges them.
136
+ std::vector<std::string> propList;
137
+ SvgBrush fill;
138
+ double fillOpacity{1};
139
+ int fillRule{1}; // 0 evenodd, 1 nonzero
140
+ SvgBrush stroke;
141
+ double strokeOpacity{1};
142
+ SvgLength strokeWidth;
143
+ int strokeLinecap{0}; // butt, round, square
144
+ int strokeLinejoin{0}; // miter, round, bevel
145
+ std::vector<SvgLength> strokeDasharray;
146
+ double strokeDashoffset{0};
147
+ double strokeMiterlimit{4};
148
+ // `currentColor` for this element and what it contains, when it sets one.
149
+ std::optional<uint32_t> color;
150
+
151
+ double opacity{1};
152
+ std::optional<SvgMatrix> matrix;
153
+ std::string clipPath;
154
+ int clipRule{1};
155
+ std::string mask;
156
+ // The filter the element draws through, and the markers a shape draws at its vertices.
157
+ std::string filter;
158
+ std::string markerStart, markerMid, markerEnd;
159
+ bool hidden{false}; // display: none
160
+
161
+ // Geometry and positions by attribute name: x, y, width, height, rx, ry, cx, cy, r, x1, y1, x2,
162
+ // y2, fx, fy; a marker's refX, refY, markerWidth and markerHeight; an offset's dx and dy.
163
+ std::map<std::string, SvgLength> lengths;
164
+ std::string d;
165
+ std::string href;
166
+
167
+ // A gradient's stops (offset, ARGB), and its units (0 objectBoundingBox, 1 userSpaceOnUse); a
168
+ // mask's, a pattern's and a filter's units and content units the same way (a filter's content
169
+ // units are its primitiveUnits), and a mask's type (0 luminance, 1 alpha).
170
+ std::vector<std::pair<double, uint32_t>> stops;
171
+ int units{0};
172
+ int contentUnits{1};
173
+ int maskType{0};
174
+ // A gradient's gradientTransform or a pattern's patternTransform.
175
+ std::optional<SvgMatrix> gradientTransform;
176
+
177
+ // A marker's markerUnits ("strokeWidth", the default, or "userSpaceOnUse") and orient ("auto",
178
+ // "auto-start-reverse" or an angle in degrees).
179
+ std::string markerUnits;
180
+ std::string orient;
181
+
182
+ // A filter step: its inputs (SourceGraphic, SourceAlpha or an earlier step's result) and its own
183
+ // result's name; a colour matrix's type (0 matrix, 1 saturate, 2 hueRotate, 3 luminanceToAlpha)
184
+ // and values; a composite's operator (0 over, 1 in, 2 out, 3 atop, 4 xor, 5 arithmetic) and k1
185
+ // to k4; a blur's deviations; a flood's colour; a merge's inputs.
186
+ std::string in1, in2, result;
187
+ int op{0};
188
+ std::vector<double> values;
189
+ std::array<double, 4> k{};
190
+ double stdDeviationX{0}, stdDeviationY{0};
191
+ SvgBrush flood{.type = SvgBrush::Type::Color, .argb = 0xff000000};
192
+ double floodOpacity{1};
193
+ std::vector<std::string> nodes;
194
+
195
+ // The viewBox of an svg or a symbol, and how it fits; an image's fit uses align too.
196
+ double minX{0}, minY{0}, vbWidth{0}, vbHeight{0};
197
+ std::string align;
198
+ int meetOrSlice{0}; // meet, slice
199
+ SvgLength bbWidth, bbHeight;
200
+
201
+ std::string uri; // an image's source
202
+
203
+ // Text: a span's characters, the font, and the positions written on the element.
204
+ std::string content;
205
+ SvgLength fontSize;
206
+ std::string fontFamily;
207
+ std::string fontWeight;
208
+ std::vector<SvgLength> xs, ys, dxs, dys;
209
+
210
+ bool operator==(const SvgElement &) const = default;
211
+ };
212
+
213
+ struct SvgNode {
214
+ SvgElement element;
215
+ std::vector<SvgNode> children;
216
+ bool operator==(const SvgNode &) const = default;
217
+ };
218
+
219
+ // An svg and everything under it, as one RNSVGSvgView holds it.
220
+ struct SvgDocument {
221
+ SvgNode root;
222
+ bool operator==(const SvgDocument &) const = default;
223
+ };
224
+
225
+ // The transform that fits a viewBox into a viewport, as preserveAspectRatio says: `align` is
226
+ // "none" or xMin|xMid|xMax with YMin|YMid|YMax, and meetOrSlice 0 fits it in, 1 covers.
227
+ SvgMatrix svgViewBoxTransform(const SvgRect &viewBox, const std::string &align, int meetOrSlice, double width, double height);
228
+
229
+ // A gradient in user space, ready to draw.
230
+ struct SvgGradient {
231
+ bool radial{false};
232
+ // Linear: from (x1, y1) to (x2, y2). Radial: centre (x1, y1), focus (x2, y2), radius r.
233
+ double x1{0}, y1{0}, x2{0}, y2{0}, r{0};
234
+ std::vector<std::pair<double, uint32_t>> stops;
235
+ // From the gradient's own space to the user space it paints in.
236
+ SvgMatrix transform;
237
+ bool operator==(const SvgGradient &) const = default;
238
+ };
239
+
240
+ struct SvgPaint {
241
+ // A colour, or a gradient when `gradient` is set.
242
+ uint32_t argb{0xff000000};
243
+ std::optional<SvgGradient> gradient;
244
+ double opacity{1};
245
+ bool operator==(const SvgPaint &) const = default;
246
+ };
247
+
248
+ struct SvgStroke {
249
+ double width{1};
250
+ int cap{0};
251
+ int join{0};
252
+ double miterLimit{4};
253
+ std::vector<double> dashes;
254
+ double dashOffset{0};
255
+ bool operator==(const SvgStroke &) const = default;
256
+ };
257
+
258
+ // A marker drawn at a vertex of a shape: where, and its direction in degrees (SVG's `auto`), the
259
+ // bisector of the incoming and outgoing directions at a vertex between two segments.
260
+ struct SvgMarkerVertex {
261
+ enum class Place { Start, Mid, End };
262
+ Place place{Place::Mid};
263
+ double x{0}, y{0};
264
+ double angle{0};
265
+ bool operator==(const SvgMarkerVertex &) const = default;
266
+ };
267
+ // The vertices a path's markers are drawn at, in order: the first is the start, the last the end.
268
+ std::vector<SvgMarkerVertex> svgMarkerVertices(const SvgPath &path);
269
+
270
+ // A pattern's tile: what one tile covers in the pattern's own space, and from that space to the
271
+ // user space the pattern fills.
272
+ struct SvgPatternTile {
273
+ SvgRect tile;
274
+ SvgMatrix transform;
275
+ bool operator==(const SvgPatternTile &) const = default;
276
+ };
277
+
278
+ // A filter step as runSvgFilter runs it, its lengths in the user space of the element filtered.
279
+ struct SvgFilterStep {
280
+ enum class Type { GaussianBlur, Offset, ColorMatrix, Flood, Composite, Merge };
281
+ Type type{Type::Offset};
282
+ // Never empty: an input left out is the step before's result, or SourceGraphic for the first.
283
+ std::string in1, in2;
284
+ // What later steps name this one's result by: its own `result`, or "#" and its index.
285
+ std::string result;
286
+ std::vector<std::string> inputs; // a merge's
287
+ // Where the step draws; nothing outside it.
288
+ SvgRect subregion;
289
+ double stdDeviationX{0}, stdDeviationY{0};
290
+ double dx{0}, dy{0};
291
+ // A 4x5 colour matrix by rows (r, g, b, a), over unpremultiplied colour, its last column an
292
+ // offset in 0 to 1.
293
+ std::array<double, 20> matrix{};
294
+ uint32_t argb{0};
295
+ double opacity{1};
296
+ int op{0};
297
+ std::array<double, 4> k{};
298
+ bool operator==(const SvgFilterStep &) const = default;
299
+ };
300
+
301
+ struct SvgFilter {
302
+ // The filter region, in the element's user space: the result is cut to it.
303
+ SvgRect region;
304
+ std::vector<SvgFilterStep> steps;
305
+ bool operator==(const SvgFilter &) const = default;
306
+ };
307
+
308
+ // A colour matrix step's 4x5 matrix for its type and values, as SVG defines saturate, hueRotate
309
+ // and luminanceToAlpha; the identity for a `matrix` without 20 values.
310
+ std::array<double, 20> svgColorMatrix(int type, const std::vector<double> &values);
311
+
312
+ // Pixels, premultiplied RGBA, 8 bits a channel, rows from the top.
313
+ struct SvgPixels {
314
+ int width{0}, height{0};
315
+ std::vector<uint8_t> rgba;
316
+ };
317
+
318
+ // Runs `filter` over `source`, the element as drawn (SourceGraphic), whose pixels `toPixels` maps
319
+ // the element's user space to. Lengths and offsets scale with the transform; a subregion or the
320
+ // region is cut to its bounds in pixels.
321
+ SvgPixels runSvgFilter(const SvgFilter &filter, const SvgPixels &source, const SvgMatrix &toPixels);
322
+
323
+ // The drawing calls a backend makes for drawSvg, in a graphics state it saves and restores.
324
+ class SvgCanvas {
325
+ public:
326
+ virtual ~SvgCanvas() = default;
327
+ virtual void save() = 0;
328
+ virtual void restore() = 0;
329
+ virtual void concat(const SvgMatrix &matrix) = 0;
330
+ virtual void clip(const SvgPath &path, bool evenOdd) = 0;
331
+ virtual void fill(const SvgPath &path, bool evenOdd, const SvgPaint &paint) = 0;
332
+ virtual void stroke(const SvgPath &path, const SvgStroke &stroke, const SvgPaint &paint) = 0;
333
+ // What is drawn until endLayer is composited as one, at `opacity`.
334
+ virtual void beginLayer(double opacity) = 0;
335
+ virtual void endLayer() = 0;
336
+ // What is drawn until endMask is the mask (its luminance, or its alpha for an alpha mask); then
337
+ // what is drawn until endMasked shows through it.
338
+ virtual void beginMask(bool alpha) = 0;
339
+ virtual void endMask() = 0;
340
+ virtual void endMasked() = 0;
341
+ // Clips to the outline `stroke` would draw of `path`.
342
+ virtual void clipToStroke(const SvgPath &path, const SvgStroke &stroke) = 0;
343
+ // Fills the clip with `tile` repeated, at `opacity`: `drawTile` draws one tile's content on a
344
+ // canvas whose origin is the tile's, in the pattern's own space.
345
+ virtual void pattern(const SvgPatternTile &tile, double opacity, const std::function<void(SvgCanvas &)> &drawTile) = 0;
346
+ // What is drawn until endFilter is the source of `filter`, whose result is drawn in its place.
347
+ virtual void beginFilter(const SvgFilter &filter) = 0;
348
+ virtual void endFilter() = 0;
349
+ virtual void image(const std::string &uri, const SvgRect &rect, const std::string &align, int meetOrSlice, double opacity) = 0;
350
+ // Draws `text` with its baseline's start at (x, y) and answers its advance.
351
+ virtual double text(
352
+ const std::string &text,
353
+ double x,
354
+ double y,
355
+ double fontSize,
356
+ const std::string &fontFamily,
357
+ const std::string &fontWeight,
358
+ const SvgPaint *fill) = 0;
359
+ };
360
+
361
+ // Draws `document` into a viewport of `width` by `height`, its origin at the canvas's.
362
+ void drawSvg(const SvgDocument &document, double width, double height, SvgCanvas &canvas);
363
+
364
+ // The svgs of a surface's views, kept by the mounting manager as it mounts them: which svg each
365
+ // change belongs to, and each svg's document when it changed.
366
+ class SvgDrawings {
367
+ public:
368
+ // The element a view's props are, or nothing for a view that is not an svg element.
369
+ // react-native-svg's glue (core/src/libraries/rnsvg.cpp) reads its props.
370
+ using Reader = std::function<std::optional<SvgElement>(const facebook::react::Props &)>;
371
+ explicit SvgDrawings(Reader reader = nullptr);
372
+
373
+ // A view was made or its props changed, or `parent`'s children changed.
374
+ void changed(const ViewTree &tree, Tag tag);
375
+ void deleted(Tag tag);
376
+
377
+ struct Drawing {
378
+ Tag svg{-1};
379
+ std::shared_ptr<const SvgDocument> document;
380
+ };
381
+ // The svgs whose documents changed since the last call.
382
+ std::vector<Drawing> settle(const ViewTree &tree);
383
+
384
+ private:
385
+ std::optional<SvgElement> element(const ViewTree &tree, Tag tag) const;
386
+ std::optional<SvgNode> node(const ViewTree &tree, Tag tag) const;
387
+
388
+ Reader reader_;
389
+ std::unordered_set<Tag> dirty_;
390
+ std::unordered_map<Tag, std::shared_ptr<const SvgDocument>> drawn_;
391
+ };
392
+
393
+ } // namespace ngn
@@ -0,0 +1,90 @@
1
+ // `<expo-symbol>` on a desktop host: expo-symbols' view (ViewManagerAdapter_SymbolModule, the
2
+ // component `registerExpoViews('expo-symbol')` commits) as a Fabric component, and the
3
+ // NgNativeSymbol module that sizes it, as @ng-native/expo's iOS module does.
4
+ //
5
+ // The core reads the props and decides what is drawn where: the paint (expo-symbols' type, tint
6
+ // and palette as a rendering mode and its colours) and the symbol's rectangle in the view, as
7
+ // UIKit's content mode `resizeMode` names places an image. The backend's view draws the SF Symbol
8
+ // with its toolkit at the system font size, as expo-symbols builds it, scaled into that rectangle.
9
+ //
10
+ // - NgNativeSymbol.imageSize(name, pointSize, weight, scale): [width, height] of the symbol's image
11
+ // at that point size, or null for a name the OS has no symbol for.
12
+ #pragma once
13
+
14
+ #include "ngn/desktop-props.h"
15
+ #include "ngn/native-module.h"
16
+
17
+ #include <react/renderer/components/view/ConcreteViewShadowNode.h>
18
+ #include <react/renderer/components/view/ViewEventEmitter.h>
19
+ #include <react/renderer/components/view/ViewProps.h>
20
+ #include <react/renderer/core/ConcreteComponentDescriptor.h>
21
+ #include <react/renderer/graphics/Color.h>
22
+
23
+ #include <memory>
24
+ #include <optional>
25
+ #include <string>
26
+ #include <string_view>
27
+ #include <utility>
28
+ #include <vector>
29
+
30
+ namespace ngn {
31
+
32
+ extern const char SymbolComponentName[];
33
+
34
+ class SymbolProps final : public facebook::react::ViewProps, public HasDesktopProps {
35
+ public:
36
+ SymbolProps() = default;
37
+ SymbolProps(
38
+ const facebook::react::PropsParserContext &context,
39
+ const SymbolProps &sourceProps,
40
+ const facebook::react::RawProps &rawProps);
41
+
42
+ std::string name;
43
+ // `monochrome`, `hierarchical`, `palette` or `multicolor`.
44
+ std::string type{"monochrome"};
45
+ // expo-symbols' scale and weight names; empty for the default.
46
+ std::string scale;
47
+ std::string weight;
48
+ facebook::react::SharedColor tintColor;
49
+ std::vector<facebook::react::SharedColor> colors;
50
+ // UIKit's content modes by name; empty for `scaleAspectFit`.
51
+ std::string resizeMode;
52
+ };
53
+
54
+ using SymbolShadowNode =
55
+ facebook::react::ConcreteViewShadowNode<SymbolComponentName, SymbolProps, facebook::react::ViewEventEmitter>;
56
+ using SymbolComponentDescriptor = facebook::react::ConcreteComponentDescriptor<SymbolShadowNode>;
57
+
58
+ // How the symbol's layers are coloured, as expo-symbols configures it.
59
+ struct SymbolPaint {
60
+ enum class Mode { Monochrome, Hierarchical, Palette, Multicolor };
61
+ Mode mode{Mode::Monochrome};
62
+ // Monochrome: the one colour, or none for the label colour. Hierarchical: the one colour, or
63
+ // none for the system blue. Palette: two or more. Multicolor: the tint for the layers with no
64
+ // colour of their own, or none.
65
+ std::vector<facebook::react::SharedColor> colors;
66
+ };
67
+
68
+ SymbolPaint symbolPaint(const SymbolProps &props);
69
+
70
+ struct SymbolRect {
71
+ double x{0}, y{0}, width{0}, height{0};
72
+ bool operator==(const SymbolRect &) const = default;
73
+ };
74
+
75
+ // Where an image of `image` size draws in a view of `box` size, from its top left, as UIKit's
76
+ // content mode `resizeMode` places it: scaled to fill, to fit, to fill keeping its ratio, or at its
77
+ // own size at the centre, an edge or a corner. An empty or unknown mode fits it.
78
+ SymbolRect placeSymbol(std::string_view resizeMode, std::pair<double, double> image, std::pair<double, double> box);
79
+
80
+ class SymbolMeasurer {
81
+ public:
82
+ virtual ~SymbolMeasurer() = default;
83
+ // The size of the symbol's image at `pointSize`, or nothing for a name with no symbol.
84
+ virtual std::optional<std::pair<double, double>> imageSize(
85
+ const std::string &name, double pointSize, const std::string &weight, const std::string &scale) = 0;
86
+ };
87
+
88
+ std::shared_ptr<NativeModule> makeSymbolModule(std::shared_ptr<SymbolMeasurer> measurer);
89
+
90
+ } // namespace ngn
@@ -0,0 +1,102 @@
1
+ // The system interface: the OS calls the core's modules make, which a backend answers with the
2
+ // toolkit's own (NSWorkspace, NSAlert, NSPasteboard, NSUserDefaults on macOS). Narrow on purpose:
3
+ // the logic around each call (what JavaScript asked, what it gets back, what persists) is core
4
+ // code, the same on every backend.
5
+ #pragma once
6
+
7
+ #include <folly/dynamic.h>
8
+
9
+ #include <functional>
10
+ #include <optional>
11
+ #include <string>
12
+ #include <vector>
13
+
14
+ namespace ngn {
15
+
16
+ struct DeviceFacts {
17
+ // "26.1"
18
+ std::string osVersion;
19
+ // "macOS"
20
+ std::string systemName;
21
+ // A BCP 47 identifier such as "en-GB" (React Native's localeIdentifier uses an underscore).
22
+ std::string locale;
23
+ // The system's layout direction for the app's preferred language.
24
+ bool rightToLeft{false};
25
+ };
26
+
27
+ enum class AlertButtonRole { Default, Cancel, Destructive };
28
+ enum class AlertInput { None, PlainText, SecureText, LoginPassword };
29
+
30
+ struct AlertButton {
31
+ std::string label;
32
+ AlertButtonRole role{AlertButtonRole::Default};
33
+ };
34
+
35
+ struct AlertRequest {
36
+ std::string title;
37
+ std::string message;
38
+ // Right to left, as AppKit places them: the first is the default button (Return).
39
+ std::vector<AlertButton> buttons;
40
+ // The button Escape presses, or -1.
41
+ int cancelIndex{-1};
42
+ AlertInput input{AlertInput::None};
43
+ std::string defaultValue;
44
+ };
45
+
46
+ // How an announcement takes its turn with what a screen reader is saying: low and medium wait for
47
+ // it, high interrupts.
48
+ enum class AnnouncementPriority { Low, Medium, High };
49
+
50
+ struct Announcement {
51
+ std::string text;
52
+ AnnouncementPriority priority{AnnouncementPriority::High};
53
+ bool operator==(const Announcement &) const = default;
54
+ };
55
+
56
+ class System {
57
+ public:
58
+ virtual ~System() = default;
59
+
60
+ virtual DeviceFacts facts() = 0;
61
+
62
+ // Opens a URL in the app that handles it. `done` gets whether one did; any thread.
63
+ virtual void openUrl(const std::string &url, std::function<void(bool opened)> done) = 0;
64
+ virtual bool canOpenUrl(const std::string &url) = 0;
65
+ virtual void openSettings(std::function<void(bool opened)> done) = 0;
66
+
67
+ // "light" or "dark", as the system draws the app now (an override included).
68
+ virtual std::string colorScheme() = 0;
69
+ // Draws the app in `scheme` ("light" or "dark"), or follows the system again for nothing. Once the
70
+ // change applies, `applied` gets the scheme that change applied (for nothing, the system's scheme
71
+ // read as it applies), on the thread that applies the changes in order: a later change's answer
72
+ // always comes after an earlier one's, and an earlier one's is never the later one's scheme.
73
+ virtual void setColorScheme(std::optional<std::string> scheme, std::function<void(std::string)> applied) = 0;
74
+
75
+ // `done` gets the index of the button pressed and the text typed: for a login-password prompt,
76
+ // the login as `text` and the password beside it. Any thread.
77
+ virtual void showAlert(
78
+ const AlertRequest &request,
79
+ std::function<void(int button, std::string text, std::string password)> done) = 0;
80
+
81
+ virtual std::optional<std::string> clipboardText() = 0;
82
+ virtual void setClipboardText(const std::string &text) = 0;
83
+ // A number that moves each time anything (this app or another) changes the clipboard.
84
+ virtual int64_t clipboardChangeCount() = 0;
85
+
86
+ // Small values that persist across launches (NSUserDefaults on macOS).
87
+ virtual std::optional<folly::dynamic> preference(const std::string &key) = 0;
88
+ virtual void setPreference(const std::string &key, std::optional<folly::dynamic> value) = 0;
89
+
90
+ // The pixel size of an encoded image (PNG, JPEG, GIF, HEIC and what else the OS decodes), or
91
+ // nothing when it is not one.
92
+ virtual std::optional<std::pair<double, double>> imageSize(const std::string &bytes) = 0;
93
+
94
+ // Has the screen reader say `announcement` (NSAccessibilityAnnouncementRequestedNotification on
95
+ // macOS). Nothing is said when none is running.
96
+ virtual void announce(const Announcement &announcement) = 0;
97
+
98
+ // Where the app keeps its own files, created if missing.
99
+ virtual std::string appDataDirectory() = 0;
100
+ };
101
+
102
+ } // namespace ngn