@botiverse/porthole 0.15.2 → 0.16.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 (109) hide show
  1. package/CHANGELOG.md +89 -0
  2. package/dist/bridge/bridge.d.ts +1 -8
  3. package/dist/bridge/bridge.js +0 -7
  4. package/dist/check/page-source.js +1 -1
  5. package/dist/check/page.js +1 -1
  6. package/dist/compile/policy.d.ts +0 -7
  7. package/dist/compile/policy.js +1 -10
  8. package/dist/config/capabilities.d.ts +8 -14
  9. package/dist/config/capabilities.js +4 -5
  10. package/dist/config/schema.d.ts +2 -13
  11. package/dist/config/validate.js +0 -24
  12. package/dist/conformance/behavior.js +26 -37
  13. package/dist/conformance/clipboard.js +47 -1
  14. package/dist/conformance/harness-source.js +1 -1
  15. package/dist/displays/displays.js +1 -3
  16. package/dist/guide/limits.js +1 -1
  17. package/dist/guide/runtime.js +1 -1
  18. package/dist/host/create-host.d.ts +1 -1
  19. package/dist/host/create-host.js +6 -51
  20. package/dist/host/door.d.ts +1 -1
  21. package/dist/host/locate.d.ts +1 -1
  22. package/dist/host/locate.js +2 -2
  23. package/dist/host/outcome.d.ts +5 -12
  24. package/dist/host/outcome.js +8 -16
  25. package/dist/host/types.d.ts +6 -22
  26. package/dist/index.d.ts +2 -4
  27. package/dist/index.js +2 -4
  28. package/dist/isolation/served.d.ts +9 -14
  29. package/dist/isolation/served.js +17 -31
  30. package/dist/isolation/types.d.ts +2 -19
  31. package/dist/isolation/types.js +0 -17
  32. package/dist/platform/focus-field.d.ts +11 -0
  33. package/dist/platform/focus-field.js +18 -0
  34. package/dist/platform/types.d.ts +6 -22
  35. package/dist/platform/web.js +8 -98
  36. package/dist/presets/presets.d.ts +0 -2
  37. package/dist/presets/presets.js +0 -1
  38. package/dist/react/frame.d.ts +0 -8
  39. package/dist/react/frame.js +0 -4
  40. package/dist/runtime/contract.d.ts +2 -2
  41. package/dist/runtime/contract.js +2 -2
  42. package/dist/runtime/types.generated.js +6 -6
  43. package/dist/server/files.js +7 -23
  44. package/dist/server/host.d.ts +1 -1
  45. package/dist/server/index.d.ts +1 -1
  46. package/dist/server/index.js +4 -6
  47. package/dist/server/naming.js +1 -1
  48. package/dist/server/pages.d.ts +9 -2
  49. package/dist/server/pages.js +28 -8
  50. package/dist/server/server.js +28 -166
  51. package/dist/server/types.d.ts +7 -7
  52. package/dist/shell/plan.js +2 -2
  53. package/dist/shell/runtime.js +1 -9
  54. package/docs/ADOPTING.md +42 -135
  55. package/docs/ARCHITECTURE.md +0 -33
  56. package/docs/DECISIONS.md +296 -9
  57. package/docs/DESIGN.md +27 -50
  58. package/docs/THREAT_MODEL.md +140 -242
  59. package/package.json +1 -1
  60. package/src/bridge/bridge.ts +1 -17
  61. package/src/check/page.ts +1 -1
  62. package/src/compile/policy.ts +1 -11
  63. package/src/config/capabilities.ts +8 -14
  64. package/src/config/schema.ts +2 -13
  65. package/src/config/validate.ts +0 -28
  66. package/src/conformance/behavior.ts +50 -52
  67. package/src/conformance/clipboard.ts +56 -1
  68. package/src/displays/displays.ts +1 -3
  69. package/src/guide/limits.ts +1 -1
  70. package/src/guide/runtime.ts +1 -1
  71. package/src/host/create-host.ts +6 -52
  72. package/src/host/door.ts +1 -1
  73. package/src/host/locate.ts +2 -2
  74. package/src/host/outcome.ts +8 -21
  75. package/src/host/types.ts +6 -20
  76. package/src/index.ts +2 -4
  77. package/src/isolation/served.ts +18 -37
  78. package/src/isolation/types.ts +2 -24
  79. package/src/platform/focus-field.ts +18 -0
  80. package/src/platform/types.ts +6 -21
  81. package/src/platform/web.ts +8 -116
  82. package/src/presets/presets.ts +0 -3
  83. package/src/react/frame.tsx +0 -10
  84. package/src/runtime/contract.ts +4 -4
  85. package/src/runtime/types.generated.ts +6 -6
  86. package/src/server/files.ts +4 -19
  87. package/src/server/host.ts +1 -1
  88. package/src/server/index.ts +4 -16
  89. package/src/server/naming.ts +1 -1
  90. package/src/server/pages.ts +38 -12
  91. package/src/server/server.ts +29 -189
  92. package/src/server/types.ts +7 -7
  93. package/src/shell/plan.ts +2 -2
  94. package/src/shell/runtime.ts +1 -9
  95. package/types/runtime/v1/artifact.d.ts +2 -3
  96. package/types/runtime/v1/assets.d.ts +1 -1
  97. package/types/runtime/v1/chat.d.ts +2 -2
  98. package/types/runtime/v1/comments.d.ts +1 -1
  99. package/types/runtime/v1/downloads.d.ts +2 -2
  100. package/types/runtime/v1/links.d.ts +2 -2
  101. package/dist/platform/focus-guard.d.ts +0 -252
  102. package/dist/platform/focus-guard.js +0 -764
  103. package/dist/server/nested.d.ts +0 -66
  104. package/dist/server/nested.js +0 -120
  105. package/dist/shell/frame.d.ts +0 -28
  106. package/dist/shell/frame.js +0 -338
  107. package/src/platform/focus-guard.ts +0 -999
  108. package/src/server/nested.ts +0 -156
  109. package/src/shell/frame.ts +0 -371
@@ -1,252 +0,0 @@
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
- * A nested page's shell (P111) says when its activation turned on, which a press in the page does,
23
- * and so does a key the person typed into it: one meant for the host's composer, after the page took
24
- * the keyboard and before the guard took it back (the audit of P111's guard, NG-1). Neither the
25
- * shell nor the host's page can tell the two apart from the activation (the shell gets no event as
26
- * focus comes into its child, measured), so (P120): in a fight over a text field the shell's word
27
- * isn't asked; a wait on a move from a text field doesn't end with the frame holding focus unjudged;
28
- * and where the host's page sees the pointer over its frames, an activation while it isn't over the
29
- * frame and the person was typing is no press.
30
- */
31
- /** How long the person's Tab counts as moving focus (the move follows its keydown at once). */
32
- export declare const TAB_MS = 1000;
33
- /**
34
- * How long transient activation lasts after a gesture (measured: 5 s on all three engines): a
35
- * host page with activation and no gesture of its own for longer had one in a frame.
36
- */
37
- export declare const ACTIVATION_SPAN_MS = 5000;
38
- /** The person is typing: a key on the host's page within this long. */
39
- export declare const TYPING_MS = 1000;
40
- /**
41
- * No press of the person's lands on a frame this soon after a key they typed on the host's page
42
- * (P122): a hand on the keys doesn't reach the pointer and press that fast (the Keystroke-Level
43
- * Model gives 400 ms to the hand's move from the keys to the mouse alone; Card, Moran and Newell,
44
- * 1980). A move into a nested page's frame, or its shell's activation turning on, within this long
45
- * is the person's next key landing in the page, which turns its activation on as a press does.
46
- * Where neither the host's page nor the shell sees the pointer (full Chromium), it holds a page that
47
- * takes the keyboard while the person types even when their key outruns the shell's answer.
48
- */
49
- export declare const KEY_PRESS_MS = 250;
50
- /**
51
- * After a take-back, the guard keeps watching (each animation frame) until focus has stayed in the
52
- * text field this long: a page that takes it again at once (on its own blur, which the take-back
53
- * fires) is caught as it does, on Firefox too (P109, after the review of the guard: GK-1).
54
- */
55
- export declare const HELD_MS = 300;
56
- /** A take-back that hasn't put focus back in the field after this long failed: counted, and tried again. */
57
- export declare const GIVE_BACK_MS = 50;
58
- /**
59
- * A frame that holds focus isn't the person's for this long after they press the host's page: the
60
- * press gives the page activation before focus leaves the frame (on Firefox, a move between
61
- * processes), and a call the frame sends in between would borrow it.
62
- */
63
- export declare const HOST_PRESS_MS = 1000;
64
- /**
65
- * When a display is stopped for taking the keyboard (P109): focus given back can't stop its frame
66
- * calling `focus()` again (nothing the host sets on the frame does, `inert` included: measured),
67
- * and each try leaves it the keys typed until focus is back. So three undone moves within 10 s
68
- * that came while the person typed on the page or that kept focus from going back (a take-back that
69
- * failed: the keys then go to the frame, and the page sees no typing to count), or five at all
70
- * within 2 s, stop it. A person's own move never fails a take-back.
71
- */
72
- export declare const TAKES: {
73
- readonly typing: {
74
- readonly most: 3;
75
- readonly withinMs: 10000;
76
- };
77
- readonly any: {
78
- readonly most: 5;
79
- readonly withinMs: 2000;
80
- };
81
- };
82
- /**
83
- * A nested page's shell (P111) says its own activation turned on: a press or key of the person's
84
- * in that page (activation goes up to ancestors, never down, so nothing on the host's page turns
85
- * it on). A move of focus into the frame within this long of it, with no press or key on the
86
- * host's page since, is the person's; so is a `comments.open` the page sends within it.
87
- */
88
- export declare const SHELL_GESTURE_MS = 1000;
89
- /**
90
- * How long a move into a nested page's frame waits for its shell's word before it is taken for
91
- * the page's: the shell says what it saw at its next animation frame, after the host's page
92
- * already heard the move. A shell that says nothing in time (gone, stalled) has its frame's move
93
- * taken back, as any page's.
94
- */
95
- export declare const SHELL_WAIT_MS = 500;
96
- /**
97
- * A shell's word that came this long before the host's page heard the move is about that move
98
- * (the shell's frame can come first); one from before then is about an earlier one.
99
- */
100
- export declare const SHELL_EARLY_MS = 150;
101
- /**
102
- * A shell that went this long without a look, or without a word to the host (its heartbeat is every
103
- * 50 ms), was stalled (P111, after its review): where the page shares the shell's thread (WebKit,
104
- * Firefox), a page that holds it from its own click handler pushes the moment the shell sees its
105
- * activation turn on past the person's next keys on the host's page. An activation it saw then is
106
- * uncertain: it is no one's gesture until it lapses.
107
- */
108
- export declare const SHELL_STALL_MS = 100;
109
- /** What a nested page's shell last said (P111), on the host's clock. */
110
- export interface ShellWord {
111
- /** Whether its engine tells activation at all (`navigator.userActivation`). */
112
- readonly supported: boolean;
113
- /** When its activation last turned on; -Infinity if it hasn't, or is off. */
114
- readonly activatedAt: number;
115
- /** Whether it last said the page's focus is in it, and when it last said focus came in. */
116
- readonly focused: boolean;
117
- readonly focusedAt: number;
118
- /** Its activation turned on while it was stalled: uncertain until it goes off (`SHELL_STALL_MS`). */
119
- readonly uncertain?: boolean;
120
- /**
121
- * Its activation turned on within `TYPING_MS` of the person's typing on the host's page, the
122
- * pointer not come over the frame since (`pressPossible`, judged as it turned on): where the
123
- * host's page sees the pointer, their key landing in the page, no press (P120).
124
- */
125
- readonly keyed?: boolean;
126
- }
127
- /** One move of the keyboard the guard undid. */
128
- export interface FocusTake {
129
- /** The person pressed a key on the host's page within the last second. */
130
- readonly typing: boolean;
131
- /**
132
- * Focus didn't stay back in the field: the frame kept it, took it again within `HELD_MS`, or it
133
- * landed nowhere.
134
- */
135
- readonly failed: boolean;
136
- }
137
- /** What the host's page knew when focus left one of its text fields for a display's frame. */
138
- export interface FocusMove {
139
- readonly now: number;
140
- /** The engine told the host's page as it happened (its window blurred): Chromium, WebKit. */
141
- readonly seen: boolean;
142
- /** The frame element is `:active`: a press on it, pointer or touch (Chromium, WebKit). */
143
- readonly pressed: boolean;
144
- /** The pointer is over the frame element (`:hover`). */
145
- readonly over: boolean;
146
- /** When the pointer last came over the frame element (`pointerover`); -Infinity if never. */
147
- readonly overSince: number;
148
- /** The person's last key on the host's page, and when. */
149
- readonly lastKey: {
150
- readonly key: string;
151
- readonly at: number;
152
- } | null;
153
- /** When the person last typed on the host's page (a key other than Tab and the modifiers). */
154
- readonly typedAt: number;
155
- /** When the text field focus left got it. */
156
- readonly focusedAt: number;
157
- /** When the host's page last saw a gesture of its own (a key, a press, a click, typed text). */
158
- readonly gestureAt: number;
159
- /** Whether the host's page has transient activation now; undefined where it can't tell. */
160
- readonly activation: boolean | undefined;
161
- /** The host moved focus into the frame itself (`DisplayHandle.focus()`), just now. */
162
- readonly hostMoved: boolean;
163
- /**
164
- * A nested page's frame (P111): what its shell said, and when the host's page last had a
165
- * trusted press or key of its own. Absent for any other frame.
166
- */
167
- readonly shell?: {
168
- readonly word: ShellWord;
169
- readonly hostInputAt: number;
170
- /** The host's page sees the pointer over its frames on this engine (`pressPossible`, P120). */
171
- readonly pointerShown?: boolean;
172
- };
173
- }
174
- /**
175
- * Whether the person moved focus into the frame themselves:
176
- * - the host did (`DisplayHandle.focus()`);
177
- * - by the keyboard: their last key on the host's page was Tab (or Shift+Tab), just now;
178
- * - by a press on the frame: where the engine tells the move as it happens (Chromium, WebKit),
179
- * the frame element is `:active`; where it doesn't (Firefox), the pointer is over the frame and
180
- * came over it after the text field got focus and after the person last typed in the host's page
181
- * (a page can't move the pointer; a composer that opened beside the frame while the pointer
182
- * rested over it, and a person typing with it there, keep their keys);
183
- * - by a gesture the host's own events don't explain: the host's page has transient activation,
184
- * and for longer than activation lasts it saw no gesture of its own and the text field has had
185
- * focus, so the person pressed or activated something in a frame since (an assistive
186
- * technology's activation, which moves no pointer and sends the host no key, is one). The
187
- * gesture that opened a composer (a selection in the frame, `selected`) is older than the
188
- * composer's focus, and doesn't count.
189
- * Anything else is the page's: focus goes back.
190
- */
191
- export declare function personMoved(move: FocusMove): boolean;
192
- /**
193
- * Whether a nested page's shell saw the person's gesture just now (P111): its activation turned on
194
- * within `SHELL_GESTURE_MS`, after the host's page's last trusted press or key.
195
- */
196
- export declare function shellGesture(word: ShellWord, hostInputAt: number, now: number): boolean;
197
- /**
198
- * Whether the person could have pressed the frame just before `at` (P120): a nested page's shell
199
- * says its activation turned on, which a key typed into the page does as well as a press. Where the
200
- * host's page sees the pointer over its frames (`shown`: Firefox; Chromium and WebKit where the frame
201
- * is in their process, not full Chromium), a press needs the pointer over the frame, come over it
202
- * since the person last typed on the host's page; within `TYPING_MS` of that typing, an activation
203
- * with the pointer elsewhere is their keys landing in the page. Anywhere else it may be a press.
204
- */
205
- export declare function pressPossible(shown: boolean, over: boolean, overSince: number, typedAt: number, at: number): boolean;
206
- /** Whether `element` takes the person's typed text: a text field, a text area, an editable region. */
207
- export declare function takesText(element: Element | null): element is HTMLElement;
208
- /** One page's guard, shared by every display's frame on it. */
209
- export interface FocusGuard {
210
- /**
211
- * Guards `frame`: `taken` hears each move into it that was undone. `nested`: it holds a nested
212
- * page's shell (P111), whose word (`shell`) decides the moves into it.
213
- */
214
- add(frame: HTMLIFrameElement, taken: (take: FocusTake) => void, options?: {
215
- readonly nested?: boolean;
216
- /** Asks a nested page's shell to look now (P120); it answers with a report naming `n`. */
217
- readonly ask?: (n: number) => void;
218
- }): () => void;
219
- /** What a nested page's shell said (P111): its activation, its focus. */
220
- shell(frame: HTMLIFrameElement, said: {
221
- readonly supported: boolean;
222
- readonly ago: number | null;
223
- readonly focused: boolean;
224
- /** How long the shell went without a look before this one (its own clock). */
225
- readonly gap: number;
226
- /** The ask this report answers (P120), if it answers one. */
227
- readonly asked?: number;
228
- }): void;
229
- /** A nested page's shell's heartbeat (P111): it is looking. */
230
- beat(frame: HTMLIFrameElement): void;
231
- /** Whether a nested page's shell saw the person's gesture just now (`shellGesture`). */
232
- gesture(frame: HTMLIFrameElement): boolean;
233
- /** The host moves focus into `frame` itself. */
234
- focus(frame: HTMLIFrameElement): void;
235
- /**
236
- * Whether the page's focus is in `frame` now, the person's own (once any move into it was
237
- * judged; on an engine that tells the host's page nothing, here and then).
238
- */
239
- focused(frame: HTMLIFrameElement): boolean;
240
- /** The host moves focus into one of its text fields: see `focusField`. */
241
- field(field: HTMLElement): void;
242
- }
243
- /** The guard for `view`'s page, made on first use. */
244
- export declare function focusGuard(view: Window): FocusGuard;
245
- /**
246
- * Moves focus into one of the host page's text fields (a composer that opens beside a display,
247
- * P109): `field.focus()` for a host to call instead. Firefox doesn't move focus from a frame that
248
- * holds it with a gesture of the person's and takes it back on its own blur (measured: the keys
249
- * then go to the frame); this blurs the frame first, and the focus guard watches that focus lands,
250
- * counting a frame that keeps it toward stopping its display. Elsewhere it is `field.focus()`.
251
- */
252
- export declare function focusField(field: HTMLElement): void;