stage-browser 0.0.0-stage → 0.1.0

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/src/ui/mock.js ADDED
@@ -0,0 +1,455 @@
1
+ /* Mock window.stage for previewing the UI in a plain browser. Loaded by app.js only when
2
+ window.stage is undefined (i.e. never inside Electron).
3
+
4
+ URL params:
5
+ scene bar | single | many | loading | pinned | omnibox | omnibox-edit | newtab
6
+ theme dark | light (sets <html data-theme>)
7
+ backdrop light | dark | 1 (paints a fake web page behind the transparent UI)
8
+ anim 0 (disable transitions/animations, for deterministic screenshots)
9
+ visible 0 (start with the bar hidden)
10
+ selfcheck main | many (run in-page interaction checks; results in #selfcheck)
11
+ */
12
+ (function () {
13
+ 'use strict';
14
+ var params = new URLSearchParams(location.search);
15
+ var scene = params.get('scene') || 'bar';
16
+ var root = document.documentElement;
17
+ if (params.get('theme')) root.dataset.theme = params.get('theme');
18
+
19
+ /* ---------- fake favicons (no network) ---------- */
20
+
21
+ function fav(letter, bg, shape) {
22
+ var inner = shape === 'circle'
23
+ ? '<circle cx="8" cy="8" r="8" fill="' + bg + '"/>'
24
+ : '<rect width="16" height="16" rx="4" fill="' + bg + '"/>';
25
+ var svg = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16">' + inner +
26
+ '<text x="8" y="11.6" font-family="-apple-system,Helvetica,Arial" font-size="10" font-weight="700" text-anchor="middle" fill="#fff">' + letter + '</text></svg>';
27
+ return 'data:image/svg+xml,' + encodeURIComponent(svg);
28
+ }
29
+
30
+ var POOL = [
31
+ { title: 'Workflow editor — Northwind', url: 'https://northwind.example/editor/2481', favicon: fav('N', '#2e6b5b') },
32
+ { title: 'Pull request #482 · acme/stage', url: 'https://github.com/acme/stage/pull/482', favicon: fav('G', '#24292f', 'circle') },
33
+ { title: 'Quarterly roadmap', url: 'https://notion.example.com/roadmap', favicon: null },
34
+ { title: 'Design review — homepage v3', url: 'https://figma.example.com/file/abc', favicon: fav('F', '#7c3aed') },
35
+ { title: 'Inbox (12)', url: 'https://mail.example.com/inbox', favicon: fav('M', '#2563eb') },
36
+ { title: 'A very long page title that will certainly need to be truncated at the edge of the tab', url: 'https://docs.example.org/guides/long', favicon: null },
37
+ { title: 'Webinar recording — lo-fi beats', url: 'https://music.example.com/live', favicon: fav('♪', '#db2777', 'circle'), audible: true },
38
+ { title: 'Analytics — Overview', url: 'https://analytics.example.net/overview', favicon: null },
39
+ { title: 'Customer interviews', url: 'https://sheets.example.com/d/1x', favicon: fav('S', '#16a34a') },
40
+ { title: 'Staging — dashboard', url: 'https://staging.acme.dev/', favicon: null }
41
+ ];
42
+
43
+ var HISTORY = [
44
+ { title: 'Northwind: Onboarding, automated', url: 'https://northwind.example/', favicon: fav('N', '#2e6b5b') },
45
+ { title: 'Workflows — Northwind', url: 'https://northwind.example/app/workflows', favicon: fav('N', '#2e6b5b') },
46
+ { title: 'Northwind docs', url: 'https://docs.northwind.example/', favicon: fav('N', '#2e6b5b') },
47
+ { title: 'Electron — Build cross-platform apps', url: 'https://www.electronjs.org/', favicon: fav('E', '#2f3241', 'circle') },
48
+ { title: 'Example Domain', url: 'https://example.com/', favicon: null },
49
+ { title: 'Hacker News', url: 'https://news.ycombinator.com/', favicon: fav('Y', '#f26522') },
50
+ { title: 'MDN Web Docs', url: 'https://developer.mozilla.org/', favicon: fav('M', '#111827') },
51
+ { title: 'Calendar — this week', url: 'https://calendar.example.com/week', favicon: fav('C', '#0ea5e9') }
52
+ ];
53
+
54
+ var nextId = 100;
55
+ function mk(p, extra) {
56
+ var t = { id: nextId++, title: p.title, url: p.url, favicon: p.favicon || null, loading: false, audible: !!p.audible, muted: false };
57
+ for (var k in extra) t[k] = extra[k];
58
+ return t;
59
+ }
60
+ function blank() { return { id: nextId++, title: 'New Tab', url: '', favicon: null, loading: false, audible: false, muted: false }; }
61
+
62
+ /* ---------- scenes ---------- */
63
+
64
+ var st = {
65
+ tabs: [], activeTabId: null, canGoBack: true, canGoForward: false, zoomFactor: 1,
66
+ bar: { visible: params.get('visible') !== '0', pinned: false },
67
+ overlay: null, barHeight: 52, fullscreen: false
68
+ };
69
+
70
+ function pick(n, skipAudible) {
71
+ var out = [];
72
+ for (var i = 0; i < n; i++) {
73
+ var p = POOL[i % POOL.length];
74
+ var t = mk(i < POOL.length ? p : { title: p.title.slice(0, 22) + ' ' + (Math.floor(i / POOL.length) + 1), url: p.url + '?p=' + i, favicon: p.favicon });
75
+ if (skipAudible) t.audible = false;
76
+ out.push(t);
77
+ }
78
+ return out;
79
+ }
80
+
81
+ switch (scene) {
82
+ case 'single':
83
+ st.tabs = pick(1, true); break;
84
+ case 'newtab':
85
+ st.tabs = [blank()]; break;
86
+ case 'many':
87
+ st.tabs = pick(18, true); st.tabs[6].audible = true; break;
88
+ case 'loading':
89
+ st.tabs = pick(6);
90
+ st.tabs[0].loading = true; st.tabs[0].favicon = null;
91
+ st.tabs[3].loading = true;
92
+ st.tabs[5].audible = false;
93
+ st.tabs[6 % 6].audible = false;
94
+ st.tabs[4].audible = true; st.tabs[4].muted = true;
95
+ st.tabs.push(mk(POOL[6]));
96
+ break;
97
+ case 'pinned':
98
+ st.tabs = pick(5, true); st.bar.pinned = true; break;
99
+ default:
100
+ st.tabs = pick(5, true); st.tabs.push(blank());
101
+ }
102
+ var activeIdx = { many: 6, loading: 0, single: 0, newtab: 0, pinned: 1 }[scene];
103
+ st.activeTabId = st.tabs[activeIdx == null ? 1 : activeIdx].id;
104
+ if (scene === 'omnibox') st.overlay = { type: 'omnibox', mode: 'new', initial: 'zap' };
105
+ if (scene === 'omnibox-edit') st.overlay = { type: 'omnibox', mode: 'edit', initial: st.tabs[1].url };
106
+
107
+ /* ---------- the API ---------- */
108
+
109
+ var listeners = [];
110
+ var calls = [];
111
+ function log(name, args) { calls.push([name].concat(args || [])); }
112
+ function snapshot() { return JSON.parse(JSON.stringify(st)); }
113
+ function emit() { var s = snapshot(); listeners.slice().forEach(function (cb) { cb(s); }); }
114
+ function indexOf(id) { for (var i = 0; i < st.tabs.length; i++) if (st.tabs[i].id === id) return i; return -1; }
115
+ function activeTab() { return st.tabs[indexOf(st.activeTabId)]; }
116
+
117
+ function looksLikeUrl(v) { return !/\s/.test(v) && (/^[a-z]+:\/\//i.test(v) || /^[^\s/]+\.[a-z]{2,}(\/|$)/i.test(v)); }
118
+ function normalize(v) { return /^[a-z]+:\/\//i.test(v) ? v : 'https://' + v; }
119
+ function hostOf(u) { try { return new URL(u).hostname.replace(/^www\./, ''); } catch (e) { return u; } }
120
+
121
+ function makeSuggestions(q) {
122
+ q = q.trim();
123
+ var lq = q.toLowerCase(), out = [];
124
+ if (q) {
125
+ out.push(looksLikeUrl(q)
126
+ ? { kind: 'url', title: q, url: normalize(q) }
127
+ : { kind: 'search', title: 'Search Google for “' + q + '”', url: 'https://www.google.com/search?q=' + encodeURIComponent(q) });
128
+ }
129
+ st.tabs.forEach(function (t) {
130
+ if (t.id === st.activeTabId && !q) return;
131
+ if (!t.url) return;
132
+ if (!q || t.title.toLowerCase().indexOf(lq) >= 0 || t.url.toLowerCase().indexOf(lq) >= 0)
133
+ out.push({ kind: 'tab', title: t.title, url: t.url, tabId: t.id, favicon: t.favicon });
134
+ });
135
+ HISTORY.forEach(function (h) {
136
+ if (!q || h.title.toLowerCase().indexOf(lq) >= 0 || h.url.toLowerCase().indexOf(lq) >= 0)
137
+ out.push({ kind: 'history', title: h.title, url: h.url, favicon: h.favicon });
138
+ });
139
+ return out.slice(0, 8);
140
+ }
141
+
142
+ window.stage = {
143
+ getState: function () { return Promise.resolve(snapshot()); },
144
+ onState: function (cb) {
145
+ listeners.push(cb);
146
+ return function () { listeners = listeners.filter(function (l) { return l !== cb; }); };
147
+ },
148
+ activateTab: function (id) { log('activateTab', [id]); st.activeTabId = id; emit(); },
149
+ closeTab: function (id) {
150
+ log('closeTab', [id]);
151
+ var i = indexOf(id);
152
+ if (i < 0) return;
153
+ st.tabs.splice(i, 1);
154
+ if (!st.tabs.length) { var b = blank(); st.tabs.push(b); st.activeTabId = b.id; }
155
+ else if (st.activeTabId === id) st.activeTabId = st.tabs[Math.min(i, st.tabs.length - 1)].id;
156
+ emit();
157
+ },
158
+ moveTab: function (id, to) {
159
+ log('moveTab', [id, to]);
160
+ var i = indexOf(id);
161
+ if (i < 0) return;
162
+ var t = st.tabs.splice(i, 1)[0];
163
+ st.tabs.splice(to, 0, t);
164
+ emit();
165
+ },
166
+ showTabMenu: function (id) { log('showTabMenu', [id]); },
167
+ openOmnibox: function (mode) {
168
+ log('openOmnibox', [mode]);
169
+ var t = activeTab();
170
+ st.overlay = { type: 'omnibox', mode: mode, initial: mode === 'edit' && t ? t.url : '' };
171
+ emit();
172
+ },
173
+ closeOverlay: function () { log('closeOverlay'); st.overlay = null; emit(); },
174
+ suggest: function (q) {
175
+ log('suggest', [q]);
176
+ return new Promise(function (res) {
177
+ setTimeout(function () { res(makeSuggestions(q)); }, q === 'sl' ? 160 : 20);
178
+ });
179
+ },
180
+ submitOmnibox: function (input, opts) {
181
+ log('submitOmnibox', [input, !!(opts && opts.newTab)]);
182
+ var url = looksLikeUrl(input) ? normalize(input) : input;
183
+ var title = hostOf(url);
184
+ if (opts && opts.newTab) {
185
+ var t = mk({ title: title, url: url });
186
+ st.tabs.push(t); st.activeTabId = t.id;
187
+ } else {
188
+ var a = activeTab();
189
+ if (a) { a.url = url; a.title = title; a.favicon = null; }
190
+ }
191
+ st.overlay = null;
192
+ emit();
193
+ },
194
+ back: function () { log('back'); },
195
+ forward: function () { log('forward'); },
196
+ reload: function () { log('reload'); },
197
+ setPinned: function (p) { log('setPinned', [p]); st.bar.pinned = !!p; emit(); },
198
+ setBarHover: function (h) { log('setBarHover', [h]); }
199
+ };
200
+ window.__stageMock = { calls: calls, state: st, emit: emit };
201
+
202
+ /* ---------- fake page behind the transparent UI ---------- */
203
+
204
+ var bd = params.get('backdrop');
205
+ var mockCss = document.createElement('style');
206
+ mockCss.textContent =
207
+ 'browser-action-list{display:flex}' +
208
+ '.mock-action{width:24px;height:24px;margin:0 2px;border-radius:6px;display:grid;place-items:center;-webkit-app-region:no-drag}' +
209
+ '.mock-action:hover{background:var(--hover)}' +
210
+ '.mock-action i{width:16px;height:16px;border-radius:5px;background:linear-gradient(135deg,#8b5cf6,#6366f1);display:grid;place-items:center}' +
211
+ '.mock-action svg{width:10px;height:10px}' +
212
+ '#mock-page{position:fixed;inset:0;z-index:-1;overflow:hidden;font:15px/1.5 -apple-system,system-ui,sans-serif;-webkit-user-select:none}' +
213
+ '#mock-page.light{background:#fff;color:#1a1a1a}#mock-page.dark{background:#0d1117;color:#e6edf3}' +
214
+ '#mock-page nav{height:64px;display:flex;align-items:center;gap:28px;padding:0 32px;border-bottom:1px solid rgb(128 128 128/.2)}' +
215
+ '#mock-page .logo{width:28px;height:28px;border-radius:8px;background:#ff4f00}' +
216
+ '#mock-page.dark .logo{background:#2f81f7}' +
217
+ '#mock-page nav b{font-weight:600}#mock-page nav span{opacity:.65;font-size:14px}' +
218
+ '#mock-page nav .cta{margin-left:auto;padding:8px 16px;border-radius:8px;background:#ff4f00;color:#fff;font-weight:600;font-size:14px;opacity:1}' +
219
+ '#mock-page.dark nav .cta{background:#238636}' +
220
+ '#mock-page main{max-width:880px;margin:0 auto;padding:56px 32px}' +
221
+ '#mock-page h1{font-size:44px;line-height:1.1;margin:0 0 16px;letter-spacing:-.03em}' +
222
+ '#mock-page p{margin:0 0 12px;opacity:.72;max-width:640px}' +
223
+ '#mock-page .cards{display:grid;grid-template-columns:repeat(3,1fr);gap:16px;margin-top:32px}' +
224
+ '#mock-page .card{border:1px solid rgb(128 128 128/.25);border-radius:12px;padding:16px;height:120px}' +
225
+ '#mock-page .card i{display:block;height:8px;border-radius:4px;background:rgb(128 128 128/.28);margin-bottom:8px}' +
226
+ '#mock-page pre{margin:24px 0 0;padding:16px;border-radius:10px;background:rgb(128 128 128/.12);font:13px/1.6 ui-monospace,Menlo,monospace;overflow:hidden}';
227
+ if (params.get('anim') === '0') mockCss.textContent += '*,*::before,*::after{transition:none!important;animation:none!important}';
228
+ document.head.appendChild(mockCss);
229
+
230
+ if (bd) {
231
+ var kind = bd === 'dark' ? 'dark' : 'light';
232
+ var page = document.createElement('div');
233
+ page.id = 'mock-page';
234
+ page.className = kind;
235
+ page.innerHTML =
236
+ '<nav><div class="logo"></div><b>Acme Cloud</b><span>Products</span><span>Solutions</span><span>Docs</span><span>Pricing</span><span class="cta">Get started</span></nav>' +
237
+ '<main><h1>Automate the busywork,<br>keep the craft.</h1>' +
238
+ '<p>Connect the tools your team already uses and let workflows handle the handoffs. Start from a template or build your own in minutes.</p>' +
239
+ '<p>Trusted by teams who present, ship, and iterate in public every week.</p>' +
240
+ '<div class="cards"><div class="card"><i style="width:60%"></i><i></i><i style="width:80%"></i></div><div class="card"><i style="width:50%"></i><i></i><i style="width:70%"></i></div><div class="card"><i style="width:70%"></i><i></i><i style="width:40%"></i></div></div>' +
241
+ '<pre>$ npx stage-browser https://example.com\n✔ opened 3 tabs\n✔ session restored</pre></main>';
242
+ document.body.insertBefore(page, document.body.firstChild);
243
+ }
244
+
245
+ // stand-in for the <browser-action-list> icons
246
+ var bal = document.querySelector('browser-action-list');
247
+ if (bal) {
248
+ bal.innerHTML =
249
+ '<span class="mock-action"><i><svg viewBox="0 0 10 10"><path d="M6 0.5L2 5.6h2.4L3.8 9.5 8 4.2H5.5z" fill="#fff"/></svg></i></span>' +
250
+ '<span class="mock-action"><i style="background:linear-gradient(135deg,#10b981,#059669)"><svg viewBox="0 0 10 10"><circle cx="5" cy="5" r="3" fill="none" stroke="#fff" stroke-width="1.6"/></svg></i></span>';
251
+ }
252
+
253
+ /* ---------- optional in-page self-check ---------- */
254
+
255
+ var sc = params.get('selfcheck');
256
+ if (sc) window.addEventListener('load', function () { setTimeout(function () { runSelfcheck(sc); }, 400); });
257
+
258
+ function runSelfcheck(suite) {
259
+ var results = [];
260
+ function sleep(ms) { return new Promise(function (r) { setTimeout(r, ms); }); }
261
+ function check(name, ok, info) { results.push({ name: name, ok: !!ok, info: ok ? '' : String(info == null ? '' : info) }); }
262
+ function $(s) { return document.querySelector(s); }
263
+ function $$(s) { return Array.prototype.slice.call(document.querySelectorAll(s)); }
264
+ function live() { return $$('#tabs .tab:not(.closing)'); }
265
+ function lastCall(name) { for (var i = calls.length - 1; i >= 0; i--) if (calls[i][0] === name) return calls[i]; return null; }
266
+ function countCalls(name) { return calls.filter(function (c) { return c[0] === name; }).length; }
267
+ function ptr(type, target, x, y, extra) {
268
+ var e = new PointerEvent(type, Object.assign({ bubbles: true, cancelable: true, clientX: x, clientY: y, button: 0, buttons: type === 'pointerup' ? 0 : 1, pointerId: 7, pointerType: 'mouse' }, extra || {}));
269
+ target.dispatchEvent(e);
270
+ }
271
+ function center(n) { var r = n.getBoundingClientRect(); return [r.left + r.width / 2, r.top + r.height / 2]; }
272
+ function clickTab(n) { var c = center(n); ptr('pointerdown', n, c[0], c[1]); ptr('pointerup', window, c[0], c[1]); }
273
+ function key(target, k, extra) {
274
+ target.dispatchEvent(new KeyboardEvent('keydown', Object.assign({ key: k, bubbles: true, cancelable: true }, extra || {})));
275
+ }
276
+ function type(v) { var i = $('#omni-input'); i.value = v; i.dispatchEvent(new Event('input', { bubbles: true })); }
277
+ function rows() { return $$('#omni-list .row'); }
278
+ function omniOpen() { return !$('#omni').hidden; }
279
+
280
+ function finish() {
281
+ var pass = results.filter(function (r) { return r.ok; }).length;
282
+ var fail = results.length - pass;
283
+ var out = 'SELFCHECK ' + (fail ? 'FAIL' : 'PASS') + ' ' + pass + '/' + results.length + '\n' +
284
+ results.map(function (r) { return (r.ok ? ' ok ' : ' FAIL ') + r.name + (r.info ? ' -> ' + r.info : ''); }).join('\n');
285
+ console.log(out);
286
+ var pre = document.createElement('pre');
287
+ pre.id = 'selfcheck';
288
+ pre.textContent = out;
289
+ pre.style.cssText = 'position:fixed;left:0;bottom:0;margin:0;font:11px monospace;background:#fff;color:#000;z-index:99;display:none';
290
+ document.body.appendChild(pre);
291
+ document.title = 'selfcheck ' + (fail ? 'FAIL' : 'PASS');
292
+ }
293
+
294
+ (async function () {
295
+ try {
296
+ if (suite === 'many') {
297
+ var tabs = $('#tabs');
298
+ check('many: compact class set', tabs.classList.contains('compact'));
299
+ check('many: tabs scroll horizontally when narrow', innerWidth > 900 || tabs.scrollWidth > tabs.clientWidth, tabs.scrollWidth + ' vs ' + tabs.clientWidth);
300
+ check('many: capsule fits inside strip', $('#capsule').getBoundingClientRect().right <= innerWidth - 12 + 0.5 && $('#capsule').getBoundingClientRect().left >= 84 - 0.5,
301
+ JSON.stringify($('#capsule').getBoundingClientRect()));
302
+ var inact = $$('#tabs .tab:not(.active)')[0];
303
+ check('many: inactive tabs are favicon-only (36px)', Math.abs(inact.getBoundingClientRect().width - 36) < 1, inact.getBoundingClientRect().width);
304
+ var act = $('#tabs .tab.active');
305
+ var ar = act.getBoundingClientRect(), tr = tabs.getBoundingClientRect();
306
+ check('many: active tab scrolled into view', ar.left >= tr.left - 1 && ar.right <= tr.right + 1, ar.left + '..' + ar.right + ' in ' + tr.left + '..' + tr.right);
307
+ finish();
308
+ return;
309
+ }
310
+
311
+ await sleep(500);
312
+ var n0 = st.tabs.length;
313
+ check('renders one element per tab', live().length === n0, live().length + ' vs ' + n0);
314
+ check('tablist/tab roles', $('#tabs').getAttribute('role') === 'tablist' && live().every(function (t) { return t.getAttribute('role') === 'tab'; }));
315
+ check('exactly one aria-selected tab', live().filter(function (t) { return t.getAttribute('aria-selected') === 'true'; }).length === 1);
316
+ check('bar is visible', document.documentElement.classList.contains('bar-visible'));
317
+ check('capsule leaves 84px for traffic lights', $('#capsule').getBoundingClientRect().left >= 84 - 0.5, $('#capsule').getBoundingClientRect().left);
318
+ check('capsule is 36px tall at top 8px', Math.abs($('#capsule').getBoundingClientRect().height - 36) < 0.5 && $('#capsule').offsetTop === 8, JSON.stringify($('#capsule').getBoundingClientRect()));
319
+
320
+ // hover
321
+ $('#capsule').dispatchEvent(new MouseEvent('mouseenter'));
322
+ $('#capsule').dispatchEvent(new MouseEvent('mouseleave'));
323
+ check('capsule hover reports setBarHover(true/false)', calls.filter(function (c) { return c[0] === 'setBarHover'; }).map(function (c) { return c[1]; }).join() === 'true,false');
324
+
325
+ // context menu
326
+ var t0 = live()[0];
327
+ t0.dispatchEvent(new MouseEvent('contextmenu', { bubbles: true, cancelable: true, button: 2 }));
328
+ check('right-click calls showTabMenu', (lastCall('showTabMenu') || [])[1] === +t0.dataset.id);
329
+
330
+ // drag to reorder: move tab 0 past tab 2
331
+ var ids = st.tabs.map(function (t) { return t.id; });
332
+ var els = live();
333
+ var a = center(els[0]), c = center(els[2]);
334
+ ptr('pointerdown', els[0], a[0], a[1]);
335
+ ptr('pointermove', window, a[0] + 8, a[1]);
336
+ await sleep(30);
337
+ ptr('pointermove', window, c[0] + 4, a[1]);
338
+ await sleep(200);
339
+ check('drag shifts the tabs it passes', els[1].style.transform.indexOf('translateX') >= 0 && els[2].style.transform.indexOf('translateX') >= 0, els[1].style.transform + '|' + els[2].style.transform);
340
+ ptr('pointerup', window, c[0] + 4, a[1]);
341
+ await sleep(400);
342
+ var mv = lastCall('moveTab');
343
+ check('drop calls moveTab(id, 2)', mv && mv[1] === ids[0] && mv[2] === 2, JSON.stringify(mv));
344
+ check('DOM order matches state after drop', live().map(function (t) { return +t.dataset.id; }).join() === st.tabs.map(function (t) { return t.id; }).join());
345
+ check('no leftover drag transforms', live().every(function (t) { return !t.style.transform; }));
346
+ check('drag does not trigger omnibox/activation click', countCalls('openOmnibox') === 0);
347
+
348
+ // activate an inactive tab, then click the active tab
349
+ var inactive = live().filter(function (t) { return !t.classList.contains('active'); })[1];
350
+ clickTab(inactive);
351
+ await sleep(50);
352
+ check('click inactive tab → activateTab', (lastCall('activateTab') || [])[1] === +inactive.dataset.id);
353
+ check('tab becomes active (aria-selected)', inactive.getAttribute('aria-selected') === 'true' && inactive.classList.contains('active'));
354
+ clickTab(inactive);
355
+ await sleep(80);
356
+ check('click active tab → openOmnibox("edit")', (lastCall('openOmnibox') || [])[1] === 'edit');
357
+ check('omnibox visible, input focused', omniOpen() && document.activeElement === $('#omni-input'));
358
+ var inp = $('#omni-input');
359
+ check('initial value fully selected', inp.value === activeTab().url && inp.selectionStart === 0 && inp.selectionEnd === inp.value.length, inp.value + ' ' + inp.selectionStart + '-' + inp.selectionEnd);
360
+ key(inp, 'Escape');
361
+ await sleep(30);
362
+ check('Esc → closeOverlay and hides', lastCall('closeOverlay') && !omniOpen());
363
+
364
+ // + button, typing, suggestions
365
+ $('#new-tab').click();
366
+ await sleep(80);
367
+ check('+ → openOmnibox("new") with empty field', (lastCall('openOmnibox') || [])[1] === 'new' && omniOpen() && $('#omni-input').value === '');
368
+ type('zap');
369
+ await sleep(250);
370
+ var r = rows();
371
+ check('suggestions render (≤ 8)', r.length > 1 && r.length <= 8, r.length);
372
+ check('first row highlighted by default', r[0] && r[0].classList.contains('sel'));
373
+ key($('#omni-input'), 'ArrowDown');
374
+ check('ArrowDown moves highlight', rows()[1].classList.contains('sel') && !rows()[0].classList.contains('sel'));
375
+ key($('#omni-input'), 'ArrowUp');
376
+ check('ArrowUp moves back', rows()[0].classList.contains('sel'));
377
+ key($('#omni-input'), 'ArrowUp');
378
+ check('ArrowUp wraps to last', rows()[rows().length - 1].classList.contains('sel'));
379
+ rows()[1].dispatchEvent(new MouseEvent('mousemove', { bubbles: true }));
380
+ check('hover moves highlight', rows()[1].classList.contains('sel'));
381
+
382
+ // pick the tab suggestion
383
+ var tabRowIdx = rows().findIndex(function (x) { return x.classList.contains('is-tab'); });
384
+ check('a tab suggestion exists', tabRowIdx >= 0);
385
+ if (tabRowIdx >= 0) {
386
+ rows()[tabRowIdx].dispatchEvent(new MouseEvent('mousemove', { bubbles: true }));
387
+ check('tab row shows "Switch to tab" hint', /Switch to tab/.test(rows()[tabRowIdx].textContent));
388
+ var before = countCalls('closeOverlay');
389
+ key($('#omni-input'), 'Enter');
390
+ await sleep(30);
391
+ check('Enter on tab suggestion → activateTab + closeOverlay', lastCall('activateTab') && countCalls('closeOverlay') === before + 1 && !omniOpen());
392
+ }
393
+
394
+ // Enter on a url (mode new → newTab true)
395
+ $('#new-tab').click(); await sleep(60);
396
+ type('example.com'); await sleep(200);
397
+ check('url-like input shows globe glyph', !!$('#omni-glyph svg circle') && !$('#omni-glyph svg path[d^="M13.2"]'));
398
+ key($('#omni-input'), 'Enter'); await sleep(30);
399
+ var sub = lastCall('submitOmnibox');
400
+ check('mode new: Enter → submitOmnibox(url, newTab:true)', sub && /example\.com/.test(sub[1]) && sub[2] === true, JSON.stringify(sub));
401
+
402
+ // edit mode: Enter navigates, Cmd+Enter opens a new tab
403
+ window.stage.openOmnibox('edit'); await sleep(60);
404
+ type('other.org'); await sleep(200);
405
+ key($('#omni-input'), 'Enter'); await sleep(30);
406
+ sub = lastCall('submitOmnibox');
407
+ check('mode edit: Enter → newTab:false', sub && /other\.org/.test(sub[1]) && sub[2] === false, JSON.stringify(sub));
408
+ window.stage.openOmnibox('edit'); await sleep(60);
409
+ type('third.net'); await sleep(200);
410
+ key($('#omni-input'), 'Enter', { metaKey: true }); await sleep(30);
411
+ sub = lastCall('submitOmnibox');
412
+ check('mode edit: Cmd+Enter → newTab:true', sub && /third\.net/.test(sub[1]) && sub[2] === true, JSON.stringify(sub));
413
+
414
+ // stale responses are dropped ('sl' answers slowly)
415
+ $('#new-tab').click(); await sleep(60);
416
+ type('sl'); await sleep(90);
417
+ type('slx'); await sleep(350);
418
+ var first = rows()[0];
419
+ check('stale suggest() response is dropped', first && /slx/.test(first.textContent) && !/“sl”/.test(first.textContent), first && first.textContent);
420
+
421
+ // Enter before suggestions catch up submits the typed text
422
+ type('quickly typed words');
423
+ key($('#omni-input'), 'Enter'); await sleep(30);
424
+ sub = lastCall('submitOmnibox');
425
+ check('Enter before debounce submits raw input', sub && sub[1] === 'quickly typed words', JSON.stringify(sub));
426
+
427
+ // backdrop click closes
428
+ $('#new-tab').click(); await sleep(60);
429
+ $('#omni-backdrop').dispatchEvent(new MouseEvent('mousedown', { bubbles: true }));
430
+ await sleep(30);
431
+ check('backdrop click → closeOverlay', !omniOpen());
432
+
433
+ // pin
434
+ $('#pin').click(); await sleep(30);
435
+ check('pin → setPinned(true), aria-pressed', (lastCall('setPinned') || [])[1] === true && $('#pin').getAttribute('aria-pressed') === 'true');
436
+
437
+ // middle click + close button
438
+ var victim = live()[0], vid = +victim.dataset.id, before2 = live().length;
439
+ victim.dispatchEvent(new MouseEvent('auxclick', { bubbles: true, cancelable: true, button: 1 }));
440
+ await sleep(400);
441
+ check('middle-click → closeTab', (lastCall('closeTab') || [])[1] === vid);
442
+ check('closed tab leaves the DOM', live().length === before2 - 1 && !$$('#tabs .tab').some(function (t) { return +t.dataset.id === vid; }), live().length + ' ' + $$('#tabs .tab').length);
443
+ var v2 = live()[1], v2id = +v2.dataset.id;
444
+ v2.querySelector('.close').click();
445
+ await sleep(400);
446
+ check('close button → closeTab', (lastCall('closeTab') || [])[1] === v2id);
447
+
448
+ finish();
449
+ } catch (e) {
450
+ check('selfcheck threw', false, e && e.stack || e);
451
+ finish();
452
+ }
453
+ })();
454
+ }
455
+ })();
@@ -0,0 +1,69 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1">
6
+ <meta name="color-scheme" content="light dark">
7
+ <title>New Tab</title>
8
+ <style>
9
+ :root {
10
+ color-scheme: light dark;
11
+ --bg: light-dark(#f6f6f7, #131316);
12
+ --glow: light-dark(rgb(255 255 255 / .9), rgb(255 255 255 / .06));
13
+ --text: light-dark(#1d1d1f, #f5f5f7);
14
+ --muted: light-dark(rgb(60 60 67 / .6), rgb(235 235 245 / .5));
15
+ --kbd-bg: light-dark(rgb(0 0 0 / .05), rgb(255 255 255 / .08));
16
+ --kbd-line: light-dark(rgb(0 0 0 / .09), rgb(255 255 255 / .1));
17
+ }
18
+ * { box-sizing: border-box; }
19
+ html, body { height: 100%; margin: 0; }
20
+ body {
21
+ display: grid;
22
+ place-items: center;
23
+ background:
24
+ radial-gradient(ellipse 60% 50% at 50% 38%, var(--glow), transparent 70%),
25
+ var(--bg);
26
+ color: var(--text);
27
+ font: 400 14px/20px -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
28
+ -webkit-font-smoothing: antialiased;
29
+ -webkit-user-select: none;
30
+ user-select: none;
31
+ cursor: default;
32
+ }
33
+ main { display: grid; justify-items: center; gap: 24px; transform: translateY(-4vh); animation: in 600ms cubic-bezier(.2,.8,.2,1) both; }
34
+ .mark { width: 40px; height: 40px; }
35
+ h1 { margin: 0; font: 600 15px/20px inherit; font-family: inherit; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
36
+ ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; justify-items: center; color: var(--muted); }
37
+ li { display: flex; align-items: center; gap: 8px; }
38
+ kbd {
39
+ font: 500 12px/20px inherit; font-family: inherit;
40
+ min-width: 24px; padding: 0 6px; text-align: center;
41
+ border-radius: 6px; background: var(--kbd-bg); box-shadow: inset 0 0 0 .5px var(--kbd-line);
42
+ color: var(--text);
43
+ }
44
+ @keyframes in { from { opacity: 0; transform: translateY(calc(-4vh + 6px)); } }
45
+ @media (prefers-reduced-motion: reduce) { main { animation: none; } }
46
+ </style>
47
+ </head>
48
+ <body>
49
+ <main>
50
+ <svg class="mark" viewBox="0 0 40 40" aria-hidden="true">
51
+ <defs>
52
+ <linearGradient id="beam" x1="0" y1="0" x2="0" y2="1">
53
+ <stop offset="0" stop-color="currentColor" stop-opacity=".0"/>
54
+ <stop offset="1" stop-color="currentColor" stop-opacity=".16"/>
55
+ </linearGradient>
56
+ </defs>
57
+ <g style="color: var(--text)">
58
+ <path d="M17 2h6l9 22H8z" fill="url(#beam)"/>
59
+ <rect x="6" y="24" width="28" height="12" rx="4" fill="none" stroke="currentColor" stroke-opacity=".7" stroke-width="2"/>
60
+ </g>
61
+ </svg>
62
+ <h1>Stage</h1>
63
+ <ul>
64
+ <li><kbd>⌘L</kbd> open a page</li>
65
+ <li>move to the top edge for tabs</li>
66
+ </ul>
67
+ </main>
68
+ </body>
69
+ </html>