@botiverse/porthole 0.14.9 → 0.14.10
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 +19 -0
- package/dist/annotate/types.d.ts +33 -2
- package/dist/annotate/validate.d.ts +6 -1
- package/dist/annotate/validate.js +31 -3
- package/dist/check/page-source.js +1 -1
- package/dist/conformance/harness-source.js +1 -1
- package/dist/host/create-host.js +5 -3
- package/dist/host/types.d.ts +3 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/react/frame.d.ts +2 -1
- package/dist/shell/annotate.d.ts +5 -1
- package/dist/shell/annotate.js +39 -12
- package/docs/ADOPTING.md +29 -0
- package/docs/DECISIONS.md +65 -0
- package/docs/DESIGN.md +15 -2
- package/docs/THREAT_MODEL.md +15 -3
- package/package.json +1 -1
- package/src/annotate/types.ts +43 -4
- package/src/annotate/validate.ts +34 -3
- package/src/host/create-host.ts +5 -3
- package/src/host/types.ts +3 -1
- package/src/index.ts +2 -1
- package/src/react/frame.tsx +2 -1
- package/src/shell/annotate.ts +39 -12
package/src/react/frame.tsx
CHANGED
|
@@ -690,7 +690,8 @@ export interface PortholeFrameProps {
|
|
|
690
690
|
| null;
|
|
691
691
|
/**
|
|
692
692
|
* The mark to follow (`annotations.track`, P112, P118): while it moves, `onAnnotation` gets
|
|
693
|
-
* `{ type: "tracked", id, rect }` at most once per animation frame, for it alone
|
|
693
|
+
* `{ type: "tracked", id, rect }` at most once per animation frame, for it alone (from a newer
|
|
694
|
+
* shell with its `documentRect` and the document's `scroll`, P132). `null` (or
|
|
694
695
|
* leaving it out once set) stops. By value: given when it changes, and when the display is made.
|
|
695
696
|
* Only a shown mark (`annotations`) is followed: another id, or a config without `annotate`, is
|
|
696
697
|
* `onHostError` (kind `"annotations"`), as the core's call throws. `annotations` without it
|
package/src/shell/annotate.ts
CHANGED
|
@@ -57,7 +57,11 @@ export const MARKER_HIT = String.raw`(count, boxAt, x, y, touch) => {
|
|
|
57
57
|
* bubble with no number, and has a marker with or without a count;
|
|
58
58
|
* - following: while a mark has a marker, once a scroll, a resize or a change of the content
|
|
59
59
|
* settles, the marks that moved since the host was last told are reported, at most once a
|
|
60
|
-
* second, so the host's own UI beside a mark can follow
|
|
60
|
+
* second, so the host's own UI beside a mark can follow;
|
|
61
|
+
* - places in the document (P132): each result's box also in the document's coordinates
|
|
62
|
+
* (`documentRect`), with how far the document was scrolled as it was read (`scroll`), and the
|
|
63
|
+
* followed mark's (`tracked`) too, so a host places marks scrolled out of the frame, and keeps
|
|
64
|
+
* them placed as the document scrolls, from one report and the followed mark's scroll.
|
|
61
65
|
*
|
|
62
66
|
* It shares the realm with the content, which can interfere with all of it: the host takes its
|
|
63
67
|
* reports as UI hints only.
|
|
@@ -306,6 +310,19 @@ export const ANNOTATE_RUNTIME = String.raw`if (declared("annotate")) {
|
|
|
306
310
|
return null;
|
|
307
311
|
};
|
|
308
312
|
const rectOf = (found) => (found.range ? rangeRect.call(found.range) : elementRect.call(found.element));
|
|
313
|
+
// How far the document is scrolled (P132): the top left of its root's box from the
|
|
314
|
+
// viewport's, negated, read with the DOM's own getBoundingClientRect (taken before content
|
|
315
|
+
// runs), never window.scrollY, which the content can replace. 0 - n: no -0 for a top at 0.
|
|
316
|
+
const scrollOf = () => {
|
|
317
|
+
const root = document.documentElement;
|
|
318
|
+
if (!root) {
|
|
319
|
+
return { x: 0, y: 0 };
|
|
320
|
+
}
|
|
321
|
+
const rect = elementRect.call(root);
|
|
322
|
+
return { x: 0 - rect.left, y: 0 - rect.top };
|
|
323
|
+
};
|
|
324
|
+
// A box in the viewport, in the document (P132): where it is as the document scrolls.
|
|
325
|
+
const inDocument = (rect, scroll) => ({ x: rect.x + scroll.x, y: rect.y + scroll.y, width: rect.width, height: rect.height });
|
|
309
326
|
|
|
310
327
|
// The shell's own layer, over the content: marks, the outline of what would be picked.
|
|
311
328
|
let layer = null;
|
|
@@ -799,7 +816,10 @@ export const ANNOTATE_RUNTIME = String.raw`if (declared("annotate")) {
|
|
|
799
816
|
if (apart(trackedBox, rect) && now - trackedAt >= 16) {
|
|
800
817
|
trackedBox = rect;
|
|
801
818
|
trackedAt = now;
|
|
802
|
-
|
|
819
|
+
// Its box moves as the document scrolls, inside the frame or not: each one tells the
|
|
820
|
+
// host the scroll, for every mark it places by its place in the document (P132).
|
|
821
|
+
const scroll = scrollOf();
|
|
822
|
+
tell(M.tracked, { id: tracking, rect, documentRect: inDocument(rect, scroll), scroll });
|
|
803
823
|
}
|
|
804
824
|
}
|
|
805
825
|
trackFrame = nextFrame(trackTick);
|
|
@@ -843,12 +863,15 @@ export const ANNOTATE_RUNTIME = String.raw`if (declared("annotate")) {
|
|
|
843
863
|
placed.forEach((each, at) => orders.set(each.mark, at));
|
|
844
864
|
return orders;
|
|
845
865
|
};
|
|
846
|
-
|
|
866
|
+
// A mark's result: its box in the viewport, and in the document (P132) by scroll, the
|
|
867
|
+
// report's one reading of it.
|
|
868
|
+
const resultOf = (mark, orders, scroll) => {
|
|
847
869
|
if (mark.found === null) {
|
|
848
870
|
return { id: mark.id, state: "orphaned" };
|
|
849
871
|
}
|
|
850
872
|
const order = (orders || ordersOf()).get(mark);
|
|
851
|
-
|
|
873
|
+
const rect = box(rectOf(mark.found));
|
|
874
|
+
return Object.assign({ id: mark.id, state: "attached", rect, documentRect: inDocument(rect, scroll) }, order === undefined ? {} : { order });
|
|
852
875
|
};
|
|
853
876
|
// Two boxes more than 0.5 px apart on any side (or one of them unknown).
|
|
854
877
|
const apart = (a, b) => !a || !b || Math.abs(a.x - b.x) > 0.5 || Math.abs(a.y - b.y) > 0.5 || Math.abs(a.width - b.width) > 0.5 || Math.abs(a.height - b.height) > 0.5;
|
|
@@ -860,17 +883,18 @@ export const ANNOTATE_RUNTIME = String.raw`if (declared("annotate")) {
|
|
|
860
883
|
}
|
|
861
884
|
return result.state === "attached" && (apart(told.rect, result.rect) || told.order !== result.order);
|
|
862
885
|
};
|
|
863
|
-
|
|
886
|
+
// With the scroll the results' document boxes were read at (P132).
|
|
887
|
+
const report = (pairs, scroll) => {
|
|
864
888
|
if (pairs.length > 0) {
|
|
865
889
|
for (const pair of pairs) {
|
|
866
890
|
pair.mark.told = pair.result;
|
|
867
891
|
}
|
|
868
|
-
tell(M.anchored, { results: pairs.map((pair) => pair.result) });
|
|
892
|
+
tell(M.anchored, { results: pairs.map((pair) => pair.result), scroll });
|
|
869
893
|
}
|
|
870
894
|
};
|
|
871
|
-
const resultsOf = (only) => {
|
|
895
|
+
const resultsOf = (only, scroll) => {
|
|
872
896
|
const orders = ordersOf();
|
|
873
|
-
return marks.map((mark) => ({ mark, result: resultOf(mark, orders) })).filter((pair) => !only || moved(pair.mark, pair.result));
|
|
897
|
+
return marks.map((mark) => ({ mark, result: resultOf(mark, orders, scroll) })).filter((pair) => !only || moved(pair.mark, pair.result));
|
|
874
898
|
};
|
|
875
899
|
// Finds every mark again; tells the host every result (after show, or when a state changed),
|
|
876
900
|
// only the marks that moved (once the content is quiet), or nothing.
|
|
@@ -892,7 +916,8 @@ export const ANNOTATE_RUNTIME = String.raw`if (declared("annotate")) {
|
|
|
892
916
|
mark.state = state;
|
|
893
917
|
}
|
|
894
918
|
if (all || changed) {
|
|
895
|
-
|
|
919
|
+
const scroll = scrollOf();
|
|
920
|
+
report(resultsOf(false, scroll), scroll);
|
|
896
921
|
} else if (quiet) {
|
|
897
922
|
follow();
|
|
898
923
|
}
|
|
@@ -977,9 +1002,10 @@ export const ANNOTATE_RUNTIME = String.raw`if (declared("annotate")) {
|
|
|
977
1002
|
const sendFollow = () => {
|
|
978
1003
|
let sent = 0;
|
|
979
1004
|
if (marks.length > 0 && !settling() && counted()) {
|
|
980
|
-
const
|
|
1005
|
+
const scroll = scrollOf();
|
|
1006
|
+
const pairs = resultsOf(true, scroll);
|
|
981
1007
|
if (pairs.length > 0) {
|
|
982
|
-
report(pairs);
|
|
1008
|
+
report(pairs, scroll);
|
|
983
1009
|
sent += 1;
|
|
984
1010
|
}
|
|
985
1011
|
}
|
|
@@ -1043,7 +1069,8 @@ export const ANNOTATE_RUNTIME = String.raw`if (declared("annotate")) {
|
|
|
1043
1069
|
setTimeout(redraw, 1850);
|
|
1044
1070
|
}
|
|
1045
1071
|
draw();
|
|
1046
|
-
|
|
1072
|
+
const scroll = scrollOf();
|
|
1073
|
+
report([{ mark, result: resultOf(mark, null, scroll) }], scroll);
|
|
1047
1074
|
};
|
|
1048
1075
|
|
|
1049
1076
|
// A marker's click (P104). The layer takes no pointer but on its markers, so a press whose
|