effect-browser 0.3.0-beta.22 → 0.3.0-beta.24

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 (138) hide show
  1. package/README.md +124 -5
  2. package/dist/ActionPort.d.mts +1 -1
  3. package/dist/ActionPort.mjs +1 -1
  4. package/dist/{Browser-Cq2K1FEA.mjs → Browser-CAQFhTkM.mjs} +561 -334
  5. package/dist/Browser-CAQFhTkM.mjs.map +1 -0
  6. package/dist/{Browser-wZhwZSlG.d.mts → Browser-DGR6ZEYo.d.mts} +9 -3
  7. package/dist/Browser.d.mts +1 -1
  8. package/dist/Browser.mjs +1 -1
  9. package/dist/{BrowserEvent-lLqJ3GJS.d.mts → BrowserEvent-C2p-NwuU.d.mts} +30 -6
  10. package/dist/BrowserEvent.d.mts +2 -2
  11. package/dist/BrowserEvent.mjs +20 -1
  12. package/dist/BrowserEvent.mjs.map +1 -1
  13. package/dist/{Change-Ba7INmay.d.mts → Change-CxT1mp2e.d.mts} +13 -2
  14. package/dist/Change.d.mts +1 -1
  15. package/dist/Change.mjs +7 -1
  16. package/dist/Change.mjs.map +1 -1
  17. package/dist/Clock-Du5nP-nK.d.mts +57 -0
  18. package/dist/Clock.d.mts +2 -57
  19. package/dist/Layout.d.mts +2 -0
  20. package/dist/Layout.mjs +81 -0
  21. package/dist/Layout.mjs.map +1 -0
  22. package/dist/Matching-MtcWZ_hA.d.mts +266 -0
  23. package/dist/Matching.d.mts +2 -37
  24. package/dist/Matching.mjs +22 -17
  25. package/dist/Matching.mjs.map +1 -1
  26. package/dist/Overlay-CoGw5tL_.d.mts +27 -0
  27. package/dist/Overlay.d.mts +2 -0
  28. package/dist/Overlay.mjs +30 -0
  29. package/dist/Overlay.mjs.map +1 -0
  30. package/dist/{Page-BF5izr8R.mjs → Page-BaAOshxo.mjs} +3 -1
  31. package/dist/Page-BaAOshxo.mjs.map +1 -0
  32. package/dist/{Page-CvsOEorc.d.mts → Page-CLzh5E9w.d.mts} +158 -6
  33. package/dist/Page.d.mts +2 -2
  34. package/dist/Page.mjs +1 -1
  35. package/dist/PageTime-68UPUZpZ.d.mts +29 -0
  36. package/dist/PageTime.d.mts +2 -0
  37. package/dist/PageTime.mjs +7 -0
  38. package/dist/PageTime.mjs.map +1 -0
  39. package/dist/Pose-2qqGzPvb.d.mts +32 -0
  40. package/dist/Pose.d.mts +2 -0
  41. package/dist/Pose.mjs +44 -0
  42. package/dist/Pose.mjs.map +1 -0
  43. package/dist/Site.d.mts +714 -0
  44. package/dist/Site.mjs +102 -0
  45. package/dist/Site.mjs.map +1 -0
  46. package/dist/{Stillness-CNlvayIo.mjs → Stillness-BwP0RdI4.mjs} +27 -6
  47. package/dist/Stillness-BwP0RdI4.mjs.map +1 -0
  48. package/dist/{Style-AO4V7Czt.mjs → Style-T3ezDYLI.mjs} +25 -2
  49. package/dist/{Style-AO4V7Czt.mjs.map → Style-T3ezDYLI.mjs.map} +1 -1
  50. package/dist/Style.d.mts +15 -2
  51. package/dist/Style.mjs +2 -2
  52. package/dist/Url-B7P-TWwL.d.mts +26 -0
  53. package/dist/Url.d.mts +2 -26
  54. package/dist/{Window-CMddGMt1.d.mts → Window-BDa8MtNP.d.mts} +4 -4
  55. package/dist/Window.d.mts +1 -1
  56. package/dist/{connection-BTeO0Hiz.mjs → connection-C_jWYIwe.mjs} +2 -2
  57. package/dist/{connection-BTeO0Hiz.mjs.map → connection-C_jWYIwe.mjs.map} +1 -1
  58. package/dist/{connection-2KHI4_KN.d.mts → connection-Db-YtlbE.d.mts} +2 -2
  59. package/dist/film/Film.d.mts +265 -0
  60. package/dist/film/Film.mjs +246 -0
  61. package/dist/film/Film.mjs.map +1 -0
  62. package/dist/fold.inpage-CyVZQHZL.d.mts +49 -0
  63. package/dist/index.d.mts +11 -8
  64. package/dist/index.mjs +8 -4
  65. package/dist/moment/Moment.d.mts +5 -5
  66. package/dist/plan/index.d.mts +2 -2
  67. package/dist/plan/index.mjs +2 -2
  68. package/dist/policy/Policy.d.mts +1 -1
  69. package/dist/policy/Policy.mjs +1 -1
  70. package/dist/pose.inpage-CLq7Mfdr.mjs +2042 -0
  71. package/dist/pose.inpage-CLq7Mfdr.mjs.map +1 -0
  72. package/dist/presentation/Presentation.d.mts +8 -1
  73. package/dist/presentation/Presentation.mjs +3 -1
  74. package/dist/presentation/Presentation.mjs.map +1 -1
  75. package/dist/presentation/Stage.d.mts +1 -1
  76. package/dist/providers/Cdp.d.mts +2 -2
  77. package/dist/providers/Cdp.mjs +1 -1
  78. package/dist/providers/Chromium.d.mts +1 -1
  79. package/dist/providers/Chromium.mjs +1 -1
  80. package/dist/stillness/Stillness.d.mts +1 -1
  81. package/dist/stillness/Stillness.mjs +1 -1
  82. package/dist/supervisor/Supervisor.mjs +3 -1
  83. package/dist/supervisor/Supervisor.mjs.map +1 -1
  84. package/dist/testing/index.d.mts +4 -30
  85. package/dist/testing/index.mjs +8 -2
  86. package/dist/testing/index.mjs.map +1 -1
  87. package/dist/workerd/Cdp.d.mts +2 -2
  88. package/dist/workerd/Cdp.mjs +1 -1
  89. package/package.json +35 -5
  90. package/src/Browser.ts +11 -6
  91. package/src/BrowserEvent.ts +19 -0
  92. package/src/Change.ts +7 -1
  93. package/src/Layout.ts +116 -0
  94. package/src/Matching.ts +24 -15
  95. package/src/Overlay.ts +37 -0
  96. package/src/Page.ts +45 -0
  97. package/src/PageTime.ts +47 -0
  98. package/src/Pose.ts +50 -0
  99. package/src/Site.ts +124 -0
  100. package/src/Style.ts +36 -0
  101. package/src/film/Film.ts +384 -0
  102. package/src/index.ts +4 -0
  103. package/src/internal/input/perform.ts +31 -3
  104. package/src/internal/input/pointer.ts +7 -4
  105. package/src/internal/input/targets.ts +1 -1
  106. package/src/internal/page/bridge.ts +65 -33
  107. package/src/internal/page/clock.inpage.ts +306 -0
  108. package/src/internal/page/compose.inpage.ts +101 -0
  109. package/src/internal/page/context.ts +2 -0
  110. package/src/internal/page/identity.ts +6 -5
  111. package/src/internal/page/overlay.inpage.ts +96 -0
  112. package/src/internal/page/overlay.ts +89 -0
  113. package/src/internal/page/page.ts +12 -0
  114. package/src/internal/page/pose.inpage.ts +200 -0
  115. package/src/internal/page/pose.ts +80 -0
  116. package/src/internal/page/time.inpage.ts +49 -0
  117. package/src/internal/page/time.ts +122 -0
  118. package/src/internal/page/viewport.ts +3 -2
  119. package/src/internal/pictures/pictures.ts +93 -32
  120. package/src/internal/reading/layout.inpage.ts +193 -0
  121. package/src/internal/reading/layout.ts +101 -0
  122. package/src/internal/reading/names.inpage.ts +15 -0
  123. package/src/internal/reading/outline.inpage.ts +2 -18
  124. package/src/internal/reading/reading.ts +22 -2
  125. package/src/internal/reading/ready.inpage.ts +18 -23
  126. package/src/internal/reading/ready.ts +23 -3
  127. package/src/internal/reading/text.inpage.ts +1 -14
  128. package/src/internal/timeline/changes.inpage.ts +7 -15
  129. package/src/internal/timeline/changes.ts +14 -1
  130. package/src/internal/timeline/record.inpage.ts +15 -6
  131. package/src/presentation/Presentation.ts +13 -0
  132. package/src/stillness/Pixels.ts +26 -0
  133. package/src/stillness/Stillness.ts +30 -5
  134. package/src/supervisor/runtime.ts +5 -1
  135. package/src/testing/page.ts +5 -0
  136. package/dist/Browser-Cq2K1FEA.mjs.map +0 -1
  137. package/dist/Page-BF5izr8R.mjs.map +0 -1
  138. package/dist/Stillness-CNlvayIo.mjs.map +0 -1
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "effect-browser",
3
- "version": "0.3.0-beta.22",
4
- "description": "Effect browser sessions, page control, screencast and moments over Playwright and CDP.",
3
+ "version": "0.3.0-beta.24",
4
+ "description": "Effect browser sessions, page control, screencast, moments and filming over Playwright and CDP.",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
@@ -130,6 +130,26 @@
130
130
  "types": "./dist/Geometry.d.mts",
131
131
  "default": "./dist/Geometry.mjs"
132
132
  },
133
+ "./Layout": {
134
+ "@effect-browser/source": "./src/Layout.ts",
135
+ "types": "./dist/Layout.d.mts",
136
+ "default": "./dist/Layout.mjs"
137
+ },
138
+ "./Overlay": {
139
+ "@effect-browser/source": "./src/Overlay.ts",
140
+ "types": "./dist/Overlay.d.mts",
141
+ "default": "./dist/Overlay.mjs"
142
+ },
143
+ "./Pose": {
144
+ "@effect-browser/source": "./src/Pose.ts",
145
+ "types": "./dist/Pose.d.mts",
146
+ "default": "./dist/Pose.mjs"
147
+ },
148
+ "./PageTime": {
149
+ "@effect-browser/source": "./src/PageTime.ts",
150
+ "types": "./dist/PageTime.d.mts",
151
+ "default": "./dist/PageTime.mjs"
152
+ },
133
153
  "./Style": {
134
154
  "@effect-browser/source": "./src/Style.ts",
135
155
  "types": "./dist/Style.d.mts",
@@ -140,6 +160,16 @@
140
160
  "types": "./dist/Window.d.mts",
141
161
  "default": "./dist/Window.mjs"
142
162
  },
163
+ "./Film": {
164
+ "@effect-browser/source": "./src/film/Film.ts",
165
+ "types": "./dist/film/Film.d.mts",
166
+ "default": "./dist/film/Film.mjs"
167
+ },
168
+ "./Site": {
169
+ "@effect-browser/source": "./src/Site.ts",
170
+ "types": "./dist/Site.d.mts",
171
+ "default": "./dist/Site.mjs"
172
+ },
143
173
  "./Stillness": {
144
174
  "@effect-browser/source": "./src/stillness/Stillness.ts",
145
175
  "types": "./dist/stillness/Stillness.d.mts",
@@ -175,9 +205,9 @@
175
205
  "test": "vp test --run"
176
206
  },
177
207
  "devDependencies": {
178
- "@effect/vitest": "4.0.3",
208
+ "@effect/vitest": "4.1.2",
179
209
  "@types/node": "26.1.2",
180
- "effect": "4.0.3",
210
+ "effect": "4.1.2",
181
211
  "esbuild": "0.28.2",
182
212
  "playwright-core": "1.63.0",
183
213
  "typescript": "7.0.2",
@@ -186,7 +216,7 @@
186
216
  "vitest": "5.0.3"
187
217
  },
188
218
  "peerDependencies": {
189
- "effect": "~4.0.3",
219
+ "effect": "~4.1.2",
190
220
  "playwright-core": "^1.63.0"
191
221
  },
192
222
  "engines": {
package/src/Browser.ts CHANGED
@@ -37,6 +37,7 @@ import {
37
37
  import * as Events from "./BrowserEvent.ts";
38
38
  import * as BrowserClock from "./Clock.ts";
39
39
  import * as Gate from "./internal/input/gate.ts";
40
+ import { documentScripts } from "./internal/page/bridge.ts";
40
41
  import { call, failWith, type Settings, undispatched } from "./internal/page/context.ts";
41
42
  import { listen } from "./internal/page/dialogs.ts";
42
43
  import * as Identity from "./internal/page/identity.ts";
@@ -114,6 +115,12 @@ export interface Options {
114
115
  readonly policyTimeout?: Duration.Input | undefined;
115
116
  /** Scripts that new documents run before their own, each where its `match` allows. */
116
117
  readonly initScripts?: ReadonlyArray<InitScript> | undefined;
118
+ /**
119
+ * Run a page clock in each top document before its own scripts, so `Page.hold` can hold and
120
+ * step its time. It keeps real time until held, but replaces the page's timers, animation
121
+ * frames, `Date` and `performance.now`, which a page script can notice. See `PageTime`.
122
+ */
123
+ readonly pageTime?: boolean | undefined;
117
124
  /**
118
125
  * The most pages the browser keeps open, those a site opens included, which are never refused. At
119
126
  * it, `newPage` waits for one to close, within the action timeout, then fails `Limit`; under
@@ -237,6 +244,8 @@ const settingsOf = Effect.fnUntraced(function* (options: Options) {
237
244
  frameHistory: yield* bound("frameHistory", options.frameHistory, Duration.seconds(5)),
238
245
  guard: options.guard,
239
246
  policyTimeout: yield* bound("policyTimeout", options.policyTimeout, Duration.minutes(5)),
247
+ // An event name the page's own scripts cannot guess, which only the clock listens for.
248
+ pageTime: options.pageTime === true ? `effect-browser-time-${yield* Identity.make}` : undefined,
240
249
  };
241
250
 
242
251
  if (
@@ -397,10 +406,6 @@ const eventsOf = (recent: Effect.Effect<ReadonlyArray<Events.RecordedEvent>>, pa
397
406
  ),
398
407
  );
399
408
 
400
- /** A script as its documents run it: everywhere, or as a block where its `match` allows. */
401
- const scoped = ({ match, source }: InitScript) =>
402
- match === undefined ? source : `if (${String(match)}.test(location.href)) {\n${source}\n}`;
403
-
404
409
  /**
405
410
  * At most `maxPages` open pages, those a site opened included, which are never refused: an open
406
411
  * past it waits for one to close, within `wait` on the owner's clock, then fails `Limit`, or fails
@@ -783,8 +788,8 @@ export const make = Effect.fn("Browser.make")(function* (
783
788
 
784
789
  // Playwright registers its init scripts as it sets up each page, before a popup's first document
785
790
  // runs, and they cost no call per document.
786
- for (const script of options.initScripts ?? [])
787
- yield* native("initScripts", () => context.addInitScript({ content: scoped(script) }));
791
+ for (const content of documentScripts(settings.pageTime, options.initScripts ?? []))
792
+ yield* native("initScripts", () => context.addInitScript({ content }));
788
793
  const register = yield* followOpened(context, registrations, registerPage, publish, now);
789
794
 
790
795
  for (const existing of context.pages()) yield* register(existing);
@@ -160,6 +160,24 @@ export class Action extends Schema.TaggedClass<Action>()("Action", {
160
160
 
161
161
  const Sequence = Schema.Int.check(Schema.isGreaterThan(0));
162
162
 
163
+ /**
164
+ * An action found its target and is about to send input there: published once, before its pointer
165
+ * travels to the target, with what its `Action` will record of it. A glide that only scrolls the
166
+ * target into view comes before. `x` and `y` are where the pointer goes, in viewport CSS pixels; for
167
+ * a drag, its start. Input with no pointer travel, such as keys or typing into the focused field,
168
+ * announces nothing.
169
+ */
170
+ export class ActionAnnounced extends Schema.TaggedClass<ActionAnnounced>()("ActionAnnounced", {
171
+ at: Schema.Finite,
172
+ page: Schema.String,
173
+ name: Name,
174
+ correlation: Schema.optional(Schema.String),
175
+ subject: Schema.optional(Subject),
176
+ to: Schema.optional(Subject),
177
+ box: Schema.optional(Box),
178
+ ...Motion.Point.fields,
179
+ }) {}
180
+
163
181
  /** One whole glide, published before its first input. Offsets use the host monotonic clock. */
164
182
  export class TrackPlanned extends Schema.TaggedClass<TrackPlanned>()("TrackPlanned", {
165
183
  at: Schema.Finite,
@@ -228,6 +246,7 @@ export class CursorChanged extends Schema.TaggedClass<CursorChanged>()("CursorCh
228
246
  }) {}
229
247
 
230
248
  export const TrackEvent = Schema.Union([
249
+ ActionAnnounced,
231
250
  TrackPlanned,
232
251
  TrackPerformed,
233
252
  PointerPressed,
package/src/Change.ts CHANGED
@@ -18,7 +18,7 @@
18
18
  */
19
19
  import { Schema } from "effect";
20
20
 
21
- import { Subject } from "./BrowserEvent.ts";
21
+ import { Box, Subject } from "./BrowserEvent.ts";
22
22
 
23
23
  /**
24
24
  * `text` changed; `appeared` and `disappeared`, whether added or removed or shown or hidden;
@@ -35,6 +35,12 @@ export class Change extends Schema.Class<Change>("effect-browser/Change")({
35
35
  * changed, so its name is empty unless something else names it, as a field's label does.
36
36
  */
37
37
  subject: Subject,
38
+ /**
39
+ * Where it is as the changes are read, in viewport CSS pixels, unrounded; for what went, where
40
+ * what it sat in is. A caller can frame what an input did beside the input. Absent for the title
41
+ * and for what is drawn nowhere, as what was hidden is.
42
+ */
43
+ box: Schema.optional(Box),
38
44
  /** When it first changed in the window, in host monotonic milliseconds on the browser's clock. */
39
45
  startedAt: Schema.Finite,
40
46
  /** When it last changed in the window. */
package/src/Layout.ts ADDED
@@ -0,0 +1,116 @@
1
+ /**
2
+ * Where things are on a page, as data: a box for each thing a caller picks, in the viewport and in
3
+ * the document, unrounded, with the boxes of words inside it, and the viewport, scroll and scale
4
+ * read with them in one call. A rehearsal measures things that exist only after an interaction,
5
+ * and puts the page back.
6
+ *
7
+ * @since 0.3.0
8
+ */
9
+ import { Effect, Exit, Schema } from "effect";
10
+
11
+ import type { Action } from "./Action.ts";
12
+ import type { BrowserError } from "./BrowserError.ts";
13
+ import { Box, Subject } from "./BrowserEvent.ts";
14
+ import { Point } from "./Geometry.ts";
15
+ import type { FindQuery, Page } from "./Page.ts";
16
+
17
+ /** A match of a pick's `words`, by its box in the viewport and in the document. */
18
+ export class Word extends Schema.Class<Word>("effect-browser/Word")({
19
+ text: Schema.String,
20
+ box: Box,
21
+ page: Box,
22
+ }) {}
23
+
24
+ /** What one pick found. */
25
+ export class Place extends Schema.Class<Place>("effect-browser/Place")({
26
+ /** The pick's own name. */
27
+ id: Schema.String,
28
+ ref: Schema.String,
29
+ subject: Subject,
30
+ /** Its box in viewport CSS pixels, unrounded, as an `at` point or a frame's pixels place it. */
31
+ box: Box,
32
+ /** The same box in document CSS pixels: `box` moved by the scroll it was read at. */
33
+ page: Box,
34
+ /** It keeps its place in the viewport as the page scrolls, so `page` holds only at this scroll. */
35
+ fixed: Schema.Boolean,
36
+ /** The matches of the pick's `words`, when it gave them, in text order. */
37
+ words: Schema.optional(Schema.Array(Word)),
38
+ }) {}
39
+
40
+ /** A page's picked places, and the viewport, scroll and scale they were read at. */
41
+ export class Layout extends Schema.Class<Layout>("effect-browser/Layout")({
42
+ page: Schema.String,
43
+ /** The tracking connection that owns the document counter. */
44
+ connection: Schema.String,
45
+ /** The document it read, as `Navigated` counts them. */
46
+ document: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),
47
+ url: Schema.String,
48
+ /** Host monotonic milliseconds, when it was read. */
49
+ at: Schema.Finite,
50
+ /** The viewport's size in CSS pixels. */
51
+ viewport: Schema.Struct({ width: Schema.Finite, height: Schema.Finite }),
52
+ /** How far the document was scrolled, in CSS pixels. */
53
+ scroll: Point,
54
+ /** Device pixels to a CSS pixel: a `scale: "device"` picture's pixels per CSS pixel. */
55
+ scale: Schema.Finite,
56
+ /** One for each pick that found something, in the order the picks were given. */
57
+ places: Schema.Array(Place),
58
+ /** The picks that found nothing. */
59
+ missing: Schema.Array(Schema.String),
60
+ }) {}
61
+
62
+ /**
63
+ * A `find` query that names one thing. Its scope defaults to the whole document. Every element it
64
+ * finds is a candidate, and `choose` takes one: the first in tree order (the default), the last,
65
+ * or the smallest or largest by area. With a selector, the candidates are what it selects that
66
+ * shows and meets the other rules, a drawing's elements among them, which `find` leaves out.
67
+ */
68
+ export interface Pick extends FindQuery {
69
+ readonly choose?: "first" | "last" | "smallest" | "largest" | undefined;
70
+ /**
71
+ * Words to box inside it: text, found ignoring case, or a pattern; each match gets its own box,
72
+ * across the elements the text is split into. At most 200 for a pick.
73
+ */
74
+ readonly words?: string | RegExp | undefined;
75
+ }
76
+
77
+ /** Picks by the names their places will carry. */
78
+ export type Picks = Readonly<Record<string, Pick>>;
79
+
80
+ /** The place a pick named, if it found one. */
81
+ export const place = (layout: Layout, id: string): Place | undefined =>
82
+ layout.places.find((each) => each.id === id);
83
+
84
+ /** What a rehearsal does, measures, and does to put the page back. */
85
+ export interface Rehearsal {
86
+ readonly act: ReadonlyArray<Action>;
87
+ readonly picks: Picks;
88
+ readonly undo: ReadonlyArray<Action>;
89
+ }
90
+
91
+ /**
92
+ * Measure what exists only after an interaction: perform `act`, wait for the page to be ready,
93
+ * read the layout, then perform `undo`, which runs whether or not acting and reading succeeded,
94
+ * and is not interrupted. A failure to act or read is the rehearsal's; otherwise one to undo is.
95
+ */
96
+ export const rehearse = (page: Page, rehearsal: Rehearsal): Effect.Effect<Layout, BrowserError> =>
97
+ Effect.uninterruptibleMask((restore) =>
98
+ Effect.gen(function* () {
99
+ const measured = yield* Effect.exit(
100
+ restore(
101
+ Effect.forEach(rehearsal.act, page.perform, { discard: true }).pipe(
102
+ Effect.andThen(page.ready()),
103
+ Effect.andThen(page.layout(rehearsal.picks)),
104
+ ),
105
+ ),
106
+ );
107
+
108
+ const undone = yield* Effect.exit(
109
+ Effect.forEach(rehearsal.undo, page.perform, { discard: true }),
110
+ );
111
+
112
+ return yield* Exit.isFailure(measured) || Exit.isSuccess(undone)
113
+ ? measured
114
+ : Exit.failCause(undone.cause);
115
+ }),
116
+ );
package/src/Matching.ts CHANGED
@@ -11,6 +11,8 @@
11
11
  */
12
12
  import type { SubjectContext } from "./BrowserEvent.ts";
13
13
  import type { Point } from "./Geometry.ts";
14
+ import type { PickRequest } from "./internal/reading/layout.inpage.ts";
15
+ import type { Picks } from "./Layout.ts";
14
16
  import type { FindQuery } from "./Page.ts";
15
17
 
16
18
  /** A string, or a pattern sent to the page as its source and flags. */
@@ -27,22 +29,29 @@ export interface FindRequest {
27
29
  readonly scope: "viewport" | "document";
28
30
  }
29
31
 
32
+ const wanted = (value: string | RegExp | undefined): Wanted | null =>
33
+ value instanceof RegExp ? { source: value.source, flags: value.flags } : (value ?? null);
34
+
30
35
  /** A public query in its serializable, fully specified form. */
31
- export const request = (query: FindQuery, scope: FindRequest["scope"]): FindRequest => {
32
- const wanted = (value: string | RegExp | undefined): Wanted | null =>
33
- value instanceof RegExp ? { source: value.source, flags: value.flags } : (value ?? null);
34
-
35
- return {
36
- selector: query.selector ?? null,
37
- state: query.state ?? "visible",
38
- role: query.role ?? null,
39
- name: wanted(query.name),
40
- text: wanted(query.text),
41
- near: query.near ?? null,
42
- at: query.at ?? null,
43
- scope: query.scope ?? scope,
44
- };
45
- };
36
+ export const request = (query: FindQuery, scope: FindRequest["scope"]): FindRequest => ({
37
+ selector: query.selector ?? null,
38
+ state: query.state ?? "visible",
39
+ role: query.role ?? null,
40
+ name: wanted(query.name),
41
+ text: wanted(query.text),
42
+ near: query.near ?? null,
43
+ at: query.at ?? null,
44
+ scope: query.scope ?? scope,
45
+ });
46
+
47
+ /** Layout picks in their serializable form. */
48
+ export const pickRequests = (picks: Picks): ReadonlyArray<PickRequest> =>
49
+ Object.entries(picks).map(([id, pick]) => ({
50
+ ...request(pick, "document"),
51
+ id,
52
+ choose: pick.choose ?? "first",
53
+ words: wanted(pick.words),
54
+ }));
46
55
 
47
56
  /** What a query is matched against, read only when a rule needs it. */
48
57
  export interface Candidate {
package/src/Overlay.ts ADDED
@@ -0,0 +1,37 @@
1
+ /**
2
+ * A layer over a page that the library draws a caller's content into, without knowing what it
3
+ * shows: a pointer, a ring round what an agent is about to press, a caption, a character. It shows
4
+ * in screenshots, screencasts and a live view alike. The library's own readers never read it:
5
+ * `find`, `snapshot`, `layout`, `text`, `changes`, `ready` and stillness see the page as if it
6
+ * were not there, and input passes through it to the page.
7
+ *
8
+ * A page has one overlay at a time, for a scope. It sits above the page's own layers but beneath
9
+ * its top layer (a modal dialog, a popover), in viewport CSS pixels, and undoes a zoom the page
10
+ * sets on its root. Each new document starts without it, and it is drawn again there, with what
11
+ * it last showed, once the document has loaded. It is gone when its scope closes.
12
+ *
13
+ * @since 0.3.0
14
+ */
15
+ import { type Effect, Schema } from "effect";
16
+
17
+ import type { BrowserError } from "./BrowserError.ts";
18
+ import type { Box } from "./BrowserEvent.ts";
19
+
20
+ /**
21
+ * What the overlay shows. `Svg` is an SVG document sized to the viewport, whose own `viewBox` maps
22
+ * any design space onto it; its scripts and event handlers are dropped. `Empty` shows nothing.
23
+ */
24
+ export const Content = Schema.TaggedUnion({
25
+ Svg: { markup: Schema.String },
26
+ Empty: {},
27
+ });
28
+
29
+ export type Content = typeof Content.Type;
30
+
31
+ export interface Overlay {
32
+ /**
33
+ * Show `content` in place of what was shown, in one call to the page, after the actions asked
34
+ * before it. Says where the drawing's top-level parts are, in viewport CSS pixels.
35
+ */
36
+ readonly draw: (content: Content) => Effect.Effect<ReadonlyArray<Box>, BrowserError>;
37
+ }
package/src/Page.ts CHANGED
@@ -32,6 +32,10 @@ import * as Motion from "./Geometry.ts";
32
32
  import { FormFieldSchema } from "./internal/input/evidence.inpage.ts";
33
33
  import * as Guard from "./internal/input/guard.inpage.ts";
34
34
  import { Correlation, FailFast } from "./internal/page/lane.ts";
35
+ import type { Layout, Picks } from "./Layout.ts";
36
+ import type { Overlay } from "./Overlay.ts";
37
+ import type { Held } from "./PageTime.ts";
38
+ import type { Poses } from "./Pose.ts";
35
39
  import { type Snapshot, type SnapshotOptions } from "./Snapshot.ts";
36
40
  import * as Url from "./Url.ts";
37
41
  import type { Window } from "./Window.ts";
@@ -108,6 +112,14 @@ export interface ScreenshotOptions {
108
112
  readonly scale?: "css" | "device" | undefined;
109
113
  }
110
114
 
115
+ /** How a page paints for a scope; see `Page.paint`. */
116
+ export interface Paint {
117
+ /** Device pixels to each CSS pixel, more than 0 and at most 4. The layout keeps its size. */
118
+ readonly scale?: number | undefined;
119
+ /** False hides the page's scrollbars from its next document on, and its layout takes their room. */
120
+ readonly scrollbars?: boolean | undefined;
121
+ }
122
+
111
123
  /**
112
124
  * What `find` looks for. Every rule given must hold; with none, it finds every element in scope
113
125
  * that has a role or is a control.
@@ -246,6 +258,8 @@ export class State extends Schema.Class<State>("effect-browser/PageState")({
246
258
  load: Schema.optional(PageLoaded),
247
259
  /** The newest screencast frame, of whichever document it names. */
248
260
  frame: Schema.optional(Frame),
261
+ /** Where the overlay's drawing was last drawn, in viewport CSS pixels; absent with none shown. */
262
+ overlay: Schema.optional(Schema.Array(Box)),
249
263
  /** The viewport's text as it was last read, with the page's title then. */
250
264
  text: Schema.optional(Text),
251
265
  }) {}
@@ -468,6 +482,28 @@ export interface Page {
468
482
  * empty result, not a failure.
469
483
  */
470
484
  readonly find: (query?: FindQuery) => Effect.Effect<ReadonlyArray<Found>, BrowserError>;
485
+ /**
486
+ * Where each pick is, in one call to the page: its box unrounded, in the viewport and in the
487
+ * document, the boxes of words in it, and the viewport, scroll and scale they were read at. A
488
+ * pick that finds nothing is listed as missing, not a failure. See `Layout`.
489
+ */
490
+ readonly layout: (picks: Picks) => Effect.Effect<Layout, BrowserError>;
491
+ /**
492
+ * A layer over the page to draw into, for the scope, that the library's readers never read.
493
+ * One at a time: a second while one is open fails `InvalidRequest`. See `Overlay`.
494
+ */
495
+ readonly overlay: Effect.Effect<Overlay, BrowserError, Scope.Scope>;
496
+ /**
497
+ * Pose the page's own elements for the scope, moved, turned and scaled as a caller says, and put
498
+ * back when the scope closes. One lease at a time: a second while one is open fails
499
+ * `InvalidRequest`. See `Pose`.
500
+ */
501
+ readonly poses: Effect.Effect<Poses, BrowserError, Scope.Scope>;
502
+ /**
503
+ * Hold the page's own time for the scope, to step it on with `advance`; real time resumes when
504
+ * the scope closes. Needs the browser's `pageTime` option; one hold at a time. See `PageTime`.
505
+ */
506
+ readonly hold: Effect.Effect<Held, BrowserError, Scope.Scope>;
471
507
  /**
472
508
  * The text the viewport shows, or one element whole, in one call to the page. Field values read
473
509
  * `••••` unless `unmask`, and a secret field's always do, as does one that was secret when the
@@ -491,6 +527,15 @@ export interface Page {
491
527
  * its document and how far it has loaded, its newest frame, and its text and title as last read.
492
528
  */
493
529
  readonly state: Effect.Effect<State>;
530
+ /**
531
+ * Paint the page at `scale` device pixels to each CSS pixel, or without its scrollbars, for a
532
+ * scope: a screenshot with `scale: "device"` then has that many more pixels, while the layout,
533
+ * its boxes and input keep their CSS pixels. Scrollbars go from the next document on, and come
534
+ * back from the next after the scope, so paint, then load the page, then measure it. One at a
535
+ * time. A browser this library launched paints at the scale of its launch (Chromium's
536
+ * `deviceScaleFactor`), and refuses another.
537
+ */
538
+ readonly paint: (options: Paint) => Effect.Effect<void, BrowserError, Scope.Scope>;
494
539
 
495
540
  readonly click: (
496
541
  target: Target,
@@ -0,0 +1,47 @@
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 `Page.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
+ * @since 0.3.0
21
+ */
22
+ import type { Duration, Effect } from "effect";
23
+
24
+ import type { BrowserError } from "./BrowserError.ts";
25
+ import type { Point } from "./Geometry.ts";
26
+ import type { Content } from "./Overlay.ts";
27
+ import type { Pose } from "./Pose.ts";
28
+
29
+ /** What else changes with page time in the same call to the page. */
30
+ export interface Step {
31
+ /** Scroll the document to this many CSS pixels down it first, at once. */
32
+ readonly scroll?: number | undefined;
33
+ /** Then pose these elements and take the pose off any other, as `Poses.set` does; the page's poses must be open. */
34
+ readonly poses?: ReadonlyArray<Pose> | undefined;
35
+ /** Then show this in the page's overlay, which must be open. */
36
+ readonly overlay?: Content | undefined;
37
+ }
38
+
39
+ export interface Held {
40
+ /**
41
+ * Move page time on by `by`, in one call to the page, after the actions asked before it. Says
42
+ * where the document is scrolled to after it.
43
+ */
44
+ readonly advance: (by: Duration.Input, step?: Step) => Effect.Effect<Point, BrowserError>;
45
+ /** How far this hold has moved page time, across the documents it held. */
46
+ readonly elapsed: Effect.Effect<Duration.Duration>;
47
+ }
package/src/Pose.ts ADDED
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Element poses: one of the page's own elements moved, turned and scaled about a point, as a caller
3
+ * says, frame by frame on held time or live, so that the page answers what touches it. A tab
4
+ * squashes under a stomp, a box dips as something lands on it, a button tilts as it is pulled, a
5
+ * field wiggles to ask for input. The library chooses no motion: each pose is a caller's.
6
+ *
7
+ * A pose is plain data, in viewport CSS pixels: moved by `dx` and `dy`, scaled by `sx` and `sy`,
8
+ * and turned `rotate` degrees clockwise, each about `origin`, by default the middle of where the
9
+ * page draws the element. As CSS writes it: `transform-origin: origin; transform: translate(dx, dy)
10
+ * rotate(rotate) scale(sx, sy)`, applied around the element's own transform. Its own `translate`,
11
+ * `rotate` and `scale` properties, which pages seldom set, give way while it is posed.
12
+ *
13
+ * A page's poses are one lease, for a scope; each `set` poses the elements it names and takes the
14
+ * pose off every other, and the scope's end takes them all off. A pose sets no attribute and starts
15
+ * none of the page's transitions, and the library's change record does not report it. Readers
16
+ * report what is drawn: `layout`, `find` and the input's targets give a posed element's box as
17
+ * posed, and a click lands where it is drawn. Only HTML elements take a pose, and one inside
18
+ * another posed element is posed about its point as if the outer one were not. A new document
19
+ * starts with none.
20
+ *
21
+ * @since 0.3.0
22
+ */
23
+ import { type Effect, Schema } from "effect";
24
+
25
+ import type { BrowserError } from "./BrowserError.ts";
26
+ import { Point } from "./Geometry.ts";
27
+
28
+ /** How an element is posed. A part left out changes nothing: no move, a scale of 1, no turn. */
29
+ export const Pose = Schema.Struct({
30
+ /** The element, by a ref from the page's current document, such as a `Layout` place's. */
31
+ ref: Schema.String,
32
+ dx: Schema.optional(Schema.Finite),
33
+ dy: Schema.optional(Schema.Finite),
34
+ sx: Schema.optional(Schema.Finite),
35
+ sy: Schema.optional(Schema.Finite),
36
+ /** Degrees, clockwise. */
37
+ rotate: Schema.optional(Schema.Finite),
38
+ /** The point it turns and scales about, in the viewport. */
39
+ origin: Schema.optional(Point),
40
+ });
41
+
42
+ export type Pose = typeof Pose.Type;
43
+
44
+ export interface Poses {
45
+ /**
46
+ * Pose these elements, in one call to the page, and take the pose off every other. A ref the
47
+ * document no longer has fails with `StaleRef`, and posing nothing.
48
+ */
49
+ readonly set: (poses: ReadonlyArray<Pose>) => Effect.Effect<void, BrowserError>;
50
+ }