dsh-workspace-browser 0.0.0-stage → 0.4.13
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/LICENSE +21 -0
- package/README.md +40 -2
- package/cordis.patch.yml +3 -0
- package/lib/client.js +1378 -0
- package/lib/index.js +2 -0
- package/package.json +38 -4
- package/scripts/build.mjs +37 -0
- package/src/browser.css +439 -0
- package/src/client.js +1087 -0
- package/src/folder.svg +4 -0
- package/src/gesture.css +30 -0
- package/src/large-icons.svg +6 -0
- package/src/list-view.svg +6 -0
- package/src/menu-folder.svg +7 -0
- package/src/mouse-gestures.js +273 -0
- package/src/session.svg +6 -0
package/src/folder.svg
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
<svg width="45" height="41" viewBox="0 0 45 41" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
+
<path d="M0 5.5C0 2.5 1.5 0 5.5 0H13C15.5 0 17 1 18.5 2.5L21.5 5.5C22.5 6.5 24 7 25.5 7H40.5C43 7 45 9 45 11V37C45 39 43.5 41 41 41H5C2.5 41 0 39 0 36.5V5.5Z" fill="#C3C3C3"/>
|
|
3
|
+
<rect x="3.5" y="10.5" width="38" height="4" rx="1.5" fill="#F9FAFB"/>
|
|
4
|
+
</svg>
|
package/src/gesture.css
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
[data-dwb-mouse-gesture-tracking] :is(iframe, webview, object, embed) { pointer-events: none !important; }
|
|
2
|
+
[data-dwb-mouse-gesture-dragging] .dwb-mouse-gesture { pointer-events: auto; cursor: default; }
|
|
3
|
+
.dwb-mouse-gesture {
|
|
4
|
+
position: fixed; inset: 0; z-index: 2147483647;
|
|
5
|
+
display: grid; place-items: center; pointer-events: none; user-select: none;
|
|
6
|
+
}
|
|
7
|
+
.dwb-mouse-gesture > * { pointer-events: none; }
|
|
8
|
+
.dwb-mouse-gesture-trail {
|
|
9
|
+
position: absolute; inset: 0; width: 100%; height: 100%;
|
|
10
|
+
fill: none; stroke: #3262E9; stroke-width: 6px; stroke-linecap: round; stroke-linejoin: round;
|
|
11
|
+
}
|
|
12
|
+
.dwb-mouse-gesture[data-stable-click] .dwb-mouse-gesture-trail { visibility: hidden; }
|
|
13
|
+
.dwb-mouse-gesture[data-finished] .dwb-mouse-gesture-trail {
|
|
14
|
+
animation: dwb-mouse-gesture-trail-fade 220ms ease-out forwards;
|
|
15
|
+
}
|
|
16
|
+
@keyframes dwb-mouse-gesture-trail-fade { to { opacity: 0; } }
|
|
17
|
+
.dwb-mouse-gesture-badge {
|
|
18
|
+
position: absolute; left: var(--dwb-gesture-badge-x); top: var(--dwb-gesture-badge-y);
|
|
19
|
+
transform: translate(-50%, -50%);
|
|
20
|
+
display: none; flex-direction: column; align-items: center; justify-content: center;
|
|
21
|
+
width: 112px; height: 112px; gap: 8px; border-radius: 20px;
|
|
22
|
+
background: rgb(0 0 0 / 74%); color: white; font-size: 14px; font-weight: 600; line-height: 1.25;
|
|
23
|
+
}
|
|
24
|
+
.dwb-mouse-gesture[data-action] .dwb-mouse-gesture-badge { display: flex; }
|
|
25
|
+
.dwb-mouse-gesture-badge svg {
|
|
26
|
+
width: 46px; height: 46px; fill: none; stroke: currentColor; stroke-width: 2;
|
|
27
|
+
stroke-linecap: round; stroke-linejoin: round;
|
|
28
|
+
}
|
|
29
|
+
.dwb-mouse-gesture[data-action="left"] .dwb-mouse-gesture-badge svg { transform: rotate(180deg); }
|
|
30
|
+
.dwb-mouse-gesture[data-action="up"] .dwb-mouse-gesture-badge svg { transform: rotate(-90deg); }
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
<svg width="55" height="55" viewBox="0 0 55 55" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
+
<rect x="10.5" y="10.5" width="15" height="15" rx="4.5" stroke-width="3" stroke="#61666B"/>
|
|
3
|
+
<rect x="10.5" y="30.5" width="15" height="15" rx="4.5" stroke-width="3" stroke="#61666B"/>
|
|
4
|
+
<rect x="30.5" y="10.5" width="15" height="15" rx="4.5" stroke-width="3" stroke="#61666B"/>
|
|
5
|
+
<rect x="30.5" y="30.5" width="15" height="15" rx="4.5" stroke-width="3" stroke="#61666B"/>
|
|
6
|
+
</svg>
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
<svg width="55" height="55" viewBox="0 0 55 55" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
+
<line x1="8.5" y1="15.5" x2="47.5" y2="15.5" stroke-width="3" stroke-linecap="round" stroke="#61666B"/>
|
|
3
|
+
<line x1="8.5" y1="24.5" x2="47.5" y2="24.5" stroke-width="3" stroke-linecap="round" stroke="#61666B"/>
|
|
4
|
+
<line x1="8.5" y1="33.5" x2="47.5" y2="33.5" stroke-width="3" stroke-linecap="round" stroke="#61666B"/>
|
|
5
|
+
<line x1="8.5" y1="42.5" x2="47.5" y2="42.5" stroke-width="3" stroke-linecap="round" stroke="#61666B"/>
|
|
6
|
+
</svg>
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
<svg width="55" height="55" viewBox="0 0 55 55" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
+
<mask id="stroke0_98_304" fill="white">
|
|
3
|
+
<path d="M5 12.5C5 9.5 6.5 7 10.5 7H18C20.5 7 22 8 23.5 9.5L26.5 12.5C27.5 13.5 29 14 30.5 14H45.5C48 14 50 16 50 18V44C50 46 48.5 48 46 48H10C7.5 48 5 46 5 43.5V12.5Z"/>
|
|
4
|
+
</mask>
|
|
5
|
+
<path d="M10.5 7C6.5 7 5 9.5 5 12.5V43.5C5 46 7.5 48 10 48H46C48.5 48 50 46 50 44V18C50 16 48 14 45.5 14H30.5C29 14 27.5 13.5 26.5 12.5L23.5 9.5C22 8 20.5 7 18 7H10.5Z" stroke-width="6" stroke="#61666B" mask="url(#stroke0_98_304)"/>
|
|
6
|
+
<rect x="11" y="20" width="33" height="22" rx="1.5" fill="#C3C3C3"/>
|
|
7
|
+
</svg>
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
const dragDistance = 2;
|
|
2
|
+
const sampleDistance = 2;
|
|
3
|
+
const minimumStraightness = 0.75;
|
|
4
|
+
const curveTolerance = 10;
|
|
5
|
+
const rightButton = 2;
|
|
6
|
+
const menuDelay = 650;
|
|
7
|
+
const feedbackDelay = 450;
|
|
8
|
+
const recognitionDelay = 34;
|
|
9
|
+
const trackingAttribute = 'data-dwb-mouse-gesture-tracking';
|
|
10
|
+
const draggingAttribute = 'data-dwb-mouse-gesture-dragging';
|
|
11
|
+
|
|
12
|
+
function recordPoint(gesture, { clientX: x, clientY: y, timeStamp }) {
|
|
13
|
+
// Pointer and compatibility mouse events may report the same samples.
|
|
14
|
+
if (timeStamp < gesture.lastSampleTime) return;
|
|
15
|
+
gesture.lastSampleTime = timeStamp;
|
|
16
|
+
const last = gesture.points.at(-1);
|
|
17
|
+
const segment = Math.hypot(x - last.x, y - last.y);
|
|
18
|
+
const start = gesture.points[0];
|
|
19
|
+
gesture.tip = { x, y, remainder: segment };
|
|
20
|
+
if (segment >= sampleDistance) {
|
|
21
|
+
gesture.points.push(gesture.tip);
|
|
22
|
+
gesture.length += segment;
|
|
23
|
+
gesture.tip.remainder = 0;
|
|
24
|
+
}
|
|
25
|
+
gesture.maxDistance = Math.max(gesture.maxDistance, Math.hypot(x - start.x, y - start.y));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function isStableClick(gesture) {
|
|
29
|
+
return gesture.maxDistance < dragDistance;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function directionOf(gesture) {
|
|
33
|
+
const start = gesture.points[0];
|
|
34
|
+
const x = gesture.tip.x - start.x;
|
|
35
|
+
const y = gesture.tip.y - start.y;
|
|
36
|
+
const distance = Math.hypot(x, y);
|
|
37
|
+
const length = gesture.length + gesture.tip.remainder;
|
|
38
|
+
// A straight stroke has a ratio of one. Detours and reversals increase the traveled length.
|
|
39
|
+
if (distance < dragDistance || (length - distance > curveTolerance && distance < length * minimumStraightness)) {
|
|
40
|
+
return 'invalid';
|
|
41
|
+
}
|
|
42
|
+
// The diagonals are the 45° boundaries between the four directions.
|
|
43
|
+
if (Math.abs(x) >= Math.abs(y)) return x < 0 ? 'left' : 'right';
|
|
44
|
+
return y < 0 ? 'up' : 'invalid';
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function createFeedback(getBadgeBounds, actionLabel) {
|
|
48
|
+
const overlay = document.createElement('div');
|
|
49
|
+
overlay.className = 'dwb-mouse-gesture';
|
|
50
|
+
overlay.setAttribute('aria-hidden', 'true');
|
|
51
|
+
overlay.innerHTML = [
|
|
52
|
+
'<svg class="dwb-mouse-gesture-trail"><polyline /></svg>',
|
|
53
|
+
'<div class="dwb-mouse-gesture-badge">',
|
|
54
|
+
'<svg viewBox="0 0 24 24"><path /></svg><span></span>',
|
|
55
|
+
'</div>',
|
|
56
|
+
].join('');
|
|
57
|
+
const trail = overlay.querySelector('polyline');
|
|
58
|
+
const icon = overlay.querySelector('.dwb-mouse-gesture-badge path');
|
|
59
|
+
const label = overlay.querySelector('span');
|
|
60
|
+
let timer;
|
|
61
|
+
let frame;
|
|
62
|
+
let displayed;
|
|
63
|
+
|
|
64
|
+
function hide() {
|
|
65
|
+
clearTimeout(timer);
|
|
66
|
+
cancelAnimationFrame(frame);
|
|
67
|
+
frame = undefined;
|
|
68
|
+
displayed = undefined;
|
|
69
|
+
trail.removeAttribute('points');
|
|
70
|
+
overlay.removeAttribute('data-finished');
|
|
71
|
+
overlay.removeAttribute('data-action');
|
|
72
|
+
overlay.removeAttribute('data-stable-click');
|
|
73
|
+
overlay.remove();
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function render(gesture) {
|
|
77
|
+
const points = gesture.points.map(({ x, y }) => x + ',' + y);
|
|
78
|
+
points.push(gesture.tip.x + ',' + gesture.tip.y);
|
|
79
|
+
trail.setAttribute('points', points.join(' '));
|
|
80
|
+
overlay.toggleAttribute('data-stable-click', isStableClick(gesture));
|
|
81
|
+
if (!overlay.isConnected) document.body.append(overlay);
|
|
82
|
+
displayed = gesture;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function draw(gesture) {
|
|
86
|
+
if (frame !== undefined) return;
|
|
87
|
+
frame = requestAnimationFrame(() => {
|
|
88
|
+
frame = undefined;
|
|
89
|
+
render(gesture);
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function finish(gesture) {
|
|
94
|
+
cancelAnimationFrame(frame);
|
|
95
|
+
frame = undefined;
|
|
96
|
+
render(gesture);
|
|
97
|
+
overlay.setAttribute('data-finished', '');
|
|
98
|
+
timer = setTimeout(hide, feedbackDelay);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function showAction(gesture, action) {
|
|
102
|
+
if (displayed !== gesture) return;
|
|
103
|
+
const bounds = getBadgeBounds();
|
|
104
|
+
if (!bounds) return;
|
|
105
|
+
overlay.style.setProperty('--dwb-gesture-badge-x', bounds.left + bounds.width / 2 + 'px');
|
|
106
|
+
overlay.style.setProperty('--dwb-gesture-badge-y', bounds.top + bounds.height / 2 + 'px');
|
|
107
|
+
overlay.dataset.action = action;
|
|
108
|
+
icon.setAttribute('d', action === 'invalid' ? 'M6 6l12 12M18 6 6 18' : 'M5 12h14m-6-6 6 6-6 6');
|
|
109
|
+
label.textContent = actionLabel(action);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return { draw, render, finish, showAction, hide, overlay };
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function installMouseGestures(resolveAction, getBadgeBounds, acceptsTarget, actionLabel) {
|
|
116
|
+
const lifetime = new AbortController();
|
|
117
|
+
const options = { capture: true, signal: lifetime.signal };
|
|
118
|
+
const feedback = createFeedback(getBadgeBounds, actionLabel);
|
|
119
|
+
const root = document.documentElement;
|
|
120
|
+
let gesture;
|
|
121
|
+
let suppressMenuUntil = -Infinity;
|
|
122
|
+
|
|
123
|
+
function cancel() {
|
|
124
|
+
if (gesture) gesture.cancelled = true;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function block(event) {
|
|
128
|
+
event.preventDefault();
|
|
129
|
+
event.stopImmediatePropagation();
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function start(event) {
|
|
133
|
+
if (gesture && (!isStableClick(gesture) || event.button !== rightButton)) {
|
|
134
|
+
block(event);
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
const pointer = event.type === 'pointerdown';
|
|
138
|
+
if (pointer && event.pointerType !== 'mouse') return;
|
|
139
|
+
if (event.button !== rightButton || !(event.buttons & rightButton)) return;
|
|
140
|
+
if (!pointer && gesture && gesture.id !== undefined) return;
|
|
141
|
+
gesture = undefined;
|
|
142
|
+
suppressMenuUntil = -Infinity;
|
|
143
|
+
feedback.hide();
|
|
144
|
+
root.removeAttribute(trackingAttribute);
|
|
145
|
+
const target = event.target;
|
|
146
|
+
if (!(target instanceof Element) || !acceptsTarget(target)) return;
|
|
147
|
+
const origin = { x: event.clientX, y: event.clientY, remainder: 0 };
|
|
148
|
+
gesture = {
|
|
149
|
+
id: pointer ? event.pointerId : undefined,
|
|
150
|
+
points: [origin],
|
|
151
|
+
tip: origin,
|
|
152
|
+
length: 0,
|
|
153
|
+
maxDistance: 0,
|
|
154
|
+
lastSampleTime: event.timeStamp,
|
|
155
|
+
perform: resolveAction(target),
|
|
156
|
+
};
|
|
157
|
+
feedback.draw(gesture);
|
|
158
|
+
// Chromium can send the first fast move straight to an embedded preview.
|
|
159
|
+
root.setAttribute(trackingAttribute, '');
|
|
160
|
+
// Capture on the original hit target so a click still opens that target's menu.
|
|
161
|
+
// Capturing at press also keeps the first fast move when it crosses a pane or frame.
|
|
162
|
+
if (pointer) {
|
|
163
|
+
try { target.setPointerCapture(event.pointerId); } catch { /* The mouse listeners can finish the stroke. */ }
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function move(event) {
|
|
168
|
+
if (!gesture || (event.pointerType && event.pointerType !== 'mouse')) return;
|
|
169
|
+
if (gesture.outside && !(event.buttons & rightButton)) {
|
|
170
|
+
complete(event.timeStamp);
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
gesture.outside = event.clientX < 0 || event.clientX >= innerWidth
|
|
174
|
+
|| event.clientY < 0 || event.clientY >= innerHeight;
|
|
175
|
+
for (const point of event.getCoalescedEvents?.() ?? []) recordPoint(gesture, point);
|
|
176
|
+
recordPoint(gesture, event);
|
|
177
|
+
if (!isStableClick(gesture)) {
|
|
178
|
+
if (!root.hasAttribute(draggingAttribute)) {
|
|
179
|
+
feedback.render(gesture);
|
|
180
|
+
root.setAttribute(draggingAttribute, '');
|
|
181
|
+
if (gesture.id !== undefined) {
|
|
182
|
+
try { feedback.overlay.setPointerCapture(gesture.id); } catch { /* Window capture listeners still isolate the stroke. */ }
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
block(event);
|
|
186
|
+
}
|
|
187
|
+
feedback.draw(gesture);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function release(event) {
|
|
191
|
+
if (!gesture) return;
|
|
192
|
+
if (event.button !== rightButton) { block(event); return; }
|
|
193
|
+
if (event.pointerType && event.pointerType !== 'mouse') return;
|
|
194
|
+
recordPoint(gesture, event);
|
|
195
|
+
if (!isStableClick(gesture)) block(event);
|
|
196
|
+
complete(event.timeStamp);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function complete(timeStamp) {
|
|
200
|
+
const finished = gesture;
|
|
201
|
+
gesture = undefined;
|
|
202
|
+
root.removeAttribute(trackingAttribute);
|
|
203
|
+
root.removeAttribute(draggingAttribute);
|
|
204
|
+
if (isStableClick(finished) || finished.aborted) {
|
|
205
|
+
feedback.hide();
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
suppressMenuUntil = timeStamp + menuDelay;
|
|
209
|
+
feedback.finish(finished);
|
|
210
|
+
setTimeout(() => {
|
|
211
|
+
if (lifetime.signal.aborted) return;
|
|
212
|
+
const action = finished.cancelled ? 'invalid' : directionOf(finished);
|
|
213
|
+
feedback.showAction(finished, finished.perform ? action : 'invalid');
|
|
214
|
+
if (action !== 'invalid') finished.perform?.(action);
|
|
215
|
+
}, recognitionDelay);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
function contextMenu(event) {
|
|
219
|
+
if (event.button !== rightButton && event.pointerType !== 'mouse') return;
|
|
220
|
+
if (gesture && !(event.buttons & rightButton)) {
|
|
221
|
+
recordPoint(gesture, event);
|
|
222
|
+
complete(event.timeStamp);
|
|
223
|
+
}
|
|
224
|
+
if ((!gesture || isStableClick(gesture)) && event.timeStamp > suppressMenuUntil) return;
|
|
225
|
+
event.preventDefault();
|
|
226
|
+
event.stopImmediatePropagation();
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
function guardInteraction(event) {
|
|
230
|
+
if (gesture && !isStableClick(gesture)) block(event);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
function abort() {
|
|
234
|
+
if (!gesture) return;
|
|
235
|
+
const { id } = gesture;
|
|
236
|
+
gesture.aborted = true;
|
|
237
|
+
complete(performance.now());
|
|
238
|
+
if (id !== undefined && feedback.overlay.hasPointerCapture(id)) feedback.overlay.releasePointerCapture(id);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
window.addEventListener('pointerdown', start, options);
|
|
242
|
+
window.addEventListener('mousedown', start, options);
|
|
243
|
+
window.addEventListener('pointermove', move, options);
|
|
244
|
+
window.addEventListener('mousemove', move, options);
|
|
245
|
+
window.addEventListener('pointerout', event => {
|
|
246
|
+
if (!event.relatedTarget && (event.buttons & rightButton)) move(event);
|
|
247
|
+
}, options);
|
|
248
|
+
window.addEventListener('pointerup', release, options);
|
|
249
|
+
window.addEventListener('mouseup', release, options);
|
|
250
|
+
window.addEventListener('pointercancel', abort, options);
|
|
251
|
+
for (const type of ['click', 'dblclick', 'wheel', 'dragstart', 'pointerover', 'pointerout', 'mouseover', 'mouseout']) {
|
|
252
|
+
window.addEventListener(type, guardInteraction, { ...options, passive: false });
|
|
253
|
+
}
|
|
254
|
+
window.addEventListener('keydown', event => {
|
|
255
|
+
if (event.key === 'Escape' && gesture) cancel();
|
|
256
|
+
}, options);
|
|
257
|
+
window.addEventListener('contextmenu', contextMenu, options);
|
|
258
|
+
window.addEventListener('auxclick', event => {
|
|
259
|
+
guardInteraction(event);
|
|
260
|
+
if (event.button === rightButton) contextMenu(event);
|
|
261
|
+
}, options);
|
|
262
|
+
window.addEventListener('blur', event => {
|
|
263
|
+
// Capture also sees blur from inputs and rows when the right press moves focus.
|
|
264
|
+
if (event.target !== window) return;
|
|
265
|
+
abort();
|
|
266
|
+
}, options);
|
|
267
|
+
return () => {
|
|
268
|
+
lifetime.abort();
|
|
269
|
+
feedback.hide();
|
|
270
|
+
root.removeAttribute(trackingAttribute);
|
|
271
|
+
root.removeAttribute(draggingAttribute);
|
|
272
|
+
};
|
|
273
|
+
}
|
package/src/session.svg
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
<svg width="44" height="42" viewBox="0 0 44 42" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
+
<path d="M4.10726 30.5233C2.44707 27.7069 1.50049 24.4586 1.50049 21C1.50049 10.2304 10.6787 1.5 22.0005 1.5C33.3223 1.5 42.5005 10.2304 42.5005 21C42.5005 31.7696 33.3223 40.5 22.0005 40.5C18.5581 40.5 15.5785 39.7672 13.4191 38.686C11.2597 37.6049 7.27069 37.7791 5.31444 38.686C3.02607 39.747 2.13615 40.1977 1.50049 40.5" stroke-width="3" stroke-linecap="round" stroke="#C3C3C3"/>
|
|
3
|
+
<circle cx="13.0005" cy="21" r="2.5" fill="#C3C3C3"/>
|
|
4
|
+
<circle cx="22.0005" cy="21" r="2.5" fill="#C3C3C3"/>
|
|
5
|
+
<circle cx="31.0005" cy="21" r="2.5" fill="#C3C3C3"/>
|
|
6
|
+
</svg>
|