@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,403 @@
1
+ #import "system.h"
2
+ #import "test-launch.h"
3
+
4
+ #import <AppKit/AppKit.h>
5
+ #import <ImageIO/ImageIO.h>
6
+
7
+ #include <folly/json.h>
8
+
9
+ #include <atomic>
10
+ #include <mutex>
11
+
12
+ namespace {
13
+
14
+ NSString *ns(const std::string &s) {
15
+ NSString *out = [NSString stringWithUTF8String:s.c_str()];
16
+ return out != nil ? out : @"";
17
+ }
18
+
19
+ std::string str(NSString *s) {
20
+ return s ? std::string(s.UTF8String) : std::string();
21
+ }
22
+
23
+ std::string schemeOf(NSAppearance *appearance) {
24
+ NSAppearanceName match = [appearance bestMatchFromAppearancesWithNames:@[ NSAppearanceNameAqua, NSAppearanceNameDarkAqua ]];
25
+ return [match isEqualToString:NSAppearanceNameDarkAqua] ? "dark" : "light";
26
+ }
27
+
28
+ void onMain(dispatch_block_t block) {
29
+ if (NSThread.isMainThread) {
30
+ block();
31
+ } else {
32
+ dispatch_async(dispatch_get_main_queue(), block);
33
+ }
34
+ }
35
+
36
+ } // namespace
37
+
38
+ namespace ngn::appkit {
39
+
40
+ void postAnnouncement(const Announcement &announcement) {
41
+ NSString *text = ns(announcement.text);
42
+ NSAccessibilityPriorityLevel priority = announcement.priority == AnnouncementPriority::Low ? NSAccessibilityPriorityLow
43
+ : announcement.priority == AnnouncementPriority::Medium ? NSAccessibilityPriorityMedium
44
+ : NSAccessibilityPriorityHigh;
45
+ onMain(^{
46
+ // Posted on the application element, as VoiceOver reads it whichever window is in front.
47
+ NSAccessibilityPostNotificationWithUserInfo(
48
+ NSApp,
49
+ NSAccessibilityAnnouncementRequestedNotification,
50
+ @{NSAccessibilityAnnouncementKey : text, NSAccessibilityPriorityKey : @(priority)});
51
+ });
52
+ }
53
+
54
+ class AppKitSystem final : public System {
55
+ public:
56
+ explicit AppKitSystem(std::string appId) : appId_(std::move(appId)) {
57
+ // Read once here on the main thread; JavaScript asks from its own.
58
+ systemScheme_ = schemeOf(NSApp.effectiveAppearance);
59
+ rightToLeft_ = NSApp.userInterfaceLayoutDirection == NSUserInterfaceLayoutDirectionRightToLeft;
60
+ }
61
+
62
+ DeviceFacts facts() override {
63
+ NSOperatingSystemVersion v = NSProcessInfo.processInfo.operatingSystemVersion;
64
+ std::string version = std::to_string(v.majorVersion) + "." + std::to_string(v.minorVersion);
65
+ if (v.patchVersion != 0) {
66
+ version += "." + std::to_string(v.patchVersion);
67
+ }
68
+ NSString *language = NSLocale.preferredLanguages.firstObject;
69
+ if (language == nil) {
70
+ language = NSLocale.currentLocale.localeIdentifier;
71
+ }
72
+ return {.osVersion = version, .systemName = "macOS", .locale = str(language), .rightToLeft = rightToLeft_};
73
+ }
74
+
75
+ void openUrl(const std::string &url, std::function<void(bool)> done) override {
76
+ NSURL *u = [NSURL URLWithString:ns(url)];
77
+ if (u == nil) {
78
+ done(false);
79
+ return;
80
+ }
81
+ auto shared = std::make_shared<std::function<void(bool)>>(std::move(done));
82
+ onMain(^{
83
+ [NSWorkspace.sharedWorkspace openURL:u
84
+ configuration:[NSWorkspaceOpenConfiguration configuration]
85
+ completionHandler:^(NSRunningApplication *app, NSError *error) {
86
+ (*shared)(error == nil);
87
+ }];
88
+ });
89
+ }
90
+
91
+ bool canOpenUrl(const std::string &url) override {
92
+ NSURL *u = [NSURL URLWithString:ns(url)];
93
+ return u != nil && [NSWorkspace.sharedWorkspace URLForApplicationToOpenURL:u] != nil;
94
+ }
95
+
96
+ void openSettings(std::function<void(bool)> done) override {
97
+ // A Mac app has no settings page of its own in System Settings; this opens System Settings.
98
+ openUrl("x-apple.systempreferences:", std::move(done));
99
+ }
100
+
101
+ std::string colorScheme() override {
102
+ std::lock_guard lock(mutex_);
103
+ return override_.value_or(systemScheme_);
104
+ }
105
+
106
+ void setColorScheme(std::optional<std::string> scheme, std::function<void(std::string)> applied) override {
107
+ {
108
+ std::lock_guard lock(mutex_);
109
+ override_ = scheme;
110
+ }
111
+ auto told = std::make_shared<std::function<void(std::string)>>(std::move(applied));
112
+ onMain(^{
113
+ NSApp.appearance = !scheme ? nil
114
+ : *scheme == "dark" ? [NSAppearance appearanceNamed:NSAppearanceNameDarkAqua]
115
+ : [NSAppearance appearanceNamed:NSAppearanceNameAqua];
116
+ // The system's scheme is not followed while an override holds: read it again as it goes,
117
+ // since the app's appearance may not change and so tell nothing.
118
+ if (!scheme) {
119
+ systemSchemeChanged(schemeOf(NSApp.effectiveAppearance));
120
+ }
121
+ // The scheme this change applied, not the latest override: a later change queued behind
122
+ // this one has set override_ already, and tells its own scheme when it applies.
123
+ if (*told) {
124
+ std::string applied;
125
+ {
126
+ std::lock_guard lock(mutex_);
127
+ applied = scheme.value_or(systemScheme_);
128
+ }
129
+ (*told)(applied);
130
+ }
131
+ });
132
+ }
133
+
134
+ // The system's own scheme, with no override. Main thread.
135
+ void systemSchemeChanged(std::string scheme) {
136
+ std::lock_guard lock(mutex_);
137
+ systemScheme_ = std::move(scheme);
138
+ }
139
+
140
+ void showAlert(const AlertRequest &request, std::function<void(int, std::string, std::string)> done) override {
141
+ auto shared = std::make_shared<std::function<void(int, std::string, std::string)>>(std::move(done));
142
+ AlertRequest r = request;
143
+ onMain(^{
144
+ NSAlert *alert = [NSAlert new];
145
+ alert.messageText = ns(r.title);
146
+ alert.informativeText = ns(r.message);
147
+ for (size_t i = 0; i < r.buttons.size(); i++) {
148
+ NSButton *button = [alert addButtonWithTitle:ns(r.buttons[i].label)];
149
+ if (r.buttons[i].role == AlertButtonRole::Destructive) {
150
+ button.hasDestructiveAction = YES;
151
+ }
152
+ if ((int)i == r.cancelIndex && i != 0) {
153
+ button.keyEquivalent = @"\033";
154
+ }
155
+ }
156
+ NSTextField *field = nil;
157
+ NSSecureTextField *password = nil;
158
+ if (r.input != AlertInput::None) {
159
+ field = r.input == AlertInput::SecureText ? [NSSecureTextField new] : [NSTextField new];
160
+ field.stringValue = ns(r.defaultValue);
161
+ field.frame = NSMakeRect(0, 0, 240, 24);
162
+ alert.accessoryView = field;
163
+ alert.window.initialFirstResponder = field;
164
+ }
165
+ // A login-password prompt: the login above, the password below it, as iOS shows them.
166
+ if (r.input == AlertInput::LoginPassword) {
167
+ field.placeholderString = @"Login";
168
+ password = [NSSecureTextField new];
169
+ password.placeholderString = @"Password";
170
+ password.frame = NSMakeRect(0, 0, 240, 24);
171
+ field.frame = NSMakeRect(0, 32, 240, 24);
172
+ NSView *fields = [[NSView alloc] initWithFrame:NSMakeRect(0, 0, 240, 56)];
173
+ [fields addSubview:field];
174
+ [fields addSubview:password];
175
+ field.nextKeyView = password;
176
+ alert.accessoryView = fields;
177
+ }
178
+ void (^finish)(NSModalResponse) = ^(NSModalResponse response) {
179
+ int index = (int)(response - NSAlertFirstButtonReturn);
180
+ (*shared)(index, field ? str(field.stringValue) : "", password ? str(password.stringValue) : "");
181
+ };
182
+ // A sheet on the key window; with none (a menu-bar app, or every window closed) the alert
183
+ // runs app-modally, so the answer always arrives.
184
+ NSWindow *key = NSApp.keyWindow;
185
+ if (key != nil && key.attachedSheet == nil) {
186
+ [alert beginSheetModalForWindow:key completionHandler:finish];
187
+ } else {
188
+ finish([alert runModal]);
189
+ }
190
+ });
191
+ }
192
+
193
+ std::optional<std::string> clipboardText() override {
194
+ NSString *text = [NSPasteboard.generalPasteboard stringForType:NSPasteboardTypeString];
195
+ if (text == nil) {
196
+ return std::nullopt;
197
+ }
198
+ return str(text);
199
+ }
200
+
201
+ void setClipboardText(const std::string &text) override {
202
+ NSPasteboard *board = NSPasteboard.generalPasteboard;
203
+ [board clearContents];
204
+ [board setString:ns(text) forType:NSPasteboardTypeString];
205
+ }
206
+
207
+ int64_t clipboardChangeCount() override {
208
+ return NSPasteboard.generalPasteboard.changeCount;
209
+ }
210
+
211
+ std::optional<folly::dynamic> preference(const std::string &key) override {
212
+ NSString *json = [appDefaults() stringForKey:ns(prefixed(key))];
213
+ if (json == nil) {
214
+ return std::nullopt;
215
+ }
216
+ try {
217
+ return folly::parseJson(str(json));
218
+ } catch (...) {
219
+ return std::nullopt;
220
+ }
221
+ }
222
+
223
+ void setPreference(const std::string &key, std::optional<folly::dynamic> value) override {
224
+ NSUserDefaults *defaults = appDefaults();
225
+ if (value) {
226
+ [defaults setObject:ns(folly::toJson(*value)) forKey:ns(prefixed(key))];
227
+ } else {
228
+ [defaults removeObjectForKey:ns(prefixed(key))];
229
+ }
230
+ }
231
+
232
+ void announce(const Announcement &announcement) override {
233
+ postAnnouncement(announcement);
234
+ }
235
+
236
+ std::optional<std::pair<double, double>> imageSize(const std::string &bytes) override {
237
+ NSData *data = [NSData dataWithBytesNoCopy:(void *)bytes.data() length:bytes.size() freeWhenDone:NO];
238
+ CGImageSourceRef source = CGImageSourceCreateWithData((__bridge CFDataRef)data, nullptr);
239
+ if (source == nullptr) {
240
+ return std::nullopt;
241
+ }
242
+ std::optional<std::pair<double, double>> size;
243
+ if (CGImageSourceGetCount(source) > 0) {
244
+ NSDictionary *props = (__bridge_transfer NSDictionary *)CGImageSourceCopyPropertiesAtIndex(source, 0, nullptr);
245
+ NSNumber *w = props[(__bridge NSString *)kCGImagePropertyPixelWidth];
246
+ NSNumber *h = props[(__bridge NSString *)kCGImagePropertyPixelHeight];
247
+ if (w != nil && h != nil) {
248
+ size = std::pair{w.doubleValue, h.doubleValue};
249
+ }
250
+ }
251
+ CFRelease(source);
252
+ return size;
253
+ }
254
+
255
+ std::string appDataDirectory() override {
256
+ NSURL *support = testLaunch() ? [NSURL fileURLWithPath:ns(testLaunch()->applicationSupport()) isDirectory:YES]
257
+ : [NSFileManager.defaultManager URLsForDirectory:NSApplicationSupportDirectory
258
+ inDomains:NSUserDomainMask]
259
+ .firstObject;
260
+ NSString *bundleId = NSBundle.mainBundle.bundleIdentifier;
261
+ NSURL *dir = [support URLByAppendingPathComponent:bundleId != nil ? bundleId : ns(appId_) isDirectory:YES];
262
+ [NSFileManager.defaultManager createDirectoryAtURL:dir withIntermediateDirectories:YES attributes:nil error:nil];
263
+ return str(dir.path);
264
+ }
265
+
266
+ private:
267
+ // A bare host binary has no bundle identifier, so every app run with it would share one
268
+ // defaults domain: the app's id keeps them apart.
269
+ std::string prefixed(const std::string &key) const {
270
+ return NSBundle.mainBundle.bundleIdentifier ? key : appId_ + "." + key;
271
+ }
272
+
273
+ std::string appId_;
274
+ std::mutex mutex_;
275
+ std::string systemScheme_;
276
+ std::optional<std::string> override_;
277
+ bool rightToLeft_{false};
278
+ };
279
+
280
+ std::shared_ptr<System> makeSystem(std::string appId) {
281
+ return std::make_shared<AppKitSystem>(std::move(appId));
282
+ }
283
+
284
+ } // namespace ngn::appkit
285
+
286
+ // Observes the app for watchApp. Kept alive for the process.
287
+ @interface NGNAppObserver : NSObject
288
+ @property (nonatomic) std::shared_ptr<ngn::HostState> state;
289
+ @property (nonatomic) std::shared_ptr<ngn::appkit::AppKitSystem> system;
290
+ @property (nonatomic) BOOL launched;
291
+ @end
292
+
293
+ @implementation NGNAppObserver
294
+
295
+ - (void)start {
296
+ NSNotificationCenter *center = NSNotificationCenter.defaultCenter;
297
+ for (NSNotificationName name in @[
298
+ NSApplicationDidBecomeActiveNotification, NSApplicationDidResignActiveNotification,
299
+ NSApplicationDidHideNotification, NSApplicationDidUnhideNotification
300
+ ]) {
301
+ [center addObserver:self selector:@selector(activityChanged) name:name object:nil];
302
+ }
303
+ [center addObserver:self selector:@selector(didLaunch) name:NSApplicationDidFinishLaunchingNotification object:nil];
304
+ // The pasteboard posts no change notification, and polling it would wake an idle app. It is
305
+ // checked where a change can come from: another app while this one was away (on becoming
306
+ // active), and this app's own key presses, clicks and menu commands, after each is handled.
307
+ self.state->clipboardChangeCount.set(NSPasteboard.generalPasteboard.changeCount);
308
+ [center addObserver:self selector:@selector(checkClipboard) name:NSMenuDidSendActionNotification object:nil];
309
+ __weak NGNAppObserver *weakSelf = self;
310
+ [NSEvent addLocalMonitorForEventsMatchingMask:NSEventMaskKeyDown | NSEventMaskLeftMouseUp | NSEventMaskRightMouseUp
311
+ handler:^NSEvent *(NSEvent *event) {
312
+ dispatch_async(dispatch_get_main_queue(), ^{
313
+ [weakSelf checkClipboard];
314
+ });
315
+ return event;
316
+ }];
317
+ [NSApp addObserver:self forKeyPath:@"effectiveAppearance" options:NSKeyValueObservingOptionNew context:nil];
318
+ // The display options post a notification as any of them changes, and VoiceOver's state is
319
+ // key-value observable, so nothing polls.
320
+ NSWorkspace *workspace = NSWorkspace.sharedWorkspace;
321
+ [workspace.notificationCenter addObserver:self
322
+ selector:@selector(accessibilityChanged)
323
+ name:NSWorkspaceAccessibilityDisplayOptionsDidChangeNotification
324
+ object:nil];
325
+ [workspace addObserver:self forKeyPath:@"voiceOverEnabled" options:NSKeyValueObservingOptionNew context:nil];
326
+ [self accessibilityChanged];
327
+ [NSAppleEventManager.sharedAppleEventManager setEventHandler:self
328
+ andSelector:@selector(handleURL:withReply:)
329
+ forEventClass:kInternetEventClass
330
+ andEventID:kAEGetURL];
331
+ self.state->colorScheme.set(self.system->colorScheme());
332
+ }
333
+
334
+ - (void)didLaunch {
335
+ self.launched = YES;
336
+ }
337
+
338
+ - (void)checkClipboard {
339
+ self.state->clipboardChangeCount.set(NSPasteboard.generalPasteboard.changeCount);
340
+ }
341
+
342
+ - (void)activityChanged {
343
+ if (NSApp.isActive) {
344
+ [self checkClipboard];
345
+ }
346
+ ngn::Activity activity = NSApp.isHidden ? ngn::Activity::Background
347
+ : NSApp.isActive ? ngn::Activity::Active
348
+ : ngn::Activity::Inactive;
349
+ self.state->activity.set(activity);
350
+ }
351
+
352
+ // macOS has no bold-text or grayscale setting an app can read, so those stay off.
353
+ - (void)accessibilityChanged {
354
+ NSWorkspace *workspace = NSWorkspace.sharedWorkspace;
355
+ self.state->accessibility.set({
356
+ .screenReader = (bool)workspace.voiceOverEnabled,
357
+ .reduceMotion = (bool)workspace.accessibilityDisplayShouldReduceMotion,
358
+ .reduceTransparency = (bool)workspace.accessibilityDisplayShouldReduceTransparency,
359
+ .invertColors = (bool)workspace.accessibilityDisplayShouldInvertColors,
360
+ .increaseContrast = (bool)workspace.accessibilityDisplayShouldIncreaseContrast,
361
+ });
362
+ }
363
+
364
+ - (void)observeValueForKeyPath:(NSString *)keyPath
365
+ ofObject:(id)object
366
+ change:(NSDictionary *)change
367
+ context:(void *)context {
368
+ if ([keyPath isEqualToString:@"voiceOverEnabled"]) {
369
+ // KVO may call on another thread; the host state is set from the main thread.
370
+ dispatch_async(dispatch_get_main_queue(), ^{
371
+ [self accessibilityChanged];
372
+ });
373
+ return;
374
+ }
375
+ // With no override of the app's own, what the app draws in is the system's scheme.
376
+ if (NSApp.appearance == nil) {
377
+ self.system->systemSchemeChanged(schemeOf(NSApp.effectiveAppearance));
378
+ }
379
+ self.state->colorScheme.set(self.system->colorScheme());
380
+ }
381
+
382
+ - (void)handleURL:(NSAppleEventDescriptor *)event withReply:(NSAppleEventDescriptor *)reply {
383
+ NSString *url = [event paramDescriptorForKeyword:keyDirectObject].stringValue;
384
+ if (url == nil) {
385
+ return;
386
+ }
387
+ // A URL that launched the app is its initial URL; later ones are events.
388
+ self.state->receiveUrl(str(url), self.launched);
389
+ }
390
+
391
+ @end
392
+
393
+ namespace ngn::appkit {
394
+
395
+ void watchApp(std::shared_ptr<HostState> state, std::shared_ptr<System> system) {
396
+ static NGNAppObserver *observer;
397
+ observer = [NGNAppObserver new];
398
+ observer.state = std::move(state);
399
+ observer.system = std::static_pointer_cast<AppKitSystem>(system);
400
+ [observer start];
401
+ }
402
+
403
+ } // namespace ngn::appkit
@@ -0,0 +1,36 @@
1
+ // What a test launch changes in the AppKit host (`TestLaunch` in launch-settings.h): windows shown
2
+ // without taking focus and no Dock icon until a test asks for the key window, the app's preferences
3
+ // in a defaults suite of the run's own, and what the run leaves behind removed as it ends.
4
+ #pragma once
5
+
6
+ #include "ngn/launch-settings.h"
7
+
8
+ #import <AppKit/AppKit.h>
9
+
10
+ #include <functional>
11
+ #include <optional>
12
+
13
+ namespace ngn::appkit {
14
+
15
+ // Set once by main before anything below is read: the launch's test settings, or nothing. Creates
16
+ // the state directory's folders and points TMPDIR at its tmp.
17
+ void beginTestLaunch(const std::optional<TestLaunch> &test);
18
+ // The test launch the host runs as, or nothing.
19
+ const std::optional<TestLaunch> &testLaunch();
20
+
21
+ // Where the app's preferences go: the run's suite in a test launch, the standard defaults otherwise.
22
+ NSUserDefaults *appDefaults();
23
+
24
+ // Shows a window: key and in front, or in a test launch in front of other apps' windows without
25
+ // becoming key or activating the app.
26
+ void showWindow(NSWindow *window);
27
+ // Brings the app to the front with `window` key. In a test launch the app first becomes a regular
28
+ // app with a Dock icon, which it was not until a test asked for the key window.
29
+ void activateWith(NSWindow *window);
30
+
31
+ // Runs at the end of a test launch, on a clean quit or SIGTERM: what the run must not leave behind.
32
+ void onTestLaunchEnd(std::function<void()> cleanup);
33
+ // Removes what the run leaves behind (each onTestLaunchEnd, and the run's defaults suite), once.
34
+ void endTestLaunch();
35
+
36
+ } // namespace ngn::appkit
@@ -0,0 +1,115 @@
1
+ #import "test-launch.h"
2
+
3
+ #include <cstdlib>
4
+ #include <filesystem>
5
+ #include <vector>
6
+
7
+ namespace ngn::appkit {
8
+
9
+ namespace {
10
+
11
+ std::optional<TestLaunch> &current() {
12
+ static std::optional<TestLaunch> test;
13
+ return test;
14
+ }
15
+
16
+ std::vector<std::function<void()>> &cleanups() {
17
+ static std::vector<std::function<void()>> list;
18
+ return list;
19
+ }
20
+
21
+ NSString *ns(const std::string &s) {
22
+ return [NSString stringWithUTF8String:s.c_str()];
23
+ }
24
+
25
+ // The file a defaults suite is kept in. Removing the suite's domain leaves it behind, empty.
26
+ std::filesystem::path suiteFile(const std::string &suite) {
27
+ NSString *library = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES).firstObject;
28
+ return std::filesystem::path(library.UTF8String) / "Preferences" / (suite + ".plist");
29
+ }
30
+
31
+ // The suites of runs that ended without removing theirs (a crash): files only, never read.
32
+ void removeStaleSuites(const TestLaunch &own) {
33
+ std::error_code ignored;
34
+ auto folder = suiteFile(own.defaultsSuite()).parent_path();
35
+ for (const auto &entry : std::filesystem::directory_iterator(folder, ignored)) {
36
+ auto name = entry.path().filename().string();
37
+ if (name.ends_with(".defaults.plist") && isStaleTestService(name, own)) {
38
+ std::filesystem::remove(entry.path(), ignored);
39
+ }
40
+ }
41
+ }
42
+
43
+ } // namespace
44
+
45
+ void beginTestLaunch(const std::optional<TestLaunch> &test) {
46
+ current() = test;
47
+ if (!test) {
48
+ return;
49
+ }
50
+ std::error_code ignored;
51
+ for (const auto &dir : {test->applicationSupport(), test->caches(), test->temp()}) {
52
+ std::filesystem::create_directories(dir, ignored);
53
+ }
54
+ // What C++ and the programs the app runs take as the temporary directory. Foundation's
55
+ // NSTemporaryDirectory ignores it, so FileSystem is given the folder itself.
56
+ setenv("TMPDIR", (test->temp() + "/").c_str(), 1);
57
+ removeStaleSuites(*test);
58
+ }
59
+
60
+ const std::optional<TestLaunch> &testLaunch() {
61
+ return current();
62
+ }
63
+
64
+ NSUserDefaults *appDefaults() {
65
+ static NSUserDefaults *defaults = current() ? [[NSUserDefaults alloc] initWithSuiteName:ns(current()->defaultsSuite())]
66
+ : NSUserDefaults.standardUserDefaults;
67
+ return defaults;
68
+ }
69
+
70
+ void showWindow(NSWindow *window) {
71
+ if (current()) {
72
+ [window orderFrontRegardless];
73
+ } else {
74
+ [window makeKeyAndOrderFront:nil];
75
+ }
76
+ }
77
+
78
+ void activateWith(NSWindow *window) {
79
+ if (current() && NSApp.activationPolicy != NSApplicationActivationPolicyRegular) {
80
+ NSApp.activationPolicy = NSApplicationActivationPolicyRegular;
81
+ }
82
+ [window makeKeyAndOrderFront:nil];
83
+ [NSApp activateIgnoringOtherApps:YES];
84
+ }
85
+
86
+ void onTestLaunchEnd(std::function<void()> cleanup) {
87
+ if (current()) {
88
+ cleanups().push_back(std::move(cleanup));
89
+ }
90
+ }
91
+
92
+ void endTestLaunch() {
93
+ static bool ended = false;
94
+ if (!current() || ended) {
95
+ return;
96
+ }
97
+ ended = true;
98
+ for (const auto &cleanup : cleanups()) {
99
+ cleanup();
100
+ }
101
+ [appDefaults() removePersistentDomainForName:ns(current()->defaultsSuite())];
102
+ CFPreferencesAppSynchronize((__bridge CFStringRef)ns(current()->defaultsSuite()));
103
+ std::error_code ignored;
104
+ std::filesystem::remove(suiteFile(current()->defaultsSuite()), ignored);
105
+ // NSSplitView autosaves into the standard defaults, under names the run prefixed.
106
+ NSUserDefaults *standard = NSUserDefaults.standardUserDefaults;
107
+ NSString *own = ns(current()->keychainPrefix());
108
+ for (NSString *key in standard.dictionaryRepresentation.allKeys) {
109
+ if ([key containsString:own]) {
110
+ [standard removeObjectForKey:key];
111
+ }
112
+ }
113
+ }
114
+
115
+ } // namespace ngn::appkit
@@ -0,0 +1,76 @@
1
+ // The AppKit controls behind `<text-input>`: NGNTextField for a single line, NGNTextView for
2
+ // multiline (whose owner, its delegate, answers textView:willCheckTextInRange: with
3
+ // NGNTextCheckingOptions). They apply the core's TextInputOptions (text-input.h) to AppKit's text checking,
4
+ // keep a field within maxLength and capitalize what is typed, draw a coloured placeholder, take a
5
+ // selection set from the props, focus themselves for autoFocus and tell their owner when they take
6
+ // the keyboard. No Fabric here, so they are tested on offscreen windows.
7
+ #pragma once
8
+
9
+ #import <AppKit/AppKit.h>
10
+
11
+ #include "ngn/text-input.h"
12
+
13
+ // The checks and substitutions `options` turns on or off on a text view: a multiline input, or the
14
+ // field editor while a field edits. An unset option leaves the text view at the user's setting.
15
+ void NGNApplyTextOptions(NSTextView *text, const ngn::TextInputOptions &options);
16
+
17
+ // What goes in for `replacement` at `range` of `current`: cut to maxLength (never through a
18
+ // composed character) and capitalized for `words` or `characters`. Empty when nothing fits.
19
+ NSString *NGNFitReplacement(NSString *current, NSRange range, NSString *replacement, const ngn::TextInputOptions &options);
20
+
21
+ // A text-checking delegate's options with `options`' capitalization: `none` turns the user's
22
+ // sentence capitalization off, on macOS 26 and later.
23
+ // The text checking key that overrides the user's automatic capitalization, or nil where the
24
+ // system has none.
25
+ NSString *NGNAutomaticCapitalizationKey();
26
+
27
+ NSDictionary<NSTextCheckingOptionKey, id> *NGNTextCheckingOptions(
28
+ NSDictionary<NSTextCheckingOptionKey, id> *checking,
29
+ const ngn::TextInputOptions &options);
30
+
31
+ // textView:shouldChangeTextInRange:replacementString: for an NSTextField subclass whose field editor
32
+ // `editor` is: `superclass`'s answer (a formatter's), then NGNFitReplacement's, putting what fits in
33
+ // place of the change when it differs. `inserting` is the control's own flag for that re-entry.
34
+ BOOL NGNControlShouldChangeText(
35
+ NSControl *control,
36
+ Class superclass,
37
+ NSTextView *editor,
38
+ NSRange range,
39
+ NSString *replacement,
40
+ const ngn::TextInputOptions &options,
41
+ BOOL *inserting);
42
+
43
+ // A single-line field: an NSTextField, or an NSSecureTextField for secure entry, in a box that swaps
44
+ // one for the other.
45
+ @interface NGNTextField : NSView
46
+ // The NSTextField (or NSSecureTextField) now in the box. A swap carries its delegate over.
47
+ @property (nonatomic, readonly) NSTextField *control;
48
+ @property (nonatomic, copy) NSString *stringValue;
49
+ @property (nonatomic, strong) NSFont *font;
50
+ @property (nonatomic, readonly) NSText *currentEditor;
51
+ // An NSSecureTextField in place of the NSTextField (or back), keeping the text, its look, and the
52
+ // keyboard and selection while editing.
53
+ @property (nonatomic) BOOL secure;
54
+ // True while `secure` swaps the control, as the editing session that ends and starts again is not the
55
+ // user's.
56
+ @property (nonatomic, readonly) BOOL swapping;
57
+ // Focuses the field the first time it is in a window.
58
+ @property (nonatomic) BOOL autoFocus;
59
+ // Called when the field takes the keyboard.
60
+ @property (nonatomic, copy) void (^focused)(void);
61
+ - (void)applyOptions:(const ngn::TextInputOptions &)options;
62
+ - (const ngn::TextInputOptions &)options;
63
+ // Drawn in the field's font; nil colour is the system's placeholder colour.
64
+ - (void)setPlaceholder:(NSString *)placeholder color:(NSColor *)color;
65
+ // Selects now while editing, or as editing starts.
66
+ - (void)selectRange:(NSRange)range;
67
+ @end
68
+
69
+ @interface NGNTextView : NSTextView
70
+ @property (nonatomic) BOOL autoFocus;
71
+ @property (nonatomic, copy) void (^focused)(void);
72
+ @property (nonatomic, copy, readonly) NSAttributedString *placeholder;
73
+ - (void)applyOptions:(const ngn::TextInputOptions &)options;
74
+ - (void)setPlaceholder:(NSString *)placeholder color:(NSColor *)color;
75
+ - (void)selectRange:(NSRange)range;
76
+ @end