effect-browser 0.3.0-beta.23 → 0.3.0-beta.25

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 (348) hide show
  1. package/README.md +437 -142
  2. package/dist/Action.d.mts +1 -1
  3. package/dist/Action.mjs +61 -9
  4. package/dist/Action.mjs.map +1 -1
  5. package/dist/Browser.d.mts +2 -2
  6. package/dist/Browser.mjs +2 -2
  7. package/dist/BrowserError.d.mts +2 -2
  8. package/dist/BrowserError.mjs +194 -41
  9. package/dist/BrowserError.mjs.map +1 -1
  10. package/dist/BrowserEvent.d.mts +2 -2
  11. package/dist/BrowserEvent.mjs +185 -35
  12. package/dist/BrowserEvent.mjs.map +1 -1
  13. package/dist/Cdp.d.mts +15 -0
  14. package/dist/Cdp.mjs +22 -0
  15. package/dist/Cdp.mjs.map +1 -0
  16. package/dist/Change.d.mts +2 -2
  17. package/dist/Change.mjs +40 -7
  18. package/dist/Change.mjs.map +1 -1
  19. package/dist/Frame.d.mts +2 -2
  20. package/dist/Frame.mjs +132 -14
  21. package/dist/Frame.mjs.map +1 -1
  22. package/dist/InputStyle.d.mts +153 -0
  23. package/dist/InputStyle.mjs +2 -0
  24. package/dist/Layout.d.mts +2 -0
  25. package/dist/Layout.mjs +123 -0
  26. package/dist/Layout.mjs.map +1 -0
  27. package/dist/Overlay.d.mts +2 -0
  28. package/dist/Overlay.mjs +58 -0
  29. package/dist/Overlay.mjs.map +1 -0
  30. package/dist/Page.d.mts +2 -2
  31. package/dist/Page.mjs +2 -2
  32. package/dist/PageTime.d.mts +2 -0
  33. package/dist/PageTime.mjs +17 -0
  34. package/dist/PageTime.mjs.map +1 -0
  35. package/dist/Pose.d.mts +2 -0
  36. package/dist/Pose.mjs +65 -0
  37. package/dist/Pose.mjs.map +1 -0
  38. package/dist/Site.d.mts +984 -0
  39. package/dist/Site.mjs +110 -0
  40. package/dist/Site.mjs.map +1 -0
  41. package/dist/Snapshot.d.mts +2 -2
  42. package/dist/Snapshot.mjs +87 -6
  43. package/dist/Snapshot.mjs.map +1 -1
  44. package/dist/Text.d.mts +2 -0
  45. package/dist/Text.mjs +45 -0
  46. package/dist/Text.mjs.map +1 -0
  47. package/dist/Window.d.mts +2 -2
  48. package/dist/Window.mjs +31 -6
  49. package/dist/Window.mjs.map +1 -1
  50. package/dist/ai/BrowserTools.d.mts +4987 -0
  51. package/dist/ai/BrowserTools.mjs +3 -0
  52. package/dist/ai/PageControl.d.mts +286 -0
  53. package/dist/ai/PageControl.mjs +426 -0
  54. package/dist/ai/PageControl.mjs.map +1 -0
  55. package/dist/ai/PromptCache.d.mts +16 -0
  56. package/dist/ai/PromptCache.mjs +72 -0
  57. package/dist/ai/PromptCache.mjs.map +1 -0
  58. package/dist/ai/Tabs.d.mts +2 -0
  59. package/dist/ai/Tabs.mjs +72 -0
  60. package/dist/ai/Tabs.mjs.map +1 -0
  61. package/dist/ai/ToolError.d.mts +34 -0
  62. package/dist/ai/ToolError.mjs +2 -0
  63. package/dist/ai/index.d.mts +6 -0
  64. package/dist/ai/index.mjs +6 -0
  65. package/dist/index.d.mts +7 -15
  66. package/dist/index.mjs +9 -8
  67. package/dist/{Action-24sLOubi.d.mts → internal/Action-CkanNTUw.d.mts} +64 -4
  68. package/dist/{Browser-wZhwZSlG.d.mts → internal/Browser-DD9Vm1c-.d.mts} +80 -10
  69. package/dist/{Browser-BKPAbyys.mjs → internal/Browser-vzD7i2oj.mjs} +658 -495
  70. package/dist/internal/Browser-vzD7i2oj.mjs.map +1 -0
  71. package/dist/{BrowserError-BlcmLVzn.d.mts → internal/BrowserError-CsuRYcDX.d.mts} +187 -28
  72. package/dist/{BrowserEvent-lLqJ3GJS.d.mts → internal/BrowserEvent-tGPYYf6R.d.mts} +197 -18
  73. package/dist/internal/BrowserTools-Yi3lOX4h.mjs +497 -0
  74. package/dist/internal/BrowserTools-Yi3lOX4h.mjs.map +1 -0
  75. package/dist/{Style-AO4V7Czt.mjs → internal/InputStyle-CPzxoN4g.mjs} +94 -16
  76. package/dist/internal/InputStyle-CPzxoN4g.mjs.map +1 -0
  77. package/dist/{moment/Moment.mjs → internal/Moment-CstaX1mR.mjs} +49 -16
  78. package/dist/internal/Moment-CstaX1mR.mjs.map +1 -0
  79. package/dist/{moment/Moment.d.mts → internal/Moment-DOcldBdf.d.mts} +54 -21
  80. package/dist/internal/Page-BfGxn7oN.d.mts +1553 -0
  81. package/dist/{Page-BF5izr8R.mjs → internal/Page-DqF-tuTx.mjs} +62 -72
  82. package/dist/internal/Page-DqF-tuTx.mjs.map +1 -0
  83. package/dist/internal/Release-CFONkPDP.d.mts +39 -0
  84. package/dist/internal/Stage-D5ymSXDT.mjs +298 -0
  85. package/dist/internal/Stage-D5ymSXDT.mjs.map +1 -0
  86. package/dist/internal/Stillness-DCPeAN1a.mjs +1124 -0
  87. package/dist/internal/Stillness-DCPeAN1a.mjs.map +1 -0
  88. package/dist/internal/Supervisor-BcY_QNIY.d.mts +108 -0
  89. package/dist/internal/Supervisor-BcglY23c.mjs +531 -0
  90. package/dist/internal/Supervisor-BcglY23c.mjs.map +1 -0
  91. package/dist/internal/Tabs-dXMscIUQ.d.mts +52 -0
  92. package/dist/internal/TestPage-CYiYbh63.d.mts +159 -0
  93. package/dist/internal/ToolError-DArsRS2m.mjs +117 -0
  94. package/dist/internal/ToolError-DArsRS2m.mjs.map +1 -0
  95. package/dist/{plan/index.d.mts → internal/Walk-BNXcfZ2z.d.mts} +59 -35
  96. package/dist/{plan/index.mjs → internal/Walk-C5ky7uSf.mjs} +83 -51
  97. package/dist/internal/Walk-C5ky7uSf.mjs.map +1 -0
  98. package/dist/{ActionPort.mjs → internal/action-port-B5EkeGOR.mjs} +6 -12
  99. package/dist/internal/action-port-B5EkeGOR.mjs.map +1 -0
  100. package/dist/internal/cdp/workerd.d.mts +13 -0
  101. package/dist/internal/cdp/workerd.mjs +19 -0
  102. package/dist/internal/cdp/workerd.mjs.map +1 -0
  103. package/dist/{Clock.mjs → internal/clock-BKSAEf00.mjs} +13 -13
  104. package/dist/internal/clock-BKSAEf00.mjs.map +1 -0
  105. package/dist/{connection-2KHI4_KN.d.mts → internal/connection-BaB0vp1o.d.mts} +6 -6
  106. package/dist/{connection-CK83pvqP.mjs → internal/connection-C2X4GmXM.mjs} +19 -15
  107. package/dist/internal/connection-C2X4GmXM.mjs.map +1 -0
  108. package/dist/internal/events-DzCrww-y.mjs +72 -0
  109. package/dist/internal/events-DzCrww-y.mjs.map +1 -0
  110. package/dist/internal/fold.inpage-CyVZQHZL.d.mts +49 -0
  111. package/dist/internal/fold.inpage-uhrT-dOB.mjs +49 -0
  112. package/dist/internal/fold.inpage-uhrT-dOB.mjs.map +1 -0
  113. package/dist/internal/functions-jBOs6GKv.mjs +27 -0
  114. package/dist/internal/functions-jBOs6GKv.mjs.map +1 -0
  115. package/dist/{Geometry-DJx9qrYy.d.mts → internal/geometry-Dhj_ztJs.d.mts} +3 -3
  116. package/dist/{Geometry.mjs → internal/geometry-Lxyflb9J.mjs} +3 -12
  117. package/dist/internal/geometry-Lxyflb9J.mjs.map +1 -0
  118. package/dist/{Matching.mjs → internal/matching-Cs-UeOY0.mjs} +24 -19
  119. package/dist/internal/matching-Cs-UeOY0.mjs.map +1 -0
  120. package/dist/internal/page-DFQb-YOK.mjs +436 -0
  121. package/dist/internal/page-DFQb-YOK.mjs.map +1 -0
  122. package/dist/internal/pose.inpage-CBFeWcVa.mjs +1996 -0
  123. package/dist/internal/pose.inpage-CBFeWcVa.mjs.map +1 -0
  124. package/dist/{Url.mjs → internal/url-DB0pQYk6.mjs} +3 -12
  125. package/dist/internal/url-DB0pQYk6.mjs.map +1 -0
  126. package/dist/policy/Policy.d.mts +60 -6
  127. package/dist/policy/Policy.mjs +52 -9
  128. package/dist/policy/Policy.mjs.map +1 -1
  129. package/dist/policy/index.d.mts +2 -0
  130. package/dist/policy/index.mjs +2 -0
  131. package/dist/presentation/Film.d.mts +332 -0
  132. package/dist/presentation/Film.mjs +298 -0
  133. package/dist/presentation/Film.mjs.map +1 -0
  134. package/dist/presentation/Motion.d.mts +5 -1
  135. package/dist/presentation/Motion.mjs +16 -2
  136. package/dist/presentation/Motion.mjs.map +1 -1
  137. package/dist/presentation/Presentation.d.mts +48 -6
  138. package/dist/presentation/Presentation.mjs +28 -9
  139. package/dist/presentation/Presentation.mjs.map +1 -1
  140. package/dist/presentation/Stage.d.mts +40 -6
  141. package/dist/presentation/Stage.mjs +1 -262
  142. package/dist/presentation/index.d.mts +5 -0
  143. package/dist/presentation/index.mjs +5 -0
  144. package/dist/supervisor/Release.d.mts +2 -0
  145. package/dist/supervisor/Release.mjs +40 -0
  146. package/dist/supervisor/Release.mjs.map +1 -0
  147. package/dist/supervisor/Supervisor.d.mts +2 -104
  148. package/dist/supervisor/Supervisor.mjs +2 -515
  149. package/dist/supervisor/index.d.mts +3 -0
  150. package/dist/supervisor/index.mjs +3 -0
  151. package/dist/testing/HttpCassette.d.mts +98 -0
  152. package/dist/testing/HttpCassette.mjs +146 -0
  153. package/dist/testing/HttpCassette.mjs.map +1 -0
  154. package/dist/testing/Story.d.mts +31 -0
  155. package/dist/testing/Story.mjs +76 -0
  156. package/dist/testing/Story.mjs.map +1 -0
  157. package/dist/testing/TestBrowser.d.mts +191 -0
  158. package/dist/testing/TestBrowser.mjs +105 -0
  159. package/dist/testing/TestBrowser.mjs.map +1 -0
  160. package/dist/testing/TestModel.d.mts +133 -0
  161. package/dist/testing/TestModel.mjs +209 -0
  162. package/dist/testing/TestModel.mjs.map +1 -0
  163. package/dist/testing/TestPage.d.mts +2 -0
  164. package/dist/testing/TestPage.mjs +47 -0
  165. package/dist/testing/TestPage.mjs.map +1 -0
  166. package/dist/testing/index.d.mts +6 -337
  167. package/dist/testing/index.mjs +6 -515
  168. package/dist/timeline/Moment.d.mts +3 -0
  169. package/dist/timeline/Moment.mjs +3 -0
  170. package/dist/timeline/Stillness.d.mts +34 -0
  171. package/dist/timeline/Stillness.mjs +2 -0
  172. package/dist/timeline/index.d.mts +3 -0
  173. package/dist/timeline/index.mjs +3 -0
  174. package/dist/walk/Walk.d.mts +2 -0
  175. package/dist/walk/Walk.mjs +2 -0
  176. package/dist/walk/index.d.mts +2 -0
  177. package/dist/walk/index.mjs +2 -0
  178. package/package.json +54 -133
  179. package/src/Action.ts +73 -8
  180. package/src/Browser.ts +85 -14
  181. package/src/BrowserError.ts +258 -63
  182. package/src/BrowserEvent.ts +264 -48
  183. package/src/Cdp.ts +42 -0
  184. package/src/Change.ts +75 -4
  185. package/src/Frame.ts +247 -14
  186. package/src/{Style.ts → InputStyle.ts} +130 -18
  187. package/src/Layout.ts +187 -0
  188. package/src/Overlay.ts +76 -0
  189. package/src/Page.ts +144 -275
  190. package/src/PageTime.ts +72 -0
  191. package/src/Pose.ts +81 -0
  192. package/src/Site.ts +136 -0
  193. package/src/Snapshot.ts +179 -3
  194. package/src/Text.ts +60 -0
  195. package/src/Window.ts +53 -3
  196. package/src/ai/BrowserTools.ts +778 -0
  197. package/src/ai/PageControl.ts +702 -0
  198. package/src/ai/PromptCache.ts +87 -0
  199. package/src/ai/Tabs.ts +84 -0
  200. package/src/ai/ToolError.ts +50 -0
  201. package/src/ai/index.ts +36 -0
  202. package/src/ai/internal/crops.ts +38 -0
  203. package/src/ai/internal/points.ts +57 -0
  204. package/src/ai/internal/receipts.ts +107 -0
  205. package/src/index.ts +87 -6
  206. package/src/{ActionPort.ts → internal/action-port.ts} +3 -3
  207. package/src/{providers → internal/cdp}/connection.ts +19 -12
  208. package/src/internal/cdp/workerd.ts +36 -0
  209. package/src/{Clock.ts → internal/clock.ts} +20 -0
  210. package/src/internal/input/actions.ts +1 -1
  211. package/src/internal/input/dispatch.ts +2 -2
  212. package/src/internal/input/guard.inpage.ts +1 -1
  213. package/src/internal/input/guard.ts +1 -1
  214. package/src/internal/input/perform.ts +35 -7
  215. package/src/internal/input/pointer.ts +9 -6
  216. package/src/internal/input/targets.inpage.ts +3 -3
  217. package/src/internal/input/targets.ts +1 -1
  218. package/src/{Matching.ts → internal/matching.ts} +28 -19
  219. package/src/internal/page/bridge.ts +67 -35
  220. package/src/internal/page/clock.inpage.ts +306 -0
  221. package/src/internal/page/compose.inpage.ts +101 -0
  222. package/src/internal/page/context.ts +4 -2
  223. package/src/internal/page/functions.ts +84 -0
  224. package/src/internal/page/navigation.ts +1 -1
  225. package/src/internal/page/openings.ts +2 -2
  226. package/src/internal/page/overlay.inpage.ts +96 -0
  227. package/src/internal/page/overlay.ts +89 -0
  228. package/src/internal/page/page.ts +39 -29
  229. package/src/internal/page/port.ts +14 -8
  230. package/src/internal/page/pose.inpage.ts +200 -0
  231. package/src/internal/page/pose.ts +80 -0
  232. package/src/internal/page/replies.ts +1 -1
  233. package/src/internal/page/requests.ts +1 -1
  234. package/src/internal/page/scripts.ts +1 -1
  235. package/src/internal/page/time.inpage.ts +49 -0
  236. package/src/internal/page/time.ts +122 -0
  237. package/src/internal/page/viewport.ts +3 -2
  238. package/src/internal/pictures/capture.ts +1 -4
  239. package/src/internal/pictures/dimensions.ts +1 -1
  240. package/src/internal/pictures/frame.ts +1 -1
  241. package/src/internal/pictures/pictures.ts +144 -91
  242. package/src/internal/reading/context.inpage.ts +2 -2
  243. package/src/internal/reading/expect.inpage.ts +1 -1
  244. package/src/internal/reading/layout.inpage.ts +193 -0
  245. package/src/internal/reading/layout.ts +101 -0
  246. package/src/internal/reading/names.inpage.ts +15 -0
  247. package/src/internal/reading/outline.inpage.ts +5 -21
  248. package/src/internal/reading/reading.ts +33 -21
  249. package/src/internal/reading/ready.inpage.ts +21 -26
  250. package/src/internal/reading/ready.ts +26 -5
  251. package/src/internal/reading/subjects.inpage.ts +3 -3
  252. package/src/internal/reading/text.inpage.ts +3 -16
  253. package/src/internal/reading/walk.inpage.ts +1 -1
  254. package/src/internal/timeline/changes.inpage.ts +7 -15
  255. package/src/internal/timeline/changes.ts +17 -5
  256. package/src/internal/timeline/record.inpage.ts +15 -6
  257. package/src/internal/timeline/sight.inpage.ts +2 -2
  258. package/src/internal/timeline/window.ts +3 -4
  259. package/src/policy/Policy.ts +70 -16
  260. package/src/policy/index.ts +12 -0
  261. package/src/presentation/Film.ts +451 -0
  262. package/src/presentation/Motion.ts +45 -3
  263. package/src/presentation/Presentation.ts +60 -14
  264. package/src/presentation/Stage.ts +73 -35
  265. package/src/presentation/index.ts +30 -0
  266. package/src/presentation/{feed.ts → internal/feed.ts} +1 -1
  267. package/src/supervisor/Release.ts +45 -0
  268. package/src/supervisor/Supervisor.ts +80 -5
  269. package/src/supervisor/index.ts +18 -0
  270. package/src/supervisor/{contract.ts → internal/contract.ts} +14 -10
  271. package/src/supervisor/{lifecycle.ts → internal/lifecycle.ts} +7 -7
  272. package/src/supervisor/{runtime.ts → internal/runtime.ts} +7 -7
  273. package/src/testing/HttpCassette.ts +260 -0
  274. package/src/testing/Story.ts +103 -0
  275. package/src/testing/TestBrowser.ts +14 -4
  276. package/src/testing/TestModel.ts +297 -0
  277. package/src/testing/TestPage.ts +92 -4
  278. package/src/testing/index.ts +35 -1
  279. package/src/testing/{evidence.ts → internal/evidence.ts} +19 -11
  280. package/src/testing/{model.ts → internal/model.ts} +14 -8
  281. package/src/testing/{page.ts → internal/page.ts} +55 -51
  282. package/src/{moment → timeline}/Moment.ts +79 -29
  283. package/src/{stillness → timeline}/Stillness.ts +89 -46
  284. package/src/timeline/index.ts +18 -0
  285. package/src/{stillness/Pixels.ts → timeline/internal/pixels.ts} +27 -1
  286. package/src/{moment → timeline/internal}/words.ts +2 -2
  287. package/src/walk/Walk.ts +165 -0
  288. package/src/walk/index.ts +12 -0
  289. package/src/{plan → walk/internal}/choose.ts +23 -14
  290. package/src/{plan → walk/internal}/data.ts +37 -14
  291. package/src/{plan → walk/internal}/execute.ts +79 -36
  292. package/src/{plan → walk/internal}/record.ts +6 -6
  293. package/src/{plan → walk/internal}/targets.ts +35 -25
  294. package/dist/ActionPort.d.mts +0 -15
  295. package/dist/ActionPort.mjs.map +0 -1
  296. package/dist/Browser-BKPAbyys.mjs.map +0 -1
  297. package/dist/Change-Ba7INmay.d.mts +0 -69
  298. package/dist/Clock.d.mts +0 -57
  299. package/dist/Clock.mjs.map +0 -1
  300. package/dist/Frame-UEH2hO5T.d.mts +0 -124
  301. package/dist/Geometry.d.mts +0 -2
  302. package/dist/Geometry.mjs.map +0 -1
  303. package/dist/Matching.d.mts +0 -37
  304. package/dist/Matching.mjs.map +0 -1
  305. package/dist/Page-BF5izr8R.mjs.map +0 -1
  306. package/dist/Page-CvsOEorc.d.mts +0 -566
  307. package/dist/Released-tURbFmal.d.mts +0 -15
  308. package/dist/Snapshot-CtBVOtuu.d.mts +0 -73
  309. package/dist/Stillness-CNlvayIo.mjs +0 -136
  310. package/dist/Stillness-CNlvayIo.mjs.map +0 -1
  311. package/dist/Style-AO4V7Czt.mjs.map +0 -1
  312. package/dist/Style.d.mts +0 -72
  313. package/dist/Style.mjs +0 -2
  314. package/dist/Url.d.mts +0 -26
  315. package/dist/Url.mjs.map +0 -1
  316. package/dist/Window-CMddGMt1.d.mts +0 -34
  317. package/dist/connection-CK83pvqP.mjs.map +0 -1
  318. package/dist/moment/Moment.mjs.map +0 -1
  319. package/dist/plan/index.mjs.map +0 -1
  320. package/dist/presentation/Stage.mjs.map +0 -1
  321. package/dist/presentation/feed.d.mts +0 -20
  322. package/dist/presentation/feed.mjs +0 -18
  323. package/dist/presentation/feed.mjs.map +0 -1
  324. package/dist/providers/Cdp.d.mts +0 -9
  325. package/dist/providers/Cdp.mjs +0 -15
  326. package/dist/providers/Cdp.mjs.map +0 -1
  327. package/dist/providers/Chromium.d.mts +0 -32
  328. package/dist/providers/Chromium.mjs +0 -55
  329. package/dist/providers/Chromium.mjs.map +0 -1
  330. package/dist/providers/Released.d.mts +0 -2
  331. package/dist/providers/Released.mjs +0 -12
  332. package/dist/providers/Released.mjs.map +0 -1
  333. package/dist/stillness/Stillness.d.mts +0 -12
  334. package/dist/stillness/Stillness.mjs +0 -2
  335. package/dist/supervisor/Supervisor.mjs.map +0 -1
  336. package/dist/testing/index.mjs.map +0 -1
  337. package/dist/workerd/Cdp.d.mts +0 -8
  338. package/dist/workerd/Cdp.mjs +0 -13
  339. package/dist/workerd/Cdp.mjs.map +0 -1
  340. package/src/plan/index.ts +0 -36
  341. package/src/providers/Cdp.ts +0 -16
  342. package/src/providers/Chromium.ts +0 -99
  343. package/src/providers/Released.ts +0 -13
  344. package/src/workerd/Cdp.ts +0 -11
  345. /package/dist/{rolldown-runtime-D7D4PA-g.mjs → internal/rolldown-runtime-D7D4PA-g.mjs} +0 -0
  346. /package/src/{Geometry.ts → internal/geometry.ts} +0 -0
  347. /package/src/{Url.ts → internal/url.ts} +0 -0
  348. /package/src/{stillness → timeline/internal}/utilsBundle.d.ts +0 -0
package/src/Page.ts CHANGED
@@ -1,5 +1,9 @@
1
1
  /**
2
- * One browser tab: navigation, snapshots, pictures and input.
2
+ * One browser tab: navigation and input.
3
+ *
4
+ * `Page` gains a member only for identity, order, time or input. Everything else a page does is a
5
+ * function in the module of what it returns, taking the page first, such as `Snapshot.read(page)`,
6
+ * `Text.read(page)` or `Change.read(page)`.
3
7
  *
4
8
  * A page waits only for itself: its operations take turns in one lane of its own. An action, which
5
9
  * sends input or navigates, has the page to itself, in the order admitted after policy approval; reads share
@@ -13,9 +17,10 @@
13
17
  * screenshot's pixels. Mouse and keyboard input share a bounded pipeline, so pacing does not wait
14
18
  * for each protocol reply. Target lookup happens before the input is sent.
15
19
  *
20
+ * @stability stable
16
21
  * @since 0.3.0
17
22
  */
18
- import { type Clock, type Duration, Effect, Schema, type Scope, type Stream } from "effect";
23
+ import { type Clock, type Duration, Effect, Function, Schema } from "effect";
19
24
 
20
25
  import {
21
26
  Action,
@@ -26,38 +31,43 @@ import {
26
31
  } from "./Action.ts";
27
32
  import { type BrowserError, type PolicyDenied } from "./BrowserError.ts";
28
33
  import { Box, type BrowserEvent, PageLoaded, Subject } from "./BrowserEvent.ts";
29
- import type { Changes } from "./Change.ts";
30
- import { type CaptureStats, Frame, Image, type ScreencastOptions } from "./Frame.ts";
31
- import * as Motion from "./Geometry.ts";
34
+ import * as Motion from "./internal/geometry.ts";
32
35
  import { FormFieldSchema } from "./internal/input/evidence.inpage.ts";
33
36
  import * as Guard from "./internal/input/guard.inpage.ts";
37
+ import {
38
+ type Implementation,
39
+ isPage as isLibraryPage,
40
+ type key,
41
+ } from "./internal/page/functions.ts";
34
42
  import { Correlation, FailFast } from "./internal/page/lane.ts";
35
- import { type Snapshot, type SnapshotOptions } from "./Snapshot.ts";
36
- import * as Url from "./Url.ts";
37
- import type { Window } from "./Window.ts";
43
+ import * as Url from "./internal/url.ts";
38
44
 
45
+ /**
46
+ * @stability stable
47
+ * @category models
48
+ * @since 0.3.0
49
+ */
39
50
  export type Point = Motion.Point;
40
51
 
41
- /** A ref from a snapshot, such as `"e12"`, or a viewport point. */
52
+ /**
53
+ * A ref from a snapshot, such as `"e12"`, or a viewport point.
54
+ *
55
+ * @stability stable
56
+ * @category models
57
+ * @since 0.3.0
58
+ */
42
59
  export type Target = string | Point;
43
60
 
44
- /** An integer rectangle in viewport CSS pixels. */
45
- export class Region extends Schema.Class<Region>("effect-browser/Region")({
46
- x: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),
47
- y: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),
48
- width: Schema.Int.check(Schema.isGreaterThan(0)),
49
- height: Schema.Int.check(Schema.isGreaterThan(0)),
50
- }) {}
51
-
52
- /** A crop and its viewport origin: add that origin to a point read from the crop. */
53
- export class Zoom extends Schema.Class<Zoom>("effect-browser/Zoom")({
54
- page: Schema.String,
55
- region: Region,
56
- image: Image,
57
- }) {}
58
-
59
- /** The target as it read before input. Point coordinates are never snapped to another position. */
60
- export class ResolvedTarget extends Schema.Class<ResolvedTarget>("effect-browser/ResolvedTarget")({
61
+ /**
62
+ * The target as it read before input. Point coordinates are never snapped to another position.
63
+ *
64
+ * @stability stable
65
+ * @category schemas
66
+ * @since 0.3.0
67
+ */
68
+ export class ResolvedTarget extends Schema.Class<ResolvedTarget>(
69
+ "effect-browser/Page/ResolvedTarget",
70
+ )({
61
71
  point: Motion.Point,
62
72
  ...Subject.fields,
63
73
  element: Schema.String,
@@ -67,170 +77,56 @@ export class ResolvedTarget extends Schema.Class<ResolvedTarget>("effect-browser
67
77
  href: Schema.optional(Schema.String),
68
78
  }) {}
69
79
 
70
- /** Action options share the execution codec. */
80
+ /**
81
+ * Action options share the execution codec.
82
+ *
83
+ * @stability stable
84
+ * @category options
85
+ * @since 0.3.0
86
+ */
71
87
  export type ClickOptions = typeof ClickOptionsSchema.Type;
72
- export type TypeOptions = typeof TypeOptionsSchema.Type;
73
- export type PressOptions = typeof PressOptionsSchema.Type;
74
- export type ScrollOptions = typeof ScrollOptionsSchema.Type;
75
88
 
76
89
  /**
77
- * How current a picture must be. The newest screencast frame serves when it qualifies, at no cost;
78
- * otherwise a new screenshot is taken.
90
+ * @stability stable
91
+ * @category options
92
+ * @since 0.3.0
79
93
  */
80
- export interface FrameOptions {
81
- /**
82
- * The oldest a reused frame may be, from its paint, at the earliest its timing allows, to now.
83
- * Defaults to 250 milliseconds; 0 always takes a new screenshot.
84
- */
85
- readonly maxAge?: Duration.Input | undefined;
86
- /**
87
- * `"input"`: reuse only a frame painted after this page's latest input, including input of an
88
- * interrupted action, and never while an action is changing the page. For a caller that has
89
- * just acted on the page.
90
- */
91
- readonly after?: "input" | undefined;
92
- }
93
-
94
- /** A screenshot reuses only a frame painted after the page's latest input, as `after: "input"`. */
95
- export interface ScreenshotOptions {
96
- /** The oldest a reused frame may be, as for `frame`. Defaults to 250 milliseconds. */
97
- readonly maxAge?: Duration.Input | undefined;
98
- /** A region of the viewport, captured in CSS pixels at the viewport's own scale; always new. */
99
- readonly clip?: Box | undefined;
100
- /** JPEG quality, 0 to 100. Defaults to 80. */
101
- readonly quality?: number | undefined;
102
- /** `"jpeg"`, the default, or `"png"`, which is always a new picture. */
103
- readonly format?: "jpeg" | "png" | undefined;
104
- /**
105
- * `"css"`, the default, a picture pixel per CSS pixel; `"device"`, the screen's own pixels, as
106
- * many to a CSS pixel as its device scale factor, which is always a new picture.
107
- */
108
- readonly scale?: "css" | "device" | undefined;
109
- }
94
+ export type TypeOptions = typeof TypeOptionsSchema.Type;
110
95
 
111
96
  /**
112
- * What `find` looks for. Every rule given must hold; with none, it finds every element in scope
113
- * that has a role or is a control.
97
+ * @stability stable
98
+ * @category options
99
+ * @since 0.3.0
114
100
  */
115
- export interface FindQuery {
116
- /** Narrow matching to this CSS selector. Invalid CSS fails InvalidRequest. */
117
- readonly selector?: string | undefined;
118
- /** Require a visible match, optionally enabled. */
119
- readonly state?: "visible" | "enabled" | undefined;
120
- /** An ARIA role, such as `"button"` or `"heading"`, ignoring case. */
121
- readonly role?: string | undefined;
122
- /**
123
- * The accessible name: a string that reads the same once spaces are collapsed and case folded,
124
- * or a pattern found in it.
125
- */
126
- readonly name?: string | RegExp | undefined;
127
- /**
128
- * Text it shows, ignoring case and spacing, or a pattern. Text inside a control or a heading is
129
- * that control's or heading's, and only the smallest element showing it matches, not every
130
- * element around it.
131
- */
132
- readonly text?: string | RegExp | undefined;
133
- /** Whole words in its context (row, column, label or heading), ignoring case and spacing. */
134
- readonly near?: string | undefined;
135
- /** Only what a point action at this viewport point would reach: the control there, or else what is painted there. */
136
- readonly at?: Point | undefined;
137
- /** The viewport (the default), or the whole document. */
138
- readonly scope?: "viewport" | "document" | undefined;
139
- }
101
+ export type PressOptions = typeof PressOptionsSchema.Type;
140
102
 
141
103
  /**
142
- * An element's state as its markup gives it: `checked` for what can be checked, `expanded`,
143
- * `selected` and `pressed` where the page says either way, and `level` for headings.
104
+ * @stability stable
105
+ * @category options
106
+ * @since 0.3.0
144
107
  */
145
- export const ElementState = Schema.Struct({
146
- disabled: Schema.Boolean,
147
- focused: Schema.Boolean,
148
- checked: Schema.optional(Schema.Boolean),
149
- expanded: Schema.optional(Schema.Boolean),
150
- selected: Schema.optional(Schema.Boolean),
151
- pressed: Schema.optional(Schema.Boolean),
152
- level: Schema.optional(Schema.Int),
153
- });
154
-
155
- export type ElementState = typeof ElementState.Type;
156
-
157
- /** An element `find` found: a ref for the actions, what it is, where it is and its state. */
158
- export class Found extends Schema.Class<Found>("effect-browser/Found")({
159
- ref: Schema.String,
160
- subject: Subject,
161
- /** Its box, rounded. Reading the document, it may be out of view. */
162
- box: Box,
163
- inViewport: Schema.Boolean,
164
- state: ElementState,
165
- }) {}
166
-
167
- export interface TextOptions {
168
- /** `"viewport"` (the default) reads what the viewport shows; a ref reads that element whole. */
169
- readonly scope?: string | undefined;
170
- /** Bound on the text's length, cut at a line. Defaults to 12,000 characters. */
171
- readonly maxChars?: number | undefined;
172
- /** Show what fields hold; a secret field still reads `••••`. Defaults to false. */
173
- readonly unmask?: boolean | undefined;
174
- }
175
-
176
- /** What a page showed as text: a line per block, with table cells apart by tabs. */
177
- export class Text extends Schema.Class<Text>("effect-browser/Text")({
178
- url: Schema.String,
179
- title: Schema.String,
180
- text: Schema.String,
181
- /** True when `text` was cut at `maxChars`. */
182
- truncated: Schema.Boolean,
183
- /** Host monotonic milliseconds from the browser's captured Effect Clock. */
184
- at: Schema.Finite,
185
- }) {}
108
+ export type ScrollOptions = typeof ScrollOptionsSchema.Type;
186
109
 
110
+ /**
111
+ * @stability stable
112
+ * @category options
113
+ * @since 0.3.0
114
+ */
187
115
  export interface ReadyOptions {
188
116
  /** How long recorded content must stay unchanged. Screen stillness is a separate feature. */
189
- readonly quietMillis?: number | undefined;
117
+ readonly quiet?: Duration.Input | undefined;
190
118
  readonly timeout?: Duration.Input | undefined;
191
119
  }
192
120
 
193
- /** The window `changes` reads, and whether to show what fields hold. */
194
- export interface ChangesOptions {
195
- /**
196
- * Where the window starts: the changes a previous read returned, to continue exactly where they
197
- * ended; a frame, at its paint; or host monotonic milliseconds, which mapped to the page's clock
198
- * may miss or repeat changes near the start if the browser's clock mapping changed since. Defaults
199
- * to the start of the record.
200
- */
201
- readonly since?: Changes | Frame | number | undefined;
202
- /**
203
- * Where it ends: a frame, at its paint, so a delayed frame's window holds nothing it does not
204
- * show; or host monotonic milliseconds. Defaults to now, and is never later.
205
- */
206
- readonly until?: Frame | number | undefined;
207
- /** Show what fields hold; a secret field still reads `••••`. Defaults to false. */
208
- readonly unmask?: boolean | undefined;
209
- }
210
-
211
- /** The window `window` reads, and whether to show what fields hold. */
212
- export interface WindowOptions {
213
- /**
214
- * Where the window starts: a previous window, to continue exactly where it ended; a frame, at its
215
- * paint; host monotonic milliseconds; or a `Duration` back from `until`. A start after `until`
216
- * leaves the window empty there.
217
- */
218
- readonly since: Window | Frame | Duration.Duration | number;
219
- /**
220
- * Where it ends: a frame, at its paint, such as one a delayed consumer airs now; or host
221
- * monotonic milliseconds. Defaults to now, and is never later.
222
- */
223
- readonly until?: Frame | number | undefined;
224
- /** Show what fields hold in its changes; a secret field still reads `••••`. Defaults to false. */
225
- readonly unmask?: boolean | undefined;
226
- }
227
-
228
121
  /**
229
122
  * What the library knows of a page now, without asking it, each part with when it learned it, in
230
- * host monotonic milliseconds: a part's age is `at` less its time. Text read before the current
231
- * document began is left out, since it tells of a document that has gone.
123
+ * host monotonic milliseconds: a part's age is `at` less its time.
124
+ *
125
+ * @stability stable
126
+ * @category schemas
127
+ * @since 0.3.0
232
128
  */
233
- export class State extends Schema.Class<State>("effect-browser/PageState")({
129
+ export class State extends Schema.Class<State>("effect-browser/Page/State")({
234
130
  page: Schema.String,
235
131
  /** The tracking connection that owns this document counter. */
236
132
  connection: Schema.String,
@@ -244,10 +140,6 @@ export class State extends Schema.Class<State>("effect-browser/PageState")({
244
140
  committedAt: Schema.optional(Schema.Finite),
245
141
  /** How far that document has loaded, as the page's own session heard; absent until parsed. */
246
142
  load: Schema.optional(PageLoaded),
247
- /** The newest screencast frame, of whichever document it names. */
248
- frame: Schema.optional(Frame),
249
- /** The viewport's text as it was last read, with the page's title then. */
250
- text: Schema.optional(Text),
251
143
  }) {}
252
144
 
253
145
  /**
@@ -266,9 +158,18 @@ export class State extends Schema.Class<State>("effect-browser/PageState")({
266
158
  *
267
159
  * Facts never come from what an element's text says. What an input means, such as a payment
268
160
  * or a deletion, takes a judge that reads the evidence in the {@link InputRequest}.
161
+ *
162
+ * @stability stable
163
+ * @category schemas
164
+ * @since 0.3.0
269
165
  */
270
166
  export const Fact = Guard.Fact;
271
167
 
168
+ /**
169
+ * @stability stable
170
+ * @category schemas
171
+ * @since 0.3.0
172
+ */
272
173
  export type Fact = typeof Fact.Type;
273
174
 
274
175
  /**
@@ -280,8 +181,12 @@ export type Fact = typeof Fact.Type;
280
181
  * field is replaced with {@link redacted}, here and in the recorded `Action`, and its key events
281
182
  * record `Unidentified` keys; `press` records the keys it is given. Validation before dispatch
282
183
  * binds the facts and the target, not the text around it, which live pages change freely.
184
+ *
185
+ * @stability stable
186
+ * @category schemas
187
+ * @since 0.3.0
283
188
  */
284
- export class InputRequest extends Schema.Class<InputRequest>("effect-browser/InputRequest")({
189
+ export class InputRequest extends Schema.Class<InputRequest>("effect-browser/Page/InputRequest")({
285
190
  page: Schema.String,
286
191
  /**
287
192
  * The page's URL, without a fragment that only names a place on the page. This and the other
@@ -326,12 +231,30 @@ export class InputRequest extends Schema.Class<InputRequest>("effect-browser/Inp
326
231
  /**
327
232
  * What replaces text typed into a `secret` field, in requests and in the recorded `Action`, and a
328
233
  * credential's value in every address the library reports.
234
+ *
235
+ * @stability stable
236
+ * @category constants
237
+ * @since 0.3.0
329
238
  */
330
239
  export const redacted = Url.withheld;
331
240
 
241
+ /**
242
+ * Whether a value is a page the library made: what a function over a page, callable with the page
243
+ * first or last, tells it from its other arguments by.
244
+ *
245
+ * @stability stable
246
+ * @category guards
247
+ * @since 0.3.0
248
+ */
249
+ export const isPage: (u: unknown) => u is Page = isLibraryPage;
250
+
332
251
  /**
333
252
  * Run page operations without waiting their turn: on a page busy with other operations, each fails
334
253
  * `Busy` at once, and `Browser.newPage` on a browser with `maxPages` open fails `Limit` at once.
254
+ *
255
+ * @stability stable
256
+ * @category combinators
257
+ * @since 0.3.0
335
258
  */
336
259
  export const failFast = <A, E, R>(effect: Effect.Effect<A, E, R>): Effect.Effect<A, E, R> =>
337
260
  Effect.provideService(effect, FailFast, true);
@@ -339,48 +262,60 @@ export const failFast = <A, E, R>(effect: Effect.Effect<A, E, R>): Effect.Effect
339
262
  /**
340
263
  * Give every action `effect` performs a caller's id, such as a model's tool call id, which its
341
264
  * recorded `Action` carries as `correlation`.
265
+ *
266
+ * @stability stable
267
+ * @category combinators
268
+ * @since 0.3.0
342
269
  */
343
- export const correlate =
344
- (id: string) =>
345
- <A, E, R>(effect: Effect.Effect<A, E, R>): Effect.Effect<A, E, R> =>
346
- Effect.provideService(effect, Correlation, id);
270
+ export const correlate: {
271
+ (id: string): <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
272
+ <A, E, R>(effect: Effect.Effect<A, E, R>, id: string): Effect.Effect<A, E, R>;
273
+ } = Function.dual(
274
+ 2,
275
+ <A, E, R>(effect: Effect.Effect<A, E, R>, id: string): Effect.Effect<A, E, R> =>
276
+ Effect.provideService(effect, Correlation, id),
277
+ );
347
278
 
348
- /** Succeed to allow, fail to deny, or await an external signal to hold the input. */
279
+ /**
280
+ * Succeed to allow, fail to deny, or await an external signal to hold the input.
281
+ *
282
+ * @stability stable
283
+ * @category models
284
+ * @since 0.3.0
285
+ */
349
286
  export type InputGuard = (request: InputRequest) => Effect.Effect<void, PolicyDenied>;
350
287
 
351
- /** What a wait requires of the query's matches. */
352
- export type UntilWant = "some" | "none" | { readonly other: string };
353
-
354
- export interface UntilResult {
355
- readonly met: boolean;
356
- readonly mark: string;
357
- }
358
-
359
- /** Scoped access to one page's shared capture and its current-document evidence. */
360
- export interface Capture {
361
- readonly stream: Stream.Stream<Frame, BrowserError>;
362
- readonly current: Frame | undefined;
363
- readonly isCurrent: (frame: Frame) => boolean;
364
- readonly confirm: (frame: Frame) => Effect.Effect<boolean, BrowserError>;
365
- readonly sync: Effect.Effect<void, BrowserError>;
366
- readonly stats: (options?: {
367
- readonly window?: Duration.Input | undefined;
368
- }) => Effect.Effect<CaptureStats, BrowserError>;
369
- }
370
-
371
- /** Script values cross the page boundary through the caller's Schema. A bundler may rewrite functions. */
288
+ /**
289
+ * Script values cross the page boundary through the caller's Schema. A bundler may rewrite functions.
290
+ *
291
+ * @stability stable
292
+ * @category options
293
+ * @since 0.3.0
294
+ */
372
295
  export interface ScriptOptions<A, Arg> {
373
296
  readonly arg: Arg;
374
297
  readonly result: Schema.Codec<A, unknown>;
375
298
  }
376
299
 
300
+ /**
301
+ * @stability stable
302
+ * @category options
303
+ * @since 0.3.0
304
+ */
377
305
  export interface ActOptions<A, Arg> extends ScriptOptions<A, Arg> {
378
306
  readonly document: number;
379
307
  /** Supplying the read's connection also refuses a document counter from another connection. */
380
308
  readonly connection?: string | undefined;
381
309
  }
382
310
 
311
+ /**
312
+ * @stability stable
313
+ * @category models
314
+ * @since 0.3.0
315
+ */
383
316
  export interface Page {
317
+ /** What the page does behind its types' modules' functions, such as `Snapshot.read`. */
318
+ readonly [key]: Implementation;
384
319
  /** Decode and perform a data action through the same policy and lane as the named methods. */
385
320
  readonly perform: (action: Action) => Effect.Effect<ResolvedTarget | string | void, BrowserError>;
386
321
  /** Read declared side-effect-free code in the main world, retrying one replaced document. */
@@ -400,22 +335,15 @@ export interface Page {
400
335
  script: (arg: Arg) => unknown,
401
336
  options: ActOptions<A, Arg>,
402
337
  ) => Effect.Effect<A, BrowserError>;
403
- /** Owning browser clock: deadlines and all frame/event timestamps use this clock. */
404
- readonly clock: Clock.Clock;
338
+ /**
339
+ * The owning browser's host clock, which stamps the page's events and frames and times its
340
+ * deadlines. It is not the page's own time, which `PageTime` holds.
341
+ */
342
+ readonly hostClock: Clock.Clock;
405
343
  /** Wait for admitted input and retain a bounded read turn through effect. */
406
344
  readonly afterInput: <A, E, R>(
407
345
  effect: Effect.Effect<A, E, R>,
408
346
  ) => Effect.Effect<A, E | BrowserError, R>;
409
- /** A scoped lease starts capture immediately, independently of its first frame. */
410
- readonly capture: (
411
- options?: ScreencastOptions,
412
- ) => Effect.Effect<Capture, BrowserError, Scope.Scope>;
413
- /** One page-side wait; replaced documents share one deadline. Unmet is met:false; an empty mark means no stable document could be sampled. */
414
- readonly until: (
415
- query: FindQuery,
416
- want: UntilWant,
417
- millis: number,
418
- ) => Effect.Effect<UntilResult, BrowserError>;
419
347
  /** The page's CDP target id: the same page has it again after a reconnect to its browser. */
420
348
  readonly id: string;
421
349
  /** The page's address, without its userinfo or known secret parameters. */
@@ -435,25 +363,6 @@ export interface Page {
435
363
  /** Close the tab, succeeding once it has closed, or at once when it already had. */
436
364
  readonly close: Effect.Effect<void, BrowserError>;
437
365
 
438
- readonly snapshot: (options?: SnapshotOptions) => Effect.Effect<Snapshot, BrowserError>;
439
- /**
440
- * A picture of the viewport, in CSS pixels: a screencast frame painted since the page's latest
441
- * input, if one qualifies, or a new one. A caller that has just acted sees what its action did.
442
- */
443
- readonly screenshot: (options?: ScreenshotOptions) => Effect.Effect<Image, BrowserError>;
444
- /**
445
- * The viewport with its timing: the newest screencast frame if it qualifies, else a new
446
- * screenshot timed by the host interval in which it was taken.
447
- */
448
- readonly frame: (options?: FrameOptions) => Effect.Effect<Frame, BrowserError>;
449
- /**
450
- * A crop in CSS pixels, unmagnified, with the origin that keeps later input in viewport pixels.
451
- * With `scale: "device"` its picture has the screen's own pixels, as a screenshot's would.
452
- */
453
- readonly zoom: (
454
- region: Region,
455
- options?: Pick<ScreenshotOptions, "scale">,
456
- ) => Effect.Effect<Zoom, BrowserError>;
457
366
  /**
458
367
  * The viewport's size in CSS pixels, the space of points, crops and page scrolls. Over CDP the
459
368
  * page reports it, within the action timeout.
@@ -462,36 +371,11 @@ export interface Page {
462
371
  { readonly width: number; readonly height: number },
463
372
  BrowserError
464
373
  >;
465
- /**
466
- * The elements that match a query, in tree order, with refs the actions take, in one call to the
467
- * page. All that match are returned, so a caller tells them apart by their context; none is an
468
- * empty result, not a failure.
469
- */
470
- readonly find: (query?: FindQuery) => Effect.Effect<ReadonlyArray<Found>, BrowserError>;
471
- /**
472
- * The text the viewport shows, or one element whole, in one call to the page. Field values read
473
- * `••••` unless `unmask`, and a secret field's always do, as does one that was secret when the
474
- * library saw it.
475
- */
476
- readonly text: (options?: TextOptions) => Effect.Effect<Text, BrowserError>;
477
- /**
478
- * What visibly changed over a window, in one call to the page. The first read starts the page's
479
- * record, so it finds none; from then the page records, and from the start of each later
480
- * document, until nobody has read it for two minutes. See `Change`.
481
- */
482
- readonly changes: (options?: ChangesOptions) => Effect.Effect<Changes, BrowserError>;
483
- /**
484
- * The page's events, changes and frames over a window: the frames and events it keeps, at no
485
- * call, and its changes, in one call, the first starting its record as `changes` does. A part
486
- * that cannot be read is missing, with why; the window fails only for bounds that are not finite.
487
- */
488
- readonly window: (options: WindowOptions) => Effect.Effect<Window, BrowserError>;
489
374
  /**
490
375
  * What the library knows of the page now, at no call and with no wait for its turn: where it is,
491
- * its document and how far it has loaded, its newest frame, and its text and title as last read.
376
+ * its document and how far it has loaded.
492
377
  */
493
378
  readonly state: Effect.Effect<State>;
494
-
495
379
  readonly click: (
496
380
  target: Target,
497
381
  options?: ClickOptions,
@@ -514,26 +398,11 @@ export interface Page {
514
398
 
515
399
  /**
516
400
  * Wait for document evidence, polling every 50 ms: parsed, painted, visible, fonts and visible
517
- * images loaded, and finite animations finished. Optional quietMillis requires recorded content
401
+ * images loaded, and finite animations finished. Optional `quiet` requires recorded content
518
402
  * to stay unchanged. Screen or foreground stillness belongs to the Stillness feature.
519
403
  * Fails Timeout after timeout, 15 seconds by default.
520
404
  */
521
405
  readonly ready: (options?: ReadyOptions) => Effect.Effect<void, BrowserError>;
522
-
523
- /**
524
- * Screencast frames for as long as the stream runs. Concurrent streams share one screencast and
525
- * its settings; explicit options that differ from a running screencast's fail with InvalidRequest.
526
- */
527
- readonly screencast: (options?: ScreencastOptions) => Stream.Stream<Frame, BrowserError>;
528
- /**
529
- * What this page's captures received, delivered and dropped, over its life or the latest
530
- * `window`, which reaches back at most a minute; a longer one is an `InvalidRequest`.
531
- */
532
- readonly captureStats: (options?: {
533
- readonly window?: Duration.Input | undefined;
534
- }) => Effect.Effect<CaptureStats, BrowserError>;
535
- /** Screencast frames painted within `frameHistory` of the newest, oldest first. */
536
- readonly recentFrames: Effect.Effect<ReadonlyArray<Frame>>;
537
406
  /** This page's events among the browser's latest `eventHistory`, oldest first. */
538
407
  readonly recentEvents: Effect.Effect<ReadonlyArray<BrowserEvent>>;
539
408
  }
@@ -0,0 +1,72 @@
1
+ /**
2
+ * A page's own time, held and stepped, so what the page does by itself happens at times a caller
3
+ * chooses: a visual test takes a transition at exactly 120 ms, a test skips a 30 second countdown
4
+ * in one step, a recording's page moves one frame's worth per frame however long each takes.
5
+ *
6
+ * A browser opened with `pageTime` runs a page clock in each top document's main world, before
7
+ * the page's own scripts. Until `hold`, it keeps real time. Held, the page's timers and
8
+ * intervals, its animation frames, `performance.now`, `Date.now`, `new Date()` and `Date()`, and
9
+ * its CSS transitions, CSS animations and Web Animations stand still, and each `advance` runs what
10
+ * falls due in time order, each timer at its own time, and then one animation frame at its end.
11
+ * An animation the page starts while held starts at the page time it is held at. Workers, media,
12
+ * `requestIdleCallback`, `MessageChannel`, events' `timeStamp` and frames' own documents keep real
13
+ * time. A clock that has been held is a page script's to notice: it replaces those globals.
14
+ *
15
+ * Loading takes real time: a document that replaces a held one starts on real time, and is held
16
+ * from the next `advance`. When the hold's scope closes, page time carries on from where it was,
17
+ * never back, and what was left of each timer and frame runs in real time. `ready` and stillness
18
+ * count an animation held part way as still running.
19
+ *
20
+ * @stability stable
21
+ * @since 0.3.0
22
+ */
23
+ import type { Duration, Effect, Scope } from "effect";
24
+
25
+ import type { BrowserError } from "./BrowserError.ts";
26
+ import type { Point } from "./internal/geometry.ts";
27
+ import { functionsOf } from "./internal/page/functions.ts";
28
+ import type { Content } from "./Overlay.ts";
29
+ import type { Page } from "./Page.ts";
30
+ import type { Pose } from "./Pose.ts";
31
+
32
+ /**
33
+ * What else changes with page time in the same call to the page.
34
+ *
35
+ * @stability stable
36
+ * @category models
37
+ * @since 0.3.0
38
+ */
39
+ export interface Step {
40
+ /** Scroll the document to this many CSS pixels down it first, at once. */
41
+ readonly scroll?: number | undefined;
42
+ /** Then pose these elements and take the pose off any other, as `Poses.set` does; the page's poses must be open. */
43
+ readonly poses?: ReadonlyArray<Pose> | undefined;
44
+ /** Then show this in the page's overlay, which must be open. */
45
+ readonly overlay?: Content | undefined;
46
+ }
47
+
48
+ /**
49
+ * @stability stable
50
+ * @category models
51
+ * @since 0.3.0
52
+ */
53
+ export interface Held {
54
+ /**
55
+ * Move page time on by `by`, in one call to the page, after the actions asked before it. Says
56
+ * where the document is scrolled to after it.
57
+ */
58
+ readonly advance: (by: Duration.Input, step?: Step) => Effect.Effect<Point, BrowserError>;
59
+ /** How far this hold has moved page time, across the documents it held. */
60
+ readonly elapsed: Effect.Effect<Duration.Duration>;
61
+ }
62
+
63
+ /**
64
+ * Hold the page's own time for the scope, to step it on with `advance`; real time resumes when
65
+ * the scope closes. Needs the browser's `pageTime` option; one hold at a time.
66
+ *
67
+ * @stability stable
68
+ * @category combinators
69
+ * @since 0.3.0
70
+ */
71
+ export const hold = (page: Page): Effect.Effect<Held, BrowserError, Scope.Scope> =>
72
+ functionsOf(page).hold;