basalt-core 0.0.0-rc5

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 (325) hide show
  1. package/LICENSE +21 -0
  2. package/dist/cli/basalt.d.ts +3 -0
  3. package/dist/cli/basalt.d.ts.map +1 -0
  4. package/dist/cli/basalt.js +47 -0
  5. package/dist/cli/basalt.js.map +1 -0
  6. package/dist/cli/bundle-cli.d.ts +12 -0
  7. package/dist/cli/bundle-cli.d.ts.map +1 -0
  8. package/dist/cli/bundle-cli.js +124 -0
  9. package/dist/cli/bundle-cli.js.map +1 -0
  10. package/dist/cli/bundleWithAssets.d.ts +79 -0
  11. package/dist/cli/bundleWithAssets.d.ts.map +1 -0
  12. package/dist/cli/bundleWithAssets.js +198 -0
  13. package/dist/cli/bundleWithAssets.js.map +1 -0
  14. package/dist/cli/desktop.d.ts +339 -0
  15. package/dist/cli/desktop.d.ts.map +1 -0
  16. package/dist/cli/desktop.js +1029 -0
  17. package/dist/cli/desktop.js.map +1 -0
  18. package/dist/cli/doctor.d.ts +31 -0
  19. package/dist/cli/doctor.d.ts.map +1 -0
  20. package/dist/cli/doctor.js +283 -0
  21. package/dist/cli/doctor.js.map +1 -0
  22. package/dist/cli/init.d.ts +77 -0
  23. package/dist/cli/init.d.ts.map +1 -0
  24. package/dist/cli/init.js +442 -0
  25. package/dist/cli/init.js.map +1 -0
  26. package/dist/cli/metro.d.ts +49 -0
  27. package/dist/cli/metro.d.ts.map +1 -0
  28. package/dist/cli/metro.js +148 -0
  29. package/dist/cli/metro.js.map +1 -0
  30. package/dist/cli/packageApp.d.ts +102 -0
  31. package/dist/cli/packageApp.d.ts.map +1 -0
  32. package/dist/cli/packageApp.js +319 -0
  33. package/dist/cli/packageApp.js.map +1 -0
  34. package/dist/cli/steps.d.ts +34 -0
  35. package/dist/cli/steps.d.ts.map +1 -0
  36. package/dist/cli/steps.js +53 -0
  37. package/dist/cli/steps.js.map +1 -0
  38. package/dist/metro-config.d.ts +168 -0
  39. package/dist/metro-config.d.ts.map +1 -0
  40. package/dist/metro-config.js +671 -0
  41. package/dist/metro-config.js.map +1 -0
  42. package/dist/react-native.config.d.ts +7 -0
  43. package/dist/react-native.config.d.ts.map +1 -0
  44. package/dist/react-native.config.js +80 -0
  45. package/dist/react-native.config.js.map +1 -0
  46. package/dist/src/DragSource.d.ts +52 -0
  47. package/dist/src/DragSource.d.ts.map +1 -0
  48. package/dist/src/DragSource.js +97 -0
  49. package/dist/src/DragSource.js.map +1 -0
  50. package/dist/src/DropTarget.d.ts +58 -0
  51. package/dist/src/DropTarget.d.ts.map +1 -0
  52. package/dist/src/DropTarget.js +131 -0
  53. package/dist/src/DropTarget.js.map +1 -0
  54. package/dist/src/KeyHandler.d.ts +57 -0
  55. package/dist/src/KeyHandler.d.ts.map +1 -0
  56. package/dist/src/KeyHandler.js +48 -0
  57. package/dist/src/KeyHandler.js.map +1 -0
  58. package/dist/src/Menu.d.ts +72 -0
  59. package/dist/src/Menu.d.ts.map +1 -0
  60. package/dist/src/Menu.js +179 -0
  61. package/dist/src/Menu.js.map +1 -0
  62. package/dist/src/TitleBar.d.ts +75 -0
  63. package/dist/src/TitleBar.d.ts.map +1 -0
  64. package/dist/src/TitleBar.js +236 -0
  65. package/dist/src/TitleBar.js.map +1 -0
  66. package/dist/src/Window.d.ts +87 -0
  67. package/dist/src/Window.d.ts.map +1 -0
  68. package/dist/src/Window.js +248 -0
  69. package/dist/src/Window.js.map +1 -0
  70. package/dist/src/closeRequest.d.ts +55 -0
  71. package/dist/src/closeRequest.d.ts.map +1 -0
  72. package/dist/src/closeRequest.js +134 -0
  73. package/dist/src/closeRequest.js.map +1 -0
  74. package/dist/src/index.d.ts +45 -0
  75. package/dist/src/index.d.ts.map +1 -0
  76. package/dist/src/index.js +92 -0
  77. package/dist/src/index.js.map +1 -0
  78. package/dist/src/overrides/Alert.d.ts +69 -0
  79. package/dist/src/overrides/Alert.d.ts.map +1 -0
  80. package/dist/src/overrides/Alert.js +112 -0
  81. package/dist/src/overrides/Alert.js.map +1 -0
  82. package/dist/src/overrides/BaseViewConfig.d.ts +28 -0
  83. package/dist/src/overrides/BaseViewConfig.d.ts.map +1 -0
  84. package/dist/src/overrides/BaseViewConfig.js +72 -0
  85. package/dist/src/overrides/BaseViewConfig.js.map +1 -0
  86. package/dist/src/overrides/Platform.linux.d.ts +10 -0
  87. package/dist/src/overrides/Platform.linux.d.ts.map +1 -0
  88. package/dist/src/overrides/Platform.linux.js +15 -0
  89. package/dist/src/overrides/Platform.linux.js.map +1 -0
  90. package/dist/src/overrides/Platform.macos.d.ts +10 -0
  91. package/dist/src/overrides/Platform.macos.d.ts.map +1 -0
  92. package/dist/src/overrides/Platform.macos.js +15 -0
  93. package/dist/src/overrides/Platform.macos.js.map +1 -0
  94. package/dist/src/overrides/Platform.windows.d.ts +10 -0
  95. package/dist/src/overrides/Platform.windows.d.ts.map +1 -0
  96. package/dist/src/overrides/Platform.windows.js +15 -0
  97. package/dist/src/overrides/Platform.windows.js.map +1 -0
  98. package/dist/src/overrides/ReactDevToolsSettingsManager.d.ts +24 -0
  99. package/dist/src/overrides/ReactDevToolsSettingsManager.d.ts.map +1 -0
  100. package/dist/src/overrides/ReactDevToolsSettingsManager.js +30 -0
  101. package/dist/src/overrides/ReactDevToolsSettingsManager.js.map +1 -0
  102. package/dist/src/overrides/RefreshControl.d.ts +52 -0
  103. package/dist/src/overrides/RefreshControl.d.ts.map +1 -0
  104. package/dist/src/overrides/RefreshControl.js +92 -0
  105. package/dist/src/overrides/RefreshControl.js.map +1 -0
  106. package/dist/src/overrides/ScrollView.d.ts +39 -0
  107. package/dist/src/overrides/ScrollView.d.ts.map +1 -0
  108. package/dist/src/overrides/ScrollView.js +59 -0
  109. package/dist/src/overrides/ScrollView.js.map +1 -0
  110. package/dist/src/overrides/Share.d.ts +96 -0
  111. package/dist/src/overrides/Share.d.ts.map +1 -0
  112. package/dist/src/overrides/Share.js +97 -0
  113. package/dist/src/overrides/Share.js.map +1 -0
  114. package/dist/src/overrides/TextInput.d.ts +81 -0
  115. package/dist/src/overrides/TextInput.d.ts.map +1 -0
  116. package/dist/src/overrides/TextInput.js +213 -0
  117. package/dist/src/overrides/TextInput.js.map +1 -0
  118. package/dist/src/overrides/View.d.ts +36 -0
  119. package/dist/src/overrides/View.d.ts.map +1 -0
  120. package/dist/src/overrides/View.js +99 -0
  121. package/dist/src/overrides/View.js.map +1 -0
  122. package/dist/src/overrides/createPlatform.d.ts +32 -0
  123. package/dist/src/overrides/createPlatform.d.ts.map +1 -0
  124. package/dist/src/overrides/createPlatform.js +84 -0
  125. package/dist/src/overrides/createPlatform.js.map +1 -0
  126. package/dist/src/overrides/setUpDeveloperTools.d.ts +28 -0
  127. package/dist/src/overrides/setUpDeveloperTools.d.ts.map +1 -0
  128. package/dist/src/overrides/setUpDeveloperTools.js +84 -0
  129. package/dist/src/overrides/setUpDeveloperTools.js.map +1 -0
  130. package/dist/src/overrides/setUpXHR.d.ts +46 -0
  131. package/dist/src/overrides/setUpXHR.d.ts.map +1 -0
  132. package/dist/src/overrides/setUpXHR.js +236 -0
  133. package/dist/src/overrides/setUpXHR.js.map +1 -0
  134. package/dist/src/quitRequest.d.ts +55 -0
  135. package/dist/src/quitRequest.d.ts.map +1 -0
  136. package/dist/src/quitRequest.js +121 -0
  137. package/dist/src/quitRequest.js.map +1 -0
  138. package/dist/src/resourcePath.d.ts +18 -0
  139. package/dist/src/resourcePath.d.ts.map +1 -0
  140. package/dist/src/resourcePath.js +31 -0
  141. package/dist/src/resourcePath.js.map +1 -0
  142. package/dist/src/responseBody.d.ts +76 -0
  143. package/dist/src/responseBody.d.ts.map +1 -0
  144. package/dist/src/responseBody.js +94 -0
  145. package/dist/src/responseBody.js.map +1 -0
  146. package/dist/src/responseHeaders.d.ts +40 -0
  147. package/dist/src/responseHeaders.d.ts.map +1 -0
  148. package/dist/src/responseHeaders.js +75 -0
  149. package/dist/src/responseHeaders.js.map +1 -0
  150. package/dist/src/titleBarState.d.ts +43 -0
  151. package/dist/src/titleBarState.d.ts.map +1 -0
  152. package/dist/src/titleBarState.js +77 -0
  153. package/dist/src/titleBarState.js.map +1 -0
  154. package/dist/src/useContextMenu.d.ts +113 -0
  155. package/dist/src/useContextMenu.d.ts.map +1 -0
  156. package/dist/src/useContextMenu.js +109 -0
  157. package/dist/src/useContextMenu.js.map +1 -0
  158. package/dist/src/useDialog.d.ts +98 -0
  159. package/dist/src/useDialog.d.ts.map +1 -0
  160. package/dist/src/useDialog.js +112 -0
  161. package/dist/src/useDialog.js.map +1 -0
  162. package/dist/src/useDisplays.d.ts +70 -0
  163. package/dist/src/useDisplays.d.ts.map +1 -0
  164. package/dist/src/useDisplays.js +118 -0
  165. package/dist/src/useDisplays.js.map +1 -0
  166. package/dist/src/useHandledKeys.d.ts +38 -0
  167. package/dist/src/useHandledKeys.d.ts.map +1 -0
  168. package/dist/src/useHandledKeys.js +70 -0
  169. package/dist/src/useHandledKeys.js.map +1 -0
  170. package/dist/src/useWindow.d.ts +140 -0
  171. package/dist/src/useWindow.d.ts.map +1 -0
  172. package/dist/src/useWindow.js +233 -0
  173. package/dist/src/useWindow.js.map +1 -0
  174. package/dist/tsconfig.tsbuildinfo +1 -0
  175. package/native/CMakeLists.txt +355 -0
  176. package/native/bootstrap.sh +613 -0
  177. package/native/cmake/CompilerFlags.cmake +49 -0
  178. package/native/cmake/Expo.cmake +125 -0
  179. package/native/cmake/ReactNativeCore.cmake +612 -0
  180. package/native/cmake/Reanimated.cmake +108 -0
  181. package/native/cmake/Skia.cmake +379 -0
  182. package/native/cmake/ThirdParty.cmake +290 -0
  183. package/native/cmake/Worklets.cmake +67 -0
  184. package/native/cmake/codegen/CMakeLists.txt +32 -0
  185. package/native/core/AppIdentity.cpp +85 -0
  186. package/native/core/AppIdentity.h +59 -0
  187. package/native/core/AppPaths.cpp +96 -0
  188. package/native/core/AppPaths.h +53 -0
  189. package/native/core/AppearanceModule.cpp +60 -0
  190. package/native/core/AppearanceModule.h +40 -0
  191. package/native/core/Backface.h +59 -0
  192. package/native/core/BlobModule.cpp +283 -0
  193. package/native/core/BlobModule.h +76 -0
  194. package/native/core/BlobRegistry.cpp +75 -0
  195. package/native/core/BlobRegistry.h +44 -0
  196. package/native/core/ColorScheme.cpp +105 -0
  197. package/native/core/ColorScheme.h +59 -0
  198. package/native/core/ComponentRegistry.h +30 -0
  199. package/native/core/ControlMetrics.h +37 -0
  200. package/native/core/CoreModules.cpp +592 -0
  201. package/native/core/CoreModules.h +308 -0
  202. package/native/core/DebuggingOverlay.cpp +106 -0
  203. package/native/core/DebuggingOverlay.h +65 -0
  204. package/native/core/DesktopControls.cpp +232 -0
  205. package/native/core/DesktopControls.h +170 -0
  206. package/native/core/DevBundle.cpp +108 -0
  207. package/native/core/DevBundle.h +69 -0
  208. package/native/core/DevMenu.cpp +99 -0
  209. package/native/core/DevMenu.h +75 -0
  210. package/native/core/DialogModule.cpp +150 -0
  211. package/native/core/DialogModule.h +51 -0
  212. package/native/core/DragAndDrop.cpp +45 -0
  213. package/native/core/DragAndDrop.h +225 -0
  214. package/native/core/ExpoImageComponent.cpp +79 -0
  215. package/native/core/ExpoImageComponent.h +80 -0
  216. package/native/core/ExpoModules.cpp +415 -0
  217. package/native/core/ExpoModules.h +115 -0
  218. package/native/core/ExpoRuntime.cpp +366 -0
  219. package/native/core/ExpoRuntime.h +42 -0
  220. package/native/core/FocusRing.h +36 -0
  221. package/native/core/FontRegistry.h +51 -0
  222. package/native/core/GestureHandlerModule.cpp +136 -0
  223. package/native/core/GestureHandlerModule.h +71 -0
  224. package/native/core/Gestures.cpp +533 -0
  225. package/native/core/Gestures.h +145 -0
  226. package/native/core/HoverTracker.cpp +69 -0
  227. package/native/core/HoverTracker.h +109 -0
  228. package/native/core/HttpClient.cpp +282 -0
  229. package/native/core/ImageBytes.cpp +205 -0
  230. package/native/core/ImageBytes.h +29 -0
  231. package/native/core/ImageCache.cpp +51 -0
  232. package/native/core/ImageCache.h +89 -0
  233. package/native/core/JsRuntimeAccess.cpp +70 -0
  234. package/native/core/JsRuntimeAccess.h +60 -0
  235. package/native/core/JsiPromise.h +51 -0
  236. package/native/core/KeyEvents.cpp +116 -0
  237. package/native/core/KeyEvents.h +144 -0
  238. package/native/core/LogBoxSurface.cpp +46 -0
  239. package/native/core/LogBoxSurface.h +68 -0
  240. package/native/core/MenuModel.h +117 -0
  241. package/native/core/MenuModule.cpp +209 -0
  242. package/native/core/MenuModule.h +66 -0
  243. package/native/core/MountingWalk.h +524 -0
  244. package/native/core/PackageModules.cpp.in +25 -0
  245. package/native/core/PackageModules.h +50 -0
  246. package/native/core/PlatformConstantsModule.cpp +63 -0
  247. package/native/core/PlatformConstantsModule.h +64 -0
  248. package/native/core/PlatformServices.h +213 -0
  249. package/native/core/PointerButtons.h +63 -0
  250. package/native/core/PullToRefresh.cpp +57 -0
  251. package/native/core/PullToRefresh.h +73 -0
  252. package/native/core/ReanimatedCompat.h +47 -0
  253. package/native/core/ReanimatedModule.cpp +203 -0
  254. package/native/core/ReanimatedModule.h +55 -0
  255. package/native/core/ScrollAnimation.cpp +59 -0
  256. package/native/core/ScrollAnimation.h +70 -0
  257. package/native/core/ScrollBounds.cpp +26 -0
  258. package/native/core/ScrollBounds.h +68 -0
  259. package/native/core/ScrollIndicator.cpp +50 -0
  260. package/native/core/ScrollIndicator.h +69 -0
  261. package/native/core/ScrollMomentum.cpp +71 -0
  262. package/native/core/ScrollMomentum.h +73 -0
  263. package/native/core/ScrollSnap.cpp +123 -0
  264. package/native/core/ScrollSnap.h +80 -0
  265. package/native/core/ShareFallback.cpp +101 -0
  266. package/native/core/ShareFallback.h +45 -0
  267. package/native/core/SkiaPictureViewComponent.cpp +11 -0
  268. package/native/core/SkiaPictureViewComponent.h +47 -0
  269. package/native/core/SourceCodeModule.cpp +55 -0
  270. package/native/core/SourceCodeModule.h +53 -0
  271. package/native/core/StatusBarModule.cpp +23 -0
  272. package/native/core/StatusBarModule.h +42 -0
  273. package/native/core/TestDialog.cpp +148 -0
  274. package/native/core/TestDialog.h +96 -0
  275. package/native/core/TestKeys.cpp +78 -0
  276. package/native/core/TestKeys.h +50 -0
  277. package/native/core/TestQuitFile.cpp +33 -0
  278. package/native/core/TestQuitFile.h +60 -0
  279. package/native/core/TestSettle.h +192 -0
  280. package/native/core/TitleBarRegions.h +31 -0
  281. package/native/core/TurboModuleProxy.cpp +51 -0
  282. package/native/core/TurboModuleProxy.h +46 -0
  283. package/native/core/UIManagerAccess.cpp +43 -0
  284. package/native/core/UIManagerAccess.h +43 -0
  285. package/native/core/WindowBoundsCache.cpp +319 -0
  286. package/native/core/WindowControl.h +235 -0
  287. package/native/core/WindowHost.h +158 -0
  288. package/native/core/WindowMethods.cpp +167 -0
  289. package/native/core/WindowMethods.h +84 -0
  290. package/native/core/WindowsModule.cpp +448 -0
  291. package/native/core/WindowsModule.h +133 -0
  292. package/native/core/WorkletsModule.cpp +199 -0
  293. package/native/core/WorkletsModule.h +57 -0
  294. package/native/core/portability_probe.cpp +210 -0
  295. package/native/tests/EventRecorder.h +124 -0
  296. package/native/tests/TestHarness.cpp +109 -0
  297. package/native/tests/TestHarness.h +89 -0
  298. package/native/tests/TreeDump.h +49 -0
  299. package/native/tests/test_app_identity.cpp +114 -0
  300. package/native/tests/test_app_paths.cpp +48 -0
  301. package/native/tests/test_appearance.cpp +107 -0
  302. package/native/tests/test_backface.cpp +79 -0
  303. package/native/tests/test_blobs.cpp +157 -0
  304. package/native/tests/test_controls.cpp +185 -0
  305. package/native/tests/test_devbundle.cpp +103 -0
  306. package/native/tests/test_drag_and_drop.cpp +143 -0
  307. package/native/tests/test_gestures.cpp +331 -0
  308. package/native/tests/test_hover.cpp +92 -0
  309. package/native/tests/test_image_cache.cpp +109 -0
  310. package/native/tests/test_js_runtime_access.cpp +137 -0
  311. package/native/tests/test_key_events.cpp +235 -0
  312. package/native/tests/test_momentum.cpp +138 -0
  313. package/native/tests/test_quit_file.cpp +104 -0
  314. package/native/tests/test_scroll_animation.cpp +120 -0
  315. package/native/tests/test_scroll_bounds.cpp +66 -0
  316. package/native/tests/test_scroll_indicator.cpp +149 -0
  317. package/native/tests/test_scroll_snap.cpp +112 -0
  318. package/native/tests/test_settle.cpp +115 -0
  319. package/native/tests/test_share.cpp +75 -0
  320. package/native/tests/test_sourcecode.cpp +62 -0
  321. package/native/tests/test_window_close.cpp +119 -0
  322. package/native/tests/test_window_limits.cpp +123 -0
  323. package/package.json +43 -0
  324. package/react-native.config.js +86 -0
  325. package/supported-versions.json +66 -0
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+ /**
3
+ * What screens the desktop has, where they are, and how dense they are.
4
+ *
5
+ * React Native's `Dimensions` reports the *window*, which is the right answer
6
+ * to a different question. An app placing a window, or deciding how much it
7
+ * can show, is asking about the screen it is on and the ones beside it.
8
+ *
9
+ * ## What each desktop will and will not say
10
+ *
11
+ * Bounds and scale factor: everywhere. The work area -- what is left after a
12
+ * menu bar, taskbar or dock -- comes from macOS and Windows, and GTK 4 has no
13
+ * way to ask, so it reports the full bounds there. The pointer's position
14
+ * comes from macOS and Windows and never from GTK.
15
+ *
16
+ * None of those are gaps waiting to be filled. `gdk_monitor_get_workarea`,
17
+ * `gdk_display_get_primary_monitor` and reading the pointer were all in GTK 3
18
+ * and were removed: Wayland has no protocol a client can use for any of them.
19
+ * See native/gtk/GtkWindowControl.cpp.
20
+ *
21
+ * So an app that needs the work area should treat "equal to bounds" as the
22
+ * answer rather than as a failure, and one that needs the pointer should check
23
+ * `known`.
24
+ *
25
+ * @format
26
+ */
27
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
28
+ if (k2 === undefined) k2 = k;
29
+ var desc = Object.getOwnPropertyDescriptor(m, k);
30
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
31
+ desc = { enumerable: true, get: function() { return m[k]; } };
32
+ }
33
+ Object.defineProperty(o, k2, desc);
34
+ }) : (function(o, m, k, k2) {
35
+ if (k2 === undefined) k2 = k;
36
+ o[k2] = m[k];
37
+ }));
38
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
39
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
40
+ }) : function(o, v) {
41
+ o["default"] = v;
42
+ });
43
+ var __importStar = (this && this.__importStar) || (function () {
44
+ var ownKeys = function(o) {
45
+ ownKeys = Object.getOwnPropertyNames || function (o) {
46
+ var ar = [];
47
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
48
+ return ar;
49
+ };
50
+ return ownKeys(o);
51
+ };
52
+ return function (mod) {
53
+ if (mod && mod.__esModule) return mod;
54
+ var result = {};
55
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
56
+ __setModuleDefault(result, mod);
57
+ return result;
58
+ };
59
+ })();
60
+ Object.defineProperty(exports, "__esModule", { value: true });
61
+ exports.isSupported = void 0;
62
+ exports.displays = displays;
63
+ exports.pointerPosition = pointerPosition;
64
+ exports.useDisplays = useDisplays;
65
+ exports.primaryDisplay = primaryDisplay;
66
+ const React = __importStar(require("react"));
67
+ const react_native_1 = require("react-native");
68
+ const NativeWindows = react_native_1.TurboModuleRegistry.get('BasaltWindows');
69
+ // Must match kDisplaysChangedEvent in native/core/WindowsModule.h.
70
+ const DISPLAYS_CHANGED_EVENT = 'basaltDisplaysChanged';
71
+ /** Whether this platform can be asked at all. */
72
+ exports.isSupported = NativeWindows?.getDisplays != null;
73
+ /**
74
+ * Every display, primary first.
75
+ *
76
+ * Synchronous, because the host keeps the list up to date rather than the
77
+ * platform asking the toolkit on demand -- see core/WindowControl.h. Empty
78
+ * before the host has reported anything, which an app can distinguish from
79
+ * "no displays" only by there being no such desktop.
80
+ */
81
+ function displays() {
82
+ const found = NativeWindows?.getDisplays?.();
83
+ return Array.isArray(found) ? found : [];
84
+ }
85
+ /** Where the pointer is. A promise: nothing reports the pointer moving. */
86
+ function pointerPosition() {
87
+ return (NativeWindows?.getPointerPosition?.() ??
88
+ Promise.resolve({ x: 0, y: 0, known: false }));
89
+ }
90
+ /**
91
+ * The displays, kept current.
92
+ *
93
+ * Re-reads whenever a monitor is plugged in, unplugged or rearranged. The
94
+ * event carries no payload for a reason -- several changes can arrive
95
+ * together, and re-reading is the only way to be right about all of them.
96
+ */
97
+ function useDisplays() {
98
+ const [current, setCurrent] = React.useState(displays);
99
+ React.useEffect(() => {
100
+ if (!exports.isSupported) {
101
+ return;
102
+ }
103
+ // Once on mount as well as on every change: the list may have changed
104
+ // between the first render and this effect.
105
+ setCurrent(displays());
106
+ const subscription = react_native_1.DeviceEventEmitter.addListener(DISPLAYS_CHANGED_EVENT, () => {
107
+ setCurrent(displays());
108
+ });
109
+ return () => subscription.remove();
110
+ }, []);
111
+ return current;
112
+ }
113
+ /** The primary display, or null on a platform with none to report. */
114
+ function primaryDisplay() {
115
+ const found = displays();
116
+ return found.find(display => display.primary) ?? found[0] ?? null;
117
+ }
118
+ //# sourceMappingURL=useDisplays.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDisplays.js","sourceRoot":"","sources":["../../src/useDisplays.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkDH,4BAGC;AAGD,0CAKC;AASD,kCAkBC;AAGD,wCAGC;AA5FD,6CAA+B;AAE/B,+CAAqE;AA8BrE,MAAM,aAAa,GAAG,kCAAmB,CAAC,GAAG,CAAsB,eAAe,CAAC,CAAC;AAEpF,mEAAmE;AACnE,MAAM,sBAAsB,GAAG,uBAAuB,CAAC;AAEvD,iDAAiD;AACpC,QAAA,WAAW,GAAG,aAAa,EAAE,WAAW,IAAI,IAAI,CAAC;AAE9D;;;;;;;GAOG;AACH,SAAgB,QAAQ;IACtB,MAAM,KAAK,GAAG,aAAa,EAAE,WAAW,EAAE,EAAE,CAAC;IAC7C,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;AAC3C,CAAC;AAED,2EAA2E;AAC3E,SAAgB,eAAe;IAC7B,OAAO,CACL,aAAa,EAAE,kBAAkB,EAAE,EAAE;QACrC,OAAO,CAAC,OAAO,CAAC,EAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,KAAK,EAAC,CAAC,CAC5C,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,WAAW;IACzB,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAY,QAAQ,CAAC,CAAC;IAElE,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,IAAI,CAAC,mBAAW,EAAE,CAAC;YACjB,OAAO;QACT,CAAC;QACD,sEAAsE;QACtE,4CAA4C;QAC5C,UAAU,CAAC,QAAQ,EAAE,CAAC,CAAC;QAEvB,MAAM,YAAY,GAAG,iCAAkB,CAAC,WAAW,CAAC,sBAAsB,EAAE,GAAG,EAAE;YAC/E,UAAU,CAAC,QAAQ,EAAE,CAAC,CAAC;QACzB,CAAC,CAAC,CAAC;QACH,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,MAAM,EAAE,CAAC;IACrC,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,sEAAsE;AACtE,SAAgB,cAAc;IAC5B,MAAM,KAAK,GAAG,QAAQ,EAAE,CAAC;IACzB,OAAO,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC;AACpE,CAAC"}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * The half of `<KeyHandler>` that is not a component.
3
+ *
4
+ * Extracted so that the `View` override can use the same implementation rather
5
+ * than a second copy of it: a view that declares `keyDownEvents` and a
6
+ * `<KeyHandler>` are two spellings of one thing, and two spellings that drifted
7
+ * apart would be worse than either.
8
+ *
9
+ * @format
10
+ */
11
+ /** A combination a view claims. Modifiers left out are required to be absent. */
12
+ export interface HandledKey {
13
+ key: string;
14
+ altKey?: boolean;
15
+ ctrlKey?: boolean;
16
+ metaKey?: boolean;
17
+ shiftKey?: boolean;
18
+ }
19
+ /** What a press reports. The same shape, which is why they compare directly. */
20
+ export type PressedKey = HandledKey;
21
+ /** The event the host emits for a press a view claimed. */
22
+ export declare const KEY_EVENT = "basaltKey";
23
+ /**
24
+ * Registers `keys` for whatever `ref` points at, and calls `onPress` when one
25
+ * of them is pressed there.
26
+ *
27
+ * `keys` is compared by identity: an app that rebuilds its list every render
28
+ * re-registers every render, which is correct and cheap. One that memoises does
29
+ * not. `onPress` is read through a ref, so changing the handler does not
30
+ * re-register anything -- the native side only wants the list.
31
+ *
32
+ * Does nothing when `keys` is absent, which is how the `View` override can call
33
+ * it unconditionally and pay almost nothing for the views that do not use it.
34
+ */
35
+ export declare function useHandledKeys(ref: {
36
+ current: unknown;
37
+ }, keys: ReadonlyArray<HandledKey> | undefined, onPress: ((pressed: PressedKey) => void) | undefined): void;
38
+ //# sourceMappingURL=useHandledKeys.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useHandledKeys.d.ts","sourceRoot":"","sources":["../../src/useHandledKeys.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAMH,iFAAiF;AACjF,MAAM,WAAW,UAAU;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,gFAAgF;AAChF,MAAM,MAAM,UAAU,GAAG,UAAU,CAAC;AASpC,2DAA2D;AAC3D,eAAO,MAAM,SAAS,cAAc,CAAC;AAKrC;;;;;;;;;;;GAWG;AACH,wBAAgB,cAAc,CAC5B,GAAG,EAAE;IAAC,OAAO,EAAE,OAAO,CAAA;CAAC,EACvB,IAAI,EAAE,aAAa,CAAC,UAAU,CAAC,GAAG,SAAS,EAC3C,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,UAAU,KAAK,IAAI,CAAC,GAAG,SAAS,GACnD,IAAI,CA0CN"}
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ /**
3
+ * The half of `<KeyHandler>` that is not a component.
4
+ *
5
+ * Extracted so that the `View` override can use the same implementation rather
6
+ * than a second copy of it: a view that declares `keyDownEvents` and a
7
+ * `<KeyHandler>` are two spellings of one thing, and two spellings that drifted
8
+ * apart would be worse than either.
9
+ *
10
+ * @format
11
+ */
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.KEY_EVENT = void 0;
14
+ exports.useHandledKeys = useHandledKeys;
15
+ const react_1 = require("react");
16
+ const react_native_1 = require("react-native");
17
+ const windows = react_native_1.TurboModuleRegistry.get('BasaltWindows');
18
+ /** The event the host emits for a press a view claimed. */
19
+ exports.KEY_EVENT = 'basaltKey';
20
+ /**
21
+ * Registers `keys` for whatever `ref` points at, and calls `onPress` when one
22
+ * of them is pressed there.
23
+ *
24
+ * `keys` is compared by identity: an app that rebuilds its list every render
25
+ * re-registers every render, which is correct and cheap. One that memoises does
26
+ * not. `onPress` is read through a ref, so changing the handler does not
27
+ * re-register anything -- the native side only wants the list.
28
+ *
29
+ * Does nothing when `keys` is absent, which is how the `View` override can call
30
+ * it unconditionally and pay almost nothing for the views that do not use it.
31
+ */
32
+ function useHandledKeys(ref, keys, onPress) {
33
+ const handler = (0, react_1.useRef)(onPress);
34
+ handler.current = onPress;
35
+ (0, react_1.useEffect)(() => {
36
+ // `__nativeTag`, with two underscores: that is the new renderer's name for
37
+ // it, and `_nativeTag` is undefined there. `<DropTarget>` learned the same.
38
+ const tag = ref.current?.__nativeTag;
39
+ if (keys == null || tag == null || windows == null) {
40
+ return;
41
+ }
42
+ windows.setHandledKeys(tag, keys);
43
+ return () => windows.clearHandledKeys(tag);
44
+ }, [keys, ref]);
45
+ (0, react_1.useEffect)(() => {
46
+ if (keys == null) {
47
+ return;
48
+ }
49
+ const subscription = react_native_1.DeviceEventEmitter.addListener(exports.KEY_EVENT, (event) => {
50
+ const tag = ref.current?.__nativeTag;
51
+ // By tag, because every listener in the app hears every event: the
52
+ // emitter is one channel and the host has already chosen which view the
53
+ // key belongs to.
54
+ if (tag == null || event.tag !== tag) {
55
+ return;
56
+ }
57
+ handler.current?.({
58
+ key: event.key,
59
+ altKey: event.altKey,
60
+ ctrlKey: event.ctrlKey,
61
+ metaKey: event.metaKey,
62
+ shiftKey: event.shiftKey,
63
+ });
64
+ });
65
+ return () => subscription.remove();
66
+ // Whether there are keys at all decides if this listens; which keys they
67
+ // are does not, because the host has already matched by the time it emits.
68
+ }, [keys == null, ref]);
69
+ }
70
+ //# sourceMappingURL=useHandledKeys.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useHandledKeys.js","sourceRoot":"","sources":["../../src/useHandledKeys.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;AA2CH,wCA8CC;AAvFD,iCAAwC;AACxC,+CAAqE;AAoBrE,MAAM,OAAO,GAAG,kCAAmB,CAAC,GAAG,CAAsB,eAAe,CAAC,CAAC;AAE9E,2DAA2D;AAC9C,QAAA,SAAS,GAAG,WAAW,CAAC;AAKrC;;;;;;;;;;;GAWG;AACH,SAAgB,cAAc,CAC5B,GAAuB,EACvB,IAA2C,EAC3C,OAAoD;IAEpD,MAAM,OAAO,GAAG,IAAA,cAAM,EAAC,OAAO,CAAC,CAAC;IAChC,OAAO,CAAC,OAAO,GAAG,OAAO,CAAC;IAE1B,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,2EAA2E;QAC3E,4EAA4E;QAC5E,MAAM,GAAG,GAAI,GAAG,CAAC,OAAuB,EAAE,WAAW,C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+ *
6
+ * window.setSize(900, 700);
7
+ * window.setPosition(100, 100);
8
+ * window.center();
9
+ * window.setFullScreen(true);
10
+ * window.minimize();
11
+ * window.toggleMaximize();
12
+ * window.close();
13
+ *
14
+ * const {width, height, x, y, fullScreen, maximized} = window.bounds;
15
+ *
16
+ * React Native has no API for any of this: on a phone there is one window, it
17
+ * is the screen, and nothing an app says would change it. On a desktop it is
18
+ * the first thing an app wants after it has drawn something.
19
+ *
20
+ * ## `bounds` is live
21
+ *
22
+ * It re-renders when the window moves, is resized, or changes state, because
23
+ * the alternative -- a `getBounds()` an app calls and caches -- is an app whose
24
+ * layout is right until somebody drags a corner. The host emits the change; see
25
+ * native/core/WindowMethods.h.
26
+ *
27
+ * Reading it before there is a window gives zeroes rather than null, so that
28
+ * `const {width} = window.bounds` never throws during a first render.
29
+ *
30
+ * ## What the platforms will not do
31
+ *
32
+ * `setPosition` and `center` do nothing on Linux, and `bounds.x` and `bounds.y`
33
+ * are always zero there. This is not unimplemented: GTK4 removed
34
+ * `gtk_window_move` and Wayland has no equivalent, because a client has no idea
35
+ * where its window is and no say in it. Both display servers centre an unplaced
36
+ * window by default, so an app that never moves its window already gets what
37
+ * `center()` would have asked for.
38
+ *
39
+ * Every other platform difference is spelling. `setSize` is a request on all
40
+ * three -- a tiling window manager may ignore it -- which is why `bounds`
41
+ * reports what happened rather than what was asked for.
42
+ *
43
+ * ## How big it may be, and where it sits
44
+ *
45
+ * window.setMinimumSize(400, 300);
46
+ * window.setMaximumSize(1200, 900); // 0 in either direction clears a limit
47
+ * window.setResizable(false);
48
+ * window.setAlwaysOnTop(true);
49
+ *
50
+ * Two of these do nothing on Linux, and that is settled rather than pending:
51
+ * GTK4 removed `gtk_window_set_geometry_hints` and `gtk_window_set_keep_above`
52
+ * because Wayland has no protocol for either. So rather than have an app read
53
+ * this paragraph, `window.capabilities` answers:
54
+ *
55
+ * {position, minimumSize, maximumSize, resizable, alwaysOnTop}
56
+ *
57
+ * all true on macOS and Windows; on Linux, `minimumSize` and `resizable`. An
58
+ * app can put its "always on top" switch away on the desktop that has no such
59
+ * thing, which is better than a switch that lies.
60
+ *
61
+ * ## Refusing to close
62
+ *
63
+ * useCloseRequest(close => {
64
+ * if (unsaved) {
65
+ * setAsking(true);
66
+ * } else {
67
+ * close();
68
+ * }
69
+ * });
70
+ *
71
+ * A window with a close handler stops closing on its own: every attempt -- its
72
+ * close button, Cmd-W, Alt+F4, the window manager -- is refused and reported,
73
+ * and the window goes when the app says so by calling the `close` it was
74
+ * handed. Which is the point: there is nowhere else to put "are you sure".
75
+ *
76
+ * On macOS this covers closing the window and not Cmd-Q, which terminates the
77
+ * application without asking any window whether it minds.
78
+ *
79
+ * @format
80
+ */
81
+ import type { CloseRequestHandler } from './closeRequest';
82
+ export type { CloseRequestHandler, WindowId } from './closeRequest';
83
+ /** Where the window is and how big, plus the two states that are not sizes. */
84
+ export type WindowBounds = {
85
+ x: number;
86
+ y: number;
87
+ width: number;
88
+ height: number;
89
+ fullScreen: boolean;
90
+ maximized: boolean;
91
+ };
92
+ /**
93
+ * What this desktop actually does, which is not the same list everywhere.
94
+ *
95
+ * All false where there is no window module, so an app that checks before
96
+ * offering a control gets the right answer rather than an exception.
97
+ */
98
+ export type WindowCapabilities = {
99
+ position: boolean;
100
+ minimumSize: boolean;
101
+ maximumSize: boolean;
102
+ resizable: boolean;
103
+ alwaysOnTop: boolean;
104
+ };
105
+ /**
106
+ * The imperative half, usable outside a component.
107
+ *
108
+ * Every call is a no-op on a host with no window module, so the same code runs
109
+ * on a platform that has not implemented one.
110
+ */
111
+ export declare const windowControl: Readonly<{
112
+ setSize(width: number, height: number): void;
113
+ setPosition(x: number, y: number): void;
114
+ center(): void;
115
+ setFullScreen(fullScreen?: boolean): void;
116
+ minimize(): void;
117
+ toggleMaximize(): void;
118
+ close(): void;
119
+ setMinimumSize(width: number, height: number): void;
120
+ setMaximumSize(width: number, height: number): void;
121
+ setResizable(resizable?: boolean): void;
122
+ setAlwaysOnTop(alwaysOnTop?: boolean): void;
123
+ getBounds(): WindowBounds;
124
+ getCapabilities(): WindowCapabilities;
125
+ }>;
126
+ /**
127
+ * Be asked before this window closes.
128
+ *
129
+ * Pass null or nothing to stop being asked, which is also what unmounting does.
130
+ * See the header above, and `<Window onCloseRequest>` for a second window.
131
+ */
132
+ export declare function useCloseRequest(handler?: CloseRequestHandler | null): void;
133
+ export type WindowControl = typeof windowControl;
134
+ /** What the hook returns: the imperative surface, plus live state. */
135
+ export type UseWindow = WindowControl & {
136
+ bounds: WindowBounds;
137
+ capabilities: WindowCapabilities;
138
+ };
139
+ export declare function useWindow(): UseWindow;
140
+ //# sourceMappingURL=useWindow.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useWindow.d.ts","sourceRoot":"","sources":["../../src/useWindow.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+EG;AASH,OAAO,KAAK,EAAC,mBAAmB,EAAC,MAAM,gBAAgB,CAAC;AAExD,YAAY,EAAC,mBAAmB,EAAE,QAAQ,EAAC,MAAM,gBAAgB,CAAC;AAElE,+EAA+E;AAC/E,MAAM,MAAM,YAAY,GAAG;IACzB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,OAAO,CAAC;IACpB,SAAS,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B,QAAQ,EAAE,OAAO,CAAC;IAClB,WAAW,EAAE,OAAO,CAAC;IACrB,WAAW,EAAE,OAAO,CAAC;IACrB,SAAS,EAAE,OAAO,CAAC;IACnB,WAAW,EAAE,OAAO,CAAC;CACtB,CAAC;AAgEF;;;;;GAKG;AACH,eAAO,MAAM,aAAa;mBACT,MAAM,UAAU,MAAM,GAAG,IAAI;mBAG7B,MAAM,KAAK,MAAM,GAAG,IAAI;cAG7B,IAAI;+BAGa,OAAO,GAAG,IAAI;gBAG7B,IAAI;sBAGE,IAAI;aAGb,IAAI;0BAGS,MAAM,UAAU,MAAM,GAAG,IAAI;0BAG7B,MAAM,UAAU,MAAM,GAAG,IAAI;6BAG1B,OAAO,GAAG,IAAI;iCAGV,OAAO,GAAG,IAAI;iBAG9B,YAAY;uBAGN,kBAAkB;EAKrC,CAAC;AAEH;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,OAAO,CAAC,EAAE,mBAAmB,GAAG,IAAI,GAAG,IAAI,CAE1E;AAED,MAAM,MAAM,aAAa,GAAG,OAAO,aAAa,CAAC;AAEjD,sEAAsE;AACtE,MAAM,MAAM,SAAS,GAAG,aAAa,GAAG;IACtC,MAAM,EAAE,YAAY,CAAC;IACrB,YAAY,EAAE,kBAAkB,CAAC;CAClC,CAAC;AAEF,wBAAgB,SAAS,IAAI,SAAS,CAmBrC"}
@@ -0,0 +1,233 @@
1
+ /**
2
+ * The window: how big it is, where it is, and what it is doing.
3
+ *
4
+ * const window = useWindow();
5
+ *
6
+ * window.setSize(900, 700);
7
+ * window.setPosition(100, 100);
8
+ * window.center();
9
+ * window.setFullScreen(true);
10
+ * window.minimize();
11
+ * window.toggleMaximize();
12
+ * window.close();
13
+ *
14
+ * const {width, height, x, y, fullScreen, maximized} = window.bounds;
15
+ *
16
+ * React Native has no API for any of this: on a phone there is one window, it
17
+ * is the screen, and nothing an app says would change it. On a desktop it is
18
+ * the first thing an app wants after it has drawn something.
19
+ *
20
+ * ## `bounds` is live
21
+ *
22
+ * It re-renders when the window moves, is resized, or changes state, because
23
+ * the alternative -- a `getBounds()` an app calls and caches -- is an app whose
24
+ * layout is right until somebody drags a corner. The host emits the change; see
25
+ * native/core/WindowMethods.h.
26
+ *
27
+ * Reading it before there is a window gives zeroes rather than null, so that
28
+ * `const {width} = window.bounds` never throws during a first render.
29
+ *
30
+ * ## What the platforms will not do
31
+ *
32
+ * `setPosition` and `center` do nothing on Linux, and `bounds.x` and `bounds.y`
33
+ * are always zero there. This is not unimplemented: GTK4 removed
34
+ * `gtk_window_move` and Wayland has no equivalent, because a client has no idea
35
+ * where its window is and no say in it. Both display servers centre an unplaced
36
+ * window by default, so an app that never moves its window already gets what
37
+ * `center()` would have asked for.
38
+ *
39
+ * Every other platform difference is spelling. `setSize` is a request on all
40
+ * three -- a tiling window manager may ignore it -- which is why `bounds`
41
+ * reports what happened rather than what was asked for.
42
+ *
43
+ * ## How big it may be, and where it sits
44
+ *
45
+ * window.setMinimumSize(400, 300);
46
+ * window.setMaximumSize(1200, 900); // 0 in either direction clears a limit
47
+ * window.setResizable(false);
48
+ * window.setAlwaysOnTop(true);
49
+ *
50
+ * Two of these do nothing on Linux, and that is settled rather than pending:
51
+ * GTK4 removed `gtk_window_set_geometry_hints` and `gtk_window_set_keep_above`
52
+ * because Wayland has no protocol for either. So rather than have an app read
53
+ * this paragraph, `window.capabilities` answers:
54
+ *
55
+ * {position, minimumSize, maximumSize, resizable, alwaysOnTop}
56
+ *
57
+ * all true on macOS and Windows; on Linux, `minimumSize` and `resizable`. An
58
+ * app can put its "always on top" switch away on the desktop that has no such
59
+ * thing, which is better than a switch that lies.
60
+ *
61
+ * ## Refusing to close
62
+ *
63
+ * useCloseRequest(close => {
64
+ * if (unsaved) {
65
+ * setAsking(true);
66
+ * } else {
67
+ * close();
68
+ * }
69
+ * });
70
+ *
71
+ * A window with a close handler stops closing on its own: every attempt -- its
72
+ * close button, Cmd-W, Alt+F4, the window manager -- is refused and reported,
73
+ * and the window goes when the app says so by calling the `close` it was
74
+ * handed. Which is the point: there is nowhere else to put "are you sure".
75
+ *
76
+ * On macOS this covers closing the window and not Cmd-Q, which terminates the
77
+ * application without asking any window whether it minds.
78
+ *
79
+ * @format
80
+ */
81
+ 'use strict';
82
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
83
+ if (k2 === undefined) k2 = k;
84
+ var desc = Object.getOwnPropertyDescriptor(m, k);
85
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
86
+ desc = { enumerable: true, get: function() { return m[k]; } };
87
+ }
88
+ Object.defineProperty(o, k2, desc);
89
+ }) : (function(o, m, k, k2) {
90
+ if (k2 === undefined) k2 = k;
91
+ o[k2] = m[k];
92
+ }));
93
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
94
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
95
+ }) : function(o, v) {
96
+ o["default"] = v;
97
+ });
98
+ var __importStar = (this && this.__importStar) || (function () {
99
+ var ownKeys = function(o) {
100
+ ownKeys = Object.getOwnPropertyNames || function (o) {
101
+ var ar = [];
102
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
103
+ return ar;
104
+ };
105
+ return ownKeys(o);
106
+ };
107
+ return function (mod) {
108
+ if (mod && mod.__esModule) return mod;
109
+ var result = {};
110
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
111
+ __setModuleDefault(result, mod);
112
+ return result;
113
+ };
114
+ })();
115
+ Object.defineProperty(exports, "__esModule", { value: true });
116
+ exports.windowControl = void 0;
117
+ exports.useCloseRequest = useCloseRequest;
118
+ exports.useWindow = useWindow;
119
+ const React = __importStar(require("react"));
120
+ const react_native_1 = require("react-native");
121
+ const closeRequest_1 = require("./closeRequest");
122
+ const NativeWindow = react_native_1.TurboModuleRegistry.get('BasaltWindow');
123
+ // Must match kWindowBoundsEvent in native/core/WindowMethods.h.
124
+ const BOUNDS_EVENT = 'basaltWindowBoundsChanged';
125
+ const NO_BOUNDS = Object.freeze({
126
+ x: 0,
127
+ y: 0,
128
+ width: 0,
129
+ height: 0,
130
+ fullScreen: false,
131
+ maximized: false,
132
+ });
133
+ // What this desktop actually does, which is not the same list everywhere.
134
+ //
135
+ // All false on a host with no window module, so an app that checks before
136
+ // offering a control gets the right answer rather than an exception.
137
+ const NO_CAPABILITIES = Object.freeze({
138
+ position: false,
139
+ minimumSize: false,
140
+ maximumSize: false,
141
+ resizable: false,
142
+ alwaysOnTop: false,
143
+ });
144
+ function readCapabilities() {
145
+ if (NativeWindow?.getCapabilities == null) {
146
+ return NO_CAPABILITIES;
147
+ }
148
+ return NativeWindow.getCapabilities() ?? NO_CAPABILITIES;
149
+ }
150
+ // Asked once. These are five booleans a platform knows at compile time, not a
151
+ // question for the window manager, and re-reading them on every render would be
152
+ // a JSI call per frame for an answer that cannot change.
153
+ const capabilities = readCapabilities();
154
+ function readBounds() {
155
+ if (NativeWindow?.getBounds == null) {
156
+ return NO_BOUNDS;
157
+ }
158
+ const bounds = NativeWindow.getBounds();
159
+ return bounds != null ? bounds : NO_BOUNDS;
160
+ }
161
+ /**
162
+ * The imperative half, usable outside a component.
163
+ *
164
+ * Every call is a no-op on a host with no window module, so the same code runs
165
+ * on a platform that has not implemented one.
166
+ */
167
+ exports.windowControl = Object.freeze({
168
+ setSize(width, height) {
169
+ NativeWindow?.setSize?.(width, height);
170
+ },
171
+ setPosition(x, y) {
172
+ NativeWindow?.setPosition?.(x, y);
173
+ },
174
+ center() {
175
+ NativeWindow?.center?.();
176
+ },
177
+ setFullScreen(fullScreen) {
178
+ NativeWindow?.setFullScreen?.(fullScreen === true);
179
+ },
180
+ minimize() {
181
+ NativeWindow?.minimize?.();
182
+ },
183
+ toggleMaximize() {
184
+ NativeWindow?.toggleMaximize?.();
185
+ },
186
+ close() {
187
+ NativeWindow?.close?.();
188
+ },
189
+ setMinimumSize(width, height) {
190
+ NativeWindow?.setMinimumSize?.(width, height);
191
+ },
192
+ setMaximumSize(width, height) {
193
+ NativeWindow?.setMaximumSize?.(width, height);
194
+ },
195
+ setResizable(resizable) {
196
+ NativeWindow?.setResizable?.(resizable !== false);
197
+ },
198
+ setAlwaysOnTop(alwaysOnTop) {
199
+ NativeWindow?.setAlwaysOnTop?.(alwaysOnTop === true);
200
+ },
201
+ getBounds() {
202
+ return readBounds();
203
+ },
204
+ getCapabilities() {
205
+ // The cached answer, so that the imperative half and the hook cannot
206
+ // disagree about a thing that does not change.
207
+ return capabilities;
208
+ },
209
+ });
210
+ /**
211
+ * Be asked before this window closes.
212
+ *
213
+ * Pass null or nothing to stop being asked, which is also what unmounting does.
214
+ * See the header above, and `<Window onCloseRequest>` for a second window.
215
+ */
216
+ function useCloseRequest(handler) {
217
+ (0, closeRequest_1.useCloseRequestFor)(closeRequest_1.mainWindowId, () => exports.windowControl.close(), handler, []);
218
+ }
219
+ function useWindow() {
220
+ const [bounds, setBounds] = React.useState(readBounds);
221
+ React.useEffect(() => {
222
+ // Read again on mount as well as subscribing. The window may have been
223
+ // resized between the first render and this effect -- which on a host that
224
+ // opens its window and mounts into it is the common case, not the rare one.
225
+ setBounds(readBounds());
226
+ const subscription = react_native_1.DeviceEventEmitter.addListener(BOUNDS_EVENT, (next) => {
227
+ setBounds(next ?? NO_BOUNDS);
228
+ });
229
+ return () => subscription.remove();
230
+ }, []);
231
+ return React.useMemo(() => ({ ...exports.windowControl, bounds, capabilities }), [bounds]);
232
+ }
233
+ //# sourceMappingURL=useWindow.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useWindow.js","sourceRoot":"","sources":["../../src/useWindow.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+EG;AAEH,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyJb,0CAEC;AAUD,8BAmBC;AAtLD,6CAA+B;AAE/B,+CAAqE;AAErE,iDAAgE;AA6ChE,MAAM,YAAY,GAAG,kCAAmB,CAAC,GAAG,CAAqB,cAAc,CAAC,CAAC;AAEjF,gEAAgE;AAChE,MAAM,YAAY,GAAG,2BAA2B,CAAC;AAEjD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CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;IAEvD,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,uEAAuE;QACvE,2EAA2E;QAC3E,4EAA4E;QAC5E,SAAS,CAAC,UAAU,EAAE,CAAC,CAAC;QAExB,MAAM,YAAY,GAAG,iCAAkB,CAAC,WAAW,CACjD,YAAY,EACZ,CAAC,IAAyB,EAAE,EAAE;YAC5B,SAAS,CAAC,IAAI,IAAI,SAAS,CAAC,CAAC;QAC/B,CAAC,CACF,CAAC;QACF,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,MAAM,EAAE,CAAC;IACrC,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,EAAC,GAAG,qBAAa,EAAE,MAAM,EAAE,YAAY,EAAC,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;AACnF,CAAC"}
@@ -0,0 +1 @@
1
+ {"root":["../src/dragsource.tsx","../src/droptarget.tsx","../src/keyhandler.tsx","../src/menu.tsx","../src/titlebar.tsx","../src/window.tsx","../src/closerequest.ts","../src/globals.d.ts","../src/index.ts","../src/quitrequest.ts","../src/resourcepath.ts","../src/responsebody.ts","../src/responseheaders.ts","../src/titlebarstate.ts","../src/usecontextmenu.ts","../src/usedialog.ts","../src/usedisplays.ts","../src/usehandledkeys.ts","../src/usewindow.ts","../src/overrides/alert.ts","../src/overrides/baseviewconfig.ts","../src/overrides/platform.d.ts","../src/overrides/platform.linux.ts","../src/overrides/platform.macos.ts","../src/overrides/platform.windows.ts","../src/overrides/reactdevtoolssettingsmanager.ts","../src/overrides/refreshcontrol.tsx","../src/overrides/scrollview.tsx","../src/overrides/share.ts","../src/overrides/textinput.tsx","../src/overrides/view.tsx","../src/overrides/createplatform.ts","../src/overrides/setupdevelopertools.ts","../src/overrides/setupxhr.ts","../src/overrides/upstream.d.ts","../cli/basalt.ts","../cli/bundle-cli.ts","../cli/bundlewithassets.ts","../cli/desktop.ts","../cli/doctor.ts","../cli/init.ts","../cli/metro.ts","../cli/packageapp.ts","../cli/steps.ts","../react-native.config.js"],"version":"6.0.3"}