effect-browser 0.3.0-beta.23 → 0.3.0-beta.25
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 +437 -142
- package/dist/Action.d.mts +1 -1
- package/dist/Action.mjs +61 -9
- package/dist/Action.mjs.map +1 -1
- package/dist/Browser.d.mts +2 -2
- package/dist/Browser.mjs +2 -2
- package/dist/BrowserError.d.mts +2 -2
- package/dist/BrowserError.mjs +194 -41
- package/dist/BrowserError.mjs.map +1 -1
- package/dist/BrowserEvent.d.mts +2 -2
- package/dist/BrowserEvent.mjs +185 -35
- package/dist/BrowserEvent.mjs.map +1 -1
- package/dist/Cdp.d.mts +15 -0
- package/dist/Cdp.mjs +22 -0
- package/dist/Cdp.mjs.map +1 -0
- package/dist/Change.d.mts +2 -2
- package/dist/Change.mjs +40 -7
- package/dist/Change.mjs.map +1 -1
- package/dist/Frame.d.mts +2 -2
- package/dist/Frame.mjs +132 -14
- package/dist/Frame.mjs.map +1 -1
- package/dist/InputStyle.d.mts +153 -0
- package/dist/InputStyle.mjs +2 -0
- package/dist/Layout.d.mts +2 -0
- package/dist/Layout.mjs +123 -0
- package/dist/Layout.mjs.map +1 -0
- package/dist/Overlay.d.mts +2 -0
- package/dist/Overlay.mjs +58 -0
- package/dist/Overlay.mjs.map +1 -0
- package/dist/Page.d.mts +2 -2
- package/dist/Page.mjs +2 -2
- package/dist/PageTime.d.mts +2 -0
- package/dist/PageTime.mjs +17 -0
- package/dist/PageTime.mjs.map +1 -0
- package/dist/Pose.d.mts +2 -0
- package/dist/Pose.mjs +65 -0
- package/dist/Pose.mjs.map +1 -0
- package/dist/Site.d.mts +984 -0
- package/dist/Site.mjs +110 -0
- package/dist/Site.mjs.map +1 -0
- package/dist/Snapshot.d.mts +2 -2
- package/dist/Snapshot.mjs +87 -6
- package/dist/Snapshot.mjs.map +1 -1
- package/dist/Text.d.mts +2 -0
- package/dist/Text.mjs +45 -0
- package/dist/Text.mjs.map +1 -0
- package/dist/Window.d.mts +2 -2
- package/dist/Window.mjs +31 -6
- package/dist/Window.mjs.map +1 -1
- package/dist/ai/BrowserTools.d.mts +4987 -0
- package/dist/ai/BrowserTools.mjs +3 -0
- package/dist/ai/PageControl.d.mts +286 -0
- package/dist/ai/PageControl.mjs +426 -0
- package/dist/ai/PageControl.mjs.map +1 -0
- package/dist/ai/PromptCache.d.mts +16 -0
- package/dist/ai/PromptCache.mjs +72 -0
- package/dist/ai/PromptCache.mjs.map +1 -0
- package/dist/ai/Tabs.d.mts +2 -0
- package/dist/ai/Tabs.mjs +72 -0
- package/dist/ai/Tabs.mjs.map +1 -0
- package/dist/ai/ToolError.d.mts +34 -0
- package/dist/ai/ToolError.mjs +2 -0
- package/dist/ai/index.d.mts +6 -0
- package/dist/ai/index.mjs +6 -0
- package/dist/index.d.mts +7 -15
- package/dist/index.mjs +9 -8
- package/dist/{Action-24sLOubi.d.mts → internal/Action-CkanNTUw.d.mts} +64 -4
- package/dist/{Browser-wZhwZSlG.d.mts → internal/Browser-DD9Vm1c-.d.mts} +80 -10
- package/dist/{Browser-BKPAbyys.mjs → internal/Browser-vzD7i2oj.mjs} +658 -495
- package/dist/internal/Browser-vzD7i2oj.mjs.map +1 -0
- package/dist/{BrowserError-BlcmLVzn.d.mts → internal/BrowserError-CsuRYcDX.d.mts} +187 -28
- package/dist/{BrowserEvent-lLqJ3GJS.d.mts → internal/BrowserEvent-tGPYYf6R.d.mts} +197 -18
- package/dist/internal/BrowserTools-Yi3lOX4h.mjs +497 -0
- package/dist/internal/BrowserTools-Yi3lOX4h.mjs.map +1 -0
- package/dist/{Style-AO4V7Czt.mjs → internal/InputStyle-CPzxoN4g.mjs} +94 -16
- package/dist/internal/InputStyle-CPzxoN4g.mjs.map +1 -0
- package/dist/{moment/Moment.mjs → internal/Moment-CstaX1mR.mjs} +49 -16
- package/dist/internal/Moment-CstaX1mR.mjs.map +1 -0
- package/dist/{moment/Moment.d.mts → internal/Moment-DOcldBdf.d.mts} +54 -21
- package/dist/internal/Page-BfGxn7oN.d.mts +1553 -0
- package/dist/{Page-BF5izr8R.mjs → internal/Page-DqF-tuTx.mjs} +62 -72
- package/dist/internal/Page-DqF-tuTx.mjs.map +1 -0
- package/dist/internal/Release-CFONkPDP.d.mts +39 -0
- package/dist/internal/Stage-D5ymSXDT.mjs +298 -0
- package/dist/internal/Stage-D5ymSXDT.mjs.map +1 -0
- package/dist/internal/Stillness-DCPeAN1a.mjs +1124 -0
- package/dist/internal/Stillness-DCPeAN1a.mjs.map +1 -0
- package/dist/internal/Supervisor-BcY_QNIY.d.mts +108 -0
- package/dist/internal/Supervisor-BcglY23c.mjs +531 -0
- package/dist/internal/Supervisor-BcglY23c.mjs.map +1 -0
- package/dist/internal/Tabs-dXMscIUQ.d.mts +52 -0
- package/dist/internal/TestPage-CYiYbh63.d.mts +159 -0
- package/dist/internal/ToolError-DArsRS2m.mjs +117 -0
- package/dist/internal/ToolError-DArsRS2m.mjs.map +1 -0
- package/dist/{plan/index.d.mts → internal/Walk-BNXcfZ2z.d.mts} +59 -35
- package/dist/{plan/index.mjs → internal/Walk-C5ky7uSf.mjs} +83 -51
- package/dist/internal/Walk-C5ky7uSf.mjs.map +1 -0
- package/dist/{ActionPort.mjs → internal/action-port-B5EkeGOR.mjs} +6 -12
- package/dist/internal/action-port-B5EkeGOR.mjs.map +1 -0
- package/dist/internal/cdp/workerd.d.mts +13 -0
- package/dist/internal/cdp/workerd.mjs +19 -0
- package/dist/internal/cdp/workerd.mjs.map +1 -0
- package/dist/{Clock.mjs → internal/clock-BKSAEf00.mjs} +13 -13
- package/dist/internal/clock-BKSAEf00.mjs.map +1 -0
- package/dist/{connection-2KHI4_KN.d.mts → internal/connection-BaB0vp1o.d.mts} +6 -6
- package/dist/{connection-CK83pvqP.mjs → internal/connection-C2X4GmXM.mjs} +19 -15
- package/dist/internal/connection-C2X4GmXM.mjs.map +1 -0
- package/dist/internal/events-DzCrww-y.mjs +72 -0
- package/dist/internal/events-DzCrww-y.mjs.map +1 -0
- package/dist/internal/fold.inpage-CyVZQHZL.d.mts +49 -0
- package/dist/internal/fold.inpage-uhrT-dOB.mjs +49 -0
- package/dist/internal/fold.inpage-uhrT-dOB.mjs.map +1 -0
- package/dist/internal/functions-jBOs6GKv.mjs +27 -0
- package/dist/internal/functions-jBOs6GKv.mjs.map +1 -0
- package/dist/{Geometry-DJx9qrYy.d.mts → internal/geometry-Dhj_ztJs.d.mts} +3 -3
- package/dist/{Geometry.mjs → internal/geometry-Lxyflb9J.mjs} +3 -12
- package/dist/internal/geometry-Lxyflb9J.mjs.map +1 -0
- package/dist/{Matching.mjs → internal/matching-Cs-UeOY0.mjs} +24 -19
- package/dist/internal/matching-Cs-UeOY0.mjs.map +1 -0
- package/dist/internal/page-DFQb-YOK.mjs +436 -0
- package/dist/internal/page-DFQb-YOK.mjs.map +1 -0
- package/dist/internal/pose.inpage-CBFeWcVa.mjs +1996 -0
- package/dist/internal/pose.inpage-CBFeWcVa.mjs.map +1 -0
- package/dist/{Url.mjs → internal/url-DB0pQYk6.mjs} +3 -12
- package/dist/internal/url-DB0pQYk6.mjs.map +1 -0
- package/dist/policy/Policy.d.mts +60 -6
- package/dist/policy/Policy.mjs +52 -9
- package/dist/policy/Policy.mjs.map +1 -1
- package/dist/policy/index.d.mts +2 -0
- package/dist/policy/index.mjs +2 -0
- package/dist/presentation/Film.d.mts +332 -0
- package/dist/presentation/Film.mjs +298 -0
- package/dist/presentation/Film.mjs.map +1 -0
- package/dist/presentation/Motion.d.mts +5 -1
- package/dist/presentation/Motion.mjs +16 -2
- package/dist/presentation/Motion.mjs.map +1 -1
- package/dist/presentation/Presentation.d.mts +48 -6
- package/dist/presentation/Presentation.mjs +28 -9
- package/dist/presentation/Presentation.mjs.map +1 -1
- package/dist/presentation/Stage.d.mts +40 -6
- package/dist/presentation/Stage.mjs +1 -262
- package/dist/presentation/index.d.mts +5 -0
- package/dist/presentation/index.mjs +5 -0
- package/dist/supervisor/Release.d.mts +2 -0
- package/dist/supervisor/Release.mjs +40 -0
- package/dist/supervisor/Release.mjs.map +1 -0
- package/dist/supervisor/Supervisor.d.mts +2 -104
- package/dist/supervisor/Supervisor.mjs +2 -515
- package/dist/supervisor/index.d.mts +3 -0
- package/dist/supervisor/index.mjs +3 -0
- package/dist/testing/HttpCassette.d.mts +98 -0
- package/dist/testing/HttpCassette.mjs +146 -0
- package/dist/testing/HttpCassette.mjs.map +1 -0
- package/dist/testing/Story.d.mts +31 -0
- package/dist/testing/Story.mjs +76 -0
- package/dist/testing/Story.mjs.map +1 -0
- package/dist/testing/TestBrowser.d.mts +191 -0
- package/dist/testing/TestBrowser.mjs +105 -0
- package/dist/testing/TestBrowser.mjs.map +1 -0
- package/dist/testing/TestModel.d.mts +133 -0
- package/dist/testing/TestModel.mjs +209 -0
- package/dist/testing/TestModel.mjs.map +1 -0
- package/dist/testing/TestPage.d.mts +2 -0
- package/dist/testing/TestPage.mjs +47 -0
- package/dist/testing/TestPage.mjs.map +1 -0
- package/dist/testing/index.d.mts +6 -337
- package/dist/testing/index.mjs +6 -515
- package/dist/timeline/Moment.d.mts +3 -0
- package/dist/timeline/Moment.mjs +3 -0
- package/dist/timeline/Stillness.d.mts +34 -0
- package/dist/timeline/Stillness.mjs +2 -0
- package/dist/timeline/index.d.mts +3 -0
- package/dist/timeline/index.mjs +3 -0
- package/dist/walk/Walk.d.mts +2 -0
- package/dist/walk/Walk.mjs +2 -0
- package/dist/walk/index.d.mts +2 -0
- package/dist/walk/index.mjs +2 -0
- package/package.json +54 -133
- package/src/Action.ts +73 -8
- package/src/Browser.ts +85 -14
- package/src/BrowserError.ts +258 -63
- package/src/BrowserEvent.ts +264 -48
- package/src/Cdp.ts +42 -0
- package/src/Change.ts +75 -4
- package/src/Frame.ts +247 -14
- package/src/{Style.ts → InputStyle.ts} +130 -18
- package/src/Layout.ts +187 -0
- package/src/Overlay.ts +76 -0
- package/src/Page.ts +144 -275
- package/src/PageTime.ts +72 -0
- package/src/Pose.ts +81 -0
- package/src/Site.ts +136 -0
- package/src/Snapshot.ts +179 -3
- package/src/Text.ts +60 -0
- package/src/Window.ts +53 -3
- package/src/ai/BrowserTools.ts +778 -0
- package/src/ai/PageControl.ts +702 -0
- package/src/ai/PromptCache.ts +87 -0
- package/src/ai/Tabs.ts +84 -0
- package/src/ai/ToolError.ts +50 -0
- package/src/ai/index.ts +36 -0
- package/src/ai/internal/crops.ts +38 -0
- package/src/ai/internal/points.ts +57 -0
- package/src/ai/internal/receipts.ts +107 -0
- package/src/index.ts +87 -6
- package/src/{ActionPort.ts → internal/action-port.ts} +3 -3
- package/src/{providers → internal/cdp}/connection.ts +19 -12
- package/src/internal/cdp/workerd.ts +36 -0
- package/src/{Clock.ts → internal/clock.ts} +20 -0
- package/src/internal/input/actions.ts +1 -1
- package/src/internal/input/dispatch.ts +2 -2
- package/src/internal/input/guard.inpage.ts +1 -1
- package/src/internal/input/guard.ts +1 -1
- package/src/internal/input/perform.ts +35 -7
- package/src/internal/input/pointer.ts +9 -6
- package/src/internal/input/targets.inpage.ts +3 -3
- package/src/internal/input/targets.ts +1 -1
- package/src/{Matching.ts → internal/matching.ts} +28 -19
- package/src/internal/page/bridge.ts +67 -35
- package/src/internal/page/clock.inpage.ts +306 -0
- package/src/internal/page/compose.inpage.ts +101 -0
- package/src/internal/page/context.ts +4 -2
- package/src/internal/page/functions.ts +84 -0
- package/src/internal/page/navigation.ts +1 -1
- package/src/internal/page/openings.ts +2 -2
- package/src/internal/page/overlay.inpage.ts +96 -0
- package/src/internal/page/overlay.ts +89 -0
- package/src/internal/page/page.ts +39 -29
- package/src/internal/page/port.ts +14 -8
- package/src/internal/page/pose.inpage.ts +200 -0
- package/src/internal/page/pose.ts +80 -0
- package/src/internal/page/replies.ts +1 -1
- package/src/internal/page/requests.ts +1 -1
- package/src/internal/page/scripts.ts +1 -1
- 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/capture.ts +1 -4
- package/src/internal/pictures/dimensions.ts +1 -1
- package/src/internal/pictures/frame.ts +1 -1
- package/src/internal/pictures/pictures.ts +144 -91
- package/src/internal/reading/context.inpage.ts +2 -2
- package/src/internal/reading/expect.inpage.ts +1 -1
- 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 +5 -21
- package/src/internal/reading/reading.ts +33 -21
- package/src/internal/reading/ready.inpage.ts +21 -26
- package/src/internal/reading/ready.ts +26 -5
- package/src/internal/reading/subjects.inpage.ts +3 -3
- package/src/internal/reading/text.inpage.ts +3 -16
- package/src/internal/reading/walk.inpage.ts +1 -1
- package/src/internal/timeline/changes.inpage.ts +7 -15
- package/src/internal/timeline/changes.ts +17 -5
- package/src/internal/timeline/record.inpage.ts +15 -6
- package/src/internal/timeline/sight.inpage.ts +2 -2
- package/src/internal/timeline/window.ts +3 -4
- package/src/policy/Policy.ts +70 -16
- package/src/policy/index.ts +12 -0
- package/src/presentation/Film.ts +451 -0
- package/src/presentation/Motion.ts +45 -3
- package/src/presentation/Presentation.ts +60 -14
- package/src/presentation/Stage.ts +73 -35
- package/src/presentation/index.ts +30 -0
- package/src/presentation/{feed.ts → internal/feed.ts} +1 -1
- package/src/supervisor/Release.ts +45 -0
- package/src/supervisor/Supervisor.ts +80 -5
- package/src/supervisor/index.ts +18 -0
- package/src/supervisor/{contract.ts → internal/contract.ts} +14 -10
- package/src/supervisor/{lifecycle.ts → internal/lifecycle.ts} +7 -7
- package/src/supervisor/{runtime.ts → internal/runtime.ts} +7 -7
- package/src/testing/HttpCassette.ts +260 -0
- package/src/testing/Story.ts +103 -0
- package/src/testing/TestBrowser.ts +14 -4
- package/src/testing/TestModel.ts +297 -0
- package/src/testing/TestPage.ts +92 -4
- package/src/testing/index.ts +35 -1
- package/src/testing/{evidence.ts → internal/evidence.ts} +19 -11
- package/src/testing/{model.ts → internal/model.ts} +14 -8
- package/src/testing/{page.ts → internal/page.ts} +55 -51
- package/src/{moment → timeline}/Moment.ts +79 -29
- package/src/{stillness → timeline}/Stillness.ts +89 -46
- package/src/timeline/index.ts +18 -0
- package/src/{stillness/Pixels.ts → timeline/internal/pixels.ts} +27 -1
- package/src/{moment → timeline/internal}/words.ts +2 -2
- package/src/walk/Walk.ts +165 -0
- package/src/walk/index.ts +12 -0
- package/src/{plan → walk/internal}/choose.ts +23 -14
- package/src/{plan → walk/internal}/data.ts +37 -14
- package/src/{plan → walk/internal}/execute.ts +79 -36
- package/src/{plan → walk/internal}/record.ts +6 -6
- package/src/{plan → walk/internal}/targets.ts +35 -25
- package/dist/ActionPort.d.mts +0 -15
- package/dist/ActionPort.mjs.map +0 -1
- package/dist/Browser-BKPAbyys.mjs.map +0 -1
- package/dist/Change-Ba7INmay.d.mts +0 -69
- package/dist/Clock.d.mts +0 -57
- package/dist/Clock.mjs.map +0 -1
- package/dist/Frame-UEH2hO5T.d.mts +0 -124
- package/dist/Geometry.d.mts +0 -2
- package/dist/Geometry.mjs.map +0 -1
- package/dist/Matching.d.mts +0 -37
- package/dist/Matching.mjs.map +0 -1
- package/dist/Page-BF5izr8R.mjs.map +0 -1
- package/dist/Page-CvsOEorc.d.mts +0 -566
- package/dist/Released-tURbFmal.d.mts +0 -15
- package/dist/Snapshot-CtBVOtuu.d.mts +0 -73
- package/dist/Stillness-CNlvayIo.mjs +0 -136
- package/dist/Stillness-CNlvayIo.mjs.map +0 -1
- package/dist/Style-AO4V7Czt.mjs.map +0 -1
- package/dist/Style.d.mts +0 -72
- package/dist/Style.mjs +0 -2
- package/dist/Url.d.mts +0 -26
- package/dist/Url.mjs.map +0 -1
- package/dist/Window-CMddGMt1.d.mts +0 -34
- package/dist/connection-CK83pvqP.mjs.map +0 -1
- package/dist/moment/Moment.mjs.map +0 -1
- package/dist/plan/index.mjs.map +0 -1
- package/dist/presentation/Stage.mjs.map +0 -1
- package/dist/presentation/feed.d.mts +0 -20
- package/dist/presentation/feed.mjs +0 -18
- package/dist/presentation/feed.mjs.map +0 -1
- package/dist/providers/Cdp.d.mts +0 -9
- package/dist/providers/Cdp.mjs +0 -15
- package/dist/providers/Cdp.mjs.map +0 -1
- package/dist/providers/Chromium.d.mts +0 -32
- package/dist/providers/Chromium.mjs +0 -55
- package/dist/providers/Chromium.mjs.map +0 -1
- package/dist/providers/Released.d.mts +0 -2
- package/dist/providers/Released.mjs +0 -12
- package/dist/providers/Released.mjs.map +0 -1
- package/dist/stillness/Stillness.d.mts +0 -12
- package/dist/stillness/Stillness.mjs +0 -2
- package/dist/supervisor/Supervisor.mjs.map +0 -1
- package/dist/testing/index.mjs.map +0 -1
- package/dist/workerd/Cdp.d.mts +0 -8
- package/dist/workerd/Cdp.mjs +0 -13
- package/dist/workerd/Cdp.mjs.map +0 -1
- package/src/plan/index.ts +0 -36
- package/src/providers/Cdp.ts +0 -16
- package/src/providers/Chromium.ts +0 -99
- package/src/providers/Released.ts +0 -13
- package/src/workerd/Cdp.ts +0 -11
- /package/dist/{rolldown-runtime-D7D4PA-g.mjs → internal/rolldown-runtime-D7D4PA-g.mjs} +0 -0
- /package/src/{Geometry.ts → internal/geometry.ts} +0 -0
- /package/src/{Url.ts → internal/url.ts} +0 -0
- /package/src/{stillness → timeline/internal}/utilsBundle.d.ts +0 -0
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Holding a page's time: one hold at a time, each step one call to the page that takes the page
|
|
3
|
+
* to itself, as an action does, so no read sees a step half made. See `PageTime`.
|
|
4
|
+
*/
|
|
5
|
+
import { Duration, Effect, Option, Schema, type Scope } from "effect";
|
|
6
|
+
|
|
7
|
+
import { type BrowserError, NotActionable } from "../../BrowserError.ts";
|
|
8
|
+
import { Box } from "../../BrowserEvent.ts";
|
|
9
|
+
import type { Held, Step } from "../../PageTime.ts";
|
|
10
|
+
import { Point } from "../geometry.ts";
|
|
11
|
+
import { type Bridge, scriptCall } from "./bridge.ts";
|
|
12
|
+
import { decodeWith, failWith, type PageContext, refuse } from "./context.ts";
|
|
13
|
+
import type { Overlays } from "./overlay.ts";
|
|
14
|
+
import { Posed, type Posing } from "./pose.ts";
|
|
15
|
+
import type { StepRequest } from "./time.inpage.ts";
|
|
16
|
+
|
|
17
|
+
const Stepped = Schema.Struct({
|
|
18
|
+
...Posed.fields,
|
|
19
|
+
told: Schema.Boolean,
|
|
20
|
+
drawn: Schema.NullOr(Schema.Array(Box)),
|
|
21
|
+
scroll: Point,
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
export const make = (page: PageContext, bridge: Bridge, overlays: Overlays, posing: Posing) => {
|
|
25
|
+
const { lane, owned, span, within } = page;
|
|
26
|
+
let holding = false;
|
|
27
|
+
|
|
28
|
+
// One step, the page to itself, the overlay's turn too when it draws.
|
|
29
|
+
const step = (operation: string, request: StepRequest) => {
|
|
30
|
+
const sent = lane
|
|
31
|
+
.write(
|
|
32
|
+
operation,
|
|
33
|
+
page.settings.actionTimeout,
|
|
34
|
+
)(
|
|
35
|
+
bridge.evaluate(operation, scriptCall("step", request)).pipe(
|
|
36
|
+
Effect.flatMap(decodeWith(operation, Stepped)),
|
|
37
|
+
Effect.tap(({ drawn }) =>
|
|
38
|
+
Effect.sync(() => {
|
|
39
|
+
if (drawn !== null && request.markup !== undefined)
|
|
40
|
+
overlays.record(request.markup, drawn);
|
|
41
|
+
page.noteInput();
|
|
42
|
+
}),
|
|
43
|
+
),
|
|
44
|
+
within(operation),
|
|
45
|
+
),
|
|
46
|
+
)
|
|
47
|
+
.pipe(span(`PageTime.${operation}`), owned);
|
|
48
|
+
|
|
49
|
+
return request.markup === undefined ? sent : overlays.turn(sent);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const unclocked = (operation: string) =>
|
|
53
|
+
failWith(operation, new NotActionable({ detail: "the page's document has no page clock" }));
|
|
54
|
+
|
|
55
|
+
const hold: Effect.Effect<Held, BrowserError, Scope.Scope> = Effect.gen(function* () {
|
|
56
|
+
const clock = page.settings.pageTime;
|
|
57
|
+
|
|
58
|
+
if (clock === undefined)
|
|
59
|
+
return yield* refuse("hold", "holding page time needs the browser's pageTime option");
|
|
60
|
+
if (holding) return yield* refuse("hold", "the page's time is held already");
|
|
61
|
+
holding = true;
|
|
62
|
+
let ended = false;
|
|
63
|
+
|
|
64
|
+
yield* Effect.addFinalizer(() =>
|
|
65
|
+
Effect.sync(() => (ended = true)).pipe(
|
|
66
|
+
Effect.andThen(step("release", { clock, op: "release", by: 0, scroll: null })),
|
|
67
|
+
Effect.ignore,
|
|
68
|
+
Effect.ensuring(Effect.sync(() => (holding = false))),
|
|
69
|
+
),
|
|
70
|
+
);
|
|
71
|
+
const held = yield* step("hold", { clock, op: "hold", by: 0, scroll: null });
|
|
72
|
+
|
|
73
|
+
if (!held.told) return yield* unclocked("hold");
|
|
74
|
+
let elapsed = 0;
|
|
75
|
+
|
|
76
|
+
const advance = (by: Duration.Input, options: Step = {}) =>
|
|
77
|
+
Effect.gen(function* () {
|
|
78
|
+
const millis = Option.map(Duration.fromInput(by), Duration.toMillis).pipe(
|
|
79
|
+
Option.getOrElse(() => Number.NaN),
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
if (ended) return yield* refuse("advance", "the hold has ended");
|
|
83
|
+
if (!Number.isFinite(millis) || millis < 0)
|
|
84
|
+
return yield* refuse("advance", "page time moves on by a finite, nonnegative duration");
|
|
85
|
+
if (options.scroll !== undefined && !Number.isFinite(options.scroll))
|
|
86
|
+
return yield* refuse("advance", "the scroll must be finite");
|
|
87
|
+
if (options.overlay !== undefined && !overlays.open())
|
|
88
|
+
return yield* refuse("advance", "drawing needs the page's overlay open");
|
|
89
|
+
if (options.poses !== undefined && !posing.open())
|
|
90
|
+
return yield* refuse("advance", "posing needs the page's poses open");
|
|
91
|
+
|
|
92
|
+
const poses =
|
|
93
|
+
options.poses === undefined
|
|
94
|
+
? undefined
|
|
95
|
+
: yield* posing.requests("advance", options.poses);
|
|
96
|
+
|
|
97
|
+
const stepped = yield* step("advance", {
|
|
98
|
+
clock,
|
|
99
|
+
op: "advance",
|
|
100
|
+
by: millis,
|
|
101
|
+
scroll: options.scroll ?? null,
|
|
102
|
+
markup:
|
|
103
|
+
options.overlay === undefined
|
|
104
|
+
? undefined
|
|
105
|
+
: options.overlay._tag === "Svg"
|
|
106
|
+
? options.overlay.markup
|
|
107
|
+
: null,
|
|
108
|
+
poses,
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
yield* posing.answered("advance", stepped);
|
|
112
|
+
if (!stepped.told) return yield* unclocked("advance");
|
|
113
|
+
elapsed += millis;
|
|
114
|
+
|
|
115
|
+
return stepped.scroll;
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
return { advance, elapsed: Effect.sync(() => Duration.millis(elapsed)) };
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
return { hold };
|
|
122
|
+
};
|
|
@@ -4,12 +4,13 @@
|
|
|
4
4
|
* pixel. Pointer bounds, page scrolls, crops, capture size and frame reuse all read this one
|
|
5
5
|
* source; the latest answer serves checks that cannot wait for the page.
|
|
6
6
|
*/
|
|
7
|
-
import { Effect } from "effect";
|
|
7
|
+
import { Effect, Schema } from "effect";
|
|
8
8
|
|
|
9
|
-
import { ViewportResultSchema } from "../reading/outline.inpage.ts";
|
|
10
9
|
import { type Bridge, scriptCall } from "./bridge.ts";
|
|
11
10
|
import { decodeWith, type PageContext } from "./context.ts";
|
|
12
11
|
|
|
12
|
+
const ViewportResultSchema = Schema.Struct({ width: Schema.Finite, height: Schema.Finite });
|
|
13
|
+
|
|
13
14
|
export const make = (page: PageContext, bridge: Bridge) => {
|
|
14
15
|
const { playwright } = page;
|
|
15
16
|
let measuredViewport: { readonly width: number; readonly height: number } | null = null;
|
|
@@ -18,8 +18,8 @@ import {
|
|
|
18
18
|
import { Base64 } from "effect/encoding";
|
|
19
19
|
|
|
20
20
|
import { type BrowserError, InvalidRequest } from "../../BrowserError.ts";
|
|
21
|
-
import { type Estimate, monotonicMillis } from "../../Clock.ts";
|
|
22
21
|
import { CaptureStats, type Frame, type ScreencastOptions, sameCapture } from "../../Frame.ts";
|
|
22
|
+
import { type Estimate, monotonicMillis } from "../clock.ts";
|
|
23
23
|
import { undispatched } from "../page/context.ts";
|
|
24
24
|
import { tally } from "./counts.ts";
|
|
25
25
|
import { readViewport, sizeFilter, type Size } from "./dimensions.ts";
|
|
@@ -82,7 +82,6 @@ export interface Controller {
|
|
|
82
82
|
BrowserError,
|
|
83
83
|
Scope.Scope
|
|
84
84
|
>;
|
|
85
|
-
readonly stream: (options?: ScreencastOptions) => Stream.Stream<Frame, BrowserError>;
|
|
86
85
|
readonly latest: Effect.Effect<Option.Option<Frame>>;
|
|
87
86
|
readonly recent: Effect.Effect<ReadonlyArray<Frame>>;
|
|
88
87
|
/** Lifetime counts, or those of the latest `windowMillis`, at most `countsKept`. */
|
|
@@ -668,8 +667,6 @@ export const make = (options: Options) =>
|
|
|
668
667
|
|
|
669
668
|
return {
|
|
670
669
|
open,
|
|
671
|
-
stream: (options?: ScreencastOptions) =>
|
|
672
|
-
Stream.unwrap(Effect.map(open(options), ({ stream }) => stream)),
|
|
673
670
|
latest: Effect.sync(() => latest),
|
|
674
671
|
recent: Effect.sync(() => history),
|
|
675
672
|
active: Effect.sync(() => generation !== undefined && generation.state._tag !== "Stopped"),
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
import { Clock, Duration, Effect, Queue } from "effect";
|
|
3
3
|
|
|
4
4
|
import type { BrowserError } from "../../BrowserError.ts";
|
|
5
|
-
import { monotonicMillis } from "../../Clock.ts";
|
|
6
5
|
import type { Frame } from "../../Frame.ts";
|
|
6
|
+
import { monotonicMillis } from "../clock.ts";
|
|
7
7
|
|
|
8
8
|
export interface Size {
|
|
9
9
|
readonly width: number;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/** Native frame timing and monotonic evidence across clock recalibration. */
|
|
2
2
|
import type { Clock } from "effect";
|
|
3
3
|
|
|
4
|
-
import { type Estimate, monotonicMillis, toHostTime, uncertaintyAt } from "../../Clock.ts";
|
|
5
4
|
import { BrowserPaint, Frame } from "../../Frame.ts";
|
|
5
|
+
import { type Estimate, monotonicMillis, toHostTime, uncertaintyAt } from "../clock.ts";
|
|
6
6
|
import type { NativeFrame, Transport } from "./transport.ts";
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -4,14 +4,21 @@
|
|
|
4
4
|
* one call where a device pixel is a CSS pixel and nothing is cropped, and two otherwise, unless
|
|
5
5
|
* Playwright emulates the viewport. The page's first clipped picture also holds the screen it reads.
|
|
6
6
|
*/
|
|
7
|
-
import { Duration, Effect, Option, Result, Schedule, Schema } from "effect";
|
|
7
|
+
import { Duration, Effect, Option, Result, Schedule, Schema, type Scope } from "effect";
|
|
8
8
|
import { Base64 } from "effect/encoding";
|
|
9
9
|
|
|
10
10
|
import { BrowserError, Failed, InvalidRequest } from "../../BrowserError.ts";
|
|
11
|
-
import
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
import {
|
|
12
|
+
Frame,
|
|
13
|
+
type FrameOptions,
|
|
14
|
+
Image,
|
|
15
|
+
type Paint,
|
|
16
|
+
Region,
|
|
17
|
+
Screenshot,
|
|
18
|
+
Zoom,
|
|
19
|
+
} from "../../Frame.ts";
|
|
20
|
+
import * as BrowserClock from "../clock.ts";
|
|
21
|
+
import type { Point } from "../geometry.ts";
|
|
15
22
|
import { type Bridge, scriptCall } from "../page/bridge.ts";
|
|
16
23
|
import {
|
|
17
24
|
decodeWith,
|
|
@@ -61,7 +68,7 @@ export const pngSize = (bytes: Uint8Array): Size | undefined => {
|
|
|
61
68
|
export type Format = "jpeg" | "png";
|
|
62
69
|
|
|
63
70
|
// A picture's pixels: CSS pixels, or the screen's own.
|
|
64
|
-
type Scale = NonNullable<
|
|
71
|
+
type Scale = NonNullable<FrameOptions["scale"]>;
|
|
65
72
|
|
|
66
73
|
// The part of `Page.getLayoutMetrics` a clip needs: the visual viewport's place in the document and
|
|
67
74
|
// its pinch scale, and the content's size in device and CSS pixels, whose ratio is the device's.
|
|
@@ -163,8 +170,80 @@ const calibrator = (page: PageContext, bridge: Bridge) => {
|
|
|
163
170
|
);
|
|
164
171
|
};
|
|
165
172
|
|
|
166
|
-
// The screen as the page reads it.
|
|
167
|
-
const ScreenSize = Schema.Struct({ width: Schema.Int, height: Schema.Int });
|
|
173
|
+
// The screen as the page reads it, and its device pixels to a CSS pixel.
|
|
174
|
+
const ScreenSize = Schema.Struct({ width: Schema.Int, height: Schema.Int, ratio: Schema.Finite });
|
|
175
|
+
|
|
176
|
+
// The device as the page's own session emulates it: the screen held for crops (see `camera`), and
|
|
177
|
+
// the device scale factor a paint asks for, 0 for the device's own, in one override that keeps the
|
|
178
|
+
// view's size. Playwright emulates the viewport of a browser this library launched, at the scale of
|
|
179
|
+
// its launch, and puts that back over any other, so there a paint keeps that scale.
|
|
180
|
+
const device = (page: PageContext, bridge: Bridge) => {
|
|
181
|
+
const { playwright, native, within } = page;
|
|
182
|
+
const { send } = page.protocol;
|
|
183
|
+
let screen: Size | undefined;
|
|
184
|
+
let scaled = 0;
|
|
185
|
+
let painting = false;
|
|
186
|
+
|
|
187
|
+
const metrics = (operation: string) =>
|
|
188
|
+
native(operation, () =>
|
|
189
|
+
send("Emulation.setDeviceMetricsOverride", {
|
|
190
|
+
width: 0,
|
|
191
|
+
height: 0,
|
|
192
|
+
deviceScaleFactor: scaled,
|
|
193
|
+
mobile: false,
|
|
194
|
+
...(screen === undefined ? {} : { screenWidth: screen.width, screenHeight: screen.height }),
|
|
195
|
+
}),
|
|
196
|
+
);
|
|
197
|
+
|
|
198
|
+
const screenOf = (operation: string) =>
|
|
199
|
+
bridge
|
|
200
|
+
.evaluate(operation, scriptCall("screenSize"))
|
|
201
|
+
.pipe(Effect.flatMap(decodeWith(operation, ScreenSize)));
|
|
202
|
+
|
|
203
|
+
// The copy has the screen alone: the view keeps its own size, and the device its pixel ratio.
|
|
204
|
+
const holdScreen = Effect.fnUntraced(function* (operation: string) {
|
|
205
|
+
if (screen !== undefined) return;
|
|
206
|
+
const { width, height } = yield* screenOf(operation);
|
|
207
|
+
|
|
208
|
+
screen = { width, height };
|
|
209
|
+
yield* metrics(operation).pipe(Effect.onError(() => Effect.sync(() => (screen = undefined))));
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
const scrollbarsHidden = (hidden: boolean) =>
|
|
213
|
+
native("paint", () => send("Emulation.setScrollbarsHidden", { hidden }));
|
|
214
|
+
|
|
215
|
+
const paint = (options: Paint): Effect.Effect<void, BrowserError, Scope.Scope> =>
|
|
216
|
+
Effect.gen(function* () {
|
|
217
|
+
const { scale, scrollbars = true } = options;
|
|
218
|
+
const launched = playwright.viewportSize() !== null;
|
|
219
|
+
|
|
220
|
+
if (scale !== undefined && !(Number.isFinite(scale) && scale > 0 && scale <= 4))
|
|
221
|
+
return yield* refuse("paint", "a page paints at more than 0 and at most 4 device pixels");
|
|
222
|
+
if (painting) return yield* refuse("paint", "the page is painted for another scope already");
|
|
223
|
+
if (scale !== undefined && launched && (yield* screenOf("paint")).ratio !== scale)
|
|
224
|
+
return yield* refuse(
|
|
225
|
+
"paint",
|
|
226
|
+
"this browser paints at the scale it was launched with, as Chromium's deviceScaleFactor sets",
|
|
227
|
+
);
|
|
228
|
+
const rescaled = scale !== undefined && !launched;
|
|
229
|
+
|
|
230
|
+
painting = true;
|
|
231
|
+
yield* Effect.addFinalizer(() =>
|
|
232
|
+
Effect.gen(function* () {
|
|
233
|
+
scaled = 0;
|
|
234
|
+
if (!scrollbars) yield* scrollbarsHidden(false);
|
|
235
|
+
if (rescaled) yield* metrics("paint");
|
|
236
|
+
}).pipe(Effect.ignore, Effect.ensuring(Effect.sync(() => (painting = false)))),
|
|
237
|
+
);
|
|
238
|
+
if (!scrollbars) yield* scrollbarsHidden(true);
|
|
239
|
+
if (rescaled) {
|
|
240
|
+
scaled = scale;
|
|
241
|
+
yield* metrics("paint");
|
|
242
|
+
}
|
|
243
|
+
}).pipe(within("paint"));
|
|
244
|
+
|
|
245
|
+
return { holdScreen, paint, scaled: () => scaled };
|
|
246
|
+
};
|
|
168
247
|
|
|
169
248
|
// A new picture in CSS pixels. Where a device pixel is not a CSS pixel, or for a crop, it is
|
|
170
249
|
// Playwright's clip over fresh layout metrics: document coordinates from the visual viewport's
|
|
@@ -179,37 +258,20 @@ const ScreenSize = Schema.Struct({ width: Schema.Int, height: Schema.Int });
|
|
|
179
258
|
// one at a time.
|
|
180
259
|
const camera = (
|
|
181
260
|
page: PageContext,
|
|
182
|
-
bridge: Bridge,
|
|
183
261
|
viewport: Viewport,
|
|
184
262
|
capture: Capture.Controller,
|
|
263
|
+
{ holdScreen, scaled }: Pick<ReturnType<typeof device>, "holdScreen" | "scaled">,
|
|
185
264
|
) => {
|
|
186
265
|
const { playwright, native, within } = page;
|
|
187
266
|
const { send } = page.protocol;
|
|
188
267
|
// Device pixels per CSS pixel, as the page's layout metrics last gave it. A picture taken in one
|
|
189
268
|
// call is checked by its size, so a page whose ratio changes is measured again.
|
|
190
269
|
let ratio = 1;
|
|
191
|
-
let screenHeld = false;
|
|
192
|
-
|
|
193
|
-
// The copy has the screen alone: the view keeps its own size, and the device its pixel ratio.
|
|
194
|
-
const holdScreen = Effect.fnUntraced(function* (operation: string) {
|
|
195
|
-
if (screenHeld) return;
|
|
196
|
-
|
|
197
|
-
const { width, height } = yield* bridge
|
|
198
|
-
.evaluate(operation, scriptCall("screenSize"))
|
|
199
|
-
.pipe(Effect.flatMap(decodeWith(operation, ScreenSize)));
|
|
200
270
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
height: 0,
|
|
205
|
-
deviceScaleFactor: 0,
|
|
206
|
-
mobile: false,
|
|
207
|
-
screenWidth: width,
|
|
208
|
-
screenHeight: height,
|
|
209
|
-
}),
|
|
271
|
+
const layoutMetrics = (operation: string) =>
|
|
272
|
+
native(operation, () => send("Page.getLayoutMetrics")).pipe(
|
|
273
|
+
Effect.flatMap(decodeWith(operation, LayoutMetrics)),
|
|
210
274
|
);
|
|
211
|
-
screenHeld = true;
|
|
212
|
-
});
|
|
213
275
|
|
|
214
276
|
const decoded = (operation: string, data: Uint8Array, format: Format) => {
|
|
215
277
|
const size = format === "png" ? pngSize(data) : jpegSize(data);
|
|
@@ -292,14 +354,19 @@ const camera = (
|
|
|
292
354
|
return yield* emulatedShot(operation, format, quality, pixels, crop);
|
|
293
355
|
}
|
|
294
356
|
|
|
295
|
-
const [
|
|
296
|
-
Effect.flatMap(decodeWith(operation, LayoutMetrics)),
|
|
357
|
+
const [measured] = yield* layoutMetrics(operation).pipe(
|
|
297
358
|
Effect.zip(crop === undefined ? Effect.void : holdScreen(operation), { concurrent: true }),
|
|
298
359
|
);
|
|
299
360
|
|
|
300
|
-
const
|
|
361
|
+
const measuredRatio = measured.contentSize.width / measured.cssContentSize.width;
|
|
301
362
|
|
|
302
|
-
|
|
363
|
+
// The layout metrics report the device's own ratio, never the one a paint emulates.
|
|
364
|
+
ratio =
|
|
365
|
+
scaled() > 0
|
|
366
|
+
? scaled()
|
|
367
|
+
: Number.isFinite(measuredRatio) && measuredRatio > 0
|
|
368
|
+
? measuredRatio
|
|
369
|
+
: 1;
|
|
303
370
|
if (crop === undefined && ratio === 1) {
|
|
304
371
|
const image = whole ?? (yield* shot(operation, format, quality));
|
|
305
372
|
|
|
@@ -308,7 +375,7 @@ const camera = (
|
|
|
308
375
|
return image;
|
|
309
376
|
}
|
|
310
377
|
const rect = crop ?? { x: 0, y: 0, ...(known ?? (yield* viewport.viewportFor(operation))) };
|
|
311
|
-
const { pageX, pageY, scale } =
|
|
378
|
+
const { pageX, pageY, scale } = measured.cssVisualViewport;
|
|
312
379
|
|
|
313
380
|
yield* holdScreen(operation);
|
|
314
381
|
|
|
@@ -322,25 +389,23 @@ const camera = (
|
|
|
322
389
|
}).pipe(capture.excluding, within(operation));
|
|
323
390
|
};
|
|
324
391
|
|
|
325
|
-
// A duration in milliseconds, or NaN for an input that is no duration.
|
|
326
|
-
const millisOf = (input: Duration.Input) =>
|
|
327
|
-
Option.match(Duration.fromInput(input), { onNone: () => Number.NaN, onSome: Duration.toMillis });
|
|
328
|
-
|
|
329
392
|
// The newest screencast frame, if it shows the page as the caller asked: painted at most `maxAge`
|
|
330
393
|
// ago at the earliest its timing allows, after the current document began, and with
|
|
331
394
|
// `after: "input"` after the page's latest input, which a read asks in its turn, once the action
|
|
332
395
|
// in flight has ended. It must have the viewport's size, as a new picture would. A screencast sends
|
|
333
396
|
// only changes and can miss a final paint, so a frame is only ever as current as its age, and a
|
|
334
397
|
// page that keeps painting while the next document loads leaves its own frames newest when the
|
|
335
|
-
// navigation returns.
|
|
398
|
+
// navigation returns. A screencast frame is a JPEG of the viewport's CSS size, so a PNG or a
|
|
399
|
+
// picture in device pixels is always new.
|
|
336
400
|
const reuse =
|
|
337
401
|
(page: PageContext, bridge: Bridge, viewport: Viewport, capture: Capture.Controller) =>
|
|
338
|
-
(
|
|
402
|
+
(options: FrameOptions) =>
|
|
339
403
|
Effect.gen(function* () {
|
|
340
|
-
const maxAge = millisOf(options.maxAge ?? defaultMaxAge);
|
|
404
|
+
const maxAge = BrowserClock.millisOf(options.maxAge ?? defaultMaxAge);
|
|
341
405
|
|
|
342
406
|
if (!(maxAge >= 0))
|
|
343
|
-
return yield* refuse(
|
|
407
|
+
return yield* refuse("frame", "maxAge must be a duration of zero or more");
|
|
408
|
+
if (options.format === "png" || options.scale === "device") return Option.none<Frame>();
|
|
344
409
|
const latest = yield* capture.latest;
|
|
345
410
|
const known = viewport.knownViewport();
|
|
346
411
|
const { activity } = page;
|
|
@@ -412,60 +477,35 @@ export const make = Effect.fnUntraced(function* (
|
|
|
412
477
|
error,
|
|
413
478
|
});
|
|
414
479
|
|
|
415
|
-
const
|
|
480
|
+
const emulated = device(page, bridge);
|
|
481
|
+
const picture = camera(page, viewport, capture, emulated);
|
|
416
482
|
const reusable = reuse(page, bridge, viewport, capture);
|
|
417
483
|
// Pictures in flight are shared, never kept: their callers say how old one may be.
|
|
418
|
-
const screenshots = lane.shared<Image>("screenshot", false);
|
|
419
484
|
const frames = lane.shared<Frame>("frame", false);
|
|
420
485
|
|
|
421
|
-
// A caller that acts and then looks must see what its action did, so a screenshot waits for the
|
|
422
|
-
// action in flight and reuses only a frame painted after the page's latest input.
|
|
423
|
-
const screenshot = (options: ScreenshotOptions = {}) =>
|
|
424
|
-
screenshots(
|
|
425
|
-
JSON.stringify([
|
|
426
|
-
millisOf(options.maxAge ?? defaultMaxAge),
|
|
427
|
-
options.clip,
|
|
428
|
-
options.quality,
|
|
429
|
-
options.format,
|
|
430
|
-
options.scale,
|
|
431
|
-
]),
|
|
432
|
-
Effect.gen(function* () {
|
|
433
|
-
// A reused frame is a JPEG of the viewport's CSS size, so a PNG or a device picture is new.
|
|
434
|
-
const reused =
|
|
435
|
-
options.clip === undefined && options.format !== "png" && options.scale !== "device"
|
|
436
|
-
? yield* reusable("screenshot", { maxAge: options.maxAge, after: "input" })
|
|
437
|
-
: Option.none<Frame>();
|
|
438
|
-
|
|
439
|
-
const image = Option.isSome(reused)
|
|
440
|
-
? reused.value.image
|
|
441
|
-
: yield* picture(
|
|
442
|
-
"screenshot",
|
|
443
|
-
options.quality ?? 80,
|
|
444
|
-
options.clip,
|
|
445
|
-
options.format,
|
|
446
|
-
options.scale,
|
|
447
|
-
);
|
|
448
|
-
|
|
449
|
-
yield* Effect.annotateCurrentSpan({ source: sourceOf(reused), bytes: image.data.length });
|
|
450
|
-
|
|
451
|
-
return image;
|
|
452
|
-
}),
|
|
453
|
-
).pipe(span("Page.screenshot"), owned);
|
|
454
|
-
|
|
455
486
|
// A new screenshot has no paint time, only the host interval in which it was taken.
|
|
456
487
|
const taken = (options: FrameOptions) =>
|
|
457
488
|
Effect.gen(function* () {
|
|
458
|
-
const reused = yield* reusable(
|
|
489
|
+
const reused = yield* reusable(options);
|
|
459
490
|
|
|
460
491
|
yield* Effect.annotateCurrentSpan("source", sourceOf(reused));
|
|
461
492
|
if (Option.isSome(reused)) return reused.value;
|
|
462
493
|
const startedAt = now();
|
|
463
|
-
|
|
494
|
+
|
|
495
|
+
const image = yield* picture(
|
|
496
|
+
"frame",
|
|
497
|
+
options.quality ?? 80,
|
|
498
|
+
undefined,
|
|
499
|
+
options.format,
|
|
500
|
+
options.scale,
|
|
501
|
+
);
|
|
502
|
+
|
|
464
503
|
const finishedAt = now();
|
|
465
504
|
|
|
466
505
|
return new Frame({
|
|
467
506
|
page: id,
|
|
468
507
|
data: image.data,
|
|
508
|
+
mediaType: image.mediaType,
|
|
469
509
|
timing: new Screenshot({
|
|
470
510
|
hostTime: startedAt + (finishedAt - startedAt) / 2,
|
|
471
511
|
uncertaintyMillis: (finishedAt - startedAt) / 2,
|
|
@@ -480,25 +520,31 @@ export const make = Effect.fnUntraced(function* (
|
|
|
480
520
|
// A frame of a stated age that the screencast has costs nothing and waits for no action; one
|
|
481
521
|
// that must follow the latest input, or a new screenshot, waits for the action in flight.
|
|
482
522
|
const frame = (options: FrameOptions = {}) =>
|
|
483
|
-
(options.after === "input"
|
|
484
|
-
? Effect.succeed(Option.none<Frame>())
|
|
485
|
-
: reusable("frame", options)
|
|
486
|
-
).pipe(
|
|
523
|
+
(options.after === "input" ? Effect.succeed(Option.none<Frame>()) : reusable(options)).pipe(
|
|
487
524
|
Effect.flatMap(
|
|
488
525
|
Option.match({
|
|
489
526
|
onSome: (reused) => Effect.as(Effect.annotateCurrentSpan("source", "frame"), reused),
|
|
490
527
|
onNone: () =>
|
|
491
528
|
frames(
|
|
492
|
-
JSON.stringify([
|
|
529
|
+
JSON.stringify([
|
|
530
|
+
BrowserClock.millisOf(options.maxAge ?? defaultMaxAge),
|
|
531
|
+
options.after,
|
|
532
|
+
options.quality,
|
|
533
|
+
options.format,
|
|
534
|
+
options.scale,
|
|
535
|
+
]),
|
|
493
536
|
taken(options),
|
|
494
537
|
),
|
|
495
538
|
}),
|
|
496
539
|
),
|
|
497
|
-
span("
|
|
540
|
+
span("Frame.read"),
|
|
498
541
|
owned,
|
|
499
542
|
);
|
|
500
543
|
|
|
501
|
-
const zoom = (
|
|
544
|
+
const zoom = (
|
|
545
|
+
requested: Region,
|
|
546
|
+
options: Pick<FrameOptions, "quality" | "format" | "scale"> = {},
|
|
547
|
+
) =>
|
|
502
548
|
lane
|
|
503
549
|
.read("zoom")(
|
|
504
550
|
Effect.gen(function* () {
|
|
@@ -513,16 +559,23 @@ export const make = Effect.fnUntraced(function* (
|
|
|
513
559
|
|
|
514
560
|
if (region.x + region.width > size.width || region.y + region.height > size.height)
|
|
515
561
|
return yield* refuse("zoom", "the crop must fit entirely within the viewport");
|
|
516
|
-
|
|
562
|
+
|
|
563
|
+
const image = yield* picture(
|
|
564
|
+
"zoom",
|
|
565
|
+
options.quality ?? 80,
|
|
566
|
+
region,
|
|
567
|
+
options.format,
|
|
568
|
+
options.scale,
|
|
569
|
+
);
|
|
517
570
|
|
|
518
571
|
return new Zoom({ page: id, region, image });
|
|
519
572
|
}).pipe(within("zoom")),
|
|
520
573
|
)
|
|
521
|
-
.pipe(span("
|
|
574
|
+
.pipe(span("Frame.zoom"), owned);
|
|
522
575
|
|
|
523
576
|
const captureStats = (options: { readonly window?: Duration.Input | undefined } = {}) => {
|
|
524
577
|
if (options.window === undefined) return capture.stats();
|
|
525
|
-
const millis = millisOf(options.window);
|
|
578
|
+
const millis = BrowserClock.millisOf(options.window);
|
|
526
579
|
|
|
527
580
|
return millis > 0 && millis <= Duration.toMillis(countsKept)
|
|
528
581
|
? capture.stats(millis)
|
|
@@ -533,5 +586,5 @@ export const make = Effect.fnUntraced(function* (
|
|
|
533
586
|
// change record's times need it.
|
|
534
587
|
const estimate = mapping.current(calibrateClock);
|
|
535
588
|
|
|
536
|
-
return { capture,
|
|
589
|
+
return { capture, frame, zoom, captureStats, estimate, paint: emulated.paint };
|
|
537
590
|
});
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
*/
|
|
12
12
|
import type { SubjectContext } from "../../BrowserEvent.ts";
|
|
13
13
|
import type { Names } from "./names.inpage.ts";
|
|
14
|
-
import type {
|
|
14
|
+
import type { Walked } from "./walk.inpage.ts";
|
|
15
15
|
|
|
16
16
|
/** What one read has learnt of the page: each table's header row and each tree's headings. */
|
|
17
17
|
export interface Known {
|
|
@@ -19,7 +19,7 @@ export interface Known {
|
|
|
19
19
|
readonly headings: Map<Node, ReadonlyArray<Element>>;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
export const context = (names: Names, walked:
|
|
22
|
+
export const context = (names: Names, walked: Walked) => {
|
|
23
23
|
const { clean, isButton, isDocument, isHtml, isInput, isRoot } = names;
|
|
24
24
|
const { isSelect, isTextArea, roleOf, textOf } = names;
|
|
25
25
|
const { visible } = walked;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* In the page: the wait an expectation takes on what `find` matches, and the mark that stands for
|
|
3
3
|
* what the matches show. See `names.inpage.ts` for what a page-side part may use.
|
|
4
4
|
*/
|
|
5
|
-
import type { FindRequest, Match } from "
|
|
5
|
+
import type { FindRequest, Match } from "../matching.ts";
|
|
6
6
|
import type { Names } from "./names.inpage.ts";
|
|
7
7
|
import type { Subjects } from "./subjects.inpage.ts";
|
|
8
8
|
|