@botiverse/porthole 0.12.0 → 0.14.0

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 (94) hide show
  1. package/dist/annotate/types.d.ts +32 -3
  2. package/dist/annotate/types.js +4 -0
  3. package/dist/annotate/validate.js +19 -2
  4. package/dist/bridge/bridge.d.ts +8 -1
  5. package/dist/bridge/bridge.js +7 -0
  6. package/dist/bridge/unseen.d.ts +8 -0
  7. package/dist/bridge/unseen.js +17 -0
  8. package/dist/check/files.js +14 -10
  9. package/dist/check/lint.js +1 -1
  10. package/dist/check/page-source.js +1 -1
  11. package/dist/check/scroll.d.ts +29 -13
  12. package/dist/check/scroll.js +74 -18
  13. package/dist/compile/policy.d.ts +7 -0
  14. package/dist/compile/policy.js +13 -1
  15. package/dist/config/capabilities.d.ts +16 -3
  16. package/dist/config/capabilities.js +1 -0
  17. package/dist/config/schema.d.ts +11 -0
  18. package/dist/config/validate.js +19 -0
  19. package/dist/conformance/harness-source.js +1 -1
  20. package/dist/displays/displays.js +3 -1
  21. package/dist/guide/limits.js +1 -1
  22. package/dist/guide/runtime.js +1 -1
  23. package/dist/host/create-host.d.ts +2 -0
  24. package/dist/host/create-host.js +100 -3
  25. package/dist/host/pass-on.d.ts +15 -0
  26. package/dist/host/pass-on.js +65 -0
  27. package/dist/host/types.d.ts +37 -0
  28. package/dist/index.d.ts +5 -1
  29. package/dist/index.js +5 -1
  30. package/dist/isolation/types.d.ts +8 -0
  31. package/dist/isolation/types.js +8 -0
  32. package/dist/platform/focus-guard.d.ts +212 -0
  33. package/dist/platform/focus-guard.js +620 -0
  34. package/dist/platform/types.d.ts +25 -0
  35. package/dist/platform/web.js +80 -2
  36. package/dist/presets/presets.d.ts +2 -0
  37. package/dist/presets/presets.js +1 -0
  38. package/dist/react/frame.d.ts +8 -0
  39. package/dist/react/frame.js +4 -0
  40. package/dist/runtime/requests.js +34 -12
  41. package/dist/runtime/types.generated.js +1 -1
  42. package/dist/server/files.js +19 -3
  43. package/dist/server/index.d.ts +1 -0
  44. package/dist/server/index.js +4 -0
  45. package/dist/server/nested.d.ts +37 -0
  46. package/dist/server/nested.js +70 -0
  47. package/dist/server/server.js +57 -7
  48. package/dist/shell/annotate.d.ts +1 -1
  49. package/dist/shell/annotate.js +157 -7
  50. package/dist/shell/frame.d.ts +45 -0
  51. package/dist/shell/frame.js +250 -0
  52. package/dist/shell/plan.js +2 -1
  53. package/dist/shell/runtime.js +49 -14
  54. package/docs/ADOPTING.md +140 -7
  55. package/docs/ARCHITECTURE.md +23 -0
  56. package/docs/DECISIONS.md +564 -5
  57. package/docs/DESIGN.md +18 -2
  58. package/docs/THREAT_MODEL.md +192 -30
  59. package/package.json +1 -1
  60. package/src/annotate/types.ts +28 -3
  61. package/src/annotate/validate.ts +23 -2
  62. package/src/bridge/bridge.ts +17 -1
  63. package/src/bridge/unseen.ts +24 -0
  64. package/src/check/files.ts +14 -10
  65. package/src/check/lint.ts +1 -1
  66. package/src/check/scroll.ts +106 -38
  67. package/src/compile/policy.ts +14 -1
  68. package/src/config/capabilities.ts +16 -3
  69. package/src/config/schema.ts +11 -0
  70. package/src/config/validate.ts +23 -0
  71. package/src/displays/displays.ts +3 -1
  72. package/src/guide/limits.ts +1 -1
  73. package/src/guide/runtime.ts +1 -1
  74. package/src/host/create-host.ts +105 -4
  75. package/src/host/pass-on.ts +73 -0
  76. package/src/host/types.ts +33 -0
  77. package/src/index.ts +5 -1
  78. package/src/isolation/types.ts +12 -0
  79. package/src/platform/focus-guard.ts +815 -0
  80. package/src/platform/types.ts +24 -0
  81. package/src/platform/web.ts +96 -2
  82. package/src/presets/presets.ts +3 -0
  83. package/src/react/frame.tsx +10 -0
  84. package/src/runtime/requests.ts +36 -14
  85. package/src/runtime/types.generated.ts +1 -1
  86. package/src/server/files.ts +19 -3
  87. package/src/server/index.ts +10 -0
  88. package/src/server/nested.ts +86 -0
  89. package/src/server/server.ts +65 -6
  90. package/src/shell/annotate.ts +157 -7
  91. package/src/shell/frame.ts +268 -0
  92. package/src/shell/plan.ts +2 -1
  93. package/src/shell/runtime.ts +49 -14
  94. package/types/runtime/v1/comments.d.ts +8 -4
@@ -0,0 +1,212 @@
1
+ /**
2
+ * The focus guard (P109): a display's frame can move the keyboard into itself whenever it likes
3
+ * (`element.focus()` in its own realm; on Chromium and WebKit with no gesture at all), and what the
4
+ * person goes on typing into the host's composer or chat box then goes to the page. Porthole can't
5
+ * stop the call, which runs in the content's realm, but the host's page can undo it: when focus
6
+ * leaves one of its text fields for a display's frame and the person didn't move it there, focus
7
+ * goes back once the engine has finished moving it, the guard watches that it stays back, and the
8
+ * display hears `focusTaken`; a display whose frame keeps doing it is stopped (`createHost`).
9
+ *
10
+ * What the host's page can see of a move into a frame, measured on Chromium, WebKit and Firefox
11
+ * (P109): Chromium and WebKit blur the host's window as it happens, and a press on the frame (a
12
+ * click, a tap, held or not) leaves the frame element `:active` then; a Tab is the host's own
13
+ * keydown just before. Firefox doesn't blur the window and shows no `:active` (a focusout on the
14
+ * field was seen in one review's runs, not in another's): its `document.activeElement` changes,
15
+ * which the guard reads at each animation frame while a frame is guarded, and the pointer over the
16
+ * frame (`:hover`, `pointerover`) is all it can tell of a press. A page that takes focus back on
17
+ * its own blur (which a take-back fires) leaves Firefox's focus on nothing (`<body>`) or in the
18
+ * frame again (the review of the guard, GK-1): the guard keeps watching after each take-back and
19
+ * counts one that didn't hold. Every engine keeps a gesture's transient activation for 5 s
20
+ * (measured: 5.04 to 5.10 s).
21
+ */
22
+ /** How long the person's Tab counts as moving focus (the move follows its keydown at once). */
23
+ export declare const TAB_MS = 1000;
24
+ /**
25
+ * How long transient activation lasts after a gesture (measured: 5 s on all three engines): a
26
+ * host page with activation and no gesture of its own for longer had one in a frame.
27
+ */
28
+ export declare const ACTIVATION_SPAN_MS = 5000;
29
+ /** The person is typing: a key on the host's page within this long. */
30
+ export declare const TYPING_MS = 1000;
31
+ /**
32
+ * After a take-back, the guard keeps watching (each animation frame) until focus has stayed in the
33
+ * text field this long: a page that takes it again at once (on its own blur, which the take-back
34
+ * fires) is caught as it does, on Firefox too (P109, after the review of the guard: GK-1).
35
+ */
36
+ export declare const HELD_MS = 300;
37
+ /** A take-back that hasn't put focus back in the field after this long failed: counted, and tried again. */
38
+ export declare const GIVE_BACK_MS = 50;
39
+ /**
40
+ * A frame that holds focus isn't the person's for this long after they press the host's page: the
41
+ * press gives the page activation before focus leaves the frame (on Firefox, a move between
42
+ * processes), and a call the frame sends in between would borrow it.
43
+ */
44
+ export declare const HOST_PRESS_MS = 1000;
45
+ /**
46
+ * When a display is stopped for taking the keyboard (P109): focus given back can't stop its frame
47
+ * calling `focus()` again (nothing the host sets on the frame does, `inert` included: measured),
48
+ * and each try leaves it the keys typed until focus is back. So three undone moves within 10 s
49
+ * that came while the person typed on the page or that kept focus from going back (a take-back that
50
+ * failed: the keys then go to the frame, and the page sees no typing to count), or five at all
51
+ * within 2 s, stop it. A person's own move never fails a take-back.
52
+ */
53
+ export declare const TAKES: {
54
+ readonly typing: {
55
+ readonly most: 3;
56
+ readonly withinMs: 10000;
57
+ };
58
+ readonly any: {
59
+ readonly most: 5;
60
+ readonly withinMs: 2000;
61
+ };
62
+ };
63
+ /**
64
+ * A nested page's shell (P111) says its own activation turned on: a press or key of the person's
65
+ * in that page (activation goes up to ancestors, never down, so nothing on the host's page turns
66
+ * it on). A move of focus into the frame within this long of it, with no press or key on the
67
+ * host's page since, is the person's; so is a `comments.open` the page sends within it.
68
+ */
69
+ export declare const SHELL_GESTURE_MS = 1000;
70
+ /**
71
+ * How long a move into a nested page's frame waits for its shell's word before it is taken for
72
+ * the page's: the shell says what it saw at its next animation frame, after the host's page
73
+ * already heard the move. A shell that says nothing in time (gone, stalled) has its frame's move
74
+ * taken back, as any page's.
75
+ */
76
+ export declare const SHELL_WAIT_MS = 500;
77
+ /**
78
+ * A shell's word that came this long before the host's page heard the move is about that move
79
+ * (the shell's frame can come first); one from before then is about an earlier one.
80
+ */
81
+ export declare const SHELL_EARLY_MS = 150;
82
+ /**
83
+ * A shell that went this long without a look, or without a word to the host (its heartbeat is every
84
+ * 50 ms), was stalled (P111, after its review): where the page shares the shell's thread (WebKit,
85
+ * Firefox), a page that holds it from its own click handler pushes the moment the shell sees its
86
+ * activation turn on past the person's next keys on the host's page. An activation it saw then is
87
+ * uncertain: it is no one's gesture until it lapses.
88
+ */
89
+ export declare const SHELL_STALL_MS = 100;
90
+ /** What a nested page's shell last said (P111), on the host's clock. */
91
+ export interface ShellWord {
92
+ /** Whether its engine tells activation at all (`navigator.userActivation`). */
93
+ readonly supported: boolean;
94
+ /** When its activation last turned on; -Infinity if it hasn't, or is off. */
95
+ readonly activatedAt: number;
96
+ /** Whether it last said the page's focus is in it, and when it last said focus came in. */
97
+ readonly focused: boolean;
98
+ readonly focusedAt: number;
99
+ /** Its activation turned on while it was stalled: uncertain until it goes off (`SHELL_STALL_MS`). */
100
+ readonly uncertain?: boolean;
101
+ }
102
+ /** One move of the keyboard the guard undid. */
103
+ export interface FocusTake {
104
+ /** The person pressed a key on the host's page within the last second. */
105
+ readonly typing: boolean;
106
+ /**
107
+ * Focus didn't stay back in the field: the frame kept it, took it again within `HELD_MS`, or it
108
+ * landed nowhere.
109
+ */
110
+ readonly failed: boolean;
111
+ }
112
+ /** What the host's page knew when focus left one of its text fields for a display's frame. */
113
+ export interface FocusMove {
114
+ readonly now: number;
115
+ /** The engine told the host's page as it happened (its window blurred): Chromium, WebKit. */
116
+ readonly seen: boolean;
117
+ /** The frame element is `:active`: a press on it, pointer or touch (Chromium, WebKit). */
118
+ readonly pressed: boolean;
119
+ /** The pointer is over the frame element (`:hover`). */
120
+ readonly over: boolean;
121
+ /** When the pointer last came over the frame element (`pointerover`); -Infinity if never. */
122
+ readonly overSince: number;
123
+ /** The person's last key on the host's page, and when. */
124
+ readonly lastKey: {
125
+ readonly key: string;
126
+ readonly at: number;
127
+ } | null;
128
+ /** When the person last typed on the host's page (a key other than Tab and the modifiers). */
129
+ readonly typedAt: number;
130
+ /** When the text field focus left got it. */
131
+ readonly focusedAt: number;
132
+ /** When the host's page last saw a gesture of its own (a key, a press, a click, typed text). */
133
+ readonly gestureAt: number;
134
+ /** Whether the host's page has transient activation now; undefined where it can't tell. */
135
+ readonly activation: boolean | undefined;
136
+ /** The host moved focus into the frame itself (`DisplayHandle.focus()`), just now. */
137
+ readonly hostMoved: boolean;
138
+ /**
139
+ * A nested page's frame (P111): what its shell said, and when the host's page last had a
140
+ * trusted press or key of its own. Absent for any other frame.
141
+ */
142
+ readonly shell?: {
143
+ readonly word: ShellWord;
144
+ readonly hostInputAt: number;
145
+ };
146
+ }
147
+ /**
148
+ * Whether the person moved focus into the frame themselves:
149
+ * - the host did (`DisplayHandle.focus()`);
150
+ * - by the keyboard: their last key on the host's page was Tab (or Shift+Tab), just now;
151
+ * - by a press on the frame: where the engine tells the move as it happens (Chromium, WebKit),
152
+ * the frame element is `:active`; where it doesn't (Firefox), the pointer is over the frame and
153
+ * came over it after the text field got focus and after the person last typed in the host's page
154
+ * (a page can't move the pointer; a composer that opened beside the frame while the pointer
155
+ * rested over it, and a person typing with it there, keep their keys);
156
+ * - by a gesture the host's own events don't explain: the host's page has transient activation,
157
+ * and for longer than activation lasts it saw no gesture of its own and the text field has had
158
+ * focus, so the person pressed or activated something in a frame since (an assistive
159
+ * technology's activation, which moves no pointer and sends the host no key, is one). The
160
+ * gesture that opened a composer (a selection in the frame, `selected`) is older than the
161
+ * composer's focus, and doesn't count.
162
+ * Anything else is the page's: focus goes back.
163
+ */
164
+ export declare function personMoved(move: FocusMove): boolean;
165
+ /**
166
+ * Whether a nested page's shell saw the person's gesture just now (P111): its activation turned on
167
+ * within `SHELL_GESTURE_MS`, after the host's page's last trusted press or key.
168
+ */
169
+ export declare function shellGesture(word: ShellWord, hostInputAt: number, now: number): boolean;
170
+ /** Whether `element` takes the person's typed text: a text field, a text area, an editable region. */
171
+ export declare function takesText(element: Element | null): element is HTMLElement;
172
+ /** One page's guard, shared by every display's frame on it. */
173
+ export interface FocusGuard {
174
+ /**
175
+ * Guards `frame`: `taken` hears each move into it that was undone. `nested`: it holds a nested
176
+ * page's shell (P111), whose word (`shell`) decides the moves into it.
177
+ */
178
+ add(frame: HTMLIFrameElement, taken: (take: FocusTake) => void, options?: {
179
+ readonly nested?: boolean;
180
+ }): () => void;
181
+ /** What a nested page's shell said (P111): its activation, its focus. */
182
+ shell(frame: HTMLIFrameElement, said: {
183
+ readonly supported: boolean;
184
+ readonly ago: number | null;
185
+ readonly focused: boolean;
186
+ /** How long the shell went without a look before this one (its own clock). */
187
+ readonly gap: number;
188
+ }): void;
189
+ /** A nested page's shell's heartbeat (P111): it is looking. */
190
+ beat(frame: HTMLIFrameElement): void;
191
+ /** Whether a nested page's shell saw the person's gesture just now (`shellGesture`). */
192
+ gesture(frame: HTMLIFrameElement): boolean;
193
+ /** The host moves focus into `frame` itself. */
194
+ focus(frame: HTMLIFrameElement): void;
195
+ /**
196
+ * Whether the page's focus is in `frame` now, the person's own (once any move into it was
197
+ * judged; on an engine that tells the host's page nothing, here and then).
198
+ */
199
+ focused(frame: HTMLIFrameElement): boolean;
200
+ /** The host moves focus into one of its text fields: see `focusField`. */
201
+ field(field: HTMLElement): void;
202
+ }
203
+ /** The guard for `view`'s page, made on first use. */
204
+ export declare function focusGuard(view: Window): FocusGuard;
205
+ /**
206
+ * Moves focus into one of the host page's text fields (a composer that opens beside a display,
207
+ * P109): `field.focus()` for a host to call instead. Firefox doesn't move focus from a frame that
208
+ * holds it with a gesture of the person's and takes it back on its own blur (measured: the keys
209
+ * then go to the frame); this blurs the frame first, and the focus guard watches that focus lands,
210
+ * counting a frame that keeps it toward stopping its display. Elsewhere it is `field.focus()`.
211
+ */
212
+ export declare function focusField(field: HTMLElement): void;