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
|
@@ -1,18 +1,25 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { nameOf, recorded } from "
|
|
5
|
-
import { Action, Box, CursorChanged, DialogShown, Disconnected, KeyChanged, Navigated, PageClosed, PageLoaded, PageOpened, PageUntracked, PointerPressed, PointerReleased,
|
|
6
|
-
import { BrowserError, Busy, Closed,
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
2
|
+
import { a as maximumSamples, n as Point, t as Plan } from "./geometry-Lxyflb9J.mjs";
|
|
3
|
+
import { a as redactWithin, i as redact, n as parse } from "./url-DB0pQYk6.mjs";
|
|
4
|
+
import { nameOf, recorded } from "../Action.mjs";
|
|
5
|
+
import { Action, ActionAnnounced, Box, CursorChanged, DialogShown, Disconnected, KeyChanged, Navigated, PageClosed, PageLoaded, PageOpened, PageUntracked, PointerPressed, PointerReleased, RequestRefused, SessionEnding, Subject, TextInserted, TrackEvent, TrackPerformed, TrackPlanned, WheelScrolled } from "../BrowserEvent.mjs";
|
|
6
|
+
import { BrowserError, Busy, Closed, Failed, InvalidRequest, Limit, NavigationFailed, NotActionable, NotFound, PolicyTimeout, StaleRef, Suspended, Threw, Timeout, call, failWith, reasonOf, refuse, undispatched } from "../BrowserError.mjs";
|
|
7
|
+
import { a as toBrowserSeconds, i as monotonicMillis, n as mapping, o as toHostTime, r as millisOf, s as uncertaintyAt, t as estimate } from "./clock-BKSAEf00.mjs";
|
|
8
|
+
import { a as State, d as FailFast, f as make$31, i as ResolvedTarget, l as redacted, m as ValidatedInputResultSchema, n as InputRequest, p as PreparedInputResultSchema, u as Correlation } from "./Page-DqF-tuTx.mjs";
|
|
9
|
+
import { n as pickRequests, r as request } from "./matching-Cs-UeOY0.mjs";
|
|
10
|
+
import { n as poseRequest } from "./pose.inpage-CBFeWcVa.mjs";
|
|
11
|
+
import "./fold.inpage-uhrT-dOB.mjs";
|
|
12
|
+
import { i as key, t as Implementation } from "./functions-jBOs6GKv.mjs";
|
|
13
|
+
import { n as execute, r as methods, t as checked } from "./action-port-B5EkeGOR.mjs";
|
|
14
|
+
import { d as description, f as parts$1, t as Current$2, u as validated } from "./InputStyle-CPzxoN4g.mjs";
|
|
15
|
+
import { BrowserPaint, CaptureStats, Frame, Image, Region, Screenshot, Zoom, sameCapture } from "../Frame.mjs";
|
|
16
|
+
import { Layout, Place, Word } from "../Layout.mjs";
|
|
17
|
+
import { Found, Snapshot } from "../Snapshot.mjs";
|
|
18
|
+
import { Text } from "../Text.mjs";
|
|
19
|
+
import { Change, Changes } from "../Change.mjs";
|
|
20
|
+
import { Window } from "../Window.mjs";
|
|
21
|
+
import { Pose } from "../Pose.mjs";
|
|
22
|
+
import { t as make$32 } from "./events-DzCrww-y.mjs";
|
|
16
23
|
import { Cache, Cause, Clock, Context, Data, DateTime, Deferred, Duration, Effect, Exit, Fiber, FiberSet, MutableRef, Option, Queue, Ref, Result, Schedule, Schema, Scope, Semaphore, Stream, SynchronizedRef } from "effect";
|
|
17
24
|
import { SecureRandom } from "effect/crypto";
|
|
18
25
|
import { Base64 } from "effect/encoding";
|
|
@@ -73,7 +80,7 @@ const step$1 = (state, input, stopped) => {
|
|
|
73
80
|
} : state;
|
|
74
81
|
}
|
|
75
82
|
};
|
|
76
|
-
const make$
|
|
83
|
+
const make$30 = (options) => {
|
|
77
84
|
let state = {
|
|
78
85
|
_tag: "Open",
|
|
79
86
|
inputs: /* @__PURE__ */ new Set()
|
|
@@ -149,12 +156,57 @@ const make$27 = (options) => {
|
|
|
149
156
|
})
|
|
150
157
|
};
|
|
151
158
|
};
|
|
159
|
+
const TypeableResultSchema = Schema.Union([Schema.Struct({
|
|
160
|
+
ok: Schema.Literal(true),
|
|
161
|
+
secret: Schema.Boolean,
|
|
162
|
+
subject: Schema.optional(Subject)
|
|
163
|
+
}), Schema.Struct({
|
|
164
|
+
error: Schema.Literals(["stale", "untypeable"]),
|
|
165
|
+
detail: Schema.String
|
|
166
|
+
})]);
|
|
167
|
+
const EditFailure = Schema.Struct({
|
|
168
|
+
error: Schema.String,
|
|
169
|
+
stale: Schema.optional(Schema.Boolean)
|
|
170
|
+
});
|
|
171
|
+
const FocusResultSchema = Schema.Union([Schema.Struct({
|
|
172
|
+
ok: Schema.Literal(true),
|
|
173
|
+
detail: Schema.String,
|
|
174
|
+
secret: Schema.Boolean
|
|
175
|
+
}), EditFailure]);
|
|
176
|
+
const EditResultSchema = Schema.Union([Schema.Struct({
|
|
177
|
+
ok: Schema.Literal(true),
|
|
178
|
+
detail: Schema.String
|
|
179
|
+
}), EditFailure]);
|
|
180
|
+
const ResolvedPointSchema = Schema.Struct({
|
|
181
|
+
...Point.fields,
|
|
182
|
+
...Subject.fields,
|
|
183
|
+
element: Schema.String,
|
|
184
|
+
box: Schema.optional(Box),
|
|
185
|
+
cursor: Schema.String,
|
|
186
|
+
href: Schema.optional(Schema.String)
|
|
187
|
+
});
|
|
188
|
+
const PointResultSchema = Schema.Union([ResolvedPointSchema, Schema.Struct({
|
|
189
|
+
error: Schema.Literals([
|
|
190
|
+
"stale",
|
|
191
|
+
"hidden",
|
|
192
|
+
"offscreen",
|
|
193
|
+
"disabled",
|
|
194
|
+
"covered",
|
|
195
|
+
"outside"
|
|
196
|
+
]),
|
|
197
|
+
detail: Schema.String
|
|
198
|
+
})]);
|
|
199
|
+
const ScrollPlanSchema = Schema.NullOr(Schema.Struct({
|
|
200
|
+
...Point.fields,
|
|
201
|
+
dx: Schema.Finite,
|
|
202
|
+
dy: Schema.Finite
|
|
203
|
+
}));
|
|
152
204
|
//#endregion
|
|
153
205
|
//#region src/internal/page/port.ts
|
|
154
206
|
/** Scoped protocol interception at the owned session boundary; native is the default. */
|
|
155
|
-
const Operation = Context.Reference("effect-browser/ProtocolOperation", { defaultValue: () => void 0 });
|
|
156
|
-
const Script = Context.Reference("effect-browser/ProtocolScript", { defaultValue: () => void 0 });
|
|
157
|
-
const Current$1 = Context.Reference("effect-browser/ProtocolPort", { defaultValue: () => ({}) });
|
|
207
|
+
const Operation = Context.Reference("effect-browser/internal/page/ProtocolOperation", { defaultValue: () => void 0 });
|
|
208
|
+
const Script = Context.Reference("effect-browser/internal/page/ProtocolScript", { defaultValue: () => void 0 });
|
|
209
|
+
const Current$1 = Context.Reference("effect-browser/internal/page/ProtocolPort", { defaultValue: () => ({}) });
|
|
158
210
|
/** The provider owns creation and passes its session to an optional scoped test adapter. */
|
|
159
211
|
const openSession = Effect.fnUntraced(function* (open, nativePage, channel = "page") {
|
|
160
212
|
const hooks = yield* Current$1;
|
|
@@ -205,7 +257,7 @@ const openCapture = Effect.fnUntraced(function* (page, source, handlers) {
|
|
|
205
257
|
var InputFailure = class extends Data.TaggedError("InputFailure") {};
|
|
206
258
|
/** Native page calls join their operation's reply ownership, including script mutations. */
|
|
207
259
|
const Current = Context.Reference("effect-browser/internal/input/Current", { defaultValue: () => void 0 });
|
|
208
|
-
const make$
|
|
260
|
+
const make$29 = () => {
|
|
209
261
|
const outstanding = /* @__PURE__ */ new Set();
|
|
210
262
|
const idle = Effect.gen(function* () {
|
|
211
263
|
while (outstanding.size > 0) yield* Effect.promise(() => Promise.all(outstanding));
|
|
@@ -339,7 +391,7 @@ const CurrentCost = Context.Reference("effect-browser/internal/page/CurrentCost"
|
|
|
339
391
|
const track = (reply) => Fiber.getCurrent()?.getRef(Current)?.track(reply) ?? reply;
|
|
340
392
|
const sizeOf = (value) => value === void 0 ? 0 : new TextEncoder().encode(JSON.stringify(value)).byteLength;
|
|
341
393
|
const decodeWith = (operation, schema) => (value) => Schema.decodeUnknownEffect(schema)(value).pipe(Effect.mapError((error) => undispatched(operation, new Failed({ detail: error.message }))));
|
|
342
|
-
const make$
|
|
394
|
+
const make$28 = (options, scope) => {
|
|
343
395
|
const { id, clock } = options;
|
|
344
396
|
const now = () => monotonicMillis(clock);
|
|
345
397
|
const owned = Effect.provideService(Clock.Clock, clock);
|
|
@@ -406,7 +458,7 @@ const make$25 = (options, scope) => {
|
|
|
406
458
|
const noteInput = () => {
|
|
407
459
|
activity.inputAt = Math.max(activity.inputAt, now());
|
|
408
460
|
};
|
|
409
|
-
const lane = make$
|
|
461
|
+
const lane = make$31({
|
|
410
462
|
now,
|
|
411
463
|
actionTimeout: options.settings.actionTimeout,
|
|
412
464
|
documentAt: () => activity.documentAt,
|
|
@@ -433,264 +485,24 @@ const make$25 = (options, scope) => {
|
|
|
433
485
|
noteInput
|
|
434
486
|
};
|
|
435
487
|
};
|
|
436
|
-
|
|
437
|
-
//#region src/internal/page/dialogs.ts
|
|
438
|
-
/** Scoped dialog responses publish their actual outcome and invalidate their page after failed answers. */
|
|
488
|
+
const encodeString = Schema.encodeSync(Schema.fromJsonString(Schema.String));
|
|
439
489
|
/**
|
|
440
|
-
*
|
|
441
|
-
*
|
|
442
|
-
* documents' commits and loads.
|
|
443
|
-
*/
|
|
444
|
-
const listen = Effect.fnUntraced(function* (playwright, page, publish, now, answer, on) {
|
|
445
|
-
const dialogs = yield* Queue.bounded(8);
|
|
446
|
-
const dialog = (shown) => {
|
|
447
|
-
if (!Queue.offerUnsafe(dialogs, {
|
|
448
|
-
kind: shown.type(),
|
|
449
|
-
message: shown.message().slice(0, 500)
|
|
450
|
-
})) on.failed();
|
|
451
|
-
};
|
|
452
|
-
yield* Queue.take(dialogs).pipe(Effect.flatMap(({ kind, message }) => {
|
|
453
|
-
const accept = kind === "alert" || kind === "beforeunload";
|
|
454
|
-
const record = (answer) => Effect.sync(() => {
|
|
455
|
-
publish(new DialogShown({
|
|
456
|
-
at: now(),
|
|
457
|
-
page,
|
|
458
|
-
kind,
|
|
459
|
-
message,
|
|
460
|
-
answer
|
|
461
|
-
}));
|
|
462
|
-
});
|
|
463
|
-
return answer(accept).pipe(Effect.tap(() => record(accept ? "accepted" : "dismissed")), Effect.tapError(() => record("failed").pipe(Effect.andThen(Effect.sync(on.failed)))));
|
|
464
|
-
}), Effect.forever, Effect.forkScoped);
|
|
465
|
-
yield* Effect.acquireRelease(Effect.sync(() => {
|
|
466
|
-
playwright.on("close", on.close);
|
|
467
|
-
playwright.on("crash", on.crash);
|
|
468
|
-
playwright.on("dialog", dialog);
|
|
469
|
-
}), () => Effect.sync(() => {
|
|
470
|
-
playwright.off("close", on.close);
|
|
471
|
-
playwright.off("crash", on.crash);
|
|
472
|
-
playwright.off("dialog", dialog);
|
|
473
|
-
}));
|
|
474
|
-
});
|
|
475
|
-
//#endregion
|
|
476
|
-
//#region src/internal/page/identity.ts
|
|
477
|
-
/** Connection identity uses the supplied SecureRandom service, or the host's Web Crypto on Node/Bun. */
|
|
478
|
-
const failed = () => undispatched("make", new Failed({ detail: "Could not name connection" }));
|
|
479
|
-
const make$24 = Effect.gen(function* () {
|
|
480
|
-
const supplied = yield* Effect.serviceOption(SecureRandom.SecureRandom);
|
|
481
|
-
return yield* Option.isSome(supplied) ? supplied.value.uuidV4() : Effect.try({
|
|
482
|
-
try: () => globalThis.crypto.randomUUID(),
|
|
483
|
-
catch: failed
|
|
484
|
-
});
|
|
485
|
-
});
|
|
486
|
-
//#endregion
|
|
487
|
-
//#region src/internal/page/openings.ts
|
|
488
|
-
/** A page's input waits for the actual tabs it opened to finish the browser's registration. */
|
|
489
|
-
const make$23 = Effect.fnUntraced(function* (playwright, cdp, registrations, closedBy) {
|
|
490
|
-
const failed = (reason) => Exit.fail(undispatched("newPage", reason));
|
|
491
|
-
let active;
|
|
492
|
-
const gone = Deferred.makeUnsafe();
|
|
493
|
-
const windowOpened = () => {
|
|
494
|
-
if (active !== void 0) active.windows += 1;
|
|
495
|
-
};
|
|
496
|
-
const popup = (opened) => {
|
|
497
|
-
if (active === void 0) return;
|
|
498
|
-
const registered = registrations.get(opened);
|
|
499
|
-
active.registrations.push(registered === void 0 ? failed(new Failed({ detail: "the popup has no registration" })) : Deferred.await(registered).pipe(Effect.asVoid));
|
|
500
|
-
Deferred.doneUnsafe(active.changed, Exit.void);
|
|
501
|
-
active.changed = Deferred.makeUnsafe();
|
|
502
|
-
};
|
|
503
|
-
const clear = Effect.sync(() => {
|
|
504
|
-
active = void 0;
|
|
505
|
-
});
|
|
506
|
-
yield* Effect.acquireRelease(Effect.sync(() => {
|
|
507
|
-
cdp.on("Page.windowOpen", windowOpened);
|
|
508
|
-
playwright.on("popup", popup);
|
|
509
|
-
}), () => Effect.sync(() => {
|
|
510
|
-
active = void 0;
|
|
511
|
-
cdp.off("Page.windowOpen", windowOpened);
|
|
512
|
-
playwright.off("popup", popup);
|
|
513
|
-
Deferred.doneUnsafe(gone, failed(new Closed({ cause: closedBy() })));
|
|
514
|
-
}));
|
|
515
|
-
return {
|
|
516
|
-
mark: () => {
|
|
517
|
-
const mark = {
|
|
518
|
-
windows: 0,
|
|
519
|
-
registrations: [],
|
|
520
|
-
changed: Deferred.makeUnsafe()
|
|
521
|
-
};
|
|
522
|
-
active = mark;
|
|
523
|
-
return mark;
|
|
524
|
-
},
|
|
525
|
-
clear,
|
|
526
|
-
settle: (mark) => Effect.gen(function* () {
|
|
527
|
-
while (mark.registrations.length < mark.windows) yield* Deferred.await(mark.changed);
|
|
528
|
-
yield* Effect.forEach(mark.registrations, (registration) => registration);
|
|
529
|
-
}).pipe(Effect.raceFirst(Deferred.await(gone)), Effect.ensuring(clear))
|
|
530
|
-
};
|
|
531
|
-
});
|
|
532
|
-
const TypeableResultSchema = Schema.Union([Schema.Struct({
|
|
533
|
-
ok: Schema.Literal(true),
|
|
534
|
-
secret: Schema.Boolean,
|
|
535
|
-
subject: Schema.optional(Subject)
|
|
536
|
-
}), Schema.Struct({
|
|
537
|
-
error: Schema.Literals(["stale", "untypeable"]),
|
|
538
|
-
detail: Schema.String
|
|
539
|
-
})]);
|
|
540
|
-
const EditFailure = Schema.Struct({
|
|
541
|
-
error: Schema.String,
|
|
542
|
-
stale: Schema.optional(Schema.Boolean)
|
|
543
|
-
});
|
|
544
|
-
const FocusResultSchema = Schema.Union([Schema.Struct({
|
|
545
|
-
ok: Schema.Literal(true),
|
|
546
|
-
detail: Schema.String,
|
|
547
|
-
secret: Schema.Boolean
|
|
548
|
-
}), EditFailure]);
|
|
549
|
-
const EditResultSchema = Schema.Union([Schema.Struct({
|
|
550
|
-
ok: Schema.Literal(true),
|
|
551
|
-
detail: Schema.String
|
|
552
|
-
}), EditFailure]);
|
|
553
|
-
const ResolvedPointSchema = Schema.Struct({
|
|
554
|
-
...Point.fields,
|
|
555
|
-
...Subject.fields,
|
|
556
|
-
element: Schema.String,
|
|
557
|
-
box: Schema.optional(Box),
|
|
558
|
-
cursor: Schema.String,
|
|
559
|
-
href: Schema.optional(Schema.String)
|
|
560
|
-
});
|
|
561
|
-
const PointResultSchema = Schema.Union([ResolvedPointSchema, Schema.Struct({
|
|
562
|
-
error: Schema.Literals([
|
|
563
|
-
"stale",
|
|
564
|
-
"hidden",
|
|
565
|
-
"offscreen",
|
|
566
|
-
"disabled",
|
|
567
|
-
"covered",
|
|
568
|
-
"outside"
|
|
569
|
-
]),
|
|
570
|
-
detail: Schema.String
|
|
571
|
-
})]);
|
|
572
|
-
const ScrollPlanSchema = Schema.NullOr(Schema.Struct({
|
|
573
|
-
...Point.fields,
|
|
574
|
-
dx: Schema.Finite,
|
|
575
|
-
dy: Schema.Finite
|
|
576
|
-
}));
|
|
577
|
-
const SnapshotResultSchema = Schema.Union([Schema.Struct({ snapshot: Snapshot }), Schema.Struct({ invalid: Schema.String })]);
|
|
578
|
-
const ViewportResultSchema = Schema.Struct({
|
|
579
|
-
width: Schema.Finite,
|
|
580
|
-
height: Schema.Finite
|
|
581
|
-
});
|
|
582
|
-
//#endregion
|
|
583
|
-
//#region src/internal/reading/ready.inpage.ts
|
|
584
|
-
/**
|
|
585
|
-
* In the page: whether it is ready to be shown, checked until it is or until a deadline. Its
|
|
586
|
-
* document is parsed and has painted since, nothing that ends is animating in view, its fonts and
|
|
587
|
-
* the images in view have loaded, nothing in view is marked busy (`aria-busy`), and the viewport
|
|
588
|
-
* shows something: text, a canvas drawn on, a picture or drawing larger than an icon, a video or a
|
|
589
|
-
* frame. So a canvas mounted blank, or a spinner alone, is still loading. A screen that only says
|
|
590
|
-
* "Loading…" in words reads as ready, and a WebGL canvas drawn once, without keeping its drawing,
|
|
591
|
-
* reads as blank. Asked for a quiet spell, where the page's changes are recorded, nothing in view
|
|
592
|
-
* may have changed for that long either. After input, it waits a task and a frame. See `names.inpage.ts` for what a page-side part may use.
|
|
593
|
-
*/
|
|
594
|
-
/** What the page is still waiting for; none when it is ready. */
|
|
595
|
-
const ReadinessSchema = Schema.Array(Schema.Literals([
|
|
596
|
-
"load",
|
|
597
|
-
"paint",
|
|
598
|
-
"animations",
|
|
599
|
-
"images",
|
|
600
|
-
"fonts",
|
|
601
|
-
"busy",
|
|
602
|
-
"content",
|
|
603
|
-
"changing"
|
|
604
|
-
]));
|
|
605
|
-
//#endregion
|
|
606
|
-
//#region src/internal/reading/text.inpage.ts
|
|
607
|
-
/**
|
|
608
|
-
* In the page: the text a page shows, and the one rule for what a field shows. A field's value
|
|
609
|
-
* reads `••••` unless a caller unmasks it, and a secret field's always does, including a field
|
|
610
|
-
* that was secret when the library saw it, such as a password its page now reveals. Text, and the
|
|
611
|
-
* outline, are cut at a line. See `names.inpage.ts` for what a page-side part may use.
|
|
612
|
-
*/
|
|
613
|
-
/** What `read` sends back, or null when its ref no longer names an element. */
|
|
614
|
-
const TextResultSchema = Schema.NullOr(Schema.Struct({
|
|
615
|
-
text: Schema.String,
|
|
616
|
-
truncated: Schema.Boolean,
|
|
617
|
-
url: Schema.String,
|
|
618
|
-
title: Schema.String
|
|
619
|
-
}));
|
|
620
|
-
//#endregion
|
|
621
|
-
//#region src/internal/timeline/changes.inpage.ts
|
|
622
|
-
/**
|
|
623
|
-
* In the page: what changed after `since`, up to `until`, as a read returns it. A read starts the
|
|
624
|
-
* record if it has not, and keeps it going. What waited for the page to render is judged first, as
|
|
625
|
-
* it stands; then each element's history is folded over the window (`history.inpage.ts`), and only
|
|
626
|
-
* now named: its role, its name when something else names it, its tag, and its context, where it
|
|
627
|
-
* is or, for what was removed, where it was. A field's value reads `••••` unless the read unmasks
|
|
628
|
-
* it, and a secret field's always does. A change names the input it followed only where it was
|
|
629
|
-
* the input's own doing, by `Change.cause`'s rule. See `names.inpage.ts` for what a page-side part
|
|
630
|
-
* may use.
|
|
490
|
+
* The expression of the page clock, a function of its event name, which the page's main world runs
|
|
491
|
+
* before its own scripts; packaging freezes it.
|
|
631
492
|
*/
|
|
493
|
+
const clockSource = "(() => {var pageScript = (function() {\n //#region src/internal/page/clock.inpage.ts\n const timers = (real, now, held, report) => {\n const all = /* @__PURE__ */ new Map();\n let next = 1;\n const arm = (id, timer) => {\n timer.real = real.setTimeout(() => {\n if (all.get(id) === timer && !held()) fire(id, timer);\n }, Math.max(0, timer.at - now()));\n };\n const fire = (id, timer) => {\n if (timer.every > 0) {\n timer.at = Math.max(timer.at + timer.every, now());\n if (!held()) arm(id, timer);\n } else all.delete(id);\n try {\n timer.run();\n } catch (error) {\n report(error);\n }\n };\n const schedule = (every) => (handler, delay, ...args) => {\n const id = next++;\n const millis = Math.max(every ? 1 : 0, Number(delay) || 0);\n const run = () => {\n if (typeof handler === \"function\") Reflect.apply(handler, window, args);\n else (0, eval)(handler);\n };\n const timer = {\n run,\n every: every ? millis : 0,\n at: now() + millis\n };\n all.set(id, timer);\n if (!held()) arm(id, timer);\n return id;\n };\n const clear = (id) => {\n const timer = all.get(Number(id));\n if (timer?.real !== void 0) real.clearTimeout(timer.real);\n all.delete(Number(id));\n };\n const runDue = (target, reach) => {\n let due;\n for (const entry of all) if (entry[1].at <= target && (due === void 0 || entry[1].at < due[1].at)) due = entry;\n if (due === void 0) return false;\n reach(due[1].at);\n fire(...due);\n return true;\n };\n return {\n setTimeout: schedule(false),\n setInterval: schedule(true),\n clear,\n runDue,\n pause: () => {\n for (const timer of all.values()) if (timer.real !== void 0) real.clearTimeout(timer.real);\n },\n resume: () => {\n for (const [id, timer] of all) arm(id, timer);\n }\n };\n };\n const animations = () => {\n let ours = /* @__PURE__ */ new WeakSet();\n const catchUp = () => {\n for (const animation of document.getAnimations()) if (animation.playState === \"running\") {\n animation.pause();\n if (!ours.has(animation)) animation.currentTime = 0;\n ours.add(animation);\n }\n };\n const move = (by) => {\n if (by <= 0) return;\n for (const animation of document.getAnimations()) {\n if (!ours.has(animation) || animation.playState !== \"paused\") continue;\n const at = Number(animation.currentTime) + by * animation.playbackRate;\n const end = Number(animation.effect?.getComputedTiming().endTime ?? Infinity);\n if (animation.playbackRate >= 0 ? at >= end : at <= 0) {\n ours.delete(animation);\n animation.finish();\n } else animation.currentTime = at;\n }\n };\n const play = () => {\n for (const animation of document.getAnimations()) if (ours.has(animation) && animation.playState === \"paused\") animation.play();\n ours = /* @__PURE__ */ new WeakSet();\n };\n return {\n catchUp,\n move,\n play\n };\n };\n const clock = (parts) => (name) => {\n if (window !== window.top) return;\n const real = {\n setTimeout: window.setTimeout.bind(window),\n clearTimeout: window.clearTimeout.bind(window),\n requestAnimationFrame: window.requestAnimationFrame.bind(window),\n cancelAnimationFrame: window.cancelAnimationFrame.bind(window),\n now: performance.now.bind(performance),\n dateNow: Date.now,\n Date\n };\n let held = false;\n let frozen = 0;\n let shift = 0;\n let dated;\n let nextFrame = 1;\n const pageNow = () => held ? frozen : real.now() + shift;\n const dateNow = () => dated === void 0 ? real.dateNow() : Math.floor(pageNow() + dated);\n const report = (error) => {\n real.setTimeout(() => {\n throw error;\n });\n };\n const timed = parts.timers(real, pageNow, () => held, report);\n const animated = parts.animations();\n const frames = /* @__PURE__ */ new Map();\n const request = (id, frame) => {\n frame.real = real.requestAnimationFrame(() => {\n frames.delete(id);\n frame.run(pageNow());\n });\n };\n const reach = (at) => {\n animated.catchUp();\n animated.move(at - frozen);\n frozen = Math.max(frozen, at);\n };\n const hold = () => {\n if (held) return;\n dated ??= real.dateNow() - real.now();\n frozen = pageNow();\n held = true;\n timed.pause();\n for (const frame of frames.values()) if (frame.real !== void 0) real.cancelAnimationFrame(frame.real);\n animated.catchUp();\n };\n const advance = (by) => {\n const target = frozen + by;\n for (let guard = 0; guard < 1e4 && timed.runDue(target, reach); guard++);\n reach(target);\n const callbacks = [...frames.values()];\n frames.clear();\n for (const frame of callbacks) try {\n frame.run(frozen);\n } catch (error) {\n report(error);\n }\n animated.catchUp();\n };\n const release = () => {\n if (!held) return;\n held = false;\n shift = Math.max(shift, frozen - real.now());\n timed.resume();\n for (const [id, frame] of frames) request(id, frame);\n animated.play();\n };\n const define = (target, key, value) => Object.defineProperty(target, key, {\n value,\n writable: true,\n configurable: true\n });\n define(window, \"setTimeout\", timed.setTimeout);\n define(window, \"setInterval\", timed.setInterval);\n define(window, \"clearTimeout\", timed.clear);\n define(window, \"clearInterval\", timed.clear);\n define(window, \"requestAnimationFrame\", (run) => {\n const id = nextFrame++;\n const frame = { run };\n frames.set(id, frame);\n if (!held) request(id, frame);\n return id;\n });\n define(window, \"cancelAnimationFrame\", (id) => {\n const frame = frames.get(id);\n if (frame?.real !== void 0) real.cancelAnimationFrame(frame.real);\n frames.delete(id);\n });\n define(performance, \"now\", pageNow);\n function PageDate(...args) {\n if (new.target === void 0) return new real.Date(dateNow()).toString();\n return Reflect.construct(real.Date, args.length === 0 ? [dateNow()] : args, new.target);\n }\n Object.setPrototypeOf(PageDate, real.Date);\n PageDate.prototype = real.Date.prototype;\n define(PageDate, \"now\", dateNow);\n define(window, \"Date\", PageDate);\n document.addEventListener(name, (event) => {\n const detail = \"detail\" in event ? event.detail : void 0;\n const op = typeof detail === \"object\" && detail !== null && \"op\" in detail ? detail.op : \"\";\n const by = typeof detail === \"object\" && detail !== null && \"by\" in detail ? Number(detail.by) : 0;\n if (op === \"holds\") {\n if (held) event.preventDefault();\n return;\n }\n if (op === \"hold\" || op === \"advance\") hold();\n if (op === \"advance\" && Number.isFinite(by) && by >= 0) advance(by);\n if (op === \"release\") release();\n event.preventDefault();\n }, true);\n };\n //#endregion\n return clock({\n timers,\n animations\n });\n})();\n\nreturn pageScript;})()";
|
|
494
|
+
/** The expression that installs the script and evaluates to its API; packaging freezes it. */
|
|
495
|
+
const installSource = "(() => {var pageScript = (function() {\n //#region src/internal/input/edit.inpage.ts\n const edit = (names, guard, placing) => {\n const { activeElement, clean, describe, inCurrentDocument, isDisabled, isHtml, isInput, isSecret, isSelect, isTextArea, lookup, nameOf, roleOf } = names;\n const { textEntry, typingRefusal } = guard;\n /** Whether text may be typed into a ref or focus, and, for a `secret`, only into a secret field. */\n const typeable = (ref, secret) => {\n const element = ref === null ? activeElement() : lookup(ref);\n if (element === void 0) return {\n error: \"stale\",\n detail: `${ref ?? \"the focused element\"} is not on the page any more`\n };\n const refusal = element === null ? secret ? \"nothing has focus to type a secret into\" : void 0 : typingRefusal(element, ref !== null) ?? (secret && !isSecret(element) ? `${describe(element)} is not a secret field` : void 0);\n if (refusal !== void 0) return {\n error: \"untypeable\",\n detail: refusal\n };\n if (element === null || ref !== null || !textEntry(element)) return {\n ok: true,\n secret: element !== null && isSecret(element)\n };\n const role = roleOf(element);\n const tag = element.tagName.toLowerCase();\n return {\n ok: true,\n secret: isSecret(element),\n subject: {\n role,\n name: nameOf(element, role),\n tag,\n context: placing.contextOf(element)\n }\n };\n };\n /**\n * The focused field, when it is a text field named `name`: one a page put in place of a field\n * just pressed and gave focus to, as a typeahead does.\n */\n const replacement = (name) => {\n const active = activeElement();\n return active !== null && textEntry(active) && inCurrentDocument(active) && nameOf(active, roleOf(active)) === name ? active : void 0;\n };\n /**\n * Focus a field to type into. `follow` is the field's name when the action pressed it first: a\n * page may answer the press with another field of that name in its place, focused, and the keys\n * follow focus there, as a person's would.\n */\n const focus = (ref, replace, follow) => {\n const element = lookup(ref) ?? (follow === null ? void 0 : replacement(follow));\n if (element === void 0) return {\n error: `${ref} is not on the page any more`,\n stale: true\n };\n if (isDisabled(element)) return { error: `${ref} is disabled` };\n if (!textEntry(element)) return { error: `${ref} is ${describe(element)}, not a text field` };\n if (isHtml(element)) element.focus();\n if (replace) {\n if (isInput(element) || isTextArea(element)) element.select();\n else element.ownerDocument.getSelection()?.selectAllChildren(element);\n }\n return {\n ok: true,\n detail: describe(element),\n secret: isSecret(element)\n };\n };\n /** Focus any element that takes focus, such as a link or a button, for a key pressed on it. */\n const focusOn = (ref) => {\n const element = lookup(ref);\n if (element === void 0) return {\n error: `${ref} is not on the page any more`,\n stale: true\n };\n if (isDisabled(element)) return { error: `${ref} is disabled` };\n if (isHtml(element)) element.focus();\n return activeElement() === element ? {\n ok: true,\n detail: describe(element)\n } : { error: `${ref} is ${describe(element)}, which does not take focus` };\n };\n const select = (ref, values) => {\n const element = lookup(ref);\n if (element === void 0) return {\n error: `${ref} is not on the page any more`,\n stale: true\n };\n if (!isSelect(element)) return { error: `${ref} is ${describe(element)}, not a <select>; click it and pick an option` };\n const wanted = values.map((value) => value.trim().toLowerCase());\n const options = Array.from(element.options);\n const chosen = options.filter((option) => wanted.includes(option.value.toLowerCase()) || wanted.includes(clean(option.text).toLowerCase()));\n if (chosen.length === 0) return { error: `no option matches; the options are ${options.map((option) => JSON.stringify(clean(option.text, 40))).join(\", \")}` };\n for (const option of options) option.selected = chosen.includes(option);\n element.dispatchEvent(new Event(\"input\", { bubbles: true }));\n element.dispatchEvent(new Event(\"change\", { bubbles: true }));\n return {\n ok: true,\n detail: chosen.map((option) => clean(option.text, 40)).join(\", \")\n };\n };\n return {\n focus,\n focusOn,\n select,\n typeable\n };\n };\n //#endregion\n //#region src/internal/input/evidence.inpage.ts\n const evidence = (names, placing) => {\n const { clean, isDocument, isInput, isSelect, isTextArea, nameOf, parentOf, roleOf, textOf } = names;\n const { groups, headingBefore, textBeside, treeOf } = placing;\n /** A field a submission would send. */\n const isField = (element) => (isInput(element) && ![\n \"button\",\n \"submit\",\n \"reset\",\n \"image\"\n ].includes(element.type) || isSelect(element) || isTextArea(element)) && !element.matches(\":disabled\");\n const isFilled = (field) => isInput(field) && (field.type === \"checkbox\" || field.type === \"radio\") ? field.checked : isInput(field) && field.type === \"file\" ? (field.files?.length ?? 0) > 0 : field.value !== \"\";\n const dialogOf = (element) => {\n for (let node = element; node !== null; node = parentOf(node)) if (node.tagName === \"DIALOG\" || /^(?:alert)?dialog$/.test(node.getAttribute(\"role\") ?? \"\")) return node;\n };\n /** What the page says about an input's first target, for a judge. Never a field's value. */\n const evidenceOf = (element, form, method, action) => {\n const name = nameOf(element, roleOf(element));\n const ids = element.getAttribute(\"aria-describedby\");\n const description = clean(ids === null ? element.getAttribute(\"aria-description\") ?? element.getAttribute(\"title\") : ids.split(/\\s+/).map((id) => element.ownerDocument.getElementById(id)?.textContent ?? \"\").join(\" \"), 120);\n const dialog = dialogOf(element);\n const title = dialog?.querySelector(\"h1,h2,h3,h4,h5,h6,[role=heading]\");\n const dialogName = dialog === void 0 ? \"\" : clean(nameOf(dialog, \"dialog\"), 120) || (title === null || title === void 0 ? \"\" : clean(textOf(title), 120));\n const root = element.getRootNode();\n const top = isDocument(root) ? root.body ?? root : root;\n const inTree = element.closest(\"dialog,[role=dialog],[role=alertdialog]\");\n let nearby = \"\";\n for (const scope of /* @__PURE__ */ new Set([\n element.closest(groups),\n inTree,\n top\n ])) if (scope !== null && nearby === \"\") nearby = textBeside(element, scope, true) || textBeside(element, scope, false);\n const heading = headingBefore(element, treeOf(element));\n const fields = form === null ? [] : Array.from(form.elements).filter(isField).slice(0, 16).map((field) => {\n const autocomplete = clean(field.getAttribute(\"autocomplete\"), 40);\n return {\n type: isInput(field) ? field.type : field.tagName.toLowerCase(),\n name: clean(isInput(field) && field.type === \"hidden\" ? field.getAttribute(\"name\") : nameOf(field, roleOf(field)), 40),\n ...autocomplete === \"\" ? {} : { autocomplete },\n filled: isFilled(field)\n };\n });\n return {\n title: clean(document.title, 120),\n ...description === \"\" || description === name ? {} : { description },\n ...dialogName === \"\" ? {} : { dialog: dialogName },\n ...heading === void 0 ? {} : { heading },\n ...nearby === \"\" ? {} : { nearby },\n ...form === null ? {} : { form: {\n method: method ?? form.method,\n action: action ?? form.action,\n fields\n } }\n };\n };\n return {\n evidenceOf,\n isField,\n isFilled\n };\n };\n //#endregion\n //#region src/internal/input/guard.inpage.ts\n const guard = (names, targets, evidence) => {\n const { activeElement, textEntry, clean, describe, inCurrentDocument, interactiveRoles, isButton, isDisabled, isHtml, isInput, isLabel, isRoot, isSecret, isSelect, isTextArea, lookup, parentOf, refFor, roleOf } = names;\n const { controlOf, details, hitAt, hrefAttribute, linkOf, receives, within } = targets;\n const { evidenceOf, isField, isFilled } = evidence;\n const nativeActivation = (element) => hrefAttribute(element) !== null || element.tagName === \"BUTTON\" || element.tagName === \"SUMMARY\" || isInput(element) && element.type !== \"hidden\";\n /**\n * The element whose activation behaviour a click or key on `element` runs, as the browser\n * resolves it along the composed path: a link, button, input, summary or a label's control.\n */\n const activationTarget = (element) => {\n for (let node = element; node !== null; node = parentOf(node)) {\n if (nativeActivation(node)) return node;\n if (isLabel(node) && node.control !== null) return node.control;\n }\n };\n /**\n * A control between a press's hit and the approved target that is not the target's own\n * activation, such as a link or button a hover handler nested into it. The approval inspected\n * the target, so that control would act unapproved.\n */\n const nestedControl = (element, hit) => {\n if (!within(element, hit)) return void 0;\n const own = activationTarget(element);\n for (let node = hit; node !== null && node !== element; node = parentOf(node) ?? node.ownerDocument.defaultView?.frameElement ?? null) if (node !== own && (nativeActivation(node) || isSelect(node) || isTextArea(node) || isLabel(node) && node.control !== null && node.control !== own || activatingRoles.has(roleOf(node) ?? \"\"))) return node;\n };\n const activatingRoles = /* @__PURE__ */ new Set([\n \"button\",\n \"link\",\n \"checkbox\",\n \"radio\",\n \"switch\",\n \"tab\",\n \"menuitem\",\n \"menuitemcheckbox\",\n \"menuitemradio\",\n \"option\",\n \"treeitem\"\n ]);\n const typingRefusal = (element, explicit) => textEntry(element) ? void 0 : explicit ? `${describe(element)} is not a text field` : activationTarget(element) !== void 0 || isSelect(element) || activatingRoles.has(roleOf(element) ?? \"\") ? `focus is on ${describe(element)}, which typed text could activate or change; type into a text field by ref, or use press for keys` : void 0;\n const isSubmitter = (element) => isButton(element) && element.type === \"submit\" || isInput(element) && (element.type === \"submit\" || element.type === \"image\");\n const defaultSubmitter = (form) => {\n const root = form.getRootNode();\n return isRoot(root) ? Array.from(root.querySelectorAll(\"button,input\")).find((candidate) => isSubmitter(candidate) && candidate.form === form) : void 0;\n };\n const purpose = (control, form) => [\n control.getAttribute(\"id\"),\n control.getAttribute(\"name\"),\n control.getAttribute(\"inputmode\"),\n control.getAttribute(\"autocomplete\"),\n control.getAttribute(\"aria-label\"),\n form?.getAttribute(\"id\"),\n form?.getAttribute(\"name\"),\n form?.getAttribute(\"aria-label\")\n ];\n const boundUrl = (url) => {\n const hash = url.indexOf(\"#\");\n return hash === -1 || /^#[/!]/.test(url.slice(hash)) ? url : url.slice(0, hash);\n };\n const inspectInput = (element, plan) => {\n const metadata = details(element, element, 0, 0);\n const control = activationTarget(element) ?? element;\n const form = isInput(control) || isButton(control) || isTextArea(control) || isSelect(control) ? control.form : null;\n const key = plan.keys === null ? void 0 : /(?:^|\\+)(\\+|[^+]+)$/.exec(plan.keys)?.[1];\n const enter = key === \"Enter\";\n const activation = plan.action === \"click\" || plan.action === \"press\" && (enter || key === \"Space\");\n const fieldEnter = isInput(control) && ![\n \"button\",\n \"reset\",\n \"submit\",\n \"image\",\n \"file\",\n \"color\",\n \"hidden\"\n ].includes(control.type) && (plan.action === \"press\" && enter || plan.action === \"type\" && plan.submit);\n const submits = form !== null && (activation && isSubmitter(control) || fieldEnter);\n const submitter = isSubmitter(control) ? control : form === null ? void 0 : defaultSubmitter(form);\n const formValue = (attribute, property) => form === null ? void 0 : submitter?.hasAttribute(`form${attribute}`) === true ? submitter[property] : form[attribute];\n const formDestination = formValue(\"action\", \"formAction\");\n const formMethod = formValue(\"method\", \"formMethod\");\n const formTarget = formValue(\"target\", \"formTarget\");\n const link = linkOf(element);\n const href = link === void 0 ? null : hrefAttribute(link);\n const sends = submits && formMethod !== \"dialog\";\n const destination = sends ? formDestination : activation ? metadata.href : void 0;\n const acts = plan.action !== \"hover\" && plan.action !== \"scroll\";\n const builtIn = sends || href !== null && !/^\\s*(?:#\\s*|javascript:[^]*)$/i.test(href) || isInput(control) && ![\n \"button\",\n \"submit\",\n \"image\",\n \"reset\"\n ].includes(control.type) || (isInput(control) || isButton(control)) && control.type === \"reset\" && form !== null || control.tagName === \"SUMMARY\" || control.closest(\"select\") !== null || textEntry(control);\n const facts = [];\n if (sends) facts.push(\"form-submit\");\n if (activation && link?.hasAttribute(\"download\") === true) facts.push(\"download\");\n if (activation && isInput(control) && control.type === \"file\") facts.push(\"upload\");\n if (plan.action === \"type\" && isSecret(control) || sends && form !== null && Array.from(form.elements).some((field) => isField(field) && isSecret(field) && isFilled(field))) facts.push(\"secret\");\n if (activation && !builtIn) facts.push(\"scripted\");\n if (acts && (metadata.role === \"canvas\" || metadata.role === \"iframe\" || metadata.name === \"\")) facts.push(\"opaque\");\n const role = metadata.role;\n const boundName = role !== null && (interactiveRoles.has(role) || role === \"canvas\" || role === \"iframe\") && !(isHtml(element) && element.isContentEditable) ? metadata.name : null;\n const fingerprint = JSON.stringify([\n purpose(control, form),\n element.tagName,\n element.id,\n role,\n boundName,\n metadata.href,\n control === element ? null : refFor(control),\n isInput(control) || isButton(control) ? control.type : control.tagName,\n isDisabled(control),\n control.getAttribute(\"readonly\"),\n control.getAttribute(\"aria-readonly\"),\n isHtml(control) && control.isContentEditable,\n control.getAttribute(\"name\"),\n control.getAttribute(\"accept\"),\n control.hasAttribute(\"multiple\"),\n link?.getAttribute(\"download\"),\n form === null ? null : refFor(form),\n form === null ? null : boundUrl(form.action),\n form?.method,\n form?.target,\n submitter === void 0 ? null : refFor(submitter),\n formDestination === void 0 ? void 0 : boundUrl(formDestination),\n formMethod,\n formTarget,\n submitter?.formNoValidate,\n form?.noValidate\n ]);\n return {\n inspected: {\n ref: refFor(element),\n element: metadata.element,\n role: metadata.role,\n name: metadata.name,\n cursor: metadata.cursor,\n ...metadata.href === void 0 ? {} : { href: metadata.href },\n secret: isSecret(control),\n fingerprint\n },\n facts,\n destination,\n explain: () => evidenceOf(element, form, formMethod, formDestination)\n };\n };\n const inspect = (plan) => {\n const targets = [];\n const facts = /* @__PURE__ */ new Set();\n let destination = plan.destination ?? void 0;\n let explain = () => ({ title: clean(document.title, 120) });\n for (const [index, target] of plan.targets.entries()) {\n let element;\n if (target === null) element = activeElement();\n else if (typeof target === \"string\") {\n element = lookup(target);\n if (element === void 0) return {\n error: \"stale\",\n detail: target + \" is not on the page any more\",\n index\n };\n } else {\n if (!Number.isFinite(target.x) || !Number.isFinite(target.y) || target.x < 0 || target.y < 0 || target.x >= window.innerWidth || target.y >= window.innerHeight) return {\n error: \"outside\",\n detail: \"the point is outside the viewport\"\n };\n const hit = hitAt(document, target.x, target.y);\n element = hit === null ? null : controlOf(hit);\n if (element === null) return {\n error: \"offscreen\",\n detail: \"nothing is painted at the point\"\n };\n }\n if (element === null) {\n targets.push(null);\n continue;\n }\n if (!inCurrentDocument(element)) return {\n error: \"stale\",\n detail: \"the input target belongs to a replaced document\",\n index\n };\n const refusal = plan.action === \"type\" ? typingRefusal(element, target !== null) : void 0;\n if (refusal !== void 0) return {\n error: \"untypeable\",\n detail: refusal\n };\n const inspected = inspectInput(element, plan);\n if (index === 0) explain = inspected.explain;\n targets.push(inspected.inspected);\n for (const fact of inspected.facts) facts.add(fact);\n destination ??= inspected.destination;\n if (inspected.destination !== void 0) try {\n if (new URL(inspected.destination, location.href).origin !== location.origin) facts.add(\"cross-origin\");\n } catch {\n return {\n error: \"outside\",\n detail: \"the input destination is not a valid URL\"\n };\n }\n }\n if (destination !== void 0) try {\n destination = new URL(destination, location.href).href;\n if (new URL(destination).origin !== location.origin) facts.add(\"cross-origin\");\n } catch {\n return {\n error: \"outside\",\n detail: \"the input destination is not a valid URL\"\n };\n }\n return {\n url: boundUrl(location.href),\n targets,\n facts: [...facts],\n ...destination === void 0 ? {} : { destination },\n explain\n };\n };\n const prepareInput = (plan) => {\n const inspected = inspect(plan);\n if (\"error\" in inspected) return inspected;\n const { explain, ...prepared } = inspected;\n return {\n ...prepared,\n evidence: explain()\n };\n };\n const bindings = (targets) => targets.map((target) => target === null ? null : [target.ref, target.fingerprint]);\n const validate = (plan, prepared, options) => {\n const current = inspect(plan);\n if (\"error\" in current) return current.error === \"stale\" ? current : {\n error: \"changed\",\n detail: current.detail\n };\n if (current.url !== prepared.url || (current.destination === void 0 || prepared.destination === void 0 ? current.destination !== prepared.destination : boundUrl(current.destination) !== boundUrl(prepared.destination)) || JSON.stringify(current.facts) !== JSON.stringify(prepared.facts) || JSON.stringify(bindings(current.targets)) !== JSON.stringify(bindings(prepared.targets))) return {\n error: \"changed\",\n detail: \"the page or input target changed while the policy was deciding\"\n };\n if (options.focused === true) {\n const active = activeElement();\n const expected = prepared.targets[0];\n if (active === null || expected === null || expected === void 0 || refFor(active) !== expected.ref) return {\n error: \"changed\",\n detail: \"focus moved away from the approved element\"\n };\n }\n for (const press of options.presses ?? []) {\n const expected = prepared.targets[press.index];\n const element = expected === null || expected === void 0 ? void 0 : lookup(expected.ref);\n const hit = hitAt(document, press.x, press.y);\n if (element === void 0 || hit === null || !receives(element, hit)) return {\n error: \"changed\",\n detail: `the approved target is no longer under the pointer at (${press.x}, ${press.y})`\n };\n const nested = nestedControl(element, hit);\n if (nested !== void 0) return {\n error: \"changed\",\n detail: `${describe(nested)} inside the approved target would receive the press at (${press.x}, ${press.y})`\n };\n }\n return { ok: true };\n };\n const validateInput = (plan, prepared, options = {}) => {\n if ((options.presses ?? []).length === 0) return validate(plan, prepared, options);\n const { promise, resolve } = Promise.withResolvers();\n if (document.visibilityState === \"hidden\") resolve();\n else requestAnimationFrame(() => requestAnimationFrame(() => resolve()));\n return promise.then(() => validate(plan, prepared, options));\n };\n return {\n prepareInput,\n textEntry,\n typingRefusal,\n validateInput\n };\n };\n //#endregion\n //#region src/internal/input/targets.inpage.ts\n const targets = (names, walked, placing) => {\n const { describe, isDisabled, lookup, nameOf, parentOf, roleOf } = names;\n const { boxOf, controlOf, hitAt } = walked;\n const { contextOf } = placing;\n /** Whether `node` is `ancestor` or inside it, across shadow roots and same-origin frames. */\n const within = (ancestor, node) => {\n for (let current = node; current !== null;) {\n if (current === ancestor) return true;\n current = parentOf(current) ?? current.ownerDocument.defaultView?.frameElement ?? null;\n }\n return false;\n };\n const receives = (element, hit) => within(element, hit) || within(hit, element);\n const hrefAttribute = (element) => element.localName === \"a\" || element.localName === \"area\" ? element.getAttribute(\"href\") ?? element.getAttributeNS(\"http://www.w3.org/1999/xlink\", \"href\") : null;\n const linkOf = (element) => {\n for (let node = element; node !== null; node = parentOf(node)) if (hrefAttribute(node) !== null) return node;\n };\n const details = (element, hit, x, y) => {\n const link = linkOf(element);\n let href;\n if (link !== void 0) try {\n href = new URL(hrefAttribute(link) ?? \"\", link.ownerDocument.baseURI).href;\n } catch {\n href = void 0;\n }\n const role = roleOf(element);\n const view = hit.ownerDocument.defaultView ?? window;\n return {\n x,\n y,\n element: describe(element),\n tag: element.tagName.toLowerCase(),\n role,\n name: nameOf(element, role),\n cursor: view.getComputedStyle(hit).cursor,\n ...href === void 0 ? {} : { href }\n };\n };\n const point = (target, scroll = true) => {\n if (typeof target !== \"string\") {\n const { x, y } = target;\n if (!Number.isFinite(x) || !Number.isFinite(y) || x < 0 || y < 0 || x >= window.innerWidth || y >= window.innerHeight) return {\n error: \"outside\",\n detail: `(${x}, ${y}) is outside the viewport`\n };\n const hit = hitAt(document, x, y);\n if (hit === null) return {\n error: \"offscreen\",\n detail: `nothing is painted at (${x}, ${y})`\n };\n const control = controlOf(hit);\n return {\n ...details(control, hit, x, y),\n context: contextOf(control),\n box: boxOf(control)\n };\n }\n const ref = target;\n const element = lookup(ref);\n if (element === void 0) return {\n error: \"stale\",\n detail: `${ref} is not on the page any more`\n };\n if (isDisabled(element)) return {\n error: \"disabled\",\n detail: `${ref} is disabled`\n };\n const rect = element.getBoundingClientRect();\n if (rect.width === 0 && rect.height === 0) return {\n error: \"hidden\",\n detail: `${ref} has no size on the page`\n };\n let box = {\n left: rect.left,\n top: rect.top,\n right: rect.right,\n bottom: rect.bottom\n };\n let visible = { ...box };\n let outside = false;\n for (let inner = element;;) {\n const view = inner.ownerDocument.defaultView ?? window;\n outside ||= box.left < 0 || box.top < 0 || box.right > view.innerWidth || box.bottom > view.innerHeight;\n visible = {\n left: Math.max(visible.left, 0),\n top: Math.max(visible.top, 0),\n right: Math.min(visible.right, view.innerWidth),\n bottom: Math.min(visible.bottom, view.innerHeight)\n };\n for (let ancestor = parentOf(inner); ancestor !== null; ancestor = parentOf(ancestor)) {\n const style = view.getComputedStyle(ancestor);\n const clip = ancestor.getBoundingClientRect();\n if (/(auto|scroll|hidden|clip)/.test(style.overflowX)) {\n visible.left = Math.max(visible.left, clip.left + ancestor.clientLeft);\n visible.right = Math.min(visible.right, clip.left + ancestor.clientLeft + ancestor.clientWidth);\n }\n if (/(auto|scroll|hidden|clip)/.test(style.overflowY)) {\n visible.top = Math.max(visible.top, clip.top + ancestor.clientTop);\n visible.bottom = Math.min(visible.bottom, clip.top + ancestor.clientTop + ancestor.clientHeight);\n }\n }\n const frame = view.frameElement;\n if (frame === null) break;\n const frameBox = frame.getBoundingClientRect();\n const dx = frameBox.left + frame.clientLeft;\n const dy = frameBox.top + frame.clientTop;\n box = {\n left: box.left + dx,\n top: box.top + dy,\n right: box.right + dx,\n bottom: box.bottom + dy\n };\n visible = {\n left: Math.max(visible.left + dx, dx),\n top: Math.max(visible.top + dy, dy),\n right: Math.min(visible.right + dx, dx + frame.clientWidth),\n bottom: Math.min(visible.bottom + dy, dy + frame.clientHeight)\n };\n inner = frame;\n }\n if (outside || visible.right <= visible.left || visible.bottom <= visible.top) {\n if (scroll) {\n element.scrollIntoView({\n block: \"center\",\n inline: \"center\",\n behavior: \"instant\"\n });\n return point(target, false);\n }\n return {\n error: \"offscreen\",\n detail: outside ? ref + \" is outside the viewport\" : `${ref} could not be scrolled into view`\n };\n }\n const x = (visible.left + visible.right) / 2;\n const y = (visible.top + visible.bottom) / 2;\n const hit = hitAt(document, x, y);\n if (hit !== null && !receives(element, hit)) return {\n error: \"covered\",\n detail: `${ref} is covered by ${describe(hit)}`\n };\n return {\n ...details(element, hit ?? element, Math.round(x), Math.round(y)),\n context: contextOf(element)\n };\n };\n const scrollPlan = (ref) => {\n const element = lookup(ref);\n if (element === void 0 || element.ownerDocument !== document) return null;\n const target = element.getBoundingClientRect();\n const centerX = (target.left + target.right) / 2;\n const centerY = (target.top + target.bottom) / 2;\n for (let ancestor = parentOf(element); ancestor !== null; ancestor = parentOf(ancestor)) {\n const style = window.getComputedStyle(ancestor);\n const horizontal = /^(auto|scroll)$/.test(style.overflowX) && ancestor.scrollWidth > ancestor.clientWidth;\n const vertical = /^(auto|scroll)$/.test(style.overflowY) && ancestor.scrollHeight > ancestor.clientHeight;\n if (!horizontal && !vertical) continue;\n const box = ancestor.getBoundingClientRect();\n const left = Math.max(0, box.left + ancestor.clientLeft);\n const top = Math.max(0, box.top + ancestor.clientTop);\n const right = Math.min(window.innerWidth, box.left + ancestor.clientLeft + ancestor.clientWidth);\n const bottom = Math.min(window.innerHeight, box.top + ancestor.clientTop + ancestor.clientHeight);\n if (right <= left || bottom <= top) continue;\n const x = (left + right) / 2;\n const y = (top + bottom) / 2;\n const dx = horizontal && (target.left < left || target.right > right) ? centerX - x : 0;\n const dy = vertical && (target.top < top || target.bottom > bottom) ? centerY - y : 0;\n if (dx === 0 && dy === 0) continue;\n const hit = hitAt(document, x, y);\n if (hit !== null && (hit === ancestor || ancestor.contains(hit))) return {\n x,\n y,\n dx,\n dy\n };\n }\n const dx = target.left < 0 || target.right > window.innerWidth ? centerX - window.innerWidth / 2 : 0;\n const dy = target.top < 0 || target.bottom > window.innerHeight ? centerY - window.innerHeight / 2 : 0;\n return dx === 0 && dy === 0 ? null : {\n x: window.innerWidth / 2,\n y: window.innerHeight / 2,\n dx,\n dy\n };\n };\n return {\n controlOf,\n details,\n hitAt,\n hrefAttribute,\n linkOf,\n point,\n receives,\n scrollPlan,\n within\n };\n };\n //#endregion\n //#region src/internal/matching.ts\n const match = () => {\n /**\n * How names, text and context compare: one Unicode form, without invisible format characters,\n * spaces collapsed, and case folded upper first, so that \"ß\" and \"SS\" read the same.\n */\n const normalize = (value) => value.normalize(\"NFKC\").replace(/\\p{Cf}/gu, \"\").replace(/\\s+/g, \" \").trim().toUpperCase().toLowerCase();\n /** A string that reads the same, or, unless `whole`, appears within; or a pattern found within. */\n const rule = (wanted, whole) => {\n if (typeof wanted !== \"string\") {\n const found = new RegExp(wanted.source, wanted.flags.replace(/[gy]/g, \"\"));\n return (value) => found.test(value.replace(/\\s+/g, \" \").trim());\n }\n const target = normalize(wanted);\n return whole ? (value) => normalize(value) === target : (value) => normalize(value).includes(target);\n };\n /** Whether a value's words appear, whole and in order, among a text's: \"BTC\" not in \"WBTC\". */\n const holds = (text, value) => ` ${normalize(text)} `.includes(` ${normalize(value)} `);\n /** Whether a candidate meets every rule a query gives; a rule left out always holds. */\n const compile = (request) => {\n const role = request.role === null ? null : normalize(request.role);\n const name = request.name === null ? null : rule(request.name, true);\n const text = request.text === null ? null : rule(request.text, false);\n const { near } = request;\n return (candidate) => {\n if (role !== null && normalize(candidate.role ?? \"\") !== role) return false;\n if (text !== null && !text(candidate.text())) return false;\n if (name !== null && !name(candidate.name())) return false;\n if (near === null) return true;\n const { row, column, label, heading } = candidate.context();\n return [\n row,\n column,\n label,\n heading\n ].some((value) => value !== void 0 && holds(value, near));\n };\n };\n /** A comparison token for ordered observations, without retaining their text. */\n const mark = (observations) => {\n let hash = 2166136261;\n for (const shown of observations) for (let index = 0; index < shown.length; index++) hash = Math.imul(hash ^ shown.charCodeAt(index), 16777619);\n return `${observations.length}:${(hash >>> 0).toString(16)}`;\n };\n return {\n compile,\n holds,\n normalize,\n mark\n };\n };\n //#endregion\n //#region src/internal/reading/context.inpage.ts\n const context = (names, walked) => {\n const { clean, isButton, isDocument, isHtml, isInput, isRoot } = names;\n const { isSelect, isTextArea, roleOf, textOf } = names;\n const { visible } = walked;\n const known = () => ({\n headers: /* @__PURE__ */ new Map(),\n headings: /* @__PURE__ */ new Map()\n });\n const unspoken = \"button,select,textarea,option,script,style,noscript,template,[role=button],[role=menuitem],[role=option],[role=tab],[role=switch],[role=checkbox],[role=radio],[aria-hidden=true]\";\n const groups = \"tr,li,article,fieldset,form,section,dialog,[role=row],[role=listitem],[role=group],[role=region],[role=dialog],[role=alertdialog]\";\n /** The visible text just before (or after) a target within `scope`, nearest kept, ≤120 characters. */\n const textBeside = (target, scope, backwards) => {\n const walker = target.ownerDocument.createTreeWalker(scope, NodeFilter.SHOW_TEXT);\n const labels = isInput(target) || isTextArea(target) || isSelect(target) || isButton(target) ? Array.from(target.labels ?? []) : [];\n let text = \"\";\n walker.currentNode = target;\n for (let steps = 0; steps < 400 && text.replace(/\\s+/g, \"\").length < 120; steps++) {\n const node = backwards ? walker.previousNode() : walker.nextNode();\n if (node === null) break;\n const parent = node.parentElement;\n if (parent === null || target.contains(parent) || parent.closest(unspoken) !== null || isHtml(parent) && parent.isContentEditable || labels.some((label) => label.contains(parent)) || !visible(parent)) continue;\n text = backwards ? `${node.textContent ?? \"\"} ${text}` : `${text} ${node.textContent ?? \"\"}`;\n }\n const words = text.replace(/\\s+/g, \" \").trim();\n return words.length <= 120 ? words : backwards ? `…${words.slice(-119).trimStart()}` : `${words.slice(0, 119).trimEnd()}…`;\n };\n /** The nearest visible heading before `target` in tree order, within `scope`. */\n const headingBefore = (target, scope, read = known()) => {\n let headings = read.headings.get(scope);\n if (headings === void 0) {\n headings = Array.from(scope.querySelectorAll(\"h1,h2,h3,h4,h5,h6,[role=heading]\")).filter((element) => roleOf(element) === \"heading\");\n read.headings.set(scope, headings);\n }\n for (const heading of headings.toReversed()) {\n if ((heading.compareDocumentPosition(target) & Node.DOCUMENT_POSITION_FOLLOWING) === 0) continue;\n const text = visible(heading) ? clean(textOf(heading), 120) : \"\";\n if (text !== \"\") return text;\n }\n };\n /** Whether an element is pinned to the viewport, where the markup around it says nothing. */\n const pinned = (element) => {\n if (!isHtml(element)) return false;\n let top = element;\n while (top.offsetParent !== null && isHtml(top.offsetParent)) top = top.offsetParent;\n return top !== element.ownerDocument.body && top !== element.ownerDocument.documentElement && getComputedStyle(top).position === \"fixed\";\n };\n const span = (cell) => Math.max(1, Number(cell.getAttribute(\"colspan\")) || 1);\n const tables = \"table,[role=table],[role=grid],[role=treegrid]\";\n /** A cell's row and column names, or nothing when it is not in a table with either. */\n const tableContext = (cell, read) => {\n const row = cell.closest(\"tr,[role=row]\");\n const table = row?.closest(tables);\n if (row === null || row === void 0 || table === null || table === void 0) return {};\n let header = read.headers.get(table);\n if (header === void 0) {\n const first = table.querySelector(\"thead tr, tr:has(> th), [role=row]:has(> [role=columnheader])\");\n header = first?.closest(tables) === table ? first : null;\n read.headers.set(table, header);\n }\n if (row === header) return {};\n const cells = Array.from(row.children);\n const index = cells.indexOf(cell);\n const lettered = (other) => /\\p{L}/u.test(textOf(other));\n const named = cells.find((other) => other.matches(\"th,[role=rowheader]\") && lettered(other)) ?? cells.find((other) => other !== cell && lettered(other));\n let left = cells.slice(0, index).reduce((sum, other) => sum + span(other), 0);\n const over = index === -1 || header === null ? void 0 : Array.from(header.children).find((candidate) => (left -= span(candidate)) < 0);\n return {\n row: named === void 0 || named === cell ? void 0 : clean(textOf(named), 60) || void 0,\n column: over === void 0 ? void 0 : clean(textOf(over), 60) || void 0\n };\n };\n /** Where text around an element is read: its dialog, else its own tree, never across a shadow root. */\n const treeOf = (element) => {\n const root = element.getRootNode();\n return element.closest(\"dialog,[role=dialog],[role=alertdialog]\") ?? (isDocument(root) ? root.body ?? root : isRoot(root) ? root : element.ownerDocument);\n };\n /** The words around an element that say which one it is. */\n const contextOf = (element, read = known()) => {\n const cell = element.closest(\"td,th,[role=cell],[role=gridcell],[role=rowheader],[role=columnheader]\");\n const table = cell === null ? {} : tableContext(cell, read);\n const parent = element.parentElement;\n const scope = element.closest(groups) ?? (parent === null || parent === element.ownerDocument.body || parent.tagName === \"HTML\" ? void 0 : parent);\n const beside = table.row !== void 0 || table.column !== void 0 || scope === void 0 ? \"\" : textBeside(element, scope, true);\n const heading = pinned(element) ? void 0 : headingBefore(element, treeOf(element), read);\n return {\n ...table,\n label: beside.length > 40 ? `…${beside.slice(-39).trimStart()}` : beside || void 0,\n heading: heading === void 0 ? void 0 : clean(heading, 60)\n };\n };\n return {\n contextOf,\n groups,\n headingBefore,\n known,\n textBeside,\n treeOf\n };\n };\n //#endregion\n //#region src/internal/reading/controls.inpage.ts\n const controls = (names, subjects, texts) => {\n const { clean, isInput, isSelect, isTextArea, refFor, textEntry } = names;\n const { stateOf } = subjects;\n const { shown } = texts;\n const states = (element, role) => {\n const { level, ...flags } = stateOf(element, role);\n const held = Object.entries(flags).flatMap(([name, value]) => value === true ? [name] : []);\n return [...level === void 0 ? [] : [`level=${level}`], ...held].map((name) => ` [${name}]`).join(\"\");\n };\n const valueOf = (element) => {\n if (isSelect(element)) {\n const selected = Array.from(element.selectedOptions, (option) => clean(option.text, 40));\n const options = Array.from(element.options).slice(0, 12).map((option) => clean(option.text, 40));\n const more = element.options.length > 12 ? ` +${element.options.length - 12} more` : \"\";\n return ` value=${JSON.stringify(selected.join(\", \"))} options=${JSON.stringify(options.join(\" | \") + more)}`;\n }\n const value = isInput(element) || isTextArea(element) ? shown(element, true) : void 0;\n return value === void 0 || value === \"\" ? \"\" : ` value=${JSON.stringify(clean(value, 80))}`;\n };\n /** A control as a value, as its outline line shows it. */\n const controlOf = (element, role, kind, name) => {\n const { disabled, checked } = stateOf(element, role);\n const select = isSelect(element) ? element : void 0;\n const value = select !== void 0 ? Array.from(select.selectedOptions, (option) => clean(option.text, 80)).join(\", \") : isInput(element) || isTextArea(element) ? clean(shown(element, true), 200) : \"\";\n const editable = textEntry(element);\n return {\n ref: refFor(element),\n kind,\n name,\n value,\n ...select === void 0 ? {} : {\n options: Array.from(select.options).slice(0, 64).map((option) => clean(option.text, 80)),\n optionCount: select.options.length\n },\n ...disabled ? { disabled } : {},\n ...checked === void 0 ? {} : { checked },\n ...editable ? { editable } : {}\n };\n };\n /**\n * The elements a selector matches, each read whole, so one inside another that matched is left\n * to it; or why the selector is not CSS.\n */\n const rootsOf = (selector) => {\n let matched;\n try {\n matched = Array.from(document.querySelectorAll(selector));\n } catch {\n return { invalid: `${JSON.stringify(selector)} is not a CSS selector` };\n }\n return matched.filter((root) => !matched.some((other) => other !== root && other.contains(root)));\n };\n return {\n controlOf,\n rootsOf,\n states,\n valueOf\n };\n };\n //#endregion\n //#region src/internal/reading/expect.inpage.ts\n const expectations = (names, subjected, matching) => {\n const { isInput, isSelect, isTextArea, roleOf, textOf } = names;\n const { elementsOf, stateOf } = subjected;\n const markOf = (elements) => matching.mark(elements.map((element) => {\n const { focused: _focused, ...state } = stateOf(element, roleOf(element));\n const value = isInput(element) || isSelect(element) || isTextArea(element) ? element.value : \"\";\n return `${textOf(element)}\\u0000${value}\\u0000${JSON.stringify(state)}\\u0001`;\n }));\n /**\n * What `find` matches, looked at every 100 ms until `want` holds of it or `millis` have passed,\n * with its mark then. It gives no refs.\n */\n const until = async (request, want, millis) => {\n const deadline = performance.now() + millis;\n for (;;) {\n const elements = elementsOf(request);\n if (\"invalid\" in elements) return elements;\n const mark = markOf(elements);\n const met = want === \"some\" ? elements.length > 0 : want === \"none\" ? elements.length === 0 : mark !== want.other;\n const left = deadline - performance.now();\n if (met || left <= 0) return {\n met,\n mark\n };\n const { promise, resolve } = Promise.withResolvers();\n setTimeout(resolve, Math.min(100, left));\n await promise;\n }\n };\n return { until };\n };\n //#endregion\n //#region src/internal/reading/layout.inpage.ts\n const layout = (names, walked, subjected, matching, placing) => {\n const { isDisabled, isOwn, nameOf, refFor, roleOf, textOf } = names;\n const { boxOf, inView, visible } = walked;\n const most = 200;\n const area = (element) => {\n const { width, height } = element.getBoundingClientRect();\n return width * height;\n };\n const chosen = (elements, choose) => choose === \"first\" ? elements[0] : choose === \"last\" ? elements.at(-1) : elements.reduce((best, element) => best === void 0 || (choose === \"smallest\" ? area(element) < area(best) : area(element) > area(best)) ? element : best, void 0);\n const fixed = (element) => {\n for (let at = element; at !== null; at = at.parentElement) if (getComputedStyle(at).position === \"fixed\") return true;\n return false;\n };\n const words = (element, wanted, dx, dy) => {\n const parts = [];\n let text = \"\";\n const walker = element.ownerDocument.createTreeWalker(element, NodeFilter.SHOW_TEXT);\n for (let node = walker.nextNode(); node !== null; node = walker.nextNode()) {\n parts.push({\n node,\n start: text.length\n });\n text += node.nodeValue ?? \"\";\n }\n const pattern = typeof wanted === \"string\" ? new RegExp(wanted.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\"), \"giu\") : new RegExp(wanted.source, wanted.flags.replace(/[gy]/g, \"\") + \"g\");\n const at = (index, end) => {\n const part = parts.findLast(({ start }) => end ? start < index : start <= index) ?? parts[0];\n return part === void 0 ? [element, 0] : [part.node, index - part.start];\n };\n const found = [];\n for (const match of text.matchAll(pattern)) {\n if (found.length === most) break;\n if (match[0] === \"\") continue;\n const range = element.ownerDocument.createRange();\n range.setStart(...at(match.index, false));\n range.setEnd(...at(match.index + match[0].length, true));\n const { x, y, width, height } = range.getBoundingClientRect();\n if (width > 0 || height > 0) found.push({\n text: match[0],\n box: {\n x: x + dx,\n y: y + dy,\n width,\n height\n }\n });\n }\n return found;\n };\n const selected = (pick) => {\n let elements;\n try {\n elements = Array.from(document.querySelectorAll(pick.selector));\n } catch {\n return { invalid: `${JSON.stringify(pick.selector)} is not a CSS selector` };\n }\n const rules = matching.compile(pick);\n return elements.filter((element) => {\n const role = roleOf(element, pick.role !== null);\n const box = boxOf(element);\n return !isOwn(element) && box.width * box.height > 0 && visible(element) && (pick.scope === \"document\" || inView(new DOMRect(box.x, box.y, box.width, box.height))) && (pick.state !== \"enabled\" || !isDisabled(element)) && rules({\n role,\n name: () => nameOf(element, role),\n text: () => textOf(element),\n context: () => placing.contextOf(element)\n });\n });\n };\n const read = (picks) => {\n const places = [];\n const missing = [];\n for (const pick of picks) {\n const elements = pick.selector === null ? subjected.elementsOf(pick) : selected({\n ...pick,\n selector: pick.selector\n });\n if (\"invalid\" in elements) return { invalid: `${pick.id}: ${elements.invalid}` };\n const element = chosen(elements, pick.choose);\n if (element === void 0) {\n missing.push(pick.id);\n continue;\n }\n const role = roleOf(element, pick.role !== null);\n const box = boxOf(element);\n const own = element.getBoundingClientRect();\n places.push({\n id: pick.id,\n ref: refFor(element),\n subject: {\n role,\n name: nameOf(element, role),\n tag: element.tagName.toLowerCase(),\n context: placing.contextOf(element)\n },\n box,\n fixed: fixed(element),\n words: pick.words === null ? void 0 : words(element, pick.words, box.x - own.x, box.y - own.y)\n });\n }\n return { layout: {\n url: location.href,\n viewport: {\n width: innerWidth,\n height: innerHeight\n },\n scroll: {\n x: scrollX,\n y: scrollY\n },\n scale: devicePixelRatio,\n places,\n missing\n } };\n };\n return { read };\n };\n //#endregion\n //#region src/internal/reading/names.inpage.ts\n const elements = () => {\n const isInput = (element) => element.tagName === \"INPUT\";\n const isTextArea = (element) => element.tagName === \"TEXTAREA\";\n const isSelect = (element) => element.tagName === \"SELECT\";\n const isFrame = (element) => element.tagName === \"IFRAME\";\n const isHtml = (element) => \"innerText\" in element;\n const isButton = (element) => element.tagName === \"BUTTON\";\n const isLabel = (element) => element.tagName === \"LABEL\";\n const textOf = (element) => isHtml(element) ? element.innerText : element.textContent ?? \"\";\n const isElement = (node) => node.nodeType === Node.ELEMENT_NODE;\n const isDocument = (node) => node.nodeType === Node.DOCUMENT_NODE;\n /** The native fields and editable regions that can receive typed text. */\n const textEntry = (element) => isInput(element) && ![\n \"button\",\n \"reset\",\n \"submit\",\n \"image\",\n \"checkbox\",\n \"radio\",\n \"file\",\n \"range\",\n \"color\",\n \"hidden\"\n ].includes(element.type) || isTextArea(element) || isHtml(element) && element.isContentEditable;\n const own = /* @__PURE__ */ new WeakSet();\n const adopt = (node) => own.add(node);\n /** Whether a node is the library's own, or inside a shadow root of one of its own. */\n const isOwn = (node) => {\n const root = node.getRootNode();\n return own.has(node) || root instanceof ShadowRoot && own.has(root.host);\n };\n const clean = (value, max = 160) => {\n const text = (value ?? \"\").replace(/\\s+/g, \" \").trim();\n return text.length > max ? `${text.slice(0, max - 1)}…` : text;\n };\n return {\n adopt,\n clean,\n isInput,\n isTextArea,\n isSelect,\n isFrame,\n isHtml,\n isButton,\n isLabel,\n textOf,\n isElement,\n isDocument,\n isOwn,\n textEntry\n };\n };\n const names = (native) => {\n const { clean, isInput, isTextArea, isSelect, isFrame, textOf, isElement } = native;\n const byElement = /* @__PURE__ */ new WeakMap();\n const byRef = /* @__PURE__ */ new Map();\n const refs = { next: 1 };\n const interactiveRoles = new Set(\"button link checkbox radio tab menuitem menuitemcheckbox menuitemradio option switch slider combobox listbox textbox searchbox spinbutton treeitem\".split(\" \"));\n const containers = {\n HEADER: \"banner\",\n NAV: \"navigation\",\n MAIN: \"main\",\n ASIDE: \"complementary\",\n FOOTER: \"contentinfo\",\n FORM: \"form\",\n DIALOG: \"dialog\"\n };\n const valueRoles = new Set(\"combobox listbox option textbox searchbox spinbutton slider\".split(\" \"));\n /**\n * A label's own words, without the options or values of the controls inside it, native or\n * scripted, such as the custom select Browserbase puts in place of a native one.\n */\n const labelText = (label) => {\n let text = \"\";\n const collect = (node) => {\n for (const child of Array.from(node.childNodes)) if (child.nodeType === Node.TEXT_NODE) text += child.textContent ?? \"\";\n else if (isElement(child) && ![\n \"SELECT\",\n \"TEXTAREA\",\n \"INPUT\",\n \"SCRIPT\",\n \"STYLE\"\n ].includes(child.tagName) && !valueRoles.has(roleOf(child) ?? \"\")) collect(child);\n };\n collect(label);\n return text;\n };\n const roleOf = (element, structural = false) => {\n const explicit = element.getAttribute(\"role\");\n if (explicit !== null && explicit.trim() !== \"\") return explicit.trim().split(/\\s+/)[0] ?? null;\n const tag = element.tagName;\n if (tag === \"A\") return element.hasAttribute(\"href\") ? \"link\" : null;\n if (tag === \"BUTTON\" || tag === \"SUMMARY\") return \"button\";\n if (isSelect(element)) return element.multiple ? \"listbox\" : \"combobox\";\n if (tag === \"TEXTAREA\") return \"textbox\";\n if (isInput(element)) {\n const type = element.type;\n if (type === \"hidden\" || type === \"color\" || type === \"file\") return null;\n if (type === \"checkbox\" || type === \"radio\") return type;\n if (type === \"range\") return \"slider\";\n if (type === \"number\") return \"spinbutton\";\n if (type === \"search\") return \"searchbox\";\n if (type === \"button\" || type === \"submit\" || type === \"reset\" || type === \"image\") return \"button\";\n return \"textbox\";\n }\n if (/^H[1-6]$/.test(tag)) return \"heading\";\n if (tag === \"IMG\") return \"img\";\n if (tag === \"CANVAS\") return \"canvas\";\n if (tag === \"IFRAME\") return \"iframe\";\n if (element.getAttribute(\"contenteditable\") === \"true\") return \"textbox\";\n if (structural) {\n if (tag === \"TH\") return element.getAttribute(\"scope\") === \"row\" ? \"rowheader\" : \"columnheader\";\n const roles = {\n TABLE: \"table\",\n TR: \"row\",\n TD: \"cell\",\n TBODY: \"rowgroup\",\n THEAD: \"rowgroup\",\n TFOOT: \"rowgroup\",\n UL: \"list\",\n OL: \"list\",\n MENU: \"list\",\n LI: \"listitem\"\n };\n if (roles[tag] !== void 0) return roles[tag];\n }\n return containers[tag] ?? null;\n };\n const nameOf = (element, role) => {\n const labelledBy = element.getAttribute(\"aria-labelledby\");\n if (labelledBy !== null) {\n const text = labelledBy.split(/\\s+/).map((id) => {\n const labelling = element.ownerDocument.getElementById(id);\n return labelling === null ? \"\" : labelText(labelling);\n }).join(\" \");\n if (clean(text) !== \"\") return clean(text);\n }\n const label = element.getAttribute(\"aria-label\");\n if (label !== null && clean(label) !== \"\") return clean(label);\n if (isInput(element) || isTextArea(element) || isSelect(element)) {\n const labels = element.labels === null ? \"\" : Array.from(element.labels, labelText).join(\" \");\n if (clean(labels) !== \"\") return clean(labels);\n if (isInput(element) && (element.type === \"button\" || element.type === \"submit\" || element.type === \"reset\")) return clean(element.value);\n return clean(element.getAttribute(\"placeholder\") ?? element.getAttribute(\"title\") ?? element.getAttribute(\"name\"));\n }\n if (role === \"img\") return clean(element.getAttribute(\"alt\") ?? element.getAttribute(\"title\"));\n if (role === \"iframe\") return clean(element.getAttribute(\"title\") ?? element.getAttribute(\"name\"));\n if (role === null || interactiveRoles.has(role) || role === \"heading\") {\n const text = isSecret(element) ? \"\" : clean(textOf(element), 120);\n if (text !== \"\") return text;\n const titled = element.querySelector(\"[title],img[alt],svg title\");\n const fallback = titled === null ? null : titled.tagName === \"IMG\" ? titled.getAttribute(\"alt\") : titled.tagName.toLowerCase() === \"title\" ? titled.textContent : titled.getAttribute(\"title\");\n return clean(element.getAttribute(\"title\") ?? fallback);\n }\n return \"\";\n };\n const isDisabled = (element) => element.matches(\":disabled\") || element.getAttribute(\"aria-disabled\") === \"true\";\n const refFor = (element) => {\n const known = byElement.get(element);\n if (known !== void 0 && byRef.get(known)?.deref() === element) return known;\n const ref = `e${refs.next++}`;\n byElement.set(element, ref);\n byRef.set(ref, new WeakRef(element));\n return ref;\n };\n const lookup = (ref) => {\n const element = byRef.get(ref)?.deref();\n return element !== void 0 && element.isConnected && inCurrentDocument(element) ? element : void 0;\n };\n const describe = (element) => {\n const id = element.id === \"\" ? \"\" : `#${element.id}`;\n const name = clean(nameOf(element, roleOf(element)), 40);\n return `<${element.tagName.toLowerCase()}${id}>${name === \"\" ? \"\" : ` \"${name}\"`}`;\n };\n const isRoot = (node) => node.nodeType === Node.DOCUMENT_NODE || node.nodeType === Node.DOCUMENT_FRAGMENT_NODE;\n const parentOf = (element) => {\n const root = element.getRootNode();\n return element.parentElement ?? (isRoot(root) && \"host\" in root ? root.host : null);\n };\n const activeElement = () => {\n let active = document.activeElement;\n while (active !== null) {\n const inner = active.shadowRoot?.activeElement ?? (isFrame(active) ? active.contentDocument?.activeElement : null);\n if (inner === null || inner === void 0 || inner === active) return active;\n active = inner;\n }\n return null;\n };\n const inCurrentDocument = (element) => {\n let owner = element.ownerDocument;\n while (owner !== document) {\n const frame = owner.defaultView?.frameElement;\n if (frame === null || frame === void 0 || !frame.isConnected || isFrame(frame) && frame.contentDocument !== owner) return false;\n owner = frame.ownerDocument;\n }\n return true;\n };\n const secretToken = /(?:^|\\s)(?:current-password|new-password|one-time-code|cc-number|cc-csc|cc-exp(?:-month|-year)?)(?=\\s|$)/i;\n const secrets = /* @__PURE__ */ new WeakSet();\n /**\n * A field the DOM marks as secret, now or before: by its type, its autocomplete tokens, or a\n * style that shows dots for what it holds, as a PIN field may.\n */\n const isSecret = (element) => {\n if (isInput(element) && element.type === \"password\" || secretToken.test(element.getAttribute(\"autocomplete\") ?? \"\") || (isInput(element) || isTextArea(element)) && !/^(none)?$/.test(getComputedStyle(element).getPropertyValue(\"-webkit-text-security\"))) secrets.add(element);\n return secrets.has(element);\n };\n return {\n ...native,\n activeElement,\n containers,\n describe,\n inCurrentDocument,\n interactiveRoles,\n isDisabled,\n isRoot,\n isSecret,\n lookup,\n nameOf,\n parentOf,\n refFor,\n refs,\n roleOf\n };\n };\n //#endregion\n //#region src/internal/reading/outline.inpage.ts\n const outline = (names, walked, subjects, texts, controlling, url) => {\n const { clean, containers, isFrame, nameOf, refFor, roleOf, textOf } = names;\n const { visit } = walked;\n const { isControl } = subjects;\n const { cut } = texts;\n const textBlocks = /^(?:P|LI|TD|TH|DT|DD|LABEL|SPAN|BLOCKQUOTE|FIGCAPTION|CAPTION|PRE|STRONG|EM|B|I|SMALL|TIME|CODE|LEGEND)$/;\n const nested = \"a[href],button,input,select,textarea,summary,[role],[onclick],[tabindex],[contenteditable],canvas,iframe\";\n const noise = /^[\\s|•·\\-–—,.:;()[\\]{}\"'/\\\\]*$/;\n /** Text inside a control's label is already that control's name. */\n const inControlLabel = (element) => {\n const label = element.closest(\"label\");\n return label !== null && label.control !== null;\n };\n const hrefOf = (element) => {\n if (element.tagName !== \"A\") return \"\";\n const raw = element.getAttribute(\"href\") ?? \"\";\n if (raw === \"\" || raw.startsWith(\"javascript:\")) return \"\";\n try {\n const { origin, href } = new URL(raw, element.ownerDocument.baseURI);\n const reported = url.redact(href);\n const own = origin === location.origin && reported.startsWith(origin);\n return ` -> ${clean(own ? reported.slice(origin.length) : reported, 80)}`;\n } catch {\n return \"\";\n }\n };\n const snapshot = (request) => {\n const roots = request.within === null ? [null] : controlling.rootsOf(request.within);\n if (\"invalid\" in roots) return roots;\n const width = window.innerWidth;\n const height = window.innerHeight;\n const query = request.query === null ? null : request.query.toLowerCase();\n const lines = [];\n const controls = [];\n let above = 0;\n let below = 0;\n const placement = (rect) => {\n if (request.full) return \"in\";\n if (rect.bottom <= 0) return \"above\";\n if (rect.top >= height) return \"below\";\n if (rect.right <= 0 || rect.left >= width) return \"aside\";\n return \"in\";\n };\n const count = (rect) => {\n const where = placement(rect);\n if (where === \"above\") above++;\n if (where === \"below\") below++;\n return where;\n };\n const emit = (depth, line, rect) => {\n if (count(rect) !== \"in\") return false;\n if (query !== null && !line.toLowerCase().includes(query)) return false;\n lines.push(`${\" \".repeat(Math.min(depth, 8))}- ${line}`);\n return true;\n };\n const control = (element, rect, role, depth) => {\n const name = nameOf(element, role);\n const kind = role ?? \"clickable\";\n const box = request.boxes || role === \"canvas\" || role === \"iframe\" ? ` ${Math.round(rect.width)}x${Math.round(rect.height)} at (${Math.round(rect.x)},${Math.round(rect.y)})` : \"\";\n const line = placement(rect) === \"in\" ? `${kind}${name === \"\" ? \"\" : ` ${JSON.stringify(name)}`} [ref=${refFor(element)}]${controlling.states(element, role)}${controlling.valueOf(element)}${hrefOf(element)}${box}` : kind;\n if (emit(depth, line, rect)) controls.push(controlling.controlOf(element, role, kind, name));\n if (isFrame(element)) {\n const body = element.contentDocument?.body;\n if ((body === null || body === void 0) && placement(rect) === \"in\") lines.push(`${\" \".repeat(Math.min(depth + 1, 8))}- (another site's frame: use a screenshot and coordinates)`);\n return {\n depth: depth + 1,\n insidePointer: false,\n controls: false\n };\n }\n if ([\n \"INPUT\",\n \"SELECT\",\n \"TEXTAREA\",\n \"CANVAS\",\n \"IMG\"\n ].includes(element.tagName)) return void 0;\n return {\n depth: depth + 1,\n insidePointer: true,\n controls: true\n };\n };\n const enter = (element, style, rect, { depth, insidePointer }) => {\n const role = roleOf(element);\n if (isControl(element, role, style, rect, insidePointer)) return control(element, rect, role, depth);\n if (role === \"heading\") {\n emit(depth, `heading ${JSON.stringify(nameOf(element, role))}${controlling.states(element, role)}`, rect);\n return;\n }\n if (role === \"img\") {\n const alt = nameOf(element, role);\n if (alt !== \"\") emit(depth, `img ${JSON.stringify(alt)}`, rect);\n return;\n }\n let inner = depth;\n if (role !== null && (containers[element.tagName] !== void 0 || role === \"dialog\")) {\n const label = element.getAttribute(\"aria-label\");\n if (emit(depth, `${role}${label === null ? \"\" : ` ${JSON.stringify(clean(label))}`}:`, rect)) inner = depth + 1;\n }\n if (textBlocks.test(element.tagName) && element.querySelector(nested) === null) {\n if (inControlLabel(element)) return void 0;\n const text = clean(textOf(element), 300);\n if (text !== \"\" && !noise.test(text)) emit(inner, `text: ${text}`, rect);\n return;\n }\n let own = \"\";\n for (const node of Array.from(element.childNodes)) if (node.nodeType === Node.TEXT_NODE) own += node.textContent ?? \"\";\n own = clean(own, 300);\n if (own !== \"\" && !noise.test(own) && !inControlLabel(element)) emit(inner, `text: ${own}`, rect);\n return {\n depth: inner,\n insidePointer: insidePointer || style.cursor === \"pointer\",\n controls: false\n };\n };\n const visitor = {\n enter,\n admit: (child, place) => !place.controls || child.matches(nested) || child.querySelector(nested) !== null,\n outside: count\n };\n for (const root of roots) visit(root, !request.full, {\n depth: 0,\n insidePointer: false,\n controls: false\n }, visitor);\n const outlined = cut(lines.join(\"\\n\"), request.maxChars);\n return { snapshot: {\n ...outlined,\n url: location.href,\n title: document.title,\n above,\n below,\n viewport: {\n width,\n height\n },\n scroll: {\n y: Math.round(window.scrollY),\n height: Math.round(document.documentElement.scrollHeight)\n },\n controls: controls.filter((control) => outlined.text.includes(`[ref=${control.ref}]`))\n } };\n };\n const viewport = () => ({\n width: window.innerWidth,\n height: window.innerHeight\n });\n return {\n snapshot,\n viewport\n };\n };\n //#endregion\n //#region src/internal/reading/ready.inpage.ts\n const ready = (walked, texts, kept) => {\n const { inView, visible } = walked;\n let copy;\n const boxed = (element) => {\n const rect = element.getBoundingClientRect();\n return rect.width * rect.height > 0 && inView(rect);\n };\n const showing = (elements) => Array.from(elements).filter((element) => boxed(element) && visible(element));\n const drawn = (canvas) => {\n copy ??= new OffscreenCanvas(32, 32).getContext(\"2d\", { willReadFrequently: true });\n if (copy === null) return true;\n try {\n copy.clearRect(0, 0, 32, 32);\n copy.imageSmoothingQuality = \"high\";\n copy.drawImage(canvas, 0, 0, 32, 32);\n return new Uint32Array(copy.getImageData(0, 0, 32, 32).data.buffer).some((pixel) => pixel !== 0);\n } catch {\n return true;\n }\n };\n const content = () => showing(document.querySelectorAll(\"video, iframe, embed, object\")).length > 0 || showing(document.querySelectorAll(\"img, svg\")).some((picture) => {\n const { width, height } = picture.getBoundingClientRect();\n return width > 64 && height > 64;\n }) || (texts.read({\n ref: null,\n maxChars: 1,\n unmask: false\n })?.text ?? \"\") !== \"\" || showing(document.querySelectorAll(\"canvas\")).some(drawn);\n const painted = () => {\n const { promise, resolve } = Promise.withResolvers();\n if (document.visibilityState === \"hidden\") resolve(false);\n else requestAnimationFrame(() => resolve(true));\n return promise;\n };\n const check = (quietMillis, clock) => painted().then((paints) => {\n const waiting = [];\n const held = clock !== null && !document.dispatchEvent(new CustomEvent(clock, {\n detail: { op: \"holds\" },\n cancelable: true\n }));\n if (document.readyState === \"loading\") waiting.push(\"load\");\n if (!paints) waiting.push(\"paint\");\n if (document.getAnimations().some((animation) => {\n const effect = animation.effect;\n return (animation.playState === \"running\" || held && animation.playState === \"paused\") && effect !== null && Number.isFinite(effect.getComputedTiming().endTime) && \"target\" in effect && effect.target instanceof Element && boxed(effect.target);\n })) waiting.push(\"animations\");\n if (Array.from(document.images).some((image) => !image.complete && boxed(image))) waiting.push(\"images\");\n if (document.fonts.status !== \"loaded\") waiting.push(\"fonts\");\n if (showing(document.querySelectorAll(\"[aria-busy=true]\")).length > 0) waiting.push(\"busy\");\n if (!content()) waiting.push(\"content\");\n if (kept.changing() > performance.timeOrigin + performance.now() - quietMillis) waiting.push(\"changing\");\n return waiting;\n });\n /**\n * Check until the page is ready, or for `millis`, and say what it is still waiting for; with\n * `quietMillis`, until nothing the record saw in view has changed for that long, too.\n */\n const wait = async (millis, quietMillis = 0, clock = null) => {\n const until = performance.now() + millis;\n for (;;) {\n const waiting = await check(quietMillis, clock);\n if (waiting.length === 0 || performance.now() >= until) return waiting;\n const { promise, resolve } = Promise.withResolvers();\n setTimeout(resolve, Math.min(50, until - performance.now()));\n await promise;\n }\n };\n /**\n * One task, then a frame: what the page's handlers for input did at once has run, a navigation\n * one of them started in a timer has been asked for, and their effect has painted. Says whether\n * the page painted, which a hidden one does not.\n */\n const settle = () => {\n const { promise, resolve } = Promise.withResolvers();\n setTimeout(resolve, 0);\n return promise.then(painted);\n };\n return {\n wait,\n settle\n };\n };\n //#endregion\n //#region src/internal/reading/subjects.inpage.ts\n const states = (names) => (element, role) => {\n const { isDisabled, isInput } = names;\n const given = (attribute) => {\n const value = element.getAttribute(attribute);\n return value === \"true\" || (value === \"false\" ? false : void 0);\n };\n const checkable = element.hasAttribute(\"aria-checked\") || [\n \"checkbox\",\n \"radio\",\n \"switch\",\n \"menuitemcheckbox\",\n \"menuitemradio\"\n ].includes(role ?? \"\");\n return {\n disabled: isDisabled(element),\n checked: checkable ? isInput(element) && element.checked || element.getAttribute(\"aria-checked\") === \"true\" : void 0,\n expanded: given(\"aria-expanded\"),\n selected: given(\"aria-selected\"),\n pressed: given(\"aria-pressed\"),\n focused: element.ownerDocument.activeElement === element,\n level: role === \"heading\" ? Number(element.getAttribute(\"aria-level\")) || Number(/^H([1-6])$/.exec(element.tagName)?.[1]) || 2 : void 0\n };\n };\n const subjects = (names, walked, matching, placing, stateOf) => {\n const { isDisabled, nameOf, refFor, roleOf, textOf } = names;\n const { acts, boxOf, controlOf, hitAt, inView } = walked;\n const { contextOf, known } = placing;\n /** What the outline lists as a control, with a ref: something a person would act on. */\n const isControl = (element, role, style, rect, insidePointer) => acts(element, role) || style.cursor === \"pointer\" && !insidePointer && rect.width > 0 && rect.height > 0;\n /**\n * The elements in scope that match a query, in tree order. Without text, an element matches\n * when it has a role or is a control. With text, any element can, but text inside a control or\n * heading is that control's or heading's, and an element is left out when one inside it\n * matches too: the smallest element showing the text is found, not each one around it.\n */\n const matched = (request) => {\n const { at } = request;\n const matches = matching.compile(request);\n const byText = request.text !== null;\n const viewport = request.scope === \"viewport\";\n const read = known();\n if (request.selector !== null) try {\n document.querySelector(request.selector);\n } catch {\n return { invalid: `${JSON.stringify(request.selector)} is not a CSS selector` };\n }\n const eligible = (element) => (request.selector === null || element.matches(request.selector)) && (request.state !== \"enabled\" || !isDisabled(element));\n const entries = [];\n const open = [];\n const named = (entry) => entry.name ??= nameOf(entry.element, entry.role);\n const placed = (entry) => entry.context ??= contextOf(entry.element, read);\n const judge = (entry, text) => matches({\n role: entry.role,\n name: () => named(entry),\n text,\n context: () => placed(entry)\n });\n const hit = at === null ? null : hitAt(document, at.x, at.y);\n if (hit !== null) {\n const element = controlOf(hit);\n const { x, y, width, height } = boxOf(element);\n const entry = {\n element,\n rect: new DOMRect(x, y, width, height),\n role: roleOf(element, request.role !== null),\n matched: false\n };\n entry.matched = eligible(element) && judge(entry, () => textOf(element));\n entries.push(entry);\n }\n if (at === null) walked.visit(null, viewport, {\n pointer: false,\n owned: false\n }, {\n enter: (element, style, rect, state) => {\n const role = roleOf(element, request.role !== null);\n const control = isControl(element, role, style, rect, state.pointer);\n const unit = control || role === \"heading\";\n const entry = eligible(element) && (byText ? unit || !state.owned : request.selector !== null || role !== null || control) && (!viewport || inView(rect)) ? {\n element,\n rect,\n role,\n matched: false\n } : void 0;\n if (entry !== void 0) entries.push(entry);\n open.push({\n entry,\n inline: style.display === \"inline\",\n parts: [],\n inside: false\n });\n return {\n pointer: state.pointer || style.cursor === \"pointer\",\n owned: state.owned || unit\n };\n },\n text: byText ? (node) => open.at(-1)?.parts.push(node.textContent ?? \"\") : void 0,\n leave: () => {\n const closed = open.pop();\n const parent = open.at(-1);\n if (closed === void 0) return;\n const { entry } = closed;\n const text = closed.parts.join(\"\");\n if (parent !== void 0) parent.parts.push(closed.inline ? text : ` ${text} `);\n if (entry !== void 0 && !(byText && closed.inside)) entry.matched = judge(entry, () => text);\n if (parent !== void 0) parent.inside ||= closed.inside || entry?.matched === true;\n }\n });\n return {\n entries: entries.filter((entry) => entry.matched),\n named,\n placed\n };\n };\n const find = (request) => {\n const result = matched(request);\n if (result.invalid !== void 0) return { invalid: result.invalid };\n const { entries, named, placed } = result;\n return { found: entries.map((entry) => ({\n ref: refFor(entry.element),\n subject: {\n role: entry.role,\n name: named(entry),\n tag: entry.element.tagName.toLowerCase(),\n context: placed(entry)\n },\n box: {\n x: Math.round(entry.rect.x),\n y: Math.round(entry.rect.y),\n width: Math.round(entry.rect.width),\n height: Math.round(entry.rect.height)\n },\n inViewport: inView(entry.rect),\n state: stateOf(entry.element, entry.role)\n })) };\n };\n /** The elements `find` would find, in tree order, with no refs given. */\n const elementsOf = (request) => {\n const result = matched(request);\n return result.invalid !== void 0 ? { invalid: result.invalid } : result.entries.map((entry) => entry.element);\n };\n return {\n find,\n elementsOf,\n isControl,\n stateOf\n };\n };\n //#endregion\n //#region src/internal/reading/text.inpage.ts\n const text = (names, walked) => {\n const { isHtml, isInput, isSecret, isSelect, isTextArea, lookup } = names;\n const valueless = [\n \"checkbox\",\n \"radio\",\n \"button\",\n \"submit\",\n \"reset\",\n \"image\",\n \"file\"\n ];\n /** What a field holds, or undefined for an element that holds nothing entered. */\n const valueOf = (element) => {\n if (isInput(element)) return valueless.includes(element.type) ? void 0 : element.value;\n if (isTextArea(element)) return element.value;\n if (isSelect(element)) return Array.from(element.selectedOptions, (option) => option.text).join(\", \");\n const parent = element.parentElement;\n return isHtml(element) && element.isContentEditable && !(parent !== null && isHtml(parent) && parent.isContentEditable) ? element.innerText : void 0;\n };\n /** What a field shows: `••••` unless `unmask`, and always for a secret field; \"\" when empty. */\n const shown = (element, unmask) => {\n const value = valueOf(element);\n if (value === void 0 || value.trim() === \"\") return value === void 0 ? void 0 : \"\";\n return unmask && !isSecret(element) ? value : \"••••\";\n };\n /** Lines cut after the last whole line within `max` characters, or at `max` when none is. */\n const cut = (lines, max) => {\n if (lines.length <= max) return {\n text: lines,\n truncated: false\n };\n const end = lines.lastIndexOf(\"\\n\", max);\n return {\n text: lines.slice(0, end > 0 ? end : max),\n truncated: true\n };\n };\n /**\n * What the viewport, or one element whole, shows as text: a line per block, table cells apart by\n * a tab, and each field as `shown` gives it.\n */\n const lines = (root, unmask) => {\n const lines = [];\n let line = \"\";\n const end = () => {\n const words = line.replace(/[^\\S\\t]+/g, \" \").replace(/ ?\\t ?/g, \" \").trim();\n if (words !== \"\") lines.push(words);\n line = \"\";\n };\n walked.visit(root, root === null, false, {\n enter: (element, style) => {\n const { display } = style;\n const value = shown(element, unmask);\n const block = !display.startsWith(\"inline\") && display !== \"contents\" && display !== \"table-cell\";\n if (display === \"table-cell\") line += \" \";\n if (block || element.tagName === \"BR\") end();\n if (value === void 0 && !(isInput(element) && valueless.includes(element.type))) return block;\n const label = isInput(element) && /^(button|submit|reset)$/.test(element.type);\n line += ` ${value ?? (label ? element.value : \"\")} `;\n if (block) end();\n },\n text: (node) => {\n line += node.textContent ?? \"\";\n },\n leave: (_, block) => {\n if (block) end();\n }\n });\n end();\n return lines.join(\"\\n\");\n };\n const read = (request) => {\n const root = request.ref === null ? null : lookup(request.ref);\n return root === void 0 ? null : {\n ...cut(lines(root, request.unmask), request.maxChars),\n url: location.href,\n title: document.title\n };\n };\n return {\n cut,\n lines,\n read,\n shown\n };\n };\n //#endregion\n //#region src/internal/reading/walk.inpage.ts\n const walk = (names) => {\n const { interactiveRoles, isElement, isFrame, isInput, parentOf, roleOf } = names;\n const skipped = new Set(\"SCRIPT STYLE NOSCRIPT TEMPLATE HEAD META LINK SVG\".split(\" \"));\n /** Whether a box, in top-document pixels, meets the viewport. */\n const inView = (rect, width = innerWidth, height = innerHeight) => rect.right > 0 && rect.bottom > 0 && rect.left < width && rect.top < height;\n /** Whether an element reached on its own shows, by the walk's rule and its ancestors'. */\n const visible = (element) => {\n if (element.closest(\"[aria-hidden=true]\") !== null) return false;\n if (element.checkVisibility({\n opacityProperty: true,\n visibilityProperty: true\n })) return true;\n if (getComputedStyle(element).display !== \"contents\") return false;\n for (let node = element; node !== null; node = parentOf(node)) {\n const style = getComputedStyle(node);\n if (style.display === \"none\" || style.opacity === \"0\" || node === element && style.visibility !== \"visible\") return false;\n }\n return true;\n };\n const untransformed = (frame, rect) => {\n if (rect.width !== frame.offsetWidth || rect.height !== frame.offsetHeight) return false;\n let ancestor = frame;\n while (ancestor !== null) {\n const style = (ancestor.ownerDocument.defaultView ?? window).getComputedStyle(ancestor);\n if (style.transform !== \"none\" || style.scale !== \"none\" || style.rotate !== \"none\" || style.perspective !== \"none\" || style.zoom !== \"1\") return false;\n ancestor = parentOf(ancestor);\n }\n return true;\n };\n /** The element painted at a point, inside shadow roots and same-origin frames. */\n const hitAt = (root, x, y) => {\n let hit = root.elementFromPoint(x, y);\n while (hit?.shadowRoot !== null && hit?.shadowRoot !== void 0) {\n const inner = hit.shadowRoot.elementFromPoint(x, y);\n if (inner === null || inner === hit) break;\n hit = inner;\n }\n if (hit !== null && isFrame(hit)) {\n const document = hit.contentDocument;\n if (document !== null) {\n const rect = hit.getBoundingClientRect();\n if (untransformed(hit, rect)) return hitAt(document, x - rect.left - hit.clientLeft, y - rect.top - hit.clientTop) ?? hit;\n }\n }\n return hit;\n };\n /** Whether its role or a click handler makes an element a control. */\n const acts = (element, role) => isInput(element) && element.type !== \"hidden\" || role !== null && (interactiveRoles.has(role) || role === \"canvas\" || role === \"iframe\") || element.hasAttribute(\"onclick\");\n const controlOf = (hit) => {\n let element = hit;\n while (element !== null) {\n if (acts(element, roleOf(element))) return element;\n element = parentOf(element);\n }\n return hit;\n };\n /** An element's box in top-document viewport pixels, through the frames around it. */\n const boxOf = (element) => {\n const { x, y, width, height } = element.getBoundingClientRect();\n const frame = element.ownerDocument.defaultView?.frameElement ?? null;\n if (frame === null) return {\n x,\n y,\n width,\n height\n };\n const outer = boxOf(frame);\n return {\n x: x + outer.x + frame.clientLeft,\n y: y + outer.y + frame.clientTop,\n width,\n height\n };\n };\n /** What is painted where pinned things sit, what is pinned in view, and every element holding it. */\n const painted = (width, height) => {\n const keep = /* @__PURE__ */ new Set();\n const hold = (element) => {\n for (let node = element; node !== null && !keep.has(node); node = parentOf(node) ?? node.ownerDocument.defaultView?.frameElement ?? null) keep.add(node);\n };\n for (const y of [\n 8,\n 48,\n height / 2,\n height - 48,\n height - 8\n ]) for (const x of [\n 8,\n 48,\n width / 4,\n width / 2,\n width * 3 / 4,\n width - 48,\n width - 8\n ]) if (x >= 0 && y >= 0 && x < width && y < height) {\n hold(hitAt(document, x, y));\n for (const beneath of document.elementsFromPoint(x, y)) hold(beneath);\n }\n for (const element of Array.from(document.querySelectorAll(\":modal, :popover-open\"))) hold(element);\n for (const element of Array.from(document.querySelectorAll(\"[style*=\\\"fixed\\\" i]\"))) if (inView(element.getBoundingClientRect(), width, height)) hold(element);\n return keep;\n };\n /**\n * Visit `root` and what it holds, or the whole document when `root` is null. With `viewport`,\n * a subtree outside the viewport is skipped, as described above.\n */\n const visit = (root, viewport, state, visitor) => {\n const { innerWidth: width, innerHeight: height } = window;\n let keep;\n const children = (parent, inner, dx, dy) => {\n const nodes = visitor.text === void 0 ? parent.children : parent.childNodes;\n for (const node of Array.from(nodes)) if (node.nodeType === Node.TEXT_NODE) visitor.text?.(node, inner);\n else if (isElement(node) && (visitor.admit === void 0 || visitor.admit(node, inner))) one(node, inner, dx, dy);\n };\n const one = (element, outer, dx, dy) => {\n if (skipped.has(element.tagName.toUpperCase())) return;\n const local = element.getBoundingClientRect();\n const rect = new DOMRect(local.x + dx, local.y + dy, local.width, local.height);\n if (viewport && local.width > 0 && local.height > 0 && !inView(rect, width, height) && !(keep ??= painted(width, height)).has(element)) {\n visitor.outside?.(rect);\n return;\n }\n const style = getComputedStyle(element);\n if (style.display === \"none\" || style.opacity === \"0\" || element.getAttribute(\"aria-hidden\") === \"true\") return;\n if (!visible(element)) {\n for (const child of Array.from(element.children)) one(child, outer, dx, dy);\n return;\n }\n const inner = visitor.enter(element, style, rect, outer);\n if (inner === void 0) return;\n if (isFrame(element)) {\n const body = element.contentDocument?.body;\n if (body !== null && body !== void 0) children(body, inner, rect.x, rect.y);\n } else {\n if (element.shadowRoot !== null) children(element.shadowRoot, inner, dx, dy);\n children(element, inner, dx, dy);\n }\n visitor.leave?.(element, inner);\n };\n if (root === null) children(document, state, 0, 0);\n else one(root, state, 0, 0);\n };\n return {\n acts,\n boxOf,\n controlOf,\n hitAt,\n inView,\n visible,\n visit\n };\n };\n //#endregion\n //#region src/internal/timeline/changes.inpage.ts\n const changes = (names, walked, placing, kept, seeing, marking, recorder) => {\n const { clean, isInput, roleOf, nameOf } = names;\n const groups = \"tr,[role=row],form,dialog,[role=dialog],[role=alertdialog]\";\n /** Whether `element` lies in what an input on `target` acted on, its group, or what it controls. */\n const local = (target, element) => {\n const controls = target.closest(\"[aria-controls]\")?.getAttribute(\"aria-controls\") ?? \"\";\n const group = target.closest(groups);\n return target.contains(element) || group?.contains(element) === true || controls.split(/\\s+/).some((id) => id !== \"\" && document.getElementById(id)?.contains(element) === true);\n };\n /** What an element sits in, or sat in as it went. */\n const parentOf = (key) => key instanceof Element ? key.isConnected ? key.parentElement : marking.placeOf(key) ?? null : null;\n const fluxMillis = 1e4;\n const stillMillis = 2e3;\n /**\n * Each input a change may follow, with what the page did before it: what changed in the 10 s\n * before, the parents that gained or lost a child then, and whether nothing changed, and nothing\n * was let go, in the 2 s before. What holds the input's target, as a menu holds its item, came\n * with it, so it counts only as changing itself.\n */\n const before = () => {\n const inputs = recorder.inputs();\n if (inputs.length === 0) return [];\n const { tracks, losses } = kept.recent();\n return inputs.map(({ at, target }) => {\n const changed = /* @__PURE__ */ new Set();\n const moved = /* @__PURE__ */ new Set();\n let still = losses.every((lost) => lost >= at || lost < at - stillMillis);\n for (const { key, kind, initial, samples } of tracks) {\n const prior = samples.flatMap(({ at: when, shown }, index) => kind === \"value\" || when >= at || when < at - fluxMillis ? [] : [shown === null || (index === 0 ? initial : samples[index - 1]?.shown) === null]);\n if (prior.length > 0) changed.add(key);\n if (prior.length === 0 || key instanceof Element && key.contains(target)) continue;\n if (prior.includes(true)) moved.add(parentOf(key));\n if (samples.some(({ at: when }) => when < at && when >= at - stillMillis)) still = false;\n }\n return {\n at,\n target,\n changed,\n moved,\n still\n };\n });\n };\n /** The input a change followed, on the page's clock, where `Change.cause`'s rule names one. */\n const causeOf = (one, element, inputs) => {\n const parent = parentOf(one.track.key);\n for (const input of inputs.toReversed()) {\n const after = one.startedAt - input.at;\n if (after < 0) continue;\n if (after > 3e3) break;\n if (!(one.track.known >= input.at - fluxMillis || input.changed.has(one.track.key) || parent !== null && input.moved.has(parent)) && (local(input.target, element) || after <= 500 && input.still)) return input.at;\n }\n };\n const describe = (one, known, unmask, inputs) => {\n const { track, kind, before, after, lowest, highest, ...times } = one;\n const element = track.key instanceof Element ? track.key : null;\n const where = element?.isConnected === true ? element : marking.placeOf(track.key) ?? null;\n const box = where === null ? void 0 : walked.boxOf(where);\n const role = element === null ? null : roleOf(element);\n const field = kind === \"value\";\n const checkable = element !== null && isInput(element) && /^(checkbox|radio)$/.test(element.type);\n const masked = (value) => value === void 0 || !field || unmask || checkable || value === \"\" ? value : \"••••\";\n return {\n ...times,\n kind,\n subject: {\n role,\n name: element === null ? \"\" : field ? nameOf(element, role) : clean(element.getAttribute(\"aria-label\"), 120),\n tag: element === null ? \"title\" : element.tagName.toLowerCase(),\n context: kind === \"title\" || where === null ? {} : placing.contextOf(where, known)\n },\n box: box === void 0 || box.width === 0 && box.height === 0 ? void 0 : box,\n before: masked(before),\n after: masked(after),\n lowest: field ? void 0 : lowest,\n highest: field ? void 0 : highest,\n cause: field || where === null ? void 0 : causeOf(one, where, inputs)\n };\n };\n /** What changed after `since`, up to `until`, and no later than now. */\n const read = (request) => {\n const now = performance.timeOrigin + performance.now();\n recorder.start();\n seeing.settle();\n const until = Math.min(request.until ?? now, now);\n const { from, dropped, folded } = kept.read(request.since ?? Number.NEGATIVE_INFINITY, until, now);\n const known = placing.known();\n const inputs = before();\n return {\n until,\n from,\n dropped,\n records: folded.map((one) => describe(one, known, request.unmask, inputs))\n };\n };\n return { read };\n };\n //#endregion\n //#region src/internal/timeline/fold.inpage.ts\n const fold = () => {\n /** The one number some words show, such as 61240 in \"$61,240\"; none for none or several. */\n const number = (words) => {\n const found = words.match(/[-+−]?\\d[\\d,]*(?:\\.\\d+)?/g);\n const value = Number(found?.length === 1 ? found[0]?.replaceAll(\",\", \"\").replace(\"−\", \"-\") : \"\");\n return found?.length === 1 && Number.isFinite(value) ? [value] : [];\n };\n /** A track's changes after `since`, up to `until`, if one was seen in view. */\n const over = (track, since, until) => {\n const inside = track.samples.filter((sample) => sample.at > since && sample.at <= until);\n const first = inside[0];\n const last = inside.at(-1);\n if (first === void 0 || last === void 0 || !inside.some((sample) => sample.seen === true)) return void 0;\n const prior = track.samples[track.samples.indexOf(first) - 1];\n const lost = track.known <= since ? track.known : void 0;\n const start = prior === void 0 ? lost === void 0 ? void 0 : track.initial : prior.shown;\n const words = [start, ...inside.map((sample) => sample.shown)].filter((each) => typeof each === \"string\");\n const numbers = words.flatMap(number);\n const ranged = inside.length > 1 && numbers.length === words.length;\n const kind = track.kind !== \"content\" ? track.kind : last.shown === null ? start === null ? \"brief\" : \"disappeared\" : start === null ? \"appeared\" : \"text\";\n return {\n track,\n kind,\n startedAt: first.at,\n at: last.at,\n before: kind === \"disappeared\" ? words.at(-1) : start ?? void 0,\n after: kind === \"brief\" ? words.at(-1) : last.shown ?? void 0,\n count: inside.length,\n lowest: ranged ? words[numbers.indexOf(Math.min(...numbers))] : void 0,\n highest: ranged ? words[numbers.indexOf(Math.max(...numbers))] : void 0,\n earlier: prior?.at ?? (lost === Number.NEGATIVE_INFINITY ? void 0 : lost)\n };\n };\n /**\n * How readily a track gives way when the record is full: one that holds no change first, then\n * one that keeps changing, one never seen in view and one that has gone; news never does.\n */\n const rank = ({ samples: [only, ...more] }) => only === void 0 ? 4 : more.length > 0 ? 3 : only.seen === false ? 2 : only.shown === null ? 1 : 0;\n return {\n number,\n over,\n rank\n };\n };\n //#endregion\n //#region src/internal/timeline/history.inpage.ts\n const history = (folding, bounds = {\n tracks: 256,\n samples: 32,\n retention: 6e4\n }) => {\n const { tracks: maxTracks, samples: maxSamples, retention } = bounds;\n const tracks = /* @__PURE__ */ new Map();\n let refused = /* @__PURE__ */ new WeakSet();\n let losses = [];\n let lastLoss = Number.NEGATIVE_INFINITY;\n const gone = [];\n let begun;\n const lose = (at, count) => {\n const last = losses.at(-1);\n if (count <= 0) return;\n lastLoss = Math.max(lastLoss, at);\n if (last?.[0] === at) last[1] += count;\n else losses.push([at, count]);\n if (losses.length > 256) losses.shift();\n };\n const latest = (track) => track.samples.at(-1)?.at ?? Number.NEGATIVE_INFINITY;\n const drop = (track) => {\n tracks.delete(track.key);\n gone.push(track.key);\n };\n let version = 0;\n let barren = -1;\n /** What gives way for a newcomer: one that holds no change, then one that keeps changing. */\n const victim = () => {\n let chosen;\n let rank = 0;\n for (const track of barren === version ? [] : tracks.values()) {\n const next = folding.rank(track);\n if (next > rank) [chosen, rank] = [track, next];\n if (rank === 4) break;\n }\n if (chosen === void 0) barren = version;\n return chosen;\n };\n const evict = (track) => {\n drop(track);\n if (track.samples.length > 0) refused.add(track.key);\n for (const sample of track.samples) lose(sample.at, 1);\n };\n /** A key the record cannot keep: its change is counted. */\n const refuse = (key, at) => {\n refused.add(key);\n lose(at, 1);\n };\n /**\n * A new state for `key` at `at`: its sample, or none when it is no change or finds no room.\n * `initial` says what a key not yet kept showed before.\n */\n const note = (key, kind, at, shown, initial) => {\n let track = tracks.get(key);\n if (track === void 0) {\n const full = !refused.has(key) && tracks.size >= maxTracks;\n const out = full ? victim() : void 0;\n if (refused.has(key) || full && out === void 0) return refuse(key, at);\n const before = initial();\n if (shown !== void 0 && shown === before) return void 0;\n if (out !== void 0) evict(out);\n track = {\n key,\n kind,\n initial: before,\n known: Number.NEGATIVE_INFINITY,\n samples: []\n };\n tracks.set(key, track);\n }\n const { samples } = track;\n version++;\n if (samples.at(-1)?.at === at) samples.pop();\n const previous = samples.length === 0 ? track.initial : samples.at(-1)?.shown;\n if (shown !== void 0 && shown === previous) return void 0;\n const oldest = samples.length >= maxSamples ? samples.shift() : void 0;\n if (oldest !== void 0) {\n track.initial = oldest.shown;\n track.known = oldest.at;\n lose(oldest.at, 1);\n }\n const sample = {\n at,\n shown,\n seen: void 0\n };\n samples.push(sample);\n return sample;\n };\n /** Judge a sample as the page rendered it; a state that repeats the one before is no change. */\n const settle = (key, sample, shown, seen) => {\n const track = tracks.get(key);\n version++;\n if (sample.shown === void 0) sample.shown = shown;\n if (sample.seen === void 0) sample.seen = seen;\n if (track === void 0) return;\n let previous = track.initial;\n const changes = track.samples.filter((each) => {\n const same = each.shown !== void 0 && each.shown === previous;\n if (!same) previous = each.shown;\n return !same;\n });\n track.samples.splice(0, track.samples.length, ...changes);\n };\n /**\n * The window after `since`, up to `until`: where the record is whole, how many changes in it the\n * record let go, and each element's changes, oldest first by when they began.\n */\n const read = (since, until, now) => {\n for (const track of tracks.values()) if (latest(track) < now - retention) drop(track);\n return {\n from: Math.min(until, Math.max(begun ?? now, now - retention, lastLoss)),\n dropped: losses.reduce((sum, [at, count]) => at > since && at <= until ? sum + count : sum, 0),\n folded: [...tracks.values()].flatMap((track) => folding.over(track, since, until) ?? []).toSorted((left, right) => left.startedAt - right.startedAt)\n };\n };\n /** When something in view last changed, or something not yet judged; for a wait for stillness. */\n const changing = () => Math.max(begun ?? Number.NEGATIVE_INFINITY, ...Array.from(tracks.values(), (track) => track.samples.findLast((sample) => sample.seen !== false)?.at ?? Number.NEGATIVE_INFINITY));\n return {\n begin: (at) => {\n begun = at;\n },\n begun: () => begun !== void 0,\n clear: () => {\n for (const track of tracks.values()) drop(track);\n refused = /* @__PURE__ */ new WeakSet();\n losses = [];\n lastLoss = Number.NEGATIVE_INFINITY;\n begun = void 0;\n },\n changing,\n /** Keys whose tracks went since this was last asked, for the recorder to stop watching. */\n forgotten: () => gone.splice(0),\n has: (key) => tracks.has(key),\n /** Whether the record has let `key` go: its later changes are counted, never kept. */\n refuses: (key) => refused.has(key),\n lose,\n note,\n read,\n /** Each element's history, and when the record let changes go, for a read to judge causes. */\n recent: () => ({\n tracks: [...tracks.values()],\n losses: losses.map(([at]) => at)\n }),\n /** A track moves to the element that took its key's place, as a re-rendered price does. */\n rekey: (from, to) => {\n const track = tracks.get(from);\n if (track === void 0 || tracks.has(to)) return false;\n tracks.delete(from);\n track.key = to;\n tracks.set(to, track);\n return true;\n },\n settle\n };\n };\n //#endregion\n //#region src/internal/timeline/marks.inpage.ts\n const marks = (names, kept, seeing) => {\n const { clean, isElement, isHtml } = names;\n const unwritten = new Set(\"SCRIPT STYLE NOSCRIPT TEMPLATE TITLE\".split(\" \"));\n const hiding = /display\\s*:\\s*none|visibility\\s*:\\s*hidden|opacity\\s*:\\s*0(?![.\\d])/i;\n let places = /* @__PURE__ */ new WeakMap();\n let title = \"\";\n const words = (text) => clean(text, 200) || null;\n const content = (element, at, shown, initial) => {\n const sample = kept.note(element, \"content\", at, shown, initial);\n if (sample !== void 0) seeing.look(element, sample);\n };\n /** What a text-only element said before this batch: its text with the batch undone. */\n const before = (leaf, records) => {\n let nodes = Array.from(leaf.childNodes);\n const old = /* @__PURE__ */ new Map();\n for (const record of records.toReversed()) if (record.type === \"characterData\") old.set(record.target, record.oldValue ?? \"\");\n else {\n const added = new Set(Array.from(record.addedNodes));\n nodes = nodes.filter((node) => !added.has(node));\n const next = record.nextSibling === null ? -1 : nodes.indexOf(record.nextSibling);\n nodes.splice(next === -1 ? nodes.length : next, 0, ...Array.from(record.removedNodes));\n }\n return words(nodes.map((node) => old.get(node) ?? node.textContent).join(\"\"));\n };\n const attribute = (element, { attributeName: name, oldValue: old }, at) => {\n const was = name === \"hidden\" ? old !== null : name === \"aria-hidden\" ? old === \"true\" : name === \"open\" ? element.tagName === \"DIALOG\" && old === null : name === \"style\" && hiding.test(old ?? \"\");\n if (name === \"style\" && !was && !hiding.test(element.getAttribute(\"style\") ?? \"\")) return;\n const state = seeing.state(element);\n if (!kept.has(element) && !was && state === void 0 && name !== \"open\") return seeing.glance(element);\n content(element, at, void 0, () => was || state === false ? null : name === \"open\" && old === null ? words(element.querySelector(\":scope > summary\")?.textContent) : words(element.textContent));\n };\n /** What one mutation added to and removed from `target`. */\n const nodes = (change, target, batch) => {\n const added = Array.from(change.addedNodes).slice(0, 64);\n const removed = Array.from(change.removedNodes).slice(0, 64);\n const text = [...added, ...removed].some((node) => !isElement(node) && /\\S/.test(node.textContent ?? \"\"));\n kept.lose(batch.at, Math.max(change.addedNodes.length, change.removedNodes.length) - 64);\n if (text) batch.owners.add(target);\n removed.forEach((gone, index) => {\n const node = added[index];\n if (!isElement(gone)) return;\n batch.left.add(gone);\n if (node !== void 0 && isElement(node) && kept.rekey(gone, node)) seeing.unwatch(gone);\n else if (kept.has(gone)) {\n places.set(gone, target);\n const sample = kept.note(gone, \"content\", batch.at, null, () => void 0);\n if (sample !== void 0) sample.seen = seeing.viewed(gone);\n seeing.unwatch(gone);\n }\n });\n for (const node of added) if (isElement(node) && isHtml(node) && !unwritten.has(node.tagName) && !node.isContentEditable) {\n if (kept.has(node) || !text && !batch.left.has(node)) {\n batch.arrived.add(node);\n content(node, batch.at, void 0, () => null);\n }\n }\n };\n /** Whether `element` is inside something this batch added, which tells it with its own words. */\n const inside = (element, arrived) => {\n for (let up = element.parentElement; arrived.size > 0 && up !== null; up = up.parentElement) if (arrived.has(up)) return true;\n return false;\n };\n const ownerOf = (change) => change.type === \"characterData\" ? change.target.parentElement : change.target;\n /** Mark what one batch of mutations changed, at `at`. */\n const mark = (records, at) => {\n const batch = {\n at,\n owners: /* @__PURE__ */ new Set(),\n arrived: /* @__PURE__ */ new Set(),\n left: /* @__PURE__ */ new Set()\n };\n let byOwner;\n for (const change of records) {\n const target = ownerOf(change);\n if (target === null || !isElement(target) || inside(target, batch.arrived)) continue;\n const known = kept.has(target) || kept.refuses(target);\n if (change.type !== \"attributes\") if (change.type === \"characterData\" || target.childElementCount === 0 && known) batch.owners.add(target);\n else nodes(change, target, batch);\n else if (isHtml(target) && target !== document.body && target !== document.documentElement) attribute(target, change, at);\n }\n for (const owner of batch.owners) {\n const leaf = owner.childElementCount === 0;\n if (kept.refuses(owner)) kept.lose(at, 1);\n if (kept.refuses(owner) || !isHtml(owner) || unwritten.has(owner.tagName)) continue;\n if (owner === document.body || owner.isContentEditable) continue;\n if (batch.arrived.has(owner) || inside(owner, batch.arrived)) continue;\n content(owner, at, leaf ? words(owner.textContent) : void 0, () => {\n byOwner ??= Map.groupBy(records, ownerOf);\n return leaf ? before(owner, byOwner.get(owner) ?? []) : void 0;\n });\n }\n if (document.title === title) return;\n const previous = words(title);\n const sample = kept.note(document, \"title\", at, words(title = document.title), () => previous);\n if (sample !== void 0) sample.seen = true;\n };\n return {\n mark,\n /** Where a removed element was, which gives its context. */\n placeOf: (key) => places.get(key),\n /** Start afresh, from the document's title now. */\n reset: () => {\n places = /* @__PURE__ */ new WeakMap();\n title = document.title;\n }\n };\n };\n //#endregion\n //#region src/internal/timeline/record.inpage.ts\n const record = (names, texts, kept, seeing, marking) => {\n const { isElement, isInput } = names;\n const epoch = () => performance.timeOrigin + performance.now();\n const declared = \"[role=alert],[role=status],[role=log],[role=dialog],[role=alertdialog],[aria-live],dialog,[popover]\";\n let running = false;\n let lastRead = 0;\n let focused = /* @__PURE__ */ new WeakMap();\n const inputs = [];\n const targetOf = (event) => {\n const target = event.composedPath()[0];\n return target instanceof Node && isElement(target) ? target : void 0;\n };\n /** A field's value as the record keeps it: a secret one's as `••••`, a box's checked or not. */\n const valueOf = (field) => isInput(field) && (field.type === \"checkbox\" || field.type === \"radio\") ? field.checked ? \"checked\" : \"not checked\" : texts.shown(field, true);\n const onFocus = (event) => {\n const field = targetOf(event);\n const value = field === void 0 ? void 0 : valueOf(field);\n if (field !== void 0 && value !== void 0) focused.set(field, value);\n };\n const onValue = (event) => {\n const field = targetOf(event);\n const value = field === void 0 ? void 0 : valueOf(field);\n if (field === void 0 || value === void 0) return;\n const sample = kept.note(field, \"value\", epoch(), value, () => focused.get(field) ?? null);\n if (sample !== void 0) seeing.look(field, sample);\n };\n const note = (target) => {\n inputs.push({\n at: epoch(),\n target\n });\n if (inputs.length > 8) inputs.shift();\n };\n const onInput = (event) => {\n const target = targetOf(event);\n if (event.isTrusted && target !== void 0) note(target);\n };\n const listeners = [\n [\"focusin\", onFocus],\n [\"input\", onValue],\n [\"change\", onValue],\n [\"pointerdown\", onInput],\n [\"keydown\", onInput]\n ];\n const options = {\n capture: true,\n passive: true\n };\n const stop = () => {\n running = false;\n document.removeEventListener(\"DOMContentLoaded\", begin);\n observer.disconnect();\n for (const [type, listener] of listeners) document.removeEventListener(type, listener, options);\n seeing.clear();\n kept.clear();\n kept.forgotten();\n inputs.length = 0;\n focused = /* @__PURE__ */ new WeakMap();\n };\n const observer = new MutationObserver((records) => {\n const at = epoch();\n if (at - lastRead > 12e4) stop();\n else marking.mark(records, at);\n });\n const begin = () => {\n if (!running || kept.begun()) return;\n observer.observe(document, {\n subtree: true,\n childList: true,\n characterData: true,\n characterDataOldValue: true,\n attributeFilter: [\n \"hidden\",\n \"open\",\n \"aria-hidden\",\n \"class\",\n \"style\"\n ],\n attributeOldValue: true\n });\n for (const [type, listener] of listeners) document.addEventListener(type, listener, options);\n marking.reset();\n for (const element of Array.from(document.querySelectorAll(declared)).slice(0, 64)) seeing.glance(element, true);\n kept.begin(epoch());\n };\n return {\n stop,\n /** Record from now, once the document is parsed; each read keeps the record going. */\n start: () => {\n lastRead = epoch();\n if (running) return;\n running = true;\n if (document.readyState === \"loading\") document.addEventListener(\"DOMContentLoaded\", begin, { once: true });\n else begin();\n },\n /**\n * Keep an input at `target` now, as a trusted one is kept: what a site does through its own\n * app, whose events the page sees as untrusted, so its changes can name their cause.\n */\n note,\n inputs: () => inputs\n };\n };\n //#endregion\n //#region src/internal/timeline/sight.inpage.ts\n const sight = (names, walked, texts, kept) => {\n const { clean } = names;\n const { visible } = walked;\n let viewed = /* @__PURE__ */ new WeakMap();\n let watching = /* @__PURE__ */ new WeakSet();\n let states = /* @__PURE__ */ new WeakMap();\n const waiting = /* @__PURE__ */ new Map();\n /** What an element shows: its words, if its style shows it. */\n const shownBy = (element) => element.isConnected && visible(element) ? clean(texts.lines(element, false), 200) || null : null;\n /** Settle what waited on an element; its words are read once, if one of them needs them. */\n const judge = (element, pending, seen, was) => {\n const shown = pending.some((sample) => sample.shown === void 0) ? shownBy(element) : void 0;\n for (const sample of pending) {\n const now = sample.shown === void 0 ? shown : sample.shown;\n kept.settle(element, sample, now, now === null ? was : seen);\n }\n };\n const observer = new IntersectionObserver((entries) => {\n for (const { target, isIntersecting } of entries) {\n const was = viewed.get(target) ?? false;\n const seen = isIntersecting && visible(target);\n const pending = waiting.get(target);\n viewed.set(target, seen);\n waiting.delete(target);\n if (pending !== void 0) judge(target, pending, seen, was);\n if (!kept.has(target)) {\n states.set(target, visible(target));\n unwatch(target);\n }\n }\n });\n /** Watch an element, asking for a fresh report even if it is watched already. */\n const watch = (element) => {\n watching.add(element);\n observer.unobserve(element);\n observer.observe(element);\n };\n const unwatch = (element) => {\n watching.delete(element);\n observer.unobserve(element);\n };\n return {\n /** Judge a sample at once if what it shows and whether it is in view are known, else on render. */\n look: (element, sample) => {\n const view = viewed.get(element);\n if (sample.shown !== void 0 && view !== void 0 && watching.has(element)) {\n sample.seen = view;\n return;\n }\n waiting.set(element, [...waiting.get(element) ?? [], sample]);\n watch(element);\n },\n /**\n * Look at an element once, for its state when it next changes: as it renders, or `now`, by its\n * style, as for the few the record looks at as it starts.\n */\n glance: (element, now = false) => {\n if (now) states.set(element, visible(element));\n if (!watching.has(element)) watch(element);\n },\n /** Whether the style of an element looked at once showed it, if it was. */\n state: (element) => states.get(element),\n /** Whether a watched element was in view as the page last rendered it. */\n viewed: (element) => viewed.get(element) ?? false,\n unwatch,\n /** Judge now what the page has not rendered since it changed, as a hidden tab never does. */\n settle: () => {\n for (const [element, pending] of waiting) {\n const seen = element.isConnected && walked.inView(element.getBoundingClientRect()) && visible(element);\n judge(element, pending, seen, viewed.get(element) ?? false);\n viewed.set(element, seen);\n }\n waiting.clear();\n for (const key of kept.forgotten()) if (key instanceof Element) unwatch(key);\n },\n clear: () => {\n observer.disconnect();\n waiting.clear();\n viewed = /* @__PURE__ */ new WeakMap();\n watching = /* @__PURE__ */ new WeakSet();\n states = /* @__PURE__ */ new WeakMap();\n }\n };\n };\n //#endregion\n //#region src/internal/url.ts\n const addresses = () => {\n const withheld = \"••••••••\";\n const credential = /token|secret|passw|passcode|passphrase|signature|credential|assertion|verifier|bearer|jwt|hmac|apikey|accesskey|privatekey|sess(?:ion)?id|saml(?:response|art)|(?:sig|otp)$|(?:auth|api|access|private|secret|signing|client|encryption|licen[cs]e|session|master|app|device|verification|verify|confirmation|confirm|activation|activate|reset|recovery|login|security|magic|onetime|mfa|2fa|sms|email|otp|oob)(?:code|key)$|^(?:auth|authorization|pwd|pass)$/;\n const ambiguous = /^(?:code|key|session|sid|ticket)$/;\n const secret = (name, value) => {\n const bare = name.toLowerCase().replace(/[^a-z0-9]/g, \"\");\n return value !== \"\" && (credential.test(bare) || ambiguous.test(bare) && value.length >= 16 && /\\d/.test(value) && /[a-z]/i.test(value));\n };\n const masked = (parameters, separator) => parameters.split(separator).map((parameter) => {\n const [name = \"\", value = \"\"] = [...new URLSearchParams(parameter)][0] ?? [];\n return secret(name, value) ? `${parameter.slice(0, parameter.indexOf(\"=\") + 1)}${withheld}` : parameter;\n }).join(separator);\n /**\n * `url` as the library reports it: without userinfo, and with each credential's value withheld,\n * so the rest keeps its identity, such as a chart's `?ticker=ETH`. An address without a host,\n * such as `data:` or `about:blank`, is content or a fixed name, and stays as it is.\n */\n const redact = (url) => {\n const parsed = URL.parse(url);\n if (parsed === null || parsed.host === \"\") return url;\n parsed.username = \"\";\n parsed.password = \"\";\n parsed.pathname = masked(parsed.pathname, \";\");\n parsed.search = masked(parsed.search.slice(1), \"&\");\n if (parsed.hash.includes(\"=\")) {\n const fragment = parsed.hash.slice(1);\n const question = fragment.indexOf(\"?\");\n const start = question >= 0 && question < fragment.indexOf(\"=\") ? question + 1 : 0;\n parsed.hash = fragment.slice(0, start) + masked(fragment.slice(start), \"&\");\n }\n return parsed.href.replaceAll(encodeURIComponent(withheld), withheld);\n };\n return {\n withheld,\n redact\n };\n };\n //#endregion\n //#region src/internal/page/compose.inpage.ts\n const compose = (parts, next) => {\n const named = parts.names(parts.elements());\n if (next !== void 0) named.refs.next = next;\n const walked = parts.walk(named);\n const placing = parts.context(named, walked);\n const matching = parts.match();\n const subjected = parts.subjects(named, walked, matching, placing, parts.states(named));\n const texts = parts.text(named, walked);\n const controlled = parts.controls(named, subjected, texts);\n const kept = parts.history(parts.fold());\n const seeing = parts.sight(named, walked, texts, kept);\n const marking = parts.marks(named, kept, seeing);\n const recorder = parts.record(named, texts, kept, seeing, marking);\n const url = parts.addresses();\n const read = parts.outline(named, walked, subjected, texts, controlled, url);\n const readiness = parts.ready(walked, texts, kept);\n const overlaid = parts.overlay(named);\n const posing = parts.pose(named);\n return {\n named,\n walked,\n placing,\n overlaid,\n posing,\n recorder,\n url,\n reads: {\n refs: named.refs,\n snapshot: read.snapshot,\n find: subjected.find,\n layout: parts.layout(named, walked, subjected, matching, placing).read,\n overlay: overlaid.draw,\n pose: posing.set,\n unpose: posing.clear,\n until: parts.expectations(named, subjected, matching).until,\n text: texts.read,\n record: recorder.start,\n stopRecord: recorder.stop,\n changes: parts.changes(named, walked, placing, kept, seeing, marking, recorder).read,\n ready: readiness.wait,\n settle: readiness.settle,\n viewport: read.viewport\n }\n };\n };\n //#endregion\n //#region src/internal/page/overlay.inpage.ts\n const overlay = (names) => {\n const svgNamespace = \"http://www.w3.org/2000/svg\";\n let host;\n let root;\n const mount = () => {\n if (host === void 0 || root === void 0) {\n host = document.createElement(\"div\");\n root = host.attachShadow({ mode: \"closed\" });\n names.adopt(host);\n const sheet = new CSSStyleSheet();\n sheet.replaceSync(\"svg { position: absolute; left: 0; top: 0; width: 100%; height: 100%; overflow: visible }\");\n root.adoptedStyleSheets = [sheet];\n }\n const zoom = Number(getComputedStyle(document.documentElement).zoom) || 1;\n for (const [name, value] of Object.entries({\n all: \"initial\",\n display: \"block\",\n position: \"fixed\",\n left: \"0\",\n top: \"0\",\n width: \"100vw\",\n height: \"100vh\",\n \"pointer-events\": \"none\",\n \"z-index\": \"2147483647\",\n contain: \"strict\",\n zoom: String(1 / zoom)\n })) host.style.setProperty(name, value, \"important\");\n if (host.parentNode !== document.documentElement) document.documentElement.append(host);\n return root;\n };\n const boxes = (drawing) => Array.from(drawing.children).slice(0, 32).map((part) => {\n const { x, y, width, height } = part.getBoundingClientRect();\n return {\n x,\n y,\n width,\n height\n };\n }).filter((box) => box.width > 0 && box.height > 0);\n /**\n * Draw an SVG document over the viewport, in place of what was drawn, or take the layer away\n * with null. Says where the drawing's parts are. Its scripts and handlers are dropped.\n */\n const draw = (markup) => {\n if (markup === null) {\n host?.remove();\n return [];\n }\n const parsed = new DOMParser().parseFromString(markup, \"image/svg+xml\");\n const drawing = parsed.documentElement;\n if (parsed.getElementsByTagName(\"parsererror\").length > 0 || drawing.namespaceURI !== svgNamespace || drawing.localName !== \"svg\") throw new Error(\"the overlay's markup is not an SVG document\");\n for (const script of Array.from(drawing.getElementsByTagName(\"script\"))) script.remove();\n for (const element of [drawing, ...Array.from(drawing.querySelectorAll(\"*\"))]) for (const attribute of Array.from(element.attributes)) if (/^on/i.test(attribute.name)) element.removeAttribute(attribute.name);\n const shown = document.importNode(drawing, true);\n mount().replaceChildren(shown);\n return boxes(shown);\n };\n return {\n draw,\n mount\n };\n };\n //#endregion\n //#region src/internal/page/pose.inpage.ts\n const pose = (names) => {\n const posed = /* @__PURE__ */ new Map();\n const isHtml = (element) => \"offsetWidth\" in element;\n const laidOut = (element, applied) => {\n const style = getComputedStyle(element);\n const [cx = 0, cy = 0] = style.transformOrigin.split(\" \").map(Number.parseFloat);\n const own = style.transform === \"none\" ? new DOMMatrix() : new DOMMatrix(style.transform);\n const whole = applied === void 0 ? own : new DOMMatrix().translate(applied.x, applied.y).rotate(applied.rotate).scale(applied.sx, applied.sy).multiply(own);\n const drawn = element.getBoundingClientRect();\n const plain = whole.isIdentity;\n const width = plain ? drawn.width : element.offsetWidth;\n const height = plain ? drawn.height : element.offsetHeight;\n let left = Infinity;\n let top = Infinity;\n for (const [x, y] of [\n [0, 0],\n [width, 0],\n [0, height],\n [width, height]\n ]) {\n const corner = whole.transformPoint({\n x: x - cx,\n y: y - cy\n });\n left = Math.min(left, corner.x + cx);\n top = Math.min(top, corner.y + cy);\n }\n const origin = {\n x: drawn.x - left + cx,\n y: drawn.y - top + cy\n };\n const middle = own.transformPoint({\n x: width / 2 - cx,\n y: height / 2 - cy\n });\n return {\n origin,\n middle: {\n x: origin.x + middle.x,\n y: origin.y + middle.y\n }\n };\n };\n const apply = (element, request) => {\n const known = posed.get(element);\n const { origin, middle } = laidOut(element, known?.applied);\n const about = request.origin ?? middle;\n const away = {\n x: about.x - origin.x,\n y: about.y - origin.y\n };\n const turned = new DOMMatrix().rotate(request.rotate).scale(request.sx, request.sy).transformPoint(away);\n const applied = {\n x: request.dx + away.x - turned.x,\n y: request.dy + away.y - turned.y,\n rotate: request.rotate,\n sx: request.sx,\n sy: request.sy\n };\n const frame = {\n translate: `${applied.x}px ${applied.y}px`,\n rotate: `${applied.rotate}deg`,\n scale: `${applied.sx} ${applied.sy}`\n };\n if (known === void 0) {\n const effect = new KeyframeEffect(element, [frame, frame], {\n duration: Infinity,\n fill: \"both\"\n });\n const animation = new Animation(effect, document.timeline);\n animation.play();\n posed.set(element, {\n animation,\n effect,\n applied\n });\n } else {\n known.effect.setKeyframes([frame, frame]);\n known.applied = applied;\n }\n };\n const takeOff = (element) => {\n posed.get(element)?.animation.cancel();\n posed.delete(element);\n };\n /**\n * The elements `requests` name, or the first that names none in the current document, or one\n * that is not an HTML element; then, to apply them, a function that poses them and takes poses\n * off every other element.\n */\n const prepare = (requests) => {\n const elements = [];\n for (const request of requests) {\n const element = names.lookup(request.ref);\n const { dx, dy, sx, sy, rotate, origin } = request;\n if (element === void 0) return { stale: request.ref };\n if (!isHtml(element)) return { invalid: `${request.ref} is not an HTML element` };\n if (![\n dx,\n dy,\n sx,\n sy,\n rotate,\n origin?.x ?? 0,\n origin?.y ?? 0\n ].every(Number.isFinite)) return { invalid: `${request.ref}'s pose is not finite numbers` };\n elements.push(element);\n }\n return { apply: () => {\n for (const element of Array.from(posed.keys())) if (!elements.includes(element)) takeOff(element);\n requests.forEach((request, index) => {\n const element = elements[index];\n if (element !== void 0) apply(element, request);\n });\n } };\n };\n const set = (requests) => {\n const prepared = prepare(requests);\n if (\"apply\" in prepared) {\n prepared.apply();\n return {};\n }\n return prepared;\n };\n const clear = () => {\n for (const element of Array.from(posed.keys())) takeOff(element);\n };\n return {\n prepare,\n set,\n clear\n };\n };\n //#endregion\n //#region src/internal/page/time.inpage.ts\n const time = (overlaid, posing) => {\n const step = (request) => {\n const posed = request.poses === void 0 ? void 0 : posing.prepare(request.poses);\n if (posed !== void 0 && !(\"apply\" in posed)) return {\n told: false,\n drawn: null,\n scroll: {\n x: scrollX,\n y: scrollY\n },\n ...posed\n };\n if (request.scroll !== null) scrollTo({\n left: scrollX,\n top: request.scroll,\n behavior: \"instant\"\n });\n const detail = {\n op: request.op,\n by: request.by\n };\n const told = !document.dispatchEvent(new CustomEvent(request.clock, {\n detail,\n cancelable: true\n }));\n posed?.apply();\n return {\n told,\n drawn: request.markup === void 0 ? null : overlaid.draw(request.markup),\n scroll: {\n x: scrollX,\n y: scrollY\n }\n };\n };\n return { step };\n };\n //#endregion\n //#region src/internal/page/bridge.ts\n const parts = {\n compose,\n elements,\n names,\n walk,\n match,\n context,\n subjects,\n states,\n expectations,\n text,\n layout,\n controls,\n fold,\n history,\n sight,\n marks,\n record,\n changes,\n ready,\n outline,\n targets,\n evidence,\n guard,\n edit,\n overlay,\n pose,\n time,\n addresses\n };\n function install(parts) {\n const source = install.toString() + Object.entries(parts).map(([name, factory]) => name + factory.toString()).join(\"\");\n let version = 2166136261;\n for (let index = 0; index < source.length; index++) version = Math.imul(version ^ source.charCodeAt(index), 16777619);\n version >>>= 0;\n const installed = globalThis.__effectBrowser;\n if (installed !== void 0 && installed.version === version) return installed;\n installed?.dispose?.();\n const { named, walked, placing, overlaid, posing, reads } = parts.compose(parts, installed?.refs?.next);\n const located = parts.targets(named, walked, placing);\n const guarded = parts.guard(named, located, parts.evidence(named, placing));\n const edited = parts.edit(named, guarded, placing);\n const api = {\n ...reads,\n version,\n dispose: reads.stopRecord,\n step: parts.time(overlaid, posing).step,\n point: located.point,\n scrollPlan: located.scrollPlan,\n screenSize: () => ({\n width: screen.width,\n height: screen.height,\n ratio: devicePixelRatio\n }),\n prepareInput: guarded.prepareInput,\n validateInput: guarded.validateInput,\n typeable: edited.typeable,\n focus: edited.focus,\n focusOn: edited.focusOn,\n select: edited.select\n };\n globalThis.__effectBrowser = api;\n return api;\n }\n //#endregion\n return install(parts);\n})();\n\nreturn pageScript;})()";
|
|
632
496
|
/**
|
|
633
|
-
* What
|
|
634
|
-
*
|
|
497
|
+
* What new documents run before their own scripts: the page clock under its event name, first, so
|
|
498
|
+
* a caller's script that keeps a timer keeps the clock's, and then the caller's scripts, each
|
|
499
|
+
* everywhere or as a block where its `match` allows.
|
|
635
500
|
*/
|
|
636
|
-
const
|
|
637
|
-
until: Schema.Finite,
|
|
638
|
-
from: Schema.Finite,
|
|
639
|
-
dropped: Schema.Int,
|
|
640
|
-
records: Schema.Array(Change)
|
|
641
|
-
});
|
|
642
|
-
//#endregion
|
|
643
|
-
//#region src/internal/timeline/fold.inpage.ts
|
|
644
|
-
const fold = () => {
|
|
645
|
-
/** The one number some words show, such as 61240 in "$61,240"; none for none or several. */
|
|
646
|
-
const number = (words) => {
|
|
647
|
-
const found = words.match(/[-+−]?\d[\d,]*(?:\.\d+)?/g);
|
|
648
|
-
const value = Number(found?.length === 1 ? found[0]?.replaceAll(",", "").replace("−", "-") : "");
|
|
649
|
-
return found?.length === 1 && Number.isFinite(value) ? [value] : [];
|
|
650
|
-
};
|
|
651
|
-
/** A track's changes after `since`, up to `until`, if one was seen in view. */
|
|
652
|
-
const over = (track, since, until) => {
|
|
653
|
-
const inside = track.samples.filter((sample) => sample.at > since && sample.at <= until);
|
|
654
|
-
const first = inside[0];
|
|
655
|
-
const last = inside.at(-1);
|
|
656
|
-
if (first === void 0 || last === void 0 || !inside.some((sample) => sample.seen === true)) return void 0;
|
|
657
|
-
const prior = track.samples[track.samples.indexOf(first) - 1];
|
|
658
|
-
const lost = track.known <= since ? track.known : void 0;
|
|
659
|
-
const start = prior === void 0 ? lost === void 0 ? void 0 : track.initial : prior.shown;
|
|
660
|
-
const words = [start, ...inside.map((sample) => sample.shown)].filter((each) => typeof each === "string");
|
|
661
|
-
const numbers = words.flatMap(number);
|
|
662
|
-
const ranged = inside.length > 1 && numbers.length === words.length;
|
|
663
|
-
const kind = track.kind !== "content" ? track.kind : last.shown === null ? start === null ? "brief" : "disappeared" : start === null ? "appeared" : "text";
|
|
664
|
-
return {
|
|
665
|
-
track,
|
|
666
|
-
kind,
|
|
667
|
-
startedAt: first.at,
|
|
668
|
-
at: last.at,
|
|
669
|
-
before: kind === "disappeared" ? words.at(-1) : start ?? void 0,
|
|
670
|
-
after: kind === "brief" ? words.at(-1) : last.shown ?? void 0,
|
|
671
|
-
count: inside.length,
|
|
672
|
-
lowest: ranged ? words[numbers.indexOf(Math.min(...numbers))] : void 0,
|
|
673
|
-
highest: ranged ? words[numbers.indexOf(Math.max(...numbers))] : void 0,
|
|
674
|
-
earlier: prior?.at ?? (lost === Number.NEGATIVE_INFINITY ? void 0 : lost)
|
|
675
|
-
};
|
|
676
|
-
};
|
|
677
|
-
/**
|
|
678
|
-
* How readily a track gives way when the record is full: one that holds no change first, then
|
|
679
|
-
* one that keeps changing, one never seen in view and one that has gone; news never does.
|
|
680
|
-
*/
|
|
681
|
-
const rank = ({ samples: [only, ...more] }) => only === void 0 ? 4 : more.length > 0 ? 3 : only.seen === false ? 2 : only.shown === null ? 1 : 0;
|
|
682
|
-
return {
|
|
683
|
-
number,
|
|
684
|
-
over,
|
|
685
|
-
rank
|
|
686
|
-
};
|
|
687
|
-
};
|
|
688
|
-
/** The expression that installs the script and evaluates to its API; packaging freezes it. */
|
|
689
|
-
const installSource = "(() => {var pageScript = (function() {\n //#region src/Matching.ts\n const match = () => {\n /**\n * How names, text and context compare: one Unicode form, without invisible format characters,\n * spaces collapsed, and case folded upper first, so that \"ß\" and \"SS\" read the same.\n */\n const normalize = (value) => value.normalize(\"NFKC\").replace(/\\p{Cf}/gu, \"\").replace(/\\s+/g, \" \").trim().toUpperCase().toLowerCase();\n /** A string that reads the same, or, unless `whole`, appears within; or a pattern found within. */\n const rule = (wanted, whole) => {\n if (typeof wanted !== \"string\") {\n const found = new RegExp(wanted.source, wanted.flags.replace(/[gy]/g, \"\"));\n return (value) => found.test(value.replace(/\\s+/g, \" \").trim());\n }\n const target = normalize(wanted);\n return whole ? (value) => normalize(value) === target : (value) => normalize(value).includes(target);\n };\n /** Whether a value's words appear, whole and in order, among a text's: \"BTC\" not in \"WBTC\". */\n const holds = (text, value) => ` ${normalize(text)} `.includes(` ${normalize(value)} `);\n /** Whether a candidate meets every rule a query gives; a rule left out always holds. */\n const compile = (request) => {\n const role = request.role === null ? null : normalize(request.role);\n const name = request.name === null ? null : rule(request.name, true);\n const text = request.text === null ? null : rule(request.text, false);\n const { near } = request;\n return (candidate) => {\n if (role !== null && normalize(candidate.role ?? \"\") !== role) return false;\n if (text !== null && !text(candidate.text())) return false;\n if (name !== null && !name(candidate.name())) return false;\n if (near === null) return true;\n const { row, column, label, heading } = candidate.context();\n return [\n row,\n column,\n label,\n heading\n ].some((value) => value !== void 0 && holds(value, near));\n };\n };\n /** A comparison token for ordered observations, without retaining their text. */\n const mark = (observations) => {\n let hash = 2166136261;\n for (const shown of observations) for (let index = 0; index < shown.length; index++) hash = Math.imul(hash ^ shown.charCodeAt(index), 16777619);\n return `${observations.length}:${(hash >>> 0).toString(16)}`;\n };\n return {\n compile,\n holds,\n normalize,\n mark\n };\n };\n //#endregion\n //#region src/Url.ts\n const addresses = () => {\n const withheld = \"••••••••\";\n const credential = /token|secret|passw|passcode|passphrase|signature|credential|assertion|verifier|bearer|jwt|hmac|apikey|accesskey|privatekey|sess(?:ion)?id|saml(?:response|art)|(?:sig|otp)$|(?:auth|api|access|private|secret|signing|client|encryption|licen[cs]e|session|master|app|device|verification|verify|confirmation|confirm|activation|activate|reset|recovery|login|security|magic|onetime|mfa|2fa|sms|email|otp|oob)(?:code|key)$|^(?:auth|authorization|pwd|pass)$/;\n const ambiguous = /^(?:code|key|session|sid|ticket)$/;\n const secret = (name, value) => {\n const bare = name.toLowerCase().replace(/[^a-z0-9]/g, \"\");\n return value !== \"\" && (credential.test(bare) || ambiguous.test(bare) && value.length >= 16 && /\\d/.test(value) && /[a-z]/i.test(value));\n };\n const masked = (parameters, separator) => parameters.split(separator).map((parameter) => {\n const [name = \"\", value = \"\"] = [...new URLSearchParams(parameter)][0] ?? [];\n return secret(name, value) ? `${parameter.slice(0, parameter.indexOf(\"=\") + 1)}${withheld}` : parameter;\n }).join(separator);\n /**\n * `url` as the library reports it: without userinfo, and with each credential's value withheld,\n * so the rest keeps its identity, such as a chart's `?ticker=ETH`. An address without a host,\n * such as `data:` or `about:blank`, is content or a fixed name, and stays as it is.\n */\n const redact = (url) => {\n const parsed = URL.parse(url);\n if (parsed === null || parsed.host === \"\") return url;\n parsed.username = \"\";\n parsed.password = \"\";\n parsed.pathname = masked(parsed.pathname, \";\");\n parsed.search = masked(parsed.search.slice(1), \"&\");\n if (parsed.hash.includes(\"=\")) {\n const fragment = parsed.hash.slice(1);\n const question = fragment.indexOf(\"?\");\n const start = question >= 0 && question < fragment.indexOf(\"=\") ? question + 1 : 0;\n parsed.hash = fragment.slice(0, start) + masked(fragment.slice(start), \"&\");\n }\n return parsed.href.replaceAll(encodeURIComponent(withheld), withheld);\n };\n return {\n withheld,\n redact\n };\n };\n //#endregion\n //#region src/internal/input/edit.inpage.ts\n const edit = (names, guard, placing) => {\n const { activeElement, clean, describe, inCurrentDocument, isDisabled, isHtml, isInput, isSecret, isSelect, isTextArea, lookup, nameOf, roleOf } = names;\n const { textEntry, typingRefusal } = guard;\n /** Whether text may be typed into a ref or focus, and, for a `secret`, only into a secret field. */\n const typeable = (ref, secret) => {\n const element = ref === null ? activeElement() : lookup(ref);\n if (element === void 0) return {\n error: \"stale\",\n detail: `${ref ?? \"the focused element\"} is not on the page any more`\n };\n const refusal = element === null ? secret ? \"nothing has focus to type a secret into\" : void 0 : typingRefusal(element, ref !== null) ?? (secret && !isSecret(element) ? `${describe(element)} is not a secret field` : void 0);\n if (refusal !== void 0) return {\n error: \"untypeable\",\n detail: refusal\n };\n if (element === null || ref !== null || !textEntry(element)) return {\n ok: true,\n secret: element !== null && isSecret(element)\n };\n const role = roleOf(element);\n const tag = element.tagName.toLowerCase();\n return {\n ok: true,\n secret: isSecret(element),\n subject: {\n role,\n name: nameOf(element, role),\n tag,\n context: placing.contextOf(element)\n }\n };\n };\n /**\n * The focused field, when it is a text field named `name`: one a page put in place of a field\n * just pressed and gave focus to, as a typeahead does.\n */\n const replacement = (name) => {\n const active = activeElement();\n return active !== null && textEntry(active) && inCurrentDocument(active) && nameOf(active, roleOf(active)) === name ? active : void 0;\n };\n /**\n * Focus a field to type into. `follow` is the field's name when the action pressed it first: a\n * page may answer the press with another field of that name in its place, focused, and the keys\n * follow focus there, as a person's would.\n */\n const focus = (ref, replace, follow) => {\n const element = lookup(ref) ?? (follow === null ? void 0 : replacement(follow));\n if (element === void 0) return {\n error: `${ref} is not on the page any more`,\n stale: true\n };\n if (isDisabled(element)) return { error: `${ref} is disabled` };\n if (!textEntry(element)) return { error: `${ref} is ${describe(element)}, not a text field` };\n if (isHtml(element)) element.focus();\n if (replace) {\n if (isInput(element) || isTextArea(element)) element.select();\n else element.ownerDocument.getSelection()?.selectAllChildren(element);\n }\n return {\n ok: true,\n detail: describe(element),\n secret: isSecret(element)\n };\n };\n /** Focus any element that takes focus, such as a link or a button, for a key pressed on it. */\n const focusOn = (ref) => {\n const element = lookup(ref);\n if (element === void 0) return {\n error: `${ref} is not on the page any more`,\n stale: true\n };\n if (isDisabled(element)) return { error: `${ref} is disabled` };\n if (isHtml(element)) element.focus();\n return activeElement() === element ? {\n ok: true,\n detail: describe(element)\n } : { error: `${ref} is ${describe(element)}, which does not take focus` };\n };\n const select = (ref, values) => {\n const element = lookup(ref);\n if (element === void 0) return {\n error: `${ref} is not on the page any more`,\n stale: true\n };\n if (!isSelect(element)) return { error: `${ref} is ${describe(element)}, not a <select>; click it and pick an option` };\n const wanted = values.map((value) => value.trim().toLowerCase());\n const options = Array.from(element.options);\n const chosen = options.filter((option) => wanted.includes(option.value.toLowerCase()) || wanted.includes(clean(option.text).toLowerCase()));\n if (chosen.length === 0) return { error: `no option matches; the options are ${options.map((option) => JSON.stringify(clean(option.text, 40))).join(\", \")}` };\n for (const option of options) option.selected = chosen.includes(option);\n element.dispatchEvent(new Event(\"input\", { bubbles: true }));\n element.dispatchEvent(new Event(\"change\", { bubbles: true }));\n return {\n ok: true,\n detail: chosen.map((option) => clean(option.text, 40)).join(\", \")\n };\n };\n return {\n focus,\n focusOn,\n select,\n typeable\n };\n };\n //#endregion\n //#region src/internal/input/evidence.inpage.ts\n const evidence = (names, placing) => {\n const { clean, isDocument, isInput, isSelect, isTextArea, nameOf, parentOf, roleOf, textOf } = names;\n const { groups, headingBefore, textBeside, treeOf } = placing;\n /** A field a submission would send. */\n const isField = (element) => (isInput(element) && ![\n \"button\",\n \"submit\",\n \"reset\",\n \"image\"\n ].includes(element.type) || isSelect(element) || isTextArea(element)) && !element.matches(\":disabled\");\n const isFilled = (field) => isInput(field) && (field.type === \"checkbox\" || field.type === \"radio\") ? field.checked : isInput(field) && field.type === \"file\" ? (field.files?.length ?? 0) > 0 : field.value !== \"\";\n const dialogOf = (element) => {\n for (let node = element; node !== null; node = parentOf(node)) if (node.tagName === \"DIALOG\" || /^(?:alert)?dialog$/.test(node.getAttribute(\"role\") ?? \"\")) return node;\n };\n /** What the page says about an input's first target, for a judge. Never a field's value. */\n const evidenceOf = (element, form, method, action) => {\n const name = nameOf(element, roleOf(element));\n const ids = element.getAttribute(\"aria-describedby\");\n const description = clean(ids === null ? element.getAttribute(\"aria-description\") ?? element.getAttribute(\"title\") : ids.split(/\\s+/).map((id) => element.ownerDocument.getElementById(id)?.textContent ?? \"\").join(\" \"), 120);\n const dialog = dialogOf(element);\n const title = dialog?.querySelector(\"h1,h2,h3,h4,h5,h6,[role=heading]\");\n const dialogName = dialog === void 0 ? \"\" : clean(nameOf(dialog, \"dialog\"), 120) || (title === null || title === void 0 ? \"\" : clean(textOf(title), 120));\n const root = element.getRootNode();\n const top = isDocument(root) ? root.body ?? root : root;\n const inTree = element.closest(\"dialog,[role=dialog],[role=alertdialog]\");\n let nearby = \"\";\n for (const scope of /* @__PURE__ */ new Set([\n element.closest(groups),\n inTree,\n top\n ])) if (scope !== null && nearby === \"\") nearby = textBeside(element, scope, true) || textBeside(element, scope, false);\n const heading = headingBefore(element, treeOf(element));\n const fields = form === null ? [] : Array.from(form.elements).filter(isField).slice(0, 16).map((field) => {\n const autocomplete = clean(field.getAttribute(\"autocomplete\"), 40);\n return {\n type: isInput(field) ? field.type : field.tagName.toLowerCase(),\n name: clean(isInput(field) && field.type === \"hidden\" ? field.getAttribute(\"name\") : nameOf(field, roleOf(field)), 40),\n ...autocomplete === \"\" ? {} : { autocomplete },\n filled: isFilled(field)\n };\n });\n return {\n title: clean(document.title, 120),\n ...description === \"\" || description === name ? {} : { description },\n ...dialogName === \"\" ? {} : { dialog: dialogName },\n ...heading === void 0 ? {} : { heading },\n ...nearby === \"\" ? {} : { nearby },\n ...form === null ? {} : { form: {\n method: method ?? form.method,\n action: action ?? form.action,\n fields\n } }\n };\n };\n return {\n evidenceOf,\n isField,\n isFilled\n };\n };\n //#endregion\n //#region src/internal/input/guard.inpage.ts\n const guard = (names, targets, evidence) => {\n const { activeElement, textEntry, clean, describe, inCurrentDocument, interactiveRoles, isButton, isDisabled, isHtml, isInput, isLabel, isRoot, isSecret, isSelect, isTextArea, lookup, parentOf, refFor, roleOf } = names;\n const { controlOf, details, hitAt, hrefAttribute, linkOf, receives, within } = targets;\n const { evidenceOf, isField, isFilled } = evidence;\n const nativeActivation = (element) => hrefAttribute(element) !== null || element.tagName === \"BUTTON\" || element.tagName === \"SUMMARY\" || isInput(element) && element.type !== \"hidden\";\n /**\n * The element whose activation behaviour a click or key on `element` runs, as the browser\n * resolves it along the composed path: a link, button, input, summary or a label's control.\n */\n const activationTarget = (element) => {\n for (let node = element; node !== null; node = parentOf(node)) {\n if (nativeActivation(node)) return node;\n if (isLabel(node) && node.control !== null) return node.control;\n }\n };\n /**\n * A control between a press's hit and the approved target that is not the target's own\n * activation, such as a link or button a hover handler nested into it. The approval inspected\n * the target, so that control would act unapproved.\n */\n const nestedControl = (element, hit) => {\n if (!within(element, hit)) return void 0;\n const own = activationTarget(element);\n for (let node = hit; node !== null && node !== element; node = parentOf(node) ?? node.ownerDocument.defaultView?.frameElement ?? null) if (node !== own && (nativeActivation(node) || isSelect(node) || isTextArea(node) || isLabel(node) && node.control !== null && node.control !== own || activatingRoles.has(roleOf(node) ?? \"\"))) return node;\n };\n const activatingRoles = /* @__PURE__ */ new Set([\n \"button\",\n \"link\",\n \"checkbox\",\n \"radio\",\n \"switch\",\n \"tab\",\n \"menuitem\",\n \"menuitemcheckbox\",\n \"menuitemradio\",\n \"option\",\n \"treeitem\"\n ]);\n const typingRefusal = (element, explicit) => textEntry(element) ? void 0 : explicit ? `${describe(element)} is not a text field` : activationTarget(element) !== void 0 || isSelect(element) || activatingRoles.has(roleOf(element) ?? \"\") ? `focus is on ${describe(element)}, which typed text could activate or change; type into a text field by ref, or use press for keys` : void 0;\n const isSubmitter = (element) => isButton(element) && element.type === \"submit\" || isInput(element) && (element.type === \"submit\" || element.type === \"image\");\n const defaultSubmitter = (form) => {\n const root = form.getRootNode();\n return isRoot(root) ? Array.from(root.querySelectorAll(\"button,input\")).find((candidate) => isSubmitter(candidate) && candidate.form === form) : void 0;\n };\n const purpose = (control, form) => [\n control.getAttribute(\"id\"),\n control.getAttribute(\"name\"),\n control.getAttribute(\"inputmode\"),\n control.getAttribute(\"autocomplete\"),\n control.getAttribute(\"aria-label\"),\n form?.getAttribute(\"id\"),\n form?.getAttribute(\"name\"),\n form?.getAttribute(\"aria-label\")\n ];\n const boundUrl = (url) => {\n const hash = url.indexOf(\"#\");\n return hash === -1 || /^#[/!]/.test(url.slice(hash)) ? url : url.slice(0, hash);\n };\n const inspectInput = (element, plan) => {\n const metadata = details(element, element, 0, 0);\n const control = activationTarget(element) ?? element;\n const form = isInput(control) || isButton(control) || isTextArea(control) || isSelect(control) ? control.form : null;\n const key = plan.keys === null ? void 0 : /(?:^|\\+)(\\+|[^+]+)$/.exec(plan.keys)?.[1];\n const enter = key === \"Enter\";\n const activation = plan.action === \"click\" || plan.action === \"press\" && (enter || key === \"Space\");\n const fieldEnter = isInput(control) && ![\n \"button\",\n \"reset\",\n \"submit\",\n \"image\",\n \"file\",\n \"color\",\n \"hidden\"\n ].includes(control.type) && (plan.action === \"press\" && enter || plan.action === \"type\" && plan.submit);\n const submits = form !== null && (activation && isSubmitter(control) || fieldEnter);\n const submitter = isSubmitter(control) ? control : form === null ? void 0 : defaultSubmitter(form);\n const formValue = (attribute, property) => form === null ? void 0 : submitter?.hasAttribute(`form${attribute}`) === true ? submitter[property] : form[attribute];\n const formDestination = formValue(\"action\", \"formAction\");\n const formMethod = formValue(\"method\", \"formMethod\");\n const formTarget = formValue(\"target\", \"formTarget\");\n const link = linkOf(element);\n const href = link === void 0 ? null : hrefAttribute(link);\n const sends = submits && formMethod !== \"dialog\";\n const destination = sends ? formDestination : activation ? metadata.href : void 0;\n const acts = plan.action !== \"hover\" && plan.action !== \"scroll\";\n const builtIn = sends || href !== null && !/^\\s*(?:#\\s*|javascript:[^]*)$/i.test(href) || isInput(control) && ![\n \"button\",\n \"submit\",\n \"image\",\n \"reset\"\n ].includes(control.type) || (isInput(control) || isButton(control)) && control.type === \"reset\" && form !== null || control.tagName === \"SUMMARY\" || control.closest(\"select\") !== null || textEntry(control);\n const facts = [];\n if (sends) facts.push(\"form-submit\");\n if (activation && link?.hasAttribute(\"download\") === true) facts.push(\"download\");\n if (activation && isInput(control) && control.type === \"file\") facts.push(\"upload\");\n if (plan.action === \"type\" && isSecret(control) || sends && form !== null && Array.from(form.elements).some((field) => isField(field) && isSecret(field) && isFilled(field))) facts.push(\"secret\");\n if (activation && !builtIn) facts.push(\"scripted\");\n if (acts && (metadata.role === \"canvas\" || metadata.role === \"iframe\" || metadata.name === \"\")) facts.push(\"opaque\");\n const role = metadata.role;\n const boundName = role !== null && (interactiveRoles.has(role) || role === \"canvas\" || role === \"iframe\") && !(isHtml(element) && element.isContentEditable) ? metadata.name : null;\n const fingerprint = JSON.stringify([\n purpose(control, form),\n element.tagName,\n element.id,\n role,\n boundName,\n metadata.href,\n control === element ? null : refFor(control),\n isInput(control) || isButton(control) ? control.type : control.tagName,\n isDisabled(control),\n control.getAttribute(\"readonly\"),\n control.getAttribute(\"aria-readonly\"),\n isHtml(control) && control.isContentEditable,\n control.getAttribute(\"name\"),\n control.getAttribute(\"accept\"),\n control.hasAttribute(\"multiple\"),\n link?.getAttribute(\"download\"),\n form === null ? null : refFor(form),\n form === null ? null : boundUrl(form.action),\n form?.method,\n form?.target,\n submitter === void 0 ? null : refFor(submitter),\n formDestination === void 0 ? void 0 : boundUrl(formDestination),\n formMethod,\n formTarget,\n submitter?.formNoValidate,\n form?.noValidate\n ]);\n return {\n inspected: {\n ref: refFor(element),\n element: metadata.element,\n role: metadata.role,\n name: metadata.name,\n cursor: metadata.cursor,\n ...metadata.href === void 0 ? {} : { href: metadata.href },\n secret: isSecret(control),\n fingerprint\n },\n facts,\n destination,\n explain: () => evidenceOf(element, form, formMethod, formDestination)\n };\n };\n const inspect = (plan) => {\n const targets = [];\n const facts = /* @__PURE__ */ new Set();\n let destination = plan.destination ?? void 0;\n let explain = () => ({ title: clean(document.title, 120) });\n for (const [index, target] of plan.targets.entries()) {\n let element;\n if (target === null) element = activeElement();\n else if (typeof target === \"string\") {\n element = lookup(target);\n if (element === void 0) return {\n error: \"stale\",\n detail: target + \" is not on the page any more\",\n index\n };\n } else {\n if (!Number.isFinite(target.x) || !Number.isFinite(target.y) || target.x < 0 || target.y < 0 || target.x >= window.innerWidth || target.y >= window.innerHeight) return {\n error: \"outside\",\n detail: \"the point is outside the viewport\"\n };\n const hit = hitAt(document, target.x, target.y);\n element = hit === null ? null : controlOf(hit);\n if (element === null) return {\n error: \"offscreen\",\n detail: \"nothing is painted at the point\"\n };\n }\n if (element === null) {\n targets.push(null);\n continue;\n }\n if (!inCurrentDocument(element)) return {\n error: \"stale\",\n detail: \"the input target belongs to a replaced document\",\n index\n };\n const refusal = plan.action === \"type\" ? typingRefusal(element, target !== null) : void 0;\n if (refusal !== void 0) return {\n error: \"untypeable\",\n detail: refusal\n };\n const inspected = inspectInput(element, plan);\n if (index === 0) explain = inspected.explain;\n targets.push(inspected.inspected);\n for (const fact of inspected.facts) facts.add(fact);\n destination ??= inspected.destination;\n if (inspected.destination !== void 0) try {\n if (new URL(inspected.destination, location.href).origin !== location.origin) facts.add(\"cross-origin\");\n } catch {\n return {\n error: \"outside\",\n detail: \"the input destination is not a valid URL\"\n };\n }\n }\n if (destination !== void 0) try {\n destination = new URL(destination, location.href).href;\n if (new URL(destination).origin !== location.origin) facts.add(\"cross-origin\");\n } catch {\n return {\n error: \"outside\",\n detail: \"the input destination is not a valid URL\"\n };\n }\n return {\n url: boundUrl(location.href),\n targets,\n facts: [...facts],\n ...destination === void 0 ? {} : { destination },\n explain\n };\n };\n const prepareInput = (plan) => {\n const inspected = inspect(plan);\n if (\"error\" in inspected) return inspected;\n const { explain, ...prepared } = inspected;\n return {\n ...prepared,\n evidence: explain()\n };\n };\n const bindings = (targets) => targets.map((target) => target === null ? null : [target.ref, target.fingerprint]);\n const validate = (plan, prepared, options) => {\n const current = inspect(plan);\n if (\"error\" in current) return current.error === \"stale\" ? current : {\n error: \"changed\",\n detail: current.detail\n };\n if (current.url !== prepared.url || (current.destination === void 0 || prepared.destination === void 0 ? current.destination !== prepared.destination : boundUrl(current.destination) !== boundUrl(prepared.destination)) || JSON.stringify(current.facts) !== JSON.stringify(prepared.facts) || JSON.stringify(bindings(current.targets)) !== JSON.stringify(bindings(prepared.targets))) return {\n error: \"changed\",\n detail: \"the page or input target changed while the policy was deciding\"\n };\n if (options.focused === true) {\n const active = activeElement();\n const expected = prepared.targets[0];\n if (active === null || expected === null || expected === void 0 || refFor(active) !== expected.ref) return {\n error: \"changed\",\n detail: \"focus moved away from the approved element\"\n };\n }\n for (const press of options.presses ?? []) {\n const expected = prepared.targets[press.index];\n const element = expected === null || expected === void 0 ? void 0 : lookup(expected.ref);\n const hit = hitAt(document, press.x, press.y);\n if (element === void 0 || hit === null || !receives(element, hit)) return {\n error: \"changed\",\n detail: `the approved target is no longer under the pointer at (${press.x}, ${press.y})`\n };\n const nested = nestedControl(element, hit);\n if (nested !== void 0) return {\n error: \"changed\",\n detail: `${describe(nested)} inside the approved target would receive the press at (${press.x}, ${press.y})`\n };\n }\n return { ok: true };\n };\n const validateInput = (plan, prepared, options = {}) => {\n if ((options.presses ?? []).length === 0) return validate(plan, prepared, options);\n const { promise, resolve } = Promise.withResolvers();\n if (document.visibilityState === \"hidden\") resolve();\n else requestAnimationFrame(() => requestAnimationFrame(() => resolve()));\n return promise.then(() => validate(plan, prepared, options));\n };\n return {\n prepareInput,\n textEntry,\n typingRefusal,\n validateInput\n };\n };\n //#endregion\n //#region src/internal/input/targets.inpage.ts\n const targets = (names, walked, placing) => {\n const { describe, isDisabled, lookup, nameOf, parentOf, roleOf } = names;\n const { boxOf, controlOf, hitAt } = walked;\n const { contextOf } = placing;\n /** Whether `node` is `ancestor` or inside it, across shadow roots and same-origin frames. */\n const within = (ancestor, node) => {\n for (let current = node; current !== null;) {\n if (current === ancestor) return true;\n current = parentOf(current) ?? current.ownerDocument.defaultView?.frameElement ?? null;\n }\n return false;\n };\n const receives = (element, hit) => within(element, hit) || within(hit, element);\n const hrefAttribute = (element) => element.localName === \"a\" || element.localName === \"area\" ? element.getAttribute(\"href\") ?? element.getAttributeNS(\"http://www.w3.org/1999/xlink\", \"href\") : null;\n const linkOf = (element) => {\n for (let node = element; node !== null; node = parentOf(node)) if (hrefAttribute(node) !== null) return node;\n };\n const details = (element, hit, x, y) => {\n const link = linkOf(element);\n let href;\n if (link !== void 0) try {\n href = new URL(hrefAttribute(link) ?? \"\", link.ownerDocument.baseURI).href;\n } catch {\n href = void 0;\n }\n const role = roleOf(element);\n const view = hit.ownerDocument.defaultView ?? window;\n return {\n x,\n y,\n element: describe(element),\n tag: element.tagName.toLowerCase(),\n role,\n name: nameOf(element, role),\n cursor: view.getComputedStyle(hit).cursor,\n ...href === void 0 ? {} : { href }\n };\n };\n const point = (target, scroll = true) => {\n if (typeof target !== \"string\") {\n const { x, y } = target;\n if (!Number.isFinite(x) || !Number.isFinite(y) || x < 0 || y < 0 || x >= window.innerWidth || y >= window.innerHeight) return {\n error: \"outside\",\n detail: `(${x}, ${y}) is outside the viewport`\n };\n const hit = hitAt(document, x, y);\n if (hit === null) return {\n error: \"offscreen\",\n detail: `nothing is painted at (${x}, ${y})`\n };\n const control = controlOf(hit);\n return {\n ...details(control, hit, x, y),\n context: contextOf(control),\n box: boxOf(control)\n };\n }\n const ref = target;\n const element = lookup(ref);\n if (element === void 0) return {\n error: \"stale\",\n detail: `${ref} is not on the page any more`\n };\n if (isDisabled(element)) return {\n error: \"disabled\",\n detail: `${ref} is disabled`\n };\n const rect = element.getBoundingClientRect();\n if (rect.width === 0 && rect.height === 0) return {\n error: \"hidden\",\n detail: `${ref} has no size on the page`\n };\n let box = {\n left: rect.left,\n top: rect.top,\n right: rect.right,\n bottom: rect.bottom\n };\n let visible = { ...box };\n let outside = false;\n for (let inner = element;;) {\n const view = inner.ownerDocument.defaultView ?? window;\n outside ||= box.left < 0 || box.top < 0 || box.right > view.innerWidth || box.bottom > view.innerHeight;\n visible = {\n left: Math.max(visible.left, 0),\n top: Math.max(visible.top, 0),\n right: Math.min(visible.right, view.innerWidth),\n bottom: Math.min(visible.bottom, view.innerHeight)\n };\n for (let ancestor = parentOf(inner); ancestor !== null; ancestor = parentOf(ancestor)) {\n const style = view.getComputedStyle(ancestor);\n const clip = ancestor.getBoundingClientRect();\n if (/(auto|scroll|hidden|clip)/.test(style.overflowX)) {\n visible.left = Math.max(visible.left, clip.left + ancestor.clientLeft);\n visible.right = Math.min(visible.right, clip.left + ancestor.clientLeft + ancestor.clientWidth);\n }\n if (/(auto|scroll|hidden|clip)/.test(style.overflowY)) {\n visible.top = Math.max(visible.top, clip.top + ancestor.clientTop);\n visible.bottom = Math.min(visible.bottom, clip.top + ancestor.clientTop + ancestor.clientHeight);\n }\n }\n const frame = view.frameElement;\n if (frame === null) break;\n const frameBox = frame.getBoundingClientRect();\n const dx = frameBox.left + frame.clientLeft;\n const dy = frameBox.top + frame.clientTop;\n box = {\n left: box.left + dx,\n top: box.top + dy,\n right: box.right + dx,\n bottom: box.bottom + dy\n };\n visible = {\n left: Math.max(visible.left + dx, dx),\n top: Math.max(visible.top + dy, dy),\n right: Math.min(visible.right + dx, dx + frame.clientWidth),\n bottom: Math.min(visible.bottom + dy, dy + frame.clientHeight)\n };\n inner = frame;\n }\n if (outside || visible.right <= visible.left || visible.bottom <= visible.top) {\n if (scroll) {\n element.scrollIntoView({\n block: \"center\",\n inline: \"center\",\n behavior: \"instant\"\n });\n return point(target, false);\n }\n return {\n error: \"offscreen\",\n detail: outside ? ref + \" is outside the viewport\" : `${ref} could not be scrolled into view`\n };\n }\n const x = (visible.left + visible.right) / 2;\n const y = (visible.top + visible.bottom) / 2;\n const hit = hitAt(document, x, y);\n if (hit !== null && !receives(element, hit)) return {\n error: \"covered\",\n detail: `${ref} is covered by ${describe(hit)}`\n };\n return {\n ...details(element, hit ?? element, Math.round(x), Math.round(y)),\n context: contextOf(element)\n };\n };\n const scrollPlan = (ref) => {\n const element = lookup(ref);\n if (element === void 0 || element.ownerDocument !== document) return null;\n const target = element.getBoundingClientRect();\n const centerX = (target.left + target.right) / 2;\n const centerY = (target.top + target.bottom) / 2;\n for (let ancestor = parentOf(element); ancestor !== null; ancestor = parentOf(ancestor)) {\n const style = window.getComputedStyle(ancestor);\n const horizontal = /^(auto|scroll)$/.test(style.overflowX) && ancestor.scrollWidth > ancestor.clientWidth;\n const vertical = /^(auto|scroll)$/.test(style.overflowY) && ancestor.scrollHeight > ancestor.clientHeight;\n if (!horizontal && !vertical) continue;\n const box = ancestor.getBoundingClientRect();\n const left = Math.max(0, box.left + ancestor.clientLeft);\n const top = Math.max(0, box.top + ancestor.clientTop);\n const right = Math.min(window.innerWidth, box.left + ancestor.clientLeft + ancestor.clientWidth);\n const bottom = Math.min(window.innerHeight, box.top + ancestor.clientTop + ancestor.clientHeight);\n if (right <= left || bottom <= top) continue;\n const x = (left + right) / 2;\n const y = (top + bottom) / 2;\n const dx = horizontal && (target.left < left || target.right > right) ? centerX - x : 0;\n const dy = vertical && (target.top < top || target.bottom > bottom) ? centerY - y : 0;\n if (dx === 0 && dy === 0) continue;\n const hit = hitAt(document, x, y);\n if (hit !== null && (hit === ancestor || ancestor.contains(hit))) return {\n x,\n y,\n dx,\n dy\n };\n }\n const dx = target.left < 0 || target.right > window.innerWidth ? centerX - window.innerWidth / 2 : 0;\n const dy = target.top < 0 || target.bottom > window.innerHeight ? centerY - window.innerHeight / 2 : 0;\n return dx === 0 && dy === 0 ? null : {\n x: window.innerWidth / 2,\n y: window.innerHeight / 2,\n dx,\n dy\n };\n };\n return {\n controlOf,\n details,\n hitAt,\n hrefAttribute,\n linkOf,\n point,\n receives,\n scrollPlan,\n within\n };\n };\n //#endregion\n //#region src/internal/reading/context.inpage.ts\n const context = (names, walked) => {\n const { clean, isButton, isDocument, isHtml, isInput, isRoot } = names;\n const { isSelect, isTextArea, roleOf, textOf } = names;\n const { visible } = walked;\n const known = () => ({\n headers: /* @__PURE__ */ new Map(),\n headings: /* @__PURE__ */ new Map()\n });\n const unspoken = \"button,select,textarea,option,script,style,noscript,template,[role=button],[role=menuitem],[role=option],[role=tab],[role=switch],[role=checkbox],[role=radio],[aria-hidden=true]\";\n const groups = \"tr,li,article,fieldset,form,section,dialog,[role=row],[role=listitem],[role=group],[role=region],[role=dialog],[role=alertdialog]\";\n /** The visible text just before (or after) a target within `scope`, nearest kept, ≤120 characters. */\n const textBeside = (target, scope, backwards) => {\n const walker = target.ownerDocument.createTreeWalker(scope, NodeFilter.SHOW_TEXT);\n const labels = isInput(target) || isTextArea(target) || isSelect(target) || isButton(target) ? Array.from(target.labels ?? []) : [];\n let text = \"\";\n walker.currentNode = target;\n for (let steps = 0; steps < 400 && text.replace(/\\s+/g, \"\").length < 120; steps++) {\n const node = backwards ? walker.previousNode() : walker.nextNode();\n if (node === null) break;\n const parent = node.parentElement;\n if (parent === null || target.contains(parent) || parent.closest(unspoken) !== null || isHtml(parent) && parent.isContentEditable || labels.some((label) => label.contains(parent)) || !visible(parent)) continue;\n text = backwards ? `${node.textContent ?? \"\"} ${text}` : `${text} ${node.textContent ?? \"\"}`;\n }\n const words = text.replace(/\\s+/g, \" \").trim();\n return words.length <= 120 ? words : backwards ? `…${words.slice(-119).trimStart()}` : `${words.slice(0, 119).trimEnd()}…`;\n };\n /** The nearest visible heading before `target` in tree order, within `scope`. */\n const headingBefore = (target, scope, read = known()) => {\n let headings = read.headings.get(scope);\n if (headings === void 0) {\n headings = Array.from(scope.querySelectorAll(\"h1,h2,h3,h4,h5,h6,[role=heading]\")).filter((element) => roleOf(element) === \"heading\");\n read.headings.set(scope, headings);\n }\n for (const heading of headings.toReversed()) {\n if ((heading.compareDocumentPosition(target) & Node.DOCUMENT_POSITION_FOLLOWING) === 0) continue;\n const text = visible(heading) ? clean(textOf(heading), 120) : \"\";\n if (text !== \"\") return text;\n }\n };\n /** Whether an element is pinned to the viewport, where the markup around it says nothing. */\n const pinned = (element) => {\n if (!isHtml(element)) return false;\n let top = element;\n while (top.offsetParent !== null && isHtml(top.offsetParent)) top = top.offsetParent;\n return top !== element.ownerDocument.body && top !== element.ownerDocument.documentElement && getComputedStyle(top).position === \"fixed\";\n };\n const span = (cell) => Math.max(1, Number(cell.getAttribute(\"colspan\")) || 1);\n const tables = \"table,[role=table],[role=grid],[role=treegrid]\";\n /** A cell's row and column names, or nothing when it is not in a table with either. */\n const tableContext = (cell, read) => {\n const row = cell.closest(\"tr,[role=row]\");\n const table = row?.closest(tables);\n if (row === null || row === void 0 || table === null || table === void 0) return {};\n let header = read.headers.get(table);\n if (header === void 0) {\n const first = table.querySelector(\"thead tr, tr:has(> th), [role=row]:has(> [role=columnheader])\");\n header = first?.closest(tables) === table ? first : null;\n read.headers.set(table, header);\n }\n if (row === header) return {};\n const cells = Array.from(row.children);\n const index = cells.indexOf(cell);\n const lettered = (other) => /\\p{L}/u.test(textOf(other));\n const named = cells.find((other) => other.matches(\"th,[role=rowheader]\") && lettered(other)) ?? cells.find((other) => other !== cell && lettered(other));\n let left = cells.slice(0, index).reduce((sum, other) => sum + span(other), 0);\n const over = index === -1 || header === null ? void 0 : Array.from(header.children).find((candidate) => (left -= span(candidate)) < 0);\n return {\n row: named === void 0 || named === cell ? void 0 : clean(textOf(named), 60) || void 0,\n column: over === void 0 ? void 0 : clean(textOf(over), 60) || void 0\n };\n };\n /** Where text around an element is read: its dialog, else its own tree, never across a shadow root. */\n const treeOf = (element) => {\n const root = element.getRootNode();\n return element.closest(\"dialog,[role=dialog],[role=alertdialog]\") ?? (isDocument(root) ? root.body ?? root : isRoot(root) ? root : element.ownerDocument);\n };\n /** The words around an element that say which one it is. */\n const contextOf = (element, read = known()) => {\n const cell = element.closest(\"td,th,[role=cell],[role=gridcell],[role=rowheader],[role=columnheader]\");\n const table = cell === null ? {} : tableContext(cell, read);\n const parent = element.parentElement;\n const scope = element.closest(groups) ?? (parent === null || parent === element.ownerDocument.body || parent.tagName === \"HTML\" ? void 0 : parent);\n const beside = table.row !== void 0 || table.column !== void 0 || scope === void 0 ? \"\" : textBeside(element, scope, true);\n const heading = pinned(element) ? void 0 : headingBefore(element, treeOf(element), read);\n return {\n ...table,\n label: beside.length > 40 ? `…${beside.slice(-39).trimStart()}` : beside || void 0,\n heading: heading === void 0 ? void 0 : clean(heading, 60)\n };\n };\n return {\n contextOf,\n groups,\n headingBefore,\n known,\n textBeside,\n treeOf\n };\n };\n //#endregion\n //#region src/internal/reading/controls.inpage.ts\n const controls = (names, subjects, texts) => {\n const { clean, isInput, isSelect, isTextArea, refFor, textEntry } = names;\n const { stateOf } = subjects;\n const { shown } = texts;\n const states = (element, role) => {\n const { level, ...flags } = stateOf(element, role);\n const held = Object.entries(flags).flatMap(([name, value]) => value === true ? [name] : []);\n return [...level === void 0 ? [] : [`level=${level}`], ...held].map((name) => ` [${name}]`).join(\"\");\n };\n const valueOf = (element) => {\n if (isSelect(element)) {\n const selected = Array.from(element.selectedOptions, (option) => clean(option.text, 40));\n const options = Array.from(element.options).slice(0, 12).map((option) => clean(option.text, 40));\n const more = element.options.length > 12 ? ` +${element.options.length - 12} more` : \"\";\n return ` value=${JSON.stringify(selected.join(\", \"))} options=${JSON.stringify(options.join(\" | \") + more)}`;\n }\n const value = isInput(element) || isTextArea(element) ? shown(element, true) : void 0;\n return value === void 0 || value === \"\" ? \"\" : ` value=${JSON.stringify(clean(value, 80))}`;\n };\n /** A control as a value, as its outline line shows it. */\n const controlOf = (element, role, kind, name) => {\n const { disabled, checked } = stateOf(element, role);\n const select = isSelect(element) ? element : void 0;\n const value = select !== void 0 ? Array.from(select.selectedOptions, (option) => clean(option.text, 80)).join(\", \") : isInput(element) || isTextArea(element) ? clean(shown(element, true), 200) : \"\";\n const editable = textEntry(element);\n return {\n ref: refFor(element),\n kind,\n name,\n value,\n ...select === void 0 ? {} : {\n options: Array.from(select.options).slice(0, 64).map((option) => clean(option.text, 80)),\n optionCount: select.options.length\n },\n ...disabled ? { disabled } : {},\n ...checked === void 0 ? {} : { checked },\n ...editable ? { editable } : {}\n };\n };\n /**\n * The elements a selector matches, each read whole, so one inside another that matched is left\n * to it; or why the selector is not CSS.\n */\n const rootsOf = (selector) => {\n let matched;\n try {\n matched = Array.from(document.querySelectorAll(selector));\n } catch {\n return { invalid: `${JSON.stringify(selector)} is not a CSS selector` };\n }\n return matched.filter((root) => !matched.some((other) => other !== root && other.contains(root)));\n };\n return {\n controlOf,\n rootsOf,\n states,\n valueOf\n };\n };\n //#endregion\n //#region src/internal/reading/expect.inpage.ts\n const expectations = (names, subjected, matching) => {\n const { isInput, isSelect, isTextArea, roleOf, textOf } = names;\n const { elementsOf, stateOf } = subjected;\n const markOf = (elements) => matching.mark(elements.map((element) => {\n const { focused: _focused, ...state } = stateOf(element, roleOf(element));\n const value = isInput(element) || isSelect(element) || isTextArea(element) ? element.value : \"\";\n return `${textOf(element)}\\u0000${value}\\u0000${JSON.stringify(state)}\\u0001`;\n }));\n /**\n * What `find` matches, looked at every 100 ms until `want` holds of it or `millis` have passed,\n * with its mark then. It gives no refs.\n */\n const until = async (request, want, millis) => {\n const deadline = performance.now() + millis;\n for (;;) {\n const elements = elementsOf(request);\n if (\"invalid\" in elements) return elements;\n const mark = markOf(elements);\n const met = want === \"some\" ? elements.length > 0 : want === \"none\" ? elements.length === 0 : mark !== want.other;\n const left = deadline - performance.now();\n if (met || left <= 0) return {\n met,\n mark\n };\n const { promise, resolve } = Promise.withResolvers();\n setTimeout(resolve, Math.min(100, left));\n await promise;\n }\n };\n return { until };\n };\n //#endregion\n //#region src/internal/reading/names.inpage.ts\n const elements = () => {\n const isInput = (element) => element.tagName === \"INPUT\";\n const isTextArea = (element) => element.tagName === \"TEXTAREA\";\n const isSelect = (element) => element.tagName === \"SELECT\";\n const isFrame = (element) => element.tagName === \"IFRAME\";\n const isHtml = (element) => \"innerText\" in element;\n const isButton = (element) => element.tagName === \"BUTTON\";\n const isLabel = (element) => element.tagName === \"LABEL\";\n const textOf = (element) => isHtml(element) ? element.innerText : element.textContent ?? \"\";\n const isElement = (node) => node.nodeType === Node.ELEMENT_NODE;\n const isDocument = (node) => node.nodeType === Node.DOCUMENT_NODE;\n /** The native fields and editable regions that can receive typed text. */\n const textEntry = (element) => isInput(element) && ![\n \"button\",\n \"reset\",\n \"submit\",\n \"image\",\n \"checkbox\",\n \"radio\",\n \"file\",\n \"range\",\n \"color\",\n \"hidden\"\n ].includes(element.type) || isTextArea(element) || isHtml(element) && element.isContentEditable;\n const clean = (value, max = 160) => {\n const text = (value ?? \"\").replace(/\\s+/g, \" \").trim();\n return text.length > max ? `${text.slice(0, max - 1)}…` : text;\n };\n return {\n clean,\n isInput,\n isTextArea,\n isSelect,\n isFrame,\n isHtml,\n isButton,\n isLabel,\n textOf,\n isElement,\n isDocument,\n textEntry\n };\n };\n const names = (native) => {\n const { clean, isInput, isTextArea, isSelect, isFrame, textOf, isElement } = native;\n const byElement = /* @__PURE__ */ new WeakMap();\n const byRef = /* @__PURE__ */ new Map();\n const refs = { next: 1 };\n const interactiveRoles = new Set(\"button link checkbox radio tab menuitem menuitemcheckbox menuitemradio option switch slider combobox listbox textbox searchbox spinbutton treeitem\".split(\" \"));\n const containers = {\n HEADER: \"banner\",\n NAV: \"navigation\",\n MAIN: \"main\",\n ASIDE: \"complementary\",\n FOOTER: \"contentinfo\",\n FORM: \"form\",\n DIALOG: \"dialog\"\n };\n const valueRoles = new Set(\"combobox listbox option textbox searchbox spinbutton slider\".split(\" \"));\n /**\n * A label's own words, without the options or values of the controls inside it, native or\n * scripted, such as the custom select Browserbase puts in place of a native one.\n */\n const labelText = (label) => {\n let text = \"\";\n const collect = (node) => {\n for (const child of Array.from(node.childNodes)) if (child.nodeType === Node.TEXT_NODE) text += child.textContent ?? \"\";\n else if (isElement(child) && ![\n \"SELECT\",\n \"TEXTAREA\",\n \"INPUT\",\n \"SCRIPT\",\n \"STYLE\"\n ].includes(child.tagName) && !valueRoles.has(roleOf(child) ?? \"\")) collect(child);\n };\n collect(label);\n return text;\n };\n const roleOf = (element, structural = false) => {\n const explicit = element.getAttribute(\"role\");\n if (explicit !== null && explicit.trim() !== \"\") return explicit.trim().split(/\\s+/)[0] ?? null;\n const tag = element.tagName;\n if (tag === \"A\") return element.hasAttribute(\"href\") ? \"link\" : null;\n if (tag === \"BUTTON\" || tag === \"SUMMARY\") return \"button\";\n if (isSelect(element)) return element.multiple ? \"listbox\" : \"combobox\";\n if (tag === \"TEXTAREA\") return \"textbox\";\n if (isInput(element)) {\n const type = element.type;\n if (type === \"hidden\" || type === \"color\" || type === \"file\") return null;\n if (type === \"checkbox\" || type === \"radio\") return type;\n if (type === \"range\") return \"slider\";\n if (type === \"number\") return \"spinbutton\";\n if (type === \"search\") return \"searchbox\";\n if (type === \"button\" || type === \"submit\" || type === \"reset\" || type === \"image\") return \"button\";\n return \"textbox\";\n }\n if (/^H[1-6]$/.test(tag)) return \"heading\";\n if (tag === \"IMG\") return \"img\";\n if (tag === \"CANVAS\") return \"canvas\";\n if (tag === \"IFRAME\") return \"iframe\";\n if (element.getAttribute(\"contenteditable\") === \"true\") return \"textbox\";\n if (structural) {\n if (tag === \"TH\") return element.getAttribute(\"scope\") === \"row\" ? \"rowheader\" : \"columnheader\";\n const roles = {\n TABLE: \"table\",\n TR: \"row\",\n TD: \"cell\",\n TBODY: \"rowgroup\",\n THEAD: \"rowgroup\",\n TFOOT: \"rowgroup\",\n UL: \"list\",\n OL: \"list\",\n MENU: \"list\",\n LI: \"listitem\"\n };\n if (roles[tag] !== void 0) return roles[tag];\n }\n return containers[tag] ?? null;\n };\n const nameOf = (element, role) => {\n const labelledBy = element.getAttribute(\"aria-labelledby\");\n if (labelledBy !== null) {\n const text = labelledBy.split(/\\s+/).map((id) => {\n const labelling = element.ownerDocument.getElementById(id);\n return labelling === null ? \"\" : labelText(labelling);\n }).join(\" \");\n if (clean(text) !== \"\") return clean(text);\n }\n const label = element.getAttribute(\"aria-label\");\n if (label !== null && clean(label) !== \"\") return clean(label);\n if (isInput(element) || isTextArea(element) || isSelect(element)) {\n const labels = element.labels === null ? \"\" : Array.from(element.labels, labelText).join(\" \");\n if (clean(labels) !== \"\") return clean(labels);\n if (isInput(element) && (element.type === \"button\" || element.type === \"submit\" || element.type === \"reset\")) return clean(element.value);\n return clean(element.getAttribute(\"placeholder\") ?? element.getAttribute(\"title\") ?? element.getAttribute(\"name\"));\n }\n if (role === \"img\") return clean(element.getAttribute(\"alt\") ?? element.getAttribute(\"title\"));\n if (role === \"iframe\") return clean(element.getAttribute(\"title\") ?? element.getAttribute(\"name\"));\n if (role === null || interactiveRoles.has(role) || role === \"heading\") {\n const text = isSecret(element) ? \"\" : clean(textOf(element), 120);\n if (text !== \"\") return text;\n const titled = element.querySelector(\"[title],img[alt],svg title\");\n const fallback = titled === null ? null : titled.tagName === \"IMG\" ? titled.getAttribute(\"alt\") : titled.tagName.toLowerCase() === \"title\" ? titled.textContent : titled.getAttribute(\"title\");\n return clean(element.getAttribute(\"title\") ?? fallback);\n }\n return \"\";\n };\n const isDisabled = (element) => element.matches(\":disabled\") || element.getAttribute(\"aria-disabled\") === \"true\";\n const refFor = (element) => {\n const known = byElement.get(element);\n if (known !== void 0 && byRef.get(known)?.deref() === element) return known;\n const ref = `e${refs.next++}`;\n byElement.set(element, ref);\n byRef.set(ref, new WeakRef(element));\n return ref;\n };\n const lookup = (ref) => {\n const element = byRef.get(ref)?.deref();\n return element !== void 0 && element.isConnected && inCurrentDocument(element) ? element : void 0;\n };\n const describe = (element) => {\n const id = element.id === \"\" ? \"\" : `#${element.id}`;\n const name = clean(nameOf(element, roleOf(element)), 40);\n return `<${element.tagName.toLowerCase()}${id}>${name === \"\" ? \"\" : ` \"${name}\"`}`;\n };\n const isRoot = (node) => node.nodeType === Node.DOCUMENT_NODE || node.nodeType === Node.DOCUMENT_FRAGMENT_NODE;\n const parentOf = (element) => {\n const root = element.getRootNode();\n return element.parentElement ?? (isRoot(root) && \"host\" in root ? root.host : null);\n };\n const activeElement = () => {\n let active = document.activeElement;\n while (active !== null) {\n const inner = active.shadowRoot?.activeElement ?? (isFrame(active) ? active.contentDocument?.activeElement : null);\n if (inner === null || inner === void 0 || inner === active) return active;\n active = inner;\n }\n return null;\n };\n const inCurrentDocument = (element) => {\n let owner = element.ownerDocument;\n while (owner !== document) {\n const frame = owner.defaultView?.frameElement;\n if (frame === null || frame === void 0 || !frame.isConnected || isFrame(frame) && frame.contentDocument !== owner) return false;\n owner = frame.ownerDocument;\n }\n return true;\n };\n const secretToken = /(?:^|\\s)(?:current-password|new-password|one-time-code|cc-number|cc-csc|cc-exp(?:-month|-year)?)(?=\\s|$)/i;\n const secrets = /* @__PURE__ */ new WeakSet();\n /**\n * A field the DOM marks as secret, now or before: by its type, its autocomplete tokens, or a\n * style that shows dots for what it holds, as a PIN field may.\n */\n const isSecret = (element) => {\n if (isInput(element) && element.type === \"password\" || secretToken.test(element.getAttribute(\"autocomplete\") ?? \"\") || (isInput(element) || isTextArea(element)) && !/^(none)?$/.test(getComputedStyle(element).getPropertyValue(\"-webkit-text-security\"))) secrets.add(element);\n return secrets.has(element);\n };\n return {\n ...native,\n activeElement,\n containers,\n describe,\n inCurrentDocument,\n interactiveRoles,\n isDisabled,\n isRoot,\n isSecret,\n lookup,\n nameOf,\n parentOf,\n refFor,\n refs,\n roleOf\n };\n };\n //#endregion\n //#region src/internal/reading/outline.inpage.ts\n const outline = (names, walked, subjects, texts, controlling, url) => {\n const { clean, containers, isFrame, nameOf, refFor, roleOf, textOf } = names;\n const { visit } = walked;\n const { isControl } = subjects;\n const { cut } = texts;\n const textBlocks = /^(?:P|LI|TD|TH|DT|DD|LABEL|SPAN|BLOCKQUOTE|FIGCAPTION|CAPTION|PRE|STRONG|EM|B|I|SMALL|TIME|CODE|LEGEND)$/;\n const nested = \"a[href],button,input,select,textarea,summary,[role],[onclick],[tabindex],[contenteditable],canvas,iframe\";\n const noise = /^[\\s|•·\\-–—,.:;()[\\]{}\"'/\\\\]*$/;\n /** Text inside a control's label is already that control's name. */\n const inControlLabel = (element) => {\n const label = element.closest(\"label\");\n return label !== null && label.control !== null;\n };\n const hrefOf = (element) => {\n if (element.tagName !== \"A\") return \"\";\n const raw = element.getAttribute(\"href\") ?? \"\";\n if (raw === \"\" || raw.startsWith(\"javascript:\")) return \"\";\n try {\n const { origin, href } = new URL(raw, element.ownerDocument.baseURI);\n const reported = url.redact(href);\n const own = origin === location.origin && reported.startsWith(origin);\n return ` -> ${clean(own ? reported.slice(origin.length) : reported, 80)}`;\n } catch {\n return \"\";\n }\n };\n const snapshot = (request) => {\n const roots = request.within === null ? [null] : controlling.rootsOf(request.within);\n if (\"invalid\" in roots) return roots;\n const width = window.innerWidth;\n const height = window.innerHeight;\n const query = request.query === null ? null : request.query.toLowerCase();\n const lines = [];\n const controls = [];\n let above = 0;\n let below = 0;\n const placement = (rect) => {\n if (request.full) return \"in\";\n if (rect.bottom <= 0) return \"above\";\n if (rect.top >= height) return \"below\";\n if (rect.right <= 0 || rect.left >= width) return \"aside\";\n return \"in\";\n };\n const count = (rect) => {\n const where = placement(rect);\n if (where === \"above\") above++;\n if (where === \"below\") below++;\n return where;\n };\n const emit = (depth, line, rect) => {\n if (count(rect) !== \"in\") return false;\n if (query !== null && !line.toLowerCase().includes(query)) return false;\n lines.push(`${\" \".repeat(Math.min(depth, 8))}- ${line}`);\n return true;\n };\n const control = (element, rect, role, depth) => {\n const name = nameOf(element, role);\n const kind = role ?? \"clickable\";\n const box = request.boxes || role === \"canvas\" || role === \"iframe\" ? ` ${Math.round(rect.width)}x${Math.round(rect.height)} at (${Math.round(rect.x)},${Math.round(rect.y)})` : \"\";\n const line = placement(rect) === \"in\" ? `${kind}${name === \"\" ? \"\" : ` ${JSON.stringify(name)}`} [ref=${refFor(element)}]${controlling.states(element, role)}${controlling.valueOf(element)}${hrefOf(element)}${box}` : kind;\n if (emit(depth, line, rect)) controls.push(controlling.controlOf(element, role, kind, name));\n if (isFrame(element)) {\n const body = element.contentDocument?.body;\n if ((body === null || body === void 0) && placement(rect) === \"in\") lines.push(`${\" \".repeat(Math.min(depth + 1, 8))}- (another site's frame: use a screenshot and coordinates)`);\n return {\n depth: depth + 1,\n insidePointer: false,\n controls: false\n };\n }\n if ([\n \"INPUT\",\n \"SELECT\",\n \"TEXTAREA\",\n \"CANVAS\",\n \"IMG\"\n ].includes(element.tagName)) return void 0;\n return {\n depth: depth + 1,\n insidePointer: true,\n controls: true\n };\n };\n const enter = (element, style, rect, { depth, insidePointer }) => {\n const role = roleOf(element);\n if (isControl(element, role, style, rect, insidePointer)) return control(element, rect, role, depth);\n if (role === \"heading\") {\n emit(depth, `heading ${JSON.stringify(nameOf(element, role))}${controlling.states(element, role)}`, rect);\n return;\n }\n if (role === \"img\") {\n const alt = nameOf(element, role);\n if (alt !== \"\") emit(depth, `img ${JSON.stringify(alt)}`, rect);\n return;\n }\n let inner = depth;\n if (role !== null && (containers[element.tagName] !== void 0 || role === \"dialog\")) {\n const label = element.getAttribute(\"aria-label\");\n if (emit(depth, `${role}${label === null ? \"\" : ` ${JSON.stringify(clean(label))}`}:`, rect)) inner = depth + 1;\n }\n if (textBlocks.test(element.tagName) && element.querySelector(nested) === null) {\n if (inControlLabel(element)) return void 0;\n const text = clean(textOf(element), 300);\n if (text !== \"\" && !noise.test(text)) emit(inner, `text: ${text}`, rect);\n return;\n }\n let own = \"\";\n for (const node of Array.from(element.childNodes)) if (node.nodeType === Node.TEXT_NODE) own += node.textContent ?? \"\";\n own = clean(own, 300);\n if (own !== \"\" && !noise.test(own) && !inControlLabel(element)) emit(inner, `text: ${own}`, rect);\n return {\n depth: inner,\n insidePointer: insidePointer || style.cursor === \"pointer\",\n controls: false\n };\n };\n const visitor = {\n enter,\n admit: (child, place) => !place.controls || child.matches(nested) || child.querySelector(nested) !== null,\n outside: count\n };\n for (const root of roots) visit(root, !request.full, {\n depth: 0,\n insidePointer: false,\n controls: false\n }, visitor);\n const outlined = cut(lines.join(\"\\n\"), request.maxChars);\n return { snapshot: {\n ...outlined,\n url: location.href,\n title: document.title,\n above,\n below,\n viewport: {\n width,\n height\n },\n scroll: {\n y: Math.round(window.scrollY),\n height: Math.round(document.documentElement.scrollHeight)\n },\n controls: controls.filter((control) => outlined.text.includes(`[ref=${control.ref}]`))\n } };\n };\n const viewport = () => ({\n width: window.innerWidth,\n height: window.innerHeight\n });\n return {\n snapshot,\n viewport\n };\n };\n //#endregion\n //#region src/internal/reading/ready.inpage.ts\n const ready = (walked, texts, kept) => {\n const { inView, visible } = walked;\n let copy;\n const boxed = (element) => {\n const rect = element.getBoundingClientRect();\n return rect.width * rect.height > 0 && inView(rect);\n };\n const showing = (elements) => Array.from(elements).filter((element) => boxed(element) && visible(element));\n const drawn = (canvas) => {\n copy ??= new OffscreenCanvas(32, 32).getContext(\"2d\", { willReadFrequently: true });\n if (copy === null) return true;\n try {\n copy.clearRect(0, 0, 32, 32);\n copy.imageSmoothingQuality = \"high\";\n copy.drawImage(canvas, 0, 0, 32, 32);\n return new Uint32Array(copy.getImageData(0, 0, 32, 32).data.buffer).some((pixel) => pixel !== 0);\n } catch {\n return true;\n }\n };\n const content = () => showing(document.querySelectorAll(\"video, iframe, embed, object\")).length > 0 || showing(document.querySelectorAll(\"img, svg\")).some((picture) => {\n const { width, height } = picture.getBoundingClientRect();\n return width > 64 && height > 64;\n }) || (texts.read({\n ref: null,\n maxChars: 1,\n unmask: false\n })?.text ?? \"\") !== \"\" || showing(document.querySelectorAll(\"canvas\")).some(drawn);\n const painted = () => {\n const { promise, resolve } = Promise.withResolvers();\n if (document.visibilityState === \"hidden\") resolve(false);\n else requestAnimationFrame(() => resolve(true));\n return promise;\n };\n const check = (quietMillis) => painted().then((paints) => {\n const waiting = [];\n if (document.readyState === \"loading\") waiting.push(\"load\");\n if (!paints) waiting.push(\"paint\");\n if (document.getAnimations().some((animation) => {\n const effect = animation.effect;\n return animation.playState === \"running\" && effect !== null && Number.isFinite(effect.getComputedTiming().endTime) && \"target\" in effect && effect.target instanceof Element && boxed(effect.target);\n })) waiting.push(\"animations\");\n if (Array.from(document.images).some((image) => !image.complete && boxed(image))) waiting.push(\"images\");\n if (document.fonts.status !== \"loaded\") waiting.push(\"fonts\");\n if (showing(document.querySelectorAll(\"[aria-busy=true]\")).length > 0) waiting.push(\"busy\");\n if (!content()) waiting.push(\"content\");\n if (kept.changing() > performance.timeOrigin + performance.now() - quietMillis) waiting.push(\"changing\");\n return waiting;\n });\n /**\n * Check until the page is ready, or for `millis`, and say what it is still waiting for; with\n * `quietMillis`, until nothing the record saw in view has changed for that long, too.\n */\n const wait = async (millis, quietMillis = 0) => {\n const until = performance.now() + millis;\n for (;;) {\n const waiting = await check(quietMillis);\n if (waiting.length === 0 || performance.now() >= until) return waiting;\n const { promise, resolve } = Promise.withResolvers();\n setTimeout(resolve, Math.min(50, until - performance.now()));\n await promise;\n }\n };\n /**\n * One task, then a frame: what the page's handlers for input did at once has run, a navigation\n * one of them started in a timer has been asked for, and their effect has painted. Says whether\n * the page painted, which a hidden one does not.\n */\n const settle = () => {\n const { promise, resolve } = Promise.withResolvers();\n setTimeout(resolve, 0);\n return promise.then(painted);\n };\n return {\n wait,\n settle\n };\n };\n //#endregion\n //#region src/internal/reading/subjects.inpage.ts\n const states = (names) => (element, role) => {\n const { isDisabled, isInput } = names;\n const given = (attribute) => {\n const value = element.getAttribute(attribute);\n return value === \"true\" || (value === \"false\" ? false : void 0);\n };\n const checkable = element.hasAttribute(\"aria-checked\") || [\n \"checkbox\",\n \"radio\",\n \"switch\",\n \"menuitemcheckbox\",\n \"menuitemradio\"\n ].includes(role ?? \"\");\n return {\n disabled: isDisabled(element),\n checked: checkable ? isInput(element) && element.checked || element.getAttribute(\"aria-checked\") === \"true\" : void 0,\n expanded: given(\"aria-expanded\"),\n selected: given(\"aria-selected\"),\n pressed: given(\"aria-pressed\"),\n focused: element.ownerDocument.activeElement === element,\n level: role === \"heading\" ? Number(element.getAttribute(\"aria-level\")) || Number(/^H([1-6])$/.exec(element.tagName)?.[1]) || 2 : void 0\n };\n };\n const subjects = (names, walked, matching, placing, stateOf) => {\n const { isDisabled, nameOf, refFor, roleOf, textOf } = names;\n const { acts, boxOf, controlOf, hitAt, inView } = walked;\n const { contextOf, known } = placing;\n /** What the outline lists as a control, with a ref: something a person would act on. */\n const isControl = (element, role, style, rect, insidePointer) => acts(element, role) || style.cursor === \"pointer\" && !insidePointer && rect.width > 0 && rect.height > 0;\n /**\n * The elements in scope that match a query, in tree order. Without text, an element matches\n * when it has a role or is a control. With text, any element can, but text inside a control or\n * heading is that control's or heading's, and an element is left out when one inside it\n * matches too: the smallest element showing the text is found, not each one around it.\n */\n const matched = (request) => {\n const { at } = request;\n const matches = matching.compile(request);\n const byText = request.text !== null;\n const viewport = request.scope === \"viewport\";\n const read = known();\n if (request.selector !== null) try {\n document.querySelector(request.selector);\n } catch {\n return { invalid: `${JSON.stringify(request.selector)} is not a CSS selector` };\n }\n const eligible = (element) => (request.selector === null || element.matches(request.selector)) && (request.state !== \"enabled\" || !isDisabled(element));\n const entries = [];\n const open = [];\n const named = (entry) => entry.name ??= nameOf(entry.element, entry.role);\n const placed = (entry) => entry.context ??= contextOf(entry.element, read);\n const judge = (entry, text) => matches({\n role: entry.role,\n name: () => named(entry),\n text,\n context: () => placed(entry)\n });\n const hit = at === null ? null : hitAt(document, at.x, at.y);\n if (hit !== null) {\n const element = controlOf(hit);\n const { x, y, width, height } = boxOf(element);\n const entry = {\n element,\n rect: new DOMRect(x, y, width, height),\n role: roleOf(element, request.role !== null),\n matched: false\n };\n entry.matched = eligible(element) && judge(entry, () => textOf(element));\n entries.push(entry);\n }\n if (at === null) walked.visit(null, viewport, {\n pointer: false,\n owned: false\n }, {\n enter: (element, style, rect, state) => {\n const role = roleOf(element, request.role !== null);\n const control = isControl(element, role, style, rect, state.pointer);\n const unit = control || role === \"heading\";\n const entry = eligible(element) && (byText ? unit || !state.owned : request.selector !== null || role !== null || control) && (!viewport || inView(rect)) ? {\n element,\n rect,\n role,\n matched: false\n } : void 0;\n if (entry !== void 0) entries.push(entry);\n open.push({\n entry,\n inline: style.display === \"inline\",\n parts: [],\n inside: false\n });\n return {\n pointer: state.pointer || style.cursor === \"pointer\",\n owned: state.owned || unit\n };\n },\n text: byText ? (node) => open.at(-1)?.parts.push(node.textContent ?? \"\") : void 0,\n leave: () => {\n const closed = open.pop();\n const parent = open.at(-1);\n if (closed === void 0) return;\n const { entry } = closed;\n const text = closed.parts.join(\"\");\n if (parent !== void 0) parent.parts.push(closed.inline ? text : ` ${text} `);\n if (entry !== void 0 && !(byText && closed.inside)) entry.matched = judge(entry, () => text);\n if (parent !== void 0) parent.inside ||= closed.inside || entry?.matched === true;\n }\n });\n return {\n entries: entries.filter((entry) => entry.matched),\n named,\n placed\n };\n };\n const find = (request) => {\n const result = matched(request);\n if (result.invalid !== void 0) return { invalid: result.invalid };\n const { entries, named, placed } = result;\n return { found: entries.map((entry) => ({\n ref: refFor(entry.element),\n subject: {\n role: entry.role,\n name: named(entry),\n tag: entry.element.tagName.toLowerCase(),\n context: placed(entry)\n },\n box: {\n x: Math.round(entry.rect.x),\n y: Math.round(entry.rect.y),\n width: Math.round(entry.rect.width),\n height: Math.round(entry.rect.height)\n },\n inViewport: inView(entry.rect),\n state: stateOf(entry.element, entry.role)\n })) };\n };\n /** The elements `find` would find, in tree order, with no refs given. */\n const elementsOf = (request) => {\n const result = matched(request);\n return result.invalid !== void 0 ? { invalid: result.invalid } : result.entries.map((entry) => entry.element);\n };\n return {\n find,\n elementsOf,\n isControl,\n stateOf\n };\n };\n //#endregion\n //#region src/internal/reading/text.inpage.ts\n const text = (names, walked) => {\n const { isHtml, isInput, isSecret, isSelect, isTextArea, lookup } = names;\n const valueless = [\n \"checkbox\",\n \"radio\",\n \"button\",\n \"submit\",\n \"reset\",\n \"image\",\n \"file\"\n ];\n /** What a field holds, or undefined for an element that holds nothing entered. */\n const valueOf = (element) => {\n if (isInput(element)) return valueless.includes(element.type) ? void 0 : element.value;\n if (isTextArea(element)) return element.value;\n if (isSelect(element)) return Array.from(element.selectedOptions, (option) => option.text).join(\", \");\n const parent = element.parentElement;\n return isHtml(element) && element.isContentEditable && !(parent !== null && isHtml(parent) && parent.isContentEditable) ? element.innerText : void 0;\n };\n /** What a field shows: `••••` unless `unmask`, and always for a secret field; \"\" when empty. */\n const shown = (element, unmask) => {\n const value = valueOf(element);\n if (value === void 0 || value.trim() === \"\") return value === void 0 ? void 0 : \"\";\n return unmask && !isSecret(element) ? value : \"••••\";\n };\n /** Lines cut after the last whole line within `max` characters, or at `max` when none is. */\n const cut = (lines, max) => {\n if (lines.length <= max) return {\n text: lines,\n truncated: false\n };\n const end = lines.lastIndexOf(\"\\n\", max);\n return {\n text: lines.slice(0, end > 0 ? end : max),\n truncated: true\n };\n };\n /**\n * What the viewport, or one element whole, shows as text: a line per block, table cells apart by\n * a tab, and each field as `shown` gives it.\n */\n const lines = (root, unmask) => {\n const lines = [];\n let line = \"\";\n const end = () => {\n const words = line.replace(/[^\\S\\t]+/g, \" \").replace(/ ?\\t ?/g, \" \").trim();\n if (words !== \"\") lines.push(words);\n line = \"\";\n };\n walked.visit(root, root === null, false, {\n enter: (element, style) => {\n const { display } = style;\n const value = shown(element, unmask);\n const block = !display.startsWith(\"inline\") && display !== \"contents\" && display !== \"table-cell\";\n if (display === \"table-cell\") line += \" \";\n if (block || element.tagName === \"BR\") end();\n if (value === void 0 && !(isInput(element) && valueless.includes(element.type))) return block;\n const label = isInput(element) && /^(button|submit|reset)$/.test(element.type);\n line += ` ${value ?? (label ? element.value : \"\")} `;\n if (block) end();\n },\n text: (node) => {\n line += node.textContent ?? \"\";\n },\n leave: (_, block) => {\n if (block) end();\n }\n });\n end();\n return lines.join(\"\\n\");\n };\n const read = (request) => {\n const root = request.ref === null ? null : lookup(request.ref);\n return root === void 0 ? null : {\n ...cut(lines(root, request.unmask), request.maxChars),\n url: location.href,\n title: document.title\n };\n };\n return {\n cut,\n lines,\n read,\n shown\n };\n };\n //#endregion\n //#region src/internal/reading/walk.inpage.ts\n const walk = (names) => {\n const { interactiveRoles, isElement, isFrame, isInput, parentOf, roleOf } = names;\n const skipped = new Set(\"SCRIPT STYLE NOSCRIPT TEMPLATE HEAD META LINK SVG\".split(\" \"));\n /** Whether a box, in top-document pixels, meets the viewport. */\n const inView = (rect, width = innerWidth, height = innerHeight) => rect.right > 0 && rect.bottom > 0 && rect.left < width && rect.top < height;\n /** Whether an element reached on its own shows, by the walk's rule and its ancestors'. */\n const visible = (element) => {\n if (element.closest(\"[aria-hidden=true]\") !== null) return false;\n if (element.checkVisibility({\n opacityProperty: true,\n visibilityProperty: true\n })) return true;\n if (getComputedStyle(element).display !== \"contents\") return false;\n for (let node = element; node !== null; node = parentOf(node)) {\n const style = getComputedStyle(node);\n if (style.display === \"none\" || style.opacity === \"0\" || node === element && style.visibility !== \"visible\") return false;\n }\n return true;\n };\n const untransformed = (frame, rect) => {\n if (rect.width !== frame.offsetWidth || rect.height !== frame.offsetHeight) return false;\n let ancestor = frame;\n while (ancestor !== null) {\n const style = (ancestor.ownerDocument.defaultView ?? window).getComputedStyle(ancestor);\n if (style.transform !== \"none\" || style.scale !== \"none\" || style.rotate !== \"none\" || style.perspective !== \"none\" || style.zoom !== \"1\") return false;\n ancestor = parentOf(ancestor);\n }\n return true;\n };\n /** The element painted at a point, inside shadow roots and same-origin frames. */\n const hitAt = (root, x, y) => {\n let hit = root.elementFromPoint(x, y);\n while (hit?.shadowRoot !== null && hit?.shadowRoot !== void 0) {\n const inner = hit.shadowRoot.elementFromPoint(x, y);\n if (inner === null || inner === hit) break;\n hit = inner;\n }\n if (hit !== null && isFrame(hit)) {\n const document = hit.contentDocument;\n if (document !== null) {\n const rect = hit.getBoundingClientRect();\n if (untransformed(hit, rect)) return hitAt(document, x - rect.left - hit.clientLeft, y - rect.top - hit.clientTop) ?? hit;\n }\n }\n return hit;\n };\n /** Whether its role or a click handler makes an element a control. */\n const acts = (element, role) => isInput(element) && element.type !== \"hidden\" || role !== null && (interactiveRoles.has(role) || role === \"canvas\" || role === \"iframe\") || element.hasAttribute(\"onclick\");\n const controlOf = (hit) => {\n let element = hit;\n while (element !== null) {\n if (acts(element, roleOf(element))) return element;\n element = parentOf(element);\n }\n return hit;\n };\n /** An element's box in top-document viewport pixels, through the frames around it. */\n const boxOf = (element) => {\n const { x, y, width, height } = element.getBoundingClientRect();\n const frame = element.ownerDocument.defaultView?.frameElement ?? null;\n if (frame === null) return {\n x,\n y,\n width,\n height\n };\n const outer = boxOf(frame);\n return {\n x: x + outer.x + frame.clientLeft,\n y: y + outer.y + frame.clientTop,\n width,\n height\n };\n };\n /** What is painted where pinned things sit, what is pinned in view, and every element holding it. */\n const painted = (width, height) => {\n const keep = /* @__PURE__ */ new Set();\n const hold = (element) => {\n for (let node = element; node !== null && !keep.has(node); node = parentOf(node) ?? node.ownerDocument.defaultView?.frameElement ?? null) keep.add(node);\n };\n for (const y of [\n 8,\n 48,\n height / 2,\n height - 48,\n height - 8\n ]) for (const x of [\n 8,\n 48,\n width / 4,\n width / 2,\n width * 3 / 4,\n width - 48,\n width - 8\n ]) if (x >= 0 && y >= 0 && x < width && y < height) {\n hold(hitAt(document, x, y));\n for (const beneath of document.elementsFromPoint(x, y)) hold(beneath);\n }\n for (const element of Array.from(document.querySelectorAll(\":modal, :popover-open\"))) hold(element);\n for (const element of Array.from(document.querySelectorAll(\"[style*=\\\"fixed\\\" i]\"))) if (inView(element.getBoundingClientRect(), width, height)) hold(element);\n return keep;\n };\n /**\n * Visit `root` and what it holds, or the whole document when `root` is null. With `viewport`,\n * a subtree outside the viewport is skipped, as described above.\n */\n const visit = (root, viewport, state, visitor) => {\n const { innerWidth: width, innerHeight: height } = window;\n let keep;\n const children = (parent, inner, dx, dy) => {\n const nodes = visitor.text === void 0 ? parent.children : parent.childNodes;\n for (const node of Array.from(nodes)) if (node.nodeType === Node.TEXT_NODE) visitor.text?.(node, inner);\n else if (isElement(node) && (visitor.admit === void 0 || visitor.admit(node, inner))) one(node, inner, dx, dy);\n };\n const one = (element, outer, dx, dy) => {\n if (skipped.has(element.tagName.toUpperCase())) return;\n const local = element.getBoundingClientRect();\n const rect = new DOMRect(local.x + dx, local.y + dy, local.width, local.height);\n if (viewport && local.width > 0 && local.height > 0 && !inView(rect, width, height) && !(keep ??= painted(width, height)).has(element)) {\n visitor.outside?.(rect);\n return;\n }\n const style = getComputedStyle(element);\n if (style.display === \"none\" || style.opacity === \"0\" || element.getAttribute(\"aria-hidden\") === \"true\") return;\n if (!visible(element)) {\n for (const child of Array.from(element.children)) one(child, outer, dx, dy);\n return;\n }\n const inner = visitor.enter(element, style, rect, outer);\n if (inner === void 0) return;\n if (isFrame(element)) {\n const body = element.contentDocument?.body;\n if (body !== null && body !== void 0) children(body, inner, rect.x, rect.y);\n } else {\n if (element.shadowRoot !== null) children(element.shadowRoot, inner, dx, dy);\n children(element, inner, dx, dy);\n }\n visitor.leave?.(element, inner);\n };\n if (root === null) children(document, state, 0, 0);\n else one(root, state, 0, 0);\n };\n return {\n acts,\n boxOf,\n controlOf,\n hitAt,\n inView,\n visible,\n visit\n };\n };\n //#endregion\n //#region src/internal/timeline/changes.inpage.ts\n const changes = (names, placing, kept, seeing, marking, recorder) => {\n const { clean, isInput, roleOf, nameOf } = names;\n const groups = \"tr,[role=row],form,dialog,[role=dialog],[role=alertdialog]\";\n /** Whether `element` lies in what an input on `target` acted on, its group, or what it controls. */\n const local = (target, element) => {\n const controls = target.closest(\"[aria-controls]\")?.getAttribute(\"aria-controls\") ?? \"\";\n const group = target.closest(groups);\n return target.contains(element) || group?.contains(element) === true || controls.split(/\\s+/).some((id) => id !== \"\" && document.getElementById(id)?.contains(element) === true);\n };\n /** What an element sits in, or sat in as it went. */\n const parentOf = (key) => key instanceof Element ? key.isConnected ? key.parentElement : marking.placeOf(key) ?? null : null;\n const fluxMillis = 1e4;\n const stillMillis = 2e3;\n /**\n * Each input a change may follow, with what the page did before it: what changed in the 10 s\n * before, the parents that gained or lost a child then, and whether nothing changed, and nothing\n * was let go, in the 2 s before. What holds the input's target, as a menu holds its item, came\n * with it, so it counts only as changing itself.\n */\n const before = () => {\n const inputs = recorder.inputs();\n if (inputs.length === 0) return [];\n const { tracks, losses } = kept.recent();\n return inputs.map(({ at, target }) => {\n const changed = /* @__PURE__ */ new Set();\n const moved = /* @__PURE__ */ new Set();\n let still = losses.every((lost) => lost >= at || lost < at - stillMillis);\n for (const { key, kind, initial, samples } of tracks) {\n const prior = samples.flatMap(({ at: when, shown }, index) => kind === \"value\" || when >= at || when < at - fluxMillis ? [] : [shown === null || (index === 0 ? initial : samples[index - 1]?.shown) === null]);\n if (prior.length > 0) changed.add(key);\n if (prior.length === 0 || key instanceof Element && key.contains(target)) continue;\n if (prior.includes(true)) moved.add(parentOf(key));\n if (samples.some(({ at: when }) => when < at && when >= at - stillMillis)) still = false;\n }\n return {\n at,\n target,\n changed,\n moved,\n still\n };\n });\n };\n /** The input a change followed, on the page's clock, where `Change.cause`'s rule names one. */\n const causeOf = (one, element, inputs) => {\n const parent = parentOf(one.track.key);\n for (const input of inputs.toReversed()) {\n const after = one.startedAt - input.at;\n if (after < 0) continue;\n if (after > 3e3) break;\n if (!(one.track.known >= input.at - fluxMillis || input.changed.has(one.track.key) || parent !== null && input.moved.has(parent)) && (local(input.target, element) || after <= 500 && input.still)) return input.at;\n }\n };\n const describe = (one, known, unmask, inputs) => {\n const { track, kind, before, after, lowest, highest, ...times } = one;\n const element = track.key instanceof Element ? track.key : null;\n const where = element?.isConnected === true ? element : marking.placeOf(track.key) ?? null;\n const role = element === null ? null : roleOf(element);\n const field = kind === \"value\";\n const checkable = element !== null && isInput(element) && /^(checkbox|radio)$/.test(element.type);\n const masked = (value) => value === void 0 || !field || unmask || checkable || value === \"\" ? value : \"••••\";\n return {\n ...times,\n kind,\n subject: {\n role,\n name: element === null ? \"\" : field ? nameOf(element, role) : clean(element.getAttribute(\"aria-label\"), 120),\n tag: element === null ? \"title\" : element.tagName.toLowerCase(),\n context: kind === \"title\" || where === null ? {} : placing.contextOf(where, known)\n },\n before: masked(before),\n after: masked(after),\n lowest: field ? void 0 : lowest,\n highest: field ? void 0 : highest,\n cause: field || where === null ? void 0 : causeOf(one, where, inputs)\n };\n };\n /** What changed after `since`, up to `until`, and no later than now. */\n const read = (request) => {\n const now = performance.timeOrigin + performance.now();\n recorder.start();\n seeing.settle();\n const until = Math.min(request.until ?? now, now);\n const { from, dropped, folded } = kept.read(request.since ?? Number.NEGATIVE_INFINITY, until, now);\n const known = placing.known();\n const inputs = before();\n return {\n until,\n from,\n dropped,\n records: folded.map((one) => describe(one, known, request.unmask, inputs))\n };\n };\n return { read };\n };\n //#endregion\n //#region src/internal/timeline/fold.inpage.ts\n const fold = () => {\n /** The one number some words show, such as 61240 in \"$61,240\"; none for none or several. */\n const number = (words) => {\n const found = words.match(/[-+−]?\\d[\\d,]*(?:\\.\\d+)?/g);\n const value = Number(found?.length === 1 ? found[0]?.replaceAll(\",\", \"\").replace(\"−\", \"-\") : \"\");\n return found?.length === 1 && Number.isFinite(value) ? [value] : [];\n };\n /** A track's changes after `since`, up to `until`, if one was seen in view. */\n const over = (track, since, until) => {\n const inside = track.samples.filter((sample) => sample.at > since && sample.at <= until);\n const first = inside[0];\n const last = inside.at(-1);\n if (first === void 0 || last === void 0 || !inside.some((sample) => sample.seen === true)) return void 0;\n const prior = track.samples[track.samples.indexOf(first) - 1];\n const lost = track.known <= since ? track.known : void 0;\n const start = prior === void 0 ? lost === void 0 ? void 0 : track.initial : prior.shown;\n const words = [start, ...inside.map((sample) => sample.shown)].filter((each) => typeof each === \"string\");\n const numbers = words.flatMap(number);\n const ranged = inside.length > 1 && numbers.length === words.length;\n const kind = track.kind !== \"content\" ? track.kind : last.shown === null ? start === null ? \"brief\" : \"disappeared\" : start === null ? \"appeared\" : \"text\";\n return {\n track,\n kind,\n startedAt: first.at,\n at: last.at,\n before: kind === \"disappeared\" ? words.at(-1) : start ?? void 0,\n after: kind === \"brief\" ? words.at(-1) : last.shown ?? void 0,\n count: inside.length,\n lowest: ranged ? words[numbers.indexOf(Math.min(...numbers))] : void 0,\n highest: ranged ? words[numbers.indexOf(Math.max(...numbers))] : void 0,\n earlier: prior?.at ?? (lost === Number.NEGATIVE_INFINITY ? void 0 : lost)\n };\n };\n /**\n * How readily a track gives way when the record is full: one that holds no change first, then\n * one that keeps changing, one never seen in view and one that has gone; news never does.\n */\n const rank = ({ samples: [only, ...more] }) => only === void 0 ? 4 : more.length > 0 ? 3 : only.seen === false ? 2 : only.shown === null ? 1 : 0;\n return {\n number,\n over,\n rank\n };\n };\n //#endregion\n //#region src/internal/timeline/history.inpage.ts\n const history = (folding, bounds = {\n tracks: 256,\n samples: 32,\n retention: 6e4\n }) => {\n const { tracks: maxTracks, samples: maxSamples, retention } = bounds;\n const tracks = /* @__PURE__ */ new Map();\n let refused = /* @__PURE__ */ new WeakSet();\n let losses = [];\n let lastLoss = Number.NEGATIVE_INFINITY;\n const gone = [];\n let begun;\n const lose = (at, count) => {\n const last = losses.at(-1);\n if (count <= 0) return;\n lastLoss = Math.max(lastLoss, at);\n if (last?.[0] === at) last[1] += count;\n else losses.push([at, count]);\n if (losses.length > 256) losses.shift();\n };\n const latest = (track) => track.samples.at(-1)?.at ?? Number.NEGATIVE_INFINITY;\n const drop = (track) => {\n tracks.delete(track.key);\n gone.push(track.key);\n };\n let version = 0;\n let barren = -1;\n /** What gives way for a newcomer: one that holds no change, then one that keeps changing. */\n const victim = () => {\n let chosen;\n let rank = 0;\n for (const track of barren === version ? [] : tracks.values()) {\n const next = folding.rank(track);\n if (next > rank) [chosen, rank] = [track, next];\n if (rank === 4) break;\n }\n if (chosen === void 0) barren = version;\n return chosen;\n };\n const evict = (track) => {\n drop(track);\n if (track.samples.length > 0) refused.add(track.key);\n for (const sample of track.samples) lose(sample.at, 1);\n };\n /** A key the record cannot keep: its change is counted. */\n const refuse = (key, at) => {\n refused.add(key);\n lose(at, 1);\n };\n /**\n * A new state for `key` at `at`: its sample, or none when it is no change or finds no room.\n * `initial` says what a key not yet kept showed before.\n */\n const note = (key, kind, at, shown, initial) => {\n let track = tracks.get(key);\n if (track === void 0) {\n const full = !refused.has(key) && tracks.size >= maxTracks;\n const out = full ? victim() : void 0;\n if (refused.has(key) || full && out === void 0) return refuse(key, at);\n const before = initial();\n if (shown !== void 0 && shown === before) return void 0;\n if (out !== void 0) evict(out);\n track = {\n key,\n kind,\n initial: before,\n known: Number.NEGATIVE_INFINITY,\n samples: []\n };\n tracks.set(key, track);\n }\n const { samples } = track;\n version++;\n if (samples.at(-1)?.at === at) samples.pop();\n const previous = samples.length === 0 ? track.initial : samples.at(-1)?.shown;\n if (shown !== void 0 && shown === previous) return void 0;\n const oldest = samples.length >= maxSamples ? samples.shift() : void 0;\n if (oldest !== void 0) {\n track.initial = oldest.shown;\n track.known = oldest.at;\n lose(oldest.at, 1);\n }\n const sample = {\n at,\n shown,\n seen: void 0\n };\n samples.push(sample);\n return sample;\n };\n /** Judge a sample as the page rendered it; a state that repeats the one before is no change. */\n const settle = (key, sample, shown, seen) => {\n const track = tracks.get(key);\n version++;\n if (sample.shown === void 0) sample.shown = shown;\n if (sample.seen === void 0) sample.seen = seen;\n if (track === void 0) return;\n let previous = track.initial;\n const changes = track.samples.filter((each) => {\n const same = each.shown !== void 0 && each.shown === previous;\n if (!same) previous = each.shown;\n return !same;\n });\n track.samples.splice(0, track.samples.length, ...changes);\n };\n /**\n * The window after `since`, up to `until`: where the record is whole, how many changes in it the\n * record let go, and each element's changes, oldest first by when they began.\n */\n const read = (since, until, now) => {\n for (const track of tracks.values()) if (latest(track) < now - retention) drop(track);\n return {\n from: Math.min(until, Math.max(begun ?? now, now - retention, lastLoss)),\n dropped: losses.reduce((sum, [at, count]) => at > since && at <= until ? sum + count : sum, 0),\n folded: [...tracks.values()].flatMap((track) => folding.over(track, since, until) ?? []).toSorted((left, right) => left.startedAt - right.startedAt)\n };\n };\n /** When something in view last changed, or something not yet judged; for a wait for stillness. */\n const changing = () => Math.max(begun ?? Number.NEGATIVE_INFINITY, ...Array.from(tracks.values(), (track) => track.samples.findLast((sample) => sample.seen !== false)?.at ?? Number.NEGATIVE_INFINITY));\n return {\n begin: (at) => {\n begun = at;\n },\n begun: () => begun !== void 0,\n clear: () => {\n for (const track of tracks.values()) drop(track);\n refused = /* @__PURE__ */ new WeakSet();\n losses = [];\n lastLoss = Number.NEGATIVE_INFINITY;\n begun = void 0;\n },\n changing,\n /** Keys whose tracks went since this was last asked, for the recorder to stop watching. */\n forgotten: () => gone.splice(0),\n has: (key) => tracks.has(key),\n /** Whether the record has let `key` go: its later changes are counted, never kept. */\n refuses: (key) => refused.has(key),\n lose,\n note,\n read,\n /** Each element's history, and when the record let changes go, for a read to judge causes. */\n recent: () => ({\n tracks: [...tracks.values()],\n losses: losses.map(([at]) => at)\n }),\n /** A track moves to the element that took its key's place, as a re-rendered price does. */\n rekey: (from, to) => {\n const track = tracks.get(from);\n if (track === void 0 || tracks.has(to)) return false;\n tracks.delete(from);\n track.key = to;\n tracks.set(to, track);\n return true;\n },\n settle\n };\n };\n //#endregion\n //#region src/internal/timeline/marks.inpage.ts\n const marks = (names, kept, seeing) => {\n const { clean, isElement, isHtml } = names;\n const unwritten = new Set(\"SCRIPT STYLE NOSCRIPT TEMPLATE TITLE\".split(\" \"));\n const hiding = /display\\s*:\\s*none|visibility\\s*:\\s*hidden|opacity\\s*:\\s*0(?![.\\d])/i;\n let places = /* @__PURE__ */ new WeakMap();\n let title = \"\";\n const words = (text) => clean(text, 200) || null;\n const content = (element, at, shown, initial) => {\n const sample = kept.note(element, \"content\", at, shown, initial);\n if (sample !== void 0) seeing.look(element, sample);\n };\n /** What a text-only element said before this batch: its text with the batch undone. */\n const before = (leaf, records) => {\n let nodes = Array.from(leaf.childNodes);\n const old = /* @__PURE__ */ new Map();\n for (const record of records.toReversed()) if (record.type === \"characterData\") old.set(record.target, record.oldValue ?? \"\");\n else {\n const added = new Set(Array.from(record.addedNodes));\n nodes = nodes.filter((node) => !added.has(node));\n const next = record.nextSibling === null ? -1 : nodes.indexOf(record.nextSibling);\n nodes.splice(next === -1 ? nodes.length : next, 0, ...Array.from(record.removedNodes));\n }\n return words(nodes.map((node) => old.get(node) ?? node.textContent).join(\"\"));\n };\n const attribute = (element, { attributeName: name, oldValue: old }, at) => {\n const was = name === \"hidden\" ? old !== null : name === \"aria-hidden\" ? old === \"true\" : name === \"open\" ? element.tagName === \"DIALOG\" && old === null : name === \"style\" && hiding.test(old ?? \"\");\n if (name === \"style\" && !was && !hiding.test(element.getAttribute(\"style\") ?? \"\")) return;\n const state = seeing.state(element);\n if (!kept.has(element) && !was && state === void 0 && name !== \"open\") return seeing.glance(element);\n content(element, at, void 0, () => was || state === false ? null : name === \"open\" && old === null ? words(element.querySelector(\":scope > summary\")?.textContent) : words(element.textContent));\n };\n /** What one mutation added to and removed from `target`. */\n const nodes = (change, target, batch) => {\n const added = Array.from(change.addedNodes).slice(0, 64);\n const removed = Array.from(change.removedNodes).slice(0, 64);\n const text = [...added, ...removed].some((node) => !isElement(node) && /\\S/.test(node.textContent ?? \"\"));\n kept.lose(batch.at, Math.max(change.addedNodes.length, change.removedNodes.length) - 64);\n if (text) batch.owners.add(target);\n removed.forEach((gone, index) => {\n const node = added[index];\n if (!isElement(gone)) return;\n batch.left.add(gone);\n if (node !== void 0 && isElement(node) && kept.rekey(gone, node)) seeing.unwatch(gone);\n else if (kept.has(gone)) {\n places.set(gone, target);\n const sample = kept.note(gone, \"content\", batch.at, null, () => void 0);\n if (sample !== void 0) sample.seen = seeing.viewed(gone);\n seeing.unwatch(gone);\n }\n });\n for (const node of added) if (isElement(node) && isHtml(node) && !unwritten.has(node.tagName) && !node.isContentEditable) {\n if (kept.has(node) || !text && !batch.left.has(node)) {\n batch.arrived.add(node);\n content(node, batch.at, void 0, () => null);\n }\n }\n };\n /** Whether `element` is inside something this batch added, which tells it with its own words. */\n const inside = (element, arrived) => {\n for (let up = element.parentElement; arrived.size > 0 && up !== null; up = up.parentElement) if (arrived.has(up)) return true;\n return false;\n };\n const ownerOf = (change) => change.type === \"characterData\" ? change.target.parentElement : change.target;\n /** Mark what one batch of mutations changed, at `at`. */\n const mark = (records, at) => {\n const batch = {\n at,\n owners: /* @__PURE__ */ new Set(),\n arrived: /* @__PURE__ */ new Set(),\n left: /* @__PURE__ */ new Set()\n };\n let byOwner;\n for (const change of records) {\n const target = ownerOf(change);\n if (target === null || !isElement(target) || inside(target, batch.arrived)) continue;\n const known = kept.has(target) || kept.refuses(target);\n if (change.type !== \"attributes\") if (change.type === \"characterData\" || target.childElementCount === 0 && known) batch.owners.add(target);\n else nodes(change, target, batch);\n else if (isHtml(target) && target !== document.body && target !== document.documentElement) attribute(target, change, at);\n }\n for (const owner of batch.owners) {\n const leaf = owner.childElementCount === 0;\n if (kept.refuses(owner)) kept.lose(at, 1);\n if (kept.refuses(owner) || !isHtml(owner) || unwritten.has(owner.tagName)) continue;\n if (owner === document.body || owner.isContentEditable) continue;\n if (batch.arrived.has(owner) || inside(owner, batch.arrived)) continue;\n content(owner, at, leaf ? words(owner.textContent) : void 0, () => {\n byOwner ??= Map.groupBy(records, ownerOf);\n return leaf ? before(owner, byOwner.get(owner) ?? []) : void 0;\n });\n }\n if (document.title === title) return;\n const previous = words(title);\n const sample = kept.note(document, \"title\", at, words(title = document.title), () => previous);\n if (sample !== void 0) sample.seen = true;\n };\n return {\n mark,\n /** Where a removed element was, which gives its context. */\n placeOf: (key) => places.get(key),\n /** Start afresh, from the document's title now. */\n reset: () => {\n places = /* @__PURE__ */ new WeakMap();\n title = document.title;\n }\n };\n };\n //#endregion\n //#region src/internal/timeline/record.inpage.ts\n const record = (names, texts, kept, seeing, marking) => {\n const { isElement, isInput } = names;\n const epoch = () => performance.timeOrigin + performance.now();\n const declared = \"[role=alert],[role=status],[role=log],[role=dialog],[role=alertdialog],[aria-live],dialog,[popover]\";\n let running = false;\n let lastRead = 0;\n let focused = /* @__PURE__ */ new WeakMap();\n const inputs = [];\n const targetOf = (event) => {\n const target = event.composedPath()[0];\n return target instanceof Node && isElement(target) ? target : void 0;\n };\n /** A field's value as the record keeps it: a secret one's as `••••`, a box's checked or not. */\n const valueOf = (field) => isInput(field) && (field.type === \"checkbox\" || field.type === \"radio\") ? field.checked ? \"checked\" : \"not checked\" : texts.shown(field, true);\n const onFocus = (event) => {\n const field = targetOf(event);\n const value = field === void 0 ? void 0 : valueOf(field);\n if (field !== void 0 && value !== void 0) focused.set(field, value);\n };\n const onValue = (event) => {\n const field = targetOf(event);\n const value = field === void 0 ? void 0 : valueOf(field);\n if (field === void 0 || value === void 0) return;\n const sample = kept.note(field, \"value\", epoch(), value, () => focused.get(field) ?? null);\n if (sample !== void 0) seeing.look(field, sample);\n };\n const onInput = (event) => {\n const target = targetOf(event);\n if (!event.isTrusted || target === void 0) return;\n inputs.push({\n at: epoch(),\n target\n });\n if (inputs.length > 8) inputs.shift();\n };\n const listeners = [\n [\"focusin\", onFocus],\n [\"input\", onValue],\n [\"change\", onValue],\n [\"pointerdown\", onInput],\n [\"keydown\", onInput]\n ];\n const options = {\n capture: true,\n passive: true\n };\n const stop = () => {\n running = false;\n document.removeEventListener(\"DOMContentLoaded\", begin);\n observer.disconnect();\n for (const [type, listener] of listeners) document.removeEventListener(type, listener, options);\n seeing.clear();\n kept.clear();\n kept.forgotten();\n inputs.length = 0;\n focused = /* @__PURE__ */ new WeakMap();\n };\n const observer = new MutationObserver((records) => {\n const at = epoch();\n if (at - lastRead > 12e4) stop();\n else marking.mark(records, at);\n });\n const begin = () => {\n if (!running || kept.begun()) return;\n observer.observe(document, {\n subtree: true,\n childList: true,\n characterData: true,\n characterDataOldValue: true,\n attributeFilter: [\n \"hidden\",\n \"open\",\n \"aria-hidden\",\n \"class\",\n \"style\"\n ],\n attributeOldValue: true\n });\n for (const [type, listener] of listeners) document.addEventListener(type, listener, options);\n marking.reset();\n for (const element of Array.from(document.querySelectorAll(declared)).slice(0, 64)) seeing.glance(element, true);\n kept.begin(epoch());\n };\n return {\n stop,\n /** Record from now, once the document is parsed; each read keeps the record going. */\n start: () => {\n lastRead = epoch();\n if (running) return;\n running = true;\n if (document.readyState === \"loading\") document.addEventListener(\"DOMContentLoaded\", begin, { once: true });\n else begin();\n },\n inputs: () => inputs\n };\n };\n //#endregion\n //#region src/internal/timeline/sight.inpage.ts\n const sight = (names, walked, texts, kept) => {\n const { clean } = names;\n const { visible } = walked;\n let viewed = /* @__PURE__ */ new WeakMap();\n let watching = /* @__PURE__ */ new WeakSet();\n let states = /* @__PURE__ */ new WeakMap();\n const waiting = /* @__PURE__ */ new Map();\n /** What an element shows: its words, if its style shows it. */\n const shownBy = (element) => element.isConnected && visible(element) ? clean(texts.lines(element, false), 200) || null : null;\n /** Settle what waited on an element; its words are read once, if one of them needs them. */\n const judge = (element, pending, seen, was) => {\n const shown = pending.some((sample) => sample.shown === void 0) ? shownBy(element) : void 0;\n for (const sample of pending) {\n const now = sample.shown === void 0 ? shown : sample.shown;\n kept.settle(element, sample, now, now === null ? was : seen);\n }\n };\n const observer = new IntersectionObserver((entries) => {\n for (const { target, isIntersecting } of entries) {\n const was = viewed.get(target) ?? false;\n const seen = isIntersecting && visible(target);\n const pending = waiting.get(target);\n viewed.set(target, seen);\n waiting.delete(target);\n if (pending !== void 0) judge(target, pending, seen, was);\n if (!kept.has(target)) {\n states.set(target, visible(target));\n unwatch(target);\n }\n }\n });\n /** Watch an element, asking for a fresh report even if it is watched already. */\n const watch = (element) => {\n watching.add(element);\n observer.unobserve(element);\n observer.observe(element);\n };\n const unwatch = (element) => {\n watching.delete(element);\n observer.unobserve(element);\n };\n return {\n /** Judge a sample at once if what it shows and whether it is in view are known, else on render. */\n look: (element, sample) => {\n const view = viewed.get(element);\n if (sample.shown !== void 0 && view !== void 0 && watching.has(element)) {\n sample.seen = view;\n return;\n }\n waiting.set(element, [...waiting.get(element) ?? [], sample]);\n watch(element);\n },\n /**\n * Look at an element once, for its state when it next changes: as it renders, or `now`, by its\n * style, as for the few the record looks at as it starts.\n */\n glance: (element, now = false) => {\n if (now) states.set(element, visible(element));\n if (!watching.has(element)) watch(element);\n },\n /** Whether the style of an element looked at once showed it, if it was. */\n state: (element) => states.get(element),\n /** Whether a watched element was in view as the page last rendered it. */\n viewed: (element) => viewed.get(element) ?? false,\n unwatch,\n /** Judge now what the page has not rendered since it changed, as a hidden tab never does. */\n settle: () => {\n for (const [element, pending] of waiting) {\n const seen = element.isConnected && walked.inView(element.getBoundingClientRect()) && visible(element);\n judge(element, pending, seen, viewed.get(element) ?? false);\n viewed.set(element, seen);\n }\n waiting.clear();\n for (const key of kept.forgotten()) if (key instanceof Element) unwatch(key);\n },\n clear: () => {\n observer.disconnect();\n waiting.clear();\n viewed = /* @__PURE__ */ new WeakMap();\n watching = /* @__PURE__ */ new WeakSet();\n states = /* @__PURE__ */ new WeakMap();\n }\n };\n };\n //#endregion\n //#region src/internal/page/bridge.ts\n const parts = {\n elements,\n names,\n walk,\n match,\n context,\n subjects,\n states,\n expectations,\n text,\n controls,\n fold,\n history,\n sight,\n marks,\n record,\n changes,\n ready,\n outline,\n targets,\n evidence,\n guard,\n edit,\n addresses\n };\n function install(parts) {\n const source = install.toString() + Object.entries(parts).map(([name, factory]) => name + factory.toString()).join(\"\");\n let version = 2166136261;\n for (let index = 0; index < source.length; index++) version = Math.imul(version ^ source.charCodeAt(index), 16777619);\n version >>>= 0;\n const installed = globalThis.__effectBrowser;\n if (installed !== void 0 && installed.version === version) return installed;\n installed?.dispose?.();\n const named = parts.names(parts.elements());\n if (installed?.refs !== void 0) named.refs.next = installed.refs.next;\n const walked = parts.walk(named);\n const placing = parts.context(named, walked);\n const matching = parts.match();\n const subjected = parts.subjects(named, walked, matching, placing, parts.states(named));\n const texts = parts.text(named, walked);\n const controlled = parts.controls(named, subjected, texts);\n const kept = parts.history(parts.fold());\n const seeing = parts.sight(named, walked, texts, kept);\n const marking = parts.marks(named, kept, seeing);\n const recorder = parts.record(named, texts, kept, seeing, marking);\n const read = parts.outline(named, walked, subjected, texts, controlled, parts.addresses());\n const located = parts.targets(named, walked, placing);\n const guarded = parts.guard(named, located, parts.evidence(named, placing));\n const edited = parts.edit(named, guarded, placing);\n const readiness = parts.ready(walked, texts, kept);\n const api = {\n version,\n refs: named.refs,\n dispose: () => recorder.stop(),\n snapshot: read.snapshot,\n find: subjected.find,\n until: parts.expectations(named, subjected, matching).until,\n text: texts.read,\n record: recorder.start,\n stopRecord: recorder.stop,\n changes: parts.changes(named, placing, kept, seeing, marking, recorder).read,\n ready: readiness.wait,\n settle: readiness.settle,\n point: located.point,\n scrollPlan: located.scrollPlan,\n viewport: read.viewport,\n screenSize: () => ({\n width: screen.width,\n height: screen.height\n }),\n prepareInput: guarded.prepareInput,\n validateInput: guarded.validateInput,\n typeable: edited.typeable,\n focus: edited.focus,\n focusOn: edited.focusOn,\n select: edited.select\n };\n globalThis.__effectBrowser = api;\n return api;\n }\n //#endregion\n return install(parts);\n})();\n\nreturn pageScript;})()";
|
|
501
|
+
const documentScripts = (clockName, scripts) => [...clockName === void 0 ? [] : [`${clockSource}(${encodeString(clockName)})`], ...scripts.map(({ match, source }) => match === void 0 ? source : `if (${String(match)}.test(location.href)) {\n${source}\n}`)];
|
|
690
502
|
const worldName = "effect-browser";
|
|
691
503
|
const recorderSource = `if (globalThis === globalThis.top) globalThis.__effectBrowser?.record();`;
|
|
692
504
|
const missing = "effect-browser: no __effectBrowser in this world";
|
|
693
|
-
const missingSource =
|
|
505
|
+
const missingSource = encodeString(missing);
|
|
694
506
|
const isMissing = (error) => error.reason._tag === "Failed" && error.reason.detail === missing;
|
|
695
507
|
const Evaluated = Schema.Struct({
|
|
696
508
|
value: Schema.optionalKey(Schema.Unknown),
|
|
@@ -763,7 +575,7 @@ const registrationFor = Effect.fnUntraced(function* (page) {
|
|
|
763
575
|
removeRecorder
|
|
764
576
|
};
|
|
765
577
|
});
|
|
766
|
-
const make$
|
|
578
|
+
const make$27 = Effect.fnUntraced(function* (page) {
|
|
767
579
|
const { id, cdp, native, span, publish, now } = page;
|
|
768
580
|
const { send } = page.protocol;
|
|
769
581
|
const { ensure, removeRecorder } = yield* registrationFor(page);
|
|
@@ -886,6 +698,102 @@ const make$22 = Effect.fnUntraced(function* (page) {
|
|
|
886
698
|
};
|
|
887
699
|
});
|
|
888
700
|
//#endregion
|
|
701
|
+
//#region src/internal/page/dialogs.ts
|
|
702
|
+
/** Scoped dialog responses publish their actual outcome and invalidate their page after failed answers. */
|
|
703
|
+
/**
|
|
704
|
+
* What a page's own Playwright events publish, its close and crash aside, while its scope is
|
|
705
|
+
* open. Dialogs are answered: alerts accepted, others dismissed. The page's own session tells its
|
|
706
|
+
* documents' commits and loads.
|
|
707
|
+
*/
|
|
708
|
+
const listen = Effect.fnUntraced(function* (playwright, page, publish, now, answer, on) {
|
|
709
|
+
const dialogs = yield* Queue.bounded(8);
|
|
710
|
+
const dialog = (shown) => {
|
|
711
|
+
if (!Queue.offerUnsafe(dialogs, {
|
|
712
|
+
kind: shown.type(),
|
|
713
|
+
message: shown.message().slice(0, 500)
|
|
714
|
+
})) on.failed();
|
|
715
|
+
};
|
|
716
|
+
yield* Queue.take(dialogs).pipe(Effect.flatMap(({ kind, message }) => {
|
|
717
|
+
const accept = kind === "alert" || kind === "beforeunload";
|
|
718
|
+
const record = (answer) => Effect.sync(() => {
|
|
719
|
+
publish(new DialogShown({
|
|
720
|
+
at: now(),
|
|
721
|
+
page,
|
|
722
|
+
kind,
|
|
723
|
+
message,
|
|
724
|
+
answer
|
|
725
|
+
}));
|
|
726
|
+
});
|
|
727
|
+
return answer(accept).pipe(Effect.tap(() => record(accept ? "accepted" : "dismissed")), Effect.tapError(() => record("failed").pipe(Effect.andThen(Effect.sync(on.failed)))));
|
|
728
|
+
}), Effect.forever, Effect.forkScoped);
|
|
729
|
+
yield* Effect.acquireRelease(Effect.sync(() => {
|
|
730
|
+
playwright.on("close", on.close);
|
|
731
|
+
playwright.on("crash", on.crash);
|
|
732
|
+
playwright.on("dialog", dialog);
|
|
733
|
+
}), () => Effect.sync(() => {
|
|
734
|
+
playwright.off("close", on.close);
|
|
735
|
+
playwright.off("crash", on.crash);
|
|
736
|
+
playwright.off("dialog", dialog);
|
|
737
|
+
}));
|
|
738
|
+
});
|
|
739
|
+
//#endregion
|
|
740
|
+
//#region src/internal/page/identity.ts
|
|
741
|
+
/** Connection identity uses the supplied SecureRandom service, or the host's Web Crypto on Node/Bun. */
|
|
742
|
+
const failed = () => undispatched("make", new Failed({ detail: "Could not name connection" }));
|
|
743
|
+
const make$26 = Effect.gen(function* () {
|
|
744
|
+
const supplied = yield* Effect.serviceOption(SecureRandom.SecureRandom);
|
|
745
|
+
return yield* Option.isSome(supplied) ? supplied.value.uuidV4() : Effect.try({
|
|
746
|
+
try: () => globalThis.crypto.randomUUID(),
|
|
747
|
+
catch: failed
|
|
748
|
+
});
|
|
749
|
+
});
|
|
750
|
+
//#endregion
|
|
751
|
+
//#region src/internal/page/openings.ts
|
|
752
|
+
/** A page's input waits for the actual tabs it opened to finish the browser's registration. */
|
|
753
|
+
const make$25 = Effect.fnUntraced(function* (playwright, cdp, registrations, closedBy) {
|
|
754
|
+
const failed = (reason) => Exit.fail(undispatched("newPage", reason));
|
|
755
|
+
let active;
|
|
756
|
+
const gone = Deferred.makeUnsafe();
|
|
757
|
+
const windowOpened = () => {
|
|
758
|
+
if (active !== void 0) active.windows += 1;
|
|
759
|
+
};
|
|
760
|
+
const popup = (opened) => {
|
|
761
|
+
if (active === void 0) return;
|
|
762
|
+
const registered = registrations.get(opened);
|
|
763
|
+
active.registrations.push(registered === void 0 ? failed(new Failed({ detail: "the popup has no registration" })) : Deferred.await(registered).pipe(Effect.asVoid));
|
|
764
|
+
Deferred.doneUnsafe(active.changed, Exit.void);
|
|
765
|
+
active.changed = Deferred.makeUnsafe();
|
|
766
|
+
};
|
|
767
|
+
const clear = Effect.sync(() => {
|
|
768
|
+
active = void 0;
|
|
769
|
+
});
|
|
770
|
+
yield* Effect.acquireRelease(Effect.sync(() => {
|
|
771
|
+
cdp.on("Page.windowOpen", windowOpened);
|
|
772
|
+
playwright.on("popup", popup);
|
|
773
|
+
}), () => Effect.sync(() => {
|
|
774
|
+
active = void 0;
|
|
775
|
+
cdp.off("Page.windowOpen", windowOpened);
|
|
776
|
+
playwright.off("popup", popup);
|
|
777
|
+
Deferred.doneUnsafe(gone, failed(new Closed({ cause: closedBy() })));
|
|
778
|
+
}));
|
|
779
|
+
return {
|
|
780
|
+
mark: () => {
|
|
781
|
+
const mark = {
|
|
782
|
+
windows: 0,
|
|
783
|
+
registrations: [],
|
|
784
|
+
changed: Deferred.makeUnsafe()
|
|
785
|
+
};
|
|
786
|
+
active = mark;
|
|
787
|
+
return mark;
|
|
788
|
+
},
|
|
789
|
+
clear,
|
|
790
|
+
settle: (mark) => Effect.gen(function* () {
|
|
791
|
+
while (mark.registrations.length < mark.windows) yield* Deferred.await(mark.changed);
|
|
792
|
+
yield* Effect.forEach(mark.registrations, (registration) => registration);
|
|
793
|
+
}).pipe(Effect.raceFirst(Deferred.await(gone)), Effect.ensuring(clear))
|
|
794
|
+
};
|
|
795
|
+
});
|
|
796
|
+
//#endregion
|
|
889
797
|
//#region src/internal/input/dispatch.ts
|
|
890
798
|
/**
|
|
891
799
|
* Sending input to the browser. Each mouse event, key and inserted text goes out on the page's
|
|
@@ -906,7 +814,7 @@ const buttonAt = (type, point, button = "left", clickCount = 1) => ({
|
|
|
906
814
|
buttons: type === "mousePressed" ? buttonMask[button] : 0,
|
|
907
815
|
clickCount
|
|
908
816
|
});
|
|
909
|
-
const make$
|
|
817
|
+
const make$24 = (page) => {
|
|
910
818
|
const { id, pointer, publish, now, noteInput, closedBy } = page;
|
|
911
819
|
const { send } = page.protocol;
|
|
912
820
|
const inputClocks = /* @__PURE__ */ new WeakMap();
|
|
@@ -1008,7 +916,7 @@ const inputFailure = (operation, targets, failure) => {
|
|
|
1008
916
|
return failWith(operation, failure.error === "outside" ? new InvalidRequest({ detail: failure.detail }) : failure.error === "stale" && typeof target === "string" ? new StaleRef({ ref: target }) : new NotActionable({ detail: failure.detail }));
|
|
1009
917
|
};
|
|
1010
918
|
const editFailure = (operation, ref, failure) => failWith(operation, failure.stale === true ? new StaleRef({ ref }) : new NotActionable({ detail: failure.error }));
|
|
1011
|
-
const make$
|
|
919
|
+
const make$23 = (page, bridge) => {
|
|
1012
920
|
const { id } = page;
|
|
1013
921
|
const { current, evaluateIn, evaluateWithContext } = bridge;
|
|
1014
922
|
const preparePolicy = (asked, info, targets, flags = {}) => Effect.gen(function* () {
|
|
@@ -1076,7 +984,7 @@ const make$20 = (page, bridge) => {
|
|
|
1076
984
|
* Keys and typing: a key chord held and released, each typed event, and the document a run of
|
|
1077
985
|
* keys must stay in.
|
|
1078
986
|
*/
|
|
1079
|
-
const make$
|
|
987
|
+
const make$22 = (page, bridge, dispatch) => {
|
|
1080
988
|
const { playwright } = page;
|
|
1081
989
|
const key = (direction, part) => {
|
|
1082
990
|
const run = () => playwright.keyboard[direction](part);
|
|
@@ -1203,12 +1111,25 @@ const admission = (page, pending, name) => {
|
|
|
1203
1111
|
end: Effect.sync(() => end?.())
|
|
1204
1112
|
};
|
|
1205
1113
|
};
|
|
1114
|
+
/** Announce an action from what it has found, then wait for its style's lead. */
|
|
1115
|
+
const announcing = (page, name, style, acted) => (to) => Effect.gen(function* () {
|
|
1116
|
+
const event = new ActionAnnounced({
|
|
1117
|
+
at: page.now(),
|
|
1118
|
+
page: page.id,
|
|
1119
|
+
name,
|
|
1120
|
+
correlation: yield* Correlation,
|
|
1121
|
+
...yield* Ref.get(acted),
|
|
1122
|
+
...to
|
|
1123
|
+
});
|
|
1124
|
+
page.publish(event);
|
|
1125
|
+
if (style.lead !== void 0) yield* style.lead(event);
|
|
1126
|
+
});
|
|
1206
1127
|
/** Close a run on every exit while preserving its native replies for the page's next input. */
|
|
1207
1128
|
const useRun = (page, sender, name, run, action, canStop) => action.pipe(Effect.tapError((error) => error.reason._tag === "Closed" ? run.close : run.close.pipe(Effect.andThen(sender.flush(name, run)), Effect.ignore)), Effect.tap(() => run.close.pipe(Effect.andThen(sender.flush(name, run)))), Effect.ensuring(run.close.pipe(Effect.andThen(page.openings.clear))), Effect.onError(() => run.recover(page.stopLoading, page.scope).pipe(Effect.when(canStop))), Effect.provideService(Current, run));
|
|
1208
|
-
const make$
|
|
1129
|
+
const make$21 = (page, sender) => {
|
|
1209
1130
|
const { id, settings, mapping, lane, publish, now, noteInput, span, owned } = page;
|
|
1210
1131
|
const { inputClocks } = sender;
|
|
1211
|
-
const input = make$
|
|
1132
|
+
const input = make$29();
|
|
1212
1133
|
const admitted = /* @__PURE__ */ new Set();
|
|
1213
1134
|
const perform = (value, info, timeout, prepare, body) => {
|
|
1214
1135
|
const name = nameOf(value);
|
|
@@ -1238,6 +1159,7 @@ const make$18 = (page, sender) => {
|
|
|
1238
1159
|
touched: touch,
|
|
1239
1160
|
at: (point) => Ref.set(at, Option.some(point)),
|
|
1240
1161
|
on: (subject, to) => Ref.set(acted, actedOn(subject, to)),
|
|
1162
|
+
announce: announcing(page, name, style, acted),
|
|
1241
1163
|
reveal: Effect.sync(() => {
|
|
1242
1164
|
revealed = true;
|
|
1243
1165
|
})
|
|
@@ -1295,8 +1217,13 @@ const make$18 = (page, sender) => {
|
|
|
1295
1217
|
to,
|
|
1296
1218
|
box,
|
|
1297
1219
|
text: info.text === void 0 ? void 0 : revealed ? info.text.slice(0, 200) : redacted,
|
|
1298
|
-
|
|
1299
|
-
|
|
1220
|
+
...Option.match(point, {
|
|
1221
|
+
onNone: () => ({}),
|
|
1222
|
+
onSome: ({ x, y }) => ({
|
|
1223
|
+
x,
|
|
1224
|
+
y
|
|
1225
|
+
})
|
|
1226
|
+
}),
|
|
1300
1227
|
ok: Exit.isSuccess(exit),
|
|
1301
1228
|
dispatched,
|
|
1302
1229
|
error: Option.match(failure, {
|
|
@@ -1323,12 +1250,13 @@ const make$18 = (page, sender) => {
|
|
|
1323
1250
|
* plan, published before its first move, from where viewers last saw the pointer when it is
|
|
1324
1251
|
* shown, and a wheel scroll goes in the style's steps.
|
|
1325
1252
|
*/
|
|
1326
|
-
const make$
|
|
1253
|
+
const make$20 = (page, dispatch, viewport) => {
|
|
1327
1254
|
const { id, pointer, publish, now, span } = page;
|
|
1328
1255
|
const { inputClocks, inputCall, dispatchMouse, sendMouse } = dispatch;
|
|
1329
1256
|
const moveTo = (operation, marks, to, cursor, travel = "approach") => Effect.gen(function* () {
|
|
1330
1257
|
const dragging = travel === "drag";
|
|
1331
1258
|
const { style } = marks;
|
|
1259
|
+
if (travel === "approach" || travel === "hover") yield* marks.announce(to);
|
|
1332
1260
|
const drawn = style.pointer ?? pointer;
|
|
1333
1261
|
const size = yield* viewport.viewportFor(operation);
|
|
1334
1262
|
const previous = Option.getOrElse(MutableRef.get(drawn), () => ({
|
|
@@ -1361,7 +1289,7 @@ const make$17 = (page, dispatch, viewport) => {
|
|
|
1361
1289
|
for (const sample of samples) {
|
|
1362
1290
|
const remaining = at + sample.afterMillis - now();
|
|
1363
1291
|
if (remaining > 0) yield* Effect.sleep(Duration.millis(remaining));
|
|
1364
|
-
yield* travel === "approach" ? marks.touched : marks.sent;
|
|
1292
|
+
yield* travel === "approach" || travel === "reveal" ? marks.touched : marks.sent;
|
|
1365
1293
|
yield* inputCall(operation, run.send(() => dispatchMouse({
|
|
1366
1294
|
type: "mouseMoved",
|
|
1367
1295
|
x: sample.x,
|
|
@@ -1421,7 +1349,7 @@ const make$17 = (page, dispatch, viewport) => {
|
|
|
1421
1349
|
* next look's to see. A tab the input opened waits for the browser's registration too.
|
|
1422
1350
|
*/
|
|
1423
1351
|
const settling = Duration.seconds(5);
|
|
1424
|
-
const make$
|
|
1352
|
+
const make$19 = (page, bridge) => {
|
|
1425
1353
|
const document = () => bridge.frameTag().document;
|
|
1426
1354
|
let parsed = -1;
|
|
1427
1355
|
let changed = Deferred.makeUnsafe();
|
|
@@ -1461,7 +1389,7 @@ const resolvedTarget = ({ x, y, box, ...target }) => new ResolvedTarget({
|
|
|
1461
1389
|
box,
|
|
1462
1390
|
...target
|
|
1463
1391
|
});
|
|
1464
|
-
const make$
|
|
1392
|
+
const make$18 = (viewport, guard, pointer, dispatch, settling) => {
|
|
1465
1393
|
const { evaluate, mutate } = guard;
|
|
1466
1394
|
const { moveTo, wheel } = pointer;
|
|
1467
1395
|
const { flush } = dispatch;
|
|
@@ -1483,7 +1411,7 @@ const make$15 = (viewport, guard, pointer, dispatch, settling) => {
|
|
|
1483
1411
|
y: plan.y
|
|
1484
1412
|
};
|
|
1485
1413
|
yield* marks.at(point);
|
|
1486
|
-
yield* moveTo(operation, marks, point);
|
|
1414
|
+
yield* moveTo(operation, marks, point, void 0, "reveal");
|
|
1487
1415
|
const before = settling.mark();
|
|
1488
1416
|
yield* wheel(operation, marks, point, Math.max(-size.width * .9, Math.min(size.width * .9, plan.dx)), Math.max(-size.height * .9, Math.min(size.height * .9, plan.dy)));
|
|
1489
1417
|
yield* flush(operation, marks.input);
|
|
@@ -1508,19 +1436,19 @@ const make$15 = (viewport, guard, pointer, dispatch, settling) => {
|
|
|
1508
1436
|
* then waits for the page to settle: a task and a frame, and a document if the input asked for one.
|
|
1509
1437
|
*/
|
|
1510
1438
|
const partsOf = (page, bridge, viewport) => {
|
|
1511
|
-
const dispatch = make$
|
|
1512
|
-
const pointer = make$
|
|
1513
|
-
const guard = make$
|
|
1514
|
-
const settling = make$
|
|
1439
|
+
const dispatch = make$24(page);
|
|
1440
|
+
const pointer = make$20(page, dispatch, viewport);
|
|
1441
|
+
const guard = make$23(page, bridge);
|
|
1442
|
+
const settling = make$19(page, bridge);
|
|
1515
1443
|
return {
|
|
1516
1444
|
page,
|
|
1517
1445
|
...settling,
|
|
1518
1446
|
viewportFor: viewport.viewportFor,
|
|
1519
|
-
perform: make$
|
|
1447
|
+
perform: make$21(page, dispatch),
|
|
1520
1448
|
...guard,
|
|
1521
|
-
...make$
|
|
1449
|
+
...make$18(viewport, guard, pointer, dispatch, settling),
|
|
1522
1450
|
...pointer,
|
|
1523
|
-
...make$
|
|
1451
|
+
...make$22(page, bridge, dispatch),
|
|
1524
1452
|
sendMouse: dispatch.sendMouse,
|
|
1525
1453
|
flush: dispatch.flush
|
|
1526
1454
|
};
|
|
@@ -1787,7 +1715,7 @@ const select = (input) => {
|
|
|
1787
1715
|
return result.detail;
|
|
1788
1716
|
}));
|
|
1789
1717
|
};
|
|
1790
|
-
const make$
|
|
1718
|
+
const make$17 = (page, bridge, viewport) => {
|
|
1791
1719
|
const parts = partsOf(page, bridge, viewport);
|
|
1792
1720
|
return {
|
|
1793
1721
|
perform: parts.perform,
|
|
@@ -2037,8 +1965,8 @@ const orderedFrame = (frame, previous) => frame.hostTime < previous && frame.tim
|
|
|
2037
1965
|
//#region src/internal/pictures/quiescence.ts
|
|
2038
1966
|
/** Actual native replies outlive callers; bounded transactions retain them without holding teardown. */
|
|
2039
1967
|
const deadline$1 = Duration.seconds(2);
|
|
2040
|
-
const make$
|
|
2041
|
-
const replies = make$
|
|
1968
|
+
const make$16 = (options) => {
|
|
1969
|
+
const replies = make$29();
|
|
2042
1970
|
const pending = /* @__PURE__ */ new Map();
|
|
2043
1971
|
const late = (kind) => options.error(/* @__PURE__ */ new Error(`${kind} exceeded its deadline`));
|
|
2044
1972
|
const track = (operation, actual, failed) => {
|
|
@@ -2218,7 +2146,7 @@ const reader = (acquire, leave, why, lost) => (settings = {}) => Effect.acquireR
|
|
|
2218
2146
|
current: lease.frame,
|
|
2219
2147
|
stream: frames(lease.subscription, lease.baseline, why, lost)
|
|
2220
2148
|
})));
|
|
2221
|
-
const make$
|
|
2149
|
+
const make$15 = (options) => Effect.gen(function* () {
|
|
2222
2150
|
const lock = yield* Semaphore.make(1);
|
|
2223
2151
|
const replies = /* @__PURE__ */ new Set();
|
|
2224
2152
|
let generation;
|
|
@@ -2280,7 +2208,7 @@ const make$12 = (options) => Effect.gen(function* () {
|
|
|
2280
2208
|
const gone = () => options.error(/* @__PURE__ */ new Error("Target page has been closed"));
|
|
2281
2209
|
const why = told(closed, gone, options.clock);
|
|
2282
2210
|
const awaitStop = (current) => pictures.wait("screencast stop").pipe(Effect.catch((error) => Effect.sync(() => notifyFailure(current, error))));
|
|
2283
|
-
const pictures = make$
|
|
2211
|
+
const pictures = make$16({
|
|
2284
2212
|
clock: options.clock,
|
|
2285
2213
|
error: options.error,
|
|
2286
2214
|
closed: isClosed,
|
|
@@ -2392,7 +2320,6 @@ const make$12 = (options) => Effect.gen(function* () {
|
|
|
2392
2320
|
})))));
|
|
2393
2321
|
return {
|
|
2394
2322
|
open,
|
|
2395
|
-
stream: (options) => Stream.unwrap(Effect.map(open(options), ({ stream }) => stream)),
|
|
2396
2323
|
latest: Effect.sync(() => latest),
|
|
2397
2324
|
recent: Effect.sync(() => history),
|
|
2398
2325
|
active: Effect.sync(() => generation !== void 0 && generation.state._tag !== "Stopped"),
|
|
@@ -2668,26 +2595,66 @@ const calibrator = (page, bridge) => {
|
|
|
2668
2595
|
};
|
|
2669
2596
|
const ScreenSize = Schema.Struct({
|
|
2670
2597
|
width: Schema.Int,
|
|
2671
|
-
height: Schema.Int
|
|
2598
|
+
height: Schema.Int,
|
|
2599
|
+
ratio: Schema.Finite
|
|
2672
2600
|
});
|
|
2673
|
-
const
|
|
2601
|
+
const device = (page, bridge) => {
|
|
2674
2602
|
const { playwright, native, within } = page;
|
|
2675
2603
|
const { send } = page.protocol;
|
|
2676
|
-
let
|
|
2677
|
-
let
|
|
2604
|
+
let screen;
|
|
2605
|
+
let scaled = 0;
|
|
2606
|
+
let painting = false;
|
|
2607
|
+
const metrics = (operation) => native(operation, () => send("Emulation.setDeviceMetricsOverride", {
|
|
2608
|
+
width: 0,
|
|
2609
|
+
height: 0,
|
|
2610
|
+
deviceScaleFactor: scaled,
|
|
2611
|
+
mobile: false,
|
|
2612
|
+
...screen === void 0 ? {} : {
|
|
2613
|
+
screenWidth: screen.width,
|
|
2614
|
+
screenHeight: screen.height
|
|
2615
|
+
}
|
|
2616
|
+
}));
|
|
2617
|
+
const screenOf = (operation) => bridge.evaluate(operation, scriptCall("screenSize")).pipe(Effect.flatMap(decodeWith(operation, ScreenSize)));
|
|
2678
2618
|
const holdScreen = Effect.fnUntraced(function* (operation) {
|
|
2679
|
-
if (
|
|
2680
|
-
const { width, height } = yield*
|
|
2681
|
-
|
|
2682
|
-
width
|
|
2683
|
-
height
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
screenWidth: width,
|
|
2687
|
-
screenHeight: height
|
|
2688
|
-
}));
|
|
2689
|
-
screenHeld = true;
|
|
2619
|
+
if (screen !== void 0) return;
|
|
2620
|
+
const { width, height } = yield* screenOf(operation);
|
|
2621
|
+
screen = {
|
|
2622
|
+
width,
|
|
2623
|
+
height
|
|
2624
|
+
};
|
|
2625
|
+
yield* metrics(operation).pipe(Effect.onError(() => Effect.sync(() => screen = void 0)));
|
|
2690
2626
|
});
|
|
2627
|
+
const scrollbarsHidden = (hidden) => native("paint", () => send("Emulation.setScrollbarsHidden", { hidden }));
|
|
2628
|
+
const paint = (options) => Effect.gen(function* () {
|
|
2629
|
+
const { scale, scrollbars = true } = options;
|
|
2630
|
+
const launched = playwright.viewportSize() !== null;
|
|
2631
|
+
if (scale !== void 0 && !(Number.isFinite(scale) && scale > 0 && scale <= 4)) return yield* refuse("paint", "a page paints at more than 0 and at most 4 device pixels");
|
|
2632
|
+
if (painting) return yield* refuse("paint", "the page is painted for another scope already");
|
|
2633
|
+
if (scale !== void 0 && launched && (yield* screenOf("paint")).ratio !== scale) return yield* refuse("paint", "this browser paints at the scale it was launched with, as Chromium's deviceScaleFactor sets");
|
|
2634
|
+
const rescaled = scale !== void 0 && !launched;
|
|
2635
|
+
painting = true;
|
|
2636
|
+
yield* Effect.addFinalizer(() => Effect.gen(function* () {
|
|
2637
|
+
scaled = 0;
|
|
2638
|
+
if (!scrollbars) yield* scrollbarsHidden(false);
|
|
2639
|
+
if (rescaled) yield* metrics("paint");
|
|
2640
|
+
}).pipe(Effect.ignore, Effect.ensuring(Effect.sync(() => painting = false))));
|
|
2641
|
+
if (!scrollbars) yield* scrollbarsHidden(true);
|
|
2642
|
+
if (rescaled) {
|
|
2643
|
+
scaled = scale;
|
|
2644
|
+
yield* metrics("paint");
|
|
2645
|
+
}
|
|
2646
|
+
}).pipe(within("paint"));
|
|
2647
|
+
return {
|
|
2648
|
+
holdScreen,
|
|
2649
|
+
paint,
|
|
2650
|
+
scaled: () => scaled
|
|
2651
|
+
};
|
|
2652
|
+
};
|
|
2653
|
+
const camera = (page, viewport, capture, { holdScreen, scaled }) => {
|
|
2654
|
+
const { playwright, native, within } = page;
|
|
2655
|
+
const { send } = page.protocol;
|
|
2656
|
+
let ratio = 1;
|
|
2657
|
+
const layoutMetrics = (operation) => native(operation, () => send("Page.getLayoutMetrics")).pipe(Effect.flatMap(decodeWith(operation, LayoutMetrics)));
|
|
2691
2658
|
const decoded = (operation, data, format) => {
|
|
2692
2659
|
const size = format === "png" ? pngSize(data) : jpegSize(data);
|
|
2693
2660
|
return size === void 0 ? failWith(operation, new Failed({ detail: `the browser's picture is not a ${format.toUpperCase()}` })) : Effect.succeed(new Image({
|
|
@@ -2724,9 +2691,9 @@ const camera = (page, bridge, viewport, capture) => {
|
|
|
2724
2691
|
if (whole !== void 0) ratio = whole.width / emulated.width;
|
|
2725
2692
|
return yield* emulatedShot(operation, format, quality, pixels, crop);
|
|
2726
2693
|
}
|
|
2727
|
-
const [
|
|
2728
|
-
const
|
|
2729
|
-
ratio = Number.isFinite(
|
|
2694
|
+
const [measured] = yield* layoutMetrics(operation).pipe(Effect.zip(crop === void 0 ? Effect.void : holdScreen(operation), { concurrent: true }));
|
|
2695
|
+
const measuredRatio = measured.contentSize.width / measured.cssContentSize.width;
|
|
2696
|
+
ratio = scaled() > 0 ? scaled() : Number.isFinite(measuredRatio) && measuredRatio > 0 ? measuredRatio : 1;
|
|
2730
2697
|
if (crop === void 0 && ratio === 1) {
|
|
2731
2698
|
const image = whole ?? (yield* shot(operation, format, quality));
|
|
2732
2699
|
viewport.remember(image);
|
|
@@ -2737,7 +2704,7 @@ const camera = (page, bridge, viewport, capture) => {
|
|
|
2737
2704
|
y: 0,
|
|
2738
2705
|
...known ?? (yield* viewport.viewportFor(operation))
|
|
2739
2706
|
};
|
|
2740
|
-
const { pageX, pageY, scale } =
|
|
2707
|
+
const { pageX, pageY, scale } = measured.cssVisualViewport;
|
|
2741
2708
|
yield* holdScreen(operation);
|
|
2742
2709
|
return yield* shot(operation, format, quality, {
|
|
2743
2710
|
x: pageX + rect.x,
|
|
@@ -2748,13 +2715,10 @@ const camera = (page, bridge, viewport, capture) => {
|
|
|
2748
2715
|
});
|
|
2749
2716
|
}).pipe(capture.excluding, within(operation));
|
|
2750
2717
|
};
|
|
2751
|
-
const
|
|
2752
|
-
onNone: () => NaN,
|
|
2753
|
-
onSome: Duration.toMillis
|
|
2754
|
-
});
|
|
2755
|
-
const reuse = (page, bridge, viewport, capture) => (operation, options) => Effect.gen(function* () {
|
|
2718
|
+
const reuse = (page, bridge, viewport, capture) => (options) => Effect.gen(function* () {
|
|
2756
2719
|
const maxAge = millisOf(options.maxAge ?? defaultMaxAge);
|
|
2757
|
-
if (!(maxAge >= 0)) return yield* refuse(
|
|
2720
|
+
if (!(maxAge >= 0)) return yield* refuse("frame", "maxAge must be a duration of zero or more");
|
|
2721
|
+
if (options.format === "png" || options.scale === "device") return Option.none();
|
|
2758
2722
|
const latest = yield* capture.latest;
|
|
2759
2723
|
const known = viewport.knownViewport();
|
|
2760
2724
|
const { activity } = page;
|
|
@@ -2765,11 +2729,11 @@ const reuse = (page, bridge, viewport, capture) => (operation, options) => Effec
|
|
|
2765
2729
|
});
|
|
2766
2730
|
/** Where a picture came from: a frame the screencast had delivered, or a new screenshot. */
|
|
2767
2731
|
const sourceOf = (reused) => Option.isSome(reused) ? "frame" : "screenshot";
|
|
2768
|
-
const make$
|
|
2732
|
+
const make$14 = Effect.fnUntraced(function* (page, bridge, viewport) {
|
|
2769
2733
|
const { id, clock, settings, mapping, now, span, owned, lane, within } = page;
|
|
2770
2734
|
const calibrateClock = calibrator(page, bridge);
|
|
2771
2735
|
const error = (cause) => Schema.is(BrowserError)(cause) ? cause : undispatched("screencast", reasonOf(cause, void 0, page.closedBy()));
|
|
2772
|
-
const capture = yield* make$
|
|
2736
|
+
const capture = yield* make$15({
|
|
2773
2737
|
id,
|
|
2774
2738
|
transport: (page.capture === void 0 ? Effect.succeed(own(page, bridge)) : apart(page, bridge, page.capture, error, yield* Effect.scope)).pipe(Effect.provideService(Current$1, yield* Current$1)),
|
|
2775
2739
|
clock,
|
|
@@ -2787,38 +2751,21 @@ const make$11 = Effect.fnUntraced(function* (page, bridge, viewport) {
|
|
|
2787
2751
|
imageSize: jpegSize,
|
|
2788
2752
|
error
|
|
2789
2753
|
});
|
|
2790
|
-
const
|
|
2754
|
+
const emulated = device(page, bridge);
|
|
2755
|
+
const picture = camera(page, viewport, capture, emulated);
|
|
2791
2756
|
const reusable = reuse(page, bridge, viewport, capture);
|
|
2792
|
-
const screenshots = lane.shared("screenshot", false);
|
|
2793
2757
|
const frames = lane.shared("frame", false);
|
|
2794
|
-
const screenshot = (options = {}) => screenshots(JSON.stringify([
|
|
2795
|
-
millisOf(options.maxAge ?? defaultMaxAge),
|
|
2796
|
-
options.clip,
|
|
2797
|
-
options.quality,
|
|
2798
|
-
options.format,
|
|
2799
|
-
options.scale
|
|
2800
|
-
]), Effect.gen(function* () {
|
|
2801
|
-
const reused = options.clip === void 0 && options.format !== "png" && options.scale !== "device" ? yield* reusable("screenshot", {
|
|
2802
|
-
maxAge: options.maxAge,
|
|
2803
|
-
after: "input"
|
|
2804
|
-
}) : Option.none();
|
|
2805
|
-
const image = Option.isSome(reused) ? reused.value.image : yield* picture("screenshot", options.quality ?? 80, options.clip, options.format, options.scale);
|
|
2806
|
-
yield* Effect.annotateCurrentSpan({
|
|
2807
|
-
source: sourceOf(reused),
|
|
2808
|
-
bytes: image.data.length
|
|
2809
|
-
});
|
|
2810
|
-
return image;
|
|
2811
|
-
})).pipe(span("Page.screenshot"), owned);
|
|
2812
2758
|
const taken = (options) => Effect.gen(function* () {
|
|
2813
|
-
const reused = yield* reusable(
|
|
2759
|
+
const reused = yield* reusable(options);
|
|
2814
2760
|
yield* Effect.annotateCurrentSpan("source", sourceOf(reused));
|
|
2815
2761
|
if (Option.isSome(reused)) return reused.value;
|
|
2816
2762
|
const startedAt = now();
|
|
2817
|
-
const image = yield* picture("frame", 80);
|
|
2763
|
+
const image = yield* picture("frame", options.quality ?? 80, void 0, options.format, options.scale);
|
|
2818
2764
|
const finishedAt = now();
|
|
2819
2765
|
return new Frame({
|
|
2820
2766
|
page: id,
|
|
2821
2767
|
data: image.data,
|
|
2768
|
+
mediaType: image.mediaType,
|
|
2822
2769
|
timing: new Screenshot({
|
|
2823
2770
|
hostTime: startedAt + (finishedAt - startedAt) / 2,
|
|
2824
2771
|
uncertaintyMillis: (finishedAt - startedAt) / 2
|
|
@@ -2829,21 +2776,27 @@ const make$11 = Effect.fnUntraced(function* (page, bridge, viewport) {
|
|
|
2829
2776
|
...bridge.frameTag()
|
|
2830
2777
|
});
|
|
2831
2778
|
});
|
|
2832
|
-
const frame = (options = {}) => (options.after === "input" ? Effect.succeed(Option.none()) : reusable(
|
|
2779
|
+
const frame = (options = {}) => (options.after === "input" ? Effect.succeed(Option.none()) : reusable(options)).pipe(Effect.flatMap(Option.match({
|
|
2833
2780
|
onSome: (reused) => Effect.as(Effect.annotateCurrentSpan("source", "frame"), reused),
|
|
2834
|
-
onNone: () => frames(JSON.stringify([
|
|
2835
|
-
|
|
2781
|
+
onNone: () => frames(JSON.stringify([
|
|
2782
|
+
millisOf(options.maxAge ?? defaultMaxAge),
|
|
2783
|
+
options.after,
|
|
2784
|
+
options.quality,
|
|
2785
|
+
options.format,
|
|
2786
|
+
options.scale
|
|
2787
|
+
]), taken(options))
|
|
2788
|
+
})), span("Frame.read"), owned);
|
|
2836
2789
|
const zoom = (requested, options = {}) => lane.read("zoom")(Effect.gen(function* () {
|
|
2837
2790
|
const region = yield* Schema.decodeEffect(Region)(requested).pipe(Effect.mapError((error) => undispatched("zoom", new InvalidRequest({ detail: error.message }))));
|
|
2838
2791
|
const size = viewport.knownViewport() ?? (yield* viewport.viewportFor("zoom"));
|
|
2839
2792
|
if (region.x + region.width > size.width || region.y + region.height > size.height) return yield* refuse("zoom", "the crop must fit entirely within the viewport");
|
|
2840
|
-
const image = yield* picture("zoom", 80, region,
|
|
2793
|
+
const image = yield* picture("zoom", options.quality ?? 80, region, options.format, options.scale);
|
|
2841
2794
|
return new Zoom({
|
|
2842
2795
|
page: id,
|
|
2843
2796
|
region,
|
|
2844
2797
|
image
|
|
2845
2798
|
});
|
|
2846
|
-
}).pipe(within("zoom"))).pipe(span("
|
|
2799
|
+
}).pipe(within("zoom"))).pipe(span("Frame.zoom"), owned);
|
|
2847
2800
|
const captureStats = (options = {}) => {
|
|
2848
2801
|
if (options.window === void 0) return capture.stats();
|
|
2849
2802
|
const millis = millisOf(options.window);
|
|
@@ -2851,32 +2804,110 @@ const make$11 = Effect.fnUntraced(function* (page, bridge, viewport) {
|
|
|
2851
2804
|
};
|
|
2852
2805
|
return {
|
|
2853
2806
|
capture,
|
|
2854
|
-
screenshot,
|
|
2855
2807
|
frame,
|
|
2856
2808
|
zoom,
|
|
2857
2809
|
captureStats,
|
|
2858
|
-
estimate: mapping.current(calibrateClock)
|
|
2810
|
+
estimate: mapping.current(calibrateClock),
|
|
2811
|
+
paint: emulated.paint
|
|
2859
2812
|
};
|
|
2860
2813
|
});
|
|
2861
2814
|
//#endregion
|
|
2815
|
+
//#region src/internal/reading/layout.ts
|
|
2816
|
+
/**
|
|
2817
|
+
* Reading where things are: `Layout.measure`, in one call to the page that takes its turn as other
|
|
2818
|
+
* reads do and shares its work with identical ones. The page gives each place's viewport box; the
|
|
2819
|
+
* document box is that box moved by the scroll read with it.
|
|
2820
|
+
*/
|
|
2821
|
+
const LayoutResult = Schema.Union([Schema.Struct({ layout: Schema.Struct({
|
|
2822
|
+
url: Schema.String,
|
|
2823
|
+
viewport: Schema.Struct({
|
|
2824
|
+
width: Schema.Finite,
|
|
2825
|
+
height: Schema.Finite
|
|
2826
|
+
}),
|
|
2827
|
+
scroll: Point,
|
|
2828
|
+
scale: Schema.Finite,
|
|
2829
|
+
missing: Schema.Array(Schema.String),
|
|
2830
|
+
places: Schema.Array(Schema.Struct({
|
|
2831
|
+
id: Schema.String,
|
|
2832
|
+
ref: Schema.String,
|
|
2833
|
+
subject: Subject,
|
|
2834
|
+
box: Box,
|
|
2835
|
+
fixed: Schema.Boolean,
|
|
2836
|
+
words: Schema.optional(Schema.Array(Schema.Struct({
|
|
2837
|
+
text: Schema.String,
|
|
2838
|
+
box: Box
|
|
2839
|
+
})))
|
|
2840
|
+
}))
|
|
2841
|
+
}) }), Schema.Struct({ invalid: Schema.String })]);
|
|
2842
|
+
const make$13 = (page, bridge) => {
|
|
2843
|
+
const { now, span, owned, within, lane } = page;
|
|
2844
|
+
const { evaluate } = bridge;
|
|
2845
|
+
const layouts = lane.shared("layout", true);
|
|
2846
|
+
const layout = (picks) => {
|
|
2847
|
+
const asked = pickRequests(picks);
|
|
2848
|
+
const once = Effect.gen(function* () {
|
|
2849
|
+
const before = bridge.frameTag().document;
|
|
2850
|
+
const result = yield* evaluate("layout", scriptCall("layout", asked)).pipe(Effect.flatMap(decodeWith("layout", LayoutResult)));
|
|
2851
|
+
if ("invalid" in result) return yield* refuse("layout", result.invalid);
|
|
2852
|
+
if (bridge.frameTag().document !== before) return yield* failWith("layout", new NotActionable({ detail: "the page's document changed while it was read" }));
|
|
2853
|
+
const { places, scroll, ...read } = result.layout;
|
|
2854
|
+
const moved = (box) => ({
|
|
2855
|
+
...box,
|
|
2856
|
+
x: box.x + scroll.x,
|
|
2857
|
+
y: box.y + scroll.y
|
|
2858
|
+
});
|
|
2859
|
+
return new Layout({
|
|
2860
|
+
...read,
|
|
2861
|
+
url: redact(read.url),
|
|
2862
|
+
page: page.id,
|
|
2863
|
+
connection: page.connection,
|
|
2864
|
+
document: before,
|
|
2865
|
+
at: now(),
|
|
2866
|
+
scroll,
|
|
2867
|
+
places: places.map(({ words, ...place }) => new Place({
|
|
2868
|
+
...place,
|
|
2869
|
+
page: moved(place.box),
|
|
2870
|
+
words: words?.map((word) => new Word({
|
|
2871
|
+
...word,
|
|
2872
|
+
page: moved(word.box)
|
|
2873
|
+
}))
|
|
2874
|
+
}))
|
|
2875
|
+
});
|
|
2876
|
+
});
|
|
2877
|
+
return layouts(JSON.stringify(asked), once.pipe(Effect.retry({
|
|
2878
|
+
times: 1,
|
|
2879
|
+
while: (error) => contextGone(error) || error.reason._tag === "NotActionable" && error.operation === "layout"
|
|
2880
|
+
}), within("layout"))).pipe(span("Layout.measure", { picks: asked.length }), owned);
|
|
2881
|
+
};
|
|
2882
|
+
return layout;
|
|
2883
|
+
};
|
|
2884
|
+
//#endregion
|
|
2862
2885
|
//#region src/internal/reading/reading.ts
|
|
2863
2886
|
/**
|
|
2864
2887
|
* Reading a page: its outline with refs, the elements a query finds and the text it shows. Each
|
|
2865
2888
|
* read takes its turn on the page and shares its work with identical reads, as `lane.ts`
|
|
2866
|
-
* describes.
|
|
2889
|
+
* describes.
|
|
2867
2890
|
*/
|
|
2891
|
+
/** The outline as a `Snapshot` reads it, or why `within` is not a selector. */
|
|
2892
|
+
const SnapshotResultSchema = Schema.Union([Schema.Struct({ snapshot: Snapshot }), Schema.Struct({ invalid: Schema.String })]);
|
|
2893
|
+
/** What `text` sends back, or null when its ref no longer names an element. */
|
|
2894
|
+
const TextResultSchema = Schema.NullOr(Schema.Struct({
|
|
2895
|
+
text: Schema.String,
|
|
2896
|
+
truncated: Schema.Boolean,
|
|
2897
|
+
url: Schema.String,
|
|
2898
|
+
title: Schema.String
|
|
2899
|
+
}));
|
|
2868
2900
|
const FindResults = Schema.Union([Schema.Struct({ found: Schema.Array(Found) }), Schema.Struct({ invalid: Schema.String })]);
|
|
2869
2901
|
const UntilResult = Schema.Union([Schema.Struct({
|
|
2870
2902
|
met: Schema.Boolean,
|
|
2871
2903
|
mark: Schema.String
|
|
2872
2904
|
}), Schema.Struct({ invalid: Schema.String })]);
|
|
2873
|
-
const make$
|
|
2905
|
+
const make$12 = (page, bridge) => Effect.sync(() => {
|
|
2874
2906
|
const { now, span, owned, within, lane } = page;
|
|
2875
2907
|
const { evaluate } = bridge;
|
|
2876
2908
|
const snapshots = lane.shared("snapshot", true);
|
|
2877
2909
|
const finds = lane.shared("find", true);
|
|
2878
2910
|
const texts = lane.shared("text", true);
|
|
2879
|
-
let viewed;
|
|
2880
2911
|
const snapshot = (snapshotOptions = {}) => {
|
|
2881
2912
|
const asked = {
|
|
2882
2913
|
full: snapshotOptions.full ?? false,
|
|
@@ -2897,7 +2928,7 @@ const make$10 = (page, bridge) => Effect.sync(() => {
|
|
|
2897
2928
|
...result.snapshot,
|
|
2898
2929
|
url: redact(url)
|
|
2899
2930
|
});
|
|
2900
|
-
}).pipe(within("snapshot"))).pipe(span("
|
|
2931
|
+
}).pipe(within("snapshot"))).pipe(span("Snapshot.read", { full: asked.full }), owned);
|
|
2901
2932
|
};
|
|
2902
2933
|
const find = (query = {}) => {
|
|
2903
2934
|
const asked = request(query, "viewport");
|
|
@@ -2906,7 +2937,7 @@ const make$10 = (page, bridge) => Effect.sync(() => {
|
|
|
2906
2937
|
if ("invalid" in result) return yield* refuse("find", result.invalid);
|
|
2907
2938
|
yield* Effect.annotateCurrentSpan({ found: result.found.length });
|
|
2908
2939
|
return result.found;
|
|
2909
|
-
}).pipe(within("find"))).pipe(span("
|
|
2940
|
+
}).pipe(within("find"))).pipe(span("Snapshot.find", {
|
|
2910
2941
|
scope: asked.scope,
|
|
2911
2942
|
role: asked.role ?? ""
|
|
2912
2943
|
}), owned);
|
|
@@ -2925,14 +2956,12 @@ const make$10 = (page, bridge) => Effect.sync(() => {
|
|
|
2925
2956
|
chars: result.text.length,
|
|
2926
2957
|
truncated: result.truncated
|
|
2927
2958
|
});
|
|
2928
|
-
|
|
2959
|
+
return new Text({
|
|
2929
2960
|
...result,
|
|
2930
2961
|
url: redact(result.url),
|
|
2931
2962
|
at: now()
|
|
2932
2963
|
});
|
|
2933
|
-
|
|
2934
|
-
return shown;
|
|
2935
|
-
}).pipe(within("text")))).pipe(span("Page.text", { scope: scope === "viewport" ? "viewport" : "ref" }), owned);
|
|
2964
|
+
}).pipe(within("text")))).pipe(span("Text.read", { scope: scope === "viewport" ? "viewport" : "ref" }), owned);
|
|
2936
2965
|
};
|
|
2937
2966
|
const until = (query, want, millis) => {
|
|
2938
2967
|
if (!Number.isFinite(millis) || millis < 0) return refuse("until", "the wait duration must be finite and nonnegative");
|
|
@@ -2947,26 +2976,34 @@ const make$10 = (page, bridge) => Effect.sync(() => {
|
|
|
2947
2976
|
mark: ""
|
|
2948
2977
|
})));
|
|
2949
2978
|
});
|
|
2950
|
-
return lane.read("expect")(Effect.void).pipe(Effect.andThen(look), within("expect", Duration.sum(Duration.millis(millis), page.settings.actionTimeout)), span("
|
|
2979
|
+
return lane.read("expect")(Effect.void).pipe(Effect.andThen(look), within("expect", Duration.sum(Duration.millis(millis), page.settings.actionTimeout)), span("Snapshot.until", { want: typeof want === "string" ? want : "other" }), owned);
|
|
2951
2980
|
};
|
|
2952
|
-
/** The viewport's text as it was last read, if after `since`, as a document began. */
|
|
2953
|
-
const viewedSince = (since) => viewed !== void 0 && viewed.at > since ? viewed : void 0;
|
|
2954
2981
|
return {
|
|
2955
2982
|
snapshot,
|
|
2956
2983
|
find,
|
|
2957
2984
|
text,
|
|
2958
|
-
until
|
|
2959
|
-
viewedSince
|
|
2985
|
+
until
|
|
2960
2986
|
};
|
|
2961
2987
|
});
|
|
2962
2988
|
//#endregion
|
|
2963
2989
|
//#region src/internal/reading/ready.ts
|
|
2964
2990
|
/** Document readiness and content quiet, independent of screen-capture features. */
|
|
2965
|
-
|
|
2966
|
-
|
|
2967
|
-
|
|
2991
|
+
/** What the page is still waiting for; none when it is ready. */
|
|
2992
|
+
const ReadinessSchema = Schema.Array(Schema.Literals([
|
|
2993
|
+
"load",
|
|
2994
|
+
"paint",
|
|
2995
|
+
"animations",
|
|
2996
|
+
"images",
|
|
2997
|
+
"fonts",
|
|
2998
|
+
"busy",
|
|
2999
|
+
"content",
|
|
3000
|
+
"changing"
|
|
3001
|
+
]));
|
|
3002
|
+
const make$11 = (page, bridge) => (options = {}) => {
|
|
3003
|
+
const quietMillis = millisOf(options.quiet ?? 0);
|
|
3004
|
+
if (!Number.isFinite(quietMillis) || quietMillis < 0) return refuse("ready", "quiet must be a finite nonnegative duration");
|
|
2968
3005
|
const timeout = options.timeout ?? Duration.seconds(15);
|
|
2969
|
-
const settled = (until) => Effect.suspend(() => bridge.evaluate("ready", scriptCall("ready", Math.max(0, Math.round(until - page.now())), quietMillis))).pipe(Effect.retry({
|
|
3006
|
+
const settled = (until) => Effect.suspend(() => bridge.evaluate("ready", scriptCall("ready", Math.max(0, Math.round(until - page.now())), quietMillis, page.settings.pageTime ?? null))).pipe(Effect.retry({
|
|
2970
3007
|
while: contextGone,
|
|
2971
3008
|
schedule: Schedule.spaced(Duration.millis(10))
|
|
2972
3009
|
}), Effect.flatMap(decodeWith("ready", ReadinessSchema)), Effect.tap((waiting) => Effect.annotateCurrentSpan({ waiting: waiting.join(",") })), Effect.filterOrElse((waiting) => waiting.length === 0, () => failWith("ready", new Timeout({ millis: Duration.toMillis(timeout) }))));
|
|
@@ -2984,9 +3021,19 @@ const make$9 = (page, bridge) => (options = {}) => {
|
|
|
2984
3021
|
* identical ones in flight share it; none is kept for a later caller, since its window ends when
|
|
2985
3022
|
* it was read.
|
|
2986
3023
|
*/
|
|
3024
|
+
/**
|
|
3025
|
+
* What a read sends back: its window and the record's state, and each change as `Change` encodes
|
|
3026
|
+
* it, all on the page's clock.
|
|
3027
|
+
*/
|
|
3028
|
+
const ChangesResultSchema = Schema.Struct({
|
|
3029
|
+
until: Schema.Finite,
|
|
3030
|
+
from: Schema.Finite,
|
|
3031
|
+
dropped: Schema.Int,
|
|
3032
|
+
records: Schema.Array(Change)
|
|
3033
|
+
});
|
|
2987
3034
|
const isChanges = Schema.is(Changes);
|
|
2988
3035
|
const markOf = (time) => time === void 0 || typeof time === "number" ? time : isChanges(time) ? `cursor ${time.cursor}` : `frame ${time.timestamp ?? time.hostTime}`;
|
|
2989
|
-
const make$
|
|
3036
|
+
const make$10 = (page, bridge, estimate) => {
|
|
2990
3037
|
const reads = page.lane.shared("changes", false);
|
|
2991
3038
|
const recording = Semaphore.makeUnsafe(1);
|
|
2992
3039
|
const idleMillis = 12e4;
|
|
@@ -3044,7 +3091,7 @@ const make$8 = (page, bridge, estimate) => {
|
|
|
3044
3091
|
cause: later(one.cause)
|
|
3045
3092
|
}))
|
|
3046
3093
|
});
|
|
3047
|
-
}).pipe(page.within("changes"))).pipe(page.span("
|
|
3094
|
+
}).pipe(page.within("changes"))).pipe(page.span("Change.read"), page.owned);
|
|
3048
3095
|
};
|
|
3049
3096
|
//#endregion
|
|
3050
3097
|
//#region src/internal/timeline/window.ts
|
|
@@ -3077,7 +3124,7 @@ const within = ({ since, until }, events, frames) => ({
|
|
|
3077
3124
|
events: events.filter((event) => event.at > since && event.at <= until && !isTrackEvent(event)),
|
|
3078
3125
|
frames: frames.filter((frame) => frame.hostTime >= since && frame.hostTime <= until)
|
|
3079
3126
|
});
|
|
3080
|
-
const make$
|
|
3127
|
+
const make$9 = (page, read, frames) => ({ since, until, unmask }) => Effect.gen(function* () {
|
|
3081
3128
|
const asked = boundsOf({
|
|
3082
3129
|
since,
|
|
3083
3130
|
until
|
|
@@ -3096,7 +3143,7 @@ const make$7 = (page, read, frames) => ({ since, until, unmask }) => Effect.gen(
|
|
|
3096
3143
|
changes: Result.getOrUndefined(changes),
|
|
3097
3144
|
missing: Option.toArray(Result.getFailure(changes))
|
|
3098
3145
|
});
|
|
3099
|
-
}).pipe(page.span("
|
|
3146
|
+
}).pipe(page.span("Window.read"), page.owned);
|
|
3100
3147
|
//#endregion
|
|
3101
3148
|
//#region src/internal/page/navigation.ts
|
|
3102
3149
|
/**
|
|
@@ -3104,7 +3151,7 @@ const make$7 = (page, read, frames) => ({ since, until, unmask }) => Effect.gen(
|
|
|
3104
3151
|
* Each move is an action, so it takes the page's turn, goes through the input guard and is
|
|
3105
3152
|
* recorded, but it sends no input.
|
|
3106
3153
|
*/
|
|
3107
|
-
const make$
|
|
3154
|
+
const make$8 = (page, perform, preparePolicy) => {
|
|
3108
3155
|
const { playwright, settings, native } = page;
|
|
3109
3156
|
const { send } = page.protocol;
|
|
3110
3157
|
const navigation = (value, run, address) => {
|
|
@@ -3190,6 +3237,86 @@ const make$6 = (page, perform, preparePolicy) => {
|
|
|
3190
3237
|
};
|
|
3191
3238
|
};
|
|
3192
3239
|
//#endregion
|
|
3240
|
+
//#region src/internal/page/overlay.ts
|
|
3241
|
+
/**
|
|
3242
|
+
* The page's overlay: one lease at a time, each drawing one call to the page, in turn after the
|
|
3243
|
+
* actions asked before it, never two at once. Each new document gets what was last drawn once it
|
|
3244
|
+
* has loaded; the lease's scope takes the layer away.
|
|
3245
|
+
*/
|
|
3246
|
+
const Drawn = Schema.Array(Box);
|
|
3247
|
+
const make$7 = (page, bridge) => {
|
|
3248
|
+
const { lane, owned, span, within } = page;
|
|
3249
|
+
const turns = Semaphore.makeUnsafe(1);
|
|
3250
|
+
let open = false;
|
|
3251
|
+
let shown = null;
|
|
3252
|
+
let drawn = [];
|
|
3253
|
+
const record = (markup, boxes) => {
|
|
3254
|
+
shown = markup;
|
|
3255
|
+
drawn = boxes;
|
|
3256
|
+
page.noteInput();
|
|
3257
|
+
};
|
|
3258
|
+
const send = (markup) => turns.withPermit(lane.read("overlay")(bridge.evaluate("overlay", scriptCall("overlay", markup)).pipe(Effect.flatMap(decodeWith("overlay", Drawn)), Effect.tap((boxes) => Effect.sync(() => record(markup, boxes))), within("overlay"))));
|
|
3259
|
+
const draw = (content) => send(content._tag === "Svg" ? content.markup : null).pipe(span("Overlay.draw"), owned);
|
|
3260
|
+
const redraw = (document) => bridge.waitForDocument(document).pipe(Effect.andThen(Effect.void.pipe(Effect.repeat({
|
|
3261
|
+
schedule: Schedule.spaced(Duration.millis(50)),
|
|
3262
|
+
until: () => bridge.loaded() !== void 0
|
|
3263
|
+
}), within("overlay", page.settings.navigationTimeout))), Effect.andThen(Effect.suspend(() => shown === null ? Effect.void : send(shown))), Effect.ignore);
|
|
3264
|
+
return {
|
|
3265
|
+
lease: Effect.gen(function* () {
|
|
3266
|
+
if (open) return yield* refuse("overlay", "the page has an overlay already");
|
|
3267
|
+
open = true;
|
|
3268
|
+
yield* Effect.addFinalizer(() => Effect.suspend(() => {
|
|
3269
|
+
open = false;
|
|
3270
|
+
return shown === null ? Effect.void : send(null).pipe(Effect.ignore);
|
|
3271
|
+
}));
|
|
3272
|
+
yield* Effect.forkScoped(Effect.suspend(() => redraw(bridge.frameTag().document)).pipe(Effect.forever));
|
|
3273
|
+
return { draw };
|
|
3274
|
+
}),
|
|
3275
|
+
drawn: () => shown === null ? void 0 : drawn,
|
|
3276
|
+
open: () => open,
|
|
3277
|
+
record,
|
|
3278
|
+
/** Run a call that draws in the overlay's turn, so no other drawing overtakes it. */
|
|
3279
|
+
turn: (effect) => turns.withPermit(effect)
|
|
3280
|
+
};
|
|
3281
|
+
};
|
|
3282
|
+
//#endregion
|
|
3283
|
+
//#region src/internal/page/pose.ts
|
|
3284
|
+
/**
|
|
3285
|
+
* The page's poses: one lease at a time, each `set` one call to the page in the page's turn, as an
|
|
3286
|
+
* action takes it, so no action resolves a target that a pose then moves. The lease's scope takes
|
|
3287
|
+
* every pose off. See `Pose`.
|
|
3288
|
+
*/
|
|
3289
|
+
/** What posing answered: nothing, or the ref it could not pose and why. */
|
|
3290
|
+
const Posed = Schema.Struct({
|
|
3291
|
+
stale: Schema.optional(Schema.String),
|
|
3292
|
+
invalid: Schema.optional(Schema.String)
|
|
3293
|
+
});
|
|
3294
|
+
const make$6 = (page, bridge) => {
|
|
3295
|
+
const { lane, owned, span, within } = page;
|
|
3296
|
+
let open = false;
|
|
3297
|
+
/** The page's requests for `poses`, each part left out made the one that changes nothing. */
|
|
3298
|
+
const requests = Effect.fnUntraced(function* (operation, poses) {
|
|
3299
|
+
const decoded = yield* Schema.decodeEffect(Schema.Array(Pose))(poses).pipe(Effect.catch(() => refuse(operation, "each pose is a ref and finite numbers")));
|
|
3300
|
+
if (decoded.length > 256) return yield* refuse(operation, "at most 256 elements are posed at once");
|
|
3301
|
+
return decoded.map(poseRequest);
|
|
3302
|
+
});
|
|
3303
|
+
/** Fail as the page's answer says, if it posed nothing. */
|
|
3304
|
+
const answered = (operation, posed) => posed.stale !== void 0 ? failWith(operation, new StaleRef({ ref: posed.stale })) : posed.invalid !== void 0 ? refuse(operation, posed.invalid) : Effect.void;
|
|
3305
|
+
const send = (operation, script) => lane.write(operation, page.settings.actionTimeout)(bridge.evaluate(operation, script).pipe(Effect.flatMap(decodeWith(operation, Posed)), Effect.flatMap((posed) => answered(operation, posed)), Effect.tap(() => Effect.sync(page.noteInput)), within(operation)));
|
|
3306
|
+
const set = (poses) => requests("pose", poses).pipe(Effect.flatMap((made) => send("pose", scriptCall("pose", made))), span("Poses.set"), owned);
|
|
3307
|
+
return {
|
|
3308
|
+
lease: Effect.gen(function* () {
|
|
3309
|
+
if (open) return yield* refuse("pose", "the page's poses are open already");
|
|
3310
|
+
open = true;
|
|
3311
|
+
yield* Effect.addFinalizer(() => send("pose", scriptCall("unpose")).pipe(Effect.ignore, Effect.ensuring(Effect.sync(() => open = false))));
|
|
3312
|
+
return { set };
|
|
3313
|
+
}),
|
|
3314
|
+
open: () => open,
|
|
3315
|
+
requests,
|
|
3316
|
+
answered
|
|
3317
|
+
};
|
|
3318
|
+
};
|
|
3319
|
+
//#endregion
|
|
3193
3320
|
//#region src/internal/page/scripts.ts
|
|
3194
3321
|
/** Main-world scripts with the page lane, document binding, policy and dispatch accounting. */
|
|
3195
3322
|
const make$5 = (page, bridge, input) => {
|
|
@@ -3248,6 +3375,75 @@ const make$5 = (page, bridge, input) => {
|
|
|
3248
3375
|
};
|
|
3249
3376
|
};
|
|
3250
3377
|
//#endregion
|
|
3378
|
+
//#region src/internal/page/time.ts
|
|
3379
|
+
/**
|
|
3380
|
+
* Holding a page's time: one hold at a time, each step one call to the page that takes the page
|
|
3381
|
+
* to itself, as an action does, so no read sees a step half made. See `PageTime`.
|
|
3382
|
+
*/
|
|
3383
|
+
const Stepped = Schema.Struct({
|
|
3384
|
+
...Posed.fields,
|
|
3385
|
+
told: Schema.Boolean,
|
|
3386
|
+
drawn: Schema.NullOr(Schema.Array(Box)),
|
|
3387
|
+
scroll: Point
|
|
3388
|
+
});
|
|
3389
|
+
const make$4 = (page, bridge, overlays, posing) => {
|
|
3390
|
+
const { lane, owned, span, within } = page;
|
|
3391
|
+
let holding = false;
|
|
3392
|
+
const step = (operation, request) => {
|
|
3393
|
+
const sent = lane.write(operation, page.settings.actionTimeout)(bridge.evaluate(operation, scriptCall("step", request)).pipe(Effect.flatMap(decodeWith(operation, Stepped)), Effect.tap(({ drawn }) => Effect.sync(() => {
|
|
3394
|
+
if (drawn !== null && request.markup !== void 0) overlays.record(request.markup, drawn);
|
|
3395
|
+
page.noteInput();
|
|
3396
|
+
})), within(operation))).pipe(span(`PageTime.${operation}`), owned);
|
|
3397
|
+
return request.markup === void 0 ? sent : overlays.turn(sent);
|
|
3398
|
+
};
|
|
3399
|
+
const unclocked = (operation) => failWith(operation, new NotActionable({ detail: "the page's document has no page clock" }));
|
|
3400
|
+
return { hold: Effect.gen(function* () {
|
|
3401
|
+
const clock = page.settings.pageTime;
|
|
3402
|
+
if (clock === void 0) return yield* refuse("hold", "holding page time needs the browser's pageTime option");
|
|
3403
|
+
if (holding) return yield* refuse("hold", "the page's time is held already");
|
|
3404
|
+
holding = true;
|
|
3405
|
+
let ended = false;
|
|
3406
|
+
yield* Effect.addFinalizer(() => Effect.sync(() => ended = true).pipe(Effect.andThen(step("release", {
|
|
3407
|
+
clock,
|
|
3408
|
+
op: "release",
|
|
3409
|
+
by: 0,
|
|
3410
|
+
scroll: null
|
|
3411
|
+
})), Effect.ignore, Effect.ensuring(Effect.sync(() => holding = false))));
|
|
3412
|
+
if (!(yield* step("hold", {
|
|
3413
|
+
clock,
|
|
3414
|
+
op: "hold",
|
|
3415
|
+
by: 0,
|
|
3416
|
+
scroll: null
|
|
3417
|
+
})).told) return yield* unclocked("hold");
|
|
3418
|
+
let elapsed = 0;
|
|
3419
|
+
const advance = (by, options = {}) => Effect.gen(function* () {
|
|
3420
|
+
const millis = Option.map(Duration.fromInput(by), Duration.toMillis).pipe(Option.getOrElse(() => NaN));
|
|
3421
|
+
if (ended) return yield* refuse("advance", "the hold has ended");
|
|
3422
|
+
if (!Number.isFinite(millis) || millis < 0) return yield* refuse("advance", "page time moves on by a finite, nonnegative duration");
|
|
3423
|
+
if (options.scroll !== void 0 && !Number.isFinite(options.scroll)) return yield* refuse("advance", "the scroll must be finite");
|
|
3424
|
+
if (options.overlay !== void 0 && !overlays.open()) return yield* refuse("advance", "drawing needs the page's overlay open");
|
|
3425
|
+
if (options.poses !== void 0 && !posing.open()) return yield* refuse("advance", "posing needs the page's poses open");
|
|
3426
|
+
const poses = options.poses === void 0 ? void 0 : yield* posing.requests("advance", options.poses);
|
|
3427
|
+
const stepped = yield* step("advance", {
|
|
3428
|
+
clock,
|
|
3429
|
+
op: "advance",
|
|
3430
|
+
by: millis,
|
|
3431
|
+
scroll: options.scroll ?? null,
|
|
3432
|
+
markup: options.overlay === void 0 ? void 0 : options.overlay._tag === "Svg" ? options.overlay.markup : null,
|
|
3433
|
+
poses
|
|
3434
|
+
});
|
|
3435
|
+
yield* posing.answered("advance", stepped);
|
|
3436
|
+
if (!stepped.told) return yield* unclocked("advance");
|
|
3437
|
+
elapsed += millis;
|
|
3438
|
+
return stepped.scroll;
|
|
3439
|
+
});
|
|
3440
|
+
return {
|
|
3441
|
+
advance,
|
|
3442
|
+
elapsed: Effect.sync(() => Duration.millis(elapsed))
|
|
3443
|
+
};
|
|
3444
|
+
}) };
|
|
3445
|
+
};
|
|
3446
|
+
//#endregion
|
|
3251
3447
|
//#region src/internal/page/viewport.ts
|
|
3252
3448
|
/**
|
|
3253
3449
|
* The viewport's size in CSS pixels. Playwright knows it only for a context it created; over CDP it
|
|
@@ -3255,7 +3451,11 @@ const make$5 = (page, bridge, input) => {
|
|
|
3255
3451
|
* pixel. Pointer bounds, page scrolls, crops, capture size and frame reuse all read this one
|
|
3256
3452
|
* source; the latest answer serves checks that cannot wait for the page.
|
|
3257
3453
|
*/
|
|
3258
|
-
const
|
|
3454
|
+
const ViewportResultSchema = Schema.Struct({
|
|
3455
|
+
width: Schema.Finite,
|
|
3456
|
+
height: Schema.Finite
|
|
3457
|
+
});
|
|
3458
|
+
const make$3 = (page, bridge) => {
|
|
3259
3459
|
const { playwright } = page;
|
|
3260
3460
|
let measuredViewport = null;
|
|
3261
3461
|
const knownViewport = () => playwright.viewportSize() ?? measuredViewport;
|
|
@@ -3287,20 +3487,22 @@ const make$4 = (page, bridge) => {
|
|
|
3287
3487
|
* navigation.
|
|
3288
3488
|
* Features use the same documented Page contract as consumers.
|
|
3289
3489
|
*/
|
|
3290
|
-
const make$
|
|
3291
|
-
const page = make$
|
|
3490
|
+
const make$2 = Effect.fnUntraced(function* (options) {
|
|
3491
|
+
const page = make$28(options, yield* Effect.scope);
|
|
3292
3492
|
const { id, playwright, native, owned, within, lane, span } = page;
|
|
3293
|
-
const bridge = yield* make$
|
|
3294
|
-
const viewport = make$
|
|
3295
|
-
const input = make$
|
|
3296
|
-
const pictures = yield* make$
|
|
3297
|
-
const reading = yield* make$
|
|
3298
|
-
const navigation = make$
|
|
3493
|
+
const bridge = yield* make$27(page);
|
|
3494
|
+
const viewport = make$3(page, bridge);
|
|
3495
|
+
const input = make$17(page, bridge, viewport);
|
|
3496
|
+
const pictures = yield* make$14(page, bridge, viewport);
|
|
3497
|
+
const reading = yield* make$12(page, bridge);
|
|
3498
|
+
const navigation = make$8(page, input.perform, input.preparePolicy);
|
|
3299
3499
|
const { capture } = pictures;
|
|
3300
|
-
const changes = make$
|
|
3500
|
+
const changes = make$10(page, bridge, pictures.estimate);
|
|
3501
|
+
const overlay = make$7(page, bridge);
|
|
3502
|
+
const poses = make$6(page, bridge);
|
|
3301
3503
|
const titles = lane.shared("title", true);
|
|
3302
3504
|
const viewports = lane.shared("viewport", true);
|
|
3303
|
-
const state = Effect.
|
|
3505
|
+
const state = Effect.sync(() => {
|
|
3304
3506
|
const { document, url } = bridge.frameTag();
|
|
3305
3507
|
const committedAt = page.activity.documentAt;
|
|
3306
3508
|
return new State({
|
|
@@ -3310,9 +3512,7 @@ const make$3 = Effect.fnUntraced(function* (options) {
|
|
|
3310
3512
|
url,
|
|
3311
3513
|
document,
|
|
3312
3514
|
committedAt: Number.isFinite(committedAt) ? committedAt : void 0,
|
|
3313
|
-
load: bridge.loaded()
|
|
3314
|
-
frame: Option.getOrUndefined(latest),
|
|
3315
|
-
text: reading.viewedSince(committedAt)
|
|
3515
|
+
load: bridge.loaded()
|
|
3316
3516
|
});
|
|
3317
3517
|
});
|
|
3318
3518
|
const current = (frame) => capture.current(frame) && bridge.frameTag().document === frame.document && frame.hostTime - frame.timing.uncertaintyMillis > page.activity.documentAt;
|
|
@@ -3323,38 +3523,43 @@ const make$3 = Effect.fnUntraced(function* (options) {
|
|
|
3323
3523
|
...navigation
|
|
3324
3524
|
}, action));
|
|
3325
3525
|
return {
|
|
3526
|
+
[key]: new Implementation({
|
|
3527
|
+
snapshot: reading.snapshot,
|
|
3528
|
+
find: reading.find,
|
|
3529
|
+
until: reading.until,
|
|
3530
|
+
text: reading.text,
|
|
3531
|
+
layout: make$13(page, bridge),
|
|
3532
|
+
changes,
|
|
3533
|
+
window: make$9(page, changes, capture.recent),
|
|
3534
|
+
overlay: overlay.lease,
|
|
3535
|
+
drawn: Effect.sync(() => Option.fromUndefinedOr(overlay.drawn())),
|
|
3536
|
+
poses: poses.lease,
|
|
3537
|
+
hold: make$4(page, bridge, overlay, poses).hold,
|
|
3538
|
+
frame: pictures.frame,
|
|
3539
|
+
zoom: pictures.zoom,
|
|
3540
|
+
capture: (options) => capture.open(options).pipe(Effect.map((lease) => ({
|
|
3541
|
+
...lease,
|
|
3542
|
+
isCurrent: current,
|
|
3543
|
+
confirm,
|
|
3544
|
+
sync: capture.sync,
|
|
3545
|
+
stats: pictures.captureStats
|
|
3546
|
+
}))),
|
|
3547
|
+
recentFrames: capture.recent,
|
|
3548
|
+
paint: pictures.paint
|
|
3549
|
+
}),
|
|
3326
3550
|
...make$5(page, bridge, input),
|
|
3327
3551
|
...methods(perform),
|
|
3328
3552
|
perform,
|
|
3329
|
-
|
|
3553
|
+
hostClock: page.clock,
|
|
3330
3554
|
afterInput,
|
|
3331
|
-
until: reading.until,
|
|
3332
|
-
capture: (options) => capture.open(options).pipe(Effect.map((lease) => ({
|
|
3333
|
-
...lease,
|
|
3334
|
-
isCurrent: current,
|
|
3335
|
-
confirm,
|
|
3336
|
-
sync: capture.sync,
|
|
3337
|
-
stats: pictures.captureStats
|
|
3338
|
-
}))),
|
|
3339
3555
|
id,
|
|
3340
3556
|
url: Effect.sync(() => redact(playwright.url())),
|
|
3341
3557
|
title: titles("", navigation.title.pipe(within("title"))).pipe(span("Page.title"), owned),
|
|
3342
3558
|
bringToFront: native("bringToFront", () => playwright.bringToFront()),
|
|
3343
3559
|
close: native("close", () => playwright.close()),
|
|
3344
|
-
snapshot: reading.snapshot,
|
|
3345
|
-
screenshot: pictures.screenshot,
|
|
3346
|
-
frame: pictures.frame,
|
|
3347
|
-
zoom: pictures.zoom,
|
|
3348
3560
|
viewport: viewports("", viewport.viewportFor("viewport").pipe(within("viewport"))).pipe(span("Page.viewport"), owned),
|
|
3349
|
-
find: reading.find,
|
|
3350
|
-
text: reading.text,
|
|
3351
|
-
changes,
|
|
3352
|
-
window: make$7(page, changes, capture.recent),
|
|
3353
3561
|
state,
|
|
3354
|
-
ready: make$
|
|
3355
|
-
screencast: capture.stream,
|
|
3356
|
-
captureStats: pictures.captureStats,
|
|
3357
|
-
recentFrames: capture.recent,
|
|
3562
|
+
ready: make$11(page, bridge),
|
|
3358
3563
|
recentEvents: options.recentEvents
|
|
3359
3564
|
};
|
|
3360
3565
|
});
|
|
@@ -3422,7 +3627,7 @@ const queryTarget = async (chrome, target, method, params, signal, session, hook
|
|
|
3422
3627
|
await chrome.send("Target.detachFromTarget", { sessionId });
|
|
3423
3628
|
}
|
|
3424
3629
|
};
|
|
3425
|
-
const make$
|
|
3630
|
+
const make$1 = Effect.fnUntraced(function* (context, chrome, native, closing) {
|
|
3426
3631
|
const clock = yield* Clock.Clock;
|
|
3427
3632
|
const hooks = yield* Current$1;
|
|
3428
3633
|
const protocol = yield* Effect.context();
|
|
@@ -3594,7 +3799,7 @@ const install = Effect.fnUntraced(function* (context, policy, clock, publish, no
|
|
|
3594
3799
|
return session;
|
|
3595
3800
|
})), (chrome) => native(() => chrome.detach(), true).pipe(Effect.orDie));
|
|
3596
3801
|
let closing = false;
|
|
3597
|
-
const owner = yield* make$
|
|
3802
|
+
const owner = yield* make$1(context, chrome, native, () => closing);
|
|
3598
3803
|
const held = /* @__PURE__ */ new Map();
|
|
3599
3804
|
const pending = yield* Queue.unbounded();
|
|
3600
3805
|
const workers = yield* Scope.make();
|
|
@@ -3650,94 +3855,49 @@ const install = Effect.fnUntraced(function* (context, policy, clock, publish, no
|
|
|
3650
3855
|
yield* owner.refresh;
|
|
3651
3856
|
});
|
|
3652
3857
|
//#endregion
|
|
3653
|
-
//#region src/internal/timeline/events.ts
|
|
3654
|
-
/**
|
|
3655
|
-
* The browser's bounded event history and replay cursors. Readers share the same records and
|
|
3656
|
-
* wakeup generation, so a delayed reader cannot block input or retain an unbounded private queue.
|
|
3657
|
-
*/
|
|
3658
|
-
/** The owning Browser validates capacity and closes this timeline with its scope. */
|
|
3659
|
-
const make$1 = (capacity) => {
|
|
3660
|
-
const records = Array.from({ length: capacity });
|
|
3661
|
-
let start = 0;
|
|
3662
|
-
let size = 0;
|
|
3663
|
-
let sequence = 0;
|
|
3664
|
-
let closed = false;
|
|
3665
|
-
let changed = Deferred.makeUnsafe();
|
|
3666
|
-
const wake = () => {
|
|
3667
|
-
const previous = changed;
|
|
3668
|
-
changed = Deferred.makeUnsafe();
|
|
3669
|
-
Deferred.doneUnsafe(previous, Effect.void);
|
|
3670
|
-
};
|
|
3671
|
-
const publish = (event) => {
|
|
3672
|
-
if (closed) return sequence;
|
|
3673
|
-
sequence += 1;
|
|
3674
|
-
const recorded = new RecordedEvent({
|
|
3675
|
-
sequence,
|
|
3676
|
-
event
|
|
3677
|
-
});
|
|
3678
|
-
records[(start + size) % capacity] = recorded;
|
|
3679
|
-
if (size < capacity) size++;
|
|
3680
|
-
else start = (start + 1) % capacity;
|
|
3681
|
-
wake();
|
|
3682
|
-
return sequence;
|
|
3683
|
-
};
|
|
3684
|
-
const stream = (after) => Stream.unwrap(Effect.sync(() => {
|
|
3685
|
-
let cursor = after ?? sequence;
|
|
3686
|
-
if (!Number.isSafeInteger(cursor) || cursor < 0 || cursor > sequence) return Stream.fromEffect(refuse("events", "the event cursor must be a nonnegative integer no greater than the latest sequence"));
|
|
3687
|
-
return Stream.fromEffectRepeat(Effect.gen(function* () {
|
|
3688
|
-
while (true) {
|
|
3689
|
-
const oldest = sequence - size + 1;
|
|
3690
|
-
if (cursor < oldest - 1) return yield* undispatched("events", new EventHistoryExpired({
|
|
3691
|
-
after: cursor,
|
|
3692
|
-
oldest,
|
|
3693
|
-
latest: sequence
|
|
3694
|
-
}));
|
|
3695
|
-
const next = cursor < sequence ? records[(start + cursor - oldest + 1) % capacity] : void 0;
|
|
3696
|
-
if (next !== void 0) {
|
|
3697
|
-
cursor = next.sequence;
|
|
3698
|
-
return next;
|
|
3699
|
-
}
|
|
3700
|
-
if (closed) return yield* Cause.done();
|
|
3701
|
-
const waiting = changed;
|
|
3702
|
-
yield* Deferred.await(waiting);
|
|
3703
|
-
}
|
|
3704
|
-
}));
|
|
3705
|
-
}));
|
|
3706
|
-
return {
|
|
3707
|
-
publish,
|
|
3708
|
-
sequence: () => sequence,
|
|
3709
|
-
recent: Effect.sync(() => Array.from({ length: size }, (_, index) => records[(start + index) % capacity]).filter((record) => record !== void 0)),
|
|
3710
|
-
stream,
|
|
3711
|
-
close: Effect.sync(() => {
|
|
3712
|
-
if (closed) return;
|
|
3713
|
-
closed = true;
|
|
3714
|
-
wake();
|
|
3715
|
-
})
|
|
3716
|
-
};
|
|
3717
|
-
};
|
|
3718
|
-
//#endregion
|
|
3719
3858
|
//#region src/Browser.ts
|
|
3720
3859
|
/**
|
|
3721
3860
|
* A live browser: its pages and what happens in it.
|
|
3722
3861
|
*
|
|
3723
3862
|
* `Browser` is a service with one implementation, built by a provider over a Playwright browser
|
|
3724
3863
|
* context: `Chromium` launches one locally, `Cdp` connects to any DevTools endpoint and
|
|
3725
|
-
*
|
|
3864
|
+
* `@effect-browser/browserbase` allocates a hosted one. Code written against `Browser` runs on all three.
|
|
3726
3865
|
* A page is named by its CDP target id, so a new connection to the same browser finds it again.
|
|
3727
3866
|
*
|
|
3867
|
+
* @stability stable
|
|
3728
3868
|
* @since 0.3.0
|
|
3729
3869
|
*/
|
|
3730
3870
|
var Browser_exports = /* @__PURE__ */ __exportAll({
|
|
3731
3871
|
Browser: () => Browser,
|
|
3732
3872
|
Suspension: () => Suspension,
|
|
3733
|
-
make: () => make
|
|
3873
|
+
make: () => make,
|
|
3874
|
+
newPage: () => newPage
|
|
3734
3875
|
});
|
|
3735
|
-
/**
|
|
3736
|
-
|
|
3876
|
+
/**
|
|
3877
|
+
* When admitted input finished; events after `since` describe the handoff interval.
|
|
3878
|
+
*
|
|
3879
|
+
* @stability stable
|
|
3880
|
+
* @category schemas
|
|
3881
|
+
* @since 0.3.0
|
|
3882
|
+
*/
|
|
3883
|
+
var Suspension = class extends Schema.Class("effect-browser/Browser/Suspension")({
|
|
3737
3884
|
since: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),
|
|
3738
3885
|
at: Schema.Finite
|
|
3739
3886
|
}) {};
|
|
3887
|
+
/**
|
|
3888
|
+
* @stability stable
|
|
3889
|
+
* @category services
|
|
3890
|
+
* @since 0.3.0
|
|
3891
|
+
*/
|
|
3740
3892
|
var Browser = class extends Context.Service()("effect-browser/Browser") {};
|
|
3893
|
+
/**
|
|
3894
|
+
* Open a page in the context's `Browser`, at `url` when given.
|
|
3895
|
+
*
|
|
3896
|
+
* @stability stable
|
|
3897
|
+
* @category constructors
|
|
3898
|
+
* @since 0.3.0
|
|
3899
|
+
*/
|
|
3900
|
+
const newPage = (url) => Effect.flatMap(Browser, (browser) => browser.newPage(url));
|
|
3741
3901
|
/** The settings every page shares, and how many events the browser keeps, from its options. */
|
|
3742
3902
|
const settingsOf = Effect.fnUntraced(function* (options) {
|
|
3743
3903
|
const invalid = (detail) => undispatched("make", new InvalidRequest({ detail }));
|
|
@@ -3750,7 +3910,8 @@ const settingsOf = Effect.fnUntraced(function* (options) {
|
|
|
3750
3910
|
navigationTimeout: yield* bound("navigationTimeout", options.navigationTimeout, Duration.seconds(30)),
|
|
3751
3911
|
frameHistory: yield* bound("frameHistory", options.frameHistory, Duration.seconds(5)),
|
|
3752
3912
|
guard: options.guard,
|
|
3753
|
-
policyTimeout: yield* bound("policyTimeout", options.policyTimeout, Duration.minutes(5))
|
|
3913
|
+
policyTimeout: yield* bound("policyTimeout", options.policyTimeout, Duration.minutes(5)),
|
|
3914
|
+
pageTime: options.pageTime === true ? `effect-browser-time-${yield* make$26}` : void 0
|
|
3754
3915
|
};
|
|
3755
3916
|
if (options.viewport !== void 0 && ![options.viewport.width, options.viewport.height].every((size) => Number.isSafeInteger(size) && size > 0)) return yield* invalid("viewport dimensions must be positive safe integers");
|
|
3756
3917
|
const eventHistory = options.eventHistory ?? 4096;
|
|
@@ -3842,8 +4003,6 @@ const releaseNative = (clock) => (run) => Effect.tryPromise(run).pipe(Effect.int
|
|
|
3842
4003
|
}), Effect.provideService(Clock.Clock, clock), Effect.ignore);
|
|
3843
4004
|
/** A page's own events among the browser's retained ones, and the openings of tabs it opened. */
|
|
3844
4005
|
const eventsOf = (recent, page) => Effect.map(recent, (records) => records.flatMap(({ event }) => "page" in event && event.page === page || event._tag === "PageOpened" && event.opener === page ? [event] : []));
|
|
3845
|
-
/** A script as its documents run it: everywhere, or as a block where its `match` allows. */
|
|
3846
|
-
const scoped = ({ match, source }) => match === void 0 ? source : `if (${String(match)}.test(location.href)) {\n${source}\n}`;
|
|
3847
4006
|
/**
|
|
3848
4007
|
* At most `maxPages` open pages, those a site opened included, which are never refused: an open
|
|
3849
4008
|
* past it waits for one to close, within `wait` on the owner's clock, then fails `Limit`, or fails
|
|
@@ -3920,14 +4079,14 @@ const tabs = (context, registry, budget, native, register, release, firstPageLoc
|
|
|
3920
4079
|
/** One connection owns clocks, loss, authority and its bounded timeline. */
|
|
3921
4080
|
const runtime = Effect.fnUntraced(function* (context, expiresAt, options) {
|
|
3922
4081
|
const clock = yield* Clock.Clock;
|
|
3923
|
-
const connection = yield* make$
|
|
4082
|
+
const connection = yield* make$26;
|
|
3924
4083
|
const protocol = yield* Current$1;
|
|
3925
4084
|
const releasePort = protocol.browser?.(connection, context);
|
|
3926
4085
|
yield* Effect.addFinalizer(() => Effect.sync(() => releasePort?.()));
|
|
3927
4086
|
const now = () => monotonicMillis(clock);
|
|
3928
4087
|
const { settings, eventHistory, maxPages } = yield* settingsOf(options);
|
|
3929
4088
|
const mapping$1 = mapping(now);
|
|
3930
|
-
const timeline = make$
|
|
4089
|
+
const timeline = make$32(eventHistory);
|
|
3931
4090
|
yield* Effect.addFinalizer(() => timeline.close);
|
|
3932
4091
|
const publish = timeline.publish;
|
|
3933
4092
|
if (expiresAt !== void 0) publish(new SessionEnding({
|
|
@@ -3954,7 +4113,7 @@ const runtime = Effect.fnUntraced(function* (context, expiresAt, options) {
|
|
|
3954
4113
|
lose,
|
|
3955
4114
|
untilLost,
|
|
3956
4115
|
native,
|
|
3957
|
-
inputGate: make$
|
|
4116
|
+
inputGate: make$30({
|
|
3958
4117
|
now,
|
|
3959
4118
|
sequence: timeline.sequence,
|
|
3960
4119
|
closedBy: lostBy,
|
|
@@ -3969,6 +4128,10 @@ const runtime = Effect.fnUntraced(function* (context, expiresAt, options) {
|
|
|
3969
4128
|
* tracks its pages and events, for as long as the surrounding scope is open. Each page's protocol
|
|
3970
4129
|
* session, capture and listeners end when that page closes or when the scope does, so a closed
|
|
3971
4130
|
* tab retains nothing and the context keeps none of them afterwards.
|
|
4131
|
+
*
|
|
4132
|
+
* @stability stable
|
|
4133
|
+
* @category constructors
|
|
4134
|
+
* @since 0.3.0
|
|
3972
4135
|
*/
|
|
3973
4136
|
const make = Effect.fn("Browser.make")(function* (context, info, options = {}) {
|
|
3974
4137
|
const { clock, connection, protocol, now, settings, maxPages, mapping, timeline, publish, lostBy, lost, lose, untilLost, native, inputGate } = yield* runtime(context, info.expiresAt, options);
|
|
@@ -3994,7 +4157,7 @@ const make = Effect.fn("Browser.make")(function* (context, info, options = {}) {
|
|
|
3994
4157
|
const paging = sentNow(send("Page.enable"));
|
|
3995
4158
|
const { targetInfo } = yield* native("newPage", () => send("Target.getTargetInfo"));
|
|
3996
4159
|
const id = targetInfo.targetId;
|
|
3997
|
-
const page = yield* make$
|
|
4160
|
+
const page = yield* make$2({
|
|
3998
4161
|
id,
|
|
3999
4162
|
session,
|
|
4000
4163
|
connection,
|
|
@@ -4009,7 +4172,7 @@ const make = Effect.fn("Browser.make")(function* (context, info, options = {}) {
|
|
|
4009
4172
|
mapping,
|
|
4010
4173
|
publish,
|
|
4011
4174
|
recentEvents: eventsOf(timeline.recent, id),
|
|
4012
|
-
openings: yield* make$
|
|
4175
|
+
openings: yield* make$25(playwright, cdp, registrations, closedBy),
|
|
4013
4176
|
focused: call("focus", () => focusing, closedBy).pipe(Effect.asVoid),
|
|
4014
4177
|
paging: (operation) => call(operation, () => paging, closedBy).pipe(Effect.asVoid),
|
|
4015
4178
|
closedBy,
|
|
@@ -4051,7 +4214,7 @@ const make = Effect.fn("Browser.make")(function* (context, info, options = {}) {
|
|
|
4051
4214
|
return page;
|
|
4052
4215
|
}).pipe(Scope.provide(scope), Effect.onError(() => Scope.close(scope, Exit.void)));
|
|
4053
4216
|
});
|
|
4054
|
-
for (const
|
|
4217
|
+
for (const content of documentScripts(settings.pageTime, options.initScripts ?? [])) yield* native("initScripts", () => context.addInitScript({ content }));
|
|
4055
4218
|
const register = yield* followOpened(context, registrations, registerPage, publish, now);
|
|
4056
4219
|
for (const existing of context.pages()) yield* register(existing);
|
|
4057
4220
|
yield* Effect.addFinalizer(() => Effect.sync(() => lose("released")));
|
|
@@ -4071,6 +4234,6 @@ const make = Effect.fn("Browser.make")(function* (context, info, options = {}) {
|
|
|
4071
4234
|
return Browser.of(service);
|
|
4072
4235
|
});
|
|
4073
4236
|
//#endregion
|
|
4074
|
-
export {
|
|
4237
|
+
export { newPage as a, make as i, Browser_exports as n, make$30 as o, Suspension as r, Browser as t };
|
|
4075
4238
|
|
|
4076
|
-
//# sourceMappingURL=Browser-
|
|
4239
|
+
//# sourceMappingURL=Browser-vzD7i2oj.mjs.map
|