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
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import { Deferred, Effect, Schema, SynchronizedRef } from "effect";
|
|
11
11
|
|
|
12
|
+
import type { InitScript } from "../../Browser.ts";
|
|
12
13
|
import { type BrowserError, Failed } from "../../BrowserError.ts";
|
|
13
14
|
import { Navigated, PageLoaded } from "../../BrowserEvent.ts";
|
|
14
15
|
import { match } from "../../Matching.ts";
|
|
@@ -20,6 +21,7 @@ import { targets, type Targets } from "../input/targets.inpage.ts";
|
|
|
20
21
|
import { context } from "../reading/context.inpage.ts";
|
|
21
22
|
import { controls } from "../reading/controls.inpage.ts";
|
|
22
23
|
import { expectations, type Expectations } from "../reading/expect.inpage.ts";
|
|
24
|
+
import { layout, type Layouts } from "../reading/layout.inpage.ts";
|
|
23
25
|
import { elements, names } from "../reading/names.inpage.ts";
|
|
24
26
|
import { outline, type Outline } from "../reading/outline.inpage.ts";
|
|
25
27
|
import { ready } from "../reading/ready.inpage.ts";
|
|
@@ -32,8 +34,13 @@ import { history } from "../timeline/history.inpage.ts";
|
|
|
32
34
|
import { marks } from "../timeline/marks.inpage.ts";
|
|
33
35
|
import { record, type Recorder } from "../timeline/record.inpage.ts";
|
|
34
36
|
import { sight } from "../timeline/sight.inpage.ts";
|
|
37
|
+
import { animations, clock, timers } from "./clock.inpage.ts";
|
|
38
|
+
import { compose } from "./compose.inpage.ts";
|
|
35
39
|
import { contextGone, decodeWith, failWith, type PageContext } from "./context.ts";
|
|
40
|
+
import { overlay, type Overlay } from "./overlay.inpage.ts";
|
|
36
41
|
import { Script } from "./port.ts";
|
|
42
|
+
import { pose, type Posing } from "./pose.inpage.ts";
|
|
43
|
+
import { time, type Time } from "./time.inpage.ts";
|
|
37
44
|
|
|
38
45
|
/** What the script installs: a version, and a function of one of its parts for each call. */
|
|
39
46
|
export interface PageApi {
|
|
@@ -42,6 +49,11 @@ export interface PageApi {
|
|
|
42
49
|
dispose: () => void;
|
|
43
50
|
snapshot: Outline["snapshot"];
|
|
44
51
|
find: Subjects["find"];
|
|
52
|
+
layout: Layouts["read"];
|
|
53
|
+
overlay: Overlay["draw"];
|
|
54
|
+
pose: Posing["set"];
|
|
55
|
+
unpose: Posing["clear"];
|
|
56
|
+
step: Time["step"];
|
|
45
57
|
until: Expectations["until"];
|
|
46
58
|
text: Texts["read"];
|
|
47
59
|
record: Recorder["start"];
|
|
@@ -53,7 +65,11 @@ export interface PageApi {
|
|
|
53
65
|
scrollPlan: Targets["scrollPlan"];
|
|
54
66
|
viewport: Outline["viewport"];
|
|
55
67
|
/** The screen as the page reads it, which another session may emulate. */
|
|
56
|
-
screenSize: () => {
|
|
68
|
+
screenSize: () => {
|
|
69
|
+
readonly width: number;
|
|
70
|
+
readonly height: number;
|
|
71
|
+
readonly ratio: number;
|
|
72
|
+
};
|
|
57
73
|
prepareInput: Guard["prepareInput"];
|
|
58
74
|
validateInput: Guard["validateInput"];
|
|
59
75
|
typeable: Edit["typeable"];
|
|
@@ -69,6 +85,7 @@ declare global {
|
|
|
69
85
|
|
|
70
86
|
/** Named factories make the composition contract independent of their declaration order. */
|
|
71
87
|
export const parts = {
|
|
88
|
+
compose,
|
|
72
89
|
elements,
|
|
73
90
|
names,
|
|
74
91
|
walk,
|
|
@@ -78,6 +95,7 @@ export const parts = {
|
|
|
78
95
|
states,
|
|
79
96
|
expectations,
|
|
80
97
|
text,
|
|
98
|
+
layout,
|
|
81
99
|
controls,
|
|
82
100
|
fold,
|
|
83
101
|
history,
|
|
@@ -91,6 +109,9 @@ export const parts = {
|
|
|
91
109
|
evidence,
|
|
92
110
|
guard,
|
|
93
111
|
edit,
|
|
112
|
+
overlay,
|
|
113
|
+
pose,
|
|
114
|
+
time,
|
|
94
115
|
addresses: Url.addresses,
|
|
95
116
|
};
|
|
96
117
|
|
|
@@ -114,42 +135,24 @@ export function install(parts: Parts): PageApi {
|
|
|
114
135
|
|
|
115
136
|
if (installed !== undefined && installed.version === version) return installed;
|
|
116
137
|
installed?.dispose?.();
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
const subjected = parts.subjects(named, walked, matching, placing, parts.states(named));
|
|
124
|
-
const texts = parts.text(named, walked);
|
|
125
|
-
const controlled = parts.controls(named, subjected, texts);
|
|
126
|
-
const kept = parts.history(parts.fold());
|
|
127
|
-
const seeing = parts.sight(named, walked, texts, kept);
|
|
128
|
-
const marking = parts.marks(named, kept, seeing);
|
|
129
|
-
const recorder = parts.record(named, texts, kept, seeing, marking);
|
|
130
|
-
const read = parts.outline(named, walked, subjected, texts, controlled, parts.addresses());
|
|
138
|
+
|
|
139
|
+
const { named, walked, placing, overlaid, posing, reads } = parts.compose(
|
|
140
|
+
parts,
|
|
141
|
+
installed?.refs?.next,
|
|
142
|
+
);
|
|
143
|
+
|
|
131
144
|
const located = parts.targets(named, walked, placing);
|
|
132
145
|
const guarded = parts.guard(named, located, parts.evidence(named, placing));
|
|
133
146
|
const edited = parts.edit(named, guarded, placing);
|
|
134
|
-
const readiness = parts.ready(walked, texts, kept);
|
|
135
147
|
|
|
136
148
|
const api: PageApi = {
|
|
149
|
+
...reads,
|
|
137
150
|
version,
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
snapshot: read.snapshot,
|
|
141
|
-
find: subjected.find,
|
|
142
|
-
until: parts.expectations(named, subjected, matching).until,
|
|
143
|
-
text: texts.read,
|
|
144
|
-
record: recorder.start,
|
|
145
|
-
stopRecord: recorder.stop,
|
|
146
|
-
changes: parts.changes(named, placing, kept, seeing, marking, recorder).read,
|
|
147
|
-
ready: readiness.wait,
|
|
148
|
-
settle: readiness.settle,
|
|
151
|
+
dispose: reads.stopRecord,
|
|
152
|
+
step: parts.time(overlaid, posing).step,
|
|
149
153
|
point: located.point,
|
|
150
154
|
scrollPlan: located.scrollPlan,
|
|
151
|
-
|
|
152
|
-
screenSize: () => ({ width: screen.width, height: screen.height }),
|
|
155
|
+
screenSize: () => ({ width: screen.width, height: screen.height, ratio: devicePixelRatio }),
|
|
153
156
|
prepareInput: guarded.prepareInput,
|
|
154
157
|
validateInput: guarded.validateInput,
|
|
155
158
|
typeable: edited.typeable,
|
|
@@ -163,10 +166,39 @@ export function install(parts: Parts): PageApi {
|
|
|
163
166
|
return api;
|
|
164
167
|
}
|
|
165
168
|
|
|
169
|
+
const encodeString = Schema.encodeSync(Schema.fromJsonString(Schema.String));
|
|
170
|
+
|
|
171
|
+
export const clockParts = { timers, animations };
|
|
172
|
+
|
|
173
|
+
// A factory applied to its parts, as one expression of their sources.
|
|
174
|
+
const applied = (factory: { toString(): string }, given: Record<string, { toString(): string }>) =>
|
|
175
|
+
`(${factory.toString()})({${Object.entries(given)
|
|
176
|
+
.map(([name, part]) => `${name}: ${part.toString()}`)
|
|
177
|
+
.join(", ")}})`;
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* The expression of the page clock, a function of its event name, which the page's main world runs
|
|
181
|
+
* before its own scripts; packaging freezes it.
|
|
182
|
+
*/
|
|
183
|
+
export const clockSource = applied(clock, clockParts);
|
|
184
|
+
|
|
166
185
|
/** The expression that installs the script and evaluates to its API; packaging freezes it. */
|
|
167
|
-
export const installSource =
|
|
168
|
-
|
|
169
|
-
|
|
186
|
+
export const installSource = applied(install, parts);
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* What new documents run before their own scripts: the page clock under its event name, first, so
|
|
190
|
+
* a caller's script that keeps a timer keeps the clock's, and then the caller's scripts, each
|
|
191
|
+
* everywhere or as a block where its `match` allows.
|
|
192
|
+
*/
|
|
193
|
+
export const documentScripts = (
|
|
194
|
+
clockName: string | undefined,
|
|
195
|
+
scripts: ReadonlyArray<InitScript>,
|
|
196
|
+
): ReadonlyArray<string> => [
|
|
197
|
+
...(clockName === undefined ? [] : [`${clockSource}(${encodeString(clockName)})`]),
|
|
198
|
+
...scripts.map(({ match, source }) =>
|
|
199
|
+
match === undefined ? source : `if (${String(match)}.test(location.href)) {\n${source}\n}`,
|
|
200
|
+
),
|
|
201
|
+
];
|
|
170
202
|
|
|
171
203
|
const worldName = "effect-browser";
|
|
172
204
|
|
|
@@ -176,7 +208,7 @@ const recorderSource = `if (globalThis === globalThis.top) globalThis.__effectBr
|
|
|
176
208
|
// What a call reads in a world without the script's API. A context id can name another world once
|
|
177
209
|
// the page has moved to a new process, so a cached id that reads this is not the library's world.
|
|
178
210
|
const missing = "effect-browser: no __effectBrowser in this world";
|
|
179
|
-
const missingSource =
|
|
211
|
+
const missingSource = encodeString(missing);
|
|
180
212
|
|
|
181
213
|
const isMissing = (error: BrowserError) =>
|
|
182
214
|
error.reason._tag === "Failed" && error.reason.detail === missing;
|
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In the page's main world, before its own scripts: the page clock, which `Page.hold` holds and
|
|
3
|
+
* steps. Until held it keeps real time. Held, the page's timers and intervals, its animation
|
|
4
|
+
* frames, `performance.now`, `Date.now`, `new Date()` and `Date()`, and its CSS transitions, CSS
|
|
5
|
+
* animations and Web Animations move only when stepped: due timers run in time order, each at its
|
|
6
|
+
* own time, animations are moved to each of those times, and then one animation frame runs at the
|
|
7
|
+
* step's end. A timer or frame asked for before the hold waits for page time, and what is left of
|
|
8
|
+
* it goes back to real time on release, when page time carries on from where it was, never back.
|
|
9
|
+
* Workers, media, `requestIdleCallback`, `MessageChannel` and events' `timeStamp` keep real time,
|
|
10
|
+
* as does a frame's document, which keeps its own clock.
|
|
11
|
+
*
|
|
12
|
+
* It listens for one event name, which only the library knows, on the document: the library's
|
|
13
|
+
* isolated world dispatches it with what to do, and the clock acknowledges by preventing its
|
|
14
|
+
* default. Its parts use only their parameters, the DOM and what they define, and the page's
|
|
15
|
+
* globals as they were before the page's scripts ran.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/** The page's timing globals as they were before its scripts ran. */
|
|
19
|
+
export interface Real {
|
|
20
|
+
readonly setTimeout: (run: () => void, millis: number) => number;
|
|
21
|
+
readonly clearTimeout: (id: number) => void;
|
|
22
|
+
readonly now: () => number;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** The page's timers and intervals by the ids it holds, each due at a page time. */
|
|
26
|
+
export const timers = (
|
|
27
|
+
real: Real,
|
|
28
|
+
now: () => number,
|
|
29
|
+
held: () => boolean,
|
|
30
|
+
report: (error: unknown) => void,
|
|
31
|
+
) => {
|
|
32
|
+
interface Timer {
|
|
33
|
+
readonly run: () => void;
|
|
34
|
+
readonly every: number;
|
|
35
|
+
at: number;
|
|
36
|
+
real?: number | undefined;
|
|
37
|
+
}
|
|
38
|
+
const all = new Map<number, Timer>();
|
|
39
|
+
let next = 1;
|
|
40
|
+
|
|
41
|
+
const arm = (id: number, timer: Timer) => {
|
|
42
|
+
timer.real = real.setTimeout(
|
|
43
|
+
() => {
|
|
44
|
+
if (all.get(id) === timer && !held()) fire(id, timer);
|
|
45
|
+
},
|
|
46
|
+
Math.max(0, timer.at - now()),
|
|
47
|
+
);
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const fire = (id: number, timer: Timer) => {
|
|
51
|
+
if (timer.every > 0) {
|
|
52
|
+
timer.at = Math.max(timer.at + timer.every, now());
|
|
53
|
+
if (!held()) arm(id, timer);
|
|
54
|
+
} else all.delete(id);
|
|
55
|
+
try {
|
|
56
|
+
timer.run();
|
|
57
|
+
} catch (error) {
|
|
58
|
+
report(error);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const schedule =
|
|
63
|
+
(every: boolean) =>
|
|
64
|
+
(handler: TimerHandler, delay?: unknown, ...args: Array<unknown>) => {
|
|
65
|
+
const id = next++;
|
|
66
|
+
const millis = Math.max(every ? 1 : 0, Number(delay) || 0);
|
|
67
|
+
|
|
68
|
+
const run = () => {
|
|
69
|
+
if (typeof handler === "function") Reflect.apply(handler, window, args);
|
|
70
|
+
// oxlint-disable-next-line no-eval -- the page's own string handler, run globally as its native timer would
|
|
71
|
+
else (0, eval)(handler);
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const timer: Timer = { run, every: every ? millis : 0, at: now() + millis };
|
|
75
|
+
|
|
76
|
+
all.set(id, timer);
|
|
77
|
+
if (!held()) arm(id, timer);
|
|
78
|
+
|
|
79
|
+
return id;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const clear = (id: unknown) => {
|
|
83
|
+
const timer = all.get(Number(id));
|
|
84
|
+
|
|
85
|
+
if (timer?.real !== undefined) real.clearTimeout(timer.real);
|
|
86
|
+
all.delete(Number(id));
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
// Run the first timer due by `target`, once `reach` has taken the page to its time.
|
|
90
|
+
const runDue = (target: number, reach: (at: number) => void) => {
|
|
91
|
+
let due: [number, Timer] | undefined;
|
|
92
|
+
|
|
93
|
+
for (const entry of all)
|
|
94
|
+
if (entry[1].at <= target && (due === undefined || entry[1].at < due[1].at)) due = entry;
|
|
95
|
+
if (due === undefined) return false;
|
|
96
|
+
reach(due[1].at);
|
|
97
|
+
fire(...due);
|
|
98
|
+
|
|
99
|
+
return true;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
return {
|
|
103
|
+
setTimeout: schedule(false),
|
|
104
|
+
setInterval: schedule(true),
|
|
105
|
+
clear,
|
|
106
|
+
runDue,
|
|
107
|
+
pause: () => {
|
|
108
|
+
for (const timer of all.values()) if (timer.real !== undefined) real.clearTimeout(timer.real);
|
|
109
|
+
},
|
|
110
|
+
resume: () => {
|
|
111
|
+
for (const [id, timer] of all) arm(id, timer);
|
|
112
|
+
},
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
/** The page's animations the clock paused, which it moves and which play again on release. */
|
|
117
|
+
export const animations = () => {
|
|
118
|
+
let ours = new WeakSet<Animation>();
|
|
119
|
+
|
|
120
|
+
// Every animation the page runs is paused at page time: one the clock has not seen began now.
|
|
121
|
+
const catchUp = () => {
|
|
122
|
+
for (const animation of document.getAnimations())
|
|
123
|
+
if (animation.playState === "running") {
|
|
124
|
+
animation.pause();
|
|
125
|
+
if (!ours.has(animation)) animation.currentTime = 0;
|
|
126
|
+
ours.add(animation);
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
const move = (by: number) => {
|
|
131
|
+
if (by <= 0) return;
|
|
132
|
+
for (const animation of document.getAnimations()) {
|
|
133
|
+
if (!ours.has(animation) || animation.playState !== "paused") continue;
|
|
134
|
+
const at = Number(animation.currentTime) + by * animation.playbackRate;
|
|
135
|
+
const end = Number(animation.effect?.getComputedTiming().endTime ?? Infinity);
|
|
136
|
+
|
|
137
|
+
if (animation.playbackRate >= 0 ? at >= end : at <= 0) {
|
|
138
|
+
ours.delete(animation);
|
|
139
|
+
animation.finish();
|
|
140
|
+
} else animation.currentTime = at;
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
const play = () => {
|
|
145
|
+
for (const animation of document.getAnimations())
|
|
146
|
+
if (ours.has(animation) && animation.playState === "paused") animation.play();
|
|
147
|
+
ours = new WeakSet();
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
return { catchUp, move, play };
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
export interface ClockParts {
|
|
154
|
+
readonly timers: typeof timers;
|
|
155
|
+
readonly animations: typeof animations;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export const clock = (parts: ClockParts) => (name: string) => {
|
|
159
|
+
if (window !== window.top) return;
|
|
160
|
+
|
|
161
|
+
const real = {
|
|
162
|
+
setTimeout: window.setTimeout.bind(window),
|
|
163
|
+
clearTimeout: window.clearTimeout.bind(window),
|
|
164
|
+
requestAnimationFrame: window.requestAnimationFrame.bind(window),
|
|
165
|
+
cancelAnimationFrame: window.cancelAnimationFrame.bind(window),
|
|
166
|
+
now: performance.now.bind(performance),
|
|
167
|
+
dateNow: Date.now,
|
|
168
|
+
Date,
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
let held = false;
|
|
172
|
+
// Page time while held; otherwise real time moved on by `shift`, so it never goes back. The
|
|
173
|
+
// date is page time from the real date's distance from it when the clock was first held.
|
|
174
|
+
let frozen = 0;
|
|
175
|
+
let shift = 0;
|
|
176
|
+
let dated: number | undefined;
|
|
177
|
+
let nextFrame = 1;
|
|
178
|
+
const pageNow = () => (held ? frozen : real.now() + shift);
|
|
179
|
+
const dateNow = () => (dated === undefined ? real.dateNow() : Math.floor(pageNow() + dated));
|
|
180
|
+
|
|
181
|
+
const report = (error: unknown) => {
|
|
182
|
+
real.setTimeout(() => {
|
|
183
|
+
throw error;
|
|
184
|
+
});
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
const timed = parts.timers(real, pageNow, () => held, report);
|
|
188
|
+
const animated = parts.animations();
|
|
189
|
+
|
|
190
|
+
// Animation frames by the ids the page holds, with their real frame while not held.
|
|
191
|
+
const frames = new Map<number, { readonly run: FrameRequestCallback; real?: number }>();
|
|
192
|
+
|
|
193
|
+
const request = (id: number, frame: { readonly run: FrameRequestCallback; real?: number }) => {
|
|
194
|
+
frame.real = real.requestAnimationFrame(() => {
|
|
195
|
+
frames.delete(id);
|
|
196
|
+
frame.run(pageNow());
|
|
197
|
+
});
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
// Move the page's animations and time on to `at`.
|
|
201
|
+
const reach = (at: number) => {
|
|
202
|
+
animated.catchUp();
|
|
203
|
+
animated.move(at - frozen);
|
|
204
|
+
frozen = Math.max(frozen, at);
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
const hold = () => {
|
|
208
|
+
if (held) return;
|
|
209
|
+
dated ??= real.dateNow() - real.now();
|
|
210
|
+
frozen = pageNow();
|
|
211
|
+
held = true;
|
|
212
|
+
timed.pause();
|
|
213
|
+
for (const frame of frames.values())
|
|
214
|
+
if (frame.real !== undefined) real.cancelAnimationFrame(frame.real);
|
|
215
|
+
animated.catchUp();
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
const advance = (by: number) => {
|
|
219
|
+
const target = frozen + by;
|
|
220
|
+
|
|
221
|
+
for (let guard = 0; guard < 10_000 && timed.runDue(target, reach); guard++);
|
|
222
|
+
reach(target);
|
|
223
|
+
const callbacks = [...frames.values()];
|
|
224
|
+
|
|
225
|
+
frames.clear();
|
|
226
|
+
for (const frame of callbacks)
|
|
227
|
+
try {
|
|
228
|
+
frame.run(frozen);
|
|
229
|
+
} catch (error) {
|
|
230
|
+
report(error);
|
|
231
|
+
}
|
|
232
|
+
animated.catchUp();
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
const release = () => {
|
|
236
|
+
if (!held) return;
|
|
237
|
+
held = false;
|
|
238
|
+
shift = Math.max(shift, frozen - real.now());
|
|
239
|
+
timed.resume();
|
|
240
|
+
for (const [id, frame] of frames) request(id, frame);
|
|
241
|
+
animated.play();
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
const define = (target: object, key: string, value: unknown) =>
|
|
245
|
+
Object.defineProperty(target, key, { value, writable: true, configurable: true });
|
|
246
|
+
|
|
247
|
+
define(window, "setTimeout", timed.setTimeout);
|
|
248
|
+
define(window, "setInterval", timed.setInterval);
|
|
249
|
+
define(window, "clearTimeout", timed.clear);
|
|
250
|
+
define(window, "clearInterval", timed.clear);
|
|
251
|
+
define(window, "requestAnimationFrame", (run: FrameRequestCallback) => {
|
|
252
|
+
const id = nextFrame++;
|
|
253
|
+
const frame = { run };
|
|
254
|
+
|
|
255
|
+
frames.set(id, frame);
|
|
256
|
+
if (!held) request(id, frame);
|
|
257
|
+
|
|
258
|
+
return id;
|
|
259
|
+
});
|
|
260
|
+
define(window, "cancelAnimationFrame", (id: number) => {
|
|
261
|
+
const frame = frames.get(id);
|
|
262
|
+
|
|
263
|
+
if (frame?.real !== undefined) real.cancelAnimationFrame(frame.real);
|
|
264
|
+
frames.delete(id);
|
|
265
|
+
});
|
|
266
|
+
define(performance, "now", pageNow);
|
|
267
|
+
|
|
268
|
+
// `Date` reads page time when it is given no time of its own.
|
|
269
|
+
function PageDate(this: unknown, ...args: Array<unknown>) {
|
|
270
|
+
if (new.target === undefined) return new real.Date(dateNow()).toString();
|
|
271
|
+
|
|
272
|
+
const made: unknown = Reflect.construct(
|
|
273
|
+
real.Date,
|
|
274
|
+
args.length === 0 ? [dateNow()] : args,
|
|
275
|
+
new.target,
|
|
276
|
+
);
|
|
277
|
+
|
|
278
|
+
return made;
|
|
279
|
+
}
|
|
280
|
+
Object.setPrototypeOf(PageDate, real.Date);
|
|
281
|
+
PageDate.prototype = real.Date.prototype;
|
|
282
|
+
define(PageDate, "now", dateNow);
|
|
283
|
+
define(window, "Date", PageDate);
|
|
284
|
+
|
|
285
|
+
document.addEventListener(
|
|
286
|
+
name,
|
|
287
|
+
(event) => {
|
|
288
|
+
const detail: unknown = "detail" in event ? event.detail : undefined;
|
|
289
|
+
const op = typeof detail === "object" && detail !== null && "op" in detail ? detail.op : "";
|
|
290
|
+
|
|
291
|
+
const by =
|
|
292
|
+
typeof detail === "object" && detail !== null && "by" in detail ? Number(detail.by) : 0;
|
|
293
|
+
|
|
294
|
+
if (op === "holds") {
|
|
295
|
+
if (held) event.preventDefault();
|
|
296
|
+
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
if (op === "hold" || op === "advance") hold();
|
|
300
|
+
if (op === "advance" && Number.isFinite(by) && by >= 0) advance(by);
|
|
301
|
+
if (op === "release") release();
|
|
302
|
+
event.preventDefault();
|
|
303
|
+
},
|
|
304
|
+
true,
|
|
305
|
+
);
|
|
306
|
+
};
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In the page: the readers, the change record, the overlay and element poses, composed from their
|
|
3
|
+
* parts in the order they depend on one another. The page script installs this with trusted
|
|
4
|
+
* input's checks and held time over it (`bridge.ts`); a site that owns its page calls it in its
|
|
5
|
+
* own bundle (`Site.ts`). See `names.inpage.ts` for what a page-side part may use.
|
|
6
|
+
*/
|
|
7
|
+
import type { match } from "../../Matching.ts";
|
|
8
|
+
import type { addresses } from "../../Url.ts";
|
|
9
|
+
import type { context } from "../reading/context.inpage.ts";
|
|
10
|
+
import type { controls } from "../reading/controls.inpage.ts";
|
|
11
|
+
import type { expectations } from "../reading/expect.inpage.ts";
|
|
12
|
+
import type { layout } from "../reading/layout.inpage.ts";
|
|
13
|
+
import type { elements, names } from "../reading/names.inpage.ts";
|
|
14
|
+
import type { outline } from "../reading/outline.inpage.ts";
|
|
15
|
+
import type { ready } from "../reading/ready.inpage.ts";
|
|
16
|
+
import type { states, subjects } from "../reading/subjects.inpage.ts";
|
|
17
|
+
import type { text } from "../reading/text.inpage.ts";
|
|
18
|
+
import type { walk } from "../reading/walk.inpage.ts";
|
|
19
|
+
import type { changes } from "../timeline/changes.inpage.ts";
|
|
20
|
+
import type { fold } from "../timeline/fold.inpage.ts";
|
|
21
|
+
import type { history } from "../timeline/history.inpage.ts";
|
|
22
|
+
import type { marks } from "../timeline/marks.inpage.ts";
|
|
23
|
+
import type { record } from "../timeline/record.inpage.ts";
|
|
24
|
+
import type { sight } from "../timeline/sight.inpage.ts";
|
|
25
|
+
import type { overlay } from "./overlay.inpage.ts";
|
|
26
|
+
import type { pose } from "./pose.inpage.ts";
|
|
27
|
+
|
|
28
|
+
/** The parts composed, by name. */
|
|
29
|
+
export interface Composed {
|
|
30
|
+
readonly elements: typeof elements;
|
|
31
|
+
readonly names: typeof names;
|
|
32
|
+
readonly walk: typeof walk;
|
|
33
|
+
readonly match: typeof match;
|
|
34
|
+
readonly context: typeof context;
|
|
35
|
+
readonly subjects: typeof subjects;
|
|
36
|
+
readonly states: typeof states;
|
|
37
|
+
readonly expectations: typeof expectations;
|
|
38
|
+
readonly text: typeof text;
|
|
39
|
+
readonly layout: typeof layout;
|
|
40
|
+
readonly controls: typeof controls;
|
|
41
|
+
readonly fold: typeof fold;
|
|
42
|
+
readonly history: typeof history;
|
|
43
|
+
readonly sight: typeof sight;
|
|
44
|
+
readonly marks: typeof marks;
|
|
45
|
+
readonly record: typeof record;
|
|
46
|
+
readonly changes: typeof changes;
|
|
47
|
+
readonly ready: typeof ready;
|
|
48
|
+
readonly outline: typeof outline;
|
|
49
|
+
readonly overlay: typeof overlay;
|
|
50
|
+
readonly pose: typeof pose;
|
|
51
|
+
readonly addresses: typeof addresses;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Compose the parts; refs go on from `next`, as a script installed before left them. */
|
|
55
|
+
export const compose = (parts: Composed, next?: number) => {
|
|
56
|
+
const named = parts.names(parts.elements());
|
|
57
|
+
|
|
58
|
+
if (next !== undefined) named.refs.next = next;
|
|
59
|
+
const walked = parts.walk(named);
|
|
60
|
+
const placing = parts.context(named, walked);
|
|
61
|
+
const matching = parts.match();
|
|
62
|
+
const subjected = parts.subjects(named, walked, matching, placing, parts.states(named));
|
|
63
|
+
const texts = parts.text(named, walked);
|
|
64
|
+
const controlled = parts.controls(named, subjected, texts);
|
|
65
|
+
const kept = parts.history(parts.fold());
|
|
66
|
+
const seeing = parts.sight(named, walked, texts, kept);
|
|
67
|
+
const marking = parts.marks(named, kept, seeing);
|
|
68
|
+
const recorder = parts.record(named, texts, kept, seeing, marking);
|
|
69
|
+
const url = parts.addresses();
|
|
70
|
+
const read = parts.outline(named, walked, subjected, texts, controlled, url);
|
|
71
|
+
const readiness = parts.ready(walked, texts, kept);
|
|
72
|
+
const overlaid = parts.overlay(named);
|
|
73
|
+
const posing = parts.pose(named);
|
|
74
|
+
|
|
75
|
+
return {
|
|
76
|
+
named,
|
|
77
|
+
walked,
|
|
78
|
+
placing,
|
|
79
|
+
overlaid,
|
|
80
|
+
posing,
|
|
81
|
+
recorder,
|
|
82
|
+
url,
|
|
83
|
+
reads: {
|
|
84
|
+
refs: named.refs,
|
|
85
|
+
snapshot: read.snapshot,
|
|
86
|
+
find: subjected.find,
|
|
87
|
+
layout: parts.layout(named, walked, subjected, matching, placing).read,
|
|
88
|
+
overlay: overlaid.draw,
|
|
89
|
+
pose: posing.set,
|
|
90
|
+
unpose: posing.clear,
|
|
91
|
+
until: parts.expectations(named, subjected, matching).until,
|
|
92
|
+
text: texts.read,
|
|
93
|
+
record: recorder.start,
|
|
94
|
+
stopRecord: recorder.stop,
|
|
95
|
+
changes: parts.changes(named, walked, placing, kept, seeing, marking, recorder).read,
|
|
96
|
+
ready: readiness.wait,
|
|
97
|
+
settle: readiness.settle,
|
|
98
|
+
viewport: read.viewport,
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
};
|
|
@@ -38,6 +38,8 @@ export interface Settings {
|
|
|
38
38
|
/** How long screencast frames stay in `recentFrames`, measured back from the newest. */
|
|
39
39
|
readonly frameHistory: Duration.Duration;
|
|
40
40
|
readonly guard: InputGuard | undefined;
|
|
41
|
+
/** The page clock's event name, when the browser runs one in each document. */
|
|
42
|
+
readonly pageTime?: string | undefined;
|
|
41
43
|
}
|
|
42
44
|
|
|
43
45
|
export interface MakeOptions {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
/** Connection identity uses the supplied
|
|
2
|
-
import {
|
|
1
|
+
/** Connection identity uses the supplied SecureRandom service, or the host's Web Crypto on Node/Bun. */
|
|
2
|
+
import { Effect, Option } from "effect";
|
|
3
|
+
import { SecureRandom } from "effect/crypto";
|
|
3
4
|
|
|
4
5
|
import { Failed } from "../../BrowserError.ts";
|
|
5
6
|
import { undispatched } from "./context.ts";
|
|
@@ -7,10 +8,10 @@ import { undispatched } from "./context.ts";
|
|
|
7
8
|
const failed = () => undispatched("make", new Failed({ detail: "Could not name connection" }));
|
|
8
9
|
|
|
9
10
|
export const make = Effect.gen(function* () {
|
|
10
|
-
const supplied = yield* Effect.serviceOption(
|
|
11
|
+
const supplied = yield* Effect.serviceOption(SecureRandom.SecureRandom);
|
|
11
12
|
|
|
12
13
|
return yield* Option.isSome(supplied)
|
|
13
|
-
? supplied.value.
|
|
14
|
-
: // oxlint-disable-next-line no-restricted-properties -- this host fallback runs only when the captured
|
|
14
|
+
? supplied.value.uuidV4()
|
|
15
|
+
: // oxlint-disable-next-line no-restricted-properties -- this host fallback runs only when the captured SecureRandom service is absent
|
|
15
16
|
Effect.try({ try: () => globalThis.crypto.randomUUID(), catch: failed });
|
|
16
17
|
});
|