pi-pocket 0.26.0 → 0.27.0-beta.2
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/CONTRIBUTING.md +1 -1
- package/docs/design/design-system.md +165 -0
- package/docs/design/ds-notes-b.md +61 -0
- package/docs/design/ds-notes-g.md +170 -0
- package/docs/design/ds-notes-t.md +303 -0
- package/docs/design/ds-notes-u.md +220 -0
- package/docs/design/ds-notes-v.md +186 -0
- package/docs/design/ds-rounds.md +160 -0
- package/docs/design/ds-u-bridge.patch +732 -0
- package/docs/examples/design-system/README.md +15 -0
- package/docs/examples/design-system/pocket/.pi/design/components/badge.html +112 -0
- package/docs/examples/design-system/pocket/.pi/design/components/button.html +203 -0
- package/docs/examples/design-system/pocket/.pi/design/components/card.html +125 -0
- package/docs/examples/design-system/pocket/.pi/design/components/code-block.html +155 -0
- package/docs/examples/design-system/pocket/.pi/design/components/input.html +156 -0
- package/docs/examples/design-system/pocket/.pi/design/components/menu-row.html +167 -0
- package/docs/examples/design-system/pocket/.pi/design/components/notice.html +171 -0
- package/docs/examples/design-system/pocket/.pi/design/components/segmented.html +120 -0
- package/docs/examples/design-system/pocket/.pi/design/components/switch.html +117 -0
- package/docs/examples/design-system/pocket/.pi/design/components/tool-step.html +163 -0
- package/docs/examples/design-system/pocket/.pi/design/dist/components.css +730 -0
- package/docs/examples/design-system/pocket/.pi/design/dist/names.md +495 -0
- package/docs/examples/design-system/pocket/.pi/design/dist/tailwind.css +1132 -0
- package/docs/examples/design-system/pocket/.pi/design/dist/tokens.css +1126 -0
- package/docs/examples/design-system/pocket/.pi/design/dist/tokens.dark.resolved.json +2022 -0
- package/docs/examples/design-system/pocket/.pi/design/dist/tokens.high-contrast.resolved.json +2022 -0
- package/docs/examples/design-system/pocket/.pi/design/dist/tokens.light.resolved.json +2022 -0
- package/docs/examples/design-system/pocket/.pi/design/dist/tokens.resolved.json +371 -0
- package/docs/examples/design-system/pocket/.pi/design/dist/tokens.studio.json +5915 -0
- package/docs/examples/design-system/pocket/.pi/design/guidelines.md +81 -0
- package/docs/examples/design-system/pocket/.pi/design/tokens.dark.json +182 -0
- package/docs/examples/design-system/pocket/.pi/design/tokens.high-contrast.json +185 -0
- package/docs/examples/design-system/pocket/.pi/design/tokens.json +2034 -0
- package/docs/features.md +6 -2
- package/docs/index.md +1 -0
- package/docs/map.md +34 -25
- package/docs/release-notes.md +1 -1
- package/docs/releases.md +45 -0
- package/package.json +2 -1
- package/src/server/design/check-cli.ts +283 -0
- package/src/server/design/color.ts +654 -0
- package/src/server/design/components.ts +328 -0
- package/src/server/design/docsite-assets.ts +29 -0
- package/src/server/design/docsite-color-section.ts +366 -0
- package/src/server/design/docsite-color.ts +303 -0
- package/src/server/design/docsite-components.ts +89 -0
- package/src/server/design/docsite-core.ts +634 -0
- package/src/server/design/docsite-css-base.ts +397 -0
- package/src/server/design/docsite-css-content.ts +477 -0
- package/src/server/design/docsite-css-phone.ts +251 -0
- package/src/server/design/docsite-css-reference.ts +374 -0
- package/src/server/design/docsite-css-specimens.ts +465 -0
- package/src/server/design/docsite-js-code.ts +96 -0
- package/src/server/design/docsite-js-core.ts +72 -0
- package/src/server/design/docsite-js-demos.ts +24 -0
- package/src/server/design/docsite-js-links.ts +25 -0
- package/src/server/design/docsite-js-nav.ts +73 -0
- package/src/server/design/docsite-js-stages.ts +81 -0
- package/src/server/design/docsite-js-table.ts +81 -0
- package/src/server/design/docsite-markdown.ts +221 -0
- package/src/server/design/docsite-motion.ts +110 -0
- package/src/server/design/docsite-reference.ts +269 -0
- package/src/server/design/docsite-sanitize.ts +193 -0
- package/src/server/design/docsite-shadows.ts +45 -0
- package/src/server/design/docsite-space.ts +289 -0
- package/src/server/design/docsite-type.ts +167 -0
- package/src/server/design/docsite.ts +508 -0
- package/src/server/design/export.ts +86 -9
- package/src/server/design/fix.ts +666 -0
- package/src/server/design/guide.ts +137 -22
- package/src/server/design/index.ts +368 -15
- package/src/server/design/lint-color.ts +293 -0
- package/src/server/design/lint-page-checks.ts +204 -0
- package/src/server/design/lint-page-elements.ts +252 -0
- package/src/server/design/lint-page-focus.ts +165 -0
- package/src/server/design/lint-page-literals.ts +293 -0
- package/src/server/design/lint-page-setup.ts +102 -0
- package/src/server/design/lint-page-states.ts +121 -0
- package/src/server/design/lint-page-values.ts +329 -0
- package/src/server/design/lint-page.ts +101 -0
- package/src/server/design/lint-suggest.ts +340 -0
- package/src/server/design/lint.ts +1136 -0
- package/src/server/design/render.ts +369 -18
- package/src/server/design/scan-braces.ts +115 -0
- package/src/server/design/scan-categorize.ts +187 -0
- package/src/server/design/scan-channels.ts +113 -0
- package/src/server/design/scan-color-base.ts +209 -0
- package/src/server/design/scan-color-names.ts +403 -0
- package/src/server/design/scan-color-palette.ts +91 -0
- package/src/server/design/scan-color-roles.ts +565 -0
- package/src/server/design/scan-colors.ts +22 -0
- package/src/server/design/scan-facts-antd.ts +171 -0
- package/src/server/design/scan-facts-files.ts +300 -0
- package/src/server/design/scan-facts-lists.ts +538 -0
- package/src/server/design/scan-facts-sass.ts +113 -0
- package/src/server/design/scan-facts-theme.ts +400 -0
- package/src/server/design/scan-facts-use.ts +674 -0
- package/src/server/design/scan-facts-wordpress.ts +374 -0
- package/src/server/design/scan-facts.ts +285 -0
- package/src/server/design/scan-files.ts +384 -0
- package/src/server/design/scan-import-convert.ts +277 -0
- package/src/server/design/scan-import-eval.ts +583 -0
- package/src/server/design/scan-import-material.ts +745 -0
- package/src/server/design/scan-import-sd-config.ts +370 -0
- package/src/server/design/scan-import-sd.ts +381 -0
- package/src/server/design/scan-import-studio.ts +242 -0
- package/src/server/design/scan-import.ts +336 -0
- package/src/server/design/scan-infer.ts +313 -0
- package/src/server/design/scan-js-eval.ts +1267 -0
- package/src/server/design/scan-palette.ts +485 -0
- package/src/server/design/scan-parse.ts +1134 -0
- package/src/server/design/scan-prepare.ts +402 -0
- package/src/server/design/scan-render-pages.ts +367 -0
- package/src/server/design/scan-render-probe.ts +229 -0
- package/src/server/design/scan-render.ts +524 -0
- package/src/server/design/scan-review.ts +54 -0
- package/src/server/design/scan-roles.ts +259 -0
- package/src/server/design/scan-sass-colors.ts +275 -0
- package/src/server/design/scan-sass-eval.ts +269 -0
- package/src/server/design/scan-sass-expr.ts +911 -0
- package/src/server/design/scan-sass-modules.ts +353 -0
- package/src/server/design/scan-sass-run.ts +1003 -0
- package/src/server/design/scan-sass-stmt.ts +256 -0
- package/src/server/design/scan-sass-values.ts +886 -0
- package/src/server/design/scan-scales.ts +983 -0
- package/src/server/design/scan-tailwind.ts +34 -0
- package/src/server/design/scan-theme-shapes.ts +579 -0
- package/src/server/design/scan-tree.ts +290 -0
- package/src/server/design/scan-util.ts +44 -0
- package/src/server/design/scan-variables.ts +470 -0
- package/src/server/design/scan.ts +703 -0
- package/src/server/design/system-schema.ts +68 -0
- package/src/server/design/system-types.ts +279 -0
- package/src/server/design/system.ts +510 -82
- package/src/server/design/tokens-base.ts +123 -0
- package/src/server/design/tokens-compile.ts +440 -0
- package/src/server/design/tokens-dtcg.ts +354 -0
- package/src/server/design/tokens-io.ts +417 -0
- package/src/server/design/tokens-model.ts +1163 -0
- package/src/server/design/tokens-names.ts +112 -0
- package/src/server/design/tokens-ramps.ts +112 -0
- package/src/server/design/tokens-summary.ts +317 -0
- package/src/server/design/tokens-tailwind.ts +324 -0
- package/src/server/design/tokens-values.ts +921 -0
- package/src/server/design/tokens.ts +533 -0
- package/src/server/docs.ts +8 -0
- package/src/server/extensions/artifacts.ts +87 -2
- package/src/server/extensions/design/app.js +280 -0
- package/src/server/extensions/design/canvas.js +142 -17
- package/src/server/extensions/design/check.js +656 -0
- package/src/server/extensions/design/color.js +383 -0
- package/src/server/extensions/design/data.js +102 -7
- package/src/server/extensions/design/devices.js +26 -0
- package/src/server/extensions/design/docks.js +117 -3
- package/src/server/extensions/design/index.js +171 -219
- package/src/server/extensions/design/messages.js +49 -0
- package/src/server/extensions/design/parts.js +15 -1
- package/src/server/extensions/design/paths.js +4 -0
- package/src/server/extensions/design/picker.js +123 -0
- package/src/server/extensions/design/specimen.js +55 -0
- package/src/server/extensions/design/state.js +72 -7
- package/src/server/extensions/design/style.css +546 -0
- package/src/server/extensions/design/system-actions.js +214 -0
- package/src/server/extensions/design/system-api.ts +62 -0
- package/src/server/extensions/design/system-data.js +315 -0
- package/src/server/extensions/design/system-preview.js +41 -0
- package/src/server/extensions/design/system-routes.ts +1122 -0
- package/src/server/extensions/design/system-sections.js +1344 -0
- package/src/server/extensions/design/system-ui.js +32 -0
- package/src/server/extensions/design/system-view.js +1196 -0
- package/src/server/extensions/design/system-widgets.js +942 -0
- package/src/server/extensions/design/system.css +2313 -0
- package/src/server/extensions/design/system.js +1479 -0
- package/src/server/extensions/design/unsaved.js +20 -0
- package/src/server/extensions/design/views.js +2 -2
- package/src/server/extensions/design/workspace.js +200 -105
- package/src/server/extensions/design.ts +89 -6
- package/src/server/extensions/updates/index.js +31 -9
- package/src/server/extensions/updates/style.css +11 -0
- package/src/server/extensions/updates.ts +29 -1
- package/src/server/host.ts +4 -1
- package/src/server/http/artifact-inspect.ts +338 -24
- package/src/server/updates.ts +235 -53
- package/src/server/versions.ts +71 -0
- package/web/artifact-bridge.js +34 -1
- package/npm-shrinkwrap.json +0 -3162
|
@@ -0,0 +1,732 @@
|
|
|
1
|
+
diff --git c/src/server/http/artifact-inspect.ts w/src/server/http/artifact-inspect.ts
|
|
2
|
+
index 9fb5a29..20d9b88 100644
|
|
3
|
+
--- c/src/server/http/artifact-inspect.ts
|
|
4
|
+
+++ w/src/server/http/artifact-inspect.ts
|
|
5
|
+
@@ -306,6 +306,196 @@ export const ARTIFACT_INSPECT = String.raw`(send, standalone) => {
|
|
6
|
+
}
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
+ // A pin's badge sits where it covers no text of the page: it tries outside the element (above, left, right, below), and
|
|
10
|
+
+ // then inside at its right edge. A place is free when no text and no picture of the page lies under the badge.
|
|
11
|
+
+ const REPLACED = /^(IMG|SVG|VIDEO|CANVAS|INPUT|SELECT|TEXTAREA|BUTTON|IFRAME|PICTURE)$/i;
|
|
12
|
+
+
|
|
13
|
+
+ const covered = (x, y, w, h) => {
|
|
14
|
+
+ const points = [[x + 2, y + 2], [x + w - 2, y + 2], [x + 2, y + h - 2], [x + w - 2, y + h - 2], [x + w / 2, y + h / 2]];
|
|
15
|
+
+
|
|
16
|
+
+ for (const [px, py] of points) {
|
|
17
|
+
+ if (px < 0 || py < 0 || px >= win.innerWidth || py >= win.innerHeight) {
|
|
18
|
+
+ continue;
|
|
19
|
+
+ }
|
|
20
|
+
+
|
|
21
|
+
+ for (const el of doc.elementsFromPoint(px, py)) {
|
|
22
|
+
+ if (el === doc.documentElement || (overlay && el === overlay.host)) {
|
|
23
|
+
+ continue;
|
|
24
|
+
+ }
|
|
25
|
+
+
|
|
26
|
+
+ if (REPLACED.test(el.tagName)) {
|
|
27
|
+
+ return true;
|
|
28
|
+
+ }
|
|
29
|
+
+
|
|
30
|
+
+ for (const node of el.childNodes) {
|
|
31
|
+
+ if (node.nodeType === 3 && node.textContent.trim() !== "") {
|
|
32
|
+
+ const range = doc.createRange();
|
|
33
|
+
+
|
|
34
|
+
+ range.selectNodeContents(node);
|
|
35
|
+
+
|
|
36
|
+
+ for (const box of range.getClientRects()) {
|
|
37
|
+
+ if (box.right > x && box.left < x + w && box.bottom > y && box.top < y + h) {
|
|
38
|
+
+ return true;
|
|
39
|
+
+ }
|
|
40
|
+
+ }
|
|
41
|
+
+ }
|
|
42
|
+
+ }
|
|
43
|
+
+ }
|
|
44
|
+
+ }
|
|
45
|
+
+
|
|
46
|
+
+ return false;
|
|
47
|
+
+ };
|
|
48
|
+
+
|
|
49
|
+
+ // The places, in the order they are tried, for a badge w wide: outside the element above it, to its left, to its right,
|
|
50
|
+
+ // above its right edge, below it, and inside at its right edge.
|
|
51
|
+
+ const BADGE_H = 22;
|
|
52
|
+
+
|
|
53
|
+
+ const placesOf = (rect, w) => [
|
|
54
|
+
+ [rect.left, rect.top - BADGE_H - 3],
|
|
55
|
+
+ [rect.left - w - 3, rect.top],
|
|
56
|
+
+ [rect.right + 3, rect.top],
|
|
57
|
+
+ [rect.right - w, rect.top - BADGE_H - 3],
|
|
58
|
+
+ [rect.left, rect.bottom + 3],
|
|
59
|
+
+ [rect.right - w - 2, rect.top + 2],
|
|
60
|
+
+ ];
|
|
61
|
+
+
|
|
62
|
+
+ const onScreen = ([x, y], w) => x >= 0 && y >= 0 && x + w <= win.innerWidth && y + BADGE_H <= win.innerHeight;
|
|
63
|
+
+
|
|
64
|
+
+ // The first place on the screen that covers no text, else the first on the screen, else the first. It costs a hit test
|
|
65
|
+
+ // for each place, so it is worked out when a pin first shows and when its element's layout changes, not every frame.
|
|
66
|
+
+ const findPlace = (rect, w) => {
|
|
67
|
+
+ const places = placesOf(rect, w);
|
|
68
|
+
+ let first = -1;
|
|
69
|
+
+
|
|
70
|
+
+ for (let at = 0; at < places.length; at += 1) {
|
|
71
|
+
+ if (onScreen(places[at], w)) {
|
|
72
|
+
+ first = first === -1 ? at : first;
|
|
73
|
+
+
|
|
74
|
+
+ if (!covered(places[at][0], places[at][1], w, BADGE_H)) {
|
|
75
|
+
+ return at;
|
|
76
|
+
+ }
|
|
77
|
+
+ }
|
|
78
|
+
+ }
|
|
79
|
+
+
|
|
80
|
+
+ return first === -1 ? 0 : first;
|
|
81
|
+
+ };
|
|
82
|
+
+
|
|
83
|
+
+ // What may have changed the page's layout since a pin was placed: its size, or its content (a throttled stamp that a
|
|
84
|
+
+ // pin compares with its own).
|
|
85
|
+
+ let layoutStamp = 0;
|
|
86
|
+
+ let layoutDirty = false;
|
|
87
|
+
+ let stampedAt = 0;
|
|
88
|
+
+ let layoutWatch = null;
|
|
89
|
+
+ // How long one frame may spend finding places: the rest wait for the next frame (a pin is hidden until it has one).
|
|
90
|
+
+ const PLACE_BUDGET = 3;
|
|
91
|
+
+
|
|
92
|
+
+ const watchLayout = () => {
|
|
93
|
+
+ if (layoutWatch !== null || typeof win.ResizeObserver !== "function") {
|
|
94
|
+
+ return;
|
|
95
|
+
+ }
|
|
96
|
+
+
|
|
97
|
+
+ const dirty = () => {
|
|
98
|
+
+ layoutDirty = true;
|
|
99
|
+
+ };
|
|
100
|
+
+
|
|
101
|
+
+ layoutWatch = [new win.ResizeObserver(() => {
|
|
102
|
+
+ layoutStamp += 1;
|
|
103
|
+
+ }), typeof win.MutationObserver === "function" ? new win.MutationObserver(dirty) : null];
|
|
104
|
+
+ layoutWatch[0].observe(doc.documentElement);
|
|
105
|
+
+ layoutWatch[1]?.observe(doc.documentElement, { subtree: true, childList: true, characterData: true, attributes: true });
|
|
106
|
+
+ };
|
|
107
|
+
+
|
|
108
|
+
+ const unwatchLayout = () => {
|
|
109
|
+
+ if (layoutWatch !== null) {
|
|
110
|
+
+ layoutWatch[0].disconnect();
|
|
111
|
+
+ layoutWatch[1]?.disconnect();
|
|
112
|
+
+ layoutWatch = null;
|
|
113
|
+
+ }
|
|
114
|
+
+ };
|
|
115
|
+
+
|
|
116
|
+
+ // The pins: all the reads first, then all the writes, so that the page's layout is worked out once and not once for each
|
|
117
|
+
+ // pin. A pin whose element is off the screen is hidden and costs a rectangle; one whose place is known costs arithmetic.
|
|
118
|
+
+ const updatePins = () => {
|
|
119
|
+
+ const started = now();
|
|
120
|
+
+ const sx = win.scrollX;
|
|
121
|
+
+ const sy = win.scrollY;
|
|
122
|
+
+ const vw = win.innerWidth;
|
|
123
|
+
+ const vh = win.innerHeight;
|
|
124
|
+
+
|
|
125
|
+
+ // The page's content changes (a mutation that the page makes, at most once a second): the places are looked at again.
|
|
126
|
+
+ if (layoutDirty && started - stampedAt > 1000) {
|
|
127
|
+
+ layoutDirty = false;
|
|
128
|
+
+ stampedAt = started;
|
|
129
|
+
+ layoutStamp += 1;
|
|
130
|
+
+ }
|
|
131
|
+
+
|
|
132
|
+
+ const drawn = [];
|
|
133
|
+
+
|
|
134
|
+
+ for (const pin of pins) {
|
|
135
|
+
+ if (!pin.el || !pin.el.isConnected) {
|
|
136
|
+
+ pin.el = findPinTarget(pin.target);
|
|
137
|
+
+ pin.stamp = -1;
|
|
138
|
+
+ }
|
|
139
|
+
+
|
|
140
|
+
+ const rect = pin.el ? pin.el.getBoundingClientRect() : null;
|
|
141
|
+
+ const real = rect !== null && (rect.width > 0 || rect.height > 0);
|
|
142
|
+
+ const near = real && rect.bottom > -40 && rect.top < vh + 40 && rect.right > -40 && rect.left < vw + 40;
|
|
143
|
+
+ let at = null;
|
|
144
|
+
+
|
|
145
|
+
+ if (near) {
|
|
146
|
+
+ // Where the element is on the page, and how big: a scroll changes neither.
|
|
147
|
+
+ const key = rect.left + sx + "," + (rect.top + sy) + "," + rect.width + "," + rect.height;
|
|
148
|
+
+ const known =
|
|
149
|
+
+ pin.place !== undefined &&
|
|
150
|
+
+ pin.key === key &&
|
|
151
|
+
+ pin.stamp === layoutStamp &&
|
|
152
|
+
+ (pin.fallback === true || onScreen(placesOf(rect, pin.w)[pin.place], pin.w));
|
|
153
|
+
+
|
|
154
|
+
+ // (one that has a place moves to its new one at once; one with none waits, when the frame's time is spent)
|
|
155
|
+
+ if (!known && (pin.place !== undefined || now() - started < PLACE_BUDGET)) {
|
|
156
|
+
+ pin.place = findPlace(rect, pin.w);
|
|
157
|
+
+ pin.key = key;
|
|
158
|
+
+ pin.stamp = layoutStamp;
|
|
159
|
+
+ pin.fallback = !onScreen(placesOf(rect, pin.w)[pin.place], pin.w);
|
|
160
|
+
+ }
|
|
161
|
+
+
|
|
162
|
+
+ if (pin.place !== undefined) {
|
|
163
|
+
+ at = placesOf(rect, pin.w)[pin.place];
|
|
164
|
+
+ }
|
|
165
|
+
+ }
|
|
166
|
+
+
|
|
167
|
+
+ drawn.push([pin, near ? rect : null, at]);
|
|
168
|
+
+ }
|
|
169
|
+
+
|
|
170
|
+
+ for (const [pin, rect, at] of drawn) {
|
|
171
|
+
+ const mine = pin.drawn;
|
|
172
|
+
+ const shown = rect !== null && at !== null;
|
|
173
|
+
+ const move = shown
|
|
174
|
+
+ ? "translate(" + Math.round(Math.min(Math.max(at[0], 2), vw - pin.w - 2)) + "px," + Math.round(Math.min(Math.max(at[1], 2), vh - BADGE_H - 2)) + "px)"
|
|
175
|
+
+ : "";
|
|
176
|
+
+ const box = shown
|
|
177
|
+
+ ? "translate(" + Math.round(rect.left) + "px," + Math.round(rect.top) + "px)"
|
|
178
|
+
+ : "";
|
|
179
|
+
+ const size = shown ? Math.round(rect.width) + "x" + Math.round(rect.height) : "";
|
|
180
|
+
+
|
|
181
|
+
+ if (mine.node !== move) {
|
|
182
|
+
+ css(pin.node, shown ? { display: "flex", transform: move } : { display: "none" });
|
|
183
|
+
+ mine.node = move;
|
|
184
|
+
+ }
|
|
185
|
+
+
|
|
186
|
+
+ if (pin.outline && (mine.box !== box || mine.size !== size)) {
|
|
187
|
+
+ css(
|
|
188
|
+
+ pin.outline,
|
|
189
|
+
+ shown
|
|
190
|
+
+ ? { display: "block", transform: box, width: Math.round(rect.width) + "px", height: Math.round(rect.height) + "px" }
|
|
191
|
+
+ : { display: "none" },
|
|
192
|
+
+ );
|
|
193
|
+
+ mine.box = box;
|
|
194
|
+
+ mine.size = size;
|
|
195
|
+
+ }
|
|
196
|
+
+ }
|
|
197
|
+
+ };
|
|
198
|
+
+
|
|
199
|
+
const update = () => {
|
|
200
|
+
if (!hoverEl && !pickedEl && pins.length === 0) {
|
|
201
|
+
if (overlay) {
|
|
202
|
+
@@ -313,6 +503,8 @@ export const ARTIFACT_INSPECT = String.raw`(send, standalone) => {
|
|
203
|
+
overlay = null;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
+ unwatchLayout();
|
|
207
|
+
+
|
|
208
|
+
return false;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
@@ -321,30 +513,7 @@ export const ARTIFACT_INSPECT = String.raw`(send, standalone) => {
|
|
212
|
+
place(shown.hover, hoverEl && hoverEl !== pickedEl ? hoverEl : null, true);
|
|
213
|
+
place(shown.picked, pickedEl, true);
|
|
214
|
+
|
|
215
|
+
- for (const pin of pins) {
|
|
216
|
+
- if (!pin.el || !pin.el.isConnected) {
|
|
217
|
+
- pin.el = findPinTarget(pin.target);
|
|
218
|
+
- }
|
|
219
|
+
-
|
|
220
|
+
- const rect = pin.el ? pin.el.getBoundingClientRect() : null;
|
|
221
|
+
- const visible = rect !== null && (rect.width > 0 || rect.height > 0);
|
|
222
|
+
-
|
|
223
|
+
- css(pin.node, {
|
|
224
|
+
- display: visible ? "flex" : "none",
|
|
225
|
+
- left: visible ? Math.min(Math.max(rect.left - 9, 2), win.innerWidth - 24) + "px" : "0",
|
|
226
|
+
- top: visible ? Math.min(Math.max(rect.top - 9, 2), win.innerHeight - 24) + "px" : "0",
|
|
227
|
+
- });
|
|
228
|
+
-
|
|
229
|
+
- if (pin.outline) {
|
|
230
|
+
- css(pin.outline, {
|
|
231
|
+
- display: visible ? "block" : "none",
|
|
232
|
+
- left: visible ? rect.left + "px" : "0",
|
|
233
|
+
- top: visible ? rect.top + "px" : "0",
|
|
234
|
+
- width: visible ? rect.width + "px" : "0",
|
|
235
|
+
- height: visible ? rect.height + "px" : "0",
|
|
236
|
+
- });
|
|
237
|
+
- }
|
|
238
|
+
- }
|
|
239
|
+
+ updatePins();
|
|
240
|
+
|
|
241
|
+
return true;
|
|
242
|
+
};
|
|
243
|
+
@@ -376,6 +545,7 @@ export const ARTIFACT_INSPECT = String.raw`(send, standalone) => {
|
|
244
|
+
|
|
245
|
+
const highlight = (targets) => {
|
|
246
|
+
pins = [];
|
|
247
|
+
+ unwatchLayout();
|
|
248
|
+
|
|
249
|
+
if (overlay) {
|
|
250
|
+
overlay.layer.replaceChildren();
|
|
251
|
+
@@ -394,6 +564,8 @@ export const ARTIFACT_INSPECT = String.raw`(send, standalone) => {
|
|
252
|
+
const text = typeof target.label === "string" || typeof target.label === "number" ? clip(target.label, 8) : String(index + 1);
|
|
253
|
+
const outline = css(doc.createElement("div"), {
|
|
254
|
+
position: "absolute",
|
|
255
|
+
+ left: "0",
|
|
256
|
+
+ top: "0",
|
|
257
|
+
display: "none",
|
|
258
|
+
"box-sizing": "border-box",
|
|
259
|
+
border: "1px solid " + ACCENT,
|
|
260
|
+
@@ -402,6 +574,8 @@ export const ARTIFACT_INSPECT = String.raw`(send, standalone) => {
|
|
261
|
+
});
|
|
262
|
+
const node = css(doc.createElement("div"), {
|
|
263
|
+
position: "absolute",
|
|
264
|
+
+ left: "0",
|
|
265
|
+
+ top: "0",
|
|
266
|
+
display: "none",
|
|
267
|
+
"align-items": "center",
|
|
268
|
+
"justify-content": "center",
|
|
269
|
+
@@ -414,12 +588,46 @@ export const ARTIFACT_INSPECT = String.raw`(send, standalone) => {
|
|
270
|
+
color: "#1a1b26",
|
|
271
|
+
font: "700 12px/1 system-ui, sans-serif",
|
|
272
|
+
"box-shadow": "0 1px 4px rgba(0,0,0,.45)",
|
|
273
|
+
+ "pointer-events": "auto",
|
|
274
|
+
+ cursor: "pointer",
|
|
275
|
+
+ });
|
|
276
|
+
+
|
|
277
|
+
+ // A tap on a pin is told to the app (it opens the finding): the page's own handlers get nothing from it.
|
|
278
|
+
+ node.addEventListener("click", (event) => {
|
|
279
|
+
+ event.stopPropagation();
|
|
280
|
+
+ send({ type: "pocket-pin", label: text, tap: true });
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
node.textContent = text;
|
|
284
|
+
shown.layer.append(outline, node);
|
|
285
|
+
- pins.push({ target: { selector: clip(target.selector, 500), pid: typeof target.pid === "string" ? clip(target.pid, 200) : "" }, el: null, node, outline });
|
|
286
|
+
+
|
|
287
|
+
+ const pin = { selector: clip(target.selector, 500), pid: typeof target.pid === "string" ? clip(target.pid, 200) : "" };
|
|
288
|
+
+
|
|
289
|
+
+ // w: the width the badge has (its words and its padding), for finding it a place before it is drawn.
|
|
290
|
+
+ pins.push({ target: pin, el: null, node, outline, w: Math.max(22, 12 + 8 * text.length), drawn: {} });
|
|
291
|
+
+
|
|
292
|
+
+ // One that is asked for comes into view (the app asks for the one that a person tapped in a list).
|
|
293
|
+
+ if (target.reveal === true) {
|
|
294
|
+
+ const el = findPinTarget(pin);
|
|
295
|
+
+
|
|
296
|
+
+ css(outline, { border: "2px solid " + ACCENT, opacity: "1" });
|
|
297
|
+
+ css(node, { "box-shadow": "0 0 0 2px #fff, 0 1px 6px rgba(0,0,0,.6)", "z-index": "1" });
|
|
298
|
+
+
|
|
299
|
+
+ if (el && typeof el.scrollIntoView === "function") {
|
|
300
|
+
+ el.scrollIntoView({ block: "center", inline: "nearest" });
|
|
301
|
+
+
|
|
302
|
+
+ // Where it is now, in the frame: the app, whose canvas may be bigger than its room, brings it into view too.
|
|
303
|
+
+ const at = el.getBoundingClientRect();
|
|
304
|
+
+
|
|
305
|
+
+ send({
|
|
306
|
+
+ type: "pocket-pin",
|
|
307
|
+
+ label: text,
|
|
308
|
+
+ rect: { x: at.left, y: at.top, width: at.width, height: at.height },
|
|
309
|
+
+ });
|
|
310
|
+
+ }
|
|
311
|
+
+ }
|
|
312
|
+
});
|
|
313
|
+
+ watchLayout();
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
paint();
|
|
317
|
+
@@ -872,6 +1080,11 @@ export const ARTIFACT_INSPECT = String.raw`(send, standalone) => {
|
|
318
|
+
const deckSheet = () => {
|
|
319
|
+
const { width, height } = deck.size;
|
|
320
|
+
const scale = Math.min(win.innerWidth / width, win.innerHeight / height) || 1;
|
|
321
|
+
+
|
|
322
|
+
+ // The window size this scale was made for: the watch below paints again when it is another (a frame that was
|
|
323
|
+
+ // not laid out when the deck started has no resize event to tell of its first size).
|
|
324
|
+
+ deck.fit = [win.innerWidth, win.innerHeight];
|
|
325
|
+
+
|
|
326
|
+
return (
|
|
327
|
+
"html,body{margin:0!important;padding:0!important;width:100%!important;height:100%!important;overflow:hidden!important}" +
|
|
328
|
+
(deck.bare ? "html{background:#000}" : "") +
|
|
329
|
+
@@ -1013,6 +1226,8 @@ export const ARTIFACT_INSPECT = String.raw`(send, standalone) => {
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
+ deck.watch?.disconnect();
|
|
334
|
+
+
|
|
335
|
+
for (const slide of deck.slides) {
|
|
336
|
+
slide.removeAttribute("data-pocket-current");
|
|
337
|
+
unshow(slide);
|
|
338
|
+
@@ -1067,6 +1282,8 @@ export const ARTIFACT_INSPECT = String.raw`(send, standalone) => {
|
|
339
|
+
view: null,
|
|
340
|
+
display: shown || "block",
|
|
341
|
+
shownInline: new Map(),
|
|
342
|
+
+ fit: [0, 0],
|
|
343
|
+
+ watch: null,
|
|
344
|
+
};
|
|
345
|
+
|
|
346
|
+
// A phone lays a page with no viewport out at 980 pixels wide: a deck needs the real width to fit it.
|
|
347
|
+
@@ -1088,6 +1305,17 @@ export const ARTIFACT_INSPECT = String.raw`(send, standalone) => {
|
|
348
|
+
|
|
349
|
+
deckEvents.add("keydown", onDeckKey);
|
|
350
|
+
deckEvents.add("resize", paintDeck);
|
|
351
|
+
+
|
|
352
|
+
+ // The page's root is as big as the window (the sheet says so): when the window gets its size after the
|
|
353
|
+
+ // deck started, with no resize event, the root changes size, and the slide is scaled for the new size.
|
|
354
|
+
+ if (typeof win.ResizeObserver === "function") {
|
|
355
|
+
+ deck.watch = new win.ResizeObserver(() => {
|
|
356
|
+
+ if (deck && (deck.fit[0] !== win.innerWidth || deck.fit[1] !== win.innerHeight)) {
|
|
357
|
+
+ paintDeck();
|
|
358
|
+
+ }
|
|
359
|
+
+ });
|
|
360
|
+
+ deck.watch.observe(doc.documentElement);
|
|
361
|
+
+ }
|
|
362
|
+
} else {
|
|
363
|
+
deck.slides = slides;
|
|
364
|
+
deck.index = Math.min(deck.index, slides.length - 1);
|
|
365
|
+
@@ -1128,6 +1356,84 @@ export const ARTIFACT_INSPECT = String.raw`(send, standalone) => {
|
|
366
|
+
}
|
|
367
|
+
};
|
|
368
|
+
|
|
369
|
+
+ // ---------------------------------------------------------------------------------------------------------------
|
|
370
|
+
+ // The height of the page's content, told to the app: a Check shortens a frame that has more room than its page.
|
|
371
|
+
+
|
|
372
|
+
+ const SIZE_SCAN = 1500;
|
|
373
|
+
+ let sizeWatch = null;
|
|
374
|
+
+ let sizeTimer = null;
|
|
375
|
+
+ let sizeSent = -1;
|
|
376
|
+
+
|
|
377
|
+
+ /** The lowest edge of anything on the page, or null when the page is too big to scan (the frame then keeps its room). */
|
|
378
|
+
+ const contentBottom = () => {
|
|
379
|
+
+ const body = doc.body;
|
|
380
|
+
+
|
|
381
|
+
+ if (!body) {
|
|
382
|
+
+ return null;
|
|
383
|
+
+ }
|
|
384
|
+
+
|
|
385
|
+
+ const all = body.querySelectorAll("*");
|
|
386
|
+
+
|
|
387
|
+
+ if (all.length > SIZE_SCAN) {
|
|
388
|
+
+ return null;
|
|
389
|
+
+ }
|
|
390
|
+
+
|
|
391
|
+
+ const scrolled = win.scrollY || 0;
|
|
392
|
+
+ let bottom = Math.max(doc.documentElement.getBoundingClientRect().bottom, body.getBoundingClientRect().bottom) + scrolled;
|
|
393
|
+
+
|
|
394
|
+
+ for (const el of all) {
|
|
395
|
+
+ if (el.localName !== "pocket-overlay") {
|
|
396
|
+
+ bottom = Math.max(bottom, el.getBoundingClientRect().bottom + scrolled);
|
|
397
|
+
+ }
|
|
398
|
+
+ }
|
|
399
|
+
+
|
|
400
|
+
+ return bottom;
|
|
401
|
+
+ };
|
|
402
|
+
+
|
|
403
|
+
+ const reportSize = () => {
|
|
404
|
+
+ sizeTimer = null;
|
|
405
|
+
+
|
|
406
|
+
+ const bottom = contentBottom();
|
|
407
|
+
+ const height = bottom === null ? 0 : Math.ceil(bottom);
|
|
408
|
+
+
|
|
409
|
+
+ if (Math.abs(height - sizeSent) >= 2) {
|
|
410
|
+
+ sizeSent = height;
|
|
411
|
+
+ send({ type: "pocket-size", height });
|
|
412
|
+
+ }
|
|
413
|
+
+ };
|
|
414
|
+
+
|
|
415
|
+
+ const sizeLater = () => {
|
|
416
|
+
+ if (sizeTimer === null) {
|
|
417
|
+
+ sizeTimer = later(reportSize, 150);
|
|
418
|
+
+ }
|
|
419
|
+
+ };
|
|
420
|
+
+
|
|
421
|
+
+ const watchSize = () => {
|
|
422
|
+
+ sizeSent = -1;
|
|
423
|
+
+ sizeLater();
|
|
424
|
+
+
|
|
425
|
+
+ if (sizeWatch === null && typeof win.ResizeObserver === "function") {
|
|
426
|
+
+ sizeWatch = new win.ResizeObserver(sizeLater);
|
|
427
|
+
+ sizeWatch.observe(doc.documentElement);
|
|
428
|
+
+
|
|
429
|
+
+ if (doc.body) {
|
|
430
|
+
+ sizeWatch.observe(doc.body);
|
|
431
|
+
+ }
|
|
432
|
+
+ }
|
|
433
|
+
+ };
|
|
434
|
+
+
|
|
435
|
+
+ const unwatchSize = () => {
|
|
436
|
+
+ if (sizeTimer !== null) {
|
|
437
|
+
+ unlater(sizeTimer);
|
|
438
|
+
+ sizeTimer = null;
|
|
439
|
+
+ }
|
|
440
|
+
+
|
|
441
|
+
+ if (sizeWatch !== null) {
|
|
442
|
+
+ sizeWatch.disconnect();
|
|
443
|
+
+ sizeWatch = null;
|
|
444
|
+
+ }
|
|
445
|
+
+ };
|
|
446
|
+
+
|
|
447
|
+
// What the app asked for, so a replaced document (a reply's HTML run again) can be given it again.
|
|
448
|
+
const desired = { inspect: false, edit: false, targets: [], tweaks: {} };
|
|
449
|
+
// The app may speak before the page is parsed (it says hello as the page starts): what needs the page waits.
|
|
450
|
+
@@ -1176,6 +1482,12 @@ export const ARTIFACT_INSPECT = String.raw`(send, standalone) => {
|
|
451
|
+
|
|
452
|
+
syncDeck();
|
|
453
|
+
start();
|
|
454
|
+
+
|
|
455
|
+
+ if (!standalone) {
|
|
456
|
+
+ watchSize();
|
|
457
|
+
+ addListener("load", sizeLater, { once: true });
|
|
458
|
+
+ }
|
|
459
|
+
+
|
|
460
|
+
ready = true;
|
|
461
|
+
|
|
462
|
+
for (const data of backlog.splice(0)) {
|
|
463
|
+
@@ -1241,6 +1553,8 @@ export const ARTIFACT_INSPECT = String.raw`(send, standalone) => {
|
|
464
|
+
hoverEl = null;
|
|
465
|
+
pickedEl = null;
|
|
466
|
+
pins = [];
|
|
467
|
+
+ unwatchLayout();
|
|
468
|
+
+ unwatchSize();
|
|
469
|
+
inspectOn = false;
|
|
470
|
+
editOn = false;
|
|
471
|
+
ready = false;
|
|
472
|
+
diff --git c/test/design-bridge-ui.test.ts w/test/design-bridge-ui.test.ts
|
|
473
|
+
index dcb3724..954a601 100644
|
|
474
|
+
--- c/test/design-bridge-ui.test.ts
|
|
475
|
+
+++ w/test/design-bridge-ui.test.ts
|
|
476
|
+
@@ -95,6 +95,29 @@ const DESIGN = `<!doctype html><html><head><meta charset="utf-8"><title>Design</
|
|
477
|
+
<script>document.getElementById("go").onclick = () => { window.clicked += 1; };</script>
|
|
478
|
+
${TEST_HOOKS}</body></html>`;
|
|
479
|
+
|
|
480
|
+
+/** A long page with a count of the hit tests that the bridge makes (a pin's place costs some): `pinwork` answers it. */
|
|
481
|
+
+const LONG = `<!doctype html><html><head><meta charset="utf-8"><title>Long</title>
|
|
482
|
+
+<style>body{font:16px/1.5 system-ui;margin:0}p{margin:0;padding:0 40px}</style></head>
|
|
483
|
+
+<body>${Array.from({ length: 160 }, (_, at) => `<p data-pid="p${at}">Row ${at}: boarding opens at nine, and the ferry leaves on the hour.</p>`).join("")}
|
|
484
|
+
+<script>
|
|
485
|
+
+window.hits = 0;
|
|
486
|
+
+const hitTest = document.elementsFromPoint.bind(document);
|
|
487
|
+
+document.elementsFromPoint = (x, y) => { window.hits += 1; return hitTest(x, y); };
|
|
488
|
+
+addEventListener("message", (event) => {
|
|
489
|
+
+ const data = event.data;
|
|
490
|
+
+ if (!data || data.type !== "pinwork" || typeof data.id !== "string") return;
|
|
491
|
+
+ if (data.reset) { window.hits = 0; }
|
|
492
|
+
+ if (data.scroll) { scrollBy(0, data.scroll); }
|
|
493
|
+
+ parent.postMessage({ id: data.id, hits: window.hits, scrollY: scrollY }, "*");
|
|
494
|
+
+});
|
|
495
|
+
+</script></body></html>`;
|
|
496
|
+
+
|
|
497
|
+
+/** A page with one element that has room around it, for a pin to sit above it: a tap on the pin, and where it is told to be. */
|
|
498
|
+
+const PINS = `<!doctype html><html><head><meta charset="utf-8"><title>Pins</title>
|
|
499
|
+
+<style>body{margin:0;height:1500px}#target{position:absolute;left:200px;top:700px;width:120px;height:40px;background:#cde}</style></head>
|
|
500
|
+
+<body><div id="target" data-pid="target">Target</div>
|
|
501
|
+
+${TEST_HOOKS}</body></html>`;
|
|
502
|
+
+
|
|
503
|
+
const DECK = `<!doctype html><html><head><meta charset="utf-8"><title>Deck</title><meta name="pocket-kind" content="deck">
|
|
504
|
+
<style>body{margin:8px}.slide{width:1920px;max-width:100%;min-width:10px;height:1080px;background:#123;color:#fff;font-size:80px}</style></head>
|
|
505
|
+
<body><section class="slide"><h1>One</h1></section><section class="slide"><h1>Two</h1></section><section class="slide"><h1>Three</h1></section>
|
|
506
|
+
@@ -257,6 +280,8 @@ before(async () => {
|
|
507
|
+
({ id: session } = await app.commands.createSession(owner(app), { cwd: work }));
|
|
508
|
+
await publish("design", DESIGN);
|
|
509
|
+
await publish("deck", DECK);
|
|
510
|
+
+ await publish("long", LONG);
|
|
511
|
+
+ await publish("pins", PINS);
|
|
512
|
+
await publish("intercept", INTERCEPT);
|
|
513
|
+
await publish("cspdeck", CSP_DECK);
|
|
514
|
+
await publish("csppage", CSP_PAGE);
|
|
515
|
+
@@ -599,6 +624,107 @@ test("pins show for a list of targets and clear on an empty list", real, async (
|
|
516
|
+
);
|
|
517
|
+
});
|
|
518
|
+
|
|
519
|
+
+test(
|
|
520
|
+
+ "pins are placed once, and a scroll or a quiet page does not look at the page again",
|
|
521
|
+
+ real,
|
|
522
|
+
+ async () => {
|
|
523
|
+
+ await openDesign("long");
|
|
524
|
+
+
|
|
525
|
+
+ const work = (extra: object = {}) =>
|
|
526
|
+
+ ask<{ hits: number; scrollY: number }>({ type: "pinwork", ...extra });
|
|
527
|
+
+
|
|
528
|
+
+ // A hundred pins on a long page: the ones in view get a place, the rest are only rectangles.
|
|
529
|
+
+ assert.equal(
|
|
530
|
+
+ await send({
|
|
531
|
+
+ type: "pocket-highlight",
|
|
532
|
+
+ targets: Array.from({ length: 100 }, (_, at) => ({
|
|
533
|
+
+ selector: `[data-pid="p${at}"]`,
|
|
534
|
+
+ label: at + 1,
|
|
535
|
+
+ })),
|
|
536
|
+
+ }),
|
|
537
|
+
+ true,
|
|
538
|
+
+ );
|
|
539
|
+
+ await settle();
|
|
540
|
+
+ await settle();
|
|
541
|
+
+ assert.ok((await work()).hits > 0, "the pins in view were given a place");
|
|
542
|
+
+
|
|
543
|
+
+ // Nothing changes: every frame reads rectangles, and none of them is a hit test.
|
|
544
|
+
+ const quiet = await work({ reset: true });
|
|
545
|
+
+
|
|
546
|
+
+ assert.equal(quiet.hits, 0);
|
|
547
|
+
+ await settle();
|
|
548
|
+
+ assert.equal((await work()).hits, 0, "a quiet page costs no hit tests");
|
|
549
|
+
+
|
|
550
|
+
+ // A scroll moves the page and the pins together: the places that were found stay.
|
|
551
|
+
+ const before = await work({ reset: true });
|
|
552
|
+
+
|
|
553
|
+
+ assert.equal(before.hits, 0);
|
|
554
|
+
+
|
|
555
|
+
+ await work({ scroll: 5 });
|
|
556
|
+
+ await settle();
|
|
557
|
+
+
|
|
558
|
+
+ const scrolled = await work();
|
|
559
|
+
+
|
|
560
|
+
+ assert.equal(scrolled.scrollY, 5);
|
|
561
|
+
+ assert.ok(
|
|
562
|
+
+ scrolled.hits <= 12,
|
|
563
|
+
+ "a small scroll finds a place only for the pins that reach the edge",
|
|
564
|
+
+ );
|
|
565
|
+
+
|
|
566
|
+
+ await send({ type: "pocket-highlight", targets: [] });
|
|
567
|
+
+ },
|
|
568
|
+
+);
|
|
569
|
+
+
|
|
570
|
+
+test(
|
|
571
|
+
+ "a tap on a pin is told to the app, and a pin asked to come into view says where its element is",
|
|
572
|
+
+ real,
|
|
573
|
+
+ async () => {
|
|
574
|
+
+ await openDesign("pins");
|
|
575
|
+
+ await send({ type: "pocket-highlight", targets: [{ selector: "#target", label: 7 }] });
|
|
576
|
+
+ await settle();
|
|
577
|
+
+ await settle();
|
|
578
|
+
+
|
|
579
|
+
+ // The page is scrolled to the top: the element is below the frame's fold, so bring it in first.
|
|
580
|
+
+ await send({
|
|
581
|
+
+ type: "pocket-highlight",
|
|
582
|
+
+ targets: [{ selector: "#target", label: 7, reveal: true }],
|
|
583
|
+
+ });
|
|
584
|
+
+ await until(
|
|
585
|
+
+ async () => (await gotOf("pocket-pin")).some((each) => each.rect !== undefined),
|
|
586
|
+
+ "where the element is",
|
|
587
|
+
+ SLOW,
|
|
588
|
+
+ );
|
|
589
|
+
+
|
|
590
|
+
+ const told = (await gotOf("pocket-pin")).find((each) => each.rect !== undefined)!;
|
|
591
|
+
+
|
|
592
|
+
+ assert.equal(told.label, "7");
|
|
593
|
+
+ // The page scrolled it to the middle of the frame (600 px high), and says where it is now.
|
|
594
|
+
+ assert.ok(Math.abs(told.rect.y + told.rect.height / 2 - 300) < 3, JSON.stringify(told));
|
|
595
|
+
+ assert.equal(told.rect.x, 200);
|
|
596
|
+
+ assert.equal(told.rect.width, 120);
|
|
597
|
+
+
|
|
598
|
+
+ // The pin sits above its element, outside it: a tap on the pin is a message, with no rectangle.
|
|
599
|
+
+ await settle();
|
|
600
|
+
+
|
|
601
|
+
+ const above = told.rect.y - 22 - 3;
|
|
602
|
+
+
|
|
603
|
+
+ await page.click({ x: told.rect.x + 11, y: above + 11 });
|
|
604
|
+
+ await until(
|
|
605
|
+
+ async () => (await gotOf("pocket-pin")).some((each) => each.tap === true),
|
|
606
|
+
+ "the tap",
|
|
607
|
+
+ SLOW,
|
|
608
|
+
+ );
|
|
609
|
+
+ assert.deepEqual(
|
|
610
|
+
+ (await gotOf("pocket-pin")).find((each) => each.tap === true),
|
|
611
|
+
+ { type: "pocket-pin", label: "7", tap: true },
|
|
612
|
+
+ );
|
|
613
|
+
+
|
|
614
|
+
+ // The page does not see the tap (the pin is not in its tree), and nothing else of the page changed.
|
|
615
|
+
+ assert.equal((await dump()).clicked, 0);
|
|
616
|
+
+ await send({ type: "pocket-highlight", targets: [] });
|
|
617
|
+
+ },
|
|
618
|
+
+);
|
|
619
|
+
+
|
|
620
|
+
test(
|
|
621
|
+
"a deck shows one slide at a time, scaled to fit, with keys, swipes, and goto",
|
|
622
|
+
real,
|
|
623
|
+
@@ -827,6 +953,26 @@ test("what a page says is checked for its shape and length", real, async () => {
|
|
624
|
+
assert.equal(await deck(1001, 0), null);
|
|
625
|
+
assert.equal(await deck("3", 0), null);
|
|
626
|
+
assert.equal(await deck(3, 0.5), null);
|
|
627
|
+
+
|
|
628
|
+
+ // A pin: a tap (no other field comes through), or where its element is (finite numbers); nothing else.
|
|
629
|
+
+ const pin = (body: object) =>
|
|
630
|
+
+ check(`bridge.checkPageMessage({ type: "pocket-pin", ...${JSON.stringify(body)} })`);
|
|
631
|
+
+
|
|
632
|
+
+ assert.deepEqual(await pin({ label: "7", tap: true, extra: 1 }), {
|
|
633
|
+
+ type: "pocket-pin",
|
|
634
|
+
+ label: "7",
|
|
635
|
+
+ tap: true,
|
|
636
|
+
+ });
|
|
637
|
+
+ assert.deepEqual(
|
|
638
|
+
+ await pin({ label: "7", rect: { x: 1, y: 2, width: 3, height: 4, more: 5 } }),
|
|
639
|
+
+ { type: "pocket-pin", label: "7", rect: { x: 1, y: 2, width: 3, height: 4 } },
|
|
640
|
+
+ );
|
|
641
|
+
+ assert.equal(await pin({ label: "7" }), null, "neither a tap nor a place");
|
|
642
|
+
+ assert.equal(await pin({ label: "toolongalabel", tap: true }), null);
|
|
643
|
+
+ assert.equal(await pin({ tap: true }), null);
|
|
644
|
+
+ assert.equal(await pin({ label: "7", rect: { x: "1", y: 2, width: 3, height: 4 } }), null);
|
|
645
|
+
+ assert.equal(await pin({ label: "7", rect: { x: 1, y: 2, width: 3 } }), null);
|
|
646
|
+
+ assert.equal(await pin({ label: "7", rect: { x: 1e9, y: 2, width: 3, height: 4 } }), null);
|
|
647
|
+
});
|
|
648
|
+
|
|
649
|
+
test("the app's own messages are checked before they go", real, async () => {
|
|
650
|
+
@@ -857,6 +1003,15 @@ test("the app's own messages are checked before they go", real, async () => {
|
|
651
|
+
).error,
|
|
652
|
+
);
|
|
653
|
+
assert.ok((await check({ type: "pocket-run", html: "<p>" })).error);
|
|
654
|
+
+ // A pin may ask to be brought into view (a finding tapped in a list); only a boolean says so.
|
|
655
|
+
+ assert.ok(
|
|
656
|
+
+ (await check({ type: "pocket-highlight", targets: [{ selector: "p", reveal: true }] }))
|
|
657
|
+
+ .message,
|
|
658
|
+
+ );
|
|
659
|
+
+ assert.ok(
|
|
660
|
+
+ (await check({ type: "pocket-highlight", targets: [{ selector: "p", reveal: "yes" }] }))
|
|
661
|
+
+ .error,
|
|
662
|
+
+ );
|
|
663
|
+
});
|
|
664
|
+
|
|
665
|
+
test(
|
|
666
|
+
diff --git c/web/artifact-bridge.js w/web/artifact-bridge.js
|
|
667
|
+
index 026f4c0..9856418 100644
|
|
668
|
+
--- c/web/artifact-bridge.js
|
|
669
|
+
+++ w/web/artifact-bridge.js
|
|
670
|
+
@@ -206,7 +206,7 @@ function checkKnob(raw) {
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
/**
|
|
674
|
+
- * What the frame's inspector said, as clean data the app may use, or null when it is not one of the four messages or
|
|
675
|
+
+ * What the frame's inspector said, as clean data the app may use, or null when it is not one of the messages or
|
|
676
|
+
* has the wrong shape. A new object is built from the known fields only, whatever else the message had.
|
|
677
|
+
*/
|
|
678
|
+
export function checkPageMessage(data) {
|
|
679
|
+
@@ -251,6 +251,33 @@ export function checkPageMessage(data) {
|
|
680
|
+
return { type: data.type, knobs };
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
+ case "pocket-pin": {
|
|
684
|
+
+ // A tap on a pin, or where the element of a pin was brought to (its rectangle in the frame).
|
|
685
|
+
+ const rect = data.rect;
|
|
686
|
+
+ const finite = (value) =>
|
|
687
|
+
+ typeof value === "number" && Number.isFinite(value) && Math.abs(value) < 1e6;
|
|
688
|
+
+
|
|
689
|
+
+ if (!isText(data.label, 8)) {
|
|
690
|
+
+ return null;
|
|
691
|
+
+ }
|
|
692
|
+
+
|
|
693
|
+
+ if (isRecord(rect)) {
|
|
694
|
+
+ return finite(rect.x) && finite(rect.y) && finite(rect.width) && finite(rect.height)
|
|
695
|
+
+ ? {
|
|
696
|
+
+ type: data.type,
|
|
697
|
+
+ label: data.label,
|
|
698
|
+
+ rect: { x: rect.x, y: rect.y, width: rect.width, height: rect.height },
|
|
699
|
+
+ }
|
|
700
|
+
+ : null;
|
|
701
|
+
+ }
|
|
702
|
+
+
|
|
703
|
+
+ return data.tap === true ? { type: data.type, label: data.label, tap: true } : null;
|
|
704
|
+
+ }
|
|
705
|
+
+
|
|
706
|
+
+ case "pocket-size":
|
|
707
|
+
+ // The height of the page's content, in the frame's pixels (0: the page was too big to measure).
|
|
708
|
+
+ return isCount(data.height, 100_000) ? { type: data.type, height: data.height } : null;
|
|
709
|
+
+
|
|
710
|
+
case "pocket-deck":
|
|
711
|
+
return isCount(data.slides, LIMITS.slides) &&
|
|
712
|
+
isCount(data.current, Math.max(data.slides - 1, 0))
|
|
713
|
+
@@ -323,6 +350,7 @@ export function checkAppMessage(raw) {
|
|
714
|
+
!isRecord(target) ||
|
|
715
|
+
!isText(target.selector, LIMITS.selector) ||
|
|
716
|
+
(target.pid !== undefined && !isText(target.pid, LIMITS.pid)) ||
|
|
717
|
+
+ (target.reveal !== undefined && typeof target.reveal !== "boolean") ||
|
|
718
|
+
!(
|
|
719
|
+
target.label === undefined ||
|
|
720
|
+
isText(target.label, 8) ||
|
|
721
|
+
@@ -342,6 +370,11 @@ export function checkAppMessage(raw) {
|
|
722
|
+
pin.label = target.label;
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
+ // Scroll this one into view in the page (a person tapped it in a list).
|
|
726
|
+
+ if (target.reveal === true) {
|
|
727
|
+
+ pin.reveal = true;
|
|
728
|
+
+ }
|
|
729
|
+
+
|
|
730
|
+
targets.push(pin);
|
|
731
|
+
}
|
|
732
|
+
|