effect-browser 0.2.0-beta.8 → 0.3.0-beta.5
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 +705 -1166
- package/dist/Browser-CM65Uo7f.mjs +437 -0
- package/dist/Browser-CM65Uo7f.mjs.map +1 -0
- package/dist/Browser.d.mts +115 -3
- package/dist/Browser.mjs +2 -22
- package/dist/BrowserError-DXXIA6Rk.d.mts +135 -0
- package/dist/BrowserError.d.mts +2 -0
- package/dist/BrowserError.mjs +202 -0
- package/dist/BrowserError.mjs.map +1 -0
- package/dist/BrowserEvent-DzdNdvoh.d.mts +277 -0
- package/dist/BrowserEvent.d.mts +2 -0
- package/dist/BrowserEvent.mjs +295 -0
- package/dist/BrowserEvent.mjs.map +1 -0
- package/dist/Cdp.d.mts +32 -0
- package/dist/Cdp.mjs +61 -0
- package/dist/Cdp.mjs.map +1 -0
- package/dist/Change-DNvztNLu.mjs +138 -0
- package/dist/Change-DNvztNLu.mjs.map +1 -0
- package/dist/Change-DVP2IJWm.d.mts +71 -0
- package/dist/Change.d.mts +2 -0
- package/dist/Change.mjs +2 -0
- package/dist/Chromium.d.mts +29 -81
- package/dist/Chromium.mjs +57 -392
- package/dist/Chromium.mjs.map +1 -1
- package/dist/Expect.d.mts +62 -0
- package/dist/Expect.mjs +114 -0
- package/dist/Expect.mjs.map +1 -0
- package/dist/Frame-BERmf_gM.d.mts +117 -0
- package/dist/Frame.d.mts +2 -0
- package/dist/Frame.mjs +123 -0
- package/dist/Frame.mjs.map +1 -0
- package/dist/Moment.d.mts +2 -0
- package/dist/Moment.mjs +288 -0
- package/dist/Moment.mjs.map +1 -0
- package/dist/Motion.d.mts +40 -0
- package/dist/Motion.mjs +122 -0
- package/dist/Motion.mjs.map +1 -0
- package/dist/Page-D4281dIi.mjs +618 -0
- package/dist/Page-D4281dIi.mjs.map +1 -0
- package/dist/Page-DYTdVhYa.d.mts +593 -0
- package/dist/Page.d.mts +2 -0
- package/dist/Page.mjs +2 -0
- package/dist/Plan-CNNOU1Tx.d.mts +112 -0
- package/dist/Plan-Dtrb-8im.mjs +311 -0
- package/dist/Plan-Dtrb-8im.mjs.map +1 -0
- package/dist/Plan.d.mts +2 -3
- package/dist/Plan.mjs +2 -2
- package/dist/Policy.d.mts +76 -0
- package/dist/Policy.mjs +237 -0
- package/dist/Policy.mjs.map +1 -0
- package/dist/Presentation.d.mts +48 -0
- package/dist/Presentation.mjs +117 -0
- package/dist/Presentation.mjs.map +1 -0
- package/dist/Snapshot-B34hZ4Jl.d.mts +68 -0
- package/dist/Snapshot.d.mts +2 -0
- package/dist/Snapshot.mjs +79 -0
- package/dist/Snapshot.mjs.map +1 -0
- package/dist/Stage.d.mts +54 -0
- package/dist/Stage.mjs +133 -0
- package/dist/Stage.mjs.map +1 -0
- package/dist/Supervisor-BtEG93gR.mjs +420 -0
- package/dist/Supervisor-BtEG93gR.mjs.map +1 -0
- package/dist/Supervisor-Im6-wbg5.d.mts +230 -0
- package/dist/Supervisor.d.mts +2 -0
- package/dist/Supervisor.mjs +2 -0
- package/dist/context-DAYjATgC.mjs +137 -0
- package/dist/context-DAYjATgC.mjs.map +1 -0
- package/dist/index.d.mts +17 -14
- package/dist/index.mjs +18 -13
- package/dist/match.inpage-xOe9LNO0.mjs +48 -0
- package/dist/match.inpage-xOe9LNO0.mjs.map +1 -0
- package/dist/page-Banfm_zc.mjs +5097 -0
- package/dist/page-Banfm_zc.mjs.map +1 -0
- package/dist/rolldown-runtime-D7D4PA-g.mjs +13 -0
- package/dist/url-CcL0K7S0.mjs +262 -0
- package/dist/url-CcL0K7S0.mjs.map +1 -0
- package/package.json +96 -61
- package/src/Browser.ts +625 -0
- package/src/BrowserError.ts +225 -0
- package/src/BrowserEvent.ts +294 -0
- package/src/Cdp.ts +101 -0
- package/src/Change.ts +88 -0
- package/src/Chromium.ts +102 -0
- package/src/Expect.ts +180 -0
- package/src/Frame.ts +130 -0
- package/src/Moment.ts +479 -0
- package/src/Motion.ts +166 -0
- package/src/Page.ts +520 -0
- package/src/Plan.ts +350 -0
- package/src/Policy.ts +325 -0
- package/src/Presentation.ts +195 -0
- package/src/Snapshot.ts +89 -0
- package/src/Stage.ts +223 -0
- package/src/Supervisor.ts +353 -0
- package/src/index.ts +20 -0
- package/src/internal/input/actions.ts +607 -0
- package/src/internal/input/dispatch.ts +161 -0
- package/src/internal/input/edit.inpage.ts +162 -0
- package/src/internal/input/evidence.inpage.ts +164 -0
- package/src/internal/input/guard.inpage.ts +605 -0
- package/src/internal/input/guard.ts +183 -0
- package/src/internal/input/keyboard.ts +112 -0
- package/src/internal/input/keys.ts +127 -0
- package/src/internal/input/perform.ts +322 -0
- package/src/internal/input/pointer.ts +153 -0
- package/src/internal/input/replies.ts +159 -0
- package/src/internal/input/settle.ts +50 -0
- package/src/internal/input/style.ts +186 -0
- package/src/internal/input/targets.inpage.ts +293 -0
- package/src/internal/input/targets.ts +148 -0
- package/src/internal/page/bridge.ts +386 -0
- package/src/internal/page/context.ts +302 -0
- package/src/internal/page/lane.ts +301 -0
- package/src/internal/page/navigation.ts +183 -0
- package/src/internal/page/openings.ts +87 -0
- package/src/internal/page/page.ts +137 -0
- package/src/internal/page/url.ts +100 -0
- package/src/internal/page/viewport.ts +43 -0
- package/src/internal/pictures/capture.ts +778 -0
- package/src/internal/pictures/clock.ts +141 -0
- package/src/internal/pictures/pictures.ts +520 -0
- package/src/internal/pictures/transport.ts +242 -0
- package/src/internal/reading/choose.ts +100 -0
- package/src/internal/reading/context.inpage.ts +201 -0
- package/src/internal/reading/controls.inpage.ts +158 -0
- package/src/internal/reading/expect.inpage.ts +70 -0
- package/src/internal/reading/match.inpage.ts +92 -0
- package/src/internal/reading/names.inpage.ts +306 -0
- package/src/internal/reading/outline.inpage.ts +260 -0
- package/src/internal/reading/reading.ts +223 -0
- package/src/internal/reading/ready.inpage.ts +154 -0
- package/src/internal/reading/ready.ts +105 -0
- package/src/internal/reading/subjects.inpage.ts +188 -0
- package/src/internal/reading/text.inpage.ts +135 -0
- package/src/internal/reading/walk.inpage.ts +220 -0
- package/src/internal/supervisor/lifecycle.ts +265 -0
- package/src/internal/timeline/changes.inpage.ts +216 -0
- package/src/internal/timeline/changes.ts +100 -0
- package/src/internal/timeline/events.ts +93 -0
- package/src/internal/timeline/fold.inpage.ts +123 -0
- package/src/internal/timeline/history.inpage.ts +229 -0
- package/src/internal/timeline/marks.inpage.ts +207 -0
- package/src/internal/timeline/record.inpage.ts +133 -0
- package/src/internal/timeline/sight.inpage.ts +122 -0
- package/src/internal/timeline/window.ts +96 -0
- package/src/internal/timeline/words.ts +65 -0
- package/dist/Bootstrap-B9UUXsvF.d.mts +0 -183
- package/dist/Bootstrap-CeQOWBy6.mjs +0 -189
- package/dist/Bootstrap-CeQOWBy6.mjs.map +0 -1
- package/dist/Bootstrap.d.mts +0 -3
- package/dist/Bootstrap.mjs +0 -2
- package/dist/Browser-n-bKgBNN.d.mts +0 -372
- package/dist/Browser.mjs.map +0 -1
- package/dist/BrowserData-CPIIIHol.d.mts +0 -585
- package/dist/BrowserData.d.mts +0 -3
- package/dist/BrowserData.mjs +0 -695
- package/dist/BrowserData.mjs.map +0 -1
- package/dist/BrowserRuntime-CFe9uUTv.d.mts +0 -148
- package/dist/BrowserRuntime-HJ1yYlFS.mjs +0 -6741
- package/dist/BrowserRuntime-HJ1yYlFS.mjs.map +0 -1
- package/dist/BrowserRuntime.d.mts +0 -3
- package/dist/BrowserRuntime.mjs +0 -3
- package/dist/Capture.d.mts +0 -56
- package/dist/Capture.mjs +0 -678
- package/dist/Capture.mjs.map +0 -1
- package/dist/CaptureData-CYriZHX1.mjs +0 -201
- package/dist/CaptureData-CYriZHX1.mjs.map +0 -1
- package/dist/CaptureData.d.mts +0 -219
- package/dist/CaptureData.mjs +0 -2
- package/dist/Errors.d.mts +0 -158
- package/dist/Errors.mjs +0 -207
- package/dist/Errors.mjs.map +0 -1
- package/dist/Images-CaaPNeed.mjs +0 -76
- package/dist/Images-CaaPNeed.mjs.map +0 -1
- package/dist/OperationOptions-DAeRS6O9.mjs +0 -55
- package/dist/OperationOptions-DAeRS6O9.mjs.map +0 -1
- package/dist/PageControl.d.mts +0 -15
- package/dist/PageControl.mjs +0 -34
- package/dist/PageControl.mjs.map +0 -1
- package/dist/PageRegistry-B3q9DS3g.mjs +0 -164
- package/dist/PageRegistry-B3q9DS3g.mjs.map +0 -1
- package/dist/Plan-D8qQ48Ic.mjs +0 -512
- package/dist/Plan-D8qQ48Ic.mjs.map +0 -1
- package/dist/PlanData-B668RxbQ.d.mts +0 -4831
- package/dist/PlanData.d.mts +0 -3
- package/dist/PlanData.mjs +0 -268
- package/dist/PlanData.mjs.map +0 -1
- package/dist/PlanInput-BJcPPncs.mjs +0 -75
- package/dist/PlanInput-BJcPPncs.mjs.map +0 -1
- package/dist/PublicSession-Bs61Eal8.mjs +0 -5601
- package/dist/PublicSession-Bs61Eal8.mjs.map +0 -1
- package/dist/Testing.d.mts +0 -479
- package/dist/Testing.mjs +0 -2147
- package/dist/Testing.mjs.map +0 -1
- package/dist/Timeline-fV22Xk-S.d.mts +0 -29
- package/dist/Timeline.d.mts +0 -4
- package/dist/Timeline.mjs +0 -20
- package/dist/Timeline.mjs.map +0 -1
- package/dist/TimelineData-BsOn-YGZ.d.mts +0 -3818
- package/dist/TimelineData.d.mts +0 -3
- package/dist/TimelineData.mjs +0 -482
- package/dist/TimelineData.mjs.map +0 -1
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In the page: whether what the recorder marked was in view, and what it showed, judged as the page
|
|
3
|
+
* renders it. An IntersectionObserver watches each element the record follows: it reports as the
|
|
4
|
+
* page renders, forces no layout, and leaves a removed element the state it last reported. What
|
|
5
|
+
* changed counts as seen when it was in the viewport and its style showed it; what went counts as
|
|
6
|
+
* seen when it was in view before it went. Words that need the page's layout are read on render
|
|
7
|
+
* too, as `text` reads an element, by the walk's one rule for what shows and with fields masked.
|
|
8
|
+
* An element whose state alone the record wants, as for a class change on something it does not
|
|
9
|
+
* follow, is looked at once. See `names.inpage.ts` for what a page-side part may use.
|
|
10
|
+
*/
|
|
11
|
+
import type { Names } from "../reading/names.inpage.ts";
|
|
12
|
+
import type { Texts } from "../reading/text.inpage.ts";
|
|
13
|
+
import type { Walk } from "../reading/walk.inpage.ts";
|
|
14
|
+
import type { Sample, Shown } from "./fold.inpage.ts";
|
|
15
|
+
import type { History } from "./history.inpage.ts";
|
|
16
|
+
|
|
17
|
+
export const sight = (names: Names, walked: Walk, texts: Texts, kept: History) => {
|
|
18
|
+
const { clean } = names;
|
|
19
|
+
const { visible } = walked;
|
|
20
|
+
// Whether each watched element was in view as the page last rendered it, and whether the style
|
|
21
|
+
// of one looked at once showed it.
|
|
22
|
+
let viewed = new WeakMap<Element, boolean>();
|
|
23
|
+
let watching = new WeakSet<Element>();
|
|
24
|
+
let states = new WeakMap<Element, boolean>();
|
|
25
|
+
const waiting = new Map<Element, Array<Sample>>();
|
|
26
|
+
|
|
27
|
+
/** What an element shows: its words, if its style shows it. */
|
|
28
|
+
const shownBy = (element: Element): Shown =>
|
|
29
|
+
element.isConnected && visible(element)
|
|
30
|
+
? clean(texts.lines(element, false), 200) || null
|
|
31
|
+
: null;
|
|
32
|
+
|
|
33
|
+
/** Settle what waited on an element; its words are read once, if one of them needs them. */
|
|
34
|
+
const judge = (element: Element, pending: ReadonlyArray<Sample>, seen: boolean, was: boolean) => {
|
|
35
|
+
const shown = pending.some((sample) => sample.shown === undefined)
|
|
36
|
+
? shownBy(element)
|
|
37
|
+
: undefined;
|
|
38
|
+
|
|
39
|
+
for (const sample of pending) {
|
|
40
|
+
const now = sample.shown === undefined ? shown : sample.shown;
|
|
41
|
+
|
|
42
|
+
kept.settle(element, sample, now, now === null ? was : seen);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const observer = new IntersectionObserver((entries) => {
|
|
47
|
+
for (const { target, isIntersecting } of entries) {
|
|
48
|
+
const was = viewed.get(target) ?? false;
|
|
49
|
+
const seen = isIntersecting && visible(target);
|
|
50
|
+
const pending = waiting.get(target);
|
|
51
|
+
|
|
52
|
+
viewed.set(target, seen);
|
|
53
|
+
waiting.delete(target);
|
|
54
|
+
if (pending !== undefined) judge(target, pending, seen, was);
|
|
55
|
+
if (!kept.has(target)) {
|
|
56
|
+
states.set(target, visible(target));
|
|
57
|
+
unwatch(target);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
/** Watch an element, asking for a fresh report even if it is watched already. */
|
|
63
|
+
const watch = (element: Element) => {
|
|
64
|
+
watching.add(element);
|
|
65
|
+
observer.unobserve(element);
|
|
66
|
+
observer.observe(element);
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const unwatch = (element: Element) => {
|
|
70
|
+
watching.delete(element);
|
|
71
|
+
observer.unobserve(element);
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
return {
|
|
75
|
+
/** Judge a sample at once if what it shows and whether it is in view are known, else on render. */
|
|
76
|
+
look: (element: Element, sample: Sample) => {
|
|
77
|
+
const view = viewed.get(element);
|
|
78
|
+
|
|
79
|
+
if (sample.shown !== undefined && view !== undefined && watching.has(element)) {
|
|
80
|
+
sample.seen = view;
|
|
81
|
+
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
waiting.set(element, [...(waiting.get(element) ?? []), sample]);
|
|
85
|
+
watch(element);
|
|
86
|
+
},
|
|
87
|
+
/**
|
|
88
|
+
* Look at an element once, for its state when it next changes: as it renders, or `now`, by its
|
|
89
|
+
* style, as for the few the record looks at as it starts.
|
|
90
|
+
*/
|
|
91
|
+
glance: (element: Element, now = false) => {
|
|
92
|
+
if (now) states.set(element, visible(element));
|
|
93
|
+
if (!watching.has(element)) watch(element);
|
|
94
|
+
},
|
|
95
|
+
/** Whether the style of an element looked at once showed it, if it was. */
|
|
96
|
+
state: (element: Element): boolean | undefined => states.get(element),
|
|
97
|
+
/** Whether a watched element was in view as the page last rendered it. */
|
|
98
|
+
viewed: (element: Element): boolean => viewed.get(element) ?? false,
|
|
99
|
+
unwatch,
|
|
100
|
+
/** Judge now what the page has not rendered since it changed, as a hidden tab never does. */
|
|
101
|
+
settle: () => {
|
|
102
|
+
for (const [element, pending] of waiting) {
|
|
103
|
+
const seen =
|
|
104
|
+
element.isConnected && walked.inView(element.getBoundingClientRect()) && visible(element);
|
|
105
|
+
|
|
106
|
+
judge(element, pending, seen, viewed.get(element) ?? false);
|
|
107
|
+
viewed.set(element, seen);
|
|
108
|
+
}
|
|
109
|
+
waiting.clear();
|
|
110
|
+
for (const key of kept.forgotten()) if (key instanceof Element) unwatch(key);
|
|
111
|
+
},
|
|
112
|
+
clear: () => {
|
|
113
|
+
observer.disconnect();
|
|
114
|
+
waiting.clear();
|
|
115
|
+
viewed = new WeakMap();
|
|
116
|
+
watching = new WeakSet();
|
|
117
|
+
states = new WeakMap();
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
export type Sight = ReturnType<typeof sight>;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A page's window over its three tracks on the browser's host clock: the events and frames it
|
|
3
|
+
* keeps, at no call, and one read of its changes, the first starting its record. A read that fails
|
|
4
|
+
* is missing, with why, and the window is still made.
|
|
5
|
+
*/
|
|
6
|
+
import { Duration, Effect, Option, Result, Schema } from "effect";
|
|
7
|
+
|
|
8
|
+
import { type BrowserError, InvalidRequest } from "../../BrowserError.ts";
|
|
9
|
+
import { type BrowserEvent, TrackEvent } from "../../BrowserEvent.ts";
|
|
10
|
+
import type { Changes } from "../../Change.ts";
|
|
11
|
+
import { Frame } from "../../Frame.ts";
|
|
12
|
+
import { Window } from "../../Moment.ts";
|
|
13
|
+
import type { ChangesOptions, WindowOptions } from "../../Page.ts";
|
|
14
|
+
import { failWith, type PageContext } from "../page/context.ts";
|
|
15
|
+
|
|
16
|
+
const isWindow = Schema.is(Window);
|
|
17
|
+
const isFrame = Schema.is(Frame);
|
|
18
|
+
const isTrackEvent = Schema.is(TrackEvent);
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Where a window asked at `now` starts and ends: never after now, nor starting after it ends.
|
|
22
|
+
* Nothing for a bound that is not finite, or a negative reach back.
|
|
23
|
+
*/
|
|
24
|
+
export const boundsOf = ({ since, until }: Pick<WindowOptions, "since" | "until">, now: number) => {
|
|
25
|
+
const end = until === undefined ? now : isFrame(until) ? until.hostTime : Math.min(until, now);
|
|
26
|
+
|
|
27
|
+
const start = isWindow(since)
|
|
28
|
+
? since.until
|
|
29
|
+
: isFrame(since)
|
|
30
|
+
? since.hostTime
|
|
31
|
+
: !Duration.isDuration(since)
|
|
32
|
+
? since
|
|
33
|
+
: Duration.isNegative(since)
|
|
34
|
+
? Number.NaN
|
|
35
|
+
: end - Duration.toMillis(since);
|
|
36
|
+
|
|
37
|
+
return Number.isFinite(start) && Number.isFinite(end)
|
|
38
|
+
? Option.some({ since: Math.min(start, end), until: end })
|
|
39
|
+
: Option.none();
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* A window's share of the kept tracks: events after its start, frames painted from it, both up to
|
|
44
|
+
* its end, so consecutive windows hold each event once and the next begins with the frame the last
|
|
45
|
+
* ended on. Pointer, key and wheel input is the presentation track, not an event here.
|
|
46
|
+
*/
|
|
47
|
+
export const within = (
|
|
48
|
+
{ since, until }: { readonly since: number; readonly until: number },
|
|
49
|
+
events: ReadonlyArray<BrowserEvent>,
|
|
50
|
+
frames: ReadonlyArray<Frame>,
|
|
51
|
+
) => ({
|
|
52
|
+
events: events.filter((event) => event.at > since && event.at <= until && !isTrackEvent(event)),
|
|
53
|
+
frames: frames.filter((frame) => frame.hostTime >= since && frame.hostTime <= until),
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
export const make =
|
|
57
|
+
(
|
|
58
|
+
page: PageContext,
|
|
59
|
+
read: (options: ChangesOptions) => Effect.Effect<Changes, BrowserError>,
|
|
60
|
+
frames: Effect.Effect<ReadonlyArray<Frame>>,
|
|
61
|
+
) =>
|
|
62
|
+
({ since, until, unmask }: WindowOptions) =>
|
|
63
|
+
Effect.gen(function* () {
|
|
64
|
+
const asked = boundsOf({ since, until }, page.now());
|
|
65
|
+
|
|
66
|
+
if (Option.isNone(asked))
|
|
67
|
+
return yield* failWith(
|
|
68
|
+
"window",
|
|
69
|
+
new InvalidRequest({
|
|
70
|
+
detail: "a window's bounds must be finite, its reach not negative",
|
|
71
|
+
}),
|
|
72
|
+
);
|
|
73
|
+
const bounds = asked.value;
|
|
74
|
+
|
|
75
|
+
// A previous window's changes go on exactly where they ended, on the page's own clock, and a
|
|
76
|
+
// frame bounds them at its paint, so that they hold nothing it does not show.
|
|
77
|
+
const changes = yield* Effect.result(
|
|
78
|
+
read({
|
|
79
|
+
since: isWindow(since)
|
|
80
|
+
? (since.changes ?? bounds.since)
|
|
81
|
+
: isFrame(since)
|
|
82
|
+
? since
|
|
83
|
+
: bounds.since,
|
|
84
|
+
until: isFrame(until) ? until : bounds.until,
|
|
85
|
+
unmask,
|
|
86
|
+
}),
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
return new Window({
|
|
90
|
+
page: page.id,
|
|
91
|
+
...bounds,
|
|
92
|
+
...within(bounds, yield* page.recentEvents, yield* frames),
|
|
93
|
+
changes: Result.getOrUndefined(changes),
|
|
94
|
+
missing: Option.toArray(Result.getFailure(changes)),
|
|
95
|
+
});
|
|
96
|
+
}).pipe(page.span("Page.window"), page.owned);
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What changed on a page, in words for a model: a change with where it is, and what it is. A moment
|
|
3
|
+
* tells its changes this way, and a tool's receipt the changes its action caused.
|
|
4
|
+
*/
|
|
5
|
+
import type { Subject, SubjectContext } from "../../BrowserEvent.ts";
|
|
6
|
+
import type { Change } from "../../Change.ts";
|
|
7
|
+
|
|
8
|
+
export const quoted = (value: string | undefined) => JSON.stringify(value ?? "");
|
|
9
|
+
|
|
10
|
+
/** A subject in words, such as `button "Play"`; one without a name says where it was. */
|
|
11
|
+
export const named = (subject: Subject, point: string | undefined) => {
|
|
12
|
+
const kind = subject.role ?? subject.tag;
|
|
13
|
+
|
|
14
|
+
if (subject.name !== "") return `${kind} ${JSON.stringify(subject.name)}`;
|
|
15
|
+
|
|
16
|
+
return point === undefined ? kind : `${kind} at ${point}`;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/** A change's context in words: `row "Ether", column "1h"` or `beside "Price", under "Bitcoin"`. */
|
|
20
|
+
export const where = ({ row, column, label, heading }: SubjectContext, grouped = false) => {
|
|
21
|
+
const parts = [
|
|
22
|
+
row === undefined ? "" : `row ${quoted(row)}`,
|
|
23
|
+
column === undefined || grouped ? "" : `column ${quoted(column)}`,
|
|
24
|
+
label === undefined ? "" : `beside ${quoted(label)}`,
|
|
25
|
+
heading === undefined || grouped ? "" : `under ${quoted(heading)}`,
|
|
26
|
+
].filter((part) => part !== "");
|
|
27
|
+
|
|
28
|
+
return parts.length === 0 ? "" : ` (${parts.join(", ")})`;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/** A change in words, such as `"$61,240" became "$62,010" (row "Bitcoin", column "Price")`. */
|
|
32
|
+
export const describe = (change: Change, grouped = false): string => {
|
|
33
|
+
const { subject, before, after, count, lowest, highest } = change;
|
|
34
|
+
const context = where(subject.context, grouped);
|
|
35
|
+
|
|
36
|
+
const range =
|
|
37
|
+
lowest === undefined || highest === undefined ? "" : `, from ${lowest} to ${highest}`;
|
|
38
|
+
|
|
39
|
+
const times = count > 1 ? ` (it changed ${count} times${range})` : "";
|
|
40
|
+
|
|
41
|
+
switch (change.kind) {
|
|
42
|
+
case "title":
|
|
43
|
+
return `the title ${before === undefined ? "now reads" : `${quoted(before)} became`} ${quoted(after)}`;
|
|
44
|
+
case "value": {
|
|
45
|
+
const field = named(subject, undefined);
|
|
46
|
+
|
|
47
|
+
if (after === "checked" || after === "not checked") return `${field} is now ${after}`;
|
|
48
|
+
if (after === undefined || after === "") return `${field} was cleared`;
|
|
49
|
+
|
|
50
|
+
return after === "••••" || before === undefined || before === ""
|
|
51
|
+
? `${field} was ${after === "••••" ? "edited" : `set to ${quoted(after)}`}`
|
|
52
|
+
: `${field} changed from ${quoted(before)} to ${quoted(after)}`;
|
|
53
|
+
}
|
|
54
|
+
case "appeared":
|
|
55
|
+
return `${quoted(after)} appeared${context}`;
|
|
56
|
+
case "disappeared":
|
|
57
|
+
return `${quoted(before)} disappeared${context}`;
|
|
58
|
+
case "brief":
|
|
59
|
+
return `${quoted(after)} appeared and went away again${context}`;
|
|
60
|
+
case "text":
|
|
61
|
+
return before === undefined
|
|
62
|
+
? `now reads ${quoted(after)}${context}${times}`
|
|
63
|
+
: `${quoted(before)} became ${quoted(after)}${context}${times}`;
|
|
64
|
+
}
|
|
65
|
+
};
|
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
import { BrowserError, InitializationError } from "./Errors.mjs";
|
|
2
|
-
import { Cause, Effect, Schema } from "effect";
|
|
3
|
-
declare namespace BindingRegistration_d_exports {
|
|
4
|
-
export { FailureMode, Origin$1 as Origin, Registration, invoke, make, schema, snapshot };
|
|
5
|
-
}
|
|
6
|
-
declare const Invoke: unique symbol;
|
|
7
|
-
declare const Origin$1: Schema.NonEmptyString;
|
|
8
|
-
declare const FailureMode: Schema.Literals<readonly ["reject-call", "fail-session"]>;
|
|
9
|
-
declare const metadataSchema: Schema.Struct<{
|
|
10
|
-
readonly name: Schema.NonEmptyString;
|
|
11
|
-
readonly origins: Schema.$Array<Schema.NonEmptyString>;
|
|
12
|
-
readonly maxConcurrent: Schema.Int;
|
|
13
|
-
readonly maxInputBytes: Schema.Int;
|
|
14
|
-
readonly maxOutputBytes: Schema.Int;
|
|
15
|
-
readonly timeoutMillis: Schema.Int;
|
|
16
|
-
readonly failureMode: Schema.Literals<readonly ["reject-call", "fail-session"]>;
|
|
17
|
-
}>;
|
|
18
|
-
type Metadata = typeof metadataSchema.Type;
|
|
19
|
-
interface Registration<E, R> extends Metadata {
|
|
20
|
-
readonly [Invoke]: (text: string, check: Effect.Effect<void, InitializationError>) => Effect.Effect<string, E | InitializationError, R>;
|
|
21
|
-
}
|
|
22
|
-
/** Retain an issued live capability at schema boundaries; a copied shape is not authority. */
|
|
23
|
-
declare const schema: Schema.declare<Registration<unknown, unknown>, Registration<unknown, unknown>>;
|
|
24
|
-
/** Pack heterogeneous codecs and handlers while their concrete input/output types are known. */
|
|
25
|
-
declare const make: <I, IEncoded, O, OEncoded, E, R>(options: BindingOptions<I, IEncoded, O, OEncoded, E, R>) => Registration<E, R>;
|
|
26
|
-
/** Authentication is identity-based even when a caller copies every enumerable field/symbol. */
|
|
27
|
-
declare const snapshot: <E, R>(registration: Registration<E, R>) => Effect.Effect<Registration<E, R>, BrowserError, never>;
|
|
28
|
-
declare const invoke: <E, R>(registration: Registration<E, R>, text: string, check: Effect.Effect<void, InitializationError>) => Effect.Effect<string, E | InitializationError, R>;
|
|
29
|
-
declare namespace Bootstrap_d_exports {
|
|
30
|
-
export { BindingDiagnostics, BindingFailure, BindingFailureMode, BindingOptions, BindingRegistration, BindingStatistics, InitScript, Origin, Permission, PermissionGrant, Plan, PlanError, PlanRequirements, Readiness, ReadinessOutcome, binding, combine, empty, init, permissions };
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Exact scheme-and-host origin, as a document reports it. Patterns are deliberately absent:
|
|
34
|
-
* a registration that cannot say exactly where it applies does not belong in a plan.
|
|
35
|
-
*/
|
|
36
|
-
declare const Origin: Schema.NonEmptyString;
|
|
37
|
-
type Origin = typeof Origin.Type;
|
|
38
|
-
/**
|
|
39
|
-
* The reviewed subset of native permission capabilities. Each name is checked against a real
|
|
40
|
-
* browser in native acceptance; an unsupported capability is refused before it is exposed.
|
|
41
|
-
*/
|
|
42
|
-
declare const Permission: Schema.Literals<readonly ["accelerometer", "background-sync", "camera", "clipboard-read", "clipboard-write", "geolocation", "gyroscope", "magnetometer", "microphone", "midi", "notifications", "payment-handler", "storage-access"]>;
|
|
43
|
-
type Permission = typeof Permission.Type;
|
|
44
|
-
declare const PermissionGrant: Schema.Struct<{
|
|
45
|
-
readonly origin: Schema.NonEmptyString;
|
|
46
|
-
readonly permissions: Schema.$Array<Schema.Literals<readonly ["accelerometer", "background-sync", "camera", "clipboard-read", "clipboard-write", "geolocation", "gyroscope", "magnetometer", "microphone", "midi", "notifications", "payment-handler", "storage-access"]>>;
|
|
47
|
-
}>;
|
|
48
|
-
type PermissionGrant = typeof PermissionGrant.Type;
|
|
49
|
-
/**
|
|
50
|
-
* Registration is not readiness. A script may start asynchronous work, but it cannot pause the
|
|
51
|
-
* website's own scripts, so a document is ready only when its expression resolves to exactly
|
|
52
|
-
* `true`. A document that was already running when the bundle was registered never ran it:
|
|
53
|
-
* `RequireFreshNavigation` reports that instead of pretending otherwise, and an explicit
|
|
54
|
-
* reload of possibly uncertain work stays a caller's decision.
|
|
55
|
-
*/
|
|
56
|
-
declare const Readiness: Schema.Struct<{
|
|
57
|
-
readonly expression: Schema.NonEmptyString;
|
|
58
|
-
readonly timeoutMillis: Schema.Int;
|
|
59
|
-
readonly existingDocuments: Schema.Literals<readonly ["RequireFreshNavigation", "AcceptAlreadyRunning"]>;
|
|
60
|
-
}>;
|
|
61
|
-
type Readiness = typeof Readiness.Type;
|
|
62
|
-
/** Trusted host configuration. Script content is never model output or page input. */
|
|
63
|
-
declare const InitScript: Schema.Struct<{
|
|
64
|
-
readonly id: Schema.NonEmptyString;
|
|
65
|
-
readonly content: Schema.NonEmptyString;
|
|
66
|
-
/** When present, the step runs only on these documents and readiness skips the rest. */
|
|
67
|
-
readonly origins: Schema.optionalKey<Schema.$Array<Schema.NonEmptyString>>;
|
|
68
|
-
readonly readiness: Schema.optionalKey<Schema.Struct<{
|
|
69
|
-
readonly expression: Schema.NonEmptyString;
|
|
70
|
-
readonly timeoutMillis: Schema.Int;
|
|
71
|
-
readonly existingDocuments: Schema.Literals<readonly ["RequireFreshNavigation", "AcceptAlreadyRunning"]>;
|
|
72
|
-
}>>;
|
|
73
|
-
}>;
|
|
74
|
-
type InitScript = typeof InitScript.Type;
|
|
75
|
-
/** A callback failure can reject one page invocation or permanently fence the session. */
|
|
76
|
-
declare const BindingFailureMode: Schema.Literals<readonly ["reject-call", "fail-session"]>;
|
|
77
|
-
type BindingFailureMode = typeof BindingFailureMode.Type;
|
|
78
|
-
/**
|
|
79
|
-
* A registration issued by `binding`. Its private executable closure carries the real consumer
|
|
80
|
-
* E/R; copying the metadata or fabricating an object does not grant callback authority.
|
|
81
|
-
*/
|
|
82
|
-
type BindingRegistration<E = never, R = never> = Registration<E, R>;
|
|
83
|
-
/**
|
|
84
|
-
* Environment-free boundary codecs keep page data validation separate from consumer services.
|
|
85
|
-
* The handler's E/R remain visible on the Plan and are supplied only by the trusted host.
|
|
86
|
-
*/
|
|
87
|
-
interface BindingOptions<I, IEncoded, O, OEncoded, E, R> {
|
|
88
|
-
readonly name: string;
|
|
89
|
-
readonly origins: ReadonlyArray<Origin>;
|
|
90
|
-
readonly input: Schema.ConstraintCodec<I, IEncoded, never, never>;
|
|
91
|
-
readonly output: Schema.ConstraintCodec<O, OEncoded, never, never>;
|
|
92
|
-
/** Defaults to one concurrent invocation. Explicit values still pass the bounded schema. */
|
|
93
|
-
readonly maxConcurrent?: number;
|
|
94
|
-
/** Defaults to 64 KiB. */
|
|
95
|
-
readonly maxInputBytes?: number;
|
|
96
|
-
/** Defaults to 64 KiB. */
|
|
97
|
-
readonly maxOutputBytes?: number;
|
|
98
|
-
/** Defaults to 10 seconds for the complete invocation. */
|
|
99
|
-
readonly timeoutMillis?: number;
|
|
100
|
-
/** Defaults to rejecting this invocation without terminating the session. */
|
|
101
|
-
readonly failureMode?: BindingFailureMode;
|
|
102
|
-
readonly handle: (input: I) => Effect.Effect<O, E, R>;
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* One ordered bundle plus its host capabilities. Callback registrations preserve E/R through
|
|
106
|
-
* their executable closures; static script/permission plans remain serializable values.
|
|
107
|
-
*/
|
|
108
|
-
interface Plan<E = unknown, R = unknown> {
|
|
109
|
-
readonly scripts: ReadonlyArray<InitScript>;
|
|
110
|
-
readonly permissions: ReadonlyArray<PermissionGrant>;
|
|
111
|
-
readonly bindings?: ReadonlyArray<BindingRegistration<E, R>>;
|
|
112
|
-
}
|
|
113
|
-
/** Host-only typed evidence. Causes are never logged or returned to page callers. */
|
|
114
|
-
interface BindingFailure<E> {
|
|
115
|
-
readonly name: string;
|
|
116
|
-
readonly mode: BindingFailureMode;
|
|
117
|
-
readonly cause: Cause.Cause<E | InitializationError>;
|
|
118
|
-
}
|
|
119
|
-
interface BindingStatistics {
|
|
120
|
-
readonly name: string;
|
|
121
|
-
readonly inFlight: number;
|
|
122
|
-
readonly pendingNative: number;
|
|
123
|
-
/** Finished/interrupted invocations whose native work or disposal has not settled. */
|
|
124
|
-
readonly retired: number;
|
|
125
|
-
readonly accepted: number;
|
|
126
|
-
readonly succeeded: number;
|
|
127
|
-
readonly rejected: number;
|
|
128
|
-
}
|
|
129
|
-
/** Copied snapshot: at most sixteen bindings and the latest thirty-two failure records. */
|
|
130
|
-
interface BindingDiagnostics<E> {
|
|
131
|
-
readonly faulted: boolean;
|
|
132
|
-
readonly bindings: ReadonlyArray<BindingStatistics>;
|
|
133
|
-
readonly failures: ReadonlyArray<BindingFailure<E>>;
|
|
134
|
-
readonly droppedFailures: number;
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* Static plans remain serializable. Live binding plans retain issued registrations by identity;
|
|
138
|
-
* this schema neither executes their callbacks nor turns copied metadata into authority. Typed
|
|
139
|
-
* acquisition validates a separate snapshot so consumer E/R is not erased by a generic decoder.
|
|
140
|
-
*/
|
|
141
|
-
declare const Plan: Schema.Struct<{
|
|
142
|
-
readonly scripts: Schema.$Array<Schema.Struct<{
|
|
143
|
-
readonly id: Schema.NonEmptyString;
|
|
144
|
-
readonly content: Schema.NonEmptyString;
|
|
145
|
-
/** When present, the step runs only on these documents and readiness skips the rest. */
|
|
146
|
-
readonly origins: Schema.optionalKey<Schema.$Array<Schema.NonEmptyString>>;
|
|
147
|
-
readonly readiness: Schema.optionalKey<Schema.Struct<{
|
|
148
|
-
readonly expression: Schema.NonEmptyString;
|
|
149
|
-
readonly timeoutMillis: Schema.Int;
|
|
150
|
-
readonly existingDocuments: Schema.Literals<readonly ["RequireFreshNavigation", "AcceptAlreadyRunning"]>;
|
|
151
|
-
}>>;
|
|
152
|
-
}>>;
|
|
153
|
-
readonly permissions: Schema.$Array<Schema.Struct<{
|
|
154
|
-
readonly origin: Schema.NonEmptyString;
|
|
155
|
-
readonly permissions: Schema.$Array<Schema.Literals<readonly ["accelerometer", "background-sync", "camera", "clipboard-read", "clipboard-write", "geolocation", "gyroscope", "magnetometer", "microphone", "midi", "notifications", "payment-handler", "storage-access"]>>;
|
|
156
|
-
}>>;
|
|
157
|
-
readonly bindings: Schema.optionalKey<Schema.$Array<Schema.declare<Registration<unknown, unknown>, Registration<unknown, unknown>>>>;
|
|
158
|
-
}>;
|
|
159
|
-
type AnyPlan = Plan<unknown, unknown>;
|
|
160
|
-
type PlanError<P extends AnyPlan> = P extends Plan<infer E, infer _R> ? E : never;
|
|
161
|
-
type PlanRequirements<P extends AnyPlan> = P extends Plan<infer _E, infer R> ? R : never;
|
|
162
|
-
declare const empty: Plan<never, never>;
|
|
163
|
-
declare const init: (script: InitScript) => Plan<never, never>;
|
|
164
|
-
declare const permissions: (grant: PermissionGrant) => Plan<never, never>;
|
|
165
|
-
/**
|
|
166
|
-
* Register a page-callable host callback without running it or capturing an ambient runtime.
|
|
167
|
-
* Native installation later owns origin/document checks, bounded admission and disposal.
|
|
168
|
-
*/
|
|
169
|
-
declare const binding: <I, IEncoded, O, OEncoded, E, R>(options: BindingOptions<I, IEncoded, O, OEncoded, E, R>) => Plan<E, R>;
|
|
170
|
-
/** Combination is ordered and preserves every callback's consumer E/R union. */
|
|
171
|
-
declare function combine<const Plans extends ReadonlyArray<AnyPlan>>(...plans: Plans): Plan<PlanError<Plans[number]>, PlanRequirements<Plans[number]>>;
|
|
172
|
-
/** What the current document is, not a promise about any other document. */
|
|
173
|
-
type ReadinessOutcome = {
|
|
174
|
-
readonly _tag: "Ready";
|
|
175
|
-
} | {
|
|
176
|
-
readonly _tag: "NotApplicable";
|
|
177
|
-
} | {
|
|
178
|
-
readonly _tag: "RequiresNavigation";
|
|
179
|
-
};
|
|
180
|
-
//#endregion
|
|
181
|
-
export { binding as _, BindingRegistration as a, init as b, InitScript as c, PermissionGrant as d, Plan as f, ReadinessOutcome as g, Readiness as h, BindingOptions as i, Origin as l, PlanRequirements as m, BindingFailure as n, BindingStatistics as o, PlanError as p, BindingFailureMode as r, Bootstrap_d_exports as s, BindingDiagnostics as t, Permission as u, combine as v, permissions as x, empty as y };
|
|
182
|
-
export {};
|
|
183
|
-
//# sourceMappingURL=Bootstrap-B9UUXsvF.d.mts.map
|
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
import { BrowserError, InitializationError, Reasons } from "./Errors.mjs";
|
|
2
|
-
import { Identifier } from "./BrowserData.mjs";
|
|
3
|
-
import { Effect, Result, Schema } from "effect";
|
|
4
|
-
//#region src/internal/browser/BindingRegistration.ts
|
|
5
|
-
const Invoke = Symbol("BrowserBindingRegistration");
|
|
6
|
-
const issued = /* @__PURE__ */ new WeakSet();
|
|
7
|
-
const Origin$1 = Schema.NonEmptyString.check(Schema.isMaxLength(2048), Schema.makeFilter((value) => {
|
|
8
|
-
try {
|
|
9
|
-
const url = new URL(value);
|
|
10
|
-
return ["http:", "https:"].includes(url.protocol) && url.origin === value && !url.username && !url.password;
|
|
11
|
-
} catch {
|
|
12
|
-
return false;
|
|
13
|
-
}
|
|
14
|
-
}, { title: "an exact http(s) origin" }));
|
|
15
|
-
const FailureMode = Schema.Literals(["reject-call", "fail-session"]);
|
|
16
|
-
const metadataSchema = Schema.Struct({
|
|
17
|
-
name: Identifier,
|
|
18
|
-
origins: Schema.Array(Origin$1).check(Schema.isMaxLength(16), Schema.isUnique(), Schema.makeFilter((origins) => origins.length > 0, { title: "at least one allowed origin" })),
|
|
19
|
-
maxConcurrent: Schema.Int.check(Schema.isBetween({
|
|
20
|
-
minimum: 1,
|
|
21
|
-
maximum: 64
|
|
22
|
-
})),
|
|
23
|
-
maxInputBytes: Schema.Int.check(Schema.isBetween({
|
|
24
|
-
minimum: 1,
|
|
25
|
-
maximum: 1048576
|
|
26
|
-
})),
|
|
27
|
-
maxOutputBytes: Schema.Int.check(Schema.isBetween({
|
|
28
|
-
minimum: 1,
|
|
29
|
-
maximum: 4194304
|
|
30
|
-
})),
|
|
31
|
-
timeoutMillis: Schema.Int.check(Schema.isBetween({
|
|
32
|
-
minimum: 1,
|
|
33
|
-
maximum: 12e4
|
|
34
|
-
})),
|
|
35
|
-
failureMode: FailureMode
|
|
36
|
-
});
|
|
37
|
-
/** Retain an issued live capability at schema boundaries; a copied shape is not authority. */
|
|
38
|
-
const schema = Schema.declare((value) => typeof value === "object" && value !== null && issued.has(value), { title: "an issued browser binding registration" });
|
|
39
|
-
const issue = (metadata, invoke) => {
|
|
40
|
-
const registration = Object.freeze({
|
|
41
|
-
...metadata,
|
|
42
|
-
origins: Object.freeze([...metadata.origins]),
|
|
43
|
-
[Invoke]: invoke
|
|
44
|
-
});
|
|
45
|
-
issued.add(registration);
|
|
46
|
-
return registration;
|
|
47
|
-
};
|
|
48
|
-
/** Pack heterogeneous codecs and handlers while their concrete input/output types are known. */
|
|
49
|
-
const make = (options) => {
|
|
50
|
-
const { maxConcurrent = 1, maxInputBytes = 65536, maxOutputBytes = 65536, timeoutMillis = 1e4, failureMode = "reject-call" } = options;
|
|
51
|
-
const decoded = Schema.decodeResult(metadataSchema)({
|
|
52
|
-
...options,
|
|
53
|
-
maxConcurrent,
|
|
54
|
-
maxInputBytes,
|
|
55
|
-
maxOutputBytes,
|
|
56
|
-
timeoutMillis,
|
|
57
|
-
failureMode
|
|
58
|
-
});
|
|
59
|
-
if (Result.isFailure(decoded)) throw decoded.failure;
|
|
60
|
-
const metadata = decoded.success;
|
|
61
|
-
const { input, output, handle } = options;
|
|
62
|
-
if (!Schema.isSchema(input) || !Schema.isSchema(output) || typeof handle !== "function") throw new TypeError("Invalid binding registration");
|
|
63
|
-
const fail = (reason) => InitializationError.make({
|
|
64
|
-
operation: "callback",
|
|
65
|
-
step: metadata.name,
|
|
66
|
-
reason
|
|
67
|
-
});
|
|
68
|
-
return issue(metadata, Effect.fnUntraced(function* (text, check) {
|
|
69
|
-
if (new TextEncoder().encode(text).length > metadata.maxInputBytes) return yield* fail("input");
|
|
70
|
-
const decoded = yield* Schema.decodeEffect(Schema.fromJsonString(input))(text).pipe(Effect.catchCause(() => Effect.fail(fail("input"))));
|
|
71
|
-
yield* check;
|
|
72
|
-
const value = yield* Effect.suspend(() => handle(decoded));
|
|
73
|
-
const encoded = yield* Schema.encodeEffect(output)(value).pipe(Effect.catchCause(() => Effect.fail(fail("output"))));
|
|
74
|
-
const json = yield* Schema.decodeUnknownEffect(Schema.Json)(encoded).pipe(Effect.catchCause(() => Effect.fail(fail("output"))));
|
|
75
|
-
const result = yield* Schema.encodeEffect(Schema.fromJsonString(Schema.Json))(json).pipe(Effect.catchCause(() => Effect.fail(fail("output"))));
|
|
76
|
-
if (new TextEncoder().encode(result).length > metadata.maxOutputBytes) return yield* fail("output");
|
|
77
|
-
return result;
|
|
78
|
-
}));
|
|
79
|
-
};
|
|
80
|
-
/** Authentication is identity-based even when a caller copies every enumerable field/symbol. */
|
|
81
|
-
const snapshot = Effect.fnUntraced(function* (registration) {
|
|
82
|
-
const invalid = () => BrowserError.make({
|
|
83
|
-
operation: "configure",
|
|
84
|
-
reason: Reasons.Configuration.make({}),
|
|
85
|
-
outcome: "undispatched"
|
|
86
|
-
});
|
|
87
|
-
if (!issued.has(registration)) return yield* invalid();
|
|
88
|
-
const metadata = yield* Schema.decodeEffect(metadataSchema)(registration).pipe(Effect.mapError(invalid));
|
|
89
|
-
return issue(metadata, registration[Invoke]);
|
|
90
|
-
});
|
|
91
|
-
const invoke = (registration, text, check) => registration[Invoke](text, check);
|
|
92
|
-
//#endregion
|
|
93
|
-
//#region src/Bootstrap.ts
|
|
94
|
-
/**
|
|
95
|
-
* Exact scheme-and-host origin, as a document reports it. Patterns are deliberately absent:
|
|
96
|
-
* a registration that cannot say exactly where it applies does not belong in a plan.
|
|
97
|
-
*/
|
|
98
|
-
const Origin = Origin$1;
|
|
99
|
-
/**
|
|
100
|
-
* The reviewed subset of native permission capabilities. Each name is checked against a real
|
|
101
|
-
* browser in native acceptance; an unsupported capability is refused before it is exposed.
|
|
102
|
-
*/
|
|
103
|
-
const Permission = Schema.Literals([
|
|
104
|
-
"accelerometer",
|
|
105
|
-
"background-sync",
|
|
106
|
-
"camera",
|
|
107
|
-
"clipboard-read",
|
|
108
|
-
"clipboard-write",
|
|
109
|
-
"geolocation",
|
|
110
|
-
"gyroscope",
|
|
111
|
-
"magnetometer",
|
|
112
|
-
"microphone",
|
|
113
|
-
"midi",
|
|
114
|
-
"notifications",
|
|
115
|
-
"payment-handler",
|
|
116
|
-
"storage-access"
|
|
117
|
-
]);
|
|
118
|
-
const PermissionGrant = Schema.Struct({
|
|
119
|
-
origin: Origin,
|
|
120
|
-
permissions: Schema.Array(Permission).check(Schema.isMaxLength(16), Schema.isUnique())
|
|
121
|
-
});
|
|
122
|
-
/**
|
|
123
|
-
* Registration is not readiness. A script may start asynchronous work, but it cannot pause the
|
|
124
|
-
* website's own scripts, so a document is ready only when its expression resolves to exactly
|
|
125
|
-
* `true`. A document that was already running when the bundle was registered never ran it:
|
|
126
|
-
* `RequireFreshNavigation` reports that instead of pretending otherwise, and an explicit
|
|
127
|
-
* reload of possibly uncertain work stays a caller's decision.
|
|
128
|
-
*/
|
|
129
|
-
const Readiness = Schema.Struct({
|
|
130
|
-
expression: Schema.NonEmptyString.check(Schema.isMaxLength(4096)),
|
|
131
|
-
timeoutMillis: Schema.Int.check(Schema.isBetween({
|
|
132
|
-
minimum: 1,
|
|
133
|
-
maximum: 12e4
|
|
134
|
-
})),
|
|
135
|
-
existingDocuments: Schema.Literals(["RequireFreshNavigation", "AcceptAlreadyRunning"])
|
|
136
|
-
});
|
|
137
|
-
/** Trusted host configuration. Script content is never model output or page input. */
|
|
138
|
-
const InitScript = Schema.Struct({
|
|
139
|
-
id: Identifier,
|
|
140
|
-
content: Schema.NonEmptyString.check(Schema.isMaxLength(65536)),
|
|
141
|
-
/** When present, the step runs only on these documents and readiness skips the rest. */
|
|
142
|
-
origins: Schema.optionalKey(Schema.Array(Origin).check(Schema.isMaxLength(16), Schema.isUnique())),
|
|
143
|
-
readiness: Schema.optionalKey(Readiness)
|
|
144
|
-
});
|
|
145
|
-
/** A callback failure can reject one page invocation or permanently fence the session. */
|
|
146
|
-
const BindingFailureMode = FailureMode;
|
|
147
|
-
/**
|
|
148
|
-
* Static plans remain serializable. Live binding plans retain issued registrations by identity;
|
|
149
|
-
* this schema neither executes their callbacks nor turns copied metadata into authority. Typed
|
|
150
|
-
* acquisition validates a separate snapshot so consumer E/R is not erased by a generic decoder.
|
|
151
|
-
*/
|
|
152
|
-
const Plan = Schema.Struct({
|
|
153
|
-
scripts: Schema.Array(InitScript).check(Schema.isMaxLength(16)),
|
|
154
|
-
permissions: Schema.Array(PermissionGrant).check(Schema.isMaxLength(16)),
|
|
155
|
-
bindings: Schema.optionalKey(Schema.Array(schema).check(Schema.isMaxLength(16)))
|
|
156
|
-
});
|
|
157
|
-
const empty = {
|
|
158
|
-
scripts: [],
|
|
159
|
-
permissions: []
|
|
160
|
-
};
|
|
161
|
-
const init = (script) => ({
|
|
162
|
-
scripts: [script],
|
|
163
|
-
permissions: []
|
|
164
|
-
});
|
|
165
|
-
const permissions = (grant) => ({
|
|
166
|
-
scripts: [],
|
|
167
|
-
permissions: [grant]
|
|
168
|
-
});
|
|
169
|
-
/**
|
|
170
|
-
* Register a page-callable host callback without running it or capturing an ambient runtime.
|
|
171
|
-
* Native installation later owns origin/document checks, bounded admission and disposal.
|
|
172
|
-
*/
|
|
173
|
-
const binding = (options) => ({
|
|
174
|
-
scripts: [],
|
|
175
|
-
permissions: [],
|
|
176
|
-
bindings: [make(options)]
|
|
177
|
-
});
|
|
178
|
-
function combine(...plans) {
|
|
179
|
-
const bindings = plans.flatMap((plan) => plan.bindings === void 0 ? [] : [...plan.bindings]);
|
|
180
|
-
return {
|
|
181
|
-
scripts: plans.flatMap((plan) => [...plan.scripts]),
|
|
182
|
-
permissions: plans.flatMap((plan) => [...plan.permissions]),
|
|
183
|
-
...bindings.length === 0 ? {} : { bindings }
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
|
-
//#endregion
|
|
187
|
-
export { PermissionGrant as a, binding as c, init as d, permissions as f, Permission as i, combine as l, snapshot as m, InitScript as n, Plan as o, invoke as p, Origin as r, Readiness as s, BindingFailureMode as t, empty as u };
|
|
188
|
-
|
|
189
|
-
//# sourceMappingURL=Bootstrap-CeQOWBy6.mjs.map
|