@adminide-stack/yantra-mobile 12.0.172 → 12.0.174-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (213) hide show
  1. package/lib/compute.js +54 -1
  2. package/lib/compute.js.map +1 -1
  3. package/lib/features/apps/AppsCatalog.js +10 -0
  4. package/lib/features/apps/AppsCatalog.js.map +1 -1
  5. package/lib/features/apps/mobileAppCatalog.js +8 -3
  6. package/lib/features/apps/mobileAppCatalog.js.map +1 -1
  7. package/lib/features/apps/nativeAppHandoff.js +4 -1
  8. package/lib/features/apps/nativeAppHandoff.js.map +1 -1
  9. package/lib/features/apps/nativeSurfaceTwin.js +2 -1
  10. package/lib/features/apps/nativeSurfaceTwin.js.map +1 -1
  11. package/lib/features/channels/ChannelIcon.js +13 -3
  12. package/lib/features/channels/ChannelIcon.js.map +1 -1
  13. package/lib/features/channels/ConnectAppsSheet.js +5 -5
  14. package/lib/features/channels/ConnectAppsSheet.js.map +1 -1
  15. package/lib/features/channels/HomeImessage.js +5 -3
  16. package/lib/features/channels/HomeImessage.js.map +1 -1
  17. package/lib/features/channels/channelLinks.js +13 -1
  18. package/lib/features/channels/channelLinks.js.map +1 -1
  19. package/lib/features/chat/NotionPageWidgetCard.js +98 -0
  20. package/lib/features/chat/NotionPageWidgetCard.js.map +1 -0
  21. package/lib/features/chat/hostTranscriptProtocol.js +5 -1
  22. package/lib/features/chat/hostTranscriptProtocol.js.map +1 -1
  23. package/lib/features/chat/notionPageWidget.js +34 -0
  24. package/lib/features/chat/notionPageWidget.js.map +1 -0
  25. package/lib/features/computer/ComputerAgentChatPane.js +45 -0
  26. package/lib/features/computer/ComputerAgentChatPane.js.map +1 -0
  27. package/lib/features/computer/ComputerDesktop.js +164 -0
  28. package/lib/features/computer/ComputerDesktop.js.map +1 -0
  29. package/lib/features/computer/ComputerExperience.js +79 -0
  30. package/lib/features/computer/ComputerExperience.js.map +1 -0
  31. package/lib/features/computer/ComputerHandoff.js +142 -0
  32. package/lib/features/computer/ComputerHandoff.js.map +1 -0
  33. package/lib/features/computer/FilesPane.js +179 -0
  34. package/lib/features/computer/FilesPane.js.map +1 -0
  35. package/lib/features/computer/LivePage.js +1093 -0
  36. package/lib/features/computer/LivePage.js.map +1 -0
  37. package/lib/features/computer/TerminalPane.js +139 -0
  38. package/lib/features/computer/TerminalPane.js.map +1 -0
  39. package/lib/features/computer/computerApi.js +819 -0
  40. package/lib/features/computer/computerApi.js.map +1 -0
  41. package/lib/features/computer/computerChat.js +42 -0
  42. package/lib/features/computer/computerChat.js.map +1 -0
  43. package/lib/features/computer/computerControls.js +227 -0
  44. package/lib/features/computer/computerControls.js.map +1 -0
  45. package/lib/features/computer/computerStyles.js +384 -0
  46. package/lib/features/computer/computerStyles.js.map +1 -0
  47. package/lib/features/computer/computerTheme.js +133 -0
  48. package/lib/features/computer/computerTheme.js.map +1 -0
  49. package/lib/features/computer/handoff.js +73 -0
  50. package/lib/features/computer/handoff.js.map +1 -0
  51. package/lib/features/computer/inputLane.js +171 -0
  52. package/lib/features/computer/inputLane.js.map +1 -0
  53. package/lib/features/computer/inputPump.js +77 -0
  54. package/lib/features/computer/inputPump.js.map +1 -0
  55. package/lib/features/computer/inputSocket.js +148 -0
  56. package/lib/features/computer/inputSocket.js.map +1 -0
  57. package/lib/features/computer/keyboardBridge.js +176 -0
  58. package/lib/features/computer/keyboardBridge.js.map +1 -0
  59. package/lib/features/computer/pageCoordinates.js +19 -0
  60. package/lib/features/computer/pageCoordinates.js.map +1 -0
  61. package/lib/features/computer/pageZoom.js +12 -0
  62. package/lib/features/computer/pageZoom.js.map +1 -0
  63. package/lib/features/computer/pictureGeometry.js +68 -0
  64. package/lib/features/computer/pictureGeometry.js.map +1 -0
  65. package/lib/features/computer/tabsState.js +7 -0
  66. package/lib/features/computer/tabsState.js.map +1 -0
  67. package/lib/features/computer/useComputerHooks.js +146 -0
  68. package/lib/features/computer/useComputerHooks.js.map +1 -0
  69. package/lib/features/games/cubeforge3D.js +11 -6
  70. package/lib/features/games/cubeforge3D.js.map +1 -1
  71. package/lib/features/games/vendored/core/cubeforge/items.js +2 -8
  72. package/lib/features/games/vendored/core/cubeforge/items.js.map +1 -1
  73. package/lib/features/games/vendored/core/cubeforge/recipes.js +1 -4
  74. package/lib/features/games/vendored/core/cubeforge/recipes.js.map +1 -1
  75. package/lib/features/games/vendored/core/cubeforge/skin.js +83 -0
  76. package/lib/features/games/vendored/core/cubeforge/skin.js.map +1 -0
  77. package/lib/features/games/vendored/core/cubeforge/worldgen.js +2 -38
  78. package/lib/features/games/vendored/core/cubeforge/worldgen.js.map +1 -1
  79. package/lib/features/games/vendored/core/engine/palette.js +2 -9
  80. package/lib/features/games/vendored/core/engine/palette.js.map +1 -1
  81. package/lib/features/games/vendored/core/lessons/lessons.js +2 -96
  82. package/lib/features/games/vendored/core/lessons/lessons.js.map +1 -1
  83. package/lib/features/games/vendored/ui/GamesRoot.js +87 -144
  84. package/lib/features/games/vendored/ui/GamesRoot.js.map +1 -1
  85. package/lib/features/games/vendored/ui/components/primitives.js +2 -50
  86. package/lib/features/games/vendored/ui/components/primitives.js.map +1 -1
  87. package/lib/features/games/vendored/ui/screens/Cubeforge3DHomeScreen.js +20 -3
  88. package/lib/features/games/vendored/ui/screens/Cubeforge3DHomeScreen.js.map +1 -1
  89. package/lib/features/games/vendored/ui/screens/SkinEditorScreen.js +169 -0
  90. package/lib/features/games/vendored/ui/screens/SkinEditorScreen.js.map +1 -0
  91. package/lib/features/games/vendored/ui/theme.js +1 -3
  92. package/lib/features/games/vendored/ui/theme.js.map +1 -1
  93. package/lib/features/links/openInApp.js +10 -1
  94. package/lib/features/links/openInApp.js.map +1 -1
  95. package/lib/features/notion/notionEditorModel.js +3 -1
  96. package/lib/features/notion/notionEditorModel.js.map +1 -1
  97. package/lib/features/webbuilder/WebBuilderExperience.js +180 -44
  98. package/lib/features/webbuilder/WebBuilderExperience.js.map +1 -1
  99. package/lib/features/webbuilder/buildFragments.js +16 -3
  100. package/lib/features/webbuilder/buildFragments.js.map +1 -1
  101. package/lib/features/webbuilder/codezenHandoff.js +29 -1
  102. package/lib/features/webbuilder/codezenHandoff.js.map +1 -1
  103. package/lib/features/webbuilder/components/CodeView.js +69 -23
  104. package/lib/features/webbuilder/components/CodeView.js.map +1 -1
  105. package/lib/features/webbuilder/components/PreviewFrame.js +62 -2
  106. package/lib/features/webbuilder/components/PreviewFrame.js.map +1 -1
  107. package/lib/features/webbuilder/components/PreviewScreen.js +37 -2
  108. package/lib/features/webbuilder/components/PreviewScreen.js.map +1 -1
  109. package/lib/features/webbuilder/components/ProjectChat.js +2 -1
  110. package/lib/features/webbuilder/components/ProjectChat.js.map +1 -1
  111. package/lib/features/webbuilder/components/ProjectSheets.js +147 -57
  112. package/lib/features/webbuilder/components/ProjectSheets.js.map +1 -1
  113. package/lib/features/webbuilder/components/PublishSheet.js +106 -2
  114. package/lib/features/webbuilder/components/PublishSheet.js.map +1 -1
  115. package/lib/features/webbuilder/components/ReferenceModeChoice.js +105 -0
  116. package/lib/features/webbuilder/components/ReferenceModeChoice.js.map +1 -0
  117. package/lib/features/webbuilder/components/RetentionBanner.js +17 -6
  118. package/lib/features/webbuilder/components/RetentionBanner.js.map +1 -1
  119. package/lib/features/webbuilder/components/SiteUploadSheet.js +327 -0
  120. package/lib/features/webbuilder/components/SiteUploadSheet.js.map +1 -0
  121. package/lib/features/webbuilder/components/StreamStallNote.js +38 -0
  122. package/lib/features/webbuilder/components/StreamStallNote.js.map +1 -0
  123. package/lib/features/webbuilder/components/StudioHome.js +18 -8
  124. package/lib/features/webbuilder/components/StudioHome.js.map +1 -1
  125. package/lib/features/webbuilder/previewRoutes.js +30 -1
  126. package/lib/features/webbuilder/previewRoutes.js.map +1 -1
  127. package/lib/features/webbuilder/studioCatalog.js +9 -2
  128. package/lib/features/webbuilder/studioCatalog.js.map +1 -1
  129. package/lib/features/webbuilder/web/chat/referenceMode.js +11 -0
  130. package/lib/features/webbuilder/web/chat/referenceMode.js.map +1 -0
  131. package/lib/features/webbuilder/web/chat/siteCopy.js +5 -2
  132. package/lib/features/webbuilder/web/chat/siteCopy.js.map +1 -1
  133. package/lib/features/webbuilder/web/chat/streamStall.js +6 -0
  134. package/lib/features/webbuilder/web/chat/streamStall.js.map +1 -0
  135. package/lib/features/webbuilder/web/code/savedCode.js +7 -0
  136. package/lib/features/webbuilder/web/code/savedCode.js.map +1 -0
  137. package/lib/features/webbuilder/web/design/directions.js.map +1 -1
  138. package/lib/features/webbuilder/web/history/versions.js.map +1 -1
  139. package/lib/features/webbuilder/web/import/websiteImport.js +27 -0
  140. package/lib/features/webbuilder/web/import/websiteImport.js.map +1 -0
  141. package/lib/features/webbuilder/web/preview/setupPhase.js +31 -0
  142. package/lib/features/webbuilder/web/preview/setupPhase.js.map +1 -0
  143. package/lib/features/webbuilder/web/publish/siteInsights.js +23 -1
  144. package/lib/features/webbuilder/web/publish/siteInsights.js.map +1 -1
  145. package/lib/features/webbuilder/web/upload/sitePhotos.js +102 -0
  146. package/lib/features/webbuilder/web/upload/sitePhotos.js.map +1 -0
  147. package/lib/routes.json +54 -0
  148. package/lib/screens/ComputerNative/index.js +124 -0
  149. package/lib/screens/ComputerNative/index.js.map +1 -0
  150. package/lib/screens/ComputerNative/useComputerHostChat.js +83 -0
  151. package/lib/screens/ComputerNative/useComputerHostChat.js.map +1 -0
  152. package/lib/screens/GamesNative/index.js +1 -1
  153. package/lib/screens/Home/components/homeCatalog.js +4 -3
  154. package/lib/screens/Home/components/homeCatalog.js.map +1 -1
  155. package/lib/screens/WebBuilder/nativeWebBuilderRedirect.js +6 -2
  156. package/lib/screens/WebBuilder/nativeWebBuilderRedirect.js.map +1 -1
  157. package/lib/screens/WebBuilderNative/index.js +15 -3
  158. package/lib/screens/WebBuilderNative/index.js.map +1 -1
  159. package/lib/screens/WebBuilderNative/useWebBuilderHost.js +18 -3
  160. package/lib/screens/WebBuilderNative/useWebBuilderHost.js.map +1 -1
  161. package/lib/screens/WebBuilderNative/webbuilderTransport.js +16 -7
  162. package/lib/screens/WebBuilderNative/webbuilderTransport.js.map +1 -1
  163. package/package.json +4 -4
  164. package/lib/features/games/vendored/core/classroom/permissions.js +0 -76
  165. package/lib/features/games/vendored/core/classroom/permissions.js.map +0 -1
  166. package/lib/features/games/vendored/core/classroom/resourceLink.js +0 -101
  167. package/lib/features/games/vendored/core/classroom/resourceLink.js.map +0 -1
  168. package/lib/features/games/vendored/core/classroom/rules.js +0 -83
  169. package/lib/features/games/vendored/core/classroom/rules.js.map +0 -1
  170. package/lib/features/games/vendored/core/classroom/worldSettings.js +0 -49
  171. package/lib/features/games/vendored/core/classroom/worldSettings.js.map +0 -1
  172. package/lib/features/games/vendored/core/cubeforge/cycle.js +0 -15
  173. package/lib/features/games/vendored/core/cubeforge/cycle.js.map +0 -1
  174. package/lib/features/games/vendored/core/cubeforge/inventory.js +0 -75
  175. package/lib/features/games/vendored/core/cubeforge/inventory.js.map +0 -1
  176. package/lib/features/games/vendored/core/cubeforge/save.js +0 -92
  177. package/lib/features/games/vendored/core/cubeforge/save.js.map +0 -1
  178. package/lib/features/games/vendored/core/cubeforge/session.js +0 -154
  179. package/lib/features/games/vendored/core/cubeforge/session.js.map +0 -1
  180. package/lib/features/games/vendored/core/engine/iso.js +0 -41
  181. package/lib/features/games/vendored/core/engine/iso.js.map +0 -1
  182. package/lib/features/games/vendored/core/engine/world.js +0 -148
  183. package/lib/features/games/vendored/core/engine/world.js.map +0 -1
  184. package/lib/features/games/vendored/core/games/catalog.js +0 -34
  185. package/lib/features/games/vendored/core/games/catalog.js.map +0 -1
  186. package/lib/features/games/vendored/core/logging/events.js +0 -24
  187. package/lib/features/games/vendored/core/logging/events.js.map +0 -1
  188. package/lib/features/games/vendored/core/logging/logger.js +0 -54
  189. package/lib/features/games/vendored/core/logging/logger.js.map +0 -1
  190. package/lib/features/games/vendored/core/session/gameSession.js +0 -317
  191. package/lib/features/games/vendored/core/session/gameSession.js.map +0 -1
  192. package/lib/features/games/vendored/core/storage/worldRepository.js +0 -192
  193. package/lib/features/games/vendored/core/storage/worldRepository.js.map +0 -1
  194. package/lib/features/games/vendored/core/store/reactive.js +0 -78
  195. package/lib/features/games/vendored/core/store/reactive.js.map +0 -1
  196. package/lib/features/games/vendored/ui/components/BlockPalette.js +0 -64
  197. package/lib/features/games/vendored/ui/components/BlockPalette.js.map +0 -1
  198. package/lib/features/games/vendored/ui/components/IsoCanvas.js +0 -124
  199. package/lib/features/games/vendored/ui/components/IsoCanvas.js.map +0 -1
  200. package/lib/features/games/vendored/ui/hooks/useReactiveQuery.js +0 -3
  201. package/lib/features/games/vendored/ui/hooks/useReactiveQuery.js.map +0 -1
  202. package/lib/features/games/vendored/ui/screens/ActivityScreen.js +0 -68
  203. package/lib/features/games/vendored/ui/screens/ActivityScreen.js.map +0 -1
  204. package/lib/features/games/vendored/ui/screens/BuilderScreen.js +0 -227
  205. package/lib/features/games/vendored/ui/screens/BuilderScreen.js.map +0 -1
  206. package/lib/features/games/vendored/ui/screens/ClassroomScreen.js +0 -95
  207. package/lib/features/games/vendored/ui/screens/ClassroomScreen.js.map +0 -1
  208. package/lib/features/games/vendored/ui/screens/CubeforgeScreen.js +0 -342
  209. package/lib/features/games/vendored/ui/screens/CubeforgeScreen.js.map +0 -1
  210. package/lib/features/games/vendored/ui/screens/HubScreen.js +0 -131
  211. package/lib/features/games/vendored/ui/screens/HubScreen.js.map +0 -1
  212. package/lib/features/games/vendored/ui/screens/WorldListScreen.js +0 -134
  213. package/lib/features/games/vendored/ui/screens/WorldListScreen.js.map +0 -1
@@ -0,0 +1,1093 @@
1
+ import {jsxs,jsx}from'react/jsx-runtime';import {useState,useEffect,useRef,useCallback,useMemo,useLayoutEffect}from'react';import {StyleSheet,Animated,Dimensions,Keyboard,View,TextInput,Pressable,ActivityIndicator,Text,Image}from'react-native';import {MaterialCommunityIcons}from'@expo/vector-icons';import {isTabGone,subscribeTabsGone,TabGoneError,liveFrame,screenshot,goBack,goForward,navigate,readPageFields,sendInput,sendLiveInput,dropToOneWindow,markTabGone,dropLive,openLive,liveInputIsFast,focusTab,TAB_GONE_MESSAGE,liveRenewAt,livePageFields}from'./computerApi.js';import {useComputerColors,useThemedStyles,MONO_FONT}from'./computerTheme.js';import {InputLane}from'./inputLane.js';import {createInputPump}from'./inputPump.js';import {inputConfigFor,hitEditable,eventsForEdit,eventForKey}from'./keyboardBridge.js';import {frameSize,pageCoordinates}from'./pageCoordinates.js';import {pictureSize,clampOffset,keepCentre,centredOffset,liftForField,middleOf}from'./pictureGeometry.js';import {useWindowsAvailable,useAppVisible}from'./useComputerHooks.js';var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ const POLL_MS = 5e3;
21
+ const CONTROLLING_POLL_MS = 700;
22
+ const STREAMING_POLL_MS = 3e4;
23
+ const LIVE_FRAME_GAP_MS = 80;
24
+ const LIVE_FRAME_GAP_WATCHING_MS = 350;
25
+ const LIVE_FRAME_FAILURES = 3;
26
+ const HOLD_REPORT_MS = 150;
27
+ const HOLD_MAX_MS = 1e4;
28
+ const AFTER_INPUT_CAPTURE_MS = 250;
29
+ const AFTER_NAV_CAPTURE_MS = 400;
30
+ const PING_MS = 700;
31
+ const TOUCH_PRESS_MS = 180;
32
+ const TOUCH_SLOP_PX = 8;
33
+ const TWO_FINGER_GRACE_MS = 80;
34
+ const LOOK_AROUND_HINT_MS = 3500;
35
+ const FIELDS_POLL_MS = 2e3;
36
+ const KEYBOARD_MARGIN_PX = 16;
37
+ function ToolButton({
38
+ icon,
39
+ label,
40
+ onPress
41
+ }) {
42
+ const C = useComputerColors();
43
+ const styles = useThemedStyles(makeStyles);
44
+ return /* @__PURE__ */ jsx(Pressable, { onPress, accessibilityRole: "button", accessibilityLabel: label, hitSlop: 6, style: ({
45
+ pressed
46
+ }) => [styles.toolButton, pressed && styles.pressed], children: /* @__PURE__ */ jsx(MaterialCommunityIcons, { name: icon, size: 18, color: C.muted }) });
47
+ }
48
+ function LivePage({
49
+ workspaceId,
50
+ tab: requestedTab,
51
+ controlling,
52
+ zoom = "fill",
53
+ fit = "width",
54
+ onTakeControl,
55
+ onLiveChange,
56
+ onLaneChange,
57
+ onFrame,
58
+ chrome = false,
59
+ autoFocusAddress = false,
60
+ keyboardRef,
61
+ onKeyboardChange
62
+ }) {
63
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
64
+ const C = useComputerColors();
65
+ const styles = useThemedStyles(makeStyles);
66
+ const contain = fit === "contain";
67
+ const windows = useWindowsAvailable(workspaceId);
68
+ const tab = windows ? requestedTab : void 0;
69
+ const [goneTab, setGoneTab] = useState(null);
70
+ useEffect(() => {
71
+ if (!tab) return;
72
+ if (isTabGone(workspaceId, tab)) setGoneTab(tab);
73
+ return subscribeTabsGone((changed, closed) => {
74
+ if (changed === workspaceId && closed === tab) setGoneTab(closed);
75
+ });
76
+ }, [workspaceId, tab]);
77
+ const gone = !!tab && goneTab === tab;
78
+ const [frame, setFrame] = useState(null);
79
+ const [updatedAt, setUpdatedAt] = useState(null);
80
+ const [draft, setDraft] = useState(null);
81
+ const [busy, setBusy] = useState(false);
82
+ const [problem, setProblem] = useState(null);
83
+ const [live, setLive] = useState(null);
84
+ const [framesDead, setFramesDead] = useState(false);
85
+ const liveRef = useRef(null);
86
+ liveRef.current = live;
87
+ const laneWhy = useRef(null);
88
+ useEffect(() => onLiveChange == null ? void 0 : onLiveChange(live), [live, onLiveChange]);
89
+ const onFrameRef = useRef(onFrame);
90
+ onFrameRef.current = onFrame;
91
+ const inFlight = useRef(false);
92
+ const forgiveStream = useCallback(() => setFramesDead(false), []);
93
+ const visible = useAppVisible(forgiveStream);
94
+ const fail = useCallback((error) => {
95
+ if (error instanceof TabGoneError) return;
96
+ setProblem(error instanceof Error ? error.message : String(error));
97
+ }, []);
98
+ const frameKey = live && !framesDead && !gone ? (_a = live.screenshotUrl) != null ? _a : null : null;
99
+ const [slots, setSlots] = useState({
100
+ a: null,
101
+ b: null,
102
+ front: "a",
103
+ shown: false
104
+ });
105
+ const slotsRef = useRef(slots);
106
+ slotsRef.current = slots;
107
+ const loading = useRef(null);
108
+ const fetching = useRef(false);
109
+ const [liveInfo, setLiveInfo] = useState(null);
110
+ const pageUrl = ((_b = liveInfo == null ? void 0 : liveInfo.pageUrl) != null ? _b : frame == null ? void 0 : frame.pageUrl) || "";
111
+ const pageTitle = (liveInfo == null ? void 0 : liveInfo.title) || (frame == null ? void 0 : frame.title) || "";
112
+ const address = draft != null ? draft : pageUrl === "about:blank" ? "" : pageUrl;
113
+ const stamp = useRef(0);
114
+ const failures = useRef(0);
115
+ const frameGeneration = useRef(0);
116
+ const nextTimer = useRef(null);
117
+ const controllingRef = useRef(controlling);
118
+ controllingRef.current = controlling;
119
+ const failedFrameRef = useRef(() => void 0);
120
+ const askNextFrameRef = useRef(() => void 0);
121
+ const askNextFrame = useCallback((delay) => {
122
+ if (nextTimer.current) clearTimeout(nextTimer.current);
123
+ const generation = frameGeneration.current;
124
+ nextTimer.current = setTimeout(() => {
125
+ nextTimer.current = null;
126
+ const session = liveRef.current;
127
+ if (!(session == null ? void 0 : session.screenshotUrl) || generation !== frameGeneration.current) return;
128
+ if (fetching.current || loading.current) return;
129
+ fetching.current = true;
130
+ stamp.current += 1;
131
+ const asked = stamp.current;
132
+ liveFrame(session, asked).then((next) => {
133
+ var _a2, _b2;
134
+ if (generation !== frameGeneration.current) return;
135
+ const {
136
+ front
137
+ } = slotsRef.current;
138
+ const back = front === "a" ? "b" : "a";
139
+ const gap = controllingRef.current ? LIVE_FRAME_GAP_MS : LIVE_FRAME_GAP_WATCHING_MS;
140
+ if (slotsRef.current.shown && ((_a2 = slotsRef.current[front]) == null ? void 0 : _a2.src) === next.src) {
141
+ failures.current = 0;
142
+ askNextFrameRef.current(gap);
143
+ } else if (((_b2 = slotsRef.current[back]) == null ? void 0 : _b2.src) === next.src) {
144
+ failures.current = 0;
145
+ setSlots((was) => __spreadProps(__spreadValues({}, was), {
146
+ front: back,
147
+ shown: true
148
+ }));
149
+ askNextFrameRef.current(gap);
150
+ } else {
151
+ loading.current = {
152
+ slot: back,
153
+ stamp: asked
154
+ };
155
+ setSlots((was) => __spreadProps(__spreadValues({}, was), {
156
+ [back]: __spreadProps(__spreadValues({}, next), {
157
+ stamp: asked
158
+ })
159
+ }));
160
+ }
161
+ if (next.title !== null || next.pageUrl !== null) {
162
+ setLiveInfo((info) => info && info.title === next.title && info.pageUrl === next.pageUrl ? info : {
163
+ title: next.title,
164
+ pageUrl: next.pageUrl
165
+ });
166
+ }
167
+ }).catch((error) => {
168
+ if (generation === frameGeneration.current) failedFrameRef.current(error);
169
+ }).finally(() => {
170
+ fetching.current = false;
171
+ });
172
+ }, delay);
173
+ }, []);
174
+ askNextFrameRef.current = askNextFrame;
175
+ useEffect(() => {
176
+ failures.current = 0;
177
+ frameGeneration.current += 1;
178
+ loading.current = null;
179
+ fetching.current = false;
180
+ if (!frameKey) {
181
+ setSlots({
182
+ a: null,
183
+ b: null,
184
+ front: "a",
185
+ shown: false
186
+ });
187
+ return void 0;
188
+ }
189
+ askNextFrame(0);
190
+ return () => {
191
+ frameGeneration.current += 1;
192
+ if (nextTimer.current) clearTimeout(nextTimer.current);
193
+ nextTimer.current = null;
194
+ };
195
+ }, [frameKey, askNextFrame]);
196
+ const [liveShape, setLiveShape] = useState(null);
197
+ const [snapShape, setSnapShape] = useState(null);
198
+ const noteShape = useCallback((kind, width, height) => {
199
+ if (!width || !height || !(width > 0) || !(height > 0)) return;
200
+ const set = kind === "live" ? setLiveShape : setSnapShape;
201
+ set((was) => was && was.width === width && was.height === height ? was : {
202
+ width,
203
+ height
204
+ });
205
+ }, []);
206
+ const onSlotLoad = useCallback((slot, frameStamp, width, height) => {
207
+ const waited = loading.current;
208
+ if (!waited || waited.slot !== slot || waited.stamp !== frameStamp) return;
209
+ loading.current = null;
210
+ failures.current = 0;
211
+ noteShape("live", width, height);
212
+ setSlots((was) => __spreadProps(__spreadValues({}, was), {
213
+ front: slot,
214
+ shown: true
215
+ }));
216
+ askNextFrame(controllingRef.current ? LIVE_FRAME_GAP_MS : LIVE_FRAME_GAP_WATCHING_MS);
217
+ }, [askNextFrame, noteShape]);
218
+ failedFrameRef.current = (error) => {
219
+ if (error instanceof TabGoneError) return;
220
+ failures.current += 1;
221
+ if (failures.current < LIVE_FRAME_FAILURES) {
222
+ askNextFrame(500 * failures.current);
223
+ return;
224
+ }
225
+ console.warn("[computer] live frames are not coming; showing snapshots, input stays live", error);
226
+ setFramesDead(true);
227
+ };
228
+ const onSlotError = useCallback((slot, frameStamp) => {
229
+ const waited = loading.current;
230
+ if (!waited || waited.slot !== slot || waited.stamp !== frameStamp) return;
231
+ loading.current = null;
232
+ failedFrameRef.current(new Error("a live frame would not decode"));
233
+ }, []);
234
+ const streaming = !!frameKey && slots.shown;
235
+ const capture = useCallback(async () => {
236
+ var _a2;
237
+ if (inFlight.current) return;
238
+ inFlight.current = true;
239
+ try {
240
+ const shot = await screenshot(workspaceId, tab);
241
+ setFrame((previous) => shot.src ? shot : previous != null ? previous : shot);
242
+ if (shot.src) {
243
+ setUpdatedAt(Date.now());
244
+ setProblem(null);
245
+ (_a2 = onFrameRef.current) == null ? void 0 : _a2.call(onFrameRef, shot);
246
+ } else if (shot.error) {
247
+ setProblem(shot.error);
248
+ }
249
+ } catch (error) {
250
+ fail(error);
251
+ } finally {
252
+ inFlight.current = false;
253
+ }
254
+ }, [workspaceId, tab, fail]);
255
+ const captureRef = useRef(capture);
256
+ captureRef.current = capture;
257
+ useEffect(() => {
258
+ if (gone || !visible) return;
259
+ void capture();
260
+ let every = controlling ? CONTROLLING_POLL_MS : POLL_MS;
261
+ if (frameKey) every = STREAMING_POLL_MS;
262
+ const timer = setInterval(() => {
263
+ void capture();
264
+ }, every);
265
+ return () => clearInterval(timer);
266
+ }, [capture, controlling, frameKey, gone, visible]);
267
+ useEffect(() => {
268
+ if (!visible || gone) {
269
+ setLive(null);
270
+ return;
271
+ }
272
+ let stopped = false;
273
+ let renew = null;
274
+ const open = async () => {
275
+ try {
276
+ const session = await openLive(workspaceId, tab);
277
+ if (stopped) return;
278
+ if (!session && !laneWhy.current) {
279
+ laneWhy.current = "no-live";
280
+ console.warn("[computer] no live session (the connector has no YANTRA_COMPUTER_LIVE, or its provider no stream): showing snapshots");
281
+ } else if (session && !session.screenshotUrl && laneWhy.current !== "no-route") {
282
+ laneWhy.current = "no-route";
283
+ console.warn("[computer] the live session has no still-frame route (screenshotUrl): showing snapshots, input on the live lane");
284
+ }
285
+ setLive(session);
286
+ if (session) renew = setTimeout(() => {
287
+ void open();
288
+ }, Math.max(1e3, liveRenewAt(session) - Date.now()));
289
+ } catch (error) {
290
+ if (stopped) return;
291
+ console.warn("[computer] no live session, controlling through the exec lane", error);
292
+ setLive(null);
293
+ }
294
+ };
295
+ void open();
296
+ return () => {
297
+ stopped = true;
298
+ if (renew) clearTimeout(renew);
299
+ };
300
+ }, [visible, gone, workspaceId, tab]);
301
+ const captureSoon = useRef(null);
302
+ const scheduleCapture = useCallback((delay) => {
303
+ if (captureSoon.current) clearTimeout(captureSoon.current);
304
+ captureSoon.current = setTimeout(() => {
305
+ void captureRef.current();
306
+ }, delay);
307
+ }, []);
308
+ const history = useCallback(async (direction) => {
309
+ try {
310
+ await (direction === "back" ? goBack(workspaceId, tab) : goForward(workspaceId, tab));
311
+ scheduleCapture(AFTER_NAV_CAPTURE_MS);
312
+ } catch (error) {
313
+ fail(error);
314
+ }
315
+ }, [workspaceId, tab, scheduleCapture, fail]);
316
+ const go = useCallback(async () => {
317
+ const target = address.trim();
318
+ if (!target) return;
319
+ setBusy(true);
320
+ setProblem(null);
321
+ try {
322
+ await navigate(workspaceId, /^https?:\/\//i.test(target) ? target : `https://${target}`, tab);
323
+ setDraft(null);
324
+ await capture();
325
+ } catch (error) {
326
+ fail(error);
327
+ } finally {
328
+ setBusy(false);
329
+ }
330
+ }, [address, workspaceId, tab, capture, fail]);
331
+ const fieldsRef = useRef(null);
332
+ const noteFields = useCallback((answer) => {
333
+ const fields = readPageFields(answer);
334
+ if (fields) fieldsRef.current = fields;
335
+ }, []);
336
+ const deliverRef = useRef(async () => {
337
+ });
338
+ deliverRef.current = async (events) => {
339
+ const session = liveRef.current;
340
+ try {
341
+ if (!session) {
342
+ await sendInput(workspaceId, events, tab);
343
+ scheduleCapture(AFTER_INPUT_CAPTURE_MS);
344
+ return;
345
+ }
346
+ const used = await sendLiveInput(session, events, noteFields);
347
+ if (used !== session && liveRef.current === session) setLive(used);
348
+ } catch (error) {
349
+ fail(error);
350
+ }
351
+ };
352
+ const [pump] = useState(() => createInputPump((events) => deliverRef.current(events)));
353
+ const laneTarget = useRef({
354
+ workspaceId,
355
+ tab
356
+ });
357
+ laneTarget.current = {
358
+ workspaceId,
359
+ tab
360
+ };
361
+ const [lane] = useState(() => new InputLane({
362
+ http: (events) => {
363
+ void pump.push(events);
364
+ },
365
+ renew: async (stale) => {
366
+ dropLive(stale.workspaceId, stale);
367
+ const fresh = await openLive(laneTarget.current.workspaceId, laneTarget.current.tab);
368
+ if (fresh) setLive(fresh);
369
+ return fresh;
370
+ },
371
+ oneWindow: (id) => dropToOneWindow(id),
372
+ tabGone: (session) => {
373
+ if (session.tab) markTabGone(session.workspaceId, session.tab);
374
+ },
375
+ problem: (message) => setProblem(message),
376
+ answer: (answer) => noteFields(answer)
377
+ }));
378
+ useEffect(() => lane.setSession(gone ? null : live, controlling && !gone), [lane, live, controlling, gone]);
379
+ useEffect(() => () => lane.dispose(), [lane]);
380
+ const send = useCallback((events) => lane.push(events), [lane]);
381
+ const fastInput = useCallback(() => lane.mode() === "socket" || liveInputIsFast(liveRef.current), [lane]);
382
+ useEffect(() => {
383
+ if (!controlling || !tab || gone) return;
384
+ focusTab(workspaceId, tab).catch((error) => {
385
+ if (!(error instanceof TabGoneError)) console.warn("[computer] could not bring the tab forward", error);
386
+ });
387
+ }, [controlling, workspaceId, tab, gone]);
388
+ const statusUrl = live == null ? void 0 : live.statusUrl;
389
+ useEffect(() => {
390
+ if (!controlling || !visible || gone) return;
391
+ let stopped = false;
392
+ const read = async () => {
393
+ const fields = await livePageFields(liveRef.current);
394
+ if (!stopped && fields) fieldsRef.current = fields;
395
+ };
396
+ void read();
397
+ const timer = setInterval(() => {
398
+ void read();
399
+ }, FIELDS_POLL_MS);
400
+ return () => {
401
+ stopped = true;
402
+ clearInterval(timer);
403
+ };
404
+ }, [controlling, visible, statusUrl, gone]);
405
+ const bridgeRef = useRef(null);
406
+ const [bridgeField, setBridgeField] = useState(null);
407
+ const [keyboardUp, setKeyboardUp] = useState(false);
408
+ const bridgeConfig = useMemo(() => {
409
+ var _a2;
410
+ return inputConfigFor((_a2 = bridgeField == null ? void 0 : bridgeField.field) != null ? _a2 : null);
411
+ }, [bridgeField]);
412
+ const [bridgeText, setBridgeText] = useState("");
413
+ const bridgeTextRef = useRef("");
414
+ const focusBridge = useCallback((field) => {
415
+ bridgeTextRef.current = "";
416
+ setBridgeText("");
417
+ setBridgeField({
418
+ field,
419
+ at: Date.now()
420
+ });
421
+ }, []);
422
+ const dressedAs = useRef(null);
423
+ useEffect(() => {
424
+ if (!bridgeField || !controlling) return;
425
+ const input = bridgeRef.current;
426
+ if (!input) return;
427
+ const dress = JSON.stringify(bridgeConfig);
428
+ const same = dressedAs.current === dress;
429
+ dressedAs.current = dress;
430
+ if (input.isFocused()) {
431
+ if (same) return;
432
+ input.blur();
433
+ }
434
+ const frameId = requestAnimationFrame(() => {
435
+ var _a2;
436
+ return (_a2 = bridgeRef.current) == null ? void 0 : _a2.focus();
437
+ });
438
+ return () => cancelAnimationFrame(frameId);
439
+ }, [bridgeField, bridgeConfig, controlling]);
440
+ const blurBridge = useCallback(() => {
441
+ var _a2;
442
+ setBridgeField(null);
443
+ (_a2 = bridgeRef.current) == null ? void 0 : _a2.blur();
444
+ }, []);
445
+ useEffect(() => {
446
+ if (!controlling) blurBridge();
447
+ }, [controlling, blurBridge]);
448
+ const openKeyboard = useCallback(() => focusBridge(null), [focusBridge]);
449
+ useEffect(() => {
450
+ if (!keyboardRef) return;
451
+ keyboardRef.current = openKeyboard;
452
+ return () => {
453
+ if (keyboardRef.current === openKeyboard) keyboardRef.current = null;
454
+ };
455
+ }, [keyboardRef, openKeyboard]);
456
+ useEffect(() => onKeyboardChange == null ? void 0 : onKeyboardChange(keyboardUp), [keyboardUp, onKeyboardChange]);
457
+ const aimKeyboard = useCallback((point) => {
458
+ var _a2;
459
+ const field = fieldsRef.current ? hitEditable(fieldsRef.current.editables, point) : null;
460
+ if (field) focusBridge(field);
461
+ else if ((_a2 = bridgeRef.current) == null ? void 0 : _a2.isFocused()) blurBridge();
462
+ }, [focusBridge, blurBridge]);
463
+ const resetBridgeText = useCallback(() => {
464
+ bridgeTextRef.current = "";
465
+ setBridgeText("");
466
+ }, []);
467
+ const onBridgeChange = useCallback((text) => {
468
+ const events = eventsForEdit(bridgeTextRef.current, text);
469
+ bridgeTextRef.current = text;
470
+ setBridgeText(text);
471
+ if (events.length) send(events);
472
+ }, [send]);
473
+ const onBridgeKey = useCallback((event) => {
474
+ const {
475
+ key
476
+ } = event.nativeEvent;
477
+ if (key === "Backspace" && bridgeTextRef.current) return;
478
+ const named = eventForKey(key);
479
+ if (named) send([named]);
480
+ }, [send]);
481
+ const onBridgeSubmit = useCallback(() => {
482
+ send([{
483
+ type: "key",
484
+ key: "Enter"
485
+ }]);
486
+ resetBridgeText();
487
+ }, [send, resetBridgeText]);
488
+ const [box, setBox] = useState(null);
489
+ const onBoxLayout = useCallback((event) => {
490
+ const {
491
+ width,
492
+ height
493
+ } = event.nativeEvent.layout;
494
+ setBox((was) => was && was.width === width && was.height === height ? was : {
495
+ width,
496
+ height
497
+ });
498
+ }, []);
499
+ const shape = (_f = (_e = (_d = (_c = streaming ? liveShape : snapShape) != null ? _c : liveShape) != null ? _d : live == null ? void 0 : live.viewport) != null ? _e : snapShape) != null ? _f : {
500
+ width: 16,
501
+ height: 10
502
+ };
503
+ const pageShape = (_g = liveShape != null ? liveShape : live == null ? void 0 : live.viewport) != null ? _g : snapShape;
504
+ const aspect = shape.width / shape.height;
505
+ const picture = pictureSize(box, aspect, zoom, contain);
506
+ const [keyboardCover, setKeyboardCover] = useState(0);
507
+ const pan = useRef(new Animated.ValueXY({
508
+ x: 0,
509
+ y: 0
510
+ })).current;
511
+ const offset = useRef({
512
+ x: 0,
513
+ y: 0
514
+ });
515
+ const moveTo = useCallback((next) => {
516
+ if (!box || !picture) return;
517
+ const clamped = clampOffset(next, box, picture, keyboardCover);
518
+ offset.current = clamped;
519
+ pan.setValue(clamped);
520
+ }, [box, picture, keyboardCover, pan]);
521
+ const lastPicture = useRef(null);
522
+ const hasPicture = streaming || !!(frame == null ? void 0 : frame.src);
523
+ useLayoutEffect(() => {
524
+ if (!box || !picture) return;
525
+ const before = lastPicture.current;
526
+ lastPicture.current = picture;
527
+ const next = before && hasPicture ? keepCentre(offset.current, box, before, picture) : centredOffset(box, picture);
528
+ offset.current = clampOffset(next, box, picture, keyboardCover);
529
+ pan.setValue(offset.current);
530
+ }, [box == null ? void 0 : box.width, box == null ? void 0 : box.height, picture == null ? void 0 : picture.width, picture == null ? void 0 : picture.height, keyboardCover]);
531
+ const boxRef = useRef(null);
532
+ const geometry = useRef({
533
+ box,
534
+ picture,
535
+ size: null,
536
+ field: null
537
+ });
538
+ geometry.current = {
539
+ box,
540
+ picture,
541
+ size: pageShape != null ? pageShape : null,
542
+ field: (_j = (_i = bridgeField == null ? void 0 : bridgeField.field) != null ? _i : (_h = fieldsRef.current) == null ? void 0 : _h.focused) != null ? _j : null
543
+ };
544
+ const keyboardHeight = useRef(0);
545
+ const fitAboveKeyboard = useCallback(() => {
546
+ var _a2, _b2;
547
+ if (!keyboardHeight.current || !((_a2 = bridgeRef.current) == null ? void 0 : _a2.isFocused())) return;
548
+ (_b2 = boxRef.current) == null ? void 0 : _b2.measureInWindow((_x, y, _w, h) => {
549
+ const screen = Dimensions.get("window").height;
550
+ const covered = Math.max(0, y + h - (screen - keyboardHeight.current));
551
+ setKeyboardCover(covered);
552
+ const {
553
+ box: at,
554
+ picture: drawn,
555
+ size,
556
+ field
557
+ } = geometry.current;
558
+ if (!field || !at || !drawn || !size) return;
559
+ const lift = liftForField(offset.current, drawn, size, field, h - covered, KEYBOARD_MARGIN_PX);
560
+ if (!lift) return;
561
+ const next = clampOffset({
562
+ x: offset.current.x,
563
+ y: offset.current.y - lift
564
+ }, at, drawn, covered);
565
+ offset.current = next;
566
+ pan.setValue(next);
567
+ });
568
+ }, [pan]);
569
+ useEffect(() => {
570
+ const show = Keyboard.addListener("keyboardDidShow", (event) => {
571
+ keyboardHeight.current = event.endCoordinates.height;
572
+ fitAboveKeyboard();
573
+ });
574
+ const hide = Keyboard.addListener("keyboardDidHide", () => {
575
+ keyboardHeight.current = 0;
576
+ setKeyboardCover(0);
577
+ });
578
+ return () => {
579
+ show.remove();
580
+ hide.remove();
581
+ };
582
+ }, [fitAboveKeyboard]);
583
+ useEffect(() => {
584
+ if (!keyboardUp) setKeyboardCover(0);
585
+ else fitAboveKeyboard();
586
+ }, [keyboardUp, bridgeField, fitAboveKeyboard]);
587
+ const overflows = !!box && !!picture && (picture.width > box.width + 1 || picture.height > box.height + 1);
588
+ const [lookAroundHint, setLookAroundHint] = useState(false);
589
+ useEffect(() => {
590
+ if (!controlling || !overflows) return;
591
+ setLookAroundHint(true);
592
+ const timer = setTimeout(() => setLookAroundHint(false), LOOK_AROUND_HINT_MS);
593
+ return () => {
594
+ clearTimeout(timer);
595
+ setLookAroundHint(false);
596
+ };
597
+ }, [controlling, overflows]);
598
+ const [ping, setPing] = useState(null);
599
+ const pingFade = useRef(new Animated.Value(0)).current;
600
+ useEffect(() => {
601
+ if (!ping) return;
602
+ pingFade.setValue(1);
603
+ Animated.timing(pingFade, {
604
+ toValue: 0,
605
+ duration: PING_MS,
606
+ useNativeDriver: true
607
+ }).start();
608
+ const timer = setTimeout(() => setPing(null), PING_MS);
609
+ return () => clearTimeout(timer);
610
+ }, [ping, pingFade]);
611
+ const gesture = useRef(null);
612
+ const pageSize = useCallback(() => {
613
+ var _a2, _b2;
614
+ return frameSize(liveShape != null ? liveShape : {
615
+ width: 0,
616
+ height: 0
617
+ }, (_b2 = (_a2 = liveRef.current) == null ? void 0 : _a2.viewport) != null ? _b2 : snapShape);
618
+ }, [liveShape, snapShape]);
619
+ const pointAt = useCallback((locationX, locationY) => {
620
+ const size = pageSize();
621
+ if (!size || !picture) return null;
622
+ return pageCoordinates(locationX, locationY, __spreadValues({
623
+ left: 0,
624
+ top: 0
625
+ }, picture), size);
626
+ }, [pageSize, picture]);
627
+ const startPan = useCallback((touches) => {
628
+ const g = gesture.current;
629
+ if (!g) return;
630
+ const middle = middleOf(touches);
631
+ if (g.timer) clearTimeout(g.timer);
632
+ gesture.current = __spreadProps(__spreadValues({}, g), {
633
+ mode: "pan",
634
+ panFrom: {
635
+ x: middle.x,
636
+ y: middle.y,
637
+ offset: __spreadValues({}, offset.current)
638
+ },
639
+ fingers: touches.length,
640
+ timer: null
641
+ });
642
+ }, []);
643
+ const onGrant = useCallback((event) => {
644
+ const {
645
+ locationX,
646
+ locationY,
647
+ pageX,
648
+ pageY,
649
+ touches
650
+ } = event.nativeEvent;
651
+ const point = pointAt(locationX, locationY);
652
+ const g = {
653
+ mode: controlling ? "pending" : "look",
654
+ startX: pageX,
655
+ startY: pageY,
656
+ point,
657
+ last: point,
658
+ button: "left",
659
+ at: Date.now(),
660
+ timer: null,
661
+ panFrom: null,
662
+ fingers: 1
663
+ };
664
+ gesture.current = g;
665
+ if (!controlling) {
666
+ if (touches.length > 1) startPan(touches);
667
+ return;
668
+ }
669
+ if (touches.length > 1) {
670
+ startPan(touches);
671
+ return;
672
+ }
673
+ if (!point) return;
674
+ setPing({
675
+ x: locationX,
676
+ y: locationY,
677
+ at: Date.now()
678
+ });
679
+ g.timer = setTimeout(() => {
680
+ const held = gesture.current;
681
+ if (held !== g || g.mode !== "pending" || !g.point) return;
682
+ g.mode = "press";
683
+ if (fastInput()) send([__spreadProps(__spreadValues({
684
+ type: "mousedown"
685
+ }, g.point), {
686
+ button: g.button
687
+ })]);
688
+ }, TOUCH_PRESS_MS);
689
+ }, [controlling, pointAt, startPan, fastInput, send]);
690
+ const onTouchJoined = useCallback((event) => {
691
+ const g = gesture.current;
692
+ const {
693
+ touches
694
+ } = event.nativeEvent;
695
+ if (!g || touches.length < 2) return;
696
+ if (g.mode === "press") return;
697
+ if (g.mode === "pan" && g.fingers === touches.length) return;
698
+ setPing(null);
699
+ startPan(touches);
700
+ }, [startPan]);
701
+ const onMove = useCallback((event) => {
702
+ const g = gesture.current;
703
+ if (!g) return;
704
+ const {
705
+ touches,
706
+ pageX,
707
+ pageY,
708
+ locationX,
709
+ locationY
710
+ } = event.nativeEvent;
711
+ if (g.mode === "pan" && g.panFrom) {
712
+ if (touches.length && touches.length !== g.fingers) {
713
+ startPan(touches);
714
+ return;
715
+ }
716
+ const middle = middleOf(touches.length ? touches : [{
717
+ pageX,
718
+ pageY
719
+ }]);
720
+ moveTo({
721
+ x: g.panFrom.offset.x + (middle.x - g.panFrom.x),
722
+ y: g.panFrom.offset.y + (middle.y - g.panFrom.y)
723
+ });
724
+ return;
725
+ }
726
+ const travelled = Math.hypot(pageX - g.startX, pageY - g.startY);
727
+ if (g.mode === "look") {
728
+ if (travelled >= TOUCH_SLOP_PX) startPan(touches.length ? touches : [{
729
+ pageX,
730
+ pageY
731
+ }]);
732
+ return;
733
+ }
734
+ if (g.mode === "pending") {
735
+ if (travelled < TOUCH_SLOP_PX) return;
736
+ if (Date.now() - g.at < TWO_FINGER_GRACE_MS) return;
737
+ if (g.timer) clearTimeout(g.timer);
738
+ g.timer = null;
739
+ if (fastInput() && g.point) {
740
+ g.mode = "press";
741
+ send([__spreadProps(__spreadValues({
742
+ type: "mousedown"
743
+ }, g.point), {
744
+ button: g.button
745
+ })]);
746
+ } else {
747
+ startPan(touches.length ? touches : [{
748
+ pageX,
749
+ pageY
750
+ }]);
751
+ return;
752
+ }
753
+ }
754
+ if (g.mode === "press" && fastInput()) {
755
+ const point = pointAt(locationX, locationY);
756
+ if (!point) return;
757
+ g.last = point;
758
+ send([__spreadProps(__spreadValues({
759
+ type: "mousemove"
760
+ }, point), {
761
+ button: g.button
762
+ })]);
763
+ }
764
+ }, [startPan, moveTo, fastInput, send, pointAt]);
765
+ const onTouchLeft = useCallback((event) => {
766
+ const g = gesture.current;
767
+ const {
768
+ touches
769
+ } = event.nativeEvent;
770
+ if (!g || g.mode !== "pan" || !touches.length) return;
771
+ startPan(touches);
772
+ }, [startPan]);
773
+ const finish = useCallback((event, cancelled) => {
774
+ var _a2, _b2;
775
+ const g = gesture.current;
776
+ gesture.current = null;
777
+ if (!g) return;
778
+ if (g.timer) clearTimeout(g.timer);
779
+ const {
780
+ pageX,
781
+ pageY,
782
+ locationX,
783
+ locationY
784
+ } = event.nativeEvent;
785
+ if (g.mode === "look") {
786
+ if (!cancelled && Math.hypot(pageX - g.startX, pageY - g.startY) < TOUCH_SLOP_PX) onTakeControl == null ? void 0 : onTakeControl();
787
+ return;
788
+ }
789
+ if (g.mode === "pan") return;
790
+ if (g.mode === "pending") {
791
+ if (cancelled || !g.point) return;
792
+ aimKeyboard(g.point);
793
+ send([__spreadProps(__spreadValues({
794
+ type: "click"
795
+ }, g.point), {
796
+ button: g.button
797
+ })]);
798
+ return;
799
+ }
800
+ const point = (_b2 = (_a2 = pointAt(locationX, locationY)) != null ? _a2 : g.last) != null ? _b2 : g.point;
801
+ if (!point) return;
802
+ if (!cancelled) aimKeyboard(point);
803
+ if (fastInput()) {
804
+ send([__spreadProps(__spreadValues({
805
+ type: "mouseup"
806
+ }, point), {
807
+ button: g.button
808
+ })]);
809
+ return;
810
+ }
811
+ if (cancelled) return;
812
+ const held = Math.min(HOLD_MAX_MS, Date.now() - g.at);
813
+ send([held >= HOLD_REPORT_MS ? __spreadProps(__spreadValues({
814
+ type: "click"
815
+ }, point), {
816
+ button: g.button,
817
+ holdMs: held
818
+ }) : __spreadProps(__spreadValues({
819
+ type: "click"
820
+ }, point), {
821
+ button: g.button
822
+ })]);
823
+ }, [onTakeControl, aimKeyboard, send, pointAt, fastInput]);
824
+ useEffect(() => {
825
+ if (controlling) return;
826
+ const g = gesture.current;
827
+ if (g == null ? void 0 : g.timer) clearTimeout(g.timer);
828
+ if (g && g.mode !== "look") gesture.current = null;
829
+ }, [controlling]);
830
+ const addressRef = useRef(null);
831
+ useEffect(() => {
832
+ var _a2;
833
+ if (autoFocusAddress && chrome) (_a2 = addressRef.current) == null ? void 0 : _a2.focus();
834
+ }, [autoFocusAddress, chrome]);
835
+ useEffect(() => () => {
836
+ for (const timer of [captureSoon, nextTimer]) if (timer.current) clearTimeout(timer.current);
837
+ const g = gesture.current;
838
+ if (g == null ? void 0 : g.timer) clearTimeout(g.timer);
839
+ }, []);
840
+ const [, tick] = useState(0);
841
+ useEffect(() => {
842
+ if (!chrome || streaming || !updatedAt) return;
843
+ const timer = setInterval(() => tick((n) => n + 1), 1e3);
844
+ return () => clearInterval(timer);
845
+ }, [chrome, streaming, updatedAt]);
846
+ const stillSrc = (_k = frame == null ? void 0 : frame.src) != null ? _k : null;
847
+ const showPicture = !gone && (streaming || !!stillSrc);
848
+ let pictureLane = "connecting";
849
+ if (streaming) pictureLane = "live";
850
+ else if (stillSrc) pictureLane = "snapshots";
851
+ useEffect(() => onLaneChange == null ? void 0 : onLaneChange(pictureLane), [pictureLane, onLaneChange]);
852
+ let pictureHint;
853
+ if (controlling) pictureHint = "Tap to click on the page";
854
+ else if (onTakeControl) pictureHint = "Tap to take control";
855
+ return /* @__PURE__ */ jsxs(View, { style: styles.root, children: [
856
+ chrome ? /* @__PURE__ */ jsxs(View, { style: styles.toolbar, children: [
857
+ /* @__PURE__ */ jsx(ToolButton, { icon: "arrow-left", label: "Back", onPress: () => {
858
+ void history("back");
859
+ } }),
860
+ /* @__PURE__ */ jsx(ToolButton, { icon: "arrow-right", label: "Forward", onPress: () => {
861
+ void history("forward");
862
+ } }),
863
+ /* @__PURE__ */ jsx(ToolButton, { icon: "refresh", label: "Refresh", onPress: () => {
864
+ void capture();
865
+ } }),
866
+ /* @__PURE__ */ jsx(TextInput, { ref: addressRef, value: address, onChangeText: setDraft, onBlur: () => setDraft(null), onSubmitEditing: () => {
867
+ void go();
868
+ }, placeholder: "Type a URL for the computer to open", placeholderTextColor: C.ghost, accessibilityLabel: "Address", autoCapitalize: "none", autoCorrect: false, keyboardType: "url", returnKeyType: "go", selectTextOnFocus: true, style: styles.address }),
869
+ /* @__PURE__ */ jsx(Pressable, { onPress: () => {
870
+ void go();
871
+ }, disabled: !address.trim() || busy, accessibilityRole: "button", accessibilityLabel: "Go", hitSlop: 6, style: ({
872
+ pressed
873
+ }) => [styles.toolButton, pressed && styles.pressed], children: busy ? /* @__PURE__ */ jsx(ActivityIndicator, { size: "small", color: C.muted }) : /* @__PURE__ */ jsx(MaterialCommunityIcons, { name: "arrow-right-circle-outline", size: 20, color: address.trim() ? C.inkSoft : C.ghost }) })
874
+ ] }) : null,
875
+ /* @__PURE__ */ jsxs(View, { ref: boxRef, style: styles.box, onLayout: onBoxLayout, children: [
876
+ gone ? /* @__PURE__ */ jsxs(View, { style: styles.center, accessibilityRole: "text", children: [
877
+ /* @__PURE__ */ jsx(MaterialCommunityIcons, { name: "application-outline", size: 22, color: C.ghost }),
878
+ /* @__PURE__ */ jsx(Text, { style: styles.centerText, children: TAB_GONE_MESSAGE })
879
+ ] }) : null,
880
+ showPicture && picture ? /* @__PURE__ */ jsxs(Animated.View, { style: [styles.picture, {
881
+ width: picture.width,
882
+ height: picture.height,
883
+ transform: pan.getTranslateTransform()
884
+ }], onStartShouldSetResponder: () => true, onMoveShouldSetResponder: () => true, onResponderTerminationRequest: () => false, onResponderGrant: onGrant, onResponderStart: onTouchJoined, onResponderMove: onMove, onResponderEnd: onTouchLeft, onResponderRelease: (event) => finish(event, false), onResponderTerminate: (event) => finish(event, true), accessible: true, accessibilityRole: "image", accessibilityLabel: pageTitle || "The computer's browser", accessibilityHint: pictureHint, children: [
885
+ /* @__PURE__ */ jsxs(View, { pointerEvents: "none", style: StyleSheet.absoluteFill, children: [
886
+ !streaming && stillSrc ? /* @__PURE__ */ jsx(Image, { source: {
887
+ uri: stillSrc
888
+ }, style: StyleSheet.absoluteFill, resizeMode: "stretch", fadeDuration: 0, onLoad: (e) => {
889
+ var _a2, _b2;
890
+ return noteShape("snap", (_a2 = e.nativeEvent.source) == null ? void 0 : _a2.width, (_b2 = e.nativeEvent.source) == null ? void 0 : _b2.height);
891
+ } }) : null,
892
+ ["a", "b"].map((slot) => {
893
+ const shot = slots[slot];
894
+ if (!shot) return null;
895
+ return /* @__PURE__ */ jsx(Image, { source: {
896
+ uri: shot.src,
897
+ headers: shot.headers
898
+ }, style: [StyleSheet.absoluteFill, {
899
+ opacity: slots.shown && slots.front === slot ? 1 : 0
900
+ }, slots.front === slot ? styles.front : null], resizeMode: "stretch", fadeDuration: 0, onLoad: (e) => {
901
+ var _a2, _b2;
902
+ return onSlotLoad(slot, shot.stamp, (_a2 = e.nativeEvent.source) == null ? void 0 : _a2.width, (_b2 = e.nativeEvent.source) == null ? void 0 : _b2.height);
903
+ }, onError: () => onSlotError(slot, shot.stamp) }, slot);
904
+ })
905
+ ] }),
906
+ ping ? /* @__PURE__ */ jsx(Animated.View, { pointerEvents: "none", style: [styles.ping, {
907
+ left: ping.x - 12,
908
+ top: ping.y - 12,
909
+ opacity: pingFade
910
+ }] }) : null
911
+ ] }) : null,
912
+ !gone && !(showPicture && picture) ? /* @__PURE__ */ jsx(View, { style: styles.center, children: problem ? /* @__PURE__ */ jsx(Text, { style: styles.centerText, children: problem }) : /* @__PURE__ */ jsxs(View, { style: styles.row, children: [
913
+ /* @__PURE__ */ jsx(ActivityIndicator, { size: "small", color: C.muted }),
914
+ /* @__PURE__ */ jsx(Text, { style: styles.centerText, children: "Starting the browser\u2026" })
915
+ ] }) }) : null,
916
+ lookAroundHint ? /* @__PURE__ */ jsxs(View, { pointerEvents: "none", style: styles.hint, accessibilityLiveRegion: "polite", children: [
917
+ /* @__PURE__ */ jsx(MaterialCommunityIcons, { name: "gesture-two-tap", size: 14, color: C.accent }),
918
+ /* @__PURE__ */ jsx(Text, { style: styles.hintText, children: "Two fingers to look around" })
919
+ ] }) : null,
920
+ controlling ? /* @__PURE__ */ jsx(
921
+ TextInput,
922
+ {
923
+ ref: bridgeRef,
924
+ value: bridgeText,
925
+ onChangeText: onBridgeChange,
926
+ onKeyPress: onBridgeKey,
927
+ onSubmitEditing: onBridgeSubmit,
928
+ submitBehavior: "submit",
929
+ onFocus: () => setKeyboardUp(true),
930
+ onBlur: () => setKeyboardUp(false),
931
+ accessibilityLabel: "Type into the page",
932
+ caretHidden: true,
933
+ contextMenuHidden: false,
934
+ importantForAutofill: "yes",
935
+ secureTextEntry: bridgeConfig.secureTextEntry,
936
+ keyboardType: bridgeConfig.keyboardType,
937
+ autoComplete: bridgeConfig.autoComplete,
938
+ textContentType: bridgeConfig.textContentType,
939
+ autoCapitalize: bridgeConfig.autoCapitalize,
940
+ autoCorrect: bridgeConfig.autoCorrect,
941
+ spellCheck: bridgeConfig.spellCheck,
942
+ returnKeyType: bridgeConfig.returnKeyType,
943
+ style: styles.bridge
944
+ }
945
+ ) : null
946
+ ] }),
947
+ chrome ? /* @__PURE__ */ jsxs(View, { style: styles.status, children: [
948
+ /* @__PURE__ */ jsx(Text, { numberOfLines: 1, style: [styles.statusText, styles.statusTitle, problem && !gone ? {
949
+ color: C.danger
950
+ } : null], children: gone ? TAB_GONE_MESSAGE : problem || pageTitle || "about:blank" }),
951
+ !gone && streaming ? /* @__PURE__ */ jsxs(View, { style: styles.row, children: [
952
+ /* @__PURE__ */ jsx(View, { style: [styles.dot, {
953
+ backgroundColor: C.live
954
+ }] }),
955
+ /* @__PURE__ */ jsx(Text, { style: [styles.statusText, {
956
+ color: C.live
957
+ }], children: "live" })
958
+ ] }) : null,
959
+ !gone && !streaming && updatedAt ? /* @__PURE__ */ jsxs(Text, { style: styles.statusText, children: [
960
+ Math.max(0, Math.round((Date.now() - updatedAt) / 1e3)),
961
+ "s ago"
962
+ ] }) : null
963
+ ] }) : null
964
+ ] });
965
+ }
966
+ const makeStyles = (C) => StyleSheet.create({
967
+ root: {
968
+ flex: 1,
969
+ backgroundColor: C.page
970
+ },
971
+ toolbar: {
972
+ flexDirection: "row",
973
+ alignItems: "center",
974
+ gap: 4,
975
+ paddingHorizontal: 8,
976
+ paddingVertical: 6,
977
+ backgroundColor: C.raised,
978
+ borderBottomWidth: StyleSheet.hairlineWidth,
979
+ borderBottomColor: C.hairline
980
+ },
981
+ toolButton: {
982
+ width: 32,
983
+ height: 32,
984
+ alignItems: "center",
985
+ justifyContent: "center",
986
+ borderRadius: 8
987
+ },
988
+ pressed: {
989
+ backgroundColor: C.fill
990
+ },
991
+ address: {
992
+ flex: 1,
993
+ minWidth: 0,
994
+ height: 32,
995
+ paddingHorizontal: 12,
996
+ borderRadius: 16,
997
+ borderWidth: StyleSheet.hairlineWidth,
998
+ borderColor: C.border,
999
+ backgroundColor: C.well,
1000
+ color: C.inkSoft,
1001
+ fontFamily: MONO_FONT,
1002
+ fontSize: 12
1003
+ },
1004
+ box: {
1005
+ flex: 1,
1006
+ overflow: "hidden",
1007
+ backgroundColor: C.page
1008
+ },
1009
+ picture: {
1010
+ position: "absolute",
1011
+ left: 0,
1012
+ top: 0
1013
+ },
1014
+ front: {
1015
+ zIndex: 1
1016
+ },
1017
+ center: {
1018
+ flex: 1,
1019
+ alignItems: "center",
1020
+ justifyContent: "center",
1021
+ gap: 8,
1022
+ paddingHorizontal: 24
1023
+ },
1024
+ centerText: {
1025
+ fontSize: 13,
1026
+ color: C.muted,
1027
+ textAlign: "center"
1028
+ },
1029
+ row: {
1030
+ flexDirection: "row",
1031
+ alignItems: "center",
1032
+ gap: 8
1033
+ },
1034
+ ping: {
1035
+ position: "absolute",
1036
+ width: 24,
1037
+ height: 24,
1038
+ borderRadius: 12,
1039
+ borderWidth: 2,
1040
+ borderColor: C.accent,
1041
+ zIndex: 2
1042
+ },
1043
+ hint: {
1044
+ position: "absolute",
1045
+ top: 12,
1046
+ alignSelf: "center",
1047
+ flexDirection: "row",
1048
+ alignItems: "center",
1049
+ gap: 6,
1050
+ paddingHorizontal: 12,
1051
+ paddingVertical: 6,
1052
+ borderRadius: 999,
1053
+ backgroundColor: C.overlay,
1054
+ zIndex: 3
1055
+ },
1056
+ hintText: {
1057
+ fontSize: 12,
1058
+ fontWeight: "500",
1059
+ color: C.ink
1060
+ },
1061
+ bridge: {
1062
+ position: "absolute",
1063
+ left: 0,
1064
+ bottom: 0,
1065
+ width: 1,
1066
+ height: 1,
1067
+ opacity: 0,
1068
+ color: "transparent"
1069
+ },
1070
+ status: {
1071
+ flexDirection: "row",
1072
+ alignItems: "center",
1073
+ gap: 8,
1074
+ paddingHorizontal: 12,
1075
+ paddingVertical: 4,
1076
+ backgroundColor: C.raised,
1077
+ borderTopWidth: StyleSheet.hairlineWidth,
1078
+ borderTopColor: C.hairline
1079
+ },
1080
+ statusText: {
1081
+ fontSize: 11,
1082
+ color: C.faint
1083
+ },
1084
+ statusTitle: {
1085
+ flex: 1,
1086
+ minWidth: 0
1087
+ },
1088
+ dot: {
1089
+ width: 6,
1090
+ height: 6,
1091
+ borderRadius: 3
1092
+ }
1093
+ });export{LivePage};//# sourceMappingURL=LivePage.js.map