@tokenoftrust/storefront-runner 7.2.5 → 7.2.6
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tokenoftrust/storefront-runner",
|
|
3
|
-
"version": "7.2.
|
|
3
|
+
"version": "7.2.6",
|
|
4
4
|
"license": "SEE LICENSE IN LICENSE",
|
|
5
5
|
"description": "World-shareable storefront runner: multi-tenant renderer on Astro/Cloudflare. No control plane.",
|
|
6
6
|
"packageManager": "pnpm@11.9.0",
|
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The
|
|
3
|
-
*
|
|
2
|
+
* The preview cue. Mounts one quiet edge tab in its own isolated surface. Activating the tab expands
|
|
3
|
+
* it to a strip with "Give feedback" and "Hide"; "Hide" collapses it to a smaller nub for the browser
|
|
4
|
+
* session. `mount` and `unmount` are idempotent and never leave a stray element behind.
|
|
4
5
|
*/
|
|
5
6
|
import { isSurfacePermitted, type HostAdapter } from "./hostAdapter.js";
|
|
6
7
|
import { createSurface, h } from "./surface.js";
|
|
7
8
|
|
|
9
|
+
export const LAUNCHER_HIDDEN_KEY = "tot-preview-launcher-hidden";
|
|
10
|
+
|
|
8
11
|
export interface LauncherOptions {
|
|
9
12
|
win: Window;
|
|
10
13
|
doc: Document;
|
|
11
14
|
adapter?: HostAdapter;
|
|
12
15
|
label?: string;
|
|
13
16
|
ariaLabel?: string;
|
|
14
|
-
/** Called when
|
|
17
|
+
/** Called when "Give feedback" is activated (click, Enter or Space). */
|
|
15
18
|
onActivate(): void;
|
|
16
19
|
}
|
|
17
20
|
|
|
@@ -20,62 +23,178 @@ export interface Launcher {
|
|
|
20
23
|
mount(): boolean;
|
|
21
24
|
unmount(): void;
|
|
22
25
|
readonly isMounted: boolean;
|
|
23
|
-
/** The
|
|
26
|
+
/** The always-present edge tab (or nub); the focus anchor. Activating it toggles the strip. */
|
|
24
27
|
readonly button: HTMLButtonElement;
|
|
28
|
+
/** "Give feedback" inside the expanded strip. */
|
|
29
|
+
readonly actionButton: HTMLButtonElement;
|
|
30
|
+
/** "Hide" inside the expanded strip. */
|
|
31
|
+
readonly hideButton: HTMLButtonElement;
|
|
25
32
|
/** The element placed in the page. */
|
|
26
33
|
readonly host: HTMLElement;
|
|
27
34
|
setLabel(label: string): void;
|
|
28
|
-
/** Reflect whether the dialog it controls is open (`aria-expanded`). */
|
|
35
|
+
/** Reflect whether the dialog it controls is open (`aria-expanded` on the action). */
|
|
29
36
|
setExpanded(expanded: boolean): void;
|
|
30
37
|
/** Show or hide a small attention dot. */
|
|
31
38
|
setBadge(on: boolean): void;
|
|
39
|
+
/** Hide the whole cue (while the page is being picked, say). */
|
|
40
|
+
setSuppressed(suppressed: boolean): void;
|
|
41
|
+
readonly isStripOpen: boolean;
|
|
42
|
+
readonly isNub: boolean;
|
|
43
|
+
openStrip(): void;
|
|
44
|
+
closeStrip(): void;
|
|
32
45
|
focus(): void;
|
|
33
46
|
}
|
|
34
47
|
|
|
48
|
+
function readHidden(win: Window): boolean {
|
|
49
|
+
try {
|
|
50
|
+
return win.sessionStorage.getItem(LAUNCHER_HIDDEN_KEY) === "1";
|
|
51
|
+
} catch {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function writeHidden(win: Window, hidden: boolean): boolean {
|
|
57
|
+
try {
|
|
58
|
+
if (hidden) win.sessionStorage.setItem(LAUNCHER_HIDDEN_KEY, "1");
|
|
59
|
+
else win.sessionStorage.removeItem(LAUNCHER_HIDDEN_KEY);
|
|
60
|
+
return true;
|
|
61
|
+
} catch {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
35
66
|
export function createLauncher(options: LauncherOptions): Launcher {
|
|
36
67
|
const { win, doc, adapter } = options;
|
|
37
68
|
const surface = createSurface({ win, doc, adapter, tag: "feedback-launcher" });
|
|
69
|
+
const baseLabel = options.label ?? "ToT preview";
|
|
70
|
+
const detail = options.ariaLabel ?? "Token of Trust preview — feedback options";
|
|
71
|
+
let label = baseLabel;
|
|
72
|
+
let stripOpen = false;
|
|
73
|
+
let nub = readHidden(win);
|
|
74
|
+
let suppressed = false;
|
|
75
|
+
|
|
76
|
+
const wrap = h(doc, "div", { class: "cue" });
|
|
38
77
|
const button = h(doc, "button", {
|
|
39
78
|
class: "fab",
|
|
40
79
|
type: "button",
|
|
41
|
-
"aria-haspopup": "
|
|
80
|
+
"aria-haspopup": "true",
|
|
42
81
|
"aria-expanded": "false",
|
|
43
|
-
...(options.ariaLabel ? { "aria-label": options.ariaLabel } : {}),
|
|
44
82
|
});
|
|
45
|
-
const labelEl = h(doc, "span", {
|
|
83
|
+
const labelEl = h(doc, "span", { class: "tab-label", text: baseLabel });
|
|
46
84
|
const dot = h(doc, "span", { class: "dot", "aria-hidden": "true", hidden: true });
|
|
47
85
|
button.append(labelEl, dot);
|
|
48
|
-
|
|
86
|
+
|
|
87
|
+
const strip = h(doc, "div", { class: "strip", role: "group", "aria-label": "Token of Trust preview", hidden: true });
|
|
88
|
+
const title = h(doc, "span", { class: "strip-title", text: "Token of Trust preview" });
|
|
89
|
+
const actionButton = h(doc, "button", { class: "strip-act", type: "button", "aria-haspopup": "dialog", "aria-expanded": "false", text: "Give feedback" });
|
|
90
|
+
const hideButton = h(doc, "button", { class: "strip-hide", type: "button", text: "Hide" });
|
|
91
|
+
strip.append(title, actionButton, hideButton);
|
|
92
|
+
wrap.append(button, strip);
|
|
93
|
+
surface.root.append(wrap);
|
|
94
|
+
|
|
95
|
+
function render() {
|
|
96
|
+
wrap.hidden = suppressed;
|
|
97
|
+
wrap.dataset.nub = String(nub && !stripOpen);
|
|
98
|
+
strip.hidden = !stripOpen;
|
|
99
|
+
button.hidden = stripOpen;
|
|
100
|
+
button.setAttribute("aria-expanded", String(stripOpen));
|
|
101
|
+
const name = nub && !stripOpen ? `Show ${detail}` : `${label} — ${detail}`;
|
|
102
|
+
button.setAttribute("aria-label", name);
|
|
103
|
+
labelEl.hidden = nub && !stripOpen;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function openStrip() {
|
|
107
|
+
stripOpen = true;
|
|
108
|
+
render();
|
|
109
|
+
actionButton.focus();
|
|
110
|
+
}
|
|
111
|
+
function closeStrip(restoreFocus = true) {
|
|
112
|
+
if (!stripOpen) return;
|
|
113
|
+
stripOpen = false;
|
|
114
|
+
render();
|
|
115
|
+
if (restoreFocus) button.focus();
|
|
116
|
+
}
|
|
117
|
+
|
|
49
118
|
button.addEventListener("click", (e) => {
|
|
50
119
|
e.preventDefault();
|
|
120
|
+
if (stripOpen) closeStrip();
|
|
121
|
+
else openStrip();
|
|
122
|
+
});
|
|
123
|
+
actionButton.addEventListener("click", (e) => {
|
|
124
|
+
e.preventDefault();
|
|
125
|
+
closeStrip(false);
|
|
51
126
|
options.onActivate();
|
|
52
127
|
});
|
|
128
|
+
hideButton.addEventListener("click", (e) => {
|
|
129
|
+
e.preventDefault();
|
|
130
|
+
nub = writeHidden(win, true);
|
|
131
|
+
closeStrip();
|
|
132
|
+
});
|
|
133
|
+
// A nub restores to the full tab when tapped; the tap on a nub also opens the strip.
|
|
134
|
+
button.addEventListener("click", () => {
|
|
135
|
+
if (nub && stripOpen) {
|
|
136
|
+
nub = false;
|
|
137
|
+
writeHidden(win, false);
|
|
138
|
+
render();
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
const onKey = (e: Event) => {
|
|
142
|
+
if ((e as KeyboardEvent).key === "Escape" && stripOpen) {
|
|
143
|
+
e.stopPropagation();
|
|
144
|
+
closeStrip();
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
surface.root.addEventListener("keydown", onKey);
|
|
148
|
+
const onOutside = (e: Event) => {
|
|
149
|
+
if (stripOpen && !e.composedPath().includes(surface.host)) closeStrip(false);
|
|
150
|
+
};
|
|
151
|
+
render();
|
|
53
152
|
|
|
54
153
|
return {
|
|
55
154
|
mount() {
|
|
56
155
|
if (!isSurfacePermitted(adapter, "launcher")) return false;
|
|
57
156
|
surface.attach();
|
|
157
|
+
doc.addEventListener("pointerdown", onOutside, true);
|
|
58
158
|
return true;
|
|
59
159
|
},
|
|
60
160
|
unmount() {
|
|
161
|
+
doc.removeEventListener("pointerdown", onOutside, true);
|
|
61
162
|
surface.detach();
|
|
62
163
|
},
|
|
63
164
|
get isMounted() {
|
|
64
165
|
return surface.isAttached;
|
|
65
166
|
},
|
|
66
167
|
button,
|
|
168
|
+
actionButton,
|
|
169
|
+
hideButton,
|
|
67
170
|
host: surface.host,
|
|
68
|
-
setLabel(
|
|
69
|
-
|
|
171
|
+
setLabel(next) {
|
|
172
|
+
label = next;
|
|
173
|
+
labelEl.textContent = next;
|
|
174
|
+
render();
|
|
70
175
|
},
|
|
71
176
|
setExpanded(expanded) {
|
|
72
|
-
|
|
177
|
+
actionButton.setAttribute("aria-expanded", String(expanded));
|
|
73
178
|
},
|
|
74
179
|
setBadge(on) {
|
|
75
180
|
dot.hidden = !on;
|
|
76
181
|
},
|
|
182
|
+
setSuppressed(next) {
|
|
183
|
+
suppressed = next;
|
|
184
|
+
if (next) stripOpen = false;
|
|
185
|
+
render();
|
|
186
|
+
},
|
|
187
|
+
get isStripOpen() {
|
|
188
|
+
return stripOpen;
|
|
189
|
+
},
|
|
190
|
+
get isNub() {
|
|
191
|
+
return nub && !stripOpen;
|
|
192
|
+
},
|
|
193
|
+
openStrip,
|
|
194
|
+
closeStrip: () => closeStrip(),
|
|
77
195
|
focus() {
|
|
78
|
-
|
|
196
|
+
if (stripOpen) actionButton.focus();
|
|
197
|
+
else button.focus();
|
|
79
198
|
},
|
|
80
199
|
};
|
|
81
200
|
}
|
|
@@ -15,14 +15,27 @@ button.primary { background: var(--fb-acc); border-color: var(--fb-acc); color:
|
|
|
15
15
|
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, [tabindex]:focus-visible {
|
|
16
16
|
outline: 3px solid var(--fb-acc); outline-offset: 2px; }
|
|
17
17
|
button[disabled] { opacity: .55; cursor: not-allowed; }
|
|
18
|
-
.
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
.cue { position: fixed; right: 12px; bottom: 0; z-index: var(--fb-z); pointer-events: auto; display: flex; align-items: flex-end; }
|
|
19
|
+
.fab { background: #f3f4f6; color: #4b5563; border: 1px solid #d1d5db; border-bottom: 0; border-radius: 8px 8px 0 0; padding: 0 10px;
|
|
20
|
+
min-height: 22px; height: 22px; font-size: 11px; line-height: 20px; font-weight: 500; opacity: .6; box-shadow: none; position: relative;
|
|
21
|
+
transition: opacity .15s; }
|
|
22
|
+
.fab:hover, .fab:focus-visible { opacity: 1; color: #111827; }
|
|
23
|
+
.fab .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #d97706; margin-left: 6px; vertical-align: middle; }
|
|
24
|
+
.cue[data-nub="true"] .fab { padding: 0; width: 28px; min-height: 8px; height: 8px; border-radius: 6px 6px 0 0; }
|
|
25
|
+
.cue[data-nub="true"] .fab .dot { position: absolute; top: -3px; right: -3px; margin: 0; }
|
|
26
|
+
.strip { display: flex; align-items: center; gap: 4px 8px; background: #111827; color: #f9fafb; border-radius: 10px 10px 0 0; padding: 4px 10px;
|
|
27
|
+
font-size: 13px; line-height: 20px; max-width: calc(100vw - 24px); }
|
|
28
|
+
.strip button { min-height: 28px; padding: 2px 10px; font-size: 13px; border-radius: 6px; }
|
|
29
|
+
.strip .strip-act { background: #4f46e5; border-color: #4f46e5; color: #fff; font-weight: 600; }
|
|
30
|
+
.strip .strip-hide { background: transparent; border-color: #6b7280; color: #e5e7eb; }
|
|
31
|
+
.strip button:focus-visible { outline: 3px solid #fbbf24; outline-offset: 2px; }
|
|
32
|
+
.fab:focus-visible { outline-offset: 0; }
|
|
22
33
|
.dialog { position: fixed; right: 16px; top: 16px; z-index: calc(var(--fb-z) + 1); pointer-events: auto; width: 360px;
|
|
23
34
|
max-width: calc(100vw - 16px); max-height: calc(100vh - 16px); overflow: auto; background: var(--fb-bg);
|
|
24
35
|
border: 1px solid var(--fb-line); border-radius: 12px; box-shadow: 0 16px 40px rgba(17,24,39,.28); }
|
|
25
36
|
@media (max-width: 600px) {
|
|
37
|
+
.strip { flex-wrap: wrap; }
|
|
38
|
+
.strip-title { flex-basis: 100%; font-size: 12px; line-height: 16px; }
|
|
26
39
|
.dialog { left: 0; right: 0; top: auto; bottom: 0; width: 100%; max-width: 100%; max-height: 85vh; border-radius: 14px 14px 0 0; }
|
|
27
40
|
}
|
|
28
41
|
.titlebar { display: flex; align-items: center; gap: 4px; padding: 8px 10px; border-bottom: 1px solid var(--fb-line); }
|
|
@@ -65,13 +65,13 @@
|
|
|
65
65
|
.tour-launcher {
|
|
66
66
|
position: fixed;
|
|
67
67
|
right: 16px;
|
|
68
|
-
bottom: 16px;
|
|
68
|
+
bottom: calc(16px + var(--tot-preview-edge-clearance, 0px));
|
|
69
69
|
display: flex;
|
|
70
70
|
flex-direction: column;
|
|
71
71
|
align-items: flex-end;
|
|
72
72
|
gap: 8px;
|
|
73
73
|
max-width: calc(100vw - 32px);
|
|
74
|
-
max-height: calc(100vh - 32px);
|
|
74
|
+
max-height: calc(100vh - 32px - var(--tot-preview-edge-clearance, 0px));
|
|
75
75
|
overflow: auto;
|
|
76
76
|
pointer-events: auto;
|
|
77
77
|
}
|