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,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The page's overlay: one lease at a time, each drawing one call to the page, in turn after the
|
|
3
|
+
* actions asked before it, never two at once. Each new document gets what was last drawn once it
|
|
4
|
+
* has loaded; the lease's scope takes the layer away.
|
|
5
|
+
*/
|
|
6
|
+
import { Duration, Effect, Schedule, Schema, type Scope, Semaphore } from "effect";
|
|
7
|
+
|
|
8
|
+
import type { BrowserError } from "../../BrowserError.ts";
|
|
9
|
+
import { Box } from "../../BrowserEvent.ts";
|
|
10
|
+
import type { Content, Overlay } from "../../Overlay.ts";
|
|
11
|
+
import { type Bridge, scriptCall } from "./bridge.ts";
|
|
12
|
+
import { decodeWith, type PageContext, refuse } from "./context.ts";
|
|
13
|
+
|
|
14
|
+
const Drawn = Schema.Array(Box);
|
|
15
|
+
|
|
16
|
+
export const make = (page: PageContext, bridge: Bridge) => {
|
|
17
|
+
const { lane, owned, span, within } = page;
|
|
18
|
+
const turns = Semaphore.makeUnsafe(1);
|
|
19
|
+
let open = false;
|
|
20
|
+
// What the layer shows, as markup, and where its parts were last drawn.
|
|
21
|
+
let shown: string | null = null;
|
|
22
|
+
let drawn: ReadonlyArray<Box> = [];
|
|
23
|
+
|
|
24
|
+
// What a call to the page drew, wherever it was drawn from.
|
|
25
|
+
const record = (markup: string | null, boxes: ReadonlyArray<Box>) => {
|
|
26
|
+
shown = markup;
|
|
27
|
+
drawn = boxes;
|
|
28
|
+
page.noteInput();
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const send = (markup: string | null) =>
|
|
32
|
+
turns.withPermit(
|
|
33
|
+
lane.read("overlay")(
|
|
34
|
+
bridge.evaluate("overlay", scriptCall("overlay", markup)).pipe(
|
|
35
|
+
Effect.flatMap(decodeWith("overlay", Drawn)),
|
|
36
|
+
Effect.tap((boxes) => Effect.sync(() => record(markup, boxes))),
|
|
37
|
+
within("overlay"),
|
|
38
|
+
),
|
|
39
|
+
),
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
const draw = (content: Content) =>
|
|
43
|
+
send(content._tag === "Svg" ? content.markup : null).pipe(span("Overlay.draw"), owned);
|
|
44
|
+
|
|
45
|
+
// Once the document after `document` has parsed, it is drawn with what was shown. A redraw that
|
|
46
|
+
// fails leaves the layer off until the next draw, which reports its own failure.
|
|
47
|
+
const redraw = (document: number) =>
|
|
48
|
+
bridge.waitForDocument(document).pipe(
|
|
49
|
+
Effect.andThen(
|
|
50
|
+
Effect.void.pipe(
|
|
51
|
+
Effect.repeat({
|
|
52
|
+
schedule: Schedule.spaced(Duration.millis(50)),
|
|
53
|
+
until: () => bridge.loaded() !== undefined,
|
|
54
|
+
}),
|
|
55
|
+
within("overlay", page.settings.navigationTimeout),
|
|
56
|
+
),
|
|
57
|
+
),
|
|
58
|
+
Effect.andThen(Effect.suspend(() => (shown === null ? Effect.void : send(shown)))),
|
|
59
|
+
Effect.ignore,
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
const lease: Effect.Effect<Overlay, BrowserError, Scope.Scope> = Effect.gen(function* () {
|
|
63
|
+
if (open) return yield* refuse("overlay", "the page has an overlay already");
|
|
64
|
+
open = true;
|
|
65
|
+
yield* Effect.addFinalizer(() =>
|
|
66
|
+
Effect.suspend(() => {
|
|
67
|
+
open = false;
|
|
68
|
+
|
|
69
|
+
return shown === null ? Effect.void : send(null).pipe(Effect.ignore);
|
|
70
|
+
}),
|
|
71
|
+
);
|
|
72
|
+
yield* Effect.forkScoped(
|
|
73
|
+
Effect.suspend(() => redraw(bridge.frameTag().document)).pipe(Effect.forever),
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
return { draw };
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
return {
|
|
80
|
+
lease,
|
|
81
|
+
drawn: () => (shown === null ? undefined : drawn),
|
|
82
|
+
open: () => open,
|
|
83
|
+
record,
|
|
84
|
+
/** Run a call that draws in the overlay's turn, so no other drawing overtakes it. */
|
|
85
|
+
turn: <A, E, R>(effect: Effect.Effect<A, E, R>) => turns.withPermit(effect),
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
export type Overlays = ReturnType<typeof make>;
|
|
@@ -7,20 +7,25 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import { Effect, Option } from "effect";
|
|
9
9
|
|
|
10
|
-
import * as ActionPort from "../../ActionPort.ts";
|
|
11
10
|
import type { Frame } from "../../Frame.ts";
|
|
12
11
|
import { type Page, State } from "../../Page.ts";
|
|
13
|
-
import * as
|
|
12
|
+
import * as ActionPort from "../action-port.ts";
|
|
14
13
|
import * as Actions from "../input/actions.ts";
|
|
15
14
|
import * as Pictures from "../pictures/pictures.ts";
|
|
15
|
+
import * as Layouts from "../reading/layout.ts";
|
|
16
16
|
import * as Reading from "../reading/reading.ts";
|
|
17
17
|
import * as Ready from "../reading/ready.ts";
|
|
18
18
|
import * as Changes from "../timeline/changes.ts";
|
|
19
19
|
import * as Window from "../timeline/window.ts";
|
|
20
|
+
import * as Url from "../url.ts";
|
|
20
21
|
import * as Bridge from "./bridge.ts";
|
|
21
22
|
import * as Context from "./context.ts";
|
|
23
|
+
import { Implementation, key } from "./functions.ts";
|
|
22
24
|
import * as Navigation from "./navigation.ts";
|
|
25
|
+
import * as Overlay from "./overlay.ts";
|
|
26
|
+
import * as Poses from "./pose.ts";
|
|
23
27
|
import * as Scripts from "./scripts.ts";
|
|
28
|
+
import * as Time from "./time.ts";
|
|
24
29
|
import * as Viewport from "./viewport.ts";
|
|
25
30
|
|
|
26
31
|
export const make = Effect.fnUntraced(function* (options: Context.MakeOptions) {
|
|
@@ -34,12 +39,14 @@ export const make = Effect.fnUntraced(function* (options: Context.MakeOptions) {
|
|
|
34
39
|
const navigation = Navigation.make(page, input.perform, input.preparePolicy);
|
|
35
40
|
const { capture } = pictures;
|
|
36
41
|
const changes = Changes.make(page, bridge, pictures.estimate);
|
|
42
|
+
const overlay = Overlay.make(page, bridge);
|
|
43
|
+
const poses = Poses.make(page, bridge);
|
|
37
44
|
const titles = lane.shared<string>("title", true);
|
|
38
45
|
const viewports = lane.shared<Effect.Success<Page["viewport"]>>("viewport", true);
|
|
39
46
|
|
|
40
47
|
// What the page's parts already know, asking it nothing: its documents as its own session saw
|
|
41
|
-
// them
|
|
42
|
-
const state = Effect.
|
|
48
|
+
// them.
|
|
49
|
+
const state = Effect.sync(() => {
|
|
43
50
|
const { document, url } = bridge.frameTag();
|
|
44
51
|
const committedAt = page.activity.documentAt;
|
|
45
52
|
|
|
@@ -51,8 +58,6 @@ export const make = Effect.fnUntraced(function* (options: Context.MakeOptions) {
|
|
|
51
58
|
document,
|
|
52
59
|
committedAt: Number.isFinite(committedAt) ? committedAt : undefined,
|
|
53
60
|
load: bridge.loaded(),
|
|
54
|
-
frame: Option.getOrUndefined(latest),
|
|
55
|
-
text: reading.viewedSince(committedAt),
|
|
56
61
|
});
|
|
57
62
|
});
|
|
58
63
|
|
|
@@ -82,45 +87,50 @@ export const make = Effect.fnUntraced(function* (options: Context.MakeOptions) {
|
|
|
82
87
|
);
|
|
83
88
|
|
|
84
89
|
const assembled: Page = {
|
|
90
|
+
[key]: new Implementation({
|
|
91
|
+
snapshot: reading.snapshot,
|
|
92
|
+
find: reading.find,
|
|
93
|
+
until: reading.until,
|
|
94
|
+
text: reading.text,
|
|
95
|
+
layout: Layouts.make(page, bridge),
|
|
96
|
+
changes,
|
|
97
|
+
window: Window.make(page, changes, capture.recent),
|
|
98
|
+
overlay: overlay.lease,
|
|
99
|
+
drawn: Effect.sync(() => Option.fromUndefinedOr(overlay.drawn())),
|
|
100
|
+
poses: poses.lease,
|
|
101
|
+
hold: Time.make(page, bridge, overlay, poses).hold,
|
|
102
|
+
frame: pictures.frame,
|
|
103
|
+
zoom: pictures.zoom,
|
|
104
|
+
capture: (options) =>
|
|
105
|
+
capture.open(options).pipe(
|
|
106
|
+
Effect.map((lease) => ({
|
|
107
|
+
...lease,
|
|
108
|
+
isCurrent: current,
|
|
109
|
+
confirm,
|
|
110
|
+
sync: capture.sync,
|
|
111
|
+
stats: pictures.captureStats,
|
|
112
|
+
})),
|
|
113
|
+
),
|
|
114
|
+
recentFrames: capture.recent,
|
|
115
|
+
paint: pictures.paint,
|
|
116
|
+
}),
|
|
85
117
|
...Scripts.make(page, bridge, input),
|
|
86
118
|
...ActionPort.methods(perform),
|
|
87
119
|
perform,
|
|
88
|
-
|
|
120
|
+
hostClock: page.clock,
|
|
89
121
|
afterInput,
|
|
90
|
-
until: reading.until,
|
|
91
|
-
capture: (options) =>
|
|
92
|
-
capture.open(options).pipe(
|
|
93
|
-
Effect.map((lease) => ({
|
|
94
|
-
...lease,
|
|
95
|
-
isCurrent: current,
|
|
96
|
-
confirm,
|
|
97
|
-
sync: capture.sync,
|
|
98
|
-
stats: pictures.captureStats,
|
|
99
|
-
})),
|
|
100
|
-
),
|
|
101
122
|
id,
|
|
102
123
|
url: Effect.sync(() => Url.redact(playwright.url())),
|
|
103
124
|
title: titles("", navigation.title.pipe(within("title"))).pipe(span("Page.title"), owned),
|
|
104
125
|
bringToFront: native("bringToFront", () => playwright.bringToFront()),
|
|
105
126
|
// Playwright answers once the page has closed, and at once for one already closed.
|
|
106
127
|
close: native("close", () => playwright.close()),
|
|
107
|
-
snapshot: reading.snapshot,
|
|
108
|
-
screenshot: pictures.screenshot,
|
|
109
|
-
frame: pictures.frame,
|
|
110
|
-
zoom: pictures.zoom,
|
|
111
128
|
viewport: viewports("", viewport.viewportFor("viewport").pipe(within("viewport"))).pipe(
|
|
112
129
|
span("Page.viewport"),
|
|
113
130
|
owned,
|
|
114
131
|
),
|
|
115
|
-
find: reading.find,
|
|
116
|
-
text: reading.text,
|
|
117
|
-
changes,
|
|
118
|
-
window: Window.make(page, changes, capture.recent),
|
|
119
132
|
state,
|
|
120
133
|
ready: Ready.make(page, bridge),
|
|
121
|
-
screencast: capture.stream,
|
|
122
|
-
captureStats: pictures.captureStats,
|
|
123
|
-
recentFrames: capture.recent,
|
|
124
134
|
recentEvents: options.recentEvents,
|
|
125
135
|
};
|
|
126
136
|
|
|
@@ -5,13 +5,19 @@ import type { BrowserContext, CDPSession, Page as NativePage } from "playwright-
|
|
|
5
5
|
import type { CaptureSource } from "../../Browser.ts";
|
|
6
6
|
import { call } from "../../BrowserError.ts";
|
|
7
7
|
|
|
8
|
-
export const Operation = Context.Reference<string | undefined>(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
export const Operation = Context.Reference<string | undefined>(
|
|
9
|
+
"effect-browser/internal/page/ProtocolOperation",
|
|
10
|
+
{
|
|
11
|
+
defaultValue: () => undefined,
|
|
12
|
+
},
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
export const Script = Context.Reference<string | undefined>(
|
|
16
|
+
"effect-browser/internal/page/ProtocolScript",
|
|
17
|
+
{
|
|
18
|
+
defaultValue: () => undefined,
|
|
19
|
+
},
|
|
20
|
+
);
|
|
15
21
|
|
|
16
22
|
export interface Session {
|
|
17
23
|
readonly channel: "page" | "capture" | "browser";
|
|
@@ -50,7 +56,7 @@ export interface Hooks {
|
|
|
50
56
|
readonly opened?: ((session: Session, inject: (event: Event) => void) => () => void) | undefined;
|
|
51
57
|
}
|
|
52
58
|
|
|
53
|
-
export const Current = Context.Reference<Hooks>("effect-browser/ProtocolPort", {
|
|
59
|
+
export const Current = Context.Reference<Hooks>("effect-browser/internal/page/ProtocolPort", {
|
|
54
60
|
defaultValue: () => ({}),
|
|
55
61
|
});
|
|
56
62
|
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In the page: element poses. A pose moves, turns and scales one of the page's own elements about
|
|
3
|
+
* a point in the viewport, through the CSS `translate`, `rotate` and `scale` properties, which
|
|
4
|
+
* apply around the element's `transform`, so the page's own transform still holds beneath. Each is
|
|
5
|
+
* a Web Animation with no end and one value: it sets no attribute and starts none of the page's
|
|
6
|
+
* transitions, the page clock's holding leaves its value as it is, and `ready` waits only for
|
|
7
|
+
* animations that end. Taking poses off cancels them. See `names.inpage.ts` for what a page-side
|
|
8
|
+
* part may use.
|
|
9
|
+
*/
|
|
10
|
+
import type { Pose } from "../../Pose.ts";
|
|
11
|
+
import type { Names } from "../reading/names.inpage.ts";
|
|
12
|
+
|
|
13
|
+
export interface PoseRequest {
|
|
14
|
+
readonly ref: string;
|
|
15
|
+
readonly dx: number;
|
|
16
|
+
readonly dy: number;
|
|
17
|
+
readonly sx: number;
|
|
18
|
+
readonly sy: number;
|
|
19
|
+
/** Degrees, clockwise. */
|
|
20
|
+
readonly rotate: number;
|
|
21
|
+
/** In the viewport, or null for the middle of where the page draws it. */
|
|
22
|
+
readonly origin: { readonly x: number; readonly y: number } | null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** A pose as the page takes it, each part left out made the one that changes nothing. */
|
|
26
|
+
export const poseRequest = (pose: Pose): PoseRequest => ({
|
|
27
|
+
ref: pose.ref,
|
|
28
|
+
dx: pose.dx ?? 0,
|
|
29
|
+
dy: pose.dy ?? 0,
|
|
30
|
+
sx: pose.sx ?? 1,
|
|
31
|
+
sy: pose.sy ?? 1,
|
|
32
|
+
rotate: pose.rotate ?? 0,
|
|
33
|
+
origin: pose.origin ?? null,
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
type Prepared =
|
|
37
|
+
| { readonly stale: string }
|
|
38
|
+
| { readonly invalid: string }
|
|
39
|
+
| { readonly apply: () => void };
|
|
40
|
+
|
|
41
|
+
interface Applied {
|
|
42
|
+
readonly x: number;
|
|
43
|
+
readonly y: number;
|
|
44
|
+
readonly rotate: number;
|
|
45
|
+
readonly sx: number;
|
|
46
|
+
readonly sy: number;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export const pose = (names: Names) => {
|
|
50
|
+
const posed = new Map<
|
|
51
|
+
HTMLElement,
|
|
52
|
+
{ animation: Animation; effect: KeyframeEffect; applied: Applied }
|
|
53
|
+
>();
|
|
54
|
+
|
|
55
|
+
// Elements of a same-origin frame come from another realm, so a property decides, not instanceof.
|
|
56
|
+
const isHtml = (element: Element): element is HTMLElement => "offsetWidth" in element;
|
|
57
|
+
|
|
58
|
+
// Where the element's border box is laid out in the viewport, and its transform origin there,
|
|
59
|
+
// from where it is drawn: its corners, about the origin, through the page's transform and then
|
|
60
|
+
// the pose last set. Exact unless an ancestor is transformed.
|
|
61
|
+
const laidOut = (element: HTMLElement, applied: Applied | undefined) => {
|
|
62
|
+
const style = getComputedStyle(element);
|
|
63
|
+
const [cx = 0, cy = 0] = style.transformOrigin.split(" ").map(Number.parseFloat);
|
|
64
|
+
const own = style.transform === "none" ? new DOMMatrix() : new DOMMatrix(style.transform);
|
|
65
|
+
|
|
66
|
+
const whole =
|
|
67
|
+
applied === undefined
|
|
68
|
+
? own
|
|
69
|
+
: new DOMMatrix()
|
|
70
|
+
.translate(applied.x, applied.y)
|
|
71
|
+
.rotate(applied.rotate)
|
|
72
|
+
.scale(applied.sx, applied.sy)
|
|
73
|
+
.multiply(own);
|
|
74
|
+
|
|
75
|
+
const drawn = element.getBoundingClientRect();
|
|
76
|
+
const plain = whole.isIdentity;
|
|
77
|
+
const width = plain ? drawn.width : element.offsetWidth;
|
|
78
|
+
const height = plain ? drawn.height : element.offsetHeight;
|
|
79
|
+
let left = Infinity;
|
|
80
|
+
let top = Infinity;
|
|
81
|
+
|
|
82
|
+
for (const [x, y] of [
|
|
83
|
+
[0, 0],
|
|
84
|
+
[width, 0],
|
|
85
|
+
[0, height],
|
|
86
|
+
[width, height],
|
|
87
|
+
] as const) {
|
|
88
|
+
const corner = whole.transformPoint({ x: x - cx, y: y - cy });
|
|
89
|
+
|
|
90
|
+
left = Math.min(left, corner.x + cx);
|
|
91
|
+
top = Math.min(top, corner.y + cy);
|
|
92
|
+
}
|
|
93
|
+
const origin = { x: drawn.x - left + cx, y: drawn.y - top + cy };
|
|
94
|
+
// The middle of the box as the page's own transform draws it.
|
|
95
|
+
const middle = own.transformPoint({ x: width / 2 - cx, y: height / 2 - cy });
|
|
96
|
+
|
|
97
|
+
return { origin, middle: { x: origin.x + middle.x, y: origin.y + middle.y } };
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
const apply = (element: HTMLElement, request: PoseRequest) => {
|
|
101
|
+
const known = posed.get(element);
|
|
102
|
+
const { origin, middle } = laidOut(element, known?.applied);
|
|
103
|
+
const about = request.origin ?? middle;
|
|
104
|
+
const away = { x: about.x - origin.x, y: about.y - origin.y };
|
|
105
|
+
|
|
106
|
+
const turned = new DOMMatrix()
|
|
107
|
+
.rotate(request.rotate)
|
|
108
|
+
.scale(request.sx, request.sy)
|
|
109
|
+
.transformPoint(away);
|
|
110
|
+
|
|
111
|
+
// Turning and scaling about the element's own origin, then moving it by the difference, turns
|
|
112
|
+
// and scales it about `about`.
|
|
113
|
+
const applied = {
|
|
114
|
+
x: request.dx + away.x - turned.x,
|
|
115
|
+
y: request.dy + away.y - turned.y,
|
|
116
|
+
rotate: request.rotate,
|
|
117
|
+
sx: request.sx,
|
|
118
|
+
sy: request.sy,
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
const frame = {
|
|
122
|
+
translate: `${applied.x}px ${applied.y}px`,
|
|
123
|
+
rotate: `${applied.rotate}deg`,
|
|
124
|
+
scale: `${applied.sx} ${applied.sy}`,
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
if (known === undefined) {
|
|
128
|
+
const effect = new KeyframeEffect(element, [frame, frame], {
|
|
129
|
+
duration: Infinity,
|
|
130
|
+
fill: "both",
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
const animation = new Animation(effect, document.timeline);
|
|
134
|
+
|
|
135
|
+
animation.play();
|
|
136
|
+
posed.set(element, { animation, effect, applied });
|
|
137
|
+
} else {
|
|
138
|
+
known.effect.setKeyframes([frame, frame]);
|
|
139
|
+
known.applied = applied;
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
const takeOff = (element: HTMLElement) => {
|
|
144
|
+
posed.get(element)?.animation.cancel();
|
|
145
|
+
posed.delete(element);
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* The elements `requests` name, or the first that names none in the current document, or one
|
|
150
|
+
* that is not an HTML element; then, to apply them, a function that poses them and takes poses
|
|
151
|
+
* off every other element.
|
|
152
|
+
*/
|
|
153
|
+
const prepare = (requests: ReadonlyArray<PoseRequest>): Prepared => {
|
|
154
|
+
const elements: Array<HTMLElement> = [];
|
|
155
|
+
|
|
156
|
+
for (const request of requests) {
|
|
157
|
+
const element = names.lookup(request.ref);
|
|
158
|
+
|
|
159
|
+
const { dx, dy, sx, sy, rotate, origin } = request;
|
|
160
|
+
|
|
161
|
+
if (element === undefined) return { stale: request.ref };
|
|
162
|
+
if (!isHtml(element)) return { invalid: `${request.ref} is not an HTML element` };
|
|
163
|
+
if (![dx, dy, sx, sy, rotate, origin?.x ?? 0, origin?.y ?? 0].every(Number.isFinite))
|
|
164
|
+
return { invalid: `${request.ref}'s pose is not finite numbers` };
|
|
165
|
+
elements.push(element);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
return {
|
|
169
|
+
apply: () => {
|
|
170
|
+
for (const element of Array.from(posed.keys()))
|
|
171
|
+
if (!elements.includes(element)) takeOff(element);
|
|
172
|
+
requests.forEach((request, index) => {
|
|
173
|
+
const element = elements[index];
|
|
174
|
+
|
|
175
|
+
if (element !== undefined) apply(element, request);
|
|
176
|
+
});
|
|
177
|
+
},
|
|
178
|
+
};
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
const set = (requests: ReadonlyArray<PoseRequest>) => {
|
|
182
|
+
const prepared = prepare(requests);
|
|
183
|
+
|
|
184
|
+
if ("apply" in prepared) {
|
|
185
|
+
prepared.apply();
|
|
186
|
+
|
|
187
|
+
return {};
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
return prepared;
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
const clear = () => {
|
|
194
|
+
for (const element of Array.from(posed.keys())) takeOff(element);
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
return { prepare, set, clear };
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
export type Posing = ReturnType<typeof pose>;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The page's poses: one lease at a time, each `set` one call to the page in the page's turn, as an
|
|
3
|
+
* action takes it, so no action resolves a target that a pose then moves. The lease's scope takes
|
|
4
|
+
* every pose off. See `Pose`.
|
|
5
|
+
*/
|
|
6
|
+
import { Effect, Schema, type Scope } from "effect";
|
|
7
|
+
|
|
8
|
+
import { type BrowserError, StaleRef } from "../../BrowserError.ts";
|
|
9
|
+
import { Pose, type Poses } from "../../Pose.ts";
|
|
10
|
+
import { type Bridge, scriptCall } from "./bridge.ts";
|
|
11
|
+
import { decodeWith, failWith, type PageContext, refuse } from "./context.ts";
|
|
12
|
+
import { poseRequest } from "./pose.inpage.ts";
|
|
13
|
+
|
|
14
|
+
/** What posing answered: nothing, or the ref it could not pose and why. */
|
|
15
|
+
export const Posed = Schema.Struct({
|
|
16
|
+
stale: Schema.optional(Schema.String),
|
|
17
|
+
invalid: Schema.optional(Schema.String),
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
export const make = (page: PageContext, bridge: Bridge) => {
|
|
21
|
+
const { lane, owned, span, within } = page;
|
|
22
|
+
let open = false;
|
|
23
|
+
|
|
24
|
+
/** The page's requests for `poses`, each part left out made the one that changes nothing. */
|
|
25
|
+
const requests = Effect.fnUntraced(function* (operation: string, poses: ReadonlyArray<Pose>) {
|
|
26
|
+
const decoded = yield* Schema.decodeEffect(Schema.Array(Pose))(poses).pipe(
|
|
27
|
+
Effect.catch(() => refuse(operation, "each pose is a ref and finite numbers")),
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
if (decoded.length > 256)
|
|
31
|
+
return yield* refuse(operation, "at most 256 elements are posed at once");
|
|
32
|
+
|
|
33
|
+
return decoded.map(poseRequest);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
/** Fail as the page's answer says, if it posed nothing. */
|
|
37
|
+
const answered = (operation: string, posed: typeof Posed.Type) =>
|
|
38
|
+
posed.stale !== undefined
|
|
39
|
+
? failWith(operation, new StaleRef({ ref: posed.stale }))
|
|
40
|
+
: posed.invalid !== undefined
|
|
41
|
+
? refuse(operation, posed.invalid)
|
|
42
|
+
: Effect.void;
|
|
43
|
+
|
|
44
|
+
const send = (operation: string, script: string) =>
|
|
45
|
+
lane.write(
|
|
46
|
+
operation,
|
|
47
|
+
page.settings.actionTimeout,
|
|
48
|
+
)(
|
|
49
|
+
bridge.evaluate(operation, script).pipe(
|
|
50
|
+
Effect.flatMap(decodeWith(operation, Posed)),
|
|
51
|
+
Effect.flatMap((posed) => answered(operation, posed)),
|
|
52
|
+
Effect.tap(() => Effect.sync(page.noteInput)),
|
|
53
|
+
within(operation),
|
|
54
|
+
),
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
const set = (poses: ReadonlyArray<Pose>) =>
|
|
58
|
+
requests("pose", poses).pipe(
|
|
59
|
+
Effect.flatMap((made) => send("pose", scriptCall("pose", made))),
|
|
60
|
+
span("Poses.set"),
|
|
61
|
+
owned,
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
const lease: Effect.Effect<Poses, BrowserError, Scope.Scope> = Effect.gen(function* () {
|
|
65
|
+
if (open) return yield* refuse("pose", "the page's poses are open already");
|
|
66
|
+
open = true;
|
|
67
|
+
yield* Effect.addFinalizer(() =>
|
|
68
|
+
send("pose", scriptCall("unpose")).pipe(
|
|
69
|
+
Effect.ignore,
|
|
70
|
+
Effect.ensuring(Effect.sync(() => (open = false))),
|
|
71
|
+
),
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
return { set };
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
return { lease, open: () => open, requests, answered };
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
export type Posing = ReturnType<typeof make>;
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
undispatched,
|
|
14
14
|
} from "../../BrowserError.ts";
|
|
15
15
|
import { type BrowserEvent, RequestRefused } from "../../BrowserEvent.ts";
|
|
16
|
-
import * as Url from "
|
|
16
|
+
import * as Url from "../url.ts";
|
|
17
17
|
import * as Port from "./port.ts";
|
|
18
18
|
import * as Owner from "./request-owner.ts";
|
|
19
19
|
|
|
@@ -11,8 +11,8 @@ import {
|
|
|
11
11
|
refuse,
|
|
12
12
|
} from "../../BrowserError.ts";
|
|
13
13
|
import { InputRequest, type Page } from "../../Page.ts";
|
|
14
|
-
import * as Url from "../../Url.ts";
|
|
15
14
|
import type { Input } from "../input/actions.ts";
|
|
15
|
+
import * as Url from "../url.ts";
|
|
16
16
|
import type { Bridge } from "./bridge.ts";
|
|
17
17
|
import { contextGone, type PageContext } from "./context.ts";
|
|
18
18
|
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In the page: one step of what a held page shows, in one call. The document is scrolled first,
|
|
3
|
+
* then the page clock in the main world is told what to do, so the page's own handlers see the
|
|
4
|
+
* scroll as its time moves, then elements are posed and the overlay is drawn. A pose naming an
|
|
5
|
+
* element the document no longer has is found before any of it, and the step does nothing. The
|
|
6
|
+
* clock hears an event only it and the
|
|
7
|
+
* library know the name of (see `clock.inpage.ts`), and acknowledges it. See `names.inpage.ts` for
|
|
8
|
+
* what a page-side part may use.
|
|
9
|
+
*/
|
|
10
|
+
import type { Overlay } from "./overlay.inpage.ts";
|
|
11
|
+
import type { PoseRequest, Posing } from "./pose.inpage.ts";
|
|
12
|
+
|
|
13
|
+
export interface StepRequest {
|
|
14
|
+
/** The page clock's event name. */
|
|
15
|
+
readonly clock: string;
|
|
16
|
+
readonly op: "hold" | "advance" | "release";
|
|
17
|
+
readonly by: number;
|
|
18
|
+
/** Where to scroll the document to, in CSS pixels down it, or null to leave it. */
|
|
19
|
+
readonly scroll: number | null;
|
|
20
|
+
/** What the overlay shows, null for nothing; left out, the overlay is left alone. */
|
|
21
|
+
readonly markup?: string | null | undefined;
|
|
22
|
+
/** The elements to pose, and no others; left out, poses are left alone. */
|
|
23
|
+
readonly poses?: ReadonlyArray<PoseRequest> | undefined;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const time = (overlaid: Overlay, posing: Posing) => {
|
|
27
|
+
const step = (request: StepRequest) => {
|
|
28
|
+
const posed = request.poses === undefined ? undefined : posing.prepare(request.poses);
|
|
29
|
+
|
|
30
|
+
if (posed !== undefined && !("apply" in posed))
|
|
31
|
+
return { told: false, drawn: null, scroll: { x: scrollX, y: scrollY }, ...posed };
|
|
32
|
+
if (request.scroll !== null)
|
|
33
|
+
scrollTo({ left: scrollX, top: request.scroll, behavior: "instant" });
|
|
34
|
+
const detail = { op: request.op, by: request.by };
|
|
35
|
+
|
|
36
|
+
const told = !document.dispatchEvent(
|
|
37
|
+
new CustomEvent(request.clock, { detail, cancelable: true }),
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
posed?.apply();
|
|
41
|
+
const drawn = request.markup === undefined ? null : overlaid.draw(request.markup);
|
|
42
|
+
|
|
43
|
+
return { told, drawn, scroll: { x: scrollX, y: scrollY } };
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
return { step };
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export type Time = ReturnType<typeof time>;
|