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
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.suggest = suggest;
4
+ const store_1 = require("./store");
5
+ const url_1 = require("./url");
6
+ const MAX = 8;
7
+ const DAY_MS = 86_400_000;
8
+ function suggest(tabs, query) {
9
+ const q = query.trim();
10
+ const words = q.toLowerCase().split(/\s+/).filter(Boolean);
11
+ const matches = (s) => {
12
+ const l = s.toLowerCase();
13
+ return words.every((w) => l.includes(w));
14
+ };
15
+ const out = [];
16
+ const seen = new Set();
17
+ const first = (0, url_1.classify)(q);
18
+ if (first) {
19
+ out.push({ kind: first.kind, title: first.kind === 'search' ? `Search Google for “${q}”` : first.url, url: first.url, favicon: null });
20
+ seen.add(first.url);
21
+ }
22
+ for (const t of tabs) {
23
+ if (out.length >= MAX)
24
+ break;
25
+ if (!t.url || (words.length && !matches(`${t.title} ${t.url}`)))
26
+ continue;
27
+ out.push({ kind: 'tab', title: t.title || t.url, url: t.url, tabId: t.id, favicon: t.favicon });
28
+ seen.add(t.url);
29
+ }
30
+ if (words.length) {
31
+ const now = Date.now();
32
+ const scored = (0, store_1.historyEntries)()
33
+ .filter((h) => !seen.has(h.url) && matches(`${h.title} ${h.url}`))
34
+ .map((h) => ({ h, score: h.visits + Math.max(0, 7 - (now - h.last) / DAY_MS) }))
35
+ .sort((a, b) => b.score - a.score);
36
+ for (const { h } of scored) {
37
+ if (out.length >= MAX)
38
+ break;
39
+ out.push({ kind: 'history', title: h.title || h.url, url: h.url, favicon: null });
40
+ }
41
+ }
42
+ return out.slice(0, MAX);
43
+ }
@@ -0,0 +1,324 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Tabs = exports.NEWTAB_FILE = void 0;
4
+ const electron_1 = require("electron");
5
+ const node_path_1 = require("node:path");
6
+ const context_menu_1 = require("./context-menu");
7
+ const store_1 = require("./store");
8
+ const url_1 = require("./url");
9
+ const window_1 = require("./window");
10
+ exports.NEWTAB_FILE = (0, node_path_1.join)(__dirname, '..', 'ui', 'newtab.html');
11
+ const CLOSED_CAP = 25;
12
+ const WEB_SCHEMES = new Set(['http:', 'https:', 'file:', 'about:', 'data:', 'blob:', 'chrome-extension:', 'view-source:', 'devtools:', 'chrome:', 'javascript:']);
13
+ function isExternal(url) {
14
+ const scheme = /^([a-z][a-z0-9+.-]*:)/i.exec(url)?.[1]?.toLowerCase();
15
+ return !!scheme && !WEB_SCHEMES.has(scheme);
16
+ }
17
+ function openExternal(url) {
18
+ electron_1.shell.openExternal(url).catch(() => { });
19
+ }
20
+ class Tabs {
21
+ list = [];
22
+ activeId = null;
23
+ ctx;
24
+ closed = [];
25
+ constructor(ctx) {
26
+ this.ctx = ctx;
27
+ }
28
+ get(id) {
29
+ return this.list.find((t) => t.id === id);
30
+ }
31
+ get active() {
32
+ return this.list.find((t) => t.id === this.activeId);
33
+ }
34
+ create(opts = {}) {
35
+ const { ctx } = this;
36
+ const view = opts.webContents
37
+ ? new electron_1.WebContentsView({ webContents: opts.webContents })
38
+ : new electron_1.WebContentsView({ webPreferences: { session: ctx.session, sandbox: true, contextIsolation: true, nodeIntegration: false } });
39
+ view.setBackgroundColor((0, window_1.bgColor)());
40
+ const wc = view.webContents;
41
+ const tab = { id: wc.id, view, wc, title: '', url: '', favicon: null, loading: false, audible: false, muted: false, newTab: false };
42
+ this.list.splice(opts.index ?? this.list.length, 0, tab);
43
+ ctx.win.contentView.addChildView(view);
44
+ view.setBounds(ctx.tabBounds());
45
+ view.setVisible(false);
46
+ this.wire(tab);
47
+ ctx.ext.addTab(wc, ctx.win);
48
+ if (!opts.webContents) {
49
+ if (opts.url)
50
+ this.load(tab, opts.url);
51
+ else
52
+ this.loadNewTab(tab);
53
+ }
54
+ if (opts.activate !== false)
55
+ this.activate(tab.id);
56
+ else
57
+ ctx.push();
58
+ return tab;
59
+ }
60
+ loadNewTab(tab) {
61
+ tab.newTab = true;
62
+ tab.wc.loadFile(exports.NEWTAB_FILE).catch(() => { });
63
+ }
64
+ load(tab, url) {
65
+ tab.newTab = false;
66
+ tab.wc.loadURL(url).catch(() => { }); // failures arrive through did-fail-load
67
+ }
68
+ wire(tab) {
69
+ const { wc } = tab;
70
+ const push = () => this.ctx.push();
71
+ const syncUrl = () => {
72
+ const u = wc.getURL();
73
+ tab.newTab = u.startsWith('file://') && decodeURI(u).endsWith('/ui/newtab.html');
74
+ tab.url = tab.newTab ? '' : u;
75
+ };
76
+ const guardExternal = (e, url) => {
77
+ if (!isExternal(url))
78
+ return;
79
+ e.preventDefault();
80
+ openExternal(url);
81
+ };
82
+ wc.on('page-title-updated', (_e, title) => {
83
+ tab.title = title;
84
+ if ((0, url_1.isWebUrl)(tab.url))
85
+ (0, store_1.setHistoryTitle)(tab.url, title);
86
+ push();
87
+ });
88
+ wc.on('page-favicon-updated', (_e, favicons) => {
89
+ tab.favicon = favicons[0] ?? null;
90
+ push();
91
+ });
92
+ wc.on('did-start-navigation', (e) => {
93
+ if (e.isMainFrame && !e.isSameDocument)
94
+ tab.favicon = null;
95
+ });
96
+ wc.on('did-start-loading', () => {
97
+ tab.loading = true;
98
+ push();
99
+ });
100
+ wc.on('did-stop-loading', () => {
101
+ tab.loading = false;
102
+ syncUrl();
103
+ if (!tab.title && tab.url)
104
+ tab.title = tab.url;
105
+ push();
106
+ });
107
+ wc.on('did-navigate', (_e, url) => {
108
+ syncUrl();
109
+ if ((0, url_1.isWebUrl)(url))
110
+ (0, store_1.addVisit)(url, wc.getTitle());
111
+ this.ctx.saveSession();
112
+ push();
113
+ });
114
+ wc.on('did-navigate-in-page', (_e, _url, isMainFrame) => {
115
+ if (!isMainFrame)
116
+ return;
117
+ syncUrl();
118
+ this.ctx.saveSession();
119
+ push();
120
+ });
121
+ wc.on('audio-state-changed', (e) => {
122
+ tab.audible = e.audible;
123
+ push();
124
+ });
125
+ wc.on('zoom-changed', push);
126
+ wc.on('did-fail-load', (_e, code, _desc, _url, isMainFrame) => {
127
+ if (!isMainFrame || code === -3)
128
+ return;
129
+ syncUrl();
130
+ push();
131
+ });
132
+ wc.on('destroyed', () => this.removeDead(tab));
133
+ wc.on('context-menu', (_e, params) => (0, context_menu_1.showPageMenu)(this.ctx, tab, params));
134
+ wc.on('will-navigate', guardExternal);
135
+ wc.on('will-redirect', guardExternal);
136
+ wc.setWindowOpenHandler((d) => this.openHandler(d));
137
+ }
138
+ openHandler({ url, disposition }) {
139
+ if (isExternal(url)) {
140
+ openExternal(url);
141
+ return { action: 'deny' };
142
+ }
143
+ if (disposition === 'new-window') {
144
+ return {
145
+ action: 'allow',
146
+ overrideBrowserWindowOptions: { autoHideMenuBar: true, backgroundColor: (0, window_1.bgColor)(), webPreferences: { sandbox: true, contextIsolation: true } },
147
+ };
148
+ }
149
+ return {
150
+ action: 'allow',
151
+ createWindow: ({ webContents }) => this.create({
152
+ webContents,
153
+ url: webContents ? undefined : url,
154
+ activate: disposition !== 'background-tab',
155
+ index: this.insertIndexAfterActive(),
156
+ }).wc,
157
+ };
158
+ }
159
+ insertIndexAfterActive() {
160
+ const i = this.list.findIndex((t) => t.id === this.activeId);
161
+ return i < 0 ? this.list.length : i + 1;
162
+ }
163
+ activate(id) {
164
+ const tab = this.get(id);
165
+ if (!tab)
166
+ return;
167
+ this.activeId = id;
168
+ for (const t of this.list)
169
+ t.view.setVisible(t === tab);
170
+ tab.view.setBounds(this.ctx.tabBounds());
171
+ this.ctx.ext.selectTab(tab.wc);
172
+ if (!this.ctx.overlay)
173
+ tab.wc.focus();
174
+ this.ctx.saveSession();
175
+ this.ctx.push();
176
+ }
177
+ focusActive() {
178
+ const t = this.active;
179
+ if (t && !t.wc.isDestroyed())
180
+ t.wc.focus();
181
+ }
182
+ close(id) {
183
+ const tab = this.get(id);
184
+ if (!tab)
185
+ return;
186
+ if ((0, url_1.isWebUrl)(tab.url))
187
+ this.closed.push(tab.url);
188
+ if (this.closed.length > CLOSED_CAP)
189
+ this.closed.shift();
190
+ this.removeFromList(tab);
191
+ this.detach(tab);
192
+ try {
193
+ this.ctx.ext.removeTab(tab.wc);
194
+ }
195
+ catch { }
196
+ if (!tab.wc.isDestroyed())
197
+ tab.wc.close();
198
+ }
199
+ // The webContents went away on its own: window.close() or crash cleanup.
200
+ removeDead(tab) {
201
+ if (!this.get(tab.id))
202
+ return;
203
+ this.removeFromList(tab);
204
+ this.detach(tab);
205
+ }
206
+ detach(tab) {
207
+ try {
208
+ this.ctx.win.contentView.removeChildView(tab.view);
209
+ }
210
+ catch { }
211
+ }
212
+ removeFromList(tab) {
213
+ const i = this.list.indexOf(tab);
214
+ if (i < 0)
215
+ return;
216
+ this.list.splice(i, 1);
217
+ if (this.ctx.quitting)
218
+ return;
219
+ const next = this.list[Math.min(i, this.list.length - 1)];
220
+ if (!next)
221
+ this.create();
222
+ else if (this.activeId === tab.id)
223
+ this.activate(next.id);
224
+ else {
225
+ this.ctx.saveSession();
226
+ this.ctx.push();
227
+ }
228
+ }
229
+ closeOthers(id) {
230
+ for (const t of this.list.filter((x) => x.id !== id))
231
+ this.close(t.id);
232
+ }
233
+ closeRight(id) {
234
+ const i = this.list.findIndex((t) => t.id === id);
235
+ for (const t of this.list.slice(i + 1))
236
+ this.close(t.id);
237
+ }
238
+ reopenClosed() {
239
+ const url = this.closed.pop();
240
+ if (url)
241
+ this.create({ url });
242
+ }
243
+ duplicate(id) {
244
+ const t = this.get(id);
245
+ if (!t)
246
+ return;
247
+ this.create({ url: t.url || undefined, index: this.list.indexOf(t) + 1 });
248
+ }
249
+ move(id, toIndex) {
250
+ const from = this.list.findIndex((t) => t.id === id);
251
+ if (from < 0)
252
+ return;
253
+ const [t] = this.list.splice(from, 1);
254
+ if (!t)
255
+ return;
256
+ this.list.splice(Math.max(0, Math.min(toIndex, this.list.length)), 0, t);
257
+ this.ctx.saveSession();
258
+ this.ctx.push();
259
+ }
260
+ step(delta) {
261
+ const n = this.list.length;
262
+ if (n < 2)
263
+ return;
264
+ const i = this.list.findIndex((t) => t.id === this.activeId);
265
+ const t = this.list[(i + delta + n) % n];
266
+ if (t)
267
+ this.activate(t.id);
268
+ }
269
+ // 1-based; 9 means the last tab.
270
+ goTo(n) {
271
+ const t = n === 9 ? this.list.at(-1) : this.list[n - 1];
272
+ if (t)
273
+ this.activate(t.id);
274
+ }
275
+ toggleMute(id) {
276
+ const t = this.get(id);
277
+ if (!t)
278
+ return;
279
+ t.muted = !t.muted;
280
+ t.wc.setAudioMuted(t.muted);
281
+ this.ctx.push();
282
+ }
283
+ open(url, { newTab }) {
284
+ const t = this.active;
285
+ if (newTab || !t)
286
+ return this.create({ url, index: this.insertIndexAfterActive() });
287
+ this.load(t, url);
288
+ this.activate(t.id);
289
+ return t;
290
+ }
291
+ layout() {
292
+ const b = this.ctx.tabBounds();
293
+ for (const t of this.list)
294
+ t.view.setBounds(b);
295
+ }
296
+ zoom(delta) {
297
+ const t = this.active;
298
+ if (!t)
299
+ return;
300
+ const f = delta === 0 ? 1 : Math.min(5, Math.max(0.25, Math.round((t.wc.getZoomFactor() + delta) * 100) / 100));
301
+ t.wc.setZoomFactor(f);
302
+ this.ctx.push();
303
+ }
304
+ snapshot() {
305
+ const a = this.active;
306
+ const live = a && !a.wc.isDestroyed() ? a.wc : null;
307
+ return {
308
+ tabs: this.list.map((t) => ({
309
+ id: t.id,
310
+ title: t.newTab ? 'New Tab' : t.title || t.url || 'Untitled',
311
+ url: t.url,
312
+ favicon: t.favicon,
313
+ loading: t.loading,
314
+ audible: t.audible,
315
+ muted: t.muted,
316
+ })),
317
+ activeTabId: this.activeId,
318
+ canGoBack: !!live && live.navigationHistory.canGoBack(),
319
+ canGoForward: !!live && live.navigationHistory.canGoForward(),
320
+ zoomFactor: live ? live.getZoomFactor() : 1,
321
+ };
322
+ }
323
+ }
324
+ exports.Tabs = Tabs;
@@ -0,0 +1,133 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UiWindow = void 0;
4
+ const electron_1 = require("electron");
5
+ const node_path_1 = require("node:path");
6
+ // The tab bar, omnibox and traffic lights live in this borderless child window over the page
7
+ // window. Content protection is per window, so keeping them out of the page window is what lets
8
+ // the page stay capturable while they don't.
9
+ class UiWindow {
10
+ win;
11
+ view;
12
+ parent;
13
+ wanted = false;
14
+ interactive = false;
15
+ // Relative to the parent's content area.
16
+ rect = { x: 0, y: 0, width: 0, height: 0 };
17
+ constructor(parent) {
18
+ this.parent = parent;
19
+ // A child window rather than a panel: it moves with the parent natively (no lag during a drag)
20
+ // and stays on the parent's Space, where a panel would float over every app and Space.
21
+ this.win = new electron_1.BaseWindow({
22
+ parent,
23
+ show: false,
24
+ frame: false,
25
+ transparent: true,
26
+ backgroundColor: '#00000000',
27
+ hasShadow: false,
28
+ roundedCorners: false,
29
+ resizable: false,
30
+ movable: false,
31
+ minimizable: false,
32
+ maximizable: false,
33
+ fullscreenable: false,
34
+ skipTaskbar: true,
35
+ // Clicks on the bar shouldn't pull keyboard focus off the page. focus() allows it while the
36
+ // omnibox is open.
37
+ focusable: false,
38
+ });
39
+ this.win.excludedFromShownWindowsMenu = true;
40
+ // This is what hides the UI from a share. A capture of the page window includes its child
41
+ // windows, and so does a full-display capture, but both skip a window whose sharingType is
42
+ // none. Checked with ScreenCaptureKit and screencapture on macOS 26.
43
+ this.win.setContentProtection(true);
44
+ this.win.setIgnoreMouseEvents(true, { forward: true });
45
+ this.view = new electron_1.WebContentsView({
46
+ webPreferences: {
47
+ // Non-persistent: it only serves the local UI. Extension icons load over crx://.
48
+ session: electron_1.session.fromPartition('stage-ui'),
49
+ preload: (0, node_path_1.join)(__dirname, '..', 'preload', 'ui-preload.js'),
50
+ contextIsolation: true,
51
+ sandbox: false,
52
+ nodeIntegration: false,
53
+ },
54
+ });
55
+ this.view.setBackgroundColor('#00000000');
56
+ this.win.contentView.addChildView(this.view);
57
+ const sync = () => this.sync();
58
+ parent
59
+ .on('move', sync)
60
+ .on('resize', sync)
61
+ .on('show', sync)
62
+ .on('hide', sync)
63
+ .on('minimize', sync)
64
+ .on('restore', sync)
65
+ .on('enter-full-screen', sync)
66
+ .on('leave-full-screen', sync)
67
+ .once('closed', () => this.destroy());
68
+ }
69
+ get shown() {
70
+ return this.wanted;
71
+ }
72
+ get live() {
73
+ return !this.win.isDestroyed() && !this.parent.isDestroyed();
74
+ }
75
+ setShown(shown) {
76
+ this.wanted = shown;
77
+ this.sync();
78
+ }
79
+ setBounds(rect) {
80
+ this.rect = rect;
81
+ this.sync();
82
+ }
83
+ // Off for the transparent shadow room under the floating bar, so the page gets those clicks.
84
+ setInteractive(on) {
85
+ if (on === this.interactive || !this.live)
86
+ return;
87
+ this.interactive = on;
88
+ // forward: mouse moves still reach the UI, so hover styles and mouseleave stay right.
89
+ this.win.setIgnoreMouseEvents(!on, { forward: true });
90
+ }
91
+ // Keyboard focus for the omnibox.
92
+ focus() {
93
+ if (!this.live)
94
+ return;
95
+ this.win.setFocusable(true);
96
+ this.win.focus();
97
+ this.view.webContents.focus();
98
+ }
99
+ // Hands keyboard focus back to the page window.
100
+ release() {
101
+ if (!this.live)
102
+ return;
103
+ const had = this.win.isFocused();
104
+ this.win.setFocusable(false);
105
+ if (had)
106
+ this.parent.focus();
107
+ }
108
+ // Shown only with its parent, at the parent's content origin. Child windows follow the parent on
109
+ // their own when it moves; this keeps size and visibility in step.
110
+ sync() {
111
+ if (!this.live)
112
+ return;
113
+ const { parent, win, rect } = this;
114
+ const show = this.wanted && parent.isVisible() && !parent.isMinimized() && rect.width > 0 && rect.height > 0;
115
+ if (!show) {
116
+ if (win.isVisible())
117
+ win.hide();
118
+ return;
119
+ }
120
+ const c = parent.getContentBounds();
121
+ win.setBounds({ x: c.x + rect.x, y: c.y + rect.y, width: rect.width, height: rect.height });
122
+ this.view.setBounds({ x: 0, y: 0, width: rect.width, height: rect.height });
123
+ if (!win.isVisible())
124
+ win.showInactive();
125
+ }
126
+ destroy() {
127
+ if (!this.view.webContents.isDestroyed())
128
+ this.view.webContents.close();
129
+ if (!this.win.isDestroyed())
130
+ this.win.destroy();
131
+ }
132
+ }
133
+ exports.UiWindow = UiWindow;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.searchUrl = searchUrl;
4
+ exports.resolveInput = resolveInput;
5
+ exports.classify = classify;
6
+ exports.isWebUrl = isWebUrl;
7
+ const SCHEME_SLASHES = /^[a-z][a-z0-9+.-]*:\/\//i;
8
+ const SCHEME_BARE = /^(about|data|mailto|view-source|blob|chrome-extension|file):/i;
9
+ const LOCAL = /^(localhost|\[[0-9a-f:]+\]|\d{1,3}(\.\d{1,3}){3})(:\d+)?([/?#].*)?$/i;
10
+ const DOTTED = /^[^\s/?#:]+\.[a-z][a-z0-9-]*(:\d+)?([/?#]\S*)?$/i;
11
+ const SEARCH_PREFIX = 'https://www.google.com/search?q=';
12
+ function searchUrl(query) {
13
+ return SEARCH_PREFIX + encodeURIComponent(query);
14
+ }
15
+ function resolveInput(input) {
16
+ const s = input.trim();
17
+ if (!s)
18
+ return null;
19
+ if (SCHEME_SLASHES.test(s) || SCHEME_BARE.test(s))
20
+ return s;
21
+ if (!/\s/.test(s)) {
22
+ if (LOCAL.test(s))
23
+ return 'http://' + s;
24
+ if (DOTTED.test(s))
25
+ return 'https://' + s;
26
+ }
27
+ return searchUrl(s);
28
+ }
29
+ function classify(input) {
30
+ const s = input.trim();
31
+ const url = resolveInput(s);
32
+ if (url === null)
33
+ return null;
34
+ return { url, kind: url.startsWith(SEARCH_PREFIX) && !s.startsWith('http') ? 'search' : 'url' };
35
+ }
36
+ function isWebUrl(url) {
37
+ return /^https?:\/\//i.test(url);
38
+ }
@@ -0,0 +1,133 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WindowDrag = exports.BAR_HEIGHT = void 0;
4
+ exports.bgColor = bgColor;
5
+ exports.createWindow = createWindow;
6
+ exports.tabBounds = tabBounds;
7
+ exports.uiBounds = uiBounds;
8
+ exports.windowAction = windowAction;
9
+ const electron_1 = require("electron");
10
+ exports.BAR_HEIGHT = 52;
11
+ // Transparent room under the floating bar so the capsule's shadow isn't clipped. The UI window lets
12
+ // the mouse through to the page there. Not used when pinned: the bar then stays up all the time, so
13
+ // it keeps to the strip.
14
+ const SHADOW_ROOM = 20;
15
+ const DRAG_TICK_MS = 8;
16
+ const DRAG_MAX_MS = 60_000;
17
+ const EMPTY = { x: 0, y: 0, width: 0, height: 0 };
18
+ function bgColor() {
19
+ return electron_1.nativeTheme.shouldUseDarkColors ? '#1c1c1e' : '#ffffff';
20
+ }
21
+ function initialBounds(saved) {
22
+ if (!saved?.width || !saved.height)
23
+ return { width: 1280, height: 800 };
24
+ const onScreen = electron_1.screen.getAllDisplays().some(({ workArea: a }) => {
25
+ return saved.x < a.x + a.width - 40 && saved.x + saved.width > a.x + 40 && saved.y >= a.y - 10 && saved.y < a.y + a.height - 40;
26
+ });
27
+ return onScreen ? saved : { width: saved.width, height: saved.height };
28
+ }
29
+ // The page window: only tab views live in it, so a single-window share shows nothing else.
30
+ function createWindow(saved, size) {
31
+ const win = new electron_1.BaseWindow({
32
+ ...initialBounds(saved),
33
+ useContentSize: size !== null,
34
+ minWidth: 480,
35
+ minHeight: 320,
36
+ show: false,
37
+ titleBarStyle: 'hidden',
38
+ backgroundColor: bgColor(),
39
+ });
40
+ if (size) {
41
+ win.setContentSize(size.width, size.height);
42
+ win.center();
43
+ }
44
+ // The native traffic lights are part of this window, so a window share would show them. The UI
45
+ // draws its own in the bar instead.
46
+ win.setWindowButtonVisibility(false);
47
+ return win;
48
+ }
49
+ function tabBounds(win) {
50
+ if (win.isDestroyed())
51
+ return EMPTY;
52
+ const [w = 0, h = 0] = win.getContentSize();
53
+ return { x: 0, y: 0, width: w, height: h };
54
+ }
55
+ // The UI window's bounds, relative to the page window's content area.
56
+ function uiBounds(win, pinned, overlay) {
57
+ const [w = 0, h = 0] = win.getContentSize();
58
+ return { x: 0, y: 0, width: w, height: overlay ? h : pinned ? exports.BAR_HEIGHT : exports.BAR_HEIGHT + SHADOW_ROOM };
59
+ }
60
+ function toggleZoom(win) {
61
+ if (win.isMaximized())
62
+ win.unmaximize();
63
+ else
64
+ win.maximize();
65
+ }
66
+ // What a title bar double-click does, per System Settings → Desktop & Dock.
67
+ function titleBarDoubleClick(win) {
68
+ const pref = electron_1.systemPreferences.getUserDefault('AppleActionOnDoubleClick', 'string');
69
+ if (pref === 'None')
70
+ return;
71
+ if (pref === 'Minimize')
72
+ win.minimize();
73
+ else
74
+ toggleZoom(win);
75
+ }
76
+ // The bar's drawn traffic lights and title-bar double-click, with macOS semantics: green toggles
77
+ // full screen, Option-green zooms.
78
+ function windowAction(win, action) {
79
+ if (win.isDestroyed())
80
+ return;
81
+ const full = win.isFullScreen();
82
+ if (action === 'close')
83
+ return win.close();
84
+ if (action === 'fullscreen')
85
+ return win.setFullScreen(!full);
86
+ if (full)
87
+ return; // minimize and zoom don't apply to a full-screen window
88
+ if (action === 'minimize')
89
+ win.minimize();
90
+ else if (action === 'zoom')
91
+ toggleZoom(win);
92
+ else if (action === 'double-click')
93
+ titleBarDoubleClick(win);
94
+ }
95
+ // Moves the page window with the cursor while the bar holds the mouse down. The bar lives in a
96
+ // child window, so -webkit-app-region would drag only the child; macOS then moves the child along
97
+ // with its parent, so the bar can't lag behind.
98
+ class WindowDrag {
99
+ win;
100
+ timer;
101
+ constructor(win) {
102
+ this.win = win;
103
+ }
104
+ get active() {
105
+ return this.timer !== undefined;
106
+ }
107
+ start() {
108
+ const { win } = this;
109
+ if (this.timer || win.isDestroyed() || win.isFullScreen())
110
+ return;
111
+ const p0 = electron_1.screen.getCursorScreenPoint();
112
+ const [x0 = 0, y0 = 0] = win.getPosition();
113
+ const started = Date.now();
114
+ let last = `${x0},${y0}`;
115
+ // A lost mouse-up can't leave the window stuck to the cursor for more than DRAG_MAX_MS.
116
+ this.timer = setInterval(() => {
117
+ if (Date.now() - started > DRAG_MAX_MS || win.isDestroyed())
118
+ return this.end();
119
+ const p = electron_1.screen.getCursorScreenPoint();
120
+ const x = x0 + p.x - p0.x;
121
+ const y = y0 + p.y - p0.y;
122
+ if (`${x},${y}` === last)
123
+ return;
124
+ last = `${x},${y}`;
125
+ win.setPosition(x, y);
126
+ }, DRAG_TICK_MS);
127
+ }
128
+ end() {
129
+ clearInterval(this.timer);
130
+ this.timer = undefined;
131
+ }
132
+ }
133
+ exports.WindowDrag = WindowDrag;