@buffcore/app-shell 0.8.44 → 0.8.45

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.
@@ -1,4 +1,5 @@
1
1
  import { prototypeNavigation, prototypeStudioOrigin } from './home-bridge.js';
2
+ import { partAnswer, partAt, prototypePartAsk } from './home-part.js';
2
3
  import { prototypeShow } from './home-show.js';
3
4
  /** Strict, small request schema; no actions or credentials, only an echoed document challenge. */
4
5
  export function prototypeChallenge(event, expected) {
@@ -70,6 +71,12 @@ export function prototypeInbox() {
70
71
  next.reply?.(nonce);
71
72
  };
72
73
  channel.port1.onmessage = (event) => {
74
+ const ask = prototypePartAsk(event.data, next);
75
+ if (ask && next.nonce) {
76
+ const expected = { navigation: next.navigation, nonce: next.nonce };
77
+ next.port.postMessage(partAnswer(expected, ask, partAt(ask.x, ask.y)));
78
+ return;
79
+ }
73
80
  const choice = prototypeShow(event.data, next);
74
81
  if (choice)
75
82
  next.show?.(choice);
@@ -0,0 +1,49 @@
1
+ export type PrototypePartAsk = {
2
+ ask: number;
3
+ x: number;
4
+ y: number;
5
+ };
6
+ export type PrototypePart = {
7
+ name?: string;
8
+ box: {
9
+ x: number;
10
+ y: number;
11
+ w: number;
12
+ h: number;
13
+ };
14
+ };
15
+ type Point = {
16
+ x: number;
17
+ y: number;
18
+ };
19
+ /**
20
+ * How far the page and its tallest scroller (the box a screen's content scrolls in) are scrolled,
21
+ * so a picture of this screen can be scrolled the same way. The studio's picture finds the scroller
22
+ * by the same rule.
23
+ */
24
+ export declare function scrolled(page?: Document): {
25
+ page: Point;
26
+ inner: Point;
27
+ };
28
+ /** A name is one short line: a label longer than this is not a part's name. */
29
+ export declare const PART_NAME = 80;
30
+ /**
31
+ * One part ask, read strictly: it arrives only on this document's private port (the studio's end
32
+ * of the hello), names the current navigation and document nonce, and carries an ask number and a
33
+ * point in the page. It grants nothing: the app only reads which element is drawn there.
34
+ */
35
+ export declare function prototypePartAsk(data: unknown, expected: {
36
+ navigation: string;
37
+ nonce?: string;
38
+ }): PrototypePartAsk | undefined;
39
+ /** The nearest element at the point with a name, with its box; the element itself without one. */
40
+ export declare function partAt(x: number, y: number, page?: Document): PrototypePart | undefined;
41
+ /** The answer to one ask: the ask's number, the part's name and box, and how far it is scrolled. */
42
+ export declare function partAnswer(expected: {
43
+ navigation: string;
44
+ nonce: string;
45
+ }, ask: PrototypePartAsk, part: PrototypePart | undefined, scroll?: {
46
+ page: Point;
47
+ inner: Point;
48
+ }): string;
49
+ export {};
@@ -0,0 +1,100 @@
1
+ // The studio's marking asks which part of the app is at a point, to name a comment ("Comment on
2
+ // Price"). Development only, like the rest of the prototype home. The answer carries the part's
3
+ // name (its accessible label or test id), its box and the scroll, never the app's data.
4
+ /**
5
+ * How far the page and its tallest scroller (the box a screen's content scrolls in) are scrolled,
6
+ * so a picture of this screen can be scrolled the same way. The studio's picture finds the scroller
7
+ * by the same rule.
8
+ */
9
+ export function scrolled(page = document) {
10
+ const view = page.defaultView;
11
+ let inner;
12
+ let most = 0;
13
+ const all = page.body?.querySelectorAll('*') ?? [];
14
+ for (let i = 0; i < all.length && i < 20_000; i++) {
15
+ const el = all[i];
16
+ const room = el.scrollHeight - el.clientHeight;
17
+ if (room > most && /auto|scroll|overlay/.test(view?.getComputedStyle(el).overflowY ?? '')) {
18
+ most = room;
19
+ inner = el;
20
+ }
21
+ }
22
+ const whole = (value = 0) => Math.max(0, Math.round(value));
23
+ return {
24
+ page: { x: whole(view?.scrollX), y: whole(view?.scrollY) },
25
+ inner: { x: whole(inner?.scrollLeft), y: whole(inner?.scrollTop) },
26
+ };
27
+ }
28
+ const allowed = new Set(['type', 'version', 'navigation', 'document', 'ask', 'x', 'y']);
29
+ /** A name is one short line: a label longer than this is not a part's name. */
30
+ export const PART_NAME = 80;
31
+ const coordinate = (value) => typeof value === 'number' && Number.isFinite(value) && value >= 0 && value <= 100_000;
32
+ /**
33
+ * One part ask, read strictly: it arrives only on this document's private port (the studio's end
34
+ * of the hello), names the current navigation and document nonce, and carries an ask number and a
35
+ * point in the page. It grants nothing: the app only reads which element is drawn there.
36
+ */
37
+ export function prototypePartAsk(data, expected) {
38
+ if (typeof data !== 'string' || data.length > 512 || !expected.nonce)
39
+ return;
40
+ let value;
41
+ try {
42
+ value = JSON.parse(data);
43
+ }
44
+ catch {
45
+ return;
46
+ }
47
+ if (!value ||
48
+ typeof value !== 'object' ||
49
+ Array.isArray(value) ||
50
+ Object.keys(value).some((key) => !allowed.has(key)) ||
51
+ value.type !== 'ape:prototype:part' ||
52
+ value.version !== 2 ||
53
+ value.navigation !== expected.navigation ||
54
+ value.document !== expected.nonce)
55
+ return;
56
+ const { ask, x, y } = value;
57
+ if (typeof ask !== 'number' || !Number.isInteger(ask) || ask < 1 || ask > 1_000_000)
58
+ return;
59
+ if (!coordinate(x) || !coordinate(y))
60
+ return;
61
+ return { ask, x, y };
62
+ }
63
+ /** The part's own name: its accessible label, else its test id in words; else none. */
64
+ function nameOf(element) {
65
+ const label = element.getAttribute('aria-label') ?? '';
66
+ const id = element.getAttribute('data-testid') ?? '';
67
+ const words = (label || id.replace(/[-_.]+/g, ' ')).replace(/\s+/g, ' ').trim();
68
+ return words && words.length <= PART_NAME ? words : undefined;
69
+ }
70
+ /** The nearest element at the point with a name, with its box; the element itself without one. */
71
+ export function partAt(x, y, page = document) {
72
+ const hit = page.elementFromPoint(x, y);
73
+ if (!hit)
74
+ return;
75
+ let named = hit;
76
+ for (let depth = 0; named && depth < 12; depth++, named = named.parentElement) {
77
+ const name = nameOf(named);
78
+ if (name)
79
+ return { name, box: boxOf(named) };
80
+ }
81
+ return { box: boxOf(hit) };
82
+ }
83
+ function boxOf(element) {
84
+ const r = element.getBoundingClientRect();
85
+ const round = (value) => Math.max(0, Math.round(value));
86
+ return { x: round(r.left), y: round(r.top), w: round(r.width), h: round(r.height) };
87
+ }
88
+ /** The answer to one ask: the ask's number, the part's name and box, and how far it is scrolled. */
89
+ export function partAnswer(expected, ask, part, scroll = scrolled()) {
90
+ return JSON.stringify({
91
+ type: 'ape:prototype:spot',
92
+ version: 2,
93
+ navigation: expected.navigation,
94
+ document: expected.nonce,
95
+ ask: ask.ask,
96
+ ...(part?.name ? { name: part.name } : {}),
97
+ box: part?.box ?? { x: Math.round(ask.x), y: Math.round(ask.y), w: 0, h: 0 },
98
+ scroll,
99
+ });
100
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@buffcore/app-shell",
3
- "version": "0.8.44",
3
+ "version": "0.8.45",
4
4
  "description": "The Expo app shell for a BuffCore product: sign-in, settings, themes, live sessions and push.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "BuffApe",
@@ -33,12 +33,12 @@
33
33
  "dependencies": {
34
34
  "@noble/hashes": "2.4.0",
35
35
  "firebase": "12.19.0",
36
- "@buffcore/config": "0.8.44",
37
- "@buffcore/contracts": "0.8.44",
38
- "@buffcore/i18n": "0.8.44",
39
- "@buffcore/sdk": "0.8.44",
40
- "@buffcore/ui": "0.8.44",
41
- "@buffcore/tokens": "0.8.44"
36
+ "@buffcore/config": "0.8.45",
37
+ "@buffcore/tokens": "0.8.45",
38
+ "@buffcore/i18n": "0.8.45",
39
+ "@buffcore/contracts": "0.8.45",
40
+ "@buffcore/sdk": "0.8.45",
41
+ "@buffcore/ui": "0.8.45"
42
42
  },
43
43
  "peerDependencies": {
44
44
  "@react-native-firebase/app": ">=26",
@@ -116,8 +116,8 @@
116
116
  "react-native-web": "0.21.4",
117
117
  "react-native-webview": "13.16.1",
118
118
  "zod": "4.6.5",
119
- "@buffcore/modules": "0.8.44",
120
- "@buffcore/server": "0.8.44"
119
+ "@buffcore/server": "0.8.45",
120
+ "@buffcore/modules": "0.8.45"
121
121
  },
122
122
  "scripts": {
123
123
  "build": "node ../../scripts/build-package.mjs",