@botiverse/porthole 0.14.13 → 0.14.15
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/CHANGELOG.md +63 -2
- package/dist/annotate/types.d.ts +47 -4
- package/dist/annotate/types.js +7 -1
- package/dist/annotate/validate.d.ts +17 -1
- package/dist/annotate/validate.js +74 -4
- package/dist/check/page-source.js +1 -1
- package/dist/conformance/harness-source.js +1 -1
- package/dist/host/create-host.js +52 -4
- package/dist/host/types.d.ts +21 -6
- package/dist/index.d.ts +1 -1
- package/dist/isolation/types.d.ts +6 -0
- package/dist/isolation/types.js +6 -0
- package/dist/platform/web.js +6 -1
- package/dist/react/frame.d.ts +13 -1
- package/dist/react/frame.js +37 -24
- package/dist/shell/annotate.d.ts +18 -4
- package/dist/shell/annotate.js +193 -22
- package/dist/shell/frame.d.ts +6 -1
- package/dist/shell/frame.js +45 -5
- package/docs/ADOPTING.md +69 -15
- package/docs/ARCHITECTURE.md +1 -0
- package/docs/DECISIONS.md +500 -18
- package/docs/DESIGN.md +44 -12
- package/docs/THREAT_MODEL.md +48 -22
- package/package.json +1 -1
- package/src/annotate/types.ts +44 -4
- package/src/annotate/validate.ts +90 -4
- package/src/host/create-host.ts +53 -3
- package/src/host/types.ts +26 -6
- package/src/index.ts +1 -0
- package/src/isolation/types.ts +7 -0
- package/src/platform/web.ts +6 -0
- package/src/react/frame.tsx +59 -31
- package/src/shell/annotate.ts +194 -22
- package/src/shell/frame.ts +45 -5
package/src/shell/annotate.ts
CHANGED
|
@@ -57,6 +57,23 @@ export const MARKER_NAME = String.raw`(mark) => {
|
|
|
57
57
|
return words === "" ? what : what + ' on "' + words + '"';
|
|
58
58
|
}`;
|
|
59
59
|
|
|
60
|
+
/**
|
|
61
|
+
* Whether a host's `focusMark` is too old to land unasked (P137): `at` is the host's `Date.now()` as
|
|
62
|
+
* it sent the word, `now` the shell's, kept before content runs. Both read the one wall clock of
|
|
63
|
+
* this machine, the only clock two realms share (`performance.now()` counts from each one's own
|
|
64
|
+
* start). No number is an older host's word, which can't be known fresh. A word from ahead of the
|
|
65
|
+
* clock has the same bound behind it: two processes can read the clock a little apart, and past
|
|
66
|
+
* that the clock was set back, and the age says nothing. Comparisons only, nothing a page can
|
|
67
|
+
* patch, and a word that makes no number (`NaN`, `Infinity`) passes neither test.
|
|
68
|
+
*/
|
|
69
|
+
export const WORD_LATE = String.raw`(at, now) => {
|
|
70
|
+
if (typeof at !== "number") {
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
const age = now - at;
|
|
74
|
+
return !(age > -100 && age < 100);
|
|
75
|
+
}`;
|
|
76
|
+
|
|
60
77
|
/**
|
|
61
78
|
* The shell's annotation runtime (P053), spliced into the shell's runtime (`__ANNOTATE__`) when
|
|
62
79
|
* the config declares `annotate`, so it runs before any content does, with the DOM's own
|
|
@@ -64,7 +81,7 @@ export const MARKER_NAME = String.raw`(mark) => {
|
|
|
64
81
|
* in one).
|
|
65
82
|
*
|
|
66
83
|
* The host drives it (`porthole/annotate.start|stop|show|focus|clear|track|clearSelection|focusMark`)
|
|
67
|
-
* and it reports (`porthole/annotate.selected|unselected|cancelled|anchored|activated|tracked`):
|
|
84
|
+
* and it reports (`porthole/annotate.selected|unselected|cancelled|anchored|activated|tracked|selectionTracked`):
|
|
68
85
|
* - picking an element: the element under the pointer (or finger) is outlined with its name; a
|
|
69
86
|
* click or tap picks it, and the content's own handlers never see that click (unless the content
|
|
70
87
|
* patched the DOM's built-ins, P105); Escape cancels (while selecting text too, P112);
|
|
@@ -80,8 +97,8 @@ export const MARKER_NAME = String.raw`(mark) => {
|
|
|
80
97
|
* focus on it (P133), is reported (`activated`), and the content's own handlers never see it; a
|
|
81
98
|
* draft is drawn apart, a dashed line and a hollow bubble with no number, and has a marker with
|
|
82
99
|
* or without a count; the host's `focusMark` (P134) puts the focus on a marker that is there, and
|
|
83
|
-
* tells nothing back; one that had to wait for the marks
|
|
84
|
-
* document
|
|
100
|
+
* tells nothing back; one that had to wait for the marks (P135), or that this document took late
|
|
101
|
+
* (P137), lands only if the focus is in this document by then;
|
|
85
102
|
* - following: while a mark has a marker, once a scroll, a resize or a change of the content
|
|
86
103
|
* settles, the marks that moved since the host was last told are reported, at most once a
|
|
87
104
|
* second, so the host's own UI beside a mark can follow;
|
|
@@ -90,7 +107,11 @@ export const MARKER_NAME = String.raw`(mark) => {
|
|
|
90
107
|
* followed mark's (`tracked`) too, so a host places marks scrolled out of the frame, and keeps
|
|
91
108
|
* them placed as the document scrolls, from one report and the followed mark's scroll;
|
|
92
109
|
* - the last line (P133): where a selection or a mark's words end, in the document's coordinates
|
|
93
|
-
* too (`lastLineDocumentRect`), so a host places its UI after them
|
|
110
|
+
* too (`lastLineDocumentRect`), so a host places its UI after them;
|
|
111
|
+
* - the selection followed (P138): what the last `selected` reported (the element picked, or the
|
|
112
|
+
* words selected) is kept, and while the host follows it (`track` with `selection`) it is drawn
|
|
113
|
+
* in the layer and its boxes are reported as a followed mark's are (`selectionTracked`), with
|
|
114
|
+
* whether it is in view, or that it is gone; it takes no pointer, no focus and no key.
|
|
94
115
|
*
|
|
95
116
|
* It shares the realm with the content, which can interfere with all of it: the host takes its
|
|
96
117
|
* reports as UI hints only.
|
|
@@ -111,6 +132,7 @@ export const ANNOTATE_RUNTIME = String.raw`if (declared("annotate")) {
|
|
|
111
132
|
activated: "porthole/annotate.activated",
|
|
112
133
|
track: "porthole/annotate.track",
|
|
113
134
|
tracked: "porthole/annotate.tracked",
|
|
135
|
+
selectionTracked: "porthole/annotate.selectionTracked",
|
|
114
136
|
clearSelection: "porthole/annotate.clearSelection",
|
|
115
137
|
focusMark: "porthole/annotate.focusMark",
|
|
116
138
|
};
|
|
@@ -125,9 +147,11 @@ export const ANNOTATE_RUNTIME = String.raw`if (declared("annotate")) {
|
|
|
125
147
|
const removeAllRanges = Selection.prototype.removeAllRanges;
|
|
126
148
|
const focusElement = HTMLElement.prototype.focus;
|
|
127
149
|
const hasFocus = Document.prototype.hasFocus;
|
|
150
|
+
const wallClock = Date.now;
|
|
128
151
|
const elementRect = Element.prototype.getBoundingClientRect;
|
|
129
152
|
const rangeRect = Range.prototype.getBoundingClientRect;
|
|
130
153
|
const rangeRects = Range.prototype.getClientRects;
|
|
154
|
+
const cloneRange = Range.prototype.cloneRange;
|
|
131
155
|
const setStart = Range.prototype.setStart;
|
|
132
156
|
const setStartBefore = Range.prototype.setStartBefore;
|
|
133
157
|
const compareBoundaryPoints = Range.prototype.compareBoundaryPoints;
|
|
@@ -384,7 +408,10 @@ export const ANNOTATE_RUNTIME = String.raw`if (declared("annotate")) {
|
|
|
384
408
|
// box of at least 44 by 44 px centred on its own (an invisible ::before; 100% is its padding
|
|
385
409
|
// box, its border 1 px), so a tap a few px off still lands on the shell's layer. A marker is
|
|
386
410
|
// a real button (P133): what a browser gives one is taken off, a ring says it has the focus.
|
|
387
|
-
|
|
411
|
+
// The selection the host follows (P138) is drawn as what is picked is: an element in the
|
|
412
|
+
// picking outline, a little lighter and without its name; words with a light fill and a line
|
|
413
|
+
// under them, in the same blue, apart from the marks' yellow (no comment is there yet).
|
|
414
|
+
const STYLE = ".mark{position:absolute;border-radius:2px;background:rgba(250,204,21,.18);box-shadow:inset 0 -2px 0 rgba(234,179,8,.95)}.mark.element{background:rgba(250,204,21,.07);box-shadow:none;outline:2px solid rgba(234,179,8,.9);outline-offset:1px}.mark.active{background:rgba(250,204,21,.26);box-shadow:inset 0 -3px 0 rgb(234,179,8),0 0 0 2px rgba(234,179,8,.45)}.mark.element.active{background:rgba(250,204,21,.12);box-shadow:none;outline-width:3px}.mark.element.quiet{background:rgba(250,204,21,.05);outline:1px solid rgba(234,179,8,.6);outline-offset:2px}.mark.element.quiet.active{background:rgba(250,204,21,.1);outline:2px solid rgba(234,179,8,.9)}.mark.draft{box-sizing:border-box;background:rgba(250,204,21,.08);box-shadow:none;border-bottom:2px dashed rgba(202,138,4,.95)}.mark.draft.active{background:rgba(250,204,21,.16);box-shadow:0 0 0 2px rgba(234,179,8,.45);border-bottom-width:3px}.mark.element.draft{background:rgba(250,204,21,.04);border-bottom:0;outline-style:dashed}.mark.element.draft.active{background:rgba(250,204,21,.08);box-shadow:none;outline-style:dashed}.marker{position:absolute;box-sizing:border-box;height:18px;min-width:18px;display:flex;align-items:center;justify-content:center;gap:3px;margin:0;padding:0 5px;border:1px solid rgba(161,98,7,.6);border-radius:9px 9px 9px 2px;background:#fde68a;color:#422006;box-shadow:0 1px 2px rgba(0,0,0,.3);font:600 11px/16px system-ui,-apple-system,Segoe UI,Roboto,sans-serif;font-style:normal;letter-spacing:0;word-spacing:0;text-transform:none;text-indent:0;text-shadow:none;direction:ltr;writing-mode:horizontal-tb;white-space:nowrap;user-select:none;-webkit-user-select:none;cursor:pointer;pointer-events:auto;appearance:none;-webkit-appearance:none}.marker:focus-visible{outline:2px solid #2563eb;outline-offset:1px}.marker:hover{background:#fcd34d}.marker.active{background:#facc15;box-shadow:0 0 0 2px rgba(234,179,8,.55),0 1px 2px rgba(0,0,0,.3)}.marker.compact{padding:0 4px}.marker.draft{border:1px dashed rgb(202,138,4);background:#fffdf5;color:#a16207;box-shadow:0 1px 2px rgba(0,0,0,.2)}.marker.draft:hover{background:#fef9e7}.marker.draft.active{background:#fef3c7;box-shadow:0 0 0 2px rgba(234,179,8,.55),0 1px 2px rgba(0,0,0,.2)}.marker.inert,[data-placing]>.marker{pointer-events:none}.touch>.marker::before{content:'';position:absolute;left:50%;top:50%;width:max(100% + 2px,44px);height:max(100% + 2px,44px);transform:translate(-50%,-50%)}.marker svg{display:block;width:11px;height:11px;flex:none}.mark.flash{animation:flash 1.8s ease-out}@keyframes flash{from{box-shadow:inset 0 -3px 0 rgb(234,179,8),0 0 0 6px rgba(250,204,21,.6)}}.hover{position:absolute;outline:2px solid #2563eb;outline-offset:1px;background:rgba(37,99,235,.12)}.held{position:absolute;outline:2px solid #2563eb;outline-offset:1px;background:rgba(37,99,235,.06)}.held.text{outline:0;border-radius:2px;background:rgba(37,99,235,.12);box-shadow:inset 0 -2px 0 #2563eb}.tag{position:absolute;max-width:70vw;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font:12px/18px ui-monospace,SFMono-Regular,Menlo,monospace;padding:0 6px;border-radius:4px;background:#1e293b;color:#fff}";
|
|
388
415
|
// Inline and important: the content's own style sheets can't hide, shrink or move it by
|
|
389
416
|
// accident. Set again at each draw, since its scripts can rewrite it (narrowing only: the
|
|
390
417
|
// content can still cover the layer, or move it with its ancestors, P104). Clipped, where an
|
|
@@ -410,6 +437,31 @@ export const ANNOTATE_RUNTIME = String.raw`if (declared("annotate")) {
|
|
|
410
437
|
|
|
411
438
|
let mode = { elements: false, text: false, hold: false };
|
|
412
439
|
let hover = null;
|
|
440
|
+
// The selection last reported as selected (P138): its anchor, and what it is in the page (the
|
|
441
|
+
// element picked, or a copy of the selection's range, which the page's changes keep up to
|
|
442
|
+
// date and which stays when the page's own selection goes). Followed while the host asks
|
|
443
|
+
// (track with selection), and drawn then. Each new selected replaces it.
|
|
444
|
+
let held = null;
|
|
445
|
+
let followingSelection = false;
|
|
446
|
+
// What the host was last told of it: "attached", "orphaned", or null (nothing yet).
|
|
447
|
+
let heldTold = null;
|
|
448
|
+
const heldGone = (found) => (found.range ? found.range.collapsed || !found.range.startContainer.isConnected : !found.element.isConnected);
|
|
449
|
+
const heldShown = () => followingSelection && held !== null && heldTold !== "orphaned" && !heldGone(held.found);
|
|
450
|
+
// The element just picked (P138, Tenny's review): it keeps its outline after selected, so
|
|
451
|
+
// there is no gap before the host follows it, and the follow's highlight takes over where it
|
|
452
|
+
// does. Without a follow (an older host) it ends as a selection does: the next pick or
|
|
453
|
+
// selection, the host's clearSelection, a mode started or stopped, clear, Escape, or the
|
|
454
|
+
// element leaving the page. Not unselected: a selection made after the pick has already
|
|
455
|
+
// ended it as it was reported, so the one unselected can clear is one from before, which
|
|
456
|
+
// the pick's own click takes away when text is selected too.
|
|
457
|
+
let picked = null;
|
|
458
|
+
const endPick = () => {
|
|
459
|
+
if (picked !== null) {
|
|
460
|
+
picked = null;
|
|
461
|
+
redraw();
|
|
462
|
+
}
|
|
463
|
+
};
|
|
464
|
+
const pickShown = () => picked !== null && !followingSelection && picked.isConnected;
|
|
413
465
|
let marks = [];
|
|
414
466
|
// The markers as last drawn, for a click to find: { id, element }. Each mark keeps its
|
|
415
467
|
// marker's node across draws, so a press that spans a redraw ends on the node it began on.
|
|
@@ -800,7 +852,7 @@ export const ANNOTATE_RUNTIME = String.raw`if (declared("annotate")) {
|
|
|
800
852
|
return boxes;
|
|
801
853
|
};
|
|
802
854
|
const draw = () => {
|
|
803
|
-
if (marks.length === 0 && hover === null && layer === null) {
|
|
855
|
+
if (marks.length === 0 && hover === null && layer === null && !heldShown() && !pickShown()) {
|
|
804
856
|
return;
|
|
805
857
|
}
|
|
806
858
|
const root = ensureLayer();
|
|
@@ -895,6 +947,24 @@ export const ANNOTATE_RUNTIME = String.raw`if (declared("annotate")) {
|
|
|
895
947
|
}
|
|
896
948
|
}
|
|
897
949
|
const outlines = [];
|
|
950
|
+
// The followed selection (P138), under the picking outline: no pointer, no focus, no name;
|
|
951
|
+
// before the host follows it, the element just picked, drawn the same way.
|
|
952
|
+
if (picked !== null && !picked.isConnected) {
|
|
953
|
+
picked = null;
|
|
954
|
+
}
|
|
955
|
+
const lit = heldShown() ? held.found : pickShown() ? { element: picked } : null;
|
|
956
|
+
if (lit !== null) {
|
|
957
|
+
const rects = lit.range ? Array.from(rangeRects.call(lit.range)).slice(0, LIMIT.boxes) : [elementRect.call(lit.element)];
|
|
958
|
+
for (const rect of rects) {
|
|
959
|
+
if (rect.width === 0 && rect.height === 0) {
|
|
960
|
+
continue;
|
|
961
|
+
}
|
|
962
|
+
const each = createElement.call(document, "div");
|
|
963
|
+
each.className = lit.range ? "held text" : "held";
|
|
964
|
+
each.style.cssText = "left:" + rect.left + "px;top:" + rect.top + "px;width:" + rect.width + "px;height:" + rect.height + "px";
|
|
965
|
+
outlines.push(each);
|
|
966
|
+
}
|
|
967
|
+
}
|
|
898
968
|
if (hover !== null && hover.isConnected) {
|
|
899
969
|
const rect = elementRect.call(hover);
|
|
900
970
|
const outline = createElement.call(document, "div");
|
|
@@ -940,9 +1010,17 @@ export const ANNOTATE_RUNTIME = String.raw`if (declared("annotate")) {
|
|
|
940
1010
|
let trackedBox = null;
|
|
941
1011
|
let trackedAt = 0;
|
|
942
1012
|
let trackFrame = 0;
|
|
1013
|
+
// The followed selection's viewport as last told (P138): a frame made smaller can leave it
|
|
1014
|
+
// out of view without moving it.
|
|
1015
|
+
let trackedView = null;
|
|
943
1016
|
const trackTick = () => {
|
|
944
1017
|
trackFrame = 0;
|
|
945
|
-
if (tracking === null) {
|
|
1018
|
+
if (tracking === null && !followingSelection) {
|
|
1019
|
+
return;
|
|
1020
|
+
}
|
|
1021
|
+
if (followingSelection) {
|
|
1022
|
+
followHeld();
|
|
1023
|
+
trackFrame = nextFrame(trackTick);
|
|
946
1024
|
return;
|
|
947
1025
|
}
|
|
948
1026
|
const mark = marks.find((each) => each.id === tracking);
|
|
@@ -961,12 +1039,79 @@ export const ANNOTATE_RUNTIME = String.raw`if (declared("annotate")) {
|
|
|
961
1039
|
}
|
|
962
1040
|
trackFrame = nextFrame(trackTick);
|
|
963
1041
|
};
|
|
964
|
-
|
|
1042
|
+
// The followed selection (P138), as a followed mark is, and on its clock: where it is at each
|
|
1043
|
+
// animation frame where it moved, or the viewport changed size, with whether any of it is in
|
|
1044
|
+
// the viewport; orphaned once while it isn't in the page (a page that took the element out,
|
|
1045
|
+
// a re-render, the words gone), found again by its anchor at most twice a second meanwhile.
|
|
1046
|
+
// Geometry only: its anchor and words went with selected. Reads boxes, nothing else: no
|
|
1047
|
+
// focus, no selection, no listener.
|
|
1048
|
+
const followHeld = () => {
|
|
1049
|
+
const now = performance.now();
|
|
1050
|
+
if (held !== null && heldGone(held.found) && now - held.tried >= 500) {
|
|
1051
|
+
held.tried = now;
|
|
1052
|
+
let found = null;
|
|
1053
|
+
try {
|
|
1054
|
+
found = find(held.anchor, textIndex());
|
|
1055
|
+
} catch (_) {
|
|
1056
|
+
found = null;
|
|
1057
|
+
}
|
|
1058
|
+
if (found !== null && !heldGone(found)) {
|
|
1059
|
+
held.found = found;
|
|
1060
|
+
}
|
|
1061
|
+
}
|
|
1062
|
+
if (held === null || heldGone(held.found)) {
|
|
1063
|
+
if (heldTold !== "orphaned") {
|
|
1064
|
+
heldTold = "orphaned";
|
|
1065
|
+
trackedBox = null;
|
|
1066
|
+
tell(M.selectionTracked, { state: "orphaned" });
|
|
1067
|
+
redraw();
|
|
1068
|
+
}
|
|
1069
|
+
return;
|
|
1070
|
+
}
|
|
1071
|
+
const rect = box(rectOf(held.found));
|
|
1072
|
+
const root = document.documentElement;
|
|
1073
|
+
const view = { width: root ? root.clientWidth : 0, height: root ? root.clientHeight : 0 };
|
|
1074
|
+
const resized = trackedView === null || trackedView.width !== view.width || trackedView.height !== view.height;
|
|
1075
|
+
if ((heldTold !== "attached" || resized || apart(trackedBox, rect)) && now - trackedAt >= 16) {
|
|
1076
|
+
heldTold = "attached";
|
|
1077
|
+
trackedBox = rect;
|
|
1078
|
+
trackedView = view;
|
|
1079
|
+
trackedAt = now;
|
|
1080
|
+
const scroll = scrollOf();
|
|
1081
|
+
const lastLineDocumentRect = lastLineOf(held.found, scroll);
|
|
1082
|
+
const inView = rect.x < view.width && rect.x + rect.width > 0 && rect.y < view.height && rect.y + rect.height > 0;
|
|
1083
|
+
tell(M.selectionTracked, Object.assign({ state: "attached", rect, documentRect: inDocument(rect, scroll), scroll, inView }, lastLineDocumentRect === null ? {} : { lastLineDocumentRect }));
|
|
1084
|
+
// The highlight goes with it (a layout change moves it without a scroll).
|
|
1085
|
+
redraw();
|
|
1086
|
+
}
|
|
1087
|
+
};
|
|
1088
|
+
// A mark, the selection (P138), or nothing: one at a time, each replacing the last.
|
|
1089
|
+
const track = (id, selection) => {
|
|
1090
|
+
const was = heldShown() || pickShown();
|
|
965
1091
|
tracking = typeof id === "string" ? id : null;
|
|
1092
|
+
followingSelection = tracking === null && selection === true;
|
|
1093
|
+
// The follow's highlight takes the pick's outline over, in this draw (Tenny's review).
|
|
1094
|
+
if (followingSelection) {
|
|
1095
|
+
picked = null;
|
|
1096
|
+
}
|
|
966
1097
|
trackedBox = null;
|
|
967
|
-
|
|
1098
|
+
trackedView = null;
|
|
1099
|
+
heldTold = null;
|
|
1100
|
+
if ((tracking !== null || followingSelection) && trackFrame === 0) {
|
|
968
1101
|
trackFrame = nextFrame(trackTick);
|
|
969
1102
|
}
|
|
1103
|
+
if (heldShown() || pickShown() || was) {
|
|
1104
|
+
draw();
|
|
1105
|
+
}
|
|
1106
|
+
};
|
|
1107
|
+
// A new selected (P138): what is followed, if the selection is, from the next frame on.
|
|
1108
|
+
const holdSelected = (anchor, found) => {
|
|
1109
|
+
held = { anchor, found, tried: 0 };
|
|
1110
|
+
if (followingSelection) {
|
|
1111
|
+
trackedBox = null;
|
|
1112
|
+
heldTold = null;
|
|
1113
|
+
redraw();
|
|
1114
|
+
}
|
|
970
1115
|
};
|
|
971
1116
|
|
|
972
1117
|
// Where each found mark starts in the document, in order (P112): its place in a list the host
|
|
@@ -1077,6 +1222,10 @@ export const ANNOTATE_RUNTIME = String.raw`if (declared("annotate")) {
|
|
|
1077
1222
|
let waitingForContent = false;
|
|
1078
1223
|
let pendingFocus = null;
|
|
1079
1224
|
let pendingMarker = null;
|
|
1225
|
+
// Asked through the kept function: a page that says it has the focus gets no landing the
|
|
1226
|
+
// platform would refuse (P135).
|
|
1227
|
+
const focusIsHere = () => callOf(hasFocus, document, []) === true;
|
|
1228
|
+
const wordLate = ${WORD_LATE};
|
|
1080
1229
|
const settling = () => anchorTimer !== 0 || waitingForContent || marks.some((mark) => mark.state === null);
|
|
1081
1230
|
const scheduleAnchor = (all) => {
|
|
1082
1231
|
if (all) {
|
|
@@ -1120,10 +1269,9 @@ export const ANNOTATE_RUNTIME = String.raw`if (declared("annotate")) {
|
|
|
1120
1269
|
pendingMarker = null;
|
|
1121
1270
|
// Parked, the host's word is old: the person may have moved on, and a marker's focus
|
|
1122
1271
|
// takes the keyboard with no gesture. So it lands only if the focus is still in this
|
|
1123
|
-
// document
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
focusMark(id);
|
|
1272
|
+
// document. Otherwise it is dropped (P135).
|
|
1273
|
+
if (focusIsHere()) {
|
|
1274
|
+
focusMark(id, false);
|
|
1127
1275
|
}
|
|
1128
1276
|
}
|
|
1129
1277
|
}, wait);
|
|
@@ -1166,9 +1314,11 @@ export const ANNOTATE_RUNTIME = String.raw`if (declared("annotate")) {
|
|
|
1166
1314
|
sent += 1;
|
|
1167
1315
|
}
|
|
1168
1316
|
}
|
|
1317
|
+
// Not while the host follows the selection (P138, Tenny's review): its reports carry where
|
|
1318
|
+
// it is; a scroll after the following ends is re-sent as before.
|
|
1169
1319
|
if (selectionScrolled) {
|
|
1170
1320
|
selectionScrolled = false;
|
|
1171
|
-
if (reportSelection(true)) {
|
|
1321
|
+
if (!followingSelection && reportSelection(true)) {
|
|
1172
1322
|
sent += 1;
|
|
1173
1323
|
}
|
|
1174
1324
|
}
|
|
@@ -1234,10 +1384,11 @@ export const ANNOTATE_RUNTIME = String.raw`if (declared("annotate")) {
|
|
|
1234
1384
|
// markers yet, so it waits for them, as focus does; then a marker that isn't there, or has
|
|
1235
1385
|
// stepped aside for picking, is nothing to do. The kept function, so a page that patched
|
|
1236
1386
|
// focus isn't handed the marker from inside the closed root. The shell's focus listener
|
|
1237
|
-
// lights it and brings it into view; nothing is told. A
|
|
1238
|
-
// focus
|
|
1239
|
-
//
|
|
1240
|
-
|
|
1387
|
+
// lights it and brings it into view; nothing is told. A fresh word reads no focus: after the
|
|
1388
|
+
// host's card closed the focus is on the host's body, so this document has none yet. One
|
|
1389
|
+
// parked is asked as it lands (P135), and one this document took late (P137: late, by when
|
|
1390
|
+
// the host sent it: a busy page doesn't park it) is asked here: its moment has passed.
|
|
1391
|
+
const focusMark = (id, late) => {
|
|
1241
1392
|
if (settling()) {
|
|
1242
1393
|
pendingMarker = id;
|
|
1243
1394
|
return;
|
|
@@ -1245,6 +1396,9 @@ export const ANNOTATE_RUNTIME = String.raw`if (declared("annotate")) {
|
|
|
1245
1396
|
if (mode.elements || !isShown(id)) {
|
|
1246
1397
|
return;
|
|
1247
1398
|
}
|
|
1399
|
+
if (late && !focusIsHere()) {
|
|
1400
|
+
return;
|
|
1401
|
+
}
|
|
1248
1402
|
for (let i = 0; i < markers.length; i += 1) {
|
|
1249
1403
|
if (markers[i].id === id) {
|
|
1250
1404
|
callOf(focusElement, markers[i].element, [{ preventScroll: true }]);
|
|
@@ -1434,6 +1588,7 @@ export const ANNOTATE_RUNTIME = String.raw`if (declared("annotate")) {
|
|
|
1434
1588
|
const stop = () => {
|
|
1435
1589
|
mode = { elements: false, text: false };
|
|
1436
1590
|
hover = null;
|
|
1591
|
+
picked = null;
|
|
1437
1592
|
reported = null;
|
|
1438
1593
|
reportedBox = null;
|
|
1439
1594
|
setCursor(false);
|
|
@@ -1501,6 +1656,9 @@ export const ANNOTATE_RUNTIME = String.raw`if (declared("annotate")) {
|
|
|
1501
1656
|
return;
|
|
1502
1657
|
}
|
|
1503
1658
|
swallowUntil = performance.now() + 2000;
|
|
1659
|
+
holdSelected(anchor, { element });
|
|
1660
|
+
picked = followingSelection ? null : element;
|
|
1661
|
+
redraw();
|
|
1504
1662
|
tell(M.selected, Object.assign({ anchor, rect: box(elementRect.call(element)) }, placeOf({ element })));
|
|
1505
1663
|
}, HOLD_MS),
|
|
1506
1664
|
};
|
|
@@ -1548,6 +1706,9 @@ export const ANNOTATE_RUNTIME = String.raw`if (declared("annotate")) {
|
|
|
1548
1706
|
mode = { elements: false, text: mode.text };
|
|
1549
1707
|
hover = null;
|
|
1550
1708
|
setCursor(false);
|
|
1709
|
+
holdSelected(anchor, { element });
|
|
1710
|
+
// Its outline stays (P138), now without its name, until the host follows it or it ends.
|
|
1711
|
+
picked = followingSelection ? null : element;
|
|
1551
1712
|
draw();
|
|
1552
1713
|
tell(M.selected, Object.assign({ anchor, rect: box(elementRect.call(element)) }, placeOf({ element })));
|
|
1553
1714
|
}, true);
|
|
@@ -1555,6 +1716,8 @@ export const ANNOTATE_RUNTIME = String.raw`if (declared("annotate")) {
|
|
|
1555
1716
|
if (event.key !== "Escape") {
|
|
1556
1717
|
return;
|
|
1557
1718
|
}
|
|
1719
|
+
// The person wants out: a pick's outline goes (P138). The key is untouched by it.
|
|
1720
|
+
endPick();
|
|
1558
1721
|
if (mode.elements) {
|
|
1559
1722
|
event.preventDefault();
|
|
1560
1723
|
event.stopImmediatePropagation();
|
|
@@ -1608,6 +1771,8 @@ export const ANNOTATE_RUNTIME = String.raw`if (declared("annotate")) {
|
|
|
1608
1771
|
}
|
|
1609
1772
|
reported = key;
|
|
1610
1773
|
reportedBox = rect;
|
|
1774
|
+
holdSelected(anchor, { range: cloneRange.call(range) });
|
|
1775
|
+
endPick();
|
|
1611
1776
|
tell(M.selected, Object.assign({ anchor, rect }, placeOf({ range })));
|
|
1612
1777
|
return true;
|
|
1613
1778
|
};
|
|
@@ -1618,6 +1783,10 @@ export const ANNOTATE_RUNTIME = String.raw`if (declared("annotate")) {
|
|
|
1618
1783
|
}
|
|
1619
1784
|
});
|
|
1620
1785
|
window.addEventListener("scroll", () => {
|
|
1786
|
+
// Not while the host follows the selection (P138, Tenny's review).
|
|
1787
|
+
if (followingSelection) {
|
|
1788
|
+
return;
|
|
1789
|
+
}
|
|
1621
1790
|
if (reported !== null) {
|
|
1622
1791
|
selectionScrolled = true;
|
|
1623
1792
|
settle();
|
|
@@ -1637,6 +1806,7 @@ export const ANNOTATE_RUNTIME = String.raw`if (declared("annotate")) {
|
|
|
1637
1806
|
case M.start:
|
|
1638
1807
|
mode = { elements: params.elements === true, text: params.text === true, hold: params.elements === "hold" };
|
|
1639
1808
|
hover = null;
|
|
1809
|
+
picked = null;
|
|
1640
1810
|
reported = null;
|
|
1641
1811
|
reportedBox = null;
|
|
1642
1812
|
setCursor(mode.elements);
|
|
@@ -1668,18 +1838,19 @@ export const ANNOTATE_RUNTIME = String.raw`if (declared("annotate")) {
|
|
|
1668
1838
|
focus(String(params.id));
|
|
1669
1839
|
break;
|
|
1670
1840
|
case M.track:
|
|
1671
|
-
track(params.id);
|
|
1841
|
+
track(params.id, params.selection === true);
|
|
1672
1842
|
break;
|
|
1673
1843
|
case M.clearSelection: {
|
|
1674
1844
|
// The host used the person's selection (P115): it goes, and with it what the shell
|
|
1675
1845
|
// held of it (a report waiting to settle, the one last told, a scroll's follow-up), so
|
|
1676
1846
|
// nothing is told back: the host knows, and the selectionchange this makes finds
|
|
1677
|
-
// nothing to report. Marks, a pick and the mode stay as they are
|
|
1678
|
-
// selected, nothing changes.
|
|
1847
|
+
// nothing to report. Marks, a pick and the mode stay as they are, but a pick's outline
|
|
1848
|
+
// goes (P138). With nothing selected, nothing changes.
|
|
1679
1849
|
cancelLater(selectionTimer);
|
|
1680
1850
|
selectionTimer = 0;
|
|
1681
1851
|
reported = null;
|
|
1682
1852
|
reportedBox = null;
|
|
1853
|
+
endPick();
|
|
1683
1854
|
selectionScrolled = false;
|
|
1684
1855
|
const selection = selectionOf.call(document);
|
|
1685
1856
|
if (selection !== null) {
|
|
@@ -1688,10 +1859,11 @@ export const ANNOTATE_RUNTIME = String.raw`if (declared("annotate")) {
|
|
|
1688
1859
|
break;
|
|
1689
1860
|
}
|
|
1690
1861
|
case M.focusMark:
|
|
1691
|
-
focusMark(String(params.id));
|
|
1862
|
+
focusMark(String(params.id), wordLate(params.at, callOf(wallClock, undefined, [])));
|
|
1692
1863
|
break;
|
|
1693
1864
|
case M.clear:
|
|
1694
1865
|
track(null);
|
|
1866
|
+
picked = null;
|
|
1695
1867
|
pendingFocus = null;
|
|
1696
1868
|
pendingMarker = null;
|
|
1697
1869
|
marks = [];
|
package/src/shell/frame.ts
CHANGED
|
@@ -26,7 +26,12 @@ import { hostOriginProblem, onNestedLabel } from "../isolation/served.ts";
|
|
|
26
26
|
* - renews the page's sealed files' address before it ends, and gives the page the new one
|
|
27
27
|
* (`porthole/files-renewed`): the page's own loads aren't its origin's (an opaque origin's never
|
|
28
28
|
* are), so only the shell, on that origin, may renew it (P083);
|
|
29
|
-
* - passes its focus to the page
|
|
29
|
+
* - passes its focus to the page: at the focus event where that takes (Firefox, from the host's
|
|
30
|
+
* `<body>`), and on the host's word that it moved it there (`porthole/shell/focus`, P136), where
|
|
31
|
+
* it doesn't: a frame's move inside the focus event that made it the focused frame sets the
|
|
32
|
+
* shell's `activeElement` and goes no further (Chromium, WebKit), and from a focused element of
|
|
33
|
+
* the host's the window hears no focus event at all (Firefox). A later task's `frame.focus()`
|
|
34
|
+
* goes through on all of them, the frame blurred first as the failed one left it active.
|
|
30
35
|
*
|
|
31
36
|
* Plain ES2020, no imports and no build step, like the runtime. `__PLAN__` is its plan.
|
|
32
37
|
*/
|
|
@@ -152,12 +157,39 @@ export const FRAME_SHELL_RUNTIME = String.raw`(() => {
|
|
|
152
157
|
};
|
|
153
158
|
requestAnimationFrame(tick);
|
|
154
159
|
setInterval(look, 50);
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
160
|
+
|
|
161
|
+
// Whether the focus is on the shell's own document, not through it on the page's (P136). Firefox
|
|
162
|
+
// tells a move from a focused element of the host's on the document alone. The host's word needs
|
|
163
|
+
// this: it never moves a focus that isn't here, and a page that has it hears no blur.
|
|
164
|
+
let holds = false;
|
|
165
|
+
// Until when a word that came ahead of the focus it speaks of holds (it crosses processes too).
|
|
166
|
+
let wordUntil = 0;
|
|
167
|
+
const handOn = () => {
|
|
168
|
+
if (holds && document.hasFocus()) {
|
|
169
|
+
frame.blur();
|
|
159
170
|
frame.focus();
|
|
160
171
|
}
|
|
172
|
+
};
|
|
173
|
+
const came = () => {
|
|
174
|
+
holds = true;
|
|
175
|
+
if (performance.now() < wordUntil) {
|
|
176
|
+
wordUntil = 0;
|
|
177
|
+
setTimeout(handOn, 0);
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
document.addEventListener("focus", came);
|
|
181
|
+
addEventListener("blur", () => {
|
|
182
|
+
holds = false;
|
|
183
|
+
look();
|
|
184
|
+
});
|
|
185
|
+
addEventListener("focus", (event) => {
|
|
186
|
+
if (event.target === window) {
|
|
187
|
+
came();
|
|
188
|
+
// Where a move can go on from inside this event (P136): Firefox, from the host's <body>.
|
|
189
|
+
if (document.activeElement !== frame) {
|
|
190
|
+
frame.focus();
|
|
191
|
+
}
|
|
192
|
+
}
|
|
161
193
|
look();
|
|
162
194
|
});
|
|
163
195
|
document.addEventListener("visibilitychange", look);
|
|
@@ -184,6 +216,14 @@ export const FRAME_SHELL_RUNTIME = String.raw`(() => {
|
|
|
184
216
|
if (data.method === PREFIX + "look" && typeof n === "number" && n >= 0 && Math.floor(n) === n) {
|
|
185
217
|
look(n);
|
|
186
218
|
}
|
|
219
|
+
// The host's own move into the frame, done (P136): on to the page.
|
|
220
|
+
if (data.method === PREFIX + "focus") {
|
|
221
|
+
if (holds) {
|
|
222
|
+
handOn();
|
|
223
|
+
} else {
|
|
224
|
+
wordUntil = performance.now() + 250;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
187
227
|
return;
|
|
188
228
|
}
|
|
189
229
|
const child = frame.contentWindow;
|