stage-browser 0.0.0-stage → 0.1.1
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/README.md +136 -2
- package/build/icon.icns +0 -0
- package/build/icon.png +0 -0
- package/dist/bin/stage.js +111 -0
- package/dist/main/cli-args.js +28 -0
- package/dist/main/context-menu.js +68 -0
- package/dist/main/context.js +2 -0
- package/dist/main/extensions.js +78 -0
- package/dist/main/ipc.js +90 -0
- package/dist/main/main.js +279 -0
- package/dist/main/menu.js +140 -0
- package/dist/main/reveal.js +155 -0
- package/dist/main/selftest.js +490 -0
- package/dist/main/store.js +85 -0
- package/dist/main/suggest.js +43 -0
- package/dist/main/tabs.js +324 -0
- package/dist/main/url.js +38 -0
- package/dist/main/window.js +68 -0
- package/dist/preload/extension-compat.js +163 -0
- package/dist/preload/ui-preload.js +33 -0
- package/dist/shared/contract.js +6 -0
- package/dist/ui/app.js +653 -0
- package/dist/ui/index.html +41 -0
- package/dist/ui/mock.js +479 -0
- package/dist/ui/newtab.html +69 -0
- package/dist/ui/styles.css +410 -0
- package/node_modules/@types/chrome/LICENSE +21 -0
- package/node_modules/@types/chrome/README.md +15 -0
- package/node_modules/@types/chrome/chrome-cast/index.d.ts +1156 -0
- package/node_modules/@types/chrome/har-format/index.d.ts +6 -0
- package/node_modules/@types/chrome/index.d.ts +13786 -0
- package/node_modules/@types/chrome/package.json +99 -0
- package/node_modules/@types/filesystem/LICENSE +21 -0
- package/node_modules/@types/filesystem/README.md +15 -0
- package/node_modules/@types/filesystem/index.d.ts +564 -0
- package/node_modules/@types/filesystem/package.json +26 -0
- package/node_modules/@types/filewriter/LICENSE +21 -0
- package/node_modules/@types/filewriter/README.md +15 -0
- package/node_modules/@types/filewriter/index.d.ts +166 -0
- package/node_modules/@types/filewriter/package.json +25 -0
- package/node_modules/@types/har-format/LICENSE +21 -0
- package/node_modules/@types/har-format/README.md +15 -0
- package/node_modules/@types/har-format/index.d.ts +938 -0
- package/node_modules/@types/har-format/package.json +31 -0
- package/node_modules/adm-zip/LICENSE +21 -0
- package/node_modules/adm-zip/README.md +90 -0
- package/node_modules/adm-zip/adm-zip.js +1020 -0
- package/node_modules/adm-zip/headers/entryHeader.js +396 -0
- package/node_modules/adm-zip/headers/index.js +2 -0
- package/node_modules/adm-zip/headers/mainHeader.js +177 -0
- package/node_modules/adm-zip/methods/deflater.js +33 -0
- package/node_modules/adm-zip/methods/index.js +3 -0
- package/node_modules/adm-zip/methods/inflater.js +64 -0
- package/node_modules/adm-zip/methods/zipcrypto.js +175 -0
- package/node_modules/adm-zip/package.json +56 -0
- package/node_modules/adm-zip/types.d.ts +223 -0
- package/node_modules/adm-zip/util/constants.js +142 -0
- package/node_modules/adm-zip/util/decoder.js +5 -0
- package/node_modules/adm-zip/util/errors.js +66 -0
- package/node_modules/adm-zip/util/fattr.js +76 -0
- package/node_modules/adm-zip/util/index.js +5 -0
- package/node_modules/adm-zip/util/utils.js +481 -0
- package/node_modules/adm-zip/zipEntry.js +415 -0
- package/node_modules/adm-zip/zipFile.js +466 -0
- package/node_modules/debug/LICENSE +20 -0
- package/node_modules/debug/README.md +481 -0
- package/node_modules/debug/package.json +64 -0
- package/node_modules/debug/src/browser.js +272 -0
- package/node_modules/debug/src/common.js +292 -0
- package/node_modules/debug/src/index.js +10 -0
- package/node_modules/debug/src/node.js +263 -0
- package/node_modules/electron-chrome-web-store/README.md +143 -0
- package/node_modules/electron-chrome-web-store/dist/chrome-web-store.preload.js +299 -0
- package/node_modules/electron-chrome-web-store/dist/cjs/browser/index.js +1674 -0
- package/node_modules/electron-chrome-web-store/dist/esm/browser/index.mjs +950 -0
- package/node_modules/electron-chrome-web-store/dist/types/browser/api.d.ts +2 -0
- package/node_modules/electron-chrome-web-store/dist/types/browser/crx3.d.ts +20 -0
- package/node_modules/electron-chrome-web-store/dist/types/browser/id.d.ts +9 -0
- package/node_modules/electron-chrome-web-store/dist/types/browser/index.d.ts +62 -0
- package/node_modules/electron-chrome-web-store/dist/types/browser/installer.d.ts +29 -0
- package/node_modules/electron-chrome-web-store/dist/types/browser/loader.d.ts +18 -0
- package/node_modules/electron-chrome-web-store/dist/types/browser/types.d.ts +21 -0
- package/node_modules/electron-chrome-web-store/dist/types/browser/updater.d.ts +6 -0
- package/node_modules/electron-chrome-web-store/dist/types/browser/utils.d.ts +4 -0
- package/node_modules/electron-chrome-web-store/dist/types/common/constants.d.ts +44 -0
- package/node_modules/electron-chrome-web-store/dist/types/renderer/chrome-web-store.preload.d.ts +1 -0
- package/node_modules/electron-chrome-web-store/package.json +43 -0
- package/node_modules/ms/index.js +162 -0
- package/node_modules/ms/license.md +21 -0
- package/node_modules/ms/package.json +38 -0
- package/node_modules/ms/readme.md +59 -0
- package/node_modules/pbf/LICENSE +27 -0
- package/node_modules/pbf/README.md +293 -0
- package/node_modules/pbf/bin/pbf +17 -0
- package/node_modules/pbf/compile.js +441 -0
- package/node_modules/pbf/dist/pbf-dev.js +838 -0
- package/node_modules/pbf/dist/pbf.js +1 -0
- package/node_modules/pbf/index.d.ts +206 -0
- package/node_modules/pbf/index.js +830 -0
- package/node_modules/pbf/package.json +63 -0
- package/node_modules/protocol-buffers-schema/.travis.yml +7 -0
- package/node_modules/protocol-buffers-schema/LICENSE +21 -0
- package/node_modules/protocol-buffers-schema/README.md +122 -0
- package/node_modules/protocol-buffers-schema/example.js +11 -0
- package/node_modules/protocol-buffers-schema/example.proto +13 -0
- package/node_modules/protocol-buffers-schema/index.js +6 -0
- package/node_modules/protocol-buffers-schema/package.json +31 -0
- package/node_modules/protocol-buffers-schema/parse.js +769 -0
- package/node_modules/protocol-buffers-schema/stringify.js +206 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/basic.json +90 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/basic.proto +11 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/comments.json +99 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/comments.proto +19 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/complex.json +125 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/complex.proto +30 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/enum.json +42 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/enum.proto +8 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/escaped-quotes.json +32 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/escaped-quotes.proto +3 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/extend.json +167 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/extend.proto +19 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/import.json +30 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/import.proto +6 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/map.json +33 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/map.proto +3 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/no-tags.proto +8 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/oneof.json +41 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/oneof.proto +6 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/option.json +364 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/option.proto +72 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/options.json +47 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/options.proto +8 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/pheromon-trajectories.proto +8 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/reserved.json +55 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/reserved.proto +17 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/search.json +30 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/search.proto +5 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/service.json +108 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/service.proto +30 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/valid-packed.proto +35 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/version.json +90 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/version.proto +13 -0
- package/node_modules/protocol-buffers-schema/test/index.js +157 -0
- package/node_modules/protocol-buffers-schema/tokenize.js +56 -0
- package/node_modules/resolve-protobuf-schema/.travis.yml +3 -0
- package/node_modules/resolve-protobuf-schema/LICENSE +21 -0
- package/node_modules/resolve-protobuf-schema/README.md +49 -0
- package/node_modules/resolve-protobuf-schema/index.js +50 -0
- package/node_modules/resolve-protobuf-schema/package.json +25 -0
- package/node_modules/resolve-protobuf-schema/test/a.proto +5 -0
- package/node_modules/resolve-protobuf-schema/test/b.proto +5 -0
- package/node_modules/resolve-protobuf-schema/test/c.proto +3 -0
- package/node_modules/resolve-protobuf-schema/test/index.js +49 -0
- package/package.json +64 -4
package/dist/ui/app.js
ADDED
|
@@ -0,0 +1,653 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// The tab capsule and omnibox. A classic script (the page's CSP only allows 'self'), so it has no
|
|
3
|
+
// imports. It talks to the main process only through window.stage; in a plain browser, mock.js fakes it.
|
|
4
|
+
{
|
|
5
|
+
const STRIP_LEFT = 84;
|
|
6
|
+
const STRIP_RIGHT = 12;
|
|
7
|
+
const CAPSULE_PAD = 8;
|
|
8
|
+
const TAB_MIN = 72;
|
|
9
|
+
const TAB_GAP = 2;
|
|
10
|
+
const DRAG_THRESHOLD = 4;
|
|
11
|
+
const SUGGEST_DEBOUNCE = 60;
|
|
12
|
+
const MAX_SUGGESTIONS = 8;
|
|
13
|
+
const CLOSE_ANIMATION_MS = 260;
|
|
14
|
+
const SETTLE_MS = 150;
|
|
15
|
+
const ICONS = {
|
|
16
|
+
close: '<svg viewBox="0 0 12 12" width="12" height="12" aria-hidden="true"><path d="M3 3l6 6M9 3L3 9" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"/></svg>',
|
|
17
|
+
newtab: '<svg viewBox="0 0 16 16" aria-hidden="true"><rect x="2.5" y="3.5" width="11" height="9" rx="2.5" fill="none" stroke="currentColor" stroke-width="1.3" stroke-dasharray="2.2 2"/></svg>',
|
|
18
|
+
speaker: '<svg class="on" viewBox="0 0 14 14" width="14" height="14" aria-hidden="true"><path d="M2.5 5.5h2l3-2.5v8l-3-2.5h-2z" fill="currentColor"/><path d="M9.5 5a3 3 0 0 1 0 4M11 3.5a5 5 0 0 1 0 7" fill="none" stroke="currentColor" stroke-width="1.2" stroke-linecap="round"/></svg>' +
|
|
19
|
+
'<svg class="off" viewBox="0 0 14 14" width="14" height="14" aria-hidden="true"><path d="M2.5 5.5h2l3-2.5v8l-3-2.5h-2z" fill="currentColor"/><path d="M9.5 5.5l3 3M12.5 5.5l-3 3" fill="none" stroke="currentColor" stroke-width="1.2" stroke-linecap="round"/></svg>',
|
|
20
|
+
search: '<svg viewBox="0 0 20 20" aria-hidden="true"><circle cx="9" cy="9" r="5.5" fill="none" stroke="currentColor" stroke-width="1.6"/><path d="M13.2 13.2L17 17" stroke="currentColor" stroke-width="1.6" stroke-linecap="round"/></svg>',
|
|
21
|
+
globe: '<svg viewBox="0 0 20 20" aria-hidden="true"><circle cx="10" cy="10" r="7" fill="none" stroke="currentColor" stroke-width="1.5"/><path d="M3 10h14M10 3c2.2 2.1 3.3 4.4 3.3 7s-1.1 4.9-3.3 7c-2.2-2.1-3.3-4.4-3.3-7S7.8 5.1 10 3z" fill="none" stroke="currentColor" stroke-width="1.3"/></svg>',
|
|
22
|
+
clock: '<svg viewBox="0 0 20 20" aria-hidden="true"><circle cx="10" cy="10" r="7" fill="none" stroke="currentColor" stroke-width="1.5"/><path d="M10 6v4.2l2.8 1.8" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/></svg>',
|
|
23
|
+
tab: '<svg viewBox="0 0 20 20" aria-hidden="true"><rect x="3" y="5" width="14" height="10.5" rx="2.5" fill="none" stroke="currentColor" stroke-width="1.5"/><path d="M3 8.5h14" stroke="currentColor" stroke-width="1.5"/></svg>',
|
|
24
|
+
};
|
|
25
|
+
const SUGGESTION_ICON = { search: 'search', url: 'globe', history: 'clock', tab: 'tab' };
|
|
26
|
+
const byId = (id, type) => {
|
|
27
|
+
const node = document.getElementById(id);
|
|
28
|
+
if (!(node instanceof type))
|
|
29
|
+
throw new Error(`#${id} is missing`);
|
|
30
|
+
return node;
|
|
31
|
+
};
|
|
32
|
+
const create = (tag, className) => {
|
|
33
|
+
const node = document.createElement(tag);
|
|
34
|
+
if (className)
|
|
35
|
+
node.className = className;
|
|
36
|
+
return node;
|
|
37
|
+
};
|
|
38
|
+
const child = (parent, selector, type) => {
|
|
39
|
+
const node = parent.querySelector(selector);
|
|
40
|
+
if (!(node instanceof type))
|
|
41
|
+
throw new Error(`${selector} is missing`);
|
|
42
|
+
return node;
|
|
43
|
+
};
|
|
44
|
+
const closest = (target, selector) => target instanceof Element ? target.closest(selector) : null;
|
|
45
|
+
const hostOf = (url) => {
|
|
46
|
+
try {
|
|
47
|
+
return new URL(url).hostname.replace(/^www\./, '');
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
return '';
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
const hashHue = (text) => {
|
|
54
|
+
let h = 0;
|
|
55
|
+
for (let i = 0; i < text.length; i++)
|
|
56
|
+
h = (h * 31 + text.charCodeAt(i)) >>> 0;
|
|
57
|
+
return h % 360;
|
|
58
|
+
};
|
|
59
|
+
const prettyUrl = (url) => url.replace(/^https?:\/\//i, '').replace(/^www\./i, '').replace(/\/$/, '');
|
|
60
|
+
const looksLikeUrl = (raw) => {
|
|
61
|
+
const v = raw.trim();
|
|
62
|
+
if (!v || /\s/.test(v))
|
|
63
|
+
return false;
|
|
64
|
+
return /^[a-z][a-z0-9+.-]*:\/\//i.test(v) || /^localhost(:\d+)?(\/|$)/i.test(v) || /^[^\s/]+\.[a-z]{2,}(:\d+)?(\/|$|\?)/i.test(v);
|
|
65
|
+
};
|
|
66
|
+
const translateX = (px) => (px ? `translateX(${px}px)` : '');
|
|
67
|
+
const tabIdOf = (node) => Number(node.dataset.id);
|
|
68
|
+
const tabFromEvent = (e) => {
|
|
69
|
+
const node = closest(e.target, '.tab');
|
|
70
|
+
return node && !node.classList.contains('closing') ? node : null;
|
|
71
|
+
};
|
|
72
|
+
const draggedSlot = (d) => {
|
|
73
|
+
const me = d.slots[d.index];
|
|
74
|
+
if (!me)
|
|
75
|
+
throw new Error('drag lost its tab');
|
|
76
|
+
return me;
|
|
77
|
+
};
|
|
78
|
+
const settleOffset = (d) => {
|
|
79
|
+
let dx = 0;
|
|
80
|
+
if (d.target > d.index)
|
|
81
|
+
for (let i = d.index + 1; i <= d.target; i++)
|
|
82
|
+
dx += (d.slots[i]?.width ?? 0) + TAB_GAP;
|
|
83
|
+
else
|
|
84
|
+
for (let i = d.target; i < d.index; i++)
|
|
85
|
+
dx -= (d.slots[i]?.width ?? 0) + TAB_GAP;
|
|
86
|
+
return dx;
|
|
87
|
+
};
|
|
88
|
+
const resetSlots = (d) => {
|
|
89
|
+
for (const s of d.slots) {
|
|
90
|
+
s.node.style.transform = '';
|
|
91
|
+
s.node.style.transition = '';
|
|
92
|
+
}
|
|
93
|
+
d.node.classList.remove('dragging');
|
|
94
|
+
};
|
|
95
|
+
const iconFor = (item) => item.favicon ? `<img alt="" draggable="false" src="${item.favicon.replace(/"/g, '"')}">` : ICONS[SUGGESTION_ICON[item.kind]];
|
|
96
|
+
const boot = (stage) => {
|
|
97
|
+
const root = document.documentElement;
|
|
98
|
+
const capsule = byId('capsule', HTMLElement);
|
|
99
|
+
const tabsEl = byId('tabs', HTMLElement);
|
|
100
|
+
const controlsEl = byId('controls', HTMLElement);
|
|
101
|
+
const newBtn = byId('new-tab', HTMLButtonElement);
|
|
102
|
+
const omni = byId('omni', HTMLElement);
|
|
103
|
+
const backdrop = byId('omni-backdrop', HTMLElement);
|
|
104
|
+
const panel = byId('omni-panel', HTMLElement);
|
|
105
|
+
const input = byId('omni-input', HTMLInputElement);
|
|
106
|
+
const list = byId('omni-list', HTMLElement);
|
|
107
|
+
const glyph = byId('omni-glyph', HTMLElement);
|
|
108
|
+
const views = new Map();
|
|
109
|
+
let state = null;
|
|
110
|
+
let drag = null;
|
|
111
|
+
let firstRender = true;
|
|
112
|
+
let layoutQueued = false;
|
|
113
|
+
const ob = { open: false, mode: 'new', initial: '', nonce: null, items: [], sel: 0, seq: 0, timer: undefined, answered: null };
|
|
114
|
+
const apply = (next) => {
|
|
115
|
+
const initial = state === null;
|
|
116
|
+
state = next;
|
|
117
|
+
renderBar(next, initial);
|
|
118
|
+
renderOverlay(next);
|
|
119
|
+
};
|
|
120
|
+
const liveTabNodes = () => Array.from(tabsEl.children).filter((c) => c instanceof HTMLElement && !c.classList.contains('closing'));
|
|
121
|
+
const renderBar = (s, initial) => {
|
|
122
|
+
if (initial) {
|
|
123
|
+
if (s.bar.visible) {
|
|
124
|
+
void capsule.offsetWidth;
|
|
125
|
+
root.classList.add('bar-visible');
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
root.classList.toggle('bar-visible', s.bar.visible);
|
|
130
|
+
}
|
|
131
|
+
root.classList.toggle('bar-pinned', s.bar.pinned);
|
|
132
|
+
root.classList.toggle('hide-ext', s.hideExtensionIcons);
|
|
133
|
+
root.classList.toggle('no-ext', !s.extensionActions);
|
|
134
|
+
renderTabs(s);
|
|
135
|
+
};
|
|
136
|
+
const renderTabs = (s) => {
|
|
137
|
+
const structural = !drag;
|
|
138
|
+
if (structural) {
|
|
139
|
+
const ids = new Set(s.tabs.map((t) => t.id));
|
|
140
|
+
for (const [id, view] of views)
|
|
141
|
+
if (!ids.has(id))
|
|
142
|
+
removeTab(id, view);
|
|
143
|
+
}
|
|
144
|
+
let prev = null;
|
|
145
|
+
for (const t of s.tabs) {
|
|
146
|
+
let view = views.get(t.id);
|
|
147
|
+
if (!view) {
|
|
148
|
+
if (!structural)
|
|
149
|
+
continue;
|
|
150
|
+
view = createTab(t, !firstRender);
|
|
151
|
+
views.set(t.id, view);
|
|
152
|
+
}
|
|
153
|
+
updateTab(view, t, t.id === s.activeTabId);
|
|
154
|
+
if (structural) {
|
|
155
|
+
let ref = prev ? prev.nextElementSibling : tabsEl.firstElementChild;
|
|
156
|
+
while (ref?.classList.contains('closing'))
|
|
157
|
+
ref = ref.nextElementSibling;
|
|
158
|
+
if (ref !== view.node)
|
|
159
|
+
tabsEl.insertBefore(view.node, ref);
|
|
160
|
+
prev = view.node;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
firstRender = false;
|
|
164
|
+
layoutTabs();
|
|
165
|
+
};
|
|
166
|
+
const createTab = (t, animate) => {
|
|
167
|
+
const node = create('div', 'tab');
|
|
168
|
+
node.setAttribute('role', 'tab');
|
|
169
|
+
node.dataset.id = String(t.id);
|
|
170
|
+
node.tabIndex = -1;
|
|
171
|
+
node.innerHTML =
|
|
172
|
+
`<span class="ico" data-k="blank"><img class="fav" alt="" draggable="false"><span class="mono" aria-hidden="true"></span><span class="spin" aria-hidden="true"></span><span class="blank">${ICONS.newtab}</span></span>` +
|
|
173
|
+
'<span class="title"></span>' +
|
|
174
|
+
`<span class="aud" aria-hidden="true">${ICONS.speaker}</span>` +
|
|
175
|
+
`<button class="close" type="button" tabindex="-1" aria-label="Close tab">${ICONS.close}</button>`;
|
|
176
|
+
const view = {
|
|
177
|
+
node,
|
|
178
|
+
ico: child(node, '.ico', HTMLSpanElement),
|
|
179
|
+
img: child(node, '.fav', HTMLImageElement),
|
|
180
|
+
mono: child(node, '.mono', HTMLSpanElement),
|
|
181
|
+
title: child(node, '.title', HTMLSpanElement),
|
|
182
|
+
aud: child(node, '.aud', HTMLSpanElement),
|
|
183
|
+
painted: {},
|
|
184
|
+
failedFavicon: null,
|
|
185
|
+
};
|
|
186
|
+
view.img.addEventListener('error', () => {
|
|
187
|
+
view.failedFavicon = view.painted.favicon ?? null;
|
|
188
|
+
const snapshot = state?.tabs.find((x) => x.id === t.id);
|
|
189
|
+
if (snapshot)
|
|
190
|
+
paintIcon(view, snapshot);
|
|
191
|
+
});
|
|
192
|
+
if (animate) {
|
|
193
|
+
node.classList.add('entering');
|
|
194
|
+
node.addEventListener('animationend', () => node.classList.remove('entering'), { once: true });
|
|
195
|
+
}
|
|
196
|
+
return view;
|
|
197
|
+
};
|
|
198
|
+
const paintIcon = (view, t) => {
|
|
199
|
+
let kind;
|
|
200
|
+
if (t.loading)
|
|
201
|
+
kind = 'spin';
|
|
202
|
+
else if (t.favicon && view.failedFavicon !== t.favicon) {
|
|
203
|
+
kind = 'img';
|
|
204
|
+
if (view.img.getAttribute('src') !== t.favicon)
|
|
205
|
+
view.img.setAttribute('src', t.favicon);
|
|
206
|
+
}
|
|
207
|
+
else if (t.url) {
|
|
208
|
+
kind = 'mono';
|
|
209
|
+
const host = hostOf(t.url) || t.url;
|
|
210
|
+
view.mono.textContent = /[a-z0-9]/i.exec(host)?.[0] ?? '•';
|
|
211
|
+
view.mono.style.setProperty('--h', String(hashHue(host)));
|
|
212
|
+
}
|
|
213
|
+
else
|
|
214
|
+
kind = 'blank';
|
|
215
|
+
if (view.ico.dataset.k !== kind)
|
|
216
|
+
view.ico.dataset.k = kind;
|
|
217
|
+
};
|
|
218
|
+
const updateTab = (view, t, active) => {
|
|
219
|
+
const { node, painted: p } = view;
|
|
220
|
+
if (p.title !== t.title || p.url !== t.url) {
|
|
221
|
+
const label = t.title || prettyUrl(t.url) || 'New Tab';
|
|
222
|
+
view.title.textContent = label;
|
|
223
|
+
node.setAttribute('aria-label', label);
|
|
224
|
+
}
|
|
225
|
+
if (p.favicon !== t.favicon || p.loading !== t.loading || p.url !== t.url)
|
|
226
|
+
paintIcon(view, t);
|
|
227
|
+
if (p.audible !== t.audible || p.muted !== t.muted) {
|
|
228
|
+
node.classList.toggle('has-aud', t.audible || t.muted);
|
|
229
|
+
view.aud.classList.toggle('is-muted', t.muted);
|
|
230
|
+
}
|
|
231
|
+
if (p.active !== active) {
|
|
232
|
+
node.classList.toggle('active', active);
|
|
233
|
+
node.setAttribute('aria-selected', String(active));
|
|
234
|
+
node.tabIndex = active ? 0 : -1;
|
|
235
|
+
if (active)
|
|
236
|
+
keepInView(node);
|
|
237
|
+
}
|
|
238
|
+
view.painted = { title: t.title, url: t.url, favicon: t.favicon, loading: t.loading, audible: t.audible, muted: t.muted, active };
|
|
239
|
+
};
|
|
240
|
+
const removeTab = (id, { node }) => {
|
|
241
|
+
views.delete(id);
|
|
242
|
+
if (matchMedia('(prefers-reduced-motion: reduce)').matches)
|
|
243
|
+
return node.remove();
|
|
244
|
+
node.classList.remove('entering');
|
|
245
|
+
node.classList.add('closing');
|
|
246
|
+
node.setAttribute('aria-hidden', 'true');
|
|
247
|
+
let done = false;
|
|
248
|
+
const finish = () => {
|
|
249
|
+
if (done)
|
|
250
|
+
return;
|
|
251
|
+
done = true;
|
|
252
|
+
node.remove();
|
|
253
|
+
layoutTabs();
|
|
254
|
+
};
|
|
255
|
+
node.addEventListener('animationend', finish, { once: true });
|
|
256
|
+
setTimeout(finish, CLOSE_ANIMATION_MS);
|
|
257
|
+
};
|
|
258
|
+
const keepInView = (node) => {
|
|
259
|
+
requestAnimationFrame(() => {
|
|
260
|
+
const l = node.offsetLeft;
|
|
261
|
+
const r = l + node.offsetWidth;
|
|
262
|
+
const vl = tabsEl.scrollLeft;
|
|
263
|
+
const vr = vl + tabsEl.clientWidth;
|
|
264
|
+
if (l < vl + 8)
|
|
265
|
+
tabsEl.scrollTo({ left: Math.max(0, l - 8), behavior: 'smooth' });
|
|
266
|
+
else if (r > vr - 8)
|
|
267
|
+
tabsEl.scrollTo({ left: r - tabsEl.clientWidth + 8, behavior: 'smooth' });
|
|
268
|
+
});
|
|
269
|
+
};
|
|
270
|
+
const layoutTabs = () => {
|
|
271
|
+
if (layoutQueued)
|
|
272
|
+
return;
|
|
273
|
+
layoutQueued = true;
|
|
274
|
+
requestAnimationFrame(() => {
|
|
275
|
+
layoutQueued = false;
|
|
276
|
+
const n = views.size;
|
|
277
|
+
const fixed = CAPSULE_PAD + newBtn.offsetWidth + controlsEl.offsetWidth + TAB_GAP * 2;
|
|
278
|
+
const avail = root.clientWidth - STRIP_LEFT - STRIP_RIGHT - fixed;
|
|
279
|
+
tabsEl.classList.toggle('compact', n > 1 && n * TAB_MIN + (n - 1) * TAB_GAP > avail);
|
|
280
|
+
updateFades();
|
|
281
|
+
});
|
|
282
|
+
};
|
|
283
|
+
const updateFades = () => {
|
|
284
|
+
const max = tabsEl.scrollWidth - tabsEl.clientWidth;
|
|
285
|
+
tabsEl.classList.toggle('fade-l', tabsEl.scrollLeft > 1);
|
|
286
|
+
tabsEl.classList.toggle('fade-r', max > 1 && tabsEl.scrollLeft < max - 1);
|
|
287
|
+
};
|
|
288
|
+
const beginDrag = (d) => {
|
|
289
|
+
const nodes = liveTabNodes();
|
|
290
|
+
const slots = nodes.map((node) => {
|
|
291
|
+
const r = node.getBoundingClientRect();
|
|
292
|
+
return { node, left: r.left, width: r.width, center: r.left + r.width / 2 };
|
|
293
|
+
});
|
|
294
|
+
const index = nodes.indexOf(d.node);
|
|
295
|
+
const me = slots[index];
|
|
296
|
+
const first = slots[0];
|
|
297
|
+
const last = slots.at(-1);
|
|
298
|
+
if (!me || !first || !last)
|
|
299
|
+
throw new Error('dragged tab is not in the strip');
|
|
300
|
+
d.node.classList.add('dragging');
|
|
301
|
+
try {
|
|
302
|
+
d.node.setPointerCapture(d.pointerId);
|
|
303
|
+
}
|
|
304
|
+
catch { }
|
|
305
|
+
document.body.style.cursor = 'grabbing';
|
|
306
|
+
return { ...d, started: true, slots, index, target: index, minDx: first.left - me.left, maxDx: last.left + last.width - me.width - me.left };
|
|
307
|
+
};
|
|
308
|
+
const onDragMove = (e) => {
|
|
309
|
+
if (!drag)
|
|
310
|
+
return;
|
|
311
|
+
const raw = e.clientX - drag.startX + (tabsEl.scrollLeft - drag.startScroll);
|
|
312
|
+
if (!drag.started) {
|
|
313
|
+
if (Math.abs(raw) < DRAG_THRESHOLD)
|
|
314
|
+
return;
|
|
315
|
+
drag = beginDrag(drag);
|
|
316
|
+
}
|
|
317
|
+
const d = drag;
|
|
318
|
+
const me = draggedSlot(d);
|
|
319
|
+
const dx = Math.max(d.minDx, Math.min(d.maxDx, raw));
|
|
320
|
+
d.node.style.transform = translateX(dx);
|
|
321
|
+
const center = me.center + dx;
|
|
322
|
+
const target = d.slots.filter((s, i) => i !== d.index && s.center < center).length;
|
|
323
|
+
if (target === d.target)
|
|
324
|
+
return;
|
|
325
|
+
d.target = target;
|
|
326
|
+
const w = me.width + TAB_GAP;
|
|
327
|
+
d.slots.forEach((s, i) => {
|
|
328
|
+
if (i === d.index)
|
|
329
|
+
return;
|
|
330
|
+
let shift = 0;
|
|
331
|
+
if (target > d.index && i > d.index && i <= target)
|
|
332
|
+
shift = -w;
|
|
333
|
+
else if (target < d.index && i >= target && i < d.index)
|
|
334
|
+
shift = w;
|
|
335
|
+
s.node.style.transform = translateX(shift);
|
|
336
|
+
});
|
|
337
|
+
};
|
|
338
|
+
const stopListening = () => {
|
|
339
|
+
window.removeEventListener('pointermove', onDragMove);
|
|
340
|
+
window.removeEventListener('pointerup', onDragEnd);
|
|
341
|
+
window.removeEventListener('pointercancel', onDragCancel);
|
|
342
|
+
document.body.style.cursor = '';
|
|
343
|
+
};
|
|
344
|
+
const onDragEnd = () => {
|
|
345
|
+
const d = drag;
|
|
346
|
+
if (!d)
|
|
347
|
+
return;
|
|
348
|
+
stopListening();
|
|
349
|
+
if (!d.started) {
|
|
350
|
+
drag = null;
|
|
351
|
+
if (d.wasActive)
|
|
352
|
+
stage.openOmnibox('edit');
|
|
353
|
+
return;
|
|
354
|
+
}
|
|
355
|
+
d.node.style.transition = 'transform 140ms var(--ease-out), background-color 140ms ease, box-shadow 140ms ease';
|
|
356
|
+
d.node.style.transform = translateX(settleOffset(d));
|
|
357
|
+
setTimeout(() => commitDrag(d), SETTLE_MS);
|
|
358
|
+
};
|
|
359
|
+
const commitDrag = (d) => {
|
|
360
|
+
tabsEl.classList.add('no-anim');
|
|
361
|
+
const others = d.slots.filter((_, i) => i !== d.index);
|
|
362
|
+
tabsEl.insertBefore(d.node, others[d.target]?.node ?? null);
|
|
363
|
+
resetSlots(d);
|
|
364
|
+
void tabsEl.offsetWidth;
|
|
365
|
+
tabsEl.classList.remove('no-anim');
|
|
366
|
+
drag = null;
|
|
367
|
+
if (d.target !== d.index)
|
|
368
|
+
stage.moveTab(d.id, d.target);
|
|
369
|
+
if (state)
|
|
370
|
+
renderTabs(state);
|
|
371
|
+
};
|
|
372
|
+
const onDragCancel = () => {
|
|
373
|
+
const d = drag;
|
|
374
|
+
if (!d)
|
|
375
|
+
return;
|
|
376
|
+
stopListening();
|
|
377
|
+
if (d.started)
|
|
378
|
+
resetSlots(d);
|
|
379
|
+
drag = null;
|
|
380
|
+
if (state)
|
|
381
|
+
renderTabs(state);
|
|
382
|
+
};
|
|
383
|
+
const renderOverlay = (s) => {
|
|
384
|
+
const o = s.overlay?.type === 'omnibox' ? s.overlay : null;
|
|
385
|
+
if (!o) {
|
|
386
|
+
if (ob.open)
|
|
387
|
+
closeOmnibox();
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
390
|
+
if (!ob.open || ob.mode !== o.mode || ob.initial !== o.initial || ob.nonce !== o.nonce)
|
|
391
|
+
openOmnibox(o);
|
|
392
|
+
};
|
|
393
|
+
const openOmnibox = (o) => {
|
|
394
|
+
const wasOpen = ob.open;
|
|
395
|
+
Object.assign(ob, { open: true, mode: o.mode, initial: o.initial, nonce: o.nonce, items: [], sel: 0, answered: null });
|
|
396
|
+
omni.hidden = false;
|
|
397
|
+
if (!wasOpen) {
|
|
398
|
+
for (const n of [panel, backdrop]) {
|
|
399
|
+
n.style.animation = 'none';
|
|
400
|
+
void n.offsetWidth;
|
|
401
|
+
n.style.animation = '';
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
input.value = ob.initial;
|
|
405
|
+
updateGlyph();
|
|
406
|
+
renderList();
|
|
407
|
+
input.focus();
|
|
408
|
+
input.select();
|
|
409
|
+
requestSuggest(ob.initial, true);
|
|
410
|
+
};
|
|
411
|
+
const closeOmnibox = () => {
|
|
412
|
+
ob.open = false;
|
|
413
|
+
ob.seq++;
|
|
414
|
+
clearTimeout(ob.timer);
|
|
415
|
+
ob.items = [];
|
|
416
|
+
omni.hidden = true;
|
|
417
|
+
omni.classList.remove('cmd');
|
|
418
|
+
list.textContent = '';
|
|
419
|
+
input.blur();
|
|
420
|
+
};
|
|
421
|
+
const updateGlyph = () => {
|
|
422
|
+
glyph.innerHTML = looksLikeUrl(input.value) ? ICONS.globe : ICONS.search;
|
|
423
|
+
};
|
|
424
|
+
const requestSuggest = (query, immediate) => {
|
|
425
|
+
clearTimeout(ob.timer);
|
|
426
|
+
const mine = ++ob.seq;
|
|
427
|
+
const run = async () => {
|
|
428
|
+
const res = await stage.suggest(query).catch(() => null);
|
|
429
|
+
if (!res || mine !== ob.seq || !ob.open)
|
|
430
|
+
return;
|
|
431
|
+
ob.items = res.slice(0, MAX_SUGGESTIONS);
|
|
432
|
+
ob.answered = query;
|
|
433
|
+
ob.sel = 0;
|
|
434
|
+
renderList();
|
|
435
|
+
};
|
|
436
|
+
if (immediate)
|
|
437
|
+
void run();
|
|
438
|
+
else
|
|
439
|
+
ob.timer = setTimeout(() => void run(), SUGGEST_DEBOUNCE);
|
|
440
|
+
};
|
|
441
|
+
const renderList = () => {
|
|
442
|
+
list.textContent = '';
|
|
443
|
+
input.setAttribute('aria-expanded', String(ob.items.length > 0));
|
|
444
|
+
ob.items.forEach((item, i) => {
|
|
445
|
+
const row = create('div', item.kind === 'tab' ? 'row is-tab' : 'row');
|
|
446
|
+
row.id = `omni-row-${i}`;
|
|
447
|
+
row.setAttribute('role', 'option');
|
|
448
|
+
let url = item.kind === 'search' ? '' : prettyUrl(item.url);
|
|
449
|
+
const title = item.title || url;
|
|
450
|
+
if (url === title)
|
|
451
|
+
url = '';
|
|
452
|
+
const hint = item.kind === 'tab'
|
|
453
|
+
? '<span>Switch to tab</span><kbd>↵</kbd>'
|
|
454
|
+
: '<span class="h-ret"><kbd>↵</kbd></span><span class="h-cmd"><span>New tab</span><kbd>⌘↵</kbd></span>';
|
|
455
|
+
row.innerHTML = `<span class="r-ico">${iconFor(item)}</span><span class="r-title"></span><span class="r-url"></span><span class="hint">${hint}</span>`;
|
|
456
|
+
child(row, '.r-title', HTMLSpanElement).textContent = title;
|
|
457
|
+
child(row, '.r-url', HTMLSpanElement).textContent = url;
|
|
458
|
+
const img = row.querySelector('.r-ico img');
|
|
459
|
+
img?.addEventListener('error', () => {
|
|
460
|
+
if (img.parentElement)
|
|
461
|
+
img.parentElement.innerHTML = ICONS[item.kind === 'tab' ? 'tab' : 'globe'];
|
|
462
|
+
});
|
|
463
|
+
row.addEventListener('mousedown', (e) => e.preventDefault());
|
|
464
|
+
row.addEventListener('mousemove', () => {
|
|
465
|
+
if (ob.sel !== i)
|
|
466
|
+
select(i, false);
|
|
467
|
+
});
|
|
468
|
+
row.addEventListener('click', (e) => commit(item, e.metaKey));
|
|
469
|
+
list.appendChild(row);
|
|
470
|
+
});
|
|
471
|
+
paintSelection(false);
|
|
472
|
+
};
|
|
473
|
+
const paintSelection = (scroll) => {
|
|
474
|
+
const rows = Array.from(list.children);
|
|
475
|
+
rows.forEach((row, i) => {
|
|
476
|
+
const on = i === ob.sel;
|
|
477
|
+
row.classList.toggle('sel', on);
|
|
478
|
+
row.setAttribute('aria-selected', String(on));
|
|
479
|
+
if (!on)
|
|
480
|
+
return;
|
|
481
|
+
input.setAttribute('aria-activedescendant', row.id);
|
|
482
|
+
if (scroll)
|
|
483
|
+
row.scrollIntoView({ block: 'nearest' });
|
|
484
|
+
});
|
|
485
|
+
if (!rows.length)
|
|
486
|
+
input.removeAttribute('aria-activedescendant');
|
|
487
|
+
};
|
|
488
|
+
const select = (i, scroll = true) => {
|
|
489
|
+
const n = ob.items.length;
|
|
490
|
+
if (!n)
|
|
491
|
+
return;
|
|
492
|
+
ob.sel = (i + n) % n;
|
|
493
|
+
paintSelection(scroll);
|
|
494
|
+
};
|
|
495
|
+
const commit = (item, cmd) => {
|
|
496
|
+
if (item?.kind === 'tab') {
|
|
497
|
+
stage.activateTab(item.tabId);
|
|
498
|
+
stage.closeOverlay();
|
|
499
|
+
return;
|
|
500
|
+
}
|
|
501
|
+
const text = item ? item.url : input.value;
|
|
502
|
+
if (!text)
|
|
503
|
+
return stage.closeOverlay();
|
|
504
|
+
stage.submitOmnibox(text, { newTab: ob.mode === 'new' || cmd });
|
|
505
|
+
};
|
|
506
|
+
stage.getState().then(apply, () => { });
|
|
507
|
+
stage.onState(apply);
|
|
508
|
+
// When the bar floats over the page, the view reaches below the strip so the capsule's shadow
|
|
509
|
+
// isn't clipped. Clicks in that transparent band belong to the page underneath.
|
|
510
|
+
document.addEventListener('pointerdown', (e) => {
|
|
511
|
+
if (e.target !== document.body && e.target !== root)
|
|
512
|
+
return;
|
|
513
|
+
if (!state || state.overlay || e.clientY < state.barHeight)
|
|
514
|
+
return;
|
|
515
|
+
e.preventDefault();
|
|
516
|
+
stage.passClick(e.clientX, e.clientY, e.button, e.detail || 1);
|
|
517
|
+
}, true);
|
|
518
|
+
tabsEl.addEventListener('scroll', updateFades, { passive: true });
|
|
519
|
+
tabsEl.addEventListener('wheel', (e) => {
|
|
520
|
+
if (Math.abs(e.deltaY) <= Math.abs(e.deltaX))
|
|
521
|
+
return;
|
|
522
|
+
tabsEl.scrollLeft += e.deltaY;
|
|
523
|
+
e.preventDefault();
|
|
524
|
+
}, { passive: false });
|
|
525
|
+
window.addEventListener('resize', layoutTabs);
|
|
526
|
+
new ResizeObserver(layoutTabs).observe(controlsEl);
|
|
527
|
+
tabsEl.addEventListener('mousedown', (e) => {
|
|
528
|
+
if (e.button === 1)
|
|
529
|
+
e.preventDefault();
|
|
530
|
+
});
|
|
531
|
+
tabsEl.addEventListener('auxclick', (e) => {
|
|
532
|
+
const node = e.button === 1 ? tabFromEvent(e) : null;
|
|
533
|
+
if (!node)
|
|
534
|
+
return;
|
|
535
|
+
e.preventDefault();
|
|
536
|
+
stage.closeTab(tabIdOf(node));
|
|
537
|
+
});
|
|
538
|
+
tabsEl.addEventListener('contextmenu', (e) => {
|
|
539
|
+
e.preventDefault();
|
|
540
|
+
const node = tabFromEvent(e);
|
|
541
|
+
if (node)
|
|
542
|
+
stage.showTabMenu(tabIdOf(node));
|
|
543
|
+
});
|
|
544
|
+
tabsEl.addEventListener('click', (e) => {
|
|
545
|
+
const node = closest(e.target, '.close') ? tabFromEvent(e) : null;
|
|
546
|
+
if (!node)
|
|
547
|
+
return;
|
|
548
|
+
e.stopPropagation();
|
|
549
|
+
stage.closeTab(tabIdOf(node));
|
|
550
|
+
});
|
|
551
|
+
tabsEl.addEventListener('keydown', (e) => {
|
|
552
|
+
const node = tabFromEvent(e);
|
|
553
|
+
if (!node)
|
|
554
|
+
return;
|
|
555
|
+
const id = tabIdOf(node);
|
|
556
|
+
if (e.key === 'Enter' || e.key === ' ') {
|
|
557
|
+
e.preventDefault();
|
|
558
|
+
if (node.classList.contains('active'))
|
|
559
|
+
stage.openOmnibox('edit');
|
|
560
|
+
else
|
|
561
|
+
stage.activateTab(id);
|
|
562
|
+
}
|
|
563
|
+
else if (e.key === 'ArrowRight' || e.key === 'ArrowLeft') {
|
|
564
|
+
const nodes = liveTabNodes();
|
|
565
|
+
const next = nodes[nodes.indexOf(node) + (e.key === 'ArrowRight' ? 1 : -1)];
|
|
566
|
+
if (!next)
|
|
567
|
+
return;
|
|
568
|
+
e.preventDefault();
|
|
569
|
+
next.focus();
|
|
570
|
+
}
|
|
571
|
+
else if (e.key === 'Delete' || e.key === 'Backspace') {
|
|
572
|
+
e.preventDefault();
|
|
573
|
+
stage.closeTab(id);
|
|
574
|
+
}
|
|
575
|
+
});
|
|
576
|
+
tabsEl.addEventListener('pointerdown', (e) => {
|
|
577
|
+
if (e.button !== 0 || drag || closest(e.target, '.close'))
|
|
578
|
+
return;
|
|
579
|
+
const node = tabFromEvent(e);
|
|
580
|
+
if (!node)
|
|
581
|
+
return;
|
|
582
|
+
const id = tabIdOf(node);
|
|
583
|
+
const wasActive = state?.activeTabId === id;
|
|
584
|
+
if (!wasActive)
|
|
585
|
+
stage.activateTab(id);
|
|
586
|
+
drag = { started: false, id, node, startX: e.clientX, startScroll: tabsEl.scrollLeft, wasActive, pointerId: e.pointerId };
|
|
587
|
+
window.addEventListener('pointermove', onDragMove);
|
|
588
|
+
window.addEventListener('pointerup', onDragEnd);
|
|
589
|
+
window.addEventListener('pointercancel', onDragCancel);
|
|
590
|
+
});
|
|
591
|
+
newBtn.addEventListener('click', () => stage.openOmnibox('new'));
|
|
592
|
+
capsule.addEventListener('mouseenter', () => stage.setBarHover(true));
|
|
593
|
+
capsule.addEventListener('mouseleave', () => stage.setBarHover(false));
|
|
594
|
+
input.addEventListener('input', () => {
|
|
595
|
+
updateGlyph();
|
|
596
|
+
requestSuggest(input.value, false);
|
|
597
|
+
});
|
|
598
|
+
input.addEventListener('keydown', (e) => {
|
|
599
|
+
if (e.isComposing)
|
|
600
|
+
return;
|
|
601
|
+
if (e.key === 'Meta')
|
|
602
|
+
omni.classList.add('cmd');
|
|
603
|
+
if (e.key === 'ArrowDown' || e.key === 'ArrowUp') {
|
|
604
|
+
e.preventDefault();
|
|
605
|
+
select(ob.sel + (e.key === 'ArrowDown' ? 1 : -1));
|
|
606
|
+
}
|
|
607
|
+
else if (e.key === 'Enter') {
|
|
608
|
+
e.preventDefault();
|
|
609
|
+
// Suggestions answer older text until they catch up, so submit exactly what is typed.
|
|
610
|
+
const item = ob.answered === input.value ? ob.items[ob.sel] : undefined;
|
|
611
|
+
if (!item && !input.value.trim())
|
|
612
|
+
return stage.closeOverlay();
|
|
613
|
+
commit(item, e.metaKey);
|
|
614
|
+
}
|
|
615
|
+
else if (e.key === 'Escape') {
|
|
616
|
+
e.preventDefault();
|
|
617
|
+
stage.closeOverlay();
|
|
618
|
+
}
|
|
619
|
+
});
|
|
620
|
+
window.addEventListener('keydown', (e) => {
|
|
621
|
+
if (e.key === 'Meta' && ob.open)
|
|
622
|
+
omni.classList.add('cmd');
|
|
623
|
+
if (e.key === 'Escape' && ob.open && e.target !== input)
|
|
624
|
+
stage.closeOverlay();
|
|
625
|
+
});
|
|
626
|
+
window.addEventListener('keyup', (e) => {
|
|
627
|
+
if (e.key === 'Meta')
|
|
628
|
+
omni.classList.remove('cmd');
|
|
629
|
+
});
|
|
630
|
+
window.addEventListener('blur', () => omni.classList.remove('cmd'));
|
|
631
|
+
window.addEventListener('focus', () => {
|
|
632
|
+
if (ob.open)
|
|
633
|
+
input.focus();
|
|
634
|
+
});
|
|
635
|
+
backdrop.addEventListener('mousedown', () => stage.closeOverlay());
|
|
636
|
+
omni.addEventListener('mousedown', (e) => {
|
|
637
|
+
if (e.target !== input && e.target instanceof Node && panel.contains(e.target))
|
|
638
|
+
e.preventDefault();
|
|
639
|
+
});
|
|
640
|
+
};
|
|
641
|
+
const start = () => {
|
|
642
|
+
if (window.stage)
|
|
643
|
+
boot(window.stage);
|
|
644
|
+
};
|
|
645
|
+
if (window.stage)
|
|
646
|
+
start();
|
|
647
|
+
else {
|
|
648
|
+
const mock = document.createElement('script');
|
|
649
|
+
mock.src = 'mock.js';
|
|
650
|
+
mock.addEventListener('load', start, { once: true });
|
|
651
|
+
document.head.appendChild(mock);
|
|
652
|
+
}
|
|
653
|
+
}
|