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

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 (249) hide show
  1. package/README.md +130 -159
  2. package/dist/Action-24sLOubi.d.mts +110 -0
  3. package/dist/Action.d.mts +2 -0
  4. package/dist/Action.mjs +141 -0
  5. package/dist/Action.mjs.map +1 -0
  6. package/dist/ActionPort.d.mts +15 -0
  7. package/dist/ActionPort.mjs +101 -0
  8. package/dist/ActionPort.mjs.map +1 -0
  9. package/dist/Browser-BKPAbyys.mjs +4076 -0
  10. package/dist/Browser-BKPAbyys.mjs.map +1 -0
  11. package/dist/{Browser-CiXHT1yO.d.mts → Browser-wZhwZSlG.d.mts} +51 -13
  12. package/dist/Browser.d.mts +2 -2
  13. package/dist/Browser.mjs +1 -1
  14. package/dist/{BrowserError-Coy7EW1N.d.mts → BrowserError-BlcmLVzn.d.mts} +22 -7
  15. package/dist/BrowserError.d.mts +2 -2
  16. package/dist/BrowserError.mjs +46 -9
  17. package/dist/BrowserError.mjs.map +1 -1
  18. package/dist/{BrowserEvent-dq6FRT8w.d.mts → BrowserEvent-lLqJ3GJS.d.mts} +93 -37
  19. package/dist/BrowserEvent.d.mts +2 -2
  20. package/dist/BrowserEvent.mjs +29 -24
  21. package/dist/BrowserEvent.mjs.map +1 -1
  22. package/dist/{Change-DqING3tr.d.mts → Change-Ba7INmay.d.mts} +4 -6
  23. package/dist/Change.d.mts +2 -2
  24. package/dist/Change.mjs +97 -2
  25. package/dist/Change.mjs.map +1 -0
  26. package/dist/Clock.d.mts +57 -0
  27. package/dist/Clock.mjs +80 -0
  28. package/dist/Clock.mjs.map +1 -0
  29. package/dist/{Frame-DkNdjjjr.d.mts → Frame-UEH2hO5T.d.mts} +10 -3
  30. package/dist/Frame.d.mts +2 -2
  31. package/dist/Frame.mjs +10 -2
  32. package/dist/Frame.mjs.map +1 -1
  33. package/dist/{Motion-DND6I-64.d.mts → Geometry-DJx9qrYy.d.mts} +7 -10
  34. package/dist/Geometry.d.mts +2 -0
  35. package/dist/Geometry.mjs +32 -0
  36. package/dist/Geometry.mjs.map +1 -0
  37. package/dist/Matching.d.mts +37 -0
  38. package/dist/Matching.mjs +72 -0
  39. package/dist/Matching.mjs.map +1 -0
  40. package/dist/Page-BF5izr8R.mjs +795 -0
  41. package/dist/Page-BF5izr8R.mjs.map +1 -0
  42. package/dist/{Page-ku6j5t-v.d.mts → Page-CvsOEorc.d.mts} +158 -185
  43. package/dist/Page.d.mts +2 -2
  44. package/dist/Page.mjs +1 -1
  45. package/dist/Released-tURbFmal.d.mts +15 -0
  46. package/dist/{Snapshot-B34hZ4Jl.d.mts → Snapshot-CtBVOtuu.d.mts} +6 -1
  47. package/dist/Snapshot.d.mts +1 -1
  48. package/dist/Snapshot.mjs.map +1 -1
  49. package/dist/Stillness-CNlvayIo.mjs +136 -0
  50. package/dist/Stillness-CNlvayIo.mjs.map +1 -0
  51. package/dist/Style-AO4V7Czt.mjs +357 -0
  52. package/dist/Style-AO4V7Czt.mjs.map +1 -0
  53. package/dist/Style.d.mts +72 -0
  54. package/dist/Style.mjs +2 -0
  55. package/dist/Url.d.mts +26 -0
  56. package/dist/Url.mjs +74 -0
  57. package/dist/Url.mjs.map +1 -0
  58. package/dist/Window-CMddGMt1.d.mts +34 -0
  59. package/dist/Window.d.mts +2 -0
  60. package/dist/Window.mjs +35 -0
  61. package/dist/Window.mjs.map +1 -0
  62. package/dist/{cdp-DL7XfEj5.d.mts → connection-2KHI4_KN.d.mts} +4 -4
  63. package/dist/{cdp-BMpYMWYe.mjs → connection-CK83pvqP.mjs} +5 -6
  64. package/dist/connection-CK83pvqP.mjs.map +1 -0
  65. package/dist/index.d.mts +15 -18
  66. package/dist/index.mjs +11 -15
  67. package/dist/moment/Moment.d.mts +86 -0
  68. package/dist/{Moment.mjs → moment/Moment.mjs} +44 -38
  69. package/dist/moment/Moment.mjs.map +1 -0
  70. package/dist/{Plan-DJ4hEEna.d.mts → plan/index.d.mts} +169 -64
  71. package/dist/{Plan-BG1WifW2.mjs → plan/index.mjs} +122 -199
  72. package/dist/plan/index.mjs.map +1 -0
  73. package/dist/{Policy-BGWjbqCl.d.mts → policy/Policy.d.mts} +16 -20
  74. package/dist/{Policy.mjs → policy/Policy.mjs} +11 -21
  75. package/dist/policy/Policy.mjs.map +1 -0
  76. package/dist/presentation/Motion.d.mts +12 -0
  77. package/dist/{Motion.mjs → presentation/Motion.mjs} +4 -27
  78. package/dist/presentation/Motion.mjs.map +1 -0
  79. package/dist/presentation/Presentation.d.mts +30 -0
  80. package/dist/presentation/Presentation.mjs +105 -0
  81. package/dist/presentation/Presentation.mjs.map +1 -0
  82. package/dist/{Stage-NHp8N81k.d.mts → presentation/Stage.d.mts} +12 -15
  83. package/dist/{Stage.mjs → presentation/Stage.mjs} +68 -76
  84. package/dist/presentation/Stage.mjs.map +1 -0
  85. package/dist/presentation/feed.d.mts +20 -0
  86. package/dist/presentation/feed.mjs +18 -0
  87. package/dist/presentation/feed.mjs.map +1 -0
  88. package/dist/providers/Cdp.d.mts +9 -0
  89. package/dist/{Cdp.mjs → providers/Cdp.mjs} +3 -8
  90. package/dist/providers/Cdp.mjs.map +1 -0
  91. package/dist/{Chromium.d.mts → providers/Chromium.d.mts} +6 -7
  92. package/dist/{Chromium.mjs → providers/Chromium.mjs} +6 -15
  93. package/dist/providers/Chromium.mjs.map +1 -0
  94. package/dist/providers/Released.d.mts +2 -0
  95. package/dist/providers/Released.mjs +12 -0
  96. package/dist/providers/Released.mjs.map +1 -0
  97. package/dist/stillness/Stillness.d.mts +12 -0
  98. package/dist/stillness/Stillness.mjs +2 -0
  99. package/dist/supervisor/Supervisor.d.mts +104 -0
  100. package/dist/supervisor/Supervisor.mjs +515 -0
  101. package/dist/supervisor/Supervisor.mjs.map +1 -0
  102. package/dist/testing/index.d.mts +337 -0
  103. package/dist/testing/index.mjs +515 -0
  104. package/dist/testing/index.mjs.map +1 -0
  105. package/dist/workerd/Cdp.d.mts +8 -3
  106. package/dist/workerd/Cdp.mjs +2 -7
  107. package/dist/workerd/Cdp.mjs.map +1 -1
  108. package/package.json +89 -39
  109. package/src/Action.ts +127 -0
  110. package/src/ActionPort.ts +128 -0
  111. package/src/Browser.ts +352 -201
  112. package/src/BrowserError.ts +63 -6
  113. package/src/BrowserEvent.ts +26 -25
  114. package/src/Change.ts +0 -2
  115. package/src/{internal/pictures/clock.ts → Clock.ts} +17 -6
  116. package/src/Frame.ts +14 -0
  117. package/src/Geometry.ts +48 -0
  118. package/src/{internal/reading/match.inpage.ts → Matching.ts} +34 -4
  119. package/src/Page.ts +111 -92
  120. package/src/Snapshot.ts +5 -0
  121. package/src/{internal/input/style.ts → Style.ts} +121 -14
  122. package/src/Window.ts +30 -0
  123. package/src/index.ts +15 -6
  124. package/src/internal/input/actions.ts +61 -119
  125. package/src/internal/input/dispatch.ts +3 -3
  126. package/src/internal/input/gate.ts +21 -18
  127. package/src/internal/input/guard.inpage.ts +25 -58
  128. package/src/internal/input/guard.ts +11 -20
  129. package/src/internal/input/keyboard.ts +12 -3
  130. package/src/internal/input/perform.ts +78 -60
  131. package/src/internal/input/pointer.ts +4 -2
  132. package/src/internal/input/settle.ts +7 -5
  133. package/src/internal/input/targets.inpage.ts +1 -1
  134. package/src/internal/input/targets.ts +4 -9
  135. package/src/internal/page/bridge.ts +209 -113
  136. package/src/internal/page/context.ts +12 -59
  137. package/src/internal/page/dialogs.ts +58 -0
  138. package/src/internal/page/identity.ts +6 -5
  139. package/src/internal/page/lane.ts +14 -15
  140. package/src/internal/page/navigation.ts +50 -42
  141. package/src/internal/page/openings.ts +11 -5
  142. package/src/internal/page/page.ts +44 -81
  143. package/src/internal/page/port.ts +125 -0
  144. package/src/internal/{input → page}/replies.ts +1 -1
  145. package/src/internal/page/request-owner.ts +269 -0
  146. package/src/internal/page/requests.ts +357 -0
  147. package/src/internal/page/scripts.ts +124 -0
  148. package/src/internal/pictures/capture.ts +255 -332
  149. package/src/internal/pictures/dimensions.ts +162 -0
  150. package/src/internal/pictures/frame.ts +68 -0
  151. package/src/internal/pictures/pictures.ts +57 -23
  152. package/src/internal/pictures/quiescence.ts +1 -1
  153. package/src/internal/pictures/state.ts +26 -0
  154. package/src/internal/pictures/transport.ts +21 -4
  155. package/src/internal/reading/controls.inpage.ts +5 -70
  156. package/src/internal/reading/expect.inpage.ts +13 -17
  157. package/src/internal/reading/names.inpage.ts +89 -45
  158. package/src/internal/reading/outline.inpage.ts +6 -7
  159. package/src/internal/reading/reading.ts +144 -176
  160. package/src/internal/reading/ready.inpage.ts +6 -17
  161. package/src/internal/reading/ready.ts +13 -135
  162. package/src/internal/reading/subjects.inpage.ts +83 -43
  163. package/src/internal/reading/walk.inpage.ts +33 -13
  164. package/src/internal/timeline/changes.ts +55 -6
  165. package/src/internal/timeline/events.ts +15 -5
  166. package/src/internal/timeline/history.inpage.ts +1 -1
  167. package/src/internal/timeline/record.inpage.ts +4 -1
  168. package/src/internal/timeline/window.ts +2 -1
  169. package/src/{Moment.ts → moment/Moment.ts} +13 -31
  170. package/src/{internal/timeline → moment}/words.ts +2 -2
  171. package/src/{internal/reading → plan}/choose.ts +3 -3
  172. package/src/plan/data.ts +117 -0
  173. package/src/plan/execute.ts +411 -0
  174. package/src/plan/index.ts +36 -0
  175. package/src/plan/record.ts +71 -0
  176. package/src/plan/targets.ts +71 -0
  177. package/src/{Policy.ts → policy/Policy.ts} +13 -10
  178. package/src/{Motion.ts → presentation/Motion.ts} +12 -46
  179. package/src/presentation/Presentation.ts +176 -0
  180. package/src/{Stage.ts → presentation/Stage.ts} +147 -112
  181. package/src/presentation/feed.ts +21 -0
  182. package/src/{Cdp.ts → providers/Cdp.ts} +2 -2
  183. package/src/{Chromium.ts → providers/Chromium.ts} +7 -10
  184. package/src/providers/Released.ts +13 -0
  185. package/src/{internal/cdp.ts → providers/connection.ts} +2 -2
  186. package/src/{internal/pictures/motion.ts → stillness/Pixels.ts} +1 -1
  187. package/src/stillness/Stillness.ts +166 -0
  188. package/src/supervisor/Supervisor.ts +170 -0
  189. package/src/supervisor/contract.ts +105 -0
  190. package/src/supervisor/lifecycle.ts +272 -0
  191. package/src/supervisor/runtime.ts +238 -0
  192. package/src/testing/TestBrowser.ts +115 -0
  193. package/src/testing/TestPage.ts +10 -0
  194. package/src/testing/evidence.ts +154 -0
  195. package/src/testing/index.ts +3 -0
  196. package/src/testing/model.ts +222 -0
  197. package/src/testing/page.ts +360 -0
  198. package/src/workerd/Cdp.ts +2 -2
  199. package/dist/Browser-CxXUjxOp.mjs +0 -619
  200. package/dist/Browser-CxXUjxOp.mjs.map +0 -1
  201. package/dist/Cdp-CzCRnMlM.d.mts +0 -10
  202. package/dist/Cdp.d.mts +0 -11
  203. package/dist/Cdp.mjs.map +0 -1
  204. package/dist/Change-DNvztNLu.mjs +0 -138
  205. package/dist/Change-DNvztNLu.mjs.map +0 -1
  206. package/dist/Chromium.mjs.map +0 -1
  207. package/dist/Expect-u3P_ENLX.d.mts +0 -62
  208. package/dist/Expect.d.mts +0 -2
  209. package/dist/Expect.mjs +0 -114
  210. package/dist/Expect.mjs.map +0 -1
  211. package/dist/Moment.d.mts +0 -2
  212. package/dist/Moment.mjs.map +0 -1
  213. package/dist/Motion.d.mts +0 -2
  214. package/dist/Motion.mjs.map +0 -1
  215. package/dist/Page-BP02bmNv.mjs +0 -264
  216. package/dist/Page-BP02bmNv.mjs.map +0 -1
  217. package/dist/Plan-BG1WifW2.mjs.map +0 -1
  218. package/dist/Plan.d.mts +0 -2
  219. package/dist/Plan.mjs +0 -2
  220. package/dist/Policy.d.mts +0 -2
  221. package/dist/Policy.mjs.map +0 -1
  222. package/dist/Presentation-DxVikn9_.d.mts +0 -48
  223. package/dist/Presentation.d.mts +0 -2
  224. package/dist/Presentation.mjs +0 -118
  225. package/dist/Presentation.mjs.map +0 -1
  226. package/dist/Stage.d.mts +0 -2
  227. package/dist/Stage.mjs.map +0 -1
  228. package/dist/Supervisor-2mPjIYYs.mjs +0 -676
  229. package/dist/Supervisor-2mPjIYYs.mjs.map +0 -1
  230. package/dist/Supervisor-CfRxbaso.d.mts +0 -317
  231. package/dist/Supervisor.d.mts +0 -2
  232. package/dist/Supervisor.mjs +0 -2
  233. package/dist/cdp-BMpYMWYe.mjs.map +0 -1
  234. package/dist/context-EGhOqjNN.mjs +0 -335
  235. package/dist/context-EGhOqjNN.mjs.map +0 -1
  236. package/dist/page-PTM8m5wC.mjs +0 -4057
  237. package/dist/page-PTM8m5wC.mjs.map +0 -1
  238. package/dist/url-Bsp2y55M.mjs +0 -264
  239. package/dist/url-Bsp2y55M.mjs.map +0 -1
  240. package/dist/workerd/index.d.mts +0 -16
  241. package/dist/workerd/index.mjs +0 -17
  242. package/src/Expect.ts +0 -180
  243. package/src/Plan.ts +0 -674
  244. package/src/Presentation.ts +0 -196
  245. package/src/Supervisor.ts +0 -632
  246. package/src/internal/supervisor/lifecycle.ts +0 -484
  247. package/src/workerd/index.ts +0 -17
  248. /package/src/{internal/page/url.ts → Url.ts} +0 -0
  249. /package/src/{internal/pictures → stillness}/utilsBundle.d.ts +0 -0
@@ -4,13 +4,52 @@
4
4
  * beside it. See `names.inpage.ts` for what a page-side part may use.
5
5
  */
6
6
  import type { SubjectContext } from "../../BrowserEvent.ts";
7
+ import type { FindRequest, Match } from "../../Matching.ts";
7
8
  import type { ContextReader } from "./context.inpage.ts";
8
- import type { FindRequest, Match } from "./match.inpage.ts";
9
9
  import type { Names } from "./names.inpage.ts";
10
10
  import type { Walk } from "./walk.inpage.ts";
11
11
 
12
- export const subjects = (names: Names, walked: Walk, matching: Match, placing: ContextReader) => {
13
- const { isDisabled, isInput, nameOf, refFor, refs, roleOf, textOf } = names;
12
+ export const states = (names: Names) => (element: Element, role: string | null) => {
13
+ const { isDisabled, isInput } = names;
14
+
15
+ // A state the page gives either way, or none.
16
+ const given = (attribute: string) => {
17
+ const value = element.getAttribute(attribute);
18
+
19
+ return value === "true" || (value === "false" ? false : undefined);
20
+ };
21
+
22
+ const checkable =
23
+ element.hasAttribute("aria-checked") ||
24
+ ["checkbox", "radio", "switch", "menuitemcheckbox", "menuitemradio"].includes(role ?? "");
25
+
26
+ // In the order the outline shows them.
27
+ return {
28
+ disabled: isDisabled(element),
29
+ checked: checkable
30
+ ? (isInput(element) && element.checked) || element.getAttribute("aria-checked") === "true"
31
+ : undefined,
32
+ expanded: given("aria-expanded"),
33
+ selected: given("aria-selected"),
34
+ pressed: given("aria-pressed"),
35
+ focused: element.ownerDocument.activeElement === element,
36
+ level:
37
+ role === "heading"
38
+ ? Number(element.getAttribute("aria-level")) ||
39
+ Number(/^H([1-6])$/.exec(element.tagName)?.[1]) ||
40
+ 2
41
+ : undefined,
42
+ };
43
+ };
44
+
45
+ export const subjects = (
46
+ names: Names,
47
+ walked: Walk,
48
+ matching: Match,
49
+ placing: ContextReader,
50
+ stateOf: ReturnType<typeof states>,
51
+ ) => {
52
+ const { isDisabled, nameOf, refFor, roleOf, textOf } = names;
14
53
  const { acts, boxOf, controlOf, hitAt, inView } = walked;
15
54
  const { contextOf, known } = placing;
16
55
 
@@ -25,37 +64,6 @@ export const subjects = (names: Names, walked: Walk, matching: Match, placing: C
25
64
  acts(element, role) ||
26
65
  (style.cursor === "pointer" && !insidePointer && rect.width > 0 && rect.height > 0);
27
66
 
28
- const stateOf = (element: Element, role: string | null) => {
29
- // A state the page gives either way, or none.
30
- const given = (attribute: string) => {
31
- const value = element.getAttribute(attribute);
32
-
33
- return value === "true" || (value === "false" ? false : undefined);
34
- };
35
-
36
- const checkable =
37
- element.hasAttribute("aria-checked") ||
38
- ["checkbox", "radio", "switch", "menuitemcheckbox", "menuitemradio"].includes(role ?? "");
39
-
40
- // In the order the outline shows them.
41
- return {
42
- disabled: isDisabled(element),
43
- checked: checkable
44
- ? (isInput(element) && element.checked) || element.getAttribute("aria-checked") === "true"
45
- : undefined,
46
- expanded: given("aria-expanded"),
47
- selected: given("aria-selected"),
48
- pressed: given("aria-pressed"),
49
- focused: element.ownerDocument.activeElement === element,
50
- level:
51
- role === "heading"
52
- ? Number(element.getAttribute("aria-level")) ||
53
- Number(/^H([1-6])$/.exec(element.tagName)?.[1]) ||
54
- 2
55
- : undefined,
56
- };
57
- };
58
-
59
67
  /**
60
68
  * The elements in scope that match a query, in tree order. Without text, an element matches
61
69
  * when it has a role or is a control. With text, any element can, but text inside a control or
@@ -69,6 +77,18 @@ export const subjects = (names: Names, walked: Walk, matching: Match, placing: C
69
77
  const viewport = request.scope === "viewport";
70
78
  const read = known();
71
79
 
80
+ if (request.selector !== null) {
81
+ try {
82
+ document.querySelector(request.selector);
83
+ } catch {
84
+ return { invalid: `${JSON.stringify(request.selector)} is not a CSS selector` };
85
+ }
86
+ }
87
+
88
+ const eligible = (element: Element) =>
89
+ (request.selector === null || element.matches(request.selector)) &&
90
+ (request.state !== "enabled" || !isDisabled(element));
91
+
72
92
  interface Entry {
73
93
  readonly element: Element;
74
94
  readonly rect: DOMRect;
@@ -103,9 +123,15 @@ export const subjects = (names: Names, walked: Walk, matching: Match, placing: C
103
123
  const element = controlOf(hit);
104
124
  const { x, y, width, height } = boxOf(element);
105
125
  const rect = new DOMRect(x, y, width, height);
106
- const entry: Entry = { element, rect, role: roleOf(element), matched: false };
107
126
 
108
- entry.matched = judge(entry, () => textOf(element));
127
+ const entry: Entry = {
128
+ element,
129
+ rect,
130
+ role: roleOf(element, request.role !== null),
131
+ matched: false,
132
+ };
133
+
134
+ entry.matched = eligible(element) && judge(entry, () => textOf(element));
109
135
  entries.push(entry);
110
136
  }
111
137
  if (at === null)
@@ -115,10 +141,15 @@ export const subjects = (names: Names, walked: Walk, matching: Match, placing: C
115
141
  { pointer: false, owned: false },
116
142
  {
117
143
  enter: (element, style, rect, state) => {
118
- const role = roleOf(element);
144
+ const role = roleOf(element, request.role !== null);
119
145
  const control = isControl(element, role, style, rect, state.pointer);
120
146
  const unit = control || role === "heading";
121
- const candidate = byText ? unit || !state.owned : role !== null || control;
147
+
148
+ const candidate =
149
+ eligible(element) &&
150
+ (byText
151
+ ? unit || !state.owned
152
+ : request.selector !== null || role !== null || control);
122
153
 
123
154
  const entry =
124
155
  candidate && (!viewport || inView(rect))
@@ -154,8 +185,10 @@ export const subjects = (names: Names, walked: Walk, matching: Match, placing: C
154
185
  };
155
186
 
156
187
  const find = (request: FindRequest) => {
157
- if (refs.next < request.firstRef) refs.next = request.firstRef;
158
- const { entries, named, placed } = matched(request);
188
+ const result = matched(request);
189
+
190
+ if (result.invalid !== undefined) return { invalid: result.invalid };
191
+ const { entries, named, placed } = result;
159
192
 
160
193
  const found = entries.map((entry) => ({
161
194
  ref: refFor(entry.element),
@@ -175,12 +208,19 @@ export const subjects = (names: Names, walked: Walk, matching: Match, placing: C
175
208
  state: stateOf(entry.element, entry.role),
176
209
  }));
177
210
 
178
- return { found, nextRef: refs.next };
211
+ return { found };
179
212
  };
180
213
 
181
214
  /** The elements `find` would find, in tree order, with no refs given. */
182
- const elementsOf = (request: FindRequest) =>
183
- matched(request).entries.map((entry) => entry.element);
215
+ const elementsOf = (
216
+ request: FindRequest,
217
+ ): ReadonlyArray<Element> | { readonly invalid: string } => {
218
+ const result = matched(request);
219
+
220
+ return result.invalid !== undefined
221
+ ? { invalid: result.invalid }
222
+ : result.entries.map((entry) => entry.element);
223
+ };
184
224
 
185
225
  return { find, elementsOf, isControl, stateOf };
186
226
  };
@@ -30,7 +30,7 @@ export interface Visitor<S> {
30
30
  }
31
31
 
32
32
  export const walk = (names: Names) => {
33
- const { interactiveRoles, isElement, isFrame, parentOf, roleOf } = names;
33
+ const { interactiveRoles, isElement, isFrame, isInput, parentOf, roleOf } = names;
34
34
 
35
35
  const skipped = new Set("SCRIPT STYLE NOSCRIPT TEMPLATE HEAD META LINK SVG".split(" "));
36
36
 
@@ -39,16 +39,24 @@ export const walk = (names: Names) => {
39
39
  rect.right > 0 && rect.bottom > 0 && rect.left < width && rect.top < height;
40
40
 
41
41
  /** Whether an element reached on its own shows, by the walk's rule and its ancestors'. */
42
- const visible = (element: Element): boolean =>
43
- element.checkVisibility({ opacityProperty: true, visibilityProperty: true }) &&
44
- element.closest("[aria-hidden=true]") === null;
42
+ const visible = (element: Element): boolean => {
43
+ if (element.closest("[aria-hidden=true]") !== null) return false;
44
+ if (element.checkVisibility({ opacityProperty: true, visibilityProperty: true })) return true;
45
+ // A contents element has no box of its own, but its text and descendants can paint.
46
+ if (getComputedStyle(element).display !== "contents") return false;
47
+ for (let node: Element | null = element; node !== null; node = parentOf(node)) {
48
+ const style = getComputedStyle(node);
45
49
 
46
- const isVisible = (element: Element, style: CSSStyleDeclaration, rect: DOMRect): boolean =>
47
- style.display !== "none" &&
48
- style.visibility === "visible" &&
49
- style.opacity !== "0" &&
50
- element.getAttribute("aria-hidden") !== "true" &&
51
- (rect.width > 0 || rect.height > 0 || style.display === "contents");
50
+ if (
51
+ style.display === "none" ||
52
+ style.opacity === "0" ||
53
+ (node === element && style.visibility !== "visible")
54
+ )
55
+ return false;
56
+ }
57
+
58
+ return true;
59
+ };
52
60
 
53
61
  // Coordinate subtraction is valid only for an untransformed frame. Report the frame itself
54
62
  // otherwise: the real pixel input still works, and its receipt must not name a guessed child.
@@ -102,6 +110,7 @@ export const walk = (names: Names) => {
102
110
 
103
111
  /** Whether its role or a click handler makes an element a control. */
104
112
  const acts = (element: Element, role: string | null): boolean =>
113
+ (isInput(element) && element.type !== "hidden") ||
105
114
  (role !== null && (interactiveRoles.has(role) || role === "canvas" || role === "iframe")) ||
106
115
  element.hasAttribute("onclick");
107
116
 
@@ -162,8 +171,7 @@ export const walk = (names: Names) => {
162
171
  * a subtree outside the viewport is skipped, as described above.
163
172
  */
164
173
  const visit = <S>(root: Element | null, viewport: boolean, state: S, visitor: Visitor<S>) => {
165
- const width = window.innerWidth;
166
- const height = window.innerHeight;
174
+ const { innerWidth: width, innerHeight: height } = window;
167
175
  let keep: Set<Element> | undefined;
168
176
 
169
177
  const children = (parent: ParentNode, inner: S, dx: number, dy: number) => {
@@ -195,7 +203,19 @@ export const walk = (names: Names) => {
195
203
  }
196
204
  const style = getComputedStyle(element);
197
205
 
198
- if (!isVisible(element, style, local)) return;
206
+ if (
207
+ style.display === "none" ||
208
+ style.opacity === "0" ||
209
+ element.getAttribute("aria-hidden") === "true"
210
+ )
211
+ return;
212
+ // Visibility can be overridden by a child, and zero-size wrappers can hold painted
213
+ // descendants. Traverse those wrappers without attributing their hidden text to a read.
214
+ if (!visible(element)) {
215
+ for (const child of Array.from(element.children)) one(child, outer, dx, dy);
216
+
217
+ return;
218
+ }
199
219
  const inner = visitor.enter(element, style, rect, outer);
200
220
 
201
221
  if (inner === undefined) return;
@@ -1,22 +1,22 @@
1
1
  /**
2
- * Reading a page's record of what changed, in one call to the page. The first read also registers
3
- * the recorder with the page's own session, in the same round trip, so that every later document
4
- * records from its start. The page's times map to the owner's clock through the browser's one
2
+ * Reading a page's record of what changed. The first read also registers the recorder with the
3
+ * page's own session so that every later document records from its start, until the idle lifetime
4
+ * expires. The page's times map to the owner's clock through the browser's one
5
5
  * clock mapping, as frames' do, which a browser's first read measures, once, where no capture has;
6
6
  * and a window can begin on the page's own clock where the previous one ended, so consecutive
7
7
  * reads neither miss nor repeat a change. A read takes its turn on the page as other reads do, and
8
8
  * identical ones in flight share it; none is kept for a later caller, since its window ends when
9
9
  * it was read.
10
10
  */
11
- import { Effect, Schema } from "effect";
11
+ import { Clock, Duration, Effect, type Fiber, Schema, Semaphore } from "effect";
12
12
 
13
13
  import type { BrowserError } from "../../BrowserError.ts";
14
14
  import { Change, Changes } from "../../Change.ts";
15
+ import * as BrowserClock from "../../Clock.ts";
15
16
  import type { Frame } from "../../Frame.ts";
16
17
  import type { ChangesOptions } from "../../Page.ts";
17
18
  import { type Bridge, scriptCall } from "../page/bridge.ts";
18
19
  import { decodeWith, type PageContext } from "../page/context.ts";
19
- import * as BrowserClock from "../pictures/clock.ts";
20
20
  import { type ChangesRequest, ChangesResultSchema } from "./changes.inpage.ts";
21
21
 
22
22
  const isChanges = Schema.is(Changes);
@@ -35,6 +35,55 @@ export const make = (
35
35
  estimate: Effect.Effect<BrowserClock.Estimate, BrowserError>,
36
36
  ) => {
37
37
  const reads = page.lane.shared<Changes>("changes", false);
38
+ const recording = Semaphore.makeUnsafe(1);
39
+ const idleMillis = 120_000;
40
+ let readAt = Number.NEGATIVE_INFINITY;
41
+ let lifetime: Fiber.Fiber<void, BrowserError> | undefined;
42
+ let expired: BrowserError | undefined;
43
+
44
+ const expiry: Effect.Effect<void, BrowserError> = Effect.suspend(() => {
45
+ const left = readAt + idleMillis - page.now();
46
+
47
+ if (left > 0) return Effect.sleep(Duration.millis(left)).pipe(Effect.andThen(expiry));
48
+
49
+ return recording
50
+ .withPermits(1)(
51
+ Effect.suspend(() => {
52
+ if (page.now() < readAt + idleMillis) return Effect.void;
53
+
54
+ return bridge.unregisterRecorder("changes").pipe(
55
+ page.within("changes"),
56
+ Effect.ensuring(
57
+ Effect.sync(() => {
58
+ lifetime = undefined;
59
+ }),
60
+ ),
61
+ );
62
+ }),
63
+ )
64
+ .pipe(
65
+ // Idle cleanup can wait for the page; its native work is bounded once admitted.
66
+ page.lane.read("changes", Duration.infinity),
67
+ Effect.andThen(Effect.suspend(() => (lifetime === undefined ? Effect.void : expiry))),
68
+ );
69
+ });
70
+
71
+ const register = recording.withPermits(1)(
72
+ Effect.gen(function* () {
73
+ if (expired !== undefined) return yield* expired;
74
+ readAt = page.now();
75
+ yield* bridge.registerRecorder("changes");
76
+ lifetime ??= yield* expiry.pipe(
77
+ Effect.tapError((error) =>
78
+ Effect.sync(() => {
79
+ expired = error;
80
+ }),
81
+ ),
82
+ Effect.provideService(Clock.Clock, page.clock),
83
+ Effect.forkIn(page.scope),
84
+ );
85
+ }),
86
+ );
38
87
 
39
88
  return (options: ChangesOptions = {}) =>
40
89
  reads(
@@ -62,7 +111,7 @@ export const make = (
62
111
 
63
112
  const [, result] = yield* Effect.all(
64
113
  [
65
- bridge.registerRecorder("changes"),
114
+ register,
66
115
  bridge
67
116
  .evaluate("changes", scriptCall("changes", request))
68
117
  .pipe(Effect.flatMap(decodeWith("changes", ChangesResultSchema))),
@@ -10,7 +10,9 @@ import { refuse, undispatched } from "../page/context.ts";
10
10
 
11
11
  /** The owning Browser validates capacity and closes this timeline with its scope. */
12
12
  export const make = (capacity: number) => {
13
- let records: ReadonlyArray<RecordedEvent> = [];
13
+ const records = Array.from<RecordedEvent | undefined>({ length: capacity });
14
+ let start = 0;
15
+ let size = 0;
14
16
  let sequence = 0;
15
17
  let closed = false;
16
18
  let changed = Deferred.makeUnsafe<void>();
@@ -28,7 +30,9 @@ export const make = (capacity: number) => {
28
30
  sequence += 1;
29
31
  const recorded = new RecordedEvent({ sequence, event });
30
32
 
31
- records = records.length < capacity ? [...records, recorded] : [...records.slice(1), recorded];
33
+ records[(start + size) % capacity] = recorded;
34
+ if (size < capacity) size++;
35
+ else start = (start + 1) % capacity;
32
36
  wake();
33
37
 
34
38
  return sequence;
@@ -51,14 +55,16 @@ export const make = (capacity: number) => {
51
55
  return Stream.fromEffectRepeat(
52
56
  Effect.gen(function* () {
53
57
  while (true) {
54
- const oldest = records[0]?.sequence ?? sequence + 1;
58
+ const oldest = sequence - size + 1;
55
59
 
56
60
  if (cursor < oldest - 1)
57
61
  return yield* undispatched(
58
62
  "events",
59
63
  new EventHistoryExpired({ after: cursor, oldest, latest: sequence }),
60
64
  );
61
- const next = records[cursor - oldest + 1];
65
+
66
+ const next =
67
+ cursor < sequence ? records[(start + cursor - oldest + 1) % capacity] : undefined;
62
68
 
63
69
  if (next !== undefined) {
64
70
  cursor = next.sequence;
@@ -80,7 +86,11 @@ export const make = (capacity: number) => {
80
86
  return {
81
87
  publish,
82
88
  sequence: () => sequence,
83
- recent: Effect.sync(() => records),
89
+ recent: Effect.sync(() =>
90
+ Array.from({ length: size }, (_, index) => records[(start + index) % capacity]).filter(
91
+ (record): record is RecordedEvent => record !== undefined,
92
+ ),
93
+ ),
84
94
  stream,
85
95
  close: Effect.sync(() => {
86
96
  if (closed) return;
@@ -180,7 +180,7 @@ export const history = (
180
180
  /** When something in view last changed, or something not yet judged; for a wait for stillness. */
181
181
  const changing = (): number =>
182
182
  Math.max(
183
- Number.NEGATIVE_INFINITY,
183
+ begun ?? Number.NEGATIVE_INFINITY,
184
184
  ...Array.from(
185
185
  tracks.values(),
186
186
  (track) =>
@@ -67,7 +67,8 @@ export const record = (
67
67
  const target = targetOf(event);
68
68
 
69
69
  if (!event.isTrusted || target === undefined) return;
70
- inputs.push({ at: performance.timeOrigin + event.timeStamp, target });
70
+ // Protocol timestamps are mapped estimates; observation and mutations share this clock.
71
+ inputs.push({ at: epoch(), target });
71
72
  if (inputs.length > 8) inputs.shift();
72
73
  };
73
74
 
@@ -83,6 +84,7 @@ export const record = (
83
84
 
84
85
  const stop = () => {
85
86
  running = false;
87
+ document.removeEventListener("DOMContentLoaded", begin);
86
88
  observer.disconnect();
87
89
  for (const [type, listener] of listeners) document.removeEventListener(type, listener, options);
88
90
  seeing.clear();
@@ -117,6 +119,7 @@ export const record = (
117
119
  };
118
120
 
119
121
  return {
122
+ stop,
120
123
  /** Record from now, once the document is parsed; each read keeps the record going. */
121
124
  start: () => {
122
125
  lastRead = epoch();
@@ -9,11 +9,12 @@ import type { BrowserError } from "../../BrowserError.ts";
9
9
  import { type BrowserEvent, TrackEvent } from "../../BrowserEvent.ts";
10
10
  import type { Changes } from "../../Change.ts";
11
11
  import { Frame } from "../../Frame.ts";
12
- import { Window } from "../../Moment.ts";
13
12
  import type { ChangesOptions, WindowOptions } from "../../Page.ts";
13
+ import { Window } from "../../Window.ts";
14
14
  import { type PageContext, refuse } from "../page/context.ts";
15
15
 
16
16
  const isWindow = Schema.is(Window);
17
+
17
18
  const isFrame = Schema.is(Frame);
18
19
  const isTrackEvent = Schema.is(TrackEvent);
19
20
 
@@ -27,37 +27,16 @@
27
27
  import { Duration, Effect, Option, Result, Schema } from "effect";
28
28
  import { Prompt } from "effect/ai";
29
29
 
30
- import { BrowserError } from "./BrowserError.ts";
31
- import { type Action, BrowserEvent } from "./BrowserEvent.ts";
32
- import { type Change, Changes } from "./Change.ts";
33
- import { Frame } from "./Frame.ts";
34
- import { refuse } from "./internal/page/context.ts";
35
- import { describe, named, quoted, where } from "./internal/timeline/words.ts";
36
- import type * as Page from "./Page.ts";
37
- import { Snapshot, type SnapshotOptions } from "./Snapshot.ts";
38
-
39
- /** A page's events, changes and frames over one window of its browser's host clock. */
40
- export class Window extends Schema.Class<Window>("effect-browser/Window")({
41
- page: Schema.String,
42
- /** Where the window starts, in host monotonic milliseconds on the owning browser’s clock. */
43
- since: Schema.Finite,
44
- /** Where it ends, never after it was taken. */
45
- until: Schema.Finite,
46
- /** The page's events after `since`, up to `until`, oldest first, without the input presentation track. */
47
- events: Schema.Array(BrowserEvent),
48
- /**
49
- * What visibly changed after `since`, up to `until`; absent where `missing` says why. A page's
50
- * first window starts its record, so the record sees none of it.
51
- */
52
- changes: Schema.optional(Changes),
53
- /** Screencast frames painted from `since` to `until`, oldest first, as far back as kept. */
54
- frames: Schema.Array(Frame),
55
- /**
56
- * Why each part that could not be read is missing: the read of its changes, by whatever
57
- * operation failed there, or a moment's picture (`frame`) or outline (`snapshot`).
58
- */
59
- missing: Schema.Array(BrowserError),
60
- }) {}
30
+ import { refuse } from "../BrowserError.ts";
31
+ import { type Action } from "../BrowserEvent.ts";
32
+ import { type Change, type Changes } from "../Change.ts";
33
+ import { type Frame } from "../Frame.ts";
34
+ import type * as Page from "../Page.ts";
35
+ import { Snapshot, type SnapshotOptions } from "../Snapshot.ts";
36
+ import { describe, named, quoted, where } from "./words.ts";
37
+
38
+ export { Window } from "../Window.ts";
39
+ import { Window } from "../Window.ts";
61
40
 
62
41
  /**
63
42
  * A window that ends at a picture of the page, its last frame, unless `missing` says why it has
@@ -485,3 +464,6 @@ export const toPrompt = (moment: Moment): Prompt.Prompt => {
485
464
  }),
486
465
  ]);
487
466
  };
467
+
468
+ /** Describe one change using the same prose as moment prompts. */
469
+ export { describe as describeChange } from "./words.ts";
@@ -2,8 +2,8 @@
2
2
  * What changed on a page, in words for a model: a change with where it is, and what it is. A moment
3
3
  * tells its changes this way, and a tool's receipt the changes its action caused.
4
4
  */
5
- import type { Subject, SubjectContext } from "../../BrowserEvent.ts";
6
- import type { Change } from "../../Change.ts";
5
+ import type { Subject, SubjectContext } from "../BrowserEvent.ts";
6
+ import type { Change } from "../Change.ts";
7
7
 
8
8
  export const quoted = (value: string | undefined) => JSON.stringify(value ?? "");
9
9
 
@@ -15,9 +15,9 @@
15
15
  */
16
16
  import { Effect, Schema } from "effect";
17
17
 
18
- import type { Subject, SubjectContext } from "../../BrowserEvent.ts";
19
- import type { Found } from "../../Page.ts";
20
- import { match } from "./match.inpage.ts";
18
+ import type { Subject, SubjectContext } from "../BrowserEvent.ts";
19
+ import { match } from "../Matching.ts";
20
+ import type { Found } from "../Page.ts";
21
21
 
22
22
  /** Nothing on the page has the step's role and name. */
23
23
  export class Missing extends Schema.TaggedError<Missing>()("Missing", {}) {
@@ -0,0 +1,117 @@
1
+ /** Serializable plan steps, expected effects, receipts and durable stopping evidence. */
2
+ import { Schema } from "effect";
3
+
4
+ import { Action } from "../Action.ts";
5
+ import { BrowserError } from "../BrowserError.ts";
6
+ import { Box, Subject } from "../BrowserEvent.ts";
7
+ import { Ambiguous, Drifted, Missing } from "./choose.ts";
8
+
9
+ /** Reuse the execution variants; recorded code has no serializable replay capability. */
10
+ const ReplayAction = Action.pipe(
11
+ Schema.refine(
12
+ (value): value is Exclude<Action, { readonly _tag: "Act" }> => value._tag !== "Act",
13
+ ),
14
+ );
15
+
16
+ const Query = Schema.Struct({
17
+ role: Schema.optional(Schema.String),
18
+ name: Schema.optional(Schema.String),
19
+ text: Schema.optional(Schema.String),
20
+ });
21
+
22
+ /**
23
+ * What a step leaves. `durable` asserts an author-chosen, lasting read-back of this operation,
24
+ * such as its uniquely named saved receipt or exact operation URL. Only Appeared and an exact
25
+ * Navigated URL allow it; a toast, absence or relative navigation cannot establish recovery.
26
+ * Relative navigation measures observed change from dispatch, without asserting causality.
27
+ */
28
+ export const Expected = Schema.Union([
29
+ Schema.TaggedStruct("Checked", { checked: Schema.Boolean }),
30
+ Schema.TaggedStruct("Appeared", {
31
+ query: Query,
32
+ durable: Schema.optional(Schema.Literal(true)),
33
+ }),
34
+ Schema.TaggedStruct("Gone", {
35
+ query: Query,
36
+ durable: Schema.optional(Schema.Never),
37
+ }),
38
+ Schema.TaggedStruct("Navigated", {
39
+ url: Schema.String,
40
+ durable: Schema.optional(Schema.Literal(true)),
41
+ }),
42
+ Schema.TaggedStruct("Navigated", {
43
+ url: Schema.optional(Schema.Never),
44
+ durable: Schema.optional(Schema.Never),
45
+ }),
46
+ ]);
47
+
48
+ export type Expected = typeof Expected.Type;
49
+
50
+ /** One recorded step: the action, what it acted on, and what else it was asked. */
51
+ export class Step extends Schema.Class<Step>("effect-browser/Plan/Step")({
52
+ action: ReplayAction,
53
+ /** The address reached, including a delayed navigation before the next action began. */
54
+ url: Schema.String,
55
+ subject: Schema.optional(Subject),
56
+ /** Where a drag ended. */
57
+ to: Schema.optional(Subject),
58
+ /** The recorded box keeps a point at the same relative position within its subject. */
59
+ box: Schema.optional(Box),
60
+ /** A slot replaces recorded typing text or a navigation address with withheld credentials. */
61
+ input: Schema.optional(Schema.String),
62
+ expect: Schema.optional(Expected),
63
+ }) {}
64
+
65
+ export class Plan extends Schema.Class<Plan>("effect-browser/Plan")({
66
+ version: Schema.Literal(3),
67
+ steps: Schema.Array(Step),
68
+ }) {
69
+ /** Version 3 carries canonical typed Actions; prior string-action encodings are rejected. */
70
+ static new(steps: ReadonlyArray<Step>): Plan {
71
+ return new Plan({ version: 3, steps });
72
+ }
73
+
74
+ /** The input slots its steps type, in order; replay needs text for each. */
75
+ get inputs(): ReadonlyArray<string> {
76
+ return this.steps.flatMap((step) => (step.input === undefined ? [] : [step.input]));
77
+ }
78
+ }
79
+
80
+ /** One completed step, on the page's host clock. `verified` means its expected effect was seen. */
81
+ export class Receipt extends Schema.Class<Receipt>("effect-browser/Plan/Receipt")({
82
+ step: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),
83
+ outcome: Schema.Literals(["taken", "verified", "skipped"]),
84
+ startedAt: Schema.Finite,
85
+ at: Schema.Finite,
86
+ }) {}
87
+
88
+ /** Durable stopping data. A begun step without a receipt must be restored as `unknown`. */
89
+ export class Stopped extends Schema.Class<Stopped>("effect-browser/Plan/Stopped")({
90
+ step: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),
91
+ input: Schema.Literals(["unsent", "unknown"]),
92
+ }) {}
93
+
94
+ /** Repeating this step could repeat an unresolved effect; the consumer must reconcile it. */
95
+ export class Uncertain extends Schema.TaggedError<Uncertain>()("Uncertain", {
96
+ detail: Schema.String,
97
+ }) {
98
+ override get message() {
99
+ return this.detail;
100
+ }
101
+ }
102
+
103
+ /** Where replay stopped, counting steps from 0, why, and the steps that completed before it. */
104
+ export class ReplayError extends Schema.TaggedError<ReplayError>()("ReplayError", {
105
+ step: Schema.Int,
106
+ reason: Schema.Union([Missing, Ambiguous, Drifted, BrowserError, Uncertain]),
107
+ input: Schema.Literals(["unsent", "unknown"]),
108
+ receipts: Schema.Array(Receipt),
109
+ }) {
110
+ get stopped(): Stopped {
111
+ return new Stopped({ step: this.step, input: this.input });
112
+ }
113
+
114
+ override get message() {
115
+ return `step ${this.step} failed: ${this.reason.message}`;
116
+ }
117
+ }