effect-browser 0.3.0-beta.23 → 0.3.0-beta.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +124 -5
- package/dist/ActionPort.d.mts +1 -1
- package/dist/ActionPort.mjs +1 -1
- package/dist/{Browser-BKPAbyys.mjs → Browser-CAQFhTkM.mjs} +559 -333
- package/dist/Browser-CAQFhTkM.mjs.map +1 -0
- package/dist/{Browser-wZhwZSlG.d.mts → Browser-DGR6ZEYo.d.mts} +9 -3
- package/dist/Browser.d.mts +1 -1
- package/dist/Browser.mjs +1 -1
- package/dist/{BrowserEvent-lLqJ3GJS.d.mts → BrowserEvent-C2p-NwuU.d.mts} +30 -6
- package/dist/BrowserEvent.d.mts +2 -2
- package/dist/BrowserEvent.mjs +20 -1
- package/dist/BrowserEvent.mjs.map +1 -1
- package/dist/{Change-Ba7INmay.d.mts → Change-CxT1mp2e.d.mts} +13 -2
- package/dist/Change.d.mts +1 -1
- package/dist/Change.mjs +7 -1
- package/dist/Change.mjs.map +1 -1
- package/dist/Clock-Du5nP-nK.d.mts +57 -0
- package/dist/Clock.d.mts +2 -57
- package/dist/Layout.d.mts +2 -0
- package/dist/Layout.mjs +81 -0
- package/dist/Layout.mjs.map +1 -0
- package/dist/Matching-MtcWZ_hA.d.mts +266 -0
- package/dist/Matching.d.mts +2 -37
- package/dist/Matching.mjs +22 -17
- package/dist/Matching.mjs.map +1 -1
- package/dist/Overlay-CoGw5tL_.d.mts +27 -0
- package/dist/Overlay.d.mts +2 -0
- package/dist/Overlay.mjs +30 -0
- package/dist/Overlay.mjs.map +1 -0
- package/dist/{Page-BF5izr8R.mjs → Page-BaAOshxo.mjs} +3 -1
- package/dist/Page-BaAOshxo.mjs.map +1 -0
- package/dist/{Page-CvsOEorc.d.mts → Page-CLzh5E9w.d.mts} +158 -6
- package/dist/Page.d.mts +2 -2
- package/dist/Page.mjs +1 -1
- package/dist/PageTime-68UPUZpZ.d.mts +29 -0
- package/dist/PageTime.d.mts +2 -0
- package/dist/PageTime.mjs +7 -0
- package/dist/PageTime.mjs.map +1 -0
- package/dist/Pose-2qqGzPvb.d.mts +32 -0
- package/dist/Pose.d.mts +2 -0
- package/dist/Pose.mjs +44 -0
- package/dist/Pose.mjs.map +1 -0
- package/dist/Site.d.mts +714 -0
- package/dist/Site.mjs +102 -0
- package/dist/Site.mjs.map +1 -0
- package/dist/{Stillness-CNlvayIo.mjs → Stillness-BwP0RdI4.mjs} +27 -6
- package/dist/Stillness-BwP0RdI4.mjs.map +1 -0
- package/dist/{Style-AO4V7Czt.mjs → Style-T3ezDYLI.mjs} +25 -2
- package/dist/{Style-AO4V7Czt.mjs.map → Style-T3ezDYLI.mjs.map} +1 -1
- package/dist/Style.d.mts +15 -2
- package/dist/Style.mjs +2 -2
- package/dist/Url-B7P-TWwL.d.mts +26 -0
- package/dist/Url.d.mts +2 -26
- package/dist/{Window-CMddGMt1.d.mts → Window-BDa8MtNP.d.mts} +4 -4
- package/dist/Window.d.mts +1 -1
- package/dist/{connection-CK83pvqP.mjs → connection-C_jWYIwe.mjs} +2 -2
- package/dist/{connection-CK83pvqP.mjs.map → connection-C_jWYIwe.mjs.map} +1 -1
- package/dist/{connection-2KHI4_KN.d.mts → connection-Db-YtlbE.d.mts} +2 -2
- package/dist/film/Film.d.mts +265 -0
- package/dist/film/Film.mjs +246 -0
- package/dist/film/Film.mjs.map +1 -0
- package/dist/fold.inpage-CyVZQHZL.d.mts +49 -0
- package/dist/index.d.mts +11 -8
- package/dist/index.mjs +8 -4
- package/dist/moment/Moment.d.mts +5 -5
- package/dist/plan/index.d.mts +2 -2
- package/dist/plan/index.mjs +2 -2
- package/dist/policy/Policy.d.mts +1 -1
- package/dist/policy/Policy.mjs +1 -1
- package/dist/pose.inpage-CLq7Mfdr.mjs +2042 -0
- package/dist/pose.inpage-CLq7Mfdr.mjs.map +1 -0
- package/dist/presentation/Presentation.d.mts +8 -1
- package/dist/presentation/Presentation.mjs +3 -1
- package/dist/presentation/Presentation.mjs.map +1 -1
- package/dist/presentation/Stage.d.mts +1 -1
- package/dist/providers/Cdp.d.mts +2 -2
- package/dist/providers/Cdp.mjs +1 -1
- package/dist/providers/Chromium.d.mts +1 -1
- package/dist/providers/Chromium.mjs +1 -1
- package/dist/stillness/Stillness.d.mts +1 -1
- package/dist/stillness/Stillness.mjs +1 -1
- package/dist/testing/index.d.mts +4 -30
- package/dist/testing/index.mjs +8 -2
- package/dist/testing/index.mjs.map +1 -1
- package/dist/workerd/Cdp.d.mts +2 -2
- package/dist/workerd/Cdp.mjs +1 -1
- package/package.json +32 -2
- package/src/Browser.ts +11 -6
- package/src/BrowserEvent.ts +19 -0
- package/src/Change.ts +7 -1
- package/src/Layout.ts +116 -0
- package/src/Matching.ts +24 -15
- package/src/Overlay.ts +37 -0
- package/src/Page.ts +45 -0
- package/src/PageTime.ts +47 -0
- package/src/Pose.ts +50 -0
- package/src/Site.ts +124 -0
- package/src/Style.ts +36 -0
- package/src/film/Film.ts +384 -0
- package/src/index.ts +4 -0
- package/src/internal/input/perform.ts +31 -3
- package/src/internal/input/pointer.ts +7 -4
- package/src/internal/input/targets.ts +1 -1
- package/src/internal/page/bridge.ts +65 -33
- package/src/internal/page/clock.inpage.ts +306 -0
- package/src/internal/page/compose.inpage.ts +101 -0
- package/src/internal/page/context.ts +2 -0
- package/src/internal/page/overlay.inpage.ts +96 -0
- package/src/internal/page/overlay.ts +89 -0
- package/src/internal/page/page.ts +12 -0
- package/src/internal/page/pose.inpage.ts +200 -0
- package/src/internal/page/pose.ts +80 -0
- package/src/internal/page/time.inpage.ts +49 -0
- package/src/internal/page/time.ts +122 -0
- package/src/internal/page/viewport.ts +3 -2
- package/src/internal/pictures/pictures.ts +93 -32
- package/src/internal/reading/layout.inpage.ts +193 -0
- package/src/internal/reading/layout.ts +101 -0
- package/src/internal/reading/names.inpage.ts +15 -0
- package/src/internal/reading/outline.inpage.ts +2 -18
- package/src/internal/reading/reading.ts +22 -2
- package/src/internal/reading/ready.inpage.ts +18 -23
- package/src/internal/reading/ready.ts +23 -3
- package/src/internal/reading/text.inpage.ts +1 -14
- package/src/internal/timeline/changes.inpage.ts +7 -15
- package/src/internal/timeline/changes.ts +14 -1
- package/src/internal/timeline/record.inpage.ts +15 -6
- package/src/presentation/Presentation.ts +13 -0
- package/src/stillness/Pixels.ts +26 -0
- package/src/stillness/Stillness.ts +30 -5
- package/src/testing/page.ts +5 -0
- package/dist/Browser-BKPAbyys.mjs.map +0 -1
- package/dist/Page-BF5izr8R.mjs.map +0 -1
- package/dist/Stillness-CNlvayIo.mjs.map +0 -1
|
@@ -2,17 +2,20 @@ import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
|
|
|
2
2
|
import { Plan, Point, maximumSamples } from "./Geometry.mjs";
|
|
3
3
|
import { parse, redact, redactWithin } from "./Url.mjs";
|
|
4
4
|
import { nameOf, recorded } from "./Action.mjs";
|
|
5
|
-
import { Action, Box, CursorChanged, DialogShown, Disconnected, KeyChanged, Navigated, PageClosed, PageLoaded, PageOpened, PageUntracked, PointerPressed, PointerReleased, RecordedEvent, RequestRefused, SessionEnding, Subject, TextInserted, TrackEvent, TrackPerformed, TrackPlanned, WheelScrolled } from "./BrowserEvent.mjs";
|
|
5
|
+
import { Action, ActionAnnounced, Box, CursorChanged, DialogShown, Disconnected, KeyChanged, Navigated, PageClosed, PageLoaded, PageOpened, PageUntracked, PointerPressed, PointerReleased, RecordedEvent, RequestRefused, SessionEnding, Subject, TextInserted, TrackEvent, TrackPerformed, TrackPlanned, WheelScrolled } from "./BrowserEvent.mjs";
|
|
6
6
|
import { BrowserError, Busy, Closed, EventHistoryExpired, Failed, InvalidRequest, Limit, NavigationFailed, NotActionable, NotFound, PolicyTimeout, StaleRef, Suspended, Threw, Timeout, call, failWith, reasonOf, refuse, undispatched } from "./BrowserError.mjs";
|
|
7
7
|
import { BrowserPaint, CaptureStats, Frame, Image, Screenshot, sameCapture } from "./Frame.mjs";
|
|
8
|
-
import { _ as PreparedInputResultSchema, c as State, g as make$
|
|
8
|
+
import { _ as PreparedInputResultSchema, c as State, g as make$32, h as FailFast, i as InputRequest, l as Text, m as Correlation, o as Region, p as redacted, r as Found, s as ResolvedTarget, u as Zoom, v as ValidatedInputResultSchema } from "./Page-BaAOshxo.mjs";
|
|
9
9
|
import { Snapshot } from "./Snapshot.mjs";
|
|
10
10
|
import { checked, execute, methods } from "./ActionPort.mjs";
|
|
11
11
|
import { estimate, mapping, monotonicMillis, toBrowserSeconds, toHostTime, uncertaintyAt } from "./Clock.mjs";
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
12
|
+
import { pickRequests, request } from "./Matching.mjs";
|
|
13
|
+
import { n as poseRequest } from "./pose.inpage-CLq7Mfdr.mjs";
|
|
14
|
+
import { d as description, f as parts$1, t as Current$2, u as validated } from "./Style-T3ezDYLI.mjs";
|
|
15
|
+
import { Layout, Place, Word } from "./Layout.mjs";
|
|
14
16
|
import { Change, Changes } from "./Change.mjs";
|
|
15
17
|
import { Window } from "./Window.mjs";
|
|
18
|
+
import { Pose } from "./Pose.mjs";
|
|
16
19
|
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
20
|
import { SecureRandom } from "effect/crypto";
|
|
18
21
|
import { Base64 } from "effect/encoding";
|
|
@@ -73,7 +76,7 @@ const step$1 = (state, input, stopped) => {
|
|
|
73
76
|
} : state;
|
|
74
77
|
}
|
|
75
78
|
};
|
|
76
|
-
const make$
|
|
79
|
+
const make$31 = (options) => {
|
|
77
80
|
let state = {
|
|
78
81
|
_tag: "Open",
|
|
79
82
|
inputs: /* @__PURE__ */ new Set()
|
|
@@ -149,6 +152,51 @@ const make$27 = (options) => {
|
|
|
149
152
|
})
|
|
150
153
|
};
|
|
151
154
|
};
|
|
155
|
+
const TypeableResultSchema = Schema.Union([Schema.Struct({
|
|
156
|
+
ok: Schema.Literal(true),
|
|
157
|
+
secret: Schema.Boolean,
|
|
158
|
+
subject: Schema.optional(Subject)
|
|
159
|
+
}), Schema.Struct({
|
|
160
|
+
error: Schema.Literals(["stale", "untypeable"]),
|
|
161
|
+
detail: Schema.String
|
|
162
|
+
})]);
|
|
163
|
+
const EditFailure = Schema.Struct({
|
|
164
|
+
error: Schema.String,
|
|
165
|
+
stale: Schema.optional(Schema.Boolean)
|
|
166
|
+
});
|
|
167
|
+
const FocusResultSchema = Schema.Union([Schema.Struct({
|
|
168
|
+
ok: Schema.Literal(true),
|
|
169
|
+
detail: Schema.String,
|
|
170
|
+
secret: Schema.Boolean
|
|
171
|
+
}), EditFailure]);
|
|
172
|
+
const EditResultSchema = Schema.Union([Schema.Struct({
|
|
173
|
+
ok: Schema.Literal(true),
|
|
174
|
+
detail: Schema.String
|
|
175
|
+
}), EditFailure]);
|
|
176
|
+
const ResolvedPointSchema = Schema.Struct({
|
|
177
|
+
...Point.fields,
|
|
178
|
+
...Subject.fields,
|
|
179
|
+
element: Schema.String,
|
|
180
|
+
box: Schema.optional(Box),
|
|
181
|
+
cursor: Schema.String,
|
|
182
|
+
href: Schema.optional(Schema.String)
|
|
183
|
+
});
|
|
184
|
+
const PointResultSchema = Schema.Union([ResolvedPointSchema, Schema.Struct({
|
|
185
|
+
error: Schema.Literals([
|
|
186
|
+
"stale",
|
|
187
|
+
"hidden",
|
|
188
|
+
"offscreen",
|
|
189
|
+
"disabled",
|
|
190
|
+
"covered",
|
|
191
|
+
"outside"
|
|
192
|
+
]),
|
|
193
|
+
detail: Schema.String
|
|
194
|
+
})]);
|
|
195
|
+
const ScrollPlanSchema = Schema.NullOr(Schema.Struct({
|
|
196
|
+
...Point.fields,
|
|
197
|
+
dx: Schema.Finite,
|
|
198
|
+
dy: Schema.Finite
|
|
199
|
+
}));
|
|
152
200
|
//#endregion
|
|
153
201
|
//#region src/internal/page/port.ts
|
|
154
202
|
/** Scoped protocol interception at the owned session boundary; native is the default. */
|
|
@@ -205,7 +253,7 @@ const openCapture = Effect.fnUntraced(function* (page, source, handlers) {
|
|
|
205
253
|
var InputFailure = class extends Data.TaggedError("InputFailure") {};
|
|
206
254
|
/** Native page calls join their operation's reply ownership, including script mutations. */
|
|
207
255
|
const Current = Context.Reference("effect-browser/internal/input/Current", { defaultValue: () => void 0 });
|
|
208
|
-
const make$
|
|
256
|
+
const make$30 = () => {
|
|
209
257
|
const outstanding = /* @__PURE__ */ new Set();
|
|
210
258
|
const idle = Effect.gen(function* () {
|
|
211
259
|
while (outstanding.size > 0) yield* Effect.promise(() => Promise.all(outstanding));
|
|
@@ -339,7 +387,7 @@ const CurrentCost = Context.Reference("effect-browser/internal/page/CurrentCost"
|
|
|
339
387
|
const track = (reply) => Fiber.getCurrent()?.getRef(Current)?.track(reply) ?? reply;
|
|
340
388
|
const sizeOf = (value) => value === void 0 ? 0 : new TextEncoder().encode(JSON.stringify(value)).byteLength;
|
|
341
389
|
const decodeWith = (operation, schema) => (value) => Schema.decodeUnknownEffect(schema)(value).pipe(Effect.mapError((error) => undispatched(operation, new Failed({ detail: error.message }))));
|
|
342
|
-
const make$
|
|
390
|
+
const make$29 = (options, scope) => {
|
|
343
391
|
const { id, clock } = options;
|
|
344
392
|
const now = () => monotonicMillis(clock);
|
|
345
393
|
const owned = Effect.provideService(Clock.Clock, clock);
|
|
@@ -406,7 +454,7 @@ const make$25 = (options, scope) => {
|
|
|
406
454
|
const noteInput = () => {
|
|
407
455
|
activity.inputAt = Math.max(activity.inputAt, now());
|
|
408
456
|
};
|
|
409
|
-
const lane = make$
|
|
457
|
+
const lane = make$32({
|
|
410
458
|
now,
|
|
411
459
|
actionTimeout: options.settings.actionTimeout,
|
|
412
460
|
documentAt: () => activity.documentAt,
|
|
@@ -433,264 +481,24 @@ const make$25 = (options, scope) => {
|
|
|
433
481
|
noteInput
|
|
434
482
|
};
|
|
435
483
|
};
|
|
436
|
-
|
|
437
|
-
//#region src/internal/page/dialogs.ts
|
|
438
|
-
/** Scoped dialog responses publish their actual outcome and invalidate their page after failed answers. */
|
|
439
|
-
/**
|
|
440
|
-
* What a page's own Playwright events publish, its close and crash aside, while its scope is
|
|
441
|
-
* open. Dialogs are answered: alerts accepted, others dismissed. The page's own session tells its
|
|
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
|
|
484
|
+
const encodeString = Schema.encodeSync(Schema.fromJsonString(Schema.String));
|
|
622
485
|
/**
|
|
623
|
-
*
|
|
624
|
-
*
|
|
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.
|
|
486
|
+
* The expression of the page clock, a function of its event name, which the page's main world runs
|
|
487
|
+
* before its own scripts; packaging freezes it.
|
|
631
488
|
*/
|
|
489
|
+
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;})()";
|
|
490
|
+
/** The expression that installs the script and evaluates to its API; packaging freezes it. */
|
|
491
|
+
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/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/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
492
|
/**
|
|
633
|
-
* What
|
|
634
|
-
*
|
|
493
|
+
* What new documents run before their own scripts: the page clock under its event name, first, so
|
|
494
|
+
* a caller's script that keeps a timer keeps the clock's, and then the caller's scripts, each
|
|
495
|
+
* everywhere or as a block where its `match` allows.
|
|
635
496
|
*/
|
|
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;})()";
|
|
497
|
+
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
498
|
const worldName = "effect-browser";
|
|
691
499
|
const recorderSource = `if (globalThis === globalThis.top) globalThis.__effectBrowser?.record();`;
|
|
692
500
|
const missing = "effect-browser: no __effectBrowser in this world";
|
|
693
|
-
const missingSource =
|
|
501
|
+
const missingSource = encodeString(missing);
|
|
694
502
|
const isMissing = (error) => error.reason._tag === "Failed" && error.reason.detail === missing;
|
|
695
503
|
const Evaluated = Schema.Struct({
|
|
696
504
|
value: Schema.optionalKey(Schema.Unknown),
|
|
@@ -763,7 +571,7 @@ const registrationFor = Effect.fnUntraced(function* (page) {
|
|
|
763
571
|
removeRecorder
|
|
764
572
|
};
|
|
765
573
|
});
|
|
766
|
-
const make$
|
|
574
|
+
const make$28 = Effect.fnUntraced(function* (page) {
|
|
767
575
|
const { id, cdp, native, span, publish, now } = page;
|
|
768
576
|
const { send } = page.protocol;
|
|
769
577
|
const { ensure, removeRecorder } = yield* registrationFor(page);
|
|
@@ -886,6 +694,102 @@ const make$22 = Effect.fnUntraced(function* (page) {
|
|
|
886
694
|
};
|
|
887
695
|
});
|
|
888
696
|
//#endregion
|
|
697
|
+
//#region src/internal/page/dialogs.ts
|
|
698
|
+
/** Scoped dialog responses publish their actual outcome and invalidate their page after failed answers. */
|
|
699
|
+
/**
|
|
700
|
+
* What a page's own Playwright events publish, its close and crash aside, while its scope is
|
|
701
|
+
* open. Dialogs are answered: alerts accepted, others dismissed. The page's own session tells its
|
|
702
|
+
* documents' commits and loads.
|
|
703
|
+
*/
|
|
704
|
+
const listen = Effect.fnUntraced(function* (playwright, page, publish, now, answer, on) {
|
|
705
|
+
const dialogs = yield* Queue.bounded(8);
|
|
706
|
+
const dialog = (shown) => {
|
|
707
|
+
if (!Queue.offerUnsafe(dialogs, {
|
|
708
|
+
kind: shown.type(),
|
|
709
|
+
message: shown.message().slice(0, 500)
|
|
710
|
+
})) on.failed();
|
|
711
|
+
};
|
|
712
|
+
yield* Queue.take(dialogs).pipe(Effect.flatMap(({ kind, message }) => {
|
|
713
|
+
const accept = kind === "alert" || kind === "beforeunload";
|
|
714
|
+
const record = (answer) => Effect.sync(() => {
|
|
715
|
+
publish(new DialogShown({
|
|
716
|
+
at: now(),
|
|
717
|
+
page,
|
|
718
|
+
kind,
|
|
719
|
+
message,
|
|
720
|
+
answer
|
|
721
|
+
}));
|
|
722
|
+
});
|
|
723
|
+
return answer(accept).pipe(Effect.tap(() => record(accept ? "accepted" : "dismissed")), Effect.tapError(() => record("failed").pipe(Effect.andThen(Effect.sync(on.failed)))));
|
|
724
|
+
}), Effect.forever, Effect.forkScoped);
|
|
725
|
+
yield* Effect.acquireRelease(Effect.sync(() => {
|
|
726
|
+
playwright.on("close", on.close);
|
|
727
|
+
playwright.on("crash", on.crash);
|
|
728
|
+
playwright.on("dialog", dialog);
|
|
729
|
+
}), () => Effect.sync(() => {
|
|
730
|
+
playwright.off("close", on.close);
|
|
731
|
+
playwright.off("crash", on.crash);
|
|
732
|
+
playwright.off("dialog", dialog);
|
|
733
|
+
}));
|
|
734
|
+
});
|
|
735
|
+
//#endregion
|
|
736
|
+
//#region src/internal/page/identity.ts
|
|
737
|
+
/** Connection identity uses the supplied SecureRandom service, or the host's Web Crypto on Node/Bun. */
|
|
738
|
+
const failed = () => undispatched("make", new Failed({ detail: "Could not name connection" }));
|
|
739
|
+
const make$27 = Effect.gen(function* () {
|
|
740
|
+
const supplied = yield* Effect.serviceOption(SecureRandom.SecureRandom);
|
|
741
|
+
return yield* Option.isSome(supplied) ? supplied.value.uuidV4() : Effect.try({
|
|
742
|
+
try: () => globalThis.crypto.randomUUID(),
|
|
743
|
+
catch: failed
|
|
744
|
+
});
|
|
745
|
+
});
|
|
746
|
+
//#endregion
|
|
747
|
+
//#region src/internal/page/openings.ts
|
|
748
|
+
/** A page's input waits for the actual tabs it opened to finish the browser's registration. */
|
|
749
|
+
const make$26 = Effect.fnUntraced(function* (playwright, cdp, registrations, closedBy) {
|
|
750
|
+
const failed = (reason) => Exit.fail(undispatched("newPage", reason));
|
|
751
|
+
let active;
|
|
752
|
+
const gone = Deferred.makeUnsafe();
|
|
753
|
+
const windowOpened = () => {
|
|
754
|
+
if (active !== void 0) active.windows += 1;
|
|
755
|
+
};
|
|
756
|
+
const popup = (opened) => {
|
|
757
|
+
if (active === void 0) return;
|
|
758
|
+
const registered = registrations.get(opened);
|
|
759
|
+
active.registrations.push(registered === void 0 ? failed(new Failed({ detail: "the popup has no registration" })) : Deferred.await(registered).pipe(Effect.asVoid));
|
|
760
|
+
Deferred.doneUnsafe(active.changed, Exit.void);
|
|
761
|
+
active.changed = Deferred.makeUnsafe();
|
|
762
|
+
};
|
|
763
|
+
const clear = Effect.sync(() => {
|
|
764
|
+
active = void 0;
|
|
765
|
+
});
|
|
766
|
+
yield* Effect.acquireRelease(Effect.sync(() => {
|
|
767
|
+
cdp.on("Page.windowOpen", windowOpened);
|
|
768
|
+
playwright.on("popup", popup);
|
|
769
|
+
}), () => Effect.sync(() => {
|
|
770
|
+
active = void 0;
|
|
771
|
+
cdp.off("Page.windowOpen", windowOpened);
|
|
772
|
+
playwright.off("popup", popup);
|
|
773
|
+
Deferred.doneUnsafe(gone, failed(new Closed({ cause: closedBy() })));
|
|
774
|
+
}));
|
|
775
|
+
return {
|
|
776
|
+
mark: () => {
|
|
777
|
+
const mark = {
|
|
778
|
+
windows: 0,
|
|
779
|
+
registrations: [],
|
|
780
|
+
changed: Deferred.makeUnsafe()
|
|
781
|
+
};
|
|
782
|
+
active = mark;
|
|
783
|
+
return mark;
|
|
784
|
+
},
|
|
785
|
+
clear,
|
|
786
|
+
settle: (mark) => Effect.gen(function* () {
|
|
787
|
+
while (mark.registrations.length < mark.windows) yield* Deferred.await(mark.changed);
|
|
788
|
+
yield* Effect.forEach(mark.registrations, (registration) => registration);
|
|
789
|
+
}).pipe(Effect.raceFirst(Deferred.await(gone)), Effect.ensuring(clear))
|
|
790
|
+
};
|
|
791
|
+
});
|
|
792
|
+
//#endregion
|
|
889
793
|
//#region src/internal/input/dispatch.ts
|
|
890
794
|
/**
|
|
891
795
|
* Sending input to the browser. Each mouse event, key and inserted text goes out on the page's
|
|
@@ -906,7 +810,7 @@ const buttonAt = (type, point, button = "left", clickCount = 1) => ({
|
|
|
906
810
|
buttons: type === "mousePressed" ? buttonMask[button] : 0,
|
|
907
811
|
clickCount
|
|
908
812
|
});
|
|
909
|
-
const make$
|
|
813
|
+
const make$25 = (page) => {
|
|
910
814
|
const { id, pointer, publish, now, noteInput, closedBy } = page;
|
|
911
815
|
const { send } = page.protocol;
|
|
912
816
|
const inputClocks = /* @__PURE__ */ new WeakMap();
|
|
@@ -1008,7 +912,7 @@ const inputFailure = (operation, targets, failure) => {
|
|
|
1008
912
|
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
913
|
};
|
|
1010
914
|
const editFailure = (operation, ref, failure) => failWith(operation, failure.stale === true ? new StaleRef({ ref }) : new NotActionable({ detail: failure.error }));
|
|
1011
|
-
const make$
|
|
915
|
+
const make$24 = (page, bridge) => {
|
|
1012
916
|
const { id } = page;
|
|
1013
917
|
const { current, evaluateIn, evaluateWithContext } = bridge;
|
|
1014
918
|
const preparePolicy = (asked, info, targets, flags = {}) => Effect.gen(function* () {
|
|
@@ -1076,7 +980,7 @@ const make$20 = (page, bridge) => {
|
|
|
1076
980
|
* Keys and typing: a key chord held and released, each typed event, and the document a run of
|
|
1077
981
|
* keys must stay in.
|
|
1078
982
|
*/
|
|
1079
|
-
const make$
|
|
983
|
+
const make$23 = (page, bridge, dispatch) => {
|
|
1080
984
|
const { playwright } = page;
|
|
1081
985
|
const key = (direction, part) => {
|
|
1082
986
|
const run = () => playwright.keyboard[direction](part);
|
|
@@ -1203,12 +1107,25 @@ const admission = (page, pending, name) => {
|
|
|
1203
1107
|
end: Effect.sync(() => end?.())
|
|
1204
1108
|
};
|
|
1205
1109
|
};
|
|
1110
|
+
/** Announce an action from what it has found, then wait for its style's lead. */
|
|
1111
|
+
const announcing = (page, name, style, acted) => (to) => Effect.gen(function* () {
|
|
1112
|
+
const event = new ActionAnnounced({
|
|
1113
|
+
at: page.now(),
|
|
1114
|
+
page: page.id,
|
|
1115
|
+
name,
|
|
1116
|
+
correlation: yield* Correlation,
|
|
1117
|
+
...yield* Ref.get(acted),
|
|
1118
|
+
...to
|
|
1119
|
+
});
|
|
1120
|
+
page.publish(event);
|
|
1121
|
+
if (style.lead !== void 0) yield* style.lead(event);
|
|
1122
|
+
});
|
|
1206
1123
|
/** Close a run on every exit while preserving its native replies for the page's next input. */
|
|
1207
1124
|
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$
|
|
1125
|
+
const make$22 = (page, sender) => {
|
|
1209
1126
|
const { id, settings, mapping, lane, publish, now, noteInput, span, owned } = page;
|
|
1210
1127
|
const { inputClocks } = sender;
|
|
1211
|
-
const input = make$
|
|
1128
|
+
const input = make$30();
|
|
1212
1129
|
const admitted = /* @__PURE__ */ new Set();
|
|
1213
1130
|
const perform = (value, info, timeout, prepare, body) => {
|
|
1214
1131
|
const name = nameOf(value);
|
|
@@ -1238,6 +1155,7 @@ const make$18 = (page, sender) => {
|
|
|
1238
1155
|
touched: touch,
|
|
1239
1156
|
at: (point) => Ref.set(at, Option.some(point)),
|
|
1240
1157
|
on: (subject, to) => Ref.set(acted, actedOn(subject, to)),
|
|
1158
|
+
announce: announcing(page, name, style, acted),
|
|
1241
1159
|
reveal: Effect.sync(() => {
|
|
1242
1160
|
revealed = true;
|
|
1243
1161
|
})
|
|
@@ -1295,8 +1213,13 @@ const make$18 = (page, sender) => {
|
|
|
1295
1213
|
to,
|
|
1296
1214
|
box,
|
|
1297
1215
|
text: info.text === void 0 ? void 0 : revealed ? info.text.slice(0, 200) : redacted,
|
|
1298
|
-
|
|
1299
|
-
|
|
1216
|
+
...Option.match(point, {
|
|
1217
|
+
onNone: () => ({}),
|
|
1218
|
+
onSome: ({ x, y }) => ({
|
|
1219
|
+
x,
|
|
1220
|
+
y
|
|
1221
|
+
})
|
|
1222
|
+
}),
|
|
1300
1223
|
ok: Exit.isSuccess(exit),
|
|
1301
1224
|
dispatched,
|
|
1302
1225
|
error: Option.match(failure, {
|
|
@@ -1323,12 +1246,13 @@ const make$18 = (page, sender) => {
|
|
|
1323
1246
|
* plan, published before its first move, from where viewers last saw the pointer when it is
|
|
1324
1247
|
* shown, and a wheel scroll goes in the style's steps.
|
|
1325
1248
|
*/
|
|
1326
|
-
const make$
|
|
1249
|
+
const make$21 = (page, dispatch, viewport) => {
|
|
1327
1250
|
const { id, pointer, publish, now, span } = page;
|
|
1328
1251
|
const { inputClocks, inputCall, dispatchMouse, sendMouse } = dispatch;
|
|
1329
1252
|
const moveTo = (operation, marks, to, cursor, travel = "approach") => Effect.gen(function* () {
|
|
1330
1253
|
const dragging = travel === "drag";
|
|
1331
1254
|
const { style } = marks;
|
|
1255
|
+
if (travel === "approach" || travel === "hover") yield* marks.announce(to);
|
|
1332
1256
|
const drawn = style.pointer ?? pointer;
|
|
1333
1257
|
const size = yield* viewport.viewportFor(operation);
|
|
1334
1258
|
const previous = Option.getOrElse(MutableRef.get(drawn), () => ({
|
|
@@ -1361,7 +1285,7 @@ const make$17 = (page, dispatch, viewport) => {
|
|
|
1361
1285
|
for (const sample of samples) {
|
|
1362
1286
|
const remaining = at + sample.afterMillis - now();
|
|
1363
1287
|
if (remaining > 0) yield* Effect.sleep(Duration.millis(remaining));
|
|
1364
|
-
yield* travel === "approach" ? marks.touched : marks.sent;
|
|
1288
|
+
yield* travel === "approach" || travel === "reveal" ? marks.touched : marks.sent;
|
|
1365
1289
|
yield* inputCall(operation, run.send(() => dispatchMouse({
|
|
1366
1290
|
type: "mouseMoved",
|
|
1367
1291
|
x: sample.x,
|
|
@@ -1421,7 +1345,7 @@ const make$17 = (page, dispatch, viewport) => {
|
|
|
1421
1345
|
* next look's to see. A tab the input opened waits for the browser's registration too.
|
|
1422
1346
|
*/
|
|
1423
1347
|
const settling = Duration.seconds(5);
|
|
1424
|
-
const make$
|
|
1348
|
+
const make$20 = (page, bridge) => {
|
|
1425
1349
|
const document = () => bridge.frameTag().document;
|
|
1426
1350
|
let parsed = -1;
|
|
1427
1351
|
let changed = Deferred.makeUnsafe();
|
|
@@ -1461,7 +1385,7 @@ const resolvedTarget = ({ x, y, box, ...target }) => new ResolvedTarget({
|
|
|
1461
1385
|
box,
|
|
1462
1386
|
...target
|
|
1463
1387
|
});
|
|
1464
|
-
const make$
|
|
1388
|
+
const make$19 = (viewport, guard, pointer, dispatch, settling) => {
|
|
1465
1389
|
const { evaluate, mutate } = guard;
|
|
1466
1390
|
const { moveTo, wheel } = pointer;
|
|
1467
1391
|
const { flush } = dispatch;
|
|
@@ -1483,7 +1407,7 @@ const make$15 = (viewport, guard, pointer, dispatch, settling) => {
|
|
|
1483
1407
|
y: plan.y
|
|
1484
1408
|
};
|
|
1485
1409
|
yield* marks.at(point);
|
|
1486
|
-
yield* moveTo(operation, marks, point);
|
|
1410
|
+
yield* moveTo(operation, marks, point, void 0, "reveal");
|
|
1487
1411
|
const before = settling.mark();
|
|
1488
1412
|
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
1413
|
yield* flush(operation, marks.input);
|
|
@@ -1508,19 +1432,19 @@ const make$15 = (viewport, guard, pointer, dispatch, settling) => {
|
|
|
1508
1432
|
* then waits for the page to settle: a task and a frame, and a document if the input asked for one.
|
|
1509
1433
|
*/
|
|
1510
1434
|
const partsOf = (page, bridge, viewport) => {
|
|
1511
|
-
const dispatch = make$
|
|
1512
|
-
const pointer = make$
|
|
1513
|
-
const guard = make$
|
|
1514
|
-
const settling = make$
|
|
1435
|
+
const dispatch = make$25(page);
|
|
1436
|
+
const pointer = make$21(page, dispatch, viewport);
|
|
1437
|
+
const guard = make$24(page, bridge);
|
|
1438
|
+
const settling = make$20(page, bridge);
|
|
1515
1439
|
return {
|
|
1516
1440
|
page,
|
|
1517
1441
|
...settling,
|
|
1518
1442
|
viewportFor: viewport.viewportFor,
|
|
1519
|
-
perform: make$
|
|
1443
|
+
perform: make$22(page, dispatch),
|
|
1520
1444
|
...guard,
|
|
1521
|
-
...make$
|
|
1445
|
+
...make$19(viewport, guard, pointer, dispatch, settling),
|
|
1522
1446
|
...pointer,
|
|
1523
|
-
...make$
|
|
1447
|
+
...make$23(page, bridge, dispatch),
|
|
1524
1448
|
sendMouse: dispatch.sendMouse,
|
|
1525
1449
|
flush: dispatch.flush
|
|
1526
1450
|
};
|
|
@@ -1787,7 +1711,7 @@ const select = (input) => {
|
|
|
1787
1711
|
return result.detail;
|
|
1788
1712
|
}));
|
|
1789
1713
|
};
|
|
1790
|
-
const make$
|
|
1714
|
+
const make$18 = (page, bridge, viewport) => {
|
|
1791
1715
|
const parts = partsOf(page, bridge, viewport);
|
|
1792
1716
|
return {
|
|
1793
1717
|
perform: parts.perform,
|
|
@@ -2037,8 +1961,8 @@ const orderedFrame = (frame, previous) => frame.hostTime < previous && frame.tim
|
|
|
2037
1961
|
//#region src/internal/pictures/quiescence.ts
|
|
2038
1962
|
/** Actual native replies outlive callers; bounded transactions retain them without holding teardown. */
|
|
2039
1963
|
const deadline$1 = Duration.seconds(2);
|
|
2040
|
-
const make$
|
|
2041
|
-
const replies = make$
|
|
1964
|
+
const make$17 = (options) => {
|
|
1965
|
+
const replies = make$30();
|
|
2042
1966
|
const pending = /* @__PURE__ */ new Map();
|
|
2043
1967
|
const late = (kind) => options.error(/* @__PURE__ */ new Error(`${kind} exceeded its deadline`));
|
|
2044
1968
|
const track = (operation, actual, failed) => {
|
|
@@ -2218,7 +2142,7 @@ const reader = (acquire, leave, why, lost) => (settings = {}) => Effect.acquireR
|
|
|
2218
2142
|
current: lease.frame,
|
|
2219
2143
|
stream: frames(lease.subscription, lease.baseline, why, lost)
|
|
2220
2144
|
})));
|
|
2221
|
-
const make$
|
|
2145
|
+
const make$16 = (options) => Effect.gen(function* () {
|
|
2222
2146
|
const lock = yield* Semaphore.make(1);
|
|
2223
2147
|
const replies = /* @__PURE__ */ new Set();
|
|
2224
2148
|
let generation;
|
|
@@ -2280,7 +2204,7 @@ const make$12 = (options) => Effect.gen(function* () {
|
|
|
2280
2204
|
const gone = () => options.error(/* @__PURE__ */ new Error("Target page has been closed"));
|
|
2281
2205
|
const why = told(closed, gone, options.clock);
|
|
2282
2206
|
const awaitStop = (current) => pictures.wait("screencast stop").pipe(Effect.catch((error) => Effect.sync(() => notifyFailure(current, error))));
|
|
2283
|
-
const pictures = make$
|
|
2207
|
+
const pictures = make$17({
|
|
2284
2208
|
clock: options.clock,
|
|
2285
2209
|
error: options.error,
|
|
2286
2210
|
closed: isClosed,
|
|
@@ -2668,26 +2592,66 @@ const calibrator = (page, bridge) => {
|
|
|
2668
2592
|
};
|
|
2669
2593
|
const ScreenSize = Schema.Struct({
|
|
2670
2594
|
width: Schema.Int,
|
|
2671
|
-
height: Schema.Int
|
|
2595
|
+
height: Schema.Int,
|
|
2596
|
+
ratio: Schema.Finite
|
|
2672
2597
|
});
|
|
2673
|
-
const
|
|
2598
|
+
const device = (page, bridge) => {
|
|
2674
2599
|
const { playwright, native, within } = page;
|
|
2675
2600
|
const { send } = page.protocol;
|
|
2676
|
-
let
|
|
2677
|
-
let
|
|
2601
|
+
let screen;
|
|
2602
|
+
let scaled = 0;
|
|
2603
|
+
let painting = false;
|
|
2604
|
+
const metrics = (operation) => native(operation, () => send("Emulation.setDeviceMetricsOverride", {
|
|
2605
|
+
width: 0,
|
|
2606
|
+
height: 0,
|
|
2607
|
+
deviceScaleFactor: scaled,
|
|
2608
|
+
mobile: false,
|
|
2609
|
+
...screen === void 0 ? {} : {
|
|
2610
|
+
screenWidth: screen.width,
|
|
2611
|
+
screenHeight: screen.height
|
|
2612
|
+
}
|
|
2613
|
+
}));
|
|
2614
|
+
const screenOf = (operation) => bridge.evaluate(operation, scriptCall("screenSize")).pipe(Effect.flatMap(decodeWith(operation, ScreenSize)));
|
|
2678
2615
|
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;
|
|
2616
|
+
if (screen !== void 0) return;
|
|
2617
|
+
const { width, height } = yield* screenOf(operation);
|
|
2618
|
+
screen = {
|
|
2619
|
+
width,
|
|
2620
|
+
height
|
|
2621
|
+
};
|
|
2622
|
+
yield* metrics(operation).pipe(Effect.onError(() => Effect.sync(() => screen = void 0)));
|
|
2690
2623
|
});
|
|
2624
|
+
const scrollbarsHidden = (hidden) => native("paint", () => send("Emulation.setScrollbarsHidden", { hidden }));
|
|
2625
|
+
const paint = (options) => Effect.gen(function* () {
|
|
2626
|
+
const { scale, scrollbars = true } = options;
|
|
2627
|
+
const launched = playwright.viewportSize() !== null;
|
|
2628
|
+
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");
|
|
2629
|
+
if (painting) return yield* refuse("paint", "the page is painted for another scope already");
|
|
2630
|
+
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");
|
|
2631
|
+
const rescaled = scale !== void 0 && !launched;
|
|
2632
|
+
painting = true;
|
|
2633
|
+
yield* Effect.addFinalizer(() => Effect.gen(function* () {
|
|
2634
|
+
scaled = 0;
|
|
2635
|
+
if (!scrollbars) yield* scrollbarsHidden(false);
|
|
2636
|
+
if (rescaled) yield* metrics("paint");
|
|
2637
|
+
}).pipe(Effect.ignore, Effect.ensuring(Effect.sync(() => painting = false))));
|
|
2638
|
+
if (!scrollbars) yield* scrollbarsHidden(true);
|
|
2639
|
+
if (rescaled) {
|
|
2640
|
+
scaled = scale;
|
|
2641
|
+
yield* metrics("paint");
|
|
2642
|
+
}
|
|
2643
|
+
}).pipe(within("paint"));
|
|
2644
|
+
return {
|
|
2645
|
+
holdScreen,
|
|
2646
|
+
paint,
|
|
2647
|
+
scaled: () => scaled
|
|
2648
|
+
};
|
|
2649
|
+
};
|
|
2650
|
+
const camera = (page, viewport, capture, { holdScreen, scaled }) => {
|
|
2651
|
+
const { playwright, native, within } = page;
|
|
2652
|
+
const { send } = page.protocol;
|
|
2653
|
+
let ratio = 1;
|
|
2654
|
+
const layoutMetrics = (operation) => native(operation, () => send("Page.getLayoutMetrics")).pipe(Effect.flatMap(decodeWith(operation, LayoutMetrics)));
|
|
2691
2655
|
const decoded = (operation, data, format) => {
|
|
2692
2656
|
const size = format === "png" ? pngSize(data) : jpegSize(data);
|
|
2693
2657
|
return size === void 0 ? failWith(operation, new Failed({ detail: `the browser's picture is not a ${format.toUpperCase()}` })) : Effect.succeed(new Image({
|
|
@@ -2724,9 +2688,9 @@ const camera = (page, bridge, viewport, capture) => {
|
|
|
2724
2688
|
if (whole !== void 0) ratio = whole.width / emulated.width;
|
|
2725
2689
|
return yield* emulatedShot(operation, format, quality, pixels, crop);
|
|
2726
2690
|
}
|
|
2727
|
-
const [
|
|
2728
|
-
const
|
|
2729
|
-
ratio = Number.isFinite(
|
|
2691
|
+
const [measured] = yield* layoutMetrics(operation).pipe(Effect.zip(crop === void 0 ? Effect.void : holdScreen(operation), { concurrent: true }));
|
|
2692
|
+
const measuredRatio = measured.contentSize.width / measured.cssContentSize.width;
|
|
2693
|
+
ratio = scaled() > 0 ? scaled() : Number.isFinite(measuredRatio) && measuredRatio > 0 ? measuredRatio : 1;
|
|
2730
2694
|
if (crop === void 0 && ratio === 1) {
|
|
2731
2695
|
const image = whole ?? (yield* shot(operation, format, quality));
|
|
2732
2696
|
viewport.remember(image);
|
|
@@ -2737,7 +2701,7 @@ const camera = (page, bridge, viewport, capture) => {
|
|
|
2737
2701
|
y: 0,
|
|
2738
2702
|
...known ?? (yield* viewport.viewportFor(operation))
|
|
2739
2703
|
};
|
|
2740
|
-
const { pageX, pageY, scale } =
|
|
2704
|
+
const { pageX, pageY, scale } = measured.cssVisualViewport;
|
|
2741
2705
|
yield* holdScreen(operation);
|
|
2742
2706
|
return yield* shot(operation, format, quality, {
|
|
2743
2707
|
x: pageX + rect.x,
|
|
@@ -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$15 = 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$16({
|
|
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,7 +2751,8 @@ 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
2757
|
const screenshots = lane.shared("screenshot", false);
|
|
2793
2758
|
const frames = lane.shared("frame", false);
|
|
@@ -2855,22 +2820,102 @@ const make$11 = Effect.fnUntraced(function* (page, bridge, viewport) {
|
|
|
2855
2820
|
frame,
|
|
2856
2821
|
zoom,
|
|
2857
2822
|
captureStats,
|
|
2858
|
-
estimate: mapping.current(calibrateClock)
|
|
2823
|
+
estimate: mapping.current(calibrateClock),
|
|
2824
|
+
paint: emulated.paint
|
|
2859
2825
|
};
|
|
2860
2826
|
});
|
|
2861
2827
|
//#endregion
|
|
2828
|
+
//#region src/internal/reading/layout.ts
|
|
2829
|
+
/**
|
|
2830
|
+
* Reading where things are: `Page.layout`, in one call to the page that takes its turn as other
|
|
2831
|
+
* reads do and shares its work with identical ones. The page gives each place's viewport box; the
|
|
2832
|
+
* document box is that box moved by the scroll read with it.
|
|
2833
|
+
*/
|
|
2834
|
+
const LayoutResult = Schema.Union([Schema.Struct({ layout: Schema.Struct({
|
|
2835
|
+
url: Schema.String,
|
|
2836
|
+
viewport: Schema.Struct({
|
|
2837
|
+
width: Schema.Finite,
|
|
2838
|
+
height: Schema.Finite
|
|
2839
|
+
}),
|
|
2840
|
+
scroll: Point,
|
|
2841
|
+
scale: Schema.Finite,
|
|
2842
|
+
missing: Schema.Array(Schema.String),
|
|
2843
|
+
places: Schema.Array(Schema.Struct({
|
|
2844
|
+
id: Schema.String,
|
|
2845
|
+
ref: Schema.String,
|
|
2846
|
+
subject: Subject,
|
|
2847
|
+
box: Box,
|
|
2848
|
+
fixed: Schema.Boolean,
|
|
2849
|
+
words: Schema.optional(Schema.Array(Schema.Struct({
|
|
2850
|
+
text: Schema.String,
|
|
2851
|
+
box: Box
|
|
2852
|
+
})))
|
|
2853
|
+
}))
|
|
2854
|
+
}) }), Schema.Struct({ invalid: Schema.String })]);
|
|
2855
|
+
const make$14 = (page, bridge) => {
|
|
2856
|
+
const { now, span, owned, within, lane } = page;
|
|
2857
|
+
const { evaluate } = bridge;
|
|
2858
|
+
const layouts = lane.shared("layout", true);
|
|
2859
|
+
const layout = (picks) => {
|
|
2860
|
+
const asked = pickRequests(picks);
|
|
2861
|
+
const once = Effect.gen(function* () {
|
|
2862
|
+
const before = bridge.frameTag().document;
|
|
2863
|
+
const result = yield* evaluate("layout", scriptCall("layout", asked)).pipe(Effect.flatMap(decodeWith("layout", LayoutResult)));
|
|
2864
|
+
if ("invalid" in result) return yield* refuse("layout", result.invalid);
|
|
2865
|
+
if (bridge.frameTag().document !== before) return yield* failWith("layout", new NotActionable({ detail: "the page's document changed while it was read" }));
|
|
2866
|
+
const { places, scroll, ...read } = result.layout;
|
|
2867
|
+
const moved = (box) => ({
|
|
2868
|
+
...box,
|
|
2869
|
+
x: box.x + scroll.x,
|
|
2870
|
+
y: box.y + scroll.y
|
|
2871
|
+
});
|
|
2872
|
+
return new Layout({
|
|
2873
|
+
...read,
|
|
2874
|
+
url: redact(read.url),
|
|
2875
|
+
page: page.id,
|
|
2876
|
+
connection: page.connection,
|
|
2877
|
+
document: before,
|
|
2878
|
+
at: now(),
|
|
2879
|
+
scroll,
|
|
2880
|
+
places: places.map(({ words, ...place }) => new Place({
|
|
2881
|
+
...place,
|
|
2882
|
+
page: moved(place.box),
|
|
2883
|
+
words: words?.map((word) => new Word({
|
|
2884
|
+
...word,
|
|
2885
|
+
page: moved(word.box)
|
|
2886
|
+
}))
|
|
2887
|
+
}))
|
|
2888
|
+
});
|
|
2889
|
+
});
|
|
2890
|
+
return layouts(JSON.stringify(asked), once.pipe(Effect.retry({
|
|
2891
|
+
times: 1,
|
|
2892
|
+
while: (error) => contextGone(error) || error.reason._tag === "NotActionable" && error.operation === "layout"
|
|
2893
|
+
}), within("layout"))).pipe(span("Page.layout", { picks: asked.length }), owned);
|
|
2894
|
+
};
|
|
2895
|
+
return layout;
|
|
2896
|
+
};
|
|
2897
|
+
//#endregion
|
|
2862
2898
|
//#region src/internal/reading/reading.ts
|
|
2863
2899
|
/**
|
|
2864
2900
|
* Reading a page: its outline with refs, the elements a query finds and the text it shows. Each
|
|
2865
2901
|
* read takes its turn on the page and shares its work with identical reads, as `lane.ts`
|
|
2866
2902
|
* describes. The viewport's text as it was last read is kept, for `Page.state`.
|
|
2867
2903
|
*/
|
|
2904
|
+
/** The outline as a `Snapshot` reads it, or why `within` is not a selector. */
|
|
2905
|
+
const SnapshotResultSchema = Schema.Union([Schema.Struct({ snapshot: Snapshot }), Schema.Struct({ invalid: Schema.String })]);
|
|
2906
|
+
/** What `text` sends back, or null when its ref no longer names an element. */
|
|
2907
|
+
const TextResultSchema = Schema.NullOr(Schema.Struct({
|
|
2908
|
+
text: Schema.String,
|
|
2909
|
+
truncated: Schema.Boolean,
|
|
2910
|
+
url: Schema.String,
|
|
2911
|
+
title: Schema.String
|
|
2912
|
+
}));
|
|
2868
2913
|
const FindResults = Schema.Union([Schema.Struct({ found: Schema.Array(Found) }), Schema.Struct({ invalid: Schema.String })]);
|
|
2869
2914
|
const UntilResult = Schema.Union([Schema.Struct({
|
|
2870
2915
|
met: Schema.Boolean,
|
|
2871
2916
|
mark: Schema.String
|
|
2872
2917
|
}), Schema.Struct({ invalid: Schema.String })]);
|
|
2873
|
-
const make$
|
|
2918
|
+
const make$13 = (page, bridge) => Effect.sync(() => {
|
|
2874
2919
|
const { now, span, owned, within, lane } = page;
|
|
2875
2920
|
const { evaluate } = bridge;
|
|
2876
2921
|
const snapshots = lane.shared("snapshot", true);
|
|
@@ -2962,11 +3007,22 @@ const make$10 = (page, bridge) => Effect.sync(() => {
|
|
|
2962
3007
|
//#endregion
|
|
2963
3008
|
//#region src/internal/reading/ready.ts
|
|
2964
3009
|
/** Document readiness and content quiet, independent of screen-capture features. */
|
|
2965
|
-
|
|
3010
|
+
/** What the page is still waiting for; none when it is ready. */
|
|
3011
|
+
const ReadinessSchema = Schema.Array(Schema.Literals([
|
|
3012
|
+
"load",
|
|
3013
|
+
"paint",
|
|
3014
|
+
"animations",
|
|
3015
|
+
"images",
|
|
3016
|
+
"fonts",
|
|
3017
|
+
"busy",
|
|
3018
|
+
"content",
|
|
3019
|
+
"changing"
|
|
3020
|
+
]));
|
|
3021
|
+
const make$12 = (page, bridge) => (options = {}) => {
|
|
2966
3022
|
const quietMillis = options.quietMillis ?? 0;
|
|
2967
3023
|
if (!Number.isFinite(quietMillis) || quietMillis < 0) return refuse("ready", "quietMillis must be finite and nonnegative");
|
|
2968
3024
|
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({
|
|
3025
|
+
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
3026
|
while: contextGone,
|
|
2971
3027
|
schedule: Schedule.spaced(Duration.millis(10))
|
|
2972
3028
|
}), 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 +3040,19 @@ const make$9 = (page, bridge) => (options = {}) => {
|
|
|
2984
3040
|
* identical ones in flight share it; none is kept for a later caller, since its window ends when
|
|
2985
3041
|
* it was read.
|
|
2986
3042
|
*/
|
|
3043
|
+
/**
|
|
3044
|
+
* What a read sends back: its window and the record's state, and each change as `Change` encodes
|
|
3045
|
+
* it, all on the page's clock.
|
|
3046
|
+
*/
|
|
3047
|
+
const ChangesResultSchema = Schema.Struct({
|
|
3048
|
+
until: Schema.Finite,
|
|
3049
|
+
from: Schema.Finite,
|
|
3050
|
+
dropped: Schema.Int,
|
|
3051
|
+
records: Schema.Array(Change)
|
|
3052
|
+
});
|
|
2987
3053
|
const isChanges = Schema.is(Changes);
|
|
2988
3054
|
const markOf = (time) => time === void 0 || typeof time === "number" ? time : isChanges(time) ? `cursor ${time.cursor}` : `frame ${time.timestamp ?? time.hostTime}`;
|
|
2989
|
-
const make$
|
|
3055
|
+
const make$11 = (page, bridge, estimate) => {
|
|
2990
3056
|
const reads = page.lane.shared("changes", false);
|
|
2991
3057
|
const recording = Semaphore.makeUnsafe(1);
|
|
2992
3058
|
const idleMillis = 12e4;
|
|
@@ -3077,7 +3143,7 @@ const within = ({ since, until }, events, frames) => ({
|
|
|
3077
3143
|
events: events.filter((event) => event.at > since && event.at <= until && !isTrackEvent(event)),
|
|
3078
3144
|
frames: frames.filter((frame) => frame.hostTime >= since && frame.hostTime <= until)
|
|
3079
3145
|
});
|
|
3080
|
-
const make$
|
|
3146
|
+
const make$10 = (page, read, frames) => ({ since, until, unmask }) => Effect.gen(function* () {
|
|
3081
3147
|
const asked = boundsOf({
|
|
3082
3148
|
since,
|
|
3083
3149
|
until
|
|
@@ -3104,7 +3170,7 @@ const make$7 = (page, read, frames) => ({ since, until, unmask }) => Effect.gen(
|
|
|
3104
3170
|
* Each move is an action, so it takes the page's turn, goes through the input guard and is
|
|
3105
3171
|
* recorded, but it sends no input.
|
|
3106
3172
|
*/
|
|
3107
|
-
const make$
|
|
3173
|
+
const make$9 = (page, perform, preparePolicy) => {
|
|
3108
3174
|
const { playwright, settings, native } = page;
|
|
3109
3175
|
const { send } = page.protocol;
|
|
3110
3176
|
const navigation = (value, run, address) => {
|
|
@@ -3190,9 +3256,89 @@ const make$6 = (page, perform, preparePolicy) => {
|
|
|
3190
3256
|
};
|
|
3191
3257
|
};
|
|
3192
3258
|
//#endregion
|
|
3259
|
+
//#region src/internal/page/overlay.ts
|
|
3260
|
+
/**
|
|
3261
|
+
* The page's overlay: one lease at a time, each drawing one call to the page, in turn after the
|
|
3262
|
+
* actions asked before it, never two at once. Each new document gets what was last drawn once it
|
|
3263
|
+
* has loaded; the lease's scope takes the layer away.
|
|
3264
|
+
*/
|
|
3265
|
+
const Drawn = Schema.Array(Box);
|
|
3266
|
+
const make$8 = (page, bridge) => {
|
|
3267
|
+
const { lane, owned, span, within } = page;
|
|
3268
|
+
const turns = Semaphore.makeUnsafe(1);
|
|
3269
|
+
let open = false;
|
|
3270
|
+
let shown = null;
|
|
3271
|
+
let drawn = [];
|
|
3272
|
+
const record = (markup, boxes) => {
|
|
3273
|
+
shown = markup;
|
|
3274
|
+
drawn = boxes;
|
|
3275
|
+
page.noteInput();
|
|
3276
|
+
};
|
|
3277
|
+
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"))));
|
|
3278
|
+
const draw = (content) => send(content._tag === "Svg" ? content.markup : null).pipe(span("Overlay.draw"), owned);
|
|
3279
|
+
const redraw = (document) => bridge.waitForDocument(document).pipe(Effect.andThen(Effect.void.pipe(Effect.repeat({
|
|
3280
|
+
schedule: Schedule.spaced(Duration.millis(50)),
|
|
3281
|
+
until: () => bridge.loaded() !== void 0
|
|
3282
|
+
}), within("overlay", page.settings.navigationTimeout))), Effect.andThen(Effect.suspend(() => shown === null ? Effect.void : send(shown))), Effect.ignore);
|
|
3283
|
+
return {
|
|
3284
|
+
lease: Effect.gen(function* () {
|
|
3285
|
+
if (open) return yield* refuse("overlay", "the page has an overlay already");
|
|
3286
|
+
open = true;
|
|
3287
|
+
yield* Effect.addFinalizer(() => Effect.suspend(() => {
|
|
3288
|
+
open = false;
|
|
3289
|
+
return shown === null ? Effect.void : send(null).pipe(Effect.ignore);
|
|
3290
|
+
}));
|
|
3291
|
+
yield* Effect.forkScoped(Effect.suspend(() => redraw(bridge.frameTag().document)).pipe(Effect.forever));
|
|
3292
|
+
return { draw };
|
|
3293
|
+
}),
|
|
3294
|
+
drawn: () => shown === null ? void 0 : drawn,
|
|
3295
|
+
open: () => open,
|
|
3296
|
+
record,
|
|
3297
|
+
/** Run a call that draws in the overlay's turn, so no other drawing overtakes it. */
|
|
3298
|
+
turn: (effect) => turns.withPermit(effect)
|
|
3299
|
+
};
|
|
3300
|
+
};
|
|
3301
|
+
//#endregion
|
|
3302
|
+
//#region src/internal/page/pose.ts
|
|
3303
|
+
/**
|
|
3304
|
+
* The page's poses: one lease at a time, each `set` one call to the page in the page's turn, as an
|
|
3305
|
+
* action takes it, so no action resolves a target that a pose then moves. The lease's scope takes
|
|
3306
|
+
* every pose off. See `Pose`.
|
|
3307
|
+
*/
|
|
3308
|
+
/** What posing answered: nothing, or the ref it could not pose and why. */
|
|
3309
|
+
const Posed = Schema.Struct({
|
|
3310
|
+
stale: Schema.optional(Schema.String),
|
|
3311
|
+
invalid: Schema.optional(Schema.String)
|
|
3312
|
+
});
|
|
3313
|
+
const make$7 = (page, bridge) => {
|
|
3314
|
+
const { lane, owned, span, within } = page;
|
|
3315
|
+
let open = false;
|
|
3316
|
+
/** The page's requests for `poses`, each part left out made the one that changes nothing. */
|
|
3317
|
+
const requests = Effect.fnUntraced(function* (operation, poses) {
|
|
3318
|
+
const decoded = yield* Schema.decodeEffect(Schema.Array(Pose))(poses).pipe(Effect.catch(() => refuse(operation, "each pose is a ref and finite numbers")));
|
|
3319
|
+
if (decoded.length > 256) return yield* refuse(operation, "at most 256 elements are posed at once");
|
|
3320
|
+
return decoded.map(poseRequest);
|
|
3321
|
+
});
|
|
3322
|
+
/** Fail as the page's answer says, if it posed nothing. */
|
|
3323
|
+
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;
|
|
3324
|
+
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)));
|
|
3325
|
+
const set = (poses) => requests("pose", poses).pipe(Effect.flatMap((made) => send("pose", scriptCall("pose", made))), span("Poses.set"), owned);
|
|
3326
|
+
return {
|
|
3327
|
+
lease: Effect.gen(function* () {
|
|
3328
|
+
if (open) return yield* refuse("pose", "the page's poses are open already");
|
|
3329
|
+
open = true;
|
|
3330
|
+
yield* Effect.addFinalizer(() => send("pose", scriptCall("unpose")).pipe(Effect.ignore, Effect.ensuring(Effect.sync(() => open = false))));
|
|
3331
|
+
return { set };
|
|
3332
|
+
}),
|
|
3333
|
+
open: () => open,
|
|
3334
|
+
requests,
|
|
3335
|
+
answered
|
|
3336
|
+
};
|
|
3337
|
+
};
|
|
3338
|
+
//#endregion
|
|
3193
3339
|
//#region src/internal/page/scripts.ts
|
|
3194
3340
|
/** Main-world scripts with the page lane, document binding, policy and dispatch accounting. */
|
|
3195
|
-
const make$
|
|
3341
|
+
const make$6 = (page, bridge, input) => {
|
|
3196
3342
|
const document = () => bridge.frameTag().document;
|
|
3197
3343
|
const changed = (operation) => failWith(operation, new NotActionable({ detail: "the script's document changed" }));
|
|
3198
3344
|
const evaluate = (operation, script, arg) => page.native(operation, () => Promise.resolve(Reflect.apply(page.playwright.evaluate.bind(page.playwright), void 0, [script, arg])));
|
|
@@ -3248,6 +3394,75 @@ const make$5 = (page, bridge, input) => {
|
|
|
3248
3394
|
};
|
|
3249
3395
|
};
|
|
3250
3396
|
//#endregion
|
|
3397
|
+
//#region src/internal/page/time.ts
|
|
3398
|
+
/**
|
|
3399
|
+
* Holding a page's time: one hold at a time, each step one call to the page that takes the page
|
|
3400
|
+
* to itself, as an action does, so no read sees a step half made. See `PageTime`.
|
|
3401
|
+
*/
|
|
3402
|
+
const Stepped = Schema.Struct({
|
|
3403
|
+
...Posed.fields,
|
|
3404
|
+
told: Schema.Boolean,
|
|
3405
|
+
drawn: Schema.NullOr(Schema.Array(Box)),
|
|
3406
|
+
scroll: Point
|
|
3407
|
+
});
|
|
3408
|
+
const make$5 = (page, bridge, overlays, posing) => {
|
|
3409
|
+
const { lane, owned, span, within } = page;
|
|
3410
|
+
let holding = false;
|
|
3411
|
+
const step = (operation, request) => {
|
|
3412
|
+
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(() => {
|
|
3413
|
+
if (drawn !== null && request.markup !== void 0) overlays.record(request.markup, drawn);
|
|
3414
|
+
page.noteInput();
|
|
3415
|
+
})), within(operation))).pipe(span(`PageTime.${operation}`), owned);
|
|
3416
|
+
return request.markup === void 0 ? sent : overlays.turn(sent);
|
|
3417
|
+
};
|
|
3418
|
+
const unclocked = (operation) => failWith(operation, new NotActionable({ detail: "the page's document has no page clock" }));
|
|
3419
|
+
return { hold: Effect.gen(function* () {
|
|
3420
|
+
const clock = page.settings.pageTime;
|
|
3421
|
+
if (clock === void 0) return yield* refuse("hold", "holding page time needs the browser's pageTime option");
|
|
3422
|
+
if (holding) return yield* refuse("hold", "the page's time is held already");
|
|
3423
|
+
holding = true;
|
|
3424
|
+
let ended = false;
|
|
3425
|
+
yield* Effect.addFinalizer(() => Effect.sync(() => ended = true).pipe(Effect.andThen(step("release", {
|
|
3426
|
+
clock,
|
|
3427
|
+
op: "release",
|
|
3428
|
+
by: 0,
|
|
3429
|
+
scroll: null
|
|
3430
|
+
})), Effect.ignore, Effect.ensuring(Effect.sync(() => holding = false))));
|
|
3431
|
+
if (!(yield* step("hold", {
|
|
3432
|
+
clock,
|
|
3433
|
+
op: "hold",
|
|
3434
|
+
by: 0,
|
|
3435
|
+
scroll: null
|
|
3436
|
+
})).told) return yield* unclocked("hold");
|
|
3437
|
+
let elapsed = 0;
|
|
3438
|
+
const advance = (by, options = {}) => Effect.gen(function* () {
|
|
3439
|
+
const millis = Option.map(Duration.fromInput(by), Duration.toMillis).pipe(Option.getOrElse(() => NaN));
|
|
3440
|
+
if (ended) return yield* refuse("advance", "the hold has ended");
|
|
3441
|
+
if (!Number.isFinite(millis) || millis < 0) return yield* refuse("advance", "page time moves on by a finite, nonnegative duration");
|
|
3442
|
+
if (options.scroll !== void 0 && !Number.isFinite(options.scroll)) return yield* refuse("advance", "the scroll must be finite");
|
|
3443
|
+
if (options.overlay !== void 0 && !overlays.open()) return yield* refuse("advance", "drawing needs the page's overlay open");
|
|
3444
|
+
if (options.poses !== void 0 && !posing.open()) return yield* refuse("advance", "posing needs the page's poses open");
|
|
3445
|
+
const poses = options.poses === void 0 ? void 0 : yield* posing.requests("advance", options.poses);
|
|
3446
|
+
const stepped = yield* step("advance", {
|
|
3447
|
+
clock,
|
|
3448
|
+
op: "advance",
|
|
3449
|
+
by: millis,
|
|
3450
|
+
scroll: options.scroll ?? null,
|
|
3451
|
+
markup: options.overlay === void 0 ? void 0 : options.overlay._tag === "Svg" ? options.overlay.markup : null,
|
|
3452
|
+
poses
|
|
3453
|
+
});
|
|
3454
|
+
yield* posing.answered("advance", stepped);
|
|
3455
|
+
if (!stepped.told) return yield* unclocked("advance");
|
|
3456
|
+
elapsed += millis;
|
|
3457
|
+
return stepped.scroll;
|
|
3458
|
+
});
|
|
3459
|
+
return {
|
|
3460
|
+
advance,
|
|
3461
|
+
elapsed: Effect.sync(() => Duration.millis(elapsed))
|
|
3462
|
+
};
|
|
3463
|
+
}) };
|
|
3464
|
+
};
|
|
3465
|
+
//#endregion
|
|
3251
3466
|
//#region src/internal/page/viewport.ts
|
|
3252
3467
|
/**
|
|
3253
3468
|
* The viewport's size in CSS pixels. Playwright knows it only for a context it created; over CDP it
|
|
@@ -3255,6 +3470,10 @@ const make$5 = (page, bridge, input) => {
|
|
|
3255
3470
|
* pixel. Pointer bounds, page scrolls, crops, capture size and frame reuse all read this one
|
|
3256
3471
|
* source; the latest answer serves checks that cannot wait for the page.
|
|
3257
3472
|
*/
|
|
3473
|
+
const ViewportResultSchema = Schema.Struct({
|
|
3474
|
+
width: Schema.Finite,
|
|
3475
|
+
height: Schema.Finite
|
|
3476
|
+
});
|
|
3258
3477
|
const make$4 = (page, bridge) => {
|
|
3259
3478
|
const { playwright } = page;
|
|
3260
3479
|
let measuredViewport = null;
|
|
@@ -3288,16 +3507,18 @@ const make$4 = (page, bridge) => {
|
|
|
3288
3507
|
* Features use the same documented Page contract as consumers.
|
|
3289
3508
|
*/
|
|
3290
3509
|
const make$3 = Effect.fnUntraced(function* (options) {
|
|
3291
|
-
const page = make$
|
|
3510
|
+
const page = make$29(options, yield* Effect.scope);
|
|
3292
3511
|
const { id, playwright, native, owned, within, lane, span } = page;
|
|
3293
|
-
const bridge = yield* make$
|
|
3512
|
+
const bridge = yield* make$28(page);
|
|
3294
3513
|
const viewport = make$4(page, bridge);
|
|
3295
|
-
const input = make$
|
|
3296
|
-
const pictures = yield* make$
|
|
3297
|
-
const reading = yield* make$
|
|
3298
|
-
const navigation = make$
|
|
3514
|
+
const input = make$18(page, bridge, viewport);
|
|
3515
|
+
const pictures = yield* make$15(page, bridge, viewport);
|
|
3516
|
+
const reading = yield* make$13(page, bridge);
|
|
3517
|
+
const navigation = make$9(page, input.perform, input.preparePolicy);
|
|
3299
3518
|
const { capture } = pictures;
|
|
3300
|
-
const changes = make$
|
|
3519
|
+
const changes = make$11(page, bridge, pictures.estimate);
|
|
3520
|
+
const overlay = make$8(page, bridge);
|
|
3521
|
+
const poses = make$7(page, bridge);
|
|
3301
3522
|
const titles = lane.shared("title", true);
|
|
3302
3523
|
const viewports = lane.shared("viewport", true);
|
|
3303
3524
|
const state = Effect.map(capture.latest, (latest) => {
|
|
@@ -3312,6 +3533,7 @@ const make$3 = Effect.fnUntraced(function* (options) {
|
|
|
3312
3533
|
committedAt: Number.isFinite(committedAt) ? committedAt : void 0,
|
|
3313
3534
|
load: bridge.loaded(),
|
|
3314
3535
|
frame: Option.getOrUndefined(latest),
|
|
3536
|
+
overlay: overlay.drawn(),
|
|
3315
3537
|
text: reading.viewedSince(committedAt)
|
|
3316
3538
|
});
|
|
3317
3539
|
});
|
|
@@ -3323,7 +3545,7 @@ const make$3 = Effect.fnUntraced(function* (options) {
|
|
|
3323
3545
|
...navigation
|
|
3324
3546
|
}, action));
|
|
3325
3547
|
return {
|
|
3326
|
-
...make$
|
|
3548
|
+
...make$6(page, bridge, input),
|
|
3327
3549
|
...methods(perform),
|
|
3328
3550
|
perform,
|
|
3329
3551
|
clock: page.clock,
|
|
@@ -3345,13 +3567,18 @@ const make$3 = Effect.fnUntraced(function* (options) {
|
|
|
3345
3567
|
screenshot: pictures.screenshot,
|
|
3346
3568
|
frame: pictures.frame,
|
|
3347
3569
|
zoom: pictures.zoom,
|
|
3570
|
+
paint: pictures.paint,
|
|
3348
3571
|
viewport: viewports("", viewport.viewportFor("viewport").pipe(within("viewport"))).pipe(span("Page.viewport"), owned),
|
|
3349
3572
|
find: reading.find,
|
|
3573
|
+
layout: make$14(page, bridge),
|
|
3574
|
+
overlay: overlay.lease,
|
|
3575
|
+
poses: poses.lease,
|
|
3576
|
+
hold: make$5(page, bridge, overlay, poses).hold,
|
|
3350
3577
|
text: reading.text,
|
|
3351
3578
|
changes,
|
|
3352
|
-
window: make$
|
|
3579
|
+
window: make$10(page, changes, capture.recent),
|
|
3353
3580
|
state,
|
|
3354
|
-
ready: make$
|
|
3581
|
+
ready: make$12(page, bridge),
|
|
3355
3582
|
screencast: capture.stream,
|
|
3356
3583
|
captureStats: pictures.captureStats,
|
|
3357
3584
|
recentFrames: capture.recent,
|
|
@@ -3750,7 +3977,8 @@ const settingsOf = Effect.fnUntraced(function* (options) {
|
|
|
3750
3977
|
navigationTimeout: yield* bound("navigationTimeout", options.navigationTimeout, Duration.seconds(30)),
|
|
3751
3978
|
frameHistory: yield* bound("frameHistory", options.frameHistory, Duration.seconds(5)),
|
|
3752
3979
|
guard: options.guard,
|
|
3753
|
-
policyTimeout: yield* bound("policyTimeout", options.policyTimeout, Duration.minutes(5))
|
|
3980
|
+
policyTimeout: yield* bound("policyTimeout", options.policyTimeout, Duration.minutes(5)),
|
|
3981
|
+
pageTime: options.pageTime === true ? `effect-browser-time-${yield* make$27}` : void 0
|
|
3754
3982
|
};
|
|
3755
3983
|
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
3984
|
const eventHistory = options.eventHistory ?? 4096;
|
|
@@ -3842,8 +4070,6 @@ const releaseNative = (clock) => (run) => Effect.tryPromise(run).pipe(Effect.int
|
|
|
3842
4070
|
}), Effect.provideService(Clock.Clock, clock), Effect.ignore);
|
|
3843
4071
|
/** A page's own events among the browser's retained ones, and the openings of tabs it opened. */
|
|
3844
4072
|
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
4073
|
/**
|
|
3848
4074
|
* At most `maxPages` open pages, those a site opened included, which are never refused: an open
|
|
3849
4075
|
* past it waits for one to close, within `wait` on the owner's clock, then fails `Limit`, or fails
|
|
@@ -3920,7 +4146,7 @@ const tabs = (context, registry, budget, native, register, release, firstPageLoc
|
|
|
3920
4146
|
/** One connection owns clocks, loss, authority and its bounded timeline. */
|
|
3921
4147
|
const runtime = Effect.fnUntraced(function* (context, expiresAt, options) {
|
|
3922
4148
|
const clock = yield* Clock.Clock;
|
|
3923
|
-
const connection = yield* make$
|
|
4149
|
+
const connection = yield* make$27;
|
|
3924
4150
|
const protocol = yield* Current$1;
|
|
3925
4151
|
const releasePort = protocol.browser?.(connection, context);
|
|
3926
4152
|
yield* Effect.addFinalizer(() => Effect.sync(() => releasePort?.()));
|
|
@@ -3954,7 +4180,7 @@ const runtime = Effect.fnUntraced(function* (context, expiresAt, options) {
|
|
|
3954
4180
|
lose,
|
|
3955
4181
|
untilLost,
|
|
3956
4182
|
native,
|
|
3957
|
-
inputGate: make$
|
|
4183
|
+
inputGate: make$31({
|
|
3958
4184
|
now,
|
|
3959
4185
|
sequence: timeline.sequence,
|
|
3960
4186
|
closedBy: lostBy,
|
|
@@ -4009,7 +4235,7 @@ const make = Effect.fn("Browser.make")(function* (context, info, options = {}) {
|
|
|
4009
4235
|
mapping,
|
|
4010
4236
|
publish,
|
|
4011
4237
|
recentEvents: eventsOf(timeline.recent, id),
|
|
4012
|
-
openings: yield* make$
|
|
4238
|
+
openings: yield* make$26(playwright, cdp, registrations, closedBy),
|
|
4013
4239
|
focused: call("focus", () => focusing, closedBy).pipe(Effect.asVoid),
|
|
4014
4240
|
paging: (operation) => call(operation, () => paging, closedBy).pipe(Effect.asVoid),
|
|
4015
4241
|
closedBy,
|
|
@@ -4051,7 +4277,7 @@ const make = Effect.fn("Browser.make")(function* (context, info, options = {}) {
|
|
|
4051
4277
|
return page;
|
|
4052
4278
|
}).pipe(Scope.provide(scope), Effect.onError(() => Scope.close(scope, Exit.void)));
|
|
4053
4279
|
});
|
|
4054
|
-
for (const
|
|
4280
|
+
for (const content of documentScripts(settings.pageTime, options.initScripts ?? [])) yield* native("initScripts", () => context.addInitScript({ content }));
|
|
4055
4281
|
const register = yield* followOpened(context, registrations, registerPage, publish, now);
|
|
4056
4282
|
for (const existing of context.pages()) yield* register(existing);
|
|
4057
4283
|
yield* Effect.addFinalizer(() => Effect.sync(() => lose("released")));
|
|
@@ -4071,6 +4297,6 @@ const make = Effect.fn("Browser.make")(function* (context, info, options = {}) {
|
|
|
4071
4297
|
return Browser.of(service);
|
|
4072
4298
|
});
|
|
4073
4299
|
//#endregion
|
|
4074
|
-
export { make$1 as a, make as i, Browser_exports as n,
|
|
4300
|
+
export { make$1 as a, make as i, Browser_exports as n, make$31 as o, Suspension as r, Browser as t };
|
|
4075
4301
|
|
|
4076
|
-
//# sourceMappingURL=Browser-
|
|
4302
|
+
//# sourceMappingURL=Browser-CAQFhTkM.mjs.map
|