stage-browser 0.1.0 → 0.2.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.
Files changed (172) hide show
  1. package/README.md +92 -45
  2. package/build/icon.icns +0 -0
  3. package/build/icon.png +0 -0
  4. package/dist/bin/stage.js +111 -0
  5. package/dist/main/cli-args.js +28 -0
  6. package/dist/main/context-menu.js +68 -0
  7. package/dist/main/context.js +2 -0
  8. package/dist/main/extensions.js +78 -0
  9. package/dist/main/ipc.js +73 -0
  10. package/dist/main/main.js +282 -0
  11. package/dist/main/menu.js +140 -0
  12. package/dist/main/reveal.js +170 -0
  13. package/dist/main/selftest.js +570 -0
  14. package/dist/main/store.js +85 -0
  15. package/dist/main/suggest.js +43 -0
  16. package/dist/main/tabs.js +324 -0
  17. package/dist/main/ui-window.js +133 -0
  18. package/dist/main/url.js +38 -0
  19. package/dist/main/window.js +133 -0
  20. package/dist/preload/extension-compat.js +163 -0
  21. package/dist/preload/ui-preload.js +34 -0
  22. package/dist/shared/contract.js +6 -0
  23. package/dist/ui/app.js +692 -0
  24. package/{src → dist}/ui/index.html +15 -5
  25. package/dist/ui/mock.js +500 -0
  26. package/{src → dist}/ui/styles.css +55 -14
  27. package/node_modules/@types/chrome/LICENSE +21 -0
  28. package/node_modules/@types/chrome/README.md +15 -0
  29. package/node_modules/@types/chrome/chrome-cast/index.d.ts +1156 -0
  30. package/node_modules/@types/chrome/har-format/index.d.ts +6 -0
  31. package/node_modules/@types/chrome/index.d.ts +13786 -0
  32. package/node_modules/@types/chrome/package.json +99 -0
  33. package/node_modules/@types/filesystem/LICENSE +21 -0
  34. package/node_modules/@types/filesystem/README.md +15 -0
  35. package/node_modules/@types/filesystem/index.d.ts +564 -0
  36. package/node_modules/@types/filesystem/package.json +26 -0
  37. package/node_modules/@types/filewriter/LICENSE +21 -0
  38. package/node_modules/@types/filewriter/README.md +15 -0
  39. package/node_modules/@types/filewriter/index.d.ts +166 -0
  40. package/node_modules/@types/filewriter/package.json +25 -0
  41. package/node_modules/@types/har-format/LICENSE +21 -0
  42. package/node_modules/@types/har-format/README.md +15 -0
  43. package/node_modules/@types/har-format/index.d.ts +938 -0
  44. package/node_modules/@types/har-format/package.json +31 -0
  45. package/node_modules/adm-zip/LICENSE +21 -0
  46. package/node_modules/adm-zip/README.md +90 -0
  47. package/node_modules/adm-zip/adm-zip.js +1020 -0
  48. package/node_modules/adm-zip/headers/entryHeader.js +396 -0
  49. package/node_modules/adm-zip/headers/index.js +2 -0
  50. package/node_modules/adm-zip/headers/mainHeader.js +177 -0
  51. package/node_modules/adm-zip/methods/deflater.js +33 -0
  52. package/node_modules/adm-zip/methods/index.js +3 -0
  53. package/node_modules/adm-zip/methods/inflater.js +64 -0
  54. package/node_modules/adm-zip/methods/zipcrypto.js +175 -0
  55. package/node_modules/adm-zip/package.json +56 -0
  56. package/node_modules/adm-zip/types.d.ts +223 -0
  57. package/node_modules/adm-zip/util/constants.js +142 -0
  58. package/node_modules/adm-zip/util/decoder.js +5 -0
  59. package/node_modules/adm-zip/util/errors.js +66 -0
  60. package/node_modules/adm-zip/util/fattr.js +76 -0
  61. package/node_modules/adm-zip/util/index.js +5 -0
  62. package/node_modules/adm-zip/util/utils.js +481 -0
  63. package/node_modules/adm-zip/zipEntry.js +415 -0
  64. package/node_modules/adm-zip/zipFile.js +466 -0
  65. package/node_modules/debug/LICENSE +20 -0
  66. package/node_modules/debug/README.md +481 -0
  67. package/node_modules/debug/package.json +64 -0
  68. package/node_modules/debug/src/browser.js +272 -0
  69. package/node_modules/debug/src/common.js +292 -0
  70. package/node_modules/debug/src/index.js +10 -0
  71. package/node_modules/debug/src/node.js +263 -0
  72. package/node_modules/electron-chrome-web-store/README.md +143 -0
  73. package/node_modules/electron-chrome-web-store/dist/chrome-web-store.preload.js +299 -0
  74. package/node_modules/electron-chrome-web-store/dist/cjs/browser/index.js +1674 -0
  75. package/node_modules/electron-chrome-web-store/dist/esm/browser/index.mjs +950 -0
  76. package/node_modules/electron-chrome-web-store/dist/types/browser/api.d.ts +2 -0
  77. package/node_modules/electron-chrome-web-store/dist/types/browser/crx3.d.ts +20 -0
  78. package/node_modules/electron-chrome-web-store/dist/types/browser/id.d.ts +9 -0
  79. package/node_modules/electron-chrome-web-store/dist/types/browser/index.d.ts +62 -0
  80. package/node_modules/electron-chrome-web-store/dist/types/browser/installer.d.ts +29 -0
  81. package/node_modules/electron-chrome-web-store/dist/types/browser/loader.d.ts +18 -0
  82. package/node_modules/electron-chrome-web-store/dist/types/browser/types.d.ts +21 -0
  83. package/node_modules/electron-chrome-web-store/dist/types/browser/updater.d.ts +6 -0
  84. package/node_modules/electron-chrome-web-store/dist/types/browser/utils.d.ts +4 -0
  85. package/node_modules/electron-chrome-web-store/dist/types/common/constants.d.ts +44 -0
  86. package/node_modules/electron-chrome-web-store/dist/types/renderer/chrome-web-store.preload.d.ts +1 -0
  87. package/node_modules/electron-chrome-web-store/package.json +43 -0
  88. package/node_modules/ms/index.js +162 -0
  89. package/node_modules/ms/license.md +21 -0
  90. package/node_modules/ms/package.json +38 -0
  91. package/node_modules/ms/readme.md +59 -0
  92. package/node_modules/pbf/LICENSE +27 -0
  93. package/node_modules/pbf/README.md +293 -0
  94. package/node_modules/pbf/bin/pbf +17 -0
  95. package/node_modules/pbf/compile.js +441 -0
  96. package/node_modules/pbf/dist/pbf-dev.js +838 -0
  97. package/node_modules/pbf/dist/pbf.js +1 -0
  98. package/node_modules/pbf/index.d.ts +206 -0
  99. package/node_modules/pbf/index.js +830 -0
  100. package/node_modules/pbf/package.json +63 -0
  101. package/node_modules/protocol-buffers-schema/.travis.yml +7 -0
  102. package/node_modules/protocol-buffers-schema/LICENSE +21 -0
  103. package/node_modules/protocol-buffers-schema/README.md +122 -0
  104. package/node_modules/protocol-buffers-schema/example.js +11 -0
  105. package/node_modules/protocol-buffers-schema/example.proto +13 -0
  106. package/node_modules/protocol-buffers-schema/index.js +6 -0
  107. package/node_modules/protocol-buffers-schema/package.json +31 -0
  108. package/node_modules/protocol-buffers-schema/parse.js +769 -0
  109. package/node_modules/protocol-buffers-schema/stringify.js +206 -0
  110. package/node_modules/protocol-buffers-schema/test/fixtures/basic.json +90 -0
  111. package/node_modules/protocol-buffers-schema/test/fixtures/basic.proto +11 -0
  112. package/node_modules/protocol-buffers-schema/test/fixtures/comments.json +99 -0
  113. package/node_modules/protocol-buffers-schema/test/fixtures/comments.proto +19 -0
  114. package/node_modules/protocol-buffers-schema/test/fixtures/complex.json +125 -0
  115. package/node_modules/protocol-buffers-schema/test/fixtures/complex.proto +30 -0
  116. package/node_modules/protocol-buffers-schema/test/fixtures/enum.json +42 -0
  117. package/node_modules/protocol-buffers-schema/test/fixtures/enum.proto +8 -0
  118. package/node_modules/protocol-buffers-schema/test/fixtures/escaped-quotes.json +32 -0
  119. package/node_modules/protocol-buffers-schema/test/fixtures/escaped-quotes.proto +3 -0
  120. package/node_modules/protocol-buffers-schema/test/fixtures/extend.json +167 -0
  121. package/node_modules/protocol-buffers-schema/test/fixtures/extend.proto +19 -0
  122. package/node_modules/protocol-buffers-schema/test/fixtures/import.json +30 -0
  123. package/node_modules/protocol-buffers-schema/test/fixtures/import.proto +6 -0
  124. package/node_modules/protocol-buffers-schema/test/fixtures/map.json +33 -0
  125. package/node_modules/protocol-buffers-schema/test/fixtures/map.proto +3 -0
  126. package/node_modules/protocol-buffers-schema/test/fixtures/no-tags.proto +8 -0
  127. package/node_modules/protocol-buffers-schema/test/fixtures/oneof.json +41 -0
  128. package/node_modules/protocol-buffers-schema/test/fixtures/oneof.proto +6 -0
  129. package/node_modules/protocol-buffers-schema/test/fixtures/option.json +364 -0
  130. package/node_modules/protocol-buffers-schema/test/fixtures/option.proto +72 -0
  131. package/node_modules/protocol-buffers-schema/test/fixtures/options.json +47 -0
  132. package/node_modules/protocol-buffers-schema/test/fixtures/options.proto +8 -0
  133. package/node_modules/protocol-buffers-schema/test/fixtures/pheromon-trajectories.proto +8 -0
  134. package/node_modules/protocol-buffers-schema/test/fixtures/reserved.json +55 -0
  135. package/node_modules/protocol-buffers-schema/test/fixtures/reserved.proto +17 -0
  136. package/node_modules/protocol-buffers-schema/test/fixtures/search.json +30 -0
  137. package/node_modules/protocol-buffers-schema/test/fixtures/search.proto +5 -0
  138. package/node_modules/protocol-buffers-schema/test/fixtures/service.json +108 -0
  139. package/node_modules/protocol-buffers-schema/test/fixtures/service.proto +30 -0
  140. package/node_modules/protocol-buffers-schema/test/fixtures/valid-packed.proto +35 -0
  141. package/node_modules/protocol-buffers-schema/test/fixtures/version.json +90 -0
  142. package/node_modules/protocol-buffers-schema/test/fixtures/version.proto +13 -0
  143. package/node_modules/protocol-buffers-schema/test/index.js +157 -0
  144. package/node_modules/protocol-buffers-schema/tokenize.js +56 -0
  145. package/node_modules/resolve-protobuf-schema/.travis.yml +3 -0
  146. package/node_modules/resolve-protobuf-schema/LICENSE +21 -0
  147. package/node_modules/resolve-protobuf-schema/README.md +49 -0
  148. package/node_modules/resolve-protobuf-schema/index.js +50 -0
  149. package/node_modules/resolve-protobuf-schema/package.json +25 -0
  150. package/node_modules/resolve-protobuf-schema/test/a.proto +5 -0
  151. package/node_modules/resolve-protobuf-schema/test/b.proto +5 -0
  152. package/node_modules/resolve-protobuf-schema/test/c.proto +3 -0
  153. package/node_modules/resolve-protobuf-schema/test/index.js +49 -0
  154. package/package.json +35 -11
  155. package/bin/stage.js +0 -52
  156. package/src/main/cli-args.js +0 -28
  157. package/src/main/context-menu.js +0 -64
  158. package/src/main/extensions.js +0 -61
  159. package/src/main/main.js +0 -310
  160. package/src/main/menu.js +0 -171
  161. package/src/main/reveal.js +0 -141
  162. package/src/main/selftest.js +0 -383
  163. package/src/main/store.js +0 -77
  164. package/src/main/suggest.js +0 -50
  165. package/src/main/tabs.js +0 -351
  166. package/src/main/url.js +0 -37
  167. package/src/main/window.js +0 -71
  168. package/src/preload/extension-compat.js +0 -34
  169. package/src/preload/ui-preload.js +0 -40
  170. package/src/ui/app.js +0 -588
  171. package/src/ui/mock.js +0 -455
  172. /package/{src → dist}/ui/newtab.html +0 -0
@@ -8,8 +8,21 @@
8
8
  <link rel="stylesheet" href="styles.css">
9
9
  </head>
10
10
  <body>
11
- <!-- Tab bar: a 52px strip with one floating capsule. The leftmost 84px stay free for the traffic lights. -->
11
+ <!-- Tab bar: a 52px strip with the traffic lights in its leftmost 84px and one floating capsule.
12
+ Its background drags the window. -->
12
13
  <div id="strip">
14
+ <div id="lights" role="group" aria-label="Window">
15
+ <button id="light-close" class="light" type="button" tabindex="-1" aria-label="Close window">
16
+ <svg viewBox="0 0 12 12" aria-hidden="true"><path d="M3.75 3.75l4.5 4.5M8.25 3.75l-4.5 4.5" fill="none" stroke="currentColor" stroke-width="1.2" stroke-linecap="round"/></svg>
17
+ </button>
18
+ <button id="light-minimize" class="light" type="button" tabindex="-1" aria-label="Minimize window">
19
+ <svg viewBox="0 0 12 12" aria-hidden="true"><path d="M3 6h6" fill="none" stroke="currentColor" stroke-width="1.3" stroke-linecap="round"/></svg>
20
+ </button>
21
+ <button id="light-zoom" class="light" type="button" tabindex="-1" aria-label="Enter full screen">
22
+ <svg class="full" viewBox="0 0 12 12" aria-hidden="true"><path d="M3.5 3.5h3.6L3.5 7.1zM8.5 8.5H4.9l3.6-3.6z" fill="currentColor"/></svg>
23
+ <svg class="plus" viewBox="0 0 12 12" aria-hidden="true"><path d="M6 3v6M3 6h6" fill="none" stroke="currentColor" stroke-width="1.3" stroke-linecap="round"/></svg>
24
+ </button>
25
+ </div>
13
26
  <div id="capsule">
14
27
  <div id="tabs" role="tablist" aria-label="Tabs"></div>
15
28
  <button id="new-tab" class="icon-btn" type="button" aria-label="New tab" title="New tab (⌘T)">
@@ -18,14 +31,11 @@
18
31
  <div id="controls">
19
32
  <span class="divider" aria-hidden="true"></span>
20
33
  <browser-action-list partition="persist:stage" alignment="bottom right"></browser-action-list>
21
- <button id="pin" class="icon-btn" type="button" aria-label="Pin tab bar" aria-pressed="false" title="Pin tab bar (⇧⌘B)">
22
- <svg viewBox="0 0 24 24" width="16" height="16" aria-hidden="true"><g transform="rotate(45 12 12)" fill="none"><path d="M12 17v5M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H8a2 2 0 0 0 0 4 1 1 0 0 1 1 1z" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/></g></svg>
23
- </button>
24
34
  </div>
25
35
  </div>
26
36
  </div>
27
37
 
28
- <!-- Omnibox overlay (shown when state.overlay.type === 'omnibox'; the view is then full-window). -->
38
+ <!-- Omnibox overlay (shown when state.overlay.type === 'omnibox'; the UI window then covers the page). -->
29
39
  <div id="omni" hidden>
30
40
  <div id="omni-backdrop"></div>
31
41
  <div id="omni-panel" role="dialog" aria-label="Open a page or search">
@@ -0,0 +1,500 @@
1
+ "use strict";
2
+ // A fake window.stage for previewing the UI in a plain browser. app.js loads it only when
3
+ // window.stage is undefined, which never happens inside Electron.
4
+ //
5
+ // URL params:
6
+ // scene bar | single | many | loading | pinned | omnibox | omnibox-edit | newtab
7
+ // theme dark | light
8
+ // backdrop light | dark paints a fake web page behind the transparent UI
9
+ // anim 0 disables transitions, for deterministic screenshots
10
+ // visible 0 starts with the bar hidden
11
+ // selfcheck main | many runs in-page interaction checks; results land in #selfcheck
12
+ {
13
+ const params = new URLSearchParams(location.search);
14
+ const scene = params.get('scene') ?? 'bar';
15
+ const root = document.documentElement;
16
+ const theme = params.get('theme');
17
+ if (theme)
18
+ root.dataset.theme = theme;
19
+ const fav = (letter, bg, shape = 'square') => {
20
+ const inner = shape === 'circle' ? `<circle cx="8" cy="8" r="8" fill="${bg}"/>` : `<rect width="16" height="16" rx="4" fill="${bg}"/>`;
21
+ const svg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16">${inner}` +
22
+ `<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>`;
23
+ return `data:image/svg+xml,${encodeURIComponent(svg)}`;
24
+ };
25
+ const POOL = [
26
+ { title: 'Workflow editor — Northwind', url: 'https://northwind.example/editor/2481', favicon: fav('N', '#2e6b5b') },
27
+ { title: 'Pull request #482 · acme/stage', url: 'https://github.com/acme/stage/pull/482', favicon: fav('G', '#24292f', 'circle') },
28
+ { title: 'Quarterly roadmap', url: 'https://notion.example.com/roadmap', favicon: null },
29
+ { title: 'Design review — homepage v3', url: 'https://figma.example.com/file/abc', favicon: fav('F', '#7c3aed') },
30
+ { title: 'Inbox (12)', url: 'https://mail.example.com/inbox', favicon: fav('M', '#2563eb') },
31
+ { 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 },
32
+ { title: 'Webinar recording — lo-fi beats', url: 'https://music.example.com/live', favicon: fav('♪', '#db2777', 'circle'), audible: true },
33
+ { title: 'Analytics — Overview', url: 'https://analytics.example.net/overview', favicon: null },
34
+ { title: 'Customer interviews', url: 'https://sheets.example.com/d/1x', favicon: fav('S', '#16a34a') },
35
+ { title: 'Staging — dashboard', url: 'https://staging.acme.dev/', favicon: null },
36
+ ];
37
+ const HISTORY = [
38
+ { title: 'Northwind: Onboarding, automated', url: 'https://northwind.example/', favicon: fav('N', '#2e6b5b') },
39
+ { title: 'Workflows — Northwind', url: 'https://northwind.example/app/workflows', favicon: fav('N', '#2e6b5b') },
40
+ { title: 'Northwind docs', url: 'https://docs.northwind.example/', favicon: fav('N', '#2e6b5b') },
41
+ { title: 'Electron — Build cross-platform apps', url: 'https://www.electronjs.org/', favicon: fav('E', '#2f3241', 'circle') },
42
+ { title: 'Example Domain', url: 'https://example.com/', favicon: null },
43
+ { title: 'Hacker News', url: 'https://news.ycombinator.com/', favicon: fav('Y', '#f26522') },
44
+ { title: 'MDN Web Docs', url: 'https://developer.mozilla.org/', favicon: fav('M', '#111827') },
45
+ { title: 'Calendar — this week', url: 'https://calendar.example.com/week', favicon: fav('C', '#0ea5e9') },
46
+ ];
47
+ let nextId = 100;
48
+ let nonce = 0;
49
+ const tab = (p) => ({ id: nextId++, title: p.title, url: p.url, favicon: p.favicon, loading: false, audible: !!p.audible, muted: false });
50
+ const blank = () => tab({ title: 'New Tab', url: '', favicon: null });
51
+ const pick = (n, silent) => Array.from({ length: n }, (_, i) => {
52
+ const p = POOL[i % POOL.length];
53
+ const page = i < POOL.length ? p : { title: `${p.title.slice(0, 22)} ${Math.floor(i / POOL.length) + 1}`, url: `${p.url}?p=${i}`, favicon: p.favicon };
54
+ const t = tab(page);
55
+ if (silent)
56
+ t.audible = false;
57
+ return t;
58
+ });
59
+ const at = (tabs, i) => {
60
+ const t = tabs[i];
61
+ if (!t)
62
+ throw new Error(`scene ${scene} has no tab ${i}`);
63
+ return t;
64
+ };
65
+ const sceneTabs = () => {
66
+ switch (scene) {
67
+ case 'single':
68
+ return { tabs: pick(1, true), active: 0 };
69
+ case 'newtab':
70
+ return { tabs: [blank()], active: 0 };
71
+ case 'many': {
72
+ const tabs = pick(18, true);
73
+ at(tabs, 6).audible = true;
74
+ return { tabs, active: 6 };
75
+ }
76
+ case 'loading': {
77
+ const tabs = pick(6, false);
78
+ Object.assign(at(tabs, 0), { loading: true, favicon: null });
79
+ Object.assign(at(tabs, 3), { loading: true });
80
+ Object.assign(at(tabs, 4), { audible: true, muted: true });
81
+ tabs.push(tab(POOL[6]));
82
+ return { tabs, active: 0 };
83
+ }
84
+ case 'pinned':
85
+ return { tabs: pick(5, true), active: 1 };
86
+ default:
87
+ return { tabs: [...pick(5, true), blank()], active: 1 };
88
+ }
89
+ };
90
+ const initial = sceneTabs();
91
+ const st = {
92
+ tabs: initial.tabs,
93
+ activeTabId: at(initial.tabs, initial.active).id,
94
+ canGoBack: true,
95
+ canGoForward: false,
96
+ zoomFactor: 1,
97
+ bar: { visible: params.get('visible') !== '0', pinned: scene === 'pinned' },
98
+ hideExtensionIcons: false,
99
+ extensionActions: 2,
100
+ overlay: null,
101
+ barHeight: 52,
102
+ fullscreen: false,
103
+ };
104
+ const omnibox = (mode, text) => ({ type: 'omnibox', mode, initial: text, nonce: ++nonce });
105
+ if (scene === 'omnibox')
106
+ st.overlay = omnibox('new', 'zap');
107
+ if (scene === 'omnibox-edit')
108
+ st.overlay = omnibox('edit', at(st.tabs, 1).url);
109
+ let listeners = [];
110
+ const calls = [];
111
+ const record = (...call) => void calls.push(call);
112
+ const snapshot = () => structuredClone(st);
113
+ const emit = () => {
114
+ const s = snapshot();
115
+ for (const cb of listeners)
116
+ cb(s);
117
+ };
118
+ const indexOf = (id) => st.tabs.findIndex((t) => t.id === id);
119
+ const activeTab = () => st.tabs.find((t) => t.id === st.activeTabId);
120
+ const looksLikeUrl = (v) => !/\s/.test(v) && (/^[a-z]+:\/\//i.test(v) || /^[^\s/]+\.[a-z]{2,}(\/|$)/i.test(v));
121
+ const normalize = (v) => (/^[a-z]+:\/\//i.test(v) ? v : `https://${v}`);
122
+ const hostOf = (u) => {
123
+ try {
124
+ return new URL(u).hostname.replace(/^www\./, '');
125
+ }
126
+ catch {
127
+ return u;
128
+ }
129
+ };
130
+ const makeSuggestions = (raw) => {
131
+ const q = raw.trim();
132
+ const lq = q.toLowerCase();
133
+ const matches = (p) => !q || p.title.toLowerCase().includes(lq) || p.url.toLowerCase().includes(lq);
134
+ const out = [];
135
+ if (q) {
136
+ out.push(looksLikeUrl(q)
137
+ ? { kind: 'url', title: q, url: normalize(q), favicon: null }
138
+ : { kind: 'search', title: `Search Google for “${q}”`, url: `https://www.google.com/search?q=${encodeURIComponent(q)}`, favicon: null });
139
+ }
140
+ for (const t of st.tabs) {
141
+ if ((t.id === st.activeTabId && !q) || !t.url || !matches(t))
142
+ continue;
143
+ out.push({ kind: 'tab', title: t.title, url: t.url, tabId: t.id, favicon: t.favicon });
144
+ }
145
+ for (const h of HISTORY)
146
+ if (matches(h))
147
+ out.push({ kind: 'history', title: h.title, url: h.url, favicon: h.favicon });
148
+ return out.slice(0, 8);
149
+ };
150
+ const api = {
151
+ getState: () => Promise.resolve(snapshot()),
152
+ onState: (cb) => {
153
+ listeners.push(cb);
154
+ return () => {
155
+ listeners = listeners.filter((l) => l !== cb);
156
+ };
157
+ },
158
+ activateTab: (id) => {
159
+ record('activateTab', id);
160
+ st.activeTabId = id;
161
+ emit();
162
+ },
163
+ closeTab: (id) => {
164
+ record('closeTab', id);
165
+ const i = indexOf(id);
166
+ if (i < 0)
167
+ return;
168
+ st.tabs.splice(i, 1);
169
+ if (!st.tabs.length) {
170
+ const b = blank();
171
+ st.tabs.push(b);
172
+ st.activeTabId = b.id;
173
+ }
174
+ else if (st.activeTabId === id)
175
+ st.activeTabId = at(st.tabs, Math.min(i, st.tabs.length - 1)).id;
176
+ emit();
177
+ },
178
+ moveTab: (id, to) => {
179
+ record('moveTab', id, to);
180
+ const i = indexOf(id);
181
+ if (i < 0)
182
+ return;
183
+ st.tabs.splice(to, 0, ...st.tabs.splice(i, 1));
184
+ emit();
185
+ },
186
+ showTabMenu: (id) => record('showTabMenu', id),
187
+ openOmnibox: (mode) => {
188
+ record('openOmnibox', mode);
189
+ st.overlay = omnibox(mode, mode === 'edit' ? (activeTab()?.url ?? '') : '');
190
+ emit();
191
+ },
192
+ closeOverlay: () => {
193
+ record('closeOverlay');
194
+ st.overlay = null;
195
+ emit();
196
+ },
197
+ suggest: (q) => {
198
+ record('suggest', q);
199
+ return new Promise((resolve) => setTimeout(() => resolve(makeSuggestions(q)), q === 'sl' ? 160 : 20));
200
+ },
201
+ submitOmnibox: (text, options) => {
202
+ record('submitOmnibox', text, options);
203
+ const url = looksLikeUrl(text) ? normalize(text) : text;
204
+ const title = hostOf(url);
205
+ if (options.newTab) {
206
+ const t = tab({ title, url, favicon: null });
207
+ st.tabs.push(t);
208
+ st.activeTabId = t.id;
209
+ }
210
+ else {
211
+ const a = activeTab();
212
+ if (a)
213
+ Object.assign(a, { url, title, favicon: null });
214
+ }
215
+ st.overlay = null;
216
+ emit();
217
+ },
218
+ back: () => record('back'),
219
+ forward: () => record('forward'),
220
+ reload: () => record('reload'),
221
+ setBarHover: (hovering) => record('setBarHover', hovering),
222
+ passClick: (x, y, button, clickCount) => record('passClick', x, y, button, clickCount),
223
+ startWindowDrag: () => record('startWindowDrag'),
224
+ endWindowDrag: () => record('endWindowDrag'),
225
+ windowAction: (action) => record('windowAction', action),
226
+ };
227
+ window.stage = api;
228
+ const mockCss = document.createElement('style');
229
+ mockCss.textContent =
230
+ 'browser-action-list{display:flex}' +
231
+ '.mock-action{width:24px;height:24px;margin:0 2px;border-radius:6px;display:grid;place-items:center}' +
232
+ '.mock-action:hover{background:var(--hover)}' +
233
+ '.mock-action i{width:16px;height:16px;border-radius:5px;background:linear-gradient(135deg,#8b5cf6,#6366f1);display:grid;place-items:center}' +
234
+ '.mock-action svg{width:10px;height:10px}' +
235
+ '#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}' +
236
+ '#mock-page.light{background:#fff;color:#1a1a1a}#mock-page.dark{background:#0d1117;color:#e6edf3}' +
237
+ '#mock-page nav{height:64px;display:flex;align-items:center;gap:28px;padding:0 32px;border-bottom:1px solid rgb(128 128 128/.2)}' +
238
+ '#mock-page .logo{width:28px;height:28px;border-radius:8px;background:#ff4f00}' +
239
+ '#mock-page.dark .logo{background:#2f81f7}' +
240
+ '#mock-page nav b{font-weight:600}#mock-page nav span{opacity:.65;font-size:14px}' +
241
+ '#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}' +
242
+ '#mock-page.dark nav .cta{background:#238636}' +
243
+ '#mock-page main{max-width:880px;margin:0 auto;padding:56px 32px}' +
244
+ '#mock-page h1{font-size:44px;line-height:1.1;margin:0 0 16px;letter-spacing:-.03em}' +
245
+ '#mock-page p{margin:0 0 12px;opacity:.72;max-width:640px}' +
246
+ '#mock-page .cards{display:grid;grid-template-columns:repeat(3,1fr);gap:16px;margin-top:32px}' +
247
+ '#mock-page .card{border:1px solid rgb(128 128 128/.25);border-radius:12px;padding:16px;height:120px}' +
248
+ '#mock-page .card i{display:block;height:8px;border-radius:4px;background:rgb(128 128 128/.28);margin-bottom:8px}' +
249
+ '#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}';
250
+ if (params.get('anim') === '0')
251
+ mockCss.textContent += '*,*::before,*::after{transition:none!important;animation:none!important}';
252
+ document.head.appendChild(mockCss);
253
+ const backdrop = params.get('backdrop');
254
+ if (backdrop) {
255
+ const page = document.createElement('div');
256
+ page.id = 'mock-page';
257
+ page.className = backdrop === 'dark' ? 'dark' : 'light';
258
+ page.innerHTML =
259
+ '<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>' +
260
+ '<main><h1>Automate the busywork,<br>keep the craft.</h1>' +
261
+ '<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>' +
262
+ '<p>Trusted by teams who present, ship, and iterate in public every week.</p>' +
263
+ '<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>' +
264
+ '<pre>$ npx stage-browser https://example.com\n✔ opened 3 tabs\n✔ session restored</pre></main>';
265
+ document.body.prepend(page);
266
+ }
267
+ const actions = document.querySelector('browser-action-list');
268
+ if (actions) {
269
+ actions.innerHTML =
270
+ '<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>' +
271
+ '<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>';
272
+ }
273
+ const describe = (v) => (v === undefined || v === null ? '' : typeof v === 'string' ? v : JSON.stringify(v));
274
+ const runSelfcheck = async (suite) => {
275
+ const results = [];
276
+ const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
277
+ const check = (name, ok, info) => void results.push({ name, ok: !!ok, info: ok ? '' : describe(info) });
278
+ const q = (sel) => {
279
+ const n = document.querySelector(sel);
280
+ if (!n)
281
+ throw new Error(`${sel} not found`);
282
+ return n;
283
+ };
284
+ const qa = (sel) => Array.from(document.querySelectorAll(sel));
285
+ const live = () => qa('#tabs .tab:not(.closing)');
286
+ const rows = () => qa('#omni-list .row');
287
+ const nth = (items, i) => {
288
+ const item = i < 0 ? items[items.length + i] : items[i];
289
+ if (item === undefined)
290
+ throw new Error(`no item ${i} of ${items.length}`);
291
+ return item;
292
+ };
293
+ const idOf = (n) => Number(n.dataset.id);
294
+ const input = () => q('#omni-input');
295
+ const omniOpen = () => !q('#omni').hidden;
296
+ const lastCall = (name) => calls.findLast((c) => c[0] === name);
297
+ const countCalls = (name) => calls.filter((c) => c[0] === name).length;
298
+ const ptr = (type, target, x, y) => target.dispatchEvent(new PointerEvent(type, { bubbles: true, cancelable: true, clientX: x, clientY: y, button: 0, buttons: type === 'pointerup' ? 0 : 1, pointerId: 7, pointerType: 'mouse' }));
299
+ const center = (n) => {
300
+ const r = n.getBoundingClientRect();
301
+ return [r.left + r.width / 2, r.top + r.height / 2];
302
+ };
303
+ const clickTab = (n) => {
304
+ const [x, y] = center(n);
305
+ ptr('pointerdown', n, x, y);
306
+ ptr('pointerup', window, x, y);
307
+ };
308
+ const key = (target, k, init = {}) => target.dispatchEvent(new KeyboardEvent('keydown', { key: k, bubbles: true, cancelable: true, ...init }));
309
+ const type = (v) => {
310
+ const i = input();
311
+ i.value = v;
312
+ i.dispatchEvent(new Event('input', { bubbles: true }));
313
+ };
314
+ const submitted = () => lastCall('submitOmnibox');
315
+ const finish = () => {
316
+ const pass = results.filter((r) => r.ok).length;
317
+ const fail = results.length - pass;
318
+ const out = `SELFCHECK ${fail ? 'FAIL' : 'PASS'} ${pass}/${results.length}\n${results.map((r) => `${r.ok ? ' ok ' : ' FAIL '}${r.name}${r.info ? ` -> ${r.info}` : ''}`).join('\n')}`;
319
+ console.log(out);
320
+ const pre = document.createElement('pre');
321
+ pre.id = 'selfcheck';
322
+ pre.textContent = out;
323
+ pre.style.cssText = 'position:fixed;left:0;bottom:0;margin:0;font:11px monospace;background:#fff;color:#000;z-index:99;display:none';
324
+ document.body.appendChild(pre);
325
+ document.title = `selfcheck ${fail ? 'FAIL' : 'PASS'}`;
326
+ };
327
+ try {
328
+ await sleep(500);
329
+ if (suite === 'many') {
330
+ const tabs = q('#tabs');
331
+ const cap = q('#capsule').getBoundingClientRect();
332
+ check('many: compact class set', tabs.classList.contains('compact'));
333
+ check('many: tabs scroll horizontally when narrow', innerWidth > 900 || tabs.scrollWidth > tabs.clientWidth, `${tabs.scrollWidth} vs ${tabs.clientWidth}`);
334
+ check('many: capsule fits inside strip', cap.right <= innerWidth - 12 + 0.5 && cap.left >= 84 - 0.5, JSON.stringify(cap));
335
+ const inactiveWidth = nth(qa('#tabs .tab:not(.active)'), 0).getBoundingClientRect().width;
336
+ check('many: inactive tabs are favicon-only (36px)', Math.abs(inactiveWidth - 36) < 1, inactiveWidth);
337
+ const ar = q('#tabs .tab.active').getBoundingClientRect();
338
+ const tr = tabs.getBoundingClientRect();
339
+ 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}`);
340
+ return finish();
341
+ }
342
+ const n0 = st.tabs.length;
343
+ const cap = q('#capsule');
344
+ check('renders one element per tab', live().length === n0, `${live().length} vs ${n0}`);
345
+ check('tablist/tab roles', q('#tabs').getAttribute('role') === 'tablist' && live().every((t) => t.getAttribute('role') === 'tab'));
346
+ check('exactly one aria-selected tab', live().filter((t) => t.getAttribute('aria-selected') === 'true').length === 1);
347
+ check('bar is visible', root.classList.contains('bar-visible'));
348
+ check('capsule leaves 84px for traffic lights', cap.getBoundingClientRect().left >= 84 - 0.5, cap.getBoundingClientRect().left);
349
+ check('capsule is 36px tall at top 8px', Math.abs(cap.getBoundingClientRect().height - 36) < 0.5 && cap.offsetTop === 8, JSON.stringify(cap.getBoundingClientRect()));
350
+ cap.dispatchEvent(new MouseEvent('mouseenter'));
351
+ cap.dispatchEvent(new MouseEvent('mouseleave'));
352
+ const hovers = calls.flatMap((c) => (c[0] === 'setBarHover' ? [c[1]] : []));
353
+ check('capsule hover reports setBarHover(true/false)', hovers.join() === 'true,false');
354
+ const lights = q('#lights').getBoundingClientRect();
355
+ check('traffic lights sit in the leftmost 84px, centred on the capsule', lights.left >= 0 && lights.right <= 84 && Math.abs(lights.top + lights.height / 2 - 26) < 0.5, JSON.stringify(lights));
356
+ q('#light-close').click();
357
+ q('#light-minimize').click();
358
+ q('#light-zoom').click();
359
+ q('#light-zoom').dispatchEvent(new MouseEvent('click', { bubbles: true, altKey: true }));
360
+ const actions = calls.flatMap((c) => (c[0] === 'windowAction' ? [c[1]] : []));
361
+ check('traffic lights → windowAction close, minimize, fullscreen; Option-green → zoom', actions.join() === 'close,minimize,fullscreen,zoom', actions.join());
362
+ const strip = q('#strip');
363
+ const drags = () => countCalls('startWindowDrag') + '/' + countCalls('endWindowDrag');
364
+ ptr('pointerdown', strip, 60, 40);
365
+ ptr('pointerup', window, 60, 40);
366
+ check('strip background pointerdown → startWindowDrag, pointerup → endWindowDrag', drags() === '1/1', drags());
367
+ ptr('pointerdown', q('#new-tab'), 60, 40);
368
+ ptr('pointerdown', nth(live(), 0), 60, 40);
369
+ check('pointerdown on a button or a tab does not drag the window', drags() === '1/1', drags());
370
+ ptr('pointercancel', window, 60, 40);
371
+ strip.dispatchEvent(new MouseEvent('dblclick', { bubbles: true }));
372
+ nth(live(), 0).dispatchEvent(new MouseEvent('dblclick', { bubbles: true }));
373
+ check('double-click on the strip background → windowAction("double-click"), on a tab → nothing', calls.filter((c) => c[0] === 'windowAction' && c[1] === 'double-click').length === 1);
374
+ const t0 = nth(live(), 0);
375
+ t0.dispatchEvent(new MouseEvent('contextmenu', { bubbles: true, cancelable: true, button: 2 }));
376
+ check('right-click calls showTabMenu', lastCall('showTabMenu')?.[1] === idOf(t0));
377
+ const ids = st.tabs.map((t) => t.id);
378
+ const els = live();
379
+ const [ax, ay] = center(nth(els, 0));
380
+ const [cx] = center(nth(els, 2));
381
+ ptr('pointerdown', nth(els, 0), ax, ay);
382
+ ptr('pointermove', window, ax + 8, ay);
383
+ await sleep(30);
384
+ ptr('pointermove', window, cx + 4, ay);
385
+ await sleep(200);
386
+ const shifted = [nth(els, 1), nth(els, 2)].map((n) => n.style.transform);
387
+ check('drag shifts the tabs it passes', shifted.every((t) => t.includes('translateX')), shifted.join('|'));
388
+ ptr('pointerup', window, cx + 4, ay);
389
+ await sleep(400);
390
+ const mv = lastCall('moveTab');
391
+ check('drop calls moveTab(id, 2)', mv?.[1] === ids[0] && mv?.[2] === 2, JSON.stringify(mv));
392
+ check('DOM order matches state after drop', live().map(idOf).join() === st.tabs.map((t) => t.id).join());
393
+ check('no leftover drag transforms', live().every((t) => !t.style.transform));
394
+ check('drag does not trigger omnibox/activation click', countCalls('openOmnibox') === 0);
395
+ const inactive = nth(live().filter((t) => !t.classList.contains('active')), 1);
396
+ clickTab(inactive);
397
+ await sleep(50);
398
+ check('click inactive tab → activateTab', lastCall('activateTab')?.[1] === idOf(inactive));
399
+ check('tab becomes active (aria-selected)', inactive.getAttribute('aria-selected') === 'true' && inactive.classList.contains('active'));
400
+ clickTab(inactive);
401
+ await sleep(80);
402
+ check('click active tab → openOmnibox("edit")', lastCall('openOmnibox')?.[1] === 'edit');
403
+ check('omnibox visible, input focused', omniOpen() && document.activeElement === input());
404
+ const inp = input();
405
+ check('initial value fully selected', inp.value === activeTab()?.url && inp.selectionStart === 0 && inp.selectionEnd === inp.value.length, `${inp.value} ${inp.selectionStart}-${inp.selectionEnd}`);
406
+ key(inp, 'Escape');
407
+ await sleep(30);
408
+ check('Esc → closeOverlay and hides', lastCall('closeOverlay') && !omniOpen());
409
+ q('#new-tab').click();
410
+ await sleep(80);
411
+ check('+ → openOmnibox("new") with empty field', lastCall('openOmnibox')?.[1] === 'new' && omniOpen() && input().value === '');
412
+ type('northwind');
413
+ await sleep(250);
414
+ const r = rows();
415
+ check('suggestions render (≤ 8)', r.length > 1 && r.length <= 8, r.length);
416
+ check('first row highlighted by default', r[0]?.classList.contains('sel'));
417
+ key(input(), 'ArrowDown');
418
+ check('ArrowDown moves highlight', nth(rows(), 1).classList.contains('sel') && !nth(rows(), 0).classList.contains('sel'));
419
+ key(input(), 'ArrowUp');
420
+ check('ArrowUp moves back', nth(rows(), 0).classList.contains('sel'));
421
+ key(input(), 'ArrowUp');
422
+ check('ArrowUp wraps to last', nth(rows(), -1).classList.contains('sel'));
423
+ nth(rows(), 1).dispatchEvent(new MouseEvent('mousemove', { bubbles: true }));
424
+ check('hover moves highlight', nth(rows(), 1).classList.contains('sel'));
425
+ const tabRow = rows().findIndex((x) => x.classList.contains('is-tab'));
426
+ check('a tab suggestion exists', tabRow >= 0);
427
+ if (tabRow >= 0) {
428
+ nth(rows(), tabRow).dispatchEvent(new MouseEvent('mousemove', { bubbles: true }));
429
+ check('tab row shows "Switch to tab" hint', /Switch to tab/.test(nth(rows(), tabRow).textContent ?? ''));
430
+ const before = countCalls('closeOverlay');
431
+ key(input(), 'Enter');
432
+ await sleep(30);
433
+ check('Enter on tab suggestion → activateTab + closeOverlay', lastCall('activateTab') && countCalls('closeOverlay') === before + 1 && !omniOpen());
434
+ }
435
+ q('#new-tab').click();
436
+ await sleep(60);
437
+ type('example.com');
438
+ await sleep(200);
439
+ check('url-like input shows globe glyph', !!document.querySelector('#omni-glyph svg circle') && !document.querySelector('#omni-glyph svg path[d^="M13.2"]'));
440
+ key(input(), 'Enter');
441
+ await sleep(30);
442
+ let sub = submitted();
443
+ check('mode new: Enter → submitOmnibox(url, newTab:true)', sub && /example\.com/.test(sub[1]) && sub[2].newTab, JSON.stringify(sub));
444
+ api.openOmnibox('edit');
445
+ await sleep(60);
446
+ type('other.org');
447
+ await sleep(200);
448
+ key(input(), 'Enter');
449
+ await sleep(30);
450
+ sub = submitted();
451
+ check('mode edit: Enter → newTab:false', sub && /other\.org/.test(sub[1]) && !sub[2].newTab, JSON.stringify(sub));
452
+ api.openOmnibox('edit');
453
+ await sleep(60);
454
+ type('third.net');
455
+ await sleep(200);
456
+ key(input(), 'Enter', { metaKey: true });
457
+ await sleep(30);
458
+ sub = submitted();
459
+ check('mode edit: Cmd+Enter → newTab:true', sub && /third\.net/.test(sub[1]) && sub[2].newTab, JSON.stringify(sub));
460
+ q('#new-tab').click();
461
+ await sleep(60);
462
+ type('sl');
463
+ await sleep(90);
464
+ type('slx');
465
+ await sleep(350);
466
+ const first = rows()[0];
467
+ check('stale suggest() response is dropped', first && /slx/.test(first.textContent ?? '') && !/“sl”/.test(first.textContent ?? ''), first?.textContent);
468
+ type('quickly typed words');
469
+ key(input(), 'Enter');
470
+ await sleep(30);
471
+ sub = submitted();
472
+ check('Enter before debounce submits raw input', sub?.[1] === 'quickly typed words', JSON.stringify(sub));
473
+ q('#new-tab').click();
474
+ await sleep(60);
475
+ q('#omni-backdrop').dispatchEvent(new MouseEvent('mousedown', { bubbles: true }));
476
+ await sleep(30);
477
+ check('backdrop click → closeOverlay', !omniOpen());
478
+ const victim = nth(live(), 0);
479
+ const vid = idOf(victim);
480
+ const before = live().length;
481
+ victim.dispatchEvent(new MouseEvent('auxclick', { bubbles: true, cancelable: true, button: 1 }));
482
+ await sleep(400);
483
+ check('middle-click → closeTab', lastCall('closeTab')?.[1] === vid);
484
+ check('closed tab leaves the DOM', live().length === before - 1 && !qa('#tabs .tab').some((t) => idOf(t) === vid), `${live().length} ${qa('#tabs .tab').length}`);
485
+ const v2 = nth(live(), 1);
486
+ const v2id = idOf(v2);
487
+ v2.querySelector('.close')?.click();
488
+ await sleep(400);
489
+ check('close button → closeTab', lastCall('closeTab')?.[1] === v2id);
490
+ finish();
491
+ }
492
+ catch (e) {
493
+ check('selfcheck threw', false, e instanceof Error ? e.stack : e);
494
+ finish();
495
+ }
496
+ };
497
+ const suite = params.get('selfcheck');
498
+ if (suite)
499
+ window.addEventListener('load', () => setTimeout(() => void runSelfcheck(suite), 400));
500
+ }