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.
Files changed (134) hide show
  1. package/README.md +124 -5
  2. package/dist/ActionPort.d.mts +1 -1
  3. package/dist/ActionPort.mjs +1 -1
  4. package/dist/{Browser-BKPAbyys.mjs → Browser-CAQFhTkM.mjs} +559 -333
  5. package/dist/Browser-CAQFhTkM.mjs.map +1 -0
  6. package/dist/{Browser-wZhwZSlG.d.mts → Browser-DGR6ZEYo.d.mts} +9 -3
  7. package/dist/Browser.d.mts +1 -1
  8. package/dist/Browser.mjs +1 -1
  9. package/dist/{BrowserEvent-lLqJ3GJS.d.mts → BrowserEvent-C2p-NwuU.d.mts} +30 -6
  10. package/dist/BrowserEvent.d.mts +2 -2
  11. package/dist/BrowserEvent.mjs +20 -1
  12. package/dist/BrowserEvent.mjs.map +1 -1
  13. package/dist/{Change-Ba7INmay.d.mts → Change-CxT1mp2e.d.mts} +13 -2
  14. package/dist/Change.d.mts +1 -1
  15. package/dist/Change.mjs +7 -1
  16. package/dist/Change.mjs.map +1 -1
  17. package/dist/Clock-Du5nP-nK.d.mts +57 -0
  18. package/dist/Clock.d.mts +2 -57
  19. package/dist/Layout.d.mts +2 -0
  20. package/dist/Layout.mjs +81 -0
  21. package/dist/Layout.mjs.map +1 -0
  22. package/dist/Matching-MtcWZ_hA.d.mts +266 -0
  23. package/dist/Matching.d.mts +2 -37
  24. package/dist/Matching.mjs +22 -17
  25. package/dist/Matching.mjs.map +1 -1
  26. package/dist/Overlay-CoGw5tL_.d.mts +27 -0
  27. package/dist/Overlay.d.mts +2 -0
  28. package/dist/Overlay.mjs +30 -0
  29. package/dist/Overlay.mjs.map +1 -0
  30. package/dist/{Page-BF5izr8R.mjs → Page-BaAOshxo.mjs} +3 -1
  31. package/dist/Page-BaAOshxo.mjs.map +1 -0
  32. package/dist/{Page-CvsOEorc.d.mts → Page-CLzh5E9w.d.mts} +158 -6
  33. package/dist/Page.d.mts +2 -2
  34. package/dist/Page.mjs +1 -1
  35. package/dist/PageTime-68UPUZpZ.d.mts +29 -0
  36. package/dist/PageTime.d.mts +2 -0
  37. package/dist/PageTime.mjs +7 -0
  38. package/dist/PageTime.mjs.map +1 -0
  39. package/dist/Pose-2qqGzPvb.d.mts +32 -0
  40. package/dist/Pose.d.mts +2 -0
  41. package/dist/Pose.mjs +44 -0
  42. package/dist/Pose.mjs.map +1 -0
  43. package/dist/Site.d.mts +714 -0
  44. package/dist/Site.mjs +102 -0
  45. package/dist/Site.mjs.map +1 -0
  46. package/dist/{Stillness-CNlvayIo.mjs → Stillness-BwP0RdI4.mjs} +27 -6
  47. package/dist/Stillness-BwP0RdI4.mjs.map +1 -0
  48. package/dist/{Style-AO4V7Czt.mjs → Style-T3ezDYLI.mjs} +25 -2
  49. package/dist/{Style-AO4V7Czt.mjs.map → Style-T3ezDYLI.mjs.map} +1 -1
  50. package/dist/Style.d.mts +15 -2
  51. package/dist/Style.mjs +2 -2
  52. package/dist/Url-B7P-TWwL.d.mts +26 -0
  53. package/dist/Url.d.mts +2 -26
  54. package/dist/{Window-CMddGMt1.d.mts → Window-BDa8MtNP.d.mts} +4 -4
  55. package/dist/Window.d.mts +1 -1
  56. package/dist/{connection-CK83pvqP.mjs → connection-C_jWYIwe.mjs} +2 -2
  57. package/dist/{connection-CK83pvqP.mjs.map → connection-C_jWYIwe.mjs.map} +1 -1
  58. package/dist/{connection-2KHI4_KN.d.mts → connection-Db-YtlbE.d.mts} +2 -2
  59. package/dist/film/Film.d.mts +265 -0
  60. package/dist/film/Film.mjs +246 -0
  61. package/dist/film/Film.mjs.map +1 -0
  62. package/dist/fold.inpage-CyVZQHZL.d.mts +49 -0
  63. package/dist/index.d.mts +11 -8
  64. package/dist/index.mjs +8 -4
  65. package/dist/moment/Moment.d.mts +5 -5
  66. package/dist/plan/index.d.mts +2 -2
  67. package/dist/plan/index.mjs +2 -2
  68. package/dist/policy/Policy.d.mts +1 -1
  69. package/dist/policy/Policy.mjs +1 -1
  70. package/dist/pose.inpage-CLq7Mfdr.mjs +2042 -0
  71. package/dist/pose.inpage-CLq7Mfdr.mjs.map +1 -0
  72. package/dist/presentation/Presentation.d.mts +8 -1
  73. package/dist/presentation/Presentation.mjs +3 -1
  74. package/dist/presentation/Presentation.mjs.map +1 -1
  75. package/dist/presentation/Stage.d.mts +1 -1
  76. package/dist/providers/Cdp.d.mts +2 -2
  77. package/dist/providers/Cdp.mjs +1 -1
  78. package/dist/providers/Chromium.d.mts +1 -1
  79. package/dist/providers/Chromium.mjs +1 -1
  80. package/dist/stillness/Stillness.d.mts +1 -1
  81. package/dist/stillness/Stillness.mjs +1 -1
  82. package/dist/testing/index.d.mts +4 -30
  83. package/dist/testing/index.mjs +8 -2
  84. package/dist/testing/index.mjs.map +1 -1
  85. package/dist/workerd/Cdp.d.mts +2 -2
  86. package/dist/workerd/Cdp.mjs +1 -1
  87. package/package.json +32 -2
  88. package/src/Browser.ts +11 -6
  89. package/src/BrowserEvent.ts +19 -0
  90. package/src/Change.ts +7 -1
  91. package/src/Layout.ts +116 -0
  92. package/src/Matching.ts +24 -15
  93. package/src/Overlay.ts +37 -0
  94. package/src/Page.ts +45 -0
  95. package/src/PageTime.ts +47 -0
  96. package/src/Pose.ts +50 -0
  97. package/src/Site.ts +124 -0
  98. package/src/Style.ts +36 -0
  99. package/src/film/Film.ts +384 -0
  100. package/src/index.ts +4 -0
  101. package/src/internal/input/perform.ts +31 -3
  102. package/src/internal/input/pointer.ts +7 -4
  103. package/src/internal/input/targets.ts +1 -1
  104. package/src/internal/page/bridge.ts +65 -33
  105. package/src/internal/page/clock.inpage.ts +306 -0
  106. package/src/internal/page/compose.inpage.ts +101 -0
  107. package/src/internal/page/context.ts +2 -0
  108. package/src/internal/page/overlay.inpage.ts +96 -0
  109. package/src/internal/page/overlay.ts +89 -0
  110. package/src/internal/page/page.ts +12 -0
  111. package/src/internal/page/pose.inpage.ts +200 -0
  112. package/src/internal/page/pose.ts +80 -0
  113. package/src/internal/page/time.inpage.ts +49 -0
  114. package/src/internal/page/time.ts +122 -0
  115. package/src/internal/page/viewport.ts +3 -2
  116. package/src/internal/pictures/pictures.ts +93 -32
  117. package/src/internal/reading/layout.inpage.ts +193 -0
  118. package/src/internal/reading/layout.ts +101 -0
  119. package/src/internal/reading/names.inpage.ts +15 -0
  120. package/src/internal/reading/outline.inpage.ts +2 -18
  121. package/src/internal/reading/reading.ts +22 -2
  122. package/src/internal/reading/ready.inpage.ts +18 -23
  123. package/src/internal/reading/ready.ts +23 -3
  124. package/src/internal/reading/text.inpage.ts +1 -14
  125. package/src/internal/timeline/changes.inpage.ts +7 -15
  126. package/src/internal/timeline/changes.ts +14 -1
  127. package/src/internal/timeline/record.inpage.ts +15 -6
  128. package/src/presentation/Presentation.ts +13 -0
  129. package/src/stillness/Pixels.ts +26 -0
  130. package/src/stillness/Stillness.ts +30 -5
  131. package/src/testing/page.ts +5 -0
  132. package/dist/Browser-BKPAbyys.mjs.map +0 -1
  133. package/dist/Page-BF5izr8R.mjs.map +0 -1
  134. package/dist/Stillness-CNlvayIo.mjs.map +0 -1
package/src/Matching.ts CHANGED
@@ -11,6 +11,8 @@
11
11
  */
12
12
  import type { SubjectContext } from "./BrowserEvent.ts";
13
13
  import type { Point } from "./Geometry.ts";
14
+ import type { PickRequest } from "./internal/reading/layout.inpage.ts";
15
+ import type { Picks } from "./Layout.ts";
14
16
  import type { FindQuery } from "./Page.ts";
15
17
 
16
18
  /** A string, or a pattern sent to the page as its source and flags. */
@@ -27,22 +29,29 @@ export interface FindRequest {
27
29
  readonly scope: "viewport" | "document";
28
30
  }
29
31
 
32
+ const wanted = (value: string | RegExp | undefined): Wanted | null =>
33
+ value instanceof RegExp ? { source: value.source, flags: value.flags } : (value ?? null);
34
+
30
35
  /** A public query in its serializable, fully specified form. */
31
- export const request = (query: FindQuery, scope: FindRequest["scope"]): FindRequest => {
32
- const wanted = (value: string | RegExp | undefined): Wanted | null =>
33
- value instanceof RegExp ? { source: value.source, flags: value.flags } : (value ?? null);
34
-
35
- return {
36
- selector: query.selector ?? null,
37
- state: query.state ?? "visible",
38
- role: query.role ?? null,
39
- name: wanted(query.name),
40
- text: wanted(query.text),
41
- near: query.near ?? null,
42
- at: query.at ?? null,
43
- scope: query.scope ?? scope,
44
- };
45
- };
36
+ export const request = (query: FindQuery, scope: FindRequest["scope"]): FindRequest => ({
37
+ selector: query.selector ?? null,
38
+ state: query.state ?? "visible",
39
+ role: query.role ?? null,
40
+ name: wanted(query.name),
41
+ text: wanted(query.text),
42
+ near: query.near ?? null,
43
+ at: query.at ?? null,
44
+ scope: query.scope ?? scope,
45
+ });
46
+
47
+ /** Layout picks in their serializable form. */
48
+ export const pickRequests = (picks: Picks): ReadonlyArray<PickRequest> =>
49
+ Object.entries(picks).map(([id, pick]) => ({
50
+ ...request(pick, "document"),
51
+ id,
52
+ choose: pick.choose ?? "first",
53
+ words: wanted(pick.words),
54
+ }));
46
55
 
47
56
  /** What a query is matched against, read only when a rule needs it. */
48
57
  export interface Candidate {
package/src/Overlay.ts ADDED
@@ -0,0 +1,37 @@
1
+ /**
2
+ * A layer over a page that the library draws a caller's content into, without knowing what it
3
+ * shows: a pointer, a ring round what an agent is about to press, a caption, a character. It shows
4
+ * in screenshots, screencasts and a live view alike. The library's own readers never read it:
5
+ * `find`, `snapshot`, `layout`, `text`, `changes`, `ready` and stillness see the page as if it
6
+ * were not there, and input passes through it to the page.
7
+ *
8
+ * A page has one overlay at a time, for a scope. It sits above the page's own layers but beneath
9
+ * its top layer (a modal dialog, a popover), in viewport CSS pixels, and undoes a zoom the page
10
+ * sets on its root. Each new document starts without it, and it is drawn again there, with what
11
+ * it last showed, once the document has loaded. It is gone when its scope closes.
12
+ *
13
+ * @since 0.3.0
14
+ */
15
+ import { type Effect, Schema } from "effect";
16
+
17
+ import type { BrowserError } from "./BrowserError.ts";
18
+ import type { Box } from "./BrowserEvent.ts";
19
+
20
+ /**
21
+ * What the overlay shows. `Svg` is an SVG document sized to the viewport, whose own `viewBox` maps
22
+ * any design space onto it; its scripts and event handlers are dropped. `Empty` shows nothing.
23
+ */
24
+ export const Content = Schema.TaggedUnion({
25
+ Svg: { markup: Schema.String },
26
+ Empty: {},
27
+ });
28
+
29
+ export type Content = typeof Content.Type;
30
+
31
+ export interface Overlay {
32
+ /**
33
+ * Show `content` in place of what was shown, in one call to the page, after the actions asked
34
+ * before it. Says where the drawing's top-level parts are, in viewport CSS pixels.
35
+ */
36
+ readonly draw: (content: Content) => Effect.Effect<ReadonlyArray<Box>, BrowserError>;
37
+ }
package/src/Page.ts CHANGED
@@ -32,6 +32,10 @@ import * as Motion from "./Geometry.ts";
32
32
  import { FormFieldSchema } from "./internal/input/evidence.inpage.ts";
33
33
  import * as Guard from "./internal/input/guard.inpage.ts";
34
34
  import { Correlation, FailFast } from "./internal/page/lane.ts";
35
+ import type { Layout, Picks } from "./Layout.ts";
36
+ import type { Overlay } from "./Overlay.ts";
37
+ import type { Held } from "./PageTime.ts";
38
+ import type { Poses } from "./Pose.ts";
35
39
  import { type Snapshot, type SnapshotOptions } from "./Snapshot.ts";
36
40
  import * as Url from "./Url.ts";
37
41
  import type { Window } from "./Window.ts";
@@ -108,6 +112,14 @@ export interface ScreenshotOptions {
108
112
  readonly scale?: "css" | "device" | undefined;
109
113
  }
110
114
 
115
+ /** How a page paints for a scope; see `Page.paint`. */
116
+ export interface Paint {
117
+ /** Device pixels to each CSS pixel, more than 0 and at most 4. The layout keeps its size. */
118
+ readonly scale?: number | undefined;
119
+ /** False hides the page's scrollbars from its next document on, and its layout takes their room. */
120
+ readonly scrollbars?: boolean | undefined;
121
+ }
122
+
111
123
  /**
112
124
  * What `find` looks for. Every rule given must hold; with none, it finds every element in scope
113
125
  * that has a role or is a control.
@@ -246,6 +258,8 @@ export class State extends Schema.Class<State>("effect-browser/PageState")({
246
258
  load: Schema.optional(PageLoaded),
247
259
  /** The newest screencast frame, of whichever document it names. */
248
260
  frame: Schema.optional(Frame),
261
+ /** Where the overlay's drawing was last drawn, in viewport CSS pixels; absent with none shown. */
262
+ overlay: Schema.optional(Schema.Array(Box)),
249
263
  /** The viewport's text as it was last read, with the page's title then. */
250
264
  text: Schema.optional(Text),
251
265
  }) {}
@@ -468,6 +482,28 @@ export interface Page {
468
482
  * empty result, not a failure.
469
483
  */
470
484
  readonly find: (query?: FindQuery) => Effect.Effect<ReadonlyArray<Found>, BrowserError>;
485
+ /**
486
+ * Where each pick is, in one call to the page: its box unrounded, in the viewport and in the
487
+ * document, the boxes of words in it, and the viewport, scroll and scale they were read at. A
488
+ * pick that finds nothing is listed as missing, not a failure. See `Layout`.
489
+ */
490
+ readonly layout: (picks: Picks) => Effect.Effect<Layout, BrowserError>;
491
+ /**
492
+ * A layer over the page to draw into, for the scope, that the library's readers never read.
493
+ * One at a time: a second while one is open fails `InvalidRequest`. See `Overlay`.
494
+ */
495
+ readonly overlay: Effect.Effect<Overlay, BrowserError, Scope.Scope>;
496
+ /**
497
+ * Pose the page's own elements for the scope, moved, turned and scaled as a caller says, and put
498
+ * back when the scope closes. One lease at a time: a second while one is open fails
499
+ * `InvalidRequest`. See `Pose`.
500
+ */
501
+ readonly poses: Effect.Effect<Poses, BrowserError, Scope.Scope>;
502
+ /**
503
+ * Hold the page's own time for the scope, to step it on with `advance`; real time resumes when
504
+ * the scope closes. Needs the browser's `pageTime` option; one hold at a time. See `PageTime`.
505
+ */
506
+ readonly hold: Effect.Effect<Held, BrowserError, Scope.Scope>;
471
507
  /**
472
508
  * The text the viewport shows, or one element whole, in one call to the page. Field values read
473
509
  * `••••` unless `unmask`, and a secret field's always do, as does one that was secret when the
@@ -491,6 +527,15 @@ export interface Page {
491
527
  * its document and how far it has loaded, its newest frame, and its text and title as last read.
492
528
  */
493
529
  readonly state: Effect.Effect<State>;
530
+ /**
531
+ * Paint the page at `scale` device pixels to each CSS pixel, or without its scrollbars, for a
532
+ * scope: a screenshot with `scale: "device"` then has that many more pixels, while the layout,
533
+ * its boxes and input keep their CSS pixels. Scrollbars go from the next document on, and come
534
+ * back from the next after the scope, so paint, then load the page, then measure it. One at a
535
+ * time. A browser this library launched paints at the scale of its launch (Chromium's
536
+ * `deviceScaleFactor`), and refuses another.
537
+ */
538
+ readonly paint: (options: Paint) => Effect.Effect<void, BrowserError, Scope.Scope>;
494
539
 
495
540
  readonly click: (
496
541
  target: Target,
@@ -0,0 +1,47 @@
1
+ /**
2
+ * A page's own time, held and stepped, so what the page does by itself happens at times a caller
3
+ * chooses: a visual test takes a transition at exactly 120 ms, a test skips a 30 second countdown
4
+ * in one step, a recording's page moves one frame's worth per frame however long each takes.
5
+ *
6
+ * A browser opened with `pageTime` runs a page clock in each top document's main world, before
7
+ * the page's own scripts. Until `Page.hold`, it keeps real time. Held, the page's timers and
8
+ * intervals, its animation frames, `performance.now`, `Date.now`, `new Date()` and `Date()`, and
9
+ * its CSS transitions, CSS animations and Web Animations stand still, and each `advance` runs what
10
+ * falls due in time order, each timer at its own time, and then one animation frame at its end.
11
+ * An animation the page starts while held starts at the page time it is held at. Workers, media,
12
+ * `requestIdleCallback`, `MessageChannel`, events' `timeStamp` and frames' own documents keep real
13
+ * time. A clock that has been held is a page script's to notice: it replaces those globals.
14
+ *
15
+ * Loading takes real time: a document that replaces a held one starts on real time, and is held
16
+ * from the next `advance`. When the hold's scope closes, page time carries on from where it was,
17
+ * never back, and what was left of each timer and frame runs in real time. `ready` and stillness
18
+ * count an animation held part way as still running.
19
+ *
20
+ * @since 0.3.0
21
+ */
22
+ import type { Duration, Effect } from "effect";
23
+
24
+ import type { BrowserError } from "./BrowserError.ts";
25
+ import type { Point } from "./Geometry.ts";
26
+ import type { Content } from "./Overlay.ts";
27
+ import type { Pose } from "./Pose.ts";
28
+
29
+ /** What else changes with page time in the same call to the page. */
30
+ export interface Step {
31
+ /** Scroll the document to this many CSS pixels down it first, at once. */
32
+ readonly scroll?: number | undefined;
33
+ /** Then pose these elements and take the pose off any other, as `Poses.set` does; the page's poses must be open. */
34
+ readonly poses?: ReadonlyArray<Pose> | undefined;
35
+ /** Then show this in the page's overlay, which must be open. */
36
+ readonly overlay?: Content | undefined;
37
+ }
38
+
39
+ export interface Held {
40
+ /**
41
+ * Move page time on by `by`, in one call to the page, after the actions asked before it. Says
42
+ * where the document is scrolled to after it.
43
+ */
44
+ readonly advance: (by: Duration.Input, step?: Step) => Effect.Effect<Point, BrowserError>;
45
+ /** How far this hold has moved page time, across the documents it held. */
46
+ readonly elapsed: Effect.Effect<Duration.Duration>;
47
+ }
package/src/Pose.ts ADDED
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Element poses: one of the page's own elements moved, turned and scaled about a point, as a caller
3
+ * says, frame by frame on held time or live, so that the page answers what touches it. A tab
4
+ * squashes under a stomp, a box dips as something lands on it, a button tilts as it is pulled, a
5
+ * field wiggles to ask for input. The library chooses no motion: each pose is a caller's.
6
+ *
7
+ * A pose is plain data, in viewport CSS pixels: moved by `dx` and `dy`, scaled by `sx` and `sy`,
8
+ * and turned `rotate` degrees clockwise, each about `origin`, by default the middle of where the
9
+ * page draws the element. As CSS writes it: `transform-origin: origin; transform: translate(dx, dy)
10
+ * rotate(rotate) scale(sx, sy)`, applied around the element's own transform. Its own `translate`,
11
+ * `rotate` and `scale` properties, which pages seldom set, give way while it is posed.
12
+ *
13
+ * A page's poses are one lease, for a scope; each `set` poses the elements it names and takes the
14
+ * pose off every other, and the scope's end takes them all off. A pose sets no attribute and starts
15
+ * none of the page's transitions, and the library's change record does not report it. Readers
16
+ * report what is drawn: `layout`, `find` and the input's targets give a posed element's box as
17
+ * posed, and a click lands where it is drawn. Only HTML elements take a pose, and one inside
18
+ * another posed element is posed about its point as if the outer one were not. A new document
19
+ * starts with none.
20
+ *
21
+ * @since 0.3.0
22
+ */
23
+ import { type Effect, Schema } from "effect";
24
+
25
+ import type { BrowserError } from "./BrowserError.ts";
26
+ import { Point } from "./Geometry.ts";
27
+
28
+ /** How an element is posed. A part left out changes nothing: no move, a scale of 1, no turn. */
29
+ export const Pose = Schema.Struct({
30
+ /** The element, by a ref from the page's current document, such as a `Layout` place's. */
31
+ ref: Schema.String,
32
+ dx: Schema.optional(Schema.Finite),
33
+ dy: Schema.optional(Schema.Finite),
34
+ sx: Schema.optional(Schema.Finite),
35
+ sy: Schema.optional(Schema.Finite),
36
+ /** Degrees, clockwise. */
37
+ rotate: Schema.optional(Schema.Finite),
38
+ /** The point it turns and scales about, in the viewport. */
39
+ origin: Schema.optional(Point),
40
+ });
41
+
42
+ export type Pose = typeof Pose.Type;
43
+
44
+ export interface Poses {
45
+ /**
46
+ * Pose these elements, in one call to the page, and take the pose off every other. A ref the
47
+ * document no longer has fails with `StaleRef`, and posing nothing.
48
+ */
49
+ readonly set: (poses: ReadonlyArray<Pose>) => Effect.Effect<void, BrowserError>;
50
+ }
package/src/Site.ts ADDED
@@ -0,0 +1,124 @@
1
+ /**
2
+ * The library's readers for a site that owns its page, called in the site's own bundle on its own
3
+ * document, with no protocol in it. It is the composition the library installs in a page over the
4
+ * protocol, so a site reads the same refs, subjects, outline, text, layout and changes as an agent
5
+ * does, draws in the same overlay, and poses elements the same way.
6
+ *
7
+ * What needs the protocol stays out:
8
+ *
9
+ * - trusted input and the checks that make it safe;
10
+ * - pictures;
11
+ * - held page time;
12
+ * - a record that starts before the page's own scripts.
13
+ *
14
+ * Instead, the site acts through its own app and `note`s each act, so the changes it brings name it
15
+ * as their cause. Time is real, so a pose or a drawing is set again on each animation frame. The
16
+ * record starts when the site calls `record`.
17
+ *
18
+ * Requests and results are the page script's own plain data. Boxes are in viewport CSS pixels, and
19
+ * a change's times are epoch milliseconds, as `performance.timeOrigin + performance.now()`. A
20
+ * request the page cannot serve answers `{ invalid }`, and a ref it no longer has `{ stale }`,
21
+ * rather than throwing. `Layout`, `Change` and `Snapshot` hold their schemas. The script runs in
22
+ * the site's own world, so it shares the globals the site's code may patch.
23
+ */
24
+ import { compose } from "./internal/page/compose.inpage.ts";
25
+ import { overlay } from "./internal/page/overlay.inpage.ts";
26
+ import { pose, poseRequest } from "./internal/page/pose.inpage.ts";
27
+ import { context } from "./internal/reading/context.inpage.ts";
28
+ import { controls } from "./internal/reading/controls.inpage.ts";
29
+ import { expectations, type Want } from "./internal/reading/expect.inpage.ts";
30
+ import { layout } from "./internal/reading/layout.inpage.ts";
31
+ import { elements, names } from "./internal/reading/names.inpage.ts";
32
+ import { outline } from "./internal/reading/outline.inpage.ts";
33
+ import { ready } from "./internal/reading/ready.inpage.ts";
34
+ import { states, subjects } from "./internal/reading/subjects.inpage.ts";
35
+ import { text } from "./internal/reading/text.inpage.ts";
36
+ import { walk } from "./internal/reading/walk.inpage.ts";
37
+ import { changes } from "./internal/timeline/changes.inpage.ts";
38
+ import { fold } from "./internal/timeline/fold.inpage.ts";
39
+ import { history } from "./internal/timeline/history.inpage.ts";
40
+ import { marks } from "./internal/timeline/marks.inpage.ts";
41
+ import { record } from "./internal/timeline/record.inpage.ts";
42
+ import { sight } from "./internal/timeline/sight.inpage.ts";
43
+ import type { Picks } from "./Layout.ts";
44
+ import { match, pickRequests, request } from "./Matching.ts";
45
+ import type { FindQuery } from "./Page.ts";
46
+ import type { Pose } from "./Pose.ts";
47
+ import { addresses } from "./Url.ts";
48
+
49
+ /**
50
+ * The readers, the change record, the overlay and poses for the current document. Make one for
51
+ * each document the site shows, and `stopRecord` the last one's.
52
+ */
53
+ export const make = () => {
54
+ const { named, recorder, url, reads } = compose({
55
+ elements,
56
+ names,
57
+ walk,
58
+ match,
59
+ context,
60
+ subjects,
61
+ states,
62
+ expectations,
63
+ text,
64
+ layout,
65
+ controls,
66
+ fold,
67
+ history,
68
+ sight,
69
+ marks,
70
+ record,
71
+ changes,
72
+ ready,
73
+ outline,
74
+ overlay,
75
+ pose,
76
+ addresses,
77
+ });
78
+
79
+ const own = overlay(named);
80
+
81
+ return {
82
+ /** What a query finds in the viewport: each element's ref, subject, box and state. */
83
+ find: (query: FindQuery) => reads.find(request(query, "viewport")),
84
+ /** Where each pick is, unrounded, with a box for each of the words it asks for. */
85
+ layout: (picks: Picks) => reads.layout(pickRequests(picks)),
86
+ /** Wait up to `millis` until what a query finds in the document is as wanted. */
87
+ until: (query: FindQuery, want: Want, millis: number) =>
88
+ reads.until(request(query, "document"), want, millis),
89
+ /** The page as an outline of its subjects, each control with a ref. */
90
+ snapshot: reads.snapshot,
91
+ /** The text the viewport shows, or one element's. */
92
+ text: reads.text,
93
+ /** Wait up to `millis` for what the page is still loading, quiet for `quietMillis`. */
94
+ ready: (millis: number, quietMillis?: number) => reads.ready(millis, quietMillis),
95
+ /** One task, then a frame; says whether the page painted. */
96
+ settle: reads.settle,
97
+ /** Record what changes from now, until `stopRecord`, or two minutes with no `changes`. */
98
+ record: reads.record,
99
+ stopRecord: reads.stopRecord,
100
+ /** Keep an act the site did through its app at `target` now, for changes to name as cause. */
101
+ note: recorder.note,
102
+ /** What changed in a window of the record, each change with its box. */
103
+ changes: reads.changes,
104
+ /** Draw an SVG document over the viewport, or take it away with null; says where its parts are. */
105
+ draw: reads.overlay,
106
+ /**
107
+ * A layer of the site's own over the viewport, which no reader reads and the record leaves
108
+ * out: a closed shadow root to render into. It takes no pointer, except parts that set
109
+ * `pointer-events: auto`.
110
+ */
111
+ layer: own.mount,
112
+ /** Pose these elements and take the pose off every other. */
113
+ pose: (poses: ReadonlyArray<Pose>) => reads.pose(poses.map(poseRequest)),
114
+ unpose: reads.unpose,
115
+ /** An element's ref, which `pose` and a read's `ref` take. */
116
+ ref: named.refFor,
117
+ /** The element a ref names, while it is in the document. */
118
+ element: named.lookup,
119
+ /** An address without its userinfo or the parameters known to carry secrets. */
120
+ redact: url.redact,
121
+ };
122
+ };
123
+
124
+ export type Site = ReturnType<typeof make>;
package/src/Style.ts CHANGED
@@ -15,6 +15,7 @@ import {
15
15
  } from "effect";
16
16
 
17
17
  import { undispatched, type BrowserError, InvalidRequest, refuse } from "./BrowserError.ts";
18
+ import type { ActionAnnounced } from "./BrowserEvent.ts";
18
19
  import type * as Motion from "./Geometry.ts";
19
20
  import { normal } from "./Geometry.ts";
20
21
  import * as Keys from "./internal/input/keys.ts";
@@ -43,6 +44,12 @@ export interface Style {
43
44
  readonly failFast: boolean;
44
45
  }) => <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E | BrowserError, R>)
45
46
  | undefined;
47
+ /**
48
+ * Wait for this once an action has announced its target, before its pointer travels there. It
49
+ * holds the page's turn and spends the action's deadline, which bounds it; the target is not
50
+ * found again after it.
51
+ */
52
+ readonly lead?: ((announced: ActionAnnounced) => Effect.Effect<void>) | undefined;
46
53
  /**
47
54
  * Whether viewers watch the input: then the pointer clicks into a field before typing, finds
48
55
  * what lies under it as it scrolls, and scrolls to a target out of view with the wheel.
@@ -262,6 +269,35 @@ const bursts = Effect.fnUntraced(function* (dx: number, dy: number) {
262
269
  return steps;
263
270
  });
264
271
 
272
+ /**
273
+ * A wheel that eases over `durationMillis`: a step each frame, sixty a second, slow at first and
274
+ * last, so a scroll that viewers watch glides to where it goes. A style takes it as its `wheel`;
275
+ * a film scrolls on its own time instead.
276
+ */
277
+ export const eased =
278
+ (durationMillis: number): Style["wheel"] =>
279
+ (dx, dy) => {
280
+ if (!Number.isFinite(durationMillis) || durationMillis < 0)
281
+ return refuse("scroll", "an eased scroll lasts a finite, nonnegative time");
282
+ if (durationMillis > maximumDurationMillis) return Effect.fail(overBudget("scroll"));
283
+ const count = Math.max(1, Math.round((durationMillis * 60) / 1000));
284
+
285
+ // How far along the scroll is at the end of `index` steps, smoothly in and out.
286
+ const along = (index: number) => {
287
+ const x = index / count;
288
+
289
+ return x * x * (3 - 2 * x);
290
+ };
291
+
292
+ return Effect.succeed(
293
+ Array.from({ length: count }, (_, index) => {
294
+ const share = along(index + 1) - along(index);
295
+
296
+ return { dx: dx * share, dy: dy * share, afterMillis: (index * durationMillis) / count };
297
+ }),
298
+ );
299
+ };
300
+
265
301
  /** Input performed for viewers, with this pointer and pace. */
266
302
  export const performed = (options: {
267
303
  readonly pointer: MutableRef.MutableRef<Option.Option<Point>>;