effect-browser 0.3.0-beta.23 → 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.
- package/README.md +124 -5
- package/dist/ActionPort.d.mts +1 -1
- package/dist/ActionPort.mjs +1 -1
- package/dist/{Browser-BKPAbyys.mjs → Browser-CAQFhTkM.mjs} +559 -333
- package/dist/Browser-CAQFhTkM.mjs.map +1 -0
- package/dist/{Browser-wZhwZSlG.d.mts → Browser-DGR6ZEYo.d.mts} +9 -3
- package/dist/Browser.d.mts +1 -1
- package/dist/Browser.mjs +1 -1
- package/dist/{BrowserEvent-lLqJ3GJS.d.mts → BrowserEvent-C2p-NwuU.d.mts} +30 -6
- package/dist/BrowserEvent.d.mts +2 -2
- package/dist/BrowserEvent.mjs +20 -1
- package/dist/BrowserEvent.mjs.map +1 -1
- package/dist/{Change-Ba7INmay.d.mts → Change-CxT1mp2e.d.mts} +13 -2
- package/dist/Change.d.mts +1 -1
- package/dist/Change.mjs +7 -1
- package/dist/Change.mjs.map +1 -1
- package/dist/Clock-Du5nP-nK.d.mts +57 -0
- package/dist/Clock.d.mts +2 -57
- package/dist/Layout.d.mts +2 -0
- package/dist/Layout.mjs +81 -0
- package/dist/Layout.mjs.map +1 -0
- package/dist/Matching-MtcWZ_hA.d.mts +266 -0
- package/dist/Matching.d.mts +2 -37
- package/dist/Matching.mjs +22 -17
- package/dist/Matching.mjs.map +1 -1
- package/dist/Overlay-CoGw5tL_.d.mts +27 -0
- package/dist/Overlay.d.mts +2 -0
- package/dist/Overlay.mjs +30 -0
- package/dist/Overlay.mjs.map +1 -0
- package/dist/{Page-BF5izr8R.mjs → Page-BaAOshxo.mjs} +3 -1
- package/dist/Page-BaAOshxo.mjs.map +1 -0
- package/dist/{Page-CvsOEorc.d.mts → Page-CLzh5E9w.d.mts} +158 -6
- package/dist/Page.d.mts +2 -2
- package/dist/Page.mjs +1 -1
- package/dist/PageTime-68UPUZpZ.d.mts +29 -0
- package/dist/PageTime.d.mts +2 -0
- package/dist/PageTime.mjs +7 -0
- package/dist/PageTime.mjs.map +1 -0
- package/dist/Pose-2qqGzPvb.d.mts +32 -0
- package/dist/Pose.d.mts +2 -0
- package/dist/Pose.mjs +44 -0
- package/dist/Pose.mjs.map +1 -0
- package/dist/Site.d.mts +714 -0
- package/dist/Site.mjs +102 -0
- package/dist/Site.mjs.map +1 -0
- package/dist/{Stillness-CNlvayIo.mjs → Stillness-BwP0RdI4.mjs} +27 -6
- package/dist/Stillness-BwP0RdI4.mjs.map +1 -0
- package/dist/{Style-AO4V7Czt.mjs → Style-T3ezDYLI.mjs} +25 -2
- package/dist/{Style-AO4V7Czt.mjs.map → Style-T3ezDYLI.mjs.map} +1 -1
- package/dist/Style.d.mts +15 -2
- package/dist/Style.mjs +2 -2
- package/dist/Url-B7P-TWwL.d.mts +26 -0
- package/dist/Url.d.mts +2 -26
- package/dist/{Window-CMddGMt1.d.mts → Window-BDa8MtNP.d.mts} +4 -4
- package/dist/Window.d.mts +1 -1
- package/dist/{connection-CK83pvqP.mjs → connection-C_jWYIwe.mjs} +2 -2
- package/dist/{connection-CK83pvqP.mjs.map → connection-C_jWYIwe.mjs.map} +1 -1
- package/dist/{connection-2KHI4_KN.d.mts → connection-Db-YtlbE.d.mts} +2 -2
- package/dist/film/Film.d.mts +265 -0
- package/dist/film/Film.mjs +246 -0
- package/dist/film/Film.mjs.map +1 -0
- package/dist/fold.inpage-CyVZQHZL.d.mts +49 -0
- package/dist/index.d.mts +11 -8
- package/dist/index.mjs +8 -4
- package/dist/moment/Moment.d.mts +5 -5
- package/dist/plan/index.d.mts +2 -2
- package/dist/plan/index.mjs +2 -2
- package/dist/policy/Policy.d.mts +1 -1
- package/dist/policy/Policy.mjs +1 -1
- package/dist/pose.inpage-CLq7Mfdr.mjs +2042 -0
- package/dist/pose.inpage-CLq7Mfdr.mjs.map +1 -0
- package/dist/presentation/Presentation.d.mts +8 -1
- package/dist/presentation/Presentation.mjs +3 -1
- package/dist/presentation/Presentation.mjs.map +1 -1
- package/dist/presentation/Stage.d.mts +1 -1
- package/dist/providers/Cdp.d.mts +2 -2
- package/dist/providers/Cdp.mjs +1 -1
- package/dist/providers/Chromium.d.mts +1 -1
- package/dist/providers/Chromium.mjs +1 -1
- package/dist/stillness/Stillness.d.mts +1 -1
- package/dist/stillness/Stillness.mjs +1 -1
- package/dist/testing/index.d.mts +4 -30
- package/dist/testing/index.mjs +8 -2
- package/dist/testing/index.mjs.map +1 -1
- package/dist/workerd/Cdp.d.mts +2 -2
- package/dist/workerd/Cdp.mjs +1 -1
- package/package.json +32 -2
- package/src/Browser.ts +11 -6
- package/src/BrowserEvent.ts +19 -0
- package/src/Change.ts +7 -1
- package/src/Layout.ts +116 -0
- package/src/Matching.ts +24 -15
- package/src/Overlay.ts +37 -0
- package/src/Page.ts +45 -0
- package/src/PageTime.ts +47 -0
- package/src/Pose.ts +50 -0
- package/src/Site.ts +124 -0
- package/src/Style.ts +36 -0
- package/src/film/Film.ts +384 -0
- package/src/index.ts +4 -0
- package/src/internal/input/perform.ts +31 -3
- package/src/internal/input/pointer.ts +7 -4
- package/src/internal/input/targets.ts +1 -1
- package/src/internal/page/bridge.ts +65 -33
- package/src/internal/page/clock.inpage.ts +306 -0
- package/src/internal/page/compose.inpage.ts +101 -0
- package/src/internal/page/context.ts +2 -0
- package/src/internal/page/overlay.inpage.ts +96 -0
- package/src/internal/page/overlay.ts +89 -0
- package/src/internal/page/page.ts +12 -0
- package/src/internal/page/pose.inpage.ts +200 -0
- package/src/internal/page/pose.ts +80 -0
- package/src/internal/page/time.inpage.ts +49 -0
- package/src/internal/page/time.ts +122 -0
- package/src/internal/page/viewport.ts +3 -2
- package/src/internal/pictures/pictures.ts +93 -32
- package/src/internal/reading/layout.inpage.ts +193 -0
- package/src/internal/reading/layout.ts +101 -0
- package/src/internal/reading/names.inpage.ts +15 -0
- package/src/internal/reading/outline.inpage.ts +2 -18
- package/src/internal/reading/reading.ts +22 -2
- package/src/internal/reading/ready.inpage.ts +18 -23
- package/src/internal/reading/ready.ts +23 -3
- package/src/internal/reading/text.inpage.ts +1 -14
- package/src/internal/timeline/changes.inpage.ts +7 -15
- package/src/internal/timeline/changes.ts +14 -1
- package/src/internal/timeline/record.inpage.ts +15 -6
- package/src/presentation/Presentation.ts +13 -0
- package/src/stillness/Pixels.ts +26 -0
- package/src/stillness/Stillness.ts +30 -5
- package/src/testing/page.ts +5 -0
- package/dist/Browser-BKPAbyys.mjs.map +0 -1
- package/dist/Page-BF5izr8R.mjs.map +0 -1
- package/dist/Stillness-CNlvayIo.mjs.map +0 -1
package/src/film/Film.ts
ADDED
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Filming a page as a function of time: a new screenshot at each time a caller asks for, of the
|
|
3
|
+
* page as it is at that film time, with what the caller draws over it then. Film time comes from
|
|
4
|
+
* a held page (`Page.hold`), which steps to each frame however long the last one took, so a
|
|
5
|
+
* frame costs one call to step the page and one screenshot; from a page that seeks itself; or
|
|
6
|
+
* from real time. The frames are pictures; encoding them is the caller's.
|
|
7
|
+
*
|
|
8
|
+
* Loading takes real time, so a film holds its time while the page loads a new document: the
|
|
9
|
+
* first frame that finds one waits for it to be ready, measures its layout, and says so as a
|
|
10
|
+
* `Passage`, which `at` sees from then on. On real time the film's start moves on by the wait.
|
|
11
|
+
*
|
|
12
|
+
* @since 0.3.0
|
|
13
|
+
*/
|
|
14
|
+
import { Clock, Duration, Effect, Schema, Stream } from "effect";
|
|
15
|
+
|
|
16
|
+
import { Action } from "../Action.ts";
|
|
17
|
+
import { type BrowserError, refuse } from "../BrowserError.ts";
|
|
18
|
+
import { monotonicMillis } from "../Clock.ts";
|
|
19
|
+
import { Image } from "../Frame.ts";
|
|
20
|
+
import { Point } from "../Geometry.ts";
|
|
21
|
+
import { Layout, type Picks } from "../Layout.ts";
|
|
22
|
+
import type { Content, Overlay } from "../Overlay.ts";
|
|
23
|
+
import { type Page, ResolvedTarget, type ScreenshotOptions } from "../Page.ts";
|
|
24
|
+
import type { Held, Step } from "../PageTime.ts";
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* What a frame shows over the page, and, on held time, where the page is scrolled to then and how
|
|
28
|
+
* its elements are posed, with the page's poses open.
|
|
29
|
+
*/
|
|
30
|
+
export type At = Step;
|
|
31
|
+
|
|
32
|
+
/** Frames at `fps` from `from` (0 by default) until before `to`, or at these times, in ms. */
|
|
33
|
+
export type Times =
|
|
34
|
+
| { readonly fps: number; readonly from?: number | undefined; readonly to: number }
|
|
35
|
+
| ReadonlyArray<number>;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Where film time comes from: a held page, stepped to each frame; a page's own seek, given each
|
|
39
|
+
* frame's time; or real time from the film's start, each frame taken when its time comes.
|
|
40
|
+
*/
|
|
41
|
+
export type Time =
|
|
42
|
+
| Held
|
|
43
|
+
| { readonly seek: (t: number) => Effect.Effect<void, BrowserError> }
|
|
44
|
+
| "real";
|
|
45
|
+
|
|
46
|
+
export interface Options<E = never> {
|
|
47
|
+
readonly times: Times;
|
|
48
|
+
readonly time: Time;
|
|
49
|
+
/** What the page shows at a film time, each frame's and each input's, from the passages so far. */
|
|
50
|
+
readonly at?:
|
|
51
|
+
| ((t: number, film: { readonly passages: ReadonlyArray<Passage> }) => Effect.Effect<At, E>)
|
|
52
|
+
| undefined;
|
|
53
|
+
/** What to measure in each new document the film arrives in. */
|
|
54
|
+
readonly picks?: Picks | undefined;
|
|
55
|
+
/**
|
|
56
|
+
* Inputs sent at their film times, in time order, each before the first frame at or after it:
|
|
57
|
+
* the page is moved to its time, and on held time it answers as its time is stepped on. One that
|
|
58
|
+
* fails fails the film.
|
|
59
|
+
*/
|
|
60
|
+
readonly inputs?: ReadonlyArray<Contact> | undefined;
|
|
61
|
+
/** The page's overlay, open, that `at`'s drawings go to. */
|
|
62
|
+
readonly overlay?: Overlay | undefined;
|
|
63
|
+
/**
|
|
64
|
+
* How each frame is taken. For frames with more pixels than the layout, paint the page first
|
|
65
|
+
* (`Page.paint`) and take them at `scale: "device"`.
|
|
66
|
+
*/
|
|
67
|
+
readonly image?: Pick<ScreenshotOptions, "format" | "quality" | "scale"> | undefined;
|
|
68
|
+
/** How many times a frame's screenshot is taken again after it times out. Defaults to 2. */
|
|
69
|
+
readonly retries?: number | undefined;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const Count = Schema.Int.check(Schema.isGreaterThanOrEqualTo(0));
|
|
73
|
+
const Millis = Schema.Finite.check(Schema.isGreaterThanOrEqualTo(0));
|
|
74
|
+
|
|
75
|
+
/** An input to send at film time `t`, in ms, with the caller's name for it. */
|
|
76
|
+
export const Contact = Schema.Struct({
|
|
77
|
+
t: Millis,
|
|
78
|
+
action: Action,
|
|
79
|
+
label: Schema.optional(Schema.String),
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
export type Contact = typeof Contact.Type;
|
|
83
|
+
|
|
84
|
+
/** An input as it was sent, at its film time. */
|
|
85
|
+
export class Sent extends Schema.Class<Sent>("effect-browser/Sent")({
|
|
86
|
+
t: Millis,
|
|
87
|
+
label: Schema.optional(Schema.String),
|
|
88
|
+
action: Action,
|
|
89
|
+
/** What a click resolved its target to, before its input. */
|
|
90
|
+
target: Schema.optional(ResolvedTarget),
|
|
91
|
+
/** The page's document after it. */
|
|
92
|
+
document: Count,
|
|
93
|
+
}) {}
|
|
94
|
+
|
|
95
|
+
/** The page's move to a new document, at the film time of the first frame that found it. */
|
|
96
|
+
export class Passage extends Schema.Class<Passage>("effect-browser/Passage")({
|
|
97
|
+
t: Millis,
|
|
98
|
+
/** The address of the document it left. */
|
|
99
|
+
left: Schema.String,
|
|
100
|
+
document: Count,
|
|
101
|
+
url: Schema.String,
|
|
102
|
+
/** Real milliseconds from the film's last step on the page before to the document's being ready. */
|
|
103
|
+
loadedAfter: Millis,
|
|
104
|
+
/** The new document's layout, ready, with the film's `picks`. */
|
|
105
|
+
layout: Layout,
|
|
106
|
+
}) {}
|
|
107
|
+
|
|
108
|
+
/** One frame: its picture at film time `t`, in ms, and what taking it cost in real time. */
|
|
109
|
+
export class Shot extends Schema.Class<Shot>("effect-browser/Shot")({
|
|
110
|
+
index: Count,
|
|
111
|
+
t: Millis,
|
|
112
|
+
image: Image,
|
|
113
|
+
/** The page's document and address after the picture, as `Page.state` gives them. */
|
|
114
|
+
document: Count,
|
|
115
|
+
url: Schema.String,
|
|
116
|
+
/** Where the document was scrolled to, in CSS pixels, on held time. */
|
|
117
|
+
scroll: Schema.optional(Point),
|
|
118
|
+
/** The inputs sent since the frame before. */
|
|
119
|
+
sent: Schema.Array(Sent),
|
|
120
|
+
/** The new document this frame was the first to find. */
|
|
121
|
+
passage: Schema.optional(Passage),
|
|
122
|
+
/** Screenshots that timed out before this one. */
|
|
123
|
+
retries: Count,
|
|
124
|
+
/** Real milliseconds from the frame's start to its picture. */
|
|
125
|
+
took: Millis,
|
|
126
|
+
/**
|
|
127
|
+
* When its picture was taken, in host monotonic milliseconds on the browser's clock, as a
|
|
128
|
+
* `Change`'s times are. On held time, the first shot at or after a change's `at` is the first
|
|
129
|
+
* that shows it; on real time, the page may change while it is pictured.
|
|
130
|
+
*/
|
|
131
|
+
at: Schema.Finite,
|
|
132
|
+
}) {}
|
|
133
|
+
|
|
134
|
+
/** What a film cost, from its shots. */
|
|
135
|
+
export class Summary extends Schema.Class<Summary>("effect-browser/FilmSummary")({
|
|
136
|
+
frames: Count,
|
|
137
|
+
retries: Count,
|
|
138
|
+
/** Real milliseconds, all frames' and the slowest one's. */
|
|
139
|
+
took: Millis,
|
|
140
|
+
slowest: Millis,
|
|
141
|
+
/** Every input sent, and every passage, in order. */
|
|
142
|
+
sent: Schema.Array(Sent),
|
|
143
|
+
passages: Schema.Array(Passage),
|
|
144
|
+
}) {}
|
|
145
|
+
|
|
146
|
+
const operation = "Film.frames";
|
|
147
|
+
|
|
148
|
+
function* rated(fps: number, from: number, to: number) {
|
|
149
|
+
const count = Math.round(((to - from) * fps) / 1000);
|
|
150
|
+
|
|
151
|
+
for (let index = 0; index < count; index++) yield from + (index * 1000) / fps;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const timesOf = (times: Times): Effect.Effect<Iterable<number>, BrowserError> => {
|
|
155
|
+
if ("fps" in times) {
|
|
156
|
+
const { fps, from = 0, to } = times;
|
|
157
|
+
|
|
158
|
+
return [fps, from, to].every(Number.isFinite) && fps > 0 && from >= 0 && to >= from
|
|
159
|
+
? Effect.succeed(rated(fps, from, to))
|
|
160
|
+
: refuse(
|
|
161
|
+
operation,
|
|
162
|
+
"a film's rate is positive and runs from a nonnegative time to a later one",
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
return times.every(
|
|
167
|
+
(t, index) => Number.isFinite(t) && t >= 0 && (index === 0 || t >= (times[index - 1] ?? t)),
|
|
168
|
+
)
|
|
169
|
+
? Effect.succeed(times)
|
|
170
|
+
: refuse(operation, "a film's times are finite, nonnegative and in order");
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
// `move` takes the page to film time `t`, showing `at` there; `drawn` says whether to draw its
|
|
174
|
+
// overlay. On held time, it says where the document is scrolled to. `skip` leaves real time that
|
|
175
|
+
// film time does not count.
|
|
176
|
+
interface Mover {
|
|
177
|
+
readonly move: (
|
|
178
|
+
t: number,
|
|
179
|
+
at: At,
|
|
180
|
+
drawn: boolean,
|
|
181
|
+
) => Effect.Effect<Point | undefined, BrowserError>;
|
|
182
|
+
readonly skip: (millis: number) => void;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
const mover = (page: Page, time: Time, overlay: Overlay | undefined): Mover => {
|
|
186
|
+
if (typeof time === "object" && "advance" in time) {
|
|
187
|
+
let now = 0;
|
|
188
|
+
|
|
189
|
+
const move: Mover["move"] = (t, { scroll, poses, overlay: content }, drawn) =>
|
|
190
|
+
time
|
|
191
|
+
.advance(Duration.millis(t - now), {
|
|
192
|
+
scroll,
|
|
193
|
+
poses,
|
|
194
|
+
overlay: drawn ? content : undefined,
|
|
195
|
+
})
|
|
196
|
+
.pipe(
|
|
197
|
+
Effect.tap(() =>
|
|
198
|
+
Effect.sync(() => {
|
|
199
|
+
now = t;
|
|
200
|
+
}),
|
|
201
|
+
),
|
|
202
|
+
);
|
|
203
|
+
|
|
204
|
+
return { move, skip: () => undefined };
|
|
205
|
+
}
|
|
206
|
+
let start: number | undefined;
|
|
207
|
+
|
|
208
|
+
const arrive =
|
|
209
|
+
time === "real"
|
|
210
|
+
? (t: number) =>
|
|
211
|
+
Effect.suspend(() => {
|
|
212
|
+
const now = monotonicMillis(page.clock);
|
|
213
|
+
|
|
214
|
+
start ??= now;
|
|
215
|
+
|
|
216
|
+
return Effect.sleep(Duration.millis(Math.max(0, start + t - now))).pipe(
|
|
217
|
+
Effect.provideService(Clock.Clock, page.clock),
|
|
218
|
+
);
|
|
219
|
+
})
|
|
220
|
+
: time.seek;
|
|
221
|
+
|
|
222
|
+
const move: Mover["move"] = (t, at, drawn) =>
|
|
223
|
+
at.scroll === undefined && at.poses === undefined
|
|
224
|
+
? arrive(t).pipe(
|
|
225
|
+
Effect.andThen(
|
|
226
|
+
drawn && at.overlay !== undefined && overlay !== undefined
|
|
227
|
+
? overlay.draw(at.overlay)
|
|
228
|
+
: Effect.void,
|
|
229
|
+
),
|
|
230
|
+
Effect.as(undefined),
|
|
231
|
+
)
|
|
232
|
+
: refuse(operation, "a film scrolls and poses the page only on held time");
|
|
233
|
+
|
|
234
|
+
return {
|
|
235
|
+
move,
|
|
236
|
+
skip: (millis) => {
|
|
237
|
+
if (start !== undefined) start += millis;
|
|
238
|
+
},
|
|
239
|
+
};
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
// A new screenshot, taken again after one that times out, with how many did.
|
|
243
|
+
const picture = (page: Page, image: Options["image"], retries: number) =>
|
|
244
|
+
Effect.gen(function* () {
|
|
245
|
+
let timedOut = 0;
|
|
246
|
+
|
|
247
|
+
const taken = yield* page.screenshot({ ...image, maxAge: 0 }).pipe(
|
|
248
|
+
Effect.tapError((error) =>
|
|
249
|
+
Effect.sync(() => (timedOut += error.reason._tag === "Timeout" ? 1 : 0)),
|
|
250
|
+
),
|
|
251
|
+
Effect.retry({ times: retries, while: (error) => error.reason._tag === "Timeout" }),
|
|
252
|
+
);
|
|
253
|
+
|
|
254
|
+
return { image: taken, retries: timedOut };
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
const keyOf = (content: Content | undefined) =>
|
|
258
|
+
content === undefined ? undefined : content._tag === "Svg" ? `svg:${content.markup}` : "empty";
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Frames of `page` at `times`, one at a time: each moves the page to its film time, draws what
|
|
262
|
+
* `at` gives there when it changed, and takes a new screenshot, again after one that times out.
|
|
263
|
+
*/
|
|
264
|
+
export const frames = <E = never>(
|
|
265
|
+
page: Page,
|
|
266
|
+
options: Options<E>,
|
|
267
|
+
): Stream.Stream<Shot, BrowserError | E> =>
|
|
268
|
+
Stream.unwrap(
|
|
269
|
+
Effect.gen(function* () {
|
|
270
|
+
const times = yield* timesOf(options.times);
|
|
271
|
+
const retries = options.retries ?? 2;
|
|
272
|
+
|
|
273
|
+
if (!Number.isSafeInteger(retries) || retries < 0)
|
|
274
|
+
return yield* refuse(operation, "retries must be a nonnegative safe integer");
|
|
275
|
+
const inputs = (options.inputs ?? []).toSorted((one, other) => one.t - other.t);
|
|
276
|
+
|
|
277
|
+
if (!inputs.every(({ t }) => Number.isFinite(t) && t >= 0))
|
|
278
|
+
return yield* refuse(operation, "an input's time is finite and nonnegative");
|
|
279
|
+
let next = 0;
|
|
280
|
+
const { move, skip } = mover(page, options.time, options.overlay);
|
|
281
|
+
const now = () => monotonicMillis(page.clock);
|
|
282
|
+
const passages: Array<Passage> = [];
|
|
283
|
+
|
|
284
|
+
const at = (t: number) =>
|
|
285
|
+
options.at === undefined ? Effect.succeed<At>({}) : options.at(t, { passages });
|
|
286
|
+
|
|
287
|
+
let shown: string | undefined;
|
|
288
|
+
let { document: seen, url: was } = yield* page.state;
|
|
289
|
+
let stepped = now();
|
|
290
|
+
|
|
291
|
+
// Take the page to film time `t`, and note when, as a passage's wait counts from it.
|
|
292
|
+
const step = (t: number, showing: At, drawn: boolean) =>
|
|
293
|
+
Effect.tap(move(t, showing, drawn), () => Effect.sync(() => (stepped = now())));
|
|
294
|
+
|
|
295
|
+
// A document the page moved to since the last frame, once it is ready.
|
|
296
|
+
const arrival = (t: number) =>
|
|
297
|
+
Effect.gen(function* () {
|
|
298
|
+
const { document, url } = yield* page.state;
|
|
299
|
+
|
|
300
|
+
if (document === seen) return undefined;
|
|
301
|
+
yield* page.ready();
|
|
302
|
+
const layout = yield* page.layout(options.picks ?? {});
|
|
303
|
+
const loadedAfter = now() - stepped;
|
|
304
|
+
|
|
305
|
+
skip(loadedAfter);
|
|
306
|
+
const passage = new Passage({ t, left: was, document, url, loadedAfter, layout });
|
|
307
|
+
|
|
308
|
+
[seen, was] = [document, url];
|
|
309
|
+
passages.push(passage);
|
|
310
|
+
|
|
311
|
+
return passage;
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
const send = ({ t, action, label }: Contact) =>
|
|
315
|
+
Effect.gen(function* () {
|
|
316
|
+
yield* step(t, yield* at(t), false);
|
|
317
|
+
const done = yield* page.perform(action);
|
|
318
|
+
const { document } = yield* page.state;
|
|
319
|
+
const target = Schema.is(ResolvedTarget)(done) ? done : undefined;
|
|
320
|
+
|
|
321
|
+
return new Sent({ t, label, action, target, document });
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
const shoot = (t: number, index: number) =>
|
|
325
|
+
Effect.gen(function* () {
|
|
326
|
+
const started = now();
|
|
327
|
+
const sent: Array<Sent> = [];
|
|
328
|
+
|
|
329
|
+
for (
|
|
330
|
+
let input = inputs[next];
|
|
331
|
+
input !== undefined && input.t <= t;
|
|
332
|
+
input = inputs[++next]
|
|
333
|
+
)
|
|
334
|
+
sent.push(yield* send(input));
|
|
335
|
+
const passage = yield* arrival(t);
|
|
336
|
+
const showing = yield* at(t);
|
|
337
|
+
const key = keyOf(showing.overlay);
|
|
338
|
+
|
|
339
|
+
if (key !== undefined && options.overlay === undefined)
|
|
340
|
+
return yield* refuse(operation, "drawing needs the page's overlay, open, in `overlay`");
|
|
341
|
+
const scroll = yield* step(t, showing, key !== undefined && key !== shown);
|
|
342
|
+
|
|
343
|
+
shown = key ?? shown;
|
|
344
|
+
const taken = yield* picture(page, options.image, retries);
|
|
345
|
+
const pictured = now();
|
|
346
|
+
const { document, url } = yield* page.state;
|
|
347
|
+
|
|
348
|
+
return new Shot({
|
|
349
|
+
index,
|
|
350
|
+
t,
|
|
351
|
+
image: taken.image,
|
|
352
|
+
document,
|
|
353
|
+
url,
|
|
354
|
+
scroll,
|
|
355
|
+
sent,
|
|
356
|
+
passage,
|
|
357
|
+
retries: taken.retries,
|
|
358
|
+
took: pictured - started,
|
|
359
|
+
at: pictured,
|
|
360
|
+
});
|
|
361
|
+
});
|
|
362
|
+
|
|
363
|
+
return Stream.fromIterable(times).pipe(
|
|
364
|
+
Stream.zipWithIndex,
|
|
365
|
+
Stream.mapEffect(([t, index]) => shoot(t, index)),
|
|
366
|
+
);
|
|
367
|
+
}),
|
|
368
|
+
);
|
|
369
|
+
|
|
370
|
+
/** Run a film's shots, which a caller has usually written out on the way, to what they cost. */
|
|
371
|
+
export const summary = <E, R>(shots: Stream.Stream<Shot, E, R>): Effect.Effect<Summary, E, R> =>
|
|
372
|
+
Stream.runFold(
|
|
373
|
+
shots,
|
|
374
|
+
() => new Summary({ frames: 0, retries: 0, took: 0, slowest: 0, sent: [], passages: [] }),
|
|
375
|
+
(sum, shot) =>
|
|
376
|
+
new Summary({
|
|
377
|
+
frames: sum.frames + 1,
|
|
378
|
+
retries: sum.retries + shot.retries,
|
|
379
|
+
took: sum.took + shot.took,
|
|
380
|
+
slowest: Math.max(sum.slowest, shot.took),
|
|
381
|
+
sent: [...sum.sent, ...shot.sent],
|
|
382
|
+
passages: shot.passage === undefined ? sum.passages : [...sum.passages, shot.passage],
|
|
383
|
+
}),
|
|
384
|
+
);
|
package/src/index.ts
CHANGED
|
@@ -8,7 +8,11 @@ export * as Change from "./Change.ts";
|
|
|
8
8
|
export * as Clock from "./Clock.ts";
|
|
9
9
|
export * as Frame from "./Frame.ts";
|
|
10
10
|
export * as Geometry from "./Geometry.ts";
|
|
11
|
+
export * as Layout from "./Layout.ts";
|
|
12
|
+
export * as Overlay from "./Overlay.ts";
|
|
11
13
|
export * as Page from "./Page.ts";
|
|
14
|
+
export * as PageTime from "./PageTime.ts";
|
|
15
|
+
export * as Pose from "./Pose.ts";
|
|
12
16
|
export * as Snapshot from "./Snapshot.ts";
|
|
13
17
|
export * as Style from "./Style.ts";
|
|
14
18
|
export * as Window from "./Window.ts";
|
|
@@ -6,7 +6,7 @@ import { Deferred, Duration, Effect, Exit, Option, Ref } from "effect";
|
|
|
6
6
|
|
|
7
7
|
import { recorded, nameOf, type Action as ActionValue } from "../../Action.ts";
|
|
8
8
|
import { BrowserError, PolicyTimeout, Timeout } from "../../BrowserError.ts";
|
|
9
|
-
import { Action, Subject } from "../../BrowserEvent.ts";
|
|
9
|
+
import { Action, ActionAnnounced, Subject } from "../../BrowserEvent.ts";
|
|
10
10
|
import type * as BrowserClock from "../../Clock.ts";
|
|
11
11
|
import { type Point, redacted, type ResolvedTarget } from "../../Page.ts";
|
|
12
12
|
import { Current, type Style, validated } from "../../Style.ts";
|
|
@@ -32,6 +32,11 @@ export interface InputMarks {
|
|
|
32
32
|
readonly at: (point: Point) => Effect.Effect<void>;
|
|
33
33
|
/** What the input acts on, and for a drag where it ends, as the page names them now. */
|
|
34
34
|
readonly on: (subject: Named, to?: Named) => Effect.Effect<void>;
|
|
35
|
+
/**
|
|
36
|
+
* The pointer is about to travel to the action's target at `to`: announce what the action acts
|
|
37
|
+
* on, and wait for the style's lead.
|
|
38
|
+
*/
|
|
39
|
+
readonly announce: (to: Point) => Effect.Effect<void>;
|
|
35
40
|
/** The action's text is not bound for a secret field, so its record may keep it. */
|
|
36
41
|
readonly reveal: Effect.Effect<void>;
|
|
37
42
|
readonly input: Replies.Run;
|
|
@@ -145,6 +150,29 @@ const admission = (page: PageContext, pending: Set<Deferred.Deferred<void>>, nam
|
|
|
145
150
|
};
|
|
146
151
|
};
|
|
147
152
|
|
|
153
|
+
/** Announce an action from what it has found, then wait for its style's lead. */
|
|
154
|
+
const announcing =
|
|
155
|
+
(
|
|
156
|
+
page: PageContext,
|
|
157
|
+
name: Action["name"],
|
|
158
|
+
style: Style,
|
|
159
|
+
acted: Ref.Ref<Pick<Action, "subject" | "to" | "box">>,
|
|
160
|
+
) =>
|
|
161
|
+
(to: Point) =>
|
|
162
|
+
Effect.gen(function* () {
|
|
163
|
+
const event = new ActionAnnounced({
|
|
164
|
+
at: page.now(),
|
|
165
|
+
page: page.id,
|
|
166
|
+
name,
|
|
167
|
+
correlation: yield* Correlation,
|
|
168
|
+
...(yield* Ref.get(acted)),
|
|
169
|
+
...to,
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
page.publish(event);
|
|
173
|
+
if (style.lead !== undefined) yield* style.lead(event);
|
|
174
|
+
});
|
|
175
|
+
|
|
148
176
|
/** Close a run on every exit while preserving its native replies for the page's next input. */
|
|
149
177
|
const useRun = <A>(
|
|
150
178
|
page: PageContext,
|
|
@@ -219,6 +247,7 @@ export const make = (page: PageContext, sender: Dispatch) => {
|
|
|
219
247
|
touched: touch,
|
|
220
248
|
at: (point: Point) => Ref.set(at, Option.some(point)),
|
|
221
249
|
on: (subject: Named, to?: Named) => Ref.set(acted, actedOn(subject, to)),
|
|
250
|
+
announce: announcing(page, name, style, acted),
|
|
222
251
|
reveal: Effect.sync(() => {
|
|
223
252
|
revealed = true;
|
|
224
253
|
}),
|
|
@@ -362,8 +391,7 @@ export const make = (page: PageContext, sender: Dispatch) => {
|
|
|
362
391
|
box,
|
|
363
392
|
text:
|
|
364
393
|
info.text === undefined ? undefined : revealed ? info.text.slice(0, 200) : redacted,
|
|
365
|
-
|
|
366
|
-
y: Option.getOrUndefined(Option.map(point, (p) => p.y)),
|
|
394
|
+
...Option.match(point, { onNone: () => ({}), onSome: ({ x, y }) => ({ x, y }) }),
|
|
367
395
|
ok: Exit.isSuccess(exit),
|
|
368
396
|
dispatched,
|
|
369
397
|
error: Option.match(failure, {
|
|
@@ -18,18 +18,21 @@ export const make = (page: PageContext, dispatch: Dispatch, viewport: Viewport)
|
|
|
18
18
|
const { id, pointer, publish, now, span } = page;
|
|
19
19
|
const { inputClocks, inputCall, dispatchMouse, sendMouse } = dispatch;
|
|
20
20
|
|
|
21
|
-
// Travel toward a press only prepares the action
|
|
22
|
-
// button it has already
|
|
21
|
+
// Travel toward a press only prepares the action, as does travel that reveals a target out of
|
|
22
|
+
// view before it is found; a hover is its travel, and a drag holds the button it has already
|
|
23
|
+
// pressed. Travel to the action's own target announces it first.
|
|
23
24
|
const moveTo = (
|
|
24
25
|
operation: string,
|
|
25
26
|
marks: InputMarks,
|
|
26
27
|
to: Point,
|
|
27
28
|
cursor?: string,
|
|
28
|
-
travel: "approach" | "hover" | "drag" = "approach",
|
|
29
|
+
travel: "approach" | "reveal" | "hover" | "drag" = "approach",
|
|
29
30
|
) =>
|
|
30
31
|
Effect.gen(function* () {
|
|
31
32
|
const dragging = travel === "drag";
|
|
32
33
|
const { style } = marks;
|
|
34
|
+
|
|
35
|
+
if (travel === "approach" || travel === "hover") yield* marks.announce(to);
|
|
33
36
|
const drawn = style.pointer ?? pointer;
|
|
34
37
|
const size = yield* viewport.viewportFor(operation);
|
|
35
38
|
|
|
@@ -80,7 +83,7 @@ export const make = (page: PageContext, dispatch: Dispatch, viewport: Viewport)
|
|
|
80
83
|
const remaining = at + sample.afterMillis - now();
|
|
81
84
|
|
|
82
85
|
if (remaining > 0) yield* Effect.sleep(Duration.millis(remaining));
|
|
83
|
-
yield* travel === "approach" ? marks.touched : marks.sent;
|
|
86
|
+
yield* travel === "approach" || travel === "reveal" ? marks.touched : marks.sent;
|
|
84
87
|
yield* inputCall(
|
|
85
88
|
operation,
|
|
86
89
|
run.send(() =>
|