@bugsee/react-native 0.0.0-stage → 7.0.0-beta2

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 (250) hide show
  1. package/BugseeReactNative.podspec +95 -0
  2. package/LICENSE +21 -0
  3. package/README.md +557 -2
  4. package/android/build.gradle +162 -0
  5. package/android/consumer-rules.pro +2 -0
  6. package/android/src/main/AndroidManifest.xml +33 -0
  7. package/android/src/main/java/com/bugsee/reactnative/AppearanceBridge.java +82 -0
  8. package/android/src/main/java/com/bugsee/reactnative/AttributeBridge.java +209 -0
  9. package/android/src/main/java/com/bugsee/reactnative/BreadcrumbFilterBridge.java +443 -0
  10. package/android/src/main/java/com/bugsee/reactnative/BridgeJson.java +168 -0
  11. package/android/src/main/java/com/bugsee/reactnative/BugseeModule.java +1869 -0
  12. package/android/src/main/java/com/bugsee/reactnative/BugseeOptionEnums.java +136 -0
  13. package/android/src/main/java/com/bugsee/reactnative/BugseePackage.java +42 -0
  14. package/android/src/main/java/com/bugsee/reactnative/BugseeReactNativeWrapper.java +200 -0
  15. package/android/src/main/java/com/bugsee/reactnative/BugseeStatusMapper.java +66 -0
  16. package/android/src/main/java/com/bugsee/reactnative/BugseeTokens.java +22 -0
  17. package/android/src/main/java/com/bugsee/reactnative/ConsoleEchoDedup.java +202 -0
  18. package/android/src/main/java/com/bugsee/reactnative/CreatedReports.java +127 -0
  19. package/android/src/main/java/com/bugsee/reactnative/DataRequestBridge.java +375 -0
  20. package/android/src/main/java/com/bugsee/reactnative/ExceptionBridge.java +88 -0
  21. package/android/src/main/java/com/bugsee/reactnative/ExceptionExecutors.java +33 -0
  22. package/android/src/main/java/com/bugsee/reactnative/LogFilterBridge.java +375 -0
  23. package/android/src/main/java/com/bugsee/reactnative/NetworkEvents.java +227 -0
  24. package/android/src/main/java/com/bugsee/reactnative/NetworkFilterBridge.java +498 -0
  25. package/android/src/main/java/com/bugsee/reactnative/PluginEndpoint.java +48 -0
  26. package/android/src/main/java/com/bugsee/reactnative/ReactNativeWebException.java +19 -0
  27. package/android/src/main/java/com/bugsee/reactnative/ReactNativeWrapperInitProvider.java +61 -0
  28. package/android/src/main/java/com/bugsee/reactnative/ReactRootOriginTracker.java +867 -0
  29. package/android/src/main/java/com/bugsee/reactnative/ReportArgs.java +58 -0
  30. package/android/src/main/java/com/bugsee/reactnative/ReportHandlerBridge.java +336 -0
  31. package/android/src/main/java/com/bugsee/reactnative/ReportHandlerDeadlines.java +57 -0
  32. package/android/src/main/java/com/bugsee/reactnative/ReportOps.java +287 -0
  33. package/android/src/main/java/com/bugsee/reactnative/SecureRectanglePulls.java +113 -0
  34. package/android/src/main/java/com/bugsee/reactnative/SecureRectangleStore.java +692 -0
  35. package/android/src/main/java/com/bugsee/reactnative/SpanHandles.java +143 -0
  36. package/android/src/main/java/com/bugsee/reactnative/WrapperChannelHolder.java +137 -0
  37. package/android/src/main/java/com/bugsee/reactnative/WrapperEventBus.java +110 -0
  38. package/android/src/main/java/com/bugsee/reactnative/WrapperRegistrar.java +54 -0
  39. package/app.plugin.js +4 -0
  40. package/ios/BGSRNConsoleCapture.h +52 -0
  41. package/ios/BGSRNConsoleCapture.mm +344 -0
  42. package/ios/BugseeModule.h +25 -0
  43. package/ios/BugseeModule.mm +2728 -0
  44. package/ios/Package.swift +71 -0
  45. package/ios/Support/Package.resolved +14 -0
  46. package/ios/Support/Package.swift +44 -0
  47. package/ios/Support/Sources/BugseeRNSupport/BGSRNAttributes.m +52 -0
  48. package/ios/Support/Sources/BugseeRNSupport/BGSRNCreatedReportOps.m +236 -0
  49. package/ios/Support/Sources/BugseeRNSupport/BGSRNCreatedReports.m +184 -0
  50. package/ios/Support/Sources/BugseeRNSupport/BGSRNDataRequestBridge.m +431 -0
  51. package/ios/Support/Sources/BugseeRNSupport/BGSRNErrorMessage.m +40 -0
  52. package/ios/Support/Sources/BugseeRNSupport/BGSRNEventBus.m +70 -0
  53. package/ios/Support/Sources/BugseeRNSupport/BGSRNExceptions.m +63 -0
  54. package/ios/Support/Sources/BugseeRNSupport/BGSRNGuardedEmit.mm +32 -0
  55. package/ios/Support/Sources/BugseeRNSupport/BGSRNJSON.m +40 -0
  56. package/ios/Support/Sources/BugseeRNSupport/BGSRNLaunchHold.m +147 -0
  57. package/ios/Support/Sources/BugseeRNSupport/BGSRNMainThread.m +23 -0
  58. package/ios/Support/Sources/BugseeRNSupport/BGSRNNetworkEvents.m +159 -0
  59. package/ios/Support/Sources/BugseeRNSupport/BGSRNNetworkFilter.m +155 -0
  60. package/ios/Support/Sources/BugseeRNSupport/BGSRNPluginEndpoint.m +21 -0
  61. package/ios/Support/Sources/BugseeRNSupport/BGSRNReactRootOriginTracker.m +63 -0
  62. package/ios/Support/Sources/BugseeRNSupport/BGSRNReactWindow.m +251 -0
  63. package/ios/Support/Sources/BugseeRNSupport/BGSRNReportArgs.m +47 -0
  64. package/ios/Support/Sources/BugseeRNSupport/BGSRNReportDeadlines.m +8 -0
  65. package/ios/Support/Sources/BugseeRNSupport/BGSRNReportHandlerBridge.m +308 -0
  66. package/ios/Support/Sources/BugseeRNSupport/BGSRNReportOps.m +345 -0
  67. package/ios/Support/Sources/BugseeRNSupport/BGSRNSecureRectangles.m +508 -0
  68. package/ios/Support/Sources/BugseeRNSupport/BGSRNSettleOnce.m +62 -0
  69. package/ios/Support/Sources/BugseeRNSupport/BGSRNSpanHandles.m +136 -0
  70. package/ios/Support/Sources/BugseeRNSupport/BGSRNStatusMapper.m +18 -0
  71. package/ios/Support/Sources/BugseeRNSupport/BGSRNTokens.m +9 -0
  72. package/ios/Support/Sources/BugseeRNSupport/BGSRNValues.m +5 -0
  73. package/ios/Support/Sources/BugseeRNSupport/BGSRNWrapper.m +54 -0
  74. package/ios/Support/Sources/BugseeRNSupport/BGSRNWrapperChannelHolder.m +59 -0
  75. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNAttributes.h +63 -0
  76. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNCreatedReportOps.h +51 -0
  77. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNCreatedReports.h +81 -0
  78. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNDataRequestBridge.h +118 -0
  79. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNErrorMessage.h +30 -0
  80. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNEventBus.h +45 -0
  81. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNExceptions.h +31 -0
  82. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNGuardedEmit.h +31 -0
  83. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNJSON.h +25 -0
  84. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNLaunchHold.h +86 -0
  85. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNMainThread.h +32 -0
  86. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNNetworkEvents.h +28 -0
  87. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNNetworkFilter.h +28 -0
  88. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNPluginEndpoint.h +17 -0
  89. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReactRootOriginTracker.h +48 -0
  90. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReactWindow.h +135 -0
  91. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportArgs.h +17 -0
  92. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportDeadlines.h +37 -0
  93. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportHandlerBridge.h +94 -0
  94. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportOps.h +86 -0
  95. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNSecureRectangles.h +198 -0
  96. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNSettleOnce.h +25 -0
  97. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNSpanHandles.h +49 -0
  98. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNStatusMapper.h +26 -0
  99. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNTokens.h +14 -0
  100. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNValues.h +18 -0
  101. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNWrapper.h +40 -0
  102. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNWrapperChannelHolder.h +74 -0
  103. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNAttributesTests.m +194 -0
  104. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNCreatedReportOpsTests.m +274 -0
  105. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNCreatedReportsTests.m +240 -0
  106. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNDataRequestBridgeTests.m +685 -0
  107. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNErrorMessageTests.m +102 -0
  108. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNEventBusTests.m +136 -0
  109. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNExceptionsTests.m +68 -0
  110. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNFakeReport.h +41 -0
  111. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNFakeReport.m +166 -0
  112. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNGuardedEmitTests.mm +85 -0
  113. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNJSONTests.m +281 -0
  114. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNLaunchHoldTests.m +230 -0
  115. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNMainThreadTests.m +97 -0
  116. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNNetworkEventsTests.m +99 -0
  117. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNNetworkFilterTests.m +134 -0
  118. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNPluginEndpointTests.m +38 -0
  119. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReactRootOriginTrackerTests.m +210 -0
  120. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReactWindowTests.m +548 -0
  121. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportArgsTests.m +51 -0
  122. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportDeadlinesTests.m +22 -0
  123. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportHandlerBridgeTests.m +382 -0
  124. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportOpsTests.m +295 -0
  125. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNSecureRectanglesTests.m +568 -0
  126. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNSettleOnceTests.m +134 -0
  127. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNSpanHandlesTests.m +153 -0
  128. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNStatusMapperTests.m +81 -0
  129. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNValuesTests.m +32 -0
  130. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNWrapperChannelHolderTests.m +205 -0
  131. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNWrapperTests.m +66 -0
  132. package/ios/react-native-spm-prefix.h +10 -0
  133. package/native-versions.json +10 -0
  134. package/package.json +62 -3
  135. package/plugin/build/bundle-phase.d.ts +41 -0
  136. package/plugin/build/bundle-phase.js +116 -0
  137. package/plugin/build/bundle-phase.js.map +1 -0
  138. package/plugin/build/dsym-script.d.ts +32 -0
  139. package/plugin/build/dsym-script.js +159 -0
  140. package/plugin/build/dsym-script.js.map +1 -0
  141. package/plugin/build/endpoint.d.ts +30 -0
  142. package/plugin/build/endpoint.js +69 -0
  143. package/plugin/build/endpoint.js.map +1 -0
  144. package/plugin/build/gradle.d.ts +65 -0
  145. package/plugin/build/gradle.js +1066 -0
  146. package/plugin/build/gradle.js.map +1 -0
  147. package/plugin/build/index.d.ts +85 -0
  148. package/plugin/build/index.js +217 -0
  149. package/plugin/build/index.js.map +1 -0
  150. package/plugin/build/manifest.d.ts +48 -0
  151. package/plugin/build/manifest.js +69 -0
  152. package/plugin/build/manifest.js.map +1 -0
  153. package/plugin/build/native-versions.baked.json +4 -0
  154. package/plugin/build/native-versions.d.ts +10 -0
  155. package/plugin/build/native-versions.js +27 -0
  156. package/plugin/build/native-versions.js.map +1 -0
  157. package/plugin/build/pbx-string.d.ts +8 -0
  158. package/plugin/build/pbx-string.js +31 -0
  159. package/plugin/build/pbx-string.js.map +1 -0
  160. package/plugin/build/podfile.d.ts +3 -0
  161. package/plugin/build/podfile.js +28 -0
  162. package/plugin/build/podfile.js.map +1 -0
  163. package/plugin/build/properties.d.ts +19 -0
  164. package/plugin/build/properties.js +41 -0
  165. package/plugin/build/properties.js.map +1 -0
  166. package/plugin/build/scheme.d.ts +20 -0
  167. package/plugin/build/scheme.js +107 -0
  168. package/plugin/build/scheme.js.map +1 -0
  169. package/react-native.config.js +26 -0
  170. package/scripts/bugsee-sourcemaps.gradle +201 -0
  171. package/scripts/bugsee-xcode.sh +83 -0
  172. package/scripts/compose-then-inject.js +113 -0
  173. package/scripts/hermes-sourcemaps.js +634 -0
  174. package/scripts/hermesc-preserve-js.cmd +6 -0
  175. package/scripts/hermesc-preserve-js.js +200 -0
  176. package/scripts/hermesc-preserve-js.sh +7 -0
  177. package/src/NativeBugsee.ts +622 -0
  178. package/src/apm/notify.ts +58 -0
  179. package/src/apm/span.ts +403 -0
  180. package/src/apm/types.ts +57 -0
  181. package/src/appearance/report.ts +171 -0
  182. package/src/architecture.ts +48 -0
  183. package/src/attributes/errors.ts +39 -0
  184. package/src/attributes/validate.ts +150 -0
  185. package/src/breadcrumbs/add.ts +58 -0
  186. package/src/breadcrumbs/data.ts +33 -0
  187. package/src/breadcrumbs/filter.ts +215 -0
  188. package/src/breadcrumbs/types.ts +64 -0
  189. package/src/bridge/json.ts +110 -0
  190. package/src/console/capture.ts +180 -0
  191. package/src/console/dedup.ts +175 -0
  192. package/src/data/validate.ts +259 -0
  193. package/src/errorName.ts +32 -0
  194. package/src/exceptions/ErrorBoundary.tsx +92 -0
  195. package/src/exceptions/RootErrorReporter.tsx +61 -0
  196. package/src/exceptions/debugIds.ts +118 -0
  197. package/src/exceptions/handlers.ts +236 -0
  198. package/src/exceptions/options.ts +85 -0
  199. package/src/exceptions/payload.ts +456 -0
  200. package/src/exceptions/report.ts +170 -0
  201. package/src/exceptions/sha1.ts +148 -0
  202. package/src/exceptions/stack.ts +355 -0
  203. package/src/index.ts +962 -0
  204. package/src/logs/filter.ts +90 -0
  205. package/src/logs/log.ts +36 -0
  206. package/src/network/add.ts +165 -0
  207. package/src/network/filter.ts +198 -0
  208. package/src/options/AndroidLaunchOptions.ts +78 -0
  209. package/src/options/BugseeLaunchOptions.ts +190 -0
  210. package/src/options/IOSLaunchOptions.ts +57 -0
  211. package/src/options/android-options-manifest.json +646 -0
  212. package/src/options/createDefaultLaunchOptions.ts +29 -0
  213. package/src/options/endpoint.ts +58 -0
  214. package/src/options/enums.ts +104 -0
  215. package/src/options/ios-enums.json +19 -0
  216. package/src/options/keys.ts +39 -0
  217. package/src/options/option-enums.json +34 -0
  218. package/src/options/option-keys.json +107 -0
  219. package/src/report/BugseeReport.ts +264 -0
  220. package/src/report/CreatedReport.ts +127 -0
  221. package/src/report/dispatcher.ts +95 -0
  222. package/src/report/errors.ts +48 -0
  223. package/src/report/fields.ts +40 -0
  224. package/src/report/types.ts +157 -0
  225. package/src/report/validate.ts +197 -0
  226. package/src/secure/BugseeSecure.tsx +202 -0
  227. package/src/secure/ancestry.ts +622 -0
  228. package/src/secure/drivers.ts +342 -0
  229. package/src/secure/followEvents.ts +57 -0
  230. package/src/secure/hold.ts +99 -0
  231. package/src/secure/measureLoop.ts +323 -0
  232. package/src/secure/nativeAnimation.ts +1005 -0
  233. package/src/secure/rectangles.ts +93 -0
  234. package/src/secure/registry.ts +237 -0
  235. package/src/secure/surface.ts +83 -0
  236. package/src/secure/tracker.ts +723 -0
  237. package/src/secure/transition.ts +488 -0
  238. package/src/secure/unit.ts +22 -0
  239. package/src/status.ts +16 -0
  240. package/src/version.ts +9 -0
  241. package/src/viewtree/anchor.tsx +105 -0
  242. package/src/viewtree/constants.ts +20 -0
  243. package/src/viewtree/fiber.ts +251 -0
  244. package/src/viewtree/requests.ts +347 -0
  245. package/src/viewtree/walk.ts +902 -0
  246. package/src/wrapper/channel.ts +33 -0
  247. package/src/wrapper/collect.ts +52 -0
  248. package/src/wrapper/events.ts +45 -0
  249. package/src/wrapper/identity.ts +54 -0
  250. package/src/wrapper/lifecycle-events.ts +89 -0
@@ -0,0 +1,723 @@
1
+ import { ancestryOfInstance, clipToAncestors, clipWatchNodes, isHidden, screensHide } from './ancestry';
2
+ import type { Ancestry } from './ancestry';
3
+ import { CoverageHold } from './hold';
4
+ import { addFrameMeasurer, addMeasurer, addParked, watchNode, watchValue } from './measureLoop';
5
+ import { whenMoved } from './drivers';
6
+ import { nativeMotion, throughMotion } from './nativeAnimation';
7
+ import { clearOwner, setOwnerRectangles } from './registry';
8
+ import { surfaceOfInstance } from './surface';
9
+ import {
10
+ SECURE_TRANSITION_HOLD_MS,
11
+ bounding,
12
+ carriedCover,
13
+ carriedCovers,
14
+ carrierEntering,
15
+ carrierLeaving,
16
+ carriersOf,
17
+ joinStack,
18
+ keyOf,
19
+ modalOf,
20
+ observeStack,
21
+ screenCover,
22
+ screenRect,
23
+ screensOn,
24
+ stackMotionOf,
25
+ stackMoving,
26
+ } from './transition';
27
+ import type { Carrier, StackChange } from './transition';
28
+ import { errorName } from '../errorName';
29
+ import type { FiberLike, WindowRect } from '../viewtree/fiber';
30
+
31
+ /** How many frames running a moving view's rectangle must stay put before it leaves the per-frame re-measure. */
32
+ export const STEADY_FRAMES = 10;
33
+
34
+ type MeasureInWindow = (callback: (x: number, y: number, width: number, height: number) => void) => void;
35
+
36
+ /**
37
+ * How a mounted, enabled view is kept measured:
38
+ * - `tick`: wholly visible; re-measured on the 100 ms tick, as on main.
39
+ * - `active`: moving, or just shown, clipped or carried in by a transition,
40
+ * or under an `Animated` component; re-measured every frame until its
41
+ * rectangle has stayed put for {@link STEADY_FRAMES} frames (under an
42
+ * `Animated` component, always: a native animation can start, or its value
43
+ * jump, on any frame, and only its nodes tell).
44
+ * - `parked`: clipped and still. Its clipping nodes (a ScrollView and its
45
+ * content, a clipping view) are watched every frame, shared with every
46
+ * view under them, and a move wakes it; each frame also asks whether its
47
+ * screens hide it (once per screen a frame); every tick re-checks it by
48
+ * measuring the view alone.
49
+ * - `hidden`: withdrawn under an inactive screen; each frame asks only
50
+ * whether the screens still hide it (once a frame per screen), and
51
+ * measures again the frame they do not.
52
+ */
53
+ type Mode = 'tick' | 'active' | 'parked' | 'hidden';
54
+
55
+ /**
56
+ * Milliseconds on a clock that only goes forward: the hold must not end
57
+ * early because the wall clock was set forward (NTP, the user). Falls back
58
+ * to `Date.now` where there is no `performance.now`.
59
+ */
60
+ export function monotonicNow(): number {
61
+ const { performance: perf } = globalThis as { performance?: { now?: () => number } };
62
+ return typeof perf?.now === 'function' ? perf.now() : Date.now();
63
+ }
64
+
65
+ function where(rect: WindowRect | null): string {
66
+ // Stryker disable next-line StringLiteral -- any marker no rectangle reads as does
67
+ return rect === null ? 'none' : `${rect.x},${rect.y},${rect.width},${rect.height}`;
68
+ }
69
+
70
+ /**
71
+ * One `<BugseeSecure>`'s measuring and publishing, from mount (`start`) to
72
+ * unmount (`depart`) or disable (`stop`). Coverage is added at once and
73
+ * removed late (see `SECURE_SHRINK_HOLD_MS`), unmounting included: native
74
+ * draws the view until it mounts the commit that removed it, and a
75
+ * transition that carries it out draws it longer (see
76
+ * `SECURE_TRANSITION_HOLD_MS`). Only `stop`, an explicit disable, removes it
77
+ * at once.
78
+ */
79
+ export class SecureTracker {
80
+ private running = false;
81
+ private warned = false;
82
+ // Stryker disable next-line StringLiteral -- any mode but active, hidden or parked starts it on no loop
83
+ private mode: Mode = 'tick';
84
+ private surface: number | null = null;
85
+ private ancestry: Ancestry | null = null;
86
+ private readonly hold = new CoverageHold();
87
+ /** The `<Modal>` the view is in (`null`: none), read once a mount; `undefined` until then. */
88
+ private modal: Carrier | null | undefined;
89
+ /** Its `<Modal>` was last seen committed as not visible: closing, and already covered. */
90
+ // Stryker disable next-line BooleanLiteral -- `start` clears it before anything reads it
91
+ private closing = false;
92
+ /** A transition carrying the view in, until `until`. */
93
+ private carried: { readonly carriers: readonly Carrier[]; readonly until: number } | null = null;
94
+ /** Where a transition can carry the view, published with the rest until `until`. */
95
+ private cover: { readonly rect: WindowRect; readonly until: number } | null = null;
96
+ /** Mounted by the commit now running: its first measurement looks for a transition carrying it in. */
97
+ // Stryker disable next-line BooleanLiteral -- `start` sets it before anything reads it
98
+ private arriving = false;
99
+ /** Carried in by a transition: re-measured every frame until it settles, whatever mode it was in. */
100
+ // Stryker disable next-line BooleanLiteral -- `start` clears it before anything reads it
101
+ private settling = false;
102
+ /** Under an `Animated` component: re-measured every frame. Set by every measurement. */
103
+ // Stryker disable next-line BooleanLiteral -- every measurement sets it before `next` reads it
104
+ private animating = false;
105
+ /** What of the view was on screen at its last measurement (`null`: nothing); `undefined`: never measured. */
106
+ private seen: WindowRect | null | undefined;
107
+ /** The native values its transforms come from, watched for an animation starting. */
108
+ // Stryker disable next-line ArrayDeclaration -- the first watch replaces it whatever it holds
109
+ private values: object[] = [];
110
+ /** Whether each of `values` may be native, as last watched. */
111
+ // Stryker disable next-line ArrayDeclaration -- the first watch replaces it whatever it holds
112
+ private natives: boolean[] = [];
113
+ private unwatchValues: Array<() => void> = [];
114
+ /** Leaves the stacks its screens are on. */
115
+ private leaveStacks: Array<() => void> = [];
116
+ /** The screens on each stack its screens are on, by the stack's place in the path, as last seen. */
117
+ private stackScreens = new Map<number, Map<object, unknown>>();
118
+ /** Frames (or checks) in a row the visible rectangle stayed put. */
119
+ private steady = 0;
120
+ private lastVisible: string | undefined;
121
+ private lastSelf: string | undefined;
122
+ // Stryker disable next-line ArrayDeclaration -- the first watch replaces it whatever it holds
123
+ private watched: FiberLike[] = [];
124
+ private unwatch: Array<() => void> = [];
125
+ private unwatchModal: (() => void) | undefined;
126
+ private removeTick: (() => void) | undefined;
127
+ private removeFrame: (() => void) | undefined;
128
+ private removeParked: (() => void) | undefined;
129
+
130
+ constructor(
131
+ private readonly view: () => { measureInWindow: MeasureInWindow } | null,
132
+ private readonly token: object,
133
+ ) {}
134
+
135
+ start(): void {
136
+ // A remount of the same instance (StrictMode) ends what its unmount left.
137
+ this.forget();
138
+ this.running = true;
139
+ this.arriving = true;
140
+ this.measure();
141
+ this.removeTick = addMeasurer(() => this.onTick());
142
+ }
143
+
144
+ /** Disabled: nothing is covered from now on, at once. */
145
+ stop(): void {
146
+ this.forget();
147
+ clearOwner(this.token);
148
+ }
149
+
150
+ /**
151
+ * Unmounted: covers what it covered, and where a transition carrying it out
152
+ * can still draw it, until that has been held long enough; then removes
153
+ * it. Called from the unmounting commit, so its deletions can be read.
154
+ */
155
+ depart(): void {
156
+ if (!this.running) {
157
+ return;
158
+ }
159
+ const now = monotonicNow();
160
+ const above = this.ancestry;
161
+ let cover: WindowRect | null = null;
162
+ // The fiber tree and props are read as they are: a getter can throw.
163
+ this.attempt(() => {
164
+ if (above !== null) {
165
+ const leaving = carriersOf(above).filter((carrier) => carrierLeaving(above, carrier));
166
+ cover = carriedCovers(above, leaving, this.seen);
167
+ const replaced = this.replacedBy(above, leaving);
168
+ if (replaced !== null) {
169
+ cover = bounding(replaced, cover);
170
+ }
171
+ this.tellStacks(above, leaving, now + SECURE_TRANSITION_HOLD_MS, true);
172
+ }
173
+ });
174
+ this.leave();
175
+ if (cover !== null) {
176
+ // Joined with a cover still running (a push it was carried in by), the later end kept.
177
+ // Only drops a cover run out: what it returns is not used.
178
+ // Stryker disable next-line ArrayDeclaration
179
+ this.covering([], now);
180
+ const until = Math.max(now + SECURE_TRANSITION_HOLD_MS, this.cover?.until ?? 0);
181
+ this.cover = { rect: bounding(cover, this.cover?.rect), until };
182
+ }
183
+ const rectangles = this.covering(this.hold.update(null, now), now);
184
+ if (rectangles.length === 0) {
185
+ clearOwner(this.token);
186
+ return;
187
+ }
188
+ this.publish(rectangles);
189
+ this.removeTick = addMeasurer(() => this.onDeparted());
190
+ }
191
+
192
+ /**
193
+ * A screen popped as another is pushed onto its stack in the same commit
194
+ * (a `replace`) is animated out by the incoming screen's animation, not its
195
+ * own: where that can draw the view, or `null` when no screen came.
196
+ */
197
+ private replacedBy(above: Ancestry, leaving: readonly Carrier[]): WindowRect | null {
198
+ let cover: WindowRect | null = null;
199
+ for (const carrier of leaving) {
200
+ // A Modal (no stack), or a stack never read: nothing to compare with.
201
+ const before = this.stackScreens.get(carrier.stack as number);
202
+ if (before === undefined) {
203
+ continue;
204
+ }
205
+ const stack = above.path[carrier.stack as number] as FiberLike;
206
+ // The commit's own stack fiber may be either of the pair.
207
+ const now = [stack, stack.alternate].flatMap((fiber) => (fiber == null ? [] : [...screensOn(fiber)]));
208
+ // Either fiber of the pair measures the same host.
209
+ const screen = screenRect(above.path[carrier.index] as FiberLike);
210
+ for (const [key, props] of now) {
211
+ if (!before.has(key)) {
212
+ // As the screen below a push: a slide up leaves it where it is; anything not known, the whole screen.
213
+ // Its stack was read, so it was measured.
214
+ const moved = screenCover(stackMotionOf(props, false), screen, this.seen as WindowRect | null, false);
215
+ // Null only for a view seen nowhere, and then for every screen: the cover stays null either way.
216
+ // Stryker disable next-line ConditionalExpression
217
+ if (moved !== null) {
218
+ cover = bounding(moved, cover);
219
+ }
220
+ }
221
+ }
222
+ }
223
+ return cover;
224
+ }
225
+
226
+ /** Leaves every loop and forgets everything, without publishing. */
227
+ private forget(): void {
228
+ this.leave();
229
+ this.surface = null;
230
+ this.ancestry = null;
231
+ this.hold.clear();
232
+ this.cover = null;
233
+ this.carried = null;
234
+ this.modal = undefined;
235
+ this.closing = false;
236
+ this.seen = undefined;
237
+ }
238
+
239
+ /** Stops measuring: off every loop, as if never started. */
240
+ private leave(): void {
241
+ this.running = false;
242
+ this.settling = false;
243
+ this.removeTick?.();
244
+ this.removeTick = undefined;
245
+ // Stryker disable next-line StringLiteral -- any mode but active, hidden or parked leaves every loop
246
+ this.enter('tick');
247
+ this.watch([]);
248
+ this.unwatchModal?.();
249
+ this.unwatchModal = undefined;
250
+ this.watchValues([]);
251
+ // Off the stacks: a stopped view ignores what it is told anyway, so this only frees it.
252
+ // Stryker disable next-line all -- so its mutants are equivalent
253
+ this.leaveStacks.forEach((leave) => leave());
254
+ this.leaveStacks = [];
255
+ this.steady = 0;
256
+ this.lastVisible = undefined;
257
+ this.lastSelf = undefined;
258
+ }
259
+
260
+ /** The tick after unmounting: publishes what is still held, and removes it all once nothing is. */
261
+ private onDeparted(): void {
262
+ const rectangles = this.covering(this.hold.publishable(monotonicNow()), monotonicNow());
263
+ if (rectangles.length === 0) {
264
+ this.forget();
265
+ clearOwner(this.token);
266
+ } else {
267
+ this.publish(rectangles);
268
+ }
269
+ }
270
+
271
+ /** `rectangles` and, while it lasts, the transition's cover. */
272
+ private covering(rectangles: WindowRect[], now: number): WindowRect[] {
273
+ // Stryker disable next-line EqualityOperator -- one millisecond either way, at the end of a second
274
+ if (this.cover !== null && this.cover.until <= now) {
275
+ this.cover = null;
276
+ }
277
+ return this.cover === null ? rectangles : [this.cover.rect, ...rectangles];
278
+ }
279
+
280
+ /** Measures the view and its clipping ancestors, and publishes what it covers. */
281
+ measure(): void {
282
+ const view = this.view();
283
+ if (!this.running || view === null) {
284
+ return;
285
+ }
286
+ try {
287
+ // The ancestry first: a view popped before its first measurement answers still knows its screen.
288
+ this.ancestry ??= ancestryOfInstance(view);
289
+ this.surface ??= surfaceOfInstance(view);
290
+ const above = this.ancestry;
291
+ if (this.modal === undefined) {
292
+ this.watchModal(above);
293
+ this.joinStacks(above);
294
+ }
295
+ if (isHidden(above)) {
296
+ // Not drawn while hidden (seen nowhere: no stack change covers anything): whatever carries it in is
297
+ // looked for once it is shown, and its stacks are read, so a pop that uncovers it is seen, whoever else
298
+ // sees it.
299
+ this.seen = null;
300
+ this.noteBirths(above);
301
+ this.attempt(() => this.checkStacks(above, monotonicNow()));
302
+ this.publish(this.covering(this.hold.update(null, monotonicNow()), monotonicNow()));
303
+ this.watch([]);
304
+ this.enter('hidden');
305
+ return;
306
+ }
307
+ // Shown again: perhaps by a transition still running. (Looking again on any other
308
+ // measurement finds the same transitions: only a cost.)
309
+ // Stryker disable all -- so its mutants are equivalent
310
+ if (this.mode === 'hidden') {
311
+ this.arriving = true;
312
+ }
313
+ // Stryker restore all
314
+ // Fabric answers every measurement at once, so the view and its
315
+ // clipping ancestors are measured in the same layout. Paper answers
316
+ // later, and its ancestors then cut nothing.
317
+ view.measureInWindow((x, y, width, height) => {
318
+ if (!this.running) {
319
+ return;
320
+ }
321
+ try {
322
+ this.measured({ x, y, width, height }, above);
323
+ } catch (error) {
324
+ this.failed(error);
325
+ }
326
+ });
327
+ } catch (error) {
328
+ this.failed(error);
329
+ }
330
+ }
331
+
332
+ private measured(self: WindowRect, above: Ancestry): void {
333
+ if (![self.x, self.y, self.width, self.height].every(Number.isFinite)) {
334
+ // A failed measurement: the last rectangle stands.
335
+ // Stryker disable next-line StringLiteral -- only the error's name is logged
336
+ throw new RangeError('BugseeSecure measured a non-finite rectangle');
337
+ }
338
+ this.lastSelf = where(self);
339
+ const now = monotonicNow();
340
+ // Where native-driven transforms can draw it, which the shadow tree never sees.
341
+ const motion = nativeMotion(above);
342
+ const { drawn, visible } =
343
+ motion === null ? { drawn: self, visible: clipToAncestors(self, above) } : throughMotion(self, above, motion);
344
+ this.seen = visible;
345
+ // Read the stacks once seen: a cover for the screens moving above or below goes out with this publish.
346
+ // Warned about once a view: the same unreadable tree warns from wherever it is read first.
347
+ // Stryker disable all
348
+ try {
349
+ this.checkStacks(above, now);
350
+ } catch (error) {
351
+ this.failed(error);
352
+ }
353
+ // Stryker restore all
354
+ // Per frame while a native animation runs; otherwise woken the frame one starts.
355
+ this.animating = motion?.running ?? false;
356
+ this.watchValues(motion?.roots ?? []);
357
+ // Stryker disable next-line ConditionalExpression -- as when shown again: arriving again only costs
358
+ if (this.arriving) {
359
+ this.arrive(above, now);
360
+ }
361
+ if (this.carried !== null) {
362
+ this.carry(visible, above, now);
363
+ }
364
+ if (this.modal) {
365
+ this.watchClosing(visible, above, now);
366
+ }
367
+ this.publish(this.covering(this.hold.update(visible, now), now));
368
+ const clipped = visible === null || visible.width < drawn.width || visible.height < drawn.height;
369
+ const at = where(visible);
370
+ this.steady = at === this.lastVisible ? this.steady + 1 : 0;
371
+ this.lastVisible = at;
372
+ this.watch(clipped ? clipWatchNodes(above) : []);
373
+ this.enter(this.next(clipped));
374
+ }
375
+
376
+ /** Mounted: is a transition carrying it in? Then it is followed every frame until it settles. */
377
+ private arrive(above: Ancestry, now: number): void {
378
+ // Stryker disable next-line BooleanLiteral -- as above
379
+ this.arriving = false;
380
+ // As in `depart`: a read that throws carries nothing, and the view is still published.
381
+ this.attempt(() => {
382
+ let until = 0;
383
+ const carriers = carriersOf(above).filter((carrier) => {
384
+ const ends = carrierEntering(above, carrier, now);
385
+ until = Math.max(until, ends ?? 0);
386
+ return ends !== undefined;
387
+ });
388
+ if (carriers.length > 0) {
389
+ this.carried = { carriers, until };
390
+ // Read by its own view before and after (as it is carried in): telling it leaving changes nothing it keeps.
391
+ // Stryker disable next-line BooleanLiteral
392
+ this.tellStacks(above, carriers, until, false);
393
+ // A Modal's content is laid out again once its dialog is up: within a frame.
394
+ this.settling = true;
395
+ }
396
+ });
397
+ }
398
+
399
+ /**
400
+ * Finds the `<Modal>` the view is in, hidden or not, and watches its host's
401
+ * props, which change the commit that hides it: woken within a frame.
402
+ */
403
+ private watchModal(above: Ancestry): void {
404
+ this.modal = null;
405
+ try {
406
+ this.modal = modalOf(above);
407
+ } catch {
408
+ // A tree that cannot be read: no Modal to watch (the measurement says why, once).
409
+ }
410
+ if (this.modal) {
411
+ const host = above.path[this.modal.index] as FiberLike;
412
+ // Stryker disable next-line StringLiteral -- woken in any mode but tick or parked, it is measured that frame
413
+ this.unwatchModal = watchNode(host, () => this.enter('active'), false);
414
+ }
415
+ }
416
+
417
+ /**
418
+ * A `<Modal>` set `visible={false}` and still mounted (iOS keeps it until
419
+ * `onDismiss`) slides out with the view in it: from the commit that hides
420
+ * it, covers the band below the view for the transition hold, as an
421
+ * unmount does where the Modal is removed at once (Android).
422
+ */
423
+ private watchClosing(self: WindowRect | null, above: Ancestry, now: number): void {
424
+ const carrier = this.modal as Carrier;
425
+ const host = (above.resolved ?? above.path)[carrier.index];
426
+ const hidden = (host?.memoizedProps as { visible?: unknown } | null | undefined)?.visible === false;
427
+ if (hidden && !this.closing) {
428
+ const cover = carriedCover(above, carrier, self);
429
+ if (cover !== null) {
430
+ // A later deadline already set (a neighbour's push) is kept: the later transition still runs.
431
+ const until = Math.max(now + SECURE_TRANSITION_HOLD_MS, this.cover?.until ?? 0);
432
+ this.cover = { rect: bounding(cover, this.cover?.rect), until };
433
+ }
434
+ }
435
+ this.closing = hidden;
436
+ }
437
+
438
+ /**
439
+ * While a transition carries it in: covers where that can draw it from
440
+ * where it rests now, as well as from where it rested before (a Modal's
441
+ * content laid out again moves the band), until the transition hold ends.
442
+ */
443
+ private carry(self: WindowRect | null, above: Ancestry, now: number): void {
444
+ const { carriers, until } = this.carried as { carriers: readonly Carrier[]; until: number };
445
+ // Past it, the cover set below would be dropped as soon as it is published.
446
+ // Stryker disable next-line ConditionalExpression,BlockStatement,EqualityOperator -- so carrying on changes nothing
447
+ if (until <= now) {
448
+ this.carried = null;
449
+ return;
450
+ }
451
+ // Not laid out yet (0x0), or cut away: drawn nowhere, so nothing to cover from it.
452
+ if (self === null || self.width <= 0 || self.height <= 0) {
453
+ return;
454
+ }
455
+ let cover: WindowRect | null;
456
+ try {
457
+ cover = carriedCovers(above, carriers, self);
458
+ } catch (error) {
459
+ // Warned once, as in `measured`.
460
+ // Stryker disable next-line all
461
+ this.failed(error);
462
+ return;
463
+ }
464
+ if (cover !== null) {
465
+ // A later deadline (a neighbour's push or pop, a close) is kept: that transition still runs.
466
+ this.cover = { rect: bounding(cover, this.cover?.rect), until: Math.max(until, this.cover?.until ?? 0) };
467
+ }
468
+ }
469
+
470
+ /** Records the transitions creating its carriers, for when it is shown while they run. */
471
+ private noteBirths(above: Ancestry): void {
472
+ try {
473
+ carriersOf(above).forEach((carrier) => carrierEntering(above, carrier, monotonicNow()));
474
+ } catch {
475
+ // Unreadable: nothing recorded; the measurement says why, once.
476
+ }
477
+ }
478
+
479
+ /** Joins the stacks its screens are on, to be told when another screen on one moves. */
480
+ private joinStacks(above: Ancestry): void {
481
+ try {
482
+ for (const carrier of carriersOf(above)) {
483
+ // Only the Modal, last, has no stack: failing on it, after the screens, joins them all the same.
484
+ // Stryker disable next-line ConditionalExpression -- so its mutant is equivalent
485
+ if (carrier.stack !== undefined) {
486
+ const stack = keyOf(above.path[carrier.stack] as FiberLike);
487
+ const told = (change: StackChange): void => this.screenMoved(carrier, change);
488
+ this.leaveStacks.push(joinStack(stack, told));
489
+ // A commit that pushes or pops a screen re-renders the stack: woken within a frame.
490
+ // Measuring the stack as well only wakes it more often; any mode but tick or parked measures that frame.
491
+ // Stryker disable next-line StringLiteral,BooleanLiteral
492
+ this.leaveStacks.push(watchNode(above.path[carrier.stack] as FiberLike, () => this.enter('active'), false));
493
+ }
494
+ }
495
+ } catch {
496
+ // Unreadable: no stacks joined; the measurement says why, once.
497
+ }
498
+ }
499
+
500
+ /** Tells the stacks of the screens in `carriers` that those screens are popped (`leaving`) or pushed. */
501
+ private tellStacks(above: Ancestry, carriers: readonly Carrier[], until: number, leaving: boolean): void {
502
+ const fibers = above.resolved ?? above.path;
503
+ for (const carrier of carriers) {
504
+ if (carrier.stack !== undefined) {
505
+ const screen = fibers[carrier.index] as FiberLike;
506
+ const stack = keyOf(above.path[carrier.stack] as FiberLike);
507
+ const motion = stackMotionOf(screen.memoizedProps, false);
508
+ stackMoving(stack, { motion, until, moving: keyOf(screen), below: undefined }, leaving);
509
+ }
510
+ }
511
+ }
512
+
513
+ /**
514
+ * Reads the stacks its screens are on: a screen pushed onto, or popped
515
+ * off, one (with or without a `<BugseeSecure>` of its own) since any view
516
+ * last read it is recorded for it. Seen on screen, it covers every change
517
+ * still in its hold that moves its own screen, uncovered or covered, from
518
+ * where it is now: also one made before it mounted, or while it was hidden.
519
+ */
520
+ private checkStacks(above: Ancestry, now: number): void {
521
+ const fibers = above.resolved ?? above.path;
522
+ for (const carrier of carriersOf(above)) {
523
+ if (carrier.stack === undefined) {
524
+ continue;
525
+ }
526
+ const stack = fibers[carrier.stack] as FiberLike;
527
+ const screens = screensOn(stack);
528
+ this.stackScreens.set(carrier.stack, screens);
529
+ observeStack(stack, screens, now).forEach((change) => this.screenMoved(carrier, change));
530
+ }
531
+ }
532
+
533
+ /**
534
+ * Another screen on a stack its screen is on is pushed or popped: its own
535
+ * screen, uncovered or covered, moves too, as `change.motion` until
536
+ * `change.until`. Covered from where it is seen now, joined with where it
537
+ * was: every measurement in the hold follows it.
538
+ */
539
+ private screenMoved(carrier: Carrier, change: StackChange): void {
540
+ const above = this.ancestry as Ancestry;
541
+ const screen = above.path[carrier.index] as FiberLike;
542
+ const key = keyOf(screen);
543
+ // A stopped view has left its stacks; a view on the moving screen is carried, over as much (each motion
544
+ // covers the screen moving at least as much as the one below).
545
+ // Stryker disable next-line ConditionalExpression,LogicalOperator,BlockStatement -- so these tests only spare work
546
+ if (!this.running || change.moving === key) {
547
+ return;
548
+ }
549
+ // Seen nowhere, nothing to cover; a change that uncovers or covers another screen does not move its own.
550
+ if (this.seen == null || (change.below !== undefined && change.below !== key)) {
551
+ return;
552
+ }
553
+ // Seen on screen, so covered somewhere.
554
+ const cover = screenCover(change.motion, screenRect(screen), this.seen, false) as WindowRect;
555
+ // Whatever cover is still running is joined, not replaced; one run out is dropped first.
556
+ // A run-out cover is dropped on the next publish anyway.
557
+ // Stryker disable next-line all -- so these are equivalent
558
+ this.covering([], monotonicNow());
559
+ const kept = this.cover;
560
+ this.cover = { rect: bounding(cover, kept?.rect), until: Math.max(change.until, kept?.until ?? 0) };
561
+ this.republish();
562
+ }
563
+
564
+ /**
565
+ * Watches `nodes` (the values its transforms come from): measured at once
566
+ * when JS moves one (where that is followed), and, for a native one, woken
567
+ * the frame its fields show a change native made (an animation ending).
568
+ */
569
+ private watchValues(nodes: readonly object[]): void {
570
+ const natives = nodes.map((node) => (node as { __isNative?: unknown }).__isNative !== false);
571
+ // Watching the same values again takes their state now as the baseline, as the frame just did: only work. A
572
+ // value made native since is polled from then on; JS moving it is followed, so that only adds a safety net.
573
+ // Stryker disable next-line ArrowFunction -- as above
574
+ const same = (node: object, index: number): boolean =>
575
+ // Stryker disable next-line ConditionalExpression,LogicalOperator,EqualityOperator -- as above
576
+ node === this.values[index] && natives[index] === this.natives[index];
577
+ // Stryker disable next-line ConditionalExpression,MethodExpression,EqualityOperator,BlockStatement -- as above
578
+ if (nodes.length === this.values.length && nodes.every(same)) {
579
+ return;
580
+ }
581
+ this.unwatchValues.forEach((stop) => stop());
582
+ this.values = [...nodes];
583
+ this.natives = natives;
584
+ // Stryker disable next-line StringLiteral -- woken in any mode but tick or parked, it is measured that frame
585
+ const wake = (): void => this.enter('active');
586
+ // Measured now: it goes active if it finds an animation running.
587
+ const now = (): void => this.measure();
588
+ this.unwatchValues = this.values.flatMap((node, index) => {
589
+ const told = whenMoved(node, now);
590
+ // Driven from JS, it keeps no frame loop where JS moving it is followed.
591
+ return told === undefined ? [watchValue(node, wake)] : natives[index] ? [told, watchValue(node, wake)] : [told];
592
+ });
593
+ }
594
+
595
+ private next(clipped: boolean): Mode {
596
+ if (this.mode === 'active') {
597
+ if (this.steady < STEADY_FRAMES || this.animating || this.carried !== null) {
598
+ return 'active';
599
+ }
600
+ this.settling = false;
601
+ return clipped ? 'parked' : 'tick';
602
+ }
603
+ // Carried in is also settling: per frame.
604
+ if (this.mode === 'hidden' || this.settling || this.animating) {
605
+ return 'active';
606
+ }
607
+ if (!clipped) {
608
+ return 'tick';
609
+ }
610
+ return this.mode === 'parked' && this.steady > 0 ? 'parked' : 'active';
611
+ }
612
+
613
+ private onTick(): void {
614
+ if (this.mode === 'tick') {
615
+ this.measure();
616
+ } else if (this.mode === 'parked' && this.changing()) {
617
+ this.republish();
618
+ }
619
+ }
620
+
621
+ /** Whether what is published will change on its own: something held, or a cover, runs out. */
622
+ private changing(): boolean {
623
+ return this.hold.holding() || this.cover !== null;
624
+ }
625
+
626
+ private republish(): void {
627
+ const now = monotonicNow();
628
+ this.publish(this.covering(this.hold.publishable(now), now));
629
+ }
630
+
631
+ private onFrame(): void {
632
+ if (this.mode === 'active') {
633
+ this.measure();
634
+ return;
635
+ }
636
+ const hides = screensHide(this.ancestry as Ancestry);
637
+ if (this.mode === 'parked') {
638
+ // A screen that goes inactive moves nothing a watch would see.
639
+ if (hides) {
640
+ this.measure();
641
+ }
642
+ return;
643
+ }
644
+ // Hidden: once its screens stop hiding it, measure (which checks fully).
645
+ if (!hides) {
646
+ this.measure();
647
+ } else if (this.changing()) {
648
+ this.republish();
649
+ }
650
+ }
651
+
652
+ /** The tick's turn for a parked view: the view alone; anything moved, measure it all. */
653
+ private checkParked(): void {
654
+ // Parked only while mounted, so the view is there.
655
+ const view = this.view() as { measureInWindow: MeasureInWindow };
656
+ view.measureInWindow((x, y, width, height) => {
657
+ if (this.running && where({ x, y, width, height }) !== this.lastSelf) {
658
+ this.measure();
659
+ }
660
+ });
661
+ }
662
+
663
+ private enter(mode: Mode): void {
664
+ if (mode === this.mode) {
665
+ return;
666
+ }
667
+ // Parked too, for its screens alone: once per screen a frame, or nothing.
668
+ const perFrame = mode !== 'tick';
669
+ if (!perFrame) {
670
+ // Every mode but tick is on frames, so leaving one for tick has this.
671
+ (this.removeFrame as () => void)();
672
+ this.removeFrame = undefined;
673
+ }
674
+ // Entering parked from elsewhere, nothing parked is registered to remove.
675
+ // Stryker disable next-line ConditionalExpression,StringLiteral -- so removing it anyway changes nothing
676
+ if (mode !== 'parked') {
677
+ this.removeParked?.();
678
+ this.removeParked = undefined;
679
+ }
680
+ if (perFrame) {
681
+ this.removeFrame ??= addFrameMeasurer(() => this.onFrame());
682
+ }
683
+ if (mode === 'parked') {
684
+ this.removeParked = addParked(() => this.checkParked());
685
+ }
686
+ // A fresh count in every mode: woken back to active, it must stay put again.
687
+ this.steady = 0;
688
+ this.mode = mode;
689
+ }
690
+
691
+ /** Watches `nodes` (replacing what was watched) and wakes on any of them moving. */
692
+ private watch(nodes: FiberLike[]): void {
693
+ if (nodes.length === this.watched.length && nodes.every((node, index) => node === this.watched[index])) {
694
+ return;
695
+ }
696
+ this.unwatch.forEach((stop) => stop());
697
+ this.watched = nodes;
698
+ // Any mode but tick or parked measures it the same frame and goes active.
699
+ // Stryker disable next-line StringLiteral -- so another mode name changes nothing
700
+ this.unwatch = nodes.map((node) => watchNode(node, () => this.enter('active')));
701
+ }
702
+
703
+ private publish(rectangles: WindowRect[]): void {
704
+ // Set by the measure that got here.
705
+ setOwnerRectangles(this.token, 0, rectangles, this.surface as number);
706
+ }
707
+
708
+ /** Runs `run`; what it throws is warned about, once a view, and stops nothing else. */
709
+ private attempt(run: () => void): void {
710
+ try {
711
+ run();
712
+ } catch (error) {
713
+ this.failed(error);
714
+ }
715
+ }
716
+
717
+ private failed(error: unknown): void {
718
+ if (!this.warned) {
719
+ this.warned = true;
720
+ console.warn('[Bugsee] BugseeSecure could not measure', errorName(error));
721
+ }
722
+ }
723
+ }