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.
- package/README.md +124 -5
- package/dist/ActionPort.d.mts +1 -1
- package/dist/ActionPort.mjs +1 -1
- package/dist/{Browser-Cq2K1FEA.mjs → Browser-CAQFhTkM.mjs} +561 -334
- 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-BTeO0Hiz.mjs → connection-C_jWYIwe.mjs} +2 -2
- package/dist/{connection-BTeO0Hiz.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/supervisor/Supervisor.mjs +3 -1
- package/dist/supervisor/Supervisor.mjs.map +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 +35 -5
- 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/identity.ts +6 -5
- 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/supervisor/runtime.ts +5 -1
- package/src/testing/page.ts +5 -0
- package/dist/Browser-Cq2K1FEA.mjs.map +0 -1
- package/dist/Page-BF5izr8R.mjs.map +0 -1
- package/dist/Stillness-CNlvayIo.mjs.map +0 -1
|
@@ -6,30 +6,15 @@
|
|
|
6
6
|
* frame. So a canvas mounted blank, or a spinner alone, is still loading. A screen that only says
|
|
7
7
|
* "Loading…" in words reads as ready, and a WebGL canvas drawn once, without keeping its drawing,
|
|
8
8
|
* reads as blank. Asked for a quiet spell, where the page's changes are recorded, nothing in view
|
|
9
|
-
* may have changed for that long either.
|
|
9
|
+
* may have changed for that long either. On a page whose time is held (see `clock.inpage.ts`), an
|
|
10
|
+
* animation paused part way is still animating: held time has yet to finish it. After input, it
|
|
11
|
+
* waits a task and a frame. See `names.inpage.ts` for what a page-side part may use.
|
|
10
12
|
*/
|
|
11
|
-
import { Schema } from "effect";
|
|
12
|
-
|
|
13
13
|
import type { History } from "../timeline/history.inpage.ts";
|
|
14
|
+
import type { Readiness } from "./ready.ts";
|
|
14
15
|
import type { Texts } from "./text.inpage.ts";
|
|
15
16
|
import type { Walk } from "./walk.inpage.ts";
|
|
16
17
|
|
|
17
|
-
/** What the page is still waiting for; none when it is ready. */
|
|
18
|
-
export const ReadinessSchema = Schema.Array(
|
|
19
|
-
Schema.Literals([
|
|
20
|
-
"load",
|
|
21
|
-
"paint",
|
|
22
|
-
"animations",
|
|
23
|
-
"images",
|
|
24
|
-
"fonts",
|
|
25
|
-
"busy",
|
|
26
|
-
"content",
|
|
27
|
-
"changing",
|
|
28
|
-
]),
|
|
29
|
-
);
|
|
30
|
-
|
|
31
|
-
export type Readiness = typeof ReadinessSchema.Type;
|
|
32
|
-
|
|
33
18
|
export const ready = (walked: Walk, texts: Texts, kept: History) => {
|
|
34
19
|
const { inView, visible } = walked;
|
|
35
20
|
// A canvas is read through a small copy: reading it directly would give it a context of ours.
|
|
@@ -85,10 +70,16 @@ export const ready = (walked: Walk, texts: Texts, kept: History) => {
|
|
|
85
70
|
};
|
|
86
71
|
|
|
87
72
|
// In a frame, before it is drawn: a canvas drawn every frame still holds its drawing then.
|
|
88
|
-
const check = (quietMillis: number): Promise<Readiness> =>
|
|
73
|
+
const check = (quietMillis: number, clock: string | null): Promise<Readiness> =>
|
|
89
74
|
painted().then((paints) => {
|
|
90
75
|
const waiting: Array<Readiness[number]> = [];
|
|
91
76
|
|
|
77
|
+
const held =
|
|
78
|
+
clock !== null &&
|
|
79
|
+
!document.dispatchEvent(
|
|
80
|
+
new CustomEvent(clock, { detail: { op: "holds" }, cancelable: true }),
|
|
81
|
+
);
|
|
82
|
+
|
|
92
83
|
if (document.readyState === "loading") waiting.push("load");
|
|
93
84
|
if (!paints) waiting.push("paint");
|
|
94
85
|
// An endless animation, such as a pulsing dot, never ends, so only those that end count.
|
|
@@ -97,7 +88,7 @@ export const ready = (walked: Walk, texts: Texts, kept: History) => {
|
|
|
97
88
|
const effect = animation.effect;
|
|
98
89
|
|
|
99
90
|
return (
|
|
100
|
-
animation.playState === "running" &&
|
|
91
|
+
(animation.playState === "running" || (held && animation.playState === "paused")) &&
|
|
101
92
|
effect !== null &&
|
|
102
93
|
Number.isFinite(effect.getComputedTiming().endTime) &&
|
|
103
94
|
"target" in effect &&
|
|
@@ -122,11 +113,15 @@ export const ready = (walked: Walk, texts: Texts, kept: History) => {
|
|
|
122
113
|
* Check until the page is ready, or for `millis`, and say what it is still waiting for; with
|
|
123
114
|
* `quietMillis`, until nothing the record saw in view has changed for that long, too.
|
|
124
115
|
*/
|
|
125
|
-
const wait = async (
|
|
116
|
+
const wait = async (
|
|
117
|
+
millis: number,
|
|
118
|
+
quietMillis = 0,
|
|
119
|
+
clock: string | null = null,
|
|
120
|
+
): Promise<Readiness> => {
|
|
126
121
|
const until = performance.now() + millis;
|
|
127
122
|
|
|
128
123
|
for (;;) {
|
|
129
|
-
const waiting = await check(quietMillis);
|
|
124
|
+
const waiting = await check(quietMillis, clock);
|
|
130
125
|
|
|
131
126
|
if (waiting.length === 0 || performance.now() >= until) return waiting;
|
|
132
127
|
const { promise, resolve } = Promise.withResolvers<void>();
|
|
@@ -1,11 +1,26 @@
|
|
|
1
1
|
/** Document readiness and content quiet, independent of screen-capture features. */
|
|
2
|
-
import { Duration, Effect, Schedule } from "effect";
|
|
2
|
+
import { Duration, Effect, Schedule, Schema } from "effect";
|
|
3
3
|
|
|
4
4
|
import { Timeout, failWith, refuse } from "../../BrowserError.ts";
|
|
5
5
|
import type { ReadyOptions } from "../../Page.ts";
|
|
6
6
|
import { type Bridge, scriptCall } from "../page/bridge.ts";
|
|
7
7
|
import { contextGone, decodeWith, type PageContext } from "../page/context.ts";
|
|
8
|
-
|
|
8
|
+
|
|
9
|
+
/** What the page is still waiting for; none when it is ready. */
|
|
10
|
+
const ReadinessSchema = Schema.Array(
|
|
11
|
+
Schema.Literals([
|
|
12
|
+
"load",
|
|
13
|
+
"paint",
|
|
14
|
+
"animations",
|
|
15
|
+
"images",
|
|
16
|
+
"fonts",
|
|
17
|
+
"busy",
|
|
18
|
+
"content",
|
|
19
|
+
"changing",
|
|
20
|
+
]),
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
export type Readiness = typeof ReadinessSchema.Type;
|
|
9
24
|
|
|
10
25
|
export const make =
|
|
11
26
|
(page: PageContext, bridge: Bridge) =>
|
|
@@ -21,7 +36,12 @@ export const make =
|
|
|
21
36
|
Effect.suspend(() =>
|
|
22
37
|
bridge.evaluate(
|
|
23
38
|
"ready",
|
|
24
|
-
scriptCall(
|
|
39
|
+
scriptCall(
|
|
40
|
+
"ready",
|
|
41
|
+
Math.max(0, Math.round(until - page.now())),
|
|
42
|
+
quietMillis,
|
|
43
|
+
page.settings.pageTime ?? null,
|
|
44
|
+
),
|
|
25
45
|
),
|
|
26
46
|
).pipe(
|
|
27
47
|
Effect.retry({ while: contextGone, schedule: Schedule.spaced(Duration.millis(10)) }),
|
|
@@ -4,9 +4,8 @@
|
|
|
4
4
|
* that was secret when the library saw it, such as a password its page now reveals. Text, and the
|
|
5
5
|
* outline, are cut at a line. See `names.inpage.ts` for what a page-side part may use.
|
|
6
6
|
*/
|
|
7
|
-
import { Schema } from "effect";
|
|
8
|
-
|
|
9
7
|
import type { Names } from "./names.inpage.ts";
|
|
8
|
+
import type { TextResult } from "./reading.ts";
|
|
10
9
|
import type { Walk } from "./walk.inpage.ts";
|
|
11
10
|
|
|
12
11
|
export interface TextRequest {
|
|
@@ -16,18 +15,6 @@ export interface TextRequest {
|
|
|
16
15
|
readonly unmask: boolean;
|
|
17
16
|
}
|
|
18
17
|
|
|
19
|
-
/** What `read` sends back, or null when its ref no longer names an element. */
|
|
20
|
-
export const TextResultSchema = Schema.NullOr(
|
|
21
|
-
Schema.Struct({
|
|
22
|
-
text: Schema.String,
|
|
23
|
-
truncated: Schema.Boolean,
|
|
24
|
-
url: Schema.String,
|
|
25
|
-
title: Schema.String,
|
|
26
|
-
}),
|
|
27
|
-
);
|
|
28
|
-
|
|
29
|
-
export type TextResult = typeof TextResultSchema.Type;
|
|
30
|
-
|
|
31
18
|
export const text = (names: Names, walked: Walk) => {
|
|
32
19
|
const { isHtml, isInput, isSecret, isSelect, isTextArea, lookup } = names;
|
|
33
20
|
|
|
@@ -8,11 +8,12 @@
|
|
|
8
8
|
* the input's own doing, by `Change.cause`'s rule. See `names.inpage.ts` for what a page-side part
|
|
9
9
|
* may use.
|
|
10
10
|
*/
|
|
11
|
-
import { Schema } from "effect";
|
|
12
11
|
|
|
13
|
-
import { Change } from "../../Change.ts";
|
|
12
|
+
import type { Change } from "../../Change.ts";
|
|
14
13
|
import type { Known, ContextReader } from "../reading/context.inpage.ts";
|
|
15
14
|
import type { Names } from "../reading/names.inpage.ts";
|
|
15
|
+
import type { Walk } from "../reading/walk.inpage.ts";
|
|
16
|
+
import type { ChangesResult } from "./changes.ts";
|
|
16
17
|
import type { Folded } from "./fold.inpage.ts";
|
|
17
18
|
import type { History } from "./history.inpage.ts";
|
|
18
19
|
import type { Marks } from "./marks.inpage.ts";
|
|
@@ -26,21 +27,9 @@ export interface ChangesRequest {
|
|
|
26
27
|
readonly unmask: boolean;
|
|
27
28
|
}
|
|
28
29
|
|
|
29
|
-
/**
|
|
30
|
-
* What a read sends back: its window and the record's state, and each change as `Change` encodes
|
|
31
|
-
* it, all on the page's clock.
|
|
32
|
-
*/
|
|
33
|
-
export const ChangesResultSchema = Schema.Struct({
|
|
34
|
-
until: Schema.Finite,
|
|
35
|
-
from: Schema.Finite,
|
|
36
|
-
dropped: Schema.Int,
|
|
37
|
-
records: Schema.Array(Change),
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
export type ChangesResult = typeof ChangesResultSchema.Encoded;
|
|
41
|
-
|
|
42
30
|
export const changes = (
|
|
43
31
|
names: Names,
|
|
32
|
+
walked: Walk,
|
|
44
33
|
placing: ContextReader,
|
|
45
34
|
kept: History,
|
|
46
35
|
seeing: Sight,
|
|
@@ -151,6 +140,8 @@ export const changes = (
|
|
|
151
140
|
const { track, kind, before, after, lowest, highest, ...times } = one;
|
|
152
141
|
const element = track.key instanceof Element ? track.key : null;
|
|
153
142
|
const where = element?.isConnected === true ? element : (marking.placeOf(track.key) ?? null);
|
|
143
|
+
// What is hidden is drawn nowhere, so it has no box.
|
|
144
|
+
const box = where === null ? undefined : walked.boxOf(where);
|
|
154
145
|
const role = element === null ? null : roleOf(element);
|
|
155
146
|
const field = kind === "value";
|
|
156
147
|
|
|
@@ -176,6 +167,7 @@ export const changes = (
|
|
|
176
167
|
tag: element === null ? "title" : element.tagName.toLowerCase(),
|
|
177
168
|
context: kind === "title" || where === null ? {} : placing.contextOf(where, known),
|
|
178
169
|
},
|
|
170
|
+
box: box === undefined || (box.width === 0 && box.height === 0) ? undefined : box,
|
|
179
171
|
before: masked(before),
|
|
180
172
|
after: masked(after),
|
|
181
173
|
lowest: field ? undefined : lowest,
|
|
@@ -17,7 +17,20 @@ import type { Frame } from "../../Frame.ts";
|
|
|
17
17
|
import type { ChangesOptions } from "../../Page.ts";
|
|
18
18
|
import { type Bridge, scriptCall } from "../page/bridge.ts";
|
|
19
19
|
import { decodeWith, type PageContext } from "../page/context.ts";
|
|
20
|
-
import {
|
|
20
|
+
import type { ChangesRequest } from "./changes.inpage.ts";
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* What a read sends back: its window and the record's state, and each change as `Change` encodes
|
|
24
|
+
* it, all on the page's clock.
|
|
25
|
+
*/
|
|
26
|
+
const ChangesResultSchema = Schema.Struct({
|
|
27
|
+
until: Schema.Finite,
|
|
28
|
+
from: Schema.Finite,
|
|
29
|
+
dropped: Schema.Int,
|
|
30
|
+
records: Schema.Array(Change),
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
export type ChangesResult = typeof ChangesResultSchema.Encoded;
|
|
21
34
|
|
|
22
35
|
const isChanges = Schema.is(Changes);
|
|
23
36
|
|
|
@@ -4,8 +4,9 @@
|
|
|
4
4
|
* nobody has read for two minutes. While it runs, a MutationObserver hands each batch to
|
|
5
5
|
* `marks.inpage.ts`, and an IntersectionObserver judges as the page renders whether what was marked
|
|
6
6
|
* was in view (`sight.inpage.ts`). A field reports its value as it is edited, a secret one only as
|
|
7
|
-
* `••••`, and trusted pointer and key input is kept, for a read to name
|
|
8
|
-
* is read: no walk, no words, no layout. See `names.inpage.ts` for what
|
|
7
|
+
* `••••`, and trusted pointer and key input is kept, or input noted as such, for a read to name
|
|
8
|
+
* causes by. Nothing unmarked is read: no walk, no words, no layout. See `names.inpage.ts` for what
|
|
9
|
+
* a page-side part may use.
|
|
9
10
|
*/
|
|
10
11
|
import type { Names } from "../reading/names.inpage.ts";
|
|
11
12
|
import type { Texts } from "../reading/text.inpage.ts";
|
|
@@ -63,13 +64,16 @@ export const record = (
|
|
|
63
64
|
if (sample !== undefined) seeing.look(field, sample);
|
|
64
65
|
};
|
|
65
66
|
|
|
67
|
+
// Protocol timestamps are mapped estimates; observation and mutations share this clock.
|
|
68
|
+
const note = (target: Element) => {
|
|
69
|
+
inputs.push({ at: epoch(), target });
|
|
70
|
+
if (inputs.length > 8) inputs.shift();
|
|
71
|
+
};
|
|
72
|
+
|
|
66
73
|
const onInput = (event: Event) => {
|
|
67
74
|
const target = targetOf(event);
|
|
68
75
|
|
|
69
|
-
if (
|
|
70
|
-
// Protocol timestamps are mapped estimates; observation and mutations share this clock.
|
|
71
|
-
inputs.push({ at: epoch(), target });
|
|
72
|
-
if (inputs.length > 8) inputs.shift();
|
|
76
|
+
if (event.isTrusted && target !== undefined) note(target);
|
|
73
77
|
};
|
|
74
78
|
|
|
75
79
|
const listeners = [
|
|
@@ -129,6 +133,11 @@ export const record = (
|
|
|
129
133
|
document.addEventListener("DOMContentLoaded", begin, { once: true });
|
|
130
134
|
else begin();
|
|
131
135
|
},
|
|
136
|
+
/**
|
|
137
|
+
* Keep an input at `target` now, as a trusted one is kept: what a site does through its own
|
|
138
|
+
* app, whose events the page sees as untrusted, so its changes can name their cause.
|
|
139
|
+
*/
|
|
140
|
+
note,
|
|
132
141
|
inputs: (): ReadonlyArray<{ readonly at: number; readonly target: Element }> => inputs,
|
|
133
142
|
};
|
|
134
143
|
};
|
|
@@ -8,6 +8,7 @@ import { type Clock, Deferred, Duration, Effect, MutableRef, Option, Semaphore }
|
|
|
8
8
|
|
|
9
9
|
import { methods } from "../ActionPort.ts";
|
|
10
10
|
import { Busy, refuse, undispatched } from "../BrowserError.ts";
|
|
11
|
+
import type { ActionAnnounced } from "../BrowserEvent.ts";
|
|
11
12
|
import { monotonicMillis } from "../Clock.ts";
|
|
12
13
|
import type { Page, Point } from "../Page.ts";
|
|
13
14
|
import * as Style from "../Style.ts";
|
|
@@ -32,6 +33,12 @@ export const human: Pacing = {
|
|
|
32
33
|
export interface Options {
|
|
33
34
|
readonly pacing?: Pacing | undefined;
|
|
34
35
|
readonly motion?: Motion.Planner | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* After a view's action has announced its target, and before its pointer travels there, wait
|
|
38
|
+
* for this: time for whatever is shown performing the input, such as a character, to arrive. It
|
|
39
|
+
* comes after the reaction's wait, holds the page's turn and spends the action's deadline.
|
|
40
|
+
*/
|
|
41
|
+
readonly lead?: ((announced: ActionAnnounced) => Effect.Effect<void>) | undefined;
|
|
35
42
|
}
|
|
36
43
|
|
|
37
44
|
export type View = Page;
|
|
@@ -75,6 +82,8 @@ export const make = Effect.fn("Presentation.make")(function* (options: Options =
|
|
|
75
82
|
wordsPerMinute: pacing.wordsPerMinute,
|
|
76
83
|
});
|
|
77
84
|
|
|
85
|
+
const { lead } = options;
|
|
86
|
+
|
|
78
87
|
const views = new WeakMap<Page, View>();
|
|
79
88
|
|
|
80
89
|
let last:
|
|
@@ -94,6 +103,10 @@ export const make = Effect.fn("Presentation.make")(function* (options: Options =
|
|
|
94
103
|
|
|
95
104
|
const style: Style.Style = {
|
|
96
105
|
...planned,
|
|
106
|
+
lead:
|
|
107
|
+
lead === undefined
|
|
108
|
+
? undefined
|
|
109
|
+
: (announced) => lead(announced).pipe(Effect.withSpan("Presentation.lead")),
|
|
97
110
|
withInput:
|
|
98
111
|
({ operation, wait, failFast }) =>
|
|
99
112
|
(effect) =>
|
package/src/stillness/Pixels.ts
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
/// <reference path="./utilsBundle.d.ts" />
|
|
14
14
|
import { jpegjs } from "playwright-core/lib/utilsBundle";
|
|
15
15
|
|
|
16
|
+
import type { Box } from "../BrowserEvent.ts";
|
|
16
17
|
import type { Frame } from "../Frame.ts";
|
|
17
18
|
|
|
18
19
|
/** A decoded frame: RGBA, `width` pixels a row. */
|
|
@@ -60,6 +61,31 @@ export const background = (pictures: ReadonlyArray<Picture>): ReadonlySet<number
|
|
|
60
61
|
);
|
|
61
62
|
};
|
|
62
63
|
|
|
64
|
+
/**
|
|
65
|
+
* The blocks a picture's boxes cover, and those around them, for boxes in CSS pixels and `scale`
|
|
66
|
+
* picture pixels to a CSS pixel: where an overlay draws, which is not the page's motion.
|
|
67
|
+
*/
|
|
68
|
+
export const covering = (boxes: ReadonlyArray<Box>, scale: number, picture: Picture) => {
|
|
69
|
+
const columns = Math.ceil(picture.width / 16);
|
|
70
|
+
const rows = Math.ceil(picture.height / 16);
|
|
71
|
+
const blocks = new Set<number>();
|
|
72
|
+
|
|
73
|
+
const block = (at: number, count: number) =>
|
|
74
|
+
Math.min(count - 1, Math.max(0, Math.floor(at / 16)));
|
|
75
|
+
|
|
76
|
+
for (const { x, y, width, height } of boxes)
|
|
77
|
+
for (let row = block(y * scale, rows) - 1; row <= block((y + height) * scale, rows) + 1; row++)
|
|
78
|
+
for (
|
|
79
|
+
let column = block(x * scale, columns) - 1;
|
|
80
|
+
column <= block((x + width) * scale, columns) + 1;
|
|
81
|
+
column++
|
|
82
|
+
)
|
|
83
|
+
if (row >= 0 && row < rows && column >= 0 && column < columns)
|
|
84
|
+
blocks.add(row * columns + column);
|
|
85
|
+
|
|
86
|
+
return blocks;
|
|
87
|
+
};
|
|
88
|
+
|
|
63
89
|
/** Whether anything moved from one picture to another outside the background. */
|
|
64
90
|
export const stirs = (from: Picture, to: Picture, mask: ReadonlySet<number>) =>
|
|
65
91
|
moved(from, to).some((block) => !mask.has(block));
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { Clock, Duration, Effect, Option, Schedule, Stream } from "effect";
|
|
3
3
|
|
|
4
4
|
import { Failed, refuse, Timeout, undispatched } from "../BrowserError.ts";
|
|
5
|
+
import type { Box } from "../BrowserEvent.ts";
|
|
5
6
|
import { monotonicMillis } from "../Clock.ts";
|
|
6
7
|
import type { Frame } from "../Frame.ts";
|
|
7
8
|
import type { Page } from "../Page.ts";
|
|
@@ -60,21 +61,36 @@ const observe = (page: Page, options: Options, timeout: Duration.Duration) =>
|
|
|
60
61
|
|
|
61
62
|
const sampled = before.filter((_, index) => index % Math.ceil(before.length / 8) === 0);
|
|
62
63
|
const mask = Motion.background(yield* Effect.forEach(sampled, decoded));
|
|
64
|
+
// Where the page's overlay draws is not the page's motion: while it shows, frames are
|
|
65
|
+
// compared, as in the foreground, outside everywhere it has drawn during the wait.
|
|
66
|
+
let width: number | undefined;
|
|
67
|
+
const covered = new Set(mask);
|
|
68
|
+
|
|
69
|
+
const outside = (seen: Motion.Picture, overlay: ReadonlyArray<Box> | undefined) =>
|
|
70
|
+
Effect.gen(function* () {
|
|
71
|
+
if (overlay === undefined) return covered;
|
|
72
|
+
width ??= (yield* page.viewport).width;
|
|
73
|
+
for (const block of Motion.covering(overlay, seen.width / width, seen))
|
|
74
|
+
covered.add(block);
|
|
75
|
+
|
|
76
|
+
return covered;
|
|
77
|
+
});
|
|
63
78
|
|
|
64
79
|
// How long the screen has been still: since a frame, or an unanswered acknowledgement. In
|
|
65
80
|
// the foreground, since a frame moved outside the background, or acknowledgements went
|
|
66
81
|
// unanswered with no frame coming.
|
|
67
82
|
const look = Effect.gen(function* () {
|
|
68
83
|
const stats = yield* capture.stats();
|
|
69
|
-
const latest =
|
|
84
|
+
const { frame: latest, overlay } = yield* page.state;
|
|
85
|
+
const comparing = foreground || overlay !== undefined;
|
|
70
86
|
const arrived = stats.received !== counts.received;
|
|
71
87
|
const unseen = stats.accepted - counts.accepted;
|
|
72
88
|
|
|
73
89
|
counts = stats;
|
|
74
90
|
if (latest === undefined || !capture.isCurrent(latest)) stirred = now();
|
|
75
|
-
else if (!
|
|
91
|
+
else if (!comparing ? arrived || stats.ackBacklog > 0 : !arrived && stats.ackBacklog > 0)
|
|
76
92
|
stirred = now();
|
|
77
|
-
else if (
|
|
93
|
+
else if (comparing && (unseen > 0 || reference === undefined)) {
|
|
78
94
|
// A move and its return between looks both count. Bound decoding; any frames lost
|
|
79
95
|
// from history, or beyond this batch, deny a quiet spell rather than hiding motion.
|
|
80
96
|
const frames = (yield* page.recentFrames).slice(-Math.max(1, Math.min(8, unseen)));
|
|
@@ -83,7 +99,10 @@ const observe = (page: Page, options: Options, timeout: Duration.Duration) =>
|
|
|
83
99
|
for (const frame of frames) {
|
|
84
100
|
const seen = yield* decoded(frame);
|
|
85
101
|
|
|
86
|
-
if (
|
|
102
|
+
if (
|
|
103
|
+
reference === undefined ||
|
|
104
|
+
Motion.stirs(reference, seen, yield* outside(seen, overlay))
|
|
105
|
+
) {
|
|
87
106
|
reference = seen;
|
|
88
107
|
stirred = now();
|
|
89
108
|
}
|
|
@@ -105,7 +124,13 @@ const observe = (page: Page, options: Options, timeout: Duration.Duration) =>
|
|
|
105
124
|
const before = counts.received;
|
|
106
125
|
|
|
107
126
|
yield* Effect.all([settled(), capture.sync], { concurrency: 2, discard: true });
|
|
108
|
-
if (
|
|
127
|
+
if (
|
|
128
|
+
(yield* look) >= millis &&
|
|
129
|
+
(foreground ||
|
|
130
|
+
(yield* page.state).overlay !== undefined ||
|
|
131
|
+
counts.received === before)
|
|
132
|
+
)
|
|
133
|
+
return;
|
|
109
134
|
}
|
|
110
135
|
});
|
|
111
136
|
|
|
@@ -58,6 +58,9 @@ export const opening =
|
|
|
58
58
|
(number: number) => {
|
|
59
59
|
let attempt = 0;
|
|
60
60
|
let began = false;
|
|
61
|
+
// The last attempt's typed failure. Since Effect 4.0.6, `Effect.retry` rethrows a cause that
|
|
62
|
+
// also holds a defect with its failures made defects, so its exit no longer carries it.
|
|
63
|
+
let failed: Option.Option<E> = Option.none();
|
|
61
64
|
|
|
62
65
|
const once: Effect.Effect<boolean, E> = Effect.uninterruptible(
|
|
63
66
|
Effect.gen(function* () {
|
|
@@ -92,6 +95,7 @@ export const opening =
|
|
|
92
95
|
const cause = Exit.isFailure(closed) ? Cause.combine(exit.cause, closed.cause) : exit.cause;
|
|
93
96
|
const error = Cause.findErrorOption(cause);
|
|
94
97
|
|
|
98
|
+
failed = error;
|
|
95
99
|
if (Option.isSome(error))
|
|
96
100
|
yield* apply({ _tag: "Failed", number, attempt, error: error.value });
|
|
97
101
|
|
|
@@ -117,7 +121,7 @@ export const opening =
|
|
|
117
121
|
? apply({
|
|
118
122
|
_tag: "GaveUp",
|
|
119
123
|
number,
|
|
120
|
-
error: Option.getOrUndefined(
|
|
124
|
+
error: Option.getOrUndefined(failed),
|
|
121
125
|
detail: describe(exit.cause),
|
|
122
126
|
})
|
|
123
127
|
: apply({ _tag: "Stopped", number, began }),
|
package/src/testing/page.ts
CHANGED
|
@@ -320,6 +320,11 @@ export const makeIn = Effect.fnUntraced(function* (
|
|
|
320
320
|
: unsupported("screenshot"),
|
|
321
321
|
frame: evidence.frame,
|
|
322
322
|
zoom: () => unsupported("zoom"),
|
|
323
|
+
layout: () => unsupported("layout"),
|
|
324
|
+
overlay: unsupported("overlay"),
|
|
325
|
+
poses: unsupported("poses"),
|
|
326
|
+
hold: unsupported("hold"),
|
|
327
|
+
paint: () => unsupported("paint"),
|
|
323
328
|
ready: () =>
|
|
324
329
|
model.get().ready === true ? read("ready", () => undefined) : unsupported("ready"),
|
|
325
330
|
capture: evidence.capture,
|